@amical/aiagent-sdk 0.1.0 → 0.1.2

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.
Files changed (42) hide show
  1. package/dist/index.d.mts +476 -0
  2. package/dist/index.d.ts +476 -0
  3. package/dist/index.js +968 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +951 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +7 -1
  8. package/.agents/skills/Viral_Writer/SKILL.md +0 -239
  9. package/.cline_memory.json +0 -58
  10. package/.node-version +0 -1
  11. package/Agents.md +0 -95
  12. package/src/agent/Agent.ts +0 -566
  13. package/src/agent/index.ts +0 -1
  14. package/src/index.ts +0 -15
  15. package/src/llm/NodeApiHandler.ts +0 -117
  16. package/src/llm/WebApiHandler.ts +0 -118
  17. package/src/llm/index.ts +0 -47
  18. package/src/mcp/NodeMcpManager.ts +0 -158
  19. package/src/mcp/WebMcpManager.ts +0 -30
  20. package/src/mcp/index.ts +0 -56
  21. package/src/memory/NodeMemoryManager.ts +0 -82
  22. package/src/memory/WebMemoryManager.ts +0 -89
  23. package/src/memory/index.ts +0 -36
  24. package/src/parser/diff.ts +0 -855
  25. package/src/parser/index.ts +0 -111
  26. package/src/parser/parse-assistant-message.ts +0 -240
  27. package/src/prompt/NodePromptManager.ts +0 -276
  28. package/src/prompt/WebPromptManager.ts +0 -277
  29. package/src/prompt/index.ts +0 -28
  30. package/src/runtime/nodeRuntime.ts +0 -112
  31. package/src/runtime/web.test.ts +0 -95
  32. package/src/runtime/webRuntime.ts +0 -119
  33. package/src/runtime.ts +0 -46
  34. package/src/shared/tools.ts +0 -270
  35. package/test-node-agent.ts +0 -113
  36. package/test-runtime.mjs +0 -36
  37. package/test.md +0 -33
  38. package/tsconfig.json +0 -28
  39. package/tsup.config.ts +0 -21
  40. package/uapi.ts +0 -3
  41. package/webFetch.ts +0 -49
  42. package/webSearch.ts +0 -19
