@truefoundry/ai-gateway-sdk 0.0.37 → 0.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/responses/freeformInputDecoder.d.ts +61 -0
- package/dist/adapters/responses/freeformInputDecoder.js +201 -0
- package/dist/adapters/responses/freeformInputDecoder.js.map +1 -0
- package/dist/adapters/responses/requestTransform.d.ts +8 -1
- package/dist/adapters/responses/requestTransform.js +69 -32
- package/dist/adapters/responses/requestTransform.js.map +1 -1
- package/dist/adapters/responses/responseTransform.d.ts +14 -1
- package/dist/adapters/responses/responseTransform.js +43 -16
- package/dist/adapters/responses/responseTransform.js.map +1 -1
- package/dist/adapters/responses/streamTransform.d.ts +14 -0
- package/dist/adapters/responses/streamTransform.js +111 -50
- package/dist/adapters/responses/streamTransform.js.map +1 -1
- package/dist/adapters/responses/toolMapping.d.ts +40 -0
- package/dist/adapters/responses/toolMapping.js +148 -0
- package/dist/adapters/responses/toolMapping.js.map +1 -0
- package/dist/autogen/models.d.ts +9 -15
- package/dist/autogen/schema.json +7 -18
- package/dist/providers/aws-bedrock-mantle/responsesLite.js +2 -15
- package/dist/providers/aws-bedrock-mantle/responsesLite.js.map +1 -1
- package/dist/providers/google-vertex-ai/utils.d.ts +1 -1
- package/dist/types/modelResponses.d.ts +111 -3
- package/dist/utils/responsesTools.d.ts +22 -0
- package/dist/utils/responsesTools.js +55 -0
- package/dist/utils/responsesTools.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streams the `input` string out of a custom tool call's JSON arguments.
|
|
3
|
+
*
|
|
4
|
+
* A custom tool reaches the provider as a function taking `{"input":"<payload>"}`, so the model
|
|
5
|
+
* streams that JSON in arbitrary fragments, while the Responses API wants the raw payload text in
|
|
6
|
+
* `response.custom_tool_call_input.delta`. This decodes the string value as it arrives instead of
|
|
7
|
+
* holding the whole call back.
|
|
8
|
+
*
|
|
9
|
+
* One invariant holds for every input: the final payload is exactly what `push` returned, joined,
|
|
10
|
+
* plus `finish().tail`. Deltas and the final `input` therefore never disagree.
|
|
11
|
+
*
|
|
12
|
+
* - Once `{"input":"` has been seen, the payload is the decoded string. Keys after it are ignored,
|
|
13
|
+
* and an invalid escape is kept literally rather than abandoning the decode.
|
|
14
|
+
* - If that prefix never shows up (bare text, another key first, a non-string value), nothing is
|
|
15
|
+
* decoded incrementally and the raw arguments are the payload, sent whole as the tail.
|
|
16
|
+
* - A high surrogate at the end of a fragment is held back until its low half arrives, so no delta
|
|
17
|
+
* carries half a character.
|
|
18
|
+
*
|
|
19
|
+
* Work per fragment is proportional to the fragment: the undecided prefix is capped, and decoding
|
|
20
|
+
* only ever looks at the unconsumed remainder, never at the whole text received so far.
|
|
21
|
+
*/
|
|
22
|
+
export interface FreeformInputFinish {
|
|
23
|
+
/** The complete payload. Always `emitted + tail`. */
|
|
24
|
+
input: string;
|
|
25
|
+
/** Payload text no `push` has returned yet and that has to go out before `.done`. */
|
|
26
|
+
tail: string;
|
|
27
|
+
/** The `input` string was seen to close, so the payload is known to be whole. */
|
|
28
|
+
closed: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** Work counters, so tests can assert the decoder stays linear without timing anything. */
|
|
31
|
+
export interface FreeformInputDecoderStats {
|
|
32
|
+
/** Characters examined while classifying the prefix (leading whitespace, match windows). */
|
|
33
|
+
prefixScanned: number;
|
|
34
|
+
/** Characters examined while decoding the string value. */
|
|
35
|
+
decodeScanned: number;
|
|
36
|
+
/** Largest amount of text held undecided at once: the prefix buffer plus a split escape. */
|
|
37
|
+
maxBuffered: number;
|
|
38
|
+
}
|
|
39
|
+
export interface FreeformInputDecoder {
|
|
40
|
+
/** Feeds the next fragment of the arguments; returns the payload text newly decoded from it. */
|
|
41
|
+
push(fragment: string): string;
|
|
42
|
+
/** Payload text already returned by `push`. */
|
|
43
|
+
readonly emitted: string;
|
|
44
|
+
readonly stats: FreeformInputDecoderStats;
|
|
45
|
+
finish(): FreeformInputFinish;
|
|
46
|
+
}
|
|
47
|
+
export declare function createFreeformInputDecoder(): FreeformInputDecoder;
|
|
48
|
+
/** Provider finish reasons for output cut off by the token limit. */
|
|
49
|
+
export declare function isTruncatedFinishReason(finishReason: string | null | undefined): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Whether a custom tool call was cut off by the token limit. Only a payload whose `input` string
|
|
52
|
+
* was seen to close is trusted on a truncated finish; bare text or unparseable JSON could end
|
|
53
|
+
* anywhere. Without a truncated finish reason the call stands as it is. The one place both the
|
|
54
|
+
* response and the stream transform decide this.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isTruncatedCustomCall(closed: boolean, finishReason: string | null | undefined): boolean;
|
|
57
|
+
/** The payload of a whole (non-streamed) custom tool call, decoded the way the stream decodes it. */
|
|
58
|
+
export declare function decodeFreeformArguments(args: string): {
|
|
59
|
+
input: string;
|
|
60
|
+
closed: boolean;
|
|
61
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streams the `input` string out of a custom tool call's JSON arguments.
|
|
3
|
+
*
|
|
4
|
+
* A custom tool reaches the provider as a function taking `{"input":"<payload>"}`, so the model
|
|
5
|
+
* streams that JSON in arbitrary fragments, while the Responses API wants the raw payload text in
|
|
6
|
+
* `response.custom_tool_call_input.delta`. This decodes the string value as it arrives instead of
|
|
7
|
+
* holding the whole call back.
|
|
8
|
+
*
|
|
9
|
+
* One invariant holds for every input: the final payload is exactly what `push` returned, joined,
|
|
10
|
+
* plus `finish().tail`. Deltas and the final `input` therefore never disagree.
|
|
11
|
+
*
|
|
12
|
+
* - Once `{"input":"` has been seen, the payload is the decoded string. Keys after it are ignored,
|
|
13
|
+
* and an invalid escape is kept literally rather than abandoning the decode.
|
|
14
|
+
* - If that prefix never shows up (bare text, another key first, a non-string value), nothing is
|
|
15
|
+
* decoded incrementally and the raw arguments are the payload, sent whole as the tail.
|
|
16
|
+
* - A high surrogate at the end of a fragment is held back until its low half arrives, so no delta
|
|
17
|
+
* carries half a character.
|
|
18
|
+
*
|
|
19
|
+
* Work per fragment is proportional to the fragment: the undecided prefix is capped, and decoding
|
|
20
|
+
* only ever looks at the unconsumed remainder, never at the whole text received so far.
|
|
21
|
+
*/
|
|
22
|
+
const PREFIX = '{"input":"';
|
|
23
|
+
const PREFIX_PATTERN = /^\{\s*"input"\s*:\s*"/;
|
|
24
|
+
/**
|
|
25
|
+
* The wrapper `{ "input" : "` has to be complete within this many characters of the first non-space
|
|
26
|
+
* character, or the arguments are raw. Leading whitespace does not count, and neither does how the
|
|
27
|
+
* text was split into fragments: the same arguments always classify the same way.
|
|
28
|
+
*/
|
|
29
|
+
const PREFIX_DECISION_LIMIT = 1024;
|
|
30
|
+
const SIMPLE_ESCAPES = {
|
|
31
|
+
'"': '"',
|
|
32
|
+
'\\': '\\',
|
|
33
|
+
'/': '/',
|
|
34
|
+
b: '\b',
|
|
35
|
+
f: '\f',
|
|
36
|
+
n: '\n',
|
|
37
|
+
r: '\r',
|
|
38
|
+
t: '\t',
|
|
39
|
+
};
|
|
40
|
+
const UNICODE_ESCAPE_LENGTH = 6; // \uXXXX
|
|
41
|
+
function isHighSurrogate(ch) {
|
|
42
|
+
if (!ch)
|
|
43
|
+
return false;
|
|
44
|
+
const code = ch.charCodeAt(0);
|
|
45
|
+
return code >= 0xd800 && code <= 0xdbff;
|
|
46
|
+
}
|
|
47
|
+
export function createFreeformInputDecoder() {
|
|
48
|
+
let phase = 'prefix';
|
|
49
|
+
/** False until the first non-space character, so leading whitespace is skipped once and never rescanned. */
|
|
50
|
+
let seenNonSpace = false;
|
|
51
|
+
const stats = { prefixScanned: 0, decodeScanned: 0, maxBuffered: 0 };
|
|
52
|
+
/** Undecided text from the first non-space character on, only while looking for the prefix. */
|
|
53
|
+
let prefixBuf = '';
|
|
54
|
+
/** Every fragment, kept only while the arguments might turn out to be raw. */
|
|
55
|
+
let raw = [];
|
|
56
|
+
/** Unconsumed tail of the string being decoded: at most a split escape sequence. */
|
|
57
|
+
let pending = '';
|
|
58
|
+
let emitted = '';
|
|
59
|
+
let heldHighSurrogate = '';
|
|
60
|
+
const decodeString = (text) => {
|
|
61
|
+
let out = '';
|
|
62
|
+
let i = 0;
|
|
63
|
+
while (i < text.length) {
|
|
64
|
+
const ch = text[i];
|
|
65
|
+
if (ch === '"') {
|
|
66
|
+
phase = 'closed';
|
|
67
|
+
i = text.length;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
if (ch !== '\\') {
|
|
71
|
+
out += ch;
|
|
72
|
+
i += 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const next = text[i + 1];
|
|
76
|
+
if (next === undefined)
|
|
77
|
+
break; // escape split across fragments, wait for the rest
|
|
78
|
+
if (next === 'u') {
|
|
79
|
+
const hex = text.slice(i + 2, i + UNICODE_ESCAPE_LENGTH);
|
|
80
|
+
if (hex.length < 4)
|
|
81
|
+
break;
|
|
82
|
+
if (/^[0-9a-fA-F]{4}$/.test(hex)) {
|
|
83
|
+
out += String.fromCharCode(parseInt(hex, 16));
|
|
84
|
+
i += UNICODE_ESCAPE_LENGTH;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
out += '\\u';
|
|
88
|
+
i += 2;
|
|
89
|
+
}
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
out += next in SIMPLE_ESCAPES ? SIMPLE_ESCAPES[next] : `\\${next}`;
|
|
93
|
+
i += 2;
|
|
94
|
+
}
|
|
95
|
+
stats.decodeScanned += i;
|
|
96
|
+
pending = phase === 'string' ? text.slice(i) : '';
|
|
97
|
+
return out;
|
|
98
|
+
};
|
|
99
|
+
/** Settles prefix vs raw once enough text is in, and returns what follows the prefix. */
|
|
100
|
+
const resolvePrefix = () => {
|
|
101
|
+
const window = prefixBuf.length > PREFIX_DECISION_LIMIT ? prefixBuf.slice(0, PREFIX_DECISION_LIMIT) : prefixBuf;
|
|
102
|
+
stats.prefixScanned += window.length;
|
|
103
|
+
const match = PREFIX_PATTERN.exec(window);
|
|
104
|
+
if (match) {
|
|
105
|
+
phase = 'string';
|
|
106
|
+
const rest = prefixBuf.slice(match[0].length);
|
|
107
|
+
prefixBuf = '';
|
|
108
|
+
raw = [];
|
|
109
|
+
return rest;
|
|
110
|
+
}
|
|
111
|
+
stats.prefixScanned += window.length;
|
|
112
|
+
const stillPossible = window.length < PREFIX_DECISION_LIMIT && PREFIX.startsWith(window.replace(/\s/g, ''));
|
|
113
|
+
if (stillPossible)
|
|
114
|
+
return '';
|
|
115
|
+
phase = 'raw';
|
|
116
|
+
prefixBuf = '';
|
|
117
|
+
return '';
|
|
118
|
+
};
|
|
119
|
+
/** Applies the surrogate hold to freshly decoded text and returns what is safe to emit. */
|
|
120
|
+
const releasable = (decoded) => {
|
|
121
|
+
let text = heldHighSurrogate + decoded;
|
|
122
|
+
heldHighSurrogate = '';
|
|
123
|
+
if (phase === 'string' && isHighSurrogate(text[text.length - 1])) {
|
|
124
|
+
heldHighSurrogate = text[text.length - 1];
|
|
125
|
+
text = text.slice(0, -1);
|
|
126
|
+
}
|
|
127
|
+
return text;
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
push(fragment) {
|
|
131
|
+
let toDecode = null;
|
|
132
|
+
if (phase === 'prefix') {
|
|
133
|
+
raw.push(fragment);
|
|
134
|
+
let kept = fragment;
|
|
135
|
+
if (!seenNonSpace) {
|
|
136
|
+
const firstNonSpace = fragment.search(/\S/);
|
|
137
|
+
stats.prefixScanned += firstNonSpace < 0 ? fragment.length : firstNonSpace + 1;
|
|
138
|
+
if (firstNonSpace < 0)
|
|
139
|
+
return '';
|
|
140
|
+
seenNonSpace = true;
|
|
141
|
+
kept = fragment.slice(firstNonSpace);
|
|
142
|
+
}
|
|
143
|
+
prefixBuf += kept;
|
|
144
|
+
stats.maxBuffered = Math.max(stats.maxBuffered, prefixBuf.length);
|
|
145
|
+
const rest = resolvePrefix();
|
|
146
|
+
if (phase === 'string')
|
|
147
|
+
toDecode = rest;
|
|
148
|
+
}
|
|
149
|
+
else if (phase === 'raw') {
|
|
150
|
+
raw.push(fragment);
|
|
151
|
+
}
|
|
152
|
+
else if (phase === 'string') {
|
|
153
|
+
toDecode = pending + fragment;
|
|
154
|
+
}
|
|
155
|
+
if (toDecode === null)
|
|
156
|
+
return '';
|
|
157
|
+
const out = releasable(decodeString(toDecode));
|
|
158
|
+
emitted += out;
|
|
159
|
+
stats.maxBuffered = Math.max(stats.maxBuffered, prefixBuf.length + pending.length);
|
|
160
|
+
return out;
|
|
161
|
+
},
|
|
162
|
+
get emitted() {
|
|
163
|
+
return emitted;
|
|
164
|
+
},
|
|
165
|
+
stats,
|
|
166
|
+
finish() {
|
|
167
|
+
// Never located the input string: the raw arguments are the payload.
|
|
168
|
+
if (phase === 'prefix' || phase === 'raw') {
|
|
169
|
+
const input = raw.join('');
|
|
170
|
+
return { input, tail: input, closed: false };
|
|
171
|
+
}
|
|
172
|
+
// An escape cut off by the end of the arguments is kept as written rather than dropped.
|
|
173
|
+
const tail = heldHighSurrogate + pending;
|
|
174
|
+
heldHighSurrogate = '';
|
|
175
|
+
pending = '';
|
|
176
|
+
emitted += tail;
|
|
177
|
+
return { input: emitted, tail, closed: phase === 'closed' };
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/** Provider finish reasons for output cut off by the token limit. */
|
|
182
|
+
export function isTruncatedFinishReason(finishReason) {
|
|
183
|
+
return finishReason === 'length' || finishReason === 'max_tokens';
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Whether a custom tool call was cut off by the token limit. Only a payload whose `input` string
|
|
187
|
+
* was seen to close is trusted on a truncated finish; bare text or unparseable JSON could end
|
|
188
|
+
* anywhere. Without a truncated finish reason the call stands as it is. The one place both the
|
|
189
|
+
* response and the stream transform decide this.
|
|
190
|
+
*/
|
|
191
|
+
export function isTruncatedCustomCall(closed, finishReason) {
|
|
192
|
+
return isTruncatedFinishReason(finishReason) && !closed;
|
|
193
|
+
}
|
|
194
|
+
/** The payload of a whole (non-streamed) custom tool call, decoded the way the stream decodes it. */
|
|
195
|
+
export function decodeFreeformArguments(args) {
|
|
196
|
+
const decoder = createFreeformInputDecoder();
|
|
197
|
+
decoder.push(args ?? '');
|
|
198
|
+
const { input, closed } = decoder.finish();
|
|
199
|
+
return { input, closed };
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=freeformInputDecoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"freeformInputDecoder.js","sourceRoot":"","sources":["../../../src/adapters/responses/freeformInputDecoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,MAAM,GAAG,YAAY,CAAC;AAC5B,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAC/C;;;;GAIG;AACH,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,cAAc,GAA2B;IAC7C,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,GAAG;IACR,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,IAAI;CACR,CAAC;AACF,MAAM,qBAAqB,GAAG,CAAC,CAAC,CAAC,SAAS;AAgC1C,SAAS,eAAe,CAAC,EAAsB;IAC7C,IAAI,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;IACtB,MAAM,IAAI,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9B,OAAO,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,IAAI,KAAK,GAAU,QAAQ,CAAC;IAC5B,4GAA4G;IAC5G,IAAI,YAAY,GAAG,KAAK,CAAC;IACzB,MAAM,KAAK,GAA8B,EAAE,aAAa,EA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AwF;YACxF,MAAM,IAAI,GAAG,iBAAiB,GAAG,OAAO,CAAC;YACzC,iBAAiB,GAAG,EAAE,CAAC;YACvB,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,IAAI,IAAI,CAAC;YAChB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9D,CAAC;KACF,CAAC;AACJ,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,uBAAuB,CAAC,YAAuC;IAC7E,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,KAAK,YAAY,CAAC;AACpE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAe,EAAE,YAAuC;IAC5F,OAAO,uBAAuB,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC;AAC1D,CAAC;AAED,qGAAqG;AACrG,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,MAAM,OAAO,GAAG,0BAA0B,EAAE,CAAC;IAC7C,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IACzB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -3,5 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Converts OpenAI Responses API requests to Chat Completions format.
|
|
5
5
|
*/
|
|
6
|
-
import { Params } from '../../types/requestBody.js';
|
|
6
|
+
import { Message, Params } from '../../types/requestBody.js';
|
|
7
7
|
export declare function transformResponsesToChatCompletions(req: any): Params;
|
|
8
|
+
/**
|
|
9
|
+
* Appends a message translated from one input item. Items of one model turn (text, then every call) arrive
|
|
10
|
+
* consecutively, but Chat Completions wants them as one assistant turn ahead of the results, and Bedrock only
|
|
11
|
+
* merges user messages, so adjacent assistant turns are rejected there. The calls are appended to the existing
|
|
12
|
+
* array in place: copying the accumulated calls per item is quadratic in the number of parallel calls.
|
|
13
|
+
*/
|
|
14
|
+
export declare function pushInputMessage(messages: Message[], msg: Message): void;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Converts OpenAI Responses API requests to Chat Completions format.
|
|
5
5
|
*/
|
|
6
|
+
import { buildResponsesToolMapping, mapResponsesToolChoice } from './toolMapping.js';
|
|
6
7
|
const ROLE_MAP = {
|
|
7
8
|
developer: 'system',
|
|
8
9
|
system: 'system',
|
|
@@ -12,6 +13,7 @@ const ROLE_MAP = {
|
|
|
12
13
|
};
|
|
13
14
|
export function transformResponsesToChatCompletions(req) {
|
|
14
15
|
const messages = [];
|
|
16
|
+
const toolMapping = buildResponsesToolMapping(req);
|
|
15
17
|
if (req.instructions) {
|
|
16
18
|
messages.push({ role: 'system', content: req.instructions });
|
|
17
19
|
}
|
|
@@ -20,9 +22,9 @@ export function transformResponsesToChatCompletions(req) {
|
|
|
20
22
|
}
|
|
21
23
|
else if (Array.isArray(req.input)) {
|
|
22
24
|
for (const item of req.input) {
|
|
23
|
-
const msg = transformInputItem(item);
|
|
25
|
+
const msg = transformInputItem(item, toolMapping);
|
|
24
26
|
if (msg)
|
|
25
|
-
messages
|
|
27
|
+
pushInputMessage(messages, msg);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
const result = { model: req.model, messages };
|
|
@@ -45,35 +47,19 @@ export function transformResponsesToChatCompletions(req) {
|
|
|
45
47
|
if (result.stream) {
|
|
46
48
|
result.stream_options = { include_usage: true };
|
|
47
49
|
}
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (t.type === 'function') {
|
|
53
|
-
tools.push({
|
|
54
|
-
type: 'function',
|
|
55
|
-
function: {
|
|
56
|
-
name: t.name,
|
|
57
|
-
description: t.description || '',
|
|
58
|
-
parameters: t.parameters,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (tools.length)
|
|
64
|
-
result.tools = tools;
|
|
50
|
+
// Function tools pass through, namespaces are flattened and `custom` tools become functions
|
|
51
|
+
// taking `{input}`. Other tool types have no Chat Completions shape and are skipped.
|
|
52
|
+
if (toolMapping.tools.length) {
|
|
53
|
+
result.tools = toolMapping.tools;
|
|
65
54
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
function: { name: req.tool_choice.name },
|
|
75
|
-
};
|
|
76
|
-
}
|
|
55
|
+
else {
|
|
56
|
+
// Providers reject these without tools (Databricks, Mantle: 400 "tool_choice without tools").
|
|
57
|
+
delete result.parallel_tool_calls;
|
|
58
|
+
}
|
|
59
|
+
if (toolMapping.tools.length && req.tool_choice) {
|
|
60
|
+
const toolChoice = mapResponsesToolChoice(req.tool_choice, toolMapping);
|
|
61
|
+
if (toolChoice !== undefined)
|
|
62
|
+
result.tool_choice = toolChoice;
|
|
77
63
|
}
|
|
78
64
|
// Transform response format (text.format)
|
|
79
65
|
if (req.text?.format) {
|
|
@@ -100,7 +86,25 @@ export function transformResponsesToChatCompletions(req) {
|
|
|
100
86
|
result.top_logprobs = req.top_logprobs;
|
|
101
87
|
return result;
|
|
102
88
|
}
|
|
103
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Appends a message translated from one input item. Items of one model turn (text, then every call) arrive
|
|
91
|
+
* consecutively, but Chat Completions wants them as one assistant turn ahead of the results, and Bedrock only
|
|
92
|
+
* merges user messages, so adjacent assistant turns are rejected there. The calls are appended to the existing
|
|
93
|
+
* array in place: copying the accumulated calls per item is quadratic in the number of parallel calls.
|
|
94
|
+
*/
|
|
95
|
+
export function pushInputMessage(messages, msg) {
|
|
96
|
+
const prev = messages[messages.length - 1];
|
|
97
|
+
if (isToolCallOnlyTurn(msg) && prev?.role === 'assistant') {
|
|
98
|
+
(prev.tool_calls ??= []).push(...msg.tool_calls);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
messages.push(msg);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function isToolCallOnlyTurn(msg) {
|
|
105
|
+
return msg.role === 'assistant' && msg.content === '' && Array.isArray(msg.tool_calls) && msg.tool_calls.length > 0;
|
|
106
|
+
}
|
|
107
|
+
function transformInputItem(item, toolMapping) {
|
|
104
108
|
// Simple message format { role, content }
|
|
105
109
|
if (item.role && item.content !== undefined && item.type !== 'function_call') {
|
|
106
110
|
return {
|
|
@@ -126,12 +130,45 @@ function transformInputItem(item) {
|
|
|
126
130
|
{
|
|
127
131
|
id: item.call_id || item.id || '',
|
|
128
132
|
type: 'function',
|
|
129
|
-
function: { name: item.name, arguments: item.arguments },
|
|
133
|
+
function: { name: toolMapping.flatName(item.namespace, item.name), arguments: item.arguments },
|
|
130
134
|
},
|
|
131
135
|
],
|
|
132
136
|
};
|
|
133
137
|
}
|
|
134
138
|
break;
|
|
139
|
+
// A custom tool call replays as the function it was offered as, with its raw payload wrapped
|
|
140
|
+
// in `input`. Always wrapped, even when the payload happens to be valid JSON.
|
|
141
|
+
// Only a string payload is accepted: the guardrail extractors scan strings, so wrapping any other
|
|
142
|
+
// shape into the arguments would let it reach the provider unscanned.
|
|
143
|
+
case 'custom_tool_call':
|
|
144
|
+
if (item.name && typeof item.input === 'string') {
|
|
145
|
+
return {
|
|
146
|
+
role: 'assistant',
|
|
147
|
+
content: '',
|
|
148
|
+
tool_calls: [
|
|
149
|
+
{
|
|
150
|
+
id: item.call_id || item.id || '',
|
|
151
|
+
type: 'function',
|
|
152
|
+
function: {
|
|
153
|
+
name: toolMapping.flatName(item.namespace, item.name),
|
|
154
|
+
arguments: JSON.stringify({ input: item.input }),
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
// Same principle for the result: a string or a list of content parts (which the extractors scan
|
|
162
|
+
// part by part), never an arbitrary object.
|
|
163
|
+
case 'custom_tool_call_output':
|
|
164
|
+
if (item.call_id && (typeof item.output === 'string' || Array.isArray(item.output))) {
|
|
165
|
+
return {
|
|
166
|
+
role: 'tool',
|
|
167
|
+
tool_call_id: item.call_id,
|
|
168
|
+
content: Array.isArray(item.output) ? transformContent(item.output) : item.output,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
135
172
|
case 'function_call_output':
|
|
136
173
|
if (item.call_id && item.output !== undefined) {
|
|
137
174
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestTransform.js","sourceRoot":"","sources":["../../../src/adapters/responses/requestTransform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"requestTransform.js","sourceRoot":"","sources":["../../../src/adapters/responses/requestTransform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAwB,MAAM,eAAe,CAAC;AAExG,MAAM,QAAQ,GAA6D;IACzE,SAAS,EAAE,QAAQ;IACnB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,MAAM;CACb,CAAC;AAEF,MAAM,UAAU,mCAAmC,CAAC,GAAQ;IAC1D,MAAM,QAAQ,GAAc,EAAE,CAAC;IAC/B,MAAM,WAAW,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC;IAEnD,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;QACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,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AC,CAAC,SAAS;oBACtB,OAAO,EAAE,CAAC,CAAC,OAAO;iBACnB;aACK,CAAC,CAAC;QACZ,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* Includes reasoning output items when thinking data is present.
|
|
6
6
|
*/
|
|
7
7
|
import { ChatCompletionResponse, ErrorResponse } from '../../providers/types.js';
|
|
8
|
-
import { OpenAIResponse } from '../../types/modelResponses.js';
|
|
8
|
+
import { OpenAIResponse, ResponseCustomToolCall, ResponseFunctionToolCall } from '../../types/modelResponses.js';
|
|
9
|
+
import { ResponsesToolMapping } from './toolMapping.js';
|
|
9
10
|
export declare const RESPONSE_DEFAULTS: {
|
|
10
11
|
truncation: "disabled";
|
|
11
12
|
parallel_tool_calls: boolean;
|
|
@@ -19,6 +20,18 @@ export declare const RESPONSE_DEFAULTS: {
|
|
|
19
20
|
background: boolean;
|
|
20
21
|
service_tier: string;
|
|
21
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* A provider tool call as the Responses item the client expects: a namespaced function gets its
|
|
25
|
+
* `namespace` and original name back, and a call to a `custom` tool comes back as
|
|
26
|
+
* `custom_tool_call` carrying the raw payload instead of `{"input": ...}`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildToolCallItem(toolCall: {
|
|
29
|
+
id?: string;
|
|
30
|
+
function: {
|
|
31
|
+
name: string;
|
|
32
|
+
arguments: string;
|
|
33
|
+
};
|
|
34
|
+
}, toolMapping: ResponsesToolMapping, finishReason?: string | null): ResponseFunctionToolCall | ResponseCustomToolCall;
|
|
22
35
|
/**
|
|
23
36
|
* Transform Chat Completions response to Responses API format.
|
|
24
37
|
*
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* Includes reasoning output items when thinking data is present.
|
|
6
6
|
*/
|
|
7
7
|
import crypto from 'crypto';
|
|
8
|
+
import { decodeFreeformArguments, isTruncatedCustomCall } from './freeformInputDecoder.js';
|
|
9
|
+
import { buildResponsesToolMapping, echoResponsesTools } from './toolMapping.js';
|
|
8
10
|
const STATUS_MAP = {
|
|
9
11
|
stop: 'completed',
|
|
10
12
|
end_turn: 'completed',
|
|
@@ -27,6 +29,40 @@ export const RESPONSE_DEFAULTS = {
|
|
|
27
29
|
background: false,
|
|
28
30
|
service_tier: 'default',
|
|
29
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* A provider tool call as the Responses item the client expects: a namespaced function gets its
|
|
34
|
+
* `namespace` and original name back, and a call to a `custom` tool comes back as
|
|
35
|
+
* `custom_tool_call` carrying the raw payload instead of `{"input": ...}`.
|
|
36
|
+
*/
|
|
37
|
+
export function buildToolCallItem(toolCall, toolMapping, finishReason) {
|
|
38
|
+
const { name, arguments: args } = toolCall.function;
|
|
39
|
+
const origin = toolMapping.originOf(name);
|
|
40
|
+
if (origin?.kind === 'custom') {
|
|
41
|
+
const { input, closed } = decodeFreeformArguments(args);
|
|
42
|
+
// Codex runs a custom tool call as soon as the item arrives and never reads `status`, so a
|
|
43
|
+
// payload cut off by the token limit must not carry its partial source (an `exec` would run
|
|
44
|
+
// half a script). Empty input makes the client report an error to the model instead.
|
|
45
|
+
const truncated = isTruncatedCustomCall(closed, finishReason);
|
|
46
|
+
return {
|
|
47
|
+
id: `ctc_${crypto.randomUUID()}`,
|
|
48
|
+
type: 'custom_tool_call',
|
|
49
|
+
call_id: toolCall.id,
|
|
50
|
+
name: origin.name,
|
|
51
|
+
...(origin.namespace && { namespace: origin.namespace }),
|
|
52
|
+
input: truncated ? '' : input,
|
|
53
|
+
...(truncated && { status: 'incomplete' }),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
id: `fc_${crypto.randomUUID()}`,
|
|
58
|
+
type: 'function_call',
|
|
59
|
+
call_id: toolCall.id,
|
|
60
|
+
name: origin?.name ?? name,
|
|
61
|
+
...(origin?.namespace && { namespace: origin.namespace }),
|
|
62
|
+
arguments: args,
|
|
63
|
+
status: 'completed',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
30
66
|
/**
|
|
31
67
|
* Transform Chat Completions response to Responses API format.
|
|
32
68
|
*
|
|
@@ -50,6 +86,8 @@ export function transformChatCompletionsToResponses(response, responseStatus, pr
|
|
|
50
86
|
};
|
|
51
87
|
}
|
|
52
88
|
const output = [];
|
|
89
|
+
const req = originalRequest || {};
|
|
90
|
+
const toolMapping = buildResponsesToolMapping(req);
|
|
53
91
|
let overallStatus = 'completed';
|
|
54
92
|
for (const choice of response.choices || []) {
|
|
55
93
|
const msg = (choice.message || {});
|
|
@@ -78,14 +116,10 @@ export function transformChatCompletionsToResponses(response, responseStatus, pr
|
|
|
78
116
|
if (msg.tool_calls?.length) {
|
|
79
117
|
for (const tc of msg.tool_calls) {
|
|
80
118
|
if (tc.type === 'function' && tc.function) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
name: tc.function.name,
|
|
86
|
-
arguments: tc.function.arguments,
|
|
87
|
-
status: 'completed',
|
|
88
|
-
});
|
|
119
|
+
const item = buildToolCallItem(tc, toolMapping, choice.finish_reason);
|
|
120
|
+
if (item.status === 'incomplete')
|
|
121
|
+
overallStatus = 'incomplete';
|
|
122
|
+
output.push(item);
|
|
89
123
|
}
|
|
90
124
|
}
|
|
91
125
|
}
|
|
@@ -121,15 +155,8 @@ export function transformChatCompletionsToResponses(response, responseStatus, pr
|
|
|
121
155
|
const reasoningTokens = usage?.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
122
156
|
const cachedTokens = usage?.prompt_tokens_details?.cached_tokens ?? 0;
|
|
123
157
|
const createdAt = response.created || Math.floor(Date.now() / 1000);
|
|
124
|
-
const req = originalRequest || {};
|
|
125
158
|
// Echo back tools from original request
|
|
126
|
-
const tools = (req.tools
|
|
127
|
-
type: t.type || 'function',
|
|
128
|
-
name: t.name,
|
|
129
|
-
description: t.description ?? null,
|
|
130
|
-
parameters: t.parameters ?? null,
|
|
131
|
-
strict: t.strict ?? null,
|
|
132
|
-
}));
|
|
159
|
+
const tools = echoResponsesTools(req.tools);
|
|
133
160
|
const textFormat = req.text?.format ? { format: req.text.format } : { format: { type: 'text' } };
|
|
134
161
|
return {
|
|
135
162
|
id: response.id || `resp_${crypto.randomUUID()}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseTransform.js","sourceRoot":"","sources":["../../../src/adapters/responses/responseTransform.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAW5B,MAAM,UAAU,GAA+D;IAC7E,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE,WAAW;IACrB,UAAU,EAAE,WAAW;IACvB,aAAa,EAAE,WAAW;IAC1B,MAAM,EAAE,YAAY;IACpB,UAAU,EAAE,YAAY;IACxB,cAAc,EAAE,WAAW;CAC5B,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,UAAU,EAAE,UAAmB;IAC/B,mBAAmB,EAAE,IAAI;IACzB,WAAW,EAAE,MAAe;IAC5B,WAAW,EAAE,CAAC;IACd,KAAK,EAAE,CAAC;IACR,gBAAgB,EAAE,CAAC;IACnB,iBAAiB,EAAE,CAAC;IACpB,YAAY,EAAE,CAAC;IACf,KAAK,EAAE,KAAK;IACZ,UAAU,EAAE,KAAK;IACjB,YAAY,EAAE,SAAS;CACxB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,mCAAmC,CACjD,QAAgD,EAChD,cAAsB,EACtB,QAAgB,EAChB,eAAqB;IAErB,IAAI,OAAO,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IACzC,IAAI,cAAc,KAAK,GAAG,EAAE,CAAC;QAC3B,MAAM,eAAe,GAAI,QAAgB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;QAChE,OAAO;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