@clearideas/agent-runtime-step-standard 0.6.2 → 0.7.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/dist/index.d.ts +4 -1
- package/dist/index.js +48 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ApprovalStep, CodeStep, SubRunStep, WebhookStep } from "@clearideas/agent-runtime-contracts";
|
|
2
|
-
import type { StepExecutionContext, StepExecutionResult, StepExecutor } from "@clearideas/agent-runtime-core";
|
|
2
|
+
import type { StepExecutionContext, StepExecutionResult, StepExecutor, StepPreflightContext } from "@clearideas/agent-runtime-core";
|
|
3
3
|
export type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
4
4
|
export type Sleep = (delayMs: number, signal?: AbortSignal) => Promise<void>;
|
|
5
5
|
export interface ApprovalStepExecutorOptions {
|
|
@@ -45,6 +45,7 @@ export interface CodeStepExecutorOptions {
|
|
|
45
45
|
*/
|
|
46
46
|
export declare class SubRunStepExecutor implements StepExecutor<SubRunStep> {
|
|
47
47
|
readonly type: "sub-run";
|
|
48
|
+
preflight(step: SubRunStep, context: StepPreflightContext): string[];
|
|
48
49
|
execute(context: StepExecutionContext & {
|
|
49
50
|
step: SubRunStep;
|
|
50
51
|
}): Promise<StepExecutionResult>;
|
|
@@ -86,6 +87,7 @@ export declare class SandboxTimeoutError extends Error {
|
|
|
86
87
|
export declare class ApprovalStepExecutor implements StepExecutor<ApprovalStep> {
|
|
87
88
|
#private;
|
|
88
89
|
readonly type: "approval";
|
|
90
|
+
preflight(step: ApprovalStep, context: StepPreflightContext): string[];
|
|
89
91
|
constructor(options?: ApprovalStepExecutorOptions);
|
|
90
92
|
execute(context: StepExecutionContext & {
|
|
91
93
|
step: ApprovalStep;
|
|
@@ -102,6 +104,7 @@ export declare class WebhookStepExecutor implements StepExecutor<WebhookStep> {
|
|
|
102
104
|
export declare class CodeStepExecutor implements StepExecutor<CodeStep> {
|
|
103
105
|
#private;
|
|
104
106
|
readonly type: "code";
|
|
107
|
+
preflight(step: CodeStep, context: StepPreflightContext): string[];
|
|
105
108
|
constructor(options?: CodeStepExecutorOptions);
|
|
106
109
|
execute(context: StepExecutionContext & {
|
|
107
110
|
step: CodeStep;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compilePromptTemplate, RunSuspendedError, } from "@clearideas/agent-runtime-core";
|
|
1
|
+
import { compilePromptTemplate, RunCancelledError, RunSuspendedError, } from "@clearideas/agent-runtime-core";
|
|
2
2
|
const getMappedVariable = (variables, path) => {
|
|
3
3
|
let current = variables;
|
|
4
4
|
for (const segment of path.split(".")) {
|
|
@@ -22,6 +22,11 @@ const getMappedVariable = (variables, path) => {
|
|
|
22
22
|
*/
|
|
23
23
|
export class SubRunStepExecutor {
|
|
24
24
|
type = "sub-run";
|
|
25
|
+
preflight(step, context) {
|
|
26
|
+
return context.subRuns
|
|
27
|
+
? []
|
|
28
|
+
: [`Sub-run step ${step.id} requires a SubRunAdapter.`];
|
|
29
|
+
}
|
|
25
30
|
async execute(context) {
|
|
26
31
|
if (!context.subRuns) {
|
|
27
32
|
throw new Error(`Sub-run step ${context.step.id} requires a SubRunAdapter`);
|
|
@@ -275,6 +280,11 @@ const statePatch = (outputVariable, output) => outputVariable && output !== unde
|
|
|
275
280
|
export class ApprovalStepExecutor {
|
|
276
281
|
type = "approval";
|
|
277
282
|
#timeoutMs;
|
|
283
|
+
preflight(step, context) {
|
|
284
|
+
return context.approvals
|
|
285
|
+
? []
|
|
286
|
+
: [`Approval step ${step.id} requires an ApprovalAdapter.`];
|
|
287
|
+
}
|
|
278
288
|
constructor(options = {}) {
|
|
279
289
|
if (options.timeoutMs !== undefined &&
|
|
280
290
|
(!Number.isInteger(options.timeoutMs) || options.timeoutMs <= 0)) {
|
|
@@ -319,6 +329,31 @@ export class ApprovalStepExecutor {
|
|
|
319
329
|
hasResponse: result.response !== undefined,
|
|
320
330
|
});
|
|
321
331
|
if (!result.approved) {
|
|
332
|
+
const onReject = context.step.onReject ?? "fail";
|
|
333
|
+
if (onReject === "cancel") {
|
|
334
|
+
throw new RunCancelledError(`Approval was rejected for step ${context.step.id}; the run was cancelled.`, { stepId: context.step.id });
|
|
335
|
+
}
|
|
336
|
+
if (onReject === "continue" || onReject === "complete") {
|
|
337
|
+
const rejected = {
|
|
338
|
+
approved: false,
|
|
339
|
+
respondedAt: result.respondedAt,
|
|
340
|
+
...(result.response !== undefined
|
|
341
|
+
? { response: result.response }
|
|
342
|
+
: {}),
|
|
343
|
+
};
|
|
344
|
+
const rejectedPatch = statePatch(context.step.outputVariable, rejected);
|
|
345
|
+
return {
|
|
346
|
+
output: rejected,
|
|
347
|
+
...(rejectedPatch ? { statePatch: rejectedPatch } : {}),
|
|
348
|
+
...(onReject === "complete" ? { endRun: true } : {}),
|
|
349
|
+
metadata: {
|
|
350
|
+
approved: false,
|
|
351
|
+
hasResponse: result.response !== undefined,
|
|
352
|
+
action: context.step.action ?? "pause",
|
|
353
|
+
onReject,
|
|
354
|
+
},
|
|
355
|
+
};
|
|
356
|
+
}
|
|
322
357
|
throw new ApprovalRejectedError(context.step.id, context.step.action);
|
|
323
358
|
}
|
|
324
359
|
const output = {
|
|
@@ -596,6 +631,18 @@ export class CodeStepExecutor {
|
|
|
596
631
|
type = "code";
|
|
597
632
|
#defaultTimeoutMs;
|
|
598
633
|
#maximumTimeoutMs;
|
|
634
|
+
preflight(step, context) {
|
|
635
|
+
const usesRunSandbox = step.sandbox === "run" ||
|
|
636
|
+
(step.sandbox !== "step" && (step.workspaces?.length ?? 0) > 0);
|
|
637
|
+
if (usesRunSandbox) {
|
|
638
|
+
return context.runSandbox
|
|
639
|
+
? []
|
|
640
|
+
: [`Code step ${step.id} requires a RunSandboxProvider.`];
|
|
641
|
+
}
|
|
642
|
+
return context.sandbox
|
|
643
|
+
? []
|
|
644
|
+
: [`Code step ${step.id} requires a SandboxAdapter.`];
|
|
645
|
+
}
|
|
599
646
|
constructor(options = {}) {
|
|
600
647
|
this.#defaultTimeoutMs = options.defaultTimeoutMs ?? 60_000;
|
|
601
648
|
this.#maximumTimeoutMs = options.maximumTimeoutMs ?? 900_000;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clearideas/agent-runtime-step-standard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Approval, webhook, and sandboxed code executors for Clear Ideas Agent Runtime.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Clear Ideas Incorporated",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"postpack": "node ../../scripts/cleanup-package-license.mjs"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@clearideas/agent-runtime-contracts": "0.
|
|
40
|
-
"@clearideas/agent-runtime-core": "0.
|
|
39
|
+
"@clearideas/agent-runtime-contracts": "0.7.0",
|
|
40
|
+
"@clearideas/agent-runtime-core": "0.7.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"typescript": "^7.0.2",
|
|
44
|
-
"vitest": "^5.
|
|
44
|
+
"vitest": "^5.1.0"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=24"
|