@pogodisco/zephyr 1.3.12 → 1.3.14

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.
@@ -1,13 +1,14 @@
1
1
  import { ActionRegistry, MergeActionRegistries } from "./types.js";
2
- export declare class ActionRegistryBuilder<R extends ActionRegistry = {}> {
2
+ export declare class ActionRegistryBuilder<R extends ActionRegistry = {}, Prefix extends string = ""> {
3
+ private prefix;
3
4
  private registry;
4
- constructor(initial?: R);
5
+ constructor(prefix: Prefix, initial?: R);
5
6
  /**
6
7
  * Accepts ANY function - sync or async, any parameter shape
7
8
  * F captures the complete function signature for full type inference
8
9
  */
9
- action<K extends string, F extends (...args: any[]) => any>(key: K, action: F): ActionRegistryBuilder<MergeActionRegistries<R, Record<K, F>>>;
10
- extend<Other extends ActionRegistry>(other: ActionRegistryBuilder<Other> | Other): ActionRegistryBuilder<MergeActionRegistries<R, Other>>;
10
+ action<K extends string, F extends (...args: any[]) => any>(key: K, action: F): ActionRegistryBuilder<MergeActionRegistries<R, Record<`${Prefix}${K}`, F>>, Prefix>;
11
+ extend<Other extends ActionRegistry>(other: ActionRegistryBuilder<Other, any> | Other): ActionRegistryBuilder<MergeActionRegistries<R, Other>, Prefix>;
11
12
  build(): R;
12
13
  }
13
- export declare function createActionRegistry<R extends ActionRegistry = {}>(initial?: R): ActionRegistryBuilder<R>;
14
+ export declare function createActionRegistry<R extends ActionRegistry = {}, Prefix extends string = "">(prefix: Prefix, initial?: R): ActionRegistryBuilder<R, Prefix>;
package/dist/registry.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export class ActionRegistryBuilder {
2
- constructor(initial) {
2
+ constructor(prefix, initial) {
3
+ this.prefix = prefix;
3
4
  this.registry = {};
4
5
  if (initial) {
5
6
  this.registry = { ...initial };
@@ -10,12 +11,21 @@ export class ActionRegistryBuilder {
10
11
  * F captures the complete function signature for full type inference
11
12
  */
12
13
  action(key, action) {
13
- this.registry[key] = action;
14
+ const fullKey = `${this.prefix}${key}`;
15
+ if (fullKey in this.registry) {
16
+ throw new Error(`Action "${fullKey}" already exists`);
17
+ }
18
+ this.registry[fullKey] = action;
14
19
  return this;
15
20
  }
16
21
  // Extend with another registry (with override)
17
22
  extend(other) {
18
23
  const otherRegistry = other instanceof ActionRegistryBuilder ? other.build() : other;
24
+ for (const key in otherRegistry) {
25
+ if (key in this.registry) {
26
+ throw new Error(`Action collision detected "${key}"`);
27
+ }
28
+ }
19
29
  Object.assign(this.registry, otherRegistry);
20
30
  return this;
21
31
  }
@@ -23,6 +33,9 @@ export class ActionRegistryBuilder {
23
33
  return this.registry;
24
34
  }
25
35
  }
26
- export function createActionRegistry(initial) {
27
- return new ActionRegistryBuilder(initial);
36
+ export function createActionRegistry(prefix, initial) {
37
+ if (!prefix || typeof prefix !== "string" || prefix?.trim() === "") {
38
+ throw new Error(`Registry prefix is required`);
39
+ }
40
+ return new ActionRegistryBuilder(prefix, initial);
28
41
  }
package/dist/session.d.ts CHANGED
@@ -1,25 +1,20 @@
1
1
  import { ActionRegistry, WorkflowObserver } from "./types.js";
2
- import { WorkflowDef } from "./workflow-composer.js";
3
- type ModuleFlows<Reg extends ActionRegistry> = Record<string, WorkflowDef<Reg, any, any>>;
4
- export declare class WorkflowSession<Reg extends ActionRegistry, State extends Record<string, any>> {
5
- private registry;
2
+ export declare class WorkflowSession<Reg extends ActionRegistry, Ctx> {
3
+ runtime: {
4
+ run: any;
5
+ getContext: () => Ctx;
6
+ };
6
7
  private subscribers;
7
8
  private running;
8
9
  private queue;
9
- state: State;
10
10
  observers: WorkflowObserver[];
11
- private moduleFlows;
12
- /**
13
- * @param baseModule Module to extend (inherits workflows)
14
- * @param registry Action registry
15
- * @param initialContext Initial context (session state) will be mutated in workflows
16
- */
17
- constructor(baseModule: ModuleFlows<Reg>, registry: Reg, initialContext: State, observers: WorkflowObserver[]);
18
- getState(): State;
19
- subscribe(fn: (state: Partial<State>) => void): () => boolean;
11
+ constructor(runtime: {
12
+ run: any;
13
+ getContext: () => Ctx;
14
+ });
15
+ subscribe(fn: (state: Partial<Ctx>) => void): () => boolean;
20
16
  private notify;
21
17
  /** Queue a workflow execution by key and input; state/context is automatically updated */
22
- dispatch(key: keyof ModuleFlows<Reg>, input?: any): void;
18
+ dispatch(workflow: any, input: any): void;
23
19
  private processQueue;
24
20
  }
25
- export {};
package/dist/session.js CHANGED
@@ -1,56 +1,32 @@
1
- import { executeWorkflow } from "./workflow-executor.js";
2
- import { createModule } from "./workflow-module.js";
3
1
  export class WorkflowSession {
4
- /**
5
- * @param baseModule Module to extend (inherits workflows)
6
- * @param registry Action registry
7
- * @param initialContext Initial context (session state) — will be mutated in workflows
8
- */
9
- constructor(baseModule, registry, initialContext, observers) {
10
- this.registry = registry;
2
+ constructor(runtime) {
3
+ this.runtime = runtime;
11
4
  this.subscribers = new Set();
12
5
  this.running = false;
13
6
  this.queue = [];
7
+ // public state: State; // session state & workflow context are the same object
14
8
  this.observers = [];
15
- // Use the same object for session state and module context
16
- this.state = initialContext;
17
- this.observers = observers;
18
- // Per-session module: inherits workflows, shares the same state/context object
19
- this.moduleFlows = createModule({
20
- registry: this.registry,
21
- context: this.state,
22
- use: [baseModule],
23
- define: () => ({}), // no new flows needed
24
- });
25
- }
26
- getState() {
27
- return this.state;
28
9
  }
29
10
  subscribe(fn) {
30
11
  this.subscribers.add(fn);
31
- fn(this.state); // immediately notify
12
+ fn(this.runtime.getContext()); // immediately notify
32
13
  return () => this.subscribers.delete(fn);
33
14
  }
34
15
  notify() {
35
16
  for (const fn of this.subscribers)
36
- fn(this.state);
17
+ fn(this.runtime.getContext());
37
18
  }
38
19
  /** Queue a workflow execution by key and input; state/context is automatically updated */
39
- dispatch(key, input = {}) {
40
- this.queue.push({ key, input });
20
+ dispatch(workflow, input) {
21
+ this.queue.push({ workflow, input });
41
22
  if (!this.running)
42
23
  this.processQueue();
43
24
  }
44
25
  async processQueue() {
45
26
  this.running = true;
46
27
  while (this.queue.length) {
47
- const { key, input } = this.queue.shift();
48
- const workflow = this.moduleFlows[key];
49
- if (!workflow)
50
- throw new Error(`Workflow ${String(key)} not found`);
51
- // state/context already lives on the module; no need to pass a separate context
52
- await executeWorkflow(workflow, this.registry, input, this.observers);
53
- // Notify subscribers after workflow mutates state
28
+ const { workflow, input } = this.queue.shift();
29
+ await this.runtime.run(workflow, input);
54
30
  this.notify();
55
31
  }
56
32
  this.running = false;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { createWorkflow } from "./workflow-composer.js";
2
1
  export type Action<F extends (...args: any[]) => any = (...args: any[]) => any> = F;
3
2
  export type ActionRegistry = Record<string, (...args: any[]) => any>;
4
3
  export type MergeActionRegistries<A extends ActionRegistry, B extends ActionRegistry> = Simplify<Omit<A, keyof B> & B>;
@@ -27,4 +26,3 @@ export type WorkflowObserver<Reg extends ActionRegistry = any> = {
27
26
  frame: ExecutionFrame;
28
27
  }, next: () => Promise<any>): Promise<any>;
29
28
  };
30
- export type WF<Reg extends ActionRegistry, Context extends Record<string, any>> = ReturnType<typeof createWorkflow<Reg, Context>>;
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { ActionRegistry } from "./types.js";
2
- import { WorkflowDef } from "./workflow-composer.js";
3
1
  type AnyFn = (...args: any[]) => any;
4
2
  /**
5
3
  * For generic actions - preserves the generic parameter
@@ -9,20 +7,4 @@ export declare function genericAction<F extends AnyFn>(fn: F): <T>() => ((...arg
9
7
  * For fixed actions
10
8
  */
11
9
  export declare function fixedAction<F extends AnyFn>(fn: F): () => ((...args: Parameters<F>) => ReturnType<F>);
12
- export declare function createRunner<Reg extends ActionRegistry>(registry: Reg): <W extends WorkflowDef<Reg, any, any, any, any>>(workflow: W, input: W extends WorkflowDef<Reg, infer I, any, any, any> ? I : never, observers?: any[]) => Promise<{
13
- output: W extends WorkflowDef<Reg, any, any, any, infer O> ? O : never;
14
- results: W extends WorkflowDef<Reg, any, infer R, any, any> ? R : never;
15
- extras: Record<string, any>;
16
- }>;
17
- /**
18
- * Create a typed runner for a specific module
19
- * @example
20
- * const run = createModuleRunner(modWithLoop, regOne);
21
- * const result = await run("loopWorkflow", { items: ["APPLE"] });
22
- */
23
- export declare function createModuleRunner<M extends Record<string, WorkflowDef<any, any, any, any, any>>, Reg extends ActionRegistry>(module: M, registry: Reg): <K extends keyof M>(key: K, input: M[K] extends WorkflowDef<Reg, infer I, any, any, any> ? I : never, observers?: any[]) => Promise<{
24
- output: M[K] extends WorkflowDef<Reg, any, any, any, infer O> ? O : never;
25
- results: M[K] extends WorkflowDef<Reg, any, infer R, any, any> ? R : never;
26
- extras: Record<string, any>;
27
- }>;
28
10
  export {};
package/dist/utils.js CHANGED
@@ -1,4 +1,3 @@
1
- import { executeWorkflow } from "./workflow-executor.js";
2
1
  /**
3
2
  * For generic actions - preserves the generic parameter
4
3
  */
@@ -16,20 +15,21 @@ export function fixedAction(fn) {
16
15
  return fn;
17
16
  };
18
17
  }
19
- export function createRunner(registry) {
20
- return async (workflow, input, observers) => {
21
- return executeWorkflow(workflow, registry, input, observers ?? []);
22
- };
23
- }
24
- /**
25
- * Create a typed runner for a specific module
26
- * @example
27
- * const run = createModuleRunner(modWithLoop, regOne);
28
- * const result = await run("loopWorkflow", { items: ["APPLE"] });
29
- */
30
- export function createModuleRunner(module, registry) {
31
- return async (key, input, observers) => {
32
- const workflow = module[key];
33
- return executeWorkflow(workflow, registry, input, observers ?? []);
34
- };
35
- }
18
+ // export function createRuntime<Reg extends ActionRegistry, Context>(
19
+ // registry: Reg,
20
+ // context: Context,
21
+ // ) {
22
+ // return {
23
+ // run: async <W extends WorkflowDef<Reg, any, any, any, any>>(
24
+ // workflow: W,
25
+ // input: W extends WorkflowDef<Reg, infer I, any, any, any> ? I : never,
26
+ // observers?: WorkflowObserver[],
27
+ // ): Promise<{
28
+ // output: W extends WorkflowDef<Reg, any, any, any, infer O> ? O : never;
29
+ // results: W extends WorkflowDef<Reg, any, infer R, any, any> ? R : never;
30
+ // extras: Record<string, any>;
31
+ // }> => {
32
+ // return executeWorkflow(workflow, registry, input, context, observers);
33
+ // },
34
+ // };
35
+ // }
@@ -58,7 +58,6 @@ export type WorkflowDef<Reg extends ActionRegistry, Input, Results, Steps extend
58
58
  input: Input;
59
59
  results: Results;
60
60
  outputResolver?: (ctx: any) => Output;
61
- __context?: any;
62
61
  };
63
62
  type StepRuntimeCtx<I, R, C> = {
64
63
  input: I;
@@ -79,16 +78,14 @@ type MergeBranchSteps<Branches extends readonly any[], Acc extends any[]> = Bran
79
78
  ...Acc,
80
79
  ...(Head extends WorkflowBuilder<any, any, any, infer S, any> ? S : [])
81
80
  ]> : Acc;
82
- export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown, Context extends Record<string, any> = {}, Steps extends StepDef<Reg, any, any>[] = [], Results = {}, Output = undefined> {
81
+ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown, Context = unknown, Steps extends StepDef<Reg, any, any>[] = [], Results = {}, Output = undefined> {
83
82
  private name;
84
- private registry;
85
- private context;
86
83
  private steps;
87
84
  private frontier;
88
85
  private pendingWhen?;
89
86
  private outputResolver?;
90
87
  private clearPendingWhen;
91
- constructor(name: string, registry: Reg, context: Context);
88
+ constructor(name: string);
92
89
  step<ID extends string, ActionName extends keyof Reg & string, ResolveOut extends ResolvedStepInput = ResolvedStepInput>(id: ID, action: ActionName, resolve?: (ctx: {
93
90
  input: Input;
94
91
  results: Results;
@@ -144,5 +141,5 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
144
141
  private validateDependencies;
145
142
  private getEndSteps;
146
143
  }
147
- export declare function createWorkflow<Reg extends ActionRegistry, Context extends Record<string, any> = {}>(registry: Reg, context?: Context): <Input = unknown>(name: string) => WorkflowBuilder<Reg, Input, Context, [], {}, undefined>;
144
+ export declare function createWorkflow<Reg extends ActionRegistry, Context extends Record<string, any> = {}>(): <Input = unknown>(name: string) => WorkflowBuilder<Reg, Input, Context, [], {}, undefined>;
148
145
  export {};
@@ -5,10 +5,8 @@ export class WorkflowBuilder {
5
5
  clearPendingWhen() {
6
6
  this.pendingWhen = undefined;
7
7
  }
8
- constructor(name, registry, context) {
8
+ constructor(name) {
9
9
  this.name = name;
10
- this.registry = registry;
11
- this.context = context;
12
10
  this.steps = [];
13
11
  this.frontier = [];
14
12
  }
@@ -37,64 +35,11 @@ export class WorkflowBuilder {
37
35
  as() {
38
36
  return this;
39
37
  }
40
- // parallel<Branches extends WorkflowBuilder<Reg, Input, Context, any, any>[]>(
41
- // ...branches: {
42
- // [K in keyof Branches]: (
43
- // builder: WorkflowBuilder<Reg, Input, Context, [], Results>,
44
- // ) => Branches[K];
45
- // }
46
- // ): WorkflowBuilder<
47
- // Reg,
48
- // Input,
49
- // Context,
50
- // [
51
- // ...Steps,
52
- // ...(Branches[number] extends WorkflowBuilder<Reg, any, any, infer S, any>
53
- // ? S
54
- // : never),
55
- // ],
56
- // Simplify<
57
- // Results &
58
- // UnionToIntersection<
59
- // {
60
- // [K in keyof Branches]: Branches[K] extends WorkflowBuilder<
61
- // Reg,
62
- // any,
63
- // any,
64
- // any,
65
- // infer R
66
- // >
67
- // ? R
68
- // : never;
69
- // }[number]
70
- // >
71
- // >
72
- // > {
73
- // const parentFrontier = [...this.frontier];
74
- // const branchEnds: string[] = [];
75
- //
76
- // branches.forEach((branch) => {
77
- // const b = new WorkflowBuilder<Reg, Input, Context, [], Results>(
78
- // this.name,
79
- // this.registry,
80
- // this.context,
81
- // );
82
- //
83
- // b.frontier = parentFrontier;
84
- // branch(b);
85
- // branchEnds.push(...b.frontier);
86
- // this.steps.push(...(b as any).steps);
87
- // });
88
- //
89
- // this.frontier = branchEnds;
90
- // this.clearPendingWhen();
91
- // return this as any;
92
- // }
93
38
  parallel(...branches) {
94
39
  const parentFrontier = [...this.frontier];
95
40
  const branchEnds = [];
96
41
  branches.forEach((branch) => {
97
- const b = new WorkflowBuilder(this.name, this.registry, this.context);
42
+ const b = new WorkflowBuilder(this.name);
98
43
  b.frontier = parentFrontier;
99
44
  branch(b);
100
45
  branchEnds.push(...b.frontier);
@@ -170,7 +115,6 @@ export class WorkflowBuilder {
170
115
  input: {},
171
116
  results: {},
172
117
  outputResolver: this.outputResolver,
173
- __context: this.context,
174
118
  };
175
119
  }
176
120
  validateDependencies() {
@@ -194,8 +138,16 @@ export class WorkflowBuilder {
194
138
  /* ------------------------------------------------ */
195
139
  /* WORKFLOW CREATOR */
196
140
  /* ------------------------------------------------ */
197
- export function createWorkflow(registry, context) {
141
+ // export function createWorkflow<
142
+ // Reg extends ActionRegistry,
143
+ // Context extends Record<string, any> = {},
144
+ // >(registry: Reg, context?: Context) {
145
+ // return function workflow<Input = unknown>(name: string) {
146
+ // return new WorkflowBuilder<Reg, Input, Context>(name);
147
+ // };
148
+ // }
149
+ export function createWorkflow() {
198
150
  return function workflow(name) {
199
- return new WorkflowBuilder(name, registry, context || {});
151
+ return new WorkflowBuilder(name);
200
152
  };
201
153
  }
@@ -1,6 +1,6 @@
1
1
  import { ActionRegistry, WorkflowObserver } from "./types.js";
2
2
  import { StepDef, WorkflowDef } from "./workflow-composer.js";
3
- export declare function executeWorkflow<Reg extends ActionRegistry, I, R, O = R, Steps extends StepDef<Reg, any, any>[] = StepDef<Reg, any, any>[]>(workflow: WorkflowDef<Reg, I, R, Steps, O>, registry: Reg, input: I, observers?: WorkflowObserver<Reg>[]): Promise<{
3
+ export declare function executeWorkflow<Reg extends ActionRegistry, I, R, O = R, Steps extends StepDef<Reg, any, any>[] = StepDef<Reg, any, any>[]>(workflow: WorkflowDef<Reg, I, R, Steps, O>, registry: Reg, input: I, context: any, observers?: WorkflowObserver<Reg>[]): Promise<{
4
4
  results: R;
5
5
  output: O;
6
6
  extras: Record<string, any>;
@@ -39,7 +39,7 @@ async function runWithRetry(actionFn, stepOptions) {
39
39
  }
40
40
  throw lastError;
41
41
  }
42
- export async function executeWorkflow(workflow, registry, input, observers = []) {
42
+ export async function executeWorkflow(workflow, registry, input, context, observers = []) {
43
43
  const results = {};
44
44
  const extras = {};
45
45
  extras.frames = {};
@@ -93,7 +93,6 @@ export async function executeWorkflow(workflow, registry, input, observers = [])
93
93
  start: Date.now(),
94
94
  };
95
95
  extras.frames[stepId] = frame;
96
- const context = workflow.__context;
97
96
  const ctx = {
98
97
  stepId,
99
98
  input,
@@ -1,10 +1,34 @@
1
- import { ActionRegistry, Simplify } from "./types.js";
1
+ import { ActionRegistry, WorkflowObserver } from "./types.js";
2
2
  import { createWorkflow, WorkflowDef } from "./workflow-composer.js";
3
3
  type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
4
+ type WorkflowFromDeps<Deps extends Record<string, any>> = {
5
+ [K in keyof Deps]: Deps[K] extends Module<any, any, infer Own, infer SubDeps> ? Own[keyof Own] | WorkflowFromDeps<SubDeps> : never;
6
+ }[keyof Deps];
4
7
  type ModuleShape = Record<string, AnyWorkflow>;
5
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
6
- type UnionToIntersectionOrEmpty<U> = [U] extends [never] ? {} : UnionToIntersection<U>;
7
- export type ModuleContext<Reg extends ActionRegistry, Context extends Record<string, any>, Deps extends ModuleShape> = {
8
+ type ContextFromDeps<Deps> = [keyof Deps] extends [never] ? {} : {
9
+ [K in keyof Deps]: Deps[K] extends Module<any, infer Ctx, any, any> ? Ctx : never;
10
+ }[keyof Deps];
11
+ type FinalContext<Reg extends ActionRegistry, Context extends Record<string, any>, Deps extends ModuleMap<Reg>> = Context & ContextFromDeps<Deps>;
12
+ type ModuleMap<Reg extends ActionRegistry> = Record<string, Module<Reg, any, any, any>>;
13
+ export type WorkflowInput<W> = W extends WorkflowDef<any, infer I, any, any, any> ? I : never;
14
+ export type WorkflowResults<W> = W extends WorkflowDef<any, any, infer R, any, any> ? R : never;
15
+ export type WorkflowOutput<W> = W extends WorkflowDef<any, any, any, any, infer O> ? O : never;
16
+ type Module<Reg extends ActionRegistry, Context extends Record<string, any>, Own extends ModuleShape = {}, Deps extends ModuleMap<Reg> = {}> = {
17
+ own: Own;
18
+ deps: Deps;
19
+ createRuntime: (config: {
20
+ registry: Reg;
21
+ context: FinalContext<Reg, Context, Deps>;
22
+ }) => {
23
+ run: <W extends Own[keyof Own] | WorkflowFromDeps<Deps>>(workflow: W, input: WorkflowInput<W>, obververs?: WorkflowObserver<Reg>[]) => Promise<{
24
+ results: WorkflowResults<W>;
25
+ output: WorkflowOutput<W>;
26
+ extras: Record<string, any>;
27
+ }>;
28
+ getContext: () => FinalContext<Reg, Context, Deps>;
29
+ };
30
+ };
31
+ export type ModuleContext<Reg extends ActionRegistry, Context extends Record<string, any>, Deps extends ModuleMap<Reg>> = {
8
32
  wf: ReturnType<typeof createWorkflow<Reg, Context>>;
9
33
  deps: Deps;
10
34
  context: Context;
@@ -14,12 +38,8 @@ export type ModuleContext<Reg extends ActionRegistry, Context extends Record<str
14
38
  context: Context;
15
39
  }) => T) => T;
16
40
  };
17
- export declare function createModule<Reg extends ActionRegistry, Context extends Record<string, any>, Use extends ModuleShape[] = [], Deps extends ModuleShape = Simplify<{
18
- [K in keyof UnionToIntersectionOrEmpty<Use[number]>]: AnyWorkflow;
19
- }>, Own extends ModuleShape = {}>({ registry, context, use, define, }: {
20
- registry: Reg;
21
- context: Context;
22
- use?: [...Use];
23
- define: (ctx: ModuleContext<Reg, Context, Deps>) => Own;
24
- }): Deps & Own;
41
+ export declare function createModuleFactory<Reg extends ActionRegistry, Context extends Record<string, any>>(): <Use extends ModuleMap<Reg> = {}, Own extends ModuleShape = {}>(config: {
42
+ use?: Use;
43
+ define: (ctx: ModuleContext<Reg, Context, Use>) => Own;
44
+ }) => Module<Reg, Context, Own, Use>;
25
45
  export {};
@@ -1,30 +1,35 @@
1
- import { createWorkflow, } from "./workflow-composer.js";
2
- function mergeModules(mods) {
3
- const seen = new Set();
4
- const result = {};
5
- for (const mod of mods) {
6
- for (const key in mod) {
7
- if (!seen.has(key)) {
8
- seen.add(key);
9
- result[key] = mod[key];
10
- }
11
- }
12
- }
13
- return result;
14
- }
15
- export function createModule({ registry, context, use, define, }) {
16
- const wf = createWorkflow(registry, context);
17
- // const deps = (use ? Object.assign({}, ...use) : {}) as Deps;
18
- const deps = (use ? mergeModules(use) : {});
1
+ import { createWorkflow } from "./workflow-composer.js";
2
+ import { executeWorkflow } from "./workflow-executor.js";
3
+ function createModule(config) {
4
+ const wf = createWorkflow();
5
+ const deps = (config.use ?? {});
19
6
  const moduleCtx = {
20
7
  wf,
21
8
  deps,
22
- context,
23
- tools: (factory) => factory({ wf, deps, context }),
9
+ context: {},
10
+ tools: (factory) => factory({
11
+ wf,
12
+ deps,
13
+ context: {},
14
+ }),
24
15
  };
25
- const own = define(moduleCtx);
16
+ const own = config.define(moduleCtx);
26
17
  return {
27
- ...deps,
28
- ...own,
18
+ own,
19
+ deps,
20
+ createRuntime({ registry, context }) {
21
+ const runtimeCtx = { ...context };
22
+ return {
23
+ run: async (workflow, input, observers = []) => {
24
+ return executeWorkflow(workflow, registry, input, context, observers);
25
+ },
26
+ getContext: () => ({ ...runtimeCtx }),
27
+ };
28
+ },
29
+ };
30
+ }
31
+ export function createModuleFactory() {
32
+ return function (config) {
33
+ return createModule(config);
29
34
  };
30
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pogodisco/zephyr",
3
- "version": "1.3.12",
3
+ "version": "1.3.14",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },