posipaki 0.16.2 → 0.17.0

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 (47) hide show
  1. package/dist/hooks-DCXE8xgc.d.ts +129 -0
  2. package/dist/hooks-DCXE8xgc.d.ts.map +1 -0
  3. package/dist/hooks-OcDWhAZK.js +72 -0
  4. package/dist/hooks-OcDWhAZK.js.map +1 -0
  5. package/dist/hooks.d.ts +2 -2
  6. package/dist/hooks.js +2 -2
  7. package/dist/index.d.ts +5 -5
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3 -3
  10. package/dist/pipe.d.ts +4 -2
  11. package/dist/pipe.d.ts.map +1 -1
  12. package/dist/pipe.js.map +1 -1
  13. package/dist/plugins/debug-logger.d.ts +6 -4
  14. package/dist/plugins/debug-logger.d.ts.map +1 -1
  15. package/dist/plugins/debug-logger.js +27 -29
  16. package/dist/plugins/debug-logger.js.map +1 -1
  17. package/dist/plugins/tree-introspection.d.ts +25 -0
  18. package/dist/plugins/tree-introspection.d.ts.map +1 -0
  19. package/dist/plugins/tree-introspection.js +44 -0
  20. package/dist/plugins/tree-introspection.js.map +1 -0
  21. package/dist/{process-Bf9HTr0m.d.ts → process-B7rh_NBl.d.ts} +3 -3
  22. package/dist/{process-Bf9HTr0m.d.ts.map → process-B7rh_NBl.d.ts.map} +1 -1
  23. package/dist/remote/index.d.ts +5 -5
  24. package/dist/remote/index.d.ts.map +1 -1
  25. package/dist/remote/index.js +18 -18
  26. package/dist/remote/index.js.map +1 -1
  27. package/dist/{src-B2jOTwzs.js → src-gcahpgho.js} +101 -210
  28. package/dist/src-gcahpgho.js.map +1 -0
  29. package/dist/supervisor.d.ts +2 -2
  30. package/dist/{types-BLIFntvm.d.ts → types-BUPRp3t_.d.ts} +10 -8
  31. package/dist/types-BUPRp3t_.d.ts.map +1 -0
  32. package/dist/xfetch.d.ts +2 -2
  33. package/package.json +4 -4
  34. package/dist/hooks-Czj67zNB.d.ts +0 -127
  35. package/dist/hooks-Czj67zNB.d.ts.map +0 -1
  36. package/dist/hooks-D5DhD9gu.js +0 -23
  37. package/dist/hooks-D5DhD9gu.js.map +0 -1
  38. package/dist/plugins/rbac.d.ts +0 -10
  39. package/dist/plugins/rbac.d.ts.map +0 -1
  40. package/dist/plugins/rbac.js +0 -21
  41. package/dist/plugins/rbac.js.map +0 -1
  42. package/dist/plugins/timeout-guard.d.ts +0 -10
  43. package/dist/plugins/timeout-guard.d.ts.map +0 -1
  44. package/dist/plugins/timeout-guard.js +0 -24
  45. package/dist/plugins/timeout-guard.js.map +0 -1
  46. package/dist/src-B2jOTwzs.js.map +0 -1
  47. package/dist/types-BLIFntvm.d.ts.map +0 -1
