@ai-matrx/agents 0.24.2 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -4,7 +4,7 @@ export { projectAgentResultForDisplay } from './presentation/result.cjs';
4
4
  export { AgentProjectionEvent, AgentProjectionOperation, AgentProjectionRenderBlock, AgentProjectionStatus, AgentProjectionTool, AgentRequestProjection, createAgentRequestProjection, projectAgentEvent, projectAgentEvents } from './projection/request.cjs';
5
5
  export { DEFAULT_WORKFLOW_PROJECTION_LIMITS, WorkflowNodeProjection, WorkflowNodeStreamEvent, WorkflowProjectionLimits, WorkflowRenderBlockIssue, WorkflowRenderBlockIssueCode, WorkflowRenderFrameSet, createWorkflowNodeProjection, projectWorkflowNodeEvent } from './projection/workflow.cjs';
6
6
  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, l as MatrxJsonObject, m as MatrxJsonValue, 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, B as MatrxTransport, 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';
7
- export { CreateMatrxTransportOptions, MATRX_AI_API_VERSION_DEFAULT, MATRX_LIVE_STREAM_UNAVAILABLE, MATRX_RESUME_CONFLICT, MATRX_RUN_IN_PROGRESS, MatrxAiApiVersion, MatrxCallError, MatrxClientSessionProvider, MatrxClientToolResult, MatrxHttpErrorLike, MatrxLiveRunRejoin, MatrxPendingCallSummary, MatrxProtocolDowngrade, MatrxProtocolFallbackOptions, MatrxRequestInfo, MatrxToolResultsResponse, MatrxTransportDiagnostics, MatrxTransportTarget, OrganizationContextError, OrganizationContextErrorCode, OrganizationOperation, ProviderSessionFailure, ProviderSessionFailureVerdict, ResumeOrRejoinOptions, 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 } from './matrx/index.cjs';
7
+ export { CreateMatrxTransportOptions, FollowUnavailableRejoinOptions, MATRX_AI_API_VERSION_DEFAULT, MATRX_LIVE_STREAM_UNAVAILABLE, MATRX_RESUME_CONFLICT, MATRX_RUN_IN_PROGRESS, MatrxAiApiVersion, MatrxCallError, MatrxClientSessionProvider, MatrxClientToolResult, MatrxFollowedOutcome, MatrxHttpErrorLike, MatrxLiveRunRejoin, MatrxLiveStreamUnavailable, MatrxPendingCallSummary, MatrxProtocolDowngrade, MatrxProtocolFallbackOptions, MatrxRequestInfo, MatrxRunPickup, MatrxRunPickupSettlement, MatrxToolResultsResponse, MatrxTransportDiagnostics, MatrxTransportTarget, OrganizationContextError, OrganizationContextErrorCode, OrganizationOperation, ProviderSessionFailure, ProviderSessionFailureVerdict, ResumeOrRejoinOptions, ResumeOrRejoinOutcome, SettleRunPickupOptions, V2_COVERED_AI_PATH_TEMPLATES, applyAiApiVersion, applyOrganizationContextHeader, assertOrganizationMatchesOperation, assertQueryOrganizationMatchesContext, createMatrxTransport, createOrganizationOperation, fetchWithMatrxProtocolFallback, followUnavailableRejoin, followWorkflowRunEvents, isCoveredAiPath, isLiveStreamUnavailable, isResumeConflict, isV2Path, listConversationPendingToolCalls, listUserPendingToolCalls, normalizeMatrxError, openMatrxStream, providerSessionFailureBody, readLiveRunRejoin, readLiveRunRequestId, readLiveStreamUnavailable, readMatrxErrorCode, reportProviderSessionFailure, requireOrganizationContext, resumeOrRejoin, runtimeOperationRejoinPath, settleRunPickup, streamErrorText, submitAgentToolResults, toV1FallbackUrl, toV2Path, withRunOrganization } from './matrx/index.cjs';
8
8
  import '@ai-matrx/data';
9
9
  import '@ai-matrx/data/net';
