@ai-zen/agents-sdk 0.4.0 → 0.5.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/CHANGELOG.md +21 -0
- package/README.md +19 -15
- package/dist/capabilities/discovery/builtin.d.ts +7 -6
- package/dist/capabilities/discovery/builtin.js +10 -9
- package/dist/capabilities/implements/builtin/BatchEditTool.d.ts +15 -0
- package/dist/capabilities/implements/builtin/BatchEditTool.js +82 -0
- package/dist/capabilities/implements/builtin/CopyTool.d.ts +10 -0
- package/dist/capabilities/implements/builtin/CopyTool.js +43 -0
- package/dist/capabilities/implements/builtin/CwdTool.d.ts +6 -0
- package/dist/capabilities/implements/builtin/CwdTool.js +20 -0
- package/dist/capabilities/implements/builtin/DownloadFileTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/{downloadFile.js → DownloadFileTool.js} +29 -24
- package/dist/capabilities/implements/builtin/EditTool.d.ts +11 -0
- package/dist/capabilities/implements/builtin/EditTool.js +84 -0
- package/dist/capabilities/implements/builtin/ExecAsyncTool.d.ts +10 -0
- package/dist/capabilities/implements/builtin/{execAsync.js → ExecAsyncTool.js} +32 -34
- package/dist/capabilities/implements/builtin/ExecTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/ExecTool.js +46 -0
- package/dist/capabilities/implements/builtin/ExistTool.d.ts +8 -0
- package/dist/capabilities/implements/builtin/ExistTool.js +30 -0
- package/dist/capabilities/implements/builtin/FindTextTool.d.ts +12 -0
- package/dist/capabilities/implements/builtin/{findText.js → FindTextTool.js} +43 -37
- package/dist/capabilities/implements/builtin/GenerateImageTool.d.ts +21 -0
- package/dist/capabilities/implements/builtin/GenerateImageTool.js +121 -0
- package/dist/capabilities/implements/builtin/GlobTool.d.ts +10 -0
- package/dist/capabilities/implements/builtin/GlobTool.js +51 -0
- package/dist/capabilities/implements/builtin/LsTool.d.ts +8 -0
- package/dist/capabilities/implements/builtin/LsTool.js +33 -0
- package/dist/capabilities/implements/builtin/MkdirTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/MkdirTool.js +39 -0
- package/dist/capabilities/implements/builtin/ReadFileTool.d.ts +8 -0
- package/dist/capabilities/implements/builtin/ReadFileTool.js +37 -0
- package/dist/capabilities/implements/builtin/RenameTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/RenameTool.js +37 -0
- package/dist/capabilities/implements/builtin/RmTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/RmTool.js +39 -0
- package/dist/capabilities/implements/builtin/SleepTool.d.ts +8 -0
- package/dist/capabilities/implements/builtin/SleepTool.js +46 -0
- package/dist/capabilities/implements/builtin/WriteFileTool.d.ts +9 -0
- package/dist/capabilities/implements/builtin/WriteFileTool.js +40 -0
- package/dist/capabilities/implements/builtin/index.d.ts +29 -21
- package/dist/capabilities/implements/builtin/index.js +44 -37
- package/dist/capabilities/implements/builtin/test-helpers.d.ts +3 -0
- package/dist/capabilities/implements/builtin/test-helpers.js +4 -0
- package/dist/index.d.ts +5 -9
- package/dist/index.js +6 -9
- package/dist/runtime/Provider.d.ts +9 -1
- package/dist/runtime/Provider.js +7 -1
- package/dist/runtime/SdkCallbackTool.d.ts +28 -0
- package/dist/runtime/SdkCallbackTool.js +33 -0
- package/dist/types/index.d.ts +12 -20
- package/package.json +1 -1
- package/dist/capabilities/implements/builtin/batchEdit.d.ts +0 -2
- package/dist/capabilities/implements/builtin/batchEdit.js +0 -76
- package/dist/capabilities/implements/builtin/copy.d.ts +0 -2
- package/dist/capabilities/implements/builtin/copy.js +0 -38
- package/dist/capabilities/implements/builtin/cwd.d.ts +0 -2
- package/dist/capabilities/implements/builtin/cwd.js +0 -15
- package/dist/capabilities/implements/builtin/downloadFile.d.ts +0 -2
- package/dist/capabilities/implements/builtin/edit.d.ts +0 -2
- package/dist/capabilities/implements/builtin/edit.js +0 -79
- package/dist/capabilities/implements/builtin/exec.d.ts +0 -2
- package/dist/capabilities/implements/builtin/exec.js +0 -38
- package/dist/capabilities/implements/builtin/execAsync.d.ts +0 -2
- package/dist/capabilities/implements/builtin/exist.d.ts +0 -2
- package/dist/capabilities/implements/builtin/exist.js +0 -25
- package/dist/capabilities/implements/builtin/findText.d.ts +0 -2
- package/dist/capabilities/implements/builtin/generateImage.d.ts +0 -9
- package/dist/capabilities/implements/builtin/generateImage.js +0 -112
- package/dist/capabilities/implements/builtin/glob.d.ts +0 -2
- package/dist/capabilities/implements/builtin/glob.js +0 -45
- package/dist/capabilities/implements/builtin/ls.d.ts +0 -2
- package/dist/capabilities/implements/builtin/ls.js +0 -28
- package/dist/capabilities/implements/builtin/mkdir.d.ts +0 -2
- package/dist/capabilities/implements/builtin/mkdir.js +0 -34
- package/dist/capabilities/implements/builtin/readFile.d.ts +0 -2
- package/dist/capabilities/implements/builtin/readFile.js +0 -31
- package/dist/capabilities/implements/builtin/rename.d.ts +0 -2
- package/dist/capabilities/implements/builtin/rename.js +0 -32
- package/dist/capabilities/implements/builtin/rm.d.ts +0 -2
- package/dist/capabilities/implements/builtin/rm.js +0 -34
- package/dist/capabilities/implements/builtin/sleep.d.ts +0 -2
- package/dist/capabilities/implements/builtin/sleep.js +0 -41
- package/dist/capabilities/implements/builtin/writeFile.d.ts +0 -2
- package/dist/capabilities/implements/builtin/writeFile.js +0 -34
- package/dist/crud/ConversationRepository.d.ts +0 -9
- package/dist/crud/ConversationRepository.js +0 -10
- package/dist/crud/DraftRepository.d.ts +0 -15
- package/dist/crud/DraftRepository.js +0 -52
- package/dist/plugin/AutoDraftPlugin.d.ts +0 -26
- package/dist/plugin/AutoDraftPlugin.js +0 -62
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Draft } from "../types/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Draft 仓储。
|
|
4
|
-
* Draft 没有 id 字段,文件名基于 conversationId:
|
|
5
|
-
* - 有 conversationId → ${conversationId}.json
|
|
6
|
-
* - 无 conversationId → _current.json
|
|
7
|
-
*/
|
|
8
|
-
export declare class DraftRepository {
|
|
9
|
-
private dir;
|
|
10
|
-
constructor(dir: string);
|
|
11
|
-
private path;
|
|
12
|
-
read(conversationId?: string): Promise<Draft | null>;
|
|
13
|
-
write(draft: Draft): Promise<void>;
|
|
14
|
-
delete(conversationId?: string): Promise<void>;
|
|
15
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
const CURRENT_DRAFT = "_current.json";
|
|
4
|
-
/**
|
|
5
|
-
* Draft 仓储。
|
|
6
|
-
* Draft 没有 id 字段,文件名基于 conversationId:
|
|
7
|
-
* - 有 conversationId → ${conversationId}.json
|
|
8
|
-
* - 无 conversationId → _current.json
|
|
9
|
-
*/
|
|
10
|
-
export class DraftRepository {
|
|
11
|
-
dir;
|
|
12
|
-
constructor(dir) {
|
|
13
|
-
this.dir = dir;
|
|
14
|
-
}
|
|
15
|
-
path(conversationId) {
|
|
16
|
-
return join(this.dir, conversationId ? `${conversationId}.json` : CURRENT_DRAFT);
|
|
17
|
-
}
|
|
18
|
-
async read(conversationId) {
|
|
19
|
-
const p = this.path(conversationId);
|
|
20
|
-
try {
|
|
21
|
-
await fs.access(p);
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
return JSON.parse(await fs.readFile(p, "utf-8"));
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async write(draft) {
|
|
34
|
-
try {
|
|
35
|
-
await fs.access(this.dir);
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
await fs.mkdir(this.dir, { recursive: true });
|
|
39
|
-
}
|
|
40
|
-
await fs.writeFile(this.path(draft.conversationId), JSON.stringify(draft, null, 2), "utf-8");
|
|
41
|
-
}
|
|
42
|
-
async delete(conversationId) {
|
|
43
|
-
const p = this.path(conversationId);
|
|
44
|
-
try {
|
|
45
|
-
await fs.access(p);
|
|
46
|
-
await fs.unlink(p);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
// 文件不存在,忽略
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Draft } from "../types/index.js";
|
|
2
|
-
import type { AgentPlugin, SendContext } from "../runtime/SdkAgent.js";
|
|
3
|
-
export interface AutoDraftOptions {
|
|
4
|
-
draftsDir: string;
|
|
5
|
-
agentId: string;
|
|
6
|
-
modelId: string;
|
|
7
|
-
conversationId?: string;
|
|
8
|
-
cwd?: string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* 自动保存 Draft 插件。
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* agent.use(new AutoDraftPlugin({
|
|
15
|
-
* draftsDir: "/path/to/drafts",
|
|
16
|
-
* agentId: "my-agent",
|
|
17
|
-
* modelId: "gpt-4",
|
|
18
|
-
* }));
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare class AutoDraftPlugin implements AgentPlugin {
|
|
22
|
-
private options;
|
|
23
|
-
constructor(options: AutoDraftOptions);
|
|
24
|
-
onInnerLoopEnd(ctx: SendContext): Promise<void>;
|
|
25
|
-
static checkDraftForRestore(draftsDir: string): Promise<Draft | null>;
|
|
26
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { DraftRepository } from "../crud/DraftRepository.js";
|
|
2
|
-
import { getLogger } from "../shared/logger.js";
|
|
3
|
-
import { promises as fs } from "node:fs";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import dayjs from "dayjs";
|
|
6
|
-
const log = getLogger();
|
|
7
|
-
const CURRENT_DRAFT = "_current.json";
|
|
8
|
-
const EXPIRE_DAYS = 7;
|
|
9
|
-
/**
|
|
10
|
-
* 自动保存 Draft 插件。
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* agent.use(new AutoDraftPlugin({
|
|
14
|
-
* draftsDir: "/path/to/drafts",
|
|
15
|
-
* agentId: "my-agent",
|
|
16
|
-
* modelId: "gpt-4",
|
|
17
|
-
* }));
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export class AutoDraftPlugin {
|
|
21
|
-
options;
|
|
22
|
-
constructor(options) {
|
|
23
|
-
this.options = options;
|
|
24
|
-
}
|
|
25
|
-
async onInnerLoopEnd(ctx) {
|
|
26
|
-
const { draftsDir, agentId, modelId, conversationId, cwd } = this.options;
|
|
27
|
-
try {
|
|
28
|
-
const draft = {
|
|
29
|
-
conversationId,
|
|
30
|
-
agentId,
|
|
31
|
-
modelId,
|
|
32
|
-
messages: ctx.agent.messages,
|
|
33
|
-
cwd,
|
|
34
|
-
updatedAt: new Date().toISOString(),
|
|
35
|
-
};
|
|
36
|
-
const repo = new DraftRepository(draftsDir);
|
|
37
|
-
await repo.write(draft);
|
|
38
|
-
}
|
|
39
|
-
catch (err) {
|
|
40
|
-
log.error(`[autoDraft] 保存失败: ${err?.message ?? err}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
static async checkDraftForRestore(draftsDir) {
|
|
44
|
-
const path = join(draftsDir, CURRENT_DRAFT);
|
|
45
|
-
try {
|
|
46
|
-
await fs.access(path);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
const repo = new DraftRepository(draftsDir);
|
|
52
|
-
const draft = await repo.read();
|
|
53
|
-
if (!draft)
|
|
54
|
-
return null;
|
|
55
|
-
const age = dayjs().diff(dayjs(draft.updatedAt), "day");
|
|
56
|
-
if (age > EXPIRE_DAYS) {
|
|
57
|
-
await repo.delete();
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
return draft;
|
|
61
|
-
}
|
|
62
|
-
}
|