@@ -0,0 +1,129 @@
1
+ import { c as SenderInfo, h as AsyncProcess, i as Message, m as AnyProcess, n as AsyncProcessFn, o as ProcessCtx, r as ExitMessage, t as AnyProcessCtx } from "./types-BUPRp3t_.js";
2
+
3
+ //#region src/actor-types.d.ts
4
+ type ActorMessages<M extends Message> = {
5
+ __tag_messages: M;
6
+ };
7
+ interface MethodOptions {
8
+ [key: string]: Function;
9
+ }
10
+ type HandlerFn<InMsg extends Message> = (msg: InMsg, sender: SenderInfo) => void | Promise<void>;
11
+ type HandlerOptions<InMsg extends Message> = Omit<{ [K in InMsg["type"]]: HandlerFn<Extract<InMsg, {
12
+ type: K;
13
+ }>> }, "STOP">;
14
+ interface ReflectionOptions {}
15
+ type Paired<Priv, Pub> = {
16
+ public: Pub;
17
+ private: Priv;
18
+ };
19
+ type HidePrivate<T> = T extends Paired<unknown, unknown> ? T["public"] : T;
20
+ interface ActorDefinition<Args, InternalState, InMsg extends Message, OutMsg extends Message, ReflectionMethods extends ReflectionOptions> {
21
+ fn: AsyncProcessFn<Args, HidePrivate<InternalState>, InMsg, OutMsg>;
22
+ /** Preferred process name (from config.name). */
23
+ name?: string;
24
+ /** Raw plugin config (array or transform). Resolved at fork time. @internal */
25
+ pvtPluginsRaw?: ActorPlugin[] | PluginTransform;
26
+ /** Spawn this actor as a standalone process. */
27
+ spawn(args: Args): Promise<AsyncProcess<Args, HidePrivate<InternalState>, InMsg, OutMsg, ReflectionMethods & ActorReflection>>;
28
+ /** Spawn this actor as a child of the calling process. */
29
+ spawnAsChild(ctx: AnyProcessCtx, args: Args, name?: string, parentPlugins?: ActorPlugin[]): Promise<AsyncProcess<Args, HidePrivate<InternalState>, InMsg, OutMsg, ReflectionMethods & ActorReflection>>;
30
+ inMessages: ActorMessages<InMsg> | undefined;
31
+ outMessages: ActorMessages<OutMsg> | undefined;
32
+ }
33
+ type ActorConfig<Args, InternalState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>, ReflectionMethods extends ReflectionOptions> = ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers, ReflectionMethods & ActorReflection>> & {
34
+ /** Preferred process name. Used by ctx.fork() when no explicit name is given. */name?: string;
35
+ plugins?: ActorPlugin[] | PluginTransform;
36
+ outMessages?: ActorMessages<OutMsg>;
37
+ inMessages?: ActorMessages<InMsg>;
38
+ setup?: (this: ActorContext<Args, never, InMsg, OutMsg, Methods, Handlers, ReflectionMethods & ActorReflection>, args: Args) => Promise<InternalState> | InternalState;
39
+ afterStart?: () => void | Promise<void>;
40
+ onStopRequested?: () => HookResult | Promise<HookResult>;
41
+ onEnd?: (reason?: unknown) => HookResult | Promise<HookResult>;
42
+ onError?: (error?: unknown) => HookResult | Promise<HookResult>;
43
+ onEmit?: (msg: OutMsg, sender: SenderInfo) => HookResult | Promise<HookResult>;
44
+ onMessage?: (msg: InMsg, sender: SenderInfo) => HookResult | Promise<HookResult>;
45
+ onUnhandled?: (msg: Message, sender: SenderInfo) => void | Promise<void>;
46
+ onChildExit?: (name: string, reason: ExitMessage) => HookResult | Promise<HookResult>;
47
+ handlers: Handlers & ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers, ReflectionMethods & ActorReflection>>;
48
+ methods?: Methods & ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers, ReflectionMethods & ActorReflection>>;
49
+ $reflectionMethods?: ReflectionMethods & ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers, ActorReflection & ActorReflection>>;
50
+ $decorate?: Partial<ActorDecorated>;
51
+ };
52
+ type AnyConfig = ActorConfig<unknown, unknown, Message, Message, MethodOptions, HandlerOptions<Message>, ReflectionOptions>;
53
+ /** Returned by onMessage hooks to prevent further dispatch. */
54
+ declare const STOP_SENTINEL: unique symbol;
55
+ /** Type-safe sentinel for short-circuiting onMessage hooks. */
56
+ declare const stopPropagation: () => typeof STOP_SENTINEL;
57
+ /** Return type of onMessage hooks: void (continue) or sentinel (stop). */
58
+ type HookResult = void | typeof STOP_SENTINEL;
59
+ /** A reusable unit of actor behaviour. */
60
+ type ActorPlugin<C = AnyConfig> = (config: C) => C | Promise<C>;
61
+ /** Transform parent plugins into child plugins. */
62
+ type PluginTransform = (parentPlugins: ActorPlugin[]) => ActorPlugin[];
63
+ type ActorContext<Args, InternalState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>, ReflectionMethods extends ReflectionOptions> = Methods & ActorDecorated & {
64
+ state: InternalState;
65
+ name: string;
66
+ id: symbol;
67
+ emit: (msg: OutMsg) => void;
68
+ agreeToStop: () => void;
69
+ reflection: ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers, ReflectionMethods>> & ReflectionMethods;
70
+ exit: (reason?: unknown) => void;
71
+ $child: Record<string, AnyProcess>;
72
+ fork<A, S, IM extends Message, OM extends Message, R extends ReflectionOptions>(fn: ActorDefinition<A, S, IM, OM, R>, name?: string, args?: A): Promise<AsyncProcess<A, HidePrivate<S>, IM, OM, R>>;
73
+ ctx: ProcessCtx<Args, HidePrivate<InternalState>, InMsg, OutMsg>;
74
+ };
75
+ //#endregion
76
+ //#region src/hooks.d.ts
77
+ /**
78
+ * Interface that plugins can augment via declaration merging.
79
+ * Plugins ship a .d.ts that adds properties to this interface,
80
+ * making them available on `this` in handlers and methods.
81
+ *
82
+ * Example (in a plugin's .d.ts):
83
+ * declare module 'posipaki' {
84
+ * interface ActorDecorated {
85
+ * log: Logger;
86
+ * }
87
+ * }
88
+ */
89
+ interface ActorDecorated {}
90
+ interface ActorReflection {}
91
+ /**
92
+ * Compose two lifecycle hooks so that `plugin` fires first.
93
+ *
94
+ * If `plugin` returns the STOP_SENTINEL (via stopPropagation()),
95
+ * `existing` is skipped entirely and the sentinel propagates.
96
+ * Otherwise `existing` fires and its return value is used.
97
+ *
98
+ * Typical use in a plugin:
99
+ * (cfg) => ({ ...cfg, onStart: chainHook(cfg.onStart, myOnStart) })
100
+ *
101
+ * @param existing - the current hook on the config (may be undefined)
102
+ * @param plugin - the new hook to prepend
103
+ * @returns a composed hook suitable for ActorConfig
104
+ */
105
+ declare function chainHook<TThis, TArgs extends unknown[]>(existing: ((this: TThis, ...args: TArgs) => HookResult | Promise<HookResult>) | undefined, plugin: (this: TThis, ...args: TArgs) => HookResult | Promise<HookResult>): (this: TThis, ...args: TArgs) => HookResult | Promise<HookResult>;
106
+ /**
107
+ * Merge an overlay config into a base config, auto-chaining every on* hook.
108
+ *
109
+ * Each key in `overlay` that starts with "on" followed by an uppercase
110
+ * letter (onStart, onMessage, onEmit, etc.) is composed via chainHook()
111
+ * so that the overlay hook fires before the base hook, and stopPropagation
112
+ * is respected.
113
+ *
114
+ * Typical use in a plugin:
115
+ * return mergeConfigs(cfg, {
116
+ * onStart() { this.log.info('starting'); },
117
+ * onEnd() { this.log.info('stopping'); },
118
+ * });
119
+ *
120
+ * @param base - the existing config (ActorConfig)
121
+ * @param overlay - new hook implementations to prepend
122
+ * @returns a new config with hooks chained
123
+ */
124
+ declare function mergeConfigs<T extends {}>(base: T, overlay: Partial<T>): T;
125
+ type Hook<T, I extends unknown[], O> = (this: T, ...args: I) => O;
126
+ declare function callHook<T, I extends unknown[], O>(fn: Hook<T, I, O> | undefined, eh: ((e: unknown) => unknown) | undefined, thisArg: T, ...args: I): Promise<O | undefined>;
127
+ //#endregion
128
+ export { ReflectionOptions as _, chainHook as a, ActorContext as c, ActorPlugin as d, HandlerFn as f, PluginTransform as g, MethodOptions as h, callHook as i, ActorDefinition as l, HookResult as m, ActorReflection as n, mergeConfigs as o, HandlerOptions as p, Hook as r, ActorConfig as s, ActorDecorated as t, ActorMessages as u, STOP_SENTINEL as v, stopPropagation as y };
129
+ //# sourceMappingURL=hooks-DCXE8xgc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks-DCXE8xgc.d.ts","names":[],"sources":["../src/actor-types.ts","../src/hooks.ts"],"mappings":";;;KAkBY,aAAA,WAAwB,OAAA;EAClC,cAAA,EAAgB,CAAC;AAAA;AAAA,UAEF,aAAA;EAAA,CACd,GAAA,WAAc,QAAQ;AAAA;AAAA,KAEb,SAAA,eAAwB,OAAA,KAClC,GAAA,EAAK,KAAA,EACL,MAAA,EAAQ,UAAA,YACE,OAAA;AAAA,KACA,cAAA,eAA6B,OAAA,IAAW,IAAA,SAE1C,KAAA,WAAgB,SAAA,CAAU,OAAA,CAAQ,KAAA;EAAS,IAAA,EAAM,CAAA;AAAA;AAAA,UAK1C,iBAAA;AAAA,KACL,MAAA;EAAsB,MAAA,EAAQ,GAAA;EAAK,OAAA,EAAS,IAAI;AAAA;AAAA,KAChD,WAAA,MACV,CAAA,SAAU,MAAA,qBAA2B,CAAA,aAAc,CAAA;AAAA,UAEpC,eAAA,oCAGD,OAAA,iBACC,OAAA,4BACW,iBAAA;EAE1B,EAAA,EAAI,cAAA,CAAe,IAAA,EAAM,WAAA,CAAY,aAAA,GAAgB,KAAA,EAAO,MAAA;EApB3C;EAsBjB,IAAA;EAzBoB;EA2BpB,aAAA,GAAgB,WAAA,KAAgB,eAAA;EA1B3B;EA4BL,KAAA,CACE,IAAA,EAAM,IAAA,GACL,OAAA,CACD,YAAA,CACE,IAAA,EACA,WAAA,CAAY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AA,EAAM,CAAA,GACR,OAAA,CAAQ,CAAA"}
@@ -0,0 +1,72 @@
1
+ //#region src/actor-types.ts
2
+ /** Returned by onMessage hooks to prevent further dispatch. */
3
+ const STOP_SENTINEL = Symbol("posipaki.stopPropagation");
4
+ /** Type-safe sentinel for short-circuiting onMessage hooks. */
5
+ const stopPropagation = () => STOP_SENTINEL;
6
+ //#endregion
7
+ //#region src/hooks.ts
8
+ /**
9
+ * Compose two lifecycle hooks so that `plugin` fires first.
10
+ *
11
+ * If `plugin` returns the STOP_SENTINEL (via stopPropagation()),
12
+ * `existing` is skipped entirely and the sentinel propagates.
13
+ * Otherwise `existing` fires and its return value is used.
14
+ *
15
+ * Typical use in a plugin:
16
+ * (cfg) => ({ ...cfg, onStart: chainHook(cfg.onStart, myOnStart) })
17
+ *
18
+ * @param existing - the current hook on the config (may be undefined)
19
+ * @param plugin - the new hook to prepend
20
+ * @returns a composed hook suitable for ActorConfig
21
+ */
22
+ function chainHook(existing, plugin) {
23
+ if (!existing) return plugin;
24
+ return async function(...args) {
25
+ const result = await plugin.call(this, ...args);
26
+ if (result === STOP_SENTINEL) return result;
27
+ return await existing.call(this, ...args);
28
+ };
29
+ }
30
+ /**
31
+ * Merge an overlay config into a base config, auto-chaining every on* hook.
32
+ *
33
+ * Each key in `overlay` that starts with "on" followed by an uppercase
34
+ * letter (onStart, onMessage, onEmit, etc.) is composed via chainHook()
35
+ * so that the overlay hook fires before the base hook, and stopPropagation
36
+ * is respected.
37
+ *
38
+ * Typical use in a plugin:
39
+ * return mergeConfigs(cfg, {
40
+ * onStart() { this.log.info('starting'); },
41
+ * onEnd() { this.log.info('stopping'); },
42
+ * });
43
+ *
44
+ * @param base - the existing config (ActorConfig)
45
+ * @param overlay - new hook implementations to prepend
46
+ * @returns a new config with hooks chained
47
+ */
48
+ function mergeConfigs(base, overlay) {
49
+ const result = { ...base };
50
+ for (const key of Object.keys(overlay)) {
51
+ const val = overlay[key];
52
+ if (typeof val === "function" && /^(on|after)[A-Z]/.test(key)) result[key] = chainHook(base[key], val);
53
+ else result[key] = val;
54
+ }
55
+ result.$reflectionMethods = {};
56
+ Object.assign(result.$reflectionMethods, "$reflectionMethods" in base ? base.$reflectionMethods : {}, "$reflectionMethods" in overlay ? overlay.$reflectionMethods : {});
57
+ return result;
58
+ }
59
+ async function callHook(fn, eh, thisArg, ...args) {
60
+ if (fn) try {
61
+ return await fn.call(thisArg, ...args);
62
+ } catch (e) {
63
+ if (eh) try {
64
+ await eh(e);
65
+ } catch {}
66
+ else throw e;
67
+ }
68
+ }
69
+ //#endregion
70
+ export { stopPropagation as a, STOP_SENTINEL as i, chainHook as n, mergeConfigs as r, callHook as t };
71
+
72
+ //# sourceMappingURL=hooks-OcDWhAZK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks-OcDWhAZK.js","names":[],"sources":["../src/actor-types.ts","../src/hooks.ts"],"sourcesContent":["// ── defineActor types ────────────────────────────────────────────────────────\n//\n// Shared between define-actor.ts (implementation) and consumers that want\n// to reference the config/context/definition shapes without importing the\n// implementation module directly.\n\nimport type {\n SenderInfo,\n AsyncProcessFn,\n Message,\n ProcessCtx,\n ExitMessage,\n AnyProcessCtx,\n} from \"./types.js\";\nimport type { ActorDecorated, ActorReflection } from \"./hooks.js\";\nimport type { AnyProcess, AsyncProcess } from \"./process.async.js\";\n\n// Internal marker do not use\nexport type ActorMessages<M extends Message> = {\n __tag_messages: M;\n};\nexport interface MethodOptions {\n [key: string]: Function;\n}\nexport type HandlerFn<InMsg extends Message> = (\n msg: InMsg,\n sender: SenderInfo,\n) => void | Promise<void>;\nexport type HandlerOptions<InMsg extends Message> = Omit<\n {\n [K in InMsg[\"type\"]]: HandlerFn<Extract<InMsg, { type: K }>>;\n },\n \"STOP\"\n>;\nexport type ReflectionMethod = (...args: unknown[]) => unknown;\nexport interface ReflectionOptions {}\nexport type Paired<Priv, Pub> = { public: Pub; private: Priv };\nexport type HidePrivate<T> =\n T extends Paired<unknown, unknown> ? T[\"public\"] : T;\n\nexport interface ActorDefinition<\n Args,\n InternalState,\n InMsg extends Message,\n OutMsg extends Message,\n ReflectionMethods extends ReflectionOptions,\n> {\n fn: AsyncProcessFn<Args, HidePrivate<InternalState>, InMsg, OutMsg>;\n /** Preferred process name (from config.name). */\n name?: string;\n /** Raw plugin config (array or transform). Resolved at fork time. @internal */\n pvtPluginsRaw?: ActorPlugin[] | PluginTransform;\n /** Spawn this actor as a standalone process. */\n spawn(\n args: Args,\n ): Promise<\n AsyncProcess<\n Args,\n HidePrivate<InternalState>,\n InMsg,\n OutMsg,\n ReflectionMethods & ActorReflection\n >\n >;\n /** Spawn this actor as a child of the calling process. */\n spawnAsChild(\n ctx: AnyProcessCtx,\n args: Args,\n name?: string,\n parentPlugins?: ActorPlugin[],\n ): Promise<\n AsyncProcess<\n Args,\n HidePrivate<InternalState>,\n InMsg,\n OutMsg,\n ReflectionMethods & ActorReflection\n >\n >;\n inMessages: ActorMessages<InMsg> | undefined;\n outMessages: ActorMessages<OutMsg> | undefined;\n}\nexport type ActorConfig<\n Args,\n InternalState,\n InMsg extends Message,\n OutMsg extends Message,\n Methods extends MethodOptions,\n Handlers extends HandlerOptions<InMsg>,\n ReflectionMethods extends ReflectionOptions,\n> = ThisType<\n ActorContext<\n Args,\n InternalState,\n InMsg,\n OutMsg,\n Methods,\n Handlers,\n ReflectionMethods & ActorReflection\n >\n> & {\n /** Preferred process name. Used by ctx.fork() when no explicit name is given. */\n name?: string;\n plugins?: ActorPlugin[] | PluginTransform;\n outMessages?: ActorMessages<OutMsg>;\n inMessages?: ActorMessages<InMsg>;\n\n setup?: (\n this: ActorContext<\n Args,\n never,\n InMsg,\n OutMsg,\n Methods,\n Handlers,\n ReflectionMethods & ActorReflection\n >,\n args: Args,\n ) => Promise<InternalState> | InternalState;\n afterStart?: () => void | Promise<void>;\n onStopRequested?: () => HookResult | Promise<HookResult>;\n onEnd?: (reason?: unknown) => HookResult | Promise<HookResult>;\n onError?: (error?: unknown) => HookResult | Promise<HookResult>;\n onEmit?: (\n msg: OutMsg,\n sender: SenderInfo,\n ) => HookResult | Promise<HookResult>;\n\n onMessage?: (\n msg: InMsg,\n sender: SenderInfo,\n ) => HookResult | Promise<HookResult>;\n\n onUnhandled?: (msg: Message, sender: SenderInfo) => void | Promise<void>;\n\n onChildExit?: (\n name: string,\n reason: ExitMessage,\n ) => HookResult | Promise<HookResult>;\n\n handlers: Handlers &\n ThisType<\n ActorContext<\n Args,\n InternalState,\n InMsg,\n OutMsg,\n Methods,\n Handlers,\n ReflectionMethods & ActorReflection\n >\n >;\n\n methods?: Methods &\n ThisType<\n ActorContext<\n Args,\n InternalState,\n InMsg,\n OutMsg,\n Methods,\n Handlers,\n ReflectionMethods & ActorReflection\n >\n >;\n $reflectionMethods?: ReflectionMethods &\n ThisType<\n ActorContext<\n Args,\n InternalState,\n InMsg,\n OutMsg,\n Methods,\n Handlers,\n ActorReflection & ActorReflection\n >\n >;\n // for plugin use only\n $decorate?: Partial<ActorDecorated>;\n};\nexport type AnyConfig = ActorConfig<\n unknown,\n unknown,\n Message,\n Message,\n MethodOptions,\n HandlerOptions<Message>,\n ReflectionOptions\n>;\n\n// ── stop propagation sentinel ────────────────────────────────────────────\n\n/** Returned by onMessage hooks to prevent further dispatch. */\nexport const STOP_SENTINEL = Symbol(\"posipaki.stopPropagation\");\n\n/** Type-safe sentinel for short-circuiting onMessage hooks. */\nexport const stopPropagation = (): typeof STOP_SENTINEL => STOP_SENTINEL;\n\n// ── hook function types ──────────────────────────────────────────────────\n\n/** Return type of onMessage hooks: void (continue) or sentinel (stop). */\nexport type HookResult = void | typeof STOP_SENTINEL;\n// ── plugin types ─────────────────────────────────────────────────────────\n\n/** A reusable unit of actor behaviour. */\nexport type ActorPlugin<C = AnyConfig> = (config: C) => C | Promise<C>;\n\n/** Transform parent plugins into child plugins. */\nexport type PluginTransform = (parentPlugins: ActorPlugin[]) => ActorPlugin[];\n\nexport type ActorContext<\n Args,\n InternalState,\n InMsg extends Message,\n OutMsg extends Message,\n Methods extends MethodOptions,\n Handlers extends HandlerOptions<InMsg>,\n ReflectionMethods extends ReflectionOptions,\n> = Methods &\n ActorDecorated & {\n state: InternalState;\n name: string;\n id: symbol;\n\n emit: (msg: OutMsg) => void;\n agreeToStop: () => void;\n\n reflection: ThisType<\n ActorContext<\n Args,\n InternalState,\n InMsg,\n OutMsg,\n Methods,\n Handlers,\n ReflectionMethods\n >\n > &\n ReflectionMethods;\n exit: (reason?: unknown) => void;\n\n $child: Record<string, AnyProcess>;\n\n fork<\n A,\n S,\n IM extends Message,\n OM extends Message,\n R extends ReflectionOptions,\n >(\n fn: ActorDefinition<A, S, IM, OM, R>,\n name?: string,\n args?: A,\n ): Promise<AsyncProcess<A, HidePrivate<S>, IM, OM, R>>;\n\n ctx: ProcessCtx<Args, HidePrivate<InternalState>, InMsg, OutMsg>;\n };\n","// ── Lifecycle Hooks ──────────────────────────────────────────────────────\n//\n// Extends ProcessCtx and defineActor with observable lifecycle hooks.\n// Hooks are additive — multiple callbacks can register for the same hook\n// point, and they fire in registration order.\n\nimport { STOP_SENTINEL, stopPropagation } from \"./actor-types.js\";\nimport type {\n HookResult,\n ActorPlugin,\n PluginTransform,\n} from \"./actor-types.js\";\n\n// ── stop propagation sentinel ────────────────────────────────────────────\n\n// Re-exports from actor-types.ts (backward compatibility)\nexport { STOP_SENTINEL, stopPropagation };\nexport type { HookResult, ActorPlugin, PluginTransform };\n\n// ── type augmentation (Fastify-style) ────────────────────────────────────\n\n/**\n * Interface that plugins can augment via declaration merging.\n * Plugins ship a .d.ts that adds properties to this interface,\n * making them available on `this` in handlers and methods.\n *\n * Example (in a plugin's .d.ts):\n * declare module 'posipaki' {\n * interface ActorDecorated {\n * log: Logger;\n * }\n * }\n */\nexport interface ActorDecorated {}\nexport interface ActorReflection {}\n\n// ── chainHook ────────────────────────────────────────────────────────────\n\n/**\n * Compose two lifecycle hooks so that `plugin` fires first.\n *\n * If `plugin` returns the STOP_SENTINEL (via stopPropagation()),\n * `existing` is skipped entirely and the sentinel propagates.\n * Otherwise `existing` fires and its return value is used.\n *\n * Typical use in a plugin:\n * (cfg) => ({ ...cfg, onStart: chainHook(cfg.onStart, myOnStart) })\n *\n * @param existing - the current hook on the config (may be undefined)\n * @param plugin - the new hook to prepend\n * @returns a composed hook suitable for ActorConfig\n */\nexport function chainHook<TThis, TArgs extends unknown[]>(\n existing:\n | ((this: TThis, ...args: TArgs) => HookResult | Promise<HookResult>)\n | undefined,\n plugin: (this: TThis, ...args: TArgs) => HookResult | Promise<HookResult>,\n): (this: TThis, ...args: TArgs) => HookResult | Promise<HookResult> {\n if (!existing) return plugin;\n return async function (this: TThis, ...args: TArgs): Promise<HookResult> {\n const result = await plugin.call(this, ...args);\n if (result === STOP_SENTINEL) return result;\n return await existing.call(this, ...args);\n } as (this: TThis, ...args: TArgs) => HookResult | Promise<HookResult>;\n}\n\n// ── mergeConfigs ─────────────────────────────────────────────────────────\n\n/**\n * Merge an overlay config into a base config, auto-chaining every on* hook.\n *\n * Each key in `overlay` that starts with \"on\" followed by an uppercase\n * letter (onStart, onMessage, onEmit, etc.) is composed via chainHook()\n * so that the overlay hook fires before the base hook, and stopPropagation\n * is respected.\n *\n * Typical use in a plugin:\n * return mergeConfigs(cfg, {\n * onStart() { this.log.info('starting'); },\n * onEnd() { this.log.info('stopping'); },\n * });\n *\n * @param base - the existing config (ActorConfig)\n * @param overlay - new hook implementations to prepend\n * @returns a new config with hooks chained\n */\nexport function mergeConfigs<T extends {}>(base: T, overlay: Partial<T>): T {\n const result = { ...base } as Record<string, unknown>;\n for (const key of Object.keys(overlay as Record<string, unknown>)) {\n const val = (overlay as Record<string, unknown>)[key];\n if (typeof val === \"function\" && /^(on|after)[A-Z]/.test(key)) {\n result[key] = chainHook(\n (base as Record<string, unknown>)[key] as (\n this: unknown,\n ...args: unknown[]\n ) => HookResult | Promise<HookResult>,\n val as (\n this: unknown,\n ...args: unknown[]\n ) => HookResult | Promise<HookResult>,\n );\n } else {\n result[key] = val;\n }\n }\n result.$reflectionMethods = {};\n Object.assign(\n result.$reflectionMethods as object,\n \"$reflectionMethods\" in base ? base.$reflectionMethods : {},\n \"$reflectionMethods\" in overlay ? overlay.$reflectionMethods : {},\n );\n\n return result as unknown as T;\n}\n\nexport type Hook<T, I extends unknown[], O> = (this: T, ...args: I) => O;\n\nexport async function callHook<T, I extends unknown[], O>(\n fn: Hook<T, I, O> | undefined,\n eh: ((e: unknown) => unknown) | undefined,\n thisArg: T,\n ...args: I\n): Promise<O | undefined> {\n if (fn) {\n try {\n return await fn.call(thisArg, ...args);\n } catch (e) {\n if (eh) {\n try {\n await eh(e);\n } catch {}\n } else {\n throw e;\n }\n }\n }\n return undefined;\n}\n"],"mappings":";;AAiMA,MAAa,gBAAgB,OAAO,0BAA0B;;AAG9D,MAAa,wBAA8C;;;;;;;;;;;;;;;;;AChJ3D,SAAgB,UACd,UAGA,QACmE;CACnE,IAAI,CAAC,UAAU,OAAO;CACtB,OAAO,eAA6B,GAAG,MAAkC;EACvE,MAAM,SAAS,MAAM,OAAO,KAAK,MAAM,GAAG,IAAI;EAC9C,IAAI,WAAW,eAAe,OAAO;EACrC,OAAO,MAAM,SAAS,KAAK,MAAM,GAAG,IAAI;CAC1C;AACF;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,aAA2B,MAAS,SAAwB;CAC1E,MAAM,SAAS,EAAE,GAAG,KAAK;CACzB,KAAK,MAAM,OAAO,OAAO,KAAK,OAAkC,GAAG;EACjE,MAAM,MAAO,QAAoC;EACjD,IAAI,OAAO,QAAQ,cAAc,mBAAmB,KAAK,GAAG,GAC1D,OAAO,OAAO,UACX,KAAiC,MAIlC,GAIF;OAEA,OAAO,OAAO;CAElB;CACA,OAAO,qBAAqB,CAAC;CAC7B,OAAO,OACL,OAAO,oBACP,wBAAwB,OAAO,KAAK,qBAAqB,CAAC,GAC1D,wBAAwB,UAAU,QAAQ,qBAAqB,CAAC,CAClE;CAEA,OAAO;AACT;AAIA,eAAsB,SACpB,IACA,IACA,SACA,GAAG,MACqB;CACxB,IAAI,IACF,IAAI;EACF,OAAO,MAAM,GAAG,KAAK,SAAS,GAAG,IAAI;CACvC,SAAS,GAAG;EACV,IAAI,IACF,IAAI;GACF,MAAM,GAAG,CAAC;EACZ,QAAQ,CAAC;OAET,MAAM;CAEV;AAGJ"}
package/dist/hooks.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as OnStartHook, b as STOP_SENTINEL, f as OnChildExitHook, g as OnMessageHook, h as OnErrorHook, m as OnEndHook, n as HookRegistry, p as OnEmitHook, s as ActorPlugin, t as ActorDecorated, u as HookResult, v as OnStopRequestedHook, x as stopPropagation, y as PluginTransform } from "./hooks-Czj67zNB.js";
2
- export { ActorDecorated, type ActorPlugin, HookRegistry, type HookResult, type OnChildExitHook, type OnEmitHook, type OnEndHook, type OnErrorHook, type OnMessageHook, type OnStartHook, type OnStopRequestedHook, type PluginTransform, STOP_SENTINEL, stopPropagation };
1
+ import { a as chainHook, d as ActorPlugin, g as PluginTransform, i as callHook, m as HookResult, n as ActorReflection, o as mergeConfigs, r as Hook, t as ActorDecorated, v as STOP_SENTINEL, y as stopPropagation } from "./hooks-DCXE8xgc.js";
2
+ export { ActorDecorated, type ActorPlugin, ActorReflection, Hook, type HookResult, type PluginTransform, STOP_SENTINEL, callHook, chainHook, mergeConfigs, stopPropagation };
package/dist/hooks.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as STOP_SENTINEL, r as stopPropagation, t as HookRegistry } from "./hooks-D5DhD9gu.js";
2
- export { HookRegistry, STOP_SENTINEL, stopPropagation };
1
+ import { a as stopPropagation, i as STOP_SENTINEL, n as chainHook, r as mergeConfigs, t as callHook } from "./hooks-OcDWhAZK.js";
2
+ export { STOP_SENTINEL, callHook, chainHook, mergeConfigs, stopPropagation };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { a as ProcessCtx, c as SenderOrigin, d as WithSender, f as WithoutSender, h as spawnAsync, i as PipeState, l as StopMessage, m as runDispatchAsync, n as ExitMessage, o as ProcessFn, p as AsyncProcess, r as Message, s as SenderInfo, t as AsyncProcessFn, u as SupervisorState } from "./types-BLIFntvm.js";
2
- import { _ as OnStartHook, a as ActorDefinition, c as HandlerFn, d as MethodOptions, f as OnChildExitHook, g as OnMessageHook, h as OnErrorHook, i as ActorContext, l as HandlerOptions, m as OnEndHook, n as HookRegistry, o as ActorMessages, p as OnEmitHook, r as ActorConfig, s as ActorPlugin, t as ActorDecorated, u as HookResult, v as OnStopRequestedHook, x as stopPropagation, y as PluginTransform } from "./hooks-Czj67zNB.js";
3
- import { n as spawn, r as runDispatch, t as Process } from "./process-Bf9HTr0m.js";
1
+ import { _ as spawnAsync, a as PipeState, c as SenderInfo, d as SupervisorState, f as WithSender, g as runDispatchAsync, h as AsyncProcess, i as Message, l as SenderOrigin, n as AsyncProcessFn, o as ProcessCtx, p as WithoutSender, r as ExitMessage, s as ProcessFn, u as StopMessage } from "./types-BUPRp3t_.js";
2
+ import { _ as ReflectionOptions, a as chainHook, c as ActorContext, d as ActorPlugin, f as HandlerFn, g as PluginTransform, h as MethodOptions, i as callHook, l as ActorDefinition, m as HookResult, n as ActorReflection, o as mergeConfigs, p as HandlerOptions, s as ActorConfig, t as ActorDecorated, u as ActorMessages, y as stopPropagation } from "./hooks-DCXE8xgc.js";
3
+ import { n as spawn, r as runDispatch, t as Process } from "./process-B7rh_NBl.js";
4
4
 
