@myagentroam/agent 0.10.23 → 0.10.24
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.
|
@@ -82,6 +82,10 @@ export async function createCodeModeEngine(options) {
|
|
|
82
82
|
const syntaxError = locateSource && error?.name === 'SyntaxError';
|
|
83
83
|
if (syntaxError)
|
|
84
84
|
message = `JavaScript compilation failed before tool execution: ${message}`.slice(0, 4096);
|
|
85
|
+
if (error?.name === 'ReferenceError' &&
|
|
86
|
+
["'text' is not defined", "'console' is not defined"].includes(message))
|
|
87
|
+
message =
|
|
88
|
+
`${message} Code Mode has no console or standalone text/image helpers; use observe.text(value) or observe.image(value).`.slice(0, 4096);
|
|
85
89
|
const location = locateSource ? compilerSourceLocation(error, input.code) : '';
|
|
86
90
|
if (location)
|
|
87
91
|
message = message.slice(0, 4096 - location.length) + location;
|
|
@@ -331,7 +335,7 @@ export async function createCodeModeEngine(options) {
|
|
|
331
335
|
}
|
|
332
336
|
if (kind === 'result')
|
|
333
337
|
return {
|
|
334
|
-
error: guestError('MAR_AGENT_TOOL_INPUT_INVALID',
|
|
338
|
+
error: guestError('MAR_AGENT_TOOL_INPUT_INVALID', `observe.result requires an unmodified original tool result or error; received ${handle ? vm.typeof(handle) : 'undefined'}. Pass the awaited tools.NAME(...) result; use observe.text(value) for derived values.`)
|
|
335
339
|
};
|
|
336
340
|
// A standalone image is a value, never an original tool-result observation.
|
|
337
341
|
if (kind === 'image') {
|
|
@@ -634,11 +638,11 @@ function streamText(value, emit) {
|
|
|
634
638
|
return;
|
|
635
639
|
}
|
|
636
640
|
const ancestors = new Set();
|
|
637
|
-
const write = (item, key) => {
|
|
641
|
+
const write = (item, key, path) => {
|
|
638
642
|
if (item && typeof item === 'object' && typeof item.toJSON === 'function')
|
|
639
643
|
item = item.toJSON(key);
|
|
640
644
|
if (['bigint', 'function', 'symbol', 'undefined'].includes(typeof item))
|
|
641
|
-
throw Object.assign(new TypeError(
|
|
645
|
+
throw Object.assign(new TypeError(`Only JSON values may be emitted; ${path} has type ${typeof item}. Omit optional fields or use null explicitly.`), {
|
|
642
646
|
code: 'MAR_AGENT_TOOL_INPUT_INVALID'
|
|
643
647
|
});
|
|
644
648
|
if (item instanceof Number || item instanceof String || item instanceof Boolean)
|
|
@@ -666,7 +670,7 @@ function streamText(value, emit) {
|
|
|
666
670
|
for (let index = 0; index < length; index++) {
|
|
667
671
|
if (index)
|
|
668
672
|
emit(',');
|
|
669
|
-
write(item[index], String(index));
|
|
673
|
+
write(item[index], String(index), `${path}[${index}]`.slice(0, 256));
|
|
670
674
|
}
|
|
671
675
|
emit(']');
|
|
672
676
|
}
|
|
@@ -689,13 +693,13 @@ function streamText(value, emit) {
|
|
|
689
693
|
(name === 'dataBase64' || (name === 'data' && item.type === 'image')) &&
|
|
690
694
|
typeof field === 'string'
|
|
691
695
|
? '[image payload omitted; use observe.image]'
|
|
692
|
-
: field, name);
|
|
696
|
+
: field, name, `${path}[${JSON.stringify(name.slice(0, 64))}]`.slice(0, 256));
|
|
693
697
|
}
|
|
694
698
|
emit('}');
|
|
695
699
|
}
|
|
696
700
|
ancestors.delete(item);
|
|
697
701
|
};
|
|
698
|
-
write(value, '');
|
|
702
|
+
write(value, '', '$');
|
|
699
703
|
}
|
|
700
704
|
function compilerSourceLocation(error, source) {
|
|
701
705
|
if (error?.name !== 'SyntaxError' ||
|
|
@@ -242,33 +242,34 @@ async function detectEncoding(path) {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
function parseReadInput(value) {
|
|
245
|
-
if (!value || typeof value !== 'object')
|
|
246
|
-
return invalidReadInput();
|
|
245
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
246
|
+
return invalidReadInput('input', 'an object with a reads array');
|
|
247
247
|
const input = value;
|
|
248
|
-
if (Object.keys(input).some((key) => key !== 'reads'))
|
|
249
|
-
return invalidReadInput();
|
|
250
248
|
if (!Array.isArray(input.reads) ||
|
|
251
249
|
input.reads.length === 0 ||
|
|
252
250
|
input.reads.length > TOOL_EXECUTION_LIMITS.readMaxBatchItems)
|
|
253
|
-
return invalidReadInput();
|
|
251
|
+
return invalidReadInput('reads', `an array of 1 to ${TOOL_EXECUTION_LIMITS.readMaxBatchItems} requests`);
|
|
252
|
+
if (Object.keys(input).some((key) => key !== 'reads'))
|
|
253
|
+
return invalidReadInput('input', 'only the reads field; put path/offset/limit inside reads');
|
|
254
254
|
return { reads: input.reads.map(parseReadRequest) };
|
|
255
255
|
}
|
|
256
|
-
function parseReadRequest(value) {
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
function parseReadRequest(value, index) {
|
|
257
|
+
const field = `reads[${index}]`;
|
|
258
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
259
|
+
return invalidReadInput(field, 'an object with path and optional offset/limit');
|
|
259
260
|
const input = value;
|
|
260
261
|
if (Object.keys(input).some((key) => !['path', 'offset', 'limit'].includes(key)))
|
|
261
|
-
return invalidReadInput();
|
|
262
|
+
return invalidReadInput(field, 'only path, offset and limit fields');
|
|
262
263
|
if (typeof input.path !== 'string' || input.path === '')
|
|
263
|
-
return invalidReadInput();
|
|
264
|
+
return invalidReadInput(`${field}.path`, 'a non-empty string');
|
|
264
265
|
if (input.offset !== undefined &&
|
|
265
266
|
input.offset !== null &&
|
|
266
267
|
(!Number.isInteger(input.offset) || input.offset < 1))
|
|
267
|
-
return invalidReadInput();
|
|
268
|
+
return invalidReadInput(`${field}.offset`, 'an integer >= 1');
|
|
268
269
|
if (input.limit !== undefined &&
|
|
269
270
|
input.limit !== null &&
|
|
270
271
|
(!Number.isInteger(input.limit) || input.limit < 1))
|
|
271
|
-
return invalidReadInput();
|
|
272
|
+
return invalidReadInput(`${field}.limit`, 'an integer >= 1');
|
|
272
273
|
return {
|
|
273
274
|
path: input.path,
|
|
274
275
|
...(typeof input.offset === 'number' ? { offset: input.offset } : {}),
|
|
@@ -292,8 +293,8 @@ function readError(path, error) {
|
|
|
292
293
|
: 'MAR_AGENT_TOOL_FAILED';
|
|
293
294
|
return { path, error: { code, message: 'Unable to read file.' } };
|
|
294
295
|
}
|
|
295
|
-
function invalidReadInput() {
|
|
296
|
-
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID',
|
|
296
|
+
function invalidReadInput(field, expected) {
|
|
297
|
+
throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', `${field}: expected ${expected}.`);
|
|
297
298
|
}
|
|
298
299
|
function escapeAttribute(value) {
|
|
299
300
|
return value.replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<');
|