@rollikey/sdk 0.0.0-stage → 0.1.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rollikey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,101 @@
1
- # Temporary Holding Version
1
+ # @rollikey/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Typed client for [Rollikey](../../README.md): put a blast-radius gate, pre-flight snapshots, a 60-second airlock and
4
+ a one-call `revert(runId)` between any AI agent and your database, Stripe, S3, GitHub and Slack/Email.
5
+
6
+ MIT licensed. The server (`packages/server`) is FSL-1.1-MIT.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @rollikey/sdk
12
+ npx -y @rollikey/mcp # the MCP proxy the client talks to
13
+ ```
14
+
15
+ ## Start the local stack
16
+
17
+ Source: https://github.com/rollikey/rollikey
18
+
19
+ ```bash
20
+ docker compose up -d # postgres, redis, mailpit, minio
21
+ npm install
22
+ npm run db:seed # migrations + 5,000 demo customers
23
+ npm run dashboard # http://localhost:3000 (side-by-side demo: http://localhost:3000/demo)
24
+ ```
25
+
26
+ Everything runs on local sandboxes at $0. Stripe is optional (`STRIPE_SECRET_KEY=sk_test_...`, test keys only).
27
+
28
+ ## The 3-line quickstart
29
+
30
+ ```ts
31
+ import { RollikeyClient } from '@rollikey/sdk';
32
+ const sp = await RollikeyClient.connectStdio({ command: 'npx', args: ['-y', '@rollikey/mcp'] });
33
+ const run = sp.run(); // 1. one run = one undo unit
34
+ try { await myAgent(run); } catch { await run.revert(); } // 2-3. unchanged agent; crash → LIFO undo
35
+ ```
36
+
37
+ `run.revert()` cancels held emails/Slack posts, then undoes every applied action in reverse order.
38
+ Bulk spikes are blocked before they execute (more than 10 rows/objects, more than $1,000 per call).
39
+
40
+ ### MCP (Claude Desktop, Cursor, any MCP client)
41
+
42
+ ```json
43
+ { "mcpServers": { "rollikey": { "command": "npx", "args": ["-y", "@rollikey/mcp"], "env": { "DATABASE_URL": "postgres://…", "REDIS_URL": "redis://…" } } } }
44
+ ```
45
+
46
+ Tools: `rollikey_db_update`, `rollikey_db_delete`, `rollikey_stripe_refund`, `rollikey_stripe_authorize_hold`,
47
+ `rollikey_stripe_capture_holds`, `rollikey_send_email`, `rollikey_s3_*`, `rollikey_github_*`, `rollikey_slack_*`,
48
+ `rollikey_revert`, `rollikey_get_run`. Pass the same `runId` on every call of one agent session.
49
+
50
+ ### Anthropic tool calls
51
+
52
+ ```ts
53
+ const run = sp.run(), tools = anthropicTools(await sp.tools()); // 1 + 2
54
+ const msg = await anthropic.messages.create({ model, max_tokens: 1024, tools, messages });
55
+ for (const b of msg.content) if (b.type === 'tool_use') result = await run.call(b.name, b.input as any); // 3
56
+ ```
57
+
58
+ ### OpenAI tool calls
59
+
60
+ ```ts
61
+ const run = sp.run(), tools = openAITools(await sp.tools()); // 1 + 2
62
+ const res = await openai.chat.completions.create({ model, tools, messages });
63
+ for (const c of res.choices[0].message.tool_calls ?? []) result = await run.call(c.function.name, JSON.parse(c.function.arguments)); // 3
64
+ ```
65
+
66
+ ### Gemini tool calls
67
+
68
+ ```ts
69
+ const run = sp.run(), tools = geminiTools(await sp.tools()); // 1 + 2
70
+ const res = await ai.models.generateContent({ model, contents, config: { tools } });
71
+ for (const fc of res.functionCalls ?? []) result = await run.call(fc.name!, fc.args ?? {}); // 3
72
+ ```
73
+
74
+ ### LangGraph
75
+
76
+ ```ts
77
+ const run = sp.run(); // 1
78
+ const tools = (await sp.tools()).map((t) => tool(async (a) => JSON.stringify(await run.call(t.name, a)), { name: t.name, description: t.description, schema: t.inputSchema })); // 2
79
+ const agent = createReactAgent({ llm, tools }); /* …invoke…, then on error: */ await run.revert(); // 3
80
+ ```
81
+
82
+ `run.call()` returns gate blocks as normal tool results (`{ status: "blocked", reason }`) so the model can adapt.
83
+ Use the typed helpers (`run.postgres.update`, `run.s3.delete`, `run.stripe.authorizeHold`, …) when you write the calls yourself.
84
+
85
+ ## Non-custodial Stripe auth-hold
86
+
87
+ ```ts
88
+ const hold = await run.stripe.authorizeHold({ amountCents: 24_900, customerId, paymentMethodId }); // capture_method: 'manual', nothing charged
89
+ await run.stripe.captureHolds(); // only after the multi-step run verified cleanly
90
+ // …or run.revert() → paymentIntents.cancel(), the customer is never charged.
91
+ ```
92
+
93
+ Rollikey never holds your money. Set `ROLLIKEY_CONNECT_FEE_BPS` (0, or 25-50) only in hosted Connect mode;
94
+ the fee applies to captured holds, never to database, S3, GitHub or Slack/Email rollbacks.
95
+
96
+ ## Examples
97
+
98
+ ```bash
99
+ npx tsx packages/sdk/examples/quickstart.ts # SDK → MCP stdio → engine
100
+ npx tsx packages/sdk/examples/tool-calls.ts # provider adapters + run.call(), offline
101
+ ```
@@ -0,0 +1,318 @@
1
+ import { type Transport } from '@modelcontextprotocol/client';
2
+ import { type StdioServerParameters } from '@modelcontextprotocol/client/stdio';
3
+ export type ActionType = 'pg.update' | 'pg.delete' | 'stripe.refund' | 'stripe.authorize_hold' | 's3.put' | 's3.delete' | 's3.acl' | 'github.issue_update' | 'github.pr_update' | 'github.branch_delete' | 'slack.post' | 'slack.archive';
4
+ /** The five core connectors Rollikey wraps. */
5
+ export declare const CONNECTORS: readonly ['postgres', 'stripe', 's3', 'github', 'slack'];
6
+ export type Connector = (typeof CONNECTORS)[number];
7
+ export type Scalar = string | number | boolean | null;
8
+ export type FilterOp = 'eq' | 'neq' | 'lt' | 'lte' | 'gt' | 'gte' | 'in' | 'not_in' | 'like' | 'ilike' | 'is_null' | 'not_null';
9
+ export type Where = Record<string, Scalar | {
10
+ op: FilterOp;
11
+ value?: Scalar | Scalar[];
12
+ }>;
13
+ export interface AppliedMutation {
14
+ status: 'applied';
15
+ runId: string;
16
+ seq: number;
17
+ snapshotId: string;
18
+ rowsAffected: number;
19
+ amountCents: number;
20
+ rows: Record<string, unknown>[];
21
+ }
22
+ export interface BlockedAction {
23
+ status: 'blocked';
24
+ runId: string;
25
+ seq: number;
26
+ snapshotId: string;
27
+ amountCents: number;
28
+ rowsMatched?: number;
29
+ reason: string;
30
+ }
31
+ export interface AppliedRefund {
32
+ status: 'applied' | 'pending';
33
+ runId: string;
34
+ seq: number;
35
+ snapshotId: string;
36
+ amountCents: number;
37
+ refundId?: string;
38
+ refundStatus?: string | null;
39
+ error?: string;
40
+ }
41
+ export interface HeldEmail {
42
+ status: 'held';
43
+ id: string;
44
+ runId: string;
45
+ releaseAt: string;
46
+ }
47
+ /** What revert does when a target changed after the agent touched it. Default 'halt'. */
48
+ export type OnDrift = 'halt' | 'overwrite';
49
+ export interface RevertOptions {
50
+ onDrift?: OnDrift;
51
+ }
52
+ export interface RevertReport {
53
+ status: 'reverted' | 'partial';
54
+ runId: string;
55
+ complete: boolean;
56
+ /** The run is fenced after a revert: new actions in it are refused (code run_fenced). */
57
+ fenced?: boolean;
58
+ onDrift?: OnDrift;
59
+ emails: RevertSlackReport;
60
+ slack: RevertSlackReport;
61
+ steps: {
62
+ seq: number;
63
+ snapshotId: string;
64
+ actionType: ActionType;
65
+ target: string;
66
+ status: 'reverted' | 'revert_failed';
67
+ compensation?: Record<string, unknown>;
68
+ error?: string;
69
+ code?: string;
70
+ drifted?: unknown[];
71
+ }[];
72
+ remaining: number[];
73
+ }
74
+ export interface RevertSlackReport {
75
+ cancelled: string[];
76
+ /** Released or being released (includes inFlight). */
77
+ alreadySent: string[];
78
+ /** Delivery attempted, outcome not yet known. */
79
+ inFlight?: string[];
80
+ }
81
+ export interface RunInfo {
82
+ runId: string;
83
+ snapshots: Record<string, unknown>[];
84
+ emails: Record<string, unknown>[];
85
+ slack: Record<string, unknown>[];
86
+ }
87
+ export interface RefundInput {
88
+ paymentIntentId?: string;
89
+ chargeId?: string;
90
+ amountCents?: number;
91
+ reason?: 'duplicate' | 'fraudulent' | 'requested_by_customer';
92
+ }
93
+ export interface HoldInput {
94
+ amountCents: number;
95
+ currency?: string;
96
+ customerId?: string;
97
+ paymentMethodId?: string;
98
+ description?: string;
99
+ }
100
+ export interface AppliedHold {
101
+ status: 'applied' | 'pending';
102
+ runId: string;
103
+ seq: number;
104
+ snapshotId: string;
105
+ amountCents: number;
106
+ paymentIntentId?: string;
107
+ holdStatus?: string;
108
+ /** Connect application fee that will be taken on capture (0 in self-hosted mode). */
109
+ feeCents?: number;
110
+ error?: string;
111
+ }
112
+ export interface CaptureResult {
113
+ runId: string;
114
+ captured: {
115
+ paymentIntentId: string;
116
+ amountCents: number;
117
+ feeCents: number;
118
+ }[];
119
+ skipped: string[];
120
+ totalFeeCents: number;
121
+ }
122
+ export interface EmailInput {
123
+ to: string | string[];
124
+ subject: string;
125
+ text?: string;
126
+ html?: string;
127
+ from?: string;
128
+ }
129
+ export interface S3PutInput {
130
+ key: string;
131
+ body: string;
132
+ encoding?: 'utf8' | 'base64';
133
+ bucket?: string;
134
+ contentType?: string;
135
+ metadata?: Record<string, string>;
136
+ }
137
+ export type S3DeleteInput = {
138
+ bucket?: string;
139
+ } & ({
140
+ keys: string[];
141
+ prefix?: never;
142
+ } | {
143
+ prefix: string;
144
+ keys?: never;
145
+ });
146
+ export interface S3Result {
147
+ status: 'applied';
148
+ runId: string;
149
+ seq: number;
150
+ snapshotId: string;
151
+ bucket: string;
152
+ objects: number;
153
+ keys: string[];
154
+ etag?: string;
155
+ amountCents: 0;
156
+ }
157
+ export interface GitHubTarget {
158
+ owner?: string;
159
+ repo?: string;
160
+ }
161
+ export interface GitHubPatch {
162
+ title?: string;
163
+ body?: string | null;
164
+ state?: 'open' | 'closed';
165
+ labels?: string[];
166
+ base?: string;
167
+ }
168
+ export interface GitHubResult {
169
+ status: 'applied';
170
+ runId: string;
171
+ seq: number;
172
+ snapshotId: string;
173
+ repo: string;
174
+ items: number;
175
+ numbers?: number[];
176
+ branches?: string[];
177
+ amountCents: 0;
178
+ }
179
+ export interface SlackPostInput {
180
+ channel: string;
181
+ text: string;
182
+ threadTs?: string;
183
+ }
184
+ export type SlackResult = {
185
+ status: 'held';
186
+ runId: string;
187
+ seq: number;
188
+ snapshotId: string;
189
+ id: string;
190
+ channel: string;
191
+ releaseAt: string;
192
+ reasons: string[];
193
+ amountCents: 0;
194
+ } | {
195
+ status: 'applied';
196
+ runId: string;
197
+ seq: number;
198
+ snapshotId: string;
199
+ channel: string;
200
+ ts: string;
201
+ backend: 'sink' | 'bot' | 'webhook';
202
+ amountCents: 0;
203
+ };
204
+ /** Thrown when the blast-radius gate stops a call. The attempt is still recorded in the ledger. */
205
+ export declare class RollikeyBlockedError extends Error {
206
+ readonly result: BlockedAction;
207
+ constructor(result: BlockedAction);
208
+ }
209
+ export declare class RollikeyToolError extends Error {
210
+ readonly code: string;
211
+ constructor(code: string, message: string);
212
+ }
213
+ export interface RollikeyClientOptions {
214
+ /**
215
+ * Low-level RollikeyClient.call() only: when true (default), gated calls throw RollikeyBlockedError.
216
+ * RollikeyRun methods (run.call, run.updateRows, run.refund, ...) always return { status: 'blocked' } instead.
217
+ */
218
+ throwOnBlocked?: boolean;
219
+ }
220
+ export declare class RollikeyClient {
221
+ private readonly client;
222
+ private readonly opts;
223
+ private constructor();
224
+ static connect(transport: Transport, opts?: RollikeyClientOptions): Promise<RollikeyClient>;
225
+ /** Spawn the Rollikey MCP server as a child process and connect over stdio. */
226
+ static connectStdio(server: StdioServerParameters, opts?: RollikeyClientOptions): Promise<RollikeyClient>;
227
+ /** Start (or resume) a run. All actions through the handle share one runId and revert together. */
228
+ run(runId?: string): RollikeyRun;
229
+ close(): Promise<void>;
230
+ /** Every Rollikey tool as a plain JSON-Schema description. `runId` is stripped: the run injects it. */
231
+ tools(): Promise<RollikeyTool[]>;
232
+ /** @internal */
233
+ call<T>(name: string, args: Record<string, unknown>): Promise<T>;
234
+ }
235
+ /** A Rollikey tool in provider-neutral form (JSON Schema). */
236
+ export interface RollikeyTool {
237
+ name: string;
238
+ description: string;
239
+ inputSchema: Record<string, unknown>;
240
+ }
241
+ /** Anthropic Messages API: `tools: anthropicTools(await sp.tools())`. */
242
+ export declare const anthropicTools: (tools: RollikeyTool[]) => {
243
+ name: string;
244
+ description: string;
245
+ input_schema: Record<string, unknown>;
246
+ }[];
247
+ /** OpenAI Chat Completions / Responses function tools: `tools: openAITools(await sp.tools())`. */
248
+ export declare const openAITools: (tools: RollikeyTool[]) => {
249
+ type: 'function';
250
+ function: {
251
+ name: string;
252
+ description: string;
253
+ parameters: Record<string, unknown>;
254
+ };
255
+ }[];
256
+ /** Gemini (@google/genai): `config: { tools: geminiTools(await sp.tools()) }`. */
257
+ export declare const geminiTools: (tools: RollikeyTool[]) => {
258
+ functionDeclarations: {
259
+ name: string;
260
+ description: string;
261
+ parametersJsonSchema: Record<string, unknown>;
262
+ }[];
263
+ }[];
264
+ export declare class RollikeyRun {
265
+ private readonly sp;
266
+ readonly runId: string;
267
+ constructor(sp: RollikeyClient, runId: string);
268
+ /**
269
+ * Route any model tool call (Anthropic / OpenAI / Gemini / LangGraph) through Rollikey.
270
+ * Returns the structured result as-is, including `status: 'blocked'`, so the model can adapt.
271
+ * Gate blocks do NOT throw here: the agent should see them as a normal tool result.
272
+ */
273
+ call<T = Record<string, unknown>>(name: string, args?: Record<string, unknown>): Promise<T>;
274
+ updateRows(table: string, where: Where, set: Record<string, Scalar>): Promise<AppliedMutation | BlockedAction>;
275
+ deleteRows(table: string, where: Where): Promise<AppliedMutation | BlockedAction>;
276
+ refund(input: RefundInput): Promise<AppliedRefund | BlockedAction>;
277
+ /** Authorize (hold) funds with manual capture. Nothing is charged until captureHolds(). */
278
+ authorizeHold(input: HoldInput): Promise<AppliedHold | BlockedAction>;
279
+ /** Capture the run's holds once the multi-step run verified cleanly. */
280
+ captureHolds(): Promise<CaptureResult>;
281
+ sendEmail(input: EmailInput): Promise<BlockedAction | HeldEmail>;
282
+ s3PutObject(input: S3PutInput): Promise<BlockedAction | S3Result>;
283
+ s3DeleteObjects(input: S3DeleteInput): Promise<BlockedAction | S3Result>;
284
+ s3SetBucketAcl(acl: 'private' | 'public-read' | 'public-read-write' | 'authenticated-read', bucket?: string): Promise<BlockedAction | S3Result>;
285
+ githubUpdateIssues(numbers: number[], patch: GitHubPatch, target?: GitHubTarget): Promise<BlockedAction | GitHubResult>;
286
+ githubUpdatePulls(numbers: number[], patch: GitHubPatch, target?: GitHubTarget): Promise<BlockedAction | GitHubResult>;
287
+ githubDeleteBranches(branches: string[], target?: GitHubTarget): Promise<BlockedAction | GitHubResult>;
288
+ slackPost(input: SlackPostInput): Promise<BlockedAction | SlackResult>;
289
+ slackArchiveChannel(channel: string): Promise<BlockedAction>;
290
+ /** The five connectors grouped by system, e.g. `run.s3.put(...)`, `run.github.deleteBranches(...)`. */
291
+ get postgres(): {
292
+ update: (table: string, where: Where, set: Record<string, Scalar>) => Promise<AppliedMutation | BlockedAction>;
293
+ delete: (table: string, where: Where) => Promise<AppliedMutation | BlockedAction>;
294
+ };
295
+ get stripe(): {
296
+ refund: (input: RefundInput) => Promise<AppliedRefund | BlockedAction>;
297
+ authorizeHold: (input: HoldInput) => Promise<AppliedHold | BlockedAction>;
298
+ captureHolds: () => Promise<CaptureResult>;
299
+ };
300
+ get s3(): {
301
+ put: (input: S3PutInput) => Promise<BlockedAction | S3Result>;
302
+ delete: (input: S3DeleteInput) => Promise<BlockedAction | S3Result>;
303
+ setBucketAcl: (acl: 'private' | 'public-read' | 'public-read-write' | 'authenticated-read', bucket?: string) => Promise<BlockedAction | S3Result>;
304
+ };
305
+ get github(): {
306
+ updateIssues: (numbers: number[], patch: GitHubPatch, target?: GitHubTarget) => Promise<BlockedAction | GitHubResult>;
307
+ updatePulls: (numbers: number[], patch: GitHubPatch, target?: GitHubTarget) => Promise<BlockedAction | GitHubResult>;
308
+ deleteBranches: (branches: string[], target?: GitHubTarget) => Promise<BlockedAction | GitHubResult>;
309
+ };
310
+ get slack(): {
311
+ post: (input: SlackPostInput) => Promise<BlockedAction | SlackResult>;
312
+ archiveChannel: (channel: string) => Promise<BlockedAction>;
313
+ email: (input: EmailInput) => Promise<BlockedAction | HeldEmail>;
314
+ };
315
+ /** Undo the run (LIFO). Default onDrift 'halt' stops for review on drift; { onDrift: 'overwrite' } restores anyway. */
316
+ revert(opts?: RevertOptions): Promise<RevertReport>;
317
+ inspect(): Promise<RunInfo>;
318
+ }
package/dist/index.js ADDED
@@ -0,0 +1,178 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { Client } from '@modelcontextprotocol/client';
3
+ import { StdioClientTransport } from '@modelcontextprotocol/client/stdio';
4
+ /** The five core connectors Rollikey wraps. */
5
+ export const CONNECTORS = ['postgres', 'stripe', 's3', 'github', 'slack'];
6
+ // ---------------------------------------------------------------------------
7
+ // Errors
8
+ // ---------------------------------------------------------------------------
9
+ /** Thrown when the blast-radius gate stops a call. The attempt is still recorded in the ledger. */
10
+ export class RollikeyBlockedError extends Error {
11
+ result;
12
+ constructor(result) {
13
+ super(result.reason);
14
+ this.result = result;
15
+ this.name = 'RollikeyBlockedError';
16
+ }
17
+ }
18
+ export class RollikeyToolError extends Error {
19
+ code;
20
+ constructor(code, message) {
21
+ super(message);
22
+ this.code = code;
23
+ this.name = 'RollikeyToolError';
24
+ }
25
+ }
26
+ export class RollikeyClient {
27
+ client;
28
+ opts;
29
+ constructor(client, opts) {
30
+ this.client = client;
31
+ this.opts = opts;
32
+ }
33
+ static async connect(transport, opts = {}) {
34
+ const client = new Client({ name: 'rollikey-sdk', version: '0.1.1' });
35
+ await client.connect(transport);
36
+ return new RollikeyClient(client, { throwOnBlocked: opts.throwOnBlocked ?? true });
37
+ }
38
+ /** Spawn the Rollikey MCP server as a child process and connect over stdio. */
39
+ static connectStdio(server, opts) {
40
+ return RollikeyClient.connect(new StdioClientTransport(server), opts);
41
+ }
42
+ /** Start (or resume) a run. All actions through the handle share one runId and revert together. */
43
+ run(runId = `run_${randomUUID()}`) {
44
+ return new RollikeyRun(this, runId);
45
+ }
46
+ close() {
47
+ return this.client.close();
48
+ }
49
+ /** Every Rollikey tool as a plain JSON-Schema description. `runId` is stripped: the run injects it. */
50
+ async tools() {
51
+ const { tools } = await this.client.listTools();
52
+ return tools.map((t) => {
53
+ const schema = JSON.parse(JSON.stringify(t.inputSchema ?? { type: 'object', properties: {} }));
54
+ delete schema.properties?.runId;
55
+ if (schema.required)
56
+ schema.required = schema.required.filter((r) => r !== 'runId');
57
+ return { name: t.name, description: t.description ?? '', inputSchema: schema };
58
+ });
59
+ }
60
+ /** @internal */
61
+ async call(name, args) {
62
+ const result = await this.client.callTool({ name, arguments: args });
63
+ const sc = result.structuredContent;
64
+ if (sc === undefined) {
65
+ const text = result.content.map((c) => (c.type === 'text' ? c.text : '')).join('\n');
66
+ throw new RollikeyToolError('no_structured_content', text || `Tool ${name} returned no data`);
67
+ }
68
+ if (sc.status === 'blocked' && this.opts.throwOnBlocked)
69
+ throw new RollikeyBlockedError(sc);
70
+ if (result.isError && sc.status !== 'blocked') {
71
+ throw new RollikeyToolError(String(sc.code ?? 'tool_error'), String(sc.message ?? 'Rollikey tool failed'));
72
+ }
73
+ return sc;
74
+ }
75
+ }
76
+ /** Anthropic Messages API: `tools: anthropicTools(await sp.tools())`. */
77
+ export const anthropicTools = (tools) => tools.map((t) => ({ name: t.name, description: t.description, input_schema: t.inputSchema }));
78
+ /** OpenAI Chat Completions / Responses function tools: `tools: openAITools(await sp.tools())`. */
79
+ export const openAITools = (tools) => tools.map((t) => ({ type: 'function', function: { name: t.name, description: t.description, parameters: t.inputSchema } }));
80
+ /** Gemini (@google/genai): `config: { tools: geminiTools(await sp.tools()) }`. */
81
+ export const geminiTools = (tools) => [
82
+ { functionDeclarations: tools.map((t) => ({ name: t.name, description: t.description, parametersJsonSchema: t.inputSchema })) },
83
+ ];
84
+ export class RollikeyRun {
85
+ sp;
86
+ runId;
87
+ constructor(sp, runId) {
88
+ this.sp = sp;
89
+ this.runId = runId;
90
+ }
91
+ /**
92
+ * Route any model tool call (Anthropic / OpenAI / Gemini / LangGraph) through Rollikey.
93
+ * Returns the structured result as-is, including `status: 'blocked'`, so the model can adapt.
94
+ * Gate blocks do NOT throw here: the agent should see them as a normal tool result.
95
+ */
96
+ async call(name, args = {}) {
97
+ try {
98
+ // runId goes last so nothing in args can move the call into another run.
99
+ return await this.sp.call(name, { ...args, runId: this.runId });
100
+ }
101
+ catch (err) {
102
+ if (err instanceof RollikeyBlockedError)
103
+ return err.result;
104
+ throw err;
105
+ }
106
+ }
107
+ updateRows(table, where, set) {
108
+ return this.call('rollikey_db_update', { table, where, set });
109
+ }
110
+ deleteRows(table, where) {
111
+ return this.call('rollikey_db_delete', { table, where });
112
+ }
113
+ refund(input) {
114
+ return this.call('rollikey_stripe_refund', { ...input });
115
+ }
116
+ /** Authorize (hold) funds with manual capture. Nothing is charged until captureHolds(). */
117
+ authorizeHold(input) {
118
+ return this.call('rollikey_stripe_authorize_hold', { ...input });
119
+ }
120
+ /** Capture the run's holds once the multi-step run verified cleanly. */
121
+ captureHolds() {
122
+ return this.call('rollikey_stripe_capture_holds', {});
123
+ }
124
+ sendEmail(input) {
125
+ return this.call('rollikey_send_email', { ...input });
126
+ }
127
+ // ---- AWS S3 ----
128
+ s3PutObject(input) {
129
+ return this.call('rollikey_s3_put_object', { ...input });
130
+ }
131
+ s3DeleteObjects(input) {
132
+ return this.call('rollikey_s3_delete_objects', { ...input });
133
+ }
134
+ s3SetBucketAcl(acl, bucket) {
135
+ return this.call('rollikey_s3_set_bucket_acl', { acl, ...(bucket ? { bucket } : {}) });
136
+ }
137
+ // ---- GitHub ----
138
+ githubUpdateIssues(numbers, patch, target = {}) {
139
+ return this.call('rollikey_github_update_issues', { ...target, numbers, patch });
140
+ }
141
+ githubUpdatePulls(numbers, patch, target = {}) {
142
+ return this.call('rollikey_github_update_pulls', { ...target, numbers, patch });
143
+ }
144
+ githubDeleteBranches(branches, target = {}) {
145
+ return this.call('rollikey_github_delete_branches', { ...target, branches });
146
+ }
147
+ // ---- Slack ----
148
+ slackPost(input) {
149
+ return this.call('rollikey_slack_post', { ...input });
150
+ }
151
+ slackArchiveChannel(channel) {
152
+ return this.call('rollikey_slack_archive_channel', { channel });
153
+ }
154
+ /** The five connectors grouped by system, e.g. `run.s3.put(...)`, `run.github.deleteBranches(...)`. */
155
+ get postgres() {
156
+ return { update: this.updateRows.bind(this), delete: this.deleteRows.bind(this) };
157
+ }
158
+ get stripe() {
159
+ return { refund: this.refund.bind(this), authorizeHold: this.authorizeHold.bind(this), captureHolds: this.captureHolds.bind(this) };
160
+ }
161
+ get s3() {
162
+ return { put: this.s3PutObject.bind(this), delete: this.s3DeleteObjects.bind(this), setBucketAcl: this.s3SetBucketAcl.bind(this) };
163
+ }
164
+ get github() {
165
+ return { updateIssues: this.githubUpdateIssues.bind(this), updatePulls: this.githubUpdatePulls.bind(this), deleteBranches: this.githubDeleteBranches.bind(this) };
166
+ }
167
+ get slack() {
168
+ return { post: this.slackPost.bind(this), archiveChannel: this.slackArchiveChannel.bind(this), email: this.sendEmail.bind(this) };
169
+ }
170
+ /** Undo the run (LIFO). Default onDrift 'halt' stops for review on drift; { onDrift: 'overwrite' } restores anyway. */
171
+ revert(opts = {}) {
172
+ return this.call('rollikey_revert', opts.onDrift ? { onDrift: opts.onDrift } : {});
173
+ }
174
+ inspect() {
175
+ return this.call('rollikey_get_run', {});
176
+ }
177
+ }
178
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@rollikey/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Typed client for Rollikey: blast-radius gate, airlock and one-call revert for AI agent actions",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/rollikey/rollikey.git",
9
+ "directory": "packages/sdk"
10
+ },
11
+ "homepage": "https://rollikey.com",
12
+ "bugs": {
13
+ "url": "https://github.com/rollikey/rollikey/issues"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "keywords": [
19
+ "ai-agents",
20
+ "mcp",
21
+ "safety",
22
+ "rollback",
23
+ "rollikey"
24
+ ],
25
+ "type": "module",
26
+ "main": "dist/index.js",
27
+ "types": "dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
34
+ "scripts": {
35
+ "build": "tsc -p tsconfig.json",
36
+ "typecheck": "tsc -p tsconfig.json --noEmit",
37
+ "prepublishOnly": "npm run build"
38
+ },
39
+ "dependencies": {
40
+ "@google/genai": "^3.3.0",
41
+ "@modelcontextprotocol/client": "^2.4.0",
42
+ "zod": "^4.6.7"
43
+ },
44
+ "files": [
45
+ "dist",
46
+ "!dist/**/*.map",
47
+ "LICENSE",
48
+ "README.md"
49
+ ],
50
+ "engines": {
51
+ "node": ">=22"
52
+ }
53
+ }