@tangle-network/agent-app 0.63.59 → 0.63.61

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 (81) hide show
  1. package/dist/{DesignCanvas-Q65UV4D5.js → DesignCanvas-566V5KVC.js} +3 -2
  2. package/dist/{DesignCanvasEditor-THEFESEX.js → DesignCanvasEditor-YWDEFWYQ.js} +3 -2
  3. package/dist/app-auth/index.js +2 -1
  4. package/dist/app-auth/index.js.map +1 -1
  5. package/dist/assistant/index.js +6 -5
  6. package/dist/assistant/index.js.map +1 -1
  7. package/dist/chat-react/index.js +3 -3
  8. package/dist/chat-routes/agent-producers.d.ts +38 -0
  9. package/dist/chat-routes/index.d.ts +1 -0
  10. package/dist/chat-routes/index.js +25 -8
  11. package/dist/chat-routes/index.js.map +1 -1
  12. package/dist/chat-routes/turn-admission.d.ts +3 -3
  13. package/dist/chat-routes/turn-route-contracts.d.ts +38 -1
  14. package/dist/chat-routes/wire.d.ts +29 -4
  15. package/dist/chat-store/index.js +4 -2
  16. package/dist/chat-store/index.js.map +1 -1
  17. package/dist/chat-store/parts.d.ts +19 -3
  18. package/dist/{chunk-P7UB7ZVP.js → chunk-75I4RXIE.js} +2 -2
  19. package/dist/{chunk-GGJYAV7R.js → chunk-DPZXCVVS.js} +2 -2
  20. package/dist/{chunk-GGJYAV7R.js.map → chunk-DPZXCVVS.js.map} +1 -1
  21. package/dist/{chunk-LAZCUQFZ.js → chunk-F2N55QQX.js} +47 -10
  22. package/dist/chunk-F2N55QQX.js.map +1 -0
  23. package/dist/{chunk-QGJOT6R6.js → chunk-F6UC2T6U.js} +49 -9
  24. package/dist/{chunk-QGJOT6R6.js.map → chunk-F6UC2T6U.js.map} +1 -1
  25. package/dist/{chunk-AICYKYYF.js → chunk-MIQL36JS.js} +17 -4
  26. package/dist/chunk-MIQL36JS.js.map +1 -0
  27. package/dist/{chunk-RILVJYXJ.js → chunk-N5KBDRSX.js} +2 -2
  28. package/dist/{chunk-IDQ7N36R.js → chunk-O2TYB3DH.js} +2 -2
  29. package/dist/{chunk-H6BRJU5M.js → chunk-RKNNMC6T.js} +1 -1
  30. package/dist/{chunk-HHPQMFKP.js → chunk-RNFVAAJJ.js} +2 -2
  31. package/dist/{chunk-KFO5R4SN.js → chunk-RVC7EHJI.js} +135 -64
  32. package/dist/chunk-RVC7EHJI.js.map +1 -0
  33. package/dist/{chunk-4E2MUVGL.js → chunk-TFV4QOCG.js} +3 -3
  34. package/dist/chunk-XBBXPZJI.js +47 -0
  35. package/dist/chunk-XBBXPZJI.js.map +1 -0
  36. package/dist/design-canvas/index.js +2 -1
  37. package/dist/design-canvas/index.js.map +1 -1
  38. package/dist/design-canvas-react/engine.js +2 -1
  39. package/dist/design-canvas-react/index.js +3 -2
  40. package/dist/design-canvas-react/index.js.map +1 -1
  41. package/dist/design-canvas-react/lazy.js +1 -1
  42. package/dist/operator/index.js +2 -2
  43. package/dist/platform/index.js +2 -1
  44. package/dist/platform/index.js.map +1 -1
  45. package/dist/preset-cloudflare/index.js +4 -4
  46. package/dist/public-consultation/index.d.ts +2 -2
  47. package/dist/public-consultation/index.js +7 -6
  48. package/dist/public-consultation/index.js.map +1 -1
  49. package/dist/sandbox/index.js +2 -2
  50. package/dist/sequences/index.js +2 -1
  51. package/dist/sequences/index.js.map +1 -1
  52. package/dist/stories/chat/fixtures.d.ts +4 -0
  53. package/dist/theme/tokens.css +2 -4
  54. package/dist/vault/store/index.js +330 -259
  55. package/dist/vault/store/index.js.map +1 -1
  56. package/dist/vault/store/sandbox-hydrate.d.ts +22 -1
  57. package/dist/vault/store/sandbox-reconcile.d.ts +11 -3
  58. package/dist/vault/store/sandbox-sync.d.ts +26 -0
  59. package/dist/web/index.d.ts +1 -0
  60. package/dist/web/index.js +7 -1
  61. package/dist/web/speakers.d.ts +30 -0
  62. package/dist/web-react/chat-messages.d.ts +1 -1
  63. package/dist/web-react/chat-stream.d.ts +7 -0
  64. package/dist/web-react/entry-composer.d.ts +2 -2
  65. package/dist/web-react/index.js +8 -5
  66. package/dist/web-react/use-file-mentions.d.ts +23 -4
  67. package/dist/workspace-react/index.d.ts +29 -1
  68. package/dist/workspace-react/index.js +34 -0
  69. package/dist/workspace-react/index.js.map +1 -1
  70. package/package.json +5 -5
  71. package/dist/chunk-AICYKYYF.js.map +0 -1
  72. package/dist/chunk-KFO5R4SN.js.map +0 -1
  73. package/dist/chunk-LAZCUQFZ.js.map +0 -1
  74. /package/dist/{DesignCanvas-Q65UV4D5.js.map → DesignCanvas-566V5KVC.js.map} +0 -0
  75. /package/dist/{DesignCanvasEditor-THEFESEX.js.map → DesignCanvasEditor-YWDEFWYQ.js.map} +0 -0
  76. /package/dist/{chunk-P7UB7ZVP.js.map → chunk-75I4RXIE.js.map} +0 -0
  77. /package/dist/{chunk-RILVJYXJ.js.map → chunk-N5KBDRSX.js.map} +0 -0
  78. /package/dist/{chunk-IDQ7N36R.js.map → chunk-O2TYB3DH.js.map} +0 -0
  79. /package/dist/{chunk-H6BRJU5M.js.map → chunk-RKNNMC6T.js.map} +0 -0
  80. /package/dist/{chunk-HHPQMFKP.js.map → chunk-RNFVAAJJ.js.map} +0 -0
  81. /package/dist/{chunk-4E2MUVGL.js.map → chunk-TFV4QOCG.js.map} +0 -0
