ai-publish-sdk 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,6 +24,21 @@ await withTimeout(() => getUserInfo(), 10_000)
24
24
 
25
25
  ## Core API
26
26
 
27
+ ### getAllowedModels()
28
+
29
+ Get the list of allowed AI models and the default model configured by the admin.
30
+
31
+ ```typescript
32
+ getAllowedModels(config?: RpcConfig): Promise<AllowedModelsInfo>
33
+
34
+ interface AllowedModelsInfo {
35
+ models: string[]
36
+ defaultModel: string | null
37
+ }
38
+ ```
39
+
40
+ Returns an empty `models` array when no models are configured.
41
+
27
42
  ### getUserInfo()
28
43
 
29
44
  Get current user info.
@@ -73,6 +88,7 @@ generateMessage(prompt: string, options: GenerateMessageOptions): Promise<string
73
88
  interface GenerateMessageOptions {
74
89
  withPageContext?: boolean // include current page content as context
75
90
  systemPrompt?: string // guide AI behavior
91
+ model?: string // model name from getAllowedModels()
76
92
  }
77
93
  ```
78
94
 
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { generateMessage, getBrandingAssets, getToken, getUserInfo } from './lib/functions';
1
+ export { getAllowedModels, generateMessage, getBrandingAssets, getToken, getUserInfo } from './lib/functions';
2
2
  export { tcp } from './lib/tcp-socket';
3
3
  export type { TcpSocket } from './lib/tcp-socket';
4
4
  export { setGlobalTimeout, withTimeout } from './lib/rpc-bridge';
5
- export type { BrandingAssets, GenerateMessageOptions, GetTokenOptions, GetTokenResult, IntegrationAppName, UserInfo } from './lib/types';
5
+ export type { AllowedModelsInfo, BrandingAssets, GenerateMessageOptions, GetTokenOptions, GetTokenResult, IntegrationAppName, UserInfo } from './lib/types';
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let u=15e3;const c=new Map;let a=!1;function d(e){u=e}let i;function m(e,t){i=t;try{return e()}finally{i=void 0}}function f(){a||(a=!0,window.addEventListener("message",e=>{const t=e.data;if(!t?.messageId||!("name"in t))return;const n=c.get(t.messageId);n&&(clearTimeout(n.timer),c.delete(t.messageId),t.error?n.reject(new Error(t.error.message??"RPC error")):n.resolve(t.data))}))}function r(e,t){return f(),new Promise((n,s)=>{const o=crypto.randomUUID(),l=setTimeout(()=>{c.delete(o),s(new Error(`RPC timeout: ${e}`))},i??u);c.set(o,{resolve:n,reject:s,timer:l});const g={action:e,params:t,messageId:o};window.parent.postMessage(g,"*")})}async function y(e,t){return r("generateMessage",[e,t])}async function p(e,t){return r("getToken",[e,t])}async function w(){return r("getUserInfo",[])}async function T(){return r("getBrandingAssets",[])}async function v(e){return r("tcpConnect",[e])}async function I(e,t){return r("tcpSend",[e,t])}async function C(e,t){return r("tcpReceive",[e,t])}async function b(e){return r("tcpClose",[e])}const M={async connect(e,t){const n=await v({host:e,port:t});return n===null?null:{send:async s=>(await I(n,{dataBase64:s}))?.bytesSent??null,receive:async()=>(await C(n))?.data??null,close:()=>b(n)}}};exports.generateMessage=y;exports.getBrandingAssets=T;exports.getToken=p;exports.getUserInfo=w;exports.setGlobalTimeout=d;exports.tcp=M;exports.withTimeout=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let u=15e3;const c=new Map;let a=!1;function d(e){u=e}let i;function f(e,t){i=t;try{return e()}finally{i=void 0}}function m(){a||(a=!0,window.addEventListener("message",e=>{const t=e.data;if(!t?.messageId||!("name"in t))return;const n=c.get(t.messageId);n&&(clearTimeout(n.timer),c.delete(t.messageId),t.error?n.reject(new Error(t.error.message??"RPC error")):n.resolve(t.data))}))}function r(e,t){return m(),new Promise((n,s)=>{const o=crypto.randomUUID(),l=setTimeout(()=>{c.delete(o),s(new Error(`RPC timeout: ${e}`))},i??u);c.set(o,{resolve:n,reject:s,timer:l});const g={action:e,params:t,messageId:o};window.parent.postMessage(g,"*")})}async function y(){return r("getAllowedModels",[])}async function p(e,t){return r("generateMessage",[e,t])}async function w(e,t){return r("getToken",[e,t])}async function T(){return r("getUserInfo",[])}async function M(){return r("getBrandingAssets",[])}async function v(e){return r("tcpConnect",[e])}async function I(e,t){return r("tcpSend",[e,t])}async function C(e,t){return r("tcpReceive",[e,t])}async function b(e){return r("tcpClose",[e])}const A={async connect(e,t){const n=await v({host:e,port:t});return n===null?null:{send:async s=>(await I(n,{dataBase64:s}))?.bytesSent??null,receive:async()=>(await C(n))?.data??null,close:()=>b(n)}}};exports.generateMessage=p;exports.getAllowedModels=y;exports.getBrandingAssets=M;exports.getToken=w;exports.getUserInfo=T;exports.setGlobalTimeout=d;exports.tcp=A;exports.withTimeout=f;
package/index.mjs CHANGED
@@ -13,7 +13,7 @@ function v(e, t) {
13
13
  a = void 0;
14
14
  }
15
15
  }
16
- function d() {
16
+ function g() {
17
17
  i || (i = !0, window.addEventListener("message", (e) => {
18
18
  const t = e.data;
19
19
  if (!t?.messageId || !("name" in t)) return;
@@ -22,7 +22,7 @@ function d() {
22
22
  }));
23
23
  }
24
24
  function r(e, t) {
25
- return d(), new Promise((n, s) => {
25
+ return g(), new Promise((n, s) => {
26
26
  const o = crypto.randomUUID(), l = setTimeout(() => {
27
27
  c.delete(o), s(new Error(`RPC timeout: ${e}`));
28
28
  }, a ?? u);
@@ -31,17 +31,20 @@ function r(e, t) {
31
31
  reject: s,
32
32
  timer: l
33
33
  });
34
- const g = { action: e, params: t, messageId: o };
35
- window.parent.postMessage(g, "*");
34
+ const d = { action: e, params: t, messageId: o };
35
+ window.parent.postMessage(d, "*");
36
36
  });
37
37
  }
38
- async function C(e, t) {
39
- return r("generateMessage", [e, t]);
38
+ async function C() {
39
+ return r("getAllowedModels", []);
40
40
  }
41
41
  async function I(e, t) {
42
+ return r("generateMessage", [e, t]);
43
+ }
44
+ async function M(e, t) {
42
45
  return r("getToken", [e, t]);
43
46
  }
44
- async function M() {
47
+ async function A() {
45
48
  return r("getUserInfo", []);
46
49
  }
47
50
  async function R() {
@@ -53,10 +56,10 @@ async function f(e) {
53
56
  async function m(e, t) {
54
57
  return r("tcpSend", [e, t]);
55
58
  }
56
- async function p(e, t) {
59
+ async function y(e, t) {
57
60
  return r("tcpReceive", [e, t]);
58
61
  }
59
- async function y(e) {
62
+ async function p(e) {
60
63
  return r("tcpClose", [e]);
61
64
  }
62
65
  const U = {
@@ -72,16 +75,17 @@ const U = {
72
75
  const n = await f({ host: e, port: t });
73
76
  return n === null ? null : {
74
77
  send: async (s) => (await m(n, { dataBase64: s }))?.bytesSent ?? null,
75
- receive: async () => (await p(n))?.data ?? null,
76
- close: () => y(n)
78
+ receive: async () => (await y(n))?.data ?? null,
79
+ close: () => p(n)
77
80
  };
78
81
  }
79
82
  };
80
83
  export {
81
- C as generateMessage,
84
+ I as generateMessage,
85
+ C as getAllowedModels,
82
86
  R as getBrandingAssets,
83
- I as getToken,
84
- M as getUserInfo,
87
+ M as getToken,
88
+ A as getUserInfo,
85
89
  T as setGlobalTimeout,
86
90
  U as tcp,
87
91
  v as withTimeout
@@ -1,4 +1,5 @@
1
- import { BrandingAssets, GenerateMessageOptions, GetTokenOptions, GetTokenResult, IntegrationAppName, TcpConnectOptions, TcpConnectionSettings, TcpReceiveOptions, TcpReceiveResult, TcpSendMessage, TcpSendResult, UserInfo } from './types';
1
+ import { AllowedModelsInfo, BrandingAssets, GenerateMessageOptions, GetTokenOptions, GetTokenResult, IntegrationAppName, TcpConnectOptions, TcpConnectionSettings, TcpReceiveOptions, TcpReceiveResult, TcpSendMessage, TcpSendResult, UserInfo } from './types';
2
+ export declare function getAllowedModels(): Promise<AllowedModelsInfo>;
2
3
  export declare function generateMessage(prompt: string, options: GenerateMessageOptions): Promise<string | null>;
3
4
  export declare function getToken(appName: IntegrationAppName, options?: GetTokenOptions): Promise<GetTokenResult | null>;
4
5
  export declare function getUserInfo(): Promise<UserInfo | null>;
package/lib/types.d.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  export type IntegrationAppName = 'gmail' | 'jira' | 'googledrive' | 'salesforce' | 'googlecalendar' | 'slack';
2
+ export interface AllowedModelsInfo {
3
+ models: string[];
4
+ defaultModel: string | null;
5
+ }
2
6
  export interface GenerateMessageOptions {
3
7
  withPageContext?: boolean;
4
8
  systemPrompt?: string;
9
+ model?: string;
5
10
  }
6
11
  export interface GetTokenOptions {
7
12
  interactive?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-publish-sdk",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "module": "./index.mjs",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",