@theokit/di-agent 0.1.0 → 0.3.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/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Scope, FactoryProvider } from '@theokit/di';
2
+ import { Workflow as Workflow$1 } from '@theokit/sdk/workflow';
2
3
 
3
4
  /**
4
5
  * Options accepted by `createAgentProvider()`. Mirrors the public
@@ -41,6 +42,345 @@ interface CreateAgentProviderOptions<TAgent> {
41
42
  */
42
43
  declare function createAgentProvider<TAgent>(options: CreateAgentProviderOptions<TAgent>): FactoryProvider<TAgent>;
43
44
 
45
+ /**
46
+ * The class a class decorator was applied to, as seen by the reader helpers.
47
+ *
48
+ * Spelled as a constructor signature rather than `Function`. `Function` is the widest callable
49
+ * type there is — it accepts any argument list and returns `any` — so it documents nothing and
50
+ * silently admits things that are not classes at all. The constructor form says what the readers
51
+ * actually receive: something you could have written `new` in front of.
52
+ *
53
+ * `abstract` so an abstract base class is accepted, and `...args: never` because the readers only
54
+ * ever pass the value to `Reflect.getMetadata` and never construct it, so the parameter list is
55
+ * deliberately unusable rather than merely unconstrained.
56
+ */
57
+ type DecoratedClass = abstract new (...args: never) => unknown;
58
+
59
+ /** What {@link Auth} declares: the identity `providers` this agent accepts, and any transport
60
+ * `sessionConfig` they need. */
61
+ interface AuthOptions {
62
+ providers?: string[];
63
+ sessionConfig?: unknown;
64
+ }
65
+ /**
66
+ * Declare how an agent class authenticates the caller.
67
+ *
68
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
69
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
70
+ */
71
+ declare function Auth(options?: AuthOptions): ClassDecorator;
72
+ /** The `@Auth` of a class, or `undefined` when it has none.
73
+ *
74
+ * Class decorators are singular by nature, so this returns one object or `undefined` — unlike the
75
+ * property and method decorators, which accumulate into a map. */
76
+ declare function readAuthMetadata(target: DecoratedClass): AuthOptions | undefined;
77
+
78
+ /** What {@link AutoSummarize} declares: the `triggerFraction` of the context window that starts a
79
+ * summarisation, how many recent turns to `keepNewest` verbatim, and optionally which `model`
80
+ * writes the summary. */
81
+ interface AutoSummarizeOptions {
82
+ triggerFraction?: number;
83
+ keepNewest?: number;
84
+ model?: string;
85
+ }
86
+ /**
87
+ * Declare that a conversation is summarised automatically as it approaches the context limit, so
88
+ * it can continue past the point where it would otherwise be truncated.
89
+ *
90
+ * Defaults are resolved at decoration time, so a reader of the metadata sees real values rather
91
+ * than having to know them.
92
+ *
93
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
94
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
95
+ */
96
+ declare function AutoSummarize(options?: AutoSummarizeOptions): ClassDecorator;
97
+ /** The `@AutoSummarize` of a class with its defaults resolved, or `undefined` when it has none.
98
+ *
99
+ * Class decorators are singular by nature, so this returns one object or `undefined` — unlike the
100
+ * property and method decorators, which accumulate into a map. */
101
+ declare function readAutoSummarizeMetadata(target: DecoratedClass): (Required<Omit<AutoSummarizeOptions, "model">> & {
102
+ model?: string;
103
+ }) | undefined;
104
+
105
+ /** What {@link Cron} declares: the `schedule` as a cron expression and the `timezone` it is read
106
+ * in. The expression is stored verbatim and never parsed here, so a malformed one surfaces
107
+ * wherever it is eventually scheduled. */
108
+ interface CronOptions {
109
+ schedule: string;
110
+ timezone?: string;
111
+ }
112
+ /** A stored `@Cron`, with the method it was applied to. The map is already keyed by that method;
113
+ * `methodKey` repeats it so an entry read on its own still says what it schedules. */
114
+ interface CronMetadata extends CronOptions {
115
+ methodKey: string | symbol;
116
+ }
117
+ /**
118
+ * `@Cron(options)` — declare a scheduled routine on a method.
119
+ *
120
+ * Accumulates per method, keyed by the method name, so a class may schedule as many
121
+ * routines as it has methods. It used to keep a single object per class, which meant a
122
+ * second `@Cron` on the same class silently discarded the first (#6).
123
+ */
124
+ declare function Cron(options: CronOptions): MethodDecorator;
125
+ /** Read `@Cron()` metadata off a class constructor, keyed by method (insertion-ordered). */
126
+ declare function readCronMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, CronMetadata>;
127
+
128
+ /** What {@link EvalDecorator} declares: the evaluation's `name`, the `scorers` that judge a run,
129
+ * and the `dataset` it runs against. */
130
+ interface EvalOptions {
131
+ name?: string;
132
+ scorers?: unknown[];
133
+ dataset?: unknown;
134
+ }
135
+ /**
136
+ * Declare an agent class as the subject of an evaluation.
137
+ *
138
+ * Named `EvalDecorator` rather than `Eval` because `eval` is a reserved word in strict mode, and
139
+ * an export nobody can import under its own name is worse than a longer one.
140
+ *
141
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
142
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
143
+ */
144
+ declare function EvalDecorator(options?: EvalOptions): ClassDecorator;
145
+ /** The `@EvalDecorator` of a class, or `undefined` when it has none.
146
+ *
147
+ * Class decorators are singular by nature, so this returns one object or `undefined` — unlike the
148
+ * property and method decorators, which accumulate into a map. */
149
+ declare function readEvalDecoratorMetadata(target: DecoratedClass): EvalOptions | undefined;
150
+
151
+ /** What {@link Hitl} declares: the `tools` whose invocation needs a human decision, and the
152
+ * `timeoutMs` after which waiting stops. */
153
+ interface HitlOptions {
154
+ tools: string[];
155
+ timeoutMs?: number;
156
+ }
157
+ /** A stored `@Hitl`, with the method it was applied to. The map is already keyed by that method;
158
+ * `methodKey` repeats it so an entry read on its own still says what it guards. */
159
+ interface HitlMetadata extends HitlOptions {
160
+ methodKey: string | symbol;
161
+ }
162
+ /**
163
+ * `@Hitl(options)` — declare a human-in-the-loop approval handler on a method.
164
+ *
165
+ * Accumulates per method, keyed by the method name, so a class may declare as many
166
+ * handlers as it has methods. It used to keep a single object per class, which meant a
167
+ * second `@Hitl` on the same class silently discarded the first (#6).
168
+ */
169
+ declare function Hitl(options: HitlOptions): MethodDecorator;
170
+ /** Read `@Hitl()` metadata off a class constructor, keyed by method (insertion-ordered). */
171
+ declare function readHitlMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, HitlMetadata>;
172
+
173
+ /** What {@link MemoryScopeDecorator} declares: the `path` naming this scope's place in the
174
+ * memory hierarchy. */
175
+ interface MemoryScopeOptions {
176
+ path: string;
177
+ }
178
+ /**
179
+ * Declare the memory scope a property reads and writes, so sibling scopes stay isolated from
180
+ * each other while a child can still see its parent.
181
+ *
182
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
183
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
184
+ */
185
+ declare function MemoryScopeDecorator(options: MemoryScopeOptions): PropertyDecorator;
186
+ /** Every `@MemoryScopeDecorator` on a class, keyed by the property it was applied to. */
187
+ declare function readMemoryScopeMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, MemoryScopeOptions>;
188
+
189
+ /** What {@link Reranker} declares: which provider and model score the candidates, and how many
190
+ * survive (`topN`). */
191
+ interface RerankerOptions {
192
+ provider?: string;
193
+ model?: string;
194
+ topN?: number;
195
+ }
196
+ /**
197
+ * Declare a property as the reranking step that reorders what a retriever returned.
198
+ *
199
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
200
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
201
+ */
202
+ declare function Reranker(options: RerankerOptions): PropertyDecorator;
203
+ /** Every `@Reranker` on a class, keyed by the property it was applied to. */
204
+ declare function readRerankerMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, RerankerOptions>;
205
+
206
+ /** What {@link Retriever} declares: how many passages to return (`topK`) and the minimum score
207
+ * a passage needs to be worth returning at all (`threshold`). */
208
+ interface RetrieverOptions {
209
+ topK?: number;
210
+ threshold?: number;
211
+ }
212
+ /**
213
+ * Declare a property as the retrieval step of a RAG pipeline.
214
+ *
215
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
216
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
217
+ */
218
+ declare function Retriever(options: RetrieverOptions): PropertyDecorator;
219
+ /** Every `@Retriever` on a class, keyed by the property it was applied to. */
220
+ declare function readRetrieverMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, RetrieverOptions>;
221
+
222
+ /**
223
+ * Metadata captured by the `@Squad()` property decorator. Declares a sequential
224
+ * agent team by referencing the agent property names that compose it. Mirrors
225
+ * the `@theokit/sdk` `createSquad` factory (decorator mandate — every agentic
226
+ * capability ships a decorator alongside the factory).
227
+ */
228
+ interface SquadMetadata {
229
+ /** Agent property names (or ids) that run in order. */
230
+ agents: string[];
231
+ /** Orchestration process. Default (omitted) = `"sequential"`. */
232
+ process?: "sequential" | "hierarchical";
233
+ /** Optional squad name. */
234
+ name?: string;
235
+ }
236
+ /**
237
+ * `@Squad(metadata)` — declare a sequential agent team on a property. The DI
238
+ * container / agent provider materializes it into a `createSquad(...)` at wiring
239
+ * time.
240
+ */
241
+ declare function Squad(metadata: SquadMetadata): PropertyDecorator;
242
+ /** Read `@Squad()` metadata off a class constructor. */
243
+ declare function readSquadMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, SquadMetadata>;
244
+
245
+ /**
246
+ * Metadata captured by the `@Step()` method decorator. Declares one step of a
247
+ * decorator-driven workflow and its single upstream dependency. Compiled into
248
+ * a `@theokit/sdk` `Workflow` by `buildWorkflow` (decorator mandate — every
249
+ * agentic capability ships a decorator alongside the factory/builder).
250
+ */
251
+ interface StepMetadata {
252
+ /**
253
+ * Method name of the upstream step this step runs after. Omitted = entry
254
+ * step (receives the workflow input). MVP supports a single dependency
255
+ * (linear chain); branching/fan-out stays the imperative `Workflow` surface.
256
+ */
257
+ after?: string;
258
+ /** Optional step id (defaults to the method name). */
259
+ name?: string;
260
+ }
261
+ /**
262
+ * `@Step(metadata?)` — mark a class method as a workflow step. The method
263
+ * receives the upstream step's return value (or the workflow input for an
264
+ * entry step) and returns this step's output.
265
+ */
266
+ declare function Step(metadata?: StepMetadata): MethodDecorator;
267
+ /** Read `@Step()` metadata off a class constructor (insertion-ordered). */
268
+ declare function readStepMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, StepMetadata>;
269
+
270
+ /** What {@link SubAgent} declares: how the parent agent describes the delegate when deciding
271
+ * whether to hand work over, and optionally which model it runs on and how deep delegation may
272
+ * nest before it stops. */
273
+ interface SubAgentOptions {
274
+ name: string;
275
+ description: string;
276
+ instructions: string;
277
+ model?: string;
278
+ maxDelegationDepth?: number;
279
+ }
280
+ /**
281
+ * Declare a property as a subagent this one may delegate to, exposed to the parent as a tool.
282
+ *
283
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
284
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
285
+ */
286
+ declare function SubAgent(options: SubAgentOptions): PropertyDecorator;
287
+ /** Every `@SubAgent` on a class, keyed by the property it was applied to. */
288
+ declare function readSubAgentMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, SubAgentOptions>;
289
+
290
+ /** What {@link Subscription} declares: the event `name` to listen for, and optionally the
291
+ * `transport` it arrives on. */
292
+ interface SubscriptionOptions {
293
+ name: string;
294
+ transport?: string;
295
+ }
296
+ /**
297
+ * Declare a property as a subscription to an event stream.
298
+ *
299
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
300
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
301
+ */
302
+ declare function Subscription(options: SubscriptionOptions): PropertyDecorator;
303
+ /** Every `@Subscription` on a class, keyed by the property it was applied to. */
304
+ declare function readSubscriptionMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, SubscriptionOptions>;
305
+
306
+ /** What {@link TextSplitter} declares: the splitting `strategy`, the target `chunkSize`, and how
307
+ * much `overlap` consecutive chunks share so a passage split mid-sentence is still retrievable
308
+ * from either side. */
309
+ interface TextSplitterOptions {
310
+ strategy?: string;
311
+ chunkSize?: number;
312
+ overlap?: number;
313
+ }
314
+ /**
315
+ * Declare a property as the step that breaks documents into indexable chunks.
316
+ *
317
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
318
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
319
+ */
320
+ declare function TextSplitter(options: TextSplitterOptions): PropertyDecorator;
321
+ /** Every `@TextSplitter` on a class, keyed by the property it was applied to. */
322
+ declare function readTextSplitterMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, TextSplitterOptions>;
323
+
324
+ /** What {@link Tool} declares about one tool: the name and description an agent sees when
325
+ * choosing it, and optionally the schema its input must match. */
326
+ interface ToolOptions {
327
+ name: string;
328
+ description: string;
329
+ inputSchema?: unknown;
330
+ }
331
+ /**
332
+ * Declare a property as a tool an agent may call.
333
+ *
334
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
335
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
336
+ */
337
+ declare function Tool(options: ToolOptions): PropertyDecorator;
338
+ /** Every `@Tool` on a class, keyed by the property it was applied to. Empty map when there are
339
+ * none — a class with no tools is ordinary, not an error. */
340
+ declare function readToolMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, ToolOptions>;
341
+
342
+ /** What {@link UseSandbox} declares: which `backend` isolates the execution, the `workDir` it
343
+ * starts in, and the `timeoutMs` after which it is abandoned. */
344
+ interface UseSandboxOptions {
345
+ backend?: "local" | "docker" | string;
346
+ workDir?: string;
347
+ timeoutMs?: number;
348
+ }
349
+ /**
350
+ * Declare that a property's work runs inside a sandbox rather than in this process.
351
+ *
352
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
353
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
354
+ */
355
+ declare function UseSandbox(options?: UseSandboxOptions): PropertyDecorator;
356
+ /** Every `@UseSandbox` on a class, keyed by the property it was applied to. */
357
+ declare function readSandboxMetadata(target: abstract new (...args: never) => unknown): ReadonlyMap<string | symbol, UseSandboxOptions>;
358
+
359
+ /** What {@link Workflow} declares about a workflow class: its `name`, an optional `retryPolicy`,
360
+ * and the schemas its input and output are expected to match. */
361
+ interface WorkflowOptions {
362
+ name?: string;
363
+ retryPolicy?: unknown;
364
+ inputSchema?: unknown;
365
+ outputSchema?: unknown;
366
+ }
367
+ /**
368
+ * Mark a class as a workflow.
369
+ *
370
+ * This is the class-level marker only. The steps are declared with `@Step` on the methods, and
371
+ * `buildWorkflow` compiles the two together into a runnable `@theokit/sdk` Workflow — which makes
372
+ * it the one decorator in this package with a consumer that ships here.
373
+ *
374
+ * Records metadata only. Nothing in this package acts on it — the runtime that does lives in
375
+ * `@theokit/sdk`, which is what lets the declaration and the execution version independently.
376
+ */
377
+ declare function Workflow(options?: WorkflowOptions): ClassDecorator;
378
+ /** The `@Workflow` of a class, or `undefined` when it has none.
379
+ *
380
+ * Class decorators are singular by nature, so this returns one object or `undefined` — unlike the
381
+ * property and method decorators, which accumulate into a map. */
382
+ declare function readWorkflowMetadata(target: DecoratedClass): WorkflowOptions | undefined;
383
+
44
384
  /**
45
385
  * Parameter decorator — injects the REQUEST-scoped Agent into a constructor.
46
386
  * Equivalent to `@Inject(AGENT_TOKEN)` but documents intent.
@@ -64,4 +404,28 @@ declare function InjectAgent(): ParameterDecorator;
64
404
  */
