@meistrari/agent-sdk 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,17 +1,18 @@
1
1
  'use strict';
2
2
 
3
3
  const vaultSdk = require('@meistrari/vault-sdk');
4
- const zod = require('zod');
4
+ const schemas = require('./schemas.cjs');
5
+ require('zod');
5
6
 
6
- var __defProp = Object.defineProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __publicField = (obj, key, value) => {
9
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ var __defProp$1 = Object.defineProperty;
8
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __publicField$1 = (obj, key, value) => {
10
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
10
11
  return value;
11
12
  };
12
13
  class DataTokenAuthStrategy {
13
14
  constructor(dataToken) {
14
- __publicField(this, "dataToken");
15
+ __publicField$1(this, "dataToken");
15
16
  this.dataToken = dataToken;
16
17
  }
17
18
  getHeaders() {
@@ -22,7 +23,7 @@ class DataTokenAuthStrategy {
22
23
  }
23
24
  class APIKeyAuthStrategy {
24
25
  constructor(apiKey) {
25
- __publicField(this, "apiKey");
26
+ __publicField$1(this, "apiKey");
26
27
  this.apiKey = apiKey;
27
28
  }
28
29
  getHeaders() {
@@ -32,6 +33,12 @@ class APIKeyAuthStrategy {
32
33
  }
33
34
  }
34
35
 
36
+ var __defProp = Object.defineProperty;
37
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
38
+ var __publicField = (obj, key, value) => {
39
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
40
+ return value;
41
+ };
35
42
  class FetchError extends Error {
36
43
  constructor(message, url, method, response) {
37
44
  super(message);
@@ -39,6 +46,7 @@ class FetchError extends Error {
39
46
  this.url = url;
40
47
  this.method = method;
41
48
  this.response = response;
49
+ __publicField(this, "kind", "http");
42
50
  this.name = "FetchError";
43
51
  }
44
52
  static async from(url, method, response) {
@@ -54,571 +62,22 @@ ${text}`,
54
62
  );
55
63
  }
56
64
  }
57
-
58
- function getDefaultExportFromCjs (x) {
59
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
60
- }
61
-
62
- var openrouterModels = [
63
- {
64
- id: "openai/gpt-5.5",
65
- name: "OpenAI: GPT-5.5",
66
- context_length: 1050000,
67
- max_completion_tokens: 128000,
68
- pricing: {
69
- prompt_per_million: 5,
70
- completion_per_million: 30,
71
- input_cache_read_per_million: 0.5
72
- },
73
- supported_parameters: [
74
- "include_reasoning",
75
- "max_completion_tokens",
76
- "max_tokens",
77
- "reasoning",
78
- "response_format",
79
- "seed",
80
- "structured_outputs",
81
- "tool_choice",
82
- "tools"
83
- ],
84
- modality: "text+image+file->text",
85
- description: "GPT-5.5 is OpenAI’s frontier model designed for complex professional workloads, building on GPT-5.4 with stronger reasoning, higher reliability, and improved token efficiency on hard tasks. It features a 1M+ token..."
86
- },
87
- {
88
- id: "openai/gpt-5.4",
89
- name: "OpenAI: GPT-5.4",
90
- context_length: 1050000,
91
- max_completion_tokens: 128000,
92
- pricing: {
93
- prompt_per_million: 2.5,
94
- completion_per_million: 15,
95
- input_cache_read_per_million: 0.25
96
- },
97
- supported_parameters: [
98
- "include_reasoning",
99
- "max_completion_tokens",
100
- "max_tokens",
101
- "reasoning",
102
- "response_format",
103
- "seed",
104
- "structured_outputs",
105
- "tool_choice",
106
- "tools"
107
- ],
108
- modality: "text+image+file->text",
109
- description: "GPT-5.4 is OpenAI’s latest frontier model, unifying the Codex and GPT lines into a single system. It features a 1M+ token context window (922K input, 128K output) with support for..."
110
- },
111
- {
112
- id: "openai/gpt-5.3-codex",
113
- name: "OpenAI: GPT-5.3-Codex",
114
- context_length: 400000,
115
- max_completion_tokens: 128000,
116
- pricing: {
117
- prompt_per_million: 1.75,
118
- completion_per_million: 14,
119
- input_cache_read_per_million: 0.17
120
- },
121
- supported_parameters: [
122
- "include_reasoning",
123
- "max_completion_tokens",
124
- "max_tokens",
125
- "reasoning",
126
- "response_format",
127
- "seed",
128
- "structured_outputs",
129
- "tool_choice",
130
- "tools"
131
- ],
132
- modality: "text+image+file->text",
133
- description: "GPT-5.3-Codex is OpenAI’s most advanced agentic coding model, combining the frontier software engineering performance of GPT-5.2-Codex with the broader reasoning and professional knowledge capabilities of GPT-5.2. It achieves state-of-the-art results"
134
- },
135
- {
136
- id: "google/gemini-3.5-flash",
137
- name: "Google: Gemini 3.5 Flash",
138
- context_length: 1048576,
139
- max_completion_tokens: 65536,
140
- pricing: {
141
- prompt_per_million: 1.5,
142
- completion_per_million: 9,
143
- input_cache_read_per_million: 0.15
144
- },
145
- supported_parameters: [
146
- "include_reasoning",
147
- "max_tokens",
148
- "reasoning",
149
- "response_format",
150
- "seed",
151
- "stop",
152
- "structured_outputs",
153
- "temperature",
154
- "tool_choice",
155
- "tools",
156
- "top_p"
157
- ],
158
- modality: "text+image+file+audio+video->text",
159
- description: "Gemini 3.5 Flash is a fast multimodal Google model aimed at coding, reasoning, and parallel agent workflows with a Flash-tier cost profile."
160
- },
161
- {
162
- id: "google/gemini-3-flash-preview",
163
- name: "Google: Gemini 3 Flash Preview",
164
- context_length: 1048576,
165
- max_completion_tokens: 65536,
166
- pricing: {
167
- prompt_per_million: 0.5,
168
- completion_per_million: 3,
169
- input_cache_read_per_million: 0.05
170
- },
171
- supported_parameters: [
172
- "include_reasoning",
173
- "max_tokens",
174
- "reasoning",
175
- "response_format",
176
- "seed",
177
- "stop",
178
- "structured_outputs",
179
- "temperature",
180
- "tool_choice",
181
- "tools",
182
- "top_p"
183
- ],
184
- modality: "text+image+file+audio+video->text",
185
- description: "Gemini 3 Flash Preview is a high speed, high value thinking model designed for agentic workflows, multi turn chat, and coding assistance. It delivers near Pro level reasoning and tool..."
186
- },
187
- {
188
- id: "google/gemini-3.1-pro-preview",
189
- name: "Google: Gemini 3.1 Pro Preview",
190
- context_length: 1048576,
191
- max_completion_tokens: 65536,
192
- pricing: {
193
- prompt_per_million: 2,
194
- completion_per_million: 12,
195
- input_cache_read_per_million: 0.2
196
- },
197
- supported_parameters: [
198
- "include_reasoning",
199
- "max_tokens",
200
- "reasoning",
201
- "response_format",
202
- "seed",
203
- "stop",
204
- "structured_outputs",
205
- "temperature",
206
- "tool_choice",
207
- "tools",
208
- "top_p"
209
- ],
210
- modality: "text+image+file+audio+video->text",
211
- description: "Gemini 3.1 Pro Preview is Google’s frontier reasoning model, delivering enhanced software engineering performance, improved agentic reliability, and more efficient token usage across complex workflows. Building on the multimodal foundation..."
212
- },
213
- {
214
- id: "xiaomi/mimo-v2-pro",
215
- name: "Xiaomi: MiMo-V2-Pro",
216
- context_length: 1048576,
217
- max_completion_tokens: 131072,
218
- pricing: {
219
- prompt_per_million: 1,
220
- completion_per_million: 3,
221
- input_cache_read_per_million: 0.2
222
- },
223
- supported_parameters: [
224
- "frequency_penalty",
225
- "include_reasoning",
226
- "max_tokens",
227
- "presence_penalty",
228
- "reasoning",
229
- "response_format",
230
- "stop",
231
- "temperature",
232
- "tool_choice",
233
- "tools",
234
- "top_p"
235
- ],
236
- modality: "text->text",
237
- description: "MiMo-V2-Pro is Xiaomi's flagship foundation model, featuring over 1T total parameters and a 1M context length, deeply optimized for agentic scenarios. It is highly adaptable to general agent frameworks like..."
238
- },
239
- {
240
- id: "xiaomi/mimo-v2-omni",
241
- name: "Xiaomi: MiMo-V2-Omni",
242
- context_length: 262144,
243
- max_completion_tokens: 65536,
244
- pricing: {
245
- prompt_per_million: 0.4,
246
- completion_per_million: 2,
247
- input_cache_read_per_million: 0.08
248
- },
249
- supported_parameters: [
250
- "frequency_penalty",
251
- "include_reasoning",
252
- "max_tokens",
253
- "presence_penalty",
254
- "reasoning",
255
- "response_format",
256
- "stop",
257
- "temperature",
258
- "tool_choice",
259
- "tools",
260
- "top_p"
261
- ],
262
- modality: "text+image+audio+video->text",
263
- description: "MiMo-V2-Omni is a frontier omni-modal model that natively processes image, video, and audio inputs within a unified architecture. It combines strong multimodal perception with agentic capability - visual grounding, multi-step..."
264
- },
265
- {
266
- id: "moonshotai/kimi-k2.5",
267
- name: "MoonshotAI: Kimi K2.5",
268
- context_length: 262144,
269
- max_completion_tokens: 65535,
270
- pricing: {
271
- prompt_per_million: 0.38,
272
- completion_per_million: 1.72,
273
- input_cache_read_per_million: 0.19
274
- },
275
- supported_parameters: [
276
- "frequency_penalty",
277
- "include_reasoning",
278
- "logit_bias",
279
- "logprobs",
280
- "max_tokens",
281
- "min_p",
282
- "parallel_tool_calls",
283
- "presence_penalty",
284
- "reasoning",
285
- "repetition_penalty",
286
- "response_format",
287
- "seed",
288
- "stop",
289
- "structured_outputs",
290
- "temperature",
291
- "tool_choice",
292
- "tools",
293
- "top_k",
294
- "top_logprobs",
295
- "top_p"
296
- ],
297
- modality: "text+image->text",
298
- description: "Kimi K2.5 is Moonshot AI's native multimodal model, delivering state-of-the-art visual coding capability and a self-directed agent swarm paradigm. Built on Kimi K2 with continued pretraining over approximately 15T mixed..."
299
- },
300
- {
301
- id: "moonshotai/kimi-k2-thinking",
302
- name: "MoonshotAI: Kimi K2 Thinking",
303
- context_length: 262144,
304
- max_completion_tokens: null,
305
- pricing: {
306
- prompt_per_million: 0.6,
307
- completion_per_million: 2.5
308
- },
309
- supported_parameters: [
310
- "frequency_penalty",
311
- "include_reasoning",
312
- "logit_bias",
313
- "max_tokens",
314
- "min_p",
315
- "presence_penalty",
316
- "reasoning",
317
- "repetition_penalty",
318
- "response_format",
319
- "seed",
320
- "stop",
321
- "structured_outputs",
322
- "temperature",
323
- "tool_choice",
324
- "tools",
325
- "top_k",
326
- "top_p"
327
- ],
328
- modality: "text->text",
329
- description: "Kimi K2 Thinking is Moonshot AI’s most advanced open reasoning model to date, extending the K2 series into agentic, long-horizon reasoning. Built on the trillion-parameter Mixture-of-Experts (MoE) architecture introduced in..."
330
- },
331
- {
332
- id: "moonshotai/kimi-k2-0905",
333
- name: "MoonshotAI: Kimi K2 0905",
334
- context_length: 262144,
335
- max_completion_tokens: 262144,
336
- pricing: {
337
- prompt_per_million: 0.4,
338
- completion_per_million: 2
339
- },
340
- supported_parameters: [
341
- "frequency_penalty",
342
- "logit_bias",
343
- "logprobs",
344
- "max_tokens",
345
- "min_p",
346
- "presence_penalty",
347
- "repetition_penalty",
348
- "response_format",
349
- "seed",
350
- "stop",
351
- "structured_outputs",
352
- "temperature",
353
- "tool_choice",
354
- "tools",
355
- "top_k",
356
- "top_logprobs",
357
- "top_p"
358
- ],
359
- modality: "text->text",
360
- description: "Kimi K2 0905 is the September update of [Kimi K2 0711](moonshotai/kimi-k2). It is a large-scale Mixture-of-Experts (MoE) language model developed by Moonshot AI, featuring 1 trillion total parameters with 32..."
361
- },
362
- {
363
- id: "z-ai/glm-5.1",
364
- name: "Z.ai: GLM 5.1",
365
- context_length: 202752,
366
- max_completion_tokens: 131072,
367
- pricing: {
368
- prompt_per_million: 1.4,
369
- completion_per_million: 4.4,
370
- input_cache_read_per_million: 0.26
371
- },
372
- supported_parameters: [
373
- "frequency_penalty",
374
- "include_reasoning",
375
- "logit_bias",
376
- "logprobs",
377
- "max_tokens",
378
- "min_p",
379
- "presence_penalty",
380
- "reasoning",
381
- "repetition_penalty",
382
- "response_format",
383
- "seed",
384
- "stop",
385
- "structured_outputs",
386
- "temperature",
387
- "tool_choice",
388
- "tools",
389
- "top_k",
390
- "top_logprobs",
391
- "top_p"
392
- ],
393
- modality: "text->text",
394
- description: "GLM-5.1 delivers a major leap in coding capability, with particularly significant gains in handling long-horizon tasks. Unlike previous models built around minute-level interactions, GLM-5.1 can work independently and continuously on..."
395
- },
396
- {
397
- id: "z-ai/glm-5v-turbo",
398
- name: "Z.ai: GLM 5V Turbo",
399
- context_length: 202752,
400
- max_completion_tokens: 131072,
401
- pricing: {
402
- prompt_per_million: 1.2,
403
- completion_per_million: 4,
404
- input_cache_read_per_million: 0.24
405
- },
406
- supported_parameters: [
407
- "include_reasoning",
408
- "max_tokens",
409
- "reasoning",
410
- "response_format",
411
- "temperature",
412
- "tool_choice",
413
- "tools",
414
- "top_p"
415
- ],
416
- modality: "text+image+video->text",
417
- description: "GLM-5V-Turbo is Z.ai’s first native multimodal agent foundation model, built for vision-based coding and agent-driven tasks. It natively handles image, video, and text inputs, excels at long-horizon planning, complex coding,..."
418
- },
419
- {
420
- id: "minimax/minimax-m2.7",
421
- name: "MiniMax: MiniMax M2.7",
422
- context_length: 204800,
423
- max_completion_tokens: 131072,
424
- pricing: {
425
- prompt_per_million: 0.3,
426
- completion_per_million: 1.2,
427
- input_cache_read_per_million: 0.06
428
- },
429
- supported_parameters: [
430
- "include_reasoning",
431
- "max_tokens",
432
- "reasoning",
433
- "response_format",
434
- "temperature",
435
- "tool_choice",
436
- "tools",
437
- "top_p"
438
- ],
439
- modality: "text->text",
440
- description: "MiniMax-M2.7 is a next-generation large language model designed for autonomous, real-world productivity and continuous improvement. Built to actively participate in its own evolution, M2.7 integrates advanced agentic capabilities through multi-agent."
441
- },
442
- {
443
- id: "minimax/minimax-m2.5",
444
- name: "MiniMax: MiniMax M2.5",
445
- context_length: 196608,
446
- max_completion_tokens: 65536,
447
- pricing: {
448
- prompt_per_million: 0.12,
449
- completion_per_million: 0.99,
450
- input_cache_read_per_million: 0.06
451
- },
452
- supported_parameters: [
453
- "frequency_penalty",
454
- "include_reasoning",
455
- "logit_bias",
456
- "logprobs",
457
- "max_tokens",
458
- "min_p",
459
- "parallel_tool_calls",
460
- "presence_penalty",
461
- "reasoning",
462
- "reasoning_effort",
463
- "repetition_penalty",
464
- "response_format",
465
- "seed",
466
- "stop",
467
- "structured_outputs",
468
- "temperature",
469
- "tool_choice",
470
- "tools",
471
- "top_k",
472
- "top_logprobs",
473
- "top_p"
474
- ],
475
- modality: "text->text",
476
- description: "MiniMax-M2.5 is a SOTA large language model designed for real-world productivity. Trained in a diverse range of complex real-world digital working environments, M2.5 builds upon the coding expertise of M2.1..."
477
- }
478
- ];
479
-
480
- const openrouterCatalog = /*@__PURE__*/getDefaultExportFromCjs(openrouterModels);
481
-
482
- const nativeAnthropicModelIds = [
483
- "claude-sonnet-4-5",
484
- "claude-sonnet-4-6",
485
- "claude-haiku-4-5",
486
- "claude-opus-4-6",
487
- "claude-opus-4-7",
488
- "claude-opus-4-8"
489
- ];
490
- zod.z.enum(nativeAnthropicModelIds);
491
- const openrouterModelIds = openrouterCatalog.map((entry) => entry.id);
492
- const modelSchema = zod.z.enum([
493
- ...nativeAnthropicModelIds,
494
- ...openrouterModelIds
495
- ]);
496
-
497
- const vaultReferenceSchema = zod.z.string().regex(/^vault:\/\/\S+$/, "vaultRef must start with vault:// and cannot contain whitespace");
498
- const agentInputSchema = zod.z.object({
499
- vaultRef: vaultReferenceSchema,
500
- filename: zod.z.string().min(1, "Filename is required").max(255, "Filename must be 255 characters or less"),
501
- metadata: zod.z.string().max(16384, "Metadata must be 16,384 characters or less").optional()
502
- }).strict();
503
- const executeAgentRequestSchema = zod.z.object({
504
- sessionId: zod.z.string().uuid().optional(),
505
- organizationName: zod.z.string().min(1).max(200).optional(),
506
- repository: zod.z.string().min(1).max(200).optional(),
507
- ref: zod.z.string().max(200).optional(),
508
- message: zod.z.string().min(1).max(8e5).optional(),
509
- inputs: zod.z.array(agentInputSchema).optional(),
510
- environmentVariables: zod.z.record(zod.z.string(), zod.z.string()).optional(),
511
- recover: zod.z.boolean().optional()
512
- }).strict().superRefine((data, ctx) => {
513
- if (!data.sessionId) {
514
- if (!data.organizationName) {
515
- ctx.addIssue({ code: "custom", message: "organizationName is required for new sessions", path: ["organizationName"] });
516
- }
517
- if (!data.repository) {
518
- ctx.addIssue({ code: "custom", message: "repository is required for new sessions", path: ["repository"] });
519
- }
520
- if (!data.message) {
521
- ctx.addIssue({ code: "custom", message: "message is required for new sessions", path: ["message"] });
522
- }
523
- } else if (!data.recover && !data.message) {
524
- ctx.addIssue({ code: "custom", message: "message is required for session continuations", path: ["message"] });
525
- }
526
- if (data.recover && !data.sessionId) {
527
- ctx.addIssue({ code: "custom", message: "sessionId is required when recover is true", path: ["sessionId"] });
65
+ class NetworkError extends Error {
66
+ constructor(url, method, cause) {
67
+ super(`Failed to ${method} ${url}: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
68
+ this.url = url;
69
+ this.method = method;
70
+ this.cause = cause;
71
+ __publicField(this, "kind", "network");
72
+ this.name = "NetworkError";
528
73
  }
529
- });
530
- const executeAgentResponseSchema = zod.z.object({
531
- success: zod.z.boolean(),
532
- sessionId: zod.z.string().optional(),
533
- error: zod.z.string().optional()
534
- });
535
- const repositoryNameSchema = zod.z.string().min(1, "Repository is required").max(200, "Repository must be 200 characters or less").regex(/^[\w.-]+$/, "Repository contains unsupported characters");
536
- const updateAgentModelRequestSchema = zod.z.object({
537
- repository: repositoryNameSchema,
538
- model: modelSchema,
539
- commitMessage: zod.z.string().max(4096, "Commit message must be 4096 characters or less").optional()
540
- }).strict();
541
- const updateAgentModelResponseSchema = zod.z.object({
542
- success: zod.z.boolean(),
543
- organizationName: zod.z.string().optional(),
544
- repository: zod.z.string().optional(),
545
- branch: zod.z.string().optional(),
546
- commitHash: zod.z.string().optional(),
547
- model: modelSchema.optional(),
548
- providerTemplate: zod.z.string().optional(),
549
- templateSynced: zod.z.boolean().optional(),
550
- files: zod.z.array(zod.z.string()).optional(),
551
- deletedFiles: zod.z.array(zod.z.string()).optional(),
552
- error: zod.z.string().optional()
553
- });
554
-
555
- const sessionStatusSchema = zod.z.enum([
556
- "pending",
557
- "running",
558
- "completed",
559
- "failed",
560
- "waiting_messages",
561
- "cancelled"
562
- ]);
563
- const sessionTimelineIdSchema = zod.z.string().min(1, "Session ID is required");
564
- const sessionTimelineResponseSchema = zod.z.object({
565
- sessionId: zod.z.string(),
566
- status: zod.z.string(),
567
- metrics: zod.z.record(zod.z.string(), zod.z.unknown()),
568
- prompt: zod.z.record(zod.z.string(), zod.z.unknown()),
569
- spans: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown()))
570
- });
571
- const sessionStatusEventSchema = zod.z.object({
572
- kind: zod.z.literal("status"),
573
- sessionId: zod.z.string(),
574
- status: sessionStatusSchema,
575
- error: zod.z.string().optional(),
576
- createdAt: zod.z.number(),
577
- updatedAt: zod.z.number()
578
- });
579
- const sessionStepsEventSchema = zod.z.object({
580
- kind: zod.z.literal("steps"),
581
- sessionId: zod.z.string(),
582
- status: sessionStatusSchema,
583
- steps: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())),
584
- nextCursor: zod.z.number().nullable(),
585
- createdAt: zod.z.number(),
586
- updatedAt: zod.z.number()
587
- });
588
- const sessionResultEventSchema = zod.z.object({
589
- kind: zod.z.literal("result"),
590
- sessionId: zod.z.string(),
591
- status: zod.z.enum(["completed", "waiting_messages"]),
592
- result: zod.z.record(zod.z.string(), zod.z.unknown()),
593
- nextCursor: zod.z.number().nullable(),
594
- createdAt: zod.z.number(),
595
- updatedAt: zod.z.number()
596
- });
597
- const sessionErrorEventSchema = zod.z.object({
598
- kind: zod.z.literal("error"),
599
- sessionId: zod.z.string(),
600
- error: zod.z.string()
601
- });
602
- const sessionTimelineFinalizeEventSchema = zod.z.object({
603
- kind: zod.z.literal("timeline-finalize"),
604
- sessionId: zod.z.string(),
605
- status: sessionStatusSchema,
606
- metrics: zod.z.record(zod.z.string(), zod.z.unknown()).nullable().optional(),
607
- prompt: zod.z.record(zod.z.string(), zod.z.unknown()).nullable().optional(),
608
- spans: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).nullable().optional(),
609
- events: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).nullable().optional(),
610
- continuation: zod.z.record(zod.z.string(), zod.z.unknown()).nullable().optional(),
611
- createdAt: zod.z.number(),
612
- updatedAt: zod.z.number()
613
- });
614
- const sessionStreamEventSchema = zod.z.discriminatedUnion("kind", [
615
- sessionStatusEventSchema,
616
- sessionStepsEventSchema,
617
- sessionResultEventSchema,
618
- sessionTimelineFinalizeEventSchema,
619
- sessionErrorEventSchema
620
- ]);
621
- const SESSION_STREAM_EVENT_KINDS = /* @__PURE__ */ new Set(["status", "steps", "result", "timeline-finalize", "error"]);
74
+ }
75
+ function isFetchError(error) {
76
+ return error instanceof FetchError;
77
+ }
78
+ function isNetworkError(error) {
79
+ return error instanceof NetworkError;
80
+ }
622
81
 
