@sonnevhq/gate 0.0.0-stage → 0.1.0
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/LICENSE +202 -0
- package/README.md +110 -2
- package/dist/adapters/index.d.ts +100 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +161 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/errors.d.ts +53 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +70 -0
- package/dist/errors.js.map +1 -0
- package/dist/gate.d.ts +138 -0
- package/dist/gate.d.ts.map +1 -0
- package/dist/gate.js +308 -0
- package/dist/gate.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +96 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +55 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Sonnev
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,111 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sonnevhq/gate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Deterministic Execution Barrier & Tamper-Evident Audit Ledger for Autonomous AI Agents.**
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
`@sonnevhq/gate` is the official TypeScript SDK for **SONNEV Gate**. It intercepts tool execution calls from autonomous LLM agents (LangChain, OpenAI Agents, CrewAI, Vercel AI SDK), evaluates arguments against deterministic policy rules, halts critical actions for human-in-the-loop authorization, and records every request in a tamper-evident SHA-256 hash-chained audit ledger.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Key Capabilities
|
|
12
|
+
|
|
13
|
+
- **Fail-Closed Execution Barrier**: Any network partition, policy mismatch, or rate limit fails closed. The tool never executes unless explicitly allowed.
|
|
14
|
+
- **Human-in-the-Loop Approval Queue**: High-value disbursements, database mutations, or sensitive API calls pause until signed off by an authorized operator in the Gate Dashboard.
|
|
15
|
+
- **Client Boundary Interception & Gateway Proxy Modes**: Wrap functions in-process for sub-millisecond evaluation, or route credentials behind Gate Proxy so autonomous agents never touch raw downstream secrets.
|
|
16
|
+
- **Customer-Defined Verification Hooks**: Inject secondary confirmation logic (e.g. verifying database state, bank webhooks, or balance thresholds) before reporting completion.
|
|
17
|
+
- **Tamper-Evident SHA-256 Audit Ledger**: Every action, policy evaluation, and operator decision is recorded in an unbroken cryptographic hash chain.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @sonnevhq/gate
|
|
25
|
+
# or
|
|
26
|
+
pnpm add @sonnevhq/gate
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Quickstart
|
|
32
|
+
|
|
33
|
+
### 1. Initialize the Gate Client
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { SonnevGate } from "@sonnevhq/gate";
|
|
37
|
+
|
|
38
|
+
const gate = new SonnevGate({
|
|
39
|
+
endpoint: process.env.SONNEV_GATE_URL || "https://gate.sonnev.com",
|
|
40
|
+
apiKey: process.env.SONNEV_GATE_API_KEY, // Agent API Key starting with sg_...
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 2. Guard Tools with `gate.wrap`
|
|
45
|
+
|
|
46
|
+
Wrap your raw tool execution logic with Gate's deterministic wrapper:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
// Define your underlying tool logic (e.g., Stripe, Twilio, SQL, Cloud APIs)
|
|
50
|
+
async function executeStripeTransfer(params: {
|
|
51
|
+
amount: number;
|
|
52
|
+
recipient: string;
|
|
53
|
+
}) {
|
|
54
|
+
return await stripe.transfers.create({
|
|
55
|
+
amount: params.amount,
|
|
56
|
+
currency: "usd",
|
|
57
|
+
destination: params.recipient,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Wrap with Gate fail-closed barrier
|
|
62
|
+
export const sendPaymentTool = gate.wrap(
|
|
63
|
+
executeStripeTransfer,
|
|
64
|
+
{
|
|
65
|
+
tool: "send_payment",
|
|
66
|
+
action: "transfer",
|
|
67
|
+
pollIntervalMs: 2000, // Polling frequency while pending operator approval
|
|
68
|
+
approvalTimeoutMs: 15 * 60 * 1000, // 15-minute timeout window before auto-rejecting
|
|
69
|
+
// Optional: Customer-defined verification hook
|
|
70
|
+
verify: async (output) => {
|
|
71
|
+
return Boolean(output && output.id);
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// Agent invokes the guarded tool normally:
|
|
77
|
+
const result = await sendPaymentTool({
|
|
78
|
+
amount: 250, // <= $500 executes immediately according to policy
|
|
79
|
+
recipient: "acct_1234567890",
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## What Happens When Human Approval is Required?
|
|
86
|
+
|
|
87
|
+
When an action exceeds automated thresholds (e.g., wiring `$2,850` when the policy ceiling is `$500`):
|
|
88
|
+
|
|
89
|
+
1. **Gate Gateway Halts Execution**: The gateway records the request and marks it `pending_approval`.
|
|
90
|
+
2. **Notification Dispatched**: Real-time notifications (Resend Email & Webhooks) alert operators.
|
|
91
|
+
3. **SDK Polls**: The `sendPaymentTool` promise pauses execution, periodically polling Gate until decision.
|
|
92
|
+
4. **Operator Approves or Rejects**:
|
|
93
|
+
- If **Approved**: The promise resolves and executes the underlying function.
|
|
94
|
+
- If **Rejected or Expired**: The promise throws an `ApprovalRejectedError` or `ApprovalTimeoutError` and execution is cancelled.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Direct Gateway API Inspection
|
|
99
|
+
|
|
100
|
+
You can also interact directly with the Gateway API if you are building custom language adapters:
|
|
101
|
+
|
|
102
|
+
- `POST /api/v1/actions/check`: Check action and evaluate against policies.
|
|
103
|
+
- `POST /api/v1/actions/:id/result`: Report execution output and duration.
|
|
104
|
+
- `GET /api/v1/actions/:id`: Check status of pending approval.
|
|
105
|
+
- `GET /api/v1/audit/verify`: Verify the integrity of the SHA-256 hash chain.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
Apache-2.0 © [SONNEV](https://sonnev.com)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { SonnevGate } from "../gate.js";
|
|
2
|
+
import type { WrapOptions } from "../types.js";
|
|
3
|
+
import type { SignedReceipt } from "@sonnevhq/core";
|
|
4
|
+
/**
|
|
5
|
+
* Adapter for Vercel AI SDK tool definitions (ai/tool).
|
|
6
|
+
* Wraps the execute function with policy enforcement.
|
|
7
|
+
*/
|
|
8
|
+
export declare function wrapVercelAITool<TParams, TResult, TToolDef extends {
|
|
9
|
+
execute?: (params: TParams) => Promise<TResult>;
|
|
10
|
+
}>(gate: SonnevGate, toolDef: TToolDef, options: Omit<WrapOptions<TParams, TResult>, "tool"> & {
|
|
11
|
+
tool?: string;
|
|
12
|
+
}): TToolDef;
|
|
13
|
+
/**
|
|
14
|
+
* Adapter for OpenAI Function Calling tool format.
|
|
15
|
+
*/
|
|
16
|
+
export interface OpenAIToolDefinition {
|
|
17
|
+
type: "function";
|
|
18
|
+
function: {
|
|
19
|
+
name: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
parameters?: Record<string, unknown>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare function wrapOpenAITool<TParams = any, TResult = any>(gate: SonnevGate, toolDef: OpenAIToolDefinition, executeFn: (params: TParams) => Promise<TResult> | TResult, options?: Omit<WrapOptions<TParams, TResult>, "tool">): OpenAIToolDefinition & {
|
|
25
|
+
execute: (params: TParams) => Promise<TResult>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Adapter for Anthropic Claude tool use format.
|
|
29
|
+
*/
|
|
30
|
+
export interface AnthropicToolDefinition {
|
|
31
|
+
name: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
input_schema?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
export declare function wrapAnthropicTool<TParams = any, TResult = any>(gate: SonnevGate, toolDef: AnthropicToolDefinition, executeFn: (params: TParams) => Promise<TResult> | TResult, options?: Omit<WrapOptions<TParams, TResult>, "tool">): AnthropicToolDefinition & {
|
|
36
|
+
execute: (params: TParams) => Promise<TResult>;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Adapter for OpenAI Agents SDK (Swarm / Agents API) tool definition format.
|
|
40
|
+
*/
|
|
41
|
+
export interface OpenAIAgentToolDefinition<TParams = any, TResult = any> {
|
|
42
|
+
name: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
parameters?: Record<string, unknown>;
|
|
45
|
+
execute?: (params: TParams, context?: any) => Promise<TResult> | TResult;
|
|
46
|
+
fn?: (params: TParams, context?: any) => Promise<TResult> | TResult;
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
export declare function wrapOpenAIAgentTool<TParams = any, TResult = any, TDef extends OpenAIAgentToolDefinition<TParams, TResult> = any>(gate: SonnevGate, toolDef: TDef, options?: Omit<WrapOptions<TParams, TResult>, "tool"> & {
|
|
50
|
+
tool?: string;
|
|
51
|
+
}): TDef;
|
|
52
|
+
/**
|
|
53
|
+
* Pre-execution guardrail for OpenAI Agents SDK.
|
|
54
|
+
*/
|
|
55
|
+
export declare function createOpenAIAgentGuardrail(gate: SonnevGate): (context: {
|
|
56
|
+
toolName: string;
|
|
57
|
+
args: Record<string, unknown>;
|
|
58
|
+
}) => Promise<import("../types.js").CheckActionResponse>;
|
|
59
|
+
/**
|
|
60
|
+
* Adapter for LangGraph / LangChain JS StructuredTool format.
|
|
61
|
+
*/
|
|
62
|
+
export interface LangGraphToolDefinition<TParams = any, TResult = any> {
|
|
63
|
+
name: string;
|
|
64
|
+
description: string;
|
|
65
|
+
schema?: unknown;
|
|
66
|
+
args_schema?: unknown;
|
|
67
|
+
func?: (params: TParams, ...args: any[]) => Promise<TResult> | TResult;
|
|
68
|
+
invoke?: (input: TParams, config?: any) => Promise<TResult> | TResult;
|
|
69
|
+
_call?: (params: TParams, ...args: any[]) => Promise<TResult> | TResult;
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}
|
|
72
|
+
export declare function wrapLangGraphTool<TParams = any, TResult = any, TTool extends LangGraphToolDefinition<TParams, TResult> = any>(gate: SonnevGate, tool: TTool, options?: Omit<WrapOptions<TParams, TResult>, "tool"> & {
|
|
73
|
+
tool?: string;
|
|
74
|
+
}): TTool;
|
|
75
|
+
/**
|
|
76
|
+
* Claude Code (Anthropic CLI) Tool Execution Interceptor Hook.
|
|
77
|
+
*/
|
|
78
|
+
export interface ClaudeCodeToolInput {
|
|
79
|
+
tool: string;
|
|
80
|
+
input: Record<string, unknown>;
|
|
81
|
+
context?: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
export interface ClaudeCodeHookResult {
|
|
84
|
+
decision: "allow" | "deny" | "pending_approval";
|
|
85
|
+
allow: boolean;
|
|
86
|
+
reason?: string;
|
|
87
|
+
actionId?: string;
|
|
88
|
+
receipt?: SignedReceipt;
|
|
89
|
+
}
|
|
90
|
+
export declare function createClaudeCodeHook(gate: SonnevGate, options?: {
|
|
91
|
+
approvalTimeoutMs?: number;
|
|
92
|
+
}): (toolCall: ClaudeCodeToolInput) => Promise<ClaudeCodeHookResult>;
|
|
93
|
+
/**
|
|
94
|
+
* Executes a tool wrapped with the Claude Code governance hook and automatically
|
|
95
|
+
* reports outcome telemetry to SONNEV Gate.
|
|
96
|
+
*/
|
|
97
|
+
export declare function runWithClaudeCodeHook<TResult = any>(gate: SonnevGate, toolCall: ClaudeCodeToolInput, toolFn: (input: Record<string, unknown>) => Promise<TResult> | TResult, options?: {
|
|
98
|
+
approvalTimeoutMs?: number;
|
|
99
|
+
}): Promise<TResult>;
|
|
100
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,SAAS;IAAE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE,EACrH,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACvE,QAAQ,CAeV;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAA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qB,CAAC,OAAO,GAAG,GAAG,EACvD,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,mBAAmB,EAC7B,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,EACtE,OAAO,CAAC,EAAE;IAAE,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAE,GACvC,OAAO,CAAC,OAAO,CAAC,CAgClB"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { PolicyDeniedError } from "../errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Adapter for Vercel AI SDK tool definitions (ai/tool).
|
|
4
|
+
* Wraps the execute function with policy enforcement.
|
|
5
|
+
*/
|
|
6
|
+
export function wrapVercelAITool(gate, toolDef, options) {
|
|
7
|
+
if (!toolDef.execute) {
|
|
8
|
+
return toolDef;
|
|
9
|
+
}
|
|
10
|
+
const toolName = options.tool || "vercel_ai_tool";
|
|
11
|
+
const wrappedExecute = gate.wrap(toolDef.execute, {
|
|
12
|
+
...options,
|
|
13
|
+
tool: toolName,
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
...toolDef,
|
|
17
|
+
execute: wrappedExecute,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function wrapOpenAITool(gate, toolDef, executeFn, options) {
|
|
21
|
+
const wrapped = gate.wrap(executeFn, {
|
|
22
|
+
...options,
|
|
23
|
+
tool: toolDef.function.name,
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
...toolDef,
|
|
27
|
+
execute: wrapped,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function wrapAnthropicTool(gate, toolDef, executeFn, options) {
|
|
31
|
+
const wrapped = gate.wrap(executeFn, {
|
|
32
|
+
...options,
|
|
33
|
+
tool: toolDef.name,
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
...toolDef,
|
|
37
|
+
execute: wrapped,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function wrapOpenAIAgentTool(gate, toolDef, options) {
|
|
41
|
+
const toolName = options?.tool || toolDef.name;
|
|
42
|
+
const fnToWrap = toolDef.execute || toolDef.fn;
|
|
43
|
+
if (!fnToWrap) {
|
|
44
|
+
return toolDef;
|
|
45
|
+
}
|
|
46
|
+
const wrapped = gate.wrap(fnToWrap, {
|
|
47
|
+
...options,
|
|
48
|
+
tool: toolName,
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
...toolDef,
|
|
52
|
+
...(toolDef.execute ? { execute: wrapped } : {}),
|
|
53
|
+
...(toolDef.fn ? { fn: wrapped } : {}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Pre-execution guardrail for OpenAI Agents SDK.
|
|
58
|
+
*/
|
|
59
|
+
export function createOpenAIAgentGuardrail(gate) {
|
|
60
|
+
return async (context) => {
|
|
61
|
+
const check = await gate.checkAction({
|
|
62
|
+
tool: context.toolName,
|
|
63
|
+
params: context.args,
|
|
64
|
+
});
|
|
65
|
+
if (check.decision === "deny" && !check.shadowMode) {
|
|
66
|
+
throw new PolicyDeniedError(check.reason, check.id, check.matchedRule);
|
|
67
|
+
}
|
|
68
|
+
return check;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function wrapLangGraphTool(gate, tool, options) {
|
|
72
|
+
const toolName = options?.tool || tool.name;
|
|
73
|
+
const wrappedFunc = tool.func
|
|
74
|
+
? gate.wrap(tool.func, { ...options, tool: toolName })
|
|
75
|
+
: undefined;
|
|
76
|
+
const wrappedInvoke = tool.invoke
|
|
77
|
+
? gate.wrap(tool.invoke, { ...options, tool: toolName })
|
|
78
|
+
: undefined;
|
|
79
|
+
const wrappedCall = tool._call
|
|
80
|
+
? gate.wrap(tool._call, { ...options, tool: toolName })
|
|
81
|
+
: undefined;
|
|
82
|
+
return {
|
|
83
|
+
...tool,
|
|
84
|
+
...(wrappedFunc ? { func: wrappedFunc } : {}),
|
|
85
|
+
...(wrappedInvoke ? { invoke: wrappedInvoke } : {}),
|
|
86
|
+
...(wrappedCall ? { _call: wrappedCall } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function createClaudeCodeHook(gate, options) {
|
|
90
|
+
return async (toolCall) => {
|
|
91
|
+
const check = await gate.checkAction({
|
|
92
|
+
tool: toolCall.tool,
|
|
93
|
+
params: toolCall.input,
|
|
94
|
+
});
|
|
95
|
+
if (check.decision === "pending_approval" && !check.shadowMode) {
|
|
96
|
+
try {
|
|
97
|
+
const approved = await gate.waitForApproval(check.id, {
|
|
98
|
+
timeoutMs: options?.approvalTimeoutMs,
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
decision: "allow",
|
|
102
|
+
allow: true,
|
|
103
|
+
actionId: check.id,
|
|
104
|
+
reason: approved.reason,
|
|
105
|
+
receipt: check.receipt,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
return {
|
|
110
|
+
decision: "deny",
|
|
111
|
+
allow: false,
|
|
112
|
+
actionId: check.id,
|
|
113
|
+
reason: err.message,
|
|
114
|
+
receipt: check.receipt,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const isAllow = check.decision === "allow" || check.shadowMode === true;
|
|
119
|
+
return {
|
|
120
|
+
decision: check.decision,
|
|
121
|
+
allow: isAllow,
|
|
122
|
+
reason: check.reason,
|
|
123
|
+
actionId: check.id,
|
|
124
|
+
receipt: check.receipt,
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Executes a tool wrapped with the Claude Code governance hook and automatically
|
|
130
|
+
* reports outcome telemetry to SONNEV Gate.
|
|
131
|
+
*/
|
|
132
|
+
export async function runWithClaudeCodeHook(gate, toolCall, toolFn, options) {
|
|
133
|
+
const hook = createClaudeCodeHook(gate, options);
|
|
134
|
+
const check = await hook(toolCall);
|
|
135
|
+
if (!check.allow) {
|
|
136
|
+
throw new PolicyDeniedError(check.reason || `Tool ${toolCall.tool} denied by SONNEV Gate`, check.actionId || "act_claude_denied");
|
|
137
|
+
}
|
|
138
|
+
const startTime = Date.now();
|
|
139
|
+
try {
|
|
140
|
+
const result = await toolFn(toolCall.input);
|
|
141
|
+
if (check.actionId) {
|
|
142
|
+
await gate.reportResult(check.actionId, {
|
|
143
|
+
status: "success",
|
|
144
|
+
output: result,
|
|
145
|
+
durationMs: Date.now() - startTime,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
if (check.actionId) {
|
|
152
|
+
await gate.reportResult(check.actionId, {
|
|
153
|
+
status: "failure",
|
|
154
|
+
error: err.message || String(err),
|
|
155
|
+
durationMs: Date.now() - startTime,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
throw err;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAgB,EAChB,OAAiB,EACjB,OAAwE;IAExE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACrB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,IAAI,gBAAgB,CAAC;IAClD,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;QAChD,GAAG,OAAO;QACV,IAAI,EAAE,QAAQ;KACf,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,OAAO;QACV,OAAO,EAAE,cAAc;KACxB,CAAC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S;aACnC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE;gBACtC,MAAM,EAAE,SAAS;gBACjB,KAAK,EAAE,GAAG,CAAC,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC;gBACjC,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;aACnC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare class GateError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when the SONNEV Gate API cannot be reached.
|
|
6
|
+
* Enforcement fails closed: tool is NEVER executed.
|
|
7
|
+
*/
|
|
8
|
+
export declare class GateUnreachableError extends GateError {
|
|
9
|
+
constructor(message?: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Thrown when an action is denied by deterministic policy evaluation.
|
|
13
|
+
*/
|
|
14
|
+
export declare class PolicyDeniedError extends GateError {
|
|
15
|
+
readonly actionId?: string;
|
|
16
|
+
readonly reason: string;
|
|
17
|
+
readonly matchedRule?: {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
priority: number;
|
|
21
|
+
reason: string;
|
|
22
|
+
};
|
|
23
|
+
constructor(reason: string, actionId?: string, matchedRule?: {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
priority: number;
|
|
27
|
+
reason: string;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Thrown when an approval request times out without human authorization.
|
|
32
|
+
*/
|
|
33
|
+
export declare class ApprovalTimeoutError extends GateError {
|
|
34
|
+
readonly actionId: string;
|
|
35
|
+
constructor(message: string, actionId: string);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Thrown when a human approver explicitly rejects the requested action.
|
|
39
|
+
*/
|
|
40
|
+
export declare class ApprovalRejectedError extends GateError {
|
|
41
|
+
readonly actionId: string;
|
|
42
|
+
readonly reason?: string;
|
|
43
|
+
constructor(actionId: string, reason?: string);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Thrown when tool post-execution verification fails intent checking.
|
|
47
|
+
*/
|
|
48
|
+
export declare class VerificationFailedError extends GateError {
|
|
49
|
+
readonly actionId?: string;
|
|
50
|
+
readonly reason: string;
|
|
51
|
+
constructor(reason: string, actionId?: string);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAK5B;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;gBACrC,OAAO,GAAE,MAA6F;CAInH;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C,SAAgB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,WAAW,CAAC,EAAE;QAC5B,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;gBAGA,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;Q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