@aithos/sdk 0.1.0-alpha.41 → 0.1.0-alpha.42
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/src/apps.d.ts +69 -0
- package/dist/src/apps.js +157 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/package.json +10 -11
package/dist/src/apps.d.ts
CHANGED
|
@@ -151,5 +151,74 @@ export declare class AppsNamespace {
|
|
|
151
151
|
* just with the app-credits pack id family.
|
|
152
152
|
*/
|
|
153
153
|
createAppTopupSession(args: CreateAppTopupSessionArgs): Promise<CreateAppTopupSessionResult>;
|
|
154
|
+
/**
|
|
155
|
+
* Build, sign, and PUBLISH a SponsorshipMandate to the authority's
|
|
156
|
+
* `aithos-app-sponsorships` table via `aithos.sponsorship_create`.
|
|
157
|
+
*
|
|
158
|
+
* Combines local signing (see {@link createSponsorshipMandate}) with the
|
|
159
|
+
* server upload step. After this resolves, the sponsorship is active —
|
|
160
|
+
* the next `sdk.compute.invokeBedrock` call targeting `args.audience.appDid`
|
|
161
|
+
* may be sponsored (subject to caps).
|
|
162
|
+
*
|
|
163
|
+
* Requires that the calling owner is the registered `owner_did` of
|
|
164
|
+
* `args.audience.appDid` in `aithos-auth-apps`; otherwise the server
|
|
165
|
+
* rejects with `-32042` "not the owner".
|
|
166
|
+
*/
|
|
167
|
+
publishSponsorship(args: CreateSponsorshipMandateArgs): Promise<{
|
|
168
|
+
mandate: SignedSponsorshipMandate;
|
|
169
|
+
sponsorshipId: string;
|
|
170
|
+
mandateHash: string;
|
|
171
|
+
status: "active";
|
|
172
|
+
createdAt: number;
|
|
173
|
+
}>;
|
|
174
|
+
/**
|
|
175
|
+
* Read the active sponsorship for an app. Open endpoint (no envelope
|
|
176
|
+
* required): the mandate is publicly signed and resolvable anyway.
|
|
177
|
+
*
|
|
178
|
+
* Returns `{ exists: false }` when no row exists for the app.
|
|
179
|
+
*/
|
|
180
|
+
getSponsorship(args: {
|
|
181
|
+
appDid: string;
|
|
182
|
+
signal?: AbortSignal;
|
|
183
|
+
}): Promise<{
|
|
184
|
+
exists: false;
|
|
185
|
+
} | {
|
|
186
|
+
exists: true;
|
|
187
|
+
sponsorshipId: string;
|
|
188
|
+
mandate: SignedSponsorshipMandate;
|
|
189
|
+
mandateHash: string;
|
|
190
|
+
status: "active" | "paused" | "depleted" | "expired" | "revoked";
|
|
191
|
+
poolConsumedLifetime: number;
|
|
192
|
+
createdAt: number;
|
|
193
|
+
lastUpdatedAt: number;
|
|
194
|
+
}>;
|
|
195
|
+
/**
|
|
196
|
+
* Revoke a published sponsorship by `app_did` + `sponsorship_id`. The
|
|
197
|
+
* row is marked `status: "revoked"` server-side; the routing cache is
|
|
198
|
+
* invalidated so the next compute call falls back to the user wallet.
|
|
199
|
+
*/
|
|
200
|
+
revokeSponsorship(args: {
|
|
201
|
+
appDid: string;
|
|
202
|
+
sponsorshipId: string;
|
|
203
|
+
reason: string;
|
|
204
|
+
signal?: AbortSignal;
|
|
205
|
+
}): Promise<{
|
|
206
|
+
status: "revoked";
|
|
207
|
+
}>;
|
|
208
|
+
/**
|
|
209
|
+
* Read the app's wallet balance (= the sponsor pool). Requires owner
|
|
210
|
+
* signature.
|
|
211
|
+
*/
|
|
212
|
+
getAppWalletBalance(args: {
|
|
213
|
+
appDid: string;
|
|
214
|
+
signal?: AbortSignal;
|
|
215
|
+
}): Promise<{
|
|
216
|
+
appDid: string;
|
|
217
|
+
exists: boolean;
|
|
218
|
+
balance: number;
|
|
219
|
+
balancePurchase: number;
|
|
220
|
+
balanceGrant: number;
|
|
221
|
+
dailySpent: number;
|
|
222
|
+
}>;
|
|
154
223
|
}
|
|
155
224
|
//# sourceMappingURL=apps.d.ts.map
|
package/dist/src/apps.js
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
// a CloudFront-fronted read endpoint or direct DDB access. We'll add it
|
|
26
26
|
// in V0.2 once the sponsorship-api Lambda exists; for now, devs check
|
|
27
27
|
// their sponsorship via the AWS Console.
|
|
28
|
-
import { base64url, sign } from "@aithos/protocol-client";
|
|
29
|
-
import { walletTopupCheckoutUrl } from "./endpoints.js";
|
|
28
|
+
import { base64url, buildSignedEnvelope, sign } from "@aithos/protocol-client";
|
|
29
|
+
import { computeInvokeUrl, walletTopupCheckoutUrl } from "./endpoints.js";
|
|
30
30
|
import { ownerKeyPair } from "./internal/protocol-client-bridge.js";
|
|
31
31
|
import { AithosSDKError } from "./types.js";
|
|
32
32
|
/* -------------------------------------------------------------------------- */
|
|
@@ -191,6 +191,161 @@ export class AppsNamespace {
|
|
|
191
191
|
}
|
|
192
192
|
return { checkoutUrl: ok.checkout_url, sessionId: ok.session_id };
|
|
193
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Build, sign, and PUBLISH a SponsorshipMandate to the authority's
|
|
196
|
+
* `aithos-app-sponsorships` table via `aithos.sponsorship_create`.
|
|
197
|
+
*
|
|
198
|
+
* Combines local signing (see {@link createSponsorshipMandate}) with the
|
|
199
|
+
* server upload step. After this resolves, the sponsorship is active —
|
|
200
|
+
* the next `sdk.compute.invokeBedrock` call targeting `args.audience.appDid`
|
|
201
|
+
* may be sponsored (subject to caps).
|
|
202
|
+
*
|
|
203
|
+
* Requires that the calling owner is the registered `owner_did` of
|
|
204
|
+
* `args.audience.appDid` in `aithos-auth-apps`; otherwise the server
|
|
205
|
+
* rejects with `-32042` "not the owner".
|
|
206
|
+
*/
|
|
207
|
+
async publishSponsorship(args) {
|
|
208
|
+
const mandate = await this.createSponsorshipMandate(args);
|
|
209
|
+
const result = await this.#signedRpc({
|
|
210
|
+
method: "aithos.sponsorship_create",
|
|
211
|
+
params: { mandate },
|
|
212
|
+
});
|
|
213
|
+
return {
|
|
214
|
+
mandate,
|
|
215
|
+
sponsorshipId: result.sponsorship_id,
|
|
216
|
+
mandateHash: result.mandate_hash,
|
|
217
|
+
status: result.status,
|
|
218
|
+
createdAt: result.created_at,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Read the active sponsorship for an app. Open endpoint (no envelope
|
|
223
|
+
* required): the mandate is publicly signed and resolvable anyway.
|
|
224
|
+
*
|
|
225
|
+
* Returns `{ exists: false }` when no row exists for the app.
|
|
226
|
+
*/
|
|
227
|
+
async getSponsorship(args) {
|
|
228
|
+
const { endpoints, fetch: fetchImpl } = this.#deps;
|
|
229
|
+
const url = computeInvokeUrl(endpoints);
|
|
230
|
+
let res;
|
|
231
|
+
try {
|
|
232
|
+
res = await fetchImpl(url, {
|
|
233
|
+
method: "POST",
|
|
234
|
+
headers: { "content-type": "application/json" },
|
|
235
|
+
body: JSON.stringify({
|
|
236
|
+
jsonrpc: "2.0",
|
|
237
|
+
id: "aithos.sponsorship_get",
|
|
238
|
+
method: "aithos.sponsorship_get",
|
|
239
|
+
params: { app_did: args.appDid },
|
|
240
|
+
}),
|
|
241
|
+
...(args.signal ? { signal: args.signal } : {}),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
catch (e) {
|
|
245
|
+
throw new AithosSDKError("network", e.message);
|
|
246
|
+
}
|
|
247
|
+
const body = (await res.json());
|
|
248
|
+
if (body.error) {
|
|
249
|
+
throw new AithosSDKError(String(body.error.code), body.error.message);
|
|
250
|
+
}
|
|
251
|
+
const r = body.result ?? {};
|
|
252
|
+
if (r.exists === false || !r.exists) {
|
|
253
|
+
return { exists: false };
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
exists: true,
|
|
257
|
+
sponsorshipId: r.sponsorship_id,
|
|
258
|
+
mandate: r.mandate,
|
|
259
|
+
mandateHash: r.mandate_hash,
|
|
260
|
+
status: r.status,
|
|
261
|
+
poolConsumedLifetime: r.pool_consumed_lifetime ?? 0,
|
|
262
|
+
createdAt: r.created_at ?? 0,
|
|
263
|
+
lastUpdatedAt: r.last_updated_at ?? 0,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Revoke a published sponsorship by `app_did` + `sponsorship_id`. The
|
|
268
|
+
* row is marked `status: "revoked"` server-side; the routing cache is
|
|
269
|
+
* invalidated so the next compute call falls back to the user wallet.
|
|
270
|
+
*/
|
|
271
|
+
async revokeSponsorship(args) {
|
|
272
|
+
const result = await this.#signedRpc({
|
|
273
|
+
method: "aithos.sponsorship_revoke",
|
|
274
|
+
params: {
|
|
275
|
+
app_did: args.appDid,
|
|
276
|
+
sponsorship_id: args.sponsorshipId,
|
|
277
|
+
reason: args.reason,
|
|
278
|
+
},
|
|
279
|
+
...(args.signal ? { signal: args.signal } : {}),
|
|
280
|
+
});
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Read the app's wallet balance (= the sponsor pool). Requires owner
|
|
285
|
+
* signature.
|
|
286
|
+
*/
|
|
287
|
+
async getAppWalletBalance(args) {
|
|
288
|
+
const result = await this.#signedRpc({
|
|
289
|
+
method: "aithos.app_wallet_get_balance",
|
|
290
|
+
params: { app_did: args.appDid },
|
|
291
|
+
...(args.signal ? { signal: args.signal } : {}),
|
|
292
|
+
});
|
|
293
|
+
return {
|
|
294
|
+
appDid: result.app_did,
|
|
295
|
+
exists: result.exists,
|
|
296
|
+
balance: result.balance,
|
|
297
|
+
balancePurchase: result.balance_purchase,
|
|
298
|
+
balanceGrant: result.balance_grant,
|
|
299
|
+
dailySpent: result.daily_spent,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Internal: sign an envelope with the calling owner's `#public` sphere
|
|
304
|
+
* and POST a JSON-RPC request to the compute proxy. Used by the
|
|
305
|
+
* sponsorship CRUD methods above. Mirrors `ComputeNamespace.#signAndPost`.
|
|
306
|
+
*/
|
|
307
|
+
async #signedRpc(opts) {
|
|
308
|
+
const { endpoints, fetch: fetchImpl } = this.#deps;
|
|
309
|
+
const owner = this.#requireOwner();
|
|
310
|
+
const publicKp = ownerKeyPair(owner, "public");
|
|
311
|
+
const url = computeInvokeUrl(endpoints);
|
|
312
|
+
const envelope = buildSignedEnvelope({
|
|
313
|
+
iss: owner.did,
|
|
314
|
+
aud: url,
|
|
315
|
+
method: opts.method,
|
|
316
|
+
verificationMethod: `${owner.did}#public`,
|
|
317
|
+
params: opts.params,
|
|
318
|
+
signer: publicKp,
|
|
319
|
+
});
|
|
320
|
+
let res;
|
|
321
|
+
try {
|
|
322
|
+
res = await fetchImpl(url, {
|
|
323
|
+
method: "POST",
|
|
324
|
+
headers: { "content-type": "application/json" },
|
|
325
|
+
body: JSON.stringify({
|
|
326
|
+
jsonrpc: "2.0",
|
|
327
|
+
id: opts.method,
|
|
328
|
+
method: opts.method,
|
|
329
|
+
params: { ...opts.params, _envelope: envelope },
|
|
330
|
+
}),
|
|
331
|
+
...(opts.signal ? { signal: opts.signal } : {}),
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
catch (e) {
|
|
335
|
+
throw new AithosSDKError("network", e.message);
|
|
336
|
+
}
|
|
337
|
+
if (!res.ok) {
|
|
338
|
+
throw new AithosSDKError("http", `HTTP ${res.status} ${res.statusText}`, { status: res.status });
|
|
339
|
+
}
|
|
340
|
+
const body = (await res.json());
|
|
341
|
+
if (body.error) {
|
|
342
|
+
throw new AithosSDKError(String(body.error.code), body.error.message, body.error.data ? { data: body.error.data } : undefined);
|
|
343
|
+
}
|
|
344
|
+
if (body.result === undefined) {
|
|
345
|
+
throw new AithosSDKError("empty", `empty result for ${opts.method}`);
|
|
346
|
+
}
|
|
347
|
+
return body.result;
|
|
348
|
+
}
|
|
194
349
|
#requireOwner() {
|
|
195
350
|
const owner = this.#deps.auth._getOwnerSigners();
|
|
196
351
|
if (!owner || owner.destroyed) {
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// Public types specific to the SDK (`AithosSDKConfig`, `AithosSDKError`)
|
|
18
18
|
// are exported from here. Endpoint config (`AithosSdkEndpoints`,
|
|
19
19
|
// `DEFAULT_SDK_ENDPOINTS`) likewise.
|
|
20
|
-
export const VERSION = "0.1.0-alpha.
|
|
20
|
+
export const VERSION = "0.1.0-alpha.42";
|
|
21
21
|
export { AithosSDK } from "./sdk.js";
|
|
22
22
|
export { AithosSDKError } from "./types.js";
|
|
23
23
|
// Re-export protocol-client's JSON-RPC error type so consumers can
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aithos/sdk",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.42",
|
|
4
4
|
"description": "Aithos SDK — high-level TypeScript developer kit for building agentic apps on the Aithos protocol. Wraps @aithos/protocol-client and exposes the Aithos compute proxy and wallet (Stripe top-up) endpoints.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aithos",
|
|
@@ -43,15 +43,6 @@
|
|
|
43
43
|
"README.md",
|
|
44
44
|
"LICENSE"
|
|
45
45
|
],
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "tsc",
|
|
48
|
-
"build:test": "tsc -p tsconfig.test.json",
|
|
49
|
-
"check-types": "tsc --noEmit && tsc -p tsconfig.test.json --noEmit",
|
|
50
|
-
"test": "npm run clean && npm run build && npm run build:test && cd dist && node --test",
|
|
51
|
-
"test:watch": "cd dist && node --test --watch",
|
|
52
|
-
"clean": "rm -rf dist",
|
|
53
|
-
"prepublishOnly": "npm run clean && npm run build && npm test"
|
|
54
|
-
},
|
|
55
46
|
"engines": {
|
|
56
47
|
"node": ">=20"
|
|
57
48
|
},
|
|
@@ -77,5 +68,13 @@
|
|
|
77
68
|
"publishConfig": {
|
|
78
69
|
"access": "public",
|
|
79
70
|
"tag": "alpha"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "tsc",
|
|
74
|
+
"build:test": "tsc -p tsconfig.test.json",
|
|
75
|
+
"check-types": "tsc --noEmit && tsc -p tsconfig.test.json --noEmit",
|
|
76
|
+
"test": "npm run clean && npm run build && npm run build:test && cd dist && node --test",
|
|
77
|
+
"test:watch": "cd dist && node --test --watch",
|
|
78
|
+
"clean": "rm -rf dist"
|
|
80
79
|
}
|
|
81
|
-
}
|
|
80
|
+
}
|