@ziggs-ai/agent-sdk 0.4.1 → 0.6.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.
- package/dist/AgentHost.d.ts +21 -0
- package/dist/AgentHost.js +61 -13
- package/dist/agent/Agent.d.ts +9 -0
- package/dist/agent/ClaudeSdkAgent.d.ts +1 -1
- package/dist/agent/ClaudeSdkAgent.js +47 -12
- package/dist/agent/claudeSdkTools.js +1 -1
- package/dist/defineAgent.d.ts +10 -5
- package/dist/defineAgent.js +16 -9
- package/dist/runtime/runTurn.js +12 -2
- package/dist/runtime/taskIntake.d.ts +18 -0
- package/dist/runtime/taskIntake.js +113 -0
- package/dist/server/ConnectionPool.d.ts +9 -2
- package/dist/server/ConnectionPool.js +18 -2
- package/dist/server/inboxLoop.d.ts +31 -11
- package/dist/server/inboxLoop.js +134 -104
- package/dist/server/runLauncher.js +9 -3
- package/dist/server/staleBacklogGate.d.ts +9 -5
- package/dist/server/staleBacklogGate.js +17 -37
- package/dist/server/tools/tier1/protocolTools.js +2 -2
- package/dist/server/tools/tier2/artifactTools.d.ts +1 -1
- package/dist/server/tools/tier2/artifactTools.js +7 -82
- package/dist/server/tools/tier2/chatTools.d.ts +1 -1
- package/dist/server/tools/tier2/chatTools.js +7 -37
- package/dist/server/tools/tier2/connectionTools.d.ts +1 -1
- package/dist/server/tools/tier2/connectionTools.js +20 -94
- package/dist/server/tools/tier2/contextTools.d.ts +2 -2
- package/dist/server/tools/tier2/contextTools.js +10 -139
- package/dist/server/tools/tier2/discoveryTools.d.ts +1 -1
- package/dist/server/tools/tier2/discoveryTools.js +7 -24
- package/dist/server/tools/tier2/grantsTools.d.ts +1 -1
- package/dist/server/tools/tier2/grantsTools.js +6 -81
- package/dist/server/tools/tier2/linkTools.d.ts +1 -1
- package/dist/server/tools/tier2/linkTools.js +12 -156
- package/dist/server/tools/tier2/paymentTools.d.ts +2 -2
- package/dist/server/tools/tier2/paymentTools.js +16 -161
- package/dist/tools/capabilityAdapter.d.ts +11 -0
- package/dist/tools/capabilityAdapter.js +30 -0
- package/dist/types.d.ts +3 -2
- package/package.json +2 -2
|
@@ -1,107 +1,33 @@
|
|
|
1
|
+
import { connectionProxyCapability, requestConnectionCapability, ConnectionsClient, } from '@ziggs-ai/api-client';
|
|
1
2
|
import { defineTool } from '../../../tools/defineTool.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
3
|
+
import { toolFromCapability } from '../../../tools/capabilityAdapter.js';
|
|
4
|
+
// ZIG-956 — connection_proxy / request_connection are shared capability
|
|
5
|
+
// definitions (api-client). connection_list_grants stays SDK-only: the MCP
|
|
6
|
+
// surface folds connection listing into ziggs_list_my_connections (ZIG-893
|
|
7
|
+
// allowance in the parity table).
|
|
8
|
+
export const connectionProxyTool = toolFromCapability(connectionProxyCapability);
|
|
9
|
+
export const requestConnectionTool = toolFromCapability(requestConnectionCapability);
|
|
10
|
+
export const connectionListGrantsTool = defineTool('connection_list_grants', { connectionId: { type: 'string', required: true } }, async (args, ctx) => {
|
|
11
|
+
if (!args['connectionId'])
|
|
12
|
+
throw new Error('connectionId is required');
|
|
4
13
|
const operatorKey = ctx?.['operatorKey'];
|
|
5
14
|
if (!operatorKey)
|
|
6
15
|
throw new Error('operatorKey missing from tool context');
|
|
7
|
-
// BACKEND_URL / ZIGGS_BACKEND_URL are the SDK runner's overrides; the shared
|
|
8
|
-
// client defaults to HTTP_URL (api-client convention) when neither is set.
|
|
9
16
|
const baseUrl = process.env.BACKEND_URL || process.env.ZIGGS_BACKEND_URL || undefined;
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
function rethrowWithContext(error, prefix) {
|
|
13
|
-
const e = error;
|
|
14
|
-
const wrapped = new Error(`${prefix}: ${e.message}`);
|
|
15
|
-
if (e.status !== undefined)
|
|
16
|
-
wrapped.status = e.status;
|
|
17
|
-
if (e.body !== undefined)
|
|
18
|
-
wrapped.body = e.body;
|
|
19
|
-
wrapped['cause'] = error;
|
|
20
|
-
throw wrapped;
|
|
21
|
-
}
|
|
22
|
-
export const connectionProxyTool = defineTool('connection_proxy', {
|
|
23
|
-
connectionId: { type: 'string', required: true },
|
|
24
|
-
grantId: { type: 'string', required: true },
|
|
25
|
-
action: { type: 'string', required: true },
|
|
26
|
-
payload: { type: 'object' },
|
|
27
|
-
}, async (args, ctx) => {
|
|
28
|
-
if (!args['connectionId'])
|
|
29
|
-
throw new Error('connectionId is required');
|
|
30
|
-
if (!args['grantId'])
|
|
31
|
-
throw new Error('grantId is required');
|
|
32
|
-
if (!args['action'])
|
|
33
|
-
throw new Error('action is required');
|
|
17
|
+
const client = new ConnectionsClient(operatorKey, ctx?.['agentId'] || undefined, baseUrl);
|
|
34
18
|
try {
|
|
35
|
-
const
|
|
36
|
-
connectionId: args['connectionId'],
|
|
37
|
-
grantId: args['grantId'],
|
|
38
|
-
action: args['action'],
|
|
39
|
-
payload: args['payload'],
|
|
40
|
-
});
|
|
41
|
-
return { status: 'ok', result };
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
rethrowWithContext(e, 'Connection proxy failed');
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
export const connectionListGrantsTool = defineTool('connection_list_grants', { connectionId: { type: 'string', required: true } }, async (args, ctx) => {
|
|
48
|
-
if (!args['connectionId'])
|
|
49
|
-
throw new Error('connectionId is required');
|
|
50
|
-
try {
|
|
51
|
-
const grants = await clientFor(ctx).listGrants({
|
|
52
|
-
connectionId: args['connectionId'],
|
|
53
|
-
});
|
|
19
|
+
const grants = await client.listGrants({ connectionId: args['connectionId'] });
|
|
54
20
|
return { grants: grants || [] };
|
|
55
21
|
}
|
|
56
22
|
catch (e) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
description: 'The chat you are working in — the consent card is opened there',
|
|
65
|
-
},
|
|
66
|
-
serverUrl: { type: 'string', required: true, description: 'Remote MCP server URL (https)' },
|
|
67
|
-
tools: {
|
|
68
|
-
type: 'array',
|
|
69
|
-
items: { type: 'string' },
|
|
70
|
-
required: true,
|
|
71
|
-
description: "Tool names you want — become the grant's allowed_actions caveats",
|
|
72
|
-
},
|
|
73
|
-
reason: {
|
|
74
|
-
type: 'string',
|
|
75
|
-
description: 'Plain-language reason shown to the human deciding',
|
|
76
|
-
},
|
|
77
|
-
}, async (args, ctx) => {
|
|
78
|
-
if (!args['chatId'])
|
|
79
|
-
throw new Error('chatId is required');
|
|
80
|
-
if (!args['serverUrl'])
|
|
81
|
-
throw new Error('serverUrl is required');
|
|
82
|
-
const tools = args['tools'];
|
|
83
|
-
if (!Array.isArray(tools) || tools.length === 0) {
|
|
84
|
-
throw new Error('tools must be a non-empty array of tool names');
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
const result = await clientFor(ctx).requestMcpConnection({
|
|
88
|
-
chatId: args['chatId'],
|
|
89
|
-
serverUrl: args['serverUrl'],
|
|
90
|
-
tools: tools,
|
|
91
|
-
reason: args['reason'],
|
|
92
|
-
});
|
|
93
|
-
return {
|
|
94
|
-
ok: true,
|
|
95
|
-
...result,
|
|
96
|
-
note: 'A connection-consent card is now in the chat awaiting your principal — they approve it right there (ZIG-798 flow). ' +
|
|
97
|
-
'Once approved, the connection + grant appear in list_grants (scopeKind=connection) / connection_list_grants for connection_proxy.',
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
catch (e) {
|
|
101
|
-
rethrowWithContext(e, 'Connection request failed');
|
|
23
|
+
const err = e;
|
|
24
|
+
const wrapped = new Error(`Failed to list connection grants: ${err.message}`);
|
|
25
|
+
if (err.status !== undefined)
|
|
26
|
+
wrapped.status = err.status;
|
|
27
|
+
if (err.body !== undefined)
|
|
28
|
+
wrapped.body = err.body;
|
|
29
|
+
throw wrapped;
|
|
102
30
|
}
|
|
103
|
-
}, {
|
|
104
|
-
description: 'Ask your principal (the human) to connect a remote MCP server and grant you the listed tools. Opens a connection-consent agreement as an approvable card in the chat you pass — the human approves it there like any other agreement. On approval the server is connected (browser OAuth if needed) and you are granted the tools; use them via connection_proxy.',
|
|
105
31
|
});
|
|
106
32
|
export const CONNECTION_TOOLS = [
|
|
107
33
|
connectionProxyTool,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ToolDefinition } from '../../../tools/defineTool.js';
|
|
2
2
|
export declare const contextReadTool: ToolDefinition;
|
|
3
3
|
export declare const contextDelegateTool: ToolDefinition;
|
|
4
4
|
export declare const contextExpandReachTool: ToolDefinition;
|
|
5
5
|
export declare const contextDiscoverGrantableTool: ToolDefinition;
|
|
6
|
-
export declare const CONTEXT_TOOLS:
|
|
6
|
+
export declare const CONTEXT_TOOLS: ToolDefinition[];
|
|
@@ -1,139 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const agentId = ctx?.['agentId'];
|
|
12
|
-
if (!operatorKey)
|
|
13
|
-
throw new Error('operatorKey missing from tool context');
|
|
14
|
-
if (!agentId)
|
|
15
|
-
throw new Error('agentId missing from tool context');
|
|
16
|
-
return { operatorKey, agentId };
|
|
17
|
-
}
|
|
18
|
-
const CONTEXT_READ_TYPES = [
|
|
19
|
-
'messages',
|
|
20
|
-
'artifacts',
|
|
21
|
-
'agreements',
|
|
22
|
-
'tasks',
|
|
23
|
-
];
|
|
24
|
-
export const contextReadTool = defineTool('context_read', {
|
|
25
|
-
type: {
|
|
26
|
-
type: 'string',
|
|
27
|
-
required: true,
|
|
28
|
-
enum: [...CONTEXT_READ_TYPES],
|
|
29
|
-
description: 'Resource type to read from the scope',
|
|
30
|
-
},
|
|
31
|
-
via: {
|
|
32
|
-
type: 'string',
|
|
33
|
-
required: true,
|
|
34
|
-
description: 'Scope entry you hold, e.g. chat:<id>, agreement:<id>, task:<id>',
|
|
35
|
-
},
|
|
36
|
-
cursor: { type: 'string', description: 'Opaque cursor from a prior nextCursor to page' },
|
|
37
|
-
after: {
|
|
38
|
-
type: 'string',
|
|
39
|
-
description: 'ISO timestamp for forward-delta (messages/artifacts)',
|
|
40
|
-
},
|
|
41
|
-
direction: {
|
|
42
|
-
type: 'string',
|
|
43
|
-
enum: ['forward'],
|
|
44
|
-
description: 'Use "forward" with after for a message forward-delta',
|
|
45
|
-
},
|
|
46
|
-
limit: { type: 'number', description: 'Page size (server default when omitted)' },
|
|
47
|
-
state: { type: 'string', description: 'Task state filter (tasks only)' },
|
|
48
|
-
contextGrantId: {
|
|
49
|
-
type: 'string',
|
|
50
|
-
description: 'Pin a specific grant when you hold several over the same scope',
|
|
51
|
-
},
|
|
52
|
-
}, async (args, ctx) => {
|
|
53
|
-
const { operatorKey, agentId } = creds(ctx);
|
|
54
|
-
const type = args['type'];
|
|
55
|
-
if (!CONTEXT_READ_TYPES.includes(type)) {
|
|
56
|
-
throw new Error(`type must be one of ${CONTEXT_READ_TYPES.join(', ')}`);
|
|
57
|
-
}
|
|
58
|
-
const via = args['via'];
|
|
59
|
-
if (!via)
|
|
60
|
-
throw new Error('via is required');
|
|
61
|
-
const direction = args['direction'];
|
|
62
|
-
if (direction !== undefined && direction !== 'forward') {
|
|
63
|
-
throw new Error('direction must be "forward"');
|
|
64
|
-
}
|
|
65
|
-
return new ContextReadClient(operatorKey, agentId).read(type, {
|
|
66
|
-
via,
|
|
67
|
-
cursor: args['cursor'],
|
|
68
|
-
after: args['after'],
|
|
69
|
-
direction: direction,
|
|
70
|
-
limit: typeof args['limit'] === 'number' ? args['limit'] : undefined,
|
|
71
|
-
state: args['state'],
|
|
72
|
-
contextGrantId: args['contextGrantId'],
|
|
73
|
-
});
|
|
74
|
-
}, {
|
|
75
|
-
description: 'Read the contents of a scope you already hold a grant for: messages | artifacts | agreements | tasks. Use list_grants first to see which scopes your grants cover, then read through any of them. Cursored; all access is grant-fenced server-side.',
|
|
76
|
-
});
|
|
77
|
-
export const contextDelegateTool = defineTool('context_delegate', {
|
|
78
|
-
parentGrantId: { type: 'string', required: true },
|
|
79
|
-
holderId: { type: 'string', required: true },
|
|
80
|
-
scopeKind: { type: 'string', required: true },
|
|
81
|
-
scopeId: { type: 'string', required: true },
|
|
82
|
-
temporal: { type: 'string', required: true },
|
|
83
|
-
expiresAt: 'string',
|
|
84
|
-
watermarkAt: 'string',
|
|
85
|
-
}, async (args, ctx) => {
|
|
86
|
-
const temporal = args['temporal'];
|
|
87
|
-
if (temporal !== 'from-now' && temporal !== 'from-start') {
|
|
88
|
-
throw new Error('temporal must be from-now or from-start');
|
|
89
|
-
}
|
|
90
|
-
const scopeKind = args['scopeKind'];
|
|
91
|
-
if (scopeKind !== 'chat' && scopeKind !== 'agreement' && scopeKind !== 'org') {
|
|
92
|
-
throw new Error('scopeKind must be chat, agreement, or org');
|
|
93
|
-
}
|
|
94
|
-
const { operatorKey, agentId } = creds(ctx);
|
|
95
|
-
return new ContextGrantsClient(operatorKey, agentId).delegateGrant(args['parentGrantId'], {
|
|
96
|
-
holderId: args['holderId'],
|
|
97
|
-
scope: { kind: scopeKind, id: args['scopeId'] },
|
|
98
|
-
temporal,
|
|
99
|
-
expiresAt: args['expiresAt'] ?? undefined,
|
|
100
|
-
watermarkAt: args['watermarkAt'],
|
|
101
|
-
});
|
|
102
|
-
}, {
|
|
103
|
-
description: 'Delegate a narrower child context grant (tighter scope, shorter expiry, or from-now). Holder-only. Delegating a grant whose original owner is another party opens an approval request rather than minting immediately (status: pending_approval).',
|
|
104
|
-
});
|
|
105
|
-
export const contextExpandReachTool = defineTool('context_expand_reach', {
|
|
106
|
-
grantId: {
|
|
107
|
-
type: 'string',
|
|
108
|
-
required: true,
|
|
109
|
-
description: 'A grant you hold (grantId from list_grants) to expand',
|
|
110
|
-
},
|
|
111
|
-
}, async (args, ctx) => {
|
|
112
|
-
const { operatorKey, agentId } = creds(ctx);
|
|
113
|
-
const grantId = args['grantId'];
|
|
114
|
-
if (!grantId)
|
|
115
|
-
throw new Error('grantId is required');
|
|
116
|
-
return new ContextGrantsClient(operatorKey, agentId).getReach(grantId);
|
|
117
|
-
}, {
|
|
118
|
-
description: 'Expand a grant you hold into the chat/agreement ids inside its scope, so you can read through it. list_grants tells you that you hold e.g. org:acme or agreement:x; this returns the actual { chats, agreements } (ids + labels only, no content) that scope covers — feed an id to context_read (via=chat:<id> / agreement:<id>). Org scope is capped: truncatedChats/truncatedAgreements say how many were left off. Holder-only, grant-fenced.',
|
|
119
|
-
});
|
|
120
|
-
// ZIG-754 — the negative-space complement to the reach tools. list_grants /
|
|
121
|
-
// context_expand_reach answer "what CAN I read?"; this answers "what exists
|
|
122
|
-
// just outside my fence that I CAN'T read yet?" so the agent can flag missing
|
|
123
|
-
// context and make an informed widen request instead of silently
|
|
124
|
-
// under-delivering on partial context. The MCP surface has had this as
|
|
125
|
-
// ziggs_discover_grantable; this is its SDK/legibility complement, backed by
|
|
126
|
-
// the same ContextDiscoveryClient (one wire contract, no fork).
|
|
127
|
-
export const contextDiscoverGrantableTool = defineTool('context_discover_grantable', {}, async (_args, ctx) => {
|
|
128
|
-
const { operatorKey, agentId } = creds(ctx);
|
|
129
|
-
const items = await new ContextDiscoveryClient(operatorKey, agentId).discoverGrantable();
|
|
130
|
-
return { count: items.length, items };
|
|
131
|
-
}, {
|
|
132
|
-
description: 'See what context EXISTS in your orgs that you CANNOT read yet — the inverse of list_grants. Covers chats, agreements, and connections (type is one of "chat" | "agreement" | "connection"; connection labels are the provider name only). Returns labels only ({ type, label, scopeRef, orgId } per item), never content, member names, tokens, or money. Bounded to orgs you have an active agreement in, and excludes anything you already hold a grant for. Use it to notice you may be missing context, then either ask your human to grant a scopeRef, or (if you hold a broader grant) context_delegate using that scopeRef. Pair with list_grants (what you hold) and context_expand_reach (what a held grant covers).',
|
|
133
|
-
});
|
|
134
|
-
export const CONTEXT_TOOLS = [
|
|
135
|
-
contextReadTool,
|
|
136
|
-
contextDelegateTool,
|
|
137
|
-
contextExpandReachTool,
|
|
138
|
-
contextDiscoverGrantableTool,
|
|
139
|
-
];
|
|
1
|
+
import { CONTEXT_CAPABILITIES, contextReadCapability, contextDelegateCapability, contextExpandReachCapability, contextDiscoverGrantableCapability, } from '@ziggs-ai/api-client';
|
|
2
|
+
import { toolFromCapability, toolsFromCapabilities } from '../../../tools/capabilityAdapter.js';
|
|
3
|
+
// ZIG-869 / ZIG-775 / ZIG-956 — context grant tools ride the same api-client
|
|
4
|
+
// clients as ziggs-mcp; the whole definition (schema + handler) is now shared
|
|
5
|
+
// via the capability layer, so the two surfaces cannot fork.
|
|
6
|
+
export const contextReadTool = toolFromCapability(contextReadCapability);
|
|
7
|
+
export const contextDelegateTool = toolFromCapability(contextDelegateCapability);
|
|
8
|
+
export const contextExpandReachTool = toolFromCapability(contextExpandReachCapability);
|
|
9
|
+
export const contextDiscoverGrantableTool = toolFromCapability(contextDiscoverGrantableCapability);
|
|
10
|
+
export const CONTEXT_TOOLS = toolsFromCapabilities(CONTEXT_CAPABILITIES);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ToolDefinition } from '../../../tools/defineTool.js';
|
|
2
2
|
export declare const agentSearchTool: ToolDefinition;
|
|
3
3
|
export declare const agentGetTool: ToolDefinition;
|
|
4
4
|
export declare const DISCOVERY_TOOLS: ToolDefinition[];
|
|
@@ -1,25 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (!agentId)
|
|
9
|
-
throw new Error('agentId missing from tool context');
|
|
10
|
-
return new AgentSearchClient(operatorKey, agentId);
|
|
11
|
-
}
|
|
12
|
-
export const agentSearchTool = defineTool('agent_search', { query: { type: 'string', required: true }, limit: 'number' }, async (args, ctx) => {
|
|
13
|
-
if (!args['query'])
|
|
14
|
-
throw new Error('query is required');
|
|
15
|
-
const options = {};
|
|
16
|
-
if (typeof args['limit'] === 'number')
|
|
17
|
-
options.limit = args['limit'];
|
|
18
|
-
return clientFor(ctx).searchAgents(args['query'], options);
|
|
19
|
-
}, { description: 'Search for agents by capability, name, or description. Returns ranked results with relevance scores. Use before agreement_propose or agreement_subcontract to discover the right agent for a job.', isGenericFallback: true });
|
|
20
|
-
export const agentGetTool = defineTool('agent_get', { agentId: { type: 'string', required: true } }, async (args, ctx) => {
|
|
21
|
-
if (!args['agentId'])
|
|
22
|
-
throw new Error('agentId is required');
|
|
23
|
-
return clientFor(ctx).getAgentById(args['agentId']);
|
|
24
|
-
}, { description: 'Fetch the full profile of a specific agent by ID. Use to confirm capabilities and terms before proposing an agreement.' });
|
|
1
|
+
import { agentSearchCapability, agentGetCapability } from '@ziggs-ai/api-client';
|
|
2
|
+
import { toolFromCapability } from '../../../tools/capabilityAdapter.js';
|
|
3
|
+
// ZIG-956 — agent discovery is a shared capability definition (api-client),
|
|
4
|
+
// so search shaping (ZIG-664 zero-hit hint, reachability rows) is identical
|
|
5
|
+
// on both surfaces.
|
|
6
|
+
export const agentSearchTool = toolFromCapability(agentSearchCapability);
|
|
7
|
+
export const agentGetTool = toolFromCapability(agentGetCapability);
|
|
25
8
|
export const DISCOVERY_TOOLS = [agentSearchTool, agentGetTool];
|
|
@@ -1,81 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* per-rail listers server-side; this lifts that unification up to the tool layer
|
|
8
|
-
* so an agent no longer has to know three tool names — or, as in the 2026-07-20
|
|
9
|
-
* incident, tell its principal grant lookup doesn't exist because its config
|
|
10
|
-
* happened to omit the one rail's lister.
|
|
11
|
-
*/
|
|
12
|
-
function creds(ctx) {
|
|
13
|
-
const operatorKey = ctx?.['operatorKey'];
|
|
14
|
-
const agentId = ctx?.['agentId'];
|
|
15
|
-
if (!operatorKey)
|
|
16
|
-
throw new Error('operatorKey missing from tool context');
|
|
17
|
-
if (!agentId)
|
|
18
|
-
throw new Error('agentId missing from tool context');
|
|
19
|
-
return { operatorKey, agentId };
|
|
20
|
-
}
|
|
21
|
-
const SCOPE_KINDS = [
|
|
22
|
-
'chat',
|
|
23
|
-
'agreement',
|
|
24
|
-
'org',
|
|
25
|
-
'connection',
|
|
26
|
-
'wallet',
|
|
27
|
-
];
|
|
28
|
-
const HEALTHS = ['active', 'expired', 'revoked'];
|
|
29
|
-
function parseScopeKinds(raw) {
|
|
30
|
-
if (raw == null)
|
|
31
|
-
return undefined;
|
|
32
|
-
const list = Array.isArray(raw) ? raw : [raw];
|
|
33
|
-
const out = [];
|
|
34
|
-
for (const r of list) {
|
|
35
|
-
if (!SCOPE_KINDS.includes(r)) {
|
|
36
|
-
throw new Error(`scopeKind must be one of ${SCOPE_KINDS.join(', ')}`);
|
|
37
|
-
}
|
|
38
|
-
if (!out.includes(r))
|
|
39
|
-
out.push(r);
|
|
40
|
-
}
|
|
41
|
-
return out.length ? out : undefined;
|
|
42
|
-
}
|
|
43
|
-
export const listGrantsTool = defineTool('list_grants', {
|
|
44
|
-
scopeKind: {
|
|
45
|
-
type: 'array',
|
|
46
|
-
items: { type: 'string', enum: [...SCOPE_KINDS] },
|
|
47
|
-
description: 'Rail filter (repeatable): chat | agreement | org (context) | connection | wallet. Omit for every rail you can read.',
|
|
48
|
-
},
|
|
49
|
-
health: {
|
|
50
|
-
type: 'string',
|
|
51
|
-
enum: [...HEALTHS],
|
|
52
|
-
description: 'Grant health filter. Defaults to active (live grants only).',
|
|
53
|
-
},
|
|
54
|
-
cursor: { type: 'string', description: 'Opaque cursor from a prior nextCursor to page' },
|
|
55
|
-
limit: { type: 'number', description: 'Page size (server default when omitted)' },
|
|
56
|
-
}, async (args, ctx) => {
|
|
57
|
-
const { operatorKey, agentId } = creds(ctx);
|
|
58
|
-
const scopeKind = parseScopeKinds(args['scopeKind']);
|
|
59
|
-
const healthArg = args['health'];
|
|
60
|
-
if (healthArg !== undefined && !HEALTHS.includes(healthArg)) {
|
|
61
|
-
throw new Error(`health must be one of ${HEALTHS.join(', ')}`);
|
|
62
|
-
}
|
|
63
|
-
const { items, nextCursor } = await new GrantsClient(operatorKey, agentId).listGrants({
|
|
64
|
-
scopeKind,
|
|
65
|
-
// Reach = live grants only by default; pass health to see expired/revoked.
|
|
66
|
-
health: healthArg ?? 'active',
|
|
67
|
-
cursor: args['cursor'],
|
|
68
|
-
limit: typeof args['limit'] === 'number' ? args['limit'] : undefined,
|
|
69
|
-
});
|
|
70
|
-
const unreadable = unreadableGrantRails(operatorKey, scopeKind);
|
|
71
|
-
return {
|
|
72
|
-
count: items.length,
|
|
73
|
-
grants: items,
|
|
74
|
-
nextCursor,
|
|
75
|
-
...(unreadable && unreadable.length ? { unreadableRails: unreadable } : {}),
|
|
76
|
-
};
|
|
77
|
-
}, {
|
|
78
|
-
description: '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.',
|
|
79
|
-
isGenericFallback: true,
|
|
80
|
-
});
|
|
81
|
-
export const GRANTS_TOOLS = [listGrantsTool];
|
|
1
|
+
import { GRANTS_CAPABILITIES, listGrantsCapability } from '@ziggs-ai/api-client';
|
|
2
|
+
import { toolFromCapability, toolsFromCapabilities } from '../../../tools/capabilityAdapter.js';
|
|
3
|
+
// ZIG-893 / ZIG-956 — the single "what authority do I hold?" tool, defined
|
|
4
|
+
// once in api-client's shared capability layer.
|
|
5
|
+
export const listGrantsTool = toolFromCapability(listGrantsCapability);
|
|
6
|
+
export const GRANTS_TOOLS = toolsFromCapabilities(GRANTS_CAPABILITIES);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ToolDefinition } from '../../../tools/defineTool.js';
|
|
2
2
|
export declare const requestLinkTool: ToolDefinition;
|
|
3
3
|
export declare const createLinkInviteTool: ToolDefinition;
|
|
4
4
|
export declare const claimLinkInviteTool: ToolDefinition;
|
|
@@ -1,156 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
function creds(ctx) {
|
|
15
|
-
const operatorKey = ctx?.['operatorKey'];
|
|
16
|
-
const agentId = ctx?.['agentId'];
|
|
17
|
-
if (!operatorKey)
|
|
18
|
-
throw new Error('operatorKey missing from tool context');
|
|
19
|
-
if (!agentId)
|
|
20
|
-
throw new Error('agentId missing from tool context');
|
|
21
|
-
return { operatorKey, agentId };
|
|
22
|
-
}
|
|
23
|
-
function webAppOrigin() {
|
|
24
|
-
return (process.env.ZIGGS_WEB_URL?.trim() || 'https://ziggsai.com').replace(/\/$/, '');
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* ZIG-670 rule carried over from the MCP tools: link-shaped summaries, not raw
|
|
28
|
-
* agreement documents — the money block, approvals array, and Mongo internals
|
|
29
|
-
* are noise on a trust relationship.
|
|
30
|
-
*/
|
|
31
|
-
function linkSummary(a) {
|
|
32
|
-
return {
|
|
33
|
-
agreementId: a.agreementId,
|
|
34
|
-
status: a.status,
|
|
35
|
-
proposalStatus: a.proposalStatus,
|
|
36
|
-
parties: {
|
|
37
|
-
creatorAgent: a.parties?.creatorAgent ?? null,
|
|
38
|
-
providerAgent: a.parties?.providerAgent ?? null,
|
|
39
|
-
creator: a.parties?.creator ?? null,
|
|
40
|
-
proposedTo: a.parties?.proposedTo ?? null,
|
|
41
|
-
},
|
|
42
|
-
...(a.description ? { description: a.description } : {}),
|
|
43
|
-
createdAt: a.createdAt,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
const LINK_IS_REACH_ONLY = '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.';
|
|
47
|
-
export const requestLinkTool = defineTool('request_link', {
|
|
48
|
-
providerId: {
|
|
49
|
-
type: 'string',
|
|
50
|
-
required: true,
|
|
51
|
-
description: 'Bare agent id to link with (the target delegate). Use agent_search or a known delegate id — do not guess.',
|
|
52
|
-
},
|
|
53
|
-
message: {
|
|
54
|
-
type: 'string',
|
|
55
|
-
description: 'Optional note shown to the counterparty human on approval (agreement description)',
|
|
56
|
-
},
|
|
57
|
-
}, async (args, ctx) => {
|
|
58
|
-
const { agreement } = await createAgreement({
|
|
59
|
-
engagementKind: 'link',
|
|
60
|
-
providerId: args['providerId'],
|
|
61
|
-
description: args['message'],
|
|
62
|
-
}, creds(ctx));
|
|
63
|
-
return {
|
|
64
|
-
status: 'pending',
|
|
65
|
-
message: '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
|
-
description: '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.',
|
|
70
|
-
isAgreementCreation: true,
|
|
71
|
-
});
|
|
72
|
-
export const createLinkInviteTool = defineTool('create_link_invite', {
|
|
73
|
-
message: {
|
|
74
|
-
type: 'string',
|
|
75
|
-
description: 'Optional note shown to whoever opens the invite (agreement description)',
|
|
76
|
-
},
|
|
77
|
-
}, async (args, ctx) => {
|
|
78
|
-
const { agreement } = await createAgreement({ engagementKind: 'link', description: args['message'] }, creds(ctx));
|
|
79
|
-
return {
|
|
80
|
-
status: 'open',
|
|
81
|
-
inviteId: agreement.agreementId,
|
|
82
|
-
claimUrl: `${webAppOrigin()}/app/link-invites/${agreement.agreementId}`,
|
|
83
|
-
message: '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.',
|
|
84
|
-
agreement: linkSummary(agreement),
|
|
85
|
-
};
|
|
86
|
-
}, {
|
|
87
|
-
description: "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.",
|
|
88
|
-
isAgreementCreation: true,
|
|
89
|
-
});
|
|
90
|
-
export const claimLinkInviteTool = defineTool('claim_link_invite', {
|
|
91
|
-
agreementId: {
|
|
92
|
-
type: 'string',
|
|
93
|
-
required: true,
|
|
94
|
-
description: 'The invite id (agreementId) shared by the issuer',
|
|
95
|
-
},
|
|
96
|
-
}, async (args, ctx) => {
|
|
97
|
-
const { agreement } = await claimAgreement(args['agreementId'], creds(ctx));
|
|
98
|
-
return {
|
|
99
|
-
status: 'linked',
|
|
100
|
-
message: `Link invite claimed — you are now linked. ${LINK_IS_REACH_ONLY}`,
|
|
101
|
-
agreement: linkSummary(agreement),
|
|
102
|
-
};
|
|
103
|
-
}, {
|
|
104
|
-
description: '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
|
-
});
|
|
106
|
-
export const listLinksTool = defineTool('list_links', {
|
|
107
|
-
status: {
|
|
108
|
-
type: 'string',
|
|
109
|
-
enum: ['active', 'open', 'cancelled', 'all'],
|
|
110
|
-
description: 'active (default) = established links; open = pending proposals/invites awaiting approval or claim; cancelled = revoked; all = every link regardless of status',
|
|
111
|
-
},
|
|
112
|
-
}, async (args, ctx) => {
|
|
113
|
-
const status = args['status'] ?? 'active';
|
|
114
|
-
if (!['active', 'open', 'cancelled', 'all'].includes(status)) {
|
|
115
|
-
throw new Error('status must be one of active, open, cancelled, all');
|
|
116
|
-
}
|
|
117
|
-
const links = await listAgreements({
|
|
118
|
-
engagementKind: 'link',
|
|
119
|
-
...(status === 'all' ? {} : { status }),
|
|
120
|
-
}, creds(ctx));
|
|
121
|
-
const summaries = links.map(linkSummary);
|
|
122
|
-
const hasActive = links.some((a) => a.status === 'active');
|
|
123
|
-
return {
|
|
124
|
-
count: summaries.length,
|
|
125
|
-
status,
|
|
126
|
-
links: summaries,
|
|
127
|
-
...(hasActive ? { nextSteps: LINK_IS_REACH_ONLY } : {}),
|
|
128
|
-
};
|
|
129
|
-
}, {
|
|
130
|
-
description: '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.',
|
|
131
|
-
isGenericFallback: true,
|
|
132
|
-
});
|
|
133
|
-
export const revokeLinkTool = defineTool('revoke_link', {
|
|
134
|
-
agreementId: {
|
|
135
|
-
type: 'string',
|
|
136
|
-
required: true,
|
|
137
|
-
description: 'agreementId of the link agreement (from list_links)',
|
|
138
|
-
},
|
|
139
|
-
}, async (args, ctx) => {
|
|
140
|
-
const result = await revokeAgreement(args['agreementId'], creds(ctx));
|
|
141
|
-
return {
|
|
142
|
-
status: 'revoked',
|
|
143
|
-
message: 'Link revoked — unpublished cross-org reach to this peer is blocked again.',
|
|
144
|
-
agreementId: args['agreementId'],
|
|
145
|
-
agreement: result.agreement ? linkSummary(result.agreement) : null,
|
|
146
|
-
};
|
|
147
|
-
}, {
|
|
148
|
-
description: '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.',
|
|
149
|
-
});
|
|
150
|
-
export const LINK_TOOLS = [
|
|
151
|
-
requestLinkTool,
|
|
152
|
-
createLinkInviteTool,
|
|
153
|
-
claimLinkInviteTool,
|
|
154
|
-
listLinksTool,
|
|
155
|
-
revokeLinkTool,
|
|
156
|
-
];
|
|
1
|
+
import { LINK_CAPABILITIES, requestLinkCapability, createLinkInviteCapability, claimLinkInviteCapability, listLinksCapability, revokeLinkCapability, } from '@ziggs-ai/api-client';
|
|
2
|
+
import { toolFromCapability, toolsFromCapabilities } from '../../../tools/capabilityAdapter.js';
|
|
3
|
+
// ZIG-898 / ZIG-956 — links are agreements with engagementKind 'link':
|
|
4
|
+
// bilateral agent-to-agent trust that gives unpublished delegates cross-org
|
|
5
|
+
// reach. Defined once in api-client's shared capability layer (including the
|
|
6
|
+
// ZIG-670 linkSummary shaping); this file only adapts them onto the SDK.
|
|
7
|
+
export const requestLinkTool = toolFromCapability(requestLinkCapability);
|
|
8
|
+
export const createLinkInviteTool = toolFromCapability(createLinkInviteCapability);
|
|
9
|
+
export const claimLinkInviteTool = toolFromCapability(claimLinkInviteCapability);
|
|
10
|
+
export const listLinksTool = toolFromCapability(listLinksCapability);
|
|
11
|
+
export const revokeLinkTool = toolFromCapability(revokeLinkCapability);
|
|
12
|
+
export const LINK_TOOLS = toolsFromCapabilities(LINK_CAPABILITIES);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ToolDefinition } from '../../../tools/defineTool.js';
|
|
2
2
|
export declare const paymentBalanceTool: ToolDefinition;
|
|
3
3
|
export declare const paymentTransferTool: ToolDefinition;
|
|
4
4
|
export declare const paymentWaitForApprovalTool: ToolDefinition;
|
|
5
|
-
export declare const paymentResolveWalletTool: ToolDefinition;
|
|
6
5
|
export declare const paymentHoldTool: ToolDefinition;
|
|
7
6
|
export declare const paymentReleaseTool: ToolDefinition;
|
|
7
|
+
export declare const paymentResolveWalletTool: ToolDefinition;
|
|
8
8
|
export declare const paymentIssueGrantTool: ToolDefinition;
|
|
9
9
|
export declare const paymentAttenuateGrantTool: ToolDefinition;
|
|
10
10
|
export declare const paymentRevokeGrantTool: ToolDefinition;
|