@core-ai/core-ai 0.7.1 → 0.8.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
@@ -281,15 +281,21 @@ type GeneratedImage = {
281
281
  revisedPrompt?: string;
282
282
  };
283
283
 
284
- declare class LLMError extends Error {
284
+ declare class CoreAIError extends Error {
285
285
  readonly cause?: unknown;
286
- constructor(message: string, cause?: unknown);
286
+ readonly provider?: string;
287
+ constructor(message: string, cause?: unknown, provider?: string);
287
288
  }
288
- declare class StreamAbortedError extends LLMError {
289
- constructor(message?: string, cause?: unknown);
289
+ declare class ValidationError extends CoreAIError {
290
+ constructor(message: string, cause?: unknown, provider?: string);
290
291
  }
291
- declare class ProviderError extends LLMError {
292
- readonly provider: string;
292
+ declare class AbortedError extends CoreAIError {
293
+ constructor(cause?: unknown, provider?: string);
294
+ }
295
+ declare class StreamAbortedError extends AbortedError {
296
+ constructor(cause?: unknown, provider?: string);
297
+ }
298
+ declare class ProviderError extends CoreAIError {
293
299
  readonly statusCode?: number;
294
300
  constructor(message: string, provider: string, statusCode?: number, cause?: unknown);
295
301
  }
@@ -298,7 +304,8 @@ type StructuredOutputErrorOptions = {
298
304
  cause?: unknown;
299
305
  rawOutput?: string;
300
306
  };
301
- declare class StructuredOutputError extends ProviderError {
307
+ declare class StructuredOutputError extends CoreAIError {
308
+ readonly statusCode?: number;
302
309
  readonly rawOutput?: string;
303
310
  constructor(message: string, provider: string, options?: StructuredOutputErrorOptions);
304
311
  }
@@ -371,4 +378,4 @@ type GenerateImageParams = ImageGenerateOptions & {
371
378
  };
372
379
  declare function generateImage(params: GenerateImageParams): Promise<ImageGenerateResult>;
373
380
 
374
- export { type AssistantContentPart, type AssistantMessage, type AssistantTextPart, type BaseGenerateOptions, type ChatInputTokenDetails, type ChatModel, type ChatOutputTokenDetails, type ChatStream, type ChatUsage, type EmbedOptions, type EmbedProviderOptions, type EmbedResult, type EmbeddingModel, 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 ImagePart, type ImageProviderOptions, LLMError, 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, asObject, assistantMessage, createChatStream, createObjectStream, defineTool, embed, generate, generateImage, generateObject, getProviderMetadata, resultToMessage, safeParseJsonObject, stream, streamObject, stripModelDateSuffix, zodSchemaToJsonSchema };
381
+ export { AbortedError, type AssistantContentPart, type AssistantMessage, type AssistantTextPart, type BaseGenerateOptions, type ChatInputTokenDetails, type ChatModel, type ChatOutputTokenDetails, type ChatStream, type ChatUsage, CoreAIError, type EmbedOptions, type EmbedProviderOptions, type EmbedResult, type EmbeddingModel, 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 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, zodSchemaToJsonSchema };
package/dist/index.js CHANGED
@@ -1,33 +1,48 @@
1
1
  // src/errors.ts
2
- var LLMError = class extends Error {
2
+ var CoreAIError = class extends Error {
3
3
  cause;
4
- constructor(message, cause) {
4
+ provider;
5
+ constructor(message, cause, provider) {
5
6
  super(message);
6
- this.name = "LLMError";
7
+ this.name = "CoreAIError";
7
8
  this.cause = cause;
9
+ this.provider = provider;
8
10
  }
9
11
  };
10
- var StreamAbortedError = class extends LLMError {
11
- constructor(message = "stream aborted", cause) {
12
- super(message, cause);
12
+ var ValidationError = class extends CoreAIError {
13
+ constructor(message, cause, provider) {
14
+ super(message, cause, provider);
15
+ this.name = "ValidationError";
16
+ }
17
+ };
18
+ var AbortedError = class extends CoreAIError {
19
+ constructor(cause, provider) {
20
+ super("operation aborted", cause, provider);
21
+ this.name = "AbortedError";
22
+ }
23
+ };
24
+ var StreamAbortedError = class extends AbortedError {
25
+ constructor(cause, provider) {
26
+ super(cause, provider);
13
27
  this.name = "StreamAbortedError";
28
+ this.message = "stream aborted";
14
29
  }
15
30
  };
16
- var ProviderError = class extends LLMError {
17
- provider;
31
+ var ProviderError = class extends CoreAIError {
18
32
  statusCode;
19
33
  constructor(message, provider, statusCode, cause) {
20
- super(message, cause);
34
+ super(message, cause, provider);
21
35
  this.name = "ProviderError";
22
- this.provider = provider;
23
36
  this.statusCode = statusCode;
24
37
  }
25
38
  };
26
- var StructuredOutputError = class extends ProviderError {
39
+ var StructuredOutputError = class extends CoreAIError {
40
+ statusCode;
27
41
  rawOutput;
28
42
  constructor(message, provider, options = {}) {
29
- super(message, provider, options.statusCode, options.cause);
43
+ super(message, options.cause, provider);
30
44
  this.name = "StructuredOutputError";
45
+ this.statusCode = options.statusCode;
31
46
  this.rawOutput = options.rawOutput;
32
47
  }
33
48
  };
@@ -108,19 +123,19 @@ function isEmptyText(value) {
108
123
  }
109
124
  function assertNonEmptyMessages(messages) {
110
125
  if (messages.length === 0) {
111
- throw new LLMError("messages must not be empty");
126
+ throw new ValidationError("messages must not be empty");
112
127
  }
113
128
  }
114
129
  function assertNonEmptyEmbedInput(input) {
115
130
  const isEmptyString = typeof input === "string" && isEmptyText(input);
116
131
  const isEmptyArray = Array.isArray(input) && input.length === 0;
117
132
  if (isEmptyString || isEmptyArray) {
118
- throw new LLMError("input must not be empty");
133
+ throw new ValidationError("input must not be empty");
119
134
  }
120
135
  }
121
136
  function assertNonEmptyPrompt(prompt) {
122
137
  if (isEmptyText(prompt)) {
123
- throw new LLMError("prompt must not be empty");
138
+ throw new ValidationError("prompt must not be empty");
124
139
  }
125
140
  }
126
141
 
@@ -240,7 +255,7 @@ function createStream(options) {
240
255
  if (terminalState.status !== "running") {
241
256
  return;
242
257
  }
243
- settleRejected(new StreamAbortedError("stream aborted"));
258
+ settleRejected(new StreamAbortedError());
244
259
  void closeSourceIterator();
245
260
  }
246
261
  if (signal) {
@@ -361,7 +376,7 @@ function createObjectStream(source, options = {}) {
361
376
  },
362
377
  finalizeResult() {
363
378
  if (objectState.status !== "ready") {
364
- throw new LLMError(
379
+ throw new CoreAIError(
365
380
  "object stream completed without emitting a final object"
366
381
  );
367
382
  }
@@ -542,13 +557,15 @@ async function generateImage(params) {
542
557
  );
543
558
  }
544
559
  export {
545
- LLMError,
560
+ AbortedError,
561
+ CoreAIError,
546
562
  ProviderError,
547
563
  StreamAbortedError,
548
564
  StructuredOutputError,
549
565
  StructuredOutputNoObjectGeneratedError,
550
566
  StructuredOutputParseError,
551
567
  StructuredOutputValidationError,
568
+ ValidationError,
552
569
  asObject,
553
570
  assistantMessage,
554
571
  createChatStream,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@core-ai/core-ai",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Type-safe LLM abstraction layer over native provider SDKs",
5
5
  "license": "MIT",
6
6
  "author": "Omnifact (https://omnifact.ai)",