@ai-matrx/agents 0.22.0 → 0.24.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/content-transfer/index.cjs +33 -33
  3. package/dist/content-transfer/index.cjs.map +1 -1
  4. package/dist/content-transfer/index.d.cts +1 -1
  5. package/dist/content-transfer/index.d.ts +1 -1
  6. package/dist/content-transfer/index.js +33 -33
  7. package/dist/content-transfer/index.js.map +1 -1
  8. package/dist/content-transfer/react/index.cjs +33 -33
  9. package/dist/content-transfer/react/index.cjs.map +1 -1
  10. package/dist/content-transfer/react/index.js +33 -33
  11. package/dist/content-transfer/react/index.js.map +1 -1
  12. package/dist/index.cjs +404 -131
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +404 -131
  17. package/dist/index.js.map +1 -1
  18. package/dist/mandates/index.cjs +2 -2
  19. package/dist/mandates/index.cjs.map +1 -1
  20. package/dist/mandates/index.d.cts +4 -4
  21. package/dist/mandates/index.d.ts +4 -4
  22. package/dist/mandates/index.js +2 -2
  23. package/dist/mandates/index.js.map +1 -1
  24. package/dist/matrx/index.cjs +404 -131
  25. package/dist/matrx/index.cjs.map +1 -1
  26. package/dist/matrx/index.d.cts +242 -4
  27. package/dist/matrx/index.d.ts +242 -4
  28. package/dist/matrx/index.js +404 -131
  29. package/dist/matrx/index.js.map +1 -1
  30. package/dist/react/index.cjs +41 -41
  31. package/dist/react/index.cjs.map +1 -1
  32. package/dist/react/index.js +41 -41
  33. package/dist/react/index.js.map +1 -1
  34. package/mandates/snapshots/keys.0.23.0.json +652 -0
  35. package/mandates/snapshots/keys.0.24.0.json +652 -0
  36. package/package.json +4 -4
@@ -1,8 +1,8 @@
1
- import { B as MatrxTransport, m as MatrxJsonValue, l as MatrxJsonObject } from '../operations--f5ko9Su.cjs';
2
- export { F as FollowRuntimeOperationOptions, a as FollowRuntimeOperationToEndOptions, b as FollowRuntimeOperationToEndResult, M as MatrxAgentStartRequest, c as MatrxApiError, d as MatrxCancelResponse, e as MatrxChatMessage, f as MatrxCompletedRun, g as MatrxContextAnchor, h as MatrxConversationContinueRequest, i as MatrxConversationResumeRequest, j as MatrxConversationStart, k as MatrxEphemeralConversation, n as MatrxMandateStartRequest, o as MatrxOperationEventsPage, p as MatrxOperationFollowEvent, q as MatrxOperationStatusResponse, r as MatrxOperationsByLinkResponse, s as MatrxRequestScope, t as MatrxRunError, u as MatrxRunHandle, v as MatrxRuntimeExecutionStatus, w as MatrxRuntimeOperationEvent, x as MatrxRuntimeOperationView, y as MatrxStoredConversationContinue, z as MatrxStoredConversationCreate, A as MatrxStreamCallOptions, C as MatrxTransportRequest, D as MatrxTurnFields, R as RunAgentToCompletionOptions, T as TERMINAL_MATRX_RUNTIME_STATUSES, E as cancelAgentRun, G as continueAgentConversation, H as continueEphemeralConversationStart, I as continueStoredConversationStart, J as extractMatrxErrorCode, K as extractMatrxErrorMessage, L as followRuntimeOperationEvents, N as followRuntimeOperationToEnd, O as getRuntimeOperationStatus, P as getRuntimeOperationsByLink, Q as listRuntimeOperationEvents, S as mintMatrxConversationId, U as newEphemeralConversationStart, V as newStoredConversationStart, W as rejoinRuntimeOperation, X as resumeAgentConversation, Y as runAgentToCompletion, Z as startAgentRun, _ as startMandateRun } from '../operations--f5ko9Su.cjs';
1
+ import { B as MatrxTransport, A as MatrxStreamCallOptions, w as MatrxRuntimeOperationEvent, a as FollowRuntimeOperationToEndOptions, v as MatrxRuntimeExecutionStatus, c as MatrxApiError, u as MatrxRunHandle, m as MatrxJsonValue, l as MatrxJsonObject } from '../operations--f5ko9Su.cjs';
2
+ export { F as FollowRuntimeOperationOptions, b as FollowRuntimeOperationToEndResult, M as MatrxAgentStartRequest, d as MatrxCancelResponse, e as MatrxChatMessage, f as MatrxCompletedRun, g as MatrxContextAnchor, h as MatrxConversationContinueRequest, i as MatrxConversationResumeRequest, j as MatrxConversationStart, k as MatrxEphemeralConversation, n as MatrxMandateStartRequest, o as MatrxOperationEventsPage, p as MatrxOperationFollowEvent, q as MatrxOperationStatusResponse, r as MatrxOperationsByLinkResponse, s as MatrxRequestScope, t as MatrxRunError, x as MatrxRuntimeOperationView, y as MatrxStoredConversationContinue, z as MatrxStoredConversationCreate, C as MatrxTransportRequest, D as MatrxTurnFields, R as RunAgentToCompletionOptions, T as TERMINAL_MATRX_RUNTIME_STATUSES, E as cancelAgentRun, G as continueAgentConversation, H as continueEphemeralConversationStart, I as continueStoredConversationStart, J as extractMatrxErrorCode, K as extractMatrxErrorMessage, L as followRuntimeOperationEvents, N as followRuntimeOperationToEnd, O as getRuntimeOperationStatus, P as getRuntimeOperationsByLink, Q as listRuntimeOperationEvents, S as mintMatrxConversationId, U as newEphemeralConversationStart, V as newStoredConversationStart, W as rejoinRuntimeOperation, X as resumeAgentConversation, Y as runAgentToCompletion, Z as startAgentRun, _ as startMandateRun } from '../operations--f5ko9Su.cjs';
3
3
  import { CredentialsPort } from '@ai-matrx/data';