65
405
  declare const AGENT_TOKEN = "@theokit/di-agent:Agent";
66
406
 
67
- export { AGENT_TOKEN, type CreateAgentProviderOptions, InjectAgent, createAgentProvider };
407
+ /**
408
+ * `buildWorkflow` — compile a `@Step`-decorated class instance into a
409
+ * `@theokit/sdk` `Workflow`.
410
+ *
411
+ * This is the materializer/bridge for the decorator-driven workflow authoring
412
+ * surface. It COMPOSES the existing `Workflow` engine — it
413
+ * adds no orchestration logic of its own (same principle as `createSquad`).
414
+ * Steps are topologically ordered by their single `after` dependency into a
415
+ * linear `Workflow.then(...)` chain; each step's return value is threaded into
416
+ * the next step. Branching/fan-out remains the imperative `Workflow` surface.
417
+ *
418
+ * NOTE: this module (unlike the metadata-only decorators) imports the
419
+ * `@theokit/sdk` peer dependency — it is the bridge layer.
420
+ */
421
+
422
+ /**
423
+ * Build a `Workflow` from a `@Step`-decorated instance. Validates the step
424
+ * graph (fail-fast) before constructing the workflow.
425
+ *
426
+ * @throws Error when there are no `@Step` methods, an `after` references an
427
+ * unknown step, or the `after` graph contains a cycle.
428
+ */
429
+ declare function buildWorkflow(instance: object): Workflow$1;
430
+
431
+ export { AGENT_TOKEN, Auth, type AuthOptions, AutoSummarize, type AutoSummarizeOptions, type CreateAgentProviderOptions, Cron, type CronMetadata, type CronOptions, type DecoratedClass, EvalDecorator, type EvalOptions, Hitl, type HitlMetadata, type HitlOptions, InjectAgent, MemoryScopeDecorator, type MemoryScopeOptions, Reranker, type RerankerOptions, Retriever, type RetrieverOptions, Squad, type SquadMetadata, Step, type StepMetadata, SubAgent, type SubAgentOptions, Subscription, type SubscriptionOptions, TextSplitter, type TextSplitterOptions, Tool, type ToolOptions, UseSandbox, type UseSandboxOptions, Workflow, type WorkflowOptions, buildWorkflow, createAgentProvider, readAuthMetadata, readAutoSummarizeMetadata, readCronMetadata, readEvalDecoratorMetadata, readHitlMetadata, readMemoryScopeMetadata, readRerankerMetadata, readRetrieverMetadata, readSandboxMetadata, readSquadMetadata, readStepMetadata, readSubAgentMetadata, readSubscriptionMetadata, readTextSplitterMetadata, readToolMetadata, readWorkflowMetadata };
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
- import { Scope, Inject } from '@theokit/di';
1
+ import { Scope, METADATA_KEYS, Inject } from '@theokit/di';
2
+ import 'reflect-metadata';
3
+ import { Workflow as Workflow$1, fn } from '@theokit/sdk/workflow';
2
4
 
