@jsonstudio/llms 0.6.3685 → 0.6.3686

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 (63) hide show
  1. package/dist/conversion/compat/actions/antigravity-thought-signature-cache.js +2 -22
  2. package/dist/conversion/compat/actions/deepseek-web-response.js +7 -0
  3. package/dist/conversion/compat/actions/field-mapping.js +153 -2
  4. package/dist/conversion/compat/actions/lmstudio-responses-input-stringify.js +104 -3
  5. package/dist/conversion/hub/node-support.js +1 -1
  6. package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +1 -9
  7. package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +28 -35
  8. package/dist/conversion/hub/pipeline/hub-pipeline.js +121 -197
  9. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.d.ts +4 -4
  10. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.js +37 -20
  11. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.d.ts +7 -6
  12. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.js +41 -69
  13. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.d.ts +0 -3
  14. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.js +1 -2
  15. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-factories.js +0 -2
  16. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +0 -1
  17. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.d.ts +2 -3
  18. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.js +5 -18
  19. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.d.ts +2 -1
  20. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.js +16 -0
  21. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.d.ts +1 -1
  22. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.js +52 -27
  23. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.d.ts +0 -1
  24. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.js +1 -1
  25. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.d.ts +1 -1
  26. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.js +5 -9
  27. package/dist/conversion/hub/process/chat-process-continue-execution.js +3 -0
  28. package/dist/conversion/hub/process/chat-process-media.d.ts +2 -1
  29. package/dist/conversion/hub/process/chat-process-media.js +63 -9
  30. package/dist/conversion/hub/process/chat-process-session-usage.d.ts +6 -24
  31. package/dist/conversion/hub/process/chat-process-session-usage.js +101 -200
  32. package/dist/conversion/hub/response/provider-response.js +13 -13
  33. package/dist/conversion/hub/types/chat-envelope.d.ts +0 -1
  34. package/dist/conversion/pipeline/codecs/v2/openai-openai-pipeline.js +4 -0
  35. package/dist/conversion/responses/responses-openai-bridge.d.ts +0 -1
  36. package/dist/conversion/responses/responses-openai-bridge.js +34 -28
  37. package/dist/conversion/shared/anthropic-message-utils.js +1 -14
  38. package/dist/conversion/shared/reasoning-normalizer.js +22 -41
  39. package/dist/conversion/shared/responses-tool-utils.js +2 -3
  40. package/dist/conversion/shared/tool-governor.js +4 -2
  41. package/dist/native/router_hotpath_napi.node +0 -0
  42. package/dist/router/virtual-router/engine/routing-state/store.js +2 -21
  43. package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.d.ts +0 -1
  44. package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.js +0 -1
  45. package/dist/router/virtual-router/engine-selection/native-compat-action-semantics.d.ts +0 -3
  46. package/dist/router/virtual-router/engine-selection/native-compat-action-semantics.js +0 -72
  47. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.d.ts +1 -1
  48. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js +1 -1
  49. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.d.ts +2 -2
  50. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js +96 -80
  51. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.d.ts +1 -0
  52. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.js +29 -0
  53. package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +2 -6
  54. package/dist/router/virtual-router/engine.js +6 -9
  55. package/dist/router/virtual-router/routing-instructions/state.js +27 -37
  56. package/dist/router/virtual-router/routing-instructions/types.d.ts +4 -6
  57. package/dist/router/virtual-router/token-estimator.js +0 -21
  58. package/dist/servertool/handlers/stop-message-auto.js +1 -11
  59. package/dist/tools/apply-patch/execution-capturer.d.ts +1 -1
  60. package/dist/tools/apply-patch/execution-capturer.js +2 -1
  61. package/dist/tools/apply-patch/regression-capturer.js +1 -2
  62. package/dist/tools/tool-registry.js +2 -1
  63. package/package.json +1 -1
@@ -1,9 +1,11 @@
1
- import { failNativeRequired, isNativeDisabledByEnv } from './native-router-hotpath-policy.js';
2
- import { loadNativeRouterHotpathBindingForInternalUse } from './native-router-hotpath.js';
1
+ import { failNativeRequired, isNativeDisabledByEnv, } from "./native-router-hotpath-policy.js";
2
+ import { loadNativeRouterHotpathBindingForInternalUse } from "./native-router-hotpath.js";
3
3
  function readNativeFunction(name) {
4
4
  const binding = loadNativeRouterHotpathBindingForInternalUse();
5
5
  const fn = binding?.[name];
6
- return typeof fn === 'function' ? fn : null;
6
+ return typeof fn === "function"
7
+ ? fn
8
+ : null;
7
9
  }
