@clearideas/agent-runtime-step-standard 1.0.1 → 1.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/dist/decision.d.ts +9 -0
- package/dist/decision.js +64 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DecisionStep } from "@clearideas/agent-runtime-contracts";
|
|
2
|
+
import { type StepExecutor, type StepExecutionContext, type StepPreflightContext, type StepExecutionResult } from "@clearideas/agent-runtime-core";
|
|
3
|
+
export declare class DecisionStepExecutor implements StepExecutor<DecisionStep> {
|
|
4
|
+
readonly type = "decision";
|
|
5
|
+
preflight(step: DecisionStep, context: StepPreflightContext): string[];
|
|
6
|
+
execute(context: StepExecutionContext & {
|
|
7
|
+
step: DecisionStep;
|
|
8
|
+
}): Promise<StepExecutionResult>;
|
|
9
|
+
}
|
package/dist/decision.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getVariableAtPath, RunSuspendedError, validateDecisionAnswer, } from "@clearideas/agent-runtime-core";
|
|
2
|
+
export class DecisionStepExecutor {
|
|
3
|
+
type = "decision";
|
|
4
|
+
preflight(step, context) {
|
|
5
|
+
return context.decisions?.has(step.decisionModel.ref)
|
|
6
|
+
? []
|
|
7
|
+
: [
|
|
8
|
+
`Unknown decision model binding "${step.decisionModel.ref}" for step ${step.id}.`,
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
async execute(context) {
|
|
12
|
+
const { step, decisions, tokenBudget } = context;
|
|
13
|
+
const ref = step.decisionModel.ref;
|
|
14
|
+
if (!decisions?.has(ref))
|
|
15
|
+
throw new Error(`Unknown decision model binding "${ref}".`);
|
|
16
|
+
const input = "fromVariable" in step.input
|
|
17
|
+
? getVariableAtPath(context.variables, step.input.fromVariable)
|
|
18
|
+
: step.input.literal;
|
|
19
|
+
if (input === undefined)
|
|
20
|
+
throw new Error("Decision input variable is missing.");
|
|
21
|
+
if (tokenBudget && tokenBudget.consumedTokens >= tokenBudget.maxTotalTokens)
|
|
22
|
+
throw new RunSuspendedError("token-budget", {
|
|
23
|
+
maxTotalTokens: tokenBudget.maxTotalTokens,
|
|
24
|
+
consumedTokens: tokenBudget.consumedTokens,
|
|
25
|
+
stepId: step.id,
|
|
26
|
+
});
|
|
27
|
+
const started = Date.now();
|
|
28
|
+
const result = await decisions.decide({
|
|
29
|
+
ref,
|
|
30
|
+
input,
|
|
31
|
+
question: step.question,
|
|
32
|
+
signal: context.signal,
|
|
33
|
+
});
|
|
34
|
+
tokenBudget?.consume(result.usage ?? {});
|
|
35
|
+
validateDecisionAnswer(step.question, result.answer);
|
|
36
|
+
const metadata = {
|
|
37
|
+
provider: result.provider,
|
|
38
|
+
model: result.model,
|
|
39
|
+
ref,
|
|
40
|
+
durationMs: Date.now() - started,
|
|
41
|
+
...(result.requestId ? { requestId: result.requestId } : {}),
|
|
42
|
+
...(result.providerConfidence === undefined
|
|
43
|
+
? {}
|
|
44
|
+
: { providerConfidence: result.providerConfidence }),
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
output: result.answer,
|
|
48
|
+
...(step.outputVariable
|
|
49
|
+
? { statePatch: { set: { [step.outputVariable]: result.answer } } }
|
|
50
|
+
: {}),
|
|
51
|
+
metadata,
|
|
52
|
+
transcript: [
|
|
53
|
+
{
|
|
54
|
+
id: crypto.randomUUID(),
|
|
55
|
+
type: "decision",
|
|
56
|
+
content: [],
|
|
57
|
+
createdAt: new Date().toISOString(),
|
|
58
|
+
metadata,
|
|
59
|
+
...(result.usage ? { usage: result.usage } : {}),
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clearideas/agent-runtime-step-standard",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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,8 +36,8 @@
|
|
|
36
36
|
"postpack": "node ../../scripts/cleanup-package-license.mjs"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@clearideas/agent-runtime-contracts": "1.0
|
|
40
|
-
"@clearideas/agent-runtime-core": "1.0
|
|
39
|
+
"@clearideas/agent-runtime-contracts": "1.1.0",
|
|
40
|
+
"@clearideas/agent-runtime-core": "1.1.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"typescript": "^7.0.2",
|