@theokit/di-agent 0.2.0 → 0.4.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.
package/CHANGELOG.md CHANGED
@@ -1,16 +1,39 @@
1
1
  # Changelog
2
2
 
3
- ## 0.2.0
3
+ ## 0.4.0
4
4
 
5
5
  ### Minor Changes
6
6
 
7
- - 461c020: Decorator-driven agent-team + workflow authoring (own identity — composition over a new engine).
7
+ - 33670b7: Realign the `@theokit/sdk` peer with the SDK this package actually imports.
8
8
 
9
- - **`@Squad(metadata)`** property decorator + `readSquadMetadata` — declarative sequential agent team backed by `@theokit/di` `METADATA_KEYS.SQUAD`. Cross-validation Gap 1.
10
- - **`@Step(metadata?)`** method decorator + `readStepMetadata` (`{ after?, name? }`) backed by `METADATA_KEYS.STEP`.
11
- - **`buildWorkflow(instance)`** — compiles a class decorated with `@Step` into a `@theokit/sdk` `Workflow` (topological order by `after`; validates no-steps / unknown-after / cycle). No new runtime engine — composes `@theokit/sdk/workflow`. Cross-validation Gap 2.
9
+ **Install-contract break.** `@theokit/sdk` moves from `^1.3.0` to `>=4.0.1 <5`. An app pinned below
10
+ 4 stops satisfying the peer. Minor bump because the version is still 0.x, where minor is the
11
+ breaking slot.
12
12
 
