@easynet/agent-runtime 1.0.2 → 1.0.4
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/.github/workflows/ci.yml +9 -24
- package/.github/workflows/release.yml +38 -26
- package/agent-runtime/.github/workflows/ci.yml +69 -0
- package/agent-runtime/.github/workflows/release.yml +118 -0
- package/agent-runtime/.releaserc.cjs +26 -0
- package/agent-runtime/config/agent.deep.yaml +25 -0
- package/agent-runtime/config/agent.react.yaml +24 -0
- package/agent-runtime/example/basic-usage.ts +49 -0
- package/agent-runtime/package-lock.json +7740 -0
- package/agent-runtime/package.json +49 -0
- package/agent-runtime/pnpm-lock.yaml +3712 -0
- package/agent-runtime/scripts/resolve-deps.js +54 -0
- package/agent-runtime/src/agents/deep-agent.ts +165 -0
- package/agent-runtime/src/agents/react-agent.helpers.ts +227 -0
- package/agent-runtime/src/agents/react-agent.ts +584 -0
- package/{src → agent-runtime/src/agents}/sub-agent.ts +2 -2
- package/agent-runtime/src/cli/args.ts +15 -0
- package/agent-runtime/src/cli/event-listener.ts +162 -0
- package/agent-runtime/src/cli/interactive.ts +144 -0
- package/agent-runtime/src/cli/runtime.ts +31 -0
- package/agent-runtime/src/cli/spinner.ts +23 -0
- package/agent-runtime/src/cli/terminal-render.ts +322 -0
- package/agent-runtime/src/cli/types.ts +33 -0
- package/agent-runtime/src/cli.ts +134 -0
- package/agent-runtime/src/config/helpers.ts +179 -0
- package/agent-runtime/src/config/index.ts +245 -0
- package/agent-runtime/src/config/types.ts +62 -0
- package/agent-runtime/src/core/context.ts +266 -0
- package/agent-runtime/src/index.ts +55 -0
- package/agent-runtime/tsconfig.json +18 -0
- package/apps/imessagebot/README.md +38 -0
- package/apps/imessagebot/config/.agent/cache/easynet/agent-tool-buildin/0.0.45/README.md +33 -0
- package/apps/imessagebot/config/.agent/cache/easynet/agent-tool-buildin/0.0.45/package-lock.json +15257 -0
- package/apps/imessagebot/config/.agent/cache/easynet/agent-tool-buildin/0.0.45/package.json +55 -0
- package/apps/imessagebot/config/agents/deep/agent.yaml +31 -0
- package/apps/imessagebot/config/agents/react/agent.yaml +58 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.43/README.md +33 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.43/package-lock.json +15457 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.43/package.json +55 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.46/README.md +33 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.46/package-lock.json +15257 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.46/package.json +62 -0
- package/apps/imessagebot/config/agents/shared/memory.yaml +31 -0
- package/apps/imessagebot/config/agents/shared/model.yaml +23 -0
- package/apps/imessagebot/config/agents/shared/tool.yaml +13 -0
- package/apps/imessagebot/config/app.yaml +14 -0
- package/apps/imessagebot/package-lock.json +53695 -0
- package/apps/imessagebot/package.json +41 -0
- package/apps/imessagebot/pnpm-lock.yaml +1589 -0
- package/apps/imessagebot/scripts/resolve-deps.js +41 -0
- package/apps/imessagebot/scripts/test-llm.mjs +27 -0
- package/apps/imessagebot/scripts/validate-tools-config.mjs +174 -0
- package/apps/imessagebot/src/config.ts +76 -0
- package/apps/imessagebot/src/context.ts +35 -0
- package/apps/imessagebot/src/index.ts +17 -0
- package/apps/imessagebot/tsconfig.json +18 -0
- package/apps/itermbot/.github/workflows/ci.yml +61 -0
- package/apps/itermbot/.github/workflows/release.yml +80 -0
- package/apps/itermbot/.releaserc.cjs +26 -0
- package/apps/itermbot/README.md +82 -0
- package/apps/itermbot/config/app.yaml +29 -0
- package/apps/itermbot/config/tsconfig.json +18 -0
- package/apps/itermbot/macos_disk_usage_agent_plan.md +244 -0
- package/apps/itermbot/package-lock.json +53697 -0
- package/apps/itermbot/package.json +57 -0
- package/apps/itermbot/pnpm-lock.yaml +3966 -0
- package/apps/itermbot/scripts/patch-buildin-cache.sh +25 -0
- package/apps/itermbot/scripts/resolve-deps.js +41 -0
- package/apps/itermbot/scripts/test-llm.mjs +32 -0
- package/apps/itermbot/skills/command-explain-and-guard/SKILL.md +39 -0
- package/apps/itermbot/skills/command-explain-and-guard/handler.js +86 -0
- package/apps/itermbot/skills/disk-usage-investigate/SKILL.md +44 -0
- package/apps/itermbot/skills/disk-usage-investigate/handler.js +12 -0
- package/apps/itermbot/skills/gpu-ssh-monitor/SKILL.md +64 -0
- package/apps/itermbot/skills/repo-triage/SKILL.md +40 -0
- package/apps/itermbot/skills/repo-triage/handler.js +56 -0
- package/apps/itermbot/skills/test-failure-diagnose/SKILL.md +43 -0
- package/apps/itermbot/skills/test-failure-diagnose/handler.js +107 -0
- package/apps/itermbot/src/config.ts +95 -0
- package/apps/itermbot/src/context.ts +35 -0
- package/apps/itermbot/src/index.ts +223 -0
- package/apps/itermbot/src/iterm/session-hint.ts +40 -0
- package/apps/itermbot/src/iterm/target-routing.ts +419 -0
- package/apps/itermbot/src/startup/colors.ts +317 -0
- package/apps/itermbot/src/startup/diagnostics.ts +97 -0
- package/apps/itermbot/src/startup/ui.ts +141 -0
- package/config/agent.deep.yaml +25 -0
- package/config/agent.react.yaml +24 -0
- package/dist/agents/deep-agent.d.ts +37 -0
- package/dist/agents/deep-agent.d.ts.map +1 -0
- package/dist/agents/deep-agent.js +115 -0
- package/dist/agents/deep-agent.js.map +1 -0
- package/dist/agents/react-agent.d.ts +40 -0
- package/dist/agents/react-agent.d.ts.map +1 -0
- package/dist/agents/react-agent.helpers.d.ts +40 -0
- package/dist/agents/react-agent.helpers.d.ts.map +1 -0
- package/dist/agents/react-agent.helpers.js +196 -0
- package/dist/agents/react-agent.helpers.js.map +1 -0
- package/dist/agents/react-agent.js +400 -0
- package/dist/agents/react-agent.js.map +1 -0
- package/dist/agents/sub-agent.d.ts +34 -0
- package/dist/agents/sub-agent.d.ts.map +1 -0
- package/dist/agents/sub-agent.js +53 -0
- package/dist/agents/sub-agent.js.map +1 -0
- package/dist/cli/args.d.ts +8 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +9 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/event-listener.d.ts +3 -0
- package/dist/cli/event-listener.d.ts.map +1 -0
- package/dist/cli/event-listener.js +131 -0
- package/dist/cli/event-listener.js.map +1 -0
- package/dist/cli/interactive.d.ts +4 -0
- package/dist/cli/interactive.d.ts.map +1 -0
- package/dist/cli/interactive.js +118 -0
- package/dist/cli/interactive.js.map +1 -0
- package/dist/cli/runtime.d.ts +8 -0
- package/dist/cli/runtime.d.ts.map +1 -0
- package/dist/cli/runtime.js +27 -0
- package/dist/cli/runtime.js.map +1 -0
- package/dist/cli/spinner.d.ts +2 -0
- package/dist/cli/spinner.d.ts.map +1 -0
- package/dist/cli/spinner.js +22 -0
- package/dist/cli/spinner.js.map +1 -0
- package/dist/cli/terminal-render.d.ts +7 -0
- package/dist/cli/terminal-render.d.ts.map +1 -0
- package/dist/cli/terminal-render.js +282 -0
- package/dist/cli/terminal-render.js.map +1 -0
- package/dist/cli/types.d.ts +29 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +3 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli.d.ts +4 -41
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +84 -588
- package/dist/cli.js.map +1 -1
- package/dist/config/helpers.d.ts +6 -0
- package/dist/config/helpers.d.ts.map +1 -0
- package/dist/config/helpers.js +164 -0
- package/dist/config/helpers.js.map +1 -0
- package/dist/config/index.d.ts +15 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +160 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +57 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/context.d.ts +8 -69
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +44 -24
- package/dist/context.js.map +1 -1
- package/dist/core/context.d.ts +66 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +149 -0
- package/dist/core/context.js.map +1 -0
- package/dist/deep-agent.d.ts +5 -2
- package/dist/deep-agent.d.ts.map +1 -1
- package/dist/deep-agent.js +44 -11
- package/dist/deep-agent.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/middleware/malformed-tool-call-middleware.d.ts +8 -0
- package/dist/middleware/malformed-tool-call-middleware.d.ts.map +1 -0
- package/dist/middleware/malformed-tool-call-middleware.js +191 -0
- package/dist/middleware/malformed-tool-call-middleware.js.map +1 -0
- package/dist/react-agent.d.ts +2 -2
- package/dist/react-agent.d.ts.map +1 -1
- package/dist/react-agent.js +28 -9
- package/dist/react-agent.js.map +1 -1
- package/package.json +1 -1
- package/scripts/resolve-deps.js +54 -0
- package/src/agents/deep-agent.ts +165 -0
- package/src/agents/react-agent.helpers.ts +227 -0
- package/src/agents/react-agent.ts +584 -0
- package/src/agents/sub-agent.ts +82 -0
- package/src/cli/args.ts +15 -0
- package/src/cli/event-listener.ts +162 -0
- package/src/cli/interactive.ts +144 -0
- package/src/cli/runtime.ts +31 -0
- package/src/cli/spinner.ts +23 -0
- package/src/cli/terminal-render.ts +322 -0
- package/src/cli/types.ts +33 -0
- package/src/cli.ts +91 -702
- package/src/config/helpers.ts +179 -0
- package/src/config/index.ts +245 -0
- package/src/config/types.ts +62 -0
- package/src/core/context.ts +266 -0
- package/src/index.ts +13 -11
- package/src/middleware/malformed-tool-call-middleware.ts +239 -0
- package/src/types/markdown-it-terminal.d.ts +4 -0
- package/src/types/marked-terminal.d.ts +16 -0
- package/dist/config.d.ts +0 -86
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -84
- package/dist/config.js.map +0 -1
- package/src/config.ts +0 -177
- package/src/context.ts +0 -247
- package/src/deep-agent.ts +0 -104
- package/src/react-agent.ts +0 -576
- /package/{src → agent-runtime/src/middleware}/malformed-tool-call-middleware.ts +0 -0
- /package/{src → agent-runtime/src/types}/markdown-it-terminal.d.ts +0 -0
- /package/{src → agent-runtime/src/types}/marked-terminal.d.ts +0 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import type { BaseMessageLike } from "@langchain/core/messages";
|
|
2
|
+
import type { LanguageModelLike } from "@langchain/core/language_models/base";
|
|
3
|
+
import { asObject } from "@easynet/agent-common";
|
|
4
|
+
import type { BaseAgentConfig } from "../core/context.js";
|
|
5
|
+
|
|
6
|
+
export interface MessageLike {
|
|
7
|
+
type?: string;
|
|
8
|
+
role?: string;
|
|
9
|
+
content?: string | unknown;
|
|
10
|
+
tool_calls?: Array<{ name?: string; args?: unknown; id?: string }>;
|
|
11
|
+
name?: string;
|
|
12
|
+
tool_call_id?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ToolRunStats {
|
|
16
|
+
invoked: number;
|
|
17
|
+
succeeded: number;
|
|
18
|
+
failed: number;
|
|
19
|
+
lastError?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function toMessageText(content: unknown): string {
|
|
23
|
+
if (typeof content === "string") return content;
|
|
24
|
+
if (!Array.isArray(content)) return "";
|
|
25
|
+
return content
|
|
26
|
+
.map((block) => {
|
|
27
|
+
if (typeof block === "string") return block;
|
|
28
|
+
if (typeof block === "object" && block !== null && "text" in block) {
|
|
29
|
+
const text = (block as { text?: unknown }).text;
|
|
30
|
+
return typeof text === "string" ? text : "";
|
|
31
|
+
}
|
|
32
|
+
return "";
|
|
33
|
+
})
|
|
34
|
+
.join("");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function inferMemoryTypeByStructure(content: string): "thread" | "cross_thread" {
|
|
38
|
+
const text = content.trim();
|
|
39
|
+
if (!text) return "thread";
|
|
40
|
+
|
|
41
|
+
const lines = text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
42
|
+
const duplicateRatio = lines.length > 0 ? 1 - new Set(lines).size / lines.length : 0;
|
|
43
|
+
const symbolCount = (text.match(/[^\p{L}\p{N}\s]/gu) ?? []).length;
|
|
44
|
+
const symbolRatio = symbolCount / Math.max(1, text.length);
|
|
45
|
+
|
|
46
|
+
if (text.length > 1200) return "thread";
|
|
47
|
+
if (lines.length > 18) return "thread";
|
|
48
|
+
if (duplicateRatio > 0.35) return "thread";
|
|
49
|
+
if (symbolRatio > 0.22) return "thread";
|
|
50
|
+
return "cross_thread";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function inferMemoryTypeWithModel(
|
|
54
|
+
llm: LanguageModelLike,
|
|
55
|
+
content: string,
|
|
56
|
+
): Promise<"thread" | "cross_thread" | null> {
|
|
57
|
+
const classifierPrompt = [
|
|
58
|
+
"Classify memory scope for an AI agent.",
|
|
59
|
+
"Return strict JSON only: {\"type\":\"thread|cross_thread\",\"confidence\":0..1}.",
|
|
60
|
+
"Decision policy:",
|
|
61
|
+
"- thread: temporary session context, command output, logs, transient task state, step-by-step investigation details.",
|
|
62
|
+
"- cross_thread: stable user preferences, durable profile facts, long-lived constraints reusable in future sessions.",
|
|
63
|
+
"Use semantic judgment, not keyword matching.",
|
|
64
|
+
].join("\n");
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const response = await llm.invoke([
|
|
68
|
+
{ role: "system", content: classifierPrompt },
|
|
69
|
+
{ role: "user", content },
|
|
70
|
+
]);
|
|
71
|
+
const text = toMessageText((response as { content?: unknown }).content).trim();
|
|
72
|
+
const jsonBlob = text.match(/\{[\s\S]*\}/)?.[0] ?? text;
|
|
73
|
+
const parsed = JSON.parse(jsonBlob) as { type?: unknown; confidence?: unknown };
|
|
74
|
+
const type = parsed.type === "thread" || parsed.type === "cross_thread" ? parsed.type : null;
|
|
75
|
+
const confidence = typeof parsed.confidence === "number" ? parsed.confidence : 0;
|
|
76
|
+
return type && confidence >= 0.6 ? type : null;
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function deriveFallbackTextFromMessages(
|
|
83
|
+
messages: BaseMessageLike[],
|
|
84
|
+
opts: { fallbackText: string; commandWindowLabel?: string },
|
|
85
|
+
): string {
|
|
86
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
87
|
+
const msg = messages[i] as MessageLike;
|
|
88
|
+
const type = msg?.type ?? msg?.role ?? "";
|
|
89
|
+
if (type !== "tool" && !msg?.tool_call_id) continue;
|
|
90
|
+
|
|
91
|
+
const raw = typeof msg.content === "string"
|
|
92
|
+
? msg.content
|
|
93
|
+
: msg.content != null
|
|
94
|
+
? String(msg.content)
|
|
95
|
+
: "";
|
|
96
|
+
if (!raw.trim()) continue;
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const parsed = JSON.parse(raw) as {
|
|
100
|
+
result?: { command?: string; windowId?: number; tabIndex?: number; to?: string; serviceType?: string };
|
|
101
|
+
evidence?: Array<{ summary?: string }>;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const summary = parsed.evidence?.find((item) => item?.summary)?.summary;
|
|
105
|
+
if (typeof summary === "string" && summary.trim()) return summary.trim();
|
|
106
|
+
|
|
107
|
+
const to = parsed.result?.to?.trim();
|
|
108
|
+
const serviceType = parsed.result?.serviceType?.trim();
|
|
109
|
+
if (to) return serviceType ? `Sent ${serviceType} message to ${to}.` : `Sent message to ${to}.`;
|
|
110
|
+
|
|
111
|
+
const command = parsed.result?.command?.trim();
|
|
112
|
+
if (!command) continue;
|
|
113
|
+
const windowId = parsed.result?.windowId;
|
|
114
|
+
const tabIndex = parsed.result?.tabIndex;
|
|
115
|
+
if (typeof windowId === "number" && typeof tabIndex === "number") {
|
|
116
|
+
return `Executed command in ${opts.commandWindowLabel ?? "window"} ${windowId}, tab ${tabIndex}: ${command}`;
|
|
117
|
+
}
|
|
118
|
+
return `Executed command: ${command}`;
|
|
119
|
+
} catch {
|
|
120
|
+
return raw.length > 200 ? `${raw.slice(0, 200)}...` : raw;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return opts.fallbackText;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function hasToolMessages(messages: unknown): boolean {
|
|
127
|
+
const list = Array.isArray(messages) ? messages : [];
|
|
128
|
+
for (const item of list) {
|
|
129
|
+
const msg = item as MessageLike;
|
|
130
|
+
const type = msg?.type ?? msg?.role ?? "";
|
|
131
|
+
if (type === "tool" || Boolean(msg?.tool_call_id) || (msg?.tool_calls?.length ?? 0) > 0) return true;
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function extractSchemaKeys(schema: unknown): string[] {
|
|
137
|
+
if (!schema || typeof schema !== "object") return [];
|
|
138
|
+
const rec = schema as Record<string, unknown>;
|
|
139
|
+
const properties = rec.properties;
|
|
140
|
+
if (properties && typeof properties === "object" && !Array.isArray(properties)) {
|
|
141
|
+
return Object.keys(properties as Record<string, unknown>);
|
|
142
|
+
}
|
|
143
|
+
const shape = rec.shape;
|
|
144
|
+
if (shape && typeof shape === "object" && !Array.isArray(shape)) {
|
|
145
|
+
return Object.keys(shape as Record<string, unknown>);
|
|
146
|
+
}
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function buildPtcHint(input: { taskIntent: string; stats: ToolRunStats; toolSignatures: string[] }): string {
|
|
151
|
+
return [
|
|
152
|
+
"[PTC_FEEDBACK]",
|
|
153
|
+
`TaskIntent: ${input.taskIntent}`,
|
|
154
|
+
`ToolStats: invoked=${input.stats.invoked}, succeeded=${input.stats.succeeded}, failed=${input.stats.failed}`,
|
|
155
|
+
input.stats.lastError ? `LastToolError: ${input.stats.lastError}` : "",
|
|
156
|
+
"Action: Retry using available tools. Do not claim tools are unavailable.",
|
|
157
|
+
"Action: If previous tool args were invalid, correct arguments strictly by schema.",
|
|
158
|
+
"Action: If a tool is needed, emit a valid tool call instead of plain explanation.",
|
|
159
|
+
`AvailableTools: ${input.toolSignatures.join("; ")}`,
|
|
160
|
+
].filter((line) => line.length > 0).join("\n");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function readAppString(appConfig: unknown, key: string): string | undefined {
|
|
164
|
+
const app = asObject(appConfig);
|
|
165
|
+
const value = app?.[key];
|
|
166
|
+
return typeof value === "string" ? value : undefined;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function readAppBoolean(appConfig: unknown, key: string): boolean | undefined {
|
|
170
|
+
const app = asObject(appConfig);
|
|
171
|
+
const value = app?.[key];
|
|
172
|
+
return typeof value === "boolean" ? value : undefined;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function pickFirstAgentName(config: BaseAgentConfig | undefined): string | undefined {
|
|
176
|
+
return Object.keys(config?.app?.agent ?? {})[0];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function pickAgentConfig(config: BaseAgentConfig | undefined, agentName?: string) {
|
|
180
|
+
if (!agentName) return undefined;
|
|
181
|
+
return config?.app?.agent?.[agentName];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function printReactSteps(messages: unknown): void {
|
|
185
|
+
const list = Array.isArray(messages) ? messages : [];
|
|
186
|
+
let stepIndex = 0;
|
|
187
|
+
|
|
188
|
+
for (let i = 0; i < list.length; i += 1) {
|
|
189
|
+
const msg = list[i] as MessageLike;
|
|
190
|
+
const type = msg?.type ?? msg?.role ?? "";
|
|
191
|
+
const content = msg?.content;
|
|
192
|
+
const contentStr = typeof content === "string"
|
|
193
|
+
? content
|
|
194
|
+
: typeof content === "object" && content !== null && Array.isArray(content)
|
|
195
|
+
? (content as { text?: string }[]).map((block) => block.text ?? JSON.stringify(block)).join("")
|
|
196
|
+
: content != null
|
|
197
|
+
? String(content)
|
|
198
|
+
: "";
|
|
199
|
+
|
|
200
|
+
if (type === "human" || (type === "user" && !msg.tool_calls)) {
|
|
201
|
+
if (contentStr.trim()) console.error(`\n--- Step (user) ---\n${contentStr.trim()}`);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (type === "ai" || type === "assistant") {
|
|
206
|
+
if (!msg.tool_calls?.length) continue;
|
|
207
|
+
stepIndex += 1;
|
|
208
|
+
if (contentStr.trim()) console.error(`\n--- ReAct Step ${stepIndex}: Thought ---\n${contentStr.trim()}`);
|
|
209
|
+
for (const toolCall of msg.tool_calls) {
|
|
210
|
+
const name = toolCall?.name ?? "?";
|
|
211
|
+
const args = typeof toolCall?.args === "object" && toolCall?.args !== null
|
|
212
|
+
? JSON.stringify(toolCall.args)
|
|
213
|
+
: String(toolCall?.args ?? "");
|
|
214
|
+
console.error(`--- ReAct Step ${stepIndex}: Action ---\n${name}(${args})`);
|
|
215
|
+
}
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (type === "tool" || msg?.tool_call_id) {
|
|
220
|
+
const toolName = msg?.name ?? "tool";
|
|
221
|
+
const observation = contentStr.length > 200 ? `${contentStr.slice(0, 200)}...` : contentStr;
|
|
222
|
+
console.error(`--- ReAct Step ${stepIndex}: Observation (${toolName}) ---\n${observation || "(empty)"}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
console.error("");
|
|
227
|
+
}
|