@tangle-network/agent-app 0.46.42 → 0.46.44

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 (55) hide show
  1. package/README.md +2 -2
  2. package/dist/assistant/index.js +9 -8
  3. package/dist/assistant/index.js.map +1 -1
  4. package/dist/catalog/index.d.ts +1 -1
  5. package/dist/catalog/index.js +5 -3
  6. package/dist/chat-react/index.js +6 -5
  7. package/dist/chat-routes/gateway-adapter.d.ts +4 -2
  8. package/dist/chat-routes/index.js +115 -24
  9. package/dist/chat-routes/index.js.map +1 -1
  10. package/dist/chat-routes/turn-routes.d.ts +20 -8
  11. package/dist/chat-routes/wire.d.ts +7 -1
  12. package/dist/chat-store/index.js +3 -2
  13. package/dist/chat-store/index.js.map +1 -1
  14. package/dist/chat-store/store.d.ts +3 -0
  15. package/dist/{chunk-KWXUBMXU.js → chunk-DXHUQ5NO.js} +1 -1
  16. package/dist/chunk-DXHUQ5NO.js.map +1 -0
  17. package/dist/{chunk-U2UAQTFY.js → chunk-HHCUPBYW.js} +3 -3
  18. package/dist/{chunk-5ZTFZBS6.js → chunk-IRYULX3R.js} +2 -2
  19. package/dist/{chunk-TH7L265V.js → chunk-MCYJON3F.js} +12 -5
  20. package/dist/chunk-MCYJON3F.js.map +1 -0
  21. package/dist/{chunk-Z4TPWP6A.js → chunk-MLJQYITH.js} +2 -2
  22. package/dist/{chunk-PZOTRGGQ.js → chunk-N55NM3W2.js} +143 -8
  23. package/dist/chunk-N55NM3W2.js.map +1 -0
  24. package/dist/{chunk-QK4IFP3E.js → chunk-P3L5HF53.js} +5 -5
  25. package/dist/{chunk-YNMPMW3G.js → chunk-SUO2R2ET.js} +2 -2
  26. package/dist/{chunk-PYDMEYWA.js → chunk-TIQKVTOD.js} +26 -9
  27. package/dist/chunk-TIQKVTOD.js.map +1 -0
  28. package/dist/{chunk-OAGD7RDM.js → chunk-UEDFSZ3E.js} +43 -16
  29. package/dist/chunk-UEDFSZ3E.js.map +1 -0
  30. package/dist/harness/index.d.ts +10 -4
  31. package/dist/harness/index.js +1 -1
  32. package/dist/{mention-editor-CBLT6LE3.js → mention-editor-Y45HQYOA.js} +3 -2
  33. package/dist/{mention-editor-CBLT6LE3.js.map → mention-editor-Y45HQYOA.js.map} +1 -1
  34. package/dist/run/index.js +1 -1
  35. package/dist/runtime/index.js +4 -2
  36. package/dist/runtime/index.js.map +1 -1
  37. package/dist/runtime/model-catalog.d.ts +9 -1
  38. package/dist/sandbox/index.d.ts +33 -0
  39. package/dist/sandbox/index.js +4 -2
  40. package/dist/skills-placement/index.js +1 -1
  41. package/dist/studio-react/index.js +3 -2
  42. package/dist/studio-react/index.js.map +1 -1
  43. package/dist/web-react/controls.d.ts +4 -4
  44. package/dist/web-react/index.js +9 -8
  45. package/package.json +15 -13
  46. package/dist/chunk-KWXUBMXU.js.map +0 -1
  47. package/dist/chunk-OAGD7RDM.js.map +0 -1
  48. package/dist/chunk-PYDMEYWA.js.map +0 -1
  49. package/dist/chunk-PZOTRGGQ.js.map +0 -1
  50. package/dist/chunk-TH7L265V.js.map +0 -1
  51. /package/dist/{chunk-U2UAQTFY.js.map → chunk-HHCUPBYW.js.map} +0 -0
  52. /package/dist/{chunk-5ZTFZBS6.js.map → chunk-IRYULX3R.js.map} +0 -0
  53. /package/dist/{chunk-Z4TPWP6A.js.map → chunk-MLJQYITH.js.map} +0 -0
  54. /package/dist/{chunk-QK4IFP3E.js.map → chunk-P3L5HF53.js.map} +0 -0
  55. /package/dist/{chunk-YNMPMW3G.js.map → chunk-SUO2R2ET.js.map} +0 -0
