@peers-app/peers-device 0.15.5 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connection-manager/connection-manager.js +1 -4
- package/dist/connection-manager/connection-manager.js.map +1 -1
- package/dist/index.d.ts +13 -7
- package/dist/index.js +13 -7
- package/dist/index.js.map +1 -1
- package/dist/main.js +6 -1
- package/dist/main.js.map +1 -1
- package/dist/message-processor.d.ts +9 -0
- package/dist/message-processor.js +102 -0
- package/dist/message-processor.js.map +1 -0
- package/dist/services-client.d.ts +24 -0
- package/dist/services-client.js +121 -0
- package/dist/services-client.js.map +1 -0
- package/dist/services-client.test.d.ts +1 -0
- package/dist/services-client.test.js +167 -0
- package/dist/services-client.test.js.map +1 -0
- package/dist/sync-group.d.ts +10 -0
- package/dist/sync-group.js +94 -48
- package/dist/sync-group.js.map +1 -1
- package/dist/sync-group.test.js +155 -0
- package/dist/sync-group.test.js.map +1 -1
- package/dist/system-tools.d.ts +62 -0
- package/dist/system-tools.js +70 -0
- package/dist/system-tools.js.map +1 -0
- package/dist/tool-call-processor.d.ts +23 -0
- package/dist/tool-call-processor.js +98 -0
- package/dist/tool-call-processor.js.map +1 -0
- package/dist/tool-loader.d.ts +41 -0
- package/dist/tool-loader.js +186 -0
- package/dist/tool-loader.js.map +1 -0
- package/dist/workflow-processor.d.ts +41 -0
- package/dist/workflow-processor.js +411 -0
- package/dist/workflow-processor.js.map +1 -0
- package/dist/workflow-processor.test.d.ts +13 -0
- package/dist/workflow-processor.test.js +326 -0
- package/dist/workflow-processor.test.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.systemToolInstances = exports.systemTools = void 0;
|
|
4
|
+
exports.registerSystemTool = registerSystemTool;
|
|
5
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
|
+
const _systemTools = [];
|
|
7
|
+
const _systemToolFns = {};
|
|
8
|
+
/** Returns a snapshot (shallow copy) of all registered system tools. */
|
|
9
|
+
const systemTools = () => [..._systemTools];
|
|
10
|
+
exports.systemTools = systemTools;
|
|
11
|
+
/** Looks up a registered system tool instance by ID, or `undefined` if not found. */
|
|
12
|
+
const systemToolInstances = (id) => _systemToolFns[id];
|
|
13
|
+
exports.systemToolInstances = systemToolInstances;
|
|
14
|
+
/**
|
|
15
|
+
* Registers a built-in ("system") tool so it can be resolved by
|
|
16
|
+
* {@link systemToolInstances} without loading code from disk.
|
|
17
|
+
*
|
|
18
|
+
* Call this at module-load time for each system tool the host application
|
|
19
|
+
* ships. The tool's `code` field is auto-populated with a placeholder so
|
|
20
|
+
* that the UI can still display something meaningful.
|
|
21
|
+
*
|
|
22
|
+
* @param tool - Partial tool definition; `toolId` is required.
|
|
23
|
+
* @param toolFnOrInstance - Either a bare function (becomes `toolFn`) or a
|
|
24
|
+
* partial `IToolInstance` (may include a custom `inputSchema`).
|
|
25
|
+
*/
|
|
26
|
+
function registerSystemTool(tool, toolFnOrInstance) {
|
|
27
|
+
if (!tool.toolId) {
|
|
28
|
+
throw new Error("Tool must have a toolId");
|
|
29
|
+
}
|
|
30
|
+
const _tool = {
|
|
31
|
+
toolId: "",
|
|
32
|
+
name: `unnamed-tool`,
|
|
33
|
+
usageDescription: `default usage description`,
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: peers_sdk_1.IOSchemaType.simple,
|
|
36
|
+
fields: [{ name: "input", description: "the tool input", type: peers_sdk_1.FieldType.string }],
|
|
37
|
+
},
|
|
38
|
+
outputSchema: {
|
|
39
|
+
type: peers_sdk_1.IOSchemaType.simple,
|
|
40
|
+
fields: [],
|
|
41
|
+
},
|
|
42
|
+
code: "",
|
|
43
|
+
...tool,
|
|
44
|
+
};
|
|
45
|
+
_tool.code = "// This is a system tool. Editing the code will have no effect.\n\n";
|
|
46
|
+
_systemTools.push(_tool);
|
|
47
|
+
let toolInstance;
|
|
48
|
+
if (typeof toolFnOrInstance === "function") {
|
|
49
|
+
_tool.code += `module.exports = ${toolFnOrInstance.toString()}`;
|
|
50
|
+
toolInstance = {
|
|
51
|
+
tool: _tool,
|
|
52
|
+
toolFn: toolFnOrInstance,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
_tool.code += `module.exports = ${toolFnOrInstance.toolFn.toString()}`;
|
|
57
|
+
toolInstance = {
|
|
58
|
+
...toolFnOrInstance,
|
|
59
|
+
tool: _tool,
|
|
60
|
+
};
|
|
61
|
+
if (toolFnOrInstance.inputSchema) {
|
|
62
|
+
_tool.inputSchema = {
|
|
63
|
+
type: peers_sdk_1.IOSchemaType.complex,
|
|
64
|
+
fields: (0, peers_sdk_1.schemaToFields)(toolFnOrInstance.inputSchema),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
_systemToolFns[tool.toolId] = toolInstance;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=system-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-tools.js","sourceRoot":"","sources":["../src/system-tools.ts"],"names":[],"mappings":";;;AA6BA,gDA+CC;AA5ED,oDAM8B;AAE9B,MAAM,YAAY,GAAY,EAAE,CAAC;AACjC,MAAM,cAAc,GAAkC,EAAE,CAAC;AAEzD,wEAAwE;AACjE,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC;AAAtC,QAAA,WAAW,eAA2B;AAEnD,qFAAqF;AAC9E,MAAM,mBAAmB,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;AAAzD,QAAA,mBAAmB,uBAAsC;AAEtE;;;;;;;;;;;GAWG;AACH,SAAgB,kBAAkB,CAChC,IAAoB,EACpB,gBAAyE;IAEzE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACjB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MAAM,CAAC,GAAG,YAAY,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type DataContext } from "@peers-app/peers-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Runs a tool directly as a one-off WorkflowRun, using the same execution path
|
|
4
|
+
* as message-triggered tools (initWrappedTool, full IWorkflowRunContext, etc).
|
|
5
|
+
*
|
|
6
|
+
* Uses userContext.subscribeToDataChangedAcrossAllGroups for completion detection
|
|
7
|
+
* so that we catch the update regardless of which context the workflow-processor
|
|
8
|
+
* writes to (it internally uses WorkflowRuns() which resolves to the default context).
|
|
9
|
+
*
|
|
10
|
+
* The WorkflowRun is inserted BEFORE the synthetic message so that message-processor.ts
|
|
11
|
+
* finds the existing run on its async check and bails out -- no race condition.
|
|
12
|
+
*
|
|
13
|
+
* @param toolId - ID of the tool to execute.
|
|
14
|
+
* @param args - Input arguments keyed by field name (read by `gatherArgs` in
|
|
15
|
+
* workflow-processor via `workflowRun.vars`).
|
|
16
|
+
* @param dataContext - Data context to insert the run and message into.
|
|
17
|
+
* @param options - Optional assistant ID and display name overrides.
|
|
18
|
+
* @returns The last entry in `instructionResults` when the run completes.
|
|
19
|
+
*/
|
|
20
|
+
export declare function runToolDirectly(toolId: string, args: Record<string, any>, dataContext: DataContext, options?: {
|
|
21
|
+
assistantId?: string;
|
|
22
|
+
toolName?: string;
|
|
23
|
+
}): Promise<any>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runToolDirectly = runToolDirectly;
|
|
4
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
5
|
+
/**
|
|
6
|
+
* Formats tool arguments into a compact human-readable string for display
|
|
7
|
+
* in the synthetic message created alongside a direct tool run.
|
|
8
|
+
*/
|
|
9
|
+
function formatArgs(args) {
|
|
10
|
+
const parts = Object.entries(args)
|
|
11
|
+
.filter(([, v]) => v !== undefined && v !== null && v !== "")
|
|
12
|
+
.map(([k, v]) => {
|
|
13
|
+
if (typeof v === "string") {
|
|
14
|
+
const s = v.length > 24 ? `${v.slice(0, 24)}…` : v;
|
|
15
|
+
return `\`${k}="${s}"\``;
|
|
16
|
+
}
|
|
17
|
+
if (typeof v === "number" || typeof v === "boolean")
|
|
18
|
+
return `\`${k}=${v}\``;
|
|
19
|
+
if (Array.isArray(v))
|
|
20
|
+
return `\`${k}=[…]\``;
|
|
21
|
+
if (typeof v === "object")
|
|
22
|
+
return `\`${k}={…}\``;
|
|
23
|
+
return `\`${k}=${v}\``;
|
|
24
|
+
});
|
|
25
|
+
return parts.length ? ` ${parts.join(", ")}` : "";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Runs a tool directly as a one-off WorkflowRun, using the same execution path
|
|
29
|
+
* as message-triggered tools (initWrappedTool, full IWorkflowRunContext, etc).
|
|
30
|
+
*
|
|
31
|
+
* Uses userContext.subscribeToDataChangedAcrossAllGroups for completion detection
|
|
32
|
+
* so that we catch the update regardless of which context the workflow-processor
|
|
33
|
+
* writes to (it internally uses WorkflowRuns() which resolves to the default context).
|
|
34
|
+
*
|
|
35
|
+
* The WorkflowRun is inserted BEFORE the synthetic message so that message-processor.ts
|
|
36
|
+
* finds the existing run on its async check and bails out -- no race condition.
|
|
37
|
+
*
|
|
38
|
+
* @param toolId - ID of the tool to execute.
|
|
39
|
+
* @param args - Input arguments keyed by field name (read by `gatherArgs` in
|
|
40
|
+
* workflow-processor via `workflowRun.vars`).
|
|
41
|
+
* @param dataContext - Data context to insert the run and message into.
|
|
42
|
+
* @param options - Optional assistant ID and display name overrides.
|
|
43
|
+
* @returns The last entry in `instructionResults` when the run completes.
|
|
44
|
+
*/
|
|
45
|
+
async function runToolDirectly(toolId, args, dataContext, options) {
|
|
46
|
+
const me = await (0, peers_sdk_1.getMe)();
|
|
47
|
+
const userContext = await (0, peers_sdk_1.getUserContext)();
|
|
48
|
+
const assistantId = options?.assistantId ||
|
|
49
|
+
(await (0, peers_sdk_1.getPrimaryAssistant)(dataContext)).assistantId ||
|
|
50
|
+
peers_sdk_1.defaultAssistantId;
|
|
51
|
+
const workflowRunId = (0, peers_sdk_1.newid)();
|
|
52
|
+
const messageId = (0, peers_sdk_1.newid)();
|
|
53
|
+
const completionPromise = new Promise((resolve, reject) => {
|
|
54
|
+
const sub = userContext.subscribeToDataChangedAcrossAllGroups((0, peers_sdk_1.WorkflowRuns)(), (evt) => {
|
|
55
|
+
const run = evt.data.dataObject;
|
|
56
|
+
if (run.workflowRunId !== workflowRunId)
|
|
57
|
+
return;
|
|
58
|
+
if (!run.completedAt && !run.inErrorState)
|
|
59
|
+
return;
|
|
60
|
+
sub.unsubscribe();
|
|
61
|
+
if (run.inErrorState) {
|
|
62
|
+
const errMsg = run.instructionResults.length
|
|
63
|
+
? String(run.instructionResults[run.instructionResults.length - 1])
|
|
64
|
+
: "Tool run failed";
|
|
65
|
+
reject(new Error(errMsg));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
resolve(run.instructionResults[run.instructionResults.length - 1]);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
await (0, peers_sdk_1.WorkflowRuns)(dataContext).insert({
|
|
73
|
+
workflowRunId,
|
|
74
|
+
parentMessageId: messageId,
|
|
75
|
+
defaultAssistantId: assistantId,
|
|
76
|
+
createdAt: new Date(),
|
|
77
|
+
vars: args,
|
|
78
|
+
instructionResults: [],
|
|
79
|
+
instructions: [{ directCallToolId: toolId }],
|
|
80
|
+
currentInstructionIndex: 0,
|
|
81
|
+
});
|
|
82
|
+
const channelId = dataContext.groupId ?? me.userId;
|
|
83
|
+
const toolMention = (0, peers_sdk_1.formatMention)({
|
|
84
|
+
kind: "tool",
|
|
85
|
+
name: options?.toolName ?? toolId,
|
|
86
|
+
id: toolId,
|
|
87
|
+
});
|
|
88
|
+
const message = `[tool-call] ${toolMention}${formatArgs(args)}`;
|
|
89
|
+
await (0, peers_sdk_1.Messages)(dataContext).insert({
|
|
90
|
+
messageId,
|
|
91
|
+
channelId,
|
|
92
|
+
userId: me.userId,
|
|
93
|
+
message,
|
|
94
|
+
createdAt: new Date(),
|
|
95
|
+
});
|
|
96
|
+
return completionPromise;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=tool-call-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-call-processor.js","sourceRoot":"","sources":["../src/tool-call-processor.ts"],"names":[],"mappings":";;AAmDA,0CA4DC;AA/GD,oDAW8B;AAE9B;;;GAGG;AACH,SAAS,UAAU,CAAC,IAAyB;IAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;SAC/B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;SAC5D,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;QACd,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;YAC1B,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACnD,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;QAC3B,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5E,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC,QAAQ,CAAC;QAC5C,IAAI,OAAO,CAAC,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC,QAAQ,CAAC;QACjD,O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ITool, type IToolInstance, type IWorkflowRunContext } from "@peers-app/peers-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Injects the function that returns the root application data directory
|
|
4
|
+
* (where tool code is cached on disk). Must be called once during app
|
|
5
|
+
* initialisation before any tool is loaded via {@link initTool}.
|
|
6
|
+
*/
|
|
7
|
+
export declare function setPeersAppDir(fn: () => string): void;
|
|
8
|
+
/**
|
|
9
|
+
* Derives a unique filesystem-safe identifier for a tool, combining its
|
|
10
|
+
* human-readable name with the last 5 characters of its ID.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getToolUniqueIdentifier(tool: ITool): string;
|
|
13
|
+
/**
|
|
14
|
+
* Resolves an {@link ITool} definition into a runnable {@link IToolInstance}.
|
|
15
|
+
*
|
|
16
|
+
* Resolution order:
|
|
17
|
+
* 1. System-tool registry ({@link systemToolInstances})
|
|
18
|
+
* 2. Package-registered tool factory (`getRegisteredTool` from peers-sdk)
|
|
19
|
+
* 3. Write the tool's `code` to disk, `require()` it, and cache the result
|
|
20
|
+
*
|
|
21
|
+
* @param tool - The tool definition to initialise.
|
|
22
|
+
* @param opts - Pass `{ refresh: true }` to force a reload even when the
|
|
23
|
+
* code hash has not changed.
|
|
24
|
+
*/
|
|
25
|
+
export declare function initTool(tool: ITool, opts?: {
|
|
26
|
+
refresh: boolean;
|
|
27
|
+
}): Promise<IToolInstance>;
|
|
28
|
+
/**
|
|
29
|
+
* Loads a tool via {@link initTool} and wraps its `toolFn` so that every
|
|
30
|
+
* invocation is automatically logged to the {@link WorkflowLogs} table
|
|
31
|
+
* with timing, arguments, result, and error state.
|
|
32
|
+
*
|
|
33
|
+
* @param tool - The tool definition.
|
|
34
|
+
* @param context - The current workflow-run context (provides the logger).
|
|
35
|
+
*/
|
|
36
|
+
export declare function initWrappedTool(tool: ITool, context: IWorkflowRunContext): Promise<IToolInstance>;
|
|
37
|
+
/**
|
|
38
|
+
* Parses tool mention markup (`<$tool:name:id>`) out of a markdown string
|
|
39
|
+
* and returns the corresponding {@link ITool} records.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getLinkedTools(markdown: string): Promise<ITool[]>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setPeersAppDir = setPeersAppDir;
|
|
7
|
+
exports.getToolUniqueIdentifier = getToolUniqueIdentifier;
|
|
8
|
+
exports.initTool = initTool;
|
|
9
|
+
exports.initWrappedTool = initWrappedTool;
|
|
10
|
+
exports.getLinkedTools = getLinkedTools;
|
|
11
|
+
const node_crypto_1 = require("node:crypto");
|
|
12
|
+
const promises_1 = require("node:fs/promises");
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
15
|
+
const lodash_1 = require("lodash");
|
|
16
|
+
const system_tools_1 = require("./system-tools");
|
|
17
|
+
let _getPeersAppDir;
|
|
18
|
+
/**
|
|
19
|
+
* Injects the function that returns the root application data directory
|
|
20
|
+
* (where tool code is cached on disk). Must be called once during app
|
|
21
|
+
* initialisation before any tool is loaded via {@link initTool}.
|
|
22
|
+
*/
|
|
23
|
+
function setPeersAppDir(fn) {
|
|
24
|
+
_getPeersAppDir = fn;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Derives a unique filesystem-safe identifier for a tool, combining its
|
|
28
|
+
* human-readable name with the last 5 characters of its ID.
|
|
29
|
+
*/
|
|
30
|
+
function getToolUniqueIdentifier(tool) {
|
|
31
|
+
// TODO there is probably a better way to solve name collisions
|
|
32
|
+
return `${tool.name}_${tool.toolId.slice(20)}`;
|
|
33
|
+
}
|
|
34
|
+
const toolCodeCache = {};
|
|
35
|
+
const toolCodeCacheSha = {};
|
|
36
|
+
/**
|
|
37
|
+
* Resolves an {@link ITool} definition into a runnable {@link IToolInstance}.
|
|
38
|
+
*
|
|
39
|
+
* Resolution order:
|
|
40
|
+
* 1. System-tool registry ({@link systemToolInstances})
|
|
41
|
+
* 2. Package-registered tool factory (`getRegisteredTool` from peers-sdk)
|
|
42
|
+
* 3. Write the tool's `code` to disk, `require()` it, and cache the result
|
|
43
|
+
*
|
|
44
|
+
* @param tool - The tool definition to initialise.
|
|
45
|
+
* @param opts - Pass `{ refresh: true }` to force a reload even when the
|
|
46
|
+
* code hash has not changed.
|
|
47
|
+
*/
|
|
48
|
+
async function initTool(tool, opts = { refresh: false }) {
|
|
49
|
+
const sysToolInstance = (0, system_tools_1.systemToolInstances)(tool.toolId);
|
|
50
|
+
if (sysToolInstance) {
|
|
51
|
+
return sysToolInstance;
|
|
52
|
+
}
|
|
53
|
+
const registeredToolInstance = (0, peers_sdk_1.getRegisteredTool)(tool.toolId);
|
|
54
|
+
if (registeredToolInstance) {
|
|
55
|
+
return registeredToolInstance;
|
|
56
|
+
}
|
|
57
|
+
const toolUID = getToolUniqueIdentifier(tool);
|
|
58
|
+
const codeHash = (0, node_crypto_1.createHash)("sha256").update(tool.code).digest("hex");
|
|
59
|
+
const refresh = opts.refresh || toolCodeCacheSha[toolUID] !== codeHash;
|
|
60
|
+
if (toolCodeCache[toolUID] && !refresh) {
|
|
61
|
+
return toolCodeCache[toolUID];
|
|
62
|
+
}
|
|
63
|
+
delete toolCodeCache[toolUID];
|
|
64
|
+
delete toolCodeCacheSha[toolUID];
|
|
65
|
+
if (!_getPeersAppDir) {
|
|
66
|
+
throw new Error("setPeersAppDir must be called before initTool");
|
|
67
|
+
}
|
|
68
|
+
const rootDir = _getPeersAppDir();
|
|
69
|
+
const toolDir = node_path_1.default.join(rootDir, "tools", toolUID);
|
|
70
|
+
const cacheKeys = Object.keys(require.cache);
|
|
71
|
+
for (const cacheKey of cacheKeys) {
|
|
72
|
+
const requireCache = require.cache[cacheKey];
|
|
73
|
+
const cachePath = requireCache?.path;
|
|
74
|
+
if (cachePath) {
|
|
75
|
+
if (cachePath.toLowerCase().startsWith(toolDir.toLowerCase())) {
|
|
76
|
+
delete require.cache[cacheKey];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
await (0, promises_1.mkdir)(toolDir, { recursive: true });
|
|
81
|
+
const toolFilePath = node_path_1.default.join(toolDir, "index.js");
|
|
82
|
+
let toolCode = tool.code;
|
|
83
|
+
toolCode = toolCode.trim();
|
|
84
|
+
if (toolCode.startsWith("```") && toolCode.endsWith("```")) {
|
|
85
|
+
toolCode = toolCode.slice(3, -3);
|
|
86
|
+
}
|
|
87
|
+
await (0, promises_1.writeFile)(toolFilePath, toolCode);
|
|
88
|
+
let toolModule = require(toolFilePath);
|
|
89
|
+
let toolInstance = {
|
|
90
|
+
tool,
|
|
91
|
+
toolFn: (...args) => "Error: toolFn was not set",
|
|
92
|
+
};
|
|
93
|
+
if (toolModule.default) {
|
|
94
|
+
toolInstance = {
|
|
95
|
+
...toolInstance,
|
|
96
|
+
...toolModule,
|
|
97
|
+
};
|
|
98
|
+
toolModule = toolModule.default;
|
|
99
|
+
}
|
|
100
|
+
if (typeof toolModule === "function") {
|
|
101
|
+
toolInstance.toolFn = toolModule;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
toolInstance = {
|
|
105
|
+
...toolInstance,
|
|
106
|
+
toolFn: () => `Error: the module built from the tool code did not return a tool function. The module should export a function named "toolFn" or make the default export a function.`,
|
|
107
|
+
...toolModule,
|
|
108
|
+
tool,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
toolCodeCacheSha[toolUID] = codeHash;
|
|
112
|
+
toolCodeCache[toolUID] = toolInstance;
|
|
113
|
+
return toolCodeCache[toolUID];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Loads a tool via {@link initTool} and wraps its `toolFn` so that every
|
|
117
|
+
* invocation is automatically logged to the {@link WorkflowLogs} table
|
|
118
|
+
* with timing, arguments, result, and error state.
|
|
119
|
+
*
|
|
120
|
+
* @param tool - The tool definition.
|
|
121
|
+
* @param context - The current workflow-run context (provides the logger).
|
|
122
|
+
*/
|
|
123
|
+
async function initWrappedTool(tool, context) {
|
|
124
|
+
const { logger } = context;
|
|
125
|
+
let toolInstance = {
|
|
126
|
+
toolFn: (...args) => "toolFn placeholder",
|
|
127
|
+
tool,
|
|
128
|
+
};
|
|
129
|
+
try {
|
|
130
|
+
toolInstance = await initTool(tool);
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
toolInstance.toolFn = () => `Error loading tool: ${tool.name}\n${err}\n\nTell the user there is an error with the tool that needs to be fixed before it can be loaded.`;
|
|
134
|
+
logger(`Error loading tool: ${tool.name}: ${String(err)}`);
|
|
135
|
+
}
|
|
136
|
+
const wrappedToolInstance = {
|
|
137
|
+
...toolInstance,
|
|
138
|
+
toolFn: async (args) => {
|
|
139
|
+
const logEntry = await logger({
|
|
140
|
+
toolId: tool.toolId,
|
|
141
|
+
toolArgs: args,
|
|
142
|
+
});
|
|
143
|
+
let result;
|
|
144
|
+
let isResultError = false;
|
|
145
|
+
const startTime = Date.now();
|
|
146
|
+
try {
|
|
147
|
+
const toolFn = toolInstance.toolFn ?? (() => "Error: toolFn was not set, check the tool code");
|
|
148
|
+
result = await toolFn(args, context);
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
isResultError = true;
|
|
152
|
+
result = `Error in tool: \`${tool.name}\`: ${err}`;
|
|
153
|
+
}
|
|
154
|
+
logEntry.isError = isResultError;
|
|
155
|
+
if ((0, lodash_1.isObject)(result)) {
|
|
156
|
+
logEntry.result = JSON.stringify(result, null, 2);
|
|
157
|
+
logEntry.resultObject = result;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
logEntry.result = String(result);
|
|
161
|
+
}
|
|
162
|
+
logEntry.toolRunTimeMs = Date.now() - startTime;
|
|
163
|
+
await (0, peers_sdk_1.WorkflowLogs)().update(logEntry);
|
|
164
|
+
return result;
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
return wrappedToolInstance;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Parses tool mention markup (`<$tool:name:id>`) out of a markdown string
|
|
171
|
+
* and returns the corresponding {@link ITool} records.
|
|
172
|
+
*/
|
|
173
|
+
async function getLinkedTools(markdown) {
|
|
174
|
+
const matchedToolIds = markdown.match(/<\$tool:([a-zA-Z0-9_-]+):[a-zA-Z0-9]{25}>/g);
|
|
175
|
+
if (!matchedToolIds) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
const toolIds = matchedToolIds.map((id) => {
|
|
179
|
+
return id.split(":")[2].slice(0, -1);
|
|
180
|
+
});
|
|
181
|
+
const fixedTools = await (0, peers_sdk_1.Tools)().list({
|
|
182
|
+
toolId: { $in: toolIds },
|
|
183
|
+
});
|
|
184
|
+
return fixedTools;
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=tool-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-loader.js","sourceRoot":"","sources":["../src/tool-loader.ts"],"names":[],"mappings":";;;;;AAsBA,wCAEC;AAMD,0DAGC;AAiBD,4BA2EC;AAUD,0CAgDC;AAMD,wCAaC;AA1MD,6CAAyC;AACzC,+CAAoD;AACpD,0DAA6B;AAC7B,oDAQ8B;AAC9B,mCAAkC;AAClC,iDAAqD;AAErD,IAAI,eAA2C,CAAC;AAEhD;;;;GAIG;AACH,SAAgB,cAAc,CAAC,EAAgB;IAC7C,eAAe,GAAG,EAAE,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,SAAgB,uBAAuB,CAAC,IAAW;IACjD,+DAA+D;IAC/D,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;AACjD,CAAC;AAED,MAAM,aAAa,GAAkC,EAAE,CAAC;AACxD,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C,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,MAAM,IAAA,iBAAK,GAAE,CAAC,IAAI,CAAC;QACpC,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE;KACzB,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type DataContext, type ITool, type IWorkflowRunContext, type UserContext } from "@peers-app/peers-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Injects the decryption function used by {@link getVariable} when a
|
|
4
|
+
* persistent variable is marked as a secret. Must be called once during
|
|
5
|
+
* app initialisation before any workflow or tool accesses secret variables.
|
|
6
|
+
*/
|
|
7
|
+
export declare function setDecryptData(fn: (value: string, groupId: string) => Promise<any>): void;
|
|
8
|
+
/**
|
|
9
|
+
* Injects the function that returns the current user's home directory.
|
|
10
|
+
* Used as the default `currentWorkingDirectory` for new workflow runs.
|
|
11
|
+
* Must be called once during app initialisation.
|
|
12
|
+
*/
|
|
13
|
+
export declare function setUserHomeDirectory(fn: () => string): void;
|
|
14
|
+
type SimilarToolsFn = (args: {
|
|
15
|
+
context: IWorkflowRunContext;
|
|
16
|
+
text: string;
|
|
17
|
+
similarityThreshold?: number;
|
|
18
|
+
maxCount?: number;
|
|
19
|
+
}) => Promise<ITool[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Injects the embedding-based tool similarity function used when an
|
|
22
|
+
* assistant's {@link ToolInclusionStrategy} is `Relevant`. This is
|
|
23
|
+
* optional -- when unset, the "Relevant" strategy simply skips the
|
|
24
|
+
* similarity search.
|
|
25
|
+
*/
|
|
26
|
+
export declare function setSimilarToolsFn(fn: SimilarToolsFn): void;
|
|
27
|
+
/**
|
|
28
|
+
* Sets up the WorkflowRuns change subscription and the 60-second polling
|
|
29
|
+
* interval. Pass a `UserContext` directly (e.g. in tests) or omit it to
|
|
30
|
+
* fall back to `getUserContext()`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function initializeWorkflowProcessor(userContext?: UserContext): void;
|
|
33
|
+
/** Scans for incomplete workflow runs and schedules them for processing. */
|
|
34
|
+
export declare function checkForWorkflowsToProcess(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Attempts to process the next instruction for a workflow run. Applies
|
|
37
|
+
* CPU-based throttling, schedule gating, sub-workflow checks, and an
|
|
38
|
+
* in-process per-run lock before delegating to {@link processNextInstruction}.
|
|
39
|
+
*/
|
|
40
|
+
export declare function tryProcessingWorkflowRun(dataContext: DataContext, workflowRunId: string): Promise<void>;
|
|
41
|
+
export {};
|