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

provider.ts

145 lines4.7 KB

1import { Schema } from "effect";
2import { TrimmedNonEmptyString } from "./baseSchemas";
3import { ProviderModelOptions } from "./model";
4import {
5 ApprovalRequestId,
6 EventId,
7 IsoDateTime,
8 NonNegativeInt,
9 ProviderItemId,
10 ThreadId,
11 TurnId,
12} from "./baseSchemas";
13import {
14 ChatAttachment,
15 PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
16 PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
17 ProviderApprovalDecision,
18 ProviderInteractionMode,
19 ProviderKind,
20 ProviderRequestKind,
21 ProviderUserInputAnswers,
22 RuntimeMode,
23} from "./orchestration";
24​
25const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
26const ProviderSessionStatus = Schema.Literals([
27 "connecting",
28 "ready",
29 "running",
30 "error",
31 "closed",
32]);
33​
34export const ProviderSession = Schema.Struct({
35 provider: ProviderKind,
36 status: ProviderSessionStatus,
37 runtimeMode: RuntimeMode,
38 cwd: Schema.optional(TrimmedNonEmptyStringSchema),
39 model: Schema.optional(TrimmedNonEmptyStringSchema),
40 threadId: ThreadId,
41 resumeCursor: Schema.optional(Schema.Unknown),
42 activeTurnId: Schema.optional(TurnId),
43 createdAt: IsoDateTime,
44 updatedAt: IsoDateTime,
45 lastError: Schema.optional(TrimmedNonEmptyStringSchema),
46});
47export type ProviderSession = typeof ProviderSession.Type;
48​
49const CodexProviderStartOptions = Schema.Struct({
50 binaryPath: Schema.optional(TrimmedNonEmptyStringSchema),
51 homePath: Schema.optional(TrimmedNonEmptyStringSchema),
52});
53​
54const ClaudeCodeProviderStartOptions = Schema.Struct({
55 binaryPath: Schema.optional(TrimmedNonEmptyStringSchema),
56 permissionMode: Schema.optional(TrimmedNonEmptyStringSchema),
57 maxThinkingTokens: Schema.optional(NonNegativeInt),
58});
59​
60const CursorProviderStartOptions = Schema.Struct({
61 binaryPath: Schema.optional(TrimmedNonEmptyStringSchema),
62});
63​
64const ProviderStartOptions = Schema.Struct({
65 codex: Schema.optional(CodexProviderStartOptions),
66 claudeCode: Schema.optional(ClaudeCodeProviderStartOptions),
67 cursor: Schema.optional(CursorProviderStartOptions),
68});
69​
70export const ProviderSessionStartInput = Schema.Struct({
71 threadId: ThreadId,
72 provider: Schema.optional(ProviderKind),
73 cwd: Schema.optional(TrimmedNonEmptyStringSchema),
74 model: Schema.optional(TrimmedNonEmptyStringSchema),
75 modelOptions: Schema.optional(ProviderModelOptions),
76 resumeCursor: Schema.optional(Schema.Unknown),
77 providerOptions: Schema.optional(ProviderStartOptions),
78 runtimeMode: RuntimeMode,
79});
80export type ProviderSessionStartInput = typeof ProviderSessionStartInput.Type;
81​
82export const ProviderSendTurnInput = Schema.Struct({
83 threadId: ThreadId,
84 input: Schema.optional(
85 TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_INPUT_CHARS)),
86 ),
87 attachments: Schema.optional(
88 Schema.Array(ChatAttachment).check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
89 ),
90 model: Schema.optional(TrimmedNonEmptyStringSchema),
91 modelOptions: Schema.optional(ProviderModelOptions),
92 interactionMode: Schema.optional(ProviderInteractionMode),
93});
94export type ProviderSendTurnInput = typeof ProviderSendTurnInput.Type;
95​
96export const ProviderTurnStartResult = Schema.Struct({
97 threadId: ThreadId,
98 turnId: TurnId,
99 resumeCursor: Schema.optional(Schema.Unknown),
100});
101export type ProviderTurnStartResult = typeof ProviderTurnStartResult.Type;
102​
103export const ProviderInterruptTurnInput = Schema.Struct({
104 threadId: ThreadId,
105 turnId: Schema.optional(TurnId),
106});
107export type ProviderInterruptTurnInput = typeof ProviderInterruptTurnInput.Type;
108​
109export const ProviderStopSessionInput = Schema.Struct({
110 threadId: ThreadId,
111});
112export type ProviderStopSessionInput = typeof ProviderStopSessionInput.Type;
113​
114export const ProviderRespondToRequestInput = Schema.Struct({
115 threadId: ThreadId,
116 requestId: ApprovalRequestId,
117 decision: ProviderApprovalDecision,
118});
119export type ProviderRespondToRequestInput = typeof ProviderRespondToRequestInput.Type;
120​
121export const ProviderRespondToUserInputInput = Schema.Struct({
122 threadId: ThreadId,
123 requestId: ApprovalRequestId,
124 answers: ProviderUserInputAnswers,
125});
126export type ProviderRespondToUserInputInput = typeof ProviderRespondToUserInputInput.Type;
127​
128const ProviderEventKind = Schema.Literals(["session", "notification", "request", "error"]);
129​
130export const ProviderEvent = Schema.Struct({
131 id: EventId,
132 kind: ProviderEventKind,
133 provider: ProviderKind,
134 threadId: ThreadId,
135 createdAt: IsoDateTime,
136 method: TrimmedNonEmptyStringSchema,
137 message: Schema.optional(TrimmedNonEmptyStringSchema),
138 turnId: Schema.optional(TurnId),
139 itemId: Schema.optional(ProviderItemId),
140 requestId: Schema.optional(ApprovalRequestId),
141 requestKind: Schema.optional(ProviderRequestKind),
142 textDelta: Schema.optional(Schema.String),
143 payload: Schema.optional(Schema.Unknown),
144});
145export type ProviderEvent = typeof ProviderEvent.Type;