@vtxmacro/cli 2026.9.8 → 2026.9.10
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/bin/vtx-service-bootstrap.js +1 -1
- package/bin/vtx.js +411 -135
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ import { fileURLToPath } from "node:url";
|
|
|
16
16
|
// agent-cli-release.json
|
|
17
17
|
var agent_cli_release_default = {
|
|
18
18
|
package_name: "@vtxmacro/cli",
|
|
19
|
-
package_version: "2026.9.
|
|
19
|
+
package_version: "2026.9.10",
|
|
20
20
|
codex_package_name: "@openai/codex",
|
|
21
21
|
codex_version: "0.147.0",
|
|
22
22
|
copilot_sdk_package_name: "@github/copilot-sdk",
|
package/bin/vtx.js
CHANGED
|
@@ -47,7 +47,7 @@ var init_agent_cli_release = __esm({
|
|
|
47
47
|
"agent-cli-release.json"() {
|
|
48
48
|
agent_cli_release_default = {
|
|
49
49
|
package_name: "@vtxmacro/cli",
|
|
50
|
-
package_version: "2026.9.
|
|
50
|
+
package_version: "2026.9.10",
|
|
51
51
|
codex_package_name: "@openai/codex",
|
|
52
52
|
codex_version: "0.147.0",
|
|
53
53
|
copilot_sdk_package_name: "@github/copilot-sdk",
|
|
@@ -21363,7 +21363,7 @@ child.once('close', async (code, signal) => {
|
|
|
21363
21363
|
retryable: true
|
|
21364
21364
|
}));
|
|
21365
21365
|
}, Math.max(1, options.timeoutMs));
|
|
21366
|
-
if (options.signal) {
|
|
21366
|
+
if (options.signal && !options.retainResponseOnAbort) {
|
|
21367
21367
|
const onAbort = () => {
|
|
21368
21368
|
this.pending.delete(id2);
|
|
21369
21369
|
this.retireResponseId(id2, method);
|
|
@@ -21833,7 +21833,12 @@ child.once('close', async (code, signal) => {
|
|
|
21833
21833
|
}
|
|
21834
21834
|
}, {
|
|
21835
21835
|
timeoutMs: Math.max(1, options.deadlineAtMs - Date.now()),
|
|
21836
|
-
signal: options.signal
|
|
21836
|
+
signal: options.signal,
|
|
21837
|
+
// Thread creation does not dispatch inference, but it can persist prompt
|
|
21838
|
+
// bytes. Keep its exact reply correlated after cancellation so we can
|
|
21839
|
+
// validate and delete the thread before reporting cleanup. The original
|
|
21840
|
+
// RPC deadline still bounds setup; turn/start keeps normal cancellation.
|
|
21841
|
+
retainResponseOnAbort: true
|
|
21837
21842
|
});
|
|
21838
21843
|
const thread = objectOrNull(result2.thread);
|
|
21839
21844
|
const permission = objectOrNull(result2.activePermissionProfile);
|
|
@@ -21852,6 +21857,15 @@ child.once('close', async (code, signal) => {
|
|
|
21852
21857
|
});
|
|
21853
21858
|
}
|
|
21854
21859
|
this.threads.set(threadId, resolvedThreadPath);
|
|
21860
|
+
if (options.signal?.aborted || Date.now() >= options.deadlineAtMs) {
|
|
21861
|
+
await this.deleteThread(threadId);
|
|
21862
|
+
throw new CodexAppServerError({
|
|
21863
|
+
message: "Codex thread setup ended before inference dispatch.",
|
|
21864
|
+
category: options.signal?.aborted ? "cancelled" : "timeout",
|
|
21865
|
+
code: options.signal?.aborted ? "cancelled" : "deadline_exceeded",
|
|
21866
|
+
retryable: false
|
|
21867
|
+
});
|
|
21868
|
+
}
|
|
21855
21869
|
return {
|
|
21856
21870
|
threadId,
|
|
21857
21871
|
threadPath: resolvedThreadPath,
|
|
@@ -23919,6 +23933,7 @@ var init_codex_adapter = __esm({
|
|
|
23919
23933
|
}
|
|
23920
23934
|
if (error48 instanceof CodexAppServerError) {
|
|
23921
23935
|
const dispatchOutcome = error48.code === "server_account_context_expired_before_provider_dispatch" ? "not_dispatched" : error48.dispatchOutcome === "not_dispatched" ? currentDispatchOutcome : error48.dispatchOutcome;
|
|
23936
|
+
input.onTerminalDispatchOutcome?.(dispatchOutcome);
|
|
23922
23937
|
if (baseCheckpoint && !completedResult) {
|
|
23923
23938
|
latestCheckpoint = {
|
|
23924
23939
|
...baseCheckpoint,
|
|
@@ -23962,6 +23977,7 @@ var init_codex_adapter = __esm({
|
|
|
23962
23977
|
dispatchOutcome: currentDispatchOutcome,
|
|
23963
23978
|
cause: error48
|
|
23964
23979
|
});
|
|
23980
|
+
input.onTerminalDispatchOutcome?.(classified.dispatchOutcome);
|
|
23965
23981
|
if (baseCheckpoint && !completedResult) {
|
|
23966
23982
|
latestCheckpoint = {
|
|
23967
23983
|
...baseCheckpoint,
|
|
@@ -24716,9 +24732,14 @@ ${input.outputSchemaJson}`
|
|
|
24716
24732
|
terminalStatus: "completed"
|
|
24717
24733
|
};
|
|
24718
24734
|
} catch (error48) {
|
|
24719
|
-
if (error48 instanceof CodexAppServerError)
|
|
24735
|
+
if (error48 instanceof CodexAppServerError) {
|
|
24736
|
+
input.onTerminalDispatchOutcome?.(error48.dispatchOutcome);
|
|
24737
|
+
throw error48;
|
|
24738
|
+
}
|
|
24720
24739
|
const cancelled = input.signal?.aborted === true;
|
|
24721
24740
|
const deadline = Date.now() >= input.deadlineAtMs;
|
|
24741
|
+
const dispatchOutcome = providerReceiptObserved ? "confirmed_dispatched" : dispatchEntered ? "outcome_unknown" : "not_dispatched";
|
|
24742
|
+
input.onTerminalDispatchOutcome?.(dispatchOutcome);
|
|
24722
24743
|
if (dispatchEntered && session) {
|
|
24723
24744
|
await session.abort().catch(() => void 0);
|
|
24724
24745
|
}
|
|
@@ -24727,7 +24748,7 @@ ${input.outputSchemaJson}`
|
|
|
24727
24748
|
category: cancelled ? "cancelled" : deadline ? "timeout" : "adapter",
|
|
24728
24749
|
code: cancelled ? "cancelled" : deadline ? "deadline_exceeded" : "copilot_adapter_failure",
|
|
24729
24750
|
retryable: false,
|
|
24730
|
-
dispatchOutcome
|
|
24751
|
+
dispatchOutcome,
|
|
24731
24752
|
cause: error48
|
|
24732
24753
|
});
|
|
24733
24754
|
} finally {
|
|
@@ -25500,12 +25521,14 @@ ${input.outputSchemaJson}`,
|
|
|
25500
25521
|
} catch (error48) {
|
|
25501
25522
|
const cancelled = input.signal?.aborted === true;
|
|
25502
25523
|
const deadline = !cancelled && boundary.signal.aborted;
|
|
25503
|
-
|
|
25524
|
+
const mapped = mapDeepSeekFailure({
|
|
25504
25525
|
error: error48,
|
|
25505
25526
|
cancelled,
|
|
25506
25527
|
deadline,
|
|
25507
25528
|
dispatchOutcome: proxyDispatchOutcome(proxy)
|
|
25508
25529
|
});
|
|
25530
|
+
input.onTerminalDispatchOutcome?.(mapped.dispatchOutcome);
|
|
25531
|
+
throw mapped;
|
|
25509
25532
|
} finally {
|
|
25510
25533
|
boundary.cleanup();
|
|
25511
25534
|
await proxy.close();
|
|
@@ -33336,6 +33359,7 @@ var init_runner = __esm({
|
|
|
33336
33359
|
let stopHostHeartbeatLoop = () => {
|
|
33337
33360
|
};
|
|
33338
33361
|
let hostHeartbeatLoop = Promise.resolve();
|
|
33362
|
+
let providerDispatchWatchdogDrainRequested = false;
|
|
33339
33363
|
const agentAbort = new AbortController();
|
|
33340
33364
|
let agentLoop = Promise.resolve();
|
|
33341
33365
|
let wakeDrain;
|
|
@@ -34135,6 +34159,24 @@ var init_runner = __esm({
|
|
|
34135
34159
|
active_attempts: active.size
|
|
34136
34160
|
});
|
|
34137
34161
|
},
|
|
34162
|
+
onAttemptStage: (stage) => {
|
|
34163
|
+
emitDiagnostic("attempt_stage_changed", {
|
|
34164
|
+
stage,
|
|
34165
|
+
job_id: claim.job_id,
|
|
34166
|
+
attempt_id: attemptId,
|
|
34167
|
+
active_attempts: active.size
|
|
34168
|
+
});
|
|
34169
|
+
},
|
|
34170
|
+
onProviderDispatchWatchdog: (observation) => {
|
|
34171
|
+
providerDispatchWatchdogDrainRequested = true;
|
|
34172
|
+
emitDiagnostic("provider_dispatch_watchdog_expired", {
|
|
34173
|
+
...observation,
|
|
34174
|
+
job_id: claim.job_id,
|
|
34175
|
+
attempt_id: attemptId,
|
|
34176
|
+
active_attempts: active.size
|
|
34177
|
+
});
|
|
34178
|
+
requestDrain("provider_dispatch_watchdog_expired");
|
|
34179
|
+
},
|
|
34138
34180
|
startRetryCount: nextStartRetryCount,
|
|
34139
34181
|
onAttemptStartRetry: (observation) => {
|
|
34140
34182
|
attemptStartRetryCounts.set(attemptId, observation.retry_count);
|
|
@@ -34501,7 +34543,8 @@ var init_runner = __esm({
|
|
|
34501
34543
|
});
|
|
34502
34544
|
});
|
|
34503
34545
|
const shouldRollover = !this.options.once && (settings.maxConcurrency === null || active.size + prepared.length < settings.maxConcurrency);
|
|
34504
|
-
|
|
34546
|
+
pendingClaimPromotions += 1;
|
|
34547
|
+
const batchReceiptDurability = mutateReceipt((current) => {
|
|
34505
34548
|
if (current.pending_claim_request?.claim_request_id !== request.claim_request_id) runnerIdentityMismatch("Batched claim receipt");
|
|
34506
34549
|
const attempts = { ...current.attempts };
|
|
34507
34550
|
for (const attempt of prepared) {
|
|
@@ -34517,6 +34560,8 @@ var init_runner = __esm({
|
|
|
34517
34560
|
updated_at: isoAt(now())
|
|
34518
34561
|
};
|
|
34519
34562
|
return shouldRollover ? preparePendingClaim(promoted) : promoted;
|
|
34563
|
+
}).then(() => void 0).finally(() => {
|
|
34564
|
+
pendingClaimPromotions = Math.max(0, pendingClaimPromotions - 1);
|
|
34520
34565
|
});
|
|
34521
34566
|
for (let index = 0; index < prepared.length; index += 1) {
|
|
34522
34567
|
const item = claim.claims[index];
|
|
@@ -34529,7 +34574,8 @@ var init_runner = __esm({
|
|
|
34529
34574
|
provider_dispatch_freshness_remaining_ms: item.provider_dispatch_freshness_remaining_ms
|
|
34530
34575
|
},
|
|
34531
34576
|
roundTripMs: claimTransportResidualMs,
|
|
34532
|
-
claimResponseReceivedAtMs
|
|
34577
|
+
claimResponseReceivedAtMs,
|
|
34578
|
+
receiptDurability: batchReceiptDurability
|
|
34533
34579
|
});
|
|
34534
34580
|
}
|
|
34535
34581
|
if (this.options.once) requestDrain("once_complete");
|
|
@@ -34573,13 +34619,17 @@ var init_runner = __esm({
|
|
|
34573
34619
|
]);
|
|
34574
34620
|
}
|
|
34575
34621
|
stopHostHeartbeatLoop();
|
|
34576
|
-
|
|
34577
|
-
|
|
34578
|
-
|
|
34579
|
-
|
|
34580
|
-
|
|
34581
|
-
|
|
34582
|
-
|
|
34622
|
+
if (providerDispatchWatchdogDrainRequested) {
|
|
34623
|
+
await settlesWithin(hostHeartbeatLoop, MIN_SLEEP_MS);
|
|
34624
|
+
} else {
|
|
34625
|
+
await hostHeartbeatLoop;
|
|
34626
|
+
await settlesWithin(
|
|
34627
|
+
hostHeartbeat("draining", {
|
|
34628
|
+
deadlineAtMs: now() + settings.drainTimeoutMs,
|
|
34629
|
+
timeoutMs: settings.drainTimeoutMs
|
|
34630
|
+
}),
|
|
34631
|
+
settings.drainTimeoutMs
|
|
34632
|
+
);
|
|
34583
34633
|
}
|
|
34584
34634
|
if (active.size > 0) {
|
|
34585
34635
|
let timedOut = false;
|
|
@@ -34617,7 +34667,11 @@ var init_runner = __esm({
|
|
|
34617
34667
|
]);
|
|
34618
34668
|
await settlesWithin(agentCleanup, settings.drainTimeoutMs);
|
|
34619
34669
|
stopHostHeartbeatLoop();
|
|
34620
|
-
|
|
34670
|
+
if (providerDispatchWatchdogDrainRequested) {
|
|
34671
|
+
await settlesWithin(hostHeartbeatLoop, MIN_SLEEP_MS);
|
|
34672
|
+
} else {
|
|
34673
|
+
await hostHeartbeatLoop;
|
|
34674
|
+
}
|
|
34621
34675
|
removeAbortListener();
|
|
34622
34676
|
unregisterSignals();
|
|
34623
34677
|
try {
|
|
@@ -34695,6 +34749,53 @@ var init_runner = __esm({
|
|
|
34695
34749
|
"The persisted same-attempt recovery scope is invalid."
|
|
34696
34750
|
);
|
|
34697
34751
|
}
|
|
34752
|
+
let lastPreProviderStage = "claimed";
|
|
34753
|
+
const reportPreProviderStage = (stage) => {
|
|
34754
|
+
if (lastPreProviderStage === stage && stage !== "claimed") return;
|
|
34755
|
+
lastPreProviderStage = stage;
|
|
34756
|
+
options.onAttemptStage?.(stage);
|
|
34757
|
+
};
|
|
34758
|
+
reportPreProviderStage("claimed");
|
|
34759
|
+
const attemptAbort = new AbortController();
|
|
34760
|
+
const relayAbort = () => attemptAbort.abort();
|
|
34761
|
+
signal.addEventListener("abort", relayAbort, { once: true });
|
|
34762
|
+
if (signal.aborted) attemptAbort.abort();
|
|
34763
|
+
let watchdogArmedAtMs = now();
|
|
34764
|
+
let providerDispatchWatchdog = null;
|
|
34765
|
+
let providerDispatchWatchdogExpired = false;
|
|
34766
|
+
let resolveProviderDispatchWatchdog;
|
|
34767
|
+
const providerDispatchWatchdogSignal = new Promise((resolve6) => {
|
|
34768
|
+
resolveProviderDispatchWatchdog = resolve6;
|
|
34769
|
+
});
|
|
34770
|
+
const clearProviderDispatchWatchdog = () => {
|
|
34771
|
+
if (providerDispatchWatchdog !== null) clearTimeout(providerDispatchWatchdog);
|
|
34772
|
+
providerDispatchWatchdog = null;
|
|
34773
|
+
};
|
|
34774
|
+
const armProviderDispatchWatchdog = (deadlineAtMs) => {
|
|
34775
|
+
clearProviderDispatchWatchdog();
|
|
34776
|
+
if (deadlineAtMs === void 0 || attemptReceipt.phase === "dispatched" || attemptAbort.signal.aborted) return;
|
|
34777
|
+
watchdogArmedAtMs = now();
|
|
34778
|
+
providerDispatchWatchdog = setTimeout(() => {
|
|
34779
|
+
providerDispatchWatchdog = null;
|
|
34780
|
+
if (providerDispatchedAt !== null || attemptAbort.signal.aborted) return;
|
|
34781
|
+
providerDispatchWatchdogExpired = true;
|
|
34782
|
+
options.onProviderDispatchWatchdog?.({
|
|
34783
|
+
last_stage: lastPreProviderStage,
|
|
34784
|
+
elapsed_ms: Math.max(0, now() - watchdogArmedAtMs),
|
|
34785
|
+
remaining_ms: Math.max(0, deadlineAtMs - now())
|
|
34786
|
+
});
|
|
34787
|
+
resolveProviderDispatchWatchdog();
|
|
34788
|
+
attemptAbort.abort();
|
|
34789
|
+
}, Math.max(MIN_SLEEP_MS, deadlineAtMs - now()));
|
|
34790
|
+
};
|
|
34791
|
+
const awaitPreProviderDurability = async (operation) => Promise.race([
|
|
34792
|
+
operation,
|
|
34793
|
+
providerDispatchWatchdogSignal.then(() => {
|
|
34794
|
+
throw new InferenceHostRecoveryRequiredError(
|
|
34795
|
+
"Provider dispatch stopped because its durable receipt missed the freshness deadline."
|
|
34796
|
+
);
|
|
34797
|
+
})
|
|
34798
|
+
]);
|
|
34698
34799
|
const persistAttempt = async (changes, clearPendingClaim = false) => {
|
|
34699
34800
|
const nextAttemptReceipt = validateAttemptReceipt({
|
|
34700
34801
|
...attemptReceipt,
|
|
@@ -34761,6 +34862,84 @@ var init_runner = __esm({
|
|
|
34761
34862
|
});
|
|
34762
34863
|
options.onClaimPersisted?.();
|
|
34763
34864
|
};
|
|
34865
|
+
const terminalizeProviderDispatchWatchdog = async () => {
|
|
34866
|
+
const failureCode = "server_account_context_expired_before_provider_dispatch";
|
|
34867
|
+
const failure = {
|
|
34868
|
+
category: "timeout",
|
|
34869
|
+
code: failureCode,
|
|
34870
|
+
retryable: false,
|
|
34871
|
+
dispatchOutcome: "not_dispatched",
|
|
34872
|
+
effectiveModel: null,
|
|
34873
|
+
effectiveEffort: null
|
|
34874
|
+
};
|
|
34875
|
+
const failureId = stableOperationId("failure", [
|
|
34876
|
+
claim.job_id,
|
|
34877
|
+
attemptId,
|
|
34878
|
+
failure.dispatchOutcome,
|
|
34879
|
+
failure.category,
|
|
34880
|
+
failure.code
|
|
34881
|
+
]);
|
|
34882
|
+
const failureRequest = jobFailRequestSchema.parse({
|
|
34883
|
+
schema_version: "external_inference_job_fail_v1",
|
|
34884
|
+
contract_version: EXTERNAL_INFERENCE_CONTRACT_VERSION,
|
|
34885
|
+
job_id: claim.job_id,
|
|
34886
|
+
host_id: claim.host_id,
|
|
34887
|
+
host_generation: claim.host_generation,
|
|
34888
|
+
advertisement_generation: claim.advertisement_generation,
|
|
34889
|
+
key_generation: claim.key_generation,
|
|
34890
|
+
claim_generation: claim.claim_generation,
|
|
34891
|
+
controller_generation: claim.controller_generation,
|
|
34892
|
+
claim_handle: claim.claim_handle,
|
|
34893
|
+
attempt_id: attemptId,
|
|
34894
|
+
failure_id: failureId,
|
|
34895
|
+
response_mode: claim.response_mode,
|
|
34896
|
+
output_schema_version: claim.output_schema_version,
|
|
34897
|
+
attempt_status: "failed_no_response",
|
|
34898
|
+
outcome: {
|
|
34899
|
+
dispatch_outcome: failure.dispatchOutcome,
|
|
34900
|
+
response_outcome: "none"
|
|
34901
|
+
},
|
|
34902
|
+
model: {
|
|
34903
|
+
requested_model: claim.requested_model,
|
|
34904
|
+
requested_reasoning_effort: claim.requested_reasoning_effort,
|
|
34905
|
+
effective_model: null,
|
|
34906
|
+
effective_reasoning_effort: null,
|
|
34907
|
+
adapter_request_id: null,
|
|
34908
|
+
adapter_response_id: null
|
|
34909
|
+
},
|
|
34910
|
+
usage: null,
|
|
34911
|
+
failure_category: failure.category,
|
|
34912
|
+
failure_code: failure.code,
|
|
34913
|
+
retryable: failure.retryable,
|
|
34914
|
+
provider_dispatch_freshness_remaining_ms: 0,
|
|
34915
|
+
membership_disposition: membershipFailureDisposition(failure),
|
|
34916
|
+
failed_at: isoAt(now())
|
|
34917
|
+
});
|
|
34918
|
+
void persistAttempt({
|
|
34919
|
+
phase: "terminal_pending",
|
|
34920
|
+
dispatch_outcome: "not_dispatched",
|
|
34921
|
+
terminal_operation_id: failureId,
|
|
34922
|
+
terminal_request: failureRequest
|
|
34923
|
+
}).catch(() => void 0);
|
|
34924
|
+
const evidenceDeadlineAtMs = Date.parse(jobInput.evidence_expires_at);
|
|
34925
|
+
const failureResult = await retryExact(() => mcp.callTool(
|
|
34926
|
+
"inference.job.fail",
|
|
34927
|
+
failureRequest,
|
|
34928
|
+
{ signal, deadlineAtMs: evidenceDeadlineAtMs }
|
|
34929
|
+
), { signal, deadlineAtMs: evidenceDeadlineAtMs });
|
|
34930
|
+
assertTerminalResult(failureRequest, failureResult);
|
|
34931
|
+
options.onAttemptOutcome?.({
|
|
34932
|
+
outcome: "failed",
|
|
34933
|
+
failure_category: failureRequest.failure_category,
|
|
34934
|
+
failure_code: failureRequest.failure_code,
|
|
34935
|
+
retryable: failureRequest.retryable,
|
|
34936
|
+
dispatch_outcome: failureRequest.outcome.dispatch_outcome,
|
|
34937
|
+
response_outcome: failureRequest.outcome.response_outcome,
|
|
34938
|
+
latency_ms: null,
|
|
34939
|
+
usage: null
|
|
34940
|
+
});
|
|
34941
|
+
return "failed";
|
|
34942
|
+
};
|
|
34764
34943
|
let outputContract = null;
|
|
34765
34944
|
let inputValidationError;
|
|
34766
34945
|
try {
|
|
@@ -34769,121 +34948,150 @@ var init_runner = __esm({
|
|
|
34769
34948
|
} catch (error48) {
|
|
34770
34949
|
inputValidationError = error48;
|
|
34771
34950
|
}
|
|
34772
|
-
|
|
34773
|
-
|
|
34774
|
-
|
|
34775
|
-
|
|
34776
|
-
|
|
34777
|
-
|
|
34778
|
-
|
|
34779
|
-
|
|
34780
|
-
|
|
34781
|
-
|
|
34782
|
-
|
|
34783
|
-
|
|
34784
|
-
|
|
34785
|
-
|
|
34786
|
-
|
|
34787
|
-
|
|
34788
|
-
|
|
34789
|
-
|
|
34790
|
-
|
|
34791
|
-
|
|
34792
|
-
|
|
34793
|
-
|
|
34794
|
-
|
|
34795
|
-
startCallCompletedAtMs = now();
|
|
34796
|
-
return result2;
|
|
34797
|
-
});
|
|
34798
|
-
const [startOutcome, claimPromotionOutcome] = await Promise.allSettled([
|
|
34799
|
-
startCallPromise,
|
|
34800
|
-
claimPromotionPromise
|
|
34801
|
-
]);
|
|
34802
|
-
if (claimPromotionOutcome.status === "rejected") {
|
|
34803
|
-
throw claimPromotionOutcome.reason;
|
|
34804
|
-
}
|
|
34805
|
-
if (startOutcome.status === "rejected") {
|
|
34806
|
-
const error48 = startOutcome.reason;
|
|
34807
|
-
if (error48 instanceof ExternalInferenceMcpError && error48.serverFailureCode === "server_account_context_expired_before_provider_dispatch") {
|
|
34808
|
-
await removeAttempt();
|
|
34809
|
-
options.onAttemptOutcome?.({
|
|
34810
|
-
outcome: "freshness_rejected_before_provider_dispatch",
|
|
34811
|
-
failure_category: "freshness",
|
|
34812
|
-
failure_code: error48.serverFailureCode,
|
|
34813
|
-
dispatch_outcome: "not_dispatched"
|
|
34814
|
-
});
|
|
34815
|
-
return "failed";
|
|
34816
|
-
}
|
|
34817
|
-
if (attemptDeadlineAtMs <= now() + MIN_CLAIM_START_WINDOW_MS) {
|
|
34818
|
-
await removeAttempt();
|
|
34819
|
-
return "failed";
|
|
34951
|
+
try {
|
|
34952
|
+
if (attemptReceipt.phase === "claimed") {
|
|
34953
|
+
const attemptDeadlineAtMs = Math.min(
|
|
34954
|
+
Date.parse(claim.deadline_at),
|
|
34955
|
+
Date.parse(claim.lease_expires_at)
|
|
34956
|
+
);
|
|
34957
|
+
if (attemptDeadlineAtMs <= now() + MIN_CLAIM_START_WINDOW_MS) {
|
|
34958
|
+
await removeAttempt();
|
|
34959
|
+
clearProviderDispatchWatchdog();
|
|
34960
|
+
signal.removeEventListener("abort", relayAbort);
|
|
34961
|
+
return "failed";
|
|
34962
|
+
}
|
|
34963
|
+
const startCallStartedAtMs = now();
|
|
34964
|
+
let startCallCompletedAtMs = startCallStartedAtMs;
|
|
34965
|
+
const acceptStartResult = (result2, freshnessAnchorAtMs, roundTripMs) => {
|
|
34966
|
+
assertStartResult(startRequest, result2);
|
|
34967
|
+
if (serverProviderDispatchDeadlineMs === void 0) return;
|
|
34968
|
+
const serverRemaining = result2.provider_dispatch_freshness_remaining_ms;
|
|
34969
|
+
if (!Number.isSafeInteger(serverRemaining) || Number(serverRemaining) < 0) {
|
|
34970
|
+
throw new InferenceHostRunnerError(
|
|
34971
|
+
"provider_dispatch_freshness_receipt_invalid",
|
|
34972
|
+
"The Server provider-dispatch freshness receipt is unavailable."
|
|
34973
|
+
);
|
|
34820
34974
|
}
|
|
34821
|
-
|
|
34822
|
-
|
|
34823
|
-
const
|
|
34824
|
-
|
|
34825
|
-
|
|
34975
|
+
startRoundTripMs = Math.max(0, roundTripMs);
|
|
34976
|
+
serverReportedFreshnessRemainingMs = Number(serverRemaining);
|
|
34977
|
+
const conservativeRemainingMs = Math.max(
|
|
34978
|
+
0,
|
|
34979
|
+
serverReportedFreshnessRemainingMs - startRoundTripMs
|
|
34826
34980
|
);
|
|
34827
|
-
|
|
34828
|
-
|
|
34829
|
-
|
|
34981
|
+
providerDispatchNotAfterMs = freshnessAnchorAtMs + conservativeRemainingMs;
|
|
34982
|
+
armProviderDispatchWatchdog(providerDispatchNotAfterMs);
|
|
34983
|
+
};
|
|
34984
|
+
if (options.prestarted) {
|
|
34985
|
+
startCallCompletedAtMs = now();
|
|
34986
|
+
acceptStartResult(
|
|
34987
|
+
options.prestarted.result,
|
|
34988
|
+
options.prestarted.claimResponseReceivedAtMs,
|
|
34989
|
+
options.prestarted.roundTripMs
|
|
34830
34990
|
);
|
|
34831
|
-
|
|
34832
|
-
|
|
34833
|
-
|
|
34991
|
+
if (options.prestarted.receiptDurability) {
|
|
34992
|
+
reportPreProviderStage("receipt_persistence");
|
|
34993
|
+
await awaitPreProviderDurability(options.prestarted.receiptDurability);
|
|
34994
|
+
}
|
|
34995
|
+
} else {
|
|
34996
|
+
reportPreProviderStage("receipt_persistence");
|
|
34997
|
+
const claimPromotionPromise = options.resumeReceipt ? Promise.resolve() : awaitPreProviderDurability(
|
|
34998
|
+
persistAttempt({ phase: "claimed" }, true)
|
|
34834
34999
|
);
|
|
34835
|
-
const
|
|
34836
|
-
|
|
34837
|
-
|
|
34838
|
-
|
|
34839
|
-
|
|
34840
|
-
|
|
34841
|
-
|
|
34842
|
-
|
|
34843
|
-
|
|
34844
|
-
|
|
34845
|
-
|
|
34846
|
-
|
|
35000
|
+
const startCallPromise = retryExact(() => mcp.callTool(
|
|
35001
|
+
"inference.job.start",
|
|
35002
|
+
startRequest,
|
|
35003
|
+
{ signal, deadlineAtMs: attemptDeadlineAtMs }
|
|
35004
|
+
), { signal, deadlineAtMs: attemptDeadlineAtMs }).then((result2) => {
|
|
35005
|
+
startCallCompletedAtMs = now();
|
|
35006
|
+
acceptStartResult(
|
|
35007
|
+
result2,
|
|
35008
|
+
startCallCompletedAtMs,
|
|
35009
|
+
startCallCompletedAtMs - startCallStartedAtMs
|
|
35010
|
+
);
|
|
35011
|
+
return result2;
|
|
34847
35012
|
});
|
|
34848
|
-
await
|
|
34849
|
-
|
|
35013
|
+
const [startOutcome, claimPromotionOutcome] = await Promise.allSettled([
|
|
35014
|
+
startCallPromise,
|
|
35015
|
+
claimPromotionPromise
|
|
35016
|
+
]);
|
|
35017
|
+
if (claimPromotionOutcome.status === "rejected") {
|
|
35018
|
+
throw claimPromotionOutcome.reason;
|
|
35019
|
+
}
|
|
35020
|
+
if (startOutcome.status === "rejected") {
|
|
35021
|
+
const error48 = startOutcome.reason;
|
|
35022
|
+
if (error48 instanceof ExternalInferenceMcpError && error48.serverFailureCode === "server_account_context_expired_before_provider_dispatch") {
|
|
35023
|
+
await removeAttempt();
|
|
35024
|
+
options.onAttemptOutcome?.({
|
|
35025
|
+
outcome: "freshness_rejected_before_provider_dispatch",
|
|
35026
|
+
failure_category: "freshness",
|
|
35027
|
+
failure_code: error48.serverFailureCode,
|
|
35028
|
+
dispatch_outcome: "not_dispatched"
|
|
35029
|
+
});
|
|
35030
|
+
clearProviderDispatchWatchdog();
|
|
35031
|
+
signal.removeEventListener("abort", relayAbort);
|
|
35032
|
+
return "failed";
|
|
35033
|
+
}
|
|
35034
|
+
if (attemptDeadlineAtMs <= now() + MIN_CLAIM_START_WINDOW_MS) {
|
|
35035
|
+
await removeAttempt();
|
|
35036
|
+
clearProviderDispatchWatchdog();
|
|
35037
|
+
signal.removeEventListener("abort", relayAbort);
|
|
35038
|
+
return "failed";
|
|
35039
|
+
}
|
|
35040
|
+
if (signal.aborted) throw error48;
|
|
35041
|
+
if (controlPlaneFatal(error48)) throw error48;
|
|
35042
|
+
const remainingMs = Math.max(
|
|
35043
|
+
MIN_SLEEP_MS,
|
|
35044
|
+
attemptDeadlineAtMs - now() - MIN_CLAIM_START_WINDOW_MS
|
|
35045
|
+
);
|
|
35046
|
+
const retryCount = Math.min(
|
|
35047
|
+
Math.max(1, options.startRetryCount),
|
|
35048
|
+
Number.MAX_SAFE_INTEGER
|
|
35049
|
+
);
|
|
35050
|
+
const retryDelayMs = Math.min(
|
|
35051
|
+
remoteRetryAfterMs(error48, attemptStartRetryFallbackMs(retryCount)),
|
|
35052
|
+
remainingMs
|
|
35053
|
+
);
|
|
35054
|
+
const rawErrorCode = error48 && typeof error48 === "object" && "code" in error48 ? String(error48.code) : "start_acknowledgement_failed";
|
|
35055
|
+
options.onAttemptStartRetry?.({
|
|
35056
|
+
failure_stage: "job_start_acknowledgement",
|
|
35057
|
+
error_code: safeFailureCode(rawErrorCode, "start_acknowledgement_failed"),
|
|
35058
|
+
http_status_code: error48 instanceof ExternalInferenceMcpError ? error48.httpStatusCode : null,
|
|
35059
|
+
retryable: retryableRemoteError(error48),
|
|
35060
|
+
definitively_not_applied: Boolean(
|
|
35061
|
+
error48 && typeof error48 === "object" && "definitivelyNotApplied" in error48 && error48.definitivelyNotApplied === true
|
|
35062
|
+
),
|
|
35063
|
+
retry_after_ms: error48 instanceof ExternalInferenceMcpError ? error48.retryAfterMs : null,
|
|
35064
|
+
retry_count: retryCount,
|
|
35065
|
+
next_delay_ms: retryDelayMs
|
|
35066
|
+
});
|
|
35067
|
+
await options.sleep(retryDelayMs, signal);
|
|
35068
|
+
clearProviderDispatchWatchdog();
|
|
35069
|
+
signal.removeEventListener("abort", relayAbort);
|
|
35070
|
+
return "retry_claimed";
|
|
35071
|
+
}
|
|
34850
35072
|
}
|
|
34851
|
-
startResult = startOutcome.value;
|
|
34852
35073
|
}
|
|
34853
|
-
|
|
34854
|
-
|
|
34855
|
-
|
|
34856
|
-
|
|
34857
|
-
|
|
34858
|
-
"
|
|
34859
|
-
|
|
34860
|
-
)
|
|
34861
|
-
}
|
|
34862
|
-
if (!options.prestarted) {
|
|
34863
|
-
startRoundTripMs = Math.max(0, startCallCompletedAtMs - startCallStartedAtMs);
|
|
34864
|
-
}
|
|
34865
|
-
serverReportedFreshnessRemainingMs = Number(serverRemaining);
|
|
34866
|
-
const conservativeRemainingMs = Math.max(
|
|
34867
|
-
0,
|
|
34868
|
-
serverReportedFreshnessRemainingMs - startRoundTripMs
|
|
35074
|
+
if (attemptReceipt.phase !== "dispatched") {
|
|
35075
|
+
const providerDispatchable = inputValidationError === void 0 && outputContract !== null;
|
|
35076
|
+
reportPreProviderStage("receipt_persistence");
|
|
35077
|
+
await awaitPreProviderDurability(
|
|
35078
|
+
persistAttempt({
|
|
35079
|
+
phase: providerDispatchable ? "dispatched" : "started",
|
|
35080
|
+
dispatch_outcome: providerDispatchable ? "outcome_unknown" : "not_dispatched"
|
|
35081
|
+
})
|
|
34869
35082
|
);
|
|
34870
|
-
const freshnessAnchorAtMs = options.prestarted ? options.prestarted.claimResponseReceivedAtMs : startCallCompletedAtMs;
|
|
34871
|
-
providerDispatchNotAfterMs = freshnessAnchorAtMs + conservativeRemainingMs;
|
|
34872
35083
|
}
|
|
34873
|
-
|
|
34874
|
-
|
|
34875
|
-
|
|
34876
|
-
|
|
34877
|
-
|
|
34878
|
-
|
|
34879
|
-
}
|
|
35084
|
+
reportPreProviderStage("thread_setup");
|
|
35085
|
+
} catch (error48) {
|
|
35086
|
+
clearProviderDispatchWatchdog();
|
|
35087
|
+
signal.removeEventListener("abort", relayAbort);
|
|
35088
|
+
if (providerDispatchWatchdogExpired) {
|
|
35089
|
+
return terminalizeProviderDispatchWatchdog();
|
|
35090
|
+
}
|
|
35091
|
+
throw error48;
|
|
34880
35092
|
}
|
|
34881
35093
|
let adapterResult;
|
|
34882
35094
|
let heartbeatFailure;
|
|
34883
|
-
const attemptAbort = new AbortController();
|
|
34884
|
-
const relayAbort = () => attemptAbort.abort();
|
|
34885
|
-
signal.addEventListener("abort", relayAbort, { once: true });
|
|
34886
|
-
if (signal.aborted) attemptAbort.abort();
|
|
34887
35095
|
let heartbeatStopped = false;
|
|
34888
35096
|
const heartbeatLoop = (async () => {
|
|
34889
35097
|
while (!heartbeatStopped && !attemptAbort.signal.aborted) {
|
|
@@ -34959,7 +35167,12 @@ var init_runner = __esm({
|
|
|
34959
35167
|
dispatchOutcome: "outcome_unknown"
|
|
34960
35168
|
});
|
|
34961
35169
|
}
|
|
34962
|
-
|
|
35170
|
+
let resolveTerminalDispatchOutcome;
|
|
35171
|
+
const terminalDispatchOutcomeSignal = new Promise((resolve6) => {
|
|
35172
|
+
resolveTerminalDispatchOutcome = resolve6;
|
|
35173
|
+
});
|
|
35174
|
+
let terminalDispatchOutcomeObserved = false;
|
|
35175
|
+
const adapterAttempt = this.dependencies.codexAdapter.runAttempt({
|
|
34963
35176
|
attemptId,
|
|
34964
35177
|
inputSha256: jobInput.input_sha256,
|
|
34965
35178
|
systemPrompt: jobInput.system_prompt,
|
|
@@ -34972,6 +35185,8 @@ var init_runner = __esm({
|
|
|
34972
35185
|
onProviderDispatch: () => {
|
|
34973
35186
|
const dispatchedAtMs = now();
|
|
34974
35187
|
providerDispatchedAt ??= isoAt(dispatchedAtMs);
|
|
35188
|
+
clearProviderDispatchWatchdog();
|
|
35189
|
+
options.onAttemptStage?.("provider_dispatched");
|
|
34975
35190
|
if (providerDispatchNotAfterMs === void 0) return;
|
|
34976
35191
|
providerDispatchFreshnessRemainingMs = Math.max(
|
|
34977
35192
|
0,
|
|
@@ -34984,8 +35199,49 @@ var init_runner = __esm({
|
|
|
34984
35199
|
start_round_trip_ms: startRoundTripMs
|
|
34985
35200
|
});
|
|
34986
35201
|
},
|
|
35202
|
+
onTerminalDispatchOutcome: (outcome) => {
|
|
35203
|
+
if (terminalDispatchOutcomeObserved) return;
|
|
35204
|
+
terminalDispatchOutcomeObserved = true;
|
|
35205
|
+
resolveTerminalDispatchOutcome(outcome);
|
|
35206
|
+
},
|
|
34987
35207
|
signal: attemptAbort.signal
|
|
34988
35208
|
});
|
|
35209
|
+
adapterResult = await Promise.race([
|
|
35210
|
+
adapterAttempt,
|
|
35211
|
+
providerDispatchWatchdogSignal.then(async () => {
|
|
35212
|
+
const classified = await Promise.race([
|
|
35213
|
+
adapterAttempt.then(
|
|
35214
|
+
(result2) => ({ kind: "result", result: result2 }),
|
|
35215
|
+
(error48) => ({ kind: "error", error: error48 })
|
|
35216
|
+
),
|
|
35217
|
+
terminalDispatchOutcomeSignal.then((outcome) => ({
|
|
35218
|
+
kind: "dispatch_outcome",
|
|
35219
|
+
outcome
|
|
35220
|
+
})),
|
|
35221
|
+
options.sleep(options.attemptHeartbeatMs).then(() => ({
|
|
35222
|
+
kind: "unsettled"
|
|
35223
|
+
}))
|
|
35224
|
+
]);
|
|
35225
|
+
if (classified.kind === "result") return classified.result;
|
|
35226
|
+
if (classified.kind === "error") throw classified.error;
|
|
35227
|
+
if (classified.kind === "dispatch_outcome" && classified.outcome === "not_dispatched") {
|
|
35228
|
+
throw new CodexAppServerError({
|
|
35229
|
+
message: "The Server account context expired before provider dispatch.",
|
|
35230
|
+
category: "timeout",
|
|
35231
|
+
code: "server_account_context_expired_before_provider_dispatch",
|
|
35232
|
+
retryable: false,
|
|
35233
|
+
dispatchOutcome: "not_dispatched"
|
|
35234
|
+
});
|
|
35235
|
+
}
|
|
35236
|
+
throw new CodexAppServerError({
|
|
35237
|
+
message: "Provider dispatch could not be excluded after the freshness watchdog expired.",
|
|
35238
|
+
category: "timeout",
|
|
35239
|
+
code: "provider_dispatch_outcome_unknown",
|
|
35240
|
+
retryable: false,
|
|
35241
|
+
dispatchOutcome: classified.kind === "dispatch_outcome" ? classified.outcome : "outcome_unknown"
|
|
35242
|
+
});
|
|
35243
|
+
})
|
|
35244
|
+
]);
|
|
34989
35245
|
adapterResultReadyAt = isoAt(now());
|
|
34990
35246
|
await persistAttempt({
|
|
34991
35247
|
phase: "dispatched",
|
|
@@ -35170,8 +35426,15 @@ var init_runner = __esm({
|
|
|
35170
35426
|
rateLimits: error48.rateLimits
|
|
35171
35427
|
});
|
|
35172
35428
|
}
|
|
35173
|
-
const
|
|
35174
|
-
|
|
35429
|
+
const effectiveError = providerDispatchWatchdogExpired && error48 instanceof CodexAppServerError && error48.dispatchOutcome === "not_dispatched" ? new CodexAppServerError({
|
|
35430
|
+
message: "The Server account context expired before provider dispatch.",
|
|
35431
|
+
category: "timeout",
|
|
35432
|
+
code: "server_account_context_expired_before_provider_dispatch",
|
|
35433
|
+
retryable: false,
|
|
35434
|
+
dispatchOutcome: "not_dispatched"
|
|
35435
|
+
}) : error48;
|
|
35436
|
+
const classified = classifyFailure(heartbeatFailure ?? effectiveError, adapterResult);
|
|
35437
|
+
const processExit = heartbeatFailure === void 0 && effectiveError instanceof CodexAppServerError && effectiveError.code === "codex_process_closed" && effectiveError.processExit?.expected_shutdown === false ? effectiveError.processExit : null;
|
|
35175
35438
|
const heartbeatAmbiguous = ambiguousHeartbeatTransport(heartbeatFailure);
|
|
35176
35439
|
const failure = heartbeatAmbiguous ? {
|
|
35177
35440
|
...classified,
|
|
@@ -35180,7 +35443,7 @@ var init_runner = __esm({
|
|
|
35180
35443
|
effectiveModel: adapterResult?.effectiveModel ?? classified.effectiveModel,
|
|
35181
35444
|
effectiveEffort: adapterResult?.effectiveReasoningEffort ?? classified.effectiveEffort
|
|
35182
35445
|
} : classified;
|
|
35183
|
-
const dispatchOutcome = heartbeatAmbiguous ? "outcome_unknown" :
|
|
35446
|
+
const dispatchOutcome = heartbeatAmbiguous ? "outcome_unknown" : effectiveError instanceof CodexAppServerError ? effectiveError.dispatchOutcome : failure.dispatchOutcome;
|
|
35184
35447
|
await persistAttempt({
|
|
35185
35448
|
phase: dispatchOutcome === "not_dispatched" ? "started" : "dispatched",
|
|
35186
35449
|
dispatch_outcome: dispatchOutcome
|
|
@@ -35221,7 +35484,7 @@ var init_runner = __esm({
|
|
|
35221
35484
|
adapter_request_id: canReportEffective ? adapterResult?.adapterRequestId ?? null : null,
|
|
35222
35485
|
adapter_response_id: canReportEffective ? adapterResult?.adapterResponseId ?? null : null
|
|
35223
35486
|
},
|
|
35224
|
-
usage: adapterResult ? reportedUsage(adapterResult, usageSource) :
|
|
35487
|
+
usage: adapterResult ? reportedUsage(adapterResult, usageSource) : effectiveError instanceof CodexAppServerError && effectiveError.usage ? reportedTokenUsage(effectiveError.usage, usageSource) : null,
|
|
35225
35488
|
failure_category: failure.category,
|
|
35226
35489
|
failure_code: failure.code,
|
|
35227
35490
|
retryable: failure.retryable,
|
|
@@ -35271,6 +35534,7 @@ var init_runner = __esm({
|
|
|
35271
35534
|
});
|
|
35272
35535
|
return "failed";
|
|
35273
35536
|
} finally {
|
|
35537
|
+
clearProviderDispatchWatchdog();
|
|
35274
35538
|
signal.removeEventListener("abort", relayAbort);
|
|
35275
35539
|
await stopHeartbeat();
|
|
35276
35540
|
}
|
|
@@ -42281,7 +42545,7 @@ var init_network_debug = __esm({
|
|
|
42281
42545
|
});
|
|
42282
42546
|
|
|
42283
42547
|
// lib/runtime/hyperliquid-account-state-adapter.ts
|
|
42284
|
-
var unsupportedUserActiveAssetCache, MAX_UNSUPPORTED_USER_ACTIVE_ASSET_CACHE_KEYS, UNSUPPORTED_USER_ACTIVE_ASSET_STORAGE_KEY, USER_FILLS_CACHE_STORAGE_PREFIX, ACCOUNT_STATE_CACHE_STORAGE_PREFIX, INFO_RATE_LIMIT_COOLDOWN_STORAGE_PREFIX, INFO_RATE_LIMIT_COOLDOWN_MIN_MS, INFO_RATE_LIMIT_COOLDOWN_MAX_MS, browserUserFillsCache, browserUserFillsInFlight, HYPERLIQUID_USER_FILLS_PROVIDER_PAGE_CAP, browserAccountStateCache, browserAccountStateInFlight, browserInfoRateLimitCooldowns, UNSUPPORTED_USER_ACTIVE_ASSET_DETAIL_PATTERNS, unsupportedUserActiveAssetCacheHydrated, hydrateUnsupportedUserActiveAssetCache, persistUnsupportedUserActiveAssetCache, toPositiveFinite, toFinite, firstFiniteNumber, parseFundingUsdcFromInfoPosition, buildActiveAssetCacheKey, buildUserFillsCacheKey, buildUserFillsStorageKey, buildAccountStateCacheKey, buildAccountStateStorageKey, normalizeInfoRateLimitApiUrl, normalizeInfoRequestType, buildInfoRateLimitCooldownKey, buildInfoRateLimitCooldownStorageKey, readInfoRateLimitCooldownUntilMs, hasActiveInfoRateLimitCooldown, writeInfoRateLimitCooldown, extractInfoRequestTypeFromRateLimitError, recordInfoRateLimitCooldownFromError, requireNonNegativeConfigSeconds, requireAccountStateCacheConfig, requireUserFillsCacheConfig, normalizeFillSymbol, buildSymbolFilter, filterFillsBySymbols, readBrowserUserFillsCache, writeBrowserUserFillsCache, cloneBrowserAccountStateResult, readBrowserAccountStateCache, writeBrowserAccountStateCache, isRateLimitError, createAbortError, waitForSharedBrowserRequest, waitForSharedBrowserUserFills, getBrowserActiveAssetTypeCandidates, normalizeHyperliquidErrorDetail, isUnsupportedUserActiveAssetError, rememberUnsupportedUserActiveAssetKey, parseInfoPositions, requireFinitePromptMetric, requirePromptClearinghouseState, requirePromptSpotState, normalizePerpDexName, listConfiguredPerpDexs, listPerpDexsForAccountState, prefixHip3PositionCoins, aggregateClearinghouseResponses, normalizeBrowserFillToTradeHistory, isPerpFill, fetchHyperliquidInfoPayload, requireHyperliquidApiUrl, requireWalletAddress, parseInfoPositionSnapshot, fetchBrowserAccountState, fetchBrowserAccountStateUncached, fetchBrowserUserFills, fetchBrowserPositionSnapshot;
|
|
42548
|
+
var unsupportedUserActiveAssetCache, MAX_UNSUPPORTED_USER_ACTIVE_ASSET_CACHE_KEYS, UNSUPPORTED_USER_ACTIVE_ASSET_STORAGE_KEY, USER_FILLS_CACHE_STORAGE_PREFIX, ACCOUNT_STATE_CACHE_STORAGE_PREFIX, INFO_RATE_LIMIT_COOLDOWN_STORAGE_PREFIX, INFO_RATE_LIMIT_COOLDOWN_MIN_MS, INFO_RATE_LIMIT_COOLDOWN_MAX_MS, browserUserFillsCache, browserUserFillsInFlight, HYPERLIQUID_USER_FILLS_PROVIDER_PAGE_CAP, browserAccountStateCache, browserAccountStateInFlight, browserInfoRateLimitCooldowns, UNSUPPORTED_USER_ACTIVE_ASSET_DETAIL_PATTERNS, unsupportedUserActiveAssetCacheHydrated, hydrateUnsupportedUserActiveAssetCache, persistUnsupportedUserActiveAssetCache, toPositiveFinite, toFinite, firstFiniteNumber, parseFundingUsdcFromInfoPosition, buildActiveAssetCacheKey, buildUserFillsCacheKey, buildUserFillsStorageKey, buildAccountStateCacheKey, buildAccountStateStorageKey, normalizeInfoRateLimitApiUrl, normalizeInfoRequestType, buildInfoRateLimitCooldownKey, buildInfoRateLimitCooldownStorageKey, readInfoRateLimitCooldownUntilMs, hasActiveInfoRateLimitCooldown, writeInfoRateLimitCooldown, extractInfoRequestTypeFromRateLimitError, recordInfoRateLimitCooldownFromError, requireNonNegativeConfigSeconds, requireAccountStateCacheConfig, requireUserFillsCacheConfig, normalizeFillSymbol, buildSymbolFilter, filterFillsBySymbols, readBrowserUserFillsCache, writeBrowserUserFillsCache, cloneBrowserAccountStateResult, withAccountStateEvidence, readBrowserAccountStateCache, writeBrowserAccountStateCache, isRateLimitError, createAbortError, waitForSharedBrowserRequest, waitForSharedBrowserUserFills, getBrowserActiveAssetTypeCandidates, normalizeHyperliquidErrorDetail, isUnsupportedUserActiveAssetError, rememberUnsupportedUserActiveAssetKey, parseInfoPositions, requireFinitePromptMetric, requirePromptClearinghouseState, requirePromptSpotState, normalizePerpDexName, listConfiguredPerpDexs, listPerpDexsForAccountState, prefixHip3PositionCoins, aggregateClearinghouseResponses, normalizeBrowserFillToTradeHistory, isPerpFill, fetchHyperliquidInfoPayload, requireHyperliquidApiUrl, requireWalletAddress, parseInfoPositionSnapshot, fetchBrowserAccountState, fetchBrowserAccountStateUncached, fetchBrowserUserFills, fetchBrowserPositionSnapshot;
|
|
42285
42549
|
var init_hyperliquid_account_state_adapter = __esm({
|
|
42286
42550
|
"lib/runtime/hyperliquid-account-state-adapter.ts"() {
|
|
42287
42551
|
"use strict";
|
|
@@ -42621,12 +42885,26 @@ var init_hyperliquid_account_state_adapter = __esm({
|
|
|
42621
42885
|
}
|
|
42622
42886
|
};
|
|
42623
42887
|
cloneBrowserAccountStateResult = (result2) => ({
|
|
42888
|
+
...result2.evidence ? { evidence: { ...result2.evidence } } : {},
|
|
42624
42889
|
accountSummary: { ...result2.accountSummary },
|
|
42625
42890
|
availableToTrade: { ...result2.availableToTrade },
|
|
42626
42891
|
positions: result2.positions.map((position) => ({ ...position })),
|
|
42627
42892
|
...result2.takerRate == null ? {} : { takerRate: result2.takerRate },
|
|
42628
42893
|
...result2.promptRescueEvidence == null ? {} : { promptRescueEvidence: { ...result2.promptRescueEvidence } }
|
|
42629
42894
|
});
|
|
42895
|
+
withAccountStateEvidence = (result2, source, fetchedAtMs, freshnessLimitMs) => {
|
|
42896
|
+
const observedAtMs = Date.now();
|
|
42897
|
+
return {
|
|
42898
|
+
...cloneBrowserAccountStateResult(result2),
|
|
42899
|
+
evidence: {
|
|
42900
|
+
source,
|
|
42901
|
+
fetchedAtMs,
|
|
42902
|
+
observedAtMs,
|
|
42903
|
+
cacheAgeMs: Math.max(0, observedAtMs - fetchedAtMs),
|
|
42904
|
+
freshnessLimitMs
|
|
42905
|
+
}
|
|
42906
|
+
};
|
|
42907
|
+
};
|
|
42630
42908
|
readBrowserAccountStateCache = (cacheKey) => {
|
|
42631
42909
|
const memoryEntry = browserAccountStateCache.get(cacheKey);
|
|
42632
42910
|
if (memoryEntry) {
|
|
@@ -43105,7 +43383,7 @@ var init_hyperliquid_account_state_adapter = __esm({
|
|
|
43105
43383
|
const now = Date.now();
|
|
43106
43384
|
const cached2 = readBrowserAccountStateCache(cacheKey);
|
|
43107
43385
|
if (!input.forceRefresh && cached2 && now - cached2.fetchedAtMs <= ttlMs) {
|
|
43108
|
-
return
|
|
43386
|
+
return withAccountStateEvidence(cached2.result, "cache", cached2.fetchedAtMs, ttlMs);
|
|
43109
43387
|
}
|
|
43110
43388
|
if (!input.forceRefresh && cached2 && now - cached2.fetchedAtMs <= staleIf429MaxAgeMs && hasActiveInfoRateLimitCooldown(apiUrl, [
|
|
43111
43389
|
"clearinghouseState",
|
|
@@ -43114,7 +43392,7 @@ var init_hyperliquid_account_state_adapter = __esm({
|
|
|
43114
43392
|
...includeExactAccountMode ? ["userAbstraction", "userDexAbstraction"] : [],
|
|
43115
43393
|
...includeActiveAssetData ? activeAssetRequestTypes : []
|
|
43116
43394
|
], now)) {
|
|
43117
|
-
return
|
|
43395
|
+
return withAccountStateEvidence(cached2.result, "stale_if_429", cached2.fetchedAtMs, staleIf429MaxAgeMs);
|
|
43118
43396
|
}
|
|
43119
43397
|
let inFlight = input.forceRefresh ? void 0 : browserAccountStateInFlight.get(cacheKey);
|
|
43120
43398
|
if (!inFlight) {
|
|
@@ -43130,11 +43408,9 @@ var init_hyperliquid_account_state_adapter = __esm({
|
|
|
43130
43408
|
dexNames,
|
|
43131
43409
|
staleIf429MaxAgeMs
|
|
43132
43410
|
}).then((result2) => {
|
|
43133
|
-
|
|
43134
|
-
|
|
43135
|
-
|
|
43136
|
-
});
|
|
43137
|
-
return cloneBrowserAccountStateResult(result2);
|
|
43411
|
+
const fetchedAtMs = Date.now();
|
|
43412
|
+
writeBrowserAccountStateCache(cacheKey, { fetchedAtMs, result: result2 });
|
|
43413
|
+
return withAccountStateEvidence(result2, "live", fetchedAtMs, null);
|
|
43138
43414
|
}).finally(() => {
|
|
43139
43415
|
if (!input.forceRefresh) {
|
|
43140
43416
|
browserAccountStateInFlight.delete(cacheKey);
|
|
@@ -43154,7 +43430,7 @@ var init_hyperliquid_account_state_adapter = __esm({
|
|
|
43154
43430
|
recordInfoRateLimitCooldownFromError(apiUrl, error48, staleIf429MaxAgeMs);
|
|
43155
43431
|
const staleCache = readBrowserAccountStateCache(cacheKey);
|
|
43156
43432
|
if (!input.forceRefresh && isRateLimitError(error48) && staleCache && Date.now() - staleCache.fetchedAtMs <= staleIf429MaxAgeMs) {
|
|
43157
|
-
return
|
|
43433
|
+
return withAccountStateEvidence(staleCache.result, "stale_if_429", staleCache.fetchedAtMs, staleIf429MaxAgeMs);
|
|
43158
43434
|
}
|
|
43159
43435
|
throw error48;
|
|
43160
43436
|
}
|
|
@@ -43405,7 +43681,7 @@ var init_hyperliquid_account_state_adapter = __esm({
|
|
|
43405
43681
|
}
|
|
43406
43682
|
};
|
|
43407
43683
|
}
|
|
43408
|
-
if (cached2 && now - cached2.fetchedAtMs <= staleIf429MaxAgeMs && hasActiveInfoRateLimitCooldown(apiUrl, ["userFills"], now)) {
|
|
43684
|
+
if (!input.forceRefresh && cached2 && now - cached2.fetchedAtMs <= staleIf429MaxAgeMs && hasActiveInfoRateLimitCooldown(apiUrl, ["userFills"], now)) {
|
|
43409
43685
|
const scopedFills = filterFillsBySymbols(cached2.rawFills, input.symbols);
|
|
43410
43686
|
const tradeHistory2 = scopedFills.map(normalizeBrowserFillToTradeHistory).filter((fill) => fill !== null);
|
|
43411
43687
|
return {
|
|
@@ -43465,7 +43741,7 @@ var init_hyperliquid_account_state_adapter = __esm({
|
|
|
43465
43741
|
} catch (error48) {
|
|
43466
43742
|
recordInfoRateLimitCooldownFromError(apiUrl, error48, staleIf429MaxAgeMs);
|
|
43467
43743
|
const staleCache = readBrowserUserFillsCache(cacheKey);
|
|
43468
|
-
if (isRateLimitError(error48)) {
|
|
43744
|
+
if (isRateLimitError(error48) && !input.forceRefresh) {
|
|
43469
43745
|
evidenceSource = "stale_if_429";
|
|
43470
43746
|
rawWalletFills = staleCache && Date.now() - staleCache.fetchedAtMs <= staleIf429MaxAgeMs ? staleCache.rawFills : [];
|
|
43471
43747
|
providerRowCount = staleCache?.providerRowCount ?? 0;
|