@ziggs-ai/api-client 0.14.1 → 0.14.3
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/dist/capabilities/agreements.d.ts +14 -1
- package/dist/capabilities/agreements.js +41 -40
- package/dist/capabilities/chat.js +11 -1
- package/dist/capabilities/discovery.js +7 -5
- package/dist/capabilities/index.d.ts +3 -2
- package/dist/capabilities/index.js +3 -2
- package/dist/capabilities/links.js +14 -15
- package/dist/capabilities/nextCall.d.ts +0 -19
- package/dist/capabilities/nextCall.js +0 -31
- package/dist/capabilities/tasks.d.ts +9 -0
- package/dist/capabilities/tasks.js +60 -0
- package/dist/http/AgreementClient.js +6 -0
- package/dist/http/ChatClient.d.ts +3 -1
- package/dist/http/ChatClient.js +6 -2
- package/dist/http/OrgsClient.d.ts +14 -4
- package/dist/http/OrgsClient.js +16 -6
- package/dist/instanceIdentity.d.ts +10 -0
- package/dist/instanceIdentity.js +13 -2
- package/dist/types.d.ts +12 -0
- package/package.json +1 -6
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ClaimedKind } from '../http/AgreementClient.js';
|
|
2
|
+
import type { Agreement } from '../types.js';
|
|
3
|
+
import { type CapabilityDefinition, type CapabilityEnv } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* One claim result shape for both surfaces. The SDK protocol runner used to
|
|
6
|
+
* return `{agreement, kind}` while MCP returned `{status, kind, message,
|
|
7
|
+
* agreement}` — same HTTP call, two answers.
|
|
8
|
+
*/
|
|
9
|
+
export declare function presentClaimResult(agreement: Agreement, kind: ClaimedKind, env: CapabilityEnv): {
|
|
10
|
+
status: string;
|
|
11
|
+
kind: ClaimedKind;
|
|
12
|
+
message: string;
|
|
13
|
+
agreement: Agreement;
|
|
14
|
+
};
|
|
2
15
|
/**
|
|
3
16
|
* the one claim verb. Requests, standing offers, and link invites
|
|
4
17
|
* are all open broadcasts; claiming any of them is this call. The respond
|
|
@@ -9,6 +9,46 @@ function claimedWhat(kind) {
|
|
|
9
9
|
return 'Hand-off claimed — the pinned agent works FOR you.';
|
|
10
10
|
return 'Request claimed — you provide the work.';
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* One claim result shape for both surfaces. The SDK protocol runner used to
|
|
14
|
+
* return `{agreement, kind}` while MCP returned `{status, kind, message,
|
|
15
|
+
* agreement}` — same HTTP call, two answers.
|
|
16
|
+
*/
|
|
17
|
+
export function presentClaimResult(agreement, kind, env) {
|
|
18
|
+
if (kind === 'link') {
|
|
19
|
+
return {
|
|
20
|
+
status: 'linked',
|
|
21
|
+
kind,
|
|
22
|
+
message: `Link invite claimed — you are now linked. ${linkIsReachOnly(env)}`,
|
|
23
|
+
agreement,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (agreement?.status !== 'active') {
|
|
27
|
+
const held = (agreement?.approvals ?? []).find((a) => a.status === 'pending');
|
|
28
|
+
const approveUrl = `${webAppOrigin(env)}/app/work/agreements/${agreement.agreementId}`;
|
|
29
|
+
const remedy = held?.heldReason === 'contact-basis'
|
|
30
|
+
? 'This is a first engagement with that counterparty — your human approves once; a standing link covers it after that.'
|
|
31
|
+
: 'Claiming for a job your human already approved activates at once — name the job with mandateAgreementId.';
|
|
32
|
+
return {
|
|
33
|
+
status: 'claimed',
|
|
34
|
+
kind,
|
|
35
|
+
message: `${claimedWhat(kind)} It is not active yet: the formation is waiting on ` +
|
|
36
|
+
'human approval, so nothing can be created under it until that lands. ' +
|
|
37
|
+
`Your human can approve it here: ${approveUrl} — ${remedy}`,
|
|
38
|
+
agreement,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
status: 'claimed',
|
|
43
|
+
kind,
|
|
44
|
+
message: kind === 'offer'
|
|
45
|
+
? 'Standing offer claimed — the publisher provides, your side pays. Spawn work under it with the task-create tool.'
|
|
46
|
+
: kind === 'hand-off'
|
|
47
|
+
? 'Hand-off claimed — the pinned agent works FOR you: you are the customer (and the payer when priced), never the worker. Spawn work under it with the task-create tool.'
|
|
48
|
+
: 'Request claimed — you provide the work. Read the terms, then post progress and set the task result under this agreement.',
|
|
49
|
+
agreement,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
12
52
|
/**
|
|
13
53
|
* the one claim verb. Requests, standing offers, and link invites
|
|
14
54
|
* are all open broadcasts; claiming any of them is this call. The respond
|
|
@@ -45,46 +85,7 @@ export const agreementClaimCapability = {
|
|
|
45
85
|
const { agreement, kind } = await claimOpenAgreement(args['agreementId'], fullCreds(env), typeof declaredMandate === 'string' && declaredMandate
|
|
46
86
|
? { mandateAgreementId: declaredMandate }
|
|
47
87
|
: {});
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
status: 'linked',
|
|
51
|
-
kind,
|
|
52
|
-
message: `Link invite claimed — you are now linked. ${linkIsReachOnly(env)}`,
|
|
53
|
-
agreement,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
// A claim only activates when the claimer could consent for its own side.
|
|
57
|
-
// When it did not, say what the row actually says — and hand over the link
|
|
58
|
-
// where the human answers: the assistant is the human's only
|
|
59
|
-
// screen and it is refused if it tries to answer for them, so the URL IS
|
|
60
|
-
// the remaining loop. The held reason picks the one sentence that helps:
|
|
61
|
-
// a formation gate has the mandate remedy; a contact gate is a one-time
|
|
62
|
-
// stranger ask that a standing link retires.
|
|
63
|
-
if (agreement?.status !== 'active') {
|
|
64
|
-
const held = (agreement?.approvals ?? []).find((a) => a.status === 'pending');
|
|
65
|
-
const approveUrl = `${webAppOrigin(env)}/app/agreements/${agreement.agreementId}`;
|
|
66
|
-
const remedy = held?.heldReason === 'contact-basis'
|
|
67
|
-
? 'This is a first engagement with that counterparty — your human approves once; a standing link covers it after that.'
|
|
68
|
-
: 'Claiming for a job your human already approved activates at once — name the job with mandateAgreementId.';
|
|
69
|
-
return {
|
|
70
|
-
status: 'claimed',
|
|
71
|
-
kind,
|
|
72
|
-
message: `${claimedWhat(kind)} It is not active yet: the formation is waiting on ` +
|
|
73
|
-
'human approval, so nothing can be created under it until that lands. ' +
|
|
74
|
-
`Your human can approve it here: ${approveUrl} — ${remedy}`,
|
|
75
|
-
agreement,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
status: 'claimed',
|
|
80
|
-
kind,
|
|
81
|
-
message: kind === 'offer'
|
|
82
|
-
? 'Standing offer claimed — the publisher provides, your side pays. Spawn work under it with the task-create tool.'
|
|
83
|
-
: kind === 'hand-off'
|
|
84
|
-
? 'Hand-off claimed — the pinned agent works FOR you: you are the customer (and the payer when priced), never the worker. Spawn work under it with the task-create tool.'
|
|
85
|
-
: 'Request claimed — you provide the work. Read the terms, then post progress and set the task result under this agreement.',
|
|
86
|
-
agreement,
|
|
87
|
-
};
|
|
88
|
+
return presentClaimResult(agreement, kind, env);
|
|
88
89
|
},
|
|
89
90
|
};
|
|
90
91
|
export const AGREEMENT_CAPABILITIES = [agreementClaimCapability];
|
|
@@ -30,12 +30,22 @@ export const openConversationCapability = {
|
|
|
30
30
|
'call without this still returns the original. Leave unset to continue where ' +
|
|
31
31
|
'you left off.',
|
|
32
32
|
},
|
|
33
|
+
agreementId: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
description: 'The hire this open is the working room for. On a store-claim kickoff, pass the ' +
|
|
36
|
+
'claimed agreement id so the payer is stamped from-start in that room.',
|
|
37
|
+
},
|
|
33
38
|
},
|
|
34
39
|
needsAgentId: true,
|
|
35
40
|
handler: async (args, env) => {
|
|
36
41
|
if (!args['participantId'])
|
|
37
42
|
throw new Error('participantId is required');
|
|
38
|
-
const { chatId, reused } = await openConversation(args['participantId'], fullCreds(env), {
|
|
43
|
+
const { chatId, reused } = await openConversation(args['participantId'], fullCreds(env), {
|
|
44
|
+
newChat: args['newChat'] === true,
|
|
45
|
+
...(typeof args['agreementId'] === 'string' && args['agreementId']
|
|
46
|
+
? { agreementId: args['agreementId'] }
|
|
47
|
+
: {}),
|
|
48
|
+
});
|
|
39
49
|
const lister = env.surface === 'mcp' ? 'ziggs_grant_list' : 'grant_list';
|
|
40
50
|
const grantNote = `Opening the room issued you a grant on it, so the chat also appears in ${lister} scopeKind=chat for context reads.`;
|
|
41
51
|
// word the note from the outcome instead of covering both cases.
|
|
@@ -5,15 +5,15 @@ export const agentSearchCapability = {
|
|
|
5
5
|
names: { sdk: 'agent_search', mcp: 'ziggs_agent_search' },
|
|
6
6
|
title: 'Search for agents',
|
|
7
7
|
descriptions: {
|
|
8
|
-
sdk: 'Search for agents by capability, name, or description. Returns ranked results with relevance scores. A keyword/natural-language query searches the published store AND
|
|
9
|
-
mcp: 'Find agents (AgentSearchClient). A keyword/natural-language query searches the published store AND
|
|
8
|
+
sdk: 'Search for agents by capability, name, or description. Returns ranked results with relevance scores. A keyword/natural-language query searches the published store AND your own org-mates. A link does NOT make the other person\'s agents findable — how they staff their side is theirs, and it changes without telling anyone; reach a linked person through the link itself (link_list gives their addressable peer id, then chat_open). Passing an EXACT agent id resolves that one agent even if unpublished/private, when you can reach it. Each row carries `doors` — its engagement doors: doors.listingAgreementId is a live listing to CLAIM (agreement_claim — the default, one hop from here) and doors.acceptsProposals says whether a direct proposal would even be accepted (most published agents are claim-only). Use returned agentId in grant/issue tools — do not guess ids.',
|
|
9
|
+
mcp: 'Find agents (AgentSearchClient). A keyword/natural-language query searches the published store AND your own org-mates — so you can find a teammate\'s delegate by name and ziggs_chat_open with it directly, even if it is unpublished/offline and has never been in a chat with you. A link does NOT make the other person\'s agents findable: a link makes the PERSON addressable, never their staffing list. To reach someone you are linked with, take their peer id from ziggs_link_list and ziggs_chat_open with that; their agents become known to you by turning up in rooms. Passing an EXACT agent id resolves that one agent even if unpublished/private, when you can reach it — an id you cannot reach comes back `reachability: "restricted"` with no name/profile, and a linked person\'s unpublished agent is one of those. Each row carries `doors` — its engagement doors: doors.listingAgreementId is a live listing to CLAIM (ziggs_agreement_claim — the default, one hop from here) and doors.acceptsProposals says whether a direct proposal would even be accepted (most published agents are claim-only). Each result carries a per-row `reachability` field derived from HOW you can reach it — `published` (store directory), `same-org`, `managed`, or `engaged`; it is not a blanket "published" label. Use returned agentId in grant/issue tools — do not guess ids.',
|
|
10
10
|
},
|
|
11
11
|
annotation: 'read-only',
|
|
12
12
|
params: {
|
|
13
13
|
query: {
|
|
14
14
|
type: 'string',
|
|
15
15
|
required: true,
|
|
16
|
-
description: 'Keyword/natural-language search (published store + your org-mates
|
|
16
|
+
description: 'Keyword/natural-language search (published store + your org-mates) OR an exact agent id (resolves that agent even if unpublished, when you can reach it)',
|
|
17
17
|
},
|
|
18
18
|
limit: { type: 'number', description: 'Max results (default server-side)' },
|
|
19
19
|
minScore: { type: 'number', description: 'Minimum match score filter' },
|
|
@@ -37,10 +37,12 @@ export const agentSearchCapability = {
|
|
|
37
37
|
return {
|
|
38
38
|
count: 0,
|
|
39
39
|
agents: [],
|
|
40
|
-
searched: ['published store', 'your org-mates'
|
|
40
|
+
searched: ['published store', 'your org-mates'],
|
|
41
41
|
hint: 'Zero hits means no agent profile matched these terms — discovery itself is up. ' +
|
|
42
42
|
'Matching is lexical against agent name/description/tags, so try shorter or different keywords. ' +
|
|
43
|
-
'If you already know the agent, pass its exact agent id as the query to resolve it directly.'
|
|
43
|
+
'If you already know the agent, pass its exact agent id as the query to resolve it directly. ' +
|
|
44
|
+
'Searching for someone you are LINKED with will always miss: a link makes the person addressable, ' +
|
|
45
|
+
'not their agents. Take their peer id from link_list and open a chat with the person instead.',
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
48
|
return { count: result.agents.length, agents: result.agents };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { type CapabilitySurface, type CapabilityAnnotation, type CapabilityParam, type CapabilityEnv, type CapabilityDefinition, fullCreds, rethrowWithContext, } from './types.js';
|
|
2
|
-
export { nextCall, peerPrincipalId,
|
|
2
|
+
export { nextCall, peerPrincipalId, type NextCall, } from './nextCall.js';
|
|
3
3
|
export { AGREEMENT_VERB_CAPABILITIES, agreementBuyCapability, agreementBidCapability, agreementBrokerCapability, agreementRequestCapability, agreementOfferCapability, agreementHandoffCapability, } from './agreementVerbs.js';
|
|
4
4
|
export { PAYMENT_CAPABILITIES, paymentBalanceCapability } from './payments.js';
|
|
5
5
|
export { LINK_CAPABILITIES, listLinksCapability, proposeLinkCapability, linkIsReachOnly, } from './links.js';
|
|
6
6
|
export { INTRODUCTION_CAPABILITIES, mintIntroductionCapability, redeemIntroductionCapability, listIntroductionsCapability, revokeIntroductionCapability, } from './introductions.js';
|
|
7
|
-
export { AGREEMENT_CAPABILITIES, agreementClaimCapability } from './agreements.js';
|
|
7
|
+
export { AGREEMENT_CAPABILITIES, agreementClaimCapability, presentClaimResult, } from './agreements.js';
|
|
8
|
+
export { TASK_CAPABILITIES, listTasksCapability } from './tasks.js';
|
|
8
9
|
export { AGREEMENT_PROPOSE_PROVIDER_ID_DESCRIPTION } from './proposeProviderId.js';
|
|
9
10
|
export { MARKETPLACE_CAPABILITIES, marketplaceViewCapability } from './marketplace.js';
|
|
10
11
|
export { GRANTS_CAPABILITIES, listGrantsCapability } from './grants.js';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { fullCreds, rethrowWithContext, } from './types.js';
|
|
2
|
-
export { nextCall, peerPrincipalId,
|
|
2
|
+
export { nextCall, peerPrincipalId, } from './nextCall.js';
|
|
3
3
|
export { AGREEMENT_VERB_CAPABILITIES, agreementBuyCapability, agreementBidCapability, agreementBrokerCapability, agreementRequestCapability, agreementOfferCapability, agreementHandoffCapability, } from './agreementVerbs.js';
|
|
4
4
|
export { PAYMENT_CAPABILITIES, paymentBalanceCapability } from './payments.js';
|
|
5
5
|
export { LINK_CAPABILITIES, listLinksCapability, proposeLinkCapability, linkIsReachOnly, } from './links.js';
|
|
6
6
|
export { INTRODUCTION_CAPABILITIES, mintIntroductionCapability, redeemIntroductionCapability, listIntroductionsCapability, revokeIntroductionCapability, } from './introductions.js';
|
|
7
|
-
export { AGREEMENT_CAPABILITIES, agreementClaimCapability } from './agreements.js';
|
|
7
|
+
export { AGREEMENT_CAPABILITIES, agreementClaimCapability, presentClaimResult, } from './agreements.js';
|
|
8
|
+
export { TASK_CAPABILITIES, listTasksCapability } from './tasks.js';
|
|
8
9
|
export { AGREEMENT_PROPOSE_PROVIDER_ID_DESCRIPTION } from './proposeProviderId.js';
|
|
9
10
|
export { MARKETPLACE_CAPABILITIES, marketplaceViewCapability } from './marketplace.js';
|
|
10
11
|
export { GRANTS_CAPABILITIES, listGrantsCapability } from './grants.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLink, listAgreements } from '../http/AgreementClient.js';
|
|
2
|
-
import { nextCall
|
|
2
|
+
import { nextCall } from './nextCall.js';
|
|
3
3
|
import { fullCreds } from './types.js';
|
|
4
4
|
const DEFAULT_WEB_URL = 'https://ziggsai.com';
|
|
5
5
|
export function webAppOrigin(env) {
|
|
@@ -31,7 +31,7 @@ function inviteShareUrl(env, agreementId) {
|
|
|
31
31
|
*/
|
|
32
32
|
export function linkIsReachOnly(env) {
|
|
33
33
|
return env.surface === 'mcp'
|
|
34
|
-
? 'A link is reach-only — it shares no context on its own. Open a chat with the PERSON on the other side (ziggs_chat_open, participantId =
|
|
34
|
+
? 'A link is reach-only — it shares no context on its own. Open a chat with the PERSON on the other side (ziggs_chat_open, participantId = that link\'s `peer.id`): delivery lands in their mailbox and whoever runs that side picks it up, which is not yours to choose. Use `peer.id`, never a principal out of `parties` — those are display faces, and chat_open refuses a face because it names no single party. Opening the room admits both sides to read and post from then on. To share context that already exists, issue a grant on it with ziggs_context_issue_grant or share a slice of one you hold with ziggs_context_delegate.'
|
|
35
35
|
: 'A link is reach-only — it shares no context on its own. Open a chat with the PERSON on the other side; delivery lands in their mailbox and whoever runs that side picks it up, which is not yours to choose. Opening the room admits both sides to it from then on. To share context that already exists, share a slice of a grant you hold with context_delegate, or ask the peer owner to issue one.';
|
|
36
36
|
}
|
|
37
37
|
const LINK_STATUSES = ['active', 'open', 'cancelled', 'all'];
|
|
@@ -53,8 +53,8 @@ export const listLinksCapability = {
|
|
|
53
53
|
names: { sdk: 'link_list', mcp: 'ziggs_link_list' },
|
|
54
54
|
title: 'List your links',
|
|
55
55
|
descriptions: {
|
|
56
|
-
sdk: 'List link agreements for this agent — bilateral agent-to-agent trust relationships (GET /agreements?engagementKind=link). Any agent can link with any other agent. Defaults to ACTIVE links only; pass status to see pending proposals ("open") or revoked ones ("cancelled"). Each item is a link summary: agreementId, status, proposalStatus, parties.
|
|
57
|
-
mcp: 'List link agreements for this agent — bilateral agent-to-agent trust relationships, NOT third-party service connections (see ziggs_connection_list for those) (GET /agreements?engagementKind=link). Any agent can link with any other agent. Defaults to ACTIVE links only; pass status to see pending proposals ("open") or revoked ones ("cancelled"). Each item is a link summary: agreementId, status, proposalStatus, and
|
|
56
|
+
sdk: 'List link agreements for this agent — bilateral agent-to-agent trust relationships (GET /agreements?engagementKind=link). Any agent can link with any other agent. Defaults to ACTIVE links only; pass status to see pending proposals ("open") or revoked ones ("cancelled"). Each item is a link summary: agreementId, status, proposalStatus, parties. Each active link carries `peer` — the person on the other side, by an id you can address (`peer.id`) plus their name. Address them with that. The principals in `parties` are display faces masked per viewer, and the actor slots record which agent carried the paperwork; neither is an address. Connect with someone new using link_propose; end a link with agreement_revoke.',
|
|
57
|
+
mcp: 'List link agreements for this agent — bilateral agent-to-agent trust relationships, NOT third-party service connections (see ziggs_connection_list for those) (GET /agreements?engagementKind=link). Any agent can link with any other agent. Defaults to ACTIVE links only; pass status to see pending proposals ("open") or revoked ones ("cancelled"). Each item is a link summary: agreementId, status, proposalStatus, parties, and — on links where you are one of the two sides — `peer`, the person on the other side by an addressable id (`peer.id`) and name. To reach them, pass `peer.id` to ziggs_chat_open. Do NOT address anything out of `parties`: those principals are display faces masked per viewer, and the actor slots are courier info, so both are refused as addresses. Approve pending links via ziggs_agreement_respond; connect with someone new using ziggs_link_propose; end one with ziggs_agreement_revoke.',
|
|
58
58
|
},
|
|
59
59
|
annotation: 'read-only',
|
|
60
60
|
params: {
|
|
@@ -77,27 +77,26 @@ export const listLinksCapability = {
|
|
|
77
77
|
const active = links.filter((a) => a.status === 'active');
|
|
78
78
|
// A link grants reach and nothing else, so the move after seeing one is
|
|
79
79
|
// always the same: open a room with that peer, or share context explicitly.
|
|
80
|
-
// Both were named in prose, and the peer id had to be dug out of `parties`
|
|
81
|
-
// by whoever read it — while being right here.
|
|
82
80
|
//
|
|
83
|
-
// The peer
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
//
|
|
81
|
+
// The peer id comes from the server now. Two earlier attempts read it off
|
|
82
|
+
// `parties` here and both were wrong: the peer's `actor` is courier info,
|
|
83
|
+
// null on any link two people formed from the web; the peer's `principal`
|
|
84
|
+
// is display state, masked to a `psn_` face across an org boundary — which
|
|
85
|
+
// is every link — and chat_open refuses a face. Neither could be fixed on
|
|
86
|
+
// this side, because the addressable id is not in the payload to find. It
|
|
87
|
+
// is now, as `peer`, resolved relative to whoever asked.
|
|
89
88
|
const readPlan = [];
|
|
90
89
|
let unnamedPeers = 0;
|
|
91
90
|
for (const link of active.slice(0, 3)) {
|
|
92
|
-
const peer =
|
|
91
|
+
const peer = link.peer?.id;
|
|
93
92
|
if (!peer) {
|
|
94
93
|
unnamedPeers += 1;
|
|
95
94
|
continue;
|
|
96
95
|
}
|
|
97
|
-
readPlan.push(nextCall(env, 'chat_open', { participantId: peer },
|
|
96
|
+
readPlan.push(nextCall(env, 'chat_open', { participantId: peer }, `open a room with ${link.peer?.name ?? 'this linked peer'} — a link alone carries no context`));
|
|
98
97
|
}
|
|
99
98
|
if (unnamedPeers > 0) {
|
|
100
|
-
readPlan.push(nextCall(env, 'chat_open', undefined, 'open a room with a linked peer: participantId is
|
|
99
|
+
readPlan.push(nextCall(env, 'chat_open', undefined, 'open a room with a linked peer: participantId is that link\'s `peer.id`. Do NOT pass a principal out of `parties` — those are display faces and chat_open refuses them'));
|
|
101
100
|
}
|
|
102
101
|
if (active.length) {
|
|
103
102
|
readPlan.push(nextCall(env, 'context_issue_grant', undefined, 'share context that already exists: a link does not share any on its own'));
|
|
@@ -54,22 +54,3 @@ export declare function nextCall(env: CapabilityEnv, capabilityKey: string, args
|
|
|
54
54
|
* call: the caller would run it, and it would do something they did not ask for.
|
|
55
55
|
*/
|
|
56
56
|
export declare function peerPrincipalId(parties: AgreementParties | undefined, selfId: string | undefined): string | null;
|
|
57
|
-
/**
|
|
58
|
-
* The peer's principal, located by finding MY side rather than by knowing my
|
|
59
|
-
* own principal id.
|
|
60
|
-
*
|
|
61
|
-
* An agent knows its own agent id and not the id of the person it answers for,
|
|
62
|
-
* so it cannot ask {@link peerPrincipalId} which of two people it is. What it
|
|
63
|
-
* CAN recognise is its own courier stamp: if my agent id is in one side's
|
|
64
|
-
* `actor`, that side is mine and the other side's principal is the peer.
|
|
65
|
-
*
|
|
66
|
-
* Note the difference from the bug this replaced. Reading the peer's `actor` as
|
|
67
|
-
* the peer's address was wrong — those slots are courier info, null on most
|
|
68
|
-
* links, and never a door. Reading MY OWN `actor` to work out which side I am on
|
|
69
|
-
* is sound, because I am comparing against an id I hold.
|
|
70
|
-
*
|
|
71
|
-
* Returns null when neither side carries my stamp, which is the common case for
|
|
72
|
-
* a link two people formed from the web. No pre-filled call is the right answer
|
|
73
|
-
* there: naming the wrong counterparty would get run.
|
|
74
|
-
*/
|
|
75
|
-
export declare function peerPrincipalForCourier(parties: AgreementParties | undefined, myAgentId: string | undefined): string | null;
|
|
@@ -45,34 +45,3 @@ export function peerPrincipalId(parties, selfId) {
|
|
|
45
45
|
return provider;
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
49
|
-
* The peer's principal, located by finding MY side rather than by knowing my
|
|
50
|
-
* own principal id.
|
|
51
|
-
*
|
|
52
|
-
* An agent knows its own agent id and not the id of the person it answers for,
|
|
53
|
-
* so it cannot ask {@link peerPrincipalId} which of two people it is. What it
|
|
54
|
-
* CAN recognise is its own courier stamp: if my agent id is in one side's
|
|
55
|
-
* `actor`, that side is mine and the other side's principal is the peer.
|
|
56
|
-
*
|
|
57
|
-
* Note the difference from the bug this replaced. Reading the peer's `actor` as
|
|
58
|
-
* the peer's address was wrong — those slots are courier info, null on most
|
|
59
|
-
* links, and never a door. Reading MY OWN `actor` to work out which side I am on
|
|
60
|
-
* is sound, because I am comparing against an id I hold.
|
|
61
|
-
*
|
|
62
|
-
* Returns null when neither side carries my stamp, which is the common case for
|
|
63
|
-
* a link two people formed from the web. No pre-filled call is the right answer
|
|
64
|
-
* there: naming the wrong counterparty would get run.
|
|
65
|
-
*/
|
|
66
|
-
export function peerPrincipalForCourier(parties, myAgentId) {
|
|
67
|
-
if (!parties || !myAgentId)
|
|
68
|
-
return null;
|
|
69
|
-
const mineIsCreator = parties.creator?.actor === myAgentId;
|
|
70
|
-
const mineIsProvider = parties.provider?.actor === myAgentId;
|
|
71
|
-
// Both sides stamped with me is one estate on both ends, not a peer.
|
|
72
|
-
if (mineIsCreator === mineIsProvider)
|
|
73
|
-
return null;
|
|
74
|
-
const peer = mineIsCreator
|
|
75
|
-
? parties.provider?.principal
|
|
76
|
-
: parties.creator?.principal;
|
|
77
|
-
return peer && peer !== myAgentId ? peer : null;
|
|
78
|
-
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CapabilityDefinition } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* One list-tasks verb. MCP and the hosted SDK both used to re-declare the
|
|
4
|
+
* same GET /tasks filters; assignedToMe vs assignedTo precedence then
|
|
5
|
+
* drifted independently. The handler is the single place that resolves
|
|
6
|
+
* those shorthands onto the HTTP query.
|
|
7
|
+
*/
|
|
8
|
+
export declare const listTasksCapability: CapabilityDefinition;
|
|
9
|
+
export declare const TASK_CAPABILITIES: CapabilityDefinition[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { listTasks } from '../http/TaskClient.js';
|
|
2
|
+
import { fullCreds } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* One list-tasks verb. MCP and the hosted SDK both used to re-declare the
|
|
5
|
+
* same GET /tasks filters; assignedToMe vs assignedTo precedence then
|
|
6
|
+
* drifted independently. The handler is the single place that resolves
|
|
7
|
+
* those shorthands onto the HTTP query.
|
|
8
|
+
*/
|
|
9
|
+
export const listTasksCapability = {
|
|
10
|
+
key: 'task_list',
|
|
11
|
+
names: { sdk: 'task_list', mcp: 'ziggs_task_list' },
|
|
12
|
+
title: 'List tasks',
|
|
13
|
+
descriptions: {
|
|
14
|
+
sdk: 'List tasks reachable by this agent (GET /tasks). Scope follows the operator key — same reach as chats and agreements. Optional state / assignee filters and cursor pagination. Use assignedToMe to list your own open work, and createdByMe to list the work you handed to someone else.',
|
|
15
|
+
mcp: 'List tasks reachable by the acting agent (GET /tasks). Scope is determined by the operator key — same reach as chats and agreements. Optional state / assignee filters and cursor pagination. Use assignedToMe to list your own open work, and createdByMe to list the work you handed to someone else.',
|
|
16
|
+
},
|
|
17
|
+
annotation: 'read-only',
|
|
18
|
+
params: {
|
|
19
|
+
state: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'Filter by state: active, completed, failed, cancelled',
|
|
22
|
+
},
|
|
23
|
+
cursor: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
description: 'Opaque cursor from a prior nextCursor',
|
|
26
|
+
},
|
|
27
|
+
limit: {
|
|
28
|
+
type: 'number',
|
|
29
|
+
description: 'Max rows (server default when omitted)',
|
|
30
|
+
},
|
|
31
|
+
assignedTo: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'Filter to tasks assigned to this agent/user id',
|
|
34
|
+
},
|
|
35
|
+
createdByMe: {
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
description: 'Tasks YOU created — the work you handed out to others. This is the check before delegating: assignedToMe lists only what was handed TO you, so a job you already assigned does not appear there and you would assign it twice.',
|
|
38
|
+
},
|
|
39
|
+
assignedToMe: {
|
|
40
|
+
type: 'boolean',
|
|
41
|
+
description: "Shorthand for assignedTo=<this agent's id>. Takes precedence over assignedTo when both are set.",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
needsAgentId: true,
|
|
45
|
+
handler: async (args, env) => {
|
|
46
|
+
const creds = fullCreds(env);
|
|
47
|
+
const assignedTo = args['assignedToMe']
|
|
48
|
+
? creds.agentId
|
|
49
|
+
: args['assignedTo'];
|
|
50
|
+
const createdBy = args['createdByMe'] ? creds.agentId : undefined;
|
|
51
|
+
return listTasks({
|
|
52
|
+
state: args['state'],
|
|
53
|
+
cursor: args['cursor'],
|
|
54
|
+
limit: typeof args['limit'] === 'number' ? args['limit'] : undefined,
|
|
55
|
+
assignedTo,
|
|
56
|
+
...(createdBy ? { createdBy } : {}),
|
|
57
|
+
}, creds);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
export const TASK_CAPABILITIES = [listTasksCapability];
|
|
@@ -54,6 +54,12 @@ export function linkSummary(a) {
|
|
|
54
54
|
provider: side(a.parties?.provider),
|
|
55
55
|
proposedTo: side(a.parties?.proposedTo),
|
|
56
56
|
},
|
|
57
|
+
// The one id on a link that can be acted on. `parties` is display state —
|
|
58
|
+
// masked per viewer, so the peer arrives as a face that every addressing
|
|
59
|
+
// verb refuses — which left a link summary carrying nobody you could open a
|
|
60
|
+
// chat with. Dropping it here is what that looked like: the server sent the
|
|
61
|
+
// peer and the allow-list ate it before any caller saw it.
|
|
62
|
+
...(a.peer ? { peer: a.peer } : {}),
|
|
57
63
|
...(a.description ? { description: a.description } : {}),
|
|
58
64
|
// Seat bookkeeping on an open invite — link state, not commerce.
|
|
59
65
|
...(a.linkInvite ? { linkInvite: a.linkInvite } : {}),
|
|
@@ -9,8 +9,9 @@ export interface ChatSummary {
|
|
|
9
9
|
orgId: string | null;
|
|
10
10
|
isOrgChat: boolean;
|
|
11
11
|
}
|
|
12
|
-
export declare function openConversation(participantId: string, creds: Creds, { newChat }?: {
|
|
12
|
+
export declare function openConversation(participantId: string, creds: Creds, { newChat, agreementId }?: {
|
|
13
13
|
newChat?: boolean;
|
|
14
|
+
agreementId?: string;
|
|
14
15
|
}): Promise<{
|
|
15
16
|
chatId: string;
|
|
16
17
|
reused?: boolean;
|
|
@@ -91,6 +92,7 @@ export declare class ChatClient {
|
|
|
91
92
|
constructor(operatorKey: string, agentId?: string);
|
|
92
93
|
open(participantId: string, opts?: {
|
|
93
94
|
newChat?: boolean;
|
|
95
|
+
agreementId?: string;
|
|
94
96
|
}): Promise<{
|
|
95
97
|
chatId: string;
|
|
96
98
|
reused?: boolean;
|
package/dist/http/ChatClient.js
CHANGED
|
@@ -17,7 +17,7 @@ function assertCreds(creds, op) {
|
|
|
17
17
|
if (!creds?.agentId)
|
|
18
18
|
throw new Error(`agentId is required for ${op}`);
|
|
19
19
|
}
|
|
20
|
-
export async function openConversation(participantId, creds, { newChat = false } = {}) {
|
|
20
|
+
export async function openConversation(participantId, creds, { newChat = false, agreementId } = {}) {
|
|
21
21
|
if (!participantId)
|
|
22
22
|
throw new Error('participantId is required for openConversation');
|
|
23
23
|
assertCreds(creds, 'open conversation');
|
|
@@ -26,7 +26,11 @@ export async function openConversation(participantId, creds, { newChat = false }
|
|
|
26
26
|
headers: buildHeaders(creds),
|
|
27
27
|
// Only sent when asked for: an older backend ignores the field, so a
|
|
28
28
|
// caller that never wants a separate room behaves identically either way.
|
|
29
|
-
body: JSON.stringify({
|
|
29
|
+
body: JSON.stringify({
|
|
30
|
+
participantId,
|
|
31
|
+
...(newChat ? { newChat: true } : {}),
|
|
32
|
+
...(agreementId ? { agreementId } : {}),
|
|
33
|
+
}),
|
|
30
34
|
});
|
|
31
35
|
if (!res.ok) {
|
|
32
36
|
const body = await res.text().catch(() => '');
|
|
@@ -27,13 +27,23 @@ export type OrgResolution = {
|
|
|
27
27
|
* match. Ambiguous names return the candidates rather than guessing.
|
|
28
28
|
*/
|
|
29
29
|
export declare function resolveOrgSelector(orgs: MyOrg[], selector: string): OrgResolution;
|
|
30
|
-
/**
|
|
31
|
-
|
|
30
|
+
/**
|
|
31
|
+
* MCP OAuth auto-provisioned delegate id prefix.
|
|
32
|
+
*
|
|
33
|
+
* The backend stopped classifying delegates by their id and now reads a stamp
|
|
34
|
+
* on the agent row, which is what freed the prefix to drop the vendor name. A
|
|
35
|
+
* client holds credentials, not rows, so this is still a shape test — but it is
|
|
36
|
+
* a shape test against a NAME, and the only thing it decides is which access
|
|
37
|
+
* endpoint to read. It said `delegate--` until the ids were renamed;
|
|
38
|
+
* left alone, every delegate session would have fallen through to the hosted
|
|
39
|
+
* reader and reported the wrong org and connection state.
|
|
40
|
+
*/
|
|
41
|
+
export declare const MCP_OAUTH_DELEGATE_AGENT_ID_PREFIX = "delegate--";
|
|
32
42
|
/** True when `agentId` is an inbound MCP OAuth auto-provisioned delegate. */
|
|
33
43
|
export declare function isMcpOAuthDelegateAgentId(agentId: string): boolean;
|
|
34
44
|
/**
|
|
35
45
|
* runtime acting org from the server (self-hire / agent
|
|
36
|
-
* row): GET /agents/
|
|
46
|
+
* row): GET /agents/delegate/access. Moved here from ziggs-mcp's inline
|
|
37
47
|
* fetch ( "one client for every surface").
|
|
38
48
|
*
|
|
39
49
|
* Only valid for MCP OAuth Claude-delegate sessions. Hosted / fleet
|
|
@@ -44,7 +54,7 @@ export declare function fetchDelegateAccess(creds: Creds, baseUrl?: string): Pro
|
|
|
44
54
|
* session access for hosted / fleet impersonation (owner key +
|
|
45
55
|
* X-Agent-Id, or an agent-scoped key that is not a Claude OAuth delegate).
|
|
46
56
|
*
|
|
47
|
-
* `GET /agents/
|
|
57
|
+
* `GET /agents/delegate/access` refuses those credentials (or reports
|
|
48
58
|
* disconnected), even though every other tool works. The credential's tenant
|
|
49
59
|
* is already on the actor (`GET /orgs/me` → `activeOrgId`).
|
|
50
60
|
*/
|
package/dist/http/OrgsClient.js
CHANGED
|
@@ -42,29 +42,39 @@ export function resolveOrgSelector(orgs, selector) {
|
|
|
42
42
|
return { status: 'ambiguous', matches: byName };
|
|
43
43
|
return { status: 'not-found' };
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
|
|
45
|
+
/**
|
|
46
|
+
* MCP OAuth auto-provisioned delegate id prefix.
|
|
47
|
+
*
|
|
48
|
+
* The backend stopped classifying delegates by their id and now reads a stamp
|
|
49
|
+
* on the agent row, which is what freed the prefix to drop the vendor name. A
|
|
50
|
+
* client holds credentials, not rows, so this is still a shape test — but it is
|
|
51
|
+
* a shape test against a NAME, and the only thing it decides is which access
|
|
52
|
+
* endpoint to read. It said `delegate--` until the ids were renamed;
|
|
53
|
+
* left alone, every delegate session would have fallen through to the hosted
|
|
54
|
+
* reader and reported the wrong org and connection state.
|
|
55
|
+
*/
|
|
56
|
+
export const MCP_OAUTH_DELEGATE_AGENT_ID_PREFIX = 'delegate--';
|
|
47
57
|
/** True when `agentId` is an inbound MCP OAuth auto-provisioned delegate. */
|
|
48
58
|
export function isMcpOAuthDelegateAgentId(agentId) {
|
|
49
59
|
return !!agentId && agentId.startsWith(MCP_OAUTH_DELEGATE_AGENT_ID_PREFIX);
|
|
50
60
|
}
|
|
51
61
|
/**
|
|
52
62
|
* runtime acting org from the server (self-hire / agent
|
|
53
|
-
* row): GET /agents/
|
|
63
|
+
* row): GET /agents/delegate/access. Moved here from ziggs-mcp's inline
|
|
54
64
|
* fetch ( "one client for every surface").
|
|
55
65
|
*
|
|
56
66
|
* Only valid for MCP OAuth Claude-delegate sessions. Hosted / fleet
|
|
57
67
|
* impersonation must use {@link fetchHostedAgentAccess}.
|
|
58
68
|
*/
|
|
59
69
|
export async function fetchDelegateAccess(creds, baseUrl) {
|
|
60
|
-
const url = `${baseUrl || getBackendUrl()}/agents/
|
|
70
|
+
const url = `${baseUrl || getBackendUrl()}/agents/delegate/access`;
|
|
61
71
|
const res = await fetch(url, {
|
|
62
72
|
method: 'GET',
|
|
63
73
|
headers: buildOperatorHeaders(creds.operatorKey, creds.agentId),
|
|
64
74
|
});
|
|
65
75
|
const body = await res.text().catch(() => '');
|
|
66
76
|
if (!res.ok) {
|
|
67
|
-
throwApiError(res, body, `GET /agents/
|
|
77
|
+
throwApiError(res, body, `GET /agents/delegate/access failed: ${res.status}`);
|
|
68
78
|
}
|
|
69
79
|
return body ? JSON.parse(body) : {};
|
|
70
80
|
}
|
|
@@ -72,7 +82,7 @@ export async function fetchDelegateAccess(creds, baseUrl) {
|
|
|
72
82
|
* session access for hosted / fleet impersonation (owner key +
|
|
73
83
|
* X-Agent-Id, or an agent-scoped key that is not a Claude OAuth delegate).
|
|
74
84
|
*
|
|
75
|
-
* `GET /agents/
|
|
85
|
+
* `GET /agents/delegate/access` refuses those credentials (or reports
|
|
76
86
|
* disconnected), even though every other tool works. The credential's tenant
|
|
77
87
|
* is already on the actor (`GET /orgs/me` → `activeOrgId`).
|
|
78
88
|
*/
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which process is calling GET /inbox.
|
|
3
|
+
*
|
|
4
|
+
* The exclusive-read claimant must be the *host* (this fleet task, a
|
|
5
|
+
* laptop fleet, an MCP process), not the API process. Two fleets share
|
|
6
|
+
* one backend task, so stamping the API's identity would let both wake.
|
|
7
|
+
*
|
|
8
|
+
* `ecs:<id>` on Fargate, `local:<host>:<pid>` otherwise. Env-derived
|
|
9
|
+
* and memoized.
|
|
10
|
+
*/
|
|
1
11
|
export declare const INBOX_HOST_CLAIMANT_HEADER = "X-Ziggs-Instance";
|
|
2
12
|
export declare function instanceIdentity(): string;
|
|
3
13
|
/** Test seam: forget the memoized value so a case can set different env. */
|
package/dist/instanceIdentity.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { hostname } from 'node:os';
|
|
2
1
|
/**
|
|
3
2
|
* Which process is calling GET /inbox.
|
|
4
3
|
*
|
|
@@ -36,7 +35,19 @@ function resolve() {
|
|
|
36
35
|
}
|
|
37
36
|
function safeHostname() {
|
|
38
37
|
try {
|
|
39
|
-
|
|
38
|
+
// Reached for at call time, not imported at the top of the file. A static
|
|
39
|
+
// `node:os` specifier makes this module — and through the inbox client,
|
|
40
|
+
// the package entry — unresolvable to a bundler with no node builtins,
|
|
41
|
+
// which is every mobile bundler. Nothing here needs the host name in order
|
|
42
|
+
// to load.
|
|
43
|
+
//
|
|
44
|
+
// `getBuiltinModule` arrived in Node 20.16 / 22.3. On anything older the
|
|
45
|
+
// name falls back below, which costs a host label on a dev machine and
|
|
46
|
+
// nothing in a deployed task: those resolve through the container
|
|
47
|
+
// metadata path above.
|
|
48
|
+
const load = process.getBuiltinModule;
|
|
49
|
+
const os = load?.('node:os');
|
|
50
|
+
return os?.hostname?.() || 'unknown-host';
|
|
40
51
|
}
|
|
41
52
|
catch {
|
|
42
53
|
return 'unknown-host';
|
package/dist/types.d.ts
CHANGED
|
@@ -168,6 +168,18 @@ export interface Agreement {
|
|
|
168
168
|
engagementKind?: EngagementKind;
|
|
169
169
|
proposalStatus?: ProposalStatus;
|
|
170
170
|
parties?: AgreementParties;
|
|
171
|
+
/**
|
|
172
|
+
* On a LINK, the person on the other side by an id you can address.
|
|
173
|
+
*
|
|
174
|
+
* `parties` is display state: read across an org boundary a principal comes
|
|
175
|
+
* back as a `psn_` face, which names no single party and every addressing
|
|
176
|
+
* verb refuses. This is the same person, resolved server-side relative to
|
|
177
|
+
* you. Present only when you are one of the two sides.
|
|
178
|
+
*/
|
|
179
|
+
peer?: {
|
|
180
|
+
id: string;
|
|
181
|
+
name: string;
|
|
182
|
+
};
|
|
171
183
|
approvals?: AgreementApprovalEntry[];
|
|
172
184
|
/** Legacy root-level price — always null in practice. Use money.price instead. */
|
|
173
185
|
price?: number | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ziggs-ai/api-client",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"description": "HTTP and WebSocket client for the Ziggs backend API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,11 +15,6 @@
|
|
|
15
15
|
"types": "./dist/http/index.d.ts",
|
|
16
16
|
"import": "./dist/http/index.js",
|
|
17
17
|
"default": "./dist/http/index.js"
|
|
18
|
-
},
|
|
19
|
-
"./websocket": {
|
|
20
|
-
"types": "./dist/websocket/index.d.ts",
|
|
21
|
-
"import": "./dist/websocket/index.js",
|
|
22
|
-
"default": "./dist/websocket/index.js"
|
|
23
18
|
}
|
|
24
19
|
},
|
|
25
20
|
"engines": {
|