@adriane-ai/graph-sdk 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +164 -7
- package/dist/index.js +326 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2305,7 +2305,7 @@ var createAgentNodeHandler = (nodeId, config) => {
|
|
|
2305
2305
|
};
|
|
2306
2306
|
var createToolNodeHandler = (config) => createToolNode(config.tools, { parallel: config.parallel });
|
|
2307
2307
|
var cachedNative;
|
|
2308
|
-
var hasEngineFns = (mod) => typeof mod === "object" && mod !== null && typeof mod.engineRun === "function" && typeof mod.engineResume === "function" && typeof mod.engineApproveAndResume === "function";
|
|
2308
|
+
var hasEngineFns = (mod) => typeof mod === "object" && mod !== null && typeof mod.engineRun === "function" && typeof mod.engineResume === "function" && typeof mod.engineApproveAndResume === "function" && typeof mod.engineSignal === "function";
|
|
2309
2309
|
var loadNativeEngine = () => {
|
|
2310
2310
|
if (cachedNative !== void 0) {
|
|
2311
2311
|
return cachedNative;
|
|
@@ -2420,6 +2420,7 @@ var RustGraphRunner = class {
|
|
|
2420
2420
|
baseSpec() {
|
|
2421
2421
|
return {
|
|
2422
2422
|
graph: this.parts.definition,
|
|
2423
|
+
subgraphs: this.parts.subgraphs,
|
|
2423
2424
|
agents: this.buildAgentsWire(),
|
|
2424
2425
|
componentNodes: this.buildComponentsWire(),
|
|
2425
2426
|
jsNodeIds: [...this.parts.jsNodeIds],
|
|
@@ -2427,8 +2428,8 @@ var RustGraphRunner = class {
|
|
|
2427
2428
|
};
|
|
2428
2429
|
}
|
|
2429
2430
|
/** Start a fresh run on the Rust engine. */
|
|
2430
|
-
async run(runId, initialData) {
|
|
2431
|
-
const spec = { ...this.baseSpec(), runId, initialData };
|
|
2431
|
+
async run(runId, initialData, inbox = {}) {
|
|
2432
|
+
const spec = { ...this.baseSpec(), runId, initialData, inbox };
|
|
2432
2433
|
const outcomeJson = await this.native.engineRun(
|
|
2433
2434
|
JSON.stringify(spec),
|
|
2434
2435
|
this.onNode,
|
|
@@ -2472,6 +2473,23 @@ var RustGraphRunner = class {
|
|
|
2472
2473
|
);
|
|
2473
2474
|
return this.outcomeToState(outcomeJson);
|
|
2474
2475
|
}
|
|
2476
|
+
/**
|
|
2477
|
+
* Deliver an external signal to a suspended run, then resume it. The Rust engine
|
|
2478
|
+
* injects `payload` into `__signals[name]` and advances past the node that awaited
|
|
2479
|
+
* the signal (a `waitForSignal` suspension is one-shot).
|
|
2480
|
+
*/
|
|
2481
|
+
async signal(state, name, payload) {
|
|
2482
|
+
const spec = { ...this.baseSpec(), state };
|
|
2483
|
+
const outcomeJson = await this.native.engineSignal(
|
|
2484
|
+
JSON.stringify(spec),
|
|
2485
|
+
name,
|
|
2486
|
+
JSON.stringify(payload ?? null),
|
|
2487
|
+
this.onNode,
|
|
2488
|
+
this.onCondition,
|
|
2489
|
+
this.onEvent
|
|
2490
|
+
);
|
|
2491
|
+
return this.outcomeToState(outcomeJson);
|
|
2492
|
+
}
|
|
2475
2493
|
};
|
|
2476
2494
|
var tryCreateRustRunner = (parts) => {
|
|
2477
2495
|
const native = loadNativeEngine();
|
|
@@ -2529,12 +2547,16 @@ var CompiledGraph = class {
|
|
|
2529
2547
|
}
|
|
2530
2548
|
this.checkpointer = new InMemoryCheckpointer();
|
|
2531
2549
|
this.eventBus = new InMemoryEventBus();
|
|
2550
|
+
const subgraphsById = new Map(
|
|
2551
|
+
(parts.subgraphs ?? []).map((graph) => [String(graph.id), graph])
|
|
2552
|
+
);
|
|
2532
2553
|
this.runtime = new GraphRuntime({
|
|
2533
2554
|
graph: parts.definition,
|
|
2534
2555
|
nodeRegistry,
|
|
2535
2556
|
conditionRegistry,
|
|
2536
2557
|
checkpointer: this.checkpointer,
|
|
2537
|
-
eventBus: this.eventBus
|
|
2558
|
+
eventBus: this.eventBus,
|
|
2559
|
+
subgraphResolver: subgraphsById.size === 0 ? void 0 : (graphId) => subgraphsById.get(String(graphId))
|
|
2538
2560
|
});
|
|
2539
2561
|
this.rustRunner = this.maybeCreateRustRunner(parts);
|
|
2540
2562
|
this.rustRunner?.subscribe((event) => {
|
|
@@ -2603,6 +2625,7 @@ var CompiledGraph = class {
|
|
|
2603
2625
|
const toolFns = this.buildToolFns(agentConfigs);
|
|
2604
2626
|
const runnerParts = {
|
|
2605
2627
|
definition: parts.definition,
|
|
2628
|
+
subgraphs: parts.subgraphs ?? [],
|
|
2606
2629
|
nodeFns: this.buildNodeFns(jsHandlerNodeIds, parts.handlers),
|
|
2607
2630
|
toolFns,
|
|
2608
2631
|
conditions: this.buildConditionFns(parts.conditions),
|
|
@@ -2660,11 +2683,20 @@ var CompiledGraph = class {
|
|
|
2660
2683
|
async run(initialData = {}, options) {
|
|
2661
2684
|
const runId = options?.runId ?? generateRunId();
|
|
2662
2685
|
if (this.rustRunner !== null) {
|
|
2663
|
-
const state2 = await this.rustRunner.run(
|
|
2686
|
+
const state2 = await this.rustRunner.run(
|
|
2687
|
+
runId,
|
|
2688
|
+
initialData,
|
|
2689
|
+
options?.inbox ?? {}
|
|
2690
|
+
);
|
|
2664
2691
|
this.captureSuspension(state2);
|
|
2665
2692
|
return state2;
|
|
2666
2693
|
}
|
|
2667
2694
|
warnTsEngineOnce();
|
|
2695
|
+
for (const [nodeId, inputs] of Object.entries(options?.inbox ?? {})) {
|
|
2696
|
+
for (const input of inputs) {
|
|
2697
|
+
await this.runtime.send(runId, nodeId, input);
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2668
2700
|
const state = await this.runtime.start(runId, initialData);
|
|
2669
2701
|
return state;
|
|
2670
2702
|
}
|
|
@@ -2703,6 +2735,27 @@ var CompiledGraph = class {
|
|
|
2703
2735
|
await this.runtime.updateState(runId, { [APPROVED_TOOLS_CHANNEL]: names });
|
|
2704
2736
|
return this.resume(runId);
|
|
2705
2737
|
}
|
|
2738
|
+
/**
|
|
2739
|
+
* Deliver an external signal to a run suspended on a `waitForSignal` node, then
|
|
2740
|
+
* resume it: the payload is injected into the `__signals` channel under `name` and
|
|
2741
|
+
* the run advances past the waiting node. The seam a control plane uses to wake a
|
|
2742
|
+
* run on an external event (a webhook, a message, an approval-out-of-band).
|
|
2743
|
+
*
|
|
2744
|
+
* Durable timers + external signals run on the **Rust engine** (the production
|
|
2745
|
+
* runtime); the in-process TypeScript fallback does not model them, so this throws
|
|
2746
|
+
* on the TS path. Run with the native addon (or `ADRIANE_SDK_ENGINE=rust`).
|
|
2747
|
+
*/
|
|
2748
|
+
async signal(runId, name, payload) {
|
|
2749
|
+
if (this.rustRunner === null) {
|
|
2750
|
+
throw new Error(
|
|
2751
|
+
"CompiledGraph.signal requires the Rust engine (durable timers/signals are not supported on the in-process TypeScript fallback). Install @adriane-ai/napi."
|
|
2752
|
+
);
|
|
2753
|
+
}
|
|
2754
|
+
const suspended = this.requireSuspendedState(runId);
|
|
2755
|
+
const state = await this.rustRunner.signal(suspended, name, payload);
|
|
2756
|
+
this.captureSuspension(state);
|
|
2757
|
+
return state;
|
|
2758
|
+
}
|
|
2706
2759
|
/**
|
|
2707
2760
|
* Project granted tool names into the wire shape the Rust engine validates: each
|
|
2708
2761
|
* tool carries the principal that requested it (the owning agent node) and the
|
|
@@ -2746,23 +2799,140 @@ var CompiledGraph = class {
|
|
|
2746
2799
|
}
|
|
2747
2800
|
/**
|
|
2748
2801
|
* Stream events as the graph executes. See {@link StreamMode} for the available
|
|
2749
|
-
* shapes.
|
|
2750
|
-
*
|
|
2751
|
-
*
|
|
2802
|
+
* shapes. On the TS engine all four modes stream natively. On the **Rust engine** the
|
|
2803
|
+
* modes are projected — incrementally — over the run-event feed that already crosses
|
|
2804
|
+
* napi:
|
|
2805
|
+
* - `updates` — a `state_update` per node completion (`delta` = the node's output).
|
|
2806
|
+
* - `values` — a full `state_value` per node completion, accumulated by replaying the
|
|
2807
|
+
* node deltas through the channel reducers (the SDK mirrors the engine's reducers),
|
|
2808
|
+
* plus a final authoritative `state_value` from the resolved run.
|
|
2809
|
+
* - `messages` — a `message_delta` per new entry appended to the `messages` channel
|
|
2810
|
+
* (message-level; token-level deltas need gateway token streaming — still deferred).
|
|
2811
|
+
* - `debug` — every run-lifecycle event wrapped as a `debug` payload.
|
|
2752
2812
|
*/
|
|
2753
2813
|
stream(initialData, mode, options) {
|
|
2754
2814
|
const runId = options?.runId ?? generateRunId();
|
|
2755
2815
|
if (this.rustRunner !== null) {
|
|
2756
|
-
return this.streamViaRust(runId, initialData);
|
|
2816
|
+
return this.streamViaRust(runId, initialData, mode);
|
|
2757
2817
|
}
|
|
2758
2818
|
warnTsEngineOnce();
|
|
2759
2819
|
return this.runtime.stream(runId, initialData, mode);
|
|
2760
2820
|
}
|
|
2761
|
-
/**
|
|
2762
|
-
|
|
2763
|
-
const
|
|
2764
|
-
this.
|
|
2765
|
-
|
|
2821
|
+
/** Seed a running channel map from the graph's channel defaults + the run's input. */
|
|
2822
|
+
seedChannels(initialData) {
|
|
2823
|
+
const running = {};
|
|
2824
|
+
for (const [name, def] of Object.entries(this.definition.channels)) {
|
|
2825
|
+
running[name] = initialData[name] ?? def.default ?? null;
|
|
2826
|
+
}
|
|
2827
|
+
for (const [key, value] of Object.entries(initialData)) {
|
|
2828
|
+
if (!(key in running)) {
|
|
2829
|
+
running[key] = value;
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
return running;
|
|
2833
|
+
}
|
|
2834
|
+
/** Apply a node delta to the running channels via the declared reducers (engine parity). */
|
|
2835
|
+
applyDelta(running, delta) {
|
|
2836
|
+
for (const [key, value] of Object.entries(delta)) {
|
|
2837
|
+
const reducer = this.definition.channels[key]?.reducer ?? "replace";
|
|
2838
|
+
if (reducer === "append") {
|
|
2839
|
+
const current = running[key];
|
|
2840
|
+
const existing = Array.isArray(current) ? current : current == null ? [] : [current];
|
|
2841
|
+
running[key] = Array.isArray(value) ? [...existing, ...value] : [...existing, value];
|
|
2842
|
+
} else if (reducer === "merge" && value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
2843
|
+
const current = running[key];
|
|
2844
|
+
const base = current !== null && typeof current === "object" && !Array.isArray(current) ? current : {};
|
|
2845
|
+
running[key] = { ...base, ...value };
|
|
2846
|
+
} else {
|
|
2847
|
+
running[key] = value;
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
/**
|
|
2852
|
+
* Drive the Rust run and project its forwarded run-event feed into {@link StreamEvent}s,
|
|
2853
|
+
* incrementally for every mode. Events arrive via the runner's subscriber while the run
|
|
2854
|
+
* promise is in flight; a small wake/queue interleaves them with the run's completion.
|
|
2855
|
+
*/
|
|
2856
|
+
async *streamViaRust(runId, initialData, mode) {
|
|
2857
|
+
const queue = [];
|
|
2858
|
+
let notify = null;
|
|
2859
|
+
const wake = () => {
|
|
2860
|
+
const resume = notify;
|
|
2861
|
+
notify = null;
|
|
2862
|
+
resume?.();
|
|
2863
|
+
};
|
|
2864
|
+
const running = this.seedChannels(initialData);
|
|
2865
|
+
let seenMessages = Array.isArray(running.messages) ? running.messages.length : 0;
|
|
2866
|
+
const shape = (event) => {
|
|
2867
|
+
if (event.type === "node_completed") {
|
|
2868
|
+
const delta = event.output ?? {};
|
|
2869
|
+
if (mode === "updates") {
|
|
2870
|
+
return [{ type: "state_update", delta, nodeId: event.nodeId }];
|
|
2871
|
+
}
|
|
2872
|
+
this.applyDelta(running, delta);
|
|
2873
|
+
if (mode === "values") {
|
|
2874
|
+
return [{ type: "state_value", state: this.syntheticState(runId, event.nodeId, running) }];
|
|
2875
|
+
}
|
|
2876
|
+
if (mode === "messages") {
|
|
2877
|
+
const messages = Array.isArray(running.messages) ? running.messages : [];
|
|
2878
|
+
const fresh = messages.slice(seenMessages);
|
|
2879
|
+
seenMessages = messages.length;
|
|
2880
|
+
return fresh.flatMap((message) => messageDeltas(message, event.nodeId));
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
if (mode === "debug") {
|
|
2884
|
+
const nodeId = "nodeId" in event ? event.nodeId : "";
|
|
2885
|
+
return [{ type: "debug", payload: event, nodeId }];
|
|
2886
|
+
}
|
|
2887
|
+
return [];
|
|
2888
|
+
};
|
|
2889
|
+
const unsubscribe = this.rustRunner.subscribe((event) => {
|
|
2890
|
+
const shaped = shape(event);
|
|
2891
|
+
if (shaped.length > 0) {
|
|
2892
|
+
queue.push(...shaped);
|
|
2893
|
+
wake();
|
|
2894
|
+
}
|
|
2895
|
+
});
|
|
2896
|
+
let done = false;
|
|
2897
|
+
const runPromise = this.rustRunner.run(runId, initialData, {}).then((state) => {
|
|
2898
|
+
this.captureSuspension(state);
|
|
2899
|
+
return state;
|
|
2900
|
+
}).finally(() => {
|
|
2901
|
+
done = true;
|
|
2902
|
+
wake();
|
|
2903
|
+
});
|
|
2904
|
+
try {
|
|
2905
|
+
for (; ; ) {
|
|
2906
|
+
while (queue.length > 0) {
|
|
2907
|
+
yield queue.shift();
|
|
2908
|
+
}
|
|
2909
|
+
if (done) {
|
|
2910
|
+
break;
|
|
2911
|
+
}
|
|
2912
|
+
await new Promise((resolve) => {
|
|
2913
|
+
notify = resolve;
|
|
2914
|
+
});
|
|
2915
|
+
}
|
|
2916
|
+
const finalState = await runPromise;
|
|
2917
|
+
if (mode === "values") {
|
|
2918
|
+
yield { type: "state_value", state: finalState };
|
|
2919
|
+
}
|
|
2920
|
+
} finally {
|
|
2921
|
+
unsubscribe();
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
/** A channels-only synthetic GraphState for a `values` stream step. */
|
|
2925
|
+
syntheticState(runId, nodeId, channels) {
|
|
2926
|
+
return {
|
|
2927
|
+
runId,
|
|
2928
|
+
graphId: this.definition.id,
|
|
2929
|
+
currentNodeId: nodeId,
|
|
2930
|
+
status: "running",
|
|
2931
|
+
channels: { ...channels },
|
|
2932
|
+
version: 0,
|
|
2933
|
+
createdAt: "",
|
|
2934
|
+
updatedAt: ""
|
|
2935
|
+
};
|
|
2766
2936
|
}
|
|
2767
2937
|
/** Subscribe to the run-event lifecycle stream. Returns an unsubscribe function. */
|
|
2768
2938
|
onEvent(handler) {
|
|
@@ -2801,6 +2971,31 @@ var toolNameOfSubject = (request) => {
|
|
|
2801
2971
|
return typeof description === "string" && description.startsWith(TOOL_SUBJECT_PREFIX2) ? description.slice(TOOL_SUBJECT_PREFIX2.length) : void 0;
|
|
2802
2972
|
};
|
|
2803
2973
|
var syntheticContext = () => ({ memory: void 0 });
|
|
2974
|
+
var messageDeltas = (message, nodeId) => {
|
|
2975
|
+
if (message === null || typeof message !== "object") {
|
|
2976
|
+
return [];
|
|
2977
|
+
}
|
|
2978
|
+
const msg = message;
|
|
2979
|
+
const out = [];
|
|
2980
|
+
const messageId = typeof msg.id === "string" ? msg.id : "";
|
|
2981
|
+
if (typeof msg.content === "string" && msg.content.length > 0) {
|
|
2982
|
+
out.push({ type: "message_delta", delta: msg.content, nodeId, messageId });
|
|
2983
|
+
}
|
|
2984
|
+
if (Array.isArray(msg.toolCalls)) {
|
|
2985
|
+
for (const call of msg.toolCalls) {
|
|
2986
|
+
if (call !== null && typeof call === "object") {
|
|
2987
|
+
const c = call;
|
|
2988
|
+
out.push({
|
|
2989
|
+
type: "tool_call",
|
|
2990
|
+
toolId: typeof c.id === "string" ? c.id : typeof c.name === "string" ? c.name : "",
|
|
2991
|
+
input: c.args ?? c.input ?? null,
|
|
2992
|
+
nodeId
|
|
2993
|
+
});
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
return out;
|
|
2998
|
+
};
|
|
2804
2999
|
var toUpdateObject = (value) => {
|
|
2805
3000
|
if (value === null || typeof value !== "object") {
|
|
2806
3001
|
return {};
|
|
@@ -2885,6 +3080,8 @@ var GraphBuilder = class {
|
|
|
2885
3080
|
agentApprovals = /* @__PURE__ */ new Map();
|
|
2886
3081
|
/** Per component node, the `{ kind, params }` carrier the Rust engine bridge needs. */
|
|
2887
3082
|
componentConfigs = /* @__PURE__ */ new Map();
|
|
3083
|
+
/** Child graphs registered as `subgraph` nodes, keyed by their (global) graph id. */
|
|
3084
|
+
subgraphDefs = /* @__PURE__ */ new Map();
|
|
2888
3085
|
entryNodeId;
|
|
2889
3086
|
constructor(options) {
|
|
2890
3087
|
this.options = options;
|
|
@@ -3013,6 +3210,85 @@ var GraphBuilder = class {
|
|
|
3013
3210
|
this.componentConfigs.set(id, { kind: descriptor.kind, params: descriptor.params });
|
|
3014
3211
|
return this;
|
|
3015
3212
|
}
|
|
3213
|
+
/**
|
|
3214
|
+
* Add a **subgraph node**: nest another graph (built with its own
|
|
3215
|
+
* {@link GraphBuilder}) as a single node. On entry the parent's channels are
|
|
3216
|
+
* projected into the child via `inputMapping` (`childKey → parentKey`; omit to copy
|
|
3217
|
+
* all parent channels); on completion the child's channels are merged back via
|
|
3218
|
+
* `outputMapping` (`parentKey → childKey`; omit to spread all child channels onto
|
|
3219
|
+
* the parent). If the child suspends (e.g. an internal human gate), the parent
|
|
3220
|
+
* suspends at this node and a parent `resume` re-attaches to the child.
|
|
3221
|
+
*
|
|
3222
|
+
* The child's wiring (node handlers, conditions, agent/component configs) is merged
|
|
3223
|
+
* into the parent — child runs share the parent's registries, keyed by GLOBAL node
|
|
3224
|
+
* id — so child node ids must not collide with the parent's. Declare on the parent
|
|
3225
|
+
* any channels the `outputMapping` writes into.
|
|
3226
|
+
*
|
|
3227
|
+
* ```ts
|
|
3228
|
+
* const child = createGraph({ name: "double", id: "double" })
|
|
3229
|
+
* .channel("in", { type: "number", default: 0 })
|
|
3230
|
+
* .channel("out", { type: "number", default: 0 })
|
|
3231
|
+
* .node("calc", (s) => ({ out: (s.in as number) * 2 }));
|
|
3232
|
+
* createGraph({ name: "parent" })
|
|
3233
|
+
* .channel("x", { type: "number", default: 21 })
|
|
3234
|
+
* .channel("y", { type: "number", default: 0 })
|
|
3235
|
+
* .subgraph("sub", child, { inputMapping: { in: "x" }, outputMapping: { y: "out" } });
|
|
3236
|
+
* ```
|
|
3237
|
+
*/
|
|
3238
|
+
subgraph(id, child, options) {
|
|
3239
|
+
if (this.handlers.has(id) || this.nodes.some((node) => String(node.id) === id)) {
|
|
3240
|
+
throw new DuplicateNodeError(id);
|
|
3241
|
+
}
|
|
3242
|
+
const childParts = child.toSubgraphParts();
|
|
3243
|
+
for (const [nodeId, handler] of childParts.handlers) {
|
|
3244
|
+
if (this.handlers.has(nodeId)) {
|
|
3245
|
+
throw new DuplicateNodeError(nodeId);
|
|
3246
|
+
}
|
|
3247
|
+
this.handlers.set(nodeId, handler);
|
|
3248
|
+
}
|
|
3249
|
+
for (const [name, fn] of childParts.conditions) {
|
|
3250
|
+
this.conditions.set(name, fn);
|
|
3251
|
+
}
|
|
3252
|
+
for (const [nodeId, config] of childParts.agentConfigs) {
|
|
3253
|
+
this.agentConfigs.set(nodeId, config);
|
|
3254
|
+
}
|
|
3255
|
+
for (const [nodeId, binding] of childParts.agentApprovals) {
|
|
3256
|
+
this.agentApprovals.set(nodeId, binding);
|
|
3257
|
+
}
|
|
3258
|
+
for (const [nodeId, config] of childParts.componentConfigs) {
|
|
3259
|
+
this.componentConfigs.set(nodeId, config);
|
|
3260
|
+
}
|
|
3261
|
+
this.subgraphDefs.set(String(childParts.definition.id), childParts.definition);
|
|
3262
|
+
for (const [graphId, definition] of childParts.subgraphDefs) {
|
|
3263
|
+
this.subgraphDefs.set(graphId, definition);
|
|
3264
|
+
}
|
|
3265
|
+
this.nodes.push({
|
|
3266
|
+
id,
|
|
3267
|
+
type: "subgraph",
|
|
3268
|
+
label: options?.label ?? id,
|
|
3269
|
+
subgraphId: childParts.definition.id,
|
|
3270
|
+
inputMapping: options?.inputMapping,
|
|
3271
|
+
outputMapping: options?.outputMapping
|
|
3272
|
+
});
|
|
3273
|
+
this.entryNodeId ??= id;
|
|
3274
|
+
return this;
|
|
3275
|
+
}
|
|
3276
|
+
/**
|
|
3277
|
+
* @internal Extract this builder's wiring so it can be nested as a subgraph by a
|
|
3278
|
+
* parent {@link GraphBuilder.subgraph}. Returns live maps (the parent merges them);
|
|
3279
|
+
* not part of the public authoring API.
|
|
3280
|
+
*/
|
|
3281
|
+
toSubgraphParts() {
|
|
3282
|
+
return {
|
|
3283
|
+
definition: this.buildDefinition(),
|
|
3284
|
+
handlers: this.handlers,
|
|
3285
|
+
conditions: this.conditions,
|
|
3286
|
+
agentConfigs: this.agentConfigs,
|
|
3287
|
+
agentApprovals: this.agentApprovals,
|
|
3288
|
+
componentConfigs: this.componentConfigs,
|
|
3289
|
+
subgraphDefs: this.subgraphDefs
|
|
3290
|
+
};
|
|
3291
|
+
}
|
|
3016
3292
|
/** Add an unconditional edge from one node to another. */
|
|
3017
3293
|
edge(from, to) {
|
|
3018
3294
|
this.edges.push({
|
|
@@ -3059,7 +3335,10 @@ var GraphBuilder = class {
|
|
|
3059
3335
|
/** Validate and compile, returning a {@link Result} instead of throwing. */
|
|
3060
3336
|
safeCompile() {
|
|
3061
3337
|
const definition = this.buildDefinition();
|
|
3062
|
-
const
|
|
3338
|
+
const subgraphs = [...this.subgraphDefs.values()];
|
|
3339
|
+
const errors = [definition, ...subgraphs].flatMap(
|
|
3340
|
+
(graph) => tryRustValidate(graph) ?? validateGraph(graph)
|
|
3341
|
+
);
|
|
3063
3342
|
if (errors.length > 0) {
|
|
3064
3343
|
return { success: false, error: new GraphCompileError(errors) };
|
|
3065
3344
|
}
|
|
@@ -3071,7 +3350,8 @@ var GraphBuilder = class {
|
|
|
3071
3350
|
conditions: this.conditions,
|
|
3072
3351
|
agentConfigs: this.agentConfigs,
|
|
3073
3352
|
agentApprovals: this.agentApprovals,
|
|
3074
|
-
componentConfigs: this.componentConfigs
|
|
3353
|
+
componentConfigs: this.componentConfigs,
|
|
3354
|
+
subgraphs
|
|
3075
3355
|
})
|
|
3076
3356
|
};
|
|
3077
3357
|
}
|
|
@@ -3086,6 +3366,33 @@ var GraphBuilder = class {
|
|
|
3086
3366
|
};
|
|
3087
3367
|
var createGraph = (options) => new GraphBuilder(options);
|
|
3088
3368
|
|
|
3369
|
+
// src/durable.ts
|
|
3370
|
+
var SLEEP_UNTIL_KEY = "__sleepUntil";
|
|
3371
|
+
var WAIT_FOR_SIGNAL_KEY = "__waitForSignal";
|
|
3372
|
+
var SUSPEND_META_KEY = "__suspend";
|
|
3373
|
+
var SIGNALS_KEY = "__signals";
|
|
3374
|
+
var sleepUntil = (wakeAt, update = {}) => ({ ...update, [SLEEP_UNTIL_KEY]: wakeAt });
|
|
3375
|
+
var waitForSignal = (name, options = {}) => ({
|
|
3376
|
+
...options.update ?? {},
|
|
3377
|
+
[WAIT_FOR_SIGNAL_KEY]: name,
|
|
3378
|
+
...options.wakeAt === void 0 ? {} : { [SLEEP_UNTIL_KEY]: options.wakeAt }
|
|
3379
|
+
});
|
|
3380
|
+
var readSuspendMeta = (state) => {
|
|
3381
|
+
const raw = state.channels[SUSPEND_META_KEY];
|
|
3382
|
+
if (raw !== null && typeof raw === "object" && typeof raw.reason === "string") {
|
|
3383
|
+
return raw;
|
|
3384
|
+
}
|
|
3385
|
+
return void 0;
|
|
3386
|
+
};
|
|
3387
|
+
var readSignal = (state, name) => {
|
|
3388
|
+
const signals = state.channels[SIGNALS_KEY];
|
|
3389
|
+
return signals !== null && typeof signals === "object" ? signals[name] : void 0;
|
|
3390
|
+
};
|
|
3391
|
+
|
|
3392
|
+
// src/send.ts
|
|
3393
|
+
var INJECTED_KEY = "__injected";
|
|
3394
|
+
var readInjected = (state) => state.channels[INJECTED_KEY];
|
|
3395
|
+
|
|
3089
3396
|
// src/components.ts
|
|
3090
3397
|
var valueToText = (value) => {
|
|
3091
3398
|
if (typeof value === "string") {
|
|
@@ -5433,6 +5740,8 @@ var assembleParts = (definition, usesApprovalEngine) => {
|
|
|
5433
5740
|
}
|
|
5434
5741
|
return {
|
|
5435
5742
|
definition,
|
|
5743
|
+
// Catalog graphs (assembled from node-metadata carriers) carry no subgraph nodes.
|
|
5744
|
+
subgraphs: [],
|
|
5436
5745
|
nodeFns: new Map(jsNodeIds.size === 0 ? [] : [...jsNodeIds].map((id) => [id, async () => ({})])),
|
|
5437
5746
|
toolFns: /* @__PURE__ */ new Map(),
|
|
5438
5747
|
conditions: /* @__PURE__ */ new Map(),
|
|
@@ -5541,6 +5850,6 @@ var isCatalogGraph = (definition) => definition.nodes.some(
|
|
|
5541
5850
|
(node) => readComponentCarrier(node.metadata) !== void 0 || readAgentCarrier(node.metadata) !== void 0
|
|
5542
5851
|
);
|
|
5543
5852
|
|
|
5544
|
-
export { AGENT_APPROVAL_INTERRUPT, APPROVAL_IDS_CHANNEL, APPROVED_TOOLS_CHANNEL, AdrianeSdkError, AnthropicProviderAdapter, CompiledGraph, DEFAULT_AGENT_OUTPUT_CHANNEL, DEFAULT_PREFERENCE, DEFAULT_REFERENCE_CORPUS, DEFAULT_TIER_TABLE, DefaultLLMGateway, DuplicateNodeError, DynamicInterrupt, EmbeddingsResponseError, GraphBuilder, GraphCompileError, InMemoryCheckpointer, InMemoryPromptRegistry, InMemoryToolRegistry, MODEL_TIERS, MissingEmbeddingsKeyError, MissingHandlerError, MockLLMProviderAdapter, ModelPolicy, OpenAICompatibleProviderAdapter, RustEngineUnavailableError, buildDocQaReference, componentCatalog, components, cosineSimilarity2 as cosineSimilarity, createAgentNodeHandler, createEmbeddings, createGraph, createToolNodeHandler, createVectorStore, docQaReferenceDefinition, exampleGraphs, isCatalogGraph, prebuilt, prebuiltCatalog, readAgentCarrier, readComponentCarrier, resumeCatalogGraph, runCatalogGraph, rustEngineAvailable, rustValidatorActive, semanticRetriever, streamAgentTokens, tierCatalog, toAgentApprovalBinding, toRustAgentConfig };
|
|
5853
|
+
export { AGENT_APPROVAL_INTERRUPT, APPROVAL_IDS_CHANNEL, APPROVED_TOOLS_CHANNEL, AdrianeSdkError, AnthropicProviderAdapter, CompiledGraph, DEFAULT_AGENT_OUTPUT_CHANNEL, DEFAULT_PREFERENCE, DEFAULT_REFERENCE_CORPUS, DEFAULT_TIER_TABLE, DefaultLLMGateway, DuplicateNodeError, DynamicInterrupt, EmbeddingsResponseError, GraphBuilder, GraphCompileError, INJECTED_KEY, InMemoryCheckpointer, InMemoryPromptRegistry, InMemoryToolRegistry, MODEL_TIERS, MissingEmbeddingsKeyError, MissingHandlerError, MockLLMProviderAdapter, ModelPolicy, OpenAICompatibleProviderAdapter, RustEngineUnavailableError, SIGNALS_KEY, SLEEP_UNTIL_KEY, SUSPEND_META_KEY, WAIT_FOR_SIGNAL_KEY, buildDocQaReference, componentCatalog, components, cosineSimilarity2 as cosineSimilarity, createAgentNodeHandler, createEmbeddings, createGraph, createToolNodeHandler, createVectorStore, docQaReferenceDefinition, exampleGraphs, isCatalogGraph, prebuilt, prebuiltCatalog, readAgentCarrier, readComponentCarrier, readInjected, readSignal, readSuspendMeta, resumeCatalogGraph, runCatalogGraph, rustEngineAvailable, rustValidatorActive, semanticRetriever, sleepUntil, streamAgentTokens, tierCatalog, toAgentApprovalBinding, toRustAgentConfig, waitForSignal };
|
|
5545
5854
|
//# sourceMappingURL=index.js.map
|
|
5546
5855
|
//# sourceMappingURL=index.js.map
|