@ziggs-ai/agent-sdk 0.2.0 → 0.2.2

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 (34) hide show
  1. package/dist/AgentHost.d.ts +9 -0
  2. package/dist/AgentHost.js +2 -0
  3. package/dist/adapters/McpAdapter.js +14 -13
  4. package/dist/agent/ClaudeSdkAgent.d.ts +5 -0
  5. package/dist/agent/ClaudeSdkAgent.js +12 -2
  6. package/dist/agent/claudeCognition.d.ts +7 -0
  7. package/dist/agent/claudeCognition.js +38 -7
  8. package/dist/agent/claudeSdkTools.js +17 -2
  9. package/dist/index.d.ts +2 -5
  10. package/dist/index.js +10 -4
  11. package/dist/server/InboxCatchUp.js +11 -10
  12. package/dist/server/tools/index.d.ts +7 -3
  13. package/dist/server/tools/index.js +13 -3
  14. package/dist/server/tools/tier2/artifactTools.d.ts +3 -0
  15. package/dist/server/tools/tier2/artifactTools.js +82 -0
  16. package/dist/server/tools/tier2/chatTools.d.ts +3 -0
  17. package/dist/server/tools/tier2/chatTools.js +37 -0
  18. package/dist/server/tools/tier2/connectionTools.d.ts +1 -0
  19. package/dist/server/tools/tier2/connectionTools.js +52 -5
  20. package/dist/server/tools/tier2/contextTools.d.ts +4 -2
  21. package/dist/server/tools/tier2/contextTools.js +105 -12
  22. package/dist/server/tools/tier2/grantsTools.d.ts +3 -0
  23. package/dist/server/tools/tier2/grantsTools.js +81 -0
  24. package/dist/server/tools/tier2/linkTools.d.ts +7 -0
  25. package/dist/server/tools/tier2/linkTools.js +156 -0
  26. package/dist/server/tools/tier2/paymentTools.d.ts +0 -1
  27. package/dist/server/tools/tier2/paymentTools.js +9 -13
  28. package/package.json +2 -2
  29. package/dist/server/ziggsconnect/ZiggsConnectClient.d.ts +0 -35
  30. package/dist/server/ziggsconnect/ZiggsConnectClient.js +0 -95
  31. package/dist/server/ziggscontext/ZiggsContextClient.d.ts +0 -48
  32. package/dist/server/ziggscontext/ZiggsContextClient.js +0 -90
  33. package/dist/server/ziggspay/ZiggsPayClient.d.ts +0 -82
  34. package/dist/server/ziggspay/ZiggsPayClient.js +0 -188
