@openai/agents-core 0.12.0 → 0.12.1
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/handoff.d.ts +1 -1
- package/dist/handoff.js +2 -2
- package/dist/handoff.js.map +1 -1
- package/dist/handoff.mjs +2 -2
- package/dist/handoff.mjs.map +1 -1
- package/dist/metadata.js +2 -2
- package/dist/metadata.mjs +2 -2
- package/dist/run.d.ts +2 -13
- package/dist/run.js +12 -37
- package/dist/run.js.map +1 -1
- package/dist/run.mjs +11 -36
- package/dist/run.mjs.map +1 -1
- package/dist/runState.d.ts +1 -1
- package/dist/runState.js +7 -184
- package/dist/runState.js.map +1 -1
- package/dist/runState.mjs +2 -179
- package/dist/runState.mjs.map +1 -1
- package/dist/runStateIdentity.d.ts +6 -0
- package/dist/runStateIdentity.js +171 -0
- package/dist/runStateIdentity.js.map +1 -0
- package/dist/runStateIdentity.mjs +168 -0
- package/dist/runStateIdentity.mjs.map +1 -0
- package/dist/runner/conversation.js +46 -4
- package/dist/runner/conversation.js.map +1 -1
- package/dist/runner/conversation.mjs +46 -4
- package/dist/runner/conversation.mjs.map +1 -1
- package/dist/runner/errorHandlers.d.ts +7 -4
- package/dist/runner/errorHandlers.js +31 -10
- package/dist/runner/errorHandlers.js.map +1 -1
- package/dist/runner/errorHandlers.mjs +31 -10
- package/dist/runner/errorHandlers.mjs.map +1 -1
- package/dist/runner/items.js +3 -8
- package/dist/runner/items.js.map +1 -1
- package/dist/runner/items.mjs +3 -8
- package/dist/runner/items.mjs.map +1 -1
- package/dist/runner/modelSettings.d.ts +1 -1
- package/dist/runner/modelSettings.js +2 -2
- package/dist/runner/modelSettings.js.map +1 -1
- package/dist/runner/modelSettings.mjs +2 -2
- package/dist/runner/modelSettings.mjs.map +1 -1
- package/dist/runner/runConfig.d.ts +16 -0
- package/dist/runner/runConfig.js +31 -0
- package/dist/runner/runConfig.js.map +1 -0
- package/dist/runner/runConfig.mjs +27 -0
- package/dist/runner/runConfig.mjs.map +1 -0
- package/dist/runner/runLoop.js +1 -1
- package/dist/runner/runLoop.js.map +1 -1
- package/dist/runner/runLoop.mjs +1 -1
- package/dist/runner/runLoop.mjs.map +1 -1
- package/dist/runner/steps.d.ts +3 -1
- package/dist/runner/steps.js +3 -1
- package/dist/runner/steps.js.map +1 -1
- package/dist/runner/steps.mjs +3 -1
- package/dist/runner/steps.mjs.map +1 -1
- package/dist/runner/toolExecution.js +12 -347
- package/dist/runner/toolExecution.js.map +1 -1
- package/dist/runner/toolExecution.mjs +10 -345
- package/dist/runner/toolExecution.mjs.map +1 -1
- package/dist/runner/toolOutputNormalization.d.ts +16 -0
- package/dist/runner/toolOutputNormalization.js +328 -0
- package/dist/runner/toolOutputNormalization.js.map +1 -0
- package/dist/runner/toolOutputNormalization.mjs +324 -0
- package/dist/runner/toolOutputNormalization.mjs.map +1 -0
- package/dist/runner/toolResultCorrelation.d.ts +22 -0
- package/dist/runner/toolResultCorrelation.js +138 -0
- package/dist/runner/toolResultCorrelation.js.map +1 -0
- package/dist/runner/toolResultCorrelation.mjs +130 -0
- package/dist/runner/toolResultCorrelation.mjs.map +1 -0
- package/dist/runner/turnResolution.js +66 -15
- package/dist/runner/turnResolution.js.map +1 -1
- package/dist/runner/turnResolution.mjs +67 -16
- package/dist/runner/turnResolution.mjs.map +1 -1
- package/dist/runner/types.d.ts +1 -1
- package/dist/sandbox/internal/process.d.ts +1 -0
- package/dist/sandbox/internal/process.js +7 -0
- package/dist/sandbox/internal/process.js.map +1 -0
- package/dist/sandbox/internal/process.mjs +2 -0
- package/dist/sandbox/internal/process.mjs.map +1 -0
- package/dist/sandbox/internal.d.ts +2 -0
- package/dist/sandbox/internal.js +15 -1
- package/dist/sandbox/internal.js.map +1 -1
- package/dist/sandbox/internal.mjs +2 -0
- package/dist/sandbox/internal.mjs.map +1 -1
- package/dist/sandbox/sandboxes/docker.js +8 -3
- package/dist/sandbox/sandboxes/docker.js.map +1 -1
- package/dist/sandbox/sandboxes/docker.mjs +8 -3
- package/dist/sandbox/sandboxes/docker.mjs.map +1 -1
- package/dist/sandbox/shared/credentials.d.ts +9 -0
- package/dist/sandbox/shared/credentials.js +10 -0
- package/dist/sandbox/shared/credentials.js.map +1 -0
- package/dist/sandbox/shared/credentials.mjs +7 -0
- package/dist/sandbox/shared/credentials.mjs.map +1 -0
- package/dist/sandbox/shared/typeGuards.d.ts +6 -1
- package/dist/sandbox/shared/typeGuards.js +23 -1
- package/dist/sandbox/shared/typeGuards.js.map +1 -1
- package/dist/sandbox/shared/typeGuards.mjs +18 -1
- package/dist/sandbox/shared/typeGuards.mjs.map +1 -1
- package/dist/utils/inlineData.d.ts +2 -0
- package/dist/utils/inlineData.js +22 -0
- package/dist/utils/inlineData.js.map +1 -0
- package/dist/utils/inlineData.mjs +18 -0
- package/dist/utils/inlineData.mjs.map +1 -0
- package/dist/utils/internal.d.ts +1 -0
- package/dist/utils/internal.js +7 -0
- package/dist/utils/internal.js.map +1 -0
- package/dist/utils/internal.mjs +2 -0
- package/dist/utils/internal.mjs.map +1 -0
- package/package.json +21 -2
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeStructuredToolOutputs = normalizeStructuredToolOutputs;
|
|
4
|
+
exports.convertStructuredToolOutputToInputItem = convertStructuredToolOutputToInputItem;
|
|
5
|
+
const base64_1 = require("../utils/base64.js");
|
|
6
|
+
const inlineData_1 = require("../utils/inlineData.js");
|
|
7
|
+
/**
|
|
8
|
+
* Accepts whatever the tool returned and attempts to coerce it into the structured protocol
|
|
9
|
+
* shapes we expose to downstream model adapters (input_text/input_image/input_file). Tools are
|
|
10
|
+
* allowed to return either a single structured object or an array of them; anything else falls
|
|
11
|
+
* back to the legacy string pipeline.
|
|
12
|
+
*/
|
|
13
|
+
function normalizeStructuredToolOutputs(output) {
|
|
14
|
+
if (Array.isArray(output)) {
|
|
15
|
+
if (output.length === 0) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const structured = [];
|
|
19
|
+
for (const item of output) {
|
|
20
|
+
const normalized = normalizeStructuredToolOutput(item);
|
|
21
|
+
if (!normalized) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
structured.push(normalized);
|
|
25
|
+
}
|
|
26
|
+
return structured;
|
|
27
|
+
}
|
|
28
|
+
const normalized = normalizeStructuredToolOutput(output);
|
|
29
|
+
return normalized ? [normalized] : null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Best-effort normalization of a single tool output item. If the object already matches the
|
|
33
|
+
* protocol shape we simply cast it; otherwise we copy the recognised fields into the canonical
|
|
34
|
+
* structure. Returning null lets the caller know we should revert to plain-string handling.
|
|
35
|
+
*/
|
|
36
|
+
function normalizeStructuredToolOutput(value) {
|
|
37
|
+
if (!isRecord(value)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const type = value.type;
|
|
41
|
+
if (type === 'text' && typeof value.text === 'string') {
|
|
42
|
+
const output = { type: 'text', text: value.text };
|
|
43
|
+
if (isRecord(value.providerData)) {
|
|
44
|
+
output.providerData = value.providerData;
|
|
45
|
+
}
|
|
46
|
+
return output;
|
|
47
|
+
}
|
|
48
|
+
if (type === 'image') {
|
|
49
|
+
const output = { type: 'image' };
|
|
50
|
+
let imageString;
|
|
51
|
+
let imageFileId;
|
|
52
|
+
const fallbackImageMediaType = (0, inlineData_1.getInlineMediaType)(value);
|
|
53
|
+
const imageField = value.image;
|
|
54
|
+
if (typeof imageField === 'string' && imageField.length > 0) {
|
|
55
|
+
imageString = imageField;
|
|
56
|
+
}
|
|
57
|
+
else if (isRecord(imageField)) {
|
|
58
|
+
const imageObj = imageField;
|
|
59
|
+
const inlineMediaType = (0, inlineData_1.getInlineMediaType)(imageObj) ?? fallbackImageMediaType;
|
|
60
|
+
if (isNonEmptyString(imageObj.url)) {
|
|
61
|
+
imageString = imageObj.url;
|
|
62
|
+
}
|
|
63
|
+
else if (isNonEmptyString(imageObj.data)) {
|
|
64
|
+
imageString = (0, inlineData_1.formatInlineData)(imageObj.data, inlineMediaType);
|
|
65
|
+
}
|
|
66
|
+
else if (imageObj.data instanceof Uint8Array &&
|
|
67
|
+
imageObj.data.length > 0) {
|
|
68
|
+
imageString = (0, inlineData_1.formatInlineData)(imageObj.data, inlineMediaType);
|
|
69
|
+
}
|
|
70
|
+
if (!imageString) {
|
|
71
|
+
const candidateId = (isNonEmptyString(imageObj.fileId) && imageObj.fileId) ||
|
|
72
|
+
(isNonEmptyString(imageObj.id) && imageObj.id) ||
|
|
73
|
+
undefined;
|
|
74
|
+
if (candidateId) {
|
|
75
|
+
imageFileId = candidateId;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!imageString &&
|
|
80
|
+
typeof value.imageUrl === 'string' &&
|
|
81
|
+
value.imageUrl.length > 0) {
|
|
82
|
+
imageString = value.imageUrl;
|
|
83
|
+
}
|
|
84
|
+
if (!imageFileId &&
|
|
85
|
+
typeof value.fileId === 'string' &&
|
|
86
|
+
value.fileId.length > 0) {
|
|
87
|
+
imageFileId = value.fileId;
|
|
88
|
+
}
|
|
89
|
+
if (!imageString &&
|
|
90
|
+
typeof value.data === 'string' &&
|
|
91
|
+
value.data.length > 0) {
|
|
92
|
+
imageString = fallbackImageMediaType
|
|
93
|
+
? (0, inlineData_1.formatInlineData)(value.data, fallbackImageMediaType)
|
|
94
|
+
: value.data;
|
|
95
|
+
}
|
|
96
|
+
else if (!imageString &&
|
|
97
|
+
value.data instanceof Uint8Array &&
|
|
98
|
+
value.data.length > 0) {
|
|
99
|
+
imageString = (0, inlineData_1.formatInlineData)(value.data, fallbackImageMediaType);
|
|
100
|
+
}
|
|
101
|
+
if (typeof value.detail === 'string' && value.detail.length > 0) {
|
|
102
|
+
output.detail = value.detail;
|
|
103
|
+
}
|
|
104
|
+
if (imageString) {
|
|
105
|
+
output.image = imageString;
|
|
106
|
+
}
|
|
107
|
+
else if (imageFileId) {
|
|
108
|
+
output.image = { fileId: imageFileId };
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
if (isRecord(value.providerData)) {
|
|
114
|
+
output.providerData = value.providerData;
|
|
115
|
+
}
|
|
116
|
+
return output;
|
|
117
|
+
}
|
|
118
|
+
if (type === 'file') {
|
|
119
|
+
const fileValue = normalizeFileValue(value);
|
|
120
|
+
if (!fileValue) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const output = { type: 'file', file: fileValue };
|
|
124
|
+
if (isRecord(value.providerData)) {
|
|
125
|
+
output.providerData = value.providerData;
|
|
126
|
+
}
|
|
127
|
+
return output;
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Translates the normalized tool output into the protocol `input_*` items. This is the last hop
|
|
133
|
+
* before we hand the data to model-specific adapters, so we generate the exact schema expected by
|
|
134
|
+
* the protocol definitions.
|
|
135
|
+
*/
|
|
136
|
+
function convertStructuredToolOutputToInputItem(output) {
|
|
137
|
+
if (output.type === 'text') {
|
|
138
|
+
const result = {
|
|
139
|
+
type: 'input_text',
|
|
140
|
+
text: output.text,
|
|
141
|
+
};
|
|
142
|
+
if (output.providerData) {
|
|
143
|
+
result.providerData = output.providerData;
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
if (output.type === 'image') {
|
|
148
|
+
const result = { type: 'input_image' };
|
|
149
|
+
if (typeof output.detail === 'string' && output.detail.length > 0) {
|
|
150
|
+
result.detail = output.detail;
|
|
151
|
+
}
|
|
152
|
+
if (typeof output.image === 'string' && output.image.length > 0) {
|
|
153
|
+
result.image = output.image;
|
|
154
|
+
}
|
|
155
|
+
else if (isRecord(output.image)) {
|
|
156
|
+
const imageObj = output.image;
|
|
157
|
+
const inlineMediaType = (0, inlineData_1.getInlineMediaType)(imageObj);
|
|
158
|
+
if (isNonEmptyString(imageObj.url)) {
|
|
159
|
+
result.image = imageObj.url;
|
|
160
|
+
}
|
|
161
|
+
else if (isNonEmptyString(imageObj.data)) {
|
|
162
|
+
result.image =
|
|
163
|
+
inlineMediaType && !imageObj.data.startsWith('data:')
|
|
164
|
+
? asDataUrl(imageObj.data, inlineMediaType)
|
|
165
|
+
: imageObj.data;
|
|
166
|
+
}
|
|
167
|
+
else if (imageObj.data instanceof Uint8Array &&
|
|
168
|
+
imageObj.data.length > 0) {
|
|
169
|
+
const base64 = (0, base64_1.encodeUint8ArrayToBase64)(imageObj.data);
|
|
170
|
+
result.image = asDataUrl(base64, inlineMediaType);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
const referencedId = (isNonEmptyString(imageObj.fileId) && imageObj.fileId) ||
|
|
174
|
+
(isNonEmptyString(imageObj.id) && imageObj.id) ||
|
|
175
|
+
undefined;
|
|
176
|
+
if (referencedId) {
|
|
177
|
+
result.image = { id: referencedId };
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (output.providerData) {
|
|
182
|
+
result.providerData = output.providerData;
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
if (output.type === 'file') {
|
|
187
|
+
const result = { type: 'input_file' };
|
|
188
|
+
const fileValue = output.file;
|
|
189
|
+
if (typeof fileValue === 'string') {
|
|
190
|
+
result.file = fileValue;
|
|
191
|
+
}
|
|
192
|
+
else if (fileValue && typeof fileValue === 'object') {
|
|
193
|
+
const record = fileValue;
|
|
194
|
+
if ('data' in record && record.data) {
|
|
195
|
+
const mediaType = record.mediaType ?? 'text/plain';
|
|
196
|
+
if (typeof record.data === 'string') {
|
|
197
|
+
result.file = asDataUrl(record.data, mediaType);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
const base64 = (0, base64_1.encodeUint8ArrayToBase64)(record.data);
|
|
201
|
+
result.file = asDataUrl(base64, mediaType);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else if (typeof record.url === 'string' && record.url.length > 0) {
|
|
205
|
+
result.file = { url: record.url };
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
const referencedId = (typeof record.id === 'string' &&
|
|
209
|
+
record.id.length > 0 &&
|
|
210
|
+
record.id) ||
|
|
211
|
+
(typeof record.fileId === 'string' && record.fileId.length > 0
|
|
212
|
+
? record.fileId
|
|
213
|
+
: undefined);
|
|
214
|
+
if (referencedId) {
|
|
215
|
+
result.file = { id: referencedId };
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (typeof record.filename === 'string' && record.filename.length > 0) {
|
|
219
|
+
result.filename = record.filename;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (output.providerData) {
|
|
223
|
+
result.providerData = output.providerData;
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
const exhaustiveCheck = output;
|
|
228
|
+
return exhaustiveCheck;
|
|
229
|
+
}
|
|
230
|
+
function normalizeFileValue(value) {
|
|
231
|
+
const directFile = value.file;
|
|
232
|
+
if (typeof directFile === 'string' && directFile.length > 0) {
|
|
233
|
+
return directFile;
|
|
234
|
+
}
|
|
235
|
+
const normalizedObject = normalizeFileObjectCandidate(directFile);
|
|
236
|
+
if (normalizedObject) {
|
|
237
|
+
return normalizedObject;
|
|
238
|
+
}
|
|
239
|
+
const legacyValue = normalizeLegacyFileValue(value);
|
|
240
|
+
if (legacyValue) {
|
|
241
|
+
return legacyValue;
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
function normalizeFileObjectCandidate(value) {
|
|
246
|
+
if (!isRecord(value)) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
if ('data' in value && value.data !== undefined) {
|
|
250
|
+
const dataValue = value.data;
|
|
251
|
+
const hasStringData = typeof dataValue === 'string' && dataValue.length > 0;
|
|
252
|
+
const hasBinaryData = dataValue instanceof Uint8Array && dataValue.length > 0;
|
|
253
|
+
if (!hasStringData && !hasBinaryData) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
if (!isNonEmptyString(value.mediaType) ||
|
|
257
|
+
!isNonEmptyString(value.filename)) {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
data: typeof dataValue === 'string' ? dataValue : new Uint8Array(dataValue),
|
|
262
|
+
mediaType: value.mediaType,
|
|
263
|
+
filename: value.filename,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
if (isNonEmptyString(value.url)) {
|
|
267
|
+
const result = { url: value.url };
|
|
268
|
+
if (isNonEmptyString(value.filename)) {
|
|
269
|
+
result.filename = value.filename;
|
|
270
|
+
}
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
const referencedId = (isNonEmptyString(value.id) && value.id) ||
|
|
274
|
+
(isNonEmptyString(value.fileId) && value.fileId);
|
|
275
|
+
if (referencedId) {
|
|
276
|
+
const result = { id: referencedId };
|
|
277
|
+
if (isNonEmptyString(value.filename)) {
|
|
278
|
+
result.filename = value.filename;
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
function normalizeLegacyFileValue(value) {
|
|
285
|
+
const filename = typeof value.filename === 'string' && value.filename.length > 0
|
|
286
|
+
? value.filename
|
|
287
|
+
: undefined;
|
|
288
|
+
const mediaType = typeof value.mediaType === 'string' && value.mediaType.length > 0
|
|
289
|
+
? value.mediaType
|
|
290
|
+
: undefined;
|
|
291
|
+
if (typeof value.fileData === 'string' && value.fileData.length > 0) {
|
|
292
|
+
if (!mediaType || !filename) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
return { data: value.fileData, mediaType, filename };
|
|
296
|
+
}
|
|
297
|
+
if (value.fileData instanceof Uint8Array && value.fileData.length > 0) {
|
|
298
|
+
if (!mediaType || !filename) {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
return { data: new Uint8Array(value.fileData), mediaType, filename };
|
|
302
|
+
}
|
|
303
|
+
if (typeof value.fileUrl === 'string' && value.fileUrl.length > 0) {
|
|
304
|
+
const result = { url: value.fileUrl };
|
|
305
|
+
if (filename) {
|
|
306
|
+
result.filename = filename;
|
|
307
|
+
}
|
|
308
|
+
return result;
|
|
309
|
+
}
|
|
310
|
+
if (typeof value.fileId === 'string' && value.fileId.length > 0) {
|
|
311
|
+
const result = { id: value.fileId };
|
|
312
|
+
if (filename) {
|
|
313
|
+
result.filename = filename;
|
|
314
|
+
}
|
|
315
|
+
return result;
|
|
316
|
+
}
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
function isRecord(value) {
|
|
320
|
+
return typeof value === 'object' && value !== null;
|
|
321
|
+
}
|
|
322
|
+
function isNonEmptyString(value) {
|
|
323
|
+
return typeof value === 'string' && value.length > 0;
|
|
324
|
+
}
|
|
325
|
+
function asDataUrl(base64, mediaType) {
|
|
326
|
+
return mediaType ? `data:${mediaType};base64,${base64}` : base64;
|
|
327
|
+
}
|
|
328
|
+
//# sourceMappingURL=toolOutputNormalization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolOutputNormalization.js","sourceRoot":"","sources":["../../src/runner/toolOutputNormalization.ts"],"names":[],"mappings":";;AAqBA,wEAmBC;AAgID,wFA6FC;AA9PD,+CAA2D;AAC3D,uDAA2E;AAO3E;;;;;GAKG;AACH,SAAgB,8BAA8B,CAC5C,MAAe;IAEf,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,UAAU,GAA2B,EAAE,CAAC;QAC9C,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YAC1B,MAAM,UAAU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,MAAc,EAAE,SAAkB;IACnD,OAAO,SAAS,CAAC,CAAC,CAAC,QAAQ,SAAS,WAAW,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { encodeUint8ArrayToBase64 } from "../utils/base64.mjs";
|
|
2
|
+
import { formatInlineData, getInlineMediaType } from "../utils/inlineData.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Accepts whatever the tool returned and attempts to coerce it into the structured protocol
|
|
5
|
+
* shapes we expose to downstream model adapters (input_text/input_image/input_file). Tools are
|
|
6
|
+
* allowed to return either a single structured object or an array of them; anything else falls
|
|
7
|
+
* back to the legacy string pipeline.
|
|
8
|
+
*/
|
|
9
|
+
export function normalizeStructuredToolOutputs(output) {
|
|
10
|
+
if (Array.isArray(output)) {
|
|
11
|
+
if (output.length === 0) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const structured = [];
|
|
15
|
+
for (const item of output) {
|
|
16
|
+
const normalized = normalizeStructuredToolOutput(item);
|
|
17
|
+
if (!normalized) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
structured.push(normalized);
|
|
21
|
+
}
|
|
22
|
+
return structured;
|
|
23
|
+
}
|
|
24
|
+
const normalized = normalizeStructuredToolOutput(output);
|
|
25
|
+
return normalized ? [normalized] : null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Best-effort normalization of a single tool output item. If the object already matches the
|
|
29
|
+
* protocol shape we simply cast it; otherwise we copy the recognised fields into the canonical
|
|
30
|
+
* structure. Returning null lets the caller know we should revert to plain-string handling.
|
|
31
|
+
*/
|
|
32
|
+
function normalizeStructuredToolOutput(value) {
|
|
33
|
+
if (!isRecord(value)) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const type = value.type;
|
|
37
|
+
if (type === 'text' && typeof value.text === 'string') {
|
|
38
|
+
const output = { type: 'text', text: value.text };
|
|
39
|
+
if (isRecord(value.providerData)) {
|
|
40
|
+
output.providerData = value.providerData;
|
|
41
|
+
}
|
|
42
|
+
return output;
|
|
43
|
+
}
|
|
44
|
+
if (type === 'image') {
|
|
45
|
+
const output = { type: 'image' };
|
|
46
|
+
let imageString;
|
|
47
|
+
let imageFileId;
|
|
48
|
+
const fallbackImageMediaType = getInlineMediaType(value);
|
|
49
|
+
const imageField = value.image;
|
|
50
|
+
if (typeof imageField === 'string' && imageField.length > 0) {
|
|
51
|
+
imageString = imageField;
|
|
52
|
+
}
|
|
53
|
+
else if (isRecord(imageField)) {
|
|
54
|
+
const imageObj = imageField;
|
|
55
|
+
const inlineMediaType = getInlineMediaType(imageObj) ?? fallbackImageMediaType;
|
|
56
|
+
if (isNonEmptyString(imageObj.url)) {
|
|
57
|
+
imageString = imageObj.url;
|
|
58
|
+
}
|
|
59
|
+
else if (isNonEmptyString(imageObj.data)) {
|
|
60
|
+
imageString = formatInlineData(imageObj.data, inlineMediaType);
|
|
61
|
+
}
|
|
62
|
+
else if (imageObj.data instanceof Uint8Array &&
|
|
63
|
+
imageObj.data.length > 0) {
|
|
64
|
+
imageString = formatInlineData(imageObj.data, inlineMediaType);
|
|
65
|
+
}
|
|
66
|
+
if (!imageString) {
|
|
67
|
+
const candidateId = (isNonEmptyString(imageObj.fileId) && imageObj.fileId) ||
|
|
68
|
+
(isNonEmptyString(imageObj.id) && imageObj.id) ||
|
|
69
|
+
undefined;
|
|
70
|
+
if (candidateId) {
|
|
71
|
+
imageFileId = candidateId;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!imageString &&
|
|
76
|
+
typeof value.imageUrl === 'string' &&
|
|
77
|
+
value.imageUrl.length > 0) {
|
|
78
|
+
imageString = value.imageUrl;
|
|
79
|
+
}
|
|
80
|
+
if (!imageFileId &&
|
|
81
|
+
typeof value.fileId === 'string' &&
|
|
82
|
+
value.fileId.length > 0) {
|
|
83
|
+
imageFileId = value.fileId;
|
|
84
|
+
}
|
|
85
|
+
if (!imageString &&
|
|
86
|
+
typeof value.data === 'string' &&
|
|
87
|
+
value.data.length > 0) {
|
|
88
|
+
imageString = fallbackImageMediaType
|
|
89
|
+
? formatInlineData(value.data, fallbackImageMediaType)
|
|
90
|
+
: value.data;
|
|
91
|
+
}
|
|
92
|
+
else if (!imageString &&
|
|
93
|
+
value.data instanceof Uint8Array &&
|
|
94
|
+
value.data.length > 0) {
|
|
95
|
+
imageString = formatInlineData(value.data, fallbackImageMediaType);
|
|
96
|
+
}
|
|
97
|
+
if (typeof value.detail === 'string' && value.detail.length > 0) {
|
|
98
|
+
output.detail = value.detail;
|
|
99
|
+
}
|
|
100
|
+
if (imageString) {
|
|
101
|
+
output.image = imageString;
|
|
102
|
+
}
|
|
103
|
+
else if (imageFileId) {
|
|
104
|
+
output.image = { fileId: imageFileId };
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
if (isRecord(value.providerData)) {
|
|
110
|
+
output.providerData = value.providerData;
|
|
111
|
+
}
|
|
112
|
+
return output;
|
|
113
|
+
}
|
|
114
|
+
if (type === 'file') {
|
|
115
|
+
const fileValue = normalizeFileValue(value);
|
|
116
|
+
if (!fileValue) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const output = { type: 'file', file: fileValue };
|
|
120
|
+
if (isRecord(value.providerData)) {
|
|
121
|
+
output.providerData = value.providerData;
|
|
122
|
+
}
|
|
123
|
+
return output;
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Translates the normalized tool output into the protocol `input_*` items. This is the last hop
|
|
129
|
+
* before we hand the data to model-specific adapters, so we generate the exact schema expected by
|
|
130
|
+
* the protocol definitions.
|
|
131
|
+
*/
|
|
132
|
+
export function convertStructuredToolOutputToInputItem(output) {
|
|
133
|
+
if (output.type === 'text') {
|
|
134
|
+
const result = {
|
|
135
|
+
type: 'input_text',
|
|
136
|
+
text: output.text,
|
|
137
|
+
};
|
|
138
|
+
if (output.providerData) {
|
|
139
|
+
result.providerData = output.providerData;
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
if (output.type === 'image') {
|
|
144
|
+
const result = { type: 'input_image' };
|
|
145
|
+
if (typeof output.detail === 'string' && output.detail.length > 0) {
|
|
146
|
+
result.detail = output.detail;
|
|
147
|
+
}
|
|
148
|
+
if (typeof output.image === 'string' && output.image.length > 0) {
|
|
149
|
+
result.image = output.image;
|
|
150
|
+
}
|
|
151
|
+
else if (isRecord(output.image)) {
|
|
152
|
+
const imageObj = output.image;
|
|
153
|
+
const inlineMediaType = getInlineMediaType(imageObj);
|
|
154
|
+
if (isNonEmptyString(imageObj.url)) {
|
|
155
|
+
result.image = imageObj.url;
|
|
156
|
+
}
|
|
157
|
+
else if (isNonEmptyString(imageObj.data)) {
|
|
158
|
+
result.image =
|
|
159
|
+
inlineMediaType && !imageObj.data.startsWith('data:')
|
|
160
|
+
? asDataUrl(imageObj.data, inlineMediaType)
|
|
161
|
+
: imageObj.data;
|
|
162
|
+
}
|
|
163
|
+
else if (imageObj.data instanceof Uint8Array &&
|
|
164
|
+
imageObj.data.length > 0) {
|
|
165
|
+
const base64 = encodeUint8ArrayToBase64(imageObj.data);
|
|
166
|
+
result.image = asDataUrl(base64, inlineMediaType);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
const referencedId = (isNonEmptyString(imageObj.fileId) && imageObj.fileId) ||
|
|
170
|
+
(isNonEmptyString(imageObj.id) && imageObj.id) ||
|
|
171
|
+
undefined;
|
|
172
|
+
if (referencedId) {
|
|
173
|
+
result.image = { id: referencedId };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (output.providerData) {
|
|
178
|
+
result.providerData = output.providerData;
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
if (output.type === 'file') {
|
|
183
|
+
const result = { type: 'input_file' };
|
|
184
|
+
const fileValue = output.file;
|
|
185
|
+
if (typeof fileValue === 'string') {
|
|
186
|
+
result.file = fileValue;
|
|
187
|
+
}
|
|
188
|
+
else if (fileValue && typeof fileValue === 'object') {
|
|
189
|
+
const record = fileValue;
|
|
190
|
+
if ('data' in record && record.data) {
|
|
191
|
+
const mediaType = record.mediaType ?? 'text/plain';
|
|
192
|
+
if (typeof record.data === 'string') {
|
|
193
|
+
result.file = asDataUrl(record.data, mediaType);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
const base64 = encodeUint8ArrayToBase64(record.data);
|
|
197
|
+
result.file = asDataUrl(base64, mediaType);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else if (typeof record.url === 'string' && record.url.length > 0) {
|
|
201
|
+
result.file = { url: record.url };
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
const referencedId = (typeof record.id === 'string' &&
|
|
205
|
+
record.id.length > 0 &&
|
|
206
|
+
record.id) ||
|
|
207
|
+
(typeof record.fileId === 'string' && record.fileId.length > 0
|
|
208
|
+
? record.fileId
|
|
209
|
+
: undefined);
|
|
210
|
+
if (referencedId) {
|
|
211
|
+
result.file = { id: referencedId };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (typeof record.filename === 'string' && record.filename.length > 0) {
|
|
215
|
+
result.filename = record.filename;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (output.providerData) {
|
|
219
|
+
result.providerData = output.providerData;
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
const exhaustiveCheck = output;
|
|
224
|
+
return exhaustiveCheck;
|
|
225
|
+
}
|
|
226
|
+
function normalizeFileValue(value) {
|
|
227
|
+
const directFile = value.file;
|
|
228
|
+
if (typeof directFile === 'string' && directFile.length > 0) {
|
|
229
|
+
return directFile;
|
|
230
|
+
}
|
|
231
|
+
const normalizedObject = normalizeFileObjectCandidate(directFile);
|
|
232
|
+
if (normalizedObject) {
|
|
233
|
+
return normalizedObject;
|
|
234
|
+
}
|
|
235
|
+
const legacyValue = normalizeLegacyFileValue(value);
|
|
236
|
+
if (legacyValue) {
|
|
237
|
+
return legacyValue;
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
function normalizeFileObjectCandidate(value) {
|
|
242
|
+
if (!isRecord(value)) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
if ('data' in value && value.data !== undefined) {
|
|
246
|
+
const dataValue = value.data;
|
|
247
|
+
const hasStringData = typeof dataValue === 'string' && dataValue.length > 0;
|
|
248
|
+
const hasBinaryData = dataValue instanceof Uint8Array && dataValue.length > 0;
|
|
249
|
+
if (!hasStringData && !hasBinaryData) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
if (!isNonEmptyString(value.mediaType) ||
|
|
253
|
+
!isNonEmptyString(value.filename)) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
data: typeof dataValue === 'string' ? dataValue : new Uint8Array(dataValue),
|
|
258
|
+
mediaType: value.mediaType,
|
|
259
|
+
filename: value.filename,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
if (isNonEmptyString(value.url)) {
|
|
263
|
+
const result = { url: value.url };
|
|
264
|
+
if (isNonEmptyString(value.filename)) {
|
|
265
|
+
result.filename = value.filename;
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
const referencedId = (isNonEmptyString(value.id) && value.id) ||
|
|
270
|
+
(isNonEmptyString(value.fileId) && value.fileId);
|
|
271
|
+
if (referencedId) {
|
|
272
|
+
const result = { id: referencedId };
|
|
273
|
+
if (isNonEmptyString(value.filename)) {
|
|
274
|
+
result.filename = value.filename;
|
|
275
|
+
}
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
function normalizeLegacyFileValue(value) {
|
|
281
|
+
const filename = typeof value.filename === 'string' && value.filename.length > 0
|
|
282
|
+
? value.filename
|
|
283
|
+
: undefined;
|
|
284
|
+
const mediaType = typeof value.mediaType === 'string' && value.mediaType.length > 0
|
|
285
|
+
? value.mediaType
|
|
286
|
+
: undefined;
|
|
287
|
+
if (typeof value.fileData === 'string' && value.fileData.length > 0) {
|
|
288
|
+
if (!mediaType || !filename) {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
return { data: value.fileData, mediaType, filename };
|
|
292
|
+
}
|
|
293
|
+
if (value.fileData instanceof Uint8Array && value.fileData.length > 0) {
|
|
294
|
+
if (!mediaType || !filename) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
return { data: new Uint8Array(value.fileData), mediaType, filename };
|
|
298
|
+
}
|
|
299
|
+
if (typeof value.fileUrl === 'string' && value.fileUrl.length > 0) {
|
|
300
|
+
const result = { url: value.fileUrl };
|
|
301
|
+
if (filename) {
|
|
302
|
+
result.filename = filename;
|
|
303
|
+
}
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
if (typeof value.fileId === 'string' && value.fileId.length > 0) {
|
|
307
|
+
const result = { id: value.fileId };
|
|
308
|
+
if (filename) {
|
|
309
|
+
result.filename = filename;
|
|
310
|
+
}
|
|
311
|
+
return result;
|
|
312
|
+
}
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
function isRecord(value) {
|
|
316
|
+
return typeof value === 'object' && value !== null;
|
|
317
|
+
}
|
|
318
|
+
function isNonEmptyString(value) {
|
|
319
|
+
return typeof value === 'string' && value.length > 0;
|
|
320
|
+
}
|
|
321
|
+
function asDataUrl(base64, mediaType) {
|
|
322
|
+
return mediaType ? `data:${mediaType};base64,${base64}` : base64;
|
|
323
|
+
}
|
|
324
|
+
//# sourceMappingURL=toolOutputNormalization.mjs.map
|