@kb-labs/gateway-contracts 0.2.0

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.
@@ -0,0 +1,1645 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const UpstreamConfigSchema: z.ZodObject<{
4
+ url: z.ZodString;
5
+ prefix: z.ZodString;
6
+ /** Strip prefix before forwarding. Default: keep prefix as-is. Use "" to strip. */
7
+ rewritePrefix: z.ZodOptional<z.ZodString>;
8
+ /** Enable WebSocket proxying for this upstream. Default: false. */
9
+ websocket: z.ZodOptional<z.ZodBoolean>;
10
+ /** Paths under this prefix that are NOT proxied (handled by gateway itself). */
11
+ excludePaths: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
12
+ description: z.ZodOptional<z.ZodString>;
13
+ }, "strip", z.ZodTypeAny, {
14
+ url: string;
15
+ prefix: string;
16
+ rewritePrefix?: string | undefined;
17
+ websocket?: boolean | undefined;
18
+ excludePaths?: string[] | undefined;
19
+ description?: string | undefined;
20
+ }, {
21
+ url: string;
22
+ prefix: string;
23
+ rewritePrefix?: string | undefined;
24
+ websocket?: boolean | undefined;
25
+ excludePaths?: string[] | undefined;
26
+ description?: string | undefined;
27
+ }>;
28
+ declare const StaticTokenEntrySchema: z.ZodObject<{
29
+ hostId: z.ZodString;
30
+ namespaceId: z.ZodString;
31
+ }, "strip", z.ZodTypeAny, {
32
+ hostId: string;
33
+ namespaceId: string;
34
+ }, {
35
+ hostId: string;
36
+ namespaceId: string;
37
+ }>;
38
+ declare const GatewayConfigSchema: z.ZodObject<{
39
+ port: z.ZodDefault<z.ZodNumber>;
40
+ upstreams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
41
+ url: z.ZodString;
42
+ prefix: z.ZodString;
43
+ /** Strip prefix before forwarding. Default: keep prefix as-is. Use "" to strip. */
44
+ rewritePrefix: z.ZodOptional<z.ZodString>;
45
+ /** Enable WebSocket proxying for this upstream. Default: false. */
46
+ websocket: z.ZodOptional<z.ZodBoolean>;
47
+ /** Paths under this prefix that are NOT proxied (handled by gateway itself). */
48
+ excludePaths: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
49
+ description: z.ZodOptional<z.ZodString>;
50
+ }, "strip", z.ZodTypeAny, {
51
+ url: string;
52
+ prefix: string;
53
+ rewritePrefix?: string | undefined;
54
+ websocket?: boolean | undefined;
55
+ excludePaths?: string[] | undefined;
56
+ description?: string | undefined;
57
+ }, {
58
+ url: string;
59
+ prefix: string;
60
+ rewritePrefix?: string | undefined;
61
+ websocket?: boolean | undefined;
62
+ excludePaths?: string[] | undefined;
63
+ description?: string | undefined;
64
+ }>>>;
65
+ /** Static tokens seeded into ICache at bootstrap — for dev/service tokens before full auth */
66
+ staticTokens: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
67
+ hostId: z.ZodString;
68
+ namespaceId: z.ZodString;
69
+ }, "strip", z.ZodTypeAny, {
70
+ hostId: string;
71
+ namespaceId: string;
72
+ }, {
73
+ hostId: string;
74
+ namespaceId: string;
75
+ }>>>;
76
+ }, "strip", z.ZodTypeAny, {
77
+ port: number;
78
+ upstreams: Record<string, {
79
+ url: string;
80
+ prefix: string;
81
+ rewritePrefix?: string | undefined;
82
+ websocket?: boolean | undefined;
83
+ excludePaths?: string[] | undefined;
84
+ description?: string | undefined;
85
+ }>;
86
+ staticTokens: Record<string, {
87
+ hostId: string;
88
+ namespaceId: string;
89
+ }>;
90
+ }, {
91
+ port?: number | undefined;
92
+ upstreams?: Record<string, {
93
+ url: string;
94
+ prefix: string;
95
+ rewritePrefix?: string | undefined;
96
+ websocket?: boolean | undefined;
97
+ excludePaths?: string[] | undefined;
98
+ description?: string | undefined;
99
+ }> | undefined;
100
+ staticTokens?: Record<string, {
101
+ hostId: string;
102
+ namespaceId: string;
103
+ }> | undefined;
104
+ }>;
105
+ type UpstreamConfig = z.infer<typeof UpstreamConfigSchema>;
106
+ type GatewayConfig = z.infer<typeof GatewayConfigSchema>;
107
+
108
+ declare const HostCapabilitySchema: z.ZodEnum<["filesystem", "git", "editor-context", "execution"]>;
109
+ declare const HostTypeSchema: z.ZodEnum<["local", "cloud"]>;
110
+ declare const HostRegistrationSchema: z.ZodObject<{
111
+ name: z.ZodString;
112
+ namespaceId: z.ZodString;
113
+ capabilities: z.ZodArray<z.ZodEnum<["filesystem", "git", "editor-context", "execution"]>, "many">;
114
+ workspacePaths: z.ZodArray<z.ZodString, "many">;
115
+ hostType: z.ZodOptional<z.ZodEnum<["local", "cloud"]>>;
116
+ }, "strip", z.ZodTypeAny, {
117
+ namespaceId: string;
118
+ capabilities: ("filesystem" | "git" | "editor-context" | "execution")[];
119
+ name: string;
120
+ workspacePaths: string[];
121
+ hostType?: "local" | "cloud" | undefined;
122
+ }, {
123
+ namespaceId: string;
124
+ capabilities: ("filesystem" | "git" | "editor-context" | "execution")[];
125
+ name: string;
126
+ workspacePaths: string[];
127
+ hostType?: "local" | "cloud" | undefined;
128
+ }>;
129
+ declare const HostStatusSchema: z.ZodEnum<["online", "offline", "degraded", "reconnecting"]>;
130
+ declare const HostDescriptorSchema: z.ZodObject<{
131
+ hostId: z.ZodString;
132
+ name: z.ZodString;
133
+ namespaceId: z.ZodString;
134
+ capabilities: z.ZodArray<z.ZodEnum<["filesystem", "git", "editor-context", "execution"]>, "many">;
135
+ status: z.ZodEnum<["online", "offline", "degraded", "reconnecting"]>;
136
+ lastSeen: z.ZodNumber;
137
+ connections: z.ZodArray<z.ZodString, "many">;
138
+ hostType: z.ZodOptional<z.ZodEnum<["local", "cloud"]>>;
139
+ workspaces: z.ZodOptional<z.ZodArray<z.ZodObject<{
140
+ workspaceId: z.ZodString;
141
+ repoFingerprint: z.ZodOptional<z.ZodString>;
142
+ branch: z.ZodOptional<z.ZodString>;
143
+ }, "strip", z.ZodTypeAny, {
144
+ workspaceId: string;
145
+ repoFingerprint?: string | undefined;
146
+ branch?: string | undefined;
147
+ }, {
148
+ workspaceId: string;
149
+ repoFingerprint?: string | undefined;
150
+ branch?: string | undefined;
151
+ }>, "many">>;
152
+ plugins: z.ZodOptional<z.ZodArray<z.ZodObject<{
153
+ id: z.ZodString;
154
+ version: z.ZodString;
155
+ }, "strip", z.ZodTypeAny, {
156
+ id: string;
157
+ version: string;
158
+ }, {
159
+ id: string;
160
+ version: string;
161
+ }>, "many">>;
162
+ createdAt: z.ZodOptional<z.ZodNumber>;
163
+ updatedAt: z.ZodOptional<z.ZodNumber>;
164
+ }, "strip", z.ZodTypeAny, {
165
+ status: "online" | "offline" | "degraded" | "reconnecting";
166
+ hostId: string;
167
+ namespaceId: string;
168
+ capabilities: ("filesystem" | "git" | "editor-context" | "execution")[];
169
+ name: string;
170
+ lastSeen: number;
171
+ connections: string[];
172
+ hostType?: "local" | "cloud" | undefined;
173
+ workspaces?: {
174
+ workspaceId: string;
175
+ repoFingerprint?: string | undefined;
176
+ branch?: string | undefined;
177
+ }[] | undefined;
178
+ plugins?: {
179
+ id: string;
180
+ version: string;
181
+ }[] | undefined;
182
+ createdAt?: number | undefined;
183
+ updatedAt?: number | undefined;
184
+ }, {
185
+ status: "online" | "offline" | "degraded" | "reconnecting";
186
+ hostId: string;
187
+ namespaceId: string;
188
+ capabilities: ("filesystem" | "git" | "editor-context" | "execution")[];
189
+ name: string;
190
+ lastSeen: number;
191
+ connections: string[];
192
+ hostType?: "local" | "cloud" | undefined;
193
+ workspaces?: {
194
+ workspaceId: string;
195
+ repoFingerprint?: string | undefined;
196
+ branch?: string | undefined;
197
+ }[] | undefined;
198
+ plugins?: {
199
+ id: string;
200
+ version: string;
201
+ }[] | undefined;
202
+ createdAt?: number | undefined;
203
+ updatedAt?: number | undefined;
204
+ }>;
205
+ declare const HostRegisterResponseSchema: z.ZodObject<{
206
+ hostId: z.ZodString;
207
+ machineToken: z.ZodString;
208
+ status: z.ZodEnum<["online", "offline", "degraded", "reconnecting"]>;
209
+ }, "strip", z.ZodTypeAny, {
210
+ status: "online" | "offline" | "degraded" | "reconnecting";
211
+ hostId: string;
212
+ machineToken: string;
213
+ }, {
214
+ status: "online" | "offline" | "degraded" | "reconnecting";
215
+ hostId: string;
216
+ machineToken: string;
217
+ }>;
218
+ type HostStatus = z.infer<typeof HostStatusSchema>;
219
+ type HostCapability = z.infer<typeof HostCapabilitySchema>;
220
+ type HostType = z.infer<typeof HostTypeSchema>;
221
+ type HostRegistration = z.infer<typeof HostRegistrationSchema>;
222
+ type HostDescriptor = z.infer<typeof HostDescriptorSchema>;
223
+ type HostRegisterResponse = z.infer<typeof HostRegisterResponseSchema>;
224
+ /**
225
+ * Durable host storage abstraction.
226
+ *
227
+ * Implementations persist host descriptors and tokens across restarts.
228
+ * The registry uses this as the "cold" layer while ICache serves as "hot" layer.
229
+ */
230
+ interface IHostStore {
231
+ /** Persist or update a host descriptor. */
232
+ save(descriptor: HostDescriptor): Promise<void>;
233
+ /** Retrieve a host by id + namespace. */
234
+ get(hostId: string, namespaceId: string): Promise<HostDescriptor | null>;
235
+ /** List all hosts in a namespace. */
236
+ list(namespaceId: string): Promise<HostDescriptor[]>;
237
+ /** List all hosts across all namespaces. */
238
+ listAll(): Promise<HostDescriptor[]>;
239
+ /** Remove a host. Returns true if it existed. */
240
+ delete(hostId: string, namespaceId: string): Promise<boolean>;
241
+ /** Persist a machine token → host mapping. */
242
+ saveToken(token: string, hostId: string, namespaceId: string): Promise<void>;
243
+ /** Resolve a machine token to its host. */
244
+ resolveToken(token: string): Promise<{
245
+ hostId: string;
246
+ namespaceId: string;
247
+ } | null>;
248
+ /** Remove a machine token. */
249
+ deleteToken(token: string): Promise<void>;
250
+ }
251
+
252
+ declare const TokenTypeSchema: z.ZodEnum<["user", "cli", "machine"]>;
253
+ declare const AuthContextSchema: z.ZodObject<{
254
+ type: z.ZodEnum<["user", "cli", "machine"]>;
255
+ userId: z.ZodString;
256
+ namespaceId: z.ZodString;
257
+ tier: z.ZodEnum<["free", "pro", "enterprise"]>;
258
+ permissions: z.ZodArray<z.ZodString, "many">;
259
+ }, "strip", z.ZodTypeAny, {
260
+ type: "user" | "cli" | "machine";
261
+ namespaceId: string;
262
+ userId: string;
263
+ tier: "free" | "pro" | "enterprise";
264
+ permissions: string[];
265
+ }, {
266
+ type: "user" | "cli" | "machine";
267
+ namespaceId: string;
268
+ userId: string;
269
+ tier: "free" | "pro" | "enterprise";
270
+ permissions: string[];
271
+ }>;
272
+ type TokenType = z.infer<typeof TokenTypeSchema>;
273
+ type AuthContext = z.infer<typeof AuthContextSchema>;
274
+ declare const RegisterRequestSchema: z.ZodObject<{
275
+ /** Human-readable name for this agent (e.g. "MacBook Pro") */
276
+ name: z.ZodString;
277
+ namespaceId: z.ZodString;
278
+ capabilities: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
279
+ /**
280
+ * X25519 public key for E2E encryption, base64url encoded.
281
+ * Generated by the agent; the server stores it for encrypting call payloads.
282
+ */
283
+ publicKey: z.ZodOptional<z.ZodString>;
284
+ }, "strip", z.ZodTypeAny, {
285
+ namespaceId: string;
286
+ capabilities: string[];
287
+ name: string;
288
+ publicKey?: string | undefined;
289
+ }, {
290
+ namespaceId: string;
291
+ name: string;
292
+ capabilities?: string[] | undefined;
293
+ publicKey?: string | undefined;
294
+ }>;
295
+ declare const RegisterResponseSchema: z.ZodObject<{
296
+ clientId: z.ZodString;
297
+ clientSecret: z.ZodString;
298
+ hostId: z.ZodString;
299
+ }, "strip", z.ZodTypeAny, {
300
+ hostId: string;
301
+ clientId: string;
302
+ clientSecret: string;
303
+ }, {
304
+ hostId: string;
305
+ clientId: string;
306
+ clientSecret: string;
307
+ }>;
308
+ declare const TokenRequestSchema: z.ZodObject<{
309
+ clientId: z.ZodString;
310
+ clientSecret: z.ZodString;
311
+ }, "strip", z.ZodTypeAny, {
312
+ clientId: string;
313
+ clientSecret: string;
314
+ }, {
315
+ clientId: string;
316
+ clientSecret: string;
317
+ }>;
318
+ declare const TokenResponseSchema: z.ZodObject<{
319
+ accessToken: z.ZodString;
320
+ refreshToken: z.ZodString;
321
+ /** Seconds until accessToken expires */
322
+ expiresIn: z.ZodNumber;
323
+ tokenType: z.ZodLiteral<"Bearer">;
324
+ }, "strip", z.ZodTypeAny, {
325
+ accessToken: string;
326
+ refreshToken: string;
327
+ expiresIn: number;
328
+ tokenType: "Bearer";
329
+ }, {
330
+ accessToken: string;
331
+ refreshToken: string;
332
+ expiresIn: number;
333
+ tokenType: "Bearer";
334
+ }>;
335
+ declare const RefreshRequestSchema: z.ZodObject<{
336
+ refreshToken: z.ZodString;
337
+ }, "strip", z.ZodTypeAny, {
338
+ refreshToken: string;
339
+ }, {
340
+ refreshToken: string;
341
+ }>;
342
+ /** JWT payload (sub = hostId) */
343
+ declare const JwtPayloadSchema: z.ZodObject<{
344
+ sub: z.ZodString;
345
+ namespaceId: z.ZodString;
346
+ tier: z.ZodEnum<["free", "pro", "enterprise"]>;
347
+ type: z.ZodEnum<["user", "cli", "machine"]>;
348
+ iat: z.ZodNumber;
349
+ exp: z.ZodNumber;
350
+ }, "strip", z.ZodTypeAny, {
351
+ type: "user" | "cli" | "machine";
352
+ namespaceId: string;
353
+ tier: "free" | "pro" | "enterprise";
354
+ sub: string;
355
+ iat: number;
356
+ exp: number;
357
+ }, {
358
+ type: "user" | "cli" | "machine";
359
+ namespaceId: string;
360
+ tier: "free" | "pro" | "enterprise";
361
+ sub: string;
362
+ iat: number;
363
+ exp: number;
364
+ }>;
365
+ type RegisterRequest = z.infer<typeof RegisterRequestSchema>;
366
+ type RegisterResponse = z.infer<typeof RegisterResponseSchema>;
367
+ type TokenRequest = z.infer<typeof TokenRequestSchema>;
368
+ type TokenResponse = z.infer<typeof TokenResponseSchema>;
369
+ type RefreshRequest = z.infer<typeof RefreshRequestSchema>;
370
+ type JwtPayload = z.infer<typeof JwtPayloadSchema>;
371
+
372
+ declare const TraceContextSchema: z.ZodObject<{
373
+ traceId: z.ZodString;
374
+ spanId: z.ZodString;
375
+ parentId: z.ZodOptional<z.ZodString>;
376
+ }, "strip", z.ZodTypeAny, {
377
+ traceId: string;
378
+ spanId: string;
379
+ parentId?: string | undefined;
380
+ }, {
381
+ traceId: string;
382
+ spanId: string;
383
+ parentId?: string | undefined;
384
+ }>;
385
+ declare const WorkspaceInfoSchema: z.ZodObject<{
386
+ workspaceId: z.ZodString;
387
+ repoFingerprint: z.ZodOptional<z.ZodString>;
388
+ branch: z.ZodOptional<z.ZodString>;
389
+ }, "strip", z.ZodTypeAny, {
390
+ workspaceId: string;
391
+ repoFingerprint?: string | undefined;
392
+ branch?: string | undefined;
393
+ }, {
394
+ workspaceId: string;
395
+ repoFingerprint?: string | undefined;
396
+ branch?: string | undefined;
397
+ }>;
398
+ declare const PluginInfoSchema: z.ZodObject<{
399
+ id: z.ZodString;
400
+ version: z.ZodString;
401
+ }, "strip", z.ZodTypeAny, {
402
+ id: string;
403
+ version: string;
404
+ }, {
405
+ id: string;
406
+ version: string;
407
+ }>;
408
+ declare const HelloMessageSchema: z.ZodObject<{
409
+ type: z.ZodLiteral<"hello">;
410
+ protocolVersion: z.ZodString;
411
+ agentVersion: z.ZodString;
412
+ hostId: z.ZodOptional<z.ZodString>;
413
+ capabilities: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
414
+ hostType: z.ZodOptional<z.ZodEnum<["local", "cloud"]>>;
415
+ workspaces: z.ZodOptional<z.ZodArray<z.ZodObject<{
416
+ workspaceId: z.ZodString;
417
+ repoFingerprint: z.ZodOptional<z.ZodString>;
418
+ branch: z.ZodOptional<z.ZodString>;
419
+ }, "strip", z.ZodTypeAny, {
420
+ workspaceId: string;
421
+ repoFingerprint?: string | undefined;
422
+ branch?: string | undefined;
423
+ }, {
424
+ workspaceId: string;
425
+ repoFingerprint?: string | undefined;
426
+ branch?: string | undefined;
427
+ }>, "many">>;
428
+ plugins: z.ZodOptional<z.ZodArray<z.ZodObject<{
429
+ id: z.ZodString;
430
+ version: z.ZodString;
431
+ }, "strip", z.ZodTypeAny, {
432
+ id: string;
433
+ version: string;
434
+ }, {
435
+ id: string;
436
+ version: string;
437
+ }>, "many">>;
438
+ }, "strip", z.ZodTypeAny, {
439
+ type: "hello";
440
+ protocolVersion: string;
441
+ agentVersion: string;
442
+ hostId?: string | undefined;
443
+ capabilities?: string[] | undefined;
444
+ hostType?: "local" | "cloud" | undefined;
445
+ workspaces?: {
446
+ workspaceId: string;
447
+ repoFingerprint?: string | undefined;
448
+ branch?: string | undefined;
449
+ }[] | undefined;
450
+ plugins?: {
451
+ id: string;
452
+ version: string;
453
+ }[] | undefined;
454
+ }, {
455
+ type: "hello";
456
+ protocolVersion: string;
457
+ agentVersion: string;
458
+ hostId?: string | undefined;
459
+ capabilities?: string[] | undefined;
460
+ hostType?: "local" | "cloud" | undefined;
461
+ workspaces?: {
462
+ workspaceId: string;
463
+ repoFingerprint?: string | undefined;
464
+ branch?: string | undefined;
465
+ }[] | undefined;
466
+ plugins?: {
467
+ id: string;
468
+ version: string;
469
+ }[] | undefined;
470
+ }>;
471
+ declare const ConnectedMessageSchema: z.ZodObject<{
472
+ type: z.ZodLiteral<"connected">;
473
+ protocolVersion: z.ZodString;
474
+ hostId: z.ZodString;
475
+ sessionId: z.ZodString;
476
+ }, "strip", z.ZodTypeAny, {
477
+ type: "connected";
478
+ hostId: string;
479
+ protocolVersion: string;
480
+ sessionId: string;
481
+ }, {
482
+ type: "connected";
483
+ hostId: string;
484
+ protocolVersion: string;
485
+ sessionId: string;
486
+ }>;
487
+ declare const NegotiateMessageSchema: z.ZodObject<{
488
+ type: z.ZodLiteral<"negotiate">;
489
+ supportedVersions: z.ZodArray<z.ZodString, "many">;
490
+ }, "strip", z.ZodTypeAny, {
491
+ type: "negotiate";
492
+ supportedVersions: string[];
493
+ }, {
494
+ type: "negotiate";
495
+ supportedVersions: string[];
496
+ }>;
497
+ declare const CallMessageSchema: z.ZodObject<{
498
+ type: z.ZodLiteral<"call">;
499
+ requestId: z.ZodString;
500
+ adapter: z.ZodString;
501
+ method: z.ZodString;
502
+ args: z.ZodArray<z.ZodUnknown, "many">;
503
+ bulk: z.ZodOptional<z.ZodBoolean>;
504
+ trace: z.ZodObject<{
505
+ traceId: z.ZodString;
506
+ spanId: z.ZodString;
507
+ parentId: z.ZodOptional<z.ZodString>;
508
+ }, "strip", z.ZodTypeAny, {
509
+ traceId: string;
510
+ spanId: string;
511
+ parentId?: string | undefined;
512
+ }, {
513
+ traceId: string;
514
+ spanId: string;
515
+ parentId?: string | undefined;
516
+ }>;
517
+ }, "strip", z.ZodTypeAny, {
518
+ type: "call";
519
+ requestId: string;
520
+ adapter: string;
521
+ method: string;
522
+ args: unknown[];
523
+ trace: {
524
+ traceId: string;
525
+ spanId: string;
526
+ parentId?: string | undefined;
527
+ };
528
+ bulk?: boolean | undefined;
529
+ }, {
530
+ type: "call";
531
+ requestId: string;
532
+ adapter: string;
533
+ method: string;
534
+ args: unknown[];
535
+ trace: {
536
+ traceId: string;
537
+ spanId: string;
538
+ parentId?: string | undefined;
539
+ };
540
+ bulk?: boolean | undefined;
541
+ }>;
542
+ declare const BulkRedirectMessageSchema: z.ZodObject<{
543
+ type: z.ZodLiteral<"bulk-redirect">;
544
+ requestId: z.ZodString;
545
+ uploadUrl: z.ZodString;
546
+ expiresAt: z.ZodNumber;
547
+ }, "strip", z.ZodTypeAny, {
548
+ type: "bulk-redirect";
549
+ requestId: string;
550
+ uploadUrl: string;
551
+ expiresAt: number;
552
+ }, {
553
+ type: "bulk-redirect";
554
+ requestId: string;
555
+ uploadUrl: string;
556
+ expiresAt: number;
557
+ }>;
558
+ declare const ChunkMessageSchema: z.ZodObject<{
559
+ type: z.ZodLiteral<"chunk">;
560
+ requestId: z.ZodString;
561
+ data: z.ZodUnknown;
562
+ index: z.ZodNumber;
563
+ }, "strip", z.ZodTypeAny, {
564
+ type: "chunk";
565
+ requestId: string;
566
+ index: number;
567
+ data?: unknown;
568
+ }, {
569
+ type: "chunk";
570
+ requestId: string;
571
+ index: number;
572
+ data?: unknown;
573
+ }>;
574
+ declare const ResultMessageSchema: z.ZodObject<{
575
+ type: z.ZodLiteral<"result">;
576
+ requestId: z.ZodString;
577
+ done: z.ZodLiteral<true>;
578
+ trace: z.ZodOptional<z.ZodObject<{
579
+ traceId: z.ZodString;
580
+ spanId: z.ZodString;
581
+ parentId: z.ZodOptional<z.ZodString>;
582
+ }, "strip", z.ZodTypeAny, {
583
+ traceId: string;
584
+ spanId: string;
585
+ parentId?: string | undefined;
586
+ }, {
587
+ traceId: string;
588
+ spanId: string;
589
+ parentId?: string | undefined;
590
+ }>>;
591
+ }, "strip", z.ZodTypeAny, {
592
+ type: "result";
593
+ requestId: string;
594
+ done: true;
595
+ trace?: {
596
+ traceId: string;
597
+ spanId: string;
598
+ parentId?: string | undefined;
599
+ } | undefined;
600
+ }, {
601
+ type: "result";
602
+ requestId: string;
603
+ done: true;
604
+ trace?: {
605
+ traceId: string;
606
+ spanId: string;
607
+ parentId?: string | undefined;
608
+ } | undefined;
609
+ }>;
610
+ declare const ErrorMessageSchema: z.ZodObject<{
611
+ type: z.ZodLiteral<"error">;
612
+ requestId: z.ZodString;
613
+ error: z.ZodObject<{
614
+ code: z.ZodString;
615
+ message: z.ZodString;
616
+ retryable: z.ZodBoolean;
617
+ }, "strip", z.ZodTypeAny, {
618
+ code: string;
619
+ message: string;
620
+ retryable: boolean;
621
+ }, {
622
+ code: string;
623
+ message: string;
624
+ retryable: boolean;
625
+ }>;
626
+ }, "strip", z.ZodTypeAny, {
627
+ type: "error";
628
+ requestId: string;
629
+ error: {
630
+ code: string;
631
+ message: string;
632
+ retryable: boolean;
633
+ };
634
+ }, {
635
+ type: "error";
636
+ requestId: string;
637
+ error: {
638
+ code: string;
639
+ message: string;
640
+ retryable: boolean;
641
+ };
642
+ }>;
643
+ declare const HeartbeatMessageSchema: z.ZodObject<{
644
+ type: z.ZodLiteral<"heartbeat">;
645
+ }, "strip", z.ZodTypeAny, {
646
+ type: "heartbeat";
647
+ }, {
648
+ type: "heartbeat";
649
+ }>;
650
+ declare const AckMessageSchema: z.ZodObject<{
651
+ type: z.ZodLiteral<"ack">;
652
+ }, "strip", z.ZodTypeAny, {
653
+ type: "ack";
654
+ }, {
655
+ type: "ack";
656
+ }>;
657
+ declare const ExecutionOutputSchema: z.ZodObject<{
658
+ type: z.ZodLiteral<"execution:output">;
659
+ requestId: z.ZodString;
660
+ executionId: z.ZodString;
661
+ stream: z.ZodEnum<["stdout", "stderr"]>;
662
+ data: z.ZodString;
663
+ timestamp: z.ZodNumber;
664
+ }, "strip", z.ZodTypeAny, {
665
+ type: "execution:output";
666
+ requestId: string;
667
+ data: string;
668
+ executionId: string;
669
+ stream: "stdout" | "stderr";
670
+ timestamp: number;
671
+ }, {
672
+ type: "execution:output";
673
+ requestId: string;
674
+ data: string;
675
+ executionId: string;
676
+ stream: "stdout" | "stderr";
677
+ timestamp: number;
678
+ }>;
679
+ declare const ExecutionProgressSchema: z.ZodObject<{
680
+ type: z.ZodLiteral<"execution:progress">;
681
+ requestId: z.ZodString;
682
+ executionId: z.ZodString;
683
+ step: z.ZodNumber;
684
+ total: z.ZodNumber;
685
+ label: z.ZodString;
686
+ timestamp: z.ZodNumber;
687
+ }, "strip", z.ZodTypeAny, {
688
+ type: "execution:progress";
689
+ requestId: string;
690
+ executionId: string;
691
+ timestamp: number;
692
+ step: number;
693
+ total: number;
694
+ label: string;
695
+ }, {
696
+ type: "execution:progress";
697
+ requestId: string;
698
+ executionId: string;
699
+ timestamp: number;
700
+ step: number;
701
+ total: number;
702
+ label: string;
703
+ }>;
704
+ declare const ExecutionArtifactSchema: z.ZodObject<{
705
+ type: z.ZodLiteral<"execution:artifact">;
706
+ requestId: z.ZodString;
707
+ executionId: z.ZodString;
708
+ name: z.ZodString;
709
+ mime: z.ZodString;
710
+ url: z.ZodString;
711
+ sizeBytes: z.ZodOptional<z.ZodNumber>;
712
+ }, "strip", z.ZodTypeAny, {
713
+ url: string;
714
+ type: "execution:artifact";
715
+ requestId: string;
716
+ executionId: string;
717
+ name: string;
718
+ mime: string;
719
+ sizeBytes?: number | undefined;
720
+ }, {
721
+ url: string;
722
+ type: "execution:artifact";
723
+ requestId: string;
724
+ executionId: string;
725
+ name: string;
726
+ mime: string;
727
+ sizeBytes?: number | undefined;
728
+ }>;
729
+ declare const ExecutionErrorEventSchema: z.ZodObject<{
730
+ type: z.ZodLiteral<"execution:error">;
731
+ requestId: z.ZodString;
732
+ executionId: z.ZodString;
733
+ code: z.ZodString;
734
+ message: z.ZodString;
735
+ retryable: z.ZodBoolean;
736
+ attempt: z.ZodOptional<z.ZodNumber>;
737
+ maxAttempts: z.ZodOptional<z.ZodNumber>;
738
+ }, "strip", z.ZodTypeAny, {
739
+ code: string;
740
+ message: string;
741
+ type: "execution:error";
742
+ requestId: string;
743
+ retryable: boolean;
744
+ executionId: string;
745
+ attempt?: number | undefined;
746
+ maxAttempts?: number | undefined;
747
+ }, {
748
+ code: string;
749
+ message: string;
750
+ type: "execution:error";
751
+ requestId: string;
752
+ retryable: boolean;
753
+ executionId: string;
754
+ attempt?: number | undefined;
755
+ maxAttempts?: number | undefined;
756
+ }>;
757
+ declare const ExecutionDoneSchema: z.ZodObject<{
758
+ type: z.ZodLiteral<"execution:done">;
759
+ requestId: z.ZodString;
760
+ executionId: z.ZodString;
761
+ exitCode: z.ZodNumber;
762
+ durationMs: z.ZodNumber;
763
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
764
+ }, "strip", z.ZodTypeAny, {
765
+ type: "execution:done";
766
+ requestId: string;
767
+ executionId: string;
768
+ exitCode: number;
769
+ durationMs: number;
770
+ metadata?: Record<string, unknown> | undefined;
771
+ }, {
772
+ type: "execution:done";
773
+ requestId: string;
774
+ executionId: string;
775
+ exitCode: number;
776
+ durationMs: number;
777
+ metadata?: Record<string, unknown> | undefined;
778
+ }>;
779
+ declare const ExecutionRetrySchema: z.ZodObject<{
780
+ type: z.ZodLiteral<"execution:retry">;
781
+ requestId: z.ZodString;
782
+ executionId: z.ZodString;
783
+ attempt: z.ZodNumber;
784
+ maxAttempts: z.ZodNumber;
785
+ delayMs: z.ZodNumber;
786
+ error: z.ZodString;
787
+ }, "strip", z.ZodTypeAny, {
788
+ type: "execution:retry";
789
+ requestId: string;
790
+ error: string;
791
+ executionId: string;
792
+ attempt: number;
793
+ maxAttempts: number;
794
+ delayMs: number;
795
+ }, {
796
+ type: "execution:retry";
797
+ requestId: string;
798
+ error: string;
799
+ executionId: string;
800
+ attempt: number;
801
+ maxAttempts: number;
802
+ delayMs: number;
803
+ }>;
804
+ declare const ExecutionCancelledSchema: z.ZodObject<{
805
+ type: z.ZodLiteral<"execution:cancelled">;
806
+ requestId: z.ZodString;
807
+ executionId: z.ZodString;
808
+ reason: z.ZodEnum<["user", "timeout", "disconnect", "system"]>;
809
+ durationMs: z.ZodNumber;
810
+ }, "strip", z.ZodTypeAny, {
811
+ type: "execution:cancelled";
812
+ requestId: string;
813
+ executionId: string;
814
+ durationMs: number;
815
+ reason: "user" | "timeout" | "disconnect" | "system";
816
+ }, {
817
+ type: "execution:cancelled";
818
+ requestId: string;
819
+ executionId: string;
820
+ durationMs: number;
821
+ reason: "user" | "timeout" | "disconnect" | "system";
822
+ }>;
823
+ declare const CancelMessageSchema: z.ZodObject<{
824
+ type: z.ZodLiteral<"cancel">;
825
+ requestId: z.ZodString;
826
+ reason: z.ZodOptional<z.ZodEnum<["user", "timeout", "disconnect"]>>;
827
+ }, "strip", z.ZodTypeAny, {
828
+ type: "cancel";
829
+ requestId: string;
830
+ reason?: "user" | "timeout" | "disconnect" | undefined;
831
+ }, {
832
+ type: "cancel";
833
+ requestId: string;
834
+ reason?: "user" | "timeout" | "disconnect" | undefined;
835
+ }>;
836
+ declare const SubscribeMessageSchema: z.ZodObject<{
837
+ type: z.ZodLiteral<"subscribe">;
838
+ executionId: z.ZodString;
839
+ }, "strip", z.ZodTypeAny, {
840
+ type: "subscribe";
841
+ executionId: string;
842
+ }, {
843
+ type: "subscribe";
844
+ executionId: string;
845
+ }>;
846
+ declare const UnsubscribeMessageSchema: z.ZodObject<{
847
+ type: z.ZodLiteral<"unsubscribe">;
848
+ executionId: z.ZodString;
849
+ }, "strip", z.ZodTypeAny, {
850
+ type: "unsubscribe";
851
+ executionId: string;
852
+ }, {
853
+ type: "unsubscribe";
854
+ executionId: string;
855
+ }>;
856
+ /** Serialized error for adapter:error messages */
857
+ declare const SerializedErrorSchema: z.ZodObject<{
858
+ code: z.ZodString;
859
+ message: z.ZodString;
860
+ retryable: z.ZodBoolean;
861
+ details: z.ZodOptional<z.ZodUnknown>;
862
+ }, "strip", z.ZodTypeAny, {
863
+ code: string;
864
+ message: string;
865
+ retryable: boolean;
866
+ details?: unknown;
867
+ }, {
868
+ code: string;
869
+ message: string;
870
+ retryable: boolean;
871
+ details?: unknown;
872
+ }>;
873
+ /** Adapter call context — propagated from host to platform */
874
+ declare const AdapterCallContextSchema: z.ZodObject<{
875
+ namespaceId: z.ZodString;
876
+ hostId: z.ZodString;
877
+ workspaceId: z.ZodOptional<z.ZodString>;
878
+ environmentId: z.ZodOptional<z.ZodString>;
879
+ executionRequestId: z.ZodOptional<z.ZodString>;
880
+ }, "strip", z.ZodTypeAny, {
881
+ hostId: string;
882
+ namespaceId: string;
883
+ workspaceId?: string | undefined;
884
+ environmentId?: string | undefined;
885
+ executionRequestId?: string | undefined;
886
+ }, {
887
+ hostId: string;
888
+ namespaceId: string;
889
+ workspaceId?: string | undefined;
890
+ environmentId?: string | undefined;
891
+ executionRequestId?: string | undefined;
892
+ }>;
893
+ /** Allowed adapter names for reverse proxy */
894
+ declare const AdapterNameSchema: z.ZodEnum<["llm", "cache", "vectorStore", "embeddings", "storage", "state"]>;
895
+ declare const AdapterCallMessageSchema: z.ZodObject<{
896
+ type: z.ZodLiteral<"adapter:call">;
897
+ requestId: z.ZodString;
898
+ adapter: z.ZodEnum<["llm", "cache", "vectorStore", "embeddings", "storage", "state"]>;
899
+ method: z.ZodString;
900
+ args: z.ZodArray<z.ZodUnknown, "many">;
901
+ timeout: z.ZodOptional<z.ZodNumber>;
902
+ context: z.ZodObject<{
903
+ namespaceId: z.ZodString;
904
+ hostId: z.ZodString;
905
+ workspaceId: z.ZodOptional<z.ZodString>;
906
+ environmentId: z.ZodOptional<z.ZodString>;
907
+ executionRequestId: z.ZodOptional<z.ZodString>;
908
+ }, "strip", z.ZodTypeAny, {
909
+ hostId: string;
910
+ namespaceId: string;
911
+ workspaceId?: string | undefined;
912
+ environmentId?: string | undefined;
913
+ executionRequestId?: string | undefined;
914
+ }, {
915
+ hostId: string;
916
+ namespaceId: string;
917
+ workspaceId?: string | undefined;
918
+ environmentId?: string | undefined;
919
+ executionRequestId?: string | undefined;
920
+ }>;
921
+ }, "strip", z.ZodTypeAny, {
922
+ type: "adapter:call";
923
+ requestId: string;
924
+ adapter: "llm" | "cache" | "vectorStore" | "embeddings" | "storage" | "state";
925
+ method: string;
926
+ args: unknown[];
927
+ context: {
928
+ hostId: string;
929
+ namespaceId: string;
930
+ workspaceId?: string | undefined;
931
+ environmentId?: string | undefined;
932
+ executionRequestId?: string | undefined;
933
+ };
934
+ timeout?: number | undefined;
935
+ }, {
936
+ type: "adapter:call";
937
+ requestId: string;
938
+ adapter: "llm" | "cache" | "vectorStore" | "embeddings" | "storage" | "state";
939
+ method: string;
940
+ args: unknown[];
941
+ context: {
942
+ hostId: string;
943
+ namespaceId: string;
944
+ workspaceId?: string | undefined;
945
+ environmentId?: string | undefined;
946
+ executionRequestId?: string | undefined;
947
+ };
948
+ timeout?: number | undefined;
949
+ }>;
950
+ declare const AdapterResponseMessageSchema: z.ZodObject<{
951
+ type: z.ZodLiteral<"adapter:response">;
952
+ requestId: z.ZodString;
953
+ result: z.ZodUnknown;
954
+ }, "strip", z.ZodTypeAny, {
955
+ type: "adapter:response";
956
+ requestId: string;
957
+ result?: unknown;
958
+ }, {
959
+ type: "adapter:response";
960
+ requestId: string;
961
+ result?: unknown;
962
+ }>;
963
+ declare const AdapterErrorMessageSchema: z.ZodObject<{
964
+ type: z.ZodLiteral<"adapter:error">;
965
+ requestId: z.ZodString;
966
+ error: z.ZodObject<{
967
+ code: z.ZodString;
968
+ message: z.ZodString;
969
+ retryable: z.ZodBoolean;
970
+ details: z.ZodOptional<z.ZodUnknown>;
971
+ }, "strip", z.ZodTypeAny, {
972
+ code: string;
973
+ message: string;
974
+ retryable: boolean;
975
+ details?: unknown;
976
+ }, {
977
+ code: string;
978
+ message: string;
979
+ retryable: boolean;
980
+ details?: unknown;
981
+ }>;
982
+ }, "strip", z.ZodTypeAny, {
983
+ type: "adapter:error";
984
+ requestId: string;
985
+ error: {
986
+ code: string;
987
+ message: string;
988
+ retryable: boolean;
989
+ details?: unknown;
990
+ };
991
+ }, {
992
+ type: "adapter:error";
993
+ requestId: string;
994
+ error: {
995
+ code: string;
996
+ message: string;
997
+ retryable: boolean;
998
+ details?: unknown;
999
+ };
1000
+ }>;
1001
+ declare const AdapterChunkMessageSchema: z.ZodObject<{
1002
+ type: z.ZodLiteral<"adapter:chunk">;
1003
+ requestId: z.ZodString;
1004
+ data: z.ZodUnknown;
1005
+ index: z.ZodNumber;
1006
+ }, "strip", z.ZodTypeAny, {
1007
+ type: "adapter:chunk";
1008
+ requestId: string;
1009
+ index: number;
1010
+ data?: unknown;
1011
+ }, {
1012
+ type: "adapter:chunk";
1013
+ requestId: string;
1014
+ index: number;
1015
+ data?: unknown;
1016
+ }>;
1017
+ declare const AdapterCancelMessageSchema: z.ZodObject<{
1018
+ type: z.ZodLiteral<"adapter:cancel">;
1019
+ requestId: z.ZodString;
1020
+ }, "strip", z.ZodTypeAny, {
1021
+ type: "adapter:cancel";
1022
+ requestId: string;
1023
+ }, {
1024
+ type: "adapter:cancel";
1025
+ requestId: string;
1026
+ }>;
1027
+ declare const ExecuteRequestSchema: z.ZodObject<{
1028
+ pluginId: z.ZodString;
1029
+ handlerRef: z.ZodString;
1030
+ exportName: z.ZodOptional<z.ZodString>;
1031
+ input: z.ZodUnknown;
1032
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
1033
+ }, "strip", z.ZodTypeAny, {
1034
+ pluginId: string;
1035
+ handlerRef: string;
1036
+ exportName?: string | undefined;
1037
+ input?: unknown;
1038
+ timeoutMs?: number | undefined;
1039
+ }, {
1040
+ pluginId: string;
1041
+ handlerRef: string;
1042
+ exportName?: string | undefined;
1043
+ input?: unknown;
1044
+ timeoutMs?: number | undefined;
1045
+ }>;
1046
+ declare const SUPPORTED_PROTOCOL_VERSIONS: readonly ["1.0"];
1047
+ type TraceContext = z.infer<typeof TraceContextSchema>;
1048
+ type HelloMessage = z.infer<typeof HelloMessageSchema>;
1049
+ type ConnectedMessage = z.infer<typeof ConnectedMessageSchema>;
1050
+ type NegotiateMessage = z.infer<typeof NegotiateMessageSchema>;
1051
+ type CallMessage = z.infer<typeof CallMessageSchema>;
1052
+ type BulkRedirectMessage = z.infer<typeof BulkRedirectMessageSchema>;
1053
+ type ChunkMessage = z.infer<typeof ChunkMessageSchema>;
1054
+ type ResultMessage = z.infer<typeof ResultMessageSchema>;
1055
+ type ErrorMessage = z.infer<typeof ErrorMessageSchema>;
1056
+ type HeartbeatMessage = z.infer<typeof HeartbeatMessageSchema>;
1057
+ type AckMessage = z.infer<typeof AckMessageSchema>;
1058
+ type ExecutionOutputMessage = z.infer<typeof ExecutionOutputSchema>;
1059
+ type ExecutionProgressMessage = z.infer<typeof ExecutionProgressSchema>;
1060
+ type ExecutionArtifactMessage = z.infer<typeof ExecutionArtifactSchema>;
1061
+ type ExecutionErrorEventMessage = z.infer<typeof ExecutionErrorEventSchema>;
1062
+ type ExecutionDoneMessage = z.infer<typeof ExecutionDoneSchema>;
1063
+ type ExecutionRetryMessage = z.infer<typeof ExecutionRetrySchema>;
1064
+ type ExecutionCancelledMessage = z.infer<typeof ExecutionCancelledSchema>;
1065
+ type CancelMessage = z.infer<typeof CancelMessageSchema>;
1066
+ type SubscribeMessage = z.infer<typeof SubscribeMessageSchema>;
1067
+ type UnsubscribeMessage = z.infer<typeof UnsubscribeMessageSchema>;
1068
+ type ExecuteRequest = z.infer<typeof ExecuteRequestSchema>;
1069
+ type WorkspaceInfo = z.infer<typeof WorkspaceInfoSchema>;
1070
+ type PluginInfo = z.infer<typeof PluginInfoSchema>;
1071
+ type SerializedError = z.infer<typeof SerializedErrorSchema>;
1072
+ type AdapterCallContext = z.infer<typeof AdapterCallContextSchema>;
1073
+ type AdapterName = z.infer<typeof AdapterNameSchema>;
1074
+ type AdapterCallMessage = z.infer<typeof AdapterCallMessageSchema>;
1075
+ type AdapterResponseMessage = z.infer<typeof AdapterResponseMessageSchema>;
1076
+ type AdapterErrorMessage = z.infer<typeof AdapterErrorMessageSchema>;
1077
+ type AdapterChunkMessage = z.infer<typeof AdapterChunkMessageSchema>;
1078
+ type AdapterCancelMessage = z.infer<typeof AdapterCancelMessageSchema>;
1079
+ type ExecutionEventMessage = ExecutionOutputMessage | ExecutionProgressMessage | ExecutionArtifactMessage | ExecutionErrorEventMessage | ExecutionDoneMessage | ExecutionRetryMessage | ExecutionCancelledMessage;
1080
+ type InboundMessage = HelloMessage | HeartbeatMessage | ChunkMessage | ResultMessage | ErrorMessage | CancelMessage | SubscribeMessage | UnsubscribeMessage | AdapterCallMessage | AdapterCancelMessage;
1081
+ type OutboundMessage = ConnectedMessage | NegotiateMessage | CallMessage | BulkRedirectMessage | AckMessage | ExecutionOutputMessage | ExecutionProgressMessage | ExecutionArtifactMessage | ExecutionErrorEventMessage | ExecutionDoneMessage | AdapterResponseMessage | AdapterErrorMessage | AdapterChunkMessage;
1082
+
1083
+ /**
1084
+ * @module gateway-contracts/client-protocol
1085
+ *
1086
+ * WS protocol for observer clients (CLI, Studio, IDE).
1087
+ * Endpoint: /clients/connect
1088
+ *
1089
+ * Separate from host-protocol (protocol.ts) — clients observe executions,
1090
+ * they don't serve adapter calls.
1091
+ *
1092
+ * Client → Gateway inbound messages:
1093
+ * - client:hello — handshake
1094
+ * - client:subscribe — subscribe to execution events
1095
+ * - client:unsubscribe
1096
+ * - client:cancel — cancel an execution (convenience, same as POST /execute/:id/cancel)
1097
+ *
1098
+ * Gateway → Client outbound messages:
1099
+ * - client:connected — handshake ack
1100
+ * - execution:output — (reused from protocol.ts ExecutionEventMessage)
1101
+ * - execution:progress
1102
+ * - execution:artifact
1103
+ * - execution:error
1104
+ * - execution:done
1105
+ * - client:error — protocol-level error (bad subscribe, not found, etc.)
1106
+ */
1107
+
1108
+ declare const ClientHelloSchema: z.ZodObject<{
1109
+ type: z.ZodLiteral<"client:hello">;
1110
+ clientVersion: z.ZodString;
1111
+ }, "strip", z.ZodTypeAny, {
1112
+ type: "client:hello";
1113
+ clientVersion: string;
1114
+ }, {
1115
+ type: "client:hello";
1116
+ clientVersion: string;
1117
+ }>;
1118
+ declare const ClientSubscribeSchema: z.ZodObject<{
1119
+ type: z.ZodLiteral<"client:subscribe">;
1120
+ executionId: z.ZodString;
1121
+ }, "strip", z.ZodTypeAny, {
1122
+ type: "client:subscribe";
1123
+ executionId: string;
1124
+ }, {
1125
+ type: "client:subscribe";
1126
+ executionId: string;
1127
+ }>;
1128
+ declare const ClientUnsubscribeSchema: z.ZodObject<{
1129
+ type: z.ZodLiteral<"client:unsubscribe">;
1130
+ executionId: z.ZodString;
1131
+ }, "strip", z.ZodTypeAny, {
1132
+ type: "client:unsubscribe";
1133
+ executionId: string;
1134
+ }, {
1135
+ type: "client:unsubscribe";
1136
+ executionId: string;
1137
+ }>;
1138
+ declare const ClientCancelSchema: z.ZodObject<{
1139
+ type: z.ZodLiteral<"client:cancel">;
1140
+ executionId: z.ZodString;
1141
+ reason: z.ZodOptional<z.ZodEnum<["user", "timeout"]>>;
1142
+ }, "strip", z.ZodTypeAny, {
1143
+ type: "client:cancel";
1144
+ executionId: string;
1145
+ reason?: "user" | "timeout" | undefined;
1146
+ }, {
1147
+ type: "client:cancel";
1148
+ executionId: string;
1149
+ reason?: "user" | "timeout" | undefined;
1150
+ }>;
1151
+ declare const ClientConnectedSchema: z.ZodObject<{
1152
+ type: z.ZodLiteral<"client:connected">;
1153
+ protocolVersion: z.ZodString;
1154
+ connectionId: z.ZodString;
1155
+ }, "strip", z.ZodTypeAny, {
1156
+ type: "client:connected";
1157
+ protocolVersion: string;
1158
+ connectionId: string;
1159
+ }, {
1160
+ type: "client:connected";
1161
+ protocolVersion: string;
1162
+ connectionId: string;
1163
+ }>;
1164
+ declare const ClientErrorSchema: z.ZodObject<{
1165
+ type: z.ZodLiteral<"client:error">;
1166
+ code: z.ZodEnum<["EXECUTION_NOT_FOUND", "FORBIDDEN", "INVALID_MESSAGE", "CANCEL_FAILED"]>;
1167
+ message: z.ZodString;
1168
+ executionId: z.ZodOptional<z.ZodString>;
1169
+ }, "strip", z.ZodTypeAny, {
1170
+ code: "EXECUTION_NOT_FOUND" | "FORBIDDEN" | "INVALID_MESSAGE" | "CANCEL_FAILED";
1171
+ message: string;
1172
+ type: "client:error";
1173
+ executionId?: string | undefined;
1174
+ }, {
1175
+ code: "EXECUTION_NOT_FOUND" | "FORBIDDEN" | "INVALID_MESSAGE" | "CANCEL_FAILED";
1176
+ message: string;
1177
+ type: "client:error";
1178
+ executionId?: string | undefined;
1179
+ }>;
1180
+ type ClientHello = z.infer<typeof ClientHelloSchema>;
1181
+ type ClientSubscribe = z.infer<typeof ClientSubscribeSchema>;
1182
+ type ClientUnsubscribe = z.infer<typeof ClientUnsubscribeSchema>;
1183
+ type ClientCancel = z.infer<typeof ClientCancelSchema>;
1184
+ type ClientConnected = z.infer<typeof ClientConnectedSchema>;
1185
+ type ClientError = z.infer<typeof ClientErrorSchema>;
1186
+ type ClientInboundMessage = ClientHello | ClientSubscribe | ClientUnsubscribe | ClientCancel;
1187
+ type ClientOutboundMessage = ClientConnected | ClientError | ExecutionEventMessage;
1188
+ declare const CLIENT_PROTOCOL_VERSION = "1.0";
1189
+
1190
+ /**
1191
+ * @module @kb-labs/gateway-contracts/llm-gateway
1192
+ * OpenAI-compatible AI Gateway schemas and types.
1193
+ *
1194
+ * Clients interact using OpenAI ChatCompletion format, but `model` field
1195
+ * is a tier abstraction (small/medium/large/fast), NOT a literal model name.
1196
+ * The platform resolves the tier to a concrete provider + model via LLMRouter config.
1197
+ */
1198
+
1199
+ /** Tier-based model selector. Clients never specify a concrete model. */
1200
+ declare const LLMTierSchema: z.ZodEnum<["small", "medium", "large"]>;
1201
+ declare const ChatMessageSchema: z.ZodObject<{
1202
+ role: z.ZodEnum<["system", "user", "assistant", "tool"]>;
1203
+ content: z.ZodString;
1204
+ tool_call_id: z.ZodOptional<z.ZodString>;
1205
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
1206
+ id: z.ZodString;
1207
+ type: z.ZodLiteral<"function">;
1208
+ function: z.ZodObject<{
1209
+ name: z.ZodString;
1210
+ arguments: z.ZodString;
1211
+ }, "strip", z.ZodTypeAny, {
1212
+ name: string;
1213
+ arguments: string;
1214
+ }, {
1215
+ name: string;
1216
+ arguments: string;
1217
+ }>;
1218
+ }, "strip", z.ZodTypeAny, {
1219
+ function: {
1220
+ name: string;
1221
+ arguments: string;
1222
+ };
1223
+ type: "function";
1224
+ id: string;
1225
+ }, {
1226
+ function: {
1227
+ name: string;
1228
+ arguments: string;
1229
+ };
1230
+ type: "function";
1231
+ id: string;
1232
+ }>, "many">>;
1233
+ }, "strip", z.ZodTypeAny, {
1234
+ role: "user" | "system" | "assistant" | "tool";
1235
+ content: string;
1236
+ tool_call_id?: string | undefined;
1237
+ tool_calls?: {
1238
+ function: {
1239
+ name: string;
1240
+ arguments: string;
1241
+ };
1242
+ type: "function";
1243
+ id: string;
1244
+ }[] | undefined;
1245
+ }, {
1246
+ role: "user" | "system" | "assistant" | "tool";
1247
+ content: string;
1248
+ tool_call_id?: string | undefined;
1249
+ tool_calls?: {
1250
+ function: {
1251
+ name: string;
1252
+ arguments: string;
1253
+ };
1254
+ type: "function";
1255
+ id: string;
1256
+ }[] | undefined;
1257
+ }>;
1258
+ declare const ChatToolSchema: z.ZodObject<{
1259
+ type: z.ZodLiteral<"function">;
1260
+ function: z.ZodObject<{
1261
+ name: z.ZodString;
1262
+ description: z.ZodOptional<z.ZodString>;
1263
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1264
+ }, "strip", z.ZodTypeAny, {
1265
+ name: string;
1266
+ description?: string | undefined;
1267
+ parameters?: Record<string, unknown> | undefined;
1268
+ }, {
1269
+ name: string;
1270
+ description?: string | undefined;
1271
+ parameters?: Record<string, unknown> | undefined;
1272
+ }>;
1273
+ }, "strip", z.ZodTypeAny, {
1274
+ function: {
1275
+ name: string;
1276
+ description?: string | undefined;
1277
+ parameters?: Record<string, unknown> | undefined;
1278
+ };
1279
+ type: "function";
1280
+ }, {
1281
+ function: {
1282
+ name: string;
1283
+ description?: string | undefined;
1284
+ parameters?: Record<string, unknown> | undefined;
1285
+ };
1286
+ type: "function";
1287
+ }>;
1288
+ declare const ChatCompletionRequestSchema: z.ZodObject<{
1289
+ /** Tier-based model selector: "small" | "medium" | "large" | "fast" */
1290
+ model: z.ZodEnum<["small", "medium", "large"]>;
1291
+ messages: z.ZodArray<z.ZodObject<{
1292
+ role: z.ZodEnum<["system", "user", "assistant", "tool"]>;
1293
+ content: z.ZodString;
1294
+ tool_call_id: z.ZodOptional<z.ZodString>;
1295
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
1296
+ id: z.ZodString;
1297
+ type: z.ZodLiteral<"function">;
1298
+ function: z.ZodObject<{
1299
+ name: z.ZodString;
1300
+ arguments: z.ZodString;
1301
+ }, "strip", z.ZodTypeAny, {
1302
+ name: string;
1303
+ arguments: string;
1304
+ }, {
1305
+ name: string;
1306
+ arguments: string;
1307
+ }>;
1308
+ }, "strip", z.ZodTypeAny, {
1309
+ function: {
1310
+ name: string;
1311
+ arguments: string;
1312
+ };
1313
+ type: "function";
1314
+ id: string;
1315
+ }, {
1316
+ function: {
1317
+ name: string;
1318
+ arguments: string;
1319
+ };
1320
+ type: "function";
1321
+ id: string;
1322
+ }>, "many">>;
1323
+ }, "strip", z.ZodTypeAny, {
1324
+ role: "user" | "system" | "assistant" | "tool";
1325
+ content: string;
1326
+ tool_call_id?: string | undefined;
1327
+ tool_calls?: {
1328
+ function: {
1329
+ name: string;
1330
+ arguments: string;
1331
+ };
1332
+ type: "function";
1333
+ id: string;
1334
+ }[] | undefined;
1335
+ }, {
1336
+ role: "user" | "system" | "assistant" | "tool";
1337
+ content: string;
1338
+ tool_call_id?: string | undefined;
1339
+ tool_calls?: {
1340
+ function: {
1341
+ name: string;
1342
+ arguments: string;
1343
+ };
1344
+ type: "function";
1345
+ id: string;
1346
+ }[] | undefined;
1347
+ }>, "many">;
1348
+ temperature: z.ZodOptional<z.ZodNumber>;
1349
+ max_tokens: z.ZodOptional<z.ZodNumber>;
1350
+ stop: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1351
+ stream: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
1352
+ tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
1353
+ type: z.ZodLiteral<"function">;
1354
+ function: z.ZodObject<{
1355
+ name: z.ZodString;
1356
+ description: z.ZodOptional<z.ZodString>;
1357
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1358
+ }, "strip", z.ZodTypeAny, {
1359
+ name: string;
1360
+ description?: string | undefined;
1361
+ parameters?: Record<string, unknown> | undefined;
1362
+ }, {
1363
+ name: string;
1364
+ description?: string | undefined;
1365
+ parameters?: Record<string, unknown> | undefined;
1366
+ }>;
1367
+ }, "strip", z.ZodTypeAny, {
1368
+ function: {
1369
+ name: string;
1370
+ description?: string | undefined;
1371
+ parameters?: Record<string, unknown> | undefined;
1372
+ };
1373
+ type: "function";
1374
+ }, {
1375
+ function: {
1376
+ name: string;
1377
+ description?: string | undefined;
1378
+ parameters?: Record<string, unknown> | undefined;
1379
+ };
1380
+ type: "function";
1381
+ }>, "many">>;
1382
+ tool_choice: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["auto", "required", "none"]>, z.ZodObject<{
1383
+ type: z.ZodLiteral<"function">;
1384
+ function: z.ZodObject<{
1385
+ name: z.ZodString;
1386
+ }, "strip", z.ZodTypeAny, {
1387
+ name: string;
1388
+ }, {
1389
+ name: string;
1390
+ }>;
1391
+ }, "strip", z.ZodTypeAny, {
1392
+ function: {
1393
+ name: string;
1394
+ };
1395
+ type: "function";
1396
+ }, {
1397
+ function: {
1398
+ name: string;
1399
+ };
1400
+ type: "function";
1401
+ }>]>>;
1402
+ }, "strip", z.ZodTypeAny, {
1403
+ stream: boolean;
1404
+ model: "small" | "medium" | "large";
1405
+ messages: {
1406
+ role: "user" | "system" | "assistant" | "tool";
1407
+ content: string;
1408
+ tool_call_id?: string | undefined;
1409
+ tool_calls?: {
1410
+ function: {
1411
+ name: string;
1412
+ arguments: string;
1413
+ };
1414
+ type: "function";
1415
+ id: string;
1416
+ }[] | undefined;
1417
+ }[];
1418
+ temperature?: number | undefined;
1419
+ max_tokens?: number | undefined;
1420
+ stop?: string | string[] | undefined;
1421
+ tools?: {
1422
+ function: {
1423
+ name: string;
1424
+ description?: string | undefined;
1425
+ parameters?: Record<string, unknown> | undefined;
1426
+ };
1427
+ type: "function";
1428
+ }[] | undefined;
1429
+ tool_choice?: "required" | "auto" | "none" | {
1430
+ function: {
1431
+ name: string;
1432
+ };
1433
+ type: "function";
1434
+ } | undefined;
1435
+ }, {
1436
+ model: "small" | "medium" | "large";
1437
+ messages: {
1438
+ role: "user" | "system" | "assistant" | "tool";
1439
+ content: string;
1440
+ tool_call_id?: string | undefined;
1441
+ tool_calls?: {
1442
+ function: {
1443
+ name: string;
1444
+ arguments: string;
1445
+ };
1446
+ type: "function";
1447
+ id: string;
1448
+ }[] | undefined;
1449
+ }[];
1450
+ stream?: boolean | undefined;
1451
+ temperature?: number | undefined;
1452
+ max_tokens?: number | undefined;
1453
+ stop?: string | string[] | undefined;
1454
+ tools?: {
1455
+ function: {
1456
+ name: string;
1457
+ description?: string | undefined;
1458
+ parameters?: Record<string, unknown> | undefined;
1459
+ };
1460
+ type: "function";
1461
+ }[] | undefined;
1462
+ tool_choice?: "required" | "auto" | "none" | {
1463
+ function: {
1464
+ name: string;
1465
+ };
1466
+ type: "function";
1467
+ } | undefined;
1468
+ }>;
1469
+ type ChatCompletionRequest = z.infer<typeof ChatCompletionRequestSchema>;
1470
+ interface ChatCompletionChoice {
1471
+ index: number;
1472
+ message: {
1473
+ role: 'assistant';
1474
+ content: string | null;
1475
+ tool_calls?: Array<{
1476
+ id: string;
1477
+ type: 'function';
1478
+ function: {
1479
+ name: string;
1480
+ arguments: string;
1481
+ };
1482
+ }>;
1483
+ };
1484
+ finish_reason: 'stop' | 'tool_calls' | 'length' | null;
1485
+ }
1486
+ interface ChatCompletionUsage {
1487
+ prompt_tokens: number;
1488
+ completion_tokens: number;
1489
+ total_tokens: number;
1490
+ }
1491
+ interface ChatCompletionResponse {
1492
+ id: string;
1493
+ object: 'chat.completion';
1494
+ created: number;
1495
+ /** Returns the tier used, not the concrete model (abstraction preserved) */
1496
+ model: string;
1497
+ choices: ChatCompletionChoice[];
1498
+ usage: ChatCompletionUsage;
1499
+ }
1500
+ interface ChatCompletionChunkDelta {
1501
+ role?: 'assistant';
1502
+ content?: string | null;
1503
+ tool_calls?: Array<{
1504
+ index: number;
1505
+ id?: string;
1506
+ type?: 'function';
1507
+ function?: {
1508
+ name?: string;
1509
+ arguments?: string;
1510
+ };
1511
+ }>;
1512
+ }
1513
+ interface ChatCompletionChunk {
1514
+ id: string;
1515
+ object: 'chat.completion.chunk';
1516
+ created: number;
1517
+ model: string;
1518
+ choices: Array<{
1519
+ index: number;
1520
+ delta: ChatCompletionChunkDelta;
1521
+ finish_reason: 'stop' | 'tool_calls' | 'length' | null;
1522
+ }>;
1523
+ }
1524
+
1525
+ /**
1526
+ * @module @kb-labs/gateway-contracts/telemetry
1527
+ * Telemetry ingestion schemas for the AI Gateway.
1528
+ *
1529
+ * External products send events through `POST /telemetry/v1/ingest`.
1530
+ * Events are written to platform analytics (SQLite/DuckDB/File) via IAnalytics.track().
1531
+ *
1532
+ * Schema is intentionally minimal — `payload` is free-form.
1533
+ * Platform provides recommended presets but does not enforce them.
1534
+ */
1535
+
1536
+ declare const TelemetryEventSchema: z.ZodObject<{
1537
+ /** Source product/service name (e.g., "my-api", "billing-service") */
1538
+ source: z.ZodString;
1539
+ /** Event type/name using dot notation (e.g., "user.signup", "api.request") */
1540
+ type: z.ZodString;
1541
+ /** ISO 8601 timestamp. Defaults to server ingest time if omitted. */
1542
+ timestamp: z.ZodOptional<z.ZodString>;
1543
+ /** Free-form event data. No schema enforced — products decide what to send. */
1544
+ payload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1545
+ /** Flat key-value tags for filtering/aggregation (e.g., { env: "prod", region: "eu" }) */
1546
+ tags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
1547
+ }, "strip", z.ZodTypeAny, {
1548
+ type: string;
1549
+ source: string;
1550
+ timestamp?: string | undefined;
1551
+ payload?: Record<string, unknown> | undefined;
1552
+ tags?: Record<string, string> | undefined;
1553
+ }, {
1554
+ type: string;
1555
+ source: string;
1556
+ timestamp?: string | undefined;
1557
+ payload?: Record<string, unknown> | undefined;
1558
+ tags?: Record<string, string> | undefined;
1559
+ }>;
1560
+ type TelemetryEvent = z.infer<typeof TelemetryEventSchema>;
1561
+ declare const TelemetryIngestRequestSchema: z.ZodObject<{
1562
+ /** Array of events to ingest (1–500 per batch) */
1563
+ events: z.ZodArray<z.ZodObject<{
1564
+ /** Source product/service name (e.g., "my-api", "billing-service") */
1565
+ source: z.ZodString;
1566
+ /** Event type/name using dot notation (e.g., "user.signup", "api.request") */
1567
+ type: z.ZodString;
1568
+ /** ISO 8601 timestamp. Defaults to server ingest time if omitted. */
1569
+ timestamp: z.ZodOptional<z.ZodString>;
1570
+ /** Free-form event data. No schema enforced — products decide what to send. */
1571
+ payload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1572
+ /** Flat key-value tags for filtering/aggregation (e.g., { env: "prod", region: "eu" }) */
1573
+ tags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
1574
+ }, "strip", z.ZodTypeAny, {
1575
+ type: string;
1576
+ source: string;
1577
+ timestamp?: string | undefined;
1578
+ payload?: Record<string, unknown> | undefined;
1579
+ tags?: Record<string, string> | undefined;
1580
+ }, {
1581
+ type: string;
1582
+ source: string;
1583
+ timestamp?: string | undefined;
1584
+ payload?: Record<string, unknown> | undefined;
1585
+ tags?: Record<string, string> | undefined;
1586
+ }>, "many">;
1587
+ }, "strip", z.ZodTypeAny, {
1588
+ events: {
1589
+ type: string;
1590
+ source: string;
1591
+ timestamp?: string | undefined;
1592
+ payload?: Record<string, unknown> | undefined;
1593
+ tags?: Record<string, string> | undefined;
1594
+ }[];
1595
+ }, {
1596
+ events: {
1597
+ type: string;
1598
+ source: string;
1599
+ timestamp?: string | undefined;
1600
+ payload?: Record<string, unknown> | undefined;
1601
+ tags?: Record<string, string> | undefined;
1602
+ }[];
1603
+ }>;
1604
+ type TelemetryIngestRequest = z.infer<typeof TelemetryIngestRequestSchema>;
1605
+ interface TelemetryIngestResponse {
1606
+ /** Number of events accepted */
1607
+ accepted: number;
1608
+ /** Number of events rejected (validation errors) */
1609
+ rejected: number;
1610
+ /** Errors for rejected events, if any */
1611
+ errors?: Array<{
1612
+ index: number;
1613
+ message: string;
1614
+ }>;
1615
+ }
1616
+
1617
+ /**
1618
+ * @module @kb-labs/gateway-contracts/platform-api
1619
+ * Unified Platform API — single dispatch endpoint for any adapter.
1620
+ *
1621
+ * Route: POST /platform/v1/{adapter}/{method}
1622
+ * Adapter and method come from URL params; args come from the request body.
1623
+ */
1624
+
1625
+ declare const PlatformCallRequestSchema: z.ZodObject<{
1626
+ /** Arguments to pass to the adapter method. Order matters. */
1627
+ args: z.ZodDefault<z.ZodArray<z.ZodUnknown, "many">>;
1628
+ }, "strip", z.ZodTypeAny, {
1629
+ args: unknown[];
1630
+ }, {
1631
+ args?: unknown[] | undefined;
1632
+ }>;
1633
+ type PlatformCallRequest = z.infer<typeof PlatformCallRequestSchema>;
1634
+ interface PlatformCallResponse {
1635
+ ok: boolean;
1636
+ result?: unknown;
1637
+ error?: {
1638
+ message: string;
1639
+ code?: string;
1640
+ };
1641
+ /** Wall-clock duration of the adapter call in milliseconds. */
1642
+ durationMs: number;
1643
+ }
1644
+
1645
+ export { type AckMessage, AckMessageSchema, type AdapterCallContext, AdapterCallContextSchema, type AdapterCallMessage, AdapterCallMessageSchema, type AdapterCancelMessage, AdapterCancelMessageSchema, type AdapterChunkMessage, AdapterChunkMessageSchema, type AdapterErrorMessage, AdapterErrorMessageSchema, type AdapterName, AdapterNameSchema, type AdapterResponseMessage, AdapterResponseMessageSchema, type AuthContext, AuthContextSchema, type BulkRedirectMessage, BulkRedirectMessageSchema, CLIENT_PROTOCOL_VERSION, type CallMessage, CallMessageSchema, type CancelMessage, CancelMessageSchema, type ChatCompletionChoice, type ChatCompletionChunk, type ChatCompletionChunkDelta, type ChatCompletionRequest, ChatCompletionRequestSchema, type ChatCompletionResponse, type ChatCompletionUsage, ChatMessageSchema, ChatToolSchema, type ChunkMessage, ChunkMessageSchema, type ClientCancel, ClientCancelSchema, type ClientConnected, ClientConnectedSchema, type ClientError, ClientErrorSchema, type ClientHello, ClientHelloSchema, type ClientInboundMessage, type ClientOutboundMessage, type ClientSubscribe, ClientSubscribeSchema, type ClientUnsubscribe, ClientUnsubscribeSchema, type ConnectedMessage, ConnectedMessageSchema, type ErrorMessage, ErrorMessageSchema, type ExecuteRequest, ExecuteRequestSchema, type ExecutionArtifactMessage, ExecutionArtifactSchema, type ExecutionCancelledMessage, ExecutionCancelledSchema, type ExecutionDoneMessage, ExecutionDoneSchema, type ExecutionErrorEventMessage, ExecutionErrorEventSchema, type ExecutionEventMessage, type ExecutionOutputMessage, ExecutionOutputSchema, type ExecutionProgressMessage, ExecutionProgressSchema, type ExecutionRetryMessage, ExecutionRetrySchema, type GatewayConfig, GatewayConfigSchema, type HeartbeatMessage, HeartbeatMessageSchema, type HelloMessage, HelloMessageSchema, type HostCapability, HostCapabilitySchema, type HostDescriptor, HostDescriptorSchema, type HostRegisterResponse, HostRegisterResponseSchema, type HostRegistration, HostRegistrationSchema, type HostStatus, HostStatusSchema, type HostType, HostTypeSchema, type IHostStore, type InboundMessage, type JwtPayload, JwtPayloadSchema, LLMTierSchema, type NegotiateMessage, NegotiateMessageSchema, type OutboundMessage, type PlatformCallRequest, PlatformCallRequestSchema, type PlatformCallResponse, type PluginInfo, PluginInfoSchema, type RefreshRequest, RefreshRequestSchema, type RegisterRequest, RegisterRequestSchema, type RegisterResponse, RegisterResponseSchema, type ResultMessage, ResultMessageSchema, SUPPORTED_PROTOCOL_VERSIONS, type SerializedError, SerializedErrorSchema, StaticTokenEntrySchema, type SubscribeMessage, SubscribeMessageSchema, type TelemetryEvent, TelemetryEventSchema, type TelemetryIngestRequest, TelemetryIngestRequestSchema, type TelemetryIngestResponse, type TokenRequest, TokenRequestSchema, type TokenResponse, TokenResponseSchema, type TokenType, TokenTypeSchema, type TraceContext, TraceContextSchema, type UnsubscribeMessage, UnsubscribeMessageSchema, type UpstreamConfig, UpstreamConfigSchema, type WorkspaceInfo, WorkspaceInfoSchema };