mu-core 0.20.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 CHANGED
@@ -8,6 +8,9 @@ export type LoopEvent = ContentPart | {
8
8
  } | {
9
9
  type: 'message';
10
10
  message: Message;
11
+ } | {
12
+ type: 'error';
13
+ error: Error;
11
14
  } | {
12
15
  type: 'done';
13
16
  messages: Message[];
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
- for await (const event of provider.stream({ model, messages, tools, signal })) {
42
- if (event.type === 'usage' || event.type === 'reasoning') {
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
- continue;
50
+ append(content, event);
51
+ if (event.type === 'tool_call')
52
+ calls.push(event);
45
53
  }
46
- yield event;
47
- append(content, event);
48
- if (event.type === 'tool_call')
49
- calls.push(event);
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: 'user', content: results };
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mu-core",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "Standalone multimodal agentic loop: content, messages, tools, provider interface, createAgent",
5
5
  "license": "MIT",
6
6
  "main": "./script/index.js",
package/script/agent.d.ts CHANGED
@@ -8,6 +8,9 @@ export type LoopEvent = ContentPart | {
8
8
  } | {
9
9
  type: 'message';
10
10
  message: Message;
11
+ } | {
12
+ type: 'error';
13
+ error: Error;
11
14
  } | {
12
15
  type: 'done';
13
16
  messages: Message[];
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
- for await (const event of provider.stream({ model, messages, tools, signal })) {
46
- if (event.type === 'usage' || event.type === 'reasoning') {
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
- continue;
54
+ append(content, event);
55
+ if (event.type === 'tool_call')
56
+ calls.push(event);
49
57
  }
50
- yield event;
51
- append(content, event);
52
- if (event.type === 'tool_call')
53
- calls.push(event);
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: 'user', content: results };
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[];