@genesislcap/ai-assistant 15.21.0 → 15.21.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.
Files changed (29) hide show
  1. package/dist/ai-assistant.api.json +135 -1
  2. package/dist/ai-assistant.d.ts +152 -0
  3. package/dist/chat-driver.cjs +281 -81
  4. package/dist/chat-driver.cjs.map +2 -2
  5. package/dist/chat-driver.mjs +277 -81
  6. package/dist/chat-driver.mjs.map +2 -2
  7. package/dist/custom-elements.json +175 -8
  8. package/dist/dts/components/chat-driver/chat-driver.d.ts +39 -0
  9. package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
  10. package/dist/dts/components/orchestrating-driver/index.d.ts +2 -1
  11. package/dist/dts/components/orchestrating-driver/index.d.ts.map +1 -1
  12. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +101 -0
  13. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
  14. package/dist/dts/config/fallback-agents.d.ts +7 -0
  15. package/dist/dts/config/fallback-agents.d.ts.map +1 -1
  16. package/dist/dts/state/debug-event-log.d.ts +1 -1
  17. package/dist/dts/state/debug-event-log.d.ts.map +1 -1
  18. package/dist/dts/utils/context-tokens.d.ts +25 -3
  19. package/dist/dts/utils/context-tokens.d.ts.map +1 -1
  20. package/dist/dts/utils/history-transform.d.ts +23 -3
  21. package/dist/dts/utils/history-transform.d.ts.map +1 -1
  22. package/dist/esm/components/chat-driver/chat-driver.js +72 -56
  23. package/dist/esm/components/orchestrating-driver/index.js +1 -1
  24. package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +266 -36
  25. package/dist/esm/config/fallback-agents.js +12 -1
  26. package/dist/esm/state/debug-event-log.js +7 -2
  27. package/dist/esm/utils/context-tokens.js +27 -3
  28. package/dist/esm/utils/history-transform.js +54 -5
  29. package/package.json +16 -16
@@ -22,15 +22,64 @@ function maskToolPayload(msg) {
22
22
  return msg;
23
23
  }
24
24
  /**
25
- * Prepares history for the LLM only: masks tool call args and results from other
26
- * agents so the active specialist is not confused by tools it does not have.
27
- * Canonical history in `ChatDriver` stays unmasked for UI and logging.
25
+ * Render another agent's tool call as prose: the narration it came with, if any, then the tool
26
+ * names. Keeps the fact that work happened without pretending the active agent can act on it.
27
+ */
28
+ function foreignToolCallText(msg) {
29
+ var _a;
30
+ const names = ((_a = msg.toolCalls) !== null && _a !== void 0 ? _a : []).map((tc) => tc.name).join(', ');
31
+ const trace = names ? `[Earlier tool call: ${names}]` : '';
32
+ return msg.content && trace ? `${msg.content}\n${trace}` : msg.content || trace;
33
+ }
34
+ /**
35
+ * Prepares history for the LLM only: another agent's tool traffic becomes prose, so the active
36
+ * specialist sees THAT work happened without being handed calls it cannot make or results it
37
+ * cannot use. Canonical history in `ChatDriver` stays untouched for UI and logging.
38
+ *
39
+ * Why prose rather than masked-in-place blocks (GENC-1573). Masking used to clear a foreign
40
+ * call's `args` and stub its result's content, but leave both as real `tool_use`/`tool_result`
41
+ * blocks on the wire. That put a large, wholly uninformative structure in front of every routed
42
+ * agent — in the measured session the fallback's requests carried 389 `tool_use` and 313
43
+ * `tool_result` blocks, every one of them another agent's, the args emptied to `{}` and the
44
+ * results reduced to the same placeholder sentence repeated 313 times. It cost tokens on every
45
+ * turn, told the model nothing, and asked a tool-less agent to make sense of a tool transcript.
46
+ *
47
+ * A foreign result is dropped rather than rendered: its content was already replaced by a
48
+ * placeholder, so the only thing left to say is "a result came back", which the call line
49
+ * already implies. It is dropped via `excludeFromProvider` rather than by filtering the array,
50
+ * so index-aligned callers and the token estimator see the same list they always did.
51
+ *
52
+ * Pairs are flattened together, keyed on tool-call id rather than per message, because a
53
+ * half-flattened pair is a rejected request: an orphaned `tool_result` has no `tool_use` to
54
+ * answer. Both halves of a pair normally carry the same `agentName` — `appendToHistory` stamps
55
+ * the active agent on the call and its result alike — but a session restored from before that
56
+ * stamping, or appended with no agent active, can hold one half unattributed, and per-message
57
+ * flattening would then split it.
28
58
  */
