@brainpilot/web 0.0.5 → 0.0.7

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 (58) hide show
  1. package/dist/assets/index-DWOsU22G.css +1 -0
  2. package/dist/assets/index-j3rGyO6m.js +445 -0
  3. package/dist/index.html +2 -2
  4. package/package.json +6 -3
  5. package/src/__tests__/agentsReducer.test.ts +67 -0
  6. package/src/__tests__/api.test.ts +118 -0
  7. package/src/__tests__/chatScrollBehavior.test.ts +48 -0
  8. package/src/__tests__/chatScrollMemory.test.ts +49 -0
  9. package/src/__tests__/demoConversation.test.ts +96 -0
  10. package/src/__tests__/demoReset.test.ts +24 -0
  11. package/src/__tests__/internalToolStrip.test.ts +108 -0
  12. package/src/__tests__/runningToast.test.ts +29 -0
  13. package/src/__tests__/tokenUsage.test.ts +48 -0
  14. package/src/__tests__/toolDisplay.test.ts +55 -0
  15. package/src/__tests__/traceReducer.test.ts +62 -0
  16. package/src/components/chat/MessageStream.tsx +104 -56
  17. package/src/components/chat/PromptComposer.tsx +120 -29
  18. package/src/components/chat/chatScrollMemory.ts +49 -0
  19. package/src/components/demo/DemoView.tsx +98 -29
  20. package/src/components/demo/TraceNodeModal.tsx +6 -2
  21. package/src/components/demo/demoBundle.ts +7 -2
  22. package/src/components/demo/demoReset.ts +16 -0
  23. package/src/components/session/AgentNetwork.tsx +68 -75
  24. package/src/components/session/AgentTraceViews.tsx +35 -70
  25. package/src/components/session/AnalyticsTab.tsx +58 -224
  26. package/src/components/session/TraceGraphView.tsx +36 -30
  27. package/src/components/session/TraceNodeDetail.tsx +61 -24
  28. package/src/components/session/agentNetworkShared.ts +10 -0
  29. package/src/components/session/traceLayout.ts +32 -0
  30. package/src/components/settings/SettingsDialog.tsx +19 -1
  31. package/src/components/shell/DesktopShell.tsx +72 -17
  32. package/src/components/sidebar/SessionList.tsx +127 -0
  33. package/src/components/sidebar/Sidebar.tsx +94 -98
  34. package/src/contexts/SSEContext.tsx +90 -1
  35. package/src/contexts/SessionContext.tsx +397 -43
  36. package/src/contexts/agentsReducer.ts +49 -0
  37. package/src/contexts/messageGroups.ts +56 -0
  38. package/src/contexts/messageReducer.ts +4 -0
  39. package/src/contexts/runningToast.ts +33 -0
  40. package/src/contexts/traceReducer.ts +62 -0
  41. package/src/contexts/turnTimer.test.ts +97 -0
  42. package/src/contexts/turnTimer.ts +108 -0
  43. package/src/contexts/useTurnTimer.ts +104 -0
  44. package/src/contracts/backend.ts +53 -2
  45. package/src/i18n/messages/analytics.ts +16 -6
  46. package/src/i18n/messages/chat.ts +26 -4
  47. package/src/i18n/messages/contexts.ts +2 -0
  48. package/src/i18n/messages/network.ts +13 -9
  49. package/src/i18n/messages/profile.ts +4 -0
  50. package/src/i18n/messages/settings.ts +4 -0
  51. package/src/i18n/messages/shell.ts +2 -0
  52. package/src/i18n/messages/trace.ts +69 -17
  53. package/src/mocks/backend.ts +7 -0
  54. package/src/styles/global.css +289 -70
  55. package/src/utils/api.ts +105 -8
  56. package/src/utils/toolDisplay.ts +74 -0
  57. package/dist/assets/index-C-8G4D4j.js +0 -448
  58. package/dist/assets/index-C501m5OS.css +0 -1
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Presentation helpers for the tool-activity block (#84).
3
+ *
4
+ * The runtime namespaces MCP tools as `mcp__<server>__<tool>` (see
5
+ * packages/runtime/src/mcp-bridge.ts) to avoid collisions, and tool
6
+ * args/results arrive as already-encoded JSON strings. Surfacing those raw in
7
+ * the chat UI reads like debug output:
8
+ * - `mcp__bp_skills__skills_tool` instead of a friendly name, and
9
+ * - payloads double-encoded into `\"key\": \"value\"` walls of backslashes.
10
+ *
11
+ * These helpers are display-only — the raw name/payload stays available for
12
+ * copying and debugging; nothing here touches the wire protocol.
13
+ */
14
+
15
+ /**
16
+ * Friendly tool name. `mcp__<server>__<tool>` collapses to `<server> · <tool>`;
17
+ * any other name (built-in tools, already-friendly names) is returned as-is.
18
+ *
19
+ * The MCP prefix split is intentionally lenient: a server or tool segment may
20
+ * itself contain single underscores, so we split on the literal `mcp__` prefix
21
+ * and the FIRST `__` separator after the server name.
22
+ */
23
+ export function formatToolName(raw: string | undefined | null): string {
24
+ if (!raw) return "tool";
25
+ if (!raw.startsWith("mcp__")) return raw;
26
+ const rest = raw.slice("mcp__".length);
27
+ const sep = rest.indexOf("__");
28
+ if (sep <= 0 || sep >= rest.length - 2) {
29
+ // Malformed (no tool segment) — show the un-prefixed remainder rather than
30
+ // the raw mcp__ identifier.
31
+ return rest || raw;
32
+ }
33
+ const server = rest.slice(0, sep);
34
+ const tool = rest.slice(sep + 2);
35
+ return `${server} · ${tool}`;
36
+ }
37
+
38
+ /**
39
+ * Pretty-print a tool payload without double-escaping. Tool args/results are
40
+ * accumulated as JSON strings over TOOL_CALL_ARGS deltas; calling
41
+ * JSON.stringify on an already-stringified value yields a `\"`-littered wall.
42
+ *
43
+ * Strategy:
44
+ * - string that parses as JSON → parse, then pretty-print the value;
45
+ * - string that does NOT parse → return verbatim (plain text / partial);
46
+ * - anything else (object/etc.) → pretty-print directly.
47
+ *
48
+ * Returns "" for null/undefined so callers can skip empty <pre> blocks.
49
+ */
50
+ export function formatPayload(value: unknown): string {
51
+ if (value === undefined || value === null) return "";
52
+ if (typeof value === "string") {
53
+ const trimmed = value.trim();
54
+ if (trimmed === "") return "";
55
+ // Only attempt a parse when it looks like JSON — avoids turning a bare
56
+ // number/quoted word into a reformatted value users didn't write.
57
+ const looksJson =
58
+ (trimmed.startsWith("{") && trimmed.endsWith("}")) ||
59
+ (trimmed.startsWith("[") && trimmed.endsWith("]"));
60
+ if (looksJson) {
61
+ try {
62
+ return JSON.stringify(JSON.parse(trimmed), null, 2);
63
+ } catch {
64
+ return value;
65
+ }
66
+ }
67
+ return value;
68
+ }
69
+ try {
70
+ return JSON.stringify(value, null, 2);
71
+ } catch {
72
+ return String(value);
73
+ }
74
+ }