10
10
 
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { projectAgentResultForDisplay } from './presentation/result.js';
4
4
  export { AgentProjectionEvent, AgentProjectionOperation, AgentProjectionRenderBlock, AgentProjectionStatus, AgentProjectionTool, AgentRequestProjection, createAgentRequestProjection, projectAgentEvent, projectAgentEvents } from './projection/request.js';
5
5
  export { DEFAULT_WORKFLOW_PROJECTION_LIMITS, WorkflowNodeProjection, WorkflowNodeStreamEvent, WorkflowProjectionLimits, WorkflowRenderBlockIssue, WorkflowRenderBlockIssueCode, WorkflowRenderFrameSet, createWorkflowNodeProjection, projectWorkflowNodeEvent } from './projection/workflow.js';
6
6
  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, l as MatrxJsonObject, m as MatrxJsonValue, 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, B as MatrxTransport, 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';
7
- export { CreateMatrxTransportOptions, MATRX_AI_API_VERSION_DEFAULT, MATRX_LIVE_STREAM_UNAVAILABLE, MATRX_RESUME_CONFLICT, MATRX_RUN_IN_PROGRESS, MatrxAiApiVersion, MatrxCallError, MatrxClientSessionProvider, MatrxClientToolResult, MatrxHttpErrorLike, MatrxLiveRunRejoin, MatrxPendingCallSummary, MatrxProtocolDowngrade, MatrxProtocolFallbackOptions, MatrxRequestInfo, MatrxToolResultsResponse, MatrxTransportDiagnostics, MatrxTransportTarget, OrganizationContextError, OrganizationContextErrorCode, OrganizationOperation, ProviderSessionFailure, ProviderSessionFailureVerdict, ResumeOrRejoinOptions, 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 } from './matrx/index.js';
7
+ export { CreateMatrxTransportOptions, FollowUnavailableRejoinOptions, MATRX_AI_API_VERSION_DEFAULT, MATRX_LIVE_STREAM_UNAVAILABLE, MATRX_RESUME_CONFLICT, MATRX_RUN_IN_PROGRESS, MatrxAiApiVersion, MatrxCallError, MatrxClientSessionProvider, MatrxClientToolResult, MatrxFollowedOutcome, MatrxHttpErrorLike, MatrxLiveRunRejoin, MatrxLiveStreamUnavailable, MatrxPendingCallSummary, MatrxProtocolDowngrade, MatrxProtocolFallbackOptions, MatrxRequestInfo, MatrxRunPickup, MatrxRunPickupSettlement, MatrxToolResultsResponse, MatrxTransportDiagnostics, MatrxTransportTarget, OrganizationContextError, OrganizationContextErrorCode, OrganizationOperation, ProviderSessionFailure, ProviderSessionFailureVerdict, ResumeOrRejoinOptions, ResumeOrRejoinOutcome, SettleRunPickupOptions, V2_COVERED_AI_PATH_TEMPLATES, applyAiApiVersion, applyOrganizationContextHeader, assertOrganizationMatchesOperation, assertQueryOrganizationMatchesContext, createMatrxTransport, createOrganizationOperation, fetchWithMatrxProtocolFallback, followUnavailableRejoin, followWorkflowRunEvents, isCoveredAiPath, isLiveStreamUnavailable, isResumeConflict, isV2Path, listConversationPendingToolCalls, listUserPendingToolCalls, normalizeMatrxError, openMatrxStream, providerSessionFailureBody, readLiveRunRejoin, readLiveRunRequestId, readLiveStreamUnavailable, readMatrxErrorCode, reportProviderSessionFailure, requireOrganizationContext, resumeOrRejoin, runtimeOperationRejoinPath, settleRunPickup, streamErrorText, submitAgentToolResults, toV1FallbackUrl, toV2Path, withRunOrganization } from './matrx/index.js';
8
8
  import '@ai-matrx/data';
9
9
  import '@ai-matrx/data/net';
10
10
 
