@core-ai/core-ai 0.13.1 → 0.15.0
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/index.d.ts +31 -0
- package/dist/index.js +39 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ type UserContentPart = TextPart | ImagePart | FilePart;
|
|
|
13
13
|
type TextPart = {
|
|
14
14
|
type: 'text';
|
|
15
15
|
text: string;
|
|
16
|
+
/**
|
|
17
|
+
* Application-owned metadata for this part. Provider adapters ignore this
|
|
18
|
+
* field and never serialize it to provider APIs.
|
|
19
|
+
*/
|
|
20
|
+
metadata?: Record<string, unknown>;
|
|
16
21
|
};
|
|
17
22
|
type ImagePart = {
|
|
18
23
|
type: 'image';
|
|
@@ -38,10 +43,20 @@ type ReasoningConfig = {
|
|
|
38
43
|
type AssistantTextPart = {
|
|
39
44
|
type: 'text';
|
|
40
45
|
text: string;
|
|
46
|
+
/**
|
|
47
|
+
* Application-owned metadata for this part. Provider adapters ignore this
|
|
48
|
+
* field and never serialize it to provider APIs.
|
|
49
|
+
*/
|
|
50
|
+
metadata?: Record<string, unknown>;
|
|
41
51
|
};
|
|
42
52
|
type ReasoningPart = {
|
|
43
53
|
type: 'reasoning';
|
|
44
54
|
text: string;
|
|
55
|
+
/**
|
|
56
|
+
* Application-owned metadata for this part. Provider adapters ignore this
|
|
57
|
+
* field and never serialize it to provider APIs.
|
|
58
|
+
*/
|
|
59
|
+
metadata?: Record<string, unknown>;
|
|
45
60
|
/**
|
|
46
61
|
* Provider-namespaced metadata for this reasoning block. The top-level key is
|
|
47
62
|
* the provider identifier (e.g. `'anthropic'`, `'openai'`), which also serves as
|
|
@@ -68,12 +83,22 @@ type ToolCall = {
|
|
|
68
83
|
id: string;
|
|
69
84
|
name: string;
|
|
70
85
|
arguments: Record<string, unknown>;
|
|
86
|
+
/**
|
|
87
|
+
* Application-owned metadata for this tool call. Provider adapters ignore
|
|
88
|
+
* this field and never serialize it to provider APIs.
|
|
89
|
+
*/
|
|
90
|
+
metadata?: Record<string, unknown>;
|
|
71
91
|
};
|
|
72
92
|
type ToolResultMessage = {
|
|
73
93
|
role: 'tool';
|
|
74
94
|
toolCallId: string;
|
|
75
95
|
content: string;
|
|
76
96
|
isError?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Application-owned metadata for this tool result. Provider adapters ignore
|
|
99
|
+
* this field and never serialize it to provider APIs.
|
|
100
|
+
*/
|
|
101
|
+
metadata?: Record<string, unknown>;
|
|
77
102
|
};
|
|
78
103
|
type ToolDefinition = {
|
|
79
104
|
name: string;
|
|
@@ -230,10 +255,16 @@ type StreamEvent = {
|
|
|
230
255
|
text: string;
|
|
231
256
|
} | {
|
|
232
257
|
type: 'reasoning-end';
|
|
258
|
+
metadata?: Record<string, unknown>;
|
|
233
259
|
providerMetadata?: Record<string, Record<string, unknown>>;
|
|
260
|
+
} | {
|
|
261
|
+
type: 'text-start';
|
|
234
262
|
} | {
|
|
235
263
|
type: 'text-delta';
|
|
236
264
|
text: string;
|
|
265
|
+
} | {
|
|
266
|
+
type: 'text-end';
|
|
267
|
+
metadata?: Record<string, unknown>;
|
|
237
268
|
} | {
|
|
238
269
|
type: 'tool-call-start';
|
|
239
270
|
toolCallId: string;
|
package/dist/index.js
CHANGED
|
@@ -81,7 +81,7 @@ function zodSchemaToJsonSchema(schema) {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// src/model-id.ts
|
|
84
|
-
var MODEL_DATE_SUFFIX_PATTERN =
|
|
84
|
+
var MODEL_DATE_SUFFIX_PATTERN = /[-@](?:\d{8}|\d{4}-\d{2}-\d{2})$/;
|
|
85
85
|
function stripModelDateSuffix(modelId) {
|
|
86
86
|
return modelId.replace(MODEL_DATE_SUFFIX_PATTERN, "");
|
|
87
87
|
}
|
|
@@ -423,8 +423,11 @@ function createChatStream(source, options = {}) {
|
|
|
423
423
|
})() : source;
|
|
424
424
|
const parts = [];
|
|
425
425
|
let textBuffer = "";
|
|
426
|
+
let textMetadata;
|
|
426
427
|
let reasoningBuffer = "";
|
|
428
|
+
let reasoningMetadata;
|
|
427
429
|
let reasoningProviderMetadata;
|
|
430
|
+
let insideText = false;
|
|
428
431
|
let insideReasoning = false;
|
|
429
432
|
let finishReason = "unknown";
|
|
430
433
|
let usage = {
|
|
@@ -438,52 +441,78 @@ function createChatStream(source, options = {}) {
|
|
|
438
441
|
};
|
|
439
442
|
const flushText = () => {
|
|
440
443
|
if (textBuffer.length === 0) {
|
|
444
|
+
textMetadata = void 0;
|
|
441
445
|
return;
|
|
442
446
|
}
|
|
443
447
|
parts.push({
|
|
444
448
|
type: "text",
|
|
445
|
-
text: textBuffer
|
|
449
|
+
text: textBuffer,
|
|
450
|
+
...textMetadata ? { metadata: textMetadata } : {}
|
|
446
451
|
});
|
|
447
452
|
textBuffer = "";
|
|
453
|
+
textMetadata = void 0;
|
|
448
454
|
};
|
|
449
455
|
const flushReasoning = () => {
|
|
450
456
|
if (reasoningBuffer.length === 0 && reasoningProviderMetadata === void 0) {
|
|
457
|
+
reasoningMetadata = void 0;
|
|
451
458
|
return;
|
|
452
459
|
}
|
|
453
460
|
parts.push({
|
|
454
461
|
type: "reasoning",
|
|
455
462
|
text: reasoningBuffer,
|
|
463
|
+
...reasoningMetadata ? { metadata: reasoningMetadata } : {},
|
|
456
464
|
...reasoningProviderMetadata ? { providerMetadata: reasoningProviderMetadata } : {}
|
|
457
465
|
});
|
|
458
466
|
reasoningBuffer = "";
|
|
467
|
+
reasoningMetadata = void 0;
|
|
459
468
|
reasoningProviderMetadata = void 0;
|
|
460
469
|
};
|
|
470
|
+
const startText = () => {
|
|
471
|
+
if (insideReasoning) {
|
|
472
|
+
flushReasoning();
|
|
473
|
+
insideReasoning = false;
|
|
474
|
+
}
|
|
475
|
+
flushText();
|
|
476
|
+
insideText = true;
|
|
477
|
+
};
|
|
461
478
|
const startReasoning = () => {
|
|
462
479
|
flushText();
|
|
480
|
+
insideText = false;
|
|
463
481
|
flushReasoning();
|
|
464
482
|
insideReasoning = true;
|
|
465
483
|
};
|
|
466
484
|
const appendReasoning = (text) => {
|
|
467
485
|
if (!insideReasoning) {
|
|
468
486
|
flushText();
|
|
487
|
+
insideText = false;
|
|
469
488
|
insideReasoning = true;
|
|
470
489
|
}
|
|
471
490
|
reasoningBuffer += text;
|
|
472
491
|
};
|
|
473
|
-
const endReasoning = (providerMetadata) => {
|
|
492
|
+
const endReasoning = (providerMetadata, metadata) => {
|
|
474
493
|
reasoningProviderMetadata = providerMetadata;
|
|
494
|
+
reasoningMetadata = metadata;
|
|
475
495
|
flushReasoning();
|
|
476
496
|
insideReasoning = false;
|
|
477
497
|
};
|
|
498
|
+
const endText = (metadata) => {
|
|
499
|
+
textMetadata = metadata;
|
|
500
|
+
flushText();
|
|
501
|
+
insideText = false;
|
|
502
|
+
};
|
|
478
503
|
const appendText = (text) => {
|
|
479
504
|
if (insideReasoning) {
|
|
480
505
|
flushReasoning();
|
|
481
506
|
insideReasoning = false;
|
|
482
507
|
}
|
|
508
|
+
if (!insideText) {
|
|
509
|
+
insideText = true;
|
|
510
|
+
}
|
|
483
511
|
textBuffer += text;
|
|
484
512
|
};
|
|
485
513
|
const appendToolCall = (toolCall) => {
|
|
486
514
|
flushText();
|
|
515
|
+
insideText = false;
|
|
487
516
|
flushReasoning();
|
|
488
517
|
insideReasoning = false;
|
|
489
518
|
parts.push({
|
|
@@ -525,6 +554,9 @@ function createChatStream(source, options = {}) {
|
|
|
525
554
|
signal,
|
|
526
555
|
reduceEvent(event) {
|
|
527
556
|
switch (event.type) {
|
|
557
|
+
case "text-start":
|
|
558
|
+
startText();
|
|
559
|
+
break;
|
|
528
560
|
case "reasoning-start":
|
|
529
561
|
startReasoning();
|
|
530
562
|
break;
|
|
@@ -532,11 +564,14 @@ function createChatStream(source, options = {}) {
|
|
|
532
564
|
appendReasoning(event.text);
|
|
533
565
|
break;
|
|
534
566
|
case "reasoning-end":
|
|
535
|
-
endReasoning(event.providerMetadata);
|
|
567
|
+
endReasoning(event.providerMetadata, event.metadata);
|
|
536
568
|
break;
|
|
537
569
|
case "text-delta":
|
|
538
570
|
appendText(event.text);
|
|
539
571
|
break;
|
|
572
|
+
case "text-end":
|
|
573
|
+
endText(event.metadata);
|
|
574
|
+
break;
|
|
540
575
|
case "tool-call-end":
|
|
541
576
|
appendToolCall(event.toolCall);
|
|
542
577
|
break;
|