4
4
  import { ResilientFetchOptions } from '@ai-matrx/data/net';
5
- import '../stream/ndjson.cjs';
5
+ import { MatrxStreamEnvelope } from '../stream/ndjson.cjs';
6
6
  import '../stream/sse.cjs';
7
7
 
8
8
  /**
@@ -307,6 +307,244 @@ declare function applyOrganizationContextHeader(headers: Record<string, string>,
307
307
  */
308
308
  declare function assertQueryOrganizationMatchesContext(queryParams: Record<string, string | number | boolean> | undefined, organizationId: string): void;
309
309
 
310
+ /**
311
+ * Resume-or-rejoin — the ONE client behavior for "pick a run back up".
312
+ *
313
+ * Server truth (aidream `services/runtime/FEATURE.md` § "A live run is
314
+ * REJOINED, never resumed beside itself"; `reconnect.run_in_progress_error`):
315
+ * - Every resume / retry / continue door asked to resume a run that is STILL
316
+ * LIVE answers `409` with, at the ROOT of the error body,
317
+ * `{error, code: "run_in_progress", live_request_id, rejoin_path, message,
318
+ * …extras}` (extras: `run_id` for workflow / SEO / comparison, `arm_index` /
319
+ * `arm`, `analysis_id`). The client follows `rejoin_path` — never a URL it
320
+ * builds — because a door outside the spine (SEO collections) answers
321
+ * `live_request_id: null` with its own `/seo/collections/{run_id}/rejoin`.
322
+ * - Chat/conversation resume keeps `code: "resume_conflict"` for older clients
323
+ * but ALSO carries `live_request_id` + `rejoin_path` (+
324
+ * `details.live_request_id`) when the run is live — then rejoin, never the
325
+ * retry loop. A bare `resume_conflict` (no rejoin target) stays host retry.
326
+ * - The envelope RESERVES `request_id` for the refusing call's own id — the
327
+ * live run is read from `live_request_id`, never `request_id` (reading it
328
+ * rejoined a request that did not exist: 404, 2026-10-01).
329
+ * - A rejoin answers `409 live_stream_unavailable` when there is no journal to
330
+ * replay (resumed workflow legs, comparison arms). Then: a body naming a
331
+ * workflow `run_id` → follow `GET /runs/{run_id}/events/stream` (the workflow
332
+ * SSE, which also carries the node_stream media frames); otherwise follow the
333
+ * durable lifecycle (`followRuntimeOperationToEnd`).
334
+ *
335
+ * Resume and rejoin are work on an EXISTING run, so they carry THAT run's
336
+ * organization (`organizationId`), never whatever the session has selected.
337
+ */
338
+
339
+ declare const MATRX_RUN_IN_PROGRESS = "run_in_progress";
340
+ declare const MATRX_RESUME_CONFLICT = "resume_conflict";
341
+ declare const MATRX_LIVE_STREAM_UNAVAILABLE = "live_stream_unavailable";
342
+ /**
343
+ * Any error carrying an HTTP status and the parsed server body —
344
+ * `MatrxApiError`, matrx-frontend's `ApiCallError`, or a host's own shape.
345
+ */
346
+ interface MatrxHttpErrorLike {
347
+ status?: unknown;
348
+ serverDetail?: unknown;
349
+ }
350
+ /**
351
+ * The machine code of a Matrx HTTP error: `code` (or the envelope's hoisted
352
+ * `error`) from `detail`, `details`, or the top level. Null when absent.
353
+ */
354
+ declare function readMatrxErrorCode(error: unknown): string | null;
355
+ /** Where to rejoin a live run, read from a resume door's 409. */
356
+ interface MatrxLiveRunRejoin {
357
+ /** The live request (`GET /runtime/operations/{id}`); null for doors outside the spine (SEO). */
358
+ liveRequestId: string | null;
359
+ /** Server-relative path to `POST` for the NDJSON replay-then-follow. Always from the body when present. */
360
+ rejoinPath: string;
361
+ /** `run_id` extra (workflow / SEO / comparison), when present. */
362
+ runId: string | null;
363
+ /** The refusal's code: `run_in_progress`, or chat's `resume_conflict` carrying a rejoin target. */
364
+ code: string;
365
+ /** The refusal body (root of the envelope), for door-specific extras (`arm_index`, `analysis_id`, …). */
366
+ body: Record<string, unknown>;
367
+ }
368
+ /**
369
+ * The rejoin target of a live-run refusal: `409` with `code: run_in_progress`,
370
+ * or chat's `409 resume_conflict` that names a live run. Null for every other
371
+ * error (a genuine failure is never mistaken for a live run). Reads
372
+ * `rejoin_path` from the body first; derives the runtime rejoin from
373
+ * `live_request_id` only when the body names no path. Never reads
374
+ * `request_id`.
375
+ */
376
+ declare function readLiveRunRejoin(error: unknown): MatrxLiveRunRejoin | null;
377
+ /**
378
+ * The request id of a run that is STILL LIVE, read from a resume door's
379
+ * refusal (`live_request_id` — never the envelope's own `request_id`). Null
380
+ * for every other error, and for a live refusal outside the spine (SEO) —
381
+ * follow `readLiveRunRejoin(error).rejoinPath` instead.
382
+ */
383
+ declare function readLiveRunRequestId(error: unknown): string | null;
384
+ /**
385
+ * A bare `409 resume_conflict` — another resume holds the claim and NO live
386
+ * run is named; retry is host policy. (A `resume_conflict` that names a live
387
+ * run is a rejoin — `readLiveRunRejoin`.)
388
+ */
389
+ declare function isResumeConflict(error: unknown): boolean;
390
+ /** `409 live_stream_unavailable` — the rejoin journal is gone; follow the durable lifecycle instead. */
391
+ declare function isLiveStreamUnavailable(error: unknown): boolean;
392
+ /**
393
+ * The server-relative rejoin path — for hosts whose stream pipeline takes a
394
+ * URL instead of a transport (prepend the resolved base URL).
395
+ */
396
+ declare function runtimeOperationRejoinPath(requestId: string): string;
397
+ /**
398
+ * The text to show for a stream `error` event: the server's `user_message`
399
+ * first (it is written for the person — e.g. "OpenAI refused this request:
400
+ * the platform's OpenAI account is out of credit."), then `message`. Accepts
401
+ * the `{event, data}` envelope or its `data` payload. Null when neither is
402
+ * present — the host supplies its own fallback; it must never REPLACE a
403
+ * message the server sent.
404
+ */
405
+ declare function streamErrorText(eventOrPayload: unknown): string | null;
406
+ /**
407
+ * Open any Matrx NDJSON stream by path (`POST`, optional JSON body) — for
408
+ * feature doors outside the agent lifecycle (`/podcast/resume/{run_id}`, …)
409
+ * so their streams ride the same transport and wire kernel as every run.
410
+ */
411
+ declare function openMatrxStream(transport: MatrxTransport, path: string, options?: MatrxStreamCallOptions & {
412
+ body?: unknown;
413
+ }): Promise<MatrxRunHandle>;
414
+ /**
415
+ * Bind a run's organization onto every call as `X-Organization-Id`. Host
416
+ * policy headers still merge on top; the package's own `createMatrxTransport`
417
+ * refuses a disagreeing org (`organization_context_mismatch`) rather than
418
+ * silently swapping it, so a host must not force the SESSION org onto a
419
+ * resume/rejoin transport.
420
+ */
421
+ declare function withRunOrganization(transport: MatrxTransport, organizationId: string): MatrxTransport;
422
+ /**
423
+ * Follow a workflow run's SSE (`GET /runs/{run_id}/events/stream`) — the
424
+ * rejoin fallback for workflow legs with no stream journal. Delivers every
425
+ * parsed event (durable run events with their seq; ephemeral `node_stream`
426
+ * frames — including `kind: "media"` — with seq null). One connection, no
427
+ * reconnect policy: resolves `{ended: true}` on the server's `end` frame,
428
+ * `{ended: false}` when the wire closes or the caller aborts.
429
+ */
430
+ declare function followWorkflowRunEvents(transport: MatrxTransport, runId: string, options: {
431
+ onEvent: (event: Record<string, unknown>, seq: number | null) => void;
432
+ lastEventId?: number | null;
433
+ signal?: AbortSignal;
434
+ }): Promise<{
435
+ ended: boolean;
436
+ }>;
437
+ type ResumeOrRejoinOutcome =
438
+ /** The resume door ran the run; its stream was delivered to `onEnvelope`. */
439
+ {
440
+ kind: "resumed";
441
+ requestId: string | null;
442
+ }
443
+ /** The run was live; its stream (from `rejoin_path`) was replayed + followed into `onEnvelope`. */
444
+ | {
445
+ kind: "rejoined";
446
+ rejoin: MatrxLiveRunRejoin;
447
+ }
448
+ /**
449
+ * The run was live but had no journal to replay; the durable lifecycle was
450
+ * followed instead. Re-query the feature's record for the result.
451
+ * `ended: false` = the follow gave up (or no operation was found).
452
+ */
453
+ | {
454
+ kind: "followed";
455
+ rejoin: MatrxLiveRunRejoin;
456
+ executionId: string | null;
457
+ ended: boolean;
458
+ status: MatrxRuntimeExecutionStatus | null;
459
+ }
460
+ /** No journal, and the run is a workflow: its run SSE was followed into `onWorkflowEvent`. */
461
+ | {
462
+ kind: "followed_workflow";
463
+ rejoin: MatrxLiveRunRejoin;
464
+ runId: string;
465
+ ended: boolean;
466
+ }
467
+ /** A bare `409 resume_conflict` (no live run named) — retry with the host's backoff policy. */
468
+ | {
469
+ kind: "resume_conflict";
470
+ error: MatrxApiError;
471
+ };
472
+ interface ResumeOrRejoinOptions extends Omit<MatrxStreamCallOptions, "signal"> {
473
+ /** Every NDJSON envelope — from the resume stream OR the rejoined stream. */
474
+ onEnvelope: (envelope: MatrxStreamEnvelope) => void;
475
+ /** THE RUN'S organization (from its durable record) — bound on every call. */
476
+ organizationId?: string | null;
477
+ signal?: AbortSignal;
478
+ /** Fired the moment a live run is detected, before the rejoin opens (reset replay-sensitive state). */
479
+ onRejoin?: (rejoin: MatrxLiveRunRejoin) => void;
480
+ /** Durable lifecycle events while following (the no-journal fallback). */
481
+ onOperationEvent?: (event: MatrxRuntimeOperationEvent) => void;
482
+ /** Workflow run SSE events (the no-journal fallback for a workflow `run_id`). */
483
+ onWorkflowEvent?: (event: Record<string, unknown>, seq: number | null) => void;
484
+ /** Tuning for the durable follow (stall / reconnect policy). */
485
+ follow?: Omit<FollowRuntimeOperationToEndOptions, "onEvent" | "signal" | "lastEventSeq">;
486
+ }
487
+ /**
488
+ * Resume a run — or, when the server says it is still live, REJOIN it.
489
+ *
490
+ * Calls `resumeCall` (the feature's resume door) and pipes its stream into
491
+ * `onEnvelope`. On a live-run refusal (`run_in_progress`, or chat's
492
+ * `resume_conflict` naming a live run) it follows the body's `rejoin_path`
493
+ * into the SAME handler under the same organization; when the rejoin has no
494
+ * journal (`live_stream_unavailable`) it follows the workflow run SSE (body
495
+ * names a workflow `run_id`) or the durable lifecycle. Never runs a live run a
496
+ * second time. A bare `resume_conflict` comes back as an outcome; any other
497
+ * error is thrown.
498
+ */
499
+ declare function resumeOrRejoin(transport: MatrxTransport, resumeCall: (transport: MatrxTransport, options: MatrxStreamCallOptions) => Promise<MatrxRunHandle>, options: ResumeOrRejoinOptions): Promise<ResumeOrRejoinOutcome>;
500
+
501
+ /**
502
+ * Browser-held provider sessions report their failures through the server.
503
+ *
504
+ * Realtime voice (OpenAI / xAI) and Cartesia TTS run browser → provider
505
+ * directly on an ephemeral token from the token broker, so a provider refusal
506
+ * (e.g. the platform's account is out of credit) never touches the server —
507
+ * the operator would never hear of it, and the person would see raw provider
508
+ * text. Every client calls `reportProviderSessionFailure` from the session's
509
+ * error handler and shows the returned `user_message`.
510
+ *
511
+ * Server truth: `POST /broker/provider-failures`
512
+ * (`aidream/api/routers/token_broker.py`; body `ProviderSessionFailureReport`
513
+ * in `aidream/services/token_broker/models.py` — `extra="forbid"`, allow-listed
514
+ * providers, bounded text; identity and organization come from the session).
515
+ */
516
+
517
+ /** The providers whose sessions a browser holds directly (server allow-list). */
518
+ type MatrxClientSessionProvider = "openai" | "xai" | "cartesia";
519
+ interface ProviderSessionFailure {
520
+ provider: MatrxClientSessionProvider;
521
+ model?: string | null;
522
+ /** HTTP status the provider answered, when the failure was an HTTP answer. */
523
+ status_code?: number | null;
524
+ /** The provider's own error type/code (`insufficient_quota`, …). */
525
+ error_type?: string | null;
526
+ /** The provider's text, verbatim — classified server-side, never shown. */
527
+ message: string;
528
+ }
529
+ /** `ProviderSessionFailureVerdict` — what to show, and whether reconnecting can help. */
530
+ interface ProviderSessionFailureVerdict {
531
+ error_type: string;
532
+ retryable: boolean;
533
+ /** The sentence to show the person (never the provider's raw text). */
534
+ user_message: string;
535
+ }
536
+ /** The body the server accepts — bounded exactly as its model bounds it. */
537
+ declare function providerSessionFailureBody(failure: ProviderSessionFailure): Record<string, string | number>;
538
+ /**
539
+ * Report a browser-held provider session failure and get the sentence to
540
+ * show. Resolves null (and warns) when the report itself could not be made —
541
+ * the caller then shows its own fallback; it never throws from an error
542
+ * handler.
543
+ */
544
+ declare function reportProviderSessionFailure(transport: MatrxTransport, failure: ProviderSessionFailure, options?: {
545
+ signal?: AbortSignal;
546
+ }): Promise<ProviderSessionFailureVerdict | null>;
547
+
310
548
  /**
311
549
  * Delegated client tools — submit results and discover pending calls.
312
550
  *
@@ -399,4 +637,4 @@ declare function listUserPendingToolCalls(transport: MatrxTransport, options?: {
399
637
  signal?: AbortSignal;
400
638
  }): Promise<MatrxPendingCallSummary[]>;
401
639
 
402
- export { type CreateMatrxTransportOptions, MATRX_AI_API_VERSION_DEFAULT, type MatrxAiApiVersion, type MatrxCallError, type MatrxClientToolResult, MatrxJsonObject, MatrxJsonValue, type MatrxPendingCallSummary, type MatrxProtocolDowngrade, type MatrxProtocolFallbackOptions, type MatrxRequestInfo, type MatrxToolResultsResponse, MatrxTransport, type MatrxTransportDiagnostics, type MatrxTransportTarget, OrganizationContextError, type OrganizationContextErrorCode, type OrganizationOperation, V2_COVERED_AI_PATH_TEMPLATES, applyAiApiVersion, applyOrganizationContextHeader, assertOrganizationMatchesOperation, assertQueryOrganizationMatchesContext, createMatrxTransport, createOrganizationOperation, fetchWithMatrxProtocolFallback, isCoveredAiPath, isV2Path, listConversationPendingToolCalls, listUserPendingToolCalls, normalizeMatrxError, requireOrganizationContext, submitAgentToolResults, toV1FallbackUrl, toV2Path };
640
+ export { type CreateMatrxTransportOptions, FollowRuntimeOperationToEndOptions, MATRX_AI_API_VERSION_DEFAULT, MATRX_LIVE_STREAM_UNAVAILABLE, MATRX_RESUME_CONFLICT, MATRX_RUN_IN_PROGRESS, type MatrxAiApiVersion, MatrxApiError, type MatrxCallError, type MatrxClientSessionProvider, type MatrxClientToolResult, type MatrxHttpErrorLike, MatrxJsonObject, MatrxJsonValue, type MatrxLiveRunRejoin, type MatrxPendingCallSummary, type MatrxProtocolDowngrade, type MatrxProtocolFallbackOptions, type MatrxRequestInfo, MatrxRunHandle, MatrxRuntimeExecutionStatus, MatrxRuntimeOperationEvent, MatrxStreamCallOptions, type MatrxToolResultsResponse, MatrxTransport, type MatrxTransportDiagnostics, type MatrxTransportTarget, OrganizationContextError, type OrganizationContextErrorCode, type OrganizationOperation, type ProviderSessionFailure, type ProviderSessionFailureVerdict, type ResumeOrRejoinOptions, type ResumeOrRejoinOutcome, V2_COVERED_AI_PATH_TEMPLATES, applyAiApiVersion, applyOrganizationContextHeader, assertOrganizationMatchesOperation, assertQueryOrganizationMatchesContext, createMatrxTransport, createOrganizationOperation, fetchWithMatrxProtocolFallback, followWorkflowRunEvents, isCoveredAiPath, isLiveStreamUnavailable, isResumeConflict, isV2Path, listConversationPendingToolCalls, listUserPendingToolCalls, normalizeMatrxError, openMatrxStream, providerSessionFailureBody, readLiveRunRejoin, readLiveRunRequestId, readMatrxErrorCode, reportProviderSessionFailure, requireOrganizationContext, resumeOrRejoin, runtimeOperationRejoinPath, streamErrorText, submitAgentToolResults, toV1FallbackUrl, toV2Path, withRunOrganization };
@@ -1,8 +1,8 @@
1
- import { B as MatrxTransport, m as MatrxJsonValue, l as MatrxJsonObject } from '../operations-Dp4ut-ac.js';
2
- export { F as FollowRuntimeOperationOptions, a as FollowRuntimeOperationToEndOptions, b as FollowRuntimeOperationToEndResult, M as MatrxAgentStartRequest, c as MatrxApiError, d as MatrxCancelResponse, e as MatrxChatMessage, f as MatrxCompletedRun, g as MatrxContextAnchor, h as MatrxConversationContinueRequest, i as MatrxConversationResumeRequest, j as MatrxConversationStart, k as MatrxEphemeralConversation, n as MatrxMandateStartRequest, o as MatrxOperationEventsPage, p as MatrxOperationFollowEvent, q as MatrxOperationStatusResponse, r as MatrxOperationsByLinkResponse, s as MatrxRequestScope, t as MatrxRunError, u as MatrxRunHandle, v as MatrxRuntimeExecutionStatus, w as MatrxRuntimeOperationEvent, x as MatrxRuntimeOperationView, y as MatrxStoredConversationContinue, z as MatrxStoredConversationCreate, A as MatrxStreamCallOptions, C as MatrxTransportRequest, D as MatrxTurnFields, R as RunAgentToCompletionOptions, T as TERMINAL_MATRX_RUNTIME_STATUSES, E as cancelAgentRun, G as continueAgentConversation, H as continueEphemeralConversationStart, I as continueStoredConversationStart, J as extractMatrxErrorCode, K as extractMatrxErrorMessage, L as followRuntimeOperationEvents, N as followRuntimeOperationToEnd, O as getRuntimeOperationStatus, P as getRuntimeOperationsByLink, Q as listRuntimeOperationEvents, S as mintMatrxConversationId, U as newEphemeralConversationStart, V as newStoredConversationStart, W as rejoinRuntimeOperation, X as resumeAgentConversation, Y as runAgentToCompletion, Z as startAgentRun, _ as startMandateRun } from '../operations-Dp4ut-ac.js';
1
+ import { B as MatrxTransport, A as MatrxStreamCallOptions, w as MatrxRuntimeOperationEvent, a as FollowRuntimeOperationToEndOptions, v as MatrxRuntimeExecutionStatus, c as MatrxApiError, u as MatrxRunHandle, m as MatrxJsonValue, l as MatrxJsonObject } from '../operations-Dp4ut-ac.js';
2
+ export { F as FollowRuntimeOperationOptions, b as FollowRuntimeOperationToEndResult, M as MatrxAgentStartRequest, d as MatrxCancelResponse, e as MatrxChatMessage, f as MatrxCompletedRun, g as MatrxContextAnchor, h as MatrxConversationContinueRequest, i as MatrxConversationResumeRequest, j as MatrxConversationStart, k as MatrxEphemeralConversation, n as MatrxMandateStartRequest, o as MatrxOperationEventsPage, p as MatrxOperationFollowEvent, q as MatrxOperationStatusResponse, r as MatrxOperationsByLinkResponse, s as MatrxRequestScope, t as MatrxRunError, x as MatrxRuntimeOperationView, y as MatrxStoredConversationContinue, z as MatrxStoredConversationCreate, C as MatrxTransportRequest, D as MatrxTurnFields, R as RunAgentToCompletionOptions, T as TERMINAL_MATRX_RUNTIME_STATUSES, E as cancelAgentRun, G as continueAgentConversation, H as continueEphemeralConversationStart, I as continueStoredConversationStart, J as extractMatrxErrorCode, K as extractMatrxErrorMessage, L as followRuntimeOperationEvents, N as followRuntimeOperationToEnd, O as getRuntimeOperationStatus, P as getRuntimeOperationsByLink, Q as listRuntimeOperationEvents, S as mintMatrxConversationId, U as newEphemeralConversationStart, V as newStoredConversationStart, W as rejoinRuntimeOperation, X as resumeAgentConversation, Y as runAgentToCompletion, Z as startAgentRun, _ as startMandateRun } from '../operations-Dp4ut-ac.js';
3
3
  import { CredentialsPort } from '@ai-matrx/data';
4
4
  import { ResilientFetchOptions } from '@ai-matrx/data/net';
5
- import '../stream/ndjson.js';
5
+ import { MatrxStreamEnvelope } from '../stream/ndjson.js';
6
6
  import '../stream/sse.js';
7
7
 
8
8
  /**
@@ -307,6 +307,244 @@ declare function applyOrganizationContextHeader(headers: Record<string, string>,
307
307
  */
