@hsuite/smart-engines-sdk 3.10.0 → 3.12.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/dist/index.js CHANGED
@@ -6609,7 +6609,7 @@ var SdkHttpError = class extends Error {
6609
6609
  };
6610
6610
  function createHttpClient(config) {
6611
6611
  const timeout = config.timeout ?? 3e4;
6612
- function getHeaders(contentType) {
6612
+ function getHeaders(contentType, opts) {
6613
6613
  const headers = {};
6614
6614
  if (contentType) {
6615
6615
  headers["Content-Type"] = contentType;
@@ -6620,6 +6620,12 @@ function createHttpClient(config) {
6620
6620
  if (config.apiKey) {
6621
6621
  headers["X-API-Key"] = config.apiKey;
6622
6622
  }
6623
+ if (opts?.customerToken) {
6624
+ headers["X-Customer-Session-Token"] = opts.customerToken;
6625
+ }
6626
+ if (opts?.headers) {
6627
+ Object.assign(headers, opts.headers);
6628
+ }
6623
6629
  return headers;
6624
6630
  }
6625
6631
  function setAuthToken(token) {
@@ -6628,14 +6634,14 @@ function createHttpClient(config) {
6628
6634
  function getAuthToken() {
6629
6635
  return config.authToken;
6630
6636
  }
6631
- async function request(method, path, body) {
6637
+ async function request(method, path, body, opts) {
6632
6638
  const url = `${config.baseUrl}${path}`;
6633
6639
  const controller = new AbortController();
6634
6640
  const timeoutId = setTimeout(() => controller.abort(), timeout);
6635
6641
  try {
6636
6642
  const init = {
6637
6643
  method,
6638
- headers: getHeaders("application/json"),
6644
+ headers: getHeaders("application/json", opts),
6639
6645
  signal: controller.signal
6640
6646
  };
6641
6647
  if (body !== void 0) {
@@ -6664,14 +6670,14 @@ function createHttpClient(config) {
6664
6670
  throw new SdkHttpError(`Network error: ${err.message}`, 0, error);
6665
6671
  }
6666
6672
  }
6667
- async function getText(path) {
6673
+ async function getText(path, opts) {
6668
6674
  const url = `${config.baseUrl}${path}`;
6669
6675
  const controller = new AbortController();
6670
6676
  const timeoutId = setTimeout(() => controller.abort(), timeout);
6671
6677
  try {
6672
6678
  const response = await fetch(url, {
6673
6679
  method: "GET",
6674
- headers: getHeaders(),
6680
+ headers: getHeaders(void 0, opts),
6675
6681
  signal: controller.signal
6676
6682
  });
6677
6683
  clearTimeout(timeoutId);
@@ -6694,7 +6700,37 @@ function createHttpClient(config) {
6694
6700
  throw new SdkHttpError(`Network error: ${err.message}`, 0, error);
6695
6701
  }
6696
6702
  }
6697
- async function upload(path, file, filename, metadata, fieldName = "file") {
6703
+ async function getBinary(path, opts) {
6704
+ const url = `${config.baseUrl}${path}`;
6705
+ const controller = new AbortController();
6706
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
6707
+ try {
6708
+ const response = await fetch(url, {
6709
+ method: "GET",
6710
+ headers: getHeaders(void 0, opts),
6711
+ signal: controller.signal
6712
+ });
6713
+ clearTimeout(timeoutId);
6714
+ if (!response.ok) {
6715
+ const errBody = await response.json().catch(() => ({}));
6716
+ throw new SdkHttpError(
6717
+ errBody.message || `API error: ${response.status} ${response.statusText}`,
6718
+ response.status,
6719
+ errBody
6720
+ );
6721
+ }
6722
+ return new Uint8Array(await response.arrayBuffer());
6723
+ } catch (error) {
6724
+ clearTimeout(timeoutId);
6725
+ if (error instanceof SdkHttpError) throw error;
6726
+ const err = error;
6727
+ if (err.name === "AbortError") {
6728
+ throw new SdkHttpError("Request timeout", 408);
6729
+ }
6730
+ throw new SdkHttpError(`Network error: ${err.message}`, 0, error);
6731
+ }
6732
+ }
6733
+ async function upload(path, file, filename, metadata, fieldName = "file", opts) {
6698
6734
  const url = `${config.baseUrl}${path}`;
6699
6735
  const controller = new AbortController();
6700
6736
  const timeoutId = setTimeout(() => controller.abort(), timeout * 2);
@@ -6714,6 +6750,12 @@ function createHttpClient(config) {
6714
6750
  if (config.apiKey) {
6715
6751
  headers["X-API-Key"] = config.apiKey;
6716
6752
  }
6753
+ if (opts?.customerToken) {
6754
+ headers["X-Customer-Session-Token"] = opts.customerToken;
6755
+ }
6756
+ if (opts?.headers) {
6757
+ Object.assign(headers, opts.headers);
6758
+ }
6717
6759
  const response = await fetch(url, {
6718
6760
  method: "POST",
6719
6761
  headers,
@@ -6761,13 +6803,14 @@ function createHttpClient(config) {
6761
6803
  }
6762
6804
  }
6763
6805
  const client = {
6764
- post: (path, body) => withAuthRetry(path, () => request("POST", path, body)),
6765
- get: (path) => withAuthRetry(path, () => request("GET", path)),
6766
- put: (path, body) => withAuthRetry(path, () => request("PUT", path, body)),
6767
- patch: (path, body) => withAuthRetry(path, () => request("PATCH", path, body)),
6768
- delete: (path) => withAuthRetry(path, () => request("DELETE", path)),
6769
- getText: (path) => withAuthRetry(path, () => getText(path)),
6770
- upload: ((path, file, filename, metadata, fieldName) => withAuthRetry(path, () => upload(path, file, filename, metadata, fieldName))),
6806
+ post: (path, body, opts) => withAuthRetry(path, () => request("POST", path, body, opts)),
6807
+ get: (path, opts) => withAuthRetry(path, () => request("GET", path, void 0, opts)),
6808
+ put: (path, body, opts) => withAuthRetry(path, () => request("PUT", path, body, opts)),
6809
+ patch: (path, body, opts) => withAuthRetry(path, () => request("PATCH", path, body, opts)),
6810
+ delete: (path, opts) => withAuthRetry(path, () => request("DELETE", path, void 0, opts)),
6811
+ getText: (path, opts) => withAuthRetry(path, () => getText(path, opts)),
6812
+ getBinary: (path, opts) => withAuthRetry(path, () => getBinary(path, opts)),
6813
+ upload: ((path, file, filename, metadata, fieldName, opts) => withAuthRetry(path, () => upload(path, file, filename, metadata, fieldName, opts))),
6771
6814
  setAuthToken,
6772
6815
  getAuthToken
6773
6816
  };
@@ -8530,50 +8573,58 @@ var AgentsClient = class {
8530
8573
  }
8531
8574
  http;
8532
8575
  /** Register a new agent */
8533
- async register(request) {
8534
- return this.http.post("/api/v3/baas/agents/register", request);
8576
+ async register(request, opts) {
8577
+ return this.http.post("/api/v3/baas/agents/register", request, opts);
8535
8578
  }
8536
8579
  /** Get agent details */
8537
- async get(agentId) {
8538
- return this.http.get(`/api/v3/baas/agents/${encodePathParam(agentId)}`);
8580
+ async get(agentId, opts) {
8581
+ return this.http.get(`/api/v3/baas/agents/${encodePathParam(agentId)}`, opts);
8539
8582
  }
8540
8583
  /** List all agents */
8541
- async list() {
8542
- return this.http.get("/api/v3/baas/agents");
8584
+ async list(opts) {
8585
+ return this.http.get("/api/v3/baas/agents", opts);
8543
8586
  }
8544
8587
  /**
8545
8588
  * Fund agent treasury (owner-only). Returns a
8546
8589
  * `PreparedTransactionResponse` wrapped in a `success: true` envelope —
8547
8590
  * the caller is expected to sign and submit the prepared bytes.
8548
8591
  */
8549
- async fund(agentId, request) {
8550
- return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/fund`, request);
8592
+ async fund(agentId, request, opts) {
8593
+ return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/fund`, request, opts);
8551
8594
  }
8552
8595
  /**
8553
8596
  * Execute a trade (agent-wallet OR owner). Returns a
8554
8597
  * `PreparedTransactionResponse` wrapped in a `success: true` envelope.
8555
8598
  */
8556
- async trade(agentId, request) {
8557
- return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/trade`, request);
8599
+ async trade(agentId, request, opts) {
8600
+ return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/trade`, request, opts);
8558
8601
  }
8559
8602
  /**
8560
8603
  * Withdraw from agent treasury (owner-only). Returns a
8561
8604
  * `PreparedTransactionResponse` wrapped in a `success: true` envelope.
8562
8605
  */
8563
- async withdraw(agentId, request) {
8564
- return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/withdraw`, request);
8606
+ async withdraw(agentId, request, opts) {
8607
+ return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/withdraw`, request, opts);
8608
+ }
8609
+ /**
8610
+ * Execute a generic, declared capability (agent-wallet OR owner). The
8611
+ * chain-agnostic general form of an agent action: the capability may settle
8612
+ * on-chain, act off-chain, or both. Returns the ordered step results.
8613
+ */
8614
+ async execute(agentId, request, opts) {
8615
+ return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/execute`, request, opts);
8565
8616
  }
8566
8617
  /** Pause an agent */
8567
- async pause(agentId) {
8568
- return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/pause`, {});
8618
+ async pause(agentId, opts) {
8619
+ return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/pause`, {}, opts);
8569
8620
  }
8570
8621
  /** Resume a paused agent */
8571
- async resume(agentId) {
8572
- return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/resume`, {});
8622
+ async resume(agentId, opts) {
8623
+ return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/resume`, {}, opts);
8573
8624
  }
8574
8625
  /** Revoke an agent (permanent) */
8575
- async revoke(agentId) {
8576
- return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/revoke`, {});
8626
+ async revoke(agentId, opts) {
8627
+ return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/revoke`, {}, opts);
8577
8628
  }
8578
8629
  /**
8579
8630
  * Update agent rules.
@@ -8583,24 +8634,24 @@ var AgentsClient = class {
8583
8634
  * Nest matched the dynamic `:agentId` GET/POST handlers and rejected
8584
8635
  * the verb mismatch.
8585
8636
  */
8586
- async updateRules(agentId, rules) {
8587
- return this.http.patch(`/api/v3/baas/agents/${encodePathParam(agentId)}/rules`, rules);
8637
+ async updateRules(agentId, rules, opts) {
8638
+ return this.http.patch(`/api/v3/baas/agents/${encodePathParam(agentId)}/rules`, rules, opts);
8588
8639
  }
8589
8640
  /** Get agent events */
8590
- async getEvents(agentId) {
8591
- return this.http.get(`/api/v3/baas/agents/${encodePathParam(agentId)}/events`);
8641
+ async getEvents(agentId, opts) {
8642
+ return this.http.get(`/api/v3/baas/agents/${encodePathParam(agentId)}/events`, opts);
8592
8643
  }
8593
8644
  /** Get agent balances across chains */
8594
- async getBalances(agentId) {
8595
- return this.http.get(`/api/v3/baas/agents/${encodePathParam(agentId)}/balances`);
8645
+ async getBalances(agentId, opts) {
8646
+ return this.http.get(`/api/v3/baas/agents/${encodePathParam(agentId)}/balances`, opts);
8596
8647
  }
8597
8648
  /** Approve a pending agent operation */
8598
- async approve(agentId, operationId) {
8599
- return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/approve/${encodePathParam(operationId)}`, {});
8649
+ async approve(agentId, operationId, opts) {
8650
+ return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/approve/${encodePathParam(operationId)}`, {}, opts);
8600
8651
  }
8601
8652
  /** Reject a pending agent operation */
8602
- async reject(agentId, operationId) {
8603
- return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/reject/${encodePathParam(operationId)}`, {});
8653
+ async reject(agentId, operationId, opts) {
8654
+ return this.http.post(`/api/v3/baas/agents/${encodePathParam(agentId)}/reject/${encodePathParam(operationId)}`, {}, opts);
8604
8655
  }
8605
8656
  };
8606
8657
 
@@ -10324,6 +10375,214 @@ function btcToSatoshis(btc) {
10324
10375
  return (amount * 1e8).toFixed(0);
10325
10376
  }
10326
10377
 
10378
+ // src/ai/index.ts
10379
+ var ai_exports = {};
10380
+ __export(ai_exports, {
10381
+ createAnthropicProvider: () => createAnthropicProvider,
10382
+ createGeminiProvider: () => createGeminiProvider,
10383
+ createModelProvider: () => createModelProvider,
10384
+ createOpenAiProvider: () => createOpenAiProvider,
10385
+ inferJson: () => inferJson
10386
+ });
10387
+
10388
+ // src/ai/anthropic.ts
10389
+ var ANTHROPIC_URL = "https://api.anthropic.com/v1/messages";
10390
+ var ANTHROPIC_VERSION = "2023-06-01";
10391
+ var DEFAULT_MAX_TOKENS = 1024;
10392
+ function createAnthropicProvider(opts) {
10393
+ const { apiKey, model } = opts;
10394
+ return {
10395
+ provider: "anthropic",
10396
+ async infer(args) {
10397
+ const messages = args.messages.filter((m) => m.role === "user" || m.role === "assistant").map((m) => ({ role: m.role, content: m.content }));
10398
+ const body = {
10399
+ model,
10400
+ max_tokens: args.maxTokens ?? DEFAULT_MAX_TOKENS,
10401
+ messages
10402
+ };
10403
+ if (args.system) {
10404
+ body.system = args.system;
10405
+ }
10406
+ const res = await fetch(ANTHROPIC_URL, {
10407
+ method: "POST",
10408
+ headers: {
10409
+ "x-api-key": apiKey,
10410
+ "anthropic-version": ANTHROPIC_VERSION,
10411
+ "content-type": "application/json"
10412
+ },
10413
+ body: JSON.stringify(body)
10414
+ });
10415
+ if (!res.ok) {
10416
+ throw new Error(`Anthropic request failed with status ${res.status}`);
10417
+ }
10418
+ const data = await res.json();
10419
+ const text = Array.isArray(data.content) ? data.content.find((b) => typeof b.text === "string")?.text : void 0;
10420
+ if (typeof text !== "string") {
10421
+ return { ok: false, error: "Anthropic response contained no text block", raw: data };
10422
+ }
10423
+ return { ok: true, text, raw: data };
10424
+ }
10425
+ };
10426
+ }
10427
+
10428
+ // src/ai/openai.ts
10429
+ var OPENAI_URL = "https://api.openai.com/v1/chat/completions";
10430
+ var DEFAULT_MAX_TOKENS2 = 1024;
10431
+ function createOpenAiProvider(opts) {
10432
+ const { apiKey, model } = opts;
10433
+ return {
10434
+ provider: "openai",
10435
+ async infer(args) {
10436
+ const messages = [];
10437
+ if (args.system) {
10438
+ messages.push({ role: "system", content: args.system });
10439
+ }
10440
+ for (const m of args.messages) {
10441
+ messages.push({ role: m.role, content: m.content });
10442
+ }
10443
+ const res = await fetch(OPENAI_URL, {
10444
+ method: "POST",
10445
+ headers: {
10446
+ Authorization: `Bearer ${apiKey}`,
10447
+ "content-type": "application/json"
10448
+ },
10449
+ body: JSON.stringify({
10450
+ model,
10451
+ max_tokens: args.maxTokens ?? DEFAULT_MAX_TOKENS2,
10452
+ messages
10453
+ })
10454
+ });
10455
+ if (!res.ok) {
10456
+ throw new Error(`OpenAI request failed with status ${res.status}`);
10457
+ }
10458
+ const data = await res.json();
10459
+ const text = data.choices?.[0]?.message?.content;
10460
+ if (typeof text !== "string") {
10461
+ return { ok: false, error: "OpenAI response contained no message content", raw: data };
10462
+ }
10463
+ return { ok: true, text, raw: data };
10464
+ }
10465
+ };
10466
+ }
10467
+
10468
+ // src/ai/gemini.ts
10469
+ var GEMINI_BASE = "https://generativelanguage.googleapis.com/v1beta/models";
10470
+ var DEFAULT_MAX_TOKENS3 = 1024;
10471
+ function createGeminiProvider(opts) {
10472
+ const { apiKey, model } = opts;
10473
+ return {
10474
+ provider: "gemini",
10475
+ async infer(args) {
10476
+ const contents = args.messages.filter((m) => m.role === "user" || m.role === "assistant").map((m) => ({
10477
+ role: m.role === "assistant" ? "model" : "user",
10478
+ parts: [{ text: m.content }]
10479
+ }));
10480
+ const body = {
10481
+ contents,
10482
+ generationConfig: { maxOutputTokens: args.maxTokens ?? DEFAULT_MAX_TOKENS3 }
10483
+ };
10484
+ if (args.system) {
10485
+ body.systemInstruction = { parts: [{ text: args.system }] };
10486
+ }
10487
+ const url = `${GEMINI_BASE}/${model}:generateContent?key=${encodeURIComponent(apiKey)}`;
10488
+ const res = await fetch(url, {
10489
+ method: "POST",
10490
+ headers: { "content-type": "application/json" },
10491
+ body: JSON.stringify(body)
10492
+ });
10493
+ if (!res.ok) {
10494
+ throw new Error(`Gemini request failed with status ${res.status}`);
10495
+ }
10496
+ const data = await res.json();
10497
+ const text = data.candidates?.[0]?.content?.parts?.[0]?.text;
10498
+ if (typeof text !== "string") {
10499
+ return { ok: false, error: "Gemini response contained no text part", raw: data };
10500
+ }
10501
+ return { ok: true, text, raw: data };
10502
+ }
10503
+ };
10504
+ }
10505
+
10506
+ // src/ai/factory.ts
10507
+ function createModelProvider(opts) {
10508
+ const { provider, apiKey, model } = opts;
10509
+ switch (provider) {
10510
+ case "anthropic":
10511
+ return createAnthropicProvider({ apiKey, model });
10512
+ case "openai":
10513
+ return createOpenAiProvider({ apiKey, model });
10514
+ case "gemini":
10515
+ return createGeminiProvider({ apiKey, model });
10516
+ default: {
10517
+ const never = provider;
10518
+ throw new Error(`Unsupported model provider: ${String(never)}`);
10519
+ }
10520
+ }
10521
+ }
10522
+
10523
+ // src/ai/infer-json.ts
10524
+ var JSON_ONLY_INSTRUCTION = "Respond with ONLY a single JSON object, no prose.";
10525
+ var RETRY_INSTRUCTION = "Return valid JSON only.";
10526
+ function extractJson(raw) {
10527
+ const start = raw.indexOf("{");
10528
+ const end = raw.lastIndexOf("}");
10529
+ if (start === -1 || end === -1 || end < start) {
10530
+ throw new Error("no JSON object found in reply");
10531
+ }
10532
+ return JSON.parse(raw.slice(start, end + 1));
10533
+ }
10534
+ async function inferJson(opts) {
10535
+ const { provider, apiKey, model, system, input, maxTokens, parse } = opts;
10536
+ let client;
10537
+ try {
10538
+ client = createModelProvider({ provider, apiKey, model });
10539
+ } catch (err) {
10540
+ return { ok: false, error: errMsg(err) };
10541
+ }
10542
+ const systemPrompt = system ? `${system}
10543
+
10544
+ ${JSON_ONLY_INSTRUCTION}` : JSON_ONLY_INSTRUCTION;
10545
+ const userContent = typeof input === "string" ? input : JSON.stringify(input);
10546
+ const messages = [{ role: "user", content: userContent }];
10547
+ const first = await runOnce(client, { system: systemPrompt, messages, maxTokens }, parse);
10548
+ if (first.ok) {
10549
+ return first;
10550
+ }
10551
+ const retryMessages = [...messages];
10552
+ if (typeof first.raw === "string") {
10553
+ retryMessages.push({ role: "assistant", content: first.raw });
10554
+ }
10555
+ retryMessages.push({ role: "user", content: RETRY_INSTRUCTION });
10556
+ const second = await runOnce(
10557
+ client,
10558
+ { system: systemPrompt, messages: retryMessages, maxTokens },
10559
+ parse
10560
+ );
10561
+ return second;
10562
+ }
10563
+ async function runOnce(client, args, parse) {
10564
+ let inferred;
10565
+ try {
10566
+ inferred = await client.infer(args);
10567
+ } catch (err) {
10568
+ return { ok: false, error: errMsg(err) };
10569
+ }
10570
+ if (!inferred.ok || typeof inferred.text !== "string") {
10571
+ return { ok: false, error: inferred.error ?? "provider returned no text", raw: inferred.text };
10572
+ }
10573
+ const raw = inferred.text;
10574
+ try {
10575
+ const parsed = extractJson(raw);
10576
+ const value = parse ? parse(parsed) : parsed;
10577
+ return { ok: true, value, raw };
10578
+ } catch (err) {
10579
+ return { ok: false, error: errMsg(err), raw };
10580
+ }
10581
+ }
10582
+ function errMsg(err) {
10583
+ return err instanceof Error ? err.message : String(err);
10584
+ }
10585
+
10327
10586
  // src/baas/index.ts
10328
10587
  var baas_exports = {};
10329
10588
  __export(baas_exports, {
@@ -10478,30 +10737,31 @@ var StorageClient = class {
10478
10737
  /**
10479
10738
  * Upload a file to storage
10480
10739
  */
10481
- async upload(file, filename, metadata) {
10740
+ async upload(file, filename, metadata, opts) {
10482
10741
  const appId = this.getAppId();
10483
- return this.http.upload(`/api/v3/baas/storage/${encodePathParam(appId)}/upload`, file, filename, metadata);
10742
+ return this.http.upload(`/api/v3/baas/storage/${encodePathParam(appId)}/upload`, file, filename, metadata, void 0, opts);
10484
10743
  }
10485
10744
  /**
10486
- * Download a file by CID
10745
+ * Download a file by CID. Returns the raw file bytes as a `Uint8Array`
10746
+ * (binary-safe — never JSON-parsed or text-decoded).
10487
10747
  */
10488
- async download(cid) {
10748
+ async download(cid, opts) {
10489
10749
  const appId = this.getAppId();
10490
- return this.http.get(`/api/v3/baas/storage/${encodePathParam(appId)}/download/${encodePathParam(cid)}`);
10750
+ return this.http.getBinary(`/api/v3/baas/storage/${encodePathParam(appId)}/download/${encodePathParam(cid)}`, opts);
10491
10751
  }
10492
10752
  /**
10493
10753
  * Get file metadata
10494
10754
  */
10495
- async getMetadata(cid) {
10755
+ async getMetadata(cid, opts) {
10496
10756
  const appId = this.getAppId();
10497
- return this.http.get(`/api/v3/baas/storage/${encodePathParam(appId)}/metadata/${encodePathParam(cid)}`);
10757
+ return this.http.get(`/api/v3/baas/storage/${encodePathParam(appId)}/metadata/${encodePathParam(cid)}`, opts);
10498
10758
  }
10499
10759
  /**
10500
10760
  * Delete a file
10501
10761
  */
10502
- async delete(cid) {
10762
+ async delete(cid, opts) {
10503
10763
  const appId = this.getAppId();
10504
- return this.http.delete(`/api/v3/baas/storage/${encodePathParam(appId)}/${encodePathParam(cid)}`);
10764
+ return this.http.delete(`/api/v3/baas/storage/${encodePathParam(appId)}/${encodePathParam(cid)}`, opts);
10505
10765
  }
10506
10766
  /**
10507
10767
  * List all files for the app.
@@ -10510,27 +10770,27 @@ var StorageClient = class {
10510
10770
  * `offset` for pagination).
10511
10771
  * @returns The file list and total count.
10512
10772
  */
10513
- async listFiles(pagination) {
10773
+ async listFiles(pagination, opts) {
10514
10774
  const appId = this.getAppId();
10515
10775
  const params = new URLSearchParams();
10516
10776
  if (pagination?.limit !== void 0) params.set("limit", String(pagination.limit));
10517
10777
  if (pagination?.offset !== void 0) params.set("offset", String(pagination.offset));
10518
10778
  const qs = params.toString();
10519
- return this.http.get(`/api/v3/baas/storage/${encodePathParam(appId)}/files${qs ? `?${qs}` : ""}`);
10779
+ return this.http.get(`/api/v3/baas/storage/${encodePathParam(appId)}/files${qs ? `?${qs}` : ""}`, opts);
10520
10780
  }
10521
10781
  /**
10522
10782
  * Get storage usage for the current app
10523
10783
  */
10524
- async getUsage() {
10784
+ async getUsage(opts) {
10525
10785
  const appId = this.getAppId();
10526
- return this.http.get(`/api/v3/baas/storage/${encodePathParam(appId)}/usage`);
10786
+ return this.http.get(`/api/v3/baas/storage/${encodePathParam(appId)}/usage`, opts);
10527
10787
  }
10528
10788
  /**
10529
10789
  * Check if a file exists
10530
10790
  */
10531
- async exists(cid) {
10791
+ async exists(cid, opts) {
10532
10792
  const appId = this.getAppId();
10533
- return this.http.get(`/api/v3/baas/storage/${encodePathParam(appId)}/exists/${encodePathParam(cid)}`);
10793
+ return this.http.get(`/api/v3/baas/storage/${encodePathParam(appId)}/exists/${encodePathParam(cid)}`, opts);
10534
10794
  }
10535
10795
  };
10536
10796
 
@@ -10543,61 +10803,99 @@ var FunctionsClient = class {
10543
10803
  http;
10544
10804
  getAppId;
10545
10805
  /**
10546
- * Deploy a new function
10547
- */
10548
- async deploy(request) {
10806
+ * Build the Ed25519 signed-code envelope the host mandates for every deploy
10807
+ * and eval. A fresh ephemeral keypair is generated per call, so no long-lived
10808
+ * signing key is held anywhere — each artifact carries its own signature.
10809
+ *
10810
+ * Scheme (must match the host verifier): `hash = sha256(code)` (hex),
10811
+ * `message = "<hash>:<timestamp>"`, signed Ed25519; `publicKey` is SPKI-DER
10812
+ * (base64). `crypto` is imported lazily so this never pulls Node built-ins
10813
+ * into a browser bundle that doesn't sign code.
10814
+ */
10815
+ async signCode(code) {
10816
+ const { generateKeyPairSync, createHash, sign: sign2 } = await import('crypto');
10817
+ const { publicKey, privateKey } = generateKeyPairSync("ed25519");
10818
+ const hash = createHash("sha256").update(code, "utf8").digest("hex");
10819
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
10820
+ const signature = sign2(null, Buffer.from(`${hash}:${timestamp}`, "utf8"), privateKey).toString("base64");
10821
+ const publicKeyDer = publicKey.export({ format: "der", type: "spki" }).toString("base64");
10822
+ return { code, hash, timestamp, signature, publicKey: publicKeyDer };
10823
+ }
10824
+ /**
10825
+ * Deploy a new function. If `signedCode` is omitted it is auto-built from
10826
+ * `request.code` via {@link signCode} — the host requires it, so the default
10827
+ * is to sign rather than 400. Pass your own envelope to override.
10828
+ */
10829
+ async deploy(request, opts) {
10549
10830
  const appId = this.getAppId();
10550
- return this.http.post(`/api/v3/baas/functions/${encodePathParam(appId)}`, request);
10831
+ const signedCode = request.signedCode ?? await this.signCode(request.code);
10832
+ return this.http.post(`/api/v3/baas/functions/${encodePathParam(appId)}`, { ...request, signedCode }, opts);
10551
10833
  }
10552
10834
  /**
10553
10835
  * Invoke a function
10554
10836
  */
10555
- async invoke(functionId, payload) {
10837
+ async invoke(functionId, payload, opts) {
10556
10838
  const appId = this.getAppId();
10557
10839
  return this.http.post(
10558
10840
  `/api/v3/baas/functions/${encodePathParam(appId)}/${encodePathParam(functionId)}/invoke`,
10559
- payload ?? {}
10841
+ payload ?? {},
10842
+ opts
10560
10843
  );
10561
10844
  }
10845
+ /**
10846
+ * Evaluate signed code once (ephemeral) — no persistent deploy.
10847
+ *
10848
+ * For throwaway / AI-generated snippets. The host runs it in the same hardened
10849
+ * isolate and discards it; metered + quota'd like a normal invocation. As with
10850
+ * {@link deploy}, `signedCode` is auto-built from `request.code` when omitted.
10851
+ */
10852
+ async eval(request, opts) {
10853
+ const appId = this.getAppId();
10854
+ const signedCode = request.signedCode ?? await this.signCode(request.code);
10855
+ return this.http.post(`/api/v3/baas/functions/${encodePathParam(appId)}/eval`, { ...request, signedCode }, opts);
10856
+ }
10562
10857
  /**
10563
10858
  * List all functions for the current app
10564
10859
  */
10565
- async list() {
10860
+ async list(opts) {
10566
10861
  const appId = this.getAppId();
10567
- return this.http.get(`/api/v3/baas/functions/${encodePathParam(appId)}`);
10862
+ return this.http.get(`/api/v3/baas/functions/${encodePathParam(appId)}`, opts);
10568
10863
  }
10569
10864
  /**
10570
10865
  * Get function details
10571
10866
  */
10572
- async get(functionId) {
10867
+ async get(functionId, opts) {
10573
10868
  const appId = this.getAppId();
10574
10869
  return this.http.get(
10575
- `/api/v3/baas/functions/${encodePathParam(appId)}/${encodePathParam(functionId)}`
10870
+ `/api/v3/baas/functions/${encodePathParam(appId)}/${encodePathParam(functionId)}`,
10871
+ opts
10576
10872
  );
10577
10873
  }
10578
10874
  /**
10579
10875
  * Update a function
10580
10876
  */
10581
- async update(functionId, updates) {
10877
+ async update(functionId, updates, opts) {
10582
10878
  const appId = this.getAppId();
10583
10879
  return this.http.put(
10584
10880
  `/api/v3/baas/functions/${encodePathParam(appId)}/${encodePathParam(functionId)}`,
10585
- updates
10881
+ updates,
10882
+ opts
10586
10883
  );
10587
10884
  }
10588
10885
  /**
10589
10886
  * Delete a function
10590
10887
  */
10591
- async delete(functionId) {
10888
+ async delete(functionId, opts) {
10592
10889
  const appId = this.getAppId();
10593
10890
  return this.http.delete(
10594
- `/api/v3/baas/functions/${encodePathParam(appId)}/${encodePathParam(functionId)}`
10891
+ `/api/v3/baas/functions/${encodePathParam(appId)}/${encodePathParam(functionId)}`,
10892
+ opts
10595
10893
  );
10596
10894
  }
10597
10895
  /**
10598
10896
  * Get function execution logs
10599
10897
  */
10600
- async getLogs(functionId, options) {
10898
+ async getLogs(functionId, options, opts) {
10601
10899
  const appId = this.getAppId();
10602
10900
  const params = new URLSearchParams();
10603
10901
  if (options?.limit !== void 0) params.set("limit", String(options.limit));
@@ -10605,15 +10903,16 @@ var FunctionsClient = class {
10605
10903
  if (options?.level) params.set("level", options.level);
10606
10904
  const qs = params.toString();
10607
10905
  return this.http.get(
10608
- `/api/v3/baas/functions/${encodePathParam(appId)}/${encodePathParam(functionId)}/logs${qs ? `?${qs}` : ""}`
10906
+ `/api/v3/baas/functions/${encodePathParam(appId)}/${encodePathParam(functionId)}/logs${qs ? `?${qs}` : ""}`,
10907
+ opts
10609
10908
  );
10610
10909
  }
10611
10910
  /**
10612
10911
  * Get function statistics for an app
10613
10912
  */
10614
- async getStats() {
10913
+ async getStats(opts) {
10615
10914
  const appId = this.getAppId();
10616
- return this.http.get(`/api/v3/baas/functions/${encodePathParam(appId)}/stats`);
10915
+ return this.http.get(`/api/v3/baas/functions/${encodePathParam(appId)}/stats`, opts);
10617
10916
  }
10618
10917
  };
10619
10918
 
@@ -10628,45 +10927,46 @@ var MessagingClient = class {
10628
10927
  /**
10629
10928
  * Create a new channel
10630
10929
  */
10631
- async createChannel(config) {
10930
+ async createChannel(config, opts) {
10632
10931
  const appId = this.getAppId();
10633
- return this.http.post(`/api/v3/baas/messaging/${encodePathParam(appId)}/channels`, config);
10932
+ return this.http.post(`/api/v3/baas/messaging/${encodePathParam(appId)}/channels`, config, opts);
10634
10933
  }
10635
10934
  /**
10636
10935
  * Delete a channel
10637
10936
  */
10638
- async deleteChannel(channelId) {
10937
+ async deleteChannel(channelId, opts) {
10639
10938
  const appId = this.getAppId();
10640
- return this.http.delete(`/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channelId)}`);
10939
+ return this.http.delete(`/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channelId)}`, opts);
10641
10940
  }
10642
10941
  /**
10643
10942
  * Get a channel by ID
10644
10943
  */
10645
- async getChannel(channelId) {
10944
+ async getChannel(channelId, opts) {
10646
10945
  const appId = this.getAppId();
10647
- return this.http.get(`/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channelId)}`);
10946
+ return this.http.get(`/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channelId)}`, opts);
10648
10947
  }
10649
10948
  /**
10650
10949
  * List all channels for the app
10651
10950
  */
10652
- async listChannels() {
10951
+ async listChannels(opts) {
10653
10952
  const appId = this.getAppId();
10654
- return this.http.get(`/api/v3/baas/messaging/${encodePathParam(appId)}/channels`);
10953
+ return this.http.get(`/api/v3/baas/messaging/${encodePathParam(appId)}/channels`, opts);
10655
10954
  }
10656
10955
  /**
10657
10956
  * Publish a message to a channel
10658
10957
  */
10659
- async publish(channel, message, metadata) {
10958
+ async publish(channel, message, metadata, opts) {
10660
10959
  const appId = this.getAppId();
10661
10960
  return this.http.post(
10662
10961
  `/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channel)}/publish`,
10663
- { data: message, metadata }
10962
+ { data: message, metadata },
10963
+ opts
10664
10964
  );
10665
10965
  }
10666
10966
  /**
10667
10967
  * Get message history for a channel
10668
10968
  */
10669
- async getHistory(channel, options) {
10969
+ async getHistory(channel, options, opts) {
10670
10970
  const appId = this.getAppId();
10671
10971
  const params = new URLSearchParams();
10672
10972
  if (options?.limit !== void 0) params.set("limit", String(options.limit));
@@ -10674,7 +10974,8 @@ var MessagingClient = class {
10674
10974
  if (options?.after) params.set("after", options.after);
10675
10975
  const qs = params.toString();
10676
10976
  return this.http.get(
10677
- `/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channel)}/history${qs ? `?${qs}` : ""}`
10977
+ `/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channel)}/history${qs ? `?${qs}` : ""}`,
10978
+ opts
10678
10979
  );
10679
10980
  }
10680
10981
  /**
@@ -10685,11 +10986,12 @@ var MessagingClient = class {
10685
10986
  * `setPresence(member)` hit a non-existent appId-scoped route and 404'd
10686
10987
  * in production. The channel is now the first argument.
10687
10988
  */
10688
- async setPresence(channel, member) {
10989
+ async setPresence(channel, member, opts) {
10689
10990
  const appId = this.getAppId();
10690
10991
  return this.http.post(
10691
10992
  `/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channel)}/presence`,
10692
- member
10993
+ member,
10994
+ opts
10693
10995
  );
10694
10996
  }
10695
10997
  /**
@@ -10701,27 +11003,29 @@ var MessagingClient = class {
10701
11003
  * `clientId` (not `memberId`) the second — they're the same identifier
10702
11004
  * but renamed to match the server param.
10703
11005
  */
10704
- async removePresence(channel, clientId) {
11006
+ async removePresence(channel, clientId, opts) {
10705
11007
  const appId = this.getAppId();
10706
11008
  return this.http.delete(
10707
- `/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channel)}/presence/${encodePathParam(clientId)}`
11009
+ `/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channel)}/presence/${encodePathParam(clientId)}`,
11010
+ opts
10708
11011
  );
10709
11012
  }
10710
11013
  /**
10711
11014
  * Get presence info for a channel
10712
11015
  */
10713
- async getPresence(channel) {
11016
+ async getPresence(channel, opts) {
10714
11017
  const appId = this.getAppId();
10715
11018
  return this.http.get(
10716
- `/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channel)}/presence`
11019
+ `/api/v3/baas/messaging/${encodePathParam(appId)}/channels/${encodePathParam(channel)}/presence`,
11020
+ opts
10717
11021
  );
10718
11022
  }
10719
11023
  /**
10720
11024
  * Get messaging statistics
10721
11025
  */
10722
- async getStats() {
11026
+ async getStats(opts) {
10723
11027
  const appId = this.getAppId();
10724
- return this.http.get(`/api/v3/baas/messaging/${encodePathParam(appId)}/stats`);
11028
+ return this.http.get(`/api/v3/baas/messaging/${encodePathParam(appId)}/stats`, opts);
10725
11029
  }
10726
11030
  };
10727
11031
 
@@ -13405,6 +13709,7 @@ exports.ValidatorDiscoveryClient = ValidatorDiscoveryClient;
13405
13709
  exports.ValidatorMetadataSchema = ValidatorMetadataSchema;
13406
13710
  exports.ValidatorRulesSchema = ValidatorRulesSchema;
13407
13711
  exports.XrplTransactionsClient = XrplTransactionsClient;
13712
+ exports.ai = ai_exports;
13408
13713
  exports.appTopic = appTopic;
13409
13714
  exports.atom = atom;
13410
13715
  exports.auth = auth_exports;
@@ -13413,7 +13718,11 @@ exports.bridge = bridge_exports;
13413
13718
  exports.canonicalizeAttestation = canonicalizeAttestation;
13414
13719
  exports.chains = chains_exports;
13415
13720
  exports.computeAttestationHash = computeAttestationHash;
13721
+ exports.createAnthropicProvider = createAnthropicProvider;
13722
+ exports.createGeminiProvider = createGeminiProvider;
13416
13723
  exports.createHttpClient = createHttpClient;
13724
+ exports.createModelProvider = createModelProvider;
13725
+ exports.createOpenAiProvider = createOpenAiProvider;
13417
13726
  exports.createResilientFetchWithBreaker = createResilientFetchWithBreaker;
13418
13727
  exports.createXrplWeb3Signer = createXrplWeb3Signer;
13419
13728
  exports.dao = dao_exports;
@@ -13429,6 +13738,7 @@ exports.forAgent = forAgent;
13429
13738
  exports.forToken = forToken;
13430
13739
  exports.forTopic = forTopic;
13431
13740
  exports.governance = governance_exports;
13741
+ exports.inferJson = inferJson;
13432
13742
  exports.isKnownNetwork = isKnownNetwork;
13433
13743
  exports.isPersonhoodVerifierNotConfigured = isPersonhoodVerifierNotConfigured;
13434
13744
  exports.isRuleRejected = isRuleRejected;