plugin-ai-api 1.0.6 → 1.0.8
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/client/index.js +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -9
- package/dist/server/routes/agent-completions.js +53 -53
- package/dist/server/utils/ai-employee-runtime.js +59 -0
- package/package.json +1 -1
- package/src/server/__tests__/agent-completions.test.ts +26 -0
- package/src/server/routes/agent-completions.ts +450 -428
- package/src/server/utils/ai-employee-runtime.ts +71 -0
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@nocobase/client"),require("@nocobase/plugin-acl/client")):"function"==typeof define&&define.amd?define("plugin-ai-api",["@nocobase/client-v2","react","antd","@nocobase/client","@nocobase/plugin-acl/client"],t):"object"==typeof exports?exports["plugin-ai-api"]=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@nocobase/client"),require("@nocobase/plugin-acl/client")):e["plugin-ai-api"]=t(e["@nocobase/client-v2"],e.react,e.antd,e["@nocobase/client"],e["@nocobase/plugin-acl/client"])}(self,function(e,t,n,r,o){return function(){"use strict";var i,a,u,c={342:function(e){e.exports=r},485:function(t){t.exports=e},79:function(e){e.exports=o},59:function(e){e.exports=n},155:function(e){e.exports=t}},l={};function p(e){var t=l[e];if(void 0!==t)return t.exports;var n=l[e]={exports:{}};return c[e](n,n.exports,p),n.exports}p.m=c,p.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return p.d(t,{a:t}),t},p.d=function(e,t){for(var n in t)p.o(t,n)&&!p.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},p.f={},p.e=function(e){return Promise.all(Object.keys(p.f).reduce(function(t,n){return p.f[n](e,t),t},[]))},p.u=function(e){return""+e+"."+({778:"5c452944cb747975",950:"83390c5f1d5a97fb"})[e]+".js"},p.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),p.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},f={},p.l=function(e,t,n,r){if(f[e])return void f[e].push(t);if(void 0!==n)for(var o,i,a=document.getElementsByTagName("script"),u=0;u<a.length;u++){var c=a[u];if(c.getAttribute("src")==e||c.getAttribute("data-rspack")=="plugin-ai-api:"+n){o=c;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,p.nc&&o.setAttribute("nonce",p.nc),o.setAttribute("data-rspack","plugin-ai-api:"+n),o.src=e),f[e]=[t];var l=function(t,n){o.onerror=o.onload=null,clearTimeout(s);var r=f[e];if(delete f[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},s=setTimeout(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.bind(null,o.onload),i&&document.head.appendChild(o)},p.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},p.g.importScripts&&(s=p.g.location+"");var f,s,d=p.g.document;if(!s&&d&&(d.currentScript&&"SCRIPT"===d.currentScript.tagName.toUpperCase()&&(s=d.currentScript.src),!s)){var b=d.getElementsByTagName("script");if(b.length)for(var h=b.length-1;h>-1&&(!s||!/^http(s?):/.test(s));)s=b[h--].src}if(!s)throw Error("Automatic publicPath is not supported in this browser");p.p=s.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i={889:0},p.f.j=function(e,t){var n=p.o(i,e)?i[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=i[e]=[t,r]});t.push(n[2]=r);var o=p.p+p.u(e),a=Error();p.l(o,function(t){if(p.o(i,e)&&(0!==(n=i[e])&&(i[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;a.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",a.name="ChunkLoadError",a.type=r,a.request=o,n[1](a)}},"chunk-"+e,e)}},a=function(e,t){var n,r,o=t[0],a=t[1],u=t[2],c=0;if(o.some(function(e){return 0!==i[e]})){for(n in a)p.o(a,n)&&(p.m[n]=a[n]);u&&u(p)}for(e&&e(t);c<o.length;c++)r=o[c],p.o(i,r)&&i[r]&&i[r][0](),i[r]=0},(u=self.webpackChunkplugin_ai_api=self.webpackChunkplugin_ai_api||[]).forEach(a.bind(null,0)),u.push=a.bind(null,u.push.bind(u));var v={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@nocobase/client"),require("@nocobase/plugin-acl/client")):"function"==typeof define&&define.amd?define("plugin-ai-api",["@nocobase/client-v2","react","antd","@nocobase/client","@nocobase/plugin-acl/client"],t):"object"==typeof exports?exports["plugin-ai-api"]=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@nocobase/client"),require("@nocobase/plugin-acl/client")):e["plugin-ai-api"]=t(e["@nocobase/client-v2"],e.react,e.antd,e["@nocobase/client"],e["@nocobase/plugin-acl/client"])}(self,function(e,t,n,r,o){return function(){"use strict";var i,a,u,c={342:function(e){e.exports=r},485:function(t){t.exports=e},79:function(e){e.exports=o},59:function(e){e.exports=n},155:function(e){e.exports=t}},l={};function p(e){var t=l[e];if(void 0!==t)return t.exports;var n=l[e]={exports:{}};return c[e](n,n.exports,p),n.exports}p.m=c,p.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return p.d(t,{a:t}),t},p.d=function(e,t){for(var n in t)p.o(t,n)&&!p.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},p.f={},p.e=function(e){return Promise.all(Object.keys(p.f).reduce(function(t,n){return p.f[n](e,t),t},[]))},p.u=function(e){return""+e+"."+({778:"5c452944cb747975",950:"83390c5f1d5a97fb"})[e]+".js"},p.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),p.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},f={},p.l=function(e,t,n,r){if(f[e])return void f[e].push(t);if(void 0!==n)for(var o,i,a=document.getElementsByTagName("script"),u=0;u<a.length;u++){var c=a[u];if(c.getAttribute("src")==e||c.getAttribute("data-rspack")=="plugin-ai-api:"+n){o=c;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,p.nc&&o.setAttribute("nonce",p.nc),o.setAttribute("data-rspack","plugin-ai-api:"+n),o.src=e),f[e]=[t];var l=function(t,n){o.onerror=o.onload=null,clearTimeout(s);var r=f[e];if(delete f[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},s=setTimeout(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.bind(null,o.onload),i&&document.head.appendChild(o)},p.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},p.g.importScripts&&(s=p.g.location+"");var f,s,d=p.g.document;if(!s&&d&&(d.currentScript&&"SCRIPT"===d.currentScript.tagName.toUpperCase()&&(s=d.currentScript.src),!s)){var b=d.getElementsByTagName("script");if(b.length)for(var h=b.length-1;h>-1&&(!s||!/^http(s?):/.test(s));)s=b[h--].src}if(!s)throw Error("Automatic publicPath is not supported in this browser");p.p=s.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i={889:0},p.f.j=function(e,t){var n=p.o(i,e)?i[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=i[e]=[t,r]});t.push(n[2]=r);var o=p.p+p.u(e),a=Error();p.l(o,function(t){if(p.o(i,e)&&(0!==(n=i[e])&&(i[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;a.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",a.name="ChunkLoadError",a.type=r,a.request=o,n[1](a)}},"chunk-"+e,e)}},a=function(e,t){var n,r,o=t[0],a=t[1],u=t[2],c=0;if(o.some(function(e){return 0!==i[e]})){for(n in a)p.o(a,n)&&(p.m[n]=a[n]);u&&u(p)}for(e&&e(t);c<o.length;c++)r=o[c],p.o(i,r)&&i[r]&&i[r][0](),i[r]=0},(u=self.webpackChunkplugin_ai_api=self.webpackChunkplugin_ai_api||[]).forEach(a.bind(null,0)),u.push=a.bind(null,u.push.bind(u));var v={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src){var n=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");n.indexOf("/static/plugins/plugin-ai-api/dist/client/")>=0&&(e=n.replace(/\/[^\/]+$/,"/"))}if(!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/plugin-ai-api/dist/client/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var a=window.location.pathname||"/",u=a.indexOf(i);e=u>=0?a.slice(0,u+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/plugin-ai-api/dist/client/"}p.p=e}(),!function(){p.r(v),p.d(v,{default:function(){return b}});var e=p(342),t=p(79),n=p.n(t),r=p(155),o=p.n(r);function i(e,t,n,r,o,i,a){try{var u=e[i](a),c=u.value}catch(e){n(e);return}u.done?t(c):Promise.resolve(c).then(r,o)}function a(e,t,n){return(a=f()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&c(o,n.prototype),o}).apply(null,arguments)}function u(e){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return a(e,arguments,u(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,e)})(e)}function f(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(f=function(){return!!e})()}var s=o().lazy(function(){return p.e("950").then(p.bind(p,693))}),d=(0,e.lazy)(function(){return p.e("778").then(p.bind(p,905))},"AiApiRolePermissions").AiApiRolePermissions,b=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=u(e),function(e,t){var n;if(t&&("object"==((n=t)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,f()?Reflect.construct(e,t||[],u(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&c(r,e),t=[{key:"load",value:function(){var e;return(e=function(){var e;return function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:c(0)}),u(a,"throw",{value:c(1)}),u(a,"return",{value:c(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function c(u){return function(c){var l=[u,c];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(t){return this.app.pluginSettingsManager.add("ai-api",{icon:"ApiOutlined",title:this.t("AI API Gateway"),aclSnippet:"pm.ai-api.configuration"}),this.app.pluginSettingsManager.add("ai-api.config",{title:this.t("Configuration"),Component:s}),(null==(e=this.app.pm.get(n()))?void 0:e.settingsUI)&&e.settingsUI.addPermissionsTab(function(e){e.t;var t=e.TabLayout,n=e.activeRole;return{key:"aiApi",label:"AI API",sort:25,children:o().createElement(t,null,o().createElement(d,{role:n}))}}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function u(e){i(a,r,o,u,c,"next",e)}function c(e){i(a,r,o,u,c,"throw",e)}u(void 0)})}).call(this)}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(r.prototype,t),r}(l(e.Plugin))}(),v}()});
|
package/dist/client-v2/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2"),require("react"),require("antd")):"function"==typeof define&&define.amd?define("plugin-ai-api/client-v2",["@nocobase/client-v2","react","antd"],t):"object"==typeof exports?exports["plugin-ai-api/client-v2"]=t(require("@nocobase/client-v2"),require("react"),require("antd")):e["plugin-ai-api/client-v2"]=t(e["@nocobase/client-v2"],e.react,e.antd)}(self,function(e,t,n){return function(){"use strict";var r,o,i,a={485:function(t){t.exports=e},59:function(e){e.exports=n},155:function(e){e.exports=t}},u={};function c(e){var t=u[e];if(void 0!==t)return t.exports;var n=u[e]={exports:{}};return a[e](n,n.exports,c),n.exports}c.m=a,c.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return c.d(t,{a:t}),t},c.d=function(e,t){for(var n in t)c.o(t,n)&&!c.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},c.f={},c.e=function(e){return Promise.all(Object.keys(c.f).reduce(function(t,n){return c.f[n](e,t),t},[]))},c.u=function(e){return""+e+".42b30b5cc9e32b8f.js"},c.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),c.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},l={},c.l=function(e,t,n,r){if(l[e])return void l[e].push(t);if(void 0!==n)for(var o,i,a=document.getElementsByTagName("script"),u=0;u<a.length;u++){var p=a[u];if(p.getAttribute("src")==e||p.getAttribute("data-rspack")=="plugin-ai-api/client-v2:"+n){o=p;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,c.nc&&o.setAttribute("nonce",c.nc),o.setAttribute("data-rspack","plugin-ai-api/client-v2:"+n),o.src=e),l[e]=[t];var f=function(t,n){o.onerror=o.onload=null,clearTimeout(s);var r=l[e];if(delete l[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},s=setTimeout(f.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=f.bind(null,o.onerror),o.onload=f.bind(null,o.onload),i&&document.head.appendChild(o)},c.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},c.g.importScripts&&(p=c.g.location+"");var l,p,f=c.g.document;if(!p&&f&&(f.currentScript&&"SCRIPT"===f.currentScript.tagName.toUpperCase()&&(p=f.currentScript.src),!p)){var s=f.getElementsByTagName("script");if(s.length)for(var d=s.length-1;d>-1&&(!p||!/^http(s?):/.test(p));)p=s[d--].src}if(!p)throw Error("Automatic publicPath is not supported in this browser");c.p=p.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r={889:0},c.f.j=function(e,t){var n=c.o(r,e)?r[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var o=new Promise(function(t,o){n=r[e]=[t,o]});t.push(n[2]=o);var i=c.p+c.u(e),a=Error();c.l(i,function(t){if(c.o(r,e)&&(0!==(n=r[e])&&(r[e]=void 0),n)){var o=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;a.message="Loading chunk "+e+" failed.\n("+o+": "+i+")",a.name="ChunkLoadError",a.type=o,a.request=i,n[1](a)}},"chunk-"+e,e)}},o=function(e,t){var n,o,i=t[0],a=t[1],u=t[2],l=0;if(i.some(function(e){return 0!==r[e]})){for(n in a)c.o(a,n)&&(c.m[n]=a[n]);u&&u(c)}for(e&&e(t);l<i.length;l++)o=i[l],c.o(r,o)&&r[o]&&r[o][0](),r[o]=0},(i=self.webpackChunkplugin_ai_api_client_v2=self.webpackChunkplugin_ai_api_client_v2||[]).forEach(o.bind(null,0)),i.push=o.bind(null,i.push.bind(i));var b={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2"),require("react"),require("antd")):"function"==typeof define&&define.amd?define("plugin-ai-api/client-v2",["@nocobase/client-v2","react","antd"],t):"object"==typeof exports?exports["plugin-ai-api/client-v2"]=t(require("@nocobase/client-v2"),require("react"),require("antd")):e["plugin-ai-api/client-v2"]=t(e["@nocobase/client-v2"],e.react,e.antd)}(self,function(e,t,n){return function(){"use strict";var r,o,i,a={485:function(t){t.exports=e},59:function(e){e.exports=n},155:function(e){e.exports=t}},u={};function c(e){var t=u[e];if(void 0!==t)return t.exports;var n=u[e]={exports:{}};return a[e](n,n.exports,c),n.exports}c.m=a,c.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return c.d(t,{a:t}),t},c.d=function(e,t){for(var n in t)c.o(t,n)&&!c.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},c.f={},c.e=function(e){return Promise.all(Object.keys(c.f).reduce(function(t,n){return c.f[n](e,t),t},[]))},c.u=function(e){return""+e+".42b30b5cc9e32b8f.js"},c.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),c.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},l={},c.l=function(e,t,n,r){if(l[e])return void l[e].push(t);if(void 0!==n)for(var o,i,a=document.getElementsByTagName("script"),u=0;u<a.length;u++){var p=a[u];if(p.getAttribute("src")==e||p.getAttribute("data-rspack")=="plugin-ai-api/client-v2:"+n){o=p;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,c.nc&&o.setAttribute("nonce",c.nc),o.setAttribute("data-rspack","plugin-ai-api/client-v2:"+n),o.src=e),l[e]=[t];var f=function(t,n){o.onerror=o.onload=null,clearTimeout(s);var r=l[e];if(delete l[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},s=setTimeout(f.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=f.bind(null,o.onerror),o.onload=f.bind(null,o.onload),i&&document.head.appendChild(o)},c.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},c.g.importScripts&&(p=c.g.location+"");var l,p,f=c.g.document;if(!p&&f&&(f.currentScript&&"SCRIPT"===f.currentScript.tagName.toUpperCase()&&(p=f.currentScript.src),!p)){var s=f.getElementsByTagName("script");if(s.length)for(var d=s.length-1;d>-1&&(!p||!/^http(s?):/.test(p));)p=s[d--].src}if(!p)throw Error("Automatic publicPath is not supported in this browser");c.p=p.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r={889:0},c.f.j=function(e,t){var n=c.o(r,e)?r[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var o=new Promise(function(t,o){n=r[e]=[t,o]});t.push(n[2]=o);var i=c.p+c.u(e),a=Error();c.l(i,function(t){if(c.o(r,e)&&(0!==(n=r[e])&&(r[e]=void 0),n)){var o=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;a.message="Loading chunk "+e+" failed.\n("+o+": "+i+")",a.name="ChunkLoadError",a.type=o,a.request=i,n[1](a)}},"chunk-"+e,e)}},o=function(e,t){var n,o,i=t[0],a=t[1],u=t[2],l=0;if(i.some(function(e){return 0!==r[e]})){for(n in a)c.o(a,n)&&(c.m[n]=a[n]);u&&u(c)}for(e&&e(t);l<i.length;l++)o=i[l],c.o(r,o)&&r[o]&&r[o][0](),r[o]=0},(i=self.webpackChunkplugin_ai_api_client_v2=self.webpackChunkplugin_ai_api_client_v2||[]).forEach(o.bind(null,0)),i.push=o.bind(null,i.push.bind(i));var b={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src){var n=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");n.indexOf("/static/plugins/plugin-ai-api/dist/client-v2/")>=0&&(e=n.replace(/\/[^\/]+$/,"/"))}if(!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/plugin-ai-api/dist/client-v2/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var a=window.location.pathname||"/",u=a.indexOf(i);e=u>=0?a.slice(0,u+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/plugin-ai-api/dist/client-v2/"}c.p=e}(),!function(){c.r(b),c.d(b,{default:function(){return u}});var e=c(485);function t(e,t,n,r,o,i,a){try{var u=e[i](a),c=u.value}catch(e){n(e);return}u.done?t(c):Promise.resolve(c).then(r,o)}function n(e,t,r){return(n=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&o(i,n.prototype),i}).apply(null,arguments)}c(155);function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,i)}function i(){return n(e,arguments,r(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,e)})(e)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}var u=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function i(){var e,t;if(!(this instanceof i))throw TypeError("Cannot call a class as a function");return e=i,t=arguments,e=r(e),function(e,t){var n;if(t&&("object"==((n=t)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,a()?Reflect.construct(e,t||[],r(this).constructor):e.apply(this,t))}return i.prototype=Object.create(e&&e.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),e&&o(i,e),n=[{key:"load",value:function(){var e;return(e=function(){return function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:c(0)}),u(a,"throw",{value:c(1)}),u(a,"return",{value:c(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function c(u){return function(c){var l=[u,c];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(e){return this.pluginSettingsManager.addMenuItem({key:"ai-api",title:this.t("AI API Gateway"),icon:"ApiOutlined",aclSnippet:"pm.ai-api.configuration"}),this.pluginSettingsManager.addPageTabItem({menuKey:"ai-api",key:"index",title:this.t("Configuration"),componentLoader:function(){return c.e("950").then(c.bind(c,693))}}),[2]})},function(){var n=this,r=arguments;return new Promise(function(o,i){var a=e.apply(n,r);function u(e){t(a,o,i,u,c,"next",e)}function c(e){t(a,o,i,u,c,"throw",e)}u(void 0)})}).call(this)}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(i.prototype,n),i}(i(e.Plugin))}(),b}()});
|
package/dist/externalVersion.js
CHANGED
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
module.exports = {
|
|
11
11
|
"react": "18.2.0",
|
|
12
12
|
"antd": "5.24.2",
|
|
13
|
-
"@nocobase/client-v2": "2.1.
|
|
14
|
-
"@nocobase/flow-engine": "2.1.
|
|
15
|
-
"@nocobase/client": "2.1.
|
|
16
|
-
"@nocobase/plugin-acl": "2.1.
|
|
17
|
-
"@nocobase/server": "2.1.
|
|
13
|
+
"@nocobase/client-v2": "2.1.23",
|
|
14
|
+
"@nocobase/flow-engine": "2.1.23",
|
|
15
|
+
"@nocobase/client": "2.1.23",
|
|
16
|
+
"@nocobase/plugin-acl": "2.1.23",
|
|
17
|
+
"@nocobase/server": "2.1.23",
|
|
18
18
|
"dayjs": "1.11.13",
|
|
19
|
-
"@nocobase/database": "2.1.
|
|
20
|
-
"@nocobase/actions": "2.1.
|
|
21
|
-
"@nocobase/resourcer": "2.1.
|
|
22
|
-
"@nocobase/plugin-ai": "2.1.
|
|
19
|
+
"@nocobase/database": "2.1.23",
|
|
20
|
+
"@nocobase/actions": "2.1.23",
|
|
21
|
+
"@nocobase/resourcer": "2.1.23",
|
|
22
|
+
"@nocobase/plugin-ai": "2.1.23"
|
|
23
23
|
};
|
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var __create = Object.create;
|
|
11
10
|
var __defProp = Object.defineProperty;
|
|
12
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
13
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
14
|
var __export = (target, all) => {
|
|
17
15
|
for (var name in all)
|
|
@@ -25,14 +23,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
23
|
}
|
|
26
24
|
return to;
|
|
27
25
|
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
27
|
var agent_completions_exports = {};
|
|
38
28
|
__export(agent_completions_exports, {
|
|
@@ -42,6 +32,7 @@ module.exports = __toCommonJS(agent_completions_exports);
|
|
|
42
32
|
var import_openai_format = require("../utils/openai-format");
|
|
43
33
|
var import_resolve_service = require("../utils/resolve-service");
|
|
44
34
|
var import_role_permission = require("../middleware/role-permission");
|
|
35
|
+
var import_ai_employee_runtime = require("../utils/ai-employee-runtime");
|
|
45
36
|
async function handleAgentCompletions(ctx, plugin) {
|
|
46
37
|
var _a;
|
|
47
38
|
const body = ctx.request.body;
|
|
@@ -106,6 +97,10 @@ async function handleAgentCompletions(ctx, plugin) {
|
|
|
106
97
|
return;
|
|
107
98
|
}
|
|
108
99
|
const wantStream = body.stream === true;
|
|
100
|
+
const lifecycle = (0, import_ai_employee_runtime.getAgentRuntimeLifecycle)(ctx);
|
|
101
|
+
let runtimeContext;
|
|
102
|
+
let lifecycleCompleted = false;
|
|
103
|
+
let ephemeralSessionId;
|
|
109
104
|
try {
|
|
110
105
|
const employeeRecord = await ctx.db.getRepository("aiEmployees").findOne({
|
|
111
106
|
filter: { username: employeeUsername }
|
|
@@ -130,6 +125,7 @@ async function handleAgentCompletions(ctx, plugin) {
|
|
|
130
125
|
}
|
|
131
126
|
});
|
|
132
127
|
const sessionId = conversation.sessionId ?? conversation.id ?? String(conversation.get("id"));
|
|
128
|
+
ephemeralSessionId = String(sessionId);
|
|
133
129
|
const userMessages = body.messages.map((msg) => ({
|
|
134
130
|
// 'assistant' role maps to the AI employee's username in NocoBase's system
|
|
135
131
|
role: msg.role === "assistant" ? employeeUsername : msg.role,
|
|
@@ -138,14 +134,19 @@ async function handleAgentCompletions(ctx, plugin) {
|
|
|
138
134
|
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
139
135
|
}
|
|
140
136
|
}));
|
|
137
|
+
runtimeContext = {
|
|
138
|
+
ctx,
|
|
139
|
+
source: "api",
|
|
140
|
+
employee: employeeRecord,
|
|
141
|
+
sessionId,
|
|
142
|
+
userId,
|
|
143
|
+
messages: userMessages,
|
|
144
|
+
metadata: {}
|
|
145
|
+
};
|
|
141
146
|
const completionId = (0, import_openai_format.generateCompletionId)();
|
|
142
147
|
let AIEmployee;
|
|
143
148
|
try {
|
|
144
|
-
|
|
145
|
-
/* webpackIgnore: true */
|
|
146
|
-
"@nocobase/plugin-ai/dist/server/ai-employees/ai-employee.js"
|
|
147
|
-
);
|
|
148
|
-
AIEmployee = mod.AIEmployee;
|
|
149
|
+
AIEmployee = await (0, import_ai_employee_runtime.loadAIEmployeeConstructor)();
|
|
149
150
|
} catch (importErr) {
|
|
150
151
|
ctx.log.error(
|
|
151
152
|
"AI API: Failed to import AIEmployee from plugin-ai. Ensure plugin-ai is installed and built.",
|
|
@@ -155,21 +156,13 @@ async function handleAgentCompletions(ctx, plugin) {
|
|
|
155
156
|
ctx.body = (0, import_openai_format.toOpenAIError)(500, "Agent mode unavailable: plugin-ai not found or not built", "server_error");
|
|
156
157
|
return;
|
|
157
158
|
}
|
|
158
|
-
if (!AIEmployee) {
|
|
159
|
-
ctx.status = 500;
|
|
160
|
-
ctx.body = (0, import_openai_format.toOpenAIError)(
|
|
161
|
-
500,
|
|
162
|
-
"Agent mode unavailable: AIEmployee class not exported by plugin-ai",
|
|
163
|
-
"server_error"
|
|
164
|
-
);
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
159
|
if (!ctx.get("x-timezone")) {
|
|
168
160
|
ctx.req.headers["x-timezone"] = "UTC";
|
|
169
161
|
}
|
|
170
162
|
if (!ctx.get("x-locale")) {
|
|
171
163
|
ctx.req.headers["x-locale"] = "en-US";
|
|
172
164
|
}
|
|
165
|
+
await (lifecycle == null ? void 0 : lifecycle.runBeforeHooks(runtimeContext));
|
|
173
166
|
if (wantStream) {
|
|
174
167
|
ctx.set({
|
|
175
168
|
"Content-Type": "text/event-stream",
|
|
@@ -231,20 +224,17 @@ async function handleAgentCompletions(ctx, plugin) {
|
|
|
231
224
|
};
|
|
232
225
|
try {
|
|
233
226
|
const aiEmployee = new AIEmployee(
|
|
234
|
-
ctx,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
// systemMessage — use AI employee's default
|
|
239
|
-
void 0,
|
|
240
|
-
// skillSettings
|
|
241
|
-
false,
|
|
242
|
-
// webSearch
|
|
243
|
-
{ llmService: service.name, model: modelId },
|
|
244
|
-
false
|
|
245
|
-
// legacy — use LangGraph (thread: 1)
|
|
227
|
+
(0, import_ai_employee_runtime.createAIEmployeeOptions)(ctx, employeeRecord, sessionId, {
|
|
228
|
+
llmService: service.name,
|
|
229
|
+
model: modelId
|
|
230
|
+
})
|
|
246
231
|
);
|
|
247
232
|
await aiEmployee.stream({ userMessages });
|
|
233
|
+
try {
|
|
234
|
+
await (lifecycle == null ? void 0 : lifecycle.runAfterHooks(runtimeContext, { succeeded: true }));
|
|
235
|
+
} finally {
|
|
236
|
+
lifecycleCompleted = true;
|
|
237
|
+
}
|
|
248
238
|
} finally {
|
|
249
239
|
ctx.res.write = originalWrite;
|
|
250
240
|
ctx.res.end = originalEnd;
|
|
@@ -263,16 +253,17 @@ async function handleAgentCompletions(ctx, plugin) {
|
|
|
263
253
|
}
|
|
264
254
|
} else {
|
|
265
255
|
const aiEmployee = new AIEmployee(
|
|
266
|
-
ctx,
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
void 0,
|
|
271
|
-
false,
|
|
272
|
-
{ llmService: service.name, model: modelId },
|
|
273
|
-
false
|
|
256
|
+
(0, import_ai_employee_runtime.createAIEmployeeOptions)(ctx, employeeRecord, sessionId, {
|
|
257
|
+
llmService: service.name,
|
|
258
|
+
model: modelId
|
|
259
|
+
})
|
|
274
260
|
);
|
|
275
261
|
const result = await aiEmployee.invoke({ userMessages });
|
|
262
|
+
try {
|
|
263
|
+
await (lifecycle == null ? void 0 : lifecycle.runAfterHooks(runtimeContext, { succeeded: true, value: result }));
|
|
264
|
+
} finally {
|
|
265
|
+
lifecycleCompleted = true;
|
|
266
|
+
}
|
|
276
267
|
const content = extractLastAiMessageContent(result);
|
|
277
268
|
ctx.status = 200;
|
|
278
269
|
ctx.set("Content-Type", "application/json");
|
|
@@ -296,19 +287,28 @@ async function handleAgentCompletions(ctx, plugin) {
|
|
|
296
287
|
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 }
|
|
297
288
|
};
|
|
298
289
|
}
|
|
299
|
-
setImmediate(async () => {
|
|
300
|
-
try {
|
|
301
|
-
await ctx.db.getRepository("aiConversations").destroy({
|
|
302
|
-
filterByTk: sessionId
|
|
303
|
-
});
|
|
304
|
-
} catch {
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
290
|
} catch (err) {
|
|
291
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
292
|
+
if (runtimeContext && !lifecycleCompleted) {
|
|
293
|
+
await (lifecycle == null ? void 0 : lifecycle.runAfterHooks(runtimeContext, { succeeded: false, error }));
|
|
294
|
+
lifecycleCompleted = true;
|
|
295
|
+
}
|
|
308
296
|
ctx.log.error("AI API agent completions error:", err);
|
|
309
297
|
if (!ctx.res.headersSent) {
|
|
310
298
|
ctx.status = 500;
|
|
311
|
-
ctx.body = (0, import_openai_format.toOpenAIError)(500,
|
|
299
|
+
ctx.body = (0, import_openai_format.toOpenAIError)(500, error.message || "Internal server error", "server_error");
|
|
300
|
+
}
|
|
301
|
+
} finally {
|
|
302
|
+
if (ephemeralSessionId) {
|
|
303
|
+
const sessionId = ephemeralSessionId;
|
|
304
|
+
setImmediate(() => {
|
|
305
|
+
ctx.db.getRepository("aiConversations").destroy({ filterByTk: sessionId }).catch((cleanupError) => {
|
|
306
|
+
ctx.log.warn("AI API: Failed to clean up ephemeral conversation.", {
|
|
307
|
+
sessionId,
|
|
308
|
+
error: cleanupError instanceof Error ? cleanupError : new Error(String(cleanupError))
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var ai_employee_runtime_exports = {};
|
|
28
|
+
__export(ai_employee_runtime_exports, {
|
|
29
|
+
createAIEmployeeOptions: () => createAIEmployeeOptions,
|
|
30
|
+
getAgentRuntimeLifecycle: () => getAgentRuntimeLifecycle,
|
|
31
|
+
loadAIEmployeeConstructor: () => loadAIEmployeeConstructor
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(ai_employee_runtime_exports);
|
|
34
|
+
function getAgentRuntimeLifecycle(ctx) {
|
|
35
|
+
return ctx.app.agentRuntimeLifecycle;
|
|
36
|
+
}
|
|
37
|
+
let cachedConstructor = null;
|
|
38
|
+
async function loadAIEmployeeConstructor() {
|
|
39
|
+
if (cachedConstructor) return cachedConstructor;
|
|
40
|
+
const modulePath = "@nocobase/plugin-ai/dist/server/ai-employees/ai-employee.js";
|
|
41
|
+
const module2 = await import(
|
|
42
|
+
/* webpackIgnore: true */
|
|
43
|
+
modulePath
|
|
44
|
+
);
|
|
45
|
+
if (typeof module2.AIEmployee !== "function") {
|
|
46
|
+
throw new Error("AIEmployee class is not exported by the installed plugin-ai runtime.");
|
|
47
|
+
}
|
|
48
|
+
cachedConstructor = module2.AIEmployee;
|
|
49
|
+
return cachedConstructor;
|
|
50
|
+
}
|
|
51
|
+
function createAIEmployeeOptions(ctx, employee, sessionId, model) {
|
|
52
|
+
return { ctx, employee, sessionId, webSearch: false, model, legacy: false };
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
createAIEmployeeOptions,
|
|
57
|
+
getAgentRuntimeLifecycle,
|
|
58
|
+
loadAIEmployeeConstructor
|
|
59
|
+
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Context } from '@nocobase/actions';
|
|
2
|
+
import { createAIEmployeeOptions } from '../utils/ai-employee-runtime';
|
|
3
|
+
|
|
4
|
+
describe('AI API agent completions', () => {
|
|
5
|
+
it('creates the object-shaped options required by AIEmployee', () => {
|
|
6
|
+
const ctx = { app: {}, db: {} } as Context;
|
|
7
|
+
const employee = { username: 'support-agent' };
|
|
8
|
+
|
|
9
|
+
const options = createAIEmployeeOptions(ctx, employee, 'session-1', {
|
|
10
|
+
llmService: 'internal-deepseek',
|
|
11
|
+
model: 'deepseek-r1',
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
expect(options).toEqual({
|
|
15
|
+
ctx,
|
|
16
|
+
employee,
|
|
17
|
+
sessionId: 'session-1',
|
|
18
|
+
webSearch: false,
|
|
19
|
+
model: {
|
|
20
|
+
llmService: 'internal-deepseek',
|
|
21
|
+
model: 'deepseek-r1',
|
|
22
|
+
},
|
|
23
|
+
legacy: false,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|