Skip to content
Source
Sign inSign up

providerPolicy.ts

96 lines3.3 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​
34const RUNTIME_MODE_RANK: Record<RuntimeMode, number> = {
35 "approval-required": 0,
36 "auto-accept-edits": 1,
37 auto: 2,
38 "full-access": 3,
39};
40​
41/** Whether `mode` grants the agent more than `ceiling`; no ceiling allows every mode. */
42export const isRuntimeModeAbove = (mode: RuntimeMode, ceiling: RuntimeMode | undefined): boolean =>
43 ceiling !== undefined && RUNTIME_MODE_RANK[mode] > RUNTIME_MODE_RANK[ceiling];
44​
45export const ProviderInteractionMode = Schema.Literals(["default", "plan"]);
46export type ProviderInteractionMode = typeof ProviderInteractionMode.Type;
47export const DEFAULT_PROVIDER_INTERACTION_MODE: ProviderInteractionMode = "default";
48​
49export const ProviderRequestKind = Schema.Literals([
50 "command",
51 "file-read",
52 "file-change",
53 "mcp-elicitation",
54 "permission",
55]);
56export type ProviderRequestKind = typeof ProviderRequestKind.Type;
57​
58export const ProviderApprovalDecision = Schema.Literals([
59 "accept",
60 "acceptForSession",
61 "acceptAlways",
62 "decline",
63 "cancel",
64]);
65export type ProviderApprovalDecision = typeof ProviderApprovalDecision.Type;
66​
67// Why an approval reached the user although the thread runs with full access:
68// the user's own ask rule, or a check the provider enforces even when bypassed.
69export const ProviderApprovalFullAccessOverride = Schema.Literals(["ask_rule", "provider_check"]);
70export type ProviderApprovalFullAccessOverride = typeof ProviderApprovalFullAccessOverride.Type;
71​
72export const ProviderApprovalOption = Schema.Struct({
73 decision: ProviderApprovalDecision,
74 label: TrimmedNonEmptyString,
75 warning: Schema.optional(TrimmedNonEmptyString),
76});
77export type ProviderApprovalOption = typeof ProviderApprovalOption.Type;
78​
79export const ProviderUserInputAnswers = Schema.Record(Schema.String, Schema.Unknown);
80export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type;
81​
82export const UserInputAttachments = Schema.Record(
83 Schema.String,
84 Schema.Array(Schema.Union([ChatImageAttachment, ChatFileAttachment])).pipe(
85 Schema.check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
86 ),
87);
88export type UserInputAttachments = typeof UserInputAttachments.Type;
89​
90export const UserInputAttachmentAnswerPayload = Schema.Struct({
91 requestId: TrimmedNonEmptyString,
92 questionTextById: Schema.optional(Schema.Record(Schema.String, Schema.String)),
93 answers: ProviderUserInputAnswers,
94 attachmentsByQuestionId: UserInputAttachments,
95});
96export type UserInputAttachmentAnswerPayload = typeof UserInputAttachmentAnswerPayload.Type;