@aigne/core 1.6.0 → 1.8.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 +27 -0
- package/lib/cjs/agents/agent.d.ts +5 -2
- package/lib/cjs/agents/agent.js +42 -24
- package/lib/cjs/agents/ai-agent.d.ts +8 -8
- package/lib/cjs/agents/ai-agent.js +5 -2
- package/lib/cjs/agents/mcp-agent.d.ts +12 -2
- package/lib/cjs/agents/mcp-agent.js +45 -27
- package/lib/cjs/agents/user-agent.d.ts +9 -9
- package/lib/cjs/agents/user-agent.js +26 -16
- package/lib/cjs/execution-engine/context.d.ts +84 -46
- package/lib/cjs/execution-engine/context.js +136 -98
- package/lib/cjs/execution-engine/execution-engine.d.ts +16 -47
- package/lib/cjs/execution-engine/execution-engine.js +14 -41
- package/lib/cjs/execution-engine/message-queue.d.ts +3 -3
- package/lib/cjs/execution-engine/message-queue.js +32 -2
- package/lib/cjs/execution-engine/usage.d.ts +11 -0
- package/lib/cjs/execution-engine/usage.js +10 -0
- package/lib/cjs/loader/agent-js.js +1 -1
- package/lib/cjs/loader/agent-yaml.d.ts +1 -0
- package/lib/cjs/loader/agent-yaml.js +4 -0
- package/lib/cjs/loader/index.d.ts +72 -1
- package/lib/cjs/loader/index.js +13 -13
- package/lib/cjs/models/chat-model.d.ts +3 -2
- package/lib/cjs/models/chat-model.js +6 -5
- package/lib/cjs/models/claude-chat-model.js +11 -8
- package/lib/cjs/models/openai-chat-model.js +5 -2
- package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
- package/lib/cjs/prompt/prompt-builder.js +3 -1
- package/lib/cjs/utils/json-schema.js +2 -2
- package/lib/cjs/utils/logger.d.ts +3 -15
- package/lib/cjs/utils/logger.js +3 -77
- package/lib/cjs/utils/mcp-utils.js +1 -5
- package/lib/cjs/utils/model-utils.js +2 -2
- package/lib/cjs/utils/type-utils.d.ts +1 -0
- package/lib/cjs/utils/typed-event-emtter.d.ts +10 -0
- package/lib/cjs/utils/typed-event-emtter.js +2 -0
- package/lib/dts/agents/agent.d.ts +5 -2
- package/lib/dts/agents/ai-agent.d.ts +8 -8
- package/lib/dts/agents/mcp-agent.d.ts +12 -2
- package/lib/dts/agents/user-agent.d.ts +9 -9
- package/lib/dts/execution-engine/context.d.ts +84 -46
- package/lib/dts/execution-engine/execution-engine.d.ts +16 -47
- package/lib/dts/execution-engine/message-queue.d.ts +3 -3
- package/lib/dts/execution-engine/usage.d.ts +11 -0
- package/lib/dts/loader/agent-yaml.d.ts +1 -0
- package/lib/dts/loader/index.d.ts +72 -1
- package/lib/dts/models/chat-model.d.ts +3 -2
- package/lib/dts/prompt/prompt-builder.d.ts +1 -1
- package/lib/dts/utils/logger.d.ts +3 -15
- package/lib/dts/utils/type-utils.d.ts +1 -0
- package/lib/dts/utils/typed-event-emtter.d.ts +10 -0
- package/lib/esm/agents/agent.d.ts +5 -2
- package/lib/esm/agents/agent.js +42 -24
- package/lib/esm/agents/ai-agent.d.ts +8 -8
- package/lib/esm/agents/ai-agent.js +5 -2
- package/lib/esm/agents/mcp-agent.d.ts +12 -2
- package/lib/esm/agents/mcp-agent.js +46 -28
- package/lib/esm/agents/user-agent.d.ts +9 -9
- package/lib/esm/agents/user-agent.js +26 -16
- package/lib/esm/execution-engine/context.d.ts +84 -46
- package/lib/esm/execution-engine/context.js +135 -98
- package/lib/esm/execution-engine/execution-engine.d.ts +16 -47
- package/lib/esm/execution-engine/execution-engine.js +15 -39
- package/lib/esm/execution-engine/message-queue.d.ts +3 -3
- package/lib/esm/execution-engine/message-queue.js +33 -3
- package/lib/esm/execution-engine/usage.d.ts +11 -0
- package/lib/esm/execution-engine/usage.js +7 -0
- package/lib/esm/loader/agent-js.js +1 -1
- package/lib/esm/loader/agent-yaml.d.ts +1 -0
- package/lib/esm/loader/agent-yaml.js +4 -0
- package/lib/esm/loader/index.d.ts +72 -1
- package/lib/esm/loader/index.js +13 -14
- package/lib/esm/models/chat-model.d.ts +3 -2
- package/lib/esm/models/chat-model.js +6 -5
- package/lib/esm/models/claude-chat-model.js +11 -8
- package/lib/esm/models/openai-chat-model.js +5 -2
- package/lib/esm/prompt/prompt-builder.d.ts +1 -1
- package/lib/esm/prompt/prompt-builder.js +3 -1
- package/lib/esm/utils/json-schema.js +2 -2
- package/lib/esm/utils/logger.d.ts +3 -15
- package/lib/esm/utils/logger.js +3 -77
- package/lib/esm/utils/mcp-utils.js +1 -5
- package/lib/esm/utils/model-utils.js +2 -2
- package/lib/esm/utils/type-utils.d.ts +1 -0
- package/lib/esm/utils/typed-event-emtter.d.ts +10 -0
- package/lib/esm/utils/typed-event-emtter.js +1 -0
- package/package.json +11 -9
- package/lib/cjs/utils/run-chat-loop.d.ts +0 -11
- package/lib/cjs/utils/run-chat-loop.js +0 -82
- package/lib/dts/utils/run-chat-loop.d.ts +0 -11
- package/lib/esm/utils/run-chat-loop.d.ts +0 -11
- package/lib/esm/utils/run-chat-loop.js +0 -76
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import inquirer from "inquirer";
|
|
2
|
-
import ora from "ora";
|
|
3
|
-
import { logger } from "./logger.js";
|
|
4
|
-
export async function runChatLoopInTerminal(userAgent, { log = console.log.bind(console), ...options } = {}) {
|
|
5
|
-
logger.setSpinner(ora());
|
|
6
|
-
let isLoopExited = false;
|
|
7
|
-
let prompt;
|
|
8
|
-
if (options?.welcome)
|
|
9
|
-
log(options.welcome);
|
|
10
|
-
if (options?.initialCall) {
|
|
11
|
-
await callAgent(userAgent, options.initialCall, { ...options, log });
|
|
12
|
-
}
|
|
13
|
-
(async () => {
|
|
14
|
-
for await (const output of userAgent.stream) {
|
|
15
|
-
if (isLoopExited)
|
|
16
|
-
return;
|
|
17
|
-
if (options?.onResponse)
|
|
18
|
-
options.onResponse(output.message);
|
|
19
|
-
else
|
|
20
|
-
log(output);
|
|
21
|
-
prompt?.ui.close();
|
|
22
|
-
}
|
|
23
|
-
})();
|
|
24
|
-
for (let i = 0;; i++) {
|
|
25
|
-
prompt = inquirer.prompt([
|
|
26
|
-
{
|
|
27
|
-
type: "input",
|
|
28
|
-
name: "question",
|
|
29
|
-
message: "💬",
|
|
30
|
-
default: i === 0 ? options?.defaultQuestion : undefined,
|
|
31
|
-
},
|
|
32
|
-
]);
|
|
33
|
-
let question;
|
|
34
|
-
try {
|
|
35
|
-
question = (await prompt).question;
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
// ignore abort error from inquirer
|
|
39
|
-
}
|
|
40
|
-
if (!question?.trim())
|
|
41
|
-
continue;
|
|
42
|
-
const cmd = COMMANDS[question.trim()];
|
|
43
|
-
if (cmd) {
|
|
44
|
-
const result = cmd();
|
|
45
|
-
if (result.message)
|
|
46
|
-
log(result.message);
|
|
47
|
-
if (result?.exit)
|
|
48
|
-
break;
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
await callAgent(userAgent, question, { ...options, log });
|
|
52
|
-
}
|
|
53
|
-
isLoopExited = true;
|
|
54
|
-
}
|
|
55
|
-
async function callAgent(agent, input, options) {
|
|
56
|
-
try {
|
|
57
|
-
const response = await logger.spinner(agent.call(options.inputKey && typeof input === "string" ? { [options.inputKey]: input } : input), "🤖");
|
|
58
|
-
if (options?.onResponse)
|
|
59
|
-
options.onResponse(response);
|
|
60
|
-
else
|
|
61
|
-
options.log(response);
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
options.log(`ERROR: ${error.message}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const COMMANDS = {
|
|
68
|
-
"/exit": () => ({ exit: true }),
|
|
69
|
-
"/help": () => ({
|
|
70
|
-
message: `\
|
|
71
|
-
Commands:
|
|
72
|
-
/exit - exit the chat loop
|
|
73
|
-
/help - show this help message
|
|
74
|
-
`,
|
|
75
|
-
}),
|
|
76
|
-
};
|