ai-publish-sdk 1.6.0 → 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 +8 -0
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/index.mjs +18 -14
- package/lib/functions.d.ts +2 -1
- package/lib/types.d.ts +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,6 +110,14 @@ 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
|
+
|
|
113
121
|
## Device API
|
|
114
122
|
|
|
115
123
|
Each `device.*` method returns `null` if the device API is unavailable
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { device,
|
|
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, BrowserMetrics, CertError, ConnectionError, DesktopAppInfo, DeviceMetrics, DeviceSnapshot, DeviceSnapshotOptions, DisplayUnit, FailedRequest, GenerateMessageOptions, GetTokenOptions, GetTokenResult, InstalledExtension, IntegrationAppName, NetworkInfo, ProcessInfo, SiteStatusInfo, SoftwareVersions, StatusPageResult, TabSnapshot, 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
|
|
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,20 +1,20 @@
|
|
|
1
1
|
let u = 15e3;
|
|
2
2
|
const c = /* @__PURE__ */ new Map();
|
|
3
|
-
let
|
|
3
|
+
let i = !1;
|
|
4
4
|
function y(e) {
|
|
5
5
|
u = e;
|
|
6
6
|
}
|
|
7
|
-
let
|
|
7
|
+
let a;
|
|
8
8
|
function S(e, t) {
|
|
9
|
-
|
|
9
|
+
a = t;
|
|
10
10
|
try {
|
|
11
11
|
return e();
|
|
12
12
|
} finally {
|
|
13
|
-
|
|
13
|
+
a = void 0;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
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;
|
|
20
20
|
const r = c.get(t.messageId);
|
|
@@ -25,7 +25,7 @@ function n(e, t) {
|
|
|
25
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
30
|
resolve: r,
|
|
31
31
|
reject: s,
|
|
@@ -47,7 +47,7 @@ async function C(e, t) {
|
|
|
47
47
|
async function I() {
|
|
48
48
|
return n("getUserInfo", []);
|
|
49
49
|
}
|
|
50
|
-
async function
|
|
50
|
+
async function k() {
|
|
51
51
|
return n("getBrandingAssets", []);
|
|
52
52
|
}
|
|
53
53
|
async function f(e) {
|
|
@@ -56,12 +56,15 @@ async function f(e) {
|
|
|
56
56
|
async function m(e, t) {
|
|
57
57
|
return n("tcpSend", [e, t]);
|
|
58
58
|
}
|
|
59
|
-
async function
|
|
59
|
+
async function v(e, t) {
|
|
60
60
|
return n("tcpReceive", [e, t]);
|
|
61
61
|
}
|
|
62
|
-
async function
|
|
62
|
+
async function w(e) {
|
|
63
63
|
return n("tcpClose", [e]);
|
|
64
64
|
}
|
|
65
|
+
async function M(e) {
|
|
66
|
+
return n("trackEvent", [e]);
|
|
67
|
+
}
|
|
65
68
|
const b = {
|
|
66
69
|
getSnapshot: (e) => n("deviceGetSnapshot", [e]),
|
|
67
70
|
getSoftware: () => n("deviceGetSoftware", []),
|
|
@@ -71,7 +74,7 @@ const b = {
|
|
|
71
74
|
getTabs: () => n("deviceGetTabs", []),
|
|
72
75
|
getSiteStatus: (e) => n("deviceGetSiteStatus", [e]),
|
|
73
76
|
getStatusPage: (e) => n("deviceGetStatusPage", [e])
|
|
74
|
-
},
|
|
77
|
+
}, E = {
|
|
75
78
|
/**
|
|
76
79
|
* Opens a TCP connection and returns a `TcpSocket` wrapper.
|
|
77
80
|
*
|
|
@@ -84,8 +87,8 @@ const b = {
|
|
|
84
87
|
const r = await f({ host: e, port: t });
|
|
85
88
|
return r === null ? null : {
|
|
86
89
|
send: async (s) => (await m(r, { dataBase64: s }))?.bytesSent ?? null,
|
|
87
|
-
receive: async () => (await
|
|
88
|
-
close: () =>
|
|
90
|
+
receive: async () => (await v(r))?.data ?? null,
|
|
91
|
+
close: () => w(r)
|
|
89
92
|
};
|
|
90
93
|
}
|
|
91
94
|
};
|
|
@@ -93,10 +96,11 @@ export {
|
|
|
93
96
|
b as device,
|
|
94
97
|
G as generateMessage,
|
|
95
98
|
T as getAllowedModels,
|
|
96
|
-
|
|
99
|
+
k as getBrandingAssets,
|
|
97
100
|
C as getToken,
|
|
98
101
|
I as getUserInfo,
|
|
99
102
|
y as setGlobalTimeout,
|
|
100
|
-
|
|
103
|
+
E as tcp,
|
|
104
|
+
M as trackEvent,
|
|
101
105
|
S as withTimeout
|
|
102
106
|
};
|
package/lib/functions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
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,6 +9,7 @@ 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>;
|
|
12
13
|
export declare const device: {
|
|
13
14
|
getSnapshot: (options?: DeviceSnapshotOptions) => Promise<DeviceSnapshot | null>;
|
|
14
15
|
getSoftware: () => Promise<SoftwareVersions | null>;
|
package/lib/types.d.ts
CHANGED
|
@@ -121,6 +121,10 @@ export interface StatusPageResult {
|
|
|
121
121
|
description: string;
|
|
122
122
|
domain: string;
|
|
123
123
|
}
|
|
124
|
+
export interface TrackEventParams {
|
|
125
|
+
eventName: SnakeCase<string>;
|
|
126
|
+
additionalDetails?: TrackEventDetails;
|
|
127
|
+
}
|
|
124
128
|
export interface DisplayUnit {
|
|
125
129
|
top: number;
|
|
126
130
|
left: number;
|
|
@@ -165,3 +169,7 @@ export interface ConnectionError {
|
|
|
165
169
|
reason: 'host-policy' | 'host-throttle' | 'other-extension' | 'network';
|
|
166
170
|
extensionId?: string;
|
|
167
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;
|