@deepstrike/wasm 0.2.27 → 0.2.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/runtime/facade.d.ts +35 -0
- package/dist/runtime/facade.js +41 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/runner.d.ts +19 -1
- package/dist/runtime/runner.js +110 -67
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { RuntimeRunner, collectText, InMemorySessionLog, LocalExecutionPlane, DEFAULT_NATIVE_ATTENTION_POLICY, DEFAULT_NATIVE_GOVERNANCE_POLICY, DEFAULT_SANDBOX_POLICY, assertNativeProfile, osProfile, validateDeclarativePolicy, ReplayProvider, extractRecordedMessages, judge, buildEvalMessages, parseVerdict, verdictOutputSchema, } from "./runtime/index.js";
|
|
1
|
+
export { RuntimeRunner, collectText, runAgent, runFanout, InMemorySessionLog, LocalExecutionPlane, DEFAULT_NATIVE_ATTENTION_POLICY, DEFAULT_NATIVE_GOVERNANCE_POLICY, DEFAULT_SANDBOX_POLICY, assertNativeProfile, osProfile, validateDeclarativePolicy, ReplayProvider, extractRecordedMessages, judge, buildEvalMessages, parseVerdict, verdictOutputSchema, } from "./runtime/index.js";
|
|
2
2
|
export type { ReplayProviderOpts, Criterion, Verdict, VerdictDetail, JudgeArgs, } from "./runtime/index.js";
|
|
3
3
|
export type { NativeOsProfile, OsProfileId, MemoryPolicy, MemoryWriteRateLimit, ResourceQuota, RuntimeOptions, SchedulerBudget, SessionEvent, SessionLog, RunContext, ExecutionPlane, } from "./runtime/index.js";
|
|
4
4
|
export { FilteredExecutionPlane } from "./runtime/filtered-plane.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { RuntimeRunner, collectText, InMemorySessionLog, LocalExecutionPlane, DEFAULT_NATIVE_ATTENTION_POLICY, DEFAULT_NATIVE_GOVERNANCE_POLICY, DEFAULT_SANDBOX_POLICY, assertNativeProfile, osProfile, validateDeclarativePolicy, ReplayProvider, extractRecordedMessages, judge, buildEvalMessages, parseVerdict, verdictOutputSchema, } from "./runtime/index.js";
|
|
1
|
+
export { RuntimeRunner, collectText, runAgent, runFanout, InMemorySessionLog, LocalExecutionPlane, DEFAULT_NATIVE_ATTENTION_POLICY, DEFAULT_NATIVE_GOVERNANCE_POLICY, DEFAULT_SANDBOX_POLICY, assertNativeProfile, osProfile, validateDeclarativePolicy, ReplayProvider, extractRecordedMessages, judge, buildEvalMessages, parseVerdict, verdictOutputSchema, } from "./runtime/index.js";
|
|
2
2
|
export { FilteredExecutionPlane } from "./runtime/filtered-plane.js";
|
|
3
3
|
export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "./runtime/sub-agent-orchestrator.js";
|
|
4
4
|
export { workflowSpecToKernel, workflowNodeSpecToKernel, submitWorkflowNodesToKernel, submitWorkflowToKernel, submitWorkflowNodesTool, startWorkflowTool, fanoutSynthesize, generateAndFilter, verifyRules } from "./runtime/types/agent.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ExecutionPlane } from "./execution-plane.js";
|
|
2
|
+
import type { SessionLog } from "./session-log.js";
|
|
3
|
+
import type { LLMProvider } from "../types.js";
|
|
4
|
+
import type { RegisteredTool } from "../tools/index.js";
|
|
5
|
+
import type { WorkflowTaskSpec, KernelAgentRole } from "./types/agent.js";
|
|
6
|
+
export interface RunAgentOptions {
|
|
7
|
+
provider: LLMProvider;
|
|
8
|
+
goal: string;
|
|
9
|
+
systemPrompt?: string;
|
|
10
|
+
tools?: RegisteredTool[];
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
maxTokens?: number;
|
|
13
|
+
maxTurns?: number;
|
|
14
|
+
sessionLog?: SessionLog;
|
|
15
|
+
executionPlane?: ExecutionPlane;
|
|
16
|
+
}
|
|
17
|
+
/** Run a single agent to completion and return its final text. */
|
|
18
|
+
export declare function runAgent(opts: RunAgentOptions): Promise<string>;
|
|
19
|
+
export interface RunFanoutOptions {
|
|
20
|
+
provider: LLMProvider;
|
|
21
|
+
tasks: WorkflowTaskSpec[];
|
|
22
|
+
synthesize: string;
|
|
23
|
+
workerRole?: KernelAgentRole;
|
|
24
|
+
synthesisRole?: KernelAgentRole;
|
|
25
|
+
sessionId?: string;
|
|
26
|
+
maxTokens?: number;
|
|
27
|
+
maxTurns?: number;
|
|
28
|
+
sessionLog?: SessionLog;
|
|
29
|
+
executionPlane?: ExecutionPlane;
|
|
30
|
+
}
|
|
31
|
+
/** Parallel fan-out → synthesize over the kernel-gated DAG (standalone runWorkflow). */
|
|
32
|
+
export declare function runFanout(opts: RunFanoutOptions): Promise<{
|
|
33
|
+
synthesis: string;
|
|
34
|
+
outputs: Record<string, string>;
|
|
35
|
+
}>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// High-level facades (parity with the Node SDK's runAgent/runFanout) so the common cases don't require
|
|
2
|
+
// assembling RuntimeRunner + session log + execution plane + collectText by hand. Browser/edge-friendly.
|
|
3
|
+
import { RuntimeRunner, collectText } from "./runner.js";
|
|
4
|
+
import { LocalExecutionPlane } from "./execution-plane.js";
|
|
5
|
+
import { InMemorySessionLog } from "./session-log.js";
|
|
6
|
+
/** Run a single agent to completion and return its final text. */
|
|
7
|
+
export async function runAgent(opts) {
|
|
8
|
+
const plane = opts.executionPlane ??
|
|
9
|
+
(opts.tools ?? []).reduce((p, t) => p.register(t), new LocalExecutionPlane());
|
|
10
|
+
const runner = new RuntimeRunner({
|
|
11
|
+
provider: opts.provider,
|
|
12
|
+
executionPlane: plane,
|
|
13
|
+
sessionLog: opts.sessionLog ?? new InMemorySessionLog(),
|
|
14
|
+
maxTokens: opts.maxTokens ?? 32_000,
|
|
15
|
+
...(opts.maxTurns !== undefined ? { maxTurns: opts.maxTurns } : {}),
|
|
16
|
+
...(opts.systemPrompt !== undefined ? { systemPrompt: opts.systemPrompt } : {}),
|
|
17
|
+
});
|
|
18
|
+
return collectText(runner.run({ sessionId: opts.sessionId ?? `agent-${crypto.randomUUID()}`, goal: opts.goal }));
|
|
19
|
+
}
|
|
20
|
+
/** Parallel fan-out → synthesize over the kernel-gated DAG (standalone runWorkflow). */
|
|
21
|
+
export async function runFanout(opts) {
|
|
22
|
+
const runner = new RuntimeRunner({
|
|
23
|
+
provider: opts.provider,
|
|
24
|
+
executionPlane: opts.executionPlane ?? new LocalExecutionPlane(),
|
|
25
|
+
sessionLog: opts.sessionLog ?? new InMemorySessionLog(),
|
|
26
|
+
maxTokens: opts.maxTokens ?? 32_000,
|
|
27
|
+
...(opts.maxTurns !== undefined ? { maxTurns: opts.maxTurns } : {}),
|
|
28
|
+
});
|
|
29
|
+
const workerRole = opts.workerRole ?? "explore";
|
|
30
|
+
const spec = {
|
|
31
|
+
nodes: [
|
|
32
|
+
...opts.tasks.map(task => ({ task, role: workerRole })),
|
|
33
|
+
{ task: opts.synthesize, role: opts.synthesisRole ?? "plan", dependsOn: opts.tasks.map((_, i) => i) },
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
const outcome = await runner.runWorkflow(spec, opts.sessionId ? { sessionId: opts.sessionId } : undefined);
|
|
37
|
+
const synthesisId = `wf-node${opts.tasks.length}`;
|
|
38
|
+
const lastCompleted = outcome.completed[outcome.completed.length - 1];
|
|
39
|
+
const synthesis = outcome.outputs[synthesisId] ?? (lastCompleted ? outcome.outputs[lastCompleted] : undefined) ?? "";
|
|
40
|
+
return { synthesis, outputs: outcome.outputs };
|
|
41
|
+
}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export type { RunContext, ExecutionPlane } from "./execution-plane.js";
|
|
|
4
4
|
export { LocalExecutionPlane } from "./execution-plane.js";
|
|
5
5
|
export type { MemoryPolicy, MemoryWriteRateLimit, ResourceQuota, RuntimeOptions, SchedulerBudget } from "./runner.js";
|
|
6
6
|
export { RuntimeRunner, collectText } from "./runner.js";
|
|
7
|
+
export { runAgent, runFanout } from "./facade.js";
|
|
8
|
+
export type { RunAgentOptions, RunFanoutOptions } from "./facade.js";
|
|
7
9
|
export { builtinReducers, resolveReducer } from "./reducers.js";
|
|
8
10
|
export type { Reducer, ReducerRegistry, ReducerInput } from "./reducers.js";
|
|
9
11
|
export { getKernel } from "./kernel.js";
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { InMemorySessionLog } from "./session-log.js";
|
|
2
2
|
export { LocalExecutionPlane } from "./execution-plane.js";
|
|
3
3
|
export { RuntimeRunner, collectText } from "./runner.js";
|
|
4
|
+
export { runAgent, runFanout } from "./facade.js";
|
|
4
5
|
export { builtinReducers, resolveReducer } from "./reducers.js";
|
|
5
6
|
export { getKernel } from "./kernel.js";
|
|
6
7
|
export { ReplayProvider } from "./replay-provider.js";
|
package/dist/runtime/runner.d.ts
CHANGED
|
@@ -186,9 +186,25 @@ export declare class RuntimeRunner {
|
|
|
186
186
|
* through the syscall trap; this driver runs each kernel-emitted batch of nodes in parallel,
|
|
187
187
|
* feeds their results back, and loops until the kernel reports the workflow complete.
|
|
188
188
|
*/
|
|
189
|
+
/**
|
|
190
|
+
* Lower the declarative governance / attention / scheduler-budget / resource-quota / memory policies
|
|
191
|
+
* into a freshly-created kernel. Shared by `execute()` (full run) and `bootstrapWorkflowKernel()`
|
|
192
|
+
* (standalone workflow) so a DAG's node spawns are gated and quota'd exactly as a mid-run spawn.
|
|
193
|
+
* Must run BEFORE `start_run`. No config ⇒ native-profile defaults.
|
|
194
|
+
*/
|
|
195
|
+
private applyKernelPolicies;
|
|
196
|
+
/**
|
|
197
|
+
* Bootstrap a standalone kernel for a host-driven workflow with no active parent run — the path a
|
|
198
|
+
* stateless handler (browser/edge worker) takes when it calls `runWorkflow(spec)` directly. Mirrors
|
|
199
|
+
* `execute()`'s pre-run setup (policies via `applyKernelPolicies`, then `start_run`) and records a
|
|
200
|
+
* best-effort `run_started` so the run is resumable. `runWorkflow` tears the kernel down afterward.
|
|
201
|
+
*/
|
|
202
|
+
private bootstrapWorkflowKernel;
|
|
189
203
|
runWorkflow(spec: WorkflowSpec, opts?: {
|
|
190
204
|
resumedCompleted?: string[];
|
|
191
205
|
resumedSubmissions?: Record<string, unknown>[][];
|
|
206
|
+
/** Standalone session id when bootstrapping (no active parent run). Defaults to a fresh uuid. */
|
|
207
|
+
sessionId?: string;
|
|
192
208
|
}): Promise<{
|
|
193
209
|
completed: string[];
|
|
194
210
|
failed: string[];
|
|
@@ -233,7 +249,9 @@ export declare class RuntimeRunner {
|
|
|
233
249
|
* Reads the session log, extracts completed workflow node agent_ids, and
|
|
234
250
|
* calls runWorkflow with resumedCompleted so the kernel skips those nodes.
|
|
235
251
|
*/
|
|
236
|
-
resumeWorkflow(spec: WorkflowSpec
|
|
252
|
+
resumeWorkflow(spec: WorkflowSpec, opts?: {
|
|
253
|
+
sessionId?: string;
|
|
254
|
+
}): Promise<{
|
|
237
255
|
completed: string[];
|
|
238
256
|
failed: string[];
|
|
239
257
|
}>;
|
package/dist/runtime/runner.js
CHANGED
|
@@ -385,56 +385,7 @@ export class RuntimeRunner {
|
|
|
385
385
|
: baseSpec;
|
|
386
386
|
startPayload.run_spec = agentRunSpecToKernel(spec);
|
|
387
387
|
}
|
|
388
|
-
|
|
389
|
-
const attentionPolicy = this.opts.attentionPolicy ?? osProfile.attentionPolicy;
|
|
390
|
-
const governancePolicy = this.opts.governancePolicy ?? osProfile.governancePolicy;
|
|
391
|
-
kernelApply(runtime, this.pendingObservations, governancePolicyToKernelEvent(governancePolicy));
|
|
392
|
-
kernelApply(runtime, this.pendingObservations, {
|
|
393
|
-
kind: "set_attention_policy",
|
|
394
|
-
...(attentionPolicy.maxQueueSize !== undefined
|
|
395
|
-
? { max_queue_size: attentionPolicy.maxQueueSize }
|
|
396
|
-
: {}),
|
|
397
|
-
});
|
|
398
|
-
if (this.opts.schedulerBudget) {
|
|
399
|
-
kernelApply(runtime, this.pendingObservations, {
|
|
400
|
-
kind: "set_scheduler_budget",
|
|
401
|
-
...(this.opts.schedulerBudget.maxWallMs !== undefined
|
|
402
|
-
? { max_wall_ms: this.opts.schedulerBudget.maxWallMs }
|
|
403
|
-
: {}),
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
if (this.opts.resourceQuota) {
|
|
407
|
-
const q = this.opts.resourceQuota;
|
|
408
|
-
kernelApply(runtime, this.pendingObservations, {
|
|
409
|
-
kind: "set_resource_quota",
|
|
410
|
-
quota: {
|
|
411
|
-
...(q.maxConcurrentSubagents !== undefined
|
|
412
|
-
? { max_concurrent_subagents: q.maxConcurrentSubagents }
|
|
413
|
-
: {}),
|
|
414
|
-
...(q.maxSpawnDepth !== undefined ? { max_spawn_depth: q.maxSpawnDepth } : {}),
|
|
415
|
-
...(q.memoryWritesPerWindow !== undefined
|
|
416
|
-
? {
|
|
417
|
-
memory_writes_per_window: [
|
|
418
|
-
q.memoryWritesPerWindow.maxWrites,
|
|
419
|
-
q.memoryWritesPerWindow.windowMs,
|
|
420
|
-
],
|
|
421
|
-
}
|
|
422
|
-
: {}),
|
|
423
|
-
},
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
if (this.opts.memoryPolicy) {
|
|
427
|
-
const m = this.opts.memoryPolicy;
|
|
428
|
-
kernelApply(runtime, this.pendingObservations, {
|
|
429
|
-
kind: "set_memory_policy",
|
|
430
|
-
...(m.memoryPath !== undefined ? { memory_path: m.memoryPath } : {}),
|
|
431
|
-
...(m.staleWarningDays !== undefined ? { stale_warning_days: m.staleWarningDays } : {}),
|
|
432
|
-
...(m.retrievalTopK !== undefined ? { retrieval_top_k: m.retrievalTopK } : {}),
|
|
433
|
-
...(m.validationEnabled !== undefined ? { validation_enabled: m.validationEnabled } : {}),
|
|
434
|
-
...(m.maxContentBytes !== undefined ? { max_content_bytes: m.maxContentBytes } : {}),
|
|
435
|
-
...(m.maxNameLength !== undefined ? { max_name_length: m.maxNameLength } : {}),
|
|
436
|
-
});
|
|
437
|
-
}
|
|
388
|
+
this.applyKernelPolicies(runtime);
|
|
438
389
|
// I4: pre-fetch memory into the knowledge partition before the first LLM turn (mirrors Node).
|
|
439
390
|
if (!resumeMidRun && this.opts.preQueryMemory && this.opts.dreamStore && this.opts.agentId) {
|
|
440
391
|
try {
|
|
@@ -1007,22 +958,112 @@ export class RuntimeRunner {
|
|
|
1007
958
|
* through the syscall trap; this driver runs each kernel-emitted batch of nodes in parallel,
|
|
1008
959
|
* feeds their results back, and loops until the kernel reports the workflow complete.
|
|
1009
960
|
*/
|
|
961
|
+
/**
|
|
962
|
+
* Lower the declarative governance / attention / scheduler-budget / resource-quota / memory policies
|
|
963
|
+
* into a freshly-created kernel. Shared by `execute()` (full run) and `bootstrapWorkflowKernel()`
|
|
964
|
+
* (standalone workflow) so a DAG's node spawns are gated and quota'd exactly as a mid-run spawn.
|
|
965
|
+
* Must run BEFORE `start_run`. No config ⇒ native-profile defaults.
|
|
966
|
+
*/
|
|
967
|
+
applyKernelPolicies(runtime) {
|
|
968
|
+
const osProfile = assertNativeProfile(this.opts.osProfile ?? "native");
|
|
969
|
+
const attentionPolicy = this.opts.attentionPolicy ?? osProfile.attentionPolicy;
|
|
970
|
+
const governancePolicy = this.opts.governancePolicy ?? osProfile.governancePolicy;
|
|
971
|
+
// K2: lower governance / attention / scheduler / quota in ONE `configure_run` event (the 0.2.30
|
|
972
|
+
// core applies each present field via its granular path). `set_memory_policy` stays separate below.
|
|
973
|
+
const { kind: _govKind, ...governance } = governancePolicyToKernelEvent(governancePolicy);
|
|
974
|
+
const config = { governance };
|
|
975
|
+
if (attentionPolicy.maxQueueSize !== undefined) {
|
|
976
|
+
config.attention_max_queue_size = attentionPolicy.maxQueueSize;
|
|
977
|
+
}
|
|
978
|
+
if (this.opts.schedulerBudget?.maxWallMs !== undefined) {
|
|
979
|
+
config.scheduler_max_wall_ms = this.opts.schedulerBudget.maxWallMs;
|
|
980
|
+
}
|
|
981
|
+
if (this.opts.resourceQuota) {
|
|
982
|
+
const q = this.opts.resourceQuota;
|
|
983
|
+
config.resource_quota = {
|
|
984
|
+
...(q.maxConcurrentSubagents !== undefined ? { max_concurrent_subagents: q.maxConcurrentSubagents } : {}),
|
|
985
|
+
...(q.maxSpawnDepth !== undefined ? { max_spawn_depth: q.maxSpawnDepth } : {}),
|
|
986
|
+
...(q.memoryWritesPerWindow !== undefined
|
|
987
|
+
? { memory_writes_per_window: [q.memoryWritesPerWindow.maxWrites, q.memoryWritesPerWindow.windowMs] }
|
|
988
|
+
: {}),
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
kernelApply(runtime, this.pendingObservations, { kind: "configure_run", config });
|
|
992
|
+
if (this.opts.memoryPolicy) {
|
|
993
|
+
const m = this.opts.memoryPolicy;
|
|
994
|
+
kernelApply(runtime, this.pendingObservations, {
|
|
995
|
+
kind: "set_memory_policy",
|
|
996
|
+
...(m.memoryPath !== undefined ? { memory_path: m.memoryPath } : {}),
|
|
997
|
+
...(m.staleWarningDays !== undefined ? { stale_warning_days: m.staleWarningDays } : {}),
|
|
998
|
+
...(m.retrievalTopK !== undefined ? { retrieval_top_k: m.retrievalTopK } : {}),
|
|
999
|
+
...(m.validationEnabled !== undefined ? { validation_enabled: m.validationEnabled } : {}),
|
|
1000
|
+
...(m.maxContentBytes !== undefined ? { max_content_bytes: m.maxContentBytes } : {}),
|
|
1001
|
+
...(m.maxNameLength !== undefined ? { max_name_length: m.maxNameLength } : {}),
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Bootstrap a standalone kernel for a host-driven workflow with no active parent run — the path a
|
|
1007
|
+
* stateless handler (browser/edge worker) takes when it calls `runWorkflow(spec)` directly. Mirrors
|
|
1008
|
+
* `execute()`'s pre-run setup (policies via `applyKernelPolicies`, then `start_run`) and records a
|
|
1009
|
+
* best-effort `run_started` so the run is resumable. `runWorkflow` tears the kernel down afterward.
|
|
1010
|
+
*/
|
|
1011
|
+
async bootstrapWorkflowKernel(sessionId, spec) {
|
|
1012
|
+
this.interrupted = false;
|
|
1013
|
+
this.pendingObservations = [];
|
|
1014
|
+
this.pendingSpoolOutputs.clear();
|
|
1015
|
+
this.currentSessionId = sessionId;
|
|
1016
|
+
const kernel = await getKernel();
|
|
1017
|
+
const runtime = new kernel.KernelRuntime({
|
|
1018
|
+
maxTokens: this.opts.maxTokens,
|
|
1019
|
+
maxTurns: this.opts.maxTurns ?? 25,
|
|
1020
|
+
...(this.opts.maxTotalTokens !== undefined ? { maxTotalTokens: this.opts.maxTotalTokens } : {}),
|
|
1021
|
+
timeoutMs: this.opts.timeoutMs !== undefined ? BigInt(this.opts.timeoutMs) : undefined,
|
|
1022
|
+
});
|
|
1023
|
+
this.activeKernel = runtime;
|
|
1024
|
+
const goal = `workflow:${spec.nodes.length} nodes`;
|
|
1025
|
+
void Promise.resolve(this.opts.sessionLog.append(sessionId, {
|
|
1026
|
+
kind: "run_started",
|
|
1027
|
+
run_id: crypto.randomUUID(),
|
|
1028
|
+
goal,
|
|
1029
|
+
criteria: [],
|
|
1030
|
+
...(this.opts.agentId ? { agent_id: this.opts.agentId } : {}),
|
|
1031
|
+
})).catch(() => { });
|
|
1032
|
+
this.applyKernelPolicies(runtime);
|
|
1033
|
+
// K1: no explicit `start_run` — the host `load_workflow` (fired next by `runWorkflow`) self-bootstraps
|
|
1034
|
+
// the run on the 0.2.30 core, matching the agent-reachable `submit_workflow` path.
|
|
1035
|
+
void goal;
|
|
1036
|
+
return runtime;
|
|
1037
|
+
}
|
|
1010
1038
|
async runWorkflow(spec, opts) {
|
|
1011
|
-
|
|
1012
|
-
|
|
1039
|
+
// Standalone entry: with no active parent run, auto-bootstrap a kernel that owns the DAG (same
|
|
1040
|
+
// governance/quota policies a full run gets), drive it, then tear it down so the runner is reusable.
|
|
1041
|
+
// Mid-run callers keep the original in-place behavior with no teardown.
|
|
1042
|
+
const bootstrapped = !this.activeKernel || !this.currentSessionId;
|
|
1043
|
+
if (bootstrapped) {
|
|
1044
|
+
await this.bootstrapWorkflowKernel(opts?.sessionId ?? `wf-${crypto.randomUUID()}`, spec);
|
|
1013
1045
|
}
|
|
1014
1046
|
const parentSessionId = this.currentSessionId;
|
|
1015
1047
|
const runtime = this.activeKernel;
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1048
|
+
try {
|
|
1049
|
+
const observations = kernelApply(runtime, this.pendingObservations, {
|
|
1050
|
+
kind: "load_workflow",
|
|
1051
|
+
spec: workflowSpecToKernel(spec),
|
|
1052
|
+
parent_session_id: parentSessionId,
|
|
1053
|
+
// W0-ABI resume: skip nodes already completed before an interruption.
|
|
1054
|
+
...(opts?.resumedCompleted && opts.resumedCompleted.length ? { resumed_completed: opts.resumedCompleted } : {}),
|
|
1055
|
+
// R3-1: re-apply recorded runtime submissions so dynamically-appended nodes are reconstructed.
|
|
1056
|
+
...(opts?.resumedSubmissions && opts.resumedSubmissions.length ? { resumed_submissions: opts.resumedSubmissions } : {}),
|
|
1057
|
+
});
|
|
1058
|
+
return await this.driveWorkflow(observations, parentSessionId, runtime);
|
|
1059
|
+
}
|
|
1060
|
+
finally {
|
|
1061
|
+
if (bootstrapped) {
|
|
1062
|
+
this.activeKernel = null;
|
|
1063
|
+
this.currentSessionId = null;
|
|
1064
|
+
this.pendingObservations = [];
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1026
1067
|
}
|
|
1027
1068
|
/**
|
|
1028
1069
|
* M5/G1: bootstrap an **agent-authored** workflow ("the model writes its own harness"). Routes the
|
|
@@ -1169,14 +1210,16 @@ export class RuntimeRunner {
|
|
|
1169
1210
|
* Reads the session log, extracts completed workflow node agent_ids, and
|
|
1170
1211
|
* calls runWorkflow with resumedCompleted so the kernel skips those nodes.
|
|
1171
1212
|
*/
|
|
1172
|
-
async resumeWorkflow(spec) {
|
|
1173
|
-
|
|
1174
|
-
|
|
1213
|
+
async resumeWorkflow(spec, opts) {
|
|
1214
|
+
// Standalone resume: a stateless handler passes the prior `sessionId`; mid-run callers omit it.
|
|
1215
|
+
const sessionId = opts?.sessionId ?? this.currentSessionId;
|
|
1216
|
+
if (!sessionId) {
|
|
1217
|
+
throw new Error("resumeWorkflow requires an active parent run or an explicit sessionId");
|
|
1175
1218
|
}
|
|
1176
|
-
const events = await this.opts.sessionLog.read(
|
|
1219
|
+
const events = await this.opts.sessionLog.read(sessionId);
|
|
1177
1220
|
const resumedCompleted = recoverCompletedWorkflowNodes(events);
|
|
1178
1221
|
const resumedSubmissions = recoverSubmittedWorkflowNodes(events);
|
|
1179
|
-
return this.runWorkflow(spec, { resumedCompleted, resumedSubmissions });
|
|
1222
|
+
return this.runWorkflow(spec, { resumedCompleted, resumedSubmissions, sessionId });
|
|
1180
1223
|
}
|
|
1181
1224
|
async appendObservations(sessionId, runtime, nextArchiveStart) {
|
|
1182
1225
|
const turn = runtime.turn();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepstrike/wasm",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.30",
|
|
4
4
|
"description": "DeepStrike WASM SDK — browser, Cloudflare Workers, Deno Deploy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"test": "node --experimental-vm-modules node_modules/.bin/jest"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@deepstrike/wasm-kernel": "0.2.
|
|
18
|
+
"@deepstrike/wasm-kernel": "0.2.30"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/jest": "^30.0.0",
|