@agentionai/agents 1.6.0 → 1.8.0-beta-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.
Files changed (41) hide show
  1. package/README.md +4 -2
  2. package/dist/agents/Agent.d.ts +9 -2
  3. package/dist/agents/Agent.js +4 -0
  4. package/dist/agents/AgentConfig.d.ts +76 -2
  5. package/dist/agents/BaseAgent.d.ts +24 -2
  6. package/dist/agents/BaseAgent.js +17 -0
  7. package/dist/agents/anthropic/ClaudeAgent.d.ts +4 -3
  8. package/dist/agents/anthropic/ClaudeAgent.js +47 -17
  9. package/dist/agents/cancellation.d.ts +55 -0
  10. package/dist/agents/cancellation.js +72 -0
  11. package/dist/agents/errors/AgentError.d.ts +50 -2
  12. package/dist/agents/errors/AgentError.js +57 -1
  13. package/dist/agents/google/GeminiAgent.d.ts +3 -2
  14. package/dist/agents/google/GeminiAgent.js +34 -11
  15. package/dist/agents/mistral/MistralAgent.d.ts +3 -2
  16. package/dist/agents/mistral/MistralAgent.js +33 -13
  17. package/dist/agents/ollama/OllamaAgent.d.ts +17 -3
  18. package/dist/agents/ollama/OllamaAgent.js +69 -19
  19. package/dist/agents/openai/OpenAiAgent.d.ts +4 -3
  20. package/dist/agents/openai/OpenAiAgent.js +52 -17
  21. package/dist/agents/openai-compatible/OpenAICompatibleAgent.d.ts +4 -3
  22. package/dist/agents/openai-compatible/OpenAICompatibleAgent.js +48 -19
  23. package/dist/agents/openrouter/OpenRouterAgent.d.ts +234 -0
  24. package/dist/agents/openrouter/OpenRouterAgent.js +711 -0
  25. package/dist/agents/openrouter/types.d.ts +164 -0
  26. package/dist/agents/openrouter/types.js +15 -0
  27. package/dist/core.d.ts +1 -0
  28. package/dist/core.js +1 -0
  29. package/dist/history/transformers.d.ts +80 -0
  30. package/dist/history/transformers.js +156 -1
  31. package/dist/history/types.d.ts +22 -2
  32. package/dist/history/types.js +13 -2
  33. package/dist/index.d.ts +5 -1
  34. package/dist/index.js +5 -1
  35. package/dist/mcp/MCPClient.js +4 -2
  36. package/dist/openrouter.d.ts +6 -0
  37. package/dist/openrouter.js +24 -0
  38. package/dist/tools/Tool.d.ts +13 -3
  39. package/dist/tools/Tool.js +18 -4
  40. package/dist/viz/types.d.ts +1 -1
  41. package/package.json +10 -1
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Tool = exports.ToolResultEvent = exports.ToolEvent = void 0;
7
7
  const events_1 = __importDefault(require("events"));
8
+ const cancellation_1 = require("../agents/cancellation");
8
9
  const VizReporter_1 = require("../viz/VizReporter");
9
10
  const VizConfig_1 = require("../viz/VizConfig");
10
11
  class ToolEvent {
@@ -67,11 +68,19 @@ class Tool extends events_1.default {
67
68
  },
68
69
  required: ["instructions"],
69
70
  },
