@matatbread/matbot-triggers 0.3.0 → 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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/tools.ts +26 -6
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "node",
5
5
  "browser"
6
6
  ],
7
- "version": "0.3.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.3.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.3.0"
40
+ "@matatbread/matbot-plugin-api": "^0.3.1"
41
41
  },
42
42
  "scripts": {
43
43
  "typecheck": "tsc --noEmit"
package/src/tools.ts CHANGED
@@ -12,6 +12,8 @@ declare module '@matatbread/matbot-plugin-api' {
12
12
  | ToolContract<Trigger, { action: 'get'; id: string }>
13
13
  | ToolContract<{ id: string }, { action: 'add'; conditions: TriggerCondition[]; tool: string; params?: object; enabled?: boolean }>
14
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 }>
15
17
  | ToolContract<{ id: string }, { action: 'remove'; id: string }>
16
18
  | ToolContract<{ triggers: Trigger[] }, { action: 'move'; tool?: string; params?: object; toTool: string; toParams?: object }>
17
19
  | ToolContract<{ triggers: Trigger[] }, { action: 'copy'; tool?: string; params?: object; toTool: string; toParams?: object }>;
@@ -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,8 +204,11 @@ 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, delete one, or bulk ' +
191
- 're-target a selected set onto a new tool — in place (move) or as duplicates (copy).\n\n' +
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' +
@@ -199,15 +219,15 @@ export function createTriggerActionTool(manager: TriggerManager): Tool<ToolResul
199
219
  type: 'object',
200
220
  required: ['action'],
201
221
  properties: {
202
- action: { type: 'string', enum: ['list', 'query', 'get', 'add', 'update', 'remove', 'move', 'copy'], description: 'The operation to perform.' },
203
- 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.' },
204
224
  conditions: { type: 'array', description: 'Conditions [{ kind: "ephemeral"|"contextual"|"retract"|"followup", rule: string }]. Required for add.',
205
225
  items: { type: 'object', properties: { kind: { type: 'string', enum: ['ephemeral', 'contextual', 'retract', 'followup'] }, rule: { type: 'string' } } } },
206
226
  tool: { type: 'string', description: 'For add: the tool to invoke. For query/move/copy: the selector matching invoke.tool.' },
207
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.' },
208
228
  toTool: { type: 'string', description: 'New tool the selected triggers should invoke. Required for move/copy.' },
209
229
  toParams: { type: 'object', description: 'New params for the selected triggers\' invocation (move/copy).' },
210
- enabled: { type: 'boolean', description: 'Set false to keep but disable the trigger.' },
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.' },
211
231
  },
212
232
  },
213
233
  executor,