plugin-ai-api 1.0.7 → 1.0.9

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.
@@ -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&&(e=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/")),!e){var n=window.__webpack_public_path__||"";n&&("/"!==n.charAt(n.length-1)&&(n+="/"),e=n+"static/plugins/plugin-ai-api/dist/client/")}if(!e){var r=window.__nocobase_modern_client_prefix__||"v",o="/"+(r=String(r).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var i=window.location.pathname||"/",a=i.indexOf(o);e=a>=0?i.slice(0,a+1):"/"}e&&(e=e.replace(RegExp("/"+r+"/?$"),"/")),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}()});
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}()});
@@ -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&&(e=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/")),!e){var n=window.__webpack_public_path__||"";n&&("/"!==n.charAt(n.length-1)&&(n+="/"),e=n+"static/plugins/plugin-ai-api/dist/client-v2/")}if(!e){var r=window.__nocobase_modern_client_prefix__||"v",o="/"+(r=String(r).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var i=window.location.pathname||"/",a=i.indexOf(o);e=a>=0?i.slice(0,a+1):"/"}e&&(e=e.replace(RegExp("/"+r+"/?$"),"/")),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}()});
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}()});
@@ -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.6",
14
- "@nocobase/flow-engine": "2.1.6",
15
- "@nocobase/client": "2.1.6",
16
- "@nocobase/plugin-acl": "2.1.6",
17
- "@nocobase/server": "2.1.6",
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.6",
20
- "@nocobase/actions": "2.1.6",
21
- "@nocobase/resourcer": "2.1.6",
22
- "@nocobase/plugin-ai": "2.1.6"
19
+ "@nocobase/actions": "2.1.23",
20
+ "@nocobase/database": "2.1.23",
21
+ "@nocobase/resourcer": "2.1.23",
22
+ "@nocobase/plugin-ai": "2.1.23"
23
23
  };