@@ -12,4 +12,4 @@
12
12
  * no agent-runtime) so pickers and client hooks have a safe import target.
13
13
  * Server code may keep importing from `./runtime`; the two share one source.
14
14
  */
15
- export { buildCatalog, fetchModelCatalog, isChatCapableModel, normalizeModelId, __resetCatalogCache, type CatalogModel, type ModelCatalog, type RouterModel, } from '../runtime/model-catalog';
15
+ export { buildCatalog, fetchModelCatalog, isChatCapableModel, normalizeModelId, sortModelsByFreshness, __resetCatalogCache, type CatalogModel, type ModelCatalog, type RouterModel, } from '../runtime/model-catalog';
@@ -3,13 +3,15 @@ import {
3
3
  buildCatalog,
4
4
  fetchModelCatalog,
5
5
  isChatCapableModel,
6
- normalizeModelId
7
- } from "../chunk-OAGD7RDM.js";
6
+ normalizeModelId,
7
+ sortModelsByFreshness
8
+ } from "../chunk-UEDFSZ3E.js";
8
9
  export {
9
10
  __resetCatalogCache,
10
11
  buildCatalog,
11
12
  fetchModelCatalog,
12
13
  isChatCapableModel,
13
- normalizeModelId
14
+ normalizeModelId,
15
+ sortModelsByFreshness
14
16
  };
15
17
  //# sourceMappingURL=index.js.map
@@ -1,13 +1,14 @@
1
1
  import {
2
2
  ComposerModeControls,
3
3
  EntryComposer
4
- } from "../chunk-QK4IFP3E.js";
4
+ } from "../chunk-P3L5HF53.js";
5
5
  import "../chunk-L7MB2LLM.js";
6
- import "../chunk-PYDMEYWA.js";
6
+ import "../chunk-TIQKVTOD.js";
7
7
  import "../chunk-SJWIZT7B.js";
