@brainpilot/runtime 0.0.5 → 0.0.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/README.md +61 -0
- package/dist/agent-error.d.ts +51 -0
- package/dist/agent-error.d.ts.map +1 -0
- package/dist/agent-error.js +163 -0
- package/dist/agent-error.js.map +1 -0
- package/dist/agent-factory.d.ts.map +1 -1
- package/dist/agent-factory.js +36 -6
- package/dist/agent-factory.js.map +1 -1
- package/dist/events.d.ts +18 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +24 -0
- package/dist/events.js.map +1 -1
- package/dist/extensions/agent-status.d.ts +91 -0
- package/dist/extensions/agent-status.d.ts.map +1 -0
- package/dist/extensions/agent-status.js +103 -0
- package/dist/extensions/agent-status.js.map +1 -0
- package/dist/extensions/trace-reminder.d.ts +94 -0
- package/dist/extensions/trace-reminder.d.ts.map +1 -0
- package/dist/extensions/trace-reminder.js +153 -0
- package/dist/extensions/trace-reminder.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mailbox.d.ts +37 -1
- package/dist/mailbox.d.ts.map +1 -1
- package/dist/mailbox.js +79 -2
- package/dist/mailbox.js.map +1 -1
- package/dist/mas-agent.d.ts +74 -12
- package/dist/mas-agent.d.ts.map +1 -1
- package/dist/mas-agent.js +158 -33
- package/dist/mas-agent.js.map +1 -1
- package/dist/materialize-skills.d.ts +40 -0
- package/dist/materialize-skills.d.ts.map +1 -0
- package/dist/materialize-skills.js +141 -0
- package/dist/materialize-skills.js.map +1 -0
- package/dist/mock-agent.d.ts.map +1 -1
- package/dist/mock-agent.js +13 -1
- package/dist/mock-agent.js.map +1 -1
- package/dist/personas.d.ts +16 -0
- package/dist/personas.d.ts.map +1 -1
- package/dist/personas.js +651 -8
- package/dist/personas.js.map +1 -1
- package/dist/pi-provider.d.ts +5 -0
- package/dist/pi-provider.d.ts.map +1 -1
- package/dist/pi-provider.js +7 -1
- package/dist/pi-provider.js.map +1 -1
- package/dist/provider-config.d.ts +5 -0
- package/dist/provider-config.d.ts.map +1 -1
- package/dist/provider-config.js +2 -0
- package/dist/provider-config.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +82 -8
- package/dist/server.js.map +1 -1
- package/dist/session-manager.d.ts +311 -8
- package/dist/session-manager.d.ts.map +1 -1
- package/dist/session-manager.js +896 -39
- package/dist/session-manager.js.map +1 -1
- package/dist/tools/skill-search.d.ts +53 -0
- package/dist/tools/skill-search.d.ts.map +1 -0
- package/dist/tools/skill-search.js +269 -0
- package/dist/tools/skill-search.js.map +1 -0
- package/dist/tools/system-tools.d.ts +22 -1
- package/dist/tools/system-tools.d.ts.map +1 -1
- package/dist/tools/system-tools.js +149 -21
- package/dist/tools/system-tools.js.map +1 -1
- package/dist/trace.d.ts +27 -1
- package/dist/trace.d.ts.map +1 -1
- package/dist/trace.js +60 -3
- package/dist/trace.js.map +1 -1
- package/dist/types.d.ts +51 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -2
package/dist/mas-agent.d.ts
CHANGED
|
@@ -8,12 +8,26 @@
|
|
|
8
8
|
* converted to RUN_ERROR + system_message and the agent goes to `error`.
|
|
9
9
|
* - Map Pi `auto_retry_start/end` → agent_status_update + system_message;
|
|
10
10
|
* suppress internal events (turn_*, compaction_*).
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
|
+
* Behavioural hooks (remind/trace/reply/delegate) used to live here as per-turn
|
|
13
|
+
* TurnTrackers (#79). They now live in the Pi-native `trace-reminder` extension
|
|
14
|
+
* (`extensions/trace-reminder.ts`), registered per AgentSession by the real
|
|
15
|
+
* factory. MasAgent is back to a pure Pi→AG-UI translator.
|
|
12
16
|
*/
|
|
13
|
-
import type { AgUiEvent, AgentState } from "@brainpilot/protocol";
|
|
17
|
+
import type { AgUiEvent, AgentState, TokenUsage } from "@brainpilot/protocol";
|
|
14
18
|
import type { EventBus } from "./event-bus.js";
|
|
15
|
-
import
|
|
19
|
+
import { type AgentErrorKind } from "./agent-error.js";
|
|
20
|
+
import type { AgentRole, IAgentSession, PiUsage } from "./types.js";
|
|
16
21
|
export type AgentStatus = "idle" | "running" | "error" | "stopped";
|
|
22
|
+
/** Zeroed token counters — the identity element for accumulation. */
|
|
23
|
+
export declare function emptyTokenUsage(): TokenUsage;
|
|
24
|
+
/**
|
|
25
|
+
* Fold a provider-reported `PiUsage` into a running `TokenUsage` total
|
|
26
|
+
* (mutates and returns `acc`). Missing fields count as 0. `total` is summed
|
|
27
|
+
* from the components rather than trusting the provider's `totalTokens` so the
|
|
28
|
+
* per-agent breakdown always sums to the session total under one definition.
|
|
29
|
+
*/
|
|
30
|
+
export declare function addUsage(acc: TokenUsage, u: PiUsage | undefined): TokenUsage;
|
|
17
31
|
export interface MasAgentOpts {
|
|
18
32
|
sessionId: string;
|
|
19
33
|
name: string;
|
|
@@ -21,6 +35,13 @@ export interface MasAgentOpts {
|
|
|
21
35
|
session: IAgentSession;
|
|
22
36
|
bus: EventBus;
|
|
23
37
|
onStatusChange?: (name: string, status: AgentStatus) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Invoked after each assistant turn whose `message_end` carried provider
|
|
40
|
+
* token usage. `delta` is just-added usage for this turn; `cumulative` is the
|
|
41
|
+
* agent's running total. The SessionManager uses this to roll up the
|
|
42
|
+
* per-session total, push a session_state frame, and persist usage.json.
|
|
43
|
+
*/
|
|
44
|
+
onUsage?: (name: string, delta: TokenUsage, cumulative: TokenUsage) => void;
|
|
24
45
|
}
|
|
25
46
|
export declare class MasAgent {
|
|
26
47
|
private readonly opts;
|
|
@@ -36,30 +57,71 @@ export declare class MasAgent {
|
|
|
36
57
|
private inReasoning;
|
|
37
58
|
private activeToolExecutions;
|
|
38
59
|
private lastError;
|
|
39
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Cumulative real token usage for THIS agent across every assistant turn,
|
|
62
|
+
* summed from provider-reported `usage` on `message_end`. Read by `usage()`;
|
|
63
|
+
* fed to `onUsage` so the SessionManager can roll up the per-session total.
|
|
64
|
+
*/
|
|
65
|
+
private cumulativeUsage;
|
|
66
|
+
/**
|
|
67
|
+
* #97 error path: recoverability class of the most recent error, or undefined
|
|
68
|
+
* when the last run did not error. The delivery loop reads this after a run to
|
|
69
|
+
* decide self-retry (retryable) vs immediate escalation to the principal
|
|
70
|
+
* (fatal). Reset to undefined whenever a run completes without error.
|
|
71
|
+
*/
|
|
72
|
+
private _lastErrorKind;
|
|
73
|
+
/**
|
|
74
|
+
* The in-flight `prompt()` promise (its try/catch/finally inclusive), or
|
|
75
|
+
* undefined when idle. `abort()` awaits this so a caller can fence the old
|
|
76
|
+
* run — guaranteeing RUN_FINISHED is emitted and `status` has settled —
|
|
77
|
+
* before starting a new one (#101).
|
|
78
|
+
*/
|
|
79
|
+
private currentPrompt;
|
|
40
80
|
constructor(opts: MasAgentOpts);
|
|
41
81
|
get status(): AgentStatus;
|
|
82
|
+
/**
|
|
83
|
+
* #97: the recoverability class of the last error (`retryable`/`fatal`), or
|
|
84
|
+
* undefined if the last run did not error. Read by the delivery loop to choose
|
|
85
|
+
* self-retry vs escalation. The headline of that error is in `lastError`.
|
|
86
|
+
*/
|
|
87
|
+
get lastErrorKind(): AgentErrorKind | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Cumulative real token usage for this agent (a copy, safe to mutate). Used
|
|
90
|
+
* by the SessionManager when rebuilding the per-session breakdown and when
|
|
91
|
+
* persisting usage.json.
|
|
92
|
+
*/
|
|
93
|
+
usage(): TokenUsage;
|
|
94
|
+
/**
|
|
95
|
+
* Restore this agent's cumulative usage from persisted state (restore path,
|
|
96
|
+
* before any new turn). No-op if `u` is undefined.
|
|
97
|
+
*/
|
|
98
|
+
seedUsage(u: TokenUsage | undefined): void;
|
|
42
99
|
/** §10 authoritative state snapshot. */
|
|
43
100
|
state(): AgentState;
|
|
44
101
|
private setStatus;
|
|
45
102
|
/**
|
|
46
103
|
* Send a prompt and stream events. Error-isolated (§7 L2): never throws.
|
|
104
|
+
* The settled promise is tracked in `currentPrompt` so `abort()` can await it.
|
|
47
105
|
*/
|
|
48
106
|
prompt(text: string): Promise<void>;
|
|
107
|
+
private runPrompt;
|
|
108
|
+
/**
|
|
109
|
+
* Abort the active run and wait for it to fully settle (#101).
|
|
110
|
+
*
|
|
111
|
+
* `session.abort()` cancels the provider stream (and for the real Pi session
|
|
112
|
+
* already awaits the agent back to idle). We then await the in-flight
|
|
113
|
+
* `prompt()` promise so that by the time abort() resolves: the original run
|
|
114
|
+
* has emitted its terminal RUN_FINISHED/RUN_ERROR, `status` has settled, and
|
|
115
|
+
* no further assistant content can be appended. This lets `interrupt()` start
|
|
116
|
+
* the principal's interrupt-notice run WITHOUT racing the old run (which would
|
|
117
|
+
* otherwise throw "Agent is already processing a prompt").
|
|
118
|
+
*/
|
|
49
119
|
abort(): Promise<void>;
|
|
50
120
|
stop(): void;
|
|
51
121
|
private recordError;
|
|
52
|
-
private resetTrackers;
|
|
53
122
|
/** Translate one Pi event into zero or more AG-UI events (§6). */
|
|
54
123
|
private onPiEvent;
|
|
55
124
|
private onAssistantDelta;
|
|
56
|
-
private onToolResult;
|
|
57
|
-
/** Expose tracker state (for hook tests). */
|
|
58
|
-
getTrackers(): {
|
|
59
|
-
replied: boolean;
|
|
60
|
-
traced: boolean;
|
|
61
|
-
delegated: boolean;
|
|
62
|
-
};
|
|
63
125
|
}
|
|
64
126
|
export type { AgUiEvent };
|
|
65
127
|
//# sourceMappingURL=mas-agent.d.ts.map
|
package/dist/mas-agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mas-agent.d.ts","sourceRoot":"","sources":["../src/mas-agent.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mas-agent.d.ts","sourceRoot":"","sources":["../src/mas-agent.ts"],"names":[],"mappings":"AAAA;;;;;;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CAAC,QAAQ,CAAC,WAAW,CAAa;IAEzC,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,oBAAoB,CAAqB;IACjD,OAAO,CAAC,SAAS,CAA0B;IAC3C;;;;OAIG;IACH,OAAO,CAAC,eAAe,CAAiC;IACxD;;;;;OAKG;IACH,OAAO,CAAC,cAAc,CAA6B;IACnD;;;;;OAKG;IACH,OAAO,CAAC,aAAa,CAA4B;gBAEpB,IAAI,EAAE,YAAY;IAS/C,IAAI,MAAM,IAAI,WAAW,CAExB;IAED;;;;OAIG;IACH,IAAI,aAAa,IAAI,cAAc,GAAG,SAAS,CAE9C;IAED;;;;OAIG;IACH,KAAK,IAAI,UAAU;IAInB;;;OAGG;IACH,SAAS,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,IAAI;IAI1C,wCAAwC;IACxC,KAAK,IAAI,UAAU;IAQnB,OAAO,CAAC,SAAS;IAajB;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YASrB,SAAS;IAkCvB;;;;;;;;;;OAUG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB5B,IAAI,IAAI,IAAI;IAMZ,OAAO,CAAC,WAAW;IAgBnB,kEAAkE;IAClE,OAAO,CAAC,SAAS;IA4HjB,OAAO,CAAC,gBAAgB;CA+CzB;AAYD,YAAY,EAAE,SAAS,EAAE,CAAC"}
|
package/dist/mas-agent.js
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
import { ev, newMessageId, newRunId } from "./events.js";
|
|
2
|
+
import { normalizeAgentError, classifyAgentError } from "./agent-error.js";
|
|
3
|
+
/** Zeroed token counters — the identity element for accumulation. */
|
|
4
|
+
export function emptyTokenUsage() {
|
|
5
|
+
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Fold a provider-reported `PiUsage` into a running `TokenUsage` total
|
|
9
|
+
* (mutates and returns `acc`). Missing fields count as 0. `total` is summed
|
|
10
|
+
* from the components rather than trusting the provider's `totalTokens` so the
|
|
11
|
+
* per-agent breakdown always sums to the session total under one definition.
|
|
12
|
+
*/
|
|
13
|
+
export function addUsage(acc, u) {
|
|
14
|
+
if (!u)
|
|
15
|
+
return acc;
|
|
16
|
+
const input = u.input ?? 0;
|
|
17
|
+
const output = u.output ?? 0;
|
|
18
|
+
const cacheRead = u.cacheRead ?? 0;
|
|
19
|
+
const cacheWrite = u.cacheWrite ?? 0;
|
|
20
|
+
acc.input += input;
|
|
21
|
+
acc.output += output;
|
|
22
|
+
acc.cacheRead += cacheRead;
|
|
23
|
+
acc.cacheWrite += cacheWrite;
|
|
24
|
+
acc.total += input + output + cacheRead + cacheWrite;
|
|
25
|
+
return acc;
|
|
26
|
+
}
|
|
2
27
|
export class MasAgent {
|
|
3
28
|
opts;
|
|
4
29
|
name;
|
|
@@ -13,8 +38,26 @@ export class MasAgent {
|
|
|
13
38
|
inReasoning = false;
|
|
14
39
|
activeToolExecutions = new Set();
|
|
15
40
|
lastError;
|
|
16
|
-
|
|
17
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Cumulative real token usage for THIS agent across every assistant turn,
|
|
43
|
+
* summed from provider-reported `usage` on `message_end`. Read by `usage()`;
|
|
44
|
+
* fed to `onUsage` so the SessionManager can roll up the per-session total.
|
|
45
|
+
*/
|
|
46
|
+
cumulativeUsage = emptyTokenUsage();
|
|
47
|
+
/**
|
|
48
|
+
* #97 error path: recoverability class of the most recent error, or undefined
|
|
49
|
+
* when the last run did not error. The delivery loop reads this after a run to
|
|
50
|
+
* decide self-retry (retryable) vs immediate escalation to the principal
|
|
51
|
+
* (fatal). Reset to undefined whenever a run completes without error.
|
|
52
|
+
*/
|
|
53
|
+
_lastErrorKind;
|
|
54
|
+
/**
|
|
55
|
+
* The in-flight `prompt()` promise (its try/catch/finally inclusive), or
|
|
56
|
+
* undefined when idle. `abort()` awaits this so a caller can fence the old
|
|
57
|
+
* run — guaranteeing RUN_FINISHED is emitted and `status` has settled —
|
|
58
|
+
* before starting a new one (#101).
|
|
59
|
+
*/
|
|
60
|
+
currentPrompt;
|
|
18
61
|
constructor(opts) {
|
|
19
62
|
this.opts = opts;
|
|
20
63
|
this.name = opts.name;
|
|
@@ -27,6 +70,30 @@ export class MasAgent {
|
|
|
27
70
|
get status() {
|
|
28
71
|
return this._status;
|
|
29
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* #97: the recoverability class of the last error (`retryable`/`fatal`), or
|
|
75
|
+
* undefined if the last run did not error. Read by the delivery loop to choose
|
|
76
|
+
* self-retry vs escalation. The headline of that error is in `lastError`.
|
|
77
|
+
*/
|
|
78
|
+
get lastErrorKind() {
|
|
79
|
+
return this._lastErrorKind;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Cumulative real token usage for this agent (a copy, safe to mutate). Used
|
|
83
|
+
* by the SessionManager when rebuilding the per-session breakdown and when
|
|
84
|
+
* persisting usage.json.
|
|
85
|
+
*/
|
|
86
|
+
usage() {
|
|
87
|
+
return { ...this.cumulativeUsage };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Restore this agent's cumulative usage from persisted state (restore path,
|
|
91
|
+
* before any new turn). No-op if `u` is undefined.
|
|
92
|
+
*/
|
|
93
|
+
seedUsage(u) {
|
|
94
|
+
if (u)
|
|
95
|
+
this.cumulativeUsage = { ...u };
|
|
96
|
+
}
|
|
30
97
|
/** §10 authoritative state snapshot. */
|
|
31
98
|
state() {
|
|
32
99
|
const s = { name: this.name, status: this._status };
|
|
@@ -51,21 +118,40 @@ export class MasAgent {
|
|
|
51
118
|
}
|
|
52
119
|
/**
|
|
53
120
|
* Send a prompt and stream events. Error-isolated (§7 L2): never throws.
|
|
121
|
+
* The settled promise is tracked in `currentPrompt` so `abort()` can await it.
|
|
54
122
|
*/
|
|
55
|
-
|
|
123
|
+
prompt(text) {
|
|
124
|
+
const p = this.runPrompt(text).finally(() => {
|
|
125
|
+
// Clear the tracker only if no newer prompt has replaced it.
|
|
126
|
+
if (this.currentPrompt === p)
|
|
127
|
+
this.currentPrompt = undefined;
|
|
128
|
+
});
|
|
129
|
+
this.currentPrompt = p;
|
|
130
|
+
return p;
|
|
131
|
+
}
|
|
132
|
+
async runPrompt(text) {
|
|
56
133
|
this.currentRunId = newRunId();
|
|
57
|
-
this.resetTrackers();
|
|
58
134
|
this.setStatus("running");
|
|
59
135
|
this.bus.emit(ev.runStarted({ sessionId: this.sessionId, agentName: this.name, runId: this.currentRunId }));
|
|
60
136
|
try {
|
|
61
137
|
await this.session.prompt(text);
|
|
62
138
|
this.bus.emit(ev.runFinished({ sessionId: this.sessionId, agentName: this.name, runId: this.currentRunId }));
|
|
63
|
-
|
|
139
|
+
// A run that reached here without an in-stream error (message_end /
|
|
140
|
+
// auto_retry_end / delta error all flip status to "error") completed
|
|
141
|
+
// cleanly — clear the error class so the delivery loop's retry counter
|
|
142
|
+
// resets on the next success.
|
|
143
|
+
if (this._status !== "error") {
|
|
144
|
+
this._lastErrorKind = undefined;
|
|
64
145
|
this.setStatus("idle");
|
|
146
|
+
}
|
|
65
147
|
}
|
|
66
148
|
catch (err) {
|
|
67
|
-
const
|
|
68
|
-
|
|
149
|
+
const raw = err?.message ?? String(err);
|
|
150
|
+
// issue #45: never surface raw SDK guidance (/login, node_modules paths)
|
|
151
|
+
// — normalize to a product message / redact local paths before it hits
|
|
152
|
+
// the event stream, events.jsonl, and lastError.
|
|
153
|
+
const { message, details } = normalizeAgentError(raw);
|
|
154
|
+
this.recordError(message, details, raw);
|
|
69
155
|
this.bus.emit(ev.runError({ sessionId: this.sessionId, agentName: this.name, runId: this.currentRunId }, message));
|
|
70
156
|
this.setStatus("error");
|
|
71
157
|
}
|
|
@@ -74,6 +160,17 @@ export class MasAgent {
|
|
|
74
160
|
this.currentMessageId = undefined;
|
|
75
161
|
}
|
|
76
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Abort the active run and wait for it to fully settle (#101).
|
|
165
|
+
*
|
|
166
|
+
* `session.abort()` cancels the provider stream (and for the real Pi session
|
|
167
|
+
* already awaits the agent back to idle). We then await the in-flight
|
|
168
|
+
* `prompt()` promise so that by the time abort() resolves: the original run
|
|
169
|
+
* has emitted its terminal RUN_FINISHED/RUN_ERROR, `status` has settled, and
|
|
170
|
+
* no further assistant content can be appended. This lets `interrupt()` start
|
|
171
|
+
* the principal's interrupt-notice run WITHOUT racing the old run (which would
|
|
172
|
+
* otherwise throw "Agent is already processing a prompt").
|
|
173
|
+
*/
|
|
77
174
|
async abort() {
|
|
78
175
|
try {
|
|
79
176
|
await this.session.abort();
|
|
@@ -81,40 +178,48 @@ export class MasAgent {
|
|
|
81
178
|
catch {
|
|
82
179
|
/* abort best-effort */
|
|
83
180
|
}
|
|
181
|
+
// Wait for the interrupted prompt to unwind its try/finally (RUN_FINISHED,
|
|
182
|
+
// status settle) before returning — do NOT optimistically force idle here.
|
|
183
|
+
try {
|
|
184
|
+
await this.currentPrompt;
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
/* prompt() is error-isolated; nothing to surface */
|
|
188
|
+
}
|
|
84
189
|
this.activeToolExecutions.clear();
|
|
85
|
-
this.setStatus("idle");
|
|
86
190
|
}
|
|
87
191
|
stop() {
|
|
88
192
|
this.unsubscribe();
|
|
89
193
|
this.session.dispose();
|
|
90
194
|
this.setStatus("stopped");
|
|
91
195
|
}
|
|
92
|
-
recordError(message, details) {
|
|
196
|
+
recordError(message, details, raw) {
|
|
93
197
|
const prev = this.lastError?.consecutiveCount ?? 0;
|
|
94
198
|
this.lastError = { message, timestamp: new Date().toISOString(), consecutiveCount: prev + 1 };
|
|
199
|
+
// #97: classify from the rawest signal we have (raw provider blob when the
|
|
200
|
+
// caller has it, else the normalized headline) so the delivery loop can pick
|
|
201
|
+
// self-retry vs escalation.
|
|
202
|
+
this._lastErrorKind = classifyAgentError(raw ?? message);
|
|
95
203
|
this.bus.emit(ev.systemMessage(this.sessionId, "error", `⚠️ Agent ${this.name} 遇到错误: ${message}`, {
|
|
96
204
|
agent: this.name,
|
|
97
205
|
details,
|
|
98
206
|
recoverable: true,
|
|
99
207
|
}));
|
|
100
208
|
}
|
|
101
|
-
resetTrackers() {
|
|
102
|
-
this.trackers = { replied: false, traced: false, delegated: false };
|
|
103
|
-
}
|
|
104
209
|
/** Translate one Pi event into zero or more AG-UI events (§6). */
|
|
105
210
|
onPiEvent(e) {
|
|
106
211
|
const ctx = { sessionId: this.sessionId, agentName: this.name, runId: this.currentRunId };
|
|
107
212
|
switch (e.type) {
|
|
108
213
|
case "agent_start":
|
|
109
|
-
case "turn_end":
|
|
110
214
|
case "agent_end":
|
|
215
|
+
case "turn_start":
|
|
216
|
+
case "turn_end":
|
|
111
217
|
case "compaction_start":
|
|
112
218
|
case "compaction_end":
|
|
113
219
|
case "queue_update":
|
|
114
220
|
// Internal / suppressed (§6 table: turn_*, compaction_* not exposed).
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
this.resetTrackers();
|
|
221
|
+
// Behavioural reactions to turn_*/agent_end now live in the Pi-native
|
|
222
|
+
// trace-reminder extension, not here.
|
|
118
223
|
return;
|
|
119
224
|
case "message_start": {
|
|
120
225
|
const msg = e;
|
|
@@ -131,6 +236,26 @@ export class MasAgent {
|
|
|
131
236
|
return;
|
|
132
237
|
}
|
|
133
238
|
case "message_end": {
|
|
239
|
+
const end = e;
|
|
240
|
+
// #63: a provider/HTTP error does NOT throw out of session.prompt(); Pi
|
|
241
|
+
// finalizes the assistant message with stopReason "error" + errorMessage
|
|
242
|
+
// and emits it here. Surface it as a visible error instead of letting the
|
|
243
|
+
// run end with an empty assistant bubble.
|
|
244
|
+
const msg = end.message;
|
|
245
|
+
if (msg?.stopReason === "error") {
|
|
246
|
+
const raw = msg.errorMessage || "provider request failed";
|
|
247
|
+
const { message, details } = normalizeAgentError(raw);
|
|
248
|
+
this.recordError(message, details, raw);
|
|
249
|
+
this.setStatus("error");
|
|
250
|
+
}
|
|
251
|
+
// Accumulate real provider token usage for this assistant turn. Pi
|
|
252
|
+
// attaches `usage` to the finalized assistant message; user/tool
|
|
253
|
+
// messages and mock feeds may omit it (addUsage no-ops on undefined).
|
|
254
|
+
if (msg?.role === "assistant" && msg.usage) {
|
|
255
|
+
const delta = addUsage(emptyTokenUsage(), msg.usage);
|
|
256
|
+
addUsage(this.cumulativeUsage, msg.usage);
|
|
257
|
+
this.opts.onUsage?.(this.name, delta, { ...this.cumulativeUsage });
|
|
258
|
+
}
|
|
134
259
|
if (this.currentMessageId) {
|
|
135
260
|
if (this.inReasoning) {
|
|
136
261
|
this.bus.emit(ev.reasoningMessageEnd(ctx, this.currentMessageId));
|
|
@@ -156,8 +281,6 @@ export class MasAgent {
|
|
|
156
281
|
this.bus.emit(ev.toolCallEnd(ctx, t.toolCallId));
|
|
157
282
|
const resultStr = typeof t.result === "string" ? t.result : safeStringify(t.result);
|
|
158
283
|
this.bus.emit(ev.toolCallResult(ctx, t.toolCallId, resultStr, t.isError));
|
|
159
|
-
// §8 hooks: mark replied/traced/delegated from tool results.
|
|
160
|
-
this.onToolResult(t.toolName, t.isError);
|
|
161
284
|
// §7 L1: surface tool errors as system_message.
|
|
162
285
|
if (t.isError) {
|
|
163
286
|
this.bus.emit(ev.systemMessage(this.sessionId, "warning", `❌ ${t.toolName} 执行失败`, {
|
|
@@ -176,7 +299,9 @@ export class MasAgent {
|
|
|
176
299
|
case "auto_retry_end": {
|
|
177
300
|
const r = e;
|
|
178
301
|
if (!r.success) {
|
|
179
|
-
|
|
302
|
+
const raw = r.finalError ?? "retry exhausted";
|
|
303
|
+
const { message, details } = normalizeAgentError(raw);
|
|
304
|
+
this.recordError(message, details, raw);
|
|
180
305
|
this.setStatus("error");
|
|
181
306
|
}
|
|
182
307
|
return;
|
|
@@ -210,24 +335,24 @@ export class MasAgent {
|
|
|
210
335
|
this.bus.emit(ev.reasoningMessageEnd(ctx, id));
|
|
211
336
|
this.inReasoning = false;
|
|
212
337
|
return;
|
|
338
|
+
case "error": {
|
|
339
|
+
// #63: provider failure streamed mid-message. Route to a visible error
|
|
340
|
+
// (the message_end handler also catches the finalized stopReason:"error",
|
|
341
|
+
// but this covers Pi builds that only emit the streaming sub-event).
|
|
342
|
+
const err = amsg;
|
|
343
|
+
const raw = err.error?.errorMessage ??
|
|
344
|
+
(typeof err.error === "string" ? err.error : undefined) ??
|
|
345
|
+
err.reason ??
|
|
346
|
+
"provider request failed";
|
|
347
|
+
const { message, details } = normalizeAgentError(raw);
|
|
348
|
+
this.recordError(message, details, raw);
|
|
349
|
+
this.setStatus("error");
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
213
352
|
default:
|
|
214
353
|
return;
|
|
215
354
|
}
|
|
216
355
|
}
|
|
217
|
-
onToolResult(toolName, isError) {
|
|
218
|
-
if (isError)
|
|
219
|
-
return;
|
|
220
|
-
if (toolName === "send_message")
|
|
221
|
-
this.trackers.replied = true;
|
|
222
|
-
if (toolName === "record_trace" || toolName.startsWith("create_trace"))
|
|
223
|
-
this.trackers.traced = true;
|
|
224
|
-
if (toolName === "create_agent")
|
|
225
|
-
this.trackers.delegated = true;
|
|
226
|
-
}
|
|
227
|
-
/** Expose tracker state (for hook tests). */
|
|
228
|
-
getTrackers() {
|
|
229
|
-
return { ...this.trackers };
|
|
230
|
-
}
|
|
231
356
|
}
|
|
232
357
|
function safeStringify(v) {
|
|
233
358
|
if (v === undefined || v === null)
|
package/dist/mas-agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mas-agent.js","sourceRoot":"","sources":["../src/mas-agent.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAmBzD,MAAM,OAAO,QAAQ;I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CAAC,GAAG,CAAC,CAAC;gBACtD,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;gBACxC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;gBACxB,OAAO;YACT,CAAC;YACD;gBACE,OAAO;QACX,CAAC;IACH,CAAC;CACF;AAED,SAAS,aAAa,CAAC,CAAU;IAC/B,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAC7C,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACpC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source category whose contents go into the always-on library. Anything else
|
|
3
|
+
* ends up in the router library. Kept as a constant so a test can pin the
|
|
4
|
+
* distribution rule explicitly.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ALWAYS_ON_CATEGORY = "01_Meta-Skills";
|
|
7
|
+
/** Result of a materialize run. */
|
|
8
|
+
export interface MaterializeSkillsResult {
|
|
9
|
+
/** Absolute always-on destination dir (`<dataRoot>/bp_template/skills`). */
|
|
10
|
+
dest: string;
|
|
11
|
+
/** Absolute router destination dir (`<dataRoot>/bp_template/skills-router`). */
|
|
12
|
+
routerDest: string;
|
|
13
|
+
/** Absolute source dir (the bundled `@brainpilot/skills` skills/). */
|
|
14
|
+
source: string | null;
|
|
15
|
+
/** Files freshly copied into the always-on dir. */
|
|
16
|
+
copied: number;
|
|
17
|
+
/** Files skipped (already existed) in the always-on dir. */
|
|
18
|
+
skipped: number;
|
|
19
|
+
/** Files freshly copied into the router dir. */
|
|
20
|
+
routerCopied: number;
|
|
21
|
+
/** Files skipped (already existed) in the router dir. */
|
|
22
|
+
routerSkipped: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Locate the bundled `skills/` directory of the `@brainpilot/skills` package.
|
|
26
|
+
* Resolves the package via `require.resolve` so it works under workspace
|
|
27
|
+
* symlinks, flat npm `node_modules`, and the Docker image alike. Returns null
|
|
28
|
+
* if the package can't be resolved (skills are a convenience, not a hard dep).
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveBundledSkillsDir(from?: string): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Materialize the bundled skills, splitting by source category:
|
|
33
|
+
* `01_Meta-Skills/*` → always-on dir, every other top-level category → router
|
|
34
|
+
* dir. Skip-if-exists at the file level on BOTH destinations: existing files
|
|
35
|
+
* are preserved, missing ones are filled in. Safe to call on every launch. A
|
|
36
|
+
* no-op (all counts 0) when the package can't be resolved or the source is
|
|
37
|
+
* empty/absent.
|
|
38
|
+
*/
|
|
39
|
+
export declare function materializeSkills(dataRoot: string): Promise<MaterializeSkillsResult>;
|
|
40
|
+
//# sourceMappingURL=materialize-skills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"materialize-skills.d.ts","sourceRoot":"","sources":["../src/materialize-skills.ts"],"names":[],"mappings":"AAsCA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AAEnD,mCAAmC;AACnC,MAAM,WAAW,uBAAuB;IACtC,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,UAAU,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,YAAY,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,GAAE,MAAwB,GAAG,MAAM,GAAG,IAAI,CASrF;AAwCD;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAsC1F"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* materialize-skills.ts — copy the bundled `@brainpilot/skills` content into a
|
|
3
|
+
* data dir, splitting it across TWO physically separate skill libraries:
|
|
4
|
+
*
|
|
5
|
+
* <dataRoot>/bp_template/skills/ (always-on, Pi-native)
|
|
6
|
+
* Loaded through Pi's `additionalSkillPaths`. Every SKILL.md's name +
|
|
7
|
+
* description appears in the agent's `<available_skills>` block. Reserved
|
|
8
|
+
* for high-frequency Meta-Skills so the prompt does not bloat.
|
|
9
|
+
*
|
|
10
|
+
* <dataRoot>/bp_template/skills-router/ (router-only)
|
|
11
|
+
* Pi never sees this directory; it is reachable only via the `skill_search`
|
|
12
|
+
* custom tool. Holds the long tail of domain skills.
|
|
13
|
+
*
|
|
14
|
+
* Distribution rule (purely physical):
|
|
15
|
+
* - bundled `01_Meta-Skills/*` → always-on
|
|
16
|
+
* - everything else → router
|
|
17
|
+
*
|
|
18
|
+
* Both libraries accept user-added skills with the SAME on-disk format
|
|
19
|
+
* (`<category>/<skill_name>/SKILL.md` + optional `references/` / `scripts/`),
|
|
20
|
+
* so the user can drop a directory into either side and it just works.
|
|
21
|
+
*
|
|
22
|
+
* Pipeline (three stages, see issues #139/#140):
|
|
23
|
+
* - package time: skills ship read-only inside `@brainpilot/skills`.
|
|
24
|
+
* - deploy time: this fn copies them into the two destinations above.
|
|
25
|
+
* - runtime: Pi loads from `bp_template/skills/` via additionalSkillPaths;
|
|
26
|
+
* `skill_search` reads `bp_template/skills-router/`.
|
|
27
|
+
*
|
|
28
|
+
* Idempotent and edit-preserving: a file that already exists at either
|
|
29
|
+
* destination is NEVER overwritten (so user edits and per-skill customisations
|
|
30
|
+
* survive). Called from BOTH the CLI `scaffold` and the runtime server startup.
|
|
31
|
+
* It lives in `@brainpilot/runtime` (not the CLI) because the dependency
|
|
32
|
+
* direction is cli → runtime.
|
|
33
|
+
*/
|
|
34
|
+
import { createRequire } from "node:module";
|
|
35
|
+
import { mkdir, readdir, copyFile, access } from "node:fs/promises";
|
|
36
|
+
import { constants as FS } from "node:fs";
|
|
37
|
+
import { dirname, join } from "node:path";
|
|
38
|
+
/**
|
|
39
|
+
* Source category whose contents go into the always-on library. Anything else
|
|
40
|
+
* ends up in the router library. Kept as a constant so a test can pin the
|
|
41
|
+
* distribution rule explicitly.
|
|
42
|
+
*/
|
|
43
|
+
export const ALWAYS_ON_CATEGORY = "01_Meta-Skills";
|
|
44
|
+
/**
|
|
45
|
+
* Locate the bundled `skills/` directory of the `@brainpilot/skills` package.
|
|
46
|
+
* Resolves the package via `require.resolve` so it works under workspace
|
|
47
|
+
* symlinks, flat npm `node_modules`, and the Docker image alike. Returns null
|
|
48
|
+
* if the package can't be resolved (skills are a convenience, not a hard dep).
|
|
49
|
+
*/
|
|
50
|
+
export function resolveBundledSkillsDir(from = import.meta.url) {
|
|
51
|
+
try {
|
|
52
|
+
const require = createRequire(from);
|
|
53
|
+
// package.json is always at the package root; skills/ sits beside it.
|
|
54
|
+
const pkgJson = require.resolve("@brainpilot/skills/package.json");
|
|
55
|
+
return join(dirname(pkgJson), "skills");
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function exists(path) {
|
|
62
|
+
try {
|
|
63
|
+
await access(path, FS.F_OK);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Recursively copy `src` → `dst`, skipping any file that already exists at the
|
|
72
|
+
* destination. Mutates `counters` so the caller can report copied/skipped.
|
|
73
|
+
*/
|
|
74
|
+
async function copyTreeSkipExisting(src, dst, counters) {
|
|
75
|
+
await mkdir(dst, { recursive: true });
|
|
76
|
+
const entries = await readdir(src, { withFileTypes: true });
|
|
77
|
+
for (const entry of entries) {
|
|
78
|
+
const from = join(src, entry.name);
|
|
79
|
+
const to = join(dst, entry.name);
|
|
80
|
+
if (entry.isDirectory()) {
|
|
81
|
+
await copyTreeSkipExisting(from, to, counters);
|
|
82
|
+
}
|
|
83
|
+
else if (entry.isFile()) {
|
|
84
|
+
if (await exists(to)) {
|
|
85
|
+
counters.skipped++;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
await copyFile(from, to);
|
|
89
|
+
counters.copied++;
|
|
90
|
+
}
|
|
91
|
+
// symlinks / other types are intentionally ignored — skill content is
|
|
92
|
+
// plain files and directories.
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Materialize the bundled skills, splitting by source category:
|
|
97
|
+
* `01_Meta-Skills/*` → always-on dir, every other top-level category → router
|
|
98
|
+
* dir. Skip-if-exists at the file level on BOTH destinations: existing files
|
|
99
|
+
* are preserved, missing ones are filled in. Safe to call on every launch. A
|
|
100
|
+
* no-op (all counts 0) when the package can't be resolved or the source is
|
|
101
|
+
* empty/absent.
|
|
102
|
+
*/
|
|
103
|
+
export async function materializeSkills(dataRoot) {
|
|
104
|
+
const dest = join(dataRoot, "bp_template", "skills");
|
|
105
|
+
const routerDest = join(dataRoot, "bp_template", "skills-router");
|
|
106
|
+
const source = resolveBundledSkillsDir();
|
|
107
|
+
const alwaysOn = { copied: 0, skipped: 0 };
|
|
108
|
+
const router = { copied: 0, skipped: 0 };
|
|
109
|
+
// Always ensure both destination dirs exist so loaders / the router tool
|
|
110
|
+
// have a stable path even when the source is missing or empty.
|
|
111
|
+
await mkdir(dest, { recursive: true });
|
|
112
|
+
await mkdir(routerDest, { recursive: true });
|
|
113
|
+
if (source && (await exists(source))) {
|
|
114
|
+
const topLevel = await readdir(source, { withFileTypes: true });
|
|
115
|
+
for (const entry of topLevel) {
|
|
116
|
+
if (!entry.isDirectory())
|
|
117
|
+
continue; // skip stray files at the source root
|
|
118
|
+
const from = join(source, entry.name);
|
|
119
|
+
if (entry.name === ALWAYS_ON_CATEGORY) {
|
|
120
|
+
// Mount the meta-skills directory at the SAME relative path inside the
|
|
121
|
+
// always-on library so a user-added meta-skill drops in identically.
|
|
122
|
+
const to = join(dest, entry.name);
|
|
123
|
+
await copyTreeSkipExisting(from, to, alwaysOn);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const to = join(routerDest, entry.name);
|
|
127
|
+
await copyTreeSkipExisting(from, to, router);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
dest,
|
|
133
|
+
routerDest,
|
|
134
|
+
source: source && (await exists(source)) ? source : null,
|
|
135
|
+
copied: alwaysOn.copied,
|
|
136
|
+
skipped: alwaysOn.skipped,
|
|
137
|
+
routerCopied: router.copied,
|
|
138
|
+
routerSkipped: router.skipped,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=materialize-skills.js.map
|