@nookplot/runtime 0.5.131 → 0.5.132
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/dist/__tests__/apiMarketplace.test.d.ts +2 -0
- package/dist/__tests__/apiMarketplace.test.d.ts.map +1 -0
- package/dist/__tests__/apiMarketplace.test.js +102 -0
- package/dist/__tests__/apiMarketplace.test.js.map +1 -0
- package/dist/__tests__/autonomous.actionDispatch.test.d.ts +2 -0
- package/dist/__tests__/autonomous.actionDispatch.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.actionDispatch.test.js +287 -0
- package/dist/__tests__/autonomous.actionDispatch.test.js.map +1 -0
- package/dist/__tests__/autonomous.dedup.test.d.ts +2 -0
- package/dist/__tests__/autonomous.dedup.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.dedup.test.js +125 -0
- package/dist/__tests__/autonomous.dedup.test.js.map +1 -0
- package/dist/__tests__/autonomous.doomLoop.test.d.ts +2 -0
- package/dist/__tests__/autonomous.doomLoop.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.doomLoop.test.js +126 -0
- package/dist/__tests__/autonomous.doomLoop.test.js.map +1 -0
- package/dist/__tests__/autonomous.getAvailableActions.test.d.ts +2 -0
- package/dist/__tests__/autonomous.getAvailableActions.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.getAvailableActions.test.js +233 -0
- package/dist/__tests__/autonomous.getAvailableActions.test.js.map +1 -0
- package/dist/__tests__/autonomous.guardrails.test.d.ts +2 -0
- package/dist/__tests__/autonomous.guardrails.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.guardrails.test.js +215 -0
- package/dist/__tests__/autonomous.guardrails.test.js.map +1 -0
- package/dist/__tests__/autonomous.hooks.test.d.ts +2 -0
- package/dist/__tests__/autonomous.hooks.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.hooks.test.js +107 -0
- package/dist/__tests__/autonomous.hooks.test.js.map +1 -0
- package/dist/__tests__/autonomous.latentSpace.test.d.ts +2 -0
- package/dist/__tests__/autonomous.latentSpace.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.latentSpace.test.js +224 -0
- package/dist/__tests__/autonomous.latentSpace.test.js.map +1 -0
- package/dist/__tests__/autonomous.lifecycle.test.d.ts +2 -0
- package/dist/__tests__/autonomous.lifecycle.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.lifecycle.test.js +147 -0
- package/dist/__tests__/autonomous.lifecycle.test.js.map +1 -0
- package/dist/__tests__/autonomous.loadedSkillRefs.test.d.ts +2 -0
- package/dist/__tests__/autonomous.loadedSkillRefs.test.d.ts.map +1 -0
- package/dist/__tests__/autonomous.loadedSkillRefs.test.js +150 -0
- package/dist/__tests__/autonomous.loadedSkillRefs.test.js.map +1 -0
- package/dist/__tests__/chatEngine.episodicHook.test.d.ts +2 -0
- package/dist/__tests__/chatEngine.episodicHook.test.d.ts.map +1 -0
- package/dist/__tests__/chatEngine.episodicHook.test.js +160 -0
- package/dist/__tests__/chatEngine.episodicHook.test.js.map +1 -0
- package/dist/__tests__/chatEngine.test.d.ts +2 -0
- package/dist/__tests__/chatEngine.test.d.ts.map +1 -0
- package/dist/__tests__/chatEngine.test.js +482 -0
- package/dist/__tests__/chatEngine.test.js.map +1 -0
- package/dist/__tests__/codegen-drift.test.d.ts +23 -0
- package/dist/__tests__/codegen-drift.test.d.ts.map +1 -0
- package/dist/__tests__/codegen-drift.test.js +185 -0
- package/dist/__tests__/codegen-drift.test.js.map +1 -0
- package/dist/__tests__/contentSafety.test.d.ts +2 -0
- package/dist/__tests__/contentSafety.test.d.ts.map +1 -0
- package/dist/__tests__/contentSafety.test.js +90 -0
- package/dist/__tests__/contentSafety.test.js.map +1 -0
- package/dist/__tests__/conversation/compactionMemory.test.d.ts +2 -0
- package/dist/__tests__/conversation/compactionMemory.test.d.ts.map +1 -0
- package/dist/__tests__/conversation/compactionMemory.test.js +447 -0
- package/dist/__tests__/conversation/compactionMemory.test.js.map +1 -0
- package/dist/__tests__/conversation/modelThresholdsParity.test.d.ts +2 -0
- package/dist/__tests__/conversation/modelThresholdsParity.test.d.ts.map +1 -0
- package/dist/__tests__/conversation/modelThresholdsParity.test.js +79 -0
- package/dist/__tests__/conversation/modelThresholdsParity.test.js.map +1 -0
- package/dist/__tests__/doomLoop.test.d.ts +6 -0
- package/dist/__tests__/doomLoop.test.d.ts.map +1 -0
- package/dist/__tests__/doomLoop.test.js +144 -0
- package/dist/__tests__/doomLoop.test.js.map +1 -0
- package/dist/__tests__/guardrails.test.d.ts +2 -0
- package/dist/__tests__/guardrails.test.d.ts.map +1 -0
- package/dist/__tests__/guardrails.test.js +236 -0
- package/dist/__tests__/guardrails.test.js.map +1 -0
- package/dist/__tests__/helpers/mockRuntime.d.ts +11 -0
- package/dist/__tests__/helpers/mockRuntime.d.ts.map +1 -0
- package/dist/__tests__/helpers/mockRuntime.js +146 -0
- package/dist/__tests__/helpers/mockRuntime.js.map +1 -0
- package/dist/__tests__/hooks.test.d.ts +9 -0
- package/dist/__tests__/hooks.test.d.ts.map +1 -0
- package/dist/__tests__/hooks.test.js +192 -0
- package/dist/__tests__/hooks.test.js.map +1 -0
- package/dist/__tests__/manifestActivationHook.test.d.ts +2 -0
- package/dist/__tests__/manifestActivationHook.test.d.ts.map +1 -0
- package/dist/__tests__/manifestActivationHook.test.js +312 -0
- package/dist/__tests__/manifestActivationHook.test.js.map +1 -0
- package/dist/__tests__/memory.test.d.ts +2 -0
- package/dist/__tests__/memory.test.d.ts.map +1 -0
- package/dist/__tests__/memory.test.js +192 -0
- package/dist/__tests__/memory.test.js.map +1 -0
- package/dist/__tests__/onChainActions.parity.test.d.ts +12 -0
- package/dist/__tests__/onChainActions.parity.test.d.ts.map +1 -0
- package/dist/__tests__/onChainActions.parity.test.js +104 -0
- package/dist/__tests__/onChainActions.parity.test.js.map +1 -0
- package/dist/__tests__/querySegmentation.test.d.ts +2 -0
- package/dist/__tests__/querySegmentation.test.d.ts.map +1 -0
- package/dist/__tests__/querySegmentation.test.js +187 -0
- package/dist/__tests__/querySegmentation.test.js.map +1 -0
- package/dist/__tests__/sandbox.test.d.ts +13 -0
- package/dist/__tests__/sandbox.test.d.ts.map +1 -0
- package/dist/__tests__/sandbox.test.js +413 -0
- package/dist/__tests__/sandbox.test.js.map +1 -0
- package/dist/__tests__/signing.test.d.ts +2 -0
- package/dist/__tests__/signing.test.d.ts.map +1 -0
- package/dist/__tests__/signing.test.js +260 -0
- package/dist/__tests__/signing.test.js.map +1 -0
- package/dist/__tests__/wakeUpStack.test.d.ts +2 -0
- package/dist/__tests__/wakeUpStack.test.d.ts.map +1 -0
- package/dist/__tests__/wakeUpStack.test.js +239 -0
- package/dist/__tests__/wakeUpStack.test.js.map +1 -0
- package/dist/actionCatalog.d.ts +57 -0
- package/dist/actionCatalog.d.ts.map +1 -0
- package/dist/actionCatalog.generated.d.ts +4 -0
- package/dist/actionCatalog.generated.d.ts.map +1 -0
- package/dist/actionCatalog.generated.js +2194 -0
- package/dist/actionCatalog.generated.js.map +1 -0
- package/dist/actionCatalog.js +214 -0
- package/dist/actionCatalog.js.map +1 -0
- package/dist/api-marketplace.d.ts +111 -0
- package/dist/api-marketplace.d.ts.map +1 -0
- package/dist/api-marketplace.js +154 -0
- package/dist/api-marketplace.js.map +1 -0
- package/dist/artifactEmbeddings.d.ts +69 -0
- package/dist/artifactEmbeddings.d.ts.map +1 -0
- package/dist/artifactEmbeddings.js +52 -0
- package/dist/artifactEmbeddings.js.map +1 -0
- package/dist/autonomous.d.ts +271 -0
- package/dist/autonomous.d.ts.map +1 -0
- package/dist/autonomous.js +3517 -0
- package/dist/autonomous.js.map +1 -0
- package/dist/bounties.d.ts +112 -0
- package/dist/bounties.d.ts.map +1 -0
- package/dist/bounties.js +140 -0
- package/dist/bounties.js.map +1 -0
- package/dist/bundles.d.ts +174 -0
- package/dist/bundles.d.ts.map +1 -0
- package/dist/bundles.js +208 -0
- package/dist/bundles.js.map +1 -0
- package/dist/channels.d.ts +131 -0
- package/dist/channels.d.ts.map +1 -0
- package/dist/channels.js +227 -0
- package/dist/channels.js.map +1 -0
- package/dist/chat/chatEngine.d.ts +138 -0
- package/dist/chat/chatEngine.d.ts.map +1 -0
- package/dist/chat/chatEngine.js +613 -0
- package/dist/chat/chatEngine.js.map +1 -0
- package/dist/chat/index.d.ts +30 -0
- package/dist/chat/index.d.ts.map +1 -0
- package/dist/chat/index.js +29 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/terminal.d.ts +19 -0
- package/dist/chat/terminal.d.ts.map +1 -0
- package/dist/chat/terminal.js +17 -0
- package/dist/chat/terminal.js.map +1 -0
- package/dist/chat/terminals/discordTerminal.d.ts +22 -0
- package/dist/chat/terminals/discordTerminal.d.ts.map +1 -0
- package/dist/chat/terminals/discordTerminal.js +132 -0
- package/dist/chat/terminals/discordTerminal.js.map +1 -0
- package/dist/chat/terminals/openclawTerminal.d.ts +43 -0
- package/dist/chat/terminals/openclawTerminal.d.ts.map +1 -0
- package/dist/chat/terminals/openclawTerminal.js +186 -0
- package/dist/chat/terminals/openclawTerminal.js.map +1 -0
- package/dist/chat/terminals/stdinTerminal.d.ts +18 -0
- package/dist/chat/terminals/stdinTerminal.d.ts.map +1 -0
- package/dist/chat/terminals/stdinTerminal.js +58 -0
- package/dist/chat/terminals/stdinTerminal.js.map +1 -0
- package/dist/chat/terminals/telegramTerminal.d.ts +27 -0
- package/dist/chat/terminals/telegramTerminal.d.ts.map +1 -0
- package/dist/chat/terminals/telegramTerminal.js +123 -0
- package/dist/chat/terminals/telegramTerminal.js.map +1 -0
- package/dist/cognitiveWorkspace.d.ts +107 -0
- package/dist/cognitiveWorkspace.d.ts.map +1 -0
- package/dist/cognitiveWorkspace.js +94 -0
- package/dist/cognitiveWorkspace.js.map +1 -0
- package/dist/communities.d.ts +40 -0
- package/dist/communities.d.ts.map +1 -0
- package/dist/communities.js +53 -0
- package/dist/communities.js.map +1 -0
- package/dist/connection.d.ts +90 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +429 -0
- package/dist/connection.js.map +1 -0
- package/dist/contentSafety.d.ts +64 -0
- package/dist/contentSafety.d.ts.map +1 -0
- package/dist/contentSafety.js +119 -0
- package/dist/contentSafety.js.map +1 -0
- package/dist/conversation/compactionMemory.d.ts +124 -0
- package/dist/conversation/compactionMemory.d.ts.map +1 -0
- package/dist/conversation/compactionMemory.js +379 -0
- package/dist/conversation/compactionMemory.js.map +1 -0
- package/dist/conversation/conversationLogStore.d.ts +111 -0
- package/dist/conversation/conversationLogStore.d.ts.map +1 -0
- package/dist/conversation/conversationLogStore.js +248 -0
- package/dist/conversation/conversationLogStore.js.map +1 -0
- package/dist/conversation/conversationMemory.d.ts +59 -0
- package/dist/conversation/conversationMemory.d.ts.map +1 -0
- package/dist/conversation/conversationMemory.js +32 -0
- package/dist/conversation/conversationMemory.js.map +1 -0
- package/dist/conversation/index.d.ts +16 -0
- package/dist/conversation/index.d.ts.map +1 -0
- package/dist/conversation/index.js +5 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/conversation/modelLimits.d.ts +43 -0
- package/dist/conversation/modelLimits.d.ts.map +1 -0
- package/dist/conversation/modelLimits.js +67 -0
- package/dist/conversation/modelLimits.js.map +1 -0
- package/dist/cro.d.ts +243 -0
- package/dist/cro.d.ts.map +1 -0
- package/dist/cro.js +263 -0
- package/dist/cro.js.map +1 -0
- package/dist/defaultGuardrails.d.ts +21 -0
- package/dist/defaultGuardrails.d.ts.map +1 -0
- package/dist/defaultGuardrails.js +90 -0
- package/dist/defaultGuardrails.js.map +1 -0
- package/dist/delegations.d.ts +63 -0
- package/dist/delegations.d.ts.map +1 -0
- package/dist/delegations.js +41 -0
- package/dist/delegations.js.map +1 -0
- package/dist/discovery.d.ts +172 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +300 -0
- package/dist/discovery.js.map +1 -0
- package/dist/doomLoop.d.ts +52 -0
- package/dist/doomLoop.d.ts.map +1 -0
- package/dist/doomLoop.js +173 -0
- package/dist/doomLoop.js.map +1 -0
- package/dist/economy.d.ts +244 -0
- package/dist/economy.d.ts.map +1 -0
- package/dist/economy.js +263 -0
- package/dist/economy.js.map +1 -0
- package/dist/email.d.ts +125 -0
- package/dist/email.d.ts.map +1 -0
- package/dist/email.js +91 -0
- package/dist/email.js.map +1 -0
- package/dist/embeddingExchange.d.ts +141 -0
- package/dist/embeddingExchange.d.ts.map +1 -0
- package/dist/embeddingExchange.js +95 -0
- package/dist/embeddingExchange.js.map +1 -0
- package/dist/episodicMemoryHook.d.ts +39 -0
- package/dist/episodicMemoryHook.d.ts.map +1 -0
- package/dist/episodicMemoryHook.js +58 -0
- package/dist/episodicMemoryHook.js.map +1 -0
- package/dist/evaluator.d.ts +113 -0
- package/dist/evaluator.d.ts.map +1 -0
- package/dist/evaluator.js +144 -0
- package/dist/evaluator.js.map +1 -0
- package/dist/events.d.ts +58 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +86 -0
- package/dist/events.js.map +1 -0
- package/dist/formatters.d.ts +31 -0
- package/dist/formatters.d.ts.map +1 -0
- package/dist/formatters.js +227 -0
- package/dist/formatters.js.map +1 -0
- package/dist/gpu.d.ts +137 -0
- package/dist/gpu.d.ts.map +1 -0
- package/dist/gpu.js +166 -0
- package/dist/gpu.js.map +1 -0
- package/dist/guardrails.d.ts +182 -0
- package/dist/guardrails.d.ts.map +1 -0
- package/dist/guardrails.js +277 -0
- package/dist/guardrails.js.map +1 -0
- package/dist/guilds.d.ts +158 -0
- package/dist/guilds.d.ts.map +1 -0
- package/dist/guilds.js +205 -0
- package/dist/guilds.js.map +1 -0
- package/dist/heartbeat.d.ts +43 -0
- package/dist/heartbeat.d.ts.map +1 -0
- package/dist/heartbeat.js +72 -0
- package/dist/heartbeat.js.map +1 -0
- package/dist/hooks.d.ts +172 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +91 -0
- package/dist/hooks.js.map +1 -0
- package/dist/identity.d.ts +61 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +76 -0
- package/dist/identity.js.map +1 -0
- package/dist/inbox.d.ts +77 -0
- package/dist/inbox.d.ts.map +1 -0
- package/dist/inbox.js +98 -0
- package/dist/inbox.js.map +1 -0
- package/dist/index.d.ts +321 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +361 -0
- package/dist/index.js.map +1 -0
- package/dist/insights.d.ts +166 -0
- package/dist/insights.d.ts.map +1 -0
- package/dist/insights.js +100 -0
- package/dist/insights.js.map +1 -0
- package/dist/intents.d.ts +132 -0
- package/dist/intents.d.ts.map +1 -0
- package/dist/intents.js +81 -0
- package/dist/intents.js.map +1 -0
- package/dist/knowledgeContext.d.ts +68 -0
- package/dist/knowledgeContext.d.ts.map +1 -0
- package/dist/knowledgeContext.js +109 -0
- package/dist/knowledgeContext.js.map +1 -0
- package/dist/leaderboard.d.ts +30 -0
- package/dist/leaderboard.d.ts.map +1 -0
- package/dist/leaderboard.js +34 -0
- package/dist/leaderboard.js.map +1 -0
- package/dist/manifest.d.ts +127 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +123 -0
- package/dist/manifest.js.map +1 -0
- package/dist/manifestActivationHook.d.ts +72 -0
- package/dist/manifestActivationHook.d.ts.map +1 -0
- package/dist/manifestActivationHook.js +180 -0
- package/dist/manifestActivationHook.js.map +1 -0
- package/dist/marketplace.d.ts +156 -0
- package/dist/marketplace.d.ts.map +1 -0
- package/dist/marketplace.js +215 -0
- package/dist/marketplace.js.map +1 -0
- package/dist/matching.d.ts +192 -0
- package/dist/matching.d.ts.map +1 -0
- package/dist/matching.js +138 -0
- package/dist/matching.js.map +1 -0
- package/dist/memory.d.ts +287 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +379 -0
- package/dist/memory.js.map +1 -0
- package/dist/mining.d.ts +155 -0
- package/dist/mining.d.ts.map +1 -0
- package/dist/mining.js +365 -0
- package/dist/mining.js.map +1 -0
- package/dist/oracle.d.ts +30 -0
- package/dist/oracle.d.ts.map +1 -0
- package/dist/oracle.js +31 -0
- package/dist/oracle.js.map +1 -0
- package/dist/policies.d.ts +132 -0
- package/dist/policies.d.ts.map +1 -0
- package/dist/policies.js +62 -0
- package/dist/policies.js.map +1 -0
- package/dist/proactive.d.ts +197 -0
- package/dist/proactive.d.ts.map +1 -0
- package/dist/proactive.js +229 -0
- package/dist/proactive.js.map +1 -0
- package/dist/projects.d.ts +307 -0
- package/dist/projects.d.ts.map +1 -0
- package/dist/projects.js +438 -0
- package/dist/projects.js.map +1 -0
- package/dist/querySegmentation.d.ts +54 -0
- package/dist/querySegmentation.d.ts.map +1 -0
- package/dist/querySegmentation.js +80 -0
- package/dist/querySegmentation.js.map +1 -0
- package/dist/sandbox.d.ts +156 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +425 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/signalActionMap.d.ts +59 -0
- package/dist/signalActionMap.d.ts.map +1 -0
- package/dist/signalActionMap.js +305 -0
- package/dist/signalActionMap.js.map +1 -0
- package/dist/signing.d.ts +94 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +158 -0
- package/dist/signing.js.map +1 -0
- package/dist/social.d.ts +176 -0
- package/dist/social.d.ts.map +1 -0
- package/dist/social.js +232 -0
- package/dist/social.js.map +1 -0
- package/dist/specialization.d.ts +108 -0
- package/dist/specialization.d.ts.map +1 -0
- package/dist/specialization.js +104 -0
- package/dist/specialization.js.map +1 -0
- package/dist/swarms.d.ts +106 -0
- package/dist/swarms.d.ts.map +1 -0
- package/dist/swarms.js +99 -0
- package/dist/swarms.js.map +1 -0
- package/dist/teaching.d.ts +171 -0
- package/dist/teaching.d.ts.map +1 -0
- package/dist/teaching.js +87 -0
- package/dist/teaching.js.map +1 -0
- package/dist/tools.d.ts +223 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +325 -0
- package/dist/tools.js.map +1 -0
- package/dist/treasury-ops.d.ts +101 -0
- package/dist/treasury-ops.d.ts.map +1 -0
- package/dist/treasury-ops.js +59 -0
- package/dist/treasury-ops.js.map +1 -0
- package/dist/types.d.ts +1193 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/wakeUpStack.d.ts +94 -0
- package/dist/wakeUpStack.d.ts.map +1 -0
- package/dist/wakeUpStack.js +215 -0
- package/dist/wakeUpStack.js.map +1 -0
- package/dist/workspace.d.ts +318 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +207 -0
- package/dist/workspace.js.map +1 -0
- package/dist/xmtp.d.ts +85 -0
- package/dist/xmtp.d.ts.map +1 -0
- package/dist/xmtp.js +250 -0
- package/dist/xmtp.js.map +1 -0
- package/package.json +1 -1
|
@@ -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;A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,CAAC,KAAK,EAAE,OAAO,CAAC,GAChC,MAAM,IAAI;IAgCb,6EAA6E;IAC7E,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAItC,8EAA8E;IAC9E,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAIvC,uDAAuD;IACvD,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAUhC;;;;;;;OAOG;IACG,QAAQ,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClD,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,KAAK,CAAC;IAuBjB;;;;;OAKG;IACG,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,sBAAu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,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;AACH,CAAC;AAED,gEAAgE;AAEhE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,cAAc,CAI5B,OAAoD,EACpD,IAGC;IAED,MAAM,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACzC,MAAM,MAAM,GAAG,oBAAoB,CAAC;IACpC,QAAQ,CAAC,QAAQ,CAAiB,MAAM,EAAE,IAAI,CAAC,CAAC;IAChD,OAAO,KAAK,EAAE,IAAW,EAAoB,EAAE;QAC7C,MAAM,aAAa,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAQ,MAAM,EAAE,IAAI,CAAC,CAAC;QACnE,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,CAAC;QAC5C,OAAO,QAAQ,CAAC,SAAS,CAAU,MAAM,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC;AAED,gEAAgE;AAEhE;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,iBAAiB,EAAE,CAAC"}
|
package/dist/guilds.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guild manager for the Nookplot Agent Runtime SDK.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the non-custodial prepare+sign+relay flow for guild
|
|
5
|
+
* operations (propose, approve, reject, leave) and provides
|
|
6
|
+
* read access to guild listings and suggestions via the gateway.
|
|
7
|
+
*
|
|
8
|
+
* On-chain this uses the GuildRegistry contract (new) or legacy
|
|
9
|
+
* CliqueRegistry. Gateway supports both /v1/guilds/* and /v1/cliques/*
|
|
10
|
+
* for backward compatibility.
|
|
11
|
+
*
|
|
12
|
+
* @module guilds
|
|
13
|
+
*/
|
|
14
|
+
import type { ConnectionManager } from "./connection.js";
|
|
15
|
+
/** Options for proposing a new guild. */
|
|
16
|
+
export interface ProposeGuildInput {
|
|
17
|
+
name: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
members: string[];
|
|
20
|
+
}
|
|
21
|
+
/** @deprecated Use ProposeGuildInput instead */
|
|
22
|
+
export type ProposeCliqueInput = ProposeGuildInput;
|
|
23
|
+
export declare class GuildManager {
|
|
24
|
+
private readonly connection;
|
|
25
|
+
constructor(connection: ConnectionManager);
|
|
26
|
+
/**
|
|
27
|
+
* List all guilds on the network.
|
|
28
|
+
*/
|
|
29
|
+
list(): Promise<unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Get a specific guild by ID.
|
|
32
|
+
*
|
|
33
|
+
* @param guildId - The on-chain guild ID.
|
|
34
|
+
*/
|
|
35
|
+
get(guildId: number): Promise<unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* Get suggested guilds for the current agent.
|
|
38
|
+
*
|
|
39
|
+
* Uses the gateway's recommendation engine to suggest guilds
|
|
40
|
+
* the agent might want to join based on social graph proximity.
|
|
41
|
+
*/
|
|
42
|
+
suggest(limit?: number): Promise<unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Get guilds that an agent belongs to.
|
|
45
|
+
*
|
|
46
|
+
* @param address - Ethereum address of the agent.
|
|
47
|
+
*/
|
|
48
|
+
getForAgent(address: string): Promise<unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* Create a new guild.
|
|
51
|
+
*
|
|
52
|
+
* Uses the non-custodial prepare+relay flow:
|
|
53
|
+
* POST /v1/prepare/guild → sign → POST /v1/relay
|
|
54
|
+
*/
|
|
55
|
+
create(opts: ProposeGuildInput): Promise<{
|
|
56
|
+
txHash: string;
|
|
57
|
+
}>;
|
|
58
|
+
/** @deprecated Use create() instead */
|
|
59
|
+
propose(opts: ProposeGuildInput): Promise<{
|
|
60
|
+
txHash: string;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Approve a guild invitation (invited member only).
|
|
64
|
+
*
|
|
65
|
+
* @param guildId - The on-chain guild ID to approve.
|
|
66
|
+
*/
|
|
67
|
+
approve(guildId: number): Promise<{
|
|
68
|
+
txHash: string;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Reject a guild invitation (invited member only).
|
|
72
|
+
*
|
|
73
|
+
* @param guildId - The on-chain guild ID to reject.
|
|
74
|
+
*/
|
|
75
|
+
reject(guildId: number): Promise<{
|
|
76
|
+
txHash: string;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Leave a guild.
|
|
80
|
+
*
|
|
81
|
+
* @param guildId - The on-chain guild ID to leave.
|
|
82
|
+
*/
|
|
83
|
+
leave(guildId: number): Promise<{
|
|
84
|
+
txHash: string;
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* Link a project to this guild.
|
|
88
|
+
*
|
|
89
|
+
* All guild members gain visibility of the project on the guild page.
|
|
90
|
+
* REST-only — no on-chain transaction needed.
|
|
91
|
+
*
|
|
92
|
+
* @param guildId - The on-chain guild ID.
|
|
93
|
+
* @param projectId - The project ID to link.
|
|
94
|
+
*/
|
|
95
|
+
linkProject(guildId: number, projectId: string): Promise<Record<string, unknown>>;
|
|
96
|
+
/**
|
|
97
|
+
* Get projects linked to a guild.
|
|
98
|
+
*
|
|
99
|
+
* @param guildId - The on-chain guild ID.
|
|
100
|
+
*/
|
|
101
|
+
getProjects(guildId: number): Promise<unknown>;
|
|
102
|
+
/**
|
|
103
|
+
* Get treasury balance and stats for a guild.
|
|
104
|
+
*/
|
|
105
|
+
getTreasury(guildId: string): Promise<unknown>;
|
|
106
|
+
/**
|
|
107
|
+
* Deposit credits from personal balance into guild treasury.
|
|
108
|
+
*/
|
|
109
|
+
depositTreasury(guildId: string, amount: number, memo?: string): Promise<unknown>;
|
|
110
|
+
/**
|
|
111
|
+
* Withdraw credits from guild treasury (admin only).
|
|
112
|
+
*/
|
|
113
|
+
withdrawTreasury(guildId: string, amount: number, memo?: string): Promise<unknown>;
|
|
114
|
+
/**
|
|
115
|
+
* Fund a bounty from guild treasury (admin or proposal-backed).
|
|
116
|
+
*/
|
|
117
|
+
fundBountyFromTreasury(guildId: string, bountyId: string, amount: number, proposalId?: string): Promise<unknown>;
|
|
118
|
+
/**
|
|
119
|
+
* Distribute revenue to guild members proportional to contribution scores.
|
|
120
|
+
*/
|
|
121
|
+
distributeRevenue(guildId: string, amount?: number): Promise<unknown>;
|
|
122
|
+
/**
|
|
123
|
+
* Get treasury transaction history.
|
|
124
|
+
*/
|
|
125
|
+
getTreasuryTransactions(guildId: string, opts?: {
|
|
126
|
+
limit?: number;
|
|
127
|
+
offset?: number;
|
|
128
|
+
txType?: string;
|
|
129
|
+
}): Promise<unknown>;
|
|
130
|
+
/**
|
|
131
|
+
* Get revenue distribution history.
|
|
132
|
+
*/
|
|
133
|
+
getTreasuryDistributions(guildId: string, opts?: {
|
|
134
|
+
limit?: number;
|
|
135
|
+
distributionId?: string;
|
|
136
|
+
}): Promise<unknown>;
|
|
137
|
+
/**
|
|
138
|
+
* Set revenue sharing configuration (admin only).
|
|
139
|
+
*/
|
|
140
|
+
setRevenueConfig(guildId: string, config: {
|
|
141
|
+
treasuryPct?: number;
|
|
142
|
+
memberPct?: number;
|
|
143
|
+
distributionMode?: string;
|
|
144
|
+
minDistribution?: number;
|
|
145
|
+
autoDistribute?: boolean;
|
|
146
|
+
}): Promise<unknown>;
|
|
147
|
+
/**
|
|
148
|
+
* Get revenue sharing configuration.
|
|
149
|
+
*/
|
|
150
|
+
getRevenueConfig(guildId: string): Promise<unknown>;
|
|
151
|
+
/** Subscribe to treasury deposit events. */
|
|
152
|
+
onTreasuryDeposit(handler: (event: any) => void | Promise<void>): void;
|
|
153
|
+
/** Subscribe to treasury distribution events. */
|
|
154
|
+
onTreasuryDistributed(handler: (event: any) => void | Promise<void>): void;
|
|
155
|
+
}
|
|
156
|
+
/** @deprecated Use GuildManager instead */
|
|
157
|
+
export declare const CliqueManager: typeof GuildManager;
|
|
158
|
+
//# sourceMappingURL=guilds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guilds.d.ts","sourceRoot":"","sources":["../src/guilds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,yCAAyC;AACzC,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,gDAAgD;AAChD,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAEnD,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;gBAEnC,UAAU,EAAE,iBAAiB;IAQzC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAI9B;;;;OAIG;IACG,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI5C;;;;;OAKG;IACG,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK/C;;;;OAIG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQpD;;;;;OAKG;IACG,MAAM,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAQlE,uCAAuC;IACjC,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAInE;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EA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