@nxisai/agent-harness 0.2.0

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 (126) hide show
  1. package/README.md +434 -0
  2. package/dist/a2ui/cards.d.ts +55 -0
  3. package/dist/a2ui/cards.d.ts.map +1 -0
  4. package/dist/a2ui/cards.js +133 -0
  5. package/dist/a2ui/cards.js.map +1 -0
  6. package/dist/a2ui/emit.d.ts +33 -0
  7. package/dist/a2ui/emit.d.ts.map +1 -0
  8. package/dist/a2ui/emit.js +116 -0
  9. package/dist/a2ui/emit.js.map +1 -0
  10. package/dist/a2ui/form.d.ts +20 -0
  11. package/dist/a2ui/form.d.ts.map +1 -0
  12. package/dist/a2ui/form.js +92 -0
  13. package/dist/a2ui/form.js.map +1 -0
  14. package/dist/a2ui/host.d.ts +34 -0
  15. package/dist/a2ui/host.d.ts.map +1 -0
  16. package/dist/a2ui/host.js +47 -0
  17. package/dist/a2ui/host.js.map +1 -0
  18. package/dist/a2ui/index.d.ts +23 -0
  19. package/dist/a2ui/index.d.ts.map +1 -0
  20. package/dist/a2ui/index.js +20 -0
  21. package/dist/a2ui/index.js.map +1 -0
  22. package/dist/a2ui/stepper.d.ts +26 -0
  23. package/dist/a2ui/stepper.d.ts.map +1 -0
  24. package/dist/a2ui/stepper.js +162 -0
  25. package/dist/a2ui/stepper.js.map +1 -0
  26. package/dist/a2ui/theme.d.ts +21 -0
  27. package/dist/a2ui/theme.d.ts.map +1 -0
  28. package/dist/a2ui/theme.js +134 -0
  29. package/dist/a2ui/theme.js.map +1 -0
  30. package/dist/a2ui/to-v09.d.ts +31 -0
  31. package/dist/a2ui/to-v09.d.ts.map +1 -0
  32. package/dist/a2ui/to-v09.js +104 -0
  33. package/dist/a2ui/to-v09.js.map +1 -0
  34. package/dist/engine.d.ts +209 -0
  35. package/dist/engine.d.ts.map +1 -0
  36. package/dist/engine.js +505 -0
  37. package/dist/engine.js.map +1 -0
  38. package/dist/harness/harness.d.ts +284 -0
  39. package/dist/harness/harness.d.ts.map +1 -0
  40. package/dist/harness/harness.js +568 -0
  41. package/dist/harness/harness.js.map +1 -0
  42. package/dist/harness/plan.d.ts +32 -0
  43. package/dist/harness/plan.d.ts.map +1 -0
  44. package/dist/harness/plan.js +68 -0
  45. package/dist/harness/plan.js.map +1 -0
  46. package/dist/harness/policy.d.ts +49 -0
  47. package/dist/harness/policy.d.ts.map +1 -0
  48. package/dist/harness/policy.js +34 -0
  49. package/dist/harness/policy.js.map +1 -0
  50. package/dist/harness/renderer.d.ts +163 -0
  51. package/dist/harness/renderer.d.ts.map +1 -0
  52. package/dist/harness/renderer.js +12 -0
  53. package/dist/harness/renderer.js.map +1 -0
  54. package/dist/harness/router/coordinator.d.ts +120 -0
  55. package/dist/harness/router/coordinator.d.ts.map +1 -0
  56. package/dist/harness/router/coordinator.js +145 -0
  57. package/dist/harness/router/coordinator.js.map +1 -0
  58. package/dist/harness/router/rules.d.ts +48 -0
  59. package/dist/harness/router/rules.d.ts.map +1 -0
  60. package/dist/harness/router/rules.js +38 -0
  61. package/dist/harness/router/rules.js.map +1 -0
  62. package/dist/harness/slots.d.ts +73 -0
  63. package/dist/harness/slots.d.ts.map +1 -0
  64. package/dist/harness/slots.js +68 -0
  65. package/dist/harness/slots.js.map +1 -0
  66. package/dist/harness/tools/bridge.d.ts +71 -0
  67. package/dist/harness/tools/bridge.d.ts.map +1 -0
  68. package/dist/harness/tools/bridge.js +271 -0
  69. package/dist/harness/tools/bridge.js.map +1 -0
  70. package/dist/harness/tools/client.d.ts +11 -0
  71. package/dist/harness/tools/client.d.ts.map +1 -0
  72. package/dist/harness/tools/client.js +21 -0
  73. package/dist/harness/tools/client.js.map +1 -0
  74. package/dist/harness/tools/discovery.d.ts +13 -0
  75. package/dist/harness/tools/discovery.d.ts.map +1 -0
  76. package/dist/harness/tools/discovery.js +43 -0
  77. package/dist/harness/tools/discovery.js.map +1 -0
  78. package/dist/harness/tools/local-context.d.ts +38 -0
  79. package/dist/harness/tools/local-context.d.ts.map +1 -0
  80. package/dist/harness/tools/local-context.js +55 -0
  81. package/dist/harness/tools/local-context.js.map +1 -0
  82. package/dist/harness/tools/schema.d.ts +52 -0
  83. package/dist/harness/tools/schema.d.ts.map +1 -0
  84. package/dist/harness/tools/schema.js +175 -0
  85. package/dist/harness/tools/schema.js.map +1 -0
  86. package/dist/harness/tools/source.d.ts +65 -0
  87. package/dist/harness/tools/source.d.ts.map +1 -0
  88. package/dist/harness/tools/source.js +89 -0
  89. package/dist/harness/tools/source.js.map +1 -0
  90. package/dist/harness/tools/webmcp.d.ts +50 -0
  91. package/dist/harness/tools/webmcp.d.ts.map +1 -0
  92. package/dist/harness/tools/webmcp.js +114 -0
  93. package/dist/harness/tools/webmcp.js.map +1 -0
  94. package/dist/index.d.ts +49 -0
  95. package/dist/index.d.ts.map +1 -0
  96. package/dist/index.js +38 -0
  97. package/dist/index.js.map +1 -0
  98. package/dist/providers/types.d.ts +123 -0
  99. package/dist/providers/types.d.ts.map +1 -0
  100. package/dist/providers/types.js +2 -0
  101. package/dist/providers/types.js.map +1 -0
  102. package/dist/types.d.ts +223 -0
  103. package/dist/types.d.ts.map +1 -0
  104. package/dist/types.js +8 -0
  105. package/dist/types.js.map +1 -0
  106. package/dist/ui/agent-fullscreen.d.ts +41 -0
  107. package/dist/ui/agent-fullscreen.d.ts.map +1 -0
  108. package/dist/ui/agent-fullscreen.js +2821 -0
  109. package/dist/ui/agent-fullscreen.js.map +1 -0
  110. package/dist/ui/config.d.ts +88 -0
  111. package/dist/ui/config.d.ts.map +1 -0
  112. package/dist/ui/config.js +96 -0
  113. package/dist/ui/config.js.map +1 -0
  114. package/dist/ui/index.d.ts +22 -0
  115. package/dist/ui/index.d.ts.map +1 -0
  116. package/dist/ui/index.js +19 -0
  117. package/dist/ui/index.js.map +1 -0
  118. package/dist/ui/tailwind.generated.d.ts +2 -0
  119. package/dist/ui/tailwind.generated.d.ts.map +1 -0
  120. package/dist/ui/tailwind.generated.js +3 -0
  121. package/dist/ui/tailwind.generated.js.map +1 -0
  122. package/dist/webmcp-contract.d.ts +57 -0
  123. package/dist/webmcp-contract.d.ts.map +1 -0
  124. package/dist/webmcp-contract.js +11 -0
  125. package/dist/webmcp-contract.js.map +1 -0
  126. package/package.json +39 -0
