@ziggs-ai/api-client 0.42.13 → 0.42.14

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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.42.14
6
+
5
7
  ## 0.42.13
6
8
 
7
9
  ## 0.42.12
@@ -1,4 +1,4 @@
1
- import { AGREEMENT_ENGAGEMENT_KIND, isBroadcastTarget, } from '../types.js';
1
+ import { AGREEMENT_ENGAGEMENT_KIND, } from '../types.js';
2
2
  /**
3
3
  * Active hires whose provider is this agent.
4
4
  *
@@ -19,9 +19,6 @@ export function activeHiresForAgent(agentId, agreements) {
19
19
  }
20
20
  if (row.parties?.provider?.actor !== agentId)
21
21
  continue;
22
- const payer = row.parties?.payer?.principal;
23
- if (typeof payer === 'string' && isBroadcastTarget(payer))
24
- continue;
25
22
  hires.push({
26
23
  agreementId: row.agreementId,
27
24
  workspace: row.payerLane ?? null,
@@ -1,5 +1,5 @@
1
1
  import { SOURCES_PARAM, sourcesArg } from './sources.js';
2
- import { delegateAgreement, getAgreement, proposeBroadcast, proposeDirectTo, } from '../http/AgreementClient.js';
2
+ import { delegateAgreement, getAgreement, proposeBroadcast, makeOffer, audienceRecipients, proposeDirectTo, } from '../http/AgreementClient.js';
3
3
  import { fullCreds } from './types.js';
4
4
  import { nextCall } from './nextCall.js';
5
5
  /**
@@ -271,7 +271,7 @@ export const agreementHandoffCapability = {
271
271
  names: { sdk: 'agreement_handoff', mcp: 'ziggs_agreement_handoff' },
272
272
  title: 'Pass a hire you hold to whoever claims it',
273
273
  descriptions: {
274
- sdk: 'Share an agent you have hired: the provider stays pinned, and whoever claims or approves becomes the customer the work is done for. Omit `to` to make it claimable by anyone. Handing off someone else\'s agent leaves that provider\'s approval pending — it must accept once before the hand-off can be claimed.',
274
+ sdk: 'Offer an agent you have hired: you are the provider and that agent does the work. Whoever takes it gets their own agreement and is the customer the work is done for. Omit `to` to offer it to anyone. When your hire ends, the offer closes; agreements already taken stay.',
275
275
  },
276
276
  annotation: 'destructive',
277
277
  params: {
@@ -282,7 +282,7 @@ export const agreementHandoffCapability = {
282
282
  },
283
283
  to: {
284
284
  type: 'string',
285
- description: 'Who receives it. Omit to publish it claimable by anyone; name a party and they approve directly.',
285
+ description: 'The person or agent who may take it. Omit to offer it to anyone.',
286
286
  },
287
287
  ...AGREEMENT_TERMS_PARAMS,
288
288
  description: {
@@ -305,15 +305,17 @@ export const agreementHandoffCapability = {
305
305
  if (!providerId) {
306
306
  throw new Error(`Cannot hand off ${parentAgreementId}: it names no provider, so there is no hire to share. Check the id with agreement_get.`);
307
307
  }
308
- const terms = {
308
+ // An offer of the agent you hold through that hire: whoever takes it gets
309
+ // their own agreement, and it closes when your hire ends.
310
+ const to = args['to'];
311
+ const agreement = await makeOffer({
309
312
  ...termsFrom(args),
310
313
  description: args['description'] ?? parent.description ?? '',
311
- parentAgreementId,
312
- };
313
- const to = args['to'];
314
- const agreement = to
315
- ? await proposeDirectTo({ ...terms, proposedTo: to, useParentProvider: true, engagementKind: 'hire' }, creds)
316
- : await proposeBroadcast({ ...terms, audience: 'everyone', useParentProvider: true, engagementKind: 'hire' }, creds);
314
+ side: 'sell',
315
+ engagementKind: 'hire',
316
+ heldThrough: parentAgreementId,
317
+ to: to ? [{ id: to }] : audienceRecipients('everyone'),
318
+ }, creds);
317
319
  return { agreement, ...(to ? {} : { readPlan: publishedNext(env) }) };
318
320
  },
319
321
  sdkOptions: { isAgreementCreation: true },
@@ -7,11 +7,14 @@ import { ContextDiscoveryClient } from '../http/ContextDiscoveryClient.js';
7
7
  import { grantCaveat, CONTEXT_GRANT_SCOPE_KINDS, } from '../http/grants.js';
8
8
  import { fetchMyOrgs, resolveOrgSelector } from '../http/OrgsClient.js';
9
9
  import { fullCreds } from './types.js';
10
- // `artifact` joined the context rail. Delegating an artifact grant
11
- // onward works (same kind, same id — an exact re-grant); narrowing a container
12
- // grant DOWN to an artifact inside it is deliberately not supported yet.
13
- // A send grant (`contact`) is never passed on, so it is not a delegation scope.
14
- const GRANT_SCOPE_KINDS = CONTEXT_GRANT_SCOPE_KINDS.filter(kind => kind !== 'address' && kind !== 'person' && kind !== 'contact');
10
+ // What an agent may give or pass on through these tools. The context rail
11
+ // now names every kind a grant exists for (a thread, an agent, a workspace,
12
+ // a wallet, a connection, platform staff), but those are given by their own
13
+ // flows, never through these tools. `artifact` is passed on as an exact
14
+ // re-grant; narrowing a container grant DOWN to an artifact inside it is not
15
+ // supported yet. A send grant (`contact`) is never passed on.
16
+ const AGENT_GIVABLE = new Set(['message', 'agreement', 'org', 'artifact', 'task']);
17
+ const GRANT_SCOPE_KINDS = CONTEXT_GRANT_SCOPE_KINDS.filter(kind => AGENT_GIVABLE.has(kind));
15
18
  const CONTEXT_TEMPORALS = ['from-now', 'from-start'];
16
19
  /**
17
20
  * Human/LLM-readable bounds for a context grant. folded a context
@@ -2,7 +2,6 @@ import { marketplaceFormation } from '../engagementGuide.js';
2
2
  import { pullOffersPage, pullRequests } from '../http/MarketplaceClient.js';
3
3
  import { fullCreds } from './types.js';
4
4
  import { nextCall } from './nextCall.js';
5
- import { BROADCAST_TARGETS } from '../types.js';
6
5
  import { LIST_FIELDS_PARAM, listedFieldNote, parseListFields, pickListedRows } from './listedFields.js';
7
6
  const VIEW_KINDS = ['all', 'requests', 'offers'];
8
7
  function publishHint(env) {
@@ -13,9 +12,8 @@ function publishHint(env) {
13
12
  return (`Reuse an active agreement that already covers the work. Otherwise claim any row with ${claim} ` +
14
13
  `(agreementId) — listings are take-it-or-leave-it, never counter one. ${publish}`);
15
14
  }
16
- /** A broadcast sentinel in a party slot means "open", not a counterparty. */
17
- const BROADCASTS = new Set(BROADCAST_TARGETS);
18
- const named = (id) => typeof id === 'string' && id && !BROADCASTS.has(id) ? id : undefined;
15
+ /** An offer's open side names nobody: an empty slot is not a counterparty. */
16
+ const named = (id) => typeof id === 'string' && id ? id : undefined;
19
17
  /**
20
18
  * One listing, as a browser needs to read it.
21
19
  *
@@ -2,11 +2,8 @@ import type { WriteSource } from '../capabilities/sources.js';
2
2
  import { type Creds, type Agreement, type EngagementKind, type BroadcastAudience } from '../types.js';
3
3
  /**
4
4
  * Shared proposal terms. When `engagementKind` is omitted the server defaults to `service`.
5
- * For an open buyer-broadcast request, set `proposedTo` to a broadcast sentinel —
6
- * `OPEN_AGREEMENT_TARGET` (`"everyone"`, fully public), `ORG_AGREEMENT_TARGET`
7
- * (`"org"`, scoped to your org) or `COMPANY_AGREEMENT_TARGET` (`"company"`,
8
- * every team in your org's company). Prefer `proposeBroadcast({ audience })` over
9
- * setting `proposedTo` by hand.
5
+ * A proposal names one party. To ask everyone, a workspace or a company, use
6
+ * `proposeBroadcast({ audience })`, which makes an offer.
10
7
  */
