@ai-matrx/agents 0.21.45 → 0.23.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 (57) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/catalog/index.cjs +7 -0
  3. package/dist/catalog/index.cjs.map +1 -1
  4. package/dist/catalog/index.d.cts +2 -2
  5. package/dist/catalog/index.d.ts +2 -2
  6. package/dist/catalog/index.js +7 -0
  7. package/dist/catalog/index.js.map +1 -1
  8. package/dist/catalog/native/index.cjs +1 -1
  9. package/dist/catalog/native/index.cjs.map +1 -1
  10. package/dist/catalog/native/index.d.cts +2 -2
  11. package/dist/catalog/native/index.d.ts +2 -2
  12. package/dist/catalog/native/index.js +1 -1
  13. package/dist/catalog/native/index.js.map +1 -1
  14. package/dist/catalog/react/index.cjs +1 -1
  15. package/dist/catalog/react/index.cjs.map +1 -1
  16. package/dist/catalog/react/index.d.cts +2 -0
  17. package/dist/catalog/react/index.d.ts +2 -0
  18. package/dist/catalog/react/index.js +1 -1
  19. package/dist/catalog/react/index.js.map +1 -1
  20. package/dist/content-transfer/index.cjs +33 -33
  21. package/dist/content-transfer/index.cjs.map +1 -1
  22. package/dist/content-transfer/index.d.cts +1 -1
  23. package/dist/content-transfer/index.d.ts +1 -1
  24. package/dist/content-transfer/index.js +33 -33
  25. package/dist/content-transfer/index.js.map +1 -1
  26. package/dist/content-transfer/react/index.cjs +33 -33
  27. package/dist/content-transfer/react/index.cjs.map +1 -1
  28. package/dist/content-transfer/react/index.js +33 -33
  29. package/dist/content-transfer/react/index.js.map +1 -1
  30. package/dist/index.cjs +326 -131
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +1 -1
  33. package/dist/index.d.ts +1 -1
  34. package/dist/index.js +326 -131
  35. package/dist/index.js.map +1 -1
  36. package/dist/mandates/index.cjs +2 -2
  37. package/dist/mandates/index.cjs.map +1 -1
  38. package/dist/mandates/index.d.cts +4 -4
  39. package/dist/mandates/index.d.ts +4 -4
  40. package/dist/mandates/index.js +2 -2
  41. package/dist/mandates/index.js.map +1 -1
  42. package/dist/matrx/index.cjs +326 -131
  43. package/dist/matrx/index.cjs.map +1 -1
  44. package/dist/matrx/index.d.cts +185 -4
  45. package/dist/matrx/index.d.ts +185 -4
  46. package/dist/matrx/index.js +326 -131
  47. package/dist/matrx/index.js.map +1 -1
  48. package/dist/{orchestra-PbGGooqJ.d.cts → orchestra-zpGHwOag.d.cts} +9 -0
  49. package/dist/{orchestra-PbGGooqJ.d.ts → orchestra-zpGHwOag.d.ts} +9 -0
  50. package/dist/react/index.cjs +41 -41
  51. package/dist/react/index.cjs.map +1 -1
  52. package/dist/react/index.js +41 -41
  53. package/dist/react/index.js.map +1 -1
  54. package/mandates/snapshots/keys.0.21.46.json +652 -0
  55. package/mandates/snapshots/keys.0.22.0.json +652 -0
  56. package/mandates/snapshots/keys.0.23.0.json +652 -0
  57. package/package.json +3 -3
