orbitx 0.0.3 → 0.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/{src/core/ai-provider.ts → dist/core/ai-provider.d.ts} +19 -25
- package/dist/core/ai-provider.d.ts.map +1 -0
- package/dist/core/ai-provider.js +4 -0
- package/dist/core/ai-provider.js.map +1 -0
- package/dist/core/base-agent.d.ts +53 -0
- package/dist/core/base-agent.d.ts.map +1 -0
- package/{src/core/base-agent.ts → dist/core/base-agent.js} +197 -269
- package/dist/core/base-agent.js.map +1 -0
- package/dist/core/deepseek-provider.d.ts +9 -0
- package/dist/core/deepseek-provider.d.ts.map +1 -0
- package/{src/core/deepseek-provider.ts → dist/core/deepseek-provider.js} +60 -71
- package/dist/core/deepseek-provider.js.map +1 -0
- package/dist/core/mcp-client.d.ts +21 -0
- package/dist/core/mcp-client.d.ts.map +1 -0
- package/{src/core/mcp-client.ts → dist/core/mcp-client.js} +90 -113
- package/dist/core/mcp-client.js.map +1 -0
- package/dist/core/mcp-computer.d.ts +4 -0
- package/dist/core/mcp-computer.d.ts.map +1 -0
- package/{src/core/mcp-computer.ts → dist/core/mcp-computer.js} +5 -5
- package/dist/core/mcp-computer.js.map +1 -0
- package/dist/core/mcp-connection.d.ts +6 -0
- package/dist/core/mcp-connection.d.ts.map +1 -0
- package/dist/core/mcp-connection.js +10 -0
- package/dist/core/mcp-connection.js.map +1 -0
- package/dist/core/mcp-ipc-connection.d.ts +20 -0
- package/dist/core/mcp-ipc-connection.d.ts.map +1 -0
- package/{src/core/mcp-ipc-connection.ts → dist/core/mcp-ipc-connection.js} +126 -153
- package/dist/core/mcp-ipc-connection.js.map +1 -0
- package/dist/core/mcp-server.d.ts +9 -0
- package/dist/core/mcp-server.d.ts.map +1 -0
- package/{src/core/mcp-server.ts → dist/core/mcp-server.js} +45 -49
- package/dist/core/mcp-server.js.map +1 -0
- package/dist/core/mcp.d.ts +29 -0
- package/dist/core/mcp.d.ts.map +1 -0
- package/dist/core/mcp.js +11 -0
- package/dist/core/mcp.js.map +1 -0
- package/dist/core/ollama-provider.d.ts +9 -0
- package/dist/core/ollama-provider.d.ts.map +1 -0
- package/{src/core/ollama-provider.ts → dist/core/ollama-provider.js} +59 -70
- package/dist/core/ollama-provider.js.map +1 -0
- package/dist/core/skill.d.ts +15 -0
- package/dist/core/skill.d.ts.map +1 -0
- package/dist/core/skill.js +11 -0
- package/dist/core/skill.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/index.ts → dist/index.js} +16 -17
- package/dist/index.js.map +1 -0
- package/dist/templates/researcher.d.ts +27 -0
- package/dist/templates/researcher.d.ts.map +1 -0
- package/dist/templates/researcher.js +70 -0
- package/dist/templates/researcher.js.map +1 -0
- package/dist/templates/simple.d.ts +27 -0
- package/dist/templates/simple.d.ts.map +1 -0
- package/dist/templates/simple.js +35 -0
- package/dist/templates/simple.js.map +1 -0
- package/dist/tests/mcp.test.d.ts +2 -0
- package/dist/tests/mcp.test.d.ts.map +1 -0
- package/{src/tests/mcp.test.ts → dist/tests/mcp.test.js} +55 -73
- package/dist/tests/mcp.test.js.map +1 -0
- package/dist/tools/fs/index.d.ts +3 -0
- package/dist/tools/fs/index.d.ts.map +1 -0
- package/dist/tools/fs/index.js +3 -0
- package/dist/tools/fs/index.js.map +1 -0
- package/dist/tools/fs/read-file.d.ts +4 -0
- package/dist/tools/fs/read-file.d.ts.map +1 -0
- package/{src/tools/fs/read-file.ts → dist/tools/fs/read-file.js} +49 -54
- package/dist/tools/fs/read-file.js.map +1 -0
- package/dist/tools/fs/write-file.d.ts +4 -0
- package/dist/tools/fs/write-file.d.ts.map +1 -0
- package/{src/tools/fs/write-file.ts → dist/tools/fs/write-file.js} +68 -73
- package/dist/tools/fs/write-file.js.map +1 -0
- package/dist/tools/utils/get-current-time.d.ts +4 -0
- package/dist/tools/utils/get-current-time.d.ts.map +1 -0
- package/{src/tools/utils/get-current-time.ts → dist/tools/utils/get-current-time.js} +40 -45
- package/dist/tools/utils/get-current-time.js.map +1 -0
- package/dist/tools/utils/index.d.ts +2 -0
- package/dist/tools/utils/index.d.ts.map +1 -0
- package/dist/tools/utils/index.js +2 -0
- package/dist/tools/utils/index.js.map +1 -0
- package/dist/tools/www/fetch.d.ts +4 -0
- package/dist/tools/www/fetch.d.ts.map +1 -0
- package/{src/tools/www/fetch.ts → dist/tools/www/fetch.js} +147 -161
- package/dist/tools/www/fetch.js.map +1 -0
- package/dist/tools/www/index.d.ts +4 -0
- package/dist/tools/www/index.d.ts.map +1 -0
- package/dist/tools/www/index.js +4 -0
- package/dist/tools/www/index.js.map +1 -0
- package/dist/tools/www/read-web-page.d.ts +4 -0
- package/dist/tools/www/read-web-page.d.ts.map +1 -0
- package/{src/tools/www/read-web-page.ts → dist/tools/www/read-web-page.js} +330 -350
- package/dist/tools/www/read-web-page.js.map +1 -0
- package/dist/tools/www/web-search.d.ts +4 -0
- package/dist/tools/www/web-search.d.ts.map +1 -0
- package/{src/tools/www/web-search.ts → dist/tools/www/web-search.js} +82 -102
- package/dist/tools/www/web-search.js.map +1 -0
- package/package.json +19 -5
- package/.env.example +0 -1
- package/orbitx.png +0 -0
- package/public/index.html +0 -397
- package/src/core/mcp-connection.ts +0 -12
- package/src/core/mcp.ts +0 -23
- package/src/core/skill.ts +0 -16
- package/src/templates/researcher.ts +0 -73
- package/src/templates/simple.ts +0 -64
- package/src/tools/fs/index.ts +0 -2
- package/src/tools/utils/index.ts +0 -1
- package/src/tools/www/index.ts +0 -3
- package/tsconfig.json +0 -34
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill.js","sourceRoot":"","sources":["../../src/core/skill.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,KAAK;IACd,MAAM,CAAC;IACP,YAAY,KAIX;QACG,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAED,QAAQ;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;CACJ;AAED,eAAe,KAAK,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { AIProvider } from "./core/ai-provider";
|
|
2
|
+
export type { ChatResponse, Message, StreamCallback } from "./core/ai-provider";
|
|
3
|
+
export { BaseAgent } from "./core/base-agent";
|
|
4
|
+
export type { ExtractedSegment, ParsedToolCall } from "./core/base-agent";
|
|
5
|
+
export { DeepSeekProvider } from "./core/deepseek-provider";
|
|
6
|
+
export { MCPClient } from "./core/mcp-client";
|
|
7
|
+
export { MCPConnection } from "./core/mcp-connection";
|
|
8
|
+
export { MCPIPCConnection } from "./core/mcp-ipc-connection";
|
|
9
|
+
export { MCPServer } from "./core/mcp-server";
|
|
10
|
+
export { MCPTool } from "./core/mcp";
|
|
11
|
+
export { OllamaProvider } from "./core/ollama-provider";
|
|
12
|
+
export { Skill } from "./core/skill";
|
|
13
|
+
export { ResearcherAgent } from "./templates/researcher";
|
|
14
|
+
export { SimpleAgent } from "./templates/simple";
|
|
15
|
+
export { ReadFileTool, WriteFileTool } from "./tools/fs";
|
|
16
|
+
export { GetCurrentTimeTool } from "./tools/utils";
|
|
17
|
+
export { FetchTool, ReadWebPageTool, WebSearchTool } from "./tools/www";
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
export { AIProvider } from "./core/ai-provider";
|
|
2
|
-
export { BaseAgent } from "./core/base-agent";
|
|
3
|
-
export { DeepSeekProvider } from "./core/deepseek-provider";
|
|
4
|
-
export { MCPClient } from "./core/mcp-client";
|
|
5
|
-
export { MCPConnection } from "./core/mcp-connection";
|
|
6
|
-
export { MCPIPCConnection } from "./core/mcp-ipc-connection";
|
|
7
|
-
export { MCPServer } from "./core/mcp-server";
|
|
8
|
-
export { MCPTool } from "./core/mcp";
|
|
9
|
-
export { OllamaProvider } from "./core/ollama-provider";
|
|
10
|
-
export { Skill } from "./core/skill";
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
|
|
17
|
-
export { FetchTool, ReadWebPageTool, WebSearchTool } from "./tools/www";
|
|
1
|
+
export { AIProvider } from "./core/ai-provider";
|
|
2
|
+
export { BaseAgent } from "./core/base-agent";
|
|
3
|
+
export { DeepSeekProvider } from "./core/deepseek-provider";
|
|
4
|
+
export { MCPClient } from "./core/mcp-client";
|
|
5
|
+
export { MCPConnection } from "./core/mcp-connection";
|
|
6
|
+
export { MCPIPCConnection } from "./core/mcp-ipc-connection";
|
|
7
|
+
export { MCPServer } from "./core/mcp-server";
|
|
8
|
+
export { MCPTool } from "./core/mcp";
|
|
9
|
+
export { OllamaProvider } from "./core/ollama-provider";
|
|
10
|
+
export { Skill } from "./core/skill";
|
|
11
|
+
export { ResearcherAgent } from "./templates/researcher";
|
|
12
|
+
export { SimpleAgent } from "./templates/simple";
|
|
13
|
+
export { ReadFileTool, WriteFileTool } from "./tools/fs";
|
|
14
|
+
export { GetCurrentTimeTool } from "./tools/utils";
|
|
15
|
+
export { FetchTool, ReadWebPageTool, WebSearchTool } from "./tools/www";
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Message } from "../core/ai-provider";
|
|
2
|
+
import type AIProvider from "../core/ai-provider";
|
|
3
|
+
import BaseAgent from "../core/base-agent";
|
|
4
|
+
import type MCPTool from "../core/mcp";
|
|
5
|
+
import type Skill from "../core/skill";
|
|
6
|
+
export declare class ResearcherAgent extends BaseAgent {
|
|
7
|
+
constructor({ aiProvider, instruction, tools, skills, maxMemorizeToken, initData }: {
|
|
8
|
+
instruction?: string;
|
|
9
|
+
tools?: MCPTool[];
|
|
10
|
+
aiProvider: AIProvider;
|
|
11
|
+
skills?: Skill[];
|
|
12
|
+
maxMemorizeToken?: number;
|
|
13
|
+
initData?: {
|
|
14
|
+
memory: string;
|
|
15
|
+
messagesFull: Message[];
|
|
16
|
+
fullInputMissTokens: number;
|
|
17
|
+
fullInputHitTokens: number;
|
|
18
|
+
fullOutputTokens: number;
|
|
19
|
+
messagesCompact: Message[];
|
|
20
|
+
currentInputMissTokens: number;
|
|
21
|
+
currentInputHitTokens: number;
|
|
22
|
+
currentOutputTokens: number;
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export default ResearcherAgent;
|
|
27
|
+
//# sourceMappingURL=researcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"researcher.d.ts","sourceRoot":"","sources":["../../src/templates/researcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,OAAO,MAAM,aAAa,CAAC;AAIvC,OAAO,KAAK,KAAK,MAAM,eAAe,CAAC;AAIvC,qBAAa,eAAgB,SAAQ,SAAS;gBAC9B,EACR,UAAU,EACV,WA6BwI,EACxI,KAIC,EACD,MAAW,EACX,gBAAwB,EACxB,QAUC,EACJ,EAAE;QACC,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;QAClB,UAAU,EAAE,UAAU,CAAC;QACvB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;QACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,EAAE;YACP,MAAM,EAAE,MAAM,CAAC;YACf,YAAY,EAAE,OAAO,EAAE,CAAC;YACxB,mBAAmB,EAAE,MAAM,CAAC;YAC5B,kBAAkB,EAAE,MAAM,CAAC;YAC3B,gBAAgB,EAAE,MAAM,CAAC;YACzB,eAAe,EAAE,OAAO,EAAE,CAAC;YAC3B,sBAAsB,EAAE,MAAM,CAAC;YAC/B,qBAAqB,EAAE,MAAM,CAAC;YAC9B,mBAAmB,EAAE,MAAM,CAAC;SAC/B,CAAA;KACJ;CAiBJ;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import BaseAgent from "../core/base-agent";
|
|
2
|
+
import MCPClient from "../core/mcp-client";
|
|
3
|
+
import MCPConnection from "../core/mcp-connection";
|
|
4
|
+
import MCPServer from "../core/mcp-server";
|
|
5
|
+
import { GetCurrentTimeTool } from "../tools/utils";
|
|
6
|
+
import { ReadWebPageTool, WebSearchTool } from "../tools/www";
|
|
7
|
+
export class ResearcherAgent extends BaseAgent {
|
|
8
|
+
constructor({ aiProvider, instruction = `You are an expert research agent. Your defining rule: never answer from memory alone — always search first, then synthesize.
|
|
9
|
+
|
|
10
|
+
## BEFORE ANY SEARCH
|
|
11
|
+
Call GetCurrentTimeTool FIRST. You need the current date to:
|
|
12
|
+
- Write accurate, time-anchored search queries (e.g. "2025" not a stale year)
|
|
13
|
+
- Know if cached/training knowledge is outdated
|
|
14
|
+
- Anchor relative terms like "latest", "recent", "current"
|
|
15
|
+
|
|
16
|
+
Do not call WebSearchTool until GetCurrentTimeTool has returned a result.
|
|
17
|
+
|
|
18
|
+
## RESEARCH DEPTH
|
|
19
|
+
Scale cycles to query complexity:
|
|
20
|
+
- Simple fact: 1 cycle minimum
|
|
21
|
+
- Standard topic: 3 cycles minimum
|
|
22
|
+
- Deep research: 5+ cycles minimum
|
|
23
|
+
|
|
24
|
+
## SEARCH CYCLE
|
|
25
|
+
After you have the current time, repeat this pattern:
|
|
26
|
+
|
|
27
|
+
SEARCH → then immediately → READ (4 URLs in parallel, same turn)
|
|
28
|
+
|
|
29
|
+
Never run a search without reading its results. Never read fewer than 4 URLs unless fewer exist. Never reuse the same query — refine each time.
|
|
30
|
+
|
|
31
|
+
## STOP CONDITION
|
|
32
|
+
After each cycle ask: Do I have enough to fully answer the question with no unresolved gaps?
|
|
33
|
+
- No → refine query, run another cycle
|
|
34
|
+
- Yes → synthesize and respond
|
|
35
|
+
|
|
36
|
+
## OUTPUT
|
|
37
|
+
Cite sources. Match length to need — brief for simple queries, comprehensive for deep research. Use the user's language for all search queries.`, tools = [
|
|
38
|
+
WebSearchTool,
|
|
39
|
+
ReadWebPageTool,
|
|
40
|
+
GetCurrentTimeTool
|
|
41
|
+
], skills = [], maxMemorizeToken = 30000, initData = {
|
|
42
|
+
memory: "",
|
|
43
|
+
messagesFull: [],
|
|
44
|
+
fullInputMissTokens: 0,
|
|
45
|
+
fullInputHitTokens: 0,
|
|
46
|
+
fullOutputTokens: 0,
|
|
47
|
+
messagesCompact: [],
|
|
48
|
+
currentInputMissTokens: 0,
|
|
49
|
+
currentInputHitTokens: 0,
|
|
50
|
+
currentOutputTokens: 0,
|
|
51
|
+
} }) {
|
|
52
|
+
const conn = new MCPConnection();
|
|
53
|
+
const mcpServer = new MCPServer(conn);
|
|
54
|
+
tools.forEach(tool => {
|
|
55
|
+
mcpServer.registerTool(tool);
|
|
56
|
+
});
|
|
57
|
+
const mcpClient = new MCPClient("DEFAULT_ENV", conn);
|
|
58
|
+
super({
|
|
59
|
+
aiProvider,
|
|
60
|
+
instruction,
|
|
61
|
+
mcpClient,
|
|
62
|
+
allowedTools: tools,
|
|
63
|
+
skills,
|
|
64
|
+
maxMemorizeToken,
|
|
65
|
+
initData,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export default ResearcherAgent;
|
|
70
|
+
//# sourceMappingURL=researcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"researcher.js","sourceRoot":"","sources":["../../src/templates/researcher.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,aAAa,MAAM,wBAAwB,CAAC;AACnD,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE9D,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC1C,YAAY,EACR,UAAU,EACV,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gJA6B0H,EACxI,KAAK,GAAG;QACJ,aAAa;QACb,eAAe;QACf,kBAAkB;KACrB,EACD,MAAM,GAAG,EAAE,EACX,gBAAgB,GAAG,KAAK,EACxB,QAAQ,GAAG;QACP,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,EAAE;QAChB,mBAAmB,EAAE,CAAC;QACtB,kBAAkB,EAAE,CAAC;QACrB,gBAAgB,EAAE,CAAC;QACnB,eAAe,EAAE,EAAE;QACnB,sBAAsB,EAAE,CAAC;QACzB,qBAAqB,EAAE,CAAC;QACxB,mBAAmB,EAAE,CAAC;KACzB,EAkBJ;QACG,MAAM,IAAI,GAAG,IAAI,aAAa,EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;QACtC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACjB,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;QACrD,KAAK,CAAC;YACF,UAAU;YACV,WAAW;YACX,SAAS;YACT,YAAY,EAAE,KAAK;YACnB,MAAM;YACN,gBAAgB;YAChB,QAAQ;SACX,CAAC,CAAC;IACP,CAAC;CACJ;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Message } from "../core/ai-provider";
|
|
2
|
+
import type AIProvider from "../core/ai-provider";
|
|
3
|
+
import BaseAgent from "../core/base-agent";
|
|
4
|
+
import type MCPTool from "../core/mcp";
|
|
5
|
+
import type Skill from "../core/skill";
|
|
6
|
+
export declare class SimpleAgent extends BaseAgent {
|
|
7
|
+
constructor({ aiProvider, instruction, tools, skills, maxMemorizeToken, initData }: {
|
|
8
|
+
instruction: string;
|
|
9
|
+
tools: MCPTool[];
|
|
10
|
+
aiProvider: AIProvider;
|
|
11
|
+
skills?: Skill[];
|
|
12
|
+
maxMemorizeToken?: number;
|
|
13
|
+
initData?: {
|
|
14
|
+
memory: string;
|
|
15
|
+
messagesFull: Message[];
|
|
16
|
+
fullInputMissTokens: number;
|
|
17
|
+
fullInputHitTokens: number;
|
|
18
|
+
fullOutputTokens: number;
|
|
19
|
+
messagesCompact: Message[];
|
|
20
|
+
currentInputMissTokens: number;
|
|
21
|
+
currentInputHitTokens: number;
|
|
22
|
+
currentOutputTokens: number;
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export default SimpleAgent;
|
|
27
|
+
//# sourceMappingURL=simple.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple.d.ts","sourceRoot":"","sources":["../../src/templates/simple.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,OAAO,MAAM,aAAa,CAAC;AAIvC,OAAO,KAAK,KAAK,MAAM,eAAe,CAAC;AAEvC,qBAAa,WAAY,SAAQ,SAAS;gBAC1B,EACR,UAAU,EACV,WAAgB,EAChB,KAAU,EACV,MAAW,EACX,gBAAwB,EACxB,QAUC,EACJ,EAAE;QACC,WAAW,EAAE,MAAM,CAAC;QACpB,KAAK,EAAE,OAAO,EAAE,CAAC;QACjB,UAAU,EAAE,UAAU,CAAC;QACvB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;QACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,EAAE;YACP,MAAM,EAAE,MAAM,CAAC;YACf,YAAY,EAAE,OAAO,EAAE,CAAC;YACxB,mBAAmB,EAAE,MAAM,CAAC;YAC5B,kBAAkB,EAAE,MAAM,CAAC;YAC3B,gBAAgB,EAAE,MAAM,CAAC;YACzB,eAAe,EAAE,OAAO,EAAE,CAAC;YAC3B,sBAAsB,EAAE,MAAM,CAAC;YAC/B,qBAAqB,EAAE,MAAM,CAAC;YAC9B,mBAAmB,EAAE,MAAM,CAAC;SAC/B,CAAA;KACJ;CAiBJ;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import BaseAgent from "../core/base-agent";
|
|
2
|
+
import MCPClient from "../core/mcp-client";
|
|
3
|
+
import MCPConnection from "../core/mcp-connection";
|
|
4
|
+
import MCPServer from "../core/mcp-server";
|
|
5
|
+
export class SimpleAgent extends BaseAgent {
|
|
6
|
+
constructor({ aiProvider, instruction = "", tools = [], skills = [], maxMemorizeToken = 16000, initData = {
|
|
7
|
+
memory: "",
|
|
8
|
+
messagesFull: [],
|
|
9
|
+
fullInputMissTokens: 0,
|
|
10
|
+
fullInputHitTokens: 0,
|
|
11
|
+
fullOutputTokens: 0,
|
|
12
|
+
messagesCompact: [],
|
|
13
|
+
currentInputMissTokens: 0,
|
|
14
|
+
currentInputHitTokens: 0,
|
|
15
|
+
currentOutputTokens: 0,
|
|
16
|
+
} }) {
|
|
17
|
+
const conn = new MCPConnection();
|
|
18
|
+
const mcpServer = new MCPServer(conn);
|
|
19
|
+
tools.forEach(tool => {
|
|
20
|
+
mcpServer.registerTool(tool);
|
|
21
|
+
});
|
|
22
|
+
const mcpClient = new MCPClient("DEFAULT_ENV", conn);
|
|
23
|
+
super({
|
|
24
|
+
aiProvider,
|
|
25
|
+
instruction,
|
|
26
|
+
mcpClient,
|
|
27
|
+
allowedTools: tools,
|
|
28
|
+
skills,
|
|
29
|
+
maxMemorizeToken,
|
|
30
|
+
initData,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export default SimpleAgent;
|
|
35
|
+
//# sourceMappingURL=simple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple.js","sourceRoot":"","sources":["../../src/templates/simple.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,aAAa,MAAM,wBAAwB,CAAC;AACnD,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAG3C,MAAM,OAAO,WAAY,SAAQ,SAAS;IACtC,YAAY,EACR,UAAU,EACV,WAAW,GAAG,EAAE,EAChB,KAAK,GAAG,EAAE,EACV,MAAM,GAAG,EAAE,EACX,gBAAgB,GAAG,KAAK,EACxB,QAAQ,GAAG;QACP,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,EAAE;QAChB,mBAAmB,EAAE,CAAC;QACtB,kBAAkB,EAAE,CAAC;QACrB,gBAAgB,EAAE,CAAC;QACnB,eAAe,EAAE,EAAE;QACnB,sBAAsB,EAAE,CAAC;QACzB,qBAAqB,EAAE,CAAC;QACxB,mBAAmB,EAAE,CAAC;KACzB,EAkBJ;QACG,MAAM,IAAI,GAAG,IAAI,aAAa,EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;QACtC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACjB,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;QACrD,KAAK,CAAC;YACF,UAAU;YACV,WAAW;YACX,SAAS;YACT,YAAY,EAAE,KAAK;YACnB,MAAM;YACN,gBAAgB;YAChB,QAAQ;SACX,CAAC,CAAC;IACP,CAAC;CACJ;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.test.d.ts","sourceRoot":"","sources":["../../src/tests/mcp.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,73 +1,55 @@
|
|
|
1
|
-
import { describe, test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import os from "os";
|
|
4
|
-
import MCPIPCConnection from "../core/mcp-ipc-connection";
|
|
5
|
-
import MCPServer from "../core/mcp-server";
|
|
6
|
-
import MCPClient from "../core/mcp-client";
|
|
7
|
-
import { GetCurrentTimeTool } from "../tools/utils";
|
|
8
|
-
import { FetchTool, WebSearchTool } from "../tools/www";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
mcpClient
|
|
28
|
-
const result = await mcpClient.getTools();
|
|
29
|
-
assert.equal(result.length,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
mcpClient.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
assert.
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
assert.ok(typeof result == "string");
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
await test("should call tool on server1 side", async () => {
|
|
60
|
-
const result = await mcpClient.callTool(FetchTool.getOptions().name, { url: "https://google.com" });
|
|
61
|
-
|
|
62
|
-
assert.ok(typeof result == "string");
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
await test("should call tool on server2 side", async () => {
|
|
66
|
-
const result = await mcpClient.callTool(WebSearchTool.getOptions().name, { query: "test" });
|
|
67
|
-
|
|
68
|
-
assert.ok(typeof result == "string");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// Need Close Connections
|
|
73
|
-
});
|
|
1
|
+
import { describe, test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import MCPIPCConnection from "../core/mcp-ipc-connection";
|
|
5
|
+
import MCPServer from "../core/mcp-server";
|
|
6
|
+
import MCPClient from "../core/mcp-client";
|
|
7
|
+
import { GetCurrentTimeTool } from "../tools/utils";
|
|
8
|
+
import { FetchTool, WebSearchTool } from "../tools/www";
|
|
9
|
+
describe("MCP Client and Server", async () => {
|
|
10
|
+
const path1 = os.platform() == "win32" ? `\\\\.\\pipe\\test${Math.random() * 1000}` : `/tmp/mcp_test${Math.random() * 1000}.sock`;
|
|
11
|
+
const path2 = os.platform() == "win32" ? `\\\\.\\pipe\\test${Math.random() * 1000}` : `/tmp/mcp_test${Math.random() * 1000}.sock`;
|
|
12
|
+
const ipcConnection11 = new MCPIPCConnection(path1);
|
|
13
|
+
const ipcConnection21 = new MCPIPCConnection(path2);
|
|
14
|
+
const ipcConnection12 = new MCPIPCConnection(path1);
|
|
15
|
+
const ipcConnection22 = new MCPIPCConnection(path2);
|
|
16
|
+
let mcpServer1;
|
|
17
|
+
let mcpServer2;
|
|
18
|
+
let mcpClient;
|
|
19
|
+
await test("should connect MCP Client to Servers and get empty tools", async () => {
|
|
20
|
+
mcpServer1 = new MCPServer(ipcConnection11);
|
|
21
|
+
mcpServer2 = new MCPServer(ipcConnection21);
|
|
22
|
+
mcpClient = new MCPClient("DEFAULT_ENV", [ipcConnection12, ipcConnection22]);
|
|
23
|
+
const result = await mcpClient.getTools();
|
|
24
|
+
assert.equal(result.length, 0);
|
|
25
|
+
});
|
|
26
|
+
await test("should register tool on client side", async () => {
|
|
27
|
+
mcpClient.registerTool(GetCurrentTimeTool);
|
|
28
|
+
const result = await mcpClient.getTools();
|
|
29
|
+
assert.equal(result.length, 1);
|
|
30
|
+
});
|
|
31
|
+
await test("should register tool on server1 side", async () => {
|
|
32
|
+
mcpServer1.registerTool(FetchTool);
|
|
33
|
+
const result = await mcpClient.getTools();
|
|
34
|
+
assert.equal(result.length, 2);
|
|
35
|
+
});
|
|
36
|
+
await test("should register tool on server2 side", async () => {
|
|
37
|
+
mcpServer2.registerTool(WebSearchTool);
|
|
38
|
+
const result = await mcpClient.getTools();
|
|
39
|
+
assert.equal(result.length, 3);
|
|
40
|
+
});
|
|
41
|
+
await test("should call tool on client side", async () => {
|
|
42
|
+
const result = await mcpClient.callTool(GetCurrentTimeTool.getOptions().name, {});
|
|
43
|
+
assert.ok(typeof result == "string");
|
|
44
|
+
});
|
|
45
|
+
await test("should call tool on server1 side", async () => {
|
|
46
|
+
const result = await mcpClient.callTool(FetchTool.getOptions().name, { url: "https://google.com" });
|
|
47
|
+
assert.ok(typeof result == "string");
|
|
48
|
+
});
|
|
49
|
+
await test("should call tool on server2 side", async () => {
|
|
50
|
+
const result = await mcpClient.callTool(WebSearchTool.getOptions().name, { query: "test" });
|
|
51
|
+
assert.ok(typeof result == "string");
|
|
52
|
+
});
|
|
53
|
+
// Need Close Connections
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=mcp.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.test.js","sourceRoot":"","sources":["../../src/tests/mcp.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,gBAAgB,MAAM,4BAA4B,CAAC;AAC1D,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAExD,QAAQ,CAAC,uBAAuB,EAAE,KAAK,IAAI,EAAE;IACzC,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,oBAAoB,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,gBAAgB,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,OAAO,CAAC;IAClI,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,oBAAoB,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,EAAE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AAC;IAGH,yBAAyB;AAC7B,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/fs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/fs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.d.ts","sourceRoot":"","sources":["../../../src/tools/fs/read-file.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAIrC,eAAO,MAAM,YAAY,SA+CvB,CAAC;AAEH,eAAe,YAAY,CAAC"}
|
|
@@ -1,54 +1,49 @@
|
|
|
1
|
-
import MCPTool from "../../core/mcp";
|
|
2
|
-
import fs from "fs/promises";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (err.code === "
|
|
39
|
-
errorMessage = `
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
export default ReadFileTool;
|
|
1
|
+
import MCPTool from "../../core/mcp";
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
export const ReadFileTool = new MCPTool({
|
|
5
|
+
name: "read-file",
|
|
6
|
+
description: "Reads text content from a file at the specified path.",
|
|
7
|
+
inputs: [{
|
|
8
|
+
name: "filePath",
|
|
9
|
+
type: "string",
|
|
10
|
+
description: `Absolute or relative path to the file (e.g., "/home/user/doc.txt" or "./file.txt")`,
|
|
11
|
+
required: true,
|
|
12
|
+
}],
|
|
13
|
+
execute: async (_, inputs) => {
|
|
14
|
+
try {
|
|
15
|
+
const { filePath } = inputs;
|
|
16
|
+
if (!filePath || typeof filePath !== "string") {
|
|
17
|
+
throw new Error("filePath must be a non-empty string");
|
|
18
|
+
}
|
|
19
|
+
const normalizedPath = path.normalize(filePath);
|
|
20
|
+
const data = await fs.readFile(normalizedPath, "utf-8");
|
|
21
|
+
return {
|
|
22
|
+
message: `File read successfully: ${normalizedPath}`,
|
|
23
|
+
path: normalizedPath,
|
|
24
|
+
content: data,
|
|
25
|
+
size: data.length
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
let errorMessage = error instanceof Error ? error.message : String(error);
|
|
30
|
+
if (error instanceof Error && "code" in error) {
|
|
31
|
+
const err = error;
|
|
32
|
+
if (err.code === "ENOENT") {
|
|
33
|
+
errorMessage = `File not found: ${inputs.filePath}`;
|
|
34
|
+
}
|
|
35
|
+
else if (err.code === "EACCES") {
|
|
36
|
+
errorMessage = `Permission denied: ${inputs.filePath}`;
|
|
37
|
+
}
|
|
38
|
+
else if (err.code === "EISDIR") {
|
|
39
|
+
errorMessage = `Path is a directory, not a file: ${inputs.filePath}`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
error: errorMessage
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
export default ReadFileTool;
|
|
49
|
+
//# sourceMappingURL=read-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.js","sourceRoot":"","sources":["../../../src/tools/fs/read-file.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,OAAO,CAAC;IACpC,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,uDAAuD;IACpE,MAAM,EAAE,CAAC;YACL,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,oFAAoF;YACjG,QAAQ,EAAE,IAAI;SACjB,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,CAAS,EAAE,MAA2B,EAAgB,EAAE;QACpE,IAAI,CAAC;YACD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;YAE5B,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBAC5C,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;YAC3D,CAAC;YAED,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAEhD,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;YAExD,OAAO;gBACH,OAAO,EAAE,2BAA2B,cAAc,EAAE;gBACpD,IAAI,EAAE,cAAc;gBACpB,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,IAAI,CAAC,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