mu-core 0.19.0 → 0.22.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/esm/agent.d.ts +3 -0
- package/esm/agent.js +16 -8
- package/esm/types.d.ts +1 -1
- package/package.json +1 -1
- package/script/agent.d.ts +3 -0
- package/script/agent.js +16 -8
- package/script/types.d.ts +1 -1
package/esm/agent.d.ts
CHANGED
package/esm/agent.js
CHANGED
|
@@ -36,17 +36,25 @@ export async function* run(opts) {
|
|
|
36
36
|
const registry = new Map(tools.map((t) => [t.name, t]));
|
|
37
37
|
const messages = [...opts.messages];
|
|
38
38
|
while (true) {
|
|
39
|
+
if (signal?.aborted)
|
|
40
|
+
break;
|
|
39
41
|
const content = [];
|
|
40
42
|
const calls = [];
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
try {
|
|
44
|
+
for await (const event of provider.stream({ model, messages, tools, signal })) {
|
|
45
|
+
if (event.type === 'usage' || event.type === 'reasoning') {
|
|
46
|
+
yield event;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
43
49
|
yield event;
|
|
44
|
-
|
|
50
|
+
append(content, event);
|
|
51
|
+
if (event.type === 'tool_call')
|
|
52
|
+
calls.push(event);
|
|
45
53
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
yield { type: 'error', error: error instanceof Error ? error : new Error(String(error)) };
|
|
57
|
+
break;
|
|
50
58
|
}
|
|
51
59
|
const message = { role: 'assistant', content };
|
|
52
60
|
messages.push(message);
|
|
@@ -58,7 +66,7 @@ export async function* run(opts) {
|
|
|
58
66
|
id: call.id,
|
|
59
67
|
content: await execute(registry, call, signal),
|
|
60
68
|
})));
|
|
61
|
-
const toolMessage = { role: '
|
|
69
|
+
const toolMessage = { role: 'tool', content: results };
|
|
62
70
|
messages.push(toolMessage);
|
|
63
71
|
yield { type: 'message', message: toolMessage };
|
|
64
72
|
}
|
package/esm/types.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type ContentPart = {
|
|
|
19
19
|
id: string;
|
|
20
20
|
content: ContentPart[];
|
|
21
21
|
};
|
|
22
|
-
export type Role = 'system' | 'user' | 'assistant';
|
|
22
|
+
export type Role = 'system' | 'user' | 'assistant' | 'tool';
|
|
23
23
|
export type Message = {
|
|
24
24
|
role: Role;
|
|
25
25
|
content: ContentPart[];
|
package/package.json
CHANGED
package/script/agent.d.ts
CHANGED
package/script/agent.js
CHANGED
|
@@ -40,17 +40,25 @@ async function* run(opts) {
|
|
|
40
40
|
const registry = new Map(tools.map((t) => [t.name, t]));
|
|
41
41
|
const messages = [...opts.messages];
|
|
42
42
|
while (true) {
|
|
43
|
+
if (signal?.aborted)
|
|
44
|
+
break;
|
|
43
45
|
const content = [];
|
|
44
46
|
const calls = [];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
try {
|
|
48
|
+
for await (const event of provider.stream({ model, messages, tools, signal })) {
|
|
49
|
+
if (event.type === 'usage' || event.type === 'reasoning') {
|
|
50
|
+
yield event;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
47
53
|
yield event;
|
|
48
|
-
|
|
54
|
+
append(content, event);
|
|
55
|
+
if (event.type === 'tool_call')
|
|
56
|
+
calls.push(event);
|
|
49
57
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
yield { type: 'error', error: error instanceof Error ? error : new Error(String(error)) };
|
|
61
|
+
break;
|
|
54
62
|
}
|
|
55
63
|
const message = { role: 'assistant', content };
|
|
56
64
|
messages.push(message);
|
|
@@ -62,7 +70,7 @@ async function* run(opts) {
|
|
|
62
70
|
id: call.id,
|
|
63
71
|
content: await execute(registry, call, signal),
|
|
64
72
|
})));
|
|
65
|
-
const toolMessage = { role: '
|
|
73
|
+
const toolMessage = { role: 'tool', content: results };
|
|
66
74
|
messages.push(toolMessage);
|
|
67
75
|
yield { type: 'message', message: toolMessage };
|
|
68
76
|
}
|
package/script/types.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type ContentPart = {
|
|
|
19
19
|
id: string;
|
|
20
20
|
content: ContentPart[];
|
|
21
21
|
};
|
|
22
|
-
export type Role = 'system' | 'user' | 'assistant';
|
|
22
|
+
export type Role = 'system' | 'user' | 'assistant' | 'tool';
|
|
23
23
|
export type Message = {
|
|
24
24
|
role: Role;
|
|
25
25
|
content: ContentPart[];
|