@travisliu/open-dynamic-workflow 0.3.1 → 0.3.5
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/CHANGELOG.md +16 -0
- package/README.md +43 -17
- package/dist/agents/codex-exec.js +3 -1
- package/dist/agents/codex-exec.js.map +1 -1
- package/dist/agents/cursor-agent.d.ts +21 -0
- package/dist/agents/cursor-agent.js +171 -0
- package/dist/agents/cursor-agent.js.map +1 -0
- package/dist/agents/execute-agent.js +1 -1
- package/dist/agents/execute-agent.js.map +1 -1
- package/dist/agents/registry.js +2 -0
- package/dist/agents/registry.js.map +1 -1
- package/dist/artifacts/call-cache.d.ts +27 -3
- package/dist/artifacts/call-cache.js +160 -59
- package/dist/artifacts/call-cache.js.map +1 -1
- package/dist/artifacts/run-store.js.map +1 -1
- package/dist/cli/commands/doctor.js +0 -4
- package/dist/cli/commands/doctor.js.map +1 -1
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/run.js +2 -1
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli/commands/validate.js +2 -1
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/init/prompts.d.ts +1 -1
- package/dist/cli/init/prompts.js +4 -4
- package/dist/cli/init/prompts.js.map +1 -1
- package/dist/cli/init/renderer.js +2 -1
- package/dist/cli/init/renderer.js.map +1 -1
- package/dist/config/defaults.js +2 -1
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/load.js +1 -1
- package/dist/config/load.js.map +1 -1
- package/dist/config/schema.js +3 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/config/types.d.ts +1 -0
- package/dist/discovery/collect-files.js +2 -2
- package/dist/discovery/collect-files.js.map +1 -1
- package/dist/discovery/definition-call.js +1 -1
- package/dist/discovery/definition-call.js.map +1 -1
- package/dist/discovery/file-patterns.js +1 -1
- package/dist/discovery/file-patterns.js.map +1 -1
- package/dist/discovery/schema-summary.js.map +1 -1
- package/dist/loop/artifacts.d.ts +39 -0
- package/dist/loop/artifacts.js +58 -0
- package/dist/loop/artifacts.js.map +1 -0
- package/dist/loop/context.d.ts +55 -0
- package/dist/loop/context.js +134 -0
- package/dist/loop/context.js.map +1 -0
- package/dist/loop/events.d.ts +62 -0
- package/dist/loop/events.js +68 -0
- package/dist/loop/events.js.map +1 -0
- package/dist/loop/id.d.ts +24 -0
- package/dist/loop/id.js +65 -0
- package/dist/loop/id.js.map +1 -0
- package/dist/loop/index.d.ts +8 -0
- package/dist/loop/index.js +9 -0
- package/dist/loop/index.js.map +1 -0
- package/dist/loop/replay.d.ts +47 -0
- package/dist/loop/replay.js +104 -0
- package/dist/loop/replay.js.map +1 -0
- package/dist/loop/results.d.ts +74 -0
- package/dist/loop/results.js +101 -0
- package/dist/loop/results.js.map +1 -0
- package/dist/loop/run.d.ts +22 -0
- package/dist/loop/run.js +671 -0
- package/dist/loop/run.js.map +1 -0
- package/dist/loop/summary.d.ts +5 -0
- package/dist/loop/summary.js +16 -0
- package/dist/loop/summary.js.map +1 -0
- package/dist/loop/types.d.ts +120 -0
- package/dist/loop/types.js +2 -0
- package/dist/loop/types.js.map +1 -0
- package/dist/loop/validate.d.ts +9 -0
- package/dist/loop/validate.js +122 -0
- package/dist/loop/validate.js.map +1 -0
- package/dist/orchestration/scheduler.js +1 -1
- package/dist/orchestration/scheduler.js.map +1 -1
- package/dist/output/events.d.ts +49 -1
- package/dist/output/events.js.map +1 -1
- package/dist/output/failed-artifacts.js +5 -0
- package/dist/output/failed-artifacts.js.map +1 -1
- package/dist/output/json-reporter.d.ts +2 -2
- package/dist/output/json-reporter.js +1 -1
- package/dist/output/json-reporter.js.map +1 -1
- package/dist/output/jsonl-reporter.d.ts +3 -4
- package/dist/output/jsonl-reporter.js +2 -2
- package/dist/output/jsonl-reporter.js.map +1 -1
- package/dist/output/pretty-renderer.js +15 -0
- package/dist/output/pretty-renderer.js.map +1 -1
- package/dist/output/pretty-reporter.js +35 -4
- package/dist/output/pretty-reporter.js.map +1 -1
- package/dist/output/pretty-view-builder.js +70 -1
- package/dist/output/pretty-view-builder.js.map +1 -1
- package/dist/output/pretty-view.d.ts +12 -2
- package/dist/output/verbose-formatter.d.ts +4 -1
- package/dist/output/verbose-formatter.js +67 -0
- package/dist/output/verbose-formatter.js.map +1 -1
- package/dist/pipeline/stage-barrier.js.map +1 -1
- package/dist/pipeline/validate.js +1 -1
- package/dist/pipeline/validate.js.map +1 -1
- package/dist/shared-agents/load.js +0 -2
- package/dist/shared-agents/load.js.map +1 -1
- package/dist/tools/load.js.map +1 -1
- package/dist/types/config.d.ts +1 -0
- package/dist/types/workflow.d.ts +13 -0
- package/dist/workflow/discovery.d.ts +1 -0
- package/dist/workflow/discovery.js +6 -4
- package/dist/workflow/discovery.js.map +1 -1
- package/dist/workflow/dsl.d.ts +1 -0
- package/dist/workflow/dsl.js +281 -137
- package/dist/workflow/dsl.js.map +1 -1
- package/dist/workflow/errors.js +1 -1
- package/dist/workflow/errors.js.map +1 -1
- package/dist/workflow/invocation-manager.js +14 -2
- package/dist/workflow/invocation-manager.js.map +1 -1
- package/dist/workflow/resolve-target.js +1 -1
- package/dist/workflow/resolve-target.js.map +1 -1
- package/dist/workflow/runtime.js +6 -1
- package/dist/workflow/runtime.js.map +1 -1
- package/dist/workflow/sandbox.js +1 -0
- package/dist/workflow/sandbox.js.map +1 -1
- package/dist/workflow/scope.d.ts +1 -1
- package/dist/workflow/scope.js +2 -15
- package/dist/workflow/scope.js.map +1 -1
- package/dist/workflow/types.d.ts +3 -0
- package/dist/workflow/validate.d.ts +2 -0
- package/dist/workflow/validate.js +369 -46
- package/dist/workflow/validate.js.map +1 -1
- package/package.json +5 -2
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { LoopRoundStatus } from "./types.js";
|
|
2
|
+
import type { SerializedError } from "../types/errors.js";
|
|
3
|
+
import type { LoopStartedPayload, LoopRoundStartedPayload, LoopRoundTerminalPayload, LoopTerminalPayload } from "../output/events.js";
|
|
4
|
+
/**
|
|
5
|
+
* Builds the payload for a loop.started event.
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildLoopStartedPayload(input: {
|
|
8
|
+
loopId: string;
|
|
9
|
+
workflowInvocationId: string;
|
|
10
|
+
label: string;
|
|
11
|
+
parentLoopId?: string;
|
|
12
|
+
maxRounds: number;
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
artifactPath?: string;
|
|
15
|
+
}): LoopStartedPayload;
|
|
16
|
+
/**
|
|
17
|
+
* Builds the payload for a loop.round.started event.
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildLoopRoundStartedPayload(input: {
|
|
20
|
+
loopId: string;
|
|
21
|
+
workflowInvocationId: string;
|
|
22
|
+
label: string;
|
|
23
|
+
roundIndex: number;
|
|
24
|
+
roundNumber: number;
|
|
25
|
+
roundId: string;
|
|
26
|
+
startedAt: string;
|
|
27
|
+
artifactPath?: string;
|
|
28
|
+
}): LoopRoundStartedPayload;
|
|
29
|
+
/**
|
|
30
|
+
* Builds the payload for a loop.round terminal event (completed, failed, cancelled, timed_out).
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildLoopRoundTerminalPayload(input: {
|
|
33
|
+
loopId: string;
|
|
34
|
+
workflowInvocationId: string;
|
|
35
|
+
label: string;
|
|
36
|
+
roundIndex: number;
|
|
37
|
+
roundNumber: number;
|
|
38
|
+
roundId: string;
|
|
39
|
+
status: LoopRoundStatus;
|
|
40
|
+
durationMs: number;
|
|
41
|
+
statePreview?: unknown;
|
|
42
|
+
reason?: string;
|
|
43
|
+
artifactPath?: string;
|
|
44
|
+
error?: SerializedError;
|
|
45
|
+
}): LoopRoundTerminalPayload;
|
|
46
|
+
/**
|
|
47
|
+
* Builds the payload for a loop terminal event.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildLoopTerminalPayload(input: {
|
|
50
|
+
loopId: string;
|
|
51
|
+
workflowInvocationId: string;
|
|
52
|
+
label: string;
|
|
53
|
+
status: "succeeded" | "max_rounds" | "failed" | "cancelled" | "timed_out";
|
|
54
|
+
roundsCompleted: number;
|
|
55
|
+
roundCount: number;
|
|
56
|
+
maxRounds: number;
|
|
57
|
+
durationMs: number;
|
|
58
|
+
reason?: string;
|
|
59
|
+
artifactPath?: string;
|
|
60
|
+
error?: SerializedError;
|
|
61
|
+
statePreview?: unknown;
|
|
62
|
+
}): LoopTerminalPayload;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the payload for a loop.started event.
|
|
3
|
+
*/
|
|
4
|
+
export function buildLoopStartedPayload(input) {
|
|
5
|
+
return {
|
|
6
|
+
loopId: input.loopId,
|
|
7
|
+
workflowInvocationId: input.workflowInvocationId,
|
|
8
|
+
label: input.label,
|
|
9
|
+
...(input.parentLoopId !== undefined ? { parentLoopId: input.parentLoopId } : {}),
|
|
10
|
+
maxRounds: input.maxRounds,
|
|
11
|
+
...(input.timeoutMs !== undefined ? { timeoutMs: input.timeoutMs } : {}),
|
|
12
|
+
...(input.artifactPath !== undefined ? { artifactPath: input.artifactPath } : {}),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Builds the payload for a loop.round.started event.
|
|
17
|
+
*/
|
|
18
|
+
export function buildLoopRoundStartedPayload(input) {
|
|
19
|
+
return {
|
|
20
|
+
loopId: input.loopId,
|
|
21
|
+
workflowInvocationId: input.workflowInvocationId,
|
|
22
|
+
label: input.label,
|
|
23
|
+
roundIndex: input.roundIndex,
|
|
24
|
+
roundNumber: input.roundNumber,
|
|
25
|
+
roundId: input.roundId,
|
|
26
|
+
startedAt: input.startedAt,
|
|
27
|
+
...(input.artifactPath !== undefined ? { artifactPath: input.artifactPath } : {}),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Builds the payload for a loop.round terminal event (completed, failed, cancelled, timed_out).
|
|
32
|
+
*/
|
|
33
|
+
export function buildLoopRoundTerminalPayload(input) {
|
|
34
|
+
return {
|
|
35
|
+
loopId: input.loopId,
|
|
36
|
+
workflowInvocationId: input.workflowInvocationId,
|
|
37
|
+
label: input.label,
|
|
38
|
+
roundIndex: input.roundIndex,
|
|
39
|
+
roundNumber: input.roundNumber,
|
|
40
|
+
roundId: input.roundId,
|
|
41
|
+
status: input.status,
|
|
42
|
+
durationMs: input.durationMs,
|
|
43
|
+
...(input.statePreview !== undefined ? { statePreview: input.statePreview } : {}),
|
|
44
|
+
...(input.reason !== undefined ? { reason: input.reason } : {}),
|
|
45
|
+
...(input.artifactPath !== undefined ? { artifactPath: input.artifactPath } : {}),
|
|
46
|
+
...(input.error !== undefined ? { error: input.error } : {}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Builds the payload for a loop terminal event.
|
|
51
|
+
*/
|
|
52
|
+
export function buildLoopTerminalPayload(input) {
|
|
53
|
+
return {
|
|
54
|
+
loopId: input.loopId,
|
|
55
|
+
workflowInvocationId: input.workflowInvocationId,
|
|
56
|
+
label: input.label,
|
|
57
|
+
status: input.status,
|
|
58
|
+
roundsCompleted: input.roundsCompleted,
|
|
59
|
+
roundCount: input.roundCount,
|
|
60
|
+
maxRounds: input.maxRounds,
|
|
61
|
+
durationMs: input.durationMs,
|
|
62
|
+
...(input.reason !== undefined ? { reason: input.reason } : {}),
|
|
63
|
+
...(input.artifactPath !== undefined ? { artifactPath: input.artifactPath } : {}),
|
|
64
|
+
...(input.error !== undefined ? { error: input.error } : {}),
|
|
65
|
+
...(input.statePreview !== undefined ? { statePreview: input.statePreview } : {}),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/loop/events.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAQvC;IACC,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,oBAAoB,EAAE,KA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C,KAAK,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjF,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,GAAG,CAAC,KAAK,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a stable loop identifier.
|
|
3
|
+
*/
|
|
4
|
+
export declare function createLoopId(label: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a stable round identifier.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createRoundId(loopId: string, roundNumber: number): string;
|
|
9
|
+
/**
|
|
10
|
+
* Input for createLoopAgentId.
|
|
11
|
+
*/
|
|
12
|
+
export interface CreateLoopAgentIdInput {
|
|
13
|
+
label: string;
|
|
14
|
+
roundNumber: number;
|
|
15
|
+
suffix?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes a loop label for use in IDs.
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeLoopLabel(label: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a stable agent identifier for use inside a loop round.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createLoopAgentId(input: CreateLoopAgentIdInput): string;
|
package/dist/loop/id.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { InvalidDslCallError } from "../workflow/errors.js";
|
|
2
|
+
const ID_NAME_PATTERN = /^[A-Za-z0-9_.:-]+$/;
|
|
3
|
+
/**
|
|
4
|
+
* Creates a stable loop identifier.
|
|
5
|
+
*/
|
|
6
|
+
export function createLoopId(label) {
|
|
7
|
+
if (!label || typeof label !== "string" || label.trim() === "") {
|
|
8
|
+
throw new InvalidDslCallError("Loop label is required to generate loop ID.");
|
|
9
|
+
}
|
|
10
|
+
return normalizeLoopLabel(label);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a stable round identifier.
|
|
14
|
+
*/
|
|
15
|
+
export function createRoundId(loopId, roundNumber) {
|
|
16
|
+
if (!loopId || typeof loopId !== "string") {
|
|
17
|
+
throw new InvalidDslCallError("createRoundId: loopId is required and must be a string.");
|
|
18
|
+
}
|
|
19
|
+
if (typeof roundNumber !== "number" || roundNumber < 1 || isNaN(roundNumber) || !Number.isInteger(roundNumber)) {
|
|
20
|
+
throw new InvalidDslCallError("createRoundId: roundNumber must be a positive integer.");
|
|
21
|
+
}
|
|
22
|
+
const paddedIndex = roundNumber.toString().padStart(4, "0");
|
|
23
|
+
return `${loopId}-round-${paddedIndex}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Normalizes a loop label for use in IDs.
|
|
27
|
+
*/
|
|
28
|
+
export function normalizeLoopLabel(label) {
|
|
29
|
+
if (!label || typeof label !== "string") {
|
|
30
|
+
return "";
|
|
31
|
+
}
|
|
32
|
+
return label
|
|
33
|
+
.toLowerCase()
|
|
34
|
+
.trim()
|
|
35
|
+
.replace(/[^a-z0-9_.:-]+/g, "-")
|
|
36
|
+
.replace(/^-+|-+$/g, "");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a stable agent identifier for use inside a loop round.
|
|
40
|
+
*/
|
|
41
|
+
export function createLoopAgentId(input) {
|
|
42
|
+
const normalizedLabel = normalizeLoopLabel(input.label);
|
|
43
|
+
const roundPart = `round-${input.roundNumber}`;
|
|
44
|
+
if (input.suffix) {
|
|
45
|
+
const trimmedSuffix = input.suffix.trim();
|
|
46
|
+
if (trimmedSuffix === "") {
|
|
47
|
+
throw new InvalidDslCallError("createLoopAgentId: suffix cannot be empty or whitespace-only.");
|
|
48
|
+
}
|
|
49
|
+
if (trimmedSuffix === "." || trimmedSuffix === "..") {
|
|
50
|
+
throw new InvalidDslCallError("createLoopAgentId: suffix cannot be '.' or '..'.");
|
|
51
|
+
}
|
|
52
|
+
if (trimmedSuffix.includes("/") || trimmedSuffix.includes("\\")) {
|
|
53
|
+
throw new InvalidDslCallError("createLoopAgentId: suffix cannot contain path separators.");
|
|
54
|
+
}
|
|
55
|
+
if (trimmedSuffix.includes("..")) {
|
|
56
|
+
throw new InvalidDslCallError("createLoopAgentId: suffix cannot contain path traversal segments.");
|
|
57
|
+
}
|
|
58
|
+
if (!ID_NAME_PATTERN.test(trimmedSuffix)) {
|
|
59
|
+
throw new InvalidDslCallError(`createLoopAgentId: suffix '${input.suffix}' contains invalid characters. Only alphanumeric, underscores, dots, colons, and hyphens are allowed.`);
|
|
60
|
+
}
|
|
61
|
+
return `${normalizedLabel}:${roundPart}:${trimmedSuffix}`;
|
|
62
|
+
}
|
|
63
|
+
return `${normalizedLabel}:${roundPart}`;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","sources":["../../src/loop/id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAE7C;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/D,MAAM,IAAI,mBAAmB,CAAC,6CAA6C,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MA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G,CAAC;QACD,IAAI,aAAa,KAAK,GAAG,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YACpD,MAAM,IAAI,mBAAmB,CAAC,kDAAkD,CAAC,CAAC;QACpF,CAAC;QACD,IAAI,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAChE,MAAM,IAAI,mBAAmB,CAAC,2DAA2D,CAAC,CAAC;QAC7F,CAAC;QACD,IAAI,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,mBAAmB,CAAC,mEAAmE,CAAC,CAAC;QACrG,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YACzC,MAAM,IAAI,mBAAmB,CAC3B,8BAA8B,KAAK,CAAC,MAAM,uGAAuG,CAClJ,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,eAAe,IAAI,SAAS,IAAI,aAAa,EAAE,CAAC;IAC5D,CAAC;IAED,OAAO,GAAG,eAAe,IAAI,SAAS,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export { runLoop, type RunLoopInput } from "./run.js";
|
|
3
|
+
export { validateAndNormalizeLoopArgs, validateLoopRunResult } from "./validate.js";
|
|
4
|
+
export { createLoopId, createRoundId, createLoopAgentId, normalizeLoopLabel } from "./id.js";
|
|
5
|
+
export { buildLoopSummary } from "./summary.js";
|
|
6
|
+
export { createLoopRoundContext, getActiveLoopContext, withActiveLoopContext, recordLoopChildAgentId, } from "./context.js";
|
|
7
|
+
export { stableHashJson, buildLoopStartReplayMarker, buildLoopRoundReplayMarker, recordLoopCacheMarker, } from "./replay.js";
|
|
8
|
+
export { getIsoTimestamp, getDurationMs, createLoopRoundRecord, createLoopExecutionRecord, createSettledSuccessEnvelope, createSettledFailureEnvelope, createLoopExhaustionError, createInvalidRunResultError, } from "./results.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export { runLoop } from "./run.js";
|
|
3
|
+
export { validateAndNormalizeLoopArgs, validateLoopRunResult } from "./validate.js";
|
|
4
|
+
export { createLoopId, createRoundId, createLoopAgentId, normalizeLoopLabel } from "./id.js";
|
|
5
|
+
export { buildLoopSummary } from "./summary.js";
|
|
6
|
+
export { createLoopRoundContext, getActiveLoopContext, withActiveLoopContext, recordLoopChildAgentId, } from "./context.js";
|
|
7
|
+
export { stableHashJson, buildLoopStartReplayMarker, buildLoopRoundReplayMarker, recordLoopCacheMarker, } from "./replay.js";
|
|
8
|
+
export { getIsoTimestamp, getDurationMs, createLoopRoundRecord, createLoopExecutionRecord, createSettledSuccessEnvelope, createSettledFailureEnvelope, createLoopExhaustionError, createInvalidRunResultError, } from "./results.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/loop/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAqB,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,aAAa,EACb,qBAAqB,EACrB,yBAAyB,EACzB,4BAA4B,EAC5B,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type RuntimeCallCache, type LoopCallCacheEntry } from "../artifacts/call-cache.js";
|
|
2
|
+
import type { ArtifactStore } from "../types/artifacts.js";
|
|
3
|
+
/**
|
|
4
|
+
* Computes a stable hash of a JSON-serializable value.
|
|
5
|
+
*/
|
|
6
|
+
export declare function stableHashJson(value: unknown): string;
|
|
7
|
+
/**
|
|
8
|
+
* Builds a loop-start replay marker.
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildLoopStartReplayMarker(input: {
|
|
11
|
+
loopId: string;
|
|
12
|
+
label: string;
|
|
13
|
+
parentLoopId?: string;
|
|
14
|
+
maxRounds: number;
|
|
15
|
+
optionsFingerprint: string;
|
|
16
|
+
initialStateHash: string;
|
|
17
|
+
maxRoundsCeiling: number;
|
|
18
|
+
}): string;
|
|
19
|
+
/**
|
|
20
|
+
* Builds a loop-round replay marker.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildLoopRoundReplayMarker(input: {
|
|
23
|
+
loopId: string;
|
|
24
|
+
label: string;
|
|
25
|
+
roundIndex: number;
|
|
26
|
+
roundNumber: number;
|
|
27
|
+
nestedCallSequence: string[];
|
|
28
|
+
stateBeforeHash: string;
|
|
29
|
+
stateAfterHash?: string;
|
|
30
|
+
status?: string;
|
|
31
|
+
}): string;
|
|
32
|
+
/**
|
|
33
|
+
* Records a loop cache marker and checks for a prefix cache hit.
|
|
34
|
+
* If there's a mismatch, it disables further cache hits.
|
|
35
|
+
*/
|
|
36
|
+
export declare function recordLoopCacheMarker(input: {
|
|
37
|
+
store: ArtifactStore;
|
|
38
|
+
cache?: RuntimeCallCache;
|
|
39
|
+
kind: "loop";
|
|
40
|
+
sequence: number;
|
|
41
|
+
loopId: string;
|
|
42
|
+
roundIndex?: number;
|
|
43
|
+
roundId?: string;
|
|
44
|
+
fingerprint: string;
|
|
45
|
+
resultPath: string;
|
|
46
|
+
status?: "succeeded" | "failed" | "cancelled" | "timed_out" | "skipped";
|
|
47
|
+
}): Promise<LoopCallCacheEntry | undefined>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
import { findPrefixCacheHit, recordLoopCall } from "../artifacts/call-cache.js";
|
|
3
|
+
/**
|
|
4
|
+
* Stable JSON stringify for consistent hashing.
|
|
5
|
+
*/
|
|
6
|
+
function stableStringify(value) {
|
|
7
|
+
return JSON.stringify(sortValue(value));
|
|
8
|
+
}
|
|
9
|
+
function sortValue(value) {
|
|
10
|
+
if (Array.isArray(value)) {
|
|
11
|
+
return value.map(sortValue);
|
|
12
|
+
}
|
|
13
|
+
if (value && typeof value === "object") {
|
|
14
|
+
const sorted = {};
|
|
15
|
+
for (const key of Object.keys(value).sort()) {
|
|
16
|
+
const child = value[key];
|
|
17
|
+
if (child !== undefined) {
|
|
18
|
+
sorted[key] = sortValue(child);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return sorted;
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Computes a stable hash of a JSON-serializable value.
|
|
27
|
+
*/
|
|
28
|
+
export function stableHashJson(value) {
|
|
29
|
+
return crypto
|
|
30
|
+
.createHash("sha256")
|
|
31
|
+
.update(stableStringify(value))
|
|
32
|
+
.digest("hex");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Builds a loop-start replay marker.
|
|
36
|
+
*/
|
|
37
|
+
export function buildLoopStartReplayMarker(input) {
|
|
38
|
+
return stableHashJson({
|
|
39
|
+
kind: "loop-start",
|
|
40
|
+
loopId: input.loopId,
|
|
41
|
+
label: input.label,
|
|
42
|
+
...(input.parentLoopId !== undefined ? { parentLoopId: input.parentLoopId } : {}),
|
|
43
|
+
maxRounds: input.maxRounds,
|
|
44
|
+
optionsFingerprint: input.optionsFingerprint,
|
|
45
|
+
initialStateHash: input.initialStateHash,
|
|
46
|
+
maxRoundsCeiling: input.maxRoundsCeiling,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
import { normalizeLoopLabel } from "./id.js";
|
|
50
|
+
function normalizeNestedCallSequence(loopId, label, roundNumber, sequence) {
|
|
51
|
+
const normalizedLabel = normalizeLoopLabel(label);
|
|
52
|
+
const prefix = `${loopId}:${normalizedLabel}:round-${roundNumber}:`;
|
|
53
|
+
let workflowCount = 0;
|
|
54
|
+
return sequence.map((id) => {
|
|
55
|
+
if (id.startsWith(prefix)) {
|
|
56
|
+
workflowCount++;
|
|
57
|
+
return `${prefix}workflow-${workflowCount}`;
|
|
58
|
+
}
|
|
59
|
+
return id;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Builds a loop-round replay marker.
|
|
64
|
+
*/
|
|
65
|
+
export function buildLoopRoundReplayMarker(input) {
|
|
66
|
+
const normalizedSequence = normalizeNestedCallSequence(input.loopId, input.label, input.roundNumber, input.nestedCallSequence);
|
|
67
|
+
return stableHashJson({
|
|
68
|
+
kind: "loop-round",
|
|
69
|
+
loopId: input.loopId,
|
|
70
|
+
label: input.label,
|
|
71
|
+
roundIndex: input.roundIndex,
|
|
72
|
+
roundNumber: input.roundNumber,
|
|
73
|
+
nestedCallSequence: normalizedSequence,
|
|
74
|
+
stateBeforeHash: input.stateBeforeHash,
|
|
75
|
+
...(input.stateAfterHash !== undefined ? { stateAfterHash: input.stateAfterHash } : {}),
|
|
76
|
+
...(input.status !== undefined ? { status: input.status } : {}),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Records a loop cache marker and checks for a prefix cache hit.
|
|
81
|
+
* If there's a mismatch, it disables further cache hits.
|
|
82
|
+
*/
|
|
83
|
+
export async function recordLoopCacheMarker(input) {
|
|
84
|
+
const hit = findPrefixCacheHit({
|
|
85
|
+
cache: input.cache,
|
|
86
|
+
kind: "loop",
|
|
87
|
+
sequence: input.sequence,
|
|
88
|
+
callId: input.loopId,
|
|
89
|
+
fingerprint: input.fingerprint,
|
|
90
|
+
});
|
|
91
|
+
await recordLoopCall({
|
|
92
|
+
store: input.store,
|
|
93
|
+
...(input.cache !== undefined ? { cache: input.cache } : {}),
|
|
94
|
+
sequence: input.sequence,
|
|
95
|
+
loopId: input.loopId,
|
|
96
|
+
...(input.roundIndex !== undefined ? { roundIndex: input.roundIndex } : {}),
|
|
97
|
+
...(input.roundId !== undefined ? { roundId: input.roundId } : {}),
|
|
98
|
+
fingerprint: input.fingerprint,
|
|
99
|
+
resultPath: input.resultPath,
|
|
100
|
+
...(input.status !== undefined ? { status: input.status } : {}),
|
|
101
|
+
});
|
|
102
|
+
return hit;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=replay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.js","sourceRoot":"","sources":["../../src/loop/replay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAkD,MAAM,4BAA4B,CAAC;AAGhI;;GAEG;AACH,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;IACD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,MAAM,GAA4B,EAAE,CAAC;QAC3C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAgC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YACvE,MAAM,KAAK,GAAI,K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AAM;QACpB,WAAW,EAAE,KAAK,CAAC,WAAW;KAC/B,CAAC,CAAC;IAEH,MAAM,cAAc,CAAC;QACnB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,GAAG,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3E,GAAG,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClE,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChE,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { LoopRoundRecord, LoopExecutionRecord, LoopSettledSuccess, LoopSettledFailure } from "./types.js";
|
|
2
|
+
import type { SerializedError } from "../types/errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the current ISO timestamp.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getIsoTimestamp(): string;
|
|
7
|
+
/**
|
|
8
|
+
* Calculates duration between two ISO timestamps.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getDurationMs(startIso: string, endIso: string): number;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a concise round record.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createLoopRoundRecord<TState>(input: {
|
|
15
|
+
index: number;
|
|
16
|
+
roundNumber: number;
|
|
17
|
+
status: "completed" | "failed" | "cancelled" | "timed_out";
|
|
18
|
+
inputState: TState;
|
|
19
|
+
nextState?: TState;
|
|
20
|
+
durationMs: number;
|
|
21
|
+
error?: SerializedError;
|
|
22
|
+
nestedCalls: {
|
|
23
|
+
agents: string[];
|
|
24
|
+
workflows: string[];
|
|
25
|
+
};
|
|
26
|
+
}): LoopRoundRecord<TState>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates an execution record.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createLoopExecutionRecord<TState>(input: {
|
|
31
|
+
loopId: string;
|
|
32
|
+
label: string;
|
|
33
|
+
status: "succeeded" | "failed" | "cancelled" | "timed_out" | "max_rounds";
|
|
34
|
+
roundsCompleted: number;
|
|
35
|
+
maxRounds: number;
|
|
36
|
+
initialState: TState;
|
|
37
|
+
finalState?: TState;
|
|
38
|
+
rounds: LoopRoundRecord<TState>[];
|
|
39
|
+
startedAt: string;
|
|
40
|
+
finishedAt: string;
|
|
41
|
+
durationMs: number;
|
|
42
|
+
artifactPath: string;
|
|
43
|
+
error?: SerializedError;
|
|
44
|
+
}): LoopExecutionRecord<TState>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates settled success envelope.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createSettledSuccessEnvelope<TState>(input: {
|
|
49
|
+
label: string;
|
|
50
|
+
loopId: string;
|
|
51
|
+
roundsCompleted: number;
|
|
52
|
+
finalState: TState;
|
|
53
|
+
artifactsDir: string;
|
|
54
|
+
}): LoopSettledSuccess<TState>;
|
|
55
|
+
/**
|
|
56
|
+
* Creates settled failure envelope.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createSettledFailureEnvelope<TState>(input: {
|
|
59
|
+
status: "failed" | "cancelled" | "timed_out" | "max_rounds";
|
|
60
|
+
label: string;
|
|
61
|
+
loopId: string;
|
|
62
|
+
roundsCompleted: number;
|
|
63
|
+
finalState?: TState;
|
|
64
|
+
error?: SerializedError;
|
|
65
|
+
artifactsDir: string;
|
|
66
|
+
}): LoopSettledFailure<TState>;
|
|
67
|
+
/**
|
|
68
|
+
* Creates loop exhaustion error.
|
|
69
|
+
*/
|
|
70
|
+
export declare function createLoopExhaustionError(label: string, maxRounds: number): Error;
|
|
71
|
+
/**
|
|
72
|
+
* Creates invalid round result error.
|
|
73
|
+
*/
|
|
74
|
+
export declare function createInvalidRunResultError(label: string, details: string): Error;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { OpenDynamicWorkflowError } from "../errors/types.js";
|
|
2
|
+
import { ErrorCode } from "../errors/codes.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the current ISO timestamp.
|
|
5
|
+
*/
|
|
6
|
+
export function getIsoTimestamp() {
|
|
7
|
+
return new Date().toISOString();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Calculates duration between two ISO timestamps.
|
|
11
|
+
*/
|
|
12
|
+
export function getDurationMs(startIso, endIso) {
|
|
13
|
+
const start = new Date(startIso).getTime();
|
|
14
|
+
const end = new Date(endIso).getTime();
|
|
15
|
+
return Math.max(0, end - start);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a concise round record.
|
|
19
|
+
*/
|
|
20
|
+
export function createLoopRoundRecord(input) {
|
|
21
|
+
return {
|
|
22
|
+
index: input.index,
|
|
23
|
+
roundNumber: input.roundNumber,
|
|
24
|
+
status: input.status,
|
|
25
|
+
inputState: input.inputState,
|
|
26
|
+
...(input.nextState !== undefined ? { nextState: input.nextState } : {}),
|
|
27
|
+
durationMs: input.durationMs,
|
|
28
|
+
...(input.error !== undefined ? { error: input.error } : {}),
|
|
29
|
+
nestedCalls: {
|
|
30
|
+
agents: [...input.nestedCalls.agents],
|
|
31
|
+
workflows: [...input.nestedCalls.workflows],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates an execution record.
|
|
37
|
+
*/
|
|
38
|
+
export function createLoopExecutionRecord(input) {
|
|
39
|
+
return {
|
|
40
|
+
schemaVersion: "open-dynamic-workflow.loop-result.v2",
|
|
41
|
+
loopId: input.loopId,
|
|
42
|
+
label: input.label,
|
|
43
|
+
status: input.status,
|
|
44
|
+
roundsCompleted: input.roundsCompleted,
|
|
45
|
+
maxRounds: input.maxRounds,
|
|
46
|
+
initialState: input.initialState,
|
|
47
|
+
...(input.finalState !== undefined ? { finalState: input.finalState } : {}),
|
|
48
|
+
rounds: [...input.rounds],
|
|
49
|
+
startedAt: input.startedAt,
|
|
50
|
+
finishedAt: input.finishedAt,
|
|
51
|
+
durationMs: input.durationMs,
|
|
52
|
+
artifactPath: input.artifactPath,
|
|
53
|
+
...(input.error !== undefined ? { error: input.error } : {}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates settled success envelope.
|
|
58
|
+
*/
|
|
59
|
+
export function createSettledSuccessEnvelope(input) {
|
|
60
|
+
return {
|
|
61
|
+
ok: true,
|
|
62
|
+
status: "succeeded",
|
|
63
|
+
label: input.label,
|
|
64
|
+
loopId: input.loopId,
|
|
65
|
+
roundsCompleted: input.roundsCompleted,
|
|
66
|
+
finalState: input.finalState,
|
|
67
|
+
artifacts: {
|
|
68
|
+
dir: input.artifactsDir,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates settled failure envelope.
|
|
74
|
+
*/
|
|
75
|
+
export function createSettledFailureEnvelope(input) {
|
|
76
|
+
return {
|
|
77
|
+
ok: false,
|
|
78
|
+
status: input.status,
|
|
79
|
+
label: input.label,
|
|
80
|
+
loopId: input.loopId,
|
|
81
|
+
roundsCompleted: input.roundsCompleted,
|
|
82
|
+
...(input.finalState !== undefined ? { finalState: input.finalState } : {}),
|
|
83
|
+
...(input.error !== undefined ? { error: input.error } : {}),
|
|
84
|
+
artifacts: {
|
|
85
|
+
dir: input.artifactsDir,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Creates loop exhaustion error.
|
|
91
|
+
*/
|
|
92
|
+
export function createLoopExhaustionError(label, maxRounds) {
|
|
93
|
+
return new OpenDynamicWorkflowError(ErrorCode.WORKFLOW_FAILED, `Loop '${label}' exhausted maxRounds of ${maxRounds}.`);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Creates invalid round result error.
|
|
97
|
+
*/
|
|
98
|
+
export function createInvalidRunResultError(label, details) {
|
|
99
|
+
return new OpenDynamicWorkflowError(ErrorCode.WORKFLOW_INVALID_CALL, `Loop '${label}' round returned invalid run result: ${details}`);
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=results.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../../src/loop/results.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,MAAc;IAC5D,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;IAC3C,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;IACvC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAA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AO,IAAI,wBAAwB,CACjC,SAAS,CAAC,eAAe,EACzB,SAAS,KAAK,4BAA4B,SAAS,GAAG,CACvD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAAC,KAAa,EAAE,OAAe;IACxE,OAAO,IAAI,wBAAwB,CACjC,SAAS,CAAC,qBAAqB,EAC/B,SAAS,KAAK,wCAAwC,OAAO,EAAE,CAChE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LoopSettledResult } from "./types.js";
|
|
2
|
+
import type { RuntimeState } from "../workflow/types.js";
|
|
3
|
+
import type { AgentCallInput, AgentResult } from "../types/agent.js";
|
|
4
|
+
import type { WorkflowCallInput } from "../types/workflow.js";
|
|
5
|
+
/**
|
|
6
|
+
* Input for runLoop.
|
|
7
|
+
*/
|
|
8
|
+
export interface RunLoopInput<TState = unknown> {
|
|
9
|
+
loopInput: unknown;
|
|
10
|
+
runtime: RuntimeState;
|
|
11
|
+
signal: AbortSignal;
|
|
12
|
+
dsl: {
|
|
13
|
+
agent: (input: AgentCallInput) => Promise<AgentResult>;
|
|
14
|
+
workflow: (input: WorkflowCallInput) => Promise<any>;
|
|
15
|
+
log: (message: string, data?: unknown) => void;
|
|
16
|
+
};
|
|
17
|
+
_stateType?: TState;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Main loop execution runtime.
|
|
21
|
+
*/
|
|
22
|
+
export declare function runLoop<TState = unknown>(input: RunLoopInput<TState>): Promise<TState | LoopSettledResult<TState>>;
|