@@ -1,90 +0,0 @@
1
- import 'dotenv/config';
2
- function getDefaultBaseUrl() {
3
- return process.env.BACKEND_URL || process.env.ZIGGS_BACKEND_URL || 'http://localhost:3000';
4
- }
5
- function parseError(text, fallback) {
6
- if (!text)
7
- return fallback;
8
- try {
9
- const parsed = JSON.parse(text);
10
- return parsed['message'] || parsed['error'] || text;
11
- }
12
- catch {
13
- return text;
14
- }
15
- }
16
- /**
17
- * HTTP client for context grants (ZIG-413).
18
- * Presentation model (signed bytes vs grant id) is intentionally not baked in here.
19
- */
20
- export class ZiggsContextClient {
21
- operatorKey;
22
- actAsAgentId;
23
- baseUrl;
24
- constructor({ operatorKey, actAsAgentId, baseUrl }) {
25
- if (!operatorKey || typeof operatorKey !== 'string') {
26
- throw new Error('ZiggsContextClient requires an operatorKey');
27
- }
28
- this.operatorKey = operatorKey;
29
- this.actAsAgentId = actAsAgentId || null;
30
- this.baseUrl = baseUrl || getDefaultBaseUrl();
31
- }
32
- /** ZIG-412: scope descriptors for what this agent can reach (no content). */
33
- async discover() {
34
- this.requireActAsAgent('discover');
35
- const res = (await this._get('/context/discovery'));
36
- return res['reach'] || [];
37
- }
38
- /** Holder delegates a narrower child grant. */
39
- async delegate(params) {
40
- this.requireActAsAgent('delegate');
41
- if (!params.parentGrantId)
42
- throw new Error('delegate: parentGrantId is required');
43
- if (!params.holderId)
44
- throw new Error('delegate: holderId is required');
45
- if (!params.scope?.kind || !params.scope?.id) {
46
- throw new Error('delegate: scope { kind, id } is required');
47
- }
48
- return this._post(`/context/grants/${encodeURIComponent(params.parentGrantId)}/delegate`, {
49
- holderId: params.holderId,
50
- scope: params.scope,
51
- temporal: params.temporal,
52
- expiresAt: params.expiresAt,
53
- watermarkAt: params.watermarkAt,
54
- });
55
- }
56
- requireActAsAgent(method) {
57
- if (!this.actAsAgentId) {
58
- throw new Error(`${method}: actAsAgentId is required — context grant calls must impersonate the grant holder agent`);
59
- }
60
- }
61
- _buildHeaders(extra = {}) {
62
- const h = { Authorization: `Bearer ${this.operatorKey}`, ...extra };
63
- if (this.actAsAgentId)
64
- h['X-Agent-Id'] = this.actAsAgentId;
65
- return h;
66
- }
67
- async _request(method, path, body) {
68
- const init = {
69
- method,
70
- headers: this._buildHeaders(body !== undefined ? { 'content-type': 'application/json' } : {}),
71
- };
72
- if (body !== undefined)
73
- init.body = JSON.stringify(body);
74
- const res = await fetch(`${this.baseUrl}${path}`, init);
75
- const text = await res.text();
76
- if (!res.ok) {
77
- const err = new Error(parseError(text, `${method} ${path} failed (${res.status})`));
78
- err.status = res.status;
79
- err.body = text;
80
- throw err;
81
- }
82
- return text ? JSON.parse(text) : {};
83
- }
84
- _get(path) {
85
- return this._request('GET', path, undefined);
86
- }
87
- _post(path, body) {
88
- return this._request('POST', path, body);
89
- }
90
- }
@@ -1,82 +0,0 @@
1
- import 'dotenv/config';
2
- export interface ZiggsPayClientOptions {
3
- operatorKey: string;
4
- actAsAgentId?: string;
5
- baseUrl?: string;
6
- }
7
- export declare class ZiggsPayClient {
8
- private operatorKey;
9
- private actAsAgentId;
10
- private baseUrl;
11
- constructor({ operatorKey, actAsAgentId, baseUrl }: ZiggsPayClientOptions);
12
- balance(): Promise<{
13
- walletId: string | null;
14
- currency: string;
15
- balance: number;
16
- availableBalance: number;
17
- }>;
18
- resolve({ userId, agentId }?: {
19
- userId?: string;
20
- agentId?: string;
21
- }): Promise<unknown>;
22
- transfer({ to, amount, idempotencyKey, description, paymentGrantId }: {
23
- to: string;
24
- amount: number;
25
- idempotencyKey?: string;
26
- description?: string;
27
- paymentGrantId?: string;
28
- }): Promise<unknown>;
29
- hold({ amount, idempotencyKey, description }: {
30
- amount: number;
31
- idempotencyKey?: string;
32
- description?: string;
33
- }): Promise<unknown>;
34
- release({ holdId, action, toWalletId, idempotencyKey }: {
35
- holdId: string;
36
- action?: string;
37
- toWalletId?: string;
38
- idempotencyKey?: string;
39
- }): Promise<unknown>;
40
- history(params?: {
41
- limit?: number;
42
- offset?: number;
43
- type?: string;
44
- }): Promise<unknown>;
45
- issueGrant({ holderId, caveats }: {
46
- holderId: string;
47
- caveats?: unknown;
48
- }): Promise<unknown>;
49
- attenuateGrant({ grantId, holderId, caveats }: {
50
- grantId: string;
51
- holderId: string;
52
- caveats?: unknown;
53
- }): Promise<unknown>;
54
- revokeGrant(grantId: string): Promise<unknown>;
55
- listGrants(): Promise<unknown[]>;
56
- createTopUpIntent({ amount, description, currency }?: {
57
- amount?: number;
58
- description?: string;
59
- currency?: string;
60
- }): Promise<unknown>;
61
- confirmMockIntent(intentId: string): Promise<unknown>;
62
- faucet({ amount, description, idempotencyKey }?: {
63
- amount?: number;
64
- description?: string;
65
- idempotencyKey?: string;
66
- }): Promise<unknown>;
67
- approvals({ status }?: {
68
- status?: string;
69
- }): Promise<unknown[]>;
70
- getApproval(approvalId: string): Promise<unknown | null>;
71
- decide(approvalId: string, decision: string, note?: string): Promise<unknown>;
72
- waitForApproval(approvalId: string, opts?: {
73
- pollMs?: number;
74
- timeoutMs?: number;
75
- signal?: AbortSignal;
76
- }): Promise<unknown>;
77
- private _buildHeaders;
78
- private _request;
79
- private _get;
80
- private _post;
81
- }
82
- export declare function createZiggsPayClient(opts: ZiggsPayClientOptions): ZiggsPayClient;
@@ -1,188 +0,0 @@
1
- import 'dotenv/config';
2
- function getDefaultBaseUrl() {
3
- return process.env.BACKEND_URL || process.env.ZIGGS_BACKEND_URL || 'http://localhost:3000';
4
- }
5
- function randomIdempotencyKey(prefix = 'op') {
6
- return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
7
- }
8
- function parseError(text, fallback) {
9
- if (!text)
10
- return fallback;
11
- try {
12
- const parsed = JSON.parse(text);
13
- return parsed['error'] || parsed['message'] || text;
14
- }
15
- catch {
16
- return text;
17
- }
18
- }
19
- export class ZiggsPayClient {
20
- operatorKey;
21
- actAsAgentId;
22
- baseUrl;
23
- constructor({ operatorKey, actAsAgentId, baseUrl }) {
24
- if (!operatorKey || typeof operatorKey !== 'string')
25
- throw new Error('ZiggsPayClient requires an operatorKey');
26
- this.operatorKey = operatorKey;
27
- this.actAsAgentId = actAsAgentId || null;
28
- this.baseUrl = baseUrl || getDefaultBaseUrl();
29
- }
30
- async balance() {
31
- const w = await this._get('/payments/wallet');
32
- const wallet = w['wallet'];
33
- return { walletId: wallet?.['walletId'] || null, currency: wallet?.['currency'] || 'pez', balance: w['balance'] ?? 0, availableBalance: w['availableBalance'] ?? 0 };
34
- }
35
- async resolve({ userId, agentId } = {}) {
36
- if (!userId && !agentId)
37
- throw new Error('resolve: provide userId or agentId');
38
- const params = new URLSearchParams();
39
- if (userId)
40
- params.set('userId', userId);
41
- if (agentId)
42
- params.set('agentId', agentId);
43
- const res = await this._get(`/payments/wallets/resolve?${params}`);
44
- return res['wallet'] || null;
45
- }
46
- async transfer({ to, amount, idempotencyKey, description, paymentGrantId }) {
47
- if (!to)
48
- throw new Error('transfer: `to` is required');
49
- if (!(Number.isInteger(amount) && amount > 0))
50
- throw new Error('transfer: `amount` must be a positive integer (cents)');
51
- if (this.actAsAgentId && !paymentGrantId)
52
- throw new Error('transfer: paymentGrantId is required for agent-impersonated transfers. The wallet owner must have issued a payment grant to this agentId.');
53
- let toWalletId = to;
54
- if (!to.startsWith('wal_')) {
55
- const w = await this.resolve(to.startsWith('agent_') ? { agentId: to } : { userId: to });
56
- if (!w?.['walletId'])
57
- throw new Error(`transfer: could not resolve wallet for "${to}"`);
58
- toWalletId = w['walletId'];
59
- }
60
- const result = await this._post('/payments/transfer', { toWalletId, amount, idempotencyKey: idempotencyKey || randomIdempotencyKey('xfer'), description, paymentGrantId });
61
- if (result?.['status'] === 'approval_required') {
62
- const approval = result['approval'] || {};
63
- return { status: 'approval_required', approvalId: approval['approvalId'] || null, expiresAt: approval['expiresAt'] || null, reason: approval['reason'] || 'Amount exceeds auto-approve threshold', toWalletId, amount };
64
- }
65
- const tx = result?.['transaction'];
66
- return { status: 'transferred', transactionId: tx?.['transactionId'] || null, toWalletId, amount };
67
- }
68
- async hold({ amount, idempotencyKey, description }) {
69
- if (!(Number.isInteger(amount) && amount > 0))
70
- throw new Error('hold: `amount` must be a positive integer (cents)');
71
- return this._post('/payments/hold', { amount, idempotencyKey: idempotencyKey || randomIdempotencyKey('hold'), description });
72
- }
73
- async release({ holdId, action = 'complete', toWalletId, idempotencyKey }) {
74
- return this._post(`/payments/release/${holdId}`, { idempotencyKey: idempotencyKey || randomIdempotencyKey('rel'), action, toWalletId });
75
- }
76
- async history(params = {}) {
77
- const q = new URLSearchParams();
78
- if (params.limit != null)
79
- q.set('limit', String(params.limit));
80
- if (params.offset != null)
81
- q.set('offset', String(params.offset));
82
- if (params.type)
83
- q.set('type', params.type);
84
- return this._get('/payments/history' + (q.toString() ? `?${q}` : ''));
85
- }
86
- async issueGrant({ holderId, caveats }) {
87
- return this._post('/payments/grants', { holderId, caveats });
88
- }
89
- async attenuateGrant({ grantId, holderId, caveats }) {
90
- return this._post(`/payments/grants/${grantId}/attenuate`, { holderId, caveats });
91
- }
92
- async revokeGrant(grantId) {
93
- return this._request('DELETE', `/payments/grants/${grantId}`, undefined);
94
- }
95
- async listGrants() {
96
- const res = await this._get('/payments/grants');
97
- return res['grants'] || [];
98
- }
99
- async createTopUpIntent({ amount, description, currency } = {}) {
100
- return this._post('/payments/onramp/intent', { amount, description, currency });
101
- }
102
- async confirmMockIntent(intentId) {
103
- return this._post(`/payments/onramp/mock-confirm/${intentId}`, {});
104
- }
105
- async faucet({ amount, description = 'Faucet', idempotencyKey } = {}) {
106
- return this._post('/payments/wallet/fund', { amount, idempotencyKey: idempotencyKey || randomIdempotencyKey('faucet'), description });
107
- }
108
- async approvals({ status = 'pending' } = {}) {
109
- const res = await this._get(`/payments/approvals?status=${encodeURIComponent(status)}`);
110
- return res['approvals'] || [];
111
- }
112
- async getApproval(approvalId) {
113
- if (!approvalId)
114
- throw new Error('getApproval: approvalId is required');
115
- try {
116
- const res = await this._get(`/payments/approvals/${approvalId}`);
117
- return res?.['approval'] || null;
118
- }
119
- catch (err) {
120
- if (err.status === 404)
121
- return null;
122
- throw err;
123
- }
124
- }
125
- async decide(approvalId, decision, note = '') {
126
- return this._post(`/payments/approvals/${approvalId}/decide`, { decision, note });
127
- }
128
- async waitForApproval(approvalId, opts = {}) {
129
- const pollMs = Math.max(500, opts.pollMs ?? 3_000);
130
- const timeoutMs = Math.max(pollMs, opts.timeoutMs ?? 120_000);
131
- const signal = opts.signal;
132
- const deadline = Date.now() + timeoutMs;
133
- const sleep = (ms) => new Promise((resolve, reject) => {
134
- const timer = setTimeout(resolve, ms);
135
- if (signal) {
136
- if (signal.aborted) {
137
- clearTimeout(timer);
138
- reject(new Error('aborted'));
139
- return;
140
- }
141
- signal.addEventListener('abort', () => { clearTimeout(timer); reject(new Error('aborted')); }, { once: true });
142
- }
143
- });
144
- while (true) {
145
- if (signal?.aborted)
146
- throw new Error('aborted');
147
- const approval = await this.getApproval(approvalId);
148
- if (!approval)
149
- return { status: 'gone' };
150
- const s = approval['status'];
151
- if (s === 'executed')
152
- return { status: 'executed', approval, transactionId: approval['executedTransactionId'] || null };
153
- if (s === 'rejected')
154
- return { status: 'rejected', approval };
155
- if (s === 'expired')
156
- return { status: 'expired', approval };
157
- const remaining = deadline - Date.now();
158
- if (remaining <= 0)
159
- return { status: 'timeout', approval };
160
- await sleep(Math.min(pollMs, remaining));
161
- }
162
- }
163
- _buildHeaders(extra = {}) {
164
- const h = { Authorization: `Bearer ${this.operatorKey}`, ...extra };
165
- if (this.actAsAgentId)
166
- h['X-Agent-Id'] = this.actAsAgentId;
167
- return h;
168
- }
169
- async _request(method, path, body) {
170
- const init = { method, headers: this._buildHeaders(body !== undefined ? { 'content-type': 'application/json' } : {}) };
171
- if (body !== undefined)
172
- init.body = JSON.stringify(body);
173
- const response = await fetch(`${this.baseUrl}${path}`, init);
174
- const text = await response.text();
175
- if (!response.ok) {
176
- const err = new Error(parseError(text, `HTTP ${response.status}`));
177
- err.status = response.status;
178
- err.body = text;
179
- throw err;
180
- }
181
- return text ? JSON.parse(text) : null;
182
- }
183
- _get(path) { return this._request('GET', path, undefined); }
184
- _post(path, body) { return this._request('POST', path, body ?? {}); }
185
- }
186
- export function createZiggsPayClient(opts) {
187
- return new ZiggsPayClient(opts);
188
- }