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
59export const ProviderApprovalOption = Schema.Struct({
60 decision: ProviderApprovalDecision,
61 label: TrimmedNonEmptyString,
62 /** Provider-supplied caution shown next to the option, such as a prompt injection warning. */
63 warning: Schema.optional(TrimmedNonEmptyString),
64});
65export type ProviderApprovalOption = typeof ProviderApprovalOption.Type;
66
67export const ProviderUserInputAnswers = Schema.Record(Schema.String, Schema.Unknown);
68export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type;
69
70export const UserInputAttachments = Schema.Record(
71 Schema.String,
72 Schema.Array(Schema.Union([ChatImageAttachment, ChatFileAttachment])).pipe(
73 Schema.check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
74 ),
75);
76export type UserInputAttachments = typeof UserInputAttachments.Type;
77
78export const UserInputAttachmentAnswerPayload = Schema.Struct({
79 requestId: TrimmedNonEmptyString,
80 questionTextById: Schema.optional(Schema.Record(Schema.String, Schema.String)),
81 answers: ProviderUserInputAnswers,
82 attachmentsByQuestionId: UserInputAttachments,
83});
84export type UserInputAttachmentAnswerPayload = typeof UserInputAttachmentAnswerPayload.Type;