11
8
  export interface ProposeTerms {
12
9
  description: string;
@@ -34,8 +31,6 @@ export interface ProposeTerms {
34
31
  * side — there is no payer input.
35
32
  */
36
33
  providerId?: string;
37
- /** Resolve the authorized active parent hire's provider on the server. */
38
- useParentProvider?: boolean;
39
34
  /** Defaults to `service` on the server when omitted. Set `hire` for representation contracts. */
40
35
  engagementKind?: EngagementKind;
41
36
  idempotencyKey?: string;
@@ -50,15 +45,13 @@ export interface ProposeDirectInput extends ProposeTerms {
50
45
  bucketId?: string;
51
46
  }
52
47
  /**
53
- * Open buyer-broadcast. `audience` selects who may see/claim it:
54
- * 'everyone' (default) = fully public; 'org' = members of the creator's active
55
- * org only; 'company' = members of every team in that org's company. Sets
56
- * `proposedTo` to the matching sentinel server-side. With 'org' or 'company'
57
- * the creator must have an active org or the server 400s, and 'company' also
58
- * needs another team in that company.
48
+ * An open request. `audience` says who may take it: 'everyone' (default),
49
+ * 'workspace' (your active workspace; 'org' is the old word for it) or
50
+ * 'company' (every team in your workspace's company). With 'workspace' or
51
+ * 'company' you must have an active workspace, or the server answers 400.
59
52
  */
60
53
  export type ProposeBroadcastInput = Omit<ProposeDirectInput, 'proposedTo'> & {
61
- audience?: BroadcastAudience;
54
+ audience?: 'everyone' | 'workspace' | 'company' | BroadcastAudience;
62
55
  /**
63
56
  * Exact-match triage for supplier hosts: a plain string they compare
64
57
  * verbatim, no LLM turn. Absent or empty still delivers the request; the
@@ -117,9 +110,50 @@ export declare function proposeAgreement(proposalData: ProposeDirectInput, creds
117
110
  /** Propose a contract to one party (user or agent). Server defaults `engagementKind` to `service`. */
118
111
  export declare function proposeDirectTo(input: ProposeDirectInput, creds: Creds): Promise<Agreement>;
119
112
  /**
120
- * Propose an open request. `audience` ('everyone' default | 'org' | 'company') picks the
121
- * broadcast sentinel written to `proposedTo`. Server defaults `engagementKind`
122
- * to `service`.
113
+ * Who may take an offer: an audience, or one person or agent by id. The
114
+ * server gives each of them the right to take it, as a grant on the offer.
115
+ */
116
+ export type OfferRecipient = {
117
+ audience: 'everyone' | 'workspace' | 'company';
118
+ id?: string;
119
+ } | {
120
+ id: string;
121
+ kind?: 'user' | 'agent';
122
+ };
123
+ /** One thing taking the offer gives the taker. */
124
+ export interface OfferGrant {
125
+ scopeKind: 'artifact' | 'thread' | 'contact';
126
+ scopeId: string;
127
+ kind?: 'read' | 'write';
128
+ }
129
+ export interface MakeOfferInput extends Omit<ProposeTerms, 'providerId' | 'useParentProvider' | 'parentAgreementId'> {
130
+ /** `sell`: whoever takes it pays. `ask`: whoever takes it does the work. */
131
+ side: 'sell' | 'ask';
132
+ /** Who may take it. Omitted: everyone. */
133
+ to?: OfferRecipient[];
134
+ /** Offer the agent of an active hire you pay for, under that hire. */
135
+ heldThrough?: string;
136
+ /** What taking it gives the taker, from what you own or hold. */
137
+ gives?: OfferGrant[];
138
+ /** A file or page of yours that whoever takes it starts from. */
139
+ entryArtifactId?: string;
140
+ /** How many may hold a live agreement from it at once. Omit for unlimited. */
141
+ maxClaims?: number;
142
+ /** For `ask`: what a supplier compares before taking it up. */
143
+ match?: string;
144
+ mandateAgreementId?: string;
145
+ bucketId?: string;
146
+ }
147
+ /**
148
+ * Make an offer: an agreement with one side left empty, which whoever holds
149
+ * the right to take it may take. Every take makes a new agreement.
150
+ */
151
+ export declare function makeOffer(input: MakeOfferInput, creds: Creds): Promise<Agreement>;
152
+ /** The offer recipients an audience names; `org` is the old word for a workspace. */
153
+ export declare function audienceRecipients(audience?: string | null): OfferRecipient[];
154
+ /**
155
+ * Post an open request: an offer that asks for work, for whoever takes it.
156
+ * `audience` ('everyone' default | 'workspace' | 'company') says who may.
123
157
  */
124
158
  export declare function proposeBroadcast(input: ProposeBroadcastInput, creds: Creds): Promise<Agreement>;
125
159
  export interface DelegateAgreementData {
@@ -1,7 +1,7 @@
1
1
  import { decodeOperatorKeyClaims } from '../shared/operatorKey.js';
2
2
  import { runtimeLog } from '../shared/runtimeLog.js';
3
3
  import { getBackendUrl } from '../utils/urlUtils.js';
4
- import { ApiError, OPEN_AGREEMENT_TARGET, isBroadcastTarget, partySideIds } from '../types.js';
4
+ import { ApiError, partySideIds } from '../types.js';
5
5
  import { throwApiError } from '../shared/apiError.js';
6
6
  import { buildCredsHeaders } from './operatorHeaders.js';
7
7
  // Lazy: read at call time so a `configureApiClient` call that lands after this
@@ -161,15 +161,54 @@ export async function proposeAgreement(proposalData, creds) {
161
161
  export async function proposeDirectTo(input, creds) {
162
162
  return proposeAgreement(input, creds);
163
163
  }
164
+ /** A side nobody is named on: the open side of an offer. */
165
+ function isEmptySide(side) {
166
+ return !!side && !side.principal && !side.actor;
167
+ }
168
+ /**
169
+ * Make an offer: an agreement with one side left empty, which whoever holds
170
+ * the right to take it may take. Every take makes a new agreement.
171
+ */
172
+ export async function makeOffer(input, creds) {
173
+ assertCreds(creds, 'offer creation');
174
+ const { idempotencyKey, ...bodyData } = input;
175
+ const headers = buildHeaders(creds);
176
+ if (idempotencyKey)
177
+ headers['Idempotency-Key'] = idempotencyKey;
178
+ const res = await fetch(`${getAgreementBaseUrl()}/offers`, {
179
+ method: 'POST',
180
+ headers,
181
+ body: JSON.stringify(bodyData),
182
+ });
183
+ if (!res.ok) {
184
+ const body = await res.text().catch(() => '');
185
+ throwApiError(res, body, `Offer creation failed: ${res.status} ${res.statusText}`);
186
+ }
187
+ const data = await res.json().catch(() => null);
188
+ if (!data?.['agreement']) {
189
+ throw new Error('Invalid response: expected { agreement } from POST /agreements/offers');
190
+ }
191
+ return shapeAgreement(data['agreement']);
192
+ }
193
+ /** The offer recipients an audience names; `org` is the old word for a workspace. */
194
+ export function audienceRecipients(audience) {
195
+ return [
196
+ {
197
+ audience: audience === 'org' || audience === 'workspace'
198
+ ? 'workspace'
199
+ : audience === 'company'
200
+ ? 'company'
201
+ : 'everyone',
202
+ },
203
+ ];
204
+ }
164
205
  /**
165
- * Propose an open request. `audience` ('everyone' default | 'org' | 'company') picks the
166
- * broadcast sentinel written to `proposedTo`. Server defaults `engagementKind`
167
- * to `service`.
206
+ * Post an open request: an offer that asks for work, for whoever takes it.
207
+ * `audience` ('everyone' default | 'workspace' | 'company') says who may.
168
208
  */
169
209
  export async function proposeBroadcast(input, creds) {
170
210
  const { audience, ...terms } = input;
171
- const proposedTo = audience && isBroadcastTarget(audience) ? audience : OPEN_AGREEMENT_TARGET;
172
- return proposeAgreement({ ...terms, proposedTo }, creds);
211
+ return makeOffer({ ...terms, side: 'ask', to: audienceRecipients(audience) }, creds);
173
212
  }
174
213
  export async function delegateAgreement(proposalData, creds) {
175
214
  if (!proposalData)
@@ -232,8 +271,11 @@ export async function respondToAgreement(agreementId, action, creds, opts = {})
232
271
  ownerUserId: opts.ownerUserId,
233
272
  agentId: creds.agentId,
234
273
  });
235
- const proposedTo = agreement.parties?.proposedTo?.principal;
236
- if (isBroadcastTarget(proposedTo) || isBroadcastTarget(agreement.parties?.payer?.principal)) {
274
+ // An offer carries its seats and leaves its proposed-to or paying side
275
+ // empty until someone takes it. A link has no payer and is not one.
276
+ const isOffer = agreement.claimSeats != null &&
277
+ agreement.engagementKind !== 'link';
278
+ if (isOffer && (isEmptySide(agreement.parties?.proposedTo) || isEmptySide(agreement.parties?.payer))) {
237
279
  // respond is approve/reject on DIRECT proposals only. An open
238
280
  // broadcast (request, standing offer, link invite) has no per-recipient
239
281
  // approval slot — a BYSTANDER can neither approve nor reject it
@@ -20,16 +20,17 @@ export interface PublishOfferPayload {
20
20
  */
21
21
  billing?: 'total' | 'per_task';
22
22
  /**
23
- * Broadcast audience: 'everyone' (default, fully public), 'org' (members of
24
- * your active org only) or 'company' (members of every team in your active
25
- * org's company).
23
+ * Who may take it: 'everyone' (default), 'workspace' (members of your
24
+ * active workspace; 'org' is the old word for it) or 'company' (members of
25
+ * every team in your workspace's company).
26
26
  */
27
- audience?: BroadcastAudience;
27
+ audience?: 'everyone' | 'workspace' | 'company' | BroadcastAudience;
28
28
  /**
29
29
  * How many customers may hold a live hire from this listing at once. A hire
30
30
  * that ends gives its seat back. Omit for unlimited.
31
31
  */
32
32
  maxClaims?: number;
33
+ /** @deprecated An offer keeps no metadata; this is not sent. */
33
34
  metadata?: Record<string, unknown>;
34
35
  /**
35
36
  * Replay handle, sent as the `Idempotency-Key` header — the same way
@@ -39,6 +40,10 @@ export interface PublishOfferPayload {
39
40
  */
40
41
  idempotencyKey?: string;
41
42
  }
43
+ /**
44
+ * Offer your work to sell: an offer whoever may take it pays for. It is
45
+ * `makeOffer` with `side: 'sell'`; `audience` says who may take it.
46
+ */
42
47
  export declare function publishOffer(payload: PublishOfferPayload, creds: Creds): Promise<Agreement>;
43
48
  /**
44
49
  * Stop taking new customers on a listing you publish, without deleting it. It
@@ -1,3 +1,4 @@
1
+ import { makeOffer, audienceRecipients } from './AgreementClient.js';
1
2
  import { decodeOperatorKeyClaims } from '../shared/operatorKey.js';
2
3
  // one shaping rule for every agreement this package parses.
3
4
  import { shapeAgreement } from './AgreementClient.js';
@@ -13,28 +14,14 @@ function assertCreds(creds, op) {
13
14
  if (!creds?.agentId && !decodeOperatorKeyClaims(creds.operatorKey)?.connectionClientId)
14
15
  throw new Error(`agentId is required for ${op}`);
15
16
  }
17
+ /**
18
+ * Offer your work to sell: an offer whoever may take it pays for. It is
19
+ * `makeOffer` with `side: 'sell'`; `audience` says who may take it.
20
+ */
16
21
  export async function publishOffer(payload, creds) {
17
22
  assertCreds(creds, 'marketplace offer publish');
18
- const { idempotencyKey, ...bodyData } = payload ?? {};
19
- const headers = buildHeaders(creds);
20
- if (idempotencyKey)
21
- headers['Idempotency-Key'] = idempotencyKey;
22
- const res = await fetch(`${getMarketplaceBaseUrl()}/offers/publish`, {
23
- method: 'POST',
24
- headers,
25
- body: JSON.stringify(bodyData),
26
- });
27
- if (!res.ok) {
28
- const body = await res.text().catch(() => '');
29
- throwApiError(res, body, `Marketplace offer publish failed: ${res.status}`);
30
- }
31
- const data = await res.json().catch(() => null);
32
- // One key name across every agreement-creating route. This used to read
33
- // `offer`, which was this route's own name for the same thing.
34
- if (!data?.['agreement']) {
35
- throw new Error('Invalid response: expected { agreement } from POST /marketplace/offers/publish');
36
- }
37
- return shapeAgreement(data['agreement']);
23
+ const { audience, metadata: _metadata, ...rest } = payload ?? {};
24
+ return makeOffer({ ...rest, side: 'sell', to: audienceRecipients(audience) }, creds);
38
25
  }
39
26
  /**
40
27
  * Stop taking new customers on a listing you publish, without deleting it. It
@@ -52,7 +39,7 @@ async function setOfferPaused(agreementId, verb, creds) {
52
39
  if (!agreementId)
53
40
  throw new Error(`agreementId is required to ${verb} a listing`);
54
41
  assertCreds(creds, `marketplace offer ${verb}`);
55
- const res = await fetch(`${getMarketplaceBaseUrl()}/offers/${encodeURIComponent(agreementId)}/${verb}`, { method: 'POST', headers: buildHeaders(creds), body: JSON.stringify({}) });
42
+ const res = await fetch(`${getBackendUrl()}/agreements/offers/${encodeURIComponent(agreementId)}/${verb}`, { method: 'POST', headers: buildHeaders(creds), body: JSON.stringify({}) });
56
43
  if (!res.ok) {
57
44
  const body = await res.text().catch(() => '');
58
45
  throwApiError(res, body, `Marketplace offer ${verb} failed: ${res.status}`);
package/dist/types.d.ts CHANGED
@@ -154,9 +154,9 @@ export type EngagementKind = (typeof AGREEMENT_ENGAGEMENT_KIND)[keyof typeof AGR
154
154
  /**
155
155
  * One side of an agreement, as the wire carries it.
156
156
  *
157
- * `principal` is the accountable person or org — never an agent. On `payer`
158
- * and `proposedTo` it may instead hold a broadcast sentinel
159
- * ({@link isBroadcastTarget}), in which case nobody has taken the side up yet.
157
+ * `principal` is the accountable person or org, never an agent. On an offer,
158
+ * the side left open (`payer` or `proposedTo`) names nobody, principal and
159
+ * actor both null, until someone takes it.
160
160
  * `actor` is the agent that performed on this side, null when the principal
161
161
  * acted itself.
162
162
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/api-client",
3
- "version": "0.42.13",
3
+ "version": "0.42.14",
4
4
  "description": "HTTP and WebSocket client for the Ziggs backend API",
5
5
  "homepage": "https://ziggsai.com/docs",
6
6
  "bugs": {
@@ -31,7 +31,7 @@
31
31
  "test:watch": "node --import tsx/esm --test --watch test/*.test.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@ziggs-ai/contracts": "0.50.12",
34
+ "@ziggs-ai/contracts": "0.50.20",
35
35
  "socket.io-client": "^4.7.0"
36
36
  },
37
37
  "keywords": [