@jsonstudio/llms 0.6.3271 → 0.6.3379

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 (49) hide show
  1. package/dist/conversion/bridge-message-utils.d.ts +4 -4
  2. package/dist/conversion/bridge-message-utils.js +28 -538
  3. package/dist/conversion/compat/actions/anthropic-claude-code-system-prompt.js +38 -0
  4. package/dist/conversion/compat/profiles/responses-crs.json +15 -0
  5. package/dist/conversion/hub/operation-table/semantic-mappers/chat-mapper.js +16 -5
  6. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage1_tool_governance/index.js +1 -6
  7. package/dist/conversion/hub/response/response-runtime.js +14 -6
  8. package/dist/conversion/responses/responses-openai-bridge/response-payload.js +11 -11
  9. package/dist/conversion/shared/anthropic-message-utils.js +2 -12
  10. package/dist/conversion/shared/chat-request-filters.js +2 -61
  11. package/dist/conversion/shared/reasoning-mapping.js +3 -0
  12. package/dist/conversion/shared/reasoning-normalizer.d.ts +1 -0
  13. package/dist/conversion/shared/reasoning-normalizer.js +35 -388
  14. package/dist/conversion/shared/reasoning-tool-normalizer.js +8 -15
  15. package/dist/conversion/shared/reasoning-utils.js +13 -35
  16. package/dist/conversion/shared/responses-tool-utils.d.ts +1 -1
  17. package/dist/conversion/shared/responses-tool-utils.js +63 -65
  18. package/dist/conversion/shared/streaming-text-extractor.d.ts +0 -5
  19. package/dist/conversion/shared/streaming-text-extractor.js +18 -111
  20. package/dist/conversion/shared/text-markup-normalizer/normalize.d.ts +1 -1
  21. package/dist/conversion/shared/text-markup-normalizer/normalize.js +3 -91
  22. package/dist/conversion/shared/thought-signature-validator.js +19 -133
  23. package/dist/conversion/shared/tool-argument-repairer.js +16 -19
  24. package/dist/conversion/shared/tool-call-id-manager.d.ts +1 -5
  25. package/dist/conversion/shared/tool-call-id-manager.js +74 -98
  26. package/dist/conversion/shared/tool-harvester.js +19 -382
  27. package/dist/conversion/shared/tool-mapping.d.ts +2 -3
  28. package/dist/conversion/shared/tool-mapping.js +28 -184
  29. package/dist/conversion/shared/tooling.js +20 -151
  30. package/dist/filters/special/response-tool-arguments-stringify.js +9 -1
  31. package/dist/guidance/index.js +2 -2
  32. package/dist/native/router_hotpath_napi.node +0 -0
  33. package/dist/router/virtual-router/engine-legacy/helpers.js +1 -1
  34. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.d.ts +39 -0
  35. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js +196 -0
  36. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.d.ts +1 -0
  37. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js +27 -0
  38. package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +34 -0
  39. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.d.ts +65 -1
  40. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +836 -35
  41. package/dist/router/virtual-router/engine.js +3 -2
  42. package/dist/router/virtual-router/routing-instructions/parse.js +30 -3
  43. package/dist/sse/sse-to-json/builders/anthropic-response-builder.js +28 -3
  44. package/dist/sse/types/anthropic-types.d.ts +3 -1
  45. package/dist/tools/apply-patch/args-normalizer/extract-patch.js +2 -2
  46. package/dist/tools/apply-patch/patch-text/looks-like-patch.js +3 -6
  47. package/dist/tools/apply-patch/patch-text/normalize.js +14 -3
  48. package/dist/tools/tool-registry.js +12 -0
  49. package/package.json +6 -1
@@ -2,7 +2,16 @@
2
2
  * Shared helpers for standard tool normalization (shell packing rules).
3
3
  * The goal is deterministic, minimal shaping so executors succeed consistently.
4
4
  */
