@anvia/core 0.12.0 → 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.
Files changed (52) hide show
  1. package/dist/agent/index.d.ts +8 -8
  2. package/dist/agent/index.js +8 -8
  3. package/dist/{agent-BWF8_O8k.d.ts → agent-BBj3jvBi.d.ts} +4 -4
  4. package/dist/{chunk-KTTIPWE7.js → chunk-CO7YK4JZ.js} +23 -143
  5. package/dist/chunk-CO7YK4JZ.js.map +1 -0
  6. package/dist/{chunk-YRERPIA5.js → chunk-CWUJUSOS.js} +4 -164
  7. package/dist/chunk-CWUJUSOS.js.map +1 -0
  8. package/dist/{chunk-R7F2JF7J.js → chunk-GISFLLNL.js} +5 -5
  9. package/dist/chunk-GISFLLNL.js.map +1 -0
  10. package/dist/{chunk-ZGIE73BH.js → chunk-HF4KHHNM.js} +2 -2
  11. package/dist/{chunk-PGFYN5ZX.js → chunk-IZM6FNCT.js} +5 -7
  12. package/dist/chunk-IZM6FNCT.js.map +1 -0
  13. package/dist/{chunk-4AJJIIAQ.js → chunk-J4XZCE4A.js} +4 -4
  14. package/dist/{chunk-MIJUAWHU.js → chunk-L62HQ5Y4.js} +4 -4
  15. package/dist/{chunk-TIH4QM55.js → chunk-MX6ATKGT.js} +4 -4
  16. package/dist/evals/index.d.ts +5 -5
  17. package/dist/evals/index.js +10 -10
  18. package/dist/extractor/index.d.ts +5 -5
  19. package/dist/extractor/index.js +9 -9
  20. package/dist/guardrails/index.d.ts +6 -84
  21. package/dist/guardrails/index.js +3 -11
  22. package/dist/{index-DsWWqP0Q.d.ts → index-Oucb3Ljj.d.ts} +1 -1
  23. package/dist/index.d.ts +9 -9
  24. package/dist/index.js +9 -13
  25. package/dist/internal/agent.d.ts +5 -5
  26. package/dist/internal/agent.js +7 -7
  27. package/dist/mcp/index.d.ts +3 -4
  28. package/dist/{middleware-BTR0eRtx.d.ts → middleware-ByyL6Rj0.d.ts} +2 -2
  29. package/dist/observability/index.d.ts +2 -2
  30. package/dist/pipeline/index.d.ts +5 -5
  31. package/dist/request/index.d.ts +5 -5
  32. package/dist/request/index.js +6 -6
  33. package/dist/skills/index.d.ts +3 -4
  34. package/dist/skills/index.js +5 -5
  35. package/dist/{think-tool-Bn3HHu_z.d.ts → think-tool-B065hm73.d.ts} +1 -4
  36. package/dist/tool/index.d.ts +4 -5
  37. package/dist/tool/index.js +4 -4
  38. package/dist/{tool-DGELXD2z.d.ts → tool-B8K543oQ.d.ts} +0 -3
  39. package/dist/{types-Dc83Qzch.d.ts → types-7F_IKQQW.d.ts} +1 -1
  40. package/dist/{types-Bx_ZtjPi.d.ts → types-BzUuhjKr.d.ts} +1 -1
  41. package/dist/{types-9VPKg7ih.d.ts → types-Pl4PFQWL.d.ts} +1 -1
  42. package/dist/vector-store/index.d.ts +3 -4
  43. package/dist/vector-store/index.js +2 -2
  44. package/package.json +1 -1
  45. package/dist/chunk-KTTIPWE7.js.map +0 -1
  46. package/dist/chunk-PGFYN5ZX.js.map +0 -1
  47. package/dist/chunk-R7F2JF7J.js.map +0 -1
  48. package/dist/chunk-YRERPIA5.js.map +0 -1
  49. /package/dist/{chunk-ZGIE73BH.js.map → chunk-HF4KHHNM.js.map} +0 -0
  50. /package/dist/{chunk-4AJJIIAQ.js.map → chunk-J4XZCE4A.js.map} +0 -0
  51. /package/dist/{chunk-MIJUAWHU.js.map → chunk-L62HQ5Y4.js.map} +0 -0
  52. /package/dist/{chunk-TIH4QM55.js.map → chunk-MX6ATKGT.js.map} +0 -0