3
5
  var __defProp = Object.defineProperty;
4
6
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -15,11 +17,276 @@ function createAgentProvider(options) {
15
17
  };
16
18
  }
17
19
  __name(createAgentProvider, "createAgentProvider");
20
+ function Auth(options = {}) {
21
+ return (target) => {
22
+ Reflect.defineMetadata(METADATA_KEYS.AUTH, options, target);
23
+ };
24
+ }
25
+ __name(Auth, "Auth");
26
+ function readAuthMetadata(target) {
27
+ return Reflect.getMetadata(METADATA_KEYS.AUTH, target);
28
+ }
29
+ __name(readAuthMetadata, "readAuthMetadata");
30
+ var DEFAULTS = {
31
+ triggerFraction: 0.85,
32
+ keepNewest: 4
33
+ };
34
+ function AutoSummarize(options = {}) {
35
+ return (target) => {
36
+ const resolved = {
37
+ ...DEFAULTS,
38
+ ...options
39
+ };
40
+ Reflect.defineMetadata(METADATA_KEYS.AUTO_SUMMARIZE, resolved, target);
41
+ };
42
+ }
43
+ __name(AutoSummarize, "AutoSummarize");
44
+ function readAutoSummarizeMetadata(target) {
45
+ return Reflect.getMetadata(METADATA_KEYS.AUTO_SUMMARIZE, target);
46
+ }
47
+ __name(readAutoSummarizeMetadata, "readAutoSummarizeMetadata");
48
+ function Cron(options) {
49
+ return (target, propertyKey, _descriptor) => {
50
+ const existing = Reflect.getMetadata(METADATA_KEYS.CRON, target.constructor) ?? /* @__PURE__ */ new Map();
51
+ existing.set(propertyKey, {
52
+ ...options,
53
+ methodKey: propertyKey
54
+ });
55
+ Reflect.defineMetadata(METADATA_KEYS.CRON, existing, target.constructor);
56
+ };
57
+ }
58
+ __name(Cron, "Cron");
59
+ function readCronMetadata(target) {
60
+ return Reflect.getMetadata(METADATA_KEYS.CRON, target) ?? /* @__PURE__ */ new Map();
61
+ }
62
+ __name(readCronMetadata, "readCronMetadata");
63
+ function EvalDecorator(options = {}) {
64
+ return (target) => {
65
+ Reflect.defineMetadata(METADATA_KEYS.EVAL, options, target);
66
+ };
67
+ }
68
+ __name(EvalDecorator, "EvalDecorator");
69
+ function readEvalDecoratorMetadata(target) {
70
+ return Reflect.getMetadata(METADATA_KEYS.EVAL, target);
71
+ }
72
+ __name(readEvalDecoratorMetadata, "readEvalDecoratorMetadata");
73
+ function Hitl(options) {
74
+ return (target, propertyKey, _descriptor) => {
75
+ const existing = Reflect.getMetadata(METADATA_KEYS.HITL, target.constructor) ?? /* @__PURE__ */ new Map();
76
+ existing.set(propertyKey, {
77
+ ...options,
78
+ methodKey: propertyKey
79
+ });
80
+ Reflect.defineMetadata(METADATA_KEYS.HITL, existing, target.constructor);
81
+ };
82
+ }
83
+ __name(Hitl, "Hitl");
84
+ function readHitlMetadata(target) {
85
+ return Reflect.getMetadata(METADATA_KEYS.HITL, target) ?? /* @__PURE__ */ new Map();
86
+ }
87
+ __name(readHitlMetadata, "readHitlMetadata");
88
+ function MemoryScopeDecorator(options) {
89
+ return (target, propertyKey) => {
90
+ const existing = Reflect.getMetadata(METADATA_KEYS.MEMORY_SCOPE, target.constructor) ?? /* @__PURE__ */ new Map();
91
+ existing.set(propertyKey, options);
92
+ Reflect.defineMetadata(METADATA_KEYS.MEMORY_SCOPE, existing, target.constructor);
93
+ };
94
+ }
95
+ __name(MemoryScopeDecorator, "MemoryScopeDecorator");
96
+ function readMemoryScopeMetadata(target) {
97
+ return Reflect.getMetadata(METADATA_KEYS.MEMORY_SCOPE, target) ?? /* @__PURE__ */ new Map();
98
+ }
99
+ __name(readMemoryScopeMetadata, "readMemoryScopeMetadata");
100
+ function Reranker(options) {
101
+ return (target, propertyKey) => {
102
+ const existing = Reflect.getMetadata(METADATA_KEYS.RERANKER, target.constructor) ?? /* @__PURE__ */ new Map();
103
+ existing.set(propertyKey, options);
104
+ Reflect.defineMetadata(METADATA_KEYS.RERANKER, existing, target.constructor);
105
+ };
106
+ }
107
+ __name(Reranker, "Reranker");
108
+ function readRerankerMetadata(target) {
109
+ return Reflect.getMetadata(METADATA_KEYS.RERANKER, target) ?? /* @__PURE__ */ new Map();
110
+ }
111
+ __name(readRerankerMetadata, "readRerankerMetadata");
112
+ function Retriever(options) {
113
+ return (target, propertyKey) => {
114
+ const existing = Reflect.getMetadata(METADATA_KEYS.RETRIEVER, target.constructor) ?? /* @__PURE__ */ new Map();
115
+ existing.set(propertyKey, options);
116
+ Reflect.defineMetadata(METADATA_KEYS.RETRIEVER, existing, target.constructor);
117
+ };
118
+ }
119
+ __name(Retriever, "Retriever");
120
+ function readRetrieverMetadata(target) {
121
+ return Reflect.getMetadata(METADATA_KEYS.RETRIEVER, target) ?? /* @__PURE__ */ new Map();
122
+ }
123
+ __name(readRetrieverMetadata, "readRetrieverMetadata");
124
+ function Squad(metadata) {
125
+ return (target, propertyKey) => {
126
+ const existing = Reflect.getMetadata(METADATA_KEYS.SQUAD, target.constructor) ?? /* @__PURE__ */ new Map();
127
+ existing.set(propertyKey, metadata);
128
+ Reflect.defineMetadata(METADATA_KEYS.SQUAD, existing, target.constructor);
129
+ };
130
+ }
131
+ __name(Squad, "Squad");
132
+ function readSquadMetadata(target) {
133
+ return Reflect.getMetadata(METADATA_KEYS.SQUAD, target) ?? /* @__PURE__ */ new Map();
134
+ }
135
+ __name(readSquadMetadata, "readSquadMetadata");
136
+ function Step(metadata = {}) {
137
+ return (target, propertyKey) => {
138
+ const existing = Reflect.getMetadata(METADATA_KEYS.STEP, target.constructor) ?? /* @__PURE__ */ new Map();
139
+ existing.set(propertyKey, metadata);
140
+ Reflect.defineMetadata(METADATA_KEYS.STEP, existing, target.constructor);
141
+ };
142
+ }
143
+ __name(Step, "Step");
144
+ function readStepMetadata(target) {
145
+ return Reflect.getMetadata(METADATA_KEYS.STEP, target) ?? /* @__PURE__ */ new Map();
146
+ }
147
+ __name(readStepMetadata, "readStepMetadata");
148
+ function SubAgent(options) {
149
+ return (target, propertyKey) => {
150
+ const existing = Reflect.getMetadata(METADATA_KEYS.SUBAGENT, target.constructor) ?? /* @__PURE__ */ new Map();
151
+ existing.set(propertyKey, options);
152
+ Reflect.defineMetadata(METADATA_KEYS.SUBAGENT, existing, target.constructor);
153
+ };
154
+ }
155
+ __name(SubAgent, "SubAgent");
156
+ function readSubAgentMetadata(target) {
157
+ return Reflect.getMetadata(METADATA_KEYS.SUBAGENT, target) ?? /* @__PURE__ */ new Map();
158
+ }
159
+ __name(readSubAgentMetadata, "readSubAgentMetadata");
160
+ function Subscription(options) {
161
+ return (target, propertyKey) => {
162
+ const existing = Reflect.getMetadata(METADATA_KEYS.SUBSCRIPTION, target.constructor) ?? /* @__PURE__ */ new Map();
163
+ existing.set(propertyKey, options);
164
+ Reflect.defineMetadata(METADATA_KEYS.SUBSCRIPTION, existing, target.constructor);
165
+ };
166
+ }
167
+ __name(Subscription, "Subscription");
168
+ function readSubscriptionMetadata(target) {
169
+ return Reflect.getMetadata(METADATA_KEYS.SUBSCRIPTION, target) ?? /* @__PURE__ */ new Map();
170
+ }
171
+ __name(readSubscriptionMetadata, "readSubscriptionMetadata");
172
+ function TextSplitter(options) {
173
+ return (target, propertyKey) => {
174
+ const existing = Reflect.getMetadata(METADATA_KEYS.TEXT_SPLITTER, target.constructor) ?? /* @__PURE__ */ new Map();
175
+ existing.set(propertyKey, options);
176
+ Reflect.defineMetadata(METADATA_KEYS.TEXT_SPLITTER, existing, target.constructor);
177
+ };
178
+ }
179
+ __name(TextSplitter, "TextSplitter");
180
+ function readTextSplitterMetadata(target) {
181
+ return Reflect.getMetadata(METADATA_KEYS.TEXT_SPLITTER, target) ?? /* @__PURE__ */ new Map();
182
+ }
183
+ __name(readTextSplitterMetadata, "readTextSplitterMetadata");
184
+ function Tool(options) {
185
+ return (target, propertyKey) => {
186
+ const existing = Reflect.getMetadata(METADATA_KEYS.TOOL, target.constructor) ?? /* @__PURE__ */ new Map();
187
+ existing.set(propertyKey, options);
188
+ Reflect.defineMetadata(METADATA_KEYS.TOOL, existing, target.constructor);
189
+ };
190
+ }
191
+ __name(Tool, "Tool");
192
+ function readToolMetadata(target) {
193
+ return Reflect.getMetadata(METADATA_KEYS.TOOL, target) ?? /* @__PURE__ */ new Map();
194
+ }
195
+ __name(readToolMetadata, "readToolMetadata");
196
+ function UseSandbox(options = {}) {
197
+ return (target, propertyKey) => {
198
+ const existing = Reflect.getMetadata(METADATA_KEYS.SANDBOX, target.constructor) ?? /* @__PURE__ */ new Map();
199
+ existing.set(propertyKey, options);
200
+ Reflect.defineMetadata(METADATA_KEYS.SANDBOX, existing, target.constructor);
201
+ };
202
+ }
203
+ __name(UseSandbox, "UseSandbox");
204
+ function readSandboxMetadata(target) {
205
+ return Reflect.getMetadata(METADATA_KEYS.SANDBOX, target) ?? /* @__PURE__ */ new Map();
206
+ }
207
+ __name(readSandboxMetadata, "readSandboxMetadata");
208
+ function Workflow(options = {}) {
209
+ return (target) => {
210
+ Reflect.defineMetadata(METADATA_KEYS.WORKFLOW, options, target);
211
+ };
212
+ }
213
+ __name(Workflow, "Workflow");
214
+ function readWorkflowMetadata(target) {
215
+ return Reflect.getMetadata(METADATA_KEYS.WORKFLOW, target);
216
+ }
217
+ __name(readWorkflowMetadata, "readWorkflowMetadata");
18
218
  function InjectAgent() {
19
219
  return Inject(AGENT_TOKEN);
20
220
  }