13
- First npm publish of these decorators (`0.1.0` on npm is the scaffold).
13
+ The old range described nothing that existed. `src/workflow-builder.ts` imports
14
+ `@theokit/sdk/workflow` at runtime, the package is developed and tested against the modern SDK, and
15
+ the published SDK has been on 4.x for months — so `npm i @theokit/di-agent @theokit/sdk@^4` ended in
16
+ `ERESOLVE`, and pnpm users got a peer warning for a combination that was never supported.
17
+ (usetheokit/theokit-di#40)
18
+
19
+ Verified at both ends of the new range: the suite passes against 4.0.1 and against 4.57.0. The
20
+ `@theokit/sdk` devDependency moves to `^4.57.0` for the same reason the range went stale unnoticed —
21
+ CI was resolving 1.x, compiling against it, and going green on a combination no consumer installs.
22
+
23
+ ### Patch Changes
24
+
25
+ - 5bb0600: O peer range do `@theokit/di` deixa de prometer uma versão em que o pacote não funciona.
26
+
27
+ Declarava `^0.1.0-next.0 || ^0.2.0`, e o piso resolvível disso é `0.1.0` — que **não exporta
28
+ `METADATA_KEYS`**, um símbolo que `src/` importa. Um consumidor que resolvesse para 0.1.0 instalava
29
+ sem erro e partia nos decorators.
30
+
31
+ Medido antes de escrever o novo range, versão a versão: `0.1.0` não tem o símbolo, `0.1.1` tem,
32
+ `0.2.0` tem. O range passa a ser `>=0.1.1 <0.3`, que é o que a suíte prova.
33
+
34
+ Encontrado pelo leg `suite at the bottom of every declared range` do dep-check, que instala o piso
35
+ de cada range declarado e corre os testes contra ele — 31 falharam. É a única forma de um piso
36
+ mentiroso aparecer: nada mais no CI instala a versão mínima.
14
37
 
15
38
  All notable changes to `@theokit/di-agent` are documented in this file.
16
39
 
@@ -19,10 +42,50 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
42
 
20
43
  ## [Unreleased]
21
44
 
45
+ ### Fixed
46
+
47
+ - Installing this package next to the `@theokit/sdk` it actually needs no longer fails. The declared
48
+ peer range was `^1.3.0` while the package imports `@theokit/sdk/workflow` at runtime and the SDK
49
+ has been on 4.x for months, so `npm i @theokit/di-agent @theokit/sdk@^4` ended in `ERESOLVE` and
50
+ pnpm users got a peer warning for a combination that was never supported. The range is now
51
+ `>=4.0.1 <5`, verified at both ends: the suite passes against 4.0.1 and against 4.57.0. (#40)
52
+
53
+ ## [0.3.0] - 2026-08-21
54
+
22
55
  ### Added
23
56
 
24
- - `@Squad({ agents, process? })` property decorator + `readSquadMetadata()` — the decorator surface for `@theokit/sdk` `createSquad` (decorator mandate). Stores team metadata via reflect-metadata, mirroring `@SubAgent`.
25
- - `@Step({ after?, name? })` method decorator + `readStepMetadata()` + `buildWorkflow(instance)` — decorator-driven workflow authoring. `@Step` declares steps + a single upstream dependency; `buildWorkflow` compiles the decorated class into a `@theokit/sdk` `Workflow` (composition — no new engine), topologically ordering steps and threading each return value to the next. Fail-fast on no steps / unknown `after` / cycle.
57
+ - Every published export now carries documentation an editor can show. Measured on the emitted
58
+ declarations, 16/56 to 56/56. Each decorator now states the thing a reader cannot infer from its
59
+ signature: this package records metadata and nothing here acts on it — the runtime that
60
+ does lives in `@theokit/sdk`. (#24)
61
+
62
+ - npm provenance is enabled again. It was switched off because npm refuses attestation for packages built from a private source repository; this one is public now, so published tarballs carry a sigstore attestation linking them to the commit and workflow that produced them.
63
+ - `DecoratedClass` — the constructor type the decorator reader helpers accept, exported so consumers can name it.
64
+
65
+ ### Changed
66
+
67
+ - The peer range on `@theokit/di` accepts `^0.2.0` alongside `^0.1.0-next.0`. `@theokit/di`
68
+ ships breaking disposal fixes as `0.2.0`, which falls outside the old range; without this,
69
+ installing both current versions would report an unmet peer dependency, and the release
70
+ tooling would force this package to `1.0.0` to express the incompatibility. Nothing here
71
+ uses the behaviour that changed — the decorators record metadata and the container never
72
+ disposed anything this package registers. (#20)
73
+ - `repository`, `homepage` and `bugs` now point at `usetheokit/theokit-di`. They pointed at `usetheo/theokit-sdk`, so every "Repository" and "Report issues" link on npm led to a project that does not host this package.
74
+ - `readAuthMetadata`, `readEvalDecoratorMetadata` and `readWorkflowMetadata` now declare their parameter as `DecoratedClass` rather than `Function`. `Function` is the widest callable type there is, so it documented nothing and admitted values that are not classes. Any class you already passed still type-checks.
75
+ - JSDoc and comments no longer cite plan tasks or edge-case identifiers that exist in no repository a reader can reach.
76
+ - **Breaking:** `readCronMetadata` and `readHitlMetadata` return a `ReadonlyMap` keyed by method name instead of a single object or `undefined`. `@Cron` and `@Hitl` kept one object per class, so decorating a second method silently discarded the first — a class with two scheduled routines quietly lost one. Both now accumulate per method, like the other fourteen decorators. Migration: `readCronMetadata(C)?.schedule` becomes `readCronMetadata(C).get("methodName")?.schedule`, and an undecorated class yields an empty map rather than `undefined` (#6).
77
+
78
+ ## 0.2.0
79
+
80
+ ### Minor Changes
81
+
82
+ - Decorator-driven agent-team + workflow authoring (own identity — composition over a new engine).
83
+
84
+ - **`@Squad(metadata)`** property decorator + `readSquadMetadata` — declarative sequential agent team backed by `@theokit/di` `METADATA_KEYS.SQUAD`.
85
+ - **`@Step(metadata?)`** method decorator + `readStepMetadata` (`{ after?, name? }`) backed by `METADATA_KEYS.STEP`.
86
+ - **`buildWorkflow(instance)`** — compiles a class decorated with `@Step` into a `@theokit/sdk` `Workflow` (topological order by `after`; validates no-steps / unknown-after / cycle). No new runtime engine — composes `@theokit/sdk/workflow`.
87
+
88
+ First npm publish of these decorators (`0.1.0` on npm is the scaffold).
26
89
 
27
90
  ## [0.1.0] - 2026-05-31
28
91
 
@@ -30,8 +93,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
30
93
 
31
94
  ### Changed
32
95
 
33
- - Removed obsolete `// biome-ignore lint/correctness/noUnusedVariables` directives from `tests/{analyze-graph,async-resolution,container-core,inject-agent,integration/real-agent}.test.ts`. They were flagged as `suppressions/unused` after the workspace enabled `javascript.parser.unsafeParameterDecoratorsEnabled` in `biome.json` (D422). (theokit-sdk-biome-cleanup)
34
- - Dropped unused `@vitest/coverage-v8` devDependency. (theokit-sdk-biome-cleanup)
96
+ - Removed obsolete `// biome-ignore lint/correctness/noUnusedVariables` directives from `tests/{analyze-graph,async-resolution,container-core,inject-agent,integration/real-agent}.test.ts`. They were flagged as `suppressions/unused` after the workspace enabled `javascript.parser.unsafeParameterDecoratorsEnabled` in `biome.json`.
97
+ - Dropped the unused `@vitest/coverage-v8` devDependency.
35
98
 
36
99
  ## [0.1.0-next.0] - 2026-05-29
37
100
 
package/LICENSE CHANGED
@@ -137,8 +137,8 @@
137
137
 
138
138
  6. Trademarks. This License does not grant permission to use the trade
139
139
  names, trademarks, service marks, or product names of the Licensor,
140
- except as required for describing the origin of the Work and
141
- reproducing the content of the NOTICE file.
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
142
 
143
143
  7. Disclaimer of Warranty. Unless required by applicable law or
144
144
  agreed to in writing, Licensor provides the Work (and each
package/dist/index.cjs CHANGED
@@ -49,16 +49,17 @@ function readAutoSummarizeMetadata(target) {
49
49
  __name(readAutoSummarizeMetadata, "readAutoSummarizeMetadata");
50
50
  function Cron(options) {
51
51
  return (target, propertyKey, _descriptor) => {
52
- const metadata = {
52
+ const existing = Reflect.getMetadata(di.METADATA_KEYS.CRON, target.constructor) ?? /* @__PURE__ */ new Map();
53
+ existing.set(propertyKey, {
53
54
  ...options,
54
55
  methodKey: propertyKey
55
- };
56
- Reflect.defineMetadata(di.METADATA_KEYS.CRON, metadata, target.constructor);
56
+ });
57
+ Reflect.defineMetadata(di.METADATA_KEYS.CRON, existing, target.constructor);
57
58
  };
58
59
  }
59
60
  __name(Cron, "Cron");
60
61
  function readCronMetadata(target) {
61
- return Reflect.getMetadata(di.METADATA_KEYS.CRON, target);
62
+ return Reflect.getMetadata(di.METADATA_KEYS.CRON, target) ?? /* @__PURE__ */ new Map();
62
63
  }
63
64
  __name(readCronMetadata, "readCronMetadata");
64
65
  function EvalDecorator(options = {}) {
@@ -73,16 +74,17 @@ function readEvalDecoratorMetadata(target) {
73
74
  __name(readEvalDecoratorMetadata, "readEvalDecoratorMetadata");
74
75
  function Hitl(options) {
75
76
  return (target, propertyKey, _descriptor) => {
76
- const metadata = {
77
+ const existing = Reflect.getMetadata(di.METADATA_KEYS.HITL, target.constructor) ?? /* @__PURE__ */ new Map();
78
+ existing.set(propertyKey, {
77
79
  ...options,
78
80
  methodKey: propertyKey
79
- };
80
- Reflect.defineMetadata(di.METADATA_KEYS.HITL, metadata, target.constructor);
81
+ });
82
+ Reflect.defineMetadata(di.METADATA_KEYS.HITL, existing, target.constructor);
81
83
  };
82
84
  }
83
85
  __name(Hitl, "Hitl");
84
86
  function readHitlMetadata(target) {
85
- return Reflect.getMetadata(di.METADATA_KEYS.HITL, target);
87
+ return Reflect.getMetadata(di.METADATA_KEYS.HITL, target) ?? /* @__PURE__ */ new Map();
86
88
  }
87
89
  __name(readHitlMetadata, "readHitlMetadata");
88
90
  function MemoryScopeDecorator(options) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tokens.ts","../src/agent-provider.ts","../src/decorators/auth.ts","../src/decorators/auto-summarize.ts","../src/decorators/cron.ts","../src/decorators/eval-decorator.ts","../src/decorators/hitl.ts","../src/decorators/memory-scope.ts","../src/decorators/reranker.ts","../src/decorators/retriever.ts","../src/decorators/squad.ts","../src/decorators/step.ts","../src/decorators/sub-agent.ts","../src/decorators/subscription.ts","../src/decorators/text-splitter.ts","../src/decorators/tool.ts","../src/decorators/use-sandbox.ts","../src/decorators/workflow.ts","../src/inject-agent.ts","../src/workflow-builder.ts"],"names":["AGENT_TOKEN","createAgentProvider","options","provide","useFactory","factory","scope","Scope","REQUEST","Auth","target","Reflect","defineMetadata","METADATA_KEYS","AUTH","readAuthMetadata","getMetadata","DEFAULTS","triggerFraction","keepNewest","AutoSummarize","resolved","AUTO_SUMMARIZE","readAutoSummarizeMetadata","Cron","propertyKey","_descriptor","metadata","methodKey","CRON","readCronMetadata","EvalDecorator","EVAL","readEvalDecoratorMetadata","Hitl","HITL","readHitlMetadata","MemoryScopeDecorator","existing","MEMORY_SCOPE","Map","set","readMemoryScopeMetadata","Reranker","RERANKER","readRerankerMetadata","Retriever","RETRIEVER","readRetrieverMetadata","Squad","SQUAD","readSquadMetadata","Step","STEP","readStepMetadata","SubAgent","SUBAGENT","readSubAgentMetadata","Subscription","SUBSCRIPTION","readSubscriptionMetadata","TextSplitter","TEXT_SPLITTER","readTextSplitterMetadata","Tool","TOOL","readToolMetadata","UseSandbox","SANDBOX","readSandboxMetadata","Workflow","WORKFLOW","readWorkflowMetadata","InjectAgent","Inject","buildWorkflow","instance","ctor","meta","size","Error","name","steps","resolveSteps","validateAfterTargets","ordered","topoSort","builder","create","s","then","fn","id","input","run","commit","key","m","k","String","method","after","call","values","undefined","has","placed","Set","visiting","visit","add","up","get","delete","push"],"mappings":";;;;;;;;;;AAKO,IAAMA,WAAAA,GAAc;;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AAA;AACrBU,IAAAA,MAAAA,CAAOI,GAAAA,CAAIrB,EAAEO,GAAG,CAAA;AAChBX,IAAAA,OAAAA,CAAQ6B,KAAKzB,CAAAA,CAAAA;EACf,CAAA,EAbc,OAAA,CAAA;AAed,EAAA,KAAA,MAAWA,CAAAA,IAAKP,KAAAA,CAAMqB,MAAAA,EAAM,QAAUd,CAAAA,CAAAA;AACtC,EAAA,OAAOJ,OAAAA;AACT;AAtBSC,MAAAA,CAAAA,QAAAA,EAAAA,UAAAA,CAAAA","file":"index.cjs","sourcesContent":["/**\n * Token used by `@InjectAgent()` to look up the Agent provider. Importing\n * this directly (instead of using the decorator) lets you register a\n * custom factory under the same token.\n */\nexport const AGENT_TOKEN = \"@theokit/di-agent:Agent\";\n","import { type FactoryProvider, Scope } from \"@theokit/di\";\n\nimport { AGENT_TOKEN } from \"./tokens.js\";\n\n/**\n * Options accepted by `createAgentProvider()`. Mirrors the public\n * `AgentOptions` from `@theokit/sdk` but kept structural so this package\n * does not have a hard import dependency on the SDK's type tree.\n *\n * The factory `async () => Agent.create(options)` is provided by the\n * consumer (see `createAgentProvider` below). This package supplies the\n * scope + token wiring.\n */\nexport interface CreateAgentProviderOptions<TAgent> {\n /**\n * Factory function that produces a fresh Agent per REQUEST.\n * Typically `() => Agent.create({...})` from `@theokit/sdk`.\n */\n factory: () => TAgent | Promise<TAgent>;\n /**\n * Override the scope. Default is `REQUEST` (the wedge — one isolated\n * Agent per HTTP request). Override to `SINGLETON` for CLI / cron /\n * single-tenant scenarios where a shared Agent is desirable.\n */\n scope?: Scope;\n}\n\n/**\n * Build a `FactoryProvider` that materializes an Agent on demand.\n *\n * @example\n * import { Agent } from \"@theokit/sdk\";\n * import { Module } from \"@theokit/di\";\n * import { createAgentProvider } from \"@theokit/di-agent\";\n *\n * @Module({\n * providers: [\n * createAgentProvider({\n * factory: () => Agent.create({ apiKey: process.env.OPENROUTER_API_KEY!, model: { id: \"openai/gpt-4o-mini\" } }),\n * }),\n * ],\n * })\n * class AppModule {}\n */\nexport function createAgentProvider<TAgent>(\n options: CreateAgentProviderOptions<TAgent>,\n): FactoryProvider<TAgent> {\n return {\n provide: AGENT_TOKEN,\n useFactory: () => options.factory(),\n scope: options.scope ?? Scope.REQUEST,\n };\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface AuthOptions {\n providers?: string[];\n sessionConfig?: unknown;\n}\n\nexport function Auth(options: AuthOptions = {}): ClassDecorator {\n return (target: Function) => {\n Reflect.defineMetadata(METADATA_KEYS.AUTH, options, target);\n };\n}\n\nexport function readAuthMetadata(target: Function): AuthOptions | undefined {\n return Reflect.getMetadata(METADATA_KEYS.AUTH, target) as AuthOptions | undefined;\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface AutoSummarizeOptions {\n triggerFraction?: number;\n keepNewest?: number;\n model?: string;\n}\n\nconst DEFAULTS: Required<Omit<AutoSummarizeOptions, \"model\">> = {\n triggerFraction: 0.85,\n keepNewest: 4,\n};\n\nexport function AutoSummarize(options: AutoSummarizeOptions = {}): ClassDecorator {\n return (target: Function) => {\n const resolved = { ...DEFAULTS, ...options };\n Reflect.defineMetadata(METADATA_KEYS.AUTO_SUMMARIZE, resolved, target);\n };\n}\n\nexport function readAutoSummarizeMetadata(\n target: abstract new (...args: never) => unknown,\n): (Required<Omit<AutoSummarizeOptions, \"model\">> & { model?: string }) | undefined {\n return Reflect.getMetadata(METADATA_KEYS.AUTO_SUMMARIZE, target) as\n | (Required<Omit<AutoSummarizeOptions, \"model\">> & { model?: string })\n | undefined;\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface CronOptions {\n schedule: string;\n timezone?: string;\n}\n\nexport interface CronMetadata extends CronOptions {\n methodKey: string | symbol;\n}\n\nexport function Cron(options: CronOptions): MethodDecorator {\n return (target: object, propertyKey: string | symbol, _descriptor: PropertyDescriptor) => {\n const metadata: CronMetadata = { ...options, methodKey: propertyKey };\n Reflect.defineMetadata(METADATA_KEYS.CRON, metadata, target.constructor);\n };\n}\n\nexport function readCronMetadata(\n target: abstract new (...args: never) => unknown,\n): CronMetadata | undefined {\n return Reflect.getMetadata(METADATA_KEYS.CRON, target) as CronMetadata | undefined;\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface EvalOptions {\n name?: string;\n scorers?: unknown[];\n dataset?: unknown;\n}\n\nexport function EvalDecorator(options: EvalOptions = {}): ClassDecorator {\n return (target: Function) => {\n Reflect.defineMetadata(METADATA_KEYS.EVAL, options, target);\n };\n}\n\nexport function readEvalDecoratorMetadata(target: Function): EvalOptions | undefined {\n return Reflect.getMetadata(METADATA_KEYS.EVAL, target) as EvalOptions | undefined;\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface HitlOptions {\n tools: string[];\n timeoutMs?: number;\n}\n\nexport interface HitlMetadata extends HitlOptions {\n methodKey: string | symbol;\n}\n\nexport function Hitl(options: HitlOptions): MethodDecorator {\n return (target: object, propertyKey: string | symbol, _descriptor: PropertyDescriptor) => {\n const metadata: HitlMetadata = { ...options, methodKey: propertyKey };\n Reflect.defineMetadata(METADATA_KEYS.HITL, metadata, target.constructor);\n };\n}\n\nexport function readHitlMetadata(\n target: abstract new (...args: never) => unknown,\n): HitlMetadata | undefined {\n return Reflect.getMetadata(METADATA_KEYS.HITL, target) as HitlMetadata | undefined;\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface MemoryScopeOptions {\n path: string;\n}\n\nexport function MemoryScopeDecorator(options: MemoryScopeOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, MemoryScopeOptions> =\n Reflect.getMetadata(METADATA_KEYS.MEMORY_SCOPE, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.MEMORY_SCOPE, existing, target.constructor);\n };\n}\n\nexport function readMemoryScopeMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, MemoryScopeOptions> {\n return Reflect.getMetadata(METADATA_KEYS.MEMORY_SCOPE, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface RerankerOptions {\n provider?: string;\n model?: string;\n topN?: number;\n}\n\nexport function Reranker(options: RerankerOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, RerankerOptions> =\n Reflect.getMetadata(METADATA_KEYS.RERANKER, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.RERANKER, existing, target.constructor);\n };\n}\n\nexport function readRerankerMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, RerankerOptions> {\n return Reflect.getMetadata(METADATA_KEYS.RERANKER, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface RetrieverOptions {\n topK?: number;\n threshold?: number;\n}\n\nexport function Retriever(options: RetrieverOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, RetrieverOptions> =\n Reflect.getMetadata(METADATA_KEYS.RETRIEVER, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.RETRIEVER, existing, target.constructor);\n };\n}\n\nexport function readRetrieverMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, RetrieverOptions> {\n return Reflect.getMetadata(METADATA_KEYS.RETRIEVER, target) ?? new Map();\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/**\n * Metadata captured by the `@Squad()` property decorator. Declares a sequential\n * agent team by referencing the agent property names that compose it. Mirrors\n * the `@theokit/sdk` `createSquad` factory (decorator mandate — every agentic\n * capability ships a decorator alongside the factory).\n */\nexport interface SquadMetadata {\n /** Agent property names (or ids) that run in order. */\n agents: string[];\n /** Orchestration process. Default (omitted) = `\"sequential\"`. */\n process?: \"sequential\" | \"hierarchical\";\n /** Optional squad name. */\n name?: string;\n}\n\n/**\n * `@Squad(metadata)` — declare a sequential agent team on a property. The DI\n * container / agent provider materializes it into a `createSquad(...)` at wiring\n * time.\n */\nexport function Squad(metadata: SquadMetadata): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, SquadMetadata> =\n Reflect.getMetadata(METADATA_KEYS.SQUAD, target.constructor) ?? new Map();\n existing.set(propertyKey, metadata);\n Reflect.defineMetadata(METADATA_KEYS.SQUAD, existing, target.constructor);\n };\n}\n\n/** Read `@Squad()` metadata off a class constructor. */\nexport function readSquadMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, SquadMetadata> {\n return Reflect.getMetadata(METADATA_KEYS.SQUAD, target) ?? new Map();\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/**\n * Metadata captured by the `@Step()` method decorator. Declares one step of a\n * decorator-driven workflow and its single upstream dependency. Compiled into\n * a `@theokit/sdk` `Workflow` by `buildWorkflow` (decorator mandate — every\n * agentic capability ships a decorator alongside the factory/builder).\n */\nexport interface StepMetadata {\n /**\n * Method name of the upstream step this step runs after. Omitted = entry\n * step (receives the workflow input). MVP supports a single dependency\n * (linear chain); branching/fan-out stays the imperative `Workflow` surface.\n */\n after?: string;\n /** Optional step id (defaults to the method name). */\n name?: string;\n}\n\n/**\n * `@Step(metadata?)` — mark a class method as a workflow step. The method\n * receives the upstream step's return value (or the workflow input for an\n * entry step) and returns this step's output.\n */\nexport function Step(metadata: StepMetadata = {}): MethodDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, StepMetadata> =\n Reflect.getMetadata(METADATA_KEYS.STEP, target.constructor) ?? new Map();\n existing.set(propertyKey, metadata);\n Reflect.defineMetadata(METADATA_KEYS.STEP, existing, target.constructor);\n };\n}\n\n/** Read `@Step()` metadata off a class constructor (insertion-ordered). */\nexport function readStepMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, StepMetadata> {\n return Reflect.getMetadata(METADATA_KEYS.STEP, target) ?? new Map();\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface SubAgentOptions {\n name: string;\n description: string;\n instructions: string;\n model?: string;\n maxDelegationDepth?: number;\n}\n\nexport function SubAgent(options: SubAgentOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, SubAgentOptions> =\n Reflect.getMetadata(METADATA_KEYS.SUBAGENT, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.SUBAGENT, existing, target.constructor);\n };\n}\n\nexport function readSubAgentMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, SubAgentOptions> {\n return Reflect.getMetadata(METADATA_KEYS.SUBAGENT, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface SubscriptionOptions {\n name: string;\n transport?: string;\n}\n\nexport function Subscription(options: SubscriptionOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, SubscriptionOptions> =\n Reflect.getMetadata(METADATA_KEYS.SUBSCRIPTION, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.SUBSCRIPTION, existing, target.constructor);\n };\n}\n\nexport function readSubscriptionMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, SubscriptionOptions> {\n return Reflect.getMetadata(METADATA_KEYS.SUBSCRIPTION, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface TextSplitterOptions {\n strategy?: string;\n chunkSize?: number;\n overlap?: number;\n}\n\nexport function TextSplitter(options: TextSplitterOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, TextSplitterOptions> =\n Reflect.getMetadata(METADATA_KEYS.TEXT_SPLITTER, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.TEXT_SPLITTER, existing, target.constructor);\n };\n}\n\nexport function readTextSplitterMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, TextSplitterOptions> {\n return Reflect.getMetadata(METADATA_KEYS.TEXT_SPLITTER, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface ToolOptions {\n name: string;\n description: string;\n inputSchema?: unknown;\n}\n\nexport function Tool(options: ToolOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, ToolOptions> =\n Reflect.getMetadata(METADATA_KEYS.TOOL, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.TOOL, existing, target.constructor);\n };\n}\n\nexport function readToolMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, ToolOptions> {\n return Reflect.getMetadata(METADATA_KEYS.TOOL, target) ?? new Map();\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface UseSandboxOptions {\n backend?: \"local\" | \"docker\" | string;\n workDir?: string;\n timeoutMs?: number;\n}\n\nexport function UseSandbox(options: UseSandboxOptions = {}): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, UseSandboxOptions> =\n Reflect.getMetadata(METADATA_KEYS.SANDBOX, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.SANDBOX, existing, target.constructor);\n };\n}\n\nexport function readSandboxMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, UseSandboxOptions> {\n return Reflect.getMetadata(METADATA_KEYS.SANDBOX, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nexport interface WorkflowOptions {\n name?: string;\n retryPolicy?: unknown;\n inputSchema?: unknown;\n outputSchema?: unknown;\n}\n\nexport function Workflow(options: WorkflowOptions = {}): ClassDecorator {\n return (target: Function) => {\n Reflect.defineMetadata(METADATA_KEYS.WORKFLOW, options, target);\n };\n}\n\nexport function readWorkflowMetadata(target: Function): WorkflowOptions | undefined {\n return Reflect.getMetadata(METADATA_KEYS.WORKFLOW, target) as WorkflowOptions | undefined;\n}\n","import { Inject } from \"@theokit/di\";\n\nimport { AGENT_TOKEN } from \"./tokens.js\";\n\n/**\n * Parameter decorator — injects the REQUEST-scoped Agent into a constructor.\n * Equivalent to `@Inject(AGENT_TOKEN)` but documents intent.\n *\n * @example\n * @Injectable()\n * class ChatController {\n * constructor(@InjectAgent() private readonly agent: Agent) {}\n *\n * async chat(message: string) {\n * return this.agent.send(message);\n * }\n * }\n */\nexport function InjectAgent(): ParameterDecorator {\n return Inject(AGENT_TOKEN);\n}\n","/**\n * `buildWorkflow` — compile a `@Step`-decorated class instance into a\n * `@theokit/sdk` `Workflow`.\n *\n * This is the materializer/bridge for the decorator-driven workflow authoring\n * surface (cross-val Gap 2). It COMPOSES the existing `Workflow` engine — it\n * adds no orchestration logic of its own (same principle as `createSquad`).\n * Steps are topologically ordered by their single `after` dependency into a\n * linear `Workflow.then(...)` chain; each step's return value is threaded into\n * the next step. Branching/fan-out remains the imperative `Workflow` surface.\n *\n * NOTE: this module (unlike the metadata-only decorators) imports the\n * `@theokit/sdk` peer dependency — it is the bridge layer.\n */\n\nimport { fn, Workflow } from \"@theokit/sdk/workflow\";\nimport { readStepMetadata, type StepMetadata } from \"./decorators/step.js\";\nimport { readWorkflowMetadata } from \"./decorators/workflow.js\";\n\ninterface ResolvedStep {\n key: string;\n id: string;\n after?: string;\n run: (input: unknown) => unknown;\n}\n\n/**\n * Build a `Workflow` from a `@Step`-decorated instance. Validates the step\n * graph (fail-fast) before constructing the workflow.\n *\n * @throws Error when there are no `@Step` methods, an `after` references an\n * unknown step, or the `after` graph contains a cycle.\n */\nexport function buildWorkflow(instance: object): Workflow {\n const ctor = instance.constructor as abstract new (...args: never) => unknown;\n const meta = readStepMetadata(ctor);\n if (meta.size === 0) {\n throw new Error(`buildWorkflow: class \"${instance.constructor.name}\" has no @Step methods`);\n }\n\n const steps = resolveSteps(instance, meta);\n validateAfterTargets(steps);\n const ordered = topoSort(steps);\n\n const name = readWorkflowMetadata(instance.constructor as Function)?.name ?? \"workflow\";\n let builder = Workflow.create({ name });\n for (const s of ordered) {\n builder = builder.then(fn(s.id, (input: unknown) => s.run(input)));\n }\n return builder.commit();\n}\n\n/** Resolve each `@Step` method into a runnable {@link ResolvedStep}. */\nfunction resolveSteps(\n instance: object,\n meta: ReadonlyMap<string | symbol, StepMetadata>,\n): Map<string, ResolvedStep> {\n const steps = new Map<string, ResolvedStep>();\n for (const [key, m] of meta) {\n const k = String(key);\n const method = (instance as Record<string, unknown>)[k];\n if (typeof method !== \"function\") {\n throw new Error(`buildWorkflow: @Step \"${k}\" is not a method`);\n }\n steps.set(k, {\n key: k,\n id: m.name ?? k,\n after: m.after,\n run: (input: unknown) => (method as (i: unknown) => unknown).call(instance, input),\n });\n }\n return steps;\n}\n\n/** Fail-fast if any `after` references a step that does not exist. */\nfunction validateAfterTargets(steps: Map<string, ResolvedStep>): void {\n for (const s of steps.values()) {\n if (s.after !== undefined && !steps.has(s.after)) {\n throw new Error(\n `buildWorkflow: @Step \"${s.key}\" declares after: \"${s.after}\" which is not a known @Step (unknown upstream)`,\n );\n }\n }\n}\n\n/**\n * Topologically order steps by their single `after` dependency. Entry steps\n * (no `after`) come first in declaration order; each dependent follows its\n * upstream. Throws on a cycle.\n */\nfunction topoSort(steps: Map<string, ResolvedStep>): ResolvedStep[] {\n const ordered: ResolvedStep[] = [];\n const placed = new Set<string>();\n const visiting = new Set<string>();\n\n const visit = (s: ResolvedStep): void => {\n if (placed.has(s.key)) return;\n if (visiting.has(s.key)) {\n throw new Error(`buildWorkflow: cycle detected in @Step \"after\" graph at \"${s.key}\"`);\n }\n visiting.add(s.key);\n if (s.after !== undefined) {\n const up = steps.get(s.after);\n if (up !== undefined) visit(up);\n }\n visiting.delete(s.key);\n placed.add(s.key);\n ordered.push(s);\n };\n\n for (const s of steps.values()) visit(s);\n return ordered;\n}\n"]}
1
+ {"version":3,"sources":["../src/tokens.ts","../src/agent-provider.ts","../src/decorators/auth.ts","../src/decorators/auto-summarize.ts","../src/decorators/cron.ts","../src/decorators/eval-decorator.ts","../src/decorators/hitl.ts","../src/decorators/memory-scope.ts","../src/decorators/reranker.ts","../src/decorators/retriever.ts","../src/decorators/squad.ts","../src/decorators/step.ts","../src/decorators/sub-agent.ts","../src/decorators/subscription.ts","../src/decorators/text-splitter.ts","../src/decorators/tool.ts","../src/decorators/use-sandbox.ts","../src/decorators/workflow.ts","../src/inject-agent.ts","../src/workflow-builder.ts"],"names":["AGENT_TOKEN","createAgentProvider","options","provide","useFactory","factory","scope","Scope","REQUEST","Auth","target","Reflect","defineMetadata","METADATA_KEYS","AUTH","readAuthMetadata","getMetadata","DEFAULTS","triggerFraction","keepNewest","AutoSummarize","resolved","AUTO_SUMMARIZE","readAutoSummarizeMetadata","Cron","propertyKey","_descriptor","existing","CRON","Map","set","methodKey","readCronMetadata","EvalDecorator","EVAL","readEvalDecoratorMetadata","Hitl","HITL","readHitlMetadata","MemoryScopeDecorator","MEMORY_SCOPE","readMemoryScopeMetadata","Reranker","RERANKER","readRerankerMetadata","Retriever","RETRIEVER","readRetrieverMetadata","Squad","metadata","SQUAD","readSquadMetadata","Step","STEP","readStepMetadata","SubAgent","SUBAGENT","readSubAgentMetadata","Subscription","SUBSCRIPTION","readSubscriptionMetadata","TextSplitter","TEXT_SPLITTER","readTextSplitterMetadata","Tool","TOOL","readToolMetadata","UseSandbox","SANDBOX","readSandboxMetadata","Workflow","WORKFLOW","readWorkflowMetadata","InjectAgent","Inject","buildWorkflow","instance","ctor","meta","size","Error","name","steps","resolveSteps","validateAfterTargets","ordered","topoSort","builder","create","s","then","fn","id","input","run","commit","key","m","k","String","method","after","call","values","undefined","has","placed","Set","visiting","visit","add","up","get","delete","push"],"mappings":";;;;;;;;;;AAKO,IAAMA,WAAAA,GAAc;;;ACuCpB,SAASC,oBACdC,OAAAA,EAA2C;AAE3C,EAAA,OAAO;IACLC,OAAAA,EAASH,WAAAA;IACTI,UAAAA,kBAAY,MAAA,CAAA,MAAMF,OAAAA,CAAQG,OAAAA,EAAO,EAArB,YAAA,CAAA;IACZC,KAAAA,EAAOJ,OAAAA,CAAQI,SAASC,QAAAA,CAAMC;AAChC,GAAA;AACF;AARgBP,MAAAA,CAAAA,mBAAAA,EAAAA,qBAAAA,CAAAA;AC1BT,SAASQ,IAAAA,CAAKP,OAAAA,GAAuB,EAAC,EAAC;AAC5C,EAAA,OAAO,CAACQ,MAAAA,KAAAA;AACNC,IAAAA,OAAAA,CAAQC,cAAAA,CAAeC,gBAAAA,CAAcC,IAAAA,EAAMZ,OAAAA,EAASQ,MAAAA,CAAAA;AACtD,EAAA,CAAA;AACF;AAJgBD,MAAAA,CAAAA,IAAAA,EAAAA,MAAAA,CAAAA;AAUT,SAASM,iBAAiBL,MAAAA,EAAsB;AACrD,EAAA,OAAOC,OAAAA,CAAQK,WAAAA,CAAYH,gBAAAA,CAAcC,IAAAA,EAAMJ,MAAAA,CAAAA;AACjD;AAFgBK,MAAAA,CAAAA,gBAAAA,EAAAA,kBAAAA,CAAAA;ACbhB,IAAME,QAAAA,GAA0D;EAC9DC,eAAAA,EAAiB,IAAA;EACjBC,UAAAA,EAAY;AACd,CAAA;AAYO,SAASC,aAAAA,CAAclB,OAAAA,GAAgC,EAAC,EAAC;AAC9D,EAAA,OAAO,CAACQ,MAAAA,KAAAA;AACN,IAAA,M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AAA,IAAIY,QAAAA,CAASH,GAAAA,CAAIhB,CAAAA,CAAEO,GAAG,CAAA,EAAG;AACvB,MAAA,MAAM,IAAIhB,KAAAA,CAAM,CAAA,yDAAA,EAA4DS,CAAAA,CAAEO,GAAG,CAAA,CAAA,CAAG,CAAA;AACtF,IAAA;AACAY,IAAAA,QAAAA,CAASE,GAAAA,CAAIrB,EAAEO,GAAG,CAAA;AAClB,IAAA,IAAIP,CAAAA,CAAEY,UAAUG,MAAAA,EAAW;AACzB,MAAA,MAAMO,EAAAA,GAAK7B,KAAAA,CAAM8B,GAAAA,CAAIvB,CAAAA,CAAEY,KAAK,CAAA;AAC5B,MAAA,IAAIU,EAAAA,KAAOP,MAAAA,EAAWK,KAAAA,CAAME,EAAAA,CAAAA;AAC9B,IAAA;AACAH,IAAAA,QAAAA,CAASK,MAAAA,CAAOxB,EAAEO,GAAG,CAAA;AACrBU,IAAAA,MAAAA,CAAOI,GAAAA,CAAIrB,EAAEO,GAAG,CAAA;AAChBX,IAAAA,OAAAA,CAAQ6B,KAAKzB,CAAAA,CAAAA;EACf,CAAA,EAbc,OAAA,CAAA;AAed,EAAA,KAAA,MAAWA,CAAAA,IAAKP,KAAAA,CAAMqB,MAAAA,EAAM,QAAUd,CAAAA,CAAAA;AACtC,EAAA,OAAOJ,OAAAA;AACT;AAtBSC,MAAAA,CAAAA,QAAAA,EAAAA,UAAAA,CAAAA","file":"index.cjs","sourcesContent":["/**\n * Token used by `@InjectAgent()` to look up the Agent provider. Importing\n * this directly (instead of using the decorator) lets you register a\n * custom factory under the same token.\n */\nexport const AGENT_TOKEN = \"@theokit/di-agent:Agent\";\n","import { type FactoryProvider, Scope } from \"@theokit/di\";\n\nimport { AGENT_TOKEN } from \"./tokens.js\";\n\n/**\n * Options accepted by `createAgentProvider()`. Mirrors the public\n * `AgentOptions` from `@theokit/sdk` but kept structural so this package\n * does not have a hard import dependency on the SDK's type tree.\n *\n * The factory `async () => Agent.create(options)` is provided by the\n * consumer (see `createAgentProvider` below). This package supplies the\n * scope + token wiring.\n */\nexport interface CreateAgentProviderOptions<TAgent> {\n /**\n * Factory function that produces a fresh Agent per REQUEST.\n * Typically `() => Agent.create({...})` from `@theokit/sdk`.\n */\n factory: () => TAgent | Promise<TAgent>;\n /**\n * Override the scope. Default is `REQUEST` (the wedge — one isolated\n * Agent per HTTP request). Override to `SINGLETON` for CLI / cron /\n * single-tenant scenarios where a shared Agent is desirable.\n */\n scope?: Scope;\n}\n\n/**\n * Build a `FactoryProvider` that materializes an Agent on demand.\n *\n * @example\n * import { Agent } from \"@theokit/sdk\";\n * import { Module } from \"@theokit/di\";\n * import { createAgentProvider } from \"@theokit/di-agent\";\n *\n * @Module({\n * providers: [\n * createAgentProvider({\n * factory: () => Agent.create({ apiKey: process.env.OPENROUTER_API_KEY!, model: { id: \"openai/gpt-4o-mini\" } }),\n * }),\n * ],\n * })\n * class AppModule {}\n */\nexport function createAgentProvider<TAgent>(\n options: CreateAgentProviderOptions<TAgent>,\n): FactoryProvider<TAgent> {\n return {\n provide: AGENT_TOKEN,\n useFactory: () => options.factory(),\n scope: options.scope ?? Scope.REQUEST,\n };\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nimport type { DecoratedClass } from \"./decorated-class.js\";\n\n/** What {@link Auth} declares: the identity `providers` this agent accepts, and any transport\n * `sessionConfig` they need. */\nexport interface AuthOptions {\n providers?: string[];\n sessionConfig?: unknown;\n}\n\n/**\n * Declare how an agent class authenticates the caller.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function Auth(options: AuthOptions = {}): ClassDecorator {\n return (target) => {\n Reflect.defineMetadata(METADATA_KEYS.AUTH, options, target);\n };\n}\n\n/** The `@Auth` of a class, or `undefined` when it has none.\n *\n * Class decorators are singular by nature, so this returns one object or `undefined` — unlike the\n * property and method decorators, which accumulate into a map. */\nexport function readAuthMetadata(target: DecoratedClass): AuthOptions | undefined {\n return Reflect.getMetadata(METADATA_KEYS.AUTH, target) as AuthOptions | undefined;\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nimport type { DecoratedClass } from \"./decorated-class.js\";\n\n/** What {@link AutoSummarize} declares: the `triggerFraction` of the context window that starts a\n * summarisation, how many recent turns to `keepNewest` verbatim, and optionally which `model`\n * writes the summary. */\nexport interface AutoSummarizeOptions {\n triggerFraction?: number;\n keepNewest?: number;\n model?: string;\n}\n\nconst DEFAULTS: Required<Omit<AutoSummarizeOptions, \"model\">> = {\n triggerFraction: 0.85,\n keepNewest: 4,\n};\n\n/**\n * Declare that a conversation is summarised automatically as it approaches the context limit, so\n * it can continue past the point where it would otherwise be truncated.\n *\n * Defaults are resolved at decoration time, so a reader of the metadata sees real values rather\n * than having to know them.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function AutoSummarize(options: AutoSummarizeOptions = {}): ClassDecorator {\n return (target) => {\n const resolved = { ...DEFAULTS, ...options };\n Reflect.defineMetadata(METADATA_KEYS.AUTO_SUMMARIZE, resolved, target);\n };\n}\n\n/** The `@AutoSummarize` of a class with its defaults resolved, or `undefined` when it has none.\n *\n * Class decorators are singular by nature, so this returns one object or `undefined` — unlike the\n * property and method decorators, which accumulate into a map. */\nexport function readAutoSummarizeMetadata(\n target: DecoratedClass,\n): (Required<Omit<AutoSummarizeOptions, \"model\">> & { model?: string }) | undefined {\n return Reflect.getMetadata(METADATA_KEYS.AUTO_SUMMARIZE, target) as\n | (Required<Omit<AutoSummarizeOptions, \"model\">> & { model?: string })\n | undefined;\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/** What {@link Cron} declares: the `schedule` as a cron expression and the `timezone` it is read\n * in. The expression is stored verbatim and never parsed here, so a malformed one surfaces\n * wherever it is eventually scheduled. */\nexport interface CronOptions {\n schedule: string;\n timezone?: string;\n}\n\n/** A stored `@Cron`, with the method it was applied to. The map is already keyed by that method;\n * `methodKey` repeats it so an entry read on its own still says what it schedules. */\nexport interface CronMetadata extends CronOptions {\n methodKey: string | symbol;\n}\n\n/**\n * `@Cron(options)` — declare a scheduled routine on a method.\n *\n * Accumulates per method, keyed by the method name, so a class may schedule as many\n * routines as it has methods. It used to keep a single object per class, which meant a\n * second `@Cron` on the same class silently discarded the first (#6).\n */\nexport function Cron(options: CronOptions): MethodDecorator {\n return (target: object, propertyKey: string | symbol, _descriptor: PropertyDescriptor) => {\n const existing: Map<string | symbol, CronMetadata> =\n Reflect.getMetadata(METADATA_KEYS.CRON, target.constructor) ?? new Map();\n existing.set(propertyKey, { ...options, methodKey: propertyKey });\n Reflect.defineMetadata(METADATA_KEYS.CRON, existing, target.constructor);\n };\n}\n\n/** Read `@Cron()` metadata off a class constructor, keyed by method (insertion-ordered). */\nexport function readCronMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, CronMetadata> {\n return Reflect.getMetadata(METADATA_KEYS.CRON, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nimport type { DecoratedClass } from \"./decorated-class.js\";\n\n/** What {@link EvalDecorator} declares: the evaluation's `name`, the `scorers` that judge a run,\n * and the `dataset` it runs against. */\nexport interface EvalOptions {\n name?: string;\n scorers?: unknown[];\n dataset?: unknown;\n}\n\n/**\n * Declare an agent class as the subject of an evaluation.\n *\n * Named `EvalDecorator` rather than `Eval` because `eval` is a reserved word in strict mode, and\n * an export nobody can import under its own name is worse than a longer one.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function EvalDecorator(options: EvalOptions = {}): ClassDecorator {\n return (target) => {\n Reflect.defineMetadata(METADATA_KEYS.EVAL, options, target);\n };\n}\n\n/** The `@EvalDecorator` of a class, or `undefined` when it has none.\n *\n * Class decorators are singular by nature, so this returns one object or `undefined` — unlike the\n * property and method decorators, which accumulate into a map. */\nexport function readEvalDecoratorMetadata(target: DecoratedClass): EvalOptions | undefined {\n return Reflect.getMetadata(METADATA_KEYS.EVAL, target) as EvalOptions | undefined;\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/** What {@link Hitl} declares: the `tools` whose invocation needs a human decision, and the\n * `timeoutMs` after which waiting stops. */\nexport interface HitlOptions {\n tools: string[];\n timeoutMs?: number;\n}\n\n/** A stored `@Hitl`, with the method it was applied to. The map is already keyed by that method;\n * `methodKey` repeats it so an entry read on its own still says what it guards. */\nexport interface HitlMetadata extends HitlOptions {\n methodKey: string | symbol;\n}\n\n/**\n * `@Hitl(options)` — declare a human-in-the-loop approval handler on a method.\n *\n * Accumulates per method, keyed by the method name, so a class may declare as many\n * handlers as it has methods. It used to keep a single object per class, which meant a\n * second `@Hitl` on the same class silently discarded the first (#6).\n */\nexport function Hitl(options: HitlOptions): MethodDecorator {\n return (target: object, propertyKey: string | symbol, _descriptor: PropertyDescriptor) => {\n const existing: Map<string | symbol, HitlMetadata> =\n Reflect.getMetadata(METADATA_KEYS.HITL, target.constructor) ?? new Map();\n existing.set(propertyKey, { ...options, methodKey: propertyKey });\n Reflect.defineMetadata(METADATA_KEYS.HITL, existing, target.constructor);\n };\n}\n\n/** Read `@Hitl()` metadata off a class constructor, keyed by method (insertion-ordered). */\nexport function readHitlMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, HitlMetadata> {\n return Reflect.getMetadata(METADATA_KEYS.HITL, target) ?? new Map();\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/** What {@link MemoryScopeDecorator} declares: the `path` naming this scope's place in the\n * memory hierarchy. */\nexport interface MemoryScopeOptions {\n path: string;\n}\n\n/**\n * Declare the memory scope a property reads and writes, so sibling scopes stay isolated from\n * each other while a child can still see its parent.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function MemoryScopeDecorator(options: MemoryScopeOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, MemoryScopeOptions> =\n Reflect.getMetadata(METADATA_KEYS.MEMORY_SCOPE, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.MEMORY_SCOPE, existing, target.constructor);\n };\n}\n\n/** Every `@MemoryScopeDecorator` on a class, keyed by the property it was applied to. */\nexport function readMemoryScopeMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, MemoryScopeOptions> {\n return Reflect.getMetadata(METADATA_KEYS.MEMORY_SCOPE, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/** What {@link Reranker} declares: which provider and model score the candidates, and how many\n * survive (`topN`). */\nexport interface RerankerOptions {\n provider?: string;\n model?: string;\n topN?: number;\n}\n\n/**\n * Declare a property as the reranking step that reorders what a retriever returned.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function Reranker(options: RerankerOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, RerankerOptions> =\n Reflect.getMetadata(METADATA_KEYS.RERANKER, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.RERANKER, existing, target.constructor);\n };\n}\n\n/** Every `@Reranker` on a class, keyed by the property it was applied to. */\nexport function readRerankerMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, RerankerOptions> {\n return Reflect.getMetadata(METADATA_KEYS.RERANKER, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/** What {@link Retriever} declares: how many passages to return (`topK`) and the minimum score\n * a passage needs to be worth returning at all (`threshold`). */\nexport interface RetrieverOptions {\n topK?: number;\n threshold?: number;\n}\n\n/**\n * Declare a property as the retrieval step of a RAG pipeline.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function Retriever(options: RetrieverOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, RetrieverOptions> =\n Reflect.getMetadata(METADATA_KEYS.RETRIEVER, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.RETRIEVER, existing, target.constructor);\n };\n}\n\n/** Every `@Retriever` on a class, keyed by the property it was applied to. */\nexport function readRetrieverMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, RetrieverOptions> {\n return Reflect.getMetadata(METADATA_KEYS.RETRIEVER, target) ?? new Map();\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/**\n * Metadata captured by the `@Squad()` property decorator. Declares a sequential\n * agent team by referencing the agent property names that compose it. Mirrors\n * the `@theokit/sdk` `createSquad` factory (decorator mandate — every agentic\n * capability ships a decorator alongside the factory).\n */\nexport interface SquadMetadata {\n /** Agent property names (or ids) that run in order. */\n agents: string[];\n /** Orchestration process. Default (omitted) = `\"sequential\"`. */\n process?: \"sequential\" | \"hierarchical\";\n /** Optional squad name. */\n name?: string;\n}\n\n/**\n * `@Squad(metadata)` — declare a sequential agent team on a property. The DI\n * container / agent provider materializes it into a `createSquad(...)` at wiring\n * time.\n */\nexport function Squad(metadata: SquadMetadata): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, SquadMetadata> =\n Reflect.getMetadata(METADATA_KEYS.SQUAD, target.constructor) ?? new Map();\n existing.set(propertyKey, metadata);\n Reflect.defineMetadata(METADATA_KEYS.SQUAD, existing, target.constructor);\n };\n}\n\n/** Read `@Squad()` metadata off a class constructor. */\nexport function readSquadMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, SquadMetadata> {\n return Reflect.getMetadata(METADATA_KEYS.SQUAD, target) ?? new Map();\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/**\n * Metadata captured by the `@Step()` method decorator. Declares one step of a\n * decorator-driven workflow and its single upstream dependency. Compiled into\n * a `@theokit/sdk` `Workflow` by `buildWorkflow` (decorator mandate — every\n * agentic capability ships a decorator alongside the factory/builder).\n */\nexport interface StepMetadata {\n /**\n * Method name of the upstream step this step runs after. Omitted = entry\n * step (receives the workflow input). MVP supports a single dependency\n * (linear chain); branching/fan-out stays the imperative `Workflow` surface.\n */\n after?: string;\n /** Optional step id (defaults to the method name). */\n name?: string;\n}\n\n/**\n * `@Step(metadata?)` — mark a class method as a workflow step. The method\n * receives the upstream step's return value (or the workflow input for an\n * entry step) and returns this step's output.\n */\nexport function Step(metadata: StepMetadata = {}): MethodDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, StepMetadata> =\n Reflect.getMetadata(METADATA_KEYS.STEP, target.constructor) ?? new Map();\n existing.set(propertyKey, metadata);\n Reflect.defineMetadata(METADATA_KEYS.STEP, existing, target.constructor);\n };\n}\n\n/** Read `@Step()` metadata off a class constructor (insertion-ordered). */\nexport function readStepMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, StepMetadata> {\n return Reflect.getMetadata(METADATA_KEYS.STEP, target) ?? new Map();\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/** What {@link SubAgent} declares: how the parent agent describes the delegate when deciding\n * whether to hand work over, and optionally which model it runs on and how deep delegation may\n * nest before it stops. */\nexport interface SubAgentOptions {\n name: string;\n description: string;\n instructions: string;\n model?: string;\n maxDelegationDepth?: number;\n}\n\n/**\n * Declare a property as a subagent this one may delegate to, exposed to the parent as a tool.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function SubAgent(options: SubAgentOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, SubAgentOptions> =\n Reflect.getMetadata(METADATA_KEYS.SUBAGENT, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.SUBAGENT, existing, target.constructor);\n };\n}\n\n/** Every `@SubAgent` on a class, keyed by the property it was applied to. */\nexport function readSubAgentMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, SubAgentOptions> {\n return Reflect.getMetadata(METADATA_KEYS.SUBAGENT, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/** What {@link Subscription} declares: the event `name` to listen for, and optionally the\n * `transport` it arrives on. */\nexport interface SubscriptionOptions {\n name: string;\n transport?: string;\n}\n\n/**\n * Declare a property as a subscription to an event stream.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function Subscription(options: SubscriptionOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, SubscriptionOptions> =\n Reflect.getMetadata(METADATA_KEYS.SUBSCRIPTION, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.SUBSCRIPTION, existing, target.constructor);\n };\n}\n\n/** Every `@Subscription` on a class, keyed by the property it was applied to. */\nexport function readSubscriptionMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, SubscriptionOptions> {\n return Reflect.getMetadata(METADATA_KEYS.SUBSCRIPTION, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/** What {@link TextSplitter} declares: the splitting `strategy`, the target `chunkSize`, and how\n * much `overlap` consecutive chunks share so a passage split mid-sentence is still retrievable\n * from either side. */\nexport interface TextSplitterOptions {\n strategy?: string;\n chunkSize?: number;\n overlap?: number;\n}\n\n/**\n * Declare a property as the step that breaks documents into indexable chunks.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function TextSplitter(options: TextSplitterOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, TextSplitterOptions> =\n Reflect.getMetadata(METADATA_KEYS.TEXT_SPLITTER, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.TEXT_SPLITTER, existing, target.constructor);\n };\n}\n\n/** Every `@TextSplitter` on a class, keyed by the property it was applied to. */\nexport function readTextSplitterMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, TextSplitterOptions> {\n return Reflect.getMetadata(METADATA_KEYS.TEXT_SPLITTER, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/** What {@link Tool} declares about one tool: the name and description an agent sees when\n * choosing it, and optionally the schema its input must match. */\nexport interface ToolOptions {\n name: string;\n description: string;\n inputSchema?: unknown;\n}\n\n/**\n * Declare a property as a tool an agent may call.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function Tool(options: ToolOptions): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, ToolOptions> =\n Reflect.getMetadata(METADATA_KEYS.TOOL, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.TOOL, existing, target.constructor);\n };\n}\n\n/** Every `@Tool` on a class, keyed by the property it was applied to. Empty map when there are\n * none — a class with no tools is ordinary, not an error. */\nexport function readToolMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, ToolOptions> {\n return Reflect.getMetadata(METADATA_KEYS.TOOL, target) ?? new Map();\n}\n","import \"reflect-metadata\";\n\nimport { METADATA_KEYS } from \"@theokit/di\";\n\n/** What {@link UseSandbox} declares: which `backend` isolates the execution, the `workDir` it\n * starts in, and the `timeoutMs` after which it is abandoned. */\nexport interface UseSandboxOptions {\n backend?: \"local\" | \"docker\" | string;\n workDir?: string;\n timeoutMs?: number;\n}\n\n/**\n * Declare that a property's work runs inside a sandbox rather than in this process.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function UseSandbox(options: UseSandboxOptions = {}): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const existing: Map<string | symbol, UseSandboxOptions> =\n Reflect.getMetadata(METADATA_KEYS.SANDBOX, target.constructor) ?? new Map();\n existing.set(propertyKey, options);\n Reflect.defineMetadata(METADATA_KEYS.SANDBOX, existing, target.constructor);\n };\n}\n\n/** Every `@UseSandbox` on a class, keyed by the property it was applied to. */\nexport function readSandboxMetadata(\n target: abstract new (...args: never) => unknown,\n): ReadonlyMap<string | symbol, UseSandboxOptions> {\n return Reflect.getMetadata(METADATA_KEYS.SANDBOX, target) ?? new Map();\n}\n","import \"reflect-metadata\";\nimport { METADATA_KEYS } from \"@theokit/di\";\n\nimport type { DecoratedClass } from \"./decorated-class.js\";\n\n/** What {@link Workflow} declares about a workflow class: its `name`, an optional `retryPolicy`,\n * and the schemas its input and output are expected to match. */\nexport interface WorkflowOptions {\n name?: string;\n retryPolicy?: unknown;\n inputSchema?: unknown;\n outputSchema?: unknown;\n}\n\n/**\n * Mark a class as a workflow.\n *\n * This is the class-level marker only. The steps are declared with `@Step` on the methods, and\n * `buildWorkflow` compiles the two together into a runnable `@theokit/sdk` Workflow — which makes\n * it the one decorator in this package with a consumer that ships here.\n *\n * Records metadata only. Nothing in this package acts on it — the runtime that does lives in\n * `@theokit/sdk`, which is what lets the declaration and the execution version independently.\n */\nexport function Workflow(options: WorkflowOptions = {}): ClassDecorator {\n return (target) => {\n Reflect.defineMetadata(METADATA_KEYS.WORKFLOW, options, target);\n };\n}\n\n/** The `@Workflow` of a class, or `undefined` when it has none.\n *\n * Class decorators are singular by nature, so this returns one object or `undefined` — unlike the\n * property and method decorators, which accumulate into a map. */\nexport function readWorkflowMetadata(target: DecoratedClass): WorkflowOptions | undefined {\n return Reflect.getMetadata(METADATA_KEYS.WORKFLOW, target) as WorkflowOptions | undefined;\n}\n","import { Inject } from \"@theokit/di\";\n\nimport { AGENT_TOKEN } from \"./tokens.js\";\n\n/**\n * Parameter decorator — injects the REQUEST-scoped Agent into a constructor.\n * Equivalent to `@Inject(AGENT_TOKEN)` but documents intent.\n *\n * @example\n * @Injectable()\n * class ChatController {\n * constructor(@InjectAgent() private readonly agent: Agent) {}\n *\n * async chat(message: string) {\n * return this.agent.send(message);\n * }\n * }\n */\nexport function InjectAgent(): ParameterDecorator {\n return Inject(AGENT_TOKEN);\n}\n","/**\n * `buildWorkflow` — compile a `@Step`-decorated class instance into a\n * `@theokit/sdk` `Workflow`.\n *\n * This is the materializer/bridge for the decorator-driven workflow authoring\n * surface. It COMPOSES the existing `Workflow` engine — it\n * adds no orchestration logic of its own (same principle as `createSquad`).\n * Steps are topologically ordered by their single `after` dependency into a\n * linear `Workflow.then(...)` chain; each step's return value is threaded into\n * the next step. Branching/fan-out remains the imperative `Workflow` surface.\n *\n * NOTE: this module (unlike the metadata-only decorators) imports the\n * `@theokit/sdk` peer dependency — it is the bridge layer.\n */\n\nimport { fn, Workflow } from \"@theokit/sdk/workflow\";\nimport type { DecoratedClass } from \"./decorators/decorated-class.js\";\nimport { readStepMetadata, type StepMetadata } from \"./decorators/step.js\";\nimport { readWorkflowMetadata } from \"./decorators/workflow.js\";\n\ninterface ResolvedStep {\n key: string;\n id: string;\n after?: string;\n run: (input: unknown) => unknown;\n}\n\n/**\n * Build a `Workflow` from a `@Step`-decorated instance. Validates the step\n * graph (fail-fast) before constructing the workflow.\n *\n * @throws Error when there are no `@Step` methods, an `after` references an\n * unknown step, or the `after` graph contains a cycle.\n */\nexport function buildWorkflow(instance: object): Workflow {\n const ctor = instance.constructor as DecoratedClass;\n const meta = readStepMetadata(ctor);\n if (meta.size === 0) {\n throw new Error(`buildWorkflow: class \"${instance.constructor.name}\" has no @Step methods`);\n }\n\n const steps = resolveSteps(instance, meta);\n validateAfterTargets(steps);\n const ordered = topoSort(steps);\n\n const name = readWorkflowMetadata(instance.constructor as DecoratedClass)?.name ?? \"workflow\";\n let builder = Workflow.create({ name });\n for (const s of ordered) {\n builder = builder.then(fn(s.id, (input: unknown) => s.run(input)));\n }\n return builder.commit();\n}\n\n/** Resolve each `@Step` method into a runnable {@link ResolvedStep}. */\nfunction resolveSteps(\n instance: object,\n meta: ReadonlyMap<string | symbol, StepMetadata>,\n): Map<string, ResolvedStep> {\n const steps = new Map<string, ResolvedStep>();\n for (const [key, m] of meta) {\n const k = String(key);\n const method = (instance as Record<string, unknown>)[k];\n if (typeof method !== \"function\") {\n throw new Error(`buildWorkflow: @Step \"${k}\" is not a method`);\n }\n steps.set(k, {\n key: k,\n id: m.name ?? k,\n after: m.after,\n run: (input: unknown) => (method as (i: unknown) => unknown).call(instance, input),\n });\n }\n return steps;\n}\n\n/** Fail-fast if any `after` references a step that does not exist. */\nfunction validateAfterTargets(steps: Map<string, ResolvedStep>): void {\n for (const s of steps.values()) {\n if (s.after !== undefined && !steps.has(s.after)) {\n throw new Error(\n `buildWorkflow: @Step \"${s.key}\" declares after: \"${s.after}\" which is not a known @Step (unknown upstream)`,\n );\n }\n }\n}\n\n/**\n * Topologically order steps by their single `after` dependency. Entry steps\n * (no `after`) come first in declaration order; each dependent follows its\n * upstream. Throws on a cycle.\n */\nfunction topoSort(steps: Map<string, ResolvedStep>): ResolvedStep[] {\n const ordered: ResolvedStep[] = [];\n const placed = new Set<string>();\n const visiting = new Set<string>();\n\n const visit = (s: ResolvedStep): void => {\n if (placed.has(s.key)) return;\n if (visiting.has(s.key)) {\n throw new Error(`buildWorkflow: cycle detected in @Step \"after\" graph at \"${s.key}\"`);\n }\n visiting.add(s.key);\n if (s.after !== undefined) {\n const up = steps.get(s.after);\n if (up !== undefined) visit(up);\n }\n visiting.delete(s.key);\n placed.add(s.key);\n ordered.push(s);\n };\n\n for (const s of steps.values()) visit(s);\n return ordered;\n}\n"]}