@anvia/core 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/index.d.ts +14 -5
- package/dist/agent/index.js +8 -3
- package/dist/{agent-B-ls5y_g.d.ts → agent-CWGuTdMJ.d.ts} +80 -6
- package/dist/{chunk-MOICCK3J.js → chunk-365W6FJD.js} +18 -6
- package/dist/chunk-365W6FJD.js.map +1 -0
- package/dist/{chunk-N7NMSGZI.js → chunk-ORLEOXD7.js} +245 -36
- package/dist/chunk-ORLEOXD7.js.map +1 -0
- package/dist/{chunk-35GF7P43.js → chunk-S7EOE6EC.js} +5 -1
- package/dist/{chunk-35GF7P43.js.map → chunk-S7EOE6EC.js.map} +1 -1
- package/dist/{chunk-LGETU3RG.js → chunk-Z7HY4WU7.js} +2 -2
- package/dist/evals/index.d.ts +2 -2
- package/dist/evals/index.js +4 -4
- package/dist/extractor/index.d.ts +2 -2
- package/dist/extractor/index.js +4 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.js +8 -4
- package/dist/internal/agent.d.ts +2 -2
- package/dist/internal/agent.js +2 -2
- package/dist/middleware-qfm1EFKK.d.ts +102 -0
- package/dist/pipeline/index.d.ts +2 -2
- package/dist/skills/index.js +1 -1
- package/dist/tool/index.d.ts +1 -1
- package/dist/tool/index.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-MOICCK3J.js.map +0 -1
- package/dist/chunk-N7NMSGZI.js.map +0 -1
- package/dist/middleware-CGiEIaBx.d.ts +0 -53
- /package/dist/{chunk-LGETU3RG.js.map → chunk-Z7HY4WU7.js.map} +0 -0
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { k as ToolSearchDocument, l as ToolSet, A as AgentMiddleware, e as ToolMiddleware } from '../middleware-qfm1EFKK.js';
|
|
2
|
+
export { C as CompletionRequestMiddlewareArgs, a as CompletionRequestMiddlewareResult, b as CompletionResponseMiddlewareArgs, c as CompletionResponseMiddlewareResult, T as ToolInputMiddlewareArgs, d as ToolInputMiddlewareResult, f as ToolOutputMiddlewareArgs, g as ToolOutputMiddlewareResult, h as ToolResultMiddlewareArgs, i as createMiddleware, j as createToolMiddleware } from '../middleware-qfm1EFKK.js';
|
|
3
|
+
import { D as DynamicContextOptions, f as DynamicToolOptions, g as PromptHook, h as AgentEventStore, i as AgentEventStoreOptions, e as Agent } from '../agent-CWGuTdMJ.js';
|
|
4
|
+
export { A as AgentChildStreamEvent, j as AgentEventAppendInput, k as AgentEventRecord, l as AgentEventStoreInclude, a as AgentStreamEvent, C as CompletionCallHookArgs, m as CompletionErrorHookArgs, n as CompletionResponseHookArgs, H as HookAction, o as HookResult, P as PromptResponse, R as RunControl, p as RunEndHookArgs, q as RunErrorHookArgs, u as RunStartHookArgs, T as ToolApprovalRequestOptions, v as ToolCallControl, w as ToolCallHookAction, x as ToolCallHookArgs, y as ToolCallHookResult, z as ToolErrorHookArgs, B as ToolHookArgs, E as ToolResultHookArgs, F as TurnEndHookArgs, G as TurnStartHookArgs, c as cancelPrompt, b as createHook, r as requestToolApproval, d as runControl, s as skipTool, t as toolCallControl } from '../agent-CWGuTdMJ.js';
|
|
3
5
|
import { C as CompletionModel, e as JsonValue, m as ToolChoice, M as Message } from '../types-C54aNoCd.js';
|
|
4
6
|
import { a as McpServer } from '../types-UhcgW8Fo.js';
|
|
5
7
|
import { MemoryStore, MemoryOptions } from '../memory/index.js';
|
|
6
8
|
import { AgentObserver, ObserveOptions } from '../observability/index.js';
|
|
7
9
|
import { Z as ZodSchema } from '../zod-schema-C7F4clpm.js';
|
|
8
10
|
import { a as SkillSet } from '../types-T9rlOIUc.js';
|
|
9
|
-
import { b as ToolSearchDocument, c as ToolSet, T as ToolMiddleware } from '../middleware-CGiEIaBx.js';
|
|
10
11
|
import { A as AnyTool } from '../tool-C3ciF-VG.js';
|
|
11
12
|
import { VectorSearchIndex } from '../vector-store/index.js';
|
|
13
|
+
import '../types-IB2e9u5M.js';
|
|
12
14
|
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
13
15
|
import '@modelcontextprotocol/sdk/client/stdio.js';
|
|
14
16
|
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
15
17
|
import 'zod';
|
|
16
|
-
import '../types-IB2e9u5M.js';
|
|
17
18
|
|
|
18
19
|
declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
|
|
19
20
|
private readonly completionModel;
|
|
@@ -55,7 +56,15 @@ declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
|
|
|
55
56
|
toolChoice(toolChoice: ToolChoice): this;
|
|
56
57
|
defaultMaxTurns(defaultMaxTurns: number): this;
|
|
57
58
|
hook(hook: PromptHook): this;
|
|
59
|
+
middleware(middleware: AgentMiddleware): this;
|
|
60
|
+
middlewares(middlewares: AgentMiddleware[]): this;
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Use `middleware` instead.
|
|
63
|
+
*/
|
|
58
64
|
toolMiddleware(middleware: ToolMiddleware): this;
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Use `middlewares` instead.
|
|
67
|
+
*/
|
|
59
68
|
toolMiddlewares(middlewares: ToolMiddleware[]): this;
|
|
60
69
|
observe(observer: AgentObserver, options?: ObserveOptions): this;
|
|
61
70
|
memory(store: MemoryStore, options?: MemoryOptions): this;
|
|
@@ -77,4 +86,4 @@ declare class PromptCancelledError extends Error {
|
|
|
77
86
|
constructor(chatHistory: Message[], reason: string);
|
|
78
87
|
}
|
|
79
88
|
|
|
80
|
-
export { AgentBuilder, AgentEventStore, AgentEventStoreOptions, MaxTurnsError, PromptCancelledError, PromptHook };
|
|
89
|
+
export { AgentBuilder, AgentEventStore, AgentEventStoreOptions, AgentMiddleware, MaxTurnsError, PromptCancelledError, PromptHook, ToolMiddleware };
|
package/dist/agent/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentBuilder
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-365W6FJD.js";
|
|
4
4
|
import {
|
|
5
5
|
MaxTurnsError,
|
|
6
6
|
PromptCancelledError,
|
|
@@ -10,11 +10,14 @@ import {
|
|
|
10
10
|
runControl,
|
|
11
11
|
skipTool,
|
|
12
12
|
toolCallControl
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-ORLEOXD7.js";
|
|
14
14
|
import "../chunk-XUUY2L2D.js";
|
|
15
15
|
import "../chunk-XXT2UCAR.js";
|
|
16
16
|
import "../chunk-YK4WAAS4.js";
|
|
17
|
-
import
|
|
17
|
+
import {
|
|
18
|
+
createMiddleware,
|
|
19
|
+
createToolMiddleware
|
|
20
|
+
} from "../chunk-S7EOE6EC.js";
|
|
18
21
|
import "../chunk-P425B6GR.js";
|
|
19
22
|
import "../chunk-6GJDBBDC.js";
|
|
20
23
|
import "../chunk-EFGX3EX5.js";
|
|
@@ -25,6 +28,8 @@ export {
|
|
|
25
28
|
PromptCancelledError,
|
|
26
29
|
cancelPrompt,
|
|
27
30
|
createHook,
|
|
31
|
+
createMiddleware,
|
|
32
|
+
createToolMiddleware,
|
|
28
33
|
requestToolApproval,
|
|
29
34
|
runControl,
|
|
30
35
|
skipTool,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { M as Message, c as CompletionResponse, j as ToolResultContent, C as CompletionModel,
|
|
1
|
+
import { M as Message, U as Usage, c as CompletionResponse, j as ToolResultContent, C as CompletionModel, 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 {
|
|
4
|
+
import { A as AgentMiddleware, e as ToolMiddleware, l as ToolSet, k as ToolSearchDocument } from './middleware-qfm1EFKK.js';
|
|
5
5
|
import { T as Tool, A as AnyTool, c as ToolCallContext, N as NormalizedToolOutput } from './tool-C3ciF-VG.js';
|
|
6
6
|
import { VectorFilter, VectorSearchResult, VectorSearchIndex } from './vector-store/index.js';
|
|
7
7
|
|
|
@@ -45,11 +45,45 @@ type CompletionCallHookArgs = {
|
|
|
45
45
|
history: Message[];
|
|
46
46
|
run: RunControl;
|
|
47
47
|
};
|
|
48
|
+
type RunStartHookArgs = {
|
|
49
|
+
prompt: Message;
|
|
50
|
+
history: Message[];
|
|
51
|
+
maxTurns: number;
|
|
52
|
+
run: RunControl;
|
|
53
|
+
};
|
|
54
|
+
type RunEndHookArgs = {
|
|
55
|
+
output: string;
|
|
56
|
+
usage: Usage;
|
|
57
|
+
messages: Message[];
|
|
58
|
+
run: RunControl;
|
|
59
|
+
};
|
|
60
|
+
type RunErrorHookArgs = {
|
|
61
|
+
error: unknown;
|
|
62
|
+
usage: Usage;
|
|
63
|
+
messages: Message[];
|
|
64
|
+
run: RunControl;
|
|
65
|
+
};
|
|
66
|
+
type TurnStartHookArgs = {
|
|
67
|
+
turn: number;
|
|
68
|
+
prompt: Message;
|
|
69
|
+
history: Message[];
|
|
70
|
+
run: RunControl;
|
|
71
|
+
};
|
|
72
|
+
type TurnEndHookArgs<RawResponse = unknown> = {
|
|
73
|
+
turn: number;
|
|
74
|
+
response: CompletionResponse<RawResponse>;
|
|
75
|
+
run: RunControl;
|
|
76
|
+
};
|
|
48
77
|
type CompletionResponseHookArgs<RawResponse = unknown> = {
|
|
49
78
|
prompt: Message;
|
|
50
79
|
response: CompletionResponse<RawResponse>;
|
|
51
80
|
run: RunControl;
|
|
52
81
|
};
|
|
82
|
+
type CompletionErrorHookArgs = {
|
|
83
|
+
prompt: Message;
|
|
84
|
+
error: unknown;
|
|
85
|
+
run: RunControl;
|
|
86
|
+
};
|
|
53
87
|
type ToolHookArgs = {
|
|
54
88
|
toolName: string;
|
|
55
89
|
toolCallId?: string;
|
|
@@ -64,6 +98,10 @@ type ToolResultHookArgs = ToolHookArgs & {
|
|
|
64
98
|
structuredResult?: ToolResultContent[] | undefined;
|
|
65
99
|
run: RunControl;
|
|
66
100
|
};
|
|
101
|
+
type ToolErrorHookArgs = ToolHookArgs & {
|
|
102
|
+
error: unknown;
|
|
103
|
+
run: RunControl;
|
|
104
|
+
};
|
|
67
105
|
declare function createHook<RawResponse = unknown>(hook: PromptHook<RawResponse>): PromptHook<RawResponse>;
|
|
68
106
|
declare function cancelPrompt(reason: string): HookAction;
|
|
69
107
|
declare function skipTool(reason: string): ToolCallHookAction;
|
|
@@ -71,10 +109,17 @@ declare function requestToolApproval(options?: ToolApprovalRequestOptions): Tool
|
|
|
71
109
|
declare const runControl: RunControl;
|
|
72
110
|
declare const toolCallControl: ToolCallControl;
|
|
73
111
|
interface PromptHook<RawResponse = unknown> {
|
|
112
|
+
onRunStart?: HookCallback<RunStartHookArgs>;
|
|
113
|
+
onRunEnd?: HookCallback<RunEndHookArgs>;
|
|
114
|
+
onRunError?: HookCallback<RunErrorHookArgs>;
|
|
115
|
+
onTurnStart?: HookCallback<TurnStartHookArgs>;
|
|
116
|
+
onTurnEnd?: HookCallback<TurnEndHookArgs<RawResponse>>;
|
|
74
117
|
onCompletionCall?: HookCallback<CompletionCallHookArgs>;
|
|
75
118
|
onCompletionResponse?: HookCallback<CompletionResponseHookArgs<RawResponse>>;
|
|
119
|
+
onCompletionError?: HookCallback<CompletionErrorHookArgs>;
|
|
76
120
|
onToolCall?: ToolCallHookCallback<ToolCallHookArgs>;
|
|
77
121
|
onToolResult?: HookCallback<ToolResultHookArgs>;
|
|
122
|
+
onToolError?: HookCallback<ToolErrorHookArgs>;
|
|
78
123
|
}
|
|
79
124
|
|
|
80
125
|
type PromptResponse = {
|
|
@@ -145,16 +190,28 @@ declare class PromptRequest<M extends CompletionModel = CompletionModel> {
|
|
|
145
190
|
private activeHook;
|
|
146
191
|
private concurrency;
|
|
147
192
|
private traceOptions;
|
|
148
|
-
private
|
|
193
|
+
private requestMiddlewares;
|
|
149
194
|
private readonly memoryRecorder;
|
|
150
195
|
private constructor();
|
|
151
196
|
static fromAgent<M extends CompletionModel>(agent: Agent<M>, prompt: string | Message | Message[], options?: {
|
|
152
197
|
memoryContext?: MemoryContext | undefined;
|
|
153
198
|
}): PromptRequest<M>;
|
|
154
199
|
maxTurns(maxTurns: number): this;
|
|
200
|
+
withHook(hook: PromptHook): this;
|
|
201
|
+
/**
|
|
202
|
+
* @deprecated Use `withHook` instead.
|
|
203
|
+
*/
|
|
155
204
|
requestHook(hook: PromptHook): this;
|
|
156
205
|
withToolConcurrency(concurrency: number): this;
|
|
206
|
+
withMiddleware(middleware: AgentMiddleware): this;
|
|
207
|
+
withMiddlewares(middlewares: AgentMiddleware[]): this;
|
|
208
|
+
/**
|
|
209
|
+
* @deprecated Use `withMiddleware` instead.
|
|
210
|
+
*/
|
|
157
211
|
withToolMiddleware(middleware: ToolMiddleware): this;
|
|
212
|
+
/**
|
|
213
|
+
* @deprecated Use `withMiddlewares` instead.
|
|
214
|
+
*/
|
|
158
215
|
withToolMiddlewares(middlewares: ToolMiddleware[]): this;
|
|
159
216
|
withTrace(trace: AgentTraceOptions): this;
|
|
160
217
|
send(): Promise<PromptResponse>;
|
|
@@ -166,7 +223,16 @@ declare class PromptRequest<M extends CompletionModel = CompletionModel> {
|
|
|
166
223
|
private startRunObservers;
|
|
167
224
|
private recordAgentEvent;
|
|
168
225
|
private runCompletionCallHook;
|
|
226
|
+
private runRunStartHook;
|
|
227
|
+
private runRunEndHook;
|
|
228
|
+
private runRunErrorHook;
|
|
229
|
+
private runTurnStartHook;
|
|
230
|
+
private runTurnEndHook;
|
|
231
|
+
private runCompletionRequestMiddlewares;
|
|
232
|
+
private runCompletionResponseMiddlewares;
|
|
169
233
|
private runCompletionResponseHook;
|
|
234
|
+
private runCompletionErrorHook;
|
|
235
|
+
private activeMiddlewares;
|
|
170
236
|
private cancelled;
|
|
171
237
|
}
|
|
172
238
|
|
|
@@ -188,7 +254,11 @@ type AgentOptions<M extends CompletionModel = CompletionModel> = {
|
|
|
188
254
|
observers?: AgentObserverRegistration[] | undefined;
|
|
189
255
|
dynamicContexts?: DynamicContextRegistration[] | undefined;
|
|
190
256
|
dynamicTools?: DynamicToolRegistration[] | undefined;
|
|
191
|
-
|
|
257
|
+
middlewares?: AgentMiddleware[] | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* @deprecated Use `middlewares` instead.
|
|
260
|
+
*/
|
|
261
|
+
toolMiddlewares?: AgentMiddleware[] | undefined;
|
|
192
262
|
memory?: MemoryRegistration | undefined;
|
|
193
263
|
eventStore?: AgentEventStoreRegistration | undefined;
|
|
194
264
|
};
|
|
@@ -262,7 +332,11 @@ declare class Agent<M extends CompletionModel = CompletionModel> {
|
|
|
262
332
|
readonly observers: AgentObserverRegistration[];
|
|
263
333
|
readonly dynamicContexts: DynamicContextRegistration[];
|
|
264
334
|
readonly dynamicTools: DynamicToolRegistration[];
|
|
265
|
-
readonly
|
|
335
|
+
readonly middlewares: AgentMiddleware[];
|
|
336
|
+
/**
|
|
337
|
+
* @deprecated Use `middlewares` instead.
|
|
338
|
+
*/
|
|
339
|
+
readonly toolMiddlewares: AgentMiddleware[];
|
|
266
340
|
readonly memory: MemoryRegistration | undefined;
|
|
267
341
|
readonly eventStore: AgentEventStoreRegistration | undefined;
|
|
268
342
|
constructor(options: AgentOptions<M>);
|
|
@@ -288,4 +362,4 @@ declare class AgentSession<M extends CompletionModel = CompletionModel> {
|
|
|
288
362
|
clear(): Promise<void>;
|
|
289
363
|
}
|
|
290
364
|
|
|
291
|
-
export { type AgentChildStreamEvent as A, type
|
|
365
|
+
export { type AgentChildStreamEvent as A, type ToolHookArgs as B, type CompletionCallHookArgs as C, type DynamicContextOptions as D, type ToolResultHookArgs as E, type TurnEndHookArgs as F, type TurnStartHookArgs as G, type HookAction as H, type AgentEventStoreRegistration as I, type AgentOptions as J, AgentSession as K, type AgentToolOptions as L, DEFAULT_MAX_TURNS as M, type DynamicContextRegistration as N, type DynamicToolRegistration as O, 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 CompletionErrorHookArgs as m, type CompletionResponseHookArgs as n, type HookResult as o, type RunEndHookArgs as p, type RunErrorHookArgs as q, requestToolApproval as r, skipTool as s, toolCallControl as t, type RunStartHookArgs as u, type ToolCallControl as v, type ToolCallHookAction as w, type ToolCallHookArgs as x, type ToolCallHookResult as y, type ToolErrorHookArgs as z };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent,
|
|
3
3
|
normalizeAgentId
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ORLEOXD7.js";
|
|
5
5
|
import {
|
|
6
6
|
resolveMemoryOptions
|
|
7
7
|
} from "./chunk-XXT2UCAR.js";
|
|
8
8
|
import {
|
|
9
9
|
ToolSet
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-S7EOE6EC.js";
|
|
11
11
|
import {
|
|
12
12
|
toProviderJsonSchema
|
|
13
13
|
} from "./chunk-P425B6GR.js";
|
|
@@ -115,14 +115,26 @@ var AgentBuilder = class {
|
|
|
115
115
|
this.requestHook = hook;
|
|
116
116
|
return this;
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
middleware(middleware) {
|
|
119
119
|
this.middlewareRegistrations.push(middleware);
|
|
120
120
|
return this;
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
middlewares(middlewares) {
|
|
123
123
|
this.middlewareRegistrations.push(...middlewares);
|
|
124
124
|
return this;
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* @deprecated Use `middleware` instead.
|
|
128
|
+
*/
|
|
129
|
+
toolMiddleware(middleware) {
|
|
130
|
+
return this.middleware(middleware);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @deprecated Use `middlewares` instead.
|
|
134
|
+
*/
|
|
135
|
+
toolMiddlewares(middlewares) {
|
|
136
|
+
return this.middlewares(middlewares);
|
|
137
|
+
}
|
|
126
138
|
observe(observer, options = {}) {
|
|
127
139
|
this.observerRegistrations.push({
|
|
128
140
|
observer,
|
|
@@ -169,7 +181,7 @@ var AgentBuilder = class {
|
|
|
169
181
|
observers: this.observerRegistrations,
|
|
170
182
|
dynamicContexts: this.dynamicContextRegistrations,
|
|
171
183
|
dynamicTools: this.dynamicToolRegistrations,
|
|
172
|
-
|
|
184
|
+
middlewares: this.middlewareRegistrations,
|
|
173
185
|
memory: this.memoryRegistration,
|
|
174
186
|
eventStore: this.eventStoreRegistration
|
|
175
187
|
});
|
|
@@ -185,4 +197,4 @@ var AgentBuilder = class {
|
|
|
185
197
|
export {
|
|
186
198
|
AgentBuilder
|
|
187
199
|
};
|
|
188
|
-
//# sourceMappingURL=chunk-
|
|
200
|
+
//# sourceMappingURL=chunk-365W6FJD.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 { AgentMiddleware, 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: AgentMiddleware[] = [];\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 middleware(middleware: AgentMiddleware): this {\n this.middlewareRegistrations.push(middleware);\n return this;\n }\n\n middlewares(middlewares: AgentMiddleware[]): this {\n this.middlewareRegistrations.push(...middlewares);\n return this;\n }\n\n /**\n * @deprecated Use `middleware` instead.\n */\n toolMiddleware(middleware: ToolMiddleware): this {\n return this.middleware(middleware);\n }\n\n /**\n * @deprecated Use `middlewares` instead.\n */\n toolMiddlewares(middlewares: ToolMiddleware[]): this {\n return this.middlewares(middlewares);\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 middlewares: 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,CAAC;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,yBAAmC,CAAC;AAAA,EACpC,wBAAqD,CAAC;AAAA,EACtD,8BAA4D,CAAC;AAAA,EAC7D,2BAAsD,CAAC;AAAA,EACvD,0BAA6C,CAAC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA,gBAAgB,IAAI,QAAQ;AAAA,EASpC,KAAK,MAAoB;AACvB,SAAK,YAAY;AACjB,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,aAA2B;AACrC,SAAK,mBAAmB;AACxB,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,cAA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