@tanstack/openai-base 0.9.12 → 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 +17 -19
- package/dist/esm/adapters/chat-completions-text.js.map +1 -1
- package/dist/esm/adapters/responses-text.js +19 -21
- 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 +17 -19
- package/src/adapters/responses-text.ts +19 -21
|
@@ -256,12 +256,10 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
256
256
|
outputSchema.required,
|
|
257
257
|
)
|
|
258
258
|
|
|
259
|
-
const timestamp = Date.now()
|
|
260
259
|
const aguiState = {
|
|
261
260
|
runId: generateId(this.name),
|
|
262
261
|
threadId: chatOptions.threadId ?? generateId(this.name),
|
|
263
262
|
messageId: generateId(this.name),
|
|
264
|
-
timestamp,
|
|
265
263
|
hasEmittedRunStarted: false,
|
|
266
264
|
}
|
|
267
265
|
|
|
@@ -285,13 +283,13 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
285
283
|
type: EventType.REASONING_MESSAGE_END,
|
|
286
284
|
messageId: reasoningMessageId,
|
|
287
285
|
model: lastModel || chatOptions.model,
|
|
288
|
-
timestamp,
|
|
286
|
+
timestamp: Date.now(),
|
|
289
287
|
}
|
|
290
288
|
yield {
|
|
291
289
|
type: EventType.REASONING_END,
|
|
292
290
|
messageId: reasoningMessageId,
|
|
293
291
|
model: lastModel || chatOptions.model,
|
|
294
|
-
timestamp,
|
|
292
|
+
timestamp: Date.now(),
|
|
295
293
|
}
|
|
296
294
|
if (stepId) {
|
|
297
295
|
yield {
|
|
@@ -299,7 +297,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
299
297
|
stepName: stepId,
|
|
300
298
|
stepId,
|
|
301
299
|
model: lastModel || chatOptions.model,
|
|
302
|
-
timestamp,
|
|
300
|
+
timestamp: Date.now(),
|
|
303
301
|
content: accumulatedReasoning,
|
|
304
302
|
}
|
|
305
303
|
}
|
|
@@ -364,7 +362,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
364
362
|
runId: aguiState.runId,
|
|
365
363
|
threadId: aguiState.threadId,
|
|
366
364
|
model: chunk.model || chatOptions.model,
|
|
367
|
-
timestamp,
|
|
365
|
+
timestamp: Date.now(),
|
|
368
366
|
parentRunId: chatOptions.parentRunId,
|
|
369
367
|
}
|
|
370
368
|
}
|
|
@@ -379,21 +377,21 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
379
377
|
type: EventType.REASONING_START,
|
|
380
378
|
messageId: reasoningMessageId,
|
|
381
379
|
model: chunk.model || chatOptions.model,
|
|
382
|
-
timestamp,
|
|
380
|
+
timestamp: Date.now(),
|
|
383
381
|
}
|
|
384
382
|
yield {
|
|
385
383
|
type: EventType.REASONING_MESSAGE_START,
|
|
386
384
|
messageId: reasoningMessageId,
|
|
387
385
|
role: 'reasoning' as const,
|
|
388
386
|
model: chunk.model || chatOptions.model,
|
|
389
|
-
timestamp,
|
|
387
|
+
timestamp: Date.now(),
|
|
390
388
|
}
|
|
391
389
|
yield {
|
|
392
390
|
type: EventType.STEP_STARTED,
|
|
393
391
|
stepName: stepId,
|
|
394
392
|
stepId,
|
|
395
393
|
model: chunk.model || chatOptions.model,
|
|
396
|
-
timestamp,
|
|
394
|
+
timestamp: Date.now(),
|
|
397
395
|
stepType: 'thinking',
|
|
398
396
|
}
|
|
399
397
|
}
|
|
@@ -403,7 +401,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
403
401
|
messageId: reasoningMessageId,
|
|
404
402
|
delta: reasoning.text,
|
|
405
403
|
model: chunk.model || chatOptions.model,
|
|
406
|
-
timestamp,
|
|
404
|
+
timestamp: Date.now(),
|
|
407
405
|
}
|
|
408
406
|
}
|
|
409
407
|
|
|
@@ -420,7 +418,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
420
418
|
type: EventType.TEXT_MESSAGE_START,
|
|
421
419
|
messageId: aguiState.messageId,
|
|
422
420
|
model: chunk.model || chatOptions.model,
|
|
423
|
-
timestamp,
|
|
421
|
+
timestamp: Date.now(),
|
|
424
422
|
role: 'assistant',
|
|
425
423
|
}
|
|
426
424
|
}
|
|
@@ -431,7 +429,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
431
429
|
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
432
430
|
messageId: aguiState.messageId,
|
|
433
431
|
model: chunk.model || chatOptions.model,
|
|
434
|
-
timestamp,
|
|
432
|
+
timestamp: Date.now(),
|
|
435
433
|
delta: deltaContent,
|
|
436
434
|
content: accumulatedContent,
|
|
437
435
|
}
|
|
@@ -448,7 +446,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
448
446
|
type: EventType.TEXT_MESSAGE_END,
|
|
449
447
|
messageId: aguiState.messageId,
|
|
450
448
|
model: lastModel || chatOptions.model,
|
|
451
|
-
timestamp,
|
|
449
|
+
timestamp: Date.now(),
|
|
452
450
|
}
|
|
453
451
|
}
|
|
454
452
|
|
|
@@ -457,7 +455,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
457
455
|
type: EventType.RUN_ERROR,
|
|
458
456
|
runId: aguiState.runId,
|
|
459
457
|
model: lastModel || chatOptions.model,
|
|
460
|
-
timestamp,
|
|
458
|
+
timestamp: Date.now(),
|
|
461
459
|
message: `${this.name}.structuredOutputStream: response contained no content`,
|
|
462
460
|
code: 'empty-response',
|
|
463
461
|
error: {
|
|
@@ -476,7 +474,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
476
474
|
type: EventType.RUN_ERROR,
|
|
477
475
|
runId: aguiState.runId,
|
|
478
476
|
model: lastModel || chatOptions.model,
|
|
479
|
-
timestamp,
|
|
477
|
+
timestamp: Date.now(),
|
|
480
478
|
message: `Failed to parse structured output as JSON. Content: ${accumulatedContent.slice(0, 200)}${accumulatedContent.length > 200 ? '...' : ''}`,
|
|
481
479
|
code: 'parse-error',
|
|
482
480
|
error: {
|
|
@@ -498,7 +496,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
498
496
|
...(accumulatedReasoning ? { reasoning: accumulatedReasoning } : {}),
|
|
499
497
|
},
|
|
500
498
|
model: lastModel || chatOptions.model,
|
|
501
|
-
timestamp,
|
|
499
|
+
timestamp: Date.now(),
|
|
502
500
|
}
|
|
503
501
|
|
|
504
502
|
yield {
|
|
@@ -506,7 +504,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
506
504
|
runId: aguiState.runId,
|
|
507
505
|
threadId: aguiState.threadId,
|
|
508
506
|
model: lastModel || chatOptions.model,
|
|
509
|
-
timestamp,
|
|
507
|
+
timestamp: Date.now(),
|
|
510
508
|
finishReason: 'stop',
|
|
511
509
|
...(lastUsage && {
|
|
512
510
|
usage: buildChatCompletionsUsage(lastUsage),
|
|
@@ -520,7 +518,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
520
518
|
runId: aguiState.runId,
|
|
521
519
|
threadId: aguiState.threadId,
|
|
522
520
|
model: chatOptions.model,
|
|
523
|
-
timestamp,
|
|
521
|
+
timestamp: Date.now(),
|
|
524
522
|
parentRunId: chatOptions.parentRunId,
|
|
525
523
|
}
|
|
526
524
|
}
|
|
@@ -540,7 +538,7 @@ export abstract class OpenAIBaseChatCompletionsTextAdapter<
|
|
|
540
538
|
type: EventType.RUN_ERROR,
|
|
541
539
|
runId: aguiState.runId,
|
|
542
540
|
model: lastModel || chatOptions.model,
|
|
543
|
-
timestamp,
|
|
541
|
+
timestamp: Date.now(),
|
|
544
542
|
message: errorPayload.message,
|
|
545
543
|
...(resolvedCode !== undefined && { code: resolvedCode }),
|
|
546
544
|
...(rawEvent !== undefined && { rawEvent }),
|
|
@@ -303,12 +303,10 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
303
303
|
outputSchema.required,
|
|
304
304
|
)
|
|
305
305
|
|
|
306
|
-
const timestamp = Date.now()
|
|
307
306
|
const aguiState = {
|
|
308
307
|
runId: generateId(this.name),
|
|
309
308
|
threadId: chatOptions.threadId ?? generateId(this.name),
|
|
310
309
|
messageId: generateId(this.name),
|
|
311
|
-
timestamp,
|
|
312
310
|
hasEmittedRunStarted: false,
|
|
313
311
|
}
|
|
314
312
|
|
|
@@ -330,13 +328,13 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
330
328
|
type: EventType.REASONING_MESSAGE_END,
|
|
331
329
|
messageId: reasoningMessageId,
|
|
332
330
|
model,
|
|
333
|
-
timestamp,
|
|
331
|
+
timestamp: Date.now(),
|
|
334
332
|
}
|
|
335
333
|
yield {
|
|
336
334
|
type: EventType.REASONING_END,
|
|
337
335
|
messageId: reasoningMessageId,
|
|
338
336
|
model,
|
|
339
|
-
timestamp,
|
|
337
|
+
timestamp: Date.now(),
|
|
340
338
|
}
|
|
341
339
|
if (stepId) {
|
|
342
340
|
yield {
|
|
@@ -344,7 +342,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
344
342
|
stepName: stepId,
|
|
345
343
|
stepId,
|
|
346
344
|
model,
|
|
347
|
-
timestamp,
|
|
345
|
+
timestamp: Date.now(),
|
|
348
346
|
content: accumulatedReasoning,
|
|
349
347
|
}
|
|
350
348
|
}
|
|
@@ -361,21 +359,21 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
361
359
|
type: EventType.REASONING_START,
|
|
362
360
|
messageId: reasoningMessageId,
|
|
363
361
|
model,
|
|
364
|
-
timestamp,
|
|
362
|
+
timestamp: Date.now(),
|
|
365
363
|
}
|
|
366
364
|
yield {
|
|
367
365
|
type: EventType.REASONING_MESSAGE_START,
|
|
368
366
|
messageId: reasoningMessageId,
|
|
369
367
|
role: 'reasoning' as const,
|
|
370
368
|
model,
|
|
371
|
-
timestamp,
|
|
369
|
+
timestamp: Date.now(),
|
|
372
370
|
}
|
|
373
371
|
yield {
|
|
374
372
|
type: EventType.STEP_STARTED,
|
|
375
373
|
stepName: stepId,
|
|
376
374
|
stepId,
|
|
377
375
|
model,
|
|
378
|
-
timestamp,
|
|
376
|
+
timestamp: Date.now(),
|
|
379
377
|
stepType: 'thinking',
|
|
380
378
|
}
|
|
381
379
|
}.bind(this)
|
|
@@ -418,7 +416,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
418
416
|
runId: aguiState.runId,
|
|
419
417
|
threadId: aguiState.threadId,
|
|
420
418
|
model,
|
|
421
|
-
timestamp,
|
|
419
|
+
timestamp: Date.now(),
|
|
422
420
|
parentRunId: chatOptions.parentRunId,
|
|
423
421
|
}
|
|
424
422
|
}
|
|
@@ -442,7 +440,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
442
440
|
type: EventType.RUN_ERROR,
|
|
443
441
|
runId: aguiState.runId,
|
|
444
442
|
model,
|
|
445
|
-
timestamp,
|
|
443
|
+
timestamp: Date.now(),
|
|
446
444
|
message: `Model refused: ${delta}`,
|
|
447
445
|
code: 'refusal',
|
|
448
446
|
error: { message: `Model refused: ${delta}`, code: 'refusal' },
|
|
@@ -471,7 +469,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
471
469
|
messageId: reasoningMessageId,
|
|
472
470
|
delta: reasoningDelta,
|
|
473
471
|
model,
|
|
474
|
-
timestamp,
|
|
472
|
+
timestamp: Date.now(),
|
|
475
473
|
}
|
|
476
474
|
continue
|
|
477
475
|
}
|
|
@@ -493,7 +491,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
493
491
|
type: EventType.TEXT_MESSAGE_START,
|
|
494
492
|
messageId: aguiState.messageId,
|
|
495
493
|
model,
|
|
496
|
-
timestamp,
|
|
494
|
+
timestamp: Date.now(),
|
|
497
495
|
role: 'assistant',
|
|
498
496
|
}
|
|
499
497
|
}
|
|
@@ -502,7 +500,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
502
500
|
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
503
501
|
messageId: aguiState.messageId,
|
|
504
502
|
model,
|
|
505
|
-
timestamp,
|
|
503
|
+
timestamp: Date.now(),
|
|
506
504
|
delta: textDelta,
|
|
507
505
|
content: accumulatedContent,
|
|
508
506
|
}
|
|
@@ -531,7 +529,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
531
529
|
type: EventType.RUN_ERROR,
|
|
532
530
|
runId: aguiState.runId,
|
|
533
531
|
model,
|
|
534
|
-
timestamp,
|
|
532
|
+
timestamp: Date.now(),
|
|
535
533
|
message,
|
|
536
534
|
...(code !== undefined && { code }),
|
|
537
535
|
error: { message, ...(code !== undefined && { code }) },
|
|
@@ -547,7 +545,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
547
545
|
type: EventType.TEXT_MESSAGE_END,
|
|
548
546
|
messageId: aguiState.messageId,
|
|
549
547
|
model,
|
|
550
|
-
timestamp,
|
|
548
|
+
timestamp: Date.now(),
|
|
551
549
|
}
|
|
552
550
|
}
|
|
553
551
|
|
|
@@ -556,7 +554,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
556
554
|
type: EventType.RUN_ERROR,
|
|
557
555
|
runId: aguiState.runId,
|
|
558
556
|
model,
|
|
559
|
-
timestamp,
|
|
557
|
+
timestamp: Date.now(),
|
|
560
558
|
message: `${this.name}.structuredOutputStream: response contained no content`,
|
|
561
559
|
code: 'empty-response',
|
|
562
560
|
error: {
|
|
@@ -575,7 +573,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
575
573
|
type: EventType.RUN_ERROR,
|
|
576
574
|
runId: aguiState.runId,
|
|
577
575
|
model,
|
|
578
|
-
timestamp,
|
|
576
|
+
timestamp: Date.now(),
|
|
579
577
|
message: `Failed to parse structured output as JSON. Content: ${accumulatedContent.slice(0, 200)}${accumulatedContent.length > 200 ? '...' : ''}`,
|
|
580
578
|
code: 'parse-error',
|
|
581
579
|
error: {
|
|
@@ -600,7 +598,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
600
598
|
...(accumulatedReasoning ? { reasoning: accumulatedReasoning } : {}),
|
|
601
599
|
},
|
|
602
600
|
model,
|
|
603
|
-
timestamp,
|
|
601
|
+
timestamp: Date.now(),
|
|
604
602
|
}
|
|
605
603
|
|
|
606
604
|
yield {
|
|
@@ -608,7 +606,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
608
606
|
runId: aguiState.runId,
|
|
609
607
|
threadId: aguiState.threadId,
|
|
610
608
|
model,
|
|
611
|
-
timestamp,
|
|
609
|
+
timestamp: Date.now(),
|
|
612
610
|
finishReason: 'stop',
|
|
613
611
|
...(usage && {
|
|
614
612
|
usage: buildResponsesUsage(usage),
|
|
@@ -622,7 +620,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
622
620
|
runId: aguiState.runId,
|
|
623
621
|
threadId: aguiState.threadId,
|
|
624
622
|
model,
|
|
625
|
-
timestamp,
|
|
623
|
+
timestamp: Date.now(),
|
|
626
624
|
parentRunId: chatOptions.parentRunId,
|
|
627
625
|
}
|
|
628
626
|
}
|
|
@@ -641,7 +639,7 @@ export abstract class OpenAIBaseResponsesTextAdapter<
|
|
|
641
639
|
type: EventType.RUN_ERROR,
|
|
642
640
|
runId: aguiState.runId,
|
|
643
641
|
model,
|
|
644
|
-
timestamp,
|
|
642
|
+
timestamp: Date.now(),
|
|
645
643
|
message: errorPayload.message,
|
|
646
644
|
...(resolvedCode !== undefined && { code: resolvedCode }),
|
|
647
645
|
...(rawEvent !== undefined && { rawEvent }),
|