veryfront 0.1.233 → 0.1.234

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/esm/deno.d.ts CHANGED
@@ -19,6 +19,7 @@ declare namespace _default {
19
19
  "./agent": string;
20
20
  "./agent/conversation-bootstrap": string;
21
21
  "./agent/durable": string;
22
+ "./agent/invoke-agent-child-runs": string;
22
23
  "./channels/control-plane": string;
23
24
  "./channels/invoke": string;
24
25
  "./tool": string;
package/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.233",
3
+ "version": "0.1.234",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "workspace": [
@@ -32,6 +32,7 @@ export default {
32
32
  "./agent": "./src/agent/index.ts",
33
33
  "./agent/conversation-bootstrap": "./src/agent/conversation-bootstrap.ts",
34
34
  "./agent/durable": "./src/agent/durable.ts",
35
+ "./agent/invoke-agent-child-runs": "./src/agent/invoke-agent-child-runs.ts",
35
36
  "./channels/control-plane": "./src/channels/control-plane.ts",
36
37
  "./channels/invoke": "./src/channels/invoke.ts",
37
38
  "./tool": "./src/tool/index.ts",
@@ -16,6 +16,14 @@ export declare function resolveConversationRunTargets(input: {
16
16
  projectId?: string | null;
17
17
  branchId?: string | null;
18
18
  }): ConversationRunTargets;
19
+ export declare const ConversationRunStatusSchema: z.ZodEnum<{
20
+ failed: "failed";
21
+ pending: "pending";
22
+ completed: "completed";
23
+ running: "running";
24
+ cancelled: "cancelled";
25
+ waiting_for_tool: "waiting_for_tool";
26
+ }>;
19
27
  export declare const ConversationRunProjectionSchema: z.ZodPipe<z.ZodObject<{
20
28
  runId: z.ZodOptional<z.ZodString>;
21
29
  run_id: z.ZodOptional<z.ZodString>;
@@ -87,6 +95,53 @@ export declare const CompleteConversationRunResponseSchema: z.ZodObject<{
87
95
  }>;
88
96
  }, z.core.$loose>;
89
97
  }, z.core.$loose>;
98
+ export declare const AppendConversationRunEventsResponseSchema: z.ZodUnion<readonly [z.ZodObject<{
99
+ latestEventId: z.ZodNumber;
100
+ latestExternalEventSequence: z.ZodNumber;
101
+ appendedCount: z.ZodNumber;
102
+ run: z.ZodObject<{
103
+ runId: z.ZodString;
104
+ conversationId: z.ZodString;
105
+ latestEventId: z.ZodNumber;
106
+ latestExternalEventSequence: z.ZodNumber;
107
+ }, z.core.$loose>;
108
+ }, z.core.$strip>, z.ZodPipe<z.ZodObject<{
109
+ latest_event_id: z.ZodNumber;
110
+ latest_external_event_sequence: z.ZodNumber;
111
+ appended_count: z.ZodNumber;
112
+ run: z.ZodObject<{
113
+ run_id: z.ZodString;
114
+ conversation_id: z.ZodString;
115
+ latest_event_id: z.ZodNumber;
116
+ latest_external_event_sequence: z.ZodNumber;
117
+ }, z.core.$loose>;
118
+ }, z.core.$strip>, z.ZodTransform<{
119
+ latestEventId: number;
120
+ latestExternalEventSequence: number;
121
+ appendedCount: number;
122
+ run: {
123
+ runId: string;
124
+ conversationId: string;
125
+ latestEventId: number;
126
+ latestExternalEventSequence: number;
127
+ run_id: string;
128
+ conversation_id: string;
129
+ latest_event_id: number;
130
+ latest_external_event_sequence: number;
131
+ };
132
+ }, {
133
+ latest_event_id: number;
134
+ latest_external_event_sequence: number;
135
+ appended_count: number;
136
+ run: {
137
+ [x: string]: unknown;
138
+ run_id: string;
139
+ conversation_id: string;
140
+ latest_event_id: number;
141
+ latest_external_event_sequence: number;
142
+ };
143
+ }>>]>;
144
+ export type AppendConversationRunEventsResponse = z.infer<typeof AppendConversationRunEventsResponseSchema>;
90
145
  export interface ConversationAgentRunUsage {
91
146
  inputTokens: number;
92
147
  outputTokens: number;
@@ -113,6 +168,35 @@ export interface FinalizeConversationAgentRunInput {
113
168
  terminalErrorCode?: string | null;
114
169
  terminalErrorMessage?: string | null;
115
170
  }
171
+ export declare class AppendConversationRunEventsError extends Error {
172
+ readonly status: number;
173
+ readonly detail: string | null;
174
+ constructor(input: {
175
+ status: number;
176
+ detail?: string | null;
177
+ statusText?: string;
178
+ });
179
+ }
180
+ export declare function parseAppendConversationRunEventsErrorBody(bodyText: string): string | null;
181
+ export declare function isIgnorableConversationRunAppendError(error: unknown): error is AppendConversationRunEventsError;
182
+ export declare function isCursorMismatchConversationRunAppendError(error: unknown): error is AppendConversationRunEventsError;
183
+ export declare function getConversationRun(input: {
184
+ authToken: string;
185
+ apiUrl: string;
186
+ conversationId: string;
187
+ runId: string;
188
+ abortSignal?: AbortSignal;
189
+ }): Promise<ConversationRunProjection>;
190
+ export declare function appendConversationRunEvents(input: {
191
+ authToken: string;
192
+ apiUrl: string;
193
+ conversationId: string;
194
+ runId: string;
195
+ expectedPreviousEventId?: number;
196
+ expectedPreviousExternalEventSequence?: number;
197
+ events: unknown[];
198
+ abortSignal?: AbortSignal;
199
+ }): Promise<AppendConversationRunEventsResponse>;
116
200
  export declare function createConversationAgentRun(input: CreateConversationAgentRunInput): Promise<ConversationRunProjection>;
117
201
  export declare function finalizeConversationAgentRun(input: FinalizeConversationAgentRunInput): Promise<void>;
118
202
  //# sourceMappingURL=durable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["../../../src/src/agent/durable.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,4BAA4B;;;;;;;;;;iBAIvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAElF,wBAAgB,6BAA6B,CAAC,KAAK,EAAE;IACnD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,GAAG,sBAAsB,CAoBzB;AAED,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC;CAC3B,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAQrC;AAED,wBAAsB,2BAA2B,CAAC,KAAK,EAAE;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,qCAAqC,CAAC,EAAE,MAAM,CAAC;IAC/C,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAyD/C;AAED,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,yBAAyB,CAAC,CA0CpC;AAED,wBAAsB,4BAA4B,CAChD,KAAK,EAAE,iCAAiC,GACvC,OAAO,CAAC,IAAI,CAAC,CAwBf"}
@@ -2,6 +2,31 @@ import "../../_dnt.polyfills.js";
2
2
  import * as dntShim from "../../_dnt.shims.js";
3
3
  import { z } from "zod";
4
4
  const AGENT_RUN_API_TIMEOUT_MS = 15_000;
5
+ function createTimedAbortSignal(timeoutMs, abortSignal) {
6
+ const controller = new AbortController();
7
+ let abortedByCaller = false;
8
+ const timeout = dntShim.setTimeout(() => {
9
+ controller.abort();
10
+ }, timeoutMs);
11
+ const onAbort = () => {
12
+ abortedByCaller = true;
13
+ controller.abort();
14
+ };
15
+ if (abortSignal?.aborted) {
16
+ onAbort();
17
+ }
18
+ else {
19
+ abortSignal?.addEventListener("abort", onAbort, { once: true });
20
+ }
21
+ return {
22
+ signal: controller.signal,
23
+ wasAbortedByCaller: () => abortedByCaller,
24
+ cleanup: () => {
25
+ clearTimeout(timeout);
26
+ abortSignal?.removeEventListener("abort", onAbort);
27
+ },
28
+ };
29
+ }
5
30
  export const ConversationRunTargetsSchema = z.object({
6
31
  sourceTargetKind: z.enum(["project", "preview_branch"]).nullable(),
7
32
  runtimeTargetKind: z.enum(["production", "preview_branch"]).nullable(),
@@ -26,6 +51,14 @@ export function resolveConversationRunTargets(input) {
26
51
  targetBranchId: null,
27
52
  });
28
53
  }
54
+ export const ConversationRunStatusSchema = z.enum([
55
+ "pending",
56
+ "running",
57
+ "waiting_for_tool",
58
+ "completed",
59
+ "failed",
60
+ "cancelled",
61
+ ]);
29
62
  export const ConversationRunProjectionSchema = z
30
63
  .object({
31
64
  runId: z.string().min(1).optional(),
@@ -38,7 +71,7 @@ export const ConversationRunProjectionSchema = z
38
71
  latest_event_id: z.number().int().nonnegative().optional(),
39
72
  latestExternalEventSequence: z.number().int().nonnegative().optional(),
40
73
  latest_external_event_sequence: z.number().int().nonnegative().optional(),
41
- status: z.enum(["pending", "running", "waiting_for_tool", "completed", "failed", "cancelled"]),
74
+ status: ConversationRunStatusSchema,
42
75
  })
43
76
  .passthrough()
44
77
  .transform((data) => {
@@ -92,11 +125,100 @@ export const CompleteConversationRunResponseSchema = z
92
125
  .passthrough(),
93
126
  })
94
127
  .passthrough();
128
+ const AppendConversationRunEventsCamelRunSchema = z
129
+ .object({
130
+ runId: z.string().min(1),
131
+ conversationId: z.string().uuid(),
132
+ latestEventId: z.number().int().nonnegative(),
133
+ latestExternalEventSequence: z.number().int().nonnegative(),
134
+ })
135
+ .passthrough();
136
+ const AppendConversationRunEventsSnakeRunSchema = z
137
+ .object({
138
+ run_id: z.string().min(1),
139
+ conversation_id: z.string().uuid(),
140
+ latest_event_id: z.number().int().nonnegative(),
141
+ latest_external_event_sequence: z.number().int().nonnegative(),
142
+ })
143
+ .passthrough();
144
+ export const AppendConversationRunEventsResponseSchema = z.union([
145
+ z.object({
146
+ latestEventId: z.number().int().nonnegative(),
147
+ latestExternalEventSequence: z.number().int().nonnegative(),
148
+ appendedCount: z.number().int().nonnegative(),
149
+ run: AppendConversationRunEventsCamelRunSchema,
150
+ }),
151
+ z.object({
152
+ latest_event_id: z.number().int().nonnegative(),
153
+ latest_external_event_sequence: z.number().int().nonnegative(),
154
+ appended_count: z.number().int().nonnegative(),
155
+ run: AppendConversationRunEventsSnakeRunSchema,
156
+ }).transform((data) => ({
157
+ latestEventId: data.latest_event_id,
158
+ latestExternalEventSequence: data.latest_external_event_sequence,
159
+ appendedCount: data.appended_count,
160
+ run: {
161
+ ...data.run,
162
+ runId: data.run.run_id,
163
+ conversationId: data.run.conversation_id,
164
+ latestEventId: data.run.latest_event_id,
165
+ latestExternalEventSequence: data.run.latest_external_event_sequence,
166
+ },
167
+ })),
168
+ ]);
169
+ const ConversationRunErrorSchema = z.object({
170
+ detail: z.string().min(1).optional(),
171
+ error: z.string().min(1).optional(),
172
+ });
173
+ export class AppendConversationRunEventsError extends Error {
174
+ status;
175
+ detail;
176
+ constructor(input) {
177
+ const detail = input.detail?.trim() || input.statusText || `HTTP ${input.status}`;
178
+ super(`Append conversation run events failed (${input.status}): ${detail}`);
179
+ this.name = "AppendConversationRunEventsError";
180
+ this.status = input.status;
181
+ this.detail = input.detail?.trim() || null;
182
+ }
183
+ }
184
+ export function parseAppendConversationRunEventsErrorBody(bodyText) {
185
+ if (!bodyText) {
186
+ return null;
187
+ }
188
+ try {
189
+ const parsed = ConversationRunErrorSchema.safeParse(JSON.parse(bodyText));
190
+ if (parsed.success) {
191
+ return parsed.data.detail ?? parsed.data.error ?? null;
192
+ }
193
+ }
194
+ catch {
195
+ return bodyText;
196
+ }
197
+ return bodyText;
198
+ }
199
+ export function isIgnorableConversationRunAppendError(error) {
200
+ if (!(error instanceof AppendConversationRunEventsError)) {
201
+ return false;
202
+ }
203
+ if (error.status === 404) {
204
+ return true;
205
+ }
206
+ if (error.status !== 400) {
207
+ return false;
208
+ }
209
+ return (error.detail === "Cannot append external events to a terminal run" ||
210
+ error.detail === "Cannot append external events while the run is waiting for a tool result");
211
+ }
212
+ export function isCursorMismatchConversationRunAppendError(error) {
213
+ return (error instanceof AppendConversationRunEventsError &&
214
+ error.status === 400 &&
215
+ error.detail === "External run event cursor mismatch");
216
+ }
95
217
  async function controlPlaneJson(input) {
96
- const controller = new AbortController();
97
- const timeout = dntShim.setTimeout(() => {
98
- controller.abort();
99
- }, AGENT_RUN_API_TIMEOUT_MS);
218
+ if (input.abortSignal?.aborted) {
219
+ throw new DOMException("This operation was aborted", "AbortError");
220
+ }
221
+ const timedAbort = createTimedAbortSignal(AGENT_RUN_API_TIMEOUT_MS, input.abortSignal);
100
222
  let response;
101
223
  try {
102
224
  response = await fetch(input.url, {
@@ -106,17 +228,19 @@ async function controlPlaneJson(input) {
106
228
  "Content-Type": "application/json",
107
229
  },
108
230
  ...(input.body !== undefined ? { body: JSON.stringify(input.body) } : {}),
109
- signal: controller.signal,
231
+ signal: timedAbort.signal,
110
232
  });
111
233
  }
112
234
  catch (error) {
113
- if (error instanceof DOMException && error.name === "AbortError") {
235
+ if (error instanceof DOMException &&
236
+ error.name === "AbortError" &&
237
+ !timedAbort.wasAbortedByCaller()) {
114
238
  throw new Error(`${input.operation} timed out after ${AGENT_RUN_API_TIMEOUT_MS}ms`);
115
239
  }
116
240
  throw error;
117
241
  }
118
242
  finally {
119
- clearTimeout(timeout);
243
+ timedAbort.cleanup();
120
244
  }
121
245
  if (!response.ok) {
122
246
  const body = await response.text().catch(() => "");
@@ -124,6 +248,63 @@ async function controlPlaneJson(input) {
124
248
  }
125
249
  return input.responseSchema.parse(await response.json());
126
250
  }
251
+ export async function getConversationRun(input) {
252
+ return controlPlaneJson({
253
+ authToken: input.authToken,
254
+ url: `${input.apiUrl}/conversations/${input.conversationId}/runs/${input.runId}`,
255
+ responseSchema: ConversationRunProjectionSchema,
256
+ operation: "Read conversation durable run projection",
257
+ abortSignal: input.abortSignal,
258
+ });
259
+ }
260
+ export async function appendConversationRunEvents(input) {
261
+ if (input.abortSignal?.aborted) {
262
+ throw new DOMException("This operation was aborted", "AbortError");
263
+ }
264
+ const timedAbort = createTimedAbortSignal(AGENT_RUN_API_TIMEOUT_MS, input.abortSignal);
265
+ let response;
266
+ try {
267
+ response = await fetch(`${input.apiUrl}/conversations/${input.conversationId}/runs/${input.runId}/events`, {
268
+ method: "POST",
269
+ headers: {
270
+ Authorization: `Bearer ${input.authToken}`,
271
+ "Content-Type": "application/json",
272
+ },
273
+ body: JSON.stringify({
274
+ ...(input.expectedPreviousEventId !== undefined
275
+ ? { expected_previous_event_id: input.expectedPreviousEventId }
276
+ : {}),
277
+ ...(input.expectedPreviousExternalEventSequence !== undefined
278
+ ? {
279
+ expected_previous_external_event_sequence: input.expectedPreviousExternalEventSequence,
280
+ }
281
+ : {}),
282
+ events: input.events,
283
+ }),
284
+ signal: timedAbort.signal,
285
+ });
286
+ }
287
+ catch (error) {
288
+ if (error instanceof DOMException &&
289
+ error.name === "AbortError" &&
290
+ !timedAbort.wasAbortedByCaller()) {
291
+ throw new Error(`Append conversation run events timed out after ${AGENT_RUN_API_TIMEOUT_MS}ms`);
292
+ }
293
+ throw error;
294
+ }
295
+ finally {
296
+ timedAbort.cleanup();
297
+ }
298
+ if (!response.ok) {
299
+ const body = await response.text().catch(() => "");
300
+ throw new AppendConversationRunEventsError({
301
+ status: response.status,
302
+ detail: parseAppendConversationRunEventsErrorBody(body),
303
+ statusText: response.statusText,
304
+ });
305
+ }
306
+ return AppendConversationRunEventsResponseSchema.parse(await response.json());
307
+ }
127
308
  export async function createConversationAgentRun(input) {
128
309
  const targets = resolveConversationRunTargets({
129
310
  projectId: input.projectId ?? null,
@@ -158,11 +339,11 @@ export async function createConversationAgentRun(input) {
158
339
  responseSchema: CreateConversationRunAcceptedSchema,
159
340
  operation: "Create canonical durable run",
160
341
  });
161
- return controlPlaneJson({
342
+ return getConversationRun({
162
343
  authToken: input.authToken,
163
- url: `${input.apiUrl}/conversations/${input.conversationId}/runs/${runId}`,
164
- responseSchema: ConversationRunProjectionSchema,
165
- operation: "Read conversation durable run projection",
344
+ apiUrl: input.apiUrl,
345
+ conversationId: input.conversationId,
346
+ runId,
166
347
  });
167
348
  }
168
349
  export async function finalizeConversationAgentRun(input) {
@@ -90,7 +90,8 @@ export { normalizeAgUiRuntimeMessages } from "./ag-ui-runtime-support.js";
90
90
  export { type AgUiBrowserEncodedEvent, type AgUiBrowserEncoderState, type AgUiBrowserRunFinishedMetadata, type AgUiRuntimeStreamEvent, buildAgUiBrowserFinalizeResponse, createAgUiBrowserEncoderState, finalizeAgUiBrowserEvents, mapRuntimeStreamEventToAgUiBrowserEvents, } from "./ag-ui-browser-encoder.js";
91
91
  export { type AgUiBrowserResponseEncoder, type AgUiBrowserResponseExecution, type AgUiBrowserResponseRequestState, createAgUiBrowserResponseStream, type CreateAgUiBrowserResponseStreamInput, } from "./ag-ui-browser-response-stream.js";
92
92
  export { bootstrapConversationAgentRun, type BootstrapConversationAgentRunResult, type ConversationMessageRecord, ConversationMessageRecordSchema, type ConversationRecord, ConversationRecordSchema, createConversationMessage, createConversationRecord, ensureConversationProjectLink, fetchConversationRecord, } from "./conversation-bootstrap.js";
93
- export { CompleteConversationRunResponseSchema, type ConversationAgentRunUsage, type ConversationRunProjection, ConversationRunProjectionSchema, type ConversationRunTargets, ConversationRunTargetsSchema, createConversationAgentRun, finalizeConversationAgentRun, resolveConversationRunTargets, } from "./durable.js";
93
+ export { appendConversationRunEvents, AppendConversationRunEventsError, type AppendConversationRunEventsResponse, AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, type ConversationAgentRunUsage, type ConversationRunProjection, ConversationRunProjectionSchema, ConversationRunStatusSchema, type ConversationRunTargets, ConversationRunTargetsSchema, createConversationAgentRun, finalizeConversationAgentRun, getConversationRun, isCursorMismatchConversationRunAppendError, isIgnorableConversationRunAppendError, parseAppendConversationRunEventsErrorBody, resolveConversationRunTargets, } from "./durable.js";
94
+ export { buildInvokeAgentChildRunLifecycleCustomEvent, buildInvokeAgentChildRunProgressEvents, buildInvokeAgentChildRunStateDelta, type InvokeAgentChildRunLifecycleCustomEvent, InvokeAgentChildRunLifecycleCustomEventSchema, type InvokeAgentChildRunLifecycleValue, InvokeAgentChildRunLifecycleValueSchema, type InvokeAgentChildRunProgressEvent, type InvokeAgentChildRunProgressInput, type InvokeAgentChildRunStateDelta, InvokeAgentChildRunStateDeltaSchema, publishInvokeAgentChildRunProgress, } from "./invoke-agent-child-runs.js";
94
95
  export { type HostedChildLifecycleAdapter, type HostedChildLifecycleRunnerOptions, type HostedChildLifecycleRunResult, type HostedChildLifecycleTerminalState, runHostedChildLifecycle, } from "./hosted-child-lifecycle.js";
95
96
  export { type HostedLifecycleAdapter, type HostedLifecycleExecution, type HostedLifecycleRunnerOptions, type HostedLifecycleRunResult, type HostedLifecycleTerminalState, runHostedLifecycle, } from "./hosted-lifecycle.js";
96
97
  export { mergeToolCallInput, mergeToolInputDelta, parseDataStreamSseEvents, parseToolInputObject, streamDataStreamEvents, stripLeadingEmptyObjectPlaceholder, } from "./data-stream.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,yBAAyB,CAAC;AAGjC,YAAY,EACV,KAAK,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,OAAO,IAAI,YAAY,EACvB,WAAW,EACX,aAAa,EACb,WAAW,EACX,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnF,OAAO,EACL,YAAY,EACZ,k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BAAgB,EAChB,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,KAAK,wBAAwB,EAC7B,8BAA8B,EAC9B,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,EAC5B,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,yBAAyB,CAAC;AAGjC,YAAY,EACV,KAAK,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,g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B,EACtB,qBAAqB,EACrB,4BAA4B,EAC5B,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
@@ -89,7 +89,8 @@ export { normalizeAgUiRuntimeMessages } from "./ag-ui-runtime-support.js";
89
89
  export { buildAgUiBrowserFinalizeResponse, createAgUiBrowserEncoderState, finalizeAgUiBrowserEvents, mapRuntimeStreamEventToAgUiBrowserEvents, } from "./ag-ui-browser-encoder.js";
90
90
  export { createAgUiBrowserResponseStream, } from "./ag-ui-browser-response-stream.js";
91
91
  export { bootstrapConversationAgentRun, ConversationMessageRecordSchema, ConversationRecordSchema, createConversationMessage, createConversationRecord, ensureConversationProjectLink, fetchConversationRecord, } from "./conversation-bootstrap.js";
92
- export { CompleteConversationRunResponseSchema, ConversationRunProjectionSchema, ConversationRunTargetsSchema, createConversationAgentRun, finalizeConversationAgentRun, resolveConversationRunTargets, } from "./durable.js";
92
+ export { appendConversationRunEvents, AppendConversationRunEventsError, AppendConversationRunEventsResponseSchema, CompleteConversationRunResponseSchema, ConversationRunProjectionSchema, ConversationRunStatusSchema, ConversationRunTargetsSchema, createConversationAgentRun, finalizeConversationAgentRun, getConversationRun, isCursorMismatchConversationRunAppendError, isIgnorableConversationRunAppendError, parseAppendConversationRunEventsErrorBody, resolveConversationRunTargets, } from "./durable.js";
93
+ export { buildInvokeAgentChildRunLifecycleCustomEvent, buildInvokeAgentChildRunProgressEvents, buildInvokeAgentChildRunStateDelta, InvokeAgentChildRunLifecycleCustomEventSchema, InvokeAgentChildRunLifecycleValueSchema, InvokeAgentChildRunStateDeltaSchema, publishInvokeAgentChildRunProgress, } from "./invoke-agent-child-runs.js";
93
94
  export { runHostedChildLifecycle, } from "./hosted-child-lifecycle.js";
94
95
  export { runHostedLifecycle, } from "./hosted-lifecycle.js";
95
96
  export { mergeToolCallInput, mergeToolInputDelta, parseDataStreamSseEvents, parseToolInputObject, streamDataStreamEvents, stripLeadingEmptyObjectPlaceholder, } from "./data-stream.js";
@@ -0,0 +1,145 @@
1
+ import "../../_dnt.polyfills.js";
2
+ import { z } from "zod";
3
+ export declare const InvokeAgentChildRunLifecycleValueSchema: z.ZodObject<{
4
+ toolCallId: z.ZodString;
5
+ childConversationId: z.ZodString;
6
+ childRunId: z.ZodString;
7
+ childMessageId: z.ZodString;
8
+ childAgentId: z.ZodString;
9
+ description: z.ZodOptional<z.ZodString>;
10
+ status: z.ZodEnum<{
11
+ failed: "failed";
12
+ pending: "pending";
13
+ completed: "completed";
14
+ running: "running";
15
+ cancelled: "cancelled";
16
+ waiting_for_tool: "waiting_for_tool";
17
+ }>;
18
+ sourceTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
19
+ project: "project";
20
+ production: "production";
21
+ environment: "environment";
22
+ preview_branch: "preview_branch";
23
+ }>>>;
24
+ runtimeTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
25
+ production: "production";
26
+ environment: "environment";
27
+ preview_branch: "preview_branch";
28
+ }>>>;
29
+ targetEnvironmentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
+ targetBranchId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
31
+ }, z.core.$strip>;
32
+ export type InvokeAgentChildRunLifecycleValue = z.infer<typeof InvokeAgentChildRunLifecycleValueSchema>;
33
+ export declare const InvokeAgentChildRunStateDeltaSchema: z.ZodObject<{
34
+ type: z.ZodLiteral<"STATE_DELTA">;
35
+ delta: z.ZodArray<z.ZodObject<{
36
+ op: z.ZodEnum<{
37
+ replace: "replace";
38
+ add: "add";
39
+ }>;
40
+ path: z.ZodString;
41
+ value: z.ZodObject<{
42
+ toolCallId: z.ZodString;
43
+ childConversationId: z.ZodString;
44
+ childRunId: z.ZodString;
45
+ childMessageId: z.ZodString;
46
+ childAgentId: z.ZodString;
47
+ description: z.ZodOptional<z.ZodString>;
48
+ status: z.ZodEnum<{
49
+ failed: "failed";
50
+ pending: "pending";
51
+ completed: "completed";
52
+ running: "running";
53
+ cancelled: "cancelled";
54
+ waiting_for_tool: "waiting_for_tool";
55
+ }>;
56
+ sourceTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
57
+ project: "project";
58
+ production: "production";
59
+ environment: "environment";
60
+ preview_branch: "preview_branch";
61
+ }>>>;
62
+ runtimeTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
63
+ production: "production";
64
+ environment: "environment";
65
+ preview_branch: "preview_branch";
66
+ }>>>;
67
+ targetEnvironmentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
68
+ targetBranchId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
69
+ }, z.core.$strip>;
70
+ }, z.core.$strip>>;
71
+ }, z.core.$strip>;
72
+ export type InvokeAgentChildRunStateDelta = z.infer<typeof InvokeAgentChildRunStateDeltaSchema>;
73
+ export declare const InvokeAgentChildRunLifecycleCustomEventSchema: z.ZodObject<{
74
+ type: z.ZodLiteral<"CUSTOM">;
75
+ name: z.ZodLiteral<"veryfront.invoke_agent.lifecycle">;
76
+ value: z.ZodObject<{
77
+ toolCallId: z.ZodString;
78
+ childConversationId: z.ZodString;
79
+ childRunId: z.ZodString;
80
+ childMessageId: z.ZodString;
81
+ childAgentId: z.ZodString;
82
+ description: z.ZodOptional<z.ZodString>;
83
+ status: z.ZodEnum<{
84
+ failed: "failed";
85
+ pending: "pending";
86
+ completed: "completed";
87
+ running: "running";
88
+ cancelled: "cancelled";
89
+ waiting_for_tool: "waiting_for_tool";
90
+ }>;
91
+ sourceTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
92
+ project: "project";
93
+ production: "production";
94
+ environment: "environment";
95
+ preview_branch: "preview_branch";
96
+ }>>>;
97
+ runtimeTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
98
+ production: "production";
99
+ environment: "environment";
100
+ preview_branch: "preview_branch";
101
+ }>>>;
102
+ targetEnvironmentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
103
+ targetBranchId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
104
+ }, z.core.$strip>;
105
+ }, z.core.$strip>;
106
+ export type InvokeAgentChildRunLifecycleCustomEvent = z.infer<typeof InvokeAgentChildRunLifecycleCustomEventSchema>;
107
+ export type InvokeAgentChildRunProgressInput = {
108
+ toolCallId: string;
109
+ childConversationId: string;
110
+ childRunId: string;
111
+ childMessageId: string;
112
+ childAgentId: string;
113
+ description?: string;
114
+ status: "pending" | "running" | "waiting_for_tool" | "completed" | "failed" | "cancelled";
115
+ sourceTargetKind?: "project" | "production" | "environment" | "preview_branch" | null;
116
+ runtimeTargetKind?: "production" | "environment" | "preview_branch" | null;
117
+ targetEnvironmentId?: string | null;
118
+ targetBranchId?: string | null;
119
+ };
120
+ export type InvokeAgentChildRunProgressEvent = InvokeAgentChildRunStateDelta | InvokeAgentChildRunLifecycleCustomEvent;
121
+ export declare function buildInvokeAgentChildRunStateDelta(input: InvokeAgentChildRunProgressInput): InvokeAgentChildRunStateDelta;
122
+ export declare function buildInvokeAgentChildRunLifecycleCustomEvent(input: InvokeAgentChildRunProgressInput): InvokeAgentChildRunLifecycleCustomEvent;
123
+ export declare function buildInvokeAgentChildRunProgressEvents(input: InvokeAgentChildRunProgressInput): readonly [InvokeAgentChildRunStateDelta, InvokeAgentChildRunLifecycleCustomEvent];
124
+ export declare function publishInvokeAgentChildRunProgress(input: {
125
+ authToken: string;
126
+ apiUrl: string;
127
+ conversationId: string;
128
+ runId: string;
129
+ expectedPreviousEventId?: number;
130
+ expectedPreviousExternalEventSequence?: number;
131
+ toolCallId: string;
132
+ childAgentId: string;
133
+ childConversationId: string;
134
+ childRunId: string;
135
+ childMessageId: string;
136
+ description?: string;
137
+ status: "pending" | "running" | "waiting_for_tool" | "completed" | "failed" | "cancelled";
138
+ sourceTargetKind?: "project" | "production" | "environment" | "preview_branch" | null;
139
+ runtimeTargetKind?: "production" | "environment" | "preview_branch" | null;
140
+ targetEnvironmentId?: string | null;
141
+ targetBranchId?: string | null;
142
+ publishParentRunEvents?: (events: InvokeAgentChildRunProgressEvent[]) => Promise<void> | void;
143
+ abortSignal?: AbortSignal;
144
+ }): Promise<void>;
145
+ //# sourceMappingURL=invoke-agent-child-runs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke-agent-child-runs.d.ts","sourceRoot":"","sources":["../../../src/src/agent/invoke-agent-child-runs.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,uCAAuC;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAalD,CAAC;AAEH,MAAM,MAAM,iCAAiC,GAAG,CAAC,CAAC,KAAK,CACrD,OAAO,uCAAuC,CAC/C,CAAC;AAEF,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAS9C,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mCAAmC,CAAC,CAAC;AAEhG,eAAO,MAAM,6CAA6C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAIxD,CAAC;AAEH,MAAM,MAAM,uCAAuC,GAAG,CAAC,CAAC,KAAK,CAC3D,OAAO,6CAA6C,CACrD,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,UAAU,EAAE,MAAM,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,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,kBAAkB,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC1F,gBAAgB,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,aAAa,GAAG,gBAAgB,GAAG,IAAI,CAAC;IACtF,iBAAiB,CAAC,EAAE,YAAY,GAAG,aAAa,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAC3E,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,sBAAsB,CAAC,EAAE,CAAC,MAAM,EAAE,gCAAgC,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC9F,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BhB"}
@@ -0,0 +1,101 @@
1
+ import "../../_dnt.polyfills.js";
2
+ import { z } from "zod";
3
+ import { appendConversationRunEvents, isIgnorableConversationRunAppendError } from "./durable.js";
4
+ const AG_UI_CUSTOM_EVENT_TYPE = "CUSTOM";
5
+ export const InvokeAgentChildRunLifecycleValueSchema = z.object({
6
+ toolCallId: z.string().min(1),
7
+ childConversationId: z.string().uuid(),
8
+ childRunId: z.string().min(1),
9
+ childMessageId: z.string().uuid(),
10
+ childAgentId: z.string().min(1),
11
+ description: z.string().min(1).optional(),
12
+ status: z.enum(["pending", "running", "waiting_for_tool", "completed", "failed", "cancelled"]),
13
+ sourceTargetKind: z.enum(["project", "production", "environment", "preview_branch"]).nullable()
14
+ .optional(),
15
+ runtimeTargetKind: z.enum(["production", "environment", "preview_branch"]).nullable().optional(),
16
+ targetEnvironmentId: z.string().uuid().nullable().optional(),
17
+ targetBranchId: z.string().uuid().nullable().optional(),
18
+ });
19
+ export const InvokeAgentChildRunStateDeltaSchema = z.object({
20
+ type: z.literal("STATE_DELTA"),
21
+ delta: z.array(z.object({
22
+ op: z.enum(["add", "replace"]),
23
+ path: z.string().min(1),
24
+ value: InvokeAgentChildRunLifecycleValueSchema,
25
+ })),
26
+ });
27
+ export const InvokeAgentChildRunLifecycleCustomEventSchema = z.object({
28
+ type: z.literal(AG_UI_CUSTOM_EVENT_TYPE),
29
+ name: z.literal("veryfront.invoke_agent.lifecycle"),
30
+ value: InvokeAgentChildRunLifecycleValueSchema,
31
+ });
32
+ function buildInvokeAgentChildRunLifecycleValue(input) {
33
+ return InvokeAgentChildRunLifecycleValueSchema.parse({
34
+ toolCallId: input.toolCallId,
35
+ childConversationId: input.childConversationId,
36
+ childRunId: input.childRunId,
37
+ childMessageId: input.childMessageId,
38
+ childAgentId: input.childAgentId,
39
+ ...(input.description ? { description: input.description } : {}),
40
+ status: input.status,
41
+ ...(input.sourceTargetKind !== undefined ? { sourceTargetKind: input.sourceTargetKind } : {}),
42
+ ...(input.runtimeTargetKind !== undefined
43
+ ? { runtimeTargetKind: input.runtimeTargetKind }
44
+ : {}),
45
+ ...(input.targetEnvironmentId !== undefined
46
+ ? { targetEnvironmentId: input.targetEnvironmentId }
47
+ : {}),
48
+ ...(input.targetBranchId !== undefined ? { targetBranchId: input.targetBranchId } : {}),
49
+ });
50
+ }
51
+ export function buildInvokeAgentChildRunStateDelta(input) {
52
+ const escapedToolCallId = input.toolCallId.replaceAll("~", "~0").replaceAll("/", "~1");
53
+ return InvokeAgentChildRunStateDeltaSchema.parse({
54
+ type: "STATE_DELTA",
55
+ delta: [
56
+ {
57
+ op: input.status === "pending" ? "add" : "replace",
58
+ path: `/invokeAgentChildRuns/${escapedToolCallId}`,
59
+ value: buildInvokeAgentChildRunLifecycleValue(input),
60
+ },
61
+ ],
62
+ });
63
+ }
64
+ export function buildInvokeAgentChildRunLifecycleCustomEvent(input) {
65
+ return InvokeAgentChildRunLifecycleCustomEventSchema.parse({
66
+ type: AG_UI_CUSTOM_EVENT_TYPE,
67
+ name: "veryfront.invoke_agent.lifecycle",
68
+ value: buildInvokeAgentChildRunLifecycleValue(input),
69
+ });
70
+ }
71
+ export function buildInvokeAgentChildRunProgressEvents(input) {
72
+ return [
73
+ buildInvokeAgentChildRunStateDelta(input),
74
+ buildInvokeAgentChildRunLifecycleCustomEvent(input),
75
+ ];
76
+ }
77
+ export async function publishInvokeAgentChildRunProgress(input) {
78
+ const events = [...buildInvokeAgentChildRunProgressEvents(input)];
79
+ if (input.publishParentRunEvents) {
80
+ await input.publishParentRunEvents(events);
81
+ return;
82
+ }
83
+ try {
84
+ await appendConversationRunEvents({
85
+ authToken: input.authToken,
86
+ apiUrl: input.apiUrl,
87
+ conversationId: input.conversationId,
88
+ runId: input.runId,
89
+ expectedPreviousEventId: input.expectedPreviousEventId,
90
+ expectedPreviousExternalEventSequence: input.expectedPreviousExternalEventSequence,
91
+ events,
92
+ abortSignal: input.abortSignal,
93
+ });
94
+ }
95
+ catch (error) {
96
+ if (isIgnorableConversationRunAppendError(error)) {
97
+ return;
98
+ }
99
+ throw error;
100
+ }
101
+ }
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.1.233";
1
+ export declare const VERSION = "0.1.234";
2
2
  //# sourceMappingURL=version-constant.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
- export const VERSION = "0.1.233";
3
+ export const VERSION = "0.1.234";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfront",
3
- "version": "0.1.233",
3
+ "version": "0.1.234",
4
4
  "description": "The simplest way to build AI-powered apps",
5
5
  "keywords": [
6
6
  "react",
@@ -77,6 +77,10 @@
77
77
  "import": "./esm/src/agent/durable.js",
78
78
  "types": "./esm/src/agent/durable.d.ts"
79
79
  },
80
+ "./agent/invoke-agent-child-runs": {
81
+ "import": "./esm/src/agent/invoke-agent-child-runs.js",
82
+ "types": "./esm/src/agent/invoke-agent-child-runs.d.ts"
83
+ },
80
84
  "./channels/control-plane": {
81
85
  "import": "./esm/src/channels/control-plane.js",
82
86
  "types": "./esm/src/channels/control-plane.d.ts"
package/src/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.233",
3
+ "version": "0.1.234",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "workspace": [
@@ -32,6 +32,7 @@ export default {
32
32
  "./agent": "./src/agent/index.ts",
33
33
  "./agent/conversation-bootstrap": "./src/agent/conversation-bootstrap.ts",
34
34
  "./agent/durable": "./src/agent/durable.ts",
35
+ "./agent/invoke-agent-child-runs": "./src/agent/invoke-agent-child-runs.ts",
35
36
  "./channels/control-plane": "./src/channels/control-plane.ts",
36
37
  "./channels/invoke": "./src/channels/invoke.ts",
37
38
  "./tool": "./src/tool/index.ts",
@@ -4,6 +4,34 @@ import { z } from "zod";
4
4
 
5
5
  const AGENT_RUN_API_TIMEOUT_MS = 15_000;
6
6
 
7
+ function createTimedAbortSignal(timeoutMs: number, abortSignal?: AbortSignal) {
8
+ const controller = new AbortController();
9
+ let abortedByCaller = false;
10
+ const timeout = dntShim.setTimeout(() => {
11
+ controller.abort();
12
+ }, timeoutMs);
13
+
14
+ const onAbort = () => {
15
+ abortedByCaller = true;
16
+ controller.abort();
17
+ };
18
+
19
+ if (abortSignal?.aborted) {
20
+ onAbort();
21
+ } else {
22
+ abortSignal?.addEventListener("abort", onAbort, { once: true });
23
+ }
24
+
25
+ return {
26
+ signal: controller.signal,
27
+ wasAbortedByCaller: () => abortedByCaller,
28
+ cleanup: () => {
29
+ clearTimeout(timeout);
30
+ abortSignal?.removeEventListener("abort", onAbort);
31
+ },
32
+ };
33
+ }
34
+
7
35
  export const ConversationRunTargetsSchema = z.object({
8
36
  sourceTargetKind: z.enum(["project", "preview_branch"]).nullable(),
9
37
  runtimeTargetKind: z.enum(["production", "preview_branch"]).nullable(),
@@ -37,6 +65,15 @@ export function resolveConversationRunTargets(input: {
37
65
  );
38
66
  }
39
67
 
68
+ export const ConversationRunStatusSchema = z.enum([
69
+ "pending",
70
+ "running",
71
+ "waiting_for_tool",
72
+ "completed",
73
+ "failed",
74
+ "cancelled",
75
+ ]);
76
+
40
77
  export const ConversationRunProjectionSchema = z
41
78
  .object({
42
79
  runId: z.string().min(1).optional(),
@@ -49,7 +86,7 @@ export const ConversationRunProjectionSchema = z
49
86
  latest_event_id: z.number().int().nonnegative().optional(),
50
87
  latestExternalEventSequence: z.number().int().nonnegative().optional(),
51
88
  latest_external_event_sequence: z.number().int().nonnegative().optional(),
52
- status: z.enum(["pending", "running", "waiting_for_tool", "completed", "failed", "cancelled"]),
89
+ status: ConversationRunStatusSchema,
53
90
  })
54
91
  .passthrough()
55
92
  .transform((data) => {
@@ -112,6 +149,59 @@ export const CompleteConversationRunResponseSchema = z
112
149
  })
113
150
  .passthrough();
114
151
 
152
+ const AppendConversationRunEventsCamelRunSchema = z
153
+ .object({
154
+ runId: z.string().min(1),
155
+ conversationId: z.string().uuid(),
156
+ latestEventId: z.number().int().nonnegative(),
157
+ latestExternalEventSequence: z.number().int().nonnegative(),
158
+ })
159
+ .passthrough();
160
+
161
+ const AppendConversationRunEventsSnakeRunSchema = z
162
+ .object({
163
+ run_id: z.string().min(1),
164
+ conversation_id: z.string().uuid(),
165
+ latest_event_id: z.number().int().nonnegative(),
166
+ latest_external_event_sequence: z.number().int().nonnegative(),
167
+ })
168
+ .passthrough();
169
+
170
+ export const AppendConversationRunEventsResponseSchema = z.union([
171
+ z.object({
172
+ latestEventId: z.number().int().nonnegative(),
173
+ latestExternalEventSequence: z.number().int().nonnegative(),
174
+ appendedCount: z.number().int().nonnegative(),
175
+ run: AppendConversationRunEventsCamelRunSchema,
176
+ }),
177
+ z.object({
178
+ latest_event_id: z.number().int().nonnegative(),
179
+ latest_external_event_sequence: z.number().int().nonnegative(),
180
+ appended_count: z.number().int().nonnegative(),
181
+ run: AppendConversationRunEventsSnakeRunSchema,
182
+ }).transform((data) => ({
183
+ latestEventId: data.latest_event_id,
184
+ latestExternalEventSequence: data.latest_external_event_sequence,
185
+ appendedCount: data.appended_count,
186
+ run: {
187
+ ...data.run,
188
+ runId: data.run.run_id,
189
+ conversationId: data.run.conversation_id,
190
+ latestEventId: data.run.latest_event_id,
191
+ latestExternalEventSequence: data.run.latest_external_event_sequence,
192
+ },
193
+ })),
194
+ ]);
195
+
196
+ export type AppendConversationRunEventsResponse = z.infer<
197
+ typeof AppendConversationRunEventsResponseSchema
198
+ >;
199
+
200
+ const ConversationRunErrorSchema = z.object({
201
+ detail: z.string().min(1).optional(),
202
+ error: z.string().min(1).optional(),
203
+ });
204
+
115
205
  export interface ConversationAgentRunUsage {
116
206
  inputTokens: number;
117
207
  outputTokens: number;
@@ -141,6 +231,71 @@ export interface FinalizeConversationAgentRunInput {
141
231
  terminalErrorMessage?: string | null;
142
232
  }
143
233
 
234
+ export class AppendConversationRunEventsError extends Error {
235
+ readonly status: number;
236
+ readonly detail: string | null;
237
+
238
+ constructor(input: {
239
+ status: number;
240
+ detail?: string | null;
241
+ statusText?: string;
242
+ }) {
243
+ const detail = input.detail?.trim() || input.statusText || `HTTP ${input.status}`;
244
+ super(`Append conversation run events failed (${input.status}): ${detail}`);
245
+ this.name = "AppendConversationRunEventsError";
246
+ this.status = input.status;
247
+ this.detail = input.detail?.trim() || null;
248
+ }
249
+ }
250
+
251
+ export function parseAppendConversationRunEventsErrorBody(bodyText: string): string | null {
252
+ if (!bodyText) {
253
+ return null;
254
+ }
255
+
256
+ try {
257
+ const parsed = ConversationRunErrorSchema.safeParse(JSON.parse(bodyText));
258
+ if (parsed.success) {
259
+ return parsed.data.detail ?? parsed.data.error ?? null;
260
+ }
261
+ } catch {
262
+ return bodyText;
263
+ }
264
+
265
+ return bodyText;
266
+ }
267
+
268
+ export function isIgnorableConversationRunAppendError(
269
+ error: unknown,
270
+ ): error is AppendConversationRunEventsError {
271
+ if (!(error instanceof AppendConversationRunEventsError)) {
272
+ return false;
273
+ }
274
+
275
+ if (error.status === 404) {
276
+ return true;
277
+ }
278
+
279
+ if (error.status !== 400) {
280
+ return false;
281
+ }
282
+
283
+ return (
284
+ error.detail === "Cannot append external events to a terminal run" ||
285
+ error.detail === "Cannot append external events while the run is waiting for a tool result"
286
+ );
287
+ }
288
+
289
+ export function isCursorMismatchConversationRunAppendError(
290
+ error: unknown,
291
+ ): error is AppendConversationRunEventsError {
292
+ return (
293
+ error instanceof AppendConversationRunEventsError &&
294
+ error.status === 400 &&
295
+ error.detail === "External run event cursor mismatch"
296
+ );
297
+ }
298
+
144
299
  async function controlPlaneJson<T>(input: {
145
300
  authToken: string;
146
301
  url: string;
@@ -148,11 +303,13 @@ async function controlPlaneJson<T>(input: {
148
303
  body?: unknown;
149
304
  responseSchema: z.ZodSchema<T>;
150
305
  operation: string;
306
+ abortSignal?: AbortSignal;
151
307
  }): Promise<T> {
152
- const controller = new AbortController();
153
- const timeout = dntShim.setTimeout(() => {
154
- controller.abort();
155
- }, AGENT_RUN_API_TIMEOUT_MS);
308
+ if (input.abortSignal?.aborted) {
309
+ throw new DOMException("This operation was aborted", "AbortError");
310
+ }
311
+
312
+ const timedAbort = createTimedAbortSignal(AGENT_RUN_API_TIMEOUT_MS, input.abortSignal);
156
313
 
157
314
  let response: Response;
158
315
  try {
@@ -163,15 +320,19 @@ async function controlPlaneJson<T>(input: {
163
320
  "Content-Type": "application/json",
164
321
  },
165
322
  ...(input.body !== undefined ? { body: JSON.stringify(input.body) } : {}),
166
- signal: controller.signal,
323
+ signal: timedAbort.signal,
167
324
  });
168
325
  } catch (error) {
169
- if (error instanceof DOMException && error.name === "AbortError") {
326
+ if (
327
+ error instanceof DOMException &&
328
+ error.name === "AbortError" &&
329
+ !timedAbort.wasAbortedByCaller()
330
+ ) {
170
331
  throw new Error(`${input.operation} timed out after ${AGENT_RUN_API_TIMEOUT_MS}ms`);
171
332
  }
172
333
  throw error;
173
334
  } finally {
174
- clearTimeout(timeout);
335
+ timedAbort.cleanup();
175
336
  }
176
337
 
177
338
  if (!response.ok) {
@@ -184,6 +345,90 @@ async function controlPlaneJson<T>(input: {
184
345
  return input.responseSchema.parse(await response.json());
185
346
  }
186
347
 
348
+ export async function getConversationRun(input: {
349
+ authToken: string;
350
+ apiUrl: string;
351
+ conversationId: string;
352
+ runId: string;
353
+ abortSignal?: AbortSignal;
354
+ }): Promise<ConversationRunProjection> {
355
+ return controlPlaneJson({
356
+ authToken: input.authToken,
357
+ url: `${input.apiUrl}/conversations/${input.conversationId}/runs/${input.runId}`,
358
+ responseSchema: ConversationRunProjectionSchema,
359
+ operation: "Read conversation durable run projection",
360
+ abortSignal: input.abortSignal,
361
+ });
362
+ }
363
+
364
+ export async function appendConversationRunEvents(input: {
365
+ authToken: string;
366
+ apiUrl: string;
367
+ conversationId: string;
368
+ runId: string;
369
+ expectedPreviousEventId?: number;
370
+ expectedPreviousExternalEventSequence?: number;
371
+ events: unknown[];
372
+ abortSignal?: AbortSignal;
373
+ }): Promise<AppendConversationRunEventsResponse> {
374
+ if (input.abortSignal?.aborted) {
375
+ throw new DOMException("This operation was aborted", "AbortError");
376
+ }
377
+
378
+ const timedAbort = createTimedAbortSignal(AGENT_RUN_API_TIMEOUT_MS, input.abortSignal);
379
+
380
+ let response: Response;
381
+ try {
382
+ response = await fetch(
383
+ `${input.apiUrl}/conversations/${input.conversationId}/runs/${input.runId}/events`,
384
+ {
385
+ method: "POST",
386
+ headers: {
387
+ Authorization: `Bearer ${input.authToken}`,
388
+ "Content-Type": "application/json",
389
+ },
390
+ body: JSON.stringify({
391
+ ...(input.expectedPreviousEventId !== undefined
392
+ ? { expected_previous_event_id: input.expectedPreviousEventId }
393
+ : {}),
394
+ ...(input.expectedPreviousExternalEventSequence !== undefined
395
+ ? {
396
+ expected_previous_external_event_sequence:
397
+ input.expectedPreviousExternalEventSequence,
398
+ }
399
+ : {}),
400
+ events: input.events,
401
+ }),
402
+ signal: timedAbort.signal,
403
+ },
404
+ );
405
+ } catch (error) {
406
+ if (
407
+ error instanceof DOMException &&
408
+ error.name === "AbortError" &&
409
+ !timedAbort.wasAbortedByCaller()
410
+ ) {
411
+ throw new Error(
412
+ `Append conversation run events timed out after ${AGENT_RUN_API_TIMEOUT_MS}ms`,
413
+ );
414
+ }
415
+ throw error;
416
+ } finally {
417
+ timedAbort.cleanup();
418
+ }
419
+
420
+ if (!response.ok) {
421
+ const body = await response.text().catch(() => "");
422
+ throw new AppendConversationRunEventsError({
423
+ status: response.status,
424
+ detail: parseAppendConversationRunEventsErrorBody(body),
425
+ statusText: response.statusText,
426
+ });
427
+ }
428
+
429
+ return AppendConversationRunEventsResponseSchema.parse(await response.json());
430
+ }
431
+
187
432
  export async function createConversationAgentRun(
188
433
  input: CreateConversationAgentRunInput,
189
434
  ): Promise<ConversationRunProjection> {
@@ -222,11 +467,11 @@ export async function createConversationAgentRun(
222
467
  operation: "Create canonical durable run",
223
468
  });
224
469
 
225
- return controlPlaneJson({
470
+ return getConversationRun({
226
471
  authToken: input.authToken,
227
- url: `${input.apiUrl}/conversations/${input.conversationId}/runs/${runId}`,
228
- responseSchema: ConversationRunProjectionSchema,
229
- operation: "Read conversation durable run projection",
472
+ apiUrl: input.apiUrl,
473
+ conversationId: input.conversationId,
474
+ runId,
230
475
  });
231
476
  }
232
477
 
@@ -193,16 +193,39 @@ export {
193
193
  fetchConversationRecord,
194
194
  } from "./conversation-bootstrap.js";
195
195
  export {
196
+ appendConversationRunEvents,
197
+ AppendConversationRunEventsError,
198
+ type AppendConversationRunEventsResponse,
199
+ AppendConversationRunEventsResponseSchema,
196
200
  CompleteConversationRunResponseSchema,
197
201
  type ConversationAgentRunUsage,
198
202
  type ConversationRunProjection,
199
203
  ConversationRunProjectionSchema,
204
+ ConversationRunStatusSchema,
200
205
  type ConversationRunTargets,
201
206
  ConversationRunTargetsSchema,
202
207
  createConversationAgentRun,
203
208
  finalizeConversationAgentRun,
209
+ getConversationRun,
210
+ isCursorMismatchConversationRunAppendError,
211
+ isIgnorableConversationRunAppendError,
212
+ parseAppendConversationRunEventsErrorBody,
204
213
  resolveConversationRunTargets,
205
214
  } from "./durable.js";
215
+ export {
216
+ buildInvokeAgentChildRunLifecycleCustomEvent,
217
+ buildInvokeAgentChildRunProgressEvents,
218
+ buildInvokeAgentChildRunStateDelta,
219
+ type InvokeAgentChildRunLifecycleCustomEvent,
220
+ InvokeAgentChildRunLifecycleCustomEventSchema,
221
+ type InvokeAgentChildRunLifecycleValue,
222
+ InvokeAgentChildRunLifecycleValueSchema,
223
+ type InvokeAgentChildRunProgressEvent,
224
+ type InvokeAgentChildRunProgressInput,
225
+ type InvokeAgentChildRunStateDelta,
226
+ InvokeAgentChildRunStateDeltaSchema,
227
+ publishInvokeAgentChildRunProgress,
228
+ } from "./invoke-agent-child-runs.js";
206
229
  export {
207
230
  type HostedChildLifecycleAdapter,
208
231
  type HostedChildLifecycleRunnerOptions,
@@ -0,0 +1,170 @@
1
+ import "../../_dnt.polyfills.js";
2
+ import { z } from "zod";
3
+ import { appendConversationRunEvents, isIgnorableConversationRunAppendError } from "./durable.js";
4
+
5
+ const AG_UI_CUSTOM_EVENT_TYPE = "CUSTOM";
6
+
7
+ export const InvokeAgentChildRunLifecycleValueSchema = z.object({
8
+ toolCallId: z.string().min(1),
9
+ childConversationId: z.string().uuid(),
10
+ childRunId: z.string().min(1),
11
+ childMessageId: z.string().uuid(),
12
+ childAgentId: z.string().min(1),
13
+ description: z.string().min(1).optional(),
14
+ status: z.enum(["pending", "running", "waiting_for_tool", "completed", "failed", "cancelled"]),
15
+ sourceTargetKind: z.enum(["project", "production", "environment", "preview_branch"]).nullable()
16
+ .optional(),
17
+ runtimeTargetKind: z.enum(["production", "environment", "preview_branch"]).nullable().optional(),
18
+ targetEnvironmentId: z.string().uuid().nullable().optional(),
19
+ targetBranchId: z.string().uuid().nullable().optional(),
20
+ });
21
+
22
+ export type InvokeAgentChildRunLifecycleValue = z.infer<
23
+ typeof InvokeAgentChildRunLifecycleValueSchema
24
+ >;
25
+
26
+ export const InvokeAgentChildRunStateDeltaSchema = z.object({
27
+ type: z.literal("STATE_DELTA"),
28
+ delta: z.array(
29
+ z.object({
30
+ op: z.enum(["add", "replace"]),
31
+ path: z.string().min(1),
32
+ value: InvokeAgentChildRunLifecycleValueSchema,
33
+ }),
34
+ ),
35
+ });
36
+
37
+ export type InvokeAgentChildRunStateDelta = z.infer<typeof InvokeAgentChildRunStateDeltaSchema>;
38
+
39
+ export const InvokeAgentChildRunLifecycleCustomEventSchema = z.object({
40
+ type: z.literal(AG_UI_CUSTOM_EVENT_TYPE),
41
+ name: z.literal("veryfront.invoke_agent.lifecycle"),
42
+ value: InvokeAgentChildRunLifecycleValueSchema,
43
+ });
44
+
45
+ export type InvokeAgentChildRunLifecycleCustomEvent = z.infer<
46
+ typeof InvokeAgentChildRunLifecycleCustomEventSchema
47
+ >;
48
+
49
+ export type InvokeAgentChildRunProgressInput = {
50
+ toolCallId: string;
51
+ childConversationId: string;
52
+ childRunId: string;
53
+ childMessageId: string;
54
+ childAgentId: string;
55
+ description?: string;
56
+ status: "pending" | "running" | "waiting_for_tool" | "completed" | "failed" | "cancelled";
57
+ sourceTargetKind?: "project" | "production" | "environment" | "preview_branch" | null;
58
+ runtimeTargetKind?: "production" | "environment" | "preview_branch" | null;
59
+ targetEnvironmentId?: string | null;
60
+ targetBranchId?: string | null;
61
+ };
62
+
63
+ export type InvokeAgentChildRunProgressEvent =
64
+ | InvokeAgentChildRunStateDelta
65
+ | InvokeAgentChildRunLifecycleCustomEvent;
66
+
67
+ function buildInvokeAgentChildRunLifecycleValue(
68
+ input: InvokeAgentChildRunProgressInput,
69
+ ): InvokeAgentChildRunLifecycleValue {
70
+ return InvokeAgentChildRunLifecycleValueSchema.parse({
71
+ toolCallId: input.toolCallId,
72
+ childConversationId: input.childConversationId,
73
+ childRunId: input.childRunId,
74
+ childMessageId: input.childMessageId,
75
+ childAgentId: input.childAgentId,
76
+ ...(input.description ? { description: input.description } : {}),
77
+ status: input.status,
78
+ ...(input.sourceTargetKind !== undefined ? { sourceTargetKind: input.sourceTargetKind } : {}),
79
+ ...(input.runtimeTargetKind !== undefined
80
+ ? { runtimeTargetKind: input.runtimeTargetKind }
81
+ : {}),
82
+ ...(input.targetEnvironmentId !== undefined
83
+ ? { targetEnvironmentId: input.targetEnvironmentId }
84
+ : {}),
85
+ ...(input.targetBranchId !== undefined ? { targetBranchId: input.targetBranchId } : {}),
86
+ });
87
+ }
88
+
89
+ export function buildInvokeAgentChildRunStateDelta(
90
+ input: InvokeAgentChildRunProgressInput,
91
+ ): InvokeAgentChildRunStateDelta {
92
+ const escapedToolCallId = input.toolCallId.replaceAll("~", "~0").replaceAll("/", "~1");
93
+ return InvokeAgentChildRunStateDeltaSchema.parse({
94
+ type: "STATE_DELTA",
95
+ delta: [
96
+ {
97
+ op: input.status === "pending" ? "add" : "replace",
98
+ path: `/invokeAgentChildRuns/${escapedToolCallId}`,
99
+ value: buildInvokeAgentChildRunLifecycleValue(input),
100
+ },
101
+ ],
102
+ });
103
+ }
104
+
105
+ export function buildInvokeAgentChildRunLifecycleCustomEvent(
106
+ input: InvokeAgentChildRunProgressInput,
107
+ ): InvokeAgentChildRunLifecycleCustomEvent {
108
+ return InvokeAgentChildRunLifecycleCustomEventSchema.parse({
109
+ type: AG_UI_CUSTOM_EVENT_TYPE,
110
+ name: "veryfront.invoke_agent.lifecycle",
111
+ value: buildInvokeAgentChildRunLifecycleValue(input),
112
+ });
113
+ }
114
+
115
+ export function buildInvokeAgentChildRunProgressEvents(
116
+ input: InvokeAgentChildRunProgressInput,
117
+ ): readonly [InvokeAgentChildRunStateDelta, InvokeAgentChildRunLifecycleCustomEvent] {
118
+ return [
119
+ buildInvokeAgentChildRunStateDelta(input),
120
+ buildInvokeAgentChildRunLifecycleCustomEvent(input),
121
+ ] as const;
122
+ }
123
+
124
+ export async function publishInvokeAgentChildRunProgress(input: {
125
+ authToken: string;
126
+ apiUrl: string;
127
+ conversationId: string;
128
+ runId: string;
129
+ expectedPreviousEventId?: number;
130
+ expectedPreviousExternalEventSequence?: number;
131
+ toolCallId: string;
132
+ childAgentId: string;
133
+ childConversationId: string;
134
+ childRunId: string;
135
+ childMessageId: string;
136
+ description?: string;
137
+ status: "pending" | "running" | "waiting_for_tool" | "completed" | "failed" | "cancelled";
138
+ sourceTargetKind?: "project" | "production" | "environment" | "preview_branch" | null;
139
+ runtimeTargetKind?: "production" | "environment" | "preview_branch" | null;
140
+ targetEnvironmentId?: string | null;
141
+ targetBranchId?: string | null;
142
+ publishParentRunEvents?: (events: InvokeAgentChildRunProgressEvent[]) => Promise<void> | void;
143
+ abortSignal?: AbortSignal;
144
+ }): Promise<void> {
145
+ const events = [...buildInvokeAgentChildRunProgressEvents(input)];
146
+
147
+ if (input.publishParentRunEvents) {
148
+ await input.publishParentRunEvents(events);
149
+ return;
150
+ }
151
+
152
+ try {
153
+ await appendConversationRunEvents({
154
+ authToken: input.authToken,
155
+ apiUrl: input.apiUrl,
156
+ conversationId: input.conversationId,
157
+ runId: input.runId,
158
+ expectedPreviousEventId: input.expectedPreviousEventId,
159
+ expectedPreviousExternalEventSequence: input.expectedPreviousExternalEventSequence,
160
+ events,
161
+ abortSignal: input.abortSignal,
162
+ });
163
+ } catch (error) {
164
+ if (isIgnorableConversationRunAppendError(error)) {
165
+ return;
166
+ }
167
+
168
+ throw error;
169
+ }
170
+ }
@@ -1,3 +1,3 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
- export const VERSION = "0.1.233";
3
+ export const VERSION = "0.1.234";