@vtxmacro/cli 2026.9.41 → 2026.9.43
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 +4 -1
- package/bin/vtx.js +692 -370
- package/package.json +1 -1
package/bin/vtx.js
CHANGED
|
@@ -77,7 +77,7 @@ var init_agent_cli_release = __esm({
|
|
|
77
77
|
"agent-cli-release.json"() {
|
|
78
78
|
agent_cli_release_default = {
|
|
79
79
|
package_name: "@vtxmacro/cli",
|
|
80
|
-
package_version: "2026.9.
|
|
80
|
+
package_version: "2026.9.43",
|
|
81
81
|
codex_package_name: "@openai/codex",
|
|
82
82
|
codex_version: "0.153.3",
|
|
83
83
|
copilot_sdk_package_name: "@github/copilot-sdk",
|
|
@@ -4196,8 +4196,8 @@ var init_az = __esm({
|
|
|
4196
4196
|
});
|
|
4197
4197
|
|
|
4198
4198
|
// node_modules/zod/v4/locales/be.js
|
|
4199
|
-
function getBelarusianPlural(
|
|
4200
|
-
const absCount = Math.abs(
|
|
4199
|
+
function getBelarusianPlural(count4, one, few, many) {
|
|
4200
|
+
const absCount = Math.abs(count4);
|
|
4201
4201
|
const lastDigit = absCount % 10;
|
|
4202
4202
|
const lastTwoDigits = absCount % 100;
|
|
4203
4203
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -6156,8 +6156,8 @@ var init_hu = __esm({
|
|
|
6156
6156
|
});
|
|
6157
6157
|
|
|
6158
6158
|
// node_modules/zod/v4/locales/hy.js
|
|
6159
|
-
function getArmenianPlural(
|
|
6160
|
-
return Math.abs(
|
|
6159
|
+
function getArmenianPlural(count4, one, many) {
|
|
6160
|
+
return Math.abs(count4) === 1 ? one : many;
|
|
6161
6161
|
}
|
|
6162
6162
|
function withDefiniteArticle(word) {
|
|
6163
6163
|
if (!word)
|
|
@@ -8326,8 +8326,8 @@ var init_pt = __esm({
|
|
|
8326
8326
|
});
|
|
8327
8327
|
|
|
8328
8328
|
// node_modules/zod/v4/locales/ru.js
|
|
8329
|
-
function getRussianPlural(
|
|
8330
|
-
const absCount = Math.abs(
|
|
8329
|
+
function getRussianPlural(count4, one, few, many) {
|
|
8330
|
+
const absCount = Math.abs(count4);
|
|
8331
8331
|
const lastDigit = absCount % 10;
|
|
8332
8332
|
const lastTwoDigits = absCount % 100;
|
|
8333
8333
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -17682,17 +17682,17 @@ async function readInferenceHostCredentialContextTransition(config2) {
|
|
|
17682
17682
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
17683
17683
|
throw new Error("Inference host credential context transition is invalid.");
|
|
17684
17684
|
}
|
|
17685
|
-
const
|
|
17685
|
+
const record5 = value;
|
|
17686
17686
|
const expectedKeys = ["schema_version", "operation", "phase", "previous", "candidate"];
|
|
17687
|
-
if (Object.keys(
|
|
17687
|
+
if (Object.keys(record5).sort().join("\0") !== expectedKeys.sort().join("\0") || record5.schema_version !== "vtx_inference_credential_context_transition_v1" || record5.operation !== "selection" && record5.operation !== "cleanup" || record5.phase !== "prepared" && record5.phase !== "committed") {
|
|
17688
17688
|
throw new Error("Inference host credential context transition is invalid.");
|
|
17689
17689
|
}
|
|
17690
17690
|
return {
|
|
17691
17691
|
schema_version: "vtx_inference_credential_context_transition_v1",
|
|
17692
|
-
operation:
|
|
17693
|
-
phase:
|
|
17694
|
-
previous:
|
|
17695
|
-
candidate:
|
|
17692
|
+
operation: record5.operation,
|
|
17693
|
+
phase: record5.phase,
|
|
17694
|
+
previous: record5.previous === null ? null : assertInferenceHostCredentialContext(record5.previous, config2),
|
|
17695
|
+
candidate: record5.candidate === null ? null : assertInferenceHostCredentialContext(record5.candidate, config2)
|
|
17696
17696
|
};
|
|
17697
17697
|
}
|
|
17698
17698
|
async function clearInferenceHostCredentialContextTransition(config2) {
|
|
@@ -17725,26 +17725,26 @@ function assertInferenceHostCredentialContext(value, config2) {
|
|
|
17725
17725
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
17726
17726
|
throw new Error("Inference host credential context is invalid.");
|
|
17727
17727
|
}
|
|
17728
|
-
const
|
|
17728
|
+
const record5 = value;
|
|
17729
17729
|
const expectedKeys = [
|
|
17730
17730
|
"schema_version",
|
|
17731
17731
|
"instance_name",
|
|
17732
17732
|
"credential_store_mode",
|
|
17733
17733
|
"credential_file_path"
|
|
17734
17734
|
];
|
|
17735
|
-
if (Object.keys(
|
|
17735
|
+
if (Object.keys(record5).sort().join("\0") !== expectedKeys.sort().join("\0") || record5.schema_version !== "vtx_inference_credential_context_v1" || record5.instance_name !== config2.instanceName || record5.credential_store_mode !== "os" && record5.credential_store_mode !== "file" || (record5.credential_store_mode === "os" ? record5.credential_file_path !== null : typeof record5.credential_file_path !== "string" || !record5.credential_file_path)) {
|
|
17736
17736
|
throw new Error("Inference host credential context is invalid.");
|
|
17737
17737
|
}
|
|
17738
|
-
const credentialFilePath =
|
|
17738
|
+
const credentialFilePath = record5.credential_store_mode === "file" ? requireNamedInstancePath(
|
|
17739
17739
|
config2.instanceName,
|
|
17740
17740
|
config2.instanceName === DEFAULT_INFERENCE_HOST_INSTANCE ? config2.baseDir : join(config2.baseDir, "instances", config2.instanceName),
|
|
17741
|
-
|
|
17741
|
+
record5.credential_file_path,
|
|
17742
17742
|
"Stored inference credential path"
|
|
17743
17743
|
) : null;
|
|
17744
17744
|
return {
|
|
17745
17745
|
schema_version: "vtx_inference_credential_context_v1",
|
|
17746
17746
|
instance_name: config2.instanceName,
|
|
17747
|
-
credential_store_mode:
|
|
17747
|
+
credential_store_mode: record5.credential_store_mode,
|
|
17748
17748
|
credential_file_path: credentialFilePath
|
|
17749
17749
|
};
|
|
17750
17750
|
}
|
|
@@ -17752,7 +17752,7 @@ function assertLocalState(value) {
|
|
|
17752
17752
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
17753
17753
|
throw new Error("Inference host local state is invalid.");
|
|
17754
17754
|
}
|
|
17755
|
-
const
|
|
17755
|
+
const record5 = value;
|
|
17756
17756
|
const exactKeys = [
|
|
17757
17757
|
"schema_version",
|
|
17758
17758
|
"issuer",
|
|
@@ -17761,10 +17761,10 @@ function assertLocalState(value) {
|
|
|
17761
17761
|
"host_generation",
|
|
17762
17762
|
"key_generation"
|
|
17763
17763
|
];
|
|
17764
|
-
if (Object.keys(
|
|
17764
|
+
if (Object.keys(record5).sort().join("\0") !== exactKeys.slice().sort().join("\0") || record5.schema_version !== 1 || typeof record5.issuer !== "string" || !record5.issuer || typeof record5.client_id !== "string" || !record5.client_id || typeof record5.host_id !== "string" || !record5.host_id || !Number.isSafeInteger(record5.host_generation) || Number(record5.host_generation) < 1 || !Number.isSafeInteger(record5.key_generation) || Number(record5.key_generation) < 1) {
|
|
17765
17765
|
throw new Error("Inference host local state is invalid.");
|
|
17766
17766
|
}
|
|
17767
|
-
return
|
|
17767
|
+
return record5;
|
|
17768
17768
|
}
|
|
17769
17769
|
async function ensureInferencePrivateDirectory(path, dependencies = {}) {
|
|
17770
17770
|
const platform = dependencies.platform ?? process.platform;
|
|
@@ -18796,7 +18796,7 @@ function validateInferenceHostCredential(value) {
|
|
|
18796
18796
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
18797
18797
|
throw new Error("Inference host credential is invalid.");
|
|
18798
18798
|
}
|
|
18799
|
-
const
|
|
18799
|
+
const record5 = value;
|
|
18800
18800
|
const exactKeys = [
|
|
18801
18801
|
"schema_version",
|
|
18802
18802
|
"issuer",
|
|
@@ -18809,21 +18809,21 @@ function validateInferenceHostCredential(value) {
|
|
|
18809
18809
|
"created_at",
|
|
18810
18810
|
"updated_at"
|
|
18811
18811
|
];
|
|
18812
|
-
if (Object.keys(
|
|
18812
|
+
if (Object.keys(record5).sort().join("\0") !== exactKeys.sort().join("\0")) {
|
|
18813
18813
|
throw new Error("Inference host credential fields are invalid.");
|
|
18814
18814
|
}
|
|
18815
|
-
if (
|
|
18815
|
+
if (record5.schema_version !== 1) {
|
|
18816
18816
|
throw new Error("Inference host credential version is invalid.");
|
|
18817
18817
|
}
|
|
18818
|
-
const issuer = canonicalUrl(String(
|
|
18818
|
+
const issuer = canonicalUrl(String(record5.issuer || ""), "Inference OAuth issuer");
|
|
18819
18819
|
const resource = canonicalUrl(
|
|
18820
|
-
String(
|
|
18820
|
+
String(record5.resource || ""),
|
|
18821
18821
|
"Inference OAuth resource"
|
|
18822
18822
|
);
|
|
18823
|
-
const clientId = String(
|
|
18824
|
-
const hostId = String(
|
|
18825
|
-
const refreshToken = String(
|
|
18826
|
-
const privateKey = String(
|
|
18823
|
+
const clientId = String(record5.client_id || "");
|
|
18824
|
+
const hostId = String(record5.host_id || "");
|
|
18825
|
+
const refreshToken = String(record5.refresh_token || "");
|
|
18826
|
+
const privateKey = String(record5.x25519_private_key || "");
|
|
18827
18827
|
if (!clientId || clientId.length > 512) {
|
|
18828
18828
|
throw new Error("Inference OAuth client ID is invalid.");
|
|
18829
18829
|
}
|
|
@@ -18836,11 +18836,11 @@ function validateInferenceHostCredential(value) {
|
|
|
18836
18836
|
if (!BASE64URL_32_BYTES.test(privateKey)) {
|
|
18837
18837
|
throw new Error("Inference host private key is invalid.");
|
|
18838
18838
|
}
|
|
18839
|
-
if (!Number.isSafeInteger(
|
|
18839
|
+
if (!Number.isSafeInteger(record5.key_generation) || Number(record5.key_generation) < 1) {
|
|
18840
18840
|
throw new Error("Inference host key generation is invalid.");
|
|
18841
18841
|
}
|
|
18842
|
-
const createdAt = isoTimestamp(
|
|
18843
|
-
const updatedAt = isoTimestamp(
|
|
18842
|
+
const createdAt = isoTimestamp(record5.created_at, "Credential creation timestamp");
|
|
18843
|
+
const updatedAt = isoTimestamp(record5.updated_at, "Credential update timestamp");
|
|
18844
18844
|
return {
|
|
18845
18845
|
schema_version: 1,
|
|
18846
18846
|
issuer,
|
|
@@ -18849,7 +18849,7 @@ function validateInferenceHostCredential(value) {
|
|
|
18849
18849
|
host_id: hostId,
|
|
18850
18850
|
refresh_token: refreshToken,
|
|
18851
18851
|
x25519_private_key: privateKey,
|
|
18852
|
-
key_generation: Number(
|
|
18852
|
+
key_generation: Number(record5.key_generation),
|
|
18853
18853
|
created_at: createdAt,
|
|
18854
18854
|
updated_at: updatedAt
|
|
18855
18855
|
};
|
|
@@ -19109,17 +19109,17 @@ var init_credential_store = __esm({
|
|
|
19109
19109
|
if (!envelope || typeof envelope !== "object" || Array.isArray(envelope)) {
|
|
19110
19110
|
throw new Error("Inference credential fallback file is invalid.");
|
|
19111
19111
|
}
|
|
19112
|
-
const
|
|
19113
|
-
if (
|
|
19112
|
+
const record5 = envelope;
|
|
19113
|
+
if (record5.schema_version !== 1 || record5.namespace !== INFERENCE_CREDENTIAL_NAMESPACE || typeof record5.account_key !== "string") {
|
|
19114
19114
|
throw new Error("Inference credential fallback identity is invalid.");
|
|
19115
19115
|
}
|
|
19116
|
-
const credential = validateInferenceHostCredential(
|
|
19116
|
+
const credential = validateInferenceHostCredential(record5.credential);
|
|
19117
19117
|
const exactAccountKey = inferenceCredentialAccountKey({
|
|
19118
19118
|
issuer: credential.issuer,
|
|
19119
19119
|
clientId: credential.client_id,
|
|
19120
19120
|
hostId: credential.host_id
|
|
19121
19121
|
});
|
|
19122
|
-
if (
|
|
19122
|
+
if (record5.account_key !== exactAccountKey || accountKey2 && record5.account_key !== accountKey2) {
|
|
19123
19123
|
throw new Error("Inference credential fallback identity is invalid.");
|
|
19124
19124
|
}
|
|
19125
19125
|
return credential;
|
|
@@ -19169,22 +19169,22 @@ var init_credential_store = __esm({
|
|
|
19169
19169
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
19170
19170
|
throw new Error("Inference credential recovery file is invalid.");
|
|
19171
19171
|
}
|
|
19172
|
-
const
|
|
19173
|
-
if (Object.keys(
|
|
19172
|
+
const record5 = parsed;
|
|
19173
|
+
if (Object.keys(record5).sort().join("\0") !== [
|
|
19174
19174
|
"account_key",
|
|
19175
19175
|
"credential",
|
|
19176
19176
|
"namespace",
|
|
19177
19177
|
"schema_version"
|
|
19178
|
-
].join("\0") ||
|
|
19178
|
+
].join("\0") || record5.schema_version !== 1 || record5.namespace !== INFERENCE_CREDENTIAL_NAMESPACE || typeof record5.account_key !== "string") {
|
|
19179
19179
|
throw new Error("Inference credential recovery identity is invalid.");
|
|
19180
19180
|
}
|
|
19181
|
-
const credential = validateInferenceHostCredential(
|
|
19181
|
+
const credential = validateInferenceHostCredential(record5.credential);
|
|
19182
19182
|
const accountKey2 = inferenceCredentialAccountKey({
|
|
19183
19183
|
issuer: credential.issuer,
|
|
19184
19184
|
clientId: credential.client_id,
|
|
19185
19185
|
hostId: credential.host_id
|
|
19186
19186
|
});
|
|
19187
|
-
if (
|
|
19187
|
+
if (record5.account_key !== accountKey2) {
|
|
19188
19188
|
throw new Error("Inference credential recovery identity is invalid.");
|
|
19189
19189
|
}
|
|
19190
19190
|
return { accountKey: accountKey2, credential };
|
|
@@ -22981,26 +22981,26 @@ var require_resolve = __commonJS({
|
|
|
22981
22981
|
return true;
|
|
22982
22982
|
}
|
|
22983
22983
|
function countKeys(schema) {
|
|
22984
|
-
var
|
|
22984
|
+
var count4 = 0, item;
|
|
22985
22985
|
if (Array.isArray(schema)) {
|
|
22986
22986
|
for (var i = 0; i < schema.length; i++) {
|
|
22987
22987
|
item = schema[i];
|
|
22988
|
-
if (typeof item == "object")
|
|
22989
|
-
if (
|
|
22988
|
+
if (typeof item == "object") count4 += countKeys(item);
|
|
22989
|
+
if (count4 == Infinity) return Infinity;
|
|
22990
22990
|
}
|
|
22991
22991
|
} else {
|
|
22992
22992
|
for (var key in schema) {
|
|
22993
22993
|
if (key == "$ref") return Infinity;
|
|
22994
22994
|
if (SIMPLE_INLINED[key]) {
|
|
22995
|
-
|
|
22995
|
+
count4++;
|
|
22996
22996
|
} else {
|
|
22997
22997
|
item = schema[key];
|
|
22998
|
-
if (typeof item == "object")
|
|
22999
|
-
if (
|
|
22998
|
+
if (typeof item == "object") count4 += countKeys(item) + 1;
|
|
22999
|
+
if (count4 == Infinity) return Infinity;
|
|
23000
23000
|
}
|
|
23001
23001
|
}
|
|
23002
23002
|
}
|
|
23003
|
-
return
|
|
23003
|
+
return count4;
|
|
23004
23004
|
}
|
|
23005
23005
|
function getFullPath(id2, normalize) {
|
|
23006
23006
|
if (normalize !== false) id2 = normalizeId(id2);
|
|
@@ -30413,7 +30413,7 @@ var init_agent_state = __esm({
|
|
|
30413
30413
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(message);
|
|
30414
30414
|
return value;
|
|
30415
30415
|
};
|
|
30416
|
-
hasExactKeys = (
|
|
30416
|
+
hasExactKeys = (record5, keys) => Object.keys(record5).sort().join("\0") === [...keys].sort().join("\0");
|
|
30417
30417
|
assertInferenceAgentFailureFence = (value) => {
|
|
30418
30418
|
const message = "Inference Agent failure fence is invalid.";
|
|
30419
30419
|
const fence = assertPlainObject(value, message);
|
|
@@ -30596,17 +30596,17 @@ var init_agent_state = __esm({
|
|
|
30596
30596
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
30597
30597
|
throw new Error("Agent-driven inference next recovery state is invalid.");
|
|
30598
30598
|
}
|
|
30599
|
-
const
|
|
30600
|
-
if (Object.keys(
|
|
30599
|
+
const record5 = value;
|
|
30600
|
+
if (Object.keys(record5).sort().join("\0") !== ["schema_version", "operation_id", "requested_at"].sort().join("\0") || record5.schema_version !== "vtx_inference_agent_next_v1" || typeof record5.operation_id !== "string" || !record5.operation_id || typeof record5.requested_at !== "string" || !Number.isFinite(Date.parse(record5.requested_at))) {
|
|
30601
30601
|
throw new Error("Agent-driven inference next recovery state is invalid.");
|
|
30602
30602
|
}
|
|
30603
|
-
return
|
|
30603
|
+
return record5;
|
|
30604
30604
|
};
|
|
30605
30605
|
assertAttemptState = (value) => {
|
|
30606
30606
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
30607
30607
|
throw new Error("Agent-driven inference attempt state is invalid.");
|
|
30608
30608
|
}
|
|
30609
|
-
const
|
|
30609
|
+
const record5 = value;
|
|
30610
30610
|
const exactKeys = [
|
|
30611
30611
|
"schema_version",
|
|
30612
30612
|
"host_id",
|
|
@@ -30623,22 +30623,22 @@ var init_agent_state = __esm({
|
|
|
30623
30623
|
"pending_terminal"
|
|
30624
30624
|
];
|
|
30625
30625
|
const freshnessKeys = ["provider_dispatch_not_after", "provider_dispatch_local_not_after"];
|
|
30626
|
-
if ("execution_mode" in
|
|
30627
|
-
if (!["server", "client"].includes(String(
|
|
30626
|
+
if ("execution_mode" in record5) {
|
|
30627
|
+
if (!["server", "client"].includes(String(record5.execution_mode))) {
|
|
30628
30628
|
throw new Error("Agent-driven inference execution mode is invalid.");
|
|
30629
30629
|
}
|
|
30630
30630
|
exactKeys.push("execution_mode");
|
|
30631
30631
|
}
|
|
30632
|
-
if (freshnessKeys.some((key) => key in
|
|
30633
|
-
if (freshnessKeys.some((key) => typeof
|
|
30632
|
+
if (freshnessKeys.some((key) => key in record5)) {
|
|
30633
|
+
if (freshnessKeys.some((key) => typeof record5[key] !== "string" || !Number.isFinite(Date.parse(record5[key])))) {
|
|
30634
30634
|
throw new Error("Agent-driven inference freshness recovery state is invalid.");
|
|
30635
30635
|
}
|
|
30636
30636
|
exactKeys.push(...freshnessKeys);
|
|
30637
30637
|
}
|
|
30638
|
-
if (Object.keys(
|
|
30638
|
+
if (Object.keys(record5).sort().join("\0") !== exactKeys.slice().sort().join("\0") || record5.schema_version !== "vtx_inference_agent_attempt_v1" || typeof record5.host_id !== "string" || !record5.host_id || typeof record5.job_id !== "string" || !record5.job_id || typeof record5.attempt_id !== "string" || !record5.attempt_id || typeof record5.claim_handle !== "string" || !record5.claim_handle || typeof record5.completion_operation_id !== "string" || !record5.completion_operation_id || typeof record5.failure_operation_id !== "string" || !record5.failure_operation_id || typeof record5.requested_model !== "string" || !record5.requested_model || typeof record5.requested_reasoning_effort !== "string" || !record5.requested_reasoning_effort || !["provider_response", "decision_candidate"].includes(String(record5.response_mode)) || typeof record5.deadline_at !== "string" || !Number.isFinite(Date.parse(record5.deadline_at)) || typeof record5.received_at !== "string" || !Number.isFinite(Date.parse(record5.received_at))) {
|
|
30639
30639
|
throw new Error("Agent-driven inference attempt state is invalid.");
|
|
30640
30640
|
}
|
|
30641
|
-
const pending2 =
|
|
30641
|
+
const pending2 = record5.pending_terminal;
|
|
30642
30642
|
if (pending2 !== null) {
|
|
30643
30643
|
if (!pending2 || typeof pending2 !== "object" || Array.isArray(pending2)) {
|
|
30644
30644
|
throw new Error("Agent-driven inference terminal recovery state is invalid.");
|
|
@@ -30655,7 +30655,7 @@ var init_agent_state = __esm({
|
|
|
30655
30655
|
throw new Error("Agent-driven inference terminal recovery state is invalid.");
|
|
30656
30656
|
}
|
|
30657
30657
|
}
|
|
30658
|
-
return
|
|
30658
|
+
return record5;
|
|
30659
30659
|
};
|
|
30660
30660
|
}
|
|
30661
30661
|
});
|
|
@@ -30902,14 +30902,14 @@ var init_runner = __esm({
|
|
|
30902
30902
|
};
|
|
30903
30903
|
};
|
|
30904
30904
|
safeInteger = (value, minimum) => typeof value === "number" && Number.isSafeInteger(value) && value >= minimum;
|
|
30905
|
-
exactObjectKeys = (
|
|
30905
|
+
exactObjectKeys = (record5, keys) => Object.keys(record5).sort().join("\0") === [...keys].sort().join("\0");
|
|
30906
30906
|
validIso = (value) => typeof value === "string" && value.length > 0 && Number.isFinite(Date.parse(value));
|
|
30907
30907
|
validateAttemptReceipt = (value) => {
|
|
30908
30908
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
30909
30909
|
throw new Error("Inference host attempt receipt is invalid.");
|
|
30910
30910
|
}
|
|
30911
|
-
const
|
|
30912
|
-
if (!exactObjectKeys(
|
|
30911
|
+
const record5 = value;
|
|
30912
|
+
if (!exactObjectKeys(record5, [
|
|
30913
30913
|
"schema_version",
|
|
30914
30914
|
"attempt_id",
|
|
30915
30915
|
"job_id",
|
|
@@ -30925,30 +30925,30 @@ var init_runner = __esm({
|
|
|
30925
30925
|
"start_request",
|
|
30926
30926
|
"terminal_request",
|
|
30927
30927
|
"updated_at"
|
|
30928
|
-
]) ||
|
|
30928
|
+
]) || record5.schema_version !== ATTEMPT_RECEIPT_SCHEMA_VERSION || typeof record5.attempt_id !== "string" || !record5.attempt_id || typeof record5.job_id !== "string" || !record5.job_id || !safeInteger(record5.profile_id, 1) || typeof record5.input_sha256 !== "string" || !/^[0-9a-f]{64}$/u.test(record5.input_sha256) || !safeInteger(record5.claim_generation, 1) || !safeInteger(record5.attempt_index, 0) || !["claimed", "started", "dispatched", "terminal_pending"].includes(String(record5.phase)) || !["not_dispatched", "confirmed_dispatched", "outcome_unknown"].includes(String(record5.dispatch_outcome)) || record5.terminal_operation_id !== null && typeof record5.terminal_operation_id !== "string" || !safeInteger(record5.job_heartbeat_sequence, 0) || !validIso(record5.updated_at)) {
|
|
30929
30929
|
throw new Error("Inference host attempt receipt is invalid.");
|
|
30930
30930
|
}
|
|
30931
|
-
const claim =
|
|
30932
|
-
if (!claim || typeof claim !== "object" || Array.isArray(claim) || claim.claim_state !== "claimed" || claim.job_id !==
|
|
30931
|
+
const claim = record5.claim;
|
|
30932
|
+
if (!claim || typeof claim !== "object" || Array.isArray(claim) || claim.claim_state !== "claimed" || claim.job_id !== record5.job_id || claim.claim_generation !== record5.claim_generation || claim.attempt_index !== record5.attempt_index || claim.input_sha256 !== record5.input_sha256) {
|
|
30933
30933
|
throw new Error("Inference host persisted claim is invalid.");
|
|
30934
30934
|
}
|
|
30935
|
-
const startRequest = attemptStartRequestSchema.parse(
|
|
30936
|
-
if (startRequest.attempt_id !==
|
|
30935
|
+
const startRequest = attemptStartRequestSchema.parse(record5.start_request);
|
|
30936
|
+
if (startRequest.attempt_id !== record5.attempt_id || startRequest.job_id !== record5.job_id || startRequest.claim_generation !== record5.claim_generation || startRequest.attempt_index !== record5.attempt_index || startRequest.input_sha256 !== record5.input_sha256) {
|
|
30937
30937
|
throw new Error("Inference host persisted start request is invalid.");
|
|
30938
30938
|
}
|
|
30939
30939
|
let terminalRequest = null;
|
|
30940
|
-
if (
|
|
30941
|
-
const schemaVersion =
|
|
30942
|
-
terminalRequest = schemaVersion === "external_inference_job_complete_v1" ? jobCompleteRequestSchema.parse(
|
|
30943
|
-
if (terminalRequest.attempt_id !==
|
|
30940
|
+
if (record5.terminal_request !== null) {
|
|
30941
|
+
const schemaVersion = record5.terminal_request.schema_version;
|
|
30942
|
+
terminalRequest = schemaVersion === "external_inference_job_complete_v1" ? jobCompleteRequestSchema.parse(record5.terminal_request) : jobFailRequestSchema.parse(record5.terminal_request);
|
|
30943
|
+
if (terminalRequest.attempt_id !== record5.attempt_id || terminalRequest.job_id !== record5.job_id || terminalRequest.claim_generation !== record5.claim_generation) {
|
|
30944
30944
|
throw new Error("Inference host persisted terminal request is invalid.");
|
|
30945
30945
|
}
|
|
30946
30946
|
}
|
|
30947
|
-
if (
|
|
30947
|
+
if (record5.phase === "terminal_pending" !== (terminalRequest !== null)) {
|
|
30948
30948
|
throw new Error("Inference host terminal receipt phase is invalid.");
|
|
30949
30949
|
}
|
|
30950
30950
|
return {
|
|
30951
|
-
...
|
|
30951
|
+
...record5,
|
|
30952
30952
|
claim,
|
|
30953
30953
|
start_request: startRequest,
|
|
30954
30954
|
terminal_request: terminalRequest
|
|
@@ -30958,7 +30958,7 @@ var init_runner = __esm({
|
|
|
30958
30958
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
30959
30959
|
throw new Error("Inference host runtime receipt is invalid.");
|
|
30960
30960
|
}
|
|
30961
|
-
const
|
|
30961
|
+
const record5 = value;
|
|
30962
30962
|
const legacyKeys = [
|
|
30963
30963
|
"schema_version",
|
|
30964
30964
|
"host_id",
|
|
@@ -30974,17 +30974,17 @@ var init_runner = __esm({
|
|
|
30974
30974
|
"updated_at"
|
|
30975
30975
|
];
|
|
30976
30976
|
const currentKeys = [...legacyKeys, "pending_claim_request"];
|
|
30977
|
-
if (!(exactObjectKeys(
|
|
30977
|
+
if (!(exactObjectKeys(record5, legacyKeys) || exactObjectKeys(record5, currentKeys) || exactObjectKeys(record5, [...legacyKeys, "last_advertisement"]) || exactObjectKeys(record5, [...currentKeys, "last_advertisement"])) || record5.schema_version !== RUNTIME_RECEIPT_SCHEMA_VERSION || typeof record5.host_id !== "string" || !record5.host_id || !safeInteger(record5.host_generation, 1) || !safeInteger(record5.key_generation, 1) || !safeInteger(record5.advertisement_generation, 1) || record5.advertisement_expires_at !== null && !validIso(record5.advertisement_expires_at) || typeof record5.registered !== "boolean" || !safeInteger(record5.host_heartbeat_sequence, 0) || !safeInteger(record5.claim_sequence, 0) || !record5.attempts || typeof record5.attempts !== "object" || Array.isArray(record5.attempts) || !validIso(record5.updated_at)) {
|
|
30978
30978
|
throw new Error("Inference host runtime receipt is invalid.");
|
|
30979
30979
|
}
|
|
30980
|
-
const lastAdvertisement =
|
|
30981
|
-
const pendingAdvertisement =
|
|
30982
|
-
const pendingClaimRequest =
|
|
30983
|
-
if (pendingClaimRequest && (pendingClaimRequest.host_id !==
|
|
30980
|
+
const lastAdvertisement = record5.last_advertisement == null ? null : hostAdvertisementSchema.parse(record5.last_advertisement);
|
|
30981
|
+
const pendingAdvertisement = record5.pending_advertisement === null ? null : hostAdvertisementSchema.parse(record5.pending_advertisement);
|
|
30982
|
+
const pendingClaimRequest = record5.pending_claim_request == null ? null : jobClaimRequestSchema.parse(record5.pending_claim_request);
|
|
30983
|
+
if (pendingClaimRequest && (pendingClaimRequest.host_id !== record5.host_id || pendingClaimRequest.host_generation !== record5.host_generation || pendingClaimRequest.key_generation !== record5.key_generation || pendingClaimRequest.advertisement_generation > Number(record5.advertisement_generation))) {
|
|
30984
30984
|
throw new Error("Inference host pending claim receipt is invalid.");
|
|
30985
30985
|
}
|
|
30986
30986
|
const attempts = Object.fromEntries(
|
|
30987
|
-
Object.entries(
|
|
30987
|
+
Object.entries(record5.attempts).map(([key, attempt]) => {
|
|
30988
30988
|
const validated = validateAttemptReceipt(attempt);
|
|
30989
30989
|
if (key !== validated.attempt_id) {
|
|
30990
30990
|
throw new Error("Inference host attempt receipt key is invalid.");
|
|
@@ -30993,9 +30993,9 @@ var init_runner = __esm({
|
|
|
30993
30993
|
})
|
|
30994
30994
|
);
|
|
30995
30995
|
return {
|
|
30996
|
-
...
|
|
30996
|
+
...record5,
|
|
30997
30997
|
pending_advertisement: pendingAdvertisement,
|
|
30998
|
-
..."last_advertisement" in
|
|
30998
|
+
..."last_advertisement" in record5 ? { last_advertisement: lastAdvertisement } : {},
|
|
30999
30999
|
pending_claim_request: pendingClaimRequest,
|
|
31000
31000
|
attempts
|
|
31001
31001
|
};
|
|
@@ -35785,9 +35785,9 @@ var init_codex_adapter = __esm({
|
|
|
35785
35785
|
continue;
|
|
35786
35786
|
}
|
|
35787
35787
|
if (!event || typeof event !== "object" || Array.isArray(event)) continue;
|
|
35788
|
-
const
|
|
35789
|
-
const payload =
|
|
35790
|
-
if (
|
|
35788
|
+
const record5 = event;
|
|
35789
|
+
const payload = record5.payload;
|
|
35790
|
+
if (record5.type === "session_meta" && payload && typeof payload === "object" && !Array.isArray(payload) && resolve3(String(payload.cwd || "")) === resolve3(checkpoint.workspacePath)) {
|
|
35791
35791
|
threadPaths.add(path);
|
|
35792
35792
|
break;
|
|
35793
35793
|
}
|
|
@@ -36954,16 +36954,16 @@ $items = @(Get-CimInstance Win32_Process | Where-Object { $_.Name -in @('node.ex
|
|
|
36954
36954
|
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
36955
36955
|
throw new Error("Windows process ownership inventory was invalid.");
|
|
36956
36956
|
}
|
|
36957
|
-
const
|
|
36958
|
-
if (!Number.isSafeInteger(
|
|
36957
|
+
const record5 = entry;
|
|
36958
|
+
if (!Number.isSafeInteger(record5.process_id) || Number(record5.process_id) < 1 || typeof record5.name !== "string" || record5.executable_path !== null && typeof record5.executable_path !== "string" || record5.command_line !== null && typeof record5.command_line !== "string" || record5.creation_date !== null && typeof record5.creation_date !== "string") {
|
|
36959
36959
|
throw new Error("Windows process ownership inventory was invalid.");
|
|
36960
36960
|
}
|
|
36961
36961
|
return {
|
|
36962
|
-
process_id: Number(
|
|
36963
|
-
name:
|
|
36964
|
-
executable_path:
|
|
36965
|
-
command_line:
|
|
36966
|
-
creation_date:
|
|
36962
|
+
process_id: Number(record5.process_id),
|
|
36963
|
+
name: record5.name,
|
|
36964
|
+
executable_path: record5.executable_path,
|
|
36965
|
+
command_line: record5.command_line,
|
|
36966
|
+
creation_date: record5.creation_date
|
|
36967
36967
|
};
|
|
36968
36968
|
});
|
|
36969
36969
|
};
|
|
@@ -41457,14 +41457,14 @@ var init_exo_credential_store = __esm({
|
|
|
41457
41457
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
41458
41458
|
throw new Error("Stored Exo credential is invalid.");
|
|
41459
41459
|
}
|
|
41460
|
-
const
|
|
41461
|
-
if (typeof
|
|
41460
|
+
const record5 = value;
|
|
41461
|
+
if (typeof record5.provider !== "string" || typeof record5.api_key !== "string") {
|
|
41462
41462
|
throw new Error("Stored Exo credential is invalid.");
|
|
41463
41463
|
}
|
|
41464
|
-
const provider = validateProvider(
|
|
41465
|
-
const apiKey = validateApiKey(
|
|
41464
|
+
const provider = validateProvider(record5.provider);
|
|
41465
|
+
const apiKey = validateApiKey(record5.api_key);
|
|
41466
41466
|
const identity2 = credentialIdentity(provider, apiKey);
|
|
41467
|
-
if (
|
|
41467
|
+
if (record5.schema_version !== 1 || record5.adapter !== "exo" || record5.identity !== identity2 || Object.keys(record5).sort().join(",") !== "adapter,api_key,identity,provider,schema_version") {
|
|
41468
41468
|
throw new Error("Stored Exo credential failed validation.");
|
|
41469
41469
|
}
|
|
41470
41470
|
return { provider, apiKey, identity: identity2 };
|
|
@@ -41658,11 +41658,11 @@ var init_pi_credential_store = __esm({
|
|
|
41658
41658
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
41659
41659
|
throw new Error("Stored Pi credential is invalid.");
|
|
41660
41660
|
}
|
|
41661
|
-
const
|
|
41662
|
-
const provider = validateProvider2(String(
|
|
41663
|
-
const apiKey = validateApiKey2(String(
|
|
41661
|
+
const record5 = value;
|
|
41662
|
+
const provider = validateProvider2(String(record5.provider ?? ""));
|
|
41663
|
+
const apiKey = validateApiKey2(String(record5.api_key ?? ""));
|
|
41664
41664
|
const identity2 = credentialIdentity2(provider, apiKey);
|
|
41665
|
-
if (
|
|
41665
|
+
if (record5.schema_version !== 1 || record5.adapter !== "pi" || record5.identity !== identity2 || Object.keys(record5).sort().join(",") !== "adapter,api_key,identity,provider,schema_version") {
|
|
41666
41666
|
throw new Error("Stored Pi credential failed validation.");
|
|
41667
41667
|
}
|
|
41668
41668
|
return { provider, apiKey, identity: identity2 };
|
|
@@ -41815,10 +41815,10 @@ var init_deepseek_credential_store = __esm({
|
|
|
41815
41815
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
41816
41816
|
throw new Error("Stored DeepSeek Harness credential is invalid.");
|
|
41817
41817
|
}
|
|
41818
|
-
const
|
|
41819
|
-
const apiKey = validateApiKey3(String(
|
|
41818
|
+
const record5 = value;
|
|
41819
|
+
const apiKey = validateApiKey3(String(record5.api_key ?? ""));
|
|
41820
41820
|
const identity2 = credentialIdentity3(apiKey);
|
|
41821
|
-
if (
|
|
41821
|
+
if (record5.schema_version !== 1 || record5.adapter !== "deepseek-harness" || record5.identity !== identity2 || Object.keys(record5).sort().join(",") !== "adapter,api_key,identity,schema_version") {
|
|
41822
41822
|
throw new Error("Stored DeepSeek Harness credential failed validation.");
|
|
41823
41823
|
}
|
|
41824
41824
|
return { apiKey, identity: identity2 };
|
|
@@ -41971,6 +41971,9 @@ var init_runtime_policy_generated = __esm({
|
|
|
41971
41971
|
"lib/runtime-policy.generated.json with { type: 'json' }"() {
|
|
41972
41972
|
runtime_policy_generated_default = {
|
|
41973
41973
|
ui: {
|
|
41974
|
+
performance_defaults: {
|
|
41975
|
+
default_timeframe: "30d"
|
|
41976
|
+
},
|
|
41974
41977
|
auth_bootstrap_retry: {
|
|
41975
41978
|
max_attempts: 3,
|
|
41976
41979
|
jitter_milliseconds: 750,
|
|
@@ -42196,28 +42199,28 @@ var init_service = __esm({
|
|
|
42196
42199
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
42197
42200
|
throw new Error("Inference-host service worker is invalid.");
|
|
42198
42201
|
}
|
|
42199
|
-
const
|
|
42200
|
-
if (typeof
|
|
42202
|
+
const record5 = value;
|
|
42203
|
+
if (typeof record5.instance_name !== "string" || !/^[a-z0-9](?:[a-z0-9-]{0,46}[a-z0-9])?$/u.test(record5.instance_name) || typeof record5.adapter !== "string" || !isDurableInferenceAdapterId(record5.adapter) || typeof record5.display_name !== "string" || !record5.display_name || record5.max_concurrency !== null && (!Number.isSafeInteger(record5.max_concurrency) || Number(record5.max_concurrency) < 1) || record5.authenticated_account_email !== null && typeof record5.authenticated_account_email !== "string" || record5.authenticated_account_identity !== void 0 && record5.authenticated_account_identity !== null && typeof record5.authenticated_account_identity !== "string" || record5.authenticated_account_plan !== null && typeof record5.authenticated_account_plan !== "string") {
|
|
42201
42204
|
throw new Error("Inference-host service worker is invalid.");
|
|
42202
42205
|
}
|
|
42203
42206
|
return {
|
|
42204
|
-
instance_name:
|
|
42205
|
-
adapter:
|
|
42206
|
-
display_name:
|
|
42207
|
-
max_concurrency:
|
|
42208
|
-
authenticated_account_identity:
|
|
42209
|
-
authenticated_account_email:
|
|
42210
|
-
authenticated_account_plan:
|
|
42211
|
-
runtime_environment: assertRuntimeEnvironment(
|
|
42207
|
+
instance_name: record5.instance_name,
|
|
42208
|
+
adapter: record5.adapter,
|
|
42209
|
+
display_name: record5.display_name,
|
|
42210
|
+
max_concurrency: record5.max_concurrency === null ? null : Number(record5.max_concurrency),
|
|
42211
|
+
authenticated_account_identity: record5.authenticated_account_identity,
|
|
42212
|
+
authenticated_account_email: record5.authenticated_account_email,
|
|
42213
|
+
authenticated_account_plan: record5.authenticated_account_plan,
|
|
42214
|
+
runtime_environment: assertRuntimeEnvironment(record5.runtime_environment)
|
|
42212
42215
|
};
|
|
42213
42216
|
};
|
|
42214
42217
|
assertManifest = (value) => {
|
|
42215
42218
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
42216
42219
|
throw new Error("Inference-host service manifest is invalid.");
|
|
42217
42220
|
}
|
|
42218
|
-
const
|
|
42219
|
-
if (
|
|
42220
|
-
const legacy =
|
|
42221
|
+
const record5 = value;
|
|
42222
|
+
if (record5.schema_version === "vtx_inference_service_v1") {
|
|
42223
|
+
const legacy = record5;
|
|
42221
42224
|
if (legacy.adapter !== "codex" || typeof legacy.installed_at !== "string" || !Number.isFinite(Date.parse(legacy.installed_at)) || typeof legacy.executable !== "string" || !legacy.executable || typeof legacy.script !== "string" || !legacy.script || typeof legacy.display_name !== "string" || !legacy.display_name || typeof legacy.log_path !== "string" || !legacy.log_path) throw new Error("Inference-host service manifest is invalid.");
|
|
42222
42225
|
const runtime_environment = withoutConcurrencyLimit(
|
|
42223
42226
|
assertRuntimeEnvironment(legacy.runtime_environment)
|
|
@@ -42241,8 +42244,8 @@ var init_service = __esm({
|
|
|
42241
42244
|
workers: [worker]
|
|
42242
42245
|
};
|
|
42243
42246
|
}
|
|
42244
|
-
if (
|
|
42245
|
-
const legacy =
|
|
42247
|
+
if (record5.schema_version === "vtx_inference_service_v2") {
|
|
42248
|
+
const legacy = record5;
|
|
42246
42249
|
if (typeof legacy.installed_at !== "string" || !Number.isFinite(Date.parse(legacy.installed_at)) || typeof legacy.executable !== "string" || !legacy.executable || typeof legacy.script !== "string" || !legacy.script || typeof legacy.log_path !== "string" || !legacy.log_path || !Array.isArray(legacy.workers) || legacy.workers.length < 1) {
|
|
42247
42250
|
throw new Error("Inference-host service manifest is invalid.");
|
|
42248
42251
|
}
|
|
@@ -42275,19 +42278,19 @@ var init_service = __esm({
|
|
|
42275
42278
|
workers: workers2
|
|
42276
42279
|
};
|
|
42277
42280
|
}
|
|
42278
|
-
if (
|
|
42281
|
+
if (record5.schema_version !== "vtx_inference_service_v3" || typeof record5.installed_at !== "string" || !Number.isFinite(Date.parse(record5.installed_at)) || typeof record5.executable !== "string" || !record5.executable || typeof record5.script !== "string" || !record5.script || typeof record5.log_path !== "string" || !record5.log_path || !Array.isArray(record5.workers) || record5.workers.length < 1) {
|
|
42279
42282
|
throw new Error("Inference-host service manifest is invalid.");
|
|
42280
42283
|
}
|
|
42281
|
-
assertServicePath(
|
|
42282
|
-
assertServicePath(
|
|
42283
|
-
assertServicePath(
|
|
42284
|
-
const workers =
|
|
42284
|
+
assertServicePath(record5.executable);
|
|
42285
|
+
assertServicePath(record5.script);
|
|
42286
|
+
assertServicePath(record5.log_path);
|
|
42287
|
+
const workers = record5.workers.map(assertWorker);
|
|
42285
42288
|
if (new Set(workers.map((worker) => worker.instance_name)).size !== workers.length) {
|
|
42286
42289
|
throw new Error("Inference-host service worker names must be unique.");
|
|
42287
42290
|
}
|
|
42288
42291
|
return {
|
|
42289
|
-
...
|
|
42290
|
-
generation: manifestGeneration(
|
|
42292
|
+
...record5,
|
|
42293
|
+
generation: manifestGeneration(record5.generation, String(record5.installed_at)),
|
|
42291
42294
|
workers
|
|
42292
42295
|
};
|
|
42293
42296
|
};
|
|
@@ -42295,11 +42298,11 @@ var init_service = __esm({
|
|
|
42295
42298
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
42296
42299
|
throw new Error("Inference-host service runtime state is invalid.");
|
|
42297
42300
|
}
|
|
42298
|
-
const
|
|
42299
|
-
if (
|
|
42301
|
+
const record5 = value;
|
|
42302
|
+
if (record5.schema_version !== "vtx_inference_service_runtime_v1" || typeof record5.manifest_generation !== "string" || record5.rejected_manifest_generation !== void 0 && record5.rejected_manifest_generation !== null && typeof record5.rejected_manifest_generation !== "string" || typeof record5.updated_at !== "string" || !Number.isFinite(Date.parse(record5.updated_at)) || !Array.isArray(record5.workers)) {
|
|
42300
42303
|
throw new Error("Inference-host service runtime state is invalid.");
|
|
42301
42304
|
}
|
|
42302
|
-
const workers =
|
|
42305
|
+
const workers = record5.workers.map((worker) => {
|
|
42303
42306
|
if (!worker || typeof worker !== "object" || Array.isArray(worker)) {
|
|
42304
42307
|
throw new Error("Inference-host service worker runtime state is invalid.");
|
|
42305
42308
|
}
|
|
@@ -42313,17 +42316,17 @@ var init_service = __esm({
|
|
|
42313
42316
|
error: item.error
|
|
42314
42317
|
};
|
|
42315
42318
|
});
|
|
42316
|
-
return { ...
|
|
42319
|
+
return { ...record5, workers };
|
|
42317
42320
|
};
|
|
42318
42321
|
assertDesiredState = (value) => {
|
|
42319
42322
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
42320
42323
|
throw new Error("Inference-host service desired state is invalid.");
|
|
42321
42324
|
}
|
|
42322
|
-
const
|
|
42323
|
-
if (
|
|
42325
|
+
const record5 = value;
|
|
42326
|
+
if (record5.schema_version !== "vtx_inference_service_desired_v1" || typeof record5.desired_running !== "boolean" || typeof record5.updated_at !== "string" || !Number.isFinite(Date.parse(record5.updated_at))) {
|
|
42324
42327
|
throw new Error("Inference-host service desired state is invalid.");
|
|
42325
42328
|
}
|
|
42326
|
-
return
|
|
42329
|
+
return record5;
|
|
42327
42330
|
};
|
|
42328
42331
|
readInferenceHostServiceManifest = async (path) => {
|
|
42329
42332
|
const raw = await readInferencePrivateFile(path, "Inference-host service manifest");
|
|
@@ -43410,10 +43413,10 @@ ${result2.stderr}`)) {
|
|
|
43410
43413
|
manifest_generation: appliedManifest.generation,
|
|
43411
43414
|
rejected_manifest_generation: rejectedManifestGeneration,
|
|
43412
43415
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
43413
|
-
workers: [...workers.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([instanceName,
|
|
43416
|
+
workers: [...workers.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([instanceName, record5]) => ({
|
|
43414
43417
|
instance_name: instanceName,
|
|
43415
|
-
state:
|
|
43416
|
-
error:
|
|
43418
|
+
state: record5.state,
|
|
43419
|
+
error: record5.error
|
|
43417
43420
|
}))
|
|
43418
43421
|
};
|
|
43419
43422
|
runtimeWriteChain = runtimeWriteChain.then(async () => {
|
|
@@ -43422,10 +43425,10 @@ ${result2.stderr}`)) {
|
|
|
43422
43425
|
});
|
|
43423
43426
|
await runtimeWriteChain;
|
|
43424
43427
|
};
|
|
43425
|
-
const updateRecord = async (
|
|
43426
|
-
if (workers.get(
|
|
43427
|
-
|
|
43428
|
-
|
|
43428
|
+
const updateRecord = async (record5, state, error48 = null) => {
|
|
43429
|
+
if (workers.get(record5.worker.instance_name) !== record5) return;
|
|
43430
|
+
record5.state = state;
|
|
43431
|
+
record5.error = error48;
|
|
43429
43432
|
await persistRuntime();
|
|
43430
43433
|
};
|
|
43431
43434
|
const waitRetry = async (milliseconds, controller) => {
|
|
@@ -43443,15 +43446,15 @@ ${result2.stderr}`)) {
|
|
|
43443
43446
|
signal.removeEventListener("abort", finishAbort);
|
|
43444
43447
|
}
|
|
43445
43448
|
};
|
|
43446
|
-
const superviseWorker = async (serviceManifest,
|
|
43449
|
+
const superviseWorker = async (serviceManifest, record5) => {
|
|
43447
43450
|
let failures = 0;
|
|
43448
|
-
while (!signal.aborted && !quiesceSignal.aborted && !
|
|
43451
|
+
while (!signal.aborted && !quiesceSignal.aborted && !record5.controller.signal.aborted && await readDesiredAcrossAtomicReplacement(desiredPath)) {
|
|
43449
43452
|
try {
|
|
43450
|
-
await updateRecord(
|
|
43453
|
+
await updateRecord(record5, "starting");
|
|
43451
43454
|
const attemptController = new AbortController();
|
|
43452
43455
|
const forwardAbort = () => attemptController.abort();
|
|
43453
43456
|
signal.addEventListener("abort", forwardAbort, { once: true });
|
|
43454
|
-
|
|
43457
|
+
record5.controller.signal.addEventListener("abort", forwardAbort, { once: true });
|
|
43455
43458
|
let result2;
|
|
43456
43459
|
let launchSettled = false;
|
|
43457
43460
|
let readinessTask = Promise.resolve();
|
|
@@ -43459,15 +43462,15 @@ ${result2.stderr}`)) {
|
|
|
43459
43462
|
try {
|
|
43460
43463
|
result2 = await launch(
|
|
43461
43464
|
serviceManifest,
|
|
43462
|
-
|
|
43465
|
+
record5.worker,
|
|
43463
43466
|
attemptController.signal,
|
|
43464
43467
|
() => {
|
|
43465
43468
|
if (readinessSignalled) return;
|
|
43466
43469
|
readinessSignalled = true;
|
|
43467
43470
|
readinessTask = (async () => {
|
|
43468
43471
|
await sleep4(500);
|
|
43469
|
-
if (!launchSettled && !attemptController.signal.aborted && !
|
|
43470
|
-
await updateRecord(
|
|
43472
|
+
if (!launchSettled && !attemptController.signal.aborted && !record5.controller.signal.aborted && !signal.aborted) {
|
|
43473
|
+
await updateRecord(record5, "running");
|
|
43471
43474
|
}
|
|
43472
43475
|
})();
|
|
43473
43476
|
},
|
|
@@ -43477,70 +43480,70 @@ ${result2.stderr}`)) {
|
|
|
43477
43480
|
launchSettled = true;
|
|
43478
43481
|
attemptController.abort();
|
|
43479
43482
|
signal.removeEventListener("abort", forwardAbort);
|
|
43480
|
-
|
|
43483
|
+
record5.controller.signal.removeEventListener("abort", forwardAbort);
|
|
43481
43484
|
await readinessTask;
|
|
43482
43485
|
}
|
|
43483
43486
|
if (result2.cooperativeStopTimedOut) {
|
|
43484
|
-
await updateRecord(
|
|
43487
|
+
await updateRecord(record5, "failed", "worker_cooperative_stop_timeout");
|
|
43485
43488
|
await appendServiceLog(serviceManifest.log_path, "worker_cooperative_stop_timeout", {
|
|
43486
|
-
instance_name:
|
|
43489
|
+
instance_name: record5.worker.instance_name
|
|
43487
43490
|
});
|
|
43488
43491
|
throw new Error("worker_cooperative_stop_timeout");
|
|
43489
43492
|
}
|
|
43490
|
-
if (signal.aborted || quiesceSignal.aborted ||
|
|
43493
|
+
if (signal.aborted || quiesceSignal.aborted || record5.controller.signal.aborted || !await readDesiredAcrossAtomicReplacement(desiredPath)) break;
|
|
43491
43494
|
failures = result2.uptimeMs >= runtime_policy_generated_default.external_inference.service.restart_stable_uptime_ms ? 0 : failures + 1;
|
|
43492
43495
|
const retryAfterMs = Math.min(runtime_policy_generated_default.external_inference.service.restart_backoff_base_ms * 2 ** Math.min(failures, runtime_policy_generated_default.external_inference.service.restart_exponent_max), runtime_policy_generated_default.external_inference.service.restart_backoff_max_ms);
|
|
43493
|
-
await updateRecord(
|
|
43496
|
+
await updateRecord(record5, "failed", "worker_exited");
|
|
43494
43497
|
await appendServiceLog(serviceManifest.log_path, "worker_exited", {
|
|
43495
|
-
instance_name:
|
|
43498
|
+
instance_name: record5.worker.instance_name,
|
|
43496
43499
|
exit_code: result2.exitCode,
|
|
43497
43500
|
uptime_ms: result2.uptimeMs,
|
|
43498
43501
|
drain_reason: result2.drainReason ?? null,
|
|
43499
43502
|
retry_after_ms: retryAfterMs
|
|
43500
43503
|
});
|
|
43501
|
-
await waitRetry(retryAfterMs,
|
|
43504
|
+
await waitRetry(retryAfterMs, record5.controller);
|
|
43502
43505
|
} catch (error48) {
|
|
43503
43506
|
if (error48 instanceof Error && error48.message === "worker_cooperative_stop_timeout") throw error48;
|
|
43504
|
-
if (signal.aborted || quiesceSignal.aborted ||
|
|
43507
|
+
if (signal.aborted || quiesceSignal.aborted || record5.controller.signal.aborted) break;
|
|
43505
43508
|
failures += 1;
|
|
43506
43509
|
const retryAfterMs = Math.min(runtime_policy_generated_default.external_inference.service.restart_backoff_base_ms * 2 ** Math.min(failures, runtime_policy_generated_default.external_inference.service.restart_exponent_max), runtime_policy_generated_default.external_inference.service.restart_backoff_max_ms);
|
|
43507
|
-
await updateRecord(
|
|
43510
|
+
await updateRecord(record5, "failed", "worker_launch_failed");
|
|
43508
43511
|
await appendServiceLog(serviceManifest.log_path, "worker_launch_failed", {
|
|
43509
|
-
instance_name:
|
|
43512
|
+
instance_name: record5.worker.instance_name,
|
|
43510
43513
|
error: error48 instanceof Error ? error48.message : "unknown",
|
|
43511
43514
|
retry_after_ms: retryAfterMs
|
|
43512
43515
|
});
|
|
43513
|
-
await waitRetry(retryAfterMs,
|
|
43516
|
+
await waitRetry(retryAfterMs, record5.controller);
|
|
43514
43517
|
}
|
|
43515
43518
|
}
|
|
43516
43519
|
};
|
|
43517
43520
|
const startWorker = (serviceManifest, worker) => {
|
|
43518
|
-
const
|
|
43521
|
+
const record5 = {
|
|
43519
43522
|
worker,
|
|
43520
43523
|
controller: new AbortController(),
|
|
43521
43524
|
promise: Promise.resolve(),
|
|
43522
43525
|
state: "starting",
|
|
43523
43526
|
error: null
|
|
43524
43527
|
};
|
|
43525
|
-
workers.set(worker.instance_name,
|
|
43526
|
-
|
|
43528
|
+
workers.set(worker.instance_name, record5);
|
|
43529
|
+
record5.promise = superviseWorker(serviceManifest, record5);
|
|
43527
43530
|
};
|
|
43528
43531
|
const reconcile = async (next) => {
|
|
43529
43532
|
const nextByName = new Map(next.workers.map((worker) => [worker.instance_name, worker]));
|
|
43530
|
-
const retiring = [...workers.values()].filter((
|
|
43531
|
-
const nextWorker = nextByName.get(
|
|
43532
|
-
return !nextWorker || !sameWorker(
|
|
43533
|
+
const retiring = [...workers.values()].filter((record5) => {
|
|
43534
|
+
const nextWorker = nextByName.get(record5.worker.instance_name);
|
|
43535
|
+
return !nextWorker || !sameWorker(record5.worker, nextWorker);
|
|
43533
43536
|
});
|
|
43534
|
-
for (const
|
|
43535
|
-
|
|
43536
|
-
await updateRecord(
|
|
43537
|
+
for (const record5 of retiring) {
|
|
43538
|
+
record5.controller.abort();
|
|
43539
|
+
await updateRecord(record5, "draining");
|
|
43537
43540
|
}
|
|
43538
|
-
const settled = await Promise.allSettled(retiring.map((
|
|
43541
|
+
const settled = await Promise.allSettled(retiring.map((record5) => record5.promise));
|
|
43539
43542
|
const failedDrain = settled.find(
|
|
43540
43543
|
(result2) => result2.status === "rejected"
|
|
43541
43544
|
);
|
|
43542
43545
|
if (failedDrain) {
|
|
43543
|
-
for (const
|
|
43546
|
+
for (const record5 of retiring) workers.delete(record5.worker.instance_name);
|
|
43544
43547
|
for (const worker of appliedManifest.workers) {
|
|
43545
43548
|
if (!workers.has(worker.instance_name)) startWorker(appliedManifest, worker);
|
|
43546
43549
|
}
|
|
@@ -43552,7 +43555,7 @@ ${result2.stderr}`)) {
|
|
|
43552
43555
|
});
|
|
43553
43556
|
return;
|
|
43554
43557
|
}
|
|
43555
|
-
for (const
|
|
43558
|
+
for (const record5 of retiring) workers.delete(record5.worker.instance_name);
|
|
43556
43559
|
for (const worker of next.workers) {
|
|
43557
43560
|
if (!workers.has(worker.instance_name)) startWorker(next, worker);
|
|
43558
43561
|
}
|
|
@@ -43566,18 +43569,18 @@ ${result2.stderr}`)) {
|
|
|
43566
43569
|
};
|
|
43567
43570
|
const drainWorkers = async () => {
|
|
43568
43571
|
const draining = [...workers.values()];
|
|
43569
|
-
for (const
|
|
43570
|
-
|
|
43571
|
-
await updateRecord(
|
|
43572
|
+
for (const record5 of draining) {
|
|
43573
|
+
record5.controller.abort();
|
|
43574
|
+
await updateRecord(record5, "draining");
|
|
43572
43575
|
}
|
|
43573
|
-
const settled = await Promise.allSettled(draining.map((
|
|
43576
|
+
const settled = await Promise.allSettled(draining.map((record5) => record5.promise));
|
|
43574
43577
|
const failedDrain = settled.find(
|
|
43575
43578
|
(result2) => result2.status === "rejected"
|
|
43576
43579
|
);
|
|
43577
43580
|
if (failedDrain) throw failedDrain.reason;
|
|
43578
|
-
for (const
|
|
43579
|
-
if (workers.get(
|
|
43580
|
-
workers.delete(
|
|
43581
|
+
for (const record5 of draining) {
|
|
43582
|
+
if (workers.get(record5.worker.instance_name) === record5) {
|
|
43583
|
+
workers.delete(record5.worker.instance_name);
|
|
43581
43584
|
}
|
|
43582
43585
|
}
|
|
43583
43586
|
await persistRuntime();
|
|
@@ -43603,7 +43606,7 @@ ${result2.stderr}`)) {
|
|
|
43603
43606
|
}
|
|
43604
43607
|
if (quiesceSignal.aborted && !signal.aborted) {
|
|
43605
43608
|
let finished = false;
|
|
43606
|
-
const completion = Promise.allSettled([...workers.values()].map((
|
|
43609
|
+
const completion = Promise.allSettled([...workers.values()].map((record5) => record5.promise)).then((results) => {
|
|
43607
43610
|
finished = true;
|
|
43608
43611
|
return results;
|
|
43609
43612
|
});
|
|
@@ -43866,7 +43869,7 @@ var init_cli = __esm({
|
|
|
43866
43869
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
43867
43870
|
throw new Error("Inference host revocation checkpoint is invalid.");
|
|
43868
43871
|
}
|
|
43869
|
-
const
|
|
43872
|
+
const record5 = value;
|
|
43870
43873
|
const exactKeys = [
|
|
43871
43874
|
"schema_version",
|
|
43872
43875
|
"account_key",
|
|
@@ -43877,11 +43880,11 @@ var init_cli = __esm({
|
|
|
43877
43880
|
"remove_credential_recovery",
|
|
43878
43881
|
"remote_revoked_at"
|
|
43879
43882
|
];
|
|
43880
|
-
const revokedAt = String(
|
|
43881
|
-
if (Object.keys(
|
|
43883
|
+
const revokedAt = String(record5.remote_revoked_at || "");
|
|
43884
|
+
if (Object.keys(record5).sort().join("\0") !== exactKeys.slice().sort().join("\0") || record5.schema_version !== "vtx_inference_revocation_v1" || typeof record5.account_key !== "string" || !record5.account_key || record5.account_key.length > 512 || typeof record5.credential_store_identity !== "string" || !record5.credential_store_identity || record5.credential_store_identity.length > 4096 || typeof record5.issuer !== "string" || !record5.issuer || record5.issuer.length > 2048 || typeof record5.client_id !== "string" || !record5.client_id || record5.client_id.length > 512 || typeof record5.host_id !== "string" || !record5.host_id || record5.host_id.length > 512 || typeof record5.remove_credential_recovery !== "boolean" || typeof record5.remote_revoked_at !== "string" || !Number.isFinite(Date.parse(revokedAt)) || new Date(revokedAt).toISOString() !== revokedAt) {
|
|
43882
43885
|
throw new Error("Inference host revocation checkpoint is invalid.");
|
|
43883
43886
|
}
|
|
43884
|
-
return
|
|
43887
|
+
return record5;
|
|
43885
43888
|
};
|
|
43886
43889
|
readRevocationCheckpoint = async (config2) => {
|
|
43887
43890
|
const raw = await readInferencePrivateFile(
|
|
@@ -45403,12 +45406,12 @@ Waiting for approval...
|
|
|
45403
45406
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
45404
45407
|
throw new Error("Agent-driven inference stdin must be one JSON object.");
|
|
45405
45408
|
}
|
|
45406
|
-
const
|
|
45407
|
-
const unexpected = Object.keys(
|
|
45409
|
+
const record5 = value;
|
|
45410
|
+
const unexpected = Object.keys(record5).filter((key) => !allowedKeys.includes(key));
|
|
45408
45411
|
if (unexpected.length > 0) {
|
|
45409
45412
|
throw new Error(`Unsupported agent-driven inference fields: ${unexpected.join(", ")}.`);
|
|
45410
45413
|
}
|
|
45411
|
-
return
|
|
45414
|
+
return record5;
|
|
45412
45415
|
};
|
|
45413
45416
|
parseOptionalAgentStdin = async (dependencies, allowedKeys) => {
|
|
45414
45417
|
if (!dependencies.readStdin && process.stdin.isTTY) return {};
|
|
@@ -45423,12 +45426,12 @@ Waiting for approval...
|
|
|
45423
45426
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
45424
45427
|
throw new Error("Agent-driven inference stdin must be one JSON object.");
|
|
45425
45428
|
}
|
|
45426
|
-
const
|
|
45427
|
-
const unexpected = Object.keys(
|
|
45429
|
+
const record5 = value;
|
|
45430
|
+
const unexpected = Object.keys(record5).filter((key) => !allowedKeys.includes(key));
|
|
45428
45431
|
if (unexpected.length > 0) {
|
|
45429
45432
|
throw new Error(`Unsupported agent-driven inference fields: ${unexpected.join(", ")}.`);
|
|
45430
45433
|
}
|
|
45431
|
-
return
|
|
45434
|
+
return record5;
|
|
45432
45435
|
};
|
|
45433
45436
|
agentOperationId = (kind) => `${kind}-${randomUUID10()}`;
|
|
45434
45437
|
agentSession = async (config2, dependencies, warnings, signal) => {
|
|
@@ -46388,7 +46391,7 @@ Waiting for approval...
|
|
|
46388
46391
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
46389
46392
|
throw new Error("Inference-host service recovery transaction is invalid.");
|
|
46390
46393
|
}
|
|
46391
|
-
const
|
|
46394
|
+
const record5 = value;
|
|
46392
46395
|
const exactKeys = [
|
|
46393
46396
|
"schema_version",
|
|
46394
46397
|
"phase",
|
|
@@ -46401,15 +46404,15 @@ Waiting for approval...
|
|
|
46401
46404
|
"cleanup_confirmed_attempt_ids",
|
|
46402
46405
|
"started_at"
|
|
46403
46406
|
];
|
|
46404
|
-
if (Object.keys(
|
|
46407
|
+
if (Object.keys(record5).sort().join("\0") !== exactKeys.sort().join("\0") || record5.schema_version !== "vtx_inference_service_recovery_v1" || record5.phase !== "prepared" && record5.phase !== "reconciled" || typeof record5.transaction_id !== "string" || !/^[0-9a-f-]{36}$/u.test(record5.transaction_id) || typeof record5.instance_name !== "string" || typeof record5.manifest_generation !== "string" || typeof record5.restore_desired_running !== "boolean" || typeof record5.recovery_backup_path !== "string" || typeof record5.recovery_backup_sha256 !== "string" || !/^[0-9a-f]{64}$/u.test(record5.recovery_backup_sha256) || !Array.isArray(record5.cleanup_confirmed_attempt_ids) || record5.cleanup_confirmed_attempt_ids.some(
|
|
46405
46408
|
(attemptId) => typeof attemptId !== "string" || attemptId.length < 1 || attemptId.length > 256
|
|
46406
|
-
) || new Set(
|
|
46409
|
+
) || new Set(record5.cleanup_confirmed_attempt_ids).size !== record5.cleanup_confirmed_attempt_ids.length || [...record5.cleanup_confirmed_attempt_ids].sort().join("\0") !== record5.cleanup_confirmed_attempt_ids.join("\0") || typeof record5.started_at !== "string" || !Number.isFinite(Date.parse(record5.started_at)) || new Date(record5.started_at).toISOString() !== record5.started_at) {
|
|
46407
46410
|
throw new Error("Inference-host service recovery transaction is invalid.");
|
|
46408
46411
|
}
|
|
46409
|
-
if (resolve11(
|
|
46412
|
+
if (resolve11(record5.recovery_backup_path) !== resolve11(recoveryBackupPath(config2, record5.transaction_id))) {
|
|
46410
46413
|
throw new Error("Inference-host service recovery backup path is invalid.");
|
|
46411
46414
|
}
|
|
46412
|
-
return
|
|
46415
|
+
return record5;
|
|
46413
46416
|
};
|
|
46414
46417
|
assertResumableCodexRecoveryEvidence = (backupAttempts, currentAttempts, cleanupConfirmedAttemptIds, phase) => {
|
|
46415
46418
|
const backupIds = Object.keys(backupAttempts).sort();
|
|
@@ -47617,13 +47620,27 @@ async function runAndReportLocalWorkCycle(options, state, leaseToken, context) {
|
|
|
47617
47620
|
...buildRuntimePayload(state),
|
|
47618
47621
|
last_run_at: lastRunAt
|
|
47619
47622
|
};
|
|
47623
|
+
let decisionResponse = null;
|
|
47620
47624
|
if (result2.decision) {
|
|
47621
|
-
await options.client.reportRuntimeDecision(options.profileId, {
|
|
47625
|
+
decisionResponse = await options.client.reportRuntimeDecision(options.profileId, {
|
|
47622
47626
|
...basePayload,
|
|
47623
47627
|
...result2.decision
|
|
47624
47628
|
}, leaseToken);
|
|
47625
47629
|
}
|
|
47626
|
-
|
|
47630
|
+
let deferredTradeSync = null;
|
|
47631
|
+
if (result2.afterDecision) {
|
|
47632
|
+
const runtime = objectOrNull2(objectOrNull2(decisionResponse)?.runtime);
|
|
47633
|
+
const decision = runtime?.last_decision;
|
|
47634
|
+
const units = runtime?.last_units;
|
|
47635
|
+
const requestedUnits = Number(result2.decision?.units);
|
|
47636
|
+
if (!result2.decision || !["BUY", "SELL", "HOLD"].includes(String(decision)) || decision !== result2.decision.decision || typeof units !== "number" || !Number.isSafeInteger(units) || units < 0 || !Number.isSafeInteger(requestedUnits) || units > requestedUnits || (decision === "HOLD" ? units !== 0 : units <= 0)) {
|
|
47637
|
+
throw new Error("Runtime decision acceptance is unavailable or inconsistent; execution skipped.");
|
|
47638
|
+
}
|
|
47639
|
+
deferredTradeSync = await result2.afterDecision({
|
|
47640
|
+
decision,
|
|
47641
|
+
units
|
|
47642
|
+
});
|
|
47643
|
+
}
|
|
47627
47644
|
const tradeSync = deferredTradeSync ? { ...result2.tradeSync ?? {}, ...deferredTradeSync } : result2.tradeSync;
|
|
47628
47645
|
if (tradeSync) {
|
|
47629
47646
|
await options.client.reportRuntimeTradeSync(options.profileId, {
|
|
@@ -48968,7 +48985,7 @@ var init_network_debug = __esm({
|
|
|
48968
48985
|
});
|
|
48969
48986
|
|
|
48970
48987
|
// lib/runtime/hyperliquid-account-state-adapter.ts
|
|
48971
|
-
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;
|
|
48988
|
+
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, hasCompletePerpDexAccountMetrics, normalizeBrowserFillToTradeHistory, isPerpFill, fetchHyperliquidInfoPayload, requireHyperliquidApiUrl, requireWalletAddress, parseInfoPositionSnapshot, fetchBrowserAccountState, fetchBrowserAccountStateUncached, fetchBrowserUserFills, fetchBrowserPositionSnapshot;
|
|
48972
48989
|
var init_hyperliquid_account_state_adapter = __esm({
|
|
48973
48990
|
"lib/runtime/hyperliquid-account-state-adapter.ts"() {
|
|
48974
48991
|
"use strict";
|
|
@@ -49656,6 +49673,20 @@ var init_hyperliquid_account_state_adapter = __esm({
|
|
|
49656
49673
|
assetPositions
|
|
49657
49674
|
};
|
|
49658
49675
|
};
|
|
49676
|
+
hasCompletePerpDexAccountMetrics = (response) => {
|
|
49677
|
+
const isFiniteMetric = (value) => (typeof value === "number" || typeof value === "string" && value.trim() !== "") && Number.isFinite(Number(value));
|
|
49678
|
+
if (!response || typeof response !== "object" || Array.isArray(response)) return false;
|
|
49679
|
+
const margin = response.marginSummary;
|
|
49680
|
+
if (!margin || typeof margin !== "object" || Array.isArray(margin)) return false;
|
|
49681
|
+
if (![margin.accountValue, margin.totalMarginUsed, response.withdrawable].every(isFiniteMetric)) return false;
|
|
49682
|
+
const maintenanceValues = [response.crossMaintenanceMarginUsed, margin.crossMaintenanceMarginUsed, margin.totalMaintenanceMargin].filter((value) => value != null);
|
|
49683
|
+
if (maintenanceValues.length === 0 || !maintenanceValues.every(isFiniteMetric)) return false;
|
|
49684
|
+
if (!Array.isArray(response.assetPositions)) return false;
|
|
49685
|
+
return response.assetPositions.every((entry) => {
|
|
49686
|
+
const position = entry?.position;
|
|
49687
|
+
return position && typeof position === "object" && !Array.isArray(position) && [position.szi, position.entryPx, position.unrealizedPnl].every(isFiniteMetric);
|
|
49688
|
+
});
|
|
49689
|
+
};
|
|
49659
49690
|
normalizeBrowserFillToTradeHistory = (fill) => {
|
|
49660
49691
|
if (!fill || typeof fill !== "object") {
|
|
49661
49692
|
return null;
|
|
@@ -49893,7 +49924,8 @@ var init_hyperliquid_account_state_adapter = __esm({
|
|
|
49893
49924
|
}
|
|
49894
49925
|
return {
|
|
49895
49926
|
dex: dexName,
|
|
49896
|
-
payload: prefixHip3PositionCoins(response, dexName)
|
|
49927
|
+
payload: prefixHip3PositionCoins(response, dexName),
|
|
49928
|
+
rawPayload: response
|
|
49897
49929
|
};
|
|
49898
49930
|
})
|
|
49899
49931
|
);
|
|
@@ -49907,6 +49939,10 @@ var init_hyperliquid_account_state_adapter = __esm({
|
|
|
49907
49939
|
...dexResponses.map((entry) => entry.payload)
|
|
49908
49940
|
]),
|
|
49909
49941
|
selectedPayload,
|
|
49942
|
+
dexPayloads: [
|
|
49943
|
+
{ dex: "", payload: defaultResponse },
|
|
49944
|
+
...dexResponses.map(({ dex, rawPayload }) => ({ dex, payload: rawPayload }))
|
|
49945
|
+
],
|
|
49910
49946
|
capturedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
49911
49947
|
};
|
|
49912
49948
|
})();
|
|
@@ -50047,6 +50083,31 @@ var init_hyperliquid_account_state_adapter = __esm({
|
|
|
50047
50083
|
);
|
|
50048
50084
|
const accountSummary = {
|
|
50049
50085
|
...normalizedSummary,
|
|
50086
|
+
...input.scopeAccountSummaryToSelectedDex === true ? {} : {
|
|
50087
|
+
perp_dex_accounts: perpsResult.dexPayloads.filter(({ payload }) => hasCompletePerpDexAccountMetrics(payload)).map(({ dex, payload }) => {
|
|
50088
|
+
const summary = buildServerPromptRescueAccountSummary({
|
|
50089
|
+
...payload,
|
|
50090
|
+
crossMaintenanceMarginUsed: firstFiniteNumber([
|
|
50091
|
+
payload.crossMaintenanceMarginUsed,
|
|
50092
|
+
payload.marginSummary?.crossMaintenanceMarginUsed,
|
|
50093
|
+
payload.marginSummary?.totalMaintenanceMargin
|
|
50094
|
+
])
|
|
50095
|
+
}, {}, "disabled", accountSummaryOptions);
|
|
50096
|
+
const accountValue = Number(payload.marginSummary.accountValue);
|
|
50097
|
+
const calculatedAvailable = accountValue - summary.total_margin_used;
|
|
50098
|
+
const availableMargin = summary.maintenance_margin > 0 ? Math.max(calculatedAvailable, Math.max(0, accountValue - 4 * summary.maintenance_margin), summary.withdrawable) : Math.max(calculatedAvailable, summary.withdrawable);
|
|
50099
|
+
return {
|
|
50100
|
+
dex,
|
|
50101
|
+
account_value: accountValue,
|
|
50102
|
+
total_margin_used: summary.total_margin_used,
|
|
50103
|
+
available_margin: availableMargin,
|
|
50104
|
+
withdrawable: summary.withdrawable,
|
|
50105
|
+
maintenance_margin: summary.maintenance_margin,
|
|
50106
|
+
cross_account_leverage: summary.cross_account_leverage,
|
|
50107
|
+
total_unrealized_pnl: summary.total_unrealized_pnl ?? 0
|
|
50108
|
+
};
|
|
50109
|
+
})
|
|
50110
|
+
},
|
|
50050
50111
|
...exactAccountMode == null ? {} : { account_mode: exactAccountMode.accountMode, mode_source: "canonical" },
|
|
50051
50112
|
address: walletAddress,
|
|
50052
50113
|
dex: input.scopeAccountSummaryToSelectedDex === true ? selectedDex : "all",
|
|
@@ -50564,11 +50625,11 @@ var init_local_breadcrumbs = __esm({
|
|
|
50564
50625
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
50565
50626
|
return null;
|
|
50566
50627
|
}
|
|
50567
|
-
const
|
|
50568
|
-
const id2 = sanitizeOptionalString(
|
|
50569
|
-
const createdAt = sanitizeOptionalString(
|
|
50570
|
-
const scope =
|
|
50571
|
-
const kind = sanitizeOptionalString(
|
|
50628
|
+
const record5 = value;
|
|
50629
|
+
const id2 = sanitizeOptionalString(record5.id);
|
|
50630
|
+
const createdAt = sanitizeOptionalString(record5.createdAt);
|
|
50631
|
+
const scope = record5.scope === "engine" || record5.scope === "host" || record5.scope === "api" ? record5.scope : null;
|
|
50632
|
+
const kind = sanitizeOptionalString(record5.kind);
|
|
50572
50633
|
if (!id2 || !createdAt || !scope || !kind) {
|
|
50573
50634
|
return null;
|
|
50574
50635
|
}
|
|
@@ -50577,16 +50638,16 @@ var init_local_breadcrumbs = __esm({
|
|
|
50577
50638
|
createdAt,
|
|
50578
50639
|
scope,
|
|
50579
50640
|
kind,
|
|
50580
|
-
detail: sanitizeOptionalString(
|
|
50581
|
-
profileId: sanitizeOptionalString(
|
|
50582
|
-
sessionId: sanitizeOptionalString(
|
|
50583
|
-
deviceId: sanitizeOptionalString(
|
|
50584
|
-
mode:
|
|
50585
|
-
runtimeState:
|
|
50586
|
-
lastRunAt: sanitizeOptionalString(
|
|
50587
|
-
visibilityState: sanitizeOptionalString(
|
|
50588
|
-
online: typeof
|
|
50589
|
-
payload: clonePayload(
|
|
50641
|
+
detail: sanitizeOptionalString(record5.detail),
|
|
50642
|
+
profileId: sanitizeOptionalString(record5.profileId),
|
|
50643
|
+
sessionId: sanitizeOptionalString(record5.sessionId),
|
|
50644
|
+
deviceId: sanitizeOptionalString(record5.deviceId),
|
|
50645
|
+
mode: record5.mode === "assistant" ? "assistant" : record5.mode === "trader" ? "trader" : null,
|
|
50646
|
+
runtimeState: record5.runtimeState === "stopped" || record5.runtimeState === "running" || record5.runtimeState === "stale" || record5.runtimeState === "offline" || record5.runtimeState === "error" ? record5.runtimeState : null,
|
|
50647
|
+
lastRunAt: sanitizeOptionalString(record5.lastRunAt),
|
|
50648
|
+
visibilityState: sanitizeOptionalString(record5.visibilityState),
|
|
50649
|
+
online: typeof record5.online === "boolean" ? record5.online : null,
|
|
50650
|
+
payload: clonePayload(record5.payload ?? null)
|
|
50590
50651
|
};
|
|
50591
50652
|
};
|
|
50592
50653
|
readLocalRuntimeBreadcrumbs = () => {
|
|
@@ -50668,6 +50729,9 @@ var init_runtime_policy_generated2 = __esm({
|
|
|
50668
50729
|
"lib/runtime-policy.generated.json"() {
|
|
50669
50730
|
runtime_policy_generated_default2 = {
|
|
50670
50731
|
ui: {
|
|
50732
|
+
performance_defaults: {
|
|
50733
|
+
default_timeframe: "30d"
|
|
50734
|
+
},
|
|
50671
50735
|
auth_bootstrap_retry: {
|
|
50672
50736
|
max_attempts: 3,
|
|
50673
50737
|
jitter_milliseconds: 750,
|
|
@@ -50952,59 +51016,59 @@ var init_server_runtime_lease = __esm({
|
|
|
50952
51016
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
50953
51017
|
return null;
|
|
50954
51018
|
}
|
|
50955
|
-
const
|
|
50956
|
-
if (String(
|
|
51019
|
+
const record5 = value;
|
|
51020
|
+
if (String(record5.profileId ?? "").trim() !== profileId) {
|
|
50957
51021
|
return null;
|
|
50958
51022
|
}
|
|
50959
|
-
if (!String(
|
|
51023
|
+
if (!String(record5.runtimeLeaseToken ?? "").trim()) {
|
|
50960
51024
|
return null;
|
|
50961
51025
|
}
|
|
50962
|
-
if (!String(
|
|
51026
|
+
if (!String(record5.leaseId ?? "").trim()) {
|
|
50963
51027
|
return null;
|
|
50964
51028
|
}
|
|
50965
|
-
if (!String(
|
|
51029
|
+
if (!String(record5.runtimeSessionId ?? "").trim()) {
|
|
50966
51030
|
return null;
|
|
50967
51031
|
}
|
|
50968
|
-
if (!String(
|
|
51032
|
+
if (!String(record5.deviceId ?? "").trim()) {
|
|
50969
51033
|
return null;
|
|
50970
51034
|
}
|
|
50971
|
-
if (
|
|
51035
|
+
if (record5.mode !== "assistant" && record5.mode !== "trader") {
|
|
50972
51036
|
return null;
|
|
50973
51037
|
}
|
|
50974
|
-
if (
|
|
51038
|
+
if (record5.scope !== "trade-runtime") {
|
|
50975
51039
|
return null;
|
|
50976
51040
|
}
|
|
50977
|
-
if (!String(
|
|
51041
|
+
if (!String(record5.issuedAt ?? "").trim()) {
|
|
50978
51042
|
return null;
|
|
50979
51043
|
}
|
|
50980
|
-
if (!String(
|
|
51044
|
+
if (!String(record5.expiresAt ?? "").trim()) {
|
|
50981
51045
|
return null;
|
|
50982
51046
|
}
|
|
50983
|
-
if (!String(
|
|
51047
|
+
if (!String(record5.renewableUntil ?? "").trim()) {
|
|
50984
51048
|
return null;
|
|
50985
51049
|
}
|
|
50986
|
-
if (!Number.isFinite(Number(
|
|
51050
|
+
if (!Number.isFinite(Number(record5.savedAt))) {
|
|
50987
51051
|
return null;
|
|
50988
51052
|
}
|
|
50989
51053
|
return {
|
|
50990
51054
|
profileId,
|
|
50991
|
-
runtimeLeaseToken: String(
|
|
50992
|
-
leaseId: String(
|
|
50993
|
-
runtimeSessionId: String(
|
|
50994
|
-
deviceId: String(
|
|
50995
|
-
schedulerInstanceId: String(
|
|
50996
|
-
mode:
|
|
51055
|
+
runtimeLeaseToken: String(record5.runtimeLeaseToken),
|
|
51056
|
+
leaseId: String(record5.leaseId),
|
|
51057
|
+
runtimeSessionId: String(record5.runtimeSessionId),
|
|
51058
|
+
deviceId: String(record5.deviceId),
|
|
51059
|
+
schedulerInstanceId: String(record5.schedulerInstanceId ?? "").trim() || null,
|
|
51060
|
+
mode: record5.mode,
|
|
50997
51061
|
scope: "trade-runtime",
|
|
50998
|
-
leaseGeneration: normalizeLeaseGeneration(
|
|
50999
|
-
issuedAt: String(
|
|
51000
|
-
expiresAt: String(
|
|
51001
|
-
renewableUntil: String(
|
|
51002
|
-
lastSeenAt:
|
|
51003
|
-
renewedAt:
|
|
51004
|
-
revokedAt:
|
|
51005
|
-
transport: typeof
|
|
51006
|
-
runtimeContractIdentity:
|
|
51007
|
-
savedAt: Number(
|
|
51062
|
+
leaseGeneration: normalizeLeaseGeneration(record5.leaseGeneration),
|
|
51063
|
+
issuedAt: String(record5.issuedAt),
|
|
51064
|
+
expiresAt: String(record5.expiresAt),
|
|
51065
|
+
renewableUntil: String(record5.renewableUntil),
|
|
51066
|
+
lastSeenAt: record5.lastSeenAt ?? null,
|
|
51067
|
+
renewedAt: record5.renewedAt ?? null,
|
|
51068
|
+
revokedAt: record5.revokedAt ?? null,
|
|
51069
|
+
transport: typeof record5.transport === "object" && record5.transport != null ? record5.transport : {},
|
|
51070
|
+
runtimeContractIdentity: record5.runtimeContractIdentity ?? null,
|
|
51071
|
+
savedAt: Number(record5.savedAt)
|
|
51008
51072
|
};
|
|
51009
51073
|
};
|
|
51010
51074
|
readPersistedLeaseMap = () => {
|
|
@@ -51092,7 +51156,7 @@ var init_server_runtime_lease = __esm({
|
|
|
51092
51156
|
if (!profileId || !runtimeLeaseToken) {
|
|
51093
51157
|
return null;
|
|
51094
51158
|
}
|
|
51095
|
-
const
|
|
51159
|
+
const record5 = {
|
|
51096
51160
|
profileId,
|
|
51097
51161
|
runtimeLeaseToken,
|
|
51098
51162
|
leaseId: String(lease.lease_id),
|
|
@@ -51114,23 +51178,23 @@ var init_server_runtime_lease = __esm({
|
|
|
51114
51178
|
};
|
|
51115
51179
|
const leaseMap = readPersistedLeaseMap();
|
|
51116
51180
|
const existingLease = leaseMap[profileId] ?? null;
|
|
51117
|
-
if (existingLease &&
|
|
51118
|
-
const incomingGeneration =
|
|
51181
|
+
if (existingLease && record5.leaseId !== existingLease.leaseId) {
|
|
51182
|
+
const incomingGeneration = record5.leaseGeneration ?? null;
|
|
51119
51183
|
const existingGeneration = existingLease.leaseGeneration ?? null;
|
|
51120
51184
|
if (existingGeneration !== null && incomingGeneration === null || existingGeneration !== null && incomingGeneration !== null && incomingGeneration <= existingGeneration) {
|
|
51121
51185
|
return existingLease;
|
|
51122
51186
|
}
|
|
51123
51187
|
if (existingGeneration === null && incomingGeneration === null) {
|
|
51124
|
-
const incomingIssuedAtMs = Date.parse(
|
|
51188
|
+
const incomingIssuedAtMs = Date.parse(record5.issuedAt);
|
|
51125
51189
|
const existingIssuedAtMs = Date.parse(existingLease.issuedAt);
|
|
51126
51190
|
if (Number.isFinite(incomingIssuedAtMs) && Number.isFinite(existingIssuedAtMs) && incomingIssuedAtMs < existingIssuedAtMs) {
|
|
51127
51191
|
return existingLease;
|
|
51128
51192
|
}
|
|
51129
51193
|
}
|
|
51130
51194
|
}
|
|
51131
|
-
leaseMap[profileId] =
|
|
51195
|
+
leaseMap[profileId] = record5;
|
|
51132
51196
|
writePersistedLeaseMap(leaseMap);
|
|
51133
|
-
return
|
|
51197
|
+
return record5;
|
|
51134
51198
|
};
|
|
51135
51199
|
clearPersistedClientRuntimeServerLease = (profileId) => {
|
|
51136
51200
|
const normalizedProfileId = normalizeProfileId(profileId);
|
|
@@ -52531,19 +52595,19 @@ function assert2(check2, message, code, info) {
|
|
|
52531
52595
|
function assertArgument(check2, message, name, value) {
|
|
52532
52596
|
assert2(check2, message, "INVALID_ARGUMENT", { argument: name, value });
|
|
52533
52597
|
}
|
|
52534
|
-
function assertArgumentCount(
|
|
52598
|
+
function assertArgumentCount(count4, expectedCount, message) {
|
|
52535
52599
|
if (message == null) {
|
|
52536
52600
|
message = "";
|
|
52537
52601
|
}
|
|
52538
52602
|
if (message) {
|
|
52539
52603
|
message = ": " + message;
|
|
52540
52604
|
}
|
|
52541
|
-
assert2(
|
|
52542
|
-
count:
|
|
52605
|
+
assert2(count4 >= expectedCount, "missing argument" + message, "MISSING_ARGUMENT", {
|
|
52606
|
+
count: count4,
|
|
52543
52607
|
expectedCount
|
|
52544
52608
|
});
|
|
52545
|
-
assert2(
|
|
52546
|
-
count:
|
|
52609
|
+
assert2(count4 <= expectedCount, "too many arguments" + message, "UNEXPECTED_ARGUMENT", {
|
|
52610
|
+
count: count4,
|
|
52547
52611
|
expectedCount
|
|
52548
52612
|
});
|
|
52549
52613
|
}
|
|
@@ -55186,15 +55250,15 @@ var init_abstract_coder = __esm({
|
|
|
55186
55250
|
get bytes() {
|
|
55187
55251
|
return new Uint8Array(this.#data);
|
|
55188
55252
|
}
|
|
55189
|
-
#incrementBytesRead(
|
|
55253
|
+
#incrementBytesRead(count4) {
|
|
55190
55254
|
if (this.#parent) {
|
|
55191
|
-
return this.#parent.#incrementBytesRead(
|
|
55255
|
+
return this.#parent.#incrementBytesRead(count4);
|
|
55192
55256
|
}
|
|
55193
|
-
this.#bytesRead +=
|
|
55257
|
+
this.#bytesRead += count4;
|
|
55194
55258
|
assert2(this.#maxInflation < 1 || this.#bytesRead <= this.#maxInflation * this.dataLength, `compressed ABI data exceeds inflation ratio of ${this.#maxInflation} ( see: https://github.com/ethers-io/ethers.js/issues/4537 )`, "BUFFER_OVERRUN", {
|
|
55195
55259
|
buffer: getBytesCopy(this.#data),
|
|
55196
55260
|
offset: this.#offset,
|
|
55197
|
-
length:
|
|
55261
|
+
length: count4,
|
|
55198
55262
|
info: {
|
|
55199
55263
|
bytesRead: this.#bytesRead,
|
|
55200
55264
|
dataLength: this.dataLength
|
|
@@ -60305,12 +60369,12 @@ var init_array = __esm({
|
|
|
60305
60369
|
if (!Array.isArray(value)) {
|
|
60306
60370
|
this._throwError("expected array value", value);
|
|
60307
60371
|
}
|
|
60308
|
-
let
|
|
60309
|
-
if (
|
|
60310
|
-
|
|
60372
|
+
let count4 = this.length;
|
|
60373
|
+
if (count4 === -1) {
|
|
60374
|
+
count4 = value.length;
|
|
60311
60375
|
writer.writeValue(value.length);
|
|
60312
60376
|
}
|
|
60313
|
-
assertArgumentCount(value.length,
|
|
60377
|
+
assertArgumentCount(value.length, count4, "coder array" + (this.localName ? " " + this.localName : ""));
|
|
60314
60378
|
let coders = [];
|
|
60315
60379
|
for (let i = 0; i < value.length; i++) {
|
|
60316
60380
|
coders.push(this.coder);
|
|
@@ -60318,13 +60382,13 @@ var init_array = __esm({
|
|
|
60318
60382
|
return pack(writer, coders, value);
|
|
60319
60383
|
}
|
|
60320
60384
|
decode(reader) {
|
|
60321
|
-
let
|
|
60322
|
-
if (
|
|
60323
|
-
|
|
60324
|
-
assert2(
|
|
60385
|
+
let count4 = this.length;
|
|
60386
|
+
if (count4 === -1) {
|
|
60387
|
+
count4 = reader.readIndex();
|
|
60388
|
+
assert2(count4 * WordSize <= reader.dataLength, "insufficient data length", "BUFFER_OVERRUN", { buffer: reader.bytes, offset: count4 * WordSize, length: reader.dataLength });
|
|
60325
60389
|
}
|
|
60326
60390
|
let coders = [];
|
|
60327
|
-
for (let i = 0; i <
|
|
60391
|
+
for (let i = 0; i < count4; i++) {
|
|
60328
60392
|
coders.push(new AnonymousCoder(this.coder));
|
|
60329
60393
|
}
|
|
60330
60394
|
return unpack(reader, coders);
|
|
@@ -62891,8 +62955,8 @@ function _pack(type, value, isArray) {
|
|
|
62891
62955
|
match = type.match(regexArray);
|
|
62892
62956
|
if (match && Array.isArray(value)) {
|
|
62893
62957
|
const baseType = match[1];
|
|
62894
|
-
const
|
|
62895
|
-
assertArgument(
|
|
62958
|
+
const count4 = parseInt(match[2] || String(value.length));
|
|
62959
|
+
assertArgument(count4 === value.length, `invalid array length for ${type}`, "value", value);
|
|
62896
62960
|
const result2 = [];
|
|
62897
62961
|
value.forEach(function(value2) {
|
|
62898
62962
|
result2.push(_pack(baseType, value2, true));
|
|
@@ -67794,7 +67858,7 @@ async function _emit(contract, event, args, payloadFunc) {
|
|
|
67794
67858
|
if (!sub) {
|
|
67795
67859
|
return false;
|
|
67796
67860
|
}
|
|
67797
|
-
const
|
|
67861
|
+
const count4 = sub.listeners.length;
|
|
67798
67862
|
sub.listeners = sub.listeners.filter(({ listener, once: once2 }) => {
|
|
67799
67863
|
const passArgs = Array.from(args);
|
|
67800
67864
|
if (payloadFunc) {
|
|
@@ -67810,7 +67874,7 @@ async function _emit(contract, event, args, payloadFunc) {
|
|
|
67810
67874
|
sub.stop();
|
|
67811
67875
|
getInternal(contract).subs.delete(sub.tag);
|
|
67812
67876
|
}
|
|
67813
|
-
return
|
|
67877
|
+
return count4 > 0;
|
|
67814
67878
|
}
|
|
67815
67879
|
async function emit(contract, event, args, payloadFunc) {
|
|
67816
67880
|
try {
|
|
@@ -71029,7 +71093,7 @@ var init_abstract_provider = __esm({
|
|
|
71029
71093
|
return false;
|
|
71030
71094
|
}
|
|
71031
71095
|
;
|
|
71032
|
-
const
|
|
71096
|
+
const count4 = sub.listeners.length;
|
|
71033
71097
|
sub.listeners = sub.listeners.filter(({ listener, once: once2 }) => {
|
|
71034
71098
|
const payload = new EventPayload(this, once2 ? null : listener, event);
|
|
71035
71099
|
try {
|
|
@@ -71044,7 +71108,7 @@ var init_abstract_provider = __esm({
|
|
|
71044
71108
|
}
|
|
71045
71109
|
this.#subs.delete(sub.tag);
|
|
71046
71110
|
}
|
|
71047
|
-
return
|
|
71111
|
+
return count4 > 0;
|
|
71048
71112
|
}
|
|
71049
71113
|
async listenerCount(event) {
|
|
71050
71114
|
if (event) {
|
|
@@ -80024,10 +80088,10 @@ function getDecryptKdfParams(data4) {
|
|
|
80024
80088
|
const prf = spelunk(data4, "crypto.kdfparams.prf:string!");
|
|
80025
80089
|
const algorithm = prf.split("-").pop();
|
|
80026
80090
|
assertArgument(algorithm === "sha256" || algorithm === "sha512", "invalid kdf.pdf", "kdf.pdf", prf);
|
|
80027
|
-
const
|
|
80091
|
+
const count4 = spelunk(data4, "crypto.kdfparams.c:int!");
|
|
80028
80092
|
const dkLen = spelunk(data4, "crypto.kdfparams.dklen:int!");
|
|
80029
80093
|
assertArgument(dkLen === 32, "invalid kdf.dklen", "kdf.dklen", dkLen);
|
|
80030
|
-
return { name: "pbkdf2", salt, count:
|
|
80094
|
+
return { name: "pbkdf2", salt, count: count4, dkLen, algorithm };
|
|
80031
80095
|
}
|
|
80032
80096
|
}
|
|
80033
80097
|
assertArgument(false, "unsupported key-derivation function", "kdf", kdf);
|
|
@@ -80037,8 +80101,8 @@ function decryptKeystoreJsonSync(json2, _password) {
|
|
|
80037
80101
|
const password = getPassword(_password);
|
|
80038
80102
|
const params = getDecryptKdfParams(data4);
|
|
80039
80103
|
if (params.name === "pbkdf2") {
|
|
80040
|
-
const { salt: salt2, count:
|
|
80041
|
-
const key2 = pbkdf2(password, salt2,
|
|
80104
|
+
const { salt: salt2, count: count4, dkLen: dkLen2, algorithm } = params;
|
|
80105
|
+
const key2 = pbkdf2(password, salt2, count4, dkLen2, algorithm);
|
|
80042
80106
|
return getAccount(data4, key2);
|
|
80043
80107
|
}
|
|
80044
80108
|
assert2(params.name === "scrypt", "cannot be reached", "UNKNOWN_ERROR", { params });
|
|
@@ -80062,8 +80126,8 @@ async function decryptKeystoreJson(json2, _password, progress) {
|
|
|
80062
80126
|
progress(0);
|
|
80063
80127
|
await stall3(0);
|
|
80064
80128
|
}
|
|
80065
|
-
const { salt: salt2, count:
|
|
80066
|
-
const key2 = pbkdf2(password, salt2,
|
|
80129
|
+
const { salt: salt2, count: count4, dkLen: dkLen2, algorithm } = params;
|
|
80130
|
+
const key2 = pbkdf2(password, salt2, count4, dkLen2, algorithm);
|
|
80067
80131
|
if (progress) {
|
|
80068
80132
|
progress(1);
|
|
80069
80133
|
await stall3(0);
|
|
@@ -84394,8 +84458,8 @@ var init_hyperliquid_client = __esm({
|
|
|
84394
84458
|
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
84395
84459
|
return { referenceSourceKind: "l2_unavailable" };
|
|
84396
84460
|
}
|
|
84397
|
-
const
|
|
84398
|
-
const observedMs = Number(
|
|
84461
|
+
const record5 = payload;
|
|
84462
|
+
const observedMs = Number(record5.time);
|
|
84399
84463
|
const nowMs = Date.now();
|
|
84400
84464
|
const referenceAgeMs = Number.isFinite(observedMs) ? Math.max(0, nowMs - observedMs) : null;
|
|
84401
84465
|
const referenceObservedAt = Number.isFinite(observedMs) ? new Date(observedMs).toISOString() : null;
|
|
@@ -84406,7 +84470,7 @@ var init_hyperliquid_client = __esm({
|
|
|
84406
84470
|
referenceAgeMs
|
|
84407
84471
|
};
|
|
84408
84472
|
}
|
|
84409
|
-
const levels = Array.isArray(
|
|
84473
|
+
const levels = Array.isArray(record5.levels) ? record5.levels : [];
|
|
84410
84474
|
const bids = Array.isArray(levels[0]) ? levels[0] : [];
|
|
84411
84475
|
const asks = Array.isArray(levels[1]) ? levels[1] : [];
|
|
84412
84476
|
const levelPrice = (value) => {
|
|
@@ -85028,12 +85092,12 @@ function validateDeviceSecrets(value, options) {
|
|
|
85028
85092
|
missing: missing3
|
|
85029
85093
|
};
|
|
85030
85094
|
}
|
|
85031
|
-
const
|
|
85032
|
-
const rawProviderKeys =
|
|
85095
|
+
const record5 = value;
|
|
85096
|
+
const rawProviderKeys = record5.providerKeys && typeof record5.providerKeys === "object" ? record5.providerKeys : {};
|
|
85033
85097
|
const providerKeys = Object.fromEntries(
|
|
85034
85098
|
Object.entries(rawProviderKeys).map(([provider, key]) => [provider, typeof key === "string" ? key.trim() : ""]).filter(([, key]) => Boolean(key))
|
|
85035
85099
|
);
|
|
85036
|
-
const rawProviderKeySlots =
|
|
85100
|
+
const rawProviderKeySlots = record5.providerKeySlots && typeof record5.providerKeySlots === "object" ? record5.providerKeySlots : {};
|
|
85037
85101
|
const providerKeySlots = Object.fromEntries(
|
|
85038
85102
|
Object.entries(rawProviderKeySlots).map(([provider, value2]) => {
|
|
85039
85103
|
const slots = Array.isArray(value2) ? value2.map((key) => typeof key === "string" ? key.trim() : "").filter(Boolean) : [];
|
|
@@ -85046,27 +85110,27 @@ function validateDeviceSecrets(value, options) {
|
|
|
85046
85110
|
Object.entries(providerKeySlots).map(([provider, slots]) => [provider, slots[0]]).filter(([, key]) => Boolean(key))
|
|
85047
85111
|
)
|
|
85048
85112
|
};
|
|
85049
|
-
const rawProviderBaseUrls =
|
|
85113
|
+
const rawProviderBaseUrls = record5.providerBaseUrls && typeof record5.providerBaseUrls === "object" ? record5.providerBaseUrls : {};
|
|
85050
85114
|
const providerBaseUrls = Object.fromEntries(
|
|
85051
85115
|
Object.entries(rawProviderBaseUrls).map(([provider, baseUrl]) => [provider, typeof baseUrl === "string" ? baseUrl.trim() : ""]).filter(([, baseUrl]) => Boolean(baseUrl))
|
|
85052
85116
|
);
|
|
85053
|
-
const rawProviderBaseUrlSlots =
|
|
85117
|
+
const rawProviderBaseUrlSlots = record5.providerBaseUrlSlots && typeof record5.providerBaseUrlSlots === "object" ? record5.providerBaseUrlSlots : {};
|
|
85054
85118
|
const providerBaseUrlSlots = Object.fromEntries(
|
|
85055
85119
|
Object.entries(rawProviderBaseUrlSlots).map(([provider, value2]) => {
|
|
85056
85120
|
const slots = Array.isArray(value2) ? value2.map((baseUrl) => typeof baseUrl === "string" ? baseUrl.trim() : "") : [];
|
|
85057
85121
|
return [provider, slots];
|
|
85058
85122
|
}).filter(([, slots]) => slots.some(Boolean))
|
|
85059
85123
|
);
|
|
85060
|
-
const storage = normalizeDeviceSecretStorage(
|
|
85061
|
-
const hyperliquidSigningKey = typeof
|
|
85062
|
-
const rawLocalAi =
|
|
85124
|
+
const storage = normalizeDeviceSecretStorage(record5.storage);
|
|
85125
|
+
const hyperliquidSigningKey = typeof record5.hyperliquidSigningKey === "string" ? record5.hyperliquidSigningKey.trim() || void 0 : void 0;
|
|
85126
|
+
const rawLocalAi = record5.localAi && typeof record5.localAi === "object" ? record5.localAi : {};
|
|
85063
85127
|
const localAi = normalizeLocalAiSecrets({
|
|
85064
85128
|
baseUrl: typeof rawLocalAi.baseUrl === "string" ? rawLocalAi.baseUrl : "",
|
|
85065
85129
|
modelName: typeof rawLocalAi.modelName === "string" ? rawLocalAi.modelName : "",
|
|
85066
85130
|
apiKey: typeof rawLocalAi.apiKey === "string" ? rawLocalAi.apiKey : "",
|
|
85067
85131
|
serverType: rawLocalAi.serverType === "ollama-native" ? "ollama-native" : rawLocalAi.serverType === "openai-compatible" ? "openai-compatible" : void 0
|
|
85068
85132
|
});
|
|
85069
|
-
const rawOpenAiCompatible =
|
|
85133
|
+
const rawOpenAiCompatible = record5.openaiCompatible && typeof record5.openaiCompatible === "object" ? record5.openaiCompatible : {};
|
|
85070
85134
|
const openaiCompatible = normalizeOpenAiCompatibleSecrets({
|
|
85071
85135
|
baseUrl: typeof rawOpenAiCompatible.baseUrl === "string" ? rawOpenAiCompatible.baseUrl : "",
|
|
85072
85136
|
modelName: typeof rawOpenAiCompatible.modelName === "string" ? rawOpenAiCompatible.modelName : "",
|
|
@@ -85316,10 +85380,10 @@ var init_vault = __esm({
|
|
|
85316
85380
|
};
|
|
85317
85381
|
};
|
|
85318
85382
|
normalizeDeviceSecretStorage = (value) => {
|
|
85319
|
-
const
|
|
85383
|
+
const record5 = value && typeof value === "object" ? value : {};
|
|
85320
85384
|
return {
|
|
85321
|
-
byok:
|
|
85322
|
-
hyperliquid:
|
|
85385
|
+
byok: record5.byok === "device" ? "device" : "server",
|
|
85386
|
+
hyperliquid: record5.hyperliquid === "device" ? "device" : "server"
|
|
85323
85387
|
};
|
|
85324
85388
|
};
|
|
85325
85389
|
normalizeLocalAiSecrets = (value) => {
|
|
@@ -86322,15 +86386,15 @@ var init_runtime_execution = __esm({
|
|
|
86322
86386
|
}
|
|
86323
86387
|
return null;
|
|
86324
86388
|
}
|
|
86325
|
-
const
|
|
86326
|
-
const direct =
|
|
86389
|
+
const record5 = node;
|
|
86390
|
+
const direct = record5.oid ?? record5.orderId ?? record5.order_id;
|
|
86327
86391
|
if (direct != null) {
|
|
86328
86392
|
const parsed = String(direct).trim();
|
|
86329
86393
|
if (parsed.length > 0) {
|
|
86330
86394
|
return parsed;
|
|
86331
86395
|
}
|
|
86332
86396
|
}
|
|
86333
|
-
for (const child of Object.values(
|
|
86397
|
+
for (const child of Object.values(record5)) {
|
|
86334
86398
|
const found = walk(child);
|
|
86335
86399
|
if (found) {
|
|
86336
86400
|
return found;
|
|
@@ -86406,19 +86470,19 @@ var init_runtime_execution = __esm({
|
|
|
86406
86470
|
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
86407
86471
|
return [];
|
|
86408
86472
|
}
|
|
86409
|
-
const
|
|
86410
|
-
const orderId = Math.trunc(Number(
|
|
86411
|
-
const triggerPrice = Number(
|
|
86412
|
-
const size = Number(
|
|
86413
|
-
if (!Number.isSafeInteger(orderId) || orderId <= 0 || !Number.isFinite(triggerPrice) || triggerPrice <= 0 || !Number.isFinite(size) || size <= 0 || typeof
|
|
86473
|
+
const record5 = entry;
|
|
86474
|
+
const orderId = Math.trunc(Number(record5.orderId));
|
|
86475
|
+
const triggerPrice = Number(record5.triggerPrice);
|
|
86476
|
+
const size = Number(record5.size);
|
|
86477
|
+
if (!Number.isSafeInteger(orderId) || orderId <= 0 || !Number.isFinite(triggerPrice) || triggerPrice <= 0 || !Number.isFinite(size) || size <= 0 || typeof record5.isLong !== "boolean") {
|
|
86414
86478
|
return [];
|
|
86415
86479
|
}
|
|
86416
86480
|
return [{
|
|
86417
86481
|
orderId,
|
|
86418
86482
|
triggerPrice,
|
|
86419
86483
|
size,
|
|
86420
|
-
isLong:
|
|
86421
|
-
positionTpsl:
|
|
86484
|
+
isLong: record5.isLong,
|
|
86485
|
+
positionTpsl: record5.positionTpsl === true
|
|
86422
86486
|
}];
|
|
86423
86487
|
});
|
|
86424
86488
|
};
|
|
@@ -86444,11 +86508,11 @@ var init_runtime_execution = __esm({
|
|
|
86444
86508
|
}
|
|
86445
86509
|
}
|
|
86446
86510
|
};
|
|
86447
|
-
rememberTrailingStop = (profileId, symbol2,
|
|
86511
|
+
rememberTrailingStop = (profileId, symbol2, record5) => {
|
|
86448
86512
|
const records = readTrackedTrailingStops(profileId, symbol2);
|
|
86449
86513
|
writeTrackedTrailingStops(profileId, symbol2, [
|
|
86450
|
-
...records.filter((candidate) => candidate.orderId !==
|
|
86451
|
-
|
|
86514
|
+
...records.filter((candidate) => candidate.orderId !== record5.orderId),
|
|
86515
|
+
record5
|
|
86452
86516
|
]);
|
|
86453
86517
|
};
|
|
86454
86518
|
protectiveGroupStorageKey = (profileId, symbol2) => `vtx:auto-protective-group:${profileId}:${symbol2}`;
|
|
@@ -86476,16 +86540,16 @@ var init_runtime_execution = __esm({
|
|
|
86476
86540
|
protectiveGroupReadFailures.add(key);
|
|
86477
86541
|
return [];
|
|
86478
86542
|
}
|
|
86479
|
-
const
|
|
86480
|
-
const entryOrderId = String(
|
|
86481
|
-
const storedProfileId = String(
|
|
86482
|
-
const storedSymbol = String(
|
|
86483
|
-
const walletAddress = String(
|
|
86484
|
-
if (
|
|
86543
|
+
const record5 = entry;
|
|
86544
|
+
const entryOrderId = String(record5.entryOrderId ?? "").trim();
|
|
86545
|
+
const storedProfileId = String(record5.profileId ?? "").trim();
|
|
86546
|
+
const storedSymbol = String(record5.symbol ?? "").trim().toUpperCase();
|
|
86547
|
+
const walletAddress = String(record5.walletAddress ?? "").trim().toLowerCase();
|
|
86548
|
+
if (record5.version !== 1 && record5.version !== 2 || storedProfileId !== profileId || storedSymbol !== symbol2.trim().toUpperCase() || !walletAddress || !entryOrderId || typeof record5.isLong !== "boolean" || !Array.isArray(record5.legs)) {
|
|
86485
86549
|
protectiveGroupReadFailures.add(key);
|
|
86486
86550
|
return [];
|
|
86487
86551
|
}
|
|
86488
|
-
const legs =
|
|
86552
|
+
const legs = record5.legs.flatMap((leg) => {
|
|
86489
86553
|
if (leg == null || typeof leg !== "object" || Array.isArray(leg)) {
|
|
86490
86554
|
protectiveGroupReadFailures.add(key);
|
|
86491
86555
|
return [];
|
|
@@ -86535,7 +86599,7 @@ var init_runtime_execution = __esm({
|
|
|
86535
86599
|
...replacement ? { replacement } : {}
|
|
86536
86600
|
}];
|
|
86537
86601
|
});
|
|
86538
|
-
const pendingRecord =
|
|
86602
|
+
const pendingRecord = record5.pendingEntry;
|
|
86539
86603
|
let pendingEntry;
|
|
86540
86604
|
if (pendingRecord != null) {
|
|
86541
86605
|
if (pendingRecord == null || typeof pendingRecord !== "object" || Array.isArray(pendingRecord)) {
|
|
@@ -86573,7 +86637,7 @@ var init_runtime_execution = __esm({
|
|
|
86573
86637
|
}
|
|
86574
86638
|
};
|
|
86575
86639
|
}
|
|
86576
|
-
const attachmentRecord =
|
|
86640
|
+
const attachmentRecord = record5.attachmentJournal;
|
|
86577
86641
|
let attachmentJournal;
|
|
86578
86642
|
if (attachmentRecord != null) {
|
|
86579
86643
|
if (attachmentRecord == null || typeof attachmentRecord !== "object" || Array.isArray(attachmentRecord)) {
|
|
@@ -86632,8 +86696,8 @@ var init_runtime_execution = __esm({
|
|
|
86632
86696
|
symbol: storedSymbol,
|
|
86633
86697
|
walletAddress,
|
|
86634
86698
|
entryOrderId,
|
|
86635
|
-
isLong:
|
|
86636
|
-
cleanupRequired:
|
|
86699
|
+
isLong: record5.isLong,
|
|
86700
|
+
cleanupRequired: record5.cleanupRequired === true,
|
|
86637
86701
|
legs,
|
|
86638
86702
|
...pendingEntry ? { pendingEntry } : {},
|
|
86639
86703
|
...attachmentJournal ? { attachmentJournal } : {}
|
|
@@ -86913,11 +86977,11 @@ var init_runtime_execution = __esm({
|
|
|
86913
86977
|
writeTrackedTrailingStops(
|
|
86914
86978
|
profileId,
|
|
86915
86979
|
symbol2,
|
|
86916
|
-
readTrackedTrailingStops(profileId, symbol2).filter((
|
|
86980
|
+
readTrackedTrailingStops(profileId, symbol2).filter((record5) => record5.orderId !== orderId)
|
|
86917
86981
|
);
|
|
86918
86982
|
};
|
|
86919
86983
|
replaceTrackedTrailingStop = (profileId, symbol2, previousOrderId, replacement) => {
|
|
86920
|
-
const retained = readTrackedTrailingStops(profileId, symbol2).filter((
|
|
86984
|
+
const retained = readTrackedTrailingStops(profileId, symbol2).filter((record5) => record5.orderId !== previousOrderId);
|
|
86921
86985
|
writeTrackedTrailingStops(
|
|
86922
86986
|
profileId,
|
|
86923
86987
|
symbol2,
|
|
@@ -89702,49 +89766,49 @@ var init_runtime_execution = __esm({
|
|
|
89702
89766
|
}
|
|
89703
89767
|
liveOrders = fetchedOrders;
|
|
89704
89768
|
} catch (error48) {
|
|
89705
|
-
return tracked.map((
|
|
89706
|
-
order_id: String(
|
|
89769
|
+
return tracked.map((record5) => ({
|
|
89770
|
+
order_id: String(record5.orderId),
|
|
89707
89771
|
symbol: symbol2,
|
|
89708
89772
|
action: "AUTO_TRAILING_SL",
|
|
89709
89773
|
status: "failed",
|
|
89710
89774
|
execution_metadata: {
|
|
89711
|
-
trigger_price:
|
|
89775
|
+
trigger_price: record5.triggerPrice,
|
|
89712
89776
|
error: `Unable to verify the tracked exchange stop: ${error48 instanceof Error ? error48.message : String(error48)}`
|
|
89713
89777
|
}
|
|
89714
89778
|
}));
|
|
89715
89779
|
}
|
|
89716
89780
|
const eligible = [];
|
|
89717
89781
|
const retained = [];
|
|
89718
|
-
for (const
|
|
89719
|
-
if (
|
|
89782
|
+
for (const record5 of tracked) {
|
|
89783
|
+
if (record5.isLong !== isLong) {
|
|
89720
89784
|
continue;
|
|
89721
89785
|
}
|
|
89722
|
-
const liveOrder = liveOrders.find((order) => order.oid ===
|
|
89786
|
+
const liveOrder = liveOrders.find((order) => order.oid === record5.orderId);
|
|
89723
89787
|
if (!liveOrder) {
|
|
89724
|
-
retained.push(
|
|
89788
|
+
retained.push(record5);
|
|
89725
89789
|
continue;
|
|
89726
89790
|
}
|
|
89727
89791
|
const triggerPrice = Number(liveOrder.trigger_px);
|
|
89728
89792
|
const size = Number(liveOrder.sz);
|
|
89729
89793
|
const liveSide = String(liveOrder.side).trim().toLowerCase();
|
|
89730
|
-
const isTrustedProtectiveOrder = String(liveOrder.coin).trim().toUpperCase() === symbol2.trim().toUpperCase() && (isLong ? liveSide === "a" || liveSide === "sell" : liveSide === "b" || liveSide === "buy") && liveOrder.reduce_only && liveOrder.is_trigger && liveOrder.trigger_kind === "sl" && liveOrder.is_position_tpsl ===
|
|
89731
|
-
if (isTrustedProtectiveOrder && triggerPrice ===
|
|
89732
|
-
eligible.push(
|
|
89794
|
+
const isTrustedProtectiveOrder = String(liveOrder.coin).trim().toUpperCase() === symbol2.trim().toUpperCase() && (isLong ? liveSide === "a" || liveSide === "sell" : liveSide === "b" || liveSide === "buy") && liveOrder.reduce_only && liveOrder.is_trigger && liveOrder.trigger_kind === "sl" && liveOrder.is_position_tpsl === record5.positionTpsl && Number.isFinite(size) && size > 0 && Number.isFinite(triggerPrice) && triggerPrice > 0;
|
|
89795
|
+
if (isTrustedProtectiveOrder && triggerPrice === record5.triggerPrice && size === record5.size) {
|
|
89796
|
+
eligible.push(record5);
|
|
89733
89797
|
} else {
|
|
89734
|
-
retained.push(
|
|
89798
|
+
retained.push(record5);
|
|
89735
89799
|
}
|
|
89736
89800
|
}
|
|
89737
89801
|
const reports = [];
|
|
89738
89802
|
const updated = [...retained];
|
|
89739
89803
|
let remainingExposure = Math.abs(currentPositionSize);
|
|
89740
|
-
for (const
|
|
89804
|
+
for (const record5 of eligible) {
|
|
89741
89805
|
const effectiveSize = roundAssetSize(
|
|
89742
|
-
Math.min(
|
|
89806
|
+
Math.min(record5.size, remainingExposure),
|
|
89743
89807
|
request.executionContext.sizeDecimals
|
|
89744
89808
|
);
|
|
89745
89809
|
remainingExposure = Math.max(0, remainingExposure - effectiveSize);
|
|
89746
89810
|
if (!Number.isFinite(effectiveSize) || effectiveSize <= 0) {
|
|
89747
|
-
const trackedLeg = readClientProtectiveGroups(profileId, symbol2).flatMap((group) => group.legs).find((leg) => leg.orderId ===
|
|
89811
|
+
const trackedLeg = readClientProtectiveGroups(profileId, symbol2).flatMap((group) => group.legs).find((leg) => leg.orderId === record5.orderId);
|
|
89748
89812
|
if (trackedLeg) {
|
|
89749
89813
|
const report = await cancelClientProtectiveLeg(
|
|
89750
89814
|
request,
|
|
@@ -89754,19 +89818,19 @@ var init_runtime_execution = __esm({
|
|
|
89754
89818
|
);
|
|
89755
89819
|
reports.push(report);
|
|
89756
89820
|
if (report.status === "executed") {
|
|
89757
|
-
replaceProtectiveLeg(profileId, symbol2,
|
|
89821
|
+
replaceProtectiveLeg(profileId, symbol2, record5.orderId, null);
|
|
89758
89822
|
} else {
|
|
89759
|
-
updated.push(
|
|
89823
|
+
updated.push(record5);
|
|
89760
89824
|
}
|
|
89761
89825
|
} else {
|
|
89762
|
-
updated.push(
|
|
89826
|
+
updated.push(record5);
|
|
89763
89827
|
reports.push({
|
|
89764
|
-
order_id: String(
|
|
89828
|
+
order_id: String(record5.orderId),
|
|
89765
89829
|
symbol: symbol2,
|
|
89766
89830
|
action: "AUTO_TRAILING_SL",
|
|
89767
89831
|
status: "failed",
|
|
89768
89832
|
execution_metadata: {
|
|
89769
|
-
trigger_price:
|
|
89833
|
+
trigger_price: record5.triggerPrice,
|
|
89770
89834
|
reason_code: "protective_order_shape_unresolved"
|
|
89771
89835
|
}
|
|
89772
89836
|
});
|
|
@@ -89784,42 +89848,42 @@ var init_runtime_execution = __esm({
|
|
|
89784
89848
|
rawCandidatePrice,
|
|
89785
89849
|
request.executionContext.sizeDecimals
|
|
89786
89850
|
)) : 0;
|
|
89787
|
-
const tightens = candidatePrice > 0 && (isLong ? candidatePrice >
|
|
89851
|
+
const tightens = candidatePrice > 0 && (isLong ? candidatePrice > record5.triggerPrice : candidatePrice < record5.triggerPrice);
|
|
89788
89852
|
const canonicalRecordSize = roundAssetSize(
|
|
89789
|
-
|
|
89853
|
+
record5.size,
|
|
89790
89854
|
request.executionContext.sizeDecimals
|
|
89791
89855
|
);
|
|
89792
89856
|
const resizes = effectiveSize !== canonicalRecordSize;
|
|
89793
89857
|
if (!tightens && !resizes) {
|
|
89794
|
-
updated.push(
|
|
89858
|
+
updated.push(record5);
|
|
89795
89859
|
continue;
|
|
89796
89860
|
}
|
|
89797
|
-
const replacementTriggerPrice = tightens ? candidatePrice :
|
|
89861
|
+
const replacementTriggerPrice = tightens ? candidatePrice : record5.triggerPrice;
|
|
89798
89862
|
if (!canPersistClientProtectiveGroups(profileId, symbol2)) {
|
|
89799
|
-
updated.push(
|
|
89863
|
+
updated.push(record5);
|
|
89800
89864
|
reports.push({
|
|
89801
|
-
order_id: String(
|
|
89865
|
+
order_id: String(record5.orderId),
|
|
89802
89866
|
symbol: symbol2,
|
|
89803
89867
|
action: "AUTO_TRAILING_SL",
|
|
89804
89868
|
status: "failed",
|
|
89805
89869
|
execution_metadata: {
|
|
89806
89870
|
trigger_price: replacementTriggerPrice,
|
|
89807
|
-
previous_trigger_price:
|
|
89871
|
+
previous_trigger_price: record5.triggerPrice,
|
|
89808
89872
|
reason_code: "protective_lifecycle_storage_unavailable"
|
|
89809
89873
|
}
|
|
89810
89874
|
});
|
|
89811
89875
|
continue;
|
|
89812
89876
|
}
|
|
89813
89877
|
const currentGroups = readFreshClientProtectiveGroups(profileId, symbol2);
|
|
89814
|
-
const sourceGroups = currentGroups.filter((group) => group.legs.some((leg) => leg.orderId ===
|
|
89878
|
+
const sourceGroups = currentGroups.filter((group) => group.legs.some((leg) => leg.orderId === record5.orderId));
|
|
89815
89879
|
const sourceGroup = sourceGroups.length === 1 ? sourceGroups[0] : null;
|
|
89816
|
-
const previousLeg = sourceGroup?.legs.filter((leg) => leg.orderId ===
|
|
89880
|
+
const previousLeg = sourceGroup?.legs.filter((leg) => leg.orderId === record5.orderId);
|
|
89817
89881
|
const replacementMutationId = createRuntimeId().toLowerCase();
|
|
89818
89882
|
const replacementClientOrderId = `0x${replacementMutationId.replaceAll("-", "")}`;
|
|
89819
89883
|
const replacementIntent = {
|
|
89820
89884
|
mutationId: replacementMutationId,
|
|
89821
89885
|
clientOrderId: replacementClientOrderId,
|
|
89822
|
-
previousOrderId:
|
|
89886
|
+
previousOrderId: record5.orderId,
|
|
89823
89887
|
triggerPrice: replacementTriggerPrice,
|
|
89824
89888
|
size: effectiveSize
|
|
89825
89889
|
};
|
|
@@ -89832,15 +89896,15 @@ var init_runtime_execution = __esm({
|
|
|
89832
89896
|
replacement: replacementIntent
|
|
89833
89897
|
});
|
|
89834
89898
|
if (reservation == null) {
|
|
89835
|
-
updated.push(
|
|
89899
|
+
updated.push(record5);
|
|
89836
89900
|
reports.push({
|
|
89837
|
-
order_id: String(
|
|
89901
|
+
order_id: String(record5.orderId),
|
|
89838
89902
|
symbol: symbol2,
|
|
89839
89903
|
action: "AUTO_TRAILING_SL",
|
|
89840
89904
|
status: "failed",
|
|
89841
89905
|
execution_metadata: {
|
|
89842
89906
|
trigger_price: replacementTriggerPrice,
|
|
89843
|
-
previous_trigger_price:
|
|
89907
|
+
previous_trigger_price: record5.triggerPrice,
|
|
89844
89908
|
reason_code: "protective_replacement_reservation_failed"
|
|
89845
89909
|
}
|
|
89846
89910
|
});
|
|
@@ -89873,7 +89937,7 @@ var init_runtime_execution = __esm({
|
|
|
89873
89937
|
replacementDispatchBoundaryCompleted = true;
|
|
89874
89938
|
},
|
|
89875
89939
|
symbol: symbol2,
|
|
89876
|
-
orderId:
|
|
89940
|
+
orderId: record5.orderId,
|
|
89877
89941
|
side: isLong ? "sell" : "buy",
|
|
89878
89942
|
size: effectiveSize,
|
|
89879
89943
|
limitPrice: replacementTriggerPrice,
|
|
@@ -89888,7 +89952,7 @@ var init_runtime_execution = __esm({
|
|
|
89888
89952
|
const modificationAcknowledgement = extractCanonicalHyperliquidOrderStateAcknowledgement(modifyResponse);
|
|
89889
89953
|
const replacementOrderId = Number(modificationAcknowledgement?.orderId);
|
|
89890
89954
|
if (!Number.isSafeInteger(replacementOrderId) || replacementOrderId <= 0) {
|
|
89891
|
-
updated.push(
|
|
89955
|
+
updated.push(record5);
|
|
89892
89956
|
reports.push({
|
|
89893
89957
|
order_id: null,
|
|
89894
89958
|
symbol: symbol2,
|
|
@@ -89896,7 +89960,7 @@ var init_runtime_execution = __esm({
|
|
|
89896
89960
|
status: "failed",
|
|
89897
89961
|
execution_metadata: {
|
|
89898
89962
|
trigger_price: replacementTriggerPrice,
|
|
89899
|
-
previous_trigger_price:
|
|
89963
|
+
previous_trigger_price: record5.triggerPrice,
|
|
89900
89964
|
error: "Trailing stop replacement did not return a trackable order id."
|
|
89901
89965
|
}
|
|
89902
89966
|
});
|
|
@@ -89946,11 +90010,11 @@ var init_runtime_execution = __esm({
|
|
|
89946
90010
|
triggerPrice: replacementTriggerPrice,
|
|
89947
90011
|
size: effectiveSize,
|
|
89948
90012
|
isLong,
|
|
89949
|
-
positionTpsl:
|
|
90013
|
+
positionTpsl: record5.positionTpsl
|
|
89950
90014
|
};
|
|
89951
90015
|
updated.push(replacementTrailingStop);
|
|
89952
90016
|
} else {
|
|
89953
|
-
removeTrackedTrailingStop(profileId, symbol2,
|
|
90017
|
+
removeTrackedTrailingStop(profileId, symbol2, record5.orderId);
|
|
89954
90018
|
reports.push({
|
|
89955
90019
|
order_id: String(replacementOrderId),
|
|
89956
90020
|
symbol: symbol2,
|
|
@@ -89970,8 +90034,8 @@ var init_runtime_execution = __esm({
|
|
|
89970
90034
|
status: "executed",
|
|
89971
90035
|
execution_metadata: {
|
|
89972
90036
|
trigger_price: replacementTriggerPrice,
|
|
89973
|
-
previous_trigger_price:
|
|
89974
|
-
previous_order_id:
|
|
90037
|
+
previous_trigger_price: record5.triggerPrice,
|
|
90038
|
+
previous_order_id: record5.orderId
|
|
89975
90039
|
}
|
|
89976
90040
|
});
|
|
89977
90041
|
} catch (error48) {
|
|
@@ -89987,16 +90051,16 @@ var init_runtime_execution = __esm({
|
|
|
89987
90051
|
throw error48;
|
|
89988
90052
|
}
|
|
89989
90053
|
if (!canonicalCleanupRetained) {
|
|
89990
|
-
updated.push(
|
|
90054
|
+
updated.push(record5);
|
|
89991
90055
|
}
|
|
89992
90056
|
reports.push({
|
|
89993
|
-
order_id: String(
|
|
90057
|
+
order_id: String(record5.orderId),
|
|
89994
90058
|
symbol: symbol2,
|
|
89995
90059
|
action: "AUTO_TRAILING_SL",
|
|
89996
90060
|
status: "failed",
|
|
89997
90061
|
execution_metadata: {
|
|
89998
90062
|
trigger_price: candidatePrice,
|
|
89999
|
-
previous_trigger_price:
|
|
90063
|
+
previous_trigger_price: record5.triggerPrice,
|
|
90000
90064
|
error: error48 instanceof Error ? error48.message : String(error48)
|
|
90001
90065
|
}
|
|
90002
90066
|
});
|
|
@@ -91336,6 +91400,215 @@ var init_runtime_execution = __esm({
|
|
|
91336
91400
|
}
|
|
91337
91401
|
});
|
|
91338
91402
|
|
|
91403
|
+
// lib/runtime/decision-contract.ts
|
|
91404
|
+
var VISIBLE_REASONING_KEYS, VISIBLE_REASONING_KEY_SET, VISIBLE_REASONING_ALIAS_KEY_SET, normalizeDecisionUnits, normalizeDecisionValue;
|
|
91405
|
+
var init_decision_contract = __esm({
|
|
91406
|
+
"lib/runtime/decision-contract.ts"() {
|
|
91407
|
+
"use strict";
|
|
91408
|
+
init_define_VTX_EXO_POLICY();
|
|
91409
|
+
init_define_VTX_GROK_POLICY();
|
|
91410
|
+
init_define_VTX_PI_MODEL_POLICY();
|
|
91411
|
+
VISIBLE_REASONING_KEYS = [
|
|
91412
|
+
"reasoning",
|
|
91413
|
+
"final_reasoning",
|
|
91414
|
+
"final_answer",
|
|
91415
|
+
"answer",
|
|
91416
|
+
"output_text",
|
|
91417
|
+
"text",
|
|
91418
|
+
"content"
|
|
91419
|
+
];
|
|
91420
|
+
VISIBLE_REASONING_KEY_SET = new Set(VISIBLE_REASONING_KEYS);
|
|
91421
|
+
VISIBLE_REASONING_ALIAS_KEY_SET = new Set([
|
|
91422
|
+
...VISIBLE_REASONING_KEYS,
|
|
91423
|
+
"reason"
|
|
91424
|
+
].map((key) => key.replace(/[^a-z0-9]+/gi, "").toLowerCase()));
|
|
91425
|
+
normalizeDecisionUnits = (rawUnits, decision) => {
|
|
91426
|
+
const parsedUnits = Number(rawUnits);
|
|
91427
|
+
if (Number.isFinite(parsedUnits) && parsedUnits >= 0) {
|
|
91428
|
+
return Math.trunc(parsedUnits);
|
|
91429
|
+
}
|
|
91430
|
+
return 0;
|
|
91431
|
+
};
|
|
91432
|
+
normalizeDecisionValue = (rawDecision) => {
|
|
91433
|
+
const decisionValue = String(rawDecision || "").trim().toUpperCase();
|
|
91434
|
+
return decisionValue === "BUY" || decisionValue === "SELL" ? decisionValue : "HOLD";
|
|
91435
|
+
};
|
|
91436
|
+
}
|
|
91437
|
+
});
|
|
91438
|
+
|
|
91439
|
+
// lib/runtime/constraint-contract.ts
|
|
91440
|
+
var normalizeOptionalInt, evaluateRuntimeDecisionAcceptance;
|
|
91441
|
+
var init_constraint_contract = __esm({
|
|
91442
|
+
"lib/runtime/constraint-contract.ts"() {
|
|
91443
|
+
"use strict";
|
|
91444
|
+
init_define_VTX_EXO_POLICY();
|
|
91445
|
+
init_define_VTX_GROK_POLICY();
|
|
91446
|
+
init_define_VTX_PI_MODEL_POLICY();
|
|
91447
|
+
init_execution_guard_contract();
|
|
91448
|
+
init_decision_contract();
|
|
91449
|
+
normalizeOptionalInt = (value) => {
|
|
91450
|
+
if (value === null || value === void 0) {
|
|
91451
|
+
return null;
|
|
91452
|
+
}
|
|
91453
|
+
const parsed = Number.parseInt(String(value), 10);
|
|
91454
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
91455
|
+
};
|
|
91456
|
+
evaluateRuntimeDecisionAcceptance = (input) => {
|
|
91457
|
+
const decision = normalizeDecisionValue(input.decision);
|
|
91458
|
+
const units = normalizeDecisionUnits(input.units, decision);
|
|
91459
|
+
if (decision === "HOLD") {
|
|
91460
|
+
return {
|
|
91461
|
+
accepted: true,
|
|
91462
|
+
decision,
|
|
91463
|
+
normalized_units: 0,
|
|
91464
|
+
reason_code: null
|
|
91465
|
+
};
|
|
91466
|
+
}
|
|
91467
|
+
if (input.constraints.runtime_disabled) {
|
|
91468
|
+
return {
|
|
91469
|
+
accepted: false,
|
|
91470
|
+
decision,
|
|
91471
|
+
normalized_units: 0,
|
|
91472
|
+
reason_code: "runtime_disabled"
|
|
91473
|
+
};
|
|
91474
|
+
}
|
|
91475
|
+
if (input.constraints.kill_switch_active) {
|
|
91476
|
+
return {
|
|
91477
|
+
accepted: false,
|
|
91478
|
+
decision,
|
|
91479
|
+
normalized_units: 0,
|
|
91480
|
+
reason_code: "kill_switch_active"
|
|
91481
|
+
};
|
|
91482
|
+
}
|
|
91483
|
+
if (!input.constraints.model_allowed) {
|
|
91484
|
+
return {
|
|
91485
|
+
accepted: false,
|
|
91486
|
+
decision,
|
|
91487
|
+
normalized_units: 0,
|
|
91488
|
+
reason_code: "model_ineligible"
|
|
91489
|
+
};
|
|
91490
|
+
}
|
|
91491
|
+
if (!input.constraints.provider_allowed) {
|
|
91492
|
+
return {
|
|
91493
|
+
accepted: false,
|
|
91494
|
+
decision,
|
|
91495
|
+
normalized_units: 0,
|
|
91496
|
+
reason_code: "provider_ineligible"
|
|
91497
|
+
};
|
|
91498
|
+
}
|
|
91499
|
+
if (units <= 0) {
|
|
91500
|
+
return {
|
|
91501
|
+
accepted: false,
|
|
91502
|
+
decision,
|
|
91503
|
+
normalized_units: 0,
|
|
91504
|
+
reason_code: "invalid_units"
|
|
91505
|
+
};
|
|
91506
|
+
}
|
|
91507
|
+
const maxPerPrompt = Math.max(Math.trunc(Number(input.constraints.max_trades_per_prompt) || 0), 0);
|
|
91508
|
+
if (maxPerPrompt === 0) {
|
|
91509
|
+
return {
|
|
91510
|
+
accepted: false,
|
|
91511
|
+
decision,
|
|
91512
|
+
normalized_units: 0,
|
|
91513
|
+
reason_code: "max_per_prompt_zero"
|
|
91514
|
+
};
|
|
91515
|
+
}
|
|
91516
|
+
const remainingGlobal = normalizeOptionalInt(input.constraints.remaining_global_units);
|
|
91517
|
+
const remainingExchange = normalizeOptionalInt(input.constraints.remaining_exchange_units);
|
|
91518
|
+
const remainingAsset = normalizeOptionalInt(input.constraints.remaining_asset_units);
|
|
91519
|
+
const currentSymbolSignedUnits = normalizeOptionalInt(input.constraints.current_symbol_signed_units) ?? 0;
|
|
91520
|
+
let cappedUnits = Math.min(units, maxPerPrompt);
|
|
91521
|
+
const exposureIncrease = (candidateUnits) => {
|
|
91522
|
+
const classified = classifyExecutionIntent(decision, candidateUnits, currentSymbolSignedUnits);
|
|
91523
|
+
return Math.max(
|
|
91524
|
+
0,
|
|
91525
|
+
Math.abs(classified.targetSignedUnits) - Math.abs(currentSymbolSignedUnits)
|
|
91526
|
+
);
|
|
91527
|
+
};
|
|
91528
|
+
const fitsCapacity = (candidateUnits) => {
|
|
91529
|
+
const increase = exposureIncrease(candidateUnits);
|
|
91530
|
+
if (remainingGlobal !== null && increase > Math.max(remainingGlobal, 0)) {
|
|
91531
|
+
return false;
|
|
91532
|
+
}
|
|
91533
|
+
if (remainingExchange !== null && increase > Math.max(remainingExchange, 0)) {
|
|
91534
|
+
return false;
|
|
91535
|
+
}
|
|
91536
|
+
if (remainingAsset !== null && increase > Math.max(remainingAsset, 0)) {
|
|
91537
|
+
return false;
|
|
91538
|
+
}
|
|
91539
|
+
return true;
|
|
91540
|
+
};
|
|
91541
|
+
while (cappedUnits > 0 && !fitsCapacity(cappedUnits)) {
|
|
91542
|
+
cappedUnits -= 1;
|
|
91543
|
+
}
|
|
91544
|
+
if (cappedUnits <= 0) {
|
|
91545
|
+
const requestedExposureIncrease = exposureIncrease(Math.min(units, maxPerPrompt));
|
|
91546
|
+
const reasonCode = requestedExposureIncrease > 0 && remainingGlobal !== null && remainingGlobal <= 0 ? "global_capacity_reached" : requestedExposureIncrease > 0 && remainingExchange !== null && remainingExchange <= 0 ? "exchange_capacity_reached" : requestedExposureIncrease > 0 && remainingAsset !== null && remainingAsset <= 0 ? "asset_capacity_reached" : "capacity_reached";
|
|
91547
|
+
return {
|
|
91548
|
+
accepted: false,
|
|
91549
|
+
decision,
|
|
91550
|
+
normalized_units: 0,
|
|
91551
|
+
reason_code: reasonCode
|
|
91552
|
+
};
|
|
91553
|
+
}
|
|
91554
|
+
return {
|
|
91555
|
+
accepted: true,
|
|
91556
|
+
decision,
|
|
91557
|
+
normalized_units: cappedUnits,
|
|
91558
|
+
reason_code: cappedUnits < units ? "units_capped" : null
|
|
91559
|
+
};
|
|
91560
|
+
};
|
|
91561
|
+
}
|
|
91562
|
+
});
|
|
91563
|
+
|
|
91564
|
+
// lib/runtime/provider-observability.ts
|
|
91565
|
+
var record4, identifier, count3, normalizeProviderDiagnostics;
|
|
91566
|
+
var init_provider_observability = __esm({
|
|
91567
|
+
"lib/runtime/provider-observability.ts"() {
|
|
91568
|
+
"use strict";
|
|
91569
|
+
init_define_VTX_EXO_POLICY();
|
|
91570
|
+
init_define_VTX_GROK_POLICY();
|
|
91571
|
+
init_define_VTX_PI_MODEL_POLICY();
|
|
91572
|
+
record4 = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
91573
|
+
identifier = (v) => typeof v === "string" && /^[A-Za-z0-9][A-Za-z0-9_.:/-]{0,255}$/.test(v) ? v : void 0;
|
|
91574
|
+
count3 = (v) => {
|
|
91575
|
+
if (typeof v !== "number" && (typeof v !== "string" || !v.trim())) return void 0;
|
|
91576
|
+
const n2 = Number(v);
|
|
91577
|
+
return Number.isFinite(n2) && n2 >= 0 && n2 <= Number.MAX_SAFE_INTEGER ? n2 : void 0;
|
|
91578
|
+
};
|
|
91579
|
+
normalizeProviderDiagnostics = (value) => {
|
|
91580
|
+
const raw = record4(value);
|
|
91581
|
+
const result2 = {};
|
|
91582
|
+
for (const key of ["retry_after_seconds", "retry_delay_seconds"]) {
|
|
91583
|
+
const n2 = count3(raw[key]);
|
|
91584
|
+
if (n2 !== void 0) result2[key] = n2;
|
|
91585
|
+
}
|
|
91586
|
+
if (typeof raw.credential_ref === "string" && /^[a-f0-9]{64}$/.test(raw.credential_ref)) result2.credential_ref = raw.credential_ref;
|
|
91587
|
+
if (raw.execution_mode === "client" || raw.execution_mode === "server") result2.execution_mode = raw.execution_mode;
|
|
91588
|
+
if (typeof raw.quota_project_ref === "string" && /^[a-f0-9]{64}$/.test(raw.quota_project_ref) && raw.quota_project_source === "provider_quota_subject") {
|
|
91589
|
+
result2.quota_project_ref = raw.quota_project_ref;
|
|
91590
|
+
result2.quota_project_source = "provider_quota_subject";
|
|
91591
|
+
}
|
|
91592
|
+
if (Array.isArray(raw.quota_violations)) {
|
|
91593
|
+
const violations = raw.quota_violations.slice(0, 16).map((item) => {
|
|
91594
|
+
const v = record4(item);
|
|
91595
|
+
const out = {};
|
|
91596
|
+
const metric = identifier(v.metric), id2 = identifier(v.id), value2 = count3(v.value);
|
|
91597
|
+
if (metric) out.metric = metric;
|
|
91598
|
+
if (id2) out.id = id2;
|
|
91599
|
+
if (value2 !== void 0) out.value = value2;
|
|
91600
|
+
const dims = record4(v.dimensions);
|
|
91601
|
+
const model = identifier(dims.model), location = identifier(dims.location);
|
|
91602
|
+
if (model || location) out.dimensions = { ...model ? { model } : {}, ...location ? { location } : {} };
|
|
91603
|
+
return out;
|
|
91604
|
+
}).filter((v) => Object.keys(v).length > 0);
|
|
91605
|
+
if (violations.length) result2.quota_violations = violations;
|
|
91606
|
+
}
|
|
91607
|
+
return result2;
|
|
91608
|
+
};
|
|
91609
|
+
}
|
|
91610
|
+
});
|
|
91611
|
+
|
|
91339
91612
|
// lib/runtime/usage-contract.ts
|
|
91340
91613
|
var PROMPT_TOKEN_KEYS, COMPLETION_TOKEN_KEYS, TOTAL_TOKEN_KEYS, REASONING_TOKEN_KEYS, CACHED_INPUT_TOKEN_KEYS, CACHE_CREATION_INPUT_TOKEN_KEYS, TOOL_USE_TOKEN_KEYS, AUDIO_INPUT_TOKEN_KEYS, AUDIO_OUTPUT_TOKEN_KEYS, BILLABLE_INPUT_TOKEN_KEYS, BILLABLE_OUTPUT_TOKEN_KEYS, BILLABLE_CACHED_INPUT_TOKEN_KEYS, BILLABLE_CACHE_CREATION_INPUT_TOKEN_KEYS, BILLABLE_TOOL_USE_TOKEN_KEYS, MAX_RUNTIME_USAGE_COUNT, PROVIDER_USAGE_DETAIL_KEYS, PROVIDER_USAGE_DETAIL_COUNT_KEY_PATTERN, PROVIDER_USAGE_DETAIL_TEXT_KEYS, MAX_PROVIDER_USAGE_DETAIL_ITEMS, isRecord, coerceOptionalRuntimeUsageCount, readOptionalRuntimeUsageCount, readNestedUsageDetailCount, sanitizeProviderUsageDetail, normalizeUsageProvenance, normalizeRuntimeUsageDetails;
|
|
91341
91614
|
var init_usage_contract = __esm({
|
|
@@ -91441,8 +91714,8 @@ var init_usage_contract = __esm({
|
|
|
91441
91714
|
continue;
|
|
91442
91715
|
}
|
|
91443
91716
|
if (PROVIDER_USAGE_DETAIL_COUNT_KEY_PATTERN.test(key)) {
|
|
91444
|
-
const
|
|
91445
|
-
if (
|
|
91717
|
+
const count4 = coerceOptionalRuntimeUsageCount(rawValue);
|
|
91718
|
+
if (count4 !== null) result2[key] = count4;
|
|
91446
91719
|
}
|
|
91447
91720
|
}
|
|
91448
91721
|
return result2;
|
|
@@ -91654,6 +91927,7 @@ var init_inference_observability = __esm({
|
|
|
91654
91927
|
init_define_VTX_EXO_POLICY();
|
|
91655
91928
|
init_define_VTX_GROK_POLICY();
|
|
91656
91929
|
init_define_VTX_PI_MODEL_POLICY();
|
|
91930
|
+
init_provider_observability();
|
|
91657
91931
|
init_usage_contract();
|
|
91658
91932
|
init_reasoning_observability();
|
|
91659
91933
|
AI_INVOCATION_CONTRACT_VERSION = 2;
|
|
@@ -91795,6 +92069,9 @@ var init_inference_observability = __esm({
|
|
|
91795
92069
|
const useCase = enumValue(source.use_case, USE_CASES, "trader");
|
|
91796
92070
|
const role = enumValue(source.role, ROLES_BY_USE_CASE[useCase], DEFAULT_ROLE[useCase]);
|
|
91797
92071
|
const reasoningContent = safeText(source.reasoning_content);
|
|
92072
|
+
const providerStatus = safeNonNegativeInt(source.provider_status_code);
|
|
92073
|
+
const requestTokensSource = source.request_input_tokens_source === "estimated_chars_v1" || source.request_input_tokens_source === "provider_count" ? source.request_input_tokens_source : null;
|
|
92074
|
+
const requestTokens = requestTokensSource ? safeNonNegativeInt(source.request_input_tokens) : null;
|
|
91798
92075
|
const traceStatus = enumValue(
|
|
91799
92076
|
source.reasoning_trace_status,
|
|
91800
92077
|
TRACE_STATUSES,
|
|
@@ -91856,7 +92133,10 @@ var init_inference_observability = __esm({
|
|
|
91856
92133
|
used_for_final_decision: source.used_for_final_decision === true,
|
|
91857
92134
|
failure_category: safeCode3(source.failure_category),
|
|
91858
92135
|
failure_code: safeCode3(source.failure_code),
|
|
91859
|
-
provider_status_code:
|
|
92136
|
+
provider_status_code: providerStatus !== null && providerStatus >= 100 && providerStatus <= 599 ? providerStatus : null,
|
|
92137
|
+
request_input_tokens: requestTokens,
|
|
92138
|
+
request_input_tokens_source: requestTokens !== null ? requestTokensSource : null,
|
|
92139
|
+
provider_diagnostics: normalizeProviderDiagnostics(source.provider_diagnostics),
|
|
91860
92140
|
retryable: typeof source.retryable === "boolean" ? source.retryable : null,
|
|
91861
92141
|
fallback_from_provider: safeIdentifier(source.fallback_from_provider),
|
|
91862
92142
|
fallback_from_model: safeIdentifier(source.fallback_from_model),
|
|
@@ -91995,6 +92275,7 @@ function buildClientExchangeSnapshot(input) {
|
|
|
91995
92275
|
mark_price: input.accountState.availableToTrade.mark_price ?? null,
|
|
91996
92276
|
account_summary: {
|
|
91997
92277
|
account_value: accountSummary.account_value ?? null,
|
|
92278
|
+
...accountSummary.perp_dex_accounts == null ? {} : { perp_dex_accounts: accountSummary.perp_dex_accounts },
|
|
91998
92279
|
total_margin_used: accountSummary.total_margin_used ?? null,
|
|
91999
92280
|
available_margin: accountSummary.available_margin ?? null,
|
|
92000
92281
|
withdrawable: accountSummary.withdrawable ?? null,
|
|
@@ -92460,6 +92741,46 @@ function createHeadlessLocalWorker(options) {
|
|
|
92460
92741
|
message: `Tradability ${providerDecision.tradability ?? "missing"} is below the ${classifiedIntent === "open" ? "Open" : "Add"} minimum of ${applicableMinimum}. No order was placed.`
|
|
92461
92742
|
}
|
|
92462
92743
|
} : null;
|
|
92744
|
+
let executionDecision = { decision: providerDecision.decision, units: providerDecision.units };
|
|
92745
|
+
if (localHyperliquidContext && providerDecision.decision !== "HOLD") {
|
|
92746
|
+
const constraints = objectOrNull3(metadata.constraint_contract) ?? {};
|
|
92747
|
+
const limit = (key) => {
|
|
92748
|
+
const raw = key === "max_trades_per_exchange" && !Object.hasOwn(promptKnobs, key) ? promptKnobs.max_trades_global : promptKnobs[key];
|
|
92749
|
+
if (raw == null) throw new Error(`Missing headless runtime ${key}.`);
|
|
92750
|
+
const value = requireFiniteNumber(raw, key);
|
|
92751
|
+
if (!Number.isSafeInteger(value) || value < 0) throw new Error(`Invalid headless runtime ${key}.`);
|
|
92752
|
+
return value;
|
|
92753
|
+
};
|
|
92754
|
+
const unitSize = localHyperliquidContext.executionContext.unitSizeUsdc;
|
|
92755
|
+
const venue = getHyperliquidMarketDex(symbol2);
|
|
92756
|
+
let globalUsage = 0;
|
|
92757
|
+
let exchangeUsage = 0;
|
|
92758
|
+
let currentSignedUnits = 0;
|
|
92759
|
+
for (const position of localHyperliquidContext.accountState.positions) {
|
|
92760
|
+
if (Number(position.size) === 0) continue;
|
|
92761
|
+
const entryPrice = requirePositiveNumber2(position.entry_price, "position entry price");
|
|
92762
|
+
const signedUnits = signedUnitsFromPosition(Number(position.size), entryPrice, unitSize);
|
|
92763
|
+
globalUsage += Math.abs(signedUnits);
|
|
92764
|
+
if (getHyperliquidMarketDex(position.symbol) === venue) exchangeUsage += Math.abs(signedUnits);
|
|
92765
|
+
if (normalizeRuntimeSymbol(position.symbol) === normalizeRuntimeSymbol(symbol2)) currentSignedUnits = signedUnits;
|
|
92766
|
+
}
|
|
92767
|
+
const accepted = evaluateRuntimeDecisionAcceptance({
|
|
92768
|
+
...executionDecision,
|
|
92769
|
+
constraints: {
|
|
92770
|
+
runtime_disabled: constraints.runtime_disabled === true,
|
|
92771
|
+
kill_switch_active: constraints.kill_switch_active === true,
|
|
92772
|
+
max_trades_per_prompt: limit("max_trades_per_prompt"),
|
|
92773
|
+
remaining_global_units: limit("max_trades_global") - globalUsage,
|
|
92774
|
+
remaining_exchange_units: limit("max_trades_per_exchange") - exchangeUsage,
|
|
92775
|
+
remaining_asset_units: limit("max_trades_per_asset") - Math.abs(currentSignedUnits),
|
|
92776
|
+
current_symbol_signed_units: currentSignedUnits,
|
|
92777
|
+
model_allowed: constraints.model_allowed !== false,
|
|
92778
|
+
provider_allowed: constraints.provider_allowed !== false
|
|
92779
|
+
}
|
|
92780
|
+
});
|
|
92781
|
+
if (!accepted.accepted) throw new Error(`Headless runtime decision rejected: ${accepted.reason_code}`);
|
|
92782
|
+
executionDecision = { decision: accepted.decision, units: accepted.normalized_units };
|
|
92783
|
+
}
|
|
92463
92784
|
const envelope = metadata.envelope ?? {};
|
|
92464
92785
|
const baseTradeSync = {
|
|
92465
92786
|
analysis_run_id: analysisRunId,
|
|
@@ -92479,8 +92800,8 @@ function createHeadlessLocalWorker(options) {
|
|
|
92479
92800
|
contract_version: requireText(envelope.contract_version, "contract version"),
|
|
92480
92801
|
contract_hash: requireText(envelope.contract_hash, "contract hash"),
|
|
92481
92802
|
policy_generation_id: requireText(envelope.policy_generation_id, "policy generation id"),
|
|
92482
|
-
decision:
|
|
92483
|
-
units:
|
|
92803
|
+
decision: executionDecision.decision,
|
|
92804
|
+
units: executionDecision.units,
|
|
92484
92805
|
final_tradability: providerDecision.tradability,
|
|
92485
92806
|
reasoning: providerDecision.reasoning,
|
|
92486
92807
|
model: requireText(prompt.model ?? metadata.model, "model"),
|
|
@@ -92506,7 +92827,7 @@ function createHeadlessLocalWorker(options) {
|
|
|
92506
92827
|
execution_snapshot_id: tradabilityBlockExecution ? decisionSnapshotId : void 0,
|
|
92507
92828
|
executions: tradabilityBlockExecution ? [tradabilityBlockExecution] : []
|
|
92508
92829
|
},
|
|
92509
|
-
afterDecision: localHyperliquidContext ? async () => {
|
|
92830
|
+
afterDecision: localHyperliquidContext ? async (accepted) => {
|
|
92510
92831
|
const freshProfile = objectOrNull3(await options.client.getSecretStatus(input.profileId));
|
|
92511
92832
|
const freshWalletAddress = requireText(
|
|
92512
92833
|
freshProfile?.hyperliquid_wallet_address,
|
|
@@ -92525,8 +92846,8 @@ function createHeadlessLocalWorker(options) {
|
|
|
92525
92846
|
cycleId: analysisRunId,
|
|
92526
92847
|
signingKey: localHyperliquidContext.signingKey,
|
|
92527
92848
|
config: buildHeadlessExchangeConfig(llmConfig),
|
|
92528
|
-
decision:
|
|
92529
|
-
units:
|
|
92849
|
+
decision: accepted.decision,
|
|
92850
|
+
units: accepted.units,
|
|
92530
92851
|
executionContext: localHyperliquidContext.executionContext
|
|
92531
92852
|
});
|
|
92532
92853
|
return {
|
|
@@ -92549,6 +92870,7 @@ var init_headless_local_worker = __esm({
|
|
|
92549
92870
|
init_hyperliquid_account_state_adapter();
|
|
92550
92871
|
init_hyperliquid_market_symbol();
|
|
92551
92872
|
init_runtime_execution();
|
|
92873
|
+
init_constraint_contract();
|
|
92552
92874
|
init_protection_storage();
|
|
92553
92875
|
init_execution_guard_contract();
|
|
92554
92876
|
init_inference_observability();
|