@talex-touch/utils 1.0.42 → 1.0.44

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.
Files changed (233) hide show
  1. package/.eslintcache +1 -0
  2. package/__tests__/cloud-sync-sdk.test.ts +442 -0
  3. package/__tests__/icons/icons.test.ts +84 -0
  4. package/__tests__/plugin-sdk-lifecycle.test.ts +130 -0
  5. package/__tests__/power-sdk.test.ts +143 -0
  6. package/__tests__/preset-export-types.test.ts +108 -0
  7. package/__tests__/search/fuzzy-match.test.ts +137 -0
  8. package/__tests__/transport/port-policy.test.ts +44 -0
  9. package/__tests__/transport-domain-sdks.test.ts +152 -0
  10. package/__tests__/types/update.test.ts +67 -0
  11. package/account/account-sdk.ts +915 -0
  12. package/account/index.ts +2 -0
  13. package/account/types.ts +321 -0
  14. package/analytics/client.ts +136 -0
  15. package/analytics/index.ts +2 -0
  16. package/analytics/types.ts +156 -0
  17. package/animation/auto-resize.ts +322 -0
  18. package/animation/window-node.ts +26 -19
  19. package/auth/clerk-types.ts +12 -30
  20. package/auth/index.ts +0 -2
  21. package/auth/useAuthState.ts +6 -14
  22. package/base/index.ts +2 -0
  23. package/base/log-level.ts +105 -0
  24. package/channel/index.ts +170 -69
  25. package/cloud-sync/cloud-sync-sdk.ts +450 -0
  26. package/cloud-sync/index.ts +1 -0
  27. package/common/file-scan-utils.ts +17 -9
  28. package/common/index.ts +4 -0
  29. package/common/logger/index.ts +46 -0
  30. package/common/logger/logger-manager.ts +303 -0
  31. package/common/logger/module-logger.ts +270 -0
  32. package/common/logger/transport-logger.ts +234 -0
  33. package/common/logger/types.ts +93 -0
  34. package/common/search/gather.ts +48 -6
  35. package/common/search/index.ts +8 -0
  36. package/common/storage/constants.ts +13 -0
  37. package/common/storage/entity/app-settings.ts +245 -0
  38. package/common/storage/entity/index.ts +3 -0
  39. package/common/storage/entity/layout-atom-types.ts +147 -0
  40. package/common/storage/entity/openers.ts +1 -0
  41. package/common/storage/entity/preset-cloud-api.ts +132 -0
  42. package/common/storage/entity/preset-export-types.ts +256 -0
  43. package/common/storage/entity/shortcut-settings.ts +1 -0
  44. package/common/storage/shortcut-storage.ts +11 -0
  45. package/common/utils/clone-diagnostics.ts +105 -0
  46. package/common/utils/file.ts +16 -8
  47. package/common/utils/index.ts +6 -2
  48. package/common/utils/payload-preview.ts +173 -0
  49. package/common/utils/polling.ts +167 -13
  50. package/common/utils/safe-path.ts +103 -0
  51. package/common/utils/safe-shell.ts +115 -0
  52. package/common/utils/task-queue.ts +4 -1
  53. package/core-box/builder/tuff-builder.ts +0 -1
  54. package/core-box/index.ts +1 -1
  55. package/core-box/recommendation.ts +38 -1
  56. package/core-box/tuff/tuff-dsl.ts +32 -0
  57. package/electron/download-manager.ts +10 -7
  58. package/electron/env-tool.ts +42 -40
  59. package/electron/index.ts +0 -1
  60. package/env/index.ts +156 -0
  61. package/eslint.config.js +55 -0
  62. package/i18n/index.ts +62 -0
  63. package/i18n/locales/en.json +226 -0
  64. package/i18n/locales/zh.json +226 -0
  65. package/i18n/message-keys.ts +236 -0
  66. package/i18n/resolver.ts +181 -0
  67. package/icons/index.ts +257 -0
  68. package/icons/svg.ts +69 -0
  69. package/index.ts +9 -1
  70. package/intelligence/client.ts +72 -42
  71. package/market/constants.ts +9 -5
  72. package/market/index.ts +1 -1
  73. package/market/types.ts +19 -4
  74. package/package.json +15 -5
  75. package/permission/index.ts +143 -46
  76. package/permission/legacy.ts +26 -0
  77. package/permission/registry.ts +304 -0
  78. package/permission/types.ts +164 -0
  79. package/plugin/channel.ts +68 -39
  80. package/plugin/index.ts +80 -7
  81. package/plugin/install.ts +3 -0
  82. package/plugin/log/types.ts +22 -5
  83. package/plugin/node/logger-manager.ts +11 -3
  84. package/plugin/node/logger.ts +24 -17
  85. package/plugin/preload.ts +25 -2
  86. package/plugin/providers/index.ts +4 -4
  87. package/plugin/providers/market-client.ts +6 -3
  88. package/plugin/providers/npm-provider.ts +22 -7
  89. package/plugin/providers/tpex-provider.ts +22 -8
  90. package/plugin/sdk/box-items.ts +14 -0
  91. package/plugin/sdk/box-sdk.ts +64 -0
  92. package/plugin/sdk/channel.ts +119 -4
  93. package/plugin/sdk/clipboard.ts +26 -12
  94. package/plugin/sdk/cloud-sync.ts +113 -0
  95. package/plugin/sdk/common.ts +19 -11
  96. package/plugin/sdk/core-box.ts +6 -15
  97. package/plugin/sdk/division-box.ts +160 -65
  98. package/plugin/sdk/examples/storage-onDidChange-example.js +5 -2
  99. package/plugin/sdk/feature-sdk.ts +111 -76
  100. package/plugin/sdk/flow.ts +146 -45
  101. package/plugin/sdk/hooks/bridge.ts +13 -6
  102. package/plugin/sdk/hooks/life-cycle.ts +35 -16
  103. package/plugin/sdk/index.ts +14 -3
  104. package/plugin/sdk/intelligence.ts +87 -0
  105. package/plugin/sdk/meta/README.md +179 -0
  106. package/plugin/sdk/meta-sdk.ts +244 -0
  107. package/plugin/sdk/notification.ts +9 -0
  108. package/plugin/sdk/plugin-info.ts +64 -0
  109. package/plugin/sdk/power.ts +155 -0
  110. package/plugin/sdk/recommend.ts +21 -0
  111. package/plugin/sdk/service/index.ts +12 -8
  112. package/plugin/sdk/sqlite.ts +141 -0
  113. package/plugin/sdk/storage.ts +2 -6
  114. package/plugin/sdk/system.ts +2 -9
  115. package/plugin/sdk/temp-files.ts +41 -0
  116. package/plugin/sdk/touch-sdk.ts +18 -0
  117. package/plugin/sdk/types.ts +44 -4
  118. package/plugin/sdk/window/index.ts +12 -9
  119. package/plugin/sdk-version.ts +231 -0
  120. package/preload/renderer.ts +3 -2
  121. package/renderer/hooks/arg-mapper.ts +16 -2
  122. package/renderer/hooks/index.ts +13 -0
  123. package/renderer/hooks/initialize.ts +2 -1
  124. package/renderer/hooks/use-agent-market-sdk.ts +7 -0
  125. package/renderer/hooks/use-agent-market.ts +106 -0
  126. package/renderer/hooks/use-agents-sdk.ts +7 -0
  127. package/renderer/hooks/use-app-sdk.ts +7 -0
  128. package/renderer/hooks/use-channel.ts +33 -4
  129. package/renderer/hooks/use-download-sdk.ts +21 -0
  130. package/renderer/hooks/use-intelligence-sdk.ts +7 -0
  131. package/renderer/hooks/use-intelligence-stats.ts +290 -0
  132. package/renderer/hooks/use-intelligence.ts +55 -214
  133. package/renderer/hooks/use-market-sdk.ts +16 -0
  134. package/renderer/hooks/use-notification-sdk.ts +7 -0
  135. package/renderer/hooks/use-permission-sdk.ts +7 -0
  136. package/renderer/hooks/use-permission.ts +325 -0
  137. package/renderer/hooks/use-platform-sdk.ts +7 -0
  138. package/renderer/hooks/use-plugin-sdk.ts +16 -0
  139. package/renderer/hooks/use-settings-sdk.ts +7 -0
  140. package/renderer/hooks/use-update-sdk.ts +21 -0
  141. package/renderer/index.ts +1 -0
  142. package/renderer/ref.ts +19 -10
  143. package/renderer/shared/components/SharedPluginDetailContent.vue +84 -0
  144. package/renderer/shared/components/SharedPluginDetailHeader.vue +116 -0
  145. package/renderer/shared/components/SharedPluginDetailMetaList.vue +39 -0
  146. package/renderer/shared/components/SharedPluginDetailReadme.vue +45 -0
  147. package/renderer/shared/components/SharedPluginDetailVersions.vue +98 -0
  148. package/renderer/shared/components/index.ts +5 -0
  149. package/renderer/shared/components/shims-vue.d.ts +5 -0
  150. package/renderer/shared/index.ts +2 -0
  151. package/renderer/shared/plugin-detail.ts +62 -0
  152. package/renderer/storage/app-settings.ts +3 -1
  153. package/renderer/storage/base-storage.ts +508 -82
  154. package/renderer/storage/intelligence-storage.ts +31 -40
  155. package/renderer/storage/openers.ts +3 -1
  156. package/renderer/storage/storage-subscription.ts +126 -42
  157. package/renderer/touch-sdk/env.ts +10 -10
  158. package/renderer/touch-sdk/index.ts +114 -18
  159. package/renderer/touch-sdk/terminal.ts +24 -13
  160. package/search/feature-matcher.ts +279 -0
  161. package/search/fuzzy-match.ts +64 -34
  162. package/search/index.ts +10 -0
  163. package/search/levenshtein-utils.ts +17 -11
  164. package/transport/errors.ts +310 -0
  165. package/transport/event/builder.ts +378 -0
  166. package/transport/event/index.ts +7 -0
  167. package/transport/event/types.ts +292 -0
  168. package/transport/events/index.ts +2670 -0
  169. package/transport/events/meta-overlay.ts +79 -0
  170. package/transport/events/types/agents.ts +177 -0
  171. package/transport/events/types/app-index.ts +9 -0
  172. package/transport/events/types/app.ts +475 -0
  173. package/transport/events/types/box-item.ts +222 -0
  174. package/transport/events/types/clipboard.ts +80 -0
  175. package/transport/events/types/core-box.ts +534 -0
  176. package/transport/events/types/device-idle.ts +7 -0
  177. package/transport/events/types/division-box.ts +99 -0
  178. package/transport/events/types/download.ts +115 -0
  179. package/transport/events/types/file-index.ts +73 -0
  180. package/transport/events/types/flow.ts +149 -0
  181. package/transport/events/types/index.ts +70 -0
  182. package/transport/events/types/market.ts +39 -0
  183. package/transport/events/types/meta-overlay.ts +184 -0
  184. package/transport/events/types/notification.ts +140 -0
  185. package/transport/events/types/permission.ts +90 -0
  186. package/transport/events/types/platform.ts +8 -0
  187. package/transport/events/types/plugin.ts +620 -0
  188. package/transport/events/types/sentry.ts +20 -0
  189. package/transport/events/types/storage.ts +208 -0
  190. package/transport/events/types/transport.ts +60 -0
  191. package/transport/events/types/tray.ts +16 -0
  192. package/transport/events/types/update.ts +78 -0
  193. package/transport/index.ts +139 -0
  194. package/transport/main.ts +2 -0
  195. package/transport/sdk/constants.ts +29 -0
  196. package/transport/sdk/domains/agents-market.ts +47 -0
  197. package/transport/sdk/domains/agents.ts +62 -0
  198. package/transport/sdk/domains/app.ts +48 -0
  199. package/transport/sdk/domains/disposable.ts +35 -0
  200. package/transport/sdk/domains/download.ts +139 -0
  201. package/transport/sdk/domains/index.ts +13 -0
  202. package/transport/sdk/domains/intelligence.ts +616 -0
  203. package/transport/sdk/domains/market.ts +35 -0
  204. package/transport/sdk/domains/notification.ts +62 -0
  205. package/transport/sdk/domains/permission.ts +85 -0
  206. package/transport/sdk/domains/platform.ts +19 -0
  207. package/transport/sdk/domains/plugin.ts +144 -0
  208. package/transport/sdk/domains/settings.ts +92 -0
  209. package/transport/sdk/domains/update.ts +64 -0
  210. package/transport/sdk/index.ts +60 -0
  211. package/transport/sdk/main-transport.ts +710 -0
  212. package/transport/sdk/main.ts +9 -0
  213. package/transport/sdk/plugin-transport.ts +654 -0
  214. package/transport/sdk/port-policy.ts +38 -0
  215. package/transport/sdk/renderer-transport.ts +1165 -0
  216. package/transport/types.ts +605 -0
  217. package/types/agent.ts +399 -0
  218. package/types/cloud-sync.ts +157 -0
  219. package/types/division-box.ts +31 -31
  220. package/types/download.ts +1 -0
  221. package/types/flow.ts +63 -12
  222. package/types/icon.ts +2 -1
  223. package/types/index.ts +5 -0
  224. package/types/intelligence.ts +166 -173
  225. package/types/modules/base.ts +2 -0
  226. package/types/path-browserify.d.ts +5 -0
  227. package/types/platform.ts +12 -0
  228. package/types/startup-info.ts +32 -0
  229. package/types/touch-app-core.ts +8 -8
  230. package/types/update.ts +94 -1
  231. package/vitest.config.ts +25 -0
  232. package/auth/useClerkConfig.ts +0 -40
  233. package/auth/useClerkProvider.ts +0 -52
