@rollikey/sdk 0.1.0 → 0.1.2
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/index.d.ts +45 -11
- package/dist/index.js +49 -21
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type Transport } from '@modelcontextprotocol/client';
|
|
2
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'
|
|
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
|
+
/** Only ever 'blocked': an email refused by a per-run cap. */
|
|
5
|
+
| 'email.send';
|
|
4
6
|
/** The five core connectors Rollikey wraps. */
|
|
5
7
|
export declare const CONNECTORS: readonly ['postgres', 'stripe', 's3', 'github', 'slack'];
|
|
6
8
|
export type Connector = (typeof CONNECTORS)[number];
|
|
@@ -44,29 +46,51 @@ export interface HeldEmail {
|
|
|
44
46
|
runId: string;
|
|
45
47
|
releaseAt: string;
|
|
46
48
|
}
|
|
49
|
+
/** What revert does when a target changed after the agent touched it. Default 'halt'. */
|
|
50
|
+
export type OnDrift = 'halt' | 'overwrite';
|
|
51
|
+
export interface RevertOptions {
|
|
52
|
+
onDrift?: OnDrift;
|
|
53
|
+
/** Operator only: snapshot ids of acknowledged revert_failed steps to skip so LIFO can continue. */
|
|
54
|
+
skipStepIds?: string[];
|
|
55
|
+
}
|
|
47
56
|
export interface RevertReport {
|
|
48
57
|
status: 'reverted' | 'partial';
|
|
49
58
|
runId: string;
|
|
50
59
|
complete: boolean;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
/** The run is fenced after a revert: new actions in it are refused (code run_fenced). */
|
|
61
|
+
fenced?: boolean;
|
|
62
|
+
onDrift?: OnDrift;
|
|
63
|
+
emails: RevertSlackReport;
|
|
55
64
|
slack: RevertSlackReport;
|
|
56
65
|
steps: {
|
|
57
66
|
seq: number;
|
|
58
67
|
snapshotId: string;
|
|
59
68
|
actionType: ActionType;
|
|
60
69
|
target: string;
|
|
61
|
-
status: 'reverted' | 'revert_failed';
|
|
70
|
+
status: 'reverted' | 'revert_failed' | 'skipped';
|
|
62
71
|
compensation?: Record<string, unknown>;
|
|
63
72
|
error?: string;
|
|
73
|
+
code?: string;
|
|
74
|
+
drifted?: unknown[];
|
|
64
75
|
}[];
|
|
65
76
|
remaining: number[];
|
|
77
|
+
/** Snapshot ids skipped via skipStepIds (still revert_failed: their side effect was not undone). */
|
|
78
|
+
skipped?: string[];
|
|
79
|
+
/** Side effects that cannot be recalled, e.g. a Slack post already sent via incoming webhook. */
|
|
80
|
+
unrecallable?: {
|
|
81
|
+
seq: number;
|
|
82
|
+
snapshotId: string;
|
|
83
|
+
actionType: ActionType;
|
|
84
|
+
target: string;
|
|
85
|
+
compensation: Record<string, unknown>;
|
|
86
|
+
}[];
|
|
66
87
|
}
|
|
67
88
|
export interface RevertSlackReport {
|
|
68
89
|
cancelled: string[];
|
|
90
|
+
/** Released or being released (includes inFlight). */
|
|
69
91
|
alreadySent: string[];
|
|
92
|
+
/** Delivery attempted, outcome not yet known. */
|
|
93
|
+
inFlight?: string[];
|
|
70
94
|
}
|
|
71
95
|
export interface RunInfo {
|
|
72
96
|
runId: string;
|
|
@@ -107,6 +131,12 @@ export interface CaptureResult {
|
|
|
107
131
|
feeCents: number;
|
|
108
132
|
}[];
|
|
109
133
|
skipped: string[];
|
|
134
|
+
/** Per-hold failures; the other holds of the run are still captured. */
|
|
135
|
+
failed: {
|
|
136
|
+
snapshotId: string;
|
|
137
|
+
paymentIntentId?: string;
|
|
138
|
+
error: string;
|
|
139
|
+
}[];
|
|
110
140
|
totalFeeCents: number;
|
|
111
141
|
}
|
|
112
142
|
export interface EmailInput {
|
|
@@ -201,7 +231,10 @@ export declare class RollikeyToolError extends Error {
|
|
|
201
231
|
constructor(code: string, message: string);
|
|
202
232
|
}
|
|
203
233
|
export interface RollikeyClientOptions {
|
|
204
|
-
/**
|
|
234
|
+
/**
|
|
235
|
+
* Low-level RollikeyClient.call() only: when true (default), gated calls throw RollikeyBlockedError.
|
|
236
|
+
* RollikeyRun methods (run.call, run.updateRows, run.refund, ...) always return { status: 'blocked' } instead.
|
|
237
|
+
*/
|
|
205
238
|
throwOnBlocked?: boolean;
|
|
206
239
|
}
|
|
207
240
|
export declare class RollikeyClient {
|
|
@@ -257,7 +290,7 @@ export declare class RollikeyRun {
|
|
|
257
290
|
* Returns the structured result as-is, including `status: 'blocked'`, so the model can adapt.
|
|
258
291
|
* Gate blocks do NOT throw here: the agent should see them as a normal tool result.
|
|
259
292
|
*/
|
|
260
|
-
call(name: string, args?: Record<string, unknown>): Promise<
|
|
293
|
+
call<T = Record<string, unknown>>(name: string, args?: Record<string, unknown>): Promise<T>;
|
|
261
294
|
updateRows(table: string, where: Where, set: Record<string, Scalar>): Promise<AppliedMutation | BlockedAction>;
|
|
262
295
|
deleteRows(table: string, where: Where): Promise<AppliedMutation | BlockedAction>;
|
|
263
296
|
refund(input: RefundInput): Promise<AppliedRefund | BlockedAction>;
|
|
@@ -265,7 +298,7 @@ export declare class RollikeyRun {
|
|
|
265
298
|
authorizeHold(input: HoldInput): Promise<AppliedHold | BlockedAction>;
|
|
266
299
|
/** Capture the run's holds once the multi-step run verified cleanly. */
|
|
267
300
|
captureHolds(): Promise<CaptureResult>;
|
|
268
|
-
sendEmail(input: EmailInput): Promise<HeldEmail>;
|
|
301
|
+
sendEmail(input: EmailInput): Promise<BlockedAction | HeldEmail>;
|
|
269
302
|
s3PutObject(input: S3PutInput): Promise<BlockedAction | S3Result>;
|
|
270
303
|
s3DeleteObjects(input: S3DeleteInput): Promise<BlockedAction | S3Result>;
|
|
271
304
|
s3SetBucketAcl(acl: 'private' | 'public-read' | 'public-read-write' | 'authenticated-read', bucket?: string): Promise<BlockedAction | S3Result>;
|
|
@@ -297,8 +330,9 @@ export declare class RollikeyRun {
|
|
|
297
330
|
get slack(): {
|
|
298
331
|
post: (input: SlackPostInput) => Promise<BlockedAction | SlackResult>;
|
|
299
332
|
archiveChannel: (channel: string) => Promise<BlockedAction>;
|
|
300
|
-
email: (input: EmailInput) => Promise<HeldEmail>;
|
|
333
|
+
email: (input: EmailInput) => Promise<BlockedAction | HeldEmail>;
|
|
301
334
|
};
|
|
302
|
-
|
|
335
|
+
/** Undo the run (LIFO). Default onDrift 'halt' stops for review on drift; { onDrift: 'overwrite' } restores anyway. */
|
|
336
|
+
revert(opts?: RevertOptions): Promise<RevertReport>;
|
|
303
337
|
inspect(): Promise<RunInfo>;
|
|
304
338
|
}
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ export class RollikeyClient {
|
|
|
31
31
|
this.opts = opts;
|
|
32
32
|
}
|
|
33
33
|
static async connect(transport, opts = {}) {
|
|
34
|
-
const client = new Client({ name: 'rollikey-sdk', version: '0.1.
|
|
34
|
+
const client = new Client({ name: 'rollikey-sdk', version: '0.1.2' });
|
|
35
35
|
await client.connect(transport);
|
|
36
36
|
return new RollikeyClient(client, { throwOnBlocked: opts.throwOnBlocked ?? true });
|
|
37
37
|
}
|
|
@@ -51,9 +51,7 @@ export class RollikeyClient {
|
|
|
51
51
|
const { tools } = await this.client.listTools();
|
|
52
52
|
return tools.map((t) => {
|
|
53
53
|
const schema = JSON.parse(JSON.stringify(t.inputSchema ?? { type: 'object', properties: {} }));
|
|
54
|
-
|
|
55
|
-
if (schema.required)
|
|
56
|
-
schema.required = schema.required.filter((r) => r !== 'runId');
|
|
54
|
+
stripRunId(schema);
|
|
57
55
|
return { name: t.name, description: t.description ?? '', inputSchema: schema };
|
|
58
56
|
});
|
|
59
57
|
}
|
|
@@ -73,6 +71,31 @@ export class RollikeyClient {
|
|
|
73
71
|
return sc;
|
|
74
72
|
}
|
|
75
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Remove `runId` everywhere it can be declared: top-level properties and every allOf / anyOf /
|
|
76
|
+
* oneOf branch (intersection schemas put it in its own allOf member). A branch left with nothing
|
|
77
|
+
* but runId is dropped, so it can never reject the remaining arguments.
|
|
78
|
+
*/
|
|
79
|
+
function stripRunId(schema) {
|
|
80
|
+
if (schema.properties && 'runId' in schema.properties)
|
|
81
|
+
delete schema.properties.runId;
|
|
82
|
+
if (schema.required)
|
|
83
|
+
schema.required = schema.required.filter((r) => r !== 'runId');
|
|
84
|
+
for (const key of ['allOf', 'anyOf', 'oneOf']) {
|
|
85
|
+
const branches = schema[key];
|
|
86
|
+
if (!Array.isArray(branches))
|
|
87
|
+
continue;
|
|
88
|
+
for (const b of branches)
|
|
89
|
+
stripRunId(b);
|
|
90
|
+
const kept = branches.filter((b) => !(b.properties && Object.keys(b.properties).length === 0 && !b.allOf && !b.anyOf && !b.oneOf));
|
|
91
|
+
if (key === 'allOf') {
|
|
92
|
+
if (kept.length === 0)
|
|
93
|
+
delete schema.allOf;
|
|
94
|
+
else
|
|
95
|
+
schema.allOf = kept;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
76
99
|
/** Anthropic Messages API: `tools: anthropicTools(await sp.tools())`. */
|
|
77
100
|
export const anthropicTools = (tools) => tools.map((t) => ({ name: t.name, description: t.description, input_schema: t.inputSchema }));
|
|
78
101
|
/** OpenAI Chat Completions / Responses function tools: `tools: openAITools(await sp.tools())`. */
|
|
@@ -95,6 +118,7 @@ export class RollikeyRun {
|
|
|
95
118
|
*/
|
|
96
119
|
async call(name, args = {}) {
|
|
97
120
|
try {
|
|
121
|
+
// runId goes last so nothing in args can move the call into another run.
|
|
98
122
|
return await this.sp.call(name, { ...args, runId: this.runId });
|
|
99
123
|
}
|
|
100
124
|
catch (err) {
|
|
@@ -104,51 +128,51 @@ export class RollikeyRun {
|
|
|
104
128
|
}
|
|
105
129
|
}
|
|
106
130
|
updateRows(table, where, set) {
|
|
107
|
-
return this.
|
|
131
|
+
return this.call('rollikey_db_update', { table, where, set });
|
|
108
132
|
}
|
|
109
133
|
deleteRows(table, where) {
|
|
110
|
-
return this.
|
|
134
|
+
return this.call('rollikey_db_delete', { table, where });
|
|
111
135
|
}
|
|
112
136
|
refund(input) {
|
|
113
|
-
return this.
|
|
137
|
+
return this.call('rollikey_stripe_refund', { ...input });
|
|
114
138
|
}
|
|
115
139
|
/** Authorize (hold) funds with manual capture. Nothing is charged until captureHolds(). */
|
|
116
140
|
authorizeHold(input) {
|
|
117
|
-
return this.
|
|
141
|
+
return this.call('rollikey_stripe_authorize_hold', { ...input });
|
|
118
142
|
}
|
|
119
143
|
/** Capture the run's holds once the multi-step run verified cleanly. */
|
|
120
144
|
captureHolds() {
|
|
121
|
-
return this.
|
|
145
|
+
return this.call('rollikey_stripe_capture_holds', {});
|
|
122
146
|
}
|
|
123
147
|
sendEmail(input) {
|
|
124
|
-
return this.
|
|
148
|
+
return this.call('rollikey_send_email', { ...input });
|
|
125
149
|
}
|
|
126
150
|
// ---- AWS S3 ----
|
|
127
151
|
s3PutObject(input) {
|
|
128
|
-
return this.
|
|
152
|
+
return this.call('rollikey_s3_put_object', { ...input });
|
|
129
153
|
}
|
|
130
154
|
s3DeleteObjects(input) {
|
|
131
|
-
return this.
|
|
155
|
+
return this.call('rollikey_s3_delete_objects', { ...input });
|
|
132
156
|
}
|
|
133
157
|
s3SetBucketAcl(acl, bucket) {
|
|
134
|
-
return this.
|
|
158
|
+
return this.call('rollikey_s3_set_bucket_acl', { acl, ...(bucket ? { bucket } : {}) });
|
|
135
159
|
}
|
|
136
160
|
// ---- GitHub ----
|
|
137
161
|
githubUpdateIssues(numbers, patch, target = {}) {
|
|
138
|
-
return this.
|
|
162
|
+
return this.call('rollikey_github_update_issues', { ...target, numbers, patch });
|
|
139
163
|
}
|
|
140
164
|
githubUpdatePulls(numbers, patch, target = {}) {
|
|
141
|
-
return this.
|
|
165
|
+
return this.call('rollikey_github_update_pulls', { ...target, numbers, patch });
|
|
142
166
|
}
|
|
143
167
|
githubDeleteBranches(branches, target = {}) {
|
|
144
|
-
return this.
|
|
168
|
+
return this.call('rollikey_github_delete_branches', { ...target, branches });
|
|
145
169
|
}
|
|
146
170
|
// ---- Slack ----
|
|
147
171
|
slackPost(input) {
|
|
148
|
-
return this.
|
|
172
|
+
return this.call('rollikey_slack_post', { ...input });
|
|
149
173
|
}
|
|
150
174
|
slackArchiveChannel(channel) {
|
|
151
|
-
return this.
|
|
175
|
+
return this.call('rollikey_slack_archive_channel', { channel });
|
|
152
176
|
}
|
|
153
177
|
/** The five connectors grouped by system, e.g. `run.s3.put(...)`, `run.github.deleteBranches(...)`. */
|
|
154
178
|
get postgres() {
|
|
@@ -166,11 +190,15 @@ export class RollikeyRun {
|
|
|
166
190
|
get slack() {
|
|
167
191
|
return { post: this.slackPost.bind(this), archiveChannel: this.slackArchiveChannel.bind(this), email: this.sendEmail.bind(this) };
|
|
168
192
|
}
|
|
169
|
-
|
|
170
|
-
|
|
193
|
+
/** Undo the run (LIFO). Default onDrift 'halt' stops for review on drift; { onDrift: 'overwrite' } restores anyway. */
|
|
194
|
+
revert(opts = {}) {
|
|
195
|
+
return this.call('rollikey_revert', {
|
|
196
|
+
...(opts.onDrift ? { onDrift: opts.onDrift } : {}),
|
|
197
|
+
...(opts.skipStepIds?.length ? { skipStepIds: opts.skipStepIds } : {}),
|
|
198
|
+
});
|
|
171
199
|
}
|
|
172
200
|
inspect() {
|
|
173
|
-
return this.
|
|
201
|
+
return this.call('rollikey_get_run', {});
|
|
174
202
|
}
|
|
175
203
|
}
|
|
176
204
|
//# sourceMappingURL=index.js.map
|