mu-core 0.20.0 → 0.22.1
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/index.d.ts +1 -1
- package/esm/types.d.ts +12 -1
- package/package.json +1 -1
- package/script/agent.d.ts +3 -0
- package/script/agent.js +16 -8
- package/script/index.d.ts +1 -1
- package/script/types.d.ts +12 -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/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { ContentPart, Message, Provider, Role, StreamEvent, Tool, Usage } from './types.js';
|
|
1
|
+
export type { ContentPart, Message, ModelModalities, Provider, Role, StreamEvent, Tool, Usage } from './types.js';
|
|
2
2
|
export { audio, image, text } from './types.js';
|
|
3
3
|
export type { Agent, AgentConfig, AgentResult, Input, LoopEvent, RunOptions } from './agent.js';
|
|
4
4
|
export { createAgent, run } from './agent.js';
|
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[];
|
|
@@ -49,6 +49,11 @@ export type StreamEvent = ContentPart | {
|
|
|
49
49
|
type: 'reasoning';
|
|
50
50
|
text: string;
|
|
51
51
|
};
|
|
52
|
+
/** Non-text input modalities a model accepts. */
|
|
53
|
+
export interface ModelModalities {
|
|
54
|
+
vision: boolean;
|
|
55
|
+
audio: boolean;
|
|
56
|
+
}
|
|
52
57
|
export interface Provider {
|
|
53
58
|
stream(req: {
|
|
54
59
|
model: string;
|
|
@@ -56,4 +61,10 @@ export interface Provider {
|
|
|
56
61
|
tools: Tool[];
|
|
57
62
|
signal?: AbortSignal;
|
|
58
63
|
}): AsyncIterable<StreamEvent>;
|
|
64
|
+
/**
|
|
65
|
+
* Probe a model's input modalities. MAY load the model (e.g. a llama.cpp `/props`
|
|
66
|
+
* fetch) — call it on model selection, not on every turn. Optional: providers that
|
|
67
|
+
* can't introspect modalities simply omit it.
|
|
68
|
+
*/
|
|
69
|
+
capabilities?(model: string): Promise<ModelModalities | undefined>;
|
|
59
70
|
}
|
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/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { ContentPart, Message, Provider, Role, StreamEvent, Tool, Usage } from './types.js';
|
|
1
|
+
export type { ContentPart, Message, ModelModalities, Provider, Role, StreamEvent, Tool, Usage } from './types.js';
|
|
2
2
|
export { audio, image, text } from './types.js';
|
|
3
3
|
export type { Agent, AgentConfig, AgentResult, Input, LoopEvent, RunOptions } from './agent.js';
|
|
4
4
|
export { createAgent, run } from './agent.js';
|
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[];
|
|
@@ -49,6 +49,11 @@ export type StreamEvent = ContentPart | {
|
|
|
49
49
|
type: 'reasoning';
|
|
50
50
|
text: string;
|
|
51
51
|
};
|
|
52
|
+
/** Non-text input modalities a model accepts. */
|
|
53
|
+
export interface ModelModalities {
|
|
54
|
+
vision: boolean;
|
|
55
|
+
audio: boolean;
|
|
56
|
+
}
|
|
52
57
|
export interface Provider {
|
|
53
58
|
stream(req: {
|
|
54
59
|
model: string;
|
|
@@ -56,4 +61,10 @@ export interface Provider {
|
|
|
56
61
|
tools: Tool[];
|
|
57
62
|
signal?: AbortSignal;
|
|
58
63
|
}): AsyncIterable<StreamEvent>;
|
|
64
|
+
/**
|
|
65
|
+
* Probe a model's input modalities. MAY load the model (e.g. a llama.cpp `/props`
|
|
66
|
+
* fetch) — call it on model selection, not on every turn. Optional: providers that
|
|
67
|
+
* can't introspect modalities simply omit it.
|
|
68
|
+
*/
|
|
69
|
+
capabilities?(model: string): Promise<ModelModalities | undefined>;
|
|
59
70
|
}
|