@meistrari/agent-sdk 0.1.3 → 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/README.md CHANGED
@@ -93,6 +93,33 @@ Multi-turn lifecycle rules:
93
93
  - Treat `completed`, `failed`, and `cancelled` as non-normal follow-up states in SDK consumers.
94
94
  - The SDK v4 path does not use the legacy `/v3/sessions/{sessionId}/continue` endpoint.
95
95
 
96
+ ### Update an agent model
97
+
98
+ ```ts
99
+ const update = await client.updateAgentModel({
100
+ repository: 'support-bot',
101
+ model: 'claude-sonnet-4-5',
102
+ commitMessage: 'Switch support bot model',
103
+ })
104
+
105
+ console.log(update.commitHash)
106
+ ```
107
+
108
+ `updateAgentModel` writes `agent.config.json` on the main branch and lets agent-api
109
+ synchronize provider-specific template files when the model provider changes.
110
+
111
+ ### Fetch a timeline summary
112
+
113
+ ```ts
114
+ const timeline = await client.fetchTimeline(sessionId, { signal })
115
+
116
+ console.log(timeline.status, timeline.metrics, timeline.spans)
117
+ ```
118
+
119
+ `fetchTimeline` returns the persisted v4 timeline summary only: `status`, `metrics`,
120
+ `prompt`, and `spans`. It does not return per-event detail. Consumers that need timeline
121
+ events should consume `streamSession` and merge stream-derived timeline events locally.
122
+
96
123
  ### Resolve Vault references
97
124
 
98
125
  ```ts
@@ -115,5 +142,7 @@ This package mirrors `@meistrari/vault-sdk` and is published as `UNLICENSED`.
115
142
 
116
143
  ## Scope
117
144
 
118
- Focused on sandbox execution: `executeAgent`, `streamSession`, and `resolveReference`.
119
- Agent CRUD, legacy polling, and timelines are intentionally out of scope.
145
+ Focused on sandbox execution and the public v4 consumer paths: `executeAgent`,
146
+ `streamSession`, `updateAgentModel`, `fetchTimeline`, and `resolveReference`. Agent CRUD,
147
+ legacy polling, and the internal sandbox timeline callback are intentionally out of
148
+ scope.
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,104 +62,22 @@ ${text}`,
54
62
  );
55
63
  }
56
64
  }