@@ -27,7 +27,7 @@ import {
27
27
  sandboxRunFailureDetail,
28
28
  streamSandboxPrompt,
29
29
  turnStorageBindings
30
- } from "./chunk-IDQ7N36R.js";
30
+ } from "./chunk-O2TYB3DH.js";
31
31
  import {
32
32
  redactErrorMessage
33
33
  } from "./chunk-MH74DY2I.js";
@@ -37,7 +37,7 @@ import {
37
37
  createAssistantDraftWriter,
38
38
  rowIdOf,
39
39
  storeSupportsDraftPersistence
40
- } from "./chunk-HHPQMFKP.js";
40
+ } from "./chunk-RNFVAAJJ.js";
41
41
  import {
42
42
  normalizeClientTurnId,
43
43
  resolveChatTurn
@@ -46,7 +46,7 @@ import {
46
46
  historyContentWithAttachments,
47
47
  mentionInputToPart,
48
48
  toChatMessageParts
49
- } from "./chunk-AICYKYYF.js";
49
+ } from "./chunk-MIQL36JS.js";
50
50
  import {
51
51
  asRecord,
52
52
  asString,
@@ -88,15 +88,16 @@ import {
88
88
  TURN_PROGRESS_FIRST,
89
89
  TURN_PROGRESS_HEADER,
90
90
  TURN_ROUTE_PHASE_MESSAGES,
91
+ agentMentionsOf,
91
92
  assertPromptPartsWithinCap,
92
93
  base64WireLen,
93
94
  buildTurnPhaseEvent,
94
95
  chatTurnRequestInit,
95
96
  mediaTypeForMentionPath,
96
97
  parseChatTurnParts,
97
- parseFileMentions,
98
+ parseMentions,
98
99
  turnResponseEventFor
99
- } from "./chunk-QGJOT6R6.js";
100
+ } from "./chunk-F6UC2T6U.js";
100
101
  import {
101
102
  ModelFailoverExhaustedError,
102
103
  buildModelChain,
@@ -1774,6 +1775,125 @@ async function* observeTurnCancellation(source, args, cancel, abort) {
1774
1775
  }
1775
1776
  }