21
221
  __name(InjectAgent, "InjectAgent");
222
+ function buildWorkflow(instance) {
223
+ const ctor = instance.constructor;
224
+ const meta = readStepMetadata(ctor);
225
+ if (meta.size === 0) {
226
+ throw new Error(`buildWorkflow: class "${instance.constructor.name}" has no @Step methods`);
227
+ }
228
+ const steps = resolveSteps(instance, meta);
229
+ validateAfterTargets(steps);
230
+ const ordered = topoSort(steps);
231
+ const name = readWorkflowMetadata(instance.constructor)?.name ?? "workflow";
232
+ let builder = Workflow$1.create({
233
+ name
234
+ });
235
+ for (const s of ordered) {
236
+ builder = builder.then(fn(s.id, (input) => s.run(input)));
237
+ }
238
+ return builder.commit();
239
+ }
240
+ __name(buildWorkflow, "buildWorkflow");
241
+ function resolveSteps(instance, meta) {
242
+ const steps = /* @__PURE__ */ new Map();
243
+ for (const [key, m] of meta) {
244
+ const k = String(key);
245
+ const method = instance[k];
246
+ if (typeof method !== "function") {
247
+ throw new Error(`buildWorkflow: @Step "${k}" is not a method`);
248
+ }
249
+ steps.set(k, {
250
+ key: k,
251
+ id: m.name ?? k,
252
+ after: m.after,
253
+ run: /* @__PURE__ */ __name((input) => method.call(instance, input), "run")
254
+ });
255
+ }
256
+ return steps;
257
+ }
258
+ __name(resolveSteps, "resolveSteps");
259
+ function validateAfterTargets(steps) {
260
+ for (const s of steps.values()) {
261
+ if (s.after !== void 0 && !steps.has(s.after)) {
262
+ throw new Error(`buildWorkflow: @Step "${s.key}" declares after: "${s.after}" which is not a known @Step (unknown upstream)`);
263
+ }
264
+ }
265
+ }
266
+ __name(validateAfterTargets, "validateAfterTargets");
267
+ function topoSort(steps) {
268
+ const ordered = [];
269
+ const placed = /* @__PURE__ */ new Set();
270
+ const visiting = /* @__PURE__ */ new Set();
271
+ const visit = /* @__PURE__ */ __name((s) => {
272
+ if (placed.has(s.key)) return;
273
+ if (visiting.has(s.key)) {
274
+ throw new Error(`buildWorkflow: cycle detected in @Step "after" graph at "${s.key}"`);
275
+ }
276
+ visiting.add(s.key);
277
+ if (s.after !== void 0) {
278
+ const up = steps.get(s.after);
279
+ if (up !== void 0) visit(up);
280
+ }
281
+ visiting.delete(s.key);
282
+ placed.add(s.key);
283
+ ordered.push(s);
284
+ }, "visit");
285
+ for (const s of steps.values()) visit(s);
286
+ return ordered;
287
+ }
288
+ __name(topoSort, "topoSort");
22
289
 
23
- export { AGENT_TOKEN, InjectAgent, createAgentProvider };
290
+ export { AGENT_TOKEN, Auth, AutoSummarize, Cron, EvalDecorator, Hitl, InjectAgent, MemoryScopeDecorator, Reranker, Retriever, Squad, Step, SubAgent, Subscription, TextSplitter, Tool, UseSandbox, Workflow, buildWorkflow, createAgentProvider, readAuthMetadata, readAutoSummarizeMetadata, readCronMetadata, readEvalDecoratorMetadata, readHitlMetadata, readMemoryScopeMetadata, readRerankerMetadata, readRetrieverMetadata, readSandboxMetadata, readSquadMetadata, readStepMetadata, readSubAgentMetadata, readSubscriptionMetadata, readTextSplitterMetadata, readToolMetadata, readWorkflowMetadata };
24
291
  //# sourceMappingURL=index.js.map
25
292
  //# sourceMappingURL=index.js.map