@ziggs-ai/api-client 0.38.0 → 0.39.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 +34 -0
- package/README.md +14 -36
- package/dist/capabilities/agreementVerbs.js +13 -21
- package/dist/capabilities/agreements.d.ts +2 -3
- package/dist/capabilities/agreements.js +8 -43
- package/dist/capabilities/artifacts.d.ts +6 -0
- package/dist/capabilities/artifacts.js +84 -43
- package/dist/capabilities/connections.js +10 -7
- package/dist/capabilities/context.d.ts +1 -1
- package/dist/capabilities/context.js +52 -45
- package/dist/capabilities/discovery.js +5 -5
- package/dist/capabilities/everyday.d.ts +1 -1
- package/dist/capabilities/everyday.js +1 -2
- package/dist/capabilities/index.d.ts +3 -4
- package/dist/capabilities/index.js +3 -4
- package/dist/capabilities/introductions.d.ts +1 -0
- package/dist/capabilities/introductions.js +64 -17
- package/dist/capabilities/links.d.ts +1 -9
- package/dist/capabilities/links.js +40 -39
- package/dist/capabilities/mcpBriefs.js +41 -34
- package/dist/capabilities/messaging.d.ts +9 -0
- package/dist/capabilities/messaging.js +11 -0
- package/dist/capabilities/nextCall.js +8 -17
- package/dist/capabilities/sources.d.ts +2 -3
- package/dist/capabilities/sources.js +1 -2
- package/dist/capabilities/tasks.d.ts +1 -0
- package/dist/capabilities/tasks.js +43 -2
- package/dist/capabilities/toolLane.js +2 -2
- package/dist/engagementGuide.d.ts +2 -2
- package/dist/engagementGuide.js +6 -6
- package/dist/handles.d.ts +1 -1
- package/dist/handles.js +2 -2
- package/dist/http/AgreementClient.d.ts +25 -63
- package/dist/http/AgreementClient.js +14 -65
- package/dist/http/ArtifactsClient.d.ts +31 -19
- package/dist/http/ArtifactsClient.js +43 -62
- package/dist/http/ConnectionsClient.d.ts +6 -7
- package/dist/http/ConnectionsClient.js +5 -3
- package/dist/http/ContextDiscoveryClient.d.ts +2 -2
- package/dist/http/ContextGrantsClient.d.ts +9 -15
- package/dist/http/ContextGrantsClient.js +3 -5
- package/dist/http/ContextOpenClient.d.ts +5 -6
- package/dist/http/ContextOpenClient.js +11 -4
- package/dist/http/ContextReadClient.d.ts +23 -27
- package/dist/http/ContextReadClient.js +24 -23
- package/dist/http/ExecutionContextClient.d.ts +5 -1
- package/dist/http/ExecutionContextClient.js +48 -1
- package/dist/http/IntroductionsClient.d.ts +33 -4
- package/dist/http/IntroductionsClient.js +6 -2
- package/dist/http/MessageRecordsClient.d.ts +36 -0
- package/dist/http/MessageRecordsClient.js +30 -0
- package/dist/http/SessionsClient.d.ts +5 -5
- package/dist/http/SessionsClient.js +6 -6
- package/dist/http/TaskClient.d.ts +35 -6
- package/dist/http/TaskClient.js +38 -36
- package/dist/http/agreementFlows.d.ts +2 -3
- package/dist/http/agreementFlows.js +5 -5
- package/dist/http/index.d.ts +3 -5
- package/dist/http/index.js +3 -4
- package/dist/http/operatorHeaders.d.ts +3 -0
- package/dist/http/operatorHeaders.js +14 -5
- package/dist/inboxAck.d.ts +2 -2
- package/dist/inboxAck.js +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/types.d.ts +25 -55
- package/package.json +2 -2
- package/dist/capabilities/chat.d.ts +0 -43
- package/dist/capabilities/chat.js +0 -196
- package/dist/capabilities/chatListFields.d.ts +0 -14
- package/dist/capabilities/chatListFields.js +0 -61
- package/dist/http/ChatClient.d.ts +0 -187
- package/dist/http/ChatClient.js +0 -219
- package/dist/http/MessagesClient.d.ts +0 -40
- package/dist/http/MessagesClient.js +0 -81
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { parseMessageCommand } from '@ziggs-ai/contracts';
|
|
2
|
+
import { buildOperatorHeaders } from './operatorHeaders.js';
|
|
3
|
+
import { getBackendUrl } from '../utils/urlUtils.js';
|
|
4
|
+
import { throwApiError } from '../shared/apiError.js';
|
|
5
|
+
/** One command and one representation, independent of navigation. */
|
|
6
|
+
export class MessageRecordsClient {
|
|
7
|
+
operatorKey;
|
|
8
|
+
agentId;
|
|
9
|
+
baseUrl;
|
|
10
|
+
constructor(operatorKey, agentId, baseUrl) {
|
|
11
|
+
this.operatorKey = operatorKey;
|
|
12
|
+
this.agentId = agentId;
|
|
13
|
+
this.baseUrl = baseUrl;
|
|
14
|
+
}
|
|
15
|
+
async request(path, init = {}) { const res = await fetch(`${this.baseUrl ?? getBackendUrl()}/messaging/${path}`, { ...init, headers: { 'content-type': 'application/json', ...buildOperatorHeaders(this.operatorKey, this.agentId) } }); if (!res.ok)
|
|
16
|
+
throwApiError(res, await res.text().catch(() => ''), `Messaging failed: ${res.status}`); return await res.json(); }
|
|
17
|
+
async get(id) { const row = await this.request(`messages/${encodeURIComponent(id)}`); if (row.messageId !== id || !row.content || !Array.isArray(row.requestedAnswers))
|
|
18
|
+
throw new Error('Invalid exact message response'); return row; }
|
|
19
|
+
async send(command) { const result = await this.request('messages', { method: 'POST', body: JSON.stringify(parseMessageCommand(command)) }); if (!['created', 'existing'].includes(result.outcome) || !result.message?.messageId || !result.message.content || !Array.isArray(result.message.recipients) || !Array.isArray(result.message.requestedAnswers))
|
|
20
|
+
throw new Error('Invalid message command response'); return result; }
|
|
21
|
+
list(input = {}) { const query = new URLSearchParams(); for (const [key, value] of Object.entries(input))
|
|
22
|
+
if (value !== undefined)
|
|
23
|
+
query.set(key, Array.isArray(value) ? value.join(',') : String(value)); return this.request(`messages?${query}`); }
|
|
24
|
+
replies(id, input = {}) { const query = new URLSearchParams(); for (const [key, value] of Object.entries(input))
|
|
25
|
+
if (value !== undefined)
|
|
26
|
+
query.set(key, String(value)); return this.request(`messages/${encodeURIComponent(id)}/replies?${query}`); }
|
|
27
|
+
controls(agreementId, taskId) { const query = new URLSearchParams({ agreementId, ...(taskId ? { taskId } : {}) }); return this.request(`controls?${query}`); }
|
|
28
|
+
answers(id) { return this.request(`messages/${encodeURIComponent(id)}/answers`); }
|
|
29
|
+
cancelAnswer(id, requestId) { return this.request(`messages/${encodeURIComponent(id)}/answers/${encodeURIComponent(requestId)}/cancel`, { method: 'POST' }); }
|
|
30
|
+
}
|
|
@@ -8,11 +8,11 @@ export interface AssistantSessionRow {
|
|
|
8
8
|
lastSeenAt: string;
|
|
9
9
|
expiresAt: string;
|
|
10
10
|
workspaceIds: string[];
|
|
11
|
-
|
|
11
|
+
heldExecutionIds: string[];
|
|
12
12
|
awake: boolean;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* List sibling windows and hold
|
|
15
|
+
* List sibling windows and hold an execution in this one.
|
|
16
16
|
* Uses the same session headers as the inbox so "this window" is the
|
|
17
17
|
* X-Ziggs-Session the host already sends.
|
|
18
18
|
*/
|
|
@@ -23,12 +23,12 @@ export declare class SessionsClient {
|
|
|
23
23
|
private url;
|
|
24
24
|
list(): Promise<AssistantSessionRow[]>;
|
|
25
25
|
/**
|
|
26
|
-
* Hold `
|
|
26
|
+
* Hold `executionContextId` in this window (omit sessionId; server resolves from
|
|
27
27
|
* X-Ziggs-Session), move it to `sessionId`, or pass null to release.
|
|
28
28
|
*/
|
|
29
|
-
hold(
|
|
29
|
+
hold(executionContextId: string, sessionId?: string | null): Promise<{
|
|
30
30
|
success: true;
|
|
31
|
-
|
|
31
|
+
executionContextId: string;
|
|
32
32
|
sessionId: string | null;
|
|
33
33
|
}>;
|
|
34
34
|
}
|
|
@@ -2,7 +2,7 @@ import { getBackendUrl } from '../utils/urlUtils.js';
|
|
|
2
2
|
import { pollSurfaceError } from '../shared/rateLimit.js';
|
|
3
3
|
import { buildCredsHeaders } from './operatorHeaders.js';
|
|
4
4
|
/**
|
|
5
|
-
* List sibling windows and hold
|
|
5
|
+
* List sibling windows and hold an execution in this one.
|
|
6
6
|
* Uses the same session headers as the inbox so "this window" is the
|
|
7
7
|
* X-Ziggs-Session the host already sends.
|
|
8
8
|
*/
|
|
@@ -48,14 +48,14 @@ export class SessionsClient {
|
|
|
48
48
|
return Array.isArray(rows) ? rows : [];
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
* Hold `
|
|
51
|
+
* Hold `executionContextId` in this window (omit sessionId; server resolves from
|
|
52
52
|
* X-Ziggs-Session), move it to `sessionId`, or pass null to release.
|
|
53
53
|
*/
|
|
54
|
-
async hold(
|
|
55
|
-
if (!
|
|
56
|
-
throw new Error('SessionsClient.hold:
|
|
54
|
+
async hold(executionContextId, sessionId) {
|
|
55
|
+
if (!executionContextId?.trim())
|
|
56
|
+
throw new Error('SessionsClient.hold: executionContextId is required');
|
|
57
57
|
const body = {
|
|
58
|
-
|
|
58
|
+
executionContextId: executionContextId.trim(),
|
|
59
59
|
};
|
|
60
60
|
if (sessionId !== undefined)
|
|
61
61
|
body.sessionId = sessionId;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type TaskUpdateState } from '@ziggs-ai/contracts';
|
|
2
|
+
export type { TaskUpdateState } from '@ziggs-ai/contracts';
|
|
1
3
|
import type { WriteSource } from '../capabilities/sources.js';
|
|
2
4
|
import { type Creds, type Task, type TaskState } from '../types.js';
|
|
3
5
|
/**
|
|
@@ -5,6 +7,8 @@ import { type Creds, type Task, type TaskState } from '../types.js';
|
|
|
5
7
|
* getTask / ziggs_task_get.
|
|
6
8
|
*/
|
|
7
9
|
export interface TaskWriteConfirm {
|
|
10
|
+
success: true;
|
|
11
|
+
/** @deprecated Use success. */
|
|
8
12
|
ok: true;
|
|
9
13
|
taskId: string;
|
|
10
14
|
/** The agreement the task hangs under, when the server reports it. */
|
|
@@ -84,7 +88,7 @@ export interface CreateTaskData {
|
|
|
84
88
|
* server-side.
|
|
85
89
|
*/
|
|
86
90
|
assigneeId?: string;
|
|
87
|
-
/**
|
|
91
|
+
/** Required artifact handles; declaring them grants no access. */
|
|
88
92
|
inputArtifactIds?: string[];
|
|
89
93
|
/**
|
|
90
94
|
* Tasks this one waits for. The task is created immediately, but its assignee
|
|
@@ -152,9 +156,8 @@ export interface UpdateTaskStateData {
|
|
|
152
156
|
/** What the result drew on. Recorded only when a result is written. */
|
|
153
157
|
sources?: WriteSource[];
|
|
154
158
|
}
|
|
155
|
-
export declare function updateTaskState(taskId: string, state:
|
|
159
|
+
export declare function updateTaskState(taskId: string, state: TaskUpdateState, data: UpdateTaskStateData | undefined, creds: Creds): Promise<TaskWriteConfirm>;
|
|
156
160
|
export declare function getActiveTasksForAgent(agentId: string, creds: Creds): Promise<Task[]>;
|
|
157
|
-
export declare function getActiveTasksForChat(chatId: string, creds: Creds): Promise<Task[]>;
|
|
158
161
|
export declare function cancelTask(taskId: string, creds: Creds): Promise<TaskWriteConfirm>;
|
|
159
162
|
export declare function getSubtasks(parentTaskId: string, creds: Creds): Promise<Task[]>;
|
|
160
163
|
export interface PlanReplaceStep {
|
|
@@ -205,6 +208,8 @@ export interface ListTasksOptions {
|
|
|
205
208
|
limit?: number;
|
|
206
209
|
/** Filter to tasks assigned to this id. */
|
|
207
210
|
assignedTo?: string;
|
|
211
|
+
/** Stored assignee, including tasks held by dependencies. */
|
|
212
|
+
assigneeId?: string;
|
|
208
213
|
/**
|
|
209
214
|
* Filter to tasks CREATED by this id — what the caller handed out, as
|
|
210
215
|
* opposed to what was handed to it.
|
|
@@ -213,12 +218,14 @@ export interface ListTasksOptions {
|
|
|
213
218
|
}
|
|
214
219
|
export interface ListTasksResult {
|
|
215
220
|
tasks: Task[];
|
|
221
|
+
/** Number of tasks on this page, not a total across pages. */
|
|
222
|
+
count: number;
|
|
216
223
|
hasMore: boolean;
|
|
217
224
|
nextCursor?: string | null;
|
|
218
225
|
}
|
|
219
226
|
export declare function listTasks(options: ListTasksOptions | undefined, creds: Creds): Promise<ListTasksResult>;
|
|
220
227
|
export interface CountTasksFilters {
|
|
221
|
-
|
|
228
|
+
agreementId?: string;
|
|
222
229
|
state?: string;
|
|
223
230
|
userId?: string;
|
|
224
231
|
agentId?: string;
|
|
@@ -237,9 +244,8 @@ export declare class TaskClient {
|
|
|
237
244
|
children?: CreatedTaskChild[];
|
|
238
245
|
}>;
|
|
239
246
|
getTask(taskId: string): Promise<Task>;
|
|
240
|
-
updateTaskState(taskId: string, state:
|
|
247
|
+
updateTaskState(taskId: string, state: TaskUpdateState, data?: UpdateTaskStateData): Promise<TaskWriteConfirm>;
|
|
241
248
|
getActiveTasksForAgent(agentId: string): Promise<Task[]>;
|
|
242
|
-
getActiveTasksForChat(chatId: string): Promise<Task[]>;
|
|
243
249
|
cancelTask(taskId: string): Promise<TaskWriteConfirm>;
|
|
244
250
|
getSubtasks(parentTaskId: string): Promise<Task[]>;
|
|
245
251
|
replaceTaskPlan(taskId: string, steps: PlanReplaceStep[]): Promise<TaskWriteConfirm>;
|
|
@@ -250,3 +256,26 @@ export declare class TaskClient {
|
|
|
250
256
|
listTasks(options?: ListTasksOptions): Promise<ListTasksResult>;
|
|
251
257
|
countTasks(filters?: CountTasksFilters): Promise<number>;
|
|
252
258
|
}
|
|
259
|
+
/** Controlled work transfer; the source execution header is preserved. */
|
|
260
|
+
export declare function delegateTask(taskId: string, body: {
|
|
261
|
+
agreementId: string;
|
|
262
|
+
assigneeId: string;
|
|
263
|
+
instructionArtifactId: string;
|
|
264
|
+
inputArtifactIds?: string[];
|
|
265
|
+
idempotencyKey?: string;
|
|
266
|
+
}, creds: Creds): Promise<{
|
|
267
|
+
taskId: string;
|
|
268
|
+
agreementId: string;
|
|
269
|
+
parentTaskId: string;
|
|
270
|
+
}>;
|
|
271
|
+
export declare function returnTaskResult(taskId: string, artifactId: string, creds: Creds): Promise<{
|
|
272
|
+
taskId: string;
|
|
273
|
+
parentTaskId: string;
|
|
274
|
+
artifactId: string;
|
|
275
|
+
outcome: 'created' | 'existing';
|
|
276
|
+
}>;
|
|
277
|
+
export declare function refreshTaskReadiness(taskId: string, creds: Creds): Promise<{
|
|
278
|
+
taskId: string;
|
|
279
|
+
ready: boolean;
|
|
280
|
+
state: string;
|
|
281
|
+
}>;
|
package/dist/http/TaskClient.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { TASK_UPDATE_STATES } from '@ziggs-ai/contracts';
|
|
1
2
|
import { decodeOperatorKeyClaims } from '../shared/operatorKey.js';
|
|
2
3
|
import { getBackendUrl } from '../utils/urlUtils.js';
|
|
3
4
|
import { partyActorIds } from '../types.js';
|
|
4
5
|
import { throwApiError } from '../shared/apiError.js';
|
|
5
|
-
import { buildCredsHeaders } from './operatorHeaders.js';
|
|
6
|
+
import { buildCredsHeaders, withoutExecution } from './operatorHeaders.js';
|
|
6
7
|
function getTaskBaseUrl() { return `${getBackendUrl()}/tasks`; }
|
|
7
8
|
// Auth, agent and the wake's lane, from the one helper — see operatorHeaders.
|
|
8
9
|
const buildHeaders = buildCredsHeaders;
|
|
@@ -38,7 +39,9 @@ async function writeTaskControl(taskId, path, method, body, creds) {
|
|
|
38
39
|
throw new Error('Task control requires a taskId');
|
|
39
40
|
assertCreds(creds, 'task control');
|
|
40
41
|
const res = await fetch(`${getTaskBaseUrl()}/${encodeURIComponent(taskId)}/${path}`, {
|
|
41
|
-
|
|
42
|
+
// A quiescence receipt must remain possible after the task execution has
|
|
43
|
+
// been stopped. The server still checks executor identity and requestId.
|
|
44
|
+
method, headers: path === 'control/ack' ? withoutExecution(buildHeaders(creds)) : buildHeaders(creds), body: JSON.stringify(body),
|
|
42
45
|
});
|
|
43
46
|
if (!res.ok)
|
|
44
47
|
throwApiError(res, await res.text().catch(() => ''), `Task control failed: ${res.status}`);
|
|
@@ -57,6 +60,7 @@ function extractWriteConfirm(data) {
|
|
|
57
60
|
d['task'] === undefined &&
|
|
58
61
|
d['description'] === undefined) {
|
|
59
62
|
return {
|
|
63
|
+
success: true,
|
|
60
64
|
ok: true,
|
|
61
65
|
...(d['control'] ? { control: d['control'] } : {}),
|
|
62
66
|
taskId: d['taskId'],
|
|
@@ -84,6 +88,7 @@ function extractWriteConfirm(data) {
|
|
|
84
88
|
if (!task?.taskId || !task.state)
|
|
85
89
|
return null;
|
|
86
90
|
return {
|
|
91
|
+
success: true,
|
|
87
92
|
ok: true,
|
|
88
93
|
taskId: task.taskId,
|
|
89
94
|
state: task.state,
|
|
@@ -140,6 +145,9 @@ export async function updateTaskState(taskId, state, data = {}, creds) {
|
|
|
140
145
|
throw new Error('updateTaskState: taskId is required');
|
|
141
146
|
if (!state)
|
|
142
147
|
throw new Error('updateTaskState: state is required');
|
|
148
|
+
if (!TASK_UPDATE_STATES.includes(state)) {
|
|
149
|
+
throw new Error('updateTaskState accepts active, completed or failed; use cancelTask to cancel');
|
|
150
|
+
}
|
|
143
151
|
assertCreds(creds, 'task state update');
|
|
144
152
|
const res = await fetch(`${getTaskBaseUrl()}/${taskId}/state`, {
|
|
145
153
|
method: 'PATCH',
|
|
@@ -217,37 +225,6 @@ async function getActiveTasksForAgentViaPartyAgreements(agentId, creds) {
|
|
|
217
225
|
const merged = lists.flat();
|
|
218
226
|
return workable(merged.filter((t) => !t.assigneeId || t.assigneeId === agentId));
|
|
219
227
|
}
|
|
220
|
-
// Backend deliberately has no `/chats/:id/tasks` route — it's composable
|
|
221
|
-
// from links → per-agreement tasks. We do the composition here so callers
|
|
222
|
-
// don't have to.
|
|
223
|
-
export async function getActiveTasksForChat(chatId, creds) {
|
|
224
|
-
if (!chatId)
|
|
225
|
-
throw new Error('getActiveTasksForChat: chatId is required');
|
|
226
|
-
assertCreds(creds, 'getting active tasks for chat');
|
|
227
|
-
const linksRes = await fetch(`${getBackendUrl()}/agreements/by-chat/${encodeURIComponent(chatId)}`, { method: 'GET', headers: buildHeaders(creds) });
|
|
228
|
-
if (!linksRes.ok) {
|
|
229
|
-
const body = await linksRes.text().catch(() => '');
|
|
230
|
-
throwApiError(linksRes, body, `Get agreements for chat failed: ${linksRes.status} ${linksRes.statusText}`);
|
|
231
|
-
}
|
|
232
|
-
const linksData = await linksRes.json().catch(() => null);
|
|
233
|
-
const rawLinks = linksData?.['links'] ?? linksData?.['agreements'];
|
|
234
|
-
const agreements = Array.isArray(rawLinks) ? rawLinks : [];
|
|
235
|
-
const agreementIds = Array.from(new Set(agreements.map((a) => a['agreementId']).filter(Boolean)));
|
|
236
|
-
if (agreementIds.length === 0)
|
|
237
|
-
return [];
|
|
238
|
-
const lists = await Promise.all(agreementIds.map(async (aid) => {
|
|
239
|
-
const url = new URL(`${getBackendUrl()}/agreements/${encodeURIComponent(aid)}/tasks`);
|
|
240
|
-
url.searchParams.set('state', 'active');
|
|
241
|
-
const res = await fetch(url.toString(), { method: 'GET', headers: buildHeaders(creds) });
|
|
242
|
-
if (!res.ok) {
|
|
243
|
-
const body = await res.text().catch(() => '');
|
|
244
|
-
throwApiError(res, body, `Get tasks for agreement ${aid} failed: ${res.status}`);
|
|
245
|
-
}
|
|
246
|
-
const data = await res.json().catch(() => null);
|
|
247
|
-
return Array.isArray(data?.['tasks']) ? data['tasks'] : [];
|
|
248
|
-
}));
|
|
249
|
-
return lists.flat();
|
|
250
|
-
}
|
|
251
228
|
export async function cancelTask(taskId, creds) {
|
|
252
229
|
if (!taskId)
|
|
253
230
|
throw new Error('cancelTask: taskId is required');
|
|
@@ -424,6 +401,8 @@ export async function listTasks(options = {}, creds) {
|
|
|
424
401
|
url.searchParams.set('limit', String(options.limit));
|
|
425
402
|
if (options.assignedTo)
|
|
426
403
|
url.searchParams.set('assignedTo', options.assignedTo);
|
|
404
|
+
if (options.assigneeId)
|
|
405
|
+
url.searchParams.set('assigneeId', options.assigneeId);
|
|
427
406
|
if (options.createdBy)
|
|
428
407
|
url.searchParams.set('createdBy', options.createdBy);
|
|
429
408
|
const res = await fetch(url.toString(), {
|
|
@@ -438,6 +417,7 @@ export async function listTasks(options = {}, creds) {
|
|
|
438
417
|
const tasks = Array.isArray(data?.['tasks']) ? data['tasks'] : [];
|
|
439
418
|
return {
|
|
440
419
|
tasks,
|
|
420
|
+
count: tasks.length,
|
|
441
421
|
hasMore: Boolean(data?.['hasMore']),
|
|
442
422
|
nextCursor: data?.['nextCursor'] ?? null,
|
|
443
423
|
};
|
|
@@ -446,8 +426,8 @@ export async function countTasks(filters = {}, creds) {
|
|
|
446
426
|
assertCreds(creds, 'count tasks');
|
|
447
427
|
// Canonical REST: GET /tasks/count.
|
|
448
428
|
const url = new URL(`${getTaskBaseUrl()}/count`);
|
|
449
|
-
if (filters.
|
|
450
|
-
url.searchParams.set('
|
|
429
|
+
if (filters.agreementId)
|
|
430
|
+
url.searchParams.set('agreementId', filters.agreementId);
|
|
451
431
|
if (filters.state)
|
|
452
432
|
url.searchParams.set('state', filters.state);
|
|
453
433
|
if (filters.userId)
|
|
@@ -487,7 +467,6 @@ export class TaskClient {
|
|
|
487
467
|
getTask(taskId) { return getTask(taskId, this.creds); }
|
|
488
468
|
updateTaskState(taskId, state, data) { return updateTaskState(taskId, state, data ?? {}, this.creds); }
|
|
489
469
|
getActiveTasksForAgent(agentId) { return getActiveTasksForAgent(agentId, this.creds); }
|
|
490
|
-
getActiveTasksForChat(chatId) { return getActiveTasksForChat(chatId, this.creds); }
|
|
491
470
|
cancelTask(taskId) { return cancelTask(taskId, this.creds); }
|
|
492
471
|
getSubtasks(parentTaskId) { return getSubtasks(parentTaskId, this.creds); }
|
|
493
472
|
replaceTaskPlan(taskId, steps) { return replaceTaskPlan(taskId, steps, this.creds); }
|
|
@@ -498,3 +477,26 @@ export class TaskClient {
|
|
|
498
477
|
listTasks(options) { return listTasks(options ?? {}, this.creds); }
|
|
499
478
|
countTasks(filters) { return countTasks(filters, this.creds); }
|
|
500
479
|
}
|
|
480
|
+
/** Controlled work transfer; the source execution header is preserved. */
|
|
481
|
+
export async function delegateTask(taskId, body, creds) {
|
|
482
|
+
const { idempotencyKey, ...payload } = body;
|
|
483
|
+
return taskTransfer(taskId, 'delegations', payload, creds, idempotencyKey);
|
|
484
|
+
}
|
|
485
|
+
export async function returnTaskResult(taskId, artifactId, creds) {
|
|
486
|
+
return taskTransfer(taskId, 'return', { artifactId }, creds);
|
|
487
|
+
}
|
|
488
|
+
export async function refreshTaskReadiness(taskId, creds) {
|
|
489
|
+
return taskTransfer(taskId, 'readiness', {}, creds);
|
|
490
|
+
}
|
|
491
|
+
async function taskTransfer(taskId, path, body, creds, key) {
|
|
492
|
+
assertCreds(creds, 'task transfer');
|
|
493
|
+
if (!taskId)
|
|
494
|
+
throw new Error('taskId is required');
|
|
495
|
+
const headers = buildHeaders(creds);
|
|
496
|
+
if (key)
|
|
497
|
+
headers['Idempotency-Key'] = key;
|
|
498
|
+
const res = await fetch(`${getTaskBaseUrl()}/${encodeURIComponent(taskId)}/${path}`, { method: 'POST', headers, body: JSON.stringify(body) });
|
|
499
|
+
if (!res.ok)
|
|
500
|
+
throwApiError(res, await res.text().catch(() => ''), `Task transfer failed: ${res.status}`);
|
|
501
|
+
return res.json();
|
|
502
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ClaimedKind, type ClaimOptions, type
|
|
1
|
+
import { type ClaimedKind, type ClaimOptions, type ProposeTerms } from './AgreementClient.js';
|
|
2
2
|
import { type Agreement, type Creds, type EngagementKind } from '../types.js';
|
|
3
3
|
/**
|
|
4
4
|
* one propose grammar. Direct, broadcast (request and standing
|
|
@@ -13,7 +13,7 @@ import { type Agreement, type Creds, type EngagementKind } from '../types.js';
|
|
|
13
13
|
export interface UnifiedProposeInput extends ProposeTerms {
|
|
14
14
|
proposedTo: string;
|
|
15
15
|
/** Required on direct proposals; optional on broadcasts/links. */
|
|
16
|
-
|
|
16
|
+
addressId?: string;
|
|
17
17
|
engagementKind?: EngagementKind;
|
|
18
18
|
}
|
|
19
19
|
export type ProposeShape = 'direct' | 'request' | 'offer';
|
|
@@ -38,5 +38,4 @@ export declare function proposeUnified(input: UnifiedProposeInput, creds: Creds)
|
|
|
38
38
|
export declare function claimOpenAgreement(agreementId: string, creds: Creds, opts?: ClaimOptions): Promise<{
|
|
39
39
|
agreement: Agreement;
|
|
40
40
|
kind: ClaimedKind;
|
|
41
|
-
room?: ClaimRoom;
|
|
42
41
|
}>;
|
|
@@ -2,7 +2,7 @@ import { claimAgreement, proposeBroadcast, proposeDirectTo, } from './AgreementC
|
|
|
2
2
|
import { publishOffer } from './MarketplaceClient.js';
|
|
3
3
|
import { isBroadcastTarget, } from '../types.js';
|
|
4
4
|
export async function proposeUnified(input, creds) {
|
|
5
|
-
const { proposedTo,
|
|
5
|
+
const { proposedTo, addressId, engagementKind, providerId, ...terms } = input;
|
|
6
6
|
if (!proposedTo)
|
|
7
7
|
throw new Error('proposedTo is required (a user/agent id, or "everyone"/"org"/"company" to broadcast)');
|
|
8
8
|
// The 'link' arm is gone. A link is not a proposal shape: it has no
|
|
@@ -34,7 +34,7 @@ export async function proposeUnified(input, creds) {
|
|
|
34
34
|
// Buyer-broadcast: the claimer works, your side pays — an open request.
|
|
35
35
|
const agreement = await proposeBroadcast({
|
|
36
36
|
...terms,
|
|
37
|
-
|
|
37
|
+
addressId: addressId ?? '',
|
|
38
38
|
engagementKind: engagementKind ?? 'service',
|
|
39
39
|
audience,
|
|
40
40
|
}, creds);
|
|
@@ -51,7 +51,7 @@ export async function proposeUnified(input, creds) {
|
|
|
51
51
|
proposedTo,
|
|
52
52
|
// Omitted rather than sent empty: an absent field says "no room", and an
|
|
53
53
|
// empty string is one more fiction for the server to interpret.
|
|
54
|
-
...(
|
|
54
|
+
...(addressId ? { addressId } : {}),
|
|
55
55
|
providerId: providerId?.trim() || proposedTo,
|
|
56
56
|
engagementKind: engagementKind ?? 'service',
|
|
57
57
|
}, creds);
|
|
@@ -74,8 +74,8 @@ export async function proposeUnified(input, creds) {
|
|
|
74
74
|
export async function claimOpenAgreement(agreementId, creds, opts = {}) {
|
|
75
75
|
if (!agreementId)
|
|
76
76
|
throw new Error('agreementId is required');
|
|
77
|
-
const { agreement, kind
|
|
77
|
+
const { agreement, kind } = await claimAgreement(agreementId, creds, opts);
|
|
78
78
|
// A server that has not shipped the `kind` field yet still claims correctly;
|
|
79
79
|
// 'request' is the shape the route has always handled.
|
|
80
|
-
return { agreement, kind: kind ?? 'request'
|
|
80
|
+
return { agreement, kind: kind ?? 'request' };
|
|
81
81
|
}
|
package/dist/http/index.d.ts
CHANGED
|
@@ -2,13 +2,10 @@ export * from './TaskClient.js';
|
|
|
2
2
|
export * from './AgreementClient.js';
|
|
3
3
|
export * from './MarketplaceClient.js';
|
|
4
4
|
export * from './agreementFlows.js';
|
|
5
|
-
export
|
|
6
|
-
export { MessagesClient, messagesListUrl } from './MessagesClient.js';
|
|
7
|
-
export type { ListMessagesOptions, ListMessagesResult } from './MessagesClient.js';
|
|
8
|
-
export { ArtifactsClient, artifactScopeForSession, AGREEMENT_LANE_PREFIX, ARTIFACT_INLINE_TEXT_MAX_CHARS, ARTIFACT_INLINE_TEXT_OVER_LIMIT_HINT, } from './ArtifactsClient.js';
|
|
5
|
+
export { ArtifactsClient, artifactScope, AGREEMENT_LANE_PREFIX, ARTIFACT_INLINE_TEXT_MAX_CHARS, ARTIFACT_INLINE_TEXT_OVER_LIMIT_HINT, } from './ArtifactsClient.js';
|
|
9
6
|
export type { ArtifactVisibility, ListArtifactsOptions, ListArtifactsQuery, ListArtifactsResult, WriteArtifactInput, } from './ArtifactsClient.js';
|
|
10
7
|
export { ContextReadClient, CONTEXT_READ_TYPES, CONTEXT_READ_VIA, VIA_KINDS, parseVia, viaHint, } from './ContextReadClient.js';
|
|
11
|
-
export type { ContextReadType, ContextReadQuery, ContextReadEnvelope, ContextSnapshotResult, ContextSnapshotParticipant, ViaKind, } from './ContextReadClient.js';
|
|
8
|
+
export type { ContextReadType, ContextReadQuery, ContextReadEnvelope, ContextSnapshotResult, ContextSnapshotQuery, ContextSnapshotParticipant, ViaKind, } from './ContextReadClient.js';
|
|
12
9
|
export { ContextOpenClient, CONTEXT_OPEN_KINDS } from './ContextOpenClient.js';
|
|
13
10
|
export type { ContextOpenKind, ContextOpenOutcome, ContextOpenRef, ContextOpenBody, ResourceAction, ResourceActionCall, ContextOpenAccess, ContextOpenResult, ContextExplainResult, } from './ContextOpenClient.js';
|
|
14
11
|
export { ContextDiscoveryClient } from './ContextDiscoveryClient.js';
|
|
@@ -37,3 +34,4 @@ export { planInboxAck, planPartialInboxAck, inboxAckAllowed, inboxAckHandledIds,
|
|
|
37
34
|
export type { InboxAckDecision, InboxAckStep, InboxAckEnvelope, PlanInboxAckOptions, } from '../inboxAck.js';
|
|
38
35
|
export { laneUnderAgreement, buildOperatorHeaders, buildCredsHeaders, } from './operatorHeaders.js';
|
|
39
36
|
export { backendToolPick, type ToolPickOption, type ToolPickAnswer, type PickTool } from './ToolPickClient.js';
|
|
37
|
+
export * from './MessageRecordsClient.js';
|
package/dist/http/index.js
CHANGED
|
@@ -2,11 +2,9 @@ export * from './TaskClient.js';
|
|
|
2
2
|
export * from './AgreementClient.js';
|
|
3
3
|
export * from './MarketplaceClient.js';
|
|
4
4
|
export * from './agreementFlows.js';
|
|
5
|
-
export * from './ChatClient.js';
|
|
6
|
-
export { MessagesClient, messagesListUrl } from './MessagesClient.js';
|
|
7
5
|
export { ArtifactsClient,
|
|
8
|
-
//
|
|
9
|
-
|
|
6
|
+
// Artifact writes name their conversation or work; a lane is never one.
|
|
7
|
+
artifactScope, AGREEMENT_LANE_PREFIX, ARTIFACT_INLINE_TEXT_MAX_CHARS, ARTIFACT_INLINE_TEXT_OVER_LIMIT_HINT, } from './ArtifactsClient.js';
|
|
10
8
|
export { ContextReadClient, CONTEXT_READ_TYPES, CONTEXT_READ_VIA, VIA_KINDS, parseVia, viaHint, } from './ContextReadClient.js';
|
|
11
9
|
export { ContextOpenClient, CONTEXT_OPEN_KINDS } from './ContextOpenClient.js';
|
|
12
10
|
export { ContextDiscoveryClient } from './ContextDiscoveryClient.js';
|
|
@@ -28,3 +26,4 @@ export { planInboxAck, planPartialInboxAck, inboxAckAllowed, inboxAckHandledIds,
|
|
|
28
26
|
// copy of a header nobody notices missing goes stale unseen.
|
|
29
27
|
export { laneUnderAgreement, buildOperatorHeaders, buildCredsHeaders, } from './operatorHeaders.js';
|
|
30
28
|
export { backendToolPick } from './ToolPickClient.js';
|
|
29
|
+
export * from './MessageRecordsClient.js';
|
|
@@ -12,6 +12,9 @@ type AssistantHints = {
|
|
|
12
12
|
};
|
|
13
13
|
/** Node-only, opt-in request context. Ordinary HTTP clients remain browser-safe. */
|
|
14
14
|
export declare function withAssistantRequest<T>(hints: AssistantHints, run: () => T): Promise<Awaited<T>>;
|
|
15
|
+
/** Start an autonomous callback with no inherited execution, attempt or assistant hints.
|
|
16
|
+
* This is an entry boundary, never a retry of a refused scoped operation. */
|
|
17
|
+
export declare function withAutonomousRequest<T>(run: () => T): Promise<Awaited<T>>;
|
|
15
18
|
export declare function assistantRequestHeaders(): Record<string, string>;
|
|
16
19
|
/** A presentation routing key; it carries no authority. */
|
|
17
20
|
export declare function laneUnderAgreement(laneId: string, agreementId?: string | null): string;
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
let assistantRequest;
|
|
2
2
|
let assistantContextLoading;
|
|
3
|
-
|
|
4
|
-
export async function withAssistantRequest(hints, run) {
|
|
3
|
+
async function requestContext() {
|
|
5
4
|
assistantContextLoading ??= import('node:async_hooks').then(({ AsyncLocalStorage }) => {
|
|
6
5
|
assistantRequest = new AsyncLocalStorage();
|
|
7
6
|
return assistantRequest;
|
|
8
7
|
});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
return assistantContextLoading;
|
|
9
|
+
}
|
|
10
|
+
/** Node-only, opt-in request context. Ordinary HTTP clients remain browser-safe. */
|
|
11
|
+
export async function withAssistantRequest(hints, run) {
|
|
12
|
+
const context = await requestContext();
|
|
12
13
|
return await context.run({ ...context.getStore(), ...hints, orgId: hints.orgId, resource: hints.resource }, run);
|
|
13
14
|
}
|
|
15
|
+
/** Start an autonomous callback with no inherited execution, attempt or assistant hints.
|
|
16
|
+
* This is an entry boundary, never a retry of a refused scoped operation. */
|
|
17
|
+
export async function withAutonomousRequest(run) {
|
|
18
|
+
return await (await requestContext()).run({}, run);
|
|
19
|
+
}
|
|
14
20
|
export function assistantRequestHeaders() {
|
|
15
21
|
const hints = assistantRequest?.getStore();
|
|
16
22
|
return {
|
|
23
|
+
...(hints?.executionContext?.attemptId ? { 'X-Ziggs-Attempt': hints.executionContext.attemptId } : {}),
|
|
17
24
|
...((hints?.executionContextId ?? hints?.executionContext?.contextId) ? { 'X-Ziggs-Execution': (hints?.executionContextId ?? hints?.executionContext?.contextId) } : {}),
|
|
18
25
|
...(hints?.orgId ? { 'X-Workspace-Id': hints.orgId } : {}),
|
|
19
26
|
...(hints?.resource ? { 'X-Ziggs-Resource': hints.resource } : {}),
|
|
@@ -49,6 +56,8 @@ export function withoutExecution(headers) {
|
|
|
49
56
|
const out = { ...headers };
|
|
50
57
|
delete out['X-Ziggs-Execution'];
|
|
51
58
|
delete out['x-ziggs-execution'];
|
|
59
|
+
delete out['X-Ziggs-Attempt'];
|
|
60
|
+
delete out['x-ziggs-attempt'];
|
|
52
61
|
return out;
|
|
53
62
|
}
|
|
54
63
|
/** What a `Creds`-shaped client sends on a JSON call: auth, agent, lane. */
|
package/dist/inboxAck.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export interface InboxAckEnvelope {
|
|
|
3
3
|
ackTo?: string | null;
|
|
4
4
|
deliveries?: ReadonlyArray<{
|
|
5
5
|
resourceId?: string | null;
|
|
6
|
-
|
|
6
|
+
receiptId?: string | null;
|
|
7
7
|
assigneeId?: string | null;
|
|
8
8
|
outOfReach?: unknown;
|
|
9
9
|
executionBlocked?: unknown;
|
|
@@ -12,7 +12,7 @@ export interface InboxAckEnvelope {
|
|
|
12
12
|
}>;
|
|
13
13
|
openRequestsAwaitingMe?: ReadonlyArray<{
|
|
14
14
|
agreementId?: string | null;
|
|
15
|
-
|
|
15
|
+
receiptId?: string | null;
|
|
16
16
|
ts?: string | null;
|
|
17
17
|
}>;
|
|
18
18
|
}
|
package/dist/inboxAck.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export function inboxAckHandledIds(envelope, ownAgentId, ownAgentIds) {
|
|
2
2
|
const mine = (id) => ownAgentIds ? ownAgentIds.includes(id ?? '') : ownAgentId ? id === ownAgentId : !!id;
|
|
3
3
|
return [...new Set([
|
|
4
|
-
...(envelope.deliveries ?? []).filter(d => mine(d.assigneeId) && !d.outOfReach && !d.executionBlocked).map(d => d.
|
|
5
|
-
...(envelope.openRequestsAwaitingMe ?? []).map(r => r.
|
|
4
|
+
...(envelope.deliveries ?? []).filter(d => mine(d.assigneeId) && !d.outOfReach && !d.executionBlocked).map(d => d.receiptId),
|
|
5
|
+
...(envelope.openRequestsAwaitingMe ?? []).map(r => r.receiptId),
|
|
6
6
|
].filter((id) => !!id))];
|
|
7
7
|
}
|
|
8
8
|
export function inboxAckAllowed(envelope, opts = {}) {
|
package/dist/index.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ export type { DelegateEnv, ResolvedDelegateCreds, } from './shared/delegateCreds
|
|
|
13
13
|
export { RateLimitedError, isRateLimited, parseRetryAfterMs, pollSurfaceError, } from './shared/rateLimit.js';
|
|
14
14
|
export { parseErrorMessage, parseErrorCode, throwApiError, } from './shared/apiError.js';
|
|
15
15
|
export { ApiError } from './types.js';
|
|
16
|
-
export type { Creds, Task, TaskState, PlanStep, PlanStepStatus, Agreement, AgreementParties, AgreementPartySide, EngagementKind, BroadcastAudience, EntryType, ContentType,
|
|
17
|
-
export type { ProposeTerms, ProposeDirectInput, ProposeBroadcastInput, ProposeAgreementData, ClaimOptions,
|
|
16
|
+
export type { Creds, Task, TaskState, PlanStep, PlanStepStatus, Agreement, AgreementParties, AgreementPartySide, EngagementKind, BroadcastAudience, EntryType, ContentType, InboxDeliveryKind, InboxDeliveryRef, InboxChatNews, InboxProposalRef, InboxTaskRef, InboxRequestRef, InboxPlanAckRef, InboxConnectionRequestRef, InboxHumanAttention, InboxEnvelope, InboxAckResult, InboxPeek, InboxReadOptions, } from './types.js';
|
|
17
|
+
export type { ProposeTerms, ProposeDirectInput, ProposeBroadcastInput, ProposeAgreementData, ClaimOptions, } from './http/AgreementClient.js';
|
|
18
18
|
export { decisionWords, speakableActor } from './decisionWords.js';
|
|
19
19
|
export type { DecisionOutcome, DecisionWords, DecisionWordsInput, } from './decisionWords.js';
|
|
20
20
|
export { planInboxAck, planPartialInboxAck, inboxAckAllowed, inboxAckHandledIds, } from './inboxAck.js';
|
|
@@ -31,9 +31,9 @@ export { inboxEngagement, isEchoOrDuplicate, isHireWorkOrder, contactPath, forma
|
|
|
31
31
|
export type { EngagementGuide, EngagementGuideKind, EngagementOutcome, EngagementTaskHint, ContactPathInput, FormationInput, GraphHonesty, HireTermsHonesty, WaitingOn, } from './engagementGuide.js';
|
|
32
32
|
export { isContextAccessRequest } from './shared/contextAccessRequest.js';
|
|
33
33
|
export { AssistantConnectionClient, type AssistantWorkspace, type McpEventStatus, } from './http/AssistantConnectionClient.js';
|
|
34
|
-
export { withAssistantRequest, assistantRequestHeaders } from './http/operatorHeaders.js';
|
|
34
|
+
export { withAssistantRequest, withAutonomousRequest, assistantRequestHeaders } from './http/operatorHeaders.js';
|
|
35
35
|
export { HANDLE_ALPHABET, findHandles, looksLikeHandle, parseHandle, parseRef, type HandleKind } from './handles.js';
|
|
36
36
|
export { describeOperationError, type OperationError } from './shared/operationError.js';
|
|
37
37
|
export { withWorkExecution, withWorkExecutionId, currentWorkExecution, withoutExecution } from './http/operatorHeaders.js';
|
|
38
38
|
export { deliveryHandlingId, type WorkExecutionContext, type WorkPositionView } from '@ziggs-ai/contracts';
|
|
39
|
-
export { validateWorkExecution } from './http/ExecutionContextClient.js';
|
|
39
|
+
export { validateWorkExecution, prepareWorkExecution, runWorkExecution } from './http/ExecutionContextClient.js';
|
package/dist/index.js
CHANGED
|
@@ -28,10 +28,10 @@ export { sessionOrientation, } from './sessionOrientation.js';
|
|
|
28
28
|
export { inboxEngagement, isEchoOrDuplicate, isHireWorkOrder, contactPath, formationGuide, marketplaceFormation, liveHireChangedTerms, liveHireConflictFromStatus, withdrawHeldGraph, reminderHonesty, graphReleaseHonesty, hintsFromTasks, } from './engagementGuide.js';
|
|
29
29
|
export { isContextAccessRequest } from './shared/contextAccessRequest.js';
|
|
30
30
|
export { AssistantConnectionClient, } from './http/AssistantConnectionClient.js';
|
|
31
|
-
export { withAssistantRequest, assistantRequestHeaders } from './http/operatorHeaders.js';
|
|
31
|
+
export { withAssistantRequest, withAutonomousRequest, assistantRequestHeaders } from './http/operatorHeaders.js';
|
|
32
32
|
// Short handles: T…, A…, C…, F… (task, agreement, chat, artifact).
|
|
33
33
|
export { HANDLE_ALPHABET, findHandles, looksLikeHandle, parseHandle, parseRef } from './handles.js';
|
|
34
34
|
export { describeOperationError } from './shared/operationError.js';
|
|
35
35
|
export { withWorkExecution, withWorkExecutionId, currentWorkExecution, withoutExecution } from './http/operatorHeaders.js';
|
|
36
36
|
export { deliveryHandlingId } from '@ziggs-ai/contracts';
|
|
37
|
-
export { validateWorkExecution } from './http/ExecutionContextClient.js';
|
|
37
|
+
export { validateWorkExecution, prepareWorkExecution, runWorkExecution } from './http/ExecutionContextClient.js';
|