@anvia/core 0.1.4 → 0.2.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 +10 -8
- package/dist/agent/index.js +5 -3
- package/dist/{agent-D5KKP9_z.d.ts → agent-CkVbMA1A.d.ts} +55 -6
- package/dist/{chunk-JDPPZCOY.js → chunk-2VCWYCPV.js} +2 -2
- package/dist/{chunk-GNWMOSNR.js → chunk-3H7FVGHU.js} +3 -3
- package/dist/chunk-3H7FVGHU.js.map +1 -0
- package/dist/{chunk-B4QHQN5K.js → chunk-445TT5Q5.js} +3 -3
- package/dist/chunk-445TT5Q5.js.map +1 -0
- package/dist/{chunk-SXLGKGKJ.js → chunk-4ILKTES4.js} +3 -3
- package/dist/{chunk-S55WOHX5.js → chunk-BT3I6O56.js} +1 -1
- package/dist/chunk-BT3I6O56.js.map +1 -0
- package/dist/{chunk-67X6U5HI.js → chunk-HGJDC56F.js} +157 -25
- package/dist/chunk-HGJDC56F.js.map +1 -0
- package/dist/{chunk-UEUE6W2X.js → chunk-JSCITGBH.js} +2 -2
- package/dist/{chunk-SRGJPXKT.js → chunk-MQVFDXPC.js} +2 -2
- package/dist/{chunk-WZTPK5HV.js → chunk-RLA7SST2.js} +12 -4
- package/dist/chunk-RLA7SST2.js.map +1 -0
- package/dist/chunk-RTOGIJH2.js +345 -0
- package/dist/chunk-RTOGIJH2.js.map +1 -0
- package/dist/{chunk-J23SIK6Y.js → chunk-X2LR54ZO.js} +4 -4
- package/dist/evals/index.d.ts +3 -3
- package/dist/evals/index.js +7 -7
- package/dist/extractor/index.d.ts +3 -3
- package/dist/extractor/index.js +6 -6
- package/dist/index.d.ts +7 -7
- package/dist/index.js +13 -11
- package/dist/mcp/index.d.ts +3 -3
- package/dist/mcp/index.js +1 -1
- package/dist/{zod-schema-Cq_9zlmJ.d.ts → middleware-2iCGCsB6.d.ts} +5 -5
- package/dist/observability/index.d.ts +6 -1
- package/dist/observability/index.js +1 -1
- package/dist/pipeline/index.d.ts +89 -14
- package/dist/pipeline/index.js +1 -1
- package/dist/skills/index.d.ts +3 -3
- package/dist/skills/index.js +5 -5
- package/dist/tool/index.d.ts +6 -6
- package/dist/tool/index.js +4 -4
- package/dist/{tool-DhuBQ3yb.d.ts → tool-DiWtAf_Q.d.ts} +10 -2
- package/dist/{types-HvopERm0.d.ts → types-21n32ltl.d.ts} +1 -1
- package/dist/{types-B5B8Sdl4.d.ts → types-ChJoZ0OH.d.ts} +1 -1
- package/dist/vector-store/index.d.ts +1 -1
- package/dist/vector-store/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-67X6U5HI.js.map +0 -1
- package/dist/chunk-B4QHQN5K.js.map +0 -1
- package/dist/chunk-FI2BTRT5.js +0 -86
- package/dist/chunk-FI2BTRT5.js.map +0 -1
- package/dist/chunk-GNWMOSNR.js.map +0 -1
- package/dist/chunk-S55WOHX5.js.map +0 -1
- package/dist/chunk-WZTPK5HV.js.map +0 -1
- /package/dist/{chunk-JDPPZCOY.js.map → chunk-2VCWYCPV.js.map} +0 -0
- /package/dist/{chunk-SXLGKGKJ.js.map → chunk-4ILKTES4.js.map} +0 -0
- /package/dist/{chunk-UEUE6W2X.js.map → chunk-JSCITGBH.js.map} +0 -0
- /package/dist/{chunk-SRGJPXKT.js.map → chunk-MQVFDXPC.js.map} +0 -0
- /package/dist/{chunk-J23SIK6Y.js.map → chunk-X2LR54ZO.js.map} +0 -0
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { MemoryStore, MemoryOptions } from '../memory/index.js';
|
|
2
2
|
export { MemoryAppendInput, MemoryContext, MemoryErrorInput, MemoryRegistration, MemorySavePolicy, ResolvedMemoryOptions, SessionOptions, resolveMemoryOptions } from '../memory/index.js';
|
|
3
|
-
import {
|
|
4
|
-
export { a as
|
|
3
|
+
import { m as DynamicContextOptions, o as DynamicToolOptions, P as PromptHook, d as AgentEventStore, f as AgentEventStoreOptions, A as Agent } from '../agent-CkVbMA1A.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-CkVbMA1A.js';
|
|
5
5
|
import { b as CompletionModel, j as JsonValue, o as ToolChoice, M as Message } from '../types-BrxLd7ay.js';
|
|
6
|
-
import { c as McpServer } from '../types-
|
|
6
|
+
import { c as McpServer } from '../types-ChJoZ0OH.js';
|
|
7
7
|
import { AgentObserver, ObserveOptions } from '../observability/index.js';
|
|
8
|
-
import { b as ToolSearchDocument, c as ToolSet, T as ToolMiddleware, Z as ZodSchema } from '../
|
|
9
|
-
import { b as SkillSet } from '../types-
|
|
10
|
-
import { A as AnyTool } from '../tool-
|
|
8
|
+
import { b as ToolSearchDocument, c as ToolSet, T as ToolMiddleware, Z as ZodSchema } from '../middleware-2iCGCsB6.js';
|
|
9
|
+
import { b as SkillSet } from '../types-21n32ltl.js';
|
|
10
|
+
import { A as AnyTool } from '../tool-DiWtAf_Q.js';
|
|
11
11
|
import { VectorSearchIndex } from '../vector-store/index.js';
|
|
12
12
|
import '@modelcontextprotocol/sdk/client/stdio.js';
|
|
13
13
|
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
14
|
-
import '../embeddings/index.js';
|
|
15
14
|
import 'zod';
|
|
15
|
+
import '../embeddings/index.js';
|
|
16
16
|
|
|
17
17
|
declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
|
|
18
18
|
private readonly completionModel;
|
|
@@ -34,6 +34,7 @@ declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
|
|
|
34
34
|
private dynamicToolRegistrations;
|
|
35
35
|
private middlewareRegistrations;
|
|
36
36
|
private memoryRegistration;
|
|
37
|
+
private eventStoreRegistration;
|
|
37
38
|
private activeToolSet;
|
|
38
39
|
constructor(agentId: string, completionModel: M);
|
|
39
40
|
name(name: string): this;
|
|
@@ -57,6 +58,7 @@ declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
|
|
|
57
58
|
toolMiddlewares(middlewares: ToolMiddleware[]): this;
|
|
58
59
|
observe(observer: AgentObserver, options?: ObserveOptions): this;
|
|
59
60
|
memory(store: MemoryStore, options?: MemoryOptions): this;
|
|
61
|
+
eventStore(store: AgentEventStore, options?: AgentEventStoreOptions): this;
|
|
60
62
|
outputSchema(schema: ZodSchema): this;
|
|
61
63
|
build(): Agent<M>;
|
|
62
64
|
private buildInstructions;
|
|
@@ -74,4 +76,4 @@ declare class PromptCancelledError extends Error {
|
|
|
74
76
|
constructor(chatHistory: Message[], reason: string);
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
export { Agent, AgentBuilder, DynamicContextOptions, DynamicToolOptions, MaxTurnsError, MemoryOptions, MemoryStore, PromptCancelledError, PromptHook };
|
|
79
|
+
export { Agent, AgentBuilder, AgentEventStore, AgentEventStoreOptions, DynamicContextOptions, DynamicToolOptions, MaxTurnsError, MemoryOptions, MemoryStore, PromptCancelledError, PromptHook };
|
package/dist/agent/index.js
CHANGED
|
@@ -8,16 +8,17 @@ import {
|
|
|
8
8
|
PromptRequest,
|
|
9
9
|
cancelPrompt,
|
|
10
10
|
createHook,
|
|
11
|
+
requestToolApproval,
|
|
11
12
|
runControl,
|
|
12
13
|
skipTool,
|
|
13
14
|
toolCallControl
|
|
14
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-HGJDC56F.js";
|
|
15
16
|
import {
|
|
16
17
|
resolveMemoryOptions
|
|
17
18
|
} from "../chunk-XXT2UCAR.js";
|
|
18
19
|
import "../chunk-YK4WAAS4.js";
|
|
19
|
-
import "../chunk-
|
|
20
|
-
import "../chunk-
|
|
20
|
+
import "../chunk-3H7FVGHU.js";
|
|
21
|
+
import "../chunk-445TT5Q5.js";
|
|
21
22
|
import "../chunk-XUUY2L2D.js";
|
|
22
23
|
import "../chunk-CP47FBJV.js";
|
|
23
24
|
export {
|
|
@@ -30,6 +31,7 @@ export {
|
|
|
30
31
|
PromptRequest,
|
|
31
32
|
cancelPrompt,
|
|
32
33
|
createHook,
|
|
34
|
+
requestToolApproval,
|
|
33
35
|
resolveMemoryOptions,
|
|
34
36
|
runControl,
|
|
35
37
|
skipTool,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { M as Message, e as CompletionResponse, 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-BrxLd7ay.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 './
|
|
5
|
-
import { T as Tool, A as AnyTool } from './tool-
|
|
4
|
+
import { T as ToolMiddleware, c as ToolSet, b as ToolSearchDocument } from './middleware-2iCGCsB6.js';
|
|
5
|
+
import { T as Tool, A as AnyTool, d as ToolCallContext } from './tool-DiWtAf_Q.js';
|
|
6
6
|
import { VectorSearchIndex, VectorFilter, VectorSearchResult } from './vector-store/index.js';
|
|
7
7
|
|
|
8
8
|
type HookAction = {
|
|
@@ -11,6 +11,10 @@ type HookAction = {
|
|
|
11
11
|
type: "terminate";
|
|
12
12
|
reason: string;
|
|
13
13
|
};
|
|
14
|
+
type ToolApprovalRequestOptions = {
|
|
15
|
+
reason?: string;
|
|
16
|
+
rejectMessage?: string;
|
|
17
|
+
};
|
|
14
18
|
type ToolCallHookAction = {
|
|
15
19
|
type: "continue";
|
|
16
20
|
} | {
|
|
@@ -19,7 +23,9 @@ type ToolCallHookAction = {
|
|
|
19
23
|
} | {
|
|
20
24
|
type: "terminate";
|
|
21
25
|
reason: string;
|
|
22
|
-
}
|
|
26
|
+
} | ({
|
|
27
|
+
type: "approval_request";
|
|
28
|
+
} & ToolApprovalRequestOptions);
|
|
23
29
|
type RunControl = {
|
|
24
30
|
continue(): HookAction;
|
|
25
31
|
cancel(reason: string): HookAction;
|
|
@@ -28,6 +34,7 @@ type ToolCallControl = {
|
|
|
28
34
|
run(): ToolCallHookAction;
|
|
29
35
|
skip(reason: string): ToolCallHookAction;
|
|
30
36
|
cancel(reason: string): ToolCallHookAction;
|
|
37
|
+
requestApproval(options?: ToolApprovalRequestOptions): ToolCallHookAction;
|
|
31
38
|
};
|
|
32
39
|
type HookResult = HookAction | undefined;
|
|
33
40
|
type ToolCallHookResult = ToolCallHookAction | undefined;
|
|
@@ -59,6 +66,7 @@ type ToolResultHookArgs = ToolHookArgs & {
|
|
|
59
66
|
declare function createHook<RawResponse = unknown>(hook: PromptHook<RawResponse>): PromptHook<RawResponse>;
|
|
60
67
|
declare function cancelPrompt(reason: string): HookAction;
|
|
61
68
|
declare function skipTool(reason: string): ToolCallHookAction;
|
|
69
|
+
declare function requestToolApproval(options?: ToolApprovalRequestOptions): ToolCallHookAction;
|
|
62
70
|
declare const runControl: RunControl;
|
|
63
71
|
declare const toolCallControl: ToolCallControl;
|
|
64
72
|
interface PromptHook<RawResponse = unknown> {
|
|
@@ -74,7 +82,7 @@ type PromptResponse = {
|
|
|
74
82
|
messages: Message[];
|
|
75
83
|
trace?: AgentTraceInfo | undefined;
|
|
76
84
|
};
|
|
77
|
-
type
|
|
85
|
+
type AgentChildStreamEvent<RawResponse = unknown> = {
|
|
78
86
|
type: "turn_start";
|
|
79
87
|
turn: number;
|
|
80
88
|
prompt: Message;
|
|
@@ -108,6 +116,7 @@ type AgentStreamEvent<RawResponse = unknown> = {
|
|
|
108
116
|
response: CompletionResponse<RawResponse>;
|
|
109
117
|
} | {
|
|
110
118
|
type: "final";
|
|
119
|
+
runId: string;
|
|
111
120
|
output: string;
|
|
112
121
|
usage: Usage;
|
|
113
122
|
messages: Message[];
|
|
@@ -116,6 +125,16 @@ type AgentStreamEvent<RawResponse = unknown> = {
|
|
|
116
125
|
type: "error";
|
|
117
126
|
error: unknown;
|
|
118
127
|
};
|
|
128
|
+
type AgentStreamEvent<RawResponse = unknown> = AgentChildStreamEvent<RawResponse> | {
|
|
129
|
+
type: "agent_tool_event";
|
|
130
|
+
turn: number;
|
|
131
|
+
toolName: string;
|
|
132
|
+
toolCallId?: string;
|
|
133
|
+
internalCallId: string;
|
|
134
|
+
agentId: string;
|
|
135
|
+
agentName?: string;
|
|
136
|
+
event: AgentChildStreamEvent<RawResponse>;
|
|
137
|
+
};
|
|
119
138
|
declare class PromptRequest<M extends CompletionModel = CompletionModel> {
|
|
120
139
|
private readonly agent;
|
|
121
140
|
private readonly promptMessage;
|
|
@@ -144,6 +163,7 @@ declare class PromptRequest<M extends CompletionModel = CompletionModel> {
|
|
|
144
163
|
private executeToolCalls;
|
|
145
164
|
private runToolResultMiddlewares;
|
|
146
165
|
private startRunObservers;
|
|
166
|
+
private recordAgentEvent;
|
|
147
167
|
private fetchDynamicContext;
|
|
148
168
|
private fetchToolDefinitions;
|
|
149
169
|
private recordToolError;
|
|
@@ -179,12 +199,40 @@ type AgentOptions<M extends CompletionModel = CompletionModel> = {
|
|
|
179
199
|
dynamicTools?: DynamicToolRegistration[] | undefined;
|
|
180
200
|
toolMiddlewares?: ToolMiddleware[] | undefined;
|
|
181
201
|
memory?: MemoryRegistration | undefined;
|
|
202
|
+
eventStore?: AgentEventStoreRegistration | undefined;
|
|
182
203
|
};
|
|
183
204
|
declare const DEFAULT_MAX_TURNS = 20;
|
|
184
205
|
type AgentToolOptions = {
|
|
185
206
|
name: string;
|
|
186
207
|
description?: string | undefined;
|
|
187
208
|
maxTurns?: number | undefined;
|
|
209
|
+
stream?: boolean | undefined;
|
|
210
|
+
};
|
|
211
|
+
type AgentEventStoreInclude = "all" | "agent_tool_events";
|
|
212
|
+
type AgentEventStoreOptions = {
|
|
213
|
+
include?: AgentEventStoreInclude | undefined;
|
|
214
|
+
};
|
|
215
|
+
type AgentEventAppendInput = {
|
|
216
|
+
runId: string;
|
|
217
|
+
agentId: string;
|
|
218
|
+
agentName?: string | undefined;
|
|
219
|
+
turn?: number | undefined;
|
|
220
|
+
toolName?: string | undefined;
|
|
221
|
+
toolCallId?: string | undefined;
|
|
222
|
+
internalCallId?: string | undefined;
|
|
223
|
+
event: unknown;
|
|
224
|
+
};
|
|
225
|
+
type AgentEventRecord = AgentEventAppendInput & {
|
|
226
|
+
createdAt?: Date | undefined;
|
|
227
|
+
};
|
|
228
|
+
interface AgentEventStore {
|
|
229
|
+
append(input: AgentEventAppendInput): Promise<void>;
|
|
230
|
+
load(runId: string): Promise<AgentEventRecord[]>;
|
|
231
|
+
clear?(runId: string): Promise<void>;
|
|
232
|
+
}
|
|
233
|
+
type AgentEventStoreRegistration = {
|
|
234
|
+
store: AgentEventStore;
|
|
235
|
+
options: Required<AgentEventStoreOptions>;
|
|
188
236
|
};
|
|
189
237
|
type DynamicContextOptions<T = unknown> = {
|
|
190
238
|
topK: number;
|
|
@@ -225,6 +273,7 @@ declare class Agent<M extends CompletionModel = CompletionModel> {
|
|
|
225
273
|
readonly dynamicTools: DynamicToolRegistration[];
|
|
226
274
|
readonly toolMiddlewares: ToolMiddleware[];
|
|
227
275
|
readonly memory: MemoryRegistration | undefined;
|
|
276
|
+
readonly eventStore: AgentEventStoreRegistration | undefined;
|
|
228
277
|
constructor(options: AgentOptions<M>);
|
|
229
278
|
prompt(prompt: string | Message | Message[]): PromptRequest<M>;
|
|
230
279
|
session(sessionId: string, options?: SessionOptions): AgentSession<M>;
|
|
@@ -232,7 +281,7 @@ declare class Agent<M extends CompletionModel = CompletionModel> {
|
|
|
232
281
|
prompt: string;
|
|
233
282
|
}, string>;
|
|
234
283
|
getTool(toolName: string): AnyTool | undefined;
|
|
235
|
-
callTool(toolName: string, args: string): Promise<string>;
|
|
284
|
+
callTool(toolName: string, args: string, context?: ToolCallContext): Promise<string>;
|
|
236
285
|
shouldApplyToolMiddleware(toolName: string): boolean;
|
|
237
286
|
}
|
|
238
287
|
declare class AgentSession<M extends CompletionModel = CompletionModel> {
|
|
@@ -248,4 +297,4 @@ declare class AgentSession<M extends CompletionModel = CompletionModel> {
|
|
|
248
297
|
clear(): Promise<void>;
|
|
249
298
|
}
|
|
250
299
|
|
|
251
|
-
export { Agent as A, type CompletionCallHookArgs as C, DEFAULT_MAX_TURNS as D, type HookAction as H, type PromptHook as P, type RunControl as R, type
|
|
300
|
+
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 };
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-YK4WAAS4.js";
|
|
4
4
|
import {
|
|
5
5
|
createTool
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-445TT5Q5.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-
|
|
398
|
+
//# sourceMappingURL=chunk-2VCWYCPV.js.map
|
|
@@ -79,7 +79,7 @@ var ToolSet = class _ToolSet {
|
|
|
79
79
|
}
|
|
80
80
|
return defs;
|
|
81
81
|
}
|
|
82
|
-
async call(toolName, args) {
|
|
82
|
+
async call(toolName, args, context) {
|
|
83
83
|
const tool = this.tools.get(toolName);
|
|
84
84
|
if (tool === void 0) {
|
|
85
85
|
throw new ToolNotFoundError(toolName);
|
|
@@ -91,7 +91,7 @@ var ToolSet = class _ToolSet {
|
|
|
91
91
|
throw new ToolJsonError(`Invalid JSON arguments for tool ${toolName}`, error);
|
|
92
92
|
}
|
|
93
93
|
try {
|
|
94
|
-
const output = await tool.call(parsedArgs);
|
|
94
|
+
const output = await tool.call(parsedArgs, context);
|
|
95
95
|
return serializeToolOutput(output);
|
|
96
96
|
} catch (error) {
|
|
97
97
|
if (error instanceof Error) {
|
|
@@ -110,4 +110,4 @@ export {
|
|
|
110
110
|
parseToolArgs,
|
|
111
111
|
ToolSet
|
|
112
112
|
};
|
|
113
|
-
//# sourceMappingURL=chunk-
|
|
113
|
+
//# sourceMappingURL=chunk-3H7FVGHU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tool/errors.ts","../src/tool/tool.ts","../src/tool/tool-set.ts"],"sourcesContent":["export class ToolCallError extends Error {\n constructor(\n message: string,\n readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"ToolCallError\";\n }\n}\n\nexport class ToolNotFoundError extends Error {\n constructor(readonly toolName: string) {\n super(`Tool not found: ${toolName}`);\n this.name = \"ToolNotFoundError\";\n }\n}\n\nexport class ToolJsonError extends Error {\n constructor(\n message: string,\n readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"ToolJsonError\";\n }\n}\n","import type { JsonObject, JsonValue, ToolDefinition } from \"../completion/types\";\n\nexport type ToolApprovalRunContext = {\n agentId: string;\n runId: string;\n sessionId?: string;\n metadata?: JsonObject;\n};\n\nexport type ToolApprovalContext<Args = unknown> = {\n toolName: string;\n args: Args;\n rawArgs: string;\n toolCallId?: string;\n internalCallId: string;\n run: ToolApprovalRunContext;\n};\n\nexport type ToolApprovalPolicy<Args = unknown> = {\n when(ctx: ToolApprovalContext<Args>): boolean | Promise<boolean>;\n reason?: string | ((ctx: ToolApprovalContext<Args>) => string | Promise<string>);\n rejectMessage?: string | ((ctx: ToolApprovalContext<Args>) => string | Promise<string>);\n};\n\nexport type ToolCallStreamEvent = {\n agentId: string;\n agentName?: string | undefined;\n event: unknown;\n};\n\nexport type ToolCallContext = {\n emitStreamEvent?(event: ToolCallStreamEvent): void | Promise<void>;\n};\n\nexport interface Tool<Args = unknown, Output = unknown> {\n readonly name: string;\n readonly approval?: ToolApprovalPolicy<Args>;\n definition(prompt: string): ToolDefinition | Promise<ToolDefinition>;\n call(args: Args, context?: ToolCallContext): Output | Promise<Output>;\n parseApprovalArgs?(args: unknown): Args;\n}\n\nexport type AnyTool = Omit<Tool<unknown, unknown>, \"approval\"> & {\n readonly approval?: unknown;\n};\n\nexport function serializeToolOutput(output: unknown): string {\n if (typeof output === \"string\") {\n return output;\n }\n\n const serialized = JSON.stringify(output);\n return serialized === undefined ? String(output) : serialized;\n}\n\nexport function parseToolArgs(args: string): JsonValue {\n if (args.trim() === \"\") {\n return {};\n }\n\n return JSON.parse(args) as JsonValue;\n}\n","import type { ToolDefinition } from \"../completion/types\";\nimport { ToolCallError, ToolJsonError, ToolNotFoundError } from \"./errors\";\nimport { type AnyTool, parseToolArgs, serializeToolOutput, type ToolCallContext } from \"./tool\";\n\nexport class ToolSet {\n private readonly tools = new Map<string, AnyTool>();\n\n static fromTools(tools: AnyTool[]): ToolSet {\n const toolSet = new ToolSet();\n for (const tool of tools) {\n toolSet.addTool(tool);\n }\n return toolSet;\n }\n\n addTool(tool: AnyTool): this {\n this.tools.set(tool.name, tool);\n return this;\n }\n\n addTools(tools: AnyTool[] | ToolSet): this {\n const values = Array.isArray(tools) ? tools : tools.values();\n for (const tool of values) {\n this.addTool(tool);\n }\n return this;\n }\n\n deleteTool(toolName: string): boolean {\n return this.tools.delete(toolName);\n }\n\n contains(toolName: string): boolean {\n return this.tools.has(toolName);\n }\n\n get(toolName: string): AnyTool | undefined {\n return this.tools.get(toolName);\n }\n\n values(): AnyTool[] {\n return [...this.tools.values()];\n }\n\n async getToolDefinitions(prompt = \"\"): Promise<ToolDefinition[]> {\n const defs: ToolDefinition[] = [];\n for (const tool of this.tools.values()) {\n defs.push(await tool.definition(prompt));\n }\n return defs;\n }\n\n async call(toolName: string, args: string, context?: ToolCallContext): Promise<string> {\n const tool = this.tools.get(toolName);\n if (tool === undefined) {\n throw new ToolNotFoundError(toolName);\n }\n\n let parsedArgs: unknown;\n try {\n parsedArgs = parseToolArgs(args);\n } catch (error) {\n throw new ToolJsonError(`Invalid JSON arguments for tool ${toolName}`, error);\n }\n\n try {\n const output = await tool.call(parsedArgs, context);\n return serializeToolOutput(output);\n } catch (error) {\n if (error instanceof Error) {\n throw new ToolCallError(error.message, error);\n }\n throw new ToolCallError(`Tool ${toolName} failed`, error);\n }\n }\n}\n"],"mappings":";AAAO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACvC,YACE,SACS,OACT;AACA,UAAM,OAAO;AAFJ;AAGT,SAAK,OAAO;AAAA,EACd;AAAA,EAJW;AAKb;AAEO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YAAqB,UAAkB;AACrC,UAAM,mBAAmB,QAAQ,EAAE;AADhB;AAEnB,SAAK,OAAO;AAAA,EACd;AAAA,EAHqB;AAIvB;AAEO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACvC,YACE,SACS,OACT;AACA,UAAM,OAAO;AAFJ;AAGT,SAAK,OAAO;AAAA,EACd;AAAA,EAJW;AAKb;;;ACqBO,SAAS,oBAAoB,QAAyB;AAC3D,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,KAAK,UAAU,MAAM;AACxC,SAAO,eAAe,SAAY,OAAO,MAAM,IAAI;AACrD;AAEO,SAAS,cAAc,MAAyB;AACrD,MAAI,KAAK,KAAK,MAAM,IAAI;AACtB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,KAAK,MAAM,IAAI;AACxB;;;ACzDO,IAAM,UAAN,MAAM,SAAQ;AAAA,EACF,QAAQ,oBAAI,IAAqB;AAAA,EAElD,OAAO,UAAU,OAA2B;AAC1C,UAAM,UAAU,IAAI,SAAQ;AAC5B,eAAW,QAAQ,OAAO;AACxB,cAAQ,QAAQ,IAAI;AAAA,IACtB;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,MAAqB;AAC3B,SAAK,MAAM,IAAI,KAAK,MAAM,IAAI;AAC9B,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,OAAkC;AACzC,UAAM,SAAS,MAAM,QAAQ,KAAK,IAAI,QAAQ,MAAM,OAAO;AAC3D,eAAW,QAAQ,QAAQ;AACzB,WAAK,QAAQ,IAAI;AAAA,IACnB;AACA,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,UAA2B;AACpC,WAAO,KAAK,MAAM,OAAO,QAAQ;AAAA,EACnC;AAAA,EAEA,SAAS,UAA2B;AAClC,WAAO,KAAK,MAAM,IAAI,QAAQ;AAAA,EAChC;AAAA,EAEA,IAAI,UAAuC;AACzC,WAAO,KAAK,MAAM,IAAI,QAAQ;AAAA,EAChC;AAAA,EAEA,SAAoB;AAClB,WAAO,CAAC,GAAG,KAAK,MAAM,OAAO,CAAC;AAAA,EAChC;AAAA,EAEA,MAAM,mBAAmB,SAAS,IAA+B;AAC/D,UAAM,OAAyB,CAAC;AAChC,eAAW,QAAQ,KAAK,MAAM,OAAO,GAAG;AACtC,WAAK,KAAK,MAAM,KAAK,WAAW,MAAM,CAAC;AAAA,IACzC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,KAAK,UAAkB,MAAc,SAA4C;AACrF,UAAM,OAAO,KAAK,MAAM,IAAI,QAAQ;AACpC,QAAI,SAAS,QAAW;AACtB,YAAM,IAAI,kBAAkB,QAAQ;AAAA,IACtC;AAEA,QAAI;AACJ,QAAI;AACF,mBAAa,cAAc,IAAI;AAAA,IACjC,SAAS,OAAO;AACd,YAAM,IAAI,cAAc,mCAAmC,QAAQ,IAAI,KAAK;AAAA,IAC9E;AAEA,QAAI;AACF,YAAM,SAAS,MAAM,KAAK,KAAK,YAAY,OAAO;AAClD,aAAO,oBAAoB,MAAM;AAAA,IACnC,SAAS,OAAO;AACd,UAAI,iBAAiB,OAAO;AAC1B,cAAM,IAAI,cAAc,MAAM,SAAS,KAAK;AAAA,MAC9C;AACA,YAAM,IAAI,cAAc,QAAQ,QAAQ,WAAW,KAAK;AAAA,IAC1D;AAAA,EACF;AACF;","names":[]}
|
|
@@ -19,9 +19,9 @@ function createTool(options) {
|
|
|
19
19
|
parameters
|
|
20
20
|
};
|
|
21
21
|
},
|
|
22
|
-
async call(args) {
|
|
22
|
+
async call(args, context = {}) {
|
|
23
23
|
const parsedArgs = options.input.parse(args);
|
|
24
|
-
const result = await options.execute(parsedArgs);
|
|
24
|
+
const result = await options.execute(parsedArgs, context);
|
|
25
25
|
return options.output === void 0 ? result : options.output.parse(result);
|
|
26
26
|
},
|
|
27
27
|
parseApprovalArgs(args) {
|
|
@@ -34,4 +34,4 @@ export {
|
|
|
34
34
|
toProviderJsonSchema,
|
|
35
35
|
createTool
|
|
36
36
|
};
|
|
37
|
-
//# sourceMappingURL=chunk-
|
|
37
|
+
//# sourceMappingURL=chunk-445TT5Q5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema/zod-schema.ts","../src/tool/create-tool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { JsonObject } from \"../completion/index\";\n\nexport type ZodSchema<T = unknown> = z.ZodType<T>;\n\nexport function toProviderJsonSchema(schema: z.ZodType): JsonObject {\n const jsonSchema = z.toJSONSchema(schema) as JsonObject;\n const { $schema: _schema, ...providerSchema } = jsonSchema;\n return providerSchema;\n}\n","import type { z } from \"zod\";\nimport { toProviderJsonSchema, type ZodSchema } from \"../schema/zod-schema\";\nimport type { Tool, ToolApprovalPolicy, ToolCallContext } from \"./tool\";\n\nexport type CreateToolOptions<\n InputSchema extends ZodSchema,\n OutputSchema extends ZodSchema | undefined = undefined,\n> = {\n name: string;\n description: string;\n input: InputSchema;\n output?: OutputSchema;\n approval?: ToolApprovalPolicy<z.output<InputSchema>>;\n execute(\n args: z.output<InputSchema>,\n context: ToolCallContext,\n ): OutputSchema extends ZodSchema\n ? z.input<OutputSchema> | Promise<z.input<OutputSchema>>\n : unknown | Promise<unknown>;\n};\n\ntype ToolOutput<OutputSchema extends ZodSchema | undefined> = OutputSchema extends ZodSchema\n ? z.output<OutputSchema>\n : unknown;\n\nexport function createTool<\n InputSchema extends ZodSchema,\n OutputSchema extends ZodSchema | undefined = undefined,\n>(\n options: CreateToolOptions<InputSchema, OutputSchema>,\n): Tool<z.output<InputSchema>, ToolOutput<OutputSchema>> {\n const parameters = toProviderJsonSchema(options.input);\n\n return {\n name: options.name,\n ...(options.approval === undefined ? {} : { approval: options.approval }),\n definition() {\n return {\n name: options.name,\n description: options.description,\n parameters,\n };\n },\n async call(args, context = {}): Promise<ToolOutput<OutputSchema>> {\n const parsedArgs = options.input.parse(args);\n const result = await options.execute(parsedArgs, context);\n return (\n options.output === undefined ? result : options.output.parse(result)\n ) as ToolOutput<OutputSchema>;\n },\n parseApprovalArgs(args): z.output<InputSchema> {\n return options.input.parse(args);\n },\n };\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAKX,SAAS,qBAAqB,QAA+B;AAClE,QAAM,aAAa,EAAE,aAAa,MAAM;AACxC,QAAM,EAAE,SAAS,SAAS,GAAG,eAAe,IAAI;AAChD,SAAO;AACT;;;ACgBO,SAAS,WAId,SACuD;AACvD,QAAM,aAAa,qBAAqB,QAAQ,KAAK;AAErD,SAAO;AAAA,IACL,MAAM,QAAQ;AAAA,IACd,GAAI,QAAQ,aAAa,SAAY,CAAC,IAAI,EAAE,UAAU,QAAQ,SAAS;AAAA,IACvE,aAAa;AACX,aAAO;AAAA,QACL,MAAM,QAAQ;AAAA,QACd,aAAa,QAAQ;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAAA,IACA,MAAM,KAAK,MAAM,UAAU,CAAC,GAAsC;AAChE,YAAM,aAAa,QAAQ,MAAM,MAAM,IAAI;AAC3C,YAAM,SAAS,MAAM,QAAQ,QAAQ,YAAY,OAAO;AACxD,aACE,QAAQ,WAAW,SAAY,SAAS,QAAQ,OAAO,MAAM,MAAM;AAAA,IAEvE;AAAA,IACA,kBAAkB,MAA6B;AAC7C,aAAO,QAAQ,MAAM,MAAM,IAAI;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentBuilder
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HGJDC56F.js";
|
|
4
4
|
import {
|
|
5
5
|
createTool
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-445TT5Q5.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-
|
|
142
|
+
//# sourceMappingURL=chunk-4ILKTES4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/observability/types.ts"],"sourcesContent":["import type {\n CompletionRequest,\n CompletionResponse,\n Message,\n ToolCall,\n Usage,\n} from \"../completion\";\nimport type { ToolCallStreamEvent } from \"../tool\";\n\nexport type AgentTraceInfo = {\n traceId?: string | undefined;\n observationId?: string | undefined;\n};\n\nexport type AgentTraceOptions = {\n name?: string | undefined;\n userId?: string | undefined;\n sessionId?: string | undefined;\n metadata?: Record<string, unknown> | undefined;\n tags?: string[] | undefined;\n version?: string | undefined;\n traceId?: string | undefined;\n failOnObserverError?: boolean | undefined;\n};\n\nexport type AgentRunStartArgs = {\n agentName?: string | undefined;\n agentDescription?: string | undefined;\n instructions?: string | undefined;\n trace?: AgentTraceOptions | undefined;\n prompt: Message;\n history: Message[];\n maxTurns: number;\n};\n\nexport type AgentRunEndArgs = {\n output: string;\n usage: Usage;\n messages: Message[];\n};\n\nexport type AgentRunErrorArgs = {\n error: unknown;\n usage: Usage;\n messages: Message[];\n};\n\nexport type AgentGenerationStartArgs = {\n turn: number;\n request: CompletionRequest;\n};\n\nexport type AgentGenerationEndArgs<RawResponse = unknown> = {\n turn: number;\n response: CompletionResponse<RawResponse>;\n firstDeltaMs?: number | undefined;\n};\n\nexport type AgentGenerationErrorArgs = {\n turn: number;\n error: unknown;\n};\n\nexport type AgentToolStartArgs = {\n turn: number;\n toolCall: ToolCall;\n toolName: string;\n args: string;\n internalCallId: string;\n toolCallId?: string | undefined;\n};\n\nexport type AgentToolEndArgs = AgentToolStartArgs & {\n result: string;\n skipped: boolean;\n};\n\nexport type AgentToolErrorArgs = AgentToolStartArgs & {\n error: unknown;\n};\n\nexport type AgentToolStreamEventArgs = AgentToolStartArgs & {\n event: ToolCallStreamEvent;\n};\n\nexport interface AgentGenerationObserver {\n end(args: AgentGenerationEndArgs): void | Promise<void>;\n error?(args: AgentGenerationErrorArgs): void | Promise<void>;\n}\n\nexport interface AgentToolObserver {\n streamEvent?(args: AgentToolStreamEventArgs): void | Promise<void>;\n end(args: AgentToolEndArgs): void | Promise<void>;\n error?(args: AgentToolErrorArgs): void | Promise<void>;\n}\n\nexport interface AgentRunObserver {\n readonly trace?: AgentTraceInfo | undefined;\n startGeneration?(\n args: AgentGenerationStartArgs,\n ): AgentGenerationObserver | undefined | Promise<AgentGenerationObserver | undefined>;\n startTool?(\n args: AgentToolStartArgs,\n ): AgentToolObserver | undefined | Promise<AgentToolObserver | undefined>;\n end(args: AgentRunEndArgs): void | Promise<void>;\n error?(args: AgentRunErrorArgs): void | Promise<void>;\n}\n\nexport interface AgentObserver {\n startRun(\n args: AgentRunStartArgs,\n ): AgentRunObserver | undefined | Promise<AgentRunObserver | undefined>;\n flush?(): void | Promise<void>;\n shutdown?(): void | Promise<void>;\n}\n\nexport type AgentObserverRegistration = {\n observer: AgentObserver;\n failOnObserverError?: boolean | undefined;\n};\n\nexport type ObserveOptions = {\n failOnObserverError?: boolean | undefined;\n};\n\nexport function createObserver(observer: AgentObserver): AgentObserver {\n return observer;\n}\n"],"mappings":";AA6HO,SAAS,eAAe,UAAwC;AACrE,SAAO;AACT;","names":[]}
|