@anvia/core 0.3.1 → 0.4.1

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 (89) hide show
  1. package/README.md +7 -8
  2. package/dist/agent/index.d.ts +10 -10
  3. package/dist/agent/index.js +10 -18
  4. package/dist/{agent-D_jXqPAZ.d.ts → agent-B-ls5y_g.d.ts} +6 -19
  5. package/dist/audio-generation/index.d.ts +1 -1
  6. package/dist/audio-generation/index.js +37 -4
  7. package/dist/audio-generation/index.js.map +1 -1
  8. package/dist/{chunk-QRZ2HPUX.js → chunk-4PHDOEKY.js} +3 -3
  9. package/dist/chunk-4PHDOEKY.js.map +1 -0
  10. package/dist/chunk-BD66WU2B.js +188 -0
  11. package/dist/chunk-BD66WU2B.js.map +1 -0
  12. package/dist/{chunk-I2HOMD3R.js → chunk-CY7SB5FG.js} +3 -3
  13. package/dist/{chunk-A7VDIZQN.js → chunk-EFGX3EX5.js} +5 -14
  14. package/dist/chunk-EFGX3EX5.js.map +1 -0
  15. package/dist/{chunk-TILE6Z2N.js → chunk-L6JCKFAX.js} +2 -2
  16. package/dist/{chunk-65QV627O.js → chunk-OIA4CN5V.js} +2 -2
  17. package/dist/chunk-OIMLU4SF.js +20 -0
  18. package/dist/chunk-OIMLU4SF.js.map +1 -0
  19. package/dist/{chunk-GSFQZYS7.js → chunk-TVIADATY.js} +579 -723
  20. package/dist/chunk-TVIADATY.js.map +1 -0
  21. package/dist/completion/index.d.ts +2 -2
  22. package/dist/embeddings/index.d.ts +4 -24
  23. package/dist/embeddings/index.js +2 -1
  24. package/dist/evals/index.d.ts +26 -21
  25. package/dist/evals/index.js +298 -15
  26. package/dist/evals/index.js.map +1 -1
  27. package/dist/extractor/index.d.ts +6 -5
  28. package/dist/extractor/index.js +8 -6
  29. package/dist/image-generation/index.d.ts +1 -1
  30. package/dist/image-generation/index.js +37 -4
  31. package/dist/image-generation/index.js.map +1 -1
  32. package/dist/index.d.ts +12 -21
  33. package/dist/index.js +14 -160
  34. package/dist/internal/agent.d.ts +8 -0
  35. package/dist/internal/agent.js +18 -0
  36. package/dist/internal/agent.js.map +1 -0
  37. package/dist/loaders/index.d.ts +1 -1
  38. package/dist/mcp/index.d.ts +4 -4
  39. package/dist/mcp/index.js +140 -4
  40. package/dist/mcp/index.js.map +1 -1
  41. package/dist/memory/index.d.ts +1 -1
  42. package/dist/{middleware-2FR89muX.d.ts → middleware-CGiEIaBx.d.ts} +4 -7
  43. package/dist/model-listing/index.js +13 -3
  44. package/dist/model-listing/index.js.map +1 -1
  45. package/dist/observability/index.d.ts +2 -2
  46. package/dist/observability/index.js +4 -3
  47. package/dist/observability/index.js.map +1 -1
  48. package/dist/pipeline/index.d.ts +9 -6
  49. package/dist/pipeline/index.js +334 -3
  50. package/dist/pipeline/index.js.map +1 -1
  51. package/dist/skills/index.d.ts +4 -4
  52. package/dist/skills/index.js +5 -4
  53. package/dist/think-tool-ByArsrxe.d.ts +26 -0
  54. package/dist/tool/index.d.ts +8 -29
  55. package/dist/tool/index.js +4 -3
  56. package/dist/{tool-ClZYES-Z.d.ts → tool-C3ciF-VG.d.ts} +2 -2
  57. package/dist/transcription/index.d.ts +1 -1
  58. package/dist/transcription/index.js +55 -4
  59. package/dist/transcription/index.js.map +1 -1
  60. package/dist/{types-BM8-Y8Hy.d.ts → types-C54aNoCd.d.ts} +1 -1
  61. package/dist/types-IB2e9u5M.d.ts +25 -0
  62. package/dist/{types-B0iXLkqi.d.ts → types-T9rlOIUc.d.ts} +2 -2
  63. package/dist/{types-fLi8uM5R.d.ts → types-UhcgW8Fo.d.ts} +3 -3
  64. package/dist/vector-store/index.d.ts +3 -3
  65. package/dist/vector-store/index.js +3 -2
  66. package/dist/zod-schema-C7F4clpm.d.ts +5 -0
  67. package/package.json +6 -2
  68. package/dist/chunk-6JCCM2K4.js +0 -304
  69. package/dist/chunk-6JCCM2K4.js.map +0 -1
  70. package/dist/chunk-7QI6ZAFI.js +0 -61
  71. package/dist/chunk-7QI6ZAFI.js.map +0 -1
  72. package/dist/chunk-A7VDIZQN.js.map +0 -1
  73. package/dist/chunk-B24Q2ZYM.js +0 -43
  74. package/dist/chunk-B24Q2ZYM.js.map +0 -1
  75. package/dist/chunk-GSFQZYS7.js.map +0 -1
  76. package/dist/chunk-I77SDTFE.js +0 -43
  77. package/dist/chunk-I77SDTFE.js.map +0 -1
  78. package/dist/chunk-NYUOBGVI.js +0 -146
  79. package/dist/chunk-NYUOBGVI.js.map +0 -1
  80. package/dist/chunk-QRZ2HPUX.js.map +0 -1
  81. package/dist/chunk-RTOGIJH2.js +0 -345
  82. package/dist/chunk-RTOGIJH2.js.map +0 -1
  83. package/dist/chunk-WJT22R3T.js +0 -18
  84. package/dist/chunk-WJT22R3T.js.map +0 -1
  85. package/dist/chunk-ZSYIQYTV.js +0 -9
  86. package/dist/chunk-ZSYIQYTV.js.map +0 -1
  87. /package/dist/{chunk-I2HOMD3R.js.map → chunk-CY7SB5FG.js.map} +0 -0
  88. /package/dist/{chunk-TILE6Z2N.js.map → chunk-L6JCKFAX.js.map} +0 -0
  89. /package/dist/{chunk-65QV627O.js.map → chunk-OIA4CN5V.js.map} +0 -0
