@shobyde/boaz 0.0.0-stage → 0.8.2

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 (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +422 -2
  3. package/dist/build/codes.d.ts +16 -0
  4. package/dist/build/codes.d.ts.map +1 -0
  5. package/dist/build/codes.js +72 -0
  6. package/dist/build/codes.js.map +1 -0
  7. package/dist/build/extract.d.ts +45 -0
  8. package/dist/build/extract.d.ts.map +1 -0
  9. package/dist/build/extract.js +484 -0
  10. package/dist/build/extract.js.map +1 -0
  11. package/dist/build/glob.d.ts +11 -0
  12. package/dist/build/glob.d.ts.map +1 -0
  13. package/dist/build/glob.js +88 -0
  14. package/dist/build/glob.js.map +1 -0
  15. package/dist/build/index.d.ts +7 -0
  16. package/dist/build/index.d.ts.map +1 -0
  17. package/dist/build/index.js +4 -0
  18. package/dist/build/index.js.map +1 -0
  19. package/dist/build/probes.d.ts +41 -0
  20. package/dist/build/probes.d.ts.map +1 -0
  21. package/dist/build/probes.js +134 -0
  22. package/dist/build/probes.js.map +1 -0
  23. package/dist/build/report.d.ts +11 -0
  24. package/dist/build/report.d.ts.map +1 -0
  25. package/dist/build/report.js +39 -0
  26. package/dist/build/report.js.map +1 -0
  27. package/dist/cli/audit.d.ts +15 -0
  28. package/dist/cli/audit.d.ts.map +1 -0
  29. package/dist/cli/audit.js +68 -0
  30. package/dist/cli/audit.js.map +1 -0
  31. package/dist/cli/bench.d.ts +7 -0
  32. package/dist/cli/bench.d.ts.map +1 -0
  33. package/dist/cli/bench.js +147 -0
  34. package/dist/cli/bench.js.map +1 -0
  35. package/dist/cli/harness.d.ts +45 -0
  36. package/dist/cli/harness.d.ts.map +1 -0
  37. package/dist/cli/harness.js +90 -0
  38. package/dist/cli/harness.js.map +1 -0
  39. package/dist/cli/index.d.ts +3 -0
  40. package/dist/cli/index.d.ts.map +1 -0
  41. package/dist/cli/index.js +404 -0
  42. package/dist/cli/index.js.map +1 -0
  43. package/dist/cli/probes.d.ts +20 -0
  44. package/dist/cli/probes.d.ts.map +1 -0
  45. package/dist/cli/probes.js +27 -0
  46. package/dist/cli/probes.js.map +1 -0
  47. package/dist/cli/skill-template.d.ts +2 -0
  48. package/dist/cli/skill-template.d.ts.map +1 -0
  49. package/dist/cli/skill-template.js +254 -0
  50. package/dist/cli/skill-template.js.map +1 -0
  51. package/dist/core/actions.d.ts +67 -0
  52. package/dist/core/actions.d.ts.map +1 -0
  53. package/dist/core/actions.js +357 -0
  54. package/dist/core/actions.js.map +1 -0
  55. package/dist/core/define.d.ts +25 -0
  56. package/dist/core/define.d.ts.map +1 -0
  57. package/dist/core/define.js +76 -0
  58. package/dist/core/define.js.map +1 -0
  59. package/dist/core/execute.d.ts +75 -0
  60. package/dist/core/execute.d.ts.map +1 -0
  61. package/dist/core/execute.js +145 -0
  62. package/dist/core/execute.js.map +1 -0
  63. package/dist/core/index.d.ts +35 -0
  64. package/dist/core/index.d.ts.map +1 -0
  65. package/dist/core/index.js +20 -0
  66. package/dist/core/index.js.map +1 -0
  67. package/dist/core/lemmas.d.ts +32 -0
  68. package/dist/core/lemmas.d.ts.map +1 -0
  69. package/dist/core/lemmas.js +80 -0
  70. package/dist/core/lemmas.js.map +1 -0
  71. package/dist/core/lexical-engine.d.ts +18 -0
  72. package/dist/core/lexical-engine.d.ts.map +1 -0
  73. package/dist/core/lexical-engine.js +296 -0
  74. package/dist/core/lexical-engine.js.map +1 -0
  75. package/dist/core/loop.d.ts +51 -0
  76. package/dist/core/loop.d.ts.map +1 -0
  77. package/dist/core/loop.js +432 -0
  78. package/dist/core/loop.js.map +1 -0
  79. package/dist/core/mcp.d.ts +119 -0
  80. package/dist/core/mcp.d.ts.map +1 -0
  81. package/dist/core/mcp.js +253 -0
  82. package/dist/core/mcp.js.map +1 -0
  83. package/dist/core/memory.d.ts +106 -0
  84. package/dist/core/memory.d.ts.map +1 -0
  85. package/dist/core/memory.js +185 -0
  86. package/dist/core/memory.js.map +1 -0
  87. package/dist/core/plan.d.ts +83 -0
  88. package/dist/core/plan.d.ts.map +1 -0
  89. package/dist/core/plan.js +258 -0
  90. package/dist/core/plan.js.map +1 -0
  91. package/dist/core/preferences.d.ts +54 -0
  92. package/dist/core/preferences.d.ts.map +1 -0
  93. package/dist/core/preferences.js +83 -0
  94. package/dist/core/preferences.js.map +1 -0
  95. package/dist/core/prompt.d.ts +23 -0
  96. package/dist/core/prompt.d.ts.map +1 -0
  97. package/dist/core/prompt.js +76 -0
  98. package/dist/core/prompt.js.map +1 -0
  99. package/dist/core/question.d.ts +96 -0
  100. package/dist/core/question.d.ts.map +1 -0
  101. package/dist/core/question.js +501 -0
  102. package/dist/core/question.js.map +1 -0
  103. package/dist/core/registry.d.ts +33 -0
  104. package/dist/core/registry.d.ts.map +1 -0
  105. package/dist/core/registry.js +72 -0
  106. package/dist/core/registry.js.map +1 -0
  107. package/dist/core/retriever.d.ts +48 -0
  108. package/dist/core/retriever.d.ts.map +1 -0
  109. package/dist/core/retriever.js +123 -0
  110. package/dist/core/retriever.js.map +1 -0
  111. package/dist/core/schema.d.ts +27 -0
  112. package/dist/core/schema.d.ts.map +1 -0
  113. package/dist/core/schema.js +231 -0
  114. package/dist/core/schema.js.map +1 -0
  115. package/dist/core/skill.d.ts +105 -0
  116. package/dist/core/skill.d.ts.map +1 -0
  117. package/dist/core/skill.js +205 -0
  118. package/dist/core/skill.js.map +1 -0
  119. package/dist/core/summarise.d.ts +52 -0
  120. package/dist/core/summarise.d.ts.map +1 -0
  121. package/dist/core/summarise.js +146 -0
  122. package/dist/core/summarise.js.map +1 -0
  123. package/dist/core/tools.d.ts +21 -0
  124. package/dist/core/tools.d.ts.map +1 -0
  125. package/dist/core/tools.js +120 -0
  126. package/dist/core/tools.js.map +1 -0
  127. package/dist/core/types.d.ts +199 -0
  128. package/dist/core/types.d.ts.map +1 -0
  129. package/dist/core/types.js +5 -0
  130. package/dist/core/types.js.map +1 -0
  131. package/dist/dom/index.d.ts +22 -0
  132. package/dist/dom/index.d.ts.map +1 -0
  133. package/dist/dom/index.js +94 -0
  134. package/dist/dom/index.js.map +1 -0
  135. package/dist/extract/index.d.ts +36 -0
  136. package/dist/extract/index.d.ts.map +1 -0
  137. package/dist/extract/index.js +86 -0
  138. package/dist/extract/index.js.map +1 -0
  139. package/dist/react/index.d.ts +52 -0
  140. package/dist/react/index.d.ts.map +1 -0
  141. package/dist/react/index.js +131 -0
  142. package/dist/react/index.js.map +1 -0
  143. package/dist/rules/engine.d.ts +152 -0
  144. package/dist/rules/engine.d.ts.map +1 -0
  145. package/dist/rules/engine.js +364 -0
  146. package/dist/rules/engine.js.map +1 -0
  147. package/dist/rules/facts.d.ts +63 -0
  148. package/dist/rules/facts.d.ts.map +1 -0
  149. package/dist/rules/facts.js +115 -0
  150. package/dist/rules/facts.js.map +1 -0
  151. package/dist/rules/index.d.ts +10 -0
  152. package/dist/rules/index.d.ts.map +1 -0
  153. package/dist/rules/index.js +5 -0
  154. package/dist/rules/index.js.map +1 -0
  155. package/dist/rules/knowledge.d.ts +78 -0
  156. package/dist/rules/knowledge.d.ts.map +1 -0
  157. package/dist/rules/knowledge.js +254 -0
  158. package/dist/rules/knowledge.js.map +1 -0
  159. package/dist/vite/index.d.ts +26 -0
  160. package/dist/vite/index.d.ts.map +1 -0
  161. package/dist/vite/index.js +112 -0
  162. package/dist/vite/index.js.map +1 -0
  163. package/package.json +108 -4
@@ -0,0 +1,432 @@
1
+ import { CapabilityIndex } from './retriever.js';
2
+ import { buildSystemPrompt, buildToolSpecs } from './prompt.js';
3
+ import { parseModelOutput } from './tools.js';
4
+ import { formatSchemaErrors, validateParams } from './schema.js';
5
+ const MAX_CORRECTIONS = 2;
6
+ /** A handler can return `{ surface: [...] }` to render UI instead of prose. */
7
+ function surfaceOf(result) {
8
+ if (result === null || typeof result !== 'object')
9
+ return undefined;
10
+ const messages = result.surface;
11
+ return Array.isArray(messages) && messages.length > 0 ? messages : undefined;
12
+ }
13
+ function clip(value, max = 600) {
14
+ let text;
15
+ try {
16
+ text = JSON.stringify(value) ?? 'null';
17
+ }
18
+ catch {
19
+ text = String(value);
20
+ }
21
+ return text.length > max ? `${text.slice(0, max)}…` : text;
22
+ }
23
+ /**
24
+ * Runs the tool-call loop for one user turn.
25
+ *
26
+ * The model is not trusted: every call is matched against the manifest, every
27
+ * argument is validated, side effects pass a confirmation gate, and the number
28
+ * of sequential calls is capped. A failure is retried once with the exact
29
+ * validator error, which is what actually makes small local models usable.
30
+ */
31
+ export class AgentRuntime {
32
+ options;
33
+ history = [];
34
+ index;
35
+ byId = new Map();
36
+ maxToolCalls;
37
+ topK;
38
+ constructor(options) {
39
+ this.options = options;
40
+ this.index = new CapabilityIndex(options.capabilities);
41
+ for (const capability of options.capabilities) {
42
+ this.byId.set(capability.id, capability);
43
+ }
44
+ this.maxToolCalls = options.maxToolCalls ?? 3;
45
+ this.topK = options.topK ?? 8;
46
+ }
47
+ get conversation() {
48
+ return this.history;
49
+ }
50
+ get capabilities() {
51
+ return [...this.byId.values()];
52
+ }
53
+ reset() {
54
+ this.history = [];
55
+ }
56
+ emit(event) {
57
+ this.options.onEvent?.(event);
58
+ }
59
+ makeContext() {
60
+ const snapshot = this.options.getSnapshot();
61
+ return {
62
+ currentRoute: snapshot.currentRoute,
63
+ navigate: (to) => {
64
+ if (!this.options.navigate) {
65
+ throw new Error(`no navigate function configured; cannot go to ${to}`);
66
+ }
67
+ return this.options.navigate(to);
68
+ },
69
+ dispatch: (name, payload) => {
70
+ if (!this.options.dispatch) {
71
+ throw new Error(`no dispatch function configured; cannot emit ${name}`);
72
+ }
73
+ this.options.dispatch(name, payload);
74
+ },
75
+ read: (key) => this.options.getSnapshot().state?.[key],
76
+ };
77
+ }
78
+ async send(userText) {
79
+ const steps = [];
80
+ const push = (step) => {
81
+ steps.push(step);
82
+ this.emit({ type: 'step', step });
83
+ };
84
+ const firstSnapshot = this.options.getSnapshot();
85
+ const retrieved = this.index.search(userText, {
86
+ currentRoute: firstSnapshot.currentRoute,
87
+ limit: this.topK,
88
+ });
89
+ const selected = retrieved.map((entry) => entry.capability);
90
+ // Always keep route capabilities for the current page: they are the most
91
+ // likely follow-up and cost one line each.
92
+ for (const capability of this.byId.values()) {
93
+ if (capability.kind === 'route' &&
94
+ capability.route === firstSnapshot.currentRoute &&
95
+ !selected.some((c) => c.id === capability.id)) {
96
+ selected.push(capability);
97
+ }
98
+ }
99
+ this.emit({ type: 'retrieval', ids: selected.map((c) => c.id) });
100
+ let context;
101
+ if (this.options.readContext) {
102
+ try {
103
+ context = await this.options.readContext(userText);
104
+ }
105
+ catch (error) {
106
+ // Grounding is optional: a broken selector must not cost the turn.
107
+ this.emit({ type: 'context-error', message: error instanceof Error ? error.message : String(error) });
108
+ }
109
+ }
110
+ const systemPrompt = buildSystemPrompt({
111
+ capabilities: selected,
112
+ snapshot: firstSnapshot,
113
+ budgetTokens: this.options.promptBudgetTokens,
114
+ instructions: this.options.instructions,
115
+ ...(context ? { context } : {}),
116
+ ...(this.options.contextBudgetTokens !== undefined
117
+ ? { contextBudgetTokens: this.options.contextBudgetTokens }
118
+ : {}),
119
+ });
120
+ const messages = [
121
+ { role: 'system', content: systemPrompt },
122
+ ...this.history,
123
+ { role: 'user', content: userText },
124
+ ];
125
+ let toolCalls = 0;
126
+ let corrections = 0;
127
+ const observations = {};
128
+ let finalText;
129
+ let textStepped = false;
130
+ let stoppedBy = 'final';
131
+ const correct = (message) => {
132
+ corrections += 1;
133
+ messages.push({ role: 'user', content: `[boaz] ${message}` });
134
+ };
135
+ while (toolCalls < this.maxToolCalls) {
136
+ const completion = await this.options.engine.complete({
137
+ messages,
138
+ tools: buildToolSpecs(selected),
139
+ observations: { ...observations },
140
+ });
141
+ for (const step of completion.steps ?? [])
142
+ push(step);
143
+ const parsed = parseModelOutput(completion.text);
144
+ if (parsed.kind === 'text') {
145
+ finalText = parsed.text || undefined;
146
+ if (finalText) {
147
+ await this.streamText(finalText);
148
+ push({ type: 'text', text: finalText });
149
+ textStepped = true;
150
+ }
151
+ break;
152
+ }
153
+ if (parsed.kind === 'malformed') {
154
+ if (corrections < MAX_CORRECTIONS) {
155
+ correct(`That reply was not usable: ${parsed.error}. Reply with either plain prose or one fenced JSON block of the form {"tool":"<id>","arguments":{}}.`);
156
+ continue;
157
+ }
158
+ push({ type: 'error', message: parsed.error });
159
+ break;
160
+ }
161
+ const capability = this.byId.get(parsed.capabilityId);
162
+ if (!capability) {
163
+ if (corrections < MAX_CORRECTIONS) {
164
+ const available = selected.map((c) => c.id).join(', ') || '(none)';
165
+ correct(`"${parsed.capabilityId}" is not a capability id. Use one of: ${available}. If none fits, reply in prose saying you cannot do it.`);
166
+ continue;
167
+ }
168
+ push({ type: 'error', message: `unknown capability "${parsed.capabilityId}"` });
169
+ break;
170
+ }
171
+ const validation = validateParams(parsed.args, capability.paramsSchema);
172
+ if (!validation.valid) {
173
+ const errors = formatSchemaErrors(validation.errors);
174
+ push({ type: 'validation-error', capabilityId: capability.id, errors, retried: corrections < MAX_CORRECTIONS });
175
+ if (corrections < MAX_CORRECTIONS) {
176
+ correct(`The call to "${capability.id}" was rejected by schema validation: ${errors.join('; ')}. Reply with the corrected JSON object only.`);
177
+ continue;
178
+ }
179
+ finalText = `I couldn't call ${capability.title} with those details.`;
180
+ break;
181
+ }
182
+ const args = validation.value;
183
+ if (capability.requiresConfirmation) {
184
+ if (!this.options.confirm) {
185
+ push({
186
+ type: 'error',
187
+ message: `${capability.id} requires confirmation but no confirmation UI is configured`,
188
+ capabilityId: capability.id,
189
+ });
190
+ finalText = `${capability.title} needs confirmation, which is not available here.`;
191
+ break;
192
+ }
193
+ const approved = await this.options.confirm({
194
+ capabilityId: capability.id,
195
+ title: capability.title,
196
+ description: capability.description,
197
+ args,
198
+ });
199
+ push({ type: 'confirmation', capabilityId: capability.id, approved });
200
+ if (!approved) {
201
+ finalText = 'Cancelled. Nothing was changed.';
202
+ break;
203
+ }
204
+ }
205
+ toolCalls += 1;
206
+ if (capability.kind === 'route') {
207
+ const route = capability.route ?? '/';
208
+ const snapshot = this.options.getSnapshot();
209
+ if (snapshot.currentRoute === route) {
210
+ push({ type: 'navigate', capabilityId: capability.id, route });
211
+ this.emit({ type: 'already-there', route });
212
+ }
213
+ else {
214
+ if (!this.options.navigate) {
215
+ push({ type: 'error', message: 'no navigate function configured', capabilityId: capability.id });
216
+ finalText = 'I cannot navigate in this environment.';
217
+ break;
218
+ }
219
+ await this.options.navigate(route);
220
+ push({ type: 'navigate', capabilityId: capability.id, route });
221
+ }
222
+ messages.push({ role: 'assistant', content: completion.text }, {
223
+ role: 'user',
224
+ content: `[boaz] Navigation succeeded. The visitor is now on ${route}.`,
225
+ });
226
+ continue;
227
+ }
228
+ // action | query: the handler lives in the module the route mounts.
229
+ let live = this.options.registry.get(capability.id);
230
+ if (!live || typeof live.handler !== 'function') {
231
+ const snapshot = this.options.getSnapshot();
232
+ if (capability.route &&
233
+ capability.route !== snapshot.currentRoute &&
234
+ this.options.navigate) {
235
+ await this.options.navigate(capability.route);
236
+ push({ type: 'navigate', capabilityId: capability.id, route: capability.route });
237
+ }
238
+ live = await this.options.registry.awaitRegistration(capability.id, 2000);
239
+ }
240
+ if (!live || typeof live.handler !== 'function') {
241
+ push({
242
+ type: 'error',
243
+ message: `no handler registered for "${capability.id}" (the module owning it may not be mounted)`,
244
+ capabilityId: capability.id,
245
+ });
246
+ finalText = `I couldn't reach the ${capability.title} control on this screen.`;
247
+ break;
248
+ }
249
+ const ctx = this.makeContext();
250
+ try {
251
+ const result = await live.handler(args, ctx);
252
+ // The handler may answer with a declarative surface (A2UI or any other
253
+ // component stream). The runtime does not interpret it: it hands the
254
+ // messages to the host, which owns the catalog and the renderer.
255
+ const surface = surfaceOf(result);
256
+ if (surface) {
257
+ push({ type: 'surface', capabilityId: capability.id, messages: surface });
258
+ messages.push({ role: 'assistant', content: completion.text }, {
259
+ role: 'user',
260
+ content: `[boaz] "${capability.id}" rendered a surface. Describe it in one sentence if the visitor still needs words.`,
261
+ });
262
+ continue;
263
+ }
264
+ observations[capability.id] = result;
265
+ if (capability.kind === 'query') {
266
+ push({ type: 'query', capabilityId: capability.id, args, result });
267
+ messages.push({ role: 'assistant', content: completion.text }, { role: 'user', content: `[boaz] Query "${capability.id}" returned ${clip(result)}.` });
268
+ }
269
+ else {
270
+ push({ type: 'action', capabilityId: capability.id, args, result });
271
+ messages.push({ role: 'assistant', content: completion.text }, {
272
+ role: 'user',
273
+ content: `[boaz] "${capability.id}" ran successfully and returned ${clip(result)}.`,
274
+ });
275
+ }
276
+ continue;
277
+ }
278
+ catch (error) {
279
+ const message = error instanceof Error ? error.message : String(error);
280
+ push({ type: 'error', message, capabilityId: capability.id });
281
+ if (corrections < MAX_CORRECTIONS) {
282
+ correct(`Running "${capability.id}" threw: ${message}. Try a different call or reply in prose.`);
283
+ continue;
284
+ }
285
+ finalText = `${capability.title} failed: ${message}`;
286
+ break;
287
+ }
288
+ }
289
+ if (!finalText && toolCalls >= this.maxToolCalls)
290
+ stoppedBy = 'max-tool-calls';
291
+ if (!finalText) {
292
+ finalText = this.summarize(steps, stoppedBy);
293
+ }
294
+ if (finalText && !textStepped) {
295
+ await this.streamText(finalText);
296
+ push({ type: 'text', text: finalText });
297
+ }
298
+ this.history.push({ role: 'user', content: userText });
299
+ this.history.push({ role: 'assistant', content: finalText });
300
+ this.emit({ type: 'turn', text: finalText, steps });
301
+ return { text: finalText, steps, stoppedBy };
302
+ }
303
+ /**
304
+ * Runs one capability by id, through the same validation, confirmation and
305
+ * handler path `send` uses. A plan that has to recover needs this: re-sending
306
+ * the visitor's words would route to the capability that just failed, so the
307
+ * host has to be able to name the runner-up directly.
308
+ */
309
+ async runCapability(capabilityId, args = {}) {
310
+ const steps = [];
311
+ const push = (step) => {
312
+ steps.push(step);
313
+ this.emit({ type: 'step', step });
314
+ };
315
+ const capability = this.byId.get(capabilityId);
316
+ if (!capability) {
317
+ return { ok: false, text: `There is no ${capabilityId} capability here.`, steps };
318
+ }
319
+ const validation = validateParams(args, capability.paramsSchema);
320
+ if (!validation.valid) {
321
+ const errors = formatSchemaErrors(validation.errors);
322
+ push({ type: 'validation-error', capabilityId, errors, retried: false });
323
+ return { ok: false, text: `${capability.title} needs details the request did not carry.`, steps };
324
+ }
325
+ if (capability.requiresConfirmation) {
326
+ if (!this.options.confirm) {
327
+ return { ok: false, text: `${capability.title} needs confirmation, which is not available here.`, steps };
328
+ }
329
+ const approved = await this.options.confirm({
330
+ capabilityId: capability.id,
331
+ title: capability.title,
332
+ description: capability.description,
333
+ args: validation.value,
334
+ });
335
+ push({ type: 'confirmation', capabilityId, approved });
336
+ if (!approved)
337
+ return { ok: false, text: 'Cancelled. Nothing was changed.', steps };
338
+ }
339
+ if (capability.kind === 'route') {
340
+ const route = capability.route ?? '/';
341
+ if (this.options.getSnapshot().currentRoute !== route) {
342
+ await this.options.navigate?.(route);
343
+ }
344
+ push({ type: 'navigate', capabilityId, route });
345
+ return { ok: true, text: `You're on ${route} now.`, steps };
346
+ }
347
+ const live = this.options.registry.get(capability.id);
348
+ if (!live || typeof live.handler !== 'function') {
349
+ return { ok: false, text: `I couldn't reach the ${capability.title} control on this screen.`, steps };
350
+ }
351
+ try {
352
+ const result = await live.handler(validation.value, this.makeContext());
353
+ const surface = surfaceOf(result);
354
+ if (surface) {
355
+ push({ type: 'surface', capabilityId, messages: surface });
356
+ return { ok: true, text: '', steps, result };
357
+ }
358
+ push({ type: capability.kind === 'query' ? 'query' : 'action', capabilityId, args: validation.value, result });
359
+ return { ok: true, text: '', steps, result };
360
+ }
361
+ catch (error) {
362
+ const message = error instanceof Error ? error.message : String(error);
363
+ push({ type: 'error', message, capabilityId });
364
+ return { ok: false, text: `${capability.title} failed: ${message}`, steps };
365
+ }
366
+ }
367
+ /**
368
+ * Reveals the finished reply as deltas. The reply is already computed, so this
369
+ * is pacing, not inference: hosts that want instant text leave streaming off.
370
+ */
371
+ async streamText(text) {
372
+ const streaming = this.options.streaming;
373
+ if (!streaming)
374
+ return;
375
+ const chunkChars = Math.max(4, streaming.chunkChars ?? 16);
376
+ // Browsers throttle timers in hidden tabs to about once a second, which would
377
+ // turn a 90-character reply into a nine-second crawl. Pace only when visible.
378
+ const hidden = typeof document !== 'undefined' && document.hidden;
379
+ const paceMs = hidden ? 0 : (streaming.paceMs ?? 0);
380
+ // A beat before the first word, so the step that produced the answer is
381
+ // readable instead of flashing past.
382
+ const leadInMs = hidden ? 0 : (streaming.leadInMs ?? 0);
383
+ if (leadInMs > 0)
384
+ await new Promise((resolve) => setTimeout(resolve, leadInMs));
385
+ for (const chunk of chunkForDisplay(text, chunkChars)) {
386
+ this.emit({ type: 'delta', text: chunk });
387
+ if (paceMs > 0)
388
+ await new Promise((resolve) => setTimeout(resolve, paceMs));
389
+ }
390
+ }
391
+ summarize(steps, stoppedBy) {
392
+ // A rendered surface is the answer. Adding a sentence on top of it is noise.
393
+ if (steps[steps.length - 1]?.type === 'surface')
394
+ return '';
395
+ const lastAction = [...steps].reverse().find((s) => s.type === 'action' || s.type === 'navigate');
396
+ if (stoppedBy === 'max-tool-calls') {
397
+ return lastAction
398
+ ? `I stopped after ${this.maxToolCalls} steps. The last one completed; tell me if you want to continue.`
399
+ : `I stopped after ${this.maxToolCalls} steps without finishing.`;
400
+ }
401
+ if (lastAction?.type === 'navigate')
402
+ return `You're on ${lastAction.route} now.`;
403
+ if (lastAction?.type === 'action') {
404
+ const title = this.byId.get(lastAction.capabilityId)?.title ?? lastAction.capabilityId;
405
+ return `${title}: done.`;
406
+ }
407
+ return "I couldn't complete that. Nothing was changed.";
408
+ }
409
+ }
410
+ /**
411
+ * Splits a finished reply into display chunks on word boundaries, so a streamed
412
+ * delta never cuts a word in half.
413
+ */
414
+ export function chunkForDisplay(text, chunkChars) {
415
+ const chunks = [];
416
+ let current = '';
417
+ for (const piece of text.split(/(\s+)/)) {
418
+ if (!piece)
419
+ continue;
420
+ if (current.length > 0 && current.length + piece.length > chunkChars) {
421
+ chunks.push(current);
422
+ current = piece;
423
+ }
424
+ else {
425
+ current += piece;
426
+ }
427
+ }
428
+ if (current)
429
+ chunks.push(current);
430
+ return chunks;
431
+ }
432
+ //# sourceMappingURL=loop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop.js","sourceRoot":"","sources":["../../src/core/loop.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEjE,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B,+EAA+E;AAC/E,SAAS,SAAS,CAAC,MAAe;IAChC,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACpE,MAAM,QAAQ,GAAI,MAAgC,CAAC,OAAO,CAAC;IAC3D,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/E,CAAC;AAED,SAAS,IAAI,CAAC,KAAc,EAAE,GAAG,GAAG,GAAG;IACrC,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7D,CAAC;AAED;;;;;;;GA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M,GAAG,UAAU,EAAE,CAAC;YACrE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrB,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,KAAK,CAAC;QACnB,CAAC;IACH,CAAC;IACD,IAAI,OAAO;QAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,119 @@
1
+ import type { ManifestCapability } from './types.js';
2
+ import { type PlanOptions } from './plan.js';
3
+ /**
4
+ * An MCP-shaped bridge: the same capabilities an in-page assistant uses,
5
+ * exposed as JSON-RPC tools, so a client that speaks the protocol can drive
6
+ * them without knowing this library exists.
7
+ *
8
+ * The point is not to imitate a model. It is to show that the tool surface a
9
+ * hosted model gets is a data structure, and that a deterministic planner can
10
+ * call it just as well: `planToolCall` routes a request to a tool name and its
11
+ * arguments, and the server answers with the protocol's result shape
12
+ * (`content` for a reader, `structuredContent` for a program).
13
+ *
14
+ * Validation happens on this side of the wire on purpose. A model client will
15
+ * happily send an argument the schema never declared, and a server that runs it
16
+ * anyway teaches the caller that the schema is decorative.
17
+ */
18
+ export type JsonRpcId = string | number | null;
19
+ export interface JsonRpcRequest {
20
+ jsonrpc?: '2.0';
21
+ id?: JsonRpcId;
22
+ method?: string;
23
+ params?: Record<string, unknown>;
24
+ }
25
+ export interface JsonRpcError {
26
+ code: number;
27
+ message: string;
28
+ data?: unknown;
29
+ }
30
+ export interface JsonRpcResponse {
31
+ jsonrpc: '2.0';
32
+ id: JsonRpcId;
33
+ result?: unknown;
34
+ error?: JsonRpcError;
35
+ }
36
+ export interface ToolDefinition {
37
+ name: string;
38
+ description: string;
39
+ inputSchema: Record<string, unknown>;
40
+ }
41
+ export interface ToolCallResult {
42
+ content: Array<{
43
+ type: 'text';
44
+ text: string;
45
+ }>;
46
+ structuredContent?: unknown;
47
+ isError?: boolean;
48
+ _meta?: Record<string, unknown>;
49
+ }
50
+ export interface ToolServerOptions {
51
+ name: string;
52
+ version: string;
53
+ capabilities: ManifestCapability[];
54
+ /** Runs one capability. The host's own path, not a second one. */
55
+ run: (capabilityId: string, args: Record<string, unknown>) => unknown | Promise<unknown>;
56
+ /** Echoed back on `initialize`. Defaults to the 2025-06-18 revision. */
57
+ protocolVersion?: string;
58
+ }
59
+ export interface ToolServer {
60
+ /** Tool definitions, in manifest order. */
61
+ tools: ToolDefinition[];
62
+ /** The capability id behind a tool name. */
63
+ capabilityFor: (toolName: string) => string | undefined;
64
+ callTool: (toolName: string, args?: Record<string, unknown>) => Promise<ToolCallResult>;
65
+ /** One JSON-RPC message in, one response out. `null` means "no response" (notification). */
66
+ handle: (message: JsonRpcRequest) => Promise<JsonRpcResponse | null>;
67
+ }
68
+ /**
69
+ * The protocol's tool-name pattern is `[a-zA-Z0-9_-]`, and every capability id
70
+ * here carries a dot (`projects.list`). Sanitising rather than renaming keeps
71
+ * the id as the record and the name as the wire format.
72
+ */
73
+ export declare function toolName(capabilityId: string): string;
74
+ export declare function toolsFromCapabilities(capabilities: ManifestCapability[]): ToolDefinition[];
75
+ /**
76
+ * A tool result a reader can use and a program can parse. The text is a
77
+ * sentence, because the first consumer of an MCP result is often a model that
78
+ * will quote it; the structure rides alongside for the deterministic caller.
79
+ */
80
+ export declare function describeToolResult(title: string, value: unknown): string;
81
+ export declare function createToolServer(options: ToolServerOptions): ToolServer;
82
+ export interface ToolClient {
83
+ initialize: () => Promise<Record<string, unknown>>;
84
+ listTools: () => Promise<ToolDefinition[]>;
85
+ callTool: (name: string, args?: Record<string, unknown>) => Promise<ToolCallResult>;
86
+ }
87
+ /**
88
+ * A client over any transport: a `send` that takes one JSON-RPC message and
89
+ * resolves the matching response. In-process it is the server's `handle`; over
90
+ * stdio it is one line in, one line out. Neither path knows about the other.
91
+ */
92
+ export declare function createToolClient(send: (message: JsonRpcRequest) => Promise<JsonRpcResponse | null>): ToolClient;
93
+ export interface PlannedToolCall {
94
+ name: string;
95
+ capabilityId: string;
96
+ args: Record<string, unknown>;
97
+ /** True when the call can run now; false when it needs an argument or a page. */
98
+ runnable: boolean;
99
+ reason?: 'args' | 'route';
100
+ }
101
+ export interface ToolPlan {
102
+ calls: PlannedToolCall[];
103
+ declined?: string;
104
+ failed?: string;
105
+ /** One sentence a host can print before making the calls. */
106
+ summary: string;
107
+ }
108
+ export interface PlanToolOptions extends PlanOptions {
109
+ }
110
+ /**
111
+ * The deterministic planner behind a tool client. One sentence becomes one
112
+ * call, a sentence with two requests becomes two calls in order, and a request
113
+ * no capability serves is declined rather than mapped onto the nearest tool.
114
+ *
115
+ * It keeps `needs` instead of ignoring it: a tool call with a missing argument
116
+ * is the MCP version of asking a page for a card it was never told to open.
117
+ */
118
+ export declare function planToolCall(query: string, options: PlanToolOptions): ToolPlan;
119
+ //# sourceMappingURL=mcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/core/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,EAA6B,KAAK,WAAW,EAAoB,MAAM,WAAW,CAAC;AAE1F;;;;;;;;;;;;;;GAcG;AAEH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,EAAE,CAAC,EAAE,SAAS,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,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