@aigne/core 1.10.0 → 1.12.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/CHANGELOG.md +28 -0
- package/LICENSE +93 -0
- package/README.md +90 -0
- package/README.zh.md +90 -0
- package/lib/cjs/agents/agent.d.ts +21 -20
- package/lib/cjs/agents/agent.js +29 -26
- package/lib/cjs/agents/ai-agent.d.ts +9 -8
- package/lib/cjs/agents/ai-agent.js +20 -14
- package/lib/cjs/agents/mcp-agent.d.ts +10 -4
- package/lib/cjs/agents/mcp-agent.js +12 -6
- package/lib/cjs/agents/memory.d.ts +1 -1
- package/lib/cjs/agents/team-agent.d.ts +28 -0
- package/lib/cjs/agents/team-agent.js +93 -0
- package/lib/cjs/agents/user-agent.d.ts +9 -10
- package/lib/cjs/agents/user-agent.js +10 -13
- package/lib/{esm/execution-engine/execution-engine.d.ts → cjs/aigne/aigne.d.ts} +9 -12
- package/lib/cjs/{execution-engine/execution-engine.js → aigne/aigne.js} +19 -19
- package/lib/cjs/{execution-engine → aigne}/context.d.ts +31 -32
- package/lib/cjs/{execution-engine → aigne}/context.js +30 -40
- package/lib/cjs/aigne/index.d.ts +4 -0
- package/lib/cjs/{execution-engine → aigne}/index.js +2 -2
- package/lib/cjs/{execution-engine → aigne}/usage.d.ts +1 -1
- package/lib/cjs/client/client.d.ts +19 -0
- package/lib/cjs/client/client.js +49 -0
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.js +2 -1
- package/lib/cjs/loader/agent-js.d.ts +2 -2
- package/lib/cjs/loader/agent-js.js +4 -5
- package/lib/cjs/loader/agent-yaml.d.ts +8 -5
- package/lib/cjs/loader/agent-yaml.js +21 -2
- package/lib/cjs/loader/index.d.ts +5 -5
- package/lib/cjs/loader/index.js +8 -19
- package/lib/cjs/models/chat-model.d.ts +1 -1
- package/lib/cjs/models/claude-chat-model.d.ts +3 -1
- package/lib/cjs/models/claude-chat-model.js +75 -60
- package/lib/cjs/models/openai-chat-model.d.ts +3 -3
- package/lib/cjs/models/openai-chat-model.js +1 -3
- package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
- package/lib/cjs/prompt/prompt-builder.js +3 -3
- package/lib/cjs/server/error.d.ts +4 -0
- package/lib/cjs/server/error.js +11 -0
- package/lib/cjs/server/server.d.ts +54 -0
- package/lib/cjs/server/server.js +130 -0
- package/lib/cjs/utils/camelize.d.ts +13 -0
- package/lib/cjs/utils/camelize.js +16 -0
- package/lib/cjs/utils/event-stream.d.ts +11 -0
- package/lib/cjs/utils/event-stream.js +91 -0
- package/lib/cjs/utils/mcp-utils.js +4 -1
- package/lib/cjs/utils/stream-utils.d.ts +10 -3
- package/lib/cjs/utils/stream-utils.js +51 -36
- package/lib/cjs/utils/type-utils.d.ts +4 -2
- package/lib/cjs/utils/type-utils.js +10 -2
- package/lib/dts/agents/agent.d.ts +21 -20
- package/lib/dts/agents/ai-agent.d.ts +9 -8
- package/lib/dts/agents/mcp-agent.d.ts +10 -4
- package/lib/dts/agents/memory.d.ts +1 -1
- package/lib/dts/agents/team-agent.d.ts +28 -0
- package/lib/dts/agents/user-agent.d.ts +9 -10
- package/lib/dts/{execution-engine/execution-engine.d.ts → aigne/aigne.d.ts} +9 -12
- package/lib/dts/{execution-engine → aigne}/context.d.ts +31 -32
- package/lib/dts/aigne/index.d.ts +4 -0
- package/lib/dts/{execution-engine → aigne}/usage.d.ts +1 -1
- package/lib/dts/client/client.d.ts +19 -0
- package/lib/dts/index.d.ts +2 -1
- package/lib/dts/loader/agent-js.d.ts +2 -2
- package/lib/dts/loader/agent-yaml.d.ts +8 -5
- package/lib/dts/loader/index.d.ts +5 -5
- package/lib/dts/models/chat-model.d.ts +1 -1
- package/lib/dts/models/claude-chat-model.d.ts +3 -1
- package/lib/dts/models/openai-chat-model.d.ts +3 -3
- package/lib/dts/prompt/prompt-builder.d.ts +1 -1
- package/lib/dts/server/error.d.ts +4 -0
- package/lib/dts/server/server.d.ts +54 -0
- package/lib/dts/utils/camelize.d.ts +13 -0
- package/lib/dts/utils/event-stream.d.ts +11 -0
- package/lib/dts/utils/stream-utils.d.ts +10 -3
- package/lib/dts/utils/type-utils.d.ts +4 -2
- package/lib/esm/agents/agent.d.ts +21 -20
- package/lib/esm/agents/agent.js +29 -27
- package/lib/esm/agents/ai-agent.d.ts +9 -8
- package/lib/esm/agents/ai-agent.js +20 -14
- package/lib/esm/agents/mcp-agent.d.ts +10 -4
- package/lib/esm/agents/mcp-agent.js +12 -6
- package/lib/esm/agents/memory.d.ts +1 -1
- package/lib/esm/agents/team-agent.d.ts +28 -0
- package/lib/esm/agents/team-agent.js +89 -0
- package/lib/esm/agents/user-agent.d.ts +9 -10
- package/lib/esm/agents/user-agent.js +11 -14
- package/lib/{cjs/execution-engine/execution-engine.d.ts → esm/aigne/aigne.d.ts} +9 -12
- package/lib/esm/{execution-engine/execution-engine.js → aigne/aigne.js} +18 -18
- package/lib/esm/{execution-engine → aigne}/context.d.ts +31 -32
- package/lib/esm/{execution-engine → aigne}/context.js +28 -38
- package/lib/esm/aigne/index.d.ts +4 -0
- package/lib/esm/aigne/index.js +4 -0
- package/lib/esm/{execution-engine → aigne}/usage.d.ts +1 -1
- package/lib/esm/client/client.d.ts +19 -0
- package/lib/esm/client/client.js +45 -0
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/loader/agent-js.d.ts +2 -2
- package/lib/esm/loader/agent-js.js +4 -5
- package/lib/esm/loader/agent-yaml.d.ts +8 -5
- package/lib/esm/loader/agent-yaml.js +21 -2
- package/lib/esm/loader/index.d.ts +5 -5
- package/lib/esm/loader/index.js +8 -19
- package/lib/esm/models/chat-model.d.ts +1 -1
- package/lib/esm/models/claude-chat-model.d.ts +3 -1
- package/lib/esm/models/claude-chat-model.js +75 -60
- package/lib/esm/models/openai-chat-model.d.ts +3 -3
- package/lib/esm/models/openai-chat-model.js +1 -3
- package/lib/esm/prompt/prompt-builder.d.ts +1 -1
- package/lib/esm/prompt/prompt-builder.js +3 -3
- package/lib/esm/server/error.d.ts +4 -0
- package/lib/esm/server/error.js +7 -0
- package/lib/esm/server/server.d.ts +54 -0
- package/lib/esm/server/server.js +123 -0
- package/lib/esm/utils/camelize.d.ts +13 -0
- package/lib/esm/utils/camelize.js +10 -0
- package/lib/esm/utils/event-stream.d.ts +11 -0
- package/lib/esm/utils/event-stream.js +85 -0
- package/lib/esm/utils/mcp-utils.js +4 -1
- package/lib/esm/utils/stream-utils.d.ts +10 -3
- package/lib/esm/utils/stream-utils.js +49 -35
- package/lib/esm/utils/type-utils.d.ts +4 -2
- package/lib/esm/utils/type-utils.js +9 -2
- package/package.json +15 -5
- package/lib/cjs/execution-engine/index.d.ts +0 -4
- package/lib/cjs/execution-engine/utils.d.ts +0 -4
- package/lib/cjs/execution-engine/utils.js +0 -34
- package/lib/dts/execution-engine/index.d.ts +0 -4
- package/lib/dts/execution-engine/utils.d.ts +0 -4
- package/lib/esm/execution-engine/index.d.ts +0 -4
- package/lib/esm/execution-engine/index.js +0 -4
- package/lib/esm/execution-engine/utils.d.ts +0 -4
- package/lib/esm/execution-engine/utils.js +0 -30
- /package/lib/cjs/{execution-engine → aigne}/message-queue.d.ts +0 -0
- /package/lib/cjs/{execution-engine → aigne}/message-queue.js +0 -0
- /package/lib/cjs/{execution-engine → aigne}/usage.js +0 -0
- /package/lib/dts/{execution-engine → aigne}/message-queue.d.ts +0 -0
- /package/lib/esm/{execution-engine → aigne}/message-queue.d.ts +0 -0
- /package/lib/esm/{execution-engine → aigne}/message-queue.js +0 -0
- /package/lib/esm/{execution-engine → aigne}/usage.js +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createParser } from "eventsource-parser";
|
|
2
|
+
import { produce } from "immer";
|
|
3
|
+
import { tryOrThrow } from "./type-utils.js";
|
|
4
|
+
export class EventStreamParser extends TransformStream {
|
|
5
|
+
constructor() {
|
|
6
|
+
let parser;
|
|
7
|
+
super({
|
|
8
|
+
start(controller) {
|
|
9
|
+
parser = createParser({
|
|
10
|
+
onEvent: (event) => {
|
|
11
|
+
const json = tryOrThrow(() => JSON.parse(event.data), (e) => {
|
|
12
|
+
controller.enqueue(new Error(`Parse response chunk json error: ${e.message} ${event.data}`));
|
|
13
|
+
});
|
|
14
|
+
if (json) {
|
|
15
|
+
if (event.event === "error") {
|
|
16
|
+
controller.enqueue(new Error(json.message));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
controller.enqueue(json);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
transform(chunk) {
|
|
26
|
+
parser?.feed(chunk);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class AgentResponseStreamParser extends TransformStream {
|
|
32
|
+
json = {};
|
|
33
|
+
constructor() {
|
|
34
|
+
super({
|
|
35
|
+
transform: (chunk, controller) => {
|
|
36
|
+
if (chunk instanceof Error) {
|
|
37
|
+
controller.error(chunk);
|
|
38
|
+
controller.terminate();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.json = produce(this.json, (draft) => {
|
|
42
|
+
if (chunk.delta.json)
|
|
43
|
+
Object.assign(draft, chunk.delta.json);
|
|
44
|
+
if (chunk.delta.text) {
|
|
45
|
+
for (const [key, text] of Object.entries(chunk.delta.text)) {
|
|
46
|
+
const original = draft[key];
|
|
47
|
+
const t = (original || "") + (text || "");
|
|
48
|
+
if (t)
|
|
49
|
+
Object.assign(draft, { [key]: t });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
controller.enqueue({
|
|
54
|
+
...chunk,
|
|
55
|
+
delta: {
|
|
56
|
+
...chunk.delta,
|
|
57
|
+
json: this.json,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export class AgentResponseStreamSSE extends ReadableStream {
|
|
65
|
+
constructor(stream) {
|
|
66
|
+
let reader;
|
|
67
|
+
super({
|
|
68
|
+
async pull(controller) {
|
|
69
|
+
reader ??= stream.getReader();
|
|
70
|
+
try {
|
|
71
|
+
const { value, done } = await reader.read();
|
|
72
|
+
if (done) {
|
|
73
|
+
controller.close();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
controller.enqueue(`data: ${JSON.stringify(value)}\n\n`);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
controller.enqueue(`event: error\ndata: ${JSON.stringify({ message: error.message })}\n\n`);
|
|
80
|
+
controller.close();
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -3,12 +3,15 @@ import { UriTemplate } from "@modelcontextprotocol/sdk/shared/uriTemplate.js";
|
|
|
3
3
|
import { CallToolResultSchema, GetPromptResultSchema, ReadResourceResultSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { MCPPrompt, MCPResource, MCPTool } from "../agents/mcp-agent.js";
|
|
6
|
+
import { isEmpty } from "./type-utils.js";
|
|
6
7
|
export function toolFromMCPTool(tool, options) {
|
|
7
8
|
return new MCPTool({
|
|
8
9
|
...options,
|
|
9
10
|
name: tool.name,
|
|
10
11
|
description: tool.description,
|
|
11
|
-
inputSchema:
|
|
12
|
+
inputSchema: isEmpty(tool.inputSchema.properties)
|
|
13
|
+
? z.object({})
|
|
14
|
+
: jsonSchemaToZod(tool.inputSchema),
|
|
12
15
|
outputSchema: CallToolResultSchema,
|
|
13
16
|
});
|
|
14
17
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AgentProcessAsyncGenerator, type AgentResponseChunk, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
2
|
+
import type { MESSAGE_KEY } from "../prompt/prompt-builder.js";
|
|
2
3
|
import { type PromiseOrValue } from "./type-utils.js";
|
|
3
4
|
export declare function objectToAgentResponseStream<T extends Message>(json: T): AgentResponseStream<T>;
|
|
4
5
|
export declare function mergeAgentResponseChunk<T extends Message>(output: T, chunk: AgentResponseChunk<T>): T;
|
|
@@ -10,6 +11,12 @@ export declare function onAgentResponseStreamEnd<T extends Message>(stream: Agen
|
|
|
10
11
|
}): ReadableStream<any>;
|
|
11
12
|
export declare function isAsyncGenerator<T extends AsyncGenerator>(value: AsyncGenerator | unknown): value is T;
|
|
12
13
|
export declare function arrayToAgentProcessAsyncGenerator<T extends Message>(chunks: (AgentResponseChunk<T> | Error)[], result?: Partial<T>): AgentProcessAsyncGenerator<T>;
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function readableStreamToArray<T>(stream: ReadableStream<T
|
|
14
|
+
export declare function arrayToReadableStream<T>(chunks: (T | Error)[]): ReadableStream<T>;
|
|
15
|
+
export declare function readableStreamToArray<T>(stream: ReadableStream<T>, options: {
|
|
16
|
+
catchError: true;
|
|
17
|
+
}): Promise<(T | Error)[]>;
|
|
18
|
+
export declare function readableStreamToArray<T>(stream: ReadableStream<T>, options?: {
|
|
19
|
+
catchError?: false;
|
|
20
|
+
}): Promise<T[]>;
|
|
15
21
|
export declare function readableStreamToAsyncIterator<T>(stream: ReadableStream<T>): AsyncIterable<T>;
|
|
22
|
+
export declare function stringToAgentResponseStream(str: string, key?: "text" | typeof MESSAGE_KEY | string): AgentResponseStream<Message>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import equal from "fast-deep-equal";
|
|
2
|
+
import { isEmptyChunk, } from "../agents/agent.js";
|
|
2
3
|
import { omitBy } from "./type-utils.js";
|
|
3
4
|
export function objectToAgentResponseStream(json) {
|
|
4
5
|
return new ReadableStream({
|
|
5
|
-
|
|
6
|
+
pull(controller) {
|
|
6
7
|
controller.enqueue({ delta: { json } });
|
|
7
8
|
controller.close();
|
|
8
9
|
},
|
|
@@ -48,40 +49,40 @@ export async function agentResponseStreamToObject(stream) {
|
|
|
48
49
|
}
|
|
49
50
|
export function asyncGeneratorToReadableStream(generator) {
|
|
50
51
|
return new ReadableStream({
|
|
51
|
-
async
|
|
52
|
+
async pull(controller) {
|
|
52
53
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (chunk.
|
|
56
|
-
|
|
57
|
-
controller.enqueue({ delta: { json: chunk.value } });
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
controller.enqueue(chunk.value);
|
|
61
|
-
}
|
|
54
|
+
const chunk = await generator.next();
|
|
55
|
+
if (chunk.value) {
|
|
56
|
+
if (chunk.done) {
|
|
57
|
+
controller.enqueue({ delta: { json: chunk.value } });
|
|
62
58
|
}
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
else {
|
|
60
|
+
controller.enqueue(chunk.value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (chunk.done) {
|
|
64
|
+
controller.close();
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
catch (error) {
|
|
68
68
|
controller.error(error);
|
|
69
69
|
}
|
|
70
|
-
finally {
|
|
71
|
-
controller.close();
|
|
72
|
-
}
|
|
73
70
|
},
|
|
74
71
|
});
|
|
75
72
|
}
|
|
76
73
|
export function onAgentResponseStreamEnd(stream, callback, options) {
|
|
74
|
+
const json = {};
|
|
75
|
+
const reader = stream.getReader();
|
|
77
76
|
return new ReadableStream({
|
|
78
|
-
async
|
|
77
|
+
async pull(controller) {
|
|
79
78
|
try {
|
|
80
|
-
const
|
|
81
|
-
|
|
79
|
+
const { value, done } = await reader.read();
|
|
80
|
+
if (!done) {
|
|
82
81
|
const chunk = options?.processChunk ? options.processChunk(value) : value;
|
|
83
|
-
|
|
82
|
+
if (!isEmptyChunk(chunk))
|
|
83
|
+
controller.enqueue(chunk);
|
|
84
84
|
mergeAgentResponseChunk(json, value);
|
|
85
|
+
return;
|
|
85
86
|
}
|
|
86
87
|
const result = await callback(json);
|
|
87
88
|
if (result && !equal(result, json)) {
|
|
@@ -90,13 +91,11 @@ export function onAgentResponseStreamEnd(stream, callback, options) {
|
|
|
90
91
|
chunk = options.processChunk(chunk);
|
|
91
92
|
controller.enqueue(chunk);
|
|
92
93
|
}
|
|
94
|
+
controller.close();
|
|
93
95
|
}
|
|
94
96
|
catch (error) {
|
|
95
97
|
controller.error(options?.errorCallback?.(error) ?? error);
|
|
96
98
|
}
|
|
97
|
-
finally {
|
|
98
|
-
controller.close();
|
|
99
|
-
}
|
|
100
99
|
},
|
|
101
100
|
});
|
|
102
101
|
}
|
|
@@ -112,24 +111,34 @@ export async function* arrayToAgentProcessAsyncGenerator(chunks, result) {
|
|
|
112
111
|
if (result !== undefined)
|
|
113
112
|
return result;
|
|
114
113
|
}
|
|
115
|
-
export function
|
|
114
|
+
export function arrayToReadableStream(chunks) {
|
|
115
|
+
const list = [...chunks];
|
|
116
116
|
return new ReadableStream({
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
controller.enqueue(chunk);
|
|
117
|
+
pull(controller) {
|
|
118
|
+
const item = list.shift();
|
|
119
|
+
if (!item) {
|
|
120
|
+
controller.close();
|
|
121
|
+
return;
|
|
124
122
|
}
|
|
125
|
-
|
|
123
|
+
if (item instanceof Error) {
|
|
124
|
+
controller.error(item);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
controller.enqueue(item);
|
|
126
128
|
},
|
|
127
129
|
});
|
|
128
130
|
}
|
|
129
|
-
export async function readableStreamToArray(stream) {
|
|
131
|
+
export async function readableStreamToArray(stream, options) {
|
|
130
132
|
const result = [];
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
try {
|
|
134
|
+
for await (const value of readableStreamToAsyncIterator(stream)) {
|
|
135
|
+
result.push(value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (!options?.catchError)
|
|
140
|
+
throw error;
|
|
141
|
+
result.push(error);
|
|
133
142
|
}
|
|
134
143
|
return result;
|
|
135
144
|
}
|
|
@@ -142,3 +151,8 @@ export async function* readableStreamToAsyncIterator(stream) {
|
|
|
142
151
|
yield value;
|
|
143
152
|
}
|
|
144
153
|
}
|
|
154
|
+
export function stringToAgentResponseStream(str, key = "text") {
|
|
155
|
+
const segmenter = new Intl.Segmenter(undefined, { granularity: "word" });
|
|
156
|
+
const segments = segmenter.segment(str);
|
|
157
|
+
return arrayToReadableStream(Array.from(segments).map((segment) => ({ delta: { text: { [key]: segment.segment } } })));
|
|
158
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type ZodType } from "zod";
|
|
2
2
|
export type PromiseOrValue<T> = T | Promise<T>;
|
|
3
|
-
export type Nullish<T> = T | null | undefined;
|
|
3
|
+
export type Nullish<T> = T | null | undefined | void;
|
|
4
4
|
export type OmitPropertiesFromArrayFirstElement<T extends unknown[], K extends string | number | symbol> = T extends [infer U, ...infer Rest] ? [Omit<U, K>, ...Rest] : never;
|
|
5
5
|
export declare function isNil(value: unknown): value is null | undefined;
|
|
6
|
+
export declare function isRecord<T>(value: unknown): value is Record<string, T>;
|
|
6
7
|
export declare function isEmpty(obj: unknown): boolean;
|
|
7
8
|
export declare function isNonNullable<T>(value: T): value is NonNullable<T>;
|
|
8
9
|
export declare function isNotEmpty<T>(arr: T[]): arr is [T, ...T[]];
|
|
@@ -12,5 +13,6 @@ export declare function orArrayToArray<T>(value?: T | T[]): T[];
|
|
|
12
13
|
export declare function createAccessorArray<T>(array: T[], accessor: (array: T[], name: string) => T | undefined): T[] & {
|
|
13
14
|
[key: string]: T;
|
|
14
15
|
};
|
|
15
|
-
export declare function checkArguments<T>(prefix: string, schema: ZodType<T>, args: T): T;
|
|
16
|
+
export declare function checkArguments<T>(prefix: string, schema: ZodType<T>, args: T | unknown): T;
|
|
16
17
|
export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error: string | Error | ((error: Error) => Error)): P;
|
|
18
|
+
export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error?: Nullish<string | Error | ((error: Error) => Nullish<Error>)>): P | undefined;
|
|
@@ -2,6 +2,9 @@ import { z } from "zod";
|
|
|
2
2
|
export function isNil(value) {
|
|
3
3
|
return value === null || value === undefined;
|
|
4
4
|
}
|
|
5
|
+
export function isRecord(value) {
|
|
6
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
}
|
|
5
8
|
export function isEmpty(obj) {
|
|
6
9
|
if (isNil(obj))
|
|
7
10
|
return true;
|
|
@@ -101,12 +104,16 @@ export function tryOrThrow(fn, error) {
|
|
|
101
104
|
const result = fn();
|
|
102
105
|
if (result instanceof Promise) {
|
|
103
106
|
return result.catch((e) => {
|
|
104
|
-
|
|
107
|
+
const error = createError(e);
|
|
108
|
+
if (error)
|
|
109
|
+
throw error;
|
|
105
110
|
});
|
|
106
111
|
}
|
|
107
112
|
return result;
|
|
108
113
|
}
|
|
109
114
|
catch (e) {
|
|
110
|
-
|
|
115
|
+
const error = createError(e);
|
|
116
|
+
if (error)
|
|
117
|
+
throw error;
|
|
111
118
|
}
|
|
112
119
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "AIGNE core library for building AI-powered applications",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
|
|
9
9
|
"homepage": "https://github.com/AIGNE-io/aigne-framework",
|
|
10
|
-
"license": "
|
|
10
|
+
"license": "Elastic-2.0",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git+https://github.com/AIGNE-io/aigne-framework"
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"agents/*": [
|
|
45
45
|
"./lib/dts/agents/*"
|
|
46
46
|
],
|
|
47
|
-
"
|
|
48
|
-
"./lib/dts/
|
|
47
|
+
"aigne/*": [
|
|
48
|
+
"./lib/dts/aigne/*"
|
|
49
49
|
],
|
|
50
50
|
"loader/*": [
|
|
51
51
|
"./lib/dts/loader/*"
|
|
@@ -63,14 +63,20 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@aigne/json-schema-to-zod": "^1.3.3",
|
|
66
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
66
|
+
"@modelcontextprotocol/sdk": "^1.10.2",
|
|
67
67
|
"@types/debug": "^4.1.12",
|
|
68
|
+
"camelize-ts": "^3.0.0",
|
|
69
|
+
"content-type": "^1.0.5",
|
|
68
70
|
"debug": "^4.4.0",
|
|
71
|
+
"eventsource-parser": "^3.0.1",
|
|
69
72
|
"fast-deep-equal": "^3.1.3",
|
|
73
|
+
"immer": "^10.1.1",
|
|
70
74
|
"inquirer": "^12.5.2",
|
|
71
75
|
"mustache": "^4.2.0",
|
|
72
76
|
"nanoid": "^5.1.5",
|
|
73
77
|
"p-retry": "^6.2.1",
|
|
78
|
+
"raw-body": "^3.0.0",
|
|
79
|
+
"ufo": "^1.6.1",
|
|
74
80
|
"uuid": "^11.1.0",
|
|
75
81
|
"yaml": "^2.7.1",
|
|
76
82
|
"zod": "^3.24.2",
|
|
@@ -85,11 +91,15 @@
|
|
|
85
91
|
"@anthropic-ai/sdk": "^0.39.0",
|
|
86
92
|
"@google/generative-ai": "^0.24.0",
|
|
87
93
|
"@types/bun": "^1.2.9",
|
|
94
|
+
"@types/compression": "^1.7.5",
|
|
95
|
+
"@types/content-type": "^1.1.8",
|
|
88
96
|
"@types/express": "^5.0.1",
|
|
89
97
|
"@types/mustache": "^4.2.5",
|
|
90
98
|
"@types/node": "^22.14.1",
|
|
99
|
+
"compression": "^1.8.0",
|
|
91
100
|
"detect-port": "^2.1.0",
|
|
92
101
|
"express": "^5.1.0",
|
|
102
|
+
"hono": "^4.7.7",
|
|
93
103
|
"npm-run-all": "^4.1.5",
|
|
94
104
|
"openai": "^4.94.0",
|
|
95
105
|
"rimraf": "^6.0.1",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type FunctionAgentFn } from "../agents/agent.js";
|
|
2
|
-
import type { Runnable } from "./context.js";
|
|
3
|
-
export declare function sequential(...agents: [Runnable, ...Runnable[]]): FunctionAgentFn;
|
|
4
|
-
export declare function parallel(...agents: [Runnable, ...Runnable[]]): FunctionAgentFn;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sequential = sequential;
|
|
4
|
-
exports.parallel = parallel;
|
|
5
|
-
const zod_1 = require("zod");
|
|
6
|
-
const agent_js_1 = require("../agents/agent.js");
|
|
7
|
-
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
8
|
-
function sequential(...agents) {
|
|
9
|
-
(0, type_utils_js_1.checkArguments)("sequential", agentArraySchema, agents);
|
|
10
|
-
let _agents = [...agents];
|
|
11
|
-
return async (input, context) => {
|
|
12
|
-
const output = {};
|
|
13
|
-
// Clone the agents to run, so that we can update the agents list during the loop
|
|
14
|
-
const agentsToRun = [..._agents];
|
|
15
|
-
_agents = [];
|
|
16
|
-
for (const agent of agentsToRun) {
|
|
17
|
-
const [o, transferToAgent] = await context.call(agent, { ...input, ...output }, { returnActiveAgent: true });
|
|
18
|
-
Object.assign(output, o);
|
|
19
|
-
_agents.push(transferToAgent);
|
|
20
|
-
}
|
|
21
|
-
return output;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function parallel(...agents) {
|
|
25
|
-
(0, type_utils_js_1.checkArguments)("parallel", agentArraySchema, agents);
|
|
26
|
-
let _agents = [...agents];
|
|
27
|
-
return async (input, context) => {
|
|
28
|
-
const result = await Promise.all(_agents.map((agent) => context.call(agent, input, { returnActiveAgent: true })));
|
|
29
|
-
_agents = result.map((i) => i[1]);
|
|
30
|
-
const outputs = result.map((i) => i[0]);
|
|
31
|
-
return Object.assign({}, ...outputs);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
const agentArraySchema = zod_1.z.array(zod_1.z.union([zod_1.z.function(), zod_1.z.instanceof(agent_js_1.Agent)]));
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type FunctionAgentFn } from "../agents/agent.js";
|
|
2
|
-
import type { Runnable } from "./context.js";
|
|
3
|
-
export declare function sequential(...agents: [Runnable, ...Runnable[]]): FunctionAgentFn;
|
|
4
|
-
export declare function parallel(...agents: [Runnable, ...Runnable[]]): FunctionAgentFn;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type FunctionAgentFn } from "../agents/agent.js";
|
|
2
|
-
import type { Runnable } from "./context.js";
|
|
3
|
-
export declare function sequential(...agents: [Runnable, ...Runnable[]]): FunctionAgentFn;
|
|
4
|
-
export declare function parallel(...agents: [Runnable, ...Runnable[]]): FunctionAgentFn;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { Agent } from "../agents/agent.js";
|
|
3
|
-
import { checkArguments } from "../utils/type-utils.js";
|
|
4
|
-
export function sequential(...agents) {
|
|
5
|
-
checkArguments("sequential", agentArraySchema, agents);
|
|
6
|
-
let _agents = [...agents];
|
|
7
|
-
return async (input, context) => {
|
|
8
|
-
const output = {};
|
|
9
|
-
// Clone the agents to run, so that we can update the agents list during the loop
|
|
10
|
-
const agentsToRun = [..._agents];
|
|
11
|
-
_agents = [];
|
|
12
|
-
for (const agent of agentsToRun) {
|
|
13
|
-
const [o, transferToAgent] = await context.call(agent, { ...input, ...output }, { returnActiveAgent: true });
|
|
14
|
-
Object.assign(output, o);
|
|
15
|
-
_agents.push(transferToAgent);
|
|
16
|
-
}
|
|
17
|
-
return output;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export function parallel(...agents) {
|
|
21
|
-
checkArguments("parallel", agentArraySchema, agents);
|
|
22
|
-
let _agents = [...agents];
|
|
23
|
-
return async (input, context) => {
|
|
24
|
-
const result = await Promise.all(_agents.map((agent) => context.call(agent, input, { returnActiveAgent: true })));
|
|
25
|
-
_agents = result.map((i) => i[1]);
|
|
26
|
-
const outputs = result.map((i) => i[0]);
|
|
27
|
-
return Object.assign({}, ...outputs);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const agentArraySchema = z.array(z.union([z.function(), z.instanceof(Agent)]));
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|