@ziggs-ai/api-client 0.42.13 → 0.42.15
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 +4 -0
- package/dist/capabilities/activeHire.js +1 -4
- package/dist/capabilities/agreementVerbs.js +12 -10
- package/dist/capabilities/context.d.ts +1 -0
- package/dist/capabilities/context.js +25 -5
- package/dist/capabilities/index.d.ts +1 -1
- package/dist/capabilities/index.js +1 -1
- package/dist/capabilities/marketplace.js +2 -4
- package/dist/capabilities/mcpBriefs.js +6 -1
- package/dist/http/AgreementClient.d.ts +51 -17
- package/dist/http/AgreementClient.js +50 -8
- package/dist/http/CallerContextClient.d.ts +28 -0
- package/dist/http/CallerContextClient.js +31 -0
- package/dist/http/MarketplaceClient.d.ts +9 -4
- package/dist/http/MarketplaceClient.js +8 -21
- package/dist/http/index.d.ts +2 -0
- package/dist/http/index.js +1 -0
- package/dist/types.d.ts +3 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AGREEMENT_ENGAGEMENT_KIND,
|
|
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: '
|
|
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: '
|
|
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
|
-
|
|
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
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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 },
|
|
@@ -16,6 +16,7 @@ export declare function contextBounds(grant: GrantView): Record<string, unknown>
|
|
|
16
16
|
* the authority on the id.
|
|
17
17
|
*/
|
|
18
18
|
export declare function resolveOrgScopeId(env: CapabilityEnv, scopeId: string): Promise<string>;
|
|
19
|
+
export declare const contextCallersCapability: CapabilityDefinition;
|
|
19
20
|
export declare const contextReadCapability: CapabilityDefinition;
|
|
20
21
|
export declare const contextExpandReachCapability: CapabilityDefinition;
|
|
21
22
|
export declare const contextDiscoverGrantableCapability: CapabilityDefinition;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isContextAccessRequest } from '../shared/contextAccessRequest.js';
|
|
2
2
|
import { presentResourceActions } from './resourceActions.js';
|
|
3
|
+
import { CallerContextClient } from '../http/CallerContextClient.js';
|
|
3
4
|
import { ContextReadClient, CONTEXT_READ_TYPES, CONTEXT_READ_VIA, parseVia, viaHint, } from '../http/ContextReadClient.js';
|
|
4
5
|
import { ContextOpenClient } from '../http/ContextOpenClient.js';
|
|
5
6
|
import { ContextGrantsClient, } from '../http/ContextGrantsClient.js';
|
|
@@ -7,11 +8,14 @@ import { ContextDiscoveryClient } from '../http/ContextDiscoveryClient.js';
|
|
|
7
8
|
import { grantCaveat, CONTEXT_GRANT_SCOPE_KINDS, } from '../http/grants.js';
|
|
8
9
|
import { fetchMyOrgs, resolveOrgSelector } from '../http/OrgsClient.js';
|
|
9
10
|
import { fullCreds } from './types.js';
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
|
|
11
|
+
// What an agent may give or pass on through these tools. The context rail
|
|
12
|
+
// now names every kind a grant exists for (a thread, an agent, a workspace,
|
|
13
|
+
// a wallet, a connection, platform staff), but those are given by their own
|
|
14
|
+
// flows, never through these tools. `artifact` is passed on as an exact
|
|
15
|
+
// re-grant; narrowing a container grant DOWN to an artifact inside it is not
|
|
16
|
+
// supported yet. A send grant (`contact`) is never passed on.
|
|
17
|
+
const AGENT_GIVABLE = new Set(['message', 'agreement', 'org', 'artifact', 'task']);
|
|
18
|
+
const GRANT_SCOPE_KINDS = CONTEXT_GRANT_SCOPE_KINDS.filter(kind => AGENT_GIVABLE.has(kind));
|
|
15
19
|
const CONTEXT_TEMPORALS = ['from-now', 'from-start'];
|
|
16
20
|
/**
|
|
17
21
|
* Human/LLM-readable bounds for a context grant. folded a context
|
|
@@ -61,6 +65,21 @@ const VIA_BY_TYPE = CONTEXT_READ_TYPES.map((t) => `${t} via ${viaHint(t)}`).join
|
|
|
61
65
|
*/
|
|
62
66
|
const ARTIFACT_VIA_NOTE = 'via=artifact:<id> is a point read of one named artifact and the ONLY way to ' +
|
|
63
67
|
'read one referenced by no agreement or task';
|
|
68
|
+
export const contextCallersCapability = {
|
|
69
|
+
key: 'context_callers',
|
|
70
|
+
names: { sdk: 'context_callers', mcp: 'ziggs_context_callers' },
|
|
71
|
+
title: 'Caller identity tree',
|
|
72
|
+
descriptions: {
|
|
73
|
+
sdk: 'Who you count as: holders, session, workspaces, owned agents. Same as GET /context/callers.',
|
|
74
|
+
},
|
|
75
|
+
annotation: 'read-only',
|
|
76
|
+
params: {},
|
|
77
|
+
handler: async (_args, env) => {
|
|
78
|
+
const creds = fullCreds(env);
|
|
79
|
+
const client = new CallerContextClient(creds.operatorKey, creds.agentId, env.baseUrl);
|
|
80
|
+
return client.getCallers();
|
|
81
|
+
},
|
|
82
|
+
};
|
|
64
83
|
export const contextReadCapability = {
|
|
65
84
|
key: 'context_read',
|
|
66
85
|
names: { sdk: 'context_read', mcp: 'ziggs_context_read' },
|
|
@@ -525,6 +544,7 @@ export const accessRequestCapability = {
|
|
|
525
544
|
},
|
|
526
545
|
};
|
|
527
546
|
export const CONTEXT_CAPABILITIES = [
|
|
547
|
+
contextCallersCapability,
|
|
528
548
|
contextReadCapability,
|
|
529
549
|
openCapability,
|
|
530
550
|
accessExplainCapability,
|
|
@@ -15,7 +15,7 @@ export { MARKETPLACE_CAPABILITIES, marketplaceViewCapability } from './marketpla
|
|
|
15
15
|
export { GRANTS_CAPABILITIES, listGrantsCapability } from './grants.js';
|
|
16
16
|
export { PAGE_GUIDE, pageGuideCapability } from './pageGuide.js';
|
|
17
17
|
export { BUCKET_CAPABILITIES, bucketCreateCapability, bucketListCapability, bucketReadCapability, bucketInsertCapability, bucketRemoveCapability, bucketAddMembersCapability, bucketJoinCapability, bucketSendCapability, bucketRemoveMemberCapability, bucketDuplicateCapability, bucketRenameCapability, bucketDeleteCapability, } from './buckets.js';
|
|
18
|
-
export { CONTEXT_CAPABILITIES, contextReadCapability, openCapability, accessExplainCapability, contextDelegateCapability, accessRequestCapability, contextExpandReachCapability, contextDiscoverGrantableCapability, contextBounds, resolveOrgScopeId, explainRefusedRead, RESOURCE_HIDDEN_MESSAGE, RESOURCE_UNREADABLE_MESSAGE, type RefusedRead, } from './context.js';
|
|
18
|
+
export { CONTEXT_CAPABILITIES, contextCallersCapability, contextReadCapability, openCapability, accessExplainCapability, contextDelegateCapability, accessRequestCapability, contextExpandReachCapability, contextDiscoverGrantableCapability, contextBounds, resolveOrgScopeId, explainRefusedRead, RESOURCE_HIDDEN_MESSAGE, RESOURCE_UNREADABLE_MESSAGE, type RefusedRead, } from './context.js';
|
|
19
19
|
export { CONNECTION_CAPABILITIES, connectionProxyCapability, requestConnectionCapability, } from './connections.js';
|
|
20
20
|
export { DISCOVERY_CAPABILITIES, agentSearchCapability, agentGetCapability, } from './discovery.js';
|
|
21
21
|
export { ARTIFACT_CAPABILITIES, recordArtifactCapability, listArtifactsCapability, findArtifactsCapability, type UnsearchedContext, attachArtifactCapability, reviewArtifactContributionCapability, contributeArtifactCapability, uploadArtifactUrlCapability, completeArtifactFileCapability, downloadArtifactCapability, reextractArtifactCapability, } from './artifacts.js';
|
|
@@ -15,7 +15,7 @@ export { MARKETPLACE_CAPABILITIES, marketplaceViewCapability } from './marketpla
|
|
|
15
15
|
export { GRANTS_CAPABILITIES, listGrantsCapability } from './grants.js';
|
|
16
16
|
export { PAGE_GUIDE, pageGuideCapability } from './pageGuide.js';
|
|
17
17
|
export { BUCKET_CAPABILITIES, bucketCreateCapability, bucketListCapability, bucketReadCapability, bucketInsertCapability, bucketRemoveCapability, bucketAddMembersCapability, bucketJoinCapability, bucketSendCapability, bucketRemoveMemberCapability, bucketDuplicateCapability, bucketRenameCapability, bucketDeleteCapability, } from './buckets.js';
|
|
18
|
-
export { CONTEXT_CAPABILITIES, contextReadCapability, openCapability, accessExplainCapability, contextDelegateCapability, accessRequestCapability, contextExpandReachCapability, contextDiscoverGrantableCapability, contextBounds, resolveOrgScopeId, explainRefusedRead, RESOURCE_HIDDEN_MESSAGE, RESOURCE_UNREADABLE_MESSAGE, } from './context.js';
|
|
18
|
+
export { CONTEXT_CAPABILITIES, contextCallersCapability, contextReadCapability, openCapability, accessExplainCapability, contextDelegateCapability, accessRequestCapability, contextExpandReachCapability, contextDiscoverGrantableCapability, contextBounds, resolveOrgScopeId, explainRefusedRead, RESOURCE_HIDDEN_MESSAGE, RESOURCE_UNREADABLE_MESSAGE, } from './context.js';
|
|
19
19
|
export { CONNECTION_CAPABILITIES, connectionProxyCapability, requestConnectionCapability, } from './connections.js';
|
|
20
20
|
export { DISCOVERY_CAPABILITIES, agentSearchCapability, agentGetCapability, } from './discovery.js';
|
|
21
21
|
export { ARTIFACT_CAPABILITIES, recordArtifactCapability, listArtifactsCapability, findArtifactsCapability, attachArtifactCapability, reviewArtifactContributionCapability, contributeArtifactCapability, uploadArtifactUrlCapability, completeArtifactFileCapability, downloadArtifactCapability, reextractArtifactCapability, } from './artifacts.js';
|
|
@@ -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
|
-
/**
|
|
17
|
-
const
|
|
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
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const BRIEFS = {
|
|
2
2
|
// Session and orientation
|
|
3
3
|
ziggs_auth_status: {
|
|
4
|
-
does: 'Shows who this connection acts as
|
|
4
|
+
does: 'Shows who this connection acts as, from GET /context/callers plus MCP binding.',
|
|
5
5
|
when: 'diagnosing a connection',
|
|
6
6
|
next: 'ziggs_inbox_peek counts waiting mail',
|
|
7
7
|
},
|
|
@@ -65,6 +65,11 @@ const BRIEFS = {
|
|
|
65
65
|
does: 'Reads authorized context for an explicit message, artifact, task or agreement.',
|
|
66
66
|
returns: 'a cursor for more messages',
|
|
67
67
|
},
|
|
68
|
+
ziggs_context_callers: {
|
|
69
|
+
does: 'Holders, session, workspaces, owned agents, pre-join invites for this connection.',
|
|
70
|
+
when: 'cold session orientation',
|
|
71
|
+
next: 'ziggs_inbox_peek',
|
|
72
|
+
},
|
|
68
73
|
// Agreements
|
|
69
74
|
ziggs_agreement_list: {
|
|
70
75
|
does: 'Lists the agreements you can reach, including hires, as short rows (ziggs_agreement_get has the full one). scope mine keeps only agreements you are a party to.',
|
|
@@ -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
|
-
*
|
|
6
|
-
* `
|
|
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
|
-
*
|
|
54
|
-
* '
|
|
55
|
-
*
|
|
56
|
-
*
|
|
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
|
-
*
|
|
121
|
-
*
|
|
122
|
-
|
|
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,
|
|
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
|
-
*
|
|
166
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
236
|
-
|
|
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
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Matches GET /context/callers — holders, workspaces, session, owned agents. */
|
|
2
|
+
export type CallerContextView = {
|
|
3
|
+
principalId: string;
|
|
4
|
+
activeOrgId: string | null;
|
|
5
|
+
holders: Array<Record<string, unknown>>;
|
|
6
|
+
preJoinWorkspaces: Array<Record<string, unknown>>;
|
|
7
|
+
session: {
|
|
8
|
+
user: Record<string, unknown> | null;
|
|
9
|
+
};
|
|
10
|
+
workspaces: {
|
|
11
|
+
orgs: unknown[];
|
|
12
|
+
activeOrgId: string | null;
|
|
13
|
+
};
|
|
14
|
+
ownedAgents: {
|
|
15
|
+
agents: unknown[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* One read of who the caller counts as: tree holders, session, workspaces,
|
|
20
|
+
* owned agents. Same payload the web app shell uses.
|
|
21
|
+
*/
|
|
22
|
+
export declare class CallerContextClient {
|
|
23
|
+
private readonly operatorKey;
|
|
24
|
+
private readonly agentId?;
|
|
25
|
+
private readonly baseUrl?;
|
|
26
|
+
constructor(operatorKey: string, agentId?: string | undefined, baseUrl?: string | undefined);
|
|
27
|
+
getCallers(): Promise<CallerContextView>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getBackendUrl } from '../utils/urlUtils.js';
|
|
2
|
+
import { pollSurfaceError } from '../shared/rateLimit.js';
|
|
3
|
+
import { buildOperatorHeaders } from './operatorHeaders.js';
|
|
4
|
+
/**
|
|
5
|
+
* One read of who the caller counts as: tree holders, session, workspaces,
|
|
6
|
+
* owned agents. Same payload the web app shell uses.
|
|
7
|
+
*/
|
|
8
|
+
export class CallerContextClient {
|
|
9
|
+
operatorKey;
|
|
10
|
+
agentId;
|
|
11
|
+
baseUrl;
|
|
12
|
+
constructor(operatorKey, agentId, baseUrl) {
|
|
13
|
+
this.operatorKey = operatorKey;
|
|
14
|
+
this.agentId = agentId;
|
|
15
|
+
this.baseUrl = baseUrl;
|
|
16
|
+
if (!operatorKey)
|
|
17
|
+
throw new Error('CallerContextClient: operatorKey is required');
|
|
18
|
+
}
|
|
19
|
+
async getCallers() {
|
|
20
|
+
const url = `${this.baseUrl || getBackendUrl()}/context/callers`;
|
|
21
|
+
const res = await fetch(url, {
|
|
22
|
+
method: 'GET',
|
|
23
|
+
headers: buildOperatorHeaders(this.operatorKey, this.agentId),
|
|
24
|
+
});
|
|
25
|
+
const text = await res.text().catch(() => '');
|
|
26
|
+
if (!res.ok) {
|
|
27
|
+
throw pollSurfaceError('CallerContextClient GET /context/callers', res, text);
|
|
28
|
+
}
|
|
29
|
+
return JSON.parse(text);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -20,16 +20,17 @@ export interface PublishOfferPayload {
|
|
|
20
20
|
*/
|
|
21
21
|
billing?: 'total' | 'per_task';
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
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 {
|
|
19
|
-
|
|
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(`${
|
|
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/http/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export type { ArtifactVisibility, ListArtifactsOptions, ListArtifactsQuery, List
|
|
|
7
7
|
export { ContextReadClient, CONTEXT_READ_TYPES, CONTEXT_READ_VIA, VIA_KINDS, parseVia, viaHint, } from './ContextReadClient.js';
|
|
8
8
|
export type { ContextReadType, ContextReadQuery, ContextReadEnvelope, ContextSnapshotResult, ContextSnapshotQuery, ContextSnapshotParticipant, ViaKind, } from './ContextReadClient.js';
|
|
9
9
|
export { ContextOpenClient, CONTEXT_OPEN_KINDS } from './ContextOpenClient.js';
|
|
10
|
+
export { CallerContextClient } from './CallerContextClient.js';
|
|
11
|
+
export type { CallerContextView } from './CallerContextClient.js';
|
|
10
12
|
export type { ContextOpenKind, ContextOpenOutcome, ContextOpenRef, ContextOpenBody, ResourceAction, ResourceActionCall, ContextOpenAccess, ContextOpenResult, ContextExplainResult, } from './ContextOpenClient.js';
|
|
11
13
|
export { ContextDiscoveryClient } from './ContextDiscoveryClient.js';
|
|
12
14
|
export type { DiscoverableItem } from './ContextDiscoveryClient.js';
|
package/dist/http/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { ArtifactsClient,
|
|
|
7
7
|
artifactScope, AGREEMENT_LANE_PREFIX, ARTIFACT_INLINE_TEXT_MAX_CHARS, ARTIFACT_INLINE_TEXT_OVER_LIMIT_HINT, } from './ArtifactsClient.js';
|
|
8
8
|
export { ContextReadClient, CONTEXT_READ_TYPES, CONTEXT_READ_VIA, VIA_KINDS, parseVia, viaHint, } from './ContextReadClient.js';
|
|
9
9
|
export { ContextOpenClient, CONTEXT_OPEN_KINDS } from './ContextOpenClient.js';
|
|
10
|
+
export { CallerContextClient } from './CallerContextClient.js';
|
|
10
11
|
export { ContextDiscoveryClient } from './ContextDiscoveryClient.js';
|
|
11
12
|
export { IntroductionsClient } from './IntroductionsClient.js';
|
|
12
13
|
export { PartiesClient } from './PartiesClient.js';
|
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
|
|
158
|
-
*
|
|
159
|
-
*
|
|
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.
|
|
3
|
+
"version": "0.42.15",
|
|
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.
|
|
34
|
+
"@ziggs-ai/contracts": "0.50.21",
|
|
35
35
|
"socket.io-client": "^4.7.0"
|
|
36
36
|
},
|
|
37
37
|
"keywords": [
|