8
10
  function safeStringify(value) {
9
11
  try {
@@ -16,7 +18,7 @@ function safeStringify(value) {
16
18
  function parseRecord(raw) {
17
19
  try {
18
20
  const parsed = JSON.parse(raw);
19
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
21
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
20
22
  return null;
21
23
  }
22
24
  return parsed;
@@ -28,27 +30,31 @@ function parseRecord(raw) {
28
30
  function parseFormatEnvelopePayload(raw, direction, fallbackProtocol, fallbackPayload) {
29
31
  try {
30
32
  const parsed = JSON.parse(raw);
31
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
33
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
32
34
  return null;
33
35
  }
34
36
  const row = parsed;
35
37
  const envelope = row.envelope;
36
- if (!envelope || typeof envelope !== 'object' || Array.isArray(envelope)) {
38
+ if (!envelope || typeof envelope !== "object" || Array.isArray(envelope)) {
37
39
  return null;
38
40
  }
39
41
  const env = envelope;
40
- const protocol = typeof env.format === 'string' && env.format.trim().length
42
+ const protocol = typeof env.format === "string" && env.format.trim().length
41
43
  ? env.format.trim()
42
44
  : fallbackProtocol;
43
- const payload = env.payload && typeof env.payload === 'object' && !Array.isArray(env.payload)
45
+ const payload = env.payload &&
46
+ typeof env.payload === "object" &&
47
+ !Array.isArray(env.payload)
44
48
  ? env.payload
45
49
  : fallbackPayload;
46
50
  const out = {
47
51
  protocol,
48
52
  direction,
49
- payload
53
+ payload,
50
54
  };
51
- if (env.metadata && typeof env.metadata === 'object' && !Array.isArray(env.metadata)) {
55
+ if (env.metadata &&
56
+ typeof env.metadata === "object" &&
57
+ !Array.isArray(env.metadata)) {
52
58
  out.meta = env.metadata;
53
59
  }
54
60
  return out;
@@ -63,7 +69,7 @@ function parseOptionalString(raw) {
63
69
  if (parsed === null) {
64
70
  return undefined;
65
71
  }
66
- if (typeof parsed !== 'string') {
72
+ if (typeof parsed !== "string") {
67
73
  return null;
68
74
  }
69
75
  const trimmed = parsed.trim();
@@ -76,149 +82,149 @@ function parseOptionalString(raw) {
76
82
  function parseBoolean(raw) {
77
83
  try {
78
84
  const parsed = JSON.parse(raw);
79
- return typeof parsed === 'boolean' ? parsed : null;
85
+ return typeof parsed === "boolean" ? parsed : null;
80
86
  }
81
87
  catch {
82
88
  return null;
83
89
  }
84
90
  }
85
91
  export function sanitizeFormatEnvelopeWithNative(candidate) {
86
- const capability = 'sanitizeFormatEnvelopeJson';
92
+ const capability = "sanitizeFormatEnvelopeJson";
87
93
  const fail = (reason) => failNativeRequired(capability, reason);
88
94
  if (isNativeDisabledByEnv()) {
89
- return fail('native disabled');
95
+ return fail("native disabled");
90
96
  }
91
- const fn = readNativeFunction('sanitizeFormatEnvelopeJson');
97
+ const fn = readNativeFunction("sanitizeFormatEnvelopeJson");
92
98
  if (!fn) {
93
99
  return fail();
94
100
  }
95
101
  const candidateJson = safeStringify(candidate);
96
102
  if (!candidateJson) {
97
- return fail('json stringify failed');
103
+ return fail("json stringify failed");
98
104
  }
99
105
  try {
100
106
  const raw = fn(candidateJson);
101
- if (typeof raw !== 'string' || !raw) {
102
- return fail('empty result');
107
+ if (typeof raw !== "string" || !raw) {
108
+ return fail("empty result");
103
109
  }
104
110
  const parsed = parseRecord(raw);
105
- return parsed ?? fail('invalid payload');
111
+ return parsed ?? fail("invalid payload");
106
112
  }
107
113
  catch (error) {
108
- const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
114
+ const reason = error instanceof Error ? error.message : String(error ?? "unknown");
109
115
  return fail(reason);
110
116
  }
111
117
  }
112
118
  export function sanitizeChatCompletionLikeWithNative(candidate) {
113
- const capability = 'sanitizeChatCompletionLikeJson';
119
+ const capability = "sanitizeChatCompletionLikeJson";
114
120
  const fail = (reason) => failNativeRequired(capability, reason);
115
121
  if (isNativeDisabledByEnv()) {
116
- return fail('native disabled');
122
+ return fail("native disabled");
117
123
  }
118
- const fn = readNativeFunction('sanitizeChatCompletionLikeJson');
124
+ const fn = readNativeFunction("sanitizeChatCompletionLikeJson");
119
125
  if (!fn) {
120
126
  return fail();
121
127
  }
122
128
  const candidateJson = safeStringify(candidate);
123
129
  if (!candidateJson) {
124
- return fail('json stringify failed');
130
+ return fail("json stringify failed");
125
131
  }
126
132
  try {
127
133
  const raw = fn(candidateJson);
128
- if (typeof raw !== 'string' || !raw) {
129
- return fail('empty result');
134
+ if (typeof raw !== "string" || !raw) {
135
+ return fail("empty result");
130
136
  }
131
137
  const parsed = parseRecord(raw);
132
- return parsed ?? fail('invalid payload');
138
+ return parsed ?? fail("invalid payload");
133
139
  }
134
140
  catch (error) {
135
- const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
141
+ const reason = error instanceof Error ? error.message : String(error ?? "unknown");
136
142
  return fail(reason);
137
143
  }
138
144
  }
139
145
  export function stripPrivateFieldsWithNative(payload) {
140
- const capability = 'stripPrivateFieldsJson';
146
+ const capability = "stripPrivateFieldsJson";
141
147
  const fail = (reason) => failNativeRequired(capability, reason);
142
148
  if (isNativeDisabledByEnv()) {
143
- return fail('native disabled');
149
+ return fail("native disabled");
144
150
  }
145
- const fn = readNativeFunction('stripPrivateFieldsJson');
151
+ const fn = readNativeFunction("stripPrivateFieldsJson");
146
152
  if (!fn) {
147
153
  return fail();
148
154
  }
149
155
  const payloadJson = safeStringify(payload);
150
156
  if (!payloadJson) {
151
- return fail('json stringify failed');
157
+ return fail("json stringify failed");
152
158
  }
153
159
  try {
154
160
  const raw = fn(payloadJson);
155
- if (typeof raw !== 'string' || !raw) {
156
- return fail('empty result');
161
+ if (typeof raw !== "string" || !raw) {
162
+ return fail("empty result");
157
163
  }
158
164
  const parsed = parseRecord(raw);
159
- return parsed ?? fail('invalid payload');
165
+ return parsed ?? fail("invalid payload");
160
166
  }
161
167
  catch (error) {
162
- const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
168
+ const reason = error instanceof Error ? error.message : String(error ?? "unknown");
163
169
  return fail(reason);
164
170
  }
165
171
  }
166
172
  export function resolveCompatProfileWithNative(adapterContext, explicitProfile) {
167
- const capability = 'resolveCompatProfileJson';
173
+ const capability = "resolveCompatProfileJson";
168
174
  const fail = (reason) => failNativeRequired(capability, reason);
169
175
  if (isNativeDisabledByEnv()) {
170
- return fail('native disabled');
176
+ return fail("native disabled");
171
177
  }
172
- const fn = readNativeFunction('resolveCompatProfileJson');
178
+ const fn = readNativeFunction("resolveCompatProfileJson");
173
179
  if (!fn) {
174
180
  return fail();
175
181
  }
176
182
  const adapterContextJson = safeStringify(adapterContext);
177
183
  const explicitJson = safeStringify(explicitProfile ?? null);
178
184
  if (!adapterContextJson || !explicitJson) {
179
- return fail('json stringify failed');
185
+ return fail("json stringify failed");
180
186
  }
181
187
  try {
182
188
  const raw = fn(adapterContextJson, explicitJson);
183
- if (typeof raw !== 'string' || !raw) {
184
- return fail('empty result');
189
+ if (typeof raw !== "string" || !raw) {
190
+ return fail("empty result");
185
191
  }
186
192
  const parsed = parseOptionalString(raw);
187
- return parsed === null ? fail('invalid payload') : parsed;
193
+ return parsed === null ? fail("invalid payload") : parsed;
188
194
  }
189
195
  catch (error) {
190
- const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
196
+ const reason = error instanceof Error ? error.message : String(error ?? "unknown");
191
197
  return fail(reason);
192
198
  }
193
199
  }
194
200
  export function resolveSseStreamModeWithNative(wantsStream, clientProtocol) {
195
- const capability = 'resolveSseStreamModeJson';
201
+ const capability = "resolveSseStreamModeJson";
196
202
  const fail = (reason) => failNativeRequired(capability, reason);
197
203
  if (isNativeDisabledByEnv()) {
198
- return fail('native disabled');
204
+ return fail("native disabled");
199
205
  }
200
- const fn = readNativeFunction('resolveSseStreamModeJson');
206
+ const fn = readNativeFunction("resolveSseStreamModeJson");
201
207
  if (!fn) {
202
208
  return fail();
203
209
  }
204
210
  try {
205
- const raw = fn(Boolean(wantsStream), String(clientProtocol || ''));
206
- if (typeof raw !== 'string' || !raw) {
207
- return fail('empty result');
211
+ const raw = fn(Boolean(wantsStream), String(clientProtocol || ""));
212
+ if (typeof raw !== "string" || !raw) {
213
+ return fail("empty result");
208
214
  }
209
215
  const parsed = parseBoolean(raw);
210
- return parsed === null ? fail('invalid payload') : parsed;
216
+ return parsed === null ? fail("invalid payload") : parsed;
211
217
  }
212
218
  catch (error) {
213
- const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
219
+ const reason = error instanceof Error ? error.message : String(error ?? "unknown");
214
220
  return fail(reason);
215
221
  }
216
222
  }
217
223
  export function parseReqInboundFormatEnvelopeWithNative(input) {
218
- const capability = 'parseFormatEnvelopeJson';
224
+ const capability = "parseFormatEnvelopeJson";
219
225
  const fail = (reason) => failNativeRequired(capability, reason);
220
226
  if (isNativeDisabledByEnv()) {
221
- return fail('native disabled');
227
+ return fail("native disabled");
222
228
  }
223
229
  const fn = readNativeFunction(capability);
224
230
  if (!fn) {
@@ -226,26 +232,33 @@ export function parseReqInboundFormatEnvelopeWithNative(input) {
226
232
  }
227
233
  const inputJson = safeStringify(input);
228
234
  if (!inputJson) {
229
- return fail('json stringify failed');
235
+ return fail("json stringify failed");
230
236
  }
231
237
  try {
232
238
  const raw = fn(inputJson);
233
- if (typeof raw !== 'string' || !raw) {
234
- return fail('empty result');
239
+ if (typeof raw !== "string" || !raw) {
240
+ return fail("empty result");
235
241
  }
236
- const parsed = parseFormatEnvelopePayload(raw, 'request', input.protocol, input.rawRequest);
237
- return parsed ?? fail('invalid payload');
242
+ const parsed = JSON.parse(raw);
243
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
244
+ return fail("invalid envelope structure");
245
+ }
246
+ const result = parsed;
247
+ if (!result.envelope || typeof result.envelope !== "object") {
248
+ return fail("missing envelope in result");
249
+ }
250
+ return result.envelope;
238
251
  }
239
252
  catch (error) {
240
- const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
253
+ const reason = error instanceof Error ? error.message : String(error ?? "unknown");
241
254
  return fail(reason);
242
255
  }
243
256
  }
244
257
  export function parseRespInboundFormatEnvelopeWithNative(input) {
245
- const capability = 'parseRespFormatEnvelopeJson';
258
+ const capability = "parseRespFormatEnvelopeJson";
246
259
  const fail = (reason) => failNativeRequired(capability, reason);
247
260
  if (isNativeDisabledByEnv()) {
248
- return fail('native disabled');
261
+ return fail("native disabled");
249
262
  }
250
263
  const fn = readNativeFunction(capability);
251
264
  if (!fn) {
@@ -253,26 +266,26 @@ export function parseRespInboundFormatEnvelopeWithNative(input) {
253
266
  }
254
267
  const inputJson = safeStringify(input);
255
268
  if (!inputJson) {
256
- return fail('json stringify failed');
269
+ return fail("json stringify failed");
257
270
  }
258
271
  try {
259
272
  const raw = fn(inputJson);
260
- if (typeof raw !== 'string' || !raw) {
261
- return fail('empty result');
273
+ if (typeof raw !== "string" || !raw) {
274
+ return fail("empty result");
262
275
  }
263
- const parsed = parseFormatEnvelopePayload(raw, 'response', input.protocol, input.payload);
264
- return parsed ?? fail('invalid payload');
276
+ const parsed = parseFormatEnvelopePayload(raw, "response", input.protocol, input.payload);
277
+ return parsed ?? fail("invalid payload");
265
278
  }
266
279
  catch (error) {
267
- const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
280
+ const reason = error instanceof Error ? error.message : String(error ?? "unknown");
268
281
  return fail(reason);
269
282
  }
270
283
  }
271
284
  export function validateChatEnvelopeWithNative(chatEnvelope, options) {
272
- const capability = 'validateChatEnvelopeJson';
285
+ const capability = "validateChatEnvelopeJson";
273
286
  const fail = (reason) => failNativeRequired(capability, reason);
274
287
  if (isNativeDisabledByEnv()) {
275
- return fail('native disabled');
288
+ return fail("native disabled");
276
289
  }
277
290
  const fn = readNativeFunction(capability);
278
291
  if (!fn) {
@@ -280,35 +293,38 @@ export function validateChatEnvelopeWithNative(chatEnvelope, options) {
280
293
  }
281
294
  const envelopeJson = safeStringify(chatEnvelope);
282
295
  if (!envelopeJson) {
283
- return fail('json stringify failed');
296
+ return fail("json stringify failed");
284
297
  }
285
- const isChatEnvelopeValidationError = (message) => typeof message === 'string' && message.includes('ChatEnvelopeValidationError(');
298
+ const isChatEnvelopeValidationError = (message) => typeof message === "string" &&
299
+ message.includes("ChatEnvelopeValidationError(");
286
300
  try {
287
- const raw = fn(envelopeJson, String(options.stage || ''), String(options.direction || ''), options.source);
301
+ const raw = fn(envelopeJson, String(options.stage || ""), String(options.direction || ""), options.source);
288
302
  const nativeErrorMessage = raw instanceof Error
289
303
  ? raw.message
290
- : raw && typeof raw === 'object' && 'message' in raw
304
+ : raw &&
305
+ typeof raw === "object" &&
306
+ "message" in raw
291
307
  ? (() => {
292
308
  const candidate = raw.message;
293
- return typeof candidate === 'string' ? candidate : '';
309
+ return typeof candidate === "string" ? candidate : "";
294
310
  })()
295
- : '';
311
+ : "";
296
312
  if (nativeErrorMessage) {
297
313
  if (isChatEnvelopeValidationError(nativeErrorMessage)) {
298
314
  throw new Error(nativeErrorMessage);
299
315
  }
300
316
  return fail(nativeErrorMessage);
301
317
  }
302
- if (typeof raw !== 'string' || !raw) {
303
- return fail('empty result');
318
+ if (typeof raw !== "string" || !raw) {
319
+ return fail("empty result");
304
320
  }
305
321
  const parsed = parseBoolean(raw);
306
322
  if (parsed !== true) {
307
- return fail('invalid payload');
323
+ return fail("invalid payload");
308
324
  }
309
325
  }
310
326
  catch (error) {
311
- const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
327
+ const reason = error instanceof Error ? error.message : String(error ?? "unknown");
312
328
  if (isChatEnvelopeValidationError(reason)) {
313
329
  throw error instanceof Error ? error : new Error(reason);
314
330
  }
@@ -19,3 +19,4 @@ export declare function mergeContextToolOutputsWithNative(existing: unknown, sna
19
19
  name?: string;
20
20
  }> | undefined;
21
21
  export declare function normalizeContextToolsWithNative(snapshot: Record<string, unknown>): unknown[] | undefined;
22
+ export declare function selectToolCallIdStyleWithNative(adapterContext: unknown, snapshot: Record<string, unknown>, current: string | undefined): string | undefined;
@@ -395,3 +395,32 @@ export function normalizeContextToolsWithNative(snapshot) {
395
395
  return fail(reason);
396
396
  }
397
397
  }
398
+ export function selectToolCallIdStyleWithNative(adapterContext, snapshot, current) {
399
+ const capability = 'selectToolCallIdStyleJson';
400
+ const fail = (reason) => failNativeRequired(capability, reason);
401
+ if (isNativeDisabledByEnv()) {
402
+ return fail('native disabled');
403
+ }
404
+ const fn = readNativeFunction('selectToolCallIdStyleJson');
405
+ if (!fn) {
406
+ return fail();
407
+ }
408
+ const adapterContextJson = safeStringify(adapterContext);
409
+ const snapshotJson = safeStringify(snapshot);
410
+ const currentJson = safeStringify(current ?? null);
411
+ if (!adapterContextJson || !snapshotJson || !currentJson) {
412
+ return fail('json stringify failed');
413
+ }
414
+ try {
415
+ const raw = fn(adapterContextJson, snapshotJson, currentJson);
416
+ if (typeof raw !== 'string' || !raw) {
417
+ return fail('empty result');
418
+ }
419
+ const parsed = parseStyle(raw);
420
+ return parsed === null ? fail('invalid payload') : parsed;
421
+ }
422
+ catch (error) {
423
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
424
+ return fail(reason);
425
+ }
426
+ }
@@ -4,9 +4,7 @@ import { pathToFileURL } from "node:url";
4
4
  import { createRequire } from "node:module";
5
5
  import { hasCompleteNativeBinding } from "./native-router-hotpath-policy.js";
6
6
  function resolveLoaderModulePath() {
7
- if (typeof __filename === "string" &&
8
- __filename.length > 0 &&
9
- __filename !== "[stdin]") {
7
+ if (typeof __filename === "string" && __filename.length > 0) {
10
8
  return __filename;
11
9
  }
12
10
  const stack = String(new Error().stack || "");
@@ -218,8 +216,6 @@ const REQUIRED_NATIVE_EXPORTS = [
218
216
  "stripInternalToolingMetadataJson",
219
217
  "enforceLmstudioResponsesFcToolCallIdsJson",
220
218
  "applyRequestRulesJson",
221
- "applyFieldMappingsJson",
222
- "stringifyLmstudioResponsesInputJson",
223
219
  "applyAnthropicClaudeCodeUserIdJson",
224
220
  "applyGeminiWebSearchRequestCompatJson",
225
221
  "prepareAntigravityThoughtSignatureForGeminiRequestJson",
@@ -230,7 +226,6 @@ const REQUIRED_NATIVE_EXPORTS = [
230
226
  "runOpenaiOpenaiRequestCodecJson",
231
227
  "runOpenaiOpenaiResponseCodecJson",
232
228
  "runResponsesOpenaiRequestCodecJson",
233
- "runResponsesOpenaiReqInboundSemanticMapJson",
234
229
  "runResponsesOpenaiResponseCodecJson",
235
230
  "runGeminiOpenaiRequestCodecJson",
236
231
  "runGeminiOpenaiResponseCodecJson",
@@ -322,6 +317,7 @@ const REQUIRED_NATIVE_EXPORTS = [
322
317
  "sanitizeResponsesFunctionNameJson",
323
318
  "shouldRecordSnapshotsJson",
324
319
  "writeSnapshotViaHooksJson",
320
+ "selectToolCallIdStyleJson",
325
321
  "serializeStopMessageStateJson",
326
322
  "shouldAttachReqOutboundContextSnapshotJson",
327
323
  "shouldReserveClockDueReminderJson",
@@ -233,6 +233,11 @@ function buildRoutingInstructionParseLog(request, metadata) {
233
233
  }
234
234
  const latest = getLatestUserMessage(messages);
235
235
  const latestText = latest ? extractMessageText(latest).trim() : '';
236
+ const latestHasMarker = /<\*\*[\s\S]*?\*\*>/.test(latestText);
237
+ const hasStopKeyword = /stopmessage/i.test(latestText);
238
+ if (!hasStopKeyword && !latestHasMarker) {
239
+ return null;
240
+ }
236
241
  const parsedKinds = parseRoutingInstructionKindsWithNative(request);
237
242
  const stopMessageTypes = parsedKinds.filter((type) => type === 'stopMessageSet' || type === 'stopMessageMode' || type === 'stopMessageClear');
238
243
  const scopedTypes = parsedKinds.filter((type) => type === 'stopMessageSet' ||
@@ -240,20 +245,12 @@ function buildRoutingInstructionParseLog(request, metadata) {
240
245
  type === 'stopMessageClear' ||
241
246
  type === 'preCommandSet' ||
242
247
  type === 'preCommandClear');
243
- const markerDetected = messages.some((message) => {
244
- if (!message || typeof message !== 'object') {
245
- return false;
246
- }
247
- const record = message;
248
- return record.role === 'user' && typeof record.content === 'string' && /<\*\*[\s\S]*?\*\*>/.test(record.content);
249
- });
250
- const hasStopKeyword = /stopmessage/i.test(latestText);
251
248
  if (!hasStopKeyword && stopMessageTypes.length === 0 && scopedTypes.length === 0) {
252
249
  return null;
253
250
  }
254
251
  return {
255
252
  requestId: metadata.requestId || 'n/a',
256
- markerDetected,
253
+ markerDetected: latestHasMarker,
257
254
  preview: latestText.replace(/\s+/g, ' ').slice(0, 120),
258
255
  stopMessageTypes,
259
256
  scopedTypes,
@@ -28,12 +28,10 @@ export function applyRoutingInstructions(instructions, currentState) {
28
28
  preCommandSource: currentState.preCommandSource,
29
29
  preCommandScriptPath: currentState.preCommandScriptPath,
30
30
  preCommandUpdatedAt: currentState.preCommandUpdatedAt,
31
- chatProcessInputTokens: currentState.chatProcessInputTokens,
32
- chatProcessMessageCount: currentState.chatProcessMessageCount,
33
- chatProcessToolsSignature: currentState.chatProcessToolsSignature,
34
- chatProcessParametersSignature: currentState.chatProcessParametersSignature,
35
- chatProcessBoundarySignature: currentState.chatProcessBoundarySignature,
36
- chatProcessUpdatedAt: currentState.chatProcessUpdatedAt
31
+ chatProcessLastTotalTokens: currentState.chatProcessLastTotalTokens,
32
+ chatProcessLastInputTokens: currentState.chatProcessLastInputTokens,
33
+ chatProcessLastMessageCount: currentState.chatProcessLastMessageCount,
34
+ chatProcessLastUpdatedAt: currentState.chatProcessLastUpdatedAt
37
35
  };
38
36
  let allowReset = false;
39
37
  let disableReset = false;
@@ -191,20 +189,20 @@ export function serializeRoutingInstructionState(state) {
191
189
  provider,
192
190
  models: Array.from(models)
193
191
  })),
194
- ...(typeof state.chatProcessInputTokens === 'number' && Number.isFinite(state.chatProcessInputTokens)
195
- ? { chatProcessInputTokens: state.chatProcessInputTokens }
192
+ ...serializeStopMessageState(state),
193
+ ...serializePreCommandState(state),
194
+ ...(typeof state.chatProcessLastTotalTokens === 'number'
195
+ ? { chatProcessLastTotalTokens: state.chatProcessLastTotalTokens }
196
196
  : {}),
197
- ...(typeof state.chatProcessMessageCount === 'number' && Number.isFinite(state.chatProcessMessageCount)
198
- ? { chatProcessMessageCount: state.chatProcessMessageCount }
197
+ ...(typeof state.chatProcessLastInputTokens === 'number'
198
+ ? { chatProcessLastInputTokens: state.chatProcessLastInputTokens }
199
199
  : {}),
200
- ...(state.chatProcessToolsSignature ? { chatProcessToolsSignature: state.chatProcessToolsSignature } : {}),
201
- ...(state.chatProcessParametersSignature ? { chatProcessParametersSignature: state.chatProcessParametersSignature } : {}),
202
- ...(state.chatProcessBoundarySignature ? { chatProcessBoundarySignature: state.chatProcessBoundarySignature } : {}),
203
- ...(typeof state.chatProcessUpdatedAt === 'number' && Number.isFinite(state.chatProcessUpdatedAt)
204
- ? { chatProcessUpdatedAt: state.chatProcessUpdatedAt }
200
+ ...(typeof state.chatProcessLastMessageCount === 'number'
201
+ ? { chatProcessLastMessageCount: state.chatProcessLastMessageCount }
205
202
  : {}),
206
- ...serializeStopMessageState(state),
207
- ...serializePreCommandState(state)
203
+ ...(typeof state.chatProcessLastUpdatedAt === 'number'
204
+ ? { chatProcessLastUpdatedAt: state.chatProcessLastUpdatedAt }
205
+ : {})
208
206
  };
209
207
  }
210
208
  export function deserializeRoutingInstructionState(data) {
@@ -227,12 +225,10 @@ export function deserializeRoutingInstructionState(data) {
227
225
  preCommandSource: undefined,
228
226
  preCommandScriptPath: undefined,
229
227
  preCommandUpdatedAt: undefined,
230
- chatProcessInputTokens: undefined,
231
- chatProcessMessageCount: undefined,
232
- chatProcessToolsSignature: undefined,
233
- chatProcessParametersSignature: undefined,
234
- chatProcessBoundarySignature: undefined,
235
- chatProcessUpdatedAt: undefined
228
+ chatProcessLastTotalTokens: undefined,
229
+ chatProcessLastInputTokens: undefined,
230
+ chatProcessLastMessageCount: undefined,
231
+ chatProcessLastUpdatedAt: undefined
236
232
  };
237
233
  if (data.forcedTarget && typeof data.forcedTarget === 'object') {
238
234
  state.forcedTarget = data.forcedTarget;
@@ -265,23 +261,17 @@ export function deserializeRoutingInstructionState(data) {
265
261
  }
266
262
  deserializeStopMessageState(data, state);
267
263
  deserializePreCommandState(data, state);
268
- if (typeof data.chatProcessInputTokens === 'number' && Number.isFinite(data.chatProcessInputTokens)) {
269
- state.chatProcessInputTokens = data.chatProcessInputTokens;
270
- }
271
- if (typeof data.chatProcessMessageCount === 'number' && Number.isFinite(data.chatProcessMessageCount)) {
272
- state.chatProcessMessageCount = data.chatProcessMessageCount;
273
- }
274
- if (typeof data.chatProcessToolsSignature === 'string' && data.chatProcessToolsSignature.trim()) {
275
- state.chatProcessToolsSignature = data.chatProcessToolsSignature.trim();
264
+ if (typeof data.chatProcessLastTotalTokens === 'number' && Number.isFinite(data.chatProcessLastTotalTokens)) {
265
+ state.chatProcessLastTotalTokens = Math.max(0, Math.round(data.chatProcessLastTotalTokens));
276
266
  }
277
- if (typeof data.chatProcessParametersSignature === 'string' && data.chatProcessParametersSignature.trim()) {
278
- state.chatProcessParametersSignature = data.chatProcessParametersSignature.trim();
267
+ if (typeof data.chatProcessLastInputTokens === 'number' && Number.isFinite(data.chatProcessLastInputTokens)) {
268
+ state.chatProcessLastInputTokens = Math.max(0, Math.round(data.chatProcessLastInputTokens));
279
269
  }
280
- if (typeof data.chatProcessBoundarySignature === 'string' && data.chatProcessBoundarySignature.trim()) {
281
- state.chatProcessBoundarySignature = data.chatProcessBoundarySignature.trim();
270
+ if (typeof data.chatProcessLastMessageCount === 'number' && Number.isFinite(data.chatProcessLastMessageCount)) {
271
+ state.chatProcessLastMessageCount = Math.max(0, Math.round(data.chatProcessLastMessageCount));
282
272
  }
283
- if (typeof data.chatProcessUpdatedAt === 'number' && Number.isFinite(data.chatProcessUpdatedAt)) {
284
- state.chatProcessUpdatedAt = data.chatProcessUpdatedAt;
273
+ if (typeof data.chatProcessLastUpdatedAt === 'number' && Number.isFinite(data.chatProcessLastUpdatedAt)) {
274
+ state.chatProcessLastUpdatedAt = Math.max(0, Math.round(data.chatProcessLastUpdatedAt));
285
275
  }
286
276
  return state;
287
277
  }
@@ -67,10 +67,8 @@ export interface RoutingInstructionState {
67
67
  preCommandSource?: string;
68
68
  preCommandScriptPath?: string;
69
69
  preCommandUpdatedAt?: number;
70
- chatProcessInputTokens?: number;
71
- chatProcessMessageCount?: number;
72
- chatProcessToolsSignature?: string;
73
- chatProcessParametersSignature?: string;
74
- chatProcessBoundarySignature?: string;
75
- chatProcessUpdatedAt?: number;
70
+ chatProcessLastTotalTokens?: number;
71
+ chatProcessLastInputTokens?: number;
72
+ chatProcessLastMessageCount?: number;
73
+ chatProcessLastUpdatedAt?: number;
76
74
  }
@@ -1,9 +1,5 @@
1
1
  import { countRequestTokens } from './token-counter.js';
2
2
  export function computeRequestTokens(request, fallbackText) {
3
- const metadataEstimate = readEstimatedTokensFromMetadata(request);
4
- if (metadataEstimate !== undefined) {
5
- return metadataEstimate;
6
- }
7
3
  try {
8
4
  return countRequestTokens(request);
9
5
  }
@@ -11,23 +7,6 @@ export function computeRequestTokens(request, fallbackText) {
11
7
  return fallbackEstimateTokens(fallbackText, request.messages?.length ?? 0);
12
8
  }
13
9
  }
14
- function readEstimatedTokensFromMetadata(request) {
15
- const metadata = request?.metadata;
16
- if (!metadata || typeof metadata !== 'object') {
17
- return undefined;
18
- }
19
- const candidates = [
20
- metadata.estimatedInputTokens,
21
- metadata.estimatedTokens,
22
- metadata.estimated_tokens
23
- ];
24
- for (const candidate of candidates) {
25
- if (typeof candidate === 'number' && Number.isFinite(candidate) && candidate > 0) {
26
- return Math.max(1, Math.round(candidate));
27
- }
28
- }
29
- return undefined;
30
- }
31
10
  function fallbackEstimateTokens(text, messageCount) {
32
11
  if (!text) {
33
12
  return Math.max(32, Math.max(messageCount, 1) * 16);