@graphrefly/graphrefly 0.11.0 → 0.13.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 (69) hide show
  1. package/dist/{chunk-FMVFRP7L.js → chunk-5RN7NBNG.js} +5 -5
  2. package/dist/{chunk-UG2QZMRN.js → chunk-6B2ZCCNN.js} +40 -39
  3. package/dist/chunk-6B2ZCCNN.js.map +1 -0
  4. package/dist/{chunk-2VHNCFGG.js → chunk-H4UFM6WD.js} +46 -17
  5. package/dist/chunk-H4UFM6WD.js.map +1 -0
  6. package/dist/{chunk-PZCDQD2U.js → chunk-HA6QMDKQ.js} +4 -4
  7. package/dist/{chunk-5WXTWOD7.js → chunk-KNGOJEYP.js} +2 -2
  8. package/dist/{chunk-OHUECHWY.js → chunk-PFMXKG4Y.js} +2 -2
  9. package/dist/{chunk-U5HFZGAQ.js → chunk-QOGWU5K7.js} +3 -3
  10. package/dist/{chunk-3WACHRHV.js → chunk-UPC5OEB5.js} +17 -17
  11. package/dist/chunk-UPC5OEB5.js.map +1 -0
  12. package/dist/{chunk-2OTXEZQO.js → chunk-UQI4GAHD.js} +3 -3
  13. package/dist/compat/nestjs/index.cjs +37 -37
  14. package/dist/compat/nestjs/index.cjs.map +1 -1
  15. package/dist/compat/nestjs/index.d.cts +4 -4
  16. package/dist/compat/nestjs/index.d.ts +4 -4
  17. package/dist/compat/nestjs/index.js +7 -7
  18. package/dist/core/index.cjs +39 -39
  19. package/dist/core/index.cjs.map +1 -1
  20. package/dist/core/index.d.cts +2 -2
  21. package/dist/core/index.d.ts +2 -2
  22. package/dist/core/index.js +5 -5
  23. package/dist/extra/index.cjs +79 -51
  24. package/dist/extra/index.cjs.map +1 -1
  25. package/dist/extra/index.d.cts +4 -4
  26. package/dist/extra/index.d.ts +4 -4
  27. package/dist/extra/index.js +5 -5
  28. package/dist/graph/index.cjs +37 -37
  29. package/dist/graph/index.cjs.map +1 -1
  30. package/dist/graph/index.d.cts +3 -3
  31. package/dist/graph/index.d.ts +3 -3
  32. package/dist/graph/index.js +4 -4
  33. package/dist/{graph-DXT95WZ3.d.ts → graph-BXIK5Dq5.d.ts} +1 -1
  34. package/dist/{graph-BE10ujU9.d.cts → graph-BhADtuFU.d.cts} +1 -1
  35. package/dist/{index-QfbXNW1N.d.cts → index-BNB0KjKe.d.ts} +24 -21
  36. package/dist/{index-C0_7g9sj.d.ts → index-BkToATim.d.ts} +1 -1
  37. package/dist/{index-Bbgvinsi.d.ts → index-CKyYg4IP.d.ts} +17 -13
  38. package/dist/{index-CCvzN5GB.d.cts → index-DANO9Gg7.d.cts} +2 -2
  39. package/dist/{index-DpZozxaJ.d.cts → index-DBhLjWSV.d.cts} +17 -13
  40. package/dist/{index-Dzdm20sx.d.ts → index-DKIyo4Bq.d.cts} +24 -21
  41. package/dist/{index-53cDGX7F.d.ts → index-DSp5R3Xq.d.ts} +3 -3
  42. package/dist/{index-aBZ2RoP0.d.cts → index-Dqemj9q0.d.cts} +3 -3
  43. package/dist/{index-nRulwTr-.d.cts → index-Wa8jXne6.d.cts} +1 -1
  44. package/dist/{index-B10Q0sQB.d.ts → index-fYObbpUw.d.ts} +2 -2
  45. package/dist/index.cjs +283 -71
  46. package/dist/index.cjs.map +1 -1
  47. package/dist/index.d.cts +85 -15
  48. package/dist/index.d.ts +85 -15
  49. package/dist/index.js +200 -16
  50. package/dist/index.js.map +1 -1
  51. package/dist/{meta-BcuDhtwu.d.cts → meta-CrZUQAJ6.d.cts} +1 -1
  52. package/dist/{meta-BcuDhtwu.d.ts → meta-CrZUQAJ6.d.ts} +1 -1
  53. package/dist/patterns/reactive-layout/index.cjs +50 -50
  54. package/dist/patterns/reactive-layout/index.cjs.map +1 -1
  55. package/dist/patterns/reactive-layout/index.d.cts +3 -3
  56. package/dist/patterns/reactive-layout/index.d.ts +3 -3
  57. package/dist/patterns/reactive-layout/index.js +4 -4
  58. package/dist/{reactive-log-OULQssZg.d.cts → reactive-log-ChbpUrY2.d.cts} +2 -2
  59. package/dist/{reactive-log-Cu0VdqkT.d.ts → reactive-log-DV--7BWd.d.ts} +2 -2
  60. package/package.json +1 -1
  61. package/dist/chunk-2VHNCFGG.js.map +0 -1
  62. package/dist/chunk-3WACHRHV.js.map +0 -1
  63. package/dist/chunk-UG2QZMRN.js.map +0 -1
  64. /package/dist/{chunk-FMVFRP7L.js.map → chunk-5RN7NBNG.js.map} +0 -0
  65. /package/dist/{chunk-PZCDQD2U.js.map → chunk-HA6QMDKQ.js.map} +0 -0
  66. /package/dist/{chunk-5WXTWOD7.js.map → chunk-KNGOJEYP.js.map} +0 -0
  67. /package/dist/{chunk-OHUECHWY.js.map → chunk-PFMXKG4Y.js.map} +0 -0
  68. /package/dist/{chunk-U5HFZGAQ.js.map → chunk-QOGWU5K7.js.map} +0 -0
  69. /package/dist/{chunk-2OTXEZQO.js.map → chunk-UQI4GAHD.js.map} +0 -0
