@core-ai/core-ai 0.3.0 → 0.4.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 +29 -16
- package/dist/index.js +14 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -106,28 +106,41 @@ type FinishReason = 'stop' | 'length' | 'tool-calls' | 'content-filter' | 'unkno
|
|
|
106
106
|
/**
|
|
107
107
|
* Token usage reported by the model after a chat completion.
|
|
108
108
|
*
|
|
109
|
-
* `
|
|
110
|
-
*
|
|
111
|
-
* `
|
|
112
|
-
* For non-reasoning models (or providers that don't report it separately)
|
|
113
|
-
* this will be `0`.
|
|
109
|
+
* `inputTokens` is always the **total** input token count, including cached
|
|
110
|
+
* reads and cache writes. Anthropic's `input_tokens` is normalized by adding
|
|
111
|
+
* `cache_read_input_tokens` and `cache_creation_input_tokens`.
|
|
114
112
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* included in `output_tokens` but not reported separately by the API).
|
|
113
|
+
* `outputTokens` is always the **total** output token count, including both
|
|
114
|
+
* visible text and internal reasoning.
|
|
115
|
+
*
|
|
116
|
+
* `inputTokenDetails` and `outputTokenDetails` provide provider-independent
|
|
117
|
+
* breakdowns for cache and reasoning accounting.
|
|
121
118
|
*/
|
|
122
119
|
type ChatUsage = {
|
|
123
|
-
/**
|
|
120
|
+
/** Total input tokens, including cached and cache-write tokens. */
|
|
124
121
|
inputTokens: number;
|
|
125
122
|
/** Total output tokens, including both visible text and reasoning. */
|
|
126
123
|
outputTokens: number;
|
|
127
|
-
/**
|
|
124
|
+
/** Breakdown of input token categories. */
|
|
125
|
+
inputTokenDetails: ChatInputTokenDetails;
|
|
126
|
+
/** Breakdown of output token categories. */
|
|
127
|
+
outputTokenDetails: ChatOutputTokenDetails;
|
|
128
|
+
};
|
|
129
|
+
type ChatInputTokenDetails = {
|
|
130
|
+
/** Input tokens served from a prior cache entry. Subset of `inputTokens`. */
|
|
131
|
+
cacheReadTokens: number;
|
|
132
|
+
/**
|
|
133
|
+
* Input tokens written to cache for future reuse. Subset of `inputTokens`.
|
|
134
|
+
* Only Anthropic reports this; other providers report `0`.
|
|
135
|
+
*/
|
|
136
|
+
cacheWriteTokens: number;
|
|
137
|
+
};
|
|
138
|
+
type ChatOutputTokenDetails = {
|
|
139
|
+
/**
|
|
140
|
+
* Tokens consumed by internal reasoning/thinking. Subset of `outputTokens`.
|
|
141
|
+
* For non-reasoning models (or providers that don't report it), this is `0`.
|
|
142
|
+
*/
|
|
128
143
|
reasoningTokens: number;
|
|
129
|
-
/** Sum of all tokens (`inputTokens + outputTokens`). */
|
|
130
|
-
totalTokens: number;
|
|
131
144
|
};
|
|
132
145
|
type StreamEvent = {
|
|
133
146
|
type: 'content-delta';
|
|
@@ -271,4 +284,4 @@ type GenerateImageParams = ImageGenerateOptions & {
|
|
|
271
284
|
};
|
|
272
285
|
declare function generateImage(params: GenerateImageParams): Promise<ImageGenerateResult>;
|
|
273
286
|
|
|
274
|
-
export { type AssistantMessage, type ChatModel, type ChatUsage, type EmbedOptions, type EmbedResult, type EmbeddingModel, type EmbeddingUsage, type FilePart, type FinishReason, type GenerateObjectOptions, type GenerateObjectResult, type GenerateOptions, type GenerateResult, type GeneratedImage, type ImageGenerateOptions, type ImageGenerateResult, type ImageModel, type ImagePart, LLMError, type Message, type ModelConfig, type ObjectStreamEvent, ProviderError, type StreamEvent, type StreamObjectOptions, type StreamObjectResult, type StreamResult, StructuredOutputError, StructuredOutputNoObjectGeneratedError, StructuredOutputParseError, StructuredOutputValidationError, type SystemMessage, type TextPart, type ToolCall, type ToolChoice, type ToolDefinition, type ToolResultMessage, type ToolSet, type UserContentPart, type UserMessage, createObjectStreamResult, createStreamResult, defineTool, embed, generate, generateImage, generateObject, stream, streamObject };
|
|
287
|
+
export { type AssistantMessage, type ChatInputTokenDetails, type ChatModel, type ChatOutputTokenDetails, type ChatUsage, type EmbedOptions, type EmbedResult, type EmbeddingModel, type EmbeddingUsage, type FilePart, type FinishReason, type GenerateObjectOptions, type GenerateObjectResult, type GenerateOptions, type GenerateResult, type GeneratedImage, type ImageGenerateOptions, type ImageGenerateResult, type ImageModel, type ImagePart, LLMError, type Message, type ModelConfig, type ObjectStreamEvent, ProviderError, type StreamEvent, type StreamObjectOptions, type StreamObjectResult, type StreamResult, StructuredOutputError, StructuredOutputNoObjectGeneratedError, StructuredOutputParseError, StructuredOutputValidationError, type SystemMessage, type TextPart, type ToolCall, type ToolChoice, type ToolDefinition, type ToolResultMessage, type ToolSet, type UserContentPart, type UserMessage, createObjectStreamResult, createStreamResult, defineTool, embed, generate, generateImage, generateObject, stream, streamObject };
|
package/dist/index.js
CHANGED
|
@@ -103,8 +103,13 @@ function createObjectStreamResult(source) {
|
|
|
103
103
|
let usage = {
|
|
104
104
|
inputTokens: 0,
|
|
105
105
|
outputTokens: 0,
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
inputTokenDetails: {
|
|
107
|
+
cacheReadTokens: 0,
|
|
108
|
+
cacheWriteTokens: 0
|
|
109
|
+
},
|
|
110
|
+
outputTokenDetails: {
|
|
111
|
+
reasoningTokens: 0
|
|
112
|
+
}
|
|
108
113
|
};
|
|
109
114
|
try {
|
|
110
115
|
for await (const event of source) {
|
|
@@ -170,8 +175,13 @@ function createStreamResult(source) {
|
|
|
170
175
|
let usage = {
|
|
171
176
|
inputTokens: 0,
|
|
172
177
|
outputTokens: 0,
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
inputTokenDetails: {
|
|
179
|
+
cacheReadTokens: 0,
|
|
180
|
+
cacheWriteTokens: 0
|
|
181
|
+
},
|
|
182
|
+
outputTokenDetails: {
|
|
183
|
+
reasoningTokens: 0
|
|
184
|
+
}
|
|
175
185
|
};
|
|
176
186
|
for await (const event of source) {
|
|
177
187
|
if (event.type === "content-delta") {
|