@@ -1,7 +1,338 @@
1
1
  import {
2
- Pipeline,
3
- PipelineBuilder
4
- } from "../chunk-RTOGIJH2.js";
2
+ mapWithConcurrency
3
+ } from "../chunk-OIMLU4SF.js";
4
+
5
+ // src/pipeline/graph.ts
6
+ function initialBuilderState(metadata) {
7
+ return {
8
+ graph: initialGraph(metadata),
9
+ terminalNodeId: "input",
10
+ terminalNodeIds: ["input"],
11
+ nextNodeIndex: 1,
12
+ nextEdgeIndex: 1
13
+ };
14
+ }
15
+ function initialGraph(metadata) {
16
+ const id = normalizeId(metadata.id ?? "pipeline");
17
+ return {
18
+ id,
19
+ ...metadata.name === void 0 ? {} : { name: metadata.name },
20
+ ...metadata.description === void 0 ? {} : { description: metadata.description },
21
+ ...metadata.metadata === void 0 ? {} : { metadata: metadata.metadata },
22
+ nodes: [{ id: "input", kind: "input", label: "Input" }],
23
+ edges: []
24
+ };
25
+ }
26
+ function appendNode(state, kind, label, options = {}) {
27
+ const node = graphNode(kind, label, state.nextNodeIndex, {
28
+ ...options,
29
+ existingIds: new Set(state.graph.nodes.map((item) => item.id))
30
+ });
31
+ return {
32
+ node,
33
+ state: appendGraphNode(state, node, activeTerminalNodeIds(state), [node.id])
34
+ };
35
+ }
36
+ function appendChildNode(state, parentId, kind, label, options = {}) {
37
+ const node = graphNode(kind, label, state.nextNodeIndex, {
38
+ ...options,
39
+ existingIds: new Set(state.graph.nodes.map((item) => item.id))
40
+ });
41
+ return {
42
+ node,
43
+ state: appendGraphNode(state, node, [parentId], activeTerminalNodeIds(state))
44
+ };
45
+ }
46
+ function activeTerminalNodeIds(state) {
47
+ return state.terminalNodeIds.length > 0 ? state.terminalNodeIds : [state.terminalNodeId];
48
+ }
49
+ function withTerminalNodes(state, terminalNodeIds) {
50
+ return {
51
+ ...state,
52
+ terminalNodeId: terminalNodeIds.at(-1) ?? state.terminalNodeId,
53
+ terminalNodeIds
54
+ };
55
+ }
56
+ function withOutputNode(state) {
57
+ const graph = cloneGraph(state.graph);
58
+ if (graph.nodes.some((node) => node.id === "output")) {
59
+ return graph;
60
+ }
61
+ graph.nodes.push({ id: "output", kind: "output", label: "Output" });
62
+ graph.edges.push(
63
+ ...activeTerminalNodeIds(state).map((sourceId, index) => ({
64
+ id: `edge_${state.nextEdgeIndex + index}`,
65
+ source: sourceId,
66
+ target: "output"
67
+ }))
68
+ );
69
+ return graph;
70
+ }
71
+ function nextStageLabel(state, prefix) {
72
+ return `${prefix} ${state.nextNodeIndex}`;
73
+ }
74
+ function cloneGraph(graph) {
75
+ return {
76
+ ...graph,
77
+ nodes: graph.nodes.map((node) => ({ ...node })),
78
+ edges: graph.edges.map((edge) => ({ ...edge }))
79
+ };
80
+ }
81
+ function appendGraphNode(state, node, sourceIds, terminalNodeIds) {
82
+ const edges = sourceIds.map((sourceId, index) => ({
83
+ id: `edge_${state.nextEdgeIndex + index}`,
84
+ source: sourceId,
85
+ target: node.id
86
+ }));
87
+ const terminalNodeId = terminalNodeIds.at(-1) ?? state.terminalNodeId;
88
+ return {
89
+ graph: {
90
+ ...state.graph,
91
+ nodes: [...state.graph.nodes, node],
92
+ edges: [...state.graph.edges, ...edges]
93
+ },
94
+ terminalNodeId,
95
+ terminalNodeIds,
96
+ nextNodeIndex: state.nextNodeIndex + 1,
97
+ nextEdgeIndex: state.nextEdgeIndex + edges.length
98
+ };
99
+ }
100
+ function graphNode(kind, label, index, options = {}) {
101
+ const id = uniqueGraphNodeId(
102
+ normalizeId(options.preferredId ?? `${kind}_${index}`),
103
+ options.existingIds ?? /* @__PURE__ */ new Set()
104
+ );
105
+ return {
106
+ id,
107
+ kind,
108
+ label,
109
+ ...options.description === void 0 ? {} : { description: options.description },
110
+ ...options.metadata === void 0 ? {} : { metadata: options.metadata },
111
+ ...options.agentId === void 0 ? {} : { agentId: options.agentId },
112
+ ...options.agentName === void 0 ? {} : { agentName: options.agentName },
113
+ ...options.pipelineId === void 0 ? {} : { pipelineId: options.pipelineId },
114
+ ...options.branchKey === void 0 ? {} : { branchKey: options.branchKey }
115
+ };
116
+ }
117
+ function normalizeId(value) {
118
+ const normalized = value.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, "_").replace(/^_+|_+$/g, "");
119
+ return normalized.length === 0 ? "pipeline" : normalized;
120
+ }
121
+ function uniqueGraphNodeId(baseId, existingIds) {
122
+ let id = baseId;
123
+ let suffix = 2;
124
+ while (existingIds.has(id)) {
125
+ id = `${baseId}_${suffix}`;
126
+ suffix += 1;
127
+ }
128
+ return id;
129
+ }
130
+
131
+ // src/pipeline/pipeline.ts
132
+ var Pipeline = class {
133
+ constructor(executor, pipelineGraph = initialGraph({})) {
134
+ this.executor = executor;
135
+ this.pipelineGraph = pipelineGraph;
136
+ this.id = pipelineGraph.id;
137
+ this.name = pipelineGraph.name;
138
+ this.description = pipelineGraph.description;
139
+ this.metadata = pipelineGraph.metadata;
140
+ }
141
+ executor;
142
+ pipelineGraph;
143
+ id;
144
+ name;
145
+ description;
146
+ metadata;
147
+ /** Run one input through the built pipeline and return the final stage output. */
148
+ async run(input, options = {}) {
149
+ return await this.executor(input, { observer: options.observer });
150
+ }
151
+ /** Run many inputs through the same pipeline with bounded concurrency. */
152
+ async batch(inputs, options) {
153
+ return mapWithConcurrency([...inputs], options.concurrency, (input) => this.run(input));
154
+ }
155
+ graph() {
156
+ return cloneGraph(this.pipelineGraph);
157
+ }
158
+ };
159
+
160
+ // src/pipeline/runtime.ts
161
+ async function runNode(context, node, fn) {
162
+ const startedAt = Date.now();
163
+ await context.observer?.onEvent({ type: "stage_started", node });
164
+ try {
165
+ const output = await fn();
166
+ await context.observer?.onEvent({
167
+ type: "stage_completed",
168
+ node,
169
+ durationMs: Date.now() - startedAt
170
+ });
171
+ return output;
172
+ } catch (error) {
173
+ await context.observer?.onEvent({
174
+ type: "stage_failed",
175
+ node,
176
+ durationMs: Date.now() - startedAt,
177
+ error
178
+ });
179
+ throw error;
180
+ }
181
+ }
182
+
183
+ // src/pipeline/builder.ts
184
+ var PipelineBuilder = class _PipelineBuilder {
185
+ executor;
186
+ state;
187
+ constructor(metadataOrExecutor, state) {
188
+ if (state !== void 0) {
189
+ this.executor = metadataOrExecutor;
190
+ this.state = state;
191
+ return;
192
+ }
193
+ if (typeof metadataOrExecutor === "function") {
194
+ const executor = metadataOrExecutor;
195
+ this.executor = ((input) => executor(input));
196
+ this.state = initialBuilderState({});
197
+ return;
198
+ }
199
+ this.executor = identity;
200
+ this.state = initialBuilderState(metadataOrExecutor ?? {});
201
+ }
202
+ /** Add a synchronous or asynchronous transform stage. */
203
+ step(fn, metadata) {
204
+ const next = appendNode(
205
+ this.state,
206
+ "step",
207
+ metadata?.name ?? nextStageLabel(this.state, "Step"),
208
+ {
209
+ description: metadata?.description,
210
+ metadata: metadata?.metadata,
211
+ preferredId: metadata?.id
212
+ }
213
+ );
214
+ return new _PipelineBuilder(
215
+ async (input, context) => {
216
+ const value = await this.runStep(input, context);
217
+ const result = await runNode(context, next.node, () => fn(value));
218
+ return result;
219
+ },
220
+ next.state
221
+ );
222
+ }
223
+ /** Compose another pipeline operation after the current stage. */
224
+ use(op, metadata) {
225
+ const nested = op instanceof Pipeline ? op : void 0;
226
+ const next = appendNode(
227
+ this.state,
228
+ nested === void 0 ? "step" : "pipeline",
229
+ metadata?.name ?? nested?.name ?? nested?.id ?? nextStageLabel(this.state, nested === void 0 ? "Operation" : "Pipeline"),
230
+ {
231
+ description: metadata?.description ?? nested?.description,
232
+ metadata: metadata?.metadata ?? nested?.metadata,
233
+ preferredId: metadata?.id,
234
+ pipelineId: nested?.id
235
+ }
236
+ );
237
+ return new _PipelineBuilder(
238
+ async (input, context) => {
239
+ const value = await this.runStep(input, context);
240
+ const result = await runNode(context, next.node, () => op.run(value));
241
+ return result;
242
+ },
243
+ next.state
244
+ );
245
+ }
246
+ /** Run named branch operations concurrently from the current value. */
247
+ parallel(branches, metadata) {
248
+ const parallel = appendNode(
249
+ this.state,
250
+ "parallel",
251
+ metadata?.name ?? `${Object.keys(branches).length} parallel branches`,
252
+ {
253
+ description: metadata?.description,
254
+ metadata: metadata?.metadata,
255
+ preferredId: metadata?.id
256
+ }
257
+ );
258
+ let nextState = parallel.state;
259
+ const branchNodes = {};
260
+ for (const key of Object.keys(branches)) {
261
+ const branch = appendChildNode(nextState, parallel.node.id, "branch", key, {
262
+ branchKey: key
263
+ });
264
+ nextState = branch.state;
265
+ branchNodes[key] = branch.node;
266
+ }
267
+ nextState = withTerminalNodes(
268
+ nextState,
269
+ Object.values(branchNodes).map((node) => node.id)
270
+ );
271
+ return new _PipelineBuilder(async (input, context) => {
272
+ const value = await this.runStep(input, context);
273
+ const entries = await runNode(
274
+ context,
275
+ parallel.node,
276
+ () => Promise.all(
277
+ Object.entries(branches).map(async ([key, op]) => {
278
+ const node = branchNodes[key];
279
+ const output = await runNode(context, node, () => op.run(value));
280
+ return [key, output];
281
+ })
282
+ )
283
+ );
284
+ return Object.fromEntries(entries);
285
+ }, nextState);
286
+ }
287
+ /** Send the current value to an agent as text and continue with the agent output. */
288
+ prompt(agent, metadata) {
289
+ const next = appendNode(this.state, "agent", metadata?.name ?? agent.name ?? agent.id, {
290
+ description: metadata?.description ?? agent.description,
291
+ metadata: metadata?.metadata,
292
+ preferredId: metadata?.id,
293
+ agentId: agent.id,
294
+ agentName: agent.name
295
+ });
296
+ return new _PipelineBuilder(async (input, context) => {
297
+ const value = await this.runStep(input, context);
298
+ return runNode(context, next.node, async () => {
299
+ const response = await agent.prompt(String(value)).send();
300
+ return response.output;
301
+ });
302
+ }, next.state);
303
+ }
304
+ /** Send the current value to an extractor as text and continue with typed schema data. */
305
+ extract(extractor, metadata) {
306
+ const next = appendNode(
307
+ this.state,
308
+ "extractor",
309
+ metadata?.name ?? nextStageLabel(this.state, "Extractor"),
310
+ {
311
+ description: metadata?.description,
312
+ metadata: metadata?.metadata,
313
+ preferredId: metadata?.id
314
+ }
315
+ );
316
+ return new _PipelineBuilder(async (input, context) => {
317
+ const value = await this.runStep(input, context);
318
+ return runNode(context, next.node, () => extractor.extract(String(value)));
319
+ }, next.state);
320
+ }
321
+ /** Finish the builder and return a runnable pipeline. */
322
+ build() {
323
+ const graph = withOutputNode(this.state);
324
+ return new Pipeline(
325
+ (input, context) => this.runStep(input, context),
326
+ graph
327
+ );
328
+ }
329
+ async runStep(input, context) {
330
+ return await this.executor(input, context);
331
+ }
332
+ };
333
+ function identity(input) {
334
+ return input;
335
+ }
5
336
  export {
6
337
  Pipeline,
7
338
  PipelineBuilder
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../../src/pipeline/graph.ts","../../src/pipeline/pipeline.ts","../../src/pipeline/runtime.ts","../../src/pipeline/builder.ts"],"sourcesContent":["import type { JsonObject } from \"../completion\";\nimport type {\n PipelineBuilderState,\n PipelineGraph,\n PipelineGraphNode,\n PipelineMetadata,\n PipelineStageKind,\n} from \"./types\";\n\nexport function initialBuilderState(metadata: PipelineMetadata): PipelineBuilderState {\n return {\n graph: initialGraph(metadata),\n terminalNodeId: \"input\",\n terminalNodeIds: [\"input\"],\n nextNodeIndex: 1,\n nextEdgeIndex: 1,\n };\n}\n\nexport function initialGraph(metadata: PipelineMetadata): PipelineGraph {\n const id = normalizeId(metadata.id ?? \"pipeline\");\n return {\n id,\n ...(metadata.name === undefined ? {} : { name: metadata.name }),\n ...(metadata.description === undefined ? {} : { description: metadata.description }),\n ...(metadata.metadata === undefined ? {} : { metadata: metadata.metadata }),\n nodes: [{ id: \"input\", kind: \"input\", label: \"Input\" }],\n edges: [],\n };\n}\n\nexport function appendNode(\n state: PipelineBuilderState,\n kind: PipelineStageKind,\n label: string,\n options: {\n description?: string | undefined;\n metadata?: JsonObject | undefined;\n preferredId?: string | undefined;\n agentId?: string | undefined;\n agentName?: string | undefined;\n pipelineId?: string | undefined;\n } = {},\n): { state: PipelineBuilderState; node: PipelineGraphNode } {\n const node = graphNode(kind, label, state.nextNodeIndex, {\n ...options,\n existingIds: new Set(state.graph.nodes.map((item) => item.id)),\n });\n return {\n node,\n state: appendGraphNode(state, node, activeTerminalNodeIds(state), [node.id]),\n };\n}\n\nexport function appendChildNode(\n state: PipelineBuilderState,\n parentId: string,\n kind: PipelineStageKind,\n label: string,\n options: {\n branchKey?: string | undefined;\n } = {},\n): { state: PipelineBuilderState; node: PipelineGraphNode } {\n const node = graphNode(kind, label, state.nextNodeIndex, {\n ...options,\n existingIds: new Set(state.graph.nodes.map((item) => item.id)),\n });\n return {\n node,\n state: appendGraphNode(state, node, [parentId], activeTerminalNodeIds(state)),\n };\n}\n\nexport function activeTerminalNodeIds(state: PipelineBuilderState): string[] {\n return state.terminalNodeIds.length > 0 ? state.terminalNodeIds : [state.terminalNodeId];\n}\n\nexport function withTerminalNodes(\n state: PipelineBuilderState,\n terminalNodeIds: string[],\n): PipelineBuilderState {\n return {\n ...state,\n terminalNodeId: terminalNodeIds.at(-1) ?? state.terminalNodeId,\n terminalNodeIds,\n };\n}\n\nexport function withOutputNode(state: PipelineBuilderState): PipelineGraph {\n const graph = cloneGraph(state.graph);\n if (graph.nodes.some((node) => node.id === \"output\")) {\n return graph;\n }\n graph.nodes.push({ id: \"output\", kind: \"output\", label: \"Output\" });\n graph.edges.push(\n ...activeTerminalNodeIds(state).map((sourceId, index) => ({\n id: `edge_${state.nextEdgeIndex + index}`,\n source: sourceId,\n target: \"output\",\n })),\n );\n return graph;\n}\n\nexport function nextStageLabel(state: PipelineBuilderState, prefix: string): string {\n return `${prefix} ${state.nextNodeIndex}`;\n}\n\nexport function cloneGraph(graph: PipelineGraph): PipelineGraph {\n return {\n ...graph,\n nodes: graph.nodes.map((node) => ({ ...node })),\n edges: graph.edges.map((edge) => ({ ...edge })),\n };\n}\n\nfunction appendGraphNode(\n state: PipelineBuilderState,\n node: PipelineGraphNode,\n sourceIds: string[],\n terminalNodeIds: string[],\n): PipelineBuilderState {\n const edges = sourceIds.map((sourceId, index) => ({\n id: `edge_${state.nextEdgeIndex + index}`,\n source: sourceId,\n target: node.id,\n }));\n const terminalNodeId = terminalNodeIds.at(-1) ?? state.terminalNodeId;\n return {\n graph: {\n ...state.graph,\n nodes: [...state.graph.nodes, node],\n edges: [...state.graph.edges, ...edges],\n },\n terminalNodeId,\n terminalNodeIds,\n nextNodeIndex: state.nextNodeIndex + 1,\n nextEdgeIndex: state.nextEdgeIndex + edges.length,\n };\n}\n\nfunction graphNode(\n kind: PipelineStageKind,\n label: string,\n index: number,\n options: {\n description?: string | undefined;\n metadata?: JsonObject | undefined;\n preferredId?: string | undefined;\n agentId?: string | undefined;\n agentName?: string | undefined;\n pipelineId?: string | undefined;\n branchKey?: string | undefined;\n existingIds?: Set<string> | undefined;\n } = {},\n): PipelineGraphNode {\n const id = uniqueGraphNodeId(\n normalizeId(options.preferredId ?? `${kind}_${index}`),\n options.existingIds ?? new Set(),\n );\n return {\n id,\n kind,\n label,\n ...(options.description === undefined ? {} : { description: options.description }),\n ...(options.metadata === undefined ? {} : { metadata: options.metadata }),\n ...(options.agentId === undefined ? {} : { agentId: options.agentId }),\n ...(options.agentName === undefined ? {} : { agentName: options.agentName }),\n ...(options.pipelineId === undefined ? {} : { pipelineId: options.pipelineId }),\n ...(options.branchKey === undefined ? {} : { branchKey: options.branchKey }),\n };\n}\n\nfunction normalizeId(value: string): string {\n const normalized = value\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9_-]+/g, \"_\")\n .replace(/^_+|_+$/g, \"\");\n return normalized.length === 0 ? \"pipeline\" : normalized;\n}\n\nfunction uniqueGraphNodeId(baseId: string, existingIds: Set<string>): string {\n let id = baseId;\n let suffix = 2;\n while (existingIds.has(id)) {\n id = `${baseId}_${suffix}`;\n suffix += 1;\n }\n return id;\n}\n","import type { JsonObject } from \"../completion\";\nimport { mapWithConcurrency } from \"../internal/concurrency\";\nimport { cloneGraph, initialGraph } from \"./graph\";\nimport type {\n PipelineBatchOptions,\n PipelineExecutor,\n PipelineGraph,\n PipelineOp,\n PipelineRunOptions,\n} from \"./types\";\n\n/** Runnable pipeline returned by `PipelineBuilder.build()`. */\nexport class Pipeline<Input, Output> implements PipelineOp<Input, Awaited<Output>> {\n readonly id: string;\n readonly name: string | undefined;\n readonly description: string | undefined;\n readonly metadata: JsonObject | undefined;\n\n constructor(\n private readonly executor: PipelineExecutor<Input, Output>,\n private readonly pipelineGraph: PipelineGraph = initialGraph({}),\n ) {\n this.id = pipelineGraph.id;\n this.name = pipelineGraph.name;\n this.description = pipelineGraph.description;\n this.metadata = pipelineGraph.metadata;\n }\n\n /** Run one input through the built pipeline and return the final stage output. */\n async run(input: Input, options: PipelineRunOptions = {}): Promise<Awaited<Output>> {\n return (await this.executor(input, { observer: options.observer })) as Awaited<Output>;\n }\n\n /** Run many inputs through the same pipeline with bounded concurrency. */\n async batch<I extends Iterable<Input>>(\n inputs: I,\n options: PipelineBatchOptions,\n ): Promise<Array<Awaited<Output>>> {\n return mapWithConcurrency([...inputs], options.concurrency, (input) => this.run(input));\n }\n\n graph(): PipelineGraph {\n return cloneGraph(this.pipelineGraph);\n }\n}\n","import type { PipelineGraphNode, PipelineRunContext } from \"./types\";\n\nexport async function runNode<Output>(\n context: PipelineRunContext,\n node: PipelineGraphNode,\n fn: () => Output | Promise<Output>,\n): Promise<Awaited<Output>> {\n const startedAt = Date.now();\n await context.observer?.onEvent({ type: \"stage_started\", node });\n try {\n const output = (await fn()) as Awaited<Output>;\n await context.observer?.onEvent({\n type: \"stage_completed\",\n node,\n durationMs: Date.now() - startedAt,\n });\n return output;\n } catch (error) {\n await context.observer?.onEvent({\n type: \"stage_failed\",\n node,\n durationMs: Date.now() - startedAt,\n error,\n });\n throw error;\n }\n}\n","import type { Agent } from \"../agent/agent\";\nimport type { CompletionModel } from \"../completion\";\nimport type { Extractor } from \"../extractor\";\nimport {\n appendChildNode,\n appendNode,\n initialBuilderState,\n nextStageLabel,\n withOutputNode,\n withTerminalNodes,\n} from \"./graph\";\nimport { Pipeline } from \"./pipeline\";\nimport { runNode } from \"./runtime\";\nimport type {\n ParallelOutput,\n PipelineBuilderState,\n PipelineExecutor,\n PipelineGraphNode,\n PipelineMetadata,\n PipelineOp,\n PipelineRunContext,\n PipelineStageMetadata,\n} from \"./types\";\n\n/** Builds a typed pipeline from an original input type to an inferred output type. */\nexport class PipelineBuilder<Input, Output = Input> {\n private readonly executor: PipelineExecutor<Input, Output>;\n private readonly state: PipelineBuilderState;\n\n constructor();\n constructor(metadata: PipelineMetadata);\n constructor(executor: (input: Input) => Output | Promise<Output>);\n constructor(executor: PipelineExecutor<Input, Output>, state: PipelineBuilderState);\n constructor(\n metadataOrExecutor?:\n | PipelineMetadata\n | ((input: Input) => Output | Promise<Output>)\n | PipelineExecutor<Input, Output>,\n state?: PipelineBuilderState,\n ) {\n if (state !== undefined) {\n this.executor = metadataOrExecutor as PipelineExecutor<Input, Output>;\n this.state = state;\n return;\n }\n\n if (typeof metadataOrExecutor === \"function\") {\n const executor = metadataOrExecutor as (input: Input) => Output | Promise<Output>;\n this.executor = ((input) => executor(input)) as PipelineExecutor<Input, Output>;\n this.state = initialBuilderState({});\n return;\n }\n\n this.executor = identity as PipelineExecutor<Input, Output>;\n this.state = initialBuilderState(metadataOrExecutor ?? {});\n }\n\n /** Add a synchronous or asynchronous transform stage. */\n step<Next>(\n fn: (input: Awaited<Output>) => Next | Promise<Next>,\n metadata?: PipelineStageMetadata,\n ): PipelineBuilder<Input, Awaited<Next>> {\n const next = appendNode(\n this.state,\n \"step\",\n metadata?.name ?? nextStageLabel(this.state, \"Step\"),\n {\n description: metadata?.description,\n metadata: metadata?.metadata,\n preferredId: metadata?.id,\n },\n );\n return new PipelineBuilder<Input, Awaited<Next>>(\n async (input, context): Promise<Awaited<Next>> => {\n const value = await this.runStep(input, context);\n const result = await runNode(context, next.node, () => fn(value));\n return result as Awaited<Next>;\n },\n next.state,\n );\n }\n\n /** Compose another pipeline operation after the current stage. */\n use<Next>(\n op: PipelineOp<Awaited<Output>, Next>,\n metadata?: PipelineStageMetadata,\n ): PipelineBuilder<Input, Awaited<Next>> {\n const nested = op instanceof Pipeline ? op : undefined;\n const next = appendNode(\n this.state,\n nested === undefined ? \"step\" : \"pipeline\",\n metadata?.name ??\n nested?.name ??\n nested?.id ??\n nextStageLabel(this.state, nested === undefined ? \"Operation\" : \"Pipeline\"),\n {\n description: metadata?.description ?? nested?.description,\n metadata: metadata?.metadata ?? nested?.metadata,\n preferredId: metadata?.id,\n pipelineId: nested?.id,\n },\n );\n return new PipelineBuilder<Input, Awaited<Next>>(\n async (input, context): Promise<Awaited<Next>> => {\n const value = await this.runStep(input, context);\n const result = await runNode(context, next.node, () => op.run(value));\n return result as Awaited<Next>;\n },\n next.state,\n );\n }\n\n /** Run named branch operations concurrently from the current value. */\n parallel<Branches extends Record<string, PipelineOp<Awaited<Output>, unknown>>>(\n branches: Branches,\n metadata?: PipelineStageMetadata,\n ): PipelineBuilder<Input, ParallelOutput<Branches>> {\n const parallel = appendNode(\n this.state,\n \"parallel\",\n metadata?.name ?? `${Object.keys(branches).length} parallel branches`,\n {\n description: metadata?.description,\n metadata: metadata?.metadata,\n preferredId: metadata?.id,\n },\n );\n let nextState = parallel.state;\n const branchNodes: Record<string, PipelineGraphNode> = {};\n for (const key of Object.keys(branches)) {\n const branch = appendChildNode(nextState, parallel.node.id, \"branch\", key, {\n branchKey: key,\n });\n nextState = branch.state;\n branchNodes[key] = branch.node;\n }\n nextState = withTerminalNodes(\n nextState,\n Object.values(branchNodes).map((node) => node.id),\n );\n\n return new PipelineBuilder<Input, ParallelOutput<Branches>>(async (input, context) => {\n const value = await this.runStep(input, context);\n const entries = await runNode(context, parallel.node, () =>\n Promise.all(\n Object.entries(branches).map(async ([key, op]) => {\n const node = branchNodes[key] as PipelineGraphNode;\n const output = await runNode(context, node, () => op.run(value));\n return [key, output] as const;\n }),\n ),\n );\n return Object.fromEntries(entries) as ParallelOutput<Branches>;\n }, nextState);\n }\n\n /** Send the current value to an agent as text and continue with the agent output. */\n prompt(\n agent: Agent<CompletionModel>,\n metadata?: PipelineStageMetadata,\n ): PipelineBuilder<Input, string> {\n const next = appendNode(this.state, \"agent\", metadata?.name ?? agent.name ?? agent.id, {\n description: metadata?.description ?? agent.description,\n metadata: metadata?.metadata,\n preferredId: metadata?.id,\n agentId: agent.id,\n agentName: agent.name,\n });\n return new PipelineBuilder<Input, string>(async (input, context) => {\n const value = await this.runStep(input, context);\n return runNode(context, next.node, async () => {\n const response = await agent.prompt(String(value)).send();\n return response.output;\n });\n }, next.state);\n }\n\n /** Send the current value to an extractor as text and continue with typed schema data. */\n extract<T>(\n extractor: Extractor<T, CompletionModel>,\n metadata?: PipelineStageMetadata,\n ): PipelineBuilder<Input, T> {\n const next = appendNode(\n this.state,\n \"extractor\",\n metadata?.name ?? nextStageLabel(this.state, \"Extractor\"),\n {\n description: metadata?.description,\n metadata: metadata?.metadata,\n preferredId: metadata?.id,\n },\n );\n return new PipelineBuilder<Input, T>(async (input, context) => {\n const value = await this.runStep(input, context);\n return runNode(context, next.node, () => extractor.extract(String(value)));\n }, next.state);\n }\n\n /** Finish the builder and return a runnable pipeline. */\n build(): Pipeline<Input, Awaited<Output>> {\n const graph = withOutputNode(this.state);\n return new Pipeline<Input, Awaited<Output>>(\n (input, context) => this.runStep(input, context) as Promise<Awaited<Output>>,\n graph,\n );\n }\n\n private async runStep(input: Input, context: PipelineRunContext): Promise<Awaited<Output>> {\n return (await this.executor(input, context)) as Awaited<Output>;\n }\n}\n\nfunction identity<T>(input: T): T {\n return input;\n}\n"],"mappings":";;;;;AASO,SAAS,oBAAoB,UAAkD;AACpF,SAAO;AAAA,IACL,OAAO,aAAa,QAAQ;AAAA,IAC5B,gBAAgB;AAAA,IAChB,iBAAiB,CAAC,OAAO;AAAA,IACzB,eAAe;AAAA,IACf,eAAe;AAAA,EACjB;AACF;AAEO,SAAS,aAAa,UAA2C;AACtE,QAAM,KAAK,YAAY,SAAS,MAAM,UAAU;AAChD,SAAO;AAAA,IACL;AAAA,IACA,GAAI,SAAS,SAAS,SAAY,CAAC,IAAI,EAAE,MAAM,SAAS,KAAK;AAAA,IAC7D,GAAI,SAAS,gBAAgB,SAAY,CAAC,IAAI,EAAE,aAAa,SAAS,YAAY;AAAA,IAClF,GAAI,SAAS,aAAa,SAAY,CAAC,IAAI,EAAE,UAAU,SAAS,SAAS;AAAA,IACzE,OAAO,CAAC,EAAE,IAAI,SAAS,MAAM,SAAS,OAAO,QAAQ,CAAC;AAAA,IACtD,OAAO,CAAC;AAAA,EACV;AACF;AAEO,SAAS,WACd,OACA,MACA,OACA,UAOI,CAAC,GACqD;AAC1D,QAAM,OAAO,UAAU,MAAM,OAAO,MAAM,eAAe;AAAA,IACvD,GAAG;AAAA,IACH,aAAa,IAAI,IAAI,MAAM,MAAM,MAAM,IAAI,CAAC,SAAS,KAAK,EAAE,CAAC;AAAA,EAC/D,CAAC;AACD,SAAO;AAAA,IAC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,UAAU,UAAU;AAAA,QACpB,aAAa,UAAU;AAAA,MACzB;AAAA,IACF;AACA,WAAO,IAAI,iBAA0B,OAAO,OAAO,YAAY;AAC7D,YAAM,QAAQ,MAAM,KAAK,QAAQ,OAAO,OAAO;AAC/C,aAAO,QAAQ,SAAS,KAAK,MAAM,MAAM,UAAU,QAAQ,OAAO,KAAK,CAAC,CAAC;AAAA,IAC3E,GAAG,KAAK,KAAK;AAAA,EACf;AAAA;AAAA,EAGA,QAA0C;AACxC,UAAM,QAAQ,eAAe,KAAK,KAAK;AACvC,WAAO,IAAI;AAAA,MACT,CAAC,OAAO,YAAY,KAAK,QAAQ,OAAO,OAAO;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAc,QAAQ,OAAc,SAAuD;AACzF,WAAQ,MAAM,KAAK,SAAS,OAAO,OAAO;AAAA,EAC5C;AACF;AAEA,SAAS,SAAY,OAAa;AAChC,SAAO;AACT;","names":[]}
@@ -1,7 +1,7 @@
1
- import { a as SkillLoader, b as SkillSet } from '../types-B0iXLkqi.js';
2
- export { S as Skill, c as SkillValidationError, d as SkillValidationIssue } from '../types-B0iXLkqi.js';
3
- import '../tool-ClZYES-Z.js';
4
- import '../types-BM8-Y8Hy.js';
1
+ import { b as SkillLoader, a as SkillSet } from '../types-T9rlOIUc.js';
2
+ export { c as Skill, S as SkillValidationError, d as SkillValidationIssue } from '../types-T9rlOIUc.js';
3
+ import '../tool-C3ciF-VG.js';
4
+ import '../types-C54aNoCd.js';
5
5
 
