@ziggs-ai/api-client 0.3.0 → 0.4.0

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.
Files changed (37) hide show
  1. package/dist/capabilities/artifacts.d.ts +3 -0
  2. package/dist/capabilities/artifacts.js +86 -0
  3. package/dist/capabilities/chat.d.ts +11 -0
  4. package/dist/capabilities/chat.js +38 -0
  5. package/dist/capabilities/connections.d.ts +4 -0
  6. package/dist/capabilities/connections.js +112 -0
  7. package/dist/capabilities/context.d.ts +23 -0
  8. package/dist/capabilities/context.js +220 -0
  9. package/dist/capabilities/discovery.d.ts +4 -0
  10. package/dist/capabilities/discovery.js +77 -0
  11. package/dist/capabilities/grants.d.ts +9 -0
  12. package/dist/capabilities/grants.js +77 -0
  13. package/dist/capabilities/index.d.ts +9 -0
  14. package/dist/capabilities/index.js +9 -0
  15. package/dist/capabilities/links.d.ts +17 -0
  16. package/dist/capabilities/links.js +193 -0
  17. package/dist/capabilities/payments.d.ts +11 -0
  18. package/dist/capabilities/payments.js +404 -0
  19. package/dist/capabilities/types.d.ts +88 -0
  20. package/dist/capabilities/types.js +24 -0
  21. package/dist/http/AgreementClient.d.ts +7 -0
  22. package/dist/http/AgreementClient.js +2 -0
  23. package/dist/http/ConnectionsClient.d.ts +27 -1
  24. package/dist/http/ConnectionsClient.js +29 -0
  25. package/dist/http/GrantsClient.d.ts +16 -0
  26. package/dist/http/GrantsClient.js +3 -0
  27. package/dist/http/OrgsClient.d.ts +36 -0
  28. package/dist/http/OrgsClient.js +61 -0
  29. package/dist/http/PaymentsClient.d.ts +75 -10
  30. package/dist/http/PaymentsClient.js +26 -14
  31. package/dist/http/index.d.ts +5 -5
  32. package/dist/http/index.js +1 -1
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.js +1 -0
  35. package/package.json +1 -1
  36. package/dist/http/grantRails.d.ts +0 -20
  37. package/dist/http/grantRails.js +0 -50
