@jsonstudio/llms 0.6.3409 → 0.6.3539

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.
Files changed (82) hide show
  1. package/dist/conversion/codecs/anthropic-openai-codec.d.ts +12 -3
  2. package/dist/conversion/codecs/anthropic-openai-codec.js +32 -92
  3. package/dist/conversion/codecs/gemini-openai-codec.d.ts +6 -5
  4. package/dist/conversion/codecs/gemini-openai-codec.js +48 -685
  5. package/dist/conversion/codecs/openai-openai-codec.d.ts +1 -1
  6. package/dist/conversion/codecs/openai-openai-codec.js +34 -100
  7. package/dist/conversion/codecs/responses-openai-codec.d.ts +1 -1
  8. package/dist/conversion/codecs/responses-openai-codec.js +47 -159
  9. package/dist/conversion/compat/actions/anthropic-claude-code-system-prompt.d.ts +2 -6
  10. package/dist/conversion/compat/actions/anthropic-claude-code-system-prompt.js +29 -245
  11. package/dist/conversion/compat/actions/anthropic-claude-code-user-id.d.ts +3 -0
  12. package/dist/conversion/compat/actions/anthropic-claude-code-user-id.js +30 -0
  13. package/dist/conversion/compat/actions/antigravity-thought-signature-prepare.js +21 -232
  14. package/dist/conversion/compat/actions/deepseek-web-request.js +41 -276
  15. package/dist/conversion/compat/actions/deepseek-web-response.js +64 -859
  16. package/dist/conversion/compat/actions/gemini-cli-request.d.ts +1 -1
  17. package/dist/conversion/compat/actions/gemini-cli-request.js +20 -613
  18. package/dist/conversion/compat/actions/gemini-web-search.d.ts +1 -15
  19. package/dist/conversion/compat/actions/gemini-web-search.js +22 -69
  20. package/dist/conversion/compat/actions/glm-tool-extraction.d.ts +3 -2
  21. package/dist/conversion/compat/actions/glm-tool-extraction.js +28 -257
  22. package/dist/conversion/compat/actions/iflow-tool-text-fallback.d.ts +0 -8
  23. package/dist/conversion/compat/actions/iflow-tool-text-fallback.js +24 -206
  24. package/dist/conversion/compat/actions/qwen-transform.d.ts +3 -2
  25. package/dist/conversion/compat/actions/qwen-transform.js +30 -271
  26. package/dist/conversion/compat/actions/tool-text-request-guidance.js +3 -173
  27. package/dist/conversion/compat/actions/universal-shape-filter.d.ts +6 -23
  28. package/dist/conversion/compat/actions/universal-shape-filter.js +4 -383
  29. package/dist/conversion/hub/pipeline/compat/native-adapter-context.js +1 -0
  30. package/dist/conversion/pipeline/codecs/v2/anthropic-openai-pipeline.d.ts +1 -2
  31. package/dist/conversion/pipeline/codecs/v2/anthropic-openai-pipeline.js +50 -104
  32. package/dist/conversion/pipeline/codecs/v2/openai-openai-pipeline.js +12 -10
  33. package/dist/conversion/pipeline/codecs/v2/responses-openai-pipeline.d.ts +0 -2
  34. package/dist/conversion/pipeline/codecs/v2/responses-openai-pipeline.js +46 -67
  35. package/dist/conversion/pipeline/codecs/v2/shared/openai-chat-helpers.js +15 -40
  36. package/dist/conversion/responses/responses-openai-bridge/response-payload.js +47 -348
  37. package/dist/conversion/responses/responses-openai-bridge.js +129 -611
  38. package/dist/conversion/shared/chat-output-normalizer.js +6 -0
  39. package/dist/conversion/shared/chat-request-filters.js +1 -1
  40. package/dist/conversion/shared/output-content-normalizer.js +10 -0
  41. package/dist/conversion/shared/responses-conversation-store.js +22 -135
  42. package/dist/conversion/shared/responses-output-builder.d.ts +0 -2
  43. package/dist/conversion/shared/responses-output-builder.js +28 -318
  44. package/dist/conversion/shared/responses-response-utils.js +35 -86
  45. package/dist/conversion/shared/streaming-text-extractor.d.ts +1 -2
  46. package/dist/conversion/shared/streaming-text-extractor.js +13 -14
  47. package/dist/native/router_hotpath_napi.node +0 -0
  48. package/dist/router/virtual-router/bootstrap/routing-config.js +11 -3
  49. package/dist/router/virtual-router/engine-legacy.d.ts +3 -3
  50. package/dist/router/virtual-router/engine-legacy.js +15 -7
  51. package/dist/router/virtual-router/engine-selection/native-compat-action-semantics.d.ts +16 -0
  52. package/dist/router/virtual-router/engine-selection/native-compat-action-semantics.js +434 -46
  53. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.d.ts +83 -0
  54. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js +295 -0
  55. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.d.ts +1 -0
  56. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.d.ts +7 -0
  57. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js +8 -1
  58. package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +383 -298
  59. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.d.ts +20 -0
  60. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +201 -0
  61. package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.d.ts +1 -0
  62. package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.js +37 -0
  63. package/dist/router/virtual-router/engine.js +0 -38
  64. package/dist/router/virtual-router/features.js +44 -3
  65. package/dist/router/virtual-router/routing-instructions/parse.d.ts +0 -12
  66. package/dist/router/virtual-router/routing-instructions/parse.js +9 -389
  67. package/dist/router/virtual-router/stop-message-state-sync.d.ts +3 -6
  68. package/dist/router/virtual-router/stop-message-state-sync.js +50 -21
  69. package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.d.ts +1 -0
  70. package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.js +26 -0
  71. package/dist/sse/sse-to-json/builders/anthropic-response-builder.js +12 -2
  72. package/package.json +1 -1
  73. package/dist/router/virtual-router/engine-legacy/route-finalize.d.ts +0 -9
  74. package/dist/router/virtual-router/engine-legacy/route-finalize.js +0 -84
  75. package/dist/router/virtual-router/engine-legacy/route-selection.d.ts +0 -17
  76. package/dist/router/virtual-router/engine-legacy/route-selection.js +0 -205
  77. package/dist/router/virtual-router/engine-legacy/route-state-allowlist.d.ts +0 -3
  78. package/dist/router/virtual-router/engine-legacy/route-state-allowlist.js +0 -36
  79. package/dist/router/virtual-router/engine-legacy/route-state.d.ts +0 -12
  80. package/dist/router/virtual-router/engine-legacy/route-state.js +0 -386
  81. package/dist/router/virtual-router/engine-legacy/routing.d.ts +0 -8
  82. package/dist/router/virtual-router/engine-legacy/routing.js +0 -8