@@ -1,270 +0,0 @@
1
- export enum AgentDefaultTool {
2
- ASK = "agent_ask_followup_question",
3
- ATTEMPT = "agent_attempt_completion",
4
- BASH = "agent_execute_command",
5
- FILE_EDIT = "agent_replace_in_file",
6
- FILE_READ = "agent_read_file",
7
- FILE_NEW = "agent_write_to_file",
8
- FILE_DELETE = "agent_delete_file",
9
- DIR_DELETE = "agent_delete_directory",
10
- SEARCH = "agent_search_files",
11
- LIST_FILES = "agent_list_files",
12
- LIST_CODE_DEF = "agent_list_code_definition_names",
13
- BROWSER = "agent_browser_action",
14
- MCP_USE = "agent_use_mcp_tool",
15
- MCP_ACCESS = "agent_access_mcp_resource",
16
- MCP_DOCS = "agent_load_mcp_documentation",
17
- NEW_TASK = "agent_new_task",
18
- PLAN_MODE = "agent_plan_mode_respond",
19
- ACT_MODE = "agent_act_mode_respond",
20
- TODO = "agent_focus_chain",
21
- WEB_FETCH = "agent_web_fetch",
22
- WEB_SEARCH = "agent_web_search",
23
- CONDENSE = "agent_condense",
24
- SUMMARIZE_TASK = "agent_summarize_task",
25
- REPORT_BUG = "agent_report_bug",
26
- NEW_RULE = "agent_new_rule",
27
- APPLY_PATCH = "agent_apply_patch",
28
- GENERATE_EXPLANATION = "agent_generate_explanation",
29
- LOAD_SKILL = "agent_load_skill",
30
- USE_SUBAGENTS = "agent_use_subagents",
31
- }
32
-
33
- export const TOOL_RESULT_BLOCK = 'tool_call_result';
34
-
35
- export const defaultTools = [
36
- {
37
- name: AgentDefaultTool.ASK,
38
- description: "Ask the user a clarifying question if more information is needed.",
39
- params: {
40
- question: "The question to ask the user.",
41
- },
42
- },
43
- {
44
- name: AgentDefaultTool.ATTEMPT,
45
- description: "After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. Optionally you may provide a CLI command to showcase the result of your work. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again. IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool. If you were using task_progress to update the task progress, you must include the completed list in the result as well.",
46
- params: {
47
- result: "(required) The result of the tool use. This should be a clear, specific description of the result.",
48
- },
49
- example: `## Example: ${AgentDefaultTool.ATTEMPT}
50
- <${AgentDefaultTool.ATTEMPT}>
51
- <result>final result or message</result>
52
- <task_progress>
53
- - [x] Set up project structure
54
- - [x] Install dependencies
55
- - [x] Run command to start server
56
- - [x] Test application
57
- </task_progress>
58
- </${AgentDefaultTool.ATTEMPT}>`,
59
- },
60
- {
61
- name: AgentDefaultTool.BASH,
62
- description: "Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. For command chaining, use the appropriate chaining syntax for the user's shell. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will be executed in the current working directory: ${context.cwd} Use @workspace:path syntax (e.g., @frontend:src/index.ts) to specify a workspace.",
63
- params: {
64
- command: "(required) The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions.",
65
- },
66
- example: `## Example: Requesting to execute a command
67
-
68
- <${AgentDefaultTool.BASH}>
69
- <command>npm run dev</command>
70
- <requires_approval>false</requires_approval>
71
- <task_progress>
72
- - [x] Set up project structure
73
- - [x] Install dependencies
74
- - [ ] Run command to start server
75
- - [ ] Test application
76
- </task_progress>
77
- </${AgentDefaultTool.BASH}>`,
78
- },
79
- {
80
- name: AgentDefaultTool.FILE_EDIT,
81
- description: "Replace specific content in a file using a search/replace diff block.",
82
- params: {
83
- path: "(required) The absolute or relative file path to modify.",
84
- diff: "(required) The diff content to apply.",
85
- },
86
- example: `## Example: Requesting to make targeted edits to a file
87
-
88
- <${AgentDefaultTool.FILE_EDIT}>
89
- <path>src/components/App.tsx</path>
90
- <diff>
91
- ------- SEARCH
92
- import React from 'react';
93
- =======
94
- import React, { useState } from 'react';
95
- +++++++ REPLACE
96
-
97
- ------- SEARCH
98
- function handleSubmit() {
99
- saveData();
100
- setLoading(false);
101
- }
102
-
103
- =======
104
- +++++++ REPLACE
105
-
106
- ------- SEARCH
107
- return (
108
- <div>
109
- =======
110
- function handleSubmit() {
111
- saveData();
112
- setLoading(false);
113
- }
114
-
115
- return (
116
- <div>
117
- +++++++ REPLACE
118
- </diff>
119
- <task_progress>
120
- - [x] Set up project structure
121
- - [x] Install dependencies
122
- - [ ] Create components
123
- - [ ] Test application
124
- </task_progress>
125
- </${AgentDefaultTool.FILE_EDIT}>`,
126
- },
127
- {
128
- name: AgentDefaultTool.FILE_READ,
129
- description: "Read the contents of a specific file.",
130
- params: {
131
- path: "(required) The absolute or relative file path to read.",
132
- },
133
- },
134
- {
135
- name: AgentDefaultTool.FILE_NEW,
136
- description: "Create or overwrite a file with new content.",
137
- params: {
138
- path: "(required) The path of the file to write to (relative to the current working directory ${context.cwd}) Use @workspace:path syntax (e.g., @frontend:src/index.ts) to specify a workspace.",
139
- content: "(required) The content to write to the file.",
140
- },
141
- example: `## Example: Requesting to create a new file
142
-
143
- <${AgentDefaultTool.FILE_NEW}>
144
- <path>src/frontend-config.json</path>
145
- <content>
146
- {
147
- "apiEndpoint": "https://api.example.com",
148
- "theme": {
149
- "primaryColor": "#007bff",
150
- "secondaryColor": "#6c757d",
151
- "fontFamily": "Arial, sans-serif"
152
- },
153
- "features": {
154
- "darkMode": true,
155
- "notifications": true,
156
- "analytics": false
157
- },
158
- "version": "1.0.0"
159
- }
160
- </content>
161
- <task_progress>
162
- - [x] Set up project structure
163
- - [x] Install dependencies
164
- - [x] Create components
165
- - [ ] Test application
166
- </task_progress>
167
- </${AgentDefaultTool.FILE_NEW}>`
168
- },
169
- {
170
- name: AgentDefaultTool.FILE_DELETE,
171
- description: "Delete a file.",
172
- params: {
173
- path: "(required) The path of the file to delete to (relative to the current working directory ${context.cwd}) Use @workspace:path syntax (e.g., @frontend:src/index.ts) to specify a workspace.",
174
- },
175
- },
176
- {
177
- name: AgentDefaultTool.DIR_DELETE,
178
- description: "Delete a directory.",
179
- params: {
180
- path: "(required) The path of the directory to delete to (relative to the current working directory ${context.cwd}) Use @workspace:path syntax (e.g., @frontend:src/index.ts) to specify a workspace.",
181
- },
182
- },
183
- {
184
- name: AgentDefaultTool.SEARCH,
185
- description: "Search for files in a directory that match a regex pattern or glob pattern.",
186
- params: {
187
- path: "(required) The absolute or relative directory path to search.",
188
- regex: "(required) The regex pattern to match files against.",
189
- file_pattern: "(optional) glob pattern like *.ts.",
190
- },
191
- },
192
- {
193
- name: AgentDefaultTool.LIST_FILES,
194
- description: "List all files in a directory.",
195
- params: {
196
- path: "(required) The absolute or relative directory path to list.",
197
- },
198
- },
199
- //================
200
- {
201
- name: AgentDefaultTool.NEW_TASK,
202
- description: "Create a new task with a given context.",
203
- params: {
204
- context: "(required) The context of the new task.",
205
- },
206
- example: `## Example: Creating a new task
207
- <${AgentDefaultTool.NEW_TASK}>
208
- <context>
209
- 1. Current Work:
210
- [Detailed description]
211
-
212
- 2. Key Technical Concepts:
213
- - [Concept 1]
214
- - [Concept 2]
215
- - [...]
216
-
217
- 3. Relevant Files and Code:
218
- - [File Name 1]
219
- - [Summary of why this file is important]
220
- - [Summary of the changes made to this file, if any]
221
- - [Important Code Snippet]
222
- - [File Name 2]
223
- - [Important Code Snippet]
224
- - [...]
225
-
226
- 4. Problem Solving:
227
- [Detailed description]
228
-
229
- 5. Pending Tasks and Next Steps:
230
- - [Task 1 details & next steps]
231
- - [Task 2 details & next steps]
232
- - [...]
233
- </context>
234
- </${AgentDefaultTool.NEW_TASK}>`,
235
- },
236
- {
237
- name: AgentDefaultTool.LOAD_SKILL,
238
- description: "Load a skill to perform a task. important: skill_name is required. must use this tool to load the skill; do not use any other method to read it.",
239
- params: {
240
- skill_name: "(required) The name of the skill to load.",
241
- },
242
- },
243
- ] as const;
244
-
245
- export const toolUseNames = Object.values(AgentDefaultTool) as AgentDefaultTool[];
246
-
247
- const dynamicToolUseNamesByNamespace = new Map<string, Set<string>>();
248
-
249
- export function setDynamicToolUseNames(namespace: string, names: string[]): void {
250
- dynamicToolUseNamesByNamespace.set(namespace, new Set(names.map((name) => name.trim()).filter(Boolean)));
251
- }
252
-
253
- export function getToolUseNames(): string[] {
254
- const defaults = [...toolUseNames];
255
- const dynamic = Array.from(dynamicToolUseNamesByNamespace.values()).flatMap((set) => Array.from(set));
256
- return Array.from(new Set([...defaults, ...dynamic]));
257
- }
258
-
259
- export const READ_ONLY_TOOLS = [
260
- AgentDefaultTool.LIST_FILES,
261
- AgentDefaultTool.FILE_READ,
262
- AgentDefaultTool.SEARCH,
263
- AgentDefaultTool.LIST_CODE_DEF,
264
- AgentDefaultTool.BROWSER,
265
- AgentDefaultTool.ASK,
266
- AgentDefaultTool.WEB_SEARCH,
267
- AgentDefaultTool.WEB_FETCH,
268
- AgentDefaultTool.LOAD_SKILL,
269
- AgentDefaultTool.USE_SUBAGENTS,
270
- ] as const;
@@ -1,113 +0,0 @@
1
- import { createNodeAgent, AgentDefaultTool } from "./src/runtime/nodeRuntime";
2
- import {webSearch} from './webSearch';
3
- import {webFetch} from './webFetch';
4
-
5
- async function main() {
6
- console.log("Initializing Node Agent...");
7
-
8
- // 请注意:在实际运行中,需要将 apiKey 替换为真实可用的密钥,
9
- // 或在运行命令时通过环境变量传入,例如: OPENAI_API_KEY="sk-xxx" tsx test-node-agent.ts
10
- // const apiKey = process.env.OPENAI_API_KEY || "YOUR_API_KEY_HERE";
11
-
12
- // 初始化 Agent
13
- const agent = createNodeAgent({
14
- apiConfig: {
15
- providerId: "dify",
16
- modelId: "115a5bb0-4a9c-409e-8652-26898ee00aa0", // 这里替换为你实际使用的模型
17
- apiKey: 'app-oPDCCXHA2lxKZOqn38WlqjOp',
18
- baseURL: 'http://api.aiagentv1.mama.cn/v1', // 如果有代理地址可以在此设置
19
- headers: {
20
- ['user-id']: 'agent-user'
21
- }
22
- },
23
- allowDefaultTools: [
24
- AgentDefaultTool.ATTEMPT,
25
- AgentDefaultTool.BASH,
26
- AgentDefaultTool.FILE_EDIT,
27
- AgentDefaultTool.FILE_READ,
28
- AgentDefaultTool.FILE_NEW,
29
- AgentDefaultTool.SEARCH,
30
- AgentDefaultTool.LIST_FILES,
31
- AgentDefaultTool.NEW_TASK,
32
- AgentDefaultTool.LOAD_SKILL,
33
- ],
34
- customInstructions: "你是一个专业的内容策划与创作引擎,服务于自媒体从业者。你的目标是帮助用户将一个主题或素材转化为适配特定平台、能够打动读者的完整内容。",
35
- customTools: [
36
- {
37
- name: 'web_search',
38
- description: 'useful when you want to search the web',
39
- params: {
40
- // 搜索查询,查询关键词,小于 15 个字符
41
- query: '(required) search query to use web search tool, less than 15 characters',
42
- },
43
- onCall: async (params: any) => {
44
- try {
45
- const res = await webSearch(params.query);
46
- return JSON.stringify(res);
47
- } catch (error: any) {
48
- return `Error searching the web: ${error.message}`;
49
- }
50
- },
51
- },
52
- {
53
- name: 'web_fetch',
54
- // 从指定 URL 获取网页内容
55
- description: 'useful when you want to fetch the content of a web page',
56
- params: {
57
- url: '(required) url to fetch the content of',
58
- },
59
- onCall: async (params: any) => {
60
- try {
61
- const res = await webFetch(params.url);
62
- return JSON.stringify(res);
63
- } catch (error: any) {
64
- return `Error fetching the web page: ${error.message}`;
65
- }
66
- },
67
- },
68
- {
69
- name: "article_write",
70
- description: "Write an article based on the given content.",
71
- params: {
72
- content: '(required) string, the article content to write.',
73
- },
74
- onCall: (params: any) => {
75
- console.log(`Custom tool "article_write" called with params: ${JSON.stringify(params)}`);
76
- return `Success!`;
77
- }
78
- },
79
- ]
80
- });
81
-
82
- // 监听状态变化
83
- agent.onStateChange = (state) => {
84
- console.log(`\n[Agent State]: ${state}`);
85
- };
86
-
87
- // 监听流式输出
88
- process.stdout.write("[Agent]: ");
89
- agent.onStreamChunk = (chunk) => {
90
- if (chunk.type === "text" && chunk.text) {
91
- process.stdout.write(chunk.text);
92
- } else if (chunk.type === "usage") {
93
- console.log(`\n[Usage]: Input: ${chunk.usage?.inputTokens}, Output: ${chunk.usage?.outputTokens}`);
94
- } else if (chunk.type === "error") {
95
- console.error(`\n[Error]: ${chunk.error?.message}`);
96
- }
97
- };
98
-
99
- // 定义一个简单的测试任务
100
- const task = "web_search 搜索分析后,web_fetch 获取到详细内容后,写一篇腾讯2026中报的主要内容,1000字左右的文章,写到 test.md 文件中";
101
-
102
- console.log(`\n[Task]: ${task}\n`);
103
-
104
- try {
105
- // 启动任务
106
- await agent.startTask(task);
107
- console.log("\nTask completed successfully!");
108
- } catch (error) {
109
- console.error("\nTask failed with error:", error);
110
- }
111
- }
112
-
113
- main().catch(console.error);
package/test-runtime.mjs DELETED
@@ -1,36 +0,0 @@
1
- import { NodeRuntime } from './dist/runtime/node.mjs';
2
- import { WebRuntime } from './dist/runtime/web.mjs';
3
- import { NodePromptManager, WebPromptManager } from './dist/index.mjs';
4
-
5
- async function run() {
6
- console.log("=== Testing NodeRuntime & Prompt ===");
7
- const nodeRuntime = new NodeRuntime();
8
- const nodeCwd = nodeRuntime.env.cwd();
9
- console.log("Node CWD:", nodeCwd);
10
- const result = await nodeRuntime.terminal.execCommand("echo hello node");
11
- console.log("Node Exec:", result.stdout.trim());
12
-
13
- const nodePrompt = new NodePromptManager("Always output JSON.");
14
- const nodeSystemPrompt = await nodePrompt.getSystemPrompt({ cwd: nodeCwd, os: nodeRuntime.env.osInfo() });
15
- console.log("Node Prompt:\n", nodeSystemPrompt.substring(0, 150) + "...\n");
16
-
17
- console.log("\n=== Testing WebRuntime & Prompt ===");
18
- const webRuntime = new WebRuntime();
19
- const webCwd = webRuntime.env.cwd();
20
- console.log("Web CWD:", webCwd);
21
-
22
- await webRuntime.fs.writeFile("/workspace/test.txt", "hello web");
23
- const exists = await webRuntime.fs.fileExists("/workspace/test.txt");
24
- console.log("Web File Exists:", exists);
25
- const content = await webRuntime.fs.readFile("/workspace/test.txt");
26
- console.log("Web File Content:", content);
27
-
28
- const webExec = await webRuntime.terminal.execCommand("echo hello");
29
- console.log("Web Exec:", webExec.stdout.trim());
30
-
31
- const webPrompt = new WebPromptManager();
32
- const webSystemPrompt = await webPrompt.getSystemPrompt({ cwd: webCwd, os: webRuntime.env.osInfo() });
33
- console.log("Web Prompt:\n", webSystemPrompt.substring(0, 150) + "...\n");
34
- }
35
-
36
- run().catch(console.error);
package/test.md DELETED
@@ -1,33 +0,0 @@
1
- # 腾讯2026中报解读:营收净利双增10%,自由现金流为何罕见转负?
2
-
3
- 8月12日,腾讯控股发布了2026年半年度业绩报告。这份中报既延续了稳健增长的底色,也透露出一个强烈的信号——腾讯正在经历一场由AI驱动的战略重构。
4
-
5
- ## 一、基本面:稳步增长的"基本盘"
6
-
7
- 先看核心财务数据。2026年上半年,腾讯实现营收4012.43亿元,同比增长10%;净利润1141.15亿元,同样增长10%。分季度看,第二季度营收2048亿元,同比增长11%;Non-IFRS经营盈利756亿元,同比增长9%;Non-IFRS归母净利润684亿元,同比增长9%。
8
-
9
- 盈利能力持续改善。二季度毛利同比增长13%至1184亿元,毛利率由去年同期的57%提升至58%。增值服务、营销服务、金融科技及企业服务三大板块毛利率全线站稳高位,分别达64%、57%和52%。
10
-
11
- ## 二、业务板块:游戏与广告双引擎发力
12
-
13
- 游戏业务表现尤为亮眼。二季度本土市场游戏收入473亿元,同比增长17%,《三角洲行动》《无畏契约》《洛克王国:世界》等多款产品贡献显著。国际市场游戏收入186亿元,按固定汇率计算同比增长4%。增值服务整体收入984亿元,同比增长8%。
14
-
15
- 营销服务是本季度最大亮点,收入同比增长22%至436亿元。这得益于AI驱动的广告推荐模型持续优化,以及微信生态闭环营销能力的整合。金融科技及企业服务收入603亿元,同比增长9%,其中云服务受AI相关需求上升和国际市场拓展推动,增长势头良好。
16
-
17
- ## 三、AI战略:马化腾的"三个层面"
18
-
19
- 马化腾在业绩报告中罕见地用较长篇幅阐述了AI战略:**"我们正在智能、应用与基础设施三个层面,构建一个全新的、AI赋能的腾讯。"**
20
-
21
- 智能层面,混元Hy3正式版发布,在智能体、代码、复杂推理等能力上大幅提升,token消耗量稳居全球前三。应用层面,AI办公助手WorkBuddy PC端6月访问量突破2000万,位居国内同类产品第一;AI编程工具CodeBuddy同样实现突破性增长。基础设施层面,腾讯大幅增加算力采购,为AI商业化铺设硬件底座。
22
-
23
- ## 四、争议焦点:自由现金流为何-138亿?
24
-
25
- 这份财报最受市场关注的一个数字,是**二季度自由现金流为-138亿元**。这是腾讯上市22年来首次出现单季自由现金流转负,对一家以"现金流充沛、高额回购分红"著称的巨头而言,冲击不小。
26
-
27
- 原因清晰:二季度资本开支高达528亿元,同比增长176%,主要用于AI算力基础设施采购;同时叠加2025年度股息支付416亿元。不过,若剔除算力采购预付等一次性因素,自由现金流实际为正的376亿元。研发投入同比增长35%至273亿元,也印证了腾讯"重投入、慢回报"的AI转型决心。
28
-
29
- ## 五、结语:从"连接一切"到"智能驱动一切"
30
-
31
- 腾讯2026年中报传递出的信号很明确:短期利润增长放缓(二季度归母净利仅增0.7%),是主动为AI战略让路的结果。当WorkBuddy已在50多个行业落地、Hy3调用量跻身全球前三、资本开支同比近乎翻两倍时,腾讯正从一家互联网平台公司,加速进化为AI基础设施与智能应用生态的核心玩家。这份中报,或许正是腾讯"AI再造"的起点。
32
-
33
- *(数据来源:腾讯控股2026年半年度业绩公告及相关新闻稿件)*
package/tsconfig.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "Bundler",
6
- "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
- "strict": true,
8
- "skipLibCheck": true,
9
- "esModuleInterop": true,
10
- "allowSyntheticDefaultImports": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "isolatedModules": true,
13
- "declaration": true,
14
- "declarationMap": true,
15
- "outDir": "dist",
16
- "resolveJsonModule": true,
17
- "baseUrl": ".",
18
- "paths": {
19
- "@/*": ["src/*"],
20
- "@utils/*": ["src/utils/*"],
21
- "@shared/*": ["src/shared/*"],
22
- "@core/*": ["src/core/*"],
23
- "@services/*": ["src/services/*"]
24
- }
25
- },
26
- "include": ["src/**/*"],
27
- "exclude": ["node_modules", "dist"]
28
- }
package/tsup.config.ts DELETED
@@ -1,21 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- export default defineConfig({
4
- entry: [
5
- 'src/index.ts',
6
- 'src/runtime/node.ts',
7
- 'src/runtime/web.ts'
8
- ],
9
- format: ['cjs', 'esm'],
10
- dts: true,
11
- splitting: false,
12
- sourcemap: true,
13
- clean: true,
14
- treeshake: true,
15
- minify: false,
16
- outExtension({ format }) {
17
- return {
18
- js: format === 'cjs' ? '.js' : '.mjs',
19
- };
20
- },
21
- });
package/uapi.ts DELETED
@@ -1,3 +0,0 @@
1
- import { UapiClient } from 'uapi-sdk-typescript'
2
-
3
- export const uapiClient = new UapiClient('https://uapis.cn', process.env.UAPI_KEY)
package/webFetch.ts DELETED
@@ -1,49 +0,0 @@
1
- import { uapiClient } from './uapi';
2
-
3
- // export async function webFetch(url: string) {
4
- // return fetch('https://cloud-iqs.aliyuncs.com/readpage/basic', {
5
- // method: 'POST',
6
- // headers: {
7
- // 'Content-Type': 'application/json',
8
- // 'Authorization': 'Bearer ' + process.env.IQS_SEARCH_KEY,
9
- // },
10
- // body: JSON.stringify({
11
- // url,
12
- // "maxAge":0,"formats":["html","markdown","text"]
13
- // }),
14
- // })
15
- // }
16
-
17
- export async function webFetch(url: string) {
18
- let resolve: any, reject: any;
19
- const promise = new Promise((resol, reje) => {
20
- resolve = resol
21
- reject = reje
22
- });
23
- try {
24
- const res = await uapiClient.webparse.postWebTomarkdownAsync({url});
25
- let setTimeoutTimer: any;
26
- const checkStatus = async (taskId: string) => {
27
- const checkRes = await uapiClient.webparse.getWebTomarkdownAsyncStatus({taskId: res.task_id!, task_id: res.task_id!});
28
- if (checkRes.status === 'pending' || checkRes.status === 'queued' || checkRes.status === 'running') {
29
- setTimeoutTimer = setTimeout(() => {
30
- checkStatus(taskId);
31
- }, 1000);
32
- } else if (checkRes.status === 'completed' && checkRes.result) {
33
- resolve(checkRes.result);
34
- } else {
35
- reject(new Error('fetch Error'));
36
- }
37
- }
38
-
39
- if (res.task_id) {
40
- await checkStatus(res.task_id);
41
- } else {
42
- reject(new Error('fetch Error'));
43
- }
44
- } catch (error) {
45
- reject(error);
46
- }
47
-
48
- return promise;
49
- }
package/webSearch.ts DELETED
@@ -1,19 +0,0 @@
1
- import { uapiClient } from './uapi';
2
-
3
- // export async function webSearch(query: string) {
4
- // return fetch('https://cloud-iqs.aliyuncs.com/search/unified', {
5
- // method: 'POST',
6
- // headers: {
7
- // 'Content-Type': 'application/json',
8
- // 'Authorization': 'Bearer ' + process.env.IQS_SEARCH_KEY,
9
- // },
10
- // body: JSON.stringify({
11
- // query,
12
- // "engineType": "Generic", "numResults": 20, "contents": { "mainText": false, "markdownText": false, "richMainBody": false, "summary": true, "rerankScore": true }
13
- // }),
14
- // })
15
- // }
16
-
17
- export async function webSearch(query: string, site?: string, sort?: string) {
18
- return uapiClient.zhiNengSouSuo.postSearchAggregate({query, site, sort});
19
- }