@ziggs-ai/api-client 0.1.17 → 0.1.18

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.
@@ -1,6 +1,5 @@
1
1
  import 'dotenv/config';
2
2
  import { type Creds, type Agreement, type EngagementKind, type BroadcastAudience } from '../types.js';
3
- import { type PublishToLedgerPayload } from './TaskClient.js';
4
3
  export type PlanReviewTiming = 'with_proposal' | 'before_execution';
5
4
  /**
6
5
  * Shared proposal terms. When `engagementKind` is omitted the server defaults to `service`.
@@ -160,13 +159,6 @@ export declare function claimAgreement(agreementId: string, creds: Creds): Promi
160
159
  ok: boolean;
161
160
  agreement: Agreement;
162
161
  }>;
163
- /**
164
- * @deprecated Use {@link claimAgreement} — same endpoint, clearer name for link + quest.
165
- */
166
- export declare function claimLink(agreementId: string, creds: Creds): Promise<{
167
- ok: boolean;
168
- agreement: Agreement;
169
- }>;
170
162
  export declare function getAgreementsByChat(chatId: string, creds: Creds): Promise<unknown[]>;
171
163
  export type ChatLinkType = 'origin' | 'mention' | 'delegation' | 'join';
172
164
  export declare function linkAgreementToChat(agreementId: string, chatId: string, linkType: ChatLinkType | undefined, creds: Creds): Promise<unknown | null>;
@@ -182,40 +174,6 @@ export declare function getArtifactsForAgreement(agreementId: string, creds: Cre
182
174
  export type UserRole = 'payer' | 'provider' | 'participant' | 'observer';
183
175
  export declare function linkUserToAgreement(agreementId: string, userId: string, role: UserRole, creds: Creds): Promise<unknown | null>;
184
176
  export declare function getUsersForAgreement(agreementId: string, creds: Creds): Promise<unknown[]>;
185
- /** @deprecated Routing is expressed via `proposedTo` (a specific principal id vs a broadcast sentinel — `OPEN_AGREEMENT_TARGET` ('everyone') or `ORG_AGREEMENT_TARGET` ('org')), not engagementKind. */
186
- export type ContractKind = 'direct' | 'delegate' | 'open';
187
- interface ContractBase extends Omit<ProposeTerms, 'description'> {
188
- description: string;
189
- }
190
- interface DirectContract extends ProposeDirectInput {
191
- kind: 'direct';
192
- }
193
- interface DelegateContract extends ContractBase {
194
- kind: 'delegate';
195
- executorId: string;
196
- chatId: string;
197
- parentAgreementId: string;
198
- parentTaskId?: string;
199
- payerId?: string;
200
- }
201
- interface OpenContract extends ContractBase {
202
- kind: 'open';
203
- chatId?: string;
204
- payerId?: string;
205
- parentTaskId?: string;
206
- }
207
- export type CreateContractInput = DirectContract | DelegateContract | OpenContract;
208
- /**
209
- * @deprecated Prefer {@link proposeDirectTo}, {@link proposeBroadcast},
210
- * {@link delegateAgreement}, or {@link publishOpenQuest}.
211
- */
212
- export declare function createContract(input: CreateContractInput, creds: Creds): Promise<Agreement>;
213
- /**
214
- * Publish a buyer-broadcast quest to the marketplace ledger (Store "Wanted").
215
- * Pass `payload.audience: 'org'` to scope it to your active org (default
216
- * `'everyone'`, fully public).
217
- */
218
- export declare function publishOpenQuest(payload: PublishToLedgerPayload, creds: Creds): Promise<Agreement>;
219
177
  export declare class AgreementClient {
220
178
  private creds;
221
179
  constructor(operatorKey: string, agentId: string);
@@ -242,11 +200,6 @@ export declare class AgreementClient {
242
200
  ok: boolean;
243
201
  agreement: Agreement;
244
202
  }>;
245
- /** @deprecated use claimAgreement */
246
- claimLink(id: string): Promise<{
247
- ok: boolean;
248
- agreement: Agreement;
249
- }>;
250
203
  listByChat(chatId: string): Promise<unknown[]>;
251
204
  linkToChat(id: string, chatId: string, linkType?: ChatLinkType): Promise<unknown>;
252
205
  listChats(id: string): Promise<unknown[]>;
@@ -260,4 +213,3 @@ export declare class AgreementClient {
260
213
  linkUser(id: string, userId: string, role: UserRole): Promise<unknown>;
261
214
  listUsers(id: string): Promise<unknown[]>;
262
215
  }
263
- export {};
@@ -2,7 +2,6 @@ import 'dotenv/config';
2
2
  import { runtimeLog } from '../shared/runtimeLog.js';
3
3
  import { getBackendUrl } from '../utils/urlUtils.js';
4
4
  import { OPEN_AGREEMENT_TARGET, ORG_AGREEMENT_TARGET, isBroadcastTarget, ApiError } from '../types.js';
5
- import { publishToLedger } from './TaskClient.js';
6
5
  // Lazy: read at call time so dotenv loaded after this module is imported
7
6
  // still takes effect. Baking it at module-load time would freeze the URL
8
7
  // before the caller's dotenv.config() runs.
@@ -374,12 +373,6 @@ export async function claimAgreement(agreementId, creds) {
374
373
  }
375
374
  return data;
376
375
  }
377
- /**
378
- * @deprecated Use {@link claimAgreement} — same endpoint, clearer name for link + quest.
379
- */
380
- export async function claimLink(agreementId, creds) {
381
- return claimAgreement(agreementId, creds);
382
- }
383
376
  // ---------------------------------------------------------------------------
384
377
  // Chat links
385
378
  // ---------------------------------------------------------------------------
@@ -556,27 +549,6 @@ export async function getUsersForAgreement(agreementId, creds) {
556
549
  return [];
557
550
  }
558
551
  }
