@agimon-ai/po-codemode 0.0.1-alpha.2 → 0.0.1-alpha.21
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 +23 -11
- package/dist/codemodeTools-De6GNjzR.mjs +761 -0
- package/dist/codemodeTools-De6GNjzR.mjs.map +1 -0
- package/dist/codemodeTools-DiqyGxSU.cjs +772 -0
- package/dist/codemodeTools-DiqyGxSU.cjs.map +1 -0
- package/dist/extensions/native.mjs +419 -0
- package/dist/extensions/native.mjs.map +1 -0
- package/dist/extensions/server.cjs +484 -23
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +485 -24
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +214 -117
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.mts +24 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/llms.txt +3 -1
- package/package.json +39 -12
- package/src/prompts/codemode-how-to-llm/SKILL.md +29 -0
- package/src/prompts/codemode-how-to-shell/SKILL.md +21 -0
- package/src/prompts/how-to-codemode/SKILL.md +71 -0
- package/dist/codemodeTools-BdwOARH8.mjs +0 -383
- package/dist/codemodeTools-BdwOARH8.mjs.map +0 -1
- package/dist/codemodeTools-CLgSDqfU.cjs +0 -394
- package/dist/codemodeTools-CLgSDqfU.cjs.map +0 -1
- package/src/prompts/po-use-codemode/SKILL.md +0 -46
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
import { assertCodemodeNamespaceName } from "@agimon-ai/po-core/codemode";
|
|
2
|
-
import { invalidImageReason } from "@agimon-ai/po-core/headless";
|
|
3
|
-
import { Type } from "typebox";
|
|
4
|
-
//#region src/services/codemodeRegistry/index.ts
|
|
5
|
-
/** The session's namespaces and script folders, in registration order. One name per session. */
|
|
6
|
-
function createCodemodeRegistry() {
|
|
7
|
-
const entries = /* @__PURE__ */ new Map();
|
|
8
|
-
const scripts = /* @__PURE__ */ new Set();
|
|
9
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
10
|
-
const notify = () => {
|
|
11
|
-
for (const listener of listeners) listener();
|
|
12
|
-
};
|
|
13
|
-
return {
|
|
14
|
-
register(source, namespace) {
|
|
15
|
-
assertCodemodeNamespaceName(namespace.name);
|
|
16
|
-
const taken = entries.get(namespace.name);
|
|
17
|
-
if (taken) throw new Error(`Code-mode namespace "${namespace.name}" from ${source} is already registered by ${taken.source}.`);
|
|
18
|
-
const entry = {
|
|
19
|
-
source,
|
|
20
|
-
namespace
|
|
21
|
-
};
|
|
22
|
-
entries.set(namespace.name, entry);
|
|
23
|
-
notify();
|
|
24
|
-
return { dispose: () => {
|
|
25
|
-
if (entries.get(namespace.name) !== entry) return;
|
|
26
|
-
entries.delete(namespace.name);
|
|
27
|
-
notify();
|
|
28
|
-
} };
|
|
29
|
-
},
|
|
30
|
-
list: () => [...entries.values()].map((entry) => entry.namespace),
|
|
31
|
-
registerScripts(_source, entry) {
|
|
32
|
-
const owned = {
|
|
33
|
-
domain: entry.domain,
|
|
34
|
-
directory: entry.directory
|
|
35
|
-
};
|
|
36
|
-
scripts.add(owned);
|
|
37
|
-
notify();
|
|
38
|
-
return { dispose: () => void (scripts.delete(owned) && notify()) };
|
|
39
|
-
},
|
|
40
|
-
listScripts: () => [...scripts],
|
|
41
|
-
subscribe(listener) {
|
|
42
|
-
listeners.add(listener);
|
|
43
|
-
return () => listeners.delete(listener);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/schemas/codemodeTools.ts
|
|
49
|
-
const DiscoverToolSchema = Type.Object({
|
|
50
|
-
namespace: Type.Optional(Type.String({ description: "Show the full TypeScript declarations of one namespace." })),
|
|
51
|
-
query: Type.Optional(Type.String({ description: "Find matching members across every namespace." }))
|
|
52
|
-
});
|
|
53
|
-
const ExecToolSchema = Type.Object({
|
|
54
|
-
code: Type.String({ description: "TypeScript body of an async function. Top-level await and return work. The returned value, console output and image() calls come back." }),
|
|
55
|
-
timeoutMs: Type.Optional(Type.Integer({
|
|
56
|
-
minimum: 1e3,
|
|
57
|
-
maximum: 12e4,
|
|
58
|
-
description: "Deadline in milliseconds. Default 30000."
|
|
59
|
-
}))
|
|
60
|
-
});
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/services/codemodeTools/index.ts
|
|
63
|
-
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
64
|
-
const MAX_TIMEOUT_MS = 12e4;
|
|
65
|
-
const MIN_TIMEOUT_MS = 1e3;
|
|
66
|
-
const MAX_LOG_CHARS = 1e4;
|
|
67
|
-
const MAX_VALUE_CHARS = 65536;
|
|
68
|
-
const MAX_DECLARATION_CHARS = 24e3;
|
|
69
|
-
const MAX_QUERY_LINES = 40;
|
|
70
|
-
const MAX_CONCURRENT_RUNS = 8;
|
|
71
|
-
const MAX_RECORDED_CALLS = 50;
|
|
72
|
-
const MAX_RECORDED_TEXT = 8e3;
|
|
73
|
-
const MAX_RECORDED_JSON = 16e3;
|
|
74
|
-
const MAX_LISTED_SCRIPTS = 20;
|
|
75
|
-
const MAX_IMAGES = 4;
|
|
76
|
-
const MAX_IMAGE_BYTES = 5242880;
|
|
77
|
-
const DEFAULT_IMAGE_MIME = "image/png";
|
|
78
|
-
const MEMBER_LINE = /^\s{2}(?:readonly\s+)?(\w+)\s*[(?:<]/u;
|
|
79
|
-
const GLOBALS_HELP = "Globals: console.log/info/warn/error, image(data, mimeType?) to return a screenshot, sleep(ms). Return a value with `return`.";
|
|
80
|
-
const SCRIPTS_HELP = "Every exec run is saved. Call a saved script with `await (await import(specifier))(args)`; inside it, `args` is the argument and its `return` is the result.";
|
|
81
|
-
function text(value, isError = false) {
|
|
82
|
-
return {
|
|
83
|
-
content: [{
|
|
84
|
-
type: "text",
|
|
85
|
-
text: value
|
|
86
|
-
}],
|
|
87
|
-
...isError ? { isError: true } : {}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function truncate(value, limit) {
|
|
91
|
-
return value.length <= limit ? value : `${value.slice(0, limit)}\n[truncated ${value.length - limit} chars]`;
|
|
92
|
-
}
|
|
93
|
-
function format(value) {
|
|
94
|
-
if (typeof value === "string") return value;
|
|
95
|
-
try {
|
|
96
|
-
const json = JSON.stringify(value, null, 2);
|
|
97
|
-
if (json !== void 0) return json;
|
|
98
|
-
} catch {}
|
|
99
|
-
return String(value);
|
|
100
|
-
}
|
|
101
|
-
function memberNames(namespace) {
|
|
102
|
-
const names = /* @__PURE__ */ new Set();
|
|
103
|
-
const declaration = new RegExp(`^declare const ${namespace.name}: \\{([\\s\\S]*?)^\\};`, "mu").exec(namespace.declarations)?.[1] ?? "";
|
|
104
|
-
for (const line of declaration.split("\n")) {
|
|
105
|
-
const name = MEMBER_LINE.exec(line)?.[1];
|
|
106
|
-
if (name) names.add(name);
|
|
107
|
-
}
|
|
108
|
-
return [...names];
|
|
109
|
-
}
|
|
110
|
-
function bytesToBase64(bytes) {
|
|
111
|
-
let binary = "";
|
|
112
|
-
for (let index = 0; index < bytes.length; index += 32768) binary += String.fromCharCode(...bytes.subarray(index, index + 32768));
|
|
113
|
-
return btoa(binary);
|
|
114
|
-
}
|
|
115
|
-
/** Collects what a script prints and the images it returns, within the output caps. */
|
|
116
|
-
function createOutput() {
|
|
117
|
-
const lines = [];
|
|
118
|
-
const images = [];
|
|
119
|
-
let imageBytes = 0;
|
|
120
|
-
const log = (level) => (...args) => {
|
|
121
|
-
const line = args.map(format).join(" ");
|
|
122
|
-
lines.push(level === "log" || level === "info" ? line : `[${level}] ${line}`);
|
|
123
|
-
};
|
|
124
|
-
const note = (message) => void lines.push(`[note] ${message}`);
|
|
125
|
-
const addImage = (input, mimeType) => {
|
|
126
|
-
if (typeof input === "object" && input !== null && "images" in input && Array.isArray(input.images)) {
|
|
127
|
-
for (const image of input.images) addImage(image);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
let data;
|
|
131
|
-
let mime = typeof mimeType === "string" ? mimeType : DEFAULT_IMAGE_MIME;
|
|
132
|
-
if (typeof input === "string") data = input.replace(/^data:([^;]+);base64,/u, (_match, type) => (mime = type, ""));
|
|
133
|
-
else if (ArrayBuffer.isView(input)) data = bytesToBase64(new Uint8Array(input.buffer, input.byteOffset, input.byteLength));
|
|
134
|
-
else if (typeof input === "object" && input !== null && "data" in input && typeof input.data === "string") {
|
|
135
|
-
data = input.data;
|
|
136
|
-
if ("mimeType" in input && typeof input.mimeType === "string") mime = input.mimeType;
|
|
137
|
-
} else throw new TypeError("image() takes base64 text, bytes, or { data, mimeType }.");
|
|
138
|
-
if (images.length >= MAX_IMAGES) throw new RangeError(`An exec run returns at most ${MAX_IMAGES} images.`);
|
|
139
|
-
imageBytes += Math.ceil(data.length * 3 / 4);
|
|
140
|
-
if (imageBytes > MAX_IMAGE_BYTES) throw new RangeError("Images from one exec run exceed 5 MB.");
|
|
141
|
-
const invalid = invalidImageReason(data, mime);
|
|
142
|
-
if (invalid !== void 0) throw new TypeError(`image() rejected an undecodable image: ${invalid}.`);
|
|
143
|
-
images.push({
|
|
144
|
-
data,
|
|
145
|
-
mimeType: mime
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
return {
|
|
149
|
-
console: {
|
|
150
|
-
log: log("log"),
|
|
151
|
-
info: log("info"),
|
|
152
|
-
warn: log("warn"),
|
|
153
|
-
error: log("error"),
|
|
154
|
-
debug: log("debug")
|
|
155
|
-
},
|
|
156
|
-
note,
|
|
157
|
-
addImage,
|
|
158
|
-
lines,
|
|
159
|
-
images
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
/** The session's active domains; every registered domain when the host reports none. */
|
|
163
|
-
function activeDomains(execution) {
|
|
164
|
-
return execution?.selection?.domains;
|
|
165
|
-
}
|
|
166
|
-
/** A JSON copy of `value`, or undefined when it does not serialise or is larger than `limit` characters. */
|
|
167
|
-
function bounded(value, limit) {
|
|
168
|
-
try {
|
|
169
|
-
const json = JSON.stringify(value);
|
|
170
|
-
return json !== void 0 && json.length <= limit ? JSON.parse(json) : void 0;
|
|
171
|
-
} catch {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
/** The call as it is kept in the transcript: text blocks only, clipped, with args and details dropped when large. */
|
|
176
|
-
function recordedCall(call) {
|
|
177
|
-
const content = (call.result?.content ?? []).flatMap((block) => {
|
|
178
|
-
const { type, text } = block ?? {};
|
|
179
|
-
return type === "text" && typeof text === "string" ? [{
|
|
180
|
-
type: "text",
|
|
181
|
-
text: truncate(text, MAX_RECORDED_TEXT)
|
|
182
|
-
}] : [];
|
|
183
|
-
});
|
|
184
|
-
const details = bounded(call.result?.details, MAX_RECORDED_JSON);
|
|
185
|
-
return {
|
|
186
|
-
name: call.name,
|
|
187
|
-
tool: call.tool,
|
|
188
|
-
args: bounded(call.args, MAX_RECORDED_JSON) ?? {},
|
|
189
|
-
ok: call.ok,
|
|
190
|
-
ms: Math.max(0, Math.round(call.ms)),
|
|
191
|
-
...call.error === void 0 ? {} : { error: truncate(call.error, MAX_RECORDED_TEXT) },
|
|
192
|
-
...call.result === void 0 ? {} : { result: {
|
|
193
|
-
content,
|
|
194
|
-
...details === void 0 ? {} : { details }
|
|
195
|
-
} }
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function toResult(result, output, saved, calls) {
|
|
199
|
-
const content = [];
|
|
200
|
-
if (output.lines.length > 0) content.push({
|
|
201
|
-
type: "text",
|
|
202
|
-
text: truncate(output.lines.join("\n"), MAX_LOG_CHARS)
|
|
203
|
-
});
|
|
204
|
-
if (result.ok) {
|
|
205
|
-
if (ArrayBuffer.isView(result.value)) content.push({
|
|
206
|
-
type: "text",
|
|
207
|
-
text: "The script returned bytes. Pass them to image(data, mimeType) instead."
|
|
208
|
-
});
|
|
209
|
-
else if (result.value !== void 0) content.push({
|
|
210
|
-
type: "text",
|
|
211
|
-
text: truncate(format(result.value), MAX_VALUE_CHARS)
|
|
212
|
-
});
|
|
213
|
-
} else {
|
|
214
|
-
const { kind, name, message } = result.error;
|
|
215
|
-
const hint = kind === "timeout" ? " Raise timeoutMs or split the work into smaller exec calls." : "";
|
|
216
|
-
content.push({
|
|
217
|
-
type: "text",
|
|
218
|
-
text: `${name}: ${message}${hint}`
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
if (content.length === 0) content.push({
|
|
222
|
-
type: "text",
|
|
223
|
-
text: "(no return value)"
|
|
224
|
-
});
|
|
225
|
-
if (saved !== void 0) content.push({
|
|
226
|
-
type: "text",
|
|
227
|
-
text: saved
|
|
228
|
-
});
|
|
229
|
-
for (const image of output.images) content.push({
|
|
230
|
-
type: "image",
|
|
231
|
-
data: image.data,
|
|
232
|
-
mimeType: image.mimeType
|
|
233
|
-
});
|
|
234
|
-
return {
|
|
235
|
-
content,
|
|
236
|
-
...calls.length > 0 ? { details: { calls } } : {},
|
|
237
|
-
...result.ok ? {} : { isError: true }
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
function sleep(ms, signal) {
|
|
241
|
-
return new Promise((resolve, reject) => {
|
|
242
|
-
if (signal.aborted) return reject(/* @__PURE__ */ new Error("Run ended."));
|
|
243
|
-
const timer = setTimeout(resolve, Math.max(0, ms));
|
|
244
|
-
signal.addEventListener("abort", () => {
|
|
245
|
-
clearTimeout(timer);
|
|
246
|
-
reject(/* @__PURE__ */ new Error("Run ended."));
|
|
247
|
-
}, { once: true });
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
/** `discover` and `exec` for one session, over the namespaces its packages contributed. */
|
|
251
|
-
function createCodemodeTools({ registry, isolate, scripts }) {
|
|
252
|
-
let running = 0;
|
|
253
|
-
const visible = (service) => registry.list().filter((namespace) => service.liveObjects || namespace.portable === true);
|
|
254
|
-
return {
|
|
255
|
-
discover: {
|
|
256
|
-
name: "discover",
|
|
257
|
-
label: "Discover",
|
|
258
|
-
description: "List the code-mode namespaces and reusable scripts you can use from `exec`, show one namespace in full, or search members and scripts. Not required before exec: its description already names the namespaces.",
|
|
259
|
-
parameters: DiscoverToolSchema,
|
|
260
|
-
promptSnippet: "List code-mode namespaces and their TypeScript declarations",
|
|
261
|
-
executionMode: "parallel",
|
|
262
|
-
async execute(_toolCallId, parameters, _signal, _onUpdate, execution) {
|
|
263
|
-
const service = isolate();
|
|
264
|
-
if (!service) return text("Code mode is not available on this host.", true);
|
|
265
|
-
const namespaces = visible(service);
|
|
266
|
-
const listed = scripts && service.liveObjects ? await scripts.list(activeDomains(execution)) : [];
|
|
267
|
-
if (parameters.namespace !== void 0) {
|
|
268
|
-
const found = namespaces.find((namespace) => namespace.name === parameters.namespace);
|
|
269
|
-
if (!found) {
|
|
270
|
-
const names = namespaces.map((namespace) => namespace.name).join(", ") || "none";
|
|
271
|
-
return text(`Unknown namespace "${parameters.namespace}". Registered: ${names}.`, true);
|
|
272
|
-
}
|
|
273
|
-
return text(truncate(found.declarations, MAX_DECLARATION_CHARS));
|
|
274
|
-
}
|
|
275
|
-
if (parameters.query !== void 0) {
|
|
276
|
-
const needle = parameters.query.toLowerCase();
|
|
277
|
-
const hits = [];
|
|
278
|
-
for (const namespace of namespaces) {
|
|
279
|
-
const lines = namespace.declarations.split("\n");
|
|
280
|
-
lines.forEach((line, index) => {
|
|
281
|
-
if (!line.toLowerCase().includes(needle) || hits.length >= MAX_QUERY_LINES) return;
|
|
282
|
-
const doc = lines[index - 1]?.trim().startsWith("/**") ? `${lines[index - 1]?.trim()} ` : "";
|
|
283
|
-
hits.push(`${namespace.name}: ${doc}${line.trim()}`);
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
for (const script of listed) {
|
|
287
|
-
if (hits.length >= MAX_QUERY_LINES) break;
|
|
288
|
-
if (`${script.specifier} ${script.description}`.toLowerCase().includes(needle)) hits.push(`script ${script.specifier}: ${script.description}`);
|
|
289
|
-
}
|
|
290
|
-
return text(hits.length > 0 ? hits.join("\n") : `No members or scripts match "${parameters.query}".`);
|
|
291
|
-
}
|
|
292
|
-
const sections = [];
|
|
293
|
-
if (namespaces.length === 0) sections.push("No namespaces are registered in this session.");
|
|
294
|
-
for (const namespace of namespaces) sections.push(`- ${namespace.name}: ${namespace.summary}\n members: ${memberNames(namespace).join(", ")}`);
|
|
295
|
-
sections.push(GLOBALS_HELP);
|
|
296
|
-
if (!service.liveObjects) sections.push("This host runs plain JavaScript with JSON-only functions.");
|
|
297
|
-
if (listed.length > 0) {
|
|
298
|
-
sections.push(`Scripts. ${SCRIPTS_HELP}`);
|
|
299
|
-
for (const script of listed.slice(0, MAX_LISTED_SCRIPTS)) sections.push(`- ${script.specifier}${script.description ? `: ${script.description}` : ""}`);
|
|
300
|
-
if (listed.length > MAX_LISTED_SCRIPTS) sections.push(`...and ${listed.length - MAX_LISTED_SCRIPTS} more; use discover({ query }) to search.`);
|
|
301
|
-
}
|
|
302
|
-
if (namespaces.length > 0) sections.push("Call discover({ namespace }) for full types.");
|
|
303
|
-
return text(sections.join("\n"));
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
exec: {
|
|
307
|
-
name: "exec",
|
|
308
|
-
label: "Exec",
|
|
309
|
-
get description() {
|
|
310
|
-
const service = isolate();
|
|
311
|
-
return [
|
|
312
|
-
"Run a TypeScript script inside the Po server with live objects from the namespaces below in scope.",
|
|
313
|
-
"It runs with full server trust, like bash. Keep each call to one logical step.",
|
|
314
|
-
(service ? visible(service) : []).map((namespace) => `- ${namespace.name}: ${namespace.summary}`).join("\n") || "(no namespaces registered yet; call discover to check)",
|
|
315
|
-
GLOBALS_HELP,
|
|
316
|
-
...scripts && service?.liveObjects ? [`${SCRIPTS_HELP} discover lists saved and domain scripts.`] : [],
|
|
317
|
-
"Use discover({ namespace }) for full signatures when needed."
|
|
318
|
-
].join("\n");
|
|
319
|
-
},
|
|
320
|
-
parameters: ExecToolSchema,
|
|
321
|
-
promptSnippet: "Run a TypeScript script against live Po objects (browser and other namespaces)",
|
|
322
|
-
executionMode: "serial",
|
|
323
|
-
async execute(_toolCallId, parameters, signal, _onUpdate, execution) {
|
|
324
|
-
const service = isolate();
|
|
325
|
-
if (!service) return text("Code mode is not available on this host.", true);
|
|
326
|
-
if (running >= MAX_CONCURRENT_RUNS) return text(`This session already has ${MAX_CONCURRENT_RUNS} exec runs active. Wait for one to finish.`, true);
|
|
327
|
-
running += 1;
|
|
328
|
-
const controller = new AbortController();
|
|
329
|
-
const runSignal = signal ? AbortSignal.any([signal, controller.signal]) : controller.signal;
|
|
330
|
-
const cleanups = [];
|
|
331
|
-
const calls = [];
|
|
332
|
-
const output = createOutput();
|
|
333
|
-
const run = {
|
|
334
|
-
sessionId: execution.sessionId,
|
|
335
|
-
signal: runSignal,
|
|
336
|
-
onDispose: (cleanup) => void cleanups.push(cleanup),
|
|
337
|
-
record: (call) => {
|
|
338
|
-
if (calls.length < MAX_RECORDED_CALLS) calls.push(recordedCall(call));
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
try {
|
|
342
|
-
let saved;
|
|
343
|
-
try {
|
|
344
|
-
const file = await scripts?.save(parameters.code);
|
|
345
|
-
if (file) saved = `Saved as ${file.specifier} (${file.path})`;
|
|
346
|
-
} catch (error) {
|
|
347
|
-
output.note(`Could not save the script: ${error instanceof Error ? error.message : String(error)}`);
|
|
348
|
-
}
|
|
349
|
-
const globals = {
|
|
350
|
-
console: output.console,
|
|
351
|
-
image: output.addImage,
|
|
352
|
-
sleep: (ms) => sleep(ms, runSignal)
|
|
353
|
-
};
|
|
354
|
-
const deny = /* @__PURE__ */ new Set();
|
|
355
|
-
for (const namespace of visible(service)) {
|
|
356
|
-
globals[namespace.name] = namespace.bind(run);
|
|
357
|
-
for (const member of namespace.deny ?? []) deny.add(member);
|
|
358
|
-
}
|
|
359
|
-
const deadlineMs = Math.min(MAX_TIMEOUT_MS, Math.max(MIN_TIMEOUT_MS, parameters.timeoutMs ?? DEFAULT_TIMEOUT_MS));
|
|
360
|
-
return toResult(await service.run({
|
|
361
|
-
source: parameters.code,
|
|
362
|
-
globals,
|
|
363
|
-
deadlineMs,
|
|
364
|
-
signal: runSignal,
|
|
365
|
-
deny: [...deny],
|
|
366
|
-
onDiagnostic: output.note,
|
|
367
|
-
...scripts ? { resolveImport: (specifier) => scripts.resolve(specifier, activeDomains(execution)) } : {}
|
|
368
|
-
}), output, saved, calls);
|
|
369
|
-
} catch (error) {
|
|
370
|
-
return text(`Code mode could not run the script: ${error instanceof Error ? error.message : String(error)}`, true);
|
|
371
|
-
} finally {
|
|
372
|
-
controller.abort();
|
|
373
|
-
for (const cleanup of cleanups.reverse()) await Promise.resolve().then(cleanup).catch((error) => output.note(`cleanup failed: ${String(error)}`));
|
|
374
|
-
running -= 1;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
//#endregion
|
|
381
|
-
export { createCodemodeRegistry as n, createCodemodeTools as t };
|
|
382
|
-
|
|
383
|
-
//# sourceMappingURL=codemodeTools-BdwOARH8.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codemodeTools-BdwOARH8.mjs","names":[],"sources":["../src/services/codemodeRegistry/index.ts","../src/schemas/codemodeTools.ts","../src/services/codemodeTools/index.ts"],"sourcesContent":["import {\n assertCodemodeNamespaceName,\n type PoCodemodeNamespace,\n type PoCodemodeRegistration,\n type PoCodemodeScriptSource,\n type PoCodemodeService,\n} from '@agimon-ai/po-core/codemode';\n\n/** The session's namespaces and script folders, in registration order. One name per session. */\nexport function createCodemodeRegistry(): PoCodemodeService {\n const entries = new Map<string, { source: string; namespace: PoCodemodeNamespace }>();\n const scripts = new Set<PoCodemodeScriptSource>();\n const listeners = new Set<() => void>();\n const notify = (): void => {\n for (const listener of listeners) listener();\n };\n return {\n register(source: string, namespace: PoCodemodeNamespace): PoCodemodeRegistration {\n assertCodemodeNamespaceName(namespace.name);\n const taken = entries.get(namespace.name);\n if (taken) {\n throw new Error(\n `Code-mode namespace \"${namespace.name}\" from ${source} is already registered by ${taken.source}.`,\n );\n }\n const entry = { source, namespace };\n entries.set(namespace.name, entry);\n notify();\n return {\n dispose: () => {\n if (entries.get(namespace.name) !== entry) return;\n entries.delete(namespace.name);\n notify();\n },\n };\n },\n list: () => [...entries.values()].map((entry) => entry.namespace),\n registerScripts(_source: string, entry: PoCodemodeScriptSource): PoCodemodeRegistration {\n const owned = { domain: entry.domain, directory: entry.directory };\n scripts.add(owned);\n notify();\n return { dispose: () => void (scripts.delete(owned) && notify()) };\n },\n listScripts: () => [...scripts],\n subscribe(listener: () => void): () => void {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n}\n","import { Type, type Static } from 'typebox';\n\nexport const DiscoverToolSchema = Type.Object({\n namespace: Type.Optional(Type.String({ description: 'Show the full TypeScript declarations of one namespace.' })),\n query: Type.Optional(Type.String({ description: 'Find matching members across every namespace.' })),\n});\nexport type DiscoverToolParams = Static<typeof DiscoverToolSchema>;\n\nexport const ExecToolSchema = Type.Object({\n code: Type.String({\n description:\n 'TypeScript body of an async function. Top-level await and return work. The returned value, console output and image() calls come back.',\n }),\n timeoutMs: Type.Optional(\n Type.Integer({ minimum: 1_000, maximum: 120_000, description: 'Deadline in milliseconds. Default 30000.' }),\n ),\n});\nexport type ExecToolParams = Static<typeof ExecToolSchema>;\n","import type {\n PoCodemodeCall,\n PoCodemodeNamespace,\n PoCodemodeRun,\n PoCodemodeService,\n} from '@agimon-ai/po-core/codemode';\nimport {\n invalidImageReason,\n type PoHeadlessContent,\n type PoHeadlessExecutionContext,\n type PoHeadlessTool,\n type PoHeadlessToolResult,\n} from '@agimon-ai/po-core/headless';\nimport type { PoIsolateResult, PoIsolateService } from '@agimon-ai/po-core/platform';\n\nimport {\n DiscoverToolSchema,\n ExecToolSchema,\n type DiscoverToolParams,\n type ExecToolParams,\n} from '../../schemas/codemodeTools';\nimport type { CodemodeScriptsPort } from '../codemodeScripts/type';\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\nconst MAX_TIMEOUT_MS = 120_000;\nconst MIN_TIMEOUT_MS = 1_000;\nconst MAX_LOG_CHARS = 10_000;\nconst MAX_VALUE_CHARS = 64 * 1024;\nconst MAX_DECLARATION_CHARS = 24_000;\nconst MAX_QUERY_LINES = 40;\n// The main agent and its subagents share one exec tool, so several runs can overlap.\nconst MAX_CONCURRENT_RUNS = 8;\n// Recorded calls ride the result's details into the transcript, so they are few and small.\nconst MAX_RECORDED_CALLS = 50;\nconst MAX_RECORDED_TEXT = 8_000;\nconst MAX_RECORDED_JSON = 16_000;\nconst MAX_LISTED_SCRIPTS = 20;\nconst MAX_IMAGES = 4;\nconst MAX_IMAGE_BYTES = 5 * 1024 * 1024;\nconst DEFAULT_IMAGE_MIME = 'image/png';\nconst MEMBER_LINE = /^\\s{2}(?:readonly\\s+)?(\\w+)\\s*[(?:<]/u;\n\nconst GLOBALS_HELP =\n 'Globals: console.log/info/warn/error, image(data, mimeType?) to return a screenshot, sleep(ms). ' +\n 'Return a value with `return`.';\nconst SCRIPTS_HELP =\n 'Every exec run is saved. Call a saved script with `await (await import(specifier))(args)`; ' +\n 'inside it, `args` is the argument and its `return` is the result.';\n\nexport interface CodemodeToolsOptions {\n readonly registry: PoCodemodeService;\n /** Resolved per call, so a host that binds the isolate late still works. */\n readonly isolate: () => PoIsolateService | undefined;\n /** Saves every exec body and backs `import()`; without it nothing is saved or importable. */\n readonly scripts?: CodemodeScriptsPort;\n}\n\nexport interface CodemodeTools {\n readonly discover: PoHeadlessTool<typeof DiscoverToolSchema>;\n readonly exec: PoHeadlessTool<typeof ExecToolSchema>;\n}\n\nfunction text(value: string, isError = false): PoHeadlessToolResult {\n return { content: [{ type: 'text', text: value }], ...(isError ? { isError: true } : {}) };\n}\n\nfunction truncate(value: string, limit: number): string {\n return value.length <= limit ? value : `${value.slice(0, limit)}\\n[truncated ${value.length - limit} chars]`;\n}\n\nfunction format(value: unknown): string {\n if (typeof value === 'string') return value;\n try {\n const json = JSON.stringify(value, null, 2);\n if (json !== undefined) return json;\n } catch {\n // Cyclic or exotic values fall back to their string form.\n }\n return String(value);\n}\n\nfunction memberNames(namespace: PoCodemodeNamespace): string[] {\n const names = new Set<string>();\n const declaration =\n new RegExp(`^declare const ${namespace.name}: \\\\{([\\\\s\\\\S]*?)^\\\\};`, 'mu').exec(namespace.declarations)?.[1] ?? '';\n for (const line of declaration.split('\\n')) {\n const name = MEMBER_LINE.exec(line)?.[1];\n if (name) names.add(name);\n }\n return [...names];\n}\n\nfunction bytesToBase64(bytes: Uint8Array): string {\n let binary = '';\n for (let index = 0; index < bytes.length; index += 0x8000) {\n binary += String.fromCharCode(...bytes.subarray(index, index + 0x8000));\n }\n return btoa(binary);\n}\n\n/** Collects what a script prints and the images it returns, within the output caps. */\nfunction createOutput() {\n const lines: string[] = [];\n const images: { data: string; mimeType: string }[] = [];\n let imageBytes = 0;\n const log =\n (level: string) =>\n (...args: unknown[]) => {\n const line = args.map(format).join(' ');\n lines.push(level === 'log' || level === 'info' ? line : `[${level}] ${line}`);\n };\n const note = (message: string): void => void lines.push(`[note] ${message}`);\n const addImage = (input: unknown, mimeType?: unknown): void => {\n if (typeof input === 'object' && input !== null && 'images' in input && Array.isArray(input.images)) {\n for (const image of input.images) addImage(image);\n return;\n }\n let data: string;\n let mime = typeof mimeType === 'string' ? mimeType : DEFAULT_IMAGE_MIME;\n if (typeof input === 'string')\n data = input.replace(/^data:([^;]+);base64,/u, (_match, type: string) => ((mime = type), ''));\n else if (ArrayBuffer.isView(input))\n data = bytesToBase64(new Uint8Array(input.buffer, input.byteOffset, input.byteLength));\n else if (typeof input === 'object' && input !== null && 'data' in input && typeof input.data === 'string') {\n data = input.data;\n if ('mimeType' in input && typeof input.mimeType === 'string') mime = input.mimeType;\n } else throw new TypeError('image() takes base64 text, bytes, or { data, mimeType }.');\n if (images.length >= MAX_IMAGES) throw new RangeError(`An exec run returns at most ${MAX_IMAGES} images.`);\n imageBytes += Math.ceil((data.length * 3) / 4);\n if (imageBytes > MAX_IMAGE_BYTES) throw new RangeError('Images from one exec run exceed 5 MB.');\n const invalid = invalidImageReason(data, mime);\n if (invalid !== undefined) throw new TypeError(`image() rejected an undecodable image: ${invalid}.`);\n images.push({ data, mimeType: mime });\n };\n const console = { log: log('log'), info: log('info'), warn: log('warn'), error: log('error'), debug: log('debug') };\n return { console, note, addImage, lines, images };\n}\n\n/** The session's active domains; every registered domain when the host reports none. */\nfunction activeDomains(execution: PoHeadlessExecutionContext | undefined): readonly string[] | undefined {\n return execution?.selection?.domains;\n}\n\n/** A JSON copy of `value`, or undefined when it does not serialise or is larger than `limit` characters. */\nfunction bounded<T>(value: T, limit: number): T | undefined {\n try {\n const json = JSON.stringify(value);\n return json !== undefined && json.length <= limit ? (JSON.parse(json) as T) : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** The call as it is kept in the transcript: text blocks only, clipped, with args and details dropped when large. */\nfunction recordedCall(call: PoCodemodeCall): PoCodemodeCall {\n const content = (call.result?.content ?? []).flatMap((block) => {\n const { type, text } = (block ?? {}) as { type?: unknown; text?: unknown };\n return type === 'text' && typeof text === 'string'\n ? [{ type: 'text', text: truncate(text, MAX_RECORDED_TEXT) }]\n : [];\n });\n const details = bounded(call.result?.details, MAX_RECORDED_JSON);\n return {\n name: call.name,\n tool: call.tool,\n args: bounded(call.args, MAX_RECORDED_JSON) ?? {},\n ok: call.ok,\n ms: Math.max(0, Math.round(call.ms)),\n ...(call.error === undefined ? {} : { error: truncate(call.error, MAX_RECORDED_TEXT) }),\n ...(call.result === undefined ? {} : { result: { content, ...(details === undefined ? {} : { details }) } }),\n };\n}\n\nfunction toResult(\n result: PoIsolateResult,\n output: ReturnType<typeof createOutput>,\n saved: string | undefined,\n calls: readonly PoCodemodeCall[],\n): PoHeadlessToolResult {\n const content: PoHeadlessContent[] = [];\n if (output.lines.length > 0) content.push({ type: 'text', text: truncate(output.lines.join('\\n'), MAX_LOG_CHARS) });\n if (result.ok) {\n if (ArrayBuffer.isView(result.value)) {\n content.push({ type: 'text', text: 'The script returned bytes. Pass them to image(data, mimeType) instead.' });\n } else if (result.value !== undefined) {\n content.push({ type: 'text', text: truncate(format(result.value), MAX_VALUE_CHARS) });\n }\n } else {\n const { kind, name, message } = result.error;\n const hint = kind === 'timeout' ? ' Raise timeoutMs or split the work into smaller exec calls.' : '';\n content.push({ type: 'text', text: `${name}: ${message}${hint}` });\n }\n if (content.length === 0) content.push({ type: 'text', text: '(no return value)' });\n if (saved !== undefined) content.push({ type: 'text', text: saved });\n for (const image of output.images) content.push({ type: 'image', data: image.data, mimeType: image.mimeType });\n return {\n content,\n ...(calls.length > 0 ? { details: { calls } } : {}),\n ...(result.ok ? {} : { isError: true }),\n };\n}\n\nfunction sleep(ms: number, signal: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal.aborted) return reject(new Error('Run ended.'));\n const timer = setTimeout(resolve, Math.max(0, ms));\n signal.addEventListener(\n 'abort',\n () => {\n clearTimeout(timer);\n reject(new Error('Run ended.'));\n },\n { once: true },\n );\n });\n}\n\n/** `discover` and `exec` for one session, over the namespaces its packages contributed. */\nexport function createCodemodeTools({ registry, isolate, scripts }: CodemodeToolsOptions): CodemodeTools {\n let running = 0;\n\n const visible = (service: PoIsolateService): PoCodemodeNamespace[] =>\n registry.list().filter((namespace) => service.liveObjects || namespace.portable === true);\n\n // ponytail: the cockpit's generic tool item renders both for now; add a poWeb renderer for exec code and images when it earns one.\n // web-plugin-tool-renderers: ignore discover, plain text result\n const discover: CodemodeTools['discover'] = {\n name: 'discover',\n label: 'Discover',\n description:\n 'List the code-mode namespaces and reusable scripts you can use from `exec`, show one namespace in full, ' +\n 'or search members and scripts. ' +\n 'Not required before exec: its description already names the namespaces.',\n parameters: DiscoverToolSchema,\n promptSnippet: 'List code-mode namespaces and their TypeScript declarations',\n executionMode: 'parallel',\n async execute(_toolCallId, parameters: DiscoverToolParams, _signal, _onUpdate, execution) {\n const service = isolate();\n if (!service) return text('Code mode is not available on this host.', true);\n const namespaces = visible(service);\n // Imports need a host with live objects; the edge saves scripts but cannot chain them.\n const listed = scripts && service.liveObjects ? await scripts.list(activeDomains(execution)) : [];\n if (parameters.namespace !== undefined) {\n const found = namespaces.find((namespace) => namespace.name === parameters.namespace);\n if (!found) {\n const names = namespaces.map((namespace) => namespace.name).join(', ') || 'none';\n return text(`Unknown namespace \"${parameters.namespace}\". Registered: ${names}.`, true);\n }\n return text(truncate(found.declarations, MAX_DECLARATION_CHARS));\n }\n if (parameters.query !== undefined) {\n const needle = parameters.query.toLowerCase();\n const hits: string[] = [];\n for (const namespace of namespaces) {\n const lines = namespace.declarations.split('\\n');\n lines.forEach((line, index) => {\n if (!line.toLowerCase().includes(needle) || hits.length >= MAX_QUERY_LINES) return;\n const doc = lines[index - 1]?.trim().startsWith('/**') ? `${lines[index - 1]?.trim()} ` : '';\n hits.push(`${namespace.name}: ${doc}${line.trim()}`);\n });\n }\n for (const script of listed) {\n if (hits.length >= MAX_QUERY_LINES) break;\n if (`${script.specifier} ${script.description}`.toLowerCase().includes(needle)) {\n hits.push(`script ${script.specifier}: ${script.description}`);\n }\n }\n return text(hits.length > 0 ? hits.join('\\n') : `No members or scripts match \"${parameters.query}\".`);\n }\n const sections: string[] = [];\n if (namespaces.length === 0) sections.push('No namespaces are registered in this session.');\n for (const namespace of namespaces) {\n sections.push(`- ${namespace.name}: ${namespace.summary}\\n members: ${memberNames(namespace).join(', ')}`);\n }\n sections.push(GLOBALS_HELP);\n if (!service.liveObjects) sections.push('This host runs plain JavaScript with JSON-only functions.');\n if (listed.length > 0) {\n sections.push(`Scripts. ${SCRIPTS_HELP}`);\n for (const script of listed.slice(0, MAX_LISTED_SCRIPTS)) {\n sections.push(`- ${script.specifier}${script.description ? `: ${script.description}` : ''}`);\n }\n if (listed.length > MAX_LISTED_SCRIPTS) {\n sections.push(`...and ${listed.length - MAX_LISTED_SCRIPTS} more; use discover({ query }) to search.`);\n }\n }\n if (namespaces.length > 0) sections.push('Call discover({ namespace }) for full types.');\n return text(sections.join('\\n'));\n },\n };\n\n // web-plugin-tool-renderers: ignore exec, generic item until a code and image renderer exists\n const exec: CodemodeTools['exec'] = {\n name: 'exec',\n label: 'Exec',\n get description(): string {\n const service = isolate();\n const namespaces = service ? visible(service) : [];\n const listed = namespaces.map((namespace) => `- ${namespace.name}: ${namespace.summary}`).join('\\n');\n return [\n 'Run a TypeScript script inside the Po server with live objects from the namespaces below in scope.',\n 'It runs with full server trust, like bash. Keep each call to one logical step.',\n listed || '(no namespaces registered yet; call discover to check)',\n GLOBALS_HELP,\n ...(scripts && service?.liveObjects ? [`${SCRIPTS_HELP} discover lists saved and domain scripts.`] : []),\n 'Use discover({ namespace }) for full signatures when needed.',\n ].join('\\n');\n },\n parameters: ExecToolSchema,\n promptSnippet: 'Run a TypeScript script against live Po objects (browser and other namespaces)',\n executionMode: 'serial',\n async execute(_toolCallId, parameters: ExecToolParams, signal, _onUpdate, execution) {\n const service = isolate();\n if (!service) return text('Code mode is not available on this host.', true);\n if (running >= MAX_CONCURRENT_RUNS)\n return text(`This session already has ${MAX_CONCURRENT_RUNS} exec runs active. Wait for one to finish.`, true);\n running += 1;\n const controller = new AbortController();\n const runSignal = signal ? AbortSignal.any([signal, controller.signal]) : controller.signal;\n const cleanups: (() => void | Promise<void>)[] = [];\n const calls: PoCodemodeCall[] = [];\n const output = createOutput();\n const run: PoCodemodeRun = {\n sessionId: execution.sessionId,\n signal: runSignal,\n onDispose: (cleanup) => void cleanups.push(cleanup),\n record: (call) => {\n if (calls.length < MAX_RECORDED_CALLS) calls.push(recordedCall(call));\n },\n };\n try {\n let saved: string | undefined;\n try {\n const file = await scripts?.save(parameters.code);\n if (file) saved = `Saved as ${file.specifier} (${file.path})`;\n } catch (error) {\n output.note(`Could not save the script: ${error instanceof Error ? error.message : String(error)}`);\n }\n const globals: Record<string, unknown> = {\n console: output.console,\n image: output.addImage,\n sleep: (ms: number) => sleep(ms, runSignal),\n };\n const deny = new Set<string>();\n for (const namespace of visible(service)) {\n globals[namespace.name] = namespace.bind(run);\n for (const member of namespace.deny ?? []) deny.add(member);\n }\n const deadlineMs = Math.min(\n MAX_TIMEOUT_MS,\n Math.max(MIN_TIMEOUT_MS, parameters.timeoutMs ?? DEFAULT_TIMEOUT_MS),\n );\n const result = await service.run({\n source: parameters.code,\n globals,\n deadlineMs,\n signal: runSignal,\n deny: [...deny],\n onDiagnostic: output.note,\n ...(scripts ? { resolveImport: (specifier) => scripts.resolve(specifier, activeDomains(execution)) } : {}),\n });\n return toResult(result, output, saved, calls);\n } catch (error) {\n return text(\n `Code mode could not run the script: ${error instanceof Error ? error.message : String(error)}`,\n true,\n );\n } finally {\n controller.abort();\n for (const cleanup of cleanups.reverse()) {\n await Promise.resolve()\n .then(cleanup)\n .catch((error: unknown) => output.note(`cleanup failed: ${String(error)}`));\n }\n running -= 1;\n }\n },\n };\n\n return { discover, exec };\n}\n"],"mappings":";;;;;AASA,SAAgB,yBAA4C;CAC1D,MAAM,0BAAU,IAAI,IAAgE;CACpF,MAAM,0BAAU,IAAI,IAA4B;CAChD,MAAM,4BAAY,IAAI,IAAgB;CACtC,MAAM,eAAqB;EACzB,KAAK,MAAM,YAAY,WAAW,SAAS;CAC7C;CACA,OAAO;EACL,SAAS,QAAgB,WAAwD;GAC/E,4BAA4B,UAAU,IAAI;GAC1C,MAAM,QAAQ,QAAQ,IAAI,UAAU,IAAI;GACxC,IAAI,OACF,MAAM,IAAI,MACR,wBAAwB,UAAU,KAAK,SAAS,OAAO,4BAA4B,MAAM,OAAO,EAClG;GAEF,MAAM,QAAQ;IAAE;IAAQ;GAAU;GAClC,QAAQ,IAAI,UAAU,MAAM,KAAK;GACjC,OAAO;GACP,OAAO,EACL,eAAe;IACb,IAAI,QAAQ,IAAI,UAAU,IAAI,MAAM,OAAO;IAC3C,QAAQ,OAAO,UAAU,IAAI;IAC7B,OAAO;GACT,EACF;EACF;EACA,YAAY,CAAC,GAAG,QAAQ,OAAO,CAAC,CAAC,CAAC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