@nookplot/runtime 0.5.100 → 0.5.106

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 (126) hide show
  1. package/dist/__tests__/autonomous.guardrails.test.d.ts +2 -0
  2. package/dist/__tests__/autonomous.guardrails.test.d.ts.map +1 -0
  3. package/dist/__tests__/autonomous.guardrails.test.js +215 -0
  4. package/dist/__tests__/autonomous.guardrails.test.js.map +1 -0
  5. package/dist/__tests__/autonomous.hooks.test.d.ts +2 -0
  6. package/dist/__tests__/autonomous.hooks.test.d.ts.map +1 -0
  7. package/dist/__tests__/autonomous.hooks.test.js +107 -0
  8. package/dist/__tests__/autonomous.hooks.test.js.map +1 -0
  9. package/dist/__tests__/chatEngine.episodicHook.test.d.ts +2 -0
  10. package/dist/__tests__/chatEngine.episodicHook.test.d.ts.map +1 -0
  11. package/dist/__tests__/chatEngine.episodicHook.test.js +160 -0
  12. package/dist/__tests__/chatEngine.episodicHook.test.js.map +1 -0
  13. package/dist/__tests__/chatEngine.test.d.ts +2 -0
  14. package/dist/__tests__/chatEngine.test.d.ts.map +1 -0
  15. package/dist/__tests__/chatEngine.test.js +482 -0
  16. package/dist/__tests__/chatEngine.test.js.map +1 -0
  17. package/dist/__tests__/conversation/compactionMemory.test.d.ts +2 -0
  18. package/dist/__tests__/conversation/compactionMemory.test.d.ts.map +1 -0
  19. package/dist/__tests__/conversation/compactionMemory.test.js +447 -0
  20. package/dist/__tests__/conversation/compactionMemory.test.js.map +1 -0
  21. package/dist/__tests__/conversation/modelThresholdsParity.test.d.ts +2 -0
  22. package/dist/__tests__/conversation/modelThresholdsParity.test.d.ts.map +1 -0
  23. package/dist/__tests__/conversation/modelThresholdsParity.test.js +79 -0
  24. package/dist/__tests__/conversation/modelThresholdsParity.test.js.map +1 -0
  25. package/dist/__tests__/guardrails.test.d.ts +2 -0
  26. package/dist/__tests__/guardrails.test.d.ts.map +1 -0
  27. package/dist/__tests__/guardrails.test.js +236 -0
  28. package/dist/__tests__/guardrails.test.js.map +1 -0
  29. package/dist/__tests__/hooks.test.d.ts +9 -0
  30. package/dist/__tests__/hooks.test.d.ts.map +1 -0
  31. package/dist/__tests__/hooks.test.js +188 -0
  32. package/dist/__tests__/hooks.test.js.map +1 -0
  33. package/dist/__tests__/querySegmentation.test.d.ts +2 -0
  34. package/dist/__tests__/querySegmentation.test.d.ts.map +1 -0
  35. package/dist/__tests__/querySegmentation.test.js +187 -0
  36. package/dist/__tests__/querySegmentation.test.js.map +1 -0
  37. package/dist/__tests__/sandbox.test.d.ts +13 -0
  38. package/dist/__tests__/sandbox.test.d.ts.map +1 -0
  39. package/dist/__tests__/sandbox.test.js +413 -0
  40. package/dist/__tests__/sandbox.test.js.map +1 -0
  41. package/dist/__tests__/wakeUpStack.test.d.ts +2 -0
  42. package/dist/__tests__/wakeUpStack.test.d.ts.map +1 -0
  43. package/dist/__tests__/wakeUpStack.test.js +239 -0
  44. package/dist/__tests__/wakeUpStack.test.js.map +1 -0
  45. package/dist/actionCatalog.generated.d.ts +1 -1
  46. package/dist/actionCatalog.generated.d.ts.map +1 -1
  47. package/dist/actionCatalog.generated.js +125 -21
  48. package/dist/actionCatalog.generated.js.map +1 -1
  49. package/dist/autonomous.d.ts +3 -0
  50. package/dist/autonomous.d.ts.map +1 -1
  51. package/dist/autonomous.js +108 -7
  52. package/dist/autonomous.js.map +1 -1
  53. package/dist/chat/chatEngine.d.ts +15 -0
  54. package/dist/chat/chatEngine.d.ts.map +1 -1
  55. package/dist/chat/chatEngine.js +59 -34
  56. package/dist/chat/chatEngine.js.map +1 -1
  57. package/dist/connection.d.ts.map +1 -1
  58. package/dist/connection.js +0 -1
  59. package/dist/connection.js.map +1 -1
  60. package/dist/conversation/compactionMemory.d.ts +124 -0
  61. package/dist/conversation/compactionMemory.d.ts.map +1 -0
  62. package/dist/conversation/compactionMemory.js +379 -0
  63. package/dist/conversation/compactionMemory.js.map +1 -0
  64. package/dist/conversation/conversationLogStore.d.ts +111 -0
  65. package/dist/conversation/conversationLogStore.d.ts.map +1 -0
  66. package/dist/conversation/conversationLogStore.js +248 -0
  67. package/dist/conversation/conversationLogStore.js.map +1 -0
  68. package/dist/conversation/conversationMemory.d.ts +59 -0
  69. package/dist/conversation/conversationMemory.d.ts.map +1 -0
  70. package/dist/conversation/conversationMemory.js +32 -0
  71. package/dist/conversation/conversationMemory.js.map +1 -0
  72. package/dist/conversation/index.d.ts +16 -0
  73. package/dist/conversation/index.d.ts.map +1 -0
  74. package/dist/conversation/index.js +5 -0
  75. package/dist/conversation/index.js.map +1 -0
  76. package/dist/conversation/modelLimits.d.ts +43 -0
  77. package/dist/conversation/modelLimits.d.ts.map +1 -0
  78. package/dist/conversation/modelLimits.js +67 -0
  79. package/dist/conversation/modelLimits.js.map +1 -0
  80. package/dist/defaultGuardrails.d.ts +21 -0
  81. package/dist/defaultGuardrails.d.ts.map +1 -0
  82. package/dist/defaultGuardrails.js +90 -0
  83. package/dist/defaultGuardrails.js.map +1 -0
  84. package/dist/episodicMemoryHook.d.ts +39 -0
  85. package/dist/episodicMemoryHook.d.ts.map +1 -0
  86. package/dist/episodicMemoryHook.js +58 -0
  87. package/dist/episodicMemoryHook.js.map +1 -0
  88. package/dist/guardrails.d.ts +182 -0
  89. package/dist/guardrails.d.ts.map +1 -0
  90. package/dist/guardrails.js +277 -0
  91. package/dist/guardrails.js.map +1 -0
  92. package/dist/hooks.d.ts +162 -0
  93. package/dist/hooks.d.ts.map +1 -0
  94. package/dist/hooks.js +91 -0
  95. package/dist/hooks.js.map +1 -0
  96. package/dist/index.d.ts +38 -3
  97. package/dist/index.d.ts.map +1 -1
  98. package/dist/index.js +51 -3
  99. package/dist/index.js.map +1 -1
  100. package/dist/knowledgeContext.d.ts +15 -1
  101. package/dist/knowledgeContext.d.ts.map +1 -1
  102. package/dist/knowledgeContext.js +26 -3
  103. package/dist/knowledgeContext.js.map +1 -1
  104. package/dist/memory.d.ts +15 -0
  105. package/dist/memory.d.ts.map +1 -1
  106. package/dist/memory.js +14 -0
  107. package/dist/memory.js.map +1 -1
  108. package/dist/querySegmentation.d.ts +54 -0
  109. package/dist/querySegmentation.d.ts.map +1 -0
  110. package/dist/querySegmentation.js +80 -0
  111. package/dist/querySegmentation.js.map +1 -0
  112. package/dist/sandbox.d.ts +156 -0
  113. package/dist/sandbox.d.ts.map +1 -0
  114. package/dist/sandbox.js +425 -0
  115. package/dist/sandbox.js.map +1 -0
  116. package/dist/signalActionMap.d.ts +19 -0
  117. package/dist/signalActionMap.d.ts.map +1 -1
  118. package/dist/signalActionMap.js +33 -0
  119. package/dist/signalActionMap.js.map +1 -1
  120. package/dist/types.d.ts +23 -1
  121. package/dist/types.d.ts.map +1 -1
  122. package/dist/wakeUpStack.d.ts +94 -0
  123. package/dist/wakeUpStack.d.ts.map +1 -0
  124. package/dist/wakeUpStack.js +215 -0
  125. package/dist/wakeUpStack.js.map +1 -0
  126. package/package.json +1 -1
