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