@agentscope-ai/flow 0.0.1

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 (176) hide show
  1. package/README.zh-CN.md +67 -0
  2. package/dist/components/base-node/index.d.ts +27 -0
  3. package/dist/components/base-node/index.js +320 -0
  4. package/dist/components/base-node/index.less +258 -0
  5. package/dist/components/branch-title-header/index.d.ts +12 -0
  6. package/dist/components/branch-title-header/index.js +176 -0
  7. package/dist/components/branch-title-header/index.less +28 -0
  8. package/dist/components/check-list-btn/index.d.ts +4 -0
  9. package/dist/components/check-list-btn/index.js +144 -0
  10. package/dist/components/check-list-btn/index.less +113 -0
  11. package/dist/components/code-input/index.d.ts +24 -0
  12. package/dist/components/code-input/index.js +356 -0
  13. package/dist/components/code-input/index.less +87 -0
  14. package/dist/components/condition-item/index.d.ts +13 -0
  15. package/dist/components/condition-item/index.js +185 -0
  16. package/dist/components/condition-item/index.less +23 -0
  17. package/dist/components/custom-connection-line/index.d.ts +4 -0
  18. package/dist/components/custom-connection-line/index.js +28 -0
  19. package/dist/components/custom-handle/source-handle.d.ts +10 -0
  20. package/dist/components/custom-handle/source-handle.js +45 -0
  21. package/dist/components/custom-handle/target-handle.d.ts +6 -0
  22. package/dist/components/custom-handle/target-handle.js +21 -0
  23. package/dist/components/custom-inputs-control/index.d.ts +56 -0
  24. package/dist/components/custom-inputs-control/index.js +366 -0
  25. package/dist/components/custom-inputs-control/index.less +28 -0
  26. package/dist/components/custom-outputs-form/index.d.ts +24 -0
  27. package/dist/components/custom-outputs-form/index.js +346 -0
  28. package/dist/components/custom-outputs-form/index.less +51 -0
  29. package/dist/components/drag-panel/index.d.ts +10 -0
  30. package/dist/components/drag-panel/index.js +79 -0
  31. package/dist/components/drag-panel/index.less +23 -0
  32. package/dist/components/draggable-with-handle/index.d.ts +13 -0
  33. package/dist/components/draggable-with-handle/index.js +81 -0
  34. package/dist/components/draggable-with-handle/index.less +23 -0
  35. package/dist/components/flow-aside/index.d.ts +4 -0
  36. package/dist/components/flow-aside/index.js +62 -0
  37. package/dist/components/flow-aside/index.less +84 -0
  38. package/dist/components/flow-base-edge/index.d.ts +5 -0
  39. package/dist/components/flow-base-edge/index.js +226 -0
  40. package/dist/components/flow-base-edge/index.less +28 -0
  41. package/dist/components/flow-base-edge/linear-gradient-svg.d.ts +21 -0
  42. package/dist/components/flow-base-edge/linear-gradient-svg.js +32 -0
  43. package/dist/components/flow-icon/index.d.ts +9 -0
  44. package/dist/components/flow-icon/index.js +30 -0
  45. package/dist/components/flow-icon/index.less +20 -0
  46. package/dist/components/flow-mini-map/index.d.ts +4 -0
  47. package/dist/components/flow-mini-map/index.js +26 -0
  48. package/dist/components/flow-mini-map/index.less +22 -0
  49. package/dist/components/flow-panel/config-panel.d.ts +15 -0
  50. package/dist/components/flow-panel/config-panel.js +303 -0
  51. package/dist/components/flow-panel/index.d.ts +7 -0
  52. package/dist/components/flow-panel/index.js +7 -0
  53. package/dist/components/flow-panel/index.less +85 -0
  54. package/dist/components/flow-panel/panel-container.d.ts +12 -0
  55. package/dist/components/flow-panel/panel-container.js +25 -0
  56. package/dist/components/flow-tools/add-node-btn.d.ts +3 -0
  57. package/dist/components/flow-tools/add-node-btn.js +26 -0
  58. package/dist/components/flow-tools/history-btn.d.ts +3 -0
  59. package/dist/components/flow-tools/history-btn.js +59 -0
  60. package/dist/components/flow-tools/index.d.ts +4 -0
  61. package/dist/components/flow-tools/index.js +29 -0
  62. package/dist/components/flow-tools/index.less +82 -0
  63. package/dist/components/flow-tools/layout-btn.d.ts +3 -0
  64. package/dist/components/flow-tools/layout-btn.js +27 -0
  65. package/dist/components/flow-tools/mini-map-btn.d.ts +3 -0
  66. package/dist/components/flow-tools/mini-map-btn.js +32 -0
  67. package/dist/components/flow-tools/scale-btn.d.ts +3 -0
  68. package/dist/components/flow-tools/scale-btn.js +101 -0
  69. package/dist/components/flow-tools/short-key-btn.d.ts +3 -0
  70. package/dist/components/flow-tools/short-key-btn.js +38 -0
  71. package/dist/components/flow-tools/short-key-content.d.ts +4 -0
  72. package/dist/components/flow-tools/short-key-content.js +153 -0
  73. package/dist/components/flow-tools/short-key-content.less +38 -0
  74. package/dist/components/flow-tools/touch-mode-btn.d.ts +3 -0
  75. package/dist/components/flow-tools/touch-mode-btn.js +89 -0
  76. package/dist/components/input-text-area/index.d.ts +16 -0
  77. package/dist/components/input-text-area/index.js +74 -0
  78. package/dist/components/input-text-area/index.less +30 -0
  79. package/dist/components/judge-form/index.d.ts +13 -0
  80. package/dist/components/judge-form/index.js +182 -0
  81. package/dist/components/judge-form/index.less +11 -0
  82. package/dist/components/node-menu/index.d.ts +35 -0
  83. package/dist/components/node-menu/index.js +266 -0
  84. package/dist/components/node-menu/index.less +79 -0
  85. package/dist/components/node-resizer/index.d.ts +11 -0
  86. package/dist/components/node-resizer/index.js +46 -0
  87. package/dist/components/node-resizer/index.less +12 -0
  88. package/dist/components/node-result-panel/index.d.ts +9 -0
  89. package/dist/components/node-result-panel/index.js +155 -0
  90. package/dist/components/node-result-panel/index.less +132 -0
  91. package/dist/components/node-tree/index.d.ts +4 -0
  92. package/dist/components/node-tree/index.js +213 -0
  93. package/dist/components/node-tree/index.less +51 -0
  94. package/dist/components/output-params-tree/index.d.ts +10 -0
  95. package/dist/components/output-params-tree/index.js +34 -0
  96. package/dist/components/output-params-tree/index.less +27 -0
  97. package/dist/components/script-code-mirror/index.d.ts +14 -0
  98. package/dist/components/script-code-mirror/index.js +162 -0
  99. package/dist/components/script-code-mirror/index.less +11 -0
  100. package/dist/components/script-edit-modal/index.d.ts +30 -0
  101. package/dist/components/script-edit-modal/index.js +84 -0
  102. package/dist/components/script-edit-modal/index.less +24 -0
  103. package/dist/components/select-with-desc/index.d.ts +5 -0
  104. package/dist/components/select-with-desc/index.js +20 -0
  105. package/dist/components/select-with-desc/index.less +11 -0
  106. package/dist/components/task-status/index.d.ts +4 -0
  107. package/dist/components/task-status/index.js +209 -0
  108. package/dist/components/task-status/index.less +65 -0
  109. package/dist/components/var-input-text-area/index.d.ts +17 -0
  110. package/dist/components/var-input-text-area/index.js +211 -0
  111. package/dist/components/var-input-text-area/index.less +64 -0
  112. package/dist/components/var-type-prefix/index.d.ts +17 -0
  113. package/dist/components/var-type-prefix/index.js +21 -0
  114. package/dist/components/variable-input/index.d.ts +24 -0
  115. package/dist/components/variable-input/index.js +163 -0
  116. package/dist/components/variable-input/index.less +13 -0
  117. package/dist/components/variable-tree-select/index.d.ts +33 -0
  118. package/dist/components/variable-tree-select/index.js +160 -0
  119. package/dist/components/variable-tree-select/index.less +61 -0
  120. package/dist/constant/index.d.ts +61 -0
  121. package/dist/constant/index.js +515 -0
  122. package/dist/flow/animate.css +5 -0
  123. package/dist/flow/context.d.ts +12 -0
  124. package/dist/flow/context.js +44 -0
  125. package/dist/flow/index.d.ts +13 -0
  126. package/dist/flow/index.js +162 -0
  127. package/dist/flow/index.less +72 -0
  128. package/dist/hooks/index.d.ts +10 -0
  129. package/dist/hooks/index.js +10 -0
  130. package/dist/hooks/use-edges-interaction.d.ts +11 -0
  131. package/dist/hooks/use-edges-interaction.js +125 -0
  132. package/dist/hooks/use-flow-debug-interaction.d.ts +5 -0
  133. package/dist/hooks/use-flow-debug-interaction.js +23 -0
  134. package/dist/hooks/use-flow-interaction.d.ts +12 -0
  135. package/dist/hooks/use-flow-interaction.js +173 -0
  136. package/dist/hooks/use-flow-key-press.d.ts +1 -0
  137. package/dist/hooks/use-flow-key-press.js +32 -0
  138. package/dist/hooks/use-flow-save.d.ts +5 -0
  139. package/dist/hooks/use-flow-save.js +47 -0
  140. package/dist/hooks/use-flow-view-port.d.ts +7 -0
  141. package/dist/hooks/use-flow-view-port.js +46 -0
  142. package/dist/hooks/use-history.d.ts +21 -0
  143. package/dist/hooks/use-history.js +80 -0
  144. package/dist/hooks/use-nodes-interaction.d.ts +34 -0
  145. package/dist/hooks/use-nodes-interaction.js +777 -0
  146. package/dist/hooks/use-nodes-output-params.d.ts +31 -0
  147. package/dist/hooks/use-nodes-output-params.js +300 -0
  148. package/dist/hooks/use-nodes-update.d.ts +9 -0
  149. package/dist/hooks/use-nodes-update.js +38 -0
  150. package/dist/hooks/use-work-flow.d.ts +4 -0
  151. package/dist/hooks/use-work-flow.js +21 -0
  152. package/dist/i18n/i18n.d.ts +62 -0
  153. package/dist/i18n/i18n.js +111 -0
  154. package/dist/i18n/index.d.ts +3 -0
  155. package/dist/i18n/index.js +12 -0
  156. package/dist/i18n/locales/en-us.json +327 -0
  157. package/dist/i18n/locales/ja-jp.json +300 -0
  158. package/dist/i18n/locales/zh-cn.json +327 -0
  159. package/dist/index.css +1 -0
  160. package/dist/index.d.ts +47 -0
  161. package/dist/index.js +47 -0
  162. package/dist/index.less +1 -0
  163. package/dist/store/index.d.ts +70 -0
  164. package/dist/store/index.js +146 -0
  165. package/dist/tailwind.css +28 -0
  166. package/dist/types/work-flow.d.ts +188 -0
  167. package/dist/types/work-flow.js +1 -0
  168. package/dist/utils/default-values.d.ts +2 -0
  169. package/dist/utils/default-values.js +16 -0
  170. package/dist/utils/index.d.ts +39 -0
  171. package/dist/utils/index.js +273 -0
  172. package/dist/utils/unique-id.d.ts +2 -0
  173. package/dist/utils/unique-id.js +39 -0
  174. package/dist/utils/work-flow.d.ts +17 -0
  175. package/dist/utils/work-flow.js +44 -0
  176. package/package.json +78 -0
