@core-ai/core-ai 0.12.0 → 0.13.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 CHANGED
@@ -85,9 +85,21 @@ type ToolChoice = 'auto' | 'none' | 'required' | {
85
85
  type: 'tool';
86
86
  toolName: string;
87
87
  };
88
+ type ModelCapabilities = {
89
+ reasoning: {
90
+ supported: boolean;
91
+ supportedEfforts: readonly ReasoningEffort[];
92
+ /**
93
+ * When true, sampling parameters such as `temperature` and `topP`
94
+ * must not be set alongside `reasoning`.
95
+ */
96
+ restrictsSamplingParams: boolean;
97
+ };
98
+ };
88
99
  type ChatModel = {
89
100
  readonly provider: string;
90
101
  readonly modelId: string;
102
+ readonly capabilities: ModelCapabilities;
91
103
  generate(options: GenerateOptions): Promise<GenerateResult>;
92
104
  stream(options: GenerateOptions): Promise<ChatStream>;
93
105
  generateObject<TSchema extends z.ZodType>(options: GenerateObjectOptions<TSchema>): Promise<GenerateObjectResult<TSchema>>;
@@ -369,6 +381,8 @@ declare function zodSchemaToJsonSchema(schema: z.ZodType): Record<string, unknow
369
381
 
370
382
  declare function stripModelDateSuffix(modelId: string): string;
371
383
 
384
+ declare function clampReasoningEffort(effort: ReasoningEffort, supportedEfforts: readonly ReasoningEffort[]): ReasoningEffort;
385
+
372
386
  declare function asObject(value: unknown): Record<string, unknown>;
373
387
  declare function safeParseJsonObject(json: string): Record<string, unknown>;
374
388
 
@@ -432,4 +446,4 @@ type GenerateImageParams = ImageGenerateOptions & {
432
446
  };
433
447
  declare function generateImage(params: GenerateImageParams): Promise<ImageGenerateResult>;
434
448
 
435
- export { AbortedError, type AssistantContentPart, type AssistantMessage, type AssistantTextPart, type BaseGenerateOptions, type ChatInputTokenDetails, type ChatModel, type ChatModelMiddleware, type ChatOutputTokenDetails, type ChatStream, type ChatUsage, CoreAIError, type EmbedOptions, type EmbedProviderOptions, type EmbedResult, type EmbeddingModel, type EmbeddingModelMiddleware, type EmbeddingUsage, type FilePart, type FinishReason, type GenerateObjectOptions, type GenerateObjectResult, type GenerateOptions, type GenerateProviderOptions, type GenerateResult, type GeneratedImage, type ImageGenerateOptions, type ImageGenerateResult, type ImageModel, type ImageModelMiddleware, type ImagePart, type ImageProviderOptions, type Message, type ObjectStream, type ObjectStreamEvent, ProviderError, type ReasoningConfig, type ReasoningEffort, type ReasoningPart, StreamAbortedError, type StreamEvent, type StreamObjectOptions, StructuredOutputError, StructuredOutputNoObjectGeneratedError, StructuredOutputParseError, StructuredOutputValidationError, type SystemMessage, type TextPart, type ToolCall, type ToolCallPart, type ToolChoice, type ToolDefinition, type ToolResultMessage, type ToolSet, type UserContentPart, type UserMessage, ValidationError, asObject, assistantMessage, createChatStream, createObjectStream, defineTool, embed, generate, generateImage, generateObject, getProviderMetadata, resultToMessage, safeParseJsonObject, stream, streamObject, stripModelDateSuffix, wrapChatModel, wrapEmbeddingModel, wrapImageModel, zodSchemaToJsonSchema };
449
+ export { AbortedError, type AssistantContentPart, type AssistantMessage, type AssistantTextPart, type BaseGenerateOptions, type ChatInputTokenDetails, type ChatModel, type ChatModelMiddleware, type ChatOutputTokenDetails, type ChatStream, type ChatUsage, CoreAIError, type EmbedOptions, type EmbedProviderOptions, type EmbedResult, type EmbeddingModel, type EmbeddingModelMiddleware, type EmbeddingUsage, type FilePart, type FinishReason, type GenerateObjectOptions, type GenerateObjectResult, type GenerateOptions, type GenerateProviderOptions, type GenerateResult, type GeneratedImage, type ImageGenerateOptions, type ImageGenerateResult, type ImageModel, type ImageModelMiddleware, type ImagePart, type ImageProviderOptions, type Message, type ModelCapabilities, type ObjectStream, type ObjectStreamEvent, ProviderError, type ReasoningConfig, type ReasoningEffort, type ReasoningPart, StreamAbortedError, type StreamEvent, type StreamObjectOptions, StructuredOutputError, StructuredOutputNoObjectGeneratedError, StructuredOutputParseError, StructuredOutputValidationError, type SystemMessage, type TextPart, type ToolCall, type ToolCallPart, type ToolChoice, type ToolDefinition, type ToolResultMessage, type ToolSet, type UserContentPart, type UserMessage, ValidationError, asObject, assistantMessage, clampReasoningEffort, createChatStream, createObjectStream, defineTool, embed, generate, generateImage, generateObject, getProviderMetadata, resultToMessage, safeParseJsonObject, stream, streamObject, stripModelDateSuffix, wrapChatModel, wrapEmbeddingModel, wrapImageModel, zodSchemaToJsonSchema };
package/dist/index.js CHANGED
@@ -86,6 +86,35 @@ function stripModelDateSuffix(modelId) {
86
86
  return modelId.replace(MODEL_DATE_SUFFIX_PATTERN, "");
87
87
  }
88
88
 
89
+ // src/model-capabilities.ts
90
+ var EFFORT_RANK = {
91
+ minimal: 0,
92
+ low: 1,
93
+ medium: 2,
94
+ high: 3,
95
+ max: 4
96
+ };
97
+ function clampReasoningEffort(effort, supportedEfforts) {
98
+ if (supportedEfforts.includes(effort)) {
99
+ return effort;
100
+ }
101
+ const [firstSupportedEffort, ...remainingSupportedEfforts] = supportedEfforts;
102
+ if (firstSupportedEffort === void 0) {
103
+ return effort;
104
+ }
105
+ const targetRank = EFFORT_RANK[effort];
106
+ let best = firstSupportedEffort;
107
+ let bestDistance = Math.abs(EFFORT_RANK[best] - targetRank);
108
+ for (const candidate of remainingSupportedEfforts) {
109
+ const distance = Math.abs(EFFORT_RANK[candidate] - targetRank);
110
+ if (distance < bestDistance) {
111
+ best = candidate;
112
+ bestDistance = distance;
113
+ }
114
+ }
115
+ return best;
116
+ }
117
+
89
118
  // src/provider-utils.ts
90
119
  function asObject(value) {
91
120
  if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -565,6 +594,7 @@ function wrapChatModel(config) {
565
594
  return {
566
595
  provider: model.provider,
567
596
  modelId: model.modelId,
597
+ capabilities: model.capabilities,
568
598
  generate(options) {
569
599
  return buildMiddlewareChain({
570
600
  model,
@@ -581,7 +611,9 @@ function wrapChatModel(config) {
581
611
  },
582
612
  generateObject(options) {
583
613
  const operations = middlewares.flatMap(
584
- (mw) => mw.generateObject ? [mw.generateObject] : []
614
+ (mw) => mw.generateObject ? [
615
+ mw.generateObject
616
+ ] : []
585
617
  );
586
618
  return buildMiddlewareChain({
587
619
  model,
@@ -673,6 +705,7 @@ export {
673
705
  ValidationError,
674
706
  asObject,
675
707
  assistantMessage,
708
+ clampReasoningEffort,
676
709
  createChatStream,
677
710
  createObjectStream,
678
711
  defineTool,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@core-ai/core-ai",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Type-safe LLM abstraction layer over native provider SDKs",
5
5
  "license": "MIT",
6
6
  "author": "Omnifact (https://omnifact.ai)",