@ai-matrx/agents 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/README.md +41 -16
- package/dist/index.cjs +415 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +396 -3
- package/dist/index.js.map +1 -1
- package/dist/matrx/index.cjs +401 -26
- package/dist/matrx/index.cjs.map +1 -1
- package/dist/matrx/index.d.cts +345 -1
- package/dist/matrx/index.d.ts +345 -1
- package/dist/matrx/index.js +382 -3
- package/dist/matrx/index.js.map +1 -1
- package/dist/presentation/result.cjs +23 -4
- package/dist/presentation/result.cjs.map +1 -1
- package/dist/presentation/result.js +3 -3
- package/dist/presentation/result.js.map +1 -1
- package/dist/projection/request.cjs +25 -6
- package/dist/projection/request.cjs.map +1 -1
- package/dist/projection/request.js +5 -3
- package/dist/projection/request.js.map +1 -1
- package/dist/projection/workflow.cjs +25 -6
- package/dist/projection/workflow.cjs.map +1 -1
- package/dist/projection/workflow.js +5 -3
- package/dist/projection/workflow.js.map +1 -1
- package/dist/react/index.cjs +1038 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +540 -0
- package/dist/react/index.d.ts +540 -0
- package/dist/react/index.js +1016 -0
- package/dist/react/index.js.map +1 -0
- package/dist/stream/ndjson.cjs +26 -7
- package/dist/stream/ndjson.cjs.map +1 -1
- package/dist/stream/ndjson.js +6 -3
- package/dist/stream/ndjson.js.map +1 -1
- package/dist/stream/sse.cjs +25 -6
- package/dist/stream/sse.cjs.map +1 -1
- package/dist/stream/sse.js +5 -3
- package/dist/stream/sse.js.map +1 -1
- package/package.json +28 -2
package/dist/matrx/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CredentialsPort } from '@ai-matrx/data';
|
|
2
|
+
import { ResilientFetchOptions } from '@ai-matrx/data/net';
|
|
1
3
|
import { MatrxStreamEnvelope, MatrxNdjsonIssue, MatrxStreamEnvelopeObservation } from '../stream/ndjson.js';
|
|
2
4
|
import { MatrxSseFrame } from '../stream/sse.js';
|
|
3
5
|
|
|
@@ -94,6 +96,300 @@ declare function extractMatrxErrorMessage(serverDetail: unknown): string | undef
|
|
|
94
96
|
*/
|
|
95
97
|
declare function extractMatrxErrorCode(serverDetail: unknown): string | null;
|
|
96
98
|
|
|
99
|
+
/**
|
|
100
|
+
* The AI API protocol-version policy — which version of the AI runtime a
|
|
101
|
+
* Matrx client talks to, and the v2 → v1 transport fallback (moved in from
|
|
102
|
+
* matrx-frontend `lib/api/ai-api-version.ts` + `call-api.ts::
|
|
103
|
+
* fetchWithV2Fallback` under C22; server truth
|
|
104
|
+
* `aidream/docs/runtime/V2_FRONTEND_MIGRATION.md`).
|
|
105
|
+
*
|
|
106
|
+
* Background: the Python backend exposes a `/v2` runtime-spine namespace that
|
|
107
|
+
* wraps the core AI request surfaces in a request-tracking envelope. Body,
|
|
108
|
+
* headers, and streaming response are BYTE-IDENTICAL to v1 — only the URL
|
|
109
|
+
* differs.
|
|
110
|
+
*
|
|
111
|
+
* ─── The one rule that keeps burning us ─────────────────────────────────────
|
|
112
|
+
* `/v2` is inserted at the FRONT of the in-app path, right before `/ai`:
|
|
113
|
+
*
|
|
114
|
+
* /ai/agents/{id} → /v2/ai/agents/{id} ✅ correct
|
|
115
|
+
* /ai/v2/agents/… ❌ WRONG (nested) — 404s
|
|
116
|
+
*
|
|
117
|
+
* `toV2Path` below is the ONLY place this transform is spelled out.
|
|
118
|
+
*
|
|
119
|
+
* ─── Scope: ONLY the covered surfaces have a v2 form ────────────────────────
|
|
120
|
+
* chat, manual, agents/{id}, conversations/{id} (+ singular aliases),
|
|
121
|
+
* prompts/{id}, mandates/{key}. EVERYTHING ELSE — cancel, warm, resume,
|
|
122
|
+
* fork-and-run, runtime operations, files … — has NO v2 route, and the server
|
|
123
|
+
* does NOT auto-downgrade (a `/v2` request to an uncovered surface is a plain
|
|
124
|
+
* 404). So the transform is a scoped allowlist, never a blanket prefix.
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
type MatrxAiApiVersion = "v1" | "v2";
|
|
128
|
+
/**
|
|
129
|
+
* The package-wide default AI API version — the production value every Matrx
|
|
130
|
+
* client runs unless its host deliberately overrides
|
|
131
|
+
* (`createMatrxTransport({ aiApiVersion })`).
|
|
132
|
+
*/
|
|
133
|
+
declare const MATRX_AI_API_VERSION_DEFAULT: MatrxAiApiVersion;
|
|
134
|
+
/**
|
|
135
|
+
* The canonical v1 path TEMPLATES the v2 spine covers, `{param}` placeholders
|
|
136
|
+
* intact — for hosts that route through a template registry.
|
|
137
|
+
*/
|
|
138
|
+
declare const V2_COVERED_AI_PATH_TEMPLATES: readonly ["/ai/manual", "/ai/chat", "/ai/agents/{agent_id}", "/ai/agent/{agent_id}", "/ai/conversations/{conversation_id}", "/ai/conversation/{conversation_id}", "/ai/prompts/{prompt_id}", "/ai/mandates/{mandate_key}"];
|
|
139
|
+
/**
|
|
140
|
+
* Insert `/v2` at the front of an in-app path. Idempotent, and prefix-aware:
|
|
141
|
+
* a legacy `/api/` compatibility prefix (stripped server-side) is preserved so
|
|
142
|
+
* `/api/ai/chat` → `/api/v2/ai/chat`.
|
|
143
|
+
*/
|
|
144
|
+
declare function toV2Path(path: string): string;
|
|
145
|
+
/** Whether `path` (already interpolated) is one of the covered surfaces. */
|
|
146
|
+
declare function isCoveredAiPath(path: string): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Whether an in-app path (or a full URL whose path was built by `toV2Path`)
|
|
149
|
+
* targets the v2 namespace — the guard the downgrade fallback keys off.
|
|
150
|
+
*/
|
|
151
|
+
declare function isV2Path(pathOrUrl: string): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* The inverse of `toV2Path` — strip the `/v2` version segment so a transport
|
|
154
|
+
* failure of the v2 endpoint (network error, 404/405, 5xx BEFORE any stream
|
|
155
|
+
* content) can retry the identical request on the v1 route. Works on a bare
|
|
156
|
+
* path, an `/api`-prefixed path, or a full URL (the `/v2/ai/` shape is unique
|
|
157
|
+
* to the version namespace). Idempotent on non-v2 input.
|
|
158
|
+
*/
|
|
159
|
+
declare function toV1FallbackUrl(url: string): string;
|
|
160
|
+
/**
|
|
161
|
+
* Apply the active AI API version to an ALREADY-INTERPOLATED in-app path.
|
|
162
|
+
*
|
|
163
|
+
* - Covered surface + v2 → `/v2` prefix inserted.
|
|
164
|
+
* - Anything else (or v1) → returned unchanged.
|
|
165
|
+
*
|
|
166
|
+
* Pass the in-app PATH only (no scheme/host); prepend the base URL afterward.
|
|
167
|
+
*/
|
|
168
|
+
declare function applyAiApiVersion(path: string, version: MatrxAiApiVersion): string;
|
|
169
|
+
/** One v2 → v1 downgrade, surfaced to the host's diagnostics sink. */
|
|
170
|
+
interface MatrxProtocolDowngrade {
|
|
171
|
+
/** The failed v2 URL. */
|
|
172
|
+
url: string;
|
|
173
|
+
/** Why the downgrade fired (thrown error text, or `HTTP <status>`). */
|
|
174
|
+
reason: string;
|
|
175
|
+
/** HTTP status when the trigger was a response (404/405/5xx). */
|
|
176
|
+
status?: number;
|
|
177
|
+
}
|
|
178
|
+
interface MatrxProtocolFallbackOptions extends ResilientFetchOptions {
|
|
179
|
+
/**
|
|
180
|
+
* Fired on every downgrade — a sustained stream of these means a v2 surface
|
|
181
|
+
* is unhealthy. The fallback also `console.warn`s unconditionally (parity
|
|
182
|
+
* with the original host pipeline) so the signal never disappears silently.
|
|
183
|
+
*/
|
|
184
|
+
onDowngrade?: (downgrade: MatrxProtocolDowngrade) => void;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* `resilientFetch` with the v2 → v1 transport fallback. Fires ONLY when a
|
|
188
|
+
* `/v2/ai/...` ENDPOINT itself fails — a network-layer throw (non-abort), a
|
|
189
|
+
* 404/405 (surface not on v2), or a 5xx — always BEFORE any stream content is
|
|
190
|
+
* consumed. Never on an application error (those fail identically on v1), and
|
|
191
|
+
* never on a caller abort (a user cancel must not be logged as a downgrade —
|
|
192
|
+
* that poisons the exact telemetry the rollout reads to judge v2 health).
|
|
193
|
+
*/
|
|
194
|
+
declare function fetchWithMatrxProtocolFallback(url: string, init: RequestInit, opts?: MatrxProtocolFallbackOptions): Promise<{
|
|
195
|
+
response: Response;
|
|
196
|
+
}>;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The PRODUCTION `MatrxTransport` — the full connection pipeline every Matrx
|
|
200
|
+
* host used to hand-roll, moved in under C22 (THE HARD PARTS LIVE IN THE
|
|
201
|
+
* PACKAGE). A host constructs it from identity alone:
|
|
202
|
+
*
|
|
203
|
+
* ```ts
|
|
204
|
+
* const transport = createMatrxTransport({
|
|
205
|
+
* baseUrl: "https://server.app.matrxserver.com",
|
|
206
|
+
* credentials, // CredentialsPort (@ai-matrx/data)
|
|
207
|
+
* organizationId: () => activeOrgId, // omit for conversation-lane calls
|
|
208
|
+
* });
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* Everything else is defaulted to the proven production values:
|
|
212
|
+
*
|
|
213
|
+
* - **timeouts** — connect 15s (for a non-streaming FastAPI handler this is
|
|
214
|
+
* effectively time-to-response), total UNCAPPED (the port cannot tell a JSON
|
|
215
|
+
* call from a long-lived NDJSON/SSE stream; the connect timeout is the JSON
|
|
216
|
+
* guard), via `@ai-matrx/data/net`'s `resilientFetch`;
|
|
217
|
+
* - **protocol** — the AI API version transform (`applyAiApiVersion`, default
|
|
218
|
+
* v2) + the loud v2 → v1 transport fallback (`./protocol`);
|
|
219
|
+
* - **credentials** — read fresh from the injected `CredentialsPort` on EVERY
|
|
220
|
+
* call, so a token refresh mid-run is picked up; mapped to headers by the
|
|
221
|
+
* ONE `credentialToHeaders`;
|
|
222
|
+
* - **org context** — the fail-closed `X-Organization-Id` binding
|
|
223
|
+
* (`./org-context`): configured lanes REQUIRE an org and refuse before the
|
|
224
|
+
* wire; unconfigured lanes (conversation-scoped calls, which carry org in
|
|
225
|
+
* the body) send none;
|
|
226
|
+
* - **error classification** — every failure normalizes through
|
|
227
|
+
* `normalizeMatrxError` into the ONE `MatrxCallError` envelope;
|
|
228
|
+
* - **diagnostics** — a typed sink the host wires to its capture/telemetry
|
|
229
|
+
* (`onRequest`, `onError`, `onProtocolDowngrade`); wiring it is optional,
|
|
230
|
+
* the transport works silently without it.
|
|
231
|
+
*
|
|
232
|
+
* Header merge order is part of the port contract: wire headers first
|
|
233
|
+
* (`Content-Type` / `Accept` / `Last-Event-ID` — the package's), then
|
|
234
|
+
* credentials, then resolver policy headers, then the org header. Policy
|
|
235
|
+
* headers never carry `Content-Type` — the wire owns it, and a policy
|
|
236
|
+
* `Content-Type` merged over a GET SSE call would corrupt the wire, so the
|
|
237
|
+
* factory strips it defensively.
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* The ONE classified error shape for Matrx client calls — the envelope hosts
|
|
242
|
+
* branch on instead of string-matching exceptions. Structurally compatible
|
|
243
|
+
* with matrx-frontend's `ApiCallError` by design.
|
|
244
|
+
*/
|
|
245
|
+
interface MatrxCallError {
|
|
246
|
+
type: "auth_error" | "network_error" | "http_error" | "validation_error" | "abort_error" | "unknown";
|
|
247
|
+
message: string;
|
|
248
|
+
/** HTTP status code, if applicable. */
|
|
249
|
+
status?: number;
|
|
250
|
+
/** Raw error detail from the server (the parsed error body). */
|
|
251
|
+
serverDetail?: unknown;
|
|
252
|
+
/** Machine code preserved through normalization (server `code`, org-context code, …). */
|
|
253
|
+
code?: string;
|
|
254
|
+
/** Original exception identity for diagnostics. */
|
|
255
|
+
name?: string;
|
|
256
|
+
/** Original exception stack. */
|
|
257
|
+
stack?: string;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Classify any failure thrown by a package client call — `MatrxApiError`,
|
|
261
|
+
* a `NetError` from the resilience layer, an org-context refusal, an abort —
|
|
262
|
+
* into the `MatrxCallError` envelope. Never throws.
|
|
263
|
+
*/
|
|
264
|
+
declare function normalizeMatrxError(err: unknown): MatrxCallError;
|
|
265
|
+
/**
|
|
266
|
+
* A fully-resolved connection target for one call: where to send it and which
|
|
267
|
+
* policy headers ride ON TOP of the wire + credential headers.
|
|
268
|
+
*/
|
|
269
|
+
interface MatrxTransportTarget {
|
|
270
|
+
/** Fully-qualified base URL, no trailing slash. */
|
|
271
|
+
baseUrl: string;
|
|
272
|
+
/**
|
|
273
|
+
* Extra policy headers for this target (e.g. a resolver that carries its own
|
|
274
|
+
* credential headers). `Content-Type` is stripped — the wire owns it.
|
|
275
|
+
*/
|
|
276
|
+
policyHeaders?: Record<string, string>;
|
|
277
|
+
/** Routing channel label surfaced to `onRequest` telemetry. */
|
|
278
|
+
channel?: string;
|
|
279
|
+
}
|
|
280
|
+
/** Context handed to every diagnostics callback. */
|
|
281
|
+
interface MatrxRequestInfo {
|
|
282
|
+
/** The final URL (base + version-transformed path). */
|
|
283
|
+
url: string;
|
|
284
|
+
method: "GET" | "POST";
|
|
285
|
+
/** The server-relative path as the package requested it. */
|
|
286
|
+
path: string;
|
|
287
|
+
/** The resolved routing channel (default "default"). */
|
|
288
|
+
channel: string;
|
|
289
|
+
/** The transport's call-site label (default "matrxTransport"). */
|
|
290
|
+
source: string;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* The typed diagnostics sink — the host wires these to its telemetry/capture
|
|
294
|
+
* systems; all optional, and the transport is fully functional without them.
|
|
295
|
+
*/
|
|
296
|
+
interface MatrxTransportDiagnostics {
|
|
297
|
+
/** Fired at the last pre-fetch moment of every call. */
|
|
298
|
+
onRequest?: (info: MatrxRequestInfo) => void;
|
|
299
|
+
/**
|
|
300
|
+
* Fired for every thrown network failure and every non-2xx response not
|
|
301
|
+
* listed in `expectedErrorStatuses`, with the classified envelope.
|
|
302
|
+
*/
|
|
303
|
+
onError?: (error: MatrxCallError, info: MatrxRequestInfo) => void;
|
|
304
|
+
/** Fired on every v2 → v1 protocol downgrade. */
|
|
305
|
+
onProtocolDowngrade?: (downgrade: MatrxProtocolDowngrade) => void;
|
|
306
|
+
}
|
|
307
|
+
interface CreateMatrxTransportOptions {
|
|
308
|
+
/** Fixed base URL, no trailing slash. Exactly one of `baseUrl` / `resolveTarget`. */
|
|
309
|
+
baseUrl?: string;
|
|
310
|
+
/**
|
|
311
|
+
* Per-call target resolver — for hosts whose base URL / policy headers are
|
|
312
|
+
* dynamic (server toggles, sandbox overrides, conversation channels).
|
|
313
|
+
* Resolution runs fresh on EVERY call. May throw to refuse a call loudly.
|
|
314
|
+
*/
|
|
315
|
+
resolveTarget?: () => MatrxTransportTarget;
|
|
316
|
+
/**
|
|
317
|
+
* The credential source (`@ai-matrx/data`), read fresh per call so token
|
|
318
|
+
* refreshes are picked up mid-run. Omit only when the resolver's
|
|
319
|
+
* `policyHeaders` already carry the credentials.
|
|
320
|
+
*/
|
|
321
|
+
credentials?: CredentialsPort;
|
|
322
|
+
/**
|
|
323
|
+
* The org-context binding. When configured, every call REQUIRES a valid org
|
|
324
|
+
* (fail-closed `organization_context_required` before the wire) and carries
|
|
325
|
+
* `X-Organization-Id`. Omit for conversation-lane transports, which send the
|
|
326
|
+
* org in the body only.
|
|
327
|
+
*/
|
|
328
|
+
organizationId?: string | (() => string | null | undefined);
|
|
329
|
+
/** AI API protocol version (value or per-call getter). Default `"v2"`. */
|
|
330
|
+
aiApiVersion?: MatrxAiApiVersion | (() => MatrxAiApiVersion);
|
|
331
|
+
/** Max ms request start → response headers. Default 15_000. */
|
|
332
|
+
connectTimeoutMs?: number;
|
|
333
|
+
/**
|
|
334
|
+
* Max ms for the whole handshake. Default `null` (uncapped) — the port
|
|
335
|
+
* cannot tell a JSON call from a long-lived stream, and capping would kill
|
|
336
|
+
* long streams; the connect timeout is the real JSON guard.
|
|
337
|
+
*/
|
|
338
|
+
totalTimeoutMs?: number | null;
|
|
339
|
+
/**
|
|
340
|
+
* HTTP failures this transport's call class fully handles as expected
|
|
341
|
+
* domain outcomes (e.g. 404 on runtime-operation identify). They still
|
|
342
|
+
* reach the package client (which maps them to typed results) but are not
|
|
343
|
+
* reported through `onError`.
|
|
344
|
+
*/
|
|
345
|
+
expectedErrorStatuses?: readonly number[];
|
|
346
|
+
/** Short call-site label surfaced on `MatrxRequestInfo` (default "matrxTransport"). */
|
|
347
|
+
source?: string;
|
|
348
|
+
diagnostics?: MatrxTransportDiagnostics;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Build the production `MatrxTransport`. See the module doc for the pipeline;
|
|
352
|
+
* every knob defaults to the proven production value.
|
|
353
|
+
*/
|
|
354
|
+
declare function createMatrxTransport(options: CreateMatrxTransportOptions): MatrxTransport;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* The fail-closed organization-context kernel — ONE implementation for every
|
|
358
|
+
* Matrx client transport (moved in from matrx-frontend
|
|
359
|
+
* `lib/api/organization-context.ts` verbatim under C22; the host module is now
|
|
360
|
+
* a re-export of this one).
|
|
361
|
+
*
|
|
362
|
+
* Transports resolve their authoritative organization first, then use these
|
|
363
|
+
* functions to bind that exact value without guessing or defaulting. The
|
|
364
|
+
* server never manufactures an org (it 422s a blank one), so the client
|
|
365
|
+
* refuses before the wire: a missing or malformed org id throws
|
|
366
|
+
* `OrganizationContextError` instead of sending a request that cannot succeed.
|
|
367
|
+
*/
|
|
368
|
+
type OrganizationContextErrorCode = "organization_context_required" | "organization_context_invalid" | "organization_context_mismatch";
|
|
369
|
+
declare class OrganizationContextError extends Error {
|
|
370
|
+
readonly code: OrganizationContextErrorCode;
|
|
371
|
+
constructor(code: OrganizationContextErrorCode, message: string);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Normalize and validate the effective organization id for a request. The
|
|
375
|
+
* override (an explicit per-call value) beats the selected context value.
|
|
376
|
+
* Throws `organization_context_required` when neither is present and
|
|
377
|
+
* `organization_context_invalid` when the candidate is not a UUID.
|
|
378
|
+
*/
|
|
379
|
+
declare function requireOrganizationContext(selectedOrganizationId: string | null | undefined, overrideOrganizationId?: string): string;
|
|
380
|
+
/**
|
|
381
|
+
* Bind `X-Organization-Id` onto a header bag. A pre-existing org header that
|
|
382
|
+
* disagrees with the context org is a `organization_context_mismatch` error —
|
|
383
|
+
* never silently overwritten in either direction.
|
|
384
|
+
*/
|
|
385
|
+
declare function applyOrganizationContextHeader(headers: Record<string, string>, organizationId: string): Record<string, string>;
|
|
386
|
+
/**
|
|
387
|
+
* Assert that an `organization_id` query parameter (when present) matches the
|
|
388
|
+
* request context organization — the query string must never smuggle a
|
|
389
|
+
* different org past the header binding.
|
|
390
|
+
*/
|
|
391
|
+
declare function assertQueryOrganizationMatchesContext(queryParams: Record<string, string | number | boolean> | undefined, organizationId: string): void;
|
|
392
|
+
|
|
97
393
|
/**
|
|
98
394
|
* The conversation-start contract — client-minted `conversation_id`, `is_new`,
|
|
99
395
|
* `store` — typed exactly per the cross-repo System of Record
|
|
@@ -585,6 +881,54 @@ interface FollowRuntimeOperationOptions {
|
|
|
585
881
|
* retry policy).
|
|
586
882
|
*/
|
|
587
883
|
declare function followRuntimeOperationEvents(transport: MatrxTransport, executionId: string, options?: FollowRuntimeOperationOptions): AsyncGenerator<MatrxOperationFollowEvent, void, undefined>;
|
|
884
|
+
interface FollowRuntimeOperationToEndOptions {
|
|
885
|
+
/** Resume cursor — the operation view's `last_event_seq` (0 = from start). */
|
|
886
|
+
lastEventSeq?: number;
|
|
887
|
+
/** Caller teardown — aborting resolves with `ended: false`. */
|
|
888
|
+
signal?: AbortSignal;
|
|
889
|
+
/**
|
|
890
|
+
* The server pings every ~15s, so a wire that is open but silent past this
|
|
891
|
+
* is dead (buffering proxy, idle-killed connection) — abort the attempt and
|
|
892
|
+
* retry rather than hanging forever. Default 45_000.
|
|
893
|
+
*/
|
|
894
|
+
stallTimeoutMs?: number;
|
|
895
|
+
/**
|
|
896
|
+
* Consecutive failed attempts before giving up. A single-server deployment
|
|
897
|
+
* deliberately drains for 60s, then starts a new container — the default
|
|
898
|
+
* budget (60 × 2s) keeps following for ~three minutes so the runtime ledger
|
|
899
|
+
* can bridge that handoff. ANY parsed frame resets the budget. Default 60.
|
|
900
|
+
*/
|
|
901
|
+
reconnectLimit?: number;
|
|
902
|
+
/** Delay between attempts. Default 2_000. */
|
|
903
|
+
reconnectDelayMs?: number;
|
|
904
|
+
/** Fired per durable spine event (lifecycle transitions + notes). */
|
|
905
|
+
onEvent: (event: MatrxRuntimeOperationEvent, seq: number | null) => void;
|
|
906
|
+
/** A failed attempt (never silently swallowed when provided). */
|
|
907
|
+
onAttemptError?: (error: unknown) => void;
|
|
908
|
+
/** A frame whose payload failed to parse (the ledger heals gaps on reconnect). */
|
|
909
|
+
onMalformedFrame?: (frame: MatrxSseFrame, error: unknown) => void;
|
|
910
|
+
}
|
|
911
|
+
interface FollowRuntimeOperationToEndResult {
|
|
912
|
+
/** True when the server sent the terminal `end` frame. */
|
|
913
|
+
ended: boolean;
|
|
914
|
+
/** The root status carried on the `end` frame (when `ended`). */
|
|
915
|
+
status: MatrxRuntimeExecutionStatus | null;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Follow an operation's lifecycle stream TO ITS END — the full production
|
|
919
|
+
* reconnect policy over `followRuntimeOperationEvents`: replay-then-follow
|
|
920
|
+
* with bounded reconnects, a stall watchdog, and durable `Last-Event-ID`
|
|
921
|
+
* cursor advancement across attempts.
|
|
922
|
+
*
|
|
923
|
+
* Resolves `{ended: true, status}` on the server's `end` frame (the operation
|
|
924
|
+
* settled); `{ended: false}` when the caller aborted or every reconnect
|
|
925
|
+
* attempt failed. A WAITING_INPUT park keeps the stream open by design — a
|
|
926
|
+
* resume re-attaches to the same execution and its events continue arriving
|
|
927
|
+
* on the same cursor. Any parsed frame — comment heartbeats included —
|
|
928
|
+
* proves the wire is alive and resets both the stall timer and the retry
|
|
929
|
+
* budget.
|
|
930
|
+
*/
|
|
931
|
+
declare function followRuntimeOperationToEnd(transport: MatrxTransport, executionId: string, options: FollowRuntimeOperationToEndOptions): Promise<FollowRuntimeOperationToEndResult>;
|
|
588
932
|
/**
|
|
589
933
|
* Rejoin the ORIGINAL NDJSON response while its detached task is still alive:
|
|
590
934
|
* `POST /runtime/operations/{request_id}/rejoin`. Replays the response from
|
|
@@ -688,4 +1032,4 @@ declare function listUserPendingToolCalls(transport: MatrxTransport, options?: {
|
|
|
688
1032
|
signal?: AbortSignal;
|
|
689
1033
|
}): Promise<MatrxPendingCallSummary[]>;
|
|
690
1034
|
|
|
691
|
-
export { type FollowRuntimeOperationOptions, type MatrxAgentStartRequest, MatrxApiError, type MatrxCancelResponse, type MatrxChatMessage, type MatrxClientToolResult, type MatrxCompletedRun, type MatrxContextAnchor, type MatrxConversationContinueRequest, type MatrxConversationResumeRequest, type MatrxConversationStart, type MatrxEphemeralConversation, type MatrxJsonObject, type MatrxJsonValue, type MatrxOperationEventsPage, type MatrxOperationFollowEvent, type MatrxOperationStatusResponse, type MatrxOperationsByLinkResponse, type MatrxPendingCallSummary, type MatrxRequestScope, MatrxRunError, type MatrxRunHandle, type MatrxRuntimeExecutionStatus, type MatrxRuntimeOperationEvent, type MatrxRuntimeOperationView, type MatrxStoredConversationContinue, type MatrxStoredConversationCreate, type MatrxStreamCallOptions, type MatrxToolResultsResponse, type MatrxTransport, type MatrxTransportRequest, type MatrxTurnFields, type RunAgentToCompletionOptions, TERMINAL_MATRX_RUNTIME_STATUSES, cancelAgentRun, continueAgentConversation, continueEphemeralConversationStart, continueStoredConversationStart, extractMatrxErrorCode, extractMatrxErrorMessage, followRuntimeOperationEvents, getRuntimeOperationStatus, getRuntimeOperationsByLink, listConversationPendingToolCalls, listRuntimeOperationEvents, listUserPendingToolCalls, mintMatrxConversationId, newEphemeralConversationStart, newStoredConversationStart, rejoinRuntimeOperation, resumeAgentConversation, runAgentToCompletion, startAgentRun, submitAgentToolResults };
|
|
1035
|
+
export { type CreateMatrxTransportOptions, type FollowRuntimeOperationOptions, type FollowRuntimeOperationToEndOptions, type FollowRuntimeOperationToEndResult, MATRX_AI_API_VERSION_DEFAULT, type MatrxAgentStartRequest, type MatrxAiApiVersion, MatrxApiError, type MatrxCallError, type MatrxCancelResponse, type MatrxChatMessage, type MatrxClientToolResult, type MatrxCompletedRun, type MatrxContextAnchor, type MatrxConversationContinueRequest, type MatrxConversationResumeRequest, type MatrxConversationStart, type MatrxEphemeralConversation, type MatrxJsonObject, type MatrxJsonValue, type MatrxOperationEventsPage, type MatrxOperationFollowEvent, type MatrxOperationStatusResponse, type MatrxOperationsByLinkResponse, type MatrxPendingCallSummary, type MatrxProtocolDowngrade, type MatrxProtocolFallbackOptions, type MatrxRequestInfo, type MatrxRequestScope, MatrxRunError, type MatrxRunHandle, type MatrxRuntimeExecutionStatus, type MatrxRuntimeOperationEvent, type MatrxRuntimeOperationView, type MatrxStoredConversationContinue, type MatrxStoredConversationCreate, type MatrxStreamCallOptions, type MatrxToolResultsResponse, type MatrxTransport, type MatrxTransportDiagnostics, type MatrxTransportRequest, type MatrxTransportTarget, type MatrxTurnFields, OrganizationContextError, type OrganizationContextErrorCode, type RunAgentToCompletionOptions, TERMINAL_MATRX_RUNTIME_STATUSES, V2_COVERED_AI_PATH_TEMPLATES, applyAiApiVersion, applyOrganizationContextHeader, assertQueryOrganizationMatchesContext, cancelAgentRun, continueAgentConversation, continueEphemeralConversationStart, continueStoredConversationStart, createMatrxTransport, extractMatrxErrorCode, extractMatrxErrorMessage, fetchWithMatrxProtocolFallback, followRuntimeOperationEvents, followRuntimeOperationToEnd, getRuntimeOperationStatus, getRuntimeOperationsByLink, isCoveredAiPath, isV2Path, listConversationPendingToolCalls, listRuntimeOperationEvents, listUserPendingToolCalls, mintMatrxConversationId, newEphemeralConversationStart, newStoredConversationStart, normalizeMatrxError, rejoinRuntimeOperation, requireOrganizationContext, resumeAgentConversation, runAgentToCompletion, startAgentRun, submitAgentToolResults, toV1FallbackUrl, toV2Path };
|