@vectorx/agent-simulator 0.1.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/README.md +76 -0
- package/bin/agent.js +55 -0
- package/lib/index.js +5 -0
- package/lib/simulator.js +224 -0
- package/lib/types.js +2 -0
- package/lib/utils.js +7 -0
- package/lib/webview-ui/Agent.js +16 -0
- package/lib/webview-ui/App.js +359 -0
- package/lib/webview-ui/ErrorBoundary.js +57 -0
- package/lib/webview-ui/components/KnowledgeBaseSearchBlock.js +62 -0
- package/lib/webview-ui/components/KnowledgeBaseSearchResult.js +37 -0
- package/lib/webview-ui/components/MarkdownRenderer.js +27 -0
- package/lib/webview-ui/components/MessageRenderer.js +36 -0
- package/lib/webview-ui/components/ThinkingBlock.js +105 -0
- package/lib/webview-ui/components/ToolUseBlock.js +20 -0
- package/lib/webview-ui/components/ToolUseBlockHeader.js +48 -0
- package/lib/webview-ui/components/index.js +23 -0
- package/lib/webview-ui/constants.js +24 -0
- package/lib/webview-ui/contexts/ThemeContext.js +50 -0
- package/lib/webview-ui/hooks/useAgentStatus.js +96 -0
- package/lib/webview-ui/index.js +17 -0
- package/lib/webview-ui/services/agent-service.js +33 -0
- package/lib/webview-ui/services/logger-service.js +51 -0
- package/lib/webview-ui/styles/copilot.js +118 -0
- package/lib/webview-ui/styles/workarea.js +72 -0
- package/lib/webview-ui/types/index.js +2 -0
- package/lib/webview-ui/types.js +2 -0
- package/lib/webview-ui/widgets/BubbleComponents.js +114 -0
- package/lib/webview-ui/widgets/LogPanel.js +66 -0
- package/lib/webview-ui/widgets/SystemLogs.js +404 -0
- package/lib/webview-ui/widgets/ToolBar.js +109 -0
- package/lib/webview-ui/widgets/index.js +20 -0
- package/package.json +79 -0
- package/public/assets/index-j_rEEDWU.js +93 -0
- package/public/assets/main.js +580 -0
- package/public/assets/style.css +1 -0
- package/public/index.html +15 -0
- package/types/index.d.ts +3 -0
- package/types/simulator.d.ts +15 -0
- package/types/types.d.ts +6 -0
- package/types/utils.d.ts +1 -0
- package/types/webview-ui/Agent.d.ts +3 -0
- package/types/webview-ui/App.d.ts +3 -0
- package/types/webview-ui/ErrorBoundary.d.ts +18 -0
- package/types/webview-ui/components/KnowledgeBaseSearchBlock.d.ts +19 -0
- package/types/webview-ui/components/KnowledgeBaseSearchResult.d.ts +8 -0
- package/types/webview-ui/components/MarkdownRenderer.d.ts +6 -0
- package/types/webview-ui/components/MessageRenderer.d.ts +6 -0
- package/types/webview-ui/components/ThinkingBlock.d.ts +7 -0
- package/types/webview-ui/components/ToolUseBlock.d.ts +9 -0
- package/types/webview-ui/components/ToolUseBlockHeader.d.ts +9 -0
- package/types/webview-ui/components/index.d.ts +7 -0
- package/types/webview-ui/constants.d.ts +17 -0
- package/types/webview-ui/contexts/ThemeContext.d.ts +11 -0
- package/types/webview-ui/hooks/useAgentStatus.d.ts +11 -0
- package/types/webview-ui/index.d.ts +2 -0
- package/types/webview-ui/services/agent-service.d.ts +27 -0
- package/types/webview-ui/services/logger-service.d.ts +29 -0
- package/types/webview-ui/styles/copilot.d.ts +13 -0
- package/types/webview-ui/styles/workarea.d.ts +10 -0
- package/types/webview-ui/types/index.d.ts +20 -0
- package/types/webview-ui/types.d.ts +48 -0
- package/types/webview-ui/widgets/BubbleComponents.d.ts +12 -0
- package/types/webview-ui/widgets/LogPanel.d.ts +14 -0
- package/types/webview-ui/widgets/SystemLogs.d.ts +23 -0
- package/types/webview-ui/widgets/ToolBar.d.ts +13 -0
- package/types/webview-ui/widgets/index.d.ts +4 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ToolBar = void 0;
|
|
16
|
+
const icons_1 = require("@ant-design/icons");
|
|
17
|
+
const antd_1 = require("antd");
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const ToolBar = ({ agentSimulatorInfo, debugStatus, showSystemLogs, isConnecting = false, onRetryConnection, onClearChat, onToggleLogs, }) => {
|
|
20
|
+
var _a, _b, _c, _d, _e;
|
|
21
|
+
const { token } = antd_1.theme.useToken();
|
|
22
|
+
const getDebugStatusText = () => {
|
|
23
|
+
if (!agentSimulatorInfo) {
|
|
24
|
+
return "服务断开";
|
|
25
|
+
}
|
|
26
|
+
switch (debugStatus) {
|
|
27
|
+
case "connecting":
|
|
28
|
+
return "正在连接服务器...";
|
|
29
|
+
case "timeout":
|
|
30
|
+
return "连接超时";
|
|
31
|
+
case "normal":
|
|
32
|
+
return "正常";
|
|
33
|
+
case "error":
|
|
34
|
+
return "服务已断开";
|
|
35
|
+
default:
|
|
36
|
+
return "未知状态";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const copyAgentId = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
var _a;
|
|
41
|
+
const agentId = (_a = agentSimulatorInfo === null || agentSimulatorInfo === void 0 ? void 0 : agentSimulatorInfo.agentInfo) === null || _a === void 0 ? void 0 : _a.agent_id;
|
|
42
|
+
if (agentId) {
|
|
43
|
+
try {
|
|
44
|
+
yield navigator.clipboard.writeText(agentId);
|
|
45
|
+
antd_1.message.success("AgentId 已复制到剪贴板");
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
const textArea = document.createElement("textarea");
|
|
49
|
+
textArea.value = agentId;
|
|
50
|
+
document.body.appendChild(textArea);
|
|
51
|
+
textArea.select();
|
|
52
|
+
document.execCommand("copy");
|
|
53
|
+
document.body.removeChild(textArea);
|
|
54
|
+
antd_1.message.success("AgentId 已复制到剪贴板");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return (react_1.default.createElement("header", { className: "app-header", style: {
|
|
59
|
+
background: token.colorBgElevated,
|
|
60
|
+
} },
|
|
61
|
+
react_1.default.createElement("div", { className: "agent-info", style: {
|
|
62
|
+
borderBottom: `1px solid ${token.colorBorder}`,
|
|
63
|
+
} },
|
|
64
|
+
react_1.default.createElement("div", { className: "agent-avatar", style: {
|
|
65
|
+
background: token.colorBgElevated,
|
|
66
|
+
} }, ((_a = agentSimulatorInfo === null || agentSimulatorInfo === void 0 ? void 0 : agentSimulatorInfo.agentInfo) === null || _a === void 0 ? void 0 : _a.agent_icon) ? (react_1.default.createElement("img", { src: agentSimulatorInfo.agentInfo.agent_icon, alt: "Agent Avatar", onError: (e) => {
|
|
67
|
+
e.target.src =
|
|
68
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='36' height='36' viewBox='0 0 24 24'%3E%3Cpath fill='%23aaa' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z'/%3E%3C/svg%3E";
|
|
69
|
+
} })) : (react_1.default.createElement("img", { src: "/avatar-placeholder.png", alt: "Agent Avatar", onError: (e) => {
|
|
70
|
+
e.target.src =
|
|
71
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='36' height='36' viewBox='0 0 24 24'%3E%3Cpath fill='%23aaa' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z'/%3E%3C/svg%3E";
|
|
72
|
+
} }))),
|
|
73
|
+
react_1.default.createElement("div", { className: "agent-details" },
|
|
74
|
+
react_1.default.createElement("div", { className: "agent-info-left" },
|
|
75
|
+
react_1.default.createElement("h1", { className: "agent-name", style: {
|
|
76
|
+
color: token.colorText,
|
|
77
|
+
} }, ((_b = agentSimulatorInfo === null || agentSimulatorInfo === void 0 ? void 0 : agentSimulatorInfo.agentInfo) === null || _b === void 0 ? void 0 : _b.agent_name) || "未连接")),
|
|
78
|
+
react_1.default.createElement("div", { className: "agent-info-right" },
|
|
79
|
+
react_1.default.createElement("div", { className: "agent-id-container" },
|
|
80
|
+
react_1.default.createElement("span", { className: "agent-id-value", title: ((_c = agentSimulatorInfo === null || agentSimulatorInfo === void 0 ? void 0 : agentSimulatorInfo.agentInfo) === null || _c === void 0 ? void 0 : _c.agent_id) || "获取中...", style: {
|
|
81
|
+
color: token.colorText,
|
|
82
|
+
} }, ((_d = agentSimulatorInfo === null || agentSimulatorInfo === void 0 ? void 0 : agentSimulatorInfo.agentInfo) === null || _d === void 0 ? void 0 : _d.agent_id) || "获取中..."),
|
|
83
|
+
((_e = agentSimulatorInfo === null || agentSimulatorInfo === void 0 ? void 0 : agentSimulatorInfo.agentInfo) === null || _e === void 0 ? void 0 : _e.agent_id) && (react_1.default.createElement(antd_1.Button, { className: "copy-icon", type: "text", size: "small", icon: react_1.default.createElement(icons_1.CopyOutlined, null), onClick: copyAgentId, title: "\u70B9\u51FB\u590D\u5236 AgentId", style: {
|
|
84
|
+
padding: "0 4px",
|
|
85
|
+
minWidth: "auto",
|
|
86
|
+
height: "auto",
|
|
87
|
+
} })))))),
|
|
88
|
+
react_1.default.createElement("div", { className: "debug-controls" },
|
|
89
|
+
react_1.default.createElement("div", { className: "debug-status" },
|
|
90
|
+
react_1.default.createElement("span", { className: "status-label", style: {
|
|
91
|
+
color: token.colorText,
|
|
92
|
+
} }, "\u8C03\u8BD5\u72B6\u6001:"),
|
|
93
|
+
react_1.default.createElement("span", { className: `status-indicator ${!agentSimulatorInfo ? "error" : debugStatus}` }, getDebugStatusText())),
|
|
94
|
+
react_1.default.createElement("div", { className: "debug-buttons", style: { display: "flex", gap: "8px" } },
|
|
95
|
+
react_1.default.createElement(antd_1.Button, { size: "small", icon: react_1.default.createElement(icons_1.ClearOutlined, null), onClick: onClearChat, title: "\u6E05\u7A7A\u804A\u5929\u8BB0\u5F55", style: {
|
|
96
|
+
borderColor: token.colorWarning,
|
|
97
|
+
color: token.colorWarning,
|
|
98
|
+
} }, "\u6E05\u7A7A\u804A\u5929"),
|
|
99
|
+
react_1.default.createElement(antd_1.Button, { size: "small", onClick: onToggleLogs, style: {
|
|
100
|
+
borderColor: showSystemLogs ? token.colorPrimary : token.colorPrimary,
|
|
101
|
+
color: showSystemLogs ? "#fff" : token.colorPrimary,
|
|
102
|
+
backgroundColor: showSystemLogs ? token.colorPrimary : "transparent",
|
|
103
|
+
} }, "\uD83D\uDCCB \u65E5\u5FD7"),
|
|
104
|
+
react_1.default.createElement(antd_1.Button, { size: "small", icon: react_1.default.createElement(icons_1.ApiOutlined, null), onClick: onRetryConnection, loading: isConnecting, title: isConnecting ? "正在连接服务器..." : "重新连接服务器", style: {
|
|
105
|
+
borderColor: token.colorSuccess,
|
|
106
|
+
color: token.colorSuccess,
|
|
107
|
+
} }, isConnecting ? "连接中..." : "重试连接")))));
|
|
108
|
+
};
|
|
109
|
+
exports.ToolBar = ToolBar;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./BubbleComponents"), exports);
|
|
18
|
+
__exportStar(require("./SystemLogs"), exports);
|
|
19
|
+
__exportStar(require("./ToolBar"), exports);
|
|
20
|
+
__exportStar(require("./LogPanel"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vectorx/agent-simulator",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Development simulator for VectorX AI agents",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"agent": "./bin/agent.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"lib",
|
|
12
|
+
"bin",
|
|
13
|
+
"README.md",
|
|
14
|
+
"public",
|
|
15
|
+
"types"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"ai",
|
|
19
|
+
"agent",
|
|
20
|
+
"simulator",
|
|
21
|
+
"development",
|
|
22
|
+
"debug"
|
|
23
|
+
],
|
|
24
|
+
"author": "",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18.0.0"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@ant-design/icons": "^5.2.6",
|
|
31
|
+
"@ant-design/x": "^1.2.0",
|
|
32
|
+
"@types/markdown-it": "^14.1.2",
|
|
33
|
+
"@vectorx/ai-sdk": "0.1.0",
|
|
34
|
+
"@vectorx/functions-framework": "0.1.0",
|
|
35
|
+
"antd": "^5.0.0",
|
|
36
|
+
"antd-style": "^3.7.1",
|
|
37
|
+
"chalk": "^4.1.2",
|
|
38
|
+
"commander": "^11.1.0",
|
|
39
|
+
"cors": "^2.8.5",
|
|
40
|
+
"dayjs": "^1.11.13",
|
|
41
|
+
"express": "^4.18.2",
|
|
42
|
+
"highlight.js": "^11.9.0",
|
|
43
|
+
"http-proxy-middleware": "^2.0.6",
|
|
44
|
+
"markdown-it": "^14.1.0",
|
|
45
|
+
"marked": "^11.1.0",
|
|
46
|
+
"node-fetch": "v2",
|
|
47
|
+
"react": "^18.2.0",
|
|
48
|
+
"react-dom": "^18.2.0",
|
|
49
|
+
"react-markdown": "^9.0.1",
|
|
50
|
+
"react-syntax-highlighter": "^15.5.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/cors": "^2.8.17",
|
|
54
|
+
"@types/express": "^4.17.21",
|
|
55
|
+
"@types/marked": "^5.0.2",
|
|
56
|
+
"@types/node": "^20.11.24",
|
|
57
|
+
"@types/react": "^18.2.0",
|
|
58
|
+
"@types/react-dom": "^18.2.0",
|
|
59
|
+
"@types/react-syntax-highlighter": "^15.5.11",
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
61
|
+
"@typescript-eslint/parser": "^7.1.0",
|
|
62
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
63
|
+
"eslint": "^8.57.0",
|
|
64
|
+
"ts-node-dev": "^2.0.0",
|
|
65
|
+
"typescript": "^5.0.0",
|
|
66
|
+
"vite": "^5.0.8"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"dev:server": "tsc -w",
|
|
70
|
+
"dev:client": "vite",
|
|
71
|
+
"dev": "npm run dev:server & npm run dev:client",
|
|
72
|
+
"build:server": "tsc",
|
|
73
|
+
"build:client": "vite build",
|
|
74
|
+
"build": "npm run build:server && npm run build:client",
|
|
75
|
+
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
76
|
+
"fix": "eslint 'src/**/*.{ts,tsx}' --fix"
|
|
77
|
+
},
|
|
78
|
+
"readme": "# VectorX Agent Simulator\n\nVectorX Agent模拟器是一个开发工具,用于帮助开发和调试AI代理应用。它提供了一个简单的界面和调试环境,允许开发者在本地模拟API请求和响应。\n\n## 特性\n\n- 提供Web界面用于实时查看模拟器状态\n- 使用标准 Fetch API 直接连接Agent服务\n- 支持流式响应和普通 JSON 响应\n- 提供命令行工具,便于快速启动和配置\n\n## 安装\n\n```bash\n# 在项目根目录安装依赖\nnpm install\n\n# 构建模拟器\ncd packages/vectorx-agent-simulator\nnpm run build\n```\n\n## 实现方式\n\nVectorX Agent Simulator 使用标准的 Fetch API 直接连接Agent服务。\n\n这种实现方式具有以下优势:\n- 使用标准 Web API,无需额外依赖\n- 直接与Agent服务通信,无需模拟层\n- 支持流式响应,实时更新内容\n- 便于理解和扩展\n\n## 使用方法\n\n### 命令行\n\n使用以下命令启动模拟器:\n\n```bash\nagent -p 3001 --agent-server-url http://localhost:3000/v1/aiagent/agents/123\n```\n\n#### 命令行参数\n\n- `-p, --port <port>`: 模拟器HTTP服务端口 (默认: 3001)\n- `--agent-server-url <agentServerUrl>`: **[必填]** Agent服务器完整URL地址,例如: http://localhost:3000/v1/aiagent/agents/123\n- `-o, --open`: 启动后自动打开浏览器 (默认: true)\n\n#### 示例\n\n```bash\n# 基本使用\nagent --agent-server-url http://localhost:3000/v1/aiagent/agents/my-agent\n\n# 指定端口\nagent -p 8080 --agent-server-url http://localhost:3000/v1/aiagent/agents/my-agent\n\n# 不自动打开浏览器\nagent --agent-server-url http://localhost:3000/v1/aiagent/agents/my-agent --no-open\n```\n\n## 开发\n\n要在开发模式下运行模拟器:\n\n```bash\n# 监视文件变化并重新构建\nnpm run dev\n\n# 在另一个终端启动模拟器\nnode bin/agent.js --agent-server-url http://localhost:3000/v1/aiagent/agents/demo-agent\n```\n\n## 许可证\n\nISC "
|
|
79
|
+
}
|