@matatbread/matbot-triggers 0.2.3 → 0.2.5
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 +13 -30
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"node",
|
|
5
5
|
"browser"
|
|
6
6
|
],
|
|
7
|
-
"version": "0.2.
|
|
7
|
+
"version": "0.2.5",
|
|
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.2.
|
|
36
|
+
"@matatbread/matbot-plugin-api": "^0.2.5"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"typescript": "^5.8.0",
|
|
40
|
-
"@matatbread/matbot-plugin-api": "^0.2.
|
|
40
|
+
"@matatbread/matbot-plugin-api": "^0.2.5"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"typecheck": "tsc --noEmit"
|
package/src/dispatch.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import type { MatbotMachine, Session,
|
|
1
|
+
import type { MatbotMachine, Session, PromptFn, MessageContent } from '@matatbread/matbot-plugin-api';
|
|
2
|
+
import { invokeTool } from '@matatbread/matbot-plugin-api';
|
|
2
3
|
import type { Trigger } from './types.js';
|
|
3
4
|
|
|
4
|
-
// Fallback when the firing hook carries no interactive prompt (cron/background run, or a frontend
|
|
5
|
-
// that supplied none): a tool that tries to prompt resolves to a rejection it surfaces as a normal
|
|
6
|
-
// tool error. When the hook DOES carry a prompt (a live interactive session behind this turn), it is
|
|
7
|
-
// forwarded instead, so a trigger can invoke an interactive tool (e.g. `ask_user`) for real.
|
|
8
|
-
const rejectingPrompt: PromptFn = (((p: string | FormField): Promise<string> => {
|
|
9
|
-
const label = typeof p === 'string' ? p : p.label;
|
|
10
|
-
return Promise.reject(new Error(`Non-interactive context: cannot prompt for "${label}"`));
|
|
11
|
-
}) as PromptFn);
|
|
12
|
-
|
|
13
5
|
export interface DispatchOutcome {
|
|
14
6
|
/** Whether the tool yielded a result — i.e. whether the model should be woken with it (inject). */
|
|
15
7
|
hadResult: boolean;
|
|
@@ -44,32 +36,23 @@ export async function dispatchTrigger(
|
|
|
44
36
|
// and the worst case is "this trigger did nothing and left a trace"; sibling triggers, the hook,
|
|
45
37
|
// and the session are unaffected. (The hook dispatcher's own try/catch is a second layer behind this.)
|
|
46
38
|
try {
|
|
47
|
-
|
|
48
|
-
if (tool === null) {
|
|
39
|
+
if (services.tools.resolve(trigger.invoke.tool) === null) {
|
|
49
40
|
console.warn(`[triggers] trigger ${trigger.id} invokes unknown tool "${trigger.invoke.tool}"; skipped.`);
|
|
50
41
|
fail(`tool "${trigger.invoke.tool}" not registered`);
|
|
51
42
|
return { hadResult: false, result: undefined, markers };
|
|
52
43
|
}
|
|
53
44
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// DRTX case — an agent reply triggers `plugin(load …)`) is interactive end-to-end, not just at
|
|
64
|
-
// the tool's own ctx.prompt calls.
|
|
65
|
-
loadPlugin: (specifier: string) => services.loadPlugin(specifier, ctx.prompt ?? rejectingPrompt),
|
|
66
|
-
unloadPlugin: (specifier: string) => services.unloadPlugin(specifier),
|
|
67
|
-
...(services.workdir !== undefined ? { workdir: services.workdir } : {}),
|
|
68
|
-
...(services.configPath !== undefined ? { configPath: services.configPath } : {}),
|
|
69
|
-
...(services.files !== undefined ? { files: services.files } : {}),
|
|
70
|
-
};
|
|
45
|
+
// The prompt (when the firing hook carries one — a live interactive session behind this turn) is
|
|
46
|
+
// forwarded so a trigger can invoke an interactive tool (e.g. `ask_user`) for real; absent, the
|
|
47
|
+
// tool runs non-interactively and a prompt attempt surfaces as a normal tool error.
|
|
48
|
+
const events = invokeTool(services, trigger.invoke.tool, trigger.invoke.params, {
|
|
49
|
+
session: ctx.session,
|
|
50
|
+
signal: ctx.signal,
|
|
51
|
+
provider: ctx.provider,
|
|
52
|
+
...(ctx.prompt !== undefined ? { prompt: ctx.prompt } : {}),
|
|
53
|
+
});
|
|
71
54
|
|
|
72
|
-
for await (const ev of
|
|
55
|
+
for await (const ev of events) {
|
|
73
56
|
if (ev.type === 'result') { result = ev.value; hadResult = true; }
|
|
74
57
|
else if (ev.type === 'marker') { markers.push({ type: 'marker', creator: ev.creator, data: ev.data }); }
|
|
75
58
|
else if (ev.type === 'error') {
|