genaicode 2.31.0 → 2.33.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 (58) hide show
  1. package/README.md +1 -0
  2. package/dist/agents/artifacts.d.ts +16 -6
  3. package/dist/agents/artifacts.js +74 -23
  4. package/dist/agents/artifacts.js.map +1 -1
  5. package/dist/agents/handoff.d.ts +14 -3
  6. package/dist/agents/handoff.js +55 -5
  7. package/dist/agents/handoff.js.map +1 -1
  8. package/dist/agents/session.d.ts +11 -0
  9. package/dist/agents/session.js +22 -5
  10. package/dist/agents/session.js.map +1 -1
  11. package/dist/agents/types.d.ts +2 -2
  12. package/dist/agents.d.ts +1 -1
  13. package/dist/app-agent/http.js +2 -2
  14. package/dist/app-agent/http.js.map +1 -1
  15. package/dist/browser/fake-model.d.ts +43 -0
  16. package/dist/browser/fake-model.js +133 -0
  17. package/dist/browser/fake-model.js.map +1 -0
  18. package/dist/browser/language-model.d.ts +74 -0
  19. package/dist/browser/language-model.js +83 -0
  20. package/dist/browser/language-model.js.map +1 -0
  21. package/dist/browser/nano.d.ts +83 -0
  22. package/dist/browser/nano.js +610 -0
  23. package/dist/browser/nano.js.map +1 -0
  24. package/dist/browser/page-agent.d.ts +74 -0
  25. package/dist/browser/page-agent.js +339 -0
  26. package/dist/browser/page-agent.js.map +1 -0
  27. package/dist/browser/tools.d.ts +36 -0
  28. package/dist/browser/tools.js +190 -0
  29. package/dist/browser/tools.js.map +1 -0
  30. package/dist/browser/webmcp.d.ts +32 -0
  31. package/dist/browser/webmcp.js +150 -0
  32. package/dist/browser/webmcp.js.map +1 -0
  33. package/dist/browser.d.ts +39 -0
  34. package/dist/browser.js +32 -0
  35. package/dist/browser.js.map +1 -0
  36. package/dist/react/agent-chat.css +174 -0
  37. package/dist/react/agent-chat.d.ts +23 -2
  38. package/dist/react/agent-chat.js +114 -13
  39. package/dist/react/agent-chat.js.map +1 -1
  40. package/dist/react/app-agent-chat.d.ts +2 -0
  41. package/dist/react/app-agent-chat.js +1 -1
  42. package/dist/react/app-agent-chat.js.map +1 -1
  43. package/dist/react/attachments.d.ts +41 -0
  44. package/dist/react/attachments.js +162 -0
  45. package/dist/react/attachments.js.map +1 -0
  46. package/dist/react/page-agent-chat.d.ts +38 -0
  47. package/dist/react/page-agent-chat.js +40 -0
  48. package/dist/react/page-agent-chat.js.map +1 -0
  49. package/dist/react.d.ts +7 -2
  50. package/dist/react.js +3 -1
  51. package/dist/react.js.map +1 -1
  52. package/dist/ui/index.js +82 -78
  53. package/dist/ui/web-client.js +187 -12
  54. package/docs/agents.md +26 -4
  55. package/docs/browser.md +200 -0
  56. package/docs/react.md +14 -13
  57. package/docs/semver.md +2 -0
  58. package/package.json +5 -1