@@ -1,285 +1,338 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { fileURLToPath, pathToFileURL } from 'node:url';
4
- import { createRequire } from 'node:module';
5
- import { hasCompleteNativeBinding } from './native-router-hotpath-policy.js';
6
- const require = createRequire(import.meta.url);
7
- const workspaceRoot = resolvePackageRoot(path.dirname(fileURLToPath(import.meta.url)));
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import { createRequire } from "node:module";
5
+ import { hasCompleteNativeBinding } from "./native-router-hotpath-policy.js";
6
+ function resolveLoaderModulePath() {
7
+ if (typeof __filename === "string" && __filename.length > 0) {
8
+ return __filename;
9
+ }
10
+ const stack = String(new Error().stack || "");
11
+ for (const line of stack.split("\n")) {
12
+ const match = line.match(/(file:\/\/[^\s)]+native-router-hotpath-loader\.(?:ts|js)|\/[^\s)]+native-router-hotpath-loader\.(?:ts|js))/);
13
+ if (!match) {
14
+ continue;
15
+ }
16
+ const rawPath = match[1];
17
+ if (rawPath.startsWith("file://")) {
18
+ try {
19
+ return decodeURIComponent(new URL(rawPath).pathname);
20
+ }
21
+ catch {
22
+ continue;
23
+ }
24
+ }
25
+ return rawPath;
26
+ }
27
+ return path.join(process.cwd(), "src/router/virtual-router/engine-selection/native-router-hotpath-loader.ts");
28
+ }
29
+ const loaderModulePath = resolveLoaderModulePath();
30
+ const nodeRequire = createRequire(loaderModulePath);
31
+ const workspaceRoot = resolvePackageRoot(path.dirname(loaderModulePath));
8
32
  let cachedBinding;
9
33
  let cachedBindingCacheKey;
