nexus-ai-pro 2.7.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/API_STABILITY.md +119 -3
  2. package/CHANGELOG.md +241 -1
  3. package/README.md +21 -3
  4. package/SECURITY.md +41 -1
  5. package/dist/batch/manager.js +16 -33
  6. package/dist/batch/openai-client.d.ts +83 -0
  7. package/dist/batch/openai-client.js +120 -0
  8. package/dist/batch/openai.d.ts +12 -21
  9. package/dist/batch/openai.js +33 -125
  10. package/dist/batch/poll.d.ts +22 -0
  11. package/dist/batch/poll.js +30 -0
  12. package/dist/cli/models.d.ts +36 -0
  13. package/dist/cli/models.js +170 -0
  14. package/dist/cli.js +11 -1
  15. package/dist/deep-agent/helpers.d.ts +4 -0
  16. package/dist/deep-agent/helpers.js +56 -4
  17. package/dist/doctor/index.d.ts +16 -1
  18. package/dist/doctor/index.js +10 -5
  19. package/dist/embeddings/adapters.d.ts +2 -2
  20. package/dist/embeddings/adapters.js +24 -13
  21. package/dist/embeddings/batch-google.d.ts +40 -0
  22. package/dist/embeddings/batch-google.js +128 -0
  23. package/dist/embeddings/batch-mock.d.ts +45 -0
  24. package/dist/embeddings/batch-mock.js +71 -0
  25. package/dist/embeddings/batch-openai.d.ts +23 -0
  26. package/dist/embeddings/batch-openai.js +55 -0
  27. package/dist/embeddings/batch.d.ts +230 -0
  28. package/dist/embeddings/batch.js +282 -0
  29. package/dist/embeddings/cache.d.ts +81 -0
  30. package/dist/embeddings/cache.js +116 -0
  31. package/dist/embeddings/engine.d.ts +7 -0
  32. package/dist/embeddings/engine.js +110 -68
  33. package/dist/embeddings/google-wire.d.ts +32 -0
  34. package/dist/embeddings/google-wire.js +33 -0
  35. package/dist/embeddings/index.d.ts +1 -1
  36. package/dist/embeddings/inputs.d.ts +30 -0
  37. package/dist/embeddings/inputs.js +103 -0
  38. package/dist/embeddings/mock.d.ts +7 -1
  39. package/dist/embeddings/mock.js +8 -2
  40. package/dist/embeddings/models.js +21 -0
  41. package/dist/evaluate/online.d.ts +5 -0
  42. package/dist/evaluate/online.js +74 -5
  43. package/dist/images/asset-stores.d.ts +47 -1
  44. package/dist/images/asset-stores.js +135 -2
  45. package/dist/images/asset-support.d.ts +94 -1
  46. package/dist/images/asset-support.js +159 -3
  47. package/dist/images/assets.d.ts +10 -3
  48. package/dist/images/assets.js +15 -2
  49. package/dist/lifecycle/budget.d.ts +60 -3
  50. package/dist/lifecycle/budget.js +147 -3
  51. package/dist/lifecycle/index.d.ts +2 -2
  52. package/dist/lifecycle/reservations.d.ts +46 -0
  53. package/dist/lifecycle/reservations.js +67 -0
  54. package/dist/media/index.d.ts +244 -0
  55. package/dist/media/index.js +262 -0
  56. package/dist/media/mistral.d.ts +34 -0
  57. package/dist/media/mistral.js +90 -0
  58. package/dist/media/mock.d.ts +36 -0
  59. package/dist/media/mock.js +45 -0
  60. package/dist/media/rag.d.ts +216 -0
  61. package/dist/media/rag.js +340 -0
  62. package/dist/models/data.d.ts +87 -0
  63. package/dist/models/data.js +235 -0
  64. package/dist/models/registry.d.ts +2 -1
  65. package/dist/models/registry.js +3 -2
  66. package/dist/postgres/embedding-cache.d.ts +29 -0
  67. package/dist/postgres/embedding-cache.js +58 -0
  68. package/dist/postgres/tenancy.d.ts +26 -1
  69. package/dist/postgres/tenancy.js +116 -1
  70. package/dist/postgres/traces.d.ts +2 -1
  71. package/dist/postgres/traces.js +13 -1
  72. package/dist/rag/chroma.d.ts +13 -1
  73. package/dist/rag/chroma.js +36 -13
  74. package/dist/rag/pinecone.js +2 -2
  75. package/dist/rag/pipeline.d.ts +17 -2
  76. package/dist/rag/pipeline.js +95 -14
  77. package/dist/rag/qdrant.js +2 -2
  78. package/dist/rag/redis.d.ts +2 -1
  79. package/dist/rag/redis.js +56 -18
  80. package/dist/rag/vector-helpers.d.ts +5 -0
  81. package/dist/rag/vector-helpers.js +7 -0
  82. package/dist/rag/weaviate.d.ts +15 -1
  83. package/dist/rag/weaviate.js +75 -12
  84. package/dist/server/tenancy.d.ts +33 -2
  85. package/dist/server/tenancy.js +162 -0
  86. package/dist/sqlite/embedding-cache.d.ts +34 -0
  87. package/dist/sqlite/embedding-cache.js +61 -0
  88. package/dist/tracing/index.d.ts +2 -2
  89. package/dist/tracing/index.js +1 -1
  90. package/dist/tracing/query.d.ts +5 -1
  91. package/dist/tracing/query.js +14 -1
  92. package/dist/tracing/stores.d.ts +2 -2
  93. package/dist/tracing/stores.js +2 -2
  94. package/dist/types/config.d.ts +5 -0
  95. package/dist/types/embeddings.d.ts +87 -5
  96. package/dist/types/images.d.ts +2 -2
  97. package/dist/types/lifecycle.d.ts +92 -1
  98. package/dist/types/tracing.d.ts +20 -1
  99. package/dist/utils/redis-command.d.ts +15 -0
  100. package/dist/utils/redis-command.js +5 -0
  101. package/dist/utils/sha256.d.ts +9 -0
  102. package/dist/utils/sha256.js +6 -0
  103. package/dist/utils/vector-bytes.d.ts +11 -0
  104. package/dist/utils/vector-bytes.js +18 -0
  105. package/dist/version.d.ts +1 -1
  106. package/dist/version.js +1 -1
  107. package/dist/video/errors.d.ts +37 -0
  108. package/dist/video/errors.js +22 -0
  109. package/dist/video/google.d.ts +52 -0
  110. package/dist/video/google.js +248 -0
  111. package/dist/video/index.d.ts +426 -0
  112. package/dist/video/index.js +666 -0
  113. package/dist/video/mock.d.ts +62 -0
  114. package/dist/video/mock.js +97 -0
  115. package/dist/video/runway.d.ts +47 -0
  116. package/dist/video/runway.js +241 -0
  117. package/dist-cjs/batch/manager.js +16 -33
  118. package/dist-cjs/batch/openai-client.d.ts +83 -0
  119. package/dist-cjs/batch/openai-client.js +125 -0
  120. package/dist-cjs/batch/openai.d.ts +12 -21
  121. package/dist-cjs/batch/openai.js +32 -124
  122. package/dist-cjs/batch/poll.d.ts +22 -0
  123. package/dist-cjs/batch/poll.js +33 -0
  124. package/dist-cjs/cli/models.d.ts +36 -0
  125. package/dist-cjs/cli/models.js +175 -0
  126. package/dist-cjs/deep-agent/helpers.d.ts +4 -0
  127. package/dist-cjs/deep-agent/helpers.js +56 -4
  128. package/dist-cjs/doctor/index.d.ts +16 -1
  129. package/dist-cjs/doctor/index.js +10 -5
  130. package/dist-cjs/embeddings/adapters.d.ts +2 -2
  131. package/dist-cjs/embeddings/adapters.js +23 -12
  132. package/dist-cjs/embeddings/batch-google.d.ts +40 -0
  133. package/dist-cjs/embeddings/batch-google.js +132 -0
  134. package/dist-cjs/embeddings/batch-mock.d.ts +45 -0
  135. package/dist-cjs/embeddings/batch-mock.js +75 -0
  136. package/dist-cjs/embeddings/batch-openai.d.ts +23 -0
  137. package/dist-cjs/embeddings/batch-openai.js +59 -0
  138. package/dist-cjs/embeddings/batch.d.ts +230 -0
  139. package/dist-cjs/embeddings/batch.js +320 -0
  140. package/dist-cjs/embeddings/cache.d.ts +81 -0
  141. package/dist-cjs/embeddings/cache.js +125 -0
  142. package/dist-cjs/embeddings/engine.d.ts +7 -0
  143. package/dist-cjs/embeddings/engine.js +143 -68
  144. package/dist-cjs/embeddings/google-wire.d.ts +32 -0
  145. package/dist-cjs/embeddings/google-wire.js +38 -0
  146. package/dist-cjs/embeddings/index.d.ts +1 -1
  147. package/dist-cjs/embeddings/inputs.d.ts +30 -0
  148. package/dist-cjs/embeddings/inputs.js +141 -0
  149. package/dist-cjs/embeddings/mock.d.ts +7 -1
  150. package/dist-cjs/embeddings/mock.js +8 -2
  151. package/dist-cjs/embeddings/models.js +21 -0
  152. package/dist-cjs/evaluate/online.d.ts +5 -0
  153. package/dist-cjs/evaluate/online.js +74 -5
  154. package/dist-cjs/images/asset-stores.d.ts +47 -1
  155. package/dist-cjs/images/asset-stores.js +133 -0
  156. package/dist-cjs/images/asset-support.d.ts +94 -1
  157. package/dist-cjs/images/asset-support.js +169 -3
  158. package/dist-cjs/images/assets.d.ts +10 -3
  159. package/dist-cjs/images/assets.js +17 -1
  160. package/dist-cjs/lifecycle/budget.d.ts +60 -3
  161. package/dist-cjs/lifecycle/budget.js +147 -3
  162. package/dist-cjs/lifecycle/index.d.ts +2 -2
  163. package/dist-cjs/lifecycle/reservations.d.ts +46 -0
  164. package/dist-cjs/lifecycle/reservations.js +71 -0
  165. package/dist-cjs/media/index.d.ts +244 -0
  166. package/dist-cjs/media/index.js +269 -0
  167. package/dist-cjs/media/mistral.d.ts +34 -0
  168. package/dist-cjs/media/mistral.js +94 -0
  169. package/dist-cjs/media/mock.d.ts +36 -0
  170. package/dist-cjs/media/mock.js +49 -0
  171. package/dist-cjs/media/rag.d.ts +216 -0
  172. package/dist-cjs/media/rag.js +344 -0
  173. package/dist-cjs/models/data.d.ts +87 -0
  174. package/dist-cjs/models/data.js +245 -0
  175. package/dist-cjs/models/registry.d.ts +2 -1
  176. package/dist-cjs/models/registry.js +3 -2
  177. package/dist-cjs/postgres/embedding-cache.d.ts +29 -0
  178. package/dist-cjs/postgres/embedding-cache.js +96 -0
  179. package/dist-cjs/postgres/tenancy.d.ts +26 -1
  180. package/dist-cjs/postgres/tenancy.js +115 -0
  181. package/dist-cjs/postgres/traces.d.ts +2 -1
  182. package/dist-cjs/postgres/traces.js +13 -1
  183. package/dist-cjs/rag/chroma.d.ts +13 -1
  184. package/dist-cjs/rag/chroma.js +35 -12
  185. package/dist-cjs/rag/pinecone.js +1 -1
  186. package/dist-cjs/rag/pipeline.d.ts +17 -2
  187. package/dist-cjs/rag/pipeline.js +95 -14
  188. package/dist-cjs/rag/qdrant.js +1 -1
  189. package/dist-cjs/rag/redis.d.ts +2 -1
  190. package/dist-cjs/rag/redis.js +55 -17
  191. package/dist-cjs/rag/vector-helpers.d.ts +5 -0
  192. package/dist-cjs/rag/vector-helpers.js +8 -0
  193. package/dist-cjs/rag/weaviate.d.ts +15 -1
  194. package/dist-cjs/rag/weaviate.js +74 -11
  195. package/dist-cjs/server/tenancy.d.ts +33 -2
  196. package/dist-cjs/server/tenancy.js +162 -0
  197. package/dist-cjs/sqlite/embedding-cache.d.ts +34 -0
  198. package/dist-cjs/sqlite/embedding-cache.js +99 -0
  199. package/dist-cjs/tracing/index.d.ts +2 -2
  200. package/dist-cjs/tracing/index.js +3 -1
  201. package/dist-cjs/tracing/query.d.ts +5 -1
  202. package/dist-cjs/tracing/query.js +16 -1
  203. package/dist-cjs/tracing/stores.d.ts +2 -2
  204. package/dist-cjs/tracing/stores.js +3 -1
  205. package/dist-cjs/types/config.d.ts +5 -0
  206. package/dist-cjs/types/embeddings.d.ts +87 -5
  207. package/dist-cjs/types/images.d.ts +2 -2
  208. package/dist-cjs/types/lifecycle.d.ts +92 -1
  209. package/dist-cjs/types/tracing.d.ts +20 -1
  210. package/dist-cjs/utils/redis-command.d.ts +15 -0
  211. package/dist-cjs/utils/redis-command.js +8 -0
  212. package/dist-cjs/utils/sha256.d.ts +9 -0
  213. package/dist-cjs/utils/sha256.js +7 -0
  214. package/dist-cjs/utils/vector-bytes.d.ts +11 -0
  215. package/dist-cjs/utils/vector-bytes.js +22 -0
  216. package/dist-cjs/version.d.ts +1 -1
  217. package/dist-cjs/version.js +1 -1
  218. package/dist-cjs/video/errors.d.ts +37 -0
  219. package/dist-cjs/video/errors.js +27 -0
  220. package/dist-cjs/video/google.d.ts +52 -0
  221. package/dist-cjs/video/google.js +252 -0
  222. package/dist-cjs/video/index.d.ts +426 -0
  223. package/dist-cjs/video/index.js +708 -0
  224. package/dist-cjs/video/mock.d.ts +62 -0
  225. package/dist-cjs/video/mock.js +101 -0
  226. package/dist-cjs/video/runway.d.ts +47 -0
  227. package/dist-cjs/video/runway.js +245 -0
  228. package/llms.txt +3 -1
  229. package/package.json +215 -4