package/dist/index.js CHANGED
@@ -64,7 +64,6 @@ import {
64
64
  fromSyslog,
65
65
  fromWebSocket,
66
66
  fromWebhook,
67
- gate,
68
67
  interval,
69
68
  last,
70
69
  linear,
@@ -126,6 +125,7 @@ import {
126
125
  toWebSocket,
127
126
  tokenBucket,
128
127
  tokenTracker,
128
+ valve,
129
129
  verifiable,
130
130
  window,
131
131
  windowCount,
@@ -137,16 +137,16 @@ import {
137
137
  workerBridge,
138
138
  workerSelf,
139
139
  zip
140
- } from "./chunk-2VHNCFGG.js";
140
+ } from "./chunk-H4UFM6WD.js";
141
141
  import {
142
142
  cqrs_exports,
143
143
  nestjs_exports
144
- } from "./chunk-PZCDQD2U.js";
144
+ } from "./chunk-HA6QMDKQ.js";
145
145
  import {
146
146
  DEFAULT_DOWN,
147
147
  bridge,
148
148
  core_exports
149
- } from "./chunk-FMVFRP7L.js";
149
+ } from "./chunk-5RN7NBNG.js";
150
150
  import {
151
151
  JsonCodec,
152
152
  createDagCborCodec,
@@ -154,7 +154,7 @@ import {
154
154
  graph_exports,
155
155
  negotiateCodec,
156
156
  replayWAL
157
- } from "./chunk-U5HFZGAQ.js";
157
+ } from "./chunk-QOGWU5K7.js";
158
158
  import {
159
159
  cached,
160
160
  createWatermarkController,
@@ -187,7 +187,7 @@ import {
187
187
  toArray,
188
188
  toMessages$,
189
189
  toObservable
190
- } from "./chunk-5WXTWOD7.js";
190
+ } from "./chunk-KNGOJEYP.js";
191
191
  import {
192
192
  ResettableTimer
193
193
  } from "./chunk-WZ2Z2CRV.js";