5
5
  //#region src/adapters.d.ts
6
6
  declare function asyncify<A, S, IM extends Message, OM extends Message>(fn: ProcessFn<A, S, IM, OM>): AsyncProcessFn<A, S, IM, OM>;
7
7
  //#endregion
8
8
  //#region src/define-actor.d.ts
9
9
  declare function defineMessages<OutMsg extends Message = Message>(): ActorMessages<OutMsg>;
10
- declare function defineActor<Args, InternalState, ExposedState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>, ReflectionMethods = {}>(config: ActorConfig<Args, InternalState, ExposedState, InMsg, OutMsg, Methods, Handlers, ReflectionMethods>): ActorDefinition<Args, ExposedState, InMsg, OutMsg, Handlers, ReflectionMethods>;
10
+ declare function defineActor<Args, InternalState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>, ReflectionMethods extends ReflectionOptions>(config: ActorConfig<Args, InternalState, InMsg, OutMsg, Methods, Handlers, ReflectionMethods>): ActorDefinition<Args, InternalState, InMsg, OutMsg, ReflectionMethods>;
11
11
  //#endregion
12
- export { type ActorConfig, type ActorContext, type ActorDecorated, type ActorDefinition, type ActorPlugin, AsyncProcess, type AsyncProcessFn, type ExitMessage, type HandlerFn, type HandlerOptions, HookRegistry, type HookResult, type Message, type MethodOptions, type OnChildExitHook, type OnEmitHook, type OnEndHook, type OnErrorHook, type OnMessageHook, type OnStartHook, type OnStopRequestedHook, type PipeState, type PluginTransform, Process, type ProcessCtx, type ProcessFn, type SenderInfo, type SenderOrigin, type StopMessage, type SupervisorState, type WithSender, type WithoutSender, asyncify, defineActor, defineMessages, runDispatch, runDispatchAsync, spawn, spawnAsync, stopPropagation };
12
+ export { type ActorConfig, type ActorContext, type ActorDecorated, type ActorDefinition, type ActorPlugin, type ActorReflection, AsyncProcess, type AsyncProcessFn, type ExitMessage, type HandlerFn, type HandlerOptions, type HookResult, type Message, type MethodOptions, type PipeState, type PluginTransform, Process, type ProcessCtx, type ProcessFn, type SenderInfo, type SenderOrigin, type StopMessage, type SupervisorState, type WithSender, type WithoutSender, asyncify, callHook, chainHook, defineActor, defineMessages, mergeConfigs, runDispatch, runDispatchAsync, spawn, spawnAsync, stopPropagation };
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/adapters.ts","../src/define-actor.ts"],"mappings":";;;;;iBAEgB,QAAA,kBAA0B,OAAA,aAAoB,OAAA,EAC5D,EAAA,EAAI,SAAA,CAAU,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA,IACvB,cAAA,CAAe,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA;;;iBC6BZ,cAAA,gBACC,OAAA,GAAU,OAAA,KACtB,aAAA,CAAc,MAAA;AAAA,iBAIH,WAAA,kDAIA,OAAA,iBACC,OAAA,kBACC,aAAA,mBACC,cAAA,CAAe,KAAA,2BAGhC,MAAA,EAAQ,WAAA,CACN,IAAA,EACA,aAAA,EACA,YAAA,EACA,KAAA,EACA,MAAA,EACA,OAAA,EACA,QAAA,EACA,iBAAA,IAED,eAAA,CAAgB,IAAA,EAAM,YAAA,EAAc,KAAA,EAAO,MAAA,EAAQ,QAAA,EAAU,iBAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/adapters.ts","../src/define-actor.ts"],"mappings":";;;;;iBAEgB,QAAA,kBAA0B,OAAA,aAAoB,OAAA,EAC5D,EAAA,EAAI,SAAA,CAAU,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA,IACvB,cAAA,CAAe,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA;;;iBCmCZ,cAAA,gBACC,OAAA,GAAU,OAAA,KACtB,aAAA,CAAc,MAAA;AAAA,iBA0CH,WAAA,oCAGA,OAAA,iBACC,OAAA,kBACC,aAAA,mBACC,cAAA,CAAe,KAAA,6BACN,iBAAA,EAE1B,MAAA,EAAQ,WAAA,CACN,IAAA,EACA,aAAA,EACA,KAAA,EACA,MAAA,EACA,OAAA,EACA,QAAA,EACA,iBAAA,IAED,eAAA,CAAgB,IAAA,EAAM,aAAA,EAAe,KAAA,EAAO,MAAA,EAAQ,iBAAA"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { i as runDispatch } from "./util-DsfVKxTT.js";
2
- import { a as AsyncProcess, c as asyncify, i as spawn, n as defineMessages, o as runDispatchAsync, r as Process, s as spawnAsync, t as defineActor } from "./src-B2jOTwzs.js";
3
- import { r as stopPropagation, t as HookRegistry } from "./hooks-D5DhD9gu.js";
4
- export { AsyncProcess, HookRegistry, Process, asyncify, defineActor, defineMessages, runDispatch, runDispatchAsync, spawn, spawnAsync, stopPropagation };
2
+ import { a as AsyncProcess, c as asyncify, i as spawn, n as defineMessages, o as runDispatchAsync, r as Process, s as spawnAsync, t as defineActor } from "./src-gcahpgho.js";
3
+ import { a as stopPropagation, n as chainHook, r as mergeConfigs, t as callHook } from "./hooks-OcDWhAZK.js";
4
+ export { AsyncProcess, Process, asyncify, callHook, chainHook, defineActor, defineMessages, mergeConfigs, runDispatch, runDispatchAsync, spawn, spawnAsync, stopPropagation };
package/dist/pipe.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ExitMessage, o as ProcessFn, r as Message } from "./types-BLIFntvm.js";
1
+ import { i as Message, r as ExitMessage, s as ProcessFn } from "./types-BUPRp3t_.js";
2
2
 
