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

provider.ts

131 lines4.4 KB

1import * as Schema from "effect/Schema";
2import { TrimmedNonEmptyString } from "./baseSchemas.ts";
3import {
4 ApprovalRequestId,
5 EventId,
6 IsoDateTime,
7 ProviderItemId,
8 ThreadId,
9 TurnId,
10} from "./baseSchemas.ts";
11import {
12 ChatAttachment,
13 ModelSelection,
14 PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
15 PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
16 ProviderApprovalDecision,
17 ProviderApprovalPolicy,
18 ProviderInteractionMode,
19 ProviderRequestKind,
20 ProviderSandboxMode,
21 ProviderUserInputAnswers,
22 RuntimeMode,
23} from "./orchestration.ts";
24import { ProviderInstanceId, ProviderDriverKind } from "./providerInstance.ts";
25​
26const ProviderSessionStatus = Schema.Literals([
27 "connecting",
28 "ready",
29 "running",
30 "error",
31 "closed",
32]);
33​
34export const ProviderSession = Schema.Struct({
35 provider: ProviderDriverKind,
36 // Optional during the driver/instance migration. Once every producer
37 // populates it (post-slice-4), routing flips to instance-id-only and the
38 // legacy `provider` field is removed.
39 providerInstanceId: Schema.optional(ProviderInstanceId),
40 status: ProviderSessionStatus,
41 runtimeMode: RuntimeMode,
42 cwd: Schema.optional(TrimmedNonEmptyString),
43 model: Schema.optional(TrimmedNonEmptyString),
44 threadId: ThreadId,
45 resumeCursor: Schema.optional(Schema.Unknown),
46 activeTurnId: Schema.optional(TurnId),
47 createdAt: IsoDateTime,
48 updatedAt: IsoDateTime,
49 lastError: Schema.optional(TrimmedNonEmptyString),
50});
51export type ProviderSession = typeof ProviderSession.Type;
52​
53export const ProviderSessionStartInput = Schema.Struct({
54 threadId: ThreadId,
55 provider: Schema.optional(ProviderDriverKind),
56 // See ProviderSession for the migration story.
57 providerInstanceId: Schema.optional(ProviderInstanceId),
58 cwd: Schema.optional(TrimmedNonEmptyString),
59 modelSelection: Schema.optional(ModelSelection),
60 resumeCursor: Schema.optional(Schema.Unknown),
61 approvalPolicy: Schema.optional(ProviderApprovalPolicy),
62 sandboxMode: Schema.optional(ProviderSandboxMode),
63 runtimeMode: RuntimeMode,
64});
65export type ProviderSessionStartInput = typeof ProviderSessionStartInput.Type;
66​
67export const ProviderSendTurnInput = Schema.Struct({
68 threadId: ThreadId,
69 input: Schema.optional(
70 TrimmedNonEmptyString.check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_INPUT_CHARS)),
71 ),
72 attachments: Schema.optional(
73 Schema.Array(ChatAttachment).check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
74 ),
75 modelSelection: Schema.optional(ModelSelection),
76 interactionMode: Schema.optional(ProviderInteractionMode),
77});
78export type ProviderSendTurnInput = typeof ProviderSendTurnInput.Type;
79​
80export const ProviderTurnStartResult = Schema.Struct({
81 threadId: ThreadId,
82 turnId: TurnId,
83 resumeCursor: Schema.optional(Schema.Unknown),
84});
85export type ProviderTurnStartResult = typeof ProviderTurnStartResult.Type;
86​
87export const ProviderInterruptTurnInput = Schema.Struct({
88 threadId: ThreadId,
89 turnId: Schema.optional(TurnId),
90});
91export type ProviderInterruptTurnInput = typeof ProviderInterruptTurnInput.Type;
92​
93export const ProviderStopSessionInput = Schema.Struct({
94 threadId: ThreadId,
95});
96export type ProviderStopSessionInput = typeof ProviderStopSessionInput.Type;
97​
98export const ProviderRespondToRequestInput = Schema.Struct({
99 threadId: ThreadId,
100 requestId: ApprovalRequestId,
101 decision: ProviderApprovalDecision,
102});
103export type ProviderRespondToRequestInput = typeof ProviderRespondToRequestInput.Type;
104​
105export const ProviderRespondToUserInputInput = Schema.Struct({
106 threadId: ThreadId,
107 requestId: ApprovalRequestId,
108 answers: ProviderUserInputAnswers,
109});
110export type ProviderRespondToUserInputInput = typeof ProviderRespondToUserInputInput.Type;
111​
112const ProviderEventKind = Schema.Literals(["session", "notification", "request", "error"]);
113​
114export const ProviderEvent = Schema.Struct({
115 id: EventId,
116 kind: ProviderEventKind,
117 provider: ProviderDriverKind,
118 // See ProviderSession for the migration story.
119 providerInstanceId: Schema.optional(ProviderInstanceId),
120 threadId: ThreadId,
121 createdAt: IsoDateTime,
122 method: TrimmedNonEmptyString,
123 message: Schema.optional(TrimmedNonEmptyString),
124 turnId: Schema.optional(TurnId),
125 itemId: Schema.optional(ProviderItemId),
126 requestId: Schema.optional(ApprovalRequestId),
127 requestKind: Schema.optional(ProviderRequestKind),
128 textDelta: Schema.optional(Schema.String),
129 payload: Schema.optional(Schema.Unknown),
130});
131export type ProviderEvent = typeof ProviderEvent.Type;