57
-
58
- const sessionStatusSchema = zod.z.enum([
59
- "pending",
60
- "running",
61
- "completed",
62
- "failed",
63
- "waiting_messages",
64
- "cancelled"
65
- ]);
66
- const vaultReferenceSchema = zod.z.string().regex(/^vault:\/\/\S+$/, "vaultRef must start with vault:// and cannot contain whitespace");
67
- const agentInputSchema = zod.z.object({
68
- vaultRef: vaultReferenceSchema,
69
- filename: zod.z.string().min(1, "Filename is required").max(255, "Filename must be 255 characters or less"),
70
- metadata: zod.z.string().max(16384, "Metadata must be 16,384 characters or less").optional()
71
- }).strict();
72
- const executeAgentRequestSchema = zod.z.object({
73
- sessionId: zod.z.string().uuid().optional(),
74
- organizationName: zod.z.string().min(1).max(200).optional(),
75
- repository: zod.z.string().min(1).max(200).optional(),
76
- ref: zod.z.string().max(200).optional(),
77
- message: zod.z.string().min(1).max(8e5).optional(),
78
- inputs: zod.z.array(agentInputSchema).optional(),
79
- environmentVariables: zod.z.record(zod.z.string(), zod.z.string()).optional(),
80
- recover: zod.z.boolean().optional()
81
- }).strict().superRefine((data, ctx) => {
82
- if (!data.sessionId) {
83
- if (!data.organizationName) {
84
- ctx.addIssue({ code: "custom", message: "organizationName is required for new sessions", path: ["organizationName"] });
85
- }
86
- if (!data.repository) {
87
- ctx.addIssue({ code: "custom", message: "repository is required for new sessions", path: ["repository"] });
88
- }
89
- if (!data.message) {
90
- ctx.addIssue({ code: "custom", message: "message is required for new sessions", path: ["message"] });
91
- }
92
- } else if (!data.recover && !data.message) {
93
- ctx.addIssue({ code: "custom", message: "message is required for session continuations", path: ["message"] });
94
- }
95
- if (data.recover && !data.sessionId) {
96
- 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";
97
73
  }
98
- });
99
- const executeAgentResponseSchema = zod.z.object({
100
- success: zod.z.boolean(),
101
- sessionId: zod.z.string().optional(),
102
- error: zod.z.string().optional()
103
- });
104
- const sessionStatusEventSchema = zod.z.object({
105
- kind: zod.z.literal("status"),
106
- sessionId: zod.z.string(),
107
- status: sessionStatusSchema,
108
- error: zod.z.string().optional(),
109
- createdAt: zod.z.number(),
110
- updatedAt: zod.z.number()
111
- });
112
- const sessionStepsEventSchema = zod.z.object({
113
- kind: zod.z.literal("steps"),
114
- sessionId: zod.z.string(),
115
- status: sessionStatusSchema,
116
- steps: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())),
117
- nextCursor: zod.z.number().nullable(),
118
- createdAt: zod.z.number(),
119
- updatedAt: zod.z.number()
120
- });
121
- const sessionResultEventSchema = zod.z.object({
122
- kind: zod.z.literal("result"),
123
- sessionId: zod.z.string(),
124
- status: zod.z.enum(["completed", "waiting_messages"]),
125
- result: zod.z.record(zod.z.string(), zod.z.unknown()),
126
- nextCursor: zod.z.number().nullable(),
127
- createdAt: zod.z.number(),
128
- updatedAt: zod.z.number()
129
- });
130
- const sessionErrorEventSchema = zod.z.object({
131
- kind: zod.z.literal("error"),
132
- sessionId: zod.z.string(),
133
- error: zod.z.string()
134
- });
135
- const sessionTimelineFinalizeEventSchema = zod.z.object({
136
- kind: zod.z.literal("timeline-finalize"),
137
- sessionId: zod.z.string(),
138
- status: sessionStatusSchema,
139
- metrics: zod.z.record(zod.z.string(), zod.z.unknown()).nullable().optional(),
140
- prompt: zod.z.record(zod.z.string(), zod.z.unknown()).nullable().optional(),
141
- spans: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).nullable().optional(),
142
- events: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).nullable().optional(),
143
- continuation: zod.z.record(zod.z.string(), zod.z.unknown()).nullable().optional(),
144
- createdAt: zod.z.number(),
145
- updatedAt: zod.z.number()
146
- });
147
- const sessionStreamEventSchema = zod.z.discriminatedUnion("kind", [
148
- sessionStatusEventSchema,
149
- sessionStepsEventSchema,
150
- sessionResultEventSchema,
151
- sessionTimelineFinalizeEventSchema,
152
- sessionErrorEventSchema
153
- ]);
154
- 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
+ }
155
81
 
