@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.
- package/.eslintcache +1 -0
- package/__tests__/cloud-sync-sdk.test.ts +442 -0
- package/__tests__/icons/icons.test.ts +84 -0
- package/__tests__/plugin-sdk-lifecycle.test.ts +130 -0
- package/__tests__/power-sdk.test.ts +143 -0
- package/__tests__/preset-export-types.test.ts +108 -0
- package/__tests__/search/fuzzy-match.test.ts +137 -0
- package/__tests__/transport/port-policy.test.ts +44 -0
- package/__tests__/transport-domain-sdks.test.ts +152 -0
- package/__tests__/types/update.test.ts +67 -0
- package/account/account-sdk.ts +915 -0
- package/account/index.ts +2 -0
- package/account/types.ts +321 -0
- package/analytics/client.ts +136 -0
- package/analytics/index.ts +2 -0
- package/analytics/types.ts +156 -0
- package/animation/auto-resize.ts +322 -0
- package/animation/window-node.ts +26 -19
- package/auth/clerk-types.ts +12 -30
- package/auth/index.ts +0 -2
- package/auth/useAuthState.ts +6 -14
- package/base/index.ts +2 -0
- package/base/log-level.ts +105 -0
- package/channel/index.ts +170 -69
- package/cloud-sync/cloud-sync-sdk.ts +450 -0
- package/cloud-sync/index.ts +1 -0
- package/common/file-scan-utils.ts +17 -9
- package/common/index.ts +4 -0
- package/common/logger/index.ts +46 -0
- package/common/logger/logger-manager.ts +303 -0
- package/common/logger/module-logger.ts +270 -0
- package/common/logger/transport-logger.ts +234 -0
- package/common/logger/types.ts +93 -0
- package/common/search/gather.ts +48 -6
- package/common/search/index.ts +8 -0
- package/common/storage/constants.ts +13 -0
- package/common/storage/entity/app-settings.ts +245 -0
- package/common/storage/entity/index.ts +3 -0
- package/common/storage/entity/layout-atom-types.ts +147 -0
- package/common/storage/entity/openers.ts +1 -0
- package/common/storage/entity/preset-cloud-api.ts +132 -0
- package/common/storage/entity/preset-export-types.ts +256 -0
- package/common/storage/entity/shortcut-settings.ts +1 -0
- package/common/storage/shortcut-storage.ts +11 -0
- package/common/utils/clone-diagnostics.ts +105 -0
- package/common/utils/file.ts +16 -8
- package/common/utils/index.ts +6 -2
- package/common/utils/payload-preview.ts +173 -0
- package/common/utils/polling.ts +167 -13
- package/common/utils/safe-path.ts +103 -0
- package/common/utils/safe-shell.ts +115 -0
- package/common/utils/task-queue.ts +4 -1
- package/core-box/builder/tuff-builder.ts +0 -1
- package/core-box/index.ts +1 -1
- package/core-box/recommendation.ts +38 -1
- package/core-box/tuff/tuff-dsl.ts +32 -0
- package/electron/download-manager.ts +10 -7
- package/electron/env-tool.ts +42 -40
- package/electron/index.ts +0 -1
- package/env/index.ts +156 -0
- package/eslint.config.js +55 -0
- package/i18n/index.ts +62 -0
- package/i18n/locales/en.json +226 -0
- package/i18n/locales/zh.json +226 -0
- package/i18n/message-keys.ts +236 -0
- package/i18n/resolver.ts +181 -0
- package/icons/index.ts +257 -0
- package/icons/svg.ts +69 -0
- package/index.ts +9 -1
- package/intelligence/client.ts +72 -42
- package/market/constants.ts +9 -5
- package/market/index.ts +1 -1
- package/market/types.ts +19 -4
- package/package.json +15 -5
- package/permission/index.ts +143 -46
- package/permission/legacy.ts +26 -0
- package/permission/registry.ts +304 -0
- package/permission/types.ts +164 -0
- package/plugin/channel.ts +68 -39
- package/plugin/index.ts +80 -7
- package/plugin/install.ts +3 -0
- package/plugin/log/types.ts +22 -5
- package/plugin/node/logger-manager.ts +11 -3
- package/plugin/node/logger.ts +24 -17
- package/plugin/preload.ts +25 -2
- package/plugin/providers/index.ts +4 -4
- package/plugin/providers/market-client.ts +6 -3
- package/plugin/providers/npm-provider.ts +22 -7
- package/plugin/providers/tpex-provider.ts +22 -8
- package/plugin/sdk/box-items.ts +14 -0
- package/plugin/sdk/box-sdk.ts +64 -0
- package/plugin/sdk/channel.ts +119 -4
- package/plugin/sdk/clipboard.ts +26 -12
- package/plugin/sdk/cloud-sync.ts +113 -0
- package/plugin/sdk/common.ts +19 -11
- package/plugin/sdk/core-box.ts +6 -15
- package/plugin/sdk/division-box.ts +160 -65
- package/plugin/sdk/examples/storage-onDidChange-example.js +5 -2
- package/plugin/sdk/feature-sdk.ts +111 -76
- package/plugin/sdk/flow.ts +146 -45
- package/plugin/sdk/hooks/bridge.ts +13 -6
- package/plugin/sdk/hooks/life-cycle.ts +35 -16
- package/plugin/sdk/index.ts +14 -3
- package/plugin/sdk/intelligence.ts +87 -0
- package/plugin/sdk/meta/README.md +179 -0
- package/plugin/sdk/meta-sdk.ts +244 -0
- package/plugin/sdk/notification.ts +9 -0
- package/plugin/sdk/plugin-info.ts +64 -0
- package/plugin/sdk/power.ts +155 -0
- package/plugin/sdk/recommend.ts +21 -0
- package/plugin/sdk/service/index.ts +12 -8
- package/plugin/sdk/sqlite.ts +141 -0
- package/plugin/sdk/storage.ts +2 -6
- package/plugin/sdk/system.ts +2 -9
- package/plugin/sdk/temp-files.ts +41 -0
- package/plugin/sdk/touch-sdk.ts +18 -0
- package/plugin/sdk/types.ts +44 -4
- package/plugin/sdk/window/index.ts +12 -9
- package/plugin/sdk-version.ts +231 -0
- package/preload/renderer.ts +3 -2
- package/renderer/hooks/arg-mapper.ts +16 -2
- package/renderer/hooks/index.ts +13 -0
- package/renderer/hooks/initialize.ts +2 -1
- package/renderer/hooks/use-agent-market-sdk.ts +7 -0
- package/renderer/hooks/use-agent-market.ts +106 -0
- package/renderer/hooks/use-agents-sdk.ts +7 -0
- package/renderer/hooks/use-app-sdk.ts +7 -0
- package/renderer/hooks/use-channel.ts +33 -4
- package/renderer/hooks/use-download-sdk.ts +21 -0
- package/renderer/hooks/use-intelligence-sdk.ts +7 -0
- package/renderer/hooks/use-intelligence-stats.ts +290 -0
- package/renderer/hooks/use-intelligence.ts +55 -214
- package/renderer/hooks/use-market-sdk.ts +16 -0
- package/renderer/hooks/use-notification-sdk.ts +7 -0
- package/renderer/hooks/use-permission-sdk.ts +7 -0
- package/renderer/hooks/use-permission.ts +325 -0
- package/renderer/hooks/use-platform-sdk.ts +7 -0
- package/renderer/hooks/use-plugin-sdk.ts +16 -0
- package/renderer/hooks/use-settings-sdk.ts +7 -0
- package/renderer/hooks/use-update-sdk.ts +21 -0
- package/renderer/index.ts +1 -0
- package/renderer/ref.ts +19 -10
- package/renderer/shared/components/SharedPluginDetailContent.vue +84 -0
- package/renderer/shared/components/SharedPluginDetailHeader.vue +116 -0
- package/renderer/shared/components/SharedPluginDetailMetaList.vue +39 -0
- package/renderer/shared/components/SharedPluginDetailReadme.vue +45 -0
- package/renderer/shared/components/SharedPluginDetailVersions.vue +98 -0
- package/renderer/shared/components/index.ts +5 -0
- package/renderer/shared/components/shims-vue.d.ts +5 -0
- package/renderer/shared/index.ts +2 -0
- package/renderer/shared/plugin-detail.ts +62 -0
- package/renderer/storage/app-settings.ts +3 -1
- package/renderer/storage/base-storage.ts +508 -82
- package/renderer/storage/intelligence-storage.ts +31 -40
- package/renderer/storage/openers.ts +3 -1
- package/renderer/storage/storage-subscription.ts +126 -42
- package/renderer/touch-sdk/env.ts +10 -10
- package/renderer/touch-sdk/index.ts +114 -18
- package/renderer/touch-sdk/terminal.ts +24 -13
- package/search/feature-matcher.ts +279 -0
- package/search/fuzzy-match.ts +64 -34
- package/search/index.ts +10 -0
- package/search/levenshtein-utils.ts +17 -11
- package/transport/errors.ts +310 -0
- package/transport/event/builder.ts +378 -0
- package/transport/event/index.ts +7 -0
- package/transport/event/types.ts +292 -0
- package/transport/events/index.ts +2670 -0
- package/transport/events/meta-overlay.ts +79 -0
- package/transport/events/types/agents.ts +177 -0
- package/transport/events/types/app-index.ts +9 -0
- package/transport/events/types/app.ts +475 -0
- package/transport/events/types/box-item.ts +222 -0
- package/transport/events/types/clipboard.ts +80 -0
- package/transport/events/types/core-box.ts +534 -0
- package/transport/events/types/device-idle.ts +7 -0
- package/transport/events/types/division-box.ts +99 -0
- package/transport/events/types/download.ts +115 -0
- package/transport/events/types/file-index.ts +73 -0
- package/transport/events/types/flow.ts +149 -0
- package/transport/events/types/index.ts +70 -0
- package/transport/events/types/market.ts +39 -0
- package/transport/events/types/meta-overlay.ts +184 -0
- package/transport/events/types/notification.ts +140 -0
- package/transport/events/types/permission.ts +90 -0
- package/transport/events/types/platform.ts +8 -0
- package/transport/events/types/plugin.ts +620 -0
- package/transport/events/types/sentry.ts +20 -0
- package/transport/events/types/storage.ts +208 -0
- package/transport/events/types/transport.ts +60 -0
- package/transport/events/types/tray.ts +16 -0
- package/transport/events/types/update.ts +78 -0
- package/transport/index.ts +139 -0
- package/transport/main.ts +2 -0
- package/transport/sdk/constants.ts +29 -0
- package/transport/sdk/domains/agents-market.ts +47 -0
- package/transport/sdk/domains/agents.ts +62 -0
- package/transport/sdk/domains/app.ts +48 -0
- package/transport/sdk/domains/disposable.ts +35 -0
- package/transport/sdk/domains/download.ts +139 -0
- package/transport/sdk/domains/index.ts +13 -0
- package/transport/sdk/domains/intelligence.ts +616 -0
- package/transport/sdk/domains/market.ts +35 -0
- package/transport/sdk/domains/notification.ts +62 -0
- package/transport/sdk/domains/permission.ts +85 -0
- package/transport/sdk/domains/platform.ts +19 -0
- package/transport/sdk/domains/plugin.ts +144 -0
- package/transport/sdk/domains/settings.ts +92 -0
- package/transport/sdk/domains/update.ts +64 -0
- package/transport/sdk/index.ts +60 -0
- package/transport/sdk/main-transport.ts +710 -0
- package/transport/sdk/main.ts +9 -0
- package/transport/sdk/plugin-transport.ts +654 -0
- package/transport/sdk/port-policy.ts +38 -0
- package/transport/sdk/renderer-transport.ts +1165 -0
- package/transport/types.ts +605 -0
- package/types/agent.ts +399 -0
- package/types/cloud-sync.ts +157 -0
- package/types/division-box.ts +31 -31
- package/types/download.ts +1 -0
- package/types/flow.ts +63 -12
- package/types/icon.ts +2 -1
- package/types/index.ts +5 -0
- package/types/intelligence.ts +166 -173
- package/types/modules/base.ts +2 -0
- package/types/path-browserify.d.ts +5 -0
- package/types/platform.ts +12 -0
- package/types/startup-info.ts +32 -0
- package/types/touch-app-core.ts +8 -8
- package/types/update.ts +94 -1
- package/vitest.config.ts +25 -0
- package/auth/useClerkConfig.ts +0 -40
- package/auth/useClerkProvider.ts +0 -52
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Core SDK types for TuffTransport
|
|
3
|
+
* @module @talex-touch/utils/transport/types
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { TuffEvent } from './event/types'
|
|
7
|
+
import type { TransportPortUpgradeRequest, TransportPortUpgradeResponse } from './events/types/transport'
|
|
8
|
+
|
|
9
|
+
// Electron types - import from electron package if available
|
|
10
|
+
// This allows the package to work in both Electron and non-Electron contexts
|
|
11
|
+
type ElectronWebContents = import('electron').WebContents
|
|
12
|
+
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Send Options
|
|
15
|
+
// ============================================================================
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Options for sending a transport message.
|
|
19
|
+
*/
|
|
20
|
+
export interface SendOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Skip batching and send immediately.
|
|
23
|
+
* Use this for time-critical requests.
|
|
24
|
+
* @defaultValue false
|
|
25
|
+
*/
|
|
26
|
+
immediate?: boolean
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Request timeout in milliseconds.
|
|
30
|
+
* @defaultValue 10000
|
|
31
|
+
*/
|
|
32
|
+
timeout?: number
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Optional cache control for transport responses.
|
|
36
|
+
* Only used when explicitly enabled.
|
|
37
|
+
*/
|
|
38
|
+
cache?: boolean | {
|
|
39
|
+
/**
|
|
40
|
+
* Custom cache key override.
|
|
41
|
+
*/
|
|
42
|
+
key?: string
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Cache mode.
|
|
46
|
+
* - prefer: return cached value when available, otherwise fetch
|
|
47
|
+
* - only: return cached value or throw if missing
|
|
48
|
+
* @defaultValue prefer
|
|
49
|
+
*/
|
|
50
|
+
mode?: 'prefer' | 'only'
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Cache time-to-live in milliseconds.
|
|
54
|
+
*/
|
|
55
|
+
ttlMs?: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Target window ID for main process.
|
|
60
|
+
* If not specified, sends to the default window.
|
|
61
|
+
* @remarks Only applicable in main process context.
|
|
62
|
+
*/
|
|
63
|
+
targetWindowId?: number
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Target WebContents ID for precise targeting.
|
|
67
|
+
* @remarks Only applicable in main process context.
|
|
68
|
+
*/
|
|
69
|
+
targetWebContentsId?: number
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ============================================================================
|
|
73
|
+
// Stream Types
|
|
74
|
+
// ============================================================================
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Message types for stream communication.
|
|
78
|
+
*/
|
|
79
|
+
export type StreamMessageType = 'data' | 'error' | 'end'
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Message structure for stream communication via MessagePort.
|
|
83
|
+
*
|
|
84
|
+
* @typeParam T - Type of the data payload
|
|
85
|
+
*/
|
|
86
|
+
export interface StreamMessage<T = unknown> {
|
|
87
|
+
/**
|
|
88
|
+
* Type of stream message.
|
|
89
|
+
*/
|
|
90
|
+
type: StreamMessageType
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Data payload (only for 'data' type).
|
|
94
|
+
*/
|
|
95
|
+
chunk?: T
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Error message (only for 'error' type).
|
|
99
|
+
*/
|
|
100
|
+
error?: string
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Stream identifier.
|
|
104
|
+
*/
|
|
105
|
+
streamId: string
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Options for stream consumption.
|
|
110
|
+
*
|
|
111
|
+
* @typeParam TChunk - Type of each data chunk
|
|
112
|
+
*/
|
|
113
|
+
export interface StreamOptions<TChunk> {
|
|
114
|
+
/**
|
|
115
|
+
* Callback invoked for each data chunk.
|
|
116
|
+
* @param chunk - The data chunk
|
|
117
|
+
*/
|
|
118
|
+
onData: (chunk: TChunk) => void
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Callback invoked when an error occurs.
|
|
122
|
+
* @param error - The error that occurred
|
|
123
|
+
*/
|
|
124
|
+
onError?: (error: Error) => void
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Callback invoked when the stream ends.
|
|
128
|
+
*/
|
|
129
|
+
onEnd?: () => void
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Optional port upgrade settings for stream transport.
|
|
133
|
+
* Set to false to disable MessagePort and use channel fallback.
|
|
134
|
+
*/
|
|
135
|
+
port?: TransportPortOpenOptions | false
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface TransportPortHandle {
|
|
139
|
+
portId: string
|
|
140
|
+
channel: string
|
|
141
|
+
port: MessagePort
|
|
142
|
+
close: (reason?: string) => Promise<void>
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface TransportPortOpenOptions extends TransportPortUpgradeRequest {
|
|
146
|
+
force?: boolean
|
|
147
|
+
timeoutMs?: number
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Controller for managing an active stream.
|
|
152
|
+
*/
|
|
153
|
+
export interface StreamController {
|
|
154
|
+
/**
|
|
155
|
+
* Cancels the stream.
|
|
156
|
+
* After cancellation, no more data/error/end callbacks will be invoked.
|
|
157
|
+
*/
|
|
158
|
+
cancel: () => void
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Whether the stream has been cancelled.
|
|
162
|
+
*/
|
|
163
|
+
readonly cancelled: boolean
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Unique identifier for this stream.
|
|
167
|
+
*/
|
|
168
|
+
readonly streamId: string
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Server-side context for emitting stream data.
|
|
173
|
+
*
|
|
174
|
+
* @typeParam TChunk - Type of data chunks to emit
|
|
175
|
+
*/
|
|
176
|
+
export interface StreamContext<TChunk> {
|
|
177
|
+
/**
|
|
178
|
+
* Emits a data chunk to the client.
|
|
179
|
+
* @param chunk - The data to send
|
|
180
|
+
*/
|
|
181
|
+
emit: (chunk: TChunk) => void
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Emits an error and closes the stream.
|
|
185
|
+
* @param err - The error to send
|
|
186
|
+
*/
|
|
187
|
+
error: (err: Error) => void
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Signals successful completion of the stream.
|
|
191
|
+
*/
|
|
192
|
+
end: () => void
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Checks if the client has cancelled the stream.
|
|
196
|
+
* @returns `true` if cancelled
|
|
197
|
+
*/
|
|
198
|
+
isCancelled: () => boolean
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Unique identifier for this stream.
|
|
202
|
+
*/
|
|
203
|
+
readonly streamId: string
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ============================================================================
|
|
207
|
+
// Batch Types
|
|
208
|
+
// ============================================================================
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Payload for a batched request.
|
|
212
|
+
*/
|
|
213
|
+
export interface BatchPayload {
|
|
214
|
+
/**
|
|
215
|
+
* Event name.
|
|
216
|
+
*/
|
|
217
|
+
event: string
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Array of individual requests.
|
|
221
|
+
*/
|
|
222
|
+
requests: Array<{
|
|
223
|
+
/**
|
|
224
|
+
* Unique request ID for response correlation.
|
|
225
|
+
*/
|
|
226
|
+
id: string
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Request payload.
|
|
230
|
+
*/
|
|
231
|
+
payload: unknown
|
|
232
|
+
}>
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Result for a single request in a batch.
|
|
237
|
+
*/
|
|
238
|
+
export interface BatchResult {
|
|
239
|
+
/**
|
|
240
|
+
* Request ID (correlates to BatchPayload.requests[].id).
|
|
241
|
+
*/
|
|
242
|
+
id: string
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Response data (if successful).
|
|
246
|
+
*/
|
|
247
|
+
data?: unknown
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Error message (if failed).
|
|
251
|
+
*/
|
|
252
|
+
error?: string
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Response for a batched request.
|
|
257
|
+
*/
|
|
258
|
+
export interface BatchResponse {
|
|
259
|
+
/**
|
|
260
|
+
* Event name.
|
|
261
|
+
*/
|
|
262
|
+
event: string
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Array of results matching the request order.
|
|
266
|
+
*/
|
|
267
|
+
results: BatchResult[]
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ============================================================================
|
|
271
|
+
// Handler Context
|
|
272
|
+
// ============================================================================
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Context provided to event handlers in the main process.
|
|
276
|
+
*/
|
|
277
|
+
export interface HandlerContext {
|
|
278
|
+
/**
|
|
279
|
+
* The WebContents that sent this request.
|
|
280
|
+
*/
|
|
281
|
+
sender: ElectronWebContents
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* The event name being handled.
|
|
285
|
+
*/
|
|
286
|
+
eventName: string
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Plugin context if this is a plugin request.
|
|
290
|
+
*/
|
|
291
|
+
plugin?: PluginSecurityContext
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// ============================================================================
|
|
295
|
+
// Plugin Security
|
|
296
|
+
// ============================================================================
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Security context for plugin communication.
|
|
300
|
+
*
|
|
301
|
+
* @remarks
|
|
302
|
+
* This maintains compatibility with the existing plugin key mechanism.
|
|
303
|
+
* Each plugin is assigned a unique key that must be included in messages.
|
|
304
|
+
*/
|
|
305
|
+
export interface PluginSecurityContext {
|
|
306
|
+
/**
|
|
307
|
+
* Plugin name.
|
|
308
|
+
*/
|
|
309
|
+
name: string
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Encrypted unique key for this plugin session.
|
|
313
|
+
* This key is generated when the plugin UI view is attached.
|
|
314
|
+
*/
|
|
315
|
+
uniqueKey: string
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Whether this is a verified plugin context.
|
|
319
|
+
*/
|
|
320
|
+
verified: boolean
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Manager for plugin security keys.
|
|
325
|
+
*
|
|
326
|
+
* @remarks
|
|
327
|
+
* This interface maintains compatibility with the existing requestKey/revokeKey mechanism.
|
|
328
|
+
*/
|
|
329
|
+
export interface PluginKeyManager {
|
|
330
|
+
/**
|
|
331
|
+
* Requests a new encrypted key for a plugin.
|
|
332
|
+
*
|
|
333
|
+
* @param pluginName - Name of the plugin
|
|
334
|
+
* @returns The encrypted key
|
|
335
|
+
*/
|
|
336
|
+
requestKey: (pluginName: string) => string
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Revokes a previously issued key.
|
|
340
|
+
*
|
|
341
|
+
* @param key - The key to revoke
|
|
342
|
+
* @returns `true` if successfully revoked
|
|
343
|
+
*/
|
|
344
|
+
revokeKey: (key: string) => boolean
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Resolves a key to its plugin name.
|
|
348
|
+
*
|
|
349
|
+
* @param key - The encrypted key
|
|
350
|
+
* @returns Plugin name or `undefined` if invalid
|
|
351
|
+
*/
|
|
352
|
+
resolveKey: (key: string) => string | undefined
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Checks if a key is valid.
|
|
356
|
+
*
|
|
357
|
+
* @param key - The key to validate
|
|
358
|
+
* @returns `true` if valid
|
|
359
|
+
*/
|
|
360
|
+
isValidKey: (key: string) => boolean
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// ============================================================================
|
|
364
|
+
// Transport Interfaces
|
|
365
|
+
// ============================================================================
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Renderer-side transport interface.
|
|
369
|
+
*
|
|
370
|
+
* @remarks
|
|
371
|
+
* This is the primary interface for renderer processes and plugins
|
|
372
|
+
* to communicate with the main process.
|
|
373
|
+
*/
|
|
374
|
+
export interface ITuffTransport {
|
|
375
|
+
/**
|
|
376
|
+
* Sends a request and waits for response.
|
|
377
|
+
*
|
|
378
|
+
* @typeParam TReq - Request payload type
|
|
379
|
+
* @typeParam TRes - Response payload type
|
|
380
|
+
* @param event - The TuffEvent to send
|
|
381
|
+
* @param payload - Request payload
|
|
382
|
+
* @param options - Send options
|
|
383
|
+
* @returns Promise resolving to the response
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```typescript
|
|
387
|
+
* const result = await transport.send(
|
|
388
|
+
* CoreBoxEvents.search.query,
|
|
389
|
+
* { text: 'hello' }
|
|
390
|
+
* )
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
send: (<TReq, TRes>(
|
|
394
|
+
event: TuffEvent<TReq, TRes>,
|
|
395
|
+
payload: TReq,
|
|
396
|
+
options?: SendOptions,
|
|
397
|
+
) => Promise<TRes>) & (<TRes>(
|
|
398
|
+
event: TuffEvent<void, TRes>,
|
|
399
|
+
payload?: void,
|
|
400
|
+
options?: SendOptions,
|
|
401
|
+
) => Promise<TRes>)
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Requests a MessagePort upgrade for a given channel.
|
|
405
|
+
* Returns a response indicating whether the upgrade was accepted.
|
|
406
|
+
*/
|
|
407
|
+
upgrade: (options: TransportPortUpgradeRequest) => Promise<TransportPortUpgradeResponse>
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Opens (or reuses) a MessagePort transport channel.
|
|
411
|
+
* Returns null when MessagePort is not available.
|
|
412
|
+
*/
|
|
413
|
+
openPort: (options: TransportPortOpenOptions) => Promise<TransportPortHandle | null>
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Initiates a stream request.
|
|
417
|
+
*
|
|
418
|
+
* @typeParam TReq - Request payload type
|
|
419
|
+
* @typeParam TChunk - Stream chunk type
|
|
420
|
+
* @param event - The stream TuffEvent
|
|
421
|
+
* @param payload - Request payload
|
|
422
|
+
* @param options - Stream callbacks
|
|
423
|
+
* @returns Promise resolving to a StreamController
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* const controller = await transport.stream(
|
|
428
|
+
* CoreBoxEvents.search.stream,
|
|
429
|
+
* { text: 'hello' },
|
|
430
|
+
* {
|
|
431
|
+
* onData: (result) => console.log(result),
|
|
432
|
+
* onEnd: () => console.log('done')
|
|
433
|
+
* }
|
|
434
|
+
* )
|
|
435
|
+
*
|
|
436
|
+
* // Later: cancel if needed
|
|
437
|
+
* controller.cancel()
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
stream: <TReq, TChunk>(
|
|
441
|
+
event: TuffEvent<TReq, AsyncIterable<TChunk>>,
|
|
442
|
+
payload: TReq,
|
|
443
|
+
options: StreamOptions<TChunk>,
|
|
444
|
+
) => Promise<StreamController>
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Registers an event handler (for receiving messages from main process).
|
|
448
|
+
*
|
|
449
|
+
* @typeParam TReq - Request payload type
|
|
450
|
+
* @typeParam TRes - Response payload type
|
|
451
|
+
* @param event - The TuffEvent to handle
|
|
452
|
+
* @param handler - Handler function
|
|
453
|
+
* @returns Cleanup function to unregister
|
|
454
|
+
*/
|
|
455
|
+
on: <TReq, TRes>(
|
|
456
|
+
event: TuffEvent<TReq, TRes>,
|
|
457
|
+
handler: (payload: TReq) => TRes | Promise<TRes>,
|
|
458
|
+
) => () => void
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Forces immediate flush of all pending batch requests.
|
|
462
|
+
* @returns Promise that resolves when all batches are flushed
|
|
463
|
+
*/
|
|
464
|
+
flush: () => Promise<void>
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Destroys the transport instance and cleans up resources.
|
|
468
|
+
*/
|
|
469
|
+
destroy: () => void
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Main process transport interface.
|
|
474
|
+
*
|
|
475
|
+
* @remarks
|
|
476
|
+
* This interface is used in the main process to handle incoming
|
|
477
|
+
* requests and send messages to renderer processes.
|
|
478
|
+
*/
|
|
479
|
+
export interface ITuffTransportMain {
|
|
480
|
+
/**
|
|
481
|
+
* Registers an event handler.
|
|
482
|
+
*
|
|
483
|
+
* @typeParam TReq - Request payload type
|
|
484
|
+
* @typeParam TRes - Response payload type
|
|
485
|
+
* @param event - The TuffEvent to handle
|
|
486
|
+
* @param handler - Handler function
|
|
487
|
+
* @returns Cleanup function to unregister
|
|
488
|
+
*/
|
|
489
|
+
on: <TReq, TRes>(
|
|
490
|
+
event: TuffEvent<TReq, TRes>,
|
|
491
|
+
handler: (payload: TReq, context: HandlerContext) => TRes | Promise<TRes>,
|
|
492
|
+
) => () => void
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Registers a stream handler.
|
|
496
|
+
*
|
|
497
|
+
* @typeParam TReq - Request payload type
|
|
498
|
+
* @typeParam TChunk - Stream chunk type
|
|
499
|
+
* @param event - The stream TuffEvent
|
|
500
|
+
* @param handler - Handler function
|
|
501
|
+
* @returns Cleanup function to unregister
|
|
502
|
+
*/
|
|
503
|
+
onStream: <TReq, TChunk>(
|
|
504
|
+
event: TuffEvent<TReq, AsyncIterable<TChunk>>,
|
|
505
|
+
handler: (payload: TReq, context: StreamContext<TChunk>) => void | Promise<void>,
|
|
506
|
+
) => () => void
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Sends a message to a specific window.
|
|
510
|
+
*
|
|
511
|
+
* @typeParam TReq - Request payload type
|
|
512
|
+
* @typeParam TRes - Response payload type
|
|
513
|
+
* @param windowId - Target window ID
|
|
514
|
+
* @param event - The TuffEvent to send
|
|
515
|
+
* @param payload - Request payload
|
|
516
|
+
* @returns Promise resolving to the response
|
|
517
|
+
*/
|
|
518
|
+
sendToWindow: <TReq, TRes>(
|
|
519
|
+
windowId: number,
|
|
520
|
+
event: TuffEvent<TReq, TRes>,
|
|
521
|
+
payload: TReq,
|
|
522
|
+
) => Promise<TRes>
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Broadcasts a message to a specific window (fire-and-forget).
|
|
526
|
+
*
|
|
527
|
+
* @typeParam TReq - Request payload type
|
|
528
|
+
* @param windowId - Target window ID
|
|
529
|
+
* @param event - The TuffEvent to send
|
|
530
|
+
* @param payload - Request payload
|
|
531
|
+
*/
|
|
532
|
+
broadcastToWindow: <TReq>(
|
|
533
|
+
windowId: number,
|
|
534
|
+
event: TuffEvent<TReq, void>,
|
|
535
|
+
payload: TReq,
|
|
536
|
+
) => void
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Sends a message to a specific WebContents.
|
|
540
|
+
*
|
|
541
|
+
* @typeParam TReq - Request payload type
|
|
542
|
+
* @typeParam TRes - Response payload type
|
|
543
|
+
* @param webContents - Target WebContents
|
|
544
|
+
* @param event - The TuffEvent to send
|
|
545
|
+
* @param payload - Request payload
|
|
546
|
+
* @returns Promise resolving to the response
|
|
547
|
+
*/
|
|
548
|
+
sendTo: <TReq, TRes>(
|
|
549
|
+
webContents: ElectronWebContents,
|
|
550
|
+
event: TuffEvent<TReq, TRes>,
|
|
551
|
+
payload: TReq,
|
|
552
|
+
) => Promise<TRes>
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Sends a message to a plugin's renderer.
|
|
556
|
+
*
|
|
557
|
+
* @typeParam TReq - Request payload type
|
|
558
|
+
* @typeParam TRes - Response payload type
|
|
559
|
+
* @param pluginName - Target plugin name
|
|
560
|
+
* @param event - The TuffEvent to send
|
|
561
|
+
* @param payload - Request payload
|
|
562
|
+
* @returns Promise resolving to the response
|
|
563
|
+
*/
|
|
564
|
+
sendToPlugin: <TReq, TRes>(
|
|
565
|
+
pluginName: string,
|
|
566
|
+
event: TuffEvent<TReq, TRes>,
|
|
567
|
+
payload: TReq,
|
|
568
|
+
) => Promise<TRes>
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Broadcasts a message to all windows.
|
|
572
|
+
*
|
|
573
|
+
* @typeParam TReq - Request payload type
|
|
574
|
+
* @param event - The TuffEvent to broadcast
|
|
575
|
+
* @param payload - Request payload
|
|
576
|
+
*/
|
|
577
|
+
broadcast: <TReq>(
|
|
578
|
+
event: TuffEvent<TReq, void>,
|
|
579
|
+
payload: TReq,
|
|
580
|
+
) => void
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Plugin key manager for security.
|
|
584
|
+
*/
|
|
585
|
+
readonly keyManager: PluginKeyManager
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Plugin-specific transport interface.
|
|
590
|
+
*
|
|
591
|
+
* @remarks
|
|
592
|
+
* Extends the base transport with plugin-specific functionality
|
|
593
|
+
* and automatic plugin context injection.
|
|
594
|
+
*/
|
|
595
|
+
export interface IPluginTuffTransport extends ITuffTransport {
|
|
596
|
+
/**
|
|
597
|
+
* The plugin name this transport belongs to.
|
|
598
|
+
*/
|
|
599
|
+
readonly pluginName: string
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* The plugin's unique security key.
|
|
603
|
+
*/
|
|
604
|
+
readonly pluginKey: string
|
|
605
|
+
}
|