10
34
  const REQUIRED_NATIVE_EXPORTS = [
11
- 'analyzeChatProcessMediaJson',
12
- 'analyzeChatWebSearchIntentJson',
13
- 'extractWebSearchSemanticsHintJson',
14
- 'extractOutputSegmentsJson',
15
- 'analyzeContinueExecutionInjectionJson',
16
- 'analyzePendingToolSyncJson',
17
- 'appendToolParseDiagnosticTextJson',
18
- 'injectToolParseDiagnosticsJson',
19
- 'applyReqProcessToolGovernanceJson',
20
- 'applyHubOperationsJson',
21
- 'applyReqProcessRouteSelectionJson',
22
- 'applyReqOutboundContextSnapshotJson',
23
- 'applyClaudeThinkingToolSchemaCompatJson',
24
- 'applyOutboundStreamPreferenceJson',
25
- 'applyTargetMetadataJson',
26
- 'applyTargetToSubjectJson',
27
- 'applyStopMessageInstructionJson',
28
- 'attachPassthroughProviderInputAuditJson',
29
- 'augmentContextSnapshotJson',
30
- 'annotatePassthroughGovernanceSkipJson',
31
- 'buildAnthropicToolAliasMapJson',
32
- 'buildAnthropicResponseFromChatJson',
33
- 'buildChatNodeResultMetadataJson',
34
- 'buildProcessedRequestFromChatResponseJson',
35
- 'applyChatProcessedRequestJson',
36
- 'buildChatProcessContextMetadataJson',
37
- 'buildChatProcessedDescriptorJson',
38
- 'applyClientPassthroughPatchJson',
39
- 'applyGovernedControlOperationsJson',
40
- 'applyGovernedMergeRequestJson',
41
- 'buildClockMarkerScheduleMessagesJson',
42
- 'buildClockReminderMessagesJson',
43
- 'buildClockReminderMetadataJson',
44
- 'buildProviderProtocolErrorJson',
45
- 'buildFormatRequestJson',
46
- 'buildClockStandardToolAppendOperationsJson',
47
- 'buildClockToolAppendOperationsJson',
48
- 'buildResponsesPayloadFromChatJson',
49
- 'buildBridgeHistoryJson',
50
- 'applyBridgeNormalizeHistoryJson',
51
- 'applyBridgeCaptureToolResultsJson',
52
- 'applyBridgeNormalizeToolIdentifiersJson',
53
- 'applyBridgeEnsureToolPlaceholdersJson',
54
- 'convertBridgeInputToChatMessagesJson',
55
- 'coerceBridgeRoleJson',
56
- 'harvestToolsJson',
57
- 'serializeToolArgumentsJson',
58
- 'pruneChatRequestPayloadJson',
59
- 'enforceToolCallIdStyleJson',
60
- 'transformToolCallIdJson',
61
- 'createToolCallIdTransformerJson',
62
- 'extractToolCallIdJson',
63
- 'normalizeIdValueJson',
64
- 'extractStreamingToolCallsJson',
65
- 'chunkStringJson',
66
- 'flattenByCommaJson',
67
- 'packShellArgsJson',
68
- 'splitCommandStringJson',
69
- 'repairFindMetaJson',
70
- 'removeTrailingUnsignedThinkingBlocksJson',
71
- 'filterInvalidThinkingBlocksJson',
72
- 'sanitizeThinkingBlockJson',
73
- 'hasValidThoughtSignatureJson',
74
- 'serializeToolOutputJson',
75
- 'ensureMessagesArrayJson',
76
- 'normalizeReasoningInChatPayloadJson',
77
- 'normalizeReasoningInResponsesPayloadJson',
78
- 'normalizeReasoningInGeminiPayloadJson',
79
- 'normalizeReasoningInAnthropicPayloadJson',
80
- 'normalizeReasoningInOpenAIPayloadJson',
81
- 'buildContinueExecutionOperationsJson',
82
- 'buildDueReminderUserMessageJson',
83
- 'buildGovernedFilterPayloadJson',
84
- 'buildPassthroughAuditJson',
85
- 'buildGuardedClockScheduleItemJson',
86
- 'buildImageAttachmentMetadataJson',
87
- 'buildReviewOperationsJson',
88
- 'buildWebSearchToolAppendOperationsJson',
89
- 'clampResponsesInputItemIdJson',
90
- 'castGovernedToolsJson',
91
- 'collectToolOutputsJson',
92
- 'buildReqInboundToolOutputSnapshotJson',
93
- 'mapBridgeToolsToChatJson',
94
- 'mapOpenaiChatToChatJson',
95
- 'mapOpenaiChatFromChatJson',
96
- 'mapChatToolsToBridgeJson',
97
- 'bridgeToolToChatDefinitionJson',
98
- 'chatToolToBridgeDefinitionJson',
99
- 'mapBridgeToolsToChatWithOptionsJson',
100
- 'mapChatToolsToBridgeWithOptionsJson',
101
- 'collectToolCallsFromResponsesJson',
102
- 'resolveFinishReasonJson',
103
- 'captureReqInboundResponsesContextSnapshotJson',
104
- 'computeQuotaBucketsJson',
105
- 'extractReasoningSegmentsJson',
106
- 'deserializeStopMessageStateJson',
107
- 'detectProviderResponseShapeJson',
108
- 'extractClockReminderDirectivesJson',
109
- 'extractContextLengthDiagnosticsJson',
110
- 'encodeMetadataPassthroughJson',
111
- 'prepareGeminiToolsForBridgeJson',
112
- 'buildGeminiToolsFromBridgeJson',
113
- 'pickResponsesPersistedFieldsJson',
114
- 'convertResponsesOutputToInputItemsJson',
115
- 'extractAntigravityGeminiSessionIdJson',
116
- 'ensureBridgeOutputFieldsJson',
117
- 'lookupAntigravityPinnedAliasForSessionIdJson',
118
- 'unpinAntigravitySessionAliasForSessionIdJson',
119
- 'cacheAntigravitySessionSignatureJson',
120
- 'getAntigravityRequestSessionMetaJson',
121
- 'resetAntigravitySignatureCachesJson',
122
- 'coerceClientHeadersJson',
123
- 'extractSessionIdentifiersJson',
124
- 'extractTargetModelIdJson',
125
- 'extractClockScheduleDirectiveTextPartsJson',
126
- 'extractSseWrapperErrorJson',
127
- 'extractMetadataPassthroughJson',
128
- 'extractJsonToolCallsFromTextJson',
129
- 'extractXmlToolCallsFromTextJson',
130
- 'extractSimpleXmlToolsFromTextJson',
131
- 'extractParameterXmlToolsFromTextJson',
132
- 'extractInvokeToolsFromTextJson',
133
- 'extractToolNamespaceXmlBlocksFromTextJson',
134
- 'extractApplyPatchCallsFromTextJson',
135
- 'extractBareExecCommandFromTextJson',
136
- 'extractExecuteBlocksFromTextJson',
137
- 'extractExploredListDirectoryCallsFromTextJson',
138
- 'extractQwenToolCallTokensFromTextJson',
139
- 'extractAdapterContextMetadataFieldsJson',
140
- 'evaluateResponsesHostPolicyJson',
141
- 'enforceChatBudgetJson',
142
- 'resolveBudgetForModelJson',
143
- 'finalizeGovernedRequestJson',
144
- 'governResponseJson',
145
- 'governToolNameResponseJson',
146
- 'findLastUserMessageIndexJson',
147
- 'injectContinueExecutionDirectiveJson',
148
- 'injectTimeTagIntoMessagesJson',
149
- 'injectMcpToolsForChatJson',
150
- 'injectMcpToolsForResponsesJson',
151
- 'mapOpenaiChatToChatJson',
152
- 'mapOpenaiChatFromChatJson',
153
- 'isStopMessageStateActiveJson',
154
- 'isContextLengthExceededSignalJson',
155
- 'isCompactionRequestJson',
156
- 'isShellLikeToolNameTokenJson',
157
- 'looksLikeJsonStreamPrefixJson',
158
- 'mapResumeToolOutputsDetailedJson',
159
- 'mergeContextToolOutputsJson',
160
- 'mergeToolCallsJson',
161
- 'mergeGovernanceSummaryIntoMetadataJson',
162
- 'findHeaderValueJson',
163
- 'normalizeAliasMapJson',
164
- 'normalizeMessageReasoningToolsJson',
165
- 'normalizeOpenaiMessageJson',
166
- 'normalizeOpenaiChatMessagesJson',
167
- 'normalizeOpenaiToolJson',
168
- 'normalizeOpenaiToolCallJson',
169
- 'normalizeChatResponseReasoningToolsJson',
170
- 'normalizeBridgeToolCallIdsJson',
171
- 'normalizeChatMessageContentJson',
172
- 'validateResponsePayloadJson',
173
- 'normalizeResponsePayloadJson',
174
- 'applyResponseBlacklistJson',
175
- 'normalizeToolCallIdsJson',
176
- 'normalizeResponsesToolCallIdsJson',
177
- 'resolveToolCallIdStyleJson',
178
- 'stripInternalToolingMetadataJson',
179
- 'enforceLmstudioResponsesFcToolCallIdsJson',
180
- 'applyRequestRulesJson',
181
- 'normalizeArgsBySchemaJson',
182
- 'normalizeToolsJson',
183
- 'normalizeFunctionCallIdJson',
184
- 'normalizeFunctionCallOutputIdJson',
185
- 'normalizeHeaderKeyJson',
186
- 'normalizeHubEndpointJson',
187
- 'normalizeOutputContentPartJson',
188
- 'normalizeToolSessionMessagesJson',
189
- 'updateToolSessionHistoryJson',
190
- 'normalizeContextCaptureLabelJson',
191
- 'normalizeSnapshotStagePayloadJson',
192
- 'normalizeContextToolsJson',
193
- 'normalizeDueInjectTextJson',
194
- 'normalizeProviderProtocolTokenJson',
195
- 'normalizeResponsesCallIdJson',
196
- 'normalizeMessageContentPartsJson',
197
- 'normalizeShellLikeToolCallsBeforeGovernanceJson',
198
- 'normalizeToolCallIdStyleCandidateJson',
199
- 'parseClockScheduleDirectiveCandidateJson',
200
- 'parseLenientJsonishJson',
201
- 'parseJsonObjectCandidateJson',
202
- 'parseProviderKeyJson',
203
- 'parseRoutingInstructionKindsJson',
204
- 'parseStopMessageInstructionJson',
205
- 'pinAliasQueueJson',
206
- 'planChatClockOperationsJson',
207
- 'planChatServertoolOrchestrationBundleJson',
208
- 'planChatWebSearchOperationsJson',
209
- 'planContinueExecutionOperationsJson',
210
- 'resolveAliasSelectionStrategyJson',
211
- 'resolveBridgePolicyJson',
212
- 'resolveBridgePolicyActionsJson',
213
- 'resolveAliasMapFromRespSemanticsJson',
214
- 'resolveClientInjectReadyJson',
215
- 'resolveClientToolsRawJson',
216
- 'resolveClientToolsRawFromRespSemanticsJson',
217
- 'resolveClockReminderFlowPlanJson',
218
- 'resolveClockConfigJson',
219
- 'resolveClockSessionScopeJson',
220
- 'resolveClockTimeTagFallbackLineJson',
221
- 'resolveCompatProfileJson',
222
- 'resolveHasActiveStopMessageForContinueExecutionJson',
223
- 'resolveHasInstructionRequestedPassthroughJson',
224
- 'resolveHubClientProtocolJson',
225
- 'resolveHubProtocolSpecJson',
226
- 'resolveHubProtocolAllowlistsJson',
227
- 'resolveOutboundStreamIntentJson',
228
- 'resolveProviderProtocolJson',
229
- 'resolveHubPolicyOverrideJson',
230
- 'resolveHubShadowCompareConfigJson',
231
- 'resolveApplyPatchToolModeFromToolsJson',
232
- 'resolveActiveProcessModeJson',
233
- 'resolveStopMessageRouterMetadataJson',
234
- 'resolveGovernanceContextJson',
235
- 'resolveStopMessageSessionScopeJson',
236
- 'VirtualRouterEngineProxy',
237
- 'ensureProtocolStateJson',
238
- 'getProtocolStateJson',
239
- 'readRuntimeMetadataJson',
240
- 'resolveDefaultToolGovernanceRulesJson',
241
- 'ensureRuntimeMetadataJson',
242
- 'cloneRuntimeMetadataJson',
243
- 'applyReqInboundSemanticLiftJson',
244
- 'pickHeaderJson',
245
- 'resolveReqOutboundContextMergePlanJson',
246
- 'runReqOutboundStage3CompatJson',
247
- 'runHubPipelineJson',
248
- 'findMappableSemanticsKeysJson',
249
- 'deriveToolCallKeyJson',
250
- 'extractToolCallsFromReasoningTextJson',
251
- 'mapReasoningContentToResponsesOutputJson',
252
- 'validateToolArgumentsJson',
253
- 'repairToolCallsJson',
254
- 'isImagePathJson',
255
- 'resolveServerToolFollowupSnapshotJson',
256
- 'resolveSseStreamModeJson',
257
- 'resolveSseProtocolFromMetadataJson',
258
- 'repairArgumentsToStringJsonishJson',
259
- 'runBridgeActionPipelineJson',
260
- 'sanitizeChatCompletionLikeJson',
261
- 'sanitizeFormatEnvelopeJson',
262
- 'sanitizeReasoningTaggedTextJson',
263
- 'ensureBridgeInstructionsJson',
264
- 'sanitizeResponsesFunctionNameJson',
265
- 'shouldRecordSnapshotsJson',
266
- 'writeSnapshotViaHooksJson',
267
- 'selectToolCallIdStyleJson',
268
- 'serializeStopMessageStateJson',
269
- 'shouldAttachReqOutboundContextSnapshotJson',
270
- 'shouldReserveClockDueReminderJson',
271
- 'shouldRunHubChatProcessJson',
272
- 'splitAntigravityTargetsJson',
273
- 'stripOrphanFunctionCallsTagJson',
274
- 'stripClockClearDirectiveTextJson',
275
- 'stripChatProcessHistoricalImagesJson',
276
- 'stripPrivateFieldsJson',
277
- 'cleanRoutingInstructionMarkersJson'
35
+ "analyzeChatProcessMediaJson",
36
+ "analyzeChatWebSearchIntentJson",
37
+ "extractWebSearchSemanticsHintJson",
38
+ "extractOutputSegmentsJson",
39
+ "analyzeContinueExecutionInjectionJson",
40
+ "analyzePendingToolSyncJson",
41
+ "appendToolParseDiagnosticTextJson",
42
+ "injectToolParseDiagnosticsJson",
43
+ "applyReqProcessToolGovernanceJson",
44
+ "applyHubOperationsJson",
45
+ "applyReqProcessRouteSelectionJson",
46
+ "applyReqOutboundContextSnapshotJson",
47
+ "applyClaudeThinkingToolSchemaCompatJson",
48
+ "applyOutboundStreamPreferenceJson",
49
+ "applyTargetMetadataJson",
50
+ "applyTargetToSubjectJson",
51
+ "applyStopMessageInstructionJson",
52
+ "attachPassthroughProviderInputAuditJson",
53
+ "augmentContextSnapshotJson",
54
+ "annotatePassthroughGovernanceSkipJson",
55
+ "buildAnthropicToolAliasMapJson",
56
+ "buildOpenaiChatFromAnthropicJson",
57
+ "buildAnthropicFromOpenaiChatJson",
58
+ "buildAnthropicResponseFromChatJson",
59
+ "buildChatNodeResultMetadataJson",
60
+ "buildProcessedRequestFromChatResponseJson",
61
+ "applyChatProcessedRequestJson",
62
+ "buildChatProcessContextMetadataJson",
63
+ "buildChatProcessedDescriptorJson",
64
+ "applyClientPassthroughPatchJson",
65
+ "applyGovernedControlOperationsJson",
66
+ "applyGovernedMergeRequestJson",
67
+ "buildClockMarkerScheduleMessagesJson",
68
+ "buildClockReminderMessagesJson",
69
+ "buildClockReminderMetadataJson",
70
+ "buildProviderProtocolErrorJson",
71
+ "buildFormatRequestJson",
72
+ "buildClockStandardToolAppendOperationsJson",
73
+ "buildClockToolAppendOperationsJson",
74
+ "buildResponsesPayloadFromChatJson",
75
+ "buildBridgeHistoryJson",
76
+ "normalizeBridgeHistorySeedJson",
77
+ "resolveResponsesBridgeToolsJson",
78
+ "resolveResponsesRequestBridgeDecisionsJson",
79
+ "filterBridgeInputForUpstreamJson",
80
+ "prepareResponsesRequestEnvelopeJson",
81
+ "appendLocalImageBlockOnLatestUserInputJson",
82
+ "applyBridgeNormalizeHistoryJson",
83
+ "applyBridgeCaptureToolResultsJson",
84
+ "applyBridgeNormalizeToolIdentifiersJson",
85
+ "applyBridgeEnsureToolPlaceholdersJson",
86
+ "convertBridgeInputToChatMessagesJson",
87
+ "coerceBridgeRoleJson",
88
+ "harvestToolsJson",
89
+ "serializeToolArgumentsJson",
90
+ "pruneChatRequestPayloadJson",
91
+ "enforceToolCallIdStyleJson",
92
+ "transformToolCallIdJson",
93
+ "createToolCallIdTransformerJson",
94
+ "extractToolCallIdJson",
95
+ "normalizeIdValueJson",
96
+ "extractStreamingToolCallsJson",
97
+ "createStreamingToolExtractorStateJson",
98
+ "resetStreamingToolExtractorStateJson",
99
+ "feedStreamingToolExtractorJson",
100
+ "chunkStringJson",
101
+ "flattenByCommaJson",
102
+ "packShellArgsJson",
103
+ "splitCommandStringJson",
104
+ "repairFindMetaJson",
105
+ "removeTrailingUnsignedThinkingBlocksJson",
106
+ "filterInvalidThinkingBlocksJson",
107
+ "sanitizeThinkingBlockJson",
108
+ "hasValidThoughtSignatureJson",
109
+ "serializeToolOutputJson",
110
+ "ensureMessagesArrayJson",
111
+ "normalizeReasoningInChatPayloadJson",
112
+ "normalizeReasoningInResponsesPayloadJson",
113
+ "normalizeReasoningInGeminiPayloadJson",
114
+ "normalizeReasoningInAnthropicPayloadJson",
115
+ "normalizeReasoningInOpenAIPayloadJson",
116
+ "buildContinueExecutionOperationsJson",
117
+ "buildDueReminderUserMessageJson",
118
+ "buildGovernedFilterPayloadJson",
119
+ "buildPassthroughAuditJson",
120
+ "buildGuardedClockScheduleItemJson",
121
+ "buildImageAttachmentMetadataJson",
122
+ "buildReviewOperationsJson",
123
+ "buildWebSearchToolAppendOperationsJson",
124
+ "clampResponsesInputItemIdJson",
125
+ "castGovernedToolsJson",
126
+ "collectToolOutputsJson",
127
+ "buildReqInboundToolOutputSnapshotJson",
128
+ "mapBridgeToolsToChatJson",
129
+ "mapOpenaiChatToChatJson",
130
+ "mapOpenaiChatFromChatJson",
131
+ "mapChatToolsToBridgeJson",
132
+ "bridgeToolToChatDefinitionJson",
133
+ "chatToolToBridgeDefinitionJson",
134
+ "mapBridgeToolsToChatWithOptionsJson",
135
+ "mapChatToolsToBridgeWithOptionsJson",
136
+ "collectToolCallsFromResponsesJson",
137
+ "resolveFinishReasonJson",
138
+ "buildChatResponseFromResponsesJson",
139
+ "captureReqInboundResponsesContextSnapshotJson",
140
+ "computeQuotaBucketsJson",
141
+ "extractReasoningSegmentsJson",
142
+ "deserializeStopMessageStateJson",
143
+ "detectProviderResponseShapeJson",
144
+ "extractClockReminderDirectivesJson",
145
+ "extractContextLengthDiagnosticsJson",
146
+ "encodeMetadataPassthroughJson",
147
+ "prepareGeminiToolsForBridgeJson",
148
+ "buildGeminiToolsFromBridgeJson",
149
+ "pickResponsesPersistedFieldsJson",
150
+ "convertResponsesOutputToInputItemsJson",
151
+ "prepareResponsesConversationEntryJson",
152
+ "resumeResponsesConversationPayloadJson",
153
+ "extractAntigravityGeminiSessionIdJson",
154
+ "ensureBridgeOutputFieldsJson",
155
+ "lookupAntigravityPinnedAliasForSessionIdJson",
156
+ "unpinAntigravitySessionAliasForSessionIdJson",
157
+ "cacheAntigravitySessionSignatureJson",
158
+ "getAntigravityRequestSessionMetaJson",
159
+ "resetAntigravitySignatureCachesJson",
160
+ "coerceClientHeadersJson",
161
+ "extractSessionIdentifiersJson",
162
+ "extractTargetModelIdJson",
163
+ "extractClockScheduleDirectiveTextPartsJson",
164
+ "extractSseWrapperErrorJson",
165
+ "extractMetadataPassthroughJson",
166
+ "extractJsonToolCallsFromTextJson",
167
+ "extractXmlToolCallsFromTextJson",
168
+ "extractSimpleXmlToolsFromTextJson",
169
+ "extractParameterXmlToolsFromTextJson",
170
+ "extractInvokeToolsFromTextJson",
171
+ "extractToolNamespaceXmlBlocksFromTextJson",
172
+ "extractApplyPatchCallsFromTextJson",
173
+ "extractBareExecCommandFromTextJson",
174
+ "extractExecuteBlocksFromTextJson",
175
+ "extractExploredListDirectoryCallsFromTextJson",
176
+ "extractQwenToolCallTokensFromTextJson",
177
+ "extractAdapterContextMetadataFieldsJson",
178
+ "evaluateResponsesHostPolicyJson",
179
+ "enforceChatBudgetJson",
180
+ "resolveBudgetForModelJson",
181
+ "finalizeGovernedRequestJson",
182
+ "governResponseJson",
183
+ "governToolNameResponseJson",
184
+ "findLastUserMessageIndexJson",
185
+ "injectContinueExecutionDirectiveJson",
186
+ "injectTimeTagIntoMessagesJson",
187
+ "injectMcpToolsForChatJson",
188
+ "injectMcpToolsForResponsesJson",
189
+ "mapOpenaiChatToChatJson",
190
+ "mapOpenaiChatFromChatJson",
191
+ "isStopMessageStateActiveJson",
192
+ "isContextLengthExceededSignalJson",
193
+ "isCompactionRequestJson",
194
+ "isShellLikeToolNameTokenJson",
195
+ "looksLikeJsonStreamPrefixJson",
196
+ "mapResumeToolOutputsDetailedJson",
197
+ "mergeContextToolOutputsJson",
198
+ "mergeToolCallsJson",
199
+ "mergeGovernanceSummaryIntoMetadataJson",
200
+ "findHeaderValueJson",
201
+ "normalizeAliasMapJson",
202
+ "normalizeMessageReasoningToolsJson",
203
+ "normalizeOpenaiMessageJson",
204
+ "normalizeOpenaiChatMessagesJson",
205
+ "normalizeOpenaiToolJson",
206
+ "normalizeOpenaiToolCallJson",
207
+ "normalizeChatResponseReasoningToolsJson",
208
+ "normalizeBridgeToolCallIdsJson",
209
+ "normalizeChatMessageContentJson",
210
+ "validateResponsePayloadJson",
211
+ "normalizeResponsePayloadJson",
212
+ "applyResponseBlacklistJson",
213
+ "normalizeToolCallIdsJson",
214
+ "normalizeResponsesToolCallIdsJson",
215
+ "resolveToolCallIdStyleJson",
216
+ "stripInternalToolingMetadataJson",
217
+ "enforceLmstudioResponsesFcToolCallIdsJson",
218
+ "applyRequestRulesJson",
219
+ "applyAnthropicClaudeCodeUserIdJson",
220
+ "applyGeminiWebSearchRequestCompatJson",
221
+ "prepareAntigravityThoughtSignatureForGeminiRequestJson",
222
+ "applyIflowToolTextFallbackJson",
223
+ "applyToolTextRequestGuidanceJson",
224
+ "applyUniversalShapeRequestFilterJson",
225
+ "applyUniversalShapeResponseFilterJson",
226
+ "runOpenaiOpenaiRequestCodecJson",
227
+ "runOpenaiOpenaiResponseCodecJson",
228
+ "runResponsesOpenaiRequestCodecJson",
229
+ "runResponsesOpenaiResponseCodecJson",
230
+ "runGeminiOpenaiRequestCodecJson",
231
+ "runGeminiOpenaiResponseCodecJson",
232
+ "runGeminiFromOpenaiChatCodecJson",
233
+ "normalizeArgsBySchemaJson",
234
+ "normalizeToolsJson",
235
+ "normalizeFunctionCallIdJson",
236
+ "normalizeFunctionCallOutputIdJson",
237
+ "normalizeHeaderKeyJson",
238
+ "normalizeHubEndpointJson",
239
+ "normalizeOutputContentPartJson",
240
+ "normalizeToolSessionMessagesJson",
241
+ "updateToolSessionHistoryJson",
242
+ "normalizeContextCaptureLabelJson",
243
+ "normalizeSnapshotStagePayloadJson",
244
+ "normalizeContextToolsJson",
245
+ "normalizeDueInjectTextJson",
246
+ "normalizeProviderProtocolTokenJson",
247
+ "normalizeResponsesCallIdJson",
248
+ "normalizeMessageContentPartsJson",
249
+ "normalizeShellLikeToolCallsBeforeGovernanceJson",
250
+ "normalizeToolCallIdStyleCandidateJson",
251
+ "parseClockScheduleDirectiveCandidateJson",
252
+ "parseLenientJsonishJson",
253
+ "parseJsonObjectCandidateJson",
254
+ "parseProviderKeyJson",
255
+ "parseRoutingInstructionKindsJson",
256
+ "parseRoutingInstructionsJson",
257
+ "parseStopMessageInstructionJson",
258
+ "pinAliasQueueJson",
259
+ "planChatClockOperationsJson",
260
+ "planChatServertoolOrchestrationBundleJson",
261
+ "planChatWebSearchOperationsJson",
262
+ "planContinueExecutionOperationsJson",
263
+ "resolveAliasSelectionStrategyJson",
264
+ "resolveBridgePolicyJson",
265
+ "resolveBridgePolicyActionsJson",
266
+ "resolveAliasMapFromRespSemanticsJson",
267
+ "resolveClientInjectReadyJson",
268
+ "resolveClientToolsRawJson",
269
+ "resolveClientToolsRawFromRespSemanticsJson",
270
+ "resolveClockReminderFlowPlanJson",
271
+ "resolveClockConfigJson",
272
+ "resolveClockSessionScopeJson",
273
+ "resolveClockTimeTagFallbackLineJson",
274
+ "resolveCompatProfileJson",
275
+ "resolveHasActiveStopMessageForContinueExecutionJson",
276
+ "resolveHasInstructionRequestedPassthroughJson",
277
+ "resolveHubClientProtocolJson",
278
+ "resolveHubProtocolSpecJson",
279
+ "resolveHubProtocolAllowlistsJson",
280
+ "resolveOutboundStreamIntentJson",
281
+ "resolveProviderProtocolJson",
282
+ "resolveHubPolicyOverrideJson",
283
+ "resolveHubShadowCompareConfigJson",
284
+ "resolveApplyPatchToolModeFromToolsJson",
285
+ "resolveActiveProcessModeJson",
286
+ "resolveStopMessageRouterMetadataJson",
287
+ "resolveGovernanceContextJson",
288
+ "resolveStopMessageSessionScopeJson",
289
+ "VirtualRouterEngineProxy",
290
+ "ensureProtocolStateJson",
291
+ "getProtocolStateJson",
292
+ "readRuntimeMetadataJson",
293
+ "resolveDefaultToolGovernanceRulesJson",
294
+ "ensureRuntimeMetadataJson",
295
+ "cloneRuntimeMetadataJson",
296
+ "applyReqInboundSemanticLiftJson",
297
+ "pickHeaderJson",
298
+ "resolveReqOutboundContextMergePlanJson",
299
+ "runReqOutboundStage3CompatJson",
300
+ "runHubPipelineJson",
301
+ "findMappableSemanticsKeysJson",
302
+ "deriveToolCallKeyJson",
303
+ "extractToolCallsFromReasoningTextJson",
304
+ "mapReasoningContentToResponsesOutputJson",
305
+ "validateToolArgumentsJson",
306
+ "repairToolCallsJson",
307
+ "isImagePathJson",
308
+ "resolveServerToolFollowupSnapshotJson",
309
+ "resolveSseStreamModeJson",
310
+ "resolveSseProtocolFromMetadataJson",
311
+ "repairArgumentsToStringJsonishJson",
312
+ "runBridgeActionPipelineJson",
313
+ "sanitizeChatCompletionLikeJson",
314
+ "sanitizeFormatEnvelopeJson",
315
+ "sanitizeReasoningTaggedTextJson",
316
+ "ensureBridgeInstructionsJson",
317
+ "sanitizeResponsesFunctionNameJson",
318
+ "shouldRecordSnapshotsJson",
319
+ "writeSnapshotViaHooksJson",
320
+ "selectToolCallIdStyleJson",
321
+ "serializeStopMessageStateJson",
322
+ "shouldAttachReqOutboundContextSnapshotJson",
323
+ "shouldReserveClockDueReminderJson",
324
+ "shouldRunHubChatProcessJson",
325
+ "splitAntigravityTargetsJson",
326
+ "stripOrphanFunctionCallsTagJson",
327
+ "stripClockClearDirectiveTextJson",
328
+ "stripChatProcessHistoricalImagesJson",
329
+ "stripPrivateFieldsJson",
330
+ "cleanRoutingInstructionMarkersJson",
278
331
  ];