@@ -0,0 +1,45 @@
1
+ import type { BatchJobRef, BatchJobState, BatchJobStatus, BatchProviderCallContext } from '../types/batch.js';
2
+ import type { EmbeddingProviderMediaPart } from '../types/embeddings.js';
3
+ import type { EmbeddingBatchOutputItem, EmbeddingBatchProvider, EmbeddingBatchProviderCapabilities, EmbeddingBatchProviderInfo, EmbeddingBatchProviderRequest } from './batch.js';
4
+ /** Options for the mock embedding batch tier. */
5
+ export interface MockEmbeddingBatchProviderOptions {
6
+ /** Its name, which its refs carry. Defaults to `mock`. */
7
+ name?: string;
8
+ /** Capabilities reported, merged over the defaults. */
9
+ capabilities?: Partial<EmbeddingBatchProviderCapabilities>;
10
+ /**
11
+ * Statuses successive polls of a batch return; the last repeats, so `['in_progress', 'completed']`
12
+ * finishes on the second poll. Defaults to completing at once.
13
+ */
14
+ statuses?: readonly BatchJobStatus[];
15
+ /** customIds that come back as errors instead of vectors. */
16
+ failItems?: readonly string[];
17
+ /** Vector width when the request sets none. Defaults to 16. */
18
+ dimensions?: number;
19
+ /** Reports input tokens per item, a word count. Defaults to true; false leaves the cost to be estimated. */
20
+ reportTokens?: boolean;
21
+ /** The text a media part's vector is hashed from, as `MockEmbeddingProviderOptions.describeMedia`. */
22
+ describeMedia?: (part: EmbeddingProviderMediaPart) => string;
23
+ }
24
+ /**
25
+ * A deterministic embedding batch tier, in memory. Each input's vector is the one
26
+ * `MockEmbeddingProvider` returns for it, so a test can compare the batch path with the direct one. It
27
+ * keeps every batch it was given in `submitted`.
28
+ */
29
+ export declare class MockEmbeddingBatchProvider implements EmbeddingBatchProvider {
30
+ private readonly options;
31
+ /** Its name and capabilities. */
32
+ readonly info: EmbeddingBatchProviderInfo;
33
+ /** Every batch submitted, in order. */
34
+ readonly submitted: EmbeddingBatchProviderRequest[];
35
+ private readonly batches;
36
+ constructor(options?: MockEmbeddingBatchProviderOptions);
37
+ /** Accepts a batch and returns its ref. */
38
+ submit(request: EmbeddingBatchProviderRequest, context: BatchProviderCallContext): Promise<BatchJobRef>;
39
+ /** The next scripted status. */
40
+ poll(ref: BatchJobRef): Promise<BatchJobState>;
41
+ /** Every input's vector, or its scripted failure. */
42
+ results(ref: BatchJobRef): Promise<EmbeddingBatchOutputItem[]>;
43
+ /** Cancels a batch: its next poll reports `cancelled`. */
44
+ cancel(ref: BatchJobRef): Promise<BatchJobState>;
45
+ }
@@ -0,0 +1,71 @@
1
+ import { createHashEmbeddings } from '../hallucination/retrieval.js';
2
+ export class MockEmbeddingBatchProvider {
3
+ options;
4
+ info;
5
+ submitted = [];
6
+ batches = new Map();
7
+ constructor(options = {}) {
8
+ this.options = options;
9
+ this.info = {
10
+ name: options.name ?? 'mock',
11
+ capabilities: {
12
+ maxItems: 50_000,
13
+ supportsCancel: true,
14
+ discount: 0.5,
15
+ inputModalities: ['text', 'image', 'audio', 'document'],
16
+ ...options.capabilities,
17
+ },
18
+ };
19
+ }
20
+ async submit(request, context) {
21
+ if (context.signal.aborted)
22
+ throw context.signal.reason ?? new Error('aborted');
23
+ this.submitted.push(request);
24
+ const id = `mock-batch-${this.submitted.length}`;
25
+ this.batches.set(id, { request, polls: 0 });
26
+ return { id, provider: this.info.name };
27
+ }
28
+ async poll(ref) {
29
+ const batch = this.batches.get(ref.id);
30
+ if (!batch)
31
+ throw new Error(`no mock batch ${ref.id}`);
32
+ const statuses = this.options.statuses ?? ['completed'];
33
+ const status = batch.cancelled
34
+ ? 'cancelled'
35
+ : (statuses[Math.min(batch.polls, statuses.length - 1)] ?? 'completed');
36
+ batch.polls += 1;
37
+ const total = batch.request.items.length;
38
+ const failed = (this.options.failItems ?? []).filter((id) => batch.request.items.some((item) => item.customId === id)).length;
39
+ return {
40
+ ref,
41
+ status,
42
+ counts: status === 'completed' ? { total, completed: total - failed, failed } : { total, completed: 0, failed: 0 },
43
+ };
44
+ }
45
+ async results(ref) {
46
+ const batch = this.batches.get(ref.id);
47
+ if (!batch)
48
+ throw new Error(`no mock batch ${ref.id}`);
49
+ const { request } = batch;
50
+ const describe = this.options.describeMedia ??
51
+ ((part) => `${part.type} ${(part.data ?? part.url)?.slice(0, 64)}`);
52
+ const texts = request.items.map((item) => item.contents
53
+ ? item.contents.map((part) => (part.type === 'text' ? part.text : describe(part))).join(' ')
54
+ : item.input);
55
+ const vectors = createHashEmbeddings(texts, request.dimensions ?? this.options.dimensions ?? 16);
56
+ const failures = new Set(this.options.failItems ?? []);
57
+ return request.items.map((item, index) => failures.has(item.customId)
58
+ ? { customId: item.customId, error: { message: 'scripted failure', code: 'mock_failure' } }
59
+ : {
60
+ customId: item.customId,
61
+ vector: vectors[index],
62
+ ...(this.options.reportTokens === false ? {} : { inputTokens: (texts[index] ?? '').split(/\s+/).length }),
63
+ });
64
+ }
65
+ async cancel(ref) {
66
+ const batch = this.batches.get(ref.id);
67
+ if (batch)
68
+ batch.cancelled = true;
69
+ return { ref, status: 'cancelled' };
70
+ }
71
+ }
@@ -0,0 +1,23 @@
1
+ import { type OpenAIBatchClientOptions } from '../batch/openai-client.js';
2
+ import type { BatchJobRef, BatchJobState, BatchProviderCallContext } from '../types/batch.js';
3
+ import type { EmbeddingBatchOutputItem, EmbeddingBatchProvider, EmbeddingBatchProviderInfo, EmbeddingBatchProviderRequest } from './batch.js';
4
+ /** Options for OpenAI's embedding batch tier: the key, and optionally the base URL, organization, and `fetch`. */
5
+ export type OpenAIEmbeddingBatchProviderOptions = OpenAIBatchClientOptions;
6
+ /**
7
+ * OpenAI's Batch API for `/v1/embeddings`: half price, a 24-hour window, and at most 50,000 inputs a
8
+ * batch. Each input is one line; failed lines are read from the error file, so none goes missing.
9
+ */
10
+ export declare class OpenAIEmbeddingBatchProvider implements EmbeddingBatchProvider {
11
+ /** Always `openai`, with its batch limits. */
12
+ readonly info: EmbeddingBatchProviderInfo;
13
+ private readonly client;
14
+ constructor(options: OpenAIEmbeddingBatchProviderOptions);
15
+ /** Uploads one line per input and creates a batch over them. */
16
+ submit(request: EmbeddingBatchProviderRequest, context: BatchProviderCallContext): Promise<BatchJobRef>;
17
+ /** Reads a batch's status and counts. */
18
+ poll(ref: BatchJobRef, context: BatchProviderCallContext): Promise<BatchJobState>;
19
+ /** Every input's vector or error, from the output and error files. */
20
+ results(ref: BatchJobRef, context: BatchProviderCallContext): Promise<EmbeddingBatchOutputItem[]>;
21
+ /** Cancels a batch. Inputs already embedded keep their results. */
22
+ cancel(ref: BatchJobRef, context: BatchProviderCallContext): Promise<BatchJobState>;
23
+ }
@@ -0,0 +1,55 @@
1
+ import { lineError, OpenAIBatchClient } from '../batch/openai-client.js';
2
+ export class OpenAIEmbeddingBatchProvider {
3
+ info = {
4
+ name: 'openai',
5
+ capabilities: {
6
+ maxItems: 50_000,
7
+ maxBytes: 200 * 1024 * 1024,
8
+ completionWindows: ['24h'],
9
+ supportsCancel: true,
10
+ discount: 0.5,
11
+ inputModalities: ['text'],
12
+ },
13
+ };
14
+ client;
15
+ constructor(options) {
16
+ this.client = new OpenAIBatchClient(options);
17
+ }
18
+ async submit(request, context) {
19
+ const { batch, fileId } = await this.client.create(request.items.map((item) => ({
20
+ custom_id: item.customId,
21
+ method: 'POST',
22
+ url: '/v1/embeddings',
23
+ body: {
24
+ model: request.model,
25
+ input: item.input,
26
+ encoding_format: 'float',
27
+ ...(request.dimensions !== undefined ? { dimensions: request.dimensions } : {}),
28
+ },
29
+ })), { endpoint: '/v1/embeddings', completionWindow: request.completionWindow, metadata: request.metadata }, context);
30
+ return { id: batch.id, provider: 'openai', metadata: { inputFileId: fileId } };
31
+ }
32
+ async poll(ref, context) {
33
+ return this.client.state(ref, await this.client.read(ref.id, context));
34
+ }
35
+ async results(ref, context) {
36
+ return (await this.client.lines(ref.id, context)).map((line) => {
37
+ const customId = line.custom_id ?? '';
38
+ const error = lineError(line);
39
+ if (error)
40
+ return { customId, error };
41
+ const body = line.response?.body;
42
+ const vector = body.data?.[0]?.embedding;
43
+ if (!Array.isArray(vector))
44
+ return { customId, error: { message: 'the line carried no embedding' } };
45
+ return {
46
+ customId,
47
+ vector,
48
+ ...(body.usage?.prompt_tokens !== undefined ? { inputTokens: body.usage.prompt_tokens } : {}),
49
+ };
50
+ });
51
+ }
52
+ async cancel(ref, context) {
53
+ return this.client.state(ref, await this.client.cancel(ref.id, context));
54
+ }
55
+ }
@@ -0,0 +1,230 @@
1
+ import type { BatchCounts, BatchJobRef, BatchJobState, BatchJobStatus, BatchProviderCallContext, BatchProviderCapabilities } from '../types/batch.js';
2
+ import type { EmbeddingInputType, EmbeddingModality, EmbeddingModelRegistryConfig, EmbeddingParts, EmbeddingProviderPart } from '../types/embeddings.js';
3
+ import type { OperationLifecycleLike } from '../types/lifecycle.js';
4
+ import type { DurableOperationHandle, OperationRunnerConfig } from '../types/operations.js';
5
+ import type { ResponseCost, TokenUsage } from '../types/response.js';
6
+ /** One input of an embedding batch, under the id its vector comes back by. */
7
+ export interface EmbeddingBatchItem {
8
+ /** Echoed back with the vector. Required, and unique: a provider does not keep the order. */
9
+ customId: string;
10
+ /** A text, or parts holding media for a model that takes it. */
11
+ input: string | EmbeddingParts;
12
+ }
13
+ /** A batch of inputs to embed through a provider's batch tier. */
14
+ export interface EmbeddingBatchSubmitRequest {
15
+ /** The inputs. Every `customId` must be unique. */
16
+ items: readonly EmbeddingBatchItem[];
17
+ /** The concrete model. A batch tier takes no alias routing. */
18
+ model: string;
19
+ /** The adapter to use. Defaults to the manager's default. */
20
+ provider?: string;
21
+ /** What the vectors will be used for. */
22
+ inputType?: EmbeddingInputType;
23
+ /** Vector size to return, on models that can shorten theirs. */
24
+ dimensions?: number;
25
+ /** Scales every vector to unit length. */
26
+ normalize?: boolean;
27
+ /** How long the provider may take, in its own vocabulary. Defaults to `24h`. */
28
+ completionWindow?: string;
29
+ /** Replays the operation accepted under this key instead of submitting a second batch. */
30
+ idempotencyKey?: string;
31
+ /** Labels attached to the batch on the provider's side. */
32
+ metadata?: Record<string, string>;
33
+ /** Overrides the manager's poll interval. */
34
+ pollIntervalMs?: number;
35
+ /** Gives up waiting after this long. The provider-side batch is left running. */
36
+ timeoutMs?: number;
37
+ /** Stops waiting. The provider-side batch keeps running unless it is cancelled. */
38
+ signal?: AbortSignal;
39
+ }
40
+ /** One input as an adapter receives it: its text, and its parts when the batch holds media. */
41
+ export interface EmbeddingBatchProviderItem {
42
+ /** The id its vector comes back by. */
43
+ customId: string;
44
+ /** Its text: a string itself, or its text parts joined. */
45
+ input: string;
46
+ /** Its parts, media resolved to base64 or a URL, when the batch holds media. */
47
+ contents?: EmbeddingProviderPart[];
48
+ }
49
+ /** A batch as an adapter receives it: inputs checked and resolved. */
50
+ export interface EmbeddingBatchProviderRequest {
51
+ /** The inputs. */
52
+ items: EmbeddingBatchProviderItem[];
53
+ /** The provider's model name. */
54
+ model: string;
55
+ /** What the vectors will be used for. */
56
+ inputType?: EmbeddingInputType;
57
+ /** Vector size to return. */
58
+ dimensions?: number;
59
+ /** The completion window. */
60
+ completionWindow?: string;
61
+ /** Labels for the provider's side. */
62
+ metadata?: Record<string, string>;
63
+ }
64
+ /** One input's outcome: its vector, or why it failed. */
65
+ export interface EmbeddingBatchOutputItem {
66
+ /** The id of the input this answers. */
67
+ customId: string;
68
+ /** The vector, when the input succeeded. */
69
+ vector?: number[];
70
+ /** Why it failed, when it did. */
71
+ error?: {
72
+ message: string;
73
+ code?: string;
74
+ status?: number;
75
+ };
76
+ /** Input tokens, when the provider reports them. */
77
+ inputTokens?: number;
78
+ }
79
+ /** What an embedding batch tier supports: a batch tier's limits, and the media it takes. */
80
+ export interface EmbeddingBatchProviderCapabilities extends BatchProviderCapabilities {
81
+ /** What its inputs can hold. Text only when absent. */
82
+ inputModalities?: readonly EmbeddingModality[];
83
+ }
84
+ /** Identifies an embedding batch adapter and what it supports. */
85
+ export interface EmbeddingBatchProviderInfo {
86
+ /** The adapter's name, which its refs carry. */
87
+ name: string;
88
+ /** What it supports. */
89
+ capabilities: EmbeddingBatchProviderCapabilities;
90
+ }
91
+ /**
92
+ * A provider's batch tier for embeddings. Everything after `submit` takes only a `BatchJobRef`, which
93
+ * is JSON and survives a restart, so a worker can collect a batch it did not submit.
94
+ */
95
+ export interface EmbeddingBatchProvider {
96
+ /** What the adapter is and what it supports. */
97
+ readonly info: EmbeddingBatchProviderInfo;
98
+ /** Submits the batch and returns a reference that survives a restart. */
99
+ submit(request: EmbeddingBatchProviderRequest, context: BatchProviderCallContext): Promise<BatchJobRef>;
100
+ /** Reads the batch's current status. */
101
+ poll(ref: BatchJobRef, context: BatchProviderCallContext): Promise<BatchJobState>;
102
+ /** Every input's outcome, once the batch has finished. */
103
+ results(ref: BatchJobRef, context: BatchProviderCallContext): Promise<EmbeddingBatchOutputItem[]>;
104
+ /** Cancels a running batch. */
105
+ cancel?(ref: BatchJobRef, context: BatchProviderCallContext): Promise<BatchJobState>;
106
+ }
107
+ /** A finished embedding batch: every input's outcome, its usage, and its cost at the batch price. */
108
+ export interface EmbeddingBatchResult {
109
+ /** The batch. */
110
+ ref: BatchJobRef;
111
+ /** Its final status. */
112
+ status: BatchJobStatus;
113
+ /** Every input's outcome, matched by `customId`, never by position. */
114
+ items: EmbeddingBatchOutputItem[];
115
+ /** How many succeeded and failed. */
116
+ counts: BatchCounts;
117
+ /** Input tokens: reported where the provider reports them, estimated where it does not. */
118
+ usage: TokenUsage;
119
+ /** Priced from the embedding registry, with the provider's discount applied. */
120
+ cost: ResponseCost;
121
+ /** ISO-8601 time it was submitted. */
122
+ createdAt?: string;
123
+ /** ISO-8601 time it finished. */
124
+ completedAt?: string;
125
+ /** The provider's final status payload. */
126
+ raw?: unknown;
127
+ }
128
+ /** Configuration for `EmbeddingBatchManager`. */
129
+ export interface EmbeddingBatchConfig {
130
+ /** Adapters, by name. */
131
+ providers?: Record<string, EmbeddingBatchProvider>;
132
+ /** The adapter used when a submission names none. */
133
+ defaultProvider?: string;
134
+ /** How often to poll a running batch. Defaults to 30 seconds. */
135
+ pollIntervalMs?: number;
136
+ /** The longest poll interval once backoff has grown it. Defaults to 5 minutes. */
137
+ maxPollIntervalMs?: number;
138
+ /** How long a submission waits before giving up. Defaults to 26 hours. */
139
+ timeoutMs?: number;
140
+ /** Embedding models and prices beyond the bundled ones, used to check inputs and price results. */
141
+ models?: EmbeddingModelRegistryConfig;
142
+ }
143
+ /** What the manager runs on. */
144
+ export interface EmbeddingBatchManagerRuntime {
145
+ /** Persists each submission, so a submitted batch survives a restart. */
146
+ operations?: OperationRunnerConfig<EmbeddingBatchResult>;
147
+ /**
148
+ * Runs every submission as one operation of a client's lifecycle, labelled `embedding`: pass
149
+ * `ai.lifecycle`. It is authorized before the provider sees it, and its cost is reconciled when the
150
+ * batch is collected.
151
+ */
152
+ lifecycle?: OperationLifecycleLike;
153
+ }
154
+ /**
155
+ * Embedding batch tiers behind one handle: submit, poll with backoff, collect, and price at the
156
+ * batch rate. A submission is a durable operation that records its batch the moment it exists, so a
157
+ * worker that dies while it waits is replaced by one that collects that batch, never a second.
158
+ */
159
+ export declare class EmbeddingBatchManager {
160
+ private readonly config;
161
+ private readonly runtime;
162
+ private readonly providers;
163
+ /** Loaded on the first `submit()`: `start()` and `resume()` need neither the runner nor the lifecycle. */
164
+ private durable?;
165
+ private readonly tokenizer;
166
+ constructor(config?: EmbeddingBatchConfig, runtime?: EmbeddingBatchManagerRuntime);
167
+ /** Registers an adapter under a name. Returns the manager, for chaining. */
168
+ registerEmbeddingBatchProvider(name: string, provider: EmbeddingBatchProvider): this;
169
+ /** Whether an adapter is registered. */
170
+ hasEmbeddingBatchProvider(name: string): boolean;
171
+ /** Every registered adapter's name. */
172
+ listEmbeddingBatchProviders(): string[];
173
+ /**
174
+ * Submits a batch and returns a durable handle that settles when the provider finishes, which can
175
+ * be hours away: persist `handle.id`, rather than block a request on `handle.result()`.
176
+ */
177
+ submit(request: EmbeddingBatchSubmitRequest): Promise<DurableOperationHandle<EmbeddingBatchResult>>;
178
+ /**
179
+ * Submits a batch and returns its ref at once, without waiting: for a caller that keeps the ref
180
+ * itself, as the ingestion pipeline does, and collects it later with `resume()`.
181
+ */
182
+ start(request: EmbeddingBatchSubmitRequest): Promise<BatchJobRef>;
183
+ /** Waits for a batch, submitted here or by another process, and collects it. */
184
+ resume(ref: BatchJobRef, options?: {
185
+ signal?: AbortSignal;
186
+ pollIntervalMs?: number;
187
+ }): Promise<EmbeddingBatchResult>;
188
+ /** The batch's state now, without waiting. */
189
+ status(ref: BatchJobRef): Promise<BatchJobState>;
190
+ /** Cancels a batch. Throws when the adapter cannot cancel. */
191
+ cancel(ref: BatchJobRef): Promise<BatchJobState>;
192
+ private prepare;
193
+ private collect;
194
+ private price;
195
+ private resolveProvider;
196
+ /** The adapter a ref belongs to: by its registered name, or the adapter's own name the ref carries. */
197
+ private providerFor;
198
+ }
199
+ /** What `batchEmbedder()` submits under. */
200
+ export interface BatchEmbedderOptions {
201
+ /** The concrete model. */
202
+ model: string;
203
+ /** The adapter. Defaults to the manager's default. */
204
+ provider?: string;
205
+ /** What the vectors will be used for. Ingestion stores documents, so defaults to `document`. */
206
+ inputType?: EmbeddingInputType;
207
+ /** Vector size to return. */
208
+ dimensions?: number;
209
+ /** Scales every vector to unit length. */
210
+ normalize?: boolean;
211
+ /** Texts per provider batch. Defaults to 10,000. */
212
+ size?: number;
213
+ /** How often to poll. Defaults to the manager's interval. */
214
+ pollIntervalMs?: number;
215
+ }
216
+ /** What `createIngestionPipeline()` takes as `batchEmbed`: submit texts as one batch, collect it later. */
217
+ export interface BatchEmbedder {
218
+ /** Texts per provider batch. */
219
+ readonly size: number;
220
+ /** Submits texts as one batch, labelled with `key`, and returns its ref, which survives a restart. */
221
+ submit(texts: string[], key: string): Promise<BatchJobRef>;
222
+ /** Waits for a batch and returns its vectors, in the order its texts were submitted. */
223
+ collect(ref: BatchJobRef, signal?: AbortSignal): Promise<number[][]>;
224
+ }
225
+ /**
226
+ * An embedding batch tier as the ingestion pipeline's `batchEmbed`: each window of chunks becomes one
227
+ * provider batch at the batch price. A batch that does not complete, or any input that fails, fails
228
+ * the collection, so a window is never written half embedded.
229
+ */
230
+ export declare function batchEmbedder(manager: EmbeddingBatchManager, options: BatchEmbedderOptions): BatchEmbedder;