1776
1777
 
1778
+ // src/chat-routes/turn-admission.ts
1779
+ function errorResponse(err) {
1780
+ return Response.json({ code: err.code, error: err.message }, { status: err.status });
1781
+ }
1782
+ function admissionServerTiming(trace) {
1783
+ const now = Date.now();
1784
+ const steps = trace.spans(now).filter((span) => span.kind === "admission").sort((a, b) => a.startMs - b.startMs).map((span) => ({ name: span.name, durMs: span.endMs - span.startMs }));
1785
+ return formatServerTiming([{ name: "admission", durMs: now - trace.startedAt }, ...steps]);
1786
+ }
1787
+ async function namedModelRefusal(policy, payload, trace) {
1788
+ const namedModel = typeof payload.model === "string" ? payload.model.trim() : "";
1789
+ if (!policy || !namedModel) return null;
1790
+ const decision = await trace.measure("admission.model_policy", "admission", () => checkModelPolicy(namedModel, policy.catalog, policy.filter, policy.context));
1791
+ return decision.allowed ? null : Response.json({ code: "model_policy_denied", error: decision.reason }, { status: 403 });
1792
+ }
1793
+ function validateTurnBody(body) {
1794
+ const threadId = typeof body.threadId === "string" ? body.threadId.trim() : "";
1795
+ if (!threadId) throw new ChatTurnInputError("Missing threadId");
1796
+ const rawContent = body.content ?? body.message ?? "";
1797
+ if (typeof rawContent !== "string") throw new ChatTurnInputError("content must be a string");
1798
+ const content = rawContent.trim();
1799
+ const fileParts = parseChatTurnParts(body.parts);
1800
+ const mentions = parseMentions(body.mentions);
1801
+ const hasAttachments = Array.isArray(body.attachments) && body.attachments.length > 0;
1802
+ if (!content && fileParts.length === 0 && mentions.length === 0 && !hasAttachments) {
1803
+ throw new ChatTurnInputError("Missing content (send text, parts, mentions, attachments, or any combination)");
1804
+ }
1805
+ assertPromptPartsWithinCap(fileParts);
1806
+ let turnId;
1807
+ try {
1808
+ turnId = normalizeClientTurnId(body.turnId);
1809
+ } catch (err) {
1810
+ throw new ChatTurnInputError(err instanceof Error ? err.message : "Invalid turnId");
1811
+ }
1812
+ const retryAttemptId = body.retryAttemptId;
1813
+ if (retryAttemptId !== void 0 && (typeof retryAttemptId !== "string" || !/^[A-Za-z0-9_-]{1,64}$/.test(retryAttemptId) || !turnId)) throw new ChatTurnInputError("retryAttemptId requires turnId and 1\u201364 letters, digits, underscores, or hyphens");
1814
+ return {
1815
+ // The VALIDATED, deduped mention list replaces the raw one on the payload,
1816
+ // so every downstream seam (`authorize`, `contextGate`, `beforeTurn`,
1817
+ // `produce`) reads checked paths and never the request's own.
1818
+ payload: { ...body, threadId, content, mentions },
1819
+ content,
1820
+ fileParts,
1821
+ mentions,
1822
+ turnId
1823
+ };
1824
+ }
1825
+ function userPartsWithFiles(userParts, fileParts, mentions) {
1826
+ return toChatMessageParts([
1827
+ ...userParts,
1828
+ ...fileParts.map((part) => ({ ...part })),
1829
+ ...mentions.map((mention) => ({ ...mentionInputToPart(mention) }))
1830
+ ]);
1831
+ }
1832
+
1833
+ // src/chat-routes/agent-producers.ts
1834
+ async function addressAgents(input) {
1835
+ const addressed = agentMentionsOf(input.mentions);
1836
+ if (addressed.length === 0) return input.produceArgs;
1837
+ const { agents } = input.options;
1838
+ if (!agents) {
1839
+ return errorResponse(new ChatTurnInputError("This chat does not address agents by mention", 400, "agents_unsupported"));
1840
+ }
1841
+ const targets = await input.trace.measure("admission.agents", "admission", () => agents.resolve({ identity: input.identity, context: input.context, mentions: addressed }));
1842
+ const byId = new Map(targets.map((target) => [target.id, target]));
1843
+ const unknown = addressed.find((mention) => !byId.has(mention.agentId));
1844
+ if (unknown) return errorResponse(new ChatTurnInputError(`Unknown agent @${unknown.handle}`, 400, "unknown_agent"));
1845
+ return { ...input.produceArgs, agents: addressed.map((mention) => byId.get(mention.agentId)) };
1846
+ }
1847
+ var SPEAKER_EVENT = "speaker";
1848
+ function speakerPart(agent) {
1849
+ return { type: "speaker", id: agent.id, name: agent.name, handle: agent.handle };
1850
+ }
1851
+ async function composeAgentProducers(args, produce) {
1852
+ const agents = args.agents ?? [];
1853
+ if (agents.length === 0) throw new Error("composeAgentProducers needs at least one responder");
1854
+ const producers = [];
1855
+ const cleanups = [];
1856
+ const stream = (async function* () {
1857
+ for (const agent of agents) {
1858
+ if (args.admissionSignal?.aborted) return;
1859
+ const producer = await produce({ ...args, agent });
1860
+ producers.push({ agent, producer });
1861
+ if (producer.cleanup) cleanups.push(producer.cleanup);
1862
+ yield { type: SPEAKER_EVENT, id: agent.id, name: agent.name, handle: agent.handle };
1863
+ for await (const event of producer.stream) yield event;
1864
+ }
1865
+ })();
1866
+ const partsOf = (entry, read) => {
1867
+ const own = entry.producer[read]?.();
1868
+ const text = entry.producer.finalText();
1869
+ const parts = own ?? (text ? [{ type: "text", text }] : []);
1870
+ return [speakerPart(entry.agent), ...parts];
1871
+ };
1872
+ const last = () => producers[producers.length - 1]?.producer;
1873
+ return {
1874
+ stream,
1875
+ finalText: () => producers.map(({ producer }) => producer.finalText()).filter((text) => text.trim() !== "").join("\n\n"),
1876
+ assistantParts: () => producers.flatMap((entry) => partsOf(entry, "assistantParts")),
1877
+ draftParts: () => producers.flatMap((entry) => partsOf(entry, "draftParts")),
1878
+ usage: () => producers.reduce((sum, { producer }) => {
1879
+ const usage = producer.usage?.() ?? {};
1880
+ for (const [key, value] of Object.entries(usage)) {
1881
+ if (typeof value === "number") sum[key] = (sum[key] ?? 0) + value;
1882
+ }
1883
+ return sum;
1884
+ }, {}),
1885
+ terminalObserved: () => producers.every(({ producer }) => producer.terminalObserved?.() ?? true),
1886
+ get model() {
1887
+ return last()?.model;
1888
+ },
1889
+ modelFailover: () => last()?.modelFailover?.(),
1890
+ modelAttribution: () => last()?.modelAttribution?.(),
1891
+ cleanup: (async () => {
1892
+ await Promise.all(cleanups);
1893
+ })()
1894
+ };
1895
+ }
1896
+
1777
1897
  // src/chat-routes/turn-route-contracts.ts
