@anvia/core 0.11.3 → 0.12.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.
- package/dist/agent/index.d.ts +6 -3
- package/dist/agent/index.js +8 -7
- package/dist/{agent-Bcpuodu2.d.ts → agent-BBj3jvBi.d.ts} +11 -2
- package/dist/{chunk-7CQAERL3.js → chunk-CO7YK4JZ.js} +333 -103
- package/dist/chunk-CO7YK4JZ.js.map +1 -0
- package/dist/chunk-CWUJUSOS.js +291 -0
- package/dist/chunk-CWUJUSOS.js.map +1 -0
- package/dist/{chunk-FV5B4SGK.js → chunk-GISFLLNL.js} +5 -5
- package/dist/{chunk-V3WTT7TE.js → chunk-HF4KHHNM.js} +2 -2
- package/dist/{chunk-5EDHXYH5.js → chunk-IZM6FNCT.js} +8 -5
- package/dist/chunk-IZM6FNCT.js.map +1 -0
- package/dist/{chunk-MLMXQ2OV.js → chunk-J4XZCE4A.js} +9 -7
- package/dist/chunk-J4XZCE4A.js.map +1 -0
- package/dist/{chunk-2GXGB6U5.js → chunk-L62HQ5Y4.js} +4 -4
- package/dist/{chunk-NI637AGP.js → chunk-MX6ATKGT.js} +12 -3
- package/dist/chunk-MX6ATKGT.js.map +1 -0
- package/dist/evals/index.d.ts +3 -2
- package/dist/evals/index.js +11 -10
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +3 -2
- package/dist/extractor/index.js +9 -8
- package/dist/guardrails/index.d.ts +133 -0
- package/dist/guardrails/index.js +27 -0
- package/dist/guardrails/index.js.map +1 -0
- package/dist/{index-CD9jb9Or.d.ts → index-Oucb3Ljj.d.ts} +7 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +28 -14
- package/dist/internal/agent.d.ts +3 -2
- package/dist/internal/agent.js +7 -6
- package/dist/observability/index.d.ts +2 -1
- package/dist/pipeline/index.d.ts +3 -2
- package/dist/pipeline/index.js +3 -3
- package/dist/request/index.d.ts +3 -2
- package/dist/request/index.js +6 -5
- package/dist/skills/index.js +4 -4
- package/dist/tool/index.js +3 -3
- package/dist/vector-store/index.js +2 -2
- package/package.json +6 -2
- package/dist/chunk-5EDHXYH5.js.map +0 -1
- package/dist/chunk-7CQAERL3.js.map +0 -1
- package/dist/chunk-MLMXQ2OV.js.map +0 -1
- package/dist/chunk-NI637AGP.js.map +0 -1
- /package/dist/{chunk-FV5B4SGK.js.map → chunk-GISFLLNL.js.map} +0 -0
- /package/dist/{chunk-V3WTT7TE.js.map → chunk-HF4KHHNM.js.map} +0 -0
- /package/dist/{chunk-2GXGB6U5.js.map → chunk-L62HQ5Y4.js.map} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { M as Message, J as JsonObject, U as Usage } from '../types-q9G7Bvwl.js';
|
|
2
|
+
|
|
3
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
4
|
+
type GuardrailMode = "enforce" | "observe";
|
|
5
|
+
type GuardrailBoundary = "input" | "output";
|
|
6
|
+
type GuardrailRunContext = {
|
|
7
|
+
agentId: string;
|
|
8
|
+
runId: string;
|
|
9
|
+
sessionId?: string | undefined;
|
|
10
|
+
metadata?: JsonObject | undefined;
|
|
11
|
+
};
|
|
12
|
+
type GuardrailDecisionRecord = {
|
|
13
|
+
policyId: string;
|
|
14
|
+
guardrailId: string;
|
|
15
|
+
boundary: GuardrailBoundary;
|
|
16
|
+
mode: GuardrailMode;
|
|
17
|
+
action: GuardrailActionName;
|
|
18
|
+
applied: boolean;
|
|
19
|
+
reason?: string | undefined;
|
|
20
|
+
message?: string | undefined;
|
|
21
|
+
metadata?: JsonObject | undefined;
|
|
22
|
+
latencyMs: number;
|
|
23
|
+
};
|
|
24
|
+
type GuardrailActionName = "allow" | "block" | "rewrite" | "error";
|
|
25
|
+
type GuardrailActionBase = {
|
|
26
|
+
reason?: string | undefined;
|
|
27
|
+
metadata?: JsonObject | undefined;
|
|
28
|
+
};
|
|
29
|
+
type GuardrailAllow = GuardrailActionBase & {
|
|
30
|
+
action: "allow";
|
|
31
|
+
};
|
|
32
|
+
type GuardrailBlock = GuardrailActionBase & {
|
|
33
|
+
action: "block";
|
|
34
|
+
reason: string;
|
|
35
|
+
message?: string | undefined;
|
|
36
|
+
};
|
|
37
|
+
type InputGuardrailRewrite = GuardrailActionBase & {
|
|
38
|
+
action: "rewrite";
|
|
39
|
+
prompt?: Message | undefined;
|
|
40
|
+
inputText?: string | undefined;
|
|
41
|
+
};
|
|
42
|
+
type OutputGuardrailRewrite = GuardrailActionBase & {
|
|
43
|
+
action: "rewrite";
|
|
44
|
+
outputText: string;
|
|
45
|
+
};
|
|
46
|
+
type InputGuardrailResult = GuardrailAllow | GuardrailBlock | InputGuardrailRewrite;
|
|
47
|
+
type OutputGuardrailResult = GuardrailAllow | GuardrailBlock | OutputGuardrailRewrite;
|
|
48
|
+
type GuardrailCommonActions = {
|
|
49
|
+
allow(options?: GuardrailActionBase): GuardrailAllow;
|
|
50
|
+
block(options: Omit<GuardrailBlock, "action">): GuardrailBlock;
|
|
51
|
+
};
|
|
52
|
+
type InputGuardrailActions = GuardrailCommonActions & {
|
|
53
|
+
rewrite(options: Omit<InputGuardrailRewrite, "action">): InputGuardrailRewrite;
|
|
54
|
+
};
|
|
55
|
+
type OutputGuardrailActions = GuardrailCommonActions & {
|
|
56
|
+
rewrite(options: Omit<OutputGuardrailRewrite, "action">): OutputGuardrailRewrite;
|
|
57
|
+
};
|
|
58
|
+
type InputGuardrailContext = {
|
|
59
|
+
prompt: Message;
|
|
60
|
+
history: Message[];
|
|
61
|
+
inputText: string;
|
|
62
|
+
run: GuardrailRunContext;
|
|
63
|
+
};
|
|
64
|
+
type OutputGuardrailContext = {
|
|
65
|
+
outputText: string;
|
|
66
|
+
messages: Message[];
|
|
67
|
+
usage: Usage;
|
|
68
|
+
run: GuardrailRunContext;
|
|
69
|
+
};
|
|
70
|
+
type InputGuardrail = {
|
|
71
|
+
id: string;
|
|
72
|
+
check(context: InputGuardrailContext, actions: InputGuardrailActions): MaybePromise<InputGuardrailResult | undefined>;
|
|
73
|
+
};
|
|
74
|
+
type OutputGuardrail = {
|
|
75
|
+
id: string;
|
|
76
|
+
check(context: OutputGuardrailContext, actions: OutputGuardrailActions): MaybePromise<OutputGuardrailResult | undefined>;
|
|
77
|
+
};
|
|
78
|
+
type GuardrailPolicy = {
|
|
79
|
+
id: string;
|
|
80
|
+
mode: GuardrailMode;
|
|
81
|
+
input: InputGuardrail[];
|
|
82
|
+
output: OutputGuardrail[];
|
|
83
|
+
};
|
|
84
|
+
type GuardrailPolicyOptions = {
|
|
85
|
+
id: string;
|
|
86
|
+
mode?: GuardrailMode | undefined;
|
|
87
|
+
input?: InputGuardrail[] | undefined;
|
|
88
|
+
output?: OutputGuardrail[] | undefined;
|
|
89
|
+
};
|
|
90
|
+
type GuardrailPolicyInput = GuardrailPolicy | GuardrailPolicy[];
|
|
91
|
+
type InputGuardrailRunResult = {
|
|
92
|
+
prompt: Message;
|
|
93
|
+
inputText: string;
|
|
94
|
+
blocked: boolean;
|
|
95
|
+
message?: string | undefined;
|
|
96
|
+
decisions: GuardrailDecisionRecord[];
|
|
97
|
+
};
|
|
98
|
+
type OutputGuardrailRunResult = {
|
|
99
|
+
outputText: string;
|
|
100
|
+
blocked: boolean;
|
|
101
|
+
message?: string | undefined;
|
|
102
|
+
decisions: GuardrailDecisionRecord[];
|
|
103
|
+
};
|
|
104
|
+
declare function defineGuardrailPolicy(options: GuardrailPolicyOptions): GuardrailPolicy;
|
|
105
|
+
declare function defineInputGuardrail(guardrail: InputGuardrail): InputGuardrail;
|
|
106
|
+
declare function defineOutputGuardrail(guardrail: OutputGuardrail): OutputGuardrail;
|
|
107
|
+
declare function allow(options?: GuardrailActionBase): GuardrailAllow;
|
|
108
|
+
declare function block(options: Omit<GuardrailBlock, "action">): GuardrailBlock;
|
|
109
|
+
declare const guardrails: {
|
|
110
|
+
blockText: typeof blockText;
|
|
111
|
+
redactText: typeof redactText;
|
|
112
|
+
};
|
|
113
|
+
declare function normalizeGuardrailPolicies(policies: GuardrailPolicyInput | undefined): GuardrailPolicy[];
|
|
114
|
+
declare function appendGuardrailPolicies(current: GuardrailPolicy[], next: GuardrailPolicyInput): GuardrailPolicy[];
|
|
115
|
+
declare function hasEnforcedOutputGuardrails(policies: GuardrailPolicy[]): boolean;
|
|
116
|
+
declare function runInputGuardrails(policies: GuardrailPolicy[], context: InputGuardrailContext): Promise<InputGuardrailRunResult>;
|
|
117
|
+
declare function runOutputGuardrails(policies: GuardrailPolicy[], context: OutputGuardrailContext): Promise<OutputGuardrailRunResult>;
|
|
118
|
+
type TextPatternBoundary = "input" | "output";
|
|
119
|
+
type TextPatternGuardrailFor<Boundary extends TextPatternBoundary> = Boundary extends "input" ? InputGuardrail : OutputGuardrail;
|
|
120
|
+
type TextPatternGuardrailOptions<Boundary extends TextPatternBoundary = TextPatternBoundary> = {
|
|
121
|
+
id: string;
|
|
122
|
+
boundary: Boundary;
|
|
123
|
+
patterns: Array<string | RegExp>;
|
|
124
|
+
reason: string;
|
|
125
|
+
message?: string | undefined;
|
|
126
|
+
};
|
|
127
|
+
type TextPatternRedactOptions<Boundary extends TextPatternBoundary = TextPatternBoundary> = TextPatternGuardrailOptions<Boundary> & {
|
|
128
|
+
replacement?: string | undefined;
|
|
129
|
+
};
|
|
130
|
+
declare function blockText<Boundary extends TextPatternBoundary>(options: TextPatternGuardrailOptions<Boundary>): TextPatternGuardrailFor<Boundary>;
|
|
131
|
+
declare function redactText<Boundary extends TextPatternBoundary>(options: TextPatternRedactOptions<Boundary>): TextPatternGuardrailFor<Boundary>;
|
|
132
|
+
|
|
133
|
+
export { type GuardrailActionBase, type GuardrailActionName, type GuardrailAllow, type GuardrailBlock, type GuardrailBoundary, type GuardrailCommonActions, type GuardrailDecisionRecord, type GuardrailMode, type GuardrailPolicy, type GuardrailPolicyInput, type GuardrailPolicyOptions, type GuardrailRunContext, type InputGuardrail, type InputGuardrailActions, type InputGuardrailContext, type InputGuardrailResult, type InputGuardrailRewrite, type InputGuardrailRunResult, type OutputGuardrail, type OutputGuardrailActions, type OutputGuardrailContext, type OutputGuardrailResult, type OutputGuardrailRewrite, type OutputGuardrailRunResult, allow, appendGuardrailPolicies, block, defineGuardrailPolicy, defineInputGuardrail, defineOutputGuardrail, guardrails, hasEnforcedOutputGuardrails, normalizeGuardrailPolicies, runInputGuardrails, runOutputGuardrails };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
allow,
|
|
3
|
+
appendGuardrailPolicies,
|
|
4
|
+
block,
|
|
5
|
+
defineGuardrailPolicy,
|
|
6
|
+
defineInputGuardrail,
|
|
7
|
+
defineOutputGuardrail,
|
|
8
|
+
guardrails,
|
|
9
|
+
hasEnforcedOutputGuardrails,
|
|
10
|
+
normalizeGuardrailPolicies,
|
|
11
|
+
runInputGuardrails,
|
|
12
|
+
runOutputGuardrails
|
|
13
|
+
} from "../chunk-CWUJUSOS.js";
|
|
14
|
+
export {
|
|
15
|
+
allow,
|
|
16
|
+
appendGuardrailPolicies,
|
|
17
|
+
block,
|
|
18
|
+
defineGuardrailPolicy,
|
|
19
|
+
defineInputGuardrail,
|
|
20
|
+
defineOutputGuardrail,
|
|
21
|
+
guardrails,
|
|
22
|
+
hasEnforcedOutputGuardrails,
|
|
23
|
+
normalizeGuardrailPolicies,
|
|
24
|
+
runInputGuardrails,
|
|
25
|
+
runOutputGuardrails
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { x as ReasoningContentType, f as ToolCall, U as Usage, M as Message, k as ToolResultContent, c as CompletionResponse, b as CompletionRequest, J as JsonObject, t as CompletionModelCapabilities, h as ToolDefinition, e as JsonValue } from './types-q9G7Bvwl.js';
|
|
2
|
+
import { GuardrailDecisionRecord } from './guardrails/index.js';
|
|
2
3
|
import { g as ToolCallStreamEvent } from './tool-B8K543oQ.js';
|
|
3
4
|
|
|
4
5
|
type PromptResponse = {
|
|
@@ -6,6 +7,7 @@ type PromptResponse = {
|
|
|
6
7
|
usage: Usage;
|
|
7
8
|
messages: Message[];
|
|
8
9
|
trace?: AgentTraceInfo | undefined;
|
|
10
|
+
guardrails?: GuardrailDecisionRecord[] | undefined;
|
|
9
11
|
};
|
|
10
12
|
type AgentDeltaEvent = {
|
|
11
13
|
type: "text_delta";
|
|
@@ -53,6 +55,10 @@ type AgentChildStreamEvent<RawResponse = unknown> = {
|
|
|
53
55
|
type: "turn_end";
|
|
54
56
|
turn: number;
|
|
55
57
|
response: CompletionResponse<RawResponse>;
|
|
58
|
+
} | {
|
|
59
|
+
type: "guardrail_decision";
|
|
60
|
+
turn?: number | undefined;
|
|
61
|
+
decision: GuardrailDecisionRecord;
|
|
56
62
|
} | {
|
|
57
63
|
type: "final";
|
|
58
64
|
runId: string;
|
|
@@ -60,6 +66,7 @@ type AgentChildStreamEvent<RawResponse = unknown> = {
|
|
|
60
66
|
usage: Usage;
|
|
61
67
|
messages: Message[];
|
|
62
68
|
trace?: AgentTraceInfo | undefined;
|
|
69
|
+
guardrails?: GuardrailDecisionRecord[] | undefined;
|
|
63
70
|
} | {
|
|
64
71
|
type: "error";
|
|
65
72
|
error: unknown;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { AgentBuilder } from './agent/index.js';
|
|
2
2
|
export { C as CreateCompletionBaseOptions, a as CreateCompletionInput, b as CreateCompletionOptions, c as CreateCompletionResult, d as CreateCompletionStreamOptions, e as CreateParsedCompletionOptions, f as CreateParsedCompletionResult, g as createCompletion, h as createCompletionStream, i as createParsedCompletion } from './create-completion-Y6YsYbQB.js';
|
|
3
3
|
export { A as AssistantContent, a as AssistantMessage, C as CompletionModel, b as CompletionRequest, c as CompletionResponse, D as Document, I as ImageContent, J as JsonObject, d as JsonPrimitive, e as JsonValue, M as Message, S as SystemMessage, T as Text, f as ToolCall, g as ToolContent, h as ToolDefinition, i as ToolMessage, j as ToolResult, k as ToolResultContent, U as Usage, l as UserContent, m as UserMessage } from './types-q9G7Bvwl.js';
|
|
4
|
+
export { GuardrailBoundary, GuardrailDecisionRecord, GuardrailMode, GuardrailPolicy, GuardrailPolicyInput, GuardrailPolicyOptions, InputGuardrail, InputGuardrailActions, InputGuardrailContext, OutputGuardrail, OutputGuardrailActions, OutputGuardrailContext, allow, block, defineGuardrailPolicy, defineInputGuardrail, defineOutputGuardrail, guardrails } from './guardrails/index.js';
|
|
4
5
|
export { cancelPrompt, createHook, requestToolApproval, runControl, skipTool, toolCallControl } from './hooks/index.js';
|
|
5
6
|
export { M as MemoryStore } from './types-CqG6d7Ce.js';
|
|
6
7
|
export { MaxTurnsError, PromptCancelledError, ToolApprovalRequiredError } from './request/index.js';
|
|
7
|
-
export { A as AgentChildStreamEvent, a as AgentStreamEvent, P as PromptResponse } from './index-
|
|
8
|
+
export { A as AgentChildStreamEvent, a as AgentStreamEvent, P as PromptResponse } from './index-Oucb3Ljj.js';
|
|
8
9
|
export { Z as ZodSchema } from './zod-schema-C7F4clpm.js';
|
|
9
10
|
export { loadSkills, skill } from './skills/index.js';
|
|
10
11
|
export { S as SkillValidationError } from './types-BzUuhjKr.js';
|
|
@@ -12,7 +13,7 @@ export { C as CreateToolOptions, c as createThinkTool, a as createTool } from '.
|
|
|
12
13
|
export { A as AnyTool, T as Tool, a as ToolApprovalContext, b as ToolApprovalDecision, c as ToolApprovalPolicy, d as ToolApprovalRequest, e as ToolApprovalsOptions, f as ToolCallContext, g as ToolCallStreamEvent } from './tool-B8K543oQ.js';
|
|
13
14
|
export { A as AgentMiddleware, C as CompletionRequestMiddlewareArgs, a as CompletionRequestMiddlewareResult, b as CompletionResponseMiddlewareArgs, c as CompletionResponseMiddlewareResult, T as ToolInputMiddlewareArgs, d as ToolInputMiddlewareResult, e as ToolMiddleware, f as ToolOutputMiddlewareArgs, g as ToolOutputMiddlewareResult, h as ToolResultMiddlewareArgs, i as createMiddleware, j as createToolMiddleware } from './middleware-ByyL6Rj0.js';
|
|
14
15
|
export { UIError, UIMessage, UIMessagePart, UIMessageRole, UIStreamEvent, UIStreamRequest, coreMessagesToUIMessages, uiMessagesToCoreMessages } from './ui/index.js';
|
|
15
|
-
import './agent-
|
|
16
|
+
import './agent-BBj3jvBi.js';
|
|
16
17
|
import './types-CGML74sE.js';
|
|
17
18
|
import './types-Pl4PFQWL.js';
|
|
18
19
|
import './types-DHHZztGO.js';
|
package/dist/index.js
CHANGED
|
@@ -2,30 +2,39 @@ import {
|
|
|
2
2
|
SkillValidationError,
|
|
3
3
|
loadSkills,
|
|
4
4
|
skill
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-HF4KHHNM.js";
|
|
6
6
|
import {
|
|
7
7
|
coreMessagesToUIMessages,
|
|
8
8
|
uiMessagesToCoreMessages
|
|
9
9
|
} from "./chunk-JNO4AR7Q.js";
|
|
10
10
|
import {
|
|
11
11
|
AgentBuilder
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-MX6ATKGT.js";
|
|
13
|
+
import "./chunk-J4XZCE4A.js";
|
|
14
14
|
import {
|
|
15
15
|
MaxTurnsError,
|
|
16
16
|
PromptCancelledError,
|
|
17
17
|
ToolApprovalRequiredError
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-CO7YK4JZ.js";
|
|
19
19
|
import "./chunk-YK4WAAS4.js";
|
|
20
20
|
import "./chunk-XUUY2L2D.js";
|
|
21
21
|
import {
|
|
22
22
|
createMiddleware,
|
|
23
23
|
createThinkTool,
|
|
24
24
|
createToolMiddleware
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-GISFLLNL.js";
|
|
26
26
|
import {
|
|
27
27
|
createTool
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-IZM6FNCT.js";
|
|
29
|
+
import {
|
|
30
|
+
cancelPrompt,
|
|
31
|
+
createHook,
|
|
32
|
+
requestToolApproval,
|
|
33
|
+
runControl,
|
|
34
|
+
skipTool,
|
|
35
|
+
toolCallControl
|
|
36
|
+
} from "./chunk-NPZDYOE6.js";
|
|
37
|
+
import "./chunk-MMHG7WAM.js";
|
|
29
38
|
import "./chunk-M6RPFHG7.js";
|
|
30
39
|
import "./chunk-JS5MGVNM.js";
|
|
31
40
|
import "./chunk-OIMLU4SF.js";
|
|
@@ -43,14 +52,13 @@ import {
|
|
|
43
52
|
} from "./chunk-5LFGEMIW.js";
|
|
44
53
|
import "./chunk-WQKHFADH.js";
|
|
45
54
|
import {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
} from "./chunk-
|
|
53
|
-
import "./chunk-MMHG7WAM.js";
|
|
55
|
+
allow,
|
|
56
|
+
block,
|
|
57
|
+
defineGuardrailPolicy,
|
|
58
|
+
defineInputGuardrail,
|
|
59
|
+
defineOutputGuardrail,
|
|
60
|
+
guardrails
|
|
61
|
+
} from "./chunk-CWUJUSOS.js";
|
|
54
62
|
export {
|
|
55
63
|
AgentBuilder,
|
|
56
64
|
AssistantContent,
|
|
@@ -62,6 +70,8 @@ export {
|
|
|
62
70
|
ToolContent,
|
|
63
71
|
Usage,
|
|
64
72
|
UserContent,
|
|
73
|
+
allow,
|
|
74
|
+
block,
|
|
65
75
|
cancelPrompt,
|
|
66
76
|
coreMessagesToUIMessages,
|
|
67
77
|
createCompletion,
|
|
@@ -72,6 +82,10 @@ export {
|
|
|
72
82
|
createThinkTool,
|
|
73
83
|
createTool,
|
|
74
84
|
createToolMiddleware,
|
|
85
|
+
defineGuardrailPolicy,
|
|
86
|
+
defineInputGuardrail,
|
|
87
|
+
defineOutputGuardrail,
|
|
88
|
+
guardrails,
|
|
75
89
|
loadSkills,
|
|
76
90
|
requestToolApproval,
|
|
77
91
|
runControl,
|
package/dist/internal/agent.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export { A as Agent, d as AgentEventAppendInput, e as AgentEventRecord, b as AgentEventStore, f as AgentEventStoreInclude, c as AgentEventStoreOptions, i as AgentEventStoreRegistration, j as AgentOptions, g as AgentSession, h as AgentToolOptions, k as DEFAULT_MAX_TURNS, D as DynamicContextOptions, l as DynamicContextRegistration, a as DynamicToolOptions, m as DynamicToolRegistration } from '../agent-
|
|
1
|
+
export { A as Agent, d as AgentEventAppendInput, e as AgentEventRecord, b as AgentEventStore, f as AgentEventStoreInclude, c as AgentEventStoreOptions, i as AgentEventStoreRegistration, j as AgentOptions, g as AgentSession, h as AgentToolOptions, k as DEFAULT_MAX_TURNS, D as DynamicContextOptions, l as DynamicContextRegistration, a as DynamicToolOptions, m as DynamicToolRegistration } from '../agent-BBj3jvBi.js';
|
|
2
2
|
import '../types-q9G7Bvwl.js';
|
|
3
|
+
import '../guardrails/index.js';
|
|
3
4
|
import '../types-CGML74sE.js';
|
|
4
5
|
import '../types-CqG6d7Ce.js';
|
|
5
|
-
import '../index-
|
|
6
|
+
import '../index-Oucb3Ljj.js';
|
|
6
7
|
import '../tool-B8K543oQ.js';
|
|
7
8
|
import '../middleware-ByyL6Rj0.js';
|
|
8
9
|
import '../types-DHHZztGO.js';
|
package/dist/internal/agent.js
CHANGED
|
@@ -2,19 +2,20 @@ import {
|
|
|
2
2
|
Agent,
|
|
3
3
|
AgentSession,
|
|
4
4
|
DEFAULT_MAX_TURNS
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-J4XZCE4A.js";
|
|
6
|
+
import "../chunk-CO7YK4JZ.js";
|
|
7
7
|
import "../chunk-YK4WAAS4.js";
|
|
8
8
|
import "../chunk-XUUY2L2D.js";
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-GISFLLNL.js";
|
|
10
|
+
import "../chunk-IZM6FNCT.js";
|
|
11
|
+
import "../chunk-NPZDYOE6.js";
|
|
12
|
+
import "../chunk-MMHG7WAM.js";
|
|
11
13
|
import "../chunk-JS5MGVNM.js";
|
|
12
14
|
import "../chunk-OIMLU4SF.js";
|
|
13
15
|
import "../chunk-SRBW3LD7.js";
|
|
14
16
|
import "../chunk-5LFGEMIW.js";
|
|
15
17
|
import "../chunk-WQKHFADH.js";
|
|
16
|
-
import "../chunk-
|
|
17
|
-
import "../chunk-MMHG7WAM.js";
|
|
18
|
+
import "../chunk-CWUJUSOS.js";
|
|
18
19
|
export {
|
|
19
20
|
Agent,
|
|
20
21
|
AgentSession,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { f as AgentGenerationEndArgs, g as AgentGenerationErrorArgs, h as AgentGenerationObserver, i as AgentGenerationStartArgs, j as AgentGenerationUpdateArgs, b as AgentObserver, d as AgentObserverRegistration, k as AgentRunEndArgs, l as AgentRunErrorArgs, m as AgentRunEventArgs, n as AgentRunObserver, o as AgentRunPromptRef, p as AgentRunStartArgs, q as AgentToolEndArgs, r as AgentToolErrorArgs, s as AgentToolObserver, t as AgentToolStartArgs, u as AgentToolStreamEventArgs, v as AgentTraceInfo, c as AgentTraceOptions, O as ObserveOptions, w as createObserver } from '../index-
|
|
1
|
+
export { f as AgentGenerationEndArgs, g as AgentGenerationErrorArgs, h as AgentGenerationObserver, i as AgentGenerationStartArgs, j as AgentGenerationUpdateArgs, b as AgentObserver, d as AgentObserverRegistration, k as AgentRunEndArgs, l as AgentRunErrorArgs, m as AgentRunEventArgs, n as AgentRunObserver, o as AgentRunPromptRef, p as AgentRunStartArgs, q as AgentToolEndArgs, r as AgentToolErrorArgs, s as AgentToolObserver, t as AgentToolStartArgs, u as AgentToolStreamEventArgs, v as AgentTraceInfo, c as AgentTraceOptions, O as ObserveOptions, w as createObserver } from '../index-Oucb3Ljj.js';
|
|
2
2
|
import '../types-q9G7Bvwl.js';
|
|
3
|
+
import '../guardrails/index.js';
|
|
3
4
|
import '../tool-B8K543oQ.js';
|
package/dist/pipeline/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { A as Agent } from '../agent-
|
|
2
|
+
import { A as Agent } from '../agent-BBj3jvBi.js';
|
|
3
3
|
import { J as JsonObject, C as CompletionModel } from '../types-q9G7Bvwl.js';
|
|
4
4
|
import { Extractor } from '../extractor/index.js';
|
|
5
|
+
import '../guardrails/index.js';
|
|
5
6
|
import '../types-CGML74sE.js';
|
|
6
7
|
import '../types-CqG6d7Ce.js';
|
|
7
|
-
import '../index-
|
|
8
|
+
import '../index-Oucb3Ljj.js';
|
|
8
9
|
import '../tool-B8K543oQ.js';
|
|
9
10
|
import '../middleware-ByyL6Rj0.js';
|
|
10
11
|
import '../types-DHHZztGO.js';
|
package/dist/pipeline/index.js
CHANGED
package/dist/request/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { M as Message } from '../types-q9G7Bvwl.js';
|
|
2
2
|
import { d as ToolApprovalRequest } from '../tool-B8K543oQ.js';
|
|
3
|
-
export { P as PromptRequest } from '../agent-
|
|
4
|
-
export { A as AgentChildStreamEvent, e as AgentDeltaEvent, a as AgentStreamEvent, P as PromptResponse } from '../index-
|
|
3
|
+
export { P as PromptRequest } from '../agent-BBj3jvBi.js';
|
|
4
|
+
export { A as AgentChildStreamEvent, e as AgentDeltaEvent, a as AgentStreamEvent, P as PromptResponse } from '../index-Oucb3Ljj.js';
|
|
5
|
+
import '../guardrails/index.js';
|
|
5
6
|
import '../types-CGML74sE.js';
|
|
6
7
|
import '../types-CqG6d7Ce.js';
|
|
7
8
|
import '../middleware-ByyL6Rj0.js';
|
package/dist/request/index.js
CHANGED
|
@@ -3,17 +3,18 @@ import {
|
|
|
3
3
|
PromptCancelledError,
|
|
4
4
|
PromptRequest,
|
|
5
5
|
ToolApprovalRequiredError
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-CO7YK4JZ.js";
|
|
7
7
|
import "../chunk-XUUY2L2D.js";
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-GISFLLNL.js";
|
|
9
|
+
import "../chunk-IZM6FNCT.js";
|
|
10
|
+
import "../chunk-NPZDYOE6.js";
|
|
11
|
+
import "../chunk-MMHG7WAM.js";
|
|
10
12
|
import "../chunk-JS5MGVNM.js";
|
|
11
13
|
import "../chunk-OIMLU4SF.js";
|
|
12
14
|
import "../chunk-SRBW3LD7.js";
|
|
13
15
|
import "../chunk-5LFGEMIW.js";
|
|
14
16
|
import "../chunk-WQKHFADH.js";
|
|
15
|
-
import "../chunk-
|
|
16
|
-
import "../chunk-MMHG7WAM.js";
|
|
17
|
+
import "../chunk-CWUJUSOS.js";
|
|
17
18
|
export {
|
|
18
19
|
MaxTurnsError,
|
|
19
20
|
PromptCancelledError,
|
package/dist/skills/index.js
CHANGED
|
@@ -2,15 +2,15 @@ import {
|
|
|
2
2
|
SkillValidationError,
|
|
3
3
|
loadSkills,
|
|
4
4
|
skill
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-HF4KHHNM.js";
|
|
6
6
|
import "../chunk-YK4WAAS4.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-GISFLLNL.js";
|
|
8
|
+
import "../chunk-IZM6FNCT.js";
|
|
9
|
+
import "../chunk-MMHG7WAM.js";
|
|
9
10
|
import "../chunk-JS5MGVNM.js";
|
|
10
11
|
import "../chunk-OIMLU4SF.js";
|
|
11
12
|
import "../chunk-5LFGEMIW.js";
|
|
12
13
|
import "../chunk-WQKHFADH.js";
|
|
13
|
-
import "../chunk-MMHG7WAM.js";
|
|
14
14
|
export {
|
|
15
15
|
SkillValidationError,
|
|
16
16
|
loadSkills,
|
package/dist/tool/index.js
CHANGED
|
@@ -13,10 +13,11 @@ import {
|
|
|
13
13
|
normalizeToolResultOutput,
|
|
14
14
|
parseToolArgs,
|
|
15
15
|
toolResultContentToText
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-GISFLLNL.js";
|
|
17
17
|
import {
|
|
18
18
|
createTool
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-IZM6FNCT.js";
|
|
20
|
+
import "../chunk-MMHG7WAM.js";
|
|
20
21
|
import "../chunk-JS5MGVNM.js";
|
|
21
22
|
import "../chunk-OIMLU4SF.js";
|
|
22
23
|
import {
|
|
@@ -24,7 +25,6 @@ import {
|
|
|
24
25
|
serializeToolResultOutput
|
|
25
26
|
} from "../chunk-5LFGEMIW.js";
|
|
26
27
|
import "../chunk-WQKHFADH.js";
|
|
27
|
-
import "../chunk-MMHG7WAM.js";
|
|
28
28
|
export {
|
|
29
29
|
ToolCallError,
|
|
30
30
|
ToolJsonError,
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
InMemoryVectorStore,
|
|
4
4
|
createVectorSearchTool,
|
|
5
5
|
vectorFilter
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-IZM6FNCT.js";
|
|
7
|
+
import "../chunk-MMHG7WAM.js";
|
|
7
8
|
import "../chunk-JS5MGVNM.js";
|
|
8
9
|
import "../chunk-OIMLU4SF.js";
|
|
9
10
|
import "../chunk-WQKHFADH.js";
|
|
10
|
-
import "../chunk-MMHG7WAM.js";
|
|
11
11
|
export {
|
|
12
12
|
InMemoryVectorIndex,
|
|
13
13
|
InMemoryVectorStore,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anvia/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Core runtime primitives for context-aware Anvia agents.",
|
|
5
5
|
"author": "anvia",
|
|
6
6
|
"maintainer": "Indra Zulfi",
|
|
@@ -56,6 +56,10 @@
|
|
|
56
56
|
"types": "./dist/extractor/index.d.ts",
|
|
57
57
|
"import": "./dist/extractor/index.js"
|
|
58
58
|
},
|
|
59
|
+
"./guardrails": {
|
|
60
|
+
"types": "./dist/guardrails/index.d.ts",
|
|
61
|
+
"import": "./dist/guardrails/index.js"
|
|
62
|
+
},
|
|
59
63
|
"./mcp": {
|
|
60
64
|
"types": "./dist/mcp/index.d.ts",
|
|
61
65
|
"import": "./dist/mcp/index.js"
|
|
@@ -127,7 +131,7 @@
|
|
|
127
131
|
"vitest": "^4.0.8"
|
|
128
132
|
},
|
|
129
133
|
"scripts": {
|
|
130
|
-
"build": "tsup src/index.ts src/agent/index.ts src/hooks/index.ts src/request/index.ts src/internal/agent.ts src/audio-generation/index.ts src/completion/index.ts src/embeddings/index.ts src/evals/index.ts src/image-generation/index.ts src/loaders/index.ts src/extractor/index.ts src/mcp/index.ts src/memory/index.ts src/model-listing/index.ts src/observability/index.ts src/pipeline/index.ts src/skills/index.ts src/streaming/index.ts src/tool/index.ts src/ui/index.ts src/transcription/index.ts src/vector-store/index.ts --format esm --dts --sourcemap --clean",
|
|
134
|
+
"build": "tsup src/index.ts src/agent/index.ts src/hooks/index.ts src/request/index.ts src/internal/agent.ts src/audio-generation/index.ts src/completion/index.ts src/embeddings/index.ts src/evals/index.ts src/image-generation/index.ts src/loaders/index.ts src/extractor/index.ts src/guardrails/index.ts src/mcp/index.ts src/memory/index.ts src/model-listing/index.ts src/observability/index.ts src/pipeline/index.ts src/skills/index.ts src/streaming/index.ts src/tool/index.ts src/ui/index.ts src/transcription/index.ts src/vector-store/index.ts --format esm --dts --sourcemap --clean",
|
|
131
135
|
"test": "vitest run",
|
|
132
136
|
"typecheck": "tsc --noEmit"
|
|
133
137
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vector-store/index.ts","../src/tool/create-tool.ts","../src/vector-store/filter.ts","../src/vector-store/lsh.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n cosineSimilarity,\n type EmbeddedDocument,\n type Embedding,\n type EmbeddingModel,\n embedText,\n type VectorMetadata,\n} from \"../embeddings\";\nimport { createTool } from \"../tool/create-tool\";\nimport type { Tool } from \"../tool/tool\";\nimport { matchesVectorFilter } from \"./filter\";\nimport { LshIndex } from \"./lsh\";\nimport type {\n IndexStrategy,\n VectorInspectPage,\n VectorInspectRequest,\n VectorSearchIndex,\n VectorSearchRequest,\n VectorSearchResult,\n VectorSearchToolOptions,\n} from \"./types\";\n\nexport { vectorFilter } from \"./filter\";\nexport type * from \"./types\";\n\ntype StoredDocument<T, Metadata extends VectorMetadata> = EmbeddedDocument<T, Metadata>;\n\nexport class InMemoryVectorStore<T, Metadata extends VectorMetadata = VectorMetadata> {\n private readonly documents = new Map<string, StoredDocument<T, Metadata>>();\n private indexStrategy: IndexStrategy;\n private lshIndex: LshIndex | undefined;\n private embeddingDimension: number | undefined;\n\n constructor(options: { index?: IndexStrategy } = {}) {\n this.indexStrategy = options.index ?? { type: \"bruteForce\" };\n }\n\n static fromDocuments<T, Metadata extends VectorMetadata = VectorMetadata>(\n documents: Array<EmbeddedDocument<T, Metadata>>,\n options: { index?: IndexStrategy } = {},\n ): InMemoryVectorStore<T, Metadata> {\n const store = new InMemoryVectorStore<T, Metadata>(options);\n store.addDocuments(documents);\n return store;\n }\n\n addDocuments(documents: Array<EmbeddedDocument<T, Metadata>>): this {\n this.validateDocumentDimensions(documents);\n for (const document of documents) {\n this.documents.set(document.id, document);\n }\n this.rebuildLshIndex();\n return this;\n }\n\n get(id: string): StoredDocument<T, Metadata> | undefined {\n return this.documents.get(id);\n }\n\n values(): Array<StoredDocument<T, Metadata>> {\n return [...this.documents.values()];\n }\n\n len(): number {\n return this.documents.size;\n }\n\n isEmpty(): boolean {\n return this.documents.size === 0;\n }\n\n index(model: EmbeddingModel): InMemoryVectorIndex<T, Metadata> {\n return new InMemoryVectorIndex(model, this);\n }\n\n candidates(queryEmbedding: Embedding): Array<StoredDocument<T, Metadata>> {\n this.validateQueryDimension(queryEmbedding);\n if (this.indexStrategy.type !== \"lsh\" || this.lshIndex === undefined) {\n return this.values();\n }\n\n const candidateIds = this.lshIndex.query(queryEmbedding.vector);\n if (candidateIds.size === 0) {\n return this.values();\n }\n\n return [...candidateIds].flatMap((id) => {\n const document = this.documents.get(id);\n return document === undefined ? [] : [document];\n });\n }\n\n private rebuildLshIndex(): void {\n if (this.indexStrategy.type !== \"lsh\") {\n this.lshIndex = undefined;\n return;\n }\n\n const firstEmbedding = this.values().flatMap((document) => document.embeddings)[0];\n if (firstEmbedding === undefined) {\n this.lshIndex = undefined;\n return;\n }\n\n const index = new LshIndex(firstEmbedding.vector.length, this.indexStrategy);\n for (const document of this.documents.values()) {\n for (const embedding of document.embeddings) {\n index.insert(document.id, embedding.vector);\n }\n }\n this.lshIndex = index;\n }\n\n private validateDocumentDimensions(documents: Array<EmbeddedDocument<T, Metadata>>): void {\n let dimension = this.embeddingDimension;\n for (const document of documents) {\n for (const embedding of document.embeddings) {\n dimension = validateEmbeddingDimension(dimension, embedding, document.id);\n }\n }\n this.embeddingDimension = dimension;\n }\n\n private validateQueryDimension(queryEmbedding: Embedding): void {\n if (this.embeddingDimension === undefined) {\n return;\n }\n validateEmbeddingDimension(this.embeddingDimension, queryEmbedding, \"query\");\n }\n}\n\nexport class InMemoryVectorIndex<T, Metadata extends VectorMetadata = VectorMetadata>\n implements VectorSearchIndex<T, Metadata>\n{\n constructor(\n private readonly model: EmbeddingModel,\n private readonly store: InMemoryVectorStore<T, Metadata>,\n ) {}\n\n async search(request: VectorSearchRequest): Promise<Array<VectorSearchResult<T, Metadata>>> {\n const queryEmbedding = await embedText(this.model, request.query);\n return this.store\n .candidates(queryEmbedding)\n .filter((document) => matchesVectorFilter(document.metadata, request.filter))\n .flatMap((document) => {\n const score = bestScore(queryEmbedding, document.embeddings);\n if (score === undefined) {\n return [];\n }\n if (request.threshold !== undefined && score < request.threshold) {\n return [];\n }\n return [\n {\n score,\n id: document.id,\n document: document.document,\n ...(document.metadata !== undefined && { metadata: document.metadata }),\n },\n ];\n })\n .sort((left, right) => right.score - left.score)\n .slice(0, Math.max(0, Math.trunc(request.topK)));\n }\n\n async searchIds(request: VectorSearchRequest): Promise<Array<{ score: number; id: string }>> {\n return (await this.search(request)).map(({ score, id }) => ({ score, id }));\n }\n\n async inspect(request: VectorInspectRequest): Promise<VectorInspectPage<T, Metadata>> {\n const limit = Math.max(0, Math.trunc(request.limit));\n const start = Math.max(0, Math.trunc(Number(request.cursor ?? \"0\")));\n const documents = this.store\n .values()\n .filter((document) => matchesVectorFilter(document.metadata, request.filter));\n const page = documents.slice(start, start + limit);\n const nextOffset = start + page.length;\n return {\n items: page.map((document) => ({\n id: document.id,\n document: document.document,\n ...(document.metadata !== undefined && { metadata: document.metadata }),\n })),\n ...(nextOffset < documents.length ? { nextCursor: String(nextOffset) } : {}),\n totalCount: documents.length,\n };\n }\n\n asTool(options: VectorSearchToolOptions): Tool<{ query: string; topK?: number }, unknown> {\n return createVectorSearchTool(this, options);\n }\n}\n\nexport function createVectorSearchTool<T, Metadata extends VectorMetadata>(\n index: VectorSearchIndex<T, Metadata>,\n options: VectorSearchToolOptions,\n): Tool<{ query: string; topK?: number }, Array<VectorSearchResult<T, Metadata>>> {\n return createTool({\n name: options.name,\n description:\n options.description ?? \"Search a vector store for documents relevant to the provided query.\",\n input: z.object({\n query: z.string().describe(\"The query string to search for relevant documents.\"),\n topK: z.number().int().positive().optional().describe(\"The maximum number of results.\"),\n }),\n output: z.array(\n z.object({\n score: z.number(),\n id: z.string(),\n document: z.any(),\n metadata: z\n .record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.null()]))\n .optional(),\n }),\n ),\n execute: ({ query, topK }) =>\n index.search({\n query,\n topK: topK ?? options.topK ?? 5,\n threshold: options.threshold,\n filter: options.filter,\n }),\n }) as Tool<{ query: string; topK?: number }, Array<VectorSearchResult<T, Metadata>>>;\n}\n\nfunction bestScore(queryEmbedding: Embedding, embeddings: Embedding[]): number | undefined {\n let best: number | undefined;\n for (const embedding of embeddings) {\n const score = cosineSimilarity(queryEmbedding.vector, embedding.vector);\n best = best === undefined ? score : Math.max(best, score);\n }\n return best;\n}\n\nfunction validateEmbeddingDimension(\n expectedDimension: number | undefined,\n embedding: Embedding,\n id: string,\n): number {\n if (expectedDimension === undefined) {\n return embedding.vector.length;\n }\n if (embedding.vector.length !== expectedDimension) {\n throw new Error(\n `Vector dimension mismatch: expected ${expectedDimension} dimensions but received ${embedding.vector.length} for ${id}`,\n );\n }\n return expectedDimension;\n}\n","import type { z } from \"zod\";\nimport { compact } from \"../internal/compact\";\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 Output = unknown,\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 : Output | Promise<Output>;\n};\n\ntype CreateToolOutput<\n OutputSchema extends ZodSchema | undefined,\n Output,\n> = OutputSchema extends ZodSchema ? z.output<OutputSchema> : Output;\n\nexport function createTool<InputSchema extends ZodSchema, Output = unknown>(\n options: CreateToolOptions<InputSchema, undefined, Output> & { output?: undefined },\n): Tool<z.output<InputSchema>, Output>;\n\nexport function createTool<InputSchema extends ZodSchema, OutputSchema extends ZodSchema>(\n options: CreateToolOptions<InputSchema, OutputSchema>,\n): Tool<z.output<InputSchema>, z.output<OutputSchema>>;\n\nexport function createTool<\n InputSchema extends ZodSchema,\n OutputSchema extends ZodSchema | undefined = undefined,\n Output = unknown,\n>(\n options: CreateToolOptions<InputSchema, OutputSchema, Output>,\n): Tool<z.output<InputSchema>, CreateToolOutput<OutputSchema, Output>> {\n const parameters = toProviderJsonSchema(options.input);\n\n return {\n ...compact({ name: options.name, 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<CreateToolOutput<OutputSchema, Output>> {\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 CreateToolOutput<OutputSchema, Output>;\n },\n parseApprovalArgs(args): z.output<InputSchema> {\n return options.input.parse(args);\n },\n };\n}\n","import type { VectorMetadata, VectorMetadataValue } from \"../embeddings\";\nimport type { VectorFilter } from \"./types\";\n\nexport type { VectorFilter } from \"./types\";\n\nexport const vectorFilter = {\n eq(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"eq\", key, value };\n },\n gt(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"gt\", key, value };\n },\n lt(key: string, value: VectorMetadataValue): VectorFilter {\n return { type: \"lt\", key, value };\n },\n and(left: VectorFilter, right: VectorFilter): VectorFilter {\n return { type: \"and\", filters: [left, right] };\n },\n or(left: VectorFilter, right: VectorFilter): VectorFilter {\n return { type: \"or\", filters: [left, right] };\n },\n};\n\nexport function matchesVectorFilter(\n metadata: VectorMetadata | undefined,\n filter: VectorFilter | undefined,\n): boolean {\n if (filter === undefined) {\n return true;\n }\n if (metadata === undefined) {\n return false;\n }\n\n switch (filter.type) {\n case \"eq\":\n return metadata[filter.key] === filter.value;\n case \"gt\":\n return compare(metadata[filter.key], filter.value) > 0;\n case \"lt\":\n return compare(metadata[filter.key], filter.value) < 0;\n case \"and\":\n return (\n matchesVectorFilter(metadata, filter.filters[0]) &&\n matchesVectorFilter(metadata, filter.filters[1])\n );\n case \"or\":\n return (\n matchesVectorFilter(metadata, filter.filters[0]) ||\n matchesVectorFilter(metadata, filter.filters[1])\n );\n }\n}\n\nfunction compare(left: VectorMetadataValue | undefined, right: VectorMetadataValue): number {\n if (typeof left === \"number\" && typeof right === \"number\") {\n return left - right;\n }\n if (typeof left === \"string\" && typeof right === \"string\") {\n return left.localeCompare(right);\n }\n if (typeof left === \"boolean\" && typeof right === \"boolean\") {\n return Number(left) - Number(right);\n }\n return 0;\n}\n","import type { LshOptions } from \"./types\";\n\nexport type { LshOptions } from \"./types\";\n\nexport class LshIndex {\n private readonly hyperplanes: number[][];\n private readonly tables: Array<Map<string, Set<string>>>;\n\n constructor(\n dimensions: number,\n private readonly options: LshOptions,\n ) {\n const rng = seededRandom(options.seed ?? 42);\n this.hyperplanes = [];\n for (let index = 0; index < options.numTables * options.numHyperplanes; index += 1) {\n const plane = Array.from({ length: dimensions }, () => rng() * 2 - 1);\n const norm = Math.sqrt(plane.reduce((sum, value) => sum + value ** 2, 0));\n this.hyperplanes.push(norm === 0 ? plane : plane.map((value) => value / norm));\n }\n this.tables = Array.from({ length: options.numTables }, () => new Map());\n }\n\n insert(id: string, vector: number[]): void {\n for (let table = 0; table < this.options.numTables; table += 1) {\n const hash = this.hash(vector, table);\n const bucket = this.tables[table]?.get(hash) ?? new Set<string>();\n bucket.add(id);\n this.tables[table]?.set(hash, bucket);\n }\n }\n\n query(vector: number[]): Set<string> {\n const candidates = new Set<string>();\n for (let table = 0; table < this.options.numTables; table += 1) {\n const hash = this.hash(vector, table);\n for (const id of this.tables[table]?.get(hash) ?? []) {\n candidates.add(id);\n }\n }\n return candidates;\n }\n\n private hash(vector: number[], table: number): string {\n let hash = \"\";\n const start = table * this.options.numHyperplanes;\n for (let offset = 0; offset < this.options.numHyperplanes; offset += 1) {\n const plane = this.hyperplanes[start + offset] as number[];\n const dot = vector.reduce((sum, value, index) => sum + value * (plane[index] ?? 0), 0);\n hash += dot >= 0 ? \"1\" : \"0\";\n }\n return hash;\n }\n}\n\nfunction seededRandom(seed: number): () => number {\n let state = seed >>> 0;\n return () => {\n state = (state * 1664525 + 1013904223) >>> 0;\n return state / 0x100000000;\n };\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,SAAS;;;ACoCX,SAAS,WAKd,SACqE;AACrE,QAAM,aAAa,qBAAqB,QAAQ,KAAK;AAErD,SAAO;AAAA,IACL,GAAG,QAA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