@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/CHANGELOG.md +42 -2
- package/LICENSE +2 -2
- package/dist/index.cjs +300 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +365 -1
- package/dist/index.d.ts +365 -1
- package/dist/index.js +269 -2
- package/dist/index.js.map +1 -1
- package/package.json +21 -17
package/CHANGELOG.md
CHANGED
|
@@ -5,14 +5,54 @@ All notable changes to `@theokit/di-agent` are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.3.0] - 2026-08-21
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Every published export now carries documentation an editor can show. Measured on the emitted
|
|
15
|
+
declarations, 16/56 to 56/56. Each decorator now states the thing a reader cannot infer from its
|
|
16
|
+
signature: this package records metadata and nothing here acts on it — the runtime that
|
|
17
|
+
does lives in `@theokit/sdk`. (#24)
|
|
18
|
+
|
|
19
|
+
- 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.
|
|
20
|
+
- `DecoratedClass` — the constructor type the decorator reader helpers accept, exported so consumers can name it.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- The peer range on `@theokit/di` accepts `^0.2.0` alongside `^0.1.0-next.0`. `@theokit/di`
|
|
25
|
+
ships breaking disposal fixes as `0.2.0`, which falls outside the old range; without this,
|
|
26
|
+
installing both current versions would report an unmet peer dependency, and the release
|
|
27
|
+
tooling would force this package to `1.0.0` to express the incompatibility. Nothing here
|
|
28
|
+
uses the behaviour that changed — the decorators record metadata and the container never
|
|
29
|
+
disposed anything this package registers. (#20)
|
|
30
|
+
- `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.
|
|
31
|
+
- `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.
|
|
32
|
+
- JSDoc and comments no longer cite plan tasks or edge-case identifiers that exist in no repository a reader can reach.
|
|
33
|
+
- **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).
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## 0.2.0
|
|
37
|
+
|
|
38
|
+
### Minor Changes
|
|
39
|
+
|
|
40
|
+
- Decorator-driven agent-team + workflow authoring (own identity — composition over a new engine).
|
|
41
|
+
|
|
42
|
+
- **`@Squad(metadata)`** property decorator + `readSquadMetadata` — declarative sequential agent team backed by `@theokit/di` `METADATA_KEYS.SQUAD`.
|
|
43
|
+
- **`@Step(metadata?)`** method decorator + `readStepMetadata` (`{ after?, name? }`) backed by `METADATA_KEYS.STEP`.
|
|
44
|
+
- **`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`.
|
|
45
|
+
|
|
46
|
+
First npm publish of these decorators (`0.1.0` on npm is the scaffold).
|
|
47
|
+
|
|
8
48
|
## [0.1.0] - 2026-05-31
|
|
9
49
|
|
|
10
50
|
> First GA release. Promotes `0.1.0-next.0` to stable. API contract preserved — no breaking changes from `0.1.0-next.0`.
|
|
11
51
|
|
|
12
52
|
### Changed
|
|
13
53
|
|
|
14
|
-
- 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
|
|
15
|
-
- Dropped unused `@vitest/coverage-v8` devDependency.
|
|
54
|
+
- 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`.
|
|
55
|
+
- Dropped the unused `@vitest/coverage-v8` devDependency.
|
|
16
56
|
|
|
17
57
|
## [0.1.0-next.0] - 2026-05-29
|
|
18
58
|
|
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
|
|
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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var di = require('@theokit/di');
|
|
4
|
+
require('reflect-metadata');
|
|
5
|
+
var workflow = require('@theokit/sdk/workflow');
|
|
4
6
|
|
|
5
7
|
var __defProp = Object.defineProperty;
|
|
6
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -17,13 +19,311 @@ function createAgentProvider(options) {
|
|
|
17
19
|
};
|
|
18
20
|
}
|
|
19
21
|
__name(createAgentProvider, "createAgentProvider");
|
|
22
|
+
function Auth(options = {}) {
|
|
23
|
+
return (target) => {
|
|
24
|
+
Reflect.defineMetadata(di.METADATA_KEYS.AUTH, options, target);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
__name(Auth, "Auth");
|
|
28
|
+
function readAuthMetadata(target) {
|
|
29
|
+
return Reflect.getMetadata(di.METADATA_KEYS.AUTH, target);
|
|
30
|
+
}
|
|
31
|
+
__name(readAuthMetadata, "readAuthMetadata");
|
|
32
|
+
var DEFAULTS = {
|
|
33
|
+
triggerFraction: 0.85,
|
|
34
|
+
keepNewest: 4
|
|
35
|
+
};
|
|
36
|
+
function AutoSummarize(options = {}) {
|
|
37
|
+
return (target) => {
|
|
38
|
+
const resolved = {
|
|
39
|
+
...DEFAULTS,
|
|
40
|
+
...options
|
|
41
|
+
};
|
|
42
|
+
Reflect.defineMetadata(di.METADATA_KEYS.AUTO_SUMMARIZE, resolved, target);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
__name(AutoSummarize, "AutoSummarize");
|
|
46
|
+
function readAutoSummarizeMetadata(target) {
|
|
47
|
+
return Reflect.getMetadata(di.METADATA_KEYS.AUTO_SUMMARIZE, target);
|
|
48
|
+
}
|
|
49
|
+
__name(readAutoSummarizeMetadata, "readAutoSummarizeMetadata");
|
|
50
|
+
function Cron(options) {
|
|
51
|
+
return (target, propertyKey, _descriptor) => {
|
|
52
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.CRON, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
53
|
+
existing.set(propertyKey, {
|
|
54
|
+
...options,
|
|
55
|
+
methodKey: propertyKey
|
|
56
|
+
});
|
|
57
|
+
Reflect.defineMetadata(di.METADATA_KEYS.CRON, existing, target.constructor);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
__name(Cron, "Cron");
|
|
61
|
+
function readCronMetadata(target) {
|
|
62
|
+
return Reflect.getMetadata(di.METADATA_KEYS.CRON, target) ?? /* @__PURE__ */ new Map();
|
|
63
|
+
}
|
|
64
|
+
__name(readCronMetadata, "readCronMetadata");
|
|
65
|
+
function EvalDecorator(options = {}) {
|
|
66
|
+
return (target) => {
|
|
67
|
+
Reflect.defineMetadata(di.METADATA_KEYS.EVAL, options, target);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
__name(EvalDecorator, "EvalDecorator");
|
|
71
|
+
function readEvalDecoratorMetadata(target) {
|
|
72
|
+
return Reflect.getMetadata(di.METADATA_KEYS.EVAL, target);
|
|
73
|
+
}
|
|
74
|
+
__name(readEvalDecoratorMetadata, "readEvalDecoratorMetadata");
|
|
75
|
+
function Hitl(options) {
|
|
76
|
+
return (target, propertyKey, _descriptor) => {
|
|
77
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.HITL, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
78
|
+
existing.set(propertyKey, {
|
|
79
|
+
...options,
|
|
80
|
+
methodKey: propertyKey
|
|
81
|
+
});
|
|
82
|
+
Reflect.defineMetadata(di.METADATA_KEYS.HITL, existing, target.constructor);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
__name(Hitl, "Hitl");
|
|
86
|
+
function readHitlMetadata(target) {
|
|
87
|
+
return Reflect.getMetadata(di.METADATA_KEYS.HITL, target) ?? /* @__PURE__ */ new Map();
|
|
88
|
+
}
|
|
89
|
+
__name(readHitlMetadata, "readHitlMetadata");
|
|
90
|
+
function MemoryScopeDecorator(options) {
|
|
91
|
+
return (target, propertyKey) => {
|
|
92
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.MEMORY_SCOPE, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
93
|
+
existing.set(propertyKey, options);
|
|
94
|
+
Reflect.defineMetadata(di.METADATA_KEYS.MEMORY_SCOPE, existing, target.constructor);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
__name(MemoryScopeDecorator, "MemoryScopeDecorator");
|
|
98
|
+
function readMemoryScopeMetadata(target) {
|
|
99
|
+
return Reflect.getMetadata(di.METADATA_KEYS.MEMORY_SCOPE, target) ?? /* @__PURE__ */ new Map();
|
|
100
|
+
}
|
|
101
|
+
__name(readMemoryScopeMetadata, "readMemoryScopeMetadata");
|
|
102
|
+
function Reranker(options) {
|
|
103
|
+
return (target, propertyKey) => {
|
|
104
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.RERANKER, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
105
|
+
existing.set(propertyKey, options);
|
|
106
|
+
Reflect.defineMetadata(di.METADATA_KEYS.RERANKER, existing, target.constructor);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
__name(Reranker, "Reranker");
|
|
110
|
+
function readRerankerMetadata(target) {
|
|
111
|
+
return Reflect.getMetadata(di.METADATA_KEYS.RERANKER, target) ?? /* @__PURE__ */ new Map();
|
|
112
|
+
}
|
|
113
|
+
__name(readRerankerMetadata, "readRerankerMetadata");
|
|
114
|
+
function Retriever(options) {
|
|
115
|
+
return (target, propertyKey) => {
|
|
116
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.RETRIEVER, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
117
|
+
existing.set(propertyKey, options);
|
|
118
|
+
Reflect.defineMetadata(di.METADATA_KEYS.RETRIEVER, existing, target.constructor);
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
__name(Retriever, "Retriever");
|
|
122
|
+
function readRetrieverMetadata(target) {
|
|
123
|
+
return Reflect.getMetadata(di.METADATA_KEYS.RETRIEVER, target) ?? /* @__PURE__ */ new Map();
|
|
124
|
+
}
|
|
125
|
+
__name(readRetrieverMetadata, "readRetrieverMetadata");
|
|
126
|
+
function Squad(metadata) {
|
|
127
|
+
return (target, propertyKey) => {
|
|
128
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.SQUAD, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
129
|
+
existing.set(propertyKey, metadata);
|
|
130
|
+
Reflect.defineMetadata(di.METADATA_KEYS.SQUAD, existing, target.constructor);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
__name(Squad, "Squad");
|
|
134
|
+
function readSquadMetadata(target) {
|
|
135
|
+
return Reflect.getMetadata(di.METADATA_KEYS.SQUAD, target) ?? /* @__PURE__ */ new Map();
|
|
136
|
+
}
|
|
137
|
+
__name(readSquadMetadata, "readSquadMetadata");
|
|
138
|
+
function Step(metadata = {}) {
|
|
139
|
+
return (target, propertyKey) => {
|
|
140
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.STEP, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
141
|
+
existing.set(propertyKey, metadata);
|
|
142
|
+
Reflect.defineMetadata(di.METADATA_KEYS.STEP, existing, target.constructor);
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
__name(Step, "Step");
|
|
146
|
+
function readStepMetadata(target) {
|
|
147
|
+
return Reflect.getMetadata(di.METADATA_KEYS.STEP, target) ?? /* @__PURE__ */ new Map();
|
|
148
|
+
}
|
|
149
|
+
__name(readStepMetadata, "readStepMetadata");
|
|
150
|
+
function SubAgent(options) {
|
|
151
|
+
return (target, propertyKey) => {
|
|
152
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.SUBAGENT, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
153
|
+
existing.set(propertyKey, options);
|
|
154
|
+
Reflect.defineMetadata(di.METADATA_KEYS.SUBAGENT, existing, target.constructor);
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
__name(SubAgent, "SubAgent");
|
|
158
|
+
function readSubAgentMetadata(target) {
|
|
159
|
+
return Reflect.getMetadata(di.METADATA_KEYS.SUBAGENT, target) ?? /* @__PURE__ */ new Map();
|
|
160
|
+
}
|
|
161
|
+
__name(readSubAgentMetadata, "readSubAgentMetadata");
|
|
162
|
+
function Subscription(options) {
|
|
163
|
+
return (target, propertyKey) => {
|
|
164
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.SUBSCRIPTION, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
165
|
+
existing.set(propertyKey, options);
|
|
166
|
+
Reflect.defineMetadata(di.METADATA_KEYS.SUBSCRIPTION, existing, target.constructor);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
__name(Subscription, "Subscription");
|
|
170
|
+
function readSubscriptionMetadata(target) {
|
|
171
|
+
return Reflect.getMetadata(di.METADATA_KEYS.SUBSCRIPTION, target) ?? /* @__PURE__ */ new Map();
|
|
172
|
+
}
|
|
173
|
+
__name(readSubscriptionMetadata, "readSubscriptionMetadata");
|
|
174
|
+
function TextSplitter(options) {
|
|
175
|
+
return (target, propertyKey) => {
|
|
176
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.TEXT_SPLITTER, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
177
|
+
existing.set(propertyKey, options);
|
|
178
|
+
Reflect.defineMetadata(di.METADATA_KEYS.TEXT_SPLITTER, existing, target.constructor);
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
__name(TextSplitter, "TextSplitter");
|
|
182
|
+
function readTextSplitterMetadata(target) {
|
|
183
|
+
return Reflect.getMetadata(di.METADATA_KEYS.TEXT_SPLITTER, target) ?? /* @__PURE__ */ new Map();
|
|
184
|
+
}
|
|
185
|
+
__name(readTextSplitterMetadata, "readTextSplitterMetadata");
|
|
186
|
+
function Tool(options) {
|
|
187
|
+
return (target, propertyKey) => {
|
|
188
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.TOOL, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
189
|
+
existing.set(propertyKey, options);
|
|
190
|
+
Reflect.defineMetadata(di.METADATA_KEYS.TOOL, existing, target.constructor);
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
__name(Tool, "Tool");
|
|
194
|
+
function readToolMetadata(target) {
|
|
195
|
+
return Reflect.getMetadata(di.METADATA_KEYS.TOOL, target) ?? /* @__PURE__ */ new Map();
|
|
196
|
+
}
|
|
197
|
+
__name(readToolMetadata, "readToolMetadata");
|
|
198
|
+
function UseSandbox(options = {}) {
|
|
199
|
+
return (target, propertyKey) => {
|
|
200
|
+
const existing = Reflect.getMetadata(di.METADATA_KEYS.SANDBOX, target.constructor) ?? /* @__PURE__ */ new Map();
|
|
201
|
+
existing.set(propertyKey, options);
|
|
202
|
+
Reflect.defineMetadata(di.METADATA_KEYS.SANDBOX, existing, target.constructor);
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
__name(UseSandbox, "UseSandbox");
|
|
206
|
+
function readSandboxMetadata(target) {
|
|
207
|
+
return Reflect.getMetadata(di.METADATA_KEYS.SANDBOX, target) ?? /* @__PURE__ */ new Map();
|
|
208
|
+
}
|
|
209
|
+
__name(readSandboxMetadata, "readSandboxMetadata");
|
|
210
|
+
function Workflow(options = {}) {
|
|
211
|
+
return (target) => {
|
|
212
|
+
Reflect.defineMetadata(di.METADATA_KEYS.WORKFLOW, options, target);
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
__name(Workflow, "Workflow");
|
|
216
|
+
function readWorkflowMetadata(target) {
|
|
217
|
+
return Reflect.getMetadata(di.METADATA_KEYS.WORKFLOW, target);
|
|
218
|
+
}
|
|
219
|
+
__name(readWorkflowMetadata, "readWorkflowMetadata");
|
|
20
220
|
function InjectAgent() {
|
|
21
221
|
return di.Inject(AGENT_TOKEN);
|
|
22
222
|
}
|
|
23
223
|
__name(InjectAgent, "InjectAgent");
|
|
224
|
+
function buildWorkflow(instance) {
|
|
225
|
+
const ctor = instance.constructor;
|
|
226
|
+
const meta = readStepMetadata(ctor);
|
|
227
|
+
if (meta.size === 0) {
|
|
228
|
+
throw new Error(`buildWorkflow: class "${instance.constructor.name}" has no @Step methods`);
|
|
229
|
+
}
|
|
230
|
+
const steps = resolveSteps(instance, meta);
|
|
231
|
+
validateAfterTargets(steps);
|
|
232
|
+
const ordered = topoSort(steps);
|
|
233
|
+
const name = readWorkflowMetadata(instance.constructor)?.name ?? "workflow";
|
|
234
|
+
let builder = workflow.Workflow.create({
|
|
235
|
+
name
|
|
236
|
+
});
|
|
237
|
+
for (const s of ordered) {
|
|
238
|
+
builder = builder.then(workflow.fn(s.id, (input) => s.run(input)));
|
|
239
|
+
}
|
|
240
|
+
return builder.commit();
|
|
241
|
+
}
|
|
242
|
+
__name(buildWorkflow, "buildWorkflow");
|
|
243
|
+
function resolveSteps(instance, meta) {
|
|
244
|
+
const steps = /* @__PURE__ */ new Map();
|
|
245
|
+
for (const [key, m] of meta) {
|
|
246
|
+
const k = String(key);
|
|
247
|
+
const method = instance[k];
|
|
248
|
+
if (typeof method !== "function") {
|
|
249
|
+
throw new Error(`buildWorkflow: @Step "${k}" is not a method`);
|
|
250
|
+
}
|
|
251
|
+
steps.set(k, {
|
|
252
|
+
key: k,
|
|
253
|
+
id: m.name ?? k,
|
|
254
|
+
after: m.after,
|
|
255
|
+
run: /* @__PURE__ */ __name((input) => method.call(instance, input), "run")
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
return steps;
|
|
259
|
+
}
|
|
260
|
+
__name(resolveSteps, "resolveSteps");
|
|
261
|
+
function validateAfterTargets(steps) {
|
|
262
|
+
for (const s of steps.values()) {
|
|
263
|
+
if (s.after !== void 0 && !steps.has(s.after)) {
|
|
264
|
+
throw new Error(`buildWorkflow: @Step "${s.key}" declares after: "${s.after}" which is not a known @Step (unknown upstream)`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
__name(validateAfterTargets, "validateAfterTargets");
|
|
269
|
+
function topoSort(steps) {
|
|
270
|
+
const ordered = [];
|
|
271
|
+
const placed = /* @__PURE__ */ new Set();
|
|
272
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
273
|
+
const visit = /* @__PURE__ */ __name((s) => {
|
|
274
|
+
if (placed.has(s.key)) return;
|
|
275
|
+
if (visiting.has(s.key)) {
|
|
276
|
+
throw new Error(`buildWorkflow: cycle detected in @Step "after" graph at "${s.key}"`);
|
|
277
|
+
}
|
|
278
|
+
visiting.add(s.key);
|
|
279
|
+
if (s.after !== void 0) {
|
|
280
|
+
const up = steps.get(s.after);
|
|
281
|
+
if (up !== void 0) visit(up);
|
|
282
|
+
}
|
|
283
|
+
visiting.delete(s.key);
|
|
284
|
+
placed.add(s.key);
|
|
285
|
+
ordered.push(s);
|
|
286
|
+
}, "visit");
|
|
287
|
+
for (const s of steps.values()) visit(s);
|
|
288
|
+
return ordered;
|
|
289
|
+
}
|
|
290
|
+
__name(topoSort, "topoSort");
|
|
24
291
|
|
|
25
292
|
exports.AGENT_TOKEN = AGENT_TOKEN;
|
|
293
|
+
exports.Auth = Auth;
|
|
294
|
+
exports.AutoSummarize = AutoSummarize;
|
|
295
|
+
exports.Cron = Cron;
|
|
296
|
+
exports.EvalDecorator = EvalDecorator;
|
|
297
|
+
exports.Hitl = Hitl;
|
|
26
298
|
exports.InjectAgent = InjectAgent;
|
|
299
|
+
exports.MemoryScopeDecorator = MemoryScopeDecorator;
|
|
300
|
+
exports.Reranker = Reranker;
|
|
301
|
+
exports.Retriever = Retriever;
|
|
302
|
+
exports.Squad = Squad;
|
|
303
|
+
exports.Step = Step;
|
|
304
|
+
exports.SubAgent = SubAgent;
|
|
305
|
+
exports.Subscription = Subscription;
|
|
306
|
+
exports.TextSplitter = TextSplitter;
|
|
307
|
+
exports.Tool = Tool;
|
|
308
|
+
exports.UseSandbox = UseSandbox;
|
|
309
|
+
exports.Workflow = Workflow;
|
|
310
|
+
exports.buildWorkflow = buildWorkflow;
|
|
27
311
|
exports.createAgentProvider = createAgentProvider;
|
|
312
|
+
exports.readAuthMetadata = readAuthMetadata;
|
|
313
|
+
exports.readAutoSummarizeMetadata = readAutoSummarizeMetadata;
|
|
314
|
+
exports.readCronMetadata = readCronMetadata;
|
|
315
|
+
exports.readEvalDecoratorMetadata = readEvalDecoratorMetadata;
|
|
316
|
+
exports.readHitlMetadata = readHitlMetadata;
|
|
317
|
+
exports.readMemoryScopeMetadata = readMemoryScopeMetadata;
|
|
318
|
+
exports.readRerankerMetadata = readRerankerMetadata;
|
|
319
|
+
exports.readRetrieverMetadata = readRetrieverMetadata;
|
|
320
|
+
exports.readSandboxMetadata = readSandboxMetadata;
|
|
321
|
+
exports.readSquadMetadata = readSquadMetadata;
|
|
322
|
+
exports.readStepMetadata = readStepMetadata;
|
|
323
|
+
exports.readSubAgentMetadata = readSubAgentMetadata;
|
|
324
|
+
exports.readSubscriptionMetadata = readSubscriptionMetadata;
|
|
325
|
+
exports.readTextSplitterMetadata = readTextSplitterMetadata;
|
|
326
|
+
exports.readToolMetadata = readToolMetadata;
|
|
327
|
+
exports.readWorkflowMetadata = readWorkflowMetadata;
|
|
28
328
|
//# sourceMappingURL=index.cjs.map
|
|
29
329
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tokens.ts","../src/agent-provider.ts","../src/inject-agent.ts"],"names":["AGENT_TOKEN","createAgentProvider","options","provide","useFactory","factory","scope","Scope","REQUEST","InjectAgent","Inject"],"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,WAAAA,GAAAA;AACd,EAAA,OAAOC,UAAOV,WAAAA,CAAAA;AAChB;AAFgBS,MAAAA,CAAAA,WAAAA,EAAAA,aAAAA,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 { 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"]}
|
|
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","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;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"]}
|