3
3
  //#region src/pipe.d.ts
4
4
  /**
@@ -16,7 +16,9 @@ interface PipeState<Params, Result> {
16
16
  * The `.state.result` of each completed child is spread into the params
17
17
  * of the next.
18
18
  */
19
- declare function pipe<Params, Result>(fns: ProcessFn<unknown, unknown, Message, Message>[]): ProcessFn<Params, PipeState<Params, Result>, Message, Message | ExitMessage>;
19
+ declare function pipe<Params, Result>(fns: ProcessFn<unknown, {
20
+ result: object;
21
+ }, Message, Message>[]): ProcessFn<Params, PipeState<Params, Result>, Message, Message | ExitMessage>;
20
22
  //#endregion
21
23
  export { PipeState, pipe };
22
24
  //# sourceMappingURL=pipe.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pipe.d.ts","names":[],"sources":["../src/pipe.ts"],"mappings":";;;AAWA;;;;;AAAA,UAAiB,SAAA;EACf,MAAA,EAAQ,MAAA;EACR,MAAA,EAAQ,MAAM;EACd,OAAA;AAAA;;;AAAO;AACR;;iBAOQ,IAAA,iBACP,GAAA,EAAK,SAAA,mBAA4B,OAAA,EAAS,OAAA,MACzC,SAAA,CACD,MAAA,EACA,SAAA,CAAU,MAAA,EAAQ,MAAA,GAClB,OAAA,EACA,OAAA,GAAU,WAAA"}
