@matatbread/matbot-triggers 0.4.1 → 0.4.4

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/dispatch.ts +13 -4
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "node",
5
5
  "browser"
6
6
  ],
7
- "version": "0.4.1",
7
+ "version": "0.4.4",
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.1"
36
+ "@matatbread/matbot-plugin-api": "^0.4.4"
37
37
  },
38
38
  "devDependencies": {
39
39
  "typescript": "^6.0.3",
40
- "@matatbread/matbot-plugin-api": "^0.4.1"
40
+ "@matatbread/matbot-plugin-api": "^0.4.4"
41
41
  },
42
42
  "scripts": {
43
43
  "typecheck": "tsc --noEmit"
package/src/dispatch.ts CHANGED
@@ -17,7 +17,8 @@ export interface DispatchOutcome {
17
17
  * model wakes: a tool that yields a `result` is producing model-facing content (`hadResult` → the
18
18
  * caller injects it); a tool that yields none is a silent side-effect (the model never wakes). Any
19
19
  * `marker` events the tool emits are collected for the caller to persist, and a tool that errors or
20
- * throws — or names an absent tool — is recorded as an error marker rather than vanishing into a log.
20
+ * throws — or names an absent tool — is recorded as an error marker rather than vanishing into a log;
21
+ * one cut off by an abort is recorded as interrupted, not as a failure.
21
22
  */
22
23
  export async function dispatchTrigger(
23
24
  services: MatbotMachine,
@@ -25,8 +26,16 @@ export async function dispatchTrigger(
25
26
  ctx: { session: Session; signal: AbortSignal; provider: string; prompt?: PromptFn },
26
27
  ): Promise<DispatchOutcome> {
27
28
  const markers: MessageContent[] = [];
29
+ // An aborted signal (a mid-turn steer, a user cancel) means the tool was cut off, not that it faulted:
30
+ // the raw abort reason is an internal token ("steer") that reads as a real failure in a durable marker.
31
+ // The runner reframes this for the tools it runs itself (INTERRUPTED_TOOL_RESULT); a trigger's tool runs
32
+ // outside that loop, so the same reframing has to happen here. The trace is still recorded — a trigger
33
+ // that was interrupted did nothing, and a post-mortem wants to know that — just not as an error.
28
34
  const fail = (error: string): void => {
29
- markers.push({ type: 'marker', creator: 'triggers', data: { triggerId: trigger.id, tool: trigger.invoke.tool, error } });
35
+ const data = ctx.signal.aborted
36
+ ? { triggerId: trigger.id, tool: trigger.invoke.tool, interrupted: true }
37
+ : { triggerId: trigger.id, tool: trigger.invoke.tool, error };
38
+ markers.push({ type: 'marker', creator: 'triggers', data });
30
39
  };
31
40
 
32
41
  let result: unknown;
@@ -56,12 +65,12 @@ export async function dispatchTrigger(
56
65
  if (ev.type === 'result') { result = ev.value; hadResult = true; }
57
66
  else if (ev.type === 'marker') { markers.push({ type: 'marker', creator: ev.creator, data: ev.data }); }
58
67
  else if (ev.type === 'error') {
59
- console.warn(`[triggers] trigger ${trigger.id} tool "${trigger.invoke.tool}" errored: ${ev.message}`);
68
+ if (!ctx.signal.aborted) console.warn(`[triggers] trigger ${trigger.id} tool "${trigger.invoke.tool}" errored: ${ev.message}`);
60
69
  fail(ev.message);
61
70
  }
62
71
  }
63
72
  } catch (e) {
64
- console.warn(`[triggers] trigger ${trigger.id} tool "${trigger.invoke.tool}" threw:`, e);
73
+ if (!ctx.signal.aborted) console.warn(`[triggers] trigger ${trigger.id} tool "${trigger.invoke.tool}" threw:`, e);
65
74
  fail(e instanceof Error ? e.message : String(e));
66
75
  }
67
76