@ziggs-ai/agent-sdk 0.2.1 → 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.
- package/dist/AgentHost.d.ts +9 -0
- package/dist/AgentHost.js +2 -0
- package/dist/adapters/McpAdapter.js +14 -13
- package/dist/agent/ClaudeSdkAgent.d.ts +5 -0
- package/dist/agent/ClaudeSdkAgent.js +12 -2
- package/dist/agent/claudeCognition.d.ts +7 -0
- package/dist/agent/claudeCognition.js +38 -7
- package/dist/agent/claudeSdkTools.js +17 -2
- package/dist/index.d.ts +2 -5
- package/dist/index.js +10 -4
- package/dist/server/tools/index.d.ts +7 -3
- package/dist/server/tools/index.js +13 -3
- 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/package.json +2 -2
- 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,124 +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
|
-
/**
|
|
33
|
-
* Scope descriptors for what this agent can reach (no content). GET
|
|
34
|
-
* /context/discovery was retired (ZIG-648); reach is now the agent's live
|
|
35
|
-
* context grants from the unified GET /grants, mapped back to the reach shape
|
|
36
|
-
* (temporal/watermark ride in caveats). Follows the cursor for completeness.
|
|
37
|
-
*/
|
|
38
|
-
async discover() {
|
|
39
|
-
this.requireActAsAgent('discover');
|
|
40
|
-
const out = [];
|
|
41
|
-
let cursor;
|
|
42
|
-
for (let page = 0; page < 50; page++) {
|
|
43
|
-
const q = new URLSearchParams();
|
|
44
|
-
for (const k of ['chat', 'agreement', 'org'])
|
|
45
|
-
q.append('scopeKind', k);
|
|
46
|
-
q.set('health', 'active');
|
|
47
|
-
if (cursor)
|
|
48
|
-
q.set('cursor', cursor);
|
|
49
|
-
const res = (await this._get(`/grants?${q.toString()}`));
|
|
50
|
-
const items = res['items'] || [];
|
|
51
|
-
for (const g of items) {
|
|
52
|
-
const caveats = g['caveats'] || [];
|
|
53
|
-
const caveat = (t) => caveats.find((c) => c.type === t)?.value;
|
|
54
|
-
const scope = g['scope'];
|
|
55
|
-
out.push({
|
|
56
|
-
grantId: g['grantId'],
|
|
57
|
-
scope: { kind: scope.kind, id: scope.id },
|
|
58
|
-
temporal: caveat('temporal') ?? 'from-now',
|
|
59
|
-
watermarkAt: caveat('watermark_at') ?? '',
|
|
60
|
-
expiresAt: g['expiresAt'] ?? null,
|
|
61
|
-
parentGrantId: g['parentGrantId'] ?? null,
|
|
62
|
-
createdAt: g['createdAt'],
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
const next = res['nextCursor'];
|
|
66
|
-
if (!next)
|
|
67
|
-
break;
|
|
68
|
-
cursor = next;
|
|
69
|
-
}
|
|
70
|
-
return out;
|
|
71
|
-
}
|
|
72
|
-
/** Holder delegates a narrower child grant. */
|
|
73
|
-
async delegate(params) {
|
|
74
|
-
this.requireActAsAgent('delegate');
|
|
75
|
-
if (!params.parentGrantId)
|
|
76
|
-
throw new Error('delegate: parentGrantId is required');
|
|
77
|
-
if (!params.holderId)
|
|
78
|
-
throw new Error('delegate: holderId is required');
|
|
79
|
-
if (!params.scope?.kind || !params.scope?.id) {
|
|
80
|
-
throw new Error('delegate: scope { kind, id } is required');
|
|
81
|
-
}
|
|
82
|
-
return this._post(`/context/grants/${encodeURIComponent(params.parentGrantId)}/delegate`, {
|
|
83
|
-
holderId: params.holderId,
|
|
84
|
-
scope: params.scope,
|
|
85
|
-
temporal: params.temporal,
|
|
86
|
-
expiresAt: params.expiresAt,
|
|
87
|
-
watermarkAt: params.watermarkAt,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
requireActAsAgent(method) {
|
|
91
|
-
if (!this.actAsAgentId) {
|
|
92
|
-
throw new Error(`${method}: actAsAgentId is required — context grant calls must impersonate the grant holder agent`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
_buildHeaders(extra = {}) {
|
|
96
|
-
const h = { Authorization: `Bearer ${this.operatorKey}`, ...extra };
|
|
97
|
-
if (this.actAsAgentId)
|
|
98
|
-
h['X-Agent-Id'] = this.actAsAgentId;
|
|
99
|
-
return h;
|
|
100
|
-
}
|
|
101
|
-
async _request(method, path, body) {
|
|
102
|
-
const init = {
|
|
103
|
-
method,
|
|
104
|
-
headers: this._buildHeaders(body !== undefined ? { 'content-type': 'application/json' } : {}),
|
|
105
|
-
};
|
|
106
|
-
if (body !== undefined)
|
|
107
|
-
init.body = JSON.stringify(body);
|
|
108
|
-
const res = await fetch(`${this.baseUrl}${path}`, init);
|
|
109
|
-
const text = await res.text();
|
|
110
|
-
if (!res.ok) {
|
|
111
|
-
const err = new Error(parseError(text, `${method} ${path} failed (${res.status})`));
|
|
112
|
-
err.status = res.status;
|
|
113
|
-
err.body = text;
|
|
114
|
-
throw err;
|
|
115
|
-
}
|
|
116
|
-
return text ? JSON.parse(text) : {};
|
|
117
|
-
}
|
|
118
|
-
_get(path) {
|
|
119
|
-
return this._request('GET', path, undefined);
|
|
120
|
-
}
|
|
121
|
-
_post(path, body) {
|
|
122
|
-
return this._request('POST', path, body);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
@@ -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
|
-
}
|