1
+ {"version":3,"file":"pipe.d.ts","names":[],"sources":["../src/pipe.ts"],"mappings":";;;AAWA;;;;;AAAA,UAAiB,SAAA;EACf,MAAA,EAAQ,MAAA;EACR,MAAA,EAAQ,MAAM;EACd,OAAA;AAAA;;;AAAO;AACR;;iBAOQ,IAAA,iBACP,GAAA,EAAK,SAAA;EAAqB,MAAA;AAAA,GAAkB,OAAA,EAAS,OAAA,MACpD,SAAA,CACD,MAAA,EACA,SAAA,CAAU,MAAA,EAAQ,MAAA,GAClB,OAAA,EACA,OAAA,GAAU,WAAA"}
package/dist/pipe.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pipe.js","names":[],"sources":["../src/pipe.ts"],"sourcesContent":["import { runDispatch } from \"./util.js\";\nimport type { ExitMessage } from \"./util.js\";\nimport type { ProcessFn, ProcessCtx } from \"./process.js\";\nimport type { AsyncProcess } from \"./process.async.js\";\nimport type { Message, WithSender } from \"./types.js\";\n\n/**\n * State yielded by the pipe process. `params` starts as a copy of the\n * initial args and is updated after each child exits by merging the\n * child's `state.result` into it.\n */\nexport interface PipeState<Params, Result> {\n params: Params | null;\n result: Result | null;\n running: boolean;\n}\n\n/**\n * Chain process functions so each runs after the previous one exits.\n * The `.state.result` of each completed child is spread into the params\n * of the next.\n */\nfunction pipe<Params, Result>(\n fns: ProcessFn<unknown, unknown, Message, Message>[],\n): ProcessFn<\n Params,\n PipeState<Params, Result>,\n Message,\n Message | ExitMessage\n> {\n return function* (\n ctx: ProcessCtx<\n Params,\n PipeState<Params, Result>,\n Message,\n Message | ExitMessage\n >,\n params: Params,\n ) {\n const state: PipeState<Params, Result> = {\n params: { ...params },\n result: null,\n running: false,\n };\n yield state;\n\n const queue = [...fns];\n let task: AsyncProcess<any, any, any, any>;\n\n function spawnNext(): void {\n const fn = queue.shift()!;\n task = ctx.forkSync(\n fn,\n `${ctx.pname} [${fn.name || \"<anonymous>\"}]`,\n )(state.params as Params);\n }\n\n function hasNext(): boolean {\n return queue.length > 0;\n }\n\n spawnNext();\n state.running = hasNext();\n\n yield* runDispatch<WithSender<Message | ExitMessage>>(\n ctx.pname,\n (maybe) => {\n const [msg, _sender] = maybe;\n\n if (msg.type === \"STOP\") {\n state.params = null;\n state.running = false;\n return;\n }\n\n if (msg.type === \"EXIT\" && _sender.fromId === task.id) {\n if (hasNext()) {\n state.params = {\n ...state.params!,\n ...task.state?.result,\n } as Params;\n spawnNext();\n } else {\n state.running = false;\n state.result = task.state?.result as Result;\n }\n }\n },\n () => !state.running,\n true,\n );\n };\n}\n\nexport { pipe };\n"],"mappings":";;;;;;;AAsBA,SAAS,KACP,KAMA;CACA,OAAO,WACL,KAMA,QACA;EACA,MAAM,QAAmC;GACvC,QAAQ,EAAE,GAAG,OAAO;GACpB,QAAQ;GACR,SAAS;EACX;EACA,MAAM;EAEN,MAAM,QAAQ,CAAC,GAAG,GAAG;EACrB,IAAI;EAEJ,SAAS,YAAkB;GACzB,MAAM,KAAK,MAAM,MAAM;GACvB,OAAO,IAAI,SACT,IACA,GAAG,IAAI,MAAM,IAAI,GAAG,QAAQ,cAAc,EAC5C,EAAE,MAAM,MAAgB;EAC1B;EAEA,SAAS,UAAmB;GAC1B,OAAO,MAAM,SAAS;EACxB;EAEA,UAAU;EACV,MAAM,UAAU,QAAQ;EAExB,OAAO,YACL,IAAI,QACH,UAAU;GACT,MAAM,CAAC,KAAK,WAAW;GAEvB,IAAI,IAAI,SAAS,QAAQ;IACvB,MAAM,SAAS;IACf,MAAM,UAAU;IAChB;GACF;GAEA,IAAI,IAAI,SAAS,UAAU,QAAQ,WAAW,KAAK,IACjD,IAAI,QAAQ,GAAG;IACb,MAAM,SAAS;KACb,GAAG,MAAM;KACT,GAAG,KAAK,OAAO;IACjB;IACA,UAAU;GACZ,OAAO;IACL,MAAM,UAAU;IAChB,MAAM,SAAS,KAAK,OAAO;GAC7B;EAEJ,SACM,CAAC,MAAM,SACb,IACF;CACF;AACF"}
1
+ {"version":3,"file":"pipe.js","names":[],"sources":["../src/pipe.ts"],"sourcesContent":["import { runDispatch } from \"./util.js\";\nimport type { ExitMessage } from \"./util.js\";\nimport type { ProcessFn, ProcessCtx } from \"./process.js\";\nimport type { AsyncProcess } from \"./process.async.js\";\nimport type { Message, WithSender } from \"./types.js\";\n\n/**\n * State yielded by the pipe process. `params` starts as a copy of the\n * initial args and is updated after each child exits by merging the\n * child's `state.result` into it.\n */\nexport interface PipeState<Params, Result> {\n params: Params | null;\n result: Result | null;\n running: boolean;\n}\n\n/**\n * Chain process functions so each runs after the previous one exits.\n * The `.state.result` of each completed child is spread into the params\n * of the next.\n */\nfunction pipe<Params, Result>(\n fns: ProcessFn<unknown, { result: object }, Message, Message>[],\n): ProcessFn<\n Params,\n PipeState<Params, Result>,\n Message,\n Message | ExitMessage\n> {\n return function* (\n ctx: ProcessCtx<\n Params,\n PipeState<Params, Result>,\n Message,\n Message | ExitMessage\n >,\n params: Params,\n ) {\n const state: PipeState<Params, Result> = {\n params: { ...params },\n result: null,\n running: false,\n };\n yield state;\n\n const queue = [...fns];\n let task: AsyncProcess<unknown, { result: object }, Message, Message, {}>;\n\n function spawnNext(): void {\n const fn = queue.shift()!;\n task = ctx.forkSync(\n fn,\n `${ctx.pname} [${fn.name || \"<anonymous>\"}]`,\n )(state.params as Params);\n }\n\n function hasNext(): boolean {\n return queue.length > 0;\n }\n\n spawnNext();\n state.running = hasNext();\n\n yield* runDispatch<WithSender<Message | ExitMessage>>(\n ctx.pname,\n (maybe) => {\n const [msg, _sender] = maybe;\n\n if (msg.type === \"STOP\") {\n state.params = null;\n state.running = false;\n return;\n }\n\n if (msg.type === \"EXIT\" && _sender.fromId === task.id) {\n if (hasNext()) {\n state.params = {\n ...state.params!,\n ...task.state?.result,\n } as Params;\n spawnNext();\n } else {\n state.running = false;\n state.result = task.state?.result as Result;\n }\n }\n },\n () => !state.running,\n true,\n );\n };\n}\n\nexport { pipe };\n"],"mappings":";;;;;;;AAsBA,SAAS,KACP,KAMA;CACA,OAAO,WACL,KAMA,QACA;EACA,MAAM,QAAmC;GACvC,QAAQ,EAAE,GAAG,OAAO;GACpB,QAAQ;GACR,SAAS;EACX;EACA,MAAM;EAEN,MAAM,QAAQ,CAAC,GAAG,GAAG;EACrB,IAAI;EAEJ,SAAS,YAAkB;GACzB,MAAM,KAAK,MAAM,MAAM;GACvB,OAAO,IAAI,SACT,IACA,GAAG,IAAI,MAAM,IAAI,GAAG,QAAQ,cAAc,EAC5C,EAAE,MAAM,MAAgB;EAC1B;EAEA,SAAS,UAAmB;GAC1B,OAAO,MAAM,SAAS;EACxB;EAEA,UAAU;EACV,MAAM,UAAU,QAAQ;EAExB,OAAO,YACL,IAAI,QACH,UAAU;GACT,MAAM,CAAC,KAAK,WAAW;GAEvB,IAAI,IAAI,SAAS,QAAQ;IACvB,MAAM,SAAS;IACf,MAAM,UAAU;IAChB;GACF;GAEA,IAAI,IAAI,SAAS,UAAU,QAAQ,WAAW,KAAK,IACjD,IAAI,QAAQ,GAAG;IACb,MAAM,SAAS;KACb,GAAG,MAAM;KACT,GAAG,KAAK,OAAO;IACjB;IACA,UAAU;GACZ,OAAO;IACL,MAAM,UAAU;IAChB,MAAM,SAAS,KAAK,OAAO;GAC7B;EAEJ,SACM,CAAC,MAAM,SACb,IACF;CACF;AACF"}
@@ -1,6 +1,11 @@
1
- import { s as ActorPlugin } from "../hooks-Czj67zNB.js";
1
+ import { d as ActorPlugin } from "../hooks-DCXE8xgc.js";
2
2
 
