@ziggs-ai/agent-sdk 0.2.1 → 0.3.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/README.md +1 -1
- package/dist/AgentHost.d.ts +21 -20
- package/dist/AgentHost.js +60 -136
- package/dist/adapters/McpAdapter.js +14 -13
- package/dist/agent/Agent.js +4 -0
- package/dist/agent/ClaudeSdkAgent.d.ts +5 -0
- package/dist/agent/ClaudeSdkAgent.js +25 -6
- package/dist/agent/claudeCognition.d.ts +7 -0
- package/dist/agent/claudeCognition.js +38 -7
- package/dist/agent/claudeSdkProtocol.d.ts +8 -7
- package/dist/agent/claudeSdkProtocol.js +8 -7
- package/dist/agent/claudeSdkTools.d.ts +4 -2
- package/dist/agent/claudeSdkTools.js +26 -6
- package/dist/agent/toolManagerToSdkMcp.js +1 -0
- package/dist/index.d.ts +5 -9
- package/dist/index.js +12 -6
- package/dist/ingress/normalizeIncoming.d.ts +17 -3
- package/dist/ingress/normalizeIncoming.js +11 -26
- package/dist/runtime/AgentMachine.d.ts +5 -2
- package/dist/runtime/AgentMachine.js +8 -2
- package/dist/runtime/runMechanical.d.ts +3 -1
- package/dist/runtime/runMechanical.js +2 -2
- package/dist/runtime/runTurn.d.ts +3 -1
- package/dist/runtime/runTurn.js +25 -7
- package/dist/runtime/wakeWriteKeys.d.ts +25 -0
- package/dist/runtime/wakeWriteKeys.js +134 -0
- package/dist/server/ConnectionPool.d.ts +7 -4
- package/dist/server/ConnectionPool.js +11 -14
- package/dist/server/ZiggsEffectHandler.js +17 -12
- package/dist/server/inboxLoop.d.ts +50 -0
- package/dist/server/{InboxCatchUp.js → inboxLoop.js} +63 -52
- package/dist/server/runLauncher.js +1 -1
- package/dist/server/tasks/TaskService.d.ts +2 -1
- package/dist/server/tasks/TaskService.js +5 -2
- package/dist/server/tools/index.d.ts +7 -3
- package/dist/server/tools/index.js +13 -3
- package/dist/server/tools/tier1/protocolRunner.d.ts +2 -1
- package/dist/server/tools/tier1/protocolRunner.js +43 -9
- package/dist/server/tools/tier1/protocolTools.js +1 -1
- package/dist/server/tools/tier2/artifactTools.d.ts +3 -0
- package/dist/server/tools/tier2/artifactTools.js +82 -0
- package/dist/server/tools/tier2/chatTools.d.ts +3 -0
- package/dist/server/tools/tier2/chatTools.js +37 -0
- package/dist/server/tools/tier2/connectionTools.d.ts +1 -0
- package/dist/server/tools/tier2/connectionTools.js +52 -5
- package/dist/server/tools/tier2/contextTools.d.ts +4 -2
- package/dist/server/tools/tier2/contextTools.js +105 -12
- package/dist/server/tools/tier2/grantsTools.d.ts +3 -0
- package/dist/server/tools/tier2/grantsTools.js +81 -0
- package/dist/server/tools/tier2/linkTools.d.ts +7 -0
- package/dist/server/tools/tier2/linkTools.js +156 -0
- package/dist/server/tools/tier2/paymentTools.d.ts +0 -1
- package/dist/server/tools/tier2/paymentTools.js +9 -13
- package/dist/types.d.ts +40 -0
- package/package.json +2 -2
- package/dist/server/InboxCatchUp.d.ts +0 -24
- package/dist/server/ziggsconnect/ZiggsConnectClient.d.ts +0 -35
- package/dist/server/ziggsconnect/ZiggsConnectClient.js +0 -95
- package/dist/server/ziggscontext/ZiggsContextClient.d.ts +0 -53
- package/dist/server/ziggscontext/ZiggsContextClient.js +0 -124
- package/dist/server/ziggspay/ZiggsPayClient.d.ts +0 -82
- package/dist/server/ziggspay/ZiggsPayClient.js +0 -203
|
@@ -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,203 +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
|
-
// GET /payments/grants was retired (ZIG-648); wallet grants the acting agent
|
|
97
|
-
// holds are listed via the unified GET /grants. Follow the cursor so a holder
|
|
98
|
-
// with more than one page isn't truncated; live grants only.
|
|
99
|
-
const all = [];
|
|
100
|
-
let cursor;
|
|
101
|
-
for (let page = 0; page < 50; page++) {
|
|
102
|
-
const q = new URLSearchParams({ scopeKind: 'wallet', health: 'active' });
|
|
103
|
-
if (cursor)
|
|
104
|
-
q.set('cursor', cursor);
|
|
105
|
-
const res = (await this._get(`/grants?${q.toString()}`));
|
|
106
|
-
all.push(...(res['items'] || []));
|
|
107
|
-
const next = res['nextCursor'];
|
|
108
|
-
if (!next)
|
|
109
|
-
break;
|
|
110
|
-
cursor = next;
|
|
111
|
-
}
|
|
112
|
-
return all;
|
|
113
|
-
}
|
|
114
|
-
async createTopUpIntent({ amount, description, currency } = {}) {
|
|
115
|
-
return this._post('/payments/onramp/intent', { amount, description, currency });
|
|
116
|
-
}
|
|
117
|
-
async confirmMockIntent(intentId) {
|
|
118
|
-
return this._post(`/payments/onramp/mock-confirm/${intentId}`, {});
|
|
119
|
-
}
|
|
120
|
-
async faucet({ amount, description = 'Faucet', idempotencyKey } = {}) {
|
|
121
|
-
return this._post('/payments/wallet/fund', { amount, idempotencyKey: idempotencyKey || randomIdempotencyKey('faucet'), description });
|
|
122
|
-
}
|
|
123
|
-
async approvals({ status = 'pending' } = {}) {
|
|
124
|
-
const res = await this._get(`/payments/approvals?status=${encodeURIComponent(status)}`);
|
|
125
|
-
return res['approvals'] || [];
|
|
126
|
-
}
|
|
127
|
-
async getApproval(approvalId) {
|
|
128
|
-
if (!approvalId)
|
|
129
|
-
throw new Error('getApproval: approvalId is required');
|
|
130
|
-
try {
|
|
131
|
-
const res = await this._get(`/payments/approvals/${approvalId}`);
|
|
132
|
-
return res?.['approval'] || null;
|
|
133
|
-
}
|
|
134
|
-
catch (err) {
|
|
135
|
-
if (err.status === 404)
|
|
136
|
-
return null;
|
|
137
|
-
throw err;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
async decide(approvalId, decision, note = '') {
|
|
141
|
-
return this._post(`/payments/approvals/${approvalId}/decide`, { decision, note });
|
|
142
|
-
}
|
|
143
|
-
async waitForApproval(approvalId, opts = {}) {
|
|
144
|
-
const pollMs = Math.max(500, opts.pollMs ?? 3_000);
|
|
145
|
-
const timeoutMs = Math.max(pollMs, opts.timeoutMs ?? 120_000);
|
|
146
|
-
const signal = opts.signal;
|
|
147
|
-
const deadline = Date.now() + timeoutMs;
|
|
148
|
-
const sleep = (ms) => new Promise((resolve, reject) => {
|
|
149
|
-
const timer = setTimeout(resolve, ms);
|
|
150
|
-
if (signal) {
|
|
151
|
-
if (signal.aborted) {
|
|
152
|
-
clearTimeout(timer);
|
|
153
|
-
reject(new Error('aborted'));
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
signal.addEventListener('abort', () => { clearTimeout(timer); reject(new Error('aborted')); }, { once: true });
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
while (true) {
|
|
160
|
-
if (signal?.aborted)
|
|
161
|
-
throw new Error('aborted');
|
|
162
|
-
const approval = await this.getApproval(approvalId);
|
|
163
|
-
if (!approval)
|
|
164
|
-
return { status: 'gone' };
|
|
165
|
-
const s = approval['status'];
|
|
166
|
-
if (s === 'executed')
|
|
167
|
-
return { status: 'executed', approval, transactionId: approval['executedTransactionId'] || null };
|
|
168
|
-
if (s === 'rejected')
|
|
169
|
-
return { status: 'rejected', approval };
|
|
170
|
-
if (s === 'expired')
|
|
171
|
-
return { status: 'expired', approval };
|
|
172
|
-
const remaining = deadline - Date.now();
|
|
173
|
-
if (remaining <= 0)
|
|
174
|
-
return { status: 'timeout', approval };
|
|
175
|
-
await sleep(Math.min(pollMs, remaining));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
_buildHeaders(extra = {}) {
|
|
179
|
-
const h = { Authorization: `Bearer ${this.operatorKey}`, ...extra };
|
|
180
|
-
if (this.actAsAgentId)
|
|
181
|
-
h['X-Agent-Id'] = this.actAsAgentId;
|
|
182
|
-
return h;
|
|
183
|
-
}
|
|
184
|
-
async _request(method, path, body) {
|
|
185
|
-
const init = { method, headers: this._buildHeaders(body !== undefined ? { 'content-type': 'application/json' } : {}) };
|
|
186
|
-
if (body !== undefined)
|
|
187
|
-
init.body = JSON.stringify(body);
|
|
188
|
-
const response = await fetch(`${this.baseUrl}${path}`, init);
|
|
189
|
-
const text = await response.text();
|
|
190
|
-
if (!response.ok) {
|
|
191
|
-
const err = new Error(parseError(text, `HTTP ${response.status}`));
|
|
192
|
-
err.status = response.status;
|
|
193
|
-
err.body = text;
|
|
194
|
-
throw err;
|
|
195
|
-
}
|
|
196
|
-
return text ? JSON.parse(text) : null;
|
|
197
|
-
}
|
|
198
|
-
_get(path) { return this._request('GET', path, undefined); }
|
|
199
|
-
_post(path, body) { return this._request('POST', path, body ?? {}); }
|
|
200
|
-
}
|
|
201
|
-
export function createZiggsPayClient(opts) {
|
|
202
|
-
return new ZiggsPayClient(opts);
|
|
203
|
-
}
|