623
82
  function normalizeStreamBuffer(buffer) {
624
83
  return buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
@@ -665,9 +124,9 @@ function getEventKind(event) {
665
124
  }
666
125
  function parseKnownEvent(event) {
667
126
  const eventKind = getEventKind(event);
668
- if (!eventKind || !SESSION_STREAM_EVENT_KINDS.has(eventKind))
127
+ if (!eventKind || !schemas.SESSION_STREAM_EVENT_KINDS.has(eventKind))
669
128
  return void 0;
670
- const parsed = sessionStreamEventSchema.safeParse(event);
129
+ const parsed = schemas.sessionStreamEventSchema.safeParse(event);
671
130
  if (!parsed.success)
672
131
  throw new Error(parsed.error.message);
673
132
  return parsed.data;
@@ -728,42 +187,49 @@ function agentClient(config) {
728
187
  headers.set("Accept", params.accept ?? "application/json");
729
188
  if (params.body !== void 0)
730
189
  headers.set("Content-Type", "application/json");
731
- const response = await fetch(url, {
732
- method: params.method,
733
- headers,
734
- body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
735
- signal: params.signal
736
- });
190
+ let response;
191
+ try {
192
+ response = await fetch(url, {
193
+ method: params.method,
194
+ headers,
195
+ body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
196
+ signal: params.signal
197
+ });
198
+ } catch (error) {
199
+ if (error instanceof DOMException && error.name === "AbortError")
200
+ throw error;
201
+ throw new NetworkError(url.toString(), params.method, error);
202
+ }
737
203
  if (!response.ok)
738
204
  throw await FetchError.from(url.toString(), params.method, response);
739
205
  return response;
740
206
  }
741
207
  async function executeAgent(input) {
742
- const body = executeAgentRequestSchema.parse(input);
208
+ const body = schemas.executeAgentRequestSchema.parse(input);
743
209
  const response = await request({
744
210
  method: "POST",
745
211
  path: "/v4/agents/execute",
746
212
  body
747
213
  });
748
- return executeAgentResponseSchema.parse(await response.json());
214
+ return schemas.executeAgentResponseSchema.parse(await response.json());
749
215
  }
750
216
  async function updateAgentModel(input) {
751
- const { repository, ...body } = updateAgentModelRequestSchema.parse(input);
217
+ const { repository, ...body } = schemas.updateAgentModelRequestSchema.parse(input);
752
218
  const response = await request({
753
219
  method: "PUT",
754
220
  path: `/v4/agents/${encodeURIComponent(repository)}/model`,
755
221
  body
756
222
  });
757
- return updateAgentModelResponseSchema.parse(await response.json());
223
+ return schemas.updateAgentModelResponseSchema.parse(await response.json());
758
224
  }
759
225
  async function fetchTimeline(sessionId, options) {
760
- const parsedSessionId = sessionTimelineIdSchema.parse(sessionId);
226
+ const parsedSessionId = schemas.sessionTimelineIdSchema.parse(sessionId);
761
227
  const response = await request({
762
228
  method: "GET",
763
229
  path: `/v4/sessions/${encodeURIComponent(parsedSessionId)}/timeline`,
764
230
  signal: options?.signal
765
231
  });
766
- return sessionTimelineResponseSchema.parse(await response.json());
232
+ return schemas.sessionTimelineResponseSchema.parse(await response.json());
767
233
  }
768
234
  async function streamSession(sessionId, options) {
769
235
  const response = await request({
@@ -807,14 +273,8 @@ function agentClient(config) {
807
273
  exports.APIKeyAuthStrategy = APIKeyAuthStrategy;
808
274
  exports.DataTokenAuthStrategy = DataTokenAuthStrategy;
809
275
  exports.FetchError = FetchError;
276
+ exports.NetworkError = NetworkError;
810
277
  exports.agentClient = agentClient;
811
- exports.agentInputSchema = agentInputSchema;
812
- exports.executeAgentRequestSchema = executeAgentRequestSchema;
813
- exports.executeAgentResponseSchema = executeAgentResponseSchema;
278
+ exports.isFetchError = isFetchError;
279
+ exports.isNetworkError = isNetworkError;
814
280
  exports.parseSessionStream = parseSessionStream;
815
- exports.sessionStatusSchema = sessionStatusSchema;
816
- exports.sessionStreamEventSchema = sessionStreamEventSchema;
817
- exports.sessionTimelineIdSchema = sessionTimelineIdSchema;
818
- exports.sessionTimelineResponseSchema = sessionTimelineResponseSchema;
819
- exports.updateAgentModelRequestSchema = updateAgentModelRequestSchema;
820
- exports.updateAgentModelResponseSchema = updateAgentModelResponseSchema;