package/dist/index.js CHANGED
@@ -1378,18 +1378,18 @@ async function followRuntimeOperationToEnd(transport, executionId, options) {
1378
1378
  let cursor = options.lastEventSeq ?? 0;
1379
1379
  let failures = 0;
1380
1380
  while (!outer?.aborted && failures < reconnectLimit) {
1381
- const attempt = new AbortController();
1382
- const onOuterAbort = () => attempt.abort();
1381
+ const attempt2 = new AbortController();
1382
+ const onOuterAbort = () => attempt2.abort();
1383
1383
  outer?.addEventListener("abort", onOuterAbort, { once: true });
1384
1384
  let stallTimer = null;
1385
1385
  const armStall = () => {
1386
1386
  if (stallTimer !== null) clearTimeout(stallTimer);
1387
- stallTimer = setTimeout(() => attempt.abort(), stallTimeoutMs);
1387
+ stallTimer = setTimeout(() => attempt2.abort(), stallTimeoutMs);
1388
1388
  };
1389
1389
  try {
1390
1390
  const items = followRuntimeOperationEvents(transport, executionId, {
1391
1391
  lastEventSeq: cursor,
1392
- signal: attempt.signal,
1392
+ signal: attempt2.signal,
1393
1393
  ...options.onMalformedFrame ? { onMalformedFrame: options.onMalformedFrame } : {}
1394
1394
  });
1395
1395
  armStall();
@@ -1484,7 +1484,7 @@ function readLiveRunRejoin(error) {
1484
1484
  const candidates = detailCandidates(bodyOf(error));
1485
1485
  if (candidates.length === 0) return null;
1486
1486
  const code = readMatrxErrorCode(error);
1487
- if (code !== MATRX_RUN_IN_PROGRESS && code !== MATRX_RESUME_CONFLICT) return null;
1487
+ if (code !== MATRX_RUN_IN_PROGRESS) return null;
1488
1488
  const liveRequestId = firstString(candidates, "live_request_id");
1489
1489
  const pathFromBody = firstString(candidates, "rejoin_path");
1490
1490
  const rejoinPath = pathFromBody && pathFromBody.startsWith("/") ? pathFromBody : liveRequestId ? runtimeOperationRejoinPath(liveRequestId) : null;
@@ -1502,7 +1502,7 @@ function readLiveRunRequestId(error) {
1502
1502
  return readLiveRunRejoin(error)?.liveRequestId ?? null;
1503
1503
  }
1504
1504
  function isResumeConflict(error) {
1505
- return statusOf(error) === 409 && readMatrxErrorCode(error) === MATRX_RESUME_CONFLICT && readLiveRunRejoin(error) === null;
1505
+ return statusOf(error) === 409 && readMatrxErrorCode(error) === MATRX_RESUME_CONFLICT;
1506
1506
  }
1507
1507
  function isLiveStreamUnavailable(error) {
1508
1508
  return statusOf(error) === 409 && readMatrxErrorCode(error) === MATRX_LIVE_STREAM_UNAVAILABLE;
@@ -1605,7 +1605,7 @@ async function resumeOrRejoin(transport, resumeCall, options) {
1605
1605
  rejoin = target;
1606
1606
  }
1607
1607
  onRejoin?.(rejoin);
1608
- let unavailableBody;
1608
+ let unavailable;
1609
1609
  try {
1610
1610
  const handle = await openMatrxStream(bound, rejoin.rejoinPath, {
1611
1611
  ...streamOptions,
@@ -1615,14 +1615,29 @@ async function resumeOrRejoin(transport, resumeCall, options) {
1615
1615
  await drain(handle, onEnvelope);
1616
1616
  return { kind: "rejoined", rejoin };
1617
1617
  } catch (error) {
1618
- if (!isLiveStreamUnavailable(error)) throw error;
1619
- unavailableBody = bodyOf(error);
1618
+ const read = readLiveStreamUnavailable(error);
1619
+ if (!read) throw error;
1620
+ unavailable = read;
1620
1621
  }
1621
- const runId = firstString(detailCandidates(unavailableBody), "run_id") ?? rejoin.runId;
1622
+ return followUnavailableRejoin(bound, rejoin, unavailable, {
1623
+ ...signalOnly,
1624
+ ...onOperationEvent ? { onOperationEvent } : {},
1625
+ ...onWorkflowEvent ? { onWorkflowEvent } : {},
1626
+ ...follow ? { follow } : {}
1627
+ });
1628
+ }
1629
+ function readLiveStreamUnavailable(error) {
1630
+ if (!isLiveStreamUnavailable(error)) return null;
1631
+ return { runId: firstString(detailCandidates(bodyOf(error)), "run_id") };
1632
+ }
1633
+ async function followUnavailableRejoin(transport, rejoin, unavailable, options = {}) {
1634
+ const bound = options.organizationId ? withRunOrganization(transport, options.organizationId) : transport;
1635
+ const signalOnly = options.signal ? { signal: options.signal } : {};
1636
+ const runId = unavailable.runId ?? rejoin.runId;
1622
1637
  if (runId && rejoin.rejoinPath.startsWith("/runtime/operations/")) {
1623
1638
  const result2 = await followWorkflowRunEvents(bound, runId, {
1624
1639
  ...signalOnly,
1625
- onEvent: (event, seq) => onWorkflowEvent?.(event, seq)
1640
+ onEvent: (event, seq) => options.onWorkflowEvent?.(event, seq)
1626
1641
  });
1627
1642
  return { kind: "followed_workflow", rejoin, runId, ended: result2.ended };
1628
1643
  }
@@ -1642,10 +1657,10 @@ async function resumeOrRejoin(transport, resumeCall, options) {
1642
1657
  };
1643
1658
  }
1644
1659
  const result = await followRuntimeOperationToEnd(bound, operation.execution_id, {
1645
- ...follow,
1660
+ ...options.follow,
1646
1661
  lastEventSeq: operation.last_event_seq,
1647
1662
  ...signalOnly,
1648
- onEvent: (event) => onOperationEvent?.(event)
1663
+ onEvent: (event) => options.onOperationEvent?.(event)
1649
1664
  });
1650
1665
  return {
1651
1666
  kind: "followed",
@@ -1655,6 +1670,35 @@ async function resumeOrRejoin(transport, resumeCall, options) {
1655
1670
  status: result.status
1656
1671
  };
1657
1672
  }
1673
+ async function attempt(run) {
1674
+ try {
1675
+ await run();
1676
+ return { reloaded: true };
1677
+ } catch (error) {
1678
+ return { reloaded: false, error };
1679
+ }
1680
+ }
1681
+ async function settleRunPickup(pickup, options) {
1682
+ switch (pickup.kind) {
1683
+ case "resumed":
1684
+ case "rejoined":
1685
+ return { state: "streamed" };
1686
+ case "resume_conflict":
1687
+ return { state: "retry" };
1688
+ case "followed_workflow":
1689
+ case "followed": {
1690
+ const status = pickup.kind === "followed" ? pickup.status : null;
1691
+ const nothingLive = pickup.kind === "followed" && pickup.executionId === null;
1692
+ if (pickup.ended || nothingLive) {
1693
+ return { state: "settled", status, ...await attempt(options.reloadSavedTurn) };
1694
+ }
1695
+ return {
1696
+ state: "still_running",
1697
+ ...await attempt(options.onStillRunning ?? options.reloadSavedTurn)
1698
+ };
1699
+ }
1700
+ }
1701
+ }
1658
1702
 
1659
1703
  // matrx/run.ts
1660
1704
  async function streamCall(transport, path, body, options) {
@@ -2114,6 +2158,7 @@ export {
2114
2158
  fetchWithMatrxProtocolFallback,
2115
2159
  followRuntimeOperationEvents,
2116
2160
  followRuntimeOperationToEnd,
2161
+ followUnavailableRejoin,
2117
2162
  followWorkflowRunEvents,
2118
2163
  getRuntimeOperationStatus,
2119
2164
  getRuntimeOperationsByLink,
@@ -2147,6 +2192,7 @@ export {
2147
2192
  readImageRoleLimits,
2148
2193
  readLiveRunRejoin,
2149
2194
  readLiveRunRequestId,
2195
+ readLiveStreamUnavailable,
2150
2196
  readMatrxErrorCode,
2151
2197
  readMatrxNdjsonStream,
2152
2198
  readMatrxSseStream,
@@ -2160,6 +2206,7 @@ export {
2160
2206
  rolesFor,
2161
2207
  runAgentToCompletion,
2162
2208
  runtimeOperationRejoinPath,
2209
+ settleRunPickup,
2163
2210
  startAgentRun,
2164
2211
  startMandateRun,
2165
2212
  streamErrorText,