@blockrun/llm 3.24.10 → 3.26.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/README.md +12 -0
- package/dist/index.cjs +114 -17
- package/dist/index.d.cts +83 -2
- package/dist/index.d.ts +83 -2
- package/dist/index.js +111 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -634,6 +634,17 @@ console.log(res.usage?.server_side_tool_usage); // { x_posts_fetched, ... }
|
|
|
634
634
|
console.log(res.costUsd, res.settlement); // what you paid, and the tx
|
|
635
635
|
```
|
|
636
636
|
|
|
637
|
+
Reasoning models take `reasoningEffort` on any chat call. Unset, the model's
|
|
638
|
+
own default applies, and some default to their highest effort (Reflection Beam
|
|
639
|
+
defaults to `"max"`); reasoning tokens bill as output:
|
|
640
|
+
|
|
641
|
+
```typescript
|
|
642
|
+
const quick = await client.chatCompletion('reflection/beam-1.0-501b-a23b', messages, {
|
|
643
|
+
reasoningEffort: 'low', // none | minimal | low | medium | high | xhigh | max, per model
|
|
644
|
+
maxTokens: 8192, // reasoning counts toward max_tokens
|
|
645
|
+
});
|
|
646
|
+
```
|
|
647
|
+
|
|
637
648
|
`costUsd`, `settlement` and the per-call `timeout` work the same on `LLMClient`
|
|
638
649
|
(Base / Arc). Both clients default to a 600 s request timeout
|
|
639
650
|
(`BLOCKRUN_CHAT_TIMEOUT`, in seconds, overrides it; the `timeout` option, in
|
|
@@ -723,6 +734,7 @@ await client.closeBatchChannel();
|
|
|
723
734
|
- **Never pays twice.** Anything that goes wrong before a batch payment is sent falls back to `exact`. Once one is sent, a call whose payment may have been charged throws `BatchPaymentUnresolvedError` and is never paid again (no new payment, no `exact`, no fallback model).
|
|
724
735
|
- **Non-streaming chat only.** `chat`, `chatCompletion`, `smartChat` and `smartChatCompletion` use batch; `stream()` and media jobs pay `exact`.
|
|
725
736
|
- **One channel per wallet.** All clients for a wallet share one channel, saved to `~/.blockrun/solana-batch/<wallet>.json` (mode `0600`) so a restart reuses it.
|
|
737
|
+
- **One process per wallet.** The process that opens the channel holds its store's lock until it exits. Other processes on that wallet (worker pools, PM2/cluster workers, parallel runs) pay `exact`, reported as `channel_store_locked`. Give each worker its own wallet, or route calls through one process. `batch.onLocked: "wait"` waits up to `batch.lockWaitMs` (default 60 s) for the lock, and `"throw"` raises `BatchChannelLockedError` (unpaid, nothing signed) instead of paying `exact`.
|
|
726
738
|
- **Observable.** Every fallback, backoff, recovery and re-read writes one stderr line; `batch.onEvent` and `client.getBatchStats()` expose the same events and counters.
|
|
727
739
|
|
|
728
740
|
The full runtime contract (the answer-by-answer table, payment-identifier
|
package/dist/index.cjs
CHANGED
|
@@ -36,11 +36,13 @@ __export(index_exports, {
|
|
|
36
36
|
AnthropicClient: () => AnthropicClient,
|
|
37
37
|
BASE_CHAIN_ID: () => BASE_CHAIN_ID,
|
|
38
38
|
BLOCKRUN_SOL_OPERATOR: () => BLOCKRUN_SOL_OPERATOR,
|
|
39
|
+
BatchChannelLockedError: () => BatchChannelLockedError,
|
|
39
40
|
BatchCloseDeferredError: () => BatchCloseDeferredError,
|
|
40
41
|
BatchPaymentUnresolvedError: () => BatchPaymentUnresolvedError,
|
|
41
42
|
BlockrunClient: () => BlockrunClient,
|
|
42
43
|
BlockrunError: () => BlockrunError,
|
|
43
44
|
DEFAULT_BATCH_IN_DOUBT: () => DEFAULT_BATCH_IN_DOUBT,
|
|
45
|
+
DEFAULT_BATCH_LOCK_WAIT_MS: () => DEFAULT_BATCH_LOCK_WAIT_MS,
|
|
44
46
|
DEFAULT_BATCH_RATE_LIMIT: () => DEFAULT_BATCH_RATE_LIMIT,
|
|
45
47
|
EVM_NETWORKS: () => EVM_NETWORKS,
|
|
46
48
|
ImageClient: () => ImageClient,
|
|
@@ -5120,7 +5122,7 @@ function getCostSummary() {
|
|
|
5120
5122
|
}
|
|
5121
5123
|
|
|
5122
5124
|
// src/version.ts
|
|
5123
|
-
var SDK_VERSION = "3.
|
|
5125
|
+
var SDK_VERSION = "3.26.0";
|
|
5124
5126
|
var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
|
|
5125
5127
|
|
|
5126
5128
|
// src/client.ts
|
|
@@ -5249,6 +5251,7 @@ var LLMClient = class _LLMClient {
|
|
|
5249
5251
|
searchParameters: options?.searchParameters,
|
|
5250
5252
|
responseFormat: options?.responseFormat,
|
|
5251
5253
|
stop: options?.stop,
|
|
5254
|
+
reasoningEffort: options?.reasoningEffort,
|
|
5252
5255
|
fallbackModels: options?.fallbackModels
|
|
5253
5256
|
});
|
|
5254
5257
|
return result.choices[0].message.content || "";
|
|
@@ -5321,6 +5324,7 @@ var LLMClient = class _LLMClient {
|
|
|
5321
5324
|
searchParameters: options?.searchParameters,
|
|
5322
5325
|
responseFormat: options?.responseFormat,
|
|
5323
5326
|
stop: options?.stop,
|
|
5327
|
+
reasoningEffort: options?.reasoningEffort,
|
|
5324
5328
|
// An explicit caller-supplied chain wins over the routed one.
|
|
5325
5329
|
fallbackModels: options?.fallbackModels ?? decision.fallbacks
|
|
5326
5330
|
});
|
|
@@ -5358,6 +5362,7 @@ var LLMClient = class _LLMClient {
|
|
|
5358
5362
|
toolChoice: options.toolChoice,
|
|
5359
5363
|
responseFormat: options.responseFormat,
|
|
5360
5364
|
stop: options.stop,
|
|
5365
|
+
reasoningEffort: options.reasoningEffort,
|
|
5361
5366
|
timeout: options.timeout,
|
|
5362
5367
|
// An explicit caller-supplied chain wins over the routed one.
|
|
5363
5368
|
fallbackModels: options.fallbackModels ?? decision.fallbacks
|
|
@@ -5444,6 +5449,7 @@ var LLMClient = class _LLMClient {
|
|
|
5444
5449
|
if (options?.toolChoice !== void 0) body.tool_choice = options.toolChoice;
|
|
5445
5450
|
if (options?.responseFormat !== void 0) body.response_format = options.responseFormat;
|
|
5446
5451
|
if (options?.stop !== void 0) body.stop = options.stop;
|
|
5452
|
+
if (options?.reasoningEffort !== void 0) body.reasoning_effort = options.reasoningEffort;
|
|
5447
5453
|
return body;
|
|
5448
5454
|
};
|
|
5449
5455
|
const chain = [model, ...options?.fallbackModels ?? []];
|
|
@@ -5817,6 +5823,7 @@ var LLMClient = class _LLMClient {
|
|
|
5817
5823
|
if (options?.toolChoice !== void 0) body.tool_choice = options.toolChoice;
|
|
5818
5824
|
if (options?.responseFormat !== void 0) body.response_format = options.responseFormat;
|
|
5819
5825
|
if (options?.stop !== void 0) body.stop = options.stop;
|
|
5826
|
+
if (options?.reasoningEffort !== void 0) body.reasoning_effort = options.reasoningEffort;
|
|
5820
5827
|
const cacheKey2 = `/v1/chat/completions:${requestModel}`;
|
|
5821
5828
|
const requestBody = JSON.stringify(body);
|
|
5822
5829
|
const cached = this.preAuthCache.get(cacheKey2);
|
|
@@ -9950,11 +9957,11 @@ var WALLET_DIR = path4.join(os3.homedir(), ".blockrun");
|
|
|
9950
9957
|
var SOLANA_WALLET_FILE = path4.join(WALLET_DIR, ".solana-session");
|
|
9951
9958
|
async function createSolanaWallet() {
|
|
9952
9959
|
const { Keypair } = await loadSolanaWeb3("Solana wallet operations");
|
|
9953
|
-
const
|
|
9960
|
+
const bs582 = await import("bs58");
|
|
9954
9961
|
const keypair = Keypair.generate();
|
|
9955
9962
|
return {
|
|
9956
9963
|
address: keypair.publicKey.toBase58(),
|
|
9957
|
-
privateKey: (
|
|
9964
|
+
privateKey: (bs582.default ?? bs582).encode(keypair.secretKey)
|
|
9958
9965
|
};
|
|
9959
9966
|
}
|
|
9960
9967
|
async function solanaKeyToBytes(privateKey) {
|
|
@@ -9992,8 +9999,8 @@ async function solanaKeyToBytes(privateKey) {
|
|
|
9992
9999
|
return bytes;
|
|
9993
10000
|
}
|
|
9994
10001
|
try {
|
|
9995
|
-
const
|
|
9996
|
-
const bytes = (
|
|
10002
|
+
const bs582 = await import("bs58");
|
|
10003
|
+
const bytes = (bs582.default ?? bs582).decode(key);
|
|
9997
10004
|
if (bytes.length !== 64) {
|
|
9998
10005
|
throw new Error(`Invalid Solana key length: expected 64 bytes, got ${bytes.length}`);
|
|
9999
10006
|
}
|
|
@@ -10174,7 +10181,19 @@ async function getOrCreateSolanaWallet() {
|
|
|
10174
10181
|
|
|
10175
10182
|
// src/poll-ownership.ts
|
|
10176
10183
|
var import_crypto = require("crypto");
|
|
10184
|
+
|
|
10185
|
+
// src/bs58.ts
|
|
10177
10186
|
var import_bs58 = __toESM(require("bs58"), 1);
|
|
10187
|
+
function unwrapBs58(mod) {
|
|
10188
|
+
const m = mod;
|
|
10189
|
+
if (typeof m?.encode === "function") return m;
|
|
10190
|
+
const inner = m?.default;
|
|
10191
|
+
if (typeof inner?.encode === "function") return inner;
|
|
10192
|
+
throw new Error("bs58: no encode() on the module or its default export");
|
|
10193
|
+
}
|
|
10194
|
+
var bs58 = unwrapBs58(import_bs58.default);
|
|
10195
|
+
|
|
10196
|
+
// src/poll-ownership.ts
|
|
10178
10197
|
var POLL_AUTH_HEADERS = {
|
|
10179
10198
|
wallet: "x-poll-wallet",
|
|
10180
10199
|
timestamp: "x-poll-timestamp",
|
|
@@ -10206,9 +10225,9 @@ function signPollOwnership(secretKey, kind, jobId, nowMs = Date.now()) {
|
|
|
10206
10225
|
const timestampS = Math.floor(nowMs / 1e3);
|
|
10207
10226
|
const signature = (0, import_crypto.sign)(null, Buffer.from(pollAuthMessage(kind, jobId, timestampS), "utf8"), privateKey);
|
|
10208
10227
|
return {
|
|
10209
|
-
[POLL_AUTH_HEADERS.wallet]:
|
|
10228
|
+
[POLL_AUTH_HEADERS.wallet]: bs58.encode(publicKey),
|
|
10210
10229
|
[POLL_AUTH_HEADERS.timestamp]: String(timestampS),
|
|
10211
|
-
[POLL_AUTH_HEADERS.signature]:
|
|
10230
|
+
[POLL_AUTH_HEADERS.signature]: bs58.encode(signature)
|
|
10212
10231
|
};
|
|
10213
10232
|
}
|
|
10214
10233
|
|
|
@@ -10217,11 +10236,12 @@ var import_async_hooks = require("async_hooks");
|
|
|
10217
10236
|
var import_crypto2 = require("crypto");
|
|
10218
10237
|
var fs6 = __toESM(require("fs"), 1);
|
|
10219
10238
|
var path5 = __toESM(require("path"), 1);
|
|
10220
|
-
var import_bs582 = __toESM(require("bs58"), 1);
|
|
10221
10239
|
var BATCH_SCHEME = "batch-settlement";
|
|
10222
10240
|
var BLOCKRUN_SOL_OPERATOR = "5YKPQUFjw5WQqhSUkEGKNNfYYVqnRRNbpYyL71qQ1vm3";
|
|
10223
10241
|
var DEFAULT_BATCH_RATE_LIMIT = { maxAttempts: 3, maxWaitMs: 6e4 };
|
|
10224
10242
|
var DEFAULT_BATCH_IN_DOUBT = { maxWaitMs: 3e5 };
|
|
10243
|
+
var DEFAULT_BATCH_LOCK_WAIT_MS = 6e4;
|
|
10244
|
+
var LOCK_POLL_MS = 500;
|
|
10225
10245
|
var BatchPaymentUnresolvedError = class extends PaymentError {
|
|
10226
10246
|
/** The {@link SolanaBatchEvent.reason} of the `unresolved` event reported with it. */
|
|
10227
10247
|
reason;
|
|
@@ -10267,6 +10287,22 @@ var BatchCloseDeferredError = class extends BlockrunError {
|
|
|
10267
10287
|
this.channelIds = init.channelIds ?? [];
|
|
10268
10288
|
}
|
|
10269
10289
|
};
|
|
10290
|
+
var BatchChannelLockedError = class extends BlockrunError {
|
|
10291
|
+
/** The paying wallet's address. */
|
|
10292
|
+
wallet;
|
|
10293
|
+
/** The live owner's pid, when the SDK knows it. */
|
|
10294
|
+
ownerPid;
|
|
10295
|
+
/** How long this call waited for the lock, in ms (0 unless `onLocked` is `"wait"`). */
|
|
10296
|
+
waitedMs;
|
|
10297
|
+
constructor(init) {
|
|
10298
|
+
super(`batch-settlement unavailable for wallet ${init.wallet}: ${init.detail}`);
|
|
10299
|
+
this.name = "BatchChannelLockedError";
|
|
10300
|
+
this.wallet = init.wallet;
|
|
10301
|
+
if (init.ownerPid !== void 0) this.ownerPid = init.ownerPid;
|
|
10302
|
+
this.waitedMs = init.waitedMs;
|
|
10303
|
+
withDisposition(this, "unpaid");
|
|
10304
|
+
}
|
|
10305
|
+
};
|
|
10270
10306
|
var INSTALL_HINT2 = "npm install @x402/core@~2.28.0 @x402/svm@~2.28.0 @solana/kit";
|
|
10271
10307
|
async function load(pkg, importer) {
|
|
10272
10308
|
try {
|
|
@@ -10778,7 +10814,7 @@ function decodeChannelAccount(owner, data) {
|
|
|
10778
10814
|
return void 0;
|
|
10779
10815
|
}
|
|
10780
10816
|
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
10781
|
-
const key = (offset) =>
|
|
10817
|
+
const key = (offset) => bs58.encode(data.subarray(offset, offset + 32));
|
|
10782
10818
|
return {
|
|
10783
10819
|
deposit: view.getBigUint64(CHANNEL.deposit, true),
|
|
10784
10820
|
settled: view.getBigUint64(CHANNEL.settled, true),
|
|
@@ -11331,12 +11367,22 @@ var SolanaBatchPayer = class {
|
|
|
11331
11367
|
if (!Number.isFinite(this.inDoubtMaxWaitMs) || this.inDoubtMaxWaitMs < 0) {
|
|
11332
11368
|
throw new Error("batch.inDoubt.maxWaitMs must be a finite number of ms >= 0");
|
|
11333
11369
|
}
|
|
11370
|
+
this.onLocked = init.options.onLocked ?? "exact";
|
|
11371
|
+
if (this.onLocked !== "exact" && this.onLocked !== "wait" && this.onLocked !== "throw") {
|
|
11372
|
+
throw new Error('batch.onLocked must be "exact", "wait" or "throw"');
|
|
11373
|
+
}
|
|
11374
|
+
this.lockWaitMs = init.options.lockWaitMs ?? DEFAULT_BATCH_LOCK_WAIT_MS;
|
|
11375
|
+
if (!Number.isFinite(this.lockWaitMs) || this.lockWaitMs < 0) {
|
|
11376
|
+
throw new Error("batch.lockWaitMs must be a finite number of ms >= 0");
|
|
11377
|
+
}
|
|
11334
11378
|
}
|
|
11335
11379
|
init;
|
|
11336
11380
|
state;
|
|
11337
11381
|
maxAttempts;
|
|
11338
11382
|
maxWaitMs;
|
|
11339
11383
|
inDoubtMaxWaitMs;
|
|
11384
|
+
onLocked;
|
|
11385
|
+
lockWaitMs;
|
|
11340
11386
|
counters = {
|
|
11341
11387
|
fallbacks: 0,
|
|
11342
11388
|
fallbacksByReason: {},
|
|
@@ -11385,6 +11431,7 @@ var SolanaBatchPayer = class {
|
|
|
11385
11431
|
if (owner !== void 0) {
|
|
11386
11432
|
return {
|
|
11387
11433
|
reason: "channel_store_locked",
|
|
11434
|
+
ownerPid: owner,
|
|
11388
11435
|
detail: owner === process.pid ? `channel store ${file} is in use by another copy of @blockrun/llm in this process (or by a process that had this pid and died: remove ${file}.lock if nothing uses it)` : `channel store ${file} is in use by process ${owner}`
|
|
11389
11436
|
};
|
|
11390
11437
|
}
|
|
@@ -11730,12 +11777,23 @@ var SolanaBatchPayer = class {
|
|
|
11730
11777
|
const unavailable = batchUnavailable(paymentRequired);
|
|
11731
11778
|
if (unavailable) return this.fallback(unavailable);
|
|
11732
11779
|
let wallet;
|
|
11780
|
+
let waitedMs = 0;
|
|
11733
11781
|
try {
|
|
11734
11782
|
wallet = await this.wallet();
|
|
11783
|
+
if ("reason" in wallet && wallet.reason === "channel_store_locked" && this.onLocked === "wait") {
|
|
11784
|
+
const started = Date.now();
|
|
11785
|
+
wallet = await this.waitForLock(wallet);
|
|
11786
|
+
waitedMs = Date.now() - started;
|
|
11787
|
+
}
|
|
11735
11788
|
} catch (err) {
|
|
11736
11789
|
return this.fallback(creationFailure(err));
|
|
11737
11790
|
}
|
|
11738
|
-
if ("reason" in wallet)
|
|
11791
|
+
if ("reason" in wallet) {
|
|
11792
|
+
if (wallet.reason === "channel_store_locked" && this.onLocked !== "exact") {
|
|
11793
|
+
return this.lockedOut(wallet.detail, wallet.ownerPid, waitedMs);
|
|
11794
|
+
}
|
|
11795
|
+
return this.fallback({ reason: wallet.reason, detail: wallet.detail });
|
|
11796
|
+
}
|
|
11739
11797
|
if (closesAtStart !== void 0 && wallet.closes !== closesAtStart) {
|
|
11740
11798
|
return this.fallback({
|
|
11741
11799
|
reason: "closed_during_call",
|
|
@@ -11752,6 +11810,40 @@ var SolanaBatchPayer = class {
|
|
|
11752
11810
|
wallet.active -= 1;
|
|
11753
11811
|
}
|
|
11754
11812
|
}
|
|
11813
|
+
/**
|
|
11814
|
+
* `onLocked: "wait"`: try the wallet's channel store again every
|
|
11815
|
+
* {@link LOCK_POLL_MS} until its owner lets go of it or `lockWaitMs` runs
|
|
11816
|
+
* out. Reported once as a `backoff` event (`channel_store_locked`).
|
|
11817
|
+
*/
|
|
11818
|
+
async waitForLock(refusal) {
|
|
11819
|
+
const deadline = Date.now() + this.lockWaitMs;
|
|
11820
|
+
let current = refusal;
|
|
11821
|
+
if (this.lockWaitMs > 0) {
|
|
11822
|
+
await this.report({
|
|
11823
|
+
type: "backoff",
|
|
11824
|
+
reason: "channel_store_locked",
|
|
11825
|
+
retryAfterMs: this.lockWaitMs,
|
|
11826
|
+
detail: refusal.detail
|
|
11827
|
+
});
|
|
11828
|
+
}
|
|
11829
|
+
while ("reason" in current && current.reason === "channel_store_locked") {
|
|
11830
|
+
const left = deadline - Date.now();
|
|
11831
|
+
if (left <= 0) break;
|
|
11832
|
+
await sleep2(Math.min(LOCK_POLL_MS, left));
|
|
11833
|
+
current = await this.wallet();
|
|
11834
|
+
}
|
|
11835
|
+
return current;
|
|
11836
|
+
}
|
|
11837
|
+
/** `onLocked` other than `"exact"`: the call's `"unpaid"` error, nothing signed. */
|
|
11838
|
+
async lockedOut(detail, ownerPid, waitedMs) {
|
|
11839
|
+
const error = new BatchChannelLockedError({
|
|
11840
|
+
wallet: await this.init.address(),
|
|
11841
|
+
detail,
|
|
11842
|
+
waitedMs,
|
|
11843
|
+
...ownerPid !== void 0 ? { ownerPid } : {}
|
|
11844
|
+
});
|
|
11845
|
+
return { kind: "failed", error };
|
|
11846
|
+
}
|
|
11755
11847
|
/**
|
|
11756
11848
|
* The close fence for a call about to send its first request: how many
|
|
11757
11849
|
* closes this wallet has completed so far, to hand to {@link pay}.
|
|
@@ -11842,11 +11934,9 @@ var SolanaBatchPayer = class {
|
|
|
11842
11934
|
}
|
|
11843
11935
|
if (wallet.busy) return fallback({ reason: "channel_busy", attempt: budget.attempt });
|
|
11844
11936
|
if (wallet.file && !holdsChannelFile(wallet.file)) {
|
|
11845
|
-
|
|
11846
|
-
|
|
11847
|
-
|
|
11848
|
-
detail: `this process no longer holds the lock on ${wallet.file}; another owner may be paying into its channels`
|
|
11849
|
-
});
|
|
11937
|
+
const detail = `this process no longer holds the lock on ${wallet.file}; another owner may be paying into its channels`;
|
|
11938
|
+
if (this.onLocked !== "exact") return this.lockedOut(detail, void 0, 0);
|
|
11939
|
+
return fallback({ reason: "channel_store_locked", attempt: budget.attempt, detail });
|
|
11850
11940
|
}
|
|
11851
11941
|
wallet.busy = true;
|
|
11852
11942
|
holding = true;
|
|
@@ -12995,6 +13085,7 @@ var SolanaLLMClient = class {
|
|
|
12995
13085
|
searchParameters: options?.searchParameters,
|
|
12996
13086
|
responseFormat: options?.responseFormat,
|
|
12997
13087
|
stop: options?.stop,
|
|
13088
|
+
reasoningEffort: options?.reasoningEffort,
|
|
12998
13089
|
fallbackModels: options?.fallbackModels
|
|
12999
13090
|
});
|
|
13000
13091
|
return result.choices[0].message.content || "";
|
|
@@ -13023,6 +13114,7 @@ var SolanaLLMClient = class {
|
|
|
13023
13114
|
if (options?.toolChoice !== void 0) body.tool_choice = options.toolChoice;
|
|
13024
13115
|
if (options?.responseFormat !== void 0) body.response_format = options.responseFormat;
|
|
13025
13116
|
if (options?.stop !== void 0) body.stop = options.stop;
|
|
13117
|
+
if (options?.reasoningEffort !== void 0) body.reasoning_effort = options.reasoningEffort;
|
|
13026
13118
|
return body;
|
|
13027
13119
|
};
|
|
13028
13120
|
const chain = [model, ...options?.fallbackModels ?? []];
|
|
@@ -13127,6 +13219,7 @@ var SolanaLLMClient = class {
|
|
|
13127
13219
|
toolChoice: options.toolChoice,
|
|
13128
13220
|
responseFormat: options.responseFormat,
|
|
13129
13221
|
stop: options.stop,
|
|
13222
|
+
reasoningEffort: options.reasoningEffort,
|
|
13130
13223
|
timeout: options.timeout,
|
|
13131
13224
|
// An explicit caller-supplied chain wins over the routed one.
|
|
13132
13225
|
fallbackModels: options.fallbackModels ?? decision.fallbacks
|
|
@@ -14486,7 +14579,8 @@ var ChatCompletions = class {
|
|
|
14486
14579
|
tools: params.tools,
|
|
14487
14580
|
toolChoice: params.tool_choice,
|
|
14488
14581
|
responseFormat: params.response_format,
|
|
14489
|
-
stop: params.stop
|
|
14582
|
+
stop: params.stop,
|
|
14583
|
+
reasoningEffort: params.reasoning_effort
|
|
14490
14584
|
}
|
|
14491
14585
|
);
|
|
14492
14586
|
return this.transformResponse(response);
|
|
@@ -14502,7 +14596,8 @@ var ChatCompletions = class {
|
|
|
14502
14596
|
tools: params.tools,
|
|
14503
14597
|
toolChoice: params.tool_choice,
|
|
14504
14598
|
responseFormat: params.response_format,
|
|
14505
|
-
stop: params.stop
|
|
14599
|
+
stop: params.stop,
|
|
14600
|
+
reasoningEffort: params.reasoning_effort
|
|
14506
14601
|
}
|
|
14507
14602
|
);
|
|
14508
14603
|
return new StreamingResponse(response, params.model);
|
|
@@ -14701,11 +14796,13 @@ var AnthropicClient = class {
|
|
|
14701
14796
|
AnthropicClient,
|
|
14702
14797
|
BASE_CHAIN_ID,
|
|
14703
14798
|
BLOCKRUN_SOL_OPERATOR,
|
|
14799
|
+
BatchChannelLockedError,
|
|
14704
14800
|
BatchCloseDeferredError,
|
|
14705
14801
|
BatchPaymentUnresolvedError,
|
|
14706
14802
|
BlockrunClient,
|
|
14707
14803
|
BlockrunError,
|
|
14708
14804
|
DEFAULT_BATCH_IN_DOUBT,
|
|
14805
|
+
DEFAULT_BATCH_LOCK_WAIT_MS,
|
|
14709
14806
|
DEFAULT_BATCH_RATE_LIMIT,
|
|
14710
14807
|
EVM_NETWORKS,
|
|
14711
14808
|
ImageClient,
|
package/dist/index.d.cts
CHANGED
|
@@ -520,6 +520,12 @@ type ResponseFormat = {
|
|
|
520
520
|
type: "json_schema";
|
|
521
521
|
json_schema: Record<string, unknown>;
|
|
522
522
|
};
|
|
523
|
+
/**
|
|
524
|
+
* `reasoning_effort` values. The gateway passes the value through, and each
|
|
525
|
+
* model accepts its own subset; xhigh/max exist on a few (e.g. Reflection
|
|
526
|
+
* Beam, Z.ai GLM), none/minimal only on models that can stop reasoning.
|
|
527
|
+
*/
|
|
528
|
+
type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
523
529
|
interface ChatOptions {
|
|
524
530
|
/** System prompt */
|
|
525
531
|
system?: string;
|
|
@@ -537,6 +543,15 @@ interface ChatOptions {
|
|
|
537
543
|
responseFormat?: ResponseFormat;
|
|
538
544
|
/** Up to 4 stop sequences (forwarded natively / mapped to stop_sequences) */
|
|
539
545
|
stop?: string | string[];
|
|
546
|
+
/**
|
|
547
|
+
* Reasoning effort for reasoning models, sent as `reasoning_effort`. Omitted
|
|
548
|
+
* when unset, so the model's own default applies (some default to their
|
|
549
|
+
* HIGHEST effort, e.g. Reflection Beam defaults to "max"). Accepted values
|
|
550
|
+
* are per model; the gateway maps "none"/"minimal" to the lowest effort a
|
|
551
|
+
* model accepts when it cannot turn reasoning off. Reasoning tokens bill as
|
|
552
|
+
* output tokens.
|
|
553
|
+
*/
|
|
554
|
+
reasoningEffort?: ReasoningEffort;
|
|
540
555
|
/**
|
|
541
556
|
* Models to try in order if the primary returns a transient error
|
|
542
557
|
* (timeout, network, 5xx). 4xx and PaymentError still propagate
|
|
@@ -564,6 +579,15 @@ interface ChatCompletionOptions {
|
|
|
564
579
|
responseFormat?: ResponseFormat;
|
|
565
580
|
/** Up to 4 stop sequences (forwarded natively / mapped to stop_sequences) */
|
|
566
581
|
stop?: string | string[];
|
|
582
|
+
/**
|
|
583
|
+
* Reasoning effort for reasoning models, sent as `reasoning_effort`. Omitted
|
|
584
|
+
* when unset, so the model's own default applies (some default to their
|
|
585
|
+
* HIGHEST effort, e.g. Reflection Beam defaults to "max"). Accepted values
|
|
586
|
+
* are per model; the gateway maps "none"/"minimal" to the lowest effort a
|
|
587
|
+
* model accepts when it cannot turn reasoning off. Reasoning tokens bill as
|
|
588
|
+
* output tokens.
|
|
589
|
+
*/
|
|
590
|
+
reasoningEffort?: ReasoningEffort;
|
|
567
591
|
/**
|
|
568
592
|
* Models to try in order if the primary returns a transient error
|
|
569
593
|
* (timeout, network, 5xx). 4xx and PaymentError still propagate
|
|
@@ -2923,6 +2947,27 @@ interface SolanaBatchOptions {
|
|
|
2923
2947
|
* by scanning the chain for it.
|
|
2924
2948
|
*/
|
|
2925
2949
|
channelStore?: string | false;
|
|
2950
|
+
/**
|
|
2951
|
+
* What a call does when another live process owns this wallet's channel
|
|
2952
|
+
* store (`channel_store_locked`). One process per wallet pays with batch:
|
|
2953
|
+
* it holds the store's lock until it exits, so worker pools, PM2/cluster
|
|
2954
|
+
* workers or parallel runs on one wallet must each use their own wallet
|
|
2955
|
+
* (or route their calls through one process).
|
|
2956
|
+
* - `"exact"` (default): the call pays with `exact`, as before.
|
|
2957
|
+
* - `"wait"`: the call waits up to {@link lockWaitMs} for the lock (the
|
|
2958
|
+
* owner has to exit), then pays with batch, or raises
|
|
2959
|
+
* {@link BatchChannelLockedError} once the wait runs out.
|
|
2960
|
+
* - `"throw"`: the call raises {@link BatchChannelLockedError} at once.
|
|
2961
|
+
*
|
|
2962
|
+
* The error is raised before anything is signed, so it is `"unpaid"`:
|
|
2963
|
+
* `fallbackModels` (and `smartChat()`'s chain) may move on, and will meet
|
|
2964
|
+
* the same lock. A process that loses its lock to another owner raises it
|
|
2965
|
+
* too unless `onLocked` is `"exact"` (waiting cannot give it back).
|
|
2966
|
+
* Locks between clients of one process do not apply: they share a channel.
|
|
2967
|
+
*/
|
|
2968
|
+
onLocked?: "exact" | "wait" | "throw";
|
|
2969
|
+
/** Most time, in ms, one call waits for the lock under `onLocked: "wait"`. Default 60000. */
|
|
2970
|
+
lockWaitMs?: number;
|
|
2926
2971
|
/**
|
|
2927
2972
|
* How a call rides out an HTTP 429 (rate limited, or channel capacity
|
|
2928
2973
|
* exhausted) on a batch payment before it pays with `exact`. The call waits
|
|
@@ -2982,6 +3027,8 @@ declare const DEFAULT_BATCH_RATE_LIMIT: {
|
|
|
2982
3027
|
declare const DEFAULT_BATCH_IN_DOUBT: {
|
|
2983
3028
|
readonly maxWaitMs: 300000;
|
|
2984
3029
|
};
|
|
3030
|
+
/** Default {@link SolanaBatchOptions.lockWaitMs}. */
|
|
3031
|
+
declare const DEFAULT_BATCH_LOCK_WAIT_MS = 60000;
|
|
2985
3032
|
/**
|
|
2986
3033
|
* One observable batch-settlement event.
|
|
2987
3034
|
*
|
|
@@ -2996,7 +3043,10 @@ declare const DEFAULT_BATCH_IN_DOUBT: {
|
|
|
2996
3043
|
* (`reason: "rate_limited"`) or because another call for the wallet hit one
|
|
2997
3044
|
* (`reason: "cooldown"`), or before each replay of a payment in doubt that
|
|
2998
3045
|
* carries a payment identifier (`reason: "in_doubt"`, or `rate_limited`
|
|
2999
|
-
* after a 429), with the answer's `status` and the wait in `retryAfterMs
|
|
3046
|
+
* after a 429), with the answer's `status` and the wait in `retryAfterMs`;
|
|
3047
|
+
* or, once, when a call starts waiting up to `lockWaitMs` for another
|
|
3048
|
+
* process's channel store lock (`reason: "channel_store_locked"`,
|
|
3049
|
+
* `onLocked: "wait"`).
|
|
3000
3050
|
* - `recovered`: a call that backed off was then paid with batch (`reason:
|
|
3001
3051
|
* "in_doubt"` when the replay of a payment in doubt resolved it), or its
|
|
3002
3052
|
* fresh challenge after the wait was served without a payment (`reason:
|
|
@@ -3167,6 +3217,26 @@ declare class BatchCloseDeferredError extends BlockrunError {
|
|
|
3167
3217
|
detail: string;
|
|
3168
3218
|
});
|
|
3169
3219
|
}
|
|
3220
|
+
/**
|
|
3221
|
+
* Batch is on, another owner holds this wallet's channel store, and the
|
|
3222
|
+
* client's `batch.onLocked` is `"wait"` (the wait ran out) or `"throw"`.
|
|
3223
|
+
* Raised before anything is signed: nothing was paid for the call, and its
|
|
3224
|
+
* {@link RetryDisposition} is `"unpaid"`.
|
|
3225
|
+
*/
|
|
3226
|
+
declare class BatchChannelLockedError extends BlockrunError {
|
|
3227
|
+
/** The paying wallet's address. */
|
|
3228
|
+
readonly wallet: string;
|
|
3229
|
+
/** The live owner's pid, when the SDK knows it. */
|
|
3230
|
+
readonly ownerPid?: number;
|
|
3231
|
+
/** How long this call waited for the lock, in ms (0 unless `onLocked` is `"wait"`). */
|
|
3232
|
+
readonly waitedMs: number;
|
|
3233
|
+
constructor(init: {
|
|
3234
|
+
wallet: string;
|
|
3235
|
+
detail: string;
|
|
3236
|
+
ownerPid?: number;
|
|
3237
|
+
waitedMs: number;
|
|
3238
|
+
});
|
|
3239
|
+
}
|
|
3170
3240
|
/**
|
|
3171
3241
|
* The outcome of one batch attempt.
|
|
3172
3242
|
*
|
|
@@ -3270,6 +3340,8 @@ declare class SolanaBatchPayer {
|
|
|
3270
3340
|
private readonly maxAttempts;
|
|
3271
3341
|
private readonly maxWaitMs;
|
|
3272
3342
|
private readonly inDoubtMaxWaitMs;
|
|
3343
|
+
private readonly onLocked;
|
|
3344
|
+
private readonly lockWaitMs;
|
|
3273
3345
|
private readonly counters;
|
|
3274
3346
|
private readonly hooks;
|
|
3275
3347
|
constructor(init: SolanaBatchPayerInit);
|
|
@@ -3387,6 +3459,14 @@ declare class SolanaBatchPayer {
|
|
|
3387
3459
|
* open a channel the caller believes is closed.
|
|
3388
3460
|
*/
|
|
3389
3461
|
pay(paymentRequired: PaymentRequired, send: (headers: Record<string, string>) => Promise<Response>, rechallenge: () => Promise<Rechallenge>, closesAtStart?: number): Promise<BatchAttempt>;
|
|
3462
|
+
/**
|
|
3463
|
+
* `onLocked: "wait"`: try the wallet's channel store again every
|
|
3464
|
+
* {@link LOCK_POLL_MS} until its owner lets go of it or `lockWaitMs` runs
|
|
3465
|
+
* out. Reported once as a `backoff` event (`channel_store_locked`).
|
|
3466
|
+
*/
|
|
3467
|
+
private waitForLock;
|
|
3468
|
+
/** `onLocked` other than `"exact"`: the call's `"unpaid"` error, nothing signed. */
|
|
3469
|
+
private lockedOut;
|
|
3390
3470
|
/**
|
|
3391
3471
|
* The close fence for a call about to send its first request: how many
|
|
3392
3472
|
* closes this wallet has completed so far, to hand to {@link pay}.
|
|
@@ -4259,6 +4339,7 @@ interface OpenAIChatCompletionParams {
|
|
|
4259
4339
|
user?: string;
|
|
4260
4340
|
tools?: Tool[];
|
|
4261
4341
|
tool_choice?: ToolChoice;
|
|
4342
|
+
reasoning_effort?: ReasoningEffort;
|
|
4262
4343
|
}
|
|
4263
4344
|
interface OpenAIChatCompletionChoice {
|
|
4264
4345
|
index: number;
|
|
@@ -4490,4 +4571,4 @@ declare function readSettlement(response: Response, quotedUsd: number, scheme: S
|
|
|
4490
4571
|
settlement: Settlement;
|
|
4491
4572
|
};
|
|
4492
4573
|
|
|
4493
|
-
export { APIError, API_KEY_URL, ARC_CHAIN_ID, AnthropicClient, type AnyTool, type ApiKeyOptions, type AudioModel, type AudioTrack, BASE_CHAIN_ID, BLOCKRUN_SOL_OPERATOR, type BarResolution, type BatchAttempt, BatchCloseDeferredError, type BatchPayloadKind, BatchPaymentUnresolvedError, type BatchUnresolvedReason, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, DEFAULT_BATCH_IN_DOUBT, DEFAULT_BATCH_RATE_LIMIT, EVM_NETWORKS, type EvmNetwork, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTAL_URL, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type Rechallenge, type ResponseFormat, RetiredEndpointError, type RetryDisposition, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type Settlement, type SmartChatCompletionOptions, type SmartChatCompletionResponse, type SmartChatOptions, type SmartChatResponse, type SolanaBatchEvent, type SolanaBatchOptions, SolanaBatchPayer, type SolanaBatchPayerInit, type SolanaBatchStats, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_ARC, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, type UrlCitation, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type WebSearchTool, type X402ClientLike, type X402HookContext, type XSearchSource, type XSearchTool, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, evmNetwork, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, readSettlement, retryDisposition, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentClient, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, toWireSearchParameters, toWireTools, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|
|
4574
|
+
export { APIError, API_KEY_URL, ARC_CHAIN_ID, AnthropicClient, type AnyTool, type ApiKeyOptions, type AudioModel, type AudioTrack, BASE_CHAIN_ID, BLOCKRUN_SOL_OPERATOR, type BarResolution, type BatchAttempt, BatchChannelLockedError, BatchCloseDeferredError, type BatchPayloadKind, BatchPaymentUnresolvedError, type BatchUnresolvedReason, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, DEFAULT_BATCH_IN_DOUBT, DEFAULT_BATCH_LOCK_WAIT_MS, DEFAULT_BATCH_RATE_LIMIT, EVM_NETWORKS, type EvmNetwork, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTAL_URL, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type ReasoningEffort, type Rechallenge, type ResponseFormat, RetiredEndpointError, type RetryDisposition, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type Settlement, type SmartChatCompletionOptions, type SmartChatCompletionResponse, type SmartChatOptions, type SmartChatResponse, type SolanaBatchEvent, type SolanaBatchOptions, SolanaBatchPayer, type SolanaBatchPayerInit, type SolanaBatchStats, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_ARC, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, type UrlCitation, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type WebSearchTool, type X402ClientLike, type X402HookContext, type XSearchSource, type XSearchTool, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, evmNetwork, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, readSettlement, retryDisposition, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentClient, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, toWireSearchParameters, toWireTools, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|
package/dist/index.d.ts
CHANGED
|
@@ -520,6 +520,12 @@ type ResponseFormat = {
|
|
|
520
520
|
type: "json_schema";
|
|
521
521
|
json_schema: Record<string, unknown>;
|
|
522
522
|
};
|
|
523
|
+
/**
|
|
524
|
+
* `reasoning_effort` values. The gateway passes the value through, and each
|
|
525
|
+
* model accepts its own subset; xhigh/max exist on a few (e.g. Reflection
|
|
526
|
+
* Beam, Z.ai GLM), none/minimal only on models that can stop reasoning.
|
|
527
|
+
*/
|
|
528
|
+
type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
523
529
|
interface ChatOptions {
|
|
524
530
|
/** System prompt */
|
|
525
531
|
system?: string;
|
|
@@ -537,6 +543,15 @@ interface ChatOptions {
|
|
|
537
543
|
responseFormat?: ResponseFormat;
|
|
538
544
|
/** Up to 4 stop sequences (forwarded natively / mapped to stop_sequences) */
|
|
539
545
|
stop?: string | string[];
|
|
546
|
+
/**
|
|
547
|
+
* Reasoning effort for reasoning models, sent as `reasoning_effort`. Omitted
|
|
548
|
+
* when unset, so the model's own default applies (some default to their
|
|
549
|
+
* HIGHEST effort, e.g. Reflection Beam defaults to "max"). Accepted values
|
|
550
|
+
* are per model; the gateway maps "none"/"minimal" to the lowest effort a
|
|
551
|
+
* model accepts when it cannot turn reasoning off. Reasoning tokens bill as
|
|
552
|
+
* output tokens.
|
|
553
|
+
*/
|
|
554
|
+
reasoningEffort?: ReasoningEffort;
|
|
540
555
|
/**
|
|
541
556
|
* Models to try in order if the primary returns a transient error
|
|
542
557
|
* (timeout, network, 5xx). 4xx and PaymentError still propagate
|
|
@@ -564,6 +579,15 @@ interface ChatCompletionOptions {
|
|
|
564
579
|
responseFormat?: ResponseFormat;
|
|
565
580
|
/** Up to 4 stop sequences (forwarded natively / mapped to stop_sequences) */
|
|
566
581
|
stop?: string | string[];
|
|
582
|
+
/**
|
|
583
|
+
* Reasoning effort for reasoning models, sent as `reasoning_effort`. Omitted
|
|
584
|
+
* when unset, so the model's own default applies (some default to their
|
|
585
|
+
* HIGHEST effort, e.g. Reflection Beam defaults to "max"). Accepted values
|
|
586
|
+
* are per model; the gateway maps "none"/"minimal" to the lowest effort a
|
|
587
|
+
* model accepts when it cannot turn reasoning off. Reasoning tokens bill as
|
|
588
|
+
* output tokens.
|
|
589
|
+
*/
|
|
590
|
+
reasoningEffort?: ReasoningEffort;
|
|
567
591
|
/**
|
|
568
592
|
* Models to try in order if the primary returns a transient error
|
|
569
593
|
* (timeout, network, 5xx). 4xx and PaymentError still propagate
|
|
@@ -2923,6 +2947,27 @@ interface SolanaBatchOptions {
|
|
|
2923
2947
|
* by scanning the chain for it.
|
|
2924
2948
|
*/
|
|
2925
2949
|
channelStore?: string | false;
|
|
2950
|
+
/**
|
|
2951
|
+
* What a call does when another live process owns this wallet's channel
|
|
2952
|
+
* store (`channel_store_locked`). One process per wallet pays with batch:
|
|
2953
|
+
* it holds the store's lock until it exits, so worker pools, PM2/cluster
|
|
2954
|
+
* workers or parallel runs on one wallet must each use their own wallet
|
|
2955
|
+
* (or route their calls through one process).
|
|
2956
|
+
* - `"exact"` (default): the call pays with `exact`, as before.
|
|
2957
|
+
* - `"wait"`: the call waits up to {@link lockWaitMs} for the lock (the
|
|
2958
|
+
* owner has to exit), then pays with batch, or raises
|
|
2959
|
+
* {@link BatchChannelLockedError} once the wait runs out.
|
|
2960
|
+
* - `"throw"`: the call raises {@link BatchChannelLockedError} at once.
|
|
2961
|
+
*
|
|
2962
|
+
* The error is raised before anything is signed, so it is `"unpaid"`:
|
|
2963
|
+
* `fallbackModels` (and `smartChat()`'s chain) may move on, and will meet
|
|
2964
|
+
* the same lock. A process that loses its lock to another owner raises it
|
|
2965
|
+
* too unless `onLocked` is `"exact"` (waiting cannot give it back).
|
|
2966
|
+
* Locks between clients of one process do not apply: they share a channel.
|
|
2967
|
+
*/
|
|
2968
|
+
onLocked?: "exact" | "wait" | "throw";
|
|
2969
|
+
/** Most time, in ms, one call waits for the lock under `onLocked: "wait"`. Default 60000. */
|
|
2970
|
+
lockWaitMs?: number;
|
|
2926
2971
|
/**
|
|
2927
2972
|
* How a call rides out an HTTP 429 (rate limited, or channel capacity
|
|
2928
2973
|
* exhausted) on a batch payment before it pays with `exact`. The call waits
|
|
@@ -2982,6 +3027,8 @@ declare const DEFAULT_BATCH_RATE_LIMIT: {
|
|
|
2982
3027
|
declare const DEFAULT_BATCH_IN_DOUBT: {
|
|
2983
3028
|
readonly maxWaitMs: 300000;
|
|
2984
3029
|
};
|
|
3030
|
+
/** Default {@link SolanaBatchOptions.lockWaitMs}. */
|
|
3031
|
+
declare const DEFAULT_BATCH_LOCK_WAIT_MS = 60000;
|
|
2985
3032
|
/**
|
|
2986
3033
|
* One observable batch-settlement event.
|
|
2987
3034
|
*
|
|
@@ -2996,7 +3043,10 @@ declare const DEFAULT_BATCH_IN_DOUBT: {
|
|
|
2996
3043
|
* (`reason: "rate_limited"`) or because another call for the wallet hit one
|
|
2997
3044
|
* (`reason: "cooldown"`), or before each replay of a payment in doubt that
|
|
2998
3045
|
* carries a payment identifier (`reason: "in_doubt"`, or `rate_limited`
|
|
2999
|
-
* after a 429), with the answer's `status` and the wait in `retryAfterMs
|
|
3046
|
+
* after a 429), with the answer's `status` and the wait in `retryAfterMs`;
|
|
3047
|
+
* or, once, when a call starts waiting up to `lockWaitMs` for another
|
|
3048
|
+
* process's channel store lock (`reason: "channel_store_locked"`,
|
|
3049
|
+
* `onLocked: "wait"`).
|
|
3000
3050
|
* - `recovered`: a call that backed off was then paid with batch (`reason:
|
|
3001
3051
|
* "in_doubt"` when the replay of a payment in doubt resolved it), or its
|
|
3002
3052
|
* fresh challenge after the wait was served without a payment (`reason:
|
|
@@ -3167,6 +3217,26 @@ declare class BatchCloseDeferredError extends BlockrunError {
|
|
|
3167
3217
|
detail: string;
|
|
3168
3218
|
});
|
|
3169
3219
|
}
|
|
3220
|
+
/**
|
|
3221
|
+
* Batch is on, another owner holds this wallet's channel store, and the
|
|
3222
|
+
* client's `batch.onLocked` is `"wait"` (the wait ran out) or `"throw"`.
|
|
3223
|
+
* Raised before anything is signed: nothing was paid for the call, and its
|
|
3224
|
+
* {@link RetryDisposition} is `"unpaid"`.
|
|
3225
|
+
*/
|
|
3226
|
+
declare class BatchChannelLockedError extends BlockrunError {
|
|
3227
|
+
/** The paying wallet's address. */
|
|
3228
|
+
readonly wallet: string;
|
|
3229
|
+
/** The live owner's pid, when the SDK knows it. */
|
|
3230
|
+
readonly ownerPid?: number;
|
|
3231
|
+
/** How long this call waited for the lock, in ms (0 unless `onLocked` is `"wait"`). */
|
|
3232
|
+
readonly waitedMs: number;
|
|
3233
|
+
constructor(init: {
|
|
3234
|
+
wallet: string;
|
|
3235
|
+
detail: string;
|
|
3236
|
+
ownerPid?: number;
|
|
3237
|
+
waitedMs: number;
|
|
3238
|
+
});
|
|
3239
|
+
}
|
|
3170
3240
|
/**
|
|
3171
3241
|
* The outcome of one batch attempt.
|
|
3172
3242
|
*
|
|
@@ -3270,6 +3340,8 @@ declare class SolanaBatchPayer {
|
|
|
3270
3340
|
private readonly maxAttempts;
|
|
3271
3341
|
private readonly maxWaitMs;
|
|
3272
3342
|
private readonly inDoubtMaxWaitMs;
|
|
3343
|
+
private readonly onLocked;
|
|
3344
|
+
private readonly lockWaitMs;
|
|
3273
3345
|
private readonly counters;
|
|
3274
3346
|
private readonly hooks;
|
|
3275
3347
|
constructor(init: SolanaBatchPayerInit);
|
|
@@ -3387,6 +3459,14 @@ declare class SolanaBatchPayer {
|
|
|
3387
3459
|
* open a channel the caller believes is closed.
|
|
3388
3460
|
*/
|
|
3389
3461
|
pay(paymentRequired: PaymentRequired, send: (headers: Record<string, string>) => Promise<Response>, rechallenge: () => Promise<Rechallenge>, closesAtStart?: number): Promise<BatchAttempt>;
|
|
3462
|
+
/**
|
|
3463
|
+
* `onLocked: "wait"`: try the wallet's channel store again every
|
|
3464
|
+
* {@link LOCK_POLL_MS} until its owner lets go of it or `lockWaitMs` runs
|
|
3465
|
+
* out. Reported once as a `backoff` event (`channel_store_locked`).
|
|
3466
|
+
*/
|
|
3467
|
+
private waitForLock;
|
|
3468
|
+
/** `onLocked` other than `"exact"`: the call's `"unpaid"` error, nothing signed. */
|
|
3469
|
+
private lockedOut;
|
|
3390
3470
|
/**
|
|
3391
3471
|
* The close fence for a call about to send its first request: how many
|
|
3392
3472
|
* closes this wallet has completed so far, to hand to {@link pay}.
|
|
@@ -4259,6 +4339,7 @@ interface OpenAIChatCompletionParams {
|
|
|
4259
4339
|
user?: string;
|
|
4260
4340
|
tools?: Tool[];
|
|
4261
4341
|
tool_choice?: ToolChoice;
|
|
4342
|
+
reasoning_effort?: ReasoningEffort;
|
|
4262
4343
|
}
|
|
4263
4344
|
interface OpenAIChatCompletionChoice {
|
|
4264
4345
|
index: number;
|
|
@@ -4490,4 +4571,4 @@ declare function readSettlement(response: Response, quotedUsd: number, scheme: S
|
|
|
4490
4571
|
settlement: Settlement;
|
|
4491
4572
|
};
|
|
4492
4573
|
|
|
4493
|
-
export { APIError, API_KEY_URL, ARC_CHAIN_ID, AnthropicClient, type AnyTool, type ApiKeyOptions, type AudioModel, type AudioTrack, BASE_CHAIN_ID, BLOCKRUN_SOL_OPERATOR, type BarResolution, type BatchAttempt, BatchCloseDeferredError, type BatchPayloadKind, BatchPaymentUnresolvedError, type BatchUnresolvedReason, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, DEFAULT_BATCH_IN_DOUBT, DEFAULT_BATCH_RATE_LIMIT, EVM_NETWORKS, type EvmNetwork, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTAL_URL, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type Rechallenge, type ResponseFormat, RetiredEndpointError, type RetryDisposition, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type Settlement, type SmartChatCompletionOptions, type SmartChatCompletionResponse, type SmartChatOptions, type SmartChatResponse, type SolanaBatchEvent, type SolanaBatchOptions, SolanaBatchPayer, type SolanaBatchPayerInit, type SolanaBatchStats, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_ARC, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, type UrlCitation, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type WebSearchTool, type X402ClientLike, type X402HookContext, type XSearchSource, type XSearchTool, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, evmNetwork, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, readSettlement, retryDisposition, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentClient, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, toWireSearchParameters, toWireTools, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|
|
4574
|
+
export { APIError, API_KEY_URL, ARC_CHAIN_ID, AnthropicClient, type AnyTool, type ApiKeyOptions, type AudioModel, type AudioTrack, BASE_CHAIN_ID, BLOCKRUN_SOL_OPERATOR, type BarResolution, type BatchAttempt, BatchChannelLockedError, BatchCloseDeferredError, type BatchPayloadKind, BatchPaymentUnresolvedError, type BatchUnresolvedReason, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, DEFAULT_BATCH_IN_DOUBT, DEFAULT_BATCH_LOCK_WAIT_MS, DEFAULT_BATCH_RATE_LIMIT, EVM_NETWORKS, type EvmNetwork, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTAL_URL, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type ReasoningEffort, type Rechallenge, type ResponseFormat, RetiredEndpointError, type RetryDisposition, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type Settlement, type SmartChatCompletionOptions, type SmartChatCompletionResponse, type SmartChatOptions, type SmartChatResponse, type SolanaBatchEvent, type SolanaBatchOptions, SolanaBatchPayer, type SolanaBatchPayerInit, type SolanaBatchStats, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_ARC, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, type UrlCitation, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type WebSearchTool, type X402ClientLike, type X402HookContext, type XSearchSource, type XSearchTool, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, evmNetwork, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, readSettlement, retryDisposition, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentClient, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, toWireSearchParameters, toWireTools, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|
package/dist/index.js
CHANGED
|
@@ -4989,7 +4989,7 @@ function getCostSummary() {
|
|
|
4989
4989
|
}
|
|
4990
4990
|
|
|
4991
4991
|
// src/version.ts
|
|
4992
|
-
var SDK_VERSION = "3.
|
|
4992
|
+
var SDK_VERSION = "3.26.0";
|
|
4993
4993
|
var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
|
|
4994
4994
|
|
|
4995
4995
|
// src/client.ts
|
|
@@ -5118,6 +5118,7 @@ var LLMClient = class _LLMClient {
|
|
|
5118
5118
|
searchParameters: options?.searchParameters,
|
|
5119
5119
|
responseFormat: options?.responseFormat,
|
|
5120
5120
|
stop: options?.stop,
|
|
5121
|
+
reasoningEffort: options?.reasoningEffort,
|
|
5121
5122
|
fallbackModels: options?.fallbackModels
|
|
5122
5123
|
});
|
|
5123
5124
|
return result.choices[0].message.content || "";
|
|
@@ -5190,6 +5191,7 @@ var LLMClient = class _LLMClient {
|
|
|
5190
5191
|
searchParameters: options?.searchParameters,
|
|
5191
5192
|
responseFormat: options?.responseFormat,
|
|
5192
5193
|
stop: options?.stop,
|
|
5194
|
+
reasoningEffort: options?.reasoningEffort,
|
|
5193
5195
|
// An explicit caller-supplied chain wins over the routed one.
|
|
5194
5196
|
fallbackModels: options?.fallbackModels ?? decision.fallbacks
|
|
5195
5197
|
});
|
|
@@ -5227,6 +5229,7 @@ var LLMClient = class _LLMClient {
|
|
|
5227
5229
|
toolChoice: options.toolChoice,
|
|
5228
5230
|
responseFormat: options.responseFormat,
|
|
5229
5231
|
stop: options.stop,
|
|
5232
|
+
reasoningEffort: options.reasoningEffort,
|
|
5230
5233
|
timeout: options.timeout,
|
|
5231
5234
|
// An explicit caller-supplied chain wins over the routed one.
|
|
5232
5235
|
fallbackModels: options.fallbackModels ?? decision.fallbacks
|
|
@@ -5313,6 +5316,7 @@ var LLMClient = class _LLMClient {
|
|
|
5313
5316
|
if (options?.toolChoice !== void 0) body.tool_choice = options.toolChoice;
|
|
5314
5317
|
if (options?.responseFormat !== void 0) body.response_format = options.responseFormat;
|
|
5315
5318
|
if (options?.stop !== void 0) body.stop = options.stop;
|
|
5319
|
+
if (options?.reasoningEffort !== void 0) body.reasoning_effort = options.reasoningEffort;
|
|
5316
5320
|
return body;
|
|
5317
5321
|
};
|
|
5318
5322
|
const chain = [model, ...options?.fallbackModels ?? []];
|
|
@@ -5686,6 +5690,7 @@ var LLMClient = class _LLMClient {
|
|
|
5686
5690
|
if (options?.toolChoice !== void 0) body.tool_choice = options.toolChoice;
|
|
5687
5691
|
if (options?.responseFormat !== void 0) body.response_format = options.responseFormat;
|
|
5688
5692
|
if (options?.stop !== void 0) body.stop = options.stop;
|
|
5693
|
+
if (options?.reasoningEffort !== void 0) body.reasoning_effort = options.reasoningEffort;
|
|
5689
5694
|
const cacheKey2 = `/v1/chat/completions:${requestModel}`;
|
|
5690
5695
|
const requestBody = JSON.stringify(body);
|
|
5691
5696
|
const cached = this.preAuthCache.get(cacheKey2);
|
|
@@ -9819,11 +9824,11 @@ var WALLET_DIR = path4.join(os3.homedir(), ".blockrun");
|
|
|
9819
9824
|
var SOLANA_WALLET_FILE = path4.join(WALLET_DIR, ".solana-session");
|
|
9820
9825
|
async function createSolanaWallet() {
|
|
9821
9826
|
const { Keypair } = await loadSolanaWeb3("Solana wallet operations");
|
|
9822
|
-
const
|
|
9827
|
+
const bs582 = await import("bs58");
|
|
9823
9828
|
const keypair = Keypair.generate();
|
|
9824
9829
|
return {
|
|
9825
9830
|
address: keypair.publicKey.toBase58(),
|
|
9826
|
-
privateKey: (
|
|
9831
|
+
privateKey: (bs582.default ?? bs582).encode(keypair.secretKey)
|
|
9827
9832
|
};
|
|
9828
9833
|
}
|
|
9829
9834
|
async function solanaKeyToBytes(privateKey) {
|
|
@@ -9861,8 +9866,8 @@ async function solanaKeyToBytes(privateKey) {
|
|
|
9861
9866
|
return bytes;
|
|
9862
9867
|
}
|
|
9863
9868
|
try {
|
|
9864
|
-
const
|
|
9865
|
-
const bytes = (
|
|
9869
|
+
const bs582 = await import("bs58");
|
|
9870
|
+
const bytes = (bs582.default ?? bs582).decode(key);
|
|
9866
9871
|
if (bytes.length !== 64) {
|
|
9867
9872
|
throw new Error(`Invalid Solana key length: expected 64 bytes, got ${bytes.length}`);
|
|
9868
9873
|
}
|
|
@@ -10043,7 +10048,19 @@ async function getOrCreateSolanaWallet() {
|
|
|
10043
10048
|
|
|
10044
10049
|
// src/poll-ownership.ts
|
|
10045
10050
|
import { createPrivateKey, createPublicKey, sign as ed25519Sign } from "crypto";
|
|
10046
|
-
|
|
10051
|
+
|
|
10052
|
+
// src/bs58.ts
|
|
10053
|
+
import bs58Import from "bs58";
|
|
10054
|
+
function unwrapBs58(mod) {
|
|
10055
|
+
const m = mod;
|
|
10056
|
+
if (typeof m?.encode === "function") return m;
|
|
10057
|
+
const inner = m?.default;
|
|
10058
|
+
if (typeof inner?.encode === "function") return inner;
|
|
10059
|
+
throw new Error("bs58: no encode() on the module or its default export");
|
|
10060
|
+
}
|
|
10061
|
+
var bs58 = unwrapBs58(bs58Import);
|
|
10062
|
+
|
|
10063
|
+
// src/poll-ownership.ts
|
|
10047
10064
|
var POLL_AUTH_HEADERS = {
|
|
10048
10065
|
wallet: "x-poll-wallet",
|
|
10049
10066
|
timestamp: "x-poll-timestamp",
|
|
@@ -10086,11 +10103,12 @@ import { AsyncLocalStorage } from "async_hooks";
|
|
|
10086
10103
|
import { randomUUID } from "crypto";
|
|
10087
10104
|
import * as fs6 from "fs";
|
|
10088
10105
|
import * as path5 from "path";
|
|
10089
|
-
import bs582 from "bs58";
|
|
10090
10106
|
var BATCH_SCHEME = "batch-settlement";
|
|
10091
10107
|
var BLOCKRUN_SOL_OPERATOR = "5YKPQUFjw5WQqhSUkEGKNNfYYVqnRRNbpYyL71qQ1vm3";
|
|
10092
10108
|
var DEFAULT_BATCH_RATE_LIMIT = { maxAttempts: 3, maxWaitMs: 6e4 };
|
|
10093
10109
|
var DEFAULT_BATCH_IN_DOUBT = { maxWaitMs: 3e5 };
|
|
10110
|
+
var DEFAULT_BATCH_LOCK_WAIT_MS = 6e4;
|
|
10111
|
+
var LOCK_POLL_MS = 500;
|
|
10094
10112
|
var BatchPaymentUnresolvedError = class extends PaymentError {
|
|
10095
10113
|
/** The {@link SolanaBatchEvent.reason} of the `unresolved` event reported with it. */
|
|
10096
10114
|
reason;
|
|
@@ -10136,6 +10154,22 @@ var BatchCloseDeferredError = class extends BlockrunError {
|
|
|
10136
10154
|
this.channelIds = init.channelIds ?? [];
|
|
10137
10155
|
}
|
|
10138
10156
|
};
|
|
10157
|
+
var BatchChannelLockedError = class extends BlockrunError {
|
|
10158
|
+
/** The paying wallet's address. */
|
|
10159
|
+
wallet;
|
|
10160
|
+
/** The live owner's pid, when the SDK knows it. */
|
|
10161
|
+
ownerPid;
|
|
10162
|
+
/** How long this call waited for the lock, in ms (0 unless `onLocked` is `"wait"`). */
|
|
10163
|
+
waitedMs;
|
|
10164
|
+
constructor(init) {
|
|
10165
|
+
super(`batch-settlement unavailable for wallet ${init.wallet}: ${init.detail}`);
|
|
10166
|
+
this.name = "BatchChannelLockedError";
|
|
10167
|
+
this.wallet = init.wallet;
|
|
10168
|
+
if (init.ownerPid !== void 0) this.ownerPid = init.ownerPid;
|
|
10169
|
+
this.waitedMs = init.waitedMs;
|
|
10170
|
+
withDisposition(this, "unpaid");
|
|
10171
|
+
}
|
|
10172
|
+
};
|
|
10139
10173
|
var INSTALL_HINT2 = "npm install @x402/core@~2.28.0 @x402/svm@~2.28.0 @solana/kit";
|
|
10140
10174
|
async function load(pkg, importer) {
|
|
10141
10175
|
try {
|
|
@@ -10647,7 +10681,7 @@ function decodeChannelAccount(owner, data) {
|
|
|
10647
10681
|
return void 0;
|
|
10648
10682
|
}
|
|
10649
10683
|
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
10650
|
-
const key = (offset) =>
|
|
10684
|
+
const key = (offset) => bs58.encode(data.subarray(offset, offset + 32));
|
|
10651
10685
|
return {
|
|
10652
10686
|
deposit: view.getBigUint64(CHANNEL.deposit, true),
|
|
10653
10687
|
settled: view.getBigUint64(CHANNEL.settled, true),
|
|
@@ -11200,12 +11234,22 @@ var SolanaBatchPayer = class {
|
|
|
11200
11234
|
if (!Number.isFinite(this.inDoubtMaxWaitMs) || this.inDoubtMaxWaitMs < 0) {
|
|
11201
11235
|
throw new Error("batch.inDoubt.maxWaitMs must be a finite number of ms >= 0");
|
|
11202
11236
|
}
|
|
11237
|
+
this.onLocked = init.options.onLocked ?? "exact";
|
|
11238
|
+
if (this.onLocked !== "exact" && this.onLocked !== "wait" && this.onLocked !== "throw") {
|
|
11239
|
+
throw new Error('batch.onLocked must be "exact", "wait" or "throw"');
|
|
11240
|
+
}
|
|
11241
|
+
this.lockWaitMs = init.options.lockWaitMs ?? DEFAULT_BATCH_LOCK_WAIT_MS;
|
|
11242
|
+
if (!Number.isFinite(this.lockWaitMs) || this.lockWaitMs < 0) {
|
|
11243
|
+
throw new Error("batch.lockWaitMs must be a finite number of ms >= 0");
|
|
11244
|
+
}
|
|
11203
11245
|
}
|
|
11204
11246
|
init;
|
|
11205
11247
|
state;
|
|
11206
11248
|
maxAttempts;
|
|
11207
11249
|
maxWaitMs;
|
|
11208
11250
|
inDoubtMaxWaitMs;
|
|
11251
|
+
onLocked;
|
|
11252
|
+
lockWaitMs;
|
|
11209
11253
|
counters = {
|
|
11210
11254
|
fallbacks: 0,
|
|
11211
11255
|
fallbacksByReason: {},
|
|
@@ -11254,6 +11298,7 @@ var SolanaBatchPayer = class {
|
|
|
11254
11298
|
if (owner !== void 0) {
|
|
11255
11299
|
return {
|
|
11256
11300
|
reason: "channel_store_locked",
|
|
11301
|
+
ownerPid: owner,
|
|
11257
11302
|
detail: owner === process.pid ? `channel store ${file} is in use by another copy of @blockrun/llm in this process (or by a process that had this pid and died: remove ${file}.lock if nothing uses it)` : `channel store ${file} is in use by process ${owner}`
|
|
11258
11303
|
};
|
|
11259
11304
|
}
|
|
@@ -11599,12 +11644,23 @@ var SolanaBatchPayer = class {
|
|
|
11599
11644
|
const unavailable = batchUnavailable(paymentRequired);
|
|
11600
11645
|
if (unavailable) return this.fallback(unavailable);
|
|
11601
11646
|
let wallet;
|
|
11647
|
+
let waitedMs = 0;
|
|
11602
11648
|
try {
|
|
11603
11649
|
wallet = await this.wallet();
|
|
11650
|
+
if ("reason" in wallet && wallet.reason === "channel_store_locked" && this.onLocked === "wait") {
|
|
11651
|
+
const started = Date.now();
|
|
11652
|
+
wallet = await this.waitForLock(wallet);
|
|
11653
|
+
waitedMs = Date.now() - started;
|
|
11654
|
+
}
|
|
11604
11655
|
} catch (err) {
|
|
11605
11656
|
return this.fallback(creationFailure(err));
|
|
11606
11657
|
}
|
|
11607
|
-
if ("reason" in wallet)
|
|
11658
|
+
if ("reason" in wallet) {
|
|
11659
|
+
if (wallet.reason === "channel_store_locked" && this.onLocked !== "exact") {
|
|
11660
|
+
return this.lockedOut(wallet.detail, wallet.ownerPid, waitedMs);
|
|
11661
|
+
}
|
|
11662
|
+
return this.fallback({ reason: wallet.reason, detail: wallet.detail });
|
|
11663
|
+
}
|
|
11608
11664
|
if (closesAtStart !== void 0 && wallet.closes !== closesAtStart) {
|
|
11609
11665
|
return this.fallback({
|
|
11610
11666
|
reason: "closed_during_call",
|
|
@@ -11621,6 +11677,40 @@ var SolanaBatchPayer = class {
|
|
|
11621
11677
|
wallet.active -= 1;
|
|
11622
11678
|
}
|
|
11623
11679
|
}
|
|
11680
|
+
/**
|
|
11681
|
+
* `onLocked: "wait"`: try the wallet's channel store again every
|
|
11682
|
+
* {@link LOCK_POLL_MS} until its owner lets go of it or `lockWaitMs` runs
|
|
11683
|
+
* out. Reported once as a `backoff` event (`channel_store_locked`).
|
|
11684
|
+
*/
|
|
11685
|
+
async waitForLock(refusal) {
|
|
11686
|
+
const deadline = Date.now() + this.lockWaitMs;
|
|
11687
|
+
let current = refusal;
|
|
11688
|
+
if (this.lockWaitMs > 0) {
|
|
11689
|
+
await this.report({
|
|
11690
|
+
type: "backoff",
|
|
11691
|
+
reason: "channel_store_locked",
|
|
11692
|
+
retryAfterMs: this.lockWaitMs,
|
|
11693
|
+
detail: refusal.detail
|
|
11694
|
+
});
|
|
11695
|
+
}
|
|
11696
|
+
while ("reason" in current && current.reason === "channel_store_locked") {
|
|
11697
|
+
const left = deadline - Date.now();
|
|
11698
|
+
if (left <= 0) break;
|
|
11699
|
+
await sleep2(Math.min(LOCK_POLL_MS, left));
|
|
11700
|
+
current = await this.wallet();
|
|
11701
|
+
}
|
|
11702
|
+
return current;
|
|
11703
|
+
}
|
|
11704
|
+
/** `onLocked` other than `"exact"`: the call's `"unpaid"` error, nothing signed. */
|
|
11705
|
+
async lockedOut(detail, ownerPid, waitedMs) {
|
|
11706
|
+
const error = new BatchChannelLockedError({
|
|
11707
|
+
wallet: await this.init.address(),
|
|
11708
|
+
detail,
|
|
11709
|
+
waitedMs,
|
|
11710
|
+
...ownerPid !== void 0 ? { ownerPid } : {}
|
|
11711
|
+
});
|
|
11712
|
+
return { kind: "failed", error };
|
|
11713
|
+
}
|
|
11624
11714
|
/**
|
|
11625
11715
|
* The close fence for a call about to send its first request: how many
|
|
11626
11716
|
* closes this wallet has completed so far, to hand to {@link pay}.
|
|
@@ -11711,11 +11801,9 @@ var SolanaBatchPayer = class {
|
|
|
11711
11801
|
}
|
|
11712
11802
|
if (wallet.busy) return fallback({ reason: "channel_busy", attempt: budget.attempt });
|
|
11713
11803
|
if (wallet.file && !holdsChannelFile(wallet.file)) {
|
|
11714
|
-
|
|
11715
|
-
|
|
11716
|
-
|
|
11717
|
-
detail: `this process no longer holds the lock on ${wallet.file}; another owner may be paying into its channels`
|
|
11718
|
-
});
|
|
11804
|
+
const detail = `this process no longer holds the lock on ${wallet.file}; another owner may be paying into its channels`;
|
|
11805
|
+
if (this.onLocked !== "exact") return this.lockedOut(detail, void 0, 0);
|
|
11806
|
+
return fallback({ reason: "channel_store_locked", attempt: budget.attempt, detail });
|
|
11719
11807
|
}
|
|
11720
11808
|
wallet.busy = true;
|
|
11721
11809
|
holding = true;
|
|
@@ -12864,6 +12952,7 @@ var SolanaLLMClient = class {
|
|
|
12864
12952
|
searchParameters: options?.searchParameters,
|
|
12865
12953
|
responseFormat: options?.responseFormat,
|
|
12866
12954
|
stop: options?.stop,
|
|
12955
|
+
reasoningEffort: options?.reasoningEffort,
|
|
12867
12956
|
fallbackModels: options?.fallbackModels
|
|
12868
12957
|
});
|
|
12869
12958
|
return result.choices[0].message.content || "";
|
|
@@ -12892,6 +12981,7 @@ var SolanaLLMClient = class {
|
|
|
12892
12981
|
if (options?.toolChoice !== void 0) body.tool_choice = options.toolChoice;
|
|
12893
12982
|
if (options?.responseFormat !== void 0) body.response_format = options.responseFormat;
|
|
12894
12983
|
if (options?.stop !== void 0) body.stop = options.stop;
|
|
12984
|
+
if (options?.reasoningEffort !== void 0) body.reasoning_effort = options.reasoningEffort;
|
|
12895
12985
|
return body;
|
|
12896
12986
|
};
|
|
12897
12987
|
const chain = [model, ...options?.fallbackModels ?? []];
|
|
@@ -12996,6 +13086,7 @@ var SolanaLLMClient = class {
|
|
|
12996
13086
|
toolChoice: options.toolChoice,
|
|
12997
13087
|
responseFormat: options.responseFormat,
|
|
12998
13088
|
stop: options.stop,
|
|
13089
|
+
reasoningEffort: options.reasoningEffort,
|
|
12999
13090
|
timeout: options.timeout,
|
|
13000
13091
|
// An explicit caller-supplied chain wins over the routed one.
|
|
13001
13092
|
fallbackModels: options.fallbackModels ?? decision.fallbacks
|
|
@@ -14355,7 +14446,8 @@ var ChatCompletions = class {
|
|
|
14355
14446
|
tools: params.tools,
|
|
14356
14447
|
toolChoice: params.tool_choice,
|
|
14357
14448
|
responseFormat: params.response_format,
|
|
14358
|
-
stop: params.stop
|
|
14449
|
+
stop: params.stop,
|
|
14450
|
+
reasoningEffort: params.reasoning_effort
|
|
14359
14451
|
}
|
|
14360
14452
|
);
|
|
14361
14453
|
return this.transformResponse(response);
|
|
@@ -14371,7 +14463,8 @@ var ChatCompletions = class {
|
|
|
14371
14463
|
tools: params.tools,
|
|
14372
14464
|
toolChoice: params.tool_choice,
|
|
14373
14465
|
responseFormat: params.response_format,
|
|
14374
|
-
stop: params.stop
|
|
14466
|
+
stop: params.stop,
|
|
14467
|
+
reasoningEffort: params.reasoning_effort
|
|
14375
14468
|
}
|
|
14376
14469
|
);
|
|
14377
14470
|
return new StreamingResponse(response, params.model);
|
|
@@ -14569,11 +14662,13 @@ export {
|
|
|
14569
14662
|
AnthropicClient,
|
|
14570
14663
|
BASE_CHAIN_ID,
|
|
14571
14664
|
BLOCKRUN_SOL_OPERATOR,
|
|
14665
|
+
BatchChannelLockedError,
|
|
14572
14666
|
BatchCloseDeferredError,
|
|
14573
14667
|
BatchPaymentUnresolvedError,
|
|
14574
14668
|
BlockrunClient,
|
|
14575
14669
|
BlockrunError,
|
|
14576
14670
|
DEFAULT_BATCH_IN_DOUBT,
|
|
14671
|
+
DEFAULT_BATCH_LOCK_WAIT_MS,
|
|
14577
14672
|
DEFAULT_BATCH_RATE_LIMIT,
|
|
14578
14673
|
EVM_NETWORKS,
|
|
14579
14674
|
ImageClient,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockrun/llm",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.26.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "TypeScript SDK for BlockRun - every frontier model behind one OpenAI-compatible client. Pay with a BlockRun API key or per-call in USDC. Smart routing picks the cheapest capable model. No rate limits.",
|
|
6
6
|
"main": "dist/index.cjs",
|