@unieai/rabi-tool-call-timeout-policy 0.2.1-rc.3 → 0.2.2-rc.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/locale/de.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Timeout-Kontrolle für Tool-Aufrufe",
4
+ "description": "Senden Sie ein Abbruchsignal entsprechend dem Zeitlimit jedes Tools und geben Sie das Timeout-Ergebnis zurück."
5
+ }
6
+ }
package/locale/es.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Control de tiempo de espera de llamada de herramienta",
4
+ "description": "Envía una señal de cancelación de acuerdo con el límite de tiempo de cada herramienta y devuelve el resultado del tiempo de espera."
5
+ }
6
+ }
package/locale/fr.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Contrôle du délai d'expiration des appels d'outils",
4
+ "description": "Envoyez un signal d'annulation en fonction de la limite de temps de chaque outil et renvoyez le résultat du délai d'attente."
5
+ }
6
+ }
package/locale/ja.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "ツール呼び出しタイムアウト制御",
4
+ "description": "ツールごとの制限時間に従ってキャンセルを通知し、タイムアウト結果を返します。"
5
+ }
6
+ }
package/locale/pt.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Controle de tempo limite de chamada de ferramenta",
4
+ "description": "Envia um sinal de cancelamento de acordo com o limite de tempo de cada ferramenta e retorna o resultado do timeout."
5
+ }
6
+ }
package/locale/ru.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Управление тайм-аутом вызова инструмента",
4
+ "description": "Отправьте сигнал отмены в соответствии с лимитом времени каждого инструмента и верните результат тайм-аута."
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unieai/rabi-tool-call-timeout-policy",
3
3
  "description": "Tool-call timeout policy: a tools/execute wrapper that arms a per-tool deadline on exec.signal and returns TOOL_TIMEOUT when it wins",
4
- "version": "0.2.1-rc.3",
4
+ "version": "0.2.2-rc.5",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -21,13 +21,16 @@
21
21
  "locale/*.json",
22
22
  "lib/index.js",
23
23
  "lib/types/**/*.d.ts",
24
+ "lib/types/**/*.d.ts.map",
25
+ "lib/**/*.js.map",
26
+ "src",
24
27
  "README.md"
25
28
  ],
26
29
  "license": "MIT",
27
30
  "peerDependencies": {
28
- "@unieai/rabi-llm": "0.2.1-rc.3",
29
- "@unieai/rabi-timeout": "0.2.1-rc.3",
30
- "@unieai/rabi-tools": "0.2.1-rc.3",
31
- "@unieai/cordis": "4.0.5"
31
+ "@unieai/rabi-llm": "0.2.2-rc.5",
32
+ "@unieai/rabi-timeout": "0.2.2-rc.5",
33
+ "@unieai/rabi-tools": "0.2.2-rc.5",
34
+ "@unieai/cordis": "4.1.0"
32
35
  }
33
36
  }
package/src/index.ts ADDED
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Cooperative tool-call timeout enforcer. A tool declares `timeoutMs` and
3
+ * promises to honor `exec.signal`; this wrapper arms that deadline and maps its
4
+ * own expiry to `TOOL_TIMEOUT` without racing or abandoning the tool promise.
5
+ *
6
+ * FIXME: settle the intended `@unieai/rabi-timeout-guard` rename before the
7
+ * first tagged release — suggestion only, aligning the name with its `guard/`
8
+ * home; decide at resolution time
9
+ * ([regrouping Agent Note](../../../../.agents/notes/archived/architecture/2026-07-29-package-regrouping.md)).
10
+ *
11
+ * @module @unieai/rabi-tool-call-timeout-policy
12
+ */
13
+
14
+ import type { Context } from '@unieai/cordis'
15
+ import { deadline, timeoutOf } from '@unieai/rabi-timeout'
16
+ import type { ToolExecutionResult } from '@unieai/rabi-tools'
17
+
18
+ /**
19
+ * The code owned by this plugin, used BOTH as the internal {@link deadline}
20
+ * classification code AND as the structured error `code` on the replacement
21
+ * tool result. Scoping {@link timeoutOf} to it keeps a nested outer deadline
22
+ * (another `tools/execute` wrapper's timer that fired first) from being misread
23
+ * as this plugin's own timeout — it reads as an ordinary upstream cancel.
24
+ */
25
+ export const TOOL_TIMEOUT = 'TOOL_TIMEOUT'
26
+
27
+ /** Cordis plugin name used by loader diagnostics. */
28
+ export const name = 'timeout-policy'
29
+
30
+ /** The tool registry service this plugin wraps (`tools/execute`) and reads (`get`). */
31
+ export const inject = ['tools']
32
+
33
+ /**
34
+ * The structured result substituted when this plugin's deadline wins. `content`
35
+ * is the model-facing message; `error.code` is the same {@link TOOL_TIMEOUT}
36
+ * this plugin owns, so a retry/sandbox plugin (and replay) can route on it.
37
+ *
38
+ * @param timeoutMs - the elapsed budget, rendered into the model-facing message.
39
+ * @returns the `isError` {@link ToolExecutionResult} with a `TOOL_TIMEOUT` error.
40
+ */
41
+ function toolTimeoutResult(timeoutMs: number): ToolExecutionResult {
42
+ const message = `tool call timed out after ${timeoutMs}ms`
43
+ return {
44
+ content: [{ type: 'text', text: `Error: ${message}` }],
45
+ isError: true,
46
+ error: { message, info: { name: 'ToolTimeoutError', code: TOOL_TIMEOUT } },
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Register the timeout wrapper. It resolves the caller-visible tool definition,
52
+ * temporarily replaces `exec.signal`, delegates, restores the upstream signal,
53
+ * and replaces the result only when this wrapper's own timer fired.
54
+ */
55
+ export function apply(ctx: Context): void {
56
+ ctx.on('tools/execute', async (exec, next): Promise<ToolExecutionResult> => {
57
+ const timeoutMs = ctx.tools.get(exec.name, exec.agent)?.timeoutMs
58
+ // A tool that declares no budget: no deadline, delegate unchanged.
59
+ if (timeoutMs === undefined) return next()
60
+
61
+ using d = deadline(exec.signal, timeoutMs, TOOL_TIMEOUT)
62
+ // Swap the derived deadline onto exec for dispatch, then restore the
63
+ // caller's own signal so post-execute listeners never see this plugin's
64
+ // (possibly already-aborted) timeout signal.
65
+ const upstream = exec.signal
66
+ exec.signal = d.signal
67
+ try {
68
+ const result = await next()
69
+ // If OUR timer fired (scoped by code — a nested outer deadline reads as
70
+ // undefined here), the tool/capability saw the abort and reached
71
+ // quiescence; replace whatever it returned (its own abort result) with the
72
+ // structured TOOL_TIMEOUT the model sees.
73
+ if (timeoutOf(d.signal, TOOL_TIMEOUT) !== undefined) {
74
+ return toolTimeoutResult(timeoutMs)
75
+ }
76
+ return result
77
+ } finally {
78
+ exec.signal = upstream
79
+ }
80
+ })
81
+ }