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

provider.ts

132 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 title: Schema.optional(TrimmedNonEmptyString),
60 modelSelection: Schema.optional(ModelSelection),
61 resumeCursor: Schema.optional(Schema.Unknown),
62 approvalPolicy: Schema.optional(ProviderApprovalPolicy),
63 sandboxMode: Schema.optional(ProviderSandboxMode),
64 runtimeMode: RuntimeMode,
65});
66export type ProviderSessionStartInput = typeof ProviderSessionStartInput.Type;
67​
68export const ProviderSendTurnInput = Schema.Struct({
69 threadId: ThreadId,
70 input: Schema.optional(
71 TrimmedNonEmptyString.check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_INPUT_CHARS)),
72 ),
73 attachments: Schema.optional(
74 Schema.Array(ChatAttachment).check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
75 ),
76 modelSelection: Schema.optional(ModelSelection),
77 interactionMode: Schema.optional(ProviderInteractionMode),
78});
79export type ProviderSendTurnInput = typeof ProviderSendTurnInput.Type;
80​
81export const ProviderTurnStartResult = Schema.Struct({
82 threadId: ThreadId,
83 turnId: TurnId,
84 resumeCursor: Schema.optional(Schema.Unknown),
85});
86export type ProviderTurnStartResult = typeof ProviderTurnStartResult.Type;
87​
88export const ProviderInterruptTurnInput = Schema.Struct({
89 threadId: ThreadId,
90 turnId: Schema.optional(TurnId),
91});
92export type ProviderInterruptTurnInput = typeof ProviderInterruptTurnInput.Type;
93​
94export const ProviderStopSessionInput = Schema.Struct({
95 threadId: ThreadId,
96});
97export type ProviderStopSessionInput = typeof ProviderStopSessionInput.Type;
98​
99export const ProviderRespondToRequestInput = Schema.Struct({
100 threadId: ThreadId,
101 requestId: ApprovalRequestId,
102 decision: ProviderApprovalDecision,
103});
104export type ProviderRespondToRequestInput = typeof ProviderRespondToRequestInput.Type;
105​
106export const ProviderRespondToUserInputInput = Schema.Struct({
107 threadId: ThreadId,
108 requestId: ApprovalRequestId,
109 answers: ProviderUserInputAnswers,
110});
111export type ProviderRespondToUserInputInput = typeof ProviderRespondToUserInputInput.Type;
112​
113const ProviderEventKind = Schema.Literals(["session", "notification", "request", "error"]);
114​
115export const ProviderEvent = Schema.Struct({
116 id: EventId,
117 kind: ProviderEventKind,
118 provider: ProviderDriverKind,
119 // See ProviderSession for the migration story.
120 providerInstanceId: Schema.optional(ProviderInstanceId),
121 threadId: ThreadId,
122 createdAt: IsoDateTime,
123 method: TrimmedNonEmptyString,
124 message: Schema.optional(TrimmedNonEmptyString),
125 turnId: Schema.optional(TurnId),
126 itemId: Schema.optional(ProviderItemId),
127 requestId: Schema.optional(ApprovalRequestId),
128 requestKind: Schema.optional(ProviderRequestKind),
129 textDelta: Schema.optional(Schema.String),
130 payload: Schema.optional(Schema.Unknown),
131});
132export type ProviderEvent = typeof ProviderEvent.Type;