@framers/agentos 0.2.7 → 0.2.9

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 (69) hide show
  1. package/dist/cognitive-pipeline/index.d.ts +197 -0
  2. package/dist/cognitive-pipeline/index.d.ts.map +1 -0
  3. package/dist/cognitive-pipeline/index.js +193 -0
  4. package/dist/cognitive-pipeline/index.js.map +1 -0
  5. package/dist/ingest-router/IngestRouter.d.ts +72 -0
  6. package/dist/ingest-router/IngestRouter.d.ts.map +1 -0
  7. package/dist/ingest-router/IngestRouter.js +98 -0
  8. package/dist/ingest-router/IngestRouter.js.map +1 -0
  9. package/dist/ingest-router/classifier.d.ts +63 -0
  10. package/dist/ingest-router/classifier.d.ts.map +1 -0
  11. package/dist/ingest-router/classifier.js +111 -0
  12. package/dist/ingest-router/classifier.js.map +1 -0
  13. package/dist/ingest-router/costs.d.ts +48 -0
  14. package/dist/ingest-router/costs.d.ts.map +1 -0
  15. package/dist/ingest-router/costs.js +63 -0
  16. package/dist/ingest-router/costs.js.map +1 -0
  17. package/dist/ingest-router/dispatcher.d.ts +35 -0
  18. package/dist/ingest-router/dispatcher.d.ts.map +1 -0
  19. package/dist/ingest-router/dispatcher.js +32 -0
  20. package/dist/ingest-router/dispatcher.js.map +1 -0
  21. package/dist/ingest-router/index.d.ts +43 -0
  22. package/dist/ingest-router/index.d.ts.map +1 -0
  23. package/dist/ingest-router/index.js +37 -0
  24. package/dist/ingest-router/index.js.map +1 -0
  25. package/dist/ingest-router/routing-tables.d.ts +122 -0
  26. package/dist/ingest-router/routing-tables.d.ts.map +1 -0
  27. package/dist/ingest-router/routing-tables.js +145 -0
  28. package/dist/ingest-router/routing-tables.js.map +1 -0
  29. package/dist/ingest-router/select-strategy.d.ts +67 -0
  30. package/dist/ingest-router/select-strategy.d.ts.map +1 -0
  31. package/dist/ingest-router/select-strategy.js +100 -0
  32. package/dist/ingest-router/select-strategy.js.map +1 -0
  33. package/dist/memory-router/adaptive.d.ts +142 -0
  34. package/dist/memory-router/adaptive.d.ts.map +1 -0
  35. package/dist/memory-router/adaptive.js +202 -0
  36. package/dist/memory-router/adaptive.js.map +1 -0
  37. package/dist/memory-router/index.d.ts +2 -0
  38. package/dist/memory-router/index.d.ts.map +1 -1
  39. package/dist/memory-router/index.js +1 -0
  40. package/dist/memory-router/index.js.map +1 -1
  41. package/dist/read-router/ReadRouter.d.ts +58 -0
  42. package/dist/read-router/ReadRouter.d.ts.map +1 -0
  43. package/dist/read-router/ReadRouter.js +91 -0
  44. package/dist/read-router/ReadRouter.js.map +1 -0
  45. package/dist/read-router/classifier.d.ts +54 -0
  46. package/dist/read-router/classifier.d.ts.map +1 -0
  47. package/dist/read-router/classifier.js +104 -0
  48. package/dist/read-router/classifier.js.map +1 -0
  49. package/dist/read-router/costs.d.ts +23 -0
  50. package/dist/read-router/costs.d.ts.map +1 -0
  51. package/dist/read-router/costs.js +51 -0
  52. package/dist/read-router/costs.js.map +1 -0
  53. package/dist/read-router/dispatcher.d.ts +33 -0
  54. package/dist/read-router/dispatcher.d.ts.map +1 -0
  55. package/dist/read-router/dispatcher.js +29 -0
  56. package/dist/read-router/dispatcher.js.map +1 -0
  57. package/dist/read-router/index.d.ts +23 -0
  58. package/dist/read-router/index.d.ts.map +1 -0
  59. package/dist/read-router/index.js +17 -0
  60. package/dist/read-router/index.js.map +1 -0
  61. package/dist/read-router/routing-tables.d.ts +85 -0
  62. package/dist/read-router/routing-tables.d.ts.map +1 -0
  63. package/dist/read-router/routing-tables.js +79 -0
  64. package/dist/read-router/routing-tables.js.map +1 -0
  65. package/dist/read-router/select-strategy.d.ts +42 -0
  66. package/dist/read-router/select-strategy.d.ts.map +1 -0
  67. package/dist/read-router/select-strategy.js +92 -0
  68. package/dist/read-router/select-strategy.js.map +1 -0
  69. package/package.json +16 -1
