@peers-app/peers-device 0.15.4 → 0.16.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/connection-manager/connection-manager.js +1 -4
- package/dist/connection-manager/connection-manager.js.map +1 -1
- package/dist/index.d.ts +12 -7
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/dist/json-diff.d.ts +16 -0
- package/dist/json-diff.js +17 -55
- package/dist/json-diff.js.map +1 -1
- package/dist/machine-stats.d.ts +6 -0
- package/dist/machine-stats.js +6 -0
- package/dist/machine-stats.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/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,41 @@
|
|
|
1
|
+
import { type 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,MAAM,gBAAgB,GAA2B,EAAE,CAAC;AAEpD;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,QAAQ,CAAC,IAAW,EAAE,IAAI,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE;IACnE,MAAM,eAAe,GAAG,IAAA,kCAAmB,EAAC,IAAI,CAAC,MAAM,CAAC,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E,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 {};
|