ai-publish-sdk 1.5.1 → 1.7.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.
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.
@@ -110,6 +110,56 @@ Execute JavaScript on the host page.
110
110
  executeScript(code: string): Promise<void>
111
111
  ```
112
112
 
113
+ ### trackEvent(params)
114
+
115
+ Emit structured analytics events from your app. The host auto-populates `timestamp`, `userId`, `email`, `userName`, `tenantId`, `application`, `appType` (widget / fullpage / sidepanel), and (sidepanel only) `activeSite` — you only supply the app-specific fields.
116
+
117
+ ```typescript
118
+ trackEvent(params: TrackEventParams): Promise<void>
119
+ ```
120
+
121
+ ## Device API
122
+
123
+ Each `device.*` method returns `null` if the device API is unavailable
124
+
125
+ ### device.getSnapshot(options?)
126
+
127
+ 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.
128
+
129
+ ```typescript
130
+ device.getSnapshot(options?: DeviceSnapshotOptions): Promise<DeviceSnapshot | null>
131
+ ```
132
+
133
+ `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`.
134
+
135
+ ### Granular getters
136
+
137
+ Each returns the same data as the corresponding field on `DeviceSnapshot`.
138
+
139
+ ```typescript
140
+ device.getSoftware(): Promise<SoftwareVersions | null> // browser/extension/OS versions
141
+ device.getDevice(): Promise<DeviceMetrics | null> // CPU, memory, displays, battery, processes
142
+ device.getBrowser(): Promise<BrowserMetrics | null> // tab count, window count, extensions
143
+ device.getNetwork(): Promise<NetworkInfo | null> // type, signal, IP, DNS, proxy latency
144
+ device.getTabs(): Promise<TabSnapshot[] | null> // per-tab URL, title, errors
145
+ device.getSiteStatus(options?: DeviceSnapshotOptions): Promise<SiteStatusInfo | null>
146
+ ```
147
+
148
+ ### device.getStatusPage(statusPageUrl)
149
+
150
+ Fetch the status of an arbitrary Statuspage.io-compatible page by URL.
151
+
152
+ ```typescript
153
+ device.getStatusPage(statusPageUrl: string): Promise<StatusPageResult | null>
154
+ ```
155
+
156
+ `StatusPageResult.indicator` ∈ `'none' | 'minor' | 'major' | 'critical' | 'unknown'`. `'unknown'` is returned when the page is unreachable or its response is unrecognized.
157
+
158
+ Example:
159
+ ```typescript
160
+ const status = await device.getStatusPage('https://www.githubstatus.com')
161
+ ```
162
+
113
163
  ## TCP API
114
164
 
115
165
  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, generateMessage, getAllowedModels, getBrandingAssets, getToken, getUserInfo, trackEvent } 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, SnakeCase, SoftwareVersions, StatusPageResult, TabSnapshot, TrackEventDetailValue, TrackEventDetails, TrackEventParams, 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 i=!1;function d(e){u=e}let a;function f(e,t){a=t;try{return e()}finally{a=void 0}}function m(){i||(i=!0,window.addEventListener("message",e=>{const t=e.data;if(!t?.messageId||!("name"in t))return;const r=c.get(t.messageId);r&&(clearTimeout(r.timer),c.delete(t.messageId),t.error?r.reject(new Error(t.error.message??"RPC error")):r.resolve(t.data))}))}function n(e,t){return m(),new Promise((r,s)=>{const o=crypto.randomUUID(),l=setTimeout(()=>{c.delete(o),s(new Error(`RPC timeout: ${e}`))},a??u);c.set(o,{resolve:r,reject:s,timer:l});const g={action:e,params:t,messageId:o};window.parent.postMessage(g,"*")})}async function v(){return n("getAllowedModels",[])}async function w(e,t){return n("generateMessage",[e,t])}async function y(e,t){return n("getToken",[e,t])}async function p(){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])}async function k(e){return n("trackEvent",[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 r=await T({host:e,port:t});return r===null?null:{send:async s=>(await G(r,{dataBase64:s}))?.bytesSent??null,receive:async()=>(await M(r))?.data??null,close:()=>b(r)}}};exports.device=I;exports.generateMessage=w;exports.getAllowedModels=v;exports.getBrandingAssets=S;exports.getToken=y;exports.getUserInfo=p;exports.setGlobalTimeout=d;exports.tcp=C;exports.trackEvent=k;exports.withTimeout=f;
package/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  let u = 15e3;
2
2
  const c = /* @__PURE__ */ new Map();
3
3
  let i = !1;
4
- function T(e) {
4
+ function y(e) {
5
5
  u = e;
6
6
  }
7
7
  let a;
8
- function v(e, t) {
8
+ function S(e, t) {
9
9
  a = t;
10
10
  try {
11
11
  return e();
@@ -17,17 +17,17 @@ 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;
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
28
  }, a ?? 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,46 @@ 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 k() {
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 v(e, t) {
60
+ return n("tcpReceive", [e, t]);
61
61
  }
62
- async function p(e) {
63
- return r("tcpClose", [e]);
62
+ async function w(e) {
63
+ return n("tcpClose", [e]);
64
64
  }
65
- const U = {
65
+ async function M(e) {
66
+ return n("trackEvent", [e]);
67
+ }
68
+ const b = {
69
+ getSnapshot: (e) => n("deviceGetSnapshot", [e]),
70
+ getSoftware: () => n("deviceGetSoftware", []),
71
+ getDevice: () => n("deviceGetDevice", []),
72
+ getBrowser: () => n("deviceGetBrowser", []),
73
+ getNetwork: () => n("deviceGetNetwork", []),
74
+ getTabs: () => n("deviceGetTabs", []),
75
+ getSiteStatus: (e) => n("deviceGetSiteStatus", [e]),
76
+ getStatusPage: (e) => n("deviceGetStatusPage", [e])
77
+ }, E = {
66
78
  /**
67
79
  * Opens a TCP connection and returns a `TcpSocket` wrapper.
68
80
  *
@@ -72,21 +84,23 @@ const U = {
72
84
  * security guarantees.
73
85
  */
74
86
  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)
87
+ const r = await f({ host: e, port: t });
88
+ return r === null ? null : {
89
+ send: async (s) => (await m(r, { dataBase64: s }))?.bytesSent ?? null,
90
+ receive: async () => (await v(r))?.data ?? null,
91
+ close: () => w(r)
80
92
  };
81
93
  }
82
94
  };
83
95
  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
96
+ b as device,
97
+ G as generateMessage,
98
+ T as getAllowedModels,
99
+ k as getBrandingAssets,
100
+ C as getToken,
101
+ I as getUserInfo,
102
+ y as setGlobalTimeout,
103
+ E as tcp,
104
+ M as trackEvent,
105
+ S as withTimeout
92
106
  };
@@ -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, TrackEventParams, 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,14 @@ 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 function trackEvent(params: TrackEventParams): Promise<void>;
13
+ export declare const device: {
14
+ getSnapshot: (options?: DeviceSnapshotOptions) => Promise<DeviceSnapshot | null>;
15
+ getSoftware: () => Promise<SoftwareVersions | null>;
16
+ getDevice: () => Promise<DeviceMetrics | null>;
17
+ getBrowser: () => Promise<BrowserMetrics | null>;
18
+ getNetwork: () => Promise<NetworkInfo | null>;
19
+ getTabs: () => Promise<TabSnapshot[] | null>;
20
+ getSiteStatus: (options?: DeviceSnapshotOptions) => Promise<SiteStatusInfo | null>;
21
+ getStatusPage: (statusPageUrl: string) => Promise<StatusPageResult | null>;
22
+ };
package/lib/types.d.ts CHANGED
@@ -50,3 +50,126 @@ 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 TrackEventParams {
125
+ eventName: SnakeCase<string>;
126
+ additionalDetails?: TrackEventDetails;
127
+ }
128
+ export interface DisplayUnit {
129
+ top: number;
130
+ left: number;
131
+ width: number;
132
+ height: number;
133
+ isPrimary: boolean;
134
+ isInternal: boolean;
135
+ isEnabled: boolean;
136
+ dpiX: number;
137
+ dpiY: number;
138
+ }
139
+ export interface ProcessInfo {
140
+ pid: number;
141
+ type: string;
142
+ title?: string;
143
+ cpuPercent?: number;
144
+ privateMemoryBytes?: number;
145
+ jsMemoryUsedBytes?: number;
146
+ }
147
+ export interface DesktopAppInfo {
148
+ name: string;
149
+ pid: number;
150
+ memoryBytes: number;
151
+ }
152
+ export interface InstalledExtension {
153
+ id: string;
154
+ name: string;
155
+ version: string;
156
+ enabled: boolean;
157
+ }
158
+ export interface FailedRequest {
159
+ url: string;
160
+ statusCode: number;
161
+ }
162
+ export interface CertError {
163
+ url: string;
164
+ errorCode: string;
165
+ }
166
+ export interface ConnectionError {
167
+ url: string;
168
+ errorCode: string;
169
+ reason: 'host-policy' | 'host-throttle' | 'other-extension' | 'network';
170
+ extensionId?: string;
171
+ }
172
+ export type SnakeCase<S extends string> = SnakeCaseInner<S> extends `_${infer Rest}` ? Rest : SnakeCaseInner<S>;
173
+ export type TrackEventDetails = Record<string, TrackEventDetailValue | Record<string, TrackEventDetailValue>>;
174
+ export type SnakeCaseInner<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Uppercase<T> ? '_' : ''}${Lowercase<T>}${SnakeCaseInner<U>}` : S;
175
+ export type TrackEventDetailValue = string | number | boolean | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-publish-sdk",
3
- "version": "1.5.1",
3
+ "version": "1.7.0",
4
4
  "module": "./index.mjs",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",