@locusai/shared 0.11.6 → 0.11.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/protocol-contracts.test.d.ts +2 -0
- package/dist/__tests__/protocol-contracts.test.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +601 -0
- package/dist/protocol/cli-stream.d.ts +270 -0
- package/dist/protocol/cli-stream.d.ts.map +1 -0
- package/dist/protocol/context.d.ts +55 -0
- package/dist/protocol/context.d.ts.map +1 -0
- package/dist/protocol/envelope.d.ts +14 -0
- package/dist/protocol/envelope.d.ts.map +1 -0
- package/dist/protocol/errors.d.ts +44 -0
- package/dist/protocol/errors.d.ts.map +1 -0
- package/dist/protocol/helpers.d.ts +58 -0
- package/dist/protocol/helpers.d.ts.map +1 -0
- package/dist/protocol/host-events.d.ts +354 -0
- package/dist/protocol/host-events.d.ts.map +1 -0
- package/dist/protocol/index.d.ts +9 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/session.d.ts +97 -0
- package/dist/protocol/session.d.ts.map +1 -0
- package/dist/protocol/ui-intents.d.ts +165 -0
- package/dist/protocol/ui-intents.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Event types emitted by the CLI in `--json-stream` mode.
|
|
4
|
+
* Each event is a single JSON line (NDJSON) written to stdout.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CliStreamEventType: {
|
|
7
|
+
/** Session started — first event, always emitted */
|
|
8
|
+
readonly START: "start";
|
|
9
|
+
/** Incremental AI response text */
|
|
10
|
+
readonly TEXT_DELTA: "text_delta";
|
|
11
|
+
/** AI is thinking/reasoning */
|
|
12
|
+
readonly THINKING: "thinking";
|
|
13
|
+
/** Tool invocation started */
|
|
14
|
+
readonly TOOL_STARTED: "tool_started";
|
|
15
|
+
/** Tool invocation completed (success or failure) */
|
|
16
|
+
readonly TOOL_COMPLETED: "tool_completed";
|
|
17
|
+
/** Session status change */
|
|
18
|
+
readonly STATUS: "status";
|
|
19
|
+
/** Structured error */
|
|
20
|
+
readonly ERROR: "error";
|
|
21
|
+
/** Session finished — terminal event, always emitted last */
|
|
22
|
+
readonly DONE: "done";
|
|
23
|
+
};
|
|
24
|
+
export type CliStreamEventType = (typeof CliStreamEventType)[keyof typeof CliStreamEventType];
|
|
25
|
+
export declare const CliStreamEventTypeSchema: z.ZodEnum<{
|
|
26
|
+
/** Session started — first event, always emitted */
|
|
27
|
+
readonly START: "start";
|
|
28
|
+
/** Incremental AI response text */
|
|
29
|
+
readonly TEXT_DELTA: "text_delta";
|
|
30
|
+
/** AI is thinking/reasoning */
|
|
31
|
+
readonly THINKING: "thinking";
|
|
32
|
+
/** Tool invocation started */
|
|
33
|
+
readonly TOOL_STARTED: "tool_started";
|
|
34
|
+
/** Tool invocation completed (success or failure) */
|
|
35
|
+
readonly TOOL_COMPLETED: "tool_completed";
|
|
36
|
+
/** Session status change */
|
|
37
|
+
readonly STATUS: "status";
|
|
38
|
+
/** Structured error */
|
|
39
|
+
readonly ERROR: "error";
|
|
40
|
+
/** Session finished — terminal event, always emitted last */
|
|
41
|
+
readonly DONE: "done";
|
|
42
|
+
}>;
|
|
43
|
+
export declare const CliStartEventSchema: z.ZodObject<{
|
|
44
|
+
protocol: z.ZodLiteral<1>;
|
|
45
|
+
sessionId: z.ZodString;
|
|
46
|
+
timestamp: z.ZodNumber;
|
|
47
|
+
type: z.ZodLiteral<"start">;
|
|
48
|
+
payload: z.ZodObject<{
|
|
49
|
+
command: z.ZodString;
|
|
50
|
+
model: z.ZodOptional<z.ZodString>;
|
|
51
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
52
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
export type CliStartEvent = z.infer<typeof CliStartEventSchema>;
|
|
56
|
+
export declare const CliTextDeltaEventSchema: z.ZodObject<{
|
|
57
|
+
protocol: z.ZodLiteral<1>;
|
|
58
|
+
sessionId: z.ZodString;
|
|
59
|
+
timestamp: z.ZodNumber;
|
|
60
|
+
type: z.ZodLiteral<"text_delta">;
|
|
61
|
+
payload: z.ZodObject<{
|
|
62
|
+
content: z.ZodString;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
}, z.core.$strip>;
|
|
65
|
+
export type CliTextDeltaEvent = z.infer<typeof CliTextDeltaEventSchema>;
|
|
66
|
+
export declare const CliThinkingEventSchema: z.ZodObject<{
|
|
67
|
+
protocol: z.ZodLiteral<1>;
|
|
68
|
+
sessionId: z.ZodString;
|
|
69
|
+
timestamp: z.ZodNumber;
|
|
70
|
+
type: z.ZodLiteral<"thinking">;
|
|
71
|
+
payload: z.ZodObject<{
|
|
72
|
+
content: z.ZodOptional<z.ZodString>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
export type CliThinkingEvent = z.infer<typeof CliThinkingEventSchema>;
|
|
76
|
+
export declare const CliToolStartedEventSchema: z.ZodObject<{
|
|
77
|
+
protocol: z.ZodLiteral<1>;
|
|
78
|
+
sessionId: z.ZodString;
|
|
79
|
+
timestamp: z.ZodNumber;
|
|
80
|
+
type: z.ZodLiteral<"tool_started">;
|
|
81
|
+
payload: z.ZodObject<{
|
|
82
|
+
tool: z.ZodString;
|
|
83
|
+
toolId: z.ZodOptional<z.ZodString>;
|
|
84
|
+
parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
}, z.core.$strip>;
|
|
87
|
+
export type CliToolStartedEvent = z.infer<typeof CliToolStartedEventSchema>;
|
|
88
|
+
export declare const CliToolCompletedEventSchema: z.ZodObject<{
|
|
89
|
+
protocol: z.ZodLiteral<1>;
|
|
90
|
+
sessionId: z.ZodString;
|
|
91
|
+
timestamp: z.ZodNumber;
|
|
92
|
+
type: z.ZodLiteral<"tool_completed">;
|
|
93
|
+
payload: z.ZodObject<{
|
|
94
|
+
tool: z.ZodString;
|
|
95
|
+
toolId: z.ZodOptional<z.ZodString>;
|
|
96
|
+
success: z.ZodBoolean;
|
|
97
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
98
|
+
error: z.ZodOptional<z.ZodString>;
|
|
99
|
+
}, z.core.$strip>;
|
|
100
|
+
}, z.core.$strip>;
|
|
101
|
+
export type CliToolCompletedEvent = z.infer<typeof CliToolCompletedEventSchema>;
|
|
102
|
+
export declare const CliStatusEventSchema: z.ZodObject<{
|
|
103
|
+
protocol: z.ZodLiteral<1>;
|
|
104
|
+
sessionId: z.ZodString;
|
|
105
|
+
timestamp: z.ZodNumber;
|
|
106
|
+
type: z.ZodLiteral<"status">;
|
|
107
|
+
payload: z.ZodObject<{
|
|
108
|
+
status: z.ZodString;
|
|
109
|
+
message: z.ZodOptional<z.ZodString>;
|
|
110
|
+
}, z.core.$strip>;
|
|
111
|
+
}, z.core.$strip>;
|
|
112
|
+
export type CliStatusEvent = z.infer<typeof CliStatusEventSchema>;
|
|
113
|
+
export declare const CliErrorEventSchema: z.ZodObject<{
|
|
114
|
+
protocol: z.ZodLiteral<1>;
|
|
115
|
+
sessionId: z.ZodString;
|
|
116
|
+
timestamp: z.ZodNumber;
|
|
117
|
+
type: z.ZodLiteral<"error">;
|
|
118
|
+
payload: z.ZodObject<{
|
|
119
|
+
error: z.ZodObject<{
|
|
120
|
+
code: z.ZodEnum<{
|
|
121
|
+
readonly CLI_NOT_FOUND: "CLI_NOT_FOUND";
|
|
122
|
+
readonly AUTH_EXPIRED: "AUTH_EXPIRED";
|
|
123
|
+
readonly NETWORK_TIMEOUT: "NETWORK_TIMEOUT";
|
|
124
|
+
readonly CONTEXT_LIMIT: "CONTEXT_LIMIT";
|
|
125
|
+
readonly MALFORMED_EVENT: "MALFORMED_EVENT";
|
|
126
|
+
readonly PROCESS_CRASHED: "PROCESS_CRASHED";
|
|
127
|
+
readonly SESSION_NOT_FOUND: "SESSION_NOT_FOUND";
|
|
128
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
129
|
+
}>;
|
|
130
|
+
message: z.ZodString;
|
|
131
|
+
details: z.ZodOptional<z.ZodUnknown>;
|
|
132
|
+
recoverable: z.ZodBoolean;
|
|
133
|
+
}, z.core.$strip>;
|
|
134
|
+
}, z.core.$strip>;
|
|
135
|
+
}, z.core.$strip>;
|
|
136
|
+
export type CliErrorEvent = z.infer<typeof CliErrorEventSchema>;
|
|
137
|
+
export declare const CliDoneEventSchema: z.ZodObject<{
|
|
138
|
+
protocol: z.ZodLiteral<1>;
|
|
139
|
+
sessionId: z.ZodString;
|
|
140
|
+
timestamp: z.ZodNumber;
|
|
141
|
+
type: z.ZodLiteral<"done">;
|
|
142
|
+
payload: z.ZodObject<{
|
|
143
|
+
exitCode: z.ZodNumber;
|
|
144
|
+
duration: z.ZodNumber;
|
|
145
|
+
toolsUsed: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
146
|
+
tokensUsed: z.ZodOptional<z.ZodNumber>;
|
|
147
|
+
success: z.ZodBoolean;
|
|
148
|
+
}, z.core.$strip>;
|
|
149
|
+
}, z.core.$strip>;
|
|
150
|
+
export type CliDoneEvent = z.infer<typeof CliDoneEventSchema>;
|
|
151
|
+
export declare const CliStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
152
|
+
protocol: z.ZodLiteral<1>;
|
|
153
|
+
sessionId: z.ZodString;
|
|
154
|
+
timestamp: z.ZodNumber;
|
|
155
|
+
type: z.ZodLiteral<"start">;
|
|
156
|
+
payload: z.ZodObject<{
|
|
157
|
+
command: z.ZodString;
|
|
158
|
+
model: z.ZodOptional<z.ZodString>;
|
|
159
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
160
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
161
|
+
}, z.core.$strip>;
|
|
162
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
163
|
+
protocol: z.ZodLiteral<1>;
|
|
164
|
+
sessionId: z.ZodString;
|
|
165
|
+
timestamp: z.ZodNumber;
|
|
166
|
+
type: z.ZodLiteral<"text_delta">;
|
|
167
|
+
payload: z.ZodObject<{
|
|
168
|
+
content: z.ZodString;
|
|
169
|
+
}, z.core.$strip>;
|
|
170
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
171
|
+
protocol: z.ZodLiteral<1>;
|
|
172
|
+
sessionId: z.ZodString;
|
|
173
|
+
timestamp: z.ZodNumber;
|
|
174
|
+
type: z.ZodLiteral<"thinking">;
|
|
175
|
+
payload: z.ZodObject<{
|
|
176
|
+
content: z.ZodOptional<z.ZodString>;
|
|
177
|
+
}, z.core.$strip>;
|
|
178
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
179
|
+
protocol: z.ZodLiteral<1>;
|
|
180
|
+
sessionId: z.ZodString;
|
|
181
|
+
timestamp: z.ZodNumber;
|
|
182
|
+
type: z.ZodLiteral<"tool_started">;
|
|
183
|
+
payload: z.ZodObject<{
|
|
184
|
+
tool: z.ZodString;
|
|
185
|
+
toolId: z.ZodOptional<z.ZodString>;
|
|
186
|
+
parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
187
|
+
}, z.core.$strip>;
|
|
188
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
189
|
+
protocol: z.ZodLiteral<1>;
|
|
190
|
+
sessionId: z.ZodString;
|
|
191
|
+
timestamp: z.ZodNumber;
|
|
192
|
+
type: z.ZodLiteral<"tool_completed">;
|
|
193
|
+
payload: z.ZodObject<{
|
|
194
|
+
tool: z.ZodString;
|
|
195
|
+
toolId: z.ZodOptional<z.ZodString>;
|
|
196
|
+
success: z.ZodBoolean;
|
|
197
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
198
|
+
error: z.ZodOptional<z.ZodString>;
|
|
199
|
+
}, z.core.$strip>;
|
|
200
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
201
|
+
protocol: z.ZodLiteral<1>;
|
|
202
|
+
sessionId: z.ZodString;
|
|
203
|
+
timestamp: z.ZodNumber;
|
|
204
|
+
type: z.ZodLiteral<"status">;
|
|
205
|
+
payload: z.ZodObject<{
|
|
206
|
+
status: z.ZodString;
|
|
207
|
+
message: z.ZodOptional<z.ZodString>;
|
|
208
|
+
}, z.core.$strip>;
|
|
209
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
210
|
+
protocol: z.ZodLiteral<1>;
|
|
211
|
+
sessionId: z.ZodString;
|
|
212
|
+
timestamp: z.ZodNumber;
|
|
213
|
+
type: z.ZodLiteral<"error">;
|
|
214
|
+
payload: z.ZodObject<{
|
|
215
|
+
error: z.ZodObject<{
|
|
216
|
+
code: z.ZodEnum<{
|
|
217
|
+
readonly CLI_NOT_FOUND: "CLI_NOT_FOUND";
|
|
218
|
+
readonly AUTH_EXPIRED: "AUTH_EXPIRED";
|
|
219
|
+
readonly NETWORK_TIMEOUT: "NETWORK_TIMEOUT";
|
|
220
|
+
readonly CONTEXT_LIMIT: "CONTEXT_LIMIT";
|
|
221
|
+
readonly MALFORMED_EVENT: "MALFORMED_EVENT";
|
|
222
|
+
readonly PROCESS_CRASHED: "PROCESS_CRASHED";
|
|
223
|
+
readonly SESSION_NOT_FOUND: "SESSION_NOT_FOUND";
|
|
224
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
225
|
+
}>;
|
|
226
|
+
message: z.ZodString;
|
|
227
|
+
details: z.ZodOptional<z.ZodUnknown>;
|
|
228
|
+
recoverable: z.ZodBoolean;
|
|
229
|
+
}, z.core.$strip>;
|
|
230
|
+
}, z.core.$strip>;
|
|
231
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
232
|
+
protocol: z.ZodLiteral<1>;
|
|
233
|
+
sessionId: z.ZodString;
|
|
234
|
+
timestamp: z.ZodNumber;
|
|
235
|
+
type: z.ZodLiteral<"done">;
|
|
236
|
+
payload: z.ZodObject<{
|
|
237
|
+
exitCode: z.ZodNumber;
|
|
238
|
+
duration: z.ZodNumber;
|
|
239
|
+
toolsUsed: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
240
|
+
tokensUsed: z.ZodOptional<z.ZodNumber>;
|
|
241
|
+
success: z.ZodBoolean;
|
|
242
|
+
}, z.core.$strip>;
|
|
243
|
+
}, z.core.$strip>], "type">;
|
|
244
|
+
export type CliStreamEvent = z.infer<typeof CliStreamEventSchema>;
|
|
245
|
+
type CliStreamPayloadMap = {
|
|
246
|
+
[CliStreamEventType.START]: CliStartEvent["payload"];
|
|
247
|
+
[CliStreamEventType.TEXT_DELTA]: CliTextDeltaEvent["payload"];
|
|
248
|
+
[CliStreamEventType.THINKING]: CliThinkingEvent["payload"];
|
|
249
|
+
[CliStreamEventType.TOOL_STARTED]: CliToolStartedEvent["payload"];
|
|
250
|
+
[CliStreamEventType.TOOL_COMPLETED]: CliToolCompletedEvent["payload"];
|
|
251
|
+
[CliStreamEventType.STATUS]: CliStatusEvent["payload"];
|
|
252
|
+
[CliStreamEventType.ERROR]: CliErrorEvent["payload"];
|
|
253
|
+
[CliStreamEventType.DONE]: CliDoneEvent["payload"];
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Create a validated CLI stream event.
|
|
257
|
+
* Validates the payload against the Zod schema before returning.
|
|
258
|
+
*/
|
|
259
|
+
export declare function createCliStreamEvent<T extends CliStreamEventType>(type: T, sessionId: string, payload: CliStreamPayloadMap[T]): CliStreamEvent;
|
|
260
|
+
/**
|
|
261
|
+
* Parse and validate an unknown value as a CliStreamEvent.
|
|
262
|
+
* Returns `{ success: true, data }` or `{ success: false, error }`.
|
|
263
|
+
*/
|
|
264
|
+
export declare function parseCliStreamEvent(value: unknown): {
|
|
265
|
+
success: boolean;
|
|
266
|
+
data?: CliStreamEvent;
|
|
267
|
+
error?: unknown;
|
|
268
|
+
};
|
|
269
|
+
export {};
|
|
270
|
+
//# sourceM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kBAAkB,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;CACpD,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,kBAAkB,EAC/D,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAC9B,cAAc,CAQhB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG;IACnD,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAMA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Active file context — path and optional language identifier.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ActiveFileContextSchema: z.ZodObject<{
|
|
6
|
+
filePath: z.ZodString;
|
|
7
|
+
languageId: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export type ActiveFileContext = z.infer<typeof ActiveFileContextSchema>;
|
|
10
|
+
/**
|
|
11
|
+
* Text selection within a file.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SelectionContextSchema: z.ZodObject<{
|
|
14
|
+
filePath: z.ZodString;
|
|
15
|
+
languageId: z.ZodOptional<z.ZodString>;
|
|
16
|
+
startLine: z.ZodNumber;
|
|
17
|
+
startColumn: z.ZodNumber;
|
|
18
|
+
endLine: z.ZodNumber;
|
|
19
|
+
endColumn: z.ZodNumber;
|
|
20
|
+
text: z.ZodString;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export type SelectionContext = z.infer<typeof SelectionContextSchema>;
|
|
23
|
+
/**
|
|
24
|
+
* Workspace context — root path of the current workspace.
|
|
25
|
+
*/
|
|
26
|
+
export declare const WorkspaceContextSchema: z.ZodObject<{
|
|
27
|
+
rootPath: z.ZodString;
|
|
28
|
+
name: z.ZodOptional<z.ZodString>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type WorkspaceContext = z.infer<typeof WorkspaceContextSchema>;
|
|
31
|
+
/**
|
|
32
|
+
* Composite context payload attached to prompt submissions.
|
|
33
|
+
* All fields are optional since context availability varies by command.
|
|
34
|
+
*/
|
|
35
|
+
export declare const ContextPayloadSchema: z.ZodObject<{
|
|
36
|
+
workspace: z.ZodOptional<z.ZodObject<{
|
|
37
|
+
rootPath: z.ZodString;
|
|
38
|
+
name: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strip>>;
|
|
40
|
+
activeFile: z.ZodOptional<z.ZodObject<{
|
|
41
|
+
filePath: z.ZodString;
|
|
42
|
+
languageId: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$strip>>;
|
|
44
|
+
selection: z.ZodOptional<z.ZodObject<{
|
|
45
|
+
filePath: z.ZodString;
|
|
46
|
+
languageId: z.ZodOptional<z.ZodString>;
|
|
47
|
+
startLine: z.ZodNumber;
|
|
48
|
+
startColumn: z.ZodNumber;
|
|
49
|
+
endLine: z.ZodNumber;
|
|
50
|
+
endColumn: z.ZodNumber;
|
|
51
|
+
text: z.ZodString;
|
|
52
|
+
}, z.core.$strip>>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
export type ContextPayload = z.infer<typeof ContextPayloadSchema>;
|
|
55
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/protocol/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;iBAGlC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;iBAQjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;iBAGjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;iBAI/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Current protocol version. Increment on breaking changes. */
|
|
3
|
+
export declare const PROTOCOL_VERSION: 1;
|
|
4
|
+
export declare const ProtocolVersionSchema: z.ZodLiteral<1>;
|
|
5
|
+
/**
|
|
6
|
+
* Base envelope wrapping all host↔webview messages.
|
|
7
|
+
* Every message includes `protocol` for forward compatibility.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ProtocolEnvelopeSchema: z.ZodObject<{
|
|
10
|
+
protocol: z.ZodLiteral<1>;
|
|
11
|
+
type: z.ZodString;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export type ProtocolEnvelope = z.infer<typeof ProtocolEnvelopeSchema>;
|
|
14
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/protocol/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,+DAA+D;AAC/D,eAAO,MAAM,gBAAgB,EAAG,CAAU,CAAC;AAE3C,eAAO,MAAM,qBAAqB,iBAA8B,CAAC;AAMjE;;;GAGG;AACH,eAAO,MAAM,sBAAsB;;;iBAGjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const ProtocolErrorCode: {
|
|
3
|
+
readonly CLI_NOT_FOUND: "CLI_NOT_FOUND";
|
|
4
|
+
readonly AUTH_EXPIRED: "AUTH_EXPIRED";
|
|
5
|
+
readonly NETWORK_TIMEOUT: "NETWORK_TIMEOUT";
|
|
6
|
+
readonly CONTEXT_LIMIT: "CONTEXT_LIMIT";
|
|
7
|
+
readonly MALFORMED_EVENT: "MALFORMED_EVENT";
|
|
8
|
+
readonly PROCESS_CRASHED: "PROCESS_CRASHED";
|
|
9
|
+
readonly SESSION_NOT_FOUND: "SESSION_NOT_FOUND";
|
|
10
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
11
|
+
};
|
|
12
|
+
export type ProtocolErrorCode = (typeof ProtocolErrorCode)[keyof typeof ProtocolErrorCode];
|
|
13
|
+
export declare const ProtocolErrorCodeSchema: z.ZodEnum<{
|
|
14
|
+
readonly CLI_NOT_FOUND: "CLI_NOT_FOUND";
|
|
15
|
+
readonly AUTH_EXPIRED: "AUTH_EXPIRED";
|
|
16
|
+
readonly NETWORK_TIMEOUT: "NETWORK_TIMEOUT";
|
|
17
|
+
readonly CONTEXT_LIMIT: "CONTEXT_LIMIT";
|
|
18
|
+
readonly MALFORMED_EVENT: "MALFORMED_EVENT";
|
|
19
|
+
readonly PROCESS_CRASHED: "PROCESS_CRASHED";
|
|
20
|
+
readonly SESSION_NOT_FOUND: "SESSION_NOT_FOUND";
|
|
21
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Structured error payload for protocol error events.
|
|
25
|
+
* Mirrors the pattern from common.ts ErrorResponseSchema but scoped
|
|
26
|
+
* to host↔webview protocol.
|
|
27
|
+
*/
|
|
28
|
+
export declare const ProtocolErrorSchema: z.ZodObject<{
|
|
29
|
+
code: z.ZodEnum<{
|
|
30
|
+
readonly CLI_NOT_FOUND: "CLI_NOT_FOUND";
|
|
31
|
+
readonly AUTH_EXPIRED: "AUTH_EXPIRED";
|
|
32
|
+
readonly NETWORK_TIMEOUT: "NETWORK_TIMEOUT";
|
|
33
|
+
readonly CONTEXT_LIMIT: "CONTEXT_LIMIT";
|
|
34
|
+
readonly MALFORMED_EVENT: "MALFORMED_EVENT";
|
|
35
|
+
readonly PROCESS_CRASHED: "PROCESS_CRASHED";
|
|
36
|
+
readonly SESSION_NOT_FOUND: "SESSION_NOT_FOUND";
|
|
37
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
38
|
+
}>;
|
|
39
|
+
message: z.ZodString;
|
|
40
|
+
details: z.ZodOptional<z.ZodUnknown>;
|
|
41
|
+
recoverable: z.ZodBoolean;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
export type ProtocolError = z.infer<typeof ProtocolErrorSchema>;
|
|
44
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/protocol/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,iBAAiB;;;;;;;;;CASpB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE7D,eAAO,MAAM,uBAAuB;;;;;;;;;EAA4B,CAAC;AAMjE;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;iBAK9B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type ProtocolError, ProtocolErrorCode } from "./errors";
|
|
2
|
+
import { type ErrorEvent, type HostEvent, HostEventType } from "./host-events";
|
|
3
|
+
import { type SessionStatus, type SessionTransitionEvent } from "./session";
|
|
4
|
+
import { type UIIntent, UIIntentType } from "./ui-intents";
|
|
5
|
+
type SafeParseResult<T> = {
|
|
6
|
+
success: true;
|
|
7
|
+
data: T;
|
|
8
|
+
} | {
|
|
9
|
+
success: false;
|
|
10
|
+
error: unknown;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Parse and validate an unknown message as a UIIntent.
|
|
14
|
+
* Returns `{ success: true, data }` or `{ success: false, error }`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseUIIntent(message: unknown): SafeParseResult<UIIntent>;
|
|
17
|
+
/**
|
|
18
|
+
* Parse and validate an unknown message as a HostEvent.
|
|
19
|
+
* Returns `{ success: true, data }` or `{ success: false, error }`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseHostEvent(message: unknown): SafeParseResult<HostEvent>;
|
|
22
|
+
/** Check if a validated UIIntent is a specific type. */
|
|
23
|
+
export declare function isUIIntentType<T extends UIIntentType>(intent: UIIntent, type: T): intent is Extract<UIIntent, {
|
|
24
|
+
type: T;
|
|
25
|
+
}>;
|
|
26
|
+
/** Check if a validated HostEvent is a specific type. */
|
|
27
|
+
export declare function isHostEventType<T extends HostEventType>(event: HostEvent, type: T): event is Extract<HostEvent, {
|
|
28
|
+
type: T;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a transition is valid according to the session state machine.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isValidTransition(from: SessionStatus, event: SessionTransitionEvent): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Get the target state for a transition, or `null` if invalid.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getNextStatus(from: SessionStatus, event: SessionTransitionEvent): SessionStatus | null;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a session status is a terminal state.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isTerminalStatus(status: SessionStatus): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Create a structured protocol error.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createProtocolError(code: ProtocolErrorCode, message: string, options?: {
|
|
46
|
+
details?: unknown;
|
|
47
|
+
recoverable?: boolean;
|
|
48
|
+
}): ProtocolError;
|
|
49
|
+
/**
|
|
50
|
+
* Create a host error event from an error code and message.
|
|
51
|
+
*/
|
|
52
|
+
export declare function createErrorEvent(code: ProtocolErrorCode, message: string, options?: {
|
|
53
|
+
sessionId?: string;
|
|
54
|
+
details?: unknown;
|
|
55
|
+
recoverable?: boolean;
|
|
56
|
+
}): ErrorEvent;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/protocol/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EACL,KAAK,UAAU,EACf,KAAK,SAAS,EAEd,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAE5B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,KAAK,QAAQ,EAAkB,YAAY,EAAE,MAAM,cAAc,CAAC;AAM3E,KAAK,eAAe,CAAC,CAAC,IAClB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC1B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAMvC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,CAAC,QAAQ,CAAC,CAEzE;AAED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