@blockrun/llm 4.2.0 → 4.3.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 +119 -52
- package/dist/index.cjs +173 -10
- package/dist/index.d.cts +220 -2
- package/dist/index.d.ts +220 -2
- package/dist/index.js +170 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -36,11 +36,14 @@ __export(index_exports, {
|
|
|
36
36
|
AnthropicClient: () => AnthropicClient,
|
|
37
37
|
BASE_CHAIN_ID: () => BASE_CHAIN_ID,
|
|
38
38
|
BLOCKRUN_SOL_OPERATOR: () => BLOCKRUN_SOL_OPERATOR,
|
|
39
|
+
BatchChannelBusyError: () => BatchChannelBusyError,
|
|
39
40
|
BatchChannelLockedError: () => BatchChannelLockedError,
|
|
40
41
|
BatchCloseDeferredError: () => BatchCloseDeferredError,
|
|
41
42
|
BatchPaymentUnresolvedError: () => BatchPaymentUnresolvedError,
|
|
42
43
|
BlockrunClient: () => BlockrunClient,
|
|
43
44
|
BlockrunError: () => BlockrunError,
|
|
45
|
+
DECISIONS_DEFAULT_MODEL: () => DECISIONS_DEFAULT_MODEL,
|
|
46
|
+
DEFAULT_BATCH_BUSY_WAIT_MS: () => DEFAULT_BATCH_BUSY_WAIT_MS,
|
|
44
47
|
DEFAULT_BATCH_IN_DOUBT: () => DEFAULT_BATCH_IN_DOUBT,
|
|
45
48
|
DEFAULT_BATCH_LOCK_WAIT_MS: () => DEFAULT_BATCH_LOCK_WAIT_MS,
|
|
46
49
|
DEFAULT_BATCH_RATE_LIMIT: () => DEFAULT_BATCH_RATE_LIMIT,
|
|
@@ -731,6 +734,38 @@ function withCost(body, response, bookedUsd, scheme) {
|
|
|
731
734
|
return body;
|
|
732
735
|
}
|
|
733
736
|
|
|
737
|
+
// src/decisions.ts
|
|
738
|
+
var DECISIONS_DEFAULT_MODEL = "gpt-6-luna";
|
|
739
|
+
var QUESTION_TYPES = /* @__PURE__ */ new Set(["predicate", "choice", "score"]);
|
|
740
|
+
function invalid(message) {
|
|
741
|
+
throw withDisposition(new Error(`decisions: ${message}`), "unpaid");
|
|
742
|
+
}
|
|
743
|
+
function buildDecisionsBody(request) {
|
|
744
|
+
if (!request || typeof request !== "object") invalid("request must be an object");
|
|
745
|
+
const { input, questions } = request;
|
|
746
|
+
const emptyInput = typeof input === "string" ? input.length === 0 : !Array.isArray(input) || input.length === 0;
|
|
747
|
+
if (emptyInput) invalid("input must be a non-empty string or a non-empty array of messages");
|
|
748
|
+
if (!Array.isArray(questions) || questions.length === 0) invalid("questions must be a non-empty array");
|
|
749
|
+
const names = /* @__PURE__ */ new Set();
|
|
750
|
+
questions.forEach((q, i) => {
|
|
751
|
+
if (!q || typeof q !== "object") invalid(`questions[${i}] must be an object`);
|
|
752
|
+
if (!QUESTION_TYPES.has(q.type)) invalid(`questions[${i}].type must be "predicate", "choice" or "score"`);
|
|
753
|
+
if (typeof q.name !== "string" || q.name.length === 0) invalid(`questions[${i}].name must be a non-empty string`);
|
|
754
|
+
if (typeof q.instructions !== "string" || q.instructions.length === 0) {
|
|
755
|
+
invalid(`questions[${i}].instructions must be a non-empty string`);
|
|
756
|
+
}
|
|
757
|
+
if (names.has(q.name)) invalid(`questions[${i}].name "${q.name}" is used twice; answers are keyed by name`);
|
|
758
|
+
names.add(q.name);
|
|
759
|
+
if (q.type === "choice" && (!Array.isArray(q.choices) || q.choices.length === 0)) {
|
|
760
|
+
invalid(`questions[${i}] (choice) needs a non-empty choices array`);
|
|
761
|
+
}
|
|
762
|
+
if (q.type === "score" && (!Array.isArray(q.levels) || q.levels.length === 0)) {
|
|
763
|
+
invalid(`questions[${i}] (score) needs a non-empty levels array, lowest first`);
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
return { ...request, model: request.model ?? DECISIONS_DEFAULT_MODEL };
|
|
767
|
+
}
|
|
768
|
+
|
|
734
769
|
// src/client.ts
|
|
735
770
|
var import_accounts2 = require("viem/accounts");
|
|
736
771
|
|
|
@@ -5317,7 +5352,7 @@ function getCostSummary() {
|
|
|
5317
5352
|
}
|
|
5318
5353
|
|
|
5319
5354
|
// src/version.ts
|
|
5320
|
-
var SDK_VERSION = "4.
|
|
5355
|
+
var SDK_VERSION = "4.3.0";
|
|
5321
5356
|
var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
|
|
5322
5357
|
|
|
5323
5358
|
// src/client.ts
|
|
@@ -6537,6 +6572,34 @@ var LLMClient = class _LLMClient {
|
|
|
6537
6572
|
const data = await this.requestWithPaymentRaw("/v1/search", body);
|
|
6538
6573
|
return data;
|
|
6539
6574
|
}
|
|
6575
|
+
/**
|
|
6576
|
+
* Typed judgments (OpenAI Decisions-compatible, `gpt-6-luna`): send
|
|
6577
|
+
* evidence and questions with a fixed answer space, get one typed answer
|
|
6578
|
+
* per question instead of text.
|
|
6579
|
+
*
|
|
6580
|
+
* Priced on input tokens only. With a wallet the 402 quotes an upper-bound
|
|
6581
|
+
* estimate of them plus the $0.001 transaction fee, and that quote settles;
|
|
6582
|
+
* with an API key the account is billed on the tokens the provider reports.
|
|
6583
|
+
* A request over the gateway's limits is refused with a 400 before payment.
|
|
6584
|
+
*
|
|
6585
|
+
* A `choice` always picks one of your values, so give it a `none` value for
|
|
6586
|
+
* inputs that fit nothing.
|
|
6587
|
+
*
|
|
6588
|
+
* @example
|
|
6589
|
+
* const { answers } = await client.decisions({
|
|
6590
|
+
* input: 'My card was charged twice for one order.',
|
|
6591
|
+
* questions: [
|
|
6592
|
+
* { type: 'predicate', name: 'urgent', instructions: 'Does this need a reply today?' },
|
|
6593
|
+
* { type: 'choice', name: 'team', instructions: 'Which team owns this?',
|
|
6594
|
+
* choices: [{ value: 'billing' }, { value: 'shipping' }, { value: 'none' }] },
|
|
6595
|
+
* ],
|
|
6596
|
+
* });
|
|
6597
|
+
*/
|
|
6598
|
+
async decisions(request) {
|
|
6599
|
+
const body = buildDecisionsBody(request);
|
|
6600
|
+
const response = await this.requestWithPayment("/v1/decisions", body);
|
|
6601
|
+
return response;
|
|
6602
|
+
}
|
|
6540
6603
|
/**
|
|
6541
6604
|
* Generic Exa endpoint proxy (POST). Useful when you need an Exa API
|
|
6542
6605
|
* surface that the typed wrappers below don't expose.
|
|
@@ -8927,7 +8990,9 @@ var PriceClient = class {
|
|
|
8927
8990
|
assetType: data.assetType,
|
|
8928
8991
|
category: data.category,
|
|
8929
8992
|
source: data.source,
|
|
8930
|
-
free: data.free
|
|
8993
|
+
free: data.free,
|
|
8994
|
+
realtime: data.realtime,
|
|
8995
|
+
note: data.note
|
|
8931
8996
|
};
|
|
8932
8997
|
}
|
|
8933
8998
|
async history(category, symbol, options) {
|
|
@@ -10585,6 +10650,8 @@ var DEFAULT_BATCH_RATE_LIMIT = { maxAttempts: 3, maxWaitMs: 6e4 };
|
|
|
10585
10650
|
var DEFAULT_BATCH_IN_DOUBT = { maxWaitMs: 3e5 };
|
|
10586
10651
|
var DEFAULT_BATCH_LOCK_WAIT_MS = 6e4;
|
|
10587
10652
|
var LOCK_POLL_MS = 500;
|
|
10653
|
+
var DEFAULT_BATCH_BUSY_WAIT_MS = 6e4;
|
|
10654
|
+
var BUSY_POLL_MS = 100;
|
|
10588
10655
|
var BatchPaymentUnresolvedError = class extends PaymentError {
|
|
10589
10656
|
/** The {@link SolanaBatchEvent.reason} of the `unresolved` event reported with it. */
|
|
10590
10657
|
reason;
|
|
@@ -10646,6 +10713,21 @@ var BatchChannelLockedError = class extends BlockrunError {
|
|
|
10646
10713
|
withDisposition(this, "unpaid");
|
|
10647
10714
|
}
|
|
10648
10715
|
};
|
|
10716
|
+
var BatchChannelBusyError = class extends BlockrunError {
|
|
10717
|
+
/** The paying wallet's address. */
|
|
10718
|
+
wallet;
|
|
10719
|
+
/** How long this call waited for the wallet, in ms (0 unless `onBusy` is `"wait"`). */
|
|
10720
|
+
waitedMs;
|
|
10721
|
+
constructor(init) {
|
|
10722
|
+
super(
|
|
10723
|
+
`batch-settlement busy for wallet ${init.wallet}: another batch call is in flight` + (init.waitedMs > 0 ? ` (waited ${init.waitedMs} ms)` : "")
|
|
10724
|
+
);
|
|
10725
|
+
this.name = "BatchChannelBusyError";
|
|
10726
|
+
this.wallet = init.wallet;
|
|
10727
|
+
this.waitedMs = init.waitedMs;
|
|
10728
|
+
withDisposition(this, "unpaid");
|
|
10729
|
+
}
|
|
10730
|
+
};
|
|
10649
10731
|
var INSTALL_HINT2 = "npm install @x402/core@~2.30.0 @x402/svm@~2.30.0 @solana/kit@^8";
|
|
10650
10732
|
async function load(pkg, importer) {
|
|
10651
10733
|
try {
|
|
@@ -10825,20 +10907,20 @@ var FileIntentJournal = class _FileIntentJournal {
|
|
|
10825
10907
|
if (err.code === "ENOENT") return {};
|
|
10826
10908
|
throw err;
|
|
10827
10909
|
}
|
|
10828
|
-
const
|
|
10910
|
+
const invalid2 = (why) => new Error(`deposit-intent journal ${this.file} is not valid (${why})`);
|
|
10829
10911
|
let parsed;
|
|
10830
10912
|
try {
|
|
10831
10913
|
parsed = JSON.parse(text);
|
|
10832
10914
|
} catch (err) {
|
|
10833
|
-
throw
|
|
10915
|
+
throw invalid2(err instanceof Error ? err.message : String(err));
|
|
10834
10916
|
}
|
|
10835
|
-
if (!isPlainObject(parsed)) throw
|
|
10836
|
-
if (parsed.version !== 1) throw
|
|
10917
|
+
if (!isPlainObject(parsed)) throw invalid2("not a JSON object");
|
|
10918
|
+
if (parsed.version !== 1) throw invalid2(`unsupported version ${JSON.stringify(parsed.version)}`);
|
|
10837
10919
|
const { intents } = parsed;
|
|
10838
|
-
if (!isPlainObject(intents)) throw
|
|
10920
|
+
if (!isPlainObject(intents)) throw invalid2("intents is not an object");
|
|
10839
10921
|
for (const [key, intent] of Object.entries(intents)) {
|
|
10840
10922
|
const why = intentProblem(key, intent);
|
|
10841
|
-
if (why) throw
|
|
10923
|
+
if (why) throw invalid2(`intent ${JSON.stringify(key)}: ${why}`);
|
|
10842
10924
|
}
|
|
10843
10925
|
return intents;
|
|
10844
10926
|
}
|
|
@@ -11718,6 +11800,14 @@ var SolanaBatchPayer = class {
|
|
|
11718
11800
|
if (!Number.isFinite(this.lockWaitMs) || this.lockWaitMs < 0) {
|
|
11719
11801
|
throw new Error("batch.lockWaitMs must be a finite number of ms >= 0");
|
|
11720
11802
|
}
|
|
11803
|
+
this.onBusy = init.options.onBusy ?? "exact";
|
|
11804
|
+
if (this.onBusy !== "exact" && this.onBusy !== "wait" && this.onBusy !== "throw") {
|
|
11805
|
+
throw new Error('batch.onBusy must be "exact", "wait" or "throw"');
|
|
11806
|
+
}
|
|
11807
|
+
this.busyWaitMs = init.options.busyWaitMs ?? DEFAULT_BATCH_BUSY_WAIT_MS;
|
|
11808
|
+
if (!Number.isFinite(this.busyWaitMs) || this.busyWaitMs < 0) {
|
|
11809
|
+
throw new Error("batch.busyWaitMs must be a finite number of ms >= 0");
|
|
11810
|
+
}
|
|
11721
11811
|
}
|
|
11722
11812
|
init;
|
|
11723
11813
|
state;
|
|
@@ -11726,6 +11816,8 @@ var SolanaBatchPayer = class {
|
|
|
11726
11816
|
inDoubtMaxWaitMs;
|
|
11727
11817
|
onLocked;
|
|
11728
11818
|
lockWaitMs;
|
|
11819
|
+
onBusy;
|
|
11820
|
+
busyWaitMs;
|
|
11729
11821
|
counters = {
|
|
11730
11822
|
fallbacks: 0,
|
|
11731
11823
|
fallbacksByReason: {},
|
|
@@ -12187,6 +12279,22 @@ var SolanaBatchPayer = class {
|
|
|
12187
12279
|
});
|
|
12188
12280
|
return { kind: "failed", error };
|
|
12189
12281
|
}
|
|
12282
|
+
/**
|
|
12283
|
+
* `onBusy: "wait"`: look at the wallet every {@link BUSY_POLL_MS} until no
|
|
12284
|
+
* batch call holds it or `deadline` passes. True when it is free.
|
|
12285
|
+
*/
|
|
12286
|
+
async waitWhileBusy(wallet, deadline) {
|
|
12287
|
+
while (wallet.busy) {
|
|
12288
|
+
const left = deadline - Date.now();
|
|
12289
|
+
if (left <= 0) return false;
|
|
12290
|
+
await sleep2(Math.min(BUSY_POLL_MS, left));
|
|
12291
|
+
}
|
|
12292
|
+
return true;
|
|
12293
|
+
}
|
|
12294
|
+
/** `onBusy` other than `"exact"`: the call's `"unpaid"` error, nothing signed. */
|
|
12295
|
+
async busyOut(waitedMs) {
|
|
12296
|
+
return { kind: "failed", error: new BatchChannelBusyError({ wallet: await this.init.address(), waitedMs }) };
|
|
12297
|
+
}
|
|
12190
12298
|
/**
|
|
12191
12299
|
* The close fence for a call about to send its first request: how many
|
|
12192
12300
|
* closes this wallet has completed so far, to hand to {@link pay}.
|
|
@@ -12212,6 +12320,8 @@ var SolanaBatchPayer = class {
|
|
|
12212
12320
|
const budget = { attempt: 1, waited: 0 };
|
|
12213
12321
|
let waitedUntil = 0;
|
|
12214
12322
|
let backedOff;
|
|
12323
|
+
let busySince;
|
|
12324
|
+
let rechallengeAfterBusy = false;
|
|
12215
12325
|
let holding = false;
|
|
12216
12326
|
let sent;
|
|
12217
12327
|
const release = () => {
|
|
@@ -12247,7 +12357,8 @@ var SolanaBatchPayer = class {
|
|
|
12247
12357
|
await sleep2(wait);
|
|
12248
12358
|
continue;
|
|
12249
12359
|
}
|
|
12250
|
-
if (budget.attempt > 1 || budget.waited > 0) {
|
|
12360
|
+
if (budget.attempt > 1 || budget.waited > 0 || rechallengeAfterBusy) {
|
|
12361
|
+
rechallengeAfterBusy = false;
|
|
12251
12362
|
let fresh;
|
|
12252
12363
|
try {
|
|
12253
12364
|
fresh = await rechallenge();
|
|
@@ -12275,7 +12386,28 @@ var SolanaBatchPayer = class {
|
|
|
12275
12386
|
detail: "closeBatchChannel() closed this wallet's channel after this call started; it opens no channel"
|
|
12276
12387
|
});
|
|
12277
12388
|
}
|
|
12278
|
-
if (wallet.busy)
|
|
12389
|
+
if (wallet.busy) {
|
|
12390
|
+
if (this.onBusy === "exact") return fallback({ reason: "channel_busy", attempt: budget.attempt });
|
|
12391
|
+
const waited = busySince === void 0 ? 0 : Date.now() - busySince;
|
|
12392
|
+
if (this.onBusy === "throw") return this.busyOut(waited);
|
|
12393
|
+
if (busySince === void 0) {
|
|
12394
|
+
busySince = Date.now();
|
|
12395
|
+
if (this.busyWaitMs > 0) {
|
|
12396
|
+
await this.report({
|
|
12397
|
+
type: "backoff",
|
|
12398
|
+
reason: "channel_busy",
|
|
12399
|
+
retryAfterMs: this.busyWaitMs,
|
|
12400
|
+
attempt: budget.attempt,
|
|
12401
|
+
detail: 'another batch call for this wallet is in flight; waiting for it (onBusy: "wait")'
|
|
12402
|
+
});
|
|
12403
|
+
}
|
|
12404
|
+
}
|
|
12405
|
+
if (!await this.waitWhileBusy(wallet, busySince + this.busyWaitMs)) {
|
|
12406
|
+
return this.busyOut(Date.now() - busySince);
|
|
12407
|
+
}
|
|
12408
|
+
rechallengeAfterBusy = true;
|
|
12409
|
+
continue;
|
|
12410
|
+
}
|
|
12279
12411
|
if (wallet.file && !holdsChannelFile(wallet.file)) {
|
|
12280
12412
|
const detail = `this process no longer holds the lock on ${wallet.file}; another owner may be paying into its channels`;
|
|
12281
12413
|
if (this.onLocked !== "exact") return this.lockedOut(detail, void 0, 0);
|
|
@@ -13900,6 +14032,22 @@ var SolanaLLMClient = class {
|
|
|
13900
14032
|
const data = await this.requestWithPaymentRaw("/v1/search", body);
|
|
13901
14033
|
return data;
|
|
13902
14034
|
}
|
|
14035
|
+
/**
|
|
14036
|
+
* Typed judgments (OpenAI Decisions-compatible, `gpt-6-luna`), paid on
|
|
14037
|
+
* Solana: one typed answer per question instead of text. See
|
|
14038
|
+
* {@link LLMClient.decisions} for the request shape.
|
|
14039
|
+
*
|
|
14040
|
+
* Under `exact` the 402's quote settles (an upper-bound estimate of the
|
|
14041
|
+
* input tokens plus the $0.001 fee). With the `batch` option the call pays
|
|
14042
|
+
* with a channel voucher and is charged the input tokens the provider
|
|
14043
|
+
* reports, with no per-call fee; `costUsd` is that metered charge. It shares
|
|
14044
|
+
* the wallet's channel with chat, one batch call at a time.
|
|
14045
|
+
*/
|
|
14046
|
+
async decisions(request) {
|
|
14047
|
+
const body = buildDecisionsBody(request);
|
|
14048
|
+
const response = await this.requestWithPayment("/v1/decisions", body);
|
|
14049
|
+
return response;
|
|
14050
|
+
}
|
|
13903
14051
|
// ── Prediction Markets (Powered by Predexon) ────────────────────────────
|
|
13904
14052
|
async pm(path7, params) {
|
|
13905
14053
|
return this.getWithPaymentRaw(`/v1/pm/${path7}`, params);
|
|
@@ -15063,8 +15211,19 @@ var Chat = class {
|
|
|
15063
15211
|
this.completions = new ChatCompletions(client, apiUrl, timeout);
|
|
15064
15212
|
}
|
|
15065
15213
|
};
|
|
15214
|
+
var Decisions = class {
|
|
15215
|
+
constructor(client) {
|
|
15216
|
+
this.client = client;
|
|
15217
|
+
}
|
|
15218
|
+
client;
|
|
15219
|
+
/** Same as {@link LLMClient.decisions}. */
|
|
15220
|
+
async create(params) {
|
|
15221
|
+
return this.client.decisions(params);
|
|
15222
|
+
}
|
|
15223
|
+
};
|
|
15066
15224
|
var OpenAI = class {
|
|
15067
15225
|
chat;
|
|
15226
|
+
decisions;
|
|
15068
15227
|
get authMode() {
|
|
15069
15228
|
return this.client.authMode;
|
|
15070
15229
|
}
|
|
@@ -15081,6 +15240,7 @@ var OpenAI = class {
|
|
|
15081
15240
|
timeout
|
|
15082
15241
|
});
|
|
15083
15242
|
this.chat = new Chat(this.client, apiUrl, timeout);
|
|
15243
|
+
this.decisions = new Decisions(this.client);
|
|
15084
15244
|
}
|
|
15085
15245
|
/**
|
|
15086
15246
|
* Get the wallet address being used for payments.
|
|
@@ -15229,11 +15389,14 @@ var AnthropicClient = class {
|
|
|
15229
15389
|
AnthropicClient,
|
|
15230
15390
|
BASE_CHAIN_ID,
|
|
15231
15391
|
BLOCKRUN_SOL_OPERATOR,
|
|
15392
|
+
BatchChannelBusyError,
|
|
15232
15393
|
BatchChannelLockedError,
|
|
15233
15394
|
BatchCloseDeferredError,
|
|
15234
15395
|
BatchPaymentUnresolvedError,
|
|
15235
15396
|
BlockrunClient,
|
|
15236
15397
|
BlockrunError,
|
|
15398
|
+
DECISIONS_DEFAULT_MODEL,
|
|
15399
|
+
DEFAULT_BATCH_BUSY_WAIT_MS,
|
|
15237
15400
|
DEFAULT_BATCH_IN_DOUBT,
|
|
15238
15401
|
DEFAULT_BATCH_LOCK_WAIT_MS,
|
|
15239
15402
|
DEFAULT_BATCH_RATE_LIMIT,
|
package/dist/index.d.cts
CHANGED
|
@@ -657,6 +657,107 @@ interface SearchResult {
|
|
|
657
657
|
sources_used?: number;
|
|
658
658
|
model?: string;
|
|
659
659
|
}
|
|
660
|
+
/** One value a `choice` question may answer with. */
|
|
661
|
+
interface DecisionChoice {
|
|
662
|
+
value: string;
|
|
663
|
+
description?: string;
|
|
664
|
+
}
|
|
665
|
+
/** One rung of a `score` rubric. Levels are listed lowest first. */
|
|
666
|
+
interface DecisionLevel {
|
|
667
|
+
label: string;
|
|
668
|
+
description?: string;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* A question with a fixed answer space. `name` keys the answer; `instructions`
|
|
672
|
+
* is what the model judges. Extra fields are forwarded as given.
|
|
673
|
+
*/
|
|
674
|
+
type DecisionQuestion = {
|
|
675
|
+
type: "predicate";
|
|
676
|
+
name: string;
|
|
677
|
+
instructions: string;
|
|
678
|
+
[k: string]: unknown;
|
|
679
|
+
} | {
|
|
680
|
+
type: "choice";
|
|
681
|
+
name: string;
|
|
682
|
+
instructions: string;
|
|
683
|
+
choices: DecisionChoice[];
|
|
684
|
+
[k: string]: unknown;
|
|
685
|
+
} | {
|
|
686
|
+
type: "score";
|
|
687
|
+
name: string;
|
|
688
|
+
instructions: string;
|
|
689
|
+
levels: DecisionLevel[];
|
|
690
|
+
[k: string]: unknown;
|
|
691
|
+
};
|
|
692
|
+
/** A message of {@link DecisionsRequest.input}: text parts and inline `data:image/*` images. */
|
|
693
|
+
interface DecisionInputMessage {
|
|
694
|
+
role: string;
|
|
695
|
+
content: unknown;
|
|
696
|
+
}
|
|
697
|
+
interface DecisionsRequest {
|
|
698
|
+
/** `"gpt-6-luna"` (the default), `"openai/gpt-6-luna"` or `"openai/gpt-6-luna-decisions"`. */
|
|
699
|
+
model?: string;
|
|
700
|
+
/** The evidence: a string, or messages whose content holds text and inline base64 images (no hosted URLs). */
|
|
701
|
+
input: string | DecisionInputMessage[];
|
|
702
|
+
/** Up to 64 questions, one typed answer each. */
|
|
703
|
+
questions: DecisionQuestion[];
|
|
704
|
+
/** Forwarded to the provider and billed as input. */
|
|
705
|
+
metadata?: Record<string, string>;
|
|
706
|
+
}
|
|
707
|
+
/** The answer to one question, keyed by the question's `name`. */
|
|
708
|
+
type DecisionAnswer = {
|
|
709
|
+
type: "predicate";
|
|
710
|
+
name: string;
|
|
711
|
+
probability: number;
|
|
712
|
+
[k: string]: unknown;
|
|
713
|
+
} | {
|
|
714
|
+
type: "choice";
|
|
715
|
+
name: string;
|
|
716
|
+
/** One of the question's `choices[].value`, always: give the question a `none` value for inputs that fit nothing. */
|
|
717
|
+
choice: string;
|
|
718
|
+
/** One entry per choice, in the order given. */
|
|
719
|
+
probabilities: Array<{
|
|
720
|
+
value: string;
|
|
721
|
+
probability: number;
|
|
722
|
+
}>;
|
|
723
|
+
confidence: number;
|
|
724
|
+
[k: string]: unknown;
|
|
725
|
+
} | {
|
|
726
|
+
type: "score";
|
|
727
|
+
name: string;
|
|
728
|
+
/** Probability-weighted position on the rubric (0 = the first level). */
|
|
729
|
+
score: number;
|
|
730
|
+
/** One entry per level, lowest first; `value` is the level's index. */
|
|
731
|
+
probabilities: Array<{
|
|
732
|
+
value: number;
|
|
733
|
+
label: string;
|
|
734
|
+
probability: number;
|
|
735
|
+
}>;
|
|
736
|
+
confidence: number;
|
|
737
|
+
[k: string]: unknown;
|
|
738
|
+
};
|
|
739
|
+
interface DecisionsResponse {
|
|
740
|
+
/** BlockRun's id for the call (`decision_<hex>`), when the gateway returns one. */
|
|
741
|
+
id?: string;
|
|
742
|
+
model: string;
|
|
743
|
+
[k: string]: unknown;
|
|
744
|
+
/** One answer per question, in the order asked. */
|
|
745
|
+
answers: DecisionAnswer[];
|
|
746
|
+
/** Only input tokens are billed; `output_tokens` is 0. */
|
|
747
|
+
usage?: {
|
|
748
|
+
input_tokens: number;
|
|
749
|
+
output_tokens: number;
|
|
750
|
+
total_tokens: number;
|
|
751
|
+
[k: string]: unknown;
|
|
752
|
+
};
|
|
753
|
+
/**
|
|
754
|
+
* What this call added to `getSpending()`: the signed quote under `exact`,
|
|
755
|
+
* the metered charge under Solana batch settlement. Undefined with an API key.
|
|
756
|
+
*/
|
|
757
|
+
costUsd?: number;
|
|
758
|
+
/** Settlement details, when a wallet payment was made. */
|
|
759
|
+
settlement?: Settlement;
|
|
760
|
+
}
|
|
660
761
|
interface ImageEditOptions {
|
|
661
762
|
/** Model ID (default: "openai/gpt-image-2") */
|
|
662
763
|
model?: string;
|
|
@@ -1094,6 +1195,10 @@ interface PricePoint {
|
|
|
1094
1195
|
category?: string;
|
|
1095
1196
|
source?: string;
|
|
1096
1197
|
free?: boolean;
|
|
1198
|
+
/** `false` for the daily-close feeds served today. */
|
|
1199
|
+
realtime?: boolean;
|
|
1200
|
+
/** The gateway's note on the data, e.g. "Daily close, not realtime. ..." */
|
|
1201
|
+
note?: string;
|
|
1097
1202
|
}
|
|
1098
1203
|
interface PriceBar {
|
|
1099
1204
|
t?: number;
|
|
@@ -1674,6 +1779,30 @@ declare class LLMClient {
|
|
|
1674
1779
|
* @returns SearchResult with summary and citations
|
|
1675
1780
|
*/
|
|
1676
1781
|
search(query: string, options?: SearchOptions): Promise<SearchResult>;
|
|
1782
|
+
/**
|
|
1783
|
+
* Typed judgments (OpenAI Decisions-compatible, `gpt-6-luna`): send
|
|
1784
|
+
* evidence and questions with a fixed answer space, get one typed answer
|
|
1785
|
+
* per question instead of text.
|
|
1786
|
+
*
|
|
1787
|
+
* Priced on input tokens only. With a wallet the 402 quotes an upper-bound
|
|
1788
|
+
* estimate of them plus the $0.001 transaction fee, and that quote settles;
|
|
1789
|
+
* with an API key the account is billed on the tokens the provider reports.
|
|
1790
|
+
* A request over the gateway's limits is refused with a 400 before payment.
|
|
1791
|
+
*
|
|
1792
|
+
* A `choice` always picks one of your values, so give it a `none` value for
|
|
1793
|
+
* inputs that fit nothing.
|
|
1794
|
+
*
|
|
1795
|
+
* @example
|
|
1796
|
+
* const { answers } = await client.decisions({
|
|
1797
|
+
* input: 'My card was charged twice for one order.',
|
|
1798
|
+
* questions: [
|
|
1799
|
+
* { type: 'predicate', name: 'urgent', instructions: 'Does this need a reply today?' },
|
|
1800
|
+
* { type: 'choice', name: 'team', instructions: 'Which team owns this?',
|
|
1801
|
+
* choices: [{ value: 'billing' }, { value: 'shipping' }, { value: 'none' }] },
|
|
1802
|
+
* ],
|
|
1803
|
+
* });
|
|
1804
|
+
*/
|
|
1805
|
+
decisions(request: DecisionsRequest): Promise<DecisionsResponse>;
|
|
1677
1806
|
/**
|
|
1678
1807
|
* Generic Exa endpoint proxy (POST). Useful when you need an Exa API
|
|
1679
1808
|
* surface that the typed wrappers below don't expose.
|
|
@@ -3038,6 +3167,26 @@ interface SolanaBatchOptions {
|
|
|
3038
3167
|
onLocked?: "exact" | "wait" | "throw";
|
|
3039
3168
|
/** Most time, in ms, one call waits for the lock under `onLocked: "wait"`. Default 60000. */
|
|
3040
3169
|
lockWaitMs?: number;
|
|
3170
|
+
/**
|
|
3171
|
+
* What a call does when another batch call for this wallet is in flight in
|
|
3172
|
+
* this process (`channel_busy`). A channel carries one pending
|
|
3173
|
+
* authorization, and each voucher builds on the previous call's metered
|
|
3174
|
+
* charge, so a wallet pays one batch call at a time: from payment until
|
|
3175
|
+
* its answer is reconciled (for `stream()`, until its receipt is read).
|
|
3176
|
+
* - `"exact"` (default): the call pays with `exact`, as before.
|
|
3177
|
+
* - `"wait"`: the call waits up to {@link busyWaitMs} for the wallet, then
|
|
3178
|
+
* pays with batch from a fresh challenge, or raises
|
|
3179
|
+
* {@link BatchChannelBusyError} once the wait runs out. Waiting calls are
|
|
3180
|
+
* not served in arrival order, and a call whose payment is in doubt can
|
|
3181
|
+
* hold the wallet up to `inDoubt.maxWaitMs`.
|
|
3182
|
+
* - `"throw"`: the call raises {@link BatchChannelBusyError} at once.
|
|
3183
|
+
*
|
|
3184
|
+
* The error is raised before anything is signed, so it is `"unpaid"`.
|
|
3185
|
+
* While calls wait, `closeBatchChannel()` defers (`call_in_flight`).
|
|
3186
|
+
*/
|
|
3187
|
+
onBusy?: "exact" | "wait" | "throw";
|
|
3188
|
+
/** Most time, in ms, one call waits for the wallet under `onBusy: "wait"`. Default 60000. */
|
|
3189
|
+
busyWaitMs?: number;
|
|
3041
3190
|
/**
|
|
3042
3191
|
* How a call rides out an HTTP 429 (rate limited, or channel capacity
|
|
3043
3192
|
* exhausted) on a batch payment before it pays with `exact`. The call waits
|
|
@@ -3099,6 +3248,8 @@ declare const DEFAULT_BATCH_IN_DOUBT: {
|
|
|
3099
3248
|
};
|
|
3100
3249
|
/** Default {@link SolanaBatchOptions.lockWaitMs}. */
|
|
3101
3250
|
declare const DEFAULT_BATCH_LOCK_WAIT_MS = 60000;
|
|
3251
|
+
/** Default {@link SolanaBatchOptions.busyWaitMs}. */
|
|
3252
|
+
declare const DEFAULT_BATCH_BUSY_WAIT_MS = 60000;
|
|
3102
3253
|
/**
|
|
3103
3254
|
* One observable batch-settlement event.
|
|
3104
3255
|
*
|
|
@@ -3116,7 +3267,8 @@ declare const DEFAULT_BATCH_LOCK_WAIT_MS = 60000;
|
|
|
3116
3267
|
* after a 429), with the answer's `status` and the wait in `retryAfterMs`;
|
|
3117
3268
|
* or, once, when a call starts waiting up to `lockWaitMs` for another
|
|
3118
3269
|
* process's channel store lock (`reason: "channel_store_locked"`,
|
|
3119
|
-
* `onLocked: "wait"`)
|
|
3270
|
+
* `onLocked: "wait"`), or for another batch call of the wallet in this
|
|
3271
|
+
* process to finish (`reason: "channel_busy"`, `onBusy: "wait"`).
|
|
3120
3272
|
* - `recovered`: a call that backed off was then paid with batch (`reason:
|
|
3121
3273
|
* "in_doubt"` when the replay of a payment in doubt resolved it), or its
|
|
3122
3274
|
* fresh challenge after the wait was served without a payment (`reason:
|
|
@@ -3307,6 +3459,22 @@ declare class BatchChannelLockedError extends BlockrunError {
|
|
|
3307
3459
|
waitedMs: number;
|
|
3308
3460
|
});
|
|
3309
3461
|
}
|
|
3462
|
+
/**
|
|
3463
|
+
* Batch is on, another batch call for this wallet is in flight in this
|
|
3464
|
+
* process, and the client's `batch.onBusy` is `"wait"` (the wait ran out) or
|
|
3465
|
+
* `"throw"`. Raised before anything is signed: nothing was paid for the call,
|
|
3466
|
+
* and its {@link RetryDisposition} is `"unpaid"`.
|
|
3467
|
+
*/
|
|
3468
|
+
declare class BatchChannelBusyError extends BlockrunError {
|
|
3469
|
+
/** The paying wallet's address. */
|
|
3470
|
+
readonly wallet: string;
|
|
3471
|
+
/** How long this call waited for the wallet, in ms (0 unless `onBusy` is `"wait"`). */
|
|
3472
|
+
readonly waitedMs: number;
|
|
3473
|
+
constructor(init: {
|
|
3474
|
+
wallet: string;
|
|
3475
|
+
waitedMs: number;
|
|
3476
|
+
});
|
|
3477
|
+
}
|
|
3310
3478
|
/**
|
|
3311
3479
|
* The outcome of one batch attempt.
|
|
3312
3480
|
*
|
|
@@ -3412,6 +3580,8 @@ declare class SolanaBatchPayer {
|
|
|
3412
3580
|
private readonly inDoubtMaxWaitMs;
|
|
3413
3581
|
private readonly onLocked;
|
|
3414
3582
|
private readonly lockWaitMs;
|
|
3583
|
+
private readonly onBusy;
|
|
3584
|
+
private readonly busyWaitMs;
|
|
3415
3585
|
private readonly counters;
|
|
3416
3586
|
private readonly hooks;
|
|
3417
3587
|
constructor(init: SolanaBatchPayerInit);
|
|
@@ -3537,6 +3707,13 @@ declare class SolanaBatchPayer {
|
|
|
3537
3707
|
private waitForLock;
|
|
3538
3708
|
/** `onLocked` other than `"exact"`: the call's `"unpaid"` error, nothing signed. */
|
|
3539
3709
|
private lockedOut;
|
|
3710
|
+
/**
|
|
3711
|
+
* `onBusy: "wait"`: look at the wallet every {@link BUSY_POLL_MS} until no
|
|
3712
|
+
* batch call holds it or `deadline` passes. True when it is free.
|
|
3713
|
+
*/
|
|
3714
|
+
private waitWhileBusy;
|
|
3715
|
+
/** `onBusy` other than `"exact"`: the call's `"unpaid"` error, nothing signed. */
|
|
3716
|
+
private busyOut;
|
|
3540
3717
|
/**
|
|
3541
3718
|
* The close fence for a call about to send its first request: how many
|
|
3542
3719
|
* closes this wallet has completed so far, to hand to {@link pay}.
|
|
@@ -4024,6 +4201,18 @@ declare class SolanaLLMClient {
|
|
|
4024
4201
|
} & Record<string, unknown>): Promise<MusicResponse>;
|
|
4025
4202
|
/** Standalone search (Solana payment). */
|
|
4026
4203
|
search(query: string, options?: SearchOptions): Promise<SearchResult>;
|
|
4204
|
+
/**
|
|
4205
|
+
* Typed judgments (OpenAI Decisions-compatible, `gpt-6-luna`), paid on
|
|
4206
|
+
* Solana: one typed answer per question instead of text. See
|
|
4207
|
+
* {@link LLMClient.decisions} for the request shape.
|
|
4208
|
+
*
|
|
4209
|
+
* Under `exact` the 402's quote settles (an upper-bound estimate of the
|
|
4210
|
+
* input tokens plus the $0.001 fee). With the `batch` option the call pays
|
|
4211
|
+
* with a channel voucher and is charged the input tokens the provider
|
|
4212
|
+
* reports, with no per-call fee; `costUsd` is that metered charge. It shares
|
|
4213
|
+
* the wallet's channel with chat, one batch call at a time.
|
|
4214
|
+
*/
|
|
4215
|
+
decisions(request: DecisionsRequest): Promise<DecisionsResponse>;
|
|
4027
4216
|
pm(path: string, params?: Record<string, string>): Promise<Record<string, unknown>>;
|
|
4028
4217
|
pmQuery(path: string, query: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
4029
4218
|
/**
|
|
@@ -4496,6 +4685,15 @@ declare class Chat {
|
|
|
4496
4685
|
completions: ChatCompletions;
|
|
4497
4686
|
constructor(client: LLMClient, apiUrl: string, timeout: number);
|
|
4498
4687
|
}
|
|
4688
|
+
/**
|
|
4689
|
+
* Decisions API namespace (OpenAI Decisions-compatible): typed judgments.
|
|
4690
|
+
*/
|
|
4691
|
+
declare class Decisions {
|
|
4692
|
+
private client;
|
|
4693
|
+
constructor(client: LLMClient);
|
|
4694
|
+
/** Same as {@link LLMClient.decisions}. */
|
|
4695
|
+
create(params: DecisionsRequest): Promise<DecisionsResponse>;
|
|
4696
|
+
}
|
|
4499
4697
|
/**
|
|
4500
4698
|
* OpenAI-compatible client for BlockRun.
|
|
4501
4699
|
*
|
|
@@ -4515,6 +4713,7 @@ declare class Chat {
|
|
|
4515
4713
|
*/
|
|
4516
4714
|
declare class OpenAI {
|
|
4517
4715
|
chat: Chat;
|
|
4716
|
+
decisions: Decisions;
|
|
4518
4717
|
get authMode(): "api-key" | "wallet";
|
|
4519
4718
|
private client;
|
|
4520
4719
|
constructor(options?: OpenAIClientOptions);
|
|
@@ -4695,4 +4894,23 @@ declare function readSettlement(response: Response, quotedUsd: number, scheme: S
|
|
|
4695
4894
|
settlement: Settlement;
|
|
4696
4895
|
};
|
|
4697
4896
|
|
|
4698
|
-
|
|
4897
|
+
/**
|
|
4898
|
+
* Decisions — typed judgments, OpenAI Decisions-compatible (`POST /v1/decisions`).
|
|
4899
|
+
*
|
|
4900
|
+
* The caller sends evidence (`input`) and questions with a fixed answer space
|
|
4901
|
+
* (predicate, choice or score) and gets one typed answer per question back
|
|
4902
|
+
* instead of text. Served on every rail: x402 `exact` on Base, Arc and Solana,
|
|
4903
|
+
* batch settlement on Solana (metered on the input tokens the provider
|
|
4904
|
+
* reports), and an account API key on api.blockrun.ai.
|
|
4905
|
+
*
|
|
4906
|
+
* The gateway owns the limits (body size, 64 questions, 255 choices or levels,
|
|
4907
|
+
* 120K characters, 8 inline images, no hosted image URLs) and refuses an
|
|
4908
|
+
* over-limit request with a 400 before any payment. This module only checks
|
|
4909
|
+
* the shape a typed caller can still get wrong, so a malformed request fails
|
|
4910
|
+
* before anything is sent.
|
|
4911
|
+
*/
|
|
4912
|
+
|
|
4913
|
+
/** The model OpenAI serves Decisions from; the gateway also accepts our catalog ids. */
|
|
4914
|
+
declare const DECISIONS_DEFAULT_MODEL = "gpt-6-luna";
|
|
4915
|
+
|
|
4916
|
+
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, BatchChannelBusyError, 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, DECISIONS_DEFAULT_MODEL, DEFAULT_BATCH_BUSY_WAIT_MS, DEFAULT_BATCH_IN_DOUBT, DEFAULT_BATCH_LOCK_WAIT_MS, DEFAULT_BATCH_RATE_LIMIT, type DecisionAnswer, type DecisionChoice, type DecisionInputMessage, type DecisionLevel, type DecisionQuestion, type DecisionsRequest, type DecisionsResponse, 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, PAYMENT_REPLAY, PHONE_PRICES, PORTAL_URL, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, PaymentReplayError, 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 WalletAuthChallenge, type WalletInfo, type WebSearchSource, type WebSearchTool, type X402ClientLike, type X402HookContext, type XSearchSource, type XSearchTool, buildPaymentRejectedError, 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, isPaymentReplay, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, paymentRejectedErrorFromBody, readSettlement, retryDisposition, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentClient, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, toWireSearchParameters, toWireTools, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|