308
308
  declare function assertQueryOrganizationMatchesContext(queryParams: Record<string, string | number | boolean> | undefined, organizationId: string): void;
309
309
 
310
+ /**
311
+ * Resume-or-rejoin — the ONE client behavior for "pick a run back up".
312
+ *
313
+ * Server truth (aidream `services/runtime/FEATURE.md` § "A live run is
314
+ * REJOINED, never resumed beside itself"; `reconnect.run_in_progress_error`):
315
+ * - Every resume / retry / continue door asked to resume a run that is STILL
316
+ * LIVE answers `409` with, at the ROOT of the error body,
317
+ * `{error, code: "run_in_progress", live_request_id, rejoin_path, message,
318
+ * …extras}` (extras: `run_id` for workflow / SEO / comparison, `arm_index` /
319
+ * `arm`, `analysis_id`). The client follows `rejoin_path` — never a URL it
320
+ * builds — because a door outside the spine (SEO collections) answers
321
+ * `live_request_id: null` with its own `/seo/collections/{run_id}/rejoin`.
322
+ * - Chat/conversation resume keeps `code: "resume_conflict"` for older clients
323
+ * but ALSO carries `live_request_id` + `rejoin_path` (+
324
+ * `details.live_request_id`) when the run is live — then rejoin, never the
325
+ * retry loop. A bare `resume_conflict` (no rejoin target) stays host retry.
326
+ * - The envelope RESERVES `request_id` for the refusing call's own id — the
327
+ * live run is read from `live_request_id`, never `request_id` (reading it
328
+ * rejoined a request that did not exist: 404, 2026-10-01).
329
+ * - A rejoin answers `409 live_stream_unavailable` when there is no journal to
330
+ * replay (resumed workflow legs, comparison arms). Then: a body naming a
331
+ * workflow `run_id` → follow `GET /runs/{run_id}/events/stream` (the workflow
332
+ * SSE, which also carries the node_stream media frames); otherwise follow the
333
+ * durable lifecycle (`followRuntimeOperationToEnd`).
334
+ *
335
+ * Resume and rejoin are work on an EXISTING run, so they carry THAT run's
336
+ * organization (`organizationId`), never whatever the session has selected.
337
+ */
338
+
339
+ declare const MATRX_RUN_IN_PROGRESS = "run_in_progress";
340
+ declare const MATRX_RESUME_CONFLICT = "resume_conflict";
341
+ declare const MATRX_LIVE_STREAM_UNAVAILABLE = "live_stream_unavailable";
342
+ /**
343
+ * Any error carrying an HTTP status and the parsed server body —
344
+ * `MatrxApiError`, matrx-frontend's `ApiCallError`, or a host's own shape.
345
+ */
346
+ interface MatrxHttpErrorLike {
347
+ status?: unknown;
348
+ serverDetail?: unknown;
349
+ }
350
+ /**
351
+ * The machine code of a Matrx HTTP error: `code` (or the envelope's hoisted
352
+ * `error`) from `detail`, `details`, or the top level. Null when absent.
353
+ */
354
+ declare function readMatrxErrorCode(error: unknown): string | null;
355
+ /** Where to rejoin a live run, read from a resume door's 409. */
356
+ interface MatrxLiveRunRejoin {
357
+ /** The live request (`GET /runtime/operations/{id}`); null for doors outside the spine (SEO). */
358
+ liveRequestId: string | null;
359
+ /** Server-relative path to `POST` for the NDJSON replay-then-follow. Always from the body when present. */
360
+ rejoinPath: string;
361
+ /** `run_id` extra (workflow / SEO / comparison), when present. */
362
+ runId: string | null;
363
+ /** The refusal's code: `run_in_progress`, or chat's `resume_conflict` carrying a rejoin target. */
364
+ code: string;
365
+ /** The refusal body (root of the envelope), for door-specific extras (`arm_index`, `analysis_id`, …). */
366
+ body: Record<string, unknown>;
367
+ }
368
+ /**
369
+ * The rejoin target of a live-run refusal: `409` with `code: run_in_progress`,
370
+ * or chat's `409 resume_conflict` that names a live run. Null for every other
371
+ * error (a genuine failure is never mistaken for a live run). Reads
372
+ * `rejoin_path` from the body first; derives the runtime rejoin from
373
+ * `live_request_id` only when the body names no path. Never reads
374
+ * `request_id`.
375
+ */
376
+ declare function readLiveRunRejoin(error: unknown): MatrxLiveRunRejoin | null;
377
+ /**
378
+ * The request id of a run that is STILL LIVE, read from a resume door's
379
+ * refusal (`live_request_id` — never the envelope's own `request_id`). Null
380
+ * for every other error, and for a live refusal outside the spine (SEO) —
381
+ * follow `readLiveRunRejoin(error).rejoinPath` instead.
382
+ */
383
+ declare function readLiveRunRequestId(error: unknown): string | null;
384
+ /**
385
+ * A bare `409 resume_conflict` — another resume holds the claim and NO live
386
+ * run is named; retry is host policy. (A `resume_conflict` that names a live
387
+ * run is a rejoin — `readLiveRunRejoin`.)
388
+ */
389
+ declare function isResumeConflict(error: unknown): boolean;
390
+ /** `409 live_stream_unavailable` — the rejoin journal is gone; follow the durable lifecycle instead. */
391
+ declare function isLiveStreamUnavailable(error: unknown): boolean;
392
+ /**
393
+ * The server-relative rejoin path — for hosts whose stream pipeline takes a
394
+ * URL instead of a transport (prepend the resolved base URL).
395
+ */
396
+ declare function runtimeOperationRejoinPath(requestId: string): string;
397
+ /**
398
+ * The text to show for a stream `error` event: the server's `user_message`
399
+ * first (it is written for the person — e.g. "OpenAI refused this request:
400
+ * the platform's OpenAI account is out of credit."), then `message`. Accepts
401
+ * the `{event, data}` envelope or its `data` payload. Null when neither is
402
+ * present — the host supplies its own fallback; it must never REPLACE a
403
+ * message the server sent.
404
+ */
405
+ declare function streamErrorText(eventOrPayload: unknown): string | null;
406
+ /**
407
+ * Open any Matrx NDJSON stream by path (`POST`, optional JSON body) — for
408
+ * feature doors outside the agent lifecycle (`/podcast/resume/{run_id}`, …)
409
+ * so their streams ride the same transport and wire kernel as every run.
410
+ */
411
+ declare function openMatrxStream(transport: MatrxTransport, path: string, options?: MatrxStreamCallOptions & {
412
+ body?: unknown;
413
+ }): Promise<MatrxRunHandle>;
414
+ /**
415
+ * Bind a run's organization onto every call as `X-Organization-Id`. Host
416
+ * policy headers still merge on top; the package's own `createMatrxTransport`
417
+ * refuses a disagreeing org (`organization_context_mismatch`) rather than
418
+ * silently swapping it, so a host must not force the SESSION org onto a
419
+ * resume/rejoin transport.
420
+ */
421
+ declare function withRunOrganization(transport: MatrxTransport, organizationId: string): MatrxTransport;
422
+ /**
423
+ * Follow a workflow run's SSE (`GET /runs/{run_id}/events/stream`) — the
424
+ * rejoin fallback for workflow legs with no stream journal. Delivers every
425
+ * parsed event (durable run events with their seq; ephemeral `node_stream`
426
+ * frames — including `kind: "media"` — with seq null). One connection, no
427
+ * reconnect policy: resolves `{ended: true}` on the server's `end` frame,
428
+ * `{ended: false}` when the wire closes or the caller aborts.
429
+ */
430
+ declare function followWorkflowRunEvents(transport: MatrxTransport, runId: string, options: {
431
+ onEvent: (event: Record<string, unknown>, seq: number | null) => void;
432
+ lastEventId?: number | null;
433
+ signal?: AbortSignal;
434
+ }): Promise<{
435
+ ended: boolean;
436
+ }>;
437
+ type ResumeOrRejoinOutcome =
438
+ /** The resume door ran the run; its stream was delivered to `onEnvelope`. */
439
+ {
440
+ kind: "resumed";
441
+ requestId: string | null;
442
+ }
443
+ /** The run was live; its stream (from `rejoin_path`) was replayed + followed into `onEnvelope`. */
444
+ | {
445
+ kind: "rejoined";
446
+ rejoin: MatrxLiveRunRejoin;
447
+ }
448
+ /**
449
+ * The run was live but had no journal to replay; the durable lifecycle was
450
+ * followed instead. Re-query the feature's record for the result.
451
+ * `ended: false` = the follow gave up (or no operation was found).
452
+ */
453
+ | {
454
+ kind: "followed";
455
+ rejoin: MatrxLiveRunRejoin;
456
+ executionId: string | null;
457
+ ended: boolean;
458
+ status: MatrxRuntimeExecutionStatus | null;
459
+ }
460
+ /** No journal, and the run is a workflow: its run SSE was followed into `onWorkflowEvent`. */
461
+ | {
462
+ kind: "followed_workflow";
463
+ rejoin: MatrxLiveRunRejoin;
464
+ runId: string;
465
+ ended: boolean;
466
+ }
467
+ /** A bare `409 resume_conflict` (no live run named) — retry with the host's backoff policy. */
468
+ | {
469
+ kind: "resume_conflict";
470
+ error: MatrxApiError;
471
+ };
472
+ interface ResumeOrRejoinOptions extends Omit<MatrxStreamCallOptions, "signal"> {
473
+ /** Every NDJSON envelope — from the resume stream OR the rejoined stream. */
474
+ onEnvelope: (envelope: MatrxStreamEnvelope) => void;
475
+ /** THE RUN'S organization (from its durable record) — bound on every call. */
476
+ organizationId?: string | null;
477
+ signal?: AbortSignal;
478
+ /** Fired the moment a live run is detected, before the rejoin opens (reset replay-sensitive state). */
479
+ onRejoin?: (rejoin: MatrxLiveRunRejoin) => void;
480
+ /** Durable lifecycle events while following (the no-journal fallback). */
481
+ onOperationEvent?: (event: MatrxRuntimeOperationEvent) => void;
482
+ /** Workflow run SSE events (the no-journal fallback for a workflow `run_id`). */
483
+ onWorkflowEvent?: (event: Record<string, unknown>, seq: number | null) => void;
484
+ /** Tuning for the durable follow (stall / reconnect policy). */
485
+ follow?: Omit<FollowRuntimeOperationToEndOptions, "onEvent" | "signal" | "lastEventSeq">;
486
+ }
487
+ /**
488
+ * Resume a run — or, when the server says it is still live, REJOIN it.
489
+ *
490
+ * Calls `resumeCall` (the feature's resume door) and pipes its stream into
491
+ * `onEnvelope`. On a live-run refusal (`run_in_progress`, or chat's
492
+ * `resume_conflict` naming a live run) it follows the body's `rejoin_path`
493
+ * into the SAME handler under the same organization; when the rejoin has no
494
+ * journal (`live_stream_unavailable`) it follows the workflow run SSE (body
495
+ * names a workflow `run_id`) or the durable lifecycle. Never runs a live run a
496
+ * second time. A bare `resume_conflict` comes back as an outcome; any other
497
+ * error is thrown.
498
+ */
499
+ declare function resumeOrRejoin(transport: MatrxTransport, resumeCall: (transport: MatrxTransport, options: MatrxStreamCallOptions) => Promise<MatrxRunHandle>, options: ResumeOrRejoinOptions): Promise<ResumeOrRejoinOutcome>;
500
+
501
+ /**
502
+ * Browser-held provider sessions report their failures through the server.
503
+ *
504
+ * Realtime voice (OpenAI / xAI) and Cartesia TTS run browser → provider
505
+ * directly on an ephemeral token from the token broker, so a provider refusal
506
+ * (e.g. the platform's account is out of credit) never touches the server —
507
+ * the operator would never hear of it, and the person would see raw provider
508
+ * text. Every client calls `reportProviderSessionFailure` from the session's
509
+ * error handler and shows the returned `user_message`.
510
+ *
511
+ * Server truth: `POST /broker/provider-failures`
512
+ * (`aidream/api/routers/token_broker.py`; body `ProviderSessionFailureReport`
513
+ * in `aidream/services/token_broker/models.py` — `extra="forbid"`, allow-listed
514
+ * providers, bounded text; identity and organization come from the session).
515
+ */
516
+
517
+ /** The providers whose sessions a browser holds directly (server allow-list). */
518
+ type MatrxClientSessionProvider = "openai" | "xai" | "cartesia";
519
+ interface ProviderSessionFailure {
520
+ provider: MatrxClientSessionProvider;
521
+ model?: string | null;
522
+ /** HTTP status the provider answered, when the failure was an HTTP answer. */
523
+ status_code?: number | null;
524
+ /** The provider's own error type/code (`insufficient_quota`, …). */
525
+ error_type?: string | null;
526
+ /** The provider's text, verbatim — classified server-side, never shown. */
527
+ message: string;
528
+ }
529
+ /** `ProviderSessionFailureVerdict` — what to show, and whether reconnecting can help. */
530
+ interface ProviderSessionFailureVerdict {
531
+ error_type: string;
532
+ retryable: boolean;
533
+ /** The sentence to show the person (never the provider's raw text). */
534
+ user_message: string;
535
+ }
536
+ /** The body the server accepts — bounded exactly as its model bounds it. */
537
+ declare function providerSessionFailureBody(failure: ProviderSessionFailure): Record<string, string | number>;
538
+ /**
539
+ * Report a browser-held provider session failure and get the sentence to
540
+ * show. Resolves null (and warns) when the report itself could not be made —
541
+ * the caller then shows its own fallback; it never throws from an error
542
+ * handler.
543
+ */
544
+ declare function reportProviderSessionFailure(transport: MatrxTransport, failure: ProviderSessionFailure, options?: {
545
+ signal?: AbortSignal;
546
+ }): Promise<ProviderSessionFailureVerdict | null>;
547
+
310
548
  /**
311
549
  * Delegated client tools — submit results and discover pending calls.
312
550
  *
@@ -399,4 +637,4 @@ declare function listUserPendingToolCalls(transport: MatrxTransport, options?: {
399
637
  signal?: AbortSignal;
400
638
  }): Promise<MatrxPendingCallSummary[]>;
401
639
 
402
- export { type CreateMatrxTransportOptions, MATRX_AI_API_VERSION_DEFAULT, type MatrxAiApiVersion, type MatrxCallError, type MatrxClientToolResult, MatrxJsonObject, MatrxJsonValue, type MatrxPendingCallSummary, type MatrxProtocolDowngrade, type MatrxProtocolFallbackOptions, type MatrxRequestInfo, type MatrxToolResultsResponse, MatrxTransport, type MatrxTransportDiagnostics, type MatrxTransportTarget, OrganizationContextError, type OrganizationContextErrorCode, type OrganizationOperation, V2_COVERED_AI_PATH_TEMPLATES, applyAiApiVersion, applyOrganizationContextHeader, assertOrganizationMatchesOperation, assertQueryOrganizationMatchesContext, createMatrxTransport, createOrganizationOperation, fetchWithMatrxProtocolFallback, isCoveredAiPath, isV2Path, listConversationPendingToolCalls, listUserPendingToolCalls, normalizeMatrxError, requireOrganizationContext, submitAgentToolResults, toV1FallbackUrl, toV2Path };
640
+ export { type CreateMatrxTransportOptions, FollowRuntimeOperationToEndOptions, MATRX_AI_API_VERSION_DEFAULT, MATRX_LIVE_STREAM_UNAVAILABLE, MATRX_RESUME_CONFLICT, MATRX_RUN_IN_PROGRESS, type MatrxAiApiVersion, MatrxApiError, type MatrxCallError, type MatrxClientSessionProvider, type MatrxClientToolResult, type MatrxHttpErrorLike, MatrxJsonObject, MatrxJsonValue, type MatrxLiveRunRejoin, type MatrxPendingCallSummary, type MatrxProtocolDowngrade, type MatrxProtocolFallbackOptions, type MatrxRequestInfo, MatrxRunHandle, MatrxRuntimeExecutionStatus, MatrxRuntimeOperationEvent, MatrxStreamCallOptions, type MatrxToolResultsResponse, MatrxTransport, type MatrxTransportDiagnostics, type MatrxTransportTarget, OrganizationContextError, type OrganizationContextErrorCode, type OrganizationOperation, type ProviderSessionFailure, type ProviderSessionFailureVerdict, type ResumeOrRejoinOptions, type ResumeOrRejoinOutcome, V2_COVERED_AI_PATH_TEMPLATES, applyAiApiVersion, applyOrganizationContextHeader, assertOrganizationMatchesOperation, assertQueryOrganizationMatchesContext, createMatrxTransport, createOrganizationOperation, fetchWithMatrxProtocolFallback, followWorkflowRunEvents, isCoveredAiPath, isLiveStreamUnavailable, isResumeConflict, isV2Path, listConversationPendingToolCalls, listUserPendingToolCalls, normalizeMatrxError, openMatrxStream, providerSessionFailureBody, readLiveRunRejoin, readLiveRunRequestId, readMatrxErrorCode, reportProviderSessionFailure, requireOrganizationContext, resumeOrRejoin, runtimeOperationRejoinPath, streamErrorText, submitAgentToolResults, toV1FallbackUrl, toV2Path, withRunOrganization };