ai-publish-sdk 1.5.0 → 1.6.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,21 +24,6 @@ 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
-
42
27
  ### getUserInfo()
43
28
 
44
29
  Get current user info.
@@ -78,6 +63,21 @@ interface GetTokenResult {
78
63
  }
79
64
  ```
80
65
 
66
+ ### getAllowedModels()
67
+
68
+ Get the list of allowed AI models and the default model.
69
+
70
+ ```typescript
71
+ getAllowedModels(): Promise<AllowedModelsInfo>
72
+
73
+ interface AllowedModelsInfo {
74
+ models: string[]
75
+ defaultModel: string | null
76
+ }
77
+ ```
78
+
79
+ Returns an empty `models` array when no models are configured.
80
+
81
81
  ### generateMessage(prompt, options)
82
82
 
83
83
  Generate an AI message.
@@ -94,7 +94,7 @@ interface GenerateMessageOptions {
94
94
 
95
95
  ### getBrandingAssets()
96
96
 
97
- Get tenant branding assets for white-label styling.
97
+ Get branding assets for white-label styling.
98
98
 
99
99
  ```typescript
100
100
  getBrandingAssets(): Promise<BrandingAssets | null>
@@ -110,6 +110,48 @@ Execute JavaScript on the host page.
110
110
  executeScript(code: string): Promise<void>
