@core-ai/core-ai 0.17.0 → 0.19.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
@@ -9,7 +9,7 @@ type UserMessage = {
9
9
  role: 'user';
10
10
  content: string | UserContentPart[];
11
11
  };
12
- type UserContentPart = TextPart | ImagePart | FilePart;
12
+ type UserContentPart = TextPart | ImagePart | FilePart | AudioPart;
13
13
  type TextPart = {
14
14
  type: 'text';
15
15
  text: string;
@@ -36,6 +36,14 @@ type FilePart = {
36
36
  mimeType: string;
37
37
  filename?: string;
38
38
  };
39
+ type AudioPart = {
40
+ type: 'audio';
41
+ source: {
42
+ type: 'base64';
43
+ mediaType: string;
44
+ data: string;
45
+ };
46
+ };
39
47
  type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'max';
40
48
  type ReasoningConfig = {
41
49
  effort: ReasoningEffort;
@@ -111,6 +119,21 @@ type ToolChoice = 'auto' | 'none' | 'required' | {
111
119
  toolName: string;
112
120
  };
113
121
  type ToolChoiceMode = 'auto' | 'none' | 'required' | 'tool';
122
+ /**
123
+ * Modalities a chat model can accept in user messages.
124
+ *
125
+ * `file` covers document attachments such as PDFs. `video` is reserved for a
126
+ * future input part.
127
+ */
128
+ type ChatInputModality = 'text' | 'image' | 'file' | 'audio' | 'video';
129
+ /**
130
+ * Modalities a chat model can emit as assistant content.
131
+ *
132
+ * Dedicated generators (`ImageModel`, and future audio/video models) are
133
+ * separate operations. Chat `output` describes native multimodal responses
134
+ * from `generate` / `stream`, not those dedicated APIs.
135
+ */
136
+ type ChatOutputModality = 'text' | 'image' | 'audio' | 'video';
114
137
  type ModelCapabilities = {
115
138
  reasoning: {
116
139
  mode: 'unsupported' | 'optional' | 'always-on';
@@ -122,6 +145,15 @@ type ModelCapabilities = {
122
145
  restrictsSamplingParams: boolean;
123
146
  supportedToolChoices: readonly ToolChoiceMode[];
124
147
  };
148
+ modalities: {
149
+ /** Modalities accepted in user messages. Always includes `'text'`. */
150
+ input: readonly ChatInputModality[];
151
+ /**
152
+ * Modalities the model can emit as assistant content. Always includes
153
+ * `'text'`. Does not describe dedicated `ImageModel` generation.
154
+ */
155
+ output: readonly ChatOutputModality[];
156
+ };
125
157
  };
126
158
  type ChatModel = {
127
159
  readonly provider: string;
@@ -373,6 +405,24 @@ declare class CoreAIError extends Error {
373
405
  declare class ValidationError extends CoreAIError {
374
406
  constructor(message: string, cause?: unknown, provider?: string);
375
407
  }
408
+ type UnsupportedInputModalityErrorOptions = {
409
+ modelId: string;
410
+ providerId: string;
411
+ requestedModalities: readonly string[];
412
+ supportedModalities: readonly string[];
413
+ unsupportedModalities: readonly string[];
414
+ };
415
+ /**
416
+ * Thrown when user messages include content parts the model does not accept.
417
+ * Extends {@link ValidationError} so existing `instanceof ValidationError`
418
+ * checks still match.
419
+ */
420
+ declare class UnsupportedInputModalityError extends ValidationError {
421
+ readonly requestedModalities: readonly string[];
422
+ readonly supportedModalities: readonly string[];
423
+ readonly unsupportedModalities: readonly string[];
424
+ constructor(options: UnsupportedInputModalityErrorOptions);
425
+ }
376
426
  declare class AbortedError extends CoreAIError {
377
427
  constructor(cause?: unknown, provider?: string);
378
428
  }
@@ -482,6 +532,36 @@ declare function zodSchemaToJsonSchema(schema: z.ZodType): Record<string, unknow
482
532
  declare function stripModelDateSuffix(modelId: string): string;
483
533
 
484
534
  declare function clampReasoningEffort(effort: ReasoningEffort, supportedEfforts: readonly ReasoningEffort[]): ReasoningEffort;
535
+ /** Text in, text out — the default chat modality profile. */
536
+ declare const TEXT_ONLY_MODALITIES: {
537
+ readonly input: readonly ["text"];
538
+ readonly output: readonly ["text"];
539
+ };
540
+ /**
541
+ * Text, image, and file in; text out.
542
+ *
543
+ * Typical vision / document chat models. Audio support is advertised separately
544
+ * by providers whose adapters accept `AudioPart`.
545
+ */
546
+ declare const MULTIMODAL_INPUT_MODALITIES: {
547
+ readonly input: readonly ["text", "image", "file"];
548
+ readonly output: readonly ["text"];
549
+ };
550
+ declare function supportsInputModality(capabilities: ModelCapabilities, modality: ChatInputModality): boolean;
551
+ declare function supportsOutputModality(capabilities: ModelCapabilities, modality: ChatOutputModality): boolean;
552
+
553
+ type ValidateInputModalitiesOptions = {
554
+ messages: Message[];
555
+ capabilities: ModelCapabilities;
556
+ modelId: string;
557
+ providerId: string;
558
+ };
559
+ /**
560
+ * Rejects user content parts whose modalities are not in
561
+ * `capabilities.modalities.input`. Part `type` values map 1:1 to input
562
+ * modalities (`text`, `image`, `file`, and future `audio` / `video`).
563
+ */
564
+ declare function validateInputModalities({ messages, capabilities, modelId, providerId, }: ValidateInputModalitiesOptions): void;
485
565
 
486
566
  declare const UNKNOWN_MODEL: unique symbol;
487
567
  type ModelCapabilitiesRegistry<TCapabilities extends ModelCapabilities = ModelCapabilities> = Record<string, TCapabilities> & {
@@ -552,4 +632,4 @@ type GenerateImageParams = ImageGenerateOptions & {
552
632
  };
553
633
  declare function generateImage(params: GenerateImageParams): Promise<ImageGenerateResult>;
554
634
 
555
- export { AbortedError, type AssistantContentPart, type AssistantMessage, type AssistantTextPart, type BaseGenerateOptions, type ChatInputTokenDetails, type ChatModel, type ChatModelMiddleware, type ChatOutputTokenDetails, type ChatStream, type ChatUsage, ContextLengthExceededError, type ContextLengthExceededErrorOptions, 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 ModelCapabilitiesRegistry, ModelOverloadedError, type ModelOverloadedErrorOptions, type ObjectStream, type ObjectStreamEvent, ProviderError, type ProviderErrorOptions, RateLimitError, type RateLimitErrorOptions, type ReasoningConfig, type ReasoningEffort, type ReasoningPart, RetryableProviderError, ServiceUnavailableError, type ServiceUnavailableErrorOptions, 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, UNKNOWN_MODEL, type UserContentPart, type UserMessage, ValidationError, asObject, asRecord, assistantMessage, clampReasoningEffort, createChatStream, createObjectStream, defineTool, embed, generate, generateImage, generateObject, getErrorMessage, getHttpStatusCode, getProviderMetadata, getRegisteredModelCapabilities, getRetryAfterSecondsFromError, getString, isAbortErrorByName, isRateLimitStatus, isTransientUnavailableStatus, parseRetryAfterSeconds, resultToMessage, safeParseJsonObject, stream, streamObject, stripModelDateSuffix, wrapChatModel, wrapEmbeddingModel, wrapImageModel, zodSchemaToJsonSchema };
635
+ export { AbortedError, type AssistantContentPart, type AssistantMessage, type AssistantTextPart, type AudioPart, type BaseGenerateOptions, type ChatInputModality, type ChatInputTokenDetails, type ChatModel, type ChatModelMiddleware, type ChatOutputModality, type ChatOutputTokenDetails, type ChatStream, type ChatUsage, ContextLengthExceededError, type ContextLengthExceededErrorOptions, 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, MULTIMODAL_INPUT_MODALITIES, type Message, type ModelCapabilities, type ModelCapabilitiesRegistry, ModelOverloadedError, type ModelOverloadedErrorOptions, type ObjectStream, type ObjectStreamEvent, ProviderError, type ProviderErrorOptions, RateLimitError, type RateLimitErrorOptions, type ReasoningConfig, type ReasoningEffort, type ReasoningPart, RetryableProviderError, ServiceUnavailableError, type ServiceUnavailableErrorOptions, StreamAbortedError, type StreamEvent, type StreamObjectOptions, StructuredOutputError, StructuredOutputNoObjectGeneratedError, StructuredOutputParseError, StructuredOutputValidationError, type SystemMessage, TEXT_ONLY_MODALITIES, type TextPart, type ToolCall, type ToolCallPart, type ToolChoice, type ToolDefinition, type ToolResultMessage, type ToolSet, UNKNOWN_MODEL, UnsupportedInputModalityError, type UnsupportedInputModalityErrorOptions, type UserContentPart, type UserMessage, type ValidateInputModalitiesOptions, ValidationError, asObject, asRecord, assistantMessage, clampReasoningEffort, createChatStream, createObjectStream, defineTool, embed, generate, generateImage, generateObject, getErrorMessage, getHttpStatusCode, getProviderMetadata, getRegisteredModelCapabilities, getRetryAfterSecondsFromError, getString, isAbortErrorByName, isRateLimitStatus, isTransientUnavailableStatus, parseRetryAfterSeconds, resultToMessage, safeParseJsonObject, stream, streamObject, stripModelDateSuffix, supportsInputModality, supportsOutputModality, validateInputModalities, wrapChatModel, wrapEmbeddingModel, wrapImageModel, zodSchemaToJsonSchema };
package/dist/index.js CHANGED
@@ -15,6 +15,25 @@ var ValidationError = class extends CoreAIError {
15
15
  this.name = "ValidationError";
16
16
  }
17
17
  };
18
+ var UnsupportedInputModalityError = class extends ValidationError {
19
+ requestedModalities;
20
+ supportedModalities;
21
+ unsupportedModalities;
22
+ constructor(options) {
23
+ const unsupported = options.unsupportedModalities.join(", ");
24
+ const supported = options.supportedModalities.join(", ") || "(none)";
25
+ const modalityWord = options.unsupportedModalities.length === 1 ? "modality" : "modalities";
26
+ super(
27
+ `${options.providerId} model "${options.modelId}" does not support input ${modalityWord}: ${unsupported}. Supported: ${supported}`,
28
+ void 0,
29
+ options.providerId
30
+ );
31
+ this.name = "UnsupportedInputModalityError";
32
+ this.requestedModalities = options.requestedModalities;
33
+ this.supportedModalities = options.supportedModalities;
34
+ this.unsupportedModalities = options.unsupportedModalities;
35
+ }
36
+ };
18
37
  var AbortedError = class extends CoreAIError {
19
38
  constructor(cause, provider) {
20
39
  super("operation aborted", cause, provider);
@@ -262,6 +281,63 @@ function clampReasoningEffort(effort, supportedEfforts) {
262
281
  }
263
282
  return best;
264
283
  }
284
+ var TEXT_ONLY_MODALITIES = {
285
+ input: ["text"],
286
+ output: ["text"]
287
+ };
288
+ var MULTIMODAL_INPUT_MODALITIES = {
289
+ input: ["text", "image", "file"],
290
+ output: ["text"]
291
+ };
292
+ function supportsInputModality(capabilities, modality) {
293
+ return capabilities.modalities.input.includes(modality);
294
+ }
295
+ function supportsOutputModality(capabilities, modality) {
296
+ return capabilities.modalities.output.includes(modality);
297
+ }
298
+
299
+ // src/validate-input-modalities.ts
300
+ function validateInputModalities({
301
+ messages,
302
+ capabilities,
303
+ modelId,
304
+ providerId
305
+ }) {
306
+ const requestedModalities = collectRequestedInputModalities(messages);
307
+ if (requestedModalities.length === 0) {
308
+ return;
309
+ }
310
+ const supportedModalities = capabilities.modalities.input;
311
+ const unsupportedModalities = requestedModalities.filter(
312
+ (modality) => !supportedModalities.includes(modality)
313
+ );
314
+ if (unsupportedModalities.length === 0) {
315
+ return;
316
+ }
317
+ throw new UnsupportedInputModalityError({
318
+ modelId,
319
+ providerId,
320
+ requestedModalities,
321
+ supportedModalities,
322
+ unsupportedModalities
323
+ });
324
+ }
325
+ function collectRequestedInputModalities(messages) {
326
+ const requested = /* @__PURE__ */ new Set();
327
+ for (const message of messages) {
328
+ if (message.role !== "user") {
329
+ continue;
330
+ }
331
+ if (typeof message.content === "string") {
332
+ requested.add("text");
333
+ continue;
334
+ }
335
+ for (const part of message.content) {
336
+ requested.add(part.type);
337
+ }
338
+ }
339
+ return [...requested];
340
+ }
265
341
 
266
342
  // src/model-capabilities-registry.ts
267
343
  var UNKNOWN_MODEL = /* @__PURE__ */ Symbol("unknown-model");
@@ -889,6 +965,7 @@ export {
889
965
  AbortedError,
890
966
  ContextLengthExceededError,
891
967
  CoreAIError,
968
+ MULTIMODAL_INPUT_MODALITIES,
892
969
  ModelOverloadedError,
893
970
  ProviderError,
894
971
  RateLimitError,
@@ -899,7 +976,9 @@ export {
899
976
  StructuredOutputNoObjectGeneratedError,
900
977
  StructuredOutputParseError,
901
978
  StructuredOutputValidationError,
979
+ TEXT_ONLY_MODALITIES,
902
980
  UNKNOWN_MODEL,
981
+ UnsupportedInputModalityError,
903
982
  ValidationError,
904
983
  asObject,
905
984
  asRecord,
@@ -927,6 +1006,9 @@ export {
927
1006
  stream,
928
1007
  streamObject,
929
1008
  stripModelDateSuffix,
1009
+ supportsInputModality,
1010
+ supportsOutputModality,
1011
+ validateInputModalities,
930
1012
  wrapChatModel,
931
1013
  wrapEmbeddingModel,
932
1014
  wrapImageModel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@core-ai/core-ai",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "description": "Type-safe LLM abstraction layer over native provider SDKs",
5
5
  "license": "MIT",
6
6
  "author": "Omnifact (https://omnifact.ai)",