5
- import { parseLenientJsonishWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
5
+ import { chunkStringWithNative, flattenByCommaWithNative, packShellArgsWithNative, repairFindMetaWithNative, splitCommandStringWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
6
+ function assertToolingNativeAvailable() {
7
+ if (typeof repairFindMetaWithNative !== 'function' ||
8
+ typeof splitCommandStringWithNative !== 'function' ||
9
+ typeof packShellArgsWithNative !== 'function' ||
10
+ typeof flattenByCommaWithNative !== 'function' ||
11
+ typeof chunkStringWithNative !== 'function') {
12
+ throw new Error('[tooling] native bindings unavailable');
13
+ }
14
+ }
6
15
  // We intentionally do NOT evaluate shell control operators (&&, |, etc.).
7
16
  // Codex CLI executor runs argv directly (execvp-like), not through a shell.
8
17
  // So we avoid wrapping with "bash -lc" and leave such tokens as-is.
@@ -13,103 +22,12 @@ import { parseLenientJsonishWithNative } from '../../router/virtual-router/engin
13
22
  * - escape bare parentheses used in predicates: `(` / `)` → `\(` / `\)`
14
23
  */
15
24
  export function repairFindMeta(script) {
16
- try {
17
- const s = String(script ?? '');
18
- if (!s)
19
- return s;
20
- const hasFind = /(^|\s)find\s/.test(s);
21
- if (!hasFind)
22
- return s;
23
- let out = s;
24
- // Only escape semicolon not already escaped (negative lookbehind)
25
- out = out.replace(/-exec([^;]*?)(?<!\\);/g, (_m, g1) => `-exec${g1} \\;`);
26
- // Collapse multiple backslashes immediately before ; into a single backslash
27
- out = out.replace(/-exec([^;]*?)\\+;/g, (_m, g1) => `-exec${g1} \\;`);
28
- // Escape parentheses only when not already escaped
29
- out = out.replace(/(?<!\\)\(/g, '\\(').replace(/(?<!\\)\)/g, '\\)');
30
- return out;
31
- }
32
- catch {
33
- return script;
34
- }
35
- }
36
- function toStringArray(v) {
37
- if (Array.isArray(v))
38
- return v.map((x) => String(x));
39
- if (typeof v === 'string')
40
- return [v];
41
- if (v == null)
42
- return [];
43
- return [String(v)];
25
+ assertToolingNativeAvailable();
26
+ return repairFindMetaWithNative(script ?? '');
44
27
  }
45
28
  export function splitCommandString(input) {
46
- const s = input.trim();
47
- if (!s)
48
- return [];
49
- try {
50
- if (s.startsWith('{') || s.startsWith('[')) {
51
- const parsed = parseLenientJsonishWithNative(s);
52
- if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
53
- const command = parsed.command;
54
- if (Array.isArray(command)) {
55
- const tokens = command.map((entry) => String(entry ?? '')).map((entry) => entry.trim()).filter(Boolean);
56
- if (tokens.length) {
57
- return tokens;
58
- }
59
- }
60
- }
61
- }
62
- }
63
- catch {
64
- // Keep legacy parser path when native parse returns non-command payload.
65
- }
66
- const out = [];
67
- let cur = '';
68
- let inSingle = false;
69
- let inDouble = false;
70
- for (let i = 0; i < s.length; i++) {
71
- const ch = s[i];
72
- if (inSingle) {
73
- if (ch === "'") {
74
- inSingle = false;
75
- continue;
76
- }
77
- cur += ch;
78
- continue;
79
- }
80
- if (inDouble) {
81
- if (ch === '"') {
82
- inDouble = false;
83
- continue;
84
- }
85
- if (ch === '\\' && i + 1 < s.length) { // simple escape in double quotes
86
- i++;
87
- cur += s[i];
88
- continue;
89
- }
90
- cur += ch;
91
- continue;
92
- }
93
- if (ch === "'") {
94
- inSingle = true;
95
- continue;
96
- }
97
- if (ch === '"') {
98
- inDouble = true;
99
- continue;
100
- }
101
- if (/\s/.test(ch)) {
102
- if (cur) {
103
- out.push(cur);
104
- cur = '';
105
- }
106
- continue;
107
- }
108
- cur += ch;
109
- }
110
- if (cur)
111
- out.push(cur);
112
- return out;
29
+ assertToolingNativeAvailable();
30
+ return splitCommandStringWithNative(input ?? '');
113
31
  }
114
32
  /**
115
33
  * Pack shell arguments per unified rules:
@@ -125,64 +43,15 @@ export function splitCommandString(input) {
125
43
  * - join(rest) uses single-space join without extra quoting
126
44
  */
127
45
  export function packShellArgs(input) {
128
- const out = { ...input };
129
- const cmdRaw = out.command;
130
- const workdir = out.workdir;
131
- // string => split into argv tokens (no shell wrapping)
132
- if (typeof cmdRaw === 'string') {
133
- const tokens = splitCommandString(cmdRaw);
134
- // handle leading cd as cwd switch
135
- if (tokens[0] === 'cd' && typeof tokens[1] === 'string' && tokens[1]) {
136
- const dir = tokens[1];
137
- let rest = tokens.slice(2);
138
- // tolerate common chain operator right after cd
139
- if (rest[0] === '&&' || rest[0] === ';') {
140
- rest = rest.slice(1);
141
- }
142
- if (!workdir)
143
- out.workdir = dir;
144
- out.command = rest.length ? rest : ['pwd'];
145
- return out;
146
- }
147
- out.command = tokens.length ? tokens : ['pwd'];
148
- if (typeof workdir === 'string' && workdir)
149
- out.workdir = workdir;
150
- return out;
151
- }
152
- // array tokens
153
- const tokens = toStringArray(cmdRaw);
154
- if (tokens.length === 0) {
155
- out.command = ['pwd'];
156
- if (typeof workdir === 'string' && workdir)
157
- out.workdir = workdir;
158
- return out;
159
- }
160
- // cd chain for argv input
161
- if (tokens[0] === 'cd' && typeof tokens[1] === 'string' && tokens[1]) {
162
- const dir = tokens[1];
163
- const rest = tokens.slice(2);
164
- if (!workdir)
165
- out.workdir = dir;
166
- out.command = rest.length ? rest : ['pwd'];
167
- return out;
168
- }
169
- // argv straight
170
- out.command = tokens;
171
- if (typeof workdir === 'string' && workdir)
172
- out.workdir = workdir;
173
- return out;
46
+ assertToolingNativeAvailable();
47
+ return packShellArgsWithNative(input);
174
48
  }
175
49
  export function flattenByComma(arr) {
176
- return arr.flatMap((t) => String(t).split(',').map(s => s.trim()).filter(Boolean));
50
+ assertToolingNativeAvailable();
51
+ return flattenByCommaWithNative(arr);
177
52
  }
178
53
  // Helper to chunk a long string into N parts (bounded)
179
54
  export function chunkString(s, minParts = 3, maxParts = 12, targetChunk = 12) {
180
- if (typeof s !== 'string' || !s.length)
181
- return [];
182
- const parts = Math.max(minParts, Math.min(maxParts, Math.ceil(s.length / targetChunk)));
183
- const step = Math.max(1, Math.ceil(s.length / parts));
184
- const out = [];
185
- for (let i = 0; i < s.length; i += step)
186
- out.push(s.slice(i, i + step));
187
- return out;
55
+ assertToolingNativeAvailable();
56
+ return chunkStringWithNative(s, minParts, maxParts, targetChunk);
188
57
  }
@@ -82,7 +82,7 @@ export class ResponseToolArgumentsStringifyFilter {
82
82
  fn.arguments = '{}';
83
83
  }
84
84
  }