6
6
  declare function loadSkills(loaders: SkillLoader | SkillLoader[]): Promise<SkillSet>;
7
7
 
@@ -2,11 +2,12 @@ import {
2
2
  SkillValidationError,
3
3
  loadSkills,
4
4
  skill
5
- } from "../chunk-TILE6Z2N.js";
5
+ } from "../chunk-L6JCKFAX.js";
6
6
  import "../chunk-YK4WAAS4.js";
7
- import "../chunk-I2HOMD3R.js";
8
- import "../chunk-65QV627O.js";
9
- import "../chunk-A7VDIZQN.js";
7
+ import "../chunk-CY7SB5FG.js";
8
+ import "../chunk-OIA4CN5V.js";
9
+ import "../chunk-EFGX3EX5.js";
10
+ import "../chunk-OIMLU4SF.js";
10
11
  export {
11
12
  SkillValidationError,
12
13
  loadSkills,
@@ -0,0 +1,26 @@
1
+ import { z } from 'zod';
2
+ import { Z as ZodSchema } from './zod-schema-C7F4clpm.js';
3
+ import { b as ToolApprovalPolicy, c as ToolCallContext, T as Tool } from './tool-C3ciF-VG.js';
4
+
5
+ type CreateToolOptions<InputSchema extends ZodSchema, OutputSchema extends ZodSchema | undefined = undefined, Output = unknown> = {
6
+ name: string;
7
+ description: string;
8
+ input: InputSchema;
9
+ output?: OutputSchema;
10
+ approval?: ToolApprovalPolicy<z.output<InputSchema>>;
11
+ execute(args: z.output<InputSchema>, context: ToolCallContext): OutputSchema extends ZodSchema ? z.input<OutputSchema> | Promise<z.input<OutputSchema>> : Output | Promise<Output>;
12
+ };
13
+ declare function createTool<InputSchema extends ZodSchema, Output = unknown>(options: CreateToolOptions<InputSchema, undefined, Output> & {
14
+ output?: undefined;
15
+ }): Tool<z.output<InputSchema>, Output>;
16
+ declare function createTool<InputSchema extends ZodSchema, OutputSchema extends ZodSchema>(options: CreateToolOptions<InputSchema, OutputSchema>): Tool<z.output<InputSchema>, z.output<OutputSchema>>;
17
+
18
+ type CreateThinkToolOptions = {
19
+ name?: string;
20
+ description?: string;
21
+ };
22
+ declare function createThinkTool(options?: CreateThinkToolOptions): Tool<{
23
+ thought: string;
24
+ }, string>;
25
+
26
+ export { type CreateToolOptions as C, createTool as a, type CreateThinkToolOptions as b, createThinkTool as c };
@@ -1,25 +1,12 @@
1
- import { z } from 'zod';
2
- import { Z as ZodSchema } from '../middleware-2FR89muX.js';
3
- export { D as DynamicToolIndex, E as EmbedToolsOptions, T as ToolMiddleware, a as ToolResultMiddlewareArgs, b as ToolSearchDocument, c as ToolSet, d as createToolIndex, e as createToolMiddleware, f as embedTools, i as isDynamicToolIndex } from '../middleware-2FR89muX.js';
4
- import { b as ToolApprovalPolicy, d as ToolCallContext, T as Tool } from '../tool-ClZYES-Z.js';
5
- export { A as AnyTool, N as NormalizedToolOutput, a as ToolApprovalContext, c as ToolApprovalRunContext, e as ToolCallStreamEvent, f as ToolOutput, i as isToolResultContentArray, n as normalizeToolResultOutput, p as parseToolArgs, s as serializeToolOutput, t as toolResultContentToText } from '../tool-ClZYES-Z.js';
6
- import '../types-BM8-Y8Hy.js';
7
- import '../embeddings/index.js';
1
+ export { b as CreateThinkToolOptions, C as CreateToolOptions, c as createThinkTool, a as createTool } from '../think-tool-ByArsrxe.js';
2
+ export { D as DynamicToolIndex, E as EmbedToolsOptions, T as ToolMiddleware, a as ToolResultMiddlewareArgs, b as ToolSearchDocument, c as ToolSet, d as createToolIndex, e as createToolMiddleware, f as embedTools, i as isDynamicToolIndex } from '../middleware-CGiEIaBx.js';
3
+ export { A as AnyTool, N as NormalizedToolOutput, T as Tool, a as ToolApprovalContext, b as ToolApprovalPolicy, e as ToolApprovalRunContext, c as ToolCallContext, d as ToolCallStreamEvent, f as ToolOutput, i as isToolResultContentArray, n as normalizeToolResultOutput, p as parseToolArgs, s as serializeToolOutput, t as toolResultContentToText } from '../tool-C3ciF-VG.js';
4
+ import 'zod';
5
+ import '../zod-schema-C7F4clpm.js';
6
+ import '../types-C54aNoCd.js';
7
+ import '../types-IB2e9u5M.js';
8
8
  import '../vector-store/index.js';
9
9
 
10
- type CreateToolOptions<InputSchema extends ZodSchema, OutputSchema extends ZodSchema | undefined = undefined, Output = unknown> = {
11
- name: string;
12
- description: string;
13
- input: InputSchema;
14
- output?: OutputSchema;
15
- approval?: ToolApprovalPolicy<z.output<InputSchema>>;
16
- execute(args: z.output<InputSchema>, context: ToolCallContext): OutputSchema extends ZodSchema ? z.input<OutputSchema> | Promise<z.input<OutputSchema>> : Output | Promise<Output>;
17
- };
18
- declare function createTool<InputSchema extends ZodSchema, Output = unknown>(options: CreateToolOptions<InputSchema, undefined, Output> & {
19
- output?: undefined;
20
- }): Tool<z.output<InputSchema>, Output>;
21
- declare function createTool<InputSchema extends ZodSchema, OutputSchema extends ZodSchema>(options: CreateToolOptions<InputSchema, OutputSchema>): Tool<z.output<InputSchema>, z.output<OutputSchema>>;
22
-
23
10
  declare class ToolCallError extends Error {
24
11
  readonly cause?: unknown | undefined;
25
12
  constructor(message: string, cause?: unknown | undefined);
@@ -33,12 +20,4 @@ declare class ToolJsonError extends Error {
33
20
  constructor(message: string, cause?: unknown | undefined);
34
21
  }
35
22
 
36
- type CreateThinkToolOptions = {
37
- name?: string;
38
- description?: string;
39
- };
40
- declare function createThinkTool(options?: CreateThinkToolOptions): Tool<{
41
- thought: string;
42
- }, string>;
43
-
44
- export { type CreateThinkToolOptions, type CreateToolOptions, Tool, ToolApprovalPolicy, ToolCallContext, ToolCallError, ToolJsonError, ToolNotFoundError, createThinkTool, createTool };
23
+ export { ToolCallError, ToolJsonError, ToolNotFoundError };
@@ -14,11 +14,12 @@ import {
14
14
  parseToolArgs,
15
15
  serializeToolOutput,
16
16
  toolResultContentToText
17
- } from "../chunk-I2HOMD3R.js";
17
+ } from "../chunk-CY7SB5FG.js";
18
18
  import {
19
19
  createTool
20
- } from "../chunk-65QV627O.js";
21
- import "../chunk-A7VDIZQN.js";
20
+ } from "../chunk-OIA4CN5V.js";
21
+ import "../chunk-EFGX3EX5.js";
22
+ import "../chunk-OIMLU4SF.js";
22
23
  export {
23
24
  ToolCallError,
24
25
  ToolJsonError,
@@ -1,4 +1,4 @@
1
- import { J as JsonObject, q as ToolDefinition, u as ToolResultContent, j as JsonValue } from './types-BM8-Y8Hy.js';
1
+ import { J as JsonObject, g as ToolDefinition, j as ToolResultContent, e as JsonValue } from './types-C54aNoCd.js';
2
2
 
3
3
  type ToolApprovalRunContext = {
4
4
  agentId: string;
@@ -47,4 +47,4 @@ declare function normalizeToolResultOutput(output: unknown): NormalizedToolOutpu
47
47
  declare function toolResultContentToText(content: ToolResultContent[]): string;
48
48
  declare function parseToolArgs(args: string): JsonValue;
49
49
 
50
- export { type AnyTool as A, type NormalizedToolOutput as N, type Tool as T, type ToolApprovalContext as a, type ToolApprovalPolicy as b, type ToolApprovalRunContext as c, type ToolCallContext as d, type ToolCallStreamEvent as e, ToolOutput as f, isToolResultContentArray as i, normalizeToolResultOutput as n, parseToolArgs as p, serializeToolOutput as s, toolResultContentToText as t };
50
+ export { type AnyTool as A, type NormalizedToolOutput as N, type Tool as T, type ToolApprovalContext as a, type ToolApprovalPolicy as b, type ToolCallContext as c, type ToolCallStreamEvent as d, type ToolApprovalRunContext as e, ToolOutput as f, isToolResultContentArray as i, normalizeToolResultOutput as n, parseToolArgs as p, serializeToolOutput as s, toolResultContentToText as t };
@@ -1,4 +1,4 @@
1
- import { j as JsonValue } from '../types-BM8-Y8Hy.js';
1
+ import { e as JsonValue } from '../types-C54aNoCd.js';
2
2
 
3
3
  type TranscriptionRequest = {
4
4
  data: Uint8Array;
@@ -1,7 +1,58 @@
1
- import {
2
- TranscriptionRequestBuilder,
3
- transcriptionRequest
4
- } from "../chunk-7QI6ZAFI.js";
1
+ // src/transcription/index.ts
2
+ var TranscriptionRequestBuilder = class {
3
+ constructor(model) {
4
+ this.model = model;
5
+ }
6
+ model;
7
+ request = {
8
+ data: new Uint8Array(),
9
+ filename: "file"
10
+ };
11
+ data(data) {
12
+ this.request = { ...this.request, data: toUint8Array(data) };
13
+ return this;
14
+ }
15
+ filename(filename) {
16
+ this.request = { ...this.request, filename };
17
+ return this;
18
+ }
19
+ language(language) {
20
+ this.request = { ...this.request, language };
21
+ return this;
22
+ }
23
+ prompt(prompt) {
24
+ this.request = { ...this.request, prompt };
25
+ return this;
26
+ }
27
+ temperature(temperature) {
28
+ this.request = { ...this.request, temperature };
29
+ return this;
30
+ }
31
+ additionalParams(additionalParams) {
32
+ this.request = { ...this.request, additionalParams };
33
+ return this;
34
+ }
35
+ build() {
36
+ if (this.request.data.byteLength === 0) {
37
+ throw new Error("Transcription data cannot be empty.");
38
+ }
39
+ return { ...this.request, data: toUint8Array(this.request.data) };
40
+ }
41
+ send() {
42
+ return this.model.transcription(this.build());
43
+ }
44
+ };
45
+ function transcriptionRequest(model) {
46
+ return new TranscriptionRequestBuilder(model);
47
+ }
48
+ function toUint8Array(bytes) {
49
+ if (bytes instanceof Uint8Array) {
50
+ return new Uint8Array(
51
+ bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength)
52
+ );
53
+ }
54
+ return new Uint8Array(bytes);
55
+ }
5
56
  export {
6
57
  TranscriptionRequestBuilder,
7
58
  transcriptionRequest
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../../src/transcription/index.ts"],"sourcesContent":["import type { JsonValue } from \"../completion\";\n\nexport type TranscriptionRequest = {\n data: Uint8Array;\n filename: string;\n language?: string | undefined;\n prompt?: string | undefined;\n temperature?: number | undefined;\n additionalParams?: JsonValue | undefined;\n};\n\nexport type TranscriptionResponse<RawResponse = unknown> = {\n text: string;\n rawResponse: RawResponse;\n};\n\nexport interface TranscriptionModel<RawResponse = unknown> {\n readonly provider?: string | undefined;\n readonly defaultModel?: string | undefined;\n transcription(request: TranscriptionRequest): Promise<TranscriptionResponse<RawResponse>>;\n}\n\nexport class TranscriptionRequestBuilder<Model extends TranscriptionModel = TranscriptionModel> {\n private request: TranscriptionRequest = {\n data: new Uint8Array(),\n filename: \"file\",\n };\n\n constructor(private readonly model: Model) {}\n\n data(data: Uint8Array | ArrayBuffer): this {\n this.request = { ...this.request, data: toUint8Array(data) };\n return this;\n }\n\n filename(filename: string): this {\n this.request = { ...this.request, filename };\n return this;\n }\n\n language(language: string): this {\n this.request = { ...this.request, language };\n return this;\n }\n\n prompt(prompt: string): this {\n this.request = { ...this.request, prompt };\n return this;\n }\n\n temperature(temperature: number): this {\n this.request = { ...this.request, temperature };\n return this;\n }\n\n additionalParams(additionalParams: JsonValue): this {\n this.request = { ...this.request, additionalParams };\n return this;\n }\n\n build(): TranscriptionRequest {\n if (this.request.data.byteLength === 0) {\n throw new Error(\"Transcription data cannot be empty.\");\n }\n return { ...this.request, data: toUint8Array(this.request.data) };\n }\n\n send(): Promise<Awaited<ReturnType<Model[\"transcription\"]>>> {\n return this.model.transcription(this.build()) as Promise<\n Awaited<ReturnType<Model[\"transcription\"]>>\n >;\n }\n}\n\nexport function transcriptionRequest<Model extends TranscriptionModel>(\n model: Model,\n): TranscriptionRequestBuilder<Model> {\n return new TranscriptionRequestBuilder(model);\n}\n\nfunction toUint8Array(bytes: Uint8Array | ArrayBuffer): Uint8Array {\n if (bytes instanceof Uint8Array) {\n return new Uint8Array(\n bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength),\n );\n }\n return new Uint8Array(bytes);\n}\n"],"mappings":";AAsBO,IAAM,8BAAN,MAAyF;AAAA,EAM9F,YAA6B,OAAc;AAAd;AAAA,EAAe;AAAA,EAAf;AAAA,EALrB,UAAgC;AAAA,IACtC,MAAM,IAAI,WAAW;AAAA,IACrB,UAAU;AAAA,EACZ;AAAA,EAIA,KAAK,MAAsC;AACzC,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,MAAM,aAAa,IAAI,EAAE;AAC3D,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,UAAwB;AAC/B,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,SAAS;AAC3C,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,UAAwB;AAC/B,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,SAAS;AAC3C,WAAO;AAAA,EACT;AAAA,EAEA,OAAO,QAAsB;AAC3B,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,OAAO;AACzC,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,aAA2B;AACrC,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,YAAY;AAC9C,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,kBAAmC;AAClD,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,iBAAiB;AACnD,WAAO;AAAA,EACT;AAAA,EAEA,QAA8B;AAC5B,QAAI,KAAK,QAAQ,KAAK,eAAe,GAAG;AACtC,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AACA,WAAO,EAAE,GAAG,KAAK,SAAS,MAAM,aAAa,KAAK,QAAQ,IAAI,EAAE;AAAA,EAClE;AAAA,EAEA,OAA6D;AAC3D,WAAO,KAAK,MAAM,cAAc,KAAK,MAAM,CAAC;AAAA,EAG9C;AACF;AAEO,SAAS,qBACd,OACoC;AACpC,SAAO,IAAI,4BAA4B,KAAK;AAC9C;AAEA,SAAS,aAAa,OAA6C;AACjE,MAAI,iBAAiB,YAAY;AAC/B,WAAO,IAAI;AAAA,MACT,MAAM,OAAO,MAAM,MAAM,YAAY,MAAM,aAAa,MAAM,UAAU;AAAA,IAC1E;AAAA,EACF;AACA,SAAO,IAAI,WAAW,KAAK;AAC7B;","names":[]}
@@ -250,4 +250,4 @@ declare function assertCompletionRequestSupported(model: CompletionModel, reques
250
250
  }): void;
