@agentscope-ai/agentscope 0.0.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.
- package/dist/agent/index.d.mts +234 -0
- package/dist/agent/index.d.ts +234 -0
- package/dist/agent/index.js +1412 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/index.mjs +1375 -0
- package/dist/agent/index.mjs.map +1 -0
- package/dist/base-BOx3UzOl.d.mts +41 -0
- package/dist/base-BoIps2RL.d.ts +41 -0
- package/dist/base-C7jwyH4Z.d.mts +52 -0
- package/dist/base-Cwi4bjze.d.ts +127 -0
- package/dist/base-DYlBMCy_.d.mts +127 -0
- package/dist/base-NX-knWOv.d.ts +52 -0
- package/dist/block-VsnHrllL.d.mts +48 -0
- package/dist/block-VsnHrllL.d.ts +48 -0
- package/dist/event/index.d.mts +181 -0
- package/dist/event/index.d.ts +181 -0
- package/dist/event/index.js +58 -0
- package/dist/event/index.js.map +1 -0
- package/dist/event/index.mjs +33 -0
- package/dist/event/index.mjs.map +1 -0
- package/dist/formatter/index.d.mts +187 -0
- package/dist/formatter/index.d.ts +187 -0
- package/dist/formatter/index.js +647 -0
- package/dist/formatter/index.js.map +1 -0
- package/dist/formatter/index.mjs +616 -0
- package/dist/formatter/index.mjs.map +1 -0
- package/dist/index-BTJDlKvQ.d.mts +195 -0
- package/dist/index-BcatlwXQ.d.ts +195 -0
- package/dist/index-CAxQAkiP.d.mts +21 -0
- package/dist/index-CAxQAkiP.d.ts +21 -0
- package/dist/mcp/index.d.mts +9 -0
- package/dist/mcp/index.d.ts +9 -0
- package/dist/mcp/index.js +432 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/index.mjs +408 -0
- package/dist/mcp/index.mjs.map +1 -0
- package/dist/message/index.d.mts +10 -0
- package/dist/message/index.d.ts +10 -0
- package/dist/message/index.js +67 -0
- package/dist/message/index.js.map +1 -0
- package/dist/message/index.mjs +37 -0
- package/dist/message/index.mjs.map +1 -0
- package/dist/message-CkN21KaY.d.mts +99 -0
- package/dist/message-CzLeTlua.d.ts +99 -0
- package/dist/model/index.d.mts +377 -0
- package/dist/model/index.d.ts +377 -0
- package/dist/model/index.js +1880 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/index.mjs +1849 -0
- package/dist/model/index.mjs.map +1 -0
- package/dist/storage/index.d.mts +68 -0
- package/dist/storage/index.d.ts +68 -0
- package/dist/storage/index.js +250 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/index.mjs +212 -0
- package/dist/storage/index.mjs.map +1 -0
- package/dist/tool/index.d.mts +311 -0
- package/dist/tool/index.d.ts +311 -0
- package/dist/tool/index.js +1494 -0
- package/dist/tool/index.js.map +1 -0
- package/dist/tool/index.mjs +1447 -0
- package/dist/tool/index.mjs.map +1 -0
- package/dist/toolkit-CEpulFi0.d.ts +99 -0
- package/dist/toolkit-CGEZSZPa.d.mts +99 -0
- package/jest.config.js +11 -0
- package/package.json +92 -0
- package/src/_utils/common.ts +104 -0
- package/src/_utils/index.ts +1 -0
- package/src/agent/agent-base.ts +0 -0
- package/src/agent/agent.test.ts +1028 -0
- package/src/agent/agent.ts +1032 -0
- package/src/agent/index.ts +2 -0
- package/src/agent/interfaces.ts +23 -0
- package/src/agent/test-compression.ts +72 -0
- package/src/event/index.ts +250 -0
- package/src/formatter/base.ts +133 -0
- package/src/formatter/dashscope-chat-formatter.test.ts +372 -0
- package/src/formatter/dashscope-chat-formatter.ts +163 -0
- package/src/formatter/deepseek-chat-formatter.ts +130 -0
- package/src/formatter/index.ts +5 -0
- package/src/formatter/ollama-chat-formatter.ts +67 -0
- package/src/formatter/openai-chat-formatter.test.ts +263 -0
- package/src/formatter/openai-chat-formatter.ts +301 -0
- package/src/formatter/openai.md +767 -0
- package/src/mcp/base.ts +114 -0
- package/src/mcp/http.test.ts +303 -0
- package/src/mcp/http.ts +224 -0
- package/src/mcp/index.ts +2 -0
- package/src/mcp/stdio.test.ts +91 -0
- package/src/mcp/stdio.ts +119 -0
- package/src/message/block.ts +60 -0
- package/src/message/enums.ts +4 -0
- package/src/message/index.ts +12 -0
- package/src/message/message.test.ts +80 -0
- package/src/message/message.ts +131 -0
- package/src/model/base.ts +226 -0
- package/src/model/dashscope-model.test.ts +335 -0
- package/src/model/dashscope-model.ts +441 -0
- package/src/model/deepseek-model.test.ts +279 -0
- package/src/model/deepseek-model.ts +401 -0
- package/src/model/index.ts +7 -0
- package/src/model/ollama-model.test.ts +307 -0
- package/src/model/ollama-model.ts +356 -0
- package/src/model/openai-model.ts +327 -0
- package/src/model/response.ts +22 -0
- package/src/model/usage.ts +12 -0
- package/src/storage/base.ts +52 -0
- package/src/storage/file-system.test.ts +587 -0
- package/src/storage/file-system.ts +269 -0
- package/src/storage/index.ts +2 -0
- package/src/tool/base.ts +23 -0
- package/src/tool/bash.test.ts +174 -0
- package/src/tool/bash.ts +152 -0
- package/src/tool/edit.test.ts +83 -0
- package/src/tool/edit.ts +95 -0
- package/src/tool/glob.test.ts +63 -0
- package/src/tool/glob.ts +166 -0
- package/src/tool/grep.test.ts +74 -0
- package/src/tool/grep.ts +256 -0
- package/src/tool/index.ts +10 -0
- package/src/tool/read.test.ts +77 -0
- package/src/tool/read.ts +117 -0
- package/src/tool/response.ts +82 -0
- package/src/tool/task.test.ts +299 -0
- package/src/tool/task.ts +399 -0
- package/src/tool/toolkit.test.ts +636 -0
- package/src/tool/toolkit.ts +601 -0
- package/src/tool/write.test.ts +52 -0
- package/src/tool/write.ts +57 -0
- package/src/type/index.ts +52 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.cjs.json +11 -0
- package/tsconfig.esm.json +10 -0
- package/tsconfig.json +14 -0
- package/tsup.config.ts +20 -0
- package/typedoc.json +52 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { jsonrepair } from 'jsonrepair';
|
|
2
|
+
|
|
3
|
+
import { JSONSerializableObject } from '../type';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a timestamp string in the format "YYYY-MM-DD HH:mm:ss.sss"
|
|
7
|
+
* representing the current date and time.
|
|
8
|
+
*
|
|
9
|
+
* @returns {string} The formatted timestamp string.
|
|
10
|
+
*/
|
|
11
|
+
export function _createTimestamp(): string {
|
|
12
|
+
return new Date().toISOString().replace('T', ' ').replace('Z', '').substring(0, 23);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Attempts to parse a JSON string into a dictionary/Record.
|
|
17
|
+
* This function is used to handle the streaming tool use block from the LLM API.
|
|
18
|
+
*
|
|
19
|
+
* @param input - The JSON string to parse.
|
|
20
|
+
* @returns A dictionary/Record parsed from the JSON string. If parsing fails, returns an empty dictionary.
|
|
21
|
+
*/
|
|
22
|
+
export function _jsonLoadsWithRepair(input: string): Record<string, JSONSerializableObject> {
|
|
23
|
+
try {
|
|
24
|
+
const jsonObj = JSON.parse(input);
|
|
25
|
+
// Check if the jsonObj is a dictionary/Record
|
|
26
|
+
if (typeof jsonObj === 'object' && jsonObj !== null && !Array.isArray(jsonObj)) {
|
|
27
|
+
return jsonObj as Record<string, JSONSerializableObject>;
|
|
28
|
+
} else {
|
|
29
|
+
// Return an empty dictionary
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
} catch {
|
|
33
|
+
try {
|
|
34
|
+
const repairedString = jsonrepair(input);
|
|
35
|
+
const jsonObj = JSON.parse(repairedString);
|
|
36
|
+
// Check if the jsonObj is a dictionary/Record
|
|
37
|
+
if (typeof jsonObj === 'object' && jsonObj !== null && !Array.isArray(jsonObj)) {
|
|
38
|
+
return jsonObj as Record<string, JSONSerializableObject>;
|
|
39
|
+
} else {
|
|
40
|
+
// Return an empty dictionary
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
} catch (e) {
|
|
44
|
+
console.error(`Failed to parse JSON "${input}" with error:`, e);
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Parses a streamed response from the post request.
|
|
52
|
+
* An async generator that yields parsed JSON objects from the SSE stream.
|
|
53
|
+
*
|
|
54
|
+
* @param response - The fetch response object.
|
|
55
|
+
* @returns An async generator yielding parsed JSON objects.
|
|
56
|
+
*/
|
|
57
|
+
export async function* _parseStreamedResponse<T>(response: Response): AsyncGenerator<T> {
|
|
58
|
+
const reader = response.body?.getReader();
|
|
59
|
+
if (!reader) {
|
|
60
|
+
throw new Error('Failed to get reader from response body for streaming.');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const decoder = new TextDecoder();
|
|
64
|
+
let buffer = '';
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
while (true) {
|
|
68
|
+
const { done, value } = await reader.read();
|
|
69
|
+
|
|
70
|
+
if (done) break;
|
|
71
|
+
|
|
72
|
+
buffer += decoder.decode(value, { stream: true });
|
|
73
|
+
|
|
74
|
+
// Handle the completed line
|
|
75
|
+
const lines = buffer.split('\n');
|
|
76
|
+
buffer = lines.pop() || ''; // Keep the last uncompleted line
|
|
77
|
+
|
|
78
|
+
for (const line of lines) {
|
|
79
|
+
const trimmedLine = line.trim();
|
|
80
|
+
if (!trimmedLine || trimmedLine.startsWith(':')) {
|
|
81
|
+
continue; // Skip the empty line and comments
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (trimmedLine.startsWith('data:')) {
|
|
85
|
+
const jsonStr = trimmedLine.slice(5).trim(); // Remove "data:" prefix
|
|
86
|
+
|
|
87
|
+
if (jsonStr === '[DONE]') {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const json = JSON.parse(jsonStr);
|
|
93
|
+
yield json;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
console.error('Failed to parse JSON:', e);
|
|
96
|
+
throw new Error(`Failed to parse JSON from stream: ${jsonStr}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} finally {
|
|
102
|
+
reader.releaseLock();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './common';
|
|
File without changes
|