openloops 0.1.31 → 0.1.33
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/clients/llm-client.d.ts +5 -0
- package/dist/clients/llm-client.js +73 -15
- package/dist/clients/llm-client.mjs +73 -15
- package/dist/clients/llm-error.d.ts +9 -0
- package/dist/clients/llm-error.js +69 -0
- package/dist/clients/llm-error.mjs +45 -0
- package/dist/clients/llm-types.d.ts +61 -0
- package/dist/clients/llm-types.js +16 -0
- package/dist/clients/llm-types.mjs +0 -0
- package/dist/clients/pi-ai-adapter.d.ts +7 -0
- package/dist/clients/pi-ai-adapter.js +137 -0
- package/dist/clients/pi-ai-adapter.mjs +113 -0
- package/dist/{agent → harness}/agent-loop.d.ts +11 -1
- package/dist/{agent → harness}/agent-state.js +1 -1
- package/dist/{agent → harness}/agent-state.mjs +1 -1
- package/dist/{agent → harness}/agent.d.ts +34 -3
- package/dist/harness/agent.js +546 -0
- package/dist/harness/agent.mjs +530 -0
- package/dist/{agent → harness}/index.js +5 -5
- package/dist/harness/native-tools.d.ts +23 -0
- package/dist/harness/native-tools.js +251 -0
- package/dist/harness/native-tools.mjs +227 -0
- package/dist/harness/tool-catalog.d.ts +16 -0
- package/dist/harness/tool-catalog.js +85 -0
- package/dist/harness/tool-catalog.mjs +59 -0
- package/dist/harness/tool-pipeline.d.ts +42 -0
- package/dist/harness/tool-pipeline.js +200 -0
- package/dist/harness/tool-pipeline.mjs +177 -0
- package/dist/harness/utils/describe-shape.d.ts +2 -0
- package/dist/harness/utils/describe-shape.js +56 -0
- package/dist/harness/utils/describe-shape.mjs +32 -0
- package/dist/harness/utils/grounding.d.ts +6 -0
- package/dist/harness/utils/grounding.js +79 -0
- package/dist/harness/utils/grounding.mjs +53 -0
- package/dist/harness/workspace.d.ts +44 -0
- package/dist/harness/workspace.js +95 -0
- package/dist/harness/workspace.mjs +78 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/loops/agi/index.d.ts +1 -0
- package/dist/loops/agi/index.js +22 -0
- package/dist/loops/agi/index.mjs +1 -0
- package/dist/loops/agi/loop.d.ts +24 -0
- package/dist/loops/agi/loop.js +220 -0
- package/dist/loops/agi/loop.mjs +197 -0
- package/dist/loops/agi/skills/reasoning-engine.d.ts +14 -0
- package/dist/loops/agi/skills/reasoning-engine.js +94 -0
- package/dist/loops/agi/skills/reasoning-engine.mjs +71 -0
- package/dist/loops/index.d.ts +1 -0
- package/dist/loops/index.js +3 -1
- package/dist/loops/index.mjs +1 -0
- package/dist/loops/plan-execute/plan-execute-loop.d.ts +2 -1
- package/dist/loops/plan-execute/plan-execute-loop.js +90 -35
- package/dist/loops/plan-execute/plan-execute-loop.mjs +80 -25
- package/dist/loops/shared/skills/action-planner.js +7 -4
- package/dist/loops/shared/skills/action-planner.mjs +7 -4
- package/dist/loops/shared/skills/final-responder.js +4 -3
- package/dist/loops/shared/skills/final-responder.mjs +4 -3
- package/dist/loops/shared/skills/state-observer.js +6 -2
- package/dist/loops/shared/skills/state-observer.mjs +6 -2
- package/dist/services/chats/entities/chat-message.entity.d.ts +4 -1
- package/dist/services/chats/entities/chat-message.entity.js +7 -3
- package/dist/services/chats/entities/chat-message.entity.mjs +7 -3
- package/dist/services/chats/entities/chat.entity.d.ts +10 -11
- package/dist/services/chats/entities/chat.entity.js +17 -21
- package/dist/services/chats/entities/chat.entity.mjs +17 -21
- package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.d.ts +2 -0
- package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.js +4 -4
- package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.mjs +2 -2
- package/dist/services/tasks/entities/agent-action.entity.d.ts +111 -0
- package/dist/services/tasks/entities/agent-action.entity.js +271 -0
- package/dist/services/tasks/entities/agent-action.entity.mjs +247 -0
- package/dist/services/tasks/entities/agent-task.entity.d.ts +176 -0
- package/dist/services/tasks/entities/agent-task.entity.js +695 -0
- package/dist/services/tasks/entities/agent-task.entity.mjs +662 -0
- package/dist/services/tasks/entities/index.d.ts +2 -0
- package/dist/services/tasks/entities/index.js +24 -0
- package/dist/services/tasks/entities/index.mjs +2 -0
- package/dist/services/tasks/index.d.ts +3 -0
- package/dist/services/tasks/index.js +26 -0
- package/dist/services/tasks/index.mjs +3 -0
- package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.d.ts +14 -0
- package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.js +60 -0
- package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.mjs +31 -0
- package/dist/services/tasks/lambdas/create-agent-action/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/create-agent-action/index.js +22 -0
- package/dist/services/tasks/lambdas/create-agent-action/index.mjs +1 -0
- package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.d.ts +14 -0
- package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.js +60 -0
- package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.mjs +31 -0
- package/dist/services/tasks/lambdas/create-agent-task/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/create-agent-task/index.js +22 -0
- package/dist/services/tasks/lambdas/create-agent-task/index.mjs +1 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.d.ts +14 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.js +55 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.mjs +26 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/index.js +22 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/index.mjs +1 -0
- package/dist/services/tasks/lambdas/index.d.ts +7 -0
- package/dist/services/tasks/lambdas/index.js +46 -0
- package/dist/services/tasks/lambdas/index.mjs +17 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.js +22 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.mjs +1 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.d.ts +16 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.js +62 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.mjs +33 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.js +22 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.mjs +1 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.d.ts +16 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.js +62 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.mjs +33 -0
- package/dist/services/tasks/lambdas/update-agent-action/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/update-agent-action/index.js +22 -0
- package/dist/services/tasks/lambdas/update-agent-action/index.mjs +1 -0
- package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.d.ts +15 -0
- package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.js +67 -0
- package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.mjs +38 -0
- package/dist/services/tasks/lambdas/update-agent-task/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/update-agent-task/index.js +22 -0
- package/dist/services/tasks/lambdas/update-agent-task/index.mjs +1 -0
- package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.d.ts +15 -0
- package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.js +67 -0
- package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.mjs +38 -0
- package/dist/services/tasks/module.d.ts +15 -0
- package/dist/services/tasks/module.js +76 -0
- package/dist/services/tasks/module.mjs +47 -0
- package/dist/services/tasks/repositories/agent-action.repository.d.ts +8 -0
- package/dist/services/tasks/repositories/agent-action.repository.js +62 -0
- package/dist/services/tasks/repositories/agent-action.repository.mjs +33 -0
- package/dist/services/tasks/repositories/agent-task.repository.d.ts +9 -0
- package/dist/services/tasks/repositories/agent-task.repository.js +65 -0
- package/dist/services/tasks/repositories/agent-task.repository.mjs +36 -0
- package/dist/services/tasks/repositories/index.d.ts +2 -0
- package/dist/services/tasks/repositories/index.js +24 -0
- package/dist/services/tasks/repositories/index.mjs +2 -0
- package/dist/services/traces/entities/agent-trace-entry.entity.d.ts +30 -0
- package/dist/services/traces/entities/agent-trace-entry.entity.js +85 -0
- package/dist/services/traces/entities/agent-trace-entry.entity.mjs +62 -0
- package/dist/services/traces/entities/index.d.ts +1 -0
- package/dist/services/traces/entities/index.js +22 -0
- package/dist/services/traces/entities/index.mjs +1 -0
- package/dist/services/traces/index.d.ts +3 -0
- package/dist/services/traces/index.js +26 -0
- package/dist/services/traces/index.mjs +3 -0
- package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.d.ts +16 -0
- package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.js +62 -0
- package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.mjs +33 -0
- package/dist/services/traces/lambdas/create-agent-traces/index.d.ts +1 -0
- package/dist/services/traces/lambdas/create-agent-traces/index.js +22 -0
- package/dist/services/traces/lambdas/create-agent-traces/index.mjs +1 -0
- package/dist/services/traces/lambdas/index.d.ts +2 -0
- package/dist/services/traces/lambdas/index.js +31 -0
- package/dist/services/traces/lambdas/index.mjs +7 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.d.ts +1 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.js +22 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.mjs +1 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.d.ts +18 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.js +67 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.mjs +38 -0
- package/dist/services/traces/module.d.ts +5 -0
- package/dist/services/traces/module.js +41 -0
- package/dist/services/traces/module.mjs +17 -0
- package/dist/services/traces/repositories/agent-trace.repository.d.ts +7 -0
- package/dist/services/traces/repositories/agent-trace.repository.js +55 -0
- package/dist/services/traces/repositories/agent-trace.repository.mjs +26 -0
- package/dist/services/traces/repositories/index.d.ts +1 -0
- package/dist/services/traces/repositories/index.js +22 -0
- package/dist/services/traces/repositories/index.mjs +1 -0
- package/dist/services/workspaces/entities/index.d.ts +1 -0
- package/dist/services/workspaces/entities/index.js +22 -0
- package/dist/services/workspaces/entities/index.mjs +1 -0
- package/dist/services/workspaces/entities/workspace-item.entity.d.ts +33 -0
- package/dist/services/workspaces/entities/workspace-item.entity.js +95 -0
- package/dist/services/workspaces/entities/workspace-item.entity.mjs +72 -0
- package/dist/services/workspaces/index.d.ts +3 -0
- package/dist/services/workspaces/index.js +26 -0
- package/dist/services/workspaces/index.mjs +3 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.d.ts +17 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.js +68 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.mjs +39 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/index.d.ts +1 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/index.js +22 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/index.mjs +1 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.d.ts +17 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.js +67 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.mjs +38 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/index.d.ts +1 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/index.js +22 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/index.mjs +1 -0
- package/dist/services/workspaces/lambdas/index.d.ts +5 -0
- package/dist/services/workspaces/lambdas/index.js +40 -0
- package/dist/services/workspaces/lambdas/index.mjs +13 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/index.d.ts +1 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/index.js +22 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/index.mjs +1 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.d.ts +18 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.js +69 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.mjs +40 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/index.d.ts +1 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/index.js +22 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/index.mjs +1 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.d.ts +14 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.js +76 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.mjs +47 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/index.d.ts +1 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/index.js +22 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/index.mjs +1 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.d.ts +19 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.js +73 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.mjs +44 -0
- package/dist/services/workspaces/module.d.ts +11 -0
- package/dist/services/workspaces/module.js +62 -0
- package/dist/services/workspaces/module.mjs +35 -0
- package/dist/services/workspaces/repositories/index.d.ts +1 -0
- package/dist/services/workspaces/repositories/index.js +22 -0
- package/dist/services/workspaces/repositories/index.mjs +1 -0
- package/dist/services/workspaces/repositories/workspace-item.repository.d.ts +18 -0
- package/dist/services/workspaces/repositories/workspace-item.repository.js +74 -0
- package/dist/services/workspaces/repositories/workspace-item.repository.mjs +45 -0
- package/dist/skills/runtime-context.d.ts +8 -0
- package/dist/skills/runtime-context.js +65 -0
- package/dist/skills/runtime-context.mjs +42 -0
- package/dist/skills/skill.d.ts +7 -0
- package/dist/skills/skill.js +26 -60
- package/dist/skills/skill.mjs +26 -60
- package/dist/tools/tool.d.ts +6 -0
- package/dist/tools/tool.js +56 -0
- package/dist/tools/tool.mjs +56 -0
- package/package.json +3 -3
- package/dist/agent/agent.js +0 -327
- package/dist/agent/agent.mjs +0 -303
- package/dist/services/chats/entities/agent-action.entity.d.ts +0 -58
- package/dist/services/chats/entities/agent-action.entity.js +0 -151
- package/dist/services/chats/entities/agent-action.entity.mjs +0 -128
- package/dist/services/chats/entities/agent-task.entity.d.ts +0 -59
- package/dist/services/chats/entities/agent-task.entity.js +0 -231
- package/dist/services/chats/entities/agent-task.entity.mjs +0 -207
- package/dist/services/chats/entities/chat-context.entity.d.ts +0 -39
- package/dist/services/chats/entities/chat-context.entity.js +0 -70
- package/dist/services/chats/entities/chat-context.entity.mjs +0 -47
- /package/dist/{agent → harness}/agent-loop.js +0 -0
- /package/dist/{agent → harness}/agent-loop.mjs +0 -0
- /package/dist/{agent → harness}/agent-state.d.ts +0 -0
- /package/dist/{agent → harness}/index.d.ts +0 -0
- /package/dist/{agent → harness}/index.mjs +0 -0
- /package/dist/{agent → harness}/utils/rank-tools-by-keywords.d.ts +0 -0
- /package/dist/{agent → harness}/utils/rank-tools-by-keywords.js +0 -0
- /package/dist/{agent → harness}/utils/rank-tools-by-keywords.mjs +0 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var native_tools_exports = {};
|
|
20
|
+
__export(native_tools_exports, {
|
|
21
|
+
NATIVE_TOOLS: () => NATIVE_TOOLS,
|
|
22
|
+
NativeTools: () => NativeTools
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(native_tools_exports);
|
|
25
|
+
var import_agent_task = require("../services/tasks/entities/agent-task.entity.js");
|
|
26
|
+
var import_tool_catalog = require("./tool-catalog");
|
|
27
|
+
const DEFAULT_SEARCH_LIMIT = 5;
|
|
28
|
+
const MAX_SEARCH_LIMIT = 8;
|
|
29
|
+
const SEARCH_DESCRIPTION_CHARS = 300;
|
|
30
|
+
const SEARCH_OUTPUT_CHARS = 5500;
|
|
31
|
+
const DEFAULT_READ_CHARS = 4e3;
|
|
32
|
+
const MAX_READ_CHARS = 5e3;
|
|
33
|
+
const MAX_FIND_MATCHES = 20;
|
|
34
|
+
const FIND_RECORD_CHARS = 600;
|
|
35
|
+
const FIND_MAX_NODES = 2e5;
|
|
36
|
+
const FIND_MAX_DEPTH = 12;
|
|
37
|
+
function squash(text) {
|
|
38
|
+
return text.toLowerCase().replace(/[^\p{L}\p{N}]/gu, "");
|
|
39
|
+
}
|
|
40
|
+
function findRecords(root, query) {
|
|
41
|
+
const wanted = squash(query);
|
|
42
|
+
const words = query.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
43
|
+
if (!wanted) return [];
|
|
44
|
+
const search = (matches) => {
|
|
45
|
+
const found = [];
|
|
46
|
+
const seen = /* @__PURE__ */ new Set();
|
|
47
|
+
let nodes = 0;
|
|
48
|
+
const walk = (value, path, parent, depth) => {
|
|
49
|
+
if (nodes++ > FIND_MAX_NODES || depth > FIND_MAX_DEPTH) return;
|
|
50
|
+
if (typeof value === "string") {
|
|
51
|
+
const record = parent !== null && typeof parent === "object" && !Array.isArray(parent) ? parent : value;
|
|
52
|
+
if (matches(value) && !seen.has(record)) {
|
|
53
|
+
seen.add(record);
|
|
54
|
+
found.push({ path, record });
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(value)) value.forEach((item, index) => walk(item, `${path}[${index}]`, value, depth + 1));
|
|
59
|
+
else if (value !== null && typeof value === "object") Object.entries(value).forEach(([key, item]) => walk(item, path ? `${path}.${key}` : key, value, depth + 1));
|
|
60
|
+
};
|
|
61
|
+
walk(root, "", null, 0);
|
|
62
|
+
return found;
|
|
63
|
+
};
|
|
64
|
+
const exact = search((text) => squash(text).includes(wanted));
|
|
65
|
+
return exact.length || words.length < 2 ? exact : search((text) => words.every((word) => squash(text).includes(squash(word))));
|
|
66
|
+
}
|
|
67
|
+
const NATIVE_TOOLS = [
|
|
68
|
+
{
|
|
69
|
+
name: "search_tools",
|
|
70
|
+
description: "Find external tools by capability. Pass a few keywords, written in the language of the tool descriptions in CONTEXT.tool_sources, each with a weight from 0.1 (marginal) to 1.0 (essential). Returns the matching tools; from your next turn they are in your tool list and you run them by naming them in an action.",
|
|
71
|
+
parameters: {
|
|
72
|
+
type: "object",
|
|
73
|
+
properties: {
|
|
74
|
+
keywords: {
|
|
75
|
+
type: "array",
|
|
76
|
+
description: "Keywords describing the capability, in the language of the tool descriptions, for example calendar, events, list",
|
|
77
|
+
items: {
|
|
78
|
+
type: "object",
|
|
79
|
+
properties: {
|
|
80
|
+
keyword: { type: "string", description: "A single word, or a short fixed expression" },
|
|
81
|
+
weight: { type: "number", description: "Importance from 0.1 to 1.0" }
|
|
82
|
+
},
|
|
83
|
+
required: ["keyword", "weight"]
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
page: { type: "integer", description: "Result page, starting at 1" },
|
|
87
|
+
limit: { type: "integer", description: `Tools per page (default ${DEFAULT_SEARCH_LIMIT}, max ${MAX_SEARCH_LIMIT})` }
|
|
88
|
+
},
|
|
89
|
+
required: ["keywords"]
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "read_context",
|
|
94
|
+
description: 'Read a workspace item: a note saved with save_context, or a large tool output (use the "workspace_ref" name from its result as "name"). Supports a path into structured content, paging for long text, and "find" to locate entries inside a large result by text.',
|
|
95
|
+
parameters: {
|
|
96
|
+
type: "object",
|
|
97
|
+
properties: {
|
|
98
|
+
name: { type: "string", description: "Name of the workspace item" },
|
|
99
|
+
path: { type: "string", description: "Optional path into structured content, like results[0].id" },
|
|
100
|
+
find: { type: "string", description: 'Text to look for inside the item (or inside "path"). Case, spaces, hyphens and underscores are ignored. Returns only the matching entries with their path, so you do not have to read a long list' },
|
|
101
|
+
offset: { type: "integer", description: "Character offset to start reading from (default 0)" },
|
|
102
|
+
max_chars: { type: "integer", description: `Maximum characters to return (default ${DEFAULT_READ_CHARS}, max ${MAX_READ_CHARS})` }
|
|
103
|
+
},
|
|
104
|
+
required: ["name"]
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "save_context",
|
|
109
|
+
description: 'Save a note in the task workspace to reuse it later, either with read_context or by referencing "{{context.<name>}}" in tool arguments. Use it for facts, decisions or intermediate results worth keeping.',
|
|
110
|
+
parameters: {
|
|
111
|
+
type: "object",
|
|
112
|
+
properties: {
|
|
113
|
+
name: { type: "string", description: "Short unique name using letters, numbers, underscore or dash" },
|
|
114
|
+
content: { type: "string", description: "The text or JSON to store" },
|
|
115
|
+
description: { type: "string", description: "One line explaining what the note contains" }
|
|
116
|
+
},
|
|
117
|
+
required: ["name", "content"]
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "ask_user",
|
|
122
|
+
description: "Pause the task and ask the user a question. Use it only when you cannot continue without information that only the user can provide. Their answer comes back as the result of this action.",
|
|
123
|
+
parameters: {
|
|
124
|
+
type: "object",
|
|
125
|
+
properties: {
|
|
126
|
+
question: { type: "string", description: "The question to show to the user, in the user's language" }
|
|
127
|
+
},
|
|
128
|
+
required: ["question"]
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: "respond",
|
|
133
|
+
description: "Deliver your final answer to the user and end the task. Use it once, when you have what you need or when you cannot do more. Do not combine it with actions whose results you still need.",
|
|
134
|
+
parameters: {
|
|
135
|
+
type: "object",
|
|
136
|
+
properties: {
|
|
137
|
+
answer: { type: "string", description: "The final answer for the user, in the user's language" }
|
|
138
|
+
},
|
|
139
|
+
required: ["answer"]
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
];
|
|
143
|
+
class NativeTools {
|
|
144
|
+
constructor(deps) {
|
|
145
|
+
this.deps = deps;
|
|
146
|
+
}
|
|
147
|
+
deps;
|
|
148
|
+
async run(task, action) {
|
|
149
|
+
const definition = NATIVE_TOOLS.find((tool) => tool.name === action.name);
|
|
150
|
+
const args = action.args ?? {};
|
|
151
|
+
const missing = (definition?.parameters.required ?? []).filter((key) => args[key] === void 0 || args[key] === null);
|
|
152
|
+
if (missing.length) {
|
|
153
|
+
action.markFailed({ message: `Invalid arguments: ${missing.map((key) => `Missing required argument "${key}"`).join("; ")}`, retryable: false });
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
action.markRunning();
|
|
157
|
+
try {
|
|
158
|
+
action.markCompleted(await this.execute(task, action.name, args));
|
|
159
|
+
} catch (error) {
|
|
160
|
+
action.markFailed({ message: error?.message ?? String(error), retryable: false });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async execute(task, name, args) {
|
|
164
|
+
switch (name) {
|
|
165
|
+
case "search_tools":
|
|
166
|
+
return this.searchTools(args);
|
|
167
|
+
case "read_context":
|
|
168
|
+
return this.readContext(task, args);
|
|
169
|
+
case "save_context":
|
|
170
|
+
return this.saveContext(task, args);
|
|
171
|
+
default:
|
|
172
|
+
throw new Error(`"${name}" is interpreted by the runtime and cannot be executed`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
searchTools(args) {
|
|
176
|
+
const keywords = (Array.isArray(args.keywords) ? args.keywords : []).map((item) => typeof item === "string" ? { keyword: item, weight: 1 } : { keyword: String(item?.keyword ?? ""), weight: Number(item?.weight) || 1 });
|
|
177
|
+
const limit = Math.min(Math.max(Number(args.limit) || DEFAULT_SEARCH_LIMIT, 1), MAX_SEARCH_LIMIT);
|
|
178
|
+
const page = Math.max(Number(args.page) || 1, 1);
|
|
179
|
+
const tools = [];
|
|
180
|
+
let size = 0;
|
|
181
|
+
for (const { tool } of this.deps.searchTools(keywords, { page, limit })) {
|
|
182
|
+
const { parameters, ...entry } = (0, import_tool_catalog.describeTool)(tool, SEARCH_DESCRIPTION_CHARS);
|
|
183
|
+
size += JSON.stringify(entry).length;
|
|
184
|
+
if (tools.length && size > SEARCH_OUTPUT_CHARS) break;
|
|
185
|
+
tools.push(entry);
|
|
186
|
+
}
|
|
187
|
+
return tools.length ? { page, tools, note: "These tools are now in your tool list: run them by naming them in an action." } : { page, tools, hint: "No tool matched. Retry with synonyms written in the language of the tool descriptions shown in CONTEXT.tool_sources." };
|
|
188
|
+
}
|
|
189
|
+
async readContext(task, args) {
|
|
190
|
+
const item = await this.deps.workspace.get(String(args.name), { taskId: task.id });
|
|
191
|
+
if (!item) {
|
|
192
|
+
const available = await this.deps.workspace.list({ taskId: task.id }).then((items) => items.map((entry) => entry.name).slice(0, 30)).catch(() => []);
|
|
193
|
+
return { found: false, error: `There is no workspace item named "${args.name}". This does not mean a search had no results.`, available };
|
|
194
|
+
}
|
|
195
|
+
const path = args.path ? String(args.path).replace(/^(?=[\w-])/, ".") : void 0;
|
|
196
|
+
const value = (0, import_agent_task.readPath)(item.content, path);
|
|
197
|
+
if (value === void 0) return { found: true, name: item.name, path_found: false };
|
|
198
|
+
if (typeof args.find === "string" && args.find.trim()) {
|
|
199
|
+
const found = findRecords(value, args.find);
|
|
200
|
+
return {
|
|
201
|
+
name: item.name,
|
|
202
|
+
find: args.find,
|
|
203
|
+
total_matches: found.length,
|
|
204
|
+
matches: found.slice(0, MAX_FIND_MATCHES).map(({ path: matchPath, record }) => {
|
|
205
|
+
const text2 = typeof record === "string" ? record : JSON.stringify(record);
|
|
206
|
+
return { path: matchPath, record: text2.length > FIND_RECORD_CHARS ? text2.slice(0, FIND_RECORD_CHARS) : record };
|
|
207
|
+
}),
|
|
208
|
+
...found.length > MAX_FIND_MATCHES ? { note: `Showing the first ${MAX_FIND_MATCHES} matches: use a more specific text.` } : {},
|
|
209
|
+
...found.length ? {} : { hint: "No entry contains this text. Try a shorter or different part of it, or read the item with a path." },
|
|
210
|
+
...item.truncated ? { stored_truncated: true } : {}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const text = typeof value === "string" ? value : JSON.stringify(value);
|
|
214
|
+
const offset = Math.max(Number(args.offset) || 0, 0);
|
|
215
|
+
const max = Math.min(Math.max(Number(args.max_chars) || DEFAULT_READ_CHARS, 1), MAX_READ_CHARS);
|
|
216
|
+
return {
|
|
217
|
+
name: item.name,
|
|
218
|
+
total_chars: text.length,
|
|
219
|
+
offset,
|
|
220
|
+
has_more: offset + max < text.length,
|
|
221
|
+
...item.truncated ? { stored_truncated: true } : {},
|
|
222
|
+
content: text.slice(offset, offset + max)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
async saveContext(task, args) {
|
|
226
|
+
const name = String(args.name).trim().replace(/[^\w-]/g, "_");
|
|
227
|
+
if (!name) throw new Error("A valid name is required");
|
|
228
|
+
let content = args.content;
|
|
229
|
+
if (typeof content === "string") {
|
|
230
|
+
try {
|
|
231
|
+
content = JSON.parse(content);
|
|
232
|
+
} catch {
|
|
233
|
+
content = args.content;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
await this.deps.workspace.save({
|
|
237
|
+
name,
|
|
238
|
+
kind: "note",
|
|
239
|
+
taskId: task.id,
|
|
240
|
+
content,
|
|
241
|
+
description: args.description,
|
|
242
|
+
source: "save_context"
|
|
243
|
+
});
|
|
244
|
+
return { saved: name };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
248
|
+
0 && (module.exports = {
|
|
249
|
+
NATIVE_TOOLS,
|
|
250
|
+
NativeTools
|
|
251
|
+
});
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import "../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { readPath } from "../services/tasks/entities/agent-task.entity.js";
|
|
3
|
+
import { describeTool } from "./tool-catalog";
|
|
4
|
+
const DEFAULT_SEARCH_LIMIT = 5;
|
|
5
|
+
const MAX_SEARCH_LIMIT = 8;
|
|
6
|
+
const SEARCH_DESCRIPTION_CHARS = 300;
|
|
7
|
+
const SEARCH_OUTPUT_CHARS = 5500;
|
|
8
|
+
const DEFAULT_READ_CHARS = 4e3;
|
|
9
|
+
const MAX_READ_CHARS = 5e3;
|
|
10
|
+
const MAX_FIND_MATCHES = 20;
|
|
11
|
+
const FIND_RECORD_CHARS = 600;
|
|
12
|
+
const FIND_MAX_NODES = 2e5;
|
|
13
|
+
const FIND_MAX_DEPTH = 12;
|
|
14
|
+
function squash(text) {
|
|
15
|
+
return text.toLowerCase().replace(/[^\p{L}\p{N}]/gu, "");
|
|
16
|
+
}
|
|
17
|
+
function findRecords(root, query) {
|
|
18
|
+
const wanted = squash(query);
|
|
19
|
+
const words = query.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
20
|
+
if (!wanted) return [];
|
|
21
|
+
const search = (matches) => {
|
|
22
|
+
const found = [];
|
|
23
|
+
const seen = /* @__PURE__ */ new Set();
|
|
24
|
+
let nodes = 0;
|
|
25
|
+
const walk = (value, path, parent, depth) => {
|
|
26
|
+
if (nodes++ > FIND_MAX_NODES || depth > FIND_MAX_DEPTH) return;
|
|
27
|
+
if (typeof value === "string") {
|
|
28
|
+
const record = parent !== null && typeof parent === "object" && !Array.isArray(parent) ? parent : value;
|
|
29
|
+
if (matches(value) && !seen.has(record)) {
|
|
30
|
+
seen.add(record);
|
|
31
|
+
found.push({ path, record });
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(value)) value.forEach((item, index) => walk(item, `${path}[${index}]`, value, depth + 1));
|
|
36
|
+
else if (value !== null && typeof value === "object") Object.entries(value).forEach(([key, item]) => walk(item, path ? `${path}.${key}` : key, value, depth + 1));
|
|
37
|
+
};
|
|
38
|
+
walk(root, "", null, 0);
|
|
39
|
+
return found;
|
|
40
|
+
};
|
|
41
|
+
const exact = search((text) => squash(text).includes(wanted));
|
|
42
|
+
return exact.length || words.length < 2 ? exact : search((text) => words.every((word) => squash(text).includes(squash(word))));
|
|
43
|
+
}
|
|
44
|
+
const NATIVE_TOOLS = [
|
|
45
|
+
{
|
|
46
|
+
name: "search_tools",
|
|
47
|
+
description: "Find external tools by capability. Pass a few keywords, written in the language of the tool descriptions in CONTEXT.tool_sources, each with a weight from 0.1 (marginal) to 1.0 (essential). Returns the matching tools; from your next turn they are in your tool list and you run them by naming them in an action.",
|
|
48
|
+
parameters: {
|
|
49
|
+
type: "object",
|
|
50
|
+
properties: {
|
|
51
|
+
keywords: {
|
|
52
|
+
type: "array",
|
|
53
|
+
description: "Keywords describing the capability, in the language of the tool descriptions, for example calendar, events, list",
|
|
54
|
+
items: {
|
|
55
|
+
type: "object",
|
|
56
|
+
properties: {
|
|
57
|
+
keyword: { type: "string", description: "A single word, or a short fixed expression" },
|
|
58
|
+
weight: { type: "number", description: "Importance from 0.1 to 1.0" }
|
|
59
|
+
},
|
|
60
|
+
required: ["keyword", "weight"]
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
page: { type: "integer", description: "Result page, starting at 1" },
|
|
64
|
+
limit: { type: "integer", description: `Tools per page (default ${DEFAULT_SEARCH_LIMIT}, max ${MAX_SEARCH_LIMIT})` }
|
|
65
|
+
},
|
|
66
|
+
required: ["keywords"]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "read_context",
|
|
71
|
+
description: 'Read a workspace item: a note saved with save_context, or a large tool output (use the "workspace_ref" name from its result as "name"). Supports a path into structured content, paging for long text, and "find" to locate entries inside a large result by text.',
|
|
72
|
+
parameters: {
|
|
73
|
+
type: "object",
|
|
74
|
+
properties: {
|
|
75
|
+
name: { type: "string", description: "Name of the workspace item" },
|
|
76
|
+
path: { type: "string", description: "Optional path into structured content, like results[0].id" },
|
|
77
|
+
find: { type: "string", description: 'Text to look for inside the item (or inside "path"). Case, spaces, hyphens and underscores are ignored. Returns only the matching entries with their path, so you do not have to read a long list' },
|
|
78
|
+
offset: { type: "integer", description: "Character offset to start reading from (default 0)" },
|
|
79
|
+
max_chars: { type: "integer", description: `Maximum characters to return (default ${DEFAULT_READ_CHARS}, max ${MAX_READ_CHARS})` }
|
|
80
|
+
},
|
|
81
|
+
required: ["name"]
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "save_context",
|
|
86
|
+
description: 'Save a note in the task workspace to reuse it later, either with read_context or by referencing "{{context.<name>}}" in tool arguments. Use it for facts, decisions or intermediate results worth keeping.',
|
|
87
|
+
parameters: {
|
|
88
|
+
type: "object",
|
|
89
|
+
properties: {
|
|
90
|
+
name: { type: "string", description: "Short unique name using letters, numbers, underscore or dash" },
|
|
91
|
+
content: { type: "string", description: "The text or JSON to store" },
|
|
92
|
+
description: { type: "string", description: "One line explaining what the note contains" }
|
|
93
|
+
},
|
|
94
|
+
required: ["name", "content"]
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: "ask_user",
|
|
99
|
+
description: "Pause the task and ask the user a question. Use it only when you cannot continue without information that only the user can provide. Their answer comes back as the result of this action.",
|
|
100
|
+
parameters: {
|
|
101
|
+
type: "object",
|
|
102
|
+
properties: {
|
|
103
|
+
question: { type: "string", description: "The question to show to the user, in the user's language" }
|
|
104
|
+
},
|
|
105
|
+
required: ["question"]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "respond",
|
|
110
|
+
description: "Deliver your final answer to the user and end the task. Use it once, when you have what you need or when you cannot do more. Do not combine it with actions whose results you still need.",
|
|
111
|
+
parameters: {
|
|
112
|
+
type: "object",
|
|
113
|
+
properties: {
|
|
114
|
+
answer: { type: "string", description: "The final answer for the user, in the user's language" }
|
|
115
|
+
},
|
|
116
|
+
required: ["answer"]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
];
|
|
120
|
+
class NativeTools {
|
|
121
|
+
constructor(deps) {
|
|
122
|
+
this.deps = deps;
|
|
123
|
+
}
|
|
124
|
+
deps;
|
|
125
|
+
async run(task, action) {
|
|
126
|
+
const definition = NATIVE_TOOLS.find((tool) => tool.name === action.name);
|
|
127
|
+
const args = action.args ?? {};
|
|
128
|
+
const missing = (definition?.parameters.required ?? []).filter((key) => args[key] === void 0 || args[key] === null);
|
|
129
|
+
if (missing.length) {
|
|
130
|
+
action.markFailed({ message: `Invalid arguments: ${missing.map((key) => `Missing required argument "${key}"`).join("; ")}`, retryable: false });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
action.markRunning();
|
|
134
|
+
try {
|
|
135
|
+
action.markCompleted(await this.execute(task, action.name, args));
|
|
136
|
+
} catch (error) {
|
|
137
|
+
action.markFailed({ message: error?.message ?? String(error), retryable: false });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async execute(task, name, args) {
|
|
141
|
+
switch (name) {
|
|
142
|
+
case "search_tools":
|
|
143
|
+
return this.searchTools(args);
|
|
144
|
+
case "read_context":
|
|
145
|
+
return this.readContext(task, args);
|
|
146
|
+
case "save_context":
|
|
147
|
+
return this.saveContext(task, args);
|
|
148
|
+
default:
|
|
149
|
+
throw new Error(`"${name}" is interpreted by the runtime and cannot be executed`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
searchTools(args) {
|
|
153
|
+
const keywords = (Array.isArray(args.keywords) ? args.keywords : []).map((item) => typeof item === "string" ? { keyword: item, weight: 1 } : { keyword: String(item?.keyword ?? ""), weight: Number(item?.weight) || 1 });
|
|
154
|
+
const limit = Math.min(Math.max(Number(args.limit) || DEFAULT_SEARCH_LIMIT, 1), MAX_SEARCH_LIMIT);
|
|
155
|
+
const page = Math.max(Number(args.page) || 1, 1);
|
|
156
|
+
const tools = [];
|
|
157
|
+
let size = 0;
|
|
158
|
+
for (const { tool } of this.deps.searchTools(keywords, { page, limit })) {
|
|
159
|
+
const { parameters, ...entry } = describeTool(tool, SEARCH_DESCRIPTION_CHARS);
|
|
160
|
+
size += JSON.stringify(entry).length;
|
|
161
|
+
if (tools.length && size > SEARCH_OUTPUT_CHARS) break;
|
|
162
|
+
tools.push(entry);
|
|
163
|
+
}
|
|
164
|
+
return tools.length ? { page, tools, note: "These tools are now in your tool list: run them by naming them in an action." } : { page, tools, hint: "No tool matched. Retry with synonyms written in the language of the tool descriptions shown in CONTEXT.tool_sources." };
|
|
165
|
+
}
|
|
166
|
+
async readContext(task, args) {
|
|
167
|
+
const item = await this.deps.workspace.get(String(args.name), { taskId: task.id });
|
|
168
|
+
if (!item) {
|
|
169
|
+
const available = await this.deps.workspace.list({ taskId: task.id }).then((items) => items.map((entry) => entry.name).slice(0, 30)).catch(() => []);
|
|
170
|
+
return { found: false, error: `There is no workspace item named "${args.name}". This does not mean a search had no results.`, available };
|
|
171
|
+
}
|
|
172
|
+
const path = args.path ? String(args.path).replace(/^(?=[\w-])/, ".") : void 0;
|
|
173
|
+
const value = readPath(item.content, path);
|
|
174
|
+
if (value === void 0) return { found: true, name: item.name, path_found: false };
|
|
175
|
+
if (typeof args.find === "string" && args.find.trim()) {
|
|
176
|
+
const found = findRecords(value, args.find);
|
|
177
|
+
return {
|
|
178
|
+
name: item.name,
|
|
179
|
+
find: args.find,
|
|
180
|
+
total_matches: found.length,
|
|
181
|
+
matches: found.slice(0, MAX_FIND_MATCHES).map(({ path: matchPath, record }) => {
|
|
182
|
+
const text2 = typeof record === "string" ? record : JSON.stringify(record);
|
|
183
|
+
return { path: matchPath, record: text2.length > FIND_RECORD_CHARS ? text2.slice(0, FIND_RECORD_CHARS) : record };
|
|
184
|
+
}),
|
|
185
|
+
...found.length > MAX_FIND_MATCHES ? { note: `Showing the first ${MAX_FIND_MATCHES} matches: use a more specific text.` } : {},
|
|
186
|
+
...found.length ? {} : { hint: "No entry contains this text. Try a shorter or different part of it, or read the item with a path." },
|
|
187
|
+
...item.truncated ? { stored_truncated: true } : {}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const text = typeof value === "string" ? value : JSON.stringify(value);
|
|
191
|
+
const offset = Math.max(Number(args.offset) || 0, 0);
|
|
192
|
+
const max = Math.min(Math.max(Number(args.max_chars) || DEFAULT_READ_CHARS, 1), MAX_READ_CHARS);
|
|
193
|
+
return {
|
|
194
|
+
name: item.name,
|
|
195
|
+
total_chars: text.length,
|
|
196
|
+
offset,
|
|
197
|
+
has_more: offset + max < text.length,
|
|
198
|
+
...item.truncated ? { stored_truncated: true } : {},
|
|
199
|
+
content: text.slice(offset, offset + max)
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
async saveContext(task, args) {
|
|
203
|
+
const name = String(args.name).trim().replace(/[^\w-]/g, "_");
|
|
204
|
+
if (!name) throw new Error("A valid name is required");
|
|
205
|
+
let content = args.content;
|
|
206
|
+
if (typeof content === "string") {
|
|
207
|
+
try {
|
|
208
|
+
content = JSON.parse(content);
|
|
209
|
+
} catch {
|
|
210
|
+
content = args.content;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
await this.deps.workspace.save({
|
|
214
|
+
name,
|
|
215
|
+
kind: "note",
|
|
216
|
+
taskId: task.id,
|
|
217
|
+
content,
|
|
218
|
+
description: args.description,
|
|
219
|
+
source: "save_context"
|
|
220
|
+
});
|
|
221
|
+
return { saved: name };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
NATIVE_TOOLS,
|
|
226
|
+
NativeTools
|
|
227
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Tool } from '../tools/tool.js';
|
|
2
|
+
import { LLMToolDefinition } from '../clients/llm-types.js';
|
|
3
|
+
export interface ToolCatalog {
|
|
4
|
+
tools: LLMToolDefinition[];
|
|
5
|
+
context: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
export interface ToolDescription {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
requires_confirmation: boolean;
|
|
11
|
+
parameters: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
export declare function isDeclarable(tool: Tool): boolean;
|
|
14
|
+
export declare function needsSearch(allTools: Tool[]): boolean;
|
|
15
|
+
export declare function describeTool(tool: Tool, chars?: number): ToolDescription;
|
|
16
|
+
export declare function buildToolCatalog(allTools: Tool[], nativeTools: LLMToolDefinition[], discovered: string[]): ToolCatalog;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var tool_catalog_exports = {};
|
|
20
|
+
__export(tool_catalog_exports, {
|
|
21
|
+
buildToolCatalog: () => buildToolCatalog,
|
|
22
|
+
describeTool: () => describeTool,
|
|
23
|
+
isDeclarable: () => isDeclarable,
|
|
24
|
+
needsSearch: () => needsSearch
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(tool_catalog_exports);
|
|
27
|
+
var import_agent_task = require("../services/tasks/entities/agent-task.entity.js");
|
|
28
|
+
const FULL_CATALOG_LIMIT = 15;
|
|
29
|
+
const SAMPLES_PER_SOURCE = 3;
|
|
30
|
+
const SAMPLE_DESCRIPTION_CHARS = 120;
|
|
31
|
+
const TOOL_DESCRIPTION_CHARS = 400;
|
|
32
|
+
const DECLARED_DESCRIPTION_CHARS = 4e3;
|
|
33
|
+
const LOCAL_SOURCE = "local";
|
|
34
|
+
const FUNCTION_NAME = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
35
|
+
function isDeclarable(tool) {
|
|
36
|
+
return FUNCTION_NAME.test(tool.name);
|
|
37
|
+
}
|
|
38
|
+
function needsSearch(allTools) {
|
|
39
|
+
return allTools.filter(isDeclarable).length > FULL_CATALOG_LIMIT;
|
|
40
|
+
}
|
|
41
|
+
function describeTool(tool, chars = TOOL_DESCRIPTION_CHARS) {
|
|
42
|
+
return {
|
|
43
|
+
name: tool.name,
|
|
44
|
+
description: tool.description.slice(0, chars),
|
|
45
|
+
requires_confirmation: tool.destructive,
|
|
46
|
+
parameters: tool.parameters
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function declare(tool) {
|
|
50
|
+
return { name: tool.name, description: tool.description.slice(0, DECLARED_DESCRIPTION_CHARS), parameters: tool.parameters };
|
|
51
|
+
}
|
|
52
|
+
function buildToolCatalog(allTools, nativeTools, discovered) {
|
|
53
|
+
const tools = allTools.filter(isDeclarable);
|
|
54
|
+
if (!needsSearch(allTools)) {
|
|
55
|
+
return {
|
|
56
|
+
tools: [...nativeTools.filter((tool) => tool.name !== import_agent_task.SEARCH_TOOLS), ...tools.map(declare)],
|
|
57
|
+
context: {}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const sources = /* @__PURE__ */ new Map();
|
|
61
|
+
for (const tool of tools) {
|
|
62
|
+
const separator = tool.name.indexOf("__");
|
|
63
|
+
const source = separator > 0 ? tool.name.slice(0, separator) : LOCAL_SOURCE;
|
|
64
|
+
sources.set(source, [...sources.get(source) ?? [], tool]);
|
|
65
|
+
}
|
|
66
|
+
const found = discovered.map((name) => tools.find((tool) => tool.name === name)).filter((tool) => !!tool);
|
|
67
|
+
return {
|
|
68
|
+
tools: [...nativeTools, ...found.map(declare)],
|
|
69
|
+
context: {
|
|
70
|
+
total_tools: tools.length,
|
|
71
|
+
tool_sources: [...sources.entries()].map(([name, items]) => ({
|
|
72
|
+
name,
|
|
73
|
+
tool_count: items.length,
|
|
74
|
+
sample: items.slice(0, SAMPLES_PER_SOURCE).map((tool) => ({ name: tool.name, description: tool.description.slice(0, SAMPLE_DESCRIPTION_CHARS) }))
|
|
75
|
+
}))
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
buildToolCatalog,
|
|
82
|
+
describeTool,
|
|
83
|
+
isDeclarable,
|
|
84
|
+
needsSearch
|
|
85
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import "../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { SEARCH_TOOLS } from "../services/tasks/entities/agent-task.entity.js";
|
|
3
|
+
const FULL_CATALOG_LIMIT = 15;
|
|
4
|
+
const SAMPLES_PER_SOURCE = 3;
|
|
5
|
+
const SAMPLE_DESCRIPTION_CHARS = 120;
|
|
6
|
+
const TOOL_DESCRIPTION_CHARS = 400;
|
|
7
|
+
const DECLARED_DESCRIPTION_CHARS = 4e3;
|
|
8
|
+
const LOCAL_SOURCE = "local";
|
|
9
|
+
const FUNCTION_NAME = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
10
|
+
function isDeclarable(tool) {
|
|
11
|
+
return FUNCTION_NAME.test(tool.name);
|
|
12
|
+
}
|
|
13
|
+
function needsSearch(allTools) {
|
|
14
|
+
return allTools.filter(isDeclarable).length > FULL_CATALOG_LIMIT;
|
|
15
|
+
}
|
|
16
|
+
function describeTool(tool, chars = TOOL_DESCRIPTION_CHARS) {
|
|
17
|
+
return {
|
|
18
|
+
name: tool.name,
|
|
19
|
+
description: tool.description.slice(0, chars),
|
|
20
|
+
requires_confirmation: tool.destructive,
|
|
21
|
+
parameters: tool.parameters
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function declare(tool) {
|
|
25
|
+
return { name: tool.name, description: tool.description.slice(0, DECLARED_DESCRIPTION_CHARS), parameters: tool.parameters };
|
|
26
|
+
}
|
|
27
|
+
function buildToolCatalog(allTools, nativeTools, discovered) {
|
|
28
|
+
const tools = allTools.filter(isDeclarable);
|
|
29
|
+
if (!needsSearch(allTools)) {
|
|
30
|
+
return {
|
|
31
|
+
tools: [...nativeTools.filter((tool) => tool.name !== SEARCH_TOOLS), ...tools.map(declare)],
|
|
32
|
+
context: {}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const sources = /* @__PURE__ */ new Map();
|
|
36
|
+
for (const tool of tools) {
|
|
37
|
+
const separator = tool.name.indexOf("__");
|
|
38
|
+
const source = separator > 0 ? tool.name.slice(0, separator) : LOCAL_SOURCE;
|
|
39
|
+
sources.set(source, [...sources.get(source) ?? [], tool]);
|
|
40
|
+
}
|
|
41
|
+
const found = discovered.map((name) => tools.find((tool) => tool.name === name)).filter((tool) => !!tool);
|
|
42
|
+
return {
|
|
43
|
+
tools: [...nativeTools, ...found.map(declare)],
|
|
44
|
+
context: {
|
|
45
|
+
total_tools: tools.length,
|
|
46
|
+
tool_sources: [...sources.entries()].map(([name, items]) => ({
|
|
47
|
+
name,
|
|
48
|
+
tool_count: items.length,
|
|
49
|
+
sample: items.slice(0, SAMPLES_PER_SOURCE).map((tool) => ({ name: tool.name, description: tool.description.slice(0, SAMPLE_DESCRIPTION_CHARS) }))
|
|
50
|
+
}))
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
buildToolCatalog,
|
|
56
|
+
describeTool,
|
|
57
|
+
isDeclarable,
|
|
58
|
+
needsSearch
|
|
59
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Logger } from '../common/logger/index.js';
|
|
2
|
+
import { Tool, BaseParams } from '../tools/tool.js';
|
|
3
|
+
import { AgentAction } from '../services/tasks/entities/agent-action.entity.js';
|
|
4
|
+
import { AgentTask } from '../services/tasks/entities/agent-task.entity.js';
|
|
5
|
+
import { Workspace } from './workspace';
|
|
6
|
+
import { WeightedKeyword, ScoredTool } from './utils/rank-tools-by-keywords';
|
|
7
|
+
export interface ToolPipelineOptions {
|
|
8
|
+
offloadThresholdChars?: number;
|
|
9
|
+
stubThresholdChars?: number;
|
|
10
|
+
maxStoredChars?: number;
|
|
11
|
+
previewChars?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ToolPipelineRunOptions {
|
|
14
|
+
blockDuplicates?: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface ToolPipelineDeps {
|
|
17
|
+
workspace: Workspace;
|
|
18
|
+
tools: () => Tool[];
|
|
19
|
+
searchTools: (keywords: WeightedKeyword[], opts?: {
|
|
20
|
+
page?: number;
|
|
21
|
+
limit?: number;
|
|
22
|
+
}) => ScoredTool[];
|
|
23
|
+
baseParams: BaseParams;
|
|
24
|
+
logger: Logger;
|
|
25
|
+
}
|
|
26
|
+
export declare class ToolPipeline {
|
|
27
|
+
private readonly deps;
|
|
28
|
+
private readonly offloadThresholdChars;
|
|
29
|
+
private readonly stubThresholdChars;
|
|
30
|
+
private readonly maxStoredChars;
|
|
31
|
+
private readonly previewChars;
|
|
32
|
+
private readonly nativeTools;
|
|
33
|
+
constructor(deps: ToolPipelineDeps, options?: ToolPipelineOptions);
|
|
34
|
+
private notFoundMessage;
|
|
35
|
+
private searchUnavailableMessage;
|
|
36
|
+
requiresApproval(action: AgentAction): boolean;
|
|
37
|
+
run(task: AgentTask, action: AgentAction, opts?: ToolPipelineRunOptions): Promise<AgentAction>;
|
|
38
|
+
private findTool;
|
|
39
|
+
private loadSources;
|
|
40
|
+
private offload;
|
|
41
|
+
}
|
|
42
|
+
export {};
|