The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { |
| 2 | ChatImageAttachment, |
| 3 | ChatFileAttachment, |
| 4 | PROVIDER_SEND_TURN_MAX_ATTACHMENTS, |
| 5 | } from "./chatAttachment.ts"; |
| 6 | import * as Schema from "effect/Schema"; |
| 7 | |
| 8 | import { TrimmedNonEmptyString } from "./baseSchemas.ts"; |
| 9 | |
| 10 | export const ProviderApprovalPolicy = Schema.Literals([ |
| 11 | "untrusted", |
| 12 | "on-failure", |
| 13 | "on-request", |
| 14 | "never", |
| 15 | ]); |
| 16 | export type ProviderApprovalPolicy = typeof ProviderApprovalPolicy.Type; |
| 17 | |
| 18 | export const ProviderSandboxMode = Schema.Literals([ |
| 19 | "read-only", |
| 20 | "workspace-write", |
| 21 | "danger-full-access", |
| 22 | ]); |
| 23 | export type ProviderSandboxMode = typeof ProviderSandboxMode.Type; |
| 24 | |
| 25 | export const RuntimeMode = Schema.Literals([ |
| 26 | "approval-required", |
| 27 | "auto-accept-edits", |
| 28 | "auto", |
| 29 | "full-access", |
| 30 | ]); |
| 31 | export type RuntimeMode = typeof RuntimeMode.Type; |
| 32 | export const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access"; |
| 33 | |
| 34 | const 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. */ |
| 42 | export const isRuntimeModeAbove = (mode: RuntimeMode, ceiling: RuntimeMode | undefined): boolean => |
| 43 | ceiling !== undefined && RUNTIME_MODE_RANK[mode] > RUNTIME_MODE_RANK[ceiling]; |
| 44 | |
| 45 | export const ProviderInteractionMode = Schema.Literals(["default", "plan"]); |
| 46 | export type ProviderInteractionMode = typeof ProviderInteractionMode.Type; |
| 47 | export const DEFAULT_PROVIDER_INTERACTION_MODE: ProviderInteractionMode = "default"; |
| 48 | |
| 49 | export const ProviderRequestKind = Schema.Literals([ |
| 50 | "command", |
| 51 | "file-read", |
| 52 | "file-change", |
| 53 | "mcp-elicitation", |
| 54 | "permission", |
| 55 | ]); |
| 56 | export type ProviderRequestKind = typeof ProviderRequestKind.Type; |
| 57 | |
| 58 | export const ProviderApprovalDecision = Schema.Literals([ |
| 59 | "accept", |
| 60 | "acceptForSession", |
| 61 | "acceptAlways", |
| 62 | "decline", |
| 63 | "cancel", |
| 64 | ]); |
| 65 | export 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. |
| 69 | export const ProviderApprovalFullAccessOverride = Schema.Literals(["ask_rule", "provider_check"]); |
| 70 | export type ProviderApprovalFullAccessOverride = typeof ProviderApprovalFullAccessOverride.Type; |
| 71 | |
| 72 | export const ProviderApprovalOption = Schema.Struct({ |
| 73 | decision: ProviderApprovalDecision, |
| 74 | label: TrimmedNonEmptyString, |
| 75 | warning: Schema.optional(TrimmedNonEmptyString), |
| 76 | }); |
| 77 | export type ProviderApprovalOption = typeof ProviderApprovalOption.Type; |
| 78 | |
| 79 | export const ProviderUserInputAnswers = Schema.Record(Schema.String, Schema.Unknown); |
| 80 | export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type; |
| 81 | |
| 82 | export 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 | ); |
| 88 | export type UserInputAttachments = typeof UserInputAttachments.Type; |
| 89 | |
| 90 | export const UserInputAttachmentAnswerPayload = Schema.Struct({ |
| 91 | requestId: TrimmedNonEmptyString, |
| 92 | questionTextById: Schema.optional(Schema.Record(Schema.String, Schema.String)), |
| 93 | answers: ProviderUserInputAnswers, |
| 94 | attachmentsByQuestionId: UserInputAttachments, |
| 95 | }); |
| 96 | export type UserInputAttachmentAnswerPayload = typeof UserInputAttachmentAnswerPayload.Type; |