@@ -0,0 +1,610 @@
1
+ import { approximateSize, EventQueue } from '../agents/event-queue.js';
2
+ import { resolvePermissions, unsupportedPermissions } from '../agents/permissions.js';
3
+ import { abortable, builtInLanguageModel, contextOf, expectedText, languageModelAvailability, streamDeltas, } from './language-model.js';
4
+ import { argumentProblems, schemaProperties, toolText } from './tools.js';
5
+ const REPLY = 'reply';
6
+ // A page has no sandbox to switch on; `read-only` is honored by refusing `write` tools.
7
+ const capabilities = {
8
+ usage: true,
9
+ approvals: true,
10
+ resume: true,
11
+ maxTurns: true,
12
+ permissions: { approval: ['ask', 'auto-approve', 'deny'], sandbox: ['read-only'] },
13
+ };
14
+ const KEPT_SESSIONS = 4;
15
+ /** A rough size of a token, for steps the browser gives no count for. */
16
+ const CHARACTERS_PER_TOKEN = 4;
17
+ /**
18
+ * The browser's built-in model (Gemini Nano through Chrome's Prompt API) as a genaicode agent.
19
+ * It runs in the page, costs nothing and sends nothing to a server; it is a small model, good
20
+ * for one or two tool calls and a short answer, not for coding.
21
+ *
22
+ * The Prompt API has no tool calling, so each step is a constrained choice: the model picks a
23
+ * tool or `reply`, then fills in that tool's arguments against its JSON Schema, and the final
24
+ * answer streams as text. `write` tools go through `task.onApproval` first, and never run under
25
+ * `permissions.sandbox: 'read-only'`; other sandbox values fail the task, as a page has none. `task.resume`
26
+ * continues a conversation; `task.cwd`, `env` and `mcpServers` mean nothing here.
27
+ */
28
+ export function nano(options = {}) {
29
+ const name = options.name ?? 'nano';
30
+ const language = options.language ?? 'en';
31
+ const maxSteps = options.maxSteps ?? 6;
32
+ const maxToolOutput = options.maxToolOutput ?? 2_000;
33
+ const maxAttachmentText = options.maxAttachmentText ?? 4_000;
34
+ const factory = () => options.languageModel ?? builtInLanguageModel();
35
+ // Asked once: every conversation is opened for the same inputs, so any of them takes any task.
36
+ let asked;
37
+ const inputs = () => (asked ??= (async () => {
38
+ const taken = [];
39
+ for (const type of new Set(options.inputs ?? [])) {
40
+ if ((await languageModelAvailability(language, factory(), [...taken, type])) !== 'unavailable')
41
+ taken.push(type);
42
+ }
43
+ return taken;
44
+ })());
45
+ // Insertion order is age: the oldest conversation is dropped first.
46
+ const sessions = new Map();
47
+ let nextSession = 1;
48
+ const monitor = (target) => {
49
+ target.addEventListener('downloadprogress', (event) => {
50
+ const loaded = event.loaded;
51
+ if (typeof loaded === 'number')
52
+ options.onDownload?.(Math.max(0, Math.min(1, loaded)));
53
+ });
54
+ };
55
+ // How many running tasks use each conversation.
56
+ const busy = new Map();
57
+ const forget = (sessionId) => {
58
+ for (const [id, session] of sessions) {
59
+ if (sessionId !== undefined && id !== sessionId)
60
+ continue;
61
+ sessions.delete(id);
62
+ try {
63
+ session.destroy();
64
+ }
65
+ catch {
66
+ // Already gone.
67
+ }
68
+ }
69
+ };
70
+ async function open(tools, signal) {
71
+ const model = factory();
72
+ if (!model)
73
+ throw new Error('This browser has no built-in language model (the Prompt API is missing).');
74
+ const created = model.create({
75
+ initialPrompts: [{ role: 'system', content: briefing(options.instructions, tools) }],
76
+ ...expectedText(language, await abortable(inputs(), signal)),
77
+ monitor,
78
+ signal,
79
+ });
80
+ // A session that arrives after the task was stopped has no owner: release it.
81
+ created.then((late) => {
82
+ if (signal.aborted)
83
+ late.destroy();
84
+ }, () => { });
85
+ return abortable(created, signal);
86
+ }
87
+ function run(task) {
88
+ const events = new EventQueue(approximateSize);
89
+ const controller = new AbortController();
90
+ const { signal } = controller;
91
+ const abort = () => controller.abort();
92
+ if (task.signal?.aborted)
93
+ abort();
94
+ else
95
+ task.signal?.addEventListener('abort', abort, { once: true });
96
+ let timedOut = false;
97
+ const timer = task.timeoutMs === undefined
98
+ ? undefined
99
+ : setTimeout(() => {
100
+ timedOut = true;
101
+ abort();
102
+ }, task.timeoutMs);
103
+ const emit = (event) => events.push(event);
104
+ // What this task spent: the growth of the context in use, step by step.
105
+ const meter = { last: 0, tokens: 0, reported: false, warned: false, over: false };
106
+ const report = (session, characters) => {
107
+ const used = contextOf(session);
108
+ if (!used)
109
+ return;
110
+ const grown = used.used - meter.last;
111
+ meter.last = used.used;
112
+ // A full window drops old messages, so the count stalls or falls: estimate that step from its text.
113
+ const tokens = grown > 0 ? grown : Math.ceil(characters / CHARACTERS_PER_TOKEN);
114
+ if (tokens > 0)
115
+ spend(tokens);
116
+ };
117
+ const spend = (tokens) => {
118
+ meter.tokens += tokens;
119
+ meter.reported = true;
120
+ emit({ type: 'usage', usage: { totalTokens: meter.tokens } });
121
+ const limit = task.budget?.maxTokens;
122
+ if (limit === undefined)
123
+ return;
124
+ if (meter.tokens > limit) {
125
+ meter.over = true;
126
+ throw new Error(`${name} went over its token budget (${meter.tokens} of ${limit}).`);
127
+ }
128
+ if (!meter.warned && meter.tokens >= limit * (task.budget?.warnAt ?? 0.8)) {
129
+ meter.warned = true;
130
+ emit({ type: 'budget-warning', warning: { kind: 'tokens', used: meter.tokens, limit } });
131
+ }
132
+ };
133
+ const finish = (status, sessionId, text, error) => {
134
+ const result = {
135
+ status,
136
+ ok: status === 'completed',
137
+ exitCode: null,
138
+ signal: null,
139
+ ...(sessionId ? { sessionId } : {}),
140
+ ...(text !== undefined ? { text } : {}),
141
+ ...(meter.reported ? { usage: { totalTokens: meter.tokens } } : {}),
142
+ ...(error ? { error } : {}),
143
+ ...(meter.over ? { failure: { kind: 'budget' } } : {}),
144
+ };
145
+ emit({ type: 'done', result });
146
+ events.close();
147
+ if (timer)
148
+ clearTimeout(timer);
149
+ task.signal?.removeEventListener('abort', abort);
150
+ return result;
151
+ };
152
+ const work = async () => {
153
+ let sessionId;
154
+ let held;
155
+ try {
156
+ const refused = unsupportedPermissions(name, capabilities, task);
157
+ if (refused)
158
+ throw new Error(refused);
159
+ const tools = typeof options.tools === 'function'
160
+ ? await abortable(Promise.resolve(options.tools()), signal)
161
+ : (options.tools ?? []);
162
+ const taken = await abortable(inputs(), signal);
163
+ const attached = await abortable(attach(task.attachments ?? [], taken, maxAttachmentText), signal);
164
+ let session = task.resume ? sessions.get(task.resume) : undefined;
165
+ sessionId = session ? task.resume : undefined;
166
+ // A new conversation's instructions count as this task's tokens.
167
+ meter.last = session ? (contextOf(session)?.used ?? 0) : 0;
168
+ if (!session) {
169
+ session = await open(tools, signal);
170
+ sessionId = `nano-${nextSession++}`;
171
+ sessions.set(sessionId, session);
172
+ }
173
+ busy.set(sessionId, (busy.get(sessionId) ?? 0) + 1);
174
+ held = sessionId;
175
+ // The oldest conversations go, but never one a task is still running in.
176
+ for (const id of [...sessions.keys()]) {
177
+ if (sessions.size <= KEPT_SESSIONS)
178
+ break;
179
+ if (!busy.has(id))
180
+ forget(id);
181
+ }
182
+ emit({ type: 'session', sessionId: sessionId, model: options.model ?? 'on-device' });
183
+ const live = session;
184
+ const text = await converse(live, tools, task, attached, emit, signal, (characters) => report(live, characters), {
185
+ watch: (call) => options.onModelCall?.(call),
186
+ spend,
187
+ maxSteps,
188
+ maxToolOutput,
189
+ });
190
+ return finish('completed', sessionId, text);
191
+ }
192
+ catch (error) {
193
+ if (signal.aborted && !meter.over) {
194
+ return finish(timedOut ? 'timeout' : 'aborted', sessionId, undefined, timedOut ? 'Timed out.' : undefined);
195
+ }
196
+ const message = describe(error);
197
+ emit({ type: 'error', message });
198
+ return finish('failed', sessionId, undefined, message);
199
+ }
200
+ finally {
201
+ if (held) {
202
+ const left = (busy.get(held) ?? 1) - 1;
203
+ if (left > 0)
204
+ busy.set(held, left);
205
+ else
206
+ busy.delete(held);
207
+ }
208
+ }
209
+ };
210
+ const result = work();
211
+ return {
212
+ result,
213
+ abort,
214
+ [Symbol.asyncIterator]: () => events.iterate(),
215
+ };
216
+ }
217
+ return {
218
+ name,
219
+ command: 'LanguageModel',
220
+ capabilities,
221
+ run,
222
+ availability: () => languageModelAvailability(language, factory()),
223
+ async prepare(signal) {
224
+ const model = factory();
225
+ if (!model)
226
+ throw new Error('This browser has no built-in language model (the Prompt API is missing).');
227
+ const taken = signal ? await abortable(inputs(), signal) : await inputs();
228
+ const session = await model.create({ ...expectedText(language, taken), monitor, signal });
229
+ session.destroy();
230
+ },
231
+ context: (sessionId) => {
232
+ const session = sessions.get(sessionId);
233
+ return session ? contextOf(session) : undefined;
234
+ },
235
+ forget,
236
+ inputs,
237
+ };
238
+ }
239
+ /** One task: choose a tool or reply, until the model replies or runs out of steps. */
240
+ async function converse(session, tools, task, attached, emit, signal, report, limits) {
241
+ const steps = Math.max(0, Math.min(limits.maxSteps, task.maxTurns ?? limits.maxSteps));
242
+ const { watch, spend } = limits;
243
+ // Steps asked on copies are metered there; asked of the conversation, they show in its own count.
244
+ const copies = typeof session.clone === 'function';
245
+ // Every step is asked on a copy of the conversation (see `structured`), so each one is told the
246
+ // whole task so far, and the conversation itself hears it once, with the request for the reply.
247
+ const { media } = attached;
248
+ const reply = async (input) => {
249
+ let text = '';
250
+ for (let attempt = 1;; attempt++) {
251
+ const started = Date.now();
252
+ try {
253
+ for await (const delta of streamDeltas(session.promptStreaming(message(input, media), { signal }), signal)) {
254
+ text += delta;
255
+ emit({ type: 'text-delta', text: delta });
256
+ }
257
+ watch({ step: 'reply', ms: Date.now() - started, constrained: false });
258
+ break;
259
+ }
260
+ catch (error) {
261
+ if (signal.aborted)
262
+ throw error;
263
+ watch({ step: 'reply', ms: Date.now() - started, constrained: false, error: describe(error) });
264
+ // Once the user saw text, a second try would say it twice.
265
+ if (text || attempt > 1 || permanent(error))
266
+ throw new Error(`Writing the reply failed: ${describe(error)}`);
267
+ }
268
+ }
269
+ signal.throwIfAborted();
270
+ notAStub(text);
271
+ emit({ type: 'message', text });
272
+ report(pending + input.length + text.length);
273
+ return text;
274
+ };
275
+ // Text exchanged with the model since the last usage report.
276
+ let pending = 0;
277
+ let story = `User: ${task.prompt.trim() || '(no text: see what is attached)'}${attached.text}`;
278
+ if (!tools.length)
279
+ return reply(story);
280
+ // A new conversation's instructions are already in its context: count them before any tool runs.
281
+ if (copies)
282
+ report(0);
283
+ const called = new Set();
284
+ for (let step = 0; step < steps; step++) {
285
+ const action = await choose(session, story, tools, media, signal, watch, spend);
286
+ if (!copies)
287
+ report(pending + story.length + action.length);
288
+ pending = 0;
289
+ if (action === REPLY)
290
+ return reply(`${story}\n\nWrite your reply to the user.`);
291
+ const tool = tools.find((candidate) => candidate.name === action);
292
+ const args = await fillArguments(session, story, tool, media, signal, watch, spend);
293
+ if (!copies)
294
+ pending += stableJson(args).length;
295
+ const id = `call-${step + 1}`;
296
+ emit({ type: 'tool-start', id, name: tool.name, input: args });
297
+ const key = `${tool.name} ${stableJson(args)}`;
298
+ let output;
299
+ let isError = false;
300
+ if (called.has(key)) {
301
+ // A small model can loop on one call; say so instead of running it again.
302
+ output = 'You already made this exact call. Use its result above and reply to the user.';
303
+ isError = true;
304
+ }
305
+ else {
306
+ called.add(key);
307
+ try {
308
+ output = await invoke(tool, args, id, task, emit, signal);
309
+ }
310
+ catch (error) {
311
+ if (signal.aborted)
312
+ throw error;
313
+ output = describe(error);
314
+ isError = true;
315
+ }
316
+ }
317
+ signal.throwIfAborted();
318
+ const shown = clip(output, limits.maxToolOutput);
319
+ emit({ type: 'tool-end', id, name: tool.name, output: shown, ...(isError ? { isError } : {}) });
320
+ story += `\n\nYou called ${tool.name} with ${stableJson(args)}.\n${isError ? `The call to ${tool.name} failed: ${shown}` : `Result of ${tool.name}:\n${shown}`}`;
321
+ }
322
+ return reply(`${story}\n\nNow write your reply to the user.`);
323
+ }
324
+ /**
325
+ * Run `ask` on a copy of the conversation and let the copy go. Chrome keeps the first
326
+ * `responseConstraint` a session was given: a later prompt with another schema fails with
327
+ * `UnknownError` or answers in the first one's shape, and a plain prompt gets JSON appended. So
328
+ * no constrained prompt is sent to the conversation itself. A browser without `clone()` gets the
329
+ * conversation, as before.
330
+ */
331
+ async function onCopy(session, signal, ask) {
332
+ if (typeof session.clone !== 'function')
333
+ return ask(session, true);
334
+ const made = session.clone({ signal });
335
+ // A copy that arrives after the task was stopped has no owner: release it.
336
+ made.then((copy) => signal.aborted && copy.destroy(), () => { });
337
+ const copy = await abortable(made, signal);
338
+ try {
339
+ return await ask(copy, false);
340
+ }
341
+ finally {
342
+ try {
343
+ copy.destroy();
344
+ }
345
+ catch {
346
+ // Already gone.
347
+ }
348
+ }
349
+ }
350
+ const ANNOTATIONS = new Set(['description', 'title', 'default', 'examples', '$comment', 'deprecated']);
351
+ const SCHEMA_MAPS = new Set(['properties', 'patternProperties', '$defs', 'definitions']);
352
+ /** `schema` without the keywords that only describe: they tell a model things, they constrain nothing. */
353
+ function constraintOf(schema) {
354
+ if (Array.isArray(schema))
355
+ return schema.map(constraintOf);
356
+ if (!schema || typeof schema !== 'object')
357
+ return schema;
358
+ const out = {};
359
+ for (const [key, value] of Object.entries(schema)) {
360
+ if (ANNOTATIONS.has(key))
361
+ continue;
362
+ if (key === 'enum' || key === 'const' || key === 'required')
363
+ out[key] = value;
364
+ else if (SCHEMA_MAPS.has(key) && value && typeof value === 'object' && !Array.isArray(value))
365
+ // Keys here are property names, not keywords: a property may be called "title".
366
+ out[key] = Object.fromEntries(Object.entries(value).map(([name, sub]) => [name, constraintOf(sub)]));
367
+ else
368
+ out[key] = constraintOf(value);
369
+ }
370
+ return out;
371
+ }
372
+ /**
373
+ * Ask for JSON that follows `schema`. The browser holds the model to it; when that call fails
374
+ * (Chrome answers some with an unexplained error), the model is asked in words instead and the
375
+ * answer is checked here against the tool's schema (`argumentProblems`) before the tool runs.
376
+ */
377
+ async function structured(session, step, question, schema, media, signal, watch, spend,
378
+ /** The question already says what shape is wanted: do not spend context on the schema. */
379
+ told = false) {
380
+ // What the copies used. Counted once the answer is in: going over budget is not a failed call.
381
+ let owed = 0;
382
+ const answer = await asked();
383
+ if (owed)
384
+ spend(owed);
385
+ return answer;
386
+ async function asked() {
387
+ const ask = async (text, constraint) => {
388
+ const started = Date.now();
389
+ const constrained = constraint !== undefined;
390
+ try {
391
+ const raw = await onCopy(session, signal, async (copy, own) => {
392
+ const before = contextOf(copy)?.used;
393
+ const out = await abortable(copy.prompt(message(text, media), { signal, ...constraint }), signal);
394
+ const after = contextOf(copy)?.used;
395
+ if (!own && before !== undefined && after !== undefined) {
396
+ owed += after > before ? after - before : Math.ceil((text.length + out.length) / CHARACTERS_PER_TOKEN);
397
+ }
398
+ return out;
399
+ });
400
+ watch({ step, ms: Date.now() - started, constrained });
401
+ return raw;
402
+ }
403
+ catch (error) {
404
+ if (!signal.aborted)
405
+ watch({ step, ms: Date.now() - started, constrained, error: describe(error) });
406
+ throw error;
407
+ }
408
+ };
409
+ try {
410
+ // The schema goes into the prompt here, in full, and the browser gets only what constrains
411
+ // the answer: Chrome failed calls where it was left to add a schema with annotations itself.
412
+ const text = told ? question : `${question}\nIt must follow this JSON Schema: ${JSON.stringify(schema)}`;
413
+ return await ask(text, {
414
+ responseConstraint: constraintOf(schema),
415
+ omitResponseConstraintInput: true,
416
+ });
417
+ }
418
+ catch (error) {
419
+ if (signal.aborted)
420
+ throw error;
421
+ const doing = step === 'choose' ? 'Choosing the next action' : 'Filling in the arguments';
422
+ if (permanent(error))
423
+ throw new Error(`${doing} failed: ${describe(error)}`);
424
+ try {
425
+ return await ask(`${question}\nAnswer with JSON only, following this JSON Schema: ${JSON.stringify(schema)}`);
426
+ }
427
+ catch (second) {
428
+ if (signal.aborted)
429
+ throw second;
430
+ throw new Error(`${doing} failed: ${describe(second)}`);
431
+ }
432
+ }
433
+ }
434
+ }
435
+ const TEXT_TYPES = /^(text\/|application\/(json|xml|javascript|typescript|x-yaml|yaml|toml|x-sh|sql|csv)\b)/;
436
+ const TEXT_NAMES = /\.(txt|md|markdown|json|jsonl|csv|tsv|ya?ml|toml|xml|html?|css|js|jsx|mjs|cjs|ts|tsx|py|rb|go|rs|java|kt|c|h|cpp|cs|php|sh|sql|log|ini|env|gd)$/i;
437
+ async function attach(files, taken, maxText) {
438
+ const attached = { text: '', media: [] };
439
+ for (const [index, file] of files.entries()) {
440
+ const name = file.name;
441
+ const label = typeof name === 'string' && name ? name : `attachment ${index + 1}`;
442
+ const kind = file.type.startsWith('image/') ? 'image' : file.type.startsWith('audio/') ? 'audio' : undefined;
443
+ if (kind) {
444
+ if (!taken.includes(kind)) {
445
+ throw new Error(`"${label}" cannot be attached: the model in this browser does not take ${kind === 'image' ? 'images' : 'audio'}.`);
446
+ }
447
+ attached.media.push({ type: kind, value: file });
448
+ attached.text += `\n\nAttached ${kind}: "${label}".`;
449
+ }
450
+ else if (TEXT_TYPES.test(file.type) || TEXT_NAMES.test(label)) {
451
+ const text = await file.text();
452
+ const cut = text.length > maxText;
453
+ attached.text += `\n\nAttached file "${label}"${cut ? ` (the first ${maxText} of ${text.length} characters)` : ''}:\n${cut ? text.slice(0, maxText) : text}`;
454
+ }
455
+ else {
456
+ throw new Error(`"${label}" cannot be attached: the model reads text files${taken.length ? `, ${taken.join(' and ')}` : ''} only.`);
457
+ }
458
+ }
459
+ return attached;
460
+ }
461
+ /** A prompt as the Prompt API takes it: plain text, or text with images and audio after it. */
462
+ function message(text, media) {
463
+ return media.length ? [{ role: 'user', content: [{ type: 'text', value: text }, ...media] }] : text;
464
+ }
465
+ /** An error a second try cannot fix. */
466
+ function permanent(error) {
467
+ return error instanceof Error && error.name === 'QuotaExceededError';
468
+ }
469
+ /** Step one: which tool, or `reply`. */
470
+ async function choose(session, input, tools, media, signal, watch, spend) {
471
+ const names = [...tools.map((tool) => tool.name), REPLY];
472
+ const question = `${input}\n\nWhat is the next action? Answer as JSON {"action": "..."} with one of: ${names.join(', ')}.`;
473
+ const raw = await structured(session, 'choose', question, {
474
+ type: 'object',
475
+ properties: { action: { type: 'string', enum: names } },
476
+ required: ['action'],
477
+ additionalProperties: false,
478
+ }, media, signal, watch, spend, true);
479
+ notAStub(raw);
480
+ const action = parseObject(raw)?.action;
481
+ return typeof action === 'string' && names.includes(action) ? action : REPLY;
482
+ }
483
+ /** Step two: the chosen tool's arguments, constrained by its schema. */
484
+ async function fillArguments(session, story, tool, media, signal, watch, spend) {
485
+ if (!Object.keys(schemaProperties(tool)).length)
486
+ return {};
487
+ const raw = await structured(session, 'arguments', `${story}\n\nYou chose to call ${tool.name}. Give the arguments for ${tool.name} as a JSON object.`, { type: 'object', additionalProperties: false, ...tool.inputSchema }, media, signal, watch, spend);
488
+ const args = parseObject(raw);
489
+ // No arguments is not the same as an answer that has none: do not run the tool on a guess.
490
+ if (!args)
491
+ throw new Error(`Filling in the arguments failed: the model did not answer with a JSON object.`);
492
+ // Asked in words, a model may add arguments the schema does not have; the browser never lets it.
493
+ const open = tool.inputSchema?.additionalProperties;
494
+ if (open === true || (open && typeof open === 'object') || tool.inputSchema?.patternProperties)
495
+ return args;
496
+ const known = schemaProperties(tool);
497
+ return Object.fromEntries(Object.entries(args).filter(([key]) => key in known));
498
+ }
499
+ /** Check the arguments, ask the user about a `write` tool, then run it. */
500
+ async function invoke(tool, args, id, task, emit, signal) {
501
+ const problems = argumentProblems(tool, args);
502
+ if (problems.length)
503
+ throw new Error(`Bad arguments: ${problems.join('; ')}.`);
504
+ tool.validate?.(args);
505
+ if (tool.write) {
506
+ const permissions = resolvePermissions(task.permissions);
507
+ if (permissions.sandbox === 'read-only')
508
+ throw new Error('Not allowed: this task is read-only.');
509
+ const approval = permissions.approval ?? 'ask';
510
+ const request = {
511
+ id,
512
+ kind: 'other',
513
+ summary: tool.summary?.(args) ?? `${tool.name} ${stableJson(args)}`,
514
+ detail: { tool: tool.name, args },
515
+ scope: 'once',
516
+ };
517
+ if (approval === 'deny')
518
+ throw new Error('Not allowed: this needs the user’s approval.');
519
+ emit({ type: 'approval-request', request });
520
+ let decision = 'deny';
521
+ if (approval === 'auto-approve')
522
+ decision = 'approve';
523
+ else if (task.onApproval) {
524
+ try {
525
+ decision =
526
+ (await abortable(Promise.resolve(task.onApproval(request, signal)), signal)) === 'approve'
527
+ ? 'approve'
528
+ : 'deny';
529
+ }
530
+ catch {
531
+ decision = 'deny';
532
+ }
533
+ }
534
+ if (signal.aborted)
535
+ decision = 'deny';
536
+ emit({
537
+ type: 'approval-resolved',
538
+ id,
539
+ decision,
540
+ ...(approval === 'auto-approve' ? { automatic: true } : {}),
541
+ });
542
+ signal.throwIfAborted();
543
+ if (decision !== 'approve')
544
+ throw new Error('The user declined this action.');
545
+ }
546
+ return toolText(await abortable(Promise.resolve(tool.run(args, signal)), signal));
547
+ }
548
+ /** Chromium builds without the model ship a Prompt API that says so and echoes the prompt. */
549
+ function notAStub(reply) {
550
+ if (/^On-device model is not available/i.test(reply)) {
551
+ throw new Error('This browser build has the Prompt API but no on-device model behind it.');
552
+ }
553
+ }
554
+ /** What the model is told once, as the system prompt. */
555
+ export function briefing(instructions, tools) {
556
+ const lines = [];
557
+ if (instructions?.trim())
558
+ lines.push(instructions.trim(), '');
559
+ if (tools.length) {
560
+ lines.push('You can act through these tools:');
561
+ for (const tool of tools)
562
+ lines.push(`- ${signature(tool)}: ${tool.description}`);
563
+ lines.push('', 'You work in steps. Each step you either pick one tool or pick "reply".', '- Pick a tool when the user asks for something a tool does, or when you need facts a tool returns.', '- Pick "reply" as soon as you can answer. Do not repeat a call you already made.', '- Never make up a tool result or a fact about the page.');
564
+ }
565
+ lines.push('Replies are short and plain: a few sentences, in the language the user writes in.');
566
+ return lines.join('\n');
567
+ }
568
+ function signature(tool) {
569
+ const required = new Set(Array.isArray(tool.inputSchema?.required) ? tool.inputSchema.required : []);
570
+ const parts = Object.entries(schemaProperties(tool)).map(([name, schema]) => {
571
+ const type = Array.isArray(schema.enum)
572
+ ? schema.enum.map((item) => JSON.stringify(item)).join('|')
573
+ : typeof schema.type === 'string'
574
+ ? schema.type
575
+ : 'any';
576
+ return `${name}${required.has(name) ? '' : '?'}: ${type}`;
577
+ });
578
+ return `${tool.name}(${parts.join(', ')})`;
579
+ }
580
+ /** The first JSON object in `raw`, or undefined. A constrained reply is the object itself. */
581
+ function parseObject(raw) {
582
+ const start = raw.indexOf('{');
583
+ const end = raw.lastIndexOf('}');
584
+ if (start < 0 || end <= start)
585
+ return undefined;
586
+ try {
587
+ const value = JSON.parse(raw.slice(start, end + 1));
588
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
589
+ }
590
+ catch {
591
+ return undefined;
592
+ }
593
+ }
594
+ function stableJson(value) {
595
+ return JSON.stringify(Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b))));
596
+ }
597
+ function clip(text, max) {
598
+ return text.length <= max ? text : `${text.slice(0, max)}\n[cut: ${text.length - max} more characters]`;
599
+ }
600
+ function describe(error) {
601
+ if (error instanceof Error) {
602
+ if (error.name === 'QuotaExceededError')
603
+ return 'The conversation no longer fits the model’s context window.';
604
+ if (error.name === 'NotSupportedError')
605
+ return `The built-in model cannot do this here: ${error.message}`;
606
+ return error.message || error.name;
607
+ }
608
+ return String(error);
609
+ }
610
+ //# sourceMappingURL=nano.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nano.js","sourceRoot":"","sources":["../../src/browser/nano.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAWtF,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,YAAY,EACZ,yBAAyB,EACzB,YAAY,GAQb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,E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