@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
package/README.md CHANGED
@@ -20,7 +20,7 @@ pnpm --filter @anvia/core build
20
20
 
21
21
  ```ts
22
22
  import { z } from "zod";
23
- import { AgentBuilder, ExtractorBuilder, PipelineBuilder, createTool } from "@anvia/core";
23
+ import { AgentBuilder, createTool } from "@anvia/core";
24
24
  import { OpenAIClient } from "@anvia/openai";
25
25
 
26
26
  const client = new OpenAIClient({
@@ -72,13 +72,8 @@ await agent
72
72
  Configure durable conversation memory on the agent, then run through a session:
73
73
 
74
74
  ```ts
75
- import {
76
- AgentBuilder,
77
- type MemoryAppendInput,
78
- type MemoryContext,
79
- type MemoryStore,
80
- type Message,
81
- } from "@anvia/core";
75
+ import { AgentBuilder, type MemoryStore, type Message } from "@anvia/core";
76
+ import type { MemoryAppendInput, MemoryContext } from "@anvia/core/memory";
82
77
 
83
78
  class AppMemoryStore implements MemoryStore {
84
79
  private readonly sessions = new Map<string, Message[]>();
@@ -113,6 +108,8 @@ new AgentBuilder("support", model).memory(memory, { savePolicy: "turn" });
113
108
  ## Structured Extraction
114
109
 
115
110
  ```ts
111
+ import { ExtractorBuilder } from "@anvia/core/extractor";
112
+
116
113
  const ticketSchema = z.object({
117
114
  customer: z.string(),
118
115
  priority: z.enum(["low", "medium", "high"]),
@@ -129,6 +126,8 @@ const ticket = await extractor.extract(
129
126
  ## Pipelines
130
127
 
131
128
  ```ts
129
+ import { PipelineBuilder } from "@anvia/core/pipeline";
130
+
132
131
  const pipeline = new PipelineBuilder<string>()
133
132
  .step((input) => `Extract this support ticket:\n\n${input}`)
134
133
  .prompt(agent)
@@ -1,19 +1,19 @@
1
+ import { D as DynamicContextOptions, f as DynamicToolOptions, g as PromptHook, h as AgentEventStore, i as AgentEventStoreOptions, e as Agent } from '../agent-B-ls5y_g.js';
2
+ export { A as AgentChildStreamEvent, j as AgentEventAppendInput, k as AgentEventRecord, l as AgentEventStoreInclude, a as AgentStreamEvent, C as CompletionCallHookArgs, m as CompletionResponseHookArgs, H as HookAction, n as HookResult, P as PromptResponse, R as RunControl, T as ToolApprovalRequestOptions, o as ToolCallControl, p as ToolCallHookAction, q as ToolCallHookArgs, u as ToolCallHookResult, v as ToolHookArgs, w as ToolResultHookArgs, c as cancelPrompt, b as createHook, r as requestToolApproval, d as runControl, s as skipTool, t as toolCallControl } from '../agent-B-ls5y_g.js';
3
+ import { C as CompletionModel, e as JsonValue, m as ToolChoice, M as Message } from '../types-C54aNoCd.js';
4
+ import { a as McpServer } from '../types-UhcgW8Fo.js';
1
5
  import { MemoryStore, MemoryOptions } from '../memory/index.js';
2
- export { MemoryAppendInput, MemoryContext, MemoryErrorInput, MemoryRegistration, MemorySavePolicy, ResolvedMemoryOptions, SessionOptions, resolveMemoryOptions } from '../memory/index.js';
3
- import { m as DynamicContextOptions, o as DynamicToolOptions, P as PromptHook, d as AgentEventStore, f as AgentEventStoreOptions, A as Agent } from '../agent-D_jXqPAZ.js';
4
- export { a as AgentChildStreamEvent, b as AgentEventAppendInput, c as AgentEventRecord, e as AgentEventStoreInclude, g as AgentEventStoreRegistration, h as AgentOptions, i as AgentSession, j as AgentStreamEvent, k as AgentToolOptions, C as CompletionCallHookArgs, l as CompletionResponseHookArgs, D as DEFAULT_MAX_TURNS, n as DynamicContextRegistration, p as DynamicToolRegistration, H as HookAction, q as HookResult, r as PromptRequest, s as PromptResponse, R as RunControl, T as ToolApprovalRequestOptions, t as ToolCallControl, u as ToolCallHookAction, v as ToolCallHookArgs, w as ToolCallHookResult, x as ToolHookArgs, y as ToolResultHookArgs, z as cancelPrompt, B as createHook, E as requestToolApproval, F as runControl, G as skipTool, I as toolCallControl } from '../agent-D_jXqPAZ.js';
5
- import { b as CompletionModel, j as JsonValue, o as ToolChoice, M as Message } from '../types-BM8-Y8Hy.js';
6
- import { c as McpServer } from '../types-fLi8uM5R.js';
7
6
  import { AgentObserver, ObserveOptions } from '../observability/index.js';
8
- import { b as ToolSearchDocument, c as ToolSet, T as ToolMiddleware, Z as ZodSchema } from '../middleware-2FR89muX.js';
9
- import { b as SkillSet } from '../types-B0iXLkqi.js';
10
- import { A as AnyTool } from '../tool-ClZYES-Z.js';
7
+ import { Z as ZodSchema } from '../zod-schema-C7F4clpm.js';
8
+ import { a as SkillSet } from '../types-T9rlOIUc.js';
9
+ import { b as ToolSearchDocument, c as ToolSet, T as ToolMiddleware } from '../middleware-CGiEIaBx.js';
10
+ import { A as AnyTool } from '../tool-C3ciF-VG.js';
11
11
  import { VectorSearchIndex } from '../vector-store/index.js';
12
12
  import '@modelcontextprotocol/sdk/client/sse.js';
13
13
  import '@modelcontextprotocol/sdk/client/stdio.js';
14
14
  import '@modelcontextprotocol/sdk/client/streamableHttp.js';
15
15
  import 'zod';
16
- import '../embeddings/index.js';
16
+ import '../types-IB2e9u5M.js';
17
17
 
18
18
  declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
19
19
  private readonly completionModel;
@@ -77,4 +77,4 @@ declare class PromptCancelledError extends Error {
77
77
  constructor(chatHistory: Message[], reason: string);
78
78
  }
79
79
 
80
- export { Agent, AgentBuilder, AgentEventStore, AgentEventStoreOptions, DynamicContextOptions, DynamicToolOptions, MaxTurnsError, MemoryOptions, MemoryStore, PromptCancelledError, PromptHook };
80
+ export { AgentBuilder, AgentEventStore, AgentEventStoreOptions, MaxTurnsError, PromptCancelledError, PromptHook };
@@ -1,39 +1,31 @@
1
1
  import {
2
- Agent,
3
- AgentBuilder,
4
- AgentSession,
5
- DEFAULT_MAX_TURNS,
2
+ AgentBuilder
3
+ } from "../chunk-BD66WU2B.js";
4
+ import {
6
5
  MaxTurnsError,
7
6
  PromptCancelledError,
8
- PromptRequest,
9
7
  cancelPrompt,
10
8
  createHook,
11
9
  requestToolApproval,
12
10
  runControl,
13
11
  skipTool,
14
12
  toolCallControl
15
- } from "../chunk-GSFQZYS7.js";
16
- import {
17
- resolveMemoryOptions
18
- } from "../chunk-XXT2UCAR.js";
19
- import "../chunk-YK4WAAS4.js";
20
- import "../chunk-I2HOMD3R.js";
21
- import "../chunk-65QV627O.js";
13
+ } from "../chunk-TVIADATY.js";
22
14
  import "../chunk-XUUY2L2D.js";