@@ -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,187 @@ 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 (verified against aidream source):
314
+ * - A resume door asked to resume a run that is STILL RUNNING answers
315
+ * `409` with `code: "run_in_progress"` and `live_request_id`
316
+ * (`aidream/api/routers/podcast_generator.py` `resume_podcast_endpoint`;
317
+ * other doors adopt the same contract). The platform error envelope
318
+ * (`aidream/api/errors.py`) hoists the detail's non-reserved keys to the top
319
+ * level and RESERVES `request_id` for the API call's own id — so the live
320
+ * run's id is read from `live_request_id`, never `request_id` (reading
321
+ * `request_id` rejoined a request that did not exist: 404, 2026-10-01).
322
+ * - The client then follows `POST /runtime/operations/{live_request_id}/rejoin`
323
+ * (NDJSON replay-then-follow). That answers `409 live_stream_unavailable`
324
+ * when the live journal is gone — the durable lifecycle stream
325
+ * (`followRuntimeOperationToEnd`) is the fallback.
326
+ * - Conversations answer `409 resume_conflict` (retryable: the suspending run
327
+ * has not persisted yet, or a duplicate lost the claim). Retrying is host
328
+ * policy — this module reports it as an outcome, never retries itself.
329
+ *
330
+ * Resume and rejoin are work on an EXISTING run, so they carry THAT run's
331
+ * organization (`organizationId`), never whatever the session has selected.
332
+ */
333
+
334
+ declare const MATRX_RUN_IN_PROGRESS = "run_in_progress";
335
+ declare const MATRX_RESUME_CONFLICT = "resume_conflict";
336
+ declare const MATRX_LIVE_STREAM_UNAVAILABLE = "live_stream_unavailable";
337
+ /**
338
+ * Any error carrying an HTTP status and the parsed server body —
339
+ * `MatrxApiError`, matrx-frontend's `ApiCallError`, or a host's own shape.
340
+ */
341
+ interface MatrxHttpErrorLike {
342
+ status?: unknown;
343
+ serverDetail?: unknown;
344
+ }
345
+ /**
346
+ * The machine code of a Matrx HTTP error: `code` (or the envelope's hoisted
347
+ * `error`) from `detail`, `details`, or the top level. Null when absent.
348
+ */
349
+ declare function readMatrxErrorCode(error: unknown): string | null;
350
+ /**
351
+ * The request id of a run that is STILL RUNNING, read from a resume door's
352
+ * `409 run_in_progress` refusal. Null for every other error, so a genuine
353
+ * failure is never mistaken for a live run. Reads `live_request_id` only —
354
+ * the envelope's `request_id` is the refusing API call's own id.
355
+ */
356
+ declare function readLiveRunRequestId(error: unknown): string | null;
357
+ /** `409 resume_conflict` — another resume holds the run claim; retry is host policy. */
358
+ declare function isResumeConflict(error: unknown): boolean;
359
+ /** `409 live_stream_unavailable` — the rejoin journal is gone; follow the durable lifecycle instead. */
360
+ declare function isLiveStreamUnavailable(error: unknown): boolean;
361
+ /**
362
+ * The server-relative rejoin path — for hosts whose stream pipeline takes a
363
+ * URL instead of a transport (prepend the resolved base URL).
364
+ */
365
+ declare function runtimeOperationRejoinPath(requestId: string): string;
366
+ /**
367
+ * The text to show for a stream `error` event: the server's `user_message`
368
+ * first (it is written for the person — e.g. "OpenAI refused this request:
369
+ * the platform's OpenAI account is out of credit."), then `message`. Accepts
370
+ * the `{event, data}` envelope or its `data` payload. Null when neither is
371
+ * present — the host supplies its own fallback; it must never REPLACE a
372
+ * message the server sent.
373
+ */
374
+ declare function streamErrorText(eventOrPayload: unknown): string | null;
375
+ /**
376
+ * Open any Matrx NDJSON stream by path (`POST`, optional JSON body) — for
377
+ * feature doors outside the agent lifecycle (`/podcast/resume/{run_id}`, …)
378
+ * so their streams ride the same transport and wire kernel as every run.
379
+ */
380
+ declare function openMatrxStream(transport: MatrxTransport, path: string, options?: MatrxStreamCallOptions & {
381
+ body?: unknown;
382
+ }): Promise<MatrxRunHandle>;
383
+ /**
384
+ * Bind a run's organization onto every call as `X-Organization-Id`. Host
385
+ * policy headers still merge on top; the package's own `createMatrxTransport`
386
+ * refuses a disagreeing org (`organization_context_mismatch`) rather than
387
+ * silently swapping it, so a host must not force the SESSION org onto a
388
+ * resume/rejoin transport.
389
+ */
390
+ declare function withRunOrganization(transport: MatrxTransport, organizationId: string): MatrxTransport;
391
+ type ResumeOrRejoinOutcome =
392
+ /** The resume door ran the run; its stream was delivered to `onEnvelope`. */
393
+ {
394
+ kind: "resumed";
395
+ requestId: string | null;
396
+ }
397
+ /** The run was still live; its original stream was replayed + followed into `onEnvelope`. */
398
+ | {
399
+ kind: "rejoined";
400
+ liveRequestId: string;
401
+ }
402
+ /**
403
+ * The run was still live but its stream could not be replayed; the durable
404
+ * lifecycle was followed instead. Re-query the feature's record for the
405
+ * result. `ended: false` = the follow gave up (or no operation was found).
406
+ */
407
+ | {
408
+ kind: "followed";
409
+ liveRequestId: string;
410
+ executionId: string | null;
411
+ ended: boolean;
412
+ status: MatrxRuntimeExecutionStatus | null;
413
+ }
414
+ /** `409 resume_conflict` — retry with the host's backoff policy. */
415
+ | {
416
+ kind: "resume_conflict";
417
+ error: MatrxApiError;
418
+ };
419
+ interface ResumeOrRejoinOptions extends Omit<MatrxStreamCallOptions, "signal"> {
420
+ /** Every NDJSON envelope — from the resume stream OR the rejoined stream. */
421
+ onEnvelope: (envelope: MatrxStreamEnvelope) => void;
422
+ /** THE RUN'S organization (from its durable record) — bound on every call. */
423
+ organizationId?: string | null;
424
+ signal?: AbortSignal;
425
+ /** Fired the moment a live run is detected, before the rejoin opens. */
426
+ onRejoin?: (liveRequestId: string) => void;
427
+ /** Durable lifecycle events while following (the no-replay fallback). */
428
+ onOperationEvent?: (event: MatrxRuntimeOperationEvent) => void;
429
+ /** Tuning for the fallback follow (stall / reconnect policy). */
430
+ follow?: Omit<FollowRuntimeOperationToEndOptions, "onEvent" | "signal" | "lastEventSeq">;
431
+ }
432
+ /**
433
+ * Resume a run — or, when the server says it is still running, REJOIN it.
434
+ *
435
+ * Calls `resumeCall` (the feature's resume door) and pipes its stream into
436
+ * `onEnvelope`. On `409 run_in_progress` it follows
437
+ * `POST /runtime/operations/{live_request_id}/rejoin` into the SAME handler
438
+ * under the same organization; when replay is unavailable it follows the
439
+ * durable lifecycle to its end. Never runs a live run a second time.
440
+ * `resume_conflict` comes back as an outcome; any other error is thrown.
441
+ */
442
+ declare function resumeOrRejoin(transport: MatrxTransport, resumeCall: (transport: MatrxTransport, options: MatrxStreamCallOptions) => Promise<MatrxRunHandle>, options: ResumeOrRejoinOptions): Promise<ResumeOrRejoinOutcome>;
443
+
444
+ /**
445
+ * Browser-held provider sessions report their failures through the server.
446
+ *
447
+ * Realtime voice (OpenAI / xAI) and Cartesia TTS run browser → provider
448
+ * directly on an ephemeral token from the token broker, so a provider refusal
449
+ * (e.g. the platform's account is out of credit) never touches the server —
450
+ * the operator would never hear of it, and the person would see raw provider
451
+ * text. Every client calls `reportProviderSessionFailure` from the session's
452
+ * error handler and shows the returned `user_message`.
453
+ *
454
+ * Server truth: `POST /broker/provider-failures`
455
+ * (`aidream/api/routers/token_broker.py`; body `ProviderSessionFailureReport`
456
+ * in `aidream/services/token_broker/models.py` — `extra="forbid"`, allow-listed
457
+ * providers, bounded text; identity and organization come from the session).
458
+ */
459
+
460
+ /** The providers whose sessions a browser holds directly (server allow-list). */
461
+ type MatrxClientSessionProvider = "openai" | "xai" | "cartesia";
462
+ interface ProviderSessionFailure {
463
+ provider: MatrxClientSessionProvider;
464
+ model?: string | null;
465
+ /** HTTP status the provider answered, when the failure was an HTTP answer. */
466
+ status_code?: number | null;
467
+ /** The provider's own error type/code (`insufficient_quota`, …). */
468
+ error_type?: string | null;
469
+ /** The provider's text, verbatim — classified server-side, never shown. */
470
+ message: string;
471
+ }
472
+ /** `ProviderSessionFailureVerdict` — what to show, and whether reconnecting can help. */
473
+ interface ProviderSessionFailureVerdict {
474
+ error_type: string;
475
+ retryable: boolean;
476
+ /** The sentence to show the person (never the provider's raw text). */
477
+ user_message: string;
478
+ }
479
+ /** The body the server accepts — bounded exactly as its model bounds it. */
480
+ declare function providerSessionFailureBody(failure: ProviderSessionFailure): Record<string, string | number>;
481
+ /**
482
+ * Report a browser-held provider session failure and get the sentence to
483
+ * show. Resolves null (and warns) when the report itself could not be made —
484
+ * the caller then shows its own fallback; it never throws from an error
485
+ * handler.
486
+ */
487
+ declare function reportProviderSessionFailure(transport: MatrxTransport, failure: ProviderSessionFailure, options?: {
488
+ signal?: AbortSignal;
489
+ }): Promise<ProviderSessionFailureVerdict | null>;
490
+
310
491
  /**
311
492
  * Delegated client tools — submit results and discover pending calls.
312
493
  *
@@ -399,4 +580,4 @@ declare function listUserPendingToolCalls(transport: MatrxTransport, options?: {
399
580
  signal?: AbortSignal;
400
581
  }): Promise<MatrxPendingCallSummary[]>;
401
582
 
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 };
583
+ 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 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, isCoveredAiPath, isLiveStreamUnavailable, isResumeConflict, isV2Path, listConversationPendingToolCalls, listUserPendingToolCalls, normalizeMatrxError, openMatrxStream, providerSessionFailureBody, 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,187 @@ 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 (verified against aidream source):
314
+ * - A resume door asked to resume a run that is STILL RUNNING answers
315
+ * `409` with `code: "run_in_progress"` and `live_request_id`
316
+ * (`aidream/api/routers/podcast_generator.py` `resume_podcast_endpoint`;
317
+ * other doors adopt the same contract). The platform error envelope
318
+ * (`aidream/api/errors.py`) hoists the detail's non-reserved keys to the top
319
+ * level and RESERVES `request_id` for the API call's own id — so the live
320
+ * run's id is read from `live_request_id`, never `request_id` (reading
321
+ * `request_id` rejoined a request that did not exist: 404, 2026-10-01).
322
+ * - The client then follows `POST /runtime/operations/{live_request_id}/rejoin`
323
+ * (NDJSON replay-then-follow). That answers `409 live_stream_unavailable`
324
+ * when the live journal is gone — the durable lifecycle stream
325
+ * (`followRuntimeOperationToEnd`) is the fallback.
326
+ * - Conversations answer `409 resume_conflict` (retryable: the suspending run
327
+ * has not persisted yet, or a duplicate lost the claim). Retrying is host
328
+ * policy — this module reports it as an outcome, never retries itself.
329
+ *
330
+ * Resume and rejoin are work on an EXISTING run, so they carry THAT run's
331
+ * organization (`organizationId`), never whatever the session has selected.
332
+ */
333
+
334
+ declare const MATRX_RUN_IN_PROGRESS = "run_in_progress";
335
+ declare const MATRX_RESUME_CONFLICT = "resume_conflict";
336
+ declare const MATRX_LIVE_STREAM_UNAVAILABLE = "live_stream_unavailable";
337
+ /**
338
+ * Any error carrying an HTTP status and the parsed server body —
339
+ * `MatrxApiError`, matrx-frontend's `ApiCallError`, or a host's own shape.
340
+ */
341
+ interface MatrxHttpErrorLike {
342
+ status?: unknown;
343
+ serverDetail?: unknown;
344
+ }
345
+ /**
346
+ * The machine code of a Matrx HTTP error: `code` (or the envelope's hoisted
347
+ * `error`) from `detail`, `details`, or the top level. Null when absent.
348
+ */
349
+ declare function readMatrxErrorCode(error: unknown): string | null;
350
+ /**
351
+ * The request id of a run that is STILL RUNNING, read from a resume door's
352
+ * `409 run_in_progress` refusal. Null for every other error, so a genuine
353
+ * failure is never mistaken for a live run. Reads `live_request_id` only —
354
+ * the envelope's `request_id` is the refusing API call's own id.
355
+ */
356
+ declare function readLiveRunRequestId(error: unknown): string | null;
357
+ /** `409 resume_conflict` — another resume holds the run claim; retry is host policy. */
358
+ declare function isResumeConflict(error: unknown): boolean;
359
+ /** `409 live_stream_unavailable` — the rejoin journal is gone; follow the durable lifecycle instead. */
360
+ declare function isLiveStreamUnavailable(error: unknown): boolean;
361
+ /**
362
+ * The server-relative rejoin path — for hosts whose stream pipeline takes a
363
+ * URL instead of a transport (prepend the resolved base URL).
364
+ */
365
+ declare function runtimeOperationRejoinPath(requestId: string): string;
366
+ /**
367
+ * The text to show for a stream `error` event: the server's `user_message`
368
+ * first (it is written for the person — e.g. "OpenAI refused this request:
369
+ * the platform's OpenAI account is out of credit."), then `message`. Accepts
370
+ * the `{event, data}` envelope or its `data` payload. Null when neither is
371
+ * present — the host supplies its own fallback; it must never REPLACE a
372
+ * message the server sent.
373
+ */
374
+ declare function streamErrorText(eventOrPayload: unknown): string | null;
375
+ /**
376
+ * Open any Matrx NDJSON stream by path (`POST`, optional JSON body) — for
377
+ * feature doors outside the agent lifecycle (`/podcast/resume/{run_id}`, …)
378
+ * so their streams ride the same transport and wire kernel as every run.
379
+ */
380
+ declare function openMatrxStream(transport: MatrxTransport, path: string, options?: MatrxStreamCallOptions & {
381
+ body?: unknown;
382
+ }): Promise<MatrxRunHandle>;
383
+ /**
384
+ * Bind a run's organization onto every call as `X-Organization-Id`. Host
385
+ * policy headers still merge on top; the package's own `createMatrxTransport`
386
+ * refuses a disagreeing org (`organization_context_mismatch`) rather than
387
+ * silently swapping it, so a host must not force the SESSION org onto a
388
+ * resume/rejoin transport.
389
+ */
390
+ declare function withRunOrganization(transport: MatrxTransport, organizationId: string): MatrxTransport;
391
+ type ResumeOrRejoinOutcome =
392
+ /** The resume door ran the run; its stream was delivered to `onEnvelope`. */
393
+ {
394
+ kind: "resumed";
395
+ requestId: string | null;
396
+ }
397
+ /** The run was still live; its original stream was replayed + followed into `onEnvelope`. */
398
+ | {
399
+ kind: "rejoined";
400
+ liveRequestId: string;
401
+ }
402
+ /**
403
+ * The run was still live but its stream could not be replayed; the durable
404
+ * lifecycle was followed instead. Re-query the feature's record for the
405
+ * result. `ended: false` = the follow gave up (or no operation was found).
406
+ */
407
+ | {
408
+ kind: "followed";
409
+ liveRequestId: string;
410
+ executionId: string | null;
411
+ ended: boolean;
412
+ status: MatrxRuntimeExecutionStatus | null;
413
+ }
414
+ /** `409 resume_conflict` — retry with the host's backoff policy. */
415
+ | {
416
+ kind: "resume_conflict";
417
+ error: MatrxApiError;
418
+ };
419
+ interface ResumeOrRejoinOptions extends Omit<MatrxStreamCallOptions, "signal"> {
420
+ /** Every NDJSON envelope — from the resume stream OR the rejoined stream. */
421
+ onEnvelope: (envelope: MatrxStreamEnvelope) => void;
422
+ /** THE RUN'S organization (from its durable record) — bound on every call. */
423
+ organizationId?: string | null;
424
+ signal?: AbortSignal;
425
+ /** Fired the moment a live run is detected, before the rejoin opens. */
426
+ onRejoin?: (liveRequestId: string) => void;
427
+ /** Durable lifecycle events while following (the no-replay fallback). */
428
+ onOperationEvent?: (event: MatrxRuntimeOperationEvent) => void;
429
+ /** Tuning for the fallback follow (stall / reconnect policy). */
430
+ follow?: Omit<FollowRuntimeOperationToEndOptions, "onEvent" | "signal" | "lastEventSeq">;
431
+ }
432
+ /**
433
+ * Resume a run — or, when the server says it is still running, REJOIN it.
434
+ *
435
+ * Calls `resumeCall` (the feature's resume door) and pipes its stream into
436
+ * `onEnvelope`. On `409 run_in_progress` it follows
437
+ * `POST /runtime/operations/{live_request_id}/rejoin` into the SAME handler
438
+ * under the same organization; when replay is unavailable it follows the
439
+ * durable lifecycle to its end. Never runs a live run a second time.
440
+ * `resume_conflict` comes back as an outcome; any other error is thrown.
441
+ */
442
+ declare function resumeOrRejoin(transport: MatrxTransport, resumeCall: (transport: MatrxTransport, options: MatrxStreamCallOptions) => Promise<MatrxRunHandle>, options: ResumeOrRejoinOptions): Promise<ResumeOrRejoinOutcome>;
443
+
444
+ /**
445
+ * Browser-held provider sessions report their failures through the server.
446
+ *
447
+ * Realtime voice (OpenAI / xAI) and Cartesia TTS run browser → provider
448
+ * directly on an ephemeral token from the token broker, so a provider refusal
449
+ * (e.g. the platform's account is out of credit) never touches the server —
450
+ * the operator would never hear of it, and the person would see raw provider
451
+ * text. Every client calls `reportProviderSessionFailure` from the session's
452
+ * error handler and shows the returned `user_message`.
453
+ *
454
+ * Server truth: `POST /broker/provider-failures`
455
+ * (`aidream/api/routers/token_broker.py`; body `ProviderSessionFailureReport`
456
+ * in `aidream/services/token_broker/models.py` — `extra="forbid"`, allow-listed
457
+ * providers, bounded text; identity and organization come from the session).
458
+ */
459
+
460
+ /** The providers whose sessions a browser holds directly (server allow-list). */
461
+ type MatrxClientSessionProvider = "openai" | "xai" | "cartesia";
462
+ interface ProviderSessionFailure {
463
+ provider: MatrxClientSessionProvider;
464
+ model?: string | null;
465
+ /** HTTP status the provider answered, when the failure was an HTTP answer. */
466
+ status_code?: number | null;
467
+ /** The provider's own error type/code (`insufficient_quota`, …). */
468
+ error_type?: string | null;
469
+ /** The provider's text, verbatim — classified server-side, never shown. */
470
+ message: string;
471
+ }
472
+ /** `ProviderSessionFailureVerdict` — what to show, and whether reconnecting can help. */
473
+ interface ProviderSessionFailureVerdict {
474
+ error_type: string;
475
+ retryable: boolean;
476
+ /** The sentence to show the person (never the provider's raw text). */
477
+ user_message: string;
478
+ }
479
+ /** The body the server accepts — bounded exactly as its model bounds it. */
480
+ declare function providerSessionFailureBody(failure: ProviderSessionFailure): Record<string, string | number>;
481
+ /**
482
+ * Report a browser-held provider session failure and get the sentence to
483
+ * show. Resolves null (and warns) when the report itself could not be made —
484
+ * the caller then shows its own fallback; it never throws from an error
485
+ * handler.
486
+ */
487
+ declare function reportProviderSessionFailure(transport: MatrxTransport, failure: ProviderSessionFailure, options?: {
488
+ signal?: AbortSignal;
489
+ }): Promise<ProviderSessionFailureVerdict | null>;
490
+
310
491
  /**
311
492
  * Delegated client tools — submit results and discover pending calls.
312
493
  *
@@ -399,4 +580,4 @@ declare function listUserPendingToolCalls(transport: MatrxTransport, options?: {
399
580
  signal?: AbortSignal;
400
581
  }): Promise<MatrxPendingCallSummary[]>;
401
582
 
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 };
583
+ 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 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, isCoveredAiPath, isLiveStreamUnavailable, isResumeConflict, isV2Path, listConversationPendingToolCalls, listUserPendingToolCalls, normalizeMatrxError, openMatrxStream, providerSessionFailureBody, readLiveRunRequestId, readMatrxErrorCode, reportProviderSessionFailure, requireOrganizationContext, resumeOrRejoin, runtimeOperationRejoinPath, streamErrorText, submitAgentToolResults, toV1FallbackUrl, toV2Path, withRunOrganization };