@matatbread/matbot-triggers 0.4.18 → 0.4.21
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/package.json +3 -3
- package/src/dispatch.ts +7 -13
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"node",
|
|
5
5
|
"browser"
|
|
6
6
|
],
|
|
7
|
-
"version": "0.4.
|
|
7
|
+
"version": "0.4.21",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=24.0.0"
|
|
10
10
|
},
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@matatbread/matbot-plugin-api": "^0.4.
|
|
36
|
+
"@matatbread/matbot-plugin-api": "^0.4.21"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"typescript": "^6.0.3",
|
|
40
|
-
"@matatbread/matbot-plugin-api": "^0.4.
|
|
40
|
+
"@matatbread/matbot-plugin-api": "^0.4.21"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"typecheck": "tsc --noEmit"
|
package/src/dispatch.ts
CHANGED
|
@@ -27,23 +27,17 @@ export function invocationParams(invoke: TriggerInvoke): unknown {
|
|
|
27
27
|
return invoke.params ?? {};
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
// core declares `ToolCallValidator` on MatbotServices, and triggers does not depend on core, so the key
|
|
31
|
-
// is read structurally. Same shape as core's `ToolInputValidator`.
|
|
32
|
-
interface InvocationValidator {
|
|
33
|
-
validateToolCall(tool: string, parameters: unknown): Promise<{ path: string; message: string }[] | undefined>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
30
|
/**
|
|
37
|
-
* Check an invocation against the tool's declared input BEFORE it is stored, with the same
|
|
38
|
-
* executor applies when the trigger fires — so a trigger that could never run is
|
|
39
|
-
* is present to fix it, rather than failing silently on some later turn. Returns
|
|
40
|
-
* or `undefined` to accept. A tool that is not registered, or no validator, is
|
|
41
|
-
* naming an absent tool fails soft by design, and nothing here can check what nothing
|
|
31
|
+
* Check an invocation against the tool's declared input BEFORE it is stored, with the same validators the
|
|
32
|
+
* executor applies when the trigger fires (`tools.validate`) — so a trigger that could never run is
|
|
33
|
+
* refused while its author is present to fix it, rather than failing silently on some later turn. Returns
|
|
34
|
+
* the rejection as text, or `undefined` to accept. A tool that is not registered, or no validator, is
|
|
35
|
+
* accepted: a trigger naming an absent tool fails soft by design, and nothing here can check what nothing
|
|
36
|
+
* declares.
|
|
42
37
|
*/
|
|
43
38
|
export async function checkInvocation(services: MatbotMachine, invoke: TriggerInvoke): Promise<string | undefined> {
|
|
44
39
|
if (services.tools.resolve(invoke.tool) === null) return undefined;
|
|
45
|
-
const
|
|
46
|
-
const errs = await validator?.validateToolCall(invoke.tool, invocationParams(invoke));
|
|
40
|
+
const errs = await services.tools.validate?.(invoke.tool, invocationParams(invoke));
|
|
47
41
|
if (errs === undefined || errs.length === 0) return undefined;
|
|
48
42
|
return `params do not match tool "${invoke.tool}": ${errs.map(e => `${e.path}: ${e.message}`).join('; ')}`;
|
|
49
43
|
}
|