depa-actor 0.1.2 → 0.2.1

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.
Files changed (96) hide show
  1. package/dist/addressing.d.ts +100 -0
  2. package/dist/addressing.d.ts.map +1 -0
  3. package/dist/addressing.js +409 -0
  4. package/dist/addressing.js.map +1 -0
  5. package/dist/core/ActorSystem.d.ts +1 -1
  6. package/dist/core/ActorSystem.d.ts.map +1 -1
  7. package/dist/dispatch/ActorDispatchAdapter.d.ts +75 -18
  8. package/dist/dispatch/ActorDispatchAdapter.d.ts.map +1 -1
  9. package/dist/dispatch/ActorDispatchAdapter.js +109 -24
  10. package/dist/dispatch/ActorDispatchAdapter.js.map +1 -1
  11. package/dist/execution/commandDeque.d.ts +121 -0
  12. package/dist/execution/commandDeque.d.ts.map +1 -0
  13. package/dist/execution/commandDeque.js +415 -0
  14. package/dist/execution/commandDeque.js.map +1 -0
  15. package/dist/execution/dispatcher.d.ts +72 -0
  16. package/dist/execution/dispatcher.d.ts.map +1 -0
  17. package/dist/execution/dispatcher.js +77 -0
  18. package/dist/execution/dispatcher.js.map +1 -0
  19. package/dist/execution/index.d.ts +7 -0
  20. package/dist/execution/index.d.ts.map +1 -0
  21. package/dist/execution/index.js +4 -0
  22. package/dist/execution/index.js.map +1 -0
  23. package/dist/execution/stack.d.ts +24 -0
  24. package/dist/execution/stack.d.ts.map +1 -0
  25. package/dist/execution/stack.js +84 -0
  26. package/dist/execution/stack.js.map +1 -0
  27. package/dist/index.d.ts +21 -15
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +15 -8
  30. package/dist/index.js.map +1 -1
  31. package/dist/orchestration/index.d.ts +8 -8
  32. package/dist/orchestration/index.d.ts.map +1 -1
  33. package/dist/orchestration/index.js +6 -6
  34. package/dist/orchestration/index.js.map +1 -1
  35. package/dist/orchestration/presets/aiAgent.d.ts +2 -2
  36. package/dist/orchestration/presets/aiAgent.d.ts.map +1 -1
  37. package/dist/orchestration/recovery.d.ts +2 -2
  38. package/dist/orchestration/recovery.d.ts.map +1 -1
  39. package/dist/orchestration/reducer.d.ts +2 -2
  40. package/dist/orchestration/reducer.d.ts.map +1 -1
  41. package/dist/orchestration/reducer.js +2 -2
  42. package/dist/orchestration/reducer.js.map +1 -1
  43. package/dist/orchestration/runtimeAdapter.d.ts +3 -3
  44. package/dist/orchestration/runtimeAdapter.d.ts.map +1 -1
  45. package/dist/orchestration/scheduler.d.ts +2 -2
  46. package/dist/orchestration/scheduler.d.ts.map +1 -1
  47. package/dist/orchestration/types.d.ts +1 -1
  48. package/dist/orchestration/types.d.ts.map +1 -1
  49. package/dist/pipeline/ActorPipeline.d.ts +36 -9
  50. package/dist/pipeline/ActorPipeline.d.ts.map +1 -1
  51. package/dist/pipeline/ActorPipeline.js +26 -16
  52. package/dist/pipeline/ActorPipeline.js.map +1 -1
  53. package/dist/runtime/ActorRuntime.d.ts +2 -2
  54. package/dist/runtime/ActorRuntime.d.ts.map +1 -1
  55. package/dist/runtime/ActorRuntime.js +1 -1
  56. package/dist/runtime/ActorRuntime.js.map +1 -1
  57. package/dist-cjs/addressing.cjs +424 -0
  58. package/dist-cjs/core/ActorSystem.cjs +172 -0
  59. package/dist-cjs/core/types.cjs +10 -0
  60. package/dist-cjs/dispatch/ActorDispatchAdapter.cjs +125 -0
  61. package/dist-cjs/execution/commandDeque.cjs +430 -0
  62. package/dist-cjs/execution/dispatcher.cjs +79 -0
  63. package/dist-cjs/execution/index.cjs +24 -0
  64. package/dist-cjs/execution/stack.cjs +88 -0
  65. package/dist-cjs/index.cjs +77 -0
  66. package/dist-cjs/orchestration/index.cjs +19 -0
  67. package/dist-cjs/orchestration/presets/aiAgent.cjs +40 -0
  68. package/dist-cjs/orchestration/recovery.cjs +112 -0
  69. package/dist-cjs/orchestration/reducer.cjs +276 -0
  70. package/dist-cjs/orchestration/runtimeAdapter.cjs +14 -0
  71. package/dist-cjs/orchestration/scheduler.cjs +86 -0
  72. package/dist-cjs/orchestration/types.cjs +14 -0
  73. package/dist-cjs/package.json +3 -0
  74. package/dist-cjs/pipeline/ActorPipeline.cjs +44 -0
  75. package/dist-cjs/runtime/ActorRuntime.cjs +77 -0
  76. package/dist-cjs/runtime/completion.cjs +75 -0
  77. package/dist-cjs/runtime/indexing.cjs +34 -0
  78. package/dist-cjs/runtime/snapshot.cjs +14 -0
  79. package/package.json +9 -4
  80. package/src/addressing.ts +756 -0
  81. package/src/core/ActorSystem.ts +1 -1
  82. package/src/dispatch/ActorDispatchAdapter.ts +219 -48
  83. package/src/execution/commandDeque.ts +656 -0
  84. package/src/execution/dispatcher.ts +188 -0
  85. package/src/execution/index.ts +58 -0
  86. package/src/execution/stack.ts +130 -0
  87. package/src/index.ts +121 -16
  88. package/src/orchestration/index.ts +8 -8
  89. package/src/orchestration/presets/aiAgent.ts +2 -2
  90. package/src/orchestration/recovery.ts +2 -2
  91. package/src/orchestration/reducer.ts +3 -3
  92. package/src/orchestration/runtimeAdapter.ts +3 -3
  93. package/src/orchestration/scheduler.ts +2 -2
  94. package/src/orchestration/types.ts +1 -1
  95. package/src/pipeline/ActorPipeline.ts +104 -58
  96. package/src/runtime/ActorRuntime.ts +2 -2
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeEffectivePriority = computeEffectivePriority;
4
+ exports.selectNextFiberId = selectNextFiberId;
5
+ exports.scheduleOne = scheduleOne;
6
+ function isSchedulable(fiber) {
7
+ return fiber.status === 'ready';
8
+ }
9
+ function computeEffectivePriority(fiber, agingStep) {
10
+ return fiber.basePriority - fiber.age * Math.max(0, agingStep);
11
+ }
12
+ function selectNextFiberId(state, now) {
13
+ const hooks = state.options.schedulerHooks;
14
+ const selectionNow = typeof now === 'number' ? now : Date.now();
15
+ let candidates = Object.values(state.fibers).filter(isSchedulable);
16
+ if (hooks?.filterCandidates) {
17
+ candidates = hooks.filterCandidates({ state, candidates, now: selectionNow });
18
+ }
19
+ else if (hooks?.filterCandidate) {
20
+ const f = hooks.filterCandidate;
21
+ candidates = candidates.filter(fiber => f({ state, fiber, now: selectionNow }));
22
+ }
23
+ if (candidates.length === 0) {
24
+ return undefined;
25
+ }
26
+ const agingStep = state.options.agingStep;
27
+ candidates.sort((a, b) => {
28
+ const pa = computeEffectivePriority(a, agingStep);
29
+ const pb = computeEffectivePriority(b, agingStep);
30
+ if (pa !== pb) {
31
+ return pa - pb;
32
+ }
33
+ return a.order - b.order;
34
+ });
35
+ return candidates[0]?.id;
36
+ }
37
+ function scheduleOne(state, now) {
38
+ const selectedFiberId = selectNextFiberId(state, now);
39
+ if (!selectedFiberId) {
40
+ return { state, effects: [] };
41
+ }
42
+ const selected = state.fibers[selectedFiberId];
43
+ if (!selected) {
44
+ return { state, effects: [] };
45
+ }
46
+ const timeoutMs = selected.timeoutMs ?? state.options.defaultTimeoutMs;
47
+ const timeoutAt = state.options.timeoutEnabled && timeoutMs > 0 ? now + timeoutMs : undefined;
48
+ const nextFibers = { ...state.fibers };
49
+ for (const [id, fiber] of Object.entries(state.fibers)) {
50
+ if (id === selectedFiberId) {
51
+ nextFibers[id] = {
52
+ ...fiber,
53
+ status: 'running',
54
+ age: 0,
55
+ timeoutAt,
56
+ updatedAt: now,
57
+ };
58
+ continue;
59
+ }
60
+ if (fiber.status === 'ready') {
61
+ nextFibers[id] = {
62
+ ...fiber,
63
+ age: fiber.age + Math.max(0, state.options.agingStep),
64
+ updatedAt: now,
65
+ };
66
+ }
67
+ }
68
+ const effects = [];
69
+ const withStep = nextFibers[selectedFiberId];
70
+ if (withStep?.step) {
71
+ effects.push({
72
+ kind: 'send',
73
+ fiberId: selectedFiberId,
74
+ to: withStep.actorId,
75
+ step: withStep.step,
76
+ });
77
+ }
78
+ return {
79
+ state: {
80
+ ...state,
81
+ fibers: nextFibers,
82
+ },
83
+ effects,
84
+ selectedFiberId,
85
+ };
86
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_ORCHESTRATOR_OPTIONS = void 0;
4
+ exports.DEFAULT_ORCHESTRATOR_OPTIONS = {
5
+ senderId: '__fiber_scheduler__',
6
+ agingStep: 1,
7
+ defaultSuspendPolicy: 'continue_others',
8
+ timeoutEnabled: false,
9
+ defaultTimeoutMs: 0,
10
+ retryEnabled: false,
11
+ retryDelayMs: 0,
12
+ retryBackoffMultiplier: 1,
13
+ deadLetterEnabled: false,
14
+ };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * depa-actor — ActorPipeline
4
+ *
5
+ * Adapts the DOP 6-step pipeline to actor context by REUSING the depa-processor
6
+ * `component` primitives (DEPA dimension chain Processor → Actor): the 6-step
7
+ * orchestration is delegated to `runByFuncStyleAdapter`, identity/null seams come
8
+ * from `stdMake*`, and the core-logic seam is `StdInnerLogic` verbatim — this module
9
+ * no longer re-implements a parallel copy of `component/types.ts`.
10
+ *
11
+ * Mapping (outer dimension):
12
+ * OuterRuntime = ActorSelf
13
+ * OuterInput = envelope payload
14
+ * OuterConfig = actor state
15
+ *
16
+ * Step 6 (output) is adapted with `TOuterOutput = void`: actor output is a side
17
+ * effect (write `self.state` / `self.send`), not a returned value. This thinly
18
+ * adapts depa-processor's pure-function `StdOuterOutputAdapter` without leaking
19
+ * actor semantics back into the generic primitive.
20
+ *
21
+ * createPipelineHandler() wraps a pipeline definition into an ActorHandler.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.createPipelineHandler = createPipelineHandler;
25
+ const depa_processor_1 = require("depa-processor");
26
+ // ─── createPipelineHandler ───────────────────────────────────────────
27
+ /**
28
+ * Wrap a pipeline definition into an ActorHandler by delegating the 6-step
29
+ * orchestration to depa-processor `runByFuncStyleAdapter`.
30
+ *
31
+ * Outer dimension: runtime = self, input = payload, config = state.
32
+ * Step 6 produces `void` — `runByFuncStyleAdapter` runs the output adapter for its
33
+ * side effects and the (void) return value is discarded.
34
+ */
35
+ function createPipelineHandler(pipeline) {
36
+ return async (self, envelope) => {
37
+ // `runByFuncStyleAdapter` returns the output adapter's value verbatim (without
38
+ // awaiting it). Capture it and await so an async step-6 side effect (write
39
+ // state / send messages) is fully settled before the handler resolves —
40
+ // preserving the original `await pipeline.output(...)` semantics.
41
+ const outputResult = await (0, depa_processor_1.runByFuncStyleAdapter)(self, envelope.payload, self.state, pipeline.computeDerived, pipeline.innerRuntime, pipeline.innerInput, pipeline.innerConfig, pipeline.coreLogic, pipeline.output);
42
+ await outputResult;
43
+ };
44
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /**
3
+ * depa-actor — ActorRuntime
4
+ *
5
+ * Lifecycle and plugin layer over ActorSystem.
6
+ * ActorSystem = engine, ActorRuntime = managed environment.
7
+ *
8
+ * Future AiAgentVm will hold an ActorRuntime instance.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.ActorRuntime = void 0;
12
+ const ActorSystem_js_1 = require("../core/ActorSystem.cjs");
13
+ // ─── ActorRuntime ────────────────────────────────────────────────────
14
+ class ActorRuntime {
15
+ system;
16
+ plugins = [];
17
+ facets = new Map();
18
+ constructor(getRuntime, plugins) {
19
+ this.plugins = plugins ?? [];
20
+ this.system = new ActorSystem_js_1.ActorSystem(getRuntime, (entry) => this.handleLog(entry));
21
+ }
22
+ // ── Plugin management ──
23
+ addPlugin(plugin) {
24
+ this.plugins.push(plugin);
25
+ }
26
+ hasFacet(name) {
27
+ return this.facets.has(name);
28
+ }
29
+ getFacet(name) {
30
+ return this.facets.get(name);
31
+ }
32
+ setFacet(name, facet) {
33
+ this.facets.set(name, facet);
34
+ return facet;
35
+ }
36
+ ensureFacet(name, create) {
37
+ const existing = this.facets.get(name);
38
+ if (existing !== undefined) {
39
+ return existing;
40
+ }
41
+ const created = create();
42
+ this.facets.set(name, created);
43
+ return created;
44
+ }
45
+ // ── Delegated API (convenience) ──
46
+ register(id, def) {
47
+ this.system.register(id, def);
48
+ for (const p of this.plugins) {
49
+ p.onRegister?.(id, def);
50
+ }
51
+ }
52
+ unregister(id) {
53
+ this.system.unregister(id);
54
+ for (const p of this.plugins) {
55
+ p.onUnregister?.(id);
56
+ }
57
+ }
58
+ sendFrom(from, to, tag, payload) {
59
+ this.system.sendFrom(from, to, tag, payload);
60
+ }
61
+ refFrom(from, to) {
62
+ return this.system.refFrom(from, to);
63
+ }
64
+ ids() {
65
+ return this.system.ids();
66
+ }
67
+ has(id) {
68
+ return this.system.has(id);
69
+ }
70
+ // ── Internal ──
71
+ handleLog(entry) {
72
+ for (const p of this.plugins) {
73
+ p.onLog?.(entry);
74
+ }
75
+ }
76
+ }
77
+ exports.ActorRuntime = ActorRuntime;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CompletionBindingRegistry = exports.CompletionSignalRegistry = void 0;
4
+ exports.createCompletionSignalRegistry = createCompletionSignalRegistry;
5
+ exports.createCompletionBindingRegistry = createCompletionBindingRegistry;
6
+ class CompletionSignalRegistry {
7
+ waiters = new Map();
8
+ subscribe(key, waiter) {
9
+ const current = this.waiters.get(key) ?? new Set();
10
+ current.add(waiter);
11
+ this.waiters.set(key, current);
12
+ return () => {
13
+ const next = this.waiters.get(key);
14
+ if (!next) {
15
+ return;
16
+ }
17
+ next.delete(waiter);
18
+ if (next.size === 0) {
19
+ this.waiters.delete(key);
20
+ }
21
+ };
22
+ }
23
+ resolve(key, result) {
24
+ const waiters = this.waiters.get(key);
25
+ if (!waiters || waiters.size === 0) {
26
+ return;
27
+ }
28
+ this.waiters.delete(key);
29
+ for (const waiter of Array.from(waiters)) {
30
+ waiter(result);
31
+ }
32
+ }
33
+ has(key) {
34
+ return (this.waiters.get(key)?.size ?? 0) > 0;
35
+ }
36
+ count(key) {
37
+ return this.waiters.get(key)?.size ?? 0;
38
+ }
39
+ clear(key) {
40
+ if (key !== undefined) {
41
+ this.waiters.delete(key);
42
+ return;
43
+ }
44
+ this.waiters.clear();
45
+ }
46
+ }
47
+ exports.CompletionSignalRegistry = CompletionSignalRegistry;
48
+ function createCompletionSignalRegistry() {
49
+ return new CompletionSignalRegistry();
50
+ }
51
+ class CompletionBindingRegistry {
52
+ bindings;
53
+ constructor(initial) {
54
+ this.bindings = Object.assign(Object.create(null), initial ?? {});
55
+ }
56
+ get(key) {
57
+ return this.bindings[key];
58
+ }
59
+ set(key, binding) {
60
+ this.bindings[key] = binding;
61
+ }
62
+ delete(key) {
63
+ delete this.bindings[key];
64
+ }
65
+ has(key) {
66
+ return key in this.bindings;
67
+ }
68
+ snapshot() {
69
+ return { ...this.bindings };
70
+ }
71
+ }
72
+ exports.CompletionBindingRegistry = CompletionBindingRegistry;
73
+ function createCompletionBindingRegistry(initial) {
74
+ return new CompletionBindingRegistry(initial);
75
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RuntimeIndexHook = void 0;
4
+ exports.createRuntimeIndexHook = createRuntimeIndexHook;
5
+ class RuntimeIndexHook {
6
+ entries = new Map();
7
+ constructor(initial) {
8
+ for (const [key, value] of Object.entries(initial ?? {})) {
9
+ this.entries.set(key, value);
10
+ }
11
+ }
12
+ get(key) {
13
+ return this.entries.get(key);
14
+ }
15
+ set(key, value) {
16
+ this.entries.set(key, value);
17
+ }
18
+ delete(key) {
19
+ this.entries.delete(key);
20
+ }
21
+ has(key) {
22
+ return this.entries.has(key);
23
+ }
24
+ values() {
25
+ return Array.from(this.entries.values());
26
+ }
27
+ snapshot() {
28
+ return Object.fromEntries(this.entries.entries());
29
+ }
30
+ }
31
+ exports.RuntimeIndexHook = RuntimeIndexHook;
32
+ function createRuntimeIndexHook(initial) {
33
+ return new RuntimeIndexHook(initial);
34
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSnapshotCodec = createSnapshotCodec;
4
+ exports.createRecoveryHooks = createRecoveryHooks;
5
+ exports.createPersistenceEffectPort = createPersistenceEffectPort;
6
+ function createSnapshotCodec(codec) {
7
+ return codec;
8
+ }
9
+ function createRecoveryHooks(hooks) {
10
+ return hooks;
11
+ }
12
+ function createPersistenceEffectPort(port) {
13
+ return port;
14
+ }
package/package.json CHANGED
@@ -1,22 +1,27 @@
1
1
  {
2
2
  "name": "depa-actor",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
- "main": "./dist/index.js",
5
+ "main": "./dist-cjs/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
11
+ "import": "./dist/index.js",
12
+ "require": "./dist-cjs/index.cjs"
12
13
  }
13
14
  },
14
15
  "files": [
15
16
  "dist",
17
+ "dist-cjs",
16
18
  "src"
17
19
  ],
20
+ "dependencies": {
21
+ "depa-processor": "0.1.1"
22
+ },
18
23
  "scripts": {
19
- "build": "tsc",
24
+ "build": "tsc && tsc -p tsconfig.cjs.json && node scripts/build-cjs.mjs",
20
25
  "dev": "tsc --watch",
21
26
  "test": "bun test",
22
27
  "test:watch": "bun test --watch"