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

provider.ts

174 lines6.0 KB

1import { Schema } from "effect";
2import { TrimmedNonEmptyString } from "./baseSchemas";
3import {
4 ApprovalRequestId,
5 EventId,
6 IsoDateTime,
7 NonNegativeInt,
8 ProviderItemId,
9 ProviderSessionId,
10 ProviderThreadId,
11 ProviderTurnId,
12 ThreadId,
13} from "./baseSchemas";
14import {
15 ChatAttachment,
16 PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
17 PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
18 ProviderApprovalDecision,
19 ProviderApprovalPolicy,
20 ProviderKind,
21 ProviderRequestKind,
22 ProviderSandboxMode,
23 TurnCountRange,
24} from "./orchestration";
25​
26const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
27​
28export const ProviderSessionStatus = Schema.Literals([
29 "connecting",
30 "ready",
31 "running",
32 "error",
33 "closed",
34]);
35export type ProviderSessionStatus = typeof ProviderSessionStatus.Type;
36​
37export const ProviderSession = Schema.Struct({
38 sessionId: ProviderSessionId,
39 provider: ProviderKind,
40 status: ProviderSessionStatus,
41 cwd: Schema.optional(TrimmedNonEmptyStringSchema),
42 model: Schema.optional(TrimmedNonEmptyStringSchema),
43 threadId: Schema.optional(ProviderThreadId),
44 resumeCursor: Schema.optional(Schema.Unknown),
45 activeTurnId: Schema.optional(ProviderTurnId),
46 createdAt: IsoDateTime,
47 updatedAt: IsoDateTime,
48 lastError: Schema.optional(TrimmedNonEmptyStringSchema),
49});
50export type ProviderSession = typeof ProviderSession.Type;
51​
52export const ProviderSessionStartInput = Schema.Struct({
53 provider: Schema.optional(ProviderKind),
54 cwd: Schema.optional(TrimmedNonEmptyStringSchema),
55 model: Schema.optional(TrimmedNonEmptyStringSchema),
56 resumeThreadId: Schema.optional(ProviderThreadId),
57 resumeCursor: Schema.optional(Schema.Unknown),
58 codexBinaryPath: Schema.optional(TrimmedNonEmptyStringSchema),
59 codexHomePath: Schema.optional(TrimmedNonEmptyStringSchema),
60 approvalPolicy: Schema.optional(ProviderApprovalPolicy),
61 sandboxMode: Schema.optional(ProviderSandboxMode),
62});
63export type ProviderSessionStartInput = typeof ProviderSessionStartInput.Type;
64​
65export const ProviderSendTurnInput = Schema.Struct({
66 sessionId: ProviderSessionId,
67 input: Schema.optional(
68 TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_INPUT_CHARS)),
69 ),
70 attachments: Schema.optional(
71 Schema.Array(ChatAttachment).check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
72 ),
73 model: Schema.optional(TrimmedNonEmptyStringSchema),
74 effort: Schema.optional(TrimmedNonEmptyStringSchema),
75});
76export type ProviderSendTurnInput = typeof ProviderSendTurnInput.Type;
77​
78export const ProviderTurnStartResult = Schema.Struct({
79 threadId: ProviderThreadId,
80 turnId: ProviderTurnId,
81 resumeCursor: Schema.optional(Schema.Unknown),
82});
83export type ProviderTurnStartResult = typeof ProviderTurnStartResult.Type;
84​
85export const ProviderInterruptTurnInput = Schema.Struct({
86 sessionId: ProviderSessionId,
87 turnId: Schema.optional(ProviderTurnId),
88});
89export type ProviderInterruptTurnInput = typeof ProviderInterruptTurnInput.Type;
90​
91export const ProviderStopSessionInput = Schema.Struct({
92 sessionId: ProviderSessionId,
93});
94export type ProviderStopSessionInput = typeof ProviderStopSessionInput.Type;
95​
96export const ProviderListCheckpointsInput = Schema.Struct({
97 sessionId: ProviderSessionId,
98});
99export type ProviderListCheckpointsInput = typeof ProviderListCheckpointsInput.Type;
100​
101export const ProviderCheckpoint = Schema.Struct({
102 id: TrimmedNonEmptyStringSchema,
103 turnCount: NonNegativeInt,
104 messageCount: NonNegativeInt,
105 label: TrimmedNonEmptyStringSchema,
106 preview: Schema.optional(TrimmedNonEmptyStringSchema),
107 isCurrent: Schema.Boolean,
108});
109export type ProviderCheckpoint = typeof ProviderCheckpoint.Type;
110​
111export const ProviderListCheckpointsResult = Schema.Struct({
112 threadId: ThreadId,
113 checkpoints: Schema.Array(ProviderCheckpoint),
114});
115export type ProviderListCheckpointsResult = typeof ProviderListCheckpointsResult.Type;
116​
117export const ProviderRevertToCheckpointInput = Schema.Struct({
118 sessionId: ProviderSessionId,
119 turnCount: NonNegativeInt,
120});
121export type ProviderRevertToCheckpointInput = typeof ProviderRevertToCheckpointInput.Type;
122​
123export const ProviderRevertToCheckpointResult = Schema.Struct({
124 threadId: ThreadId,
125 turnCount: NonNegativeInt,
126 messageCount: NonNegativeInt,
127 rolledBackTurns: NonNegativeInt,
128 checkpoints: Schema.Array(ProviderCheckpoint),
129});
130export type ProviderRevertToCheckpointResult = typeof ProviderRevertToCheckpointResult.Type;
131​
132export const ProviderGetCheckpointDiffInput = Schema.Struct({
133 sessionId: ProviderSessionId,
134 ...TurnCountRange.fields,
135});
136export type ProviderGetCheckpointDiffInput = typeof ProviderGetCheckpointDiffInput.Type;
137​
138export const ProviderGetCheckpointDiffResult = Schema.Struct({
139 threadId: ThreadId,
140 ...TurnCountRange.fields,
141 diff: Schema.String,
142});
143export type ProviderGetCheckpointDiffResult = typeof ProviderGetCheckpointDiffResult.Type;
144​
145export const ProviderRespondToRequestInput = Schema.Struct({
146 sessionId: ProviderSessionId,
147 requestId: ApprovalRequestId,
148 decision: ProviderApprovalDecision,
149});
150export type ProviderRespondToRequestInput = typeof ProviderRespondToRequestInput.Type;
151​
152export const ProviderEventKind = Schema.Literals(["session", "notification", "request", "error"]);
153export type ProviderEventKind = typeof ProviderEventKind.Type;
154​
155export const ProviderEvent = Schema.Struct({
156 id: EventId,
157 kind: ProviderEventKind,
158 provider: ProviderKind,
159 sessionId: ProviderSessionId,
160 createdAt: IsoDateTime,
161 method: TrimmedNonEmptyStringSchema,
162 message: Schema.optional(TrimmedNonEmptyStringSchema),
163 threadId: Schema.optional(ProviderThreadId),
164 turnId: Schema.optional(ProviderTurnId),
165 itemId: Schema.optional(ProviderItemId),
166 requestId: Schema.optional(ApprovalRequestId),
167 requestKind: Schema.optional(ProviderRequestKind),
168 textDelta: Schema.optional(Schema.String),
169 payload: Schema.optional(Schema.Unknown),
170});
171export type ProviderEvent = typeof ProviderEvent.Type;
172​
173export type ProviderSendTurnAttachment = typeof ChatAttachment.Type;
174export type ProviderSendTurnAttachmentInput = typeof ChatAttachment.Type;