@glueco/shared 0.1.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,2098 @@
1
+ import { z, ZodSchema } from 'zod';
2
+
3
+ /**
4
+ * Gateway error codes.
5
+ */
6
+ declare enum ErrorCode {
7
+ ERR_RESOURCE_REQUIRED = "ERR_RESOURCE_REQUIRED",
8
+ ERR_UNKNOWN_RESOURCE = "ERR_UNKNOWN_RESOURCE",
9
+ ERR_RESOURCE_NOT_CONFIGURED = "ERR_RESOURCE_NOT_CONFIGURED",
10
+ ERR_UNSUPPORTED_ACTION = "ERR_UNSUPPORTED_ACTION",
11
+ ERR_MISSING_AUTH = "ERR_MISSING_AUTH",
12
+ ERR_INVALID_SIGNATURE = "ERR_INVALID_SIGNATURE",
13
+ ERR_EXPIRED_TIMESTAMP = "ERR_EXPIRED_TIMESTAMP",
14
+ ERR_INVALID_NONCE = "ERR_INVALID_NONCE",
15
+ ERR_APP_NOT_FOUND = "ERR_APP_NOT_FOUND",
16
+ ERR_APP_DISABLED = "ERR_APP_DISABLED",
17
+ ERR_PERMISSION_DENIED = "ERR_PERMISSION_DENIED",
18
+ ERR_PERMISSION_EXPIRED = "ERR_PERMISSION_EXPIRED",
19
+ ERR_CONSTRAINT_VIOLATION = "ERR_CONSTRAINT_VIOLATION",
20
+ ERR_RATE_LIMIT_EXCEEDED = "ERR_RATE_LIMIT_EXCEEDED",
21
+ ERR_BUDGET_EXCEEDED = "ERR_BUDGET_EXCEEDED",
22
+ ERR_INVALID_REQUEST = "ERR_INVALID_REQUEST",
23
+ ERR_INVALID_JSON = "ERR_INVALID_JSON",
24
+ ERR_CONTRACT_VALIDATION_FAILED = "ERR_CONTRACT_VALIDATION_FAILED",
25
+ ERR_INTERNAL = "ERR_INTERNAL",
26
+ ERR_UPSTREAM_ERROR = "ERR_UPSTREAM_ERROR",
27
+ ERR_INVALID_PAIRING_STRING = "ERR_INVALID_PAIRING_STRING",
28
+ ERR_INVALID_CONNECT_CODE = "ERR_INVALID_CONNECT_CODE",
29
+ ERR_SESSION_EXPIRED = "ERR_SESSION_EXPIRED",
30
+ ERR_UNSUPPORTED_POP_VERSION = "ERR_UNSUPPORTED_POP_VERSION",
31
+ ERR_POLICY_VIOLATION = "ERR_POLICY_VIOLATION",
32
+ ERR_MODEL_NOT_ALLOWED = "ERR_MODEL_NOT_ALLOWED",
33
+ ERR_MAX_TOKENS_EXCEEDED = "ERR_MAX_TOKENS_EXCEEDED",
34
+ ERR_TOOLS_NOT_ALLOWED = "ERR_TOOLS_NOT_ALLOWED",
35
+ ERR_STREAMING_NOT_ALLOWED = "ERR_STREAMING_NOT_ALLOWED"
36
+ }
37
+ /**
38
+ * Get HTTP status code for an error code.
39
+ */
40
+ declare function getErrorStatus(code: ErrorCode): number;
41
+ /**
42
+ * Gateway error class.
43
+ */
44
+ declare class GatewayError extends Error {
45
+ readonly code: ErrorCode;
46
+ readonly status: number;
47
+ readonly details?: Record<string, unknown>;
48
+ readonly requestId?: string;
49
+ constructor(code: ErrorCode, message: string, options?: {
50
+ details?: Record<string, unknown>;
51
+ requestId?: string;
52
+ });
53
+ toJSON(): {
54
+ error: {
55
+ details?: Record<string, unknown> | undefined;
56
+ requestId?: string | undefined;
57
+ code: ErrorCode;
58
+ message: string;
59
+ };
60
+ };
61
+ }
62
+ /**
63
+ * Create a resource required error with helpful message.
64
+ */
65
+ declare function resourceRequiredError(hint?: string): GatewayError;
66
+ /**
67
+ * Standard error response schema.
68
+ * All API errors should conform to this shape.
69
+ */
70
+ declare const GatewayErrorResponseSchema: z.ZodObject<{
71
+ error: z.ZodObject<{
72
+ code: z.ZodString;
73
+ message: z.ZodString;
74
+ requestId: z.ZodOptional<z.ZodString>;
75
+ details: z.ZodOptional<z.ZodUnknown>;
76
+ }, "strip", z.ZodTypeAny, {
77
+ code: string;
78
+ message: string;
79
+ details?: unknown;
80
+ requestId?: string | undefined;
81
+ }, {
82
+ code: string;
83
+ message: string;
84
+ details?: unknown;
85
+ requestId?: string | undefined;
86
+ }>;
87
+ }, "strip", z.ZodTypeAny, {
88
+ error: {
89
+ code: string;
90
+ message: string;
91
+ details?: unknown;
92
+ requestId?: string | undefined;
93
+ };
94
+ }, {
95
+ error: {
96
+ code: string;
97
+ message: string;
98
+ details?: unknown;
99
+ requestId?: string | undefined;
100
+ };
101
+ }>;
102
+ type GatewayErrorResponse = z.infer<typeof GatewayErrorResponseSchema>;
103
+ /**
104
+ * Create a standard error response object.
105
+ */
106
+ declare function createErrorResponse(code: string, message: string, options?: {
107
+ requestId?: string;
108
+ details?: unknown;
109
+ }): GatewayErrorResponse;
110
+
111
+ /**
112
+ * Chat message schema (OpenAI-compatible).
113
+ */
114
+ declare const ChatMessageSchema: z.ZodObject<{
115
+ role: z.ZodEnum<["system", "user", "assistant", "tool"]>;
116
+ content: z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodObject<{
117
+ type: z.ZodString;
118
+ text: z.ZodOptional<z.ZodString>;
119
+ image_url: z.ZodOptional<z.ZodObject<{
120
+ url: z.ZodString;
121
+ detail: z.ZodOptional<z.ZodString>;
122
+ }, "strip", z.ZodTypeAny, {
123
+ url: string;
124
+ detail?: string | undefined;
125
+ }, {
126
+ url: string;
127
+ detail?: string | undefined;
128
+ }>>;
129
+ }, "strip", z.ZodTypeAny, {
130
+ type: string;
131
+ text?: string | undefined;
132
+ image_url?: {
133
+ url: string;
134
+ detail?: string | undefined;
135
+ } | undefined;
136
+ }, {
137
+ type: string;
138
+ text?: string | undefined;
139
+ image_url?: {
140
+ url: string;
141
+ detail?: string | undefined;
142
+ } | undefined;
143
+ }>, "many">]>>;
144
+ name: z.ZodOptional<z.ZodString>;
145
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
146
+ id: z.ZodString;
147
+ type: z.ZodLiteral<"function">;
148
+ function: z.ZodObject<{
149
+ name: z.ZodString;
150
+ arguments: z.ZodString;
151
+ }, "strip", z.ZodTypeAny, {
152
+ name: string;
153
+ arguments: string;
154
+ }, {
155
+ name: string;
156
+ arguments: string;
157
+ }>;
158
+ }, "strip", z.ZodTypeAny, {
159
+ function: {
160
+ name: string;
161
+ arguments: string;
162
+ };
163
+ type: "function";
164
+ id: string;
165
+ }, {
166
+ function: {
167
+ name: string;
168
+ arguments: string;
169
+ };
170
+ type: "function";
171
+ id: string;
172
+ }>, "many">>;
173
+ tool_call_id: z.ZodOptional<z.ZodString>;
174
+ }, "strip", z.ZodTypeAny, {
175
+ role: "system" | "user" | "assistant" | "tool";
176
+ content: string | {
177
+ type: string;
178
+ text?: string | undefined;
179
+ image_url?: {
180
+ url: string;
181
+ detail?: string | undefined;
182
+ } | undefined;
183
+ }[] | null;
184
+ name?: string | undefined;
185
+ tool_calls?: {
186
+ function: {
187
+ name: string;
188
+ arguments: string;
189
+ };
190
+ type: "function";
191
+ id: string;
192
+ }[] | undefined;
193
+ tool_call_id?: string | undefined;
194
+ }, {
195
+ role: "system" | "user" | "assistant" | "tool";
196
+ content: string | {
197
+ type: string;
198
+ text?: string | undefined;
199
+ image_url?: {
200
+ url: string;
201
+ detail?: string | undefined;
202
+ } | undefined;
203
+ }[] | null;
204
+ name?: string | undefined;
205
+ tool_calls?: {
206
+ function: {
207
+ name: string;
208
+ arguments: string;
209
+ };
210
+ type: "function";
211
+ id: string;
212
+ }[] | undefined;
213
+ tool_call_id?: string | undefined;
214
+ }>;
215
+ /**
216
+ * Chat completion request schema (OpenAI-compatible).
217
+ */
218
+ declare const ChatCompletionRequestSchema: z.ZodObject<{
219
+ model: z.ZodString;
220
+ messages: z.ZodArray<z.ZodObject<{
221
+ role: z.ZodEnum<["system", "user", "assistant", "tool"]>;
222
+ content: z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodObject<{
223
+ type: z.ZodString;
224
+ text: z.ZodOptional<z.ZodString>;
225
+ image_url: z.ZodOptional<z.ZodObject<{
226
+ url: z.ZodString;
227
+ detail: z.ZodOptional<z.ZodString>;
228
+ }, "strip", z.ZodTypeAny, {
229
+ url: string;
230
+ detail?: string | undefined;
231
+ }, {
232
+ url: string;
233
+ detail?: string | undefined;
234
+ }>>;
235
+ }, "strip", z.ZodTypeAny, {
236
+ type: string;
237
+ text?: string | undefined;
238
+ image_url?: {
239
+ url: string;
240
+ detail?: string | undefined;
241
+ } | undefined;
242
+ }, {
243
+ type: string;
244
+ text?: string | undefined;
245
+ image_url?: {
246
+ url: string;
247
+ detail?: string | undefined;
248
+ } | undefined;
249
+ }>, "many">]>>;
250
+ name: z.ZodOptional<z.ZodString>;
251
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
252
+ id: z.ZodString;
253
+ type: z.ZodLiteral<"function">;
254
+ function: z.ZodObject<{
255
+ name: z.ZodString;
256
+ arguments: z.ZodString;
257
+ }, "strip", z.ZodTypeAny, {
258
+ name: string;
259
+ arguments: string;
260
+ }, {
261
+ name: string;
262
+ arguments: string;
263
+ }>;
264
+ }, "strip", z.ZodTypeAny, {
265
+ function: {
266
+ name: string;
267
+ arguments: string;
268
+ };
269
+ type: "function";
270
+ id: string;
271
+ }, {
272
+ function: {
273
+ name: string;
274
+ arguments: string;
275
+ };
276
+ type: "function";
277
+ id: string;
278
+ }>, "many">>;
279
+ tool_call_id: z.ZodOptional<z.ZodString>;
280
+ }, "strip", z.ZodTypeAny, {
281
+ role: "system" | "user" | "assistant" | "tool";
282
+ content: string | {
283
+ type: string;
284
+ text?: string | undefined;
285
+ image_url?: {
286
+ url: string;
287
+ detail?: string | undefined;
288
+ } | undefined;
289
+ }[] | null;
290
+ name?: string | undefined;
291
+ tool_calls?: {
292
+ function: {
293
+ name: string;
294
+ arguments: string;
295
+ };
296
+ type: "function";
297
+ id: string;
298
+ }[] | undefined;
299
+ tool_call_id?: string | undefined;
300
+ }, {
301
+ role: "system" | "user" | "assistant" | "tool";
302
+ content: string | {
303
+ type: string;
304
+ text?: string | undefined;
305
+ image_url?: {
306
+ url: string;
307
+ detail?: string | undefined;
308
+ } | undefined;
309
+ }[] | null;
310
+ name?: string | undefined;
311
+ tool_calls?: {
312
+ function: {
313
+ name: string;
314
+ arguments: string;
315
+ };
316
+ type: "function";
317
+ id: string;
318
+ }[] | undefined;
319
+ tool_call_id?: string | undefined;
320
+ }>, "many">;
321
+ temperature: z.ZodOptional<z.ZodNumber>;
322
+ top_p: z.ZodOptional<z.ZodNumber>;
323
+ n: z.ZodOptional<z.ZodNumber>;
324
+ stream: z.ZodOptional<z.ZodBoolean>;
325
+ stop: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
326
+ max_tokens: z.ZodOptional<z.ZodNumber>;
327
+ max_completion_tokens: z.ZodOptional<z.ZodNumber>;
328
+ presence_penalty: z.ZodOptional<z.ZodNumber>;
329
+ frequency_penalty: z.ZodOptional<z.ZodNumber>;
330
+ logit_bias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
331
+ user: z.ZodOptional<z.ZodString>;
332
+ tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
333
+ type: z.ZodLiteral<"function">;
334
+ function: z.ZodObject<{
335
+ name: z.ZodString;
336
+ description: z.ZodOptional<z.ZodString>;
337
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
338
+ }, "strip", z.ZodTypeAny, {
339
+ name: string;
340
+ description?: string | undefined;
341
+ parameters?: Record<string, unknown> | undefined;
342
+ }, {
343
+ name: string;
344
+ description?: string | undefined;
345
+ parameters?: Record<string, unknown> | undefined;
346
+ }>;
347
+ }, "strip", z.ZodTypeAny, {
348
+ function: {
349
+ name: string;
350
+ description?: string | undefined;
351
+ parameters?: Record<string, unknown> | undefined;
352
+ };
353
+ type: "function";
354
+ }, {
355
+ function: {
356
+ name: string;
357
+ description?: string | undefined;
358
+ parameters?: Record<string, unknown> | undefined;
359
+ };
360
+ type: "function";
361
+ }>, "many">>;
362
+ tool_choice: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"none">, z.ZodLiteral<"auto">, z.ZodLiteral<"required">, z.ZodObject<{
363
+ type: z.ZodLiteral<"function">;
364
+ function: z.ZodObject<{
365
+ name: z.ZodString;
366
+ }, "strip", z.ZodTypeAny, {
367
+ name: string;
368
+ }, {
369
+ name: string;
370
+ }>;
371
+ }, "strip", z.ZodTypeAny, {
372
+ function: {
373
+ name: string;
374
+ };
375
+ type: "function";
376
+ }, {
377
+ function: {
378
+ name: string;
379
+ };
380
+ type: "function";
381
+ }>]>>;
382
+ response_format: z.ZodOptional<z.ZodObject<{
383
+ type: z.ZodEnum<["text", "json_object"]>;
384
+ }, "strip", z.ZodTypeAny, {
385
+ type: "text" | "json_object";
386
+ }, {
387
+ type: "text" | "json_object";
388
+ }>>;
389
+ seed: z.ZodOptional<z.ZodNumber>;
390
+ }, "strip", z.ZodTypeAny, {
391
+ model: string;
392
+ messages: {
393
+ role: "system" | "user" | "assistant" | "tool";
394
+ content: string | {
395
+ type: string;
396
+ text?: string | undefined;
397
+ image_url?: {
398
+ url: string;
399
+ detail?: string | undefined;
400
+ } | undefined;
401
+ }[] | null;
402
+ name?: string | undefined;
403
+ tool_calls?: {
404
+ function: {
405
+ name: string;
406
+ arguments: string;
407
+ };
408
+ type: "function";
409
+ id: string;
410
+ }[] | undefined;
411
+ tool_call_id?: string | undefined;
412
+ }[];
413
+ user?: string | undefined;
414
+ temperature?: number | undefined;
415
+ top_p?: number | undefined;
416
+ n?: number | undefined;
417
+ stream?: boolean | undefined;
418
+ stop?: string | string[] | undefined;
419
+ max_tokens?: number | undefined;
420
+ max_completion_tokens?: number | undefined;
421
+ presence_penalty?: number | undefined;
422
+ frequency_penalty?: number | undefined;
423
+ logit_bias?: Record<string, number> | undefined;
424
+ tools?: {
425
+ function: {
426
+ name: string;
427
+ description?: string | undefined;
428
+ parameters?: Record<string, unknown> | undefined;
429
+ };
430
+ type: "function";
431
+ }[] | undefined;
432
+ tool_choice?: "none" | "auto" | "required" | {
433
+ function: {
434
+ name: string;
435
+ };
436
+ type: "function";
437
+ } | undefined;
438
+ response_format?: {
439
+ type: "text" | "json_object";
440
+ } | undefined;
441
+ seed?: number | undefined;
442
+ }, {
443
+ model: string;
444
+ messages: {
445
+ role: "system" | "user" | "assistant" | "tool";
446
+ content: string | {
447
+ type: string;
448
+ text?: string | undefined;
449
+ image_url?: {
450
+ url: string;
451
+ detail?: string | undefined;
452
+ } | undefined;
453
+ }[] | null;
454
+ name?: string | undefined;
455
+ tool_calls?: {
456
+ function: {
457
+ name: string;
458
+ arguments: string;
459
+ };
460
+ type: "function";
461
+ id: string;
462
+ }[] | undefined;
463
+ tool_call_id?: string | undefined;
464
+ }[];
465
+ user?: string | undefined;
466
+ temperature?: number | undefined;
467
+ top_p?: number | undefined;
468
+ n?: number | undefined;
469
+ stream?: boolean | undefined;
470
+ stop?: string | string[] | undefined;
471
+ max_tokens?: number | undefined;
472
+ max_completion_tokens?: number | undefined;
473
+ presence_penalty?: number | undefined;
474
+ frequency_penalty?: number | undefined;
475
+ logit_bias?: Record<string, number> | undefined;
476
+ tools?: {
477
+ function: {
478
+ name: string;
479
+ description?: string | undefined;
480
+ parameters?: Record<string, unknown> | undefined;
481
+ };
482
+ type: "function";
483
+ }[] | undefined;
484
+ tool_choice?: "none" | "auto" | "required" | {
485
+ function: {
486
+ name: string;
487
+ };
488
+ type: "function";
489
+ } | undefined;
490
+ response_format?: {
491
+ type: "text" | "json_object";
492
+ } | undefined;
493
+ seed?: number | undefined;
494
+ }>;
495
+ type ChatCompletionRequest = z.infer<typeof ChatCompletionRequestSchema>;
496
+ type ChatMessage = z.infer<typeof ChatMessageSchema>;
497
+ /**
498
+ * Permission request schema.
499
+ * Includes optional requested duration for apps to suggest their needs.
500
+ */
501
+ declare const PermissionRequestSchema: z.ZodObject<{
502
+ resourceId: z.ZodString;
503
+ actions: z.ZodArray<z.ZodString, "many">;
504
+ constraints: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
505
+ /** Optional: App's requested/preferred duration for this permission */
506
+ requestedDuration: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
507
+ type: z.ZodLiteral<"preset">;
508
+ preset: z.ZodEnum<["1_hour", "4_hours", "24_hours", "1_week", "1_month", "3_months", "1_year", "forever", "custom"]>;
509
+ }, "strip", z.ZodTypeAny, {
510
+ type: "preset";
511
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
512
+ }, {
513
+ type: "preset";
514
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
515
+ }>, z.ZodObject<{
516
+ type: z.ZodLiteral<"duration">;
517
+ durationMs: z.ZodNumber;
518
+ }, "strip", z.ZodTypeAny, {
519
+ type: "duration";
520
+ durationMs: number;
521
+ }, {
522
+ type: "duration";
523
+ durationMs: number;
524
+ }>, z.ZodObject<{
525
+ type: z.ZodLiteral<"until">;
526
+ expiresAt: z.ZodString;
527
+ }, "strip", z.ZodTypeAny, {
528
+ type: "until";
529
+ expiresAt: string;
530
+ }, {
531
+ type: "until";
532
+ expiresAt: string;
533
+ }>]>>;
534
+ }, "strip", z.ZodTypeAny, {
535
+ resourceId: string;
536
+ actions: string[];
537
+ constraints?: Record<string, unknown> | undefined;
538
+ requestedDuration?: {
539
+ type: "preset";
540
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
541
+ } | {
542
+ type: "duration";
543
+ durationMs: number;
544
+ } | {
545
+ type: "until";
546
+ expiresAt: string;
547
+ } | undefined;
548
+ }, {
549
+ resourceId: string;
550
+ actions: string[];
551
+ constraints?: Record<string, unknown> | undefined;
552
+ requestedDuration?: {
553
+ type: "preset";
554
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
555
+ } | {
556
+ type: "duration";
557
+ durationMs: number;
558
+ } | {
559
+ type: "until";
560
+ expiresAt: string;
561
+ } | undefined;
562
+ }>;
563
+ /**
564
+ * App metadata schema.
565
+ */
566
+ declare const AppMetadataSchema: z.ZodObject<{
567
+ name: z.ZodString;
568
+ description: z.ZodOptional<z.ZodString>;
569
+ homepage: z.ZodOptional<z.ZodString>;
570
+ }, "strip", z.ZodTypeAny, {
571
+ name: string;
572
+ description?: string | undefined;
573
+ homepage?: string | undefined;
574
+ }, {
575
+ name: string;
576
+ description?: string | undefined;
577
+ homepage?: string | undefined;
578
+ }>;
579
+ /**
580
+ * Install request schema (for prepare endpoint).
581
+ */
582
+ declare const InstallRequestSchema: z.ZodObject<{
583
+ connectCode: z.ZodString;
584
+ app: z.ZodObject<{
585
+ name: z.ZodString;
586
+ description: z.ZodOptional<z.ZodString>;
587
+ homepage: z.ZodOptional<z.ZodString>;
588
+ }, "strip", z.ZodTypeAny, {
589
+ name: string;
590
+ description?: string | undefined;
591
+ homepage?: string | undefined;
592
+ }, {
593
+ name: string;
594
+ description?: string | undefined;
595
+ homepage?: string | undefined;
596
+ }>;
597
+ publicKey: z.ZodString;
598
+ requestedPermissions: z.ZodArray<z.ZodObject<{
599
+ resourceId: z.ZodString;
600
+ actions: z.ZodArray<z.ZodString, "many">;
601
+ constraints: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
602
+ /** Optional: App's requested/preferred duration for this permission */
603
+ requestedDuration: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
604
+ type: z.ZodLiteral<"preset">;
605
+ preset: z.ZodEnum<["1_hour", "4_hours", "24_hours", "1_week", "1_month", "3_months", "1_year", "forever", "custom"]>;
606
+ }, "strip", z.ZodTypeAny, {
607
+ type: "preset";
608
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
609
+ }, {
610
+ type: "preset";
611
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
612
+ }>, z.ZodObject<{
613
+ type: z.ZodLiteral<"duration">;
614
+ durationMs: z.ZodNumber;
615
+ }, "strip", z.ZodTypeAny, {
616
+ type: "duration";
617
+ durationMs: number;
618
+ }, {
619
+ type: "duration";
620
+ durationMs: number;
621
+ }>, z.ZodObject<{
622
+ type: z.ZodLiteral<"until">;
623
+ expiresAt: z.ZodString;
624
+ }, "strip", z.ZodTypeAny, {
625
+ type: "until";
626
+ expiresAt: string;
627
+ }, {
628
+ type: "until";
629
+ expiresAt: string;
630
+ }>]>>;
631
+ }, "strip", z.ZodTypeAny, {
632
+ resourceId: string;
633
+ actions: string[];
634
+ constraints?: Record<string, unknown> | undefined;
635
+ requestedDuration?: {
636
+ type: "preset";
637
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
638
+ } | {
639
+ type: "duration";
640
+ durationMs: number;
641
+ } | {
642
+ type: "until";
643
+ expiresAt: string;
644
+ } | undefined;
645
+ }, {
646
+ resourceId: string;
647
+ actions: string[];
648
+ constraints?: Record<string, unknown> | undefined;
649
+ requestedDuration?: {
650
+ type: "preset";
651
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
652
+ } | {
653
+ type: "duration";
654
+ durationMs: number;
655
+ } | {
656
+ type: "until";
657
+ expiresAt: string;
658
+ } | undefined;
659
+ }>, "many">;
660
+ redirectUri: z.ZodString;
661
+ }, "strip", z.ZodTypeAny, {
662
+ connectCode: string;
663
+ app: {
664
+ name: string;
665
+ description?: string | undefined;
666
+ homepage?: string | undefined;
667
+ };
668
+ publicKey: string;
669
+ requestedPermissions: {
670
+ resourceId: string;
671
+ actions: string[];
672
+ constraints?: Record<string, unknown> | undefined;
673
+ requestedDuration?: {
674
+ type: "preset";
675
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
676
+ } | {
677
+ type: "duration";
678
+ durationMs: number;
679
+ } | {
680
+ type: "until";
681
+ expiresAt: string;
682
+ } | undefined;
683
+ }[];
684
+ redirectUri: string;
685
+ }, {
686
+ connectCode: string;
687
+ app: {
688
+ name: string;
689
+ description?: string | undefined;
690
+ homepage?: string | undefined;
691
+ };
692
+ publicKey: string;
693
+ requestedPermissions: {
694
+ resourceId: string;
695
+ actions: string[];
696
+ constraints?: Record<string, unknown> | undefined;
697
+ requestedDuration?: {
698
+ type: "preset";
699
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
700
+ } | {
701
+ type: "duration";
702
+ durationMs: number;
703
+ } | {
704
+ type: "until";
705
+ expiresAt: string;
706
+ } | undefined;
707
+ }[];
708
+ redirectUri: string;
709
+ }>;
710
+ type InstallRequest = z.infer<typeof InstallRequestSchema>;
711
+ /**
712
+ * Resource auth configuration in discovery response.
713
+ */
714
+ declare const ResourceAuthSchema: z.ZodObject<{
715
+ pop: z.ZodObject<{
716
+ version: z.ZodNumber;
717
+ }, "strip", z.ZodTypeAny, {
718
+ version: number;
719
+ }, {
720
+ version: number;
721
+ }>;
722
+ }, "strip", z.ZodTypeAny, {
723
+ pop: {
724
+ version: number;
725
+ };
726
+ }, {
727
+ pop: {
728
+ version: number;
729
+ };
730
+ }>;
731
+ /**
732
+ * Resource entry in discovery response.
733
+ */
734
+ declare const ResourceDiscoveryEntrySchema: z.ZodObject<{
735
+ resourceId: z.ZodString;
736
+ actions: z.ZodArray<z.ZodString, "many">;
737
+ auth: z.ZodObject<{
738
+ pop: z.ZodObject<{
739
+ version: z.ZodNumber;
740
+ }, "strip", z.ZodTypeAny, {
741
+ version: number;
742
+ }, {
743
+ version: number;
744
+ }>;
745
+ }, "strip", z.ZodTypeAny, {
746
+ pop: {
747
+ version: number;
748
+ };
749
+ }, {
750
+ pop: {
751
+ version: number;
752
+ };
753
+ }>;
754
+ constraints: z.ZodOptional<z.ZodObject<{
755
+ supports: z.ZodArray<z.ZodString, "many">;
756
+ }, "strip", z.ZodTypeAny, {
757
+ supports: string[];
758
+ }, {
759
+ supports: string[];
760
+ }>>;
761
+ }, "strip", z.ZodTypeAny, {
762
+ resourceId: string;
763
+ actions: string[];
764
+ auth: {
765
+ pop: {
766
+ version: number;
767
+ };
768
+ };
769
+ constraints?: {
770
+ supports: string[];
771
+ } | undefined;
772
+ }, {
773
+ resourceId: string;
774
+ actions: string[];
775
+ auth: {
776
+ pop: {
777
+ version: number;
778
+ };
779
+ };
780
+ constraints?: {
781
+ supports: string[];
782
+ } | undefined;
783
+ }>;
784
+ /**
785
+ * Gateway info in discovery response.
786
+ */
787
+ declare const GatewayInfoSchema: z.ZodObject<{
788
+ version: z.ZodString;
789
+ name: z.ZodOptional<z.ZodString>;
790
+ }, "strip", z.ZodTypeAny, {
791
+ version: string;
792
+ name?: string | undefined;
793
+ }, {
794
+ version: string;
795
+ name?: string | undefined;
796
+ }>;
797
+ /**
798
+ * Full discovery response schema.
799
+ */
800
+ declare const ResourcesDiscoveryResponseSchema: z.ZodObject<{
801
+ gateway: z.ZodObject<{
802
+ version: z.ZodString;
803
+ name: z.ZodOptional<z.ZodString>;
804
+ }, "strip", z.ZodTypeAny, {
805
+ version: string;
806
+ name?: string | undefined;
807
+ }, {
808
+ version: string;
809
+ name?: string | undefined;
810
+ }>;
811
+ resources: z.ZodArray<z.ZodObject<{
812
+ resourceId: z.ZodString;
813
+ actions: z.ZodArray<z.ZodString, "many">;
814
+ auth: z.ZodObject<{
815
+ pop: z.ZodObject<{
816
+ version: z.ZodNumber;
817
+ }, "strip", z.ZodTypeAny, {
818
+ version: number;
819
+ }, {
820
+ version: number;
821
+ }>;
822
+ }, "strip", z.ZodTypeAny, {
823
+ pop: {
824
+ version: number;
825
+ };
826
+ }, {
827
+ pop: {
828
+ version: number;
829
+ };
830
+ }>;
831
+ constraints: z.ZodOptional<z.ZodObject<{
832
+ supports: z.ZodArray<z.ZodString, "many">;
833
+ }, "strip", z.ZodTypeAny, {
834
+ supports: string[];
835
+ }, {
836
+ supports: string[];
837
+ }>>;
838
+ }, "strip", z.ZodTypeAny, {
839
+ resourceId: string;
840
+ actions: string[];
841
+ auth: {
842
+ pop: {
843
+ version: number;
844
+ };
845
+ };
846
+ constraints?: {
847
+ supports: string[];
848
+ } | undefined;
849
+ }, {
850
+ resourceId: string;
851
+ actions: string[];
852
+ auth: {
853
+ pop: {
854
+ version: number;
855
+ };
856
+ };
857
+ constraints?: {
858
+ supports: string[];
859
+ } | undefined;
860
+ }>, "many">;
861
+ }, "strip", z.ZodTypeAny, {
862
+ gateway: {
863
+ version: string;
864
+ name?: string | undefined;
865
+ };
866
+ resources: {
867
+ resourceId: string;
868
+ actions: string[];
869
+ auth: {
870
+ pop: {
871
+ version: number;
872
+ };
873
+ };
874
+ constraints?: {
875
+ supports: string[];
876
+ } | undefined;
877
+ }[];
878
+ }, {
879
+ gateway: {
880
+ version: string;
881
+ name?: string | undefined;
882
+ };
883
+ resources: {
884
+ resourceId: string;
885
+ actions: string[];
886
+ auth: {
887
+ pop: {
888
+ version: number;
889
+ };
890
+ };
891
+ constraints?: {
892
+ supports: string[];
893
+ } | undefined;
894
+ }[];
895
+ }>;
896
+ type ResourcesDiscoveryResponse = z.infer<typeof ResourcesDiscoveryResponseSchema>;
897
+ type ResourceDiscoveryEntry = z.infer<typeof ResourceDiscoveryEntrySchema>;
898
+ type GatewayInfo = z.infer<typeof GatewayInfoSchema>;
899
+
900
+ /**
901
+ * Time window restriction.
902
+ * Allows access only during specific hours of the day.
903
+ */
904
+ interface TimeWindow {
905
+ /** Start hour (0-23) in the specified timezone */
906
+ startHour: number;
907
+ /** End hour (0-23) in the specified timezone */
908
+ endHour: number;
909
+ /** Timezone for the time window (e.g., "UTC", "America/New_York") */
910
+ timezone: string;
911
+ /** Days of week allowed (0=Sunday, 6=Saturday). Empty = all days */
912
+ allowedDays?: number[];
913
+ }
914
+ /**
915
+ * Rate limit configuration.
916
+ */
917
+ interface RateLimitConfig$1 {
918
+ /** Maximum requests allowed in the window */
919
+ maxRequests: number;
920
+ /** Window duration in seconds */
921
+ windowSeconds: number;
922
+ }
923
+ /**
924
+ * Burst limit configuration.
925
+ * Allows short-term spikes above the sustained rate limit.
926
+ */
927
+ interface BurstConfig {
928
+ /** Maximum requests allowed in burst window */
929
+ limit: number;
930
+ /** Burst window duration in seconds (typically short, e.g., 10s) */
931
+ windowSeconds: number;
932
+ }
933
+ /**
934
+ * Quota configuration for daily/monthly limits.
935
+ */
936
+ interface QuotaConfig {
937
+ /** Daily request quota (null = unlimited) */
938
+ daily?: number;
939
+ /** Monthly request quota (null = unlimited) */
940
+ monthly?: number;
941
+ }
942
+ /**
943
+ * Token budget for LLM resources.
944
+ */
945
+ interface TokenBudget {
946
+ /** Daily token budget (null = unlimited) */
947
+ daily?: number;
948
+ /** Monthly token budget (null = unlimited) */
949
+ monthly?: number;
950
+ }
951
+ /**
952
+ * Per-model rate limit configuration.
953
+ * Allows fine-grained control over different models.
954
+ */
955
+ interface ModelRateLimit {
956
+ /** Model identifier */
957
+ model: string;
958
+ /** Maximum requests per window for this model */
959
+ maxRequests: number;
960
+ /** Window duration in seconds */
961
+ windowSeconds: number;
962
+ /** Maximum output tokens per request for this model (overrides global) */
963
+ maxOutputTokens?: number;
964
+ /** Daily token budget for this specific model */
965
+ dailyTokenBudget?: number;
966
+ /** Monthly token budget for this specific model */
967
+ monthlyTokenBudget?: number;
968
+ }
969
+ /**
970
+ * LLM-specific constraints.
971
+ */
972
+ interface LLMConstraints {
973
+ /** Allowed model IDs (empty = all models allowed) */
974
+ allowedModels?: string[];
975
+ /** Maximum output tokens per request */
976
+ maxOutputTokens?: number;
977
+ /** Maximum input tokens per request */
978
+ maxInputTokens?: number;
979
+ /** Allow streaming responses */
980
+ allowStreaming?: boolean;
981
+ /** Maximum context window */
982
+ maxContextWindow?: number;
983
+ /** Per-model rate limits (overrides global rate limits) */
984
+ modelRateLimits?: ModelRateLimit[];
985
+ /** Allow tool/function calling */
986
+ allowTools?: boolean;
987
+ }
988
+ /**
989
+ * Email-specific constraints.
990
+ */
991
+ interface EmailConstraints {
992
+ /** Allowed from domains */
993
+ allowedFromDomains?: string[];
994
+ /** Maximum recipients per email */
995
+ maxRecipients?: number;
996
+ /** Allow HTML content */
997
+ allowHtml?: boolean;
998
+ /** Maximum attachment size in bytes */
999
+ maxAttachmentSize?: number;
1000
+ }
1001
+ /**
1002
+ * Generic HTTP constraints.
1003
+ */
1004
+ interface HTTPConstraints {
1005
+ /** Maximum request body size in bytes */
1006
+ maxRequestBodySize?: number;
1007
+ /** Allowed HTTP methods */
1008
+ allowedMethods?: string[];
1009
+ /** Custom constraints */
1010
+ custom?: Record<string, unknown>;
1011
+ }
1012
+ /**
1013
+ * Union type for all constraint types.
1014
+ */
1015
+ type ResourceConstraints$1 = LLMConstraints | EmailConstraints | HTTPConstraints | Record<string, unknown>;
1016
+ /**
1017
+ * Complete access policy for a permission.
1018
+ * This is what the proxy owner configures during approval.
1019
+ */
1020
+ interface AccessPolicy {
1021
+ /** When the permission becomes valid (ISO string, null = immediately) */
1022
+ validFrom?: string | null;
1023
+ /** When the permission expires (ISO string, null = never) */
1024
+ expiresAt?: string | null;
1025
+ /** Time-of-day restrictions */
1026
+ timeWindow?: TimeWindow | null;
1027
+ /** Sustained rate limit */
1028
+ rateLimit?: RateLimitConfig$1;
1029
+ /** Burst allowance */
1030
+ burst?: BurstConfig;
1031
+ /** Request quotas */
1032
+ quota?: QuotaConfig;
1033
+ /** Token budget (LLM resources) */
1034
+ tokenBudget?: TokenBudget;
1035
+ /** Resource-specific constraints */
1036
+ constraints?: ResourceConstraints$1;
1037
+ }
1038
+ type ExpiryPreset = "1_hour" | "4_hours" | "today" | "24_hours" | "this_week" | "1_month" | "3_months" | "1_year" | "never" | "custom";
1039
+ interface ExpiryPresetOption {
1040
+ value: ExpiryPreset;
1041
+ label: string;
1042
+ description: string;
1043
+ getDate: () => Date | null;
1044
+ }
1045
+ /**
1046
+ * Get expiry date from preset.
1047
+ */
1048
+ declare function getExpiryFromPreset(preset: ExpiryPreset): Date | null;
1049
+ /**
1050
+ * All available expiry presets with labels.
1051
+ */
1052
+ declare const EXPIRY_PRESETS: ExpiryPresetOption[];
1053
+ interface RateLimitPreset {
1054
+ label: string;
1055
+ value: RateLimitConfig$1;
1056
+ }
1057
+ declare const RATE_LIMIT_PRESETS: RateLimitPreset[];
1058
+ /**
1059
+ * Check if a permission is currently valid based on time controls.
1060
+ */
1061
+ declare function isPermissionValidNow(policy: AccessPolicy): {
1062
+ valid: boolean;
1063
+ reason?: string;
1064
+ };
1065
+ /**
1066
+ * Format an access policy for display.
1067
+ */
1068
+ declare function formatAccessPolicySummary(policy: AccessPolicy): string[];
1069
+
1070
+ /**
1071
+ * PoP header schema for v1 protocol.
1072
+ * Validates all required headers for PoP authentication.
1073
+ */
1074
+ declare const PopHeadersV1Schema: z.ZodObject<{
1075
+ "x-pop-v": z.ZodLiteral<"1">;
1076
+ "x-app-id": z.ZodString;
1077
+ "x-ts": z.ZodString;
1078
+ "x-nonce": z.ZodString;
1079
+ "x-sig": z.ZodString;
1080
+ }, "strip", z.ZodTypeAny, {
1081
+ "x-pop-v": "1";
1082
+ "x-app-id": string;
1083
+ "x-ts": string;
1084
+ "x-nonce": string;
1085
+ "x-sig": string;
1086
+ }, {
1087
+ "x-pop-v": "1";
1088
+ "x-app-id": string;
1089
+ "x-ts": string;
1090
+ "x-nonce": string;
1091
+ "x-sig": string;
1092
+ }>;
1093
+ type PopHeadersV1 = z.infer<typeof PopHeadersV1Schema>;
1094
+ /**
1095
+ * Parameters for building a canonical request string.
1096
+ */
1097
+ interface CanonicalRequestParams {
1098
+ /** HTTP method (will be uppercased) */
1099
+ method: string;
1100
+ /** URL path with query string (e.g., "/v1/chat/completions?stream=true") */
1101
+ pathWithQuery: string;
1102
+ /** App ID from x-app-id header */
1103
+ appId: string;
1104
+ /** Unix timestamp from x-ts header */
1105
+ ts: string;
1106
+ /** Nonce from x-nonce header */
1107
+ nonce: string;
1108
+ /** Base64url-encoded SHA-256 hash of request body */
1109
+ bodyHash: string;
1110
+ }
1111
+ /**
1112
+ * Build the canonical request string for PoP v1 signature.
1113
+ *
1114
+ * Format:
1115
+ * ```
1116
+ * v1\n
1117
+ * <METHOD>\n
1118
+ * <PATH_WITH_QUERY>\n
1119
+ * <APP_ID>\n
1120
+ * <TS>\n
1121
+ * <NONCE>\n
1122
+ * <BODY_HASH>\n
1123
+ * ```
1124
+ *
1125
+ * @param params - The canonical request parameters
1126
+ * @returns The canonical request string to be signed
1127
+ *
1128
+ * @example
1129
+ * const canonical = buildCanonicalRequestV1({
1130
+ * method: "POST",
1131
+ * pathWithQuery: "/v1/chat/completions?stream=true",
1132
+ * appId: "app_123",
1133
+ * ts: "1706000000",
1134
+ * nonce: "abc123xyz456def7",
1135
+ * bodyHash: "base64url-sha256-hash",
1136
+ * });
1137
+ */
1138
+ declare function buildCanonicalRequestV1(params: CanonicalRequestParams): string;
1139
+ /**
1140
+ * Extract path with query from a URL.
1141
+ * Combines pathname and search (including '?' when present).
1142
+ *
1143
+ * @example
1144
+ * getPathWithQuery(new URL("https://example.com/v1/chat?stream=true"))
1145
+ * // Returns: "/v1/chat?stream=true"
1146
+ *
1147
+ * getPathWithQuery(new URL("https://example.com/v1/chat"))
1148
+ * // Returns: "/v1/chat"
1149
+ */
1150
+ declare function getPathWithQuery(url: URL): string;
1151
+ /**
1152
+ * Current PoP protocol version.
1153
+ */
1154
+ declare const POP_VERSION: "1";
1155
+ /**
1156
+ * Error codes specific to PoP authentication.
1157
+ */
1158
+ declare enum PopErrorCode {
1159
+ UNSUPPORTED_VERSION = "ERR_UNSUPPORTED_POP_VERSION"
1160
+ }
1161
+
1162
+ /**
1163
+ * Enforcement fields returned by validateAndShape.
1164
+ * These are normalized, enforceable knobs that plugins MUST provide
1165
+ * when constraints require them. This replaces the legacy extractor system.
1166
+ *
1167
+ * The schema-first approach ensures:
1168
+ * - Enforcement cannot be bypassed by malformed payloads
1169
+ * - Plugins are responsible for extracting enforcement fields during validation
1170
+ * - No "fail-open" extraction - if a field is needed, it must be provided
1171
+ */
1172
+ declare const EnforcementFieldsSchema: z.ZodObject<{
1173
+ model: z.ZodOptional<z.ZodString>;
1174
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
1175
+ usesTools: z.ZodOptional<z.ZodBoolean>;
1176
+ stream: z.ZodOptional<z.ZodBoolean>;
1177
+ fromDomain: z.ZodOptional<z.ZodString>;
1178
+ toDomains: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1179
+ recipientCount: z.ZodOptional<z.ZodNumber>;
1180
+ contentType: z.ZodOptional<z.ZodString>;
1181
+ }, "strip", z.ZodTypeAny, {
1182
+ model?: string | undefined;
1183
+ stream?: boolean | undefined;
1184
+ maxOutputTokens?: number | undefined;
1185
+ usesTools?: boolean | undefined;
1186
+ fromDomain?: string | undefined;
1187
+ toDomains?: string[] | undefined;
1188
+ recipientCount?: number | undefined;
1189
+ contentType?: string | undefined;
1190
+ }, {
1191
+ model?: string | undefined;
1192
+ stream?: boolean | undefined;
1193
+ maxOutputTokens?: number | undefined;
1194
+ usesTools?: boolean | undefined;
1195
+ fromDomain?: string | undefined;
1196
+ toDomains?: string[] | undefined;
1197
+ recipientCount?: number | undefined;
1198
+ contentType?: string | undefined;
1199
+ }>;
1200
+ type EnforcementFields = z.infer<typeof EnforcementFieldsSchema>;
1201
+ /**
1202
+ * @deprecated Use EnforcementFields instead. ExtractedRequest is kept for backward compatibility
1203
+ * but will be removed in a future version. The extractor system has been replaced with
1204
+ * schema-first validation where plugins return enforcement fields from validateAndShape.
1205
+ */
1206
+ declare const ExtractedRequestSchema: z.ZodObject<{
1207
+ model: z.ZodOptional<z.ZodString>;
1208
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
1209
+ usesTools: z.ZodOptional<z.ZodBoolean>;
1210
+ stream: z.ZodOptional<z.ZodBoolean>;
1211
+ fromDomain: z.ZodOptional<z.ZodString>;
1212
+ toDomains: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1213
+ recipientCount: z.ZodOptional<z.ZodNumber>;
1214
+ contentType: z.ZodOptional<z.ZodString>;
1215
+ }, "strip", z.ZodTypeAny, {
1216
+ model?: string | undefined;
1217
+ stream?: boolean | undefined;
1218
+ maxOutputTokens?: number | undefined;
1219
+ usesTools?: boolean | undefined;
1220
+ fromDomain?: string | undefined;
1221
+ toDomains?: string[] | undefined;
1222
+ recipientCount?: number | undefined;
1223
+ contentType?: string | undefined;
1224
+ }, {
1225
+ model?: string | undefined;
1226
+ stream?: boolean | undefined;
1227
+ maxOutputTokens?: number | undefined;
1228
+ usesTools?: boolean | undefined;
1229
+ fromDomain?: string | undefined;
1230
+ toDomains?: string[] | undefined;
1231
+ recipientCount?: number | undefined;
1232
+ contentType?: string | undefined;
1233
+ }>;
1234
+ /**
1235
+ * @deprecated Use EnforcementFields instead.
1236
+ */
1237
+ type ExtractedRequest = EnforcementFields;
1238
+ /**
1239
+ * Enforcement metadata that target apps may optionally provide.
1240
+ * This is NOT required for enforcement - the proxy can operate without it.
1241
+ * Treat as advisory only.
1242
+ */
1243
+ declare const EnforcementMetaSchema: z.ZodObject<{
1244
+ /** App-provided request ID for correlation */
1245
+ requestId: z.ZodOptional<z.ZodString>;
1246
+ /** Declared intent (advisory only, not enforced) */
1247
+ intent: z.ZodOptional<z.ZodString>;
1248
+ /** App-declared expected model (advisory only) */
1249
+ expectedModel: z.ZodOptional<z.ZodString>;
1250
+ }, "strip", z.ZodTypeAny, {
1251
+ requestId?: string | undefined;
1252
+ intent?: string | undefined;
1253
+ expectedModel?: string | undefined;
1254
+ }, {
1255
+ requestId?: string | undefined;
1256
+ intent?: string | undefined;
1257
+ expectedModel?: string | undefined;
1258
+ }>;
1259
+ type EnforcementMeta = z.infer<typeof EnforcementMetaSchema>;
1260
+ /**
1261
+ * Policy definition for enforcement.
1262
+ * This mirrors ResourceConstraints but is focused on enforcement.
1263
+ */
1264
+ interface EnforcementPolicy {
1265
+ allowedModels?: string[];
1266
+ maxOutputTokens?: number;
1267
+ allowTools?: boolean;
1268
+ allowStreaming?: boolean;
1269
+ allowedFromDomains?: string[];
1270
+ allowedToDomains?: string[];
1271
+ maxRecipients?: number;
1272
+ maxRequestBodySize?: number;
1273
+ }
1274
+ /**
1275
+ * Result of policy enforcement.
1276
+ */
1277
+ interface EnforcementResult {
1278
+ allowed: boolean;
1279
+ violation?: {
1280
+ code: string;
1281
+ message: string;
1282
+ field: string;
1283
+ actual?: unknown;
1284
+ limit?: unknown;
1285
+ };
1286
+ }
1287
+
1288
+ /**
1289
+ * Plugin authentication configuration.
1290
+ */
1291
+ declare const PluginAuthSchema: z.ZodObject<{
1292
+ pop: z.ZodObject<{
1293
+ version: z.ZodNumber;
1294
+ }, "strip", z.ZodTypeAny, {
1295
+ version: number;
1296
+ }, {
1297
+ version: number;
1298
+ }>;
1299
+ }, "strip", z.ZodTypeAny, {
1300
+ pop: {
1301
+ version: number;
1302
+ };
1303
+ }, {
1304
+ pop: {
1305
+ version: number;
1306
+ };
1307
+ }>;
1308
+ type PluginAuth = z.infer<typeof PluginAuthSchema>;
1309
+ /**
1310
+ * Plugin support configuration.
1311
+ * Describes which enforcement knobs the plugin supports.
1312
+ */
1313
+ declare const PluginSupportsSchema: z.ZodObject<{
1314
+ enforcement: z.ZodArray<z.ZodString, "many">;
1315
+ }, "strip", z.ZodTypeAny, {
1316
+ enforcement: string[];
1317
+ }, {
1318
+ enforcement: string[];
1319
+ }>;
1320
+ type PluginSupports = z.infer<typeof PluginSupportsSchema>;
1321
+ /**
1322
+ * Extractor descriptor - describes how to extract enforceable fields.
1323
+ * Can reference a function name (for core extractors) or provide inline config.
1324
+ */
1325
+ declare const ExtractorDescriptorSchema: z.ZodObject<{
1326
+ /** Reference to core extractor by name (e.g., "openai-compatible", "gemini") */
1327
+ type: z.ZodOptional<z.ZodString>;
1328
+ /** Custom extraction config (for future use) */
1329
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1330
+ }, "strip", z.ZodTypeAny, {
1331
+ type?: string | undefined;
1332
+ config?: Record<string, unknown> | undefined;
1333
+ }, {
1334
+ type?: string | undefined;
1335
+ config?: Record<string, unknown> | undefined;
1336
+ }>;
1337
+ type ExtractorDescriptor = z.infer<typeof ExtractorDescriptorSchema>;
1338
+ /**
1339
+ * Credential schema field descriptor.
1340
+ * Used for UI generation to collect provider credentials.
1341
+ */
1342
+ declare const CredentialFieldSchema: z.ZodObject<{
1343
+ name: z.ZodString;
1344
+ type: z.ZodEnum<["string", "secret", "url", "number", "boolean"]>;
1345
+ label: z.ZodString;
1346
+ description: z.ZodOptional<z.ZodString>;
1347
+ required: z.ZodDefault<z.ZodBoolean>;
1348
+ default: z.ZodOptional<z.ZodUnknown>;
1349
+ }, "strip", z.ZodTypeAny, {
1350
+ type: "string" | "number" | "boolean" | "url" | "secret";
1351
+ name: string;
1352
+ required: boolean;
1353
+ label: string;
1354
+ description?: string | undefined;
1355
+ default?: unknown;
1356
+ }, {
1357
+ type: "string" | "number" | "boolean" | "url" | "secret";
1358
+ name: string;
1359
+ label: string;
1360
+ description?: string | undefined;
1361
+ required?: boolean | undefined;
1362
+ default?: unknown;
1363
+ }>;
1364
+ type CredentialField = z.infer<typeof CredentialFieldSchema>;
1365
+ /**
1366
+ * Full credential schema for a plugin.
1367
+ */
1368
+ declare const PluginCredentialSchemaSchema: z.ZodObject<{
1369
+ fields: z.ZodArray<z.ZodObject<{
1370
+ name: z.ZodString;
1371
+ type: z.ZodEnum<["string", "secret", "url", "number", "boolean"]>;
1372
+ label: z.ZodString;
1373
+ description: z.ZodOptional<z.ZodString>;
1374
+ required: z.ZodDefault<z.ZodBoolean>;
1375
+ default: z.ZodOptional<z.ZodUnknown>;
1376
+ }, "strip", z.ZodTypeAny, {
1377
+ type: "string" | "number" | "boolean" | "url" | "secret";
1378
+ name: string;
1379
+ required: boolean;
1380
+ label: string;
1381
+ description?: string | undefined;
1382
+ default?: unknown;
1383
+ }, {
1384
+ type: "string" | "number" | "boolean" | "url" | "secret";
1385
+ name: string;
1386
+ label: string;
1387
+ description?: string | undefined;
1388
+ required?: boolean | undefined;
1389
+ default?: unknown;
1390
+ }>, "many">;
1391
+ }, "strip", z.ZodTypeAny, {
1392
+ fields: {
1393
+ type: "string" | "number" | "boolean" | "url" | "secret";
1394
+ name: string;
1395
+ required: boolean;
1396
+ label: string;
1397
+ description?: string | undefined;
1398
+ default?: unknown;
1399
+ }[];
1400
+ }, {
1401
+ fields: {
1402
+ type: "string" | "number" | "boolean" | "url" | "secret";
1403
+ name: string;
1404
+ label: string;
1405
+ description?: string | undefined;
1406
+ required?: boolean | undefined;
1407
+ default?: unknown;
1408
+ }[];
1409
+ }>;
1410
+ type PluginCredentialSchema = z.infer<typeof PluginCredentialSchemaSchema>;
1411
+ /**
1412
+ * Usage metrics extracted from response.
1413
+ */
1414
+ interface PluginUsageMetrics {
1415
+ inputTokens?: number;
1416
+ outputTokens?: number;
1417
+ totalTokens?: number;
1418
+ model?: string;
1419
+ custom?: Record<string, unknown>;
1420
+ }
1421
+ /**
1422
+ * Execute options passed to plugin.
1423
+ */
1424
+ interface PluginExecuteOptions {
1425
+ stream: boolean;
1426
+ signal?: AbortSignal;
1427
+ }
1428
+ /**
1429
+ * Execute result from plugin.
1430
+ */
1431
+ interface PluginExecuteResult {
1432
+ /** For non-streaming responses */
1433
+ response?: unknown;
1434
+ /** For streaming responses */
1435
+ stream?: ReadableStream<Uint8Array>;
1436
+ /** Response content type */
1437
+ contentType: string;
1438
+ /** Usage metrics (available for non-streaming) */
1439
+ usage?: PluginUsageMetrics;
1440
+ }
1441
+ /**
1442
+ * Validation result from plugin.
1443
+ * In the schema-first pipeline:
1444
+ * - shapedInput: The validated/transformed payload ready for upstream execution
1445
+ * - enforcement: Normalized fields extracted during validation for policy enforcement
1446
+ *
1447
+ * The enforcement fields are REQUIRED when constraints exist for those fields.
1448
+ * This ensures enforcement cannot be bypassed by malformed payloads.
1449
+ */
1450
+ interface PluginValidationResult {
1451
+ valid: boolean;
1452
+ error?: string;
1453
+ /** Transformed/validated input ready for execution (provider-native format) */
1454
+ shapedInput?: unknown;
1455
+ /** Normalized enforcement fields extracted during validation */
1456
+ enforcement?: EnforcementFields;
1457
+ }
1458
+ /**
1459
+ * Mapped error from plugin.
1460
+ */
1461
+ interface PluginMappedError {
1462
+ status: number;
1463
+ code: string;
1464
+ message: string;
1465
+ retryable: boolean;
1466
+ }
1467
+ /**
1468
+ * Context for plugin execution.
1469
+ * Contains resolved credentials and configuration.
1470
+ */
1471
+ interface PluginExecuteContext {
1472
+ /** The resolved API key/secret */
1473
+ secret: string;
1474
+ /** Additional config (e.g., custom baseUrl) */
1475
+ config: Record<string, unknown> | null;
1476
+ }
1477
+ /**
1478
+ * Resource constraints passed to validation.
1479
+ */
1480
+ interface PluginResourceConstraints {
1481
+ allowedModels?: string[];
1482
+ maxOutputTokens?: number;
1483
+ maxInputTokens?: number;
1484
+ allowStreaming?: boolean;
1485
+ allowedFromDomains?: string[];
1486
+ allowedToDomains?: string[];
1487
+ maxRecipients?: number;
1488
+ allowHtml?: boolean;
1489
+ allowAttachments?: boolean;
1490
+ maxRequestBodySize?: number;
1491
+ [key: string]: unknown;
1492
+ }
1493
+ /**
1494
+ * Action schema descriptor for client contracts.
1495
+ * Describes the request/response schema for a single action.
1496
+ */
1497
+ interface PluginActionSchemaDescriptor {
1498
+ /** Zod schema for validating requests (optional, can be inferred from contracts) */
1499
+ requestSchema?: ZodSchema;
1500
+ /** Zod schema for validating responses (optional, can be inferred from contracts) */
1501
+ responseSchema?: ZodSchema;
1502
+ /** Human-readable description of this action */
1503
+ description?: string;
1504
+ }
1505
+ /**
1506
+ * Client contract metadata for dual-entrypoint plugins.
1507
+ * Describes how the client-side interface is organized.
1508
+ *
1509
+ * Example:
1510
+ * ```ts
1511
+ * client: {
1512
+ * namespace: "gemini",
1513
+ * actions: {
1514
+ * "chat.completions": {
1515
+ * requestSchema: ChatCompletionRequestSchema,
1516
+ * responseSchema: ChatCompletionResponseSchema,
1517
+ * description: "Generate chat completions using Gemini"
1518
+ * }
1519
+ * }
1520
+ * }
1521
+ * ```
1522
+ */
1523
+ interface PluginClientContract {
1524
+ /**
1525
+ * Namespace for the client wrapper (used for import organization).
1526
+ * Example: "gemini" -> `import { gemini } from "@glueco/plugin-llm-gemini/client"`
1527
+ */
1528
+ namespace: string;
1529
+ /**
1530
+ * Action descriptors mapping action names to their schemas.
1531
+ * Keys should match the `actions` array in the plugin.
1532
+ */
1533
+ actions: Record<string, PluginActionSchemaDescriptor>;
1534
+ /**
1535
+ * Package entrypoint for the client module.
1536
+ * Default: "./client"
1537
+ */
1538
+ entrypoint?: string;
1539
+ }
1540
+ /**
1541
+ * Core plugin contract.
1542
+ * Every plugin must implement this interface.
1543
+ */
1544
+ interface PluginContract {
1545
+ /**
1546
+ * Unique plugin identifier.
1547
+ * Format: <resourceType>:<provider>
1548
+ * Examples: "llm:groq", "llm:gemini", "mail:resend"
1549
+ */
1550
+ readonly id: string;
1551
+ /**
1552
+ * Resource type category.
1553
+ * Examples: "llm", "mail", "storage"
1554
+ */
1555
+ readonly resourceType: string;
1556
+ /**
1557
+ * Provider name.
1558
+ * Examples: "groq", "gemini", "resend", "openai"
1559
+ */
1560
+ readonly provider: string;
1561
+ /**
1562
+ * Plugin version string (semver).
1563
+ */
1564
+ readonly version: string;
1565
+ /**
1566
+ * Human-readable display name.
1567
+ */
1568
+ readonly name: string;
1569
+ /**
1570
+ * Supported actions.
1571
+ * Examples: ["chat.completions", "models.list"]
1572
+ */
1573
+ readonly actions: string[];
1574
+ /**
1575
+ * Authentication configuration for discovery.
1576
+ */
1577
+ readonly auth: PluginAuth;
1578
+ /**
1579
+ * Enforcement support configuration.
1580
+ */
1581
+ readonly supports: PluginSupports;
1582
+ /**
1583
+ * Optional extractor descriptors per action.
1584
+ * Key = action name, value = extractor descriptor.
1585
+ */
1586
+ readonly extractors?: Record<string, ExtractorDescriptor>;
1587
+ /**
1588
+ * Optional credential schema for UI generation.
1589
+ */
1590
+ readonly credentialSchema?: PluginCredentialSchema;
1591
+ /**
1592
+ * Optional client contract metadata for dual-entrypoint plugins.
1593
+ * Describes the client-side interface for typed wrappers.
1594
+ *
1595
+ * This metadata is used by:
1596
+ * - SDK typed wrappers to provide autocomplete
1597
+ * - Documentation generation
1598
+ * - System-check app (optional validation)
1599
+ */
1600
+ readonly client?: PluginClientContract;
1601
+ /**
1602
+ * Validate input and apply constraints.
1603
+ * Returns shaped input ready for execution.
1604
+ */
1605
+ validateAndShape(action: string, input: unknown, constraints: PluginResourceConstraints): PluginValidationResult;
1606
+ /**
1607
+ * Execute the resource action.
1608
+ */
1609
+ execute(action: string, shapedInput: unknown, ctx: PluginExecuteContext, options: PluginExecuteOptions): Promise<PluginExecuteResult>;
1610
+ /**
1611
+ * Extract usage metrics from response.
1612
+ */
1613
+ extractUsage(response: unknown): PluginUsageMetrics;
1614
+ /**
1615
+ * Map provider errors to standardized format.
1616
+ */
1617
+ mapError(error: unknown): PluginMappedError;
1618
+ }
1619
+ /**
1620
+ * Schema to validate plugin metadata at registration.
1621
+ */
1622
+ declare const PluginClientContractSchema: z.ZodObject<{
1623
+ namespace: z.ZodString;
1624
+ actions: z.ZodRecord<z.ZodString, z.ZodObject<{
1625
+ requestSchema: z.ZodOptional<z.ZodAny>;
1626
+ responseSchema: z.ZodOptional<z.ZodAny>;
1627
+ description: z.ZodOptional<z.ZodString>;
1628
+ }, "strip", z.ZodTypeAny, {
1629
+ description?: string | undefined;
1630
+ requestSchema?: any;
1631
+ responseSchema?: any;
1632
+ }, {
1633
+ description?: string | undefined;
1634
+ requestSchema?: any;
1635
+ responseSchema?: any;
1636
+ }>>;
1637
+ entrypoint: z.ZodOptional<z.ZodString>;
1638
+ }, "strip", z.ZodTypeAny, {
1639
+ actions: Record<string, {
1640
+ description?: string | undefined;
1641
+ requestSchema?: any;
1642
+ responseSchema?: any;
1643
+ }>;
1644
+ namespace: string;
1645
+ entrypoint?: string | undefined;
1646
+ }, {
1647
+ actions: Record<string, {
1648
+ description?: string | undefined;
1649
+ requestSchema?: any;
1650
+ responseSchema?: any;
1651
+ }>;
1652
+ namespace: string;
1653
+ entrypoint?: string | undefined;
1654
+ }>;
1655
+ declare const PluginMetadataSchema: z.ZodObject<{
1656
+ id: z.ZodString;
1657
+ resourceType: z.ZodString;
1658
+ provider: z.ZodString;
1659
+ version: z.ZodString;
1660
+ name: z.ZodString;
1661
+ actions: z.ZodArray<z.ZodString, "many">;
1662
+ auth: z.ZodObject<{
1663
+ pop: z.ZodObject<{
1664
+ version: z.ZodNumber;
1665
+ }, "strip", z.ZodTypeAny, {
1666
+ version: number;
1667
+ }, {
1668
+ version: number;
1669
+ }>;
1670
+ }, "strip", z.ZodTypeAny, {
1671
+ pop: {
1672
+ version: number;
1673
+ };
1674
+ }, {
1675
+ pop: {
1676
+ version: number;
1677
+ };
1678
+ }>;
1679
+ supports: z.ZodObject<{
1680
+ enforcement: z.ZodArray<z.ZodString, "many">;
1681
+ }, "strip", z.ZodTypeAny, {
1682
+ enforcement: string[];
1683
+ }, {
1684
+ enforcement: string[];
1685
+ }>;
1686
+ extractors: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
1687
+ /** Reference to core extractor by name (e.g., "openai-compatible", "gemini") */
1688
+ type: z.ZodOptional<z.ZodString>;
1689
+ /** Custom extraction config (for future use) */
1690
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1691
+ }, "strip", z.ZodTypeAny, {
1692
+ type?: string | undefined;
1693
+ config?: Record<string, unknown> | undefined;
1694
+ }, {
1695
+ type?: string | undefined;
1696
+ config?: Record<string, unknown> | undefined;
1697
+ }>>>;
1698
+ credentialSchema: z.ZodOptional<z.ZodObject<{
1699
+ fields: z.ZodArray<z.ZodObject<{
1700
+ name: z.ZodString;
1701
+ type: z.ZodEnum<["string", "secret", "url", "number", "boolean"]>;
1702
+ label: z.ZodString;
1703
+ description: z.ZodOptional<z.ZodString>;
1704
+ required: z.ZodDefault<z.ZodBoolean>;
1705
+ default: z.ZodOptional<z.ZodUnknown>;
1706
+ }, "strip", z.ZodTypeAny, {
1707
+ type: "string" | "number" | "boolean" | "url" | "secret";
1708
+ name: string;
1709
+ required: boolean;
1710
+ label: string;
1711
+ description?: string | undefined;
1712
+ default?: unknown;
1713
+ }, {
1714
+ type: "string" | "number" | "boolean" | "url" | "secret";
1715
+ name: string;
1716
+ label: string;
1717
+ description?: string | undefined;
1718
+ required?: boolean | undefined;
1719
+ default?: unknown;
1720
+ }>, "many">;
1721
+ }, "strip", z.ZodTypeAny, {
1722
+ fields: {
1723
+ type: "string" | "number" | "boolean" | "url" | "secret";
1724
+ name: string;
1725
+ required: boolean;
1726
+ label: string;
1727
+ description?: string | undefined;
1728
+ default?: unknown;
1729
+ }[];
1730
+ }, {
1731
+ fields: {
1732
+ type: "string" | "number" | "boolean" | "url" | "secret";
1733
+ name: string;
1734
+ label: string;
1735
+ description?: string | undefined;
1736
+ required?: boolean | undefined;
1737
+ default?: unknown;
1738
+ }[];
1739
+ }>>;
1740
+ client: z.ZodOptional<z.ZodObject<{
1741
+ namespace: z.ZodString;
1742
+ actions: z.ZodRecord<z.ZodString, z.ZodObject<{
1743
+ requestSchema: z.ZodOptional<z.ZodAny>;
1744
+ responseSchema: z.ZodOptional<z.ZodAny>;
1745
+ description: z.ZodOptional<z.ZodString>;
1746
+ }, "strip", z.ZodTypeAny, {
1747
+ description?: string | undefined;
1748
+ requestSchema?: any;
1749
+ responseSchema?: any;
1750
+ }, {
1751
+ description?: string | undefined;
1752
+ requestSchema?: any;
1753
+ responseSchema?: any;
1754
+ }>>;
1755
+ entrypoint: z.ZodOptional<z.ZodString>;
1756
+ }, "strip", z.ZodTypeAny, {
1757
+ actions: Record<string, {
1758
+ description?: string | undefined;
1759
+ requestSchema?: any;
1760
+ responseSchema?: any;
1761
+ }>;
1762
+ namespace: string;
1763
+ entrypoint?: string | undefined;
1764
+ }, {
1765
+ actions: Record<string, {
1766
+ description?: string | undefined;
1767
+ requestSchema?: any;
1768
+ responseSchema?: any;
1769
+ }>;
1770
+ namespace: string;
1771
+ entrypoint?: string | undefined;
1772
+ }>>;
1773
+ }, "strip", z.ZodTypeAny, {
1774
+ name: string;
1775
+ id: string;
1776
+ actions: string[];
1777
+ version: string;
1778
+ auth: {
1779
+ pop: {
1780
+ version: number;
1781
+ };
1782
+ };
1783
+ supports: {
1784
+ enforcement: string[];
1785
+ };
1786
+ resourceType: string;
1787
+ provider: string;
1788
+ extractors?: Record<string, {
1789
+ type?: string | undefined;
1790
+ config?: Record<string, unknown> | undefined;
1791
+ }> | undefined;
1792
+ credentialSchema?: {
1793
+ fields: {
1794
+ type: "string" | "number" | "boolean" | "url" | "secret";
1795
+ name: string;
1796
+ required: boolean;
1797
+ label: string;
1798
+ description?: string | undefined;
1799
+ default?: unknown;
1800
+ }[];
1801
+ } | undefined;
1802
+ client?: {
1803
+ actions: Record<string, {
1804
+ description?: string | undefined;
1805
+ requestSchema?: any;
1806
+ responseSchema?: any;
1807
+ }>;
1808
+ namespace: string;
1809
+ entrypoint?: string | undefined;
1810
+ } | undefined;
1811
+ }, {
1812
+ name: string;
1813
+ id: string;
1814
+ actions: string[];
1815
+ version: string;
1816
+ auth: {
1817
+ pop: {
1818
+ version: number;
1819
+ };
1820
+ };
1821
+ supports: {
1822
+ enforcement: string[];
1823
+ };
1824
+ resourceType: string;
1825
+ provider: string;
1826
+ extractors?: Record<string, {
1827
+ type?: string | undefined;
1828
+ config?: Record<string, unknown> | undefined;
1829
+ }> | undefined;
1830
+ credentialSchema?: {
1831
+ fields: {
1832
+ type: "string" | "number" | "boolean" | "url" | "secret";
1833
+ name: string;
1834
+ label: string;
1835
+ description?: string | undefined;
1836
+ required?: boolean | undefined;
1837
+ default?: unknown;
1838
+ }[];
1839
+ } | undefined;
1840
+ client?: {
1841
+ actions: Record<string, {
1842
+ description?: string | undefined;
1843
+ requestSchema?: any;
1844
+ responseSchema?: any;
1845
+ }>;
1846
+ namespace: string;
1847
+ entrypoint?: string | undefined;
1848
+ } | undefined;
1849
+ }>;
1850
+ type PluginMetadata = z.infer<typeof PluginMetadataSchema>;
1851
+ /**
1852
+ * Validate plugin object has correct metadata.
1853
+ */
1854
+ declare function validatePluginMetadata(plugin: unknown): {
1855
+ valid: boolean;
1856
+ error?: string;
1857
+ metadata?: PluginMetadata;
1858
+ };
1859
+ /**
1860
+ * Discovery entry format for plugins.
1861
+ */
1862
+ interface PluginDiscoveryEntry {
1863
+ resourceId: string;
1864
+ actions: string[];
1865
+ auth: PluginAuth;
1866
+ version: string;
1867
+ constraints: {
1868
+ supports: string[];
1869
+ };
1870
+ /** Client entrypoint info (if SDK-compatible) */
1871
+ client?: {
1872
+ namespace: string;
1873
+ entrypoint: string;
1874
+ };
1875
+ }
1876
+ /**
1877
+ * Convert plugin to discovery entry format.
1878
+ * Includes version for client compatibility checks.
1879
+ *
1880
+ * TODO: Add version compatibility negotiation in future iteration.
1881
+ * The version exposed here allows target apps to verify they are
1882
+ * using a compatible client version.
1883
+ */
1884
+ declare function pluginToDiscoveryEntry(plugin: PluginContract): PluginDiscoveryEntry;
1885
+ /**
1886
+ * Base plugin options for creating plugins.
1887
+ */
1888
+ interface CreatePluginOptions {
1889
+ id: string;
1890
+ resourceType: string;
1891
+ provider: string;
1892
+ version: string;
1893
+ name: string;
1894
+ actions: string[];
1895
+ auth?: PluginAuth;
1896
+ supports?: PluginSupports;
1897
+ extractors?: Record<string, ExtractorDescriptor>;
1898
+ credentialSchema?: PluginCredentialSchema;
1899
+ /** Client contract metadata for SDK-compatible plugins */
1900
+ client?: PluginClientContract;
1901
+ }
1902
+ /**
1903
+ * Default auth configuration.
1904
+ */
1905
+ declare const DEFAULT_PLUGIN_AUTH: PluginAuth;
1906
+ /**
1907
+ * Default supports configuration.
1908
+ */
1909
+ declare const DEFAULT_PLUGIN_SUPPORTS: PluginSupports;
1910
+ /**
1911
+ * Helper to create plugin with defaults.
1912
+ */
1913
+ declare function createPluginBase(options: CreatePluginOptions): {
1914
+ id: string;
1915
+ resourceType: string;
1916
+ provider: string;
1917
+ version: string;
1918
+ name: string;
1919
+ actions: string[];
1920
+ auth: PluginAuth;
1921
+ supports: PluginSupports;
1922
+ extractors?: Record<string, ExtractorDescriptor>;
1923
+ credentialSchema?: PluginCredentialSchema;
1924
+ client?: PluginClientContract;
1925
+ };
1926
+
1927
+ /**
1928
+ * Preset duration identifiers.
1929
+ * Apps can request these, and the proxy recognizes them.
1930
+ */
1931
+ type DurationPresetId = "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever" | "custom";
1932
+ /**
1933
+ * Duration preset definition.
1934
+ */
1935
+ interface DurationPreset {
1936
+ id: DurationPresetId;
1937
+ label: string;
1938
+ description: string;
1939
+ /** Duration in milliseconds, null = never expires */
1940
+ durationMs: number | null;
1941
+ /** Suggested for short-term testing */
1942
+ isTemporary?: boolean;
1943
+ /** Suggested for production use */
1944
+ isRecommended?: boolean;
1945
+ }
1946
+ /**
1947
+ * All available duration presets in order of duration.
1948
+ */
1949
+ declare const DURATION_PRESETS: DurationPreset[];
1950
+ /**
1951
+ * Get a preset by ID.
1952
+ */
1953
+ declare function getDurationPreset(id: DurationPresetId): DurationPreset | undefined;
1954
+ /**
1955
+ * Calculate expiry date from a duration preset ID.
1956
+ * @returns Date object or null for "forever"
1957
+ */
1958
+ declare function getExpiryFromDurationPreset(presetId: DurationPresetId, fromDate?: Date): Date | null;
1959
+ /**
1960
+ * Calculate expiry date from a duration in milliseconds.
1961
+ */
1962
+ declare function getExpiryFromDuration(durationMs: number, fromDate?: Date): Date;
1963
+ /**
1964
+ * Find the closest matching preset for a given duration.
1965
+ */
1966
+ declare function findClosestPreset(durationMs: number | null): DurationPreset;
1967
+ /**
1968
+ * Format a duration in milliseconds to human readable.
1969
+ */
1970
+ declare function formatDuration(durationMs: number | null): string;
1971
+ /**
1972
+ * Format an expiry date relative to now.
1973
+ */
1974
+ declare function formatExpiryRelative(expiresAt: Date | null): string;
1975
+ /**
1976
+ * Duration preset ID schema for validation.
1977
+ */
1978
+ declare const DurationPresetIdSchema: z.ZodEnum<["1_hour", "4_hours", "24_hours", "1_week", "1_month", "3_months", "1_year", "forever", "custom"]>;
1979
+ /**
1980
+ * Requested duration schema.
1981
+ * Apps can specify their preferred duration when requesting permissions.
1982
+ */
1983
+ declare const RequestedDurationSchema: z.ZodUnion<[z.ZodObject<{
1984
+ type: z.ZodLiteral<"preset">;
1985
+ preset: z.ZodEnum<["1_hour", "4_hours", "24_hours", "1_week", "1_month", "3_months", "1_year", "forever", "custom"]>;
1986
+ }, "strip", z.ZodTypeAny, {
1987
+ type: "preset";
1988
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
1989
+ }, {
1990
+ type: "preset";
1991
+ preset: "custom" | "1_hour" | "4_hours" | "24_hours" | "1_week" | "1_month" | "3_months" | "1_year" | "forever";
1992
+ }>, z.ZodObject<{
1993
+ type: z.ZodLiteral<"duration">;
1994
+ durationMs: z.ZodNumber;
1995
+ }, "strip", z.ZodTypeAny, {
1996
+ type: "duration";
1997
+ durationMs: number;
1998
+ }, {
1999
+ type: "duration";
2000
+ durationMs: number;
2001
+ }>, z.ZodObject<{
2002
+ type: z.ZodLiteral<"until">;
2003
+ expiresAt: z.ZodString;
2004
+ }, "strip", z.ZodTypeAny, {
2005
+ type: "until";
2006
+ expiresAt: string;
2007
+ }, {
2008
+ type: "until";
2009
+ expiresAt: string;
2010
+ }>]>;
2011
+ type RequestedDuration = z.infer<typeof RequestedDurationSchema>;
2012
+ /**
2013
+ * Resolve a RequestedDuration to an expiry Date (or null for forever).
2014
+ */
2015
+ declare function resolveRequestedDuration(duration: RequestedDuration | undefined, fromDate?: Date): Date | null;
2016
+ /**
2017
+ * Create a preset-based RequestedDuration.
2018
+ */
2019
+ declare function createPresetDuration(preset: DurationPresetId): RequestedDuration;
2020
+ /**
2021
+ * Create a duration-based RequestedDuration.
2022
+ */
2023
+ declare function createDurationMs(durationMs: number): RequestedDuration;
2024
+ /**
2025
+ * Create an until-based RequestedDuration.
2026
+ */
2027
+ declare function createUntilDuration(expiresAt: Date): RequestedDuration;
2028
+
2029
+ /**
2030
+ * Resource identifier format: <resourceType>:<provider>
2031
+ * Examples: llm:groq, llm:gemini, mail:resend
2032
+ */
2033
+ type ResourceId = `${string}:${string}`;
2034
+ /**
2035
+ * Parse a resource ID into its components.
2036
+ */
2037
+ declare function parseResourceId(resourceId: string): {
2038
+ resourceType: string;
2039
+ provider: string;
2040
+ };
2041
+ /**
2042
+ * Create a resource ID from components.
2043
+ */
2044
+ declare function createResourceId(resourceType: string, provider: string): ResourceId;
2045
+ /**
2046
+ * Pairing string info parsed from pair::<url>::<code>
2047
+ */
2048
+ interface PairingInfo {
2049
+ proxyUrl: string;
2050
+ connectCode: string;
2051
+ }
2052
+ /**
2053
+ * Rate limit configuration.
2054
+ */
2055
+ interface RateLimitConfig {
2056
+ maxRequests: number;
2057
+ windowSeconds: number;
2058
+ }
2059
+ /**
2060
+ * Permission request for an app.
2061
+ */
2062
+ interface PermissionRequest {
2063
+ resourceId: string;
2064
+ actions: string[];
2065
+ constraints?: Record<string, unknown>;
2066
+ rateLimit?: RateLimitConfig;
2067
+ }
2068
+ /**
2069
+ * App metadata for registration.
2070
+ */
2071
+ interface AppMetadata {
2072
+ name: string;
2073
+ description?: string;
2074
+ homepage?: string;
2075
+ }
2076
+ /**
2077
+ * Gateway config stored after approval.
2078
+ */
2079
+ interface GatewayConfig {
2080
+ appId: string;
2081
+ proxyUrl: string;
2082
+ }
2083
+ /**
2084
+ * Resource constraint types (generic).
2085
+ */
2086
+ interface ResourceConstraints {
2087
+ allowedModels?: string[];
2088
+ maxOutputTokens?: number;
2089
+ maxInputTokens?: number;
2090
+ allowStreaming?: boolean;
2091
+ allowedFromDomains?: string[];
2092
+ maxRecipients?: number;
2093
+ allowHtml?: boolean;
2094
+ maxRequestBodySize?: number;
2095
+ custom?: Record<string, unknown>;
2096
+ }
2097
+
2098
+ export { type AccessPolicy, type AppMetadata, AppMetadataSchema, type BurstConfig, type CanonicalRequestParams, type ChatCompletionRequest, ChatCompletionRequestSchema, type ChatMessage, ChatMessageSchema, type CreatePluginOptions, type CredentialField, CredentialFieldSchema, DEFAULT_PLUGIN_AUTH, DEFAULT_PLUGIN_SUPPORTS, DURATION_PRESETS, type DurationPreset, type DurationPresetId, DurationPresetIdSchema, EXPIRY_PRESETS, type EmailConstraints, type EnforcementFields, EnforcementFieldsSchema, type EnforcementMeta, EnforcementMetaSchema, type EnforcementPolicy, type EnforcementResult, ErrorCode, type ExpiryPreset, type ExpiryPresetOption, type ExtractedRequest, ExtractedRequestSchema, type ExtractorDescriptor, ExtractorDescriptorSchema, type GatewayConfig, GatewayError, type GatewayErrorResponse, GatewayErrorResponseSchema, type GatewayInfo, GatewayInfoSchema, type HTTPConstraints, type InstallRequest, InstallRequestSchema, type LLMConstraints, type ModelRateLimit, POP_VERSION, type PairingInfo, type PermissionRequest, PermissionRequestSchema, type PluginActionSchemaDescriptor, type PluginAuth, PluginAuthSchema, type PluginClientContract, PluginClientContractSchema, type PluginContract, type PluginCredentialSchema, PluginCredentialSchemaSchema, type PluginDiscoveryEntry, type PluginExecuteContext, type PluginExecuteOptions, type PluginExecuteResult, type PluginMappedError, type PluginMetadata, PluginMetadataSchema, type PluginResourceConstraints, type PluginSupports, PluginSupportsSchema, type PluginUsageMetrics, type PluginValidationResult, PopErrorCode, type PopHeadersV1, PopHeadersV1Schema, type QuotaConfig, RATE_LIMIT_PRESETS, type RateLimitConfig, type RateLimitPreset, type RequestedDuration, RequestedDurationSchema, ResourceAuthSchema, type ResourceConstraints, type ResourceDiscoveryEntry, ResourceDiscoveryEntrySchema, type ResourceId, type ResourcesDiscoveryResponse, ResourcesDiscoveryResponseSchema, type TimeWindow, type TokenBudget, buildCanonicalRequestV1, createDurationMs, createErrorResponse, createPluginBase, createPresetDuration, createResourceId, createUntilDuration, findClosestPreset, formatAccessPolicySummary, formatDuration, formatExpiryRelative, getDurationPreset, getErrorStatus, getExpiryFromDuration, getExpiryFromDurationPreset, getExpiryFromPreset, getPathWithQuery, isPermissionValidNow, parseResourceId, pluginToDiscoveryEntry, resolveRequestedDuration, resourceRequiredError, validatePluginMetadata };