Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@arc-dev/runtime

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arc-dev/runtime - npm Package Compare versions

Comparing version
0.0.2-alpha.6
to
0.0.2-alpha.7
+2
-2
dist/executor.d.ts
import { Arc, ArcEvent, ArcState } from "@arc-dev/core";
import { Storage } from "./types";
export declare function executeArc<State extends Record<string, any>, Context extends Record<string, any>>(arc: Arc<State, Context>, arcState: ArcState<State, Context>, resumeResolvers: Map<string, (value: any) => void>, initialExecuted?: Set<string>, storage?: Storage, sessionId?: string, parentArc?: Arc<any, any>, parentLoopNodeId?: string, parentExecuted?: Set<string>): AsyncIterable<ArcEvent<State, Context>>;
import { Storage } from "@arc-dev/storage";
export declare function executeArc<State extends Record<string, any>, Context extends Record<string, any>>(arc: Arc<State, Context>, arcState: ArcState<State, Context>, resumeResolvers: Map<string, (value: any) => void>, initialExecuted?: Set<string>, storage?: Storage, sessionId?: string, parentArc?: Arc<any, any>, parentLoopNodeId?: string, parentExecutedNodes?: Set<string>, serverless?: boolean): AsyncIterable<ArcEvent<State, Context>>;
//# sourceMappingURL=executor.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAIH,QAAQ,EACR,QAAQ,EACT,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AA8DlC,wBAAuB,UAAU,CAC/B,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAEnC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,EACxB,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,C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,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CA6WzC"}
'use strict';
var core = require('@arc-dev/core');
var model = require('@arc-dev/model');
async function* execute(node, arcState) {
const stateContext = arcState.getStateContext();
const models = arcState.getModels();
switch (node.kind) {
case core.ArcNodeKind.Agent: {
const agent = node.handler;
yield* agent.run(stateContext, node.id);
yield* agent.run(stateContext, node.id, models);
const pendingContext = stateContext.__pendingContext;

@@ -20,3 +22,3 @@ if (pendingContext) {

const action = node.handler;
yield* action.run(stateContext, node.id);
yield* action.run(stateContext, node.id, models);
const pendingState = stateContext.__pendingState;

@@ -42,3 +44,2 @@ if (pendingState) {

for (const edge of edges) {
// Entry edges (no from) don't add dependencies - target node is an entry point
if (!edge.from || edge.from === edge.to) {

@@ -79,3 +80,3 @@ continue;

};
async function* executeArc(arc, arcState, resumeResolvers, initialExecuted, storage, sessionId, parentArc, parentLoopNodeId, parentExecuted) {
async function* executeArc(arc, arcState, resumeResolvers, initialExecuted, storage, sessionId, parentArc, parentLoopNodeId, parentExecutedNodes, serverless) {
const executed = initialExecuted

@@ -174,4 +175,4 @@ ? new Set(initialExecuted)

parentLoopNodeId: parentLoopNodeId || undefined, // Store loop node ID
parentExecuted: parentExecuted
? Array.from(parentExecuted)
parentExecutedNodes: parentExecutedNodes
? Array.from(parentExecutedNodes)
: undefined, // Store parent's executed set if this is a sub-arc

@@ -196,2 +197,15 @@ });

};
// In serverless environments (e.g., Cloudflare Workers), we must end the stream
// after emitting the pause event to avoid hanging the request.
// The client will need to call /resume to continue execution.
if (serverless) {
yield {
type: "log",
level: "info",
message: `Pausing execution in serverless mode. Use /resume endpoint to continue.`,
timestamp: Date.now(),
};
return; // End the generator, allowing the Worker to complete
}
// For in-process resumption (long-running environments), wait for the promise
const result = await resumePromise;

@@ -281,6 +295,19 @@ yield {

};
// Store parent's executed set (without the loop node, so it can run again when resuming)
// The loop node needs to run again to check the condition and continue the loop
const parentExecutedSet = new Set(executed);
yield* executeArc(subArc, arcState, resumeResolvers, undefined, storage, sessionId, arc, node.id, parentExecutedSet);
const parentExecutedNodesSet = new Set(executed);
yield* executeArc(subArc, arcState, resumeResolvers, undefined, storage, sessionId, arc, node.id, parentExecutedNodesSet, serverless);
// In serverless mode, check if execution was paused
// If the session still exists in storage, it means we paused
if (serverless && storage && sessionId) {
const storedSession = await storage.get(sessionId);
if (storedSession) {
yield {
type: "log",
level: "info",
message: `Loop "${node.id}" paused in serverless mode at iteration ${iteration + 1}`,
timestamp: Date.now(),
};
// Return early to end the stream and allow the Worker to complete
return;
}
}
iteration++;

@@ -385,5 +412,23 @@ }

sessionIdGenerator;
models;
constructor(options) {
this.storage = options?.storage || new InMemoryStorage();
this.sessionIdGenerator = () => `session_${Date.now()}_${Math.random().toString(36).substring(7)}`;
if (options?.models) {
this.models = options.models;
}
else {
let apiKey = "";
if (typeof globalThis !== "undefined") {
const nodeProcess = globalThis.process;
apiKey = nodeProcess?.env?.OPENAI_API_KEY || "";
if (!apiKey) {
apiKey = globalThis.OPENAI_API_KEY || "";
}
}
if (!apiKey) {
throw new Error("Models require an API key. Provide models via ArcRuntimeOptions or set OPENAI_API_KEY environment variable.");
}
this.models = model.createModels({ apiKey });
}
}

@@ -410,4 +455,2 @@ async resume(sessionId, input) {

async *resumeFromSession(sessionId, input) {
// Clear any existing resolver since we're starting a new execution
// In serverless environments, we can't rely on the original execution still running
if (this.resumeResolvers.has(sessionId)) {

@@ -438,3 +481,3 @@ this.resumeResolvers.delete(sessionId);

};
const arcState = core.ArcState.fromSerialized(stored.snapshot);
const arcState = core.ArcState.fromSerialized(stored.snapshot, this.models);
const resumeInput = input !== undefined ? input : stored.pendingInput;

@@ -450,3 +493,2 @@ if (resumeInput === undefined) {

}
// Set the input for the paused node
const inputValue = typeof resumeInput === "string"

@@ -463,5 +505,3 @@ ? resumeInput

try {
// First, execute the sub-arc with the input to complete it
yield* executeArc(stored.arc, arcState, this.resumeResolvers, new Set(stored.snapshot.executed), this.storage, sessionId);
// If this was a sub-arc with a parent, continue the parent loop
yield* executeArc(stored.arc, arcState, this.resumeResolvers, new Set(stored.snapshot.executed), this.storage, sessionId, undefined, undefined, undefined, false);
if (stored.parentArc && stored.parentLoopNodeId) {

@@ -474,6 +514,4 @@ yield {

};
// Use the stored parent executed set to continue from where we left off
// This ensures we don't restart the parent arc from the beginning
const parentExecuted = stored.parentExecuted
? new Set(stored.parentExecuted)
const parentExecutedNodes = stored.parentExecutedNodes
? new Set(stored.parentExecutedNodes)
: new Set();

@@ -483,13 +521,9 @@ yield {

level: "info",
message: `Continuing parent arc with executed nodes: [${Array.from(parentExecuted).join(", ")}]`,
message: `Continuing parent arc with executed nodes: [${Array.from(parentExecutedNodes).join(", ")}]`,
timestamp: Date.now(),
};
yield* executeArc(stored.parentArc, arcState, this.resumeResolvers, parentExecuted, // Use stored parent executed set to continue from where we left off
this.storage, sessionId);
yield* executeArc(stored.parentArc, arcState, this.resumeResolvers, parentExecutedNodes, this.storage, sessionId, undefined, undefined, undefined, false);
}
// Check if executor is still paused (waiting for input)
// If not paused, the arc completed successfully
const stillPaused = await this.storage.get(sessionId);
if (!stillPaused) {
// Clear any remaining storage entry to be safe
await this.storage.delete(sessionId);

@@ -524,3 +558,3 @@ const finalContext = arcState.getContext().toJS();

async *run(arc, state, sessionId) {
const arcState = new core.ArcState(state);
const arcState = new core.ArcState(state, this.models);
const execSessionId = sessionId || this.sessionIdGenerator();

@@ -540,3 +574,3 @@ try {

};
yield* executeArc(arc, arcState, this.resumeResolvers, undefined, this.storage, execSessionId);
yield* executeArc(arc, arcState, this.resumeResolvers, undefined, this.storage, execSessionId, undefined, undefined, undefined, false);
const finalContext = arcState.getContext().toJS();

@@ -574,5 +608,164 @@ const finalState = arcState.getState().toJS();

}
class ArcServerlessRuntime extends ArcRuntime {
async *run(arc, state, sessionId) {
const arcState = new core.ArcState(state, this.models);
const execSessionId = sessionId || this.sessionIdGenerator();
try {
yield {
type: "arc-started",
arcId: arc.id,
initialState: state,
timestamp: Date.now(),
};
yield {
type: "log",
level: "info",
message: `Arc "${arc.id}" started (serverless mode)`,
timestamp: Date.now(),
};
yield* executeArc(arc, arcState, this.resumeResolvers, undefined, this.storage, execSessionId, undefined, undefined, undefined, true);
const storedSession = await this.storage.get(execSessionId);
if (storedSession) {
yield {
type: "log",
level: "info",
message: `Arc "${arc.id}" paused, session stored for resumption`,
timestamp: Date.now(),
};
return;
}
const finalContext = arcState.getContext().toJS();
const finalState = arcState.getState().toJS();
yield {
type: "arc-completed",
arcId: arc.id,
finalState,
finalContext,
timestamp: Date.now(),
};
yield {
type: "log",
level: "info",
message: `Arc "${arc.id}" completed`,
timestamp: Date.now(),
};
if (execSessionId) {
await this.storage.delete(execSessionId);
}
}
catch (error) {
if (execSessionId) {
await this.storage.delete(execSessionId);
}
yield {
type: "arc-error",
arcId: arc.id,
error: error instanceof Error ? error : new Error(String(error)),
timestamp: Date.now(),
};
}
}
async *resumeFromSession(sessionId, input) {
if (this.resumeResolvers.has(sessionId)) {
this.resumeResolvers.delete(sessionId);
yield {
type: "log",
level: "info",
message: `[Runtime] Cleared existing resolver for session ${sessionId} before resuming`,
timestamp: Date.now(),
};
}
const stored = await this.storage.get(sessionId);
if (!stored) {
yield {
type: "arc-error",
arcId: "unknown",
error: new Error(`Session ${sessionId} not found or expired`),
timestamp: Date.now(),
};
return;
}
yield {
type: "log",
level: "info",
message: `[Runtime] Resuming session ${sessionId} (serverless mode), paused at node "${stored.nodeId}", arc: "${stored.arc.id}", has parent: ${!!stored.parentArc}`,
timestamp: Date.now(),
};
const arcState = core.ArcState.fromSerialized(stored.snapshot, this.models);
const resumeInput = input !== undefined ? input : stored.pendingInput;
if (resumeInput === undefined) {
yield {
type: "arc-error",
arcId: stored.arc.id,
error: new Error(`No input provided for session ${sessionId}`),
timestamp: Date.now(),
};
return;
}
const inputValue = typeof resumeInput === "string"
? resumeInput
: JSON.stringify(resumeInput);
yield {
type: "log",
level: "info",
message: `[Runtime] Setting edge input for node "${stored.nodeId}" with value: ${inputValue}`,
timestamp: Date.now(),
};
arcState.setEdgeContext(stored.nodeId, inputValue);
try {
yield* executeArc(stored.arc, arcState, this.resumeResolvers, new Set(stored.snapshot.executed), this.storage, sessionId, undefined, undefined, undefined, true);
if (stored.parentArc && stored.parentLoopNodeId) {
yield {
type: "log",
level: "info",
message: `Sub-arc completed, continuing parent arc "${stored.parentArc.id}" loop "${stored.parentLoopNodeId}"`,
timestamp: Date.now(),
};
// Use the stored parent executed set to continue from where we left off
// This ensures we don't restart the parent arc from the beginning
const parentExecutedNodes = stored.parentExecutedNodes
? new Set(stored.parentExecutedNodes)
: new Set();
yield {
type: "log",
level: "info",
message: `Continuing parent arc with executed nodes: [${Array.from(parentExecutedNodes).join(", ")}]`,
timestamp: Date.now(),
};
yield* executeArc(stored.parentArc, arcState, this.resumeResolvers, parentExecutedNodes, this.storage, sessionId, undefined, undefined, undefined, true);
}
const stillPaused = await this.storage.get(sessionId);
if (!stillPaused) {
await this.storage.delete(sessionId);
const finalContext = arcState.getContext().toJS();
const finalState = arcState.getState().toJS();
yield {
type: "arc-completed",
arcId: stored.arc.id,
finalState,
finalContext,
timestamp: Date.now(),
};
yield {
type: "log",
level: "info",
message: `Arc "${stored.arc.id}" completed`,
timestamp: Date.now(),
};
}
}
catch (error) {
await this.storage.delete(sessionId);
yield {
type: "arc-error",
arcId: stored.arc.id,
error: error instanceof Error ? error : new Error(String(error)),
timestamp: Date.now(),
};
}
}
}
exports.ArcRuntime = ArcRuntime;
exports.InMemoryStorage = InMemoryStorage;
exports.ArcServerlessRuntime = ArcServerlessRuntime;
//# sourceMappingURL=index.cjs.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.cjs","sources":["../src/nodes.ts","../src/executor.ts","../src/storage/in-memory.ts","../src/runtime.ts"],"sourcesContent":["import {\n ArcNode,\n ArcState,\n ArcNodeKind,\n ImmutableMap,\n ArcEvent,\n} from \"@arc-dev/core\";\n\nexport async function* execute<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n>(\n node: ArcNode<State, Context>,\n arcState: ArcState<State, Context>\n): AsyncIterable<ArcEvent<State, Context>> {\n const stateContext = arcState.getStateContext();\n\n switch (node.kind) {\n case ArcNodeKind.Agent: {\n const agent = node.handler;\n yield* agent.run(stateContext, node.id);\n\n const pendingContext = (stateContext as any).__pendingContext;\n if (pendingContext) {\n arcState.setContext(pendingContext.nodeId, pendingContext.result);\n delete (stateContext as any).__pendingContext;\n }\n\n break;\n }\n case ArcNodeKind.Action: {\n const action = node.handler;\n yield* action.run(stateContext, node.id);\n\n const pendingState = (stateContext as any).__pendingState;\n\n if (pendingState) {\n arcState.setState(pendingState);\n delete (stateContext as any).__pendingState;\n }\n\n break;\n }\n case ArcNodeKind.Arc: {\n arcState.setContext(node.id, ImmutableMap({ executed: true }));\n break;\n }\n }\n}\n","import {\n Arc,\n ArcStateContext,\n ArcEdge,\n ArcNodeKind,\n ArcEvent,\n ArcState,\n} from \"@arc-dev/core\";\nimport { execute } from \"./nodes\";\nimport { Storage } from \"./types\";\n\nconst buildDependencyMap = (\n nodes: Array<{ id: string }>,\n edges: ArcEdge[]\n): Map<string, string[]> => {\n const deps = new Map<string, string[]>();\n\n for (const node of nodes) {\n deps.set(node.id, []);\n }\n\n for (const edge of edges) {\n // Entry edges (no from) don't add dependencies - target node is an entry point\n if (!edge.from || edge.from === edge.to) {\n continue;\n }\n const currentDeps = deps.get(edge.to) || [];\n currentDeps.push(edge.from);\n deps.set(edge.to, currentDeps);\n }\n\n return deps;\n};\n\nconst getEdgeConditions = (\n nodeId: string,\n edges: ArcEdge[],\n conditions: Map<string, (sc: ArcStateContext<any, any>) => boolean>\n): Array<(sc: ArcStateContext<any, any>) => boolean> => {\n const edgeConditions: Array<(sc: ArcStateContext<any, any>) => boolean> = [];\n\n for (const edge of edges) {\n if (edge.to === nodeId && edge.from && edge.from !== edge.to) {\n if (edge.when) {\n edgeConditions.push(edge.when);\n } else if (edge.condition && conditions.has(edge.condition)) {\n const conditionFn = conditions.get(edge.condition)!;\n edgeConditions.push(conditionFn);\n }\n }\n }\n\n return edgeConditions;\n};\n\nconst getWaitingEdges = (nodeId: string, edges: ArcEdge[]): ArcEdge[] => {\n return edges.filter(\n (edge) =>\n edge.to === nodeId && (!edge.from || edge.from !== edge.to) && edge.wait\n );\n};\n\nconst getLoopEdge = (nodeId: string, edges: ArcEdge[]): ArcEdge | null => {\n for (const edge of edges) {\n if (edge.from === nodeId && edge.to === nodeId) {\n return edge;\n }\n }\n return null;\n};\n\nexport async function* executeArc<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n>(\n arc: Arc<State, Context>,\n arcState: ArcState<State, Context>,\n resumeResolvers: Map<string, (value: any) => void>,\n initialExecuted?: Set<string>,\n storage?: Storage,\n sessionId?: string,\n parentArc?: Arc<any, any>,\n parentLoopNodeId?: string,\n parentExecuted?: Set<string>\n): AsyncIterable<ArcEvent<State, Context>> {\n const executed = initialExecuted\n ? new Set(initialExecuted)\n : new Set<string>();\n let changed = true;\n\n const dependencyMap = buildDependencyMap(arc.nodes, arc.edges);\n\n while (changed) {\n changed = false;\n\n for (const node of arc.nodes) {\n if (executed.has(node.id)) continue;\n\n const deps = dependencyMap.get(node.id) || [];\n const depsDone = deps.every((d: string) => executed.has(d));\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\": deps=${JSON.stringify(deps)}, depsDone=${depsDone}`,\n timestamp: Date.now(),\n };\n\n if (!depsDone) {\n continue;\n }\n\n const stateContext = arcState.getStateContext();\n\n const edgeConditions = getEdgeConditions(\n node.id,\n arc.edges,\n arc.conditions\n );\n\n if (edgeConditions.length > 0) {\n const allConditionsMet = edgeConditions.every((condFn) => {\n try {\n return condFn(stateContext);\n } catch (e) {\n return false;\n }\n });\n\n if (!allConditionsMet) {\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Skipping node \"${node.id}\" due to edge condition(s)`,\n timestamp: Date.now(),\n };\n executed.add(node.id);\n changed = true;\n continue;\n }\n }\n\n const waitingEdges = getWaitingEdges(node.id, arc.edges);\n\n if (waitingEdges.length > 0) {\n const edgeContext = arcState.getEdgeContext();\n const hasInput = edgeContext.has(node.id);\n\n if (hasInput) {\n const inputValue = edgeContext.get(node.id);\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\" has waiting edge(s) but input already provided (${inputValue}), continuing execution`,\n timestamp: Date.now(),\n };\n // Don't clear the edge input yet - let the node read it first\n // It will be cleared after node execution below\n } else {\n // No input yet, need to wait for it\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\" has ${waitingEdges.length} waiting edge(s)`,\n timestamp: Date.now(),\n };\n\n for (const edge of waitingEdges) {\n if (edge.wait) {\n const { message } = edge.wait;\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Pausing execution at node \"${node.id}\" waiting for input on edge ${edge.from || \"entry\"} -> ${edge.to}`,\n timestamp: Date.now(),\n };\n\n // Use sessionId if available, otherwise fall back to nodeId for same-instance resume\n const resolverKey = sessionId || node.id;\n const resumePromise = new Promise<any>((resolve) => {\n resumeResolvers.set(resolverKey, resolve);\n });\n\n // If storage is provided, store execution state\n // If this is a sub-arc, store both the sub-arc and parent arc so we can continue the loop\n if (storage && sessionId) {\n await storage.store(sessionId, {\n arc, // Store the current arc (sub-arc if in a loop)\n snapshot: {\n executed: Array.from(executed),\n ...arcState.serialize(),\n },\n nodeId: node.id,\n parentArc: parentArc || undefined, // Store parent arc if this is a sub-arc\n parentLoopNodeId: parentLoopNodeId || undefined, // Store loop node ID\n parentExecuted: parentExecuted\n ? Array.from(parentExecuted)\n : undefined, // Store parent's executed set if this is a sub-arc\n });\n }\n\n // Emit node-paused with state - platforms handle validation themselves\n yield {\n type: \"node-paused\" as const,\n nodeId: node.id,\n prompt: message,\n state: stateContext.state.toJS() as State,\n context: stateContext.context.toJS() as Context,\n timestamp: Date.now(),\n sessionId: sessionId,\n snapshot: storage\n ? undefined // Don't include in event if using storage\n : {\n executed: Array.from(executed),\n ...arcState.serialize(),\n },\n };\n\n const result = await resumePromise;\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Resumed with input for node ${node.id}`,\n timestamp: Date.now(),\n };\n\n // Convert result to string for edge input (maintaining compatibility)\n const inputValue =\n typeof result === \"string\" ? result : JSON.stringify(result);\n arcState.setEdgeContext(node.id, inputValue);\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Input received on edge ${edge.from || \"entry\"} -> ${edge.to}`,\n timestamp: Date.now(),\n };\n }\n }\n }\n }\n\n const loopEdge = getLoopEdge(node.id, arc.edges);\n\n if (loopEdge && node.kind === ArcNodeKind.Arc && node.handler.arc) {\n const subArc = node.handler.arc;\n const maxIterations = loopEdge.maxIterations || 100;\n let iteration = 0;\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Starting loop \"${node.id}\" (max ${maxIterations} iterations)`,\n timestamp: Date.now(),\n };\n\n while (iteration < maxIterations) {\n const stateContext = arcState.getStateContext();\n\n let shouldContinue = true;\n\n if (loopEdge.when) {\n try {\n shouldContinue = loopEdge.when(stateContext);\n } catch (e) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: e instanceof Error ? e : new Error(String(e)),\n timestamp: Date.now(),\n };\n break;\n }\n } else if (\n loopEdge.condition &&\n arc.conditions.has(loopEdge.condition)\n ) {\n const conditionFn = arc.conditions.get(loopEdge.condition)!;\n try {\n shouldContinue = conditionFn(stateContext);\n } catch (e) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: e instanceof Error ? e : new Error(String(e)),\n timestamp: Date.now(),\n };\n break;\n }\n }\n\n if (!shouldContinue) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Loop \"${node.id}\" condition failed after ${iteration} iterations`,\n timestamp: Date.now(),\n };\n // Clear storage entry if loop completed naturally (not paused)\n // This ensures that when the executor finishes, the runtime knows the arc is done\n if (storage && sessionId) {\n await storage.delete(sessionId);\n }\n break;\n }\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Loop \"${node.id}\" iteration ${iteration + 1}`,\n timestamp: Date.now(),\n };\n\n // Store parent's executed set (without the loop node, so it can run again when resuming)\n // The loop node needs to run again to check the condition and continue the loop\n const parentExecutedSet = new Set(executed);\n\n yield* executeArc(\n subArc,\n arcState,\n resumeResolvers,\n undefined,\n storage,\n sessionId,\n arc,\n node.id,\n parentExecutedSet\n );\n\n iteration++;\n }\n\n if (iteration >= maxIterations) {\n yield {\n type: \"log\" as const,\n level: \"warn\" as const,\n message: `Loop \"${node.id}\" reached max iterations (${maxIterations})`,\n timestamp: Date.now(),\n };\n // Clear storage entry if loop completed due to max iterations (not paused)\n if (storage && sessionId) {\n await storage.delete(sessionId);\n }\n }\n\n executed.add(node.id);\n changed = true;\n } else {\n yield {\n type: \"node-started\" as const,\n nodeId: node.id,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Running node \"${node.id}\" (${node.kind})`,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `About to execute node ${node.id}`,\n timestamp: Date.now(),\n };\n\n try {\n yield* execute(node, arcState);\n } catch (error) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n throw error;\n }\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Finished executing node ${node.id}`,\n timestamp: Date.now(),\n };\n\n const stateContext = arcState.getStateContext();\n\n yield {\n type: \"node-completed\" as const,\n nodeId: node.id,\n state: stateContext.state.toJS() as State,\n context: stateContext.context.toJS() as Context,\n timestamp: Date.now(),\n };\n\n // Clear edge input after node execution if it was set (for waiting edges)\n const waitingEdgesForNode = getWaitingEdges(node.id, arc.edges);\n if (waitingEdgesForNode.length > 0) {\n const edgeContext = arcState.getEdgeContext();\n if (edgeContext.has(node.id)) {\n arcState.clearEdgeContext(node.id);\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Cleared edge input for node \"${node.id}\" after execution`,\n timestamp: Date.now(),\n };\n }\n }\n\n executed.add(node.id);\n\n changed = true;\n }\n }\n }\n}\n","import { Storage, StoredExecution } from \"..\";\n\nexport class InMemoryStorage implements Storage {\n private executions: Map<string, StoredExecution> = new Map();\n\n store(sessionId: string, execution: StoredExecution): void {\n this.executions.set(sessionId, execution);\n }\n\n get(sessionId: string): StoredExecution | null {\n return this.executions.get(sessionId) || null;\n }\n\n delete(sessionId: string): void {\n this.executions.delete(sessionId);\n }\n}\n","import {\n ArcRuntime as ArcRuntimeType,\n Arc,\n ArcState,\n ArcEvent,\n} from \"@arc-dev/core\";\nimport { executeArc } from \"./executor\";\nimport { InMemoryStorage } from \"./storage\";\nimport { Storage } from \"./types/storage\";\n\nexport interface ArcRuntimeOptions {\n storage?: Storage;\n}\n\nexport class ArcRuntime implements ArcRuntimeType {\n private resumeResolvers: Map<string, (value: any) => void> = new Map();\n private storage: Storage;\n private sessionIdGenerator: () => string;\n\n constructor(options?: ArcRuntimeOptions) {\n this.storage = options?.storage || new InMemoryStorage();\n this.sessionIdGenerator = () =>\n `session_${Date.now()}_${Math.random().toString(36).substring(7)}`;\n }\n\n async resume<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(sessionId: string, input: any): Promise<string | void> {\n const resolver = this.resumeResolvers.get(sessionId);\n\n if (resolver) {\n resolver(input);\n this.resumeResolvers.delete(sessionId);\n return;\n }\n\n const stored = this.storage.get(sessionId);\n const storedExecution = stored instanceof Promise ? await stored : stored;\n\n if (storedExecution) {\n storedExecution.pendingInput = input;\n\n const storeResult = this.storage.store(sessionId, storedExecution);\n if (storeResult instanceof Promise) {\n await storeResult;\n }\n\n return sessionId;\n }\n\n return sessionId;\n }\n\n async *resumeFromSession<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(sessionId: string, input?: any): AsyncIterable<ArcEvent<State, Context>> {\n // Clear any existing resolver since we're starting a new execution\n // In serverless environments, we can't rely on the original execution still running\n if (this.resumeResolvers.has(sessionId)) {\n this.resumeResolvers.delete(sessionId);\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Cleared existing resolver for session ${sessionId} before resuming`,\n timestamp: Date.now(),\n };\n }\n\n const stored = await this.storage.get(sessionId);\n\n if (!stored) {\n yield {\n type: \"arc-error\" as const,\n arcId: \"unknown\",\n error: new Error(`Session ${sessionId} not found or expired`),\n timestamp: Date.now(),\n };\n return;\n }\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Resuming session ${sessionId}, paused at node \"${stored.nodeId}\", arc: \"${stored.arc.id}\", has parent: ${!!stored.parentArc}`,\n timestamp: Date.now(),\n };\n\n const arcState = ArcState.fromSerialized<State, Context>(stored.snapshot);\n\n const resumeInput = input !== undefined ? input : stored.pendingInput;\n\n if (resumeInput === undefined) {\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: new Error(`No input provided for session ${sessionId}`),\n timestamp: Date.now(),\n };\n return;\n }\n\n // Set the input for the paused node\n const inputValue =\n typeof resumeInput === \"string\"\n ? resumeInput\n : JSON.stringify(resumeInput);\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Setting edge input for node \"${stored.nodeId}\" with value: ${inputValue}`,\n timestamp: Date.now(),\n };\n\n arcState.setEdgeContext(stored.nodeId, inputValue);\n\n try {\n // First, execute the sub-arc with the input to complete it\n yield* executeArc(\n stored.arc,\n arcState,\n this.resumeResolvers,\n new Set(stored.snapshot.executed),\n this.storage,\n sessionId\n );\n\n // If this was a sub-arc with a parent, continue the parent loop\n if (stored.parentArc && stored.parentLoopNodeId) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Sub-arc completed, continuing parent arc \"${stored.parentArc.id}\" loop \"${stored.parentLoopNodeId}\"`,\n timestamp: Date.now(),\n };\n\n // Use the stored parent executed set to continue from where we left off\n // This ensures we don't restart the parent arc from the beginning\n const parentExecuted = stored.parentExecuted\n ? new Set(stored.parentExecuted)\n : new Set<string>();\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Continuing parent arc with executed nodes: [${Array.from(parentExecuted).join(\", \")}]`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n stored.parentArc,\n arcState,\n this.resumeResolvers,\n parentExecuted, // Use stored parent executed set to continue from where we left off\n this.storage,\n sessionId\n );\n }\n\n // Check if executor is still paused (waiting for input)\n // If not paused, the arc completed successfully\n const stillPaused = await this.storage.get(sessionId);\n if (!stillPaused) {\n // Clear any remaining storage entry to be safe\n await this.storage.delete(sessionId);\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: stored.arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${stored.arc.id}\" completed`,\n timestamp: Date.now(),\n };\n }\n } catch (error) {\n await this.storage.delete(sessionId);\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n\n async *run<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(\n arc: Arc<State, Context>,\n state: State,\n sessionId?: string\n ): AsyncIterable<ArcEvent<State, Context>> {\n const arcState = new ArcState<State, Context>(state);\n const execSessionId = sessionId || this.sessionIdGenerator();\n\n try {\n yield {\n type: \"arc-started\" as const,\n arcId: arc.id,\n initialState: state,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" started`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n arc,\n arcState,\n this.resumeResolvers,\n undefined,\n this.storage,\n execSessionId\n );\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" completed`,\n timestamp: Date.now(),\n };\n\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n } catch (error) {\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n yield {\n type: \"arc-error\" as const,\n arcId: arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n}\n"],"names":["ArcNodeKind","ImmutableMap","ArcState"],"mappings":";;;;AAQO,gBAAgB,OAAO,CAI5B,IAA6B,EAC7B,QAAkC,EAAA;AAElC,IAAA,MAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,EAAE;AAE/C,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAKA,gBAAW,CAAC,KAAK,EAAE;AACtB,YAAA,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO;AAC1B,YAAA,OAAO,KAAK,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,CAAC;AAEvC,YAAA,MAAM,cAAc,GAAI,YAAoB,CAAC,gBAAgB;YAC7D,IAAI,cAAc,EAAE;gBAClB,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC;gBACjE,OAAQ,YAAoB,CAAC,gBAAgB;YAC/C;YAEA;QACF;AACA,QAAA,KAAKA,gBAAW,CAAC,MAAM,EAAE;AACvB,YAAA,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO;AAC3B,YAAA,OAAO,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,CAAC;AAExC,YAAA,MAAM,YAAY,GAAI,YAAoB,CAAC,cAAc;YAEzD,IAAI,YAAY,EAAE;AAChB,gBAAA,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC;gBAC/B,OAAQ,YAAoB,CAAC,cA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age/dist/index.js","../src/runtime.ts"],"sourcesContent":["import {\n ArcNode,\n ArcState,\n ArcNodeKind,\n ImmutableMap,\n ArcEvent,\n} from \"@arc-dev/core\";\n\nexport async function* execute<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n>(\n node: ArcNode<State, Context>,\n arcState: ArcState<State, Context>\n): AsyncIterable<ArcEvent<State, Context>> {\n const stateContext = arcState.getStateContext();\n const models = arcState.getModels();\n\n switch (node.kind) {\n case ArcNodeKind.Agent: {\n const agent = node.handler;\n yield* agent.run(stateContext, node.id, models);\n\n const pendingContext = (stateContext as any).__pendingContext;\n if (pendingContext) {\n arcState.setContext(pendingContext.nodeId, pendingContext.result);\n delete (stateContext as any).__pendingContext;\n }\n\n break;\n }\n case ArcNodeKind.Action: {\n const action = node.handler;\n yield* action.run(stateContext, node.id, models);\n\n const pendingState = (stateContext as any).__pendingState;\n\n if (pendingState) {\n arcState.setState(pendingState);\n delete (stateContext as any).__pendingState;\n }\n\n break;\n }\n case ArcNodeKind.Arc: {\n arcState.setContext(node.id, ImmutableMap({ executed: true }));\n break;\n }\n }\n}\n","import {\n Arc,\n ArcStateContext,\n ArcEdge,\n ArcNodeKind,\n ArcEvent,\n ArcState,\n} from \"@arc-dev/core\";\nimport { execute } from \"./nodes\";\nimport { Storage } from \"@arc-dev/storage\";\n\nconst buildDependencyMap = (\n nodes: Array<{ id: string }>,\n edges: ArcEdge[]\n): Map<string, string[]> => {\n const deps = new Map<string, string[]>();\n\n for (const node of nodes) {\n deps.set(node.id, []);\n }\n\n for (const edge of edges) {\n if (!edge.from || edge.from === edge.to) {\n continue;\n }\n const currentDeps = deps.get(edge.to) || [];\n currentDeps.push(edge.from);\n deps.set(edge.to, currentDeps);\n }\n\n return deps;\n};\n\nconst getEdgeConditions = (\n nodeId: string,\n edges: ArcEdge[],\n conditions: Map<string, (sc: ArcStateContext<any, any>) => boolean>\n): Array<(sc: ArcStateContext<any, any>) => boolean> => {\n const edgeConditions: Array<(sc: ArcStateContext<any, any>) => boolean> = [];\n\n for (const edge of edges) {\n if (edge.to === nodeId && edge.from && edge.from !== edge.to) {\n if (edge.when) {\n edgeConditions.push(edge.when);\n } else if (edge.condition && conditions.has(edge.condition)) {\n const conditionFn = conditions.get(edge.condition)!;\n edgeConditions.push(conditionFn);\n }\n }\n }\n\n return edgeConditions;\n};\n\nconst getWaitingEdges = (nodeId: string, edges: ArcEdge[]): ArcEdge[] => {\n return edges.filter(\n (edge) =>\n edge.to === nodeId && (!edge.from || edge.from !== edge.to) && edge.wait\n );\n};\n\nconst getLoopEdge = (nodeId: string, edges: ArcEdge[]): ArcEdge | null => {\n for (const edge of edges) {\n if (edge.from === nodeId && edge.to === nodeId) {\n return edge;\n }\n }\n return null;\n};\n\nexport async function* executeArc<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n>(\n arc: Arc<State, Context>,\n arcState: ArcState<State, Context>,\n resumeResolvers: Map<string, (value: any) => void>,\n initialExecuted?: Set<string>,\n storage?: Storage,\n sessionId?: string,\n parentArc?: Arc<any, any>,\n parentLoopNodeId?: string,\n parentExecutedNodes?: Set<string>,\n serverless?: boolean\n): AsyncIterable<ArcEvent<State, Context>> {\n const executed = initialExecuted\n ? new Set(initialExecuted)\n : new Set<string>();\n let changed = true;\n\n const dependencyMap = buildDependencyMap(arc.nodes, arc.edges);\n\n while (changed) {\n changed = false;\n\n for (const node of arc.nodes) {\n if (executed.has(node.id)) continue;\n\n const deps = dependencyMap.get(node.id) || [];\n const depsDone = deps.every((d: string) => executed.has(d));\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\": deps=${JSON.stringify(deps)}, depsDone=${depsDone}`,\n timestamp: Date.now(),\n };\n\n if (!depsDone) {\n continue;\n }\n\n const stateContext = arcState.getStateContext();\n\n const edgeConditions = getEdgeConditions(\n node.id,\n arc.edges,\n arc.conditions\n );\n\n if (edgeConditions.length > 0) {\n const allConditionsMet = edgeConditions.every((condFn) => {\n try {\n return condFn(stateContext);\n } catch (e) {\n return false;\n }\n });\n\n if (!allConditionsMet) {\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Skipping node \"${node.id}\" due to edge condition(s)`,\n timestamp: Date.now(),\n };\n executed.add(node.id);\n changed = true;\n continue;\n }\n }\n\n const waitingEdges = getWaitingEdges(node.id, arc.edges);\n\n if (waitingEdges.length > 0) {\n const edgeContext = arcState.getEdgeContext();\n const hasInput = edgeContext.has(node.id);\n\n if (hasInput) {\n const inputValue = edgeContext.get(node.id);\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\" has waiting edge(s) but input already provided (${inputValue}), continuing execution`,\n timestamp: Date.now(),\n };\n // Don't clear the edge input yet - let the node read it first\n // It will be cleared after node execution below\n } else {\n // No input yet, need to wait for it\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\" has ${waitingEdges.length} waiting edge(s)`,\n timestamp: Date.now(),\n };\n\n for (const edge of waitingEdges) {\n if (edge.wait) {\n const { message } = edge.wait;\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Pausing execution at node \"${node.id}\" waiting for input on edge ${edge.from || \"entry\"} -> ${edge.to}`,\n timestamp: Date.now(),\n };\n\n // Use sessionId if available, otherwise fall back to nodeId for same-instance resume\n const resolverKey = sessionId || node.id;\n const resumePromise = new Promise<any>((resolve) => {\n resumeResolvers.set(resolverKey, resolve);\n });\n\n // If storage is provided, store execution state\n // If this is a sub-arc, store both the sub-arc and parent arc so we can continue the loop\n if (storage && sessionId) {\n await storage.store(sessionId, {\n arc, // Store the current arc (sub-arc if in a loop)\n snapshot: {\n executed: Array.from(executed),\n ...arcState.serialize(),\n },\n nodeId: node.id,\n parentArc: parentArc || undefined, // Store parent arc if this is a sub-arc\n parentLoopNodeId: parentLoopNodeId || undefined, // Store loop node ID\n parentExecutedNodes: parentExecutedNodes\n ? Array.from(parentExecutedNodes)\n : undefined, // Store parent's executed set if this is a sub-arc\n });\n }\n\n // Emit node-paused with state - platforms handle validation themselves\n yield {\n type: \"node-paused\" as const,\n nodeId: node.id,\n prompt: message,\n state: stateContext.state.toJS() as State,\n context: stateContext.context.toJS() as Context,\n timestamp: Date.now(),\n sessionId: sessionId,\n snapshot: storage\n ? undefined // Don't include in event if using storage\n : {\n executed: Array.from(executed),\n ...arcState.serialize(),\n },\n };\n\n // In serverless environments (e.g., Cloudflare Workers), we must end the stream\n // after emitting the pause event to avoid hanging the request.\n // The client will need to call /resume to continue execution.\n if (serverless) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Pausing execution in serverless mode. Use /resume endpoint to continue.`,\n timestamp: Date.now(),\n };\n return; // End the generator, allowing the Worker to complete\n }\n\n // For in-process resumption (long-running environments), wait for the promise\n const result = await resumePromise;\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Resumed with input for node ${node.id}`,\n timestamp: Date.now(),\n };\n\n // Convert result to string for edge input (maintaining compatibility)\n const inputValue =\n typeof result === \"string\" ? result : JSON.stringify(result);\n arcState.setEdgeContext(node.id, inputValue);\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Input received on edge ${edge.from || \"entry\"} -> ${edge.to}`,\n timestamp: Date.now(),\n };\n }\n }\n }\n }\n\n const loopEdge = getLoopEdge(node.id, arc.edges);\n\n if (loopEdge && node.kind === ArcNodeKind.Arc && node.handler.arc) {\n const subArc = node.handler.arc;\n const maxIterations = loopEdge.maxIterations || 100;\n let iteration = 0;\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Starting loop \"${node.id}\" (max ${maxIterations} iterations)`,\n timestamp: Date.now(),\n };\n\n while (iteration < maxIterations) {\n const stateContext = arcState.getStateContext();\n\n let shouldContinue = true;\n\n if (loopEdge.when) {\n try {\n shouldContinue = loopEdge.when(stateContext);\n } catch (e) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: e instanceof Error ? e : new Error(String(e)),\n timestamp: Date.now(),\n };\n break;\n }\n } else if (\n loopEdge.condition &&\n arc.conditions.has(loopEdge.condition)\n ) {\n const conditionFn = arc.conditions.get(loopEdge.condition)!;\n try {\n shouldContinue = conditionFn(stateContext);\n } catch (e) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: e instanceof Error ? e : new Error(String(e)),\n timestamp: Date.now(),\n };\n break;\n }\n }\n\n if (!shouldContinue) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Loop \"${node.id}\" condition failed after ${iteration} iterations`,\n timestamp: Date.now(),\n };\n // Clear storage entry if loop completed naturally (not paused)\n // This ensures that when the executor finishes, the runtime knows the arc is done\n if (storage && sessionId) {\n await storage.delete(sessionId);\n }\n break;\n }\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Loop \"${node.id}\" iteration ${iteration + 1}`,\n timestamp: Date.now(),\n };\n\n const parentExecutedNodesSet = new Set(executed);\n\n yield* executeArc(\n subArc,\n arcState,\n resumeResolvers,\n undefined,\n storage,\n sessionId,\n arc,\n node.id,\n parentExecutedNodesSet,\n serverless\n );\n\n // In serverless mode, check if execution was paused\n // If the session still exists in storage, it means we paused\n if (serverless && storage && sessionId) {\n const storedSession = await storage.get(sessionId);\n if (storedSession) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Loop \"${node.id}\" paused in serverless mode at iteration ${iteration + 1}`,\n timestamp: Date.now(),\n };\n // Return early to end the stream and allow the Worker to complete\n return;\n }\n }\n\n iteration++;\n }\n\n if (iteration >= maxIterations) {\n yield {\n type: \"log\" as const,\n level: \"warn\" as const,\n message: `Loop \"${node.id}\" reached max iterations (${maxIterations})`,\n timestamp: Date.now(),\n };\n // Clear storage entry if loop completed due to max iterations (not paused)\n if (storage && sessionId) {\n await storage.delete(sessionId);\n }\n }\n\n executed.add(node.id);\n changed = true;\n } else {\n yield {\n type: \"node-started\" as const,\n nodeId: node.id,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Running node \"${node.id}\" (${node.kind})`,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `About to execute node ${node.id}`,\n timestamp: Date.now(),\n };\n\n try {\n yield* execute(node, arcState);\n } catch (error) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n throw error;\n }\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Finished executing node ${node.id}`,\n timestamp: Date.now(),\n };\n\n const stateContext = arcState.getStateContext();\n\n yield {\n type: \"node-completed\" as const,\n nodeId: node.id,\n state: stateContext.state.toJS() as State,\n context: stateContext.context.toJS() as Context,\n timestamp: Date.now(),\n };\n\n // Clear edge input after node execution if it was set (for waiting edges)\n const waitingEdgesForNode = getWaitingEdges(node.id, arc.edges);\n if (waitingEdgesForNode.length > 0) {\n const edgeContext = arcState.getEdgeContext();\n if (edgeContext.has(node.id)) {\n arcState.clearEdgeContext(node.id);\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Cleared edge input for node \"${node.id}\" after execution`,\n timestamp: Date.now(),\n };\n }\n }\n\n executed.add(node.id);\n\n changed = true;\n }\n }\n }\n}\n","class InMemoryStorage {\n executions = new Map();\n store(sessionId, execution) {\n this.executions.set(sessionId, execution);\n }\n get(sessionId) {\n return this.executions.get(sessionId) || null;\n }\n delete(sessionId) {\n this.executions.delete(sessionId);\n }\n}\n\nexport { InMemoryStorage };\n//# sourceMappingURL=index.js.map\n","import {\n ArcRuntime as ArcRuntimeType,\n Arc,\n ArcState,\n ArcEvent,\n} from \"@arc-dev/core\";\nimport { executeArc } from \"./executor\";\nimport { InMemoryStorage, Storage } from \"@arc-dev/storage\";\nimport { Models, createModels } from \"@arc-dev/model\";\n\nexport interface ArcRuntimeOptions {\n storage?: Storage;\n models?: Models;\n}\n\nexport class ArcRuntime implements ArcRuntimeType {\n protected resumeResolvers: Map<string, (value: any) => void> = new Map();\n protected storage: Storage;\n protected sessionIdGenerator: () => string;\n protected models: Models;\n\n constructor(options?: ArcRuntimeOptions) {\n this.storage = options?.storage || new InMemoryStorage();\n this.sessionIdGenerator = () =>\n `session_${Date.now()}_${Math.random().toString(36).substring(7)}`;\n\n if (options?.models) {\n this.models = options.models;\n } else {\n let apiKey = \"\";\n if (typeof globalThis !== \"undefined\") {\n const nodeProcess = (globalThis as any).process;\n apiKey = nodeProcess?.env?.OPENAI_API_KEY || \"\";\n if (!apiKey) {\n apiKey = (globalThis as any).OPENAI_API_KEY || \"\";\n }\n }\n\n if (!apiKey) {\n throw new Error(\n \"Models require an API key. Provide models via ArcRuntimeOptions or set OPENAI_API_KEY environment variable.\"\n );\n }\n\n this.models = createModels({ apiKey });\n }\n }\n\n async resume<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(sessionId: string, input: any): Promise<string | void> {\n const resolver = this.resumeResolvers.get(sessionId);\n\n if (resolver) {\n resolver(input);\n this.resumeResolvers.delete(sessionId);\n return;\n }\n\n const stored = this.storage.get(sessionId);\n const storedExecution = stored instanceof Promise ? await stored : stored;\n\n if (storedExecution) {\n storedExecution.pendingInput = input;\n\n const storeResult = this.storage.store(sessionId, storedExecution);\n if (storeResult instanceof Promise) {\n await storeResult;\n }\n\n return sessionId;\n }\n\n return sessionId;\n }\n\n async *resumeFromSession<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(sessionId: string, input?: any): AsyncIterable<ArcEvent<State, Context>> {\n if (this.resumeResolvers.has(sessionId)) {\n this.resumeResolvers.delete(sessionId);\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Cleared existing resolver for session ${sessionId} before resuming`,\n timestamp: Date.now(),\n };\n }\n\n const stored = await this.storage.get(sessionId);\n\n if (!stored) {\n yield {\n type: \"arc-error\" as const,\n arcId: \"unknown\",\n error: new Error(`Session ${sessionId} not found or expired`),\n timestamp: Date.now(),\n };\n return;\n }\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Resuming session ${sessionId}, paused at node \"${stored.nodeId}\", arc: \"${stored.arc.id}\", has parent: ${!!stored.parentArc}`,\n timestamp: Date.now(),\n };\n\n const arcState = ArcState.fromSerialized<State, Context>(\n stored.snapshot,\n this.models\n );\n\n const resumeInput = input !== undefined ? input : stored.pendingInput;\n\n if (resumeInput === undefined) {\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: new Error(`No input provided for session ${sessionId}`),\n timestamp: Date.now(),\n };\n return;\n }\n\n const inputValue =\n typeof resumeInput === \"string\"\n ? resumeInput\n : JSON.stringify(resumeInput);\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Setting edge input for node \"${stored.nodeId}\" with value: ${inputValue}`,\n timestamp: Date.now(),\n };\n\n arcState.setEdgeContext(stored.nodeId, inputValue);\n\n try {\n yield* executeArc(\n stored.arc,\n arcState,\n this.resumeResolvers,\n new Set(stored.snapshot.executed),\n this.storage,\n sessionId,\n undefined,\n undefined,\n undefined,\n false\n );\n\n if (stored.parentArc && stored.parentLoopNodeId) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Sub-arc completed, continuing parent arc \"${stored.parentArc.id}\" loop \"${stored.parentLoopNodeId}\"`,\n timestamp: Date.now(),\n };\n\n const parentExecutedNodes = stored.parentExecutedNodes\n ? new Set(stored.parentExecutedNodes)\n : new Set<string>();\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Continuing parent arc with executed nodes: [${Array.from(parentExecutedNodes).join(\", \")}]`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n stored.parentArc,\n arcState,\n this.resumeResolvers,\n parentExecutedNodes,\n this.storage,\n sessionId,\n undefined,\n undefined,\n undefined,\n false\n );\n }\n\n const stillPaused = await this.storage.get(sessionId);\n if (!stillPaused) {\n await this.storage.delete(sessionId);\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: stored.arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${stored.arc.id}\" completed`,\n timestamp: Date.now(),\n };\n }\n } catch (error) {\n await this.storage.delete(sessionId);\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n\n async *run<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(\n arc: Arc<State, Context>,\n state: State,\n sessionId?: string\n ): AsyncIterable<ArcEvent<State, Context>> {\n const arcState = new ArcState<State, Context>(state, this.models);\n const execSessionId = sessionId || this.sessionIdGenerator();\n\n try {\n yield {\n type: \"arc-started\" as const,\n arcId: arc.id,\n initialState: state,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" started`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n arc,\n arcState,\n this.resumeResolvers,\n undefined,\n this.storage,\n execSessionId,\n undefined,\n undefined,\n undefined,\n false\n );\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" completed`,\n timestamp: Date.now(),\n };\n\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n } catch (error) {\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n yield {\n type: \"arc-error\" as const,\n arcId: arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n}\n\nexport class ArcServerlessRuntime extends ArcRuntime {\n async *run<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(\n arc: Arc<State, Context>,\n state: State,\n sessionId?: string\n ): AsyncIterable<ArcEvent<State, Context>> {\n const arcState = new ArcState<State, Context>(state, this.models);\n const execSessionId = sessionId || this.sessionIdGenerator();\n\n try {\n yield {\n type: \"arc-started\" as const,\n arcId: arc.id,\n initialState: state,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" started (serverless mode)`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n arc,\n arcState,\n this.resumeResolvers,\n undefined,\n this.storage,\n execSessionId,\n undefined,\n undefined,\n undefined,\n true\n );\n\n const storedSession = await this.storage.get(execSessionId);\n if (storedSession) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" paused, session stored for resumption`,\n timestamp: Date.now(),\n };\n return;\n }\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" completed`,\n timestamp: Date.now(),\n };\n\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n } catch (error) {\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n yield {\n type: \"arc-error\" as const,\n arcId: arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n\n async *resumeFromSession<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(sessionId: string, input?: any): AsyncIterable<ArcEvent<State, Context>> {\n if (this.resumeResolvers.has(sessionId)) {\n this.resumeResolvers.delete(sessionId);\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Cleared existing resolver for session ${sessionId} before resuming`,\n timestamp: Date.now(),\n };\n }\n\n const stored = await this.storage.get(sessionId);\n\n if (!stored) {\n yield {\n type: \"arc-error\" as const,\n arcId: \"unknown\",\n error: new Error(`Session ${sessionId} not found or expired`),\n timestamp: Date.now(),\n };\n return;\n }\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Resuming session ${sessionId} (serverless mode), paused at node \"${stored.nodeId}\", arc: \"${stored.arc.id}\", has parent: ${!!stored.parentArc}`,\n timestamp: Date.now(),\n };\n\n const arcState = ArcState.fromSerialized<State, Context>(\n stored.snapshot,\n this.models\n );\n\n const resumeInput = input !== undefined ? input : stored.pendingInput;\n\n if (resumeInput === undefined) {\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: new Error(`No input provided for session ${sessionId}`),\n timestamp: Date.now(),\n };\n return;\n }\n\n const inputValue =\n typeof resumeInput === \"string\"\n ? resumeInput\n : JSON.stringify(resumeInput);\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Setting edge input for node \"${stored.nodeId}\" with value: ${inputValue}`,\n timestamp: Date.now(),\n };\n\n arcState.setEdgeContext(stored.nodeId, inputValue);\n\n try {\n yield* executeArc(\n stored.arc,\n arcState,\n this.resumeResolvers,\n new Set(stored.snapshot.executed),\n this.storage,\n sessionId,\n undefined,\n undefined,\n undefined,\n true\n );\n\n if (stored.parentArc && stored.parentLoopNodeId) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Sub-arc completed, continuing parent arc \"${stored.parentArc.id}\" loop \"${stored.parentLoopNodeId}\"`,\n timestamp: Date.now(),\n };\n\n // Use the stored parent executed set to continue from where we left off\n // This ensures we don't restart the parent arc from the beginning\n const parentExecutedNodes = stored.parentExecutedNodes\n ? new Set(stored.parentExecutedNodes)\n : new Set<string>();\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Continuing parent arc with executed nodes: [${Array.from(parentExecutedNodes).join(\", \")}]`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n stored.parentArc,\n arcState,\n this.resumeResolvers,\n parentExecutedNodes,\n this.storage,\n sessionId,\n undefined,\n undefined,\n undefined,\n true\n );\n }\n\n const stillPaused = await this.storage.get(sessionId);\n if (!stillPaused) {\n await this.storage.delete(sessionId);\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: stored.arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${stored.arc.id}\" completed`,\n timestamp: Date.now(),\n };\n }\n } catch (error) {\n await this.storage.delete(sessionId);\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n}\n"],"names":["ArcNodeKind","ImmutableMap","createModels","ArcState"],"mappings":";;;;;AAQO,gBAAgB,OAAO,CAI5B,IAA6B,EAC7B,QAAkC,EAAA;AAElC,IAAA,MAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,EAAE;AAC/C,IAAA,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,EAAE;AAEnC,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAKA,gBAAW,CAAC,KAAK,EAAE;AACtB,YAAA,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO;AAC1B,YAAA,OAAO,KAAK,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC;AAE/C,YAAA,MAAM,cAAc,GAAI,YAAoB,CAAC,gBAAgB;YAC7D,IAAI,cAAc,EAAE;gBAClB,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC;gBACjE,OAAQ,YAAoB,CAAC,gBAAgB;YAC/C;YAEA;QACF;AACA,QAAA,KAAKA,gBAAW,CAAC,MAAM,EAAE;AACvB,YAAA,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO;AAC3B,YAAA,OAAO,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,EA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AAa;AAC3C,oBAAA,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;iBACtB;YACH;QACF;QAAE,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;YACpC,MAAM;AACJ,gBAAA,IAAI,EAAE,WAAoB;AAC1B,gBAAA,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE;AACpB,gBAAA,KAAK,EAAE,KAAK,YAAY,KAAK,GAAG,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,gBAAA,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB;QACH;IACF;AACD;;;;;"}

@@ -1,32 +0,15 @@

import { Arc, ArcRuntime as ArcRuntime$1, ArcEvent } from '@arc-dev/core';
import { ArcRuntime as ArcRuntime$1, ArcEvent, Arc } from '@arc-dev/core';
export { ArcEvent } from '@arc-dev/core';
import { Storage } from '@arc-dev/storage';
import { Models } from '@arc-dev/model';
interface Snapshot {
executed: string[];
state: any;
nodeContext?: any;
edgeContext?: Record<string, any>;
}
interface StoredExecution {
arc: Arc<any, any>;
snapshot: Snapshot;
nodeId: string;
pendingInput?: any;
parentArc?: Arc<any, any>;
parentLoopNodeId?: string;
parentExecuted?: string[];
}
interface Storage {
store(sessionId: string, execution: StoredExecution): Promise<void> | void;
get(sessionId: string): Promise<StoredExecution | null> | StoredExecution | null;
delete(sessionId: string): Promise<void> | void;
}
interface ArcRuntimeOptions {
storage?: Storage;
models?: Models;
}
declare class ArcRuntime implements ArcRuntime$1 {
private resumeResolvers;
private storage;
private sessionIdGenerator;
protected resumeResolvers: Map<string, (value: any) => void>;
protected storage: Storage;
protected sessionIdGenerator: () => string;
protected models: Models;
constructor(options?: ArcRuntimeOptions);

@@ -37,11 +20,8 @@ resume<State extends Record<string, any>, Context extends Record<string, any>>(sessionId: string, input: any): Promise<string | void>;

}
declare class InMemoryStorage implements Storage {
private executions;
store(sessionId: string, execution: StoredExecution): void;
get(sessionId: string): StoredExecution | null;
delete(sessionId: string): void;
declare class ArcServerlessRuntime extends ArcRuntime {
run<State extends Record<string, any>, Context extends Record<string, any>>(arc: Arc<State, Context>, state: State, sessionId?: string): AsyncIterable<ArcEvent<State, Context>>;
resumeFromSession<State extends Record<string, any>, Context extends Record<string, any>>(sessionId: string, input?: any): AsyncIterable<ArcEvent<State, Context>>;
}
export { ArcRuntime, InMemoryStorage };
export type { ArcRuntimeOptions, Snapshot, Storage, StoredExecution };
export { ArcRuntime, ArcServerlessRuntime };
export type { ArcRuntimeOptions };

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,cAAc,WAAW,CAAC;AAC1B,mBAAmB,SAAS,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC7D,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,mBAAmB,SAAS,CAAC"}
import { ArcNodeKind, ImmutableMap, ArcState } from '@arc-dev/core';
import { createModels } from '@arc-dev/model';
async function* execute(node, arcState) {
const stateContext = arcState.getStateContext();
const models = arcState.getModels();
switch (node.kind) {
case ArcNodeKind.Agent: {
const agent = node.handler;
yield* agent.run(stateContext, node.id);
yield* agent.run(stateContext, node.id, models);
const pendingContext = stateContext.__pendingContext;

@@ -18,3 +20,3 @@ if (pendingContext) {

const action = node.handler;
yield* action.run(stateContext, node.id);
yield* action.run(stateContext, node.id, models);
const pendingState = stateContext.__pendingState;

@@ -40,3 +42,2 @@ if (pendingState) {

for (const edge of edges) {
// Entry edges (no from) don't add dependencies - target node is an entry point
if (!edge.from || edge.from === edge.to) {

@@ -77,3 +78,3 @@ continue;

};
async function* executeArc(arc, arcState, resumeResolvers, initialExecuted, storage, sessionId, parentArc, parentLoopNodeId, parentExecuted) {
async function* executeArc(arc, arcState, resumeResolvers, initialExecuted, storage, sessionId, parentArc, parentLoopNodeId, parentExecutedNodes, serverless) {
const executed = initialExecuted

@@ -172,4 +173,4 @@ ? new Set(initialExecuted)

parentLoopNodeId: parentLoopNodeId || undefined, // Store loop node ID
parentExecuted: parentExecuted
? Array.from(parentExecuted)
parentExecutedNodes: parentExecutedNodes
? Array.from(parentExecutedNodes)
: undefined, // Store parent's executed set if this is a sub-arc

@@ -194,2 +195,15 @@ });

};
// In serverless environments (e.g., Cloudflare Workers), we must end the stream
// after emitting the pause event to avoid hanging the request.
// The client will need to call /resume to continue execution.
if (serverless) {
yield {
type: "log",
level: "info",
message: `Pausing execution in serverless mode. Use /resume endpoint to continue.`,
timestamp: Date.now(),
};
return; // End the generator, allowing the Worker to complete
}
// For in-process resumption (long-running environments), wait for the promise
const result = await resumePromise;

@@ -279,6 +293,19 @@ yield {

};
// Store parent's executed set (without the loop node, so it can run again when resuming)
// The loop node needs to run again to check the condition and continue the loop
const parentExecutedSet = new Set(executed);
yield* executeArc(subArc, arcState, resumeResolvers, undefined, storage, sessionId, arc, node.id, parentExecutedSet);
const parentExecutedNodesSet = new Set(executed);
yield* executeArc(subArc, arcState, resumeResolvers, undefined, storage, sessionId, arc, node.id, parentExecutedNodesSet, serverless);
// In serverless mode, check if execution was paused
// If the session still exists in storage, it means we paused
if (serverless && storage && sessionId) {
const storedSession = await storage.get(sessionId);
if (storedSession) {
yield {
type: "log",
level: "info",
message: `Loop "${node.id}" paused in serverless mode at iteration ${iteration + 1}`,
timestamp: Date.now(),
};
// Return early to end the stream and allow the Worker to complete
return;
}
}
iteration++;

@@ -383,5 +410,23 @@ }

sessionIdGenerator;
models;
constructor(options) {
this.storage = options?.storage || new InMemoryStorage();
this.sessionIdGenerator = () => `session_${Date.now()}_${Math.random().toString(36).substring(7)}`;
if (options?.models) {
this.models = options.models;
}
else {
let apiKey = "";
if (typeof globalThis !== "undefined") {
const nodeProcess = globalThis.process;
apiKey = nodeProcess?.env?.OPENAI_API_KEY || "";
if (!apiKey) {
apiKey = globalThis.OPENAI_API_KEY || "";
}
}
if (!apiKey) {
throw new Error("Models require an API key. Provide models via ArcRuntimeOptions or set OPENAI_API_KEY environment variable.");
}
this.models = createModels({ apiKey });
}
}

@@ -408,4 +453,2 @@ async resume(sessionId, input) {

async *resumeFromSession(sessionId, input) {
// Clear any existing resolver since we're starting a new execution
// In serverless environments, we can't rely on the original execution still running
if (this.resumeResolvers.has(sessionId)) {

@@ -436,3 +479,3 @@ this.resumeResolvers.delete(sessionId);

};
const arcState = ArcState.fromSerialized(stored.snapshot);
const arcState = ArcState.fromSerialized(stored.snapshot, this.models);
const resumeInput = input !== undefined ? input : stored.pendingInput;

@@ -448,3 +491,2 @@ if (resumeInput === undefined) {

}
// Set the input for the paused node
const inputValue = typeof resumeInput === "string"

@@ -461,5 +503,3 @@ ? resumeInput

try {
// First, execute the sub-arc with the input to complete it
yield* executeArc(stored.arc, arcState, this.resumeResolvers, new Set(stored.snapshot.executed), this.storage, sessionId);
// If this was a sub-arc with a parent, continue the parent loop
yield* executeArc(stored.arc, arcState, this.resumeResolvers, new Set(stored.snapshot.executed), this.storage, sessionId, undefined, undefined, undefined, false);
if (stored.parentArc && stored.parentLoopNodeId) {

@@ -472,6 +512,4 @@ yield {

};
// Use the stored parent executed set to continue from where we left off
// This ensures we don't restart the parent arc from the beginning
const parentExecuted = stored.parentExecuted
? new Set(stored.parentExecuted)
const parentExecutedNodes = stored.parentExecutedNodes
? new Set(stored.parentExecutedNodes)
: new Set();

@@ -481,13 +519,9 @@ yield {

level: "info",
message: `Continuing parent arc with executed nodes: [${Array.from(parentExecuted).join(", ")}]`,
message: `Continuing parent arc with executed nodes: [${Array.from(parentExecutedNodes).join(", ")}]`,
timestamp: Date.now(),
};
yield* executeArc(stored.parentArc, arcState, this.resumeResolvers, parentExecuted, // Use stored parent executed set to continue from where we left off
this.storage, sessionId);
yield* executeArc(stored.parentArc, arcState, this.resumeResolvers, parentExecutedNodes, this.storage, sessionId, undefined, undefined, undefined, false);
}
// Check if executor is still paused (waiting for input)
// If not paused, the arc completed successfully
const stillPaused = await this.storage.get(sessionId);
if (!stillPaused) {
// Clear any remaining storage entry to be safe
await this.storage.delete(sessionId);

@@ -522,3 +556,3 @@ const finalContext = arcState.getContext().toJS();

async *run(arc, state, sessionId) {
const arcState = new ArcState(state);
const arcState = new ArcState(state, this.models);
const execSessionId = sessionId || this.sessionIdGenerator();

@@ -538,3 +572,3 @@ try {

};
yield* executeArc(arc, arcState, this.resumeResolvers, undefined, this.storage, execSessionId);
yield* executeArc(arc, arcState, this.resumeResolvers, undefined, this.storage, execSessionId, undefined, undefined, undefined, false);
const finalContext = arcState.getContext().toJS();

@@ -572,4 +606,163 @@ const finalState = arcState.getState().toJS();

}
class ArcServerlessRuntime extends ArcRuntime {
async *run(arc, state, sessionId) {
const arcState = new ArcState(state, this.models);
const execSessionId = sessionId || this.sessionIdGenerator();
try {
yield {
type: "arc-started",
arcId: arc.id,
initialState: state,
timestamp: Date.now(),
};
yield {
type: "log",
level: "info",
message: `Arc "${arc.id}" started (serverless mode)`,
timestamp: Date.now(),
};
yield* executeArc(arc, arcState, this.resumeResolvers, undefined, this.storage, execSessionId, undefined, undefined, undefined, true);
const storedSession = await this.storage.get(execSessionId);
if (storedSession) {
yield {
type: "log",
level: "info",
message: `Arc "${arc.id}" paused, session stored for resumption`,
timestamp: Date.now(),
};
return;
}
const finalContext = arcState.getContext().toJS();
const finalState = arcState.getState().toJS();
yield {
type: "arc-completed",
arcId: arc.id,
finalState,
finalContext,
timestamp: Date.now(),
};
yield {
type: "log",
level: "info",
message: `Arc "${arc.id}" completed`,
timestamp: Date.now(),
};
if (execSessionId) {
await this.storage.delete(execSessionId);
}
}
catch (error) {
if (execSessionId) {
await this.storage.delete(execSessionId);
}
yield {
type: "arc-error",
arcId: arc.id,
error: error instanceof Error ? error : new Error(String(error)),
timestamp: Date.now(),
};
}
}
async *resumeFromSession(sessionId, input) {
if (this.resumeResolvers.has(sessionId)) {
this.resumeResolvers.delete(sessionId);
yield {
type: "log",
level: "info",
message: `[Runtime] Cleared existing resolver for session ${sessionId} before resuming`,
timestamp: Date.now(),
};
}
const stored = await this.storage.get(sessionId);
if (!stored) {
yield {
type: "arc-error",
arcId: "unknown",
error: new Error(`Session ${sessionId} not found or expired`),
timestamp: Date.now(),
};
return;
}
yield {
type: "log",
level: "info",
message: `[Runtime] Resuming session ${sessionId} (serverless mode), paused at node "${stored.nodeId}", arc: "${stored.arc.id}", has parent: ${!!stored.parentArc}`,
timestamp: Date.now(),
};
const arcState = ArcState.fromSerialized(stored.snapshot, this.models);
const resumeInput = input !== undefined ? input : stored.pendingInput;
if (resumeInput === undefined) {
yield {
type: "arc-error",
arcId: stored.arc.id,
error: new Error(`No input provided for session ${sessionId}`),
timestamp: Date.now(),
};
return;
}
const inputValue = typeof resumeInput === "string"
? resumeInput
: JSON.stringify(resumeInput);
yield {
type: "log",
level: "info",
message: `[Runtime] Setting edge input for node "${stored.nodeId}" with value: ${inputValue}`,
timestamp: Date.now(),
};
arcState.setEdgeContext(stored.nodeId, inputValue);
try {
yield* executeArc(stored.arc, arcState, this.resumeResolvers, new Set(stored.snapshot.executed), this.storage, sessionId, undefined, undefined, undefined, true);
if (stored.parentArc && stored.parentLoopNodeId) {
yield {
type: "log",
level: "info",
message: `Sub-arc completed, continuing parent arc "${stored.parentArc.id}" loop "${stored.parentLoopNodeId}"`,
timestamp: Date.now(),
};
// Use the stored parent executed set to continue from where we left off
// This ensures we don't restart the parent arc from the beginning
const parentExecutedNodes = stored.parentExecutedNodes
? new Set(stored.parentExecutedNodes)
: new Set();
yield {
type: "log",
level: "info",
message: `Continuing parent arc with executed nodes: [${Array.from(parentExecutedNodes).join(", ")}]`,
timestamp: Date.now(),
};
yield* executeArc(stored.parentArc, arcState, this.resumeResolvers, parentExecutedNodes, this.storage, sessionId, undefined, undefined, undefined, true);
}
const stillPaused = await this.storage.get(sessionId);
if (!stillPaused) {
await this.storage.delete(sessionId);
const finalContext = arcState.getContext().toJS();
const finalState = arcState.getState().toJS();
yield {
type: "arc-completed",
arcId: stored.arc.id,
finalState,
finalContext,
timestamp: Date.now(),
};
yield {
type: "log",
level: "info",
message: `Arc "${stored.arc.id}" completed`,
timestamp: Date.now(),
};
}
}
catch (error) {
await this.storage.delete(sessionId);
yield {
type: "arc-error",
arcId: stored.arc.id,
error: error instanceof Error ? error : new Error(String(error)),
timestamp: Date.now(),
};
}
}
}
export { ArcRuntime, InMemoryStorage };
export { ArcRuntime, ArcServerlessRuntime };
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sources":["../src/nodes.ts","../src/executor.ts","../src/storage/in-memory.ts","../src/runtime.ts"],"sourcesContent":["import {\n ArcNode,\n ArcState,\n ArcNodeKind,\n ImmutableMap,\n ArcEvent,\n} from \"@arc-dev/core\";\n\nexport async function* execute<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n>(\n node: ArcNode<State, Context>,\n arcState: ArcState<State, Context>\n): AsyncIterable<ArcEvent<State, Context>> {\n const stateContext = arcState.getStateContext();\n\n switch (node.kind) {\n case ArcNodeKind.Agent: {\n const agent = node.handler;\n yield* agent.run(stateContext, node.id);\n\n const pendingContext = (stateContext as any).__pendingContext;\n if (pendingContext) {\n arcState.setContext(pendingContext.nodeId, pendingContext.result);\n delete (stateContext as any).__pendingContext;\n }\n\n break;\n }\n case ArcNodeKind.Action: {\n const action = node.handler;\n yield* action.run(stateContext, node.id);\n\n const pendingState = (stateContext as any).__pendingState;\n\n if (pendingState) {\n arcState.setState(pendingState);\n delete (stateContext as any).__pendingState;\n }\n\n break;\n }\n case ArcNodeKind.Arc: {\n arcState.setContext(node.id, ImmutableMap({ executed: true }));\n break;\n }\n }\n}\n","import {\n Arc,\n ArcStateContext,\n ArcEdge,\n ArcNodeKind,\n ArcEvent,\n ArcState,\n} from \"@arc-dev/core\";\nimport { execute } from \"./nodes\";\nimport { Storage } from \"./types\";\n\nconst buildDependencyMap = (\n nodes: Array<{ id: string }>,\n edges: ArcEdge[]\n): Map<string, string[]> => {\n const deps = new Map<string, string[]>();\n\n for (const node of nodes) {\n deps.set(node.id, []);\n }\n\n for (const edge of edges) {\n // Entry edges (no from) don't add dependencies - target node is an entry point\n if (!edge.from || edge.from === edge.to) {\n continue;\n }\n const currentDeps = deps.get(edge.to) || [];\n currentDeps.push(edge.from);\n deps.set(edge.to, currentDeps);\n }\n\n return deps;\n};\n\nconst getEdgeConditions = (\n nodeId: string,\n edges: ArcEdge[],\n conditions: Map<string, (sc: ArcStateContext<any, any>) => boolean>\n): Array<(sc: ArcStateContext<any, any>) => boolean> => {\n const edgeConditions: Array<(sc: ArcStateContext<any, any>) => boolean> = [];\n\n for (const edge of edges) {\n if (edge.to === nodeId && edge.from && edge.from !== edge.to) {\n if (edge.when) {\n edgeConditions.push(edge.when);\n } else if (edge.condition && conditions.has(edge.condition)) {\n const conditionFn = conditions.get(edge.condition)!;\n edgeConditions.push(conditionFn);\n }\n }\n }\n\n return edgeConditions;\n};\n\nconst getWaitingEdges = (nodeId: string, edges: ArcEdge[]): ArcEdge[] => {\n return edges.filter(\n (edge) =>\n edge.to === nodeId && (!edge.from || edge.from !== edge.to) && edge.wait\n );\n};\n\nconst getLoopEdge = (nodeId: string, edges: ArcEdge[]): ArcEdge | null => {\n for (const edge of edges) {\n if (edge.from === nodeId && edge.to === nodeId) {\n return edge;\n }\n }\n return null;\n};\n\nexport async function* executeArc<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n>(\n arc: Arc<State, Context>,\n arcState: ArcState<State, Context>,\n resumeResolvers: Map<string, (value: any) => void>,\n initialExecuted?: Set<string>,\n storage?: Storage,\n sessionId?: string,\n parentArc?: Arc<any, any>,\n parentLoopNodeId?: string,\n parentExecuted?: Set<string>\n): AsyncIterable<ArcEvent<State, Context>> {\n const executed = initialExecuted\n ? new Set(initialExecuted)\n : new Set<string>();\n let changed = true;\n\n const dependencyMap = buildDependencyMap(arc.nodes, arc.edges);\n\n while (changed) {\n changed = false;\n\n for (const node of arc.nodes) {\n if (executed.has(node.id)) continue;\n\n const deps = dependencyMap.get(node.id) || [];\n const depsDone = deps.every((d: string) => executed.has(d));\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\": deps=${JSON.stringify(deps)}, depsDone=${depsDone}`,\n timestamp: Date.now(),\n };\n\n if (!depsDone) {\n continue;\n }\n\n const stateContext = arcState.getStateContext();\n\n const edgeConditions = getEdgeConditions(\n node.id,\n arc.edges,\n arc.conditions\n );\n\n if (edgeConditions.length > 0) {\n const allConditionsMet = edgeConditions.every((condFn) => {\n try {\n return condFn(stateContext);\n } catch (e) {\n return false;\n }\n });\n\n if (!allConditionsMet) {\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Skipping node \"${node.id}\" due to edge condition(s)`,\n timestamp: Date.now(),\n };\n executed.add(node.id);\n changed = true;\n continue;\n }\n }\n\n const waitingEdges = getWaitingEdges(node.id, arc.edges);\n\n if (waitingEdges.length > 0) {\n const edgeContext = arcState.getEdgeContext();\n const hasInput = edgeContext.has(node.id);\n\n if (hasInput) {\n const inputValue = edgeContext.get(node.id);\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\" has waiting edge(s) but input already provided (${inputValue}), continuing execution`,\n timestamp: Date.now(),\n };\n // Don't clear the edge input yet - let the node read it first\n // It will be cleared after node execution below\n } else {\n // No input yet, need to wait for it\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\" has ${waitingEdges.length} waiting edge(s)`,\n timestamp: Date.now(),\n };\n\n for (const edge of waitingEdges) {\n if (edge.wait) {\n const { message } = edge.wait;\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Pausing execution at node \"${node.id}\" waiting for input on edge ${edge.from || \"entry\"} -> ${edge.to}`,\n timestamp: Date.now(),\n };\n\n // Use sessionId if available, otherwise fall back to nodeId for same-instance resume\n const resolverKey = sessionId || node.id;\n const resumePromise = new Promise<any>((resolve) => {\n resumeResolvers.set(resolverKey, resolve);\n });\n\n // If storage is provided, store execution state\n // If this is a sub-arc, store both the sub-arc and parent arc so we can continue the loop\n if (storage && sessionId) {\n await storage.store(sessionId, {\n arc, // Store the current arc (sub-arc if in a loop)\n snapshot: {\n executed: Array.from(executed),\n ...arcState.serialize(),\n },\n nodeId: node.id,\n parentArc: parentArc || undefined, // Store parent arc if this is a sub-arc\n parentLoopNodeId: parentLoopNodeId || undefined, // Store loop node ID\n parentExecuted: parentExecuted\n ? Array.from(parentExecuted)\n : undefined, // Store parent's executed set if this is a sub-arc\n });\n }\n\n // Emit node-paused with state - platforms handle validation themselves\n yield {\n type: \"node-paused\" as const,\n nodeId: node.id,\n prompt: message,\n state: stateContext.state.toJS() as State,\n context: stateContext.context.toJS() as Context,\n timestamp: Date.now(),\n sessionId: sessionId,\n snapshot: storage\n ? undefined // Don't include in event if using storage\n : {\n executed: Array.from(executed),\n ...arcState.serialize(),\n },\n };\n\n const result = await resumePromise;\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Resumed with input for node ${node.id}`,\n timestamp: Date.now(),\n };\n\n // Convert result to string for edge input (maintaining compatibility)\n const inputValue =\n typeof result === \"string\" ? result : JSON.stringify(result);\n arcState.setEdgeContext(node.id, inputValue);\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Input received on edge ${edge.from || \"entry\"} -> ${edge.to}`,\n timestamp: Date.now(),\n };\n }\n }\n }\n }\n\n const loopEdge = getLoopEdge(node.id, arc.edges);\n\n if (loopEdge && node.kind === ArcNodeKind.Arc && node.handler.arc) {\n const subArc = node.handler.arc;\n const maxIterations = loopEdge.maxIterations || 100;\n let iteration = 0;\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Starting loop \"${node.id}\" (max ${maxIterations} iterations)`,\n timestamp: Date.now(),\n };\n\n while (iteration < maxIterations) {\n const stateContext = arcState.getStateContext();\n\n let shouldContinue = true;\n\n if (loopEdge.when) {\n try {\n shouldContinue = loopEdge.when(stateContext);\n } catch (e) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: e instanceof Error ? e : new Error(String(e)),\n timestamp: Date.now(),\n };\n break;\n }\n } else if (\n loopEdge.condition &&\n arc.conditions.has(loopEdge.condition)\n ) {\n const conditionFn = arc.conditions.get(loopEdge.condition)!;\n try {\n shouldContinue = conditionFn(stateContext);\n } catch (e) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: e instanceof Error ? e : new Error(String(e)),\n timestamp: Date.now(),\n };\n break;\n }\n }\n\n if (!shouldContinue) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Loop \"${node.id}\" condition failed after ${iteration} iterations`,\n timestamp: Date.now(),\n };\n // Clear storage entry if loop completed naturally (not paused)\n // This ensures that when the executor finishes, the runtime knows the arc is done\n if (storage && sessionId) {\n await storage.delete(sessionId);\n }\n break;\n }\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Loop \"${node.id}\" iteration ${iteration + 1}`,\n timestamp: Date.now(),\n };\n\n // Store parent's executed set (without the loop node, so it can run again when resuming)\n // The loop node needs to run again to check the condition and continue the loop\n const parentExecutedSet = new Set(executed);\n\n yield* executeArc(\n subArc,\n arcState,\n resumeResolvers,\n undefined,\n storage,\n sessionId,\n arc,\n node.id,\n parentExecutedSet\n );\n\n iteration++;\n }\n\n if (iteration >= maxIterations) {\n yield {\n type: \"log\" as const,\n level: \"warn\" as const,\n message: `Loop \"${node.id}\" reached max iterations (${maxIterations})`,\n timestamp: Date.now(),\n };\n // Clear storage entry if loop completed due to max iterations (not paused)\n if (storage && sessionId) {\n await storage.delete(sessionId);\n }\n }\n\n executed.add(node.id);\n changed = true;\n } else {\n yield {\n type: \"node-started\" as const,\n nodeId: node.id,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Running node \"${node.id}\" (${node.kind})`,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `About to execute node ${node.id}`,\n timestamp: Date.now(),\n };\n\n try {\n yield* execute(node, arcState);\n } catch (error) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n throw error;\n }\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Finished executing node ${node.id}`,\n timestamp: Date.now(),\n };\n\n const stateContext = arcState.getStateContext();\n\n yield {\n type: \"node-completed\" as const,\n nodeId: node.id,\n state: stateContext.state.toJS() as State,\n context: stateContext.context.toJS() as Context,\n timestamp: Date.now(),\n };\n\n // Clear edge input after node execution if it was set (for waiting edges)\n const waitingEdgesForNode = getWaitingEdges(node.id, arc.edges);\n if (waitingEdgesForNode.length > 0) {\n const edgeContext = arcState.getEdgeContext();\n if (edgeContext.has(node.id)) {\n arcState.clearEdgeContext(node.id);\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Cleared edge input for node \"${node.id}\" after execution`,\n timestamp: Date.now(),\n };\n }\n }\n\n executed.add(node.id);\n\n changed = true;\n }\n }\n }\n}\n","import { Storage, StoredExecution } from \"..\";\n\nexport class InMemoryStorage implements Storage {\n private executions: Map<string, StoredExecution> = new Map();\n\n store(sessionId: string, execution: StoredExecution): void {\n this.executions.set(sessionId, execution);\n }\n\n get(sessionId: string): StoredExecution | null {\n return this.executions.get(sessionId) || null;\n }\n\n delete(sessionId: string): void {\n this.executions.delete(sessionId);\n }\n}\n","import {\n ArcRuntime as ArcRuntimeType,\n Arc,\n ArcState,\n ArcEvent,\n} from \"@arc-dev/core\";\nimport { executeArc } from \"./executor\";\nimport { InMemoryStorage } from \"./storage\";\nimport { Storage } from \"./types/storage\";\n\nexport interface ArcRuntimeOptions {\n storage?: Storage;\n}\n\nexport class ArcRuntime implements ArcRuntimeType {\n private resumeResolvers: Map<string, (value: any) => void> = new Map();\n private storage: Storage;\n private sessionIdGenerator: () => string;\n\n constructor(options?: ArcRuntimeOptions) {\n this.storage = options?.storage || new InMemoryStorage();\n this.sessionIdGenerator = () =>\n `session_${Date.now()}_${Math.random().toString(36).substring(7)}`;\n }\n\n async resume<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(sessionId: string, input: any): Promise<string | void> {\n const resolver = this.resumeResolvers.get(sessionId);\n\n if (resolver) {\n resolver(input);\n this.resumeResolvers.delete(sessionId);\n return;\n }\n\n const stored = this.storage.get(sessionId);\n const storedExecution = stored instanceof Promise ? await stored : stored;\n\n if (storedExecution) {\n storedExecution.pendingInput = input;\n\n const storeResult = this.storage.store(sessionId, storedExecution);\n if (storeResult instanceof Promise) {\n await storeResult;\n }\n\n return sessionId;\n }\n\n return sessionId;\n }\n\n async *resumeFromSession<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(sessionId: string, input?: any): AsyncIterable<ArcEvent<State, Context>> {\n // Clear any existing resolver since we're starting a new execution\n // In serverless environments, we can't rely on the original execution still running\n if (this.resumeResolvers.has(sessionId)) {\n this.resumeResolvers.delete(sessionId);\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Cleared existing resolver for session ${sessionId} before resuming`,\n timestamp: Date.now(),\n };\n }\n\n const stored = await this.storage.get(sessionId);\n\n if (!stored) {\n yield {\n type: \"arc-error\" as const,\n arcId: \"unknown\",\n error: new Error(`Session ${sessionId} not found or expired`),\n timestamp: Date.now(),\n };\n return;\n }\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Resuming session ${sessionId}, paused at node \"${stored.nodeId}\", arc: \"${stored.arc.id}\", has parent: ${!!stored.parentArc}`,\n timestamp: Date.now(),\n };\n\n const arcState = ArcState.fromSerialized<State, Context>(stored.snapshot);\n\n const resumeInput = input !== undefined ? input : stored.pendingInput;\n\n if (resumeInput === undefined) {\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: new Error(`No input provided for session ${sessionId}`),\n timestamp: Date.now(),\n };\n return;\n }\n\n // Set the input for the paused node\n const inputValue =\n typeof resumeInput === \"string\"\n ? resumeInput\n : JSON.stringify(resumeInput);\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Setting edge input for node \"${stored.nodeId}\" with value: ${inputValue}`,\n timestamp: Date.now(),\n };\n\n arcState.setEdgeContext(stored.nodeId, inputValue);\n\n try {\n // First, execute the sub-arc with the input to complete it\n yield* executeArc(\n stored.arc,\n arcState,\n this.resumeResolvers,\n new Set(stored.snapshot.executed),\n this.storage,\n sessionId\n );\n\n // If this was a sub-arc with a parent, continue the parent loop\n if (stored.parentArc && stored.parentLoopNodeId) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Sub-arc completed, continuing parent arc \"${stored.parentArc.id}\" loop \"${stored.parentLoopNodeId}\"`,\n timestamp: Date.now(),\n };\n\n // Use the stored parent executed set to continue from where we left off\n // This ensures we don't restart the parent arc from the beginning\n const parentExecuted = stored.parentExecuted\n ? new Set(stored.parentExecuted)\n : new Set<string>();\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Continuing parent arc with executed nodes: [${Array.from(parentExecuted).join(\", \")}]`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n stored.parentArc,\n arcState,\n this.resumeResolvers,\n parentExecuted, // Use stored parent executed set to continue from where we left off\n this.storage,\n sessionId\n );\n }\n\n // Check if executor is still paused (waiting for input)\n // If not paused, the arc completed successfully\n const stillPaused = await this.storage.get(sessionId);\n if (!stillPaused) {\n // Clear any remaining storage entry to be safe\n await this.storage.delete(sessionId);\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: stored.arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${stored.arc.id}\" completed`,\n timestamp: Date.now(),\n };\n }\n } catch (error) {\n await this.storage.delete(sessionId);\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n\n async *run<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(\n arc: Arc<State, Context>,\n state: State,\n sessionId?: string\n ): AsyncIterable<ArcEvent<State, Context>> {\n const arcState = new ArcState<State, Context>(state);\n const execSessionId = sessionId || this.sessionIdGenerator();\n\n try {\n yield {\n type: \"arc-started\" as const,\n arcId: arc.id,\n initialState: state,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" started`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n arc,\n arcState,\n this.resumeResolvers,\n undefined,\n this.storage,\n execSessionId\n );\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" completed`,\n timestamp: Date.now(),\n };\n\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n } catch (error) {\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n yield {\n type: \"arc-error\" as const,\n arcId: arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n}\n"],"names":[],"mappings":";;AAQO,gBAAgB,OAAO,CAI5B,IAA6B,EAC7B,QAAkC,EAAA;AAElC,IAAA,MAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,EAAE;AAE/C,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,WA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E,MAAe;AACtB,gBAAA,OAAO,EAAE,CAAA,KAAA,EAAQ,GAAG,CAAC,EAAE,CAAA,WAAA,CAAa;AACpC,gBAAA,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB;YAED,IAAI,aAAa,EAAE;gBACjB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC;YAC1C;QACF;QAAE,OAAO,KAAK,EAAE;YACd,IAAI,aAAa,EAAE;gBACjB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC;YAC1C;YACA,MAAM;AACJ,gBAAA,IAAI,EAAE,WAAoB;gBAC1B,KAAK,EAAE,GAAG,CAAC,EAAE;AACb,gBAAA,KAAK,EAAE,KAAK,YAAY,KAAK,GAAG,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,gBAAA,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB;QACH;IACF;AACD;;;;"}
{"version":3,"file":"index.js","sources":["../src/nodes.ts","../src/executor.ts","../../arc-storage/dist/index.js","../src/runtime.ts"],"sourcesContent":["import {\n ArcNode,\n ArcState,\n ArcNodeKind,\n ImmutableMap,\n ArcEvent,\n} from \"@arc-dev/core\";\n\nexport async function* execute<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n>(\n node: ArcNode<State, Context>,\n arcState: ArcState<State, Context>\n): AsyncIterable<ArcEvent<State, Context>> {\n const stateContext = arcState.getStateContext();\n const models = arcState.getModels();\n\n switch (node.kind) {\n case ArcNodeKind.Agent: {\n const agent = node.handler;\n yield* agent.run(stateContext, node.id, models);\n\n const pendingContext = (stateContext as any).__pendingContext;\n if (pendingContext) {\n arcState.setContext(pendingContext.nodeId, pendingContext.result);\n delete (stateContext as any).__pendingContext;\n }\n\n break;\n }\n case ArcNodeKind.Action: {\n const action = node.handler;\n yield* action.run(stateContext, node.id, models);\n\n const pendingState = (stateContext as any).__pendingState;\n\n if (pendingState) {\n arcState.setState(pendingState);\n delete (stateContext as any).__pendingState;\n }\n\n break;\n }\n case ArcNodeKind.Arc: {\n arcState.setContext(node.id, ImmutableMap({ executed: true }));\n break;\n }\n }\n}\n","import {\n Arc,\n ArcStateContext,\n ArcEdge,\n ArcNodeKind,\n ArcEvent,\n ArcState,\n} from \"@arc-dev/core\";\nimport { execute } from \"./nodes\";\nimport { Storage } from \"@arc-dev/storage\";\n\nconst buildDependencyMap = (\n nodes: Array<{ id: string }>,\n edges: ArcEdge[]\n): Map<string, string[]> => {\n const deps = new Map<string, string[]>();\n\n for (const node of nodes) {\n deps.set(node.id, []);\n }\n\n for (const edge of edges) {\n if (!edge.from || edge.from === edge.to) {\n continue;\n }\n const currentDeps = deps.get(edge.to) || [];\n currentDeps.push(edge.from);\n deps.set(edge.to, currentDeps);\n }\n\n return deps;\n};\n\nconst getEdgeConditions = (\n nodeId: string,\n edges: ArcEdge[],\n conditions: Map<string, (sc: ArcStateContext<any, any>) => boolean>\n): Array<(sc: ArcStateContext<any, any>) => boolean> => {\n const edgeConditions: Array<(sc: ArcStateContext<any, any>) => boolean> = [];\n\n for (const edge of edges) {\n if (edge.to === nodeId && edge.from && edge.from !== edge.to) {\n if (edge.when) {\n edgeConditions.push(edge.when);\n } else if (edge.condition && conditions.has(edge.condition)) {\n const conditionFn = conditions.get(edge.condition)!;\n edgeConditions.push(conditionFn);\n }\n }\n }\n\n return edgeConditions;\n};\n\nconst getWaitingEdges = (nodeId: string, edges: ArcEdge[]): ArcEdge[] => {\n return edges.filter(\n (edge) =>\n edge.to === nodeId && (!edge.from || edge.from !== edge.to) && edge.wait\n );\n};\n\nconst getLoopEdge = (nodeId: string, edges: ArcEdge[]): ArcEdge | null => {\n for (const edge of edges) {\n if (edge.from === nodeId && edge.to === nodeId) {\n return edge;\n }\n }\n return null;\n};\n\nexport async function* executeArc<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n>(\n arc: Arc<State, Context>,\n arcState: ArcState<State, Context>,\n resumeResolvers: Map<string, (value: any) => void>,\n initialExecuted?: Set<string>,\n storage?: Storage,\n sessionId?: string,\n parentArc?: Arc<any, any>,\n parentLoopNodeId?: string,\n parentExecutedNodes?: Set<string>,\n serverless?: boolean\n): AsyncIterable<ArcEvent<State, Context>> {\n const executed = initialExecuted\n ? new Set(initialExecuted)\n : new Set<string>();\n let changed = true;\n\n const dependencyMap = buildDependencyMap(arc.nodes, arc.edges);\n\n while (changed) {\n changed = false;\n\n for (const node of arc.nodes) {\n if (executed.has(node.id)) continue;\n\n const deps = dependencyMap.get(node.id) || [];\n const depsDone = deps.every((d: string) => executed.has(d));\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\": deps=${JSON.stringify(deps)}, depsDone=${depsDone}`,\n timestamp: Date.now(),\n };\n\n if (!depsDone) {\n continue;\n }\n\n const stateContext = arcState.getStateContext();\n\n const edgeConditions = getEdgeConditions(\n node.id,\n arc.edges,\n arc.conditions\n );\n\n if (edgeConditions.length > 0) {\n const allConditionsMet = edgeConditions.every((condFn) => {\n try {\n return condFn(stateContext);\n } catch (e) {\n return false;\n }\n });\n\n if (!allConditionsMet) {\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Skipping node \"${node.id}\" due to edge condition(s)`,\n timestamp: Date.now(),\n };\n executed.add(node.id);\n changed = true;\n continue;\n }\n }\n\n const waitingEdges = getWaitingEdges(node.id, arc.edges);\n\n if (waitingEdges.length > 0) {\n const edgeContext = arcState.getEdgeContext();\n const hasInput = edgeContext.has(node.id);\n\n if (hasInput) {\n const inputValue = edgeContext.get(node.id);\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\" has waiting edge(s) but input already provided (${inputValue}), continuing execution`,\n timestamp: Date.now(),\n };\n // Don't clear the edge input yet - let the node read it first\n // It will be cleared after node execution below\n } else {\n // No input yet, need to wait for it\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Node \"${node.id}\" has ${waitingEdges.length} waiting edge(s)`,\n timestamp: Date.now(),\n };\n\n for (const edge of waitingEdges) {\n if (edge.wait) {\n const { message } = edge.wait;\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Pausing execution at node \"${node.id}\" waiting for input on edge ${edge.from || \"entry\"} -> ${edge.to}`,\n timestamp: Date.now(),\n };\n\n // Use sessionId if available, otherwise fall back to nodeId for same-instance resume\n const resolverKey = sessionId || node.id;\n const resumePromise = new Promise<any>((resolve) => {\n resumeResolvers.set(resolverKey, resolve);\n });\n\n // If storage is provided, store execution state\n // If this is a sub-arc, store both the sub-arc and parent arc so we can continue the loop\n if (storage && sessionId) {\n await storage.store(sessionId, {\n arc, // Store the current arc (sub-arc if in a loop)\n snapshot: {\n executed: Array.from(executed),\n ...arcState.serialize(),\n },\n nodeId: node.id,\n parentArc: parentArc || undefined, // Store parent arc if this is a sub-arc\n parentLoopNodeId: parentLoopNodeId || undefined, // Store loop node ID\n parentExecutedNodes: parentExecutedNodes\n ? Array.from(parentExecutedNodes)\n : undefined, // Store parent's executed set if this is a sub-arc\n });\n }\n\n // Emit node-paused with state - platforms handle validation themselves\n yield {\n type: \"node-paused\" as const,\n nodeId: node.id,\n prompt: message,\n state: stateContext.state.toJS() as State,\n context: stateContext.context.toJS() as Context,\n timestamp: Date.now(),\n sessionId: sessionId,\n snapshot: storage\n ? undefined // Don't include in event if using storage\n : {\n executed: Array.from(executed),\n ...arcState.serialize(),\n },\n };\n\n // In serverless environments (e.g., Cloudflare Workers), we must end the stream\n // after emitting the pause event to avoid hanging the request.\n // The client will need to call /resume to continue execution.\n if (serverless) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Pausing execution in serverless mode. Use /resume endpoint to continue.`,\n timestamp: Date.now(),\n };\n return; // End the generator, allowing the Worker to complete\n }\n\n // For in-process resumption (long-running environments), wait for the promise\n const result = await resumePromise;\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Resumed with input for node ${node.id}`,\n timestamp: Date.now(),\n };\n\n // Convert result to string for edge input (maintaining compatibility)\n const inputValue =\n typeof result === \"string\" ? result : JSON.stringify(result);\n arcState.setEdgeContext(node.id, inputValue);\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Input received on edge ${edge.from || \"entry\"} -> ${edge.to}`,\n timestamp: Date.now(),\n };\n }\n }\n }\n }\n\n const loopEdge = getLoopEdge(node.id, arc.edges);\n\n if (loopEdge && node.kind === ArcNodeKind.Arc && node.handler.arc) {\n const subArc = node.handler.arc;\n const maxIterations = loopEdge.maxIterations || 100;\n let iteration = 0;\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Starting loop \"${node.id}\" (max ${maxIterations} iterations)`,\n timestamp: Date.now(),\n };\n\n while (iteration < maxIterations) {\n const stateContext = arcState.getStateContext();\n\n let shouldContinue = true;\n\n if (loopEdge.when) {\n try {\n shouldContinue = loopEdge.when(stateContext);\n } catch (e) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: e instanceof Error ? e : new Error(String(e)),\n timestamp: Date.now(),\n };\n break;\n }\n } else if (\n loopEdge.condition &&\n arc.conditions.has(loopEdge.condition)\n ) {\n const conditionFn = arc.conditions.get(loopEdge.condition)!;\n try {\n shouldContinue = conditionFn(stateContext);\n } catch (e) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: e instanceof Error ? e : new Error(String(e)),\n timestamp: Date.now(),\n };\n break;\n }\n }\n\n if (!shouldContinue) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Loop \"${node.id}\" condition failed after ${iteration} iterations`,\n timestamp: Date.now(),\n };\n // Clear storage entry if loop completed naturally (not paused)\n // This ensures that when the executor finishes, the runtime knows the arc is done\n if (storage && sessionId) {\n await storage.delete(sessionId);\n }\n break;\n }\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Loop \"${node.id}\" iteration ${iteration + 1}`,\n timestamp: Date.now(),\n };\n\n const parentExecutedNodesSet = new Set(executed);\n\n yield* executeArc(\n subArc,\n arcState,\n resumeResolvers,\n undefined,\n storage,\n sessionId,\n arc,\n node.id,\n parentExecutedNodesSet,\n serverless\n );\n\n // In serverless mode, check if execution was paused\n // If the session still exists in storage, it means we paused\n if (serverless && storage && sessionId) {\n const storedSession = await storage.get(sessionId);\n if (storedSession) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Loop \"${node.id}\" paused in serverless mode at iteration ${iteration + 1}`,\n timestamp: Date.now(),\n };\n // Return early to end the stream and allow the Worker to complete\n return;\n }\n }\n\n iteration++;\n }\n\n if (iteration >= maxIterations) {\n yield {\n type: \"log\" as const,\n level: \"warn\" as const,\n message: `Loop \"${node.id}\" reached max iterations (${maxIterations})`,\n timestamp: Date.now(),\n };\n // Clear storage entry if loop completed due to max iterations (not paused)\n if (storage && sessionId) {\n await storage.delete(sessionId);\n }\n }\n\n executed.add(node.id);\n changed = true;\n } else {\n yield {\n type: \"node-started\" as const,\n nodeId: node.id,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Running node \"${node.id}\" (${node.kind})`,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `About to execute node ${node.id}`,\n timestamp: Date.now(),\n };\n\n try {\n yield* execute(node, arcState);\n } catch (error) {\n yield {\n type: \"node-error\" as const,\n nodeId: node.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n throw error;\n }\n\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Finished executing node ${node.id}`,\n timestamp: Date.now(),\n };\n\n const stateContext = arcState.getStateContext();\n\n yield {\n type: \"node-completed\" as const,\n nodeId: node.id,\n state: stateContext.state.toJS() as State,\n context: stateContext.context.toJS() as Context,\n timestamp: Date.now(),\n };\n\n // Clear edge input after node execution if it was set (for waiting edges)\n const waitingEdgesForNode = getWaitingEdges(node.id, arc.edges);\n if (waitingEdgesForNode.length > 0) {\n const edgeContext = arcState.getEdgeContext();\n if (edgeContext.has(node.id)) {\n arcState.clearEdgeContext(node.id);\n yield {\n type: \"log\" as const,\n level: \"debug\" as const,\n message: `Cleared edge input for node \"${node.id}\" after execution`,\n timestamp: Date.now(),\n };\n }\n }\n\n executed.add(node.id);\n\n changed = true;\n }\n }\n }\n}\n","class InMemoryStorage {\n executions = new Map();\n store(sessionId, execution) {\n this.executions.set(sessionId, execution);\n }\n get(sessionId) {\n return this.executions.get(sessionId) || null;\n }\n delete(sessionId) {\n this.executions.delete(sessionId);\n }\n}\n\nexport { InMemoryStorage };\n//# sourceMappingURL=index.js.map\n","import {\n ArcRuntime as ArcRuntimeType,\n Arc,\n ArcState,\n ArcEvent,\n} from \"@arc-dev/core\";\nimport { executeArc } from \"./executor\";\nimport { InMemoryStorage, Storage } from \"@arc-dev/storage\";\nimport { Models, createModels } from \"@arc-dev/model\";\n\nexport interface ArcRuntimeOptions {\n storage?: Storage;\n models?: Models;\n}\n\nexport class ArcRuntime implements ArcRuntimeType {\n protected resumeResolvers: Map<string, (value: any) => void> = new Map();\n protected storage: Storage;\n protected sessionIdGenerator: () => string;\n protected models: Models;\n\n constructor(options?: ArcRuntimeOptions) {\n this.storage = options?.storage || new InMemoryStorage();\n this.sessionIdGenerator = () =>\n `session_${Date.now()}_${Math.random().toString(36).substring(7)}`;\n\n if (options?.models) {\n this.models = options.models;\n } else {\n let apiKey = \"\";\n if (typeof globalThis !== \"undefined\") {\n const nodeProcess = (globalThis as any).process;\n apiKey = nodeProcess?.env?.OPENAI_API_KEY || \"\";\n if (!apiKey) {\n apiKey = (globalThis as any).OPENAI_API_KEY || \"\";\n }\n }\n\n if (!apiKey) {\n throw new Error(\n \"Models require an API key. Provide models via ArcRuntimeOptions or set OPENAI_API_KEY environment variable.\"\n );\n }\n\n this.models = createModels({ apiKey });\n }\n }\n\n async resume<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(sessionId: string, input: any): Promise<string | void> {\n const resolver = this.resumeResolvers.get(sessionId);\n\n if (resolver) {\n resolver(input);\n this.resumeResolvers.delete(sessionId);\n return;\n }\n\n const stored = this.storage.get(sessionId);\n const storedExecution = stored instanceof Promise ? await stored : stored;\n\n if (storedExecution) {\n storedExecution.pendingInput = input;\n\n const storeResult = this.storage.store(sessionId, storedExecution);\n if (storeResult instanceof Promise) {\n await storeResult;\n }\n\n return sessionId;\n }\n\n return sessionId;\n }\n\n async *resumeFromSession<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(sessionId: string, input?: any): AsyncIterable<ArcEvent<State, Context>> {\n if (this.resumeResolvers.has(sessionId)) {\n this.resumeResolvers.delete(sessionId);\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Cleared existing resolver for session ${sessionId} before resuming`,\n timestamp: Date.now(),\n };\n }\n\n const stored = await this.storage.get(sessionId);\n\n if (!stored) {\n yield {\n type: \"arc-error\" as const,\n arcId: \"unknown\",\n error: new Error(`Session ${sessionId} not found or expired`),\n timestamp: Date.now(),\n };\n return;\n }\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Resuming session ${sessionId}, paused at node \"${stored.nodeId}\", arc: \"${stored.arc.id}\", has parent: ${!!stored.parentArc}`,\n timestamp: Date.now(),\n };\n\n const arcState = ArcState.fromSerialized<State, Context>(\n stored.snapshot,\n this.models\n );\n\n const resumeInput = input !== undefined ? input : stored.pendingInput;\n\n if (resumeInput === undefined) {\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: new Error(`No input provided for session ${sessionId}`),\n timestamp: Date.now(),\n };\n return;\n }\n\n const inputValue =\n typeof resumeInput === \"string\"\n ? resumeInput\n : JSON.stringify(resumeInput);\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Setting edge input for node \"${stored.nodeId}\" with value: ${inputValue}`,\n timestamp: Date.now(),\n };\n\n arcState.setEdgeContext(stored.nodeId, inputValue);\n\n try {\n yield* executeArc(\n stored.arc,\n arcState,\n this.resumeResolvers,\n new Set(stored.snapshot.executed),\n this.storage,\n sessionId,\n undefined,\n undefined,\n undefined,\n false\n );\n\n if (stored.parentArc && stored.parentLoopNodeId) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Sub-arc completed, continuing parent arc \"${stored.parentArc.id}\" loop \"${stored.parentLoopNodeId}\"`,\n timestamp: Date.now(),\n };\n\n const parentExecutedNodes = stored.parentExecutedNodes\n ? new Set(stored.parentExecutedNodes)\n : new Set<string>();\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Continuing parent arc with executed nodes: [${Array.from(parentExecutedNodes).join(\", \")}]`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n stored.parentArc,\n arcState,\n this.resumeResolvers,\n parentExecutedNodes,\n this.storage,\n sessionId,\n undefined,\n undefined,\n undefined,\n false\n );\n }\n\n const stillPaused = await this.storage.get(sessionId);\n if (!stillPaused) {\n await this.storage.delete(sessionId);\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: stored.arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${stored.arc.id}\" completed`,\n timestamp: Date.now(),\n };\n }\n } catch (error) {\n await this.storage.delete(sessionId);\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n\n async *run<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(\n arc: Arc<State, Context>,\n state: State,\n sessionId?: string\n ): AsyncIterable<ArcEvent<State, Context>> {\n const arcState = new ArcState<State, Context>(state, this.models);\n const execSessionId = sessionId || this.sessionIdGenerator();\n\n try {\n yield {\n type: \"arc-started\" as const,\n arcId: arc.id,\n initialState: state,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" started`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n arc,\n arcState,\n this.resumeResolvers,\n undefined,\n this.storage,\n execSessionId,\n undefined,\n undefined,\n undefined,\n false\n );\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" completed`,\n timestamp: Date.now(),\n };\n\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n } catch (error) {\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n yield {\n type: \"arc-error\" as const,\n arcId: arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n}\n\nexport class ArcServerlessRuntime extends ArcRuntime {\n async *run<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(\n arc: Arc<State, Context>,\n state: State,\n sessionId?: string\n ): AsyncIterable<ArcEvent<State, Context>> {\n const arcState = new ArcState<State, Context>(state, this.models);\n const execSessionId = sessionId || this.sessionIdGenerator();\n\n try {\n yield {\n type: \"arc-started\" as const,\n arcId: arc.id,\n initialState: state,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" started (serverless mode)`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n arc,\n arcState,\n this.resumeResolvers,\n undefined,\n this.storage,\n execSessionId,\n undefined,\n undefined,\n undefined,\n true\n );\n\n const storedSession = await this.storage.get(execSessionId);\n if (storedSession) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" paused, session stored for resumption`,\n timestamp: Date.now(),\n };\n return;\n }\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${arc.id}\" completed`,\n timestamp: Date.now(),\n };\n\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n } catch (error) {\n if (execSessionId) {\n await this.storage.delete(execSessionId);\n }\n yield {\n type: \"arc-error\" as const,\n arcId: arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n\n async *resumeFromSession<\n State extends Record<string, any>,\n Context extends Record<string, any>,\n >(sessionId: string, input?: any): AsyncIterable<ArcEvent<State, Context>> {\n if (this.resumeResolvers.has(sessionId)) {\n this.resumeResolvers.delete(sessionId);\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Cleared existing resolver for session ${sessionId} before resuming`,\n timestamp: Date.now(),\n };\n }\n\n const stored = await this.storage.get(sessionId);\n\n if (!stored) {\n yield {\n type: \"arc-error\" as const,\n arcId: \"unknown\",\n error: new Error(`Session ${sessionId} not found or expired`),\n timestamp: Date.now(),\n };\n return;\n }\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Resuming session ${sessionId} (serverless mode), paused at node \"${stored.nodeId}\", arc: \"${stored.arc.id}\", has parent: ${!!stored.parentArc}`,\n timestamp: Date.now(),\n };\n\n const arcState = ArcState.fromSerialized<State, Context>(\n stored.snapshot,\n this.models\n );\n\n const resumeInput = input !== undefined ? input : stored.pendingInput;\n\n if (resumeInput === undefined) {\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: new Error(`No input provided for session ${sessionId}`),\n timestamp: Date.now(),\n };\n return;\n }\n\n const inputValue =\n typeof resumeInput === \"string\"\n ? resumeInput\n : JSON.stringify(resumeInput);\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `[Runtime] Setting edge input for node \"${stored.nodeId}\" with value: ${inputValue}`,\n timestamp: Date.now(),\n };\n\n arcState.setEdgeContext(stored.nodeId, inputValue);\n\n try {\n yield* executeArc(\n stored.arc,\n arcState,\n this.resumeResolvers,\n new Set(stored.snapshot.executed),\n this.storage,\n sessionId,\n undefined,\n undefined,\n undefined,\n true\n );\n\n if (stored.parentArc && stored.parentLoopNodeId) {\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Sub-arc completed, continuing parent arc \"${stored.parentArc.id}\" loop \"${stored.parentLoopNodeId}\"`,\n timestamp: Date.now(),\n };\n\n // Use the stored parent executed set to continue from where we left off\n // This ensures we don't restart the parent arc from the beginning\n const parentExecutedNodes = stored.parentExecutedNodes\n ? new Set(stored.parentExecutedNodes)\n : new Set<string>();\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Continuing parent arc with executed nodes: [${Array.from(parentExecutedNodes).join(\", \")}]`,\n timestamp: Date.now(),\n };\n\n yield* executeArc(\n stored.parentArc,\n arcState,\n this.resumeResolvers,\n parentExecutedNodes,\n this.storage,\n sessionId,\n undefined,\n undefined,\n undefined,\n true\n );\n }\n\n const stillPaused = await this.storage.get(sessionId);\n if (!stillPaused) {\n await this.storage.delete(sessionId);\n\n const finalContext = arcState.getContext().toJS() as Context;\n const finalState = arcState.getState().toJS() as State;\n\n yield {\n type: \"arc-completed\" as const,\n arcId: stored.arc.id,\n finalState,\n finalContext,\n timestamp: Date.now(),\n };\n\n yield {\n type: \"log\" as const,\n level: \"info\" as const,\n message: `Arc \"${stored.arc.id}\" completed`,\n timestamp: Date.now(),\n };\n }\n } catch (error) {\n await this.storage.delete(sessionId);\n yield {\n type: \"arc-error\" as const,\n arcId: stored.arc.id,\n error: error instanceof Error ? error : new Error(String(error)),\n timestamp: Date.now(),\n };\n }\n }\n}\n"],"names":[],"mappings":";;;AAQO,gBAAgB,OAAO,CAI5B,IAA6B,EAC7B,QAAkC,EAAA;AAElC,IAAA,MAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,EAAE;AAC/C,IAA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uB,OAAO,CAC5B,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAEnC,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,EAC7B,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,GACjC,aAAa,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAkCzC"}
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EAGR,QAAQ,EACT,MAAM,eAAe,CAAC;AAEvB,wBAAuB,OAAO,CAC5B,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAEnC,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,EAC7B,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,GACjC,aAAa,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAmCzC"}
import { ArcRuntime as ArcRuntimeType, Arc, ArcEvent } from "@arc-dev/core";
import { Storage } from "./types/storage";
import { Storage } from "@arc-dev/storage";
import { Models } from "@arc-dev/model";
export interface ArcRuntimeOptions {
storage?: Storage;
models?: Models;
}
export declare class ArcRuntime implements ArcRuntimeType {
private resumeResolvers;
private storage;
private sessionIdGenerator;
protected resumeResolvers: Map<string, (value: any) => void>;
protected storage: Storage;
protected sessionIdGenerator: () => string;
protected models: Models;
constructor(options?: ArcRuntimeOptions);

@@ -15,2 +18,6 @@ resume<State extends Record<string, any>, Context extends Record<string, any>>(sessionId: string, input: any): Promise<string | void>;

}
export declare class ArcServerlessRuntime extends ArcRuntime {
run<State extends Record<string, any>, Context extends Record<string, any>>(arc: Arc<State, Context>, state: State, sessionId?: string): AsyncIterable<ArcEvent<State, Context>>;
resumeFromSession<State extends Record<string, any>, Context extends Record<string, any>>(sessionId: string, input?: any): AsyncIterable<ArcEvent<State, Context>>;
}
//# sourceMappingURL=runtime.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,IAAI,cAAc,EAC5B,GAAG,EAEH,QAAQ,EACT,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,UAAW,YAAW,cAAc;IAC/C,OAAO,CAAC,eAAe,CAAgD;IACvE,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,kBAAkB,CAAe;gBAE7B,OAAO,CAAC,EAAE,iBAAiB;IAMjC,MAAM,CACV,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA0BjD,iBAAiB,CACtB,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,aAAa,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IA4InE,GAAG,CACR,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAEnC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,EACxB,KAA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C;IA6InE,GAAG,CACR,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAEnC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,EACxB,KAAK,EAAE,KAAK,EACZ,SAAS,CAAC,EAAE,MAAM,GACjB,aAAa,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;CAiE3C;AAED,qBAAa,oBAAqB,SAAQ,UAAU;IAC3C,GAAG,CACR,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAEnC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,EACxB,KAAK,EAAE,KAAK,EACZ,SAAS,CAAC,EAAE,MAAM,GACjB,aAAa,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IA6EnC,iBAAiB,CACtB,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,aAAa,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;CA8I3E"}

@@ -1,3 +0,2 @@

export * from "./storage";
export type { ArcEvent } from "@arc-dev/core";
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
{
"name": "@arc-dev/runtime",
"version": "0.0.2-alpha.6",
"version": "0.0.2-alpha.7",
"description": "Single process runtime implementation for ARC",

@@ -28,4 +28,5 @@ "license": "Apache-2.0",

"pino-pretty": "^13.1.2",
"@arc-dev/core": "0.0.2-alpha.6",
"@arc-dev/models": "0.0.2-alpha.5"
"@arc-dev/core": "0.0.2-alpha.7",
"@arc-dev/model": "0.0.2-alpha.6",
"@arc-dev/storage": "0.0.2-alpha.0"
},

@@ -32,0 +33,0 @@ "devDependencies": {

import { Storage, StoredExecution } from "..";
export declare class InMemoryStorage implements Storage {
private executions;
store(sessionId: string, execution: StoredExecution): void;
get(sessionId: string): StoredExecution | null;
delete(sessionId: string): void;
}
//# sourceMappingURL=in-memory.d.ts.map
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../src/storage/in-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAE9C,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,UAAU,CAA2C;IAE7D,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,GAAG,IAAI;IAI1D,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IAI9C,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAGhC"}
export * from "./in-memory";
//# sourceMappingURL=index.d.ts.map
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
import { Arc } from "@arc-dev/core";
export interface Snapshot {
executed: string[];
state: any;
nodeContext?: any;
edgeContext?: Record<string, any>;
}
export interface StoredExecution {
arc: Arc<any, any>;
snapshot: Snapshot;
nodeId: string;
pendingInput?: any;
parentArc?: Arc<any, any>;
parentLoopNodeId?: string;
parentExecuted?: string[];
}
export interface Storage {
store(sessionId: string, execution: StoredExecution): Promise<void> | void;
get(sessionId: string): Promise<StoredExecution | null> | StoredExecution | null;
delete(sessionId: string): Promise<void> | void;
}
//# sourceMappingURL=storage.d.ts.map
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/types/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,SAAS,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAE3E,GAAG,CACD,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC;IAE5D,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACjD"}