ai 4.1.5 → 4.1.7

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.
@@ -92,12 +92,8 @@ function mockValues(...values) {
92
92
  };
93
93
  }
94
94
 
95
- // util/delay.ts
96
- async function delay(delayInMs) {
97
- return delayInMs == null ? Promise.resolve() : new Promise((resolve) => setTimeout(resolve, delayInMs));
98
- }
99
-
100
95
  // core/util/simulate-readable-stream.ts
96
+ var import_provider_utils = require("@ai-sdk/provider-utils");
101
97
  function simulateReadableStream({
102
98
  chunks,
103
99
  initialDelayInMs = 0,
@@ -105,12 +101,12 @@ function simulateReadableStream({
105
101
  _internal
106
102
  }) {
107
103
  var _a;
108
- const delay2 = (_a = _internal == null ? void 0 : _internal.delay) != null ? _a : delay;
104
+ const delay = (_a = _internal == null ? void 0 : _internal.delay) != null ? _a : import_provider_utils.delay;
109
105
  let index = 0;
110
106
  return new ReadableStream({
111
107
  async pull(controller) {
112
108
  if (index < chunks.length) {
113
- await delay2(index === 0 ? initialDelayInMs : chunkDelayInMs);
109
+ await delay(index === 0 ? initialDelayInMs : chunkDelayInMs);
114
110
  controller.enqueue(chunks[index++]);
115
111
  } else {
116
112
  controller.close();
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../../core/test/not-implemented.ts","../../core/test/mock-embedding-model-v1.ts","../../core/test/mock-id.ts","../../core/test/mock-language-model-v1.ts","../../core/test/mock-values.ts","../../util/delay.ts","../../core/util/simulate-readable-stream.ts"],"sourcesContent":["export { convertArrayToReadableStream } from '@ai-sdk/provider-utils/test';\nexport { MockEmbeddingModelV1 } from '../core/test/mock-embedding-model-v1';\nexport { mockId } from '../core/test/mock-id';\nexport { MockLanguageModelV1 } from '../core/test/mock-language-model-v1';\nexport { mockValues } from '../core/test/mock-values';\n\nimport { simulateReadableStream as originalSimulateReadableStream } from '../core/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 { EmbeddingModelV1 } from '@ai-sdk/provider';\nimport { Embedding } from '../types';\nimport { EmbeddingModelUsage } from '../types/usage';\nimport { notImplemented } from './not-implemented';\n\nexport class MockEmbeddingModelV1<VALUE> implements EmbeddingModelV1<VALUE> {\n readonly specificationVersion = 'v1';\n\n readonly provider: EmbeddingModelV1<VALUE>['provider'];\n readonly modelId: EmbeddingModelV1<VALUE>['modelId'];\n readonly maxEmbeddingsPerCall: EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall'];\n readonly supportsParallelCalls: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n\n doEmbed: EmbeddingModelV1<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?: EmbeddingModelV1<VALUE>['provider'];\n modelId?: EmbeddingModelV1<VALUE>['modelId'];\n maxEmbeddingsPerCall?:\n | EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall']\n | null;\n supportsParallelCalls?: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n doEmbed?: EmbeddingModelV1<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\nexport function mockEmbed<VALUE>(\n expectedValues: Array<VALUE>,\n embeddings: Array<Embedding>,\n usage?: EmbeddingModelUsage,\n): EmbeddingModelV1<VALUE>['doEmbed'] {\n return async ({ values }) => {\n assert.deepStrictEqual(expectedValues, values);\n return { embeddings, usage };\n };\n}\n","export function mockId({\n prefix = 'id',\n}: {\n prefix?: string;\n} = {}): () => string {\n let counter = 0;\n return () => `${prefix}-${counter++}`;\n}\n","import { LanguageModelV1 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockLanguageModelV1 implements LanguageModelV1 {\n readonly specificationVersion = 'v1';\n\n readonly provider: LanguageModelV1['provider'];\n readonly modelId: LanguageModelV1['modelId'];\n\n supportsUrl: LanguageModelV1['supportsUrl'];\n doGenerate: LanguageModelV1['doGenerate'];\n doStream: LanguageModelV1['doStream'];\n\n readonly defaultObjectGenerationMode: LanguageModelV1['defaultObjectGenerationMode'];\n readonly supportsStructuredOutputs: LanguageModelV1['supportsStructuredOutputs'];\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n supportsUrl = undefined,\n doGenerate = notImplemented,\n doStream = notImplemented,\n defaultObjectGenerationMode = undefined,\n supportsStructuredOutputs = undefined,\n }: {\n provider?: LanguageModelV1['provider'];\n modelId?: LanguageModelV1['modelId'];\n supportsUrl?: LanguageModelV1['supportsUrl'];\n doGenerate?: LanguageModelV1['doGenerate'];\n doStream?: LanguageModelV1['doStream'];\n defaultObjectGenerationMode?: LanguageModelV1['defaultObjectGenerationMode'];\n supportsStructuredOutputs?: LanguageModelV1['supportsStructuredOutputs'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.doGenerate = doGenerate;\n this.doStream = doStream;\n this.supportsUrl = supportsUrl;\n\n this.defaultObjectGenerationMode = defaultObjectGenerationMode;\n this.supportsStructuredOutputs = supportsStructuredOutputs;\n }\n}\n","export function mockValues<T>(...values: T[]): () => T {\n let counter = 0;\n return () => values[counter++] ?? values[values.length - 1];\n}\n","/**\n * Creates a Promise that resolves after a specified delay\n * @param delayInMs - The delay duration in milliseconds. If null or undefined, resolves immediately.\n * @returns A Promise that resolves after the specified delay\n */\nexport async function delay(delayInMs?: number | null): Promise<void> {\n return delayInMs == null\n ? Promise.resolve()\n : new Promise(resolve => setTimeout(resolve, delayInMs));\n}\n","import { delay as delayFunction } from '../../util/delay';\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAAAA;AAAA;AAAA;AAAA,kBAA6C;;;ACAtC,SAAS,iBAAwB;AACtC,QAAM,IAAI,MAAM,iBAAiB;AACnC;;;ACGO,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,sDAAwB;AACpD,SAAK,wBAAwB;AAC7B,SAAK,UAAU;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AyB;","names":["simulateReadableStream","delay","simulateReadableStream"]}
1
+ {"version":3,"sources":["../index.ts","../../core/test/not-implemented.ts","../../core/test/mock-embedding-model-v1.ts","../../core/test/mock-id.ts","../../core/test/mock-language-model-v1.ts","../../core/test/mock-values.ts","../../core/util/simulate-readable-stream.ts"],"sourcesContent":["export { convertArrayToReadableStream } from '@ai-sdk/provider-utils/test';\nexport { MockEmbeddingModelV1 } from '../core/test/mock-embedding-model-v1';\nexport { mockId } from '../core/test/mock-id';\nexport { MockLanguageModelV1 } from '../core/test/mock-language-model-v1';\nexport { mockValues } from '../core/test/mock-values';\n\nimport { simulateReadableStream as originalSimulateReadableStream } from '../core/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 { EmbeddingModelV1 } from '@ai-sdk/provider';\nimport { Embedding } from '../types';\nimport { EmbeddingModelUsage } from '../types/usage';\nimport { notImplemented } from './not-implemented';\n\nexport class MockEmbeddingModelV1<VALUE> implements EmbeddingModelV1<VALUE> {\n readonly specificationVersion = 'v1';\n\n readonly provider: EmbeddingModelV1<VALUE>['provider'];\n readonly modelId: EmbeddingModelV1<VALUE>['modelId'];\n readonly maxEmbeddingsPerCall: EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall'];\n readonly supportsParallelCalls: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n\n doEmbed: EmbeddingModelV1<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?: EmbeddingModelV1<VALUE>['provider'];\n modelId?: EmbeddingModelV1<VALUE>['modelId'];\n maxEmbeddingsPerCall?:\n | EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall']\n | null;\n supportsParallelCalls?: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n doEmbed?: EmbeddingModelV1<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\nexport function mockEmbed<VALUE>(\n expectedValues: Array<VALUE>,\n embeddings: Array<Embedding>,\n usage?: EmbeddingModelUsage,\n): EmbeddingModelV1<VALUE>['doEmbed'] {\n return async ({ values }) => {\n assert.deepStrictEqual(expectedValues, values);\n return { embeddings, usage };\n };\n}\n","export function mockId({\n prefix = 'id',\n}: {\n prefix?: string;\n} = {}): () => string {\n let counter = 0;\n return () => `${prefix}-${counter++}`;\n}\n","import { LanguageModelV1 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockLanguageModelV1 implements LanguageModelV1 {\n readonly specificationVersion = 'v1';\n\n readonly provider: LanguageModelV1['provider'];\n readonly modelId: LanguageModelV1['modelId'];\n\n supportsUrl: LanguageModelV1['supportsUrl'];\n doGenerate: LanguageModelV1['doGenerate'];\n doStream: LanguageModelV1['doStream'];\n\n readonly defaultObjectGenerationMode: LanguageModelV1['defaultObjectGenerationMode'];\n readonly supportsStructuredOutputs: LanguageModelV1['supportsStructuredOutputs'];\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n supportsUrl = undefined,\n doGenerate = notImplemented,\n doStream = notImplemented,\n defaultObjectGenerationMode = undefined,\n supportsStructuredOutputs = undefined,\n }: {\n provider?: LanguageModelV1['provider'];\n modelId?: LanguageModelV1['modelId'];\n supportsUrl?: LanguageModelV1['supportsUrl'];\n doGenerate?: LanguageModelV1['doGenerate'];\n doStream?: LanguageModelV1['doStream'];\n defaultObjectGenerationMode?: LanguageModelV1['defaultObjectGenerationMode'];\n supportsStructuredOutputs?: LanguageModelV1['supportsStructuredOutputs'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.doGenerate = doGenerate;\n this.doStream = doStream;\n this.supportsUrl = supportsUrl;\n\n this.defaultObjectGenerationMode = defaultObjectGenerationMode;\n this.supportsStructuredOutputs = supportsStructuredOutputs;\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAAAA;AAAA;AAAA;AAAA,kBAA6C;;;ACAtC,SAAS,iBAAwB;AACtC,QAAM,IAAI,MAAM,iBAAiB;AACnC;;;AC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AQ;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;;;AN3BO,IAAMC,0BAAyB;","names":["simulateReadableStream","delayFunction","simulateReadableStream"]}
@@ -63,12 +63,8 @@ function mockValues(...values) {
63
63
  };
64
64
  }
65
65
 
66
- // util/delay.ts
67
- async function delay(delayInMs) {
68
- return delayInMs == null ? Promise.resolve() : new Promise((resolve) => setTimeout(resolve, delayInMs));
69
- }
70
-
71
66
  // core/util/simulate-readable-stream.ts
67
+ import { delay as delayFunction } from "@ai-sdk/provider-utils";
72
68
  function simulateReadableStream({
73
69
  chunks,
74
70
  initialDelayInMs = 0,
@@ -76,12 +72,12 @@ function simulateReadableStream({
76
72
  _internal
77
73
  }) {
78
74
  var _a;
79
- const delay2 = (_a = _internal == null ? void 0 : _internal.delay) != null ? _a : delay;
75
+ const delay = (_a = _internal == null ? void 0 : _internal.delay) != null ? _a : delayFunction;
80
76
  let index = 0;
81
77
  return new ReadableStream({
82
78
  async pull(controller) {
83
79
  if (index < chunks.length) {
84
- await delay2(index === 0 ? initialDelayInMs : chunkDelayInMs);
80
+ await delay(index === 0 ? initialDelayInMs : chunkDelayInMs);
85
81
  controller.enqueue(chunks[index++]);
86
82
  } else {
87
83
  controller.close();
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../../core/test/not-implemented.ts","../../core/test/mock-embedding-model-v1.ts","../../core/test/mock-id.ts","../../core/test/mock-language-model-v1.ts","../../core/test/mock-values.ts","../../util/delay.ts","../../core/util/simulate-readable-stream.ts"],"sourcesContent":["export { convertArrayToReadableStream } from '@ai-sdk/provider-utils/test';\nexport { MockEmbeddingModelV1 } from '../core/test/mock-embedding-model-v1';\nexport { mockId } from '../core/test/mock-id';\nexport { MockLanguageModelV1 } from '../core/test/mock-language-model-v1';\nexport { mockValues } from '../core/test/mock-values';\n\nimport { simulateReadableStream as originalSimulateReadableStream } from '../core/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 { EmbeddingModelV1 } from '@ai-sdk/provider';\nimport { Embedding } from '../types';\nimport { EmbeddingModelUsage } from '../types/usage';\nimport { notImplemented } from './not-implemented';\n\nexport class MockEmbeddingModelV1<VALUE> implements EmbeddingModelV1<VALUE> {\n readonly specificationVersion = 'v1';\n\n readonly provider: EmbeddingModelV1<VALUE>['provider'];\n readonly modelId: EmbeddingModelV1<VALUE>['modelId'];\n readonly maxEmbeddingsPerCall: EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall'];\n readonly supportsParallelCalls: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n\n doEmbed: EmbeddingModelV1<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?: EmbeddingModelV1<VALUE>['provider'];\n modelId?: EmbeddingModelV1<VALUE>['modelId'];\n maxEmbeddingsPerCall?:\n | EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall']\n | null;\n supportsParallelCalls?: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n doEmbed?: EmbeddingModelV1<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\nexport function mockEmbed<VALUE>(\n expectedValues: Array<VALUE>,\n embeddings: Array<Embedding>,\n usage?: EmbeddingModelUsage,\n): EmbeddingModelV1<VALUE>['doEmbed'] {\n return async ({ values }) => {\n assert.deepStrictEqual(expectedValues, values);\n return { embeddings, usage };\n };\n}\n","export function mockId({\n prefix = 'id',\n}: {\n prefix?: string;\n} = {}): () => string {\n let counter = 0;\n return () => `${prefix}-${counter++}`;\n}\n","import { LanguageModelV1 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockLanguageModelV1 implements LanguageModelV1 {\n readonly specificationVersion = 'v1';\n\n readonly provider: LanguageModelV1['provider'];\n readonly modelId: LanguageModelV1['modelId'];\n\n supportsUrl: LanguageModelV1['supportsUrl'];\n doGenerate: LanguageModelV1['doGenerate'];\n doStream: LanguageModelV1['doStream'];\n\n readonly defaultObjectGenerationMode: LanguageModelV1['defaultObjectGenerationMode'];\n readonly supportsStructuredOutputs: LanguageModelV1['supportsStructuredOutputs'];\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n supportsUrl = undefined,\n doGenerate = notImplemented,\n doStream = notImplemented,\n defaultObjectGenerationMode = undefined,\n supportsStructuredOutputs = undefined,\n }: {\n provider?: LanguageModelV1['provider'];\n modelId?: LanguageModelV1['modelId'];\n supportsUrl?: LanguageModelV1['supportsUrl'];\n doGenerate?: LanguageModelV1['doGenerate'];\n doStream?: LanguageModelV1['doStream'];\n defaultObjectGenerationMode?: LanguageModelV1['defaultObjectGenerationMode'];\n supportsStructuredOutputs?: LanguageModelV1['supportsStructuredOutputs'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.doGenerate = doGenerate;\n this.doStream = doStream;\n this.supportsUrl = supportsUrl;\n\n this.defaultObjectGenerationMode = defaultObjectGenerationMode;\n this.supportsStructuredOutputs = supportsStructuredOutputs;\n }\n}\n","export function mockValues<T>(...values: T[]): () => T {\n let counter = 0;\n return () => values[counter++] ?? values[values.length - 1];\n}\n","/**\n * Creates a Promise that resolves after a specified delay\n * @param delayInMs - The delay duration in milliseconds. If null or undefined, resolves immediately.\n * @returns A Promise that resolves after the specified delay\n */\nexport async function delay(delayInMs?: number | null): Promise<void> {\n return delayInMs == null\n ? Promise.resolve()\n : new Promise(resolve => setTimeout(resolve, delayInMs));\n}\n","import { delay as delayFunction } from '../../util/delay';\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,SAAS,oCAAoC;;;ACAtC,SAAS,iBAAwB;AACtC,QAAM,IAAI,MAAM,iBAAiB;AACnC;;;ACGO,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,sDAAwB;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AA,EACF,CAAC;AACH;;;AP3BO,IAAMC,0BAAyB;","names":["delay","simulateReadableStream"]}
1
+ {"version":3,"sources":["../index.ts","../../core/test/not-implemented.ts","../../core/test/mock-embedding-model-v1.ts","../../core/test/mock-id.ts","../../core/test/mock-language-model-v1.ts","../../core/test/mock-values.ts","../../core/util/simulate-readable-stream.ts"],"sourcesContent":["export { convertArrayToReadableStream } from '@ai-sdk/provider-utils/test';\nexport { MockEmbeddingModelV1 } from '../core/test/mock-embedding-model-v1';\nexport { mockId } from '../core/test/mock-id';\nexport { MockLanguageModelV1 } from '../core/test/mock-language-model-v1';\nexport { mockValues } from '../core/test/mock-values';\n\nimport { simulateReadableStream as originalSimulateReadableStream } from '../core/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 { EmbeddingModelV1 } from '@ai-sdk/provider';\nimport { Embedding } from '../types';\nimport { EmbeddingModelUsage } from '../types/usage';\nimport { notImplemented } from './not-implemented';\n\nexport class MockEmbeddingModelV1<VALUE> implements EmbeddingModelV1<VALUE> {\n readonly specificationVersion = 'v1';\n\n readonly provider: EmbeddingModelV1<VALUE>['provider'];\n readonly modelId: EmbeddingModelV1<VALUE>['modelId'];\n readonly maxEmbeddingsPerCall: EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall'];\n readonly supportsParallelCalls: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n\n doEmbed: EmbeddingModelV1<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?: EmbeddingModelV1<VALUE>['provider'];\n modelId?: EmbeddingModelV1<VALUE>['modelId'];\n maxEmbeddingsPerCall?:\n | EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall']\n | null;\n supportsParallelCalls?: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n doEmbed?: EmbeddingModelV1<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\nexport function mockEmbed<VALUE>(\n expectedValues: Array<VALUE>,\n embeddings: Array<Embedding>,\n usage?: EmbeddingModelUsage,\n): EmbeddingModelV1<VALUE>['doEmbed'] {\n return async ({ values }) => {\n assert.deepStrictEqual(expectedValues, values);\n return { embeddings, usage };\n };\n}\n","export function mockId({\n prefix = 'id',\n}: {\n prefix?: string;\n} = {}): () => string {\n let counter = 0;\n return () => `${prefix}-${counter++}`;\n}\n","import { LanguageModelV1 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockLanguageModelV1 implements LanguageModelV1 {\n readonly specificationVersion = 'v1';\n\n readonly provider: LanguageModelV1['provider'];\n readonly modelId: LanguageModelV1['modelId'];\n\n supportsUrl: LanguageModelV1['supportsUrl'];\n doGenerate: LanguageModelV1['doGenerate'];\n doStream: LanguageModelV1['doStream'];\n\n readonly defaultObjectGenerationMode: LanguageModelV1['defaultObjectGenerationMode'];\n readonly supportsStructuredOutputs: LanguageModelV1['supportsStructuredOutputs'];\n constructor({\n provider = 'mock-provider',\n modelId = 'mock-model-id',\n supportsUrl = undefined,\n doGenerate = notImplemented,\n doStream = notImplemented,\n defaultObjectGenerationMode = undefined,\n supportsStructuredOutputs = undefined,\n }: {\n provider?: LanguageModelV1['provider'];\n modelId?: LanguageModelV1['modelId'];\n supportsUrl?: LanguageModelV1['supportsUrl'];\n doGenerate?: LanguageModelV1['doGenerate'];\n doStream?: LanguageModelV1['doStream'];\n defaultObjectGenerationMode?: LanguageModelV1['defaultObjectGenerationMode'];\n supportsStructuredOutputs?: LanguageModelV1['supportsStructuredOutputs'];\n } = {}) {\n this.provider = provider;\n this.modelId = modelId;\n this.doGenerate = doGenerate;\n this.doStream = doStream;\n this.supportsUrl = supportsUrl;\n\n this.defaultObjectGenerationMode = defaultObjectGenerationMode;\n this.supportsStructuredOutputs = supportsStructuredOutputs;\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,SAAS,oCAAoC;;;ACAtC,SAAS,iBAAwB;AACtC,QAAM,IAAI,MAAM,iBAAiB;AACnC;;;ACGO,IAAM,uBAAN,MAAqE;AAAA,EAU1E,YAAY;AAAA,IACV,WA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