@vtxmacro/cli 2026.10.46 → 2026.10.48
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/exo-harness.ts +24 -8
- package/bin/vtx-mcp.js +26 -10
- package/bin/vtx-service-bootstrap.js +25 -9
- package/bin/vtx-service-launcher.js +24 -8
- package/bin/vtx.js +527 -175
- package/package.json +1 -1
package/bin/vtx.js
CHANGED
|
@@ -122,7 +122,7 @@ var init_routing = __esm({
|
|
|
122
122
|
var agent_cli_release_default;
|
|
123
123
|
var init_agent_cli_release = __esm({
|
|
124
124
|
"agent-cli-release.json"() {
|
|
125
|
-
agent_cli_release_default = { package_name: "@vtxmacro/cli", package_version: "2026.10.
|
|
125
|
+
agent_cli_release_default = { package_name: "@vtxmacro/cli", package_version: "2026.10.48", codex_package_name: "@openai/codex", codex_version: "0.155.0", copilot_sdk_package_name: "@github/copilot-sdk", copilot_sdk_version: "1.0.0-beta.8", copilot_cli_package_name: "@github/copilot", copilot_cli_version: "1.0.80", deepseek_harness_version: "0.1.1-rc.2", deepseek_harness_packages: ["@deepseek-ai/dsh-agent", "@deepseek-ai/dsh-agent-instructions", "@deepseek-ai/dsh-agent-loop", "@deepseek-ai/dsh-agent-spine-demo", "@deepseek-ai/dsh-anonymous-user-id", "@deepseek-ai/dsh-atomic-write", "@deepseek-ai/dsh-attachment", "@deepseek-ai/dsh-brand", "@deepseek-ai/dsh-code-runtime", "@deepseek-ai/dsh-credentials", "@deepseek-ai/dsh-fs", "@deepseek-ai/dsh-goal", "@deepseek-ai/dsh-goal-round-driver", "@deepseek-ai/dsh-home-paths", "@deepseek-ai/dsh-invariants", "@deepseek-ai/dsh-jobs", "@deepseek-ai/dsh-jobs-local", "@deepseek-ai/dsh-launch-environment", "@deepseek-ai/dsh-llm", "@deepseek-ai/dsh-llm-deepseek", "@deepseek-ai/dsh-llm-retry", "@deepseek-ai/dsh-output-retention", "@deepseek-ai/dsh-sandbox", "@deepseek-ai/dsh-sandbox-policy", "@deepseek-ai/dsh-scope", "@deepseek-ai/dsh-session", "@deepseek-ai/dsh-session-checkpoint-policy", "@deepseek-ai/dsh-session-persistence", "@deepseek-ai/dsh-session-persistence-jsonl", "@deepseek-ai/dsh-session-projection", "@deepseek-ai/dsh-session-title", "@deepseek-ai/dsh-settings", "@deepseek-ai/dsh-shell", "@deepseek-ai/dsh-shell-env", "@deepseek-ai/dsh-skill", "@deepseek-ai/dsh-skill-filesystem", "@deepseek-ai/dsh-subprocess", "@deepseek-ai/dsh-system-prompt", "@deepseek-ai/dsh-timeout", "@deepseek-ai/dsh-tool-bash", "@deepseek-ai/dsh-tool-goal", "@deepseek-ai/dsh-tool-jobs", "@deepseek-ai/dsh-tool-skill", "@deepseek-ai/dsh-tools", "@deepseek-ai/dsh-typert-protocol", "@deepseek-ai/dsh-user-approval"], deepseek_cordis_package_name: "@deepseek-ai/cordis", deepseek_cordis_version: "4.0.1", deepseek_support_packages: { "@deepseek-ai/cordis-plugin-timer": "1.1.3" }, platforms: { "linux-x64": { package_name: "@openai/codex-linux-x64", target: "x86_64-unknown-linux-musl", binary_name: "codex", sha256: "660e159a49e823ac8e5986cb238f73158ce4b957d40d9292f8de90862644b501" }, "win32-x64": { package_name: "@openai/codex-win32-x64", target: "x86_64-pc-windows-msvc", binary_name: "codex.exe", sha256: "e4c11374bd9de8ad5c3b7617fd4654bb7839901edb0863f9930666863c7a021b" } }, pi_coding_agent_package_name: "@earendil-works/pi-coding-agent", pi_ai_package_name: "@earendil-works/pi-ai", pi_version: "0.85.1", pi_support_packages: ["@earendil-works/pi-agent-core", "@earendil-works/pi-telemetry", "@earendil-works/pi-tui", "@earendil-works/chord"], grok_version: "1.0.30", grok_platforms: { "linux-x64": { package_name: "@xai-official/grok-linux-x64", binary_name: "grok", sha256: "504dd6546ab991b75d36698242875ce461489cd1f8cd84285873cb55bd5c7d54" }, "win32-x64": { package_name: "@xai-official/grok-win32-x64", binary_name: "grok.exe", sha256: "48736d1a4342a801ea26d0ecde4c516b653f791399065adaa55973f83abd8867" } } };
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
|
|
@@ -525,8 +525,6 @@ var init_runtime_policy_generated = __esm({
|
|
|
525
525
|
observed_activity_recent_ms: 8e3,
|
|
526
526
|
startup_hold_activation_gap_ms: 9e4,
|
|
527
527
|
hidden_ticker_update_interval_ms: 16,
|
|
528
|
-
client_close_fill_sync_attempts: 3,
|
|
529
|
-
client_close_fill_sync_retry_step_ms: 300,
|
|
530
528
|
post_leverage_update_order_delay_ms: 250,
|
|
531
529
|
takeover_telemetry_error_chars: 500,
|
|
532
530
|
takeover_telemetry_error_name_chars: 120,
|
|
@@ -848,7 +846,6 @@ var init_runtime_policy_generated = __esm({
|
|
|
848
846
|
protective_actions: {
|
|
849
847
|
adoption_request_timeout_milliseconds: 2e4,
|
|
850
848
|
idle_recheck_seconds: 60,
|
|
851
|
-
attention_refresh_seconds: 60,
|
|
852
849
|
evidence_max_items: 32,
|
|
853
850
|
evidence_shared_read_seconds: 10,
|
|
854
851
|
retry_delay_seconds: 15,
|
|
@@ -978,10 +975,6 @@ var init_runtime_policy_generated = __esm({
|
|
|
978
975
|
},
|
|
979
976
|
defaults: {
|
|
980
977
|
server_ai_max_slippage: 5
|
|
981
|
-
},
|
|
982
|
-
risk: {
|
|
983
|
-
max_order_notional: 5e3,
|
|
984
|
-
max_position_notional: 1e4
|
|
985
978
|
}
|
|
986
979
|
},
|
|
987
980
|
agent_cli: {
|
|
@@ -1247,7 +1240,6 @@ var init_runtime_policy_generated = __esm({
|
|
|
1247
1240
|
capacity_recovery_weight_per_minute: 120,
|
|
1248
1241
|
background_floor_weight: 120,
|
|
1249
1242
|
background_admission_wait_seconds: 90,
|
|
1250
|
-
cooldown_seconds: 60,
|
|
1251
1243
|
metadata_ttl_seconds: 300,
|
|
1252
1244
|
user_fees_ttl_seconds: 300,
|
|
1253
1245
|
account_mode_ttl_seconds: 30,
|
|
@@ -1514,7 +1506,7 @@ var init_runtime_policy_generated = __esm({
|
|
|
1514
1506
|
});
|
|
1515
1507
|
|
|
1516
1508
|
// lib/constants.ts
|
|
1517
|
-
var MS_PER_SECOND, SECONDS_PER_MINUTE, MINUTES_PER_HOUR, HOURS_PER_DAY, DAYS_PER_WEEK, MS_PER_MINUTE, SECONDS_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_WEEK, MINUTES_PER_DAY, MINUTES_PER_WEEK, MS_PER_HOUR, MS_PER_DAY, READ_STAMP_TIE_MS, READ_STAMP_STEP_BACK_MS, CLOCK_FIELD_DIGITS, BACKOFF_GROWTH_FACTOR, BYTES_PER_KIB, BYTES_PER_MIB, BITS_PER_BYTE, BYTE_MASK, OWNER_ONLY_FILE_MODE, OWNER_ONLY_DIRECTORY_MODE, GROUP_OTHER_PERMISSION_BITS, DECIMAL_RADIX, HEX_RADIX, BASE36_RADIX, BYTE_HEX_DIGITS, UINT32_HEX_DIGITS, RANDOM_FRACTION_PREFIX_LENGTH, PERCENT_SCALE, MIDPOINT_DIVISOR, SQUARE_EXPONENT, FNV1A_32_OFFSET_BASIS, FNV1A_32_PRIME, JSON_INDENT_SPACES, INT32_MIN, INT32_MAX, SET_TIMEOUT_MAX_DELAY_MS, POSITION_SIZE_EPSILON, CANDLE_TIMEFRAME_SECONDS, HTTP_STATUS, HTTP_STATUS_MIN, HTTP_STATUS_MAX, HTTP_CLIENT_ERROR_MIN, HTTP_SERVER_ERROR_MIN, PROMPT_RESCUE_ASKS_PER_CYCLE_BUILD,
|
|
1509
|
+
var MS_PER_SECOND, SECONDS_PER_MINUTE, MINUTES_PER_HOUR, HOURS_PER_DAY, DAYS_PER_WEEK, MS_PER_MINUTE, SECONDS_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_WEEK, MINUTES_PER_DAY, MINUTES_PER_WEEK, MS_PER_HOUR, MS_PER_DAY, READ_STAMP_TIE_MS, READ_STAMP_STEP_BACK_MS, CLOCK_FIELD_DIGITS, BACKOFF_GROWTH_FACTOR, BYTES_PER_KIB, BYTES_PER_MIB, BITS_PER_BYTE, BYTE_MASK, OWNER_ONLY_FILE_MODE, OWNER_ONLY_DIRECTORY_MODE, GROUP_OTHER_PERMISSION_BITS, DECIMAL_RADIX, HEX_RADIX, BASE36_RADIX, BYTE_HEX_DIGITS, UINT32_HEX_DIGITS, RANDOM_FRACTION_PREFIX_LENGTH, PERCENT_SCALE, MIDPOINT_DIVISOR, SQUARE_EXPONENT, FNV1A_32_OFFSET_BASIS, FNV1A_32_PRIME, JSON_INDENT_SPACES, INT32_MIN, INT32_MAX, SET_TIMEOUT_MAX_DELAY_MS, POSITION_SIZE_EPSILON, CANDLE_TIMEFRAME_SECONDS, HTTP_STATUS, HTTP_STATUS_MIN, HTTP_STATUS_MAX, HTTP_CLIENT_ERROR_MIN, HTTP_SERVER_ERROR_MIN, PROMPT_RESCUE_ASKS_PER_CYCLE_BUILD, AI_COST_ESTIMATE_PERIOD_DAYS, SECONDS_PER_AI_COST_ESTIMATE_PERIOD, DATE_FIELD_DIGITS, EXTERNAL_INFERENCE_LIMITS, NODE_ARGV_COMMAND_ARGS_START, EXIT_CODE_TEMPFAIL, SHA256_INITIAL_STATE, SHA256_ROUND_CONSTANTS, SHA256, UINT64_HIGH_WORD_DIVISOR, CANONICAL_BASE64URL, INFERENCE_ENVELOPE_CRYPTO, EXTERNAL_INFERENCE_SCHEMA_BOUNDS, JSON_RPC_ERROR_CODES, INFERENCE_MCP_SCHEMA_PROBE_MAX_DEPTH, INFERENCE_HOST_PROCESS_LOCK_RECORD_SCHEMA_VERSION, NATIVE_PROTECTION_RECORD_WITH_LOTS_VERSION, INFERENCE_HOST_RECLAIM_GUARD_CREATE_PASSES, LINUX_PROC_STAT_COMM_TERMINATOR_CHARS, INFERENCE_HOST_RANDOM_BYTES, INFERENCE_OAUTH_TOKEN_MAX_LENGTH, INFERENCE_CREDENTIAL_WINDOWS_NOT_FOUND_EXIT_CODE, MACOS_SECURITY_ITEM_NOT_FOUND_EXIT_CODE, INFERENCE_CREDENTIAL_LABEL_ACCOUNT_KEY_CHARS, INFERENCE_HOST_STABLE_OPERATION_ID_HASH_CHARS, INFERENCE_HOST_DRAIN_PRIORITY, INFERENCE_JOB_CLAIM_SCHEMA_VERSION, INFERENCE_HOST_WINDOWS_TASK_IDENTITY_MAX_CHARS, INFERENCE_HOST_OWNER_ONLY_EXECUTABLE_MODE, WINDOWS_TASKKILL_PROCESS_NOT_FOUND_EXIT_CODE, INFERENCE_HOST_CLI_MAX_SERVICE_POSITIONALS, INFERENCE_HOST_CLI_MAX_COMMAND_POSITIONALS, INFERENCE_HOST_DISPLAY_NAME_MAX_CHARS, INFERENCE_HOST_REVOCATION_CHECKPOINT_MAX_CHARS, INFERENCE_HOST_MODEL_ID_MAX_CHARS, CODEX_RECOVERY_RECEIPT_MAX_CHARS, CODEX_HOSTED_ATTEMPT_PATH_SEGMENTS, CODEX_GUARDIAN_PROCESS_TOKEN_BYTES, CODEX_RATE_LIMIT_EXHAUSTED_PERCENT, INFERENCE_HOST_PROXY_TOKEN_BYTES, AGENT_TOOL_SERVER_TOKEN_BYTES, GROK_NATIVE_SESSION_GROUP_NAME_MAX_CHARS, GROK_POLICY_TRANSPORT_MAX_BYTES, EXO_POLICY_MAX_TOOL_ROUNDS, EXO_POLICY_MAX_MODELS, EXO_POLICY_MODEL_NAME_MAX_CHARS, CLAUDE_CODE_POLICY_MAX_MODELS, CLAUDE_CODE_POLICY_MODEL_NAME_MAX_CHARS, CLAUDE_CODE_POLICY_MAX_TURNS, ANTHROPIC_SCHEMA_PROPERTY_NAME_MAX_CHARS, EXO_RUNTIME_VERSION_COMMIT_CHARS, PI_QUALIFIED_MODEL_ID_MAX_CHARS, PI_STRUCTURED_OUTPUT_MAX_DEPTH, PI_STRUCTURED_OUTPUT_MAX_PROPERTIES, INFERENCE_HOST_API_KEY_MIN_CHARS, INFERENCE_HOST_API_KEY_MAX_BYTES, INFERENCE_HOST_API_KEY_IDENTITY_HEX_CHARS, DEEPSEEK_HARNESS_NODE_LTS_MAJOR, DEEPSEEK_HARNESS_NODE_LTS_MIN_MINOR, DEEPSEEK_HARNESS_NODE_CURRENT_MAJOR, PROMPT_FIXED_DIGITS, PROMPT_SIGNIFICANT_DIGITS, PROMPT_NUMBER_MAX_DIGITS, PROMPT_RELATIVE_VOLUME_DIGITS, BINARY_RADIX, PROMPT_PRICE_INTEGER_THRESHOLD, PROMPT_MARGIN_UTILIZATION_DECIMALS, PROMPT_SYMBOL_MAX_CHARS, PROMPT_PARTIAL_UNIT_ROUND_UP_FRACTION, HALF_UP_ROUNDING_OFFSET, PROMPT_ENTRY_PRICE_MATCH_ABS_TOLERANCE, PROMPT_ENTRY_PRICE_MATCH_REL_TOLERANCE, DECISION_OUTPUT_EXAMPLE_TRADABILITY, INDICATOR_RSI_PERIOD, INDICATOR_ATR_PERIOD, INDICATOR_MACD_FAST_PERIOD, INDICATOR_MACD_SLOW_PERIOD, INDICATOR_MACD_SIGNAL_PERIOD, INDICATOR_BOLLINGER_PERIOD, INDICATOR_BOLLINGER_STD_DEV, INDICATOR_OSCILLATOR_MAX, EMA_SMOOTHING_NUMERATOR, PROMPT_EMA_PERIODS, JSON_UNICODE_ESCAPE_PREFIX_LENGTH, JSON_UNICODE_ESCAPE_HEX_DIGITS, JSON_CONTROL_CHARACTER_MAX, RUNTIME_DEBUG_SNIPPET_CHARS, RUNTIME_DEBUG_PROMPT_SNIPPET_CHARS, RUNTIME_DEBUG_TOKEN_PREFIX_CHARS, RUNTIME_DEBUG_USD_DECIMALS, REVIEW_FAILURE_DETAIL_MAX_CHARS, RUNTIME_LATENCY_SECONDS_DECIMALS, AI_SCHEDULE_CLOCK_PARTS, ESTIMATED_CHARS_PER_TOKEN, PROVIDER_ERROR_RAW_TEXT_MAX_CHARS, AI_CALL_COST_DECIMALS, PROVIDER_DIAGNOSTIC_LIMITS, AI_INVOCATION_CONTRACT_VERSION, AI_INVOCATION_TELEMETRY_LIMITS, PROVIDER_USAGE_DETAIL_LIMITS, HYPERLIQUID_EXCHANGE_SPECIFICATION, HYPERLIQUID_TIF_GTC, HYPERLIQUID_TPSL_BATCH_MIN_ORDERS, HYPERLIQUID_USER_FILLS_PROVIDER_PAGE_CAP, HYPERLIQUID_ROW_WEIGHTED_INFO_REQUESTS, HYPERLIQUID_INFO_ROWS_PER_EXTRA_WEIGHT, HYPERLIQUID_PUBLIC_READ_WINDOWS_KEPT, CLIENT_RUNTIME_NOTE_GAP_MAX_LOOPS, HYPERLIQUID_META_AND_ASSET_CTXS_PARTS, HYPERLIQUID_SIDE_PAIR_LENGTH, HYPERLIQUID_SIGNED_SIZE_MATCH_EXTRA_DECIMALS, HYPERLIQUID_OPEN_ORDERS_MAX_NESTING_DEPTH, ACCOUNT_PAYLOAD_MODE_SEARCH_MAX_DEPTH, HYPERLIQUID_ACCOUNT_ROUNDING_DECIMALS, HYPERLIQUID_UNREALIZED_PNL_ZERO_TOLERANCE, HYPERLIQUID_MAX_DEPLOYER_FEE_SCALE, HYPERLIQUID_DEPLOYER_FEE_SCALE_MULTIPLIER, HYPERLIQUID_GROWTH_MODE_FEE_FACTOR, HYPERLIQUID_ALIGNED_QUOTE_NON_DEPLOYER_FEE_FACTOR, HYPERLIQUID_CLOSE_SIZE_RELATIVE_TOLERANCE, HYPERLIQUID_POSITION_SIZE_MATCH_ABS_TOLERANCE, HYPERLIQUID_POSITION_SIZE_MATCH_RELATIVE_TOLERANCE, HYPERLIQUID_LOT_FLOOR_NOISE_DECIMALS, HYPERLIQUID_RECOVERY_BACKOFF_MAX_EXPONENT, HYPERLIQUID_RECOVERY_CONCURRENCY_GROWTH_FACTOR, UUID_BYTES, UUID_HEX_GROUP_ENDS, MSGPACK, CLIENT_RUNTIME_DEFAULT_RETRY_SECONDS, CLIENT_RUNTIME_PROVIDER_ATTEMPT_SUMMARY_MAX_CHARS, CLIENT_RUNTIME_HL_REQUEST_TYPE_MAX_CHARS, CLIENT_RUNTIME_DRAWDOWN_DEBUG_DECIMALS, CLIENT_PROTECTIVE_GROUP_VERSION, CLIENT_PROTECTIVE_TPSL_PAIR_LEGS, CLIENT_PROTECTIVE_FILL_MATCH_ABS_TOLERANCE, CLIENT_PROTECTIVE_FILL_MATCH_REL_TOLERANCE, CLIENT_CLOSE_FILL_EPSILON_ULPS, COPY_TRADING_SIZE_EPSILON, COPY_TRADING_RELATIVE_SIZE_TOLERANCE, COPY_TRADING_NOTIONAL_CAP_TOLERANCE_USD, CLIENT_ACCOUNT_PNL_NONZERO_MIN_USD, RUNTIME_PORTFOLIO_PERIOD_ENTRY_LENGTH, CLIENT_EXCHANGE_RECONCILIATION_MAX_DELAY_MS, RFC1918_172_BLOCK_SECOND_OCTET, AGENT_CLI_TAKEOVER_REQUIRED_EXIT_CODE, EXIT_CODE_INTERRUPTED, EXIT_CODE_SIGNAL_BASE, CLIENT_PROTECTION_CAPABILITY_VERSION, BYOK_PROVIDER_DISPLAY_ORDER_STEP, TOKENS_PER_MILLION, RENDER_DEBUG_ID_RANDOM_CHARS;
|
|
1518
1510
|
var init_constants = __esm({
|
|
1519
1511
|
"lib/constants.ts"() {
|
|
1520
1512
|
"use strict";
|
|
@@ -1610,7 +1602,6 @@ var init_constants = __esm({
|
|
|
1610
1602
|
HTTP_CLIENT_ERROR_MIN = 400;
|
|
1611
1603
|
HTTP_SERVER_ERROR_MIN = 500;
|
|
1612
1604
|
PROMPT_RESCUE_ASKS_PER_CYCLE_BUILD = 2;
|
|
1613
|
-
USD_DISPLAY_DECIMALS = 2;
|
|
1614
1605
|
AI_COST_ESTIMATE_PERIOD_DAYS = 30;
|
|
1615
1606
|
SECONDS_PER_AI_COST_ESTIMATE_PERIOD = SECONDS_PER_DAY * AI_COST_ESTIMATE_PERIOD_DAYS;
|
|
1616
1607
|
DATE_FIELD_DIGITS = 2;
|
|
@@ -1974,8 +1965,11 @@ var init_constants = __esm({
|
|
|
1974
1965
|
hip3_asset_id_base: 1e5,
|
|
1975
1966
|
hip3_asset_id_dex_stride: 1e4,
|
|
1976
1967
|
// A trailing stop's percent retracement carries at most this many decimals.
|
|
1977
|
-
trailing_retracement_pct_max_decimals: 3
|
|
1968
|
+
trailing_retracement_pct_max_decimals: 3,
|
|
1969
|
+
// Good-til-cancelled time in force as the order wire spells it.
|
|
1970
|
+
good_til_cancelled_time_in_force: "Gtc"
|
|
1978
1971
|
};
|
|
1972
|
+
HYPERLIQUID_TIF_GTC = HYPERLIQUID_EXCHANGE_SPECIFICATION.good_til_cancelled_time_in_force;
|
|
1979
1973
|
HYPERLIQUID_TPSL_BATCH_MIN_ORDERS = 2;
|
|
1980
1974
|
HYPERLIQUID_USER_FILLS_PROVIDER_PAGE_CAP = 2e3;
|
|
1981
1975
|
HYPERLIQUID_ROW_WEIGHTED_INFO_REQUESTS = [
|
|
@@ -2063,6 +2057,7 @@ var init_constants = __esm({
|
|
|
2063
2057
|
AGENT_CLI_TAKEOVER_REQUIRED_EXIT_CODE = 2;
|
|
2064
2058
|
EXIT_CODE_INTERRUPTED = 130;
|
|
2065
2059
|
EXIT_CODE_SIGNAL_BASE = 128;
|
|
2060
|
+
CLIENT_PROTECTION_CAPABILITY_VERSION = 2;
|
|
2066
2061
|
BYOK_PROVIDER_DISPLAY_ORDER_STEP = 10;
|
|
2067
2062
|
TOKENS_PER_MILLION = 1e6;
|
|
2068
2063
|
RENDER_DEBUG_ID_RANDOM_CHARS = 6;
|
|
@@ -20649,8 +20644,6 @@ var init_runtime_policy_generated2 = __esm({
|
|
|
20649
20644
|
observed_activity_recent_ms: 8e3,
|
|
20650
20645
|
startup_hold_activation_gap_ms: 9e4,
|
|
20651
20646
|
hidden_ticker_update_interval_ms: 16,
|
|
20652
|
-
client_close_fill_sync_attempts: 3,
|
|
20653
|
-
client_close_fill_sync_retry_step_ms: 300,
|
|
20654
20647
|
post_leverage_update_order_delay_ms: 250,
|
|
20655
20648
|
takeover_telemetry_error_chars: 500,
|
|
20656
20649
|
takeover_telemetry_error_name_chars: 120,
|
|
@@ -20972,7 +20965,6 @@ var init_runtime_policy_generated2 = __esm({
|
|
|
20972
20965
|
protective_actions: {
|
|
20973
20966
|
adoption_request_timeout_milliseconds: 2e4,
|
|
20974
20967
|
idle_recheck_seconds: 60,
|
|
20975
|
-
attention_refresh_seconds: 60,
|
|
20976
20968
|
evidence_max_items: 32,
|
|
20977
20969
|
evidence_shared_read_seconds: 10,
|
|
20978
20970
|
retry_delay_seconds: 15,
|
|
@@ -21102,10 +21094,6 @@ var init_runtime_policy_generated2 = __esm({
|
|
|
21102
21094
|
},
|
|
21103
21095
|
defaults: {
|
|
21104
21096
|
server_ai_max_slippage: 5
|
|
21105
|
-
},
|
|
21106
|
-
risk: {
|
|
21107
|
-
max_order_notional: 5e3,
|
|
21108
|
-
max_position_notional: 1e4
|
|
21109
21097
|
}
|
|
21110
21098
|
},
|
|
21111
21099
|
agent_cli: {
|
|
@@ -21371,7 +21359,6 @@ var init_runtime_policy_generated2 = __esm({
|
|
|
21371
21359
|
capacity_recovery_weight_per_minute: 120,
|
|
21372
21360
|
background_floor_weight: 120,
|
|
21373
21361
|
background_admission_wait_seconds: 90,
|
|
21374
|
-
cooldown_seconds: 60,
|
|
21375
21362
|
metadata_ttl_seconds: 300,
|
|
21376
21363
|
user_fees_ttl_seconds: 300,
|
|
21377
21364
|
account_mode_ttl_seconds: 30,
|
|
@@ -59738,16 +59725,18 @@ async function getExecutionAssetMetadata(exchange, symbol2, options) {
|
|
|
59738
59725
|
});
|
|
59739
59726
|
if (!response.ok) {
|
|
59740
59727
|
const summary = `Failed to fetch execution asset metadata: ${response.status} ${response.statusText}`;
|
|
59728
|
+
const code = await response.clone().json().then((body) => typeof body?.detail?.code === "string" ? body.detail.code : null).catch(() => null);
|
|
59741
59729
|
const detail = await getErrorMessageFromResponse(response, summary);
|
|
59742
59730
|
throw new ExecutionAssetMetadataRequestError(
|
|
59743
59731
|
detail === summary ? summary : `${summary}: ${detail}`,
|
|
59744
59732
|
response.status,
|
|
59745
|
-
parseRetryAfterMs2(response.headers.get("Retry-After"))
|
|
59733
|
+
parseRetryAfterMs2(response.headers.get("Retry-After")),
|
|
59734
|
+
code
|
|
59746
59735
|
);
|
|
59747
59736
|
}
|
|
59748
59737
|
return response.json();
|
|
59749
59738
|
}
|
|
59750
|
-
var ExecutionAssetMetadataRequestError;
|
|
59739
|
+
var ExecutionAssetMetadataRequestError, CLIENT_EXECUTION_METADATA_DEVICE_READ, executionMetadataNeedsDeviceRead;
|
|
59751
59740
|
var init_market_data = __esm({
|
|
59752
59741
|
"lib/api/market-data.ts"() {
|
|
59753
59742
|
"use strict";
|
|
@@ -59761,13 +59750,16 @@ var init_market_data = __esm({
|
|
|
59761
59750
|
init_shared();
|
|
59762
59751
|
init_constants();
|
|
59763
59752
|
ExecutionAssetMetadataRequestError = class extends Error {
|
|
59764
|
-
constructor(message, status, retryAfterMs) {
|
|
59753
|
+
constructor(message, status, retryAfterMs, code = null) {
|
|
59765
59754
|
super(message);
|
|
59766
59755
|
this.status = status;
|
|
59767
59756
|
this.retryAfterMs = retryAfterMs;
|
|
59757
|
+
this.code = code;
|
|
59768
59758
|
this.name = "ExecutionAssetMetadataRequestError";
|
|
59769
59759
|
}
|
|
59770
59760
|
};
|
|
59761
|
+
CLIENT_EXECUTION_METADATA_DEVICE_READ = "client_execution_metadata_device_read";
|
|
59762
|
+
executionMetadataNeedsDeviceRead = (error48) => error48 instanceof ExecutionAssetMetadataRequestError && error48.code === CLIENT_EXECUTION_METADATA_DEVICE_READ;
|
|
59771
59763
|
}
|
|
59772
59764
|
});
|
|
59773
59765
|
|
|
@@ -60315,6 +60307,17 @@ var init_admin_signups = __esm({
|
|
|
60315
60307
|
}
|
|
60316
60308
|
});
|
|
60317
60309
|
|
|
60310
|
+
// lib/api/client-exchange-reconciliation.ts
|
|
60311
|
+
var init_client_exchange_reconciliation = __esm({
|
|
60312
|
+
"lib/api/client-exchange-reconciliation.ts"() {
|
|
60313
|
+
"use strict";
|
|
60314
|
+
init_define_VTX_CLAUDE_CODE_POLICY();
|
|
60315
|
+
init_define_VTX_EXO_POLICY();
|
|
60316
|
+
init_define_VTX_GROK_POLICY();
|
|
60317
|
+
init_define_VTX_PI_MODEL_POLICY();
|
|
60318
|
+
}
|
|
60319
|
+
});
|
|
60320
|
+
|
|
60318
60321
|
// lib/runtime/hyperliquid-account-mode-contract.ts
|
|
60319
60322
|
function resolveExactHyperliquidAccountMode(userAbstraction, ...dexEvidence) {
|
|
60320
60323
|
const mode = extractCanonicalHyperliquidAccountMode(userAbstraction);
|
|
@@ -61808,6 +61811,92 @@ var init_hyperliquid_exchange_rejections = __esm({
|
|
|
61808
61811
|
}
|
|
61809
61812
|
});
|
|
61810
61813
|
|
|
61814
|
+
// lib/runtime/hyperliquid-market-catalog.ts
|
|
61815
|
+
var DEFAULT_DEX, DEFAULT_DEX_INDEX, ISOLATED_ONLY_MARGIN_MODES, malformed, perpDexIndexes, integer3, marketIdentityRow, listedMarketRows;
|
|
61816
|
+
var init_hyperliquid_market_catalog = __esm({
|
|
61817
|
+
"lib/runtime/hyperliquid-market-catalog.ts"() {
|
|
61818
|
+
"use strict";
|
|
61819
|
+
init_define_VTX_CLAUDE_CODE_POLICY();
|
|
61820
|
+
init_define_VTX_EXO_POLICY();
|
|
61821
|
+
init_define_VTX_GROK_POLICY();
|
|
61822
|
+
init_define_VTX_PI_MODEL_POLICY();
|
|
61823
|
+
init_constants();
|
|
61824
|
+
init_hyperliquid_market_symbol();
|
|
61825
|
+
init_runtime_error_reason_rules2();
|
|
61826
|
+
DEFAULT_DEX = "";
|
|
61827
|
+
DEFAULT_DEX_INDEX = 0;
|
|
61828
|
+
ISOLATED_ONLY_MARGIN_MODES = /* @__PURE__ */ new Set(["nocross", "strictisolated"]);
|
|
61829
|
+
malformed = (message) => new RuntimeReasonError(message, "hyperliquid_data_unavailable");
|
|
61830
|
+
perpDexIndexes = (perpDexs) => {
|
|
61831
|
+
if (!Array.isArray(perpDexs) || perpDexs.length === 0 || perpDexs.some((item) => item !== null && (!item || typeof item !== "object" || Array.isArray(item) || !String(item.name ?? "").trim()))) {
|
|
61832
|
+
throw malformed("Hyperliquid returned a malformed perpDexs list.");
|
|
61833
|
+
}
|
|
61834
|
+
const indexes = /* @__PURE__ */ new Map([[DEFAULT_DEX, DEFAULT_DEX_INDEX]]);
|
|
61835
|
+
perpDexs.forEach((item, index) => {
|
|
61836
|
+
if (item === null) indexes.set(DEFAULT_DEX, index);
|
|
61837
|
+
else indexes.set(String(item.name).trim().toLowerCase(), index);
|
|
61838
|
+
});
|
|
61839
|
+
return indexes;
|
|
61840
|
+
};
|
|
61841
|
+
integer3 = (value) => {
|
|
61842
|
+
const parsed = typeof value === "number" ? value : typeof value === "string" && value.trim() ? Number(value) : NaN;
|
|
61843
|
+
return Number.isFinite(parsed) ? Math.trunc(parsed) : null;
|
|
61844
|
+
};
|
|
61845
|
+
marketIdentityRow = (input) => {
|
|
61846
|
+
const symbol2 = normalizeHyperliquidMarketSymbol(input.asset.name);
|
|
61847
|
+
if (!symbol2) throw malformed("A Hyperliquid market entry has no name.");
|
|
61848
|
+
const dex = getHyperliquidMarketDex(symbol2);
|
|
61849
|
+
if (dex !== String(input.dex ?? "").trim().toLowerCase()) throw malformed(`Hyperliquid listed ${symbol2} under another DEX.`);
|
|
61850
|
+
const baseSymbol = dex ? symbol2.slice(dex.length + 1) : symbol2;
|
|
61851
|
+
const szDecimals = integer3(input.asset.szDecimals);
|
|
61852
|
+
if (szDecimals === null || szDecimals < 0) throw malformed(`Hyperliquid's entry for ${symbol2} has no size precision.`);
|
|
61853
|
+
const leverage = input.asset.maxLeverage ? integer3(input.asset.maxLeverage) : 1;
|
|
61854
|
+
if (leverage === null) throw malformed(`Hyperliquid's entry for ${symbol2} has an invalid max leverage.`);
|
|
61855
|
+
const rawMarginMode = input.asset.marginMode;
|
|
61856
|
+
const marginMode = rawMarginMode === null || rawMarginMode === void 0 ? null : String(rawMarginMode).trim() || null;
|
|
61857
|
+
const assetId = input.perpDexIndex === DEFAULT_DEX_INDEX ? input.indexInMeta : HYPERLIQUID_EXCHANGE_SPECIFICATION.hip3_asset_id_base + input.perpDexIndex * HYPERLIQUID_EXCHANGE_SPECIFICATION.hip3_asset_id_dex_stride + input.indexInMeta;
|
|
61858
|
+
return {
|
|
61859
|
+
symbol: symbol2,
|
|
61860
|
+
dex,
|
|
61861
|
+
coin: symbol2,
|
|
61862
|
+
base_symbol: baseSymbol,
|
|
61863
|
+
quote_symbol: "USDC",
|
|
61864
|
+
display_symbol: `${baseSymbol}-USDC`,
|
|
61865
|
+
asset_id: assetId,
|
|
61866
|
+
asset_index: assetId,
|
|
61867
|
+
index_in_meta: input.indexInMeta,
|
|
61868
|
+
perp_dex_index: input.perpDexIndex,
|
|
61869
|
+
max_leverage: Math.max(1, leverage),
|
|
61870
|
+
sz_decimals: szDecimals,
|
|
61871
|
+
market_type: "perp",
|
|
61872
|
+
margin_mode: marginMode,
|
|
61873
|
+
only_isolated: input.asset.onlyIsolated === true || ISOLATED_ONLY_MARGIN_MODES.has(String(marginMode ?? "").toLowerCase())
|
|
61874
|
+
};
|
|
61875
|
+
};
|
|
61876
|
+
listedMarketRows = (requested, metas, dexIndexes, caseSensitiveSymbols, options) => {
|
|
61877
|
+
if (Array.isArray(caseSensitiveSymbols)) configureHyperliquidMarketSymbolCasing(caseSensitiveSymbols);
|
|
61878
|
+
const wanted = new Set(requested.map((symbol2) => normalizeHyperliquidMarketSymbol(symbol2)).filter(Boolean));
|
|
61879
|
+
const listed = {};
|
|
61880
|
+
for (const [dex, response] of Object.entries(metas)) {
|
|
61881
|
+
const universe = response && typeof response === "object" ? response.universe : null;
|
|
61882
|
+
if (!Array.isArray(universe) || universe.length === 0 || universe.some((asset) => !asset || typeof asset !== "object" || !String(asset.name ?? "").trim())) {
|
|
61883
|
+
throw malformed(`Hyperliquid returned malformed market metadata for ${dex || "the default DEX"}.`);
|
|
61884
|
+
}
|
|
61885
|
+
const perpDexIndex = dex === DEFAULT_DEX ? DEFAULT_DEX_INDEX : dexIndexes.get(dex);
|
|
61886
|
+
if (perpDexIndex === void 0) throw malformed(`Hyperliquid does not list the perp DEX ${dex}.`);
|
|
61887
|
+
universe.forEach((asset, indexInMeta) => {
|
|
61888
|
+
const symbol2 = normalizeHyperliquidMarketSymbol(asset.name);
|
|
61889
|
+
const delisted = asset.isDelisted === true;
|
|
61890
|
+
if (wanted.has(symbol2) && (options.includeDelisted || !delisted)) {
|
|
61891
|
+
listed[symbol2] = marketIdentityRow({ dex, perpDexIndex, indexInMeta, asset });
|
|
61892
|
+
}
|
|
61893
|
+
});
|
|
61894
|
+
}
|
|
61895
|
+
return listed;
|
|
61896
|
+
};
|
|
61897
|
+
}
|
|
61898
|
+
});
|
|
61899
|
+
|
|
61811
61900
|
// lib/runtime/exchange-mutation-fence.ts
|
|
61812
61901
|
var activeSettlementsByScope, normalizeScope, trackBrowserExchangeMutation, waitForBrowserExchangeMutationSettlement;
|
|
61813
61902
|
var init_exchange_mutation_fence = __esm({
|
|
@@ -93135,7 +93224,7 @@ var init_hyperliquid_signer = __esm({
|
|
|
93135
93224
|
});
|
|
93136
93225
|
|
|
93137
93226
|
// lib/runtime/hyperliquid-client.ts
|
|
93138
|
-
var HyperliquidExchangeRejectionError, durableMutationAuthorityArgs, assertFreshPreparedExecutionContext, normalizeSymbol, HYPERLIQUID_NONCE_STORAGE_KEY, HYPERLIQUID_NONCE_LOCK_NAME, lastGeneratedNonce, readBrowserStoredHyperliquidNonce, writeBrowserStoredHyperliquidNonce, browserNonceCoordinator, allocateHyperliquidNonce, hostNonceAllocator, allocateActionNonce, generateHyperliquidNonce, normalizeDecimalString, HYPERLIQUID_PRICE_SIGNIFICANT_FIGURES, HYPERLIQUID_INTEGER_PRICE_MINIMUM, shortestDecimalParts, formatHyperliquidPerpPriceGrid, formatHyperliquidTriggerPriceWire, hyperliquidOrderPriceRounding, formatHyperliquidOrderPriceWire, countSignificantDigits, countDecimalPlaces, validateHyperliquidPerpPriceWire, validateHyperliquidSizeWire, formatSizeWire, inferApiUrl, inferIsTestnet, postHyperliquidInfoRead, postHyperliquidInfo, fetchBrowserHyperliquidInfoPayload, fetchBrowserHyperliquidInfoRead, fetchBrowserHyperliquidInfoText, coerceMarketMaxLeverage, toFiniteNumber, OPEN_ORDER_NUMERIC_STRING, OPEN_ORDER_ID_STRING, parseCanonicalOpenOrderId, parseOpenOrderFiniteNumber, parseOpenOrderNonNegativeNumber, NATIVE_FIRED_TRIGGER_CONDITION, parseOpenOrderPositiveNumber, parseOpenOrderPresentationNumber, readOpenOrderField, firstFiniteNumber, parseFundingUsdcFromInfoPosition, isExchangeIsolatedOnly, resolveLeverageTarget, computeHip3AssetId, getPerpDexIndexMap, buildAssetInfosFromMetaResponse, requireWalletAddress, assertPositiveInteger, assertPositiveNumber, normalizeOrderSide, normalizeHyperliquidClientOrderId, resolveAssets, findResolvedAsset, normalizeExecutionAssetMetadata, resolveHyperliquidAsset, resolveHyperliquidAssetIndex, decimalUnits, quantizeHyperliquidOrderSizeValue, hyperliquidSignedSizeMatchesRequestedSize, finitePositive, readDevicePrivateExecutionContext, quantizeHyperliquidOrderSize, fetchBrowserAvailableAssets, fetchBrowserAllMids, fetchBrowserSymbolMidPrice, fetchBrowserOpenOrders, parseCanonicalHyperliquidOrderStatusEvidence, fetchBrowserOrderStatusEvidence, fetchBrowserUserRole, fetchBrowserAccountState, fetchBrowserPosition, buildHyperliquidOrderWire, buildHyperliquidTriggerOrderWire, signHyperliquidPayload, signHyperliquidPreparedAction, buildHyperliquidCancelPayload, buildHyperliquidUpdateLeveragePayload, buildHyperliquidMarketOrderPayload, buildHyperliquidLimitOrderPayload, buildHyperliquidTriggerOrderPayload, buildHyperliquidOrderBatchPayload, buildHyperliquidModifyOrderPayload, TRAILING_PCT_PATTERN, buildHyperliquidTrailingStopPayload, extractHyperliquidExchangeError, acknowledgementLookupPacing, lookupUntilListed, resolveHyperliquidTriggerAcknowledgements, readHyperliquidTrailingStopAcknowledgement, resolveHyperliquidModifyAcknowledgement, isDefinitiveHyperliquidExchangeResponse, extractDefinitiveHyperliquidOrderId, CANONICAL_POSITIVE_DECIMAL_PATTERN, extractCanonicalHyperliquidOrderStateAcknowledgement, extractCanonicalHyperliquidOrderStateAcknowledgements, extractCanonicalHyperliquidFilledOrderAcknowledgement, extractDefinitiveHyperliquidOrderMemberResults, buildHyperliquidOrderDiagnostics, loadClientExecutionReferenceEvidence, sha256Hex, extractSignedPayloadClientOrderId, extractSignedPayloadMutationCorrelation, assertDurableMutationMatchesSignedAction, exchangeRejectionReason, exchangeActionPriority, submitHyperliquidExchangePayload;
|
|
93227
|
+
var HyperliquidExchangeRejectionError, durableMutationAuthorityArgs, assertFreshPreparedExecutionContext, normalizeSymbol, normalizeBotMarket, HYPERLIQUID_NONCE_STORAGE_KEY, HYPERLIQUID_NONCE_LOCK_NAME, lastGeneratedNonce, readBrowserStoredHyperliquidNonce, writeBrowserStoredHyperliquidNonce, browserNonceCoordinator, allocateHyperliquidNonce, hostNonceAllocator, allocateActionNonce, generateHyperliquidNonce, normalizeDecimalString, HYPERLIQUID_PRICE_SIGNIFICANT_FIGURES, HYPERLIQUID_INTEGER_PRICE_MINIMUM, shortestDecimalParts, formatHyperliquidPerpPriceGrid, formatHyperliquidTriggerPriceWire, hyperliquidOrderPriceRounding, formatHyperliquidOrderPriceWire, countSignificantDigits, countDecimalPlaces, validateHyperliquidPerpPriceWire, validateHyperliquidSizeWire, formatSizeWire, inferApiUrl, inferIsTestnet, postHyperliquidInfoRead, postHyperliquidInfo, fetchBrowserHyperliquidInfoPayload, fetchBrowserHyperliquidInfoRead, fetchBrowserHyperliquidInfoText, coerceMarketMaxLeverage, toFiniteNumber, OPEN_ORDER_NUMERIC_STRING, OPEN_ORDER_ID_STRING, parseCanonicalOpenOrderId, parseOpenOrderFiniteNumber, parseOpenOrderNonNegativeNumber, NATIVE_FIRED_TRIGGER_CONDITION, parseOpenOrderPositiveNumber, parseOpenOrderPresentationNumber, readOpenOrderField, firstFiniteNumber, parseFundingUsdcFromInfoPosition, isExchangeIsolatedOnly, resolveLeverageTarget, computeHip3AssetId, getPerpDexIndexMap, buildAssetInfosFromMetaResponse, requireWalletAddress, assertPositiveInteger, assertPositiveNumber, normalizeOrderSide, normalizeHyperliquidClientOrderId, resolveAssets, findResolvedAsset, normalizeExecutionAssetMetadata, readDeviceExecutionAssetMetadata, requireBotProfileId, executionAssetMetadataFor, resolveHyperliquidAsset, resolveHyperliquidAssetIndex, decimalUnits, quantizeHyperliquidOrderSizeValue, hyperliquidSignedSizeMatchesRequestedSize, finitePositive, readDevicePrivateExecutionContext, quantizeHyperliquidOrderSize, fetchBrowserAvailableAssets, fetchBrowserAllMids, fetchBrowserSymbolMidPrice, fetchBrowserOpenOrders, parseCanonicalHyperliquidOrderStatusEvidence, fetchBrowserOrderStatusEvidence, fetchBrowserUserRole, fetchBrowserAccountState, fetchBrowserPosition, buildHyperliquidOrderWire, buildHyperliquidTriggerOrderWire, signHyperliquidPayload, signHyperliquidPreparedAction, buildHyperliquidCancelPayload, buildHyperliquidUpdateLeveragePayload, buildHyperliquidMarketOrderPayload, buildHyperliquidLimitOrderPayload, buildHyperliquidTriggerOrderPayload, buildHyperliquidOrderBatchPayload, buildHyperliquidModifyOrderPayload, TRAILING_PCT_PATTERN, buildHyperliquidTrailingStopPayload, extractHyperliquidExchangeError, acknowledgementLookupPacing, lookupUntilListed, resolveHyperliquidTriggerAcknowledgements, readHyperliquidTrailingStopAcknowledgement, resolveHyperliquidModifyAcknowledgement, isDefinitiveHyperliquidExchangeResponse, extractDefinitiveHyperliquidOrderId, CANONICAL_POSITIVE_DECIMAL_PATTERN, extractCanonicalHyperliquidOrderStateAcknowledgement, extractCanonicalHyperliquidOrderStateAcknowledgements, extractCanonicalHyperliquidFilledOrderAcknowledgement, extractDefinitiveHyperliquidOrderMemberResults, buildHyperliquidOrderDiagnostics, loadClientExecutionReferenceEvidence, sha256Hex, extractSignedPayloadClientOrderId, extractSignedPayloadMutationCorrelation, assertDurableMutationMatchesSignedAction, exchangeRejectionReason, exchangeActionPriority, submitHyperliquidExchangePayload;
|
|
93139
93228
|
var init_hyperliquid_client = __esm({
|
|
93140
93229
|
"lib/runtime/hyperliquid-client.ts"() {
|
|
93141
93230
|
"use strict";
|
|
@@ -93154,6 +93243,8 @@ var init_hyperliquid_client = __esm({
|
|
|
93154
93243
|
init_hyperliquid_exchange_rejections();
|
|
93155
93244
|
init_hyperliquid_market_symbol();
|
|
93156
93245
|
init_network_debug();
|
|
93246
|
+
init_hyperliquid_market_catalog();
|
|
93247
|
+
init_runtime_error_reason_rules2();
|
|
93157
93248
|
init_runtime_redaction();
|
|
93158
93249
|
init_exchange_mutation_fence();
|
|
93159
93250
|
init_runtime_handoff();
|
|
@@ -93196,6 +93287,11 @@ var init_hyperliquid_client = __esm({
|
|
|
93196
93287
|
}
|
|
93197
93288
|
};
|
|
93198
93289
|
normalizeSymbol = (value) => normalizeHyperliquidMarketSymbol(value);
|
|
93290
|
+
normalizeBotMarket = (config2, value) => {
|
|
93291
|
+
const caseSensitiveSymbols = config2?.client_runtime_hyperliquid_case_sensitive_symbols;
|
|
93292
|
+
if (Array.isArray(caseSensitiveSymbols)) configureHyperliquidMarketSymbolCasing(caseSensitiveSymbols);
|
|
93293
|
+
return normalizeSymbol(value);
|
|
93294
|
+
};
|
|
93199
93295
|
HYPERLIQUID_NONCE_STORAGE_KEY = "vtx_hyperliquid_exchange_nonce_v1";
|
|
93200
93296
|
HYPERLIQUID_NONCE_LOCK_NAME = "vtx_hyperliquid_exchange_nonce";
|
|
93201
93297
|
lastGeneratedNonce = 0;
|
|
@@ -93673,16 +93769,57 @@ var init_hyperliquid_client = __esm({
|
|
|
93673
93769
|
only_isolated: metadata.only_isolated === true
|
|
93674
93770
|
};
|
|
93675
93771
|
};
|
|
93772
|
+
readDeviceExecutionAssetMetadata = async (input, symbol2) => {
|
|
93773
|
+
const market = normalizeBotMarket(input.config, symbol2);
|
|
93774
|
+
const dex = getHyperliquidMarketDex(market);
|
|
93775
|
+
const notListed = () => new RuntimeReasonError(`Hyperliquid does not list ${market}.`, "internal_data_error");
|
|
93776
|
+
const perpDexConfig = input.config?.client_runtime_hyperliquid_perp_dexs;
|
|
93777
|
+
const enabledDexes = perpDexConfig?.enabled && Array.isArray(perpDexConfig.allowed_dexes) ? perpDexConfig.allowed_dexes.map((value) => String(value ?? "").trim().toLowerCase()) : [];
|
|
93778
|
+
if (dex && !enabledDexes.includes(dex)) throw notListed();
|
|
93779
|
+
let indexes = /* @__PURE__ */ new Map([["", 0]]);
|
|
93780
|
+
if (dex) {
|
|
93781
|
+
indexes = perpDexIndexes(await postHyperliquidInfo(input, { type: "perpDexs" }, "hyperliquid.perpDexs"));
|
|
93782
|
+
if (!indexes.has(dex)) throw notListed();
|
|
93783
|
+
}
|
|
93784
|
+
const meta3 = await postHyperliquidInfo(input, dex ? { type: "meta", dex } : { type: "meta" }, `hyperliquid.meta${dex ? `.${dex}` : ""}`);
|
|
93785
|
+
const row = listedMarketRows(
|
|
93786
|
+
[market],
|
|
93787
|
+
{ [dex]: meta3 },
|
|
93788
|
+
indexes,
|
|
93789
|
+
input.config?.client_runtime_hyperliquid_case_sensitive_symbols,
|
|
93790
|
+
{ includeDelisted: true }
|
|
93791
|
+
)[market];
|
|
93792
|
+
if (!row) throw notListed();
|
|
93793
|
+
return row;
|
|
93794
|
+
};
|
|
93795
|
+
requireBotProfileId = (input, symbol2) => {
|
|
93796
|
+
const profileId = Number(input.profileId);
|
|
93797
|
+
if (!Number.isSafeInteger(profileId) || profileId <= 0) {
|
|
93798
|
+
throw new RuntimeReasonError(`The bot's profile is needed to read ${symbol2}'s execution metadata.`, "internal_data_error");
|
|
93799
|
+
}
|
|
93800
|
+
return profileId;
|
|
93801
|
+
};
|
|
93802
|
+
executionAssetMetadataFor = async (input, symbol2, options = {}) => {
|
|
93803
|
+
const requestOptions = {
|
|
93804
|
+
profileId: requireBotProfileId(input, symbol2),
|
|
93805
|
+
...options.forceCatalogRefresh ? { forceCatalogRefresh: true } : {},
|
|
93806
|
+
...input.publicRequestPriority === "trading_reduce" ? { publicRequestPriority: "trading_reduce" } : {}
|
|
93807
|
+
};
|
|
93808
|
+
try {
|
|
93809
|
+
return await getExecutionAssetMetadata("hyperliquid", symbol2, requestOptions);
|
|
93810
|
+
} catch (error48) {
|
|
93811
|
+
if (!executionMetadataNeedsDeviceRead(error48)) throw error48;
|
|
93812
|
+
options.onDeviceRead?.();
|
|
93813
|
+
return readDeviceExecutionAssetMetadata(input, symbol2);
|
|
93814
|
+
}
|
|
93815
|
+
};
|
|
93676
93816
|
resolveHyperliquidAsset = async (input) => {
|
|
93677
|
-
const symbol2 =
|
|
93817
|
+
const symbol2 = normalizeBotMarket(input.config, input.symbol);
|
|
93678
93818
|
if (!symbol2) {
|
|
93679
93819
|
throw new Error("Missing Hyperliquid symbol.");
|
|
93680
93820
|
}
|
|
93681
93821
|
if (input.refreshCatalog) {
|
|
93682
|
-
return normalizeExecutionAssetMetadata(symbol2, await
|
|
93683
|
-
forceCatalogRefresh: true,
|
|
93684
|
-
...input.publicRequestPriority === "trading_reduce" ? { publicRequestPriority: "trading_reduce" } : {}
|
|
93685
|
-
}));
|
|
93822
|
+
return normalizeExecutionAssetMetadata(symbol2, await executionAssetMetadataFor(input, symbol2, { forceCatalogRefresh: true }));
|
|
93686
93823
|
}
|
|
93687
93824
|
if (Array.isArray(input.assets) && input.assets.length > 0) {
|
|
93688
93825
|
const explicitAsset = findResolvedAsset(symbol2, input.assets);
|
|
@@ -93690,10 +93827,16 @@ var init_hyperliquid_client = __esm({
|
|
|
93690
93827
|
return explicitAsset;
|
|
93691
93828
|
}
|
|
93692
93829
|
}
|
|
93830
|
+
requireBotProfileId(input, symbol2);
|
|
93831
|
+
let readOnDevice = false;
|
|
93693
93832
|
try {
|
|
93694
|
-
|
|
93695
|
-
|
|
93833
|
+
return normalizeExecutionAssetMetadata(symbol2, await executionAssetMetadataFor(input, symbol2, {
|
|
93834
|
+
onDeviceRead: () => {
|
|
93835
|
+
readOnDevice = true;
|
|
93836
|
+
}
|
|
93837
|
+
}));
|
|
93696
93838
|
} catch (executionMetadataError) {
|
|
93839
|
+
if (readOnDevice) throw executionMetadataError;
|
|
93697
93840
|
const assets = await resolveAssets(input);
|
|
93698
93841
|
const fallbackAsset = findResolvedAsset(symbol2, assets);
|
|
93699
93842
|
if (fallbackAsset) {
|
|
@@ -93807,7 +93950,7 @@ var init_hyperliquid_client = __esm({
|
|
|
93807
93950
|
return { executionPositionSize, executionMarkPrice, executionContextAtMs };
|
|
93808
93951
|
};
|
|
93809
93952
|
quantizeHyperliquidOrderSize = async (input) => {
|
|
93810
|
-
const symbol2 =
|
|
93953
|
+
const symbol2 = normalizeBotMarket(input.config, input.symbol);
|
|
93811
93954
|
if (!symbol2) {
|
|
93812
93955
|
throw new Error("Missing Hyperliquid symbol.");
|
|
93813
93956
|
}
|
|
@@ -93818,7 +93961,7 @@ var init_hyperliquid_client = __esm({
|
|
|
93818
93961
|
symbol: symbol2
|
|
93819
93962
|
}) : null;
|
|
93820
93963
|
devicePrivateContext?.catch(() => void 0);
|
|
93821
|
-
const metadata =
|
|
93964
|
+
const metadata = await executionAssetMetadataFor(input, symbol2);
|
|
93822
93965
|
const deviceContext = devicePrivateContext ? await devicePrivateContext : null;
|
|
93823
93966
|
const executionContextReceivedAtMonotonicMs = globalThis.performance.now();
|
|
93824
93967
|
const resolved = normalizeExecutionAssetMetadata(symbol2, metadata);
|
|
@@ -93875,9 +94018,9 @@ var init_hyperliquid_client = __esm({
|
|
|
93875
94018
|
const allowedDexes = Array.isArray(perpDexConfig.allowed_dexes) ? perpDexConfig.allowed_dexes.map((dex) => String(dex || "").trim().toLowerCase()).filter(Boolean) : [];
|
|
93876
94019
|
if (allowedDexes.length > 0) {
|
|
93877
94020
|
const perpDexPayload = await postHyperliquidInfo(input, { type: "perpDexs" }, "hyperliquid.perpDexs");
|
|
93878
|
-
const
|
|
94021
|
+
const perpDexIndexes2 = getPerpDexIndexMap(perpDexPayload);
|
|
93879
94022
|
for (const dex of allowedDexes) {
|
|
93880
|
-
const perpDexIndex =
|
|
94023
|
+
const perpDexIndex = perpDexIndexes2.get(dex);
|
|
93881
94024
|
if (perpDexIndex === void 0) {
|
|
93882
94025
|
throw new Error(`Configured Hyperliquid perp DEX is not available: ${dex}`);
|
|
93883
94026
|
}
|
|
@@ -94517,7 +94660,7 @@ var init_hyperliquid_client = __esm({
|
|
|
94517
94660
|
input = { ...input, publicRequestPriority: input.reduceOnly === true ? "trading_reduce" : "trading_execute" };
|
|
94518
94661
|
assertPositiveNumber(input.size, "Hyperliquid order size");
|
|
94519
94662
|
assertPositiveNumber(input.limitPrice, "Hyperliquid limit price");
|
|
94520
|
-
const order = await buildHyperliquidOrderWire(input, input.tif ??
|
|
94663
|
+
const order = await buildHyperliquidOrderWire(input, input.tif ?? HYPERLIQUID_TIF_GTC, input.limitPrice, "limit");
|
|
94521
94664
|
return signHyperliquidPayload(input, {
|
|
94522
94665
|
type: "order",
|
|
94523
94666
|
orders: [order],
|
|
@@ -94586,7 +94729,7 @@ var init_hyperliquid_client = __esm({
|
|
|
94586
94729
|
isTakeProfit: member.triggerKind === "tp"
|
|
94587
94730
|
}) : await buildHyperliquidOrderWire(
|
|
94588
94731
|
memberInput,
|
|
94589
|
-
member.tif ??
|
|
94732
|
+
member.tif ?? HYPERLIQUID_TIF_GTC,
|
|
94590
94733
|
member.limitPrice,
|
|
94591
94734
|
member.priceKind ?? "limit"
|
|
94592
94735
|
)
|
|
@@ -94615,7 +94758,7 @@ var init_hyperliquid_client = __esm({
|
|
|
94615
94758
|
const order = input.orderKind === "trigger" ? await buildHyperliquidTriggerOrderWire({
|
|
94616
94759
|
...input,
|
|
94617
94760
|
triggerPrice: Number(input.triggerPrice)
|
|
94618
|
-
}) : await buildHyperliquidOrderWire(input, input.tif ??
|
|
94761
|
+
}) : await buildHyperliquidOrderWire(input, input.tif ?? HYPERLIQUID_TIF_GTC, input.limitPrice, "limit");
|
|
94619
94762
|
return signHyperliquidPayload(input, {
|
|
94620
94763
|
type: "modify",
|
|
94621
94764
|
oid: modifyTarget,
|
|
@@ -95316,8 +95459,9 @@ var init_hyperliquid_client = __esm({
|
|
|
95316
95459
|
clientOrderIds: durableMutation.clientOrderIds ?? null,
|
|
95317
95460
|
...durableMutation.protection ? { protection: durableMutation.protection } : {},
|
|
95318
95461
|
...durableMutation.protectiveActionId ? { protectiveActionId: durableMutation.protectiveActionId } : {},
|
|
95462
|
+
...durableMutation.safetyClose ? { safetyClose: durableMutation.safetyClose } : {},
|
|
95319
95463
|
// A trailing stop has no CLOID: the server binds the lot it signs.
|
|
95320
|
-
...durableMutation.protection || durableMutation.protectiveActionId || durableMutation.operationKind === "trailing_stop" ? { signedPayload: serializedPayload } : {},
|
|
95464
|
+
...durableMutation.protection || durableMutation.protectiveActionId || durableMutation.safetyClose || durableMutation.operationKind === "trailing_stop" ? { signedPayload: serializedPayload } : {},
|
|
95321
95465
|
attemptEvidence: diagnostics.first_order ? {
|
|
95322
95466
|
requestedExchangeSize: diagnostics.first_order.size,
|
|
95323
95467
|
submittedLimitPrice: diagnostics.first_order.price,
|
|
@@ -95661,7 +95805,7 @@ var exchange_mutation_evidence_exports = {};
|
|
|
95661
95805
|
__export(exchange_mutation_evidence_exports, {
|
|
95662
95806
|
readClientExchangeReconciliationEvidence: () => readClientExchangeReconciliationEvidence
|
|
95663
95807
|
});
|
|
95664
|
-
var resolveHyperliquidApiUrl, readClientExchangeReconciliationEvidence;
|
|
95808
|
+
var profileRuntimeConfig, resolveHyperliquidApiUrl, readClientExchangeReconciliationEvidence;
|
|
95665
95809
|
var init_exchange_mutation_evidence = __esm({
|
|
95666
95810
|
"lib/runtime/exchange-mutation-evidence.ts"() {
|
|
95667
95811
|
"use strict";
|
|
@@ -95672,15 +95816,18 @@ var init_exchange_mutation_evidence = __esm({
|
|
|
95672
95816
|
init_api2();
|
|
95673
95817
|
init_hyperliquid_client();
|
|
95674
95818
|
init_monotonic_clock();
|
|
95675
|
-
|
|
95676
|
-
const fromAnswer = String(answered ?? "").trim();
|
|
95677
|
-
if (fromAnswer) return fromAnswer;
|
|
95819
|
+
profileRuntimeConfig = async (profileId, signal) => {
|
|
95678
95820
|
const numericProfileId = Number(profileId);
|
|
95679
|
-
|
|
95821
|
+
return getLLMConfig(
|
|
95680
95822
|
void 0,
|
|
95681
95823
|
Number.isSafeInteger(numericProfileId) && numericProfileId > 0 ? numericProfileId : void 0,
|
|
95682
95824
|
signal
|
|
95683
95825
|
);
|
|
95826
|
+
};
|
|
95827
|
+
resolveHyperliquidApiUrl = async (profileId, answered, signal) => {
|
|
95828
|
+
const fromAnswer = String(answered ?? "").trim();
|
|
95829
|
+
if (fromAnswer) return fromAnswer;
|
|
95830
|
+
const config2 = await profileRuntimeConfig(profileId, signal);
|
|
95684
95831
|
const apiUrl = String(config2?.client_runtime_exchange_endpoints?.hyperliquid_api_url ?? "").trim();
|
|
95685
95832
|
if (!apiUrl) throw new Error("Missing client runtime Hyperliquid API URL.");
|
|
95686
95833
|
return apiUrl;
|
|
@@ -95715,6 +95862,12 @@ var init_exchange_mutation_evidence = __esm({
|
|
|
95715
95862
|
"hyperliquid.frontendOpenOrders"
|
|
95716
95863
|
);
|
|
95717
95864
|
const historicalOrders = input.required.historical_orders === true ? await fetchBrowserHyperliquidInfoPayload(readInput, { type: "historicalOrders", user: wallet }, "hyperliquid.historicalOrders") : void 0;
|
|
95865
|
+
const assetSymbol = String(input.required.execution_asset_symbol ?? "").trim();
|
|
95866
|
+
const executionAsset = assetSymbol ? await readDeviceExecutionAssetMetadata({
|
|
95867
|
+
...readInput,
|
|
95868
|
+
// Which HIP-3 DEXes VTX enables: the caller's runtime config, else the profile's.
|
|
95869
|
+
config: input.config ?? await profileRuntimeConfig(input.profileId, input.signal)
|
|
95870
|
+
}, assetSymbol) : void 0;
|
|
95718
95871
|
return {
|
|
95719
95872
|
evidence: {
|
|
95720
95873
|
wallet_address: wallet,
|
|
@@ -95722,7 +95875,8 @@ var init_exchange_mutation_evidence = __esm({
|
|
|
95722
95875
|
order_statuses: orderStatuses,
|
|
95723
95876
|
active_asset_data: activeAssetData,
|
|
95724
95877
|
...openOrders === void 0 ? {} : { open_orders: openOrders },
|
|
95725
|
-
...historicalOrders === void 0 ? {} : { historical_orders: historicalOrders }
|
|
95878
|
+
...historicalOrders === void 0 ? {} : { historical_orders: historicalOrders },
|
|
95879
|
+
...executionAsset === void 0 ? {} : { execution_asset: executionAsset }
|
|
95726
95880
|
},
|
|
95727
95881
|
startedAtMonotonicMs
|
|
95728
95882
|
};
|
|
@@ -96048,6 +96202,21 @@ async function getAiTradingStatus(cookie, profileId, options) {
|
|
|
96048
96202
|
return recordStatusExchanges(await response.json());
|
|
96049
96203
|
}, { cookie });
|
|
96050
96204
|
}
|
|
96205
|
+
async function syncTradeHistoryFills(profileId, walletAddress, fills) {
|
|
96206
|
+
const response = await apiFetch(`${getApiUrl()}/trading/history/sync`, {
|
|
96207
|
+
method: "POST",
|
|
96208
|
+
headers: getProfileHeaders({
|
|
96209
|
+
"Content-Type": "application/json"
|
|
96210
|
+
}, profileId),
|
|
96211
|
+
credentials: "include",
|
|
96212
|
+
body: JSON.stringify({ wallet_address: walletAddress, fills })
|
|
96213
|
+
});
|
|
96214
|
+
if (!response.ok) {
|
|
96215
|
+
const message = await getErrorMessageFromResponse(response, "Failed to sync trade history fills", { fallbackDetail: true });
|
|
96216
|
+
throw new Error(message);
|
|
96217
|
+
}
|
|
96218
|
+
return response.json();
|
|
96219
|
+
}
|
|
96051
96220
|
async function postClientRuntime(path, profileId, body, options) {
|
|
96052
96221
|
const requestUrl2 = `${getApiUrl()}/trading/ai${path}`;
|
|
96053
96222
|
const numericProfileId = toNumericProfileId(profileId);
|
|
@@ -96353,6 +96522,13 @@ async function handOffClientRuntimeSession(profileId, payload, options) {
|
|
|
96353
96522
|
}
|
|
96354
96523
|
);
|
|
96355
96524
|
}
|
|
96525
|
+
function hostHasBrowserExchangeSession() {
|
|
96526
|
+
try {
|
|
96527
|
+
return typeof window !== "undefined" && typeof window.localStorage !== "undefined" && typeof window.sessionStorage !== "undefined";
|
|
96528
|
+
} catch {
|
|
96529
|
+
return false;
|
|
96530
|
+
}
|
|
96531
|
+
}
|
|
96356
96532
|
async function beginClientRuntimeExchangeMutation(profileId, payload, requiredRuntimeSessionId, explicitRuntimeLeaseToken, explicitRuntimeDeviceId, explicitSchedulerInstanceId) {
|
|
96357
96533
|
const authority = payload.pinnedAuthority ?? resolveClientExchangeMutationAuthority(
|
|
96358
96534
|
profileId,
|
|
@@ -96384,6 +96560,7 @@ async function beginClientRuntimeExchangeMutation(profileId, payload, requiredRu
|
|
|
96384
96560
|
...payload.protection ? { protection: payload.protection } : {},
|
|
96385
96561
|
...payload.protectiveActionId ? { protective_action_id: payload.protectiveActionId } : {},
|
|
96386
96562
|
...payload.signedPayload ? { signed_payload: payload.signedPayload } : {},
|
|
96563
|
+
...payload.safetyClose ? { safety_close: payload.safetyClose } : {},
|
|
96387
96564
|
attempt_evidence: payload.attemptEvidence ? {
|
|
96388
96565
|
requested_exchange_size: payload.attemptEvidence.requestedExchangeSize ?? null,
|
|
96389
96566
|
submitted_limit_price: payload.attemptEvidence.submittedLimitPrice ?? null,
|
|
@@ -96503,50 +96680,14 @@ async function refuseClientProtectiveAction(profileId, actionId, reasonCode, req
|
|
|
96503
96680
|
authority.requestOptions
|
|
96504
96681
|
);
|
|
96505
96682
|
}
|
|
96506
|
-
async function reportClientProtectiveEvidence(profileId, report,
|
|
96507
|
-
|
|
96508
|
-
profileId,
|
|
96509
|
-
requiredRuntimeSessionId,
|
|
96510
|
-
explicitRuntimeLeaseToken,
|
|
96511
|
-
explicitRuntimeDeviceId,
|
|
96512
|
-
explicitSchedulerInstanceId
|
|
96513
|
-
);
|
|
96514
|
-
return postClientRuntime(
|
|
96515
|
-
"/runtime/protective-evidence",
|
|
96516
|
-
authority.numericProfileId,
|
|
96517
|
-
JSON.stringify({ ...clientExchangeMutationAuthorityBody(authority), ...report }),
|
|
96518
|
-
authority.requestOptions
|
|
96519
|
-
);
|
|
96683
|
+
async function reportClientProtectiveEvidence(profileId, report, ...identity2) {
|
|
96684
|
+
return postClientDeviceReport("/runtime/protective-evidence", profileId, report, identity2);
|
|
96520
96685
|
}
|
|
96521
|
-
async function reportClientHistoryEvidence(profileId, report,
|
|
96522
|
-
|
|
96523
|
-
profileId,
|
|
96524
|
-
requiredRuntimeSessionId,
|
|
96525
|
-
explicitRuntimeLeaseToken,
|
|
96526
|
-
explicitRuntimeDeviceId,
|
|
96527
|
-
explicitSchedulerInstanceId
|
|
96528
|
-
);
|
|
96529
|
-
return postClientRuntime(
|
|
96530
|
-
"/runtime/history-evidence",
|
|
96531
|
-
authority.numericProfileId,
|
|
96532
|
-
JSON.stringify({ ...clientExchangeMutationAuthorityBody(authority), ...report }),
|
|
96533
|
-
authority.requestOptions
|
|
96534
|
-
);
|
|
96686
|
+
async function reportClientHistoryEvidence(profileId, report, ...identity2) {
|
|
96687
|
+
return postClientDeviceReport("/runtime/history-evidence", profileId, report, identity2);
|
|
96535
96688
|
}
|
|
96536
|
-
async function reportClientPortfolioEvidence(profileId, report,
|
|
96537
|
-
|
|
96538
|
-
profileId,
|
|
96539
|
-
requiredRuntimeSessionId,
|
|
96540
|
-
explicitRuntimeLeaseToken,
|
|
96541
|
-
explicitRuntimeDeviceId,
|
|
96542
|
-
explicitSchedulerInstanceId
|
|
96543
|
-
);
|
|
96544
|
-
return postClientRuntime(
|
|
96545
|
-
"/runtime/portfolio-evidence",
|
|
96546
|
-
authority.numericProfileId,
|
|
96547
|
-
JSON.stringify({ ...clientExchangeMutationAuthorityBody(authority), ...report }),
|
|
96548
|
-
authority.requestOptions
|
|
96549
|
-
);
|
|
96689
|
+
async function reportClientPortfolioEvidence(profileId, report, ...identity2) {
|
|
96690
|
+
return postClientDeviceReport("/runtime/portfolio-evidence", profileId, report, identity2);
|
|
96550
96691
|
}
|
|
96551
96692
|
async function adoptClientProtectiveLegs(profileId, payload, requiredRuntimeSessionId, explicitRuntimeLeaseToken, explicitRuntimeDeviceId, explicitSchedulerInstanceId) {
|
|
96552
96693
|
const authority = resolveClientExchangeMutationAuthority(
|
|
@@ -97245,7 +97386,7 @@ async function getClientRuntimeStatuses(profileIds, signal, options) {
|
|
|
97245
97386
|
ttlMs: viewer.requestKey ? 0 : CLIENT_RUNTIME_STATUSES_DEDUPE_TTL_MS
|
|
97246
97387
|
});
|
|
97247
97388
|
}
|
|
97248
|
-
var clientRuntimeSecretHeaders, preferencesWriteQueue, getCopyTradingRuntimeLeaseToken, getCopyTradingSchedulerInstanceId, AI_TRADE_HISTORY_BY_ORDER_IDS_MAX_BATCH, AI_TRADE_HISTORY_BY_ORDER_IDS_MAX_CONCURRENCY, resolveClientRuntimeStatusViewerHeaders, CLIENT_SUPPORTED_PROMPT_CONTRACT_VERSION,
|
|
97389
|
+
var clientRuntimeSecretHeaders, preferencesWriteQueue, getCopyTradingRuntimeLeaseToken, getCopyTradingSchedulerInstanceId, AI_TRADE_HISTORY_BY_ORDER_IDS_MAX_BATCH, AI_TRADE_HISTORY_BY_ORDER_IDS_MAX_CONCURRENCY, resolveClientRuntimeStatusViewerHeaders, CLIENT_SUPPORTED_PROMPT_CONTRACT_VERSION, completedDeferredClientRuntimeStops, rememberCompletedDeferredClientRuntimeStop, consumeCompletedDeferredClientRuntimeStop, toNumericProfileId, buildClientRuntimeBody, shouldAttachRuntimeIdempotencyKey, attachRuntimeLeaseHeader, attachRuntimeSchedulerInstanceHeader, resolveRuntimeLeaseToken, resolveSchedulerBoundRuntimeLeaseToken, persistRuntimeLeaseFromPayload, persistRuntimeLeaseStatusMetadata, shouldClearPersistedRuntimeLeaseOnError, createRuntimeRequestError, parseClientRuntimeRequestContext, recordRuntimeAuthFailureBreadcrumb, classifyRuntimeRequestError, annotateRuntimeRequestError, CLIENT_RUNTIME_RETRYABLE_STATUSES, isRetryableClientRuntimeStatus, shouldRetryClientRuntimeHttpStatus, isRuntimeIdempotencyInProgressError, isRetryableRuntimeConflictError, resolveClientRuntimeRetryDelayMs, reconcilePendingClientExchangeMutation, CLIENT_RUNTIME_CLAIM_EXCHANGE_MUTATION_WAIT_CODES, CLIENT_EXCHANGE_AUTHORITY_DEVICE_KEY, CLIENT_EXCHANGE_AUTHORITY_SESSION_KEY, getOrCreateClientExchangeAuthorityIdentity, resolveClientExchangeMutationAuthority, pinClientExchangeMutationAuthority, CLIENT_EXCHANGE_MUTATION_AUTHORITY_MISMATCH, isClientExchangeMutationAuthorityConflict, handOffClientExchangeMutationToReconciliation, clientExchangeMutationAuthorityBody, isPendingClientExchangeMutationError, isMissingActiveClientExchangeMutationError, clientExchangeMutationReconciliationTimers, ClientExchangeMutationRebuildRequiredError, isTerminalClientExchangeMutation, clientExchangeMutationReconciliationKey, clearScheduledClientExchangeMutationReconciliation, snapshotClientExchangeMutationReconciliationAuthority, completeClientExchangeMutationReconciliation, protectiveBoundClientExchangeMutations, rememberProtectiveBoundClientExchangeMutation, isProtectiveBoundClientExchangeMutation, postClientExchangeMutationReconciliation, scheduleClientExchangeMutationReconciliation, postClientDeviceReport, reportClientTradeMarketRead;
|
|
97249
97390
|
var init_api2 = __esm({
|
|
97250
97391
|
"lib/api.ts"() {
|
|
97251
97392
|
"use strict";
|
|
@@ -97290,6 +97431,7 @@ var init_api2 = __esm({
|
|
|
97290
97431
|
init_account_summary();
|
|
97291
97432
|
init_mobile_notifications();
|
|
97292
97433
|
init_admin_signups();
|
|
97434
|
+
init_client_exchange_reconciliation();
|
|
97293
97435
|
init_server_runtime_lease();
|
|
97294
97436
|
clientRuntimeSecretHeaders = (profileId) => {
|
|
97295
97437
|
const headers = getProfileHeaders({}, profileId);
|
|
@@ -97332,7 +97474,6 @@ var init_api2 = __esm({
|
|
|
97332
97474
|
CLIENT_SUPPORTED_PROMPT_CONTRACT_VERSION = String(
|
|
97333
97475
|
process.env.NEXT_PUBLIC_CLIENT_RUNTIME_PROMPT_CONTRACT_VERSION || "2026-08-24.1"
|
|
97334
97476
|
).trim() || "2026-08-24.1";
|
|
97335
|
-
CLIENT_PROTECTION_CAPABILITY_VERSION = 1;
|
|
97336
97477
|
completedDeferredClientRuntimeStops = /* @__PURE__ */ new Set();
|
|
97337
97478
|
rememberCompletedDeferredClientRuntimeStop = (profileId, result) => {
|
|
97338
97479
|
if (result.runtime_stop_completed === true) {
|
|
@@ -97726,7 +97867,7 @@ var init_api2 = __esm({
|
|
|
97726
97867
|
"The active persisted trader lease does not match this runtime execution session."
|
|
97727
97868
|
);
|
|
97728
97869
|
}
|
|
97729
|
-
if (
|
|
97870
|
+
if (!hostHasBrowserExchangeSession()) {
|
|
97730
97871
|
throw new Error(
|
|
97731
97872
|
"Authenticated browser storage is required for manual exchange submission."
|
|
97732
97873
|
);
|
|
@@ -97910,6 +98051,16 @@ var init_api2 = __esm({
|
|
|
97910
98051
|
requestOptions: authority
|
|
97911
98052
|
});
|
|
97912
98053
|
};
|
|
98054
|
+
postClientDeviceReport = (path, profileId, report, identity2) => {
|
|
98055
|
+
const authority = resolveClientExchangeMutationAuthority(profileId, ...identity2);
|
|
98056
|
+
return postClientRuntime(
|
|
98057
|
+
path,
|
|
98058
|
+
authority.numericProfileId,
|
|
98059
|
+
JSON.stringify({ ...clientExchangeMutationAuthorityBody(authority), ...report }),
|
|
98060
|
+
authority.requestOptions
|
|
98061
|
+
);
|
|
98062
|
+
};
|
|
98063
|
+
reportClientTradeMarketRead = (profileId, mutationId, read, ...identity2) => postClientDeviceReport(`/runtime/exchange-mutations/${encodeURIComponent(mutationId)}/position-read`, profileId, read, identity2);
|
|
97913
98064
|
}
|
|
97914
98065
|
});
|
|
97915
98066
|
|
|
@@ -99223,6 +99374,7 @@ var init_browser_trading = __esm({
|
|
|
99223
99374
|
const payload = await buildHyperliquidUpdateLeveragePayload({
|
|
99224
99375
|
config: input.config ?? null,
|
|
99225
99376
|
publicRequestPriority: priorityOf(input),
|
|
99377
|
+
profileId: input.profileId,
|
|
99226
99378
|
signingKey,
|
|
99227
99379
|
symbol: input.symbol,
|
|
99228
99380
|
leverage: input.leverage,
|
|
@@ -99262,6 +99414,7 @@ var init_browser_trading = __esm({
|
|
|
99262
99414
|
const payload = await buildHyperliquidMarketOrderPayload({
|
|
99263
99415
|
config: input.config ?? null,
|
|
99264
99416
|
publicRequestPriority: priorityOf(input),
|
|
99417
|
+
profileId: input.profileId,
|
|
99265
99418
|
signingKey,
|
|
99266
99419
|
symbol: input.symbol,
|
|
99267
99420
|
side: input.side,
|
|
@@ -99294,7 +99447,8 @@ var init_browser_trading = __esm({
|
|
|
99294
99447
|
...childClientOrderIds.length ? { clientOrderIds: [String(mutation.clientOrderId), ...childClientOrderIds] } : {},
|
|
99295
99448
|
onExchangeOrderDispatched: input.onExchangeOrderDispatched,
|
|
99296
99449
|
...input.protection ? { protection: input.protection } : {},
|
|
99297
|
-
...input.onSettled ? { onSettled: input.onSettled } : {}
|
|
99450
|
+
...input.onSettled ? { onSettled: input.onSettled } : {},
|
|
99451
|
+
...input.safetyClose ? { safetyClose: input.safetyClose } : {}
|
|
99298
99452
|
},
|
|
99299
99453
|
...childClientOrderIds.length ? { triggerAcknowledgementWalletAddress: input.walletAddress ?? null } : {}
|
|
99300
99454
|
});
|
|
@@ -99343,6 +99497,7 @@ var init_browser_trading = __esm({
|
|
|
99343
99497
|
const payload = await buildHyperliquidLimitOrderPayload({
|
|
99344
99498
|
config: input.config ?? null,
|
|
99345
99499
|
publicRequestPriority: priorityOf(input),
|
|
99500
|
+
profileId: input.profileId,
|
|
99346
99501
|
signingKey,
|
|
99347
99502
|
symbol: input.symbol,
|
|
99348
99503
|
side: input.side,
|
|
@@ -99381,6 +99536,7 @@ var init_browser_trading = __esm({
|
|
|
99381
99536
|
const payload = await buildHyperliquidTriggerOrderPayload({
|
|
99382
99537
|
config: input.config ?? null,
|
|
99383
99538
|
publicRequestPriority: priorityOf(input),
|
|
99539
|
+
profileId: input.profileId,
|
|
99384
99540
|
signingKey,
|
|
99385
99541
|
symbol: input.symbol,
|
|
99386
99542
|
side: input.side,
|
|
@@ -99421,6 +99577,7 @@ var init_browser_trading = __esm({
|
|
|
99421
99577
|
const payload = await buildHyperliquidOrderBatchPayload({
|
|
99422
99578
|
config: input.config ?? null,
|
|
99423
99579
|
publicRequestPriority: priorityOf(input),
|
|
99580
|
+
profileId: input.profileId,
|
|
99424
99581
|
signingKey,
|
|
99425
99582
|
symbol: input.symbol,
|
|
99426
99583
|
members: input.members,
|
|
@@ -99457,6 +99614,7 @@ var init_browser_trading = __esm({
|
|
|
99457
99614
|
const payload = await buildHyperliquidModifyOrderPayload({
|
|
99458
99615
|
config: input.config ?? null,
|
|
99459
99616
|
publicRequestPriority: priorityOf(input),
|
|
99617
|
+
profileId: input.profileId,
|
|
99460
99618
|
signingKey,
|
|
99461
99619
|
symbol: input.symbol,
|
|
99462
99620
|
orderId: input.orderId,
|
|
@@ -99504,6 +99662,7 @@ var init_browser_trading = __esm({
|
|
|
99504
99662
|
const payload = await buildHyperliquidCancelPayload({
|
|
99505
99663
|
config: input.config ?? null,
|
|
99506
99664
|
publicRequestPriority: priorityOf(input),
|
|
99665
|
+
profileId: input.profileId,
|
|
99507
99666
|
signingKey,
|
|
99508
99667
|
symbol: input.symbol,
|
|
99509
99668
|
orderId: input.orderId,
|
|
@@ -99537,6 +99696,7 @@ var init_browser_trading = __esm({
|
|
|
99537
99696
|
const payload = await buildHyperliquidTrailingStopPayload({
|
|
99538
99697
|
config: input.config ?? null,
|
|
99539
99698
|
publicRequestPriority: priorityOf(input),
|
|
99699
|
+
profileId: input.profileId,
|
|
99540
99700
|
signingKey,
|
|
99541
99701
|
symbol: input.symbol,
|
|
99542
99702
|
side: input.side,
|
|
@@ -99602,7 +99762,8 @@ var init_browser_trading = __esm({
|
|
|
99602
99762
|
slippage: input.slippage,
|
|
99603
99763
|
reduceOnly: true,
|
|
99604
99764
|
assets: input.assets,
|
|
99605
|
-
onExchangeOrderDispatched: input.onExchangeOrderDispatched
|
|
99765
|
+
onExchangeOrderDispatched: input.onExchangeOrderDispatched,
|
|
99766
|
+
...input.safetyClose ? { safetyClose: { reason: input.safetyClose, position_size: String(positionSize) } } : {}
|
|
99606
99767
|
});
|
|
99607
99768
|
};
|
|
99608
99769
|
}
|
|
@@ -101147,6 +101308,9 @@ var init_protective_evidence = __esm({
|
|
|
101147
101308
|
includeMark: request.include_mark === true || existing?.kind === "market" && existing.includeMark,
|
|
101148
101309
|
shareable: request.reason === "leg_active" && (existing?.kind !== "market" || existing.shareable)
|
|
101149
101310
|
});
|
|
101311
|
+
} else if (request.kind === "execution_asset") {
|
|
101312
|
+
const symbol2 = String(request.symbol ?? "").trim();
|
|
101313
|
+
if (symbol2) items.set(`execution_asset:${symbol2}`, { kind: "execution_asset", symbol: symbol2 });
|
|
101150
101314
|
}
|
|
101151
101315
|
}
|
|
101152
101316
|
return [...items.values()];
|
|
@@ -101168,7 +101332,7 @@ var init_protective_evidence = __esm({
|
|
|
101168
101332
|
const observedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
101169
101333
|
const perDex = /* @__PURE__ */ new Map();
|
|
101170
101334
|
const scope = `${String(input.apiUrl ?? "")}|${wallet.toLowerCase()}`;
|
|
101171
|
-
const shareable = batch.every((item) => item.kind !== "fills" && item.shareable);
|
|
101335
|
+
const shareable = batch.every((item) => item.kind === "execution_asset" || item.kind !== "fills" && item.shareable);
|
|
101172
101336
|
const dexRead = (key, body, label2) => {
|
|
101173
101337
|
let read = perDex.get(key);
|
|
101174
101338
|
if (read) return read;
|
|
@@ -101193,7 +101357,13 @@ var init_protective_evidence = __esm({
|
|
|
101193
101357
|
const orderStatuses = [];
|
|
101194
101358
|
const fills = [];
|
|
101195
101359
|
const markets = [];
|
|
101360
|
+
const assets = [];
|
|
101196
101361
|
await Promise.all(batch.map(async (item) => {
|
|
101362
|
+
if (item.kind === "execution_asset") {
|
|
101363
|
+
const row = await readOrNull(() => readDeviceExecutionAssetMetadata(input, item.symbol));
|
|
101364
|
+
if (row != null) assets.push({ symbol: item.symbol, row });
|
|
101365
|
+
return;
|
|
101366
|
+
}
|
|
101197
101367
|
if (item.kind === "order_status") {
|
|
101198
101368
|
const oid = orderStatusOid(item.orderRef);
|
|
101199
101369
|
const response = await readOrNull(() => fetchBrowserHyperliquidInfoPayload(
|
|
@@ -101233,7 +101403,8 @@ var init_protective_evidence = __esm({
|
|
|
101233
101403
|
if (orderStatuses.length > 0) report.order_statuses = orderStatuses;
|
|
101234
101404
|
if (fills.length > 0) report.fills = fills;
|
|
101235
101405
|
if (markets.length > 0) report.markets = markets;
|
|
101236
|
-
|
|
101406
|
+
if (assets.length > 0) report.assets = assets;
|
|
101407
|
+
const items = orderStatuses.length + fills.length + markets.length + assets.length;
|
|
101237
101408
|
return items > 0 ? { report, items, startedAtMonotonicMs } : null;
|
|
101238
101409
|
};
|
|
101239
101410
|
withEvidenceReporterLock = async (profileId, work, busy) => {
|
|
@@ -101843,7 +102014,7 @@ var init_client_exchange_mutations = __esm({
|
|
|
101843
102014
|
});
|
|
101844
102015
|
|
|
101845
102016
|
// lib/runtime/execution-guard-contract.ts
|
|
101846
|
-
var unitsFromPosition, signedUnitsFromPosition, signedUnitsFromEntryPosition, classifyExecutionIntent, reductionFirstOrder,
|
|
102017
|
+
var unitsFromPosition, signedUnitsFromPosition, signedUnitsFromEntryPosition, classifyExecutionIntent, reductionFirstOrder, orderMetadataRetryReason, copyClosingSize, copyOrderClosingSize, copyOrderNotionalCap, resolveExecutionTarget, decisionOrderSizeAsset, flipExecutionLegs, executedOrderPositionEvent;
|
|
101847
102018
|
var init_execution_guard_contract = __esm({
|
|
101848
102019
|
"lib/runtime/execution-guard-contract.ts"() {
|
|
101849
102020
|
"use strict";
|
|
@@ -102044,32 +102215,12 @@ var init_execution_guard_contract = __esm({
|
|
|
102044
102215
|
const reduces = plans.map((plan) => classifyExecutionIntent(plan.decision, plan.units, plan.signedUnits).reduceOnly);
|
|
102045
102216
|
return plans.map((_, index) => index).sort((left, right) => Number(reduces[right]) - Number(reduces[left]));
|
|
102046
102217
|
};
|
|
102047
|
-
usdAmount = (value) => `$${value.toLocaleString("en-US", {
|
|
102048
|
-
minimumFractionDigits: USD_DISPLAY_DECIMALS,
|
|
102049
|
-
maximumFractionDigits: USD_DISPLAY_DECIMALS
|
|
102050
|
-
})}`;
|
|
102051
102218
|
orderMetadataRetryReason = (rejection) => {
|
|
102052
102219
|
const message = String(rejection ?? "").toLowerCase();
|
|
102053
102220
|
if (message.includes("invalid size")) return "invalid_size";
|
|
102054
102221
|
if (message.includes("reference price") && message.includes("95% away")) return "reference_price";
|
|
102055
102222
|
return null;
|
|
102056
102223
|
};
|
|
102057
|
-
orderCeilingRefusal = (input) => {
|
|
102058
|
-
const closingSide2 = input.side === "sell" && input.currentPositionSize > 0 || input.side === "buy" && input.currentPositionSize < 0;
|
|
102059
|
-
if (input.reduceOnly && closingSide2 && input.size <= Math.abs(input.currentPositionSize)) {
|
|
102060
|
-
return null;
|
|
102061
|
-
}
|
|
102062
|
-
const orderNotional = input.size * input.price;
|
|
102063
|
-
if (orderNotional > input.maxOrderNotional) {
|
|
102064
|
-
return `Order notional ${usdAmount(orderNotional)} exceeds limit ${usdAmount(input.maxOrderNotional)}`;
|
|
102065
|
-
}
|
|
102066
|
-
const resultingSize = input.side === "buy" ? input.currentPositionSize + input.size : input.currentPositionSize - input.size;
|
|
102067
|
-
const resultingNotional = Math.abs(resultingSize) * input.price;
|
|
102068
|
-
if (resultingNotional > input.maxPositionNotional) {
|
|
102069
|
-
return `Resulting position notional ${usdAmount(resultingNotional)} exceeds limit ${usdAmount(input.maxPositionNotional)}`;
|
|
102070
|
-
}
|
|
102071
|
-
return null;
|
|
102072
|
-
};
|
|
102073
102224
|
copyClosingSize = (destinationPosition, destinationDelta) => destinationPosition * destinationDelta >= 0 ? 0 : Math.min(Math.abs(destinationDelta), Math.abs(destinationPosition));
|
|
102074
102225
|
copyOrderClosingSize = (input) => {
|
|
102075
102226
|
const size = Number.isFinite(input.size) && input.size > 0 ? input.size : 0;
|
|
@@ -102741,9 +102892,9 @@ var init_native_position_protection = __esm({
|
|
|
102741
102892
|
roundDecimalHalfUp = (value, decimals) => {
|
|
102742
102893
|
const text = String(value);
|
|
102743
102894
|
if (text.includes("e")) return "0";
|
|
102744
|
-
const [
|
|
102745
|
-
if (fraction.length <= decimals) return fraction ? `${
|
|
102746
|
-
let units = BigInt(`${
|
|
102895
|
+
const [integer4, fraction = ""] = text.split(".");
|
|
102896
|
+
if (fraction.length <= decimals) return fraction ? `${integer4}.${fraction}`.replace(/\.?0+$/, "") : integer4;
|
|
102897
|
+
let units = BigInt(`${integer4}${fraction.slice(0, decimals)}`);
|
|
102747
102898
|
if (fraction[decimals] >= HALF_UP_DIGIT) units += BigInt(1);
|
|
102748
102899
|
const digits = units.toString().padStart(decimals + 1, "0");
|
|
102749
102900
|
const rounded = `${digits.slice(0, -decimals)}.${digits.slice(-decimals)}`;
|
|
@@ -104488,7 +104639,7 @@ var init_runtime_execution = __esm({
|
|
|
104488
104639
|
let target;
|
|
104489
104640
|
try {
|
|
104490
104641
|
target = resolveLeverageTarget(
|
|
104491
|
-
await resolveHyperliquidAsset({ symbol: symbol2, config: input.config ?? null, publicRequestPriority: "trading_reconcile" }),
|
|
104642
|
+
await resolveHyperliquidAsset({ symbol: symbol2, config: input.config ?? null, publicRequestPriority: "trading_reconcile", profileId: input.profileId }),
|
|
104492
104643
|
context.leverage,
|
|
104493
104644
|
context.marginMode !== "isolated"
|
|
104494
104645
|
);
|
|
@@ -105968,7 +106119,8 @@ var init_runtime_execution = __esm({
|
|
|
105968
106119
|
const { sz_decimals: assetSizeDecimals } = await resolveHyperliquidAsset({
|
|
105969
106120
|
symbol: symbol2,
|
|
105970
106121
|
config: request.config,
|
|
105971
|
-
publicRequestPriority: "trading_reduce"
|
|
106122
|
+
publicRequestPriority: "trading_reduce",
|
|
106123
|
+
profileId
|
|
105972
106124
|
});
|
|
105973
106125
|
const candidates = allocatedCandidates.map((candidate) => ({
|
|
105974
106126
|
...candidate,
|
|
@@ -109490,7 +109642,8 @@ var init_runtime_execution = __esm({
|
|
|
109490
109642
|
const { sz_decimals: assetSizeDecimals } = await resolveHyperliquidAsset({
|
|
109491
109643
|
symbol: symbol2,
|
|
109492
109644
|
config: request.config,
|
|
109493
|
-
publicRequestPriority: "trading_reduce"
|
|
109645
|
+
publicRequestPriority: "trading_reduce",
|
|
109646
|
+
profileId
|
|
109494
109647
|
});
|
|
109495
109648
|
const reports = [];
|
|
109496
109649
|
const updated = [...retained];
|
|
@@ -109793,11 +109946,12 @@ var init_runtime_execution = __esm({
|
|
|
109793
109946
|
});
|
|
109794
109947
|
};
|
|
109795
109948
|
isDefinitiveEntryRejection = (error48, entryMutationId) => error48 instanceof HyperliquidExchangeRejectionError && Boolean(entryMutationId) && String(error48.clientMutationId ?? "").trim().toLowerCase() === String(entryMutationId).trim().toLowerCase();
|
|
109796
|
-
resolveExchangeSizeDecimals = async (symbol2, config2, publicRequestPriority) => {
|
|
109949
|
+
resolveExchangeSizeDecimals = async (symbol2, config2, publicRequestPriority, profileId) => {
|
|
109797
109950
|
const { sz_decimals: sizeDecimals } = await resolveHyperliquidAsset({
|
|
109798
109951
|
symbol: symbol2,
|
|
109799
109952
|
config: config2,
|
|
109800
|
-
publicRequestPriority
|
|
109953
|
+
publicRequestPriority,
|
|
109954
|
+
profileId
|
|
109801
109955
|
});
|
|
109802
109956
|
if (!Number.isInteger(sizeDecimals) || sizeDecimals < 0) {
|
|
109803
109957
|
throw new Error(`Hyperliquid size precision is unavailable for ${symbol2}.`);
|
|
@@ -109837,6 +109991,7 @@ var init_runtime_execution = __esm({
|
|
|
109837
109991
|
const asset = await resolveHyperliquidAsset({
|
|
109838
109992
|
symbol: input.executionContext.symbol,
|
|
109839
109993
|
config: input.config ?? void 0,
|
|
109994
|
+
profileId: input.profileId,
|
|
109840
109995
|
publicRequestPriority: executionReadPriority(input),
|
|
109841
109996
|
refreshCatalog: true
|
|
109842
109997
|
});
|
|
@@ -110403,7 +110558,7 @@ var init_runtime_execution = __esm({
|
|
|
110403
110558
|
const groups2 = readFreshClientProtectiveGroups(String(request.profileId).trim(), context.symbol);
|
|
110404
110559
|
if (hasClientProtectiveGroupReadFailure(String(request.profileId).trim(), context.symbol) || groups2.some((group) => group.walletAddress !== String(context.walletAddress ?? "").trim().toLowerCase() || group.pendingEntry || group.attachmentJournal || group.cleanupRequired || group.legs.some((leg) => leg.replacement))) return [];
|
|
110405
110560
|
if (!groups2.some((group) => group.legs.some((leg) => leg.isTrailing && typeof leg.orderId === "number"))) return [];
|
|
110406
|
-
const assetSizeDecimals = await resolveExchangeSizeDecimals(context.symbol, request.config ?? void 0, "trading_reduce");
|
|
110561
|
+
const assetSizeDecimals = await resolveExchangeSizeDecimals(context.symbol, request.config ?? void 0, "trading_reduce", request.profileId);
|
|
110407
110562
|
const isLong = context.currentPositionSize > 0;
|
|
110408
110563
|
const improves = groups2.some((group) => group.isLong === isLong && group.legs.some((leg) => {
|
|
110409
110564
|
if (!leg.isTrailing || typeof leg.orderId !== "number") return false;
|
|
@@ -110485,7 +110640,7 @@ var init_runtime_execution = __esm({
|
|
|
110485
110640
|
if (!hasUnresolvedClientProtectiveIdentity(groups2)) continue;
|
|
110486
110641
|
let symbolReports = [];
|
|
110487
110642
|
try {
|
|
110488
|
-
const sizeDecimals = await resolveExchangeSizeDecimals(symbol2, input.config, "trading_reconcile");
|
|
110643
|
+
const sizeDecimals = await resolveExchangeSizeDecimals(symbol2, input.config, "trading_reconcile", profileId);
|
|
110489
110644
|
const core = {
|
|
110490
110645
|
profileId,
|
|
110491
110646
|
config: input.config,
|
|
@@ -110715,7 +110870,7 @@ var init_runtime_execution = __esm({
|
|
|
110715
110870
|
const ownGroups = groups2.filter((group) => group.pendingEntry != null && group.walletAddress === walletAddress.toLowerCase());
|
|
110716
110871
|
if (ownGroups.length === 0) return [];
|
|
110717
110872
|
input.beforeRead?.();
|
|
110718
|
-
const sizeDecimals = await resolveExchangeSizeDecimals(symbol2, input.config, "trading_reconcile");
|
|
110873
|
+
const sizeDecimals = await resolveExchangeSizeDecimals(symbol2, input.config, "trading_reconcile", profileId);
|
|
110719
110874
|
const request = {
|
|
110720
110875
|
mutationAuthority: "manual_session",
|
|
110721
110876
|
profileId,
|
|
@@ -110858,7 +111013,8 @@ var init_runtime_execution = __esm({
|
|
|
110858
111013
|
sizeDecimals: await resolveExchangeSizeDecimals(
|
|
110859
111014
|
unsizedInput.executionContext.symbol,
|
|
110860
111015
|
unsizedInput.config ?? void 0,
|
|
110861
|
-
unsizedInput.decision === "HOLD" || requestedUnits <= 0 ? "trading_reconcile" : executionReadPriority(unsizedInput)
|
|
111016
|
+
unsizedInput.decision === "HOLD" || requestedUnits <= 0 ? "trading_reconcile" : executionReadPriority(unsizedInput),
|
|
111017
|
+
unsizedInput.profileId
|
|
110862
111018
|
)
|
|
110863
111019
|
}
|
|
110864
111020
|
};
|
|
@@ -111425,19 +111581,6 @@ var init_runtime_execution = __esm({
|
|
|
111425
111581
|
executionSnapshotCapturedAt
|
|
111426
111582
|
};
|
|
111427
111583
|
}
|
|
111428
|
-
if (input.executionMode === "server") {
|
|
111429
|
-
const ceilingRefusal = orderCeilingRefusal({
|
|
111430
|
-
side: classified.side,
|
|
111431
|
-
size: sizeAsset,
|
|
111432
|
-
price: executionPrice,
|
|
111433
|
-
// A flip's close has filled by now: its new position starts from flat.
|
|
111434
|
-
currentPositionSize: targetResolution.closeOpposingPosition ? 0 : currentPositionSize,
|
|
111435
|
-
reduceOnly: classified.reduceOnly === true,
|
|
111436
|
-
maxOrderNotional: runtime_policy_generated_default2.trading.risk.max_order_notional,
|
|
111437
|
-
maxPositionNotional: runtime_policy_generated_default2.trading.risk.max_position_notional
|
|
111438
|
-
});
|
|
111439
|
-
if (ceilingRefusal !== null) throw new Error(`Order rejected by risk manager: ${ceilingRefusal}`);
|
|
111440
|
-
}
|
|
111441
111584
|
const entryRequiresFlatAbsenceProof = Number.isFinite(currentPositionSize) && currentPositionSize === 0 || targetResolution.closeOpposingPosition;
|
|
111442
111585
|
if (entryRequiresFlatAbsenceProof) {
|
|
111443
111586
|
const finalProtectionObservation = await verifyNoLiveClientProtectiveTriggers(
|
|
@@ -112078,7 +112221,8 @@ var init_runtime_execution = __esm({
|
|
|
112078
112221
|
const { sz_decimals: assetSizeDecimals } = await resolveHyperliquidAsset({
|
|
112079
112222
|
symbol: input.executionContext.symbol,
|
|
112080
112223
|
config: input.config,
|
|
112081
|
-
publicRequestPriority: "trading_reduce"
|
|
112224
|
+
publicRequestPriority: "trading_reduce",
|
|
112225
|
+
profileId: input.profileId
|
|
112082
112226
|
});
|
|
112083
112227
|
const provisionalLeg = {
|
|
112084
112228
|
kind,
|
|
@@ -112452,9 +112596,12 @@ var init_runtime_execution = __esm({
|
|
|
112452
112596
|
roundingMode: "nearest",
|
|
112453
112597
|
includePrivateContext: desiredPosition != null && Number.isFinite(desiredPosition),
|
|
112454
112598
|
// The device reads its own position and mark; the server never reads
|
|
112455
|
-
// a Client wallet.
|
|
112599
|
+
// a Client wallet. The bot's own profile and runtime config name the
|
|
112600
|
+
// market's execution row (a market VTX's cached list lacks is read here).
|
|
112456
112601
|
walletAddress: input.walletAddress,
|
|
112457
|
-
signal: input.signal
|
|
112602
|
+
signal: input.signal,
|
|
112603
|
+
profileId: input.profileId,
|
|
112604
|
+
config: input.config ?? null
|
|
112458
112605
|
});
|
|
112459
112606
|
if (desiredPosition != null && Number.isFinite(desiredPosition)) {
|
|
112460
112607
|
const preparedContextMaxAgeMs = Number(
|
|
@@ -113186,7 +113333,7 @@ var init_periodic_schedule = __esm({
|
|
|
113186
113333
|
});
|
|
113187
113334
|
|
|
113188
113335
|
// lib/runtime/provider-observability.ts
|
|
113189
|
-
var MAX_DIAGNOSTIC_LIST_ITEMS, record4, ERROR_TOKEN, ERROR_DOMAIN, ERROR_INPUT, ERROR_ECHO_REDACTIONS, ERROR_PROSE_REDACTIONS, CONTROL_CHARACTER_RUN, WHITESPACE_RUN, collapseProse, settled, REDACTED_MARKER_START, boundedMessage, normalizeProviderError, identifier, count4, normalizeProviderDiagnostics, providerRequestId, hash4, googleCredentialDiagnostics, extractProviderDiagnostics, estimateRequestInputTokens;
|
|
113336
|
+
var MAX_DIAGNOSTIC_LIST_ITEMS, record4, ERROR_TOKEN, ERROR_DOMAIN, ERROR_INPUT, ERROR_ECHO_REDACTIONS, ERROR_PROSE_REDACTIONS, CONTROL_CHARACTER_RUN, WHITESPACE_RUN, collapseProse, settled, REDACTED_MARKER_START, boundedMessage, normalizeProviderError, identifier, count4, normalizeProviderDiagnostics, providerRequestId, hash4, googleCredentialDiagnostics, withExecutionMode, extractProviderDiagnostics, estimateRequestInputTokens;
|
|
113190
113337
|
var init_provider_observability = __esm({
|
|
113191
113338
|
"lib/runtime/provider-observability.ts"() {
|
|
113192
113339
|
"use strict";
|
|
@@ -113324,7 +113471,12 @@ var init_provider_observability = __esm({
|
|
|
113324
113471
|
const digest2 = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value));
|
|
113325
113472
|
return Array.from(new Uint8Array(digest2), (b3) => b3.toString(HEX_RADIX).padStart(BYTE_HEX_DIGITS, "0")).join("");
|
|
113326
113473
|
};
|
|
113327
|
-
googleCredentialDiagnostics = async (apiKey) => ({ credential_ref: await hash4(`google:${apiKey}`)
|
|
113474
|
+
googleCredentialDiagnostics = async (apiKey) => ({ credential_ref: await hash4(`google:${apiKey}`) });
|
|
113475
|
+
withExecutionMode = (diagnostics, executionMode) => ({
|
|
113476
|
+
...diagnostics,
|
|
113477
|
+
execution_mode: executionMode,
|
|
113478
|
+
...diagnostics.egress_route === void 0 || diagnostics.egress_route === "node" ? {} : { egress_route: executionMode === "server" ? "server_direct" : "client_direct" }
|
|
113479
|
+
});
|
|
113328
113480
|
extractProviderDiagnostics = async (payload, response) => {
|
|
113329
113481
|
const result = {};
|
|
113330
113482
|
const retryAfter = response?.headers?.get?.("retry-after");
|
|
@@ -116128,6 +116280,156 @@ var init_client_runtime_status_store = __esm({
|
|
|
116128
116280
|
}
|
|
116129
116281
|
});
|
|
116130
116282
|
|
|
116283
|
+
// lib/trade-history-order-id.ts
|
|
116284
|
+
var INTEGER_ID_PATTERN, toSafeIntegerAlias, addOrderIdLookupKey, collectOrderIdLookupKeys;
|
|
116285
|
+
var init_trade_history_order_id = __esm({
|
|
116286
|
+
"lib/trade-history-order-id.ts"() {
|
|
116287
|
+
"use strict";
|
|
116288
|
+
init_define_VTX_CLAUDE_CODE_POLICY();
|
|
116289
|
+
init_define_VTX_EXO_POLICY();
|
|
116290
|
+
init_define_VTX_GROK_POLICY();
|
|
116291
|
+
init_define_VTX_PI_MODEL_POLICY();
|
|
116292
|
+
INTEGER_ID_PATTERN = /^-?\d+$/;
|
|
116293
|
+
toSafeIntegerAlias = (rawString) => {
|
|
116294
|
+
if (!INTEGER_ID_PATTERN.test(rawString)) {
|
|
116295
|
+
return null;
|
|
116296
|
+
}
|
|
116297
|
+
try {
|
|
116298
|
+
const asBigInt = BigInt(rawString);
|
|
116299
|
+
if (asBigInt > BigInt(Number.MAX_SAFE_INTEGER) || asBigInt < BigInt(Number.MIN_SAFE_INTEGER)) {
|
|
116300
|
+
return null;
|
|
116301
|
+
}
|
|
116302
|
+
return String(Number(rawString));
|
|
116303
|
+
} catch {
|
|
116304
|
+
return null;
|
|
116305
|
+
}
|
|
116306
|
+
};
|
|
116307
|
+
addOrderIdLookupKey = (target, rawValue) => {
|
|
116308
|
+
if (rawValue === null || rawValue === void 0) {
|
|
116309
|
+
return;
|
|
116310
|
+
}
|
|
116311
|
+
if (typeof rawValue === "bigint") {
|
|
116312
|
+
target.add(rawValue.toString());
|
|
116313
|
+
return;
|
|
116314
|
+
}
|
|
116315
|
+
if (typeof rawValue === "number") {
|
|
116316
|
+
if (!Number.isFinite(rawValue)) {
|
|
116317
|
+
return;
|
|
116318
|
+
}
|
|
116319
|
+
target.add(String(rawValue));
|
|
116320
|
+
return;
|
|
116321
|
+
}
|
|
116322
|
+
if (typeof rawValue === "string") {
|
|
116323
|
+
const trimmed = rawValue.trim();
|
|
116324
|
+
if (!trimmed) {
|
|
116325
|
+
return;
|
|
116326
|
+
}
|
|
116327
|
+
target.add(trimmed);
|
|
116328
|
+
const numericAlias = toSafeIntegerAlias(trimmed);
|
|
116329
|
+
if (numericAlias) {
|
|
116330
|
+
target.add(numericAlias);
|
|
116331
|
+
}
|
|
116332
|
+
}
|
|
116333
|
+
};
|
|
116334
|
+
collectOrderIdLookupKeys = (rawValue) => {
|
|
116335
|
+
const keys = /* @__PURE__ */ new Set();
|
|
116336
|
+
addOrderIdLookupKey(keys, rawValue);
|
|
116337
|
+
return Array.from(keys);
|
|
116338
|
+
};
|
|
116339
|
+
}
|
|
116340
|
+
});
|
|
116341
|
+
|
|
116342
|
+
// lib/runtime/client-trade-readback.ts
|
|
116343
|
+
var filledOrderIds, syncFilledOrderFills, readClientTradeOutcome, tradeMutationId, reportClientTradeReadback;
|
|
116344
|
+
var init_client_trade_readback = __esm({
|
|
116345
|
+
"lib/runtime/client-trade-readback.ts"() {
|
|
116346
|
+
"use strict";
|
|
116347
|
+
init_define_VTX_CLAUDE_CODE_POLICY();
|
|
116348
|
+
init_define_VTX_EXO_POLICY();
|
|
116349
|
+
init_define_VTX_GROK_POLICY();
|
|
116350
|
+
init_define_VTX_PI_MODEL_POLICY();
|
|
116351
|
+
init_runtime_policy_generated2();
|
|
116352
|
+
init_api2();
|
|
116353
|
+
init_trade_history_order_id();
|
|
116354
|
+
init_hyperliquid_account_state_adapter();
|
|
116355
|
+
init_hyperliquid_client();
|
|
116356
|
+
init_hyperliquid_market_symbol();
|
|
116357
|
+
filledOrderIds = (exchangeResult) => {
|
|
116358
|
+
const statuses = exchangeResult?.response?.data?.statuses;
|
|
116359
|
+
const ids = /* @__PURE__ */ new Set();
|
|
116360
|
+
for (const status of Array.isArray(statuses) ? statuses : []) {
|
|
116361
|
+
const filled = status?.filled;
|
|
116362
|
+
for (const id2 of collectOrderIdLookupKeys(filled?.oid)) ids.add(id2);
|
|
116363
|
+
}
|
|
116364
|
+
return ids;
|
|
116365
|
+
};
|
|
116366
|
+
syncFilledOrderFills = async (target, exchangeResult) => {
|
|
116367
|
+
const orderIds = filledOrderIds(exchangeResult);
|
|
116368
|
+
if (orderIds.size === 0) return;
|
|
116369
|
+
const {
|
|
116370
|
+
close_fill_sync_max_attempts: maxAttempts,
|
|
116371
|
+
close_fill_sync_retry_step_milliseconds: retryStepMs
|
|
116372
|
+
} = runtime_policy_generated_default2.trading.engine.client_runtime;
|
|
116373
|
+
for (let attempt2 = 0; attempt2 < maxAttempts; attempt2 += 1) {
|
|
116374
|
+
if (attempt2 > 0) await new Promise((resolve16) => setTimeout(resolve16, attempt2 * retryStepMs));
|
|
116375
|
+
try {
|
|
116376
|
+
const { rawFills } = await fetchBrowserUserFills({
|
|
116377
|
+
config: target.config,
|
|
116378
|
+
walletAddress: target.walletAddress,
|
|
116379
|
+
symbols: [target.symbol],
|
|
116380
|
+
forceRefresh: true,
|
|
116381
|
+
publicRequestPriority: "trading_reconcile",
|
|
116382
|
+
signal: target.signal
|
|
116383
|
+
});
|
|
116384
|
+
const matching = rawFills.filter((fill) => collectOrderIdLookupKeys(fill.oid).some((id2) => orderIds.has(id2)));
|
|
116385
|
+
if (matching.length > 0) {
|
|
116386
|
+
await syncTradeHistoryFills(Number(target.profileId), target.walletAddress, matching);
|
|
116387
|
+
return;
|
|
116388
|
+
}
|
|
116389
|
+
} catch {
|
|
116390
|
+
}
|
|
116391
|
+
}
|
|
116392
|
+
};
|
|
116393
|
+
readClientTradeOutcome = async (target, exchangeResult) => {
|
|
116394
|
+
const [position] = await Promise.all([
|
|
116395
|
+
fetchBrowserPosition({
|
|
116396
|
+
config: target.config,
|
|
116397
|
+
walletAddress: target.walletAddress,
|
|
116398
|
+
symbol: target.symbol,
|
|
116399
|
+
profileId: target.profileId,
|
|
116400
|
+
publicRequestPriority: "trading_reconcile",
|
|
116401
|
+
signal: target.signal
|
|
116402
|
+
}),
|
|
116403
|
+
syncFilledOrderFills(target, exchangeResult)
|
|
116404
|
+
]);
|
|
116405
|
+
return { position, position_dex: getHyperliquidMarketDex(target.symbol) };
|
|
116406
|
+
};
|
|
116407
|
+
tradeMutationId = (outcome) => {
|
|
116408
|
+
const id2 = outcome instanceof HyperliquidExchangeRejectionError ? outcome.clientMutationId : outcome?.client_runtime_mutation_id;
|
|
116409
|
+
return typeof id2 === "string" && id2.trim() ? id2.trim() : null;
|
|
116410
|
+
};
|
|
116411
|
+
reportClientTradeReadback = async (target, outcome) => {
|
|
116412
|
+
try {
|
|
116413
|
+
const mutationId = tradeMutationId(outcome);
|
|
116414
|
+
const walletAddress = String(target.walletAddress || "").trim();
|
|
116415
|
+
const { config: config2, authority } = target;
|
|
116416
|
+
if (target.executionMode !== "client" || !mutationId || !walletAddress || !config2) return;
|
|
116417
|
+
const read = await readClientTradeOutcome(
|
|
116418
|
+
{ ...target, walletAddress, config: config2 },
|
|
116419
|
+
outcome instanceof Error ? null : outcome
|
|
116420
|
+
);
|
|
116421
|
+
await reportClientTradeMarketRead(target.profileId, mutationId, read, ...authority ? [
|
|
116422
|
+
authority.runtimeSessionId,
|
|
116423
|
+
authority.runtimeLeaseToken,
|
|
116424
|
+
authority.runtimeDeviceId,
|
|
116425
|
+
authority.schedulerInstanceId
|
|
116426
|
+
] : []);
|
|
116427
|
+
} catch {
|
|
116428
|
+
}
|
|
116429
|
+
};
|
|
116430
|
+
}
|
|
116431
|
+
});
|
|
116432
|
+
|
|
116131
116433
|
// lib/runtime/perp-dex-scope.ts
|
|
116132
116434
|
var perpDexScopeForSymbols, equityVenuesForSymbols, profileEquityVenues, profileExchanges, positionsOnVenues;
|
|
116133
116435
|
var init_perp_dex_scope = __esm({
|
|
@@ -116183,6 +116485,7 @@ var init_client_killswitch = __esm({
|
|
|
116183
116485
|
init_api2();
|
|
116184
116486
|
init_constants();
|
|
116185
116487
|
init_browser_trading();
|
|
116488
|
+
init_client_trade_readback();
|
|
116186
116489
|
init_perp_dex_scope();
|
|
116187
116490
|
init_hyperliquid_account_state_adapter();
|
|
116188
116491
|
toPositiveFinite2 = (value) => {
|
|
@@ -116352,6 +116655,7 @@ var init_client_killswitch = __esm({
|
|
|
116352
116655
|
),
|
|
116353
116656
|
Math.round(timeoutSeconds * MS_PER_SECOND)
|
|
116354
116657
|
);
|
|
116658
|
+
const outcomes = [];
|
|
116355
116659
|
try {
|
|
116356
116660
|
for (let index = 0; index < positions.length; index += 1) {
|
|
116357
116661
|
const position = positions[index];
|
|
@@ -116360,7 +116664,7 @@ var init_client_killswitch = __esm({
|
|
|
116360
116664
|
break;
|
|
116361
116665
|
}
|
|
116362
116666
|
try {
|
|
116363
|
-
await executeClientClosePosition({
|
|
116667
|
+
const outcome = await executeClientClosePosition({
|
|
116364
116668
|
profileId: input.profileId,
|
|
116365
116669
|
walletAddress: input.walletAddress,
|
|
116366
116670
|
config: input.config,
|
|
@@ -116368,16 +116672,27 @@ var init_client_killswitch = __esm({
|
|
|
116368
116672
|
symbol: position.symbol,
|
|
116369
116673
|
size: Math.abs(Number(position.size)),
|
|
116370
116674
|
position,
|
|
116371
|
-
signal: closeController.signal
|
|
116675
|
+
signal: closeController.signal,
|
|
116676
|
+
...input.authority ? { ...input.authority, safetyClose: input.reason } : {}
|
|
116372
116677
|
});
|
|
116678
|
+
outcomes.push({ symbol: position.symbol, outcome });
|
|
116373
116679
|
positionsClosed += 1;
|
|
116374
|
-
} catch {
|
|
116680
|
+
} catch (error48) {
|
|
116681
|
+
outcomes.push({ symbol: position.symbol, outcome: error48 });
|
|
116375
116682
|
positionCloseFailures += 1;
|
|
116376
116683
|
}
|
|
116377
116684
|
}
|
|
116378
116685
|
} finally {
|
|
116379
116686
|
clearTimeout(timeoutId);
|
|
116380
116687
|
}
|
|
116688
|
+
await Promise.all(outcomes.map(({ symbol: symbol2, outcome }) => reportClientTradeReadback({
|
|
116689
|
+
profileId: input.profileId,
|
|
116690
|
+
walletAddress: input.walletAddress,
|
|
116691
|
+
config: input.config,
|
|
116692
|
+
symbol: symbol2,
|
|
116693
|
+
executionMode: input.executionMode,
|
|
116694
|
+
authority: input.authority
|
|
116695
|
+
}, outcome)));
|
|
116381
116696
|
return {
|
|
116382
116697
|
requested: true,
|
|
116383
116698
|
positionsClosed,
|
|
@@ -116424,33 +116739,33 @@ var init_history_evidence = __esm({
|
|
|
116424
116739
|
isDecimalText = (value) => typeof value === "string" && DECIMAL_TEXT.test(value.trim());
|
|
116425
116740
|
isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
116426
116741
|
parseHistoryPage = (stream, body, startMs, endMs) => {
|
|
116427
|
-
const
|
|
116742
|
+
const malformed2 = (detail) => new HistoryPageError(`The ${stream} page is not a valid Hyperliquid response: ${detail}`);
|
|
116428
116743
|
if (!STREAMS.has(stream)) throw new HistoryPageError(`Unknown history stream ${stream}.`);
|
|
116429
|
-
if (!isInt(startMs) || !isInt(endMs) || startMs < 0 || endMs < startMs) throw
|
|
116430
|
-
if (typeof body !== "string") throw
|
|
116744
|
+
if (!isInt(startMs) || !isInt(endMs) || startMs < 0 || endMs < startMs) throw malformed2("the window is invalid");
|
|
116745
|
+
if (typeof body !== "string") throw malformed2("the body must be the raw response text");
|
|
116431
116746
|
let rows;
|
|
116432
116747
|
try {
|
|
116433
116748
|
rows = JSON.parse(body);
|
|
116434
116749
|
} catch {
|
|
116435
|
-
throw
|
|
116750
|
+
throw malformed2("the body is not JSON");
|
|
116436
116751
|
}
|
|
116437
|
-
if (!Array.isArray(rows)) throw
|
|
116752
|
+
if (!Array.isArray(rows)) throw malformed2("the body is not a list");
|
|
116438
116753
|
for (const row of rows) {
|
|
116439
|
-
if (!isRecord4(row)) throw
|
|
116754
|
+
if (!isRecord4(row)) throw malformed2("a row is not an object");
|
|
116440
116755
|
const time3 = row.time;
|
|
116441
|
-
if (!isInt(time3)) throw
|
|
116442
|
-
if (time3 < startMs || time3 > endMs) throw
|
|
116443
|
-
if (!isText(row.hash)) throw
|
|
116756
|
+
if (!isInt(time3)) throw malformed2("a row has no millisecond time");
|
|
116757
|
+
if (time3 < startMs || time3 > endMs) throw malformed2("a row lies outside the requested window");
|
|
116758
|
+
if (!isText(row.hash)) throw malformed2("a row has no hash");
|
|
116444
116759
|
if (stream === "fills") {
|
|
116445
116760
|
if (!(isText(row.coin) && isInt(row.oid) && (row.side === "A" || row.side === "B") && isDecimalText(row.px) && isDecimalText(row.sz))) {
|
|
116446
|
-
throw
|
|
116761
|
+
throw malformed2("a fill lacks coin, oid, side, px or sz");
|
|
116447
116762
|
}
|
|
116448
116763
|
continue;
|
|
116449
116764
|
}
|
|
116450
116765
|
const delta = row.delta;
|
|
116451
|
-
if (!isRecord4(delta) || !isText(delta.type)) throw
|
|
116766
|
+
if (!isRecord4(delta) || !isText(delta.type)) throw malformed2("a row has no typed delta");
|
|
116452
116767
|
if (stream === "funding" && !(delta.type === "funding" && isText(delta.coin) && isDecimalText(delta.usdc))) {
|
|
116453
|
-
throw
|
|
116768
|
+
throw malformed2("a funding row lacks coin or usdc");
|
|
116454
116769
|
}
|
|
116455
116770
|
}
|
|
116456
116771
|
return rows;
|
|
@@ -116620,12 +116935,12 @@ var init_host_wake_schedule = __esm({
|
|
|
116620
116935
|
init_define_VTX_GROK_POLICY();
|
|
116621
116936
|
init_define_VTX_PI_MODEL_POLICY();
|
|
116622
116937
|
marker = null;
|
|
116623
|
-
markBatchableTimer = (handle) => {
|
|
116624
|
-
marker?.(handle, "batchable");
|
|
116938
|
+
markBatchableTimer = (handle, options) => {
|
|
116939
|
+
marker?.(handle, "batchable", options);
|
|
116625
116940
|
return handle;
|
|
116626
116941
|
};
|
|
116627
|
-
markDeferrableTimer = (handle) => {
|
|
116628
|
-
marker?.(handle, "deferrable");
|
|
116942
|
+
markDeferrableTimer = (handle, options) => {
|
|
116943
|
+
marker?.(handle, "deferrable", options);
|
|
116629
116944
|
return handle;
|
|
116630
116945
|
};
|
|
116631
116946
|
}
|
|
@@ -118816,7 +119131,8 @@ var init_provider_client = __esm({
|
|
|
118816
119131
|
providerDispatchClockMs = () => typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
|
|
118817
119132
|
beginProviderDispatch = (requestBody) => ({
|
|
118818
119133
|
requestInputTokens: estimateRequestInputTokens(requestBody),
|
|
118819
|
-
|
|
119134
|
+
// Where the call runs is its caller's to say (withExecutionMode, on its invocation record).
|
|
119135
|
+
providerDiagnostics: {},
|
|
118820
119136
|
sentReasoningParameters: extractReasoningParameters(requestBody),
|
|
118821
119137
|
effectiveReasoningParameters: {},
|
|
118822
119138
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -120863,7 +121179,7 @@ var init_provider_client = __esm({
|
|
|
120863
121179
|
provider_request_id: input.providerRequestId ?? response?.providerRequestId,
|
|
120864
121180
|
request_input_tokens: input.requestInputTokens ?? response?.requestInputTokens,
|
|
120865
121181
|
request_input_tokens_source: (input.requestInputTokens ?? response?.requestInputTokens) != null ? "estimated_chars_v1" : null,
|
|
120866
|
-
provider_diagnostics: input.providerDiagnostics ?? response?.providerDiagnostics ?? {},
|
|
121182
|
+
provider_diagnostics: withExecutionMode(input.providerDiagnostics ?? response?.providerDiagnostics ?? {}, input.executionMode),
|
|
120867
121183
|
service_tier: response?.serviceTier,
|
|
120868
121184
|
system_fingerprint: response?.systemFingerprint,
|
|
120869
121185
|
credential_slot_index: input.credentialSlotIndex,
|
|
@@ -121028,6 +121344,7 @@ var init_provider_client = __esm({
|
|
|
121028
121344
|
} : void 0;
|
|
121029
121345
|
const maxTokens = requestedMaxTokens ?? null;
|
|
121030
121346
|
const runtimeMode = toRuntimeExecutionMode(input.mode);
|
|
121347
|
+
const { executionMode } = input;
|
|
121031
121348
|
const normalizedExtraMessages = normalizeRuntimeChatHistory(extraMessages);
|
|
121032
121349
|
const invocationContext = input.invocationContext ?? defaultInvocationContext();
|
|
121033
121350
|
const priorInvocationAttempts = [...input.invocationAttemptChain ?? []];
|
|
@@ -121061,6 +121378,7 @@ var init_provider_client = __esm({
|
|
|
121061
121378
|
const missingKey = new Error(openAiCompatibleOverrideConfigured ? "No API key is saved for the OpenAI-compatible endpoint. Save that endpoint's own key in System settings; the OpenAI key is never sent to a custom endpoint." : `No profile API key was provided for source '${provider}'.`);
|
|
121062
121379
|
const neverSent = await buildBrowserInvocation({
|
|
121063
121380
|
context: invocationContext,
|
|
121381
|
+
executionMode,
|
|
121064
121382
|
attemptIndex: priorInvocationAttempts.length,
|
|
121065
121383
|
status: "failed",
|
|
121066
121384
|
provider,
|
|
@@ -121106,6 +121424,7 @@ var init_provider_client = __esm({
|
|
|
121106
121424
|
const errorDetail = String(attempt2.errorDetail || "Provider compatibility dispatch failed.");
|
|
121107
121425
|
chain.push(await buildBrowserInvocation({
|
|
121108
121426
|
context: invocationContext,
|
|
121427
|
+
executionMode,
|
|
121109
121428
|
attemptIndex: chain.length,
|
|
121110
121429
|
status: "failed",
|
|
121111
121430
|
provider,
|
|
@@ -121441,6 +121760,7 @@ var init_provider_client = __esm({
|
|
|
121441
121760
|
) : null;
|
|
121442
121761
|
const failedInvocation = await buildBrowserInvocation({
|
|
121443
121762
|
context: invocationContext,
|
|
121763
|
+
executionMode,
|
|
121444
121764
|
attemptIndex: invocationAttempts2.length,
|
|
121445
121765
|
status: nativeFailureKind === "timeout" ? "failed" : isAbortLikeError(error48) ? "cancelled" : "failed",
|
|
121446
121766
|
provider,
|
|
@@ -121646,6 +121966,7 @@ var init_provider_client = __esm({
|
|
|
121646
121966
|
);
|
|
121647
121967
|
const successInvocation = await buildBrowserInvocation({
|
|
121648
121968
|
context: invocationContext,
|
|
121969
|
+
executionMode,
|
|
121649
121970
|
attemptIndex: observedInvocationAttempts.length,
|
|
121650
121971
|
status: "succeeded",
|
|
121651
121972
|
provider,
|
|
@@ -128294,6 +128615,7 @@ ${stringifyPromptJson(candlesPayload)}
|
|
|
128294
128615
|
},
|
|
128295
128616
|
profileId: input.profileId,
|
|
128296
128617
|
mode: input.mode,
|
|
128618
|
+
executionMode: input.executionMode,
|
|
128297
128619
|
provider: entryProvider,
|
|
128298
128620
|
model: entry.model_id,
|
|
128299
128621
|
systemPrompt,
|
|
@@ -128675,6 +128997,7 @@ ${reviewOutputContract}`;
|
|
|
128675
128997
|
},
|
|
128676
128998
|
profileId: input.profileId,
|
|
128677
128999
|
mode: input.mode,
|
|
129000
|
+
executionMode: input.executionMode,
|
|
128678
129001
|
provider: reviewProvider,
|
|
128679
129002
|
model: reviewModel,
|
|
128680
129003
|
systemPrompt: reviewPromptArtifacts.systemPrompt,
|
|
@@ -129998,7 +130321,8 @@ var init_engine = __esm({
|
|
|
129998
130321
|
this._primaryAnalysisDisabled = false;
|
|
129999
130322
|
this._loopEarlyReturnRetryDelayMs = CLIENT_RUNTIME_POLICY.loop_early_return_retry_milliseconds;
|
|
130000
130323
|
this._executionModeMismatchConsecutiveCount = 0;
|
|
130001
|
-
|
|
130324
|
+
// Set by attach from the host's own answer; unknown before then.
|
|
130325
|
+
this._expectedExecutionMode = null;
|
|
130002
130326
|
this._settleUnreportedModelCalls = null;
|
|
130003
130327
|
// How many of an error's model calls its last error report carried.
|
|
130004
130328
|
this._lastErrorReportCalls = null;
|
|
@@ -130223,7 +130547,10 @@ var init_engine = __esm({
|
|
|
130223
130547
|
config: paused.config,
|
|
130224
130548
|
signingKey,
|
|
130225
130549
|
timeoutSeconds,
|
|
130226
|
-
venues: stopCloseVenues
|
|
130550
|
+
venues: stopCloseVenues,
|
|
130551
|
+
authority: this.safetyCloseAuthority(),
|
|
130552
|
+
executionMode: this._expectedExecutionMode,
|
|
130553
|
+
reason: "close_on_stop"
|
|
130227
130554
|
});
|
|
130228
130555
|
if (summary.positionCloseFailures > 0) {
|
|
130229
130556
|
throw new Error(`${summary.positionCloseFailures} position(s) could not be closed`);
|
|
@@ -131156,7 +131483,20 @@ var init_engine = __esm({
|
|
|
131156
131483
|
if (lease?.runtimeSessionId !== sessionId || lease.deviceId !== deviceId || lease.mode !== "trader" || !lease.runtimeLeaseToken) return null;
|
|
131157
131484
|
return { runtimeSessionId: sessionId, runtimeLeaseToken: lease.runtimeLeaseToken, runtimeDeviceId: deviceId, schedulerInstanceId: this._instanceId };
|
|
131158
131485
|
}
|
|
131159
|
-
/**
|
|
131486
|
+
/**
|
|
131487
|
+
* The authority a safety close this engine sends outside its cycle (a kill
|
|
131488
|
+
* switch's, a close on stop's) signs with. A browser or desktop page keeps
|
|
131489
|
+
* exactly the authority it had (its own session, or a trader lease it may
|
|
131490
|
+
* use), so its safety close meets no check it did not meet before. A Node
|
|
131491
|
+
* host (the CLI, Android's or VTX's runtime host) has no browser session:
|
|
131492
|
+
* it signs with this engine's own trader lease, bound to a scheduler
|
|
131493
|
+
* instance or not (an agent token's claim binds none), and the close is then
|
|
131494
|
+
* marked a safety close (client-killswitch.ts), so a stale runtime contract
|
|
131495
|
+
* or a bot no longer set to run does not refuse it.
|
|
131496
|
+
*/
|
|
131497
|
+
safetyCloseAuthority() {
|
|
131498
|
+
return hostHasBrowserExchangeSession() ? null : this.traderLeaseAuthority;
|
|
131499
|
+
}
|
|
131160
131500
|
/**
|
|
131161
131501
|
* Resolves once no cycle is in flight, or after the timeout: a Node runtime
|
|
131162
131502
|
* host draining for a restart lets the current cycle finish, as a Python
|
|
@@ -131175,6 +131515,7 @@ var init_engine = __esm({
|
|
|
131175
131515
|
clearTimeout(timer);
|
|
131176
131516
|
return settled2;
|
|
131177
131517
|
}
|
|
131518
|
+
/** Whether this engine runs, starts, or stops a runtime (never claim it again). */
|
|
131178
131519
|
get active() {
|
|
131179
131520
|
return this._startPromise !== null || this._isStopping || this._state === "running" || this._state === "stale" || this._state === "offline";
|
|
131180
131521
|
}
|
|
@@ -131210,7 +131551,7 @@ var init_engine = __esm({
|
|
|
131210
131551
|
if (String(lease.profile_id) !== String(profileId) || !grantSessionId || !grantDeviceId) {
|
|
131211
131552
|
throw new Error("The runtime grant does not belong to this profile.");
|
|
131212
131553
|
}
|
|
131213
|
-
this._expectedExecutionMode = options.executionMode
|
|
131554
|
+
this._expectedExecutionMode = options.executionMode;
|
|
131214
131555
|
this._manualRunRequested = false;
|
|
131215
131556
|
this._aiScheduleCheckPending = false;
|
|
131216
131557
|
this._checkOnlyCycleInFlight = false;
|
|
@@ -132399,6 +132740,11 @@ var init_engine = __esm({
|
|
|
132399
132740
|
await this.reportError("Client runtime session secrets were not initialized.", { fatal: true });
|
|
132400
132741
|
return;
|
|
132401
132742
|
}
|
|
132743
|
+
const executionMode = this._expectedExecutionMode;
|
|
132744
|
+
if (!executionMode) {
|
|
132745
|
+
await this.reportError("Client runtime execution mode was not initialized.", { fatal: true });
|
|
132746
|
+
return;
|
|
132747
|
+
}
|
|
132402
132748
|
const profileId = this._profileId;
|
|
132403
132749
|
const sessionId = this._sessionId;
|
|
132404
132750
|
const deviceId = this._deviceId;
|
|
@@ -132645,7 +132991,7 @@ var init_engine = __esm({
|
|
|
132645
132991
|
},
|
|
132646
132992
|
ignoreAiSchedule,
|
|
132647
132993
|
aiScheduleCheckOnly,
|
|
132648
|
-
executionMode
|
|
132994
|
+
executionMode,
|
|
132649
132995
|
onPreparedExecutionContexts: async ({ config: config2, executionContexts }) => {
|
|
132650
132996
|
if (runtimeMode !== "trader") return;
|
|
132651
132997
|
const cancelled = () => this._state !== "running" || this._isStopping || this._windowHandoffRequested || this._killswitchLatched || this._profileId !== profileId || this._sessionId !== sessionId || this._deviceId !== deviceId || (getRuntimeContractBindingTupleToken(this._activeRuntimeContractIdentity) ?? getRuntimeStatusContractBindingTupleToken(this._runtimeStatus)) !== loopContractBindingToken;
|
|
@@ -132663,6 +133009,7 @@ var init_engine = __esm({
|
|
|
132663
133009
|
decision: "HOLD",
|
|
132664
133010
|
units: 0,
|
|
132665
133011
|
executionContext,
|
|
133012
|
+
executionMode,
|
|
132666
133013
|
shouldCancelBeforeExchangeOrderDispatch: cancelled,
|
|
132667
133014
|
beforeTrailingMaintenance: (signal) => this._assertFreshClientWalletAssignment(profileId, executionContext.walletAddress, signal, "trailing stop maintenance"),
|
|
132668
133015
|
onExchangeOrderDispatched: () => {
|
|
@@ -133175,7 +133522,7 @@ var init_engine = __esm({
|
|
|
133175
133522
|
config: config2,
|
|
133176
133523
|
decision: plan.decision,
|
|
133177
133524
|
units: plan.units,
|
|
133178
|
-
executionMode
|
|
133525
|
+
executionMode,
|
|
133179
133526
|
executionContext: plan.executionContext,
|
|
133180
133527
|
skipTrailingMaintenance: this._trailingObservations.some((request) => request.executionContext.decisionSnapshotId === plan.executionContext.decisionSnapshotId),
|
|
133181
133528
|
signal: analysisAbortController.signal,
|
|
@@ -134256,7 +134603,7 @@ var init_engine = __esm({
|
|
|
134256
134603
|
// its start.
|
|
134257
134604
|
analyzingObservedAtMs: heartbeatObservedAtMs
|
|
134258
134605
|
});
|
|
134259
|
-
if (Number(response.protective_actions_pending ?? 0) > 0) {
|
|
134606
|
+
if (Number(response.protective_actions_pending ?? 0) > 0 || response.protective_evidence_due === true) {
|
|
134260
134607
|
notifyClientProtectiveActionsPending(heartbeatProfileId);
|
|
134261
134608
|
}
|
|
134262
134609
|
if (this._isStopping || this._state === "stopped" || this._profileId !== heartbeatProfileId || this._sessionId !== heartbeatSessionId || this._deviceId !== heartbeatDeviceId || this._mode !== heartbeatMode || this._lifecycleGeneration !== heartbeatLifecycleGeneration) {
|
|
@@ -134716,7 +135063,10 @@ var init_engine = __esm({
|
|
|
134716
135063
|
config: config2,
|
|
134717
135064
|
signingKey,
|
|
134718
135065
|
timeoutSeconds: closeTimeoutSeconds,
|
|
134719
|
-
venues: evaluation.closeVenues
|
|
135066
|
+
venues: evaluation.closeVenues,
|
|
135067
|
+
authority: this.safetyCloseAuthority(),
|
|
135068
|
+
executionMode: this._expectedExecutionMode,
|
|
135069
|
+
reason: "killswitch"
|
|
134720
135070
|
});
|
|
134721
135071
|
} else {
|
|
134722
135072
|
closeSummary = {
|
|
@@ -135710,7 +136060,9 @@ async function attachEngine(options, engine, claimed, claimKind) {
|
|
|
135710
136060
|
claimKind,
|
|
135711
136061
|
preflight,
|
|
135712
136062
|
skipServerHydration: true,
|
|
135713
|
-
unboundSchedulerLease: true
|
|
136063
|
+
unboundSchedulerLease: true,
|
|
136064
|
+
// The headless Client Mode runtime runs on the user's own machine.
|
|
136065
|
+
executionMode: "client"
|
|
135714
136066
|
});
|
|
135715
136067
|
}
|
|
135716
136068
|
async function persistRuntimeState(options, identity2, { claim }) {
|