@matatbread/matbot-triggers 0.2.9 → 0.3.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/package.json +3 -3
- package/src/tools.ts +41 -42
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"node",
|
|
5
5
|
"browser"
|
|
6
6
|
],
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.3.1",
|
|
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.
|
|
36
|
+
"@matatbread/matbot-plugin-api": "^0.3.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"typescript": "^6.0.3",
|
|
40
|
-
"@matatbread/matbot-plugin-api": "^0.
|
|
40
|
+
"@matatbread/matbot-plugin-api": "^0.3.1"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"typecheck": "tsc --noEmit"
|
package/src/tools.ts
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import type { Tool, ToolExecutor,
|
|
1
|
+
import type { Tool, ToolExecutor, ToolContract, ToolResultOf, ToolContext, MatbotMachine } from '@matatbread/matbot-plugin-api';
|
|
2
2
|
import type { TriggerManager } from './manager.js';
|
|
3
3
|
import type { TriggerCondition, TriggerKind, Trigger } from './types.js';
|
|
4
4
|
|
|
5
5
|
declare module '@matatbread/matbot-plugin-api' {
|
|
6
|
-
interface
|
|
6
|
+
interface ToolContracts {
|
|
7
7
|
// One arm per action: a caller of `invokeTool(machine, 'trigger_action', { action: '…' })` gets the
|
|
8
|
-
// matching result narrowed by the `action` it passed (see
|
|
8
|
+
// matching result narrowed by the `action` it passed (see ToolContract / the multi-action note on ToolContracts).
|
|
9
9
|
trigger_action:
|
|
10
|
-
|
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
|
|
|
10
|
+
| ToolContract<{ triggers: Trigger[] }, { action: 'list' }>
|
|
11
|
+
| ToolContract<{ triggers: Trigger[] }, { action: 'query'; tool?: string; params?: object }>
|
|
12
|
+
| ToolContract<Trigger, { action: 'get'; id: string }>
|
|
13
|
+
| ToolContract<{ id: string }, { action: 'add'; conditions: TriggerCondition[]; tool: string; params?: object; enabled?: boolean }>
|
|
14
|
+
| ToolContract<Trigger, { action: 'update'; id: string; conditions?: TriggerCondition[]; tool?: string; params?: object; enabled?: boolean }>
|
|
15
|
+
| ToolContract<Trigger, { action: 'disable'; id: string }>
|
|
16
|
+
| ToolContract<Trigger, { action: 'enable'; id: string }>
|
|
17
|
+
| ToolContract<{ id: string }, { action: 'remove'; id: string }>
|
|
18
|
+
| ToolContract<{ triggers: Trigger[] }, { action: 'move'; tool?: string; params?: object; toTool: string; toParams?: object }>
|
|
19
|
+
| ToolContract<{ triggers: Trigger[] }, { action: 'copy'; tool?: string; params?: object; toTool: string; toParams?: object }>;
|
|
18
20
|
triggers_config:
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
21
|
+
| ToolContract<{ classifierProvider: string | null; available: string[] }, { action: 'get' }>
|
|
22
|
+
| ToolContract<{ classifierProvider: string }, { action: 'set'; provider: string }>
|
|
23
|
+
| ToolContract<{ classifierProvider: null }, { action: 'clear' }>;
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -59,6 +61,8 @@ type TriggerActionInput =
|
|
|
59
61
|
| { action: 'get'; id: string }
|
|
60
62
|
| { action: 'add'; conditions: TriggerCondition[]; tool: string; params?: unknown; enabled?: boolean }
|
|
61
63
|
| { action: 'update'; id: string; conditions?: TriggerCondition[]; tool?: string; params?: unknown; enabled?: boolean }
|
|
64
|
+
| { action: 'disable'; id: string }
|
|
65
|
+
| { action: 'enable'; id: string }
|
|
62
66
|
| { action: 'remove'; id: string }
|
|
63
67
|
| { action: 'move'; tool?: string; params?: unknown; toTool: string; toParams?: unknown }
|
|
64
68
|
| { action: 'copy'; tool?: string; params?: unknown; toTool: string; toParams?: unknown };
|
|
@@ -136,6 +140,19 @@ export function createTriggerActionTool(manager: TriggerManager): Tool<ToolResul
|
|
|
136
140
|
return;
|
|
137
141
|
}
|
|
138
142
|
|
|
143
|
+
// Suspend/resume: keep the trigger but flip whether `evaluate` considers it. Less aggressive
|
|
144
|
+
// than `remove` — the conditions and invocation are preserved, so re-enabling restores it
|
|
145
|
+
// exactly. The go-to when a trigger fires too eagerly and you want to stop it without losing it.
|
|
146
|
+
case 'disable':
|
|
147
|
+
case 'enable': {
|
|
148
|
+
const { id } = args as Extract<TriggerActionInput, { action: 'disable' | 'enable' }>;
|
|
149
|
+
if (!id) { yield { type: 'error', message: `action "${args.action}" requires "id".` }; return; }
|
|
150
|
+
const t = await manager.update(id, { enabled: args.action === 'enable' });
|
|
151
|
+
if (t === undefined) { yield { type: 'error', message: `Trigger not found: "${id}"` }; return; }
|
|
152
|
+
yield { type: 'result', value: t };
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
139
156
|
case 'remove': {
|
|
140
157
|
const { id } = args as Extract<TriggerActionInput, { action: 'remove' }>;
|
|
141
158
|
if (!id) { yield { type: 'error', message: 'action "remove" requires "id".' }; return; }
|
|
@@ -177,7 +194,7 @@ export function createTriggerActionTool(manager: TriggerManager): Tool<ToolResul
|
|
|
177
194
|
}
|
|
178
195
|
|
|
179
196
|
default:
|
|
180
|
-
yield { type: 'error', message: `Unknown action "${String(args.action)}". Expected one of: list, query, get, add, update, remove, move, copy.` };
|
|
197
|
+
yield { type: 'error', message: `Unknown action "${String(args.action)}". Expected one of: list, query, get, add, update, disable, enable, remove, move, copy.` };
|
|
181
198
|
}
|
|
182
199
|
},
|
|
183
200
|
};
|
|
@@ -187,25 +204,14 @@ export function createTriggerActionTool(manager: TriggerManager): Tool<ToolResul
|
|
|
187
204
|
description:
|
|
188
205
|
'Manage triggers — data-driven hooks that invoke a tool when an LLM classifier judges one of ' +
|
|
189
206
|
'their conditions matched against the current turn. Use this to list triggers, find the ones ' +
|
|
190
|
-
'that invoke a given tool (query), read one, create one, edit one by id,
|
|
191
|
-
'
|
|
207
|
+
'that invoke a given tool (query), read one, create one, edit one by id, suspend one so it stops ' +
|
|
208
|
+
'firing while keeping it (disable) or bring it back (enable), delete one, or bulk re-target a ' +
|
|
209
|
+
'selected set onto a new tool — in place (move) or as duplicates (copy).\n\n' +
|
|
210
|
+
'When a trigger fires too eagerly, prefer "disable" over "remove": it keeps the conditions and ' +
|
|
211
|
+
'invocation intact (so "enable" restores it exactly) but excludes it from evaluation entirely.\n\n' +
|
|
192
212
|
GUIDANCE + '\n\n' +
|
|
193
213
|
'A trigger has a stable `id` — address it by that, never by its conditions. To change one, ' +
|
|
194
214
|
'"get" or "list" first to read the id, then "update" by id.\n\n' +
|
|
195
|
-
'Parameters depend on `action` (TypeScript):\n' +
|
|
196
|
-
'```ts\n' +
|
|
197
|
-
"type TriggerKind = 'ephemeral' | 'contextual' | 'retract' | 'followup'; // ephemeral=judge user msg+inject for this turn; contextual=judge user msg+fold durably onto it; retract=wrong, redo; followup=stands, add steer turn\n" +
|
|
198
|
-
'type TriggerCondition = { kind: TriggerKind; rule: string };\n' +
|
|
199
|
-
'type TriggerAction =\n' +
|
|
200
|
-
" | { action: 'list' } // -> { triggers: [...] }\n" +
|
|
201
|
-
" | { action: 'query'; tool?: string; params?: object } // triggers invoking that tool -> { triggers: [...] }\n" +
|
|
202
|
-
" | { action: 'get'; id: string } // -> the trigger\n" +
|
|
203
|
-
" | { action: 'add'; conditions: TriggerCondition[]; tool: string; params?: object; enabled?: boolean } // -> { id }\n" +
|
|
204
|
-
" | { action: 'update'; id: string; conditions?: TriggerCondition[]; tool?: string; params?: object; enabled?: boolean } // edit by id\n" +
|
|
205
|
-
" | { action: 'remove'; id: string } // -> { id }\n" +
|
|
206
|
-
" | { action: 'move'; tool?: string; params?: object; toTool: string; toParams?: object } // re-target the queried set's invoke to toTool/toParams in place -> { triggers: [...] }\n" +
|
|
207
|
-
" | { action: 'copy'; tool?: string; params?: object; toTool: string; toParams?: object }; // duplicate the queried set, the copies invoking toTool/toParams -> { triggers: [...] }\n" +
|
|
208
|
-
'```\n\n' +
|
|
209
215
|
'For `move`/`copy`, `tool`/`params` are the SAME selector as `query` (they pick which triggers ' +
|
|
210
216
|
'to act on); `toTool`/`toParams` are the new invocation. A filter is required — both refuse to ' +
|
|
211
217
|
'act on the entire trigger set.',
|
|
@@ -213,15 +219,15 @@ export function createTriggerActionTool(manager: TriggerManager): Tool<ToolResul
|
|
|
213
219
|
type: 'object',
|
|
214
220
|
required: ['action'],
|
|
215
221
|
properties: {
|
|
216
|
-
action: { type: 'string', enum: ['list', 'query', 'get', 'add', 'update', 'remove', 'move', 'copy'], description: 'The operation to perform.' },
|
|
217
|
-
id: { type: 'string', description: 'Trigger id. Required for get/update/remove.' },
|
|
222
|
+
action: { type: 'string', enum: ['list', 'query', 'get', 'add', 'update', 'disable', 'enable', 'remove', 'move', 'copy'], description: 'The operation to perform.' },
|
|
223
|
+
id: { type: 'string', description: 'Trigger id. Required for get/update/disable/enable/remove.' },
|
|
218
224
|
conditions: { type: 'array', description: 'Conditions [{ kind: "ephemeral"|"contextual"|"retract"|"followup", rule: string }]. Required for add.',
|
|
219
225
|
items: { type: 'object', properties: { kind: { type: 'string', enum: ['ephemeral', 'contextual', 'retract', 'followup'] }, rule: { type: 'string' } } } },
|
|
220
226
|
tool: { type: 'string', description: 'For add: the tool to invoke. For query/move/copy: the selector matching invoke.tool.' },
|
|
221
227
|
params: { type: 'object', description: 'For add: params passed verbatim as the invoked tool\'s input. For query/move/copy: the selector matching invoke.params.' },
|
|
222
228
|
toTool: { type: 'string', description: 'New tool the selected triggers should invoke. Required for move/copy.' },
|
|
223
229
|
toParams: { type: 'object', description: 'New params for the selected triggers\' invocation (move/copy).' },
|
|
224
|
-
enabled: { type: 'boolean', description: '
|
|
230
|
+
enabled: { type: 'boolean', description: 'On add/update, set false to keep but suspend the trigger (absent ⇒ enabled). To toggle an existing trigger, prefer the dedicated "disable"/"enable" actions.' },
|
|
225
231
|
},
|
|
226
232
|
},
|
|
227
233
|
executor,
|
|
@@ -275,14 +281,7 @@ export function createTriggersConfigTool(services: MatbotMachine): Tool<ToolResu
|
|
|
275
281
|
'provider judges trigger conditions. It is an alias for an existing provider, not a new one. Unset, ' +
|
|
276
282
|
"the classifier uses the current turn's own provider; set it to pin a small/fast model. `get` " +
|
|
277
283
|
'reports the current pin and the available provider names; `set` pins one (it must already be ' +
|
|
278
|
-
'configured — see the provider tool); `clear` reverts to the turn provider
|
|
279
|
-
'Parameters (TypeScript):\n' +
|
|
280
|
-
'```ts\n' +
|
|
281
|
-
"type TriggersConfig =\n" +
|
|
282
|
-
" | { action: 'get' } // -> { classifierProvider: string | null, available }\n" +
|
|
283
|
-
" | { action: 'set'; provider: string } // pin a provider -> { classifierProvider }\n" +
|
|
284
|
-
" | { action: 'clear' }; // revert to the turn provider -> { classifierProvider: null }\n" +
|
|
285
|
-
'```',
|
|
284
|
+
'configured — see the provider tool); `clear` reverts to the turn provider.',
|
|
286
285
|
inputSchema: {
|
|
287
286
|
type: 'object',
|
|
288
287
|
required: ['action'],
|