@ziggs-ai/api-client 0.1.14 → 0.1.16

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,10 +1,13 @@
1
1
  import 'dotenv/config';
2
- import { type Creds, type Agreement, type EngagementKind } from '../types.js';
2
+ import { type Creds, type Agreement, type EngagementKind, type BroadcastAudience } from '../types.js';
3
3
  import { type PublishToLedgerPayload } from './TaskClient.js';
4
4
  export type PlanReviewTiming = 'with_proposal' | 'before_execution';
5
5
  /**
6
6
  * Shared proposal terms. When `engagementKind` is omitted the server defaults to `service`.
7
- * Use `proposedTo: OPEN_AGREEMENT_TARGET` (`"everyone"`) for open buyer-broadcast quests.
7
+ * For an open buyer-broadcast quest, set `proposedTo` to a broadcast sentinel —
8
+ * `OPEN_AGREEMENT_TARGET` (`"everyone"`, fully public) or `ORG_AGREEMENT_TARGET`
9
+ * (`"org"`, scoped to your org). Prefer `proposeBroadcast({ audience })` over
10
+ * setting `proposedTo` by hand.
8
11
  */
9
12
  export interface ProposeTerms {
10
13
  description: string;
@@ -29,14 +32,25 @@ export interface ProposeDirectInput extends ProposeTerms {
29
32
  proposedTo: string;
30
33
  chatId: string;
31
34
  }
32
- /** Open buyer-broadcast: any agent may claim (`proposedTo` is set to `"everyone"`). */
33
- export type ProposeBroadcastInput = Omit<ProposeDirectInput, 'proposedTo'>;
35
+ /**
36
+ * Open buyer-broadcast. `audience` selects who may see/claim it:
37
+ * 'everyone' (default) = fully public; 'org' = members of the creator's active
38
+ * org only. Sets `proposedTo` to the matching sentinel server-side. When
39
+ * `audience: 'org'` the creator must have an active org or the server 400s.
40
+ */
41
+ export type ProposeBroadcastInput = Omit<ProposeDirectInput, 'proposedTo'> & {
42
+ audience?: BroadcastAudience;
43
+ };
34
44
  /** @deprecated Alias for {@link ProposeDirectInput}. */
35
45
  export type ProposeAgreementData = ProposeDirectInput;
36
46
  export declare function proposeAgreement(proposalData: ProposeDirectInput, creds: Creds): Promise<Agreement>;
37
47
  /** Propose a contract to one party (user or agent). Server defaults `engagementKind` to `service`. */
38
48
  export declare function proposeDirectTo(input: ProposeDirectInput, creds: Creds): Promise<Agreement>;
39
- /** Propose an open quest (`proposedTo: "everyone"`). Server defaults `engagementKind` to `service`. */
49
+ /**
50
+ * Propose an open quest. `audience` ('everyone' default | 'org') picks the
51
+ * broadcast sentinel written to `proposedTo`. Server defaults `engagementKind`
52
+ * to `service`.
53
+ */
40
54
  export declare function proposeBroadcast(input: ProposeBroadcastInput, creds: Creds): Promise<Agreement>;
41
55
  export interface DelegateAgreementData {
42
56
  description: string;
@@ -59,8 +73,10 @@ export declare function delegateAgreement(proposalData: DelegateAgreementData, c
59
73
  /**
60
74
  * Approve or reject a pending agreement (ZIG-524 canonical client path).
61
75
  *
62
- * Routes to `POST /claim` (open broadcast) or `PUT /approvals/:partyId` (ledger).
63
- * Legacy rows without approvals[] are backfilled server-side on PUT.
76
+ * Routes to `POST /claim` (open or org-scoped broadcast) or
77
+ * `PUT /approvals/:partyId` (ledger). Legacy rows without approvals[] are
78
+ * backfilled server-side on PUT. The server rejects a /claim from a non-member
79
+ * of an org-scoped broadcast's org.
64
80
  */
65
81
  export declare function respondToAgreement(agreementId: string, action: 'approve' | 'reject', creds: Creds, opts?: {
66
82
  ownerUserId?: string | null;
@@ -134,7 +150,9 @@ export declare function revokeAgreement(agreementId: string, creds: Creds): Prom
134
150
  /**
135
151
  * Claim an open agreement (ZIG-524 phase 2 / ZIG-525):
136
152
  * - open link invite (`engagementKind: link`, proposedTo everyone)
137
- * - open broadcast quest (proposedTo everyone, status open)
153
+ * - open broadcast quest (proposedTo 'everyone', status open)
154
+ * - org-scoped broadcast quest (proposedTo 'org') — the server rejects the
155
+ * claim with 403 if the caller is not a member of the agreement's orgId
138
156
  *
139
157
  * POST /agreements/:id/claim — canonical; no partyId in body.
140
158
  */
@@ -164,7 +182,7 @@ export declare function getArtifactsForAgreement(agreementId: string, creds: Cre
164
182
  export type UserRole = 'payer' | 'provider' | 'participant' | 'observer';
165
183
  export declare function linkUserToAgreement(agreementId: string, userId: string, role: UserRole, creds: Creds): Promise<unknown | null>;
166
184
  export declare function getUsersForAgreement(agreementId: string, creds: Creds): Promise<unknown[]>;
167
- /** @deprecated Routing is expressed via `proposedTo` (specific id vs `OPEN_AGREEMENT_TARGET`), not engagementKind. */
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. */
168
186
  export type ContractKind = 'direct' | 'delegate' | 'open';
169
187
  interface ContractBase extends Omit<ProposeTerms, 'description'> {
170
188
  description: string;
@@ -192,7 +210,11 @@ export type CreateContractInput = DirectContract | DelegateContract | OpenContra
192
210
  * {@link delegateAgreement}, or {@link publishOpenQuest}.
193
211
  */
194
212
  export declare function createContract(input: CreateContractInput, creds: Creds): Promise<Agreement>;
195
- /** Publish a buyer-broadcast quest to the marketplace ledger (Store "Wanted"). */
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
+ */
196
218
  export declare function publishOpenQuest(payload: PublishToLedgerPayload, creds: Creds): Promise<Agreement>;
197
219
  export declare class AgreementClient {
198
220
  private creds;
@@ -1,7 +1,7 @@
1
1
  import 'dotenv/config';
2
2
  import { runtimeLog } from '../shared/runtimeLog.js';
3
3
  import { getBackendUrl } from '../utils/urlUtils.js';
4
- import { OPEN_AGREEMENT_TARGET, ApiError } from '../types.js';
4
+ import { OPEN_AGREEMENT_TARGET, ORG_AGREEMENT_TARGET, isBroadcastTarget, ApiError } from '../types.js';
5
5
  import { publishToLedger } from './TaskClient.js';
6
6
  // Lazy: read at call time so dotenv loaded after this module is imported
7
7
  // still takes effect. Baking it at module-load time would freeze the URL
@@ -65,9 +65,15 @@ export async function proposeAgreement(proposalData, creds) {
65
65
  export async function proposeDirectTo(input, creds) {
66
66
  return proposeAgreement(input, creds);
67
67
  }
68
- /** Propose an open quest (`proposedTo: "everyone"`). Server defaults `engagementKind` to `service`. */
68
+ /**
69
+ * Propose an open quest. `audience` ('everyone' default | 'org') picks the
70
+ * broadcast sentinel written to `proposedTo`. Server defaults `engagementKind`
71
+ * to `service`.
72
+ */
69
73
  export async function proposeBroadcast(input, creds) {
70
- return proposeAgreement({ ...input, proposedTo: OPEN_AGREEMENT_TARGET }, creds);
74
+ const { audience, ...terms } = input;
75
+ const proposedTo = audience === ORG_AGREEMENT_TARGET ? ORG_AGREEMENT_TARGET : OPEN_AGREEMENT_TARGET;
76
+ return proposeAgreement({ ...terms, proposedTo }, creds);
71
77
  }
72
78
  export async function delegateAgreement(proposalData, creds) {
73
79
  if (!proposalData)
@@ -106,8 +112,10 @@ export async function delegateAgreement(proposalData, creds) {
106
112
  /**
107
113
  * Approve or reject a pending agreement (ZIG-524 canonical client path).
108
114
  *
109
- * Routes to `POST /claim` (open broadcast) or `PUT /approvals/:partyId` (ledger).
110
- * Legacy rows without approvals[] are backfilled server-side on PUT.
115
+ * Routes to `POST /claim` (open or org-scoped broadcast) or
116
+ * `PUT /approvals/:partyId` (ledger). Legacy rows without approvals[] are
117
+ * backfilled server-side on PUT. The server rejects a /claim from a non-member
118
+ * of an org-scoped broadcast's org.
111
119
  */
112
120
  export async function respondToAgreement(agreementId, action, creds, opts = {}) {
113
121
  if (!agreementId || !action)
@@ -118,7 +126,7 @@ export async function respondToAgreement(agreementId, action, creds, opts = {})
118
126
  throw new Error(`Agreement ${agreementId} not found`);
119
127
  }
120
128
  const proposedTo = agreement.parties?.proposedTo;
121
- if (proposedTo === OPEN_AGREEMENT_TARGET) {
129
+ if (isBroadcastTarget(proposedTo)) {
122
130
  if (action === 'reject')
123
131
  return agreement;
124
132
  const { agreement: updated } = await claimAgreement(agreementId, creds);
@@ -345,7 +353,9 @@ export async function revokeAgreement(agreementId, creds) {
345
353
  /**
346
354
  * Claim an open agreement (ZIG-524 phase 2 / ZIG-525):
347
355
  * - open link invite (`engagementKind: link`, proposedTo everyone)
348
- * - open broadcast quest (proposedTo everyone, status open)
356
+ * - open broadcast quest (proposedTo 'everyone', status open)
357
+ * - org-scoped broadcast quest (proposedTo 'org') — the server rejects the
358
+ * claim with 403 if the caller is not a member of the agreement's orgId
349
359
  *
350
360
  * POST /agreements/:id/claim — canonical; no partyId in body.
351
361
  */
@@ -559,7 +569,11 @@ export async function createContract(input, creds) {
559
569
  return delegateAgreement(rest, creds);
560
570
  return publishOpenQuest(rest, creds);
561
571
  }
562
- /** Publish a buyer-broadcast quest to the marketplace ledger (Store "Wanted"). */
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
+ */
563
577
  export async function publishOpenQuest(payload, creds) {
564
578
  return publishToLedger(payload, creds);
565
579
  }
@@ -20,6 +20,8 @@ export interface WriteArtifactInput {
20
20
  chatId?: string;
21
21
  /** When the artifact is associated with an agreement. */
22
22
  agreementId?: string;
23
+ /** Optional task binding — creates a TaskArtifactLink alongside the primary scope link. */
24
+ taskId?: string;
23
25
  service?: Record<string, unknown>;
24
26
  }
25
27
  /**
@@ -70,6 +70,7 @@ export class ArtifactsClient {
70
70
  visibility: input.visibility ?? 'chat',
71
71
  chatId: input.chatId,
72
72
  agreementId: input.agreementId,
73
+ taskId: input.taskId,
73
74
  service: input.service,
74
75
  }),
75
76
  });
@@ -1,5 +1,5 @@
1
1
  import 'dotenv/config';
2
- import { type Creds, type Agreement } from '../types.js';
2
+ import { type Creds, type Agreement, type BroadcastAudience } from '../types.js';
3
3
  export interface PublishOfferPayload {
4
4
  description: string;
5
5
  price?: number;
@@ -8,6 +8,8 @@ export interface PublishOfferPayload {
8
8
  maxExecutions?: number;
9
9
  /** `hire` = claimer becomes the provider's principal on claim. Defaults to `service` server-side. */
10
10
  engagementKind?: 'hire' | 'service';
11
+ /** Broadcast audience: 'everyone' (default, fully public) or 'org' (members of your active org only). */
12
+ audience?: BroadcastAudience;
11
13
  metadata?: Record<string, unknown>;
12
14
  }
13
15
  export declare function publishOffer(payload: PublishOfferPayload, creds: Creds): Promise<Agreement>;
@@ -1,5 +1,5 @@
1
1
  import 'dotenv/config';
2
- import { type Creds, type Task, type TaskState, type Agreement } from '../types.js';
2
+ import { type Creds, type Task, type TaskState, type Agreement, type BroadcastAudience } from '../types.js';
3
3
  export interface CreateTaskData {
4
4
  description: string;
5
5
  agreementId: string;
@@ -34,6 +34,8 @@ export interface PublishToLedgerPayload {
34
34
  expiresAt?: string;
35
35
  maxExecutions?: number;
36
36
  agreementDescription?: string;
37
+ /** Broadcast audience: 'everyone' (default, fully public) or 'org' (members of your active org only). */
38
+ audience?: BroadcastAudience;
37
39
  }
38
40
  export declare function publishToLedger(payload: PublishToLedgerPayload, creds: Creds): Promise<Agreement>;
39
41
  export interface PullFromLedgerOptions {
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ export * from './http/index.js';
2
2
  export { WebSocketClient } from './websocket/index.js';
3
3
  export { createControlSocket } from './websocket/ControlSocket.js';
4
4
  export { ConnectionManager } from './ConnectionManager.js';
5
- export { EntryTypes, ContentTypes, OPEN_AGREEMENT_TARGET, AGREEMENT_ENGAGEMENT_KIND, isValidContentType } from './types.js';
5
+ export { EntryTypes, ContentTypes, OPEN_AGREEMENT_TARGET, ORG_AGREEMENT_TARGET, BROADCAST_TARGETS, isBroadcastTarget, AGREEMENT_ENGAGEMENT_KIND, isValidContentType } from './types.js';
6
6
  export { getBackendUrl, getWebSocketUrl } from './utils/urlUtils.js';
7
7
  export { runtimeLog, resetRuntimeLogLevelCache } from './shared/runtimeLog.js';
8
- export type { Creds, Task, TaskState, PlanStep, PlanStepStatus, Agreement, EngagementKind, EntryType, ContentType, MessageMetadata, MessageHandler, ApiError, } from './types.js';
8
+ export type { Creds, Task, TaskState, PlanStep, PlanStepStatus, Agreement, EngagementKind, BroadcastAudience, EntryType, ContentType, MessageMetadata, MessageHandler, ApiError, } from './types.js';
9
9
  export type { ProposeTerms, ProposeDirectInput, ProposeBroadcastInput, ProposeAgreementData, } from './http/AgreementClient.js';
package/dist/index.js CHANGED
@@ -2,6 +2,6 @@ export * from './http/index.js';
2
2
  export { WebSocketClient } from './websocket/index.js';
3
3
  export { createControlSocket } from './websocket/ControlSocket.js';
4
4
  export { ConnectionManager } from './ConnectionManager.js';
5
- export { EntryTypes, ContentTypes, OPEN_AGREEMENT_TARGET, AGREEMENT_ENGAGEMENT_KIND, isValidContentType } from './types.js';
5
+ export { EntryTypes, ContentTypes, OPEN_AGREEMENT_TARGET, ORG_AGREEMENT_TARGET, BROADCAST_TARGETS, isBroadcastTarget, AGREEMENT_ENGAGEMENT_KIND, isValidContentType } from './types.js';
6
6
  export { getBackendUrl, getWebSocketUrl } from './utils/urlUtils.js';
7
7
  export { runtimeLog, resetRuntimeLogLevelCache } from './shared/runtimeLog.js';
package/dist/types.d.ts CHANGED
@@ -105,8 +105,16 @@ export declare const ContentTypes: {
105
105
  export type ContentType = (typeof ContentTypes)[keyof typeof ContentTypes];
106
106
  /** ⚠️ SYNC: Mirrors backend src/chat/chat.types.ts isValidContentType */
107
107
  export declare function isValidContentType(contentType: string, entryType: string): boolean;
108
- /** ⚠️ SYNC: Keep in sync with backend. This is the canonical SDK-side definition. */
108
+ /** ⚠️ SYNC: Keep in sync with backend agreements.constants.ts. Fully-public broadcast sentinel. */
109
109
  export declare const OPEN_AGREEMENT_TARGET: "everyone";
110
+ /** ⚠️ SYNC: backend ORG_AGREEMENT_TARGET. Org-scoped broadcast: visible/claimable only by members of the agreement's orgId. */
111
+ export declare const ORG_AGREEMENT_TARGET: "org";
112
+ /** Audience for a broadcast proposal: fully public ('everyone') or org-scoped ('org'). */
113
+ export type BroadcastAudience = typeof OPEN_AGREEMENT_TARGET | typeof ORG_AGREEMENT_TARGET;
114
+ /** Both broadcast sentinels — values that occupy a party slot but are NOT real principal ids. */
115
+ export declare const BROADCAST_TARGETS: readonly ["everyone", "org"];
116
+ /** True when `id` is a broadcast sentinel ('everyone' | 'org') rather than a concrete principal id. */
117
+ export declare function isBroadcastTarget(id: string | null | undefined): boolean;
110
118
  export interface MessageMetadata {
111
119
  chatId: string;
112
120
  /** Stable id for dedup across push + inbox catch-up (ZIG-454). */
package/dist/types.js CHANGED
@@ -48,5 +48,13 @@ const VALID_CONTENT_TYPES = {
48
48
  export function isValidContentType(contentType, entryType) {
49
49
  return VALID_CONTENT_TYPES[entryType]?.includes(contentType) ?? false;
50
50
  }
51
- /** ⚠️ SYNC: Keep in sync with backend. This is the canonical SDK-side definition. */
51
+ /** ⚠️ SYNC: Keep in sync with backend agreements.constants.ts. Fully-public broadcast sentinel. */
52
52
  export const OPEN_AGREEMENT_TARGET = 'everyone';
53
+ /** ⚠️ SYNC: backend ORG_AGREEMENT_TARGET. Org-scoped broadcast: visible/claimable only by members of the agreement's orgId. */
54
+ export const ORG_AGREEMENT_TARGET = 'org';
55
+ /** Both broadcast sentinels — values that occupy a party slot but are NOT real principal ids. */
56
+ export const BROADCAST_TARGETS = [OPEN_AGREEMENT_TARGET, ORG_AGREEMENT_TARGET];
57
+ /** True when `id` is a broadcast sentinel ('everyone' | 'org') rather than a concrete principal id. */
58
+ export function isBroadcastTarget(id) {
59
+ return id === OPEN_AGREEMENT_TARGET || id === ORG_AGREEMENT_TARGET;
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/api-client",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "HTTP and WebSocket client for the Ziggs backend API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",