@meistrari/agent-sdk 0.2.0 → 0.3.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.
package/dist/index.mjs CHANGED
@@ -1,15 +1,16 @@
1
1
  import { VaultFile } from '@meistrari/vault-sdk';
2
- import { z } from 'zod';
2
+ import { SESSION_STREAM_EVENT_KINDS, sessionStreamEventSchema, executeAgentRequestSchema, executeAgentResponseSchema, updateAgentModelRequestSchema, updateAgentModelResponseSchema, sessionTimelineIdSchema, sessionTimelineResponseSchema } from './schemas.mjs';
3
+ import 'zod';
3
4
 
4
- var __defProp = Object.defineProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => {
7
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ var __defProp$1 = Object.defineProperty;
6
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __publicField$1 = (obj, key, value) => {
8
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
8
9
  return value;
9
10
  };
10
11
  class DataTokenAuthStrategy {
11
12
  constructor(dataToken) {
12
- __publicField(this, "dataToken");
13
+ __publicField$1(this, "dataToken");
13
14
  this.dataToken = dataToken;
14
15
  }
15
16
  getHeaders() {
@@ -20,7 +21,7 @@ class DataTokenAuthStrategy {
20
21
  }
21
22
  class APIKeyAuthStrategy {
22
23
  constructor(apiKey) {
23
- __publicField(this, "apiKey");
24
+ __publicField$1(this, "apiKey");
24
25
  this.apiKey = apiKey;
25
26
  }
26
27
  getHeaders() {
@@ -30,6 +31,12 @@ class APIKeyAuthStrategy {
30
31
  }
31
32
  }
32
33
 
34
+ var __defProp = Object.defineProperty;
35
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
36
+ var __publicField = (obj, key, value) => {
37
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
38
+ return value;
39
+ };
33
40
  class FetchError extends Error {
34
41
  constructor(message, url, method, response) {
35
42
  super(message);
@@ -37,6 +44,7 @@ class FetchError extends Error {
37
44
  this.url = url;
38
45
  this.method = method;
39
46
  this.response = response;
47
+ __publicField(this, "kind", "http");
40
48
  this.name = "FetchError";
41
49
  }
42
50
  static async from(url, method, response) {
@@ -52,571 +60,22 @@ ${text}`,
52
60
  );
53
61
  }
54
62
  }
55
-
56
- function getDefaultExportFromCjs (x) {
57
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
58
- }
59
-
60
- var openrouterModels = [
61
- {
62
- id: "openai/gpt-5.5",
63
- name: "OpenAI: GPT-5.5",
64
- context_length: 1050000,
65
- max_completion_tokens: 128000,
66
- pricing: {
67
- prompt_per_million: 5,
68
- completion_per_million: 30,
69
- input_cache_read_per_million: 0.5
70
- },
71
- supported_parameters: [
72
- "include_reasoning",
73
- "max_completion_tokens",
74
- "max_tokens",
75
- "reasoning",
76
- "response_format",
77
- "seed",
78
- "structured_outputs",
79
- "tool_choice",
80
- "tools"
81
- ],
82
- modality: "text+image+file->text",
83
- 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..."
84
- },
85
- {
86
- id: "openai/gpt-5.4",
87
- name: "OpenAI: GPT-5.4",
88
- context_length: 1050000,
89
- max_completion_tokens: 128000,
90
- pricing: {
91
- prompt_per_million: 2.5,
92
- completion_per_million: 15,
93
- input_cache_read_per_million: 0.25
94
- },
95
- supported_parameters: [
96
- "include_reasoning",
97
- "max_completion_tokens",
98
- "max_tokens",
99
- "reasoning",
100
- "response_format",
101
- "seed",
102
- "structured_outputs",
103
- "tool_choice",
104
- "tools"
105
- ],
106
- modality: "text+image+file->text",
107
- 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..."
108
- },
109
- {
110
- id: "openai/gpt-5.3-codex",
111
- name: "OpenAI: GPT-5.3-Codex",
112
- context_length: 400000,
113
- max_completion_tokens: 128000,
114
- pricing: {
115
- prompt_per_million: 1.75,
116
- completion_per_million: 14,
117
- input_cache_read_per_million: 0.17
118
- },
119
- supported_parameters: [
120
- "include_reasoning",
121
- "max_completion_tokens",
122
- "max_tokens",
123
- "reasoning",
124
- "response_format",
125
- "seed",
126
- "structured_outputs",
127
- "tool_choice",
128
- "tools"
129
- ],
130
- modality: "text+image+file->text",
131
- 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"
132
- },
133
- {
134
- id: "google/gemini-3.5-flash",
135
- name: "Google: Gemini 3.5 Flash",
136
- context_length: 1048576,
137
- max_completion_tokens: 65536,
138
- pricing: {
139
- prompt_per_million: 1.5,
140
- completion_per_million: 9,
141
- input_cache_read_per_million: 0.15
142
- },
143
- supported_parameters: [
144
- "include_reasoning",
145
- "max_tokens",
146
- "reasoning",
147
- "response_format",
148
- "seed",
149
- "stop",
150
- "structured_outputs",
151
- "temperature",
152
- "tool_choice",
153
- "tools",
154
- "top_p"
155
- ],
156
- modality: "text+image+file+audio+video->text",
157
- 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."
158
- },
159
- {
160
- id: "google/gemini-3-flash-preview",
161
- name: "Google: Gemini 3 Flash Preview",
162
- context_length: 1048576,
163
- max_completion_tokens: 65536,
164
- pricing: {
165
- prompt_per_million: 0.5,
166
- completion_per_million: 3,
167
- input_cache_read_per_million: 0.05
168
- },
169
- supported_parameters: [
170
- "include_reasoning",
171
- "max_tokens",
172
- "reasoning",
173
- "response_format",
174
- "seed",
175
- "stop",
176
- "structured_outputs",
177
- "temperature",
178
- "tool_choice",
179
- "tools",
180
- "top_p"
181
- ],
182
- modality: "text+image+file+audio+video->text",
183
- 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..."
184
- },
185
- {
186
- id: "google/gemini-3.1-pro-preview",
187
- name: "Google: Gemini 3.1 Pro Preview",
188
- context_length: 1048576,
189
- max_completion_tokens: 65536,
190
- pricing: {
191
- prompt_per_million: 2,
192
- completion_per_million: 12,
193
- input_cache_read_per_million: 0.2
194
- },
195
- supported_parameters: [
196
- "include_reasoning",
197
- "max_tokens",
198
- "reasoning",
199
- "response_format",
200
- "seed",
201
- "stop",
202
- "structured_outputs",
203
- "temperature",
204
- "tool_choice",
205
- "tools",
206
- "top_p"
207
- ],
208
- modality: "text+image+file+audio+video->text",
209
- 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..."
210
- },
211
- {
212
- id: "xiaomi/mimo-v2-pro",
213
- name: "Xiaomi: MiMo-V2-Pro",
214
- context_length: 1048576,
215
- max_completion_tokens: 131072,
216
- pricing: {
217
- prompt_per_million: 1,
218
- completion_per_million: 3,
219
- input_cache_read_per_million: 0.2
220
- },
221
- supported_parameters: [
222
- "frequency_penalty",
223
- "include_reasoning",
224
- "max_tokens",
225
- "presence_penalty",
226
- "reasoning",
227
- "response_format",
228
- "stop",
229
- "temperature",
230
- "tool_choice",
231
- "tools",
232
- "top_p"
233
- ],
234
- modality: "text->text",
235
- 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..."
236
- },
237
- {
238
- id: "xiaomi/mimo-v2-omni",
239
- name: "Xiaomi: MiMo-V2-Omni",
240
- context_length: 262144,
241
- max_completion_tokens: 65536,
242
- pricing: {
243
- prompt_per_million: 0.4,
244
- completion_per_million: 2,
245
- input_cache_read_per_million: 0.08
246
- },
247
- supported_parameters: [
248
- "frequency_penalty",
249
- "include_reasoning",
250
- "max_tokens",
251
- "presence_penalty",
252
- "reasoning",
253
- "response_format",
254
- "stop",
255
- "temperature",
256
- "tool_choice",
257
- "tools",
258
- "top_p"
259
- ],
260
- modality: "text+image+audio+video->text",
261
- 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..."
262
- },
263
- {
264
- id: "moonshotai/kimi-k2.5",
265
- name: "MoonshotAI: Kimi K2.5",
266
- context_length: 262144,
267
- max_completion_tokens: 65535,
268
- pricing: {
269
- prompt_per_million: 0.38,
270
- completion_per_million: 1.72,
271
- input_cache_read_per_million: 0.19
272
- },
273
- supported_parameters: [
274
- "frequency_penalty",
275
- "include_reasoning",
276
- "logit_bias",
277
- "logprobs",
278
- "max_tokens",
279
- "min_p",
280
- "parallel_tool_calls",
281
- "presence_penalty",
282
- "reasoning",
283
- "repetition_penalty",
284
- "response_format",
285
- "seed",
286
- "stop",
287
- "structured_outputs",
288
- "temperature",
289
- "tool_choice",
290
- "tools",
291
- "top_k",
292
- "top_logprobs",
293
- "top_p"
294
- ],
295
- modality: "text+image->text",
296
- 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..."
297
- },
298
- {
299
- id: "moonshotai/kimi-k2-thinking",
300
- name: "MoonshotAI: Kimi K2 Thinking",
301
- context_length: 262144,
302
- max_completion_tokens: null,
303
- pricing: {
304
- prompt_per_million: 0.6,
305
- completion_per_million: 2.5
306
- },
307
- supported_parameters: [
308
- "frequency_penalty",
309
- "include_reasoning",
310
- "logit_bias",
311
- "max_tokens",
312
- "min_p",
313
- "presence_penalty",
314
- "reasoning",
315
- "repetition_penalty",
316
- "response_format",
317
- "seed",
318
- "stop",
319
- "structured_outputs",
320
- "temperature",
321
- "tool_choice",
322
- "tools",
323
- "top_k",
324
- "top_p"
325
- ],
326
- modality: "text->text",
327
- 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..."
328
- },
329
- {
330
- id: "moonshotai/kimi-k2-0905",
331
- name: "MoonshotAI: Kimi K2 0905",
332
- context_length: 262144,
333
- max_completion_tokens: 262144,
334
- pricing: {
335
- prompt_per_million: 0.4,
336
- completion_per_million: 2
337
- },
338
- supported_parameters: [
339
- "frequency_penalty",
340
- "logit_bias",
341
- "logprobs",
342
- "max_tokens",
343
- "min_p",
344
- "presence_penalty",
345
- "repetition_penalty",
346
- "response_format",
347
- "seed",
348
- "stop",
349
- "structured_outputs",
350
- "temperature",
351
- "tool_choice",
352
- "tools",
353
- "top_k",
354
- "top_logprobs",
355
- "top_p"
356
- ],
357
- modality: "text->text",
358
- 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..."
359
- },
360
- {
361
- id: "z-ai/glm-5.1",
362
- name: "Z.ai: GLM 5.1",
363
- context_length: 202752,
364
- max_completion_tokens: 131072,
365
- pricing: {
366
- prompt_per_million: 1.4,
367
- completion_per_million: 4.4,
368
- input_cache_read_per_million: 0.26
369
- },
370
- supported_parameters: [
371
- "frequency_penalty",
372
- "include_reasoning",
373
- "logit_bias",
374
- "logprobs",
375
- "max_tokens",
376
- "min_p",
377
- "presence_penalty",
378
- "reasoning",
379
- "repetition_penalty",
380
- "response_format",
381
- "seed",
382
- "stop",
383
- "structured_outputs",
384
- "temperature",
385
- "tool_choice",
386
- "tools",
387
- "top_k",
388
- "top_logprobs",
389
- "top_p"
390
- ],
391
- modality: "text->text",
392
- 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..."
393
- },
394
- {
395
- id: "z-ai/glm-5v-turbo",
396
- name: "Z.ai: GLM 5V Turbo",
397
- context_length: 202752,
398
- max_completion_tokens: 131072,
399
- pricing: {
400
- prompt_per_million: 1.2,
401
- completion_per_million: 4,
402
- input_cache_read_per_million: 0.24
403
- },
404
- supported_parameters: [
405
- "include_reasoning",
406
- "max_tokens",
407
- "reasoning",
408
- "response_format",
409
- "temperature",
410
- "tool_choice",
411
- "tools",
412
- "top_p"
413
- ],
414
- modality: "text+image+video->text",
415
- 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,..."
416
- },
417
- {
418
- id: "minimax/minimax-m2.7",
419
- name: "MiniMax: MiniMax M2.7",
420
- context_length: 204800,
421
- max_completion_tokens: 131072,
422
- pricing: {
423
- prompt_per_million: 0.3,
424
- completion_per_million: 1.2,
425
- input_cache_read_per_million: 0.06
426
- },
427
- supported_parameters: [
428
- "include_reasoning",
429
- "max_tokens",
430
- "reasoning",
431
- "response_format",
432
- "temperature",
433
- "tool_choice",
434
- "tools",
435
- "top_p"
436
- ],
437
- modality: "text->text",
438
- 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."
439
- },
440
- {
441
- id: "minimax/minimax-m2.5",
442
- name: "MiniMax: MiniMax M2.5",
443
- context_length: 196608,
444
- max_completion_tokens: 65536,
445
- pricing: {
446
- prompt_per_million: 0.12,
447
- completion_per_million: 0.99,
448
- input_cache_read_per_million: 0.06
449
- },
450
- supported_parameters: [
451
- "frequency_penalty",
452
- "include_reasoning",
453
- "logit_bias",
454
- "logprobs",
455
- "max_tokens",
456
- "min_p",
457
- "parallel_tool_calls",
458
- "presence_penalty",
459
- "reasoning",
460
- "reasoning_effort",
461
- "repetition_penalty",
462
- "response_format",
463
- "seed",
464
- "stop",
465
- "structured_outputs",
466
- "temperature",
467
- "tool_choice",
468
- "tools",
469
- "top_k",
470
- "top_logprobs",
471
- "top_p"
472
- ],
473
- modality: "text->text",
474
- 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..."
475
- }
476
- ];
477
-
478
- const openrouterCatalog = /*@__PURE__*/getDefaultExportFromCjs(openrouterModels);
479
-
480
- const nativeAnthropicModelIds = [
481
- "claude-sonnet-4-5",
482
- "claude-sonnet-4-6",
483
- "claude-haiku-4-5",
484
- "claude-opus-4-6",
485
- "claude-opus-4-7",
486
- "claude-opus-4-8"
487
- ];
488
- z.enum(nativeAnthropicModelIds);
489
- const openrouterModelIds = openrouterCatalog.map((entry) => entry.id);
490
- const modelSchema = z.enum([
491
- ...nativeAnthropicModelIds,
492
- ...openrouterModelIds
493
- ]);
494
-
495
- const vaultReferenceSchema = z.string().regex(/^vault:\/\/\S+$/, "vaultRef must start with vault:// and cannot contain whitespace");
496
- const agentInputSchema = z.object({
497
- vaultRef: vaultReferenceSchema,
498
- filename: z.string().min(1, "Filename is required").max(255, "Filename must be 255 characters or less"),
499
- metadata: z.string().max(16384, "Metadata must be 16,384 characters or less").optional()
500
- }).strict();
501
- const executeAgentRequestSchema = z.object({
502
- sessionId: z.string().uuid().optional(),
503
- organizationName: z.string().min(1).max(200).optional(),
504
- repository: z.string().min(1).max(200).optional(),
505
- ref: z.string().max(200).optional(),
506
- message: z.string().min(1).max(8e5).optional(),
507
- inputs: z.array(agentInputSchema).optional(),
508
- environmentVariables: z.record(z.string(), z.string()).optional(),
509
- recover: z.boolean().optional()
510
- }).strict().superRefine((data, ctx) => {
511
- if (!data.sessionId) {
512
- if (!data.organizationName) {
513
- ctx.addIssue({ code: "custom", message: "organizationName is required for new sessions", path: ["organizationName"] });
514
- }
515
- if (!data.repository) {
516
- ctx.addIssue({ code: "custom", message: "repository is required for new sessions", path: ["repository"] });
517
- }
518
- if (!data.message) {
519
- ctx.addIssue({ code: "custom", message: "message is required for new sessions", path: ["message"] });
520
- }
521
- } else if (!data.recover && !data.message) {
522
- ctx.addIssue({ code: "custom", message: "message is required for session continuations", path: ["message"] });
523
- }
524
- if (data.recover && !data.sessionId) {
525
- ctx.addIssue({ code: "custom", message: "sessionId is required when recover is true", path: ["sessionId"] });
63
+ class NetworkError extends Error {
64
+ constructor(url, method, cause) {
65
+ super(`Failed to ${method} ${url}: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
66
+ this.url = url;
67
+ this.method = method;
68
+ this.cause = cause;
69
+ __publicField(this, "kind", "network");
70
+ this.name = "NetworkError";
526
71
  }
527
- });
528
- const executeAgentResponseSchema = z.object({
529
- success: z.boolean(),
530
- sessionId: z.string().optional(),
531
- error: z.string().optional()
532
- });
533
- const repositoryNameSchema = z.string().min(1, "Repository is required").max(200, "Repository must be 200 characters or less").regex(/^[\w.-]+$/, "Repository contains unsupported characters");
534
- const updateAgentModelRequestSchema = z.object({
535
- repository: repositoryNameSchema,
536
- model: modelSchema,
537
- commitMessage: z.string().max(4096, "Commit message must be 4096 characters or less").optional()
538
- }).strict();
539
- const updateAgentModelResponseSchema = z.object({
540
- success: z.boolean(),
541
- organizationName: z.string().optional(),
542
- repository: z.string().optional(),
543
- branch: z.string().optional(),
544
- commitHash: z.string().optional(),
545
- model: modelSchema.optional(),
546
- providerTemplate: z.string().optional(),
547
- templateSynced: z.boolean().optional(),
548
- files: z.array(z.string()).optional(),
549
- deletedFiles: z.array(z.string()).optional(),
550
- error: z.string().optional()
551
- });
552
-
553
- const sessionStatusSchema = z.enum([
554
- "pending",
555
- "running",
556
- "completed",
557
- "failed",
558
- "waiting_messages",
559
- "cancelled"
560
- ]);
561
- const sessionTimelineIdSchema = z.string().min(1, "Session ID is required");
562
- const sessionTimelineResponseSchema = z.object({
563
- sessionId: z.string(),
564
- status: z.string(),
565
- metrics: z.record(z.string(), z.unknown()),
566
- prompt: z.record(z.string(), z.unknown()),
567
- spans: z.array(z.record(z.string(), z.unknown()))
568
- });
569
- const sessionStatusEventSchema = z.object({
570
- kind: z.literal("status"),
571
- sessionId: z.string(),
572
- status: sessionStatusSchema,
573
- error: z.string().optional(),
574
- createdAt: z.number(),
575
- updatedAt: z.number()
576
- });
577
- const sessionStepsEventSchema = z.object({
578
- kind: z.literal("steps"),
579
- sessionId: z.string(),
580
- status: sessionStatusSchema,
581
- steps: z.array(z.record(z.string(), z.unknown())),
582
- nextCursor: z.number().nullable(),
583
- createdAt: z.number(),
584
- updatedAt: z.number()
585
- });
586
- const sessionResultEventSchema = z.object({
587
- kind: z.literal("result"),
588
- sessionId: z.string(),
589
- status: z.enum(["completed", "waiting_messages"]),
590
- result: z.record(z.string(), z.unknown()),
591
- nextCursor: z.number().nullable(),
592
- createdAt: z.number(),
593
- updatedAt: z.number()
594
- });
595
- const sessionErrorEventSchema = z.object({
596
- kind: z.literal("error"),
597
- sessionId: z.string(),
598
- error: z.string()
599
- });
600
- const sessionTimelineFinalizeEventSchema = z.object({
601
- kind: z.literal("timeline-finalize"),
602
- sessionId: z.string(),
603
- status: sessionStatusSchema,
604
- metrics: z.record(z.string(), z.unknown()).nullable().optional(),
605
- prompt: z.record(z.string(), z.unknown()).nullable().optional(),
606
- spans: z.array(z.record(z.string(), z.unknown())).nullable().optional(),
607
- events: z.array(z.record(z.string(), z.unknown())).nullable().optional(),
608
- continuation: z.record(z.string(), z.unknown()).nullable().optional(),
609
- createdAt: z.number(),
610
- updatedAt: z.number()
611
- });
612
- const sessionStreamEventSchema = z.discriminatedUnion("kind", [
613
- sessionStatusEventSchema,
614
- sessionStepsEventSchema,
615
- sessionResultEventSchema,
616
- sessionTimelineFinalizeEventSchema,
617
- sessionErrorEventSchema
618
- ]);
619
- const SESSION_STREAM_EVENT_KINDS = /* @__PURE__ */ new Set(["status", "steps", "result", "timeline-finalize", "error"]);
72
+ }
73
+ function isFetchError(error) {
74
+ return error instanceof FetchError;
75
+ }
76
+ function isNetworkError(error) {
77
+ return error instanceof NetworkError;
78
+ }
620
79
 
621
80
  function normalizeStreamBuffer(buffer) {
622
81
  return buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
@@ -726,12 +185,19 @@ function agentClient(config) {
726
185
  headers.set("Accept", params.accept ?? "application/json");
727
186
  if (params.body !== void 0)
728
187
  headers.set("Content-Type", "application/json");
729
- const response = await fetch(url, {
730
- method: params.method,
731
- headers,
732
- body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
733
- signal: params.signal
734
- });
188
+ let response;
189
+ try {
190
+ response = await fetch(url, {
191
+ method: params.method,
192
+ headers,
193
+ body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
194
+ signal: params.signal
195
+ });
196
+ } catch (error) {
197
+ if (error instanceof DOMException && error.name === "AbortError")
198
+ throw error;
199
+ throw new NetworkError(url.toString(), params.method, error);
200
+ }
735
201
  if (!response.ok)
736
202
  throw await FetchError.from(url.toString(), params.method, response);
737
203
  return response;
@@ -802,4 +268,4 @@ function agentClient(config) {
802
268
  return { executeAgent, updateAgentModel, fetchTimeline, streamSession, resolveReference };
803
269
  }
804
270
 
805
- export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, agentClient, agentInputSchema, executeAgentRequestSchema, executeAgentResponseSchema, parseSessionStream, sessionStatusSchema, sessionStreamEventSchema, sessionTimelineIdSchema, sessionTimelineResponseSchema, updateAgentModelRequestSchema, updateAgentModelResponseSchema };
271
+ export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, NetworkError, agentClient, isFetchError, isNetworkError, parseSessionStream };