@graphrefly/graphrefly 0.11.0 → 0.12.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.
Files changed (37) hide show
  1. package/dist/{chunk-UG2QZMRN.js → chunk-4F2ZFD5L.js} +2 -1
  2. package/dist/{chunk-OHUECHWY.js → chunk-6OLNYOGU.js} +2 -2
  3. package/dist/{chunk-2VHNCFGG.js → chunk-BRPCN2HJ.js} +46 -17
  4. package/dist/chunk-BRPCN2HJ.js.map +1 -0
  5. package/dist/{chunk-U5HFZGAQ.js → chunk-IXTW3BIO.js} +3 -3
  6. package/dist/{chunk-3WACHRHV.js → chunk-JYRHO63K.js} +3 -3
  7. package/dist/{chunk-PZCDQD2U.js → chunk-NULSP7U4.js} +4 -4
  8. package/dist/{chunk-2OTXEZQO.js → chunk-VQWLA6XQ.js} +3 -3
  9. package/dist/{chunk-5WXTWOD7.js → chunk-X732W3QA.js} +2 -2
  10. package/dist/{chunk-FMVFRP7L.js → chunk-XWMTVV2D.js} +3 -3
  11. package/dist/compat/nestjs/index.js +7 -7
  12. package/dist/core/index.js +3 -3
  13. package/dist/extra/index.cjs +42 -14
  14. package/dist/extra/index.cjs.map +1 -1
  15. package/dist/extra/index.d.cts +1 -1
  16. package/dist/extra/index.d.ts +1 -1
  17. package/dist/extra/index.js +5 -5
  18. package/dist/graph/index.js +4 -4
  19. package/dist/{index-Bbgvinsi.d.ts → index-CiAqgfFg.d.ts} +14 -10
  20. package/dist/{index-DpZozxaJ.d.cts → index-CthwPnHQ.d.cts} +14 -10
  21. package/dist/index.cjs +230 -18
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +75 -5
  24. package/dist/index.d.ts +75 -5
  25. package/dist/index.js +198 -14
  26. package/dist/index.js.map +1 -1
  27. package/dist/patterns/reactive-layout/index.js +4 -4
  28. package/package.json +1 -1
  29. package/dist/chunk-2VHNCFGG.js.map +0 -1
  30. /package/dist/{chunk-UG2QZMRN.js.map → chunk-4F2ZFD5L.js.map} +0 -0
  31. /package/dist/{chunk-OHUECHWY.js.map → chunk-6OLNYOGU.js.map} +0 -0
  32. /package/dist/{chunk-U5HFZGAQ.js.map → chunk-IXTW3BIO.js.map} +0 -0
  33. /package/dist/{chunk-3WACHRHV.js.map → chunk-JYRHO63K.js.map} +0 -0
  34. /package/dist/{chunk-PZCDQD2U.js.map → chunk-NULSP7U4.js.map} +0 -0
  35. /package/dist/{chunk-2OTXEZQO.js.map → chunk-VQWLA6XQ.js.map} +0 -0
  36. /package/dist/{chunk-5WXTWOD7.js.map → chunk-X732W3QA.js.map} +0 -0
  37. /package/dist/{chunk-FMVFRP7L.js.map → chunk-XWMTVV2D.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -182,7 +182,6 @@ __export(index_exports, {
182
182
  fromTimer: () => fromTimer,
183
183
  fromWebSocket: () => fromWebSocket,
184
184
  fromWebhook: () => fromWebhook,
185
- gate: () => gate,
186
185
  globToRegExp: () => globToRegExp,
187
186
  graph: () => graph_exports,
188
187
  graphspec: () => graphspec_exports,
@@ -298,6 +297,7 @@ __export(index_exports, {
298
297
  toWebSocket: () => toWebSocket,
299
298
  tokenBucket: () => tokenBucket,
300
299
  tokenTracker: () => tokenTracker,
300
+ valve: () => valve,
301
301
  verifiable: () => verifiable,
302
302
  version: () => version,
303
303
  vue: () => vue_exports,
@@ -6948,7 +6948,6 @@ __export(extra_exports, {
6948
6948
  fromTimer: () => fromTimer,
6949
6949
  fromWebSocket: () => fromWebSocket,
6950
6950
  fromWebhook: () => fromWebhook,
6951
- gate: () => gate,
6952
6951
  globToRegExp: () => globToRegExp,
6953
6952
  interval: () => interval,
6954
6953
  last: () => last,
@@ -7027,6 +7026,7 @@ __export(extra_exports, {
7027
7026
  toWebSocket: () => toWebSocket,
7028
7027
  tokenBucket: () => tokenBucket,
7029
7028
  tokenTracker: () => tokenTracker,
7029
+ valve: () => valve,
7030
7030
  verifiable: () => verifiable,
7031
7031
  window: () => window,
7032
7032
  windowCount: () => windowCount,
@@ -11507,30 +11507,58 @@ function throttle(source, ms, opts) {
11507
11507
  );
11508
11508
  }
11509
11509
  function sample(source, notifier, opts) {
11510
+ let lastSourceValue = NO_VALUE;
11511
+ let terminated = false;
11512
+ let sourceCompleted = false;
11510
11513
  return node([source, notifier], () => void 0, {
11511
11514
  ...operatorOpts3(opts),
11512
11515
  completeWhenDepsComplete: false,
11516
+ onResubscribe: opts?.resubscribable === true ? () => {
11517
+ lastSourceValue = NO_VALUE;
11518
+ terminated = false;
11519
+ sourceCompleted = false;
11520
+ } : void 0,
11513
11521
  onMessage(msg, i, a) {
11522
+ if (terminated) return true;
11514
11523
  const t = msg[0];
11515
- if (t === ERROR) {
11524
+ const tier = messageTier(t);
11525
+ if (tier >= 3) {
11526
+ if (t === ERROR) {
11527
+ terminated = true;
11528
+ a.down([msg]);
11529
+ return true;
11530
+ }
11531
+ if (t === COMPLETE) {
11532
+ if (i === 0) {
11533
+ sourceCompleted = true;
11534
+ lastSourceValue = NO_VALUE;
11535
+ return true;
11536
+ }
11537
+ terminated = true;
11538
+ a.down([msg]);
11539
+ return true;
11540
+ }
11516
11541
  a.down([msg]);
11517
11542
  return true;
11518
11543
  }
11519
- if (t === COMPLETE) {
11544
+ if (i === 0) {
11545
+ if (t === DATA) {
11546
+ lastSourceValue = msg[1];
11547
+ return true;
11548
+ }
11549
+ if (t === DIRTY || t === RESOLVED) return true;
11520
11550
  a.down([msg]);
11521
11551
  return true;
11522
11552
  }
11523
- if (i === 1 && t === DATA) {
11524
- a.emit(source.get());
11525
- return true;
11526
- }
11527
- if (i === 1 && t === RESOLVED) {
11528
- return true;
11529
- }
11530
- if (i === 0) {
11553
+ if (t === DATA) {
11554
+ if (lastSourceValue !== NO_VALUE && !sourceCompleted) {
11555
+ a.emit(lastSourceValue);
11556
+ }
11531
11557
  return true;
11532
11558
  }
11533
- return false;
11559
+ if (t === RESOLVED) return true;
11560
+ a.down([msg]);
11561
+ return true;
11534
11562
  }
11535
11563
  });
11536
11564
  }
@@ -11997,7 +12025,7 @@ function rescue(source, recover, opts) {
11997
12025
  }
11998
12026
  });
11999
12027
  }
12000
- function gate(source, control, opts) {
12028
+ function valve(source, control, opts) {
12001
12029
  return node(
12002
12030
  [source, control],
12003
12031
  (_deps, a) => {
@@ -12963,6 +12991,7 @@ __export(ai_exports, {
12963
12991
  knobsAsTools: () => knobsAsTools,
12964
12992
  llmConsolidator: () => llmConsolidator,
12965
12993
  llmExtractor: () => llmExtractor,
12994
+ promptNode: () => promptNode,
12966
12995
  suggestStrategy: () => suggestStrategy,
12967
12996
  systemPromptBuilder: () => systemPromptBuilder,
12968
12997
  toolRegistry: () => toolRegistry,
@@ -13478,6 +13507,75 @@ function fromLLMStream(adapter, messages, opts) {
13478
13507
  }
13479
13508
  };
13480
13509
  }
13510
+ function extractContent(resp) {
13511
+ if (resp != null && typeof resp === "object" && "content" in resp) {
13512
+ return String(resp.content);
13513
+ }
13514
+ if (typeof resp === "string") return resp;
13515
+ return String(resp);
13516
+ }
13517
+ function promptNode(adapter, deps, prompt, opts) {
13518
+ const format = opts?.format ?? "text";
13519
+ const retries = opts?.retries ?? 0;
13520
+ const useCache = opts?.cache ?? false;
13521
+ const cache2 = useCache ? /* @__PURE__ */ new Map() : null;
13522
+ const messagesNode = derived(
13523
+ deps,
13524
+ (values) => {
13525
+ const text = typeof prompt === "string" ? prompt : prompt(...values);
13526
+ const msgs = [];
13527
+ if (opts?.systemPrompt) msgs.push({ role: "system", content: opts.systemPrompt });
13528
+ msgs.push({ role: "user", content: text });
13529
+ return msgs;
13530
+ },
13531
+ {
13532
+ name: opts?.name ? `${opts.name}::messages` : "prompt_node::messages",
13533
+ meta: aiMeta("prompt_node")
13534
+ }
13535
+ );
13536
+ const result = switchMap(messagesNode, (msgs) => {
13537
+ if (!msgs || msgs.length === 0) {
13538
+ return state(null);
13539
+ }
13540
+ const cacheKey = useCache ? JSON.stringify(msgs.map((m) => [m.role, m.content])) : "";
13541
+ if (cache2?.has(cacheKey)) {
13542
+ return state(cache2.get(cacheKey));
13543
+ }
13544
+ async function attempt(remaining) {
13545
+ try {
13546
+ const resp = await new Promise((resolve, reject) => {
13547
+ const input = adapter.invoke(msgs, {
13548
+ model: opts?.model,
13549
+ temperature: opts?.temperature,
13550
+ maxTokens: opts?.maxTokens,
13551
+ systemPrompt: opts?.systemPrompt
13552
+ });
13553
+ if (input && typeof input.then === "function") {
13554
+ input.then(resolve, reject);
13555
+ } else if (input && typeof input.get === "function") {
13556
+ resolve(input.get());
13557
+ } else {
13558
+ resolve(input);
13559
+ }
13560
+ });
13561
+ const content = extractContent(resp);
13562
+ let parsed;
13563
+ if (format === "json") {
13564
+ parsed = JSON.parse(stripFences(content));
13565
+ } else {
13566
+ parsed = content;
13567
+ }
13568
+ cache2?.set(cacheKey, parsed);
13569
+ return parsed;
13570
+ } catch (err) {
13571
+ if (remaining > 0) return attempt(remaining - 1);
13572
+ throw err;
13573
+ }
13574
+ }
13575
+ return attempt(retries);
13576
+ });
13577
+ return result;
13578
+ }
13481
13579
  var ChatStreamGraph = class extends Graph {
13482
13580
  _log;
13483
13581
  _keepaliveSubs = [];
@@ -17693,7 +17791,7 @@ __export(orchestration_exports, {
17693
17791
  approval: () => approval,
17694
17792
  branch: () => branch,
17695
17793
  forEach: () => forEach2,
17696
- gate: () => gate2,
17794
+ gate: () => gate,
17697
17795
  join: () => join2,
17698
17796
  loop: () => loop,
17699
17797
  onFailure: () => onFailure,
@@ -17701,6 +17799,7 @@ __export(orchestration_exports, {
17701
17799
  sensor: () => sensor,
17702
17800
  subPipeline: () => subPipeline,
17703
17801
  task: () => task,
17802
+ valve: () => valve2,
17704
17803
  wait: () => wait
17705
17804
  });
17706
17805
  function resolveDep(graph, dep) {
@@ -17800,7 +17899,7 @@ function branch(graph, name, source, predicate, opts) {
17800
17899
  registerStep(graph, name, step, src.path ? [src.path] : []);
17801
17900
  return step;
17802
17901
  }
17803
- function gate2(graph, name, source, control, opts) {
17902
+ function valve2(graph, name, source, control, opts) {
17804
17903
  const src = resolveDep(graph, source);
17805
17904
  const ctrl = resolveDep(graph, control);
17806
17905
  const step = node(
@@ -17817,7 +17916,7 @@ function gate2(graph, name, source, control, opts) {
17817
17916
  ...opts,
17818
17917
  name,
17819
17918
  describeKind: "operator",
17820
- meta: baseMeta3("gate", opts?.meta)
17919
+ meta: baseMeta3("valve", opts?.meta)
17821
17920
  }
17822
17921
  );
17823
17922
  registerStep(
@@ -17856,6 +17955,119 @@ function approval(graph, name, source, approver, opts) {
17856
17955
  );
17857
17956
  return step;
17858
17957
  }
17958
+ function gate(graph, name, source, opts) {
17959
+ const maxPending = opts?.maxPending ?? Infinity;
17960
+ if (maxPending < 1 && maxPending !== Infinity) {
17961
+ throw new RangeError("gate: maxPending must be >= 1");
17962
+ }
17963
+ const startOpen = opts?.startOpen ?? false;
17964
+ const src = resolveDep(graph, source);
17965
+ const pendingNode = state([], { name: "pending", equals: () => false });
17966
+ const isOpenNode = state(startOpen, { name: "isOpen" });
17967
+ const countNode = node([pendingNode], ([arr]) => arr.length, {
17968
+ name: "count",
17969
+ describeKind: "derived"
17970
+ });
17971
+ let queue = [];
17972
+ let torn = false;
17973
+ function syncPending() {
17974
+ pendingNode.down([[DATA, [...queue]]]);
17975
+ }
17976
+ function enqueue(value) {
17977
+ queue.push(value);
17978
+ if (queue.length > maxPending) queue.shift();
17979
+ syncPending();
17980
+ }
17981
+ function dequeue(n) {
17982
+ const items = queue.splice(0, n);
17983
+ syncPending();
17984
+ return items;
17985
+ }
17986
+ function guardTorn(method) {
17987
+ if (torn) throw new Error(`gate: ${method}() called after gate was torn down`);
17988
+ }
17989
+ const output = node([src.node], () => void 0, {
17990
+ name,
17991
+ describeKind: "operator",
17992
+ meta: baseMeta3("gate", opts?.meta),
17993
+ onMessage(msg, _depIndex, actions) {
17994
+ if (msg[0] === DATA) {
17995
+ if (isOpenNode.get()) {
17996
+ actions.emit(msg[1]);
17997
+ } else {
17998
+ enqueue(msg[1]);
17999
+ actions.down([[RESOLVED]]);
18000
+ }
18001
+ return true;
18002
+ }
18003
+ if (msg[0] === TEARDOWN) {
18004
+ torn = true;
18005
+ queue = [];
18006
+ syncPending();
18007
+ actions.down([msg]);
18008
+ return true;
18009
+ }
18010
+ if (msg[0] === COMPLETE || msg[0] === ERROR) {
18011
+ torn = true;
18012
+ queue = [];
18013
+ syncPending();
18014
+ actions.down([msg]);
18015
+ return true;
18016
+ }
18017
+ actions.down([msg]);
18018
+ return true;
18019
+ }
18020
+ });
18021
+ const controller = {
18022
+ node: output,
18023
+ pending: pendingNode,
18024
+ count: countNode,
18025
+ isOpen: isOpenNode,
18026
+ approve(count = 1) {
18027
+ guardTorn("approve");
18028
+ const items = dequeue(count);
18029
+ for (const item of items) {
18030
+ if (torn) break;
18031
+ output.down([[DATA, item]]);
18032
+ }
18033
+ },
18034
+ reject(count = 1) {
18035
+ guardTorn("reject");
18036
+ dequeue(count);
18037
+ },
18038
+ modify(fn, count = 1) {
18039
+ guardTorn("modify");
18040
+ const snapshot = [...queue];
18041
+ const items = dequeue(count);
18042
+ for (let i = 0; i < items.length; i++) {
18043
+ if (torn) break;
18044
+ output.down([[DATA, fn(items[i], i, snapshot)]]);
18045
+ }
18046
+ },
18047
+ open() {
18048
+ guardTorn("open");
18049
+ isOpenNode.down([[DATA, true]]);
18050
+ const items = dequeue(queue.length);
18051
+ for (const item of items) {
18052
+ if (torn) break;
18053
+ output.down([[DATA, item]]);
18054
+ }
18055
+ },
18056
+ close() {
18057
+ guardTorn("close");
18058
+ isOpenNode.down([[DATA, false]]);
18059
+ }
18060
+ };
18061
+ countNode.subscribe(() => void 0);
18062
+ registerStep(graph, name, output, src.path ? [src.path] : []);
18063
+ const internal = new Graph(`${name}_state`);
18064
+ internal.add("pending", pendingNode);
18065
+ internal.add("isOpen", isOpenNode);
18066
+ internal.add("count", countNode);
18067
+ internal.connect("pending", "count");
18068
+ graph.mount(`${name}_state`, internal);
18069
+ return controller;
18070
+ }
17859
18071
  function forEach2(graph, name, source, run, opts) {
17860
18072
  const src = resolveDep(graph, source);
17861
18073
  let terminated = false;
@@ -18675,7 +18887,6 @@ var version = "0.0.0";
18675
18887
  fromTimer,
18676
18888
  fromWebSocket,
18677
18889
  fromWebhook,
18678
- gate,
18679
18890
  globToRegExp,
18680
18891
  graph,
18681
18892
  graphspec,
@@ -18791,6 +19002,7 @@ var version = "0.0.0";
18791
19002
  toWebSocket,
18792
19003
  tokenBucket,
18793
19004
  tokenTracker,
19005
+ valve,
18794
19006
  verifiable,
18795
19007
  version,
18796
19008
  vue,