156
82
  function normalizeStreamBuffer(buffer) {
157
83
  return buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
@@ -198,9 +124,9 @@ function getEventKind(event) {
198
124
  }
199
125
  function parseKnownEvent(event) {
200
126
  const eventKind = getEventKind(event);
201
- if (!eventKind || !SESSION_STREAM_EVENT_KINDS.has(eventKind))
127
+ if (!eventKind || !schemas.SESSION_STREAM_EVENT_KINDS.has(eventKind))
202
128
  return void 0;
203
- const parsed = sessionStreamEventSchema.safeParse(event);
129
+ const parsed = schemas.sessionStreamEventSchema.safeParse(event);
204
130
  if (!parsed.success)
205
131
  throw new Error(parsed.error.message);
206
132
  return parsed.data;
@@ -261,24 +187,49 @@ function agentClient(config) {
261
187
  headers.set("Accept", params.accept ?? "application/json");
262
188
  if (params.body !== void 0)
263
189
  headers.set("Content-Type", "application/json");
264
- const response = await fetch(url, {
265
- method: params.method,
266
- headers,
267
- body: params.body !== void 0 ? JSON.stringify(params.body) : void 0,
268
- signal: params.signal
269
- });
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
+ }
270
203
  if (!response.ok)
271
204
  throw await FetchError.from(url.toString(), params.method, response);
272
205
  return response;
273
206
  }
274
207
  async function executeAgent(input) {
275
- const body = executeAgentRequestSchema.parse(input);
208
+ const body = schemas.executeAgentRequestSchema.parse(input);
276
209
  const response = await request({
277
210
  method: "POST",
278
211
  path: "/v4/agents/execute",
279
212
  body
280
213
  });
281
- return executeAgentResponseSchema.parse(await response.json());
214
+ return schemas.executeAgentResponseSchema.parse(await response.json());
215
+ }
216
+ async function updateAgentModel(input) {
217
+ const { repository, ...body } = schemas.updateAgentModelRequestSchema.parse(input);
218
+ const response = await request({
219
+ method: "PUT",
220
+ path: `/v4/agents/${encodeURIComponent(repository)}/model`,
221
+ body
222
+ });
223
+ return schemas.updateAgentModelResponseSchema.parse(await response.json());
224
+ }
225
+ async function fetchTimeline(sessionId, options) {
226
+ const parsedSessionId = schemas.sessionTimelineIdSchema.parse(sessionId);
227
+ const response = await request({
228
+ method: "GET",
229
+ path: `/v4/sessions/${encodeURIComponent(parsedSessionId)}/timeline`,
230
+ signal: options?.signal
231
+ });
232
+ return schemas.sessionTimelineResponseSchema.parse(await response.json());
282
233
  }
283
234
  async function streamSession(sessionId, options) {
284
235
  const response = await request({
@@ -316,16 +267,14 @@ function agentClient(config) {
316
267
  return JSON.parse(await vaultFile.content.text());
317
268
  return vaultFile.content.arrayBuffer();
318
269
  }
319
- return { executeAgent, streamSession, resolveReference };
270
+ return { executeAgent, updateAgentModel, fetchTimeline, streamSession, resolveReference };
320
271
  }
321
272
 
322
273
  exports.APIKeyAuthStrategy = APIKeyAuthStrategy;
323
274
  exports.DataTokenAuthStrategy = DataTokenAuthStrategy;
324
275
  exports.FetchError = FetchError;
276
+ exports.NetworkError = NetworkError;
325
277
  exports.agentClient = agentClient;
326
- exports.agentInputSchema = agentInputSchema;
327
- exports.executeAgentRequestSchema = executeAgentRequestSchema;
328
- exports.executeAgentResponseSchema = executeAgentResponseSchema;
278
+ exports.isFetchError = isFetchError;
279
+ exports.isNetworkError = isNetworkError;
329
280
  exports.parseSessionStream = parseSessionStream;
330
- exports.sessionStatusSchema = sessionStatusSchema;
331
- exports.sessionStreamEventSchema = sessionStreamEventSchema;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,6 @@
1
- import { z } from 'zod';
1
+ import { E as ExecuteAgentRequest, a as ExecuteAgentResponse, U as UpdateAgentModelRequest, b as UpdateAgentModelResponse, S as SessionTimelineResponse, c as SessionStreamEvent } from './shared/agent-sdk.4ad2c746.cjs';
2
+ export { A as AgentInput, d as SessionStatus, T as TimelineEvent, e as TimelineMetrics, f as TimelinePrompt, g as TimelineRunTurnMetrics, h as TimelineSpan, i as TimelineToolResult } from './shared/agent-sdk.4ad2c746.cjs';
3
+ import 'zod';
2
4
 
3
5
  interface AuthStrategy {
4
6
  getHeaders: () => Headers;
@@ -14,107 +16,6 @@ declare class APIKeyAuthStrategy implements AuthStrategy {
14
16
  getHeaders(): Headers;
15
17
  }
16
18
 
17
- declare const sessionStatusSchema: z.ZodEnum<{
18
- pending: "pending";
19
- running: "running";
20
- completed: "completed";
21
- failed: "failed";
22
- waiting_messages: "waiting_messages";
23
- cancelled: "cancelled";
24
- }>;
25
- type SessionStatus = z.infer<typeof sessionStatusSchema>;
26
- declare const agentInputSchema: z.ZodObject<{
27
- vaultRef: z.ZodString;
28
- filename: z.ZodString;
29
- metadata: z.ZodOptional<z.ZodString>;
30
- }, z.core.$strict>;
31
- type AgentInput = z.infer<typeof agentInputSchema>;
32
- declare const executeAgentRequestSchema: z.ZodObject<{
33
- sessionId: z.ZodOptional<z.ZodString>;
34
- organizationName: z.ZodOptional<z.ZodString>;
35
- repository: z.ZodOptional<z.ZodString>;
36
- ref: z.ZodOptional<z.ZodString>;
37
- message: z.ZodOptional<z.ZodString>;
38
- inputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
39
- vaultRef: z.ZodString;
40
- filename: z.ZodString;
41
- metadata: z.ZodOptional<z.ZodString>;
42
- }, z.core.$strict>>>;
43
- environmentVariables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
44
- recover: z.ZodOptional<z.ZodBoolean>;
45
- }, z.core.$strict>;
46
- type ExecuteAgentRequest = z.infer<typeof executeAgentRequestSchema>;
47
- declare const executeAgentResponseSchema: z.ZodObject<{
48
- success: z.ZodBoolean;
49
- sessionId: z.ZodOptional<z.ZodString>;
50
- error: z.ZodOptional<z.ZodString>;
51
- }, z.core.$strip>;
52
- type ExecuteAgentResponse = z.infer<typeof executeAgentResponseSchema>;
53
- declare const sessionStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
54
- kind: z.ZodLiteral<"status">;
55
- sessionId: z.ZodString;
56
- status: z.ZodEnum<{
57
- pending: "pending";
58
- running: "running";
59
- completed: "completed";
60
- failed: "failed";
61
- waiting_messages: "waiting_messages";
62
- cancelled: "cancelled";
63
- }>;
64
- error: z.ZodOptional<z.ZodString>;
65
- createdAt: z.ZodNumber;
66
- updatedAt: z.ZodNumber;
67
- }, z.core.$strip>, z.ZodObject<{
68
- kind: z.ZodLiteral<"steps">;
69
- sessionId: z.ZodString;
70
- status: z.ZodEnum<{
71
- pending: "pending";
72
- running: "running";
73
- completed: "completed";
74
- failed: "failed";
75
- waiting_messages: "waiting_messages";
76
- cancelled: "cancelled";
77
- }>;
78
- steps: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
79
- nextCursor: z.ZodNullable<z.ZodNumber>;
80
- createdAt: z.ZodNumber;
81
- updatedAt: z.ZodNumber;
82
- }, z.core.$strip>, z.ZodObject<{
83
- kind: z.ZodLiteral<"result">;
84
- sessionId: z.ZodString;
85
- status: z.ZodEnum<{
86
- completed: "completed";
87
- waiting_messages: "waiting_messages";
88
- }>;
89
- result: z.ZodRecord<z.ZodString, z.ZodUnknown>;
90
- nextCursor: z.ZodNullable<z.ZodNumber>;
91
- createdAt: z.ZodNumber;
92
- updatedAt: z.ZodNumber;
93
- }, z.core.$strip>, z.ZodObject<{
94
- kind: z.ZodLiteral<"timeline-finalize">;
95
- sessionId: z.ZodString;
96
- status: z.ZodEnum<{
97
- pending: "pending";
98
- running: "running";
99
- completed: "completed";
100
- failed: "failed";
101
- waiting_messages: "waiting_messages";
102
- cancelled: "cancelled";
103
- }>;
104
- metrics: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
105
- prompt: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
106
- spans: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
107
- events: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
108
- continuation: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
109
- createdAt: z.ZodNumber;
110
- updatedAt: z.ZodNumber;
111
- }, z.core.$strip>, z.ZodObject<{
112
- kind: z.ZodLiteral<"error">;
113
- sessionId: z.ZodString;
114
- error: z.ZodString;
115
- }, z.core.$strip>], "kind">;
116
- type SessionStreamEvent = z.infer<typeof sessionStreamEventSchema>;
117
-
118
19
  interface AgentClientConfig {
119
20
  baseUrl: string;
120
21
  authStrategy: AuthStrategy;
@@ -124,6 +25,9 @@ interface StreamSessionOptions {
124
25
  cursor?: number;
125
26
  signal?: AbortSignal;
126
27
  }
28
+ interface FetchTimelineOptions {
29
+ signal?: AbortSignal;
30
+ }
127
31
  type ResolveReferenceAs = 'bytes' | 'stream' | 'json';
128
32
  interface ResolveReferenceOptions {
129
33
  as?: ResolveReferenceAs;
@@ -132,6 +36,8 @@ interface ResolveReferenceOptions {
132
36
 
133
37
  declare function agentClient(config: AgentClientConfig): {
134
38
  executeAgent: (input: ExecuteAgentRequest) => Promise<ExecuteAgentResponse>;
39
+ updateAgentModel: (input: UpdateAgentModelRequest) => Promise<UpdateAgentModelResponse>;
40
+ fetchTimeline: (sessionId: string, options?: FetchTimelineOptions) => Promise<SessionTimelineResponse>;
135
41
  streamSession: (sessionId: string, options?: StreamSessionOptions) => Promise<AsyncIterable<SessionStreamEvent>>;
136
42
  resolveReference: {
137
43
  (reference: string, options?: {
@@ -155,11 +61,22 @@ declare class FetchError extends Error {
155
61
  readonly url: string;
156
62
  readonly method: string;
157
63
  readonly response: Response;
64
+ readonly kind: "http";
158
65
  constructor(message: string, url: string, method: string, response: Response);
159
66
  static from(url: string, method: string, response: Response): Promise<FetchError>;
160
67
  }
68
+ declare class NetworkError extends Error {
69
+ readonly url: string;
70
+ readonly method: string;
71
+ readonly cause: unknown;
72
+ readonly kind: "network";
73
+ constructor(url: string, method: string, cause: unknown);
74
+ }
75
+ type AgentRequestError = FetchError | NetworkError;
76
+ declare function isFetchError(error: unknown): error is FetchError;
77
+ declare function isNetworkError(error: unknown): error is NetworkError;
161
78
 
162
79
  declare function parseSessionStream(stream: ReadableStream<Uint8Array>): AsyncIterable<SessionStreamEvent>;
163
80
 
164
- export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, agentClient, agentInputSchema, executeAgentRequestSchema, executeAgentResponseSchema, parseSessionStream, sessionStatusSchema, sessionStreamEventSchema };
165
- export type { AgentClient, AgentClientConfig, AgentInput, AuthStrategy, ExecuteAgentRequest, ExecuteAgentResponse, ResolveReferenceAs, ResolveReferenceOptions, SessionStatus, SessionStreamEvent, StreamSessionOptions };
81
+ export { APIKeyAuthStrategy, DataTokenAuthStrategy, ExecuteAgentRequest, ExecuteAgentResponse, FetchError, NetworkError, SessionStreamEvent, SessionTimelineResponse, UpdateAgentModelRequest, UpdateAgentModelResponse, agentClient, isFetchError, isNetworkError, parseSessionStream };
82
+ export type { AgentClient, AgentClientConfig, AgentRequestError, AuthStrategy, FetchTimelineOptions, ResolveReferenceAs, ResolveReferenceOptions, StreamSessionOptions };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,6 @@
1
- import { z } from 'zod';
1
+ import { E as ExecuteAgentRequest, a as ExecuteAgentResponse, U as UpdateAgentModelRequest, b as UpdateAgentModelResponse, S as SessionTimelineResponse, c as SessionStreamEvent } from './shared/agent-sdk.4ad2c746.mjs';
2
+ export { A as AgentInput, d as SessionStatus, T as TimelineEvent, e as TimelineMetrics, f as TimelinePrompt, g as TimelineRunTurnMetrics, h as TimelineSpan, i as TimelineToolResult } from './shared/agent-sdk.4ad2c746.mjs';
3
+ import 'zod';
2
4
 
3
5
  interface AuthStrategy {
4
6
  getHeaders: () => Headers;
@@ -14,107 +16,6 @@ declare class APIKeyAuthStrategy implements AuthStrategy {
14
16
  getHeaders(): Headers;
15
17
  }
16
18
 
17
- declare const sessionStatusSchema: z.ZodEnum<{
18
- pending: "pending";
19
- running: "running";
20
- completed: "completed";
21
- failed: "failed";
22
- waiting_messages: "waiting_messages";
23
- cancelled: "cancelled";
24
- }>;
25
- type SessionStatus = z.infer<typeof sessionStatusSchema>;
26
- declare const agentInputSchema: z.ZodObject<{
27
- vaultRef: z.ZodString;
28
- filename: z.ZodString;
29
- metadata: z.ZodOptional<z.ZodString>;
30
- }, z.core.$strict>;
31
- type AgentInput = z.infer<typeof agentInputSchema>;
32
- declare const executeAgentRequestSchema: z.ZodObject<{
33
- sessionId: z.ZodOptional<z.ZodString>;
34
- organizationName: z.ZodOptional<z.ZodString>;
35
- repository: z.ZodOptional<z.ZodString>;
36
- ref: z.ZodOptional<z.ZodString>;
37
- message: z.ZodOptional<z.ZodString>;
38
- inputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
39
- vaultRef: z.ZodString;
40
- filename: z.ZodString;
41
- metadata: z.ZodOptional<z.ZodString>;
42
- }, z.core.$strict>>>;
43
- environmentVariables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
44
- recover: z.ZodOptional<z.ZodBoolean>;
45
- }, z.core.$strict>;
46
- type ExecuteAgentRequest = z.infer<typeof executeAgentRequestSchema>;
47
- declare const executeAgentResponseSchema: z.ZodObject<{
48
- success: z.ZodBoolean;
49
- sessionId: z.ZodOptional<z.ZodString>;
50
- error: z.ZodOptional<z.ZodString>;
51
- }, z.core.$strip>;
52
- type ExecuteAgentResponse = z.infer<typeof executeAgentResponseSchema>;
53
- declare const sessionStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
54
- kind: z.ZodLiteral<"status">;
55
- sessionId: z.ZodString;
56
- status: z.ZodEnum<{
57
- pending: "pending";
58
- running: "running";
59
- completed: "completed";
60
- failed: "failed";
61
- waiting_messages: "waiting_messages";
62
- cancelled: "cancelled";
63
- }>;
64
- error: z.ZodOptional<z.ZodString>;
65
- createdAt: z.ZodNumber;
66
- updatedAt: z.ZodNumber;
67
- }, z.core.$strip>, z.ZodObject<{
68
- kind: z.ZodLiteral<"steps">;
69
- sessionId: z.ZodString;
70
- status: z.ZodEnum<{
71
- pending: "pending";
72
- running: "running";
73
- completed: "completed";
74
- failed: "failed";
75
- waiting_messages: "waiting_messages";
76
- cancelled: "cancelled";
77
- }>;
78
- steps: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
79
- nextCursor: z.ZodNullable<z.ZodNumber>;
80
- createdAt: z.ZodNumber;
81
- updatedAt: z.ZodNumber;
82
- }, z.core.$strip>, z.ZodObject<{
83
- kind: z.ZodLiteral<"result">;
84
- sessionId: z.ZodString;
85
- status: z.ZodEnum<{
86
- completed: "completed";
87
- waiting_messages: "waiting_messages";
88
- }>;
89
- result: z.ZodRecord<z.ZodString, z.ZodUnknown>;
90
- nextCursor: z.ZodNullable<z.ZodNumber>;
91
- createdAt: z.ZodNumber;
92
- updatedAt: z.ZodNumber;
93
- }, z.core.$strip>, z.ZodObject<{
94
- kind: z.ZodLiteral<"timeline-finalize">;
95
- sessionId: z.ZodString;
96
- status: z.ZodEnum<{
97
- pending: "pending";
98
- running: "running";
99
- completed: "completed";
100
- failed: "failed";
101
- waiting_messages: "waiting_messages";
102
- cancelled: "cancelled";
103
- }>;
104
- metrics: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
105
- prompt: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
106
- spans: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
107
- events: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
108
- continuation: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
109
- createdAt: z.ZodNumber;
110
- updatedAt: z.ZodNumber;
111
- }, z.core.$strip>, z.ZodObject<{
112
- kind: z.ZodLiteral<"error">;
113
- sessionId: z.ZodString;
114
- error: z.ZodString;
115
- }, z.core.$strip>], "kind">;
116
- type SessionStreamEvent = z.infer<typeof sessionStreamEventSchema>;
117
-
118
19
  interface AgentClientConfig {
119
20
  baseUrl: string;
120
21
  authStrategy: AuthStrategy;
@@ -124,6 +25,9 @@ interface StreamSessionOptions {
124
25
  cursor?: number;
125
26
  signal?: AbortSignal;
126
27
  }
28
+ interface FetchTimelineOptions {
29
+ signal?: AbortSignal;
30
+ }
127
31
  type ResolveReferenceAs = 'bytes' | 'stream' | 'json';
128
32
  interface ResolveReferenceOptions {
129
33
  as?: ResolveReferenceAs;
@@ -132,6 +36,8 @@ interface ResolveReferenceOptions {
132
36
 
133
37
  declare function agentClient(config: AgentClientConfig): {
134
38
  executeAgent: (input: ExecuteAgentRequest) => Promise<ExecuteAgentResponse>;
39
+ updateAgentModel: (input: UpdateAgentModelRequest) => Promise<UpdateAgentModelResponse>;
40
+ fetchTimeline: (sessionId: string, options?: FetchTimelineOptions) => Promise<SessionTimelineResponse>;
135
41
  streamSession: (sessionId: string, options?: StreamSessionOptions) => Promise<AsyncIterable<SessionStreamEvent>>;
136
42
  resolveReference: {
137
43
  (reference: string, options?: {
@@ -155,11 +61,22 @@ declare class FetchError extends Error {
155
61
  readonly url: string;
156
62
  readonly method: string;
157
63
  readonly response: Response;
64
+ readonly kind: "http";
158
65
  constructor(message: string, url: string, method: string, response: Response);
159
66
  static from(url: string, method: string, response: Response): Promise<FetchError>;
160
67
  }
68
+ declare class NetworkError extends Error {
69
+ readonly url: string;
70
+ readonly method: string;
71
+ readonly cause: unknown;
72
+ readonly kind: "network";
73
+ constructor(url: string, method: string, cause: unknown);
74
+ }
75
+ type AgentRequestError = FetchError | NetworkError;
76
+ declare function isFetchError(error: unknown): error is FetchError;
77
+ declare function isNetworkError(error: unknown): error is NetworkError;
161
78
 
162
79
  declare function parseSessionStream(stream: ReadableStream<Uint8Array>): AsyncIterable<SessionStreamEvent>;
163
80
 
164
- export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, agentClient, agentInputSchema, executeAgentRequestSchema, executeAgentResponseSchema, parseSessionStream, sessionStatusSchema, sessionStreamEventSchema };
165
- export type { AgentClient, AgentClientConfig, AgentInput, AuthStrategy, ExecuteAgentRequest, ExecuteAgentResponse, ResolveReferenceAs, ResolveReferenceOptions, SessionStatus, SessionStreamEvent, StreamSessionOptions };
81
+ export { APIKeyAuthStrategy, DataTokenAuthStrategy, ExecuteAgentRequest, ExecuteAgentResponse, FetchError, NetworkError, SessionStreamEvent, SessionTimelineResponse, UpdateAgentModelRequest, UpdateAgentModelResponse, agentClient, isFetchError, isNetworkError, parseSessionStream };
82
+ export type { AgentClient, AgentClientConfig, AgentRequestError, AuthStrategy, FetchTimelineOptions, ResolveReferenceAs, ResolveReferenceOptions, StreamSessionOptions };