genaicode 2.32.0 → 2.34.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.
- package/README.md +2 -0
- package/dist/agents/drivers/anthropic-managed.d.ts +141 -0
- package/dist/agents/drivers/anthropic-managed.js +753 -0
- package/dist/agents/drivers/anthropic-managed.js.map +1 -0
- package/dist/agents/drivers/cursor-cloud.d.ts +78 -0
- package/dist/agents/drivers/cursor-cloud.js +478 -0
- package/dist/agents/drivers/cursor-cloud.js.map +1 -0
- package/dist/agents/drivers/gemini-managed.d.ts +78 -0
- package/dist/agents/drivers/gemini-managed.js +526 -0
- package/dist/agents/drivers/gemini-managed.js.map +1 -0
- package/dist/agents/drivers/managed-http.d.ts +28 -0
- package/dist/agents/drivers/managed-http.js +142 -0
- package/dist/agents/drivers/managed-http.js.map +1 -0
- package/dist/agents/drivers/openai-managed.d.ts +79 -0
- package/dist/agents/drivers/openai-managed.js +402 -0
- package/dist/agents/drivers/openai-managed.js.map +1 -0
- package/dist/agents/failover.d.ts +19 -1
- package/dist/agents/failover.js +63 -2
- package/dist/agents/failover.js.map +1 -1
- package/dist/agents/hosted.d.ts +5 -1
- package/dist/agents/hosted.js +45 -132
- package/dist/agents/hosted.js.map +1 -1
- package/dist/agents/managed.d.ts +154 -0
- package/dist/agents/managed.js +561 -0
- package/dist/agents/managed.js.map +1 -0
- package/dist/agents/runtime.d.ts +5 -1
- package/dist/agents/runtime.js +9 -0
- package/dist/agents/runtime.js.map +1 -1
- package/dist/agents/session.d.ts +11 -0
- package/dist/agents/session.js.map +1 -1
- package/dist/agents.d.ts +11 -1
- package/dist/agents.js +6 -1
- package/dist/agents.js.map +1 -1
- package/dist/backend/backend.d.ts +131 -0
- package/dist/backend/backend.js +773 -0
- package/dist/backend/backend.js.map +1 -0
- package/dist/backend/limiter.d.ts +34 -0
- package/dist/backend/limiter.js +76 -0
- package/dist/backend/limiter.js.map +1 -0
- package/dist/backend/node.d.ts +10 -0
- package/dist/backend/node.js +124 -0
- package/dist/backend/node.js.map +1 -0
- package/dist/backend/protocol.d.ts +98 -0
- package/dist/backend/protocol.js +2 -0
- package/dist/backend/protocol.js.map +1 -0
- package/dist/backend/seal.d.ts +7 -0
- package/dist/backend/seal.js +60 -0
- package/dist/backend/seal.js.map +1 -0
- package/dist/backend.d.ts +27 -0
- package/dist/backend.js +25 -0
- package/dist/backend.js.map +1 -0
- package/dist/browser/fake-model.d.ts +43 -0
- package/dist/browser/fake-model.js +133 -0
- package/dist/browser/fake-model.js.map +1 -0
- package/dist/browser/invoke.d.ts +17 -0
- package/dist/browser/invoke.js +69 -0
- package/dist/browser/invoke.js.map +1 -0
- package/dist/browser/language-model.d.ts +74 -0
- package/dist/browser/language-model.js +83 -0
- package/dist/browser/language-model.js.map +1 -0
- package/dist/browser/nano.d.ts +93 -0
- package/dist/browser/nano.js +564 -0
- package/dist/browser/nano.js.map +1 -0
- package/dist/browser/page-agent.d.ts +81 -0
- package/dist/browser/page-agent.js +360 -0
- package/dist/browser/page-agent.js.map +1 -0
- package/dist/browser/remote.d.ts +44 -0
- package/dist/browser/remote.js +372 -0
- package/dist/browser/remote.js.map +1 -0
- package/dist/browser/tools.d.ts +36 -0
- package/dist/browser/tools.js +190 -0
- package/dist/browser/tools.js.map +1 -0
- package/dist/browser/webmcp.d.ts +32 -0
- package/dist/browser/webmcp.js +150 -0
- package/dist/browser/webmcp.js.map +1 -0
- package/dist/browser.d.ts +46 -0
- package/dist/browser.js +38 -0
- package/dist/browser.js.map +1 -0
- package/dist/core/types.d.ts +5 -0
- package/dist/core/types.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/google-converter.js +3 -0
- package/dist/providers/google-converter.js.map +1 -1
- package/dist/providers/google.js +7 -10
- package/dist/providers/google.js.map +1 -1
- package/dist/react/agent-chat.css +141 -0
- package/dist/react/agent-chat.d.ts +12 -2
- package/dist/react/agent-chat.js +32 -4
- package/dist/react/agent-chat.js.map +1 -1
- package/dist/react/attachments.d.ts +41 -0
- package/dist/react/attachments.js +162 -0
- package/dist/react/attachments.js.map +1 -0
- package/dist/react/page-agent-chat.d.ts +38 -0
- package/dist/react/page-agent-chat.js +44 -0
- package/dist/react/page-agent-chat.js.map +1 -0
- package/dist/react.d.ts +6 -1
- package/dist/react.js +2 -0
- package/dist/react.js.map +1 -1
- package/dist/ui/web-client.js +154 -13
- package/docs/CHANGELOG.md +38 -395
- package/docs/agents.md +207 -1
- package/docs/backend.md +125 -0
- package/docs/browser.md +205 -0
- package/docs/changelog-2.26-and-older.md +441 -0
- package/docs/pivot.md +1 -1
- package/docs/semver.md +2 -0
- package/package.json +9 -1
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { approximateSize, EventQueue } from '../agents/event-queue.js';
|
|
2
|
+
import { unsupportedPermissions } from '../agents/permissions.js';
|
|
3
|
+
import { addUsage } from '../agents/usage.js';
|
|
4
|
+
import { ask, invoke } from './invoke.js';
|
|
5
|
+
import { abortable } from './language-model.js';
|
|
6
|
+
import { TEXT_NAMES, TEXT_TYPES } from './nano.js';
|
|
7
|
+
// A page has no sandbox to switch on; `read-only` is honored by refusing `write` tools.
|
|
8
|
+
const capabilities = {
|
|
9
|
+
usage: true,
|
|
10
|
+
approvals: true,
|
|
11
|
+
resume: true,
|
|
12
|
+
permissions: { approval: ['ask', 'auto-approve', 'deny'], sandbox: ['read-only'] },
|
|
13
|
+
};
|
|
14
|
+
const KEPT_SESSIONS = 8;
|
|
15
|
+
const IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp']);
|
|
16
|
+
class Failed extends Error {
|
|
17
|
+
failure;
|
|
18
|
+
status;
|
|
19
|
+
constructor(message, failure, status) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.failure = failure;
|
|
22
|
+
this.status = status;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The page's assistant on a model behind your server: the server (`createAgentBackend()` from
|
|
27
|
+
* `genaicode/backend`) holds the model and its key, the page runs its own tools when the model
|
|
28
|
+
* calls them and asks the user before a `write` tool, as with `nano()`. Use it as
|
|
29
|
+
* `createPageAgent({ agent: remote({ url, tools }) })`, or with `withFallback([remote(...), nano(...)])`
|
|
30
|
+
* so the page goes on with the built-in model when the backend is out (signed out, over its
|
|
31
|
+
* allowance, down).
|
|
32
|
+
*/
|
|
33
|
+
export function remote(options) {
|
|
34
|
+
const name = options.name ?? 'assistant';
|
|
35
|
+
const base = options.url.replace(/\/$/, '');
|
|
36
|
+
const maxAttachmentText = options.maxAttachmentText ?? 4_000;
|
|
37
|
+
const maxToolOutput = options.maxToolOutput ?? 8_000;
|
|
38
|
+
// The backend's token for each conversation; insertion order is age.
|
|
39
|
+
const sessions = new Map();
|
|
40
|
+
let nextSession = 1;
|
|
41
|
+
const doFetch = (input, init) => (options.fetch ?? globalThis.fetch)(input, init);
|
|
42
|
+
async function post(body, signal, emit) {
|
|
43
|
+
let response;
|
|
44
|
+
try {
|
|
45
|
+
response = await doFetch(`${base}/turn`, {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
headers: {
|
|
48
|
+
'content-type': 'application/json',
|
|
49
|
+
...(await abortable(Promise.resolve(options.headers?.()), signal)),
|
|
50
|
+
},
|
|
51
|
+
body: JSON.stringify(body),
|
|
52
|
+
credentials: options.credentials ?? 'same-origin',
|
|
53
|
+
signal,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
signal.throwIfAborted();
|
|
58
|
+
throw new Failed(`The assistant's server cannot be reached: ${describe(error)}`, { kind: 'unavailable' });
|
|
59
|
+
}
|
|
60
|
+
if (!response.ok)
|
|
61
|
+
throw await refusal(response);
|
|
62
|
+
if (!response.body)
|
|
63
|
+
throw new Failed('The assistant sent nothing back.', { kind: 'crash' });
|
|
64
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
65
|
+
let buffer = '';
|
|
66
|
+
for (;;) {
|
|
67
|
+
let chunk;
|
|
68
|
+
try {
|
|
69
|
+
chunk = await reader.read();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
signal.throwIfAborted();
|
|
73
|
+
throw new Failed(`The connection to the assistant broke: ${describe(error)}`, { kind: 'unavailable' });
|
|
74
|
+
}
|
|
75
|
+
const { done, value } = chunk;
|
|
76
|
+
if (value)
|
|
77
|
+
buffer += value;
|
|
78
|
+
let newline;
|
|
79
|
+
while ((newline = buffer.indexOf('\n')) >= 0) {
|
|
80
|
+
const line = buffer.slice(0, newline).trim();
|
|
81
|
+
buffer = buffer.slice(newline + 1);
|
|
82
|
+
if (!line)
|
|
83
|
+
continue;
|
|
84
|
+
let parsed;
|
|
85
|
+
try {
|
|
86
|
+
parsed = JSON.parse(line);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (parsed.type === 'turn-end') {
|
|
92
|
+
void reader.cancel().catch(() => { });
|
|
93
|
+
return parsed;
|
|
94
|
+
}
|
|
95
|
+
if (parsed.type === 'text-delta' ||
|
|
96
|
+
parsed.type === 'message' ||
|
|
97
|
+
parsed.type === 'tool-start' ||
|
|
98
|
+
parsed.type === 'tool-end' ||
|
|
99
|
+
parsed.type === 'error') {
|
|
100
|
+
emit(parsed);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (done)
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
signal.throwIfAborted();
|
|
107
|
+
throw new Failed('The assistant stopped without finishing the turn.', { kind: 'crash' });
|
|
108
|
+
}
|
|
109
|
+
function run(task) {
|
|
110
|
+
const events = new EventQueue(approximateSize);
|
|
111
|
+
const controller = new AbortController();
|
|
112
|
+
const { signal } = controller;
|
|
113
|
+
const abort = () => controller.abort();
|
|
114
|
+
if (task.signal?.aborted)
|
|
115
|
+
abort();
|
|
116
|
+
else
|
|
117
|
+
task.signal?.addEventListener('abort', abort, { once: true });
|
|
118
|
+
let timedOut = false;
|
|
119
|
+
const timer = task.timeoutMs === undefined
|
|
120
|
+
? undefined
|
|
121
|
+
: setTimeout(() => {
|
|
122
|
+
timedOut = true;
|
|
123
|
+
abort();
|
|
124
|
+
}, task.timeoutMs);
|
|
125
|
+
const emit = (event) => events.push(event);
|
|
126
|
+
let tokens = 0;
|
|
127
|
+
let usage = {};
|
|
128
|
+
// A write ran (a page tool, or a server tool the user approved) during this run.
|
|
129
|
+
let acted = false;
|
|
130
|
+
let over = false;
|
|
131
|
+
const finish = (status, sessionId, extra = {}) => {
|
|
132
|
+
const result = {
|
|
133
|
+
status,
|
|
134
|
+
ok: status === 'completed',
|
|
135
|
+
exitCode: null,
|
|
136
|
+
signal: null,
|
|
137
|
+
...(sessionId ? { sessionId } : {}),
|
|
138
|
+
...(extra.text !== undefined ? { text: extra.text } : {}),
|
|
139
|
+
...(tokens ? { usage: { ...usage, totalTokens: tokens } } : {}),
|
|
140
|
+
...(extra.error ? { error: extra.error } : {}),
|
|
141
|
+
...(extra.failure ? { failure: extra.failure } : over ? { failure: { kind: 'budget' } } : {}),
|
|
142
|
+
};
|
|
143
|
+
emit({ type: 'done', result });
|
|
144
|
+
events.close();
|
|
145
|
+
if (timer)
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
task.signal?.removeEventListener('abort', abort);
|
|
148
|
+
return result;
|
|
149
|
+
};
|
|
150
|
+
const work = async () => {
|
|
151
|
+
let sessionId;
|
|
152
|
+
try {
|
|
153
|
+
const refused = unsupportedPermissions(name, capabilities, task);
|
|
154
|
+
if (refused)
|
|
155
|
+
throw new Error(refused);
|
|
156
|
+
const tools = typeof options.tools === 'function'
|
|
157
|
+
? await abortable(Promise.resolve(options.tools()), signal)
|
|
158
|
+
: (options.tools ?? []);
|
|
159
|
+
const specs = options.sendTools === false
|
|
160
|
+
? undefined
|
|
161
|
+
: tools.map((tool) => ({
|
|
162
|
+
name: tool.name,
|
|
163
|
+
description: tool.description,
|
|
164
|
+
...(tool.inputSchema ? { inputSchema: tool.inputSchema } : {}),
|
|
165
|
+
...(tool.write ? { write: true } : {}),
|
|
166
|
+
}));
|
|
167
|
+
const attached = await abortable(attach(task.attachments ?? [], maxAttachmentText), signal);
|
|
168
|
+
sessionId = task.resume && sessions.has(task.resume) ? task.resume : `remote-${nextSession++}`;
|
|
169
|
+
emit({ type: 'session', sessionId, model: name });
|
|
170
|
+
const keep = (state) => {
|
|
171
|
+
if (!state)
|
|
172
|
+
return;
|
|
173
|
+
sessions.delete(sessionId);
|
|
174
|
+
sessions.set(sessionId, state);
|
|
175
|
+
for (const id of sessions.keys()) {
|
|
176
|
+
if (sessions.size <= KEPT_SESSIONS)
|
|
177
|
+
break;
|
|
178
|
+
sessions.delete(id);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const prompt = `${task.prompt.trim()}${attached.text}`;
|
|
182
|
+
let body = {
|
|
183
|
+
...(sessions.has(sessionId) ? { state: sessions.get(sessionId) } : {}),
|
|
184
|
+
prompt,
|
|
185
|
+
...(attached.images.length ? { images: attached.images } : {}),
|
|
186
|
+
...(specs ? { tools: specs } : {}),
|
|
187
|
+
};
|
|
188
|
+
let restarted = false;
|
|
189
|
+
let step = 0;
|
|
190
|
+
for (;;) {
|
|
191
|
+
let end;
|
|
192
|
+
try {
|
|
193
|
+
end = await post(body, signal, emit);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
// An expired or foreign conversation: start a new one with this prompt, once.
|
|
197
|
+
// The token is no good for any later turn either.
|
|
198
|
+
if (error instanceof Failed && error.status === 409)
|
|
199
|
+
sessions.delete(sessionId);
|
|
200
|
+
if (error instanceof Failed && error.status === 409 && body.prompt !== undefined && !restarted) {
|
|
201
|
+
restarted = true;
|
|
202
|
+
sessions.delete(sessionId);
|
|
203
|
+
const { state: _old, ...fresh } = body;
|
|
204
|
+
void _old;
|
|
205
|
+
body = fresh;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
keep(end.state);
|
|
211
|
+
const spent = end.usage?.totalTokens ?? (end.usage?.inputTokens ?? 0) + (end.usage?.outputTokens ?? 0);
|
|
212
|
+
if (spent) {
|
|
213
|
+
tokens += spent;
|
|
214
|
+
usage = addUsage(usage, { ...end.usage, totalTokens: spent });
|
|
215
|
+
emit({ type: 'usage', usage: { ...usage, totalTokens: tokens } });
|
|
216
|
+
const limit = task.budget?.maxTokens;
|
|
217
|
+
if (limit !== undefined && tokens > limit) {
|
|
218
|
+
over = true;
|
|
219
|
+
throw new Error(`${name} went over its token budget (${tokens} of ${limit}).`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (end.status === 'failed')
|
|
223
|
+
throw new Failed(end.error ?? 'The assistant failed.', end.failure);
|
|
224
|
+
if (end.status === 'completed')
|
|
225
|
+
return finish('completed', sessionId, { text: end.text ?? '' });
|
|
226
|
+
if (task.maxTurns !== undefined && ++step > task.maxTurns) {
|
|
227
|
+
throw new Error(`${name} used its ${task.maxTurns} tool steps.`);
|
|
228
|
+
}
|
|
229
|
+
const results = [];
|
|
230
|
+
for (const call of end.calls ?? []) {
|
|
231
|
+
emit({ type: 'tool-start', id: call.id, name: call.name, input: call.input });
|
|
232
|
+
const tool = tools.find((candidate) => candidate.name === call.name);
|
|
233
|
+
let output;
|
|
234
|
+
let isError = false;
|
|
235
|
+
try {
|
|
236
|
+
if (!tool)
|
|
237
|
+
throw new Error(`This page has no tool called ${call.name}.`);
|
|
238
|
+
// Either side calling it a write is enough to ask first.
|
|
239
|
+
output = await invoke(tool, call.input ?? {}, call.id, task, emit, signal, {
|
|
240
|
+
write: call.write,
|
|
241
|
+
onWrite: () => (acted = true),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
signal.throwIfAborted();
|
|
246
|
+
output = describe(error);
|
|
247
|
+
isError = true;
|
|
248
|
+
}
|
|
249
|
+
emit({ type: 'tool-end', id: call.id, name: call.name, output, ...(isError ? { isError } : {}) });
|
|
250
|
+
results.push({ id: call.id, output: clip(output, maxToolOutput), ...(isError ? { isError } : {}) });
|
|
251
|
+
}
|
|
252
|
+
const approvals = [];
|
|
253
|
+
for (const request of end.approvals ?? []) {
|
|
254
|
+
const decision = await ask(request, task, emit, signal);
|
|
255
|
+
if (decision === 'approve')
|
|
256
|
+
acted = true;
|
|
257
|
+
approvals.push({ id: request.id, decision: decision === 'approve' ? 'approve' : 'deny' });
|
|
258
|
+
}
|
|
259
|
+
body = {
|
|
260
|
+
state: end.state,
|
|
261
|
+
...(results.length ? { results } : {}),
|
|
262
|
+
...(approvals.length ? { approvals } : {}),
|
|
263
|
+
...(!results.length && !approvals.length ? { results: [] } : {}),
|
|
264
|
+
...(specs ? { tools: specs } : {}),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
if (signal.aborted && !over) {
|
|
270
|
+
return finish(timedOut ? 'timeout' : 'aborted', sessionId, timedOut ? { error: 'Timed out.' } : {});
|
|
271
|
+
}
|
|
272
|
+
// After a write ran, another agent given the same prompt would do it again: no failover.
|
|
273
|
+
const message = acted
|
|
274
|
+
? `${describe(error)} It had already changed something, so it is not handed to another model.`
|
|
275
|
+
: describe(error);
|
|
276
|
+
emit({ type: 'error', message });
|
|
277
|
+
return finish('failed', sessionId, {
|
|
278
|
+
error: message,
|
|
279
|
+
...(error instanceof Failed && error.failure && !acted ? { failure: error.failure } : {}),
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
const result = work();
|
|
284
|
+
return {
|
|
285
|
+
result,
|
|
286
|
+
abort,
|
|
287
|
+
[Symbol.asyncIterator]: () => events.iterate(),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
name,
|
|
292
|
+
command: base,
|
|
293
|
+
capabilities,
|
|
294
|
+
run,
|
|
295
|
+
async info(signal) {
|
|
296
|
+
let response;
|
|
297
|
+
try {
|
|
298
|
+
response = await doFetch(`${base}/info`, {
|
|
299
|
+
headers: { ...(await abortable(Promise.resolve(options.headers?.()), signal)) },
|
|
300
|
+
credentials: options.credentials ?? 'same-origin',
|
|
301
|
+
...(signal ? { signal } : {}),
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
throw new Failed(`The assistant's server cannot be reached: ${describe(error)}`, { kind: 'unavailable' });
|
|
306
|
+
}
|
|
307
|
+
if (!response.ok)
|
|
308
|
+
throw await refusal(response);
|
|
309
|
+
return (await response.json());
|
|
310
|
+
},
|
|
311
|
+
forget(sessionId) {
|
|
312
|
+
if (sessionId === undefined)
|
|
313
|
+
sessions.clear();
|
|
314
|
+
else
|
|
315
|
+
sessions.delete(sessionId);
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/** A refused request as an error that says what kind of failure it was. */
|
|
320
|
+
async function refusal(response) {
|
|
321
|
+
let body = {};
|
|
322
|
+
try {
|
|
323
|
+
body = (await response.json());
|
|
324
|
+
}
|
|
325
|
+
catch {
|
|
326
|
+
// Not ours: a proxy's page.
|
|
327
|
+
}
|
|
328
|
+
const failure = body.failure ??
|
|
329
|
+
(response.status === 401 || response.status === 403
|
|
330
|
+
? { kind: 'auth' }
|
|
331
|
+
: response.status === 429
|
|
332
|
+
? { kind: 'quota' }
|
|
333
|
+
: response.status === 404 || response.status >= 500
|
|
334
|
+
? { kind: 'unavailable' }
|
|
335
|
+
: undefined);
|
|
336
|
+
const said = typeof body.error === 'string' ? body.error : response.statusText || `HTTP ${response.status}`;
|
|
337
|
+
return new Failed(`The assistant refused: ${said}.`, failure, response.status);
|
|
338
|
+
}
|
|
339
|
+
async function attach(files, maxText) {
|
|
340
|
+
const attached = { text: '', images: [] };
|
|
341
|
+
for (const [index, file] of files.entries()) {
|
|
342
|
+
const name = file.name;
|
|
343
|
+
const label = typeof name === 'string' && name ? name : `attachment ${index + 1}`;
|
|
344
|
+
if (IMAGE_TYPES.has(file.type)) {
|
|
345
|
+
attached.images.push({ mediaType: file.type, data: await base64(file), name: label });
|
|
346
|
+
attached.text += `\n\nAttached image: "${label}".`;
|
|
347
|
+
}
|
|
348
|
+
else if (TEXT_TYPES.test(file.type) || TEXT_NAMES.test(label)) {
|
|
349
|
+
const text = await file.text();
|
|
350
|
+
const cut = text.length > maxText;
|
|
351
|
+
attached.text += `\n\nAttached file "${label}"${cut ? ` (the first ${maxText} of ${text.length} characters)` : ''}:\n${cut ? text.slice(0, maxText) : text}`;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
throw new Error(`"${label}" cannot be attached: the assistant reads text files and images only.`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return attached;
|
|
358
|
+
}
|
|
359
|
+
async function base64(file) {
|
|
360
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
361
|
+
let binary = '';
|
|
362
|
+
for (let i = 0; i < bytes.length; i += 0x8000)
|
|
363
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
|
|
364
|
+
return btoa(binary);
|
|
365
|
+
}
|
|
366
|
+
function describe(error) {
|
|
367
|
+
return error instanceof Error ? error.message || error.name : String(error);
|
|
368
|
+
}
|
|
369
|
+
function clip(text, max) {
|
|
370
|
+
return text.length <= max ? text : `${text.slice(0, max)}\n[cut: ${text.length - max} more characters]`;
|
|
371
|
+
}
|
|
372
|
+
//# sourceMappingURL=remote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote.js","sourceRoot":"","sources":["../../src/browser/remote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAWlE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EAAE,GAAG,EAA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
|
|
2
|
+
export type PageToolOutput = string | {
|
|
3
|
+
text: string;
|
|
4
|
+
} | Record<string, unknown> | unknown[] | number | boolean | null;
|
|
5
|
+
/**
|
|
6
|
+
* Something the page lets an agent do: a function with a name, a description and a JSON Schema
|
|
7
|
+
* for its arguments. The same list serves the in-page agent (`nano`, `createPageAgent`) and
|
|
8
|
+
* outside agents over WebMCP (`exposeWebMcp`). It has the shape of `AppTool` from
|
|
9
|
+
* `genaicode/app-agent`, so one definition can serve both a server agent and the page.
|
|
10
|
+
*/
|
|
11
|
+
export interface PageTool {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
/** JSON Schema of the arguments (an object schema). Default: no arguments. */
|
|
15
|
+
inputSchema?: Record<string, unknown>;
|
|
16
|
+
/** Changes something for the user: it runs only after the user approved the call. */
|
|
17
|
+
write?: boolean;
|
|
18
|
+
/** The one line the user reads before approving a `write` call. Default: the tool and its arguments. */
|
|
19
|
+
summary?(args: Record<string, unknown>): string;
|
|
20
|
+
/** Throw to refuse a call, before anyone is asked to approve it. */
|
|
21
|
+
validate?(args: Record<string, unknown>): void;
|
|
22
|
+
run(args: Record<string, unknown>, signal?: AbortSignal): Promise<PageToolOutput> | PageToolOutput;
|
|
23
|
+
}
|
|
24
|
+
/** A tool's output as the text an agent reads. */
|
|
25
|
+
export declare function toolText(output: PageToolOutput | undefined): string;
|
|
26
|
+
/** The properties of a tool's argument schema; empty when it takes none. */
|
|
27
|
+
export declare function schemaProperties(tool: Pick<PageTool, 'inputSchema'>): Record<string, Record<string, unknown>>;
|
|
28
|
+
/**
|
|
29
|
+
* The problems with `args` for `tool`, by its `inputSchema`: missing required arguments, wrong
|
|
30
|
+
* types, values outside an `enum`, a `const`, numeric bounds, string and array lengths, a
|
|
31
|
+
* `pattern`, and the same inside nested objects and arrays. It covers what tools declare in
|
|
32
|
+
* practice, not all of JSON Schema (no `$ref`, `oneOf` or `format`); `tool.validate` does the rest.
|
|
33
|
+
* An argument the schema does not name is a problem only where the schema says
|
|
34
|
+
* `additionalProperties: false`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function argumentProblems(tool: Pick<PageTool, 'inputSchema'>, args: Record<string, unknown>): string[];
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/** A tool's output as the text an agent reads. */
|
|
2
|
+
export function toolText(output) {
|
|
3
|
+
if (output === undefined || output === null)
|
|
4
|
+
return 'done';
|
|
5
|
+
if (typeof output === 'string')
|
|
6
|
+
return output;
|
|
7
|
+
if (typeof output === 'object' && !Array.isArray(output)) {
|
|
8
|
+
const keys = Object.keys(output);
|
|
9
|
+
if (keys.length === 1 && typeof output.text === 'string') {
|
|
10
|
+
return output.text;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
return JSON.stringify(output) ?? String(output);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return String(output);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** The properties of a tool's argument schema; empty when it takes none. */
|
|
21
|
+
export function schemaProperties(tool) {
|
|
22
|
+
const properties = tool.inputSchema?.properties;
|
|
23
|
+
return properties && typeof properties === 'object' ? properties : {};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The problems with `args` for `tool`, by its `inputSchema`: missing required arguments, wrong
|
|
27
|
+
* types, values outside an `enum`, a `const`, numeric bounds, string and array lengths, a
|
|
28
|
+
* `pattern`, and the same inside nested objects and arrays. It covers what tools declare in
|
|
29
|
+
* practice, not all of JSON Schema (no `$ref`, `oneOf` or `format`); `tool.validate` does the rest.
|
|
30
|
+
* An argument the schema does not name is a problem only where the schema says
|
|
31
|
+
* `additionalProperties: false`.
|
|
32
|
+
*/
|
|
33
|
+
export function argumentProblems(tool, args) {
|
|
34
|
+
const problems = [];
|
|
35
|
+
if (tool.inputSchema)
|
|
36
|
+
check({ type: 'object', ...tool.inputSchema }, args, '', problems);
|
|
37
|
+
return problems;
|
|
38
|
+
}
|
|
39
|
+
const isSchema = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
40
|
+
const article = (noun) => (/^[aeio]/.test(noun) ? 'an' : 'a');
|
|
41
|
+
function typeOf(value) {
|
|
42
|
+
return value === null ? 'null' : Array.isArray(value) ? 'array' : typeof value;
|
|
43
|
+
}
|
|
44
|
+
function isType(value, type) {
|
|
45
|
+
if (type === 'integer')
|
|
46
|
+
return Number.isInteger(value);
|
|
47
|
+
if (type === 'number')
|
|
48
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
49
|
+
return typeOf(value) === type;
|
|
50
|
+
}
|
|
51
|
+
/** JSON equality: the order of an object's keys does not matter. */
|
|
52
|
+
function same(a, b) {
|
|
53
|
+
if (a === b)
|
|
54
|
+
return true;
|
|
55
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
56
|
+
return (Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, index) => same(item, b[index])));
|
|
57
|
+
}
|
|
58
|
+
if (!isSchema(a) || !isSchema(b))
|
|
59
|
+
return false;
|
|
60
|
+
const keys = Object.keys(a);
|
|
61
|
+
return keys.length === Object.keys(b).length && keys.every((key) => key in b && same(a[key], b[key]));
|
|
62
|
+
}
|
|
63
|
+
/** `value / step` is whole, give or take what floating point loses (0.3 / 0.1 is 2.9999999999999996). */
|
|
64
|
+
function isMultiple(value, step) {
|
|
65
|
+
const quotient = value / step;
|
|
66
|
+
// A few units of rounding error at this size: never a real fraction of a step.
|
|
67
|
+
return Math.abs(quotient - Math.round(quotient)) <= 4 * Number.EPSILON * Math.max(1, Math.abs(quotient));
|
|
68
|
+
}
|
|
69
|
+
/** `patternProperties` as regular expressions; a pattern that does not compile matches nothing. */
|
|
70
|
+
function patternSchemas(map) {
|
|
71
|
+
if (!isSchema(map))
|
|
72
|
+
return [];
|
|
73
|
+
const out = [];
|
|
74
|
+
for (const [source, sub] of Object.entries(map)) {
|
|
75
|
+
if (!isSchema(sub))
|
|
76
|
+
continue;
|
|
77
|
+
try {
|
|
78
|
+
out.push([new RegExp(source, 'u'), sub]);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// Not a pattern this engine reads.
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
function allowsNull(schema) {
|
|
87
|
+
if (!isSchema(schema))
|
|
88
|
+
return false;
|
|
89
|
+
if ('const' in schema)
|
|
90
|
+
return schema.const === null;
|
|
91
|
+
if (Array.isArray(schema.enum))
|
|
92
|
+
return schema.enum.includes(null);
|
|
93
|
+
return schema.type === 'null' || (Array.isArray(schema.type) && schema.type.includes('null'));
|
|
94
|
+
}
|
|
95
|
+
function check(schema, value, path, problems) {
|
|
96
|
+
const name = `"${path}"`;
|
|
97
|
+
if ('const' in schema && !same(schema.const, value)) {
|
|
98
|
+
problems.push(`${name} must be ${JSON.stringify(schema.const)}`);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (Array.isArray(schema.enum) && !schema.enum.some((item) => same(item, value))) {
|
|
102
|
+
problems.push(`${name} must be one of ${schema.enum.map((item) => JSON.stringify(item)).join(', ')}`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const types = typeof schema.type === 'string' ? [schema.type] : Array.isArray(schema.type) ? schema.type : [];
|
|
106
|
+
const named = types.filter((type) => typeof type === 'string');
|
|
107
|
+
if (named.length && !named.some((type) => isType(value, type))) {
|
|
108
|
+
problems.push(`${name} must be ${named.map((type) => `${article(type)} ${type}`).join(' or ')}`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (typeof value === 'string') {
|
|
112
|
+
// JSON Schema counts characters (code points), not UTF-16 units: an emoji is one.
|
|
113
|
+
const length = [...value].length;
|
|
114
|
+
if (typeof schema.minLength === 'number' && length < schema.minLength) {
|
|
115
|
+
problems.push(value ? `${name} is too short (at least ${schema.minLength} characters)` : `${name} must not be empty`);
|
|
116
|
+
}
|
|
117
|
+
if (typeof schema.maxLength === 'number' && length > schema.maxLength) {
|
|
118
|
+
problems.push(`${name} is too long (at most ${schema.maxLength} characters)`);
|
|
119
|
+
}
|
|
120
|
+
if (typeof schema.pattern === 'string') {
|
|
121
|
+
let matches = true;
|
|
122
|
+
try {
|
|
123
|
+
matches = new RegExp(schema.pattern, 'u').test(value);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// A pattern this engine cannot read decides nothing.
|
|
127
|
+
}
|
|
128
|
+
if (!matches)
|
|
129
|
+
problems.push(`${name} must match ${schema.pattern}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (typeof value === 'number') {
|
|
133
|
+
if (typeof schema.minimum === 'number' && value < schema.minimum)
|
|
134
|
+
problems.push(`${name} must be at least ${schema.minimum}`);
|
|
135
|
+
if (typeof schema.maximum === 'number' && value > schema.maximum)
|
|
136
|
+
problems.push(`${name} must be at most ${schema.maximum}`);
|
|
137
|
+
if (typeof schema.exclusiveMinimum === 'number' && value <= schema.exclusiveMinimum) {
|
|
138
|
+
problems.push(`${name} must be more than ${schema.exclusiveMinimum}`);
|
|
139
|
+
}
|
|
140
|
+
if (typeof schema.exclusiveMaximum === 'number' && value >= schema.exclusiveMaximum) {
|
|
141
|
+
problems.push(`${name} must be less than ${schema.exclusiveMaximum}`);
|
|
142
|
+
}
|
|
143
|
+
if (typeof schema.multipleOf === 'number' && schema.multipleOf > 0 && !isMultiple(value, schema.multipleOf)) {
|
|
144
|
+
problems.push(`${name} must be a multiple of ${schema.multipleOf}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (Array.isArray(value)) {
|
|
148
|
+
if (typeof schema.minItems === 'number' && value.length < schema.minItems) {
|
|
149
|
+
problems.push(`${name} needs at least ${schema.minItems} items`);
|
|
150
|
+
}
|
|
151
|
+
if (typeof schema.maxItems === 'number' && value.length > schema.maxItems) {
|
|
152
|
+
problems.push(`${name} takes at most ${schema.maxItems} items`);
|
|
153
|
+
}
|
|
154
|
+
if (isSchema(schema.items)) {
|
|
155
|
+
for (const [index, item] of value.entries())
|
|
156
|
+
check(schema.items, item, `${path}[${index}]`, problems);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (isSchema(value)) {
|
|
160
|
+
const properties = isSchema(schema.properties) ? schema.properties : {};
|
|
161
|
+
const at = (key) => (path ? `${path}.${key}` : key);
|
|
162
|
+
const patterns = patternSchemas(schema.patternProperties);
|
|
163
|
+
for (const key of Array.isArray(schema.required) ? schema.required : []) {
|
|
164
|
+
if (typeof key !== 'string')
|
|
165
|
+
continue;
|
|
166
|
+
// A small model writes null for what it leaves out, so null counts as missing unless the schema asks for it.
|
|
167
|
+
if (value[key] === undefined || (value[key] === null && !allowsNull(properties[key]))) {
|
|
168
|
+
problems.push(`"${at(key)}" is required`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
for (const [key, item] of Object.entries(value)) {
|
|
172
|
+
// A model writes null for an argument it leaves out.
|
|
173
|
+
if (item === undefined || item === null)
|
|
174
|
+
continue;
|
|
175
|
+
const property = properties[key];
|
|
176
|
+
const matched = patterns.filter(([pattern]) => pattern.test(key));
|
|
177
|
+
for (const [, sub] of matched)
|
|
178
|
+
check(sub, item, at(key), problems);
|
|
179
|
+
if (isSchema(property))
|
|
180
|
+
check(property, item, at(key), problems);
|
|
181
|
+
else if (matched.length)
|
|
182
|
+
continue;
|
|
183
|
+
else if (schema.additionalProperties === false)
|
|
184
|
+
problems.push(`"${at(key)}" is not an argument`);
|
|
185
|
+
else if (isSchema(schema.additionalProperties))
|
|
186
|
+
check(schema.additionalProperties, item, at(key), problems);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/browser/tools.ts"],"names":[],"mappings":"AAuBA,kDAAkD;AAClD,MAAM,UAAU,QAAQ,CAAC,MAAkC;IACzD,IA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