70
- execute: async (input) => {
71
+ execute: async (input, _context, options) => {
71
72
  try {
72
- return (await agent.execute(input.instructions));
73
+ return (await agent.execute(input.instructions, {
74
+ signal: options?.signal,
75
+ }));
73
76
  }
74
77
  catch (error) {
78
+ // A cancelled run is not a tool failure: reporting it as a tool
79
+ // result would have the calling agent carry on with the very run
80
+ // that was just cancelled.
81
+ if ((0, cancellation_1.isAbortError)(error, options?.signal)) {
82
+ throw error;
83
+ }
75
84
  return JSON.stringify({
76
85
  error: "Failed to execute instructions: " + error.message,
77
86
  });
@@ -87,7 +96,12 @@ class Tool extends events_1.default {
87
96
  this.description = config.description;
88
97
  this.schema = config.inputSchema;
89
98
  }
90
- async execute(agentId, agentName, input, id, agentModel, agentVendor) {
99
+ /**
100
+ * @param options Per-call options. `options.signal` is the agent run's
101
+ * `AbortSignal`, forwarded to the tool's own `execute` so it
102
+ * can cancel whatever work it started.
103
+ */
104
+ async execute(agentId, agentName, input, id, agentModel, agentVendor, options) {
91
105
  const event = new ToolEvent(this, input, id, agentId, agentName);
92
106
  this.emit(ToolEvent.EXECUTE, event);
93
107
  if (event.isDefaultPrevented) {
@@ -105,7 +119,7 @@ class Tool extends events_1.default {
105
119
  vizEventId = VizReporter_1.vizReporter.toolStart(this.name, id, input, vizSource);
106
120
  }
107
121
  try {
108
- const result = await this.executeFn(input, this.context);
122
+ const result = await this.executeFn(input, this.context, options);
109
123
  const resultEvent = new ToolResultEvent(this, input, id, result, agentId, agentName);
110
124
  this.emit(ToolResultEvent.RESULT, resultEvent);
111
125
  if (resultEvent.isDefaultPrevented) {
@@ -2,7 +2,7 @@
2
2
  * Visualization event types and interfaces for agent monitoring.
3
3
  * These types define the contract between agention-lib and @agention/viz.
4
4
  */
5
- export type VizVendor = "anthropic" | "openai" | "mistral" | "gemini" | "ollama" | "llamacpp";
5
+ export type VizVendor = "anthropic" | "openai" | "mistral" | "gemini" | "ollama" | "llamacpp" | "openrouter";
6
6
  export type VizEventType = "session.start" | "session.end" | "pipeline.start" | "pipeline.end" | "executor.start" | "executor.end" | "agent.start" | "agent.complete" | "agent.error" | "tool.start" | "tool.complete" | "tool.error" | "message.user" | "message.assistant";
7
7
  export type VizExecutorType = "sequential" | "parallel" | "map" | "voting" | "router";
8
8
  export type VizStopReason = "end_turn" | "tool_use" | "max_tokens" | "stop_sequence" | "error";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentionai/agents",
3
3
  "author": "Laurent Zuijdwijk",
4
- "version": "1.6.0",
4
+ "version": "1.8.0-beta-0",
5
5
  "description": "Agent Library",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -38,6 +38,10 @@
38
38
  "types": "./dist/llamacpp.d.ts",
39
39
  "default": "./dist/llamacpp.js"
40
40
  },
41
+ "./openrouter": {
42
+ "types": "./dist/openrouter.d.ts",
43
+ "default": "./dist/openrouter.js"
44
+ },
41
45
  "./embeddings": {
42
46
  "types": "./dist/embeddings/index.d.ts",
43
47
  "default": "./dist/embeddings/index.js"
@@ -114,6 +118,7 @@
114
118
  "@lancedb/lancedb": "^0.23.0",
115
119
  "@mistralai/mistralai": "^1.13.0",
116
120
  "@modelcontextprotocol/sdk": "^1.30.0",
121
+ "@openrouter/sdk": "^1.2.37",
117
122
  "@types/jest": "^29.5.0",
118
123
  "@types/node": "^18.15.11",
119
124
  "apache-arrow": "^18.1.0",
@@ -145,6 +150,7 @@
145
150
  "@lancedb/lancedb": "^0.23.0",
146
151
  "@mistralai/mistralai": "^1.13.0",
147
152
  "@modelcontextprotocol/sdk": "^1.26.0",
153
+ "@openrouter/sdk": "^1.2.29",
148
154
  "apache-arrow": "^18.0.0",
149
155
  "ollama": "^0.5.18",
150
156
  "openai": "^6.16.0",
@@ -180,6 +186,9 @@
180
186
  },
181
187
  "ollama": {
182
188
  "optional": true
189
+ },
190
+ "@openrouter/sdk": {
191
+ "optional": true
183
192
  }
184
193
  },
185
194
  "dependencies": {