251
251
  declare function textFromAssistantContent(content: AssistantContent[]): string;
252
252
 
253
- export { AssistantContent as A, CompletionCapabilityError as C, type Document as D, type ImageContent as I, type JsonObject as J, Message as M, type Reasoning as R, type StreamingCompletionModel as S, type Text as T, Usage as U, type AssistantMessage as a, type CompletionModel as b, type CompletionModelCapabilities as c, type CompletionRequest as d, type CompletionResponse as e, type CompletionStreamEvent as f, type DocumentContent as g, type ImageDetail as h, type JsonPrimitive as i, type JsonValue as j, type ReasoningContent as k, type ReasoningContentType as l, type SystemMessage as m, type ToolCall as n, type ToolChoice as o, ToolContent as p, type ToolDefinition as q, type ToolFunction as r, type ToolMessage as s, type ToolResult as t, type ToolResultContent as u, UserContent as v, type UserMessage as w, assertCompletionRequestSupported as x, reasoningDisplayText as y, textFromAssistantContent as z };
253
+ export { AssistantContent as A, type CompletionModel as C, type Document as D, type ImageContent as I, type JsonObject as J, Message as M, type Reasoning as R, type SystemMessage as S, type Text as T, Usage as U, type AssistantMessage as a, type CompletionRequest as b, type CompletionResponse as c, type JsonPrimitive as d, type JsonValue as e, type ToolCall as f, type ToolDefinition as g, type ToolMessage as h, type ToolResult as i, type ToolResultContent as j, UserContent as k, type UserMessage as l, type ToolChoice as m, CompletionCapabilityError as n, type CompletionModelCapabilities as o, type CompletionStreamEvent as p, type DocumentContent as q, type ImageDetail as r, type ReasoningContent as s, type ReasoningContentType as t, type StreamingCompletionModel as u, ToolContent as v, type ToolFunction as w, assertCompletionRequestSupported as x, reasoningDisplayText as y, textFromAssistantContent as z };
@@ -0,0 +1,25 @@
1
+ type Embedding = {
2
+ document: string;
3
+ vector: number[];
4
+ };
5
+ interface EmbeddingModel {
6
+ readonly dimensions?: number | undefined;
7
+ readonly maxBatchSize?: number | undefined;
8
+ embedTexts(texts: string[]): Promise<Embedding[]>;
9
+ }
10
+ type EmbeddedDocument<T, Metadata extends VectorMetadata = VectorMetadata> = {
11
+ id: string;
12
+ document: T;
13
+ metadata?: Metadata | undefined;
14
+ embeddings: Embedding[];
15
+ };
16
+ type VectorMetadataValue = string | number | boolean | null;
17
+ type VectorMetadata = Record<string, VectorMetadataValue>;
18
+ type EmbedDocumentsOptions<T, Metadata extends VectorMetadata = VectorMetadata> = {
19
+ id?: ((document: T, index: number) => string) | undefined;
20
+ content(document: T, index: number): string | string[];
21
+ metadata?: ((document: T, index: number) => Metadata | undefined) | undefined;
22
+ concurrency?: number | undefined;
23
+ };
24
+
25
+ export type { EmbeddingModel as E, VectorMetadata as V, EmbedDocumentsOptions as a, EmbeddedDocument as b, Embedding as c, VectorMetadataValue as d };