@aid-framework/runtime 0.0.0 → 0.1.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +53 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/agents/deep_agents.d.ts +78 -0
  5. package/dist/agents/deep_agents.d.ts.map +1 -0
  6. package/dist/agents/deep_agents.js +477 -0
  7. package/dist/agents/deep_agents.js.map +1 -0
  8. package/dist/agents/engine.d.ts +85 -0
  9. package/dist/agents/engine.d.ts.map +1 -0
  10. package/dist/agents/engine.js +129 -0
  11. package/dist/agents/engine.js.map +1 -0
  12. package/dist/agents/gateway_chat_model.d.ts +151 -0
  13. package/dist/agents/gateway_chat_model.d.ts.map +1 -0
  14. package/dist/agents/gateway_chat_model.js +350 -0
  15. package/dist/agents/gateway_chat_model.js.map +1 -0
  16. package/dist/agents/guardrail_middleware.d.ts +57 -0
  17. package/dist/agents/guardrail_middleware.d.ts.map +1 -0
  18. package/dist/agents/guardrail_middleware.js +85 -0
  19. package/dist/agents/guardrail_middleware.js.map +1 -0
  20. package/dist/agents/guardrails.d.ts +124 -0
  21. package/dist/agents/guardrails.d.ts.map +1 -0
  22. package/dist/agents/guardrails.js +336 -0
  23. package/dist/agents/guardrails.js.map +1 -0
  24. package/dist/agents/index.d.ts +15 -0
  25. package/dist/agents/index.d.ts.map +1 -0
  26. package/dist/agents/index.js +15 -0
  27. package/dist/agents/index.js.map +1 -0
  28. package/dist/agents/ir.d.ts +144 -0
  29. package/dist/agents/ir.d.ts.map +1 -0
  30. package/dist/agents/ir.js +513 -0
  31. package/dist/agents/ir.js.map +1 -0
  32. package/dist/agents/loop.d.ts +145 -0
  33. package/dist/agents/loop.d.ts.map +1 -0
  34. package/dist/agents/loop.js +1025 -0
  35. package/dist/agents/loop.js.map +1 -0
  36. package/dist/agents/memory.d.ts +115 -0
  37. package/dist/agents/memory.d.ts.map +1 -0
  38. package/dist/agents/memory.js +258 -0
  39. package/dist/agents/memory.js.map +1 -0
  40. package/dist/agents/state.d.ts +137 -0
  41. package/dist/agents/state.d.ts.map +1 -0
  42. package/dist/agents/state.js +255 -0
  43. package/dist/agents/state.js.map +1 -0
  44. package/dist/concurrency.d.ts +36 -0
  45. package/dist/concurrency.d.ts.map +1 -0
  46. package/dist/concurrency.js +86 -0
  47. package/dist/concurrency.js.map +1 -0
  48. package/dist/control.d.ts +116 -0
  49. package/dist/control.d.ts.map +1 -0
  50. package/dist/control.js +281 -0
  51. package/dist/control.js.map +1 -0
  52. package/dist/cost.d.ts +95 -0
  53. package/dist/cost.d.ts.map +1 -0
  54. package/dist/cost.js +161 -0
  55. package/dist/cost.js.map +1 -0
  56. package/dist/errors.d.ts +213 -0
  57. package/dist/errors.d.ts.map +1 -0
  58. package/dist/errors.js +316 -0
  59. package/dist/errors.js.map +1 -0
  60. package/dist/evals/dataset.d.ts +45 -0
  61. package/dist/evals/dataset.d.ts.map +1 -0
  62. package/dist/evals/dataset.js +147 -0
  63. package/dist/evals/dataset.js.map +1 -0
  64. package/dist/evals/gate.d.ts +236 -0
  65. package/dist/evals/gate.d.ts.map +1 -0
  66. package/dist/evals/gate.js +572 -0
  67. package/dist/evals/gate.js.map +1 -0
  68. package/dist/evals/metrics.d.ts +141 -0
  69. package/dist/evals/metrics.d.ts.map +1 -0
  70. package/dist/evals/metrics.js +364 -0
  71. package/dist/evals/metrics.js.map +1 -0
  72. package/dist/evals/predicate.d.ts +79 -0
  73. package/dist/evals/predicate.d.ts.map +1 -0
  74. package/dist/evals/predicate.js +178 -0
  75. package/dist/evals/predicate.js.map +1 -0
  76. package/dist/evals/runner.d.ts +94 -0
  77. package/dist/evals/runner.d.ts.map +1 -0
  78. package/dist/evals/runner.js +202 -0
  79. package/dist/evals/runner.js.map +1 -0
  80. package/dist/gateway.d.ts +118 -0
  81. package/dist/gateway.d.ts.map +1 -0
  82. package/dist/gateway.js +250 -0
  83. package/dist/gateway.js.map +1 -0
  84. package/dist/index.d.ts +83 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +59 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/internal/json.d.ts +44 -0
  89. package/dist/internal/json.d.ts.map +1 -0
  90. package/dist/internal/json.js +90 -0
  91. package/dist/internal/json.js.map +1 -0
  92. package/dist/internal/text.d.ts +17 -0
  93. package/dist/internal/text.d.ts.map +1 -0
  94. package/dist/internal/text.js +22 -0
  95. package/dist/internal/text.js.map +1 -0
  96. package/dist/pipeline.d.ts +80 -0
  97. package/dist/pipeline.d.ts.map +1 -0
  98. package/dist/pipeline.js +159 -0
  99. package/dist/pipeline.js.map +1 -0
  100. package/dist/policy.d.ts +52 -0
  101. package/dist/policy.d.ts.map +1 -0
  102. package/dist/policy.js +199 -0
  103. package/dist/policy.js.map +1 -0
  104. package/dist/prompts.d.ts +86 -0
  105. package/dist/prompts.d.ts.map +1 -0
  106. package/dist/prompts.js +337 -0
  107. package/dist/prompts.js.map +1 -0
  108. package/dist/providers/base.d.ts +19 -0
  109. package/dist/providers/base.d.ts.map +1 -0
  110. package/dist/providers/base.js +13 -0
  111. package/dist/providers/base.js.map +1 -0
  112. package/dist/providers/fake.d.ts +98 -0
  113. package/dist/providers/fake.d.ts.map +1 -0
  114. package/dist/providers/fake.js +181 -0
  115. package/dist/providers/fake.js.map +1 -0
  116. package/dist/providers/http.d.ts +62 -0
  117. package/dist/providers/http.d.ts.map +1 -0
  118. package/dist/providers/http.js +245 -0
  119. package/dist/providers/http.js.map +1 -0
  120. package/dist/retrieval/chunking.d.ts +88 -0
  121. package/dist/retrieval/chunking.d.ts.map +1 -0
  122. package/dist/retrieval/chunking.js +188 -0
  123. package/dist/retrieval/chunking.js.map +1 -0
  124. package/dist/retrieval/citations.d.ts +98 -0
  125. package/dist/retrieval/citations.d.ts.map +1 -0
  126. package/dist/retrieval/citations.js +134 -0
  127. package/dist/retrieval/citations.js.map +1 -0
  128. package/dist/retrieval/connectors.d.ts +74 -0
  129. package/dist/retrieval/connectors.d.ts.map +1 -0
  130. package/dist/retrieval/connectors.js +218 -0
  131. package/dist/retrieval/connectors.js.map +1 -0
  132. package/dist/retrieval/embedding.d.ts +116 -0
  133. package/dist/retrieval/embedding.d.ts.map +1 -0
  134. package/dist/retrieval/embedding.js +282 -0
  135. package/dist/retrieval/embedding.js.map +1 -0
  136. package/dist/retrieval/gate.d.ts +52 -0
  137. package/dist/retrieval/gate.d.ts.map +1 -0
  138. package/dist/retrieval/gate.js +91 -0
  139. package/dist/retrieval/gate.js.map +1 -0
  140. package/dist/retrieval/hybrid.d.ts +76 -0
  141. package/dist/retrieval/hybrid.d.ts.map +1 -0
  142. package/dist/retrieval/hybrid.js +150 -0
  143. package/dist/retrieval/hybrid.js.map +1 -0
  144. package/dist/retrieval/metrics.d.ts +126 -0
  145. package/dist/retrieval/metrics.d.ts.map +1 -0
  146. package/dist/retrieval/metrics.js +200 -0
  147. package/dist/retrieval/metrics.js.map +1 -0
  148. package/dist/retrieval/pgvector.d.ts +62 -0
  149. package/dist/retrieval/pgvector.d.ts.map +1 -0
  150. package/dist/retrieval/pgvector.js +262 -0
  151. package/dist/retrieval/pgvector.js.map +1 -0
  152. package/dist/retrieval/rerank.d.ts +61 -0
  153. package/dist/retrieval/rerank.d.ts.map +1 -0
  154. package/dist/retrieval/rerank.js +105 -0
  155. package/dist/retrieval/rerank.js.map +1 -0
  156. package/dist/retrieval/retriever.d.ts +125 -0
  157. package/dist/retrieval/retriever.d.ts.map +1 -0
  158. package/dist/retrieval/retriever.js +281 -0
  159. package/dist/retrieval/retriever.js.map +1 -0
  160. package/dist/retrieval/stores.d.ts +106 -0
  161. package/dist/retrieval/stores.d.ts.map +1 -0
  162. package/dist/retrieval/stores.js +142 -0
  163. package/dist/retrieval/stores.js.map +1 -0
  164. package/dist/retrieval/types.d.ts +314 -0
  165. package/dist/retrieval/types.d.ts.map +1 -0
  166. package/dist/retrieval/types.js +388 -0
  167. package/dist/retrieval/types.js.map +1 -0
  168. package/dist/steps.d.ts +156 -0
  169. package/dist/steps.d.ts.map +1 -0
  170. package/dist/steps.js +199 -0
  171. package/dist/steps.js.map +1 -0
  172. package/dist/structured.d.ts +91 -0
  173. package/dist/structured.d.ts.map +1 -0
  174. package/dist/structured.js +155 -0
  175. package/dist/structured.js.map +1 -0
  176. package/dist/tools.d.ts +100 -0
  177. package/dist/tools.d.ts.map +1 -0
  178. package/dist/tools.js +201 -0
  179. package/dist/tools.js.map +1 -0
  180. package/dist/tracing.d.ts +104 -0
  181. package/dist/tracing.d.ts.map +1 -0
  182. package/dist/tracing.js +155 -0
  183. package/dist/tracing.js.map +1 -0
  184. package/dist/types.d.ts +240 -0
  185. package/dist/types.d.ts.map +1 -0
  186. package/dist/types.js +357 -0
  187. package/dist/types.js.map +1 -0
  188. package/package.json +80 -14