@@ -1,16 +1,16 @@
1
- import { D as DynamicContextOptions, a as DynamicToolOptions, b as AgentEventStore, c as AgentEventStoreOptions, A as Agent } from '../agent-BWF8_O8k.js';
2
- export { d as AgentEventAppendInput, e as AgentEventRecord, f as AgentEventStoreInclude, g as AgentSession, h as AgentToolOptions } from '../agent-BWF8_O8k.js';
1
+ import { D as DynamicContextOptions, a as DynamicToolOptions, b as AgentEventStore, c as AgentEventStoreOptions, A as Agent } from '../agent-BBj3jvBi.js';
2
+ export { d as AgentEventAppendInput, e as AgentEventRecord, f as AgentEventStoreInclude, g as AgentSession, h as AgentToolOptions } from '../agent-BBj3jvBi.js';
3
3
  import { Z as ZodSchema } from '../zod-schema-C7F4clpm.js';
4
4
  import { C as CompletionModel, e as JsonValue, n as ToolChoice } from '../types-q9G7Bvwl.js';
5
5
  import { GuardrailPolicyInput } from '../guardrails/index.js';
6
6
  import { P as PromptHook } from '../types-CGML74sE.js';
7
- import { a as McpServer } from '../types-Dc83Qzch.js';
7
+ import { a as McpServer } from '../types-7F_IKQQW.js';
8
8
  import { M as MemoryStore, a as MemoryOptions } from '../types-CqG6d7Ce.js';
9
- import { b as AgentObserver, O as ObserveOptions } from '../index-DsWWqP0Q.js';
10
- import { a as SkillSet } from '../types-Bx_ZtjPi.js';
11
- import { k as ToolSearchDocument, l as ToolSet, A as AgentMiddleware, e as ToolMiddleware } from '../middleware-BTR0eRtx.js';
12
- import { A as AnyTool, e as ToolApprovalsOptions } from '../tool-DGELXD2z.js';
13
- import { a as VectorSearchIndex } from '../types-9VPKg7ih.js';
9
+ import { b as AgentObserver, O as ObserveOptions } from '../index-Oucb3Ljj.js';
10
+ import { a as SkillSet } from '../types-BzUuhjKr.js';
11
+ import { k as ToolSearchDocument, l as ToolSet, A as AgentMiddleware, e as ToolMiddleware } from '../middleware-ByyL6Rj0.js';
12
+ import { A as AnyTool, e as ToolApprovalsOptions } from '../tool-B8K543oQ.js';
13
+ import { a as VectorSearchIndex } from '../types-Pl4PFQWL.js';
14
14
  import 'zod';
15
15
  import '@modelcontextprotocol/sdk/client/sse.js';
16
16
  import '@modelcontextprotocol/sdk/client/stdio.js';
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  AgentBuilder
3
- } from "../chunk-TIH4QM55.js";
4
- import "../chunk-4AJJIIAQ.js";
5
- import "../chunk-KTTIPWE7.js";
3
+ } from "../chunk-MX6ATKGT.js";
4
+ import "../chunk-J4XZCE4A.js";
5
+ import "../chunk-CO7YK4JZ.js";
6
6
  import "../chunk-YK4WAAS4.js";
7
7
  import "../chunk-XUUY2L2D.js";
8
- import "../chunk-R7F2JF7J.js";
9
- import "../chunk-PGFYN5ZX.js";
8
+ import "../chunk-GISFLLNL.js";
9
+ import "../chunk-IZM6FNCT.js";
10
10
  import "../chunk-NPZDYOE6.js";
11
11
  import "../chunk-MMHG7WAM.js";
12
12
  import "../chunk-M6RPFHG7.js";
13
+ import "../chunk-JS5MGVNM.js";
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-JS5MGVNM.js";
17
- import "../chunk-OIMLU4SF.js";
18
- import "../chunk-YRERPIA5.js";
18
+ import "../chunk-CWUJUSOS.js";
19
19
  export {
20
20
  AgentBuilder
21
21
  };
