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

provider.ts

123 lines3.8 KB

1import { Schema } from "effect";
2import { TrimmedNonEmptyString } from "./baseSchemas";
3import {
4 ApprovalRequestId,
5 EventId,
6 IsoDateTime,
7 ProviderItemId,
8 ThreadId,
9 TurnId,
10} from "./baseSchemas";
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 ProviderKind,
20 ProviderRequestKind,
21 ProviderSandboxMode,
22 ProviderUserInputAnswers,
23 RuntimeMode,
24} from "./orchestration";
25​
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(TrimmedNonEmptyString),
39 model: Schema.optional(TrimmedNonEmptyString),
40 threadId: ThreadId,
41 resumeCursor: Schema.optional(Schema.Unknown),
42 activeTurnId: Schema.optional(TurnId),
43 createdAt: IsoDateTime,
44 updatedAt: IsoDateTime,
45 lastError: Schema.optional(TrimmedNonEmptyString),
46});
47export type ProviderSession = typeof ProviderSession.Type;
48​
49export const ProviderSessionStartInput = Schema.Struct({
50 threadId: ThreadId,
51 provider: Schema.optional(ProviderKind),
52 cwd: Schema.optional(TrimmedNonEmptyString),
53 modelSelection: Schema.optional(ModelSelection),
54 resumeCursor: Schema.optional(Schema.Unknown),
55 approvalPolicy: Schema.optional(ProviderApprovalPolicy),
56 sandboxMode: Schema.optional(ProviderSandboxMode),
57 runtimeMode: RuntimeMode,
58});
59export type ProviderSessionStartInput = typeof ProviderSessionStartInput.Type;
60​
61export const ProviderSendTurnInput = Schema.Struct({
62 threadId: ThreadId,
63 input: Schema.optional(
64 TrimmedNonEmptyString.check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_INPUT_CHARS)),
65 ),
66 attachments: Schema.optional(
67 Schema.Array(ChatAttachment).check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
68 ),
69 modelSelection: Schema.optional(ModelSelection),
70 interactionMode: Schema.optional(ProviderInteractionMode),
71});
72export type ProviderSendTurnInput = typeof ProviderSendTurnInput.Type;
73​
74export const ProviderTurnStartResult = Schema.Struct({
75 threadId: ThreadId,
76 turnId: TurnId,
77 resumeCursor: Schema.optional(Schema.Unknown),
78});
79export type ProviderTurnStartResult = typeof ProviderTurnStartResult.Type;
80​
81export const ProviderInterruptTurnInput = Schema.Struct({
82 threadId: ThreadId,
83 turnId: Schema.optional(TurnId),
84});
85export type ProviderInterruptTurnInput = typeof ProviderInterruptTurnInput.Type;
86​
87export const ProviderStopSessionInput = Schema.Struct({
88 threadId: ThreadId,
89});
90export type ProviderStopSessionInput = typeof ProviderStopSessionInput.Type;
91​
92export const ProviderRespondToRequestInput = Schema.Struct({
93 threadId: ThreadId,
94 requestId: ApprovalRequestId,
95 decision: ProviderApprovalDecision,
96});
97export type ProviderRespondToRequestInput = typeof ProviderRespondToRequestInput.Type;
98​
99export const ProviderRespondToUserInputInput = Schema.Struct({
100 threadId: ThreadId,
101 requestId: ApprovalRequestId,
102 answers: ProviderUserInputAnswers,
103});
104export type ProviderRespondToUserInputInput = typeof ProviderRespondToUserInputInput.Type;
105​
106const ProviderEventKind = Schema.Literals(["session", "notification", "request", "error"]);
107​
108export const ProviderEvent = Schema.Struct({
109 id: EventId,
110 kind: ProviderEventKind,
111 provider: ProviderKind,
112 threadId: ThreadId,
113 createdAt: IsoDateTime,
114 method: TrimmedNonEmptyString,
115 message: Schema.optional(TrimmedNonEmptyString),
116 turnId: Schema.optional(TurnId),
117 itemId: Schema.optional(ProviderItemId),
118 requestId: Schema.optional(ApprovalRequestId),
119 requestKind: Schema.optional(ProviderRequestKind),
120 textDelta: Schema.optional(Schema.String),
121 payload: Schema.optional(Schema.Unknown),
122});
123export type ProviderEvent = typeof ProviderEvent.Type;