15
+ import "../chunk-XXT2UCAR.js";
16
+ import "../chunk-YK4WAAS4.js";
17
+ import "../chunk-CY7SB5FG.js";
18
+ import "../chunk-OIA4CN5V.js";
23
19
  import "../chunk-6GJDBBDC.js";
24
- import "../chunk-A7VDIZQN.js";
20
+ import "../chunk-EFGX3EX5.js";
21
+ import "../chunk-OIMLU4SF.js";
25
22
  export {
26
- Agent,
27
23
  AgentBuilder,
28
- AgentSession,
29
- DEFAULT_MAX_TURNS,
30
24
  MaxTurnsError,
31
25
  PromptCancelledError,
32
- PromptRequest,
33
26
  cancelPrompt,
34
27
  createHook,
35
28
  requestToolApproval,
36
- resolveMemoryOptions,
37
29
  runControl,
38
30
  skipTool,
39
31
  toolCallControl
@@ -1,9 +1,9 @@
1
- import { M as Message, e as CompletionResponse, u as ToolResultContent, b as CompletionModel, U as Usage, l as ReasoningContentType, n as ToolCall, D as Document, j as JsonValue, o as ToolChoice, J as JsonObject } from './types-BM8-Y8Hy.js';
1
+ import { M as Message, c as CompletionResponse, j as ToolResultContent, C as CompletionModel, U as Usage, t as ReasoningContentType, f as ToolCall, D as Document, e as JsonValue, m as ToolChoice, J as JsonObject } from './types-C54aNoCd.js';
2
2
  import { MemoryContext, MemoryRegistration, SessionOptions } from './memory/index.js';
3
3
  import { AgentTraceOptions, AgentTraceInfo, AgentObserverRegistration } from './observability/index.js';
4
- import { T as ToolMiddleware, c as ToolSet, b as ToolSearchDocument } from './middleware-2FR89muX.js';
5
- import { T as Tool, A as AnyTool, d as ToolCallContext, N as NormalizedToolOutput } from './tool-ClZYES-Z.js';
6
- import { VectorSearchIndex, VectorFilter, VectorSearchResult } from './vector-store/index.js';
4
+ import { T as ToolMiddleware, c as ToolSet, b as ToolSearchDocument } from './middleware-CGiEIaBx.js';
5
+ import { T as Tool, A as AnyTool, c as ToolCallContext, N as NormalizedToolOutput } from './tool-C3ciF-VG.js';
6
+ import { VectorFilter, VectorSearchResult, VectorSearchIndex } from './vector-store/index.js';
7
7
 
8
8
  type HookAction = {
9
9
  type: "continue";
@@ -140,14 +140,13 @@ type AgentStreamEvent<RawResponse = unknown> = AgentChildStreamEvent<RawResponse
140
140
  declare class PromptRequest<M extends CompletionModel = CompletionModel> {
141
141
  private readonly agent;
142
142
  private readonly promptMessage;
143
- private readonly initialHistory;
144
- private readonly memoryContext;
145
143
  private chatHistory;
146
144
  private maxTurnCount;
147
145
  private activeHook;
148
146
  private concurrency;
149
147
  private traceOptions;
150
148
  private requestToolMiddlewares;
149
+ private readonly memoryRecorder;
151
150
  private constructor();
152
151
  static fromAgent<M extends CompletionModel>(agent: Agent<M>, prompt: string | Message | Message[], options?: {
153
152
  memoryContext?: MemoryContext | undefined;
@@ -163,24 +162,12 @@ declare class PromptRequest<M extends CompletionModel = CompletionModel> {
163
162
  readableStream(): ReadableStream<Uint8Array>;
164
163
  private runCompletion;
165
164
  private providerTraceRequest;
166
- private toolTraceMetadata;
167
165
  private executeToolCalls;
168
- private runToolResultMiddlewares;
169
166
  private startRunObservers;
170
167
  private recordAgentEvent;
171
- private fetchDynamicContext;
172
- private fetchToolDefinitions;
173
- private recordToolError;
174
168
  private runCompletionCallHook;
175
169
  private runCompletionResponseHook;
176
170
  private cancelled;
177
- private memory;
178
- private memoryPolicy;
179
- private prepareMemoryRun;
180
- private commitMemoryMessages;
181
- private commitCompletedMemoryTurn;
182
- private commitCompletedMemoryRun;
183
- private recordMemoryError;
184
171
  }
185
172
 
186
173
  type AgentOptions<M extends CompletionModel = CompletionModel> = {
@@ -301,4 +288,4 @@ declare class AgentSession<M extends CompletionModel = CompletionModel> {
301
288
  clear(): Promise<void>;
302
289
  }
303
290
 
304
- export { Agent as A, createHook as B, type CompletionCallHookArgs as C, DEFAULT_MAX_TURNS as D, requestToolApproval as E, runControl as F, skipTool as G, type HookAction as H, toolCallControl as I, type PromptHook as P, type RunControl as R, type ToolApprovalRequestOptions as T, type AgentChildStreamEvent as a, type AgentEventAppendInput as b, type AgentEventRecord as c, type AgentEventStore as d, type AgentEventStoreInclude as e, type AgentEventStoreOptions as f, type AgentEventStoreRegistration as g, type AgentOptions as h, AgentSession as i, type AgentStreamEvent as j, type AgentToolOptions as k, type CompletionResponseHookArgs as l, type DynamicContextOptions as m, type DynamicContextRegistration as n, type DynamicToolOptions as o, type DynamicToolRegistration as p, type HookResult as q, PromptRequest as r, type PromptResponse as s, type ToolCallControl as t, type ToolCallHookAction as u, type ToolCallHookArgs as v, type ToolCallHookResult as w, type ToolHookArgs as x, type ToolResultHookArgs as y, cancelPrompt as z };
291
+ export { type AgentChildStreamEvent as A, type AgentToolOptions as B, type CompletionCallHookArgs as C, type DynamicContextOptions as D, DEFAULT_MAX_TURNS as E, type DynamicContextRegistration as F, type DynamicToolRegistration as G, type HookAction as H, type PromptResponse as P, type RunControl as R, type ToolApprovalRequestOptions as T, type AgentStreamEvent as a, createHook as b, cancelPrompt as c, runControl as d, Agent as e, type DynamicToolOptions as f, type PromptHook as g, type AgentEventStore as h, type AgentEventStoreOptions as i, type AgentEventAppendInput as j, type AgentEventRecord as k, type AgentEventStoreInclude as l, type CompletionResponseHookArgs as m, type HookResult as n, type ToolCallControl as o, type ToolCallHookAction as p, type ToolCallHookArgs as q, requestToolApproval as r, skipTool as s, toolCallControl as t, type ToolCallHookResult as u, type ToolHookArgs as v, type ToolResultHookArgs as w, type AgentEventStoreRegistration as x, type AgentOptions as y, AgentSession as z };
@@ -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 AudioGenerationRequest = {
4
4
  text: string;
@@ -1,7 +1,40 @@
1
- import {
2
- AudioGenerationRequestBuilder,
3
- audioGenerationRequest
4
- } from "../chunk-I77SDTFE.js";
1
+ // src/audio-generation/index.ts
2
+ var AudioGenerationRequestBuilder = class {
3
+ constructor(model) {
4
+ this.model = model;
5
+ }
6
+ model;
7
+ request = {
8
+ text: "",
9
+ voice: "",
10
+ speed: 1
11
+ };
12
+ text(text) {
13
+ this.request = { ...this.request, text };
14
+ return this;
15
+ }
16
+ voice(voice) {
17
+ this.request = { ...this.request, voice };
18
+ return this;
19
+ }
20
+ speed(speed) {
21
+ this.request = { ...this.request, speed };
22
+ return this;
23
+ }
24
+ additionalParams(additionalParams) {
25
+ this.request = { ...this.request, additionalParams };
26
+ return this;
27
+ }
28
+ build() {
29
+ return { ...this.request };
30
+ }
31
+ send() {
32
+ return this.model.audioGeneration(this.build());
33
+ }
34
+ };
35
+ function audioGenerationRequest(model) {
36
+ return new AudioGenerationRequestBuilder(model);
37
+ }
5
38
  export {
6
39
  AudioGenerationRequestBuilder,
7
40
  audioGenerationRequest
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../../src/audio-generation/index.ts"],"sourcesContent":["import type { JsonValue } from \"../completion\";\n\nexport type AudioGenerationRequest = {\n text: string;\n voice: string;\n speed: number;\n additionalParams?: JsonValue | undefined;\n};\n\nexport type AudioGenerationResponse<RawResponse = unknown> = {\n audio: Uint8Array;\n mediaType?: string | undefined;\n rawResponse: RawResponse;\n};\n\nexport interface AudioGenerationModel<RawResponse = unknown> {\n readonly provider?: string | undefined;\n readonly defaultModel?: string | undefined;\n audioGeneration(request: AudioGenerationRequest): Promise<AudioGenerationResponse<RawResponse>>;\n}\n\nexport class AudioGenerationRequestBuilder<\n Model extends AudioGenerationModel = AudioGenerationModel,\n> {\n private request: AudioGenerationRequest = {\n text: \"\",\n voice: \"\",\n speed: 1,\n };\n\n constructor(private readonly model: Model) {}\n\n text(text: string): this {\n this.request = { ...this.request, text };\n return this;\n }\n\n voice(voice: string): this {\n this.request = { ...this.request, voice };\n return this;\n }\n\n speed(speed: number): this {\n this.request = { ...this.request, speed };\n return this;\n }\n\n additionalParams(additionalParams: JsonValue): this {\n this.request = { ...this.request, additionalParams };\n return this;\n }\n\n build(): AudioGenerationRequest {\n return { ...this.request };\n }\n\n send(): Promise<Awaited<ReturnType<Model[\"audioGeneration\"]>>> {\n return this.model.audioGeneration(this.build()) as Promise<\n Awaited<ReturnType<Model[\"audioGeneration\"]>>\n >;\n }\n}\n\nexport function audioGenerationRequest<Model extends AudioGenerationModel>(\n model: Model,\n): AudioGenerationRequestBuilder<Model> {\n return new AudioGenerationRequestBuilder(model);\n}\n"],"mappings":";AAqBO,IAAM,gCAAN,MAEL;AAAA,EAOA,YAA6B,OAAc;AAAd;AAAA,EAAe;AAAA,EAAf;AAAA,EANrB,UAAkC;AAAA,IACxC,MAAM;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EAIA,KAAK,MAAoB;AACvB,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,KAAK;AACvC,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,OAAqB;AACzB,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,MAAM;AACxC,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,OAAqB;AACzB,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,MAAM;AACxC,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,kBAAmC;AAClD,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,iBAAiB;AACnD,WAAO;AAAA,EACT;AAAA,EAEA,QAAgC;AAC9B,WAAO,EAAE,GAAG,KAAK,QAAQ;AAAA,EAC3B;AAAA,EAEA,OAA+D;AAC7D,WAAO,KAAK,MAAM,gBAAgB,KAAK,MAAM,CAAC;AAAA,EAGhD;AACF;AAEO,SAAS,uBACd,OACsC;AACtC,SAAO,IAAI,8BAA8B,KAAK;AAChD;","names":[]}
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  AgentBuilder
3
- } from "./chunk-GSFQZYS7.js";
3
+ } from "./chunk-BD66WU2B.js";
4
4
  import {
5
5
  createTool
6
- } from "./chunk-65QV627O.js";
6
+ } from "./chunk-OIA4CN5V.js";
7
7
  import {
8
8
  CompletionCapabilityError,
9
9
  CompletionRequestBuilder,
@@ -139,4 +139,4 @@ export {
139
139
  Extractor,
140
140
  ExtractorBuilder
141
141
  };
142
- //# sourceMappingURL=chunk-QRZ2HPUX.js.map
142
+ //# sourceMappingURL=chunk-4PHDOEKY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/extractor/extractor.ts"],"sourcesContent":["import type { Agent } from \"../agent/agent\";\nimport { AgentBuilder } from \"../agent/builder\";\nimport {\n CompletionCapabilityError,\n type CompletionModel,\n CompletionRequestBuilder,\n type CompletionResponse,\n type JsonValue,\n type Message,\n Message as MessageFactory,\n type ToolChoice,\n Usage,\n} from \"../completion/index\";\nimport type { ZodSchema } from \"../schema/zod-schema\";\nimport { createTool } from \"../tool/index\";\n\nconst SUBMIT_TOOL_NAME = \"submit\";\n\nconst DEFAULT_EXTRACTOR_INSTRUCTIONS =\n \"You are an AI assistant whose purpose is to extract structured data from the provided text.\\n\" +\n \"You have access to a `submit` function that defines the structure of the data to extract.\\n\" +\n \"Always call the `submit` function with the structured data. Use default or null values when information is missing.\";\n\nexport type ExtractionResponse<T> = {\n data: T;\n usage: Usage;\n messages: Message[];\n};\n\nexport class ExtractionError extends Error {\n constructor(\n message: string,\n readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"ExtractionError\";\n }\n}\n\nexport class Extractor<T, M extends CompletionModel = CompletionModel> {\n constructor(\n private readonly agent: Agent<M>,\n private readonly schema: ZodSchema<T>,\n private readonly retryCount: number,\n ) {}\n\n async extract(text: string | Message): Promise<T> {\n return (await this.extractWithUsage(text)).data;\n }\n\n async extractWithUsage(text: string | Message): Promise<ExtractionResponse<T>> {\n return this.run(text);\n }\n\n async extractWithHistory(text: string | Message, history: Message[]): Promise<T> {\n return (await this.run(text, history)).data;\n }\n\n getInner(): Agent<M> {\n return this.agent;\n }\n\n private async run(text: string | Message, history?: Message[]): Promise<ExtractionResponse<T>> {\n let usage = Usage.empty();\n let lastError: unknown;\n const prompt = typeof text === \"string\" ? MessageFactory.user(text) : text;\n\n for (let attempt = 0; attempt <= this.retryCount; attempt += 1) {\n try {\n const toolDefs = await this.agent.toolSet.getToolDefinitions(extractRagText(prompt));\n const response = await new CompletionRequestBuilder(this.agent.model, prompt)\n .instructions(this.agent.instructions)\n .messages(history ?? [])\n .documents(this.agent.staticContext)\n .tools(toolDefs)\n .temperature(this.agent.temperature)\n .maxTokens(this.agent.maxTokens)\n .additionalParams(this.agent.additionalParams)\n .toolChoice(this.agent.toolChoice)\n .send();\n usage = Usage.add(usage, response.usage);\n const data = extractSubmittedData(response, this.schema);\n return {\n data,\n usage,\n messages: [\n ...(history ?? []),\n prompt,\n MessageFactory.assistant(response.choice, response.messageId),\n ],\n };\n } catch (error) {\n if (error instanceof CompletionCapabilityError) {\n throw error;\n }\n lastError = error;\n }\n }\n\n throw new ExtractionError(\"No data extracted\", lastError);\n }\n}\n\nexport class ExtractorBuilder<T, M extends CompletionModel = CompletionModel> {\n private readonly agentBuilder: AgentBuilder<M>;\n private retryCount = 0;\n\n constructor(\n model: M,\n private readonly schema: ZodSchema<T>,\n ) {\n this.agentBuilder = new AgentBuilder(\"extractor\", model)\n .instructions(DEFAULT_EXTRACTOR_INSTRUCTIONS)\n .tool(\n createTool({\n name: SUBMIT_TOOL_NAME,\n description: \"Submit the structured data extracted from the provided text.\",\n input: schema,\n output: schema,\n execute: (args) => args,\n }),\n )\n .toolChoice(\"required\");\n }\n\n instructions(instructions: string): this {\n this.agentBuilder.instructions(instructions);\n return this;\n }\n\n context(text: string, id?: string): this {\n this.agentBuilder.context(text, id);\n return this;\n }\n\n temperature(temperature: number): this {\n this.agentBuilder.temperature(temperature);\n return this;\n }\n\n maxTokens(maxTokens: number): this {\n this.agentBuilder.maxTokens(maxTokens);\n return this;\n }\n\n additionalParams(params: JsonValue): this {\n this.agentBuilder.additionalParams(params);\n return this;\n }\n\n toolChoice(toolChoice: ToolChoice): this {\n this.agentBuilder.toolChoice(toolChoice);\n return this;\n }\n\n retries(retries: number): this {\n this.retryCount = Math.max(0, Math.trunc(retries));\n return this;\n }\n\n build(): Extractor<T, M> {\n return new Extractor(this.agentBuilder.build(), this.schema, this.retryCount);\n }\n}\n\nfunction extractSubmittedData<T>(response: CompletionResponse, schema: ZodSchema<T>): T {\n const submitted = response.choice\n .filter((content) => content.type === \"tool_call\")\n .filter((toolCall) => toolCall.function.name === SUBMIT_TOOL_NAME)\n .at(-1);\n\n if (submitted === undefined) {\n throw new ExtractionError(\"The model did not call the submit tool\");\n }\n\n return schema.parse(submitted.function.arguments);\n}\n\nfunction extractRagText(message: Message): string | undefined {\n if (message.role === \"user\") {\n return message.content.flatMap((item) => (item.type === \"text\" ? [item.text] : [])).join(\"\\n\");\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,I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EAEA,QAAQ,SAAuB;AAC7B,SAAK,aAAa,KAAK,IAAI,GAAG,KAAK,MAAM,OAAO,CAAC;AACjD,WAAO;AAAA,EACT;AAAA,EAEA,QAAyB;AACvB,WAAO,IAAI,UAAU,KAAK,aAAa,MAAM,GAAG,KAAK,QAAQ,KAAK,UAAU;AAAA,EAC9E;AACF;AAEA,SAAS,qBAAwB,UAA8B,QAAyB;AACtF,QAAM,YAAY,SAAS,OACxB,OAAO,CAAC,YAAY,QAAQ,SAAS,WAAW,EAChD,OAAO,CAAC,aAAa,SAAS,SAAS,SAAS,gBAAgB,EAChE,GAAG,EAAE;AAER,MAAI,cAAc,QAAW;AAC3B,UAAM,IAAI,gBAAgB,wCAAwC;AAAA,EACpE;AAEA,SAAO,OAAO,MAAM,UAAU,SAAS,SAAS;AAClD;AAEA,SAAS,eAAe,SAAsC;AAC5D,MAAI,QAAQ,SAAS,QAAQ;AAC3B,WAAO,QAAQ,QAAQ,QAAQ,CAAC,SAAU,KAAK,SAAS,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,CAAE,EAAE,KAAK,IAAI;AAAA,EAC/F;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,188 @@
1
+ import {
2
+ Agent,
3
+ normalizeAgentId
4
+ } from "./chunk-TVIADATY.js";
5
+ import {
6
+ resolveMemoryOptions
7
+ } from "./chunk-XXT2UCAR.js";
8
+ import {
9
+ ToolSet
10
+ } from "./chunk-CY7SB5FG.js";
11
+ import {
12
+ toProviderJsonSchema
13
+ } from "./chunk-OIA4CN5V.js";
14
+
15
+ // src/agent/builder.ts
16
+ var AgentBuilder = class {
17
+ constructor(agentId, completionModel) {
18
+ this.completionModel = completionModel;
19
+ this.agentId = normalizeAgentId(agentId);
20
+ }
21
+ completionModel;
22
+ agentId;
23
+ agentName;
24
+ agentDescription;
25
+ instructionBlocks = [];
26
+ contextDocs = [];
27
+ temp;
28
+ maxTokenCount;
29
+ params;
30
+ choice;
31
+ turns;
32
+ requestHook;
33
+ schema;
34
+ skillInstructionBlocks = [];
35
+ observerRegistrations = [];
36
+ dynamicContextRegistrations = [];
37
+ dynamicToolRegistrations = [];
38
+ middlewareRegistrations = [];
39
+ memoryRegistration;
40
+ eventStoreRegistration;
41
+ activeToolSet = new ToolSet();
42
+ name(name) {
43
+ this.agentName = name;
44
+ return this;
45
+ }
46
+ description(description) {
47
+ this.agentDescription = description;
48
+ return this;
49
+ }
50
+ instructions(instructions) {
51
+ if (instructions.length > 0) {
52
+ this.instructionBlocks.push(instructions);
53
+ }
54
+ return this;
55
+ }
56
+ context(text, id = `static_doc_${this.contextDocs.length}`) {
57
+ this.contextDocs.push({ id, text });
58
+ return this;
59
+ }
60
+ dynamicContext(index, options) {
61
+ this.dynamicContextRegistrations.push({ index, options });
62
+ return this;
63
+ }
64
+ dynamicTools(index, options) {
65
+ this.dynamicToolRegistrations.push({ index, options });
66
+ return this;
67
+ }
68
+ tool(tool) {
69
+ this.activeToolSet.addTool(tool);
70
+ return this;
71
+ }
72
+ tools(tools) {
73
+ this.activeToolSet.addTools(tools);
74
+ return this;
75
+ }
76
+ mcp(servers) {
77
+ for (const server of servers) {
78
+ this.activeToolSet.addTools(server.tools);
79
+ }
80
+ return this;
81
+ }
82
+ skills(skillSet) {
83
+ if (skillSet.instructions.length > 0) {
84
+ this.skillInstructionBlocks.push(skillSet.instructions);
85
+ }
86
+ this.activeToolSet.addTools(skillSet.tools);
87
+ return this;
88
+ }
89
+ useToolSet(toolSet) {
90
+ toolSet.addTools(this.activeToolSet);
91
+ this.activeToolSet = toolSet;
92
+ return this;
93
+ }
94
+ temperature(temperature) {
95
+ this.temp = temperature;
96
+ return this;
97
+ }
98
+ maxTokens(maxTokens) {
99
+ this.maxTokenCount = maxTokens;
100
+ return this;
101
+ }
102
+ additionalParams(params) {
103
+ this.params = params;
104
+ return this;
105
+ }
106
+ toolChoice(toolChoice) {
107
+ this.choice = toolChoice;
108
+ return this;
109
+ }
110
+ defaultMaxTurns(defaultMaxTurns) {
111
+ this.turns = defaultMaxTurns;
112
+ return this;
113
+ }
114
+ hook(hook) {
115
+ this.requestHook = hook;
116
+ return this;
117
+ }
118
+ toolMiddleware(middleware) {
119
+ this.middlewareRegistrations.push(middleware);
120
+ return this;
121
+ }
122
+ toolMiddlewares(middlewares) {
123
+ this.middlewareRegistrations.push(...middlewares);
124
+ return this;
125
+ }
126
+ observe(observer, options = {}) {
127
+ this.observerRegistrations.push({
128
+ observer,
129
+ failOnObserverError: options.failOnObserverError
130
+ });
131
+ return this;
132
+ }
133
+ memory(store, options = {}) {
134
+ this.memoryRegistration = {
135
+ store,
136
+ options: resolveMemoryOptions(options)
137
+ };
138
+ return this;
139
+ }
140
+ eventStore(store, options = {}) {
141
+ this.eventStoreRegistration = {
142
+ store,
143
+ options: {
144
+ include: options.include ?? "all"
145
+ }
146
+ };
147
+ return this;
148
+ }
149
+ outputSchema(schema) {
150
+ this.schema = toProviderJsonSchema(schema);
151
+ return this;
152
+ }
153
+ build() {
154
+ return new Agent({
155
+ id: this.agentId,
156
+ name: this.agentName,
157
+ description: this.agentDescription,
158
+ model: this.completionModel,
159
+ instructions: this.buildInstructions(),
160
+ staticContext: this.contextDocs,
161
+ temperature: this.temp,
162
+ maxTokens: this.maxTokenCount,
163
+ additionalParams: this.params,
164
+ toolSet: this.activeToolSet,
165
+ toolChoice: this.choice,
166
+ defaultMaxTurns: this.turns,
167
+ hook: this.requestHook,
168
+ outputSchema: this.schema,
169
+ observers: this.observerRegistrations,
170
+ dynamicContexts: this.dynamicContextRegistrations,
171
+ dynamicTools: this.dynamicToolRegistrations,
172
+ toolMiddlewares: this.middlewareRegistrations,
173
+ memory: this.memoryRegistration,
174
+ eventStore: this.eventStoreRegistration
175
+ });
176
+ }
177
+ buildInstructions() {
178
+ const parts = [...this.instructionBlocks, ...this.skillInstructionBlocks].filter(
179
+ (part) => part !== void 0 && part.length > 0
180
+ );
181
+ return parts.length === 0 ? void 0 : parts.join("\n\n");
182
+ }
183
+ };
184
+
185
+ export {
186
+ AgentBuilder
187
+ };
188
+ //# sourceMappingURL=chunk-BD66WU2B.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/agent/builder.ts"],"sourcesContent":["import type { CompletionModel, Document, JsonObject, JsonValue, ToolChoice } from \"../completion\";\nimport type { McpServer } from \"../mcp\";\nimport {\n type MemoryOptions,\n type MemoryRegistration,\n type MemoryStore,\n resolveMemoryOptions,\n} from \"../memory\";\nimport type { AgentObserver, AgentObserverRegistration, ObserveOptions } from \"../observability\";\nimport { toProviderJsonSchema, type ZodSchema } from \"../schema/zod-schema\";\nimport type { SkillSet } from \"../skills\";\nimport type { ToolSearchDocument } from \"../tool/dynamic-tools\";\nimport type { ToolMiddleware } from \"../tool/middleware\";\nimport type { AnyTool } from \"../tool/tool\";\nimport { ToolSet } from \"../tool/tool-set\";\nimport type { VectorSearchIndex } from \"../vector-store\";\nimport {\n Agent,\n type AgentEventStore,\n type AgentEventStoreOptions,\n type AgentEventStoreRegistration,\n type DynamicContextOptions,\n type DynamicContextRegistration,\n type DynamicToolOptions,\n type DynamicToolRegistration,\n} from \"./agent\";\nimport type { PromptHook } from \"./hooks\";\nimport { normalizeAgentId } from \"./ids\";\n\nexport class AgentBuilder<M extends CompletionModel = CompletionModel> {\n private readonly agentId: string;\n private agentName: string | undefined;\n private agentDescription: string | undefined;\n private instructionBlocks: string[] = [];\n private contextDocs: Document[] = [];\n private temp: number | undefined;\n private maxTokenCount: number | undefined;\n private params: JsonValue | undefined;\n private choice: ToolChoice | undefined;\n private turns: number | undefined;\n private requestHook: PromptHook | undefined;\n private schema: JsonObject | undefined;\n private skillInstructionBlocks: string[] = [];\n private observerRegistrations: AgentObserverRegistration[] = [];\n private dynamicContextRegistrations: DynamicContextRegistration[] = [];\n private dynamicToolRegistrations: DynamicToolRegistration[] = [];\n private middlewareRegistrations: ToolMiddleware[] = [];\n private memoryRegistration: MemoryRegistration | undefined;\n private eventStoreRegistration: AgentEventStoreRegistration | undefined;\n private activeToolSet = new ToolSet();\n\n constructor(\n agentId: string,\n private readonly completionModel: M,\n ) {\n this.agentId = normalizeAgentId(agentId);\n }\n\n name(name: string): this {\n this.agentName = name;\n return this;\n }\n\n description(description: string): this {\n this.agentDescription = description;\n return this;\n }\n\n instructions(instructions: string): this {\n if (instructions.length > 0) {\n this.instructionBlocks.push(instructions);\n }\n return this;\n }\n\n context(text: string, id = `static_doc_${this.contextDocs.length}`): this {\n this.contextDocs.push({ id, text });\n return this;\n }\n\n dynamicContext<T>(index: VectorSearchIndex<T>, options: DynamicContextOptions<T>): this {\n this.dynamicContextRegistrations.push({ index, options } as DynamicContextRegistration);\n return this;\n }\n\n dynamicTools(index: VectorSearchIndex<ToolSearchDocument>, options: DynamicToolOptions): this {\n this.dynamicToolRegistrations.push({ index, options });\n return this;\n }\n\n tool(tool: AnyTool): this {\n this.activeToolSet.addTool(tool);\n return this;\n }\n\n tools(tools: AnyTool[]): this {\n this.activeToolSet.addTools(tools);\n return this;\n }\n\n mcp(servers: McpServer[]): this {\n for (const server of servers) {\n this.activeToolSet.addTools(server.tools);\n }\n return this;\n }\n\n skills(skillSet: SkillSet): this {\n if (skillSet.instructions.length > 0) {\n this.skillInstructionBlocks.push(skillSet.instructions);\n }\n this.activeToolSet.addTools(skillSet.tools);\n return this;\n }\n\n useToolSet(toolSet: ToolSet): this {\n toolSet.addTools(this.activeToolSet);\n this.activeToolSet = toolSet;\n return this;\n }\n\n temperature(temperature: number): this {\n this.temp = temperature;\n return this;\n }\n\n maxTokens(maxTokens: number): this {\n this.maxTokenCount = maxTokens;\n return this;\n }\n\n additionalParams(params: JsonValue): this {\n this.params = params;\n return this;\n }\n\n toolChoice(toolChoice: ToolChoice): this {\n this.choice = toolChoice;\n return this;\n }\n\n defaultMaxTurns(defaultMaxTurns: number): this {\n this.turns = defaultMaxTurns;\n return this;\n }\n\n hook(hook: PromptHook): this {\n this.requestHook = hook;\n return this;\n }\n\n toolMiddleware(middleware: ToolMiddleware): this {\n this.middlewareRegistrations.push(middleware);\n return this;\n }\n\n toolMiddlewares(middlewares: ToolMiddleware[]): this {\n this.middlewareRegistrations.push(...middlewares);\n return this;\n }\n\n observe(observer: AgentObserver, options: ObserveOptions = {}): this {\n this.observerRegistrations.push({\n observer,\n failOnObserverError: options.failOnObserverError,\n });\n return this;\n }\n\n memory(store: MemoryStore, options: MemoryOptions = {}): this {\n this.memoryRegistration = {\n store,\n options: resolveMemoryOptions(options),\n };\n return this;\n }\n\n eventStore(store: AgentEventStore, options: AgentEventStoreOptions = {}): this {\n this.eventStoreRegistration = {\n store,\n options: {\n include: options.include ?? \"all\",\n },\n };\n return this;\n }\n\n outputSchema(schema: ZodSchema): this {\n this.schema = toProviderJsonSchema(schema);\n return this;\n }\n\n build(): Agent<M> {\n return new Agent({\n id: this.agentId,\n name: this.agentName,\n description: this.agentDescription,\n model: this.completionModel,\n instructions: this.buildInstructions(),\n staticContext: this.contextDocs,\n temperature: this.temp,\n maxTokens: this.maxTokenCount,\n additionalParams: this.params,\n toolSet: this.activeToolSet,\n toolChoice: this.choice,\n defaultMaxTurns: this.turns,\n hook: this.requestHook,\n outputSchema: this.schema,\n observers: this.observerRegistrations,\n dynamicContexts: this.dynamicContextRegistrations,\n dynamicTools: this.dynamicToolRegistrations,\n toolMiddlewares: this.middlewareRegistrations,\n memory: this.memoryRegistration,\n eventStore: this.eventStoreRegistration,\n });\n }\n\n private buildInstructions(): string | undefined {\n const parts = [...this.instructionBlocks, ...this.skillInstructionBlocks].filter(\n (part): part is string => part !== undefined && part.length > 0,\n );\n return parts.length === 0 ? undefined : parts.join(\"\\n\\n\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA6BO,IAAM,eAAN,MAAgE;AAAA,EAsBrE,YACE,SACiB,iBACjB;AADiB;AAEjB,SAAK,UAAU,iBAAiB,OAAO;AAAA,EACzC;AAAA,EAHmB;AAAA,EAvBF;AAAA,EACT;AAAA,EACA;AAAA,EACA,oBAA8B,CAAC;AAAA,EAC/B,cAA0B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A,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAyB;AACpC,SAAK,SAAS,qBAAqB,MAAM;AACzC,WAAO;AAAA,EACT;AAAA,EAEA,QAAkB;AAChB,WAAO,IAAI,MAAM;AAAA,MACf,IAAI,KAAK;AAAA,MACT,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,OAAO,KAAK;AAAA,MACZ,cAAc,KAAK,kBAAkB;AAAA,MACrC,eAAe,KAAK;AAAA,MACpB,aAAa,KAAK;AAAA,MAClB,WAAW,KAAK;AAAA,MAChB,kBAAkB,KAAK;AAAA,MACvB,SAAS,KAAK;AAAA,MACd,YAAY,KAAK;AAAA,MACjB,iBAAiB,KAAK;AAAA,MACtB,MAAM,KAAK;AAAA,MACX,cAAc,KAAK;AAAA,MACnB,WAAW,KAAK;AAAA,MAChB,iBAAiB,KAAK;AAAA,MACtB,cAAc,KAAK;AAAA,MACnB,iBAAiB,KAAK;AAAA,MACtB,QAAQ,KAAK;AAAA,MACb,YAAY,KAAK;AAAA,IACnB,CAAC;AAAA,EACH;AAAA,EAEQ,oBAAwC;AAC9C,UAAM,QAAQ,CAAC,GAAG,KAAK,mBAAmB,GAAG,KAAK,sBAAsB,EAAE;AAAA,MACxE,CAAC,SAAyB,SAAS,UAAa,KAAK,SAAS;AAAA,IAChE;AACA,WAAO,MAAM,WAAW,IAAI,SAAY,MAAM,KAAK,MAAM;AAAA,EAC3D;AACF;","names":[]}
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  InMemoryVectorStore,
3
3
  createTool
4
- } from "./chunk-65QV627O.js";
4
+ } from "./chunk-OIA4CN5V.js";
5
5
  import {
6
6
  embedDocuments
7
- } from "./chunk-A7VDIZQN.js";
7
+ } from "./chunk-EFGX3EX5.js";
8
8
 
9
9
  // src/tool/errors.ts
10
10
  var ToolCallError = class extends Error {
@@ -237,4 +237,4 @@ export {
237
237
  createToolMiddleware,
238
238
  createThinkTool
239
239
  };
240
- //# sourceMappingURL=chunk-I2HOMD3R.js.map
240
+ //# sourceMappingURL=chunk-CY7SB5FG.js.map
@@ -1,3 +1,7 @@
1
+ import {
2
+ mapWithConcurrency
3
+ } from "./chunk-OIMLU4SF.js";
4
+
1
5
  // src/embeddings/index.ts
2
6
  async function embedText(model, text) {
3
7
  const embeddings = await embedTexts(model, [text]);
@@ -117,19 +121,6 @@ function chunk(items, size) {
117
121
  }
118
122
  return chunks;
119
123
  }
120
- async function mapWithConcurrency(items, concurrency, mapper) {
121
- const results = new Array(items.length);
122
- let next = 0;
123
- async function worker() {
124
- while (next < items.length) {
125
- const index = next;
126
- next += 1;
127
- results[index] = await mapper(items[index]);
128
- }
129
- }
130
- await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, () => worker()));
131
- return results;
132
- }
133
124
 
