@graphrefly/graphrefly 0.25.0 → 0.27.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/README.md +8 -0
- package/dist/ai-CaR_912Q.d.cts +1033 -0
- package/dist/ai-WlRltJV7.d.ts +1033 -0
- package/dist/audit-ClmqGOCx.d.cts +245 -0
- package/dist/audit-DRlSzBu9.d.ts +245 -0
- package/dist/{chunk-QOWVNWOC.js → chunk-3ZWCKRHX.js} +27 -25
- package/dist/{chunk-QOWVNWOC.js.map → chunk-3ZWCKRHX.js.map} +1 -1
- package/dist/chunk-APFNLIRG.js +62 -0
- package/dist/chunk-APFNLIRG.js.map +1 -0
- package/dist/chunk-AT5LKYNL.js +395 -0
- package/dist/chunk-AT5LKYNL.js.map +1 -0
- package/dist/{chunk-IAHGTNOZ.js → chunk-BQ6RQQFF.js} +351 -2095
- package/dist/chunk-BQ6RQQFF.js.map +1 -0
- package/dist/{chunk-L2GLW2U7.js → chunk-BVZYTZ5H.js} +9 -103
- package/dist/chunk-BVZYTZ5H.js.map +1 -0
- package/dist/{chunk-EVR6UFUV.js → chunk-DST5DKZS.js} +19 -15
- package/dist/{chunk-EVR6UFUV.js.map → chunk-DST5DKZS.js.map} +1 -1
- package/dist/{chunk-TKE3JGOH.js → chunk-GTE6PWRZ.js} +5 -692
- package/dist/chunk-GTE6PWRZ.js.map +1 -0
- package/dist/chunk-HXZEYDUR.js +94 -0
- package/dist/chunk-HXZEYDUR.js.map +1 -0
- package/dist/chunk-J22W6HV3.js +107 -0
- package/dist/chunk-J22W6HV3.js.map +1 -0
- package/dist/{chunk-PY4XCDLR.js → chunk-J2VBW3DZ.js} +6 -95
- package/dist/chunk-J2VBW3DZ.js.map +1 -0
- package/dist/{chunk-HWPIFSW2.js → chunk-JSCT3CR4.js} +6 -4
- package/dist/{chunk-HWPIFSW2.js.map → chunk-JSCT3CR4.js.map} +1 -1
- package/dist/chunk-JWBCY4NC.js +330 -0
- package/dist/chunk-JWBCY4NC.js.map +1 -0
- package/dist/chunk-K2AUJHVP.js +2251 -0
- package/dist/chunk-K2AUJHVP.js.map +1 -0
- package/dist/chunk-MJ2NKQQL.js +119 -0
- package/dist/chunk-MJ2NKQQL.js.map +1 -0
- package/dist/chunk-N6UR7YVY.js +198 -0
- package/dist/chunk-N6UR7YVY.js.map +1 -0
- package/dist/chunk-NC6S43JJ.js +456 -0
- package/dist/chunk-NC6S43JJ.js.map +1 -0
- package/dist/chunk-OFVJBJXR.js +98 -0
- package/dist/chunk-OFVJBJXR.js.map +1 -0
- package/dist/chunk-OHISZPOJ.js +97 -0
- package/dist/chunk-OHISZPOJ.js.map +1 -0
- package/dist/chunk-OU5CQKNW.js +102 -0
- package/dist/chunk-OU5CQKNW.js.map +1 -0
- package/dist/{chunk-XOFWRC73.js → chunk-PF7GRZMW.js} +316 -21
- package/dist/chunk-PF7GRZMW.js.map +1 -0
- package/dist/{chunk-5DJTTKX3.js → chunk-PHOUUNK7.js} +74 -111
- package/dist/chunk-PHOUUNK7.js.map +1 -0
- package/dist/chunk-RNHBMHKA.js +1665 -0
- package/dist/chunk-RNHBMHKA.js.map +1 -0
- package/dist/chunk-SX52TAR4.js +110 -0
- package/dist/chunk-SX52TAR4.js.map +1 -0
- package/dist/{chunk-H4RVA4VE.js → chunk-VYPWMZ6H.js} +2 -2
- package/dist/chunk-WBZOVTYK.js +171 -0
- package/dist/chunk-WBZOVTYK.js.map +1 -0
- package/dist/chunk-WKNUIZOY.js +354 -0
- package/dist/chunk-WKNUIZOY.js.map +1 -0
- package/dist/chunk-X3VMZYBT.js +713 -0
- package/dist/chunk-X3VMZYBT.js.map +1 -0
- package/dist/chunk-X5R3GL6H.js +525 -0
- package/dist/chunk-X5R3GL6H.js.map +1 -0
- package/dist/chunk-XGPU467M.js +136 -0
- package/dist/chunk-XGPU467M.js.map +1 -0
- package/dist/compat/index.cjs +7656 -0
- package/dist/compat/index.cjs.map +1 -0
- package/dist/compat/index.d.cts +18 -0
- package/dist/compat/index.d.ts +18 -0
- package/dist/compat/index.js +50 -0
- package/dist/compat/index.js.map +1 -0
- package/dist/compat/jotai/index.cjs +2048 -0
- package/dist/compat/jotai/index.cjs.map +1 -0
- package/dist/compat/jotai/index.d.cts +2 -0
- package/dist/compat/jotai/index.d.ts +2 -0
- package/dist/compat/jotai/index.js +9 -0
- package/dist/compat/jotai/index.js.map +1 -0
- package/dist/compat/nanostores/index.cjs +2175 -0
- package/dist/compat/nanostores/index.cjs.map +1 -0
- package/dist/compat/nanostores/index.d.cts +2 -0
- package/dist/compat/nanostores/index.d.ts +2 -0
- package/dist/compat/nanostores/index.js +23 -0
- package/dist/compat/nanostores/index.js.map +1 -0
- package/dist/compat/nestjs/index.cjs +350 -16
- package/dist/compat/nestjs/index.cjs.map +1 -1
- package/dist/compat/nestjs/index.d.cts +6 -6
- package/dist/compat/nestjs/index.d.ts +6 -6
- package/dist/compat/nestjs/index.js +11 -9
- package/dist/compat/react/index.cjs +141 -0
- package/dist/compat/react/index.cjs.map +1 -0
- package/dist/compat/react/index.d.cts +2 -0
- package/dist/compat/react/index.d.ts +2 -0
- package/dist/compat/react/index.js +12 -0
- package/dist/compat/react/index.js.map +1 -0
- package/dist/compat/solid/index.cjs +128 -0
- package/dist/compat/solid/index.cjs.map +1 -0
- package/dist/compat/solid/index.d.cts +2 -0
- package/dist/compat/solid/index.d.ts +2 -0
- package/dist/compat/solid/index.js +12 -0
- package/dist/compat/solid/index.js.map +1 -0
- package/dist/compat/svelte/index.cjs +131 -0
- package/dist/compat/svelte/index.cjs.map +1 -0
- package/dist/compat/svelte/index.d.cts +2 -0
- package/dist/compat/svelte/index.d.ts +2 -0
- package/dist/compat/svelte/index.js +12 -0
- package/dist/compat/svelte/index.js.map +1 -0
- package/dist/compat/vue/index.cjs +146 -0
- package/dist/compat/vue/index.cjs.map +1 -0
- package/dist/compat/vue/index.d.cts +3 -0
- package/dist/compat/vue/index.d.ts +3 -0
- package/dist/compat/vue/index.js +12 -0
- package/dist/compat/vue/index.js.map +1 -0
- package/dist/compat/zustand/index.cjs +4931 -0
- package/dist/compat/zustand/index.cjs.map +1 -0
- package/dist/compat/zustand/index.d.cts +5 -0
- package/dist/compat/zustand/index.d.ts +5 -0
- package/dist/compat/zustand/index.js +12 -0
- package/dist/compat/zustand/index.js.map +1 -0
- package/dist/composite-C7PcQvcs.d.cts +303 -0
- package/dist/composite-aUCvjZVR.d.ts +303 -0
- package/dist/core/index.cjs +53 -4
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +4 -3
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.js +26 -24
- package/dist/demo-shell-BDkOptd6.d.ts +102 -0
- package/dist/demo-shell-Crid1WdR.d.cts +102 -0
- package/dist/extra/index.cjs +222 -110
- package/dist/extra/index.cjs.map +1 -1
- package/dist/extra/index.d.cts +6 -4
- package/dist/extra/index.d.ts +6 -4
- package/dist/extra/index.js +72 -65
- package/dist/extra/sources.cjs +2486 -0
- package/dist/extra/sources.cjs.map +1 -0
- package/dist/extra/sources.d.cts +465 -0
- package/dist/extra/sources.d.ts +465 -0
- package/dist/extra/sources.js +57 -0
- package/dist/extra/sources.js.map +1 -0
- package/dist/graph/index.cjs +408 -14
- package/dist/graph/index.cjs.map +1 -1
- package/dist/graph/index.d.cts +5 -5
- package/dist/graph/index.d.ts +5 -5
- package/dist/graph/index.js +13 -5
- package/dist/{graph-D-3JIQme.d.cts → graph-CCwGKLCm.d.ts} +195 -4
- package/dist/{graph-B6NFqv3z.d.ts → graph-DNCrvZSn.d.cts} +195 -4
- package/dist/index-3lsddbbS.d.ts +86 -0
- package/dist/index-B1tloyhO.d.cts +34 -0
- package/dist/{index-CYkjxu3s.d.ts → index-B6D3QNSA.d.ts} +33 -4
- package/dist/index-B6EhDnjH.d.cts +37 -0
- package/dist/index-B9B7_HEY.d.ts +37 -0
- package/dist/{index-Ds23Wvou.d.ts → index-BHlKbUwO.d.cts} +131 -883
- package/dist/{index-DiobMNwE.d.ts → index-BPVt8kqc.d.ts} +3 -3
- package/dist/index-BaSM3aYt.d.ts +195 -0
- package/dist/index-BuEoe-Qu.d.ts +121 -0
- package/dist/{index-Ch0IpIO0.d.cts → index-BwfLUNw4.d.ts} +131 -883
- package/dist/index-ByQxazQJ.d.cts +86 -0
- package/dist/index-C0svESO4.d.ts +127 -0
- package/dist/{index-OXImXMq6.d.ts → index-C8oil6M6.d.ts} +18 -196
- package/dist/{index-DKE1EATr.d.cts → index-CI3DprxP.d.cts} +18 -196
- package/dist/{index-AMWewNDe.d.cts → index-CO8uBlUh.d.cts} +33 -4
- package/dist/index-CxFrXH4m.d.ts +45 -0
- package/dist/index-D8wS_PeY.d.cts +121 -0
- package/dist/index-DO_6JN9Z.d.cts +127 -0
- package/dist/index-DVGiGFGT.d.cts +195 -0
- package/dist/index-DYme44FM.d.cts +44 -0
- package/dist/{index-J7Kc0oIQ.d.cts → index-DlLp-2Xn.d.cts} +3 -3
- package/dist/index-Dzk2hrlR.d.ts +44 -0
- package/dist/index-VHqptjhu.d.cts +45 -0
- package/dist/index-VdHQMPy1.d.ts +36 -0
- package/dist/index-Xi3u0HCQ.d.cts +36 -0
- package/dist/index-wEn0eFe8.d.ts +34 -0
- package/dist/index.cjs +1780 -176
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +784 -2082
- package/dist/index.d.ts +784 -2082
- package/dist/index.js +955 -4349
- package/dist/index.js.map +1 -1
- package/dist/memory-C6Z2tGpC.d.cts +139 -0
- package/dist/memory-li6FL5RM.d.ts +139 -0
- package/dist/messaging-Gt4LPbyA.d.cts +269 -0
- package/dist/messaging-XDoYablx.d.ts +269 -0
- package/dist/{meta-DWbkoq1s.d.cts → meta-BxCA7rcr.d.cts} +1 -1
- package/dist/{meta-CnkLA_43.d.ts → meta-CbznRPYJ.d.ts} +1 -1
- package/dist/{node-B-f-Lu-k.d.cts → node-BmerH3kS.d.cts} +26 -1
- package/dist/{node-B-f-Lu-k.d.ts → node-BmerH3kS.d.ts} +26 -1
- package/dist/{observable-uP-wy_uK.d.ts → observable-BgGUwcqp.d.ts} +1 -1
- package/dist/{observable-DBnrwcar.d.cts → observable-DJt_AxzQ.d.cts} +1 -1
- package/dist/patterns/ai.cjs +7930 -0
- package/dist/patterns/ai.cjs.map +1 -0
- package/dist/patterns/ai.d.cts +10 -0
- package/dist/patterns/ai.d.ts +10 -0
- package/dist/patterns/ai.js +71 -0
- package/dist/patterns/ai.js.map +1 -0
- package/dist/patterns/audit.cjs +5805 -0
- package/dist/patterns/audit.cjs.map +1 -0
- package/dist/patterns/audit.d.cts +6 -0
- package/dist/patterns/audit.d.ts +6 -0
- package/dist/patterns/audit.js +29 -0
- package/dist/patterns/audit.js.map +1 -0
- package/dist/patterns/demo-shell.cjs +5604 -0
- package/dist/patterns/demo-shell.cjs.map +1 -0
- package/dist/patterns/demo-shell.d.cts +6 -0
- package/dist/patterns/demo-shell.d.ts +6 -0
- package/dist/patterns/demo-shell.js +15 -0
- package/dist/patterns/demo-shell.js.map +1 -0
- package/dist/patterns/memory.cjs +5283 -0
- package/dist/patterns/memory.cjs.map +1 -0
- package/dist/patterns/memory.d.cts +5 -0
- package/dist/patterns/memory.d.ts +5 -0
- package/dist/patterns/memory.js +20 -0
- package/dist/patterns/memory.js.map +1 -0
- package/dist/patterns/reactive-layout/index.cjs +355 -13
- package/dist/patterns/reactive-layout/index.cjs.map +1 -1
- package/dist/patterns/reactive-layout/index.d.cts +6 -5
- package/dist/patterns/reactive-layout/index.d.ts +6 -5
- package/dist/patterns/reactive-layout/index.js +15 -12
- package/dist/reactive-layout-MQP--J3F.d.cts +183 -0
- package/dist/reactive-layout-u5Ulnqag.d.ts +183 -0
- package/dist/{storage-BuTdpCI1.d.cts → storage-CMjUUuxn.d.ts} +10 -2
- package/dist/{storage-F2X1U1x0.d.ts → storage-DdWlZo6U.d.cts} +10 -2
- package/dist/sugar-CCOxXK1e.d.ts +201 -0
- package/dist/sugar-D02n5JjF.d.cts +201 -0
- package/package.json +63 -3
- package/dist/chunk-5DJTTKX3.js.map +0 -1
- package/dist/chunk-IAHGTNOZ.js.map +0 -1
- package/dist/chunk-L2GLW2U7.js.map +0 -1
- package/dist/chunk-MW4VAKAO.js +0 -47
- package/dist/chunk-MW4VAKAO.js.map +0 -1
- package/dist/chunk-PY4XCDLR.js.map +0 -1
- package/dist/chunk-TKE3JGOH.js.map +0 -1
- package/dist/chunk-XOFWRC73.js.map +0 -1
- package/dist/index-BJB7t9gg.d.cts +0 -392
- package/dist/index-C-TXEa7C.d.ts +0 -392
- /package/dist/{chunk-H4RVA4VE.js.map → chunk-VYPWMZ6H.js.map} +0 -0
|
@@ -0,0 +1,1033 @@
|
|
|
1
|
+
import { N as Node, a as NodeOptions, t as NodeActions, A as Actor } from './node-BmerH3kS.cjs';
|
|
2
|
+
import { D as DistillBundle, E as Extraction } from './composite-C7PcQvcs.cjs';
|
|
3
|
+
import { NodeInput } from './extra/sources.cjs';
|
|
4
|
+
import { a as StorageHandle, S as StorageTier } from './storage-DdWlZo6U.cjs';
|
|
5
|
+
import { a as Graph, G as GraphOptions, k as GraphAttachStorageOptions } from './graph-DNCrvZSn.cjs';
|
|
6
|
+
import { V as VectorIndexBundle, K as KnowledgeGraphGraph, L as LightCollectionBundle, a as VectorSearchResult } from './memory-C6Z2tGpC.cjs';
|
|
7
|
+
import { T as TopicGraph } from './messaging-Gt4LPbyA.cjs';
|
|
8
|
+
import { D as DerivedFn } from './sugar-D02n5JjF.cjs';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Orchestration patterns (roadmap §4.1).
|
|
12
|
+
*
|
|
13
|
+
* Domain-layer helpers that build workflow shapes on top of core + extra primitives.
|
|
14
|
+
* Exported under the `patterns.orchestration` namespace to avoid collisions with
|
|
15
|
+
* Phase 2 operator names (for example `gate`, `forEach`).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
type StepRef = string | Node<unknown>;
|
|
19
|
+
type OrchestrationMeta = {
|
|
20
|
+
orchestration?: true;
|
|
21
|
+
orchestration_type?: string;
|
|
22
|
+
};
|
|
23
|
+
type OrchestrationStepOptions = Omit<NodeOptions<unknown>, "describeKind" | "name" | "meta"> & {
|
|
24
|
+
deps?: ReadonlyArray<StepRef>;
|
|
25
|
+
meta?: Record<string, unknown> & OrchestrationMeta;
|
|
26
|
+
};
|
|
27
|
+
type BranchResult<T> = {
|
|
28
|
+
branch: "then" | "else";
|
|
29
|
+
value: T;
|
|
30
|
+
};
|
|
31
|
+
type SensorControls<T> = {
|
|
32
|
+
node: Node<T>;
|
|
33
|
+
push(value: T): void;
|
|
34
|
+
error(err: unknown): void;
|
|
35
|
+
complete(): void;
|
|
36
|
+
};
|
|
37
|
+
type LoopOptions = Omit<OrchestrationStepOptions, "deps"> & {
|
|
38
|
+
iterations?: number | StepRef;
|
|
39
|
+
};
|
|
40
|
+
type WaitOptions = Omit<OrchestrationStepOptions, "deps">;
|
|
41
|
+
type SubPipelineBuilder = (sub: Graph) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Creates an orchestration graph container.
|
|
44
|
+
*/
|
|
45
|
+
declare function pipeline(name: string, opts?: GraphOptions): Graph;
|
|
46
|
+
/**
|
|
47
|
+
* Registers a workflow task node.
|
|
48
|
+
*/
|
|
49
|
+
declare function task<T>(graph: Graph, name: string, run: DerivedFn<T>, opts?: OrchestrationStepOptions): Node<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Emits tagged branch outcomes (`then` / `else`) for each source value.
|
|
52
|
+
*/
|
|
53
|
+
declare function branch<T>(graph: Graph, name: string, source: StepRef, predicate: (value: T) => boolean, opts?: Omit<OrchestrationStepOptions, "deps">): Node<BranchResult<T>>;
|
|
54
|
+
/**
|
|
55
|
+
* Forwards source values only while `control` is truthy.
|
|
56
|
+
*/
|
|
57
|
+
declare function valve<T>(graph: Graph, name: string, source: StepRef, control: StepRef, opts?: Omit<OrchestrationStepOptions, "deps">): Node<T>;
|
|
58
|
+
type ApprovalOptions = Omit<OrchestrationStepOptions, "deps"> & {
|
|
59
|
+
isApproved?: (value: unknown) => boolean;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Human/LLM approval gate over a source value.
|
|
63
|
+
*/
|
|
64
|
+
declare function approval<T>(graph: Graph, name: string, source: StepRef, approver: StepRef, opts?: ApprovalOptions): Node<T>;
|
|
65
|
+
interface GateOptions {
|
|
66
|
+
/** Maximum queue size. Oldest values are FIFO-dropped when exceeded. Default: Infinity. */
|
|
67
|
+
maxPending?: number;
|
|
68
|
+
/** Start in open mode (auto-approve). Default: false. */
|
|
69
|
+
startOpen?: boolean;
|
|
70
|
+
meta?: Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
/** Control surface returned by {@link gate}. */
|
|
73
|
+
interface GateController<T> {
|
|
74
|
+
/** The output node registered in the graph (subscribe to receive approved values). */
|
|
75
|
+
node: Node<T>;
|
|
76
|
+
/** Reactive queue of values waiting for approval. */
|
|
77
|
+
pending: Node<T[]>;
|
|
78
|
+
/** Derived count of pending items. */
|
|
79
|
+
count: Node<number>;
|
|
80
|
+
/** Whether the gate is currently open (auto-approving). */
|
|
81
|
+
isOpen: Node<boolean>;
|
|
82
|
+
/** Approve and forward the next `count` pending values (default: 1). */
|
|
83
|
+
approve(count?: number): void;
|
|
84
|
+
/** Reject (discard) the next `count` pending values (default: 1). */
|
|
85
|
+
reject(count?: number): void;
|
|
86
|
+
/**
|
|
87
|
+
* Transform and forward `count` pending values (default: 1).
|
|
88
|
+
* `fn` receives `(value, index, pending)` — Array.map-style.
|
|
89
|
+
*/
|
|
90
|
+
modify(fn: (value: T, index: number, pending: readonly T[]) => T, count?: number): void;
|
|
91
|
+
/** Flush all pending values and auto-approve future values. */
|
|
92
|
+
open(): void;
|
|
93
|
+
/** Re-enable manual gating (stop auto-approving). */
|
|
94
|
+
close(): void;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Human-in-the-loop gate: queues incoming values from `source` and lets an external
|
|
98
|
+
* controller {@link GateController.approve approve}, {@link GateController.reject reject},
|
|
99
|
+
* or {@link GateController.modify modify} them before forwarding downstream.
|
|
100
|
+
*
|
|
101
|
+
* Observable surfaces (`pending`, `count`, `isOpen`) are reactive nodes registered in
|
|
102
|
+
* the graph. The gate output node is also registered.
|
|
103
|
+
*/
|
|
104
|
+
declare function gate<T>(graph: Graph, name: string, source: StepRef, opts?: GateOptions): GateController<T>;
|
|
105
|
+
/**
|
|
106
|
+
* Registers a workflow side-effect step that runs `run` for each upstream
|
|
107
|
+
* DATA value.
|
|
108
|
+
*
|
|
109
|
+
* `run` receives the full `NodeActions` and is the **sole emission point** —
|
|
110
|
+
* call `actions.emit(v)` or `actions.down(msgs)` inside `run` to produce
|
|
111
|
+
* downstream output. If `run` does not emit, this step acts as a pure
|
|
112
|
+
* side-effect sink (graph-observable but no output). Throwing inside `run`
|
|
113
|
+
* terminates the step with ERROR.
|
|
114
|
+
*/
|
|
115
|
+
declare function forEach<T>(graph: Graph, name: string, source: StepRef, run: (value: T, actions: NodeActions) => void, opts?: Omit<OrchestrationStepOptions, "deps">): Node<T>;
|
|
116
|
+
/**
|
|
117
|
+
* Registers a join step that emits a tuple of latest dependency values.
|
|
118
|
+
*/
|
|
119
|
+
declare function join<T extends readonly unknown[]>(graph: Graph, name: string, deps: {
|
|
120
|
+
[K in keyof T]: StepRef;
|
|
121
|
+
}, opts?: Omit<OrchestrationStepOptions, "deps">): Node<T>;
|
|
122
|
+
/**
|
|
123
|
+
* Registers a loop step that applies `iterate` to each source value N times.
|
|
124
|
+
*/
|
|
125
|
+
declare function loop<T>(graph: Graph, name: string, source: StepRef, iterate: (value: T, iteration: number, actions: NodeActions) => T, opts?: LoopOptions): Node<T>;
|
|
126
|
+
/**
|
|
127
|
+
* Mounts and returns a child workflow graph.
|
|
128
|
+
*/
|
|
129
|
+
declare function subPipeline(graph: Graph, name: string, childOrBuild?: Graph | SubPipelineBuilder, opts?: GraphOptions): Graph;
|
|
130
|
+
/**
|
|
131
|
+
* Registers a producer-style sensor source and returns imperative controls.
|
|
132
|
+
*/
|
|
133
|
+
declare function sensor<T>(graph: Graph, name: string, initial?: T, opts?: Omit<NodeOptions<unknown>, "name" | "describeKind" | "meta"> & {
|
|
134
|
+
meta?: Record<string, unknown>;
|
|
135
|
+
}): SensorControls<T>;
|
|
136
|
+
/**
|
|
137
|
+
* Registers a delayed-forwarding step (value-level wait).
|
|
138
|
+
*/
|
|
139
|
+
declare function wait<T>(graph: Graph, name: string, source: StepRef, ms: number, opts?: WaitOptions): Node<T>;
|
|
140
|
+
/**
|
|
141
|
+
* Registers an error-recovery step for a source.
|
|
142
|
+
*/
|
|
143
|
+
declare function onFailure<T>(graph: Graph, name: string, source: StepRef, recover: (err: unknown, actions: NodeActions) => T, opts?: Omit<OrchestrationStepOptions, "deps">): Node<T>;
|
|
144
|
+
|
|
145
|
+
type orchestration_ApprovalOptions = ApprovalOptions;
|
|
146
|
+
type orchestration_BranchResult<T> = BranchResult<T>;
|
|
147
|
+
type orchestration_GateController<T> = GateController<T>;
|
|
148
|
+
type orchestration_GateOptions = GateOptions;
|
|
149
|
+
type orchestration_LoopOptions = LoopOptions;
|
|
150
|
+
type orchestration_OrchestrationStepOptions = OrchestrationStepOptions;
|
|
151
|
+
type orchestration_SensorControls<T> = SensorControls<T>;
|
|
152
|
+
type orchestration_StepRef = StepRef;
|
|
153
|
+
type orchestration_SubPipelineBuilder = SubPipelineBuilder;
|
|
154
|
+
type orchestration_WaitOptions = WaitOptions;
|
|
155
|
+
declare const orchestration_approval: typeof approval;
|
|
156
|
+
declare const orchestration_branch: typeof branch;
|
|
157
|
+
declare const orchestration_forEach: typeof forEach;
|
|
158
|
+
declare const orchestration_gate: typeof gate;
|
|
159
|
+
declare const orchestration_join: typeof join;
|
|
160
|
+
declare const orchestration_loop: typeof loop;
|
|
161
|
+
declare const orchestration_onFailure: typeof onFailure;
|
|
162
|
+
declare const orchestration_pipeline: typeof pipeline;
|
|
163
|
+
declare const orchestration_sensor: typeof sensor;
|
|
164
|
+
declare const orchestration_subPipeline: typeof subPipeline;
|
|
165
|
+
declare const orchestration_task: typeof task;
|
|
166
|
+
declare const orchestration_valve: typeof valve;
|
|
167
|
+
declare const orchestration_wait: typeof wait;
|
|
168
|
+
declare namespace orchestration {
|
|
169
|
+
export { type orchestration_ApprovalOptions as ApprovalOptions, type orchestration_BranchResult as BranchResult, type orchestration_GateController as GateController, type orchestration_GateOptions as GateOptions, type orchestration_LoopOptions as LoopOptions, type orchestration_OrchestrationStepOptions as OrchestrationStepOptions, type orchestration_SensorControls as SensorControls, type orchestration_StepRef as StepRef, type orchestration_SubPipelineBuilder as SubPipelineBuilder, type orchestration_WaitOptions as WaitOptions, orchestration_approval as approval, orchestration_branch as branch, orchestration_forEach as forEach, orchestration_gate as gate, orchestration_join as join, orchestration_loop as loop, orchestration_onFailure as onFailure, orchestration_pipeline as pipeline, orchestration_sensor as sensor, orchestration_subPipeline as subPipeline, orchestration_task as task, orchestration_valve as valve, orchestration_wait as wait };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* AI surface patterns (roadmap §4.4).
|
|
174
|
+
*
|
|
175
|
+
* Domain-layer factories for LLM-backed agents, chat, tool registries, and
|
|
176
|
+
* agentic memory. Composed from core + extra + Phase 3–4.3 primitives.
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
/** A single chat message in a conversation. */
|
|
180
|
+
type ChatMessage = {
|
|
181
|
+
readonly role: "system" | "user" | "assistant" | "tool";
|
|
182
|
+
readonly content: string;
|
|
183
|
+
readonly name?: string;
|
|
184
|
+
readonly toolCallId?: string;
|
|
185
|
+
readonly toolCalls?: readonly ToolCall[];
|
|
186
|
+
readonly metadata?: Record<string, unknown>;
|
|
187
|
+
};
|
|
188
|
+
/** A tool invocation request from an LLM. */
|
|
189
|
+
type ToolCall = {
|
|
190
|
+
readonly id: string;
|
|
191
|
+
readonly name: string;
|
|
192
|
+
readonly arguments: Record<string, unknown>;
|
|
193
|
+
};
|
|
194
|
+
/** The response from an LLM invocation. */
|
|
195
|
+
type LLMResponse = {
|
|
196
|
+
readonly content: string;
|
|
197
|
+
readonly toolCalls?: readonly ToolCall[];
|
|
198
|
+
readonly usage?: {
|
|
199
|
+
readonly inputTokens: number;
|
|
200
|
+
readonly outputTokens: number;
|
|
201
|
+
};
|
|
202
|
+
readonly finishReason?: string;
|
|
203
|
+
readonly metadata?: Record<string, unknown>;
|
|
204
|
+
};
|
|
205
|
+
/** Provider-agnostic LLM client adapter protocol. */
|
|
206
|
+
type LLMAdapter = {
|
|
207
|
+
invoke(messages: readonly ChatMessage[], opts?: LLMInvokeOptions): NodeInput<LLMResponse>;
|
|
208
|
+
stream(messages: readonly ChatMessage[], opts?: LLMInvokeOptions): AsyncIterable<string>;
|
|
209
|
+
};
|
|
210
|
+
type LLMInvokeOptions = {
|
|
211
|
+
model?: string;
|
|
212
|
+
temperature?: number;
|
|
213
|
+
maxTokens?: number;
|
|
214
|
+
tools?: readonly ToolDefinition[];
|
|
215
|
+
systemPrompt?: string;
|
|
216
|
+
signal?: AbortSignal;
|
|
217
|
+
};
|
|
218
|
+
/** A tool definition for LLM consumption. */
|
|
219
|
+
type ToolDefinition = {
|
|
220
|
+
readonly name: string;
|
|
221
|
+
readonly description: string;
|
|
222
|
+
readonly parameters: Record<string, unknown>;
|
|
223
|
+
readonly handler: (args: Record<string, unknown>) => NodeInput<unknown>;
|
|
224
|
+
/**
|
|
225
|
+
* V0 version of the backing node at `knobsAsTools()` call time (§6.0b).
|
|
226
|
+
* Snapshot — re-call `knobsAsTools()` to refresh.
|
|
227
|
+
*/
|
|
228
|
+
readonly version?: {
|
|
229
|
+
id: string;
|
|
230
|
+
version: number;
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
type AgentLoopStatus = "idle" | "thinking" | "acting" | "done" | "error";
|
|
234
|
+
/**
|
|
235
|
+
* A single chunk from any streaming source (LLM tokens, WebSocket, SSE, file tail).
|
|
236
|
+
* Generic enough for any streaming source, not just LLM.
|
|
237
|
+
*/
|
|
238
|
+
type StreamChunk = {
|
|
239
|
+
/** Identifier for the stream source (adapter name, URL, etc.). */
|
|
240
|
+
readonly source: string;
|
|
241
|
+
/** This chunk's content. */
|
|
242
|
+
readonly token: string;
|
|
243
|
+
/** Full accumulated text so far. */
|
|
244
|
+
readonly accumulated: string;
|
|
245
|
+
/** 0-based chunk counter. */
|
|
246
|
+
readonly index: number;
|
|
247
|
+
};
|
|
248
|
+
type FromLLMOptions = {
|
|
249
|
+
name?: string;
|
|
250
|
+
model?: string;
|
|
251
|
+
temperature?: number;
|
|
252
|
+
maxTokens?: number;
|
|
253
|
+
tools?: readonly ToolDefinition[];
|
|
254
|
+
systemPrompt?: string;
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Reactive LLM invocation adapter. Returns a derived node that re-invokes
|
|
258
|
+
* the LLM whenever the messages dep changes.
|
|
259
|
+
*
|
|
260
|
+
* Uses `switchMap` internally — new invocations cancel stale in-flight ones.
|
|
261
|
+
*/
|
|
262
|
+
declare function fromLLM(adapter: LLMAdapter, messages: NodeInput<readonly ChatMessage[]>, opts?: FromLLMOptions): Node<LLMResponse | null>;
|
|
263
|
+
type StreamingPromptNodeOptions = {
|
|
264
|
+
name?: string;
|
|
265
|
+
model?: string;
|
|
266
|
+
temperature?: number;
|
|
267
|
+
maxTokens?: number;
|
|
268
|
+
/** Output format — `"json"` attempts JSON.parse on the final accumulated text. Default: `"text"`. */
|
|
269
|
+
format?: "text" | "json";
|
|
270
|
+
systemPrompt?: string;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Bundle returned by {@link streamingPromptNode}.
|
|
274
|
+
*/
|
|
275
|
+
type StreamingPromptNodeHandle<T> = {
|
|
276
|
+
/** Final parsed result (emits once per invocation, after stream completes). */
|
|
277
|
+
output: Node<T | null>;
|
|
278
|
+
/** Live stream topic — subscribe to `stream.latest` or `stream.events` for chunks. */
|
|
279
|
+
stream: TopicGraph<StreamChunk>;
|
|
280
|
+
/** Tear down the keepalive subscription and release resources. */
|
|
281
|
+
dispose: () => void;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Streaming LLM transform: wraps a prompt template + adapter into a reactive
|
|
285
|
+
* streaming pipeline. Re-invokes the LLM whenever any dep changes; the
|
|
286
|
+
* previous in-flight stream is canceled automatically via `switchMap`.
|
|
287
|
+
*
|
|
288
|
+
* Each token chunk is published to a {@link TopicGraph} as a {@link StreamChunk}.
|
|
289
|
+
* Extractors can mount on the topic independently (see {@link streamExtractor}).
|
|
290
|
+
* Zero overhead if nobody subscribes to the stream topic.
|
|
291
|
+
*
|
|
292
|
+
* The `output` node emits the final parsed result (like {@link promptNode}).
|
|
293
|
+
* The async boundary is handled by `fromAny` (spec §5.10 compliant).
|
|
294
|
+
*/
|
|
295
|
+
declare function streamingPromptNode<T = string>(adapter: LLMAdapter, deps: readonly Node<unknown>[], prompt: string | ((...depValues: unknown[]) => string), opts?: StreamingPromptNodeOptions): StreamingPromptNodeHandle<T>;
|
|
296
|
+
/**
|
|
297
|
+
* Mounts an extractor function on a streaming topic. Returns a derived node
|
|
298
|
+
* that emits extracted values as chunks arrive.
|
|
299
|
+
*
|
|
300
|
+
* `extractFn` receives the accumulated text from the latest chunk and returns
|
|
301
|
+
* the extracted value, or `null` if nothing detected yet. This is the building
|
|
302
|
+
* block for keyword flags, tool call detection, cost metering, etc.
|
|
303
|
+
*
|
|
304
|
+
* @param streamTopic - The stream topic to extract from.
|
|
305
|
+
* @param extractFn - `(accumulated: string) => T | null`.
|
|
306
|
+
* @param opts - Optional name.
|
|
307
|
+
* @returns Derived node emitting extracted values.
|
|
308
|
+
*/
|
|
309
|
+
declare function streamExtractor<T>(streamTopic: TopicGraph<StreamChunk>, extractFn: (accumulated: string) => T | null, opts?: {
|
|
310
|
+
name?: string;
|
|
311
|
+
/**
|
|
312
|
+
* Optional structural equals for the extractor output. When two
|
|
313
|
+
* consecutive chunks produce structurally-equal outputs, the framework
|
|
314
|
+
* emits `RESOLVED` instead of `DATA`, saving downstream work. Default:
|
|
315
|
+
* reference equality (`Object.is`). The library cannot know your
|
|
316
|
+
* output shape — supply this when your `extractFn` returns structured
|
|
317
|
+
* objects or arrays.
|
|
318
|
+
*/
|
|
319
|
+
equals?: (a: T | null, b: T | null) => boolean;
|
|
320
|
+
}): Node<T | null>;
|
|
321
|
+
/** A keyword match detected in the stream. */
|
|
322
|
+
type KeywordFlag = {
|
|
323
|
+
readonly label: string;
|
|
324
|
+
readonly pattern: RegExp;
|
|
325
|
+
readonly match: string;
|
|
326
|
+
readonly position: number;
|
|
327
|
+
};
|
|
328
|
+
type KeywordFlagExtractorOptions = {
|
|
329
|
+
patterns: readonly {
|
|
330
|
+
pattern: RegExp;
|
|
331
|
+
label: string;
|
|
332
|
+
}[];
|
|
333
|
+
name?: string;
|
|
334
|
+
/**
|
|
335
|
+
* Maximum length of any pattern's literal text. Used as an overlap window
|
|
336
|
+
* when cursoring through the accumulated stream so matches that span
|
|
337
|
+
* chunk boundaries aren't missed. Default: 128.
|
|
338
|
+
*/
|
|
339
|
+
maxPatternLength?: number;
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* Mounts a keyword-flag extractor on a streaming topic. Scans accumulated text
|
|
343
|
+
* for all configured patterns and emits an array of matches.
|
|
344
|
+
*
|
|
345
|
+
* Use cases: design invariant violations (`setTimeout`, `EventEmitter`), PII
|
|
346
|
+
* detection (SSN, email, phone), toxicity keywords, off-track reasoning.
|
|
347
|
+
*
|
|
348
|
+
* **Streaming optimization.** Maintains a cursor across chunks in `ctx.store`
|
|
349
|
+
* so each chunk scans only the delta region `accumulated.slice(scannedTo -
|
|
350
|
+
* maxPatternLength)` — not the full string. Default structural equals
|
|
351
|
+
* suppresses DATA emission when no new flags were found this chunk.
|
|
352
|
+
*/
|
|
353
|
+
declare function keywordFlagExtractor(streamTopic: TopicGraph<StreamChunk>, opts: KeywordFlagExtractorOptions): Node<readonly KeywordFlag[]>;
|
|
354
|
+
/** A tool call detected in the stream. */
|
|
355
|
+
type ExtractedToolCall = {
|
|
356
|
+
readonly name: string;
|
|
357
|
+
readonly arguments: Record<string, unknown>;
|
|
358
|
+
readonly raw: string;
|
|
359
|
+
readonly startIndex: number;
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Mounts a tool-call extractor on a streaming topic. Scans accumulated text
|
|
363
|
+
* for complete JSON objects containing `"name"` and `"arguments"` keys (the
|
|
364
|
+
* standard tool_call shape). Partial JSON is ignored until the closing brace.
|
|
365
|
+
*
|
|
366
|
+
* Feeds into the tool interception chain for reactive tool gating mid-stream.
|
|
367
|
+
*
|
|
368
|
+
* **Streaming optimization.** Maintains a cursor (`scanFrom`) in `ctx.store`
|
|
369
|
+
* so each chunk resumes brace-scanning from the position after the last
|
|
370
|
+
* complete parse (or the last incomplete open brace). Already-parsed objects
|
|
371
|
+
* are not re-parsed. Default structural equals suppresses DATA emission when
|
|
372
|
+
* no new tool call completed this chunk.
|
|
373
|
+
*/
|
|
374
|
+
declare function toolCallExtractor(streamTopic: TopicGraph<StreamChunk>, opts?: {
|
|
375
|
+
name?: string;
|
|
376
|
+
}): Node<readonly ExtractedToolCall[]>;
|
|
377
|
+
/** A cost meter reading from the stream. */
|
|
378
|
+
type CostMeterReading = {
|
|
379
|
+
readonly chunkCount: number;
|
|
380
|
+
readonly charCount: number;
|
|
381
|
+
readonly estimatedTokens: number;
|
|
382
|
+
};
|
|
383
|
+
type CostMeterOptions = {
|
|
384
|
+
/** Characters per token approximation. Default: 4 (GPT-family). */
|
|
385
|
+
charsPerToken?: number;
|
|
386
|
+
name?: string;
|
|
387
|
+
};
|
|
388
|
+
/**
|
|
389
|
+
* Mounts a cost meter on a streaming topic. Counts chunks, characters, and
|
|
390
|
+
* estimates token count. Compose with `budgetGate` for hard-stop when LLM
|
|
391
|
+
* output exceeds budget mid-generation.
|
|
392
|
+
*
|
|
393
|
+
* Default structural equals suppresses DATA emission when two consecutive
|
|
394
|
+
* readings are identical (same chunk count + char count + token estimate).
|
|
395
|
+
*/
|
|
396
|
+
declare function costMeterExtractor(streamTopic: TopicGraph<StreamChunk>, opts?: CostMeterOptions): Node<CostMeterReading>;
|
|
397
|
+
/** Options for {@link redactor}. */
|
|
398
|
+
type RedactorOptions = {
|
|
399
|
+
name?: string;
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* Stream extractor that replaces matched patterns in the accumulated text.
|
|
403
|
+
*
|
|
404
|
+
* Returns a derived node emitting a sanitized `StreamChunk` on every chunk:
|
|
405
|
+
* `accumulated` and `token` have matched substrings replaced by `replaceFn`.
|
|
406
|
+
* The default `replaceFn` replaces with `"[REDACTED]"`.
|
|
407
|
+
*
|
|
408
|
+
* Compose with `contentGate` for in-flight safety pipelines.
|
|
409
|
+
*
|
|
410
|
+
* @param streamTopic - Streaming topic to monitor.
|
|
411
|
+
* @param patterns - Array of RegExps to match against accumulated text.
|
|
412
|
+
* @param replaceFn - Replacement producer (default: always `"[REDACTED]"`).
|
|
413
|
+
*/
|
|
414
|
+
declare function redactor(streamTopic: TopicGraph<StreamChunk>, patterns: RegExp[], replaceFn?: (match: string, pattern: RegExp) => string, opts?: RedactorOptions): Node<StreamChunk>;
|
|
415
|
+
/** Content safety decision. */
|
|
416
|
+
type ContentDecision = "allow" | "block" | "review";
|
|
417
|
+
/** Options for {@link contentGate}. */
|
|
418
|
+
type ContentGateOptions = {
|
|
419
|
+
/**
|
|
420
|
+
* Hard-block threshold multiplier (default 1.5).
|
|
421
|
+
* Scores above `threshold * hardMultiplier` emit `"block"`.
|
|
422
|
+
* Scores between `threshold` and that emit `"review"`.
|
|
423
|
+
*/
|
|
424
|
+
hardMultiplier?: number;
|
|
425
|
+
name?: string;
|
|
426
|
+
};
|
|
427
|
+
/**
|
|
428
|
+
* Derived node that classifies accumulated stream text as `"allow"`,
|
|
429
|
+
* `"review"`, or `"block"` based on a classifier score.
|
|
430
|
+
*
|
|
431
|
+
* Emits a three-way decision on every new chunk:
|
|
432
|
+
* - `"allow"` — score below `threshold`
|
|
433
|
+
* - `"review"` — score in `[threshold, threshold × hardMultiplier)`
|
|
434
|
+
* - `"block"` — score at or above `threshold × hardMultiplier`
|
|
435
|
+
*
|
|
436
|
+
* Wire the output into a `valve` (automatic) or `gate` (human approval).
|
|
437
|
+
* This node does not itself control flow — it just classifies.
|
|
438
|
+
*
|
|
439
|
+
* @param streamTopic - Streaming topic to classify.
|
|
440
|
+
* @param classifier - `(accumulated: string) => number` scoring function, or
|
|
441
|
+
* a `Node<number>` for live scores.
|
|
442
|
+
* @param threshold - Score at which output becomes "review" or "block".
|
|
443
|
+
*/
|
|
444
|
+
declare function contentGate(streamTopic: TopicGraph<StreamChunk>, classifier: ((accumulated: string) => number) | Node<number>, threshold: number, opts?: ContentGateOptions): Node<ContentDecision>;
|
|
445
|
+
type GatedStreamOptions = StreamingPromptNodeOptions & {
|
|
446
|
+
/** Gate options (maxPending, startOpen). */
|
|
447
|
+
gate?: Omit<GateOptions, "meta">;
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* Bundle returned by {@link gatedStream}.
|
|
451
|
+
*/
|
|
452
|
+
type GatedStreamHandle<T> = {
|
|
453
|
+
/** Final parsed result (after gate approval). */
|
|
454
|
+
output: Node<T | null>;
|
|
455
|
+
/** Live stream topic — subscribe to `stream.latest` for chunks. */
|
|
456
|
+
stream: TopicGraph<StreamChunk>;
|
|
457
|
+
/** Gate controller — approve, reject (aborts in-flight stream), modify. */
|
|
458
|
+
gate: GateController<T | null>;
|
|
459
|
+
/** Tear down everything. */
|
|
460
|
+
dispose: () => void;
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* Streaming LLM transform with human-in-the-loop gate integration.
|
|
464
|
+
*
|
|
465
|
+
* Composes {@link streamingPromptNode} with {@link gate} so that:
|
|
466
|
+
* - `gate.reject()` discards the pending value **and** aborts the in-flight
|
|
467
|
+
* stream (cancels the `AbortController`).
|
|
468
|
+
* - `gate.modify()` transforms the pending value before forwarding downstream.
|
|
469
|
+
* - `gate.approve()` forwards the final result as normal.
|
|
470
|
+
*
|
|
471
|
+
* The abort-on-reject works by toggling an internal cancel signal that causes
|
|
472
|
+
* the `switchMap` inside `streamingPromptNode` to restart with an empty message
|
|
473
|
+
* list, which triggers the `AbortController.abort()` in the async generator's
|
|
474
|
+
* `finally` block.
|
|
475
|
+
*/
|
|
476
|
+
declare function gatedStream<T = string>(graph: Graph, name: string, adapter: LLMAdapter, deps: readonly Node<unknown>[], prompt: string | ((...depValues: unknown[]) => string), opts?: GatedStreamOptions): GatedStreamHandle<T>;
|
|
477
|
+
type PromptNodeOptions = {
|
|
478
|
+
name?: string;
|
|
479
|
+
model?: string;
|
|
480
|
+
temperature?: number;
|
|
481
|
+
maxTokens?: number;
|
|
482
|
+
/** Output format — `"json"` attempts JSON.parse on the response. Default: `"text"`. */
|
|
483
|
+
format?: "text" | "json";
|
|
484
|
+
/** Number of retries on transient errors. Default: 0. */
|
|
485
|
+
retries?: number;
|
|
486
|
+
/** Cache LLM responses for identical inputs. Default: false. */
|
|
487
|
+
cache?: boolean;
|
|
488
|
+
systemPrompt?: string;
|
|
489
|
+
meta?: Record<string, unknown>;
|
|
490
|
+
};
|
|
491
|
+
/**
|
|
492
|
+
* Universal LLM transform: wraps a prompt template + model adapter into a reactive derived node.
|
|
493
|
+
* Re-invokes the LLM whenever any dep changes. Suitable for triage, QA, hypothesis, parity, etc.
|
|
494
|
+
*
|
|
495
|
+
* @param adapter - LLM adapter (provider-agnostic).
|
|
496
|
+
* @param deps - Input nodes whose values feed the prompt.
|
|
497
|
+
* @param prompt - Static string or template function receiving dep values.
|
|
498
|
+
* @param opts - Optional configuration.
|
|
499
|
+
* @returns `Node` emitting LLM responses (string or parsed JSON).
|
|
500
|
+
*/
|
|
501
|
+
declare function promptNode<T = string>(adapter: LLMAdapter, deps: readonly Node<unknown>[], prompt: string | ((...depValues: unknown[]) => string), opts?: PromptNodeOptions): Node<T | null>;
|
|
502
|
+
type ChatStreamOptions = {
|
|
503
|
+
graph?: GraphOptions;
|
|
504
|
+
maxMessages?: number;
|
|
505
|
+
};
|
|
506
|
+
declare class ChatStreamGraph extends Graph {
|
|
507
|
+
private readonly _log;
|
|
508
|
+
readonly messages: Node<readonly ChatMessage[]>;
|
|
509
|
+
readonly latest: Node<ChatMessage | null>;
|
|
510
|
+
readonly messageCount: Node<number>;
|
|
511
|
+
constructor(name: string, opts?: ChatStreamOptions);
|
|
512
|
+
append(role: ChatMessage["role"], content: string, extra?: Partial<ChatMessage>): void;
|
|
513
|
+
appendToolResult(callId: string, content: string): void;
|
|
514
|
+
clear(): void;
|
|
515
|
+
allMessages(): readonly ChatMessage[];
|
|
516
|
+
}
|
|
517
|
+
declare function chatStream(name: string, opts?: ChatStreamOptions): ChatStreamGraph;
|
|
518
|
+
type ToolRegistryOptions = {
|
|
519
|
+
graph?: GraphOptions;
|
|
520
|
+
};
|
|
521
|
+
declare class ToolRegistryGraph extends Graph {
|
|
522
|
+
readonly definitions: Node<ReadonlyMap<string, ToolDefinition>>;
|
|
523
|
+
readonly schemas: Node<readonly ToolDefinition[]>;
|
|
524
|
+
constructor(name: string, opts?: ToolRegistryOptions);
|
|
525
|
+
register(tool: ToolDefinition): void;
|
|
526
|
+
unregister(name: string): void;
|
|
527
|
+
execute(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
528
|
+
getDefinition(name: string): ToolDefinition | undefined;
|
|
529
|
+
}
|
|
530
|
+
declare function toolRegistry(name: string, opts?: ToolRegistryOptions): ToolRegistryGraph;
|
|
531
|
+
/**
|
|
532
|
+
* Assembles a system prompt from reactive sections. Each section is a
|
|
533
|
+
* `NodeInput<string>` — the prompt updates when any section changes.
|
|
534
|
+
*/
|
|
535
|
+
type SystemPromptHandle = Node<string> & {
|
|
536
|
+
dispose: () => void;
|
|
537
|
+
};
|
|
538
|
+
declare function systemPromptBuilder(sections: readonly NodeInput<string>[], opts?: {
|
|
539
|
+
separator?: string;
|
|
540
|
+
name?: string;
|
|
541
|
+
}): SystemPromptHandle;
|
|
542
|
+
type LLMExtractorOptions = {
|
|
543
|
+
adapter: LLMAdapter;
|
|
544
|
+
model?: string;
|
|
545
|
+
temperature?: number;
|
|
546
|
+
maxTokens?: number;
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* Returns an `extractFn` callback for `distill()` that invokes an LLM to
|
|
550
|
+
* extract structured memories from raw input.
|
|
551
|
+
*
|
|
552
|
+
* The system prompt should instruct the LLM to return JSON matching
|
|
553
|
+
* `Extraction<TMem>` shape: `{ upsert: [{ key, value }], remove?: [key] }`.
|
|
554
|
+
*/
|
|
555
|
+
declare function llmExtractor<TRaw, TMem>(systemPrompt: string, opts: LLMExtractorOptions): (raw: TRaw, existing: ReadonlyMap<string, TMem>) => NodeInput<Extraction<TMem>>;
|
|
556
|
+
type LLMConsolidatorOptions = LLMExtractorOptions;
|
|
557
|
+
/**
|
|
558
|
+
* Returns a `consolidateFn` callback for `distill()` that invokes an LLM to
|
|
559
|
+
* cluster and merge related memories.
|
|
560
|
+
*/
|
|
561
|
+
declare function llmConsolidator<TMem>(systemPrompt: string, opts: LLMConsolidatorOptions): (entries: ReadonlyMap<string, TMem>) => NodeInput<Extraction<TMem>>;
|
|
562
|
+
/** Scores for the three admission dimensions. Each 0–1. */
|
|
563
|
+
type AdmissionScores = {
|
|
564
|
+
readonly persistence: number;
|
|
565
|
+
readonly structure: number;
|
|
566
|
+
readonly personalValue: number;
|
|
567
|
+
};
|
|
568
|
+
type AdmissionScore3DOptions = {
|
|
569
|
+
/** Custom scoring function. Default: rule-based (all dimensions 0.5). */
|
|
570
|
+
scoreFn?: (raw: unknown) => AdmissionScores;
|
|
571
|
+
/** Minimum persistence score to admit (default 0.3). */
|
|
572
|
+
persistenceThreshold?: number;
|
|
573
|
+
/** Minimum personalValue score to admit (default 0.3). */
|
|
574
|
+
personalValueThreshold?: number;
|
|
575
|
+
/** Require structure score > 0 to admit (default false). */
|
|
576
|
+
requireStructured?: boolean;
|
|
577
|
+
};
|
|
578
|
+
/**
|
|
579
|
+
* Creates a 3D admission filter function compatible with `agentMemory`'s
|
|
580
|
+
* `admissionFilter` option. Scores each candidate on persistence, structure,
|
|
581
|
+
* and personalValue, then applies thresholds.
|
|
582
|
+
*/
|
|
583
|
+
declare function admissionFilter3D(opts?: AdmissionScore3DOptions): (raw: unknown) => boolean;
|
|
584
|
+
type MemoryTier = "permanent" | "active" | "archived";
|
|
585
|
+
type MemoryTiersOptions<TMem> = {
|
|
586
|
+
/** Exponential decay rate per second for active tier.
|
|
587
|
+
* Default: 7-day half-life ≈ ln(2)/(7×86400) ≈ 0.00000114. */
|
|
588
|
+
decayRate?: number;
|
|
589
|
+
/** Max entries in the active tier before archiving lowest-scored (default 1000). */
|
|
590
|
+
maxActive?: number;
|
|
591
|
+
/** Score threshold below which active entries get archived (default 0.1). */
|
|
592
|
+
archiveThreshold?: number;
|
|
593
|
+
/** Predicate: true → entry belongs in permanent tier (default: never). */
|
|
594
|
+
permanentFilter?: (key: string, mem: TMem) => boolean;
|
|
595
|
+
/** Storage tier for the archive. Omit to disable archiving. */
|
|
596
|
+
archiveTier?: StorageTier;
|
|
597
|
+
/** Options forwarded to `graph.attachStorage` for the archive tier. */
|
|
598
|
+
archiveStorageOptions?: GraphAttachStorageOptions;
|
|
599
|
+
};
|
|
600
|
+
type MemoryTiersBundle<TMem> = {
|
|
601
|
+
/** Permanent tier: never evicted. */
|
|
602
|
+
readonly permanent: LightCollectionBundle<TMem>;
|
|
603
|
+
/** Active entries node (reactive, holds ReadonlyMap). */
|
|
604
|
+
readonly activeEntries: Node<unknown>;
|
|
605
|
+
/** Archive storage handle (null if no tier configured). */
|
|
606
|
+
readonly archiveHandle: StorageHandle | null;
|
|
607
|
+
/** Classify a key into its current tier. */
|
|
608
|
+
tierOf: (key: string) => MemoryTier;
|
|
609
|
+
/** Move a key to the permanent tier. */
|
|
610
|
+
markPermanent: (key: string, value: TMem) => void;
|
|
611
|
+
};
|
|
612
|
+
type RetrievalQuery = {
|
|
613
|
+
readonly text?: string;
|
|
614
|
+
readonly vector?: readonly number[];
|
|
615
|
+
readonly entityIds?: readonly string[];
|
|
616
|
+
};
|
|
617
|
+
type RetrievalPipelineOptions<TMem> = {
|
|
618
|
+
/** Max candidates from vector search (default 20). */
|
|
619
|
+
topK?: number;
|
|
620
|
+
/** KG expansion depth in hops (default 1). */
|
|
621
|
+
graphDepth?: number;
|
|
622
|
+
/** Token budget for final packing (default 2000). */
|
|
623
|
+
budget?: number;
|
|
624
|
+
/** Cost function for budget packing. */
|
|
625
|
+
cost: (mem: TMem) => number;
|
|
626
|
+
/** Score function for ranking. */
|
|
627
|
+
score: (mem: TMem, context: unknown) => number;
|
|
628
|
+
};
|
|
629
|
+
/** A single entry in the retrieval result, with causal trace metadata. */
|
|
630
|
+
type RetrievalEntry<TMem> = {
|
|
631
|
+
readonly key: string;
|
|
632
|
+
readonly value: TMem;
|
|
633
|
+
readonly score: number;
|
|
634
|
+
readonly sources: ReadonlyArray<"vector" | "graph" | "store">;
|
|
635
|
+
};
|
|
636
|
+
/** Causal trace for a retrieval run. */
|
|
637
|
+
type RetrievalTrace<TMem> = {
|
|
638
|
+
readonly vectorCandidates: ReadonlyArray<VectorSearchResult<TMem>>;
|
|
639
|
+
readonly graphExpanded: ReadonlyArray<string>;
|
|
640
|
+
readonly ranked: ReadonlyArray<RetrievalEntry<TMem>>;
|
|
641
|
+
readonly packed: ReadonlyArray<RetrievalEntry<TMem>>;
|
|
642
|
+
};
|
|
643
|
+
type AgentMemoryOptions<TMem = unknown> = {
|
|
644
|
+
graph?: GraphOptions;
|
|
645
|
+
/** LLM adapter for extraction and consolidation. */
|
|
646
|
+
adapter?: LLMAdapter;
|
|
647
|
+
/** System prompt for the extractor LLM. */
|
|
648
|
+
extractPrompt?: string;
|
|
649
|
+
/** Custom extractFn (overrides adapter + extractPrompt). */
|
|
650
|
+
extractFn?: (raw: unknown, existing: ReadonlyMap<string, TMem>) => NodeInput<Extraction<TMem>>;
|
|
651
|
+
/** System prompt for the consolidation LLM. */
|
|
652
|
+
consolidatePrompt?: string;
|
|
653
|
+
/** Custom consolidateFn (overrides adapter + consolidatePrompt). */
|
|
654
|
+
consolidateFn?: (entries: ReadonlyMap<string, TMem>) => NodeInput<Extraction<TMem>>;
|
|
655
|
+
/** Reactive trigger for consolidation (caller supplies e.g. `fromTimer`). */
|
|
656
|
+
consolidateTrigger?: NodeInput<unknown>;
|
|
657
|
+
/** Score function for budget packing (required). */
|
|
658
|
+
score: (mem: TMem, context: unknown) => number;
|
|
659
|
+
/** Cost function for budget packing (required). */
|
|
660
|
+
cost: (mem: TMem) => number;
|
|
661
|
+
/** Token budget for compact view (default 2000). */
|
|
662
|
+
budget?: number;
|
|
663
|
+
/** Context node for scoring. */
|
|
664
|
+
context?: NodeInput<unknown>;
|
|
665
|
+
/** Admission filter (default: admit all). */
|
|
666
|
+
admissionFilter?: (candidate: unknown) => boolean;
|
|
667
|
+
/** Vector index dimensions (> 0 enables vector index for retrieval). */
|
|
668
|
+
vectorDimensions?: number;
|
|
669
|
+
/** Extract embedding vector from a memory entry (enables vector index). */
|
|
670
|
+
embedFn?: (mem: TMem) => readonly number[] | undefined;
|
|
671
|
+
/** Enable knowledge graph for entity/relation tracking. */
|
|
672
|
+
enableKnowledgeGraph?: boolean;
|
|
673
|
+
/** Extract entities and relations from a memory entry. */
|
|
674
|
+
entityFn?: (key: string, mem: TMem) => {
|
|
675
|
+
entities?: Array<{
|
|
676
|
+
id: string;
|
|
677
|
+
value: unknown;
|
|
678
|
+
}>;
|
|
679
|
+
relations?: Array<{
|
|
680
|
+
from: string;
|
|
681
|
+
to: string;
|
|
682
|
+
relation: string;
|
|
683
|
+
weight?: number;
|
|
684
|
+
}>;
|
|
685
|
+
} | undefined;
|
|
686
|
+
/** 3-tier storage configuration. Omit to use single-tier (existing behavior). */
|
|
687
|
+
tiers?: MemoryTiersOptions<TMem>;
|
|
688
|
+
/** Retrieval pipeline configuration. Requires vector index or knowledge graph. */
|
|
689
|
+
retrieval?: {
|
|
690
|
+
/** Max candidates from vector search (default 20). */
|
|
691
|
+
topK?: number;
|
|
692
|
+
/** KG expansion depth in hops (default 1). */
|
|
693
|
+
graphDepth?: number;
|
|
694
|
+
};
|
|
695
|
+
/** Periodic reflection/consolidation configuration. */
|
|
696
|
+
reflection?: {
|
|
697
|
+
/** Interval in ms between consolidation runs (default 300_000 = 5 min). */
|
|
698
|
+
interval?: number;
|
|
699
|
+
/** Enable/disable periodic reflection (default true when consolidateFn is available). */
|
|
700
|
+
enabled?: boolean;
|
|
701
|
+
};
|
|
702
|
+
};
|
|
703
|
+
type AgentMemoryGraph<TMem = unknown> = Graph & {
|
|
704
|
+
readonly distillBundle: DistillBundle<TMem>;
|
|
705
|
+
readonly compact: Node<Array<{
|
|
706
|
+
key: string;
|
|
707
|
+
value: TMem;
|
|
708
|
+
score: number;
|
|
709
|
+
}>>;
|
|
710
|
+
readonly size: Node<number>;
|
|
711
|
+
/** Vector index bundle (null if not enabled). */
|
|
712
|
+
readonly vectors: VectorIndexBundle<TMem> | null;
|
|
713
|
+
/** Knowledge graph (null if not enabled). */
|
|
714
|
+
readonly kg: KnowledgeGraphGraph<unknown, string> | null;
|
|
715
|
+
/** Memory tiers bundle (null if not configured). */
|
|
716
|
+
readonly memoryTiers: MemoryTiersBundle<TMem> | null;
|
|
717
|
+
/** Retrieval result node (null if no retrieval pipeline configured). */
|
|
718
|
+
readonly retrieval: Node<ReadonlyArray<RetrievalEntry<TMem>>> | null;
|
|
719
|
+
/** Latest retrieval trace for observability (null if no retrieval pipeline). */
|
|
720
|
+
readonly retrievalTrace: Node<RetrievalTrace<TMem> | null> | null;
|
|
721
|
+
/**
|
|
722
|
+
* Execute a retrieval query (null if no retrieval pipeline).
|
|
723
|
+
*
|
|
724
|
+
* **Synchronous consumer API** — returns the result immediately and batch-writes
|
|
725
|
+
* `retrieval` and `retrievalTrace` state nodes for observers. Reads the store
|
|
726
|
+
* snapshot and context value **at call time** (external-boundary read).
|
|
727
|
+
*
|
|
728
|
+
* **Do not call from inside a reactive fn body** (derived fn, subscribe callback,
|
|
729
|
+
* effect body). The cache reads would become transitive protocol violations and
|
|
730
|
+
* may observe wave-progressive rather than wave-final state.
|
|
731
|
+
*
|
|
732
|
+
* **Caller-batch caveat:** if invoked inside a caller's `batch(() => ...)` alongside
|
|
733
|
+
* upstream store mutations, the store snapshot reflects what has been committed to
|
|
734
|
+
* `store.entries.cache` at call time. State-backed stores update cache synchronously
|
|
735
|
+
* so batched inserts are visible; derived-backed store transforms may defer. If you
|
|
736
|
+
* need fresh state after batched mutations, call `retrieve` after the batch returns.
|
|
737
|
+
*/
|
|
738
|
+
readonly retrieve: ((query: RetrievalQuery) => ReadonlyArray<RetrievalEntry<TMem>>) | null;
|
|
739
|
+
};
|
|
740
|
+
declare function agentMemory<TMem = unknown>(name: string, source: NodeInput<unknown>, opts: AgentMemoryOptions<TMem>): AgentMemoryGraph<TMem>;
|
|
741
|
+
type AgentLoopOptions = {
|
|
742
|
+
graph?: GraphOptions;
|
|
743
|
+
adapter: LLMAdapter;
|
|
744
|
+
tools?: readonly ToolDefinition[];
|
|
745
|
+
systemPrompt?: string;
|
|
746
|
+
maxTurns?: number;
|
|
747
|
+
stopWhen?: (response: LLMResponse) => boolean;
|
|
748
|
+
onToolCall?: (call: ToolCall) => void;
|
|
749
|
+
maxMessages?: number;
|
|
750
|
+
model?: string;
|
|
751
|
+
temperature?: number;
|
|
752
|
+
maxTokens?: number;
|
|
753
|
+
};
|
|
754
|
+
declare class AgentLoopGraph extends Graph {
|
|
755
|
+
readonly chat: ChatStreamGraph;
|
|
756
|
+
readonly tools: ToolRegistryGraph;
|
|
757
|
+
readonly status: Node<AgentLoopStatus>;
|
|
758
|
+
readonly turnCount: Node<number>;
|
|
759
|
+
readonly lastResponse: Node<LLMResponse | null>;
|
|
760
|
+
private readonly _statusState;
|
|
761
|
+
private readonly _turnCountState;
|
|
762
|
+
private readonly _adapter;
|
|
763
|
+
private readonly _maxTurns;
|
|
764
|
+
private readonly _stopWhen?;
|
|
765
|
+
private readonly _onToolCall?;
|
|
766
|
+
private readonly _systemPrompt?;
|
|
767
|
+
private readonly _model?;
|
|
768
|
+
private readonly _temperature?;
|
|
769
|
+
private readonly _maxTokens?;
|
|
770
|
+
private _running;
|
|
771
|
+
private _abortController;
|
|
772
|
+
constructor(name: string, opts: AgentLoopOptions);
|
|
773
|
+
/**
|
|
774
|
+
* Start the agent loop with a user message. The loop runs reactively:
|
|
775
|
+
* think (LLM call) → act (tool execution) → repeat until done.
|
|
776
|
+
*
|
|
777
|
+
* Messages accumulate across calls. Call `chat.clear()` before `run()`
|
|
778
|
+
* to reset conversation history.
|
|
779
|
+
*/
|
|
780
|
+
run(userMessage: string): Promise<LLMResponse | null>;
|
|
781
|
+
private _invokeLLM;
|
|
782
|
+
private _shouldStop;
|
|
783
|
+
destroy(): void;
|
|
784
|
+
}
|
|
785
|
+
declare function agentLoop(name: string, opts: AgentLoopOptions): AgentLoopGraph;
|
|
786
|
+
/** OpenAI function-calling tool schema. */
|
|
787
|
+
type OpenAIToolSchema = {
|
|
788
|
+
readonly type: "function";
|
|
789
|
+
readonly function: {
|
|
790
|
+
readonly name: string;
|
|
791
|
+
readonly description: string;
|
|
792
|
+
readonly parameters: Record<string, unknown>;
|
|
793
|
+
};
|
|
794
|
+
};
|
|
795
|
+
/** MCP (Model Context Protocol) tool schema. */
|
|
796
|
+
type McpToolSchema = {
|
|
797
|
+
readonly name: string;
|
|
798
|
+
readonly description: string;
|
|
799
|
+
readonly inputSchema: Record<string, unknown>;
|
|
800
|
+
};
|
|
801
|
+
/** Result of {@link knobsAsTools}. */
|
|
802
|
+
type KnobsAsToolsResult = {
|
|
803
|
+
/** OpenAI function-calling tool schemas. */
|
|
804
|
+
readonly openai: readonly OpenAIToolSchema[];
|
|
805
|
+
/** MCP tool schemas. */
|
|
806
|
+
readonly mcp: readonly McpToolSchema[];
|
|
807
|
+
/** GraphReFly ToolDefinitions with handlers that call `graph.set()`. */
|
|
808
|
+
readonly definitions: readonly ToolDefinition[];
|
|
809
|
+
};
|
|
810
|
+
/**
|
|
811
|
+
* Derive tool schemas from a graph's writable (knob) nodes.
|
|
812
|
+
*
|
|
813
|
+
* Knobs are state nodes whose `meta.access` is `"llm"`, `"both"`, or absent
|
|
814
|
+
* (default: writable). Each knob becomes a tool that calls `graph.set()`.
|
|
815
|
+
*
|
|
816
|
+
* Speaks **domain language** (spec §5.4): the returned schemas use node names
|
|
817
|
+
* and meta descriptions — no protocol internals exposed.
|
|
818
|
+
*
|
|
819
|
+
* @param graph - The graph to introspect.
|
|
820
|
+
* @param actor - Optional actor for guard-scoped describe.
|
|
821
|
+
* @returns OpenAI, MCP, and GraphReFly tool schemas.
|
|
822
|
+
*/
|
|
823
|
+
declare function knobsAsTools(graph: Graph, actor?: Actor): KnobsAsToolsResult;
|
|
824
|
+
type GaugesAsContextOptions = {
|
|
825
|
+
/** Group gauges by `meta.tags` (default true). */
|
|
826
|
+
groupByTags?: boolean;
|
|
827
|
+
/** Separator between gauge lines (default "\n"). */
|
|
828
|
+
separator?: string;
|
|
829
|
+
/**
|
|
830
|
+
* V0 delta mode (§6.0b): only include nodes whose `v.version` exceeds
|
|
831
|
+
* the corresponding entry in this map. Nodes without V0 or not in the
|
|
832
|
+
* map are always included. Callers maintain this map across calls.
|
|
833
|
+
*
|
|
834
|
+
* The `id` field guards against node replacement: if a node is removed
|
|
835
|
+
* and re-added under the same name (new id), it is always included.
|
|
836
|
+
*/
|
|
837
|
+
sinceVersion?: ReadonlyMap<string, {
|
|
838
|
+
id: string;
|
|
839
|
+
version: number;
|
|
840
|
+
}>;
|
|
841
|
+
};
|
|
842
|
+
/**
|
|
843
|
+
* Format a graph's readable (gauge) nodes as a context string for LLM
|
|
844
|
+
* system prompts.
|
|
845
|
+
*
|
|
846
|
+
* Gauges are nodes with `meta.description` or `meta.format`. Values are
|
|
847
|
+
* formatted using `meta.format` and `meta.unit` hints.
|
|
848
|
+
*
|
|
849
|
+
* @param graph - The graph to introspect.
|
|
850
|
+
* @param actor - Optional actor for guard-scoped describe.
|
|
851
|
+
* @param options - Formatting options.
|
|
852
|
+
* @returns A formatted string ready for system prompt injection.
|
|
853
|
+
*/
|
|
854
|
+
declare function gaugesAsContext(graph: Graph, actor?: Actor, options?: GaugesAsContextOptions): string;
|
|
855
|
+
/** Validation result from {@link validateGraphDef}. */
|
|
856
|
+
type GraphDefValidation = {
|
|
857
|
+
readonly valid: boolean;
|
|
858
|
+
readonly errors: readonly string[];
|
|
859
|
+
};
|
|
860
|
+
/**
|
|
861
|
+
* Validate an LLM-generated graph definition before passing to
|
|
862
|
+
* `Graph.fromSnapshot()`.
|
|
863
|
+
*
|
|
864
|
+
* Checks:
|
|
865
|
+
* - Required fields: `name`, `nodes`, `edges`
|
|
866
|
+
* - Node types are valid enum values
|
|
867
|
+
* - Edge `from`/`to` reference existing nodes
|
|
868
|
+
* - No duplicate edge entries
|
|
869
|
+
*
|
|
870
|
+
* @param def - The graph definition to validate (parsed JSON).
|
|
871
|
+
* @returns Validation result with errors array.
|
|
872
|
+
*/
|
|
873
|
+
declare function validateGraphDef(def: unknown): GraphDefValidation;
|
|
874
|
+
type GraphFromSpecOptions = {
|
|
875
|
+
model?: string;
|
|
876
|
+
temperature?: number;
|
|
877
|
+
maxTokens?: number;
|
|
878
|
+
/** Callback to construct topology before values are applied (passed to `Graph.fromSnapshot`). */
|
|
879
|
+
build?: (g: Graph) => void;
|
|
880
|
+
/** Extra instructions appended to the system prompt. */
|
|
881
|
+
systemPromptExtra?: string;
|
|
882
|
+
};
|
|
883
|
+
/**
|
|
884
|
+
* Ask an LLM to compose a Graph from a natural-language description.
|
|
885
|
+
*
|
|
886
|
+
* The LLM returns a JSON graph definition which is validated and then
|
|
887
|
+
* constructed via `Graph.fromSnapshot()`.
|
|
888
|
+
*
|
|
889
|
+
* @param naturalLanguage - The problem/use-case description.
|
|
890
|
+
* @param adapter - LLM adapter for the generation call.
|
|
891
|
+
* @param opts - Model options and optional `build` callback for node factories.
|
|
892
|
+
* @returns A constructed Graph.
|
|
893
|
+
* @throws On invalid LLM output or validation failure.
|
|
894
|
+
*/
|
|
895
|
+
declare function graphFromSpec(naturalLanguage: string, adapter: LLMAdapter, opts?: GraphFromSpecOptions): Promise<Graph>;
|
|
896
|
+
/** A single operation in a strategy plan. */
|
|
897
|
+
type StrategyOperation = {
|
|
898
|
+
readonly type: "add_node";
|
|
899
|
+
readonly name: string;
|
|
900
|
+
readonly nodeType: string;
|
|
901
|
+
readonly meta?: Record<string, unknown>;
|
|
902
|
+
readonly initial?: unknown;
|
|
903
|
+
} | {
|
|
904
|
+
readonly type: "remove_node";
|
|
905
|
+
readonly name: string;
|
|
906
|
+
} | {
|
|
907
|
+
readonly type: "connect";
|
|
908
|
+
readonly from: string;
|
|
909
|
+
readonly to: string;
|
|
910
|
+
} | {
|
|
911
|
+
readonly type: "disconnect";
|
|
912
|
+
readonly from: string;
|
|
913
|
+
readonly to: string;
|
|
914
|
+
} | {
|
|
915
|
+
readonly type: "set_value";
|
|
916
|
+
readonly name: string;
|
|
917
|
+
readonly value: unknown;
|
|
918
|
+
} | {
|
|
919
|
+
readonly type: "update_meta";
|
|
920
|
+
readonly name: string;
|
|
921
|
+
readonly key: string;
|
|
922
|
+
readonly value: unknown;
|
|
923
|
+
};
|
|
924
|
+
/** Structured strategy plan returned by {@link suggestStrategy}. */
|
|
925
|
+
type StrategyPlan = {
|
|
926
|
+
readonly summary: string;
|
|
927
|
+
readonly operations: readonly StrategyOperation[];
|
|
928
|
+
readonly reasoning: string;
|
|
929
|
+
};
|
|
930
|
+
type SuggestStrategyOptions = {
|
|
931
|
+
model?: string;
|
|
932
|
+
temperature?: number;
|
|
933
|
+
maxTokens?: number;
|
|
934
|
+
actor?: Actor;
|
|
935
|
+
};
|
|
936
|
+
/**
|
|
937
|
+
* Ask an LLM to analyze a graph and suggest topology/parameter changes
|
|
938
|
+
* to solve a stated problem.
|
|
939
|
+
*
|
|
940
|
+
* Returns a structured plan — does NOT auto-apply. The caller reviews
|
|
941
|
+
* and selectively applies operations.
|
|
942
|
+
*
|
|
943
|
+
* @param graph - The graph to analyze.
|
|
944
|
+
* @param problem - Natural-language problem statement.
|
|
945
|
+
* @param adapter - LLM adapter for the analysis call.
|
|
946
|
+
* @param opts - Model and actor options.
|
|
947
|
+
* @returns A structured strategy plan.
|
|
948
|
+
* @throws On invalid LLM output.
|
|
949
|
+
*/
|
|
950
|
+
declare function suggestStrategy(graph: Graph, problem: string, adapter: LLMAdapter, opts?: SuggestStrategyOptions): Promise<StrategyPlan>;
|
|
951
|
+
|
|
952
|
+
type ai_AdmissionScore3DOptions = AdmissionScore3DOptions;
|
|
953
|
+
type ai_AdmissionScores = AdmissionScores;
|
|
954
|
+
type ai_AgentLoopGraph = AgentLoopGraph;
|
|
955
|
+
declare const ai_AgentLoopGraph: typeof AgentLoopGraph;
|
|
956
|
+
type ai_AgentLoopOptions = AgentLoopOptions;
|
|
957
|
+
type ai_AgentLoopStatus = AgentLoopStatus;
|
|
958
|
+
type ai_AgentMemoryGraph<TMem = unknown> = AgentMemoryGraph<TMem>;
|
|
959
|
+
type ai_AgentMemoryOptions<TMem = unknown> = AgentMemoryOptions<TMem>;
|
|
960
|
+
type ai_ChatMessage = ChatMessage;
|
|
961
|
+
type ai_ChatStreamGraph = ChatStreamGraph;
|
|
962
|
+
declare const ai_ChatStreamGraph: typeof ChatStreamGraph;
|
|
963
|
+
type ai_ChatStreamOptions = ChatStreamOptions;
|
|
964
|
+
type ai_ContentDecision = ContentDecision;
|
|
965
|
+
type ai_ContentGateOptions = ContentGateOptions;
|
|
966
|
+
type ai_CostMeterOptions = CostMeterOptions;
|
|
967
|
+
type ai_CostMeterReading = CostMeterReading;
|
|
968
|
+
type ai_ExtractedToolCall = ExtractedToolCall;
|
|
969
|
+
type ai_FromLLMOptions = FromLLMOptions;
|
|
970
|
+
type ai_GatedStreamHandle<T> = GatedStreamHandle<T>;
|
|
971
|
+
type ai_GatedStreamOptions = GatedStreamOptions;
|
|
972
|
+
type ai_GaugesAsContextOptions = GaugesAsContextOptions;
|
|
973
|
+
type ai_GraphDefValidation = GraphDefValidation;
|
|
974
|
+
type ai_GraphFromSpecOptions = GraphFromSpecOptions;
|
|
975
|
+
type ai_KeywordFlag = KeywordFlag;
|
|
976
|
+
type ai_KeywordFlagExtractorOptions = KeywordFlagExtractorOptions;
|
|
977
|
+
type ai_KnobsAsToolsResult = KnobsAsToolsResult;
|
|
978
|
+
type ai_LLMAdapter = LLMAdapter;
|
|
979
|
+
type ai_LLMConsolidatorOptions = LLMConsolidatorOptions;
|
|
980
|
+
type ai_LLMExtractorOptions = LLMExtractorOptions;
|
|
981
|
+
type ai_LLMInvokeOptions = LLMInvokeOptions;
|
|
982
|
+
type ai_LLMResponse = LLMResponse;
|
|
983
|
+
type ai_McpToolSchema = McpToolSchema;
|
|
984
|
+
type ai_MemoryTier = MemoryTier;
|
|
985
|
+
type ai_MemoryTiersBundle<TMem> = MemoryTiersBundle<TMem>;
|
|
986
|
+
type ai_MemoryTiersOptions<TMem> = MemoryTiersOptions<TMem>;
|
|
987
|
+
type ai_OpenAIToolSchema = OpenAIToolSchema;
|
|
988
|
+
type ai_PromptNodeOptions = PromptNodeOptions;
|
|
989
|
+
type ai_RedactorOptions = RedactorOptions;
|
|
990
|
+
type ai_RetrievalEntry<TMem> = RetrievalEntry<TMem>;
|
|
991
|
+
type ai_RetrievalPipelineOptions<TMem> = RetrievalPipelineOptions<TMem>;
|
|
992
|
+
type ai_RetrievalQuery = RetrievalQuery;
|
|
993
|
+
type ai_RetrievalTrace<TMem> = RetrievalTrace<TMem>;
|
|
994
|
+
type ai_StrategyOperation = StrategyOperation;
|
|
995
|
+
type ai_StrategyPlan = StrategyPlan;
|
|
996
|
+
type ai_StreamChunk = StreamChunk;
|
|
997
|
+
type ai_StreamingPromptNodeHandle<T> = StreamingPromptNodeHandle<T>;
|
|
998
|
+
type ai_StreamingPromptNodeOptions = StreamingPromptNodeOptions;
|
|
999
|
+
type ai_SuggestStrategyOptions = SuggestStrategyOptions;
|
|
1000
|
+
type ai_SystemPromptHandle = SystemPromptHandle;
|
|
1001
|
+
type ai_ToolCall = ToolCall;
|
|
1002
|
+
type ai_ToolDefinition = ToolDefinition;
|
|
1003
|
+
type ai_ToolRegistryGraph = ToolRegistryGraph;
|
|
1004
|
+
declare const ai_ToolRegistryGraph: typeof ToolRegistryGraph;
|
|
1005
|
+
type ai_ToolRegistryOptions = ToolRegistryOptions;
|
|
1006
|
+
declare const ai_admissionFilter3D: typeof admissionFilter3D;
|
|
1007
|
+
declare const ai_agentLoop: typeof agentLoop;
|
|
1008
|
+
declare const ai_agentMemory: typeof agentMemory;
|
|
1009
|
+
declare const ai_chatStream: typeof chatStream;
|
|
1010
|
+
declare const ai_contentGate: typeof contentGate;
|
|
1011
|
+
declare const ai_costMeterExtractor: typeof costMeterExtractor;
|
|
1012
|
+
declare const ai_fromLLM: typeof fromLLM;
|
|
1013
|
+
declare const ai_gatedStream: typeof gatedStream;
|
|
1014
|
+
declare const ai_gaugesAsContext: typeof gaugesAsContext;
|
|
1015
|
+
declare const ai_graphFromSpec: typeof graphFromSpec;
|
|
1016
|
+
declare const ai_keywordFlagExtractor: typeof keywordFlagExtractor;
|
|
1017
|
+
declare const ai_knobsAsTools: typeof knobsAsTools;
|
|
1018
|
+
declare const ai_llmConsolidator: typeof llmConsolidator;
|
|
1019
|
+
declare const ai_llmExtractor: typeof llmExtractor;
|
|
1020
|
+
declare const ai_promptNode: typeof promptNode;
|
|
1021
|
+
declare const ai_redactor: typeof redactor;
|
|
1022
|
+
declare const ai_streamExtractor: typeof streamExtractor;
|
|
1023
|
+
declare const ai_streamingPromptNode: typeof streamingPromptNode;
|
|
1024
|
+
declare const ai_suggestStrategy: typeof suggestStrategy;
|
|
1025
|
+
declare const ai_systemPromptBuilder: typeof systemPromptBuilder;
|
|
1026
|
+
declare const ai_toolCallExtractor: typeof toolCallExtractor;
|
|
1027
|
+
declare const ai_toolRegistry: typeof toolRegistry;
|
|
1028
|
+
declare const ai_validateGraphDef: typeof validateGraphDef;
|
|
1029
|
+
declare namespace ai {
|
|
1030
|
+
export { type ai_AdmissionScore3DOptions as AdmissionScore3DOptions, type ai_AdmissionScores as AdmissionScores, ai_AgentLoopGraph as AgentLoopGraph, type ai_AgentLoopOptions as AgentLoopOptions, type ai_AgentLoopStatus as AgentLoopStatus, type ai_AgentMemoryGraph as AgentMemoryGraph, type ai_AgentMemoryOptions as AgentMemoryOptions, type ai_ChatMessage as ChatMessage, ai_ChatStreamGraph as ChatStreamGraph, type ai_ChatStreamOptions as ChatStreamOptions, type ai_ContentDecision as ContentDecision, type ai_ContentGateOptions as ContentGateOptions, type ai_CostMeterOptions as CostMeterOptions, type ai_CostMeterReading as CostMeterReading, type ai_ExtractedToolCall as ExtractedToolCall, type ai_FromLLMOptions as FromLLMOptions, type ai_GatedStreamHandle as GatedStreamHandle, type ai_GatedStreamOptions as GatedStreamOptions, type ai_GaugesAsContextOptions as GaugesAsContextOptions, type ai_GraphDefValidation as GraphDefValidation, type ai_GraphFromSpecOptions as GraphFromSpecOptions, type ai_KeywordFlag as KeywordFlag, type ai_KeywordFlagExtractorOptions as KeywordFlagExtractorOptions, type ai_KnobsAsToolsResult as KnobsAsToolsResult, type ai_LLMAdapter as LLMAdapter, type ai_LLMConsolidatorOptions as LLMConsolidatorOptions, type ai_LLMExtractorOptions as LLMExtractorOptions, type ai_LLMInvokeOptions as LLMInvokeOptions, type ai_LLMResponse as LLMResponse, type ai_McpToolSchema as McpToolSchema, type ai_MemoryTier as MemoryTier, type ai_MemoryTiersBundle as MemoryTiersBundle, type ai_MemoryTiersOptions as MemoryTiersOptions, type ai_OpenAIToolSchema as OpenAIToolSchema, type ai_PromptNodeOptions as PromptNodeOptions, type ai_RedactorOptions as RedactorOptions, type ai_RetrievalEntry as RetrievalEntry, type ai_RetrievalPipelineOptions as RetrievalPipelineOptions, type ai_RetrievalQuery as RetrievalQuery, type ai_RetrievalTrace as RetrievalTrace, type ai_StrategyOperation as StrategyOperation, type ai_StrategyPlan as StrategyPlan, type ai_StreamChunk as StreamChunk, type ai_StreamingPromptNodeHandle as StreamingPromptNodeHandle, type ai_StreamingPromptNodeOptions as StreamingPromptNodeOptions, type ai_SuggestStrategyOptions as SuggestStrategyOptions, type ai_SystemPromptHandle as SystemPromptHandle, type ai_ToolCall as ToolCall, type ai_ToolDefinition as ToolDefinition, ai_ToolRegistryGraph as ToolRegistryGraph, type ai_ToolRegistryOptions as ToolRegistryOptions, ai_admissionFilter3D as admissionFilter3D, ai_agentLoop as agentLoop, ai_agentMemory as agentMemory, ai_chatStream as chatStream, ai_contentGate as contentGate, ai_costMeterExtractor as costMeterExtractor, ai_fromLLM as fromLLM, ai_gatedStream as gatedStream, ai_gaugesAsContext as gaugesAsContext, ai_graphFromSpec as graphFromSpec, ai_keywordFlagExtractor as keywordFlagExtractor, ai_knobsAsTools as knobsAsTools, ai_llmConsolidator as llmConsolidator, ai_llmExtractor as llmExtractor, ai_promptNode as promptNode, ai_redactor as redactor, ai_streamExtractor as streamExtractor, ai_streamingPromptNode as streamingPromptNode, ai_suggestStrategy as suggestStrategy, ai_systemPromptBuilder as systemPromptBuilder, ai_toolCallExtractor as toolCallExtractor, ai_toolRegistry as toolRegistry, ai_validateGraphDef as validateGraphDef };
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
export { type ToolRegistryOptions as $, type AdmissionScore3DOptions as A, type MemoryTiersBundle as B, type ChatMessage as C, type MemoryTiersOptions as D, type ExtractedToolCall as E, type FromLLMOptions as F, type GateController as G, type RetrievalEntry as H, type RetrievalPipelineOptions as I, type RetrievalQuery as J, type KeywordFlag as K, type LLMAdapter as L, type McpToolSchema as M, type RetrievalTrace as N, type OpenAIToolSchema as O, type PromptNodeOptions as P, type StrategyPlan as Q, type RedactorOptions as R, type StrategyOperation as S, type StreamChunk as T, type StreamingPromptNodeHandle as U, type StreamingPromptNodeOptions as V, type SuggestStrategyOptions as W, type SystemPromptHandle as X, type ToolCall as Y, type ToolDefinition as Z, ToolRegistryGraph as _, ai as a, admissionFilter3D as a0, agentLoop as a1, agentMemory as a2, chatStream as a3, contentGate as a4, costMeterExtractor as a5, fromLLM as a6, gatedStream as a7, gaugesAsContext as a8, graphFromSpec as a9, keywordFlagExtractor as aa, knobsAsTools as ab, llmConsolidator as ac, llmExtractor as ad, promptNode as ae, redactor as af, streamExtractor as ag, streamingPromptNode as ah, suggestStrategy as ai, systemPromptBuilder as aj, toolCallExtractor as ak, toolRegistry as al, validateGraphDef as am, type AdmissionScores as b, AgentLoopGraph as c, type AgentLoopOptions as d, type AgentLoopStatus as e, type AgentMemoryGraph as f, type AgentMemoryOptions as g, ChatStreamGraph as h, type ChatStreamOptions as i, type ContentDecision as j, type ContentGateOptions as k, type CostMeterOptions as l, type CostMeterReading as m, type GatedStreamHandle as n, orchestration as o, type GatedStreamOptions as p, type GaugesAsContextOptions as q, type GraphDefValidation as r, type GraphFromSpecOptions as s, type KeywordFlagExtractorOptions as t, type KnobsAsToolsResult as u, type LLMConsolidatorOptions as v, type LLMExtractorOptions as w, type LLMInvokeOptions as x, type LLMResponse as y, type MemoryTier as z };
|