@link-assistant/agent 0.25.5 → 0.25.6
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/package.json +1 -1
- package/src/cli/cmd/run.ts +5 -1
- package/src/cli/continuous-mode.js +3 -0
- package/src/cli/event-handler.js +5 -1
- package/src/index.js +3 -0
- package/src/util/error-text.ts +82 -0
package/package.json
CHANGED
package/src/cli/cmd/run.ts
CHANGED
|
@@ -264,7 +264,11 @@ export const RunCommand = cmd({
|
|
|
264
264
|
err = String(props.error.data.message);
|
|
265
265
|
}
|
|
266
266
|
errorMsg = errorMsg ? errorMsg + EOL + err : err;
|
|
267
|
-
|
|
267
|
+
// Always include the human-readable string alongside the
|
|
268
|
+
// machine-readable object so consumers never print
|
|
269
|
+
// "[object Object]" (#289).
|
|
270
|
+
if (outputJsonEvent('error', { message: err, error: props.error }))
|
|
271
|
+
continue;
|
|
268
272
|
UI.error(err);
|
|
269
273
|
}
|
|
270
274
|
|
|
@@ -11,6 +11,7 @@ import { SessionPrompt } from '../session/prompt.ts';
|
|
|
11
11
|
import { createEventHandler, serializeOutput } from '../json-standard/index.ts';
|
|
12
12
|
import { createContinuousStdinReader } from './input-queue.js';
|
|
13
13
|
import { outputBusEvent } from './event-handler.js';
|
|
14
|
+
import { errorText } from '../util/error-text.ts';
|
|
14
15
|
import { Permission } from '../permission/index.ts';
|
|
15
16
|
import { Log } from '../util/log.ts';
|
|
16
17
|
import { config } from '../config/config.ts';
|
|
@@ -385,6 +386,7 @@ export async function runContinuousServerMode(
|
|
|
385
386
|
type: 'error',
|
|
386
387
|
timestamp: Date.now(),
|
|
387
388
|
sessionID,
|
|
389
|
+
message: errorText(error),
|
|
388
390
|
error: error instanceof Error ? error.message : String(error),
|
|
389
391
|
});
|
|
390
392
|
});
|
|
@@ -598,6 +600,7 @@ export async function runContinuousDirectMode(
|
|
|
598
600
|
type: 'error',
|
|
599
601
|
timestamp: Date.now(),
|
|
600
602
|
sessionID,
|
|
603
|
+
message: errorText(error),
|
|
601
604
|
error: error instanceof Error ? error.message : String(error),
|
|
602
605
|
});
|
|
603
606
|
});
|
package/src/cli/event-handler.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Bus } from '../bus/index.ts';
|
|
7
|
+
import { errorText } from '../util/error-text.ts';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Create a subscription for session bus events that outputs events in the selected JSON format.
|
|
@@ -90,11 +91,13 @@ export function outputBusEvent({
|
|
|
90
91
|
|
|
91
92
|
// If tool failed, also output an error event
|
|
92
93
|
if (part.state?.status === 'error') {
|
|
94
|
+
const stateError = part.state.error;
|
|
93
95
|
eventHandler.output({
|
|
94
96
|
type: 'error',
|
|
95
97
|
timestamp: Date.now(),
|
|
96
98
|
sessionID,
|
|
97
|
-
|
|
99
|
+
message: errorText(stateError, 'Tool execution failed'),
|
|
100
|
+
error: stateError || 'Tool execution failed',
|
|
98
101
|
});
|
|
99
102
|
}
|
|
100
103
|
}
|
|
@@ -145,6 +148,7 @@ export function outputBusEvent({
|
|
|
145
148
|
type: 'error',
|
|
146
149
|
timestamp: Date.now(),
|
|
147
150
|
sessionID,
|
|
151
|
+
message: errorText(props.error),
|
|
148
152
|
error: props.error,
|
|
149
153
|
});
|
|
150
154
|
}
|
package/src/index.js
CHANGED
|
@@ -27,6 +27,7 @@ import { McpCommand } from './cli/cmd/mcp.ts';
|
|
|
27
27
|
import { AuthCommand } from './cli/cmd/auth.ts';
|
|
28
28
|
import { FormatError } from './cli/error.ts';
|
|
29
29
|
import { UI } from './cli/ui.ts';
|
|
30
|
+
import { errorText } from './util/error-text.ts';
|
|
30
31
|
import {
|
|
31
32
|
createVerboseFetch,
|
|
32
33
|
registerPendingStreamLogExitHandler,
|
|
@@ -520,6 +521,7 @@ async function runServerMode(
|
|
|
520
521
|
type: 'error',
|
|
521
522
|
timestamp: Date.now(),
|
|
522
523
|
sessionID,
|
|
524
|
+
message: errorText(error),
|
|
523
525
|
error: error instanceof Error ? error.message : String(error),
|
|
524
526
|
});
|
|
525
527
|
});
|
|
@@ -605,6 +607,7 @@ async function runDirectMode(
|
|
|
605
607
|
type: 'error',
|
|
606
608
|
timestamp: Date.now(),
|
|
607
609
|
sessionID,
|
|
610
|
+
message: errorText(error),
|
|
608
611
|
error: error instanceof Error ? error.message : String(error),
|
|
609
612
|
});
|
|
610
613
|
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-readable rendering of arbitrary error values (issue #289).
|
|
3
|
+
*
|
|
4
|
+
* JSON `error` events used to carry only the machine-readable
|
|
5
|
+
* `NamedError.toObject()` shape (`{name, data: {message}}`), so consumers doing
|
|
6
|
+
* `` `${record.error}` `` published `[object Object]` and the real cause was
|
|
7
|
+
* lost. Every emitted `error` event now also carries a `message` string
|
|
8
|
+
* produced by `stringifyErrorValue`.
|
|
9
|
+
*
|
|
10
|
+
* The renderer is circular-safe and depth-limited, and never invents a
|
|
11
|
+
* placeholder: when nothing readable can be derived it returns an empty
|
|
12
|
+
* string so the caller can pick its own fallback.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const MAX_DEPTH = 5;
|
|
16
|
+
|
|
17
|
+
function fromParts(name: string | undefined, message: string | undefined) {
|
|
18
|
+
if (name && message) return `${name}: ${message}`;
|
|
19
|
+
return message || name || '';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function render(value: unknown, depth: number, seen: Set<object>): string {
|
|
23
|
+
if (value === null || value === undefined) return '';
|
|
24
|
+
if (typeof value === 'string') return value.trim();
|
|
25
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
26
|
+
return String(value);
|
|
27
|
+
if (typeof value !== 'object') return '';
|
|
28
|
+
|
|
29
|
+
const object = value as Record<string, unknown>;
|
|
30
|
+
if (seen.has(object)) return '';
|
|
31
|
+
if (depth >= MAX_DEPTH) return '';
|
|
32
|
+
seen.add(object);
|
|
33
|
+
|
|
34
|
+
if (Array.isArray(object)) {
|
|
35
|
+
const rendered = object
|
|
36
|
+
.map((item) => render(item, depth + 1, seen))
|
|
37
|
+
.filter((item) => item.length > 0);
|
|
38
|
+
return rendered.join('; ');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (object instanceof Error) {
|
|
42
|
+
return fromParts(object.name, object.message) || String(object);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// NamedError.toObject(): { name, data: { message, ... } }
|
|
46
|
+
const name = typeof object.name === 'string' ? object.name : undefined;
|
|
47
|
+
const data = object.data;
|
|
48
|
+
if (data && typeof data === 'object') {
|
|
49
|
+
const dataMessage = render(
|
|
50
|
+
(data as Record<string, unknown>).message,
|
|
51
|
+
depth + 1,
|
|
52
|
+
seen
|
|
53
|
+
);
|
|
54
|
+
if (dataMessage) return fromParts(name, dataMessage);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const message = render(object.message, depth + 1, seen);
|
|
58
|
+
if (message) return fromParts(name, message);
|
|
59
|
+
|
|
60
|
+
// Envelope shapes: { error: … }, { cause: … }
|
|
61
|
+
const nested =
|
|
62
|
+
render(object.error, depth + 1, seen) ||
|
|
63
|
+
render(object.cause, depth + 1, seen);
|
|
64
|
+
if (nested) return name ? fromParts(name, nested) : nested;
|
|
65
|
+
|
|
66
|
+
return name || '';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Render any error-ish value as a human-readable string.
|
|
71
|
+
* Returns an empty string when nothing readable can be derived.
|
|
72
|
+
*/
|
|
73
|
+
export function stringifyErrorValue(value: unknown): string {
|
|
74
|
+
return render(value, 0, new Set<object>());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Same as {@link stringifyErrorValue} but guarantees a non-empty string.
|
|
79
|
+
*/
|
|
80
|
+
export function errorText(value: unknown, fallback = 'Unknown error'): string {
|
|
81
|
+
return stringifyErrorValue(value) || fallback;
|
|
82
|
+
}
|