@mast-ai/core 0.1.1 → 0.2.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/dist/agentTool.js +1 -2
- package/dist/runner.d.ts +14 -1
- package/dist/runner.js +27 -1
- package/package.json +1 -1
package/dist/agentTool.js
CHANGED
|
@@ -22,14 +22,13 @@ export function createAgentTool(runner, agent, options) {
|
|
|
22
22
|
definition: () => definition,
|
|
23
23
|
async call(args, context) {
|
|
24
24
|
const input = options.buildInput(args);
|
|
25
|
-
const builder = runner.runBuilder(agent);
|
|
25
|
+
const builder = runner.runBuilder(agent).forwardTo(context);
|
|
26
26
|
if (context.signal)
|
|
27
27
|
builder.signal(context.signal);
|
|
28
28
|
for await (const event of builder.runStream(input)) {
|
|
29
29
|
if (event.type === 'done') {
|
|
30
30
|
return event.output;
|
|
31
31
|
}
|
|
32
|
-
context.onEvent?.(event);
|
|
33
32
|
}
|
|
34
33
|
throw new AgentError(`Sub-agent '${agent.name}' stream ended without a 'done' event.`);
|
|
35
34
|
},
|
package/dist/runner.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentConfig, AgentEvent, AgentResult, Message } from './types.js';
|
|
2
2
|
import type { LlmAdapter } from './adapter/index.js';
|
|
3
|
-
import { type ToolProvider } from './tool.js';
|
|
3
|
+
import { type ToolContext, type ToolProvider } from './tool.js';
|
|
4
4
|
import { Conversation } from './conversation.js';
|
|
5
5
|
type StreamExecutor = (input: string, history: Message[], signal?: AbortSignal, onToolEvent?: (toolName: string, event: AgentEvent) => void) => AsyncIterable<AgentEvent>;
|
|
6
6
|
/**
|
|
@@ -15,6 +15,7 @@ export declare class RunBuilder {
|
|
|
15
15
|
private _history;
|
|
16
16
|
private _signal?;
|
|
17
17
|
private _onToolEvent?;
|
|
18
|
+
private _forwardContext?;
|
|
18
19
|
constructor(agent: AgentConfig, execute: StreamExecutor);
|
|
19
20
|
/** Prepend prior conversation turns. */
|
|
20
21
|
history(messages: Message[]): this;
|
|
@@ -27,6 +28,18 @@ export declare class RunBuilder {
|
|
|
27
28
|
* events — use `runBuilder().onToolEvent(...).runStream()` for that.
|
|
28
29
|
*/
|
|
29
30
|
onToolEvent(handler: (toolName: string, event: AgentEvent) => void): this;
|
|
31
|
+
/**
|
|
32
|
+
* Forwards every non-`done` event yielded by this run to
|
|
33
|
+
* `parentContext.onEvent`. Intended for tools that internally run a
|
|
34
|
+
* sub-agent: chain this so the parent runner's UI can populate
|
|
35
|
+
* `subThinking` / `subText` / `nestedToolEvents` on the parent's tool
|
|
36
|
+
* entry without manual forwarding boilerplate.
|
|
37
|
+
*
|
|
38
|
+
* `done` events are filtered out to avoid leaking child conversation
|
|
39
|
+
* history to the parent's consumers. If `parentContext.onEvent` is
|
|
40
|
+
* undefined, this is a no-op.
|
|
41
|
+
*/
|
|
42
|
+
forwardTo(parentContext: ToolContext): this;
|
|
30
43
|
/** Executes the run and returns a stream of {@link AgentEvent} objects. */
|
|
31
44
|
runStream(input: string): AsyncIterable<AgentEvent>;
|
|
32
45
|
/** Executes the run and returns the final text output. */
|
package/dist/runner.js
CHANGED
|
@@ -15,6 +15,7 @@ export class RunBuilder {
|
|
|
15
15
|
_history = [];
|
|
16
16
|
_signal;
|
|
17
17
|
_onToolEvent;
|
|
18
|
+
_forwardContext;
|
|
18
19
|
constructor(agent, execute) {
|
|
19
20
|
this.agent = agent;
|
|
20
21
|
this.execute = execute;
|
|
@@ -39,9 +40,34 @@ export class RunBuilder {
|
|
|
39
40
|
this._onToolEvent = handler;
|
|
40
41
|
return this;
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Forwards every non-`done` event yielded by this run to
|
|
45
|
+
* `parentContext.onEvent`. Intended for tools that internally run a
|
|
46
|
+
* sub-agent: chain this so the parent runner's UI can populate
|
|
47
|
+
* `subThinking` / `subText` / `nestedToolEvents` on the parent's tool
|
|
48
|
+
* entry without manual forwarding boilerplate.
|
|
49
|
+
*
|
|
50
|
+
* `done` events are filtered out to avoid leaking child conversation
|
|
51
|
+
* history to the parent's consumers. If `parentContext.onEvent` is
|
|
52
|
+
* undefined, this is a no-op.
|
|
53
|
+
*/
|
|
54
|
+
forwardTo(parentContext) {
|
|
55
|
+
this._forwardContext = parentContext;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
42
58
|
/** Executes the run and returns a stream of {@link AgentEvent} objects. */
|
|
43
59
|
runStream(input) {
|
|
44
|
-
|
|
60
|
+
const stream = this.execute(input, this._history, this._signal, this._onToolEvent);
|
|
61
|
+
const onEvent = this._forwardContext?.onEvent;
|
|
62
|
+
if (!onEvent)
|
|
63
|
+
return stream;
|
|
64
|
+
return (async function* () {
|
|
65
|
+
for await (const event of stream) {
|
|
66
|
+
if (event.type !== 'done')
|
|
67
|
+
onEvent(event);
|
|
68
|
+
yield event;
|
|
69
|
+
}
|
|
70
|
+
})();
|
|
45
71
|
}
|
|
46
72
|
/** Executes the run and returns the final text output. */
|
|
47
73
|
async run(input) {
|