ai-publish-sdk 1.3.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,9 +88,20 @@ 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
 
95
+ ### getBrandingAssets()
96
+
97
+ Get tenant branding assets for white-label styling.
98
+
99
+ ```typescript
100
+ getBrandingAssets(): Promise<BrandingAssets | null>
101
+ ```
102
+
103
+ Returns `BrandingAssets` with fields: `logoUrl`, `darkLogoUrl`, `brandColor` (all `string | null`).
104
+
79
105
  ### executeScript(code)
80
106
 
81
107
  Execute JavaScript on the host page.
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { generateMessage, 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 { 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 m(e){u=e}let i;function d(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 p(e,t){return r("generateMessage",[e,t])}async function y(e,t){return r("getToken",[e,t])}async function w(){return r("getUserInfo",[])}async function T(e){return r("tcpConnect",[e])}async function v(e,t){return r("tcpSend",[e,t])}async function I(e,t){return r("tcpReceive",[e,t])}async function C(e){return r("tcpClose",[e])}const b={async connect(e,t){const n=await T({host:e,port:t});return n===null?null:{send:async s=>(await v(n,{dataBase64:s}))?.bytesSent??null,receive:async()=>(await I(n))?.data??null,close:()=>C(n)}}};exports.generateMessage=p;exports.getToken=y;exports.getUserInfo=w;exports.setGlobalTimeout=m;exports.tcp=b;exports.withTimeout=d;
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 m() {
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 m() {
22
22
  }));
23
23
  }
24
24
  function r(e, t) {
25
- return m(), 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);
@@ -35,28 +35,34 @@ function r(e, t) {
35
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
  }
50
+ async function R() {
51
+ return r("getBrandingAssets", []);
52
+ }
47
53
  async function f(e) {
48
54
  return r("tcpConnect", [e]);
49
55
  }
50
- async function g(e, t) {
56
+ async function m(e, t) {
51
57
  return r("tcpSend", [e, t]);
52
58
  }
53
- async function p(e, t) {
59
+ async function y(e, t) {
54
60
  return r("tcpReceive", [e, t]);
55
61
  }
56
- async function y(e) {
62
+ async function p(e) {
57
63
  return r("tcpClose", [e]);
58
64
  }
59
- const R = {
65
+ const U = {
60
66
  /**
61
67
  * Opens a TCP connection and returns a `TcpSocket` wrapper.
62
68
  *
@@ -68,17 +74,19 @@ const R = {
68
74
  async connect(e, t) {
69
75
  const n = await f({ host: e, port: t });
70
76
  return n === null ? null : {
71
- send: async (s) => (await g(n, { dataBase64: s }))?.bytesSent ?? null,
72
- receive: async () => (await p(n))?.data ?? null,
73
- close: () => y(n)
77
+ send: async (s) => (await m(n, { dataBase64: s }))?.bytesSent ?? null,
78
+ receive: async () => (await y(n))?.data ?? null,
79
+ close: () => p(n)
74
80
  };
75
81
  }
76
82
  };
77
83
  export {
78
- C as generateMessage,
79
- I as getToken,
80
- M as getUserInfo,
84
+ I as generateMessage,
85
+ C as getAllowedModels,
86
+ R as getBrandingAssets,
87
+ M as getToken,
88
+ A as getUserInfo,
81
89
  T as setGlobalTimeout,
82
- R as tcp,
90
+ U as tcp,
83
91
  v as withTimeout
84
92
  };
@@ -1,7 +1,9 @@
1
- import { 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>;
6
+ export declare function getBrandingAssets(): Promise<BrandingAssets | null>;
5
7
  export declare function executeScript(code: string): Promise<void>;
6
8
  export declare function tcpConnect(options: TcpConnectOptions): Promise<TcpConnectionSettings | null>;
7
9
  export declare function tcpSend(connection: TcpConnectionSettings, message: TcpSendMessage): Promise<TcpSendResult | 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;
@@ -21,6 +26,11 @@ export interface UserInfo {
21
26
  email?: string;
22
27
  picture?: string;
23
28
  }
29
+ export interface BrandingAssets {
30
+ logoUrl: string | null;
31
+ darkLogoUrl: string | null;
32
+ brandColor: string | null;
33
+ }
24
34
  export interface TcpConnectOptions {
25
35
  host: string;
26
36
  port: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-publish-sdk",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "module": "./index.mjs",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",