@@ -0,0 +1,388 @@
1
+ /**
2
+ * Shapes the retrieval runtime shares across its modules.
3
+ *
4
+ * Two families live here and the split is deliberate.
5
+ *
6
+ * * The **IR mirror** models (`SourceSpec`, `ChunkingSpec`, `IndexSpec`,
7
+ * `RerankSpec`, `RefreshSpec`, `RetrieverSpec`, `EmbeddingSpec`,
8
+ * `VectorStoreSpec`) reproduce the L1 IR's `retrievers` / `embeddings` /
9
+ * `stores` entries field for field. The IR spells these in camelCase
10
+ * (`keepMetadata`, `embedModel`, `topK`, `inputPerMTok`, ...) and so does this
11
+ * file, because in TypeScript the IR's own spelling *is* the natural one: there
12
+ * is no second vocabulary to translate from. Enum values are the IR's own
13
+ * strings (`recursive`, `pgvector`, `cosine`) and are never re-spelled.
14
+ * * The **resolved** models (`PinnedEmbedding`, `RetrieverBinding`) are what
15
+ * generated code binds with literals. They carry the exact embedding model id
16
+ * rather than an alias, so a run is reproducible from the generated source
17
+ * alone and nothing is resolved at run time.
18
+ */
19
+ import { ConfigurationError, FeatureDeferredError } from '../errors.js';
20
+ import { repr, sha256Parts } from '../internal/json.js';
21
+ import { CostProfile } from '../types.js';
22
+ export const DISTANCE_METRICS = ['cosine', 'dot', 'l2'];
23
+ function requireNonEmpty(value, label) {
24
+ if (value.length === 0) {
25
+ throw new ConfigurationError(`${label} must not be empty`);
26
+ }
27
+ return value;
28
+ }
29
+ function requirePositiveInt(value, label) {
30
+ if (!Number.isInteger(value) || value <= 0) {
31
+ throw new ConfigurationError(`${label} must be a positive integer`);
32
+ }
33
+ return value;
34
+ }
35
+ function requireNonNegativeInt(value, label) {
36
+ if (!Number.isInteger(value) || value < 0) {
37
+ throw new ConfigurationError(`${label} must be a non-negative integer`);
38
+ }
39
+ return value;
40
+ }
41
+ /** `retriever.source`. */
42
+ export class SourceSpec {
43
+ kind;
44
+ uri;
45
+ glob;
46
+ constructor(init) {
47
+ this.kind = init.kind;
48
+ this.uri = init.uri;
49
+ this.glob = init.glob ?? null;
50
+ }
51
+ }
52
+ /** `retriever.chunking`. */
53
+ export class ChunkingSpec {
54
+ strategy;
55
+ size;
56
+ overlap;
57
+ keepMetadata;
58
+ constructor(init) {
59
+ this.strategy = init.strategy;
60
+ this.size = requirePositiveInt(init.size, 'chunking size');
61
+ this.overlap = requireNonNegativeInt(init.overlap, 'chunking overlap');
62
+ this.keepMetadata = [...(init.keepMetadata ?? [])];
63
+ }
64
+ }
65
+ /** `retriever.index`. */
66
+ export class IndexSpec {
67
+ metric;
68
+ hybrid;
69
+ params;
70
+ constructor(init) {
71
+ this.metric = init.metric;
72
+ this.hybrid = init.hybrid;
73
+ this.params = init.params ?? null;
74
+ }
75
+ }
76
+ /** `retriever.rerank`. */
77
+ export class RerankSpec {
78
+ model;
79
+ topN;
80
+ constructor(init) {
81
+ this.model = init.model;
82
+ this.topN = requirePositiveInt(init.topN, 'rerank topN');
83
+ }
84
+ }
85
+ /** `retriever.refresh`. */
86
+ export class RefreshSpec {
87
+ mode;
88
+ schedule;
89
+ constructor(init) {
90
+ this.mode = init.mode;
91
+ this.schedule = init.schedule ?? null;
92
+ }
93
+ }
94
+ /** One entry of the IR's `retrievers` map. */
95
+ export class RetrieverSpec {
96
+ id;
97
+ source;
98
+ chunking;
99
+ embedModel;
100
+ store;
101
+ index;
102
+ topK;
103
+ rerank;
104
+ filters;
105
+ refresh;
106
+ traits;
107
+ constructor(init) {
108
+ this.id = requireNonEmpty(init.id, 'retriever id');
109
+ this.source = init.source;
110
+ this.chunking = init.chunking;
111
+ this.embedModel = init.embedModel;
112
+ this.store = init.store;
113
+ this.index = init.index;
114
+ this.topK = requirePositiveInt(init.topK, 'retriever topK');
115
+ this.rerank = init.rerank ?? null;
116
+ this.filters = init.filters === undefined || init.filters === null ? null : [...init.filters];
117
+ this.refresh = init.refresh;
118
+ this.traits = [...(init.traits ?? [])];
119
+ }
120
+ }
121
+ /**
122
+ * `embedding.costProfile` -- USD per **million** tokens.
123
+ *
124
+ * Not interchangeable with {@link CostProfile}, which prices per *thousand*
125
+ * tokens because it predates the IR. {@link pinnedEmbedding} is the single place
126
+ * the two are converted, so the factor of 1000 is stated once rather than assumed
127
+ * at every call site.
128
+ */
129
+ export class EmbeddingCostProfile {
130
+ inputPerMTok;
131
+ outputPerMTok;
132
+ constructor(init) {
133
+ for (const [label, value] of [
134
+ ['inputPerMTok', init.inputPerMTok],
135
+ ['outputPerMTok', init.outputPerMTok],
136
+ ]) {
137
+ if (!Number.isFinite(value) || value < 0) {
138
+ throw new ConfigurationError(`${label} must be a non-negative number`);
139
+ }
140
+ }
141
+ this.inputPerMTok = init.inputPerMTok;
142
+ this.outputPerMTok = init.outputPerMTok;
143
+ }
144
+ }
145
+ /**
146
+ * One entry of the IR's `embeddings` map.
147
+ *
148
+ * `id` is the *alias* a retriever's `embedModel` names -- the resolution the
149
+ * runtime must never repeat at run time.
150
+ */
151
+ export class EmbeddingSpec {
152
+ id;
153
+ provider;
154
+ modelId;
155
+ dimensions;
156
+ costProfile;
157
+ traits;
158
+ constructor(init) {
159
+ this.id = requireNonEmpty(init.id, 'embedding id');
160
+ this.provider = init.provider;
161
+ this.modelId = init.modelId;
162
+ this.dimensions = init.dimensions === undefined ? null : init.dimensions;
163
+ if (this.dimensions !== null) {
164
+ requirePositiveInt(this.dimensions, 'embedding dimensions');
165
+ }
166
+ this.costProfile = init.costProfile ?? null;
167
+ this.traits = [...(init.traits ?? [])];
168
+ }
169
+ }
170
+ /** One entry of the IR's `stores` map. */
171
+ export class VectorStoreSpec {
172
+ id;
173
+ kind;
174
+ uri;
175
+ dimensions;
176
+ traits;
177
+ constructor(init) {
178
+ this.id = requireNonEmpty(init.id, 'store id');
179
+ this.kind = init.kind;
180
+ this.uri = init.uri ?? null;
181
+ this.dimensions = init.dimensions === undefined ? null : init.dimensions;
182
+ if (this.dimensions !== null) {
183
+ requirePositiveInt(this.dimensions, 'store dimensions');
184
+ }
185
+ this.traits = [...(init.traits ?? [])];
186
+ }
187
+ }
188
+ /** The IR's `retrieval` metric variant: `{kind, expectDocs, k}`. */
189
+ export class RetrievalMetricSpec {
190
+ kind;
191
+ expectDocs;
192
+ k;
193
+ constructor(init) {
194
+ this.kind = 'retrieval';
195
+ this.expectDocs = [...init.expectDocs];
196
+ this.k = requirePositiveInt(init.k, 'retrieval metric k');
197
+ }
198
+ }
199
+ /**
200
+ * An `embedModel` alias already resolved to an exact embedding model.
201
+ *
202
+ * The same contract as `PinnedModel`: a baseline recorded against
203
+ * `text-embedding-3-small` means nothing if the alias floats to another
204
+ * revision, so the resolved id, the dimensions and the price are all *recorded
205
+ * inputs* rather than lookups a run performs.
206
+ */
207
+ export class PinnedEmbedding {
208
+ alias;
209
+ provider;
210
+ modelId;
211
+ dimensions;
212
+ cost;
213
+ constructor(init) {
214
+ this.alias = requireNonEmpty(init.alias, 'embedding alias');
215
+ this.provider = requireNonEmpty(init.provider, 'embedding provider');
216
+ this.modelId = requireNonEmpty(init.modelId, 'embedding modelId');
217
+ this.dimensions = requirePositiveInt(init.dimensions, 'embedding dimensions');
218
+ this.cost = init.cost;
219
+ }
220
+ }
221
+ /**
222
+ * A retriever as generated code binds it, with every alias resolved.
223
+ *
224
+ * `embedModel` keeps the declared alias purely so cost can be attributed to the
225
+ * name the spec used; `embedding` is the resolved model actually called.
226
+ * `storeKind` is resolved from the store entry, because a run must not discover
227
+ * at search time which backend it wrote to.
228
+ *
229
+ * `storeUri` is deliberately kept *unresolved*: a hosted store's location is a
230
+ * deployment secret, which is why the IR writes `env:PGVECTOR_URL` rather than a
231
+ * DSN. The name is pinned in code; the value is read from the environment at run
232
+ * time, and an environment variable is not an alias.
233
+ */
234
+ export class RetrieverBinding {
235
+ retrieverId;
236
+ source;
237
+ chunking;
238
+ embedModel;
239
+ embedding;
240
+ store;
241
+ storeKind;
242
+ storeUri;
243
+ index;
244
+ topK;
245
+ rerank;
246
+ refreshMode;
247
+ traits;
248
+ constructor(init) {
249
+ this.retrieverId = requireNonEmpty(init.retrieverId, 'retrieverId');
250
+ this.source = init.source;
251
+ this.chunking = init.chunking;
252
+ this.embedModel = requireNonEmpty(init.embedModel, 'embedModel');
253
+ this.embedding = init.embedding;
254
+ this.store = requireNonEmpty(init.store, 'store');
255
+ this.storeKind = init.storeKind;
256
+ this.storeUri = init.storeUri ?? null;
257
+ this.index = init.index;
258
+ this.topK = requirePositiveInt(init.topK, 'retriever topK');
259
+ this.rerank = init.rerank ?? null;
260
+ this.refreshMode = init.refreshMode ?? 'full';
261
+ this.traits = [...(init.traits ?? [])];
262
+ }
263
+ }
264
+ /**
265
+ * One indexed passage.
266
+ *
267
+ * `chunkId` hashes the document id, the chunk's position *and* its text. That is
268
+ * what makes ingest idempotent: identical input re-chunks to identical ids, so a
269
+ * second ingest replaces rather than duplicates. Position is part of the hash on
270
+ * purpose -- two byte-identical paragraphs in one document must stay two chunks
271
+ * instead of colliding into one.
272
+ */
273
+ export class Chunk {
274
+ chunkId;
275
+ docId;
276
+ uri;
277
+ index;
278
+ start;
279
+ end;
280
+ text;
281
+ metadata;
282
+ constructor(init) {
283
+ this.chunkId = requireNonEmpty(init.chunkId, 'chunkId');
284
+ this.docId = requireNonEmpty(init.docId, 'docId');
285
+ this.uri = init.uri ?? '';
286
+ this.index = requireNonNegativeInt(init.index, 'chunk index');
287
+ this.start = requireNonNegativeInt(init.start, 'chunk start');
288
+ this.end = requireNonNegativeInt(init.end, 'chunk end');
289
+ this.text = init.text;
290
+ this.metadata = { ...(init.metadata ?? {}) };
291
+ }
292
+ }
293
+ /** A chunk with the score that ranked it. */
294
+ export class ScoredChunk {
295
+ chunk;
296
+ score;
297
+ constructor(init) {
298
+ this.chunk = init.chunk;
299
+ this.score = init.score;
300
+ }
301
+ }
302
+ /**
303
+ * The content hash that identifies a chunk.
304
+ *
305
+ * Shared by every chunker so the id scheme cannot differ between strategies; a
306
+ * strategy that changed the id scheme would silently duplicate a corpus on
307
+ * re-ingest instead of replacing it.
308
+ */
309
+ export function chunkIdFor(docId, index, text) {
310
+ return `sha256:${sha256Parts([docId, String(index), text])}`;
311
+ }
312
+ /**
313
+ * Resolve an IR embedding entry into the pinned form generated code carries.
314
+ *
315
+ * `dimensions` may be supplied when the IR entry omits it (the schema makes it
316
+ * optional); it is an error to have neither, because an unpinned width would let a
317
+ * store accept vectors a later run cannot compare against.
318
+ */
319
+ export function pinnedEmbedding(spec, init) {
320
+ const width = init.dimensions ?? spec.dimensions;
321
+ if (width === null || width === undefined) {
322
+ throw new ConfigurationError(`embedding ${repr(spec.id)} pins no dimensions and none were supplied; the vector ` +
323
+ 'width must be recorded with the pinned model so stores stay comparable');
324
+ }
325
+ const profile = spec.costProfile;
326
+ // costProfile quotes USD per MTok; CostProfile quotes USD per 1k tokens.
327
+ const scale = 1000.0;
328
+ return new PinnedEmbedding({
329
+ alias: init.alias,
330
+ provider: spec.provider,
331
+ modelId: spec.modelId,
332
+ dimensions: width,
333
+ cost: new CostProfile({
334
+ inputPer1kUsd: profile === null ? 0.0 : profile.inputPerMTok / scale,
335
+ outputPer1kUsd: profile === null ? 0.0 : profile.outputPerMTok / scale,
336
+ }),
337
+ });
338
+ }
339
+ /**
340
+ * Bind one IR retriever entry to the embedding and store it names.
341
+ *
342
+ * `embedModel` names an *embeddings entry id*, not a provider model, and `store`
343
+ * names a *stores entry id*. Both are checked here rather than trusted, because a
344
+ * mistyped reference in generated code would otherwise surface as an empty or
345
+ * mis-scored corpus far from its cause.
346
+ */
347
+ export function bindingFromSpec(spec, init) {
348
+ const { embedding, store } = init;
349
+ if (spec.embedModel !== embedding.id) {
350
+ throw new ConfigurationError(`retriever ${repr(spec.id)} names embedModel ${repr(spec.embedModel)} but embedding ` +
351
+ `${repr(embedding.id)} was supplied`);
352
+ }
353
+ if (spec.store !== store.id) {
354
+ throw new ConfigurationError(`retriever ${repr(spec.id)} names store ${repr(spec.store)} but store ` +
355
+ `${repr(store.id)} was supplied`);
356
+ }
357
+ if (spec.filters !== null && spec.filters.length > 0) {
358
+ // The spec validator already refuses filters; the runtime checks too, because
359
+ // generated code is reachable without the validator having run.
360
+ throw new FeatureDeferredError(`retriever ${repr(spec.id)} declares filters, which spec v0.1 does not implement: a ` +
361
+ "filter would have to be pushed into every store adapter's query");
362
+ }
363
+ const pinned = pinnedEmbedding(embedding, {
364
+ alias: spec.embedModel,
365
+ dimensions: init.dimensions ?? null,
366
+ });
367
+ if (store.dimensions !== null && store.dimensions !== pinned.dimensions) {
368
+ throw new ConfigurationError(`store ${repr(store.id)} is declared ${store.dimensions}-dimensional but retriever ` +
369
+ `${repr(spec.id)} pins ${pinned.dimensions} dimensions via embedModel ` +
370
+ `${repr(spec.embedModel)}; the two must agree before anything is indexed`);
371
+ }
372
+ return new RetrieverBinding({
373
+ retrieverId: spec.id,
374
+ source: spec.source,
375
+ chunking: spec.chunking,
376
+ embedModel: spec.embedModel,
377
+ embedding: pinned,
378
+ store: spec.store,
379
+ storeKind: store.kind,
380
+ storeUri: store.uri,
381
+ index: spec.index,
382
+ topK: spec.topK,
383
+ rerank: spec.rerank,
384
+ refreshMode: spec.refresh.mode,
385
+ traits: spec.traits,
386
+ });
387
+ }
388
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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iE,CACpE,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,EAAE;QACxC,KAAK,EAAE,IAAI,CAAC,UAAU;QACtB,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI;KACpC,CAAC,CAAC;IACH,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,IAAI,KAAK,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU,EAAE,CAAC;QACxE,MAAM,IAAI,kBAAkB,CAC1B,SAAS,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,gBAAgB,KAAK,CAAC,UAAU,6BAA6B;YAClF,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,UAAU,6BAA6B;YACvE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,iDAAiD,CAC5E,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,gBAAgB,CAAC;QAC1B,WAAW,EAAE,IAAI,CAAC,EAAE;QACpB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,SAAS,EAAE,MAAM;QACjB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,SAAS,EAAE,KAAK,CAAC,IAAI;QACrB,QAAQ,EAAE,KAAK,CAAC,GAAG;QACnB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;QAC9B,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Leaf pipeline steps: `generate`, `retrieve`, `tool` and `emit`.
3
+ *
4
+ * `pipeline.ts` runs steps and `control.ts` composes them; this module is the third
5
+ * part of the family and builds the leaves a pipeline actually reaches the outside
6
+ * world with. Each factory returns an ordinary {@link CompositeStep}, so a leaf
7
+ * composes with a composite by the same rule.
8
+ *
9
+ * Why these exist at all: a generated application inlines its steps as hand-written
10
+ * async functions, which leaves a caller who is *not* the generator -- a test, a
11
+ * conformance runner, a hand-built pipeline -- with no way to drive one step kind
12
+ * without re-writing the primitive's call and its binding rule. That duplication is
13
+ * where the two disagree. A step here is the same primitive the generator calls:
14
+ *
15
+ * - `retrieve` calls {@link RetrieverSeam.retrieve} and binds the `RetrievalResult`.
16
+ * - `tool` calls {@link ToolExecutor.execute} and binds what the tool returned,
17
+ * refusing an error outcome and parsing the content.
18
+ * - `generate` renders a prompt, calls {@link ModelGateway.generate}, and runs the
19
+ * structured path when the caller names an output type.
20
+ * - `emit` projects the context into the event fields a caller names.
21
+ *
22
+ * Every factory takes its inputs **already resolved**: the query string, the argument
23
+ * mapping, the prompt values. Interpolating a spec template against the context is the
24
+ * *emitted step body's* job, and a second implementation of it here would be a second
25
+ * thing to keep in step with the generator's. What is not duplicated is the part that
26
+ * is the same for every caller: the primitive call, the error contract, the parse, and
27
+ * the name the result is bound under.
28
+ *
29
+ * `emit` is the one leaf whose whole behaviour is reading the context, so
30
+ * {@link resolveSource} lives here rather than in a caller: a field's source is a
31
+ * binding name, optionally followed by one attribute, which is exactly the reference
32
+ * path the generator derives for the same field.
33
+ */
34
+ import type { CompositeStep } from './control.js';
35
+ import type { ModelGateway } from './gateway.js';
36
+ import type { PipelineContext } from './pipeline.js';
37
+ import type { PromptRegistry } from './prompts.js';
38
+ import type { RetrievalResult } from './retrieval/citations.js';
39
+ import type { StructuredOutput } from './structured.js';
40
+ import type { ToolExecutor } from './tools.js';
41
+ /**
42
+ * The context key an `emit` step binds its projected payload under.
43
+ *
44
+ * Deliberately *not* in `RESERVED_KEYS`. That set is mirrored in the generator and
45
+ * pinned against the runtime by a generator test, so a seventh entry would have to be
46
+ * emitted as well -- and the generated applications do not compose their response
47
+ * through this step yet. A generated route keeps building its event object itself;
48
+ * adding the key here would reserve a spec name for a step the emitted apps never
49
+ * call. {@link emitStep} takes the key as an option so the generator can adopt it
50
+ * under its own name when it does.
51
+ */
52
+ export declare const EMITTED_KEY = "emitted";
53
+ /**
54
+ * One `emit` field's value: a binding, then at most one attribute below it.
55
+ *
56
+ * The one-segment form is the request event's or a scalar binding's whole value; the
57
+ * two-segment form is a struct's field. Deeper paths are not accepted, because the
58
+ * spec layer's reference paths stop at one field and this resolver exists to read
59
+ * exactly what the generator reads.
60
+ *
61
+ * A missing binding is a {@link PipelineError} naming the key -- the same refusal
62
+ * {@link PipelineContext.require} makes -- and a missing attribute is one naming both
63
+ * the source and the field, because "the field is not there" and "the binding is not
64
+ * there" are different mistakes and both mean the response would be wrong.
65
+ */
66
+ export declare function resolveSource(context: PipelineContext, source: string): unknown;
67
+ /**
68
+ * Build the event payload from the context, field by field.
69
+ *
70
+ * `fields` maps each event field to its source, in the order the caller declared
71
+ * them: an insertion-ordered mapping keeps the payload's own order stable, so a
72
+ * projection that reorders its fields is observable rather than invisible. Each source
73
+ * is a binding name or a `binding.attribute` path, which is the shape the generator
74
+ * derives for the same field via `responsePlan`.
75
+ *
76
+ * The step **binds** its payload and does not stop the pipeline. Stopping would lose
77
+ * it: both runtimes carry the *pre-step* context out of a stop, so a stopping step
78
+ * cannot bind anything. A generated route does not stop at its emit either -- it runs
79
+ * every step and only then builds the response object -- so a later step still runs
80
+ * after this one, which is the behaviour a pipeline that composed it would see.
81
+ */
82
+ export declare function emitStep(fields: Readonly<Record<string, string>>, options?: {
83
+ readonly key?: string;
84
+ readonly name?: string;
85
+ }): CompositeStep;
86
+ /**
87
+ * The one method a `retrieve` step needs.
88
+ *
89
+ * `Retriever` satisfies it, which is what a generated application passes. Stated as a
90
+ * seam rather than as the concrete class so a caller that does not own a retriever -- a
91
+ * test, a conformance runner -- can drive the step without building an embedding model
92
+ * and a vector store it will never search. The step duplicates no part of the search:
93
+ * it decides the query, the ceiling and the name, and binding the result is all it adds.
94
+ */
95
+ export interface RetrieverSeam {
96
+ retrieve(query: string, options?: {
97
+ readonly topK?: number | null;
98
+ }): Promise<RetrievalResult>;
99
+ }
100
+ /**
101
+ * Search `retriever` and bind the cited passages under `binding`.
102
+ *
103
+ * `topK` is passed through rather than resolved here, so `undefined` keeps meaning
104
+ * "the binding's own ceiling" exactly as `Retriever.retrieve` defines it.
105
+ */
106
+ export declare function retrieveStep(retriever: RetrieverSeam, options: {
107
+ readonly binding: string;
108
+ readonly query: string;
109
+ readonly topK?: number;
110
+ readonly name?: string;
111
+ }): CompositeStep;
112
+ /**
113
+ * Call `tool` and bind what it returned, refusing an error outcome.
114
+ *
115
+ * The call id is the binding name, which makes a trace of a tool step name the value
116
+ * it produced. An error outcome throws rather than binding a message: a tool the model
117
+ * called and that failed is not a value the next step can meaningfully read, and the
118
+ * generator's own step throws for the same reason.
119
+ *
120
+ * `output` is the struct to parse the content into when the spec declared a named
121
+ * output; without one the content is bound as parsed JSON, so a tool declaring
122
+ * `string` binds the string it returned rather than a re-encoded copy.
123
+ */
124
+ export declare function toolStep(tools: ToolExecutor, options: {
125
+ readonly binding: string;
126
+ readonly tool: string;
127
+ readonly arguments: Readonly<Record<string, unknown>>;
128
+ readonly output?: StructuredOutput<unknown>;
129
+ readonly name?: string;
130
+ }): CompositeStep;
131
+ /**
132
+ * Render `prompt`, ask `model` for one completion, and bind the answer.
133
+ *
134
+ * The call is built once and handed to the structured path as its `call`, so a repair
135
+ * round re-sends an already-rendered prompt instead of rendering again -- the same
136
+ * closure the generated step emits, and the reason a retry cannot silently re-read a
137
+ * binding that changed underneath it.
138
+ *
139
+ * `values` are the prompt's own values and are passed to the registry unrendered:
140
+ * {@link PromptRegistry.render} is the one place a template becomes text. With
141
+ * `structured` the answer is parsed into that type, and a parse failure throws after
142
+ * the repair rounds rather than binding a half-valid object.
143
+ */
144
+ export declare function generateStep(gateway: ModelGateway, prompts: PromptRegistry, options: {
145
+ readonly binding: string;
146
+ readonly prompt: string;
147
+ readonly model: string;
148
+ readonly values?: Readonly<Record<string, unknown>>;
149
+ readonly version?: string;
150
+ readonly structured?: StructuredOutput<unknown>;
151
+ readonly temperature?: number;
152
+ readonly maxOutputTokens?: number;
153
+ readonly fallbacks?: readonly string[];
154
+ readonly name?: string;
155
+ }): CompositeStep;
156
+ //# sourceMappingURL=steps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../src/steps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,YAAY,CAAC;AAgBrC;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAuB/E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACxC,OAAO,GAAE;IAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAC9D,aAAa,CAQf;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ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