3
3
  //#region src/plugins/debug-logger.d.ts
4
+ declare module "../hooks" {
5
+ interface ActorDecorated {
6
+ log: Logger;
7
+ }
8
+ }
4
9
  interface DebugLogFn {
5
10
  (message: string, ...args: unknown[]): void;
6
11
  }
@@ -10,12 +15,9 @@ interface Logger {
10
15
  warn: DebugLogFn;
11
16
  error: DebugLogFn;
12
17
  }
13
- /** Factory: receives an actor name, returns a Logger. */
14
18
  type LoggerFactory = (name: string) => Logger;
15
19
  interface DebugLoggerOpts {
16
- /** Message types to silence (e.g. ['HEARTBEAT', 'TICK']). Default: none. */
17
20
  ignore?: string[];
18
- /** Logger factory. Default: console-based logger. */
19
21
  factory?: LoggerFactory;
20
22
  }
21
23
  declare function debugLogger(opts?: DebugLoggerOpts): ActorPlugin;
@@ -1 +1 @@
1
- {"version":3,"file":"debug-logger.d.ts","names":[],"sources":["../../src/plugins/debug-logger.ts"],"mappings":";;;UAmCiB,UAAA;EAAA,CACd,OAAA,aAAoB,IAAI;AAAA;AAAA,UAGV,MAAA;EACf,KAAA,EAAO,UAAA;EACP,IAAA,EAAM,UAAA;EACN,IAAA,EAAM,UAAA;EACN,KAAA,EAAO,UAAA;AAAA;;KAIG,aAAA,IAAiB,IAAA,aAAiB,MAAM;AAAA,UAInC,eAAA;EATT;EAWN,MAAA;EAViB;EAYjB,OAAA,GAAU,aAAa;AAAA;AAAA,iBAyCT,WAAA,CAAY,IAAA,GAAO,eAAA,GAAkB,WAAW"}
1
+ {"version":3,"file":"debug-logger.d.ts","names":[],"sources":["../../src/plugins/debug-logger.ts"],"mappings":";;;;YAKY,cAAA;IACR,GAAA,EAAK,MAAM;EAAA;AAAA;AAAA,UAIE,UAAA;EAAA,CACd,OAAA,aAAoB,IAAI;AAAA;AAAA,UAEV,MAAA;EACf,KAAA,EAAO,UAAA;EACP,IAAA,EAAM,UAAA;EACN,IAAA,EAAM,UAAA;EACN,KAAA,EAAO,UAAA;AAAA;AAAA,KAEG,aAAA,IAAiB,IAAA,aAAiB,MAAM;AAAA,UACnC,eAAA;EACf,MAAA;EACA,OAAA,GAAU,aAAa;AAAA;AAAA,iBA+BT,WAAA,CAAY,IAAA,GAAO,eAAA,GAAkB,WAAW"}
@@ -1,3 +1,4 @@
1
+ import { r as mergeConfigs } from "../hooks-OcDWhAZK.js";
1
2
  //#region src/plugins/debug-logger.ts
2
3
  function patterns() {
3
4
  const raw = (process.env.DEBUG ?? "").trim();
@@ -9,48 +10,45 @@ function matches(name, pats) {
9
10
  for (const p of pats) {
10
11
  if (p === "*") return true;
11
12
  if (p.endsWith(":*")) {
12
- const prefix = p.slice(0, -2);
13
- if (name === prefix || name.startsWith(prefix + ":")) return true;
14
- continue;
15
- }
16
- if (p === name) return true;
13
+ if (name === p.slice(0, -2) || name.startsWith(p.slice(0, -2) + ":")) return true;
14
+ } else if (p === name) return true;
17
15
  }
18
16
  return false;
19
17
  }
20
18
  function defaultFactory(name) {
21
19
  return {
22
- debug: (...args) => console.debug(`[${name}]`, ...args),
23
- info: (...args) => console.info(`[${name}]`, ...args),
24
- warn: (...args) => console.warn(`[${name}]`, ...args),
25
- error: (...args) => console.error(`[${name}]`, ...args)
20
+ debug: (...a) => console.debug(`[${name}]`, ...a),
21
+ info: (...a) => console.info(`[${name}]`, ...a),
22
+ warn: (...a) => console.warn(`[${name}]`, ...a),
23
+ error: (...a) => console.error(`[${name}]`, ...a)
26
24
  };
27
25
  }
