@runplane/runplane-sdk 1.1.0 → 1.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 +1 -122
- package/dist/index.js +17 -100
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -104,138 +104,17 @@ type RunplaneErrorCode = "BLOCKED" | "DENIED" | "TIMEOUT" | "NETWORK_ERROR" | "I
|
|
|
104
104
|
* @runplane/runplane-sdk - Main client for the Runplane API
|
|
105
105
|
*/
|
|
106
106
|
|
|
107
|
-
/**
|
|
108
|
-
* Runplane SDK Client
|
|
109
|
-
*
|
|
110
|
-
* The main entry point for interacting with the Runplane control plane.
|
|
111
|
-
* Use this to request execution clearance before performing sensitive actions.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* import { Runplane } from "@runplane/runplane-sdk";
|
|
116
|
-
*
|
|
117
|
-
* const runplane = new Runplane({
|
|
118
|
-
* apiKey: process.env.RUNPLANE_SYSTEM_KEY!,
|
|
119
|
-
* baseUrl: "https://runplane.ai",
|
|
120
|
-
* failMode: "closed"
|
|
121
|
-
* });
|
|
122
|
-
*
|
|
123
|
-
* const decision = await runplane.decide({
|
|
124
|
-
* actionType: "send_email",
|
|
125
|
-
* target: "marketing_list",
|
|
126
|
-
* context: { recipients: 1200 }
|
|
127
|
-
* });
|
|
128
|
-
*
|
|
129
|
-
* if (decision.decision === "ALLOW") {
|
|
130
|
-
* // Proceed with the action
|
|
131
|
-
* }
|
|
132
|
-
* ```
|
|
133
|
-
*/
|
|
134
107
|
declare class Runplane {
|
|
135
108
|
private readonly baseUrl;
|
|
136
109
|
private readonly apiKey;
|
|
137
110
|
private readonly timeoutMs;
|
|
138
111
|
private readonly failMode;
|
|
139
112
|
private readonly approvalPoller;
|
|
113
|
+
private hasLoggedInit;
|
|
140
114
|
constructor(config: RunplaneConfig);
|
|
141
|
-
/**
|
|
142
|
-
* Request a decision from the Runplane control plane.
|
|
143
|
-
*
|
|
144
|
-
* Call this before executing any sensitive action. The response will indicate
|
|
145
|
-
* whether the action should be ALLOWED, BLOCKED, or REQUIRE_APPROVAL.
|
|
146
|
-
*
|
|
147
|
-
* @param request - The action details to evaluate
|
|
148
|
-
* @returns The decision response
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* const decision = await runplane.decide({
|
|
153
|
-
* actionType: "delete_record",
|
|
154
|
-
* target: "users.prod",
|
|
155
|
-
* context: { recordId: "usr_123", reason: "gdpr_request" }
|
|
156
|
-
* });
|
|
157
|
-
*
|
|
158
|
-
* switch (decision.decision) {
|
|
159
|
-
* case "ALLOW":
|
|
160
|
-
* await deleteRecord(recordId);
|
|
161
|
-
* break;
|
|
162
|
-
* case "BLOCK":
|
|
163
|
-
* console.error("Action blocked:", decision.reason);
|
|
164
|
-
* break;
|
|
165
|
-
* case "REQUIRE_APPROVAL":
|
|
166
|
-
* // Wait for human approval
|
|
167
|
-
* const result = await runplane.waitForApproval(decision.requestId);
|
|
168
|
-
* if (result.approved) {
|
|
169
|
-
* await deleteRecord(recordId);
|
|
170
|
-
* }
|
|
171
|
-
* break;
|
|
172
|
-
* }
|
|
173
|
-
* ```
|
|
174
|
-
*/
|
|
175
115
|
decide(request: DecideRequest): Promise<DecideResponse>;
|
|
176
|
-
/**
|
|
177
|
-
* Wait for an approval decision on a pending request.
|
|
178
|
-
*
|
|
179
|
-
* Use this when decide() returns REQUIRE_APPROVAL. This method will poll
|
|
180
|
-
* the approval endpoint until the request is approved, denied, or times out.
|
|
181
|
-
*
|
|
182
|
-
* @param requestId - The requestId from the decide() response
|
|
183
|
-
* @param options - Optional configuration for polling behavior
|
|
184
|
-
* @returns The approval result
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* ```typescript
|
|
188
|
-
* const decision = await runplane.decide({ ... });
|
|
189
|
-
*
|
|
190
|
-
* if (decision.decision === "REQUIRE_APPROVAL") {
|
|
191
|
-
* console.log("Waiting for approval...");
|
|
192
|
-
*
|
|
193
|
-
* const result = await runplane.waitForApproval(decision.requestId, {
|
|
194
|
-
* timeoutMs: 600000, // 10 minutes
|
|
195
|
-
* onPoll: (status, elapsed) => {
|
|
196
|
-
* console.log(`Still waiting... ${elapsed}ms elapsed`);
|
|
197
|
-
* }
|
|
198
|
-
* });
|
|
199
|
-
*
|
|
200
|
-
* if (result.approved) {
|
|
201
|
-
* console.log("Approved by:", result.resolvedBy);
|
|
202
|
-
* } else {
|
|
203
|
-
* console.log("Denied:", result.comment);
|
|
204
|
-
* }
|
|
205
|
-
* }
|
|
206
|
-
* ```
|
|
207
|
-
*/
|
|
208
116
|
waitForApproval(requestId: string, options?: WaitForApprovalOptions): Promise<WaitForApprovalResult>;
|
|
209
|
-
/**
|
|
210
|
-
* Guard a function with containment evaluation.
|
|
211
|
-
*
|
|
212
|
-
* This is a convenience method that wraps decide() and waitForApproval()
|
|
213
|
-
* into a single call. If the action is blocked or denied, it throws.
|
|
214
|
-
* If approved, it executes the provided function.
|
|
215
|
-
*
|
|
216
|
-
* @param actionType - Type of action being performed
|
|
217
|
-
* @param target - Target resource
|
|
218
|
-
* @param context - Additional context
|
|
219
|
-
* @param fn - Function to execute if allowed
|
|
220
|
-
* @returns The result of fn()
|
|
221
|
-
* @throws RunplaneError if blocked, denied, or times out (in closed mode)
|
|
222
|
-
*
|
|
223
|
-
* @example
|
|
224
|
-
* ```typescript
|
|
225
|
-
* const result = await runplane.guard(
|
|
226
|
-
* "payment_transfer",
|
|
227
|
-
* "external_bank",
|
|
228
|
-
* { amount: 50000, currency: "USD" },
|
|
229
|
-
* async () => {
|
|
230
|
-
* return await paymentService.transfer(amount, recipient);
|
|
231
|
-
* }
|
|
232
|
-
* );
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
117
|
guard<T>(actionType: string, target: string, context: Record<string, unknown> | null, fn: () => Promise<T>): Promise<T>;
|
|
236
|
-
/**
|
|
237
|
-
* Handle API failures according to failMode
|
|
238
|
-
*/
|
|
239
118
|
private handleFailure;
|
|
240
119
|
}
|
|
241
120
|
|
package/dist/index.js
CHANGED
|
@@ -138,10 +138,16 @@ var DEFAULT_APPROVAL_TIMEOUT_MS = 3e5;
|
|
|
138
138
|
var DEFAULT_APPROVAL_POLL_INTERVAL_MS = 2e3;
|
|
139
139
|
var Runplane = class {
|
|
140
140
|
constructor(config) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
// 🔥 New: log only once per instance
|
|
142
|
+
this.hasLoggedInit = false;
|
|
143
|
+
if (!config?.apiKey || config.apiKey.trim() === "") {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`Runplane API key is required.
|
|
146
|
+
|
|
147
|
+
\u{1F449} Start your free 14-day trial:
|
|
148
|
+
https://runplane.ai/
|
|
149
|
+
|
|
150
|
+
Then add your API key to the SDK config.`
|
|
145
151
|
);
|
|
146
152
|
}
|
|
147
153
|
this.apiKey = config.apiKey;
|
|
@@ -155,40 +161,6 @@ var Runplane = class {
|
|
|
155
161
|
pollIntervalMs: config.approvalPollIntervalMs ?? DEFAULT_APPROVAL_POLL_INTERVAL_MS
|
|
156
162
|
});
|
|
157
163
|
}
|
|
158
|
-
/**
|
|
159
|
-
* Request a decision from the Runplane control plane.
|
|
160
|
-
*
|
|
161
|
-
* Call this before executing any sensitive action. The response will indicate
|
|
162
|
-
* whether the action should be ALLOWED, BLOCKED, or REQUIRE_APPROVAL.
|
|
163
|
-
*
|
|
164
|
-
* @param request - The action details to evaluate
|
|
165
|
-
* @returns The decision response
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* ```typescript
|
|
169
|
-
* const decision = await runplane.decide({
|
|
170
|
-
* actionType: "delete_record",
|
|
171
|
-
* target: "users.prod",
|
|
172
|
-
* context: { recordId: "usr_123", reason: "gdpr_request" }
|
|
173
|
-
* });
|
|
174
|
-
*
|
|
175
|
-
* switch (decision.decision) {
|
|
176
|
-
* case "ALLOW":
|
|
177
|
-
* await deleteRecord(recordId);
|
|
178
|
-
* break;
|
|
179
|
-
* case "BLOCK":
|
|
180
|
-
* console.error("Action blocked:", decision.reason);
|
|
181
|
-
* break;
|
|
182
|
-
* case "REQUIRE_APPROVAL":
|
|
183
|
-
* // Wait for human approval
|
|
184
|
-
* const result = await runplane.waitForApproval(decision.requestId);
|
|
185
|
-
* if (result.approved) {
|
|
186
|
-
* await deleteRecord(recordId);
|
|
187
|
-
* }
|
|
188
|
-
* break;
|
|
189
|
-
* }
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
164
|
async decide(request) {
|
|
193
165
|
const controller = new AbortController();
|
|
194
166
|
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
@@ -197,7 +169,7 @@ var Runplane = class {
|
|
|
197
169
|
method: "POST",
|
|
198
170
|
headers: {
|
|
199
171
|
"Content-Type": "application/json",
|
|
200
|
-
|
|
172
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
201
173
|
},
|
|
202
174
|
body: JSON.stringify({
|
|
203
175
|
agentKey: this.apiKey,
|
|
@@ -240,68 +212,16 @@ var Runplane = class {
|
|
|
240
212
|
clearTimeout(timeout);
|
|
241
213
|
}
|
|
242
214
|
}
|
|
243
|
-
/**
|
|
244
|
-
* Wait for an approval decision on a pending request.
|
|
245
|
-
*
|
|
246
|
-
* Use this when decide() returns REQUIRE_APPROVAL. This method will poll
|
|
247
|
-
* the approval endpoint until the request is approved, denied, or times out.
|
|
248
|
-
*
|
|
249
|
-
* @param requestId - The requestId from the decide() response
|
|
250
|
-
* @param options - Optional configuration for polling behavior
|
|
251
|
-
* @returns The approval result
|
|
252
|
-
*
|
|
253
|
-
* @example
|
|
254
|
-
* ```typescript
|
|
255
|
-
* const decision = await runplane.decide({ ... });
|
|
256
|
-
*
|
|
257
|
-
* if (decision.decision === "REQUIRE_APPROVAL") {
|
|
258
|
-
* console.log("Waiting for approval...");
|
|
259
|
-
*
|
|
260
|
-
* const result = await runplane.waitForApproval(decision.requestId, {
|
|
261
|
-
* timeoutMs: 600000, // 10 minutes
|
|
262
|
-
* onPoll: (status, elapsed) => {
|
|
263
|
-
* console.log(`Still waiting... ${elapsed}ms elapsed`);
|
|
264
|
-
* }
|
|
265
|
-
* });
|
|
266
|
-
*
|
|
267
|
-
* if (result.approved) {
|
|
268
|
-
* console.log("Approved by:", result.resolvedBy);
|
|
269
|
-
* } else {
|
|
270
|
-
* console.log("Denied:", result.comment);
|
|
271
|
-
* }
|
|
272
|
-
* }
|
|
273
|
-
* ```
|
|
274
|
-
*/
|
|
275
215
|
async waitForApproval(requestId, options) {
|
|
276
216
|
return this.approvalPoller.poll(requestId, options);
|
|
277
217
|
}
|
|
278
|
-
/**
|
|
279
|
-
* Guard a function with containment evaluation.
|
|
280
|
-
*
|
|
281
|
-
* This is a convenience method that wraps decide() and waitForApproval()
|
|
282
|
-
* into a single call. If the action is blocked or denied, it throws.
|
|
283
|
-
* If approved, it executes the provided function.
|
|
284
|
-
*
|
|
285
|
-
* @param actionType - Type of action being performed
|
|
286
|
-
* @param target - Target resource
|
|
287
|
-
* @param context - Additional context
|
|
288
|
-
* @param fn - Function to execute if allowed
|
|
289
|
-
* @returns The result of fn()
|
|
290
|
-
* @throws RunplaneError if blocked, denied, or times out (in closed mode)
|
|
291
|
-
*
|
|
292
|
-
* @example
|
|
293
|
-
* ```typescript
|
|
294
|
-
* const result = await runplane.guard(
|
|
295
|
-
* "payment_transfer",
|
|
296
|
-
* "external_bank",
|
|
297
|
-
* { amount: 50000, currency: "USD" },
|
|
298
|
-
* async () => {
|
|
299
|
-
* return await paymentService.transfer(amount, recipient);
|
|
300
|
-
* }
|
|
301
|
-
* );
|
|
302
|
-
* ```
|
|
303
|
-
*/
|
|
304
218
|
async guard(actionType, target, context, fn) {
|
|
219
|
+
if (!this.hasLoggedInit) {
|
|
220
|
+
console.log(
|
|
221
|
+
"Runplane active. Manage your policies at https://runplane.ai/"
|
|
222
|
+
);
|
|
223
|
+
this.hasLoggedInit = true;
|
|
224
|
+
}
|
|
305
225
|
const response = await this.decide({
|
|
306
226
|
actionType,
|
|
307
227
|
target,
|
|
@@ -337,9 +257,6 @@ var Runplane = class {
|
|
|
337
257
|
response.requestId
|
|
338
258
|
);
|
|
339
259
|
}
|
|
340
|
-
/**
|
|
341
|
-
* Handle API failures according to failMode
|
|
342
|
-
*/
|
|
343
260
|
handleFailure(reason, request) {
|
|
344
261
|
const requestId = request.requestId ?? crypto.randomUUID();
|
|
345
262
|
if (this.failMode === "open") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runplane/runplane-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Runtime governance SDK for AI agent actions. Wrap sensitive operations with guard() to enforce ALLOW, BLOCK, or REQUIRE_APPROVAL decisions before execution.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|