@arvo-tools/agentic 1.2.16 → 2.0.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/AgentDefaults.d.ts +4 -1
- package/dist/Agent/AgentDefaults.d.ts.map +1 -1
- package/dist/Agent/AgentDefaults.js +110 -73
- package/dist/Agent/AgentDefaults.js.map +1 -1
- package/dist/Agent/agentLoop.d.ts +19 -17
- package/dist/Agent/agentLoop.d.ts.map +1 -1
- package/dist/Agent/agentLoop.js +239 -120
- package/dist/Agent/agentLoop.js.map +1 -1
- package/dist/Agent/index.d.ts +91 -39
- package/dist/Agent/index.d.ts.map +1 -1
- package/dist/Agent/index.js +218 -146
- package/dist/Agent/index.js.map +1 -1
- package/dist/Agent/schema.d.ts +326 -22
- package/dist/Agent/schema.d.ts.map +1 -1
- package/dist/Agent/schema.js +23 -1
- package/dist/Agent/schema.js.map +1 -1
- package/dist/Agent/stream/schema.d.ts +39 -39
- package/dist/Agent/types.d.ts +170 -79
- package/dist/Agent/types.d.ts.map +1 -1
- package/dist/Agent/utils.d.ts +6 -0
- package/dist/Agent/utils.d.ts.map +1 -1
- package/dist/Agent/utils.js +10 -1
- package/dist/Agent/utils.js.map +1 -1
- package/dist/AgentTool/index.d.ts +2 -3
- package/dist/AgentTool/index.d.ts.map +1 -1
- package/dist/AgentTool/index.js +11 -7
- package/dist/AgentTool/index.js.map +1 -1
- package/dist/AgentTool/types.d.ts +27 -9
- package/dist/AgentTool/types.d.ts.map +1 -1
- package/dist/Integrations/MCPClient.d.ts +2 -2
- package/dist/Integrations/MCPClient.js +2 -2
- package/dist/Integrations/anthropic/index.d.ts.map +1 -1
- package/dist/Integrations/anthropic/index.js +3 -3
- package/dist/Integrations/anthropic/index.js.map +1 -1
- package/dist/Integrations/openai/index.d.ts.map +1 -1
- package/dist/Integrations/openai/index.js +3 -3
- package/dist/Integrations/openai/index.js.map +1 -1
- package/dist/Integrations/types.d.ts +89 -15
- package/dist/Integrations/types.d.ts.map +1 -1
- package/dist/Integrations/types.js +47 -0
- package/dist/Integrations/types.js.map +1 -1
- package/dist/SimplePermissionManager/contract.d.ts +4 -4
- package/dist/SimplePermissionManager/index.d.ts +12 -12
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/Agent/index.js
CHANGED
|
@@ -57,6 +57,17 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
57
57
|
}
|
|
58
58
|
return t;
|
|
59
59
|
};
|
|
60
|
+
var __values = (this && this.__values) || function(o) {
|
|
61
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
62
|
+
if (m) return m.call(o);
|
|
63
|
+
if (o && typeof o.length === "number") return {
|
|
64
|
+
next: function () {
|
|
65
|
+
if (o && i >= o.length) o = void 0;
|
|
66
|
+
return { value: o && o[i++], done: !o };
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
70
|
+
};
|
|
60
71
|
var __read = (this && this.__read) || function (o, n) {
|
|
61
72
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
62
73
|
if (!m) return o;
|
|
@@ -82,23 +93,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
82
93
|
}
|
|
83
94
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
84
95
|
};
|
|
85
|
-
var __values = (this && this.__values) || function(o) {
|
|
86
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
87
|
-
if (m) return m.call(o);
|
|
88
|
-
if (o && typeof o.length === "number") return {
|
|
89
|
-
next: function () {
|
|
90
|
-
if (o && i >= o.length) o = void 0;
|
|
91
|
-
return { value: o && o[i++], done: !o };
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
95
|
-
};
|
|
96
96
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
97
97
|
exports.createArvoAgent = void 0;
|
|
98
98
|
var arvo_core_1 = require("arvo-core");
|
|
99
99
|
var arvo_event_handler_1 = require("arvo-event-handler");
|
|
100
100
|
var uuid_1 = require("uuid");
|
|
101
|
+
var AgentDefaults_js_1 = require("./AgentDefaults.js");
|
|
101
102
|
var agentLoop_js_1 = require("./agentLoop.js");
|
|
103
|
+
var schema_js_1 = require("./schema.js");
|
|
102
104
|
var utils_js_1 = require("./stream/utils.js");
|
|
103
105
|
var utils_js_2 = require("./utils.js");
|
|
104
106
|
/**
|
|
@@ -109,19 +111,36 @@ var utils_js_2 = require("./utils.js");
|
|
|
109
111
|
* consuming zero resources between event processing cycles while maintaining conversation
|
|
110
112
|
* state in persistent memory.
|
|
111
113
|
*
|
|
112
|
-
* @
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
|
|
124
|
-
*
|
|
114
|
+
* @remark
|
|
115
|
+
* **Execution Model:**
|
|
116
|
+
* The agent follows a start-stop-resume pattern. On initialization, it builds context from
|
|
117
|
+
* the input event, then enters a ReAct (Reason+Act) cognitive loop. When calling Arvo services,
|
|
118
|
+
* it persists state to memory and suspends, enabling any worker to resume it later. This
|
|
119
|
+
* eliminates long-running processes and enables horizontal scaling.
|
|
120
|
+
*
|
|
121
|
+
* **Tool Ecosystem:**
|
|
122
|
+
* - **Internal Tools:** Synchronous functions for fast, CPU-bound operations.
|
|
123
|
+
* - **MCP Tools:** External tools via Model Context Protocol (filesystem, databases, APIs).
|
|
124
|
+
* - **Arvo Services:** Asynchronous event-driven services that trigger suspension.
|
|
125
|
+
*
|
|
126
|
+
* Both Internal and MCP tools execute synchronously within the loop, while Arvo service calls
|
|
127
|
+
* cause the agent to emit events and suspend until responses arrive.
|
|
128
|
+
*
|
|
129
|
+
* **Priority Batch Execution:**
|
|
130
|
+
* When the LLM requests multiple tools, they are sorted by priority. Only the highest-priority
|
|
131
|
+
* batch executes; lower-priority calls are dropped. This enforces safety guardrails (e.g.,
|
|
132
|
+
* requiring human approval before destructive actions).
|
|
133
|
+
*
|
|
134
|
+
* **Permission Management:**
|
|
135
|
+
* Tools can be placed under permission policy via `explicitPermissionRequired`. The permission
|
|
136
|
+
* manager evaluates each tool call as APPROVED (execute), DENIED (block permanently), or
|
|
137
|
+
* REQUESTABLE (block and emit permission request). Permission state persists across suspensions.
|
|
138
|
+
*
|
|
139
|
+
* **Self-Correction:**
|
|
140
|
+
* If the LLM's outputs fails contract schema validation, the error is fed back and the
|
|
141
|
+
* agent retries, enabling automatic repair of malformed responses or tools calls.
|
|
142
|
+
*
|
|
143
|
+
* @param param - Configuration object defining the agent's contracts, tools, memory backend,
|
|
125
144
|
* LLM integration, and version-specific behavior handlers.
|
|
126
145
|
*
|
|
127
146
|
* @returns An ArvoResumable instance that participates in the event fabric as a standard
|
|
@@ -149,16 +168,17 @@ var utils_js_2 = require("./utils.js");
|
|
|
149
168
|
* name: 'check_time',
|
|
150
169
|
* description: 'Returns current server time in ISO format',
|
|
151
170
|
* input: z.object({}),
|
|
152
|
-
*
|
|
153
|
-
* fn: async () => ({ time: new Date().toISOString() })
|
|
171
|
+
* fn: async () => ({ data: { time: new Date().toISOString() } })
|
|
154
172
|
* })
|
|
155
173
|
* },
|
|
156
|
-
*
|
|
174
|
+
* inferenceConfig: {
|
|
175
|
+
* llm: openaiLLMIntegration(new OpenAI(), { model: 'gpt-4o' }),
|
|
176
|
+
* },
|
|
157
177
|
* memory: memory,
|
|
158
|
-
* permissionManager: new
|
|
178
|
+
* permissionManager: new SimplePermissionManager(),
|
|
159
179
|
* handler: {
|
|
160
180
|
* '1.0.0': {
|
|
161
|
-
*
|
|
181
|
+
* explicitPermissionRequired: async ({ services }) => [
|
|
162
182
|
* services.billing.name // Require permission for billing calls
|
|
163
183
|
* ],
|
|
164
184
|
* context: AgentDefaults.CONTEXT_BUILDER(async ({ tools }) =>
|
|
@@ -172,19 +192,34 @@ var utils_js_2 = require("./utils.js");
|
|
|
172
192
|
* ```
|
|
173
193
|
*/
|
|
174
194
|
var createArvoAgent = function (_a) {
|
|
175
|
-
var _b;
|
|
176
|
-
var contracts = _a.contracts, memory = _a.memory, handler = _a.handler,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
195
|
+
var e_1, _b, _c;
|
|
196
|
+
var contracts = _a.contracts, memory = _a.memory, handler = _a.handler, inferenceConfig = _a.inferenceConfig, mcp = _a.mcp, _d = _a.maxAgentCycles, maxAgentCycles = _d === void 0 ? 5 : _d, tools = _a.tools, onStream = _a.onStream, permissionManager = _a.permissionManager, defaultEventEmissionDomains = _a.defaultEventEmissionDomains;
|
|
197
|
+
// biome-ignore lint/suspicious/noExplicitAny: Needs to be general
|
|
198
|
+
var serviceContracts = {};
|
|
199
|
+
var serviceTransformers = {};
|
|
200
|
+
try {
|
|
201
|
+
for (var _e = __values(Object.entries(contracts.services)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
202
|
+
var _g = __read(_f.value, 2), key = _g[0], _h = _g[1], contract = _h.contract, transformer = _h.transformer;
|
|
203
|
+
serviceContracts[key] = contract;
|
|
204
|
+
if (transformer) {
|
|
205
|
+
serviceTransformers[contract.accepts.type] = transformer;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
210
|
+
finally {
|
|
211
|
+
try {
|
|
212
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
213
|
+
}
|
|
214
|
+
finally { if (e_1) throw e_1.error; }
|
|
215
|
+
}
|
|
181
216
|
var serviceTypeToDomainMap = Object.fromEntries(Object.values(contracts.services)
|
|
182
217
|
.filter(function (item) { var _a; return (_a = item.domains) === null || _a === void 0 ? void 0 : _a.length; })
|
|
183
218
|
.map(function (item) { return [item.contract.accepts.type, item.domains]; }));
|
|
184
219
|
if ((Object.keys(serviceContracts).length > 0 || permissionManager) && !memory) {
|
|
185
220
|
// If permissions manager or service contracts are defined and
|
|
186
|
-
// memory is not defined then that is not allowed
|
|
187
|
-
//
|
|
221
|
+
// memory is not defined then that is not allowed as by adding
|
|
222
|
+
// the permission manager it will automatically imply that sometime in its lifecycle,
|
|
188
223
|
// the Agent will need event-driven coordinations and will create a
|
|
189
224
|
// suspension boundary
|
|
190
225
|
throw new arvo_event_handler_1.ConfigViolation((0, arvo_core_1.cleanString)("\n ArvoAgent<".concat(contracts.self.type, "> configuration error.\n\n This agent is configured with capabilities that can introduce a suspension boundary\n (service contracts and/or a permission manager), but no memory backend was provided.\n\n Why this matters:\n - Service contracts and permission workflows may cause the agent to emit an event and suspend.\n - Suspending requires persisting conversation state so the agent can resume correctly.\n\n How to fix:\n - Provide a memory backend (e.g. SimpleMachineMemory or any implementation of IMachineMemory), or\n - Remove service contracts and the permission manager if this agent is intended\n to run as a single synchronous execution without suspension.\n ")));
|
|
@@ -192,7 +227,7 @@ var createArvoAgent = function (_a) {
|
|
|
192
227
|
return (0, arvo_event_handler_1.createArvoResumable)({
|
|
193
228
|
contracts: {
|
|
194
229
|
self: contracts.self,
|
|
195
|
-
services: __assign(__assign({}, serviceContracts), (permissionManager ? (
|
|
230
|
+
services: __assign(__assign({}, serviceContracts), (permissionManager ? (_c = {}, _c["pm-".concat((0, uuid_1.v4)())] = permissionManager.contract, _c) : {})),
|
|
196
231
|
},
|
|
197
232
|
memory: memory !== null && memory !== void 0 ? memory : new arvo_event_handler_1.SimpleMachineMemory(),
|
|
198
233
|
types: {
|
|
@@ -203,13 +238,14 @@ var createArvoAgent = function (_a) {
|
|
|
203
238
|
handler: Object.fromEntries(Object.keys(contracts.self.versions).map(function (ver) { return [
|
|
204
239
|
ver,
|
|
205
240
|
(function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
206
|
-
var otelInfo, agentEventStreamer, contextBuilder, outputBuilder, thisVersionLlmIntegration, versionLlmResponseType, selfVersionedContract, outputFormat, permissionManagerContext, serviceTools, mcpTools, internalTools, permissionPolicy,
|
|
241
|
+
var context, otelInfo, agentEventStreamer, contextBuilder, outputBuilder, thisVersionLlmIntegration, versionLlmResponseType, selfVersionedContract, outputFormat, permissionManagerContext, preInferenceHook, postInferenceHook, serviceTools, mcpTools, internalTools, permissionPolicy, agentCycles, _c, parentSubject$$, inputData, llmContext, response_1, resumableContextToPersist_1, resumedContext, messages, _d, _e, _f, toolUseId, _g, type, responseEventType, data, transformedResult, e_2_1, response_2, resumableContextToPersist_2, e_3;
|
|
207
242
|
var e_2, _h;
|
|
208
|
-
var _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24;
|
|
209
|
-
var span = _b.span, input = _b.input,
|
|
210
|
-
return __generator(this, function (
|
|
211
|
-
switch (
|
|
243
|
+
var _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43;
|
|
244
|
+
var span = _b.span, input = _b.input, _context = _b.context, service = _b.service;
|
|
245
|
+
return __generator(this, function (_44) {
|
|
246
|
+
switch (_44.label) {
|
|
212
247
|
case 0:
|
|
248
|
+
context = _context ? schema_js_1.AgentStateSchema.parse(_context) : null;
|
|
213
249
|
otelInfo = {
|
|
214
250
|
span: span,
|
|
215
251
|
headers: (0, arvo_core_1.getOtelHeaderFromSpan)(span),
|
|
@@ -232,37 +268,39 @@ var createArvoAgent = function (_a) {
|
|
|
232
268
|
(0, arvo_core_1.exceptionToSpan)(e, span);
|
|
233
269
|
}
|
|
234
270
|
};
|
|
235
|
-
|
|
271
|
+
_44.label = 1;
|
|
236
272
|
case 1:
|
|
237
|
-
|
|
238
|
-
contextBuilder = (_j = handler[ver]) === null || _j === void 0 ? void 0 : _j.context;
|
|
239
|
-
outputBuilder = (
|
|
240
|
-
thisVersionLlmIntegration = (
|
|
241
|
-
versionLlmResponseType = (
|
|
273
|
+
_44.trys.push([1, 23, 25, 27]);
|
|
274
|
+
contextBuilder = (_k = (_j = handler[ver]) === null || _j === void 0 ? void 0 : _j.context) !== null && _k !== void 0 ? _k : AgentDefaults_js_1.AgentDefaults.CONTEXT_BUILDER();
|
|
275
|
+
outputBuilder = (_m = (_l = handler[ver]) === null || _l === void 0 ? void 0 : _l.output) !== null && _m !== void 0 ? _m : AgentDefaults_js_1.AgentDefaults.OUTPUT_BUILDER;
|
|
276
|
+
thisVersionLlmIntegration = (_q = (_p = (_o = handler[ver]) === null || _o === void 0 ? void 0 : _o.inferenceConfig) === null || _p === void 0 ? void 0 : _p.llm) !== null && _q !== void 0 ? _q : inferenceConfig === null || inferenceConfig === void 0 ? void 0 : inferenceConfig.llm;
|
|
277
|
+
versionLlmResponseType = (_u = (_t = (_s = (_r = handler[ver]) === null || _r === void 0 ? void 0 : _r.inferenceConfig) === null || _s === void 0 ? void 0 : _s.responseType) !== null && _t !== void 0 ? _t : inferenceConfig.responseType) !== null && _u !== void 0 ? _u : 'text';
|
|
242
278
|
selfVersionedContract = contracts.self.version(ver);
|
|
243
279
|
outputFormat = selfVersionedContract.emits[selfVersionedContract.metadata.completeEventType];
|
|
244
280
|
permissionManagerContext = {
|
|
245
|
-
subject: (
|
|
246
|
-
accesscontrol: (
|
|
281
|
+
subject: (_w = (_v = context === null || context === void 0 ? void 0 : context.currentSubject) !== null && _v !== void 0 ? _v : input === null || input === void 0 ? void 0 : input.subject) !== null && _w !== void 0 ? _w : 'unknown',
|
|
282
|
+
accesscontrol: (_y = (_x = context === null || context === void 0 ? void 0 : context.initEventAccessControl) !== null && _x !== void 0 ? _x : input === null || input === void 0 ? void 0 : input.accesscontrol) !== null && _y !== void 0 ? _y : null,
|
|
247
283
|
name: contracts.self.type,
|
|
248
284
|
};
|
|
285
|
+
preInferenceHook = (_4 = (_2 = (_1 = (_0 = (_z = handler[ver]) === null || _z === void 0 ? void 0 : _z.inferenceConfig) === null || _0 === void 0 ? void 0 : _0.hooks) === null || _1 === void 0 ? void 0 : _1.preInference) !== null && _2 !== void 0 ? _2 : (_3 = inferenceConfig === null || inferenceConfig === void 0 ? void 0 : inferenceConfig.hooks) === null || _3 === void 0 ? void 0 : _3.preInference) !== null && _4 !== void 0 ? _4 : null;
|
|
286
|
+
postInferenceHook = (_10 = (_8 = (_7 = (_6 = (_5 = handler[ver]) === null || _5 === void 0 ? void 0 : _5.inferenceConfig) === null || _6 === void 0 ? void 0 : _6.hooks) === null || _7 === void 0 ? void 0 : _7.postInference) !== null && _8 !== void 0 ? _8 : (_9 = inferenceConfig === null || inferenceConfig === void 0 ? void 0 : inferenceConfig.hooks) === null || _9 === void 0 ? void 0 : _9.postInference) !== null && _10 !== void 0 ? _10 : null;
|
|
249
287
|
return [4 /*yield*/, (mcp === null || mcp === void 0 ? void 0 : mcp.connect({ otelInfo: otelInfo }))];
|
|
250
288
|
case 2:
|
|
251
|
-
|
|
289
|
+
_44.sent();
|
|
252
290
|
serviceTools = (0, utils_js_2.generateServiceToolDefinitions)(contracts.services);
|
|
253
291
|
return [4 /*yield*/, (0, utils_js_2.generateMcpToolDefinitions)(mcp !== null && mcp !== void 0 ? mcp : null, { otelInfo: otelInfo })];
|
|
254
292
|
case 3:
|
|
255
|
-
mcpTools =
|
|
293
|
+
mcpTools = _44.sent();
|
|
256
294
|
internalTools = (0, utils_js_2.generateAgentInternalToolDefinitions)(tools !== null && tools !== void 0 ? tools : {});
|
|
257
|
-
return [4 /*yield*/, ((
|
|
295
|
+
return [4 /*yield*/, ((_12 = (_11 = handler[ver]) === null || _11 === void 0 ? void 0 : _11.explicitPermissionRequired) === null || _12 === void 0 ? void 0 : _12.call(_11, {
|
|
258
296
|
services: serviceTools,
|
|
259
297
|
mcp: mcpTools,
|
|
260
298
|
tools: internalTools,
|
|
261
299
|
}))];
|
|
262
300
|
case 4:
|
|
263
|
-
permissionPolicy = (
|
|
264
|
-
|
|
265
|
-
max:
|
|
301
|
+
permissionPolicy = (_13 = (_44.sent())) !== null && _13 !== void 0 ? _13 : [];
|
|
302
|
+
agentCycles = (_14 = context === null || context === void 0 ? void 0 : context.agentCycles) !== null && _14 !== void 0 ? _14 : {
|
|
303
|
+
max: maxAgentCycles,
|
|
266
304
|
current: 0,
|
|
267
305
|
};
|
|
268
306
|
if (!input) return [3 /*break*/, 8];
|
|
@@ -275,12 +313,12 @@ var createArvoAgent = function (_a) {
|
|
|
275
313
|
selfContract: selfVersionedContract,
|
|
276
314
|
})];
|
|
277
315
|
case 5:
|
|
278
|
-
llmContext = (
|
|
316
|
+
llmContext = (_15 = (_44.sent())) !== null && _15 !== void 0 ? _15 : null;
|
|
279
317
|
return [4 /*yield*/, (0, agentLoop_js_1.agentLoop)({
|
|
280
318
|
permissionManagerContext: permissionManagerContext,
|
|
281
319
|
initLifecycle: 'init',
|
|
282
|
-
system: (
|
|
283
|
-
messages: (((
|
|
320
|
+
system: (_16 = llmContext === null || llmContext === void 0 ? void 0 : llmContext.system) !== null && _16 !== void 0 ? _16 : null,
|
|
321
|
+
messages: (((_17 = llmContext === null || llmContext === void 0 ? void 0 : llmContext.messages) === null || _17 === void 0 ? void 0 : _17.length)
|
|
284
322
|
? llmContext.messages
|
|
285
323
|
: [
|
|
286
324
|
{
|
|
@@ -289,13 +327,15 @@ var createArvoAgent = function (_a) {
|
|
|
289
327
|
seenCount: 0,
|
|
290
328
|
},
|
|
291
329
|
]).map(function (item) { var _a; return (__assign(__assign({}, item), { seenCount: (_a = item.seenCount) !== null && _a !== void 0 ? _a : 0 })); }),
|
|
292
|
-
tools: Object.values(__assign(__assign(__assign({}, mcpTools), serviceTools), internalTools)),
|
|
330
|
+
tools: (0, utils_js_2.applyToolEnablement)(Object.values(__assign(__assign(__assign({}, mcpTools), serviceTools), internalTools)), (_18 = llmContext === null || llmContext === void 0 ? void 0 : llmContext.enabledTools) !== null && _18 !== void 0 ? _18 : {}),
|
|
331
|
+
preInferenceHook: preInferenceHook,
|
|
332
|
+
postInferenceHook: postInferenceHook,
|
|
293
333
|
outputFormat: outputFormat,
|
|
294
334
|
outputBuilder: outputBuilder,
|
|
295
335
|
llmResponseType: versionLlmResponseType,
|
|
296
336
|
llm: thisVersionLlmIntegration,
|
|
297
337
|
mcp: mcp !== null && mcp !== void 0 ? mcp : null,
|
|
298
|
-
|
|
338
|
+
agentCycles: agentCycles,
|
|
299
339
|
currentTotalExecutionUnits: 0,
|
|
300
340
|
onStream: agentEventStreamer,
|
|
301
341
|
currentTotalUsageTokens: {
|
|
@@ -306,16 +346,17 @@ var createArvoAgent = function (_a) {
|
|
|
306
346
|
permissionPolicy: permissionPolicy,
|
|
307
347
|
}, { otelInfo: otelInfo })];
|
|
308
348
|
case 6:
|
|
309
|
-
response_1 =
|
|
349
|
+
response_1 = _44.sent();
|
|
310
350
|
resumableContextToPersist_1 = {
|
|
311
|
-
initEventAccessControl: (
|
|
351
|
+
initEventAccessControl: (_19 = input.accesscontrol) !== null && _19 !== void 0 ? _19 : null,
|
|
312
352
|
currentSubject: input.subject,
|
|
313
|
-
|
|
353
|
+
enabledTools: (_20 = llmContext === null || llmContext === void 0 ? void 0 : llmContext.enabledTools) !== null && _20 !== void 0 ? _20 : {},
|
|
354
|
+
system: (_21 = llmContext === null || llmContext === void 0 ? void 0 : llmContext.system) !== null && _21 !== void 0 ? _21 : null,
|
|
314
355
|
messages: response_1.messages,
|
|
315
|
-
|
|
316
|
-
awaitingToolCalls: Object.fromEntries(((
|
|
356
|
+
agentCycles: response_1.agentCycles,
|
|
357
|
+
awaitingToolCalls: Object.fromEntries(((_22 = response_1.toolCalls) !== null && _22 !== void 0 ? _22 : []).map(function (item) { return [
|
|
317
358
|
item.toolUseId,
|
|
318
|
-
{ type: item.name, data: null },
|
|
359
|
+
{ type: item.name, responseEventType: null, data: null },
|
|
319
360
|
]; })),
|
|
320
361
|
totalExecutionUnits: response_1.executionUnits,
|
|
321
362
|
totalTokenUsage: response_1.tokenUsage,
|
|
@@ -337,14 +378,14 @@ var createArvoAgent = function (_a) {
|
|
|
337
378
|
}),
|
|
338
379
|
}];
|
|
339
380
|
}
|
|
340
|
-
return [4 /*yield*/, ((
|
|
381
|
+
return [4 /*yield*/, ((_23 = permissionManager === null || permissionManager === void 0 ? void 0 : permissionManager.cleanup) === null || _23 === void 0 ? void 0 : _23.call(permissionManager, {
|
|
341
382
|
source: permissionManagerContext,
|
|
342
383
|
config: { otelInfo: otelInfo },
|
|
343
384
|
}))];
|
|
344
385
|
case 7:
|
|
345
|
-
|
|
386
|
+
_44.sent();
|
|
346
387
|
return [2 /*return*/, {
|
|
347
|
-
context: resumableContextToPersist_1,
|
|
388
|
+
context: schema_js_1.AgentStateSchema.parse(resumableContextToPersist_1),
|
|
348
389
|
output: __assign({ __executionunits: response_1.executionUnits }, response_1.output),
|
|
349
390
|
}];
|
|
350
391
|
case 8:
|
|
@@ -355,7 +396,9 @@ var createArvoAgent = function (_a) {
|
|
|
355
396
|
if (!((service === null || service === void 0 ? void 0 : service.parentid) && resumedContext.awaitingToolCalls[service.parentid])) return [3 /*break*/, 11];
|
|
356
397
|
// biome-ignore lint/style/noNonNullAssertion: It cannot be null. The if clause does already
|
|
357
398
|
resumedContext.awaitingToolCalls[service.parentid].data = service.data;
|
|
358
|
-
|
|
399
|
+
// biome-ignore lint/style/noNonNullAssertion: It cannot be null. The if clause does already
|
|
400
|
+
resumedContext.awaitingToolCalls[service.parentid].responseEventType = service.type;
|
|
401
|
+
if (!(service.type === ((_26 = (_25 = (_24 = permissionManager === null || permissionManager === void 0 ? void 0 : permissionManager.contract) === null || _24 === void 0 ? void 0 : _24.emitList) === null || _25 === void 0 ? void 0 : _25[0]) === null || _26 === void 0 ? void 0 : _26.type))) return [3 /*break*/, 10];
|
|
359
402
|
return [4 /*yield*/, (permissionManager === null || permissionManager === void 0 ? void 0 : permissionManager.set({
|
|
360
403
|
source: permissionManagerContext,
|
|
361
404
|
// biome-ignore lint/suspicious/noExplicitAny: Type casting here is weird
|
|
@@ -363,73 +406,102 @@ var createArvoAgent = function (_a) {
|
|
|
363
406
|
config: { otelInfo: otelInfo },
|
|
364
407
|
}))];
|
|
365
408
|
case 9:
|
|
366
|
-
|
|
367
|
-
|
|
409
|
+
_44.sent();
|
|
410
|
+
_44.label = 10;
|
|
368
411
|
case 10:
|
|
369
|
-
if (service.type === ((
|
|
370
|
-
throw new Error((0, arvo_core_1.cleanString)("\n [Critical] The agent's attempt to request permission via ".concat((
|
|
412
|
+
if (service.type === ((_28 = (_27 = permissionManager === null || permissionManager === void 0 ? void 0 : permissionManager.contract) === null || _27 === void 0 ? void 0 : _27.systemError) === null || _28 === void 0 ? void 0 : _28.type)) {
|
|
413
|
+
throw new Error((0, arvo_core_1.cleanString)("\n [Critical] The agent's attempt to request permission via ".concat((_30 = (_29 = permissionManager === null || permissionManager === void 0 ? void 0 : permissionManager.contract) === null || _29 === void 0 ? void 0 : _29.accepts) === null || _30 === void 0 ? void 0 : _30.type, "\n failed with error: ").concat(JSON.stringify(service.data), "\n ")));
|
|
371
414
|
}
|
|
372
|
-
|
|
415
|
+
_44.label = 11;
|
|
373
416
|
case 11:
|
|
374
417
|
if (Object.values(resumedContext.awaitingToolCalls).some(function (item) { return item.data === null; })) {
|
|
375
|
-
return [2 /*return*/, { context: resumedContext }];
|
|
418
|
+
return [2 /*return*/, { context: schema_js_1.AgentStateSchema.parse(resumedContext) }];
|
|
376
419
|
}
|
|
377
420
|
messages = __spreadArray([], __read(resumedContext.messages), false);
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
toolUseId: toolUseId,
|
|
397
|
-
content: JSON.stringify(data !== null && data !== void 0 ? data : {}),
|
|
398
|
-
},
|
|
399
|
-
seenCount: 0,
|
|
400
|
-
});
|
|
401
|
-
}
|
|
421
|
+
_44.label = 12;
|
|
422
|
+
case 12:
|
|
423
|
+
_44.trys.push([12, 18, 19, 20]);
|
|
424
|
+
_d = __values(Object.entries(resumedContext.awaitingToolCalls)), _e = _d.next();
|
|
425
|
+
_44.label = 13;
|
|
426
|
+
case 13:
|
|
427
|
+
if (!!_e.done) return [3 /*break*/, 17];
|
|
428
|
+
_f = __read(_e.value, 2), toolUseId = _f[0], _g = _f[1], type = _g.type, responseEventType = _g.responseEventType, data = _g.data;
|
|
429
|
+
if (type === ((_32 = (_31 = permissionManager === null || permissionManager === void 0 ? void 0 : permissionManager.contract) === null || _31 === void 0 ? void 0 : _31.accepts) === null || _32 === void 0 ? void 0 : _32.type)) {
|
|
430
|
+
messages.push({
|
|
431
|
+
role: 'user',
|
|
432
|
+
content: {
|
|
433
|
+
type: 'text',
|
|
434
|
+
content: "The response of the permission request. ".concat(JSON.stringify(data !== null && data !== void 0 ? data : {})),
|
|
435
|
+
},
|
|
436
|
+
seenCount: 0,
|
|
437
|
+
});
|
|
438
|
+
return [3 /*break*/, 16];
|
|
402
439
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
440
|
+
if (!(serviceTransformers[type] && responseEventType && data)) return [3 /*break*/, 15];
|
|
441
|
+
return [4 /*yield*/, serviceTransformers[type]({
|
|
442
|
+
type: responseEventType,
|
|
443
|
+
data: data,
|
|
444
|
+
toolUseId: toolUseId,
|
|
445
|
+
})];
|
|
446
|
+
case 14:
|
|
447
|
+
transformedResult = _44.sent();
|
|
448
|
+
if (Array.isArray(transformedResult)) {
|
|
449
|
+
messages = __spreadArray(__spreadArray([], __read(messages), false), __read(transformedResult), false);
|
|
409
450
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
case
|
|
429
|
-
|
|
430
|
-
|
|
451
|
+
else {
|
|
452
|
+
messages.push(transformedResult);
|
|
453
|
+
}
|
|
454
|
+
return [3 /*break*/, 16];
|
|
455
|
+
case 15:
|
|
456
|
+
messages.push({
|
|
457
|
+
role: 'user',
|
|
458
|
+
content: {
|
|
459
|
+
type: 'tool_result',
|
|
460
|
+
toolUseId: toolUseId,
|
|
461
|
+
content: JSON.stringify(data !== null && data !== void 0 ? data : {}),
|
|
462
|
+
},
|
|
463
|
+
seenCount: 0,
|
|
464
|
+
});
|
|
465
|
+
_44.label = 16;
|
|
466
|
+
case 16:
|
|
467
|
+
_e = _d.next();
|
|
468
|
+
return [3 /*break*/, 13];
|
|
469
|
+
case 17: return [3 /*break*/, 20];
|
|
470
|
+
case 18:
|
|
471
|
+
e_2_1 = _44.sent();
|
|
472
|
+
e_2 = { error: e_2_1 };
|
|
473
|
+
return [3 /*break*/, 20];
|
|
474
|
+
case 19:
|
|
475
|
+
try {
|
|
476
|
+
if (_e && !_e.done && (_h = _d.return)) _h.call(_d);
|
|
477
|
+
}
|
|
478
|
+
finally { if (e_2) throw e_2.error; }
|
|
479
|
+
return [7 /*endfinally*/];
|
|
480
|
+
case 20: return [4 /*yield*/, (0, agentLoop_js_1.agentLoop)({
|
|
481
|
+
permissionManagerContext: permissionManagerContext,
|
|
482
|
+
initLifecycle: 'tool_result',
|
|
483
|
+
system: (_33 = resumedContext.system) !== null && _33 !== void 0 ? _33 : null,
|
|
484
|
+
messages: messages,
|
|
485
|
+
tools: (0, utils_js_2.applyToolEnablement)(Object.values(__assign(__assign(__assign({}, mcpTools), serviceTools), internalTools)), resumedContext.enabledTools),
|
|
486
|
+
outputFormat: outputFormat,
|
|
487
|
+
preInferenceHook: preInferenceHook,
|
|
488
|
+
postInferenceHook: postInferenceHook,
|
|
489
|
+
outputBuilder: outputBuilder,
|
|
490
|
+
llmResponseType: versionLlmResponseType,
|
|
491
|
+
llm: thisVersionLlmIntegration,
|
|
492
|
+
mcp: mcp !== null && mcp !== void 0 ? mcp : null,
|
|
493
|
+
agentCycles: agentCycles,
|
|
494
|
+
currentTotalExecutionUnits: resumedContext.totalExecutionUnits,
|
|
495
|
+
onStream: agentEventStreamer,
|
|
496
|
+
currentTotalUsageTokens: resumedContext.totalTokenUsage,
|
|
497
|
+
permissionManager: permissionManager !== null && permissionManager !== void 0 ? permissionManager : null,
|
|
498
|
+
permissionPolicy: permissionPolicy,
|
|
499
|
+
}, { otelInfo: otelInfo })];
|
|
500
|
+
case 21:
|
|
501
|
+
response_2 = _44.sent();
|
|
502
|
+
resumableContextToPersist_2 = __assign(__assign({}, resumedContext), { messages: response_2.messages, agentCycles: response_2.agentCycles, awaitingToolCalls: Object.fromEntries(((_34 = response_2.toolCalls) !== null && _34 !== void 0 ? _34 : []).map(function (item) { return [
|
|
431
503
|
item.toolUseId,
|
|
432
|
-
{ type: item.name, data: null },
|
|
504
|
+
{ type: item.name, data: null, responseEventType: null },
|
|
433
505
|
]; })), totalExecutionUnits: response_2.executionUnits, totalTokenUsage: response_2.tokenUsage });
|
|
434
506
|
if (response_2.toolCalls) {
|
|
435
507
|
return [2 /*return*/, {
|
|
@@ -448,36 +520,36 @@ var createArvoAgent = function (_a) {
|
|
|
448
520
|
}),
|
|
449
521
|
}];
|
|
450
522
|
}
|
|
451
|
-
return [4 /*yield*/, ((
|
|
523
|
+
return [4 /*yield*/, ((_35 = permissionManager === null || permissionManager === void 0 ? void 0 : permissionManager.cleanup) === null || _35 === void 0 ? void 0 : _35.call(permissionManager, {
|
|
452
524
|
source: permissionManagerContext,
|
|
453
525
|
config: { otelInfo: otelInfo },
|
|
454
526
|
}))];
|
|
455
|
-
case
|
|
456
|
-
|
|
527
|
+
case 22:
|
|
528
|
+
_44.sent();
|
|
457
529
|
return [2 /*return*/, {
|
|
458
|
-
context: resumableContextToPersist_2,
|
|
530
|
+
context: schema_js_1.AgentStateSchema.parse(resumableContextToPersist_2),
|
|
459
531
|
output: __assign({ __executionunits: response_2.executionUnits }, response_2.output),
|
|
460
532
|
}];
|
|
461
|
-
case
|
|
462
|
-
|
|
533
|
+
case 23:
|
|
534
|
+
e_3 = _44.sent();
|
|
463
535
|
// Add correct otelinfo object here
|
|
464
|
-
return [4 /*yield*/, ((
|
|
536
|
+
return [4 /*yield*/, ((_36 = permissionManager === null || permissionManager === void 0 ? void 0 : permissionManager.cleanup) === null || _36 === void 0 ? void 0 : _36.call(permissionManager, {
|
|
465
537
|
source: {
|
|
466
|
-
subject: (
|
|
467
|
-
accesscontrol: (
|
|
538
|
+
subject: (_39 = (_38 = (_37 = context === null || context === void 0 ? void 0 : context.currentSubject) !== null && _37 !== void 0 ? _37 : input === null || input === void 0 ? void 0 : input.subject) !== null && _38 !== void 0 ? _38 : service === null || service === void 0 ? void 0 : service.subject) !== null && _39 !== void 0 ? _39 : 'unknown',
|
|
539
|
+
accesscontrol: (_42 = (_41 = (_40 = context === null || context === void 0 ? void 0 : context.initEventAccessControl) !== null && _40 !== void 0 ? _40 : input === null || input === void 0 ? void 0 : input.accesscontrol) !== null && _41 !== void 0 ? _41 : service === null || service === void 0 ? void 0 : service.accesscontrol) !== null && _42 !== void 0 ? _42 : null,
|
|
468
540
|
name: contracts.self.type,
|
|
469
541
|
},
|
|
470
542
|
config: { otelInfo: otelInfo },
|
|
471
543
|
}))];
|
|
472
|
-
case
|
|
544
|
+
case 24:
|
|
473
545
|
// Add correct otelinfo object here
|
|
474
|
-
|
|
475
|
-
throw
|
|
476
|
-
case
|
|
477
|
-
case
|
|
478
|
-
|
|
546
|
+
_44.sent();
|
|
547
|
+
throw e_3;
|
|
548
|
+
case 25: return [4 /*yield*/, ((_43 = mcp === null || mcp === void 0 ? void 0 : mcp.disconnect({ otelInfo: otelInfo })) === null || _43 === void 0 ? void 0 : _43.catch(console.error))];
|
|
549
|
+
case 26:
|
|
550
|
+
_44.sent();
|
|
479
551
|
return [7 /*endfinally*/];
|
|
480
|
-
case
|
|
552
|
+
case 27: return [2 /*return*/];
|
|
481
553
|
}
|
|
482
554
|
});
|
|
483
555
|
}); }),
|