85
- else if ((name === 'exec_command' || name === 'shell_command' || name === 'bash') && isObject(parsed)) {
85
+ else if (name === 'exec_command' && isObject(parsed)) {
86
86
  const normalized = normalizeExecCommandArgs(parsed);
87
87
  const next = normalized.ok ? normalized.normalized : parsed;
88
88
  try {
@@ -92,6 +92,14 @@ export class ResponseToolArgumentsStringifyFilter {
92
92
  fn.arguments = '{}';
93
93
  }
94
94
  }
95
+ else if ((name === 'shell_command' || name === 'bash') && isObject(parsed)) {
96
+ try {
97
+ fn.arguments = JSON.stringify(parsed ?? {});
98
+ }
99
+ catch {
100
+ fn.arguments = '{}';
101
+ }
102
+ }
95
103
  else {
96
104
  if (typeof argIn !== 'string') {
97
105
  try {
@@ -67,7 +67,7 @@ function buildApplyPatchGuidanceText() {
67
67
  '*** End Patch',
68
68
  '```',
69
69
  '',
70
- 'Paths must stay relative to the workspace root (no leading "/" or drive letters).'
70
+ 'Paths must be workspace-relative ONLY (no leading "/" or drive letters). Absolute paths will be rejected by the sandbox.'
71
71
  ].join('\n');
72
72
  return { marker, text };
73
73
  }
@@ -127,7 +127,7 @@ function augmentApplyPatch(fn) {
127
127
  const props = params.properties;
128
128
  props.patch = {
129
129
  type: 'string',
130
- description: 'Patch text. Supports "*** Begin Patch" format or GNU unified diff. Paths must be workspace-relative.'
130
+ description: 'Patch text. Supports "*** Begin Patch" format or GNU unified diff. Paths must be workspace-relative (absolute paths are rejected).'
131
131
  };
132
132
  props.input = {
133
133
  type: 'string',
@@ -91,7 +91,7 @@ export function hasLatestUserRoutingInstructionMarker(messages) {
91
91
  continue;
92
92
  }
93
93
  if (message.role !== 'user') {
94
- return false;
94
+ continue;
95
95
  }
96
96
  const content = extractMessageText(message);
97
97
  if (!content) {
@@ -58,6 +58,30 @@ export interface NativeApplyBridgeEnsureToolPlaceholdersOutput {
58
58
  messages: unknown[];
59
59
  toolOutputs?: Array<Record<string, unknown>>;
60
60
  }
61
+ export interface NativeBridgeInputToChatInput {
62
+ input: unknown[];
63
+ tools?: Array<Record<string, unknown>>;
64
+ toolResultFallbackText?: string;
65
+ normalizeFunctionName?: string;
66
+ }
67
+ export interface NativeBridgeInputToChatOutput {
68
+ messages: Array<Record<string, unknown>>;
69
+ }
70
+ export interface NativeCoerceBridgeRoleInput {
71
+ role: unknown;
72
+ }
73
+ export interface NativeSerializeToolArgumentsInput {
74
+ args?: unknown;
75
+ }
76
+ export interface NativeSerializeToolOutputInput {
77
+ output?: unknown;
78
+ }
79
+ export interface NativeEnsureMessagesArrayInput {
80
+ state?: unknown;
81
+ }
82
+ export interface NativeEnsureMessagesArrayOutput {
83
+ messages: Array<Record<string, unknown>>;
84
+ }
61
85
  export interface NativeEnsureBridgeOutputFieldsInput {
62
86
  messages: unknown[];
63
87
  toolFallback?: string;
@@ -137,12 +161,27 @@ export interface NativeNormalizeMessageReasoningToolsOutput {
137
161
  toolCallsAdded: number;
138
162
  cleanedReasoning?: string;
139
163
  }
164
+ export interface NativeHarvestToolsInput {
165
+ signal: Record<string, unknown>;
166
+ context?: Record<string, unknown>;
167
+ }
168
+ export interface NativeHarvestToolsOutput {
169
+ deltaEvents: Array<Record<string, unknown>>;
170
+ normalized?: Record<string, unknown>;
171
+ stats?: Record<string, unknown>;
172
+ }
140
173
  export declare function normalizeBridgeToolCallIdsWithNative(input: NativeBridgeToolCallIdsInput): NativeBridgeToolCallIdsOutput;
141
174
  export declare function applyBridgeNormalizeToolIdentifiersWithNative(input: NativeApplyBridgeNormalizeToolIdentifiersInput): NativeBridgeToolCallIdsOutput;
142
175
  export declare function buildBridgeHistoryWithNative(input: NativeBridgeHistoryInput): NativeBridgeHistoryOutput;
143
176
  export declare function applyBridgeNormalizeHistoryWithNative(input: NativeApplyBridgeNormalizeHistoryInput): NativeApplyBridgeNormalizeHistoryOutput;
144
177
  export declare function applyBridgeCaptureToolResultsWithNative(input: NativeApplyBridgeCaptureToolResultsInput): NativeApplyBridgeCaptureToolResultsOutput;
145
178
  export declare function applyBridgeEnsureToolPlaceholdersWithNative(input: NativeApplyBridgeEnsureToolPlaceholdersInput): NativeApplyBridgeEnsureToolPlaceholdersOutput;
179
+ export declare function convertBridgeInputToChatMessagesWithNative(input: NativeBridgeInputToChatInput): NativeBridgeInputToChatOutput;
180
+ export declare function coerceBridgeRoleWithNative(role: unknown): string;
181
+ export declare function serializeToolOutputWithNative(input: NativeSerializeToolOutputInput): string | null;
182
+ export declare function serializeToolArgumentsWithNative(input: NativeSerializeToolArgumentsInput): string;
183
+ export declare function ensureMessagesArrayWithNative(input: NativeEnsureMessagesArrayInput): NativeEnsureMessagesArrayOutput;
184
+ export declare function harvestToolsWithNative(input: NativeHarvestToolsInput): NativeHarvestToolsOutput;
146
185
  export declare function ensureBridgeOutputFieldsWithNative(input: NativeEnsureBridgeOutputFieldsInput): NativeEnsureBridgeOutputFieldsOutput;
147
186
  export declare function applyBridgeMetadataActionWithNative(input: NativeApplyBridgeMetadataActionInput): NativeApplyBridgeMetadataActionOutput;
148
187
  export declare function applyBridgeReasoningExtractWithNative(input: NativeApplyBridgeReasoningExtractInput): NativeApplyBridgeReasoningExtractOutput;
@@ -38,6 +38,20 @@ function parseOutput(raw) {
38
38
  return null;
39
39
  }
40
40
  }
41
+ function parseEnsureMessagesArrayOutput(raw) {
42
+ try {
43
+ const parsed = JSON.parse(raw);
44
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
45
+ return null;
46
+ }
47
+ const row = parsed;
48
+ const messages = Array.isArray(row.messages) ? row.messages : [];
49
+ return { messages };
50
+ }
51
+ catch {
52
+ return null;
53
+ }
54
+ }
41
55
  function parseBridgeHistoryOutput(raw) {
42
56
  try {
43
57
  const parsed = JSON.parse(raw);
@@ -68,6 +82,14 @@ function parseBridgeHistoryOutput(raw) {
68
82
  return null;
69
83
  }
70
84
  }
85
+ function parseBridgeInputToChatOutput(raw) {
86
+ const parsed = parseRecord(raw);
87
+ if (!parsed || !Array.isArray(parsed.messages)) {
88
+ return null;
89
+ }
90
+ const messages = parsed.messages.filter((entry) => Boolean(entry) && typeof entry === 'object' && !Array.isArray(entry));
91
+ return { messages };
92
+ }
71
93
  function parseBridgeActionState(raw) {
72
94
  try {
73
95
  const parsed = JSON.parse(raw);
@@ -517,6 +539,180 @@ export function applyBridgeEnsureToolPlaceholdersWithNative(input) {
517
539
  return fail(reason);
518
540
  }
519
541
  }
542
+ export function convertBridgeInputToChatMessagesWithNative(input) {
543
+ const capability = 'convertBridgeInputToChatMessagesJson';
544
+ const fail = (reason) => failNativeRequired(capability, reason);
545
+ if (isNativeDisabledByEnv()) {
546
+ return fail('native disabled');
547
+ }
548
+ const fn = readNativeFunction(capability);
549
+ if (!fn) {
550
+ return fail();
551
+ }
552
+ const payloadJson = safeStringify({
553
+ input: input.input,
554
+ tools: input.tools,
555
+ toolResultFallbackText: input.toolResultFallbackText,
556
+ normalizeFunctionName: input.normalizeFunctionName
557
+ });
558
+ if (!payloadJson) {
559
+ return fail('json stringify failed');
560
+ }
561
+ try {
562
+ const raw = fn(payloadJson);
563
+ if (typeof raw !== 'string' || !raw) {
564
+ return fail('empty result');
565
+ }
566
+ const parsed = parseBridgeInputToChatOutput(raw);
567
+ return parsed ?? fail('invalid payload');
568
+ }
569
+ catch (error) {
570
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
571
+ return fail(reason);
572
+ }
573
+ }
574
+ export function coerceBridgeRoleWithNative(role) {
575
+ const capability = 'coerceBridgeRoleJson';
576
+ const fail = (reason) => failNativeRequired(capability, reason);
577
+ if (isNativeDisabledByEnv()) {
578
+ return fail('native disabled');
579
+ }
580
+ const fn = readNativeFunction(capability);
581
+ if (!fn) {
582
+ return fail();
583
+ }
584
+ const payloadJson = safeStringify({ role });
585
+ if (!payloadJson) {
586
+ return fail('json stringify failed');
587
+ }
588
+ try {
589
+ const raw = fn(payloadJson);
590
+ if (typeof raw !== 'string' || !raw) {
591
+ return fail('empty result');
592
+ }
593
+ const parsed = JSON.parse(raw);
594
+ return typeof parsed === 'string' ? parsed : fail('invalid payload');
595
+ }
596
+ catch (error) {
597
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
598
+ return fail(reason);
599
+ }
600
+ }
601
+ export function serializeToolOutputWithNative(input) {
602
+ const capability = 'serializeToolOutputJson';
603
+ const fail = (reason) => failNativeRequired(capability, reason);
604
+ if (isNativeDisabledByEnv()) {
605
+ return fail('native disabled');
606
+ }
607
+ const fn = readNativeFunction(capability);
608
+ if (!fn) {
609
+ return fail();
610
+ }
611
+ const payloadJson = safeStringify({ output: input.output });
612
+ if (!payloadJson) {
613
+ return fail('json stringify failed');
614
+ }
615
+ try {
616
+ const raw = fn(payloadJson);
617
+ if (typeof raw !== 'string') {
618
+ return fail('empty result');
619
+ }
620
+ const parsed = JSON.parse(raw);
621
+ return typeof parsed === 'string' || parsed === null ? parsed : fail('invalid payload');
622
+ }
623
+ catch (error) {
624
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
625
+ return fail(reason);
626
+ }
627
+ }
628
+ export function serializeToolArgumentsWithNative(input) {
629
+ const capability = 'serializeToolArgumentsJson';
630
+ const fail = (reason) => failNativeRequired(capability, reason);
631
+ if (isNativeDisabledByEnv()) {
632
+ return fail('native disabled');
633
+ }
634
+ const fn = readNativeFunction(capability);
635
+ if (!fn) {
636
+ return fail();
637
+ }
638
+ const payloadJson = safeStringify({ args: input.args });
639
+ if (!payloadJson) {
640
+ return fail('json stringify failed');
641
+ }
642
+ try {
643
+ const raw = fn(payloadJson);
644
+ if (typeof raw !== 'string' || !raw) {
645
+ return fail('empty result');
646
+ }
647
+ const parsed = JSON.parse(raw);
648
+ return typeof parsed === 'string' ? parsed : fail('invalid payload');
649
+ }
650
+ catch (error) {
651
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
652
+ return fail(reason);
653
+ }
654
+ }
655
+ export function ensureMessagesArrayWithNative(input) {
656
+ const capability = 'ensureMessagesArrayJson';
657
+ const fail = (reason) => failNativeRequired(capability, reason);
658
+ if (isNativeDisabledByEnv()) {
659
+ return fail('native disabled');
660
+ }
661
+ const fn = readNativeFunction(capability);
662
+ if (!fn) {
663
+ return fail();
664
+ }
665
+ const payloadJson = safeStringify({ state: input.state });
666
+ if (!payloadJson) {
667
+ return fail('json stringify failed');
668
+ }
669
+ try {
670
+ const raw = fn(payloadJson);
671
+ if (typeof raw !== 'string' || !raw) {
672
+ return fail('empty result');
673
+ }
674
+ const parsed = parseEnsureMessagesArrayOutput(raw);
675
+ return parsed ?? fail('invalid payload');
676
+ }
677
+ catch (error) {
678
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
679
+ return fail(reason);
680
+ }
681
+ }
682
+ export function harvestToolsWithNative(input) {
683
+ const capability = 'harvestToolsJson';
684
+ const fail = (reason) => failNativeRequired(capability, reason);
685
+ if (isNativeDisabledByEnv()) {
686
+ return fail('native disabled');
687
+ }
688
+ const fn = readNativeFunction(capability);
689
+ if (!fn) {
690
+ return fail();
691
+ }
692
+ const payloadJson = safeStringify({ signal: input.signal, context: input.context });
693
+ if (!payloadJson) {
694
+ return fail('json stringify failed');
695
+ }
696
+ try {
697
+ const raw = fn(payloadJson);
698
+ if (typeof raw !== 'string' || !raw) {
699
+ return fail('empty result');
700
+ }
701
+ const parsed = JSON.parse(raw);
702
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
703
+ return fail('invalid payload');
704
+ }
705
+ const row = parsed;
706
+ if (!Array.isArray(row.deltaEvents)) {
707
+ return fail('invalid payload');
708
+ }
709
+ return row;
710
+ }
711
+ catch (error) {
712
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
713
+ return fail(reason);
714
+ }
715
+ }
520
716
  export function ensureBridgeOutputFieldsWithNative(input) {
521
717
  const capability = 'ensureBridgeOutputFieldsJson';
522
718
  const fail = (reason) => failNativeRequired(capability, reason);
@@ -13,6 +13,7 @@ export interface NativeReqInboundChatToStandardizedInput {
13
13
  endpoint: string;
14
14
  requestId?: string;
15
15
  }
16
+ export declare function pruneChatRequestPayloadWithNative(payload: Record<string, unknown>, preserveStreamField?: boolean): Record<string, unknown>;
16
17
  export declare function sanitizeReqInboundFormatEnvelopeWithNative<T>(candidate: unknown): T;
17
18
  export declare function mapReqInboundResumeToolOutputsDetailedWithNative(responsesResume: unknown): Array<{
18
19
  tool_call_id: string;
@@ -87,6 +87,33 @@ function replaceRecord(target, source) {
87
87
  }
88
88
  Object.assign(target, source);
89
89
  }
90
+ export function pruneChatRequestPayloadWithNative(payload, preserveStreamField = false) {
91
+ const capability = 'pruneChatRequestPayloadJson';
92
+ const fail = (reason) => failNativeRequired(capability, reason);
93
+ if (isNativeDisabledByEnv()) {
94
+ return fail('native disabled');
95
+ }
96
+ const fn = readNativeFunction(capability);
97
+ if (!fn) {
98
+ return fail();
99
+ }
100
+ const payloadJson = safeStringify({ payload, preserveStreamField });
101
+ if (!payloadJson) {
102
+ return fail('json stringify failed');
103
+ }
104
+ try {
105
+ const raw = fn(payloadJson);
106
+ if (typeof raw !== 'string' || !raw) {
107
+ return fail('empty result');
108
+ }
109
+ const parsed = parseRecord(raw);
110
+ return parsed ?? fail('invalid payload');
111
+ }
112
+ catch (error) {
113
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
114
+ return fail(reason);
115
+ }
116
+ }
90
117
  export function sanitizeReqInboundFormatEnvelopeWithNative(candidate) {
91
118
  return sanitizeFormatEnvelopeWithNative(candidate);
92
119
  }
@@ -51,6 +51,33 @@ const REQUIRED_NATIVE_EXPORTS = [
51
51
  'applyBridgeCaptureToolResultsJson',
52
52
  'applyBridgeNormalizeToolIdentifiersJson',
53
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',
54
81
  'buildContinueExecutionOperationsJson',
55
82
  'buildDueReminderUserMessageJson',
56
83
  'buildGovernedFilterPayloadJson',
@@ -67,8 +94,13 @@ const REQUIRED_NATIVE_EXPORTS = [
67
94
  'mapOpenaiChatToChatJson',
68
95
  'mapOpenaiChatFromChatJson',
69
96
  'mapChatToolsToBridgeJson',
97
+ 'bridgeToolToChatDefinitionJson',
98
+ 'chatToolToBridgeDefinitionJson',
99
+ 'mapBridgeToolsToChatWithOptionsJson',
100
+ 'mapChatToolsToBridgeWithOptionsJson',
70
101
  'captureReqInboundResponsesContextSnapshotJson',
71
102
  'computeQuotaBucketsJson',
103
+ 'extractReasoningSegmentsJson',
72
104
  'deserializeStopMessageStateJson',
73
105
  'detectProviderResponseShapeJson',
74
106
  'extractClockReminderDirectivesJson',
@@ -206,6 +238,8 @@ const REQUIRED_NATIVE_EXPORTS = [
206
238
  'deriveToolCallKeyJson',
207
239
  'extractToolCallsFromReasoningTextJson',
208
240
  'mapReasoningContentToResponsesOutputJson',
241
+ 'validateToolArgumentsJson',
242
+ 'repairToolCallsJson',
209
243
  'isImagePathJson',
210
244
  'resolveServerToolFollowupSnapshotJson',
211
245
  'resolveSseStreamModeJson',