@@ -195,17 +195,17 @@ import {
195
195
  analyzeAndMeasure,
196
196
  computeLineBreaks,
197
197
  reactive_layout_exports
198
- } from "./chunk-3WACHRHV.js";
198
+ } from "./chunk-UPC5OEB5.js";
199
199
  import {
200
200
  GRAPH_META_SEGMENT,
201
201
  Graph,
202
202
  reachable
203
- } from "./chunk-2OTXEZQO.js";
203
+ } from "./chunk-UQI4GAHD.js";
204
204
  import {
205
205
  describeNode,
206
206
  metaSnapshot,
207
207
  resolveDescribeFields
208
- } from "./chunk-OHUECHWY.js";
208
+ } from "./chunk-PFMXKG4Y.js";
209
209
  import {
210
210
  CLEANUP_RESULT,
211
211
  COMPLETE,
@@ -228,9 +228,9 @@ import {
228
228
  createVersioning,
229
229
  defaultHash,
230
230
  derived,
231
+ downWithBatch,
231
232
  dynamicNode,
232
233
  effect,
233
- emitWithBatch,
234
234
  isBatching,
235
235
  isKnownMessageType,
236
236
  isPhase2Message,
@@ -249,7 +249,7 @@ import {
249
249
  propagatesToMeta,
250
250
  state,
251
251
  wallClockNs
252
- } from "./chunk-UG2QZMRN.js";
252
+ } from "./chunk-6B2ZCCNN.js";
253
253
 
254
254
  // src/compat/index.ts
255
255
  var compat_exports = {};
@@ -1075,6 +1075,7 @@ __export(ai_exports, {
1075
1075
  knobsAsTools: () => knobsAsTools,
1076
1076
  llmConsolidator: () => llmConsolidator,
1077
1077
  llmExtractor: () => llmExtractor,
1078
+ promptNode: () => promptNode,
1078
1079
  suggestStrategy: () => suggestStrategy,
1079
1080
  systemPromptBuilder: () => systemPromptBuilder,
1080
1081
  toolRegistry: () => toolRegistry,
@@ -1590,6 +1591,75 @@ function fromLLMStream(adapter, messages, opts) {
1590
1591
  }
1591
1592
  };
1592
1593
  }
1594
+ function extractContent(resp) {
1595
+ if (resp != null && typeof resp === "object" && "content" in resp) {
1596
+ return String(resp.content);
1597
+ }
1598
+ if (typeof resp === "string") return resp;
1599
+ return String(resp);
1600
+ }
1601
+ function promptNode(adapter, deps, prompt, opts) {
1602
+ const format = opts?.format ?? "text";
1603
+ const retries = opts?.retries ?? 0;
1604
+ const useCache = opts?.cache ?? false;
1605
+ const cache2 = useCache ? /* @__PURE__ */ new Map() : null;
1606
+ const messagesNode = derived(
1607
+ deps,
1608
+ (values) => {
1609
+ const text = typeof prompt === "string" ? prompt : prompt(...values);
1610
+ const msgs = [];
1611
+ if (opts?.systemPrompt) msgs.push({ role: "system", content: opts.systemPrompt });
1612
+ msgs.push({ role: "user", content: text });
1613
+ return msgs;
1614
+ },
1615
+ {
1616
+ name: opts?.name ? `${opts.name}::messages` : "prompt_node::messages",
1617
+ meta: aiMeta("prompt_node")
1618
+ }
1619
+ );
1620
+ const result = switchMap(messagesNode, (msgs) => {
1621
+ if (!msgs || msgs.length === 0) {
1622
+ return state(null);
1623
+ }
1624
+ const cacheKey = useCache ? JSON.stringify(msgs.map((m) => [m.role, m.content])) : "";
1625
+ if (cache2?.has(cacheKey)) {
1626
+ return state(cache2.get(cacheKey));
1627
+ }
1628
+ async function attempt(remaining) {
1629
+ try {
1630
+ const resp = await new Promise((resolve, reject) => {
1631
+ const input = adapter.invoke(msgs, {
1632
+ model: opts?.model,
1633
+ temperature: opts?.temperature,
1634
+ maxTokens: opts?.maxTokens,
1635
+ systemPrompt: opts?.systemPrompt
1636
+ });
1637
+ if (input && typeof input.then === "function") {
1638
+ input.then(resolve, reject);
1639
+ } else if (input && typeof input.get === "function") {
1640
+ resolve(input.get());
1641
+ } else {
1642
+ resolve(input);
1643
+ }
1644
+ });
1645
+ const content = extractContent(resp);
1646
+ let parsed;
1647
+ if (format === "json") {
1648
+ parsed = JSON.parse(stripFences(content));
1649
+ } else {
1650
+ parsed = content;
1651
+ }
1652
+ cache2?.set(cacheKey, parsed);
1653
+ return parsed;
1654
+ } catch (err) {
1655
+ if (remaining > 0) return attempt(remaining - 1);
1656
+ throw err;
1657
+ }
1658
+ }
1659
+ return attempt(retries);
1660
+ });
1661
+ return result;
1662
+ }
1593
1663
  var ChatStreamGraph = class extends Graph {
1594
1664
  _log;
1595
1665
  _keepaliveSubs = [];
@@ -5229,7 +5299,7 @@ __export(orchestration_exports, {
5229
5299
  approval: () => approval,
5230
5300
  branch: () => branch,
5231
5301
  forEach: () => forEach2,
5232
- gate: () => gate2,
5302
+ gate: () => gate,
5233
5303
  join: () => join,
5234
5304
  loop: () => loop,
5235
5305
  onFailure: () => onFailure,
@@ -5237,6 +5307,7 @@ __export(orchestration_exports, {
5237
5307
  sensor: () => sensor,
5238
5308
  subPipeline: () => subPipeline,
5239
5309
  task: () => task,
5310
+ valve: () => valve2,
5240
5311
  wait: () => wait
5241
5312
  });
5242
5313
  function resolveDep(graph, dep) {
@@ -5336,7 +5407,7 @@ function branch(graph, name, source, predicate, opts) {
5336
5407
  registerStep(graph, name, step, src.path ? [src.path] : []);
5337
5408
  return step;
5338
5409
  }
5339
- function gate2(graph, name, source, control, opts) {
5410
+ function valve2(graph, name, source, control, opts) {
5340
5411
  const src = resolveDep(graph, source);
5341
5412
  const ctrl = resolveDep(graph, control);
5342
5413
  const step = node(
@@ -5353,7 +5424,7 @@ function gate2(graph, name, source, control, opts) {
5353
5424
  ...opts,
5354
5425
  name,
5355
5426
  describeKind: "operator",
5356
- meta: baseMeta3("gate", opts?.meta)
5427
+ meta: baseMeta3("valve", opts?.meta)
5357
5428
  }
5358
5429
  );
5359
5430
  registerStep(
@@ -5392,6 +5463,119 @@ function approval(graph, name, source, approver, opts) {
5392
5463
  );
5393
5464
  return step;
5394
5465
  }
5466
+ function gate(graph, name, source, opts) {
5467
+ const maxPending = opts?.maxPending ?? Infinity;
5468
+ if (maxPending < 1 && maxPending !== Infinity) {
5469
+ throw new RangeError("gate: maxPending must be >= 1");
5470
+ }
5471
+ const startOpen = opts?.startOpen ?? false;
5472
+ const src = resolveDep(graph, source);
5473
+ const pendingNode = state([], { name: "pending", equals: () => false });
5474
+ const isOpenNode = state(startOpen, { name: "isOpen" });
5475
+ const countNode = node([pendingNode], ([arr]) => arr.length, {
5476
+ name: "count",
5477
+ describeKind: "derived"
5478
+ });
5479
+ let queue = [];
5480
+ let torn = false;
5481
+ function syncPending() {
5482
+ pendingNode.down([[DATA, [...queue]]]);
5483
+ }
5484
+ function enqueue(value) {
5485
+ queue.push(value);
5486
+ if (queue.length > maxPending) queue.shift();
5487
+ syncPending();
5488
+ }
5489
+ function dequeue(n) {
5490
+ const items = queue.splice(0, n);
5491
+ syncPending();
5492
+ return items;
5493
+ }
5494
+ function guardTorn(method) {
5495
+ if (torn) throw new Error(`gate: ${method}() called after gate was torn down`);
5496
+ }
5497
+ const output = node([src.node], () => void 0, {
5498
+ name,
5499
+ describeKind: "operator",
5500
+ meta: baseMeta3("gate", opts?.meta),
5501
+ onMessage(msg, _depIndex, actions) {
5502
+ if (msg[0] === DATA) {
5503
+ if (isOpenNode.get()) {
5504
+ actions.emit(msg[1]);
5505
+ } else {
5506
+ enqueue(msg[1]);
5507
+ actions.down([[RESOLVED]]);
5508
+ }
5509
+ return true;
5510
+ }
5511
+ if (msg[0] === TEARDOWN) {
5512
+ torn = true;
5513
+ queue = [];
5514
+ syncPending();
5515
+ actions.down([msg]);
5516
+ return true;
5517
+ }
5518
+ if (msg[0] === COMPLETE || msg[0] === ERROR) {
5519
+ torn = true;
5520
+ queue = [];
5521
+ syncPending();
5522
+ actions.down([msg]);
5523
+ return true;
5524
+ }
5525
+ actions.down([msg]);
5526
+ return true;
5527
+ }
5528
+ });
5529
+ const controller = {
5530
+ node: output,
5531
+ pending: pendingNode,
5532
+ count: countNode,
5533
+ isOpen: isOpenNode,
5534
+ approve(count = 1) {
5535
+ guardTorn("approve");
5536
+ const items = dequeue(count);
5537
+ for (const item of items) {
5538
+ if (torn) break;
5539
+ output.down([[DATA, item]]);
5540
+ }
5541
+ },
5542
+ reject(count = 1) {
5543
+ guardTorn("reject");
5544
+ dequeue(count);
5545
+ },
5546
+ modify(fn, count = 1) {
5547
+ guardTorn("modify");
5548
+ const snapshot = [...queue];
5549
+ const items = dequeue(count);
5550
+ for (let i = 0; i < items.length; i++) {
5551
+ if (torn) break;
5552
+ output.down([[DATA, fn(items[i], i, snapshot)]]);
5553
+ }
5554
+ },
5555
+ open() {
5556
+ guardTorn("open");
5557
+ isOpenNode.down([[DATA, true]]);
5558
+ const items = dequeue(queue.length);
5559
+ for (const item of items) {
5560
+ if (torn) break;
5561
+ output.down([[DATA, item]]);
5562
+ }
5563
+ },
5564
+ close() {
5565
+ guardTorn("close");
5566
+ isOpenNode.down([[DATA, false]]);
5567
+ }
5568
+ };
5569
+ countNode.subscribe(() => void 0);
5570
+ registerStep(graph, name, output, src.path ? [src.path] : []);
5571
+ const internal = new Graph(`${name}_state`);
5572
+ internal.add("pending", pendingNode);
5573
+ internal.add("isOpen", isOpenNode);
5574
+ internal.add("count", countNode);
5575
+ internal.connect("pending", "count");
5576
+ graph.mount(`${name}_state`, internal);
5577
+ return controller;
5578
+ }
5395
5579
  function forEach2(graph, name, source, run, opts) {
5396
5580
  const src = resolveDep(graph, source);
5397
5581
  let terminated = false;
@@ -5672,10 +5856,10 @@ export {
5672
5856
  distill,
5673
5857
  distinctUntilChanged,
5674
5858
  domain_templates_exports as domainTemplates,
5859
+ downWithBatch,
5675
5860
  dynamicNode,
5676
5861
  effect,
5677
5862
  elementAt,
5678
- emitWithBatch,
5679
5863
  empty,
5680
5864
  escapeRegexChar,
5681
5865
  exhaustMap,
@@ -5720,7 +5904,6 @@ export {
5720
5904
  fromTimer,
5721
5905
  fromWebSocket,
5722
5906
  fromWebhook,
5723
- gate,
5724
5907
  globToRegExp,
5725
5908
  graph_exports as graph,
5726
5909
  graphspec_exports as graphspec,
@@ -5836,6 +6019,7 @@ export {
5836
6019
  toWebSocket,
5837
6020
  tokenBucket,
5838
6021
  tokenTracker,
6022
+ valve,
5839
6023
  verifiable,
5840
6024
  version,
5841
6025
  vue_exports as vue,