@@ -0,0 +1,2 @@
1
+ export * from './account-sdk'
2
+ export * from './types'
@@ -0,0 +1,321 @@
1
+ /**
2
+ * Account subscription plan types
3
+ */
4
+ export enum SubscriptionPlan {
5
+ FREE = 'free',
6
+ PRO = 'pro',
7
+ PLUS = 'plus',
8
+ TEAM = 'team',
9
+ ENTERPRISE = 'enterprise',
10
+ }
11
+
12
+ /**
13
+ * Subscription billing cycle
14
+ */
15
+ export enum BillingCycle {
16
+ MONTHLY = 'monthly',
17
+ YEARLY = 'yearly',
18
+ LIFETIME = 'lifetime',
19
+ }
20
+
21
+ /**
22
+ * Subscription status
23
+ */
24
+ export enum SubscriptionStatus {
25
+ ACTIVE = 'active',
26
+ TRIALING = 'trialing',
27
+ PAST_DUE = 'past_due',
28
+ CANCELED = 'canceled',
29
+ EXPIRED = 'expired',
30
+ PAUSED = 'paused',
31
+ }
32
+
33
+ /**
34
+ * Account verification status
35
+ */
36
+ export enum VerificationStatus {
37
+ UNVERIFIED = 'unverified',
38
+ PENDING = 'pending',
39
+ VERIFIED = 'verified',
40
+ }
41
+
42
+ /**
43
+ * User role in organization/team
44
+ */
45
+ export enum TeamRole {
46
+ OWNER = 'owner',
47
+ ADMIN = 'admin',
48
+ MEMBER = 'member',
49
+ GUEST = 'guest',
50
+ }
51
+
52
+ /**
53
+ * Feature flag for gated features
54
+ */
55
+ export interface FeatureFlag {
56
+ id: string
57
+ enabled: boolean
58
+ value?: string | number | boolean
59
+ }
60
+
61
+ /**
62
+ * Plan quota limits
63
+ */
64
+ export interface PlanQuota {
65
+ /** AI requests per day */
66
+ aiRequestsPerDay: number
67
+ /** AI tokens per month */
68
+ aiTokensPerMonth: number
69
+ /** Max plugins allowed */
70
+ maxPlugins: number
71
+ /** Max storage in bytes */
72
+ maxStorageBytes: number
73
+ /** Max team members (for team/enterprise) */
74
+ maxTeamMembers?: number
75
+ /** Max workspaces */
76
+ maxWorkspaces?: number
77
+ /** Custom model access */
78
+ customModelAccess: boolean
79
+ /** Priority support */
80
+ prioritySupport: boolean
81
+ /** API access */
82
+ apiAccess: boolean
83
+ /** Advanced analytics */
84
+ advancedAnalytics: boolean
85
+ }
86
+
87
+ /**
88
+ * Current usage statistics
89
+ */
90
+ export interface UsageStats {
91
+ /** AI requests used today */
92
+ aiRequestsToday: number
93
+ /** AI requests used this month */
94
+ aiRequestsThisMonth: number
95
+ /** AI tokens used this month */
96
+ aiTokensThisMonth: number
97
+ /** Storage used in bytes */
98
+ storageUsedBytes: number
99
+ /** Plugins installed count */
100
+ pluginsInstalled: number
101
+ /** Last activity timestamp */
102
+ lastActivityAt?: number
103
+ }
104
+
105
+ /**
106
+ * Subscription details
107
+ */
108
+ export interface Subscription {
109
+ /** Subscription ID */
110
+ id: string
111
+ /** Current plan */
112
+ plan: SubscriptionPlan
113
+ /** Subscription status */
114
+ status: SubscriptionStatus
115
+ /** Billing cycle */
116
+ billingCycle: BillingCycle
117
+ /** Plan quota limits */
118
+ quota: PlanQuota
119
+ /** Current usage */
120
+ usage: UsageStats
121
+ /** Start date */
122
+ startedAt: number
123
+ /** Current period end date */
124
+ currentPeriodEnd: number
125
+ /** Trial end date (if trialing) */
126
+ trialEndAt?: number
127
+ /** Cancellation date (if canceled) */
128
+ canceledAt?: number
129
+ /** Cancel at period end */
130
+ cancelAtPeriodEnd: boolean
131
+ /** Auto-renew enabled */
132
+ autoRenew: boolean
133
+ /** Payment method on file */
134
+ hasPaymentMethod: boolean
135
+ /** Price in cents */
136
+ priceInCents?: number
137
+ /** Currency code */
138
+ currency?: string
139
+ }
140
+
141
+ /**
142
+ * Social connection info
143
+ */
144
+ export interface SocialConnection {
145
+ provider: 'google' | 'github' | 'apple' | 'microsoft' | 'discord' | 'twitter'
146
+ providerId: string
147
+ email?: string
148
+ username?: string
149
+ avatarUrl?: string
150
+ connectedAt: number
151
+ }
152
+
153
+ /**
154
+ * User profile
155
+ */
156
+ export interface UserProfile {
157
+ /** User ID */
158
+ id: string
159
+ /** Display name */
160
+ displayName: string
161
+ /** Username (unique) */
162
+ username?: string
163
+ /** First name */
164
+ firstName?: string
165
+ /** Last name */
166
+ lastName?: string
167
+ /** Primary email */
168
+ email: string
169
+ /** Email verified */
170
+ emailVerified: boolean
171
+ /** Avatar URL */
172
+ avatarUrl?: string
173
+ /** Phone number */
174
+ phone?: string
175
+ /** Phone verified */
176
+ phoneVerified?: boolean
177
+ /** Bio/description */
178
+ bio?: string
179
+ /** Locale/language preference */
180
+ locale?: string
181
+ /** Timezone */
182
+ timezone?: string
183
+ /** Account created at */
184
+ createdAt: number
185
+ /** Last updated at */
186
+ updatedAt: number
187
+ /** Last sign in at */
188
+ lastSignInAt?: number
189
+ /** Two-factor enabled */
190
+ twoFactorEnabled: boolean
191
+ /** Connected social accounts */
192
+ socialConnections: SocialConnection[]
193
+ }
194
+
195
+ /**
196
+ * Team/Organization info
197
+ */
198
+ export interface Team {
199
+ /** Team ID */
200
+ id: string
201
+ /** Team name */
202
+ name: string
203
+ /** Team slug (URL-safe) */
204
+ slug: string
205
+ /** Team logo URL */
206
+ logoUrl?: string
207
+ /** Team description */
208
+ description?: string
209
+ /** User's role in team */
210
+ role: TeamRole
211
+ /** Member count */
212
+ memberCount: number
213
+ /** Team created at */
214
+ createdAt: number
215
+ /** Team subscription (if separate from user) */
216
+ subscription?: Subscription
217
+ }
218
+
219
+ /**
220
+ * Device session info
221
+ */
222
+ export interface DeviceSession {
223
+ /** Session ID */
224
+ id: string
225
+ /** Device name/type */
226
+ deviceName: string
227
+ /** Device type */
228
+ deviceType: 'desktop' | 'mobile' | 'tablet' | 'unknown'
229
+ /** Operating system */
230
+ os?: string
231
+ /** Browser/client */
232
+ client?: string
233
+ /** IP address */
234
+ ipAddress?: string
235
+ /** Location (city, country) */
236
+ location?: string
237
+ /** Is current session */
238
+ isCurrent: boolean
239
+ /** Last active at */
240
+ lastActiveAt: number
241
+ /** Created at */
242
+ createdAt: number
243
+ }
244
+
245
+ /**
246
+ * Complete account info
247
+ */
248
+ export interface AccountInfo {
249
+ /** User profile */
250
+ profile: UserProfile
251
+ /** Subscription details */
252
+ subscription: Subscription
253
+ /** Teams user belongs to */
254
+ teams: Team[]
255
+ /** Active sessions */
256
+ sessions: DeviceSession[]
257
+ /** Feature flags */
258
+ features: FeatureFlag[]
259
+ /** Account verification status */
260
+ verificationStatus: VerificationStatus
261
+ /** Is beta tester */
262
+ isBetaTester: boolean
263
+ /** Referral code */
264
+ referralCode?: string
265
+ /** Referred by user ID */
266
+ referredBy?: string
267
+ /** Referral count */
268
+ referralCount: number
269
+ }
270
+
271
+ /**
272
+ * Account SDK configuration
273
+ */
274
+ export interface AccountSDKConfig {
275
+ /** API base URL */
276
+ apiBaseUrl?: string
277
+ /** Cache TTL in milliseconds */
278
+ cacheTTL?: number
279
+ /** Enable offline mode */
280
+ offlineMode?: boolean
281
+ }
282
+
283
+ /**
284
+ * Quota check result
285
+ */
286
+ export interface QuotaCheckResult {
287
+ /** Is allowed */
288
+ allowed: boolean
289
+ /** Reason if not allowed */
290
+ reason?: string
291
+ /** Remaining quota */
292
+ remaining?: number
293
+ /** Reset time */
294
+ resetAt?: number
295
+ }
296
+
297
+ /**
298
+ * Plan comparison item
299
+ */
300
+ export interface PlanComparisonItem {
301
+ feature: string
302
+ free: string | boolean | number
303
+ pro: string | boolean | number
304
+ plus: string | boolean | number
305
+ team: string | boolean | number
306
+ enterprise: string | boolean | number
307
+ }
308
+
309
+ /**
310
+ * Upgrade options
311
+ */
312
+ export interface UpgradeOption {
313
+ plan: SubscriptionPlan
314
+ name: string
315
+ description: string
316
+ priceMonthly: number
317
+ priceYearly: number
318
+ currency: string
319
+ features: string[]
320
+ recommended?: boolean
321
+ }
@@ -0,0 +1,136 @@
1
+ import type { ITuffTransport } from '../transport'
2
+ import type {
3
+ CounterPayload,
4
+ FeatureStats,
5
+ GaugePayload,
6
+ HistogramPayload,
7
+ PluginAnalyticsSDK,
8
+ PluginStats,
9
+ } from './types'
10
+ import { hasWindow } from '../env'
11
+ import { useTuffTransport } from '../transport'
12
+ import { AppEvents } from '../transport/events'
13
+
14
+ const emptyStats: PluginStats = {
15
+ featureCalls: {},
16
+ totalCalls: 0,
17
+ avgResponseTime: 0,
18
+ topFeatures: [],
19
+ counters: {},
20
+ gauges: {},
21
+ histograms: {},
22
+ }
23
+
24
+ /**
25
+ * Create a plugin/renderer analytics client powered by TuffTransport.
26
+ */
27
+ export function createPluginAnalyticsClient(options?: {
28
+ pluginName?: string
29
+ pluginVersion?: string
30
+ transport?: ITuffTransport
31
+ }): PluginAnalyticsSDK {
32
+ let transport = options?.transport
33
+ const pluginName = options?.pluginName
34
+ const pluginVersion = options?.pluginVersion ?? resolveRuntimePluginVersion()
35
+
36
+ const getTransport = () => {
37
+ if (transport)
38
+ return transport
39
+ try {
40
+ transport = useTuffTransport()
41
+ return transport
42
+ }
43
+ catch {
44
+ return null
45
+ }
46
+ }
47
+
48
+ const withDefaultPlugin = <T extends Record<string, any>>(
49
+ payload: T,
50
+ ): T & { pluginName?: string, pluginVersion?: string } => ({
51
+ ...payload,
52
+ pluginName: payload.pluginName ?? pluginName,
53
+ pluginVersion: payload.pluginVersion ?? pluginVersion,
54
+ })
55
+
56
+ return {
57
+ async trackEvent(eventName, metadata, featureId) {
58
+ const tx = getTransport()
59
+ if (!tx)
60
+ return
61
+ await tx.send(AppEvents.analytics.sdk.trackEvent, withDefaultPlugin({ eventName, featureId, metadata }))
62
+ },
63
+
64
+ async trackDuration(operationName, durationMs, featureId) {
65
+ const tx = getTransport()
66
+ if (!tx)
67
+ return
68
+ await tx.send(AppEvents.analytics.sdk.trackDuration, withDefaultPlugin({ operationName, durationMs, featureId }))
69
+ },
70
+
71
+ async measure(operationName, fn) {
72
+ const startedAt = Date.now()
73
+ try {
74
+ const result = await fn()
75
+ await this.trackDuration(operationName, Date.now() - startedAt)
76
+ return result
77
+ }
78
+ catch (error) {
79
+ await this.trackDuration(operationName, Date.now() - startedAt)
80
+ throw error
81
+ }
82
+ },
83
+
84
+ async getStats() {
85
+ const tx = getTransport()
86
+ if (!tx)
87
+ return emptyStats
88
+ return tx.send(AppEvents.analytics.sdk.getStats, withDefaultPlugin({}))
89
+ },
90
+
91
+ async getFeatureStats(featureId) {
92
+ const tx = getTransport()
93
+ if (!tx)
94
+ return { count: 0, avgDuration: 0 } satisfies FeatureStats
95
+ return tx.send(AppEvents.analytics.sdk.getFeatureStats, withDefaultPlugin({ featureId }))
96
+ },
97
+
98
+ async getTopFeatures(limit) {
99
+ const tx = getTransport()
100
+ if (!tx)
101
+ return []
102
+ return tx.send(AppEvents.analytics.sdk.getTopFeatures, withDefaultPlugin({ limit }))
103
+ },
104
+
105
+ async incrementCounter(name, value) {
106
+ const tx = getTransport()
107
+ if (!tx)
108
+ return
109
+ const payload: CounterPayload = { name, value }
110
+ await tx.send(AppEvents.analytics.sdk.incrementCounter, withDefaultPlugin(payload))
111
+ },
112
+
113
+ async setGauge(name, value) {
114
+ const tx = getTransport()
115
+ if (!tx)
116
+ return
117
+ const payload: GaugePayload = { name, value }
118
+ await tx.send(AppEvents.analytics.sdk.setGauge, withDefaultPlugin(payload))
119
+ },
120
+
121
+ async recordHistogram(name, value) {
122
+ const tx = getTransport()
123
+ if (!tx)
124
+ return
125
+ const payload: HistogramPayload = { name, value }
126
+ await tx.send(AppEvents.analytics.sdk.recordHistogram, withDefaultPlugin(payload))
127
+ },
128
+ }
129
+ }
130
+
131
+ function resolveRuntimePluginVersion(): string | undefined {
132
+ if (!hasWindow())
133
+ return undefined
134
+ const plugin = (window as any).$plugin as { version?: unknown } | undefined
135
+ return typeof plugin?.version === 'string' ? plugin.version : undefined
136
+ }
@@ -0,0 +1,2 @@
1
+ export { createPluginAnalyticsClient } from './client'
2
+ export * from './types'
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Shared analytics types.
3
+ */
4
+
5
+ export type AnalyticsWindowType = '1m' | '5m' | '15m' | '1h' | '24h'
6
+
7
+ export interface CoreMetrics {
8
+ ipc?: {
9
+ requestCount?: number
10
+ avgLatency?: number
11
+ p50Latency?: number
12
+ p95Latency?: number
13
+ p99Latency?: number
14
+ errorCount?: number
15
+ slowRequests?: number
16
+ }
17
+ system?: {
18
+ cpuUsage?: number
19
+ memoryUsed?: number
20
+ memoryTotal?: number
21
+ heapUsed?: number
22
+ heapTotal?: number
23
+ }
24
+ modules?: Record<string, {
25
+ operationCount?: number
26
+ avgDuration?: number
27
+ errorCount?: number
28
+ }>
29
+ plugins?: Record<string, {
30
+ featureCalls?: Record<string, number>
31
+ totalCalls?: number
32
+ avgResponseTime?: number
33
+ topFeatures?: Array<{ id: string, count: number }>
34
+ }>
35
+ search?: {
36
+ totalSearches?: number
37
+ avgDuration?: number
38
+ providerTimings?: Record<string, number>
39
+ }
40
+ }
41
+
42
+ export interface AnalyticsSnapshot {
43
+ windowType: AnalyticsWindowType
44
+ timestamp: number
45
+ metrics: CoreMetrics
46
+ }
47
+
48
+ export interface AnalyticsRangeRequest {
49
+ windowType: AnalyticsWindowType
50
+ from: number
51
+ to: number
52
+ }
53
+
54
+ export interface AnalyticsExportPayload extends AnalyticsRangeRequest {
55
+ format?: 'json' | 'csv'
56
+ dimensions?: Array<'ipc' | 'system' | 'modules' | 'plugins' | 'search'>
57
+ }
58
+
59
+ export interface AnalyticsExportResult {
60
+ format: 'json' | 'csv'
61
+ content: string
62
+ payload: AnalyticsExportPayload
63
+ exportedAt: number
64
+ }
65
+
66
+ export interface PluginStats {
67
+ featureCalls: Record<string, number>
68
+ totalCalls: number
69
+ avgResponseTime: number
70
+ topFeatures: Array<{ id: string, count: number }>
71
+ counters: Record<string, number>
72
+ gauges: Record<string, number>
73
+ histograms: Record<string, number[]>
74
+ }
75
+
76
+ export interface FeatureStats {
77
+ count: number
78
+ avgDuration: number
79
+ lastDuration?: number
80
+ }
81
+
82
+ export interface TrackEventPayload {
83
+ eventName: string
84
+ featureId?: string
85
+ metadata?: Record<string, unknown>
86
+ pluginName?: string
87
+ pluginVersion?: string
88
+ }
89
+
90
+ export interface TrackDurationPayload {
91
+ operationName: string
92
+ durationMs: number
93
+ featureId?: string
94
+ pluginName?: string
95
+ pluginVersion?: string
96
+ }
97
+
98
+ export interface CounterPayload {
99
+ name: string
100
+ value?: number
101
+ pluginName?: string
102
+ pluginVersion?: string
103
+ }
104
+
105
+ export interface GaugePayload {
106
+ name: string
107
+ value: number
108
+ pluginName?: string
109
+ pluginVersion?: string
110
+ }
111
+
112
+ export interface HistogramPayload {
113
+ name: string
114
+ value: number
115
+ pluginName?: string
116
+ pluginVersion?: string
117
+ }
118
+
119
+ export type AnalyticsMessageStatus = 'unread' | 'read' | 'archived'
120
+ export type AnalyticsMessageSeverity = 'info' | 'warn' | 'error'
121
+ export type AnalyticsMessageSource = 'analytics' | 'sentry' | 'update' | 'permission' | 'system'
122
+
123
+ export interface AnalyticsMessage {
124
+ id: string
125
+ source: AnalyticsMessageSource
126
+ severity: AnalyticsMessageSeverity
127
+ title: string
128
+ message: string
129
+ meta?: Record<string, unknown>
130
+ status: AnalyticsMessageStatus
131
+ createdAt: number
132
+ }
133
+
134
+ export interface AnalyticsMessageListRequest {
135
+ status?: AnalyticsMessageStatus | 'all'
136
+ source?: AnalyticsMessageSource
137
+ since?: number
138
+ limit?: number
139
+ }
140
+
141
+ export interface AnalyticsMessageUpdateRequest {
142
+ id: string
143
+ status: AnalyticsMessageStatus
144
+ }
145
+
146
+ export interface PluginAnalyticsSDK {
147
+ trackEvent: (eventName: string, metadata?: Record<string, unknown>, featureId?: string) => Promise<void>
148
+ trackDuration: (operationName: string, durationMs: number, featureId?: string) => Promise<void>
149
+ measure: <T>(operationName: string, fn: () => T | Promise<T>) => Promise<T>
150
+ getStats: () => Promise<PluginStats>
151
+ getFeatureStats: (featureId: string) => Promise<FeatureStats>
152
+ getTopFeatures: (limit?: number) => Promise<Array<{ id: string, count: number }>>
153
+ incrementCounter: (name: string, value?: number) => Promise<void>
154
+ setGauge: (name: string, value: number) => Promise<void>
155
+ recordHistogram: (name: string, value: number) => Promise<void>
156
+ }