@ziggs-ai/agent-sdk 0.2.0 → 0.2.1
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContextReadClient,
|
|
1
|
+
import { ContextReadClient, GrantsClient, InboxClient, getChatsForAgreement, getAgreementStatus, } from '@ziggs-ai/api-client';
|
|
2
2
|
import { runtimeLog } from '../shared/runtimeLog.js';
|
|
3
3
|
const READ_PAGE = 100;
|
|
4
4
|
function log(label, msg) {
|
|
@@ -47,7 +47,7 @@ function rowToMetadata(row, chatId) {
|
|
|
47
47
|
text: row.text,
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
async function chatIdsForScope(scope, creds, baseUrl,
|
|
50
|
+
async function chatIdsForScope(scope, creds, baseUrl, grants) {
|
|
51
51
|
const { kind, id } = scope.scope;
|
|
52
52
|
switch (kind) {
|
|
53
53
|
case 'chat':
|
|
@@ -57,12 +57,13 @@ async function chatIdsForScope(scope, creds, baseUrl, discovery) {
|
|
|
57
57
|
return [...new Set(links.map((l) => l.chatId).filter(Boolean))];
|
|
58
58
|
}
|
|
59
59
|
case 'org': {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
// All pages of live chat grants — an org-scope catch-up must not miss
|
|
61
|
+
// chats hidden behind pagination (GET /grants defaults to one page).
|
|
62
|
+
const items = await grants.listAllGrants({
|
|
63
|
+
scopeKind: 'chat',
|
|
64
|
+
health: 'active',
|
|
65
|
+
});
|
|
66
|
+
return [...new Set(items.map((g) => g.scope.id))];
|
|
66
67
|
}
|
|
67
68
|
default:
|
|
68
69
|
return [];
|
|
@@ -120,7 +121,7 @@ export async function runInboxCatchUp(deps) {
|
|
|
120
121
|
const label = deps.label ?? 'InboxCatchUp';
|
|
121
122
|
const inbox = new InboxClient(deps.creds.operatorKey, deps.creds.agentId, deps.baseUrl);
|
|
122
123
|
const reader = new ContextReadClient(deps.creds.operatorKey, deps.creds.agentId, deps.baseUrl);
|
|
123
|
-
const
|
|
124
|
+
const grants = new GrantsClient(deps.creds.operatorKey, deps.creds.agentId, deps.baseUrl);
|
|
124
125
|
const envelope = await inbox.getInbox();
|
|
125
126
|
const countCap = envelope.countCap;
|
|
126
127
|
let messagesDelivered = 0;
|
|
@@ -154,7 +155,7 @@ export async function runInboxCatchUp(deps) {
|
|
|
154
155
|
log(label, `scope agreement:${scope.scope.id} terminal — acked, not re-delivered`);
|
|
155
156
|
continue;
|
|
156
157
|
}
|
|
157
|
-
const chatIds = await chatIdsForScope(scope, deps.creds, deps.baseUrl,
|
|
158
|
+
const chatIds = await chatIdsForScope(scope, deps.creds, deps.baseUrl, grants);
|
|
158
159
|
if (!chatIds.length && (scope.newMessages > 0 || scope.newArtifacts > 0)) {
|
|
159
160
|
warn(label, `no chat ids for scope ${scope.scope.kind}:${scope.scope.id} (${scope.newMessages} msgs)`);
|
|
160
161
|
}
|
|
@@ -36,7 +36,12 @@ export declare class ZiggsContextClient {
|
|
|
36
36
|
private actAsAgentId;
|
|
37
37
|
private baseUrl;
|
|
38
38
|
constructor({ operatorKey, actAsAgentId, baseUrl }: ZiggsContextClientOptions);
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Scope descriptors for what this agent can reach (no content). GET
|
|
41
|
+
* /context/discovery was retired (ZIG-648); reach is now the agent's live
|
|
42
|
+
* context grants from the unified GET /grants, mapped back to the reach shape
|
|
43
|
+
* (temporal/watermark ride in caveats). Follows the cursor for completeness.
|
|
44
|
+
*/
|
|
40
45
|
discover(): Promise<ContextReachDescriptor[]>;
|
|
41
46
|
/** Holder delegates a narrower child grant. */
|
|
42
47
|
delegate(params: DelegateContextGrantParams): Promise<unknown>;
|
|
@@ -29,11 +29,45 @@ export class ZiggsContextClient {
|
|
|
29
29
|
this.actAsAgentId = actAsAgentId || null;
|
|
30
30
|
this.baseUrl = baseUrl || getDefaultBaseUrl();
|
|
31
31
|
}
|
|
32
|
-
/**
|
|
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
|
+
*/
|
|
33
38
|
async discover() {
|
|
34
39
|
this.requireActAsAgent('discover');
|
|
35
|
-
const
|
|
36
|
-
|
|
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;
|
|
37
71
|
}
|
|
38
72
|
/** Holder delegates a narrower child grant. */
|
|
39
73
|
async delegate(params) {
|
|
@@ -93,8 +93,23 @@ export class ZiggsPayClient {
|
|
|
93
93
|
return this._request('DELETE', `/payments/grants/${grantId}`, undefined);
|
|
94
94
|
}
|
|
95
95
|
async listGrants() {
|
|
96
|
-
|
|
97
|
-
|
|
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;
|
|
98
113
|
}
|
|
99
114
|
async createTopUpIntent({ amount, description, currency } = {}) {
|
|
100
115
|
return this._post('/payments/onramp/intent', { amount, description, currency });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ziggs-ai/agent-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Agent framework SDK for building autonomous agents on the Ziggs platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@anthropic-ai/claude-agent-sdk": "^0.3.204",
|
|
27
27
|
"@anthropic-ai/sdk": "^0.110.0",
|
|
28
28
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
29
|
-
"@ziggs-ai/api-client": "^0.1.
|
|
29
|
+
"@ziggs-ai/api-client": "^0.1.29",
|
|
30
30
|
"ajv": "^8.17.1",
|
|
31
31
|
"dotenv": "^17.2.3",
|
|
32
32
|
"openai": "^4.0.0",
|