111
111
  ```
112
112
 
113
+ ## Device API
114
+
115
+ Each `device.*` method returns `null` if the device API is unavailable
116
+
117
+ ### device.getSnapshot(options?)
118
+
119
+ Get a full snapshot covering all sections in one call. Convenient for debugging or one-shot dumps; for repeated polling prefer the granular getters below.
120
+
121
+ ```typescript
122
+ device.getSnapshot(options?: DeviceSnapshotOptions): Promise<DeviceSnapshot | null>
123
+ ```
124
+
125
+ `DeviceSnapshot` contains: `software`, `device`, `browser`, `network`, `tabs`, `siteStatus`. Pass `options.knownStatusPages` (a `domain → statusPageUrl` map) to also resolve a status page for the active tab into `siteStatus.currentSiteStatus`.
126
+
127
+ ### Granular getters
128
+
129
+ Each returns the same data as the corresponding field on `DeviceSnapshot`.
130
+
131
+ ```typescript
132
+ device.getSoftware(): Promise<SoftwareVersions | null> // browser/extension/OS versions
133
+ device.getDevice(): Promise<DeviceMetrics | null> // CPU, memory, displays, battery, processes
134
+ device.getBrowser(): Promise<BrowserMetrics | null> // tab count, window count, extensions
135
+ device.getNetwork(): Promise<NetworkInfo | null> // type, signal, IP, DNS, proxy latency
136
+ device.getTabs(): Promise<TabSnapshot[] | null> // per-tab URL, title, errors
137
+ device.getSiteStatus(options?: DeviceSnapshotOptions): Promise<SiteStatusInfo | null>
138
+ ```
139
+
140
+ ### device.getStatusPage(statusPageUrl)
141
+
142
+ Fetch the status of an arbitrary Statuspage.io-compatible page by URL.
143
+
144
+ ```typescript
145
+ device.getStatusPage(statusPageUrl: string): Promise<StatusPageResult | null>
146
+ ```
147
+
148
+ `StatusPageResult.indicator` ∈ `'none' | 'minor' | 'major' | 'critical' | 'unknown'`. `'unknown'` is returned when the page is unreachable or its response is unrecognized.
149
+
150
+ Example:
151
+ ```typescript
152
+ const status = await device.getStatusPage('https://www.githubstatus.com')
153
+ ```
154
+
113
155
  ## TCP API
114
156
 
115
157
  All data is base64-encoded. Import as `import { tcp }`.
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { getAllowedModels, generateMessage, getBrandingAssets, getToken, getUserInfo } from './lib/functions';
1
+ export { device, 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 { AllowedModelsInfo, BrandingAssets, GenerateMessageOptions, GetTokenOptions, GetTokenResult, IntegrationAppName, UserInfo } from './lib/types';
5
+ export type { AllowedModelsInfo, BrandingAssets, BrowserMetrics, CertError, ConnectionError, DesktopAppInfo, DeviceMetrics, DeviceSnapshot, DeviceSnapshotOptions, DisplayUnit, FailedRequest, GenerateMessageOptions, GetTokenOptions, GetTokenResult, InstalledExtension, IntegrationAppName, NetworkInfo, ProcessInfo, SiteStatusInfo, SoftwareVersions, StatusPageResult, TabSnapshot, 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 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;
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 s=c.get(t.messageId);s&&(clearTimeout(s.timer),c.delete(t.messageId),t.error?s.reject(new Error(t.error.message??"RPC error")):s.resolve(t.data))}))}function n(e,t){return m(),new Promise((s,r)=>{const o=crypto.randomUUID(),l=setTimeout(()=>{c.delete(o),r(new Error(`RPC timeout: ${e}`))},i??u);c.set(o,{resolve:s,reject:r,timer:l});const g={action:e,params:t,messageId:o};window.parent.postMessage(g,"*")})}async function w(){return n("getAllowedModels",[])}async function v(e,t){return n("generateMessage",[e,t])}async function p(e,t){return n("getToken",[e,t])}async function y(){return n("getUserInfo",[])}async function S(){return n("getBrandingAssets",[])}async function T(e){return n("tcpConnect",[e])}async function G(e,t){return n("tcpSend",[e,t])}async function M(e,t){return n("tcpReceive",[e,t])}async function b(e){return n("tcpClose",[e])}const I={getSnapshot:e=>n("deviceGetSnapshot",[e]),getSoftware:()=>n("deviceGetSoftware",[]),getDevice:()=>n("deviceGetDevice",[]),getBrowser:()=>n("deviceGetBrowser",[]),getNetwork:()=>n("deviceGetNetwork",[]),getTabs:()=>n("deviceGetTabs",[]),getSiteStatus:e=>n("deviceGetSiteStatus",[e]),getStatusPage:e=>n("deviceGetStatusPage",[e])},C={async connect(e,t){const s=await T({host:e,port:t});return s===null?null:{send:async r=>(await G(s,{dataBase64:r}))?.bytesSent??null,receive:async()=>(await M(s))?.data??null,close:()=>b(s)}}};exports.device=I;exports.generateMessage=v;exports.getAllowedModels=w;exports.getBrandingAssets=S;exports.getToken=p;exports.getUserInfo=y;exports.setGlobalTimeout=d;exports.tcp=C;exports.withTimeout=f;
package/index.mjs CHANGED
@@ -1,33 +1,33 @@
1
1
  let u = 15e3;
2
2
  const c = /* @__PURE__ */ new Map();
3
- let i = !1;
4
- function T(e) {
3
+ let a = !1;
4
+ function y(e) {
5
5
  u = e;
6
6
  }
7
- let a;
8
- function v(e, t) {
9
- a = t;
7
+ let i;
8
+ function S(e, t) {
9
+ i = t;
10
10
  try {
11
11
  return e();
12
12
  } finally {
13
- a = void 0;
13
+ i = void 0;
14
14
  }
15
15
  }
16
16
  function g() {
17
- i || (i = !0, window.addEventListener("message", (e) => {
17
+ a || (a = !0, window.addEventListener("message", (e) => {
18
18
  const t = e.data;
19
19
  if (!t?.messageId || !("name" in t)) return;
20
- const n = c.get(t.messageId);
21
- n && (clearTimeout(n.timer), c.delete(t.messageId), t.error ? n.reject(new Error(t.error.message ?? "RPC error")) : n.resolve(t.data));
20
+ const r = c.get(t.messageId);
21
+ r && (clearTimeout(r.timer), c.delete(t.messageId), t.error ? r.reject(new Error(t.error.message ?? "RPC error")) : r.resolve(t.data));
22
22
  }));
23
23
  }
24
- function r(e, t) {
25
- return g(), new Promise((n, s) => {
24
+ function n(e, t) {
25
+ return g(), new Promise((r, s) => {
26
26
  const o = crypto.randomUUID(), l = setTimeout(() => {
27
27
  c.delete(o), s(new Error(`RPC timeout: ${e}`));
28
- }, a ?? u);
28
+ }, i ?? u);
29
29
  c.set(o, {
30
- resolve: n,
30
+ resolve: r,
31
31
  reject: s,
32
32
  timer: l
33
33
  });
@@ -35,34 +35,43 @@ function r(e, t) {
35
35
  window.parent.postMessage(d, "*");
36
36
  });
37
37
  }
38
- async function C() {
39
- return r("getAllowedModels", []);
38
+ async function T() {
39
+ return n("getAllowedModels", []);
40
40
  }
41
- async function I(e, t) {
42
- return r("generateMessage", [e, t]);
41
+ async function G(e, t) {
42
+ return n("generateMessage", [e, t]);
43
43
  }
44
- async function M(e, t) {
45
- return r("getToken", [e, t]);
44
+ async function C(e, t) {
45
+ return n("getToken", [e, t]);
46
46
  }
47
- async function A() {
48
- return r("getUserInfo", []);
47
+ async function I() {
48
+ return n("getUserInfo", []);
49
49
  }
50
- async function R() {
51
- return r("getBrandingAssets", []);
50
+ async function M() {
51
+ return n("getBrandingAssets", []);
52
52
  }
53
53
  async function f(e) {
54
- return r("tcpConnect", [e]);
54
+ return n("tcpConnect", [e]);
55
55
  }
56
56
  async function m(e, t) {
57
- return r("tcpSend", [e, t]);
57
+ return n("tcpSend", [e, t]);
58
58
  }
59
- async function y(e, t) {
60
- return r("tcpReceive", [e, t]);
59
+ async function w(e, t) {
60
+ return n("tcpReceive", [e, t]);
61
61
  }
62
62
  async function p(e) {
63
- return r("tcpClose", [e]);
63
+ return n("tcpClose", [e]);
64
64
  }
65
- const U = {
65
+ const b = {
66
+ getSnapshot: (e) => n("deviceGetSnapshot", [e]),
67
+ getSoftware: () => n("deviceGetSoftware", []),
68
+ getDevice: () => n("deviceGetDevice", []),
69
+ getBrowser: () => n("deviceGetBrowser", []),
70
+ getNetwork: () => n("deviceGetNetwork", []),
71
+ getTabs: () => n("deviceGetTabs", []),
72
+ getSiteStatus: (e) => n("deviceGetSiteStatus", [e]),
73
+ getStatusPage: (e) => n("deviceGetStatusPage", [e])
74
+ }, P = {
66
75
  /**
67
76
  * Opens a TCP connection and returns a `TcpSocket` wrapper.
68
77
  *
@@ -72,21 +81,22 @@ const U = {
72
81
  * security guarantees.
73
82
  */
74
83
  async connect(e, t) {
75
- const n = await f({ host: e, port: t });
76
- return n === null ? null : {
77
- send: async (s) => (await m(n, { dataBase64: s }))?.bytesSent ?? null,
78
- receive: async () => (await y(n))?.data ?? null,
79
- close: () => p(n)
84
+ const r = await f({ host: e, port: t });
85
+ return r === null ? null : {
86
+ send: async (s) => (await m(r, { dataBase64: s }))?.bytesSent ?? null,
87
+ receive: async () => (await w(r))?.data ?? null,
88
+ close: () => p(r)
80
89
  };
81
90
  }
82
91
  };
83
92
  export {
84
- I as generateMessage,
85
- C as getAllowedModels,
86
- R as getBrandingAssets,
87
- M as getToken,
88
- A as getUserInfo,
89
- T as setGlobalTimeout,
90
- U as tcp,
91
- v as withTimeout
93
+ b as device,
94
+ G as generateMessage,
95
+ T as getAllowedModels,
96
+ M as getBrandingAssets,
97
+ C as getToken,
98
+ I as getUserInfo,
99
+ y as setGlobalTimeout,
100
+ P as tcp,
101
+ S as withTimeout
92
102
  };
@@ -1,4 +1,4 @@
1
- import { AllowedModelsInfo, BrandingAssets, GenerateMessageOptions, GetTokenOptions, GetTokenResult, IntegrationAppName, TcpConnectOptions, TcpConnectionSettings, TcpReceiveOptions, TcpReceiveResult, TcpSendMessage, TcpSendResult, UserInfo } from './types';
1
+ import { AllowedModelsInfo, BrandingAssets, BrowserMetrics, DeviceMetrics, DeviceSnapshot, DeviceSnapshotOptions, GenerateMessageOptions, GetTokenOptions, GetTokenResult, IntegrationAppName, NetworkInfo, SiteStatusInfo, SoftwareVersions, StatusPageResult, TabSnapshot, TcpConnectOptions, TcpConnectionSettings, TcpReceiveOptions, TcpReceiveResult, TcpSendMessage, TcpSendResult, UserInfo } from './types';
2
2
  export declare function getAllowedModels(): Promise<AllowedModelsInfo>;
3
3
  export declare function generateMessage(prompt: string, options: GenerateMessageOptions): Promise<string | null>;
4
4
  export declare function getToken(appName: IntegrationAppName, options?: GetTokenOptions): Promise<GetTokenResult | null>;
@@ -9,3 +9,13 @@ export declare function tcpConnect(options: TcpConnectOptions): Promise<TcpConne
9
9
  export declare function tcpSend(connection: TcpConnectionSettings, message: TcpSendMessage): Promise<TcpSendResult | null>;
10
10
  export declare function tcpReceive(connection: TcpConnectionSettings, options?: TcpReceiveOptions): Promise<TcpReceiveResult | null>;
11
11
  export declare function tcpClose(connection: TcpConnectionSettings): Promise<void>;
12
+ export declare const device: {
13
+ getSnapshot: (options?: DeviceSnapshotOptions) => Promise<DeviceSnapshot | null>;
14
+ getSoftware: () => Promise<SoftwareVersions | null>;
15
+ getDevice: () => Promise<DeviceMetrics | null>;
16
+ getBrowser: () => Promise<BrowserMetrics | null>;
17
+ getNetwork: () => Promise<NetworkInfo | null>;
18
+ getTabs: () => Promise<TabSnapshot[] | null>;
19
+ getSiteStatus: (options?: DeviceSnapshotOptions) => Promise<SiteStatusInfo | null>;
20
+ getStatusPage: (statusPageUrl: string) => Promise<StatusPageResult | null>;
21
+ };
package/lib/types.d.ts CHANGED
@@ -50,3 +50,118 @@ export interface TcpReceiveOptions {
50
50
  export interface TcpReceiveResult {
51
51
  data: string;
52
52
  }
53
+ export interface DeviceSnapshotOptions {
54
+ knownStatusPages?: Record<string, string>;
55
+ }
56
+ export interface DeviceSnapshot {
57
+ software: SoftwareVersions;
58
+ device: DeviceMetrics;
59
+ browser: BrowserMetrics;
60
+ network: NetworkInfo;
61
+ tabs: TabSnapshot[];
62
+ siteStatus: SiteStatusInfo;
63
+ }
64
+ export interface SoftwareVersions {
65
+ browserVersion: string;
66
+ extensionVersion: string;
67
+ agentVersion?: string;
68
+ osVersion?: string;
69
+ deviceModel?: string;
70
+ deviceHostName?: string;
71
+ }
72
+ export interface DeviceMetrics {
73
+ cpuModel: string;
74
+ architecture: string;
75
+ numOfProcessors: number;
76
+ totalMemoryMb: number;
77
+ diskStorageGb?: number;
78
+ displays: DisplayUnit[];
79
+ batteryPercent?: number;
80
+ isCharging?: boolean;
81
+ isPowerSavingMode?: boolean;
82
+ lastRebootTime?: string;
83
+ processes: ProcessInfo[];
84
+ desktopApps?: DesktopAppInfo[];
85
+ }
86
+ export interface BrowserMetrics {
87
+ tabCount: number;
88
+ windowCount: number;
89
+ extensions: InstalledExtension[];
90
+ proxyConfig?: string;
91
+ }
92
+ export interface NetworkInfo {
93
+ type: 'WiFi' | 'Ethernet' | 'Unknown';
94
+ isOnline: boolean;
95
+ wifiSignalDbm?: number;
96
+ ssid?: string;
97
+ ipAddress?: string;
98
+ gateway?: string;
99
+ dnsServers?: string[];
100
+ ipaProxyLatencyMs?: number;
101
+ ipaProxyAddress?: string;
102
+ }
103
+ export interface TabSnapshot {
104
+ tabId: number;
105
+ url: string;
106
+ title: string;
107
+ isActive: boolean;
108
+ isUnresponsive?: boolean;
109
+ isCrashed?: boolean;
110
+ failedHttpRequests?: FailedRequest[];
111
+ failedDnsLookups?: string[];
112
+ certErrors?: CertError[];
113
+ connectionErrors?: ConnectionError[];
114
+ }
115
+ export interface SiteStatusInfo {
116
+ hostStatus: StatusPageResult;
117
+ currentSiteStatus: StatusPageResult | null;
118
+ }
119
+ export interface StatusPageResult {
120
+ indicator: 'none' | 'minor' | 'major' | 'critical' | 'unknown';
121
+ description: string;
122
+ domain: string;
123
+ }
124
+ export interface DisplayUnit {
125
+ top: number;
126
+ left: number;
127
+ width: number;
128
+ height: number;
129
+ isPrimary: boolean;
130
+ isInternal: boolean;
131
+ isEnabled: boolean;
132
+ dpiX: number;
133
+ dpiY: number;
134
+ }
135
+ export interface ProcessInfo {
136
+ pid: number;
137
+ type: string;
138
+ title?: string;
139
+ cpuPercent?: number;
140
+ privateMemoryBytes?: number;
141
+ jsMemoryUsedBytes?: number;
142
+ }
143
+ export interface DesktopAppInfo {
144
+ name: string;
145
+ pid: number;
146
+ memoryBytes: number;
147
+ }
148
+ export interface InstalledExtension {
149
+ id: string;
150
+ name: string;
151
+ version: string;
152
+ enabled: boolean;
153
+ }
154
+ export interface FailedRequest {
155
+ url: string;
156
+ statusCode: number;
157
+ }
158
+ export interface CertError {
159
+ url: string;
160
+ errorCode: string;
161
+ }
162
+ export interface ConnectionError {
163
+ url: string;
164
+ errorCode: string;
165
+ reason: 'host-policy' | 'host-throttle' | 'other-extension' | 'network';
166
+ extensionId?: string;
167
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-publish-sdk",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "module": "./index.mjs",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",