@hsuite/smart-engines-sdk 3.13.0 → 3.14.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/CHANGELOG.md +14 -0
- package/dist/index.d.ts +78 -5
- package/dist/index.js +161 -11
- package/dist/index.js.map +1 -1
- package/dist/nestjs/index.d.ts +61 -1
- package/dist/nestjs/index.js +126 -2
- package/dist/nestjs/index.js.map +1 -1
- package/package.json +1 -1
package/dist/nestjs/index.d.ts
CHANGED
|
@@ -1634,6 +1634,7 @@ export interface ClusterInfo {
|
|
|
1634
1634
|
}
|
|
1635
1635
|
export type HttpCallOptions = {
|
|
1636
1636
|
customerToken?: string;
|
|
1637
|
+
onBehalfOf?: string;
|
|
1637
1638
|
headers?: Record<string, string>;
|
|
1638
1639
|
};
|
|
1639
1640
|
export type HttpClient = {
|
|
@@ -1644,6 +1645,11 @@ export type HttpClient = {
|
|
|
1644
1645
|
delete<T = any>(path: string, opts?: HttpCallOptions): Promise<T>;
|
|
1645
1646
|
getText(path: string, opts?: HttpCallOptions): Promise<string>;
|
|
1646
1647
|
getBinary(path: string, opts?: HttpCallOptions): Promise<Uint8Array>;
|
|
1648
|
+
getBinaryWithMeta(path: string, opts?: HttpCallOptions): Promise<{
|
|
1649
|
+
bytes: Uint8Array;
|
|
1650
|
+
contentType?: string;
|
|
1651
|
+
filename?: string;
|
|
1652
|
+
}>;
|
|
1647
1653
|
upload<T = any>(path: string, file: Blob | Buffer, filename: string, metadata?: Record<string, string>, fieldName?: string, opts?: HttpCallOptions): Promise<T>;
|
|
1648
1654
|
setAuthToken(token: string | undefined): void;
|
|
1649
1655
|
getAuthToken(): string | undefined;
|
|
@@ -3371,6 +3377,29 @@ export type AgentInfo = {
|
|
|
3371
3377
|
owner: string;
|
|
3372
3378
|
createdAt: string;
|
|
3373
3379
|
lastActiveAt?: string;
|
|
3380
|
+
agentWallet?: string;
|
|
3381
|
+
treasuryAccount?: string;
|
|
3382
|
+
entityId?: string;
|
|
3383
|
+
};
|
|
3384
|
+
export type AgentCertification = {
|
|
3385
|
+
agentId: string;
|
|
3386
|
+
entityId?: string;
|
|
3387
|
+
ownerWallet?: string;
|
|
3388
|
+
status?: string;
|
|
3389
|
+
agentWallet?: string;
|
|
3390
|
+
treasuryAccount?: string;
|
|
3391
|
+
primaryChain?: string;
|
|
3392
|
+
rulesHash?: string;
|
|
3393
|
+
ruleRef?: string;
|
|
3394
|
+
blsGroupPublicKey?: string;
|
|
3395
|
+
stateHistoryTopicId?: string;
|
|
3396
|
+
recentEvents: Array<{
|
|
3397
|
+
agentId: string;
|
|
3398
|
+
type: string;
|
|
3399
|
+
payload: Record<string, unknown>;
|
|
3400
|
+
timestamp: string;
|
|
3401
|
+
}>;
|
|
3402
|
+
recentTxIds: string[];
|
|
3374
3403
|
};
|
|
3375
3404
|
export type AgentEvent = {
|
|
3376
3405
|
eventId: string;
|
|
@@ -3423,6 +3452,14 @@ export type AgentExecuteResponse = {
|
|
|
3423
3452
|
export type AgentPreparedTransactionResponse = PreparedTransactionResponse & {
|
|
3424
3453
|
success: true;
|
|
3425
3454
|
};
|
|
3455
|
+
export type AgentPendingApprovalResponse = {
|
|
3456
|
+
success: true;
|
|
3457
|
+
pendingOpId: string;
|
|
3458
|
+
agentId: string;
|
|
3459
|
+
action: string;
|
|
3460
|
+
status: "awaiting_approval";
|
|
3461
|
+
description: string;
|
|
3462
|
+
};
|
|
3426
3463
|
declare class AgentsClient {
|
|
3427
3464
|
private readonly http;
|
|
3428
3465
|
constructor(http: HttpClient);
|
|
@@ -3432,7 +3469,7 @@ declare class AgentsClient {
|
|
|
3432
3469
|
agents: AgentInfo[];
|
|
3433
3470
|
total: number;
|
|
3434
3471
|
}>;
|
|
3435
|
-
fund(agentId: string, request: AgentFundRequest, opts?: HttpCallOptions): Promise<AgentPreparedTransactionResponse>;
|
|
3472
|
+
fund(agentId: string, request: AgentFundRequest, opts?: HttpCallOptions): Promise<AgentPreparedTransactionResponse | AgentPendingApprovalResponse>;
|
|
3436
3473
|
trade(agentId: string, request: AgentTradeRequest, opts?: HttpCallOptions): Promise<AgentPreparedTransactionResponse>;
|
|
3437
3474
|
withdraw(agentId: string, request: AgentWithdrawRequest, opts?: HttpCallOptions): Promise<AgentPreparedTransactionResponse>;
|
|
3438
3475
|
execute(agentId: string, request: AgentExecuteRequest, opts?: HttpCallOptions): Promise<AgentExecuteResponse & {
|
|
@@ -3450,6 +3487,7 @@ declare class AgentsClient {
|
|
|
3450
3487
|
success: boolean;
|
|
3451
3488
|
status: string;
|
|
3452
3489
|
}>;
|
|
3490
|
+
certification(agentId: string, opts?: HttpCallOptions): Promise<AgentCertification>;
|
|
3453
3491
|
updateRules(agentId: string, rules: Partial<AgentRules>, opts?: HttpCallOptions): Promise<AgentInfo>;
|
|
3454
3492
|
getEvents(agentId: string, opts?: HttpCallOptions): Promise<{
|
|
3455
3493
|
events: AgentEvent[];
|
|
@@ -3668,6 +3706,11 @@ export type BaasFunctionInfo = {
|
|
|
3668
3706
|
lastInvokedAt?: string;
|
|
3669
3707
|
invocationCount: number;
|
|
3670
3708
|
};
|
|
3709
|
+
export type BaasFunctionCode = {
|
|
3710
|
+
functionId: string;
|
|
3711
|
+
code: string | null;
|
|
3712
|
+
codeHash?: string;
|
|
3713
|
+
};
|
|
3671
3714
|
export type BaasFunctionLog = {
|
|
3672
3715
|
timestamp: string;
|
|
3673
3716
|
level: "debug" | "info" | "warn" | "error";
|
|
@@ -4840,6 +4883,11 @@ declare class StorageClient {
|
|
|
4840
4883
|
constructor(http: HttpClient, getAppId: () => string);
|
|
4841
4884
|
upload(file: Blob | Buffer, filename: string, metadata?: Record<string, string>, opts?: HttpCallOptions): Promise<BaasUploadResult>;
|
|
4842
4885
|
download(cid: string, opts?: HttpCallOptions): Promise<Uint8Array>;
|
|
4886
|
+
downloadWithMeta(cid: string, opts?: HttpCallOptions): Promise<{
|
|
4887
|
+
bytes: Uint8Array;
|
|
4888
|
+
contentType?: string;
|
|
4889
|
+
filename?: string;
|
|
4890
|
+
}>;
|
|
4843
4891
|
getMetadata(cid: string, opts?: HttpCallOptions): Promise<BaasFileMetadata>;
|
|
4844
4892
|
delete(cid: string, opts?: HttpCallOptions): Promise<{
|
|
4845
4893
|
success: boolean;
|
|
@@ -4870,6 +4918,7 @@ declare class FunctionsClient {
|
|
|
4870
4918
|
total: number;
|
|
4871
4919
|
}>;
|
|
4872
4920
|
get(functionId: string, opts?: HttpCallOptions): Promise<BaasFunctionInfo>;
|
|
4921
|
+
getCode(functionId: string, opts?: HttpCallOptions): Promise<BaasFunctionCode>;
|
|
4873
4922
|
update(functionId: string, updates: Partial<BaasFunctionDeployRequest>, opts?: HttpCallOptions): Promise<BaasFunctionInfo>;
|
|
4874
4923
|
delete(functionId: string, opts?: HttpCallOptions): Promise<{
|
|
4875
4924
|
success: boolean;
|
|
@@ -12375,6 +12424,9 @@ export type CreateAgentRequest = {
|
|
|
12375
12424
|
ruleRef: RuleRef;
|
|
12376
12425
|
name: string;
|
|
12377
12426
|
agentType?: string;
|
|
12427
|
+
securityMode?: EntitySecurityMode;
|
|
12428
|
+
payerAccountId?: string;
|
|
12429
|
+
fundWith?: FundWith;
|
|
12378
12430
|
};
|
|
12379
12431
|
export type EntityCreationResult = {
|
|
12380
12432
|
entityId: string;
|
|
@@ -12458,6 +12510,14 @@ export declare class EntitiesClient {
|
|
|
12458
12510
|
}): Promise<EntityCreationResult>;
|
|
12459
12511
|
createTopic(req: CreateTopicRequest): Promise<EntityCreationResult>;
|
|
12460
12512
|
createAgent(req: CreateAgentRequest): Promise<EntityCreationResult>;
|
|
12513
|
+
prepareCreateAgent(req: Omit<CreateAgentRequest, "fundWith">): Promise<PreparedEntityCreation>;
|
|
12514
|
+
executeCreateAgent(req: {
|
|
12515
|
+
entityId: string;
|
|
12516
|
+
chain: ChainType;
|
|
12517
|
+
securityMode?: EntitySecurityMode;
|
|
12518
|
+
signedFundingBlob?: string;
|
|
12519
|
+
createTxId?: string;
|
|
12520
|
+
}): Promise<EntityCreationResult>;
|
|
12461
12521
|
launchpad(req: LaunchpadEntityRequest): Promise<LaunchpadEntityResult>;
|
|
12462
12522
|
get(entityId: string): Promise<EntityInfo>;
|
|
12463
12523
|
listByOwner(filter?: ListEntitiesFilter): Promise<ListEntitiesResponse>;
|
package/dist/nestjs/index.js
CHANGED
|
@@ -1149,6 +1149,13 @@ var SdkHttpError = class extends Error {
|
|
|
1149
1149
|
}
|
|
1150
1150
|
statusCode;
|
|
1151
1151
|
details;
|
|
1152
|
+
/**
|
|
1153
|
+
* True for transient failures worth retrying: a 5xx, a 429 (rate limit), a 408
|
|
1154
|
+
* (timeout), or a 0 (network/abort). Deterministic 4xx client errors are not.
|
|
1155
|
+
*/
|
|
1156
|
+
get isRetryable() {
|
|
1157
|
+
return this.statusCode === 0 || this.statusCode === 408 || this.statusCode === 429 || this.statusCode >= 500;
|
|
1158
|
+
}
|
|
1152
1159
|
};
|
|
1153
1160
|
function createHttpClient(config) {
|
|
1154
1161
|
const timeout = config.timeout ?? 3e4;
|
|
@@ -1166,6 +1173,10 @@ function createHttpClient(config) {
|
|
|
1166
1173
|
if (opts?.customerToken) {
|
|
1167
1174
|
headers["X-Customer-Session-Token"] = opts.customerToken;
|
|
1168
1175
|
}
|
|
1176
|
+
if (opts?.onBehalfOf) {
|
|
1177
|
+
headers["Authorization"] = `Bearer ${opts.onBehalfOf}`;
|
|
1178
|
+
headers["X-Customer-Session-Claim"] = opts.onBehalfOf;
|
|
1179
|
+
}
|
|
1169
1180
|
if (opts?.headers) {
|
|
1170
1181
|
Object.assign(headers, opts.headers);
|
|
1171
1182
|
}
|
|
@@ -1273,6 +1284,41 @@ function createHttpClient(config) {
|
|
|
1273
1284
|
throw new SdkHttpError(`Network error: ${err.message}`, 0, error);
|
|
1274
1285
|
}
|
|
1275
1286
|
}
|
|
1287
|
+
async function getBinaryWithMeta(path, opts) {
|
|
1288
|
+
const url = `${config.baseUrl}${path}`;
|
|
1289
|
+
const controller = new AbortController();
|
|
1290
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
1291
|
+
try {
|
|
1292
|
+
const response = await fetch(url, {
|
|
1293
|
+
method: "GET",
|
|
1294
|
+
headers: getHeaders(void 0, opts),
|
|
1295
|
+
signal: controller.signal
|
|
1296
|
+
});
|
|
1297
|
+
clearTimeout(timeoutId);
|
|
1298
|
+
if (!response.ok) {
|
|
1299
|
+
const errBody = await response.json().catch(() => ({}));
|
|
1300
|
+
throw new SdkHttpError(
|
|
1301
|
+
errBody.message || `API error: ${response.status} ${response.statusText}`,
|
|
1302
|
+
response.status,
|
|
1303
|
+
errBody
|
|
1304
|
+
);
|
|
1305
|
+
}
|
|
1306
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
1307
|
+
const contentType = response.headers.get("content-type") ?? void 0;
|
|
1308
|
+
const disposition = response.headers.get("content-disposition") ?? "";
|
|
1309
|
+
const match = /filename\*?=(?:UTF-8'')?"?([^"\n;]+)"?/i.exec(disposition);
|
|
1310
|
+
const filename = match ? decodeURIComponent(match[1].trim()) : void 0;
|
|
1311
|
+
return { bytes, contentType, filename };
|
|
1312
|
+
} catch (error) {
|
|
1313
|
+
clearTimeout(timeoutId);
|
|
1314
|
+
if (error instanceof SdkHttpError) throw error;
|
|
1315
|
+
const err = error;
|
|
1316
|
+
if (err.name === "AbortError") {
|
|
1317
|
+
throw new SdkHttpError("Request timeout", 408);
|
|
1318
|
+
}
|
|
1319
|
+
throw new SdkHttpError(`Network error: ${err.message}`, 0, error);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1276
1322
|
async function upload(path, file, filename, metadata, fieldName = "file", opts) {
|
|
1277
1323
|
const url = `${config.baseUrl}${path}`;
|
|
1278
1324
|
const controller = new AbortController();
|
|
@@ -1296,6 +1342,10 @@ function createHttpClient(config) {
|
|
|
1296
1342
|
if (opts?.customerToken) {
|
|
1297
1343
|
headers["X-Customer-Session-Token"] = opts.customerToken;
|
|
1298
1344
|
}
|
|
1345
|
+
if (opts?.onBehalfOf) {
|
|
1346
|
+
headers["Authorization"] = `Bearer ${opts.onBehalfOf}`;
|
|
1347
|
+
headers["X-Customer-Session-Claim"] = opts.onBehalfOf;
|
|
1348
|
+
}
|
|
1299
1349
|
if (opts?.headers) {
|
|
1300
1350
|
Object.assign(headers, opts.headers);
|
|
1301
1351
|
}
|
|
@@ -1353,6 +1403,7 @@ function createHttpClient(config) {
|
|
|
1353
1403
|
delete: (path, opts) => withAuthRetry(path, () => request("DELETE", path, void 0, opts)),
|
|
1354
1404
|
getText: (path, opts) => withAuthRetry(path, () => getText(path, opts)),
|
|
1355
1405
|
getBinary: (path, opts) => withAuthRetry(path, () => getBinary(path, opts)),
|
|
1406
|
+
getBinaryWithMeta: (path, opts) => withAuthRetry(path, () => getBinaryWithMeta(path, opts)),
|
|
1356
1407
|
upload: ((path, file, filename, metadata, fieldName, opts) => withAuthRetry(path, () => upload(path, file, filename, metadata, fieldName, opts))),
|
|
1357
1408
|
setAuthToken,
|
|
1358
1409
|
getAuthToken
|
|
@@ -2992,9 +3043,12 @@ var AgentsClient = class {
|
|
|
2992
3043
|
return this.http.get("/api/v3/baas/agents", opts);
|
|
2993
3044
|
}
|
|
2994
3045
|
/**
|
|
2995
|
-
* Fund agent treasury (owner-only).
|
|
3046
|
+
* Fund agent treasury (owner-only). Normally returns a
|
|
2996
3047
|
* `PreparedTransactionResponse` wrapped in a `success: true` envelope —
|
|
2997
|
-
* the caller is expected to sign and submit the prepared bytes.
|
|
3048
|
+
* the caller is expected to sign and submit the prepared bytes. When the
|
|
3049
|
+
* amount trips an approval-required rule the host instead returns an
|
|
3050
|
+
* {@link AgentPendingApprovalResponse}; discriminate with
|
|
3051
|
+
* {@link isAgentFundPending}.
|
|
2998
3052
|
*/
|
|
2999
3053
|
async fund(agentId, request, opts) {
|
|
3000
3054
|
return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/fund`, request, opts);
|
|
@@ -3033,6 +3087,14 @@ var AgentsClient = class {
|
|
|
3033
3087
|
async revoke(agentId, opts) {
|
|
3034
3088
|
return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/revoke`, {}, opts);
|
|
3035
3089
|
}
|
|
3090
|
+
/**
|
|
3091
|
+
* Get an agent's certification snapshot (identity, rule refs, BLS group key,
|
|
3092
|
+
* and recent on-chain activity). A 404 throws `SdkHttpError` via `http.get`
|
|
3093
|
+
* — parity with {@link get}.
|
|
3094
|
+
*/
|
|
3095
|
+
async certification(agentId, opts) {
|
|
3096
|
+
return this.http.get(`/api/v3/baas/agents/${encodePathParam(agentId)}/certification`, opts);
|
|
3097
|
+
}
|
|
3036
3098
|
/**
|
|
3037
3099
|
* Update agent rules.
|
|
3038
3100
|
*
|
|
@@ -4406,6 +4468,20 @@ var StorageClient = class {
|
|
|
4406
4468
|
const appId = this.getAppId();
|
|
4407
4469
|
return this.http.getBinary(`/api/v3/baas/storage/${encodePathParam(appId)}/download/${encodePathParam(cid)}`, opts);
|
|
4408
4470
|
}
|
|
4471
|
+
/**
|
|
4472
|
+
* Download a file by CID WITH its response metadata — the raw bytes plus the
|
|
4473
|
+
* host-supplied `contentType` (derived from the stored file's metadata) and,
|
|
4474
|
+
* when present, the `filename`. Use this instead of {@link download} when the
|
|
4475
|
+
* caller must echo the content-type back to its own client; a bytes-only
|
|
4476
|
+
* download cannot recover it.
|
|
4477
|
+
*/
|
|
4478
|
+
async downloadWithMeta(cid, opts) {
|
|
4479
|
+
const appId = this.getAppId();
|
|
4480
|
+
return this.http.getBinaryWithMeta(
|
|
4481
|
+
`/api/v3/baas/storage/${encodePathParam(appId)}/download/${encodePathParam(cid)}`,
|
|
4482
|
+
opts
|
|
4483
|
+
);
|
|
4484
|
+
}
|
|
4409
4485
|
/**
|
|
4410
4486
|
* Get file metadata
|
|
4411
4487
|
*/
|
|
@@ -4528,6 +4604,16 @@ var FunctionsClient = class {
|
|
|
4528
4604
|
opts
|
|
4529
4605
|
);
|
|
4530
4606
|
}
|
|
4607
|
+
/**
|
|
4608
|
+
* Get a function's source code
|
|
4609
|
+
*/
|
|
4610
|
+
async getCode(functionId, opts) {
|
|
4611
|
+
const appId = this.getAppId();
|
|
4612
|
+
return this.http.get(
|
|
4613
|
+
`/api/v3/baas/functions/${encodePathParam(appId)}/${encodePathParam(functionId)}/code`,
|
|
4614
|
+
opts
|
|
4615
|
+
);
|
|
4616
|
+
}
|
|
4531
4617
|
/**
|
|
4532
4618
|
* Update a function
|
|
4533
4619
|
*/
|
|
@@ -5109,6 +5195,44 @@ var EntitiesClient = class _EntitiesClient {
|
|
|
5109
5195
|
async createAgent(req) {
|
|
5110
5196
|
return this.http.post("/api/v3/baas/entities/createAgent", req);
|
|
5111
5197
|
}
|
|
5198
|
+
/**
|
|
5199
|
+
* PREPARE half of the payer-funded agent-create flow.
|
|
5200
|
+
*
|
|
5201
|
+
* POSTs `/api/v3/baas/entities/prepare-create` with `entityType: 'agent'`. The cluster
|
|
5202
|
+
* runs the per-entity DKG (persists the binding, submits nothing on-chain) and
|
|
5203
|
+
* returns the unsigned payer-funding `Payment`(s) the caller signs + submits with
|
|
5204
|
+
* their own wallet — mirroring `prepareCreateAccount`. The agent's primary chain
|
|
5205
|
+
* is relayed as `chain` (the generic prepare/execute DTO key) so the host's
|
|
5206
|
+
* chain-bound preparer runs; `name` / `agentType` / `ruleRef` ride along.
|
|
5207
|
+
*/
|
|
5208
|
+
async prepareCreateAgent(req) {
|
|
5209
|
+
const { primaryChain, ...rest } = req;
|
|
5210
|
+
return this.http.post("/api/v3/baas/entities/prepare-create", {
|
|
5211
|
+
entityType: "agent",
|
|
5212
|
+
chain: primaryChain,
|
|
5213
|
+
...rest
|
|
5214
|
+
});
|
|
5215
|
+
}
|
|
5216
|
+
/**
|
|
5217
|
+
* EXECUTE half of the payer-funded agent-create flow.
|
|
5218
|
+
*
|
|
5219
|
+
* POSTs `/api/v3/baas/entities/execute-create` with `entityType: 'agent'`. The entity
|
|
5220
|
+
* already exists (its DKG ran during prepare); pass `signedFundingBlob` for the
|
|
5221
|
+
* validator to submit the payer's signed funding tx (XRPL/Stellar account-model
|
|
5222
|
+
* relay), or omit it when the caller already submitted the funding tx themselves.
|
|
5223
|
+
* `createTxId` is the Hedera receipt thread (the prepared create's
|
|
5224
|
+
* `transactionId`); ignored for non-Hedera chains. Mirrors
|
|
5225
|
+
* `executeCreateAccount` but tags `entityType: 'agent'`.
|
|
5226
|
+
*/
|
|
5227
|
+
async executeCreateAgent(req) {
|
|
5228
|
+
const { createTxId, signedFundingBlob, ...rest } = req;
|
|
5229
|
+
return this.http.post("/api/v3/baas/entities/execute-create", {
|
|
5230
|
+
...rest,
|
|
5231
|
+
...createTxId !== void 0 ? { createTxId } : {},
|
|
5232
|
+
...signedFundingBlob !== void 0 ? { signedFundingBlob } : {},
|
|
5233
|
+
entityType: "agent"
|
|
5234
|
+
});
|
|
5235
|
+
}
|
|
5112
5236
|
/**
|
|
5113
5237
|
* Mega-helper: build a token rule with a launchpad ModuleEntry attached,
|
|
5114
5238
|
* publish it, create the token, and return the combined result in one HTTP
|