@@ -2,10 +2,10 @@ import { C as CompletionModel, M as Message, D as Document, e as JsonValue, n as
2
2
  import { GuardrailPolicyInput, GuardrailPolicy } from './guardrails/index.js';
3
3
  import { P as PromptHook } from './types-CGML74sE.js';
4
4
  import { c as MemoryContext, e as MemoryRegistration, S as SessionOptions } from './types-CqG6d7Ce.js';
5
- import { c as AgentTraceOptions, P as PromptResponse, a as AgentStreamEvent, d as AgentObserverRegistration } from './index-DsWWqP0Q.js';
6
- import { e as ToolApprovalsOptions, T as Tool, A as AnyTool, f as ToolCallContext, N as NormalizedToolOutput } from './tool-DGELXD2z.js';
7
- import { A as AgentMiddleware, e as ToolMiddleware, k as ToolSearchDocument, l as ToolSet } from './middleware-BTR0eRtx.js';
8
- import { V as VectorFilter, c as VectorSearchResult, a as VectorSearchIndex } from './types-9VPKg7ih.js';
5
+ import { c as AgentTraceOptions, P as PromptResponse, a as AgentStreamEvent, d as AgentObserverRegistration } from './index-Oucb3Ljj.js';
6
+ import { e as ToolApprovalsOptions, T as Tool, A as AnyTool, f as ToolCallContext, N as NormalizedToolOutput } from './tool-B8K543oQ.js';
7
+ import { A as AgentMiddleware, e as ToolMiddleware, k as ToolSearchDocument, l as ToolSet } from './middleware-ByyL6Rj0.js';
8
+ import { V as VectorFilter, c as VectorSearchResult, a as VectorSearchIndex } from './types-Pl4PFQWL.js';
9
9
 
10
10
  declare class PromptRequest<M extends CompletionModel = CompletionModel> {
11
11
  private readonly agent;
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  parseToolArgs,
6
6
  toolResultContentToText
7
- } from "./chunk-R7F2JF7J.js";
7
+ } from "./chunk-GISFLLNL.js";
8
8
  import {
9
9
  runControl,
10
10
  toolCallControl
@@ -12,6 +12,9 @@ import {
12
12
  import {
13
13
  compact
14
14
  } from "./chunk-MMHG7WAM.js";
15
+ import {
16
+ mapWithConcurrency
17
+ } from "./chunk-OIMLU4SF.js";
15
18
  import {
16
19
  CompletionRequestBuilder,
17
20
  isStreamingCompletionModel
@@ -24,17 +27,12 @@ import {
24
27
  assertCompletionRequestSupported,
25
28
  textFromAssistantContent
26
29
  } from "./chunk-5LFGEMIW.js";
27
- import {
28
- mapWithConcurrency
29
- } from "./chunk-OIMLU4SF.js";
30
30
  import {
31
31
  appendGuardrailPolicies,
32
32
  hasEnforcedOutputGuardrails,
33
33
  runInputGuardrails,
34
- runOutputGuardrails,
35
- runToolGuardrails,
36
- runToolResultGuardrails
37
- } from "./chunk-YRERPIA5.js";
34
+ runOutputGuardrails
35
+ } from "./chunk-CWUJUSOS.js";
38
36
 
39
37
  // src/request/errors.ts
40
38
  var MaxTurnsError = class extends Error {
@@ -549,26 +547,22 @@ function isGenerationDeltaEvent(type) {
549
547
  // src/internal/prompt-runtime/tool-execution.ts
550
548
  var MCP_TOOL_METADATA_KEY = /* @__PURE__ */ Symbol.for("anvia.mcp.tool.metadata");
551
549
  var ToolCallExecutor = class {
552
- constructor(agent, activeHook, approvals, guardrails, runContext, concurrency, requestMiddlewares, cancel, onGuardrailDecision) {
550
+ constructor(agent, activeHook, approvals, runContext, concurrency, requestMiddlewares, cancel) {
553
551
  this.agent = agent;
554
552
  this.activeHook = activeHook;
555
553
  this.approvals = approvals;
556
- this.guardrails = guardrails;
557
554
  this.runContext = runContext;
558
555
  this.concurrency = concurrency;
559
556
  this.requestMiddlewares = requestMiddlewares;
560
557
  this.cancel = cancel;
561
- this.onGuardrailDecision = onGuardrailDecision;
562
558
  }
563
559
  agent;
564
560
  activeHook;
565
561
  approvals;
566
- guardrails;
567
562
  runContext;
568
563
  concurrency;
569
564
  requestMiddlewares;
570
565
  cancel;
571
- onGuardrailDecision;
572
566
  async execute(toolCalls, onResult, onStreamEvent, observation) {
573
567
  return mapWithConcurrency(toolCalls, this.concurrency, async (toolCall) => {
574
568
  const args = JSON.stringify(toolCall.function.arguments ?? {});
@@ -628,48 +622,22 @@ var ToolCallExecutor = class {
628
622
  originalArgs: args
629
623
  });
630
624
  hookArgs.args = effectiveArgs;
631
- const inputGuardrailResult = await runToolGuardrails(
632
- this.guardrails,
633
- tool?.inputGuardrails ?? [],
634
- toolGuardrailContext(
635
- tool,
636
- hookArgs,
637
- this.agent,
638
- this.runContext,
639
- observation?.turn ?? 0
640
- )
641
- );
642
- await this.recordGuardrailDecisions(inputGuardrailResult.decisions);
643
- effectiveArgs = inputGuardrailResult.rawArgs;
644
- hookArgs.args = effectiveArgs;
645
- if (inputGuardrailResult.blocked) {
646
- output = inputGuardrailResult.message ?? "Tool call blocked by guardrail.";
625
+ approvalDecision = callAction?.type === "approval_request" ? await this.requestApproval(tool, hookArgs, callAction) : await this.evaluateToolApproval(tool, hookArgs) ?? { approved: true };
626
+ if (!approvalDecision.approved) {
627
+ output = approvalDecision.result;
647
628
  skipped = true;
648
629
  } else {
649
- approvalDecision = inputGuardrailResult.approval !== void 0 ? await this.requestApproval(
650
- tool,
630
+ output = await this.runApprovedToolCall(
631
+ toolCall,
651
632
  hookArgs,
652
- compact({
653
- reason: inputGuardrailResult.approval.reason,
654
- rejectMessage: inputGuardrailResult.approval.rejectMessage
655
- })
656
- ) : callAction?.type === "approval_request" ? await this.requestApproval(tool, hookArgs, callAction) : await this.evaluateToolApproval(tool, hookArgs) ?? { approved: true };
657
- if (!approvalDecision.approved) {
658
- output = approvalDecision.result;
659
- skipped = true;
660
- } else {
661
- output = await this.runApprovedToolCall(
662
- toolCall,
663
- hookArgs,
664
- effectiveArgs,
665
- args,
666
- toolObservers,
667
- observation,
668
- onStreamEvent,
669
- false
670
- );
671
- effectiveArgs = hookArgs.args;
672
- }
633
+ effectiveArgs,
634
+ args,
635
+ toolObservers,
636
+ observation,
637
+ onStreamEvent,
638
+ false
639
+ );
640
+ effectiveArgs = hookArgs.args;
673
641
  }
674
642
  } catch (error) {
675
643
  await recordToolError(
@@ -701,29 +669,6 @@ var ToolCallExecutor = class {
701
669
  structuredResult = toolOutputToStructuredResult(middlewareReplacement);
702
670
  }
703
671
  }
704
- const resultGuardrailResult = await runToolResultGuardrails(
705
- this.guardrails,
706
- tool?.outputGuardrails ?? [],
707
- toolResultGuardrailContext(
708
- tool,
709
- hookArgs,
710
- result,
711
- structuredResult,
712
- this.agent,
713
- this.runContext,
714
- observation?.turn ?? 0
715
- )
716
- );
717
- await this.recordGuardrailDecisions(resultGuardrailResult.decisions);
718
- if (resultGuardrailResult.blocked) {
719
- output = resultGuardrailResult.message ?? "Tool result blocked by guardrail.";
720
- result = toolOutputToText(output);
721
- structuredResult = toolOutputToStructuredResult(output);
722
- } else if (resultGuardrailResult.result !== result || resultGuardrailResult.structuredResult !== structuredResult) {
723
- output = resultGuardrailResult.structuredResult ?? resultGuardrailResult.result;
724
- result = resultGuardrailResult.result;
725
- structuredResult = resultGuardrailResult.structuredResult;
726
- }
727
672
  const resultAction = await this.activeHook?.onToolResult?.({
728
673
  ...hookArgs,
729
674
  args: effectiveArgs,
@@ -810,11 +755,6 @@ var ToolCallExecutor = class {
810
755
  return error instanceof Error ? error.toString() : String(error);
811
756
  }
812
757
  }
813
- async recordGuardrailDecisions(decisions) {
814
- for (const decision of decisions) {
815
- await this.onGuardrailDecision?.(decision);
816
- }
817
- }
818
758
  async runToolResultMiddlewares(args) {
819
759
  let result = args.result;
820
760
  let structuredResult = args.structuredResult;
@@ -916,55 +856,6 @@ function approvalContext(tool, hookArgs, agent, run) {
916
856
  })
917
857
  });
918
858
  }
919
- function toolGuardrailContext(tool, hookArgs, agent, run, turn) {
920
- const parsedArgs = parseGuardrailContextArgs(tool, hookArgs.args);
921
- return compact({
922
- toolName: hookArgs.toolName,
923
- args: parsedArgs,
924
- rawArgs: hookArgs.args,
925
- toolCallId: hookArgs.toolCallId,
926
- internalCallId: hookArgs.internalCallId,
927
- turn,
928
- run: guardrailRunContext(agent, run)
929
- });
930
- }
931
- function toolResultGuardrailContext(tool, hookArgs, result, structuredResult, agent, run, turn) {
932
- const parsedArgs = parseGuardrailContextArgs(tool, hookArgs.args);
933
- return compact({
934
- toolName: hookArgs.toolName,
935
- args: parsedArgs,
936
- rawArgs: hookArgs.args,
937
- result,
938
- structuredResult,
939
- toolCallId: hookArgs.toolCallId,
940
- internalCallId: hookArgs.internalCallId,
941
- turn,
942
- run: guardrailRunContext(agent, run)
943
- });
944
- }
945
- function parseGuardrailContextArgs(tool, rawArgs) {
946
- const parsedArgs = parseGuardrailArgs(rawArgs);
947
- try {
948
- return tool?.parseApprovalArgs?.(parsedArgs) ?? parsedArgs;
949
- } catch {
950
- return parsedArgs;
951
- }
952
- }
953
- function parseGuardrailArgs(args) {
954
- try {
955
- return parseToolArgs(args);
956
- } catch {
957
- return args;
958
- }
959
- }
960
- function guardrailRunContext(agent, run) {
961
- return compact({
962
- agentId: agent.id,
963
- runId: run.runId,
964
- sessionId: run.sessionId,
965
- metadata: run.metadata
966
- });
967
- }
968
859
  function normalizeApprovalDecision(decision) {
969
860
  if (typeof decision === "boolean") {
970
861
  return { approved: decision };
@@ -988,8 +879,6 @@ function toolTraceMetadata(tool) {
988
879
  const mcpMetadata = typeof metadata === "object" && metadata !== null ? metadata : void 0;
989
880
  return {
990
881
  approvalRequired: tool.approval !== void 0,
991
- inputGuardrailCount: tool.inputGuardrails?.length ?? 0,
992
- outputGuardrailCount: tool.outputGuardrails?.length ?? 0,
993
882
  ...typeof mcpMetadata?.serverName === "string" && mcpMetadata.serverName.length > 0 ? { mcpServerName: mcpMetadata.serverName } : {}
994
883
  };
995
884
  }
@@ -1449,9 +1338,6 @@ var PromptRequest = class _PromptRequest {
1449
1338
  turn: currentTurns,
1450
1339
  runObservers,
1451
1340
  toolDefinitions: request.tools
1452
- },
1453
- async (decision) => {
1454
- await this.recordGuardrailDecision(decision, runObservers);
1455
1341
  }
1456
1342
  );
1457
1343
  const toolMessage = Message.tool(toolResults);
@@ -1721,10 +1607,6 @@ var PromptRequest = class _PromptRequest {
1721
1607
  turn: currentTurns,
1722
1608
  runObservers,
1723
1609
  toolDefinitions: request.tools
1724
- },
1725
- async (decision) => {
1726
- await this.recordGuardrailDecision(decision, runObservers);
1727
- toolResultEvents.enqueue({ type: "guardrail_decision", decision });
1728
1610
  }
1729
1611
  );
1730
1612
  toolResultsPromise.then(
@@ -1792,12 +1674,11 @@ var PromptRequest = class _PromptRequest {
1792
1674
  };
1793
1675
  }
1794
1676
  }
1795
- async executeToolCalls(runId, toolCalls, newMessages, onResult, onStreamEvent, observation, onGuardrailDecision) {
1677
+ async executeToolCalls(runId, toolCalls, newMessages, onResult, onStreamEvent, observation) {
1796
1678
  const executor = new ToolCallExecutor(
1797
1679
  this.agent,
1798
1680
  this.activeHook,
1799
1681
  this.approvalOptions,
1800
- this.guardrailPolicies,
1801
1682
  {
1802
1683
  runId,
1803
1684
  sessionId: this.memoryContext?.sessionId,
@@ -1805,8 +1686,7 @@ var PromptRequest = class _PromptRequest {
1805
1686
  },
1806
1687
  this.concurrency,
1807
1688
  this.requestMiddlewares,
1808
- (reason) => this.cancelled(newMessages, reason),
1809
- onGuardrailDecision
1689
+ (reason) => this.cancelled(newMessages, reason)
1810
1690
  );
1811
1691
  return executor.execute(toolCalls, onResult, onStreamEvent, observation);
1812
1692
  }
@@ -2134,4 +2014,4 @@ export {
2134
2014
  extractRagText,
2135
2015
  PromptRequest
2136
2016
  };
2137
- //# sourceMappingURL=chunk-KTTIPWE7.js.map
2017
+ //# sourceMappingURL=chunk-CO7YK4JZ.js.map