@plolink/sdk 0.0.10 → 0.0.11
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 +82 -0
- package/dist/modules/llm/index.cjs +105 -0
- package/dist/modules/llm/index.cjs.map +1 -0
- package/dist/modules/llm/index.d.cts +179 -0
- package/dist/modules/llm/index.d.ts +179 -0
- package/dist/modules/llm/index.js +103 -0
- package/dist/modules/llm/index.js.map +1 -0
- package/dist/modules/preset-agent-task/index.cjs +360 -0
- package/dist/modules/preset-agent-task/index.cjs.map +1 -0
- package/dist/modules/preset-agent-task/index.d.cts +736 -0
- package/dist/modules/preset-agent-task/index.d.ts +736 -0
- package/dist/modules/preset-agent-task/index.js +358 -0
- package/dist/modules/preset-agent-task/index.js.map +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// src/modules/preset-agent-task/index.ts
|
|
2
|
+
var PresetAgentTask = class {
|
|
3
|
+
constructor(client) {
|
|
4
|
+
this.baseUrl = "/api/v1/preset-agent-tasks";
|
|
5
|
+
this.client = client;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 创建预设
|
|
9
|
+
*
|
|
10
|
+
* @param params - 创建参数
|
|
11
|
+
* @returns 预设ID和code
|
|
12
|
+
* @throws {PlolinkError} 当参数无效或创建失败时抛出
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const result = await presetAgentTask.create({
|
|
17
|
+
* code: 'talent-resume-parse',
|
|
18
|
+
* name: '简历解析预设',
|
|
19
|
+
* description: '自动解析简历并提取关键信息',
|
|
20
|
+
* prompt: '请解析上传的简历文件,提取候选人的基本信息、教育背景、工作经历等关键数据',
|
|
21
|
+
* model: 'doubao-seed-1-6-lite-251015',
|
|
22
|
+
* selectedSkills: ['talent/resume-parse', 'common/file-extract'],
|
|
23
|
+
* timeoutMs: 1800000,
|
|
24
|
+
* businessKey: 'talent-resume-parse'
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* console.log('预设ID:', result.id);
|
|
28
|
+
* console.log('预设标识:', result.code);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
async create(params) {
|
|
32
|
+
return this.client.axiosInstance.post(this.baseUrl, params);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 获取预设列表
|
|
36
|
+
*
|
|
37
|
+
* @param options - 查询选项
|
|
38
|
+
* @returns 分页的预设列表
|
|
39
|
+
* @throws {PlolinkError} 当请求失败时抛出
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // 获取所有启用的预设
|
|
44
|
+
* const result = await presetAgentTask.list({
|
|
45
|
+
* enabled: true,
|
|
46
|
+
* page: 1,
|
|
47
|
+
* pageSize: 20
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* console.log('总数:', result.total);
|
|
51
|
+
* result.list.forEach(preset => {
|
|
52
|
+
* console.log(`${preset.code}: ${preset.name}`);
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async list(options) {
|
|
57
|
+
return this.client.axiosInstance.get(this.baseUrl, {
|
|
58
|
+
params: options
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 获取预设详情
|
|
63
|
+
*
|
|
64
|
+
* @param id - 预设ID
|
|
65
|
+
* @returns 预设详细信息
|
|
66
|
+
* @throws {PlolinkError} 当预设不存在时抛出
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const preset = await presetAgentTask.getById('clx_preset_123');
|
|
71
|
+
* console.log('预设名称:', preset.name);
|
|
72
|
+
* console.log('预设指令:', preset.prompt);
|
|
73
|
+
* console.log('AI模型:', preset.model);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
async getById(id) {
|
|
77
|
+
return this.client.axiosInstance.get(`${this.baseUrl}/${id}`);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 通过code获取预设
|
|
81
|
+
*
|
|
82
|
+
* @param code - 预设唯一标识
|
|
83
|
+
* @returns 预设详细信息
|
|
84
|
+
* @throws {PlolinkError} 当预设不存在时抛出
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const preset = await presetAgentTask.getByCode('talent-resume-parse');
|
|
89
|
+
* console.log('预设ID:', preset.id);
|
|
90
|
+
* console.log('预设名称:', preset.name);
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
async getByCode(code) {
|
|
94
|
+
const result = await this.list({ enabled: true, pageSize: 100 });
|
|
95
|
+
const preset = result.list.find((p) => p.code === code);
|
|
96
|
+
if (!preset) {
|
|
97
|
+
throw new Error(`Preset not found with code: ${code}`);
|
|
98
|
+
}
|
|
99
|
+
return this.getById(preset.id);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 更新预设
|
|
103
|
+
*
|
|
104
|
+
* @param id - 预设ID
|
|
105
|
+
* @param params - 更新参数
|
|
106
|
+
* @throws {PlolinkError} 当预设不存在或更新失败时抛出
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* await presetAgentTask.update('clx_preset_123', {
|
|
111
|
+
* name: '简历解析预设(更新)',
|
|
112
|
+
* enabled: false
|
|
113
|
+
* });
|
|
114
|
+
*
|
|
115
|
+
* console.log('预设更新成功');
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
async update(id, params) {
|
|
119
|
+
await this.client.axiosInstance.put(`${this.baseUrl}/${id}`, params);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 删除预设
|
|
123
|
+
*
|
|
124
|
+
* @param id - 预设ID
|
|
125
|
+
* @throws {PlolinkError} 当预设不存在或删除失败时抛出
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* await presetAgentTask.delete('clx_preset_123');
|
|
130
|
+
* console.log('预设删除成功');
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
async delete(id) {
|
|
134
|
+
await this.client.axiosInstance.delete(`${this.baseUrl}/${id}`);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 执行预设(核心方法)
|
|
138
|
+
*
|
|
139
|
+
* @description
|
|
140
|
+
* 通过预设code执行预设任务。可以附加额外指令和输入文件。
|
|
141
|
+
*
|
|
142
|
+
* 执行后可以通过以下方式获取结果:
|
|
143
|
+
* - 方式1:轮询查询 - 使用 getExecutionById() 定期查询执行状态
|
|
144
|
+
* - 方式2:Webhook推送 - 配置Webhook接收执行完成通知
|
|
145
|
+
*
|
|
146
|
+
* @param params - 执行参数
|
|
147
|
+
* @returns 执行ID和初始状态
|
|
148
|
+
* @throws {PlolinkError} 当预设不存在或执行失败时抛出
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* // 执行预设
|
|
153
|
+
* const result = await presetAgentTask.execute({
|
|
154
|
+
* code: 'talent-resume-parse',
|
|
155
|
+
* additionalPrompt: '请特别关注技能匹配度',
|
|
156
|
+
* inputFileId: 'file-resume-123'
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* console.log('执行ID:', result.executionId);
|
|
160
|
+
* console.log('初始状态:', result.status); // 'INITIALIZING'
|
|
161
|
+
*
|
|
162
|
+
* // 方式1:轮询查询结果
|
|
163
|
+
* let execution;
|
|
164
|
+
* do {
|
|
165
|
+
* await new Promise(resolve => setTimeout(resolve, 5000)); // 等待5秒
|
|
166
|
+
* execution = await presetAgentTask.getExecutionById(result.executionId);
|
|
167
|
+
* console.log('当前状态:', execution.status);
|
|
168
|
+
* } while (execution.status === 'INITIALIZING' || execution.status === 'RUNNING');
|
|
169
|
+
*
|
|
170
|
+
* console.log('执行完成!');
|
|
171
|
+
* console.log('输出文件:', execution.outputFileId);
|
|
172
|
+
* console.log('Token消耗:', execution.metrics.inputTokens);
|
|
173
|
+
* console.log('费用:', execution.metrics.totalCost);
|
|
174
|
+
*
|
|
175
|
+
* // 方式2:通过Webhook接收结果(需要在系统中配置)
|
|
176
|
+
* // Webhook URL会收到POST请求:
|
|
177
|
+
* // {
|
|
178
|
+
* // module: "preset-agent-task",
|
|
179
|
+
* // action: "execution.completed",
|
|
180
|
+
* // data: {
|
|
181
|
+
* // executionId: "...",
|
|
182
|
+
* // outputFileId: "...",
|
|
183
|
+
* // metrics: {...}
|
|
184
|
+
* // }
|
|
185
|
+
* // }
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
async execute(params) {
|
|
189
|
+
return this.client.axiosInstance.post(`${this.baseUrl}/execute`, params);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* 获取执行记录列表
|
|
193
|
+
*
|
|
194
|
+
* @param options - 查询选项
|
|
195
|
+
* @returns 分页的执行记录列表
|
|
196
|
+
* @throws {PlolinkError} 当请求失败时抛出
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* // 查询特定预设的执行记录
|
|
201
|
+
* const result = await presetAgentTask.listExecutions({
|
|
202
|
+
* presetId: 'clx_preset_123',
|
|
203
|
+
* status: 'COMPLETED',
|
|
204
|
+
* page: 1,
|
|
205
|
+
* pageSize: 20
|
|
206
|
+
* });
|
|
207
|
+
*
|
|
208
|
+
* console.log('总数:', result.total);
|
|
209
|
+
* result.list.forEach(execution => {
|
|
210
|
+
* console.log(`执行ID: ${execution.id}, 状态: ${execution.status}`);
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
async listExecutions(options) {
|
|
215
|
+
return this.client.axiosInstance.get(
|
|
216
|
+
`${this.baseUrl}/executions`,
|
|
217
|
+
{ params: options }
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* 获取执行详情
|
|
222
|
+
*
|
|
223
|
+
* @description
|
|
224
|
+
* 获取执行记录的完整信息,包括输出文件ID、Token消耗、费用等。
|
|
225
|
+
* 注意:不包含agentTaskId、runId(完全隐藏Agent Task细节)
|
|
226
|
+
*
|
|
227
|
+
* @param executionId - 执行ID
|
|
228
|
+
* @returns 执行详细信息
|
|
229
|
+
* @throws {PlolinkError} 当执行记录不存在时抛出
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const execution = await presetAgentTask.getExecutionById('clx_exec_789');
|
|
234
|
+
*
|
|
235
|
+
* console.log('执行状态:', execution.status);
|
|
236
|
+
* console.log('预设名称:', execution.presetName);
|
|
237
|
+
* console.log('输入文件:', execution.inputFileId);
|
|
238
|
+
* console.log('输出文件:', execution.outputFileId);
|
|
239
|
+
* console.log('执行时长:', execution.duration, 'ms');
|
|
240
|
+
* console.log('Token消耗:', execution.metrics.inputTokens, '+', execution.metrics.outputTokens);
|
|
241
|
+
* console.log('总费用:', execution.metrics.totalCost, 'USD');
|
|
242
|
+
*
|
|
243
|
+
* if (execution.status === 'FAILED') {
|
|
244
|
+
* console.error('错误信息:', execution.errorMessage);
|
|
245
|
+
* }
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
async getExecutionById(executionId) {
|
|
249
|
+
return this.client.axiosInstance.get(`${this.baseUrl}/executions/${executionId}`);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* 取消执行
|
|
253
|
+
*
|
|
254
|
+
* @param executionId - 执行ID
|
|
255
|
+
* @param reason - 取消原因(可选)
|
|
256
|
+
* @throws {PlolinkError} 当执行不存在或取消失败时抛出
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* await presetAgentTask.cancelExecution('clx_exec_789', '用户主动取消');
|
|
261
|
+
* console.log('执行已取消');
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
async cancelExecution(executionId, reason) {
|
|
265
|
+
await this.client.axiosInstance.post(`${this.baseUrl}/executions/${executionId}/cancel`, { reason });
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* 重新执行
|
|
269
|
+
*
|
|
270
|
+
* @description
|
|
271
|
+
* 使用相同的参数重新执行预设任务。
|
|
272
|
+
*
|
|
273
|
+
* @param executionId - 原执行ID
|
|
274
|
+
* @returns 新的执行ID和状态
|
|
275
|
+
* @throws {PlolinkError} 当原执行不存在或重试失败时抛出
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* const result = await presetAgentTask.retryExecution('clx_exec_789');
|
|
280
|
+
* console.log('新执行ID:', result.executionId);
|
|
281
|
+
* console.log('初始状态:', result.status);
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
async retryExecution(executionId) {
|
|
285
|
+
return this.client.axiosInstance.post(`${this.baseUrl}/executions/${executionId}/retry`);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* 导出预设配置
|
|
289
|
+
*
|
|
290
|
+
* @description
|
|
291
|
+
* 导出选中的预设配置为JSON格式,可用于跨团队/环境迁移。
|
|
292
|
+
* 注意:extendedSkillsFileId需要手动处理(文件不跨团队)
|
|
293
|
+
*
|
|
294
|
+
* @param presetIds - 预设ID数组
|
|
295
|
+
* @returns 导出的配置(JSON格式)
|
|
296
|
+
* @throws {PlolinkError} 当预设不存在或导出失败时抛出
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```typescript
|
|
300
|
+
* const config = await presetAgentTask.export(['clx_preset_123', 'clx_preset_456']);
|
|
301
|
+
*
|
|
302
|
+
* console.log('配置版本:', config.version);
|
|
303
|
+
* console.log('导出时间:', config.exportedAt);
|
|
304
|
+
* console.log('预设数量:', config.presets.length);
|
|
305
|
+
*
|
|
306
|
+
* // 保存到文件(Node.js环境)
|
|
307
|
+
* const fs = require('fs');
|
|
308
|
+
* fs.writeFileSync('presets.json', JSON.stringify(config, null, 2));
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
async export(presetIds) {
|
|
312
|
+
return this.client.axiosInstance.post(`${this.baseUrl}/export`, { presetIds });
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* 导入预设配置
|
|
316
|
+
*
|
|
317
|
+
* @description
|
|
318
|
+
* 从导出的JSON配置导入预设到当前团队。
|
|
319
|
+
* 支持冲突处理策略:skip(跳过已存在)或 overwrite(覆盖已存在)
|
|
320
|
+
*
|
|
321
|
+
* @param config - 导出的配置
|
|
322
|
+
* @param conflictStrategy - 冲突策略('skip' 或 'overwrite'),默认 'skip'
|
|
323
|
+
* @returns 导入结果
|
|
324
|
+
* @throws {PlolinkError} 当配置无效或导入失败时抛出
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```typescript
|
|
328
|
+
* // 从文件读取(Node.js环境)
|
|
329
|
+
* const fs = require('fs');
|
|
330
|
+
* const config = JSON.parse(fs.readFileSync('presets.json', 'utf-8'));
|
|
331
|
+
*
|
|
332
|
+
* // 导入(跳过已存在的code)
|
|
333
|
+
* const result = await presetAgentTask.import(config, 'skip');
|
|
334
|
+
* console.log('导入成功:', result.imported);
|
|
335
|
+
* console.log('跳过:', result.skipped);
|
|
336
|
+
* console.log('失败:', result.failed);
|
|
337
|
+
*
|
|
338
|
+
* result.details.forEach(detail => {
|
|
339
|
+
* console.log(`${detail.code}: ${detail.status}`);
|
|
340
|
+
* if (detail.status === 'imported') {
|
|
341
|
+
* console.log(' 新预设ID:', detail.presetId);
|
|
342
|
+
* } else if (detail.status === 'failed') {
|
|
343
|
+
* console.log(' 错误:', detail.error);
|
|
344
|
+
* }
|
|
345
|
+
* });
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
async import(config, conflictStrategy = "skip") {
|
|
349
|
+
return this.client.axiosInstance.post(`${this.baseUrl}/import`, {
|
|
350
|
+
...config,
|
|
351
|
+
conflictStrategy
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
export { PresetAgentTask };
|
|
357
|
+
//# sourceMappingURL=index.js.map
|
|
358
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/modules/preset-agent-task/index.ts"],"names":[],"mappings":";AA6FO,IAAM,kBAAN,MAAsB;AAAA,EAI3B,YAAY,MAAA,EAAuB;AAFnC,IAAA,IAAA,CAAQ,OAAA,GAAU,4BAAA;AAGhB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BA,MAAa,OAAO,MAAA,EAAmE;AACrF,IAAA,OAAO,KAAK,MAAA,CAAO,aAAA,CAAc,IAAA,CAAK,IAAA,CAAK,SAAS,MAAM,CAAA;AAAA,EAC5D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwBA,MAAa,KAAK,OAAA,EAAqE;AACrF,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,aAAA,CAAc,GAAA,CAAI,KAAK,OAAA,EAAS;AAAA,MACjD,MAAA,EAAQ;AAAA,KACT,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,MAAa,QAAQ,EAAA,EAAmC;AACtD,IAAA,OAAO,IAAA,CAAK,OAAO,aAAA,CAAc,GAAA,CAAI,GAAG,IAAA,CAAK,OAAO,CAAA,CAAA,EAAI,EAAE,CAA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A,EACH;AACF","file":"index.js","sourcesContent":["/**\n * 预设Agent任务模块\n * \n * @description\n * 预设Agent任务是对Agent Task能力的封装,提供开箱即用的业务能力。\n * \n * 核心功能:\n * - 预设配置管理(CRUD)\n * - 预设执行(通过code调用)\n * - 执行记录查询\n * - 执行管理(取消、重试)\n * - 配置导出/导入\n * \n * 注意:完全隐藏Agent Task实现细节,不暴露agentTaskId、runId\n * \n * @example\n * ```typescript\n * import { PlolinkClient } from '@plolink/sdk';\n * import { PresetAgentTask } from '@plolink/sdk/preset-agent-task';\n * \n * const client = new PlolinkClient({\n * mode: 'apiKey',\n * apiKey: 'your-api-key'\n * });\n * \n * const presetAgentTask = new PresetAgentTask(client);\n * \n * // 执行预设\n * const result = await presetAgentTask.execute({\n * code: 'talent-resume-parse',\n * additionalPrompt: '请特别关注技能匹配度',\n * inputFileId: 'file-resume-123'\n * });\n * \n * console.log('执行ID:', result.executionId);\n * console.log('初始状态:', result.status);\n * \n * // 方式1:轮询查询结果\n * const execution = await presetAgentTask.getExecutionById(result.executionId);\n * console.log('输出文件:', execution.outputFileId);\n * \n * // 方式2:通过Webhook接收结果(需要在系统中配置Webhook)\n * // POST /your-webhook-url\n * // { module: \"preset-agent-task\", action: \"execution.completed\", data: {...} }\n * ```\n * \n * @module preset-agent-task\n */\n\nimport type { PlolinkClient } from '../../core/client';\nimport type {\n PresetConfig,\n PresetListItem,\n CreatePresetParams,\n UpdatePresetParams,\n ExecutePresetParams,\n PresetExecution,\n PresetExecutionListItem,\n PresetListQuery,\n ExecutionListQuery,\n PaginatedResult,\n ExecutionResult,\n ExportedConfig,\n ImportResult,\n ConflictStrategy,\n} from '../../types/preset-agent-task';\n\n// Re-export types\nexport type {\n PresetConfig,\n PresetListItem,\n CreatePresetParams,\n UpdatePresetParams,\n ExecutePresetParams,\n PresetExecution,\n PresetExecutionListItem,\n PresetListQuery,\n ExecutionListQuery,\n PaginatedResult,\n ExecutionResult,\n ExportedConfig,\n ImportResult,\n ConflictStrategy,\n PresetExecutionStatus,\n ExecutionMetrics,\n PresetConfigForExport,\n ImportResultDetail,\n PresetExecutionWebhookPayload,\n} from '../../types/preset-agent-task';\n\n/**\n * 预设Agent任务模块\n */\nexport class PresetAgentTask {\n private client: PlolinkClient;\n private baseUrl = '/api/v1/preset-agent-tasks';\n\n constructor(client: PlolinkClient) {\n this.client = client;\n }\n\n /**\n * 创建预设\n * \n * @param params - 创建参数\n * @returns 预设ID和code\n * @throws {PlolinkError} 当参数无效或创建失败时抛出\n * \n * @example\n * ```typescript\n * const result = await presetAgentTask.create({\n * code: 'talent-resume-parse',\n * name: '简历解析预设',\n * description: '自动解析简历并提取关键信息',\n * prompt: '请解析上传的简历文件,提取候选人的基本信息、教育背景、工作经历等关键数据',\n * model: 'doubao-seed-1-6-lite-251015',\n * selectedSkills: ['talent/resume-parse', 'common/file-extract'],\n * timeoutMs: 1800000,\n * businessKey: 'talent-resume-parse'\n * });\n * \n * console.log('预设ID:', result.id);\n * console.log('预设标识:', result.code);\n * ```\n */\n public async create(params: CreatePresetParams): Promise<{ id: string; code: string }> {\n return this.client.axiosInstance.post(this.baseUrl, params);\n }\n\n /**\n * 获取预设列表\n * \n * @param options - 查询选项\n * @returns 分页的预设列表\n * @throws {PlolinkError} 当请求失败时抛出\n * \n * @example\n * ```typescript\n * // 获取所有启用的预设\n * const result = await presetAgentTask.list({\n * enabled: true,\n * page: 1,\n * pageSize: 20\n * });\n * \n * console.log('总数:', result.total);\n * result.list.forEach(preset => {\n * console.log(`${preset.code}: ${preset.name}`);\n * });\n * ```\n */\n public async list(options?: PresetListQuery): Promise<PaginatedResult<PresetListItem>> {\n return this.client.axiosInstance.get(this.baseUrl, {\n params: options,\n });\n }\n\n /**\n * 获取预设详情\n * \n * @param id - 预设ID\n * @returns 预设详细信息\n * @throws {PlolinkError} 当预设不存在时抛出\n * \n * @example\n * ```typescript\n * const preset = await presetAgentTask.getById('clx_preset_123');\n * console.log('预设名称:', preset.name);\n * console.log('预设指令:', preset.prompt);\n * console.log('AI模型:', preset.model);\n * ```\n */\n public async getById(id: string): Promise<PresetConfig> {\n return this.client.axiosInstance.get(`${this.baseUrl}/${id}`);\n }\n\n /**\n * 通过code获取预设\n * \n * @param code - 预设唯一标识\n * @returns 预设详细信息\n * @throws {PlolinkError} 当预设不存在时抛出\n * \n * @example\n * ```typescript\n * const preset = await presetAgentTask.getByCode('talent-resume-parse');\n * console.log('预设ID:', preset.id);\n * console.log('预设名称:', preset.name);\n * ```\n */\n public async getByCode(code: string): Promise<PresetConfig> {\n // 通过列表查找匹配的code\n const result = await this.list({ enabled: true, pageSize: 100 });\n const preset = result.list.find((p) => p.code === code);\n \n if (!preset) {\n throw new Error(`Preset not found with code: ${code}`);\n }\n \n return this.getById(preset.id);\n }\n\n /**\n * 更新预设\n * \n * @param id - 预设ID\n * @param params - 更新参数\n * @throws {PlolinkError} 当预设不存在或更新失败时抛出\n * \n * @example\n * ```typescript\n * await presetAgentTask.update('clx_preset_123', {\n * name: '简历解析预设(更新)',\n * enabled: false\n * });\n * \n * console.log('预设更新成功');\n * ```\n */\n public async update(id: string, params: UpdatePresetParams): Promise<void> {\n await this.client.axiosInstance.put(`${this.baseUrl}/${id}`, params);\n }\n\n /**\n * 删除预设\n * \n * @param id - 预设ID\n * @throws {PlolinkError} 当预设不存在或删除失败时抛出\n * \n * @example\n * ```typescript\n * await presetAgentTask.delete('clx_preset_123');\n * console.log('预设删除成功');\n * ```\n */\n public async delete(id: string): Promise<void> {\n await this.client.axiosInstance.delete(`${this.baseUrl}/${id}`);\n }\n\n /**\n * 执行预设(核心方法)\n * \n * @description\n * 通过预设code执行预设任务。可以附加额外指令和输入文件。\n * \n * 执行后可以通过以下方式获取结果:\n * - 方式1:轮询查询 - 使用 getExecutionById() 定期查询执行状态\n * - 方式2:Webhook推送 - 配置Webhook接收执行完成通知\n * \n * @param params - 执行参数\n * @returns 执行ID和初始状态\n * @throws {PlolinkError} 当预设不存在或执行失败时抛出\n * \n * @example\n * ```typescript\n * // 执行预设\n * const result = await presetAgentTask.execute({\n * code: 'talent-resume-parse',\n * additionalPrompt: '请特别关注技能匹配度',\n * inputFileId: 'file-resume-123'\n * });\n * \n * console.log('执行ID:', result.executionId);\n * console.log('初始状态:', result.status); // 'INITIALIZING'\n * \n * // 方式1:轮询查询结果\n * let execution;\n * do {\n * await new Promise(resolve => setTimeout(resolve, 5000)); // 等待5秒\n * execution = await presetAgentTask.getExecutionById(result.executionId);\n * console.log('当前状态:', execution.status);\n * } while (execution.status === 'INITIALIZING' || execution.status === 'RUNNING');\n * \n * console.log('执行完成!');\n * console.log('输出文件:', execution.outputFileId);\n * console.log('Token消耗:', execution.metrics.inputTokens);\n * console.log('费用:', execution.metrics.totalCost);\n * \n * // 方式2:通过Webhook接收结果(需要在系统中配置)\n * // Webhook URL会收到POST请求:\n * // {\n * // module: \"preset-agent-task\",\n * // action: \"execution.completed\",\n * // data: {\n * // executionId: \"...\",\n * // outputFileId: \"...\",\n * // metrics: {...}\n * // }\n * // }\n * ```\n */\n public async execute(params: ExecutePresetParams): Promise<ExecutionResult> {\n return this.client.axiosInstance.post(`${this.baseUrl}/execute`, params);\n }\n\n /**\n * 获取执行记录列表\n * \n * @param options - 查询选项\n * @returns 分页的执行记录列表\n * @throws {PlolinkError} 当请求失败时抛出\n * \n * @example\n * ```typescript\n * // 查询特定预设的执行记录\n * const result = await presetAgentTask.listExecutions({\n * presetId: 'clx_preset_123',\n * status: 'COMPLETED',\n * page: 1,\n * pageSize: 20\n * });\n * \n * console.log('总数:', result.total);\n * result.list.forEach(execution => {\n * console.log(`执行ID: ${execution.id}, 状态: ${execution.status}`);\n * });\n * ```\n */\n public async listExecutions(options?: ExecutionListQuery): Promise<PaginatedResult<PresetExecutionListItem>> {\n return this.client.axiosInstance.get(\n `${this.baseUrl}/executions`,\n { params: options }\n );\n }\n\n /**\n * 获取执行详情\n * \n * @description\n * 获取执行记录的完整信息,包括输出文件ID、Token消耗、费用等。\n * 注意:不包含agentTaskId、runId(完全隐藏Agent Task细节)\n * \n * @param executionId - 执行ID\n * @returns 执行详细信息\n * @throws {PlolinkError} 当执行记录不存在时抛出\n * \n * @example\n * ```typescript\n * const execution = await presetAgentTask.getExecutionById('clx_exec_789');\n * \n * console.log('执行状态:', execution.status);\n * console.log('预设名称:', execution.presetName);\n * console.log('输入文件:', execution.inputFileId);\n * console.log('输出文件:', execution.outputFileId);\n * console.log('执行时长:', execution.duration, 'ms');\n * console.log('Token消耗:', execution.metrics.inputTokens, '+', execution.metrics.outputTokens);\n * console.log('总费用:', execution.metrics.totalCost, 'USD');\n * \n * if (execution.status === 'FAILED') {\n * console.error('错误信息:', execution.errorMessage);\n * }\n * ```\n */\n public async getExecutionById(executionId: string): Promise<PresetExecution> {\n return this.client.axiosInstance.get(`${this.baseUrl}/executions/${executionId}`);\n }\n\n /**\n * 取消执行\n * \n * @param executionId - 执行ID\n * @param reason - 取消原因(可选)\n * @throws {PlolinkError} 当执行不存在或取消失败时抛出\n * \n * @example\n * ```typescript\n * await presetAgentTask.cancelExecution('clx_exec_789', '用户主动取消');\n * console.log('执行已取消');\n * ```\n */\n public async cancelExecution(executionId: string, reason?: string): Promise<void> {\n await this.client.axiosInstance.post(`${this.baseUrl}/executions/${executionId}/cancel`, { reason });\n }\n\n /**\n * 重新执行\n * \n * @description\n * 使用相同的参数重新执行预设任务。\n * \n * @param executionId - 原执行ID\n * @returns 新的执行ID和状态\n * @throws {PlolinkError} 当原执行不存在或重试失败时抛出\n * \n * @example\n * ```typescript\n * const result = await presetAgentTask.retryExecution('clx_exec_789');\n * console.log('新执行ID:', result.executionId);\n * console.log('初始状态:', result.status);\n * ```\n */\n public async retryExecution(executionId: string): Promise<ExecutionResult> {\n return this.client.axiosInstance.post(`${this.baseUrl}/executions/${executionId}/retry`);\n }\n\n /**\n * 导出预设配置\n * \n * @description\n * 导出选中的预设配置为JSON格式,可用于跨团队/环境迁移。\n * 注意:extendedSkillsFileId需要手动处理(文件不跨团队)\n * \n * @param presetIds - 预设ID数组\n * @returns 导出的配置(JSON格式)\n * @throws {PlolinkError} 当预设不存在或导出失败时抛出\n * \n * @example\n * ```typescript\n * const config = await presetAgentTask.export(['clx_preset_123', 'clx_preset_456']);\n * \n * console.log('配置版本:', config.version);\n * console.log('导出时间:', config.exportedAt);\n * console.log('预设数量:', config.presets.length);\n * \n * // 保存到文件(Node.js环境)\n * const fs = require('fs');\n * fs.writeFileSync('presets.json', JSON.stringify(config, null, 2));\n * ```\n */\n public async export(presetIds: string[]): Promise<ExportedConfig> {\n return this.client.axiosInstance.post(`${this.baseUrl}/export`, { presetIds });\n }\n\n /**\n * 导入预设配置\n * \n * @description\n * 从导出的JSON配置导入预设到当前团队。\n * 支持冲突处理策略:skip(跳过已存在)或 overwrite(覆盖已存在)\n * \n * @param config - 导出的配置\n * @param conflictStrategy - 冲突策略('skip' 或 'overwrite'),默认 'skip'\n * @returns 导入结果\n * @throws {PlolinkError} 当配置无效或导入失败时抛出\n * \n * @example\n * ```typescript\n * // 从文件读取(Node.js环境)\n * const fs = require('fs');\n * const config = JSON.parse(fs.readFileSync('presets.json', 'utf-8'));\n * \n * // 导入(跳过已存在的code)\n * const result = await presetAgentTask.import(config, 'skip');\n * console.log('导入成功:', result.imported);\n * console.log('跳过:', result.skipped);\n * console.log('失败:', result.failed);\n * \n * result.details.forEach(detail => {\n * console.log(`${detail.code}: ${detail.status}`);\n * if (detail.status === 'imported') {\n * console.log(' 新预设ID:', detail.presetId);\n * } else if (detail.status === 'failed') {\n * console.log(' 错误:', detail.error);\n * }\n * });\n * ```\n */\n public async import(config: ExportedConfig, conflictStrategy: ConflictStrategy = 'skip'): Promise<ImportResult> {\n return this.client.axiosInstance.post(`${this.baseUrl}/import`, {\n ...config,\n conflictStrategy,\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plolink/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Plolink 开放平台官方 SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -56,6 +56,16 @@
|
|
|
56
56
|
"import": "./dist/modules/report-writer/index.js",
|
|
57
57
|
"require": "./dist/modules/report-writer/index.cjs"
|
|
58
58
|
},
|
|
59
|
+
"./preset-agent-task": {
|
|
60
|
+
"types": "./dist/modules/preset-agent-task/index.d.ts",
|
|
61
|
+
"import": "./dist/modules/preset-agent-task/index.js",
|
|
62
|
+
"require": "./dist/modules/preset-agent-task/index.cjs"
|
|
63
|
+
},
|
|
64
|
+
"./llm": {
|
|
65
|
+
"types": "./dist/modules/llm/index.d.ts",
|
|
66
|
+
"import": "./dist/modules/llm/index.js",
|
|
67
|
+
"require": "./dist/modules/llm/index.cjs"
|
|
68
|
+
},
|
|
59
69
|
"./common": {
|
|
60
70
|
"types": "./dist/common/index.d.ts",
|
|
61
71
|
"import": "./dist/common/index.js",
|