29
59
  export function transformHistoryForAgent(history, agentName) {
60
+ var _a;
61
+ const isForeign = (msg) => !!msg.agentName && msg.agentName !== agentName;
62
+ // Pass 1: every tool-call id on either side of a foreign pair.
63
+ const foreignCallIds = new Set();
64
+ for (const msg of history) {
65
+ if (!isForeign(msg))
66
+ continue;
67
+ for (const tc of (_a = msg.toolCalls) !== null && _a !== void 0 ? _a : [])
68
+ foreignCallIds.add(tc.id);
69
+ if (msg.toolResult)
70
+ foreignCallIds.add(msg.toolResult.toolCallId);
71
+ }
72
+ // Pass 2: flatten both halves of anything the first pass touched, whatever its own attribution.
30
73
  return history.map((msg) => {
31
- if (!msg.agentName || msg.agentName === agentName)
74
+ var _a;
75
+ const pairIsForeign = ((_a = msg.toolCalls) !== null && _a !== void 0 ? _a : []).some((tc) => foreignCallIds.has(tc.id)) ||
76
+ (msg.toolResult ? foreignCallIds.has(msg.toolResult.toolCallId) : false);
77
+ if (!pairIsForeign)
32
78
  return msg;
33
- return maskToolPayload(msg);
79
+ if (msg.toolResult) {
80
+ return Object.assign(Object.assign({}, maskToolPayload(msg)), { excludeFromProvider: true });
81
+ }
82
+ return Object.assign(Object.assign({}, msg), { content: foreignToolCallText(msg), toolCalls: undefined });
34
83
  });
35
84
  }
36
85
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/ai-assistant",
3
3
  "description": "Genesis AI Assistant micro-frontend",
4
- "version": "15.21.0",
4
+ "version": "15.21.1",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/esm/index.js",
7
7
  "types": "dist/ai-assistant.d.ts",
@@ -74,26 +74,26 @@
74
74
  }
75
75
  },
76
76
  "devDependencies": {
77
- "@genesislcap/foundation-testing": "15.21.0",
78
- "@genesislcap/genx": "15.21.0",
79
- "@genesislcap/rollup-builder": "15.21.0",
80
- "@genesislcap/ts-builder": "15.21.0",
81
- "@genesislcap/uvu-playwright-builder": "15.21.0",
82
- "@genesislcap/vite-builder": "15.21.0",
83
- "@genesislcap/webpack-builder": "15.21.0",
77
+ "@genesislcap/foundation-testing": "15.21.1",
78
+ "@genesislcap/genx": "15.21.1",
79
+ "@genesislcap/rollup-builder": "15.21.1",
80
+ "@genesislcap/ts-builder": "15.21.1",
81
+ "@genesislcap/uvu-playwright-builder": "15.21.1",
82
+ "@genesislcap/vite-builder": "15.21.1",
83
+ "@genesislcap/webpack-builder": "15.21.1",
84
84
  "@types/dompurify": "^3.0.5",
85
85
  "@types/marked": "^5.0.2",
86
86
  "esbuild": "0.25.12"
87
87
  },
88
88
  "dependencies": {
89
- "@genesislcap/foundation-ai": "15.21.0",
90
- "@genesislcap/foundation-logger": "15.21.0",
91
- "@genesislcap/foundation-notifications": "15.21.0",
92
- "@genesislcap/foundation-redux": "15.21.0",
93
- "@genesislcap/foundation-ui": "15.21.0",
94
- "@genesislcap/foundation-utils": "15.21.0",
95
- "@genesislcap/rapid-design-system": "15.21.0",
96
- "@genesislcap/web-core": "15.21.0",
89
+ "@genesislcap/foundation-ai": "15.21.1",
90
+ "@genesislcap/foundation-logger": "15.21.1",
91
+ "@genesislcap/foundation-notifications": "15.21.1",
92
+ "@genesislcap/foundation-redux": "15.21.1",
93
+ "@genesislcap/foundation-ui": "15.21.1",
94
+ "@genesislcap/foundation-utils": "15.21.1",
95
+ "@genesislcap/rapid-design-system": "15.21.1",
96
+ "@genesislcap/web-core": "15.21.1",
97
97
  "dompurify": "^3.3.1",
98
98
  "marked": "^17.0.3"
99
99
  },