@@ -0,0 +1,63 @@
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_api_usage_records_exports = {};
28
+ __export(ai_api_usage_records_exports, {
29
+ default: () => ai_api_usage_records_default
30
+ });
31
+ module.exports = __toCommonJS(ai_api_usage_records_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var ai_api_usage_records_default = (0, import_database.defineCollection)({
34
+ name: "aiApiUsageRecords",
35
+ autoGenId: true,
36
+ fields: [
37
+ { name: "requestId", type: "string", unique: true, index: true },
38
+ { name: "userId", type: "string", index: true },
39
+ { name: "roleName", type: "string", index: true },
40
+ { name: "authType", type: "string", index: true },
41
+ { name: "oauthClientId", type: "string", allowNull: true, index: true },
42
+ { name: "oauthSubject", type: "string", allowNull: true },
43
+ { name: "oauthScopes", type: "json", allowNull: true },
44
+ { name: "endpoint", type: "string" },
45
+ { name: "mode", type: "string", allowNull: true },
46
+ { name: "model", type: "string", allowNull: true, index: true },
47
+ { name: "status", type: "string", index: true },
48
+ { name: "httpStatus", type: "integer", allowNull: true },
49
+ { name: "errorCode", type: "string", allowNull: true },
50
+ { name: "streaming", type: "boolean", defaultValue: false },
51
+ { name: "inputTokens", type: "integer", allowNull: true },
52
+ { name: "outputTokens", type: "integer", allowNull: true },
53
+ { name: "totalTokens", type: "integer", allowNull: true },
54
+ { name: "estimatedCost", type: "decimal", allowNull: true, precision: 20, scale: 8 },
55
+ { name: "currency", type: "string", allowNull: true },
56
+ { name: "providerRequestId", type: "string", allowNull: true },
57
+ { name: "requestMetadata", type: "jsonb", defaultValue: {} },
58
+ { name: "responseMetadata", type: "jsonb", defaultValue: {} },
59
+ { name: "startedAt", type: "datetimeTz", allowNull: true },
60
+ { name: "completedAt", type: "datetimeTz", allowNull: true },
61
+ { name: "durationMs", type: "integer", allowNull: true }
62
+ ]
63
+ });
@@ -27,19 +27,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
27
27
  var role_permission_exports = {};
28
28
  __export(role_permission_exports, {
29
29
  checkEmployeeAccess: () => checkEmployeeAccess,
30
- checkRolePermission: () => checkRolePermission
30
+ checkRolePermission: () => checkRolePermission,
31
+ invalidateRolePermissionCache: () => invalidateRolePermissionCache
31
32
  });
32
33
  module.exports = __toCommonJS(role_permission_exports);
33
34
  var import_openai_format = require("../utils/openai-format");
35
+ const PERMISSION_TTL_MS = 15e3;
36
+ const permissionCache = /* @__PURE__ */ new Map();
37
+ function invalidateRolePermissionCache(roleName) {
38
+ if (roleName) permissionCache.delete(roleName);
39
+ else permissionCache.clear();
40
+ }
34
41
  async function checkRolePermission(ctx) {
35
42
  var _a;
36
43
  const roleName = ((_a = ctx.state.currentRoles) == null ? void 0 : _a[0]) || "member";
37
44
  if (roleName === "root" || roleName === "admin") {
38
45
  return true;
39
46
  }
40
- const record = await ctx.db.getRepository("aiApiRolePermissions").findOne({
41
- filter: { roleName }
42
- });
47
+ const cached = permissionCache.get(roleName);
48
+ const record = cached && cached.expiresAt > Date.now() ? cached.record : await ctx.db.getRepository("aiApiRolePermissions").findOne({ filter: { roleName } });
49
+ if (!cached || cached.expiresAt <= Date.now()) {
50
+ permissionCache.set(roleName, { record, expiresAt: Date.now() + PERMISSION_TTL_MS });
51
+ }
43
52
  if (!(record == null ? void 0 : record.enabled)) {
44
53
  ctx.status = 403;
45
54
  ctx.body = (0, import_openai_format.toOpenAIError)(
@@ -62,5 +71,6 @@ function checkEmployeeAccess(ctx, employeeUsername) {
62
71
  // Annotate the CommonJS export names for ESM import in node:
63
72
  0 && (module.exports = {
64
73
  checkEmployeeAccess,
65
- checkRolePermission
74
+ checkRolePermission,
75
+ invalidateRolePermissionCache
66
76
  });
@@ -44,6 +44,7 @@ var import_server = require("@nocobase/server");
44
44
  var import_router = require("./routes/router");
45
45
  var import_ai_api_config = __toESM(require("./resource/ai-api-config"));
46
46
  var import_rate_limiter = require("./utils/rate-limiter");
47
+ var import_role_permission = require("./middleware/role-permission");
47
48
  var import_dayjs = __toESM(require("dayjs"));
48
49
  var import_utc = __toESM(require("dayjs/plugin/utc"));
49
50
  var import_timezone = __toESM(require("dayjs/plugin/timezone"));
@@ -61,8 +62,14 @@ class PluginAiApiServer extends import_server.Plugin {
61
62
  async beforeLoad() {
62
63
  }
63
64
  async load() {
64
- this.app.use((0, import_router.createAiLlmRouter)(this), { before: "resourcer" });
65
+ this.app.use((0, import_router.createAiLlmRouter)(this), { after: "idp-oauth-resource-auth", before: "resourcer" });
65
66
  this.app.resourceManager.define(import_ai_api_config.default);
67
+ this.app.db.on("aiApiRolePermissions.afterSave", (model) => {
68
+ (0, import_role_permission.invalidateRolePermissionCache)(model.get("roleName"));
69
+ });
70
+ this.app.db.on("aiApiRolePermissions.afterDestroy", (model) => {
71
+ (0, import_role_permission.invalidateRolePermissionCache)(model.get("roleName"));
72
+ });
66
73
  this.app.acl.registerSnippet({
67
74
  name: `pm.${this.name}.configuration`,
68
75
  actions: ["aiApiConfig:*", "aiApiRolePermissions:*"]
@@ -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
- const mod = await import(
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
- employeeRecord,
236
- sessionId,
237
- void 0,
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
- employeeRecord,
268
- sessionId,
269
- void 0,
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, err.message || "Internal server error", "server_error");
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
  }
@@ -37,7 +37,7 @@ async function authenticateBearer(ctx) {
37
37
  ctx.status = 401;
38
38
  ctx.body = (0, import_openai_format.toOpenAIError)(
39
39
  401,
40
- "Missing or invalid Authorization header. Expected: Bearer <api-key>",
40
+ "Missing or invalid Authorization header. Expected: Bearer <access-token>",
41
41
  "invalid_request_error",
42
42
  "invalid_api_key"
43
43
  );
@@ -50,11 +50,16 @@ async function authenticateBearer(ctx) {
50
50
  return false;
51
51
  }
52
52
  try {
53
- const auth = ctx.app["authManager"];
54
- if (!auth) {
55
- ctx.status = 500;
56
- ctx.body = (0, import_openai_format.toOpenAIError)(500, "Auth system not available", "server_error");
57
- return false;
53
+ if (ctx.state.currentUser) {
54
+ if (!ctx.state.currentRole) {
55
+ const requestedRole = ctx.get("X-Role");
56
+ const rolesRepository2 = ctx.db.getRepository("users.roles", ctx.state.currentUser.id);
57
+ const roles2 = await rolesRepository2.find({ fields: ["name"] });
58
+ const roleNames2 = roles2.map((role) => role.name);
59
+ ctx.state.currentRole = roleNames2.includes(requestedRole) ? requestedRole : roleNames2[0];
60
+ ctx.state.currentRoles = ctx.state.currentRole ? [ctx.state.currentRole] : roleNames2;
61
+ }
62
+ return true;
58
63
  }
59
64
  const jwt = (_a = ctx.app["authManager"]) == null ? void 0 : _a.jwt;
60
65
  if (!jwt) {
@@ -75,6 +80,16 @@ async function authenticateBearer(ctx) {
75
80
  ctx.body = (0, import_openai_format.toOpenAIError)(401, "Invalid or expired API key", "invalid_request_error", "invalid_api_key");
76
81
  return false;
77
82
  }
83
+ if (!decoded.roleName) {
84
+ ctx.status = 401;
85
+ ctx.body = (0, import_openai_format.toOpenAIError)(
86
+ 401,
87
+ "Token was not resolved by the NocoBase auth middleware",
88
+ "invalid_request_error",
89
+ "invalid_api_key"
90
+ );
91
+ return false;
92
+ }
78
93
  const user = await ctx.db.getRepository("users").findOne({
79
94
  filterByTk: decoded.userId
80
95
  });
@@ -84,7 +99,22 @@ async function authenticateBearer(ctx) {
84
99
  return false;
85
100
  }
86
101
  ctx.state.currentUser = user;
87
- ctx.state.currentRoles = decoded.roleName ? [decoded.roleName] : ["member"];
102
+ const rolesRepository = ctx.db.getRepository("users.roles", user.id);
103
+ const roles = await rolesRepository.find({ fields: ["name"] });
104
+ const roleNames = roles.map((role) => role.name);
105
+ if (!roleNames.includes(decoded.roleName)) {
106
+ ctx.status = 403;
107
+ ctx.body = (0, import_openai_format.toOpenAIError)(
108
+ 403,
109
+ "The API key role is no longer assigned to this user",
110
+ "permission_denied",
111
+ "role_not_permitted"
112
+ );
113
+ return false;
114
+ }
115
+ ctx.state.currentRole = decoded.roleName;
116
+ ctx.state.currentRoles = [decoded.roleName];
117
+ ctx.state.aiApiAuthType = "apiKey";
88
118
  if (!ctx.auth) {
89
119
  ctx.auth = {};
90
120
  }
@@ -49,11 +49,12 @@ var import_embeddings = require("./embeddings");
49
49
  var import_openai_format = require("../utils/openai-format");
50
50
  var import_rate_limit = require("../middleware/rate-limit");
51
51
  var import_role_permission = require("../middleware/role-permission");
52
+ var import_usage = require("../usage");
52
53
  const API_PREFIX = "/api/ai-llm/v1";
53
54
  function createAiLlmRouter(plugin) {
54
55
  const checkRateLimit = (0, import_rate_limit.createRateLimitMiddleware)(plugin.rateLimiter);
55
56
  return async (ctx, next) => {
56
- var _a;
57
+ var _a, _b;
57
58
  const { path, method } = ctx;
58
59
  if (!path.startsWith(API_PREFIX)) {
59
60
  return next();
@@ -100,6 +101,18 @@ function createAiLlmRouter(plugin) {
100
101
  }
101
102
  const model = ((_a = ctx.request.body) == null ? void 0 : _a.model) ?? "-";
102
103
  const t0 = Date.now();
104
+ let usageId;
105
+ try {
106
+ usageId = await (0, import_usage.startUsageRecord)(
107
+ ctx,
108
+ requestId,
109
+ subPath,
110
+ String(model),
111
+ Boolean((_b = ctx.request.body) == null ? void 0 : _b.stream)
112
+ );
113
+ } catch (usageError) {
114
+ ctx.log.error("AI API usage record could not be created:", usageError);
115
+ }
103
116
  try {
104
117
  if (method === "POST" && subPath === "/chat/completions") {
105
118
  const mode = await resolveMode(ctx);
@@ -166,6 +179,14 @@ function createAiLlmRouter(plugin) {
166
179
  ctx.status = 500;
167
180
  ctx.body = (0, import_openai_format.toOpenAIError)(500, err.message || "Internal server error", "server_error");
168
181
  }
182
+ } finally {
183
+ if (usageId !== void 0) {
184
+ try {
185
+ await (0, import_usage.finishUsageRecord)(ctx, usageId, t0, ctx.status >= 200 && ctx.status < 400 ? "succeeded" : "failed");
186
+ } catch (usageError) {
187
+ ctx.log.error("AI API usage record could not be finalized:", usageError);
188
+ }
189
+ }
169
190
  }
170
191
  };
171
192
  }
@@ -0,0 +1,80 @@
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 usage_exports = {};
28
+ __export(usage_exports, {
29
+ finishUsageRecord: () => finishUsageRecord,
30
+ startUsageRecord: () => startUsageRecord
31
+ });
32
+ module.exports = __toCommonJS(usage_exports);
33
+ async function startUsageRecord(ctx, requestId, endpoint, model, streaming) {
34
+ var _a, _b;
35
+ const body = ctx.request.body || {};
36
+ const messages = Array.isArray(body.messages) ? body.messages : void 0;
37
+ const oauth = ctx.state.oauthPrincipal;
38
+ const record = await ctx.db.getRepository("aiApiUsageRecords").create({
39
+ values: {
40
+ requestId,
41
+ userId: String((_a = ctx.state.currentUser) == null ? void 0 : _a.id),
42
+ roleName: ctx.state.currentRole || ((_b = ctx.state.currentRoles) == null ? void 0 : _b[0]) || "unknown",
43
+ authType: ctx.state.aiApiAuthType || (oauth ? "oidc" : "session"),
44
+ oauthClientId: oauth == null ? void 0 : oauth.clientId,
45
+ oauthSubject: oauth == null ? void 0 : oauth.subject,
46
+ oauthScopes: oauth == null ? void 0 : oauth.scopes,
47
+ endpoint,
48
+ mode: ctx.get("X-AI-Mode") || void 0,
49
+ model: model === "-" ? void 0 : model,
50
+ status: "pending",
51
+ streaming,
52
+ startedAt: /* @__PURE__ */ new Date(),
53
+ requestMetadata: { messageCount: messages == null ? void 0 : messages.length, requestedMaxTokens: body.max_tokens }
54
+ }
55
+ });
56
+ return record.id;
57
+ }
58
+ async function finishUsageRecord(ctx, id, startedAt, status) {
59
+ var _a;
60
+ const response = ctx.body || {};
61
+ const usage = response.usage;
62
+ const values = {
63
+ status,
64
+ httpStatus: ctx.status,
65
+ errorCode: (_a = response.error) == null ? void 0 : _a.code,
66
+ inputTokens: usage == null ? void 0 : usage.prompt_tokens,
67
+ outputTokens: usage == null ? void 0 : usage.completion_tokens,
68
+ totalTokens: usage == null ? void 0 : usage.total_tokens,
69
+ providerRequestId: response.id,
70
+ completedAt: /* @__PURE__ */ new Date(),
71
+ durationMs: Date.now() - startedAt,
72
+ responseMetadata: { usageSource: usage ? "response" : "unavailable" }
73
+ };
74
+ await ctx.db.getRepository("aiApiUsageRecords").update({ filterByTk: id, values });
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ finishUsageRecord,
79
+ startUsageRecord
80
+ });