forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-guards.ts
More file actions
35 lines (32 loc) · 920 Bytes
/
Copy pathruntime-guards.ts
File metadata and controls
35 lines (32 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { RuntimeError } from "../errors/runtime-errors.js";
export function assertRuntimeStarted(isStarted: boolean): void {
if (!isStarted) {
throw new RuntimeError(
"RUNTIME_NOT_STARTED",
"AgentRuntime must be started before executing tasks."
);
}
}
export function assertNonEmptyValue(
value: string,
fieldName: string,
code: "INVALID_TASK" | "EXECUTION_FAILED" = "INVALID_TASK"
): void {
if (value.trim().length === 0) {
throw new RuntimeError(code, `${fieldName} must be a non-empty string.`, {
fieldName
});
}
}
export function assertMaxToolCalls(
currentToolCalls: number,
maxToolCalls: number
): void {
if (maxToolCalls >= 0 && currentToolCalls >= maxToolCalls) {
throw new RuntimeError(
"MAX_TOOL_CALLS_EXCEEDED",
`Task exceeded maximum allowed tool calls limit of ${maxToolCalls}.`,
{ currentToolCalls, maxToolCalls }
);
}
}