559
- /**
560
- * @deprecated Prefer {@link proposeDirectTo}, {@link proposeBroadcast},
561
- * {@link delegateAgreement}, or {@link publishOpenQuest}.
562
- */
563
- export async function createContract(input, creds) {
564
- assertCreds(creds, 'contract creation');
565
- const { kind, ...rest } = input;
566
- if (kind === 'direct')
567
- return proposeDirectTo(rest, creds);
568
- if (kind === 'delegate')
569
- return delegateAgreement(rest, creds);
570
- return publishOpenQuest(rest, creds);
571
- }
572
- /**
573
- * Publish a buyer-broadcast quest to the marketplace ledger (Store "Wanted").
574
- * Pass `payload.audience: 'org'` to scope it to your active org (default
575
- * `'everyone'`, fully public).
576
- */
577
- export async function publishOpenQuest(payload, creds) {
578
- return publishToLedger(payload, creds);
579
- }
580
552
  export class AgreementClient {
581
553
  creds;
582
554
  constructor(operatorKey, agentId) {
@@ -600,8 +572,6 @@ export class AgreementClient {
600
572
  create(data) { return createAgreement(data, this.creds); }
601
573
  revoke(id) { return revokeAgreement(id, this.creds); }
602
574
  claimAgreement(id) { return claimAgreement(id, this.creds); }
603
- /** @deprecated use claimAgreement */
604
- claimLink(id) { return claimAgreement(id, this.creds); }
605
575
  listByChat(chatId) { return getAgreementsByChat(chatId, this.creds); }
606
576
  linkToChat(id, chatId, linkType) { return linkAgreementToChat(id, chatId, linkType ?? 'mention', this.creds); }
607
577
  listChats(id) { return getChatsForAgreement(id, this.creds); }
@@ -19,10 +19,31 @@ export interface PullOffersOptions {
19
19
  }
20
20
  export declare function pullOffers(options: PullOffersOptions | undefined, creds: Creds): Promise<Agreement[]>;
21
21
  export declare function claimOffer(agreementId: string, creds: Creds): Promise<Agreement>;
22
+ export interface PublishQuestPayload {
23
+ description: string;
24
+ chatId?: string;
25
+ payerId?: string;
26
+ parentTaskId?: string;
27
+ price?: number;
28
+ lifecycle?: string;
29
+ expiresAt?: string;
30
+ maxExecutions?: number;
31
+ agreementDescription?: string;
32
+ /** Broadcast audience: 'everyone' (default, fully public) or 'org' (members of your active org only). */
33
+ audience?: BroadcastAudience;
34
+ }
35
+ export declare function publishQuest(payload: PublishQuestPayload, creds: Creds): Promise<Agreement>;
36
+ export interface PullQuestsOptions {
37
+ limit?: number;
38
+ since?: string;
39
+ }
40
+ export declare function pullQuests(options: PullQuestsOptions | undefined, creds: Creds): Promise<Agreement[]>;
22
41
  export declare class MarketplaceClient {
23
42
  private creds;
24
43
  constructor(operatorKey: string, agentId: string);
25
44
  publishOffer(payload: PublishOfferPayload): Promise<Agreement>;
26
45
  pullOffers(options?: PullOffersOptions): Promise<Agreement[]>;
27
46
  claimOffer(agreementId: string): Promise<Agreement>;
47
+ publishQuest(payload: PublishQuestPayload): Promise<Agreement>;
48
+ pullQuests(options?: PullQuestsOptions): Promise<Agreement[]>;
28
49
  }
@@ -75,6 +75,41 @@ export async function claimOffer(agreementId, creds) {
75
75
  throw new Error(data?.['error'] || 'Claim failed');
76
76
  return data['offer'];
77
77
  }
78
+ export async function publishQuest(payload, creds) {
79
+ assertCreds(creds, 'quest publish');
80
+ const res = await fetch(`${getMarketplaceBaseUrl()}/quests/publish`, {
81
+ method: 'POST',
82
+ headers: buildHeaders(creds),
83
+ body: JSON.stringify(payload || {}),
84
+ });
85
+ if (!res.ok) {
86
+ const body = await res.text().catch(() => '');
87
+ throwApiError(res, body, `Quest publish failed: ${res.status}`);
88
+ }
89
+ const data = await res.json().catch(() => null);
90
+ if (!data?.['agreement'])
91
+ throw new Error('Quest publish returned no agreement');
92
+ return data['agreement'];
93
+ }
94
+ export async function pullQuests(options, creds) {
95
+ assertCreds(creds, 'quest pull');
96
+ const params = new URLSearchParams();
97
+ if (options?.limit != null)
98
+ params.set('limit', String(options.limit));
99
+ if (options?.since)
100
+ params.set('since', options.since);
101
+ const qs = params.toString();
102
+ const res = await fetch(`${getMarketplaceBaseUrl()}/quests${qs ? `?${qs}` : ''}`, {
103
+ method: 'GET',
104
+ headers: buildHeaders(creds),
105
+ });
106
+ if (!res.ok) {
107
+ const body = await res.text().catch(() => '');
108
+ throwApiError(res, body, `Quest pull failed: ${res.status}`);
109
+ }
110
+ const data = await res.json().catch(() => null);
111
+ return data?.['agreements'] ?? [];
112
+ }
78
113
  export class MarketplaceClient {
79
114
  creds;
80
115
  constructor(operatorKey, agentId) {
@@ -87,4 +122,6 @@ export class MarketplaceClient {
87
122
  publishOffer(payload) { return publishOffer(payload, this.creds); }
88
123
  pullOffers(options) { return pullOffers(options, this.creds); }
89
124
  claimOffer(agreementId) { return claimOffer(agreementId, this.creds); }
125
+ publishQuest(payload) { return publishQuest(payload, this.creds); }
126
+ pullQuests(options) { return pullQuests(options, this.creds); }
90
127
  }
@@ -1,11 +1,13 @@
1
1
  import 'dotenv/config';
2
- import { type Creds, type Task, type TaskState, type Agreement, type BroadcastAudience } from '../types.js';
2
+ import { type Creds, type Task, type TaskState } from '../types.js';
3
3
  export interface CreateTaskData {
4
4
  description: string;
5
5
  agreementId: string;
6
6
  parentTaskId?: string;
7
7
  plan?: unknown;
8
8
  idempotencyKey?: string;
9
+ /** Explicit delegation target (ZIG-586) — must be a party to the agreement; validated server-side. */
10
+ assigneeId?: string;
9
11
  }
10
12
  export declare function createTask(taskData: CreateTaskData, creds: Creds): Promise<Task>;
11
13
  export declare function getTask(taskId: string, creds: Creds): Promise<Task>;
@@ -24,34 +26,14 @@ export interface PlanReplaceStep {
24
26
  order: number;
25
27
  }
26
28
  export declare function replaceTaskPlan(taskId: string, steps: PlanReplaceStep[], creds: Creds): Promise<Task>;
27
- export interface PublishToLedgerPayload {
28
- description: string;
29
- chatId?: string;
30
- payerId?: string;
31
- parentTaskId?: string;
32
- price?: number;
33
- lifecycle?: string;
34
- expiresAt?: string;
35
- maxExecutions?: number;
36
- agreementDescription?: string;
37
- /** Broadcast audience: 'everyone' (default, fully public) or 'org' (members of your active org only). */
38
- audience?: BroadcastAudience;
39
- }
40
- export declare function publishToLedger(payload: PublishToLedgerPayload, creds: Creds): Promise<Agreement>;
41
- export interface PullFromLedgerOptions {
42
- limit?: number;
43
- since?: string;
44
- }
45
- export declare function pullFromLedger(options: PullFromLedgerOptions | undefined, creds: Creds): Promise<Agreement[]>;
46
- export declare function claimLedgerTask(agreementId: string, creds: Creds, options?: {
47
- idempotencyKey?: string;
48
- }): Promise<Agreement>;
49
29
  export declare function reportTask(taskId: string, message: string | undefined, creds: Creds): Promise<Task>;
50
30
  export declare function setTaskSatisfaction(taskId: string, satisfaction: 'positive' | 'negative', creds: Creds): Promise<Task>;
51
31
  export interface ListTasksOptions {
52
32
  state?: string;
53
33
  cursor?: string;
54
34
  limit?: number;
35
+ /** Filter to tasks assigned to this id (ZIG-586). */
36
+ assignedTo?: string;
55
37
  }
56
38
  export interface ListTasksResult {
57
39
  tasks: Task[];
@@ -77,11 +59,6 @@ export declare class TaskClient {
77
59
  cancelTask(taskId: string): Promise<Task>;
78
60
  getSubtasks(parentTaskId: string): Promise<Task[]>;
79
61
  replaceTaskPlan(taskId: string, steps: PlanReplaceStep[]): Promise<Task>;
80
- publishToLedger(payload: PublishToLedgerPayload): Promise<Agreement>;
81
- pullFromLedger(options?: PullFromLedgerOptions): Promise<Agreement[]>;
82
- claimLedgerTask(taskId: string, options?: {
83
- idempotencyKey?: string;
84
- }): Promise<Agreement>;
85
62
  reportTask(taskId: string, message?: string): Promise<Task>;
86
63
  setTaskSatisfaction(taskId: string, satisfaction: 'positive' | 'negative'): Promise<Task>;
87
64
  listTasks(options?: ListTasksOptions): Promise<ListTasksResult>;
@@ -2,7 +2,6 @@ import 'dotenv/config';
2
2
  import { getBackendUrl } from '../utils/urlUtils.js';
3
3
  import { ApiError } from '../types.js';
4
4
  function getTaskBaseUrl() { return `${getBackendUrl()}/tasks`; }
5
- function getMarketplaceBaseUrl() { return `${getBackendUrl()}/marketplace`; }
6
5
  function buildHeaders(creds) {
7
6
  return {
8
7
  'content-type': 'application/json',
@@ -206,62 +205,6 @@ export async function replaceTaskPlan(taskId, steps, creds) {
206
205
  throw new Error('Invalid response: task data not found');
207
206
  return task;
208
207
  }
209
- export async function publishToLedger(payload, creds) {
210
- assertCreds(creds, 'quest publish');
211
- const res = await fetch(`${getMarketplaceBaseUrl()}/quests/publish`, {
212
- method: 'POST',
213
- headers: buildHeaders(creds),
214
- body: JSON.stringify(payload || {}),
215
- });
216
- if (!res.ok) {
217
- const body = await res.text().catch(() => '');
218
- throwApiError(res, body, `Quest publish failed: ${res.status}`);
219
- }
220
- const data = await res.json().catch(() => null);
221
- if (!data?.['agreement'])
222
- throw new Error('Quest publish returned no agreement');
223
- return data['agreement'];
224
- }
225
- export async function pullFromLedger(options, creds) {
226
- assertCreds(creds, 'quest pull');
227
- const params = new URLSearchParams();
228
- if (options?.limit != null)
229
- params.set('limit', String(options.limit));
230
- if (options?.since)
231
- params.set('since', options.since);
232
- const qs = params.toString();
233
- const res = await fetch(`${getMarketplaceBaseUrl()}/quests${qs ? `?${qs}` : ''}`, {
234
- method: 'GET',
235
- headers: buildHeaders(creds),
236
- });
237
- if (!res.ok) {
238
- const body = await res.text().catch(() => '');
239
- throwApiError(res, body, `Quest pull failed: ${res.status}`);
240
- }
241
- const data = await res.json().catch(() => null);
242
- return data?.['agreements'] ?? [];
243
- }
244
- export async function claimLedgerTask(agreementId, creds, options) {
245
- if (!agreementId)
246
- throw new Error('agreementId is required');
247
- assertCreds(creds, 'quest claim');
248
- const headers = buildHeaders(creds);
249
- if (options?.idempotencyKey)
250
- headers['Idempotency-Key'] = options.idempotencyKey;
251
- const res = await fetch(`${getMarketplaceBaseUrl()}/quests/claim`, {
252
- method: 'POST',
253
- headers,
254
- body: JSON.stringify({ agreementId }),
255
- });
256
- if (!res.ok) {
257
- const body = await res.text().catch(() => '');
258
- throwApiError(res, body, `Quest claim failed: ${res.status}`);
259
- }
260
- const data = await res.json().catch(() => null);
261
- if (!data?.['ok'])
262
- throw new Error(data?.['error'] || 'Claim failed');
263
- return data['agreement'];
264
- }
265
208
  // ---------------------------------------------------------------------------
266
209
  // Reporting & satisfaction
267
210
  // ---------------------------------------------------------------------------
@@ -314,6 +257,8 @@ export async function listTasks(options = {}, creds) {
314
257
  url.searchParams.set('cursor', options.cursor);
315
258
  if (options.limit != null)
316
259
  url.searchParams.set('limit', String(options.limit));
260
+ if (options.assignedTo)
261
+ url.searchParams.set('assignedTo', options.assignedTo);
317
262
  const res = await fetch(url.toString(), {
318
263
  method: 'GET',
319
264
  headers: buildHeaders(creds),
@@ -373,9 +318,6 @@ export class TaskClient {
373
318
  cancelTask(taskId) { return cancelTask(taskId, this.creds); }
374
319
  getSubtasks(parentTaskId) { return getSubtasks(parentTaskId, this.creds); }
375
320
  replaceTaskPlan(taskId, steps) { return replaceTaskPlan(taskId, steps, this.creds); }
376
- publishToLedger(payload) { return publishToLedger(payload, this.creds); }
377
- pullFromLedger(options) { return pullFromLedger(options, this.creds); }
378
- claimLedgerTask(taskId, options) { return claimLedgerTask(taskId, this.creds, options); }
379
321
  reportTask(taskId, message) { return reportTask(taskId, message, this.creds); }
380
322
  setTaskSatisfaction(taskId, satisfaction) { return setTaskSatisfaction(taskId, satisfaction, this.creds); }
381
323
  listTasks(options) { return listTasks(options ?? {}, this.creds); }
package/dist/types.d.ts CHANGED
@@ -20,6 +20,8 @@ export interface Task {
20
20
  agentId?: string;
21
21
  executorId?: string;
22
22
  payerId?: string;
23
+ /** Explicit delegation target (ZIG-586) — id of the agent/user this task is assigned to, or null when unassigned. */
24
+ assigneeId?: string | null;
23
25
  agreementId?: string;
24
26
  agreement?: Agreement;
25
27
  state: TaskState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/api-client",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "HTTP and WebSocket client for the Ziggs backend API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",