134
125
  export {
135
126
  embedText,
@@ -142,4 +133,4 @@ export {
142
133
  manhattanDistance,
143
134
  chebyshevDistance
144
135
  };
145
- //# sourceMappingURL=chunk-A7VDIZQN.js.map
136
+ //# sourceMappingURL=chunk-EFGX3EX5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/embeddings/index.ts"],"sourcesContent":["import { mapWithConcurrency } from \"../internal/concurrency\";\nimport type {\n EmbedDocumentsOptions,\n EmbeddedDocument,\n Embedding,\n EmbeddingModel,\n VectorMetadata,\n} from \"./types\";\n\nexport type * from \"./types\";\n\nexport async function embedText(model: EmbeddingModel, text: string): Promise<Embedding> {\n const embeddings = await embedTexts(model, [text]);\n const embedding = embeddings[0];\n if (embedding === undefined) {\n throw new Error(\"Embedding model returned no embeddings\");\n }\n return embedding;\n}\n\nexport async function embedTexts(model: EmbeddingModel, texts: string[]): Promise<Embedding[]> {\n if (texts.length === 0) {\n return [];\n }\n\n const maxBatchSize = Math.max(1, Math.trunc(model.maxBatchSize ?? texts.length));\n const batches: string[][] = [];\n for (let index = 0; index < texts.length; index += maxBatchSize) {\n batches.push(texts.slice(index, index + maxBatchSize));\n }\n\n const results = await mapWithConcurrency(batches, 1, (batch) => model.embedTexts(batch));\n const embeddings = results.flat();\n if (embeddings.length !== texts.length) {\n throw new Error(\n `Embedding model returned ${embeddings.length} embeddings for ${texts.length} texts`,\n );\n }\n return embeddings;\n}\n\nexport async function embedDocuments<T, Metadata extends VectorMetadata = VectorMetadata>(\n model: EmbeddingModel,\n documents: T[],\n options: EmbedDocumentsOptions<T, Metadata>,\n): Promise<Array<EmbeddedDocument<T, Metadata>>> {\n const prepared = documents.map((document, index) => {\n const content = options.content(document, index);\n const texts = Array.isArray(content) ? content : [content];\n return {\n id: options.id?.(document, index) ?? `doc${index}`,\n document,\n metadata: options.metadata?.(document, index),\n texts,\n };\n });\n\n const flatTexts = prepared.flatMap((item, documentIndex) =>\n item.texts.map((text) => ({ documentIndex, text })),\n );\n const embeddings = await mapWithConcurrency(\n chunk(flatTexts, Math.max(1, Math.trunc(model.maxBatchSize ?? (flatTexts.length || 1)))),\n Math.max(1, Math.trunc(options.concurrency ?? 1)),\n async (batch) => {\n const batchEmbeddings = await model.embedTexts(batch.map((item) => item.text));\n if (batchEmbeddings.length !== batch.length) {\n throw new Error(\n `Embedding model returned ${batchEmbeddings.length} embeddings for ${batch.length} texts`,\n );\n }\n return batch.map((item, index) => ({\n documentIndex: item.documentIndex,\n embedding: batchEmbeddings[index] as Embedding,\n }));\n },\n );\n\n const byDocument = new Map<number, Embedding[]>();\n for (const item of embeddings.flat()) {\n const list = byDocument.get(item.documentIndex) ?? [];\n list.push(item.embedding);\n byDocument.set(item.documentIndex, list);\n }\n\n return prepared.map((item, index) => ({\n id: item.id,\n document: item.document,\n ...(item.metadata === undefined ? {} : { metadata: item.metadata }),\n embeddings: byDocument.get(index) ?? [],\n }));\n}\n\nexport function dotProduct(left: number[], right: number[]): number {\n assertSameDimensions(left, right);\n return left.reduce((sum, value, index) => sum + value * (right[index] as number), 0);\n}\n\nexport function cosineSimilarity(left: number[], right: number[]): number {\n assertSameDimensions(left, right);\n const leftMagnitude = magnitude(left);\n const rightMagnitude = magnitude(right);\n if (leftMagnitude === 0 || rightMagnitude === 0) {\n return 0;\n }\n return dotProduct(left, right) / (leftMagnitude * rightMagnitude);\n}\n\nexport function angularDistance(left: number[], right: number[]): number {\n const similarity = Math.max(-1, Math.min(1, cosineSimilarity(left, right)));\n return Math.acos(similarity) / Math.PI;\n}\n\nexport function euclideanDistance(left: number[], right: number[]): number {\n assertSameDimensions(left, right);\n return Math.sqrt(\n left.reduce((sum, value, index) => sum + (value - (right[index] as number)) ** 2, 0),\n );\n}\n\nexport function manhattanDistance(left: number[], right: number[]): number {\n assertSameDimensions(left, right);\n return left.reduce((sum, value, index) => sum + Math.abs(value - (right[index] as number)), 0);\n}\n\nexport function chebyshevDistance(left: number[], right: number[]): number {\n assertSameDimensions(left, right);\n return left.reduce(\n (max, value, index) => Math.max(max, Math.abs(value - (right[index] as number))),\n 0,\n );\n}\n\nfunction magnitude(vector: number[]): number {\n return Math.sqrt(vector.reduce((sum, value) => sum + value ** 2, 0));\n}\n\nfunction assertSameDimensions(left: number[], right: number[]): void {\n if (left.length !== right.length) {\n throw new Error(`Vector dimension mismatch: ${left.length} !== ${right.length}`);\n }\n}\n\nfunction chunk<T>(items: T[], size: number): T[][] {\n const chunks: T[][] = [];\n for (let index = 0; index < items.length; index += size) {\n chunks.push(items.slice(index, index + size));\n }\n return chunks;\n}\n"],"mappings":";;;;;AAWA,eAAsB,UAAU,OAAuB,MAAkC;AACvF,QAAM,aAAa,MAAM,WAAW,OAAO,CAAC,IAAI,CAAC;AACjD,QAAM,YAAY,WAAW,CAAC;AAC9B,MAAI,cAAc,QAAW;AAC3B,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC1D;AACA,SAAO;AACT;AAEA,eAAsB,WAAW,OAAuB,OAAuC;AAC7F,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,eAAe,KAAK,IAAI,GAAG,KAAK,MAAM,MAAM,gBAAgB,MAAM,MAAM,CAAC;AAC/E,QAAM,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B,MAAgB,OAAyB;AACzE,uBAAqB,MAAM,KAAK;AAChC,SAAO,KAAK;AAAA,IACV,KAAK,OAAO,CAAC,KAAK,OAAO,UAAU,OAAO,QAAS,MAAM,KAAK,MAAiB,GAAG,CAAC;AAAA,EACrF;AACF;AAEO,SAAS,kBAAkB,MAAgB,OAAyB;AACzE,uBAAqB,MAAM,KAAK;AAChC,SAAO,KAAK,OAAO,CAAC,KAAK,OAAO,UAAU,MAAM,KAAK,IAAI,QAAS,MAAM,KAAK,CAAY,GAAG,CAAC;AAC/F;AAEO,SAAS,kBAAkB,MAAgB,OAAyB;AACzE,uBAAqB,MAAM,KAAK;AAChC,SAAO,KAAK;AAAA,IACV,CAAC,KAAK,OAAO,UAAU,KAAK,IAAI,KAAK,KAAK,IAAI,QAAS,MAAM,KAAK,CAAY,CAAC;AAAA,IAC/E;AAAA,EACF;AACF;AAEA,SAAS,UAAU,QAA0B;AAC3C,SAAO,KAAK,KAAK,OAAO,OAAO,CAAC,KAAK,UAAU,MAAM,SAAS,GAAG,CAAC,CAAC;AACrE;AAEA,SAAS,qBAAqB,MAAgB,OAAuB;AACnE,MAAI,KAAK,WAAW,MAAM,QAAQ;AAChC,UAAM,IAAI,MAAM,8BAA8B,KAAK,MAAM,QAAQ,MAAM,MAAM,EAAE;AAAA,EACjF;AACF;AAEA,SAAS,MAAS,OAAY,MAAqB;AACjD,QAAM,SAAgB,CAAC;AACvB,WAAS,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,MAAM;AACvD,WAAO,KAAK,MAAM,MAAM,OAAO,QAAQ,IAAI,CAAC;AAAA,EAC9C;AACA,SAAO;AACT;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-YK4WAAS4.js";
4
4
  import {
5
5
  createTool
6
- } from "./chunk-65QV627O.js";
6
+ } from "./chunk-OIA4CN5V.js";
7
7
 