1778
1898
  var INTENT_LINE_TIMEOUT_MS = 1500;
1779
1899
  var INTENT_LINE_HISTORY_MESSAGES = 6;
@@ -1974,7 +2094,7 @@ async function buildDispatchParts(input) {
1974
2094
  const readMention = input.readSandboxMention ?? readSandboxMention;
1975
2095
  const resolveMentionPath = input.resolveMentionPath ?? input.resolveAttachmentPath;
1976
2096
  const forcePath = input.forcePath ?? false;
1977
- const mentions = input.mentions ?? [];
2097
+ const mentions = (input.mentions ?? []).filter((mention) => mention.mentionKind !== "agent");
1978
2098
  const requestMaxBytes = input.requestMaxBytes ?? DISPATCH_REQUEST_MAX_BYTES;
1979
2099
  const structuralReserveBytes = input.structuralReserveBytes ?? DISPATCH_STRUCTURAL_RESERVE_BYTES;
1980
2100
  const maxParts = input.maxParts ?? DISPATCH_MAX_PARTS;
@@ -2148,61 +2268,6 @@ function startTurnPrefetch(prefetch, input) {
2148
2268
  };
2149
2269
  }
2150
2270
 
2151
- // src/chat-routes/turn-admission.ts
2152
- function errorResponse(err) {
2153
- return Response.json({ code: err.code, error: err.message }, { status: err.status });
2154
- }
2155
- function admissionServerTiming(trace) {
2156
- const now = Date.now();
2157
- const steps = trace.spans(now).filter((span) => span.kind === "admission").sort((a, b) => a.startMs - b.startMs).map((span) => ({ name: span.name, durMs: span.endMs - span.startMs }));
2158
- return formatServerTiming([{ name: "admission", durMs: now - trace.startedAt }, ...steps]);
2159
- }
2160
- async function namedModelRefusal(policy, payload, trace) {
2161
- const namedModel = typeof payload.model === "string" ? payload.model.trim() : "";
2162
- if (!policy || !namedModel) return null;
2163
- const decision = await trace.measure("admission.model_policy", "admission", () => checkModelPolicy(namedModel, policy.catalog, policy.filter, policy.context));
2164
- return decision.allowed ? null : Response.json({ code: "model_policy_denied", error: decision.reason }, { status: 403 });
2165
- }
2166
- function validateTurnBody(body) {
2167
- const threadId = typeof body.threadId === "string" ? body.threadId.trim() : "";
2168
- if (!threadId) throw new ChatTurnInputError("Missing threadId");
2169
- const rawContent = body.content ?? body.message ?? "";
2170
- if (typeof rawContent !== "string") throw new ChatTurnInputError("content must be a string");
2171
- const content = rawContent.trim();
2172
- const fileParts = parseChatTurnParts(body.parts);
2173
- const mentions = parseFileMentions(body.mentions);
2174
- const hasAttachments = Array.isArray(body.attachments) && body.attachments.length > 0;
2175
- if (!content && fileParts.length === 0 && mentions.length === 0 && !hasAttachments) {
2176
- throw new ChatTurnInputError("Missing content (send text, parts, mentions, attachments, or any combination)");
2177
- }
2178
- assertPromptPartsWithinCap(fileParts);
2179
- let turnId;
2180
- try {
2181
- turnId = normalizeClientTurnId(body.turnId);
2182
- } catch (err) {
2183
- throw new ChatTurnInputError(err instanceof Error ? err.message : "Invalid turnId");
2184
- }
2185
- const retryAttemptId = body.retryAttemptId;
2186
- if (retryAttemptId !== void 0 && (typeof retryAttemptId !== "string" || !/^[A-Za-z0-9_-]{1,64}$/.test(retryAttemptId) || !turnId)) throw new ChatTurnInputError("retryAttemptId requires turnId and 1\u201364 letters, digits, underscores, or hyphens");
2187
- return {
2188
- // The VALIDATED, deduped mention list replaces the raw one on the payload,
2189
- // so every downstream seam (`authorize`, `contextGate`, `beforeTurn`,
2190
- // `produce`) reads checked paths and never the request's own.
2191
- payload: { ...body, threadId, content, mentions },
2192
- content,
2193
- fileParts,
2194
- mentions,
2195
- turnId
2196
- };
2197
- }
2198
- function userPartsWithFiles(userParts, fileParts, mentions) {
2199
- return toChatMessageParts([
2200
- ...userParts,
2201
- ...fileParts.map((part) => ({ ...part })),
2202
- ...mentions.map((mention) => ({ ...mentionInputToPart(mention) }))
2203
- ]);
2204
- }
2205
-
2206
2271
  // src/chat-routes/turn-execution.ts