28
26
  function debugLogger(opts) {
29
27
  const ignoreSet = new Set(opts?.ignore ?? []);
30
28
  const factory = opts?.factory ?? defaultFactory;
31
- return {
32
- name: "debugLogger",
33
- install(self) {
34
- const name = self.name;
35
- const pats = patterns();
36
- const log = factory(name);
37
- self.decorate("log", log);
38
- if (!matches(name, pats)) return;
39
- self.hooks.onMessage((msg, sender) => {
40
- if (ignoreSet.has(msg.type)) return;
41
- const via = sender?.fromName ? ` from ${sender.fromName}` : "";
42
- log.debug(`${name} ← ${msg.type}${via}`, msg);
43
- });
44
- self.hooks.onEmit((msg) => {
29
+ return async (config) => {
30
+ const name = config.name ?? "actor";
31
+ const pats = patterns();
32
+ const log = factory(name);
33
+ let result = mergeConfigs(config, {
34
+ methods: { ...config.methods },
35
+ $decorate: { log }
36
+ });
37
+ if (matches(name, pats)) result = mergeConfigs(result, {
38
+ onMessage(msg) {
39
+ if (!ignoreSet.has(msg.type)) log.debug(`${name} ${msg.type}`, msg);
40
+ },
41
+ onEmit(msg) {
45
42
  log.debug(`${name} → ${msg.type}`, msg);
46
- });
47
- self.hooks.onChildExit((childName) => {
43
+ },
44
+ onChildExit(childName) {
48
45
  log.debug(`child ${childName} exited`);
49
- });
50
- self.hooks.onError((err) => {
46
+ },
47
+ onError(err) {
51
48
  log.error(`${err.message ?? err}`);
52
- });
53
- }
49
+ }
50
+ });
51
+ return result;
54
52
  };
55
53
  }
56
54
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"debug-logger.js","names":[],"sources":["../../src/plugins/debug-logger.ts"],"sourcesContent":["// ── debugLogger Plugin ───────────────────────────────────────────────────\n//\n// Controlled via the DEBUG environment variable.\n//\n// DEBUG format: comma-separated patterns with glob-like subtree matching.\n//\n// DEBUG=* enable all debug logging\n// DEBUG=openai:connector log only the connector actor\n// DEBUG=openai:* log the openai actor and its subtree\n// DEBUG=openai:connector,openai:tools log connector and tools\n//\n// Usage:\n//\n// import { debugLogger } from 'posipaki/plugins/debug-logger';\n// const MyActor = defineActor({\n// plugins: [debugLogger()],\n// ...\n// });\n//\n// The plugin decorates every actor with `this.log` — a logger instance\n// available in handlers, hooks, and lifecycle methods. By default it\n// writes to `console`, but you can supply a custom factory:\n//\n// import { debugLogger } from 'posipaki/plugins/debug-logger';\n// plugins: [debugLogger({ factory: (name) => myCustomLogger(name) })],\n//\n// Message filtering: pass `ignore` to suppress noisy message types.\n//\n// plugins: [debugLogger({ ignore: ['HEARTBEAT', 'TICK'] })],\n//\n\nimport type { ActorPlugin } from '../hooks.js';\n\n// ── Logger interface ────────────────────────────────────────────────────\n\nexport interface DebugLogFn {\n (message: string, ...args: unknown[]): void;\n}\n\nexport interface Logger {\n debug: DebugLogFn;\n info: DebugLogFn;\n warn: DebugLogFn;\n error: DebugLogFn;\n}\n\n/** Factory: receives an actor name, returns a Logger. */\nexport type LoggerFactory = (name: string) => Logger;\n\n// ── options ─────────────────────────────────────────────────────────────\n\nexport interface DebugLoggerOpts {\n /** Message types to silence (e.g. ['HEARTBEAT', 'TICK']). Default: none. */\n ignore?: string[];\n /** Logger factory. Default: console-based logger. */\n factory?: LoggerFactory;\n}\n\n// ── pattern matching ─────────────────────────────────────────────────────\n\nfunction patterns(): string[] {\n const raw = (process.env.DEBUG ?? '').trim();\n if (!raw) return [];\n return raw\n .split(',')\n .map((p) => p.trim())\n .filter(Boolean);\n}\n\nfunction matches(name: string, pats: string[]): boolean {\n if (pats.length === 0) return false;\n for (const p of pats) {\n if (p === '*') return true;\n if (p.endsWith(':*')) {\n const prefix = p.slice(0, -2);\n if (name === prefix || name.startsWith(prefix + ':')) return true;\n continue;\n }\n if (p === name) return true;\n }\n return false;\n}\n\n// ── default logger ──────────────────────────────────────────────────────\n\nfunction defaultFactory(name: string): Logger {\n return {\n debug: (...args: unknown[]) => console.debug(`[${name}]`, ...args),\n info: (...args: unknown[]) => console.info(`[${name}]`, ...args),\n warn: (...args: unknown[]) => console.warn(`[${name}]`, ...args),\n error: (...args: unknown[]) => console.error(`[${name}]`, ...args),\n };\n}\n\n// ── plugin ───────────────────────────────────────────────────────────────\n\nexport function debugLogger(opts?: DebugLoggerOpts): ActorPlugin {\n const ignoreSet = new Set(opts?.ignore ?? []);\n const factory = opts?.factory ?? defaultFactory;\n\n return {\n name: 'debugLogger',\n install(self) {\n const name: string = self.name;\n const pats = patterns();\n const log = factory(name);\n\n // Always decorate so handlers can use this.log.\n self.decorate('log', log);\n\n // Only register hooks if DEBUG patterns match.\n if (!matches(name, pats)) return;\n\n self.hooks.onMessage((msg: any, sender: any) => {\n if (ignoreSet.has(msg.type)) return;\n const via = sender?.fromName ? ` from ${sender.fromName}` : '';\n log.debug(`${name} ← ${msg.type}${via}`, msg);\n });\n\n self.hooks.onEmit((msg: any) => {\n log.debug(`${name} → ${msg.type}`, msg);\n });\n\n self.hooks.onChildExit((childName: string) => {\n log.debug(`child ${childName} exited`);\n });\n\n self.hooks.onError((err: unknown) => {\n log.error(`${(err as Error).message ?? err}`);\n });\n },\n };\n}\n"],"mappings":";AA4DA,SAAS,WAAqB;CAC5B,MAAM,OAAO,QAAQ,IAAI,SAAS,IAAI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AAa;IAC5D,IAAI,MAAM,GAAG,KAAK,KAAK,IAAI,OAAO,OAAO,GAAG;GAC9C,CAAC;GAED,KAAK,MAAM,QAAQ,QAAa;IAC9B,IAAI,MAAM,GAAG,KAAK,KAAK,IAAI,QAAQ,GAAG;GACxC,CAAC;GAED,KAAK,MAAM,aAAa,cAAsB;IAC5C,IAAI,MAAM,SAAS,UAAU,QAAQ;GACvC,CAAC;GAED,KAAK,MAAM,SAAS,QAAiB;IACnC,IAAI,MAAM,GAAI,IAAc,WAAW,KAAK;GAC9C,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"debug-logger.js","names":[],"sources":["../../src/plugins/debug-logger.ts"],"sourcesContent":["import type { ActorPlugin } from \"../hooks\";\nimport { mergeConfigs } from \"../hooks\";\nimport type { Message } from \"../types\";\n\ndeclare module \"../hooks\" {\n interface ActorDecorated {\n log: Logger;\n }\n}\n\nexport interface DebugLogFn {\n (message: string, ...args: unknown[]): void;\n}\nexport interface Logger {\n debug: DebugLogFn;\n info: DebugLogFn;\n warn: DebugLogFn;\n error: DebugLogFn;\n}\nexport type LoggerFactory = (name: string) => Logger;\nexport interface DebugLoggerOpts {\n ignore?: string[];\n factory?: LoggerFactory;\n}\n\nfunction patterns(): string[] {\n const raw = (process.env.DEBUG ?? \"\").trim();\n if (!raw) return [];\n return raw\n .split(\",\")\n .map((p) => p.trim())\n .filter(Boolean);\n}\nfunction matches(name: string, pats: string[]): boolean {\n if (pats.length === 0) return false;\n for (const p of pats) {\n if (p === \"*\") return true;\n if (p.endsWith(\":*\")) {\n if (name === p.slice(0, -2) || name.startsWith(p.slice(0, -2) + \":\"))\n return true;\n } else if (p === name) return true;\n }\n return false;\n}\nfunction defaultFactory(name: string): Logger {\n return {\n debug: (...a: unknown[]) => console.debug(`[${name}]`, ...a),\n info: (...a: unknown[]) => console.info(`[${name}]`, ...a),\n warn: (...a: unknown[]) => console.warn(`[${name}]`, ...a),\n error: (...a: unknown[]) => console.error(`[${name}]`, ...a),\n };\n}\n\nexport function debugLogger(opts?: DebugLoggerOpts): ActorPlugin {\n const ignoreSet = new Set(opts?.ignore ?? []);\n const factory = opts?.factory ?? defaultFactory;\n return async (config) => {\n const name: string = config.name ?? \"actor\";\n const pats = patterns();\n const log = factory(name);\n\n // Always decorate this.log even when DEBUG is empty\n let result = mergeConfigs(config, {\n methods: { ...config.methods },\n $decorate: { log },\n });\n\n if (matches(name, pats)) {\n result = mergeConfigs(result, {\n onMessage(msg: Message) {\n if (!ignoreSet.has(msg.type)) log.debug(`${name} ← ${msg.type}`, msg);\n },\n onEmit(msg: Message) {\n log.debug(`${name} → ${msg.type}`, msg);\n },\n onChildExit(childName: string) {\n log.debug(`child ${childName} exited`);\n },\n onError(err: unknown) {\n log.error(`${(err as Error).message ?? err}`);\n },\n });\n }\n\n return result;\n };\n}\n"],"mappings":";;AAyBA,SAAS,WAAqB;CAC5B,MAAM,OAAO,QAAQ,IAAI,SAAS,IAAI,KAAK;CAC3C,IAAI,CAAC,KAAK,OAAO,CAAC;CAClB,OAAO,IACJ,MAAM,GAAG,EACT,KAAK,MAAM,EAAE,KAAK,CAAC,EACnB,OAAO,OAAO;AACnB;AACA,SAAS,QAAQ,MAAc,MAAyB;CACtD,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,KAAK,MAAM,KAAK,MAAM;EACpB,IAAI,MAAM,KAAK,OAAO;EACtB,IAAI,EAAE,SAAS,IAAI;OACb,SAAS,EAAE,MAAM,GAAG,EAAE,KAAK,KAAK,WAAW,EAAE,MAAM,GAAG,EAAE,IAAI,GAAG,GACjE,OAAO;EAAA,OACJ,IAAI,MAAM,MAAM,OAAO;CAChC;CACA,OAAO;AACT;AACA,SAAS,eAAe,MAAsB;CAC5C,OAAO;EACL,QAAQ,GAAG,MAAiB,QAAQ,MAAM,IAAI,KAAK,IAAI,GAAG,CAAC;EAC3D,OAAO,GAAG,MAAiB,QAAQ,KAAK,IAAI,KAAK,IAAI,GAAG,CAAC;EACzD,OAAO,GAAG,MAAiB,QAAQ,KAAK,IAAI,KAAK,IAAI,GAAG,CAAC;EACzD,QAAQ,GAAG,MAAiB,QAAQ,MAAM,IAAI,KAAK,IAAI,GAAG,CAAC;CAC7D;AACF;AAEA,SAAgB,YAAY,MAAqC;CAC/D,MAAM,YAAY,IAAI,IAAI,MAAM,UAAU,CAAC,CAAC;CAC5C,MAAM,UAAU,MAAM,WAAW;CACjC,OAAO,OAAO,WAAW;EACvB,MAAM,OAAe,OAAO,QAAQ;EACpC,MAAM,OAAO,SAAS;EACtB,MAAM,MAAM,QAAQ,IAAI;EAGxB,IAAI,SAAS,aAAa,QAAQ;GAChC,SAAS,EAAE,GAAG,OAAO,QAAQ;GAC7B,WAAW,EAAE,IAAI;EACnB,CAAC;EAED,IAAI,QAAQ,MAAM,IAAI,GACpB,SAAS,aAAa,QAAQ;GAC5B,UAAU,KAAc;IACtB,IAAI,CAAC,UAAU,IAAI,IAAI,IAAI,GAAG,IAAI,MAAM,GAAG,KAAK,KAAK,IAAI,QAAQ,GAAG;GACtE;GACA,OAAO,KAAc;IACnB,IAAI,MAAM,GAAG,KAAK,KAAK,IAAI,QAAQ,GAAG;GACxC;GACA,YAAY,WAAmB;IAC7B,IAAI,MAAM,SAAS,UAAU,QAAQ;GACvC;GACA,QAAQ,KAAc;IACpB,IAAI,MAAM,GAAI,IAAc,WAAW,KAAK;GAC9C;EACF,CAAC;EAGH,OAAO;CACT;AACF"}
@@ -0,0 +1,25 @@
1
+ import { d as ActorPlugin } from "../hooks-DCXE8xgc.js";
2
+
3
+ //#region src/plugins/tree-introspection.d.ts
4
+ declare module "../hooks" {
5
+ interface ActorReflection {
6
+ "inspect.getTree": TreeReflectionMethods["inspect.getTree"];
7
+ "inspect.getState": TreeReflectionMethods["inspect.getState"];
8
+ "inspect.stop": TreeReflectionMethods["inspect.stop"];
9
+ }
10
+ }
11
+ interface TreeReflectionMethods {
12
+ "inspect.getTree": (prefix?: string) => TreeNode;
13
+ "inspect.getState": () => unknown;
14
+ "inspect.stop": () => void;
15
+ }
16
+ interface TreeNode {
17
+ pname: string;
18
+ parentName: string | null;
19
+ children: TreeNode[];
20
+ status: "running" | "no introspection";
21
+ }
22
+ declare function inspect(): ActorPlugin;
23
+ //#endregion
24
+ export { TreeNode, inspect };
25
+ //# sourceMappingURL=tree-introspection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-introspection.d.ts","names":[],"sources":["../../src/plugins/tree-introspection.ts"],"mappings":";;;;YAKY,eAAA;IACR,iBAAA,EAAmB,qBAAA;IACnB,kBAAA,EAAoB,qBAAA;IACpB,cAAA,EAAgB,qBAAA;EAAA;AAAA;AAAA,UAIV,qBAAA;EACR,iBAAA,GAAoB,MAAA,cAAoB,QAAQ;EAChD,kBAAA;EACA,cAAA;AAAA;AAAA,UAGe,QAAA;EACf,KAAA;EACA,UAAA;EACA,QAAA,EAAU,QAAQ;EAClB,MAAA;AAAA;AAAA,iBAGc,OAAA,IAAW,WAAW"}
@@ -0,0 +1,44 @@
1
+ import { r as mergeConfigs } from "../hooks-OcDWhAZK.js";
2
+ //#region src/plugins/tree-introspection.ts
3
+ function inspect() {
4
+ return async (config) => {
5
+ return mergeConfigs(config, { $reflectionMethods: {
6
+ ...config.$reflectionMethods,
7
+ "inspect.getTree": function(prefix) {
8
+ const children = [];
9
+ for (const child of Object.values(this.$child)) {
10
+ const cr = child.$reflection;
11
+ if (typeof cr["inspect.getTree"] === "function") {
12
+ const sub = cr["inspect.getTree"](prefix);
13
+ if (!prefix || sub.pname.startsWith(prefix)) children.push(sub);
14
+ } else {
15
+ const n = child.pname;
16
+ if (!prefix || n.startsWith(prefix)) children.push({
17
+ pname: n,
18
+ parentName: this.name,
19
+ children: [],
20
+ status: "no introspection"
21
+ });
22
+ }
23
+ }
24
+ const selfCtx = this.ctx;
25
+ return {
26
+ pname: selfCtx.pname,
27
+ parentName: selfCtx.parentName,
28
+ children,
29
+ status: "running"
30
+ };
31
+ },
32
+ "inspect.getState": function() {
33
+ return this.state;
34
+ },
35
+ "inspect.stop": function() {
36
+ this.exit("inspector");
37
+ }
38
+ } });
39
+ };
40
+ }
41
+ //#endregion
42
+ export { inspect };
43
+
44
+ //# sourceMappingURL=tree-introspection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-introspection.js","names":[],"sources":["../../src/plugins/tree-introspection.ts"],"sourcesContent":["import { mergeConfigs } from \"../hooks.js\";\nimport type { ActorPlugin, ActorReflection as AR } from \"../hooks.js\";\nimport { AnyProcessCtx } from \"../types.js\";\n\ndeclare module \"../hooks\" {\n interface ActorReflection {\n \"inspect.getTree\": TreeReflectionMethods[\"inspect.getTree\"];\n \"inspect.getState\": TreeReflectionMethods[\"inspect.getState\"];\n \"inspect.stop\": TreeReflectionMethods[\"inspect.stop\"];\n }\n}\n\ninterface TreeReflectionMethods {\n \"inspect.getTree\": (prefix?: string) => TreeNode;\n \"inspect.getState\": () => unknown;\n \"inspect.stop\": () => void;\n}\n\nexport interface TreeNode {\n pname: string;\n parentName: string | null;\n children: TreeNode[];\n status: \"running\" | \"no introspection\";\n}\n\nexport function inspect(): ActorPlugin {\n return async (config) => {\n return mergeConfigs(config, {\n $reflectionMethods: {\n ...config.$reflectionMethods,\n \"inspect.getTree\": function (prefix?: string) {\n const children: TreeNode[] = [];\n for (const child of Object.values(this.$child)) {\n const cr = child.$reflection as AR;\n if (typeof cr[\"inspect.getTree\"] === \"function\") {\n const sub = cr[\"inspect.getTree\"](prefix) as TreeNode;\n if (!prefix || sub.pname.startsWith(prefix)) children.push(sub);\n } else {\n const n = child.pname;\n if (!prefix || n.startsWith(prefix))\n children.push({\n pname: n,\n parentName: this.name,\n children: [],\n status: \"no introspection\",\n });\n }\n }\n const selfCtx = this.ctx as AnyProcessCtx;\n return {\n pname: selfCtx.pname,\n parentName: selfCtx.parentName,\n children,\n status: \"running\" as const,\n } satisfies TreeNode;\n },\n \"inspect.getState\": function () {\n const state = this.state as unknown;\n return state;\n },\n \"inspect.stop\": function () {\n this.exit(\"inspector\");\n },\n },\n });\n };\n}\n"],"mappings":";;AAyBA,SAAgB,UAAuB;CACrC,OAAO,OAAO,WAAW;EACvB,OAAO,aAAa,QAAQ,EAC1B,oBAAoB;GAClB,GAAG,OAAO;GACV,mBAAmB,SAAU,QAAiB;IAC5C,MAAM,WAAuB,CAAC;IAC9B,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,MAAM,GAAG;KAC9C,MAAM,KAAK,MAAM;KACjB,IAAI,OAAO,GAAG,uBAAuB,YAAY;MAC/C,MAAM,MAAM,GAAG,mBAAmB,MAAM;MACxC,IAAI,CAAC,UAAU,IAAI,MAAM,WAAW,MAAM,GAAG,SAAS,KAAK,GAAG;KAChE,OAAO;MACL,MAAM,IAAI,MAAM;MAChB,IAAI,CAAC,UAAU,EAAE,WAAW,MAAM,GAChC,SAAS,KAAK;OACZ,OAAO;OACP,YAAY,KAAK;OACjB,UAAU,CAAC;OACX,QAAQ;MACV,CAAC;KACL;IACF;IACA,MAAM,UAAU,KAAK;IACrB,OAAO;KACL,OAAO,QAAQ;KACf,YAAY,QAAQ;KACpB;KACA,QAAQ;IACV;GACF;GACA,oBAAoB,WAAY;IAE9B,OADc,KAAK;GAErB;GACA,gBAAgB,WAAY;IAC1B,KAAK,KAAK,WAAW;GACvB;EACF,EACF,CAAC;CACH;AACF"}
@@ -1,4 +1,4 @@
1
- import { d as WithSender, n as ExitMessage, o as ProcessFn, p as AsyncProcess, r as Message } from "./types-BLIFntvm.js";
1
+ import { f as WithSender, h as AsyncProcess, i as Message, r as ExitMessage, s as ProcessFn } from "./types-BUPRp3t_.js";
2
2
 