8
- import "../chunk-YNMPMW3G.js";
9
- import "../chunk-KWXUBMXU.js";
10
- import "../chunk-TH7L265V.js";
8
+ import "../chunk-SUO2R2ET.js";
9
+ import "../chunk-DXHUQ5NO.js";
10
+ import "../chunk-MCYJON3F.js";
11
+ import "../chunk-UEDFSZ3E.js";
11
12
  export {
12
13
  ComposerModeControls,
13
14
  EntryComposer
@@ -1,13 +1,15 @@
1
1
  import type { SandboxStreamEvent } from '../sandbox/index';
2
- import type { ChatTurnRoutes } from './turn-routes';
2
+ import type { ChatTurnExecutionLimits, ChatTurnRoutes } from './turn-routes';
3
3
  import { type ChatTurnRequestPayload } from './wire';
4
4
  export interface StreamChatRouteAsSandboxOptions {
5
5
  routes: ChatTurnRoutes;
6
6
  request: Request;
7
7
  payload: ChatTurnRequestPayload;
8
8
  waitUntil?: (promise: Promise<unknown>) => void;
9
- /** Abort the in-process route when the gateway client disconnects. */
9
+ /** Stop forwarding when the API client disconnects. The persisted turn continues. */
10
10
  signal?: AbortSignal;
11
+ /** Limits authenticated by the gateway and forwarded to the producer. */
12
+ executionLimits?: ChatTurnExecutionLimits;
11
13
  }
12
14
  /**
13
15
  * Drive the normal persisted chat route and expose its events to an
@@ -24,7 +24,7 @@ import {
24
24
  checkAttachmentType,
25
25
  sanitizeAttachmentFileName,
26
26
  sniffBinary
27
- } from "../chunk-YNMPMW3G.js";
27
+ } from "../chunk-SUO2R2ET.js";
28
28
  import {
29
29
  createInteractionAnswerRoute
30
30
  } from "../chunk-ZSSCVT6H.js";
@@ -36,7 +36,7 @@ import {
36
36
  attachmentKindForMime,
37
37
  mentionInputToPart,
38
38
  toChatMessageParts
39
- } from "../chunk-5ZTFZBS6.js";
39
+ } from "../chunk-IRYULX3R.js";
40
40
  import "../chunk-ZVEEWGDK.js";
41
41
  import {
42
42
  ChatTurnInputError,
@@ -58,7 +58,7 @@ import {
58
58
  parseFileMentions,
59
59
  promptPartsByteSize,
60
60
  validateSandboxMentionPath
61
- } from "../chunk-KWXUBMXU.js";
61
+ } from "../chunk-DXHUQ5NO.js";
62
62
  import {
63
63
  normalizeClientTurnId,
64
64
  resolveChatTurn
@@ -112,8 +112,8 @@ import {
112
112
  flattenHistory,
113
113
  readSandboxBinaryBytes,
114
114
  statSandboxFileSize
115
- } from "../chunk-PZOTRGGQ.js";
116
- import "../chunk-TH7L265V.js";
115
+ } from "../chunk-N55NM3W2.js";
116
+ import "../chunk-MCYJON3F.js";
117
117
  import "../chunk-LWSJK546.js";
118
118
  import "../chunk-P5PIAQVS.js";
119
119
  import "../chunk-KBJL6LIW.js";
@@ -467,7 +467,8 @@ function createChatTurnRoutes(options) {
467
467
  prompt,
468
468
  executionId,
469
469
  turnStreamId,
470
- priorMessages: chatTurn.priorMessages
470
+ priorMessages: chatTurn.priorMessages,
471
+ ...ctx?.executionLimits ? { executionLimits: ctx.executionLimits } : {}
471
472
  };
472
473
  let lockAcquired = false;
473
474
  let lockHandle;
@@ -949,25 +950,23 @@ async function closeIteratorAfterAbort(iterator) {
949
950
 
950
951
  // src/chat-routes/gateway-adapter.ts
951
952
  async function* streamChatRouteAsSandboxEvents(options) {
952
- const routeAbort = new AbortController();
953
953
  const parentSignal = options.signal ?? options.request.signal;
954
- const abortRoute = () => routeAbort.abort();
955
- if (parentSignal.aborted) abortRoute();
956
- else parentSignal.addEventListener("abort", abortRoute, { once: true });
954
+ if (parentSignal.aborted) return;
955
+ let reader;
956
+ const stopForwarding = () => void reader?.cancel();
957
+ parentSignal.addEventListener("abort", stopForwarding, { once: true });
957
958
  const request = new Request(options.request.url, {
958
959
  ...chatTurnRequestInit(options.payload),
959
- headers: options.request.headers,
960
- signal: routeAbort.signal
960
+ headers: options.request.headers
961
961
  });
962
962
  request.headers.set("Content-Type", "application/json");
963
- let reader;
964
963
  let complete = false;
965
964
  try {
966
965
  const response = await options.routes.turn(
967
966
  request,
968
967
  {
969
- cancelOnDisconnect: true,
970
- ...options.waitUntil ? { waitUntil: options.waitUntil } : {}
968
+ ...options.waitUntil ? { waitUntil: options.waitUntil } : {},
969
+ ...options.executionLimits ? { executionLimits: options.executionLimits } : {}
971
970
  }
972
971
  );
973
972
  if (!response.ok) {
@@ -976,6 +975,10 @@ async function* streamChatRouteAsSandboxEvents(options) {
976
975
  }
977
976
  if (!response.body) throw new Error("chat route returned no stream");
978
977
  reader = response.body.getReader();
978
+ if (parentSignal.aborted) {
979
+ await reader.cancel().catch(() => void 0);
980
+ return;
981
+ }
979
982
  const decoder = new TextDecoder();
980
983
  let buffer = "";
981
984
  for (; ; ) {
@@ -996,12 +999,9 @@ async function* streamChatRouteAsSandboxEvents(options) {
996
999
  }
997
1000
  }
998
1001
  } finally {
999
- if (!complete) {
1000
- routeAbort.abort();
1001
- await reader?.cancel().catch(() => void 0);
1002
- }
1002
+ if (!complete) await reader?.cancel().catch(() => void 0);
1003
1003
  reader?.releaseLock();
1004
- parentSignal.removeEventListener("abort", abortRoute);
1004
+ parentSignal.removeEventListener("abort", stopForwarding);
1005
1005
  }
1006
1006
  }
1007
1007
  function parseEvent(line) {
@@ -1023,15 +1023,81 @@ function parseEvent(line) {
1023
1023
  if (data !== void 0 && (!data || typeof data !== "object" || Array.isArray(data))) {
1024
1024
  throw new Error("chat route returned invalid event data");
1025
1025
  }
1026
+ const dataUsage = data && data.usage;
1027
+ if (dataUsage !== void 0 && (!dataUsage || typeof dataUsage !== "object" || Array.isArray(dataUsage))) {
1028
+ throw new Error("chat route returned invalid data.usage");
1029
+ }
1026
1030
  if (event.text !== void 0 && typeof event.text !== "string") {
1027
1031
  throw new Error("chat route returned an invalid text event");
1028
1032
  }
1033
+ const usage = event.usage;
1034
+ if (usage !== void 0 && (!usage || typeof usage !== "object" || Array.isArray(usage))) {
1035
+ throw new Error("chat route returned invalid usage");
1036
+ }
1037
+ if (event.toolName !== void 0 && typeof event.toolName !== "string") {
1038
+ throw new Error("chat route returned an invalid tool name");
1039
+ }
1029
1040
  return {
1030
1041
  ...typeof event.type === "string" ? { type: event.type } : {},
1031
1042
  ...data ? { data } : {},
1032
- ...typeof event.text === "string" ? { text: event.text } : {}
1043
+ ...typeof event.text === "string" ? { text: event.text } : {},
1044
+ ...usage ? { usage } : {},
1045
+ ...typeof event.toolName === "string" ? { toolName: event.toolName } : {}
1033
1046
  };
1034
1047
  }
1048
+ function isNonNegativeSafeInteger(value) {
1049
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
1050
+ }
1051
+ function aliasedSafeInteger(usage, field, alias) {
1052
+ const value = usage[field];
1053
+ const aliasValue = alias ? usage[alias] : void 0;
1054
+ for (const candidate of [value, aliasValue]) {
1055
+ if (candidate !== void 0 && !isNonNegativeSafeInteger(candidate)) {
1056
+ throw new Error(`chat route returned invalid usage.${field}`);
1057
+ }
1058
+ }
1059
+ if (value !== void 0 && aliasValue !== void 0 && value !== aliasValue) {
1060
+ throw new Error(`chat route returned conflicting usage.${field}`);
1061
+ }
1062
+ return value ?? aliasValue;
1063
+ }
1064
+ function aliasedNonNegativeNumber(usage, field, alias) {
1065
+ const value = usage[field];
1066
+ const aliasValue = alias ? usage[alias] : void 0;
1067
+ for (const candidate of [value, aliasValue]) {
1068
+ if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
1069
+ throw new Error(`chat route returned invalid usage.${field}`);
1070
+ }
1071
+ }
1072
+ if (value !== void 0 && aliasValue !== void 0 && value !== aliasValue) {
1073
+ throw new Error(`chat route returned conflicting usage.${field}`);
1074
+ }
1075
+ return value ?? aliasValue;
1076
+ }
1077
+ function providerUsageUpdate(value) {
1078
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
1079
+ const source = value;
1080
+ const usage = {};
1081
+ const inputTokens = aliasedSafeInteger(source, "inputTokens", "promptTokens");
1082
+ const outputTokens = aliasedSafeInteger(source, "outputTokens", "completionTokens");
1083
+ const reasoningTokens = aliasedSafeInteger(source, "reasoningTokens");
1084
+ const toolTokens = aliasedSafeInteger(source, "toolTokens");
1085
+ const toolCallCount = aliasedSafeInteger(source, "toolCallCount");
1086
+ const providerCostUsd = aliasedNonNegativeNumber(source, "providerCostUsd", "costUsd");
1087
+ if (inputTokens !== void 0) usage.inputTokens = inputTokens;
1088
+ if (outputTokens !== void 0) usage.outputTokens = outputTokens;
1089
+ if (reasoningTokens !== void 0) usage.reasoningTokens = reasoningTokens;
1090
+ if (toolTokens !== void 0) usage.toolTokens = toolTokens;
1091
+ if (toolCallCount !== void 0) usage.toolCallCount = toolCallCount;
1092
+ if (providerCostUsd !== void 0) usage.providerCostUsd = providerCostUsd;
1093
+ if (source.budgetEnforced !== void 0) {
1094
+ if (typeof source.budgetEnforced !== "boolean") {
1095
+ throw new Error("chat route returned invalid usage.budgetEnforced");
1096
+ }
1097
+ usage.budgetEnforced = source.budgetEnforced;
1098
+ }
1099
+ return Object.keys(usage).length > 0 ? usage : null;
1100
+ }
1035
1101
  function toSandboxEvent(event) {
1036
1102
  if (!event) return null;
1037
1103
  if (event.type === "text") {
@@ -1041,7 +1107,16 @@ function toSandboxEvent(event) {
1041
1107
  data: { part: { type: "text" }, delta: event.text }
1042
1108
  };
1043
1109
  }
1044
- if (event.type === "reasoning" || event.type === "usage") return null;
1110
+ if (event.type === "reasoning") return null;
1111
+ if (event.type === "usage" || event.usage || event.data?.usage) {
1112
+ const usage = providerUsageUpdate(event.usage ?? event.data?.usage);
1113
+ if (!usage) return null;
1114
+ return { type: "usage", data: { usage } };
1115
+ }
1116
+ if (event.type === "tool_result") {
1117
+ if (!event.toolName) throw new Error("chat route tool result had no tool name");
1118
+ return { type: "tool_result", data: { tool: { name: event.toolName } } };
1119
+ }
1045
1120
  if (event.type === "input-required" && !event.data?.inputRequired) {
1046
1121
  const prompt = typeof event.data?.prompt === "string" ? event.data.prompt : void 0;
1047
1122
  return {
@@ -1655,7 +1730,15 @@ function createSandboxChatProducer(options) {
1655
1730
  const promptTokens = usage.inputTokens ?? 0;
1656
1731
  const completionTokens = usage.outputTokens ?? 0;
1657
1732
  if (promptTokens || completionTokens) {
1658
- yield { type: "usage", usage: { promptTokens, completionTokens } };
1733
+ yield {
1734
+ type: "usage",
1735
+ usage: {
1736
+ promptTokens,
1737
+ completionTokens,
1738
+ ...usage.reasoningTokens !== void 0 ? { reasoningTokens: usage.reasoningTokens } : {},
1739
+ ...usage.costUsd !== void 0 ? { providerCostUsd: usage.costUsd } : {}
1740
+ }
1741
+ };
1659
1742
  }
1660
1743
  }
1661
1744
  function* drainModelNotices() {
@@ -1728,7 +1811,15 @@ function createSandboxChatProducer(options) {
1728
1811
  const promptTokens = usage.inputTokens ?? 0;
1729
1812
  const completionTokens = usage.outputTokens ?? 0;
1730
1813
  if (promptTokens || completionTokens) {
1731
- yield { type: "usage", usage: { promptTokens, completionTokens } };
1814
+ yield {
1815
+ type: "usage",
1816
+ usage: {
1817
+ promptTokens,
1818
+ completionTokens,
1819
+ ...usage.reasoningTokens !== void 0 ? { reasoningTokens: usage.reasoningTokens } : {},
1820
+ ...usage.costUsd !== void 0 ? { providerCostUsd: usage.costUsd } : {}
1821
+ }
1822
+ };
1732
1823
  }
1733
1824
  continue;
1734
1825
  }