@@ -0,0 +1,77 @@
1
+ import { GrantsClient } from '../http/GrantsClient.js';
2
+ import { fullCreds } from './types.js';
3
+ const SCOPE_KINDS = [
4
+ 'chat',
5
+ 'agreement',
6
+ 'org',
7
+ 'connection',
8
+ 'wallet',
9
+ ];
10
+ const HEALTHS = ['active', 'expired', 'revoked'];
11
+ function parseScopeKinds(raw) {
12
+ if (raw == null)
13
+ return undefined;
14
+ const list = Array.isArray(raw) ? raw : [raw];
15
+ const out = [];
16
+ for (const r of list) {
17
+ if (!SCOPE_KINDS.includes(r)) {
18
+ throw new Error(`scopeKind must be one of ${SCOPE_KINDS.join(', ')}`);
19
+ }
20
+ if (!out.includes(r))
21
+ out.push(r);
22
+ }
23
+ return out.length ? out : undefined;
24
+ }
25
+ /**
26
+ * ZIG-893 — the single "what authority do I hold?" tool. One name, every rail
27
+ * (context chat/agreement/org, connection, wallet), holder-scoped,
28
+ * cross-session. `unreadableRails` comes from the backend (ZIG-956) so a short
29
+ * list is never presented as complete when the key can't read a rail.
30
+ */
31
+ export const listGrantsCapability = {
32
+ key: 'list_grants',
33
+ names: { sdk: 'list_grants', mcp: 'ziggs_list_grants' },
34
+ descriptions: {
35
+ sdk: 'List every grant this agent holds across all rails in one call — context (chat/agreement/org), connection, and wallet — as canonical grants (grantId, scope, caveats, expiresAt, health; no message/artifact content or credentials). The single answer to "what grants of mine do you hold?", holder-scoped and cross-session. Filter by scopeKind (rail) and health (defaults to active). Rails you lack the operator-key read scope for are named in unreadableRails, not silently dropped. Cursor-paginated: pass cursor from a prior nextCursor. Pair with context_read to read through a context grant, or context_expand_reach to enumerate a scope.',
36
+ mcp: 'List every grant this delegate holds across all rails in one call — context (chat/agreement/org), connection, and wallet — as canonical grants (grantId, scope, caveats, expiresAt, health; no content or credentials). The single answer to "what grants of mine do you hold?", holder-scoped and cross-session. Filter by scopeKind (rail) and health (defaults to active). Rails you lack the operator-key read scope for are named in unreadableRails, not silently dropped. Cursor-paginated: pass cursor from a prior nextCursor to page. Pass a grantId to ziggs_read_context to pin a specific grant, or ziggs_expand_context to enumerate a scope.',
37
+ },
38
+ annotation: 'read-only',
39
+ params: {
40
+ scopeKind: {
41
+ type: 'array',
42
+ items: { type: 'string', enum: SCOPE_KINDS },
43
+ description: 'Rail filter (repeatable): chat | agreement | org (context) | connection | wallet. Omit for every rail you can read.',
44
+ },
45
+ health: {
46
+ type: 'string',
47
+ enum: HEALTHS,
48
+ description: 'Grant health filter. Defaults to active (live grants only).',
49
+ },
50
+ cursor: { type: 'string', description: 'Opaque cursor from a prior nextCursor to page' },
51
+ limit: { type: 'number', description: 'Page size (server default when omitted)' },
52
+ },
53
+ needsAgentId: true,
54
+ handler: async (args, env) => {
55
+ const creds = fullCreds(env);
56
+ const scopeKind = parseScopeKinds(args['scopeKind']);
57
+ const healthArg = args['health'];
58
+ if (healthArg !== undefined && !HEALTHS.includes(healthArg)) {
59
+ throw new Error(`health must be one of ${HEALTHS.join(', ')}`);
60
+ }
61
+ const { items, nextCursor, unreadableRails } = await new GrantsClient(creds.operatorKey, creds.agentId, env.baseUrl).listGrants({
62
+ scopeKind,
63
+ // Reach = live grants only by default; pass health to see expired/revoked.
64
+ health: healthArg ?? 'active',
65
+ cursor: args['cursor'],
66
+ limit: typeof args['limit'] === 'number' ? args['limit'] : undefined,
67
+ });
68
+ return {
69
+ count: items.length,
70
+ grants: items,
71
+ nextCursor,
72
+ ...(unreadableRails?.length ? { unreadableRails } : {}),
73
+ };
74
+ },
75
+ sdkOptions: { isGenericFallback: true },
76
+ };
77
+ export const GRANTS_CAPABILITIES = [listGrantsCapability];
@@ -0,0 +1,9 @@
1
+ export { type CapabilitySurface, type CapabilityAnnotation, type CapabilityParam, type CapabilityEnv, type CapabilityDefinition, fullCreds, rethrowWithContext, } from './types.js';
2
+ export { PAYMENT_CAPABILITIES, paymentBalanceCapability, paymentTransferCapability, paymentWaitForApprovalCapability, paymentHoldCapability, paymentReleaseCapability, paymentResolveWalletCapability, paymentIssueGrantCapability, paymentAttenuateGrantCapability, paymentRevokeGrantCapability, } from './payments.js';
3
+ export { LINK_CAPABILITIES, requestLinkCapability, createLinkInviteCapability, claimLinkInviteCapability, listLinksCapability, revokeLinkCapability, linkSummary, linkIsReachOnly, } from './links.js';
4
+ export { GRANTS_CAPABILITIES, listGrantsCapability } from './grants.js';
5
+ export { CONTEXT_CAPABILITIES, contextReadCapability, contextDelegateCapability, contextExpandReachCapability, contextDiscoverGrantableCapability, contextBounds, resolveOrgScopeId, } from './context.js';
6
+ export { CONNECTION_CAPABILITIES, connectionProxyCapability, requestConnectionCapability, } from './connections.js';
7
+ export { DISCOVERY_CAPABILITIES, agentSearchCapability, agentGetCapability, } from './discovery.js';
8
+ export { ARTIFACT_CAPABILITIES, recordArtifactCapability } from './artifacts.js';
9
+ export { CHAT_CAPABILITIES, openConversationCapability } from './chat.js';
@@ -0,0 +1,9 @@
1
+ export { fullCreds, rethrowWithContext, } from './types.js';
2
+ export { PAYMENT_CAPABILITIES, paymentBalanceCapability, paymentTransferCapability, paymentWaitForApprovalCapability, paymentHoldCapability, paymentReleaseCapability, paymentResolveWalletCapability, paymentIssueGrantCapability, paymentAttenuateGrantCapability, paymentRevokeGrantCapability, } from './payments.js';
3
+ export { LINK_CAPABILITIES, requestLinkCapability, createLinkInviteCapability, claimLinkInviteCapability, listLinksCapability, revokeLinkCapability, linkSummary, linkIsReachOnly, } from './links.js';
4
+ export { GRANTS_CAPABILITIES, listGrantsCapability } from './grants.js';
5
+ export { CONTEXT_CAPABILITIES, contextReadCapability, contextDelegateCapability, contextExpandReachCapability, contextDiscoverGrantableCapability, contextBounds, resolveOrgScopeId, } from './context.js';
6
+ export { CONNECTION_CAPABILITIES, connectionProxyCapability, requestConnectionCapability, } from './connections.js';
7
+ export { DISCOVERY_CAPABILITIES, agentSearchCapability, agentGetCapability, } from './discovery.js';
8
+ export { ARTIFACT_CAPABILITIES, recordArtifactCapability } from './artifacts.js';
9
+ export { CHAT_CAPABILITIES, openConversationCapability } from './chat.js';
@@ -0,0 +1,17 @@
1
+ import type { Agreement } from '../types.js';
2
+ import { type CapabilityDefinition, type CapabilityEnv } from './types.js';
3
+ /**
4
+ * ZIG-670 — link-shaped summaries, not raw agreement documents: the money
5
+ * block, approvals array, and Mongo internals are noise on a trust
6
+ * relationship. ZIG-956 moved this into the shared layer so the MCP mutations
7
+ * return it too (they used to leak the raw agreement doc).
8
+ */
9
+ export declare function linkSummary(a: Agreement): Record<string, unknown>;
10
+ /** A link is reach-only — the follow-up move differs by surface tool names. */
11
+ export declare function linkIsReachOnly(env: CapabilityEnv): string;
12
+ export declare const requestLinkCapability: CapabilityDefinition;
13
+ export declare const createLinkInviteCapability: CapabilityDefinition;
14
+ export declare const claimLinkInviteCapability: CapabilityDefinition;
15
+ export declare const listLinksCapability: CapabilityDefinition;
16
+ export declare const revokeLinkCapability: CapabilityDefinition;
17
+ export declare const LINK_CAPABILITIES: CapabilityDefinition[];
@@ -0,0 +1,193 @@
1
+ import { createAgreement, claimAgreement, listAgreements, revokeAgreement, } from '../http/AgreementClient.js';
2
+ import { fullCreds } from './types.js';
3
+ const DEFAULT_WEB_URL = 'https://ziggsai.com';
4
+ function webAppOrigin(env) {
5
+ return (env.webUrl?.trim() || DEFAULT_WEB_URL).replace(/\/$/, '');
6
+ }
7
+ /**
8
+ * ZIG-670 — link-shaped summaries, not raw agreement documents: the money
9
+ * block, approvals array, and Mongo internals are noise on a trust
10
+ * relationship. ZIG-956 moved this into the shared layer so the MCP mutations
11
+ * return it too (they used to leak the raw agreement doc).
12
+ */
13
+ export function linkSummary(a) {
14
+ return {
15
+ agreementId: a.agreementId,
16
+ status: a.status,
17
+ proposalStatus: a.proposalStatus,
18
+ parties: {
19
+ creatorAgent: a.parties?.creatorAgent ?? null,
20
+ providerAgent: a.parties?.providerAgent ?? null,
21
+ creator: a.parties?.creator ?? null,
22
+ proposedTo: a.parties?.proposedTo ?? null,
23
+ },
24
+ ...(a.description ? { description: a.description } : {}),
25
+ createdAt: a.createdAt,
26
+ };
27
+ }
28
+ /** A link is reach-only — the follow-up move differs by surface tool names. */
29
+ export function linkIsReachOnly(env) {
30
+ return env.surface === 'mcp'
31
+ ? 'A link is reach-only. Open a chat with the peer (ziggs_open_conversation, participantId = peer agent id) and grant it chat access with ziggs_issue_grant, or share a slice of a grant you hold with ziggs_delegate_grant, before reading context.'
32
+ : 'A link is reach-only: it does not grant context. Share a slice of a grant you hold with context_delegate, or ask the peer owner to issue one, before reading.';
33
+ }
34
+ const LINK_STATUSES = ['active', 'open', 'cancelled', 'all'];
35
+ export const requestLinkCapability = {
36
+ key: 'request_link',
37
+ names: { sdk: 'request_link', mcp: 'ziggs_request_link' },
38
+ descriptions: {
39
+ sdk: 'Request a bilateral trust link with another agent before cross-org reach (party-to-party, NOT a third-party service connection — that is the connection rail). A link is just an agreement (engagementKind "link"). The target OWNER must approve it before unpublished delegates can message each other.',
40
+ mcp: 'Request a bilateral trust link with another agent before cross-org reach (party-to-party, NOT a third-party service connection — see ziggs_list_my_connections for that). A link is just an agreement (POST /agreements {engagementKind:"link"}). The target OWNER must approve it (via ziggs_respond_to_agreement) before unpublished delegates can message each other.',
41
+ },
42
+ annotation: 'write',
43
+ params: {
44
+ providerId: {
45
+ type: 'string',
46
+ required: true,
47
+ description: 'Bare agent id to link with (the target delegate). Use agent search or a known delegate id — do not guess.',
48
+ },
49
+ message: {
50
+ type: 'string',
51
+ description: 'Optional note shown to the counterparty human on approval (agreement description)',
52
+ },
53
+ },
54
+ needsAgentId: true,
55
+ handler: async (args, env) => {
56
+ const { agreement } = await createAgreement({
57
+ engagementKind: 'link',
58
+ providerId: args['providerId'],
59
+ description: args['message'],
60
+ }, fullCreds(env));
61
+ return {
62
+ status: 'pending',
63
+ message: env.surface === 'mcp'
64
+ ? 'Link agreement created — the counterparty owner must approve (ziggs_respond_to_agreement) before cross-org reach. Surface pending state to the human.'
65
+ : 'Link agreement created — the counterparty owner must approve (agreement_respond on their side) before cross-org reach. Surface pending state to your principal.',
66
+ agreement: linkSummary(agreement),
67
+ };
68
+ },
69
+ sdkOptions: { isAgreementCreation: true },
70
+ };
71
+ export const createLinkInviteCapability = {
72
+ key: 'create_link_invite',
73
+ names: { sdk: 'create_link_invite', mcp: 'ziggs_create_link_invite' },
74
+ descriptions: {
75
+ sdk: "Create a shareable OPEN link invite (bilateral agent-to-agent trust) when you do NOT have the counterparty's agent id (e.g. connecting across orgs). Creates an open link agreement proposed to everyone; the recipient forms the link by claiming the returned inviteId.",
76
+ mcp: 'Create a shareable OPEN link invite (bilateral agent-to-agent trust, NOT a third-party service connection — see ziggs_list_my_connections for that) when you do NOT have the counterparty\'s agent id (e.g. connecting across orgs). Creates an open link agreement (POST /agreements {engagementKind:"link"}, proposedTo:"everyone"). Share the returned inviteId (agreementId) out-of-band; the recipient forms the link by calling ziggs_claim_link_invite — neither side pastes an agent id. Revoke via ziggs_revoke_link to disable.',
77
+ },
78
+ annotation: 'write',
79
+ params: {
80
+ message: {
81
+ type: 'string',
82
+ description: 'Optional note shown to whoever opens the invite (agreement description)',
83
+ },
84
+ },
85
+ needsAgentId: true,
86
+ handler: async (args, env) => {
87
+ const { agreement } = await createAgreement({ engagementKind: 'link', description: args['message'] }, fullCreds(env));
88
+ return {
89
+ status: 'open',
90
+ inviteId: agreement.agreementId,
91
+ claimUrl: `${webAppOrigin(env)}/app/link-invites/${agreement.agreementId}`,
92
+ message: env.surface === 'mcp'
93
+ ? 'Open link invite created. Share claimUrl with the counterparty — they open it in the Ziggs web app to claim and activate the link. No agent id needed on either side.'
94
+ : 'Open link invite created. Share claimUrl (or the inviteId) with the counterparty — they claim it in the Ziggs web app or via their claim_link_invite tool. No agent id needed on either side. Revoke with revoke_link to disable.',
95
+ agreement: linkSummary(agreement),
96
+ };
97
+ },
98
+ sdkOptions: { isAgreementCreation: true },
99
+ };
100
+ export const claimLinkInviteCapability = {
101
+ key: 'claim_link_invite',
102
+ names: { sdk: 'claim_link_invite', mcp: 'ziggs_claim_link_invite' },
103
+ descriptions: {
104
+ sdk: 'Claim an open link invite by its id to form a bilateral link. You become the counterparty and the link activates immediately (cross-org reach). You cannot claim your own invite.',
105
+ mcp: 'Claim an open link invite by its id to form a bilateral link (agent-to-agent trust, NOT a third-party service connection — see ziggs_list_my_connections for that) (POST /agreements/:id/claim). You become the counterparty and the link activates immediately (cross-org reach + bilateral context grants). You cannot claim your own invite.',
106
+ },
107
+ annotation: 'write',
108
+ params: {
109
+ agreementId: {
110
+ type: 'string',
111
+ required: true,
112
+ description: 'The invite id (agreementId) shared by the issuer',
113
+ },
114
+ },
115
+ needsAgentId: true,
116
+ handler: async (args, env) => {
117
+ const { agreement } = await claimAgreement(args['agreementId'], fullCreds(env));
118
+ return {
119
+ status: 'linked',
120
+ message: `Link invite claimed — you are now linked. ${linkIsReachOnly(env)}`,
121
+ agreement: linkSummary(agreement),
122
+ };
123
+ },
124
+ };
125
+ export const listLinksCapability = {
126
+ key: 'list_links',
127
+ names: { sdk: 'list_links', mcp: 'ziggs_list_links' },
128
+ descriptions: {
129
+ sdk: 'List link agreements for this agent — bilateral agent-to-agent trust relationships (GET /agreements?engagementKind=link). 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.',
130
+ mcp: 'List link agreements for this delegate — bilateral agent-to-agent trust relationships, NOT third-party service connections (see ziggs_list_my_connections for those) (GET /agreements?engagementKind=link). 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.creatorAgent (requester), parties.providerAgent (target), parties.proposedTo (target owner). Approve pending links via ziggs_respond_to_agreement.',
131
+ },
132
+ annotation: 'read-only',
133
+ params: {
134
+ status: {
135
+ type: 'string',
136
+ enum: LINK_STATUSES,
137
+ description: 'active (default) = established links; open = pending proposals/invites awaiting approval or claim; cancelled = revoked; all = every link regardless of status',
138
+ },
139
+ },
140
+ needsAgentId: true,
141
+ handler: async (args, env) => {
142
+ const status = args['status'] ?? 'active';
143
+ if (!LINK_STATUSES.includes(status)) {
144
+ throw new Error('status must be one of active, open, cancelled, all');
145
+ }
146
+ const links = await listAgreements({
147
+ engagementKind: 'link',
148
+ ...(status === 'all' ? {} : { status }),
149
+ }, fullCreds(env));
150
+ const summaries = links.map(linkSummary);
151
+ const hasActive = links.some((a) => a.status === 'active');
152
+ return {
153
+ count: summaries.length,
154
+ status,
155
+ links: summaries,
156
+ ...(hasActive ? { nextSteps: linkIsReachOnly(env) } : {}),
157
+ };
158
+ },
159
+ sdkOptions: { isGenericFallback: true },
160
+ };
161
+ export const revokeLinkCapability = {
162
+ key: 'revoke_link',
163
+ names: { sdk: 'revoke_link', mcp: 'ziggs_revoke_link' },
164
+ descriptions: {
165
+ sdk: 'Revoke a bilateral link agreement (DELETE /agreements/:agreementId). Either party may revoke; cross-org reach ends immediately. For non-link agreements (hire/service/quest), use agreement_revoke — same endpoint, different messaging.',
166
+ mcp: 'Revoke a bilateral link agreement — agent-to-agent trust, NOT a third-party service connection (DELETE /agreements/:agreementId). Either party may revoke; cross-org reach ends immediately. For non-link agreements (hire/service/quest), use ziggs_revoke_agreement — same endpoint, different messaging.',
167
+ },
168
+ annotation: 'destructive',
169
+ params: {
170
+ agreementId: {
171
+ type: 'string',
172
+ required: true,
173
+ description: 'agreementId of the link agreement (from the link lister)',
174
+ },
175
+ },
176
+ needsAgentId: true,
177
+ handler: async (args, env) => {
178
+ const result = await revokeAgreement(args['agreementId'], fullCreds(env));
179
+ return {
180
+ status: 'revoked',
181
+ message: 'Link revoked — unpublished cross-org reach to this peer is blocked again.',
182
+ agreementId: args['agreementId'],
183
+ agreement: result.agreement ? linkSummary(result.agreement) : null,
184
+ };
185
+ },
186
+ };
187
+ export const LINK_CAPABILITIES = [
188
+ requestLinkCapability,
189
+ createLinkInviteCapability,
190
+ claimLinkInviteCapability,
191
+ listLinksCapability,
192
+ revokeLinkCapability,
193
+ ];
@@ -0,0 +1,11 @@
1
+ import { type CapabilityDefinition } from './types.js';
2
+ export declare const paymentBalanceCapability: CapabilityDefinition;
3
+ export declare const paymentResolveWalletCapability: CapabilityDefinition;
4
+ export declare const paymentTransferCapability: CapabilityDefinition;
5
+ export declare const paymentWaitForApprovalCapability: CapabilityDefinition;
6
+ export declare const paymentHoldCapability: CapabilityDefinition;
7
+ export declare const paymentReleaseCapability: CapabilityDefinition;
8
+ export declare const paymentIssueGrantCapability: CapabilityDefinition;
9
+ export declare const paymentAttenuateGrantCapability: CapabilityDefinition;
10
+ export declare const paymentRevokeGrantCapability: CapabilityDefinition;
11
+ export declare const PAYMENT_CAPABILITIES: CapabilityDefinition[];