@ziggs-ai/api-client 0.10.1 → 0.10.3
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/http/TaskClient.d.ts +30 -12
- package/dist/http/TaskClient.js +69 -25
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { type Creds, type Task, type TaskState } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* ZIG-1321 — thin confirmation from task write verbs. Full object stays on
|
|
4
|
+
* getTask / ziggs_task_get.
|
|
5
|
+
*/
|
|
6
|
+
export interface TaskWriteConfirm {
|
|
7
|
+
ok: true;
|
|
8
|
+
taskId: string;
|
|
9
|
+
state: TaskState;
|
|
10
|
+
updatedAt?: string;
|
|
11
|
+
status?: string;
|
|
12
|
+
stepCount?: number;
|
|
13
|
+
structureChanged?: boolean;
|
|
14
|
+
stepId?: string;
|
|
15
|
+
stepStatus?: string;
|
|
16
|
+
resultRecorded?: boolean;
|
|
17
|
+
terminalState?: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
2
20
|
/**
|
|
3
21
|
* When the buyer reviews a task's plan. Task-rail only — an agreement has no
|
|
4
22
|
* plan to review, which is why cut this from the propose/counter/
|
|
@@ -32,10 +50,10 @@ export interface UpdateTaskStateData {
|
|
|
32
50
|
*/
|
|
33
51
|
idempotencyKey?: string;
|
|
34
52
|
}
|
|
35
|
-
export declare function updateTaskState(taskId: string, state: TaskState, data: UpdateTaskStateData | undefined, creds: Creds): Promise<
|
|
53
|
+
export declare function updateTaskState(taskId: string, state: TaskState, data: UpdateTaskStateData | undefined, creds: Creds): Promise<TaskWriteConfirm>;
|
|
36
54
|
export declare function getActiveTasksForAgent(agentId: string, creds: Creds): Promise<Task[]>;
|
|
37
55
|
export declare function getActiveTasksForChat(chatId: string, creds: Creds): Promise<Task[]>;
|
|
38
|
-
export declare function cancelTask(taskId: string, creds: Creds): Promise<
|
|
56
|
+
export declare function cancelTask(taskId: string, creds: Creds): Promise<TaskWriteConfirm>;
|
|
39
57
|
export declare function getSubtasks(parentTaskId: string, creds: Creds): Promise<Task[]>;
|
|
40
58
|
export interface PlanReplaceStep {
|
|
41
59
|
/** Omit to let the server mint `step-<n>`. */
|
|
@@ -52,10 +70,10 @@ export interface PlanReplaceStep {
|
|
|
52
70
|
/** Optional step output stored with this replace. */
|
|
53
71
|
result?: unknown;
|
|
54
72
|
}
|
|
55
|
-
export declare function replaceTaskPlan(taskId: string, steps: PlanReplaceStep[], creds: Creds): Promise<
|
|
56
|
-
export declare function updateTaskPlanStep(taskId: string, stepId: string, status: string, result: unknown, creds: Creds): Promise<
|
|
57
|
-
export declare function reportTask(taskId: string, message: string | undefined, creds: Creds): Promise<
|
|
58
|
-
export declare function setTaskSatisfaction(taskId: string, satisfaction: 'positive' | 'negative', creds: Creds): Promise<
|
|
73
|
+
export declare function replaceTaskPlan(taskId: string, steps: PlanReplaceStep[], creds: Creds): Promise<TaskWriteConfirm>;
|
|
74
|
+
export declare function updateTaskPlanStep(taskId: string, stepId: string, status: string, result: unknown, creds: Creds): Promise<TaskWriteConfirm>;
|
|
75
|
+
export declare function reportTask(taskId: string, message: string | undefined, creds: Creds): Promise<TaskWriteConfirm>;
|
|
76
|
+
export declare function setTaskSatisfaction(taskId: string, satisfaction: 'positive' | 'negative', creds: Creds): Promise<TaskWriteConfirm>;
|
|
59
77
|
export interface ListTasksOptions {
|
|
60
78
|
state?: string;
|
|
61
79
|
cursor?: string;
|
|
@@ -85,15 +103,15 @@ export declare class TaskClient {
|
|
|
85
103
|
constructor(operatorKey: string, agentId?: string);
|
|
86
104
|
createTask(data: CreateTaskData): Promise<Task>;
|
|
87
105
|
getTask(taskId: string): Promise<Task>;
|
|
88
|
-
updateTaskState(taskId: string, state: TaskState, data?: UpdateTaskStateData): Promise<
|
|
106
|
+
updateTaskState(taskId: string, state: TaskState, data?: UpdateTaskStateData): Promise<TaskWriteConfirm>;
|
|
89
107
|
getActiveTasksForAgent(agentId: string): Promise<Task[]>;
|
|
90
108
|
getActiveTasksForChat(chatId: string): Promise<Task[]>;
|
|
91
|
-
cancelTask(taskId: string): Promise<
|
|
109
|
+
cancelTask(taskId: string): Promise<TaskWriteConfirm>;
|
|
92
110
|
getSubtasks(parentTaskId: string): Promise<Task[]>;
|
|
93
|
-
replaceTaskPlan(taskId: string, steps: PlanReplaceStep[]): Promise<
|
|
94
|
-
updateTaskPlanStep(taskId: string, stepId: string, status: string, result?: unknown): Promise<
|
|
95
|
-
reportTask(taskId: string, message?: string): Promise<
|
|
96
|
-
setTaskSatisfaction(taskId: string, satisfaction: 'positive' | 'negative'): Promise<
|
|
111
|
+
replaceTaskPlan(taskId: string, steps: PlanReplaceStep[]): Promise<TaskWriteConfirm>;
|
|
112
|
+
updateTaskPlanStep(taskId: string, stepId: string, status: string, result?: unknown): Promise<TaskWriteConfirm>;
|
|
113
|
+
reportTask(taskId: string, message?: string): Promise<TaskWriteConfirm>;
|
|
114
|
+
setTaskSatisfaction(taskId: string, satisfaction: 'positive' | 'negative'): Promise<TaskWriteConfirm>;
|
|
97
115
|
listTasks(options?: ListTasksOptions): Promise<ListTasksResult>;
|
|
98
116
|
countTasks(filters?: CountTasksFilters): Promise<number>;
|
|
99
117
|
}
|
package/dist/http/TaskClient.js
CHANGED
|
@@ -24,10 +24,54 @@ function extractTask(data) {
|
|
|
24
24
|
if (d['task'] && typeof d['task'] === 'object' && d['task']['taskId']) {
|
|
25
25
|
return d['task'];
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
// Top-level task document (GET / create). Do not treat ZIG-1321 thin write
|
|
28
|
+
// confirms (`ok: true`, no description) as a Task.
|
|
29
|
+
if (typeof d['taskId'] === 'string' && d['ok'] !== true) {
|
|
28
30
|
return d;
|
|
31
|
+
}
|
|
29
32
|
return null;
|
|
30
33
|
}
|
|
34
|
+
function extractWriteConfirm(data) {
|
|
35
|
+
if (!data || typeof data !== 'object')
|
|
36
|
+
return null;
|
|
37
|
+
const d = data;
|
|
38
|
+
// New thin shape (no nested task / no description dump).
|
|
39
|
+
if (typeof d['taskId'] === 'string' &&
|
|
40
|
+
typeof d['state'] === 'string' &&
|
|
41
|
+
d['task'] === undefined &&
|
|
42
|
+
d['description'] === undefined) {
|
|
43
|
+
return {
|
|
44
|
+
ok: true,
|
|
45
|
+
taskId: d['taskId'],
|
|
46
|
+
state: d['state'],
|
|
47
|
+
...(typeof d['updatedAt'] === 'string' || d['updatedAt'] instanceof Date
|
|
48
|
+
? { updatedAt: String(d['updatedAt']) }
|
|
49
|
+
: {}),
|
|
50
|
+
...(typeof d['status'] === 'string' ? { status: d['status'] } : {}),
|
|
51
|
+
...(typeof d['stepCount'] === 'number' ? { stepCount: d['stepCount'] } : {}),
|
|
52
|
+
...(typeof d['structureChanged'] === 'boolean'
|
|
53
|
+
? { structureChanged: d['structureChanged'] }
|
|
54
|
+
: {}),
|
|
55
|
+
...(typeof d['stepId'] === 'string' ? { stepId: d['stepId'] } : {}),
|
|
56
|
+
...(typeof d['stepStatus'] === 'string' ? { stepStatus: d['stepStatus'] } : {}),
|
|
57
|
+
...(d['resultRecorded'] === true ? { resultRecorded: true } : {}),
|
|
58
|
+
...(typeof d['terminalState'] === 'string'
|
|
59
|
+
? { terminalState: d['terminalState'] }
|
|
60
|
+
: {}),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// Legacy fat echo — compress to the thin fields so callers stay forward-compat.
|
|
64
|
+
const task = extractTask(data);
|
|
65
|
+
if (!task?.taskId || !task.state)
|
|
66
|
+
return null;
|
|
67
|
+
return {
|
|
68
|
+
ok: true,
|
|
69
|
+
taskId: task.taskId,
|
|
70
|
+
state: task.state,
|
|
71
|
+
...(task.updatedAt ? { updatedAt: task.updatedAt } : {}),
|
|
72
|
+
...(typeof d['status'] === 'string' ? { status: d['status'] } : {}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
31
75
|
export async function createTask(taskData, creds) {
|
|
32
76
|
if (!taskData)
|
|
33
77
|
throw new Error('Task data is required for task creation');
|
|
@@ -85,10 +129,10 @@ export async function updateTaskState(taskId, state, data = {}, creds) {
|
|
|
85
129
|
throwApiError(res, body, `Task state update failed: ${res.status} ${res.statusText}`);
|
|
86
130
|
}
|
|
87
131
|
const result = await res.json().catch(() => null);
|
|
88
|
-
const
|
|
89
|
-
if (!
|
|
90
|
-
throw new Error('Invalid response: task
|
|
91
|
-
return
|
|
132
|
+
const confirm = extractWriteConfirm(result);
|
|
133
|
+
if (!confirm)
|
|
134
|
+
throw new Error('Invalid response: task write confirm not found');
|
|
135
|
+
return confirm;
|
|
92
136
|
}
|
|
93
137
|
export async function getActiveTasksForAgent(agentId, creds) {
|
|
94
138
|
if (!agentId)
|
|
@@ -182,10 +226,10 @@ export async function cancelTask(taskId, creds) {
|
|
|
182
226
|
throwApiError(res, body, `Task cancel failed: ${res.status} ${res.statusText}`);
|
|
183
227
|
}
|
|
184
228
|
const result = await res.json().catch(() => null);
|
|
185
|
-
const
|
|
186
|
-
if (!
|
|
187
|
-
throw new Error('Invalid response: task
|
|
188
|
-
return
|
|
229
|
+
const confirm = extractWriteConfirm(result);
|
|
230
|
+
if (!confirm)
|
|
231
|
+
throw new Error('Invalid response: task write confirm not found');
|
|
232
|
+
return confirm;
|
|
189
233
|
}
|
|
190
234
|
export async function getSubtasks(parentTaskId, creds) {
|
|
191
235
|
if (!parentTaskId)
|
|
@@ -219,10 +263,10 @@ export async function replaceTaskPlan(taskId, steps, creds) {
|
|
|
219
263
|
throwApiError(res, responseBody, `Plan replace failed: ${res.status} ${res.statusText}`);
|
|
220
264
|
}
|
|
221
265
|
const data = await res.json().catch(() => null);
|
|
222
|
-
const
|
|
223
|
-
if (!
|
|
224
|
-
throw new Error('Invalid response: task
|
|
225
|
-
return
|
|
266
|
+
const confirm = extractWriteConfirm(data);
|
|
267
|
+
if (!confirm)
|
|
268
|
+
throw new Error('Invalid response: task write confirm not found');
|
|
269
|
+
return confirm;
|
|
226
270
|
}
|
|
227
271
|
export async function updateTaskPlanStep(taskId, stepId, status, result, creds) {
|
|
228
272
|
if (!taskId)
|
|
@@ -242,10 +286,10 @@ export async function updateTaskPlanStep(taskId, stepId, status, result, creds)
|
|
|
242
286
|
throwApiError(res, responseBody, `Plan step update failed: ${res.status} ${res.statusText}`);
|
|
243
287
|
}
|
|
244
288
|
const data = await res.json().catch(() => null);
|
|
245
|
-
const
|
|
246
|
-
if (!
|
|
247
|
-
throw new Error('Invalid response: task
|
|
248
|
-
return
|
|
289
|
+
const confirm = extractWriteConfirm(data);
|
|
290
|
+
if (!confirm)
|
|
291
|
+
throw new Error('Invalid response: task write confirm not found');
|
|
292
|
+
return confirm;
|
|
249
293
|
}
|
|
250
294
|
// ---------------------------------------------------------------------------
|
|
251
295
|
// Reporting & satisfaction
|
|
@@ -264,10 +308,10 @@ export async function reportTask(taskId, message = '', creds) {
|
|
|
264
308
|
throwApiError(res, body, `Task report failed: ${res.status} ${res.statusText}`);
|
|
265
309
|
}
|
|
266
310
|
const data = await res.json().catch(() => null);
|
|
267
|
-
const
|
|
268
|
-
if (!
|
|
269
|
-
throw new Error('Invalid response: task
|
|
270
|
-
return
|
|
311
|
+
const confirm = extractWriteConfirm(data);
|
|
312
|
+
if (!confirm)
|
|
313
|
+
throw new Error('Invalid response: task write confirm not found');
|
|
314
|
+
return confirm;
|
|
271
315
|
}
|
|
272
316
|
export async function setTaskSatisfaction(taskId, satisfaction, creds) {
|
|
273
317
|
if (!taskId)
|
|
@@ -285,10 +329,10 @@ export async function setTaskSatisfaction(taskId, satisfaction, creds) {
|
|
|
285
329
|
throwApiError(res, body, `Task satisfaction failed: ${res.status} ${res.statusText}`);
|
|
286
330
|
}
|
|
287
331
|
const data = await res.json().catch(() => null);
|
|
288
|
-
const
|
|
289
|
-
if (!
|
|
290
|
-
throw new Error('Invalid response: task
|
|
291
|
-
return
|
|
332
|
+
const confirm = extractWriteConfirm(data);
|
|
333
|
+
if (!confirm)
|
|
334
|
+
throw new Error('Invalid response: task write confirm not found');
|
|
335
|
+
return confirm;
|
|
292
336
|
}
|
|
293
337
|
export async function listTasks(options = {}, creds) {
|
|
294
338
|
assertCreds(creds, 'list tasks');
|
package/dist/types.d.ts
CHANGED
|
@@ -415,7 +415,7 @@ export interface InboxAckResult {
|
|
|
415
415
|
}
|
|
416
416
|
/**
|
|
417
417
|
* Long-poll option shared by the inbox reads. The server holds the request up
|
|
418
|
-
* to this many seconds (server-clamped, ~
|
|
418
|
+
* to this many seconds (server-clamped, ~110s ceiling) and returns as soon as
|
|
419
419
|
* anything actionable exists. Omit for an immediate snapshot — the response
|
|
420
420
|
* shape is identical either way, so `wait` only changes how long an EMPTY
|
|
421
421
|
* answer is withheld.
|