package/dist/engine.js ADDED
@@ -0,0 +1,505 @@
1
+ import { toolSchema } from './harness/tools/schema.js';
2
+ // ── Config ───────────────────────────────────────────────────────────────────
3
+ export const TRANSFORMERS_CDN = 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.2.0';
4
+ /** The Hugging Face repository the weights are loaded from. */
5
+ export const MODEL_ID = 'onnx-community/gemma-4-E2B-it-ONNX';
6
+ /** Origin to load weights from. Empty serves them from the Hugging Face Hub. */
7
+ export const MODEL_HOST = '';
8
+ /** Path template applied under {@link MODEL_HOST}. `{model}` is substituted. */
9
+ export const MODEL_PATH_TEMPLATE = '{model}/';
10
+ /** Generations allowed per goal. One is enough unless the model must retry. */
11
+ export const MAX_STEPS = 3;
12
+ /** Default token ceiling for one generation. */
13
+ export const MAX_NEW_TOKENS = 512;
14
+ /** How long {@link WebMcpTools.waitForTools} waits for tools to register. */
15
+ export const TOOLS_TIMEOUT_MS = 20000;
16
+ /**
17
+ * The default instructions, used when no `systemPrompt` is supplied.
18
+ *
19
+ * Directs the model to call a tool as soon as it knows which one applies, with
20
+ * whatever fields it has, because the harness collects the rest.
21
+ */
22
+ export const SYSTEM_PROMPT = [
23
+ 'You are an in-page assistant embedded in a web form.',
24
+ "Use the available tools to complete the user's request by filling and submitting the form.",
25
+ "Infer each argument from the user's message and the tool's schema.",
26
+ 'Use parameter names EXACTLY as defined in the tool schema — do not rename, translate, or add suffixes like "_needs".',
27
+ 'Only include fields the user provided or that are clearly implied; never invent emails, names, or dates.',
28
+ 'Fields marked "required" in the schema must always be provided — name and email are always required.',
29
+ // The harness collects missing fields itself, as a form or a stepper, which
30
+ // requires the model to hand over a partial call rather than asking in prose.
31
+ 'Call the tool as soon as you know which one is right, even if some required fields are still unknown — include the fields you do have and simply omit the rest.',
32
+ 'Never ask the user to supply a missing field in prose. Leave it out of the call; the page will collect it.',
33
+ 'Call at most one tool per turn.',
34
+ ].join(' ');
35
+ /**
36
+ * Storage key marking a load that started but never finished.
37
+ *
38
+ * Written before the first byte and cleared on success or on a caught error, so
39
+ * a value left behind means the renderer was terminated mid-load. That can
40
+ * happen when the browser kills the process over a Cache Storage failure on an
41
+ * entry this size, which runs no catch block, no `onerror` and no `unload`
42
+ * handler. Persisting the attempt is what lets the next load detect it and
43
+ * retry without the browser cache.
44
+ */
45
+ const LOAD_GUARD_KEY = 'nxis-agent-load-guard';
46
+ /** Where the attribution badge points. */
47
+ export const NXIS_SITE_URL = 'https://nxis.ai';
48
+ // ── Brand and icons ──────────────────────────────────────────────────────────
49
+ // Inline SVG using `currentColor`, so icons inherit the surrounding theme.
50
+ export const NXIS_LOGO_SVG = `<svg viewBox="0 0 39.6 30.4" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
51
+ <defs>
52
+ <radialGradient id="nx-g1" cx="20.65" cy="-40.83" fx="20.65" fy="-40.83" r="14.12" gradientTransform="translate(0 -25.62) scale(1 -1)" gradientUnits="userSpaceOnUse">
53
+ <stop offset="0" stop-color="#3f9cf8"/><stop offset=".22" stop-color="#3891f6"/><stop offset=".59" stop-color="#2675f3"/><stop offset=".79" stop-color="#1c64f2"/>
54
+ </radialGradient>
55
+ <radialGradient id="nx-g2" cx="8.54" cy="485.55" fx="8.54" fy="485.55" r="11.08" gradientTransform="translate(0 -294)" href="#nx-g1"/>
56
+ <radialGradient id="nx-g3" cx="31.03" cy="479.6" fx="31.03" fy="479.6" r="10.02" gradientTransform="translate(0 -294)" href="#nx-g1"/>
57
+ </defs>
58
+ <path fill="url(#nx-g1)" d="M33.65.1c-1,1.7-1.9,3.2-2.7,4.7-4.8,8.3-9.6,16.6-14.4,24.9-.3.5-.5.6-1.1.6h-7.8c.2-.2.2-.4.3-.6C13.55,20,19.15,10.3,24.75.6c.2-.4.5-.6,1-.6h7.1c.3.1.4.1.8.1h0Z"/>
59
+ <path fill="url(#nx-g2)" d="M17.15.1c-1.2,2.1-2.3,4-3.5,6-1.7,2.9-3.3,5.8-5,8.6-.2.4-.3.7,0,1.2.6.9,1.1,1.8,1.6,2.7.1.2.2.5.1.6-1.3,2.3-2.7,4.7-4.1,7.1-.2-.3-.3-.4-.4-.6-1.9-3.3-3.8-6.6-5.7-9.8-.2-.4-.2-.7,0-1.1C2.85,10.1,5.55,5.4,8.25.7c.3-.4.6-.6,1.1-.6C11.85.1,14.45,0,17.15.1h0Z"/>
60
+ <path fill="url(#nx-g3)" d="M22.45,30.3c4.4-7.6,8.7-15,13-22.5.1.2.2.3.3.5,1.2,2.1,2.4,4.2,3.7,6.3.2.4.2.7,0,1-2.7,4.7-5.5,9.4-8.2,14.2-.2.4-.5.6-1,.6-2.5-.1-5.1,0-7.8-.1h0Z"/>
61
+ </svg>`;
62
+ /** Heroicon `check-circle`, for a success state. */
63
+ export const ICON_CHECK = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"/></svg>';
64
+ /** Heroicon `exclamation-triangle`, for an error state. */
65
+ export const ICON_WARN = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z"/></svg>';
66
+ /** Heroicon `arrow-long-right`, for send and submit controls. */
67
+ export const ICON_ARROW = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M13.5 4.5 21 12m0 0-7.5 7.5M21 12H3"/></svg>';
68
+ /** Heroicon `cog-6-tooth`, for settings. */
69
+ export const ICON_GEAR = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.24-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281Z"/><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"/></svg>';
70
+ /** Heroicon `plus`, for a new conversation. */
71
+ export const ICON_PLUS = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15"/></svg>';
72
+ /** Heroicon `bars-3`, for the conversation drawer. */
73
+ export const ICON_MENU = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.8" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5M3.75 17.25h16.5"/></svg>';
74
+ // Heroicons v2, outline 24. Inlined because the element renders into a shadow
75
+ // root as a single file, where an icon font or sprite sheet would be a second
76
+ // network request.
77
+ /** Heroicon `stop`, shown on the send button while a turn can be stopped. */
78
+ export const ICON_STOP = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.8" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M5.25 7.5A2.25 2.25 0 0 1 7.5 5.25h9a2.25 2.25 0 0 1 2.25 2.25v9a2.25 2.25 0 0 1-2.25 2.25h-9a2.25 2.25 0 0 1-2.25-2.25v-9Z"/></svg>';
79
+ /** Heroicon `clipboard-document`, for copying a message. */
80
+ export const ICON_COPY = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M15.666 3.888A2.25 2.25 0 0 0 13.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 0 1-.75.75H9a.75.75 0 0 1-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2.25 2.25 0 0 1-2.25 2.25H6.75A2.25 2.25 0 0 1 4.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 0 1 1.927-.184"/></svg>';
81
+ /** Heroicon `pencil-square`, for editing a message. */
82
+ export const ICON_PENCIL = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M16.862 4.487l1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10"/></svg>';
83
+ /** Heroicon `arrow-path`, for sending a message again. */
84
+ export const ICON_REDO = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99"/></svg>';
85
+ /** Heroicon `check`, the confirmation shown after a copy. */
86
+ export const ICON_CHECK_MARK = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"/></svg>';
87
+ /** Heroicon `trash`, for deleting a conversation. */
88
+ export const ICON_TRASH = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0"/></svg>';
89
+ // ── Text helpers ─────────────────────────────────────────────────────────────
90
+ export function humanize(s) {
91
+ return String(s).replace(/[_-]+/g, ' ').trim();
92
+ }
93
+ /** Lower-case the first character, for a name used mid-sentence. */
94
+ export function lcFirst(s) {
95
+ return s ? s.charAt(0).toLowerCase() + s.slice(1) : s;
96
+ }
97
+ /** Escape `&`, `<`, `>` and `"` for interpolation into markup. */
98
+ export function escapeHtml(s) {
99
+ return String(s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c]);
100
+ }
101
+ // ── Gemma 4 tool-call parsing ────────────────────────────────────────────────
102
+ // Gemma 4 emits: <|tool_call>call:NAME{param:<|"|>string<|"|>,num:42}<tool_call|>
103
+ /**
104
+ * Matches a tool call in Gemma's output.
105
+ *
106
+ * The name class allows `-` and `.`, which appear in tool names generated from
107
+ * a page's Schema.org actions (`quote-form`, `booking-form`). A narrower class
108
+ * both fails to parse the call and fails to strip it, leaving the raw marker
109
+ * visible as if it were the reply.
110
+ */
111
+ const TOOL_CALL_RE = /<\|tool_call>\s*call:([A-Za-z0-9_.\-]+)\s*\{([\s\S]*?)\}\s*<tool_call\|>/;
112
+ const STR_DELIM = '<|"|>';
113
+ function coerce(raw) {
114
+ const v = raw.trim();
115
+ if (v === 'true')
116
+ return true;
117
+ if (v === 'false')
118
+ return false;
119
+ if (v === 'null')
120
+ return null;
121
+ if (/^-?\d+(\.\d+)?$/.test(v))
122
+ return Number(v);
123
+ return v.replace(/^["']|["']$/g, '');
124
+ }
125
+ function parseArgs(body) {
126
+ const args = {};
127
+ const s = body.trim();
128
+ let i = 0;
129
+ while (i < s.length) {
130
+ while (i < s.length && (s[i] === ',' || s[i] === ' ' || s[i] === '\n'))
131
+ i++;
132
+ const colon = s.indexOf(':', i);
133
+ if (colon === -1)
134
+ break;
135
+ const key = s.slice(i, colon).trim().replace(/^["']|["']$/g, '');
136
+ i = colon + 1;
137
+ while (s[i] === ' ')
138
+ i++;
139
+ let value;
140
+ if (s.startsWith(STR_DELIM, i)) {
141
+ const start = i + STR_DELIM.length;
142
+ const end = s.indexOf(STR_DELIM, start);
143
+ value = s.slice(start, end === -1 ? s.length : end);
144
+ i = end === -1 ? s.length : end + STR_DELIM.length;
145
+ }
146
+ else {
147
+ let end = s.indexOf(',', i);
148
+ if (end === -1)
149
+ end = s.length;
150
+ value = coerce(s.slice(i, end));
151
+ i = end;
152
+ }
153
+ if (key)
154
+ args[key] = value;
155
+ }
156
+ return args;
157
+ }
158
+ /** Extract a tool call from model output, or null for a plain answer. */
159
+ export function parseToolCall(text) {
160
+ const m = text.match(TOOL_CALL_RE);
161
+ if (!m)
162
+ return null;
163
+ return { name: m[1], args: parseArgs(m[2]) };
164
+ }
165
+ /** Strip tool-call blocks and special tokens for human-readable display. */
166
+ export function stripMarkers(text) {
167
+ return text
168
+ .replace(new RegExp(TOOL_CALL_RE.source, 'g'), '') // whole tool-call blocks
169
+ .split(STR_DELIM)
170
+ .join('"') // string delimiter → quote (before token sweep)
171
+ .replace(/<\|[^>]*>|<[^|>]*\|>/g, '') // stray Gemma <|…> / <…|> tokens (turn, tool_call, …)
172
+ .replace(/<start_of_turn>\s*\w*/g, '') // start-of-turn marker + role word
173
+ .replace(/<end_of_turn>|<eos>|<bos>|<pad>/g, '') // remaining plain markers
174
+ // The piped form `<|start_of_turn>model` loses its marker to the sweep
175
+ // above, leaving the bare role word to be removed here.
176
+ .replace(/^\s*(?:model|assistant|user)\b[:\s]*/i, '')
177
+ .trim();
178
+ }
179
+ /**
180
+ * The default provider: Gemma 4 (E2B) running on WebGPU in the browser.
181
+ *
182
+ * Owns everything model-specific, including fetching Transformers.js and the
183
+ * weights, applying the chat template, and parsing Gemma's tool-call markers,
184
+ * so that the harness sees only text and structured calls.
185
+ *
186
+ * @example
187
+ * ```ts
188
+ * const provider = new LocalGemmaProvider({ useBrowserCache: true });
189
+ * const harness = new AgentHarness({ renderer, provider });
190
+ * ```
191
+ */
192
+ export class LocalGemmaProvider {
193
+ constructor(opts = {}) {
194
+ this.name = 'gemma-4-e2b';
195
+ this.local = true;
196
+ /** True when this load dropped the cache because the last one never returned. */
197
+ this.cacheDisabledAfterCrash = false;
198
+ this.modelHost = opts.modelHost || MODEL_HOST;
199
+ this.modelPathTemplate = opts.modelPathTemplate || MODEL_PATH_TEMPLATE;
200
+ this.systemPrompt = opts.systemPrompt || SYSTEM_PROMPT;
201
+ this.onStatus = opts.onStatus || (() => { });
202
+ this.onProgress = opts.onProgress || (() => { });
203
+ this.useBrowserCache = opts.useBrowserCache !== false;
204
+ this.engine = null; // { tokenizer, model }
205
+ this.T = null; // transformers module
206
+ this._enginePromise = null; // in-flight load (dedupes preload/open/send)
207
+ this._progress = new Map();
208
+ }
209
+ /**
210
+ * Whether the weights are loaded and usable right now.
211
+ *
212
+ * Side-effect free: reading it does not start a load. Use it to distinguish a
213
+ * first visit, where a load takes tens of seconds, from a warm one.
214
+ */
215
+ get ready() {
216
+ return !!this.engine;
217
+ }
218
+ /**
219
+ * Whether a load is in flight.
220
+ *
221
+ * Distinct from {@link LocalGemmaProvider.ready}: both false means nothing
222
+ * has been requested yet, while `loading` alone means a download is running.
223
+ */
224
+ get loading() {
225
+ return !!this._enginePromise && !this.engine;
226
+ }
227
+ _status(text, isError = false) {
228
+ this.onStatus(text, isError);
229
+ }
230
+ /**
231
+ * Begin downloading the weights in the background.
232
+ *
233
+ * @param mode - `'idle'` waits for the browser to be free, keeping the
234
+ * download off the critical path of the host page. `'eager'` starts at once,
235
+ * which spends hundreds of megabytes of a visitor's bandwidth before they
236
+ * have asked for anything, and suits only pages where the agent is the point.
237
+ */
238
+ schedulePreload(mode = 'idle') {
239
+ if (!('gpu' in navigator))
240
+ return;
241
+ const start = () => this.ensureEngine().catch(() => {
242
+ /* surfaced on use */
243
+ });
244
+ if (mode === 'eager') {
245
+ start();
246
+ return;
247
+ }
248
+ if ('requestIdleCallback' in window)
249
+ window.requestIdleCallback(start, { timeout: 3000 });
250
+ else
251
+ setTimeout(start, 1200);
252
+ }
253
+ /** Single shared promise so preload + open + send never double-download. */
254
+ ensureEngine() {
255
+ if (this.engine)
256
+ return Promise.resolve(this.engine);
257
+ if (!this._enginePromise) {
258
+ this._enginePromise = this._loadEngine();
259
+ this._enginePromise.catch(() => {
260
+ // A rejection reached a handler, so the guard has served its purpose.
261
+ // Only a load that never returns at all should cost the next its cache.
262
+ this._writeGuard(0);
263
+ this._enginePromise = null;
264
+ }); // allow retry
265
+ }
266
+ return this._enginePromise;
267
+ }
268
+ async _loadEngine() {
269
+ if (!('gpu' in navigator)) {
270
+ throw new Error('WebGPU is not available. Use Chrome/Edge 113+ with WebGPU enabled.');
271
+ }
272
+ // A guard left from last time means that load never returned. The browser
273
+ // cache is the likeliest cause, so this attempt runs without it.
274
+ const died = this._readGuard();
275
+ const useCache = this.useBrowserCache && died === 0;
276
+ this._writeGuard(died + 1);
277
+ this.cacheDisabledAfterCrash = !useCache && this.useBrowserCache;
278
+ this._resetProgress();
279
+ this._status(this.cacheDisabledAfterCrash
280
+ ? 'Last load did not finish — retrying without the browser cache…'
281
+ : 'Loading runtime…');
282
+ // The specifier is a URL, not a package: Transformers.js is fetched at
283
+ // runtime and must never be bundled. Each bundler needs its own directive,
284
+ // and omitting one is not harmless. Turbopack, which does not recognise
285
+ // @vite-ignore, compiles this into an external require that has no browser
286
+ // implementation and throws when the agent is opened.
287
+ const T = await import(
288
+ /* @vite-ignore */ /* webpackIgnore: true */ /* turbopackIgnore: true */ TRANSFORMERS_CDN);
289
+ this.T = T;
290
+ if (T.env && !useCache) {
291
+ // Both flags are needed: `useBrowserCache` governs Cache Storage, and
292
+ // the custom cache is the fallback path that would otherwise be used.
293
+ T.env.useBrowserCache = false;
294
+ T.env.useCustomCache = false;
295
+ }
296
+ const host = (this.modelHost || '').trim();
297
+ if (host && T.env) {
298
+ T.env.remoteHost = host.endsWith('/') ? host : host + '/';
299
+ T.env.remotePathTemplate = this.modelPathTemplate || MODEL_PATH_TEMPLATE;
300
+ }
301
+ const ModelClass = T.Gemma4ForConditionalGeneration || T.AutoModelForImageTextToText || T.AutoModelForCausalLM;
302
+ if (!ModelClass)
303
+ throw new Error('This Transformers.js build has no Gemma 4 model class — bump the version.');
304
+ // Text-only function calling, so the tokenizer rather than AutoProcessor,
305
+ // which would build Gemma 4's unused image and audio preprocessors.
306
+ this._resetProgress();
307
+ this._status('Loading tokenizer…');
308
+ const tokenizer = await T.AutoTokenizer.from_pretrained(MODEL_ID, {
309
+ progress_callback: (p) => this._trackProgress(p),
310
+ });
311
+ this._resetProgress();
312
+ this._status('Downloading Gemma 4 E2B — first run fetches several GB (cached afterward)…');
313
+ const model = await ModelClass.from_pretrained(MODEL_ID, {
314
+ dtype: 'q4f16',
315
+ device: 'webgpu',
316
+ progress_callback: (p) => this._trackProgress(p),
317
+ });
318
+ this.engine = { tokenizer, model };
319
+ // The load returned, so the guard can be cleared.
320
+ this._writeGuard(0);
321
+ this.onProgress(0);
322
+ await this._warmup(); // compile WebGPU kernels so the first real reply is fast
323
+ this._status('Model ready');
324
+ return this.engine;
325
+ }
326
+ async _warmup() {
327
+ try {
328
+ this._status('Warming up…');
329
+ const { tokenizer, model } = this.engine;
330
+ const inputs = await tokenizer.apply_chat_template([{ role: 'user', content: 'hi' }], {
331
+ add_generation_prompt: true,
332
+ add_special_tokens: false,
333
+ return_dict: true,
334
+ });
335
+ await model.generate({ ...inputs, max_new_tokens: 1, do_sample: false });
336
+ }
337
+ catch {
338
+ /* best-effort */
339
+ }
340
+ }
341
+ _trackProgress(p) {
342
+ if (p && p.status === 'progress' && p.file) {
343
+ this._progress.set(p.file, { loaded: p.loaded || 0, total: p.total || 0 });
344
+ let loaded = 0;
345
+ let total = 0;
346
+ for (const v of this._progress.values()) {
347
+ loaded += v.loaded;
348
+ total += v.total;
349
+ }
350
+ if (total > 0) {
351
+ // Uncapped, and allowed to decrease. Clamping it to never fall means
352
+ // the tokenizer's few files reach 100% within a second and hold the
353
+ // indicator full for the rest of the multi-minute weight download.
354
+ this.onProgress((loaded / total) * 100, { loaded, total });
355
+ }
356
+ }
357
+ // `ready` is intentionally not handled: it fires once per artefact, so the
358
+ // tokenizer's arrives mid-download and resetting on it would drop the
359
+ // indicator to nothing and back. The counters reset when the next load
360
+ // starts instead.
361
+ }
362
+ /** How many loads have started and not come back. Survives the tab dying. */
363
+ _readGuard() {
364
+ try {
365
+ return Number(localStorage.getItem(LOAD_GUARD_KEY)) || 0;
366
+ }
367
+ catch {
368
+ return 0; // storage disabled — the guard degrades to "no history"
369
+ }
370
+ }
371
+ _writeGuard(n) {
372
+ try {
373
+ if (n > 0)
374
+ localStorage.setItem(LOAD_GUARD_KEY, String(n));
375
+ else
376
+ localStorage.removeItem(LOAD_GUARD_KEY);
377
+ }
378
+ catch {
379
+ /* storage disabled */
380
+ }
381
+ }
382
+ /**
383
+ * Begin measuring a new load stage from zero.
384
+ *
385
+ * Stages are measured separately because they differ by orders of magnitude
386
+ * in size and the label names one at a time. Pooling them would report the
387
+ * tokenizer's completion as progress on the weights.
388
+ */
389
+ _resetProgress() {
390
+ this._progress.clear();
391
+ }
392
+ /**
393
+ * Generate one completion.
394
+ *
395
+ * Gemma expresses tool calls as markers within its output, so they are parsed
396
+ * here and reported as {@link Completion.call}, leaving the harness with text
397
+ * it can render directly.
398
+ *
399
+ * @param req - The conversation, tools, abort signal and token callback.
400
+ * @returns The generated text with markers stripped, and the tool call it
401
+ * contained, if any.
402
+ */
403
+ async complete(req) {
404
+ const text = await this.generate(req.messages, this.buildToolDefs(req.tools), {
405
+ onToken: req.onToken,
406
+ maxNewTokens: req.maxTokens,
407
+ signal: req.signal,
408
+ });
409
+ return { text: stripMarkers(text), call: parseToolCall(text) ?? undefined };
410
+ }
411
+ /** Satisfies `ModelProvider.load`; the work is in ensureEngine. */
412
+ async load() {
413
+ await this.ensureEngine();
414
+ }
415
+ /** Satisfies `ModelProvider.preload`. */
416
+ preload(mode = 'idle') {
417
+ this.schedulePreload(mode);
418
+ }
419
+ buildToolDefs(tools) {
420
+ return tools.map((t) => ({
421
+ type: 'function',
422
+ function: { name: t.name, description: t.description, parameters: toolSchema(t) },
423
+ }));
424
+ }
425
+ /** Token count of arbitrary text via the loaded tokenizer (0 if unavailable). */
426
+ async countTokens(text) {
427
+ try {
428
+ await this.ensureEngine();
429
+ return this.engine.tokenizer.encode(text).length;
430
+ }
431
+ catch {
432
+ return 0;
433
+ }
434
+ }
435
+ /**
436
+ * Run one generation.
437
+ *
438
+ * @param messages - The conversation, including the system prompt.
439
+ * @param toolDefs - Tool definitions in the form the chat template expects.
440
+ * @param options - Streaming, usage reporting, token cap and abort signal.
441
+ * @returns The generated text, with protocol markers stripped.
442
+ * @throws `AbortError` if the signal is already aborted when called.
443
+ */
444
+ async generate(messages, toolDefs, { onToken, onUsage, maxNewTokens, signal, } = {}) {
445
+ await this.ensureEngine();
446
+ if (signal?.aborted)
447
+ throw new DOMException('Aborted', 'AbortError');
448
+ const { tokenizer, model } = this.engine;
449
+ const inputs = await tokenizer.apply_chat_template(messages, {
450
+ tools: toolDefs,
451
+ add_generation_prompt: true,
452
+ enable_thinking: false,
453
+ tokenize: true,
454
+ add_special_tokens: false,
455
+ return_dict: true,
456
+ });
457
+ let streamed = '';
458
+ const streamer = new this.T.TextStreamer(tokenizer, {
459
+ skip_prompt: true,
460
+ skip_special_tokens: false,
461
+ callback_function: (t) => {
462
+ streamed += t;
463
+ if (onToken)
464
+ onToken(stripMarkers(streamed));
465
+ },
466
+ });
467
+ // Generation stops at the next token once this is tripped. A fresh instance
468
+ // per call, since the class holds its interrupted flag and a reused one
469
+ // would stop every later generation immediately.
470
+ const stopper = new this.T.InterruptableStoppingCriteria();
471
+ const onAbort = () => stopper.interrupt();
472
+ signal?.addEventListener('abort', onAbort, { once: true });
473
+ let output;
474
+ try {
475
+ output = await model.generate({
476
+ ...inputs,
477
+ max_new_tokens: maxNewTokens ?? MAX_NEW_TOKENS,
478
+ do_sample: false,
479
+ stopping_criteria: stopper,
480
+ streamer,
481
+ });
482
+ }
483
+ finally {
484
+ signal?.removeEventListener('abort', onAbort);
485
+ }
486
+ let decoded = streamed;
487
+ try {
488
+ const promptLen = inputs.input_ids.dims.at(-1);
489
+ const newTokens = output.slice(null, [promptLen, null]);
490
+ decoded = tokenizer.batch_decode(newTokens, { skip_special_tokens: false })[0];
491
+ if (onUsage)
492
+ onUsage({ promptTokens: promptLen, outputTokens: output.dims.at(-1) - promptLen });
493
+ }
494
+ catch {
495
+ /* fall back to streamed text */
496
+ }
497
+ return decoded;
498
+ }
499
+ }
500
+ /**
501
+ * @deprecated Use {@link LocalGemmaProvider}. The harness takes a
502
+ * {@link ModelProvider}, of which this is one implementation.
503
+ */
504
+ export const AgentEngine = LocalGemmaProvider;
505
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAiBvD,gFAAgF;AAChF,MAAM,CAAC,MAAM,gBAAgB,GAC3B,8DAA8D,CAAC;AACjE,+DAA+D;AAC/D,MAAM,CAAC,MAAM,QAAQ,GAAG,oCAAoC,CAAC;AAC7D,gFAAgF;AAChF,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAC7B,gFAAgF;AAChF,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAC9C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,g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