@@ -0,0 +1,273 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
+ import { ITERATION_PADDING, NEW_NODE_PADDING } from "../constant";
11
+ import i18n from "../i18n";
12
+ import ELK from 'elkjs/lib/elk.bundled.js';
13
+ import { cloneDeep } from 'lodash-es';
14
+ import uniqueId from "./unique-id";
15
+ export var generateEdge = function generateEdge(connection) {
16
+ var isParent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
17
+ var source = connection.source,
18
+ sourceHandle = connection.sourceHandle,
19
+ target = connection.target,
20
+ targetHandle = connection.targetHandle;
21
+ return {
22
+ id: "".concat(source, "-").concat(sourceHandle, "-").concat(target, "-").concat(targetHandle),
23
+ type: 'default',
24
+ source: source,
25
+ target: target,
26
+ sourceHandle: sourceHandle,
27
+ targetHandle: targetHandle,
28
+ zIndex: isParent ? 1002 : 0,
29
+ data: {}
30
+ };
31
+ };
32
+ export function splitAtFirstDigit(str) {
33
+ var match = str.match(/\d/); // 找到第一个数字字符
34
+ if (!match) {
35
+ // 如果没有数字,返回原字符串和空字符串
36
+ return [str, ''];
37
+ }
38
+ var index = match.index; // 第一个数字的索引
39
+ var part1 = str.slice(0, index); // 第一个数字之前的部分(不包含数字)
40
+ var part2 = str.slice(index); // 从第一个数字开始到结尾(包含数字)
41
+
42
+ return [part1, part2];
43
+ }
44
+ export var generateUniqueName = function generateUniqueName(name, names) {
45
+ var existingNames = new Set(names);
46
+ var index = 1;
47
+ var oldLabel = splitAtFirstDigit(name)[0];
48
+ var uniqueName = "".concat(oldLabel).concat(index);
49
+ while (existingNames.has(uniqueName)) {
50
+ ++index;
51
+ uniqueName = "".concat(oldLabel).concat(index);
52
+ }
53
+ return uniqueName;
54
+ };
55
+ export var getTypeFromId = function getTypeFromId(source) {
56
+ if (!source) return '';
57
+ var parts = source.split('_');
58
+ return parts[0] || '';
59
+ };
60
+ export function isMacOS() {
61
+ var _navigator = navigator,
62
+ userAgent = _navigator.userAgent;
63
+ var isMac = /Macintosh|MacIntel|MacPPC|Mac68K/.test(userAgent);
64
+ return isMac;
65
+ }
66
+ export var MAC_KEY_MAP = {
67
+ ctrl: 'meta'
68
+ };
69
+ export function transformToMacKey(key) {
70
+ if (isMacOS()) {
71
+ return MAC_KEY_MAP[key];
72
+ }
73
+ return key;
74
+ }
75
+ export function extractVariables(text) {
76
+ var saveFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
77
+ var regex = /\${(.*?)}/g;
78
+ var matches = text.match(regex);
79
+ var variableObj = {};
80
+ matches === null || matches === void 0 || matches.forEach(function (match) {
81
+ var key = saveFormat ? match : match.substring(2, match.length - 1);
82
+ if (variableObj[key]) return;
83
+ variableObj[key] = 1;
84
+ return match.substring(2, match.length - 1);
85
+ });
86
+ return Object.keys(variableObj);
87
+ }
88
+ export var getIteratorNodeSize = function getIteratorNodeSize(childrenNodes) {
89
+ var _measured;
90
+ var rightNode = null;
91
+ var bottomNode = null;
92
+ childrenNodes.forEach(function (n) {
93
+ if (rightNode) {
94
+ if (n.position.x + n.width > rightNode.position.x + rightNode.width) rightNode = n;
95
+ } else {
96
+ rightNode = n;
97
+ }
98
+ if (bottomNode) {
99
+ var _n$measured, _bottomNode$measured;
100
+ if (n.position.y + (((_n$measured = n.measured) === null || _n$measured === void 0 ? void 0 : _n$measured.height) || n.height) > bottomNode.position.y + (((_bottomNode$measured = bottomNode.measured) === null || _bottomNode$measured === void 0 ? void 0 : _bottomNode$measured.height) || bottomNode.height)) bottomNode = n;
101
+ } else {
102
+ bottomNode = n;
103
+ }
104
+ });
105
+ var newWidth = rightNode ? rightNode.position.x + ITERATION_PADDING.right + (rightNode.width || 0) : 0;
106
+ var newHeight = bottomNode ? bottomNode.position.y + ITERATION_PADDING.bottom + (((_measured = bottomNode.measured) === null || _measured === void 0 ? void 0 : _measured.height) || bottomNode.height || 0) : 0;
107
+ return {
108
+ width: newWidth > 640 ? newWidth : 640,
109
+ height: newHeight > 400 ? newHeight : 400
110
+ };
111
+ };
112
+ var LAYOUT_OPTIONS = {
113
+ 'elk.algorithm': 'layered',
114
+ 'elk.layered.spacing.nodeNodeBetweenLayers': '150',
115
+ 'elk.spacing.nodeNode': '150',
116
+ 'elk.layered.nodePlacement.strategy': 'SIMPLE'
117
+ };
118
+ export var layoutFlow = /*#__PURE__*/function () {
119
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
120
+ var nodes, edges, isSubFlow, elk, graph, layoutedGraph, commonDistanceHeight, commonDistantWidth, _layoutedGraph$childr, _layoutedGraph$childr2, topNode, leftNode, layoutedNodes;
121
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
122
+ while (1) switch (_context.prev = _context.next) {
123
+ case 0:
124
+ nodes = _ref.nodes, edges = _ref.edges, isSubFlow = _ref.isSubFlow;
125
+ elk = new ELK();
126
+ graph = {
127
+ id: 'root',
128
+ layoutOptions: LAYOUT_OPTIONS,
129
+ children: nodes.map(function (n) {
130
+ var _n$measured$width, _n$measured2, _n$measured$height, _n$measured3;
131
+ var targetPorts = [];
132
+ var sourcePorts = [];
133
+ edges.forEach(function (edgeItem) {
134
+ if (edgeItem.target === n.id) targetPorts.push({
135
+ id: edgeItem.targetHandle,
136
+ properties: {
137
+ side: 'WEST'
138
+ }
139
+ });
140
+ if (edgeItem.source === n.id) sourcePorts.push({
141
+ id: edgeItem.sourceHandle,
142
+ properties: {
143
+ side: 'EAST'
144
+ }
145
+ });
146
+ });
147
+ return _objectSpread(_objectSpread({}, n), {}, {
148
+ width: (_n$measured$width = (_n$measured2 = n.measured) === null || _n$measured2 === void 0 ? void 0 : _n$measured2.width) !== null && _n$measured$width !== void 0 ? _n$measured$width : 320,
149
+ height: (_n$measured$height = (_n$measured3 = n.measured) === null || _n$measured3 === void 0 ? void 0 : _n$measured3.height) !== null && _n$measured$height !== void 0 ? _n$measured$height : 58,
150
+ targetPosition: 'left',
151
+ sourcePosition: 'right',
152
+ properties: {
153
+ 'org.eclipse.elk.portConstraints': 'FIXED_ORDER'
154
+ },
155
+ ports: [{
156
+ id: n.id
157
+ }].concat(targetPorts, sourcePorts)
158
+ });
159
+ }),
160
+ edges: cloneDeep(edges)
161
+ };
162
+ _context.next = 5;
163
+ return elk.layout(graph);
164
+ case 5:
165
+ layoutedGraph = _context.sent;
166
+ commonDistanceHeight = 0;
167
+ commonDistantWidth = 0;
168
+ if (isSubFlow) {
169
+ topNode = (_layoutedGraph$childr = layoutedGraph.children) === null || _layoutedGraph$childr === void 0 ? void 0 : _layoutedGraph$childr.reduce(function (min, current) {
170
+ return (current.y || 0) < (min.y || 0) ? current : min;
171
+ }, layoutedGraph.children[0] || {
172
+ y: 0
173
+ });
174
+ leftNode = (_layoutedGraph$childr2 = layoutedGraph.children) === null || _layoutedGraph$childr2 === void 0 ? void 0 : _layoutedGraph$childr2.reduce(function (min, current) {
175
+ return (current.x || 0) < (min.x || 0) ? current : min;
176
+ }, layoutedGraph.children[0] || {
177
+ x: 0
178
+ });
179
+ commonDistanceHeight = ITERATION_PADDING.top - ((topNode === null || topNode === void 0 ? void 0 : topNode.y) || 0);
180
+ commonDistantWidth = ITERATION_PADDING.left - ((leftNode === null || leftNode === void 0 ? void 0 : leftNode.x) || 0);
181
+ }
182
+ layoutedNodes = nodes.map(function (node) {
183
+ var _layoutedGraph$childr3, _layoutedNode$x, _layoutedNode$y;
184
+ var layoutedNode = (_layoutedGraph$childr3 = layoutedGraph.children) === null || _layoutedGraph$childr3 === void 0 ? void 0 : _layoutedGraph$childr3.find(function (lgNode) {
185
+ return lgNode.id === node.id;
186
+ });
187
+ return _objectSpread(_objectSpread({}, node), {}, {
188
+ position: {
189
+ x: ((_layoutedNode$x = layoutedNode === null || layoutedNode === void 0 ? void 0 : layoutedNode.x) !== null && _layoutedNode$x !== void 0 ? _layoutedNode$x : 0) + commonDistantWidth,
190
+ y: ((_layoutedNode$y = layoutedNode === null || layoutedNode === void 0 ? void 0 : layoutedNode.y) !== null && _layoutedNode$y !== void 0 ? _layoutedNode$y : 0) + commonDistanceHeight
191
+ }
192
+ });
193
+ });
194
+ return _context.abrupt("return", {
195
+ layoutedNodes: layoutedNodes
196
+ });
197
+ case 11:
198
+ case "end":
199
+ return _context.stop();
200
+ }
201
+ }, _callee);
202
+ }));
203
+ return function layoutFlow(_x) {
204
+ return _ref2.apply(this, arguments);
205
+ };
206
+ }();
207
+ export var getParentInputParams = function getParentInputParams(node) {
208
+ var input_params = node.data.input_params;
209
+ var list = [];
210
+ input_params.forEach(function (item) {
211
+ var _item$type;
212
+ if ((_item$type = item.type) !== null && _item$type !== void 0 && _item$type.includes('Array') && !!item.value) {
213
+ var arrayType = item.type.replace(/^Array<(.+)>$/, '$1');
214
+ list.push({
215
+ label: "item (in ".concat(item.key, ")"),
216
+ value: "${".concat(node.id, ".").concat(item.key, "}"),
217
+ type: arrayType
218
+ });
219
+ }
220
+ });
221
+ return list;
222
+ };
223
+ export var copyNodeConfig = function copyNodeConfig(node, nodes) {
224
+ return _objectSpread(_objectSpread({}, node), {}, {
225
+ id: "".concat(node.type, "_").concat(uniqueId(4)),
226
+ position: {
227
+ x: node.position.x + node.width + NEW_NODE_PADDING.x,
228
+ y: node.position.y
229
+ },
230
+ selected: true,
231
+ data: _objectSpread(_objectSpread({}, node.data), {}, {
232
+ label: generateUniqueName(node.data.label, nodes.map(function (item) {
233
+ return item.data.label;
234
+ }))
235
+ })
236
+ });
237
+ };
238
+ export var copySubFlowNodeConfig = function copySubFlowNodeConfig(node, nodes) {
239
+ return _objectSpread(_objectSpread({}, node), {}, {
240
+ id: "".concat(node.type, "_").concat(uniqueId(4)),
241
+ position: {
242
+ x: node.position.x,
243
+ y: node.position.y
244
+ },
245
+ data: _objectSpread(_objectSpread({}, node.data), {}, {
246
+ label: generateUniqueName(node.data.label, nodes.map(function (item) {
247
+ return item.data.label;
248
+ }))
249
+ })
250
+ });
251
+ };
252
+ export var isEventInInput = function isEventInInput(event) {
253
+ // @ts-ignore
254
+ if (!event.target.matches) return false;
255
+ var whiteDomList = ['div.cm-content', 'input', 'div.text-editor-content'];
256
+ // @ts-ignore
257
+ return whiteDomList.some(function (item) {
258
+ return event.target.matches(item);
259
+ });
260
+ };
261
+ export var setWorkFlowLanguage = function setWorkFlowLanguage(language) {
262
+ i18n.setCurrentLanguage(language);
263
+ };
264
+ export var matchVariableFromVarItem = function matchVariableFromVarItem(variable, varItems) {
265
+ return varItems.find(function (child) {
266
+ var _child$children;
267
+ if (child.value === variable) return true;
268
+ if ((_child$children = child.children) !== null && _child$children !== void 0 && _child$children.length) {
269
+ return matchVariableFromVarItem(variable, child.children);
270
+ }
271
+ return false;
272
+ });
273
+ };
@@ -0,0 +1,2 @@
1
+ export declare function setUniqueIdStrategy(strategy: 'incremental' | 'random'): void;
2
+ export default function uniqueId(length: number): string;
@@ -0,0 +1,39 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ var charset = [['0', '9'], ['a', 'z'], ['A', 'Z']].map(function (pair) {
8
+ return pair.map(function (char) {
9
+ return char.charCodeAt(0);
10
+ });
11
+ }).flatMap(function (_ref) {
12
+ var _ref2 = _slicedToArray(_ref, 2),
13
+ start = _ref2[0],
14
+ end = _ref2[1];
15
+ return Array.from({
16
+ length: end - start + 1
17
+ }, function (_, index) {
18
+ return start + index;
19
+ });
20
+ });
21
+ var randomId = function randomId(length) {
22
+ return String.fromCharCode.apply(String, Array.from({
23
+ length: length
24
+ }, function () {
25
+ return charset[Math.floor(Math.random() * charset.length)];
26
+ }));
27
+ };
28
+ var _seed = 0;
29
+ var incrementalId = function incrementalId(length) {
30
+ _seed += 1;
31
+ return "".concat(_seed.toString(16), "######").substring(0, length);
32
+ };
33
+ var _strategy = 'random';
34
+ export function setUniqueIdStrategy(strategy) {
35
+ _strategy = strategy;
36
+ }
37
+ export default function uniqueId(length) {
38
+ return _strategy === 'incremental' ? incrementalId(length) : randomId(length);
39
+ }
@@ -0,0 +1,17 @@
1
+ import { IWorkFlowNode } from "../types/work-flow";
2
+ import { Edge } from '@xyflow/react';
3
+ /**
4
+ * Get all upstream adjacent node parameter interfaces for the specified node
5
+ */
6
+ export interface GetNeighborNodesParams {
7
+ nodes: IWorkFlowNode[];
8
+ edges: Edge[];
9
+ nodeId: string;
10
+ visited?: Set<string>;
11
+ }
12
+ /**
13
+ * Get all upstream adjacent nodes of the specified node
14
+ * @param params - Parameter object
15
+ * @returns A mapping of adjacent nodes, with the key as the node ID and the value as the node object
16
+ */
17
+ export declare const getNeighborNodes: (params: GetNeighborNodesParams) => Record<string, IWorkFlowNode>;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Get all upstream adjacent node parameter interfaces for the specified node
3
+ */
4
+
5
+ /**
6
+ * Get all upstream adjacent nodes of the specified node
7
+ * @param params - Parameter object
8
+ * @returns A mapping of adjacent nodes, with the key as the node ID and the value as the node object
9
+ */
10
+ export var getNeighborNodes = function getNeighborNodes(params) {
11
+ var nodes = params.nodes,
12
+ edges = params.edges,
13
+ nodeId = params.nodeId,
14
+ _params$visited = params.visited,
15
+ visited = _params$visited === void 0 ? new Set() : _params$visited;
16
+ if (visited.has(nodeId)) {
17
+ return {};
18
+ }
19
+ visited.add(nodeId);
20
+ var edgeItems = edges.filter(function (item) {
21
+ return item.target === nodeId;
22
+ });
23
+ if (!edgeItems.length) {
24
+ return {};
25
+ }
26
+ var sourceNodeIds = new Set(edgeItems.map(function (edge) {
27
+ return edge.source;
28
+ }));
29
+ var sourceNodes = nodes.filter(function (item) {
30
+ return sourceNodeIds.has(item.id);
31
+ });
32
+ var nodesMap = {};
33
+ sourceNodes.forEach(function (item) {
34
+ nodesMap[item.id] = item;
35
+ var neighborNodes = getNeighborNodes({
36
+ nodes: nodes,
37
+ edges: edges,
38
+ nodeId: item.id,
39
+ visited: visited
40
+ });
41
+ Object.assign(nodesMap, neighborNodes);
42
+ });
43
+ return nodesMap;
44
+ };
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@agentscope-ai/flow",
3
+ "version": "0.0.1",
4
+ "description": "A powerful and flexible flow canvas rendering engine designed for AI applications. Provides comprehensive workflow visualization and interaction capabilities for platforms like Bailian and AgentScope, enabling seamless creation and management of complex AI agent workflows with an intuitive drag-and-drop interface.",
5
+ "module": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build:css": "tailwindcss -i ./tailwind.css -o ./dist/index.css --minify",
12
+ "build:copy": "cp ./tailwind.css ./dist/tailwind.css",
13
+ "build:replace": "node -e \"const fs=require('fs'); const content=fs.readFileSync('./dist/index.js','utf8'); fs.writeFileSync('./dist/index.js', content.replace('../tailwind.css', './index.css'));\"",
14
+ "build": "father build && npm run build:css && npm run build:copy && npm run build:replace",
15
+ "build:watch": "father dev",
16
+ "dev": "dumi dev && father dev",
17
+ "docs:build": "dumi build",
18
+ "docs:preview": "dumi preview",
19
+ "doctor": "father doctor",
20
+ "prepublishOnly": "npm run build",
21
+ "start": "npm run dev"
22
+ },
23
+ "commitlint": {
24
+ "extends": [
25
+ "@commitlint/config-conventional"
26
+ ]
27
+ },
28
+ "dependencies": {
29
+ "@agentscope-ai/icons": "^1.0.35",
30
+ "@codemirror/autocomplete": "^6.0.0",
31
+ "@codemirror/lang-javascript": "^6.2.3",
32
+ "@codemirror/lang-python": "^6.1.7",
33
+ "@codemirror/lint": "^6.0.0",
34
+ "@codemirror/state": "^6.5.2",
35
+ "@codemirror/view": "^6.9.2",
36
+ "@dnd-kit/core": "^6.3.1",
37
+ "@dnd-kit/sortable": "^8.0.0",
38
+ "@dnd-kit/utilities": "^3.2.2",
39
+ "@uiw/codemirror-theme-vscode": "^4.23.10",
40
+ "@uiw/react-codemirror": "4.20.2",
41
+ "@xyflow/react": "12.3.5",
42
+ "ahooks": "3.8.1",
43
+ "antd": "5.23.2",
44
+ "classnames": "^2.5.1",
45
+ "dayjs": "^1.11.13",
46
+ "elkjs": "^0.9.3",
47
+ "lodash-es": "^4.17.21",
48
+ "use-bus": "^2.5.2",
49
+ "zustand": "^5.0.3"
50
+ },
51
+ "devDependencies": {
52
+ "@agentscope-ai/chat": "^1.1.17",
53
+ "@agentscope-ai/design": "^1.0.7",
54
+ "@commitlint/cli": "^17.1.2",
55
+ "@commitlint/config-conventional": "^17.1.0",
56
+ "@types/lodash-es": "^4.17.12",
57
+ "@types/react": "^18.0.0",
58
+ "@types/react-dom": "^18.0.0",
59
+ "@umijs/plugins": "^4.3.8",
60
+ "dumi": "^2.4.13",
61
+ "father": "^4.1.0",
62
+ "react": "^18.0.0",
63
+ "react-dom": "^18.0.0",
64
+ "tailwindcss": "^3.4.15"
65
+ },
66
+ "peerDependencies": {
67
+ "@agentscope-ai/chat": "^1.1.17",
68
+ "@agentscope-ai/design": "^1.0.7",
69
+ "antd": "5.23.2",
70
+ "react": ">=16.9.0",
71
+ "react-dom": ">=16.9.0"
72
+ },
73
+ "publishConfig": {
74
+ "registry": "https://registry.npmjs.org",
75
+ "access": "public"
76
+ },
77
+ "authors": []
78
+ }