3
3
  //#region src/util.d.ts
4
4
  type ReducerClosure<M> = (msg: M) => void;
@@ -23,11 +23,11 @@ declare function runDispatch<M>(name: string, fn: ReducerClosure<M>, readyFn?: R
23
23
  declare function spawn<A, S, IM extends Message = Message, OM extends Message = ExitMessage>(fn: ProcessFn<A, S, IM, OM>, pname: string, tp?: (m: WithSender<OM>) => void): (a: A) => Process<A, S, IM, OM>;
24
24
  /** @deprecated Use {@link AsyncProcess} instead. Sync processes are
25
25
  * wrapped via asyncify internally; spawnAsync handles both. */
26
- declare class Process<A, S, IM extends Message, OM extends Message> extends AsyncProcess<A, S, IM, OM> {
26
+ declare class Process<A, S, IM extends Message, OM extends Message> extends AsyncProcess<A, S, IM, OM, {}> {
27
27
  constructor(fn: ProcessFn<A, S, IM, OM>, pname: string, tp?: (m: WithSender<OM>) => void);
28
28
  start(a: A): this;
29
29
  tick(): Promise<void>;
30
30
  }
31
31
  //#endregion
32
32
  export { spawn as n, runDispatch as r, Process as t };
33
- //# sourceMappingURL=process-Bf9HTr0m.d.ts.map
33
+ //# sourceMappingURL=process-B7rh_NBl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"process-Bf9HTr0m.d.ts","names":["level","args","Array","M","msg","name","ReducerClosure","fn","ReadyFn","readyFn","debugLevel","Generator","A","S","IM","type","OM","ExitMessage","toAllChildren","m","toParent","id","pname","proc","ctx","gen","cancel","flush","DeferCb","DeferredCall","promise","Promise","resolve","NotifyFn","Waiter"],"sources":["../src/util.d.ts","../src/process.ts"],"mappings":";;;KAEK,cAAA,OAAqBI,GAAAA,EAAK,CAAC;AAAA,KAC3B,OAAA;;;;;;iBAOY,WAAA,IAAeC,IAAAA,UAAcE,EAAAA,EAAI,cAAA,CAAe,CAAA,GAAIE,OAAAA,GAAU,OAAA,EAASC,UAAAA,aAAuB,SAAA,aAAsB,CAAA;AARrG;AAAA;;;;AACpB;AACC;;;;;iBCIG,KAAA,kBAGH,OAAA,GAAU,OAAA,aACV,OAAA,GAAU,WAAA,EAErB,EAAA,EAAI,SAAA,CAAU,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA,GACxB,KAAA,UACA,EAAA,IAAM,CAAA,EAAG,UAAA,CAAW,EAAA,cAClB,CAAA,EAAG,CAAA,KAAM,OAAA,CAAQ,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA;;;cAMzB,OAAA,kBAGO,OAAA,aACA,OAAA,UACH,YAAA,CAAa,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA;cAE7B,EAAA,EAAI,SAAA,CAAU,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA,GACxB,KAAA,UACA,EAAA,IAAM,CAAA,EAAG,UAAA,CAAW,EAAA;EAKtB,KAAA,CAAM,CAAA,EAAG,CAAA;EAIT,IAAA,IAAQ,OAAA;AAAA"}
1
+ {"version":3,"file":"process-B7rh_NBl.d.ts","names":["level","args","Array","M","msg","name","ReducerClosure","fn","ReadyFn","readyFn","debugLevel","Generator","A","S","IM","type","OM","ExitMessage","toAllChildren","m","toParent","id","pname","proc","ctx","gen","cancel","flush","DeferCb","DeferredCall","promise","Promise","resolve","NotifyFn","Waiter"],"sources":["../src/util.d.ts","../src/process.ts"],"mappings":";;;KAEK,cAAA,OAAqBI,GAAAA,EAAK,CAAC;AAAA,KAC3B,OAAA;;;;;;iBAOY,WAAA,IAAeC,IAAAA,UAAcE,EAAAA,EAAI,cAAA,CAAe,CAAA,GAAIE,OAAAA,GAAU,OAAA,EAASC,UAAAA,aAAuB,SAAA,aAAsB,CAAA;AARrG;AAAA;;;;AACpB;AACC;;;;;iBCIG,KAAA,kBAGH,OAAA,GAAU,OAAA,aACV,OAAA,GAAU,WAAA,EAErB,EAAA,EAAI,SAAA,CAAU,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA,GACxB,KAAA,UACA,EAAA,IAAM,CAAA,EAAG,UAAA,CAAW,EAAA,cAClB,CAAA,EAAG,CAAA,KAAM,OAAA,CAAQ,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA;;;cAMzB,OAAA,kBAGO,OAAA,aACA,OAAA,UACH,YAAA,CAAa,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA;cAE7B,EAAA,EAAI,SAAA,CAAU,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA,GACxB,KAAA,UACA,EAAA,IAAM,CAAA,EAAG,UAAA,CAAW,EAAA;EAKtB,KAAA,CAAM,CAAA,EAAG,CAAA;EAIT,IAAA,IAAQ,OAAA;AAAA"}