279
332
  function resolvePackageRoot(startDir) {
280
333
  let current = startDir;
281
334
  for (let i = 0; i < 10; i += 1) {
282
- if (fs.existsSync(path.join(current, 'package.json'))) {
335
+ if (fs.existsSync(path.join(current, "package.json"))) {
283
336
  return current;
284
337
  }
285
338
  const parent = path.dirname(current);
@@ -288,39 +341,49 @@ function resolvePackageRoot(startDir) {
288
341
  }
289
342
  current = parent;
290
343
  }
291
- return path.resolve(startDir, '../../../../');
344
+ return path.resolve(startDir, "../../../../");
292
345
  }
293
346
  function readNativePathFromEnv() {
294
- const raw = String(process.env.ROUTECODEX_LLMS_ROUTER_NATIVE_PATH || process.env.RCC_LLMS_ROUTER_NATIVE_PATH || '').trim();
347
+ const raw = String(process.env.ROUTECODEX_LLMS_ROUTER_NATIVE_PATH ||
348
+ process.env.RCC_LLMS_ROUTER_NATIVE_PATH ||
349
+ "").trim();
295
350
  return raw || undefined;
296
351
  }
297
352
  function buildNativeBindingCacheKey(envPath) {
298
353
  if (!envPath) {
299
- return 'auto';
354
+ return "auto";
300
355
  }
301
- const resolved = path.isAbsolute(envPath) ? envPath : path.resolve(process.cwd(), envPath);
356
+ const resolved = path.isAbsolute(envPath)
357
+ ? envPath
358
+ : path.resolve(process.cwd(), envPath);
302
359
  return `env:${resolved}`;
303
360
  }
304
361
  function resolveLoadPathForNode(resolvedPath) {
305
362
  const ext = path.extname(resolvedPath).toLowerCase();
306
- if (!ext || ext === '.node') {
363
+ if (!ext || ext === ".node") {
307
364
  return resolvedPath;
308
365
  }
309
- if (ext !== '.dylib' && ext !== '.so' && ext !== '.dll') {
366
+ if (ext !== ".dylib" && ext !== ".so" && ext !== ".dll") {
310
367
  return resolvedPath;
311
368
  }
312
- return resolvedPath.replace(/\.(dylib|so|dll)$/i, '.node');
369
+ return resolvedPath.replace(/\.(dylib|so|dll)$/i, ".node");
313
370
  }
314
371
  function tryRequireFromPath(modulePath, options) {
315
372
  try {
316
- const resolved = path.isAbsolute(modulePath) ? modulePath : path.resolve(process.cwd(), modulePath);
373
+ const resolved = path.isAbsolute(modulePath)
374
+ ? modulePath
375
+ : path.resolve(process.cwd(), modulePath);
317
376
  const loadPath = resolveLoadPathForNode(resolved);
318
- const loaded = require(loadPath);
319
- if (!loaded || typeof loaded !== 'object') {
377
+ const loaded = nodeRequire(loadPath);
378
+ if (!loaded || typeof loaded !== "object") {
320
379
  return null;
321
380
  }
322
- if (options?.requireComplete !== false && !hasCompleteNativeBinding(loaded, REQUIRED_NATIVE_EXPORTS)) {
323
- return null;
381
+ if (options?.requireComplete !== false &&
382
+ !hasCompleteNativeBinding(loaded, REQUIRED_NATIVE_EXPORTS)) {
383
+ // Do not reject an already-loadable native binding here.
384
+ // Capability-level wrappers still fail fast for any missing export,
385
+ // while this avoids false negatives during startup/import on some Node/NAPI path combinations.
386
+ return loaded;
324
387
  }
325
388
  return loaded;
326
389
  }
@@ -328,11 +391,34 @@ function tryRequireFromPath(modulePath, options) {
328
391
  return null;
329
392
  }
330
393
  }
394
+ function dedupePaths(paths) {
395
+ const seen = new Set();
396
+ const out = [];
397
+ for (const candidate of paths) {
398
+ const normalized = path.normalize(candidate);
399
+ if (seen.has(normalized)) {
400
+ continue;
401
+ }
402
+ seen.add(normalized);
403
+ out.push(candidate);
404
+ }
405
+ return out;
406
+ }
407
+ function getModuleRelativeNativeCandidates() {
408
+ const loaderDir = path.dirname(loaderModulePath);
409
+ return dedupePaths([
410
+ path.resolve(loaderDir, "../../../../rust-core/target/release/router_hotpath_napi.node"),
411
+ path.resolve(loaderDir, "../../../../rust-core/target/debug/router_hotpath_napi.node"),
412
+ path.resolve(loaderDir, "../../../native/router_hotpath_napi.node"),
413
+ ]);
414
+ }
331
415
  function getWorkspaceNativeCandidates() {
332
- return ['release', 'debug'].map((mode) => path.join(workspaceRoot, 'rust-core', 'target', mode, 'router_hotpath_napi.node'));
416
+ return dedupePaths(["release", "debug"].map((mode) => path.join(workspaceRoot, "rust-core", "target", mode, "router_hotpath_napi.node")));
333
417
  }
334
418
  function getPackagedNativeCandidates() {
335
- return [path.join(workspaceRoot, 'dist', 'native', 'router_hotpath_napi.node')];
419
+ return dedupePaths([
420
+ path.join(workspaceRoot, "dist", "native", "router_hotpath_napi.node"),
421
+ ]);
336
422
  }
337
423
  export function loadNativeRouterHotpathBinding() {
338
424
  const envPath = readNativePathFromEnv();
@@ -349,14 +435,11 @@ export function loadNativeRouterHotpathBinding() {
349
435
  if (cachedBinding)
350
436
  return cachedBinding;
351
437
  }
352
- for (const candidate of getWorkspaceNativeCandidates()) {
353
- const loaded = tryRequireFromPath(candidate);
354
- if (loaded) {
355
- cachedBinding = loaded;
356
- return cachedBinding;
357
- }
358
- }
359
- for (const candidate of getPackagedNativeCandidates()) {
438
+ for (const candidate of [
439
+ ...getModuleRelativeNativeCandidates(),
440
+ ...getWorkspaceNativeCandidates(),
441
+ ...getPackagedNativeCandidates(),
442
+ ]) {
360
443
  const loaded = tryRequireFromPath(candidate);
361
444
  if (loaded) {
362
445
  cachedBinding = loaded;
@@ -371,6 +454,8 @@ export function resolveNativeModuleUrlFromEnv() {
371
454
  if (!modulePath) {
372
455
  return undefined;
373
456
  }
374
- const normalized = path.isAbsolute(modulePath) ? modulePath : path.resolve(process.cwd(), modulePath);
457
+ const normalized = path.isAbsolute(modulePath)
458
+ ? modulePath
459
+ : path.resolve(process.cwd(), modulePath);
375
460
  return pathToFileURL(normalized).href;
376
461
  }