From 1d38d2a53118014ead3af5b293772db2050dda00 Mon Sep 17 00:00:00 2001 From: Lars Grammel Date: Tue, 9 Apr 2024 19:17:54 +0200 Subject: [PATCH] Move specification into @ai-sdk/specification package. (#1303) --- .changeset/eight-bananas-relax.md | 6 + docs/pages/docs/ai-core/custom-provider.mdx | 6 +- .../anthropic-messages-language-model.test.ts | 2 +- .../anthropic-messages-language-model.ts | 6 +- .../convert-to-anthropic-messages-prompt.ts | 4 +- .../anthropic/map-anthropic-stop-reason.ts | 2 +- .../core/generate-object/generate-object.ts | 6 +- .../core/generate-object/stream-object.ts | 4 +- .../core/core/generate-text/generate-text.ts | 2 +- .../generate-text/run-tools-transformation.ts | 5 +- .../core/core/generate-text/stream-text.ts | 7 +- packages/core/core/generate-text/tool-call.ts | 6 +- .../convert-to-language-model-prompt.ts | 2 +- packages/core/core/prompt/data-content.ts | 2 +- .../core/core/prompt/get-validated-prompt.ts | 2 +- .../core/core/prompt/prepare-call-settings.ts | 2 +- .../core/core/test/mock-language-model-v1.ts | 2 +- .../util/retry-with-exponential-backoff.ts | 3 +- ...onvert-to-google-generative-ai-messages.ts | 4 +- ...oogle-generative-ai-language-model.test.ts | 2 +- .../google-generative-ai-language-model.ts | 6 +- .../map-google-generative-ai-finish-reason.ts | 2 +- .../convert-to-mistral-chat-messages.ts | 5 +- .../core/mistral/map-mistral-finish-reason.ts | 2 +- .../mistral-chat-language-model.test.ts | 2 +- .../mistral/mistral-chat-language-model.ts | 6 +- .../openai/convert-to-openai-chat-messages.ts | 3 +- .../convert-to-openai-completion-prompt.ts | 2 +- .../core/openai/map-openai-finish-reason.ts | 2 +- .../openai/openai-chat-language-model.test.ts | 2 +- .../core/openai/openai-chat-language-model.ts | 6 +- .../openai-completion-language-model.test.ts | 2 +- .../openai-completion-language-model.ts | 6 +- packages/core/package.json | 12 +- packages/core/spec/index.ts | 2 - packages/core/spec/util/load-api-key.ts | 2 +- packages/core/spec/util/parse-json.ts | 3 +- packages/core/spec/util/post-to-api.ts | 2 +- packages/core/spec/util/response-handler.ts | 3 +- packages/core/spec/util/validate-types.ts | 2 +- packages/core/tsup.config.ts | 8 - packages/specification/README.md | 1 + packages/specification/package.json | 54 ++ .../src}/errors/api-call-error.ts | 0 .../src/errors/get-error-message.ts | 15 + .../src}/errors/index.ts | 0 .../src}/errors/invalid-argument-error.ts | 0 .../src}/errors/invalid-data-content-error.ts | 0 .../src}/errors/invalid-prompt-error.ts | 0 .../errors/invalid-response-data-error.ts | 0 .../errors/invalid-tool-arguments-error.ts | 2 +- .../src}/errors/json-parse-error.ts | 2 +- .../src}/errors/load-api-key-error.ts | 0 .../src}/errors/no-object-generated-error.ts | 0 .../src}/errors/no-response-body-error.ts | 0 .../src}/errors/no-such-tool-error.ts | 0 .../src}/errors/retry-error.ts | 0 .../src}/errors/tool-call-parse-error.ts | 2 +- .../src}/errors/type-validation-error.ts | 2 +- .../errors/unsupported-functionality-error.ts | 0 .../errors/unsupported-json-schema-error.ts | 0 packages/specification/src/index.ts | 2 + .../src}/language-model/index.ts | 0 .../src}/language-model/v1/index.ts | 0 .../v1/language-model-v1-call-options.ts | 0 .../v1/language-model-v1-call-settings.ts | 0 .../v1/language-model-v1-call-warning.ts | 0 .../v1/language-model-v1-finish-reason.ts | 0 .../language-model-v1-function-tool-call.ts | 0 .../v1/language-model-v1-function-tool.ts | 0 .../v1/language-model-v1-prompt.ts | 0 .../language-model/v1/language-model-v1.ts | 0 packages/specification/tsconfig.json | 9 + packages/specification/tsup.config.ts | 11 + packages/specification/turbo.json | 8 + pnpm-lock.yaml | 551 +++++++----------- 76 files changed, 407 insertions(+), 407 deletions(-) create mode 100644 .changeset/eight-bananas-relax.md create mode 100644 packages/specification/README.md create mode 100644 packages/specification/package.json rename packages/{core/spec => specification/src}/errors/api-call-error.ts (100%) create mode 100644 packages/specification/src/errors/get-error-message.ts rename packages/{core/spec => specification/src}/errors/index.ts (100%) rename packages/{core/spec => specification/src}/errors/invalid-argument-error.ts (100%) rename packages/{core/spec => specification/src}/errors/invalid-data-content-error.ts (100%) rename packages/{core/spec => specification/src}/errors/invalid-prompt-error.ts (100%) rename packages/{core/spec => specification/src}/errors/invalid-response-data-error.ts (100%) rename packages/{core/spec => specification/src}/errors/invalid-tool-arguments-error.ts (95%) rename packages/{core/spec => specification/src}/errors/json-parse-error.ts (93%) rename packages/{core/spec => specification/src}/errors/load-api-key-error.ts (100%) rename packages/{core/spec => specification/src}/errors/no-object-generated-error.ts (100%) rename packages/{core/spec => specification/src}/errors/no-response-body-error.ts (100%) rename packages/{core/spec => specification/src}/errors/no-such-tool-error.ts (100%) rename packages/{core/spec => specification/src}/errors/retry-error.ts (100%) rename packages/{core/spec => specification/src}/errors/tool-call-parse-error.ts (95%) rename packages/{core/spec => specification/src}/errors/type-validation-error.ts (93%) rename packages/{core/spec => specification/src}/errors/unsupported-functionality-error.ts (100%) rename packages/{core/spec => specification/src}/errors/unsupported-json-schema-error.ts (100%) create mode 100644 packages/specification/src/index.ts rename packages/{core/spec => specification/src}/language-model/index.ts (100%) rename packages/{core/spec => specification/src}/language-model/v1/index.ts (100%) rename packages/{core/spec => specification/src}/language-model/v1/language-model-v1-call-options.ts (100%) rename packages/{core/spec => specification/src}/language-model/v1/language-model-v1-call-settings.ts (100%) rename packages/{core/spec => specification/src}/language-model/v1/language-model-v1-call-warning.ts (100%) rename packages/{core/spec => specification/src}/language-model/v1/language-model-v1-finish-reason.ts (100%) rename packages/{core/spec => specification/src}/language-model/v1/language-model-v1-function-tool-call.ts (100%) rename packages/{core/spec => specification/src}/language-model/v1/language-model-v1-function-tool.ts (100%) rename packages/{core/spec => specification/src}/language-model/v1/language-model-v1-prompt.ts (100%) rename packages/{core/spec => specification/src}/language-model/v1/language-model-v1.ts (100%) create mode 100644 packages/specification/tsconfig.json create mode 100644 packages/specification/tsup.config.ts create mode 100644 packages/specification/turbo.json diff --git a/.changeset/eight-bananas-relax.md b/.changeset/eight-bananas-relax.md new file mode 100644 index 000000000000..1ea7b612dd95 --- /dev/null +++ b/.changeset/eight-bananas-relax.md @@ -0,0 +1,6 @@ +--- +'@ai-sdk/specification': minor +'ai': patch +--- + +Move Language Model Specification to separate package. diff --git a/docs/pages/docs/ai-core/custom-provider.mdx b/docs/pages/docs/ai-core/custom-provider.mdx index 4d773cb4b843..db58bab22edb 100644 --- a/docs/pages/docs/ai-core/custom-provider.mdx +++ b/docs/pages/docs/ai-core/custom-provider.mdx @@ -14,7 +14,7 @@ import { Callout } from 'nextra-theme-docs'; The AI SDK provides a language model specification. You can write your own providers that adhere to the AI SDK language model specification and they will be compatible with the AI Core functions. -You can find the Language Model Specification in the [AI SDK repository](https://github.com/vercel/ai/tree/main/packages/core/spec/language-model/v1). +You can find the Language Model Specification in the [AI SDK repository](https://github.com/vercel/ai/tree/main/packages/specification/src/language-model/v1). It can be imported from `ai/spec`. We provide an [OpenAI reference implementation](https://github.com/vercel/ai/tree/main/packages/core/openai) @@ -76,14 +76,14 @@ export const customprovider = new CustomProvider(); ## Language Model Implementation -Please refer to the Language Model Specification in the [AI SDK repository](https://github.com/vercel/ai/tree/main/packages/core/spec/language-model/v1). +Please refer to the Language Model Specification in the [AI SDK repository](https://github.com/vercel/ai/tree/main/packages/specification/src/language-model/v1). We provide an [OpenAI reference implementation](https://github.com/vercel/ai/tree/main/packages/core/openai) and a [Mistral reference implementation](https://github.com/vercel/ai/tree/main/packages/core/mistral). ### Errors -The AI SDK provides [standardized errors](https://github.com/vercel/ai/tree/main/packages/core/spec/errors) that should be used by providers where possible. +The AI SDK provides [standardized errors](https://github.com/vercel/ai/tree/main/packages/specification/src/errors) that should be used by providers where possible. This will make it easy for user to debug them. ### Retries, timeouts, and abort signals diff --git a/packages/core/anthropic/anthropic-messages-language-model.test.ts b/packages/core/anthropic/anthropic-messages-language-model.test.ts index dcdddcbb84df..19529add6baf 100644 --- a/packages/core/anthropic/anthropic-messages-language-model.test.ts +++ b/packages/core/anthropic/anthropic-messages-language-model.test.ts @@ -1,4 +1,4 @@ -import { LanguageModelV1Prompt } from '../spec'; +import { LanguageModelV1Prompt } from '@ai-sdk/specification'; import { convertStreamToArray } from '../spec/test/convert-stream-to-array'; import { JsonTestServer } from '../spec/test/json-test-server'; import { StreamingTestServer } from '../spec/test/streaming-test-server'; diff --git a/packages/core/anthropic/anthropic-messages-language-model.ts b/packages/core/anthropic/anthropic-messages-language-model.ts index bafd33f1f744..c6e042978270 100644 --- a/packages/core/anthropic/anthropic-messages-language-model.ts +++ b/packages/core/anthropic/anthropic-messages-language-model.ts @@ -1,12 +1,14 @@ -import { z } from 'zod'; import { LanguageModelV1, LanguageModelV1CallWarning, LanguageModelV1FinishReason, LanguageModelV1FunctionToolCall, LanguageModelV1StreamPart, - ParseResult, UnsupportedFunctionalityError, +} from '@ai-sdk/specification'; +import { z } from 'zod'; +import { + ParseResult, createEventSourceResponseHandler, createJsonResponseHandler, postJsonToApi, diff --git a/packages/core/anthropic/convert-to-anthropic-messages-prompt.ts b/packages/core/anthropic/convert-to-anthropic-messages-prompt.ts index a23b554c02f3..f9d9dc31351c 100644 --- a/packages/core/anthropic/convert-to-anthropic-messages-prompt.ts +++ b/packages/core/anthropic/convert-to-anthropic-messages-prompt.ts @@ -1,8 +1,8 @@ import { LanguageModelV1Prompt, UnsupportedFunctionalityError, - convertUint8ArrayToBase64, -} from '../spec'; +} from '@ai-sdk/specification'; +import { convertUint8ArrayToBase64 } from '../spec'; import { AnthropicMessage, AnthropicMessagesPrompt, diff --git a/packages/core/anthropic/map-anthropic-stop-reason.ts b/packages/core/anthropic/map-anthropic-stop-reason.ts index 1f74731abd69..f1fe695ef9d5 100644 --- a/packages/core/anthropic/map-anthropic-stop-reason.ts +++ b/packages/core/anthropic/map-anthropic-stop-reason.ts @@ -1,4 +1,4 @@ -import { LanguageModelV1FinishReason } from '../spec'; +import { LanguageModelV1FinishReason } from '@ai-sdk/specification'; export function mapAnthropicStopReason( finishReason: string | null | undefined, diff --git a/packages/core/core/generate-object/generate-object.ts b/packages/core/core/generate-object/generate-object.ts index 8bf722804a17..60da2c9859f1 100644 --- a/packages/core/core/generate-object/generate-object.ts +++ b/packages/core/core/generate-object/generate-object.ts @@ -1,11 +1,11 @@ -import { z } from 'zod'; import { LanguageModelV1, LanguageModelV1CallWarning, LanguageModelV1FinishReason, NoTextGeneratedError, - safeParseJSON, -} from '../../spec'; +} from '@ai-sdk/specification'; +import { z } from 'zod'; +import { safeParseJSON } from '../../spec'; import { TokenUsage, calculateTokenUsage } from '../generate-text/token-usage'; import { CallSettings } from '../prompt/call-settings'; import { convertToLanguageModelPrompt } from '../prompt/convert-to-language-model-prompt'; diff --git a/packages/core/core/generate-object/stream-object.ts b/packages/core/core/generate-object/stream-object.ts index b68fe3436308..fb436fd5cadc 100644 --- a/packages/core/core/generate-object/stream-object.ts +++ b/packages/core/core/generate-object/stream-object.ts @@ -1,10 +1,10 @@ -import { z } from 'zod'; import { LanguageModelV1, LanguageModelV1CallOptions, LanguageModelV1CallWarning, LanguageModelV1StreamPart, -} from '../../spec'; +} from '@ai-sdk/specification'; +import { z } from 'zod'; import { CallSettings } from '../prompt/call-settings'; import { convertToLanguageModelPrompt } from '../prompt/convert-to-language-model-prompt'; import { getValidatedPrompt } from '../prompt/get-validated-prompt'; diff --git a/packages/core/core/generate-text/generate-text.ts b/packages/core/core/generate-text/generate-text.ts index e4f6d81001b2..fc3e36cd55bf 100644 --- a/packages/core/core/generate-text/generate-text.ts +++ b/packages/core/core/generate-text/generate-text.ts @@ -2,7 +2,7 @@ import { LanguageModelV1, LanguageModelV1CallWarning, LanguageModelV1FinishReason, -} from '../../spec'; +} from '@ai-sdk/specification'; import { CallSettings } from '../prompt/call-settings'; import { convertToLanguageModelPrompt } from '../prompt/convert-to-language-model-prompt'; import { getValidatedPrompt } from '../prompt/get-validated-prompt'; diff --git a/packages/core/core/generate-text/run-tools-transformation.ts b/packages/core/core/generate-text/run-tools-transformation.ts index a33c95b9f807..26c98aecde2e 100644 --- a/packages/core/core/generate-text/run-tools-transformation.ts +++ b/packages/core/core/generate-text/run-tools-transformation.ts @@ -1,4 +1,7 @@ -import { LanguageModelV1StreamPart, NoSuchToolError } from '../../spec'; +import { + LanguageModelV1StreamPart, + NoSuchToolError, +} from '@ai-sdk/specification'; import { generateId } from '../../shared/generate-id'; import { ExperimentalTool } from '../tool'; import { TextStreamPart } from './stream-text'; diff --git a/packages/core/core/generate-text/stream-text.ts b/packages/core/core/generate-text/stream-text.ts index 1b33562ec6fa..9f2b178982c4 100644 --- a/packages/core/core/generate-text/stream-text.ts +++ b/packages/core/core/generate-text/stream-text.ts @@ -1,5 +1,8 @@ -import { LanguageModelV1FinishReason } from '../../spec'; -import { LanguageModelV1, LanguageModelV1CallWarning } from '../../spec/index'; +import { + LanguageModelV1, + LanguageModelV1CallWarning, + LanguageModelV1FinishReason, +} from '@ai-sdk/specification'; import { AIStreamCallbacksAndOptions, createCallbacksTransformer, diff --git a/packages/core/core/generate-text/tool-call.ts b/packages/core/core/generate-text/tool-call.ts index 46ee4a3ad3bf..fbf4f830d702 100644 --- a/packages/core/core/generate-text/tool-call.ts +++ b/packages/core/core/generate-text/tool-call.ts @@ -1,10 +1,10 @@ -import { z } from 'zod'; import { InvalidToolArgumentsError, LanguageModelV1FunctionToolCall, NoSuchToolError, - safeParseJSON, -} from '../../spec'; +} from '@ai-sdk/specification'; +import { z } from 'zod'; +import { safeParseJSON } from '../../spec'; import { ExperimentalTool } from '../tool'; import { ValueOf } from '../util/value-of'; diff --git a/packages/core/core/prompt/convert-to-language-model-prompt.ts b/packages/core/core/prompt/convert-to-language-model-prompt.ts index 4f6bd087d55d..e214e5ddf4fa 100644 --- a/packages/core/core/prompt/convert-to-language-model-prompt.ts +++ b/packages/core/core/prompt/convert-to-language-model-prompt.ts @@ -3,7 +3,7 @@ import { LanguageModelV1Message, LanguageModelV1Prompt, LanguageModelV1TextPart, -} from '../../spec'; +} from '@ai-sdk/specification'; import { detectImageMimeType } from '../util/detect-image-mimetype'; import { convertDataContentToUint8Array } from './data-content'; import { ValidatedPrompt } from './get-validated-prompt'; diff --git a/packages/core/core/prompt/data-content.ts b/packages/core/core/prompt/data-content.ts index edfe551dc02c..58af564e27a2 100644 --- a/packages/core/core/prompt/data-content.ts +++ b/packages/core/core/prompt/data-content.ts @@ -1,5 +1,5 @@ +import { InvalidDataContentError } from '@ai-sdk/specification'; import { - InvalidDataContentError, convertBase64ToUint8Array, convertUint8ArrayToBase64, } from '../../spec'; diff --git a/packages/core/core/prompt/get-validated-prompt.ts b/packages/core/core/prompt/get-validated-prompt.ts index 53f60a991b8e..43b07e44b197 100644 --- a/packages/core/core/prompt/get-validated-prompt.ts +++ b/packages/core/core/prompt/get-validated-prompt.ts @@ -1,4 +1,4 @@ -import { InvalidPromptError } from '../../spec'; +import { InvalidPromptError } from '@ai-sdk/specification'; import { ExperimentalMessage } from './message'; import { Prompt } from './prompt'; diff --git a/packages/core/core/prompt/prepare-call-settings.ts b/packages/core/core/prompt/prepare-call-settings.ts index b32b8486bf01..88bda9a71e71 100644 --- a/packages/core/core/prompt/prepare-call-settings.ts +++ b/packages/core/core/prompt/prepare-call-settings.ts @@ -1,5 +1,5 @@ +import { InvalidArgumentError } from '@ai-sdk/specification'; import { CallSettings } from './call-settings'; -import { InvalidArgumentError } from '../../spec'; /** * Validates call settings and sets default values. diff --git a/packages/core/core/test/mock-language-model-v1.ts b/packages/core/core/test/mock-language-model-v1.ts index 1e21689c7f5c..7d22459dcd6a 100644 --- a/packages/core/core/test/mock-language-model-v1.ts +++ b/packages/core/core/test/mock-language-model-v1.ts @@ -1,4 +1,4 @@ -import { LanguageModelV1 } from '../../spec/index'; +import { LanguageModelV1 } from '@ai-sdk/specification'; export class MockLanguageModelV1 implements LanguageModelV1 { readonly specificationVersion = 'v1'; diff --git a/packages/core/core/util/retry-with-exponential-backoff.ts b/packages/core/core/util/retry-with-exponential-backoff.ts index 73ad7b7c24e2..5119bffc0d6b 100644 --- a/packages/core/core/util/retry-with-exponential-backoff.ts +++ b/packages/core/core/util/retry-with-exponential-backoff.ts @@ -1,4 +1,5 @@ -import { APICallError, RetryError, getErrorMessage } from '../../spec'; +import { APICallError, RetryError } from '@ai-sdk/specification'; +import { getErrorMessage } from '../../spec'; import { delay } from './delay'; export type RetryFunction = ( diff --git a/packages/core/google/convert-to-google-generative-ai-messages.ts b/packages/core/google/convert-to-google-generative-ai-messages.ts index 824247a75918..0b53153751af 100644 --- a/packages/core/google/convert-to-google-generative-ai-messages.ts +++ b/packages/core/google/convert-to-google-generative-ai-messages.ts @@ -1,8 +1,8 @@ import { LanguageModelV1Prompt, UnsupportedFunctionalityError, - convertUint8ArrayToBase64, -} from '../spec'; +} from '@ai-sdk/specification'; +import { convertUint8ArrayToBase64 } from '../spec'; import { GoogleGenerativeAIContentPart, GoogleGenerativeAIPrompt, diff --git a/packages/core/google/google-generative-ai-language-model.test.ts b/packages/core/google/google-generative-ai-language-model.test.ts index 5e4cefa223fb..61d23d153cc2 100644 --- a/packages/core/google/google-generative-ai-language-model.test.ts +++ b/packages/core/google/google-generative-ai-language-model.test.ts @@ -1,4 +1,4 @@ -import { LanguageModelV1Prompt } from '../spec'; +import { LanguageModelV1Prompt } from '@ai-sdk/specification'; import { convertStreamToArray } from '../spec/test/convert-stream-to-array'; import { JsonTestServer } from '../spec/test/json-test-server'; import { StreamingTestServer } from '../spec/test/streaming-test-server'; diff --git a/packages/core/google/google-generative-ai-language-model.ts b/packages/core/google/google-generative-ai-language-model.ts index d9af8588a739..56a7522d0495 100644 --- a/packages/core/google/google-generative-ai-language-model.ts +++ b/packages/core/google/google-generative-ai-language-model.ts @@ -1,11 +1,13 @@ -import { z } from 'zod'; import { LanguageModelV1, LanguageModelV1CallWarning, LanguageModelV1FinishReason, LanguageModelV1StreamPart, - ParseResult, UnsupportedFunctionalityError, +} from '@ai-sdk/specification'; +import { z } from 'zod'; +import { + ParseResult, createEventSourceResponseHandler, createJsonResponseHandler, postJsonToApi, diff --git a/packages/core/google/map-google-generative-ai-finish-reason.ts b/packages/core/google/map-google-generative-ai-finish-reason.ts index d9b9039425ed..2ec5cba3abb2 100644 --- a/packages/core/google/map-google-generative-ai-finish-reason.ts +++ b/packages/core/google/map-google-generative-ai-finish-reason.ts @@ -1,4 +1,4 @@ -import { LanguageModelV1FinishReason } from '../spec'; +import { LanguageModelV1FinishReason } from '@ai-sdk/specification'; export function mapGoogleGenerativeAIFinishReason({ finishReason, diff --git a/packages/core/mistral/convert-to-mistral-chat-messages.ts b/packages/core/mistral/convert-to-mistral-chat-messages.ts index fb9de1fe1b30..daf4782d1454 100644 --- a/packages/core/mistral/convert-to-mistral-chat-messages.ts +++ b/packages/core/mistral/convert-to-mistral-chat-messages.ts @@ -1,4 +1,7 @@ -import { LanguageModelV1Prompt, UnsupportedFunctionalityError } from '../spec'; +import { + LanguageModelV1Prompt, + UnsupportedFunctionalityError, +} from '@ai-sdk/specification'; import { MistralChatPrompt } from './mistral-chat-prompt'; export function convertToMistralChatMessages( diff --git a/packages/core/mistral/map-mistral-finish-reason.ts b/packages/core/mistral/map-mistral-finish-reason.ts index aed6263dc0a6..1ee8ab2a2617 100644 --- a/packages/core/mistral/map-mistral-finish-reason.ts +++ b/packages/core/mistral/map-mistral-finish-reason.ts @@ -1,4 +1,4 @@ -import { LanguageModelV1FinishReason } from '../spec'; +import { LanguageModelV1FinishReason } from '@ai-sdk/specification'; export function mapMistralFinishReason( finishReason: string | null | undefined, diff --git a/packages/core/mistral/mistral-chat-language-model.test.ts b/packages/core/mistral/mistral-chat-language-model.test.ts index a3e4c1b56393..90357e2bb1a5 100644 --- a/packages/core/mistral/mistral-chat-language-model.test.ts +++ b/packages/core/mistral/mistral-chat-language-model.test.ts @@ -1,4 +1,4 @@ -import { LanguageModelV1Prompt } from '../spec'; +import { LanguageModelV1Prompt } from '@ai-sdk/specification'; import { convertStreamToArray } from '../spec/test/convert-stream-to-array'; import { JsonTestServer } from '../spec/test/json-test-server'; import { StreamingTestServer } from '../spec/test/streaming-test-server'; diff --git a/packages/core/mistral/mistral-chat-language-model.ts b/packages/core/mistral/mistral-chat-language-model.ts index 1018988359b5..0482e25ca345 100644 --- a/packages/core/mistral/mistral-chat-language-model.ts +++ b/packages/core/mistral/mistral-chat-language-model.ts @@ -1,11 +1,13 @@ -import { z } from 'zod'; import { LanguageModelV1, LanguageModelV1CallWarning, LanguageModelV1FinishReason, LanguageModelV1StreamPart, - ParseResult, UnsupportedFunctionalityError, +} from '@ai-sdk/specification'; +import { z } from 'zod'; +import { + ParseResult, createEventSourceResponseHandler, createJsonResponseHandler, postJsonToApi, diff --git a/packages/core/openai/convert-to-openai-chat-messages.ts b/packages/core/openai/convert-to-openai-chat-messages.ts index 36343a22fd8b..81c25676a5e2 100644 --- a/packages/core/openai/convert-to-openai-chat-messages.ts +++ b/packages/core/openai/convert-to-openai-chat-messages.ts @@ -1,4 +1,5 @@ -import { LanguageModelV1Prompt, convertUint8ArrayToBase64 } from '../spec'; +import { LanguageModelV1Prompt } from '@ai-sdk/specification'; +import { convertUint8ArrayToBase64 } from '../spec'; import { OpenAIChatPrompt } from './openai-chat-prompt'; export function convertToOpenAIChatMessages( diff --git a/packages/core/openai/convert-to-openai-completion-prompt.ts b/packages/core/openai/convert-to-openai-completion-prompt.ts index 61d12b4f41ae..6835509a9e9d 100644 --- a/packages/core/openai/convert-to-openai-completion-prompt.ts +++ b/packages/core/openai/convert-to-openai-completion-prompt.ts @@ -2,7 +2,7 @@ import { InvalidPromptError, LanguageModelV1Prompt, UnsupportedFunctionalityError, -} from '../spec'; +} from '@ai-sdk/specification'; export function convertToOpenAICompletionPrompt({ prompt, diff --git a/packages/core/openai/map-openai-finish-reason.ts b/packages/core/openai/map-openai-finish-reason.ts index e84b95cdac5c..5018add1ebbc 100644 --- a/packages/core/openai/map-openai-finish-reason.ts +++ b/packages/core/openai/map-openai-finish-reason.ts @@ -1,4 +1,4 @@ -import { LanguageModelV1FinishReason } from '../spec'; +import { LanguageModelV1FinishReason } from '@ai-sdk/specification'; export function mapOpenAIFinishReason( finishReason: string | null | undefined, diff --git a/packages/core/openai/openai-chat-language-model.test.ts b/packages/core/openai/openai-chat-language-model.test.ts index 8d9ca8885aae..6e0c822dbd89 100644 --- a/packages/core/openai/openai-chat-language-model.test.ts +++ b/packages/core/openai/openai-chat-language-model.test.ts @@ -1,4 +1,4 @@ -import { LanguageModelV1Prompt } from '../spec'; +import { LanguageModelV1Prompt } from '@ai-sdk/specification'; import { convertStreamToArray } from '../spec/test/convert-stream-to-array'; import { JsonTestServer } from '../spec/test/json-test-server'; import { StreamingTestServer } from '../spec/test/streaming-test-server'; diff --git a/packages/core/openai/openai-chat-language-model.ts b/packages/core/openai/openai-chat-language-model.ts index db7f724424fe..1c8454b79f3d 100644 --- a/packages/core/openai/openai-chat-language-model.ts +++ b/packages/core/openai/openai-chat-language-model.ts @@ -1,11 +1,13 @@ -import { z } from 'zod'; import { InvalidResponseDataError, LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1StreamPart, - ParseResult, UnsupportedFunctionalityError, +} from '@ai-sdk/specification'; +import { z } from 'zod'; +import { + ParseResult, createEventSourceResponseHandler, createJsonResponseHandler, generateId, diff --git a/packages/core/openai/openai-completion-language-model.test.ts b/packages/core/openai/openai-completion-language-model.test.ts index 2725bc649b3d..0901c8bbd4d4 100644 --- a/packages/core/openai/openai-completion-language-model.test.ts +++ b/packages/core/openai/openai-completion-language-model.test.ts @@ -1,4 +1,4 @@ -import { LanguageModelV1Prompt } from '../spec'; +import { LanguageModelV1Prompt } from '@ai-sdk/specification'; import { convertStreamToArray } from '../spec/test/convert-stream-to-array'; import { JsonTestServer } from '../spec/test/json-test-server'; import { StreamingTestServer } from '../spec/test/streaming-test-server'; diff --git a/packages/core/openai/openai-completion-language-model.ts b/packages/core/openai/openai-completion-language-model.ts index 2f8afc12d964..208784d6e54d 100644 --- a/packages/core/openai/openai-completion-language-model.ts +++ b/packages/core/openai/openai-completion-language-model.ts @@ -1,10 +1,12 @@ -import { z } from 'zod'; import { LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1StreamPart, - ParseResult, UnsupportedFunctionalityError, +} from '@ai-sdk/specification'; +import { z } from 'zod'; +import { + ParseResult, createEventSourceResponseHandler, createJsonResponseHandler, postJsonToApi, diff --git a/packages/core/package.json b/packages/core/package.json index c98a97de6265..6a4e9b3e6168 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -14,7 +14,6 @@ "solid/dist/**/*", "prompts/dist/**/*", "rsc/dist/**/*", - "spec/dist/**/*", "google/dist/**/*", "openai/dist/**/*", "anthropic/dist/**/*", @@ -22,7 +21,7 @@ ], "scripts": { "build": "tsup && cat react/dist/index.server.d.ts >> react/dist/index.d.ts", - "clean": "rm -rf dist && rm -rf core/dist && rm -rf google/dist && rm -rf anthropic/dist && rm -rf openai/dist && rm -rf mistral/dist && rm -rf spec/dist && rm -rf react/dist && rm -rf svelte/dist && rm -rf vue/dist && rm -rf solid/dist && rm -rf rsc/dist", + "clean": "rm -rf dist && rm -rf core/dist && rm -rf google/dist && rm -rf anthropic/dist && rm -rf openai/dist && rm -rf mistral/dist && rm -rf react/dist && rm -rf svelte/dist && rm -rf vue/dist && rm -rf solid/dist && rm -rf rsc/dist", "dev": "tsup --watch", "lint": "eslint \"./**/*.ts*\"", "type-check": "tsc --noEmit", @@ -52,12 +51,6 @@ "import": "./dist/index.mjs", "require": "./dist/index.js" }, - "./spec": { - "types": "./spec/dist/index.d.ts", - "import": "./spec/dist/index.mjs", - "module": "./spec/dist/index.mjs", - "require": "./spec/dist/index.js" - }, "./anthropic": { "types": "./anthropic/dist/index.d.ts", "import": "./anthropic/dist/index.mjs", @@ -115,7 +108,7 @@ } }, "dependencies": { - "@types/json-schema": "7.0.15", + "@ai-sdk/specification": "0.1.0", "secure-json-parse": "2.7.0", "eventsource-parser": "1.1.2", "jsondiffpatch": "0.6.0", @@ -140,6 +133,7 @@ "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.5.1", "@testing-library/vue": "^8.0.1", + "@types/json-schema": "7.0.15", "@types/node": "^17.0.12", "@types/react": "^18.2.8", "@types/react-dom": "^18.2.0", diff --git a/packages/core/spec/index.ts b/packages/core/spec/index.ts index abea6ad5b8ee..50611af24820 100644 --- a/packages/core/spec/index.ts +++ b/packages/core/spec/index.ts @@ -1,3 +1 @@ -export * from './errors/index'; -export * from './language-model/index'; export * from './util/index'; diff --git a/packages/core/spec/util/load-api-key.ts b/packages/core/spec/util/load-api-key.ts index f466e27576d9..062474bcfe69 100644 --- a/packages/core/spec/util/load-api-key.ts +++ b/packages/core/spec/util/load-api-key.ts @@ -1,4 +1,4 @@ -import { LoadAPIKeyError } from '../errors/load-api-key-error'; +import { LoadAPIKeyError } from '@ai-sdk/specification'; export function loadApiKey({ apiKey, diff --git a/packages/core/spec/util/parse-json.ts b/packages/core/spec/util/parse-json.ts index 4a65648d4426..e2f63a17fd72 100644 --- a/packages/core/spec/util/parse-json.ts +++ b/packages/core/spec/util/parse-json.ts @@ -1,7 +1,6 @@ +import { JSONParseError, TypeValidationError } from '@ai-sdk/specification'; import SecureJSON from 'secure-json-parse'; import { ZodSchema } from 'zod'; -import { JSONParseError } from '../errors/json-parse-error'; -import { TypeValidationError } from '../errors/type-validation-error'; import { safeValidateTypes, validateTypes } from './validate-types'; /** diff --git a/packages/core/spec/util/post-to-api.ts b/packages/core/spec/util/post-to-api.ts index d09f39bc9a7b..1befad8680b5 100644 --- a/packages/core/spec/util/post-to-api.ts +++ b/packages/core/spec/util/post-to-api.ts @@ -1,4 +1,4 @@ -import { APICallError } from '../errors/api-call-error'; +import { APICallError } from '@ai-sdk/specification'; import { ResponseHandler } from './response-handler'; export const postJsonToApi = async ({ diff --git a/packages/core/spec/util/response-handler.ts b/packages/core/spec/util/response-handler.ts index b2620eb49973..959fcfaef96f 100644 --- a/packages/core/spec/util/response-handler.ts +++ b/packages/core/spec/util/response-handler.ts @@ -1,10 +1,9 @@ +import { APICallError, NoResponseBodyError } from '@ai-sdk/specification'; import { EventSourceParserStream, ParsedEvent, } from 'eventsource-parser/stream'; import { ZodSchema } from 'zod'; -import { APICallError } from '../errors'; -import { NoResponseBodyError } from '../errors/no-response-body-error'; import { ParseResult, parseJSON, safeParseJSON } from './parse-json'; export type ResponseHandler = (options: { diff --git a/packages/core/spec/util/validate-types.ts b/packages/core/spec/util/validate-types.ts index f9df8f462fb7..62fa80f50538 100644 --- a/packages/core/spec/util/validate-types.ts +++ b/packages/core/spec/util/validate-types.ts @@ -1,5 +1,5 @@ +import { TypeValidationError } from '@ai-sdk/specification'; import { ZodSchema } from 'zod'; -import { TypeValidationError } from '../errors/type-validation-error'; /** * Validates the types of an unknown object using a schema and diff --git a/packages/core/tsup.config.ts b/packages/core/tsup.config.ts index 9e3eec60f0ae..f25b2251ccb9 100644 --- a/packages/core/tsup.config.ts +++ b/packages/core/tsup.config.ts @@ -133,12 +133,4 @@ export default defineConfig([ dts: true, sourcemap: true, }, - // AI Core: Model Specification - { - entry: ['spec/index.ts'], - format: ['cjs', 'esm'], - outDir: 'spec/dist', - dts: true, - sourcemap: true, - }, ]); diff --git a/packages/specification/README.md b/packages/specification/README.md new file mode 100644 index 000000000000..d46c265b6034 --- /dev/null +++ b/packages/specification/README.md @@ -0,0 +1 @@ +# Vercel AI SDK - Language Model Specification diff --git a/packages/specification/package.json b/packages/specification/package.json new file mode 100644 index 000000000000..5e3deb5a7304 --- /dev/null +++ b/packages/specification/package.json @@ -0,0 +1,54 @@ +{ + "name": "@ai-sdk/specification", + "version": "0.1.0", + "license": "Apache-2.0", + "sideEffects": false, + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "files": [ + "dist/**/*" + ], + "scripts": { + "build": "tsup", + "clean": "rm -rf dist", + "dev": "tsup --watch", + "lint": "eslint \"./**/*.ts*\"", + "type-check": "tsc --noEmit", + "prettier-check": "prettier --check \"./**/*.ts*\"" + }, + "exports": { + "./package.json": "./package.json", + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/index.js" + } + }, + "dependencies": { + "json-schema": "0.4.0" + }, + "devDependencies": { + "@types/json-schema": "7.0.15", + "@types/node": "^20", + "@vercel/ai-tsconfig": "workspace:*", + "tsup": "^8" + }, + "engines": { + "node": ">=20" + }, + "publishConfig": { + "access": "public" + }, + "homepage": "https://sdk.vercel.ai/docs", + "repository": { + "type": "git", + "url": "git+https://github.com/vercel/ai.git" + }, + "bugs": { + "url": "https://github.com/vercel/ai/issues" + }, + "keywords": [ + "ai" + ] +} diff --git a/packages/core/spec/errors/api-call-error.ts b/packages/specification/src/errors/api-call-error.ts similarity index 100% rename from packages/core/spec/errors/api-call-error.ts rename to packages/specification/src/errors/api-call-error.ts diff --git a/packages/specification/src/errors/get-error-message.ts b/packages/specification/src/errors/get-error-message.ts new file mode 100644 index 000000000000..62c29e58a51c --- /dev/null +++ b/packages/specification/src/errors/get-error-message.ts @@ -0,0 +1,15 @@ +export function getErrorMessage(error: unknown | undefined) { + if (error == null) { + return 'unknown error'; + } + + if (typeof error === 'string') { + return error; + } + + if (error instanceof Error) { + return error.message; + } + + return JSON.stringify(error); +} diff --git a/packages/core/spec/errors/index.ts b/packages/specification/src/errors/index.ts similarity index 100% rename from packages/core/spec/errors/index.ts rename to packages/specification/src/errors/index.ts diff --git a/packages/core/spec/errors/invalid-argument-error.ts b/packages/specification/src/errors/invalid-argument-error.ts similarity index 100% rename from packages/core/spec/errors/invalid-argument-error.ts rename to packages/specification/src/errors/invalid-argument-error.ts diff --git a/packages/core/spec/errors/invalid-data-content-error.ts b/packages/specification/src/errors/invalid-data-content-error.ts similarity index 100% rename from packages/core/spec/errors/invalid-data-content-error.ts rename to packages/specification/src/errors/invalid-data-content-error.ts diff --git a/packages/core/spec/errors/invalid-prompt-error.ts b/packages/specification/src/errors/invalid-prompt-error.ts similarity index 100% rename from packages/core/spec/errors/invalid-prompt-error.ts rename to packages/specification/src/errors/invalid-prompt-error.ts diff --git a/packages/core/spec/errors/invalid-response-data-error.ts b/packages/specification/src/errors/invalid-response-data-error.ts similarity index 100% rename from packages/core/spec/errors/invalid-response-data-error.ts rename to packages/specification/src/errors/invalid-response-data-error.ts diff --git a/packages/core/spec/errors/invalid-tool-arguments-error.ts b/packages/specification/src/errors/invalid-tool-arguments-error.ts similarity index 95% rename from packages/core/spec/errors/invalid-tool-arguments-error.ts rename to packages/specification/src/errors/invalid-tool-arguments-error.ts index 759bf2913139..60c55b454bc5 100644 --- a/packages/core/spec/errors/invalid-tool-arguments-error.ts +++ b/packages/specification/src/errors/invalid-tool-arguments-error.ts @@ -1,4 +1,4 @@ -import { getErrorMessage } from '../util'; +import { getErrorMessage } from './get-error-message'; export class InvalidToolArgumentsError extends Error { readonly toolName: string; diff --git a/packages/core/spec/errors/json-parse-error.ts b/packages/specification/src/errors/json-parse-error.ts similarity index 93% rename from packages/core/spec/errors/json-parse-error.ts rename to packages/specification/src/errors/json-parse-error.ts index f65514aefe1b..03499161e83c 100644 --- a/packages/core/spec/errors/json-parse-error.ts +++ b/packages/specification/src/errors/json-parse-error.ts @@ -1,4 +1,4 @@ -import { getErrorMessage } from '../util/get-error-message'; +import { getErrorMessage } from './get-error-message'; export class JSONParseError extends Error { // note: property order determines debugging output diff --git a/packages/core/spec/errors/load-api-key-error.ts b/packages/specification/src/errors/load-api-key-error.ts similarity index 100% rename from packages/core/spec/errors/load-api-key-error.ts rename to packages/specification/src/errors/load-api-key-error.ts diff --git a/packages/core/spec/errors/no-object-generated-error.ts b/packages/specification/src/errors/no-object-generated-error.ts similarity index 100% rename from packages/core/spec/errors/no-object-generated-error.ts rename to packages/specification/src/errors/no-object-generated-error.ts diff --git a/packages/core/spec/errors/no-response-body-error.ts b/packages/specification/src/errors/no-response-body-error.ts similarity index 100% rename from packages/core/spec/errors/no-response-body-error.ts rename to packages/specification/src/errors/no-response-body-error.ts diff --git a/packages/core/spec/errors/no-such-tool-error.ts b/packages/specification/src/errors/no-such-tool-error.ts similarity index 100% rename from packages/core/spec/errors/no-such-tool-error.ts rename to packages/specification/src/errors/no-such-tool-error.ts diff --git a/packages/core/spec/errors/retry-error.ts b/packages/specification/src/errors/retry-error.ts similarity index 100% rename from packages/core/spec/errors/retry-error.ts rename to packages/specification/src/errors/retry-error.ts diff --git a/packages/core/spec/errors/tool-call-parse-error.ts b/packages/specification/src/errors/tool-call-parse-error.ts similarity index 95% rename from packages/core/spec/errors/tool-call-parse-error.ts rename to packages/specification/src/errors/tool-call-parse-error.ts index 369c781092ab..c06cc7e56e7c 100644 --- a/packages/core/spec/errors/tool-call-parse-error.ts +++ b/packages/specification/src/errors/tool-call-parse-error.ts @@ -1,5 +1,5 @@ import { LanguageModelV1FunctionTool } from '../language-model/v1/language-model-v1-function-tool'; -import { getErrorMessage } from '../util/get-error-message'; +import { getErrorMessage } from './get-error-message'; export class ToolCallParseError extends Error { readonly cause: unknown; diff --git a/packages/core/spec/errors/type-validation-error.ts b/packages/specification/src/errors/type-validation-error.ts similarity index 93% rename from packages/core/spec/errors/type-validation-error.ts rename to packages/specification/src/errors/type-validation-error.ts index 83ebc18925ab..0b250f5b33af 100644 --- a/packages/core/spec/errors/type-validation-error.ts +++ b/packages/specification/src/errors/type-validation-error.ts @@ -1,4 +1,4 @@ -import { getErrorMessage } from '../util/get-error-message'; +import { getErrorMessage } from './get-error-message'; export class TypeValidationError extends Error { readonly value: unknown; diff --git a/packages/core/spec/errors/unsupported-functionality-error.ts b/packages/specification/src/errors/unsupported-functionality-error.ts similarity index 100% rename from packages/core/spec/errors/unsupported-functionality-error.ts rename to packages/specification/src/errors/unsupported-functionality-error.ts diff --git a/packages/core/spec/errors/unsupported-json-schema-error.ts b/packages/specification/src/errors/unsupported-json-schema-error.ts similarity index 100% rename from packages/core/spec/errors/unsupported-json-schema-error.ts rename to packages/specification/src/errors/unsupported-json-schema-error.ts diff --git a/packages/specification/src/index.ts b/packages/specification/src/index.ts new file mode 100644 index 000000000000..e47c91e1bf17 --- /dev/null +++ b/packages/specification/src/index.ts @@ -0,0 +1,2 @@ +export * from './errors/index'; +export * from './language-model/index'; diff --git a/packages/core/spec/language-model/index.ts b/packages/specification/src/language-model/index.ts similarity index 100% rename from packages/core/spec/language-model/index.ts rename to packages/specification/src/language-model/index.ts diff --git a/packages/core/spec/language-model/v1/index.ts b/packages/specification/src/language-model/v1/index.ts similarity index 100% rename from packages/core/spec/language-model/v1/index.ts rename to packages/specification/src/language-model/v1/index.ts diff --git a/packages/core/spec/language-model/v1/language-model-v1-call-options.ts b/packages/specification/src/language-model/v1/language-model-v1-call-options.ts similarity index 100% rename from packages/core/spec/language-model/v1/language-model-v1-call-options.ts rename to packages/specification/src/language-model/v1/language-model-v1-call-options.ts diff --git a/packages/core/spec/language-model/v1/language-model-v1-call-settings.ts b/packages/specification/src/language-model/v1/language-model-v1-call-settings.ts similarity index 100% rename from packages/core/spec/language-model/v1/language-model-v1-call-settings.ts rename to packages/specification/src/language-model/v1/language-model-v1-call-settings.ts diff --git a/packages/core/spec/language-model/v1/language-model-v1-call-warning.ts b/packages/specification/src/language-model/v1/language-model-v1-call-warning.ts similarity index 100% rename from packages/core/spec/language-model/v1/language-model-v1-call-warning.ts rename to packages/specification/src/language-model/v1/language-model-v1-call-warning.ts diff --git a/packages/core/spec/language-model/v1/language-model-v1-finish-reason.ts b/packages/specification/src/language-model/v1/language-model-v1-finish-reason.ts similarity index 100% rename from packages/core/spec/language-model/v1/language-model-v1-finish-reason.ts rename to packages/specification/src/language-model/v1/language-model-v1-finish-reason.ts diff --git a/packages/core/spec/language-model/v1/language-model-v1-function-tool-call.ts b/packages/specification/src/language-model/v1/language-model-v1-function-tool-call.ts similarity index 100% rename from packages/core/spec/language-model/v1/language-model-v1-function-tool-call.ts rename to packages/specification/src/language-model/v1/language-model-v1-function-tool-call.ts diff --git a/packages/core/spec/language-model/v1/language-model-v1-function-tool.ts b/packages/specification/src/language-model/v1/language-model-v1-function-tool.ts similarity index 100% rename from packages/core/spec/language-model/v1/language-model-v1-function-tool.ts rename to packages/specification/src/language-model/v1/language-model-v1-function-tool.ts diff --git a/packages/core/spec/language-model/v1/language-model-v1-prompt.ts b/packages/specification/src/language-model/v1/language-model-v1-prompt.ts similarity index 100% rename from packages/core/spec/language-model/v1/language-model-v1-prompt.ts rename to packages/specification/src/language-model/v1/language-model-v1-prompt.ts diff --git a/packages/core/spec/language-model/v1/language-model-v1.ts b/packages/specification/src/language-model/v1/language-model-v1.ts similarity index 100% rename from packages/core/spec/language-model/v1/language-model-v1.ts rename to packages/specification/src/language-model/v1/language-model-v1.ts diff --git a/packages/specification/tsconfig.json b/packages/specification/tsconfig.json new file mode 100644 index 000000000000..3dc0ba4f10f5 --- /dev/null +++ b/packages/specification/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "./node_modules/@vercel/ai-tsconfig/react-library.json", + "compilerOptions": { + "target": "ES2018", + "stripInternal": true + }, + "include": ["."], + "exclude": ["dist", "build", "node_modules"] +} diff --git a/packages/specification/tsup.config.ts b/packages/specification/tsup.config.ts new file mode 100644 index 000000000000..d321ab0bc17a --- /dev/null +++ b/packages/specification/tsup.config.ts @@ -0,0 +1,11 @@ +import { defineConfig } from 'tsup'; + +export default defineConfig([ + { + entry: ['src/index.ts'], + format: ['cjs', 'esm'], + external: ['react', 'svelte', 'vue'], + dts: true, + sourcemap: true, + }, +]); diff --git a/packages/specification/turbo.json b/packages/specification/turbo.json new file mode 100644 index 000000000000..b6e9be79bd21 --- /dev/null +++ b/packages/specification/turbo.json @@ -0,0 +1,8 @@ +{ + "extends": ["//"], + "pipeline": { + "build": { + "outputs": ["**/dist/**"] + } + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39d51523bcca..6b0b7d6af223 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -502,7 +502,7 @@ importers: version: link:../../packages/core langchain: specifier: ^0.0.196 - version: 0.0.196 + version: 0.0.196(@aws-sdk/client-bedrock-runtime@3.451.0)(@huggingface/inference@2.6.4)(cohere-ai@7.6.2)(jsdom@23.0.0) next: specifier: 14.1.1 version: 14.1.1(react-dom@18.2.0)(react@18.2.0) @@ -1072,9 +1072,9 @@ importers: packages/core: dependencies: - '@types/json-schema': - specifier: 7.0.15 - version: 7.0.15 + '@ai-sdk/specification': + specifier: 0.1.0 + version: link:../specification eventsource-parser: specifier: 1.1.2 version: 1.1.2 @@ -1151,6 +1151,9 @@ importers: '@testing-library/vue': specifier: ^8.0.1 version: 8.0.1(@vue/compiler-sfc@3.3.8)(vue@3.3.8) + '@types/json-schema': + specifier: 7.0.15 + version: 7.0.15 '@types/node': specifier: ^17.0.12 version: 17.0.45 @@ -1212,6 +1215,25 @@ importers: specifier: 3.22.4 version: 3.22.4 + packages/specification: + dependencies: + json-schema: + specifier: 0.4.0 + version: 0.4.0 + devDependencies: + '@types/json-schema': + specifier: 7.0.15 + version: 7.0.15 + '@types/node': + specifier: ^20 + version: 20.11.20 + '@vercel/ai-tsconfig': + specifier: workspace:* + version: link:../../tools/tsconfig + tsup: + specifier: ^8 + version: 8.0.2 + tools/eslint-config: dependencies: eslint-config-next: @@ -5712,6 +5734,126 @@ packages: picomatch: 2.3.1 rollup: 3.29.4 + /@rollup/rollup-android-arm-eabi@4.14.1: + resolution: {integrity: sha512-fH8/o8nSUek8ceQnT7K4EQbSiV7jgkHq81m9lWZFIXjJ7lJzpWXbQFpT/Zh6OZYnpFykvzC3fbEvEAFZu03dPA==} + cpu: [arm] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-android-arm64@4.14.1: + resolution: {integrity: sha512-Y/9OHLjzkunF+KGEoJr3heiD5X9OLa8sbT1lm0NYeKyaM3oMhhQFvPB0bNZYJwlq93j8Z6wSxh9+cyKQaxS7PQ==} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-darwin-arm64@4.14.1: + resolution: {integrity: sha512-+kecg3FY84WadgcuSVm6llrABOdQAEbNdnpi5X3UwWiFVhZIZvKgGrF7kmLguvxHNQy+UuRV66cLVl3S+Rkt+Q==} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-darwin-x64@4.14.1: + resolution: {integrity: sha512-2pYRzEjVqq2TB/UNv47BV/8vQiXkFGVmPFwJb+1E0IFFZbIX8/jo1olxqqMbo6xCXf8kabANhp5bzCij2tFLUA==} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-arm-gnueabihf@4.14.1: + resolution: {integrity: sha512-mS6wQ6Do6/wmrF9aTFVpIJ3/IDXhg1EZcQFYHZLHqw6AzMBjTHWnCG35HxSqUNphh0EHqSM6wRTT8HsL1C0x5g==} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-arm64-gnu@4.14.1: + resolution: {integrity: sha512-p9rGKYkHdFMzhckOTFubfxgyIO1vw//7IIjBBRVzyZebWlzRLeNhqxuSaZ7kCEKVkm/kuC9fVRW9HkC/zNRG2w==} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-arm64-musl@4.14.1: + resolution: {integrity: sha512-nDY6Yz5xS/Y4M2i9JLQd3Rofh5OR8Bn8qe3Mv/qCVpHFlwtZSBYSPaU4mrGazWkXrdQ98GB//H0BirGR/SKFSw==} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-powerpc64le-gnu@4.14.1: + resolution: {integrity: sha512-im7HE4VBL+aDswvcmfx88Mp1soqL9OBsdDBU8NqDEYtkri0qV0THhQsvZtZeNNlLeCUQ16PZyv7cqutjDF35qw==} + cpu: [ppc64le] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-riscv64-gnu@4.14.1: + resolution: {integrity: sha512-RWdiHuAxWmzPJgaHJdpvUUlDz8sdQz4P2uv367T2JocdDa98iRw2UjIJ4QxSyt077mXZT2X6pKfT2iYtVEvOFw==} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-s390x-gnu@4.14.1: + resolution: {integrity: sha512-VMgaGQ5zRX6ZqV/fas65/sUGc9cPmsntq2FiGmayW9KMNfWVG/j0BAqImvU4KTeOOgYSf1F+k6at1UfNONuNjA==} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-x64-gnu@4.14.1: + resolution: {integrity: sha512-9Q7DGjZN+hTdJomaQ3Iub4m6VPu1r94bmK2z3UeWP3dGUecRC54tmVu9vKHTm1bOt3ASoYtEz6JSRLFzrysKlA==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-x64-musl@4.14.1: + resolution: {integrity: sha512-JNEG/Ti55413SsreTguSx0LOVKX902OfXIKVg+TCXO6Gjans/k9O6ww9q3oLGjNDaTLxM+IHFMeXy/0RXL5R/g==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-win32-arm64-msvc@4.14.1: + resolution: {integrity: sha512-ryS22I9y0mumlLNwDFYZRDFLwWh3aKaC72CWjFcFvxK0U6v/mOkM5Up1bTbCRAhv3kEIwW2ajROegCIQViUCeA==} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-win32-ia32-msvc@4.14.1: + resolution: {integrity: sha512-TdloItiGk+T0mTxKx7Hp279xy30LspMso+GzQvV2maYePMAWdmrzqSNZhUpPj3CGw12aGj57I026PgLCTu8CGg==} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-win32-x64-msvc@4.14.1: + resolution: {integrity: sha512-wQGI+LY/Py20zdUPq+XCem7JcPOyzIJBm3dli+56DJsQOHbnXZFEwgmnC6el1TPAfC8lBT3m+z69RmLykNUbew==} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@rushstack/eslint-patch@1.5.1: resolution: {integrity: sha512-6i/8UoL0P5y4leBIGzvkZdS85RDMG9y1ihZzmTZQ5LdHUYmZ7pKFoj8X0236s3lusPs1Fa5HTQUpwI+UfTcmeA==} @@ -6461,6 +6603,7 @@ packages: /@types/json-schema@7.0.15: resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} + dev: true /@types/json5@0.0.29: resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} @@ -7812,6 +7955,16 @@ packages: load-tsconfig: 0.2.5 dev: true + /bundle-require@4.0.2(esbuild@0.19.12): + resolution: {integrity: sha512-jwzPOChofl67PSTW2SGubV9HBQAhhR2i6nskiOThauo9dzwDUgOWQScFVaJkjEfYX+UXiD+LEx8EblQMc2wIag==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + peerDependencies: + esbuild: '>=0.17' + dependencies: + esbuild: 0.19.12 + load-tsconfig: 0.2.5 + dev: true + /busboy@1.6.0: resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==} engines: {node: '>=10.16.0'} @@ -8197,7 +8350,6 @@ packages: url-join: 4.0.1 transitivePeerDependencies: - encoding - dev: true /color-convert@1.9.3: resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==} @@ -11910,328 +12062,6 @@ packages: - encoding dev: false - /langchain@0.0.196: - resolution: {integrity: sha512-kt17GGTDFWHNv3jJOIXymsQxfa+h9UQ6hrHbhur+V2pV6RBKO5E+RRCvnCqBzbnOPtrlkENF6Wl3Ezmsfo21dg==} - engines: {node: '>=18'} - peerDependencies: - '@aws-crypto/sha256-js': ^5.0.0 - '@aws-sdk/client-bedrock-runtime': ^3.422.0 - '@aws-sdk/client-dynamodb': ^3.310.0 - '@aws-sdk/client-kendra': ^3.352.0 - '@aws-sdk/client-lambda': ^3.310.0 - '@aws-sdk/client-s3': ^3.310.0 - '@aws-sdk/client-sagemaker-runtime': ^3.310.0 - '@aws-sdk/client-sfn': ^3.310.0 - '@aws-sdk/credential-provider-node': ^3.388.0 - '@azure/storage-blob': ^12.15.0 - '@clickhouse/client': ^0.0.14 - '@cloudflare/ai': ^1.0.12 - '@elastic/elasticsearch': ^8.4.0 - '@getmetal/metal-sdk': '*' - '@getzep/zep-js': ^0.9.0 - '@gomomento/sdk': ^1.47.1 - '@gomomento/sdk-core': ^1.47.1 - '@gomomento/sdk-web': ^1.47.1 - '@google-ai/generativelanguage': ^0.2.1 - '@google-cloud/storage': ^6.10.1 - '@huggingface/inference': ^2.6.4 - '@mozilla/readability': '*' - '@notionhq/client': ^2.2.10 - '@opensearch-project/opensearch': '*' - '@pinecone-database/pinecone': ^1.1.0 - '@planetscale/database': ^1.8.0 - '@qdrant/js-client-rest': ^1.2.0 - '@raycast/api': ^1.55.2 - '@rockset/client': ^0.9.1 - '@smithy/eventstream-codec': ^2.0.5 - '@smithy/protocol-http': ^3.0.6 - '@smithy/signature-v4': ^2.0.10 - '@smithy/util-utf8': ^2.0.0 - '@supabase/postgrest-js': ^1.1.1 - '@supabase/supabase-js': ^2.10.0 - '@tensorflow-models/universal-sentence-encoder': '*' - '@tensorflow/tfjs-converter': '*' - '@tensorflow/tfjs-core': '*' - '@upstash/redis': ^1.20.6 - '@vercel/kv': ^0.2.3 - '@vercel/postgres': ^0.5.0 - '@writerai/writer-sdk': ^0.40.2 - '@xata.io/client': ^0.25.1 - '@xenova/transformers': ^2.5.4 - '@zilliz/milvus2-sdk-node': '>=2.2.7' - apify-client: ^2.7.1 - assemblyai: ^2.0.2 - axios: '*' - cassandra-driver: ^4.7.2 - cheerio: ^1.0.0-rc.12 - chromadb: '*' - closevector-common: 0.1.0-alpha.1 - closevector-node: 0.1.0-alpha.10 - closevector-web: 0.1.0-alpha.16 - cohere-ai: '>=6.0.0' - convex: ^1.3.1 - d3-dsv: ^2.0.0 - epub2: ^3.0.1 - faiss-node: ^0.5.1 - fast-xml-parser: ^4.2.7 - firebase-admin: ^11.9.0 - google-auth-library: ^8.9.0 - googleapis: ^126.0.1 - hnswlib-node: ^1.4.2 - html-to-text: ^9.0.5 - ignore: ^5.2.0 - ioredis: ^5.3.2 - jsdom: '*' - llmonitor: ^0.5.9 - lodash: ^4.17.21 - mammoth: '*' - mongodb: ^5.2.0 - mysql2: ^3.3.3 - neo4j-driver: '*' - node-llama-cpp: '*' - notion-to-md: ^3.1.0 - pdf-parse: 1.1.1 - peggy: ^3.0.2 - pg: ^8.11.0 - pg-copy-streams: ^6.0.5 - pickleparser: ^0.2.1 - playwright: ^1.32.1 - portkey-ai: ^0.1.11 - puppeteer: ^19.7.2 - redis: ^4.6.4 - replicate: ^0.18.0 - sonix-speech-recognition: ^2.1.1 - srt-parser-2: ^1.2.2 - typeorm: ^0.3.12 - typesense: ^1.5.3 - usearch: ^1.1.1 - vectordb: ^0.1.4 - voy-search: 0.6.2 - weaviate-ts-client: ^1.4.0 - web-auth-library: ^1.0.3 - ws: ^8.14.2 - youtube-transcript: ^1.0.6 - youtubei.js: ^5.8.0 - peerDependenciesMeta: - '@aws-crypto/sha256-js': - optional: true - '@aws-sdk/client-bedrock-runtime': - optional: true - '@aws-sdk/client-dynamodb': - optional: true - '@aws-sdk/client-kendra': - optional: true - '@aws-sdk/client-lambda': - optional: true - '@aws-sdk/client-s3': - optional: true - '@aws-sdk/client-sagemaker-runtime': - optional: true - '@aws-sdk/client-sfn': - optional: true - '@aws-sdk/credential-provider-node': - optional: true - '@azure/storage-blob': - optional: true - '@clickhouse/client': - optional: true - '@cloudflare/ai': - optional: true - '@elastic/elasticsearch': - optional: true - '@getmetal/metal-sdk': - optional: true - '@getzep/zep-js': - optional: true - '@gomomento/sdk': - optional: true - '@gomomento/sdk-core': - optional: true - '@gomomento/sdk-web': - optional: true - '@google-ai/generativelanguage': - optional: true - '@google-cloud/storage': - optional: true - '@huggingface/inference': - optional: true - '@mozilla/readability': - optional: true - '@notionhq/client': - optional: true - '@opensearch-project/opensearch': - optional: true - '@pinecone-database/pinecone': - optional: true - '@planetscale/database': - optional: true - '@qdrant/js-client-rest': - optional: true - '@raycast/api': - optional: true - '@rockset/client': - optional: true - '@smithy/eventstream-codec': - optional: true - '@smithy/protocol-http': - optional: true - '@smithy/signature-v4': - optional: true - '@smithy/util-utf8': - optional: true - '@supabase/postgrest-js': - optional: true - '@supabase/supabase-js': - optional: true - '@tensorflow-models/universal-sentence-encoder': - optional: true - '@tensorflow/tfjs-converter': - optional: true - '@tensorflow/tfjs-core': - optional: true - '@upstash/redis': - optional: true - '@vercel/kv': - optional: true - '@vercel/postgres': - optional: true - '@writerai/writer-sdk': - optional: true - '@xata.io/client': - optional: true - '@xenova/transformers': - optional: true - '@zilliz/milvus2-sdk-node': - optional: true - apify-client: - optional: true - assemblyai: - optional: true - axios: - optional: true - cassandra-driver: - optional: true - cheerio: - optional: true - chromadb: - optional: true - closevector-common: - optional: true - closevector-node: - optional: true - closevector-web: - optional: true - cohere-ai: - optional: true - convex: - optional: true - d3-dsv: - optional: true - epub2: - optional: true - faiss-node: - optional: true - fast-xml-parser: - optional: true - firebase-admin: - optional: true - google-auth-library: - optional: true - googleapis: - optional: true - hnswlib-node: - optional: true - html-to-text: - optional: true - ignore: - optional: true - ioredis: - optional: true - jsdom: - optional: true - llmonitor: - optional: true - lodash: - optional: true - mammoth: - optional: true - mongodb: - optional: true - mysql2: - optional: true - neo4j-driver: - optional: true - node-llama-cpp: - optional: true - notion-to-md: - optional: true - pdf-parse: - optional: true - peggy: - optional: true - pg: - optional: true - pg-copy-streams: - optional: true - pickleparser: - optional: true - playwright: - optional: true - portkey-ai: - optional: true - puppeteer: - optional: true - redis: - optional: true - replicate: - optional: true - sonix-speech-recognition: - optional: true - srt-parser-2: - optional: true - typeorm: - optional: true - typesense: - optional: true - usearch: - optional: true - vectordb: - optional: true - voy-search: - optional: true - weaviate-ts-client: - optional: true - web-auth-library: - optional: true - ws: - optional: true - youtube-transcript: - optional: true - youtubei.js: - optional: true - dependencies: - '@anthropic-ai/sdk': 0.9.1 - binary-extensions: 2.2.0 - expr-eval: 2.0.2 - flat: 5.0.2 - js-tiktoken: 1.0.7 - js-yaml: 4.1.0 - jsonpointer: 5.0.1 - langchain-core: 0.0.1 - langchainhub: 0.0.6 - langsmith: 0.0.48 - ml-distance: 4.0.1 - openai: 4.28.4 - openapi-types: 12.1.3 - p-retry: 4.6.2 - uuid: 9.0.1 - yaml: 2.3.4 - zod: 3.22.4 - zod-to-json-schema: 3.20.3(zod@3.22.4) - transitivePeerDependencies: - - encoding - dev: false - /langchain@0.0.196(@aws-sdk/client-bedrock-runtime@3.451.0)(@huggingface/inference@2.6.4)(cohere-ai@7.6.2)(jsdom@23.0.0): resolution: {integrity: sha512-kt17GGTDFWHNv3jJOIXymsQxfa+h9UQ6hrHbhur+V2pV6RBKO5E+RRCvnCqBzbnOPtrlkENF6Wl3Ezmsfo21dg==} engines: {node: '>=18'} @@ -12547,7 +12377,7 @@ packages: langchainhub: 0.0.6 langsmith: 0.0.48 ml-distance: 4.0.1 - openai: 4.29.0 + openai: 4.28.4 openapi-types: 12.1.3 p-retry: 4.6.2 uuid: 9.0.1 @@ -12556,7 +12386,6 @@ packages: zod-to-json-schema: 3.20.3(zod@3.22.4) transitivePeerDependencies: - encoding - dev: true /langchainhub@0.0.6: resolution: {integrity: sha512-SW6105T+YP1cTe0yMf//7kyshCgvCTyFBMTgH2H3s9rTAR4e+78DA/BBrUL/Mt4Q5eMWui7iGuAYb3pgGsdQ9w==} @@ -14145,7 +13974,6 @@ packages: web-streams-polyfill: 3.2.1 transitivePeerDependencies: - encoding - dev: false /openai@4.29.0: resolution: {integrity: sha512-ic6C681bSow1XQdKhADthM/OOKqNL05M1gCFLx1mRqLJ+yH49v6qnvaWQ76kwqI/IieCuVTXfRfTk3sz4cB45w==} @@ -15587,6 +15415,31 @@ packages: optionalDependencies: fsevents: 2.3.3 + /rollup@4.14.1: + resolution: {integrity: sha512-4LnHSdd3QK2pa1J6dFbfm1HN0D7vSK/ZuZTsdyUAlA6Rr1yTouUTL13HaDOGJVgby461AhrNGBS7sCGXXtT+SA==} + engines: {node: '>=18.0.0', npm: '>=8.0.0'} + hasBin: true + dependencies: + '@types/estree': 1.0.5 + optionalDependencies: + '@rollup/rollup-android-arm-eabi': 4.14.1 + '@rollup/rollup-android-arm64': 4.14.1 + '@rollup/rollup-darwin-arm64': 4.14.1 + '@rollup/rollup-darwin-x64': 4.14.1 + '@rollup/rollup-linux-arm-gnueabihf': 4.14.1 + '@rollup/rollup-linux-arm64-gnu': 4.14.1 + '@rollup/rollup-linux-arm64-musl': 4.14.1 + '@rollup/rollup-linux-powerpc64le-gnu': 4.14.1 + '@rollup/rollup-linux-riscv64-gnu': 4.14.1 + '@rollup/rollup-linux-s390x-gnu': 4.14.1 + '@rollup/rollup-linux-x64-gnu': 4.14.1 + '@rollup/rollup-linux-x64-musl': 4.14.1 + '@rollup/rollup-win32-arm64-msvc': 4.14.1 + '@rollup/rollup-win32-ia32-msvc': 4.14.1 + '@rollup/rollup-win32-x64-msvc': 4.14.1 + fsevents: 2.3.3 + dev: true + /route-sort@1.0.0: resolution: {integrity: sha512-SFgmvjoIhp5S4iBEDW3XnbT+7PRuZ55oRuNjY+CDB1SGZkyCG9bqQ3/dhaZTctTBYMAvDxd2Uy9dStuaUfgJqQ==} engines: {node: '>= 6'} @@ -16955,6 +16808,44 @@ packages: - ts-node dev: true + /tsup@8.0.2: + resolution: {integrity: sha512-NY8xtQXdH7hDUAZwcQdY/Vzlw9johQsaqf7iwZ6g1DOUlFYQ5/AtVAjTvihhEyeRlGo4dLRVHtrRaL35M1daqQ==} + engines: {node: '>=18'} + hasBin: true + peerDependencies: + '@microsoft/api-extractor': ^7.36.0 + '@swc/core': ^1 + postcss: ^8.4.12 + typescript: '>=4.5.0' + peerDependenciesMeta: + '@microsoft/api-extractor': + optional: true + '@swc/core': + optional: true + postcss: + optional: true + typescript: + optional: true + dependencies: + bundle-require: 4.0.2(esbuild@0.19.12) + cac: 6.7.14 + chokidar: 3.5.3 + debug: 4.3.4 + esbuild: 0.19.12 + execa: 5.1.1 + globby: 11.1.0 + joycon: 3.1.1 + postcss-load-config: 4.0.1(postcss@8.4.31) + resolve-from: 5.0.0 + rollup: 4.14.1 + source-map: 0.8.0-beta.0 + sucrase: 3.34.0 + tree-kill: 1.2.2 + transitivePeerDependencies: + - supports-color + - ts-node + dev: true + /tsutils@3.21.0(typescript@5.1.3): resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'}