8
8
  // src/skills/instructions.ts
9
9
  function skillInstructions(skills) {
@@ -395,4 +395,4 @@ export {
395
395
  SkillValidationError,
396
396
  skill
397
397
  };
398
- //# sourceMappingURL=chunk-TILE6Z2N.js.map
398
+ //# sourceMappingURL=chunk-L6JCKFAX.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  cosineSimilarity,
3
3
  embedText
4
- } from "./chunk-A7VDIZQN.js";
4
+ } from "./chunk-EFGX3EX5.js";
5
5
 
6
6
  // src/vector-store/index.ts
7
7
  import { z as z2 } from "zod";
@@ -300,4 +300,4 @@ export {
300
300
  InMemoryVectorIndex,
301
301
  createVectorSearchTool
302
302
  };
303
- //# sourceMappingURL=chunk-65QV627O.js.map
303
+ //# sourceMappingURL=chunk-OIA4CN5V.js.map
@@ -0,0 +1,20 @@
1
+ // src/internal/concurrency.ts
2
+ async function mapWithConcurrency(inputs, concurrency, mapper) {
3
+ const limit = Math.max(1, Math.trunc(concurrency));
4
+ const results = new Array(inputs.length);
5
+ let nextIndex = 0;
6
+ async function worker() {
7
+ while (nextIndex < inputs.length) {
8
+ const index = nextIndex;
9
+ nextIndex += 1;
10
+ results[index] = await mapper(inputs[index]);
11
+ }
12
+ }
13
+ await Promise.all(Array.from({ length: Math.min(limit, inputs.length) }, () => worker()));
14
+ return results;
15
+ }
16
+
17
+ export {
18
+ mapWithConcurrency
19
+ };
20
+ //# sourceMappingURL=chunk-OIMLU4SF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internal/concurrency.ts"],"sourcesContent":["export async function mapWithConcurrency<Input, Output>(\n inputs: Input[],\n concurrency: number,\n mapper: (input: Input) => Promise<Output>,\n): Promise<Output[]> {\n const limit = Math.max(1, Math.trunc(concurrency));\n const results = new Array<Output>(inputs.length);\n let nextIndex = 0;\n\n async function worker(): Promise<void> {\n while (nextIndex < inputs.length) {\n const index = nextIndex;\n nextIndex += 1;\n results[index] = await mapper(inputs[index] as Input);\n }\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, inputs.length) }, () => worker()));\n return results;\n}\n"],"mappings":";AAAA,eAAsB,mBACpB,QACA,aACA,QACmB;AACnB,QAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,WAAW,CAAC;AACjD,QAAM,UAAU,IAAI,MAAc,OAAO,MAAM;AAC/C,MAAI,YAAY;AAEhB,iBAAe,SAAwB;AACrC,WAAO,YAAY,OAAO,QAAQ;AAChC,YAAM,QAAQ;AACd,mBAAa;AACb,cAAQ,KAAK,IAAI,MAAM,OAAO,OAAO,KAAK,CAAU;AAAA,IACtD;AAAA,EACF;AAEA,QAAM,QAAQ,IAAI,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,OAAO,OAAO,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,CAAC;AACxF,SAAO;AACT;","names":[]}