@@ -0,0 +1,197 @@
1
+ /**
2
+ * AgentOS CognitivePipeline Module
3
+ *
4
+ * Smart per-message orchestration. Composes the LLM-as-judge stages of
5
+ * the agentos pipeline into one orchestrator. Each stage is independent
6
+ * and optional — wire only the stages you need, or compose all four.
7
+ *
8
+ * **What this is NOT:** safety guardrails. CognitivePipeline picks
9
+ * strategies (which architecture per ingest, which retrieval per recall,
10
+ * which reader per read). It does NOT block, refuse, or validate output —
11
+ * those concerns live in `core/guardrails` and the
12
+ * `agentos-ext-grounding-guard` / `agentos-ext-topicality` /
13
+ * `agentos-ext-pii-redaction` extensions.
14
+ *
15
+ * **The three orchestrator stages:**
16
+ *
17
+ * ```
18
+ * Content Query Query
19
+ * │ │ │
20
+ * ▼ ▼ ▼
21
+ * ┌─────────┐ ┌─────────────┐ ┌─────────────┐
22
+ * │ Ingest │ │ Recall │ │ Read │
23
+ * │ Stage │ │ Stage │ │ Stage │
24
+ * │ (input) │ │ (memory) │ │ (reader) │
25
+ * └─────────┘ └─────────────┘ └─────────────┘
26
+ * │ │ │
27
+ * ▼ ▼ ▼
28
+ * Memory state Retrieved traces Final answer
29
+ * ```
30
+ *
31
+ * Output guardrails (a separate, existing concern) sit downstream of the
32
+ * Read stage's answer to enforce safety and policy.
33
+ *
34
+ * **Why a composition primitive:** each individual router is independently
35
+ * useful and ships with its own classifier + dispatcher + table machinery.
36
+ * CognitivePipeline gives consumers a single object to coordinate the
37
+ * stages without duplicating per-stage wiring. It does NOT add new
38
+ * routing logic — it's a thin facade over the stage primitives.
39
+ *
40
+ * The interfaces below ({@link IngestStage}, {@link RecallStage},
41
+ * {@link ReadStage}) are deliberately minimal so consumers can wire any
42
+ * implementation:
43
+ *
44
+ * - The shipping `IngestRouter` / `MemoryRouter` / `ReadRouter` classes
45
+ * each satisfy the corresponding stage interface via thin adapters
46
+ * (see `ingestRouterAsStage` / `memoryRouterAsStage` / `readRouterAsStage`).
47
+ * - Custom implementations (rule-based, ML-driven, mock for tests) can
48
+ * satisfy the same interfaces and slot in.
49
+ *
50
+ * @module @framers/agentos/cognitive-pipeline
51
+ */
52
+ /**
53
+ * Generic decision metadata bundled with each stage's result. Stages
54
+ * report enough information for downstream telemetry without leaking
55
+ * stage-specific types into the orchestrator.
56
+ */
57
+ export interface IngestStageResult {
58
+ readonly writtenTraces: number;
59
+ readonly strategy: string;
60
+ readonly ingestRouterDecision: unknown;
61
+ }
62
+ export interface RecallStageResult<TTrace> {
63
+ readonly traces: TTrace[];
64
+ readonly backend: string;
65
+ readonly memoryRouterDecision: unknown;
66
+ }
67
+ export interface ReadStageResult<TOutcome> {
68
+ readonly outcome: TOutcome;
69
+ readonly strategy: string;
70
+ readonly readRouterDecision: unknown;
71
+ }
72
+ /**
73
+ * Pluggable input-stage. Wrap an `IngestRouter` or any equivalent
74
+ * implementation that turns content into stored traces.
75
+ */
76
+ export interface IngestStage {
77
+ ingest(content: string, payload?: unknown): Promise<IngestStageResult>;
78
+ }
79
+ /**
80
+ * Pluggable recall-stage. Wrap a `MemoryRouter` or any equivalent
81
+ * implementation that turns a query into retrieved traces.
82
+ */
83
+ export interface RecallStage<TTrace> {
84
+ recall(query: string, payload?: unknown): Promise<RecallStageResult<TTrace>>;
85
+ }
86
+ /**
87
+ * Pluggable read-stage. Wrap a `ReadRouter` or any equivalent
88
+ * implementation that turns a query+evidence pair into a final answer.
89
+ */
90
+ export interface ReadStage<TTrace, TOutcome> {
91
+ read(query: string, traces: TTrace[], payload?: unknown): Promise<ReadStageResult<TOutcome>>;
92
+ }
93
+ export interface RecallAndReadResult<TTrace, TOutcome> {
94
+ readonly recallStage: RecallStageResult<TTrace>;
95
+ readonly readStage: ReadStageResult<TOutcome>;
96
+ readonly outcome: TOutcome;
97
+ }
98
+ export interface CognitivePipelineOptions<TTrace, TOutcome> {
99
+ readonly ingest?: IngestStage;
100
+ readonly recall?: RecallStage<TTrace>;
101
+ readonly read?: ReadStage<TTrace, TOutcome>;
102
+ }
103
+ export declare class MissingStageError extends Error {
104
+ constructor(stage: 'IngestStage' | 'RecallStage' | 'ReadStage');
105
+ }
106
+ /**
107
+ * Top-level pipeline composition. One instance per agent / endpoint;
108
+ * reuse across requests.
109
+ *
110
+ * @example Full pipeline
111
+ * ```ts
112
+ * import { CognitivePipeline } from '../cognitive-pipeline';
113
+ * import { ingestRouterAsStage } from '../cognitive-pipeline';
114
+ *
115
+ * const pipeline = new CognitivePipeline({
116
+ * ingest: ingestRouterAsStage(myIngestRouter),
117
+ * recall: memoryRouterAsStage(myMemoryRouter),
118
+ * read: readRouterAsStage(myReadRouter),
119
+ * });
120
+ *
121
+ * await pipeline.ingest(newContent);
122
+ * const { outcome } = await pipeline.recallAndRead("what's my latest job?");
123
+ * ```
124
+ */
125
+ export declare class CognitivePipeline<TTrace, TOutcome> {
126
+ private readonly ingestStage;
127
+ private readonly recallStage;
128
+ private readonly readStage;
129
+ constructor(options: CognitivePipelineOptions<TTrace, TOutcome>);
130
+ get hasIngestStage(): boolean;
131
+ get hasRecallStage(): boolean;
132
+ get hasReadStage(): boolean;
133
+ ingest(content: string, payload?: unknown): Promise<IngestStageResult>;
134
+ recall(query: string, payload?: unknown): Promise<RecallStageResult<TTrace>>;
135
+ read(query: string, traces: TTrace[], payload?: unknown): Promise<ReadStageResult<TOutcome>>;
136
+ /**
137
+ * Recall traces for the query, then run the reader on those traces.
138
+ * Standard "ask a question, get an answer" path.
139
+ */
140
+ recallAndRead(query: string, recallPayload?: unknown, readPayload?: unknown): Promise<RecallAndReadResult<TTrace, TOutcome>>;
141
+ }
142
+ /**
143
+ * Wrap an `IngestRouter` as an {@link IngestStage}. The IngestRouter
144
+ * must have been constructed with a dispatcher; otherwise the stage will
145
+ * throw on every call.
146
+ */
147
+ export declare function ingestRouterAsStage<TOutcome extends {
148
+ writtenTraces?: number;
149
+ }>(router: {
150
+ decideAndDispatch: (content: string, payload?: unknown) => Promise<{
151
+ decision: {
152
+ routing: {
153
+ chosenStrategy: string;
154
+ };
155
+ };
156
+ outcome: TOutcome;
157
+ }>;
158
+ }): IngestStage;
159
+ /**
160
+ * Wrap a `MemoryRouter` as a {@link RecallStage}. The MemoryRouter
161
+ * must have been constructed with a dispatcher.
162
+ */
163
+ export declare function memoryRouterAsStage<TTrace>(router: {
164
+ decideAndDispatch: <T = TTrace>(query: string, payload?: unknown) => Promise<{
165
+ decision: {
166
+ routing: {
167
+ chosenBackend: string;
168
+ };
169
+ };
170
+ traces: T[];
171
+ backend: string;
172
+ }>;
173
+ }): RecallStage<TTrace>;
174
+ /**
175
+ * Wrap a `ReadRouter` as a {@link ReadStage}. The ReadRouter must
176
+ * have been constructed with a dispatcher.
177
+ */
178
+ export declare function readRouterAsStage<TTrace extends {
179
+ id?: string;
180
+ text?: string;
181
+ }, TOutcome>(router: {
182
+ decideAndDispatch: <T = TOutcome>(query: string, evidence: readonly string[], payload?: unknown) => Promise<{
183
+ decision: {
184
+ routing: {
185
+ chosenStrategy: string;
186
+ };
187
+ };
188
+ outcome: T;
189
+ }>;
190
+ },
191
+ /**
192
+ * Optional adapter to turn a TTrace into a string for the read-router's
193
+ * evidence array. Default: serialize `{id, text}`-shaped traces by
194
+ * concatenating text fields.
195
+ */
196
+ traceToString?: (trace: TTrace) => string): ReadStage<TTrace, TOutcome>;
197
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cognitive-pipeline/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAMH;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,oBAAoB,EAAE,OAAO,CAAC;CACxC;AAED,MAAM,WAAW,iBAAiB,CAAC,MAAM;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,oBAAoB,EAAE,OAAO,CAA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
+ * the agentos pipeline into one orchestrator. Each stage is independent
6
+ * and optional — wire only the stages you need, or compose all four.
7
+ *
8
+ * **What this is NOT:** safety guardrails. CognitivePipeline picks
9
+ * strategies (which architecture per ingest, which retrieval per recall,
10
+ * which reader per read). It does NOT block, refuse, or validate output —
11
+ * those concerns live in `core/guardrails` and the
12
+ * `agentos-ext-grounding-guard` / `agentos-ext-topicality` /
13
+ * `agentos-ext-pii-redaction` extensions.
14
+ *
15
+ * **The three orchestrator stages:**
16
+ *
17
+ * ```
18
+ * Content Query Query
19
+ * │ │ │
20
+ * ▼ ▼ ▼
21
+ * ┌─────────┐ ┌─────────────┐ ┌─────────────┐
22
+ * │ Ingest │ │ Recall │ │ Read │
23
+ * │ Stage │ │ Stage │ │ Stage │
24
+ * │ (input) │ │ (memory) │ │ (reader) │
25
+ * └─────────┘ └─────────────┘ └─────────────┘
26
+ * │ │ │
27
+ * ▼ ▼ ▼
28
+ * Memory state Retrieved traces Final answer
29
+ * ```
30
+ *
31
+ * Output guardrails (a separate, existing concern) sit downstream of the
32
+ * Read stage's answer to enforce safety and policy.
33
+ *
34
+ * **Why a composition primitive:** each individual router is independently
35
+ * useful and ships with its own classifier + dispatcher + table machinery.
36
+ * CognitivePipeline gives consumers a single object to coordinate the
37
+ * stages without duplicating per-stage wiring. It does NOT add new
38
+ * routing logic — it's a thin facade over the stage primitives.
39
+ *
40
+ * The interfaces below ({@link IngestStage}, {@link RecallStage},
41
+ * {@link ReadStage}) are deliberately minimal so consumers can wire any
42
+ * implementation:
43
+ *
44
+ * - The shipping `IngestRouter` / `MemoryRouter` / `ReadRouter` classes
45
+ * each satisfy the corresponding stage interface via thin adapters
46
+ * (see `ingestRouterAsStage` / `memoryRouterAsStage` / `readRouterAsStage`).
47
+ * - Custom implementations (rule-based, ML-driven, mock for tests) can
48
+ * satisfy the same interfaces and slot in.
49
+ *
50
+ * @module @framers/agentos/cognitive-pipeline
51
+ */
52
+ // ============================================================================
53
+ // Errors
54
+ // ============================================================================
55
+ export class MissingStageError extends Error {
56
+ constructor(stage) {
57
+ super(`CognitivePipeline: ${stage} is not configured. ` +
58
+ `Pass it in options at construction.`);
59
+ this.name = 'MissingStageError';
60
+ }
61
+ }
62
+ // ============================================================================
63
+ // Orchestrator
64
+ // ============================================================================
65
+ /**
66
+ * Top-level pipeline composition. One instance per agent / endpoint;
67
+ * reuse across requests.
68
+ *
69
+ * @example Full pipeline
70
+ * ```ts
71
+ * import { CognitivePipeline } from '../cognitive-pipeline/index.js';
72
+ * import { ingestRouterAsStage } from '../cognitive-pipeline';
73
+ *
74
+ * const pipeline = new CognitivePipeline({
75
+ * ingest: ingestRouterAsStage(myIngestRouter),
76
+ * recall: memoryRouterAsStage(myMemoryRouter),
77
+ * read: readRouterAsStage(myReadRouter),
78
+ * });
79
+ *
80
+ * await pipeline.ingest(newContent);
81
+ * const { outcome } = await pipeline.recallAndRead("what's my latest job?");
82
+ * ```
83
+ */
84
+ export class CognitivePipeline {
85
+ constructor(options) {
86
+ this.ingestStage = options.ingest ?? null;
87
+ this.recallStage = options.recall ?? null;
88
+ this.readStage = options.read ?? null;
89
+ }
90
+ get hasIngestStage() {
91
+ return this.ingestStage !== null;
92
+ }
93
+ get hasRecallStage() {
94
+ return this.recallStage !== null;
95
+ }
96
+ get hasReadStage() {
97
+ return this.readStage !== null;
98
+ }
99
+ async ingest(content, payload) {
100
+ if (!this.ingestStage)
101
+ throw new MissingStageError('IngestStage');
102
+ return this.ingestStage.ingest(content, payload);
103
+ }
104
+ async recall(query, payload) {
105
+ if (!this.recallStage)
106
+ throw new MissingStageError('RecallStage');
107
+ return this.recallStage.recall(query, payload);
108
+ }
109
+ async read(query, traces, payload) {
110
+ if (!this.readStage)
111
+ throw new MissingStageError('ReadStage');
112
+ return this.readStage.read(query, traces, payload);
113
+ }
114
+ /**
115
+ * Recall traces for the query, then run the reader on those traces.
116
+ * Standard "ask a question, get an answer" path.
117
+ */
118
+ async recallAndRead(query, recallPayload, readPayload) {
119
+ if (!this.recallStage)
120
+ throw new MissingStageError('RecallStage');
121
+ if (!this.readStage)
122
+ throw new MissingStageError('ReadStage');
123
+ const recallStage = await this.recallStage.recall(query, recallPayload);
124
+ const readStage = await this.readStage.read(query, recallStage.traces, readPayload);
125
+ return {
126
+ recallStage,
127
+ readStage,
128
+ outcome: readStage.outcome,
129
+ };
130
+ }
131
+ }
132
+ // ============================================================================
133
+ // Adapters: shipping routers → stage interfaces
134
+ // ============================================================================
135
+ /**
136
+ * Wrap an `IngestRouter` as an {@link IngestStage}. The IngestRouter
137
+ * must have been constructed with a dispatcher; otherwise the stage will
138
+ * throw on every call.
139
+ */
140
+ export function ingestRouterAsStage(router) {
141
+ return {
142
+ async ingest(content, payload) {
143
+ const result = await router.decideAndDispatch(content, payload);
144
+ return {
145
+ writtenTraces: result.outcome.writtenTraces ?? 0,
146
+ strategy: result.decision.routing.chosenStrategy,
147
+ ingestRouterDecision: result.decision,
148
+ };
149
+ },
150
+ };
151
+ }
152
+ /**
153
+ * Wrap a `MemoryRouter` as a {@link RecallStage}. The MemoryRouter
154
+ * must have been constructed with a dispatcher.
155
+ */
156
+ export function memoryRouterAsStage(router) {
157
+ return {
158
+ async recall(query, payload) {
159
+ const result = await router.decideAndDispatch(query, payload);
160
+ return {
161
+ traces: result.traces,
162
+ backend: result.backend,
163
+ memoryRouterDecision: result.decision,
164
+ };
165
+ },
166
+ };
167
+ }
168
+ /**
169
+ * Wrap a `ReadRouter` as a {@link ReadStage}. The ReadRouter must
170
+ * have been constructed with a dispatcher.
171
+ */
172
+ export function readRouterAsStage(router,
173
+ /**
174
+ * Optional adapter to turn a TTrace into a string for the read-router's
175
+ * evidence array. Default: serialize `{id, text}`-shaped traces by
176
+ * concatenating text fields.
177
+ */
178
+ traceToString) {
179
+ const toString = traceToString ??
180
+ ((t) => t.text ?? JSON.stringify(t));
181
+ return {
182
+ async read(query, traces, payload) {
183
+ const evidenceStrings = traces.map(toString);
184
+ const result = await router.decideAndDispatch(query, evidenceStrings, payload);
185
+ return {
186
+ outcome: result.outcome,
187
+ strategy: result.decision.routing.chosenStrategy,
188
+ readRouterDecision: result.decision,
189
+ };
190
+ },
191
+ };
192
+ }
193
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cognitive-pipeline/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AA6EH,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,KAAkD;QAC5D,KAAK,CACH,sBAAsB,KAAK,sBAAsB;YAC/C,qCAAqC,CACxC,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,iBAAiB;IAK5B,YAAY,OAAmD;QAC7D,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC;IACxC,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC;IACnC,CAAC;IACD,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC;IACnC,CAAC;IACD,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,OAAiB;QAC7C,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,iBAAiB,CAAC,aAAa,CAAC,CAAC;Q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AC,OAAO;gBACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc;gBAChD,kBAAkB,EAAE,MAAM,CAAC,QAAQ;aACpC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @file IngestRouter.ts
3
+ * @description Top-level input-stage orchestrator that composes the
4
+ * ingest classifier and the pure {@link selectIngestStrategy} into a
5
+ * single per-content routing call.
6
+ *
7
+ * Same shape as MemoryRouter (recall-stage) so the multi-stage guardrails
8
+ * orchestrator can compose them uniformly. Decide-only and decide+dispatch
9
+ * flows are both supported.
10
+ *
11
+ * @module @framers/agentos/ingest-router/IngestRouter
12
+ */
13
+ import type { IIngestClassifier, IngestClassifierResult } from './classifier.js';
14
+ import { type IngestStrategyCostPoint } from './costs.js';
15
+ import { type IngestContentKind, type IngestRouterPreset, type IngestRoutingTable, type IngestStrategyId } from './routing-tables.js';
16
+ import { type IngestBudgetMode, type IngestRoutingDecision } from './select-strategy.js';
17
+ import type { IIngestDispatcher } from './dispatcher.js';
18
+ export interface IngestBudgetPolicy {
19
+ readonly perIngestUsd?: number;
20
+ readonly mode?: IngestBudgetMode;
21
+ }
22
+ export interface IngestRouterOptions {
23
+ readonly classifier: IIngestClassifier;
24
+ readonly preset?: IngestRouterPreset;
25
+ readonly routingTable?: IngestRoutingTable;
26
+ readonly mapping?: Partial<Record<IngestContentKind, IngestStrategyId>>;
27
+ readonly budget?: IngestBudgetPolicy;
28
+ readonly strategyCosts?: Readonly<Record<IngestStrategyId, IngestStrategyCostPoint>>;
29
+ readonly useFewShotPrompt?: boolean;
30
+ readonly dispatcher?: IIngestDispatcher<unknown, unknown>;
31
+ }
32
+ export interface IngestRouterDecideOptions {
33
+ /**
34
+ * Optional manual override of the classifier. When set, the classifier
35
+ * is NOT invoked and the routing table is consulted with this kind
36
+ * directly. Useful when the caller already knows the content kind
37
+ * (e.g., file extension determines code vs structured-data).
38
+ */
39
+ readonly manualKind?: IngestContentKind;
40
+ readonly groundTruthKind?: IngestContentKind | null;
41
+ readonly useFewShotPrompt?: boolean;
42
+ }
43
+ export interface IngestRouterDecision {
44
+ readonly classifier: IngestClassifierResult;
45
+ readonly routing: IngestRoutingDecision;
46
+ }
47
+ export interface IngestRouterDispatchedResult<TOutcome> {
48
+ readonly decision: IngestRouterDecision;
49
+ readonly outcome: TOutcome;
50
+ readonly strategy: IngestStrategyId;
51
+ }
52
+ export declare class IngestRouterDispatcherMissingError extends Error {
53
+ constructor();
54
+ }
55
+ /**
56
+ * Public input-stage orchestrator. One instance per ingest endpoint;
57
+ * reuse across content events.
58
+ */
59
+ export declare class IngestRouter {
60
+ private readonly classifier;
61
+ private readonly preset;
62
+ private readonly routingTable;
63
+ private readonly budgetPerIngestUsd;
64
+ private readonly budgetMode;
65
+ private readonly strategyCosts;
66
+ private readonly defaultUseFewShotPrompt;
67
+ private readonly dispatcher;
68
+ constructor(options: IngestRouterOptions);
69
+ decide(content: string, options?: IngestRouterDecideOptions): Promise<IngestRouterDecision>;
70
+ decideAndDispatch<TOutcome, TPayload = undefined>(content: string, dispatchPayload?: TPayload, options?: IngestRouterDecideOptions): Promise<IngestRouterDispatchedResult<TOutcome>>;
71
+ }
72
+ //# sourceMappingURL=IngestRouter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IngestRouter.d.ts","sourceRoot":"","sources":["../../src/ingest-router/IngestRouter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,YAAY,CAAC;AACpB,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,q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,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;CACrC;AAED,qBAAa,kCAAmC,SAAQ,KAAK;;CAQ5D;AAED;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAgB;IACnD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAE5B;IACF,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAU;IAClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6C;gBAE5D,OAAO,EAAE,mBAAmB;IA4BlC,MAAM,CACV,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,yBAAyB,GAClC,OAAO,CAAC,oBAAoB,CAAC;IAgC1B,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,EACpD,OAAO,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,QAAQ,EAC1B,OAAO,CAAC,EAAE,yBAAyB,GAClC,OAAO,CAAC,4BAA4B,CAAC,QAAQ,CAAC,CAAC;CAkBnD"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @file IngestRouter.ts
3
+ * @description Top-level input-stage orchestrator that composes the
4
+ * ingest classifier and the pure {@link selectIngestStrategy} into a
5
+ * single per-content routing call.
6
+ *
7
+ * Same shape as MemoryRouter (recall-stage) so the multi-stage guardrails
8
+ * orchestrator can compose them uniformly. Decide-only and decide+dispatch
9
+ * flows are both supported.
10
+ *
11
+ * @module @framers/agentos/ingest-router/IngestRouter
12
+ */
13
+ import { DEFAULT_INGEST_COSTS, } from './costs.js';
14
+ import { PRESET_INGEST_TABLES, } from './routing-tables.js';
15
+ import { selectIngestStrategy, } from './select-strategy.js';
16
+ export class IngestRouterDispatcherMissingError extends Error {
17
+ constructor() {
18
+ super('IngestRouter.decideAndDispatch requires a dispatcher. ' +
19
+ 'Either pass a dispatcher in options or call `decide` and dispatch yourself.');
20
+ this.name = 'IngestRouterDispatcherMissingError';
21
+ }
22
+ }
23
+ /**
24
+ * Public input-stage orchestrator. One instance per ingest endpoint;
25
+ * reuse across content events.
26
+ */
27
+ export class IngestRouter {
28
+ constructor(options) {
29
+ this.classifier = options.classifier;
30
+ this.preset = options.preset ?? 'raw-chunks';
31
+ this.dispatcher = options.dispatcher ?? null;
32
+ const baseTable = options.routingTable ?? PRESET_INGEST_TABLES[this.preset];
33
+ if (options.mapping) {
34
+ const patched = {
35
+ ...baseTable.defaultMapping,
36
+ };
37
+ for (const key of Object.keys(options.mapping)) {
38
+ const ov = options.mapping[key];
39
+ if (ov)
40
+ patched[key] = ov;
41
+ }
42
+ this.routingTable = Object.freeze({
43
+ preset: baseTable.preset,
44
+ defaultMapping: Object.freeze(patched),
45
+ });
46
+ }
47
+ else {
48
+ this.routingTable = baseTable;
49
+ }
50
+ this.budgetPerIngestUsd = options.budget?.perIngestUsd ?? null;
51
+ this.budgetMode = options.budget?.mode ?? 'cheapest-fallback';
52
+ this.strategyCosts = options.strategyCosts ?? DEFAULT_INGEST_COSTS;
53
+ this.defaultUseFewShotPrompt = options.useFewShotPrompt ?? false;
54
+ }
55
+ async decide(content, options) {
56
+ let classifier;
57
+ if (options?.manualKind) {
58
+ classifier = {
59
+ kind: options.manualKind,
60
+ tokensIn: 0,
61
+ tokensOut: 0,
62
+ model: 'manual',
63
+ };
64
+ }
65
+ else {
66
+ const useFewShot = options?.useFewShotPrompt ?? this.defaultUseFewShotPrompt;
67
+ classifier = await this.classifier.classify(content, useFewShot ? { useFewShotPrompt: true } : undefined);
68
+ }
69
+ const routing = selectIngestStrategy({
70
+ predictedKind: classifier.kind,
71
+ groundTruthKind: options?.groundTruthKind ?? null,
72
+ config: {
73
+ table: this.routingTable,
74
+ budgetPerIngestUsd: this.budgetPerIngestUsd,
75
+ budgetMode: this.budgetMode,
76
+ strategyCosts: this.strategyCosts,
77
+ },
78
+ });
79
+ return { classifier, routing };
80
+ }
81
+ async decideAndDispatch(content, dispatchPayload, options) {
82
+ if (!this.dispatcher) {
83
+ throw new IngestRouterDispatcherMissingError();
84
+ }
85
+ const decision = await this.decide(content, options);
86
+ const dispatched = (await this.dispatcher.dispatch({
87
+ strategy: decision.routing.chosenStrategy,
88
+ content,
89
+ payload: dispatchPayload,
90
+ }));
91
+ return {
92
+ decision,
93
+ outcome: dispatched.outcome,
94
+ strategy: dispatched.strategy,
95
+ };
96
+ }
97
+ }
98
+ //# sourceMappingURL=IngestRouter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IngestRouter.js","sourceRoot":"","sources":["../../src/ingest-router/IngestRouter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,EACL,oBAAoB,GAErB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,GAKrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,GAGrB,MAAM,sBAAsB,CAAC;AA+C9B,MAAM,OAAO,kCAAmC,SAAQ,KAAK;IAC3D;QACE,KAAK,CACH,wDAAwD;YACtD,6EAA6E,CAChF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,oCAAoC,CAAC;IACnD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,YAAY;IAYvB,YAAY,OAA4B;QACtC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,YAAY,CAAC;QAC7C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC;QAE7C,MAAM,SAAS,GAAG,OAAO,CAAC,YAAY,IAAI,oBAAoB,CAAC,IAAI,CAAC,MA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classifier that maps a piece of content to
4
+ * one of the six {@link IngestContentKind} values.
5
+ *
6
+ * Same shape as the memory-router classifier — deliberately so the
7
+ * multi-stage guardrails orchestrator can compose them with one mental
8
+ * model.
9
+ *
10
+ * @module @framers/agentos/ingest-router/classifier
11
+ */
12
+ import { type IngestContentKind } from './routing-tables.js';
13
+ export interface IngestClassifierLLMRequest {
14
+ readonly system: string;
15
+ readonly user: string;
16
+ readonly maxTokens: number;
17
+ readonly temperature: number;
18
+ }
19
+ export interface IngestClassifierLLMResponse {
20
+ readonly text: string;
21
+ readonly tokensIn: number;
22
+ readonly tokensOut: number;
23
+ readonly model: string;
24
+ }
25
+ export interface IIngestClassifierLLM {
26
+ invoke(request: IngestClassifierLLMRequest): Promise<IngestClassifierLLMResponse>;
27
+ }
28
+ export interface IngestClassifierClassifyOptions {
29
+ /** Use the few-shot prompt variant (more accurate on ambiguous content). */
30
+ readonly useFewShotPrompt?: boolean;
31
+ }
32
+ export interface IngestClassifierResult {
33
+ readonly kind: IngestContentKind;
34
+ readonly tokensIn: number;
35
+ readonly tokensOut: number;
36
+ readonly model: string;
37
+ }
38
+ export interface IIngestClassifier {
39
+ classify(content: string, options?: IngestClassifierClassifyOptions): Promise<IngestClassifierResult>;
40
+ }
41
+ export declare const INGEST_CLASSIFIER_SYSTEM_PROMPT = "You are classifying a piece of content into one of six ingest kinds for memory storage.\n\nReturn ONLY the kind token (no explanation, no quotes, no punctuation).\n\nKinds:\n- short-conversation: 1-3 turns of chat dialog. Examples: a one-message Q&A, a brief support exchange.\n- long-conversation: extended chat sessions across many turns. Examples: a 50-turn coding conversation, a 30-turn customer support thread.\n- long-article: prose document over ~500 words. Examples: a blog post, a research paper section, a long email.\n- code: source code, configuration files, schemas. Examples: a TypeScript module, a SQL migration, a JSON schema.\n- structured-data: tabular or JSON-style records. Examples: a CSV, a JSON list of records, a database export.\n- multimodal: content that includes images, video frames, or audio. Examples: a PDF with figures, a presentation slide.";
42
+ export declare const INGEST_CLASSIFIER_SYSTEM_PROMPT_FEWSHOT = "You are classifying a piece of content into one of six ingest kinds for memory storage.\n\nReturn ONLY the kind token (no explanation, no quotes, no punctuation).\n\nKinds:\n- short-conversation: 1-3 turns of chat dialog.\n- long-conversation: extended chat sessions across many turns.\n- long-article: prose document over ~500 words.\n- code: source code, configuration files, schemas.\n- structured-data: tabular or JSON-style records.\n- multimodal: content that includes images, video frames, or audio.\n\nExamples:\n\nContent: \"user: hi\\nassistant: hi! how can I help?\"\nKind: short-conversation\n\nContent: \"[3000 words of a research paper introduction]\"\nKind: long-article\n\nContent: \"export function fibonacci(n: number): number { return n < 2 ? n : fibonacci(n-1) + fibonacci(n-2); }\"\nKind: code\n\nContent: \"[CSV with 50 rows of user records]\"\nKind: structured-data\n\nContent: \"[40 turns of a customer-support thread]\"\nKind: long-conversation\n\nContent: \"[image bytes + caption text]\"\nKind: multimodal";
43
+ export declare const SAFE_INGEST_FALLBACK_KIND: IngestContentKind;
44
+ export declare function normalizeIngestClassifierOutput(raw: string): string;
45
+ export declare function parseIngestClassifierOutput(raw: string): IngestContentKind;
46
+ export interface LLMIngestClassifierOptions {
47
+ readonly llm: IIngestClassifierLLM;
48
+ readonly maxTokens?: number;
49
+ /**
50
+ * Maximum content characters to forward to the classifier. Most ingest
51
+ * decisions can be made from the first ~1k chars (kind detection
52
+ * doesn't require the full body). Default 1000.
53
+ */
54
+ readonly maxContentChars?: number;
55
+ }
56
+ export declare class LLMIngestClassifier implements IIngestClassifier {
57
+ private readonly llm;
58
+ private readonly maxTokens;
59
+ private readonly maxContentChars;
60
+ constructor(options: LLMIngestClassifierOptions);
61
+ classify(content: string, options?: IngestClassifierClassifyOptions): Promise<IngestClassifierResult>;
62
+ }
63
+ //# sourceMappingURL=classifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../../src/ingest-router/classifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAEL,KAAK,iBAA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