@@ -0,0 +1,39 @@
1
+ /**
2
+ * episodicMemoryHook — installs a `chat_turn_complete` listener that persists
3
+ * each turn into the agent's episodic memory tier.
4
+ *
5
+ * Replaces the inlined `runtime.memory.storeMemory("episodic", …)` call that
6
+ * previously lived in `chat/chatEngine.ts`. Behavior is byte-for-byte
7
+ * preserved when the engine emits `enableMemory: true` — see the
8
+ * `chatEngine.episodicHook.test.ts` regression suite for proof.
9
+ *
10
+ * Auto-installed by `NookplotRuntime.connect()` unless the runtime was
11
+ * constructed with `{ autoInstallHooks: false }`. Opt-out, not opt-in —
12
+ * existing agents get the prior behavior for free.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const dispose = installEpisodicMemoryHook(runtime, { tagPrefix: "myagent" });
17
+ * // ...later
18
+ * dispose(); // stop the hook (also called automatically on runtime.disconnect)
19
+ * ```
20
+ *
21
+ * @module episodicMemoryHook
22
+ */
23
+ import type { NookplotRuntime } from "./index.js";
24
+ import type { HookRegistry } from "./hooks.js";
25
+ export interface EpisodicHookOptions {
26
+ /** Override the registry the hook subscribes to. Defaults to `runtime.hooks`. */
27
+ hooks?: HookRegistry;
28
+ /** Extra tags appended to every stored entry (e.g. ["env:prod"]). */
29
+ extraTags?: string[];
30
+ /** Override the agent name used in the formatted line. Defaults to payload.agentName. */
31
+ agentName?: string;
32
+ }
33
+ /**
34
+ * Subscribe to `chat_turn_complete` and write each turn to episodic memory.
35
+ *
36
+ * Returns a disposer that removes the listener.
37
+ */
38
+ export declare function installEpisodicMemoryHook(runtime: NookplotRuntime, opts?: EpisodicHookOptions): () => void;
39
+ //# sourceMappingURL=episodicMemoryHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"episodicMemoryHook.d.ts","sourceRoot":"","sources":["../src/episodicMemoryHook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAGxE,MAAM,WAAW,mBAAmB;IAClC,iFAAiF;IACjF,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,eAAe,EACxB,IAAI,GAAE,mBAAwB,GAC7B,MAAM,IAAI,CAoCZ"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * episodicMemoryHook — installs a `chat_turn_complete` listener that persists
3
+ * each turn into the agent's episodic memory tier.
4
+ *
5
+ * Replaces the inlined `runtime.memory.storeMemory("episodic", …)` call that
6
+ * previously lived in `chat/chatEngine.ts`. Behavior is byte-for-byte
7
+ * preserved when the engine emits `enableMemory: true` — see the
8
+ * `chatEngine.episodicHook.test.ts` regression suite for proof.
9
+ *
10
+ * Auto-installed by `NookplotRuntime.connect()` unless the runtime was
11
+ * constructed with `{ autoInstallHooks: false }`. Opt-out, not opt-in —
12
+ * existing agents get the prior behavior for free.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const dispose = installEpisodicMemoryHook(runtime, { tagPrefix: "myagent" });
17
+ * // ...later
18
+ * dispose(); // stop the hook (also called automatically on runtime.disconnect)
19
+ * ```
20
+ *
21
+ * @module episodicMemoryHook
22
+ */
23
+ import { hooks as defaultHooks } from "./hooks.js";
24
+ /**
25
+ * Subscribe to `chat_turn_complete` and write each turn to episodic memory.
26
+ *
27
+ * Returns a disposer that removes the listener.
28
+ */
29
+ export function installEpisodicMemoryHook(runtime, opts = {}) {
30
+ const hooks = opts.hooks ?? runtime.hooks ?? defaultHooks;
31
+ const listener = (payload) => {
32
+ // Respect the engine's enableMemory flag — when memory is disabled at
33
+ // the engine level, suppress writes regardless of hook registration.
34
+ if (payload.enableMemory === false)
35
+ return;
36
+ const { platform, sender, message, response, toolsUsed, toolCallCount, senderId, channelId } = payload;
37
+ const agentName = opts.agentName ?? payload.agentName ?? "Agent";
38
+ const extraTags = opts.extraTags ?? [];
39
+ runtime.memory
40
+ .storeMemory("episodic", `[${platform}] ${sender}: ${message}\n${agentName}: ${response}`, {
41
+ tags: ["conversation", platform, ...(toolsUsed ? ["tool_use"] : []), ...extraTags],
42
+ metadata: {
43
+ platform,
44
+ senderId: senderId ?? null,
45
+ senderName: sender ?? null,
46
+ channelId: channelId ?? null,
47
+ toolsUsed,
48
+ toolCallCount,
49
+ messageLength: message.length,
50
+ responseLength: response.length,
51
+ timestamp: new Date().toISOString(),
52
+ },
53
+ })
54
+ .catch(() => { });
55
+ };
56
+ return hooks.register("chat_turn_complete", listener);
57
+ }
58
+ //# sourceMappingURL=episodicMemoryHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"episodicMemoryHook.js","sourceRoot":"","sources":["../src/episodicMemoryHook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO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;aACA,KAAK,CAAC,GAAG,EAAE,GAAuC,CAAC,CAAC,CAAC;IAC1D,CAAC,CAAC;IAEF,OAAO,KAAK,CAAC,QAAQ,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Guardrails — declarative per-action parameter validation.
3
+ *
4
+ * A guardrail is a function attached to a specific `actionType`. It can:
5
+ * - **Pass** by returning `undefined` / nothing.
6
+ * - **Mutate args** by returning `Partial<TArgs>` — declared keys overwrite,
7
+ * undeclared keys are preserved.
8
+ * - **Block** by throwing `InputGuardrailTripped` (input) or
9
+ * `OutputGuardrailTripped` (output). The wrapped dispatcher converts any
10
+ * other error into an `InputGuardrailTripped` so callers always observe
11
+ * a single error class for "validation failure".
12
+ *
13
+ * This is a SEPARATE concern from `contentSafety` (string sanitizers) and
14
+ * `ContentScanner` (gateway threat-detection) — guardrails operate on typed
15
+ * arg objects scoped to a specific action, see those args, and can short-
16
+ * circuit the dispatch. All three layers can run on the same call.
17
+ *
18
+ * Composition order at the dispatcher (`runtime/src/autonomous.ts`
19
+ * `handleActionRequest`):
20
+ * 1. `action_start` hook fires.
21
+ * 2. `tool_input` hook fires.
22
+ * 3. Input guardrails run in declared order; first throw → `action_error`.
23
+ * 4. Action body executes.
24
+ * 5. `tool_output` hook fires.
25
+ * 6. Output guardrails run; first throw → `action_error`.
26
+ * 7. `action_end` hook fires.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * runtime.guardrails.register("send_dm", {
31
+ * input: [
32
+ * ({ to }) => {
33
+ * if (!/^0x[0-9a-fA-F]{40}$/.test(to as string)) {
34
+ * throw new InputGuardrailTripped("`to` must be a 0x-prefixed 40-hex address");
35
+ * }
36
+ * },
37
+ * ({ content }) => ({ content: sanitizeForPrompt(content as string, 2000) }),
38
+ * ],
39
+ * });
40
+ * ```
41
+ *
42
+ * @module guardrails
43
+ */
44
+ import { type HookRegistry } from "./hooks.js";
45
+ /** Base class for guardrail short-circuits. Catch this to handle either side. */
46
+ export declare class GuardrailTripped extends Error {
47
+ constructor(message: string, options?: {
48
+ cause?: unknown;
49
+ });
50
+ }
51
+ /** Thrown when an input guardrail rejects or any guardrail callback throws
52
+ * during the input phase. The dispatcher converts this into `action_error`. */
53
+ export declare class InputGuardrailTripped extends GuardrailTripped {
54
+ constructor(message: string, options?: {
55
+ cause?: unknown;
56
+ });
57
+ }
58
+ /** Thrown when an output guardrail rejects. The dispatcher converts this
59
+ * into `action_error` after the action body has already executed. */
60
+ export declare class OutputGuardrailTripped extends GuardrailTripped {
61
+ constructor(message: string, options?: {
62
+ cause?: unknown;
63
+ });
64
+ }
65
+ /**
66
+ * An input guardrail. Receives the (possibly mutated) args from prior
67
+ * guardrails. Returns `void` to pass, `Partial<TArgs>` to mutate, or throws
68
+ * `InputGuardrailTripped` to block.
69
+ *
70
+ * TS does not introspect parameter names — the caller declares which keys
71
+ * the guardrail accepts via the `Pick<TArgs, …>` type. Returned objects are
72
+ * shallow-merged onto args; undeclared keys in the return value are still
73
+ * applied (TS can't enforce param-binding at runtime), but agents should
74
+ * stick to the declared keys for parity with the Python `inspect.signature`
75
+ * extraction.
76
+ */
77
+ export type InputGuardrail<TArgs extends Record<string, unknown> = Record<string, unknown>> = (args: TArgs) => void | undefined | Partial<TArgs> | Promise<void | undefined | Partial<TArgs>>;
78
+ /**
79
+ * An output guardrail. Receives the action result. Returns `void` to pass,
80
+ * `Partial<TResult>` to mutate, or throws `OutputGuardrailTripped` to block.
81
+ *
82
+ * Output guardrails CANNOT replace the entire result — the merge is shallow
83
+ * AND `undefined` values in the return are filtered out before merge. This
84
+ * means a guardrail cannot silently drop security-critical fields (`txHash`,
85
+ * `signature`) by returning `{ txHash: undefined }`. To intentionally clear
86
+ * a field, throw `OutputGuardrailTripped` instead.
87
+ */
88
+ export type OutputGuardrail<TResult = unknown> = (result: TResult) => void | undefined | Partial<TResult> | Promise<void | undefined | Partial<TResult>>;
89
+ export interface GuardrailSet<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> {
90
+ input?: InputGuardrail<TArgs>[];
91
+ output?: OutputGuardrail<TResult>[];
92
+ }
93
+ /**
94
+ * Per-action guardrail registry. Keyed on `actionType` (the same string the
95
+ * dispatcher uses, e.g. `"send_dm"` or `"create_bounty"`). Multiple `register`
96
+ * calls APPEND — guardrails compose in registration order so an early
97
+ * mutation is visible to later validators.
98
+ *
99
+ * `runInput` / `runOutput` are the dispatcher integration points. They:
100
+ * - Apply guardrails sequentially (not in parallel — order matters).
101
+ * - Shallow-merge any returned `Partial<>` onto the working args.
102
+ * - Re-throw `InputGuardrailTripped` / `OutputGuardrailTripped` as-is.
103
+ * - Wrap any other thrown error in `InputGuardrailTripped` / `OutputGuardrailTripped`
104
+ * with the original attached as `cause`.
105
+ *
106
+ * Tool hooks (`tool_input` / `tool_output`) are emitted by the dispatcher,
107
+ * not by the registry — keeps the emit point next to the action boundary.
108
+ */
109
+ export declare class GuardrailRegistry {
110
+ private readonly inputs;
111
+ private readonly outputs;
112
+ private readonly hooks;
113
+ constructor(hooks?: HookRegistry);
114
+ /**
115
+ * Register one or more guardrails for an action. Returns a disposer that
116
+ * removes only the guardrails added by this call.
117
+ *
118
+ * `actionType` is deliberately typed as `string`, not a union of known
119
+ * action names. The registry does NOT validate against `ON_CHAIN_ACTIONS`
120
+ * — agents can attach guardrails to custom off-chain handlers, to internal
121
+ * action names, or to third-party actions added via SDK extension. The
122
+ * dispatcher only invokes guardrails whose key matches the actionType it's
123
+ * currently handling, so registering for an unknown key is harmless (the
124
+ * guardrail simply never runs).
125
+ *
126
+ * If you need strict validation — e.g. a CI check that a guardrail is
127
+ * actually wired to a real action — use {@link countInput} /
128
+ * {@link countOutput} in a test that asserts against the exported
129
+ * `ON_CHAIN_ACTIONS` set from `autonomous.ts`.
130
+ */
131
+ register<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown>(actionType: string, set: GuardrailSet<TArgs, TResult>): () => void;
132
+ /** Number of registered input guardrails for an action (test inspection). */
133
+ countInput(actionType: string): number;
134
+ /** Number of registered output guardrails for an action (test inspection). */
135
+ countOutput(actionType: string): number;
136
+ /** Test helper. With no arg, clears all guardrails. */
137
+ clear(actionType?: string): void;
138
+ /**
139
+ * Run input guardrails in declared order and return the (possibly mutated)
140
+ * args. Throws `InputGuardrailTripped` if any guardrail rejects.
141
+ *
142
+ * The original `args` object is not mutated — a new shallow copy is
143
+ * returned even when no mutations occurred, to keep caller semantics
144
+ * predictable.
145
+ */
146
+ runInput<TArgs extends Record<string, unknown>>(actionType: string, args: TArgs): Promise<TArgs>;
147
+ /**
148
+ * Run output guardrails in declared order and return the (possibly
149
+ * mutated) result. Throws `OutputGuardrailTripped` on rejection. Like
150
+ * `runInput`, the working object is shallow-cloned for each mutation so
151
+ * the caller's `result` reference is untouched until the call returns.
152
+ */
153
+ runOutput<TResult>(actionType: string, result: TResult): Promise<TResult>;
154
+ }
155
+ /**
156
+ * Decorator-style wrapper for a single action handler. Convenient when an
157
+ * agent wants to attach guardrails to a one-off handler (a custom CLI tool,
158
+ * a unit-test fixture) without registering them globally.
159
+ *
160
+ * For the dispatcher integration, prefer `GuardrailRegistry.register()` +
161
+ * `registry.runInput` / `registry.runOutput` — that path is what
162
+ * `runtime/src/autonomous.ts:handleActionRequest` calls.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * const sendDm = withGuardrails(rawSendDm, {
167
+ * input: [({ to }) => { if (!to.startsWith("0x")) throw new InputGuardrailTripped("bad addr"); }],
168
+ * output: [({ messageId }) => { if (!messageId) throw new OutputGuardrailTripped("missing id"); }],
169
+ * });
170
+ * ```
171
+ */
172
+ export declare function withGuardrails<TArgs extends Record<string, unknown>, TResult>(handler: (args: TArgs) => Promise<TResult> | TResult, opts: {
173
+ input?: InputGuardrail<TArgs>[];
174
+ output?: OutputGuardrail<TResult>[];
175
+ }): (args: TArgs) => Promise<TResult>;
176
+ /**
177
+ * Module singleton. `NookplotRuntime` exposes its own `runtime.guardrails`
178
+ * which is the same object as this — `import { guardrails } from
179
+ * "@nookplot/runtime"` and `runtime.guardrails` are interchangeable.
180
+ */
181
+ export declare const guardrails: GuardrailRegistry;
182
+ //# sourceMappingURL=guardrails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrails.d.ts","sourceRoot":"","sources":["../src/guardrails.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAItE,iFAAiF;AACjF,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAO3D;AAED;gFACgF;AAChF,qBAAa,qBAAsB,SAAQ,gBAAgB;gBAC7C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAI3D;AAED;sEACsE;AACtE,qBAAa,sBAAuB,SAAQ,gBAAgB;gBAC9C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAI3D;AAID;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAC5F,IAAI,EAAE,KAAK,KACR,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAEpF;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,GAAG,OAAO,IAAI,CAC/C,MAAM,EAAE,OAAO,KACZ,IAAI,GAAG,SAAS,GAAG,OA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SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CAwBhF;AAsBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAC5B,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,OAAO,EAEP,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,EACpD,IAAI,EAAE;IACJ,KAAK,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;IAChC,MAAM,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;CACrC,GACA,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CASnC;AAID;;;;GAIG;AACH,eAAO,MAAM,UAAU,mBAA0B,CAAC"}
@@ -0,0 +1,277 @@
1
+ /**
2
+ * Guardrails — declarative per-action parameter validation.
3
+ *
4
+ * A guardrail is a function attached to a specific `actionType`. It can:
5
+ * - **Pass** by returning `undefined` / nothing.
6
+ * - **Mutate args** by returning `Partial<TArgs>` — declared keys overwrite,
7
+ * undeclared keys are preserved.
8
+ * - **Block** by throwing `InputGuardrailTripped` (input) or
9
+ * `OutputGuardrailTripped` (output). The wrapped dispatcher converts any
10
+ * other error into an `InputGuardrailTripped` so callers always observe
11
+ * a single error class for "validation failure".
12
+ *
13
+ * This is a SEPARATE concern from `contentSafety` (string sanitizers) and
14
+ * `ContentScanner` (gateway threat-detection) — guardrails operate on typed
15
+ * arg objects scoped to a specific action, see those args, and can short-
16
+ * circuit the dispatch. All three layers can run on the same call.
17
+ *
18
+ * Composition order at the dispatcher (`runtime/src/autonomous.ts`
19
+ * `handleActionRequest`):
20
+ * 1. `action_start` hook fires.
21
+ * 2. `tool_input` hook fires.
22
+ * 3. Input guardrails run in declared order; first throw → `action_error`.
23
+ * 4. Action body executes.
24
+ * 5. `tool_output` hook fires.
25
+ * 6. Output guardrails run; first throw → `action_error`.
26
+ * 7. `action_end` hook fires.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * runtime.guardrails.register("send_dm", {
31
+ * input: [
32
+ * ({ to }) => {
33
+ * if (!/^0x[0-9a-fA-F]{40}$/.test(to as string)) {
34
+ * throw new InputGuardrailTripped("`to` must be a 0x-prefixed 40-hex address");
35
+ * }
36
+ * },
37
+ * ({ content }) => ({ content: sanitizeForPrompt(content as string, 2000) }),
38
+ * ],
39
+ * });
40
+ * ```
41
+ *
42
+ * @module guardrails
43
+ */
44
+ import { hooks as defaultHooks } from "./hooks.js";
45
+ // ── Errors ───────────────────────────────────────────────────
46
+ /** Base class for guardrail short-circuits. Catch this to handle either side. */
47
+ export class GuardrailTripped extends Error {
48
+ constructor(message, options) {
49
+ super(message);
50
+ this.name = "GuardrailTripped";
51
+ if (options?.cause !== undefined) {
52
+ this.cause = options.cause;
53
+ }
54
+ }
55
+ }
56
+ /** Thrown when an input guardrail rejects or any guardrail callback throws
57
+ * during the input phase. The dispatcher converts this into `action_error`. */
58
+ export class InputGuardrailTripped extends GuardrailTripped {
59
+ constructor(message, options) {
60
+ super(message, options);
61
+ this.name = "InputGuardrailTripped";
62
+ }
63
+ }
64
+ /** Thrown when an output guardrail rejects. The dispatcher converts this
65
+ * into `action_error` after the action body has already executed. */
66
+ export class OutputGuardrailTripped extends GuardrailTripped {
67
+ constructor(message, options) {
68
+ super(message, options);
69
+ this.name = "OutputGuardrailTripped";
70
+ }
71
+ }
72
+ // ── Registry ─────────────────────────────────────────────────
73
+ /**
74
+ * Per-action guardrail registry. Keyed on `actionType` (the same string the
75
+ * dispatcher uses, e.g. `"send_dm"` or `"create_bounty"`). Multiple `register`
76
+ * calls APPEND — guardrails compose in registration order so an early
77
+ * mutation is visible to later validators.
78
+ *
79
+ * `runInput` / `runOutput` are the dispatcher integration points. They:
80
+ * - Apply guardrails sequentially (not in parallel — order matters).
81
+ * - Shallow-merge any returned `Partial<>` onto the working args.
82
+ * - Re-throw `InputGuardrailTripped` / `OutputGuardrailTripped` as-is.
83
+ * - Wrap any other thrown error in `InputGuardrailTripped` / `OutputGuardrailTripped`
84
+ * with the original attached as `cause`.
85
+ *
86
+ * Tool hooks (`tool_input` / `tool_output`) are emitted by the dispatcher,
87
+ * not by the registry — keeps the emit point next to the action boundary.
88
+ */
89
+ export class GuardrailRegistry {
90
+ inputs = new Map();
91
+ outputs = new Map();
92
+ hooks;
93
+ constructor(hooks = defaultHooks) {
94
+ this.hooks = hooks;
95
+ }
96
+ /**
97
+ * Register one or more guardrails for an action. Returns a disposer that
98
+ * removes only the guardrails added by this call.
99
+ *
100
+ * `actionType` is deliberately typed as `string`, not a union of known
101
+ * action names. The registry does NOT validate against `ON_CHAIN_ACTIONS`
102
+ * — agents can attach guardrails to custom off-chain handlers, to internal
103
+ * action names, or to third-party actions added via SDK extension. The
104
+ * dispatcher only invokes guardrails whose key matches the actionType it's
105
+ * currently handling, so registering for an unknown key is harmless (the
106
+ * guardrail simply never runs).
107
+ *
108
+ * If you need strict validation — e.g. a CI check that a guardrail is
109
+ * actually wired to a real action — use {@link countInput} /
110
+ * {@link countOutput} in a test that asserts against the exported
111
+ * `ON_CHAIN_ACTIONS` set from `autonomous.ts`.
112
+ */
113
+ register(actionType, set) {
114
+ const inputs = (set.input ?? []);
115
+ const outputs = (set.output ?? []);
116
+ if (inputs.length === 0 && outputs.length === 0)
117
+ return () => { };
118
+ const inputBucket = this.inputs.get(actionType) ?? [];
119
+ const outputBucket = this.outputs.get(actionType) ?? [];
120
+ inputBucket.push(...inputs);
121
+ outputBucket.push(...outputs);
122
+ if (inputBucket.length > 0)
123
+ this.inputs.set(actionType, inputBucket);
124
+ if (outputBucket.length > 0)
125
+ this.outputs.set(actionType, outputBucket);
126
+ return () => {
127
+ const ib = this.inputs.get(actionType);
128
+ if (ib) {
129
+ for (const cb of inputs) {
130
+ const idx = ib.indexOf(cb);
131
+ if (idx >= 0)
132
+ ib.splice(idx, 1);
133
+ }
134
+ if (ib.length === 0)
135
+ this.inputs.delete(actionType);
136
+ }
137
+ const ob = this.outputs.get(actionType);
138
+ if (ob) {
139
+ for (const cb of outputs) {
140
+ const idx = ob.indexOf(cb);
141
+ if (idx >= 0)
142
+ ob.splice(idx, 1);
143
+ }
144
+ if (ob.length === 0)
145
+ this.outputs.delete(actionType);
146
+ }
147
+ };
148
+ }
149
+ /** Number of registered input guardrails for an action (test inspection). */
150
+ countInput(actionType) {
151
+ return this.inputs.get(actionType)?.length ?? 0;
152
+ }
153
+ /** Number of registered output guardrails for an action (test inspection). */
154
+ countOutput(actionType) {
155
+ return this.outputs.get(actionType)?.length ?? 0;
156
+ }
157
+ /** Test helper. With no arg, clears all guardrails. */
158
+ clear(actionType) {
159
+ if (actionType) {
160
+ this.inputs.delete(actionType);
161
+ this.outputs.delete(actionType);
162
+ }
163
+ else {
164
+ this.inputs.clear();
165
+ this.outputs.clear();
166
+ }
167
+ }
168
+ /**
169
+ * Run input guardrails in declared order and return the (possibly mutated)
170
+ * args. Throws `InputGuardrailTripped` if any guardrail rejects.
171
+ *
172
+ * The original `args` object is not mutated — a new shallow copy is
173
+ * returned even when no mutations occurred, to keep caller semantics
174
+ * predictable.
175
+ */
176
+ async runInput(actionType, args) {
177
+ const list = this.inputs.get(actionType);
178
+ let working = { ...args };
179
+ if (!list || list.length === 0)
180
+ return working;
181
+ for (const guardrail of list) {
182
+ try {
183
+ const ret = await guardrail(working);
184
+ if (ret && typeof ret === "object") {
185
+ mergeDropUndefined(working, ret);
186
+ }
187
+ }
188
+ catch (err) {
189
+ if (err instanceof InputGuardrailTripped)
190
+ throw err;
191
+ const msg = err instanceof Error ? err.message : String(err);
192
+ throw new InputGuardrailTripped(`Input guardrail for "${actionType}" failed: ${msg}`, { cause: err });
193
+ }
194
+ }
195
+ return working;
196
+ }
197
+ /**
198
+ * Run output guardrails in declared order and return the (possibly
199
+ * mutated) result. Throws `OutputGuardrailTripped` on rejection. Like
200
+ * `runInput`, the working object is shallow-cloned for each mutation so
201
+ * the caller's `result` reference is untouched until the call returns.
202
+ */
203
+ async runOutput(actionType, result) {
204
+ const list = this.outputs.get(actionType);
205
+ if (!list || list.length === 0)
206
+ return result;
207
+ let working = result;
208
+ for (const guardrail of list) {
209
+ try {
210
+ const ret = await guardrail(working);
211
+ if (ret && typeof ret === "object" && working && typeof working === "object") {
212
+ const clone = { ...working };
213
+ mergeDropUndefined(clone, ret);
214
+ working = clone;
215
+ }
216
+ }
217
+ catch (err) {
218
+ if (err instanceof OutputGuardrailTripped)
219
+ throw err;
220
+ const msg = err instanceof Error ? err.message : String(err);
221
+ throw new OutputGuardrailTripped(`Output guardrail for "${actionType}" failed: ${msg}`, { cause: err });
222
+ }
223
+ }
224
+ return working;
225
+ }
226
+ }
227
+ /**
228
+ * Shallow-merge `patch` into `target`, skipping keys whose value is
229
+ * `undefined`. This is the single defensive merge used by both input and
230
+ * output guardrails. The rule: a guardrail can SET a field to anything
231
+ * (including `null` or an empty string — semantically meaningful), but
232
+ * cannot DROP a field by returning `undefined`. To drop, throw.
233
+ */
234
+ function mergeDropUndefined(target, patch) {
235
+ for (const key of Object.keys(patch)) {
236
+ const value = patch[key];
237
+ if (value === undefined)
238
+ continue;
239
+ target[key] = value;
240
+ }
241
+ }
242
+ // ── withGuardrails wrapper (standalone helper) ───────────────
243
+ /**
244
+ * Decorator-style wrapper for a single action handler. Convenient when an
245
+ * agent wants to attach guardrails to a one-off handler (a custom CLI tool,
246
+ * a unit-test fixture) without registering them globally.
247
+ *
248
+ * For the dispatcher integration, prefer `GuardrailRegistry.register()` +
249
+ * `registry.runInput` / `registry.runOutput` — that path is what
250
+ * `runtime/src/autonomous.ts:handleActionRequest` calls.
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * const sendDm = withGuardrails(rawSendDm, {
255
+ * input: [({ to }) => { if (!to.startsWith("0x")) throw new InputGuardrailTripped("bad addr"); }],
256
+ * output: [({ messageId }) => { if (!messageId) throw new OutputGuardrailTripped("missing id"); }],
257
+ * });
258
+ * ```
259
+ */
260
+ export function withGuardrails(handler, opts) {
261
+ const registry = new GuardrailRegistry();
262
+ const ACTION = "__withGuardrails__";
263
+ registry.register(ACTION, opts);
264
+ return async (args) => {
265
+ const validatedArgs = await registry.runInput(ACTION, args);
266
+ const result = await handler(validatedArgs);
267
+ return registry.runOutput(ACTION, result);
268
+ };
269
+ }
270
+ // ── Module-level singleton ───────────────────────────────────
271
+ /**
272
+ * Module singleton. `NookplotRuntime` exposes its own `runtime.guardrails`
273
+ * which is the same object as this — `import { guardrails } from
274
+ * "@nookplot/runtime"` and `runtime.guardrails` are interchangeable.
275
+ */
276
+ export const guardrails = new GuardrailRegistry();
277
+ //# sourceMappingURL=guardrails.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrails.js","sourceRoot":"","sources":["../src/guardrails.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAAE,KAAK,IAAI,YAAY,EAAqB,MAAM,YAAY,CAAC;AAEtE,gEAAgE;AAEhE,iFAAiF;AACjF,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,IAA4B,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AAED;gFACgF;AAChF,MAAM,OAAO,qBAAsB,SAAQ,gBAAgB;IACzD,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED;sEACsE;AACtE,MAAM,OAAO,sBAAuB,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