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

providerPolicy.ts

109 lines3.8 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​
79/**
80 * What an approval to run a repository's push hooks names. Clients show it as the request's
81 * details; the item's `prompt` stays the whole question in one sentence.
82 */
83export const ProviderApprovalPushHooks = Schema.Struct({
84 branch: Schema.String,
85 /** Hook files, relative to the checkout when they are in it. */
86 files: Schema.Array(Schema.String),
87 /** Hooks Git's configuration defines. */
88 commands: Schema.Array(Schema.Struct({ name: Schema.String, command: Schema.String })),
89});
90export type ProviderApprovalPushHooks = typeof ProviderApprovalPushHooks.Type;
91​
92export const ProviderUserInputAnswers = Schema.Record(Schema.String, Schema.Unknown);
93export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type;
94​
95export const UserInputAttachments = Schema.Record(
96 Schema.String,
97 Schema.Array(Schema.Union([ChatImageAttachment, ChatFileAttachment])).pipe(
98 Schema.check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
99 ),
100);
101export type UserInputAttachments = typeof UserInputAttachments.Type;
102​
103export const UserInputAttachmentAnswerPayload = Schema.Struct({
104 requestId: TrimmedNonEmptyString,
105 questionTextById: Schema.optional(Schema.Record(Schema.String, Schema.String)),
106 answers: ProviderUserInputAnswers,
107 attachmentsByQuestionId: UserInputAttachments,
108});
109export type UserInputAttachmentAnswerPayload = typeof UserInputAttachmentAnswerPayload.Type;