@tanstack/openai-base 0.9.11 → 0.9.13
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/esm/adapters/chat-completions-text.js +25 -23
- package/dist/esm/adapters/chat-completions-text.js.map +1 -1
- package/dist/esm/adapters/responses-text.js +24 -23
- package/dist/esm/adapters/responses-text.js.map +1 -1
- package/dist/esm/utils/schema-converter.js.map +1 -1
- package/package.json +5 -5
- package/src/adapters/chat-completions-text.ts +21 -19
- package/src/adapters/responses-text.ts +23 -21
|
@@ -113,9 +113,12 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
113
113
|
} catch {
|
|
114
114
|
throw new Error(`Failed to parse structured output as JSON. Content: ${rawText.slice(0, 200)}${rawText.length > 200 ? "..." : ""}`);
|
|
115
115
|
}
|
|
116
|
+
const transformed = this.transformStructuredOutput(parsed);
|
|
117
|
+
const usage = buildResponsesUsage(response.usage);
|
|
116
118
|
return {
|
|
117
|
-
data:
|
|
118
|
-
rawText
|
|
119
|
+
data: transformed,
|
|
120
|
+
rawText,
|
|
121
|
+
...usage && { usage }
|
|
119
122
|
};
|
|
120
123
|
} catch (error) {
|
|
121
124
|
chatOptions.logger.errors(`${this.name}.structuredOutput fatal`, {
|
|
@@ -142,12 +145,10 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
142
145
|
const { chatOptions, outputSchema } = options;
|
|
143
146
|
const requestParams = this.mapOptionsToRequest(chatOptions);
|
|
144
147
|
const jsonSchema = this.makeStructuredOutputCompatible(outputSchema, outputSchema.required);
|
|
145
|
-
const timestamp = Date.now();
|
|
146
148
|
const aguiState = {
|
|
147
149
|
runId: generateId(this.name),
|
|
148
150
|
threadId: chatOptions.threadId ?? generateId(this.name),
|
|
149
151
|
messageId: generateId(this.name),
|
|
150
|
-
timestamp,
|
|
151
152
|
hasEmittedRunStarted: false
|
|
152
153
|
};
|
|
153
154
|
let accumulatedContent = "";
|
|
@@ -165,20 +166,20 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
165
166
|
type: EventType.REASONING_MESSAGE_END,
|
|
166
167
|
messageId: reasoningMessageId,
|
|
167
168
|
model,
|
|
168
|
-
timestamp
|
|
169
|
+
timestamp: Date.now()
|
|
169
170
|
};
|
|
170
171
|
yield {
|
|
171
172
|
type: EventType.REASONING_END,
|
|
172
173
|
messageId: reasoningMessageId,
|
|
173
174
|
model,
|
|
174
|
-
timestamp
|
|
175
|
+
timestamp: Date.now()
|
|
175
176
|
};
|
|
176
177
|
if (stepId) yield {
|
|
177
178
|
type: EventType.STEP_FINISHED,
|
|
178
179
|
stepName: stepId,
|
|
179
180
|
stepId,
|
|
180
181
|
model,
|
|
181
|
-
timestamp,
|
|
182
|
+
timestamp: Date.now(),
|
|
182
183
|
content: accumulatedReasoning
|
|
183
184
|
};
|
|
184
185
|
}
|
|
@@ -191,21 +192,21 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
191
192
|
type: EventType.REASONING_START,
|
|
192
193
|
messageId: reasoningMessageId,
|
|
193
194
|
model,
|
|
194
|
-
timestamp
|
|
195
|
+
timestamp: Date.now()
|
|
195
196
|
};
|
|
196
197
|
yield {
|
|
197
198
|
type: EventType.REASONING_MESSAGE_START,
|
|
198
199
|
messageId: reasoningMessageId,
|
|
199
200
|
role: "reasoning",
|
|
200
201
|
model,
|
|
201
|
-
timestamp
|
|
202
|
+
timestamp: Date.now()
|
|
202
203
|
};
|
|
203
204
|
yield {
|
|
204
205
|
type: EventType.STEP_STARTED,
|
|
205
206
|
stepName: stepId,
|
|
206
207
|
stepId,
|
|
207
208
|
model,
|
|
208
|
-
timestamp,
|
|
209
|
+
timestamp: Date.now(),
|
|
209
210
|
stepType: "thinking"
|
|
210
211
|
};
|
|
211
212
|
}.bind(this);
|
|
@@ -237,7 +238,7 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
237
238
|
runId: aguiState.runId,
|
|
238
239
|
threadId: aguiState.threadId,
|
|
239
240
|
model,
|
|
240
|
-
timestamp,
|
|
241
|
+
timestamp: Date.now(),
|
|
241
242
|
parentRunId: chatOptions.parentRunId
|
|
242
243
|
};
|
|
243
244
|
}
|
|
@@ -252,7 +253,7 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
252
253
|
type: EventType.RUN_ERROR,
|
|
253
254
|
runId: aguiState.runId,
|
|
254
255
|
model,
|
|
255
|
-
timestamp,
|
|
256
|
+
timestamp: Date.now(),
|
|
256
257
|
message: `Model refused: ${delta}`,
|
|
257
258
|
code: "refusal",
|
|
258
259
|
error: {
|
|
@@ -274,7 +275,7 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
274
275
|
messageId: reasoningMessageId,
|
|
275
276
|
delta: reasoningDelta,
|
|
276
277
|
model,
|
|
277
|
-
timestamp
|
|
278
|
+
timestamp: Date.now()
|
|
278
279
|
};
|
|
279
280
|
continue;
|
|
280
281
|
}
|
|
@@ -289,7 +290,7 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
289
290
|
type: EventType.TEXT_MESSAGE_START,
|
|
290
291
|
messageId: aguiState.messageId,
|
|
291
292
|
model,
|
|
292
|
-
timestamp,
|
|
293
|
+
timestamp: Date.now(),
|
|
293
294
|
role: "assistant"
|
|
294
295
|
};
|
|
295
296
|
}
|
|
@@ -298,7 +299,7 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
298
299
|
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
299
300
|
messageId: aguiState.messageId,
|
|
300
301
|
model,
|
|
301
|
-
timestamp,
|
|
302
|
+
timestamp: Date.now(),
|
|
302
303
|
delta: textDelta,
|
|
303
304
|
content: accumulatedContent
|
|
304
305
|
};
|
|
@@ -318,7 +319,7 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
318
319
|
type: EventType.RUN_ERROR,
|
|
319
320
|
runId: aguiState.runId,
|
|
320
321
|
model,
|
|
321
|
-
timestamp,
|
|
322
|
+
timestamp: Date.now(),
|
|
322
323
|
message,
|
|
323
324
|
...code !== void 0 && { code },
|
|
324
325
|
error: {
|
|
@@ -334,14 +335,14 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
334
335
|
type: EventType.TEXT_MESSAGE_END,
|
|
335
336
|
messageId: aguiState.messageId,
|
|
336
337
|
model,
|
|
337
|
-
timestamp
|
|
338
|
+
timestamp: Date.now()
|
|
338
339
|
};
|
|
339
340
|
if (accumulatedContent.length === 0) {
|
|
340
341
|
yield {
|
|
341
342
|
type: EventType.RUN_ERROR,
|
|
342
343
|
runId: aguiState.runId,
|
|
343
344
|
model,
|
|
344
|
-
timestamp,
|
|
345
|
+
timestamp: Date.now(),
|
|
345
346
|
message: `${this.name}.structuredOutputStream: response contained no content`,
|
|
346
347
|
code: "empty-response",
|
|
347
348
|
error: {
|
|
@@ -359,7 +360,7 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
359
360
|
type: EventType.RUN_ERROR,
|
|
360
361
|
runId: aguiState.runId,
|
|
361
362
|
model,
|
|
362
|
-
timestamp,
|
|
363
|
+
timestamp: Date.now(),
|
|
363
364
|
message: `Failed to parse structured output as JSON. Content: ${accumulatedContent.slice(0, 200)}${accumulatedContent.length > 200 ? "..." : ""}`,
|
|
364
365
|
code: "parse-error",
|
|
365
366
|
error: {
|
|
@@ -379,14 +380,14 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
379
380
|
...accumulatedReasoning ? { reasoning: accumulatedReasoning } : {}
|
|
380
381
|
},
|
|
381
382
|
model,
|
|
382
|
-
timestamp
|
|
383
|
+
timestamp: Date.now()
|
|
383
384
|
};
|
|
384
385
|
yield {
|
|
385
386
|
type: EventType.RUN_FINISHED,
|
|
386
387
|
runId: aguiState.runId,
|
|
387
388
|
threadId: aguiState.threadId,
|
|
388
389
|
model,
|
|
389
|
-
timestamp,
|
|
390
|
+
timestamp: Date.now(),
|
|
390
391
|
finishReason: "stop",
|
|
391
392
|
...usage && { usage: buildResponsesUsage(usage) }
|
|
392
393
|
};
|
|
@@ -398,7 +399,7 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
398
399
|
runId: aguiState.runId,
|
|
399
400
|
threadId: aguiState.threadId,
|
|
400
401
|
model,
|
|
401
|
-
timestamp,
|
|
402
|
+
timestamp: Date.now(),
|
|
402
403
|
parentRunId: chatOptions.parentRunId
|
|
403
404
|
};
|
|
404
405
|
}
|
|
@@ -410,7 +411,7 @@ var OpenAIBaseResponsesTextAdapter = class extends BaseTextAdapter {
|
|
|
410
411
|
type: EventType.RUN_ERROR,
|
|
411
412
|
runId: aguiState.runId,
|
|
412
413
|
model,
|
|
413
|
-
timestamp,
|
|
414
|
+
timestamp: Date.now(),
|
|
414
415
|
message: errorPayload.message,
|
|
415
416
|
...resolvedCode !== void 0 && { code: resolvedCode },
|
|
416
417
|
...rawEvent !== void 0 && { rawEvent },
|