2207
2272
  import { deriveExecutionId, handleChatTurn } from "@tangle-network/agent-runtime/durable";
2208
2273
 
@@ -2694,8 +2759,11 @@ async function runAdmittedTurn({
2694
2759
  ...admitted.prefetched ? { prefetched: admitted.prefetched } : {},
2695
2760
  ...ctx?.executionLimits ? { executionLimits: ctx.executionLimits } : {}
2696
2761
  };
2762
+ const addressed = await addressAgents({ options, mentions, identity, context, produceArgs, trace });
2763
+ if (addressed instanceof Response) return addressed;
2764
+ produceArgs = addressed;
2697
2765
  const selected = selectTurnProducer(options.produce, produceArgs);
2698
- const dispatched = dispatchFirstFor(selected, produceArgs, trace);
2766
+ const dispatched = produceArgs.agents ? void 0 : dispatchFirstFor(selected, produceArgs, trace);
2699
2767
  if (dispatched) early.add(dispatched.refuse);
2700
2768
  const turnLock = options.turnLock;
2701
2769
  if (turnLock) {
@@ -3085,7 +3153,7 @@ function createTurnEngine(identity, ctx, log, state, dispatched, produceArgs, tr
3085
3153
  produce: () => ({
3086
3154
  stream: (async function* () {
3087
3155
  const producerStream = async function* () {
3088
- const started = dispatched ? dispatched.take(produceArgs) : trace.measure("admission.produce", "admission", () => produce(produceArgs));
3156
+ const started = dispatched ? dispatched.take(produceArgs) : produceArgs.agents ? trace.measure("admission.produce", "admission", () => composeAgentProducers(produceArgs, produce)) : trace.measure("admission.produce", "admission", () => produce(produceArgs));
3089
3157
  if (!dispatched) {
3090
3158
  const cleanup = started.then((producer) => producer.cleanup, () => void 0);
3091
3159
  ctx?.waitUntil?.(cleanup);
@@ -3922,6 +3990,9 @@ export {
3922
3990
  withProducerStream,
3923
3991
  cancelChatTurn,
3924
3992
  observeTurnCancellation,
3993
+ SPEAKER_EVENT,
3994
+ speakerPart,
3995
+ composeAgentProducers,
3925
3996
  INTENT_LINE_TIMEOUT_MS,
3926
3997
  INTENT_LINE_HISTORY_MESSAGES,
3927
3998
  INTENT_LINE_MAX_CHARS,
@@ -3936,4 +4007,4 @@ export {
3936
4007
  createChatTurnRoutes,
3937
4008
  streamChatRouteAsSandboxEvents
3938
4009
  };
3939
- //# sourceMappingURL=chunk-KFO5R4SN.js.map
4010
+ //# sourceMappingURL=chunk-RVC7EHJI.js.map