@ai-matrx/agents 0.37.1 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -122,6 +122,7 @@ __export(index_exports, {
122
122
  readLiveStreamUnavailable: () => readLiveStreamUnavailable,
123
123
  readMatrxErrorCode: () => readMatrxErrorCode,
124
124
  readMatrxErrorCodeFromMessage: () => readMatrxErrorCodeFromMessage,
125
+ readMatrxJsonResponse: () => readMatrxJsonResponse,
125
126
  readMatrxNdjsonStream: () => readMatrxNdjsonStream,
126
127
  readMatrxSseStream: () => readMatrxSseStream,
127
128
  redactUrlForRequestLog: () => redactUrlForRequestLog,
@@ -141,6 +142,7 @@ __export(index_exports, {
141
142
  runWaitKnobKey: () => runWaitKnobKey,
142
143
  runWaitTimeoutMessage: () => runWaitTimeoutMessage,
143
144
  runtimeOperationRejoinPath: () => runtimeOperationRejoinPath,
145
+ sendMatrxRequest: () => sendMatrxRequest,
144
146
  settleRunPickup: () => settleRunPickup,
145
147
  shouldReportMatrxCallError: () => shouldReportMatrxCallError,
146
148
  startAgentRun: () => startAgentRun,
@@ -1492,13 +1494,15 @@ function buildMatrxRequestUrl(baseUrl, pathTemplate, pathParams, queryParams) {
1492
1494
  }
1493
1495
  const fullPath = resolvedPath.startsWith("/api/") ? resolvedPath.slice(4) : resolvedPath;
1494
1496
  const url = `${baseUrl}${fullPath}`;
1495
- if (queryParams && Object.keys(queryParams).length > 0) {
1496
- const qs = new URLSearchParams(
1497
- Object.fromEntries(
1498
- Object.entries(queryParams).map(([k, v]) => [k, String(v)])
1499
- )
1500
- ).toString();
1501
- return `${url}?${qs}`;
1497
+ if (queryParams) {
1498
+ const search = new URLSearchParams();
1499
+ for (const [key, value] of Object.entries(queryParams)) {
1500
+ if (value === null || value === void 0) continue;
1501
+ const values = Array.isArray(value) ? value : [value];
1502
+ for (const entry of values) search.append(key, String(entry));
1503
+ }
1504
+ const qs = search.toString();
1505
+ if (qs) return `${url}${url.includes("?") ? "&" : "?"}${qs}`;
1502
1506
  }
1503
1507
  return url;
1504
1508
  }
@@ -1682,6 +1686,44 @@ async function executeMatrxCall(request, hooks = {}) {
1682
1686
  ...parsed.conversationId !== null ? { conversationId: parsed.conversationId } : {}
1683
1687
  };
1684
1688
  }
1689
+ async function sendMatrxRequest(url, init = {}, options = {}) {
1690
+ const callerSignal = options.signal ?? init.signal ?? void 0;
1691
+ if (options.timeoutMs === void 0) {
1692
+ return fetch(url, { ...init, ...callerSignal ? { signal: callerSignal } : {} });
1693
+ }
1694
+ const controller = new AbortController();
1695
+ const onCallerAbort = () => controller.abort(callerSignal?.reason);
1696
+ if (callerSignal) {
1697
+ if (callerSignal.aborted) controller.abort(callerSignal.reason);
1698
+ else callerSignal.addEventListener("abort", onCallerAbort, { once: true });
1699
+ }
1700
+ let timedOut = false;
1701
+ const timer = setTimeout(() => {
1702
+ timedOut = true;
1703
+ controller.abort();
1704
+ }, options.timeoutMs);
1705
+ try {
1706
+ return await fetch(url, { ...init, signal: controller.signal });
1707
+ } catch (error) {
1708
+ if (timedOut) {
1709
+ throw new BackendApiError({
1710
+ code: "request_timeout",
1711
+ detail: `${init.method ?? "GET"} ${url} exceeded ${options.timeoutMs}ms`,
1712
+ userMessage: "The request timed out \u2014 please retry.",
1713
+ status: 504
1714
+ });
1715
+ }
1716
+ throw error;
1717
+ } finally {
1718
+ clearTimeout(timer);
1719
+ callerSignal?.removeEventListener("abort", onCallerAbort);
1720
+ }
1721
+ }
1722
+ async function readMatrxJsonResponse(response) {
1723
+ if (!response.ok) throw await parseHttpError(response);
1724
+ if (response.status === 204) return null;
1725
+ return await response.json();
1726
+ }
1685
1727
 
1686
1728
  // matrx/client.ts
1687
1729
  function classifyStatus(status) {