ai 5.1.0-beta.8 → 6.0.0-beta.100
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/CHANGELOG.md +704 -0
- package/README.md +130 -45
- package/dist/index.d.mts +2212 -1704
- package/dist/index.d.ts +2212 -1704
- package/dist/index.js +4435 -3547
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4385 -3515
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +7 -7
- package/dist/internal/index.d.ts +7 -7
- package/dist/internal/index.js +186 -79
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +186 -79
- package/dist/internal/index.mjs.map +1 -1
- package/dist/test/index.d.mts +69 -53
- package/dist/test/index.d.ts +69 -53
- package/dist/test/index.js +61 -27
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +55 -22
- package/dist/test/index.mjs.map +1 -1
- package/package.json +12 -15
- package/dist/mcp-stdio/index.d.mts +0 -89
- package/dist/mcp-stdio/index.d.ts +0 -89
- package/dist/mcp-stdio/index.js +0 -349
- package/dist/mcp-stdio/index.js.map +0 -1
- package/dist/mcp-stdio/index.mjs +0 -322
- package/dist/mcp-stdio/index.mjs.map +0 -1
- package/mcp-stdio.d.ts +0 -1
package/dist/test/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../test/index.ts","../../src/test/not-implemented.ts","../../src/test/mock-embedding-model-v2.ts","../../src/test/mock-image-model-v2.ts","../../src/test/mock-language-model-v2.ts","../../src/test/mock-provider-v2.ts","../../src/test/mock-speech-model-v2.ts","../../src/test/mock-transcription-model-v2.ts","../../src/test/mock-values.ts","../../src/util/simulate-readable-stream.ts"],"sourcesContent":["export {\n convertArrayToAsyncIterable,\n convertArrayToReadableStream,\n convertReadableStreamToArray,\n mockId,\n} from '@ai-sdk/provider-utils/test';\nexport { MockEmbeddingModelV3 } from '../src/test/mock-embedding-model-v2';\nexport { MockImageModelV2 } from '../src/test/mock-image-model-v2';\nexport { MockLanguageModelV2 } from '../src/test/mock-language-model-v2';\nexport { MockProviderV2 } from '../src/test/mock-provider-v2';\nexport { MockSpeechModelV2 } from '../src/test/mock-speech-model-v2';\nexport { MockTranscriptionModelV2 } from '../src/test/mock-transcription-model-v2';\nexport { mockValues } from '../src/test/mock-values';\n\nimport { simulateReadableStream as originalSimulateReadableStream } from '../src/util/simulate-readable-stream';\n\n/**\n * @deprecated Use `simulateReadableStream` from `ai` instead.\n */\nexport const simulateReadableStream = originalSimulateReadableStream;\n","export function notImplemented(): never {\n throw new Error('Not implemented');\n}\n","import { EmbeddingModelV3 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockEmbeddingModelV3<VALUE> implements EmbeddingModelV3<VALUE> {\n readonly specificationVersion = 'v3';\n\n readonly provider: EmbeddingModelV3<VALUE>['provider'];\n readonly modelId: EmbeddingModelV3<VALUE>['modelId'];\n readonly maxEmbeddingsPerCall: EmbeddingModelV3<VALUE>['maxEmbeddingsPerCall'];\n readonly supportsParallelCalls: EmbeddingModelV3<VALUE>['supportsParallelCalls'];\n\n doEmbed: EmbeddingModelV3<VALUE>['doEmbed'];\n\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n maxEmbeddingsPerCall = 1,\n supportsParallelCalls = false,\n doEmbed = notImplemented,\n }: {\n provider?: EmbeddingModelV3<VALUE>['provider'];\n modelId?: EmbeddingModelV3<VALUE>['modelId'];\n maxEmbeddingsPerCall?:\n | EmbeddingModelV3<VALUE>['maxEmbeddingsPerCall']\n | null;\n supportsParallelCalls?: EmbeddingModelV3<VALUE>['supportsParallelCalls'];\n doEmbed?: EmbeddingModelV3<VALUE>['doEmbed'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.maxEmbeddingsPerCall = maxEmbeddingsPerCall ?? undefined;\n this.supportsParallelCalls = supportsParallelCalls;\n this.doEmbed = doEmbed;\n }\n}\n","import { ImageModelV2 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockImageModelV2 implements ImageModelV2 {\n readonly specificationVersion = 'v2';\n readonly provider: ImageModelV2['provider'];\n readonly modelId: ImageModelV2['modelId'];\n readonly maxImagesPerCall: ImageModelV2['maxImagesPerCall'];\n\n doGenerate: ImageModelV2['doGenerate'];\n\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n maxImagesPerCall = 1,\n doGenerate = notImplemented,\n }: {\n provider?: ImageModelV2['provider'];\n modelId?: ImageModelV2['modelId'];\n maxImagesPerCall?: ImageModelV2['maxImagesPerCall'];\n doGenerate?: ImageModelV2['doGenerate'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.maxImagesPerCall = maxImagesPerCall;\n this.doGenerate = doGenerate;\n }\n}\n","import { LanguageModelV2 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockLanguageModelV2 implements LanguageModelV2 {\n readonly specificationVersion = 'v2';\n\n private _supportedUrls: () => LanguageModelV2['supportedUrls'];\n\n readonly provider: LanguageModelV2['provider'];\n readonly modelId: LanguageModelV2['modelId'];\n\n doGenerate: LanguageModelV2['doGenerate'];\n doStream: LanguageModelV2['doStream'];\n\n doGenerateCalls: Parameters<LanguageModelV2['doGenerate']>[0][] = [];\n doStreamCalls: Parameters<LanguageModelV2['doStream']>[0][] = [];\n\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n supportedUrls = {},\n doGenerate = notImplemented,\n doStream = notImplemented,\n }: {\n provider?: LanguageModelV2['provider'];\n modelId?: LanguageModelV2['modelId'];\n supportedUrls?:\n | LanguageModelV2['supportedUrls']\n | (() => LanguageModelV2['supportedUrls']);\n doGenerate?:\n | LanguageModelV2['doGenerate']\n | Awaited<ReturnType<LanguageModelV2['doGenerate']>>\n | Awaited<ReturnType<LanguageModelV2['doGenerate']>>[];\n doStream?:\n | LanguageModelV2['doStream']\n | Awaited<ReturnType<LanguageModelV2['doStream']>>\n | Awaited<ReturnType<LanguageModelV2['doStream']>>[];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.doGenerate = async options => {\n this.doGenerateCalls.push(options);\n\n if (typeof doGenerate === 'function') {\n return doGenerate(options);\n } else if (Array.isArray(doGenerate)) {\n return doGenerate[this.doGenerateCalls.length];\n } else {\n return doGenerate;\n }\n };\n this.doStream = async options => {\n this.doStreamCalls.push(options);\n\n if (typeof doStream === 'function') {\n return doStream(options);\n } else if (Array.isArray(doStream)) {\n return doStream[this.doStreamCalls.length];\n } else {\n return doStream;\n }\n };\n this._supportedUrls =\n typeof supportedUrls === 'function'\n ? supportedUrls\n : async () => supportedUrls;\n }\n\n get supportedUrls() {\n return this._supportedUrls();\n }\n}\n","import {\n EmbeddingModelV3,\n ImageModelV2,\n LanguageModelV2,\n NoSuchModelError,\n ProviderV2,\n SpeechModelV2,\n TranscriptionModelV2,\n} from '@ai-sdk/provider';\n\nexport class MockProviderV2 implements ProviderV2 {\n languageModel: ProviderV2['languageModel'];\n textEmbeddingModel: ProviderV2['textEmbeddingModel'];\n imageModel: ProviderV2['imageModel'];\n transcriptionModel: ProviderV2['transcriptionModel'];\n speechModel: ProviderV2['speechModel'];\n\n constructor({\n languageModels,\n embeddingModels,\n imageModels,\n transcriptionModels,\n speechModels,\n }: {\n languageModels?: Record<string, LanguageModelV2>;\n embeddingModels?: Record<string, EmbeddingModelV3<string>>;\n imageModels?: Record<string, ImageModelV2>;\n transcriptionModels?: Record<string, TranscriptionModelV2>;\n speechModels?: Record<string, SpeechModelV2>;\n } = {}) {\n this.languageModel = (modelId: string) => {\n if (!languageModels?.[modelId]) {\n throw new NoSuchModelError({ modelId, modelType: 'languageModel' });\n }\n return languageModels[modelId];\n };\n this.textEmbeddingModel = (modelId: string) => {\n if (!embeddingModels?.[modelId]) {\n throw new NoSuchModelError({\n modelId,\n modelType: 'textEmbeddingModel',\n });\n }\n return embeddingModels[modelId];\n };\n this.imageModel = (modelId: string) => {\n if (!imageModels?.[modelId]) {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n }\n return imageModels[modelId];\n };\n this.transcriptionModel = (modelId: string) => {\n if (!transcriptionModels?.[modelId]) {\n throw new NoSuchModelError({\n modelId,\n modelType: 'transcriptionModel',\n });\n }\n return transcriptionModels[modelId];\n };\n this.speechModel = (modelId: string) => {\n if (!speechModels?.[modelId]) {\n throw new NoSuchModelError({ modelId, modelType: 'speechModel' });\n }\n return speechModels[modelId];\n };\n }\n}\n","import { SpeechModelV2 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockSpeechModelV2 implements SpeechModelV2 {\n readonly specificationVersion = 'v2';\n readonly provider: SpeechModelV2['provider'];\n readonly modelId: SpeechModelV2['modelId'];\n\n doGenerate: SpeechModelV2['doGenerate'];\n\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n doGenerate = notImplemented,\n }: {\n provider?: SpeechModelV2['provider'];\n modelId?: SpeechModelV2['modelId'];\n doGenerate?: SpeechModelV2['doGenerate'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.doGenerate = doGenerate;\n }\n}\n","import { TranscriptionModelV2 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockTranscriptionModelV2 implements TranscriptionModelV2 {\n readonly specificationVersion = 'v2';\n readonly provider: TranscriptionModelV2['provider'];\n readonly modelId: TranscriptionModelV2['modelId'];\n\n doGenerate: TranscriptionModelV2['doGenerate'];\n\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n doGenerate = notImplemented,\n }: {\n provider?: TranscriptionModelV2['provider'];\n modelId?: TranscriptionModelV2['modelId'];\n doGenerate?: TranscriptionModelV2['doGenerate'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.doGenerate = doGenerate;\n }\n}\n","export function mockValues<T>(...values: T[]): () => T {\n let counter = 0;\n return () => values[counter++] ?? values[values.length - 1];\n}\n","import { delay as delayFunction } from '@ai-sdk/provider-utils';\n\n/**\n * Creates a ReadableStream that emits the provided values with an optional delay between each value.\n *\n * @param options - The configuration options\n * @param options.chunks - Array of values to be emitted by the stream\n * @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.\n * @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.\n * @returns A ReadableStream that emits the provided values\n */\nexport function simulateReadableStream<T>({\n chunks,\n initialDelayInMs = 0,\n chunkDelayInMs = 0,\n _internal,\n}: {\n chunks: T[];\n initialDelayInMs?: number | null;\n chunkDelayInMs?: number | null;\n _internal?: {\n delay?: (ms: number | null) => Promise<void>;\n };\n}): ReadableStream<T> {\n const delay = _internal?.delay ?? delayFunction;\n\n let index = 0;\n\n return new ReadableStream({\n async pull(controller) {\n if (index < chunks.length) {\n await delay(index === 0 ? initialDelayInMs : chunkDelayInMs);\n controller.enqueue(chunks[index++]);\n } else {\n controller.close();\n }\n },\n });\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACLA,SAAS,iBAAwB;AACtC,QAAM,IAAI,MAAM,iBAAiB;AACnC;;;ACCO,IAAM,uBAAN,MAAqE;AAAA,EAU1E,YAAY;AAAA,IACV,WAAW;AAAA,IACX,UAAU;AAAA,IACV,uBAAuB;AAAA,IACvB,wBAAwB;AAAA,IACxB,UAAU;AAAA,EACZ,IAQI,CAAC,GAAG;AAvBR,SAAS,uBAAuB;AAwB9B,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,uBAAuB,wBAAwB;AACpD,SAAK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W;AAChB,SAAK,UAAU;AACf,SAAK,aAAa;AAAA,EACpB;AACF;;;ACpBO,IAAM,2BAAN,MAA+D;AAAA,EAOpE,YAAY;AAAA,IACV,WAAW;AAAA,IACX,UAAU;AAAA,IACV,aAAa;AAAA,EACf,IAII,CAAC,GAAG;AAdR,SAAS,uBAAuB;AAe9B,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,aAAa;AAAA,EACpB;AACF;;;ACvBO,SAAS,cAAiB,QAAsB;AACrD,MAAI,UAAU;AACd,SAAO,MAAM,OAAO,SAAS,KAAK,OAAO,OAAO,SAAS,CAAC;AAC5D;;;ACHA,SAAS,SAAS,qBAAqB;AAWhC,SAAS,uBAA0B;AAAA,EACxC;AAAA,EACA,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB;AACF,GAOsB;AACpB,QAAM,QAAQ,WAAW,SAAS;AAElC,MAAI,QAAQ;AAEZ,SAAO,IAAI,eAAe;AAAA,IACxB,MAAM,KAAK,YAAY;AACrB,UAAI,QAAQ,OAAO,QAAQ;AACzB,cAAM,MAAM,UAAU,IAAI,mBAAmB,cAAc;AAC3D,mBAAW,QAAQ,OAAO,OAAO,CAAC;AAAA,MACpC,OAAO;AACL,mBAAW,MAAM;AAAA,MACnB;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;ATnBO,IAAMA,0BAAyB;","names":["simulateReadableStream"]}
|
|
1
|
+
{"version":3,"sources":["../../test/index.ts","../../src/test/not-implemented.ts","../../src/test/mock-embedding-model-v3.ts","../../src/test/mock-image-model-v3.ts","../../src/test/mock-language-model-v3.ts","../../src/test/mock-provider-v3.ts","../../src/test/mock-speech-model-v3.ts","../../src/test/mock-transcription-model-v3.ts","../../src/test/mock-reranking-model-v3.ts","../../src/test/mock-values.ts","../../src/util/simulate-readable-stream.ts"],"sourcesContent":["export {\n convertArrayToAsyncIterable,\n convertArrayToReadableStream,\n convertReadableStreamToArray,\n mockId,\n} from '@ai-sdk/provider-utils/test';\nexport { MockEmbeddingModelV3 } from '../src/test/mock-embedding-model-v3';\nexport { MockImageModelV3 } from '../src/test/mock-image-model-v3';\nexport { MockLanguageModelV3 } from '../src/test/mock-language-model-v3';\nexport { MockProviderV3 } from '../src/test/mock-provider-v3';\nexport { MockSpeechModelV3 } from '../src/test/mock-speech-model-v3';\nexport { MockTranscriptionModelV3 } from '../src/test/mock-transcription-model-v3';\nexport { MockRerankingModelV3 } from '../src/test/mock-reranking-model-v3';\nexport { mockValues } from '../src/test/mock-values';\n\nimport { simulateReadableStream as originalSimulateReadableStream } from '../src/util/simulate-readable-stream';\n\n/**\n * @deprecated Use `simulateReadableStream` from `ai` instead.\n */\nexport const simulateReadableStream = originalSimulateReadableStream;\n","export function notImplemented(): never {\n throw new Error('Not implemented');\n}\n","import { EmbeddingModelV3 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockEmbeddingModelV3<VALUE> implements EmbeddingModelV3<VALUE> {\n readonly specificationVersion = 'v3';\n\n readonly provider: EmbeddingModelV3<VALUE>['provider'];\n readonly modelId: EmbeddingModelV3<VALUE>['modelId'];\n readonly maxEmbeddingsPerCall: EmbeddingModelV3<VALUE>['maxEmbeddingsPerCall'];\n readonly supportsParallelCalls: EmbeddingModelV3<VALUE>['supportsParallelCalls'];\n\n doEmbed: EmbeddingModelV3<VALUE>['doEmbed'];\n\n doEmbedCalls: Parameters<EmbeddingModelV3<VALUE>['doEmbed']>[0][] = [];\n\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n maxEmbeddingsPerCall = 1,\n supportsParallelCalls = false,\n doEmbed = notImplemented,\n }: {\n provider?: EmbeddingModelV3<VALUE>['provider'];\n modelId?: EmbeddingModelV3<VALUE>['modelId'];\n maxEmbeddingsPerCall?:\n | EmbeddingModelV3<VALUE>['maxEmbeddingsPerCall']\n | null;\n supportsParallelCalls?: EmbeddingModelV3<VALUE>['supportsParallelCalls'];\n doEmbed?:\n | EmbeddingModelV3<VALUE>['doEmbed']\n | Awaited<ReturnType<EmbeddingModelV3<VALUE>['doEmbed']>>\n | Awaited<ReturnType<EmbeddingModelV3<VALUE>['doEmbed']>>[];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.maxEmbeddingsPerCall = maxEmbeddingsPerCall ?? undefined;\n this.supportsParallelCalls = supportsParallelCalls;\n this.doEmbed = async options => {\n this.doEmbedCalls.push(options);\n\n if (typeof doEmbed === 'function') {\n return doEmbed(options);\n } else if (Array.isArray(doEmbed)) {\n return doEmbed[this.doEmbedCalls.length];\n } else {\n return doEmbed;\n }\n };\n }\n}\n","import { ImageModelV3 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockImageModelV3 implements ImageModelV3 {\n readonly specificationVersion = 'v3';\n readonly provider: ImageModelV3['provider'];\n readonly modelId: ImageModelV3['modelId'];\n readonly maxImagesPerCall: ImageModelV3['maxImagesPerCall'];\n\n doGenerate: ImageModelV3['doGenerate'];\n\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n maxImagesPerCall = 1,\n doGenerate = notImplemented,\n }: {\n provider?: ImageModelV3['provider'];\n modelId?: ImageModelV3['modelId'];\n maxImagesPerCall?: ImageModelV3['maxImagesPerCall'];\n doGenerate?: ImageModelV3['doGenerate'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.maxImagesPerCall = maxImagesPerCall;\n this.doGenerate = doGenerate;\n }\n}\n","import { LanguageModelV3 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockLanguageModelV3 implements LanguageModelV3 {\n readonly specificationVersion = 'v3';\n\n private _supportedUrls: () => LanguageModelV3['supportedUrls'];\n\n readonly provider: LanguageModelV3['provider'];\n readonly modelId: LanguageModelV3['modelId'];\n\n doGenerate: LanguageModelV3['doGenerate'];\n doStream: LanguageModelV3['doStream'];\n\n doGenerateCalls: Parameters<LanguageModelV3['doGenerate']>[0][] = [];\n doStreamCalls: Parameters<LanguageModelV3['doStream']>[0][] = [];\n\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n supportedUrls = {},\n doGenerate = notImplemented,\n doStream = notImplemented,\n }: {\n provider?: LanguageModelV3['provider'];\n modelId?: LanguageModelV3['modelId'];\n supportedUrls?:\n | LanguageModelV3['supportedUrls']\n | (() => LanguageModelV3['supportedUrls']);\n doGenerate?:\n | LanguageModelV3['doGenerate']\n | Awaited<ReturnType<LanguageModelV3['doGenerate']>>\n | Awaited<ReturnType<LanguageModelV3['doGenerate']>>[];\n doStream?:\n | LanguageModelV3['doStream']\n | Awaited<ReturnType<LanguageModelV3['doStream']>>\n | Awaited<ReturnType<LanguageModelV3['doStream']>>[];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.doGenerate = async options => {\n this.doGenerateCalls.push(options);\n\n if (typeof doGenerate === 'function') {\n return doGenerate(options);\n } else if (Array.isArray(doGenerate)) {\n return doGenerate[this.doGenerateCalls.length];\n } else {\n return doGenerate;\n }\n };\n this.doStream = async options => {\n this.doStreamCalls.push(options);\n\n if (typeof doStream === 'function') {\n return doStream(options);\n } else if (Array.isArray(doStream)) {\n return doStream[this.doStreamCalls.length];\n } else {\n return doStream;\n }\n };\n this._supportedUrls =\n typeof supportedUrls === 'function'\n ? supportedUrls\n : async () => supportedUrls;\n }\n\n get supportedUrls() {\n return this._supportedUrls();\n }\n}\n","import {\n EmbeddingModelV3,\n ImageModelV3,\n LanguageModelV3,\n NoSuchModelError,\n ProviderV3,\n SpeechModelV3,\n TranscriptionModelV3,\n RerankingModelV3,\n} from '@ai-sdk/provider';\n\nexport class MockProviderV3 implements ProviderV3 {\n readonly specificationVersion = 'v3' as const;\n\n languageModel: ProviderV3['languageModel'];\n textEmbeddingModel: ProviderV3['textEmbeddingModel'];\n imageModel: ProviderV3['imageModel'];\n transcriptionModel: ProviderV3['transcriptionModel'];\n speechModel: ProviderV3['speechModel'];\n rerankingModel: ProviderV3['rerankingModel'];\n\n constructor({\n languageModels,\n embeddingModels,\n imageModels,\n transcriptionModels,\n speechModels,\n rerankingModels,\n }: {\n languageModels?: Record<string, LanguageModelV3>;\n embeddingModels?: Record<string, EmbeddingModelV3<string>>;\n imageModels?: Record<string, ImageModelV3>;\n transcriptionModels?: Record<string, TranscriptionModelV3>;\n speechModels?: Record<string, SpeechModelV3>;\n rerankingModels?: Record<string, RerankingModelV3>;\n } = {}) {\n this.languageModel = (modelId: string) => {\n if (!languageModels?.[modelId]) {\n throw new NoSuchModelError({ modelId, modelType: 'languageModel' });\n }\n return languageModels[modelId];\n };\n this.textEmbeddingModel = (modelId: string) => {\n if (!embeddingModels?.[modelId]) {\n throw new NoSuchModelError({\n modelId,\n modelType: 'textEmbeddingModel',\n });\n }\n return embeddingModels[modelId];\n };\n this.imageModel = (modelId: string) => {\n if (!imageModels?.[modelId]) {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n }\n return imageModels[modelId];\n };\n this.transcriptionModel = (modelId: string) => {\n if (!transcriptionModels?.[modelId]) {\n throw new NoSuchModelError({\n modelId,\n modelType: 'transcriptionModel',\n });\n }\n return transcriptionModels[modelId];\n };\n this.speechModel = (modelId: string): SpeechModelV3 => {\n if (!speechModels?.[modelId]) {\n throw new NoSuchModelError({ modelId, modelType: 'speechModel' });\n }\n return speechModels[modelId];\n };\n this.rerankingModel = (modelId: string) => {\n if (!rerankingModels?.[modelId]) {\n throw new NoSuchModelError({ modelId, modelType: 'rerankingModel' });\n }\n return rerankingModels[modelId];\n };\n }\n}\n","import { SpeechModelV3 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockSpeechModelV3 implements SpeechModelV3 {\n readonly specificationVersion = 'v3';\n readonly provider: SpeechModelV3['provider'];\n readonly modelId: SpeechModelV3['modelId'];\n\n doGenerate: SpeechModelV3['doGenerate'];\n\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n doGenerate = notImplemented,\n }: {\n provider?: SpeechModelV3['provider'];\n modelId?: SpeechModelV3['modelId'];\n doGenerate?: SpeechModelV3['doGenerate'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.doGenerate = doGenerate;\n }\n}\n","import { TranscriptionModelV3 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockTranscriptionModelV3 implements TranscriptionModelV3 {\n readonly specificationVersion = 'v3';\n readonly provider: TranscriptionModelV3['provider'];\n readonly modelId: TranscriptionModelV3['modelId'];\n\n doGenerate: TranscriptionModelV3['doGenerate'];\n\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n doGenerate = notImplemented,\n }: {\n provider?: TranscriptionModelV3['provider'];\n modelId?: TranscriptionModelV3['modelId'];\n doGenerate?: TranscriptionModelV3['doGenerate'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.doGenerate = doGenerate;\n }\n}\n","import { RerankingModelV3 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockRerankingModelV3 implements RerankingModelV3 {\n readonly specificationVersion = 'v3';\n\n readonly provider: RerankingModelV3['provider'];\n readonly modelId: RerankingModelV3['modelId'];\n\n doRerank: RerankingModelV3['doRerank'];\n\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n doRerank = notImplemented,\n }: {\n provider?: RerankingModelV3['provider'];\n modelId?: RerankingModelV3['modelId'];\n doRerank?: RerankingModelV3['doRerank'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.doRerank = doRerank;\n }\n}\n","export function mockValues<T>(...values: T[]): () => T {\n let counter = 0;\n return () => values[counter++] ?? values[values.length - 1];\n}\n","import { delay as delayFunction } from '@ai-sdk/provider-utils';\n\n/**\n * Creates a ReadableStream that emits the provided values with an optional delay between each value.\n *\n * @param options - The configuration options\n * @param options.chunks - Array of values to be emitted by the stream\n * @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.\n * @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.\n * @returns A ReadableStream that emits the provided values\n */\nexport function simulateReadableStream<T>({\n chunks,\n initialDelayInMs = 0,\n chunkDelayInMs = 0,\n _internal,\n}: {\n chunks: T[];\n initialDelayInMs?: number | null;\n chunkDelayInMs?: number | null;\n _internal?: {\n delay?: (ms: number | null) => Promise<void>;\n };\n}): ReadableStream<T> {\n const delay = _internal?.delay ?? delayFunction;\n\n let index = 0;\n\n return new ReadableStream({\n async pull(controller) {\n if (index < chunks.length) {\n await delay(index === 0 ? initialDelayInMs : chunkDelayInMs);\n controller.enqueue(chunks[index++]);\n } else {\n controller.close();\n }\n },\n });\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACLA,SAAS,iBAAwB;AACtC,QAAM,IAAI,MAAM,iBAAiB;AACnC;;;ACCO,IAAM,uBAAN,MAAqE;AAAA,EAY1E,YAAY;AAAA,IACV,WAAW;AAAA,IACX,UAAU;AAAA,IACV,uBAAuB;AAAA,IACvB,wBAAwB;AAAA,IACxB,UAAU;AAAA,EACZ,IAWI,CAAC,GAAG;AA5BR,SAAS,uBAAuB;AAShC,wBAAoE,CAAC;AAoBnE,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,uBAAuB,wBAAwB;AACpD,SAAK,wBAAwB;AAC7B,SAAK,UAAU,OAAM,YAAW;AAC9B,WAAK,aAAa,KAAK,OAAO;AAE9B,UAAI,OAAO,YAAY,YAAY;AACjC,eAAO,QAAQ,OAAO;AAAA,MACxB,WAAW,MAAM,QAAQ,OAAO,GAAG;AACjC,eAAO,QAAQ,KAAK,aAAa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,MAAM;AAAA,MACnB;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;AVlBO,IAAMA,0BAAyB;","names":["simulateReadableStream"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-beta.100",
|
|
4
4
|
"description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dist/**/*",
|
|
12
12
|
"CHANGELOG.md",
|
|
13
13
|
"internal.d.ts",
|
|
14
|
-
"
|
|
14
|
+
"README.md",
|
|
15
15
|
"test.d.ts"
|
|
16
16
|
],
|
|
17
17
|
"exports": {
|
|
@@ -32,34 +32,30 @@
|
|
|
32
32
|
"import": "./dist/test/index.mjs",
|
|
33
33
|
"module": "./dist/test/index.mjs",
|
|
34
34
|
"require": "./dist/test/index.js"
|
|
35
|
-
},
|
|
36
|
-
"./mcp-stdio": {
|
|
37
|
-
"types": "./dist/mcp-stdio/index.d.ts",
|
|
38
|
-
"import": "./dist/mcp-stdio/index.mjs",
|
|
39
|
-
"module": "./dist/mcp-stdio/index.mjs",
|
|
40
|
-
"require": "./dist/mcp-stdio/index.js"
|
|
41
35
|
}
|
|
42
36
|
},
|
|
43
37
|
"dependencies": {
|
|
44
38
|
"@opentelemetry/api": "1.9.0",
|
|
45
|
-
"@ai-sdk/
|
|
46
|
-
"@ai-sdk/
|
|
47
|
-
"@ai-sdk/provider": "
|
|
48
|
-
"@ai-sdk/provider-utils": "3.1.0-beta.2"
|
|
39
|
+
"@ai-sdk/gateway": "2.0.0-beta.52",
|
|
40
|
+
"@ai-sdk/provider": "3.0.0-beta.16",
|
|
41
|
+
"@ai-sdk/provider-utils": "4.0.0-beta.33"
|
|
49
42
|
},
|
|
50
43
|
"devDependencies": {
|
|
51
44
|
"@edge-runtime/vm": "^5.0.0",
|
|
52
45
|
"@types/json-schema": "7.0.15",
|
|
53
46
|
"@types/node": "20.17.24",
|
|
47
|
+
"esbuild": "^0.24.2",
|
|
54
48
|
"eslint": "8.57.1",
|
|
55
49
|
"tsup": "^7.2.0",
|
|
50
|
+
"tsx": "^4.19.2",
|
|
56
51
|
"typescript": "5.8.3",
|
|
57
52
|
"zod": "3.25.76",
|
|
53
|
+
"@ai-sdk/test-server": "1.0.0-beta.1",
|
|
58
54
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
59
55
|
"eslint-config-vercel-ai": "0.0.0"
|
|
60
56
|
},
|
|
61
57
|
"peerDependencies": {
|
|
62
|
-
"zod": "^3.25.76 || ^4"
|
|
58
|
+
"zod": "^3.25.76 || ^4.1.8"
|
|
63
59
|
},
|
|
64
60
|
"engines": {
|
|
65
61
|
"node": ">=18"
|
|
@@ -96,7 +92,7 @@
|
|
|
96
92
|
"scripts": {
|
|
97
93
|
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
98
94
|
"build:watch": "pnpm clean && tsup --watch --tsconfig tsconfig.build.json",
|
|
99
|
-
"clean": "
|
|
95
|
+
"clean": "del-cli dist *.tsbuildinfo",
|
|
100
96
|
"lint": "eslint \"./**/*.ts*\"",
|
|
101
97
|
"type-check": "tsc --build",
|
|
102
98
|
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
|
@@ -104,6 +100,7 @@
|
|
|
104
100
|
"test:update": "pnpm test:node -u",
|
|
105
101
|
"test:watch": "vitest --config vitest.node.config.js",
|
|
106
102
|
"test:edge": "vitest --config vitest.edge.config.js --run",
|
|
107
|
-
"test:node": "vitest --config vitest.node.config.js --run"
|
|
103
|
+
"test:node": "vitest --config vitest.node.config.js --run",
|
|
104
|
+
"check-bundle-size": "tsx scripts/check-bundle-size.ts"
|
|
108
105
|
}
|
|
109
106
|
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { IOType } from 'node:child_process';
|
|
2
|
-
import { Stream } from 'node:stream';
|
|
3
|
-
import { z } from 'zod/v4';
|
|
4
|
-
|
|
5
|
-
declare const JSONRPCMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
6
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
7
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
8
|
-
method: z.ZodString;
|
|
9
|
-
params: z.ZodOptional<z.ZodObject<{
|
|
10
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
11
|
-
}, z.core.$loose>>;
|
|
12
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
13
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
14
|
-
method: z.ZodString;
|
|
15
|
-
params: z.ZodOptional<z.ZodObject<{
|
|
16
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
17
|
-
}, z.core.$loose>>;
|
|
18
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
19
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
20
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
21
|
-
result: z.ZodObject<{
|
|
22
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
23
|
-
}, z.core.$loose>;
|
|
24
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
25
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
26
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
27
|
-
error: z.ZodObject<{
|
|
28
|
-
code: z.ZodNumber;
|
|
29
|
-
message: z.ZodString;
|
|
30
|
-
data: z.ZodOptional<z.ZodUnknown>;
|
|
31
|
-
}, z.core.$strip>;
|
|
32
|
-
}, z.core.$strict>]>;
|
|
33
|
-
type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Transport interface for MCP (Model Context Protocol) communication.
|
|
37
|
-
* Maps to the `Transport` interface in the MCP spec.
|
|
38
|
-
*/
|
|
39
|
-
interface MCPTransport {
|
|
40
|
-
/**
|
|
41
|
-
* Initialize and start the transport
|
|
42
|
-
*/
|
|
43
|
-
start(): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Send a JSON-RPC message through the transport
|
|
46
|
-
* @param message The JSON-RPC message to send
|
|
47
|
-
*/
|
|
48
|
-
send(message: JSONRPCMessage): Promise<void>;
|
|
49
|
-
/**
|
|
50
|
-
* Clean up and close the transport
|
|
51
|
-
*/
|
|
52
|
-
close(): Promise<void>;
|
|
53
|
-
/**
|
|
54
|
-
* Event handler for transport closure
|
|
55
|
-
*/
|
|
56
|
-
onclose?: () => void;
|
|
57
|
-
/**
|
|
58
|
-
* Event handler for transport errors
|
|
59
|
-
*/
|
|
60
|
-
onerror?: (error: Error) => void;
|
|
61
|
-
/**
|
|
62
|
-
* Event handler for received messages
|
|
63
|
-
*/
|
|
64
|
-
onmessage?: (message: JSONRPCMessage) => void;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
interface StdioConfig {
|
|
68
|
-
command: string;
|
|
69
|
-
args?: string[];
|
|
70
|
-
env?: Record<string, string>;
|
|
71
|
-
stderr?: IOType | Stream | number;
|
|
72
|
-
cwd?: string;
|
|
73
|
-
}
|
|
74
|
-
declare class StdioMCPTransport implements MCPTransport {
|
|
75
|
-
private process?;
|
|
76
|
-
private abortController;
|
|
77
|
-
private readBuffer;
|
|
78
|
-
private serverParams;
|
|
79
|
-
onclose?: () => void;
|
|
80
|
-
onerror?: (error: unknown) => void;
|
|
81
|
-
onmessage?: (message: JSONRPCMessage) => void;
|
|
82
|
-
constructor(server: StdioConfig);
|
|
83
|
-
start(): Promise<void>;
|
|
84
|
-
private processReadBuffer;
|
|
85
|
-
close(): Promise<void>;
|
|
86
|
-
send(message: JSONRPCMessage): Promise<void>;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export { StdioMCPTransport as Experimental_StdioMCPTransport, StdioConfig };
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { IOType } from 'node:child_process';
|
|
2
|
-
import { Stream } from 'node:stream';
|
|
3
|
-
import { z } from 'zod/v4';
|
|
4
|
-
|
|
5
|
-
declare const JSONRPCMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
6
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
7
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
8
|
-
method: z.ZodString;
|
|
9
|
-
params: z.ZodOptional<z.ZodObject<{
|
|
10
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
11
|
-
}, z.core.$loose>>;
|
|
12
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
13
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
14
|
-
method: z.ZodString;
|
|
15
|
-
params: z.ZodOptional<z.ZodObject<{
|
|
16
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
17
|
-
}, z.core.$loose>>;
|
|
18
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
19
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
20
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
21
|
-
result: z.ZodObject<{
|
|
22
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
23
|
-
}, z.core.$loose>;
|
|
24
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
25
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
|
26
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
27
|
-
error: z.ZodObject<{
|
|
28
|
-
code: z.ZodNumber;
|
|
29
|
-
message: z.ZodString;
|
|
30
|
-
data: z.ZodOptional<z.ZodUnknown>;
|
|
31
|
-
}, z.core.$strip>;
|
|
32
|
-
}, z.core.$strict>]>;
|
|
33
|
-
type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Transport interface for MCP (Model Context Protocol) communication.
|
|
37
|
-
* Maps to the `Transport` interface in the MCP spec.
|
|
38
|
-
*/
|
|
39
|
-
interface MCPTransport {
|
|
40
|
-
/**
|
|
41
|
-
* Initialize and start the transport
|
|
42
|
-
*/
|
|
43
|
-
start(): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Send a JSON-RPC message through the transport
|
|
46
|
-
* @param message The JSON-RPC message to send
|
|
47
|
-
*/
|
|
48
|
-
send(message: JSONRPCMessage): Promise<void>;
|
|
49
|
-
/**
|
|
50
|
-
* Clean up and close the transport
|
|
51
|
-
*/
|
|
52
|
-
close(): Promise<void>;
|
|
53
|
-
/**
|
|
54
|
-
* Event handler for transport closure
|
|
55
|
-
*/
|
|
56
|
-
onclose?: () => void;
|
|
57
|
-
/**
|
|
58
|
-
* Event handler for transport errors
|
|
59
|
-
*/
|
|
60
|
-
onerror?: (error: Error) => void;
|
|
61
|
-
/**
|
|
62
|
-
* Event handler for received messages
|
|
63
|
-
*/
|
|
64
|
-
onmessage?: (message: JSONRPCMessage) => void;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
interface StdioConfig {
|
|
68
|
-
command: string;
|
|
69
|
-
args?: string[];
|
|
70
|
-
env?: Record<string, string>;
|
|
71
|
-
stderr?: IOType | Stream | number;
|
|
72
|
-
cwd?: string;
|
|
73
|
-
}
|
|
74
|
-
declare class StdioMCPTransport implements MCPTransport {
|
|
75
|
-
private process?;
|
|
76
|
-
private abortController;
|
|
77
|
-
private readBuffer;
|
|
78
|
-
private serverParams;
|
|
79
|
-
onclose?: () => void;
|
|
80
|
-
onerror?: (error: unknown) => void;
|
|
81
|
-
onmessage?: (message: JSONRPCMessage) => void;
|
|
82
|
-
constructor(server: StdioConfig);
|
|
83
|
-
start(): Promise<void>;
|
|
84
|
-
private processReadBuffer;
|
|
85
|
-
close(): Promise<void>;
|
|
86
|
-
send(message: JSONRPCMessage): Promise<void>;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export { StdioMCPTransport as Experimental_StdioMCPTransport, StdioConfig };
|
package/dist/mcp-stdio/index.js
DELETED
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name2 in all)
|
|
8
|
-
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// mcp-stdio/index.ts
|
|
21
|
-
var mcp_stdio_exports = {};
|
|
22
|
-
__export(mcp_stdio_exports, {
|
|
23
|
-
Experimental_StdioMCPTransport: () => StdioMCPTransport
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(mcp_stdio_exports);
|
|
26
|
-
|
|
27
|
-
// src/tool/mcp/json-rpc-message.ts
|
|
28
|
-
var import_v42 = require("zod/v4");
|
|
29
|
-
|
|
30
|
-
// src/tool/mcp/types.ts
|
|
31
|
-
var import_v4 = require("zod/v4");
|
|
32
|
-
var ClientOrServerImplementationSchema = import_v4.z.looseObject({
|
|
33
|
-
name: import_v4.z.string(),
|
|
34
|
-
version: import_v4.z.string()
|
|
35
|
-
});
|
|
36
|
-
var BaseParamsSchema = import_v4.z.looseObject({
|
|
37
|
-
_meta: import_v4.z.optional(import_v4.z.object({}).loose())
|
|
38
|
-
});
|
|
39
|
-
var ResultSchema = BaseParamsSchema;
|
|
40
|
-
var RequestSchema = import_v4.z.object({
|
|
41
|
-
method: import_v4.z.string(),
|
|
42
|
-
params: import_v4.z.optional(BaseParamsSchema)
|
|
43
|
-
});
|
|
44
|
-
var ServerCapabilitiesSchema = import_v4.z.looseObject({
|
|
45
|
-
experimental: import_v4.z.optional(import_v4.z.object({}).loose()),
|
|
46
|
-
logging: import_v4.z.optional(import_v4.z.object({}).loose()),
|
|
47
|
-
prompts: import_v4.z.optional(
|
|
48
|
-
import_v4.z.looseObject({
|
|
49
|
-
listChanged: import_v4.z.optional(import_v4.z.boolean())
|
|
50
|
-
})
|
|
51
|
-
),
|
|
52
|
-
resources: import_v4.z.optional(
|
|
53
|
-
import_v4.z.looseObject({
|
|
54
|
-
subscribe: import_v4.z.optional(import_v4.z.boolean()),
|
|
55
|
-
listChanged: import_v4.z.optional(import_v4.z.boolean())
|
|
56
|
-
})
|
|
57
|
-
),
|
|
58
|
-
tools: import_v4.z.optional(
|
|
59
|
-
import_v4.z.looseObject({
|
|
60
|
-
listChanged: import_v4.z.optional(import_v4.z.boolean())
|
|
61
|
-
})
|
|
62
|
-
)
|
|
63
|
-
});
|
|
64
|
-
var InitializeResultSchema = ResultSchema.extend({
|
|
65
|
-
protocolVersion: import_v4.z.string(),
|
|
66
|
-
capabilities: ServerCapabilitiesSchema,
|
|
67
|
-
serverInfo: ClientOrServerImplementationSchema,
|
|
68
|
-
instructions: import_v4.z.optional(import_v4.z.string())
|
|
69
|
-
});
|
|
70
|
-
var PaginatedResultSchema = ResultSchema.extend({
|
|
71
|
-
nextCursor: import_v4.z.optional(import_v4.z.string())
|
|
72
|
-
});
|
|
73
|
-
var ToolSchema = import_v4.z.object({
|
|
74
|
-
name: import_v4.z.string(),
|
|
75
|
-
description: import_v4.z.optional(import_v4.z.string()),
|
|
76
|
-
inputSchema: import_v4.z.object({
|
|
77
|
-
type: import_v4.z.literal("object"),
|
|
78
|
-
properties: import_v4.z.optional(import_v4.z.object({}).loose())
|
|
79
|
-
}).loose()
|
|
80
|
-
}).loose();
|
|
81
|
-
var ListToolsResultSchema = PaginatedResultSchema.extend({
|
|
82
|
-
tools: import_v4.z.array(ToolSchema)
|
|
83
|
-
});
|
|
84
|
-
var TextContentSchema = import_v4.z.object({
|
|
85
|
-
type: import_v4.z.literal("text"),
|
|
86
|
-
text: import_v4.z.string()
|
|
87
|
-
}).loose();
|
|
88
|
-
var ImageContentSchema = import_v4.z.object({
|
|
89
|
-
type: import_v4.z.literal("image"),
|
|
90
|
-
data: import_v4.z.base64(),
|
|
91
|
-
mimeType: import_v4.z.string()
|
|
92
|
-
}).loose();
|
|
93
|
-
var ResourceContentsSchema = import_v4.z.object({
|
|
94
|
-
/**
|
|
95
|
-
* The URI of this resource.
|
|
96
|
-
*/
|
|
97
|
-
uri: import_v4.z.string(),
|
|
98
|
-
/**
|
|
99
|
-
* The MIME type of this resource, if known.
|
|
100
|
-
*/
|
|
101
|
-
mimeType: import_v4.z.optional(import_v4.z.string())
|
|
102
|
-
}).loose();
|
|
103
|
-
var TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
104
|
-
text: import_v4.z.string()
|
|
105
|
-
});
|
|
106
|
-
var BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
107
|
-
blob: import_v4.z.base64()
|
|
108
|
-
});
|
|
109
|
-
var EmbeddedResourceSchema = import_v4.z.object({
|
|
110
|
-
type: import_v4.z.literal("resource"),
|
|
111
|
-
resource: import_v4.z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
|
112
|
-
}).loose();
|
|
113
|
-
var CallToolResultSchema = ResultSchema.extend({
|
|
114
|
-
content: import_v4.z.array(
|
|
115
|
-
import_v4.z.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
|
|
116
|
-
),
|
|
117
|
-
isError: import_v4.z.boolean().default(false).optional()
|
|
118
|
-
}).or(
|
|
119
|
-
ResultSchema.extend({
|
|
120
|
-
toolResult: import_v4.z.unknown()
|
|
121
|
-
})
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
// src/tool/mcp/json-rpc-message.ts
|
|
125
|
-
var JSONRPC_VERSION = "2.0";
|
|
126
|
-
var JSONRPCRequestSchema = import_v42.z.object({
|
|
127
|
-
jsonrpc: import_v42.z.literal(JSONRPC_VERSION),
|
|
128
|
-
id: import_v42.z.union([import_v42.z.string(), import_v42.z.number().int()])
|
|
129
|
-
}).merge(RequestSchema).strict();
|
|
130
|
-
var JSONRPCResponseSchema = import_v42.z.object({
|
|
131
|
-
jsonrpc: import_v42.z.literal(JSONRPC_VERSION),
|
|
132
|
-
id: import_v42.z.union([import_v42.z.string(), import_v42.z.number().int()]),
|
|
133
|
-
result: ResultSchema
|
|
134
|
-
}).strict();
|
|
135
|
-
var JSONRPCErrorSchema = import_v42.z.object({
|
|
136
|
-
jsonrpc: import_v42.z.literal(JSONRPC_VERSION),
|
|
137
|
-
id: import_v42.z.union([import_v42.z.string(), import_v42.z.number().int()]),
|
|
138
|
-
error: import_v42.z.object({
|
|
139
|
-
code: import_v42.z.number().int(),
|
|
140
|
-
message: import_v42.z.string(),
|
|
141
|
-
data: import_v42.z.optional(import_v42.z.unknown())
|
|
142
|
-
})
|
|
143
|
-
}).strict();
|
|
144
|
-
var JSONRPCNotificationSchema = import_v42.z.object({
|
|
145
|
-
jsonrpc: import_v42.z.literal(JSONRPC_VERSION)
|
|
146
|
-
}).merge(
|
|
147
|
-
import_v42.z.object({
|
|
148
|
-
method: import_v42.z.string(),
|
|
149
|
-
params: import_v42.z.optional(BaseParamsSchema)
|
|
150
|
-
})
|
|
151
|
-
).strict();
|
|
152
|
-
var JSONRPCMessageSchema = import_v42.z.union([
|
|
153
|
-
JSONRPCRequestSchema,
|
|
154
|
-
JSONRPCNotificationSchema,
|
|
155
|
-
JSONRPCResponseSchema,
|
|
156
|
-
JSONRPCErrorSchema
|
|
157
|
-
]);
|
|
158
|
-
|
|
159
|
-
// src/error/mcp-client-error.ts
|
|
160
|
-
var import_provider = require("@ai-sdk/provider");
|
|
161
|
-
var name = "AI_MCPClientError";
|
|
162
|
-
var marker = `vercel.ai.error.${name}`;
|
|
163
|
-
var symbol = Symbol.for(marker);
|
|
164
|
-
var _a;
|
|
165
|
-
var MCPClientError = class extends import_provider.AISDKError {
|
|
166
|
-
constructor({
|
|
167
|
-
name: name2 = "MCPClientError",
|
|
168
|
-
message,
|
|
169
|
-
cause
|
|
170
|
-
}) {
|
|
171
|
-
super({ name: name2, message, cause });
|
|
172
|
-
this[_a] = true;
|
|
173
|
-
}
|
|
174
|
-
static isInstance(error) {
|
|
175
|
-
return import_provider.AISDKError.hasMarker(error, marker);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
_a = symbol;
|
|
179
|
-
|
|
180
|
-
// mcp-stdio/create-child-process.ts
|
|
181
|
-
var import_node_child_process = require("child_process");
|
|
182
|
-
|
|
183
|
-
// mcp-stdio/get-environment.ts
|
|
184
|
-
function getEnvironment(customEnv) {
|
|
185
|
-
const DEFAULT_INHERITED_ENV_VARS = globalThis.process.platform === "win32" ? [
|
|
186
|
-
"APPDATA",
|
|
187
|
-
"HOMEDRIVE",
|
|
188
|
-
"HOMEPATH",
|
|
189
|
-
"LOCALAPPDATA",
|
|
190
|
-
"PATH",
|
|
191
|
-
"PROCESSOR_ARCHITECTURE",
|
|
192
|
-
"SYSTEMDRIVE",
|
|
193
|
-
"SYSTEMROOT",
|
|
194
|
-
"TEMP",
|
|
195
|
-
"USERNAME",
|
|
196
|
-
"USERPROFILE"
|
|
197
|
-
] : ["HOME", "LOGNAME", "PATH", "SHELL", "TERM", "USER"];
|
|
198
|
-
const env = customEnv ? { ...customEnv } : {};
|
|
199
|
-
for (const key of DEFAULT_INHERITED_ENV_VARS) {
|
|
200
|
-
const value = globalThis.process.env[key];
|
|
201
|
-
if (value === void 0) {
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
if (value.startsWith("()")) {
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
env[key] = value;
|
|
208
|
-
}
|
|
209
|
-
return env;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// mcp-stdio/create-child-process.ts
|
|
213
|
-
function createChildProcess(config, signal) {
|
|
214
|
-
var _a2, _b;
|
|
215
|
-
return (0, import_node_child_process.spawn)(config.command, (_a2 = config.args) != null ? _a2 : [], {
|
|
216
|
-
env: getEnvironment(config.env),
|
|
217
|
-
stdio: ["pipe", "pipe", (_b = config.stderr) != null ? _b : "inherit"],
|
|
218
|
-
shell: false,
|
|
219
|
-
signal,
|
|
220
|
-
windowsHide: globalThis.process.platform === "win32" && isElectron(),
|
|
221
|
-
cwd: config.cwd
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
function isElectron() {
|
|
225
|
-
return "type" in globalThis.process;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// mcp-stdio/mcp-stdio-transport.ts
|
|
229
|
-
var StdioMCPTransport = class {
|
|
230
|
-
constructor(server) {
|
|
231
|
-
this.abortController = new AbortController();
|
|
232
|
-
this.readBuffer = new ReadBuffer();
|
|
233
|
-
this.serverParams = server;
|
|
234
|
-
}
|
|
235
|
-
async start() {
|
|
236
|
-
if (this.process) {
|
|
237
|
-
throw new MCPClientError({
|
|
238
|
-
message: "StdioMCPTransport already started."
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
return new Promise((resolve, reject) => {
|
|
242
|
-
var _a2, _b, _c, _d;
|
|
243
|
-
try {
|
|
244
|
-
const process = createChildProcess(
|
|
245
|
-
this.serverParams,
|
|
246
|
-
this.abortController.signal
|
|
247
|
-
);
|
|
248
|
-
this.process = process;
|
|
249
|
-
this.process.on("error", (error) => {
|
|
250
|
-
var _a3, _b2;
|
|
251
|
-
if (error.name === "AbortError") {
|
|
252
|
-
(_a3 = this.onclose) == null ? void 0 : _a3.call(this);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
reject(error);
|
|
256
|
-
(_b2 = this.onerror) == null ? void 0 : _b2.call(this, error);
|
|
257
|
-
});
|
|
258
|
-
this.process.on("spawn", () => {
|
|
259
|
-
resolve();
|
|
260
|
-
});
|
|
261
|
-
this.process.on("close", (_code) => {
|
|
262
|
-
var _a3;
|
|
263
|
-
this.process = void 0;
|
|
264
|
-
(_a3 = this.onclose) == null ? void 0 : _a3.call(this);
|
|
265
|
-
});
|
|
266
|
-
(_a2 = this.process.stdin) == null ? void 0 : _a2.on("error", (error) => {
|
|
267
|
-
var _a3;
|
|
268
|
-
(_a3 = this.onerror) == null ? void 0 : _a3.call(this, error);
|
|
269
|
-
});
|
|
270
|
-
(_b = this.process.stdout) == null ? void 0 : _b.on("data", (chunk) => {
|
|
271
|
-
this.readBuffer.append(chunk);
|
|
272
|
-
this.processReadBuffer();
|
|
273
|
-
});
|
|
274
|
-
(_c = this.process.stdout) == null ? void 0 : _c.on("error", (error) => {
|
|
275
|
-
var _a3;
|
|
276
|
-
(_a3 = this.onerror) == null ? void 0 : _a3.call(this, error);
|
|
277
|
-
});
|
|
278
|
-
} catch (error) {
|
|
279
|
-
reject(error);
|
|
280
|
-
(_d = this.onerror) == null ? void 0 : _d.call(this, error);
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
processReadBuffer() {
|
|
285
|
-
var _a2, _b;
|
|
286
|
-
while (true) {
|
|
287
|
-
try {
|
|
288
|
-
const message = this.readBuffer.readMessage();
|
|
289
|
-
if (message === null) {
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
(_a2 = this.onmessage) == null ? void 0 : _a2.call(this, message);
|
|
293
|
-
} catch (error) {
|
|
294
|
-
(_b = this.onerror) == null ? void 0 : _b.call(this, error);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
async close() {
|
|
299
|
-
this.abortController.abort();
|
|
300
|
-
this.process = void 0;
|
|
301
|
-
this.readBuffer.clear();
|
|
302
|
-
}
|
|
303
|
-
send(message) {
|
|
304
|
-
return new Promise((resolve) => {
|
|
305
|
-
var _a2;
|
|
306
|
-
if (!((_a2 = this.process) == null ? void 0 : _a2.stdin)) {
|
|
307
|
-
throw new MCPClientError({
|
|
308
|
-
message: "StdioClientTransport not connected"
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
const json = serializeMessage(message);
|
|
312
|
-
if (this.process.stdin.write(json)) {
|
|
313
|
-
resolve();
|
|
314
|
-
} else {
|
|
315
|
-
this.process.stdin.once("drain", resolve);
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
var ReadBuffer = class {
|
|
321
|
-
append(chunk) {
|
|
322
|
-
this.buffer = this.buffer ? Buffer.concat([this.buffer, chunk]) : chunk;
|
|
323
|
-
}
|
|
324
|
-
readMessage() {
|
|
325
|
-
if (!this.buffer)
|
|
326
|
-
return null;
|
|
327
|
-
const index = this.buffer.indexOf("\n");
|
|
328
|
-
if (index === -1) {
|
|
329
|
-
return null;
|
|
330
|
-
}
|
|
331
|
-
const line = this.buffer.toString("utf8", 0, index);
|
|
332
|
-
this.buffer = this.buffer.subarray(index + 1);
|
|
333
|
-
return deserializeMessage(line);
|
|
334
|
-
}
|
|
335
|
-
clear() {
|
|
336
|
-
this.buffer = void 0;
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
function serializeMessage(message) {
|
|
340
|
-
return JSON.stringify(message) + "\n";
|
|
341
|
-
}
|
|
342
|
-
function deserializeMessage(line) {
|
|
343
|
-
return JSONRPCMessageSchema.parse(JSON.parse(line));
|
|
344
|
-
}
|
|
345
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
346
|
-
0 && (module.exports = {
|
|
347
|
-
Experimental_StdioMCPTransport
|
|
348
|
-
});
|
|
349
|
-
//# sourceMappingURL=index.js.map
|