Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

providerPolicy.ts

88 lines3.0 KB

1import {
2 ChatImageAttachment,
3 ChatFileAttachment,
4 PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
5} from "./chatAttachment.ts";
6import * as Schema from "effect/Schema";
7​
8import { TrimmedNonEmptyString } from "./baseSchemas.ts";
9​
10export const ProviderApprovalPolicy = Schema.Literals([
11 "untrusted",
12 "on-failure",
13 "on-request",
14 "never",
15]);
16export type ProviderApprovalPolicy = typeof ProviderApprovalPolicy.Type;
17​
18export const ProviderSandboxMode = Schema.Literals([
19 "read-only",
20 "workspace-write",
21 "danger-full-access",
22]);
23export type ProviderSandboxMode = typeof ProviderSandboxMode.Type;
24​
25export const RuntimeMode = Schema.Literals([
26 "approval-required",
27 "auto-accept-edits",
28 "auto",
29 "full-access",
30]);
31export type RuntimeMode = typeof RuntimeMode.Type;
32export const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access";
33​
34export const ProviderInteractionMode = Schema.Literals(["default", "plan"]);
35export type ProviderInteractionMode = typeof ProviderInteractionMode.Type;
36export const DEFAULT_PROVIDER_INTERACTION_MODE: ProviderInteractionMode = "default";
37​
38export const ProviderRequestKind = Schema.Literals([
39 "command",
40 "file-read",
41 "file-change",
42 "mcp-elicitation",
43 "permission",
44]);
45export type ProviderRequestKind = typeof ProviderRequestKind.Type;
46​
47export const AssistantDeliveryMode = Schema.Literals(["buffered", "streaming"]);
48export type AssistantDeliveryMode = typeof AssistantDeliveryMode.Type;
49​
50export const ProviderApprovalDecision = Schema.Literals([
51 "accept",
52 "acceptForSession",
53 "acceptAlways",
54 "decline",
55 "cancel",
56]);
57export type ProviderApprovalDecision = typeof ProviderApprovalDecision.Type;
58​
59// Why an approval reached the user although the thread runs with full access:
60// the user's own ask rule, or a check the provider enforces even when bypassed.
61export const ProviderApprovalFullAccessOverride = Schema.Literals(["ask_rule", "provider_check"]);
62export type ProviderApprovalFullAccessOverride = typeof ProviderApprovalFullAccessOverride.Type;
63​
64export const ProviderApprovalOption = Schema.Struct({
65 decision: ProviderApprovalDecision,
66 label: TrimmedNonEmptyString,
67 warning: Schema.optional(TrimmedNonEmptyString),
68});
69export type ProviderApprovalOption = typeof ProviderApprovalOption.Type;
70​
71export const ProviderUserInputAnswers = Schema.Record(Schema.String, Schema.Unknown);
72export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type;
73​
74export const UserInputAttachments = Schema.Record(
75 Schema.String,
76 Schema.Array(Schema.Union([ChatImageAttachment, ChatFileAttachment])).pipe(
77 Schema.check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
78 ),
79);
80export type UserInputAttachments = typeof UserInputAttachments.Type;
81​
82export const UserInputAttachmentAnswerPayload = Schema.Struct({
83 requestId: TrimmedNonEmptyString,
84 questionTextById: Schema.optional(Schema.Record(Schema.String, Schema.String)),
85 answers: ProviderUserInputAnswers,
86 attachmentsByQuestionId: UserInputAttachments,
87});
88export type UserInputAttachmentAnswerPayload = typeof UserInputAttachmentAnswerPayload.Type;