@ai-workbench/connect 0.7.23 → 0.7.26
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 +20 -73
- package/client/index.cjs +93 -65
- package/helper/host-directories.cjs +8 -1
- package/lib/api.d.ts +21 -163
- package/lib/component-download.d.ts +1 -1
- package/lib/component-download.js +1 -1
- package/lib/component-source.d.ts +6 -27
- package/lib/component-source.js +10 -138
- package/lib/components.d.ts +1 -1
- package/lib/components.js +86 -98
- package/lib/connect.d.ts +0 -3
- package/lib/connect.js +15 -62
- package/lib/connection-messages.d.ts +2 -3
- package/lib/connection-messages.js +5 -4
- package/lib/conversation-log.d.ts +9 -0
- package/lib/conversation-log.js +44 -0
- package/lib/cordis.d.ts +1 -4
- package/lib/defaults.d.ts +0 -7
- package/lib/defaults.js +0 -2
- package/lib/enrollment.js +1 -8
- package/lib/host-directories.d.ts +6 -4
- package/lib/host-directories.js +4 -4
- package/lib/host-session-projects.d.ts +8 -58
- package/lib/host-session-projects.js +45 -270
- package/lib/index.d.ts +2 -11
- package/lib/index.js +11 -23
- package/lib/integration.d.ts +2 -2
- package/lib/integration.js +0 -2
- package/lib/native-workspace.d.ts +10 -0
- package/lib/needs.js +13 -25
- package/lib/ports.d.ts +1 -6
- package/lib/profile-runtime.js +59 -152
- package/lib/profile-settings.d.ts +6 -1
- package/lib/profile-settings.js +3 -5
- package/lib/startup.js +2 -2
- package/lib/workspace-directory-picker-types.d.ts +44 -0
- package/lib/workspace-directory-picker-types.js +1 -0
- package/lib/workspace-directory-picker.d.ts +30 -0
- package/lib/workspace-directory-picker.js +394 -0
- package/lib/workspace-location-types.d.ts +3 -7
- package/lib/workspace-locations.d.ts +5 -29
- package/lib/workspace-locations.js +81 -204
- package/package.json +3 -2
- package/helper/projects.cjs +0 -57
- package/lib/conversation-detail-settings.d.ts +0 -32
- package/lib/conversation-detail-settings.js +0 -119
- package/lib/conversation-details.d.ts +0 -30
- package/lib/conversation-details.js +0 -595
- package/lib/host-session-store.d.ts +0 -27
- package/lib/host-session-store.js +0 -130
- package/lib/local-acceptance-store.d.ts +0 -18
- package/lib/local-acceptance-store.js +0 -133
- package/lib/local-user-turn-acceptance.d.ts +0 -76
- package/lib/local-user-turn-acceptance.js +0 -289
- package/lib/local-user-turn-types.d.ts +0 -40
- package/lib/login-diagnostics.d.ts +0 -28
- package/lib/login-diagnostics.js +0 -57
- package/lib/projects.d.ts +0 -4
- package/lib/projects.js +0 -41
- package/lib/workspace-bindings.d.ts +0 -64
- package/lib/workspace-bindings.js +0 -379
- /package/lib/{local-user-turn-types.js → native-workspace.js} +0 -0
package/lib/api.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { LocalUserTurnAcceptanceRequest, LocalUserTurnAcceptance } from './local-user-turn-types.ts';
|
|
2
|
-
export type { LocalUserTurnAcceptanceRequest, LocalUserTurnAcceptance } from './local-user-turn-types.ts';
|
|
3
1
|
export { CONNECTION_MESSAGES, connectionEmployeeMessage } from './connection-messages.ts';
|
|
4
2
|
import type { HostWorkspaceResolveContext, WorkspaceLocationState, WorkspaceBrowseRequest, WorkspaceBrowsePage, WorkspaceSelectRequest } from './workspace-location-types.ts';
|
|
5
3
|
export type * from './workspace-location-types.ts';
|
|
6
4
|
import type { LocalWorkspaceContextRequest, LocalWorkspaceContext } from './local-workspace-context.ts';
|
|
7
5
|
export type { LocalWorkspaceContextRequest, LocalWorkspaceContext, LocalWorkspaceProcess } from './local-workspace-context.ts';
|
|
8
6
|
export type Provider = 'claude' | 'codex';
|
|
9
|
-
export type NeedCode = '
|
|
7
|
+
export type NeedCode = 'WORKSPACE_PICKER_INVALID' | 'WORKSPACE_PICKER_STORAGE_FAILED' | 'WORKSPACE_PICKER_ROLLBACK_FAILED' | 'LOCAL_WORKSPACE_CONTEXT_UNSUPPORTED' | 'LOCAL_WORKSPACE_CONTEXT_UNAVAILABLE' | 'HOST_DIRECTORY_EXISTS' | 'HOST_DIRECTORY_INVALID' | 'HOST_DIRECTORY_UNREADABLE' | 'HOST_DIRECTORY_CHANGED' | 'HOST_DIRECTORY_PAGE_TOO_LARGE' | 'WORKSPACE_LOCATION_REQUIRED' | 'WORKSPACE_LOCATION_INVALID' | 'WORKSPACE_LOCATION_CONFLICT' | 'WORKSPACE_LOCATION_PROVIDER_REQUIRED' | 'WORKSPACE_EXECUTION_UNAVAILABLE' | 'WORKSPACE_LOCATION_STORAGE_FAILED' | 'REMOTE_DETAIL_STORAGE_FAILED' | 'MODEL_CATALOG_CONTEXT_INVALID' | 'ACTIVATION_CONFLICT' | 'ACTIVATION_CANCELLED' | 'ENROLLMENT_CLEANUP_UNBOUND' | 'ENROLLMENT_CLEANUP_FAILED' | 'ENROLLMENT_MISMATCH' | 'LOCAL_STATE_INVALID' | 'ALREADY_RUNNING' | 'ENROLLMENT_RECEIPT_REQUIRED' | 'CONTROL_PROTOCOL_INVALID' | 'HELPER_HANDOFF_FAILED' | 'HELPER_SHUTDOWN_FORCED' | 'ENROLLMENT_RESULT_UNKNOWN' | 'ENROLLMENT_REJECTED' | 'ENROLLMENT_REQUIRED' | 'ENROLLMENT_INVALID' | 'NETWORK_KEY_INVALID' | 'HOST_OFFLINE' | 'EMPLOYEE_MISSING' | 'SSH_FAILED' | 'LOGIN_REQUIRED' | 'POLICY_DENIED' | 'CONNECTION_LOST' | 'DEPENDENCY_REQUIRED' | 'SETTINGS_REQUIRED' | 'AUTH_STATUS_INVALID' | 'LOGIN_FAILED' | 'LOGIN_PROMPT_INVALID' | 'DISPOSED' | 'HOST_TRUST_REQUIRED' | 'HOST_KEY_MISMATCH' | 'PROJECT_PROTOCOL_INVALID' | 'PROJECT_BINDING_REQUIRED' | 'PROJECT_BINDING_INVALID';
|
|
10
8
|
export interface ConnectNeed {
|
|
11
9
|
code: NeedCode;
|
|
12
10
|
layer: 'enrollment' | 'network' | 'ssh' | 'auth' | 'integration' | 'settings' | 'projects';
|
|
@@ -34,20 +32,7 @@ export interface SessionTarget {
|
|
|
34
32
|
settingsPath: string;
|
|
35
33
|
protocolVersion: 1;
|
|
36
34
|
}
|
|
37
|
-
export interface HostContext {
|
|
38
|
-
enforcement: 'production' | 'test';
|
|
39
|
-
checkExitCode: 0 | 1;
|
|
40
|
-
failedChecks: {
|
|
41
|
-
id: string;
|
|
42
|
-
status: string;
|
|
43
|
-
}[];
|
|
44
|
-
unverifiedChecks: {
|
|
45
|
-
id: string;
|
|
46
|
-
status: string;
|
|
47
|
-
}[];
|
|
48
|
-
}
|
|
49
35
|
export interface SshTarget {
|
|
50
|
-
hostContext?: HostContext;
|
|
51
36
|
host: string;
|
|
52
37
|
username: string;
|
|
53
38
|
port: number;
|
|
@@ -67,23 +52,10 @@ export interface ConnectState {
|
|
|
67
52
|
provider?: Provider;
|
|
68
53
|
need?: ConnectNeed;
|
|
69
54
|
}
|
|
70
|
-
export interface Project {
|
|
71
|
-
name: string;
|
|
72
|
-
path: string;
|
|
73
|
-
}
|
|
74
|
-
export interface ProjectList {
|
|
75
|
-
projects: Project[];
|
|
76
|
-
unavailable: {
|
|
77
|
-
name: string;
|
|
78
|
-
reason: 'invalid-name' | 'symlink' | 'not-directory' | 'permissions' | 'not-git' | 'invalid-git' | 'outside-root';
|
|
79
|
-
}[];
|
|
80
|
-
}
|
|
81
55
|
export interface ConnectionRecovery {
|
|
82
56
|
version: 1;
|
|
83
|
-
phase: 'reconnecting'
|
|
84
|
-
message: '正在自动重连' | '请联系管理员';
|
|
57
|
+
phase: 'reconnecting';
|
|
85
58
|
startedAt: number;
|
|
86
|
-
administratorAfterMs: number;
|
|
87
59
|
}
|
|
88
60
|
export interface ConnectionState {
|
|
89
61
|
recovery?: ConnectionRecovery;
|
|
@@ -105,7 +77,6 @@ export interface LoginPromptState {
|
|
|
105
77
|
providerNeeds: Partial<Record<Provider, ConnectNeed>>;
|
|
106
78
|
technicalDetails: {
|
|
107
79
|
code?: NeedCode;
|
|
108
|
-
hostContext?: HostContext;
|
|
109
80
|
};
|
|
110
81
|
}
|
|
111
82
|
export interface LoginPromptResult {
|
|
@@ -115,41 +86,20 @@ export interface LoginPromptResult {
|
|
|
115
86
|
need?: ConnectNeed;
|
|
116
87
|
}
|
|
117
88
|
export interface ContractInfo {
|
|
89
|
+
workspaceDirectoryPicker?: 1;
|
|
118
90
|
apiVersion: '0.7.0';
|
|
119
91
|
status: 'implemented';
|
|
120
|
-
|
|
121
|
-
remoteConversationDetails?: 1;
|
|
122
|
-
loginDiagnostics?: 1;
|
|
123
|
-
preflightDiagnostics?: 1;
|
|
92
|
+
conversationLog?: 1;
|
|
124
93
|
workspaceLocations?: 1;
|
|
125
94
|
connectionMessages?: 1;
|
|
126
95
|
localWorkspaceContext?: 1;
|
|
127
96
|
modelCatalogTarget?: 1;
|
|
128
|
-
localUserTurnAcceptance?: 1;
|
|
129
97
|
hostWorkspaceResolution?: 1;
|
|
130
98
|
}
|
|
131
99
|
export interface WorkspaceUse {
|
|
132
100
|
provider: Provider;
|
|
133
101
|
purpose: 'user-turn';
|
|
134
102
|
}
|
|
135
|
-
export interface WorkspaceNotice {
|
|
136
|
-
noticeId: string;
|
|
137
|
-
claimId: string;
|
|
138
|
-
workspaceName: string;
|
|
139
|
-
messageKey: 'remote-workspace-binding';
|
|
140
|
-
}
|
|
141
|
-
export interface SessionProjectTarget {
|
|
142
|
-
instanceId: string;
|
|
143
|
-
epoch: number;
|
|
144
|
-
bindingRevision: number;
|
|
145
|
-
bindingId: string;
|
|
146
|
-
sessionId: string;
|
|
147
|
-
workspaceId: string;
|
|
148
|
-
project: Project;
|
|
149
|
-
target: SshTarget;
|
|
150
|
-
notice?: WorkspaceNotice;
|
|
151
|
-
source?: 'legacy-host';
|
|
152
|
-
}
|
|
153
103
|
export interface HostSessionProjectTarget {
|
|
154
104
|
instanceId: string;
|
|
155
105
|
epoch: number;
|
|
@@ -159,44 +109,12 @@ export interface HostSessionProjectTarget {
|
|
|
159
109
|
workspaceId: string;
|
|
160
110
|
source: 'host';
|
|
161
111
|
directory: import('./host-directories.ts').HostDirectoryInfo;
|
|
162
|
-
project:
|
|
112
|
+
project: {
|
|
113
|
+
name: string;
|
|
114
|
+
path: string;
|
|
115
|
+
};
|
|
163
116
|
target: SshTarget;
|
|
164
117
|
}
|
|
165
|
-
export interface WorkspaceBindingState {
|
|
166
|
-
instanceId: string;
|
|
167
|
-
revision: number;
|
|
168
|
-
items: {
|
|
169
|
-
bindingId: string;
|
|
170
|
-
workspaceId: string;
|
|
171
|
-
workspaceName: string;
|
|
172
|
-
status: 'ready' | 'unavailable' | 'invalid' | 'pending';
|
|
173
|
-
notice: {
|
|
174
|
-
noticeId: string;
|
|
175
|
-
settings: 'pending' | 'displayed';
|
|
176
|
-
provider: 'pending' | 'claimed' | 'delivered' | 'unknown';
|
|
177
|
-
};
|
|
178
|
-
}[];
|
|
179
|
-
}
|
|
180
|
-
export type WorkspaceNoticeReceipt = {
|
|
181
|
-
noticeId: string;
|
|
182
|
-
surface: 'settings';
|
|
183
|
-
outcome: 'displayed';
|
|
184
|
-
} | {
|
|
185
|
-
noticeId: string;
|
|
186
|
-
surface: 'provider';
|
|
187
|
-
claimId: string;
|
|
188
|
-
sessionId: string;
|
|
189
|
-
provider: Provider;
|
|
190
|
-
outcome: 'delivered';
|
|
191
|
-
deliveryId: string;
|
|
192
|
-
} | {
|
|
193
|
-
noticeId: string;
|
|
194
|
-
surface: 'provider';
|
|
195
|
-
claimId: string;
|
|
196
|
-
sessionId: string;
|
|
197
|
-
provider: Provider;
|
|
198
|
-
outcome: 'not-delivered' | 'unknown';
|
|
199
|
-
};
|
|
200
118
|
export interface EnrollmentState {
|
|
201
119
|
instanceId: string;
|
|
202
120
|
revision: number;
|
|
@@ -223,32 +141,6 @@ export interface RemoteConversationDetail {
|
|
|
223
141
|
method?: string;
|
|
224
142
|
payload: DetailJson;
|
|
225
143
|
}
|
|
226
|
-
export interface RemoteConversationDetailState {
|
|
227
|
-
instanceId: string;
|
|
228
|
-
epoch: number;
|
|
229
|
-
revision: number;
|
|
230
|
-
phase: 'loading' | 'ready' | 'unavailable' | 'failed' | 'disposed';
|
|
231
|
-
sessions: {
|
|
232
|
-
sessionId: string;
|
|
233
|
-
provider: Provider;
|
|
234
|
-
total: number;
|
|
235
|
-
unknownCount: number;
|
|
236
|
-
actionRequiredCount: number;
|
|
237
|
-
}[];
|
|
238
|
-
need?: ConnectNeed;
|
|
239
|
-
}
|
|
240
|
-
export interface RemoteDetailQuery {
|
|
241
|
-
sessionId: string;
|
|
242
|
-
provider: Provider;
|
|
243
|
-
cursor?: string;
|
|
244
|
-
}
|
|
245
|
-
export interface RemoteDetailPage {
|
|
246
|
-
items: RemoteConversationDetail[];
|
|
247
|
-
total: number;
|
|
248
|
-
unknownCount: number;
|
|
249
|
-
actionRequiredCount: number;
|
|
250
|
-
nextCursor?: string;
|
|
251
|
-
}
|
|
252
144
|
export interface ModelCatalogTarget {
|
|
253
145
|
version: 1;
|
|
254
146
|
purpose: 'model-catalog';
|
|
@@ -259,54 +151,24 @@ export interface ModelCatalogTarget {
|
|
|
259
151
|
target: SshTarget;
|
|
260
152
|
}
|
|
261
153
|
export interface ConnectApi {
|
|
262
|
-
|
|
154
|
+
getWorkspaceDirectoryPickerSettings?(): import('./workspace-directory-picker-types.ts').WorkspacePickerSettings;
|
|
155
|
+
browseWorkspaceDirectories?(request: import('./workspace-directory-picker-types.ts').WorkspacePickerRequest): Promise<Result<import('./workspace-directory-picker-types.ts').WorkspacePickerPage>>;
|
|
156
|
+
createWorkspaceDirectory?(request: {
|
|
157
|
+
selectionToken: string;
|
|
158
|
+
name: string;
|
|
159
|
+
}): Promise<Result<import('./workspace-directory-picker-types.ts').WorkspacePickerPage>>;
|
|
160
|
+
selectWorkspaceDirectory?(request: {
|
|
161
|
+
selectionToken: string;
|
|
162
|
+
}): Promise<Result<import('./workspace-directory-picker-types.ts').WorkspacePickerSelection>>;
|
|
263
163
|
getLocalWorkspaceContext?(request: LocalWorkspaceContextRequest): Promise<Result<LocalWorkspaceContext>>;
|
|
264
164
|
getWorkspaceLocationState?(): WorkspaceLocationState;
|
|
265
165
|
onWorkspaceLocationState?(listener: (state: WorkspaceLocationState) => void): () => void;
|
|
266
166
|
refreshWorkspaceLocations?(): Promise<Result<WorkspaceLocationState>>;
|
|
267
167
|
browseWorkspaceHostDirectories?(request: WorkspaceBrowseRequest): Promise<Result<WorkspaceBrowsePage>>;
|
|
268
168
|
selectWorkspaceLocation?(request: WorkspaceSelectRequest): Promise<Result<WorkspaceLocationState>>;
|
|
269
|
-
appendLoginDiagnostic(detail: RemoteConversationDetail): Promise<Result<{
|
|
270
|
-
eventId: string;
|
|
271
|
-
recorded: true;
|
|
272
|
-
}>>;
|
|
273
|
-
getLoginDiagnosticReceipt(query: {
|
|
274
|
-
eventId: string;
|
|
275
|
-
sessionId: string;
|
|
276
|
-
provider: Provider;
|
|
277
|
-
}): Promise<Result<{
|
|
278
|
-
eventId: string;
|
|
279
|
-
recorded: false;
|
|
280
|
-
} | {
|
|
281
|
-
eventId: string;
|
|
282
|
-
recorded: true;
|
|
283
|
-
detail: RemoteConversationDetail;
|
|
284
|
-
}>>;
|
|
285
|
-
listLoginDiagnostics(query: RemoteDetailQuery): Promise<Result<RemoteDetailPage>>;
|
|
286
|
-
getLoginDiagnosticState(): RemoteConversationDetailState;
|
|
287
|
-
onLoginDiagnosticState(listener: (state: RemoteConversationDetailState) => void): () => void;
|
|
288
169
|
getModelCatalogTarget(provider: Provider): Result<ModelCatalogTarget>;
|
|
289
|
-
appendRemoteConversationDetail(detail: RemoteConversationDetail
|
|
290
|
-
|
|
291
|
-
}): Promise<Result<{
|
|
292
|
-
eventId: string;
|
|
293
|
-
recorded: true;
|
|
294
|
-
}>>;
|
|
295
|
-
getRemoteConversationDetailReceipt(query: {
|
|
296
|
-
eventId: string;
|
|
297
|
-
sessionId: string;
|
|
298
|
-
provider: Provider;
|
|
299
|
-
}): Promise<Result<{
|
|
300
|
-
eventId: string;
|
|
301
|
-
recorded: false;
|
|
302
|
-
} | {
|
|
303
|
-
eventId: string;
|
|
304
|
-
recorded: true;
|
|
305
|
-
detail: RemoteConversationDetail;
|
|
306
|
-
}>>;
|
|
307
|
-
getRemoteConversationDetailState(): RemoteConversationDetailState;
|
|
308
|
-
onRemoteConversationDetailState(listener: (state: RemoteConversationDetailState) => void): () => void;
|
|
309
|
-
listRemoteConversationDetails(query: RemoteDetailQuery): Promise<Result<RemoteDetailPage>>;
|
|
170
|
+
appendRemoteConversationDetail(detail: RemoteConversationDetail): void;
|
|
171
|
+
readConversationLog(): Promise<Result<string>>;
|
|
310
172
|
getContractInfo(): ContractInfo;
|
|
311
173
|
getEnrollmentState(): EnrollmentState;
|
|
312
174
|
onEnrollmentState(listener: (state: EnrollmentState) => void): () => void;
|
|
@@ -314,10 +176,7 @@ export interface ConnectApi {
|
|
|
314
176
|
outcome: 'imported' | 'cancelled';
|
|
315
177
|
state: EnrollmentState;
|
|
316
178
|
}>>;
|
|
317
|
-
|
|
318
|
-
onWorkspaceBindingState(listener: (state: WorkspaceBindingState) => void): () => void;
|
|
319
|
-
acknowledgeWorkspaceNotice(receipt: WorkspaceNoticeReceipt): Promise<Result<void>>;
|
|
320
|
-
resolveSessionProject(sessionId: string, use: WorkspaceUse, location?: HostWorkspaceResolveContext): Promise<Result<SessionProjectTarget | HostSessionProjectTarget>>;
|
|
179
|
+
resolveSessionProject(sessionId: string, use: WorkspaceUse, location: HostWorkspaceResolveContext): Promise<Result<HostSessionProjectTarget>>;
|
|
321
180
|
getConnectionState(): ConnectionState;
|
|
322
181
|
onConnectionState(listener: (state: ConnectionState) => void): () => void;
|
|
323
182
|
getLoginPromptState(): LoginPromptState;
|
|
@@ -325,8 +184,6 @@ export interface ConnectApi {
|
|
|
325
184
|
requestLoginPrompt(provider: Provider, intent: 'automatic' | 'user'): Promise<Result<LoginPromptState>>;
|
|
326
185
|
respondLoginPrompt(requestId: string, action: 'authorize' | 'defer'): Promise<Result<LoginPromptState>>;
|
|
327
186
|
refreshLoginPrompts(): Promise<Result<LoginPromptState>>;
|
|
328
|
-
listProjects(): Promise<Result<ProjectList>>;
|
|
329
|
-
createProject(name: string): Promise<Result<Project>>;
|
|
330
187
|
getState(): ConnectState;
|
|
331
188
|
connect(): Promise<Result<SshTarget>>;
|
|
332
189
|
getSshTarget(): Promise<Result<SshTarget>>;
|
|
@@ -335,3 +192,4 @@ export interface ConnectApi {
|
|
|
335
192
|
ensureReady(provider: Provider): Promise<Result<SshTarget>>;
|
|
336
193
|
dispose(): Promise<void>;
|
|
337
194
|
}
|
|
195
|
+
export type * from './workspace-directory-picker-types.ts';
|
|
@@ -29,6 +29,6 @@ export type ComponentProgressStore = ReturnType<typeof createComponentProgress>;
|
|
|
29
29
|
export declare class ComponentDownloadError extends Error {
|
|
30
30
|
constructor(code: string);
|
|
31
31
|
}
|
|
32
|
-
export declare const componentCertificateMessage = "\
|
|
32
|
+
export declare const componentCertificateMessage = "\u8FDE\u63A5\u88AB\u622A\u83B7\uFF0C\u53EF\u80FD\u8FDE\u4E0D\u4E0A\u4E3B\u673A\u3002";
|
|
33
33
|
export declare const isComponentCertificateFailure: (reason: string) => boolean;
|
|
34
34
|
export declare function downloadComponent(source: string, signal: AbortSignal, maxRedirects: number): Promise<Response>;
|
|
@@ -18,7 +18,7 @@ export class ComponentDownloadError extends Error {
|
|
|
18
18
|
// Node24.13.1 X509表除OUT_OF_MEM(非证书原因)外的验证码,另含Node主机名校验码。
|
|
19
19
|
const certificateCodes = new Set(['UNABLE_TO_GET_ISSUER_CERT', 'UNABLE_TO_GET_CRL', 'UNABLE_TO_DECRYPT_CERT_SIGNATURE', 'UNABLE_TO_DECRYPT_CRL_SIGNATURE', 'UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY', 'CERT_SIGNATURE_FAILURE', 'CRL_SIGNATURE_FAILURE', 'CERT_NOT_YET_VALID', 'CERT_HAS_EXPIRED', 'CRL_NOT_YET_VALID', 'CRL_HAS_EXPIRED', 'ERROR_IN_CERT_NOT_BEFORE_FIELD', 'ERROR_IN_CERT_NOT_AFTER_FIELD', 'ERROR_IN_CRL_LAST_UPDATE_FIELD', 'ERROR_IN_CRL_NEXT_UPDATE_FIELD', 'DEPTH_ZERO_SELF_SIGNED_CERT', 'SELF_SIGNED_CERT_IN_CHAIN', 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY', 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', 'CERT_CHAIN_TOO_LONG', 'CERT_REVOKED', 'INVALID_CA', 'PATH_LENGTH_EXCEEDED', 'INVALID_PURPOSE', 'CERT_UNTRUSTED', 'CERT_REJECTED', 'HOSTNAME_MISMATCH', 'ERR_TLS_CERT_ALTNAME_INVALID']);
|
|
20
20
|
const tlsPrefix = 'COMPONENT_DOWNLOAD_TLS_';
|
|
21
|
-
export const componentCertificateMessage = '
|
|
21
|
+
export const componentCertificateMessage = '连接被截获,可能连不上主机。';
|
|
22
22
|
export const isComponentCertificateFailure = (reason) => reason.startsWith(tlsPrefix) && certificateCodes.has(reason.slice(tlsPrefix.length));
|
|
23
23
|
function downloadError(error, signal, fallback) {
|
|
24
24
|
const code = typeof error === 'object' && error !== null ? error.code : undefined;
|
|
@@ -1,52 +1,31 @@
|
|
|
1
1
|
export declare const COMPONENT_SOURCES: Readonly<{
|
|
2
|
-
github: {
|
|
3
|
-
label: string;
|
|
4
|
-
source: "https://github.com/electron/electron/releases/download/v44.0.0/electron-v44.0.0-darwin-arm64.zip";
|
|
5
|
-
};
|
|
6
2
|
npmmirror: {
|
|
7
3
|
label: string;
|
|
8
4
|
source: string;
|
|
9
5
|
};
|
|
10
6
|
}>;
|
|
11
|
-
export
|
|
12
|
-
export declare
|
|
13
|
-
export declare const preset: (id: unknown) => id is ComponentSourceId;
|
|
14
|
-
interface Options {
|
|
15
|
-
profileDir?: string;
|
|
16
|
-
metadataMaxBytes: number;
|
|
17
|
-
source?: string;
|
|
7
|
+
export declare const DEFAULT_SOURCE_REASON = "\u767B\u5F55\u7EC4\u4EF6\u56FA\u5B9A\u4ECE npmmirror \u4E0B\u8F7D\u3002";
|
|
8
|
+
export declare function createComponentSources(options: {
|
|
18
9
|
sha256?: string;
|
|
19
|
-
|
|
20
|
-
busy: () => boolean;
|
|
21
|
-
}
|
|
22
|
-
export declare function createComponentSources(options: Options): {
|
|
10
|
+
}): {
|
|
23
11
|
ready: Promise<void>;
|
|
24
12
|
getState: () => {
|
|
25
|
-
changing: boolean;
|
|
26
13
|
instanceId: `${string}-${string}-${string}-${string}-${string}`;
|
|
27
14
|
revision: number;
|
|
28
|
-
phase:
|
|
15
|
+
phase: string;
|
|
29
16
|
selectedId: string;
|
|
30
17
|
selectedLabel: string;
|
|
31
18
|
reason: string;
|
|
32
19
|
version: string;
|
|
33
20
|
sha256: string | null;
|
|
34
|
-
errorCode: string | null;
|
|
35
|
-
selectionErrorCode: string | null;
|
|
36
|
-
choices: {
|
|
37
|
-
id: string;
|
|
38
|
-
label: string;
|
|
39
|
-
}[];
|
|
40
21
|
};
|
|
41
|
-
onState(
|
|
42
|
-
resolve
|
|
22
|
+
onState(_fn: () => void): () => void;
|
|
23
|
+
resolve(): Promise<{
|
|
43
24
|
source: string;
|
|
44
25
|
id: string;
|
|
45
26
|
label: string;
|
|
46
27
|
reason: string;
|
|
47
28
|
}>;
|
|
48
|
-
select: (id: unknown) => Promise<void>;
|
|
49
29
|
dispose(): Promise<void>;
|
|
50
30
|
};
|
|
51
31
|
export type ComponentSources = ReturnType<typeof createComponentSources>;
|
|
52
|
-
export {};
|
package/lib/component-source.js
CHANGED
|
@@ -1,146 +1,18 @@
|
|
|
1
|
-
import { join, isAbsolute, resolve } from 'node:path';
|
|
2
|
-
import { lstat, realpath, open, rename, rm } from 'node:fs/promises';
|
|
3
1
|
import { randomUUID } from 'node:crypto';
|
|
4
|
-
import { privateDirectory, readPrivate } from "./private-files.js";
|
|
5
2
|
import { ELECTRON_PIN } from "./defaults.js";
|
|
6
3
|
import { ComponentDownloadError } from "./component-download.js";
|
|
7
4
|
export const COMPONENT_SOURCES = Object.freeze({
|
|
8
|
-
|
|
9
|
-
npmmirror: { label: 'npmmirror 镜像(Electron 官方文档列出)', source: 'https://npmmirror.com/mirrors/electron/44.0.0/electron-v44.0.0-darwin-arm64.zip' },
|
|
5
|
+
npmmirror: { label: 'npmmirror', source: 'https://npmmirror.com/mirrors/electron/44.0.0/electron-v44.0.0-darwin-arm64.zip' },
|
|
10
6
|
});
|
|
11
|
-
export const DEFAULT_SOURCE_REASON = '
|
|
12
|
-
export const preset = (id) => typeof id === 'string' && Object.hasOwn(COMPONENT_SOURCES, id);
|
|
7
|
+
export const DEFAULT_SOURCE_REASON = '登录组件固定从 npmmirror 下载。';
|
|
13
8
|
export function createComponentSources(options) {
|
|
14
|
-
let
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const listeners = new Set();
|
|
18
|
-
const pending = new Set();
|
|
19
|
-
function error(code) { throw new ComponentDownloadError(code); }
|
|
20
|
-
const notify = () => { if (!disposed) {
|
|
21
|
-
state = { ...state, revision: state.revision + 1 };
|
|
22
|
-
for (const fn of listeners)
|
|
23
|
-
fn();
|
|
24
|
-
} };
|
|
25
|
-
const blocked = (code) => { state = { ...state, phase: 'blocked', errorCode: code }; notify(); };
|
|
26
|
-
const directory = options.profileDir ? join(options.profileDir, 'ai-workbench-connect') : undefined;
|
|
27
|
-
const file = directory ? join(directory, 'component-source.json') : undefined;
|
|
28
|
-
const checkPin = () => { if (options.sha256 !== ELECTRON_PIN.sha256)
|
|
29
|
-
error('COMPONENT_PIN_MISMATCH'); };
|
|
30
|
-
async function canonical() { if (!options.profileDir || !directory || !isAbsolute(options.profileDir) || await realpath(options.profileDir) !== resolve(options.profileDir))
|
|
31
|
-
error('COMPONENT_SOURCE_PROFILE_REQUIRED'); await privateDirectory(directory); if (await realpath(directory) !== resolve(directory))
|
|
32
|
-
error('COMPONENT_SOURCE_STATE_INVALID'); }
|
|
33
|
-
const ready = (async () => {
|
|
34
|
-
try {
|
|
35
|
-
if (!file)
|
|
36
|
-
error('COMPONENT_SOURCE_PROFILE_REQUIRED');
|
|
37
|
-
if (!source)
|
|
38
|
-
error('COMPONENT_SOURCE_INVALID');
|
|
39
|
-
const initialUrl = new URL(source);
|
|
40
|
-
if (initialUrl.protocol !== 'https:' || initialUrl.username || initialUrl.password)
|
|
41
|
-
error('COMPONENT_SOURCE_INVALID');
|
|
42
|
-
await canonical();
|
|
43
|
-
try {
|
|
44
|
-
const stat = await lstat(file);
|
|
45
|
-
if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1)
|
|
46
|
-
error('COMPONENT_SOURCE_STATE_INVALID');
|
|
47
|
-
const saved = JSON.parse(await readPrivate(file, options.metadataMaxBytes));
|
|
48
|
-
if (saved.schemaVersion !== 1 || !preset(saved.sourceId))
|
|
49
|
-
error('COMPONENT_SOURCE_STATE_INVALID');
|
|
50
|
-
const savedId = saved.sourceId;
|
|
51
|
-
selected = savedId;
|
|
52
|
-
source = COMPONENT_SOURCES[savedId].source;
|
|
53
|
-
state = { ...state, selectedId: savedId, selectedLabel: COMPONENT_SOURCES[savedId].label, reason: '沿用你在本设置节保存的下载源;未自动切源。' };
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
if (e.code !== 'ENOENT')
|
|
57
|
-
throw e;
|
|
58
|
-
}
|
|
59
|
-
if (!source)
|
|
60
|
-
error('COMPONENT_SOURCE_INVALID');
|
|
61
|
-
const url = new URL(source);
|
|
62
|
-
if (url.protocol !== 'https:' || url.username || url.password)
|
|
63
|
-
error('COMPONENT_SOURCE_INVALID');
|
|
64
|
-
state = { ...state, phase: 'ready' };
|
|
65
|
-
notify();
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
blocked(e instanceof ComponentDownloadError ? e.message : 'COMPONENT_SOURCE_STATE_INVALID');
|
|
69
|
-
}
|
|
70
|
-
})();
|
|
71
|
-
async function resolveSource() { await ready; if (disposed)
|
|
72
|
-
error('COMPONENT_SOURCE_DISPOSED'); if (state.phase === 'blocked')
|
|
73
|
-
error(state.errorCode); if (changing)
|
|
74
|
-
error('COMPONENT_SOURCE_BUSY'); if (selected)
|
|
75
|
-
checkPin(); return { source: source, id: state.selectedId, label: state.selectedLabel, reason: state.reason }; }
|
|
76
|
-
function select(id) {
|
|
77
|
-
const task = (async () => {
|
|
78
|
-
if (!preset(id))
|
|
79
|
-
error('COMPONENT_SOURCE_INVALID');
|
|
9
|
+
let disposed = false;
|
|
10
|
+
const state = { instanceId: randomUUID(), revision: 0, phase: 'ready', selectedId: 'npmmirror', selectedLabel: COMPONENT_SOURCES.npmmirror.label, reason: DEFAULT_SOURCE_REASON, version: '44.0.0', sha256: options.sha256 ?? null };
|
|
11
|
+
return { ready: Promise.resolve(), getState: () => structuredClone(state), onState(_fn) { return () => { }; }, async resolve() {
|
|
80
12
|
if (disposed)
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
let temp;
|
|
87
|
-
try {
|
|
88
|
-
await ready;
|
|
89
|
-
if (disposed)
|
|
90
|
-
error('COMPONENT_SOURCE_DISPOSED');
|
|
91
|
-
if (state.phase === 'blocked')
|
|
92
|
-
error(state.errorCode);
|
|
93
|
-
if (options.busy())
|
|
94
|
-
error('COMPONENT_SOURCE_BUSY');
|
|
95
|
-
checkPin();
|
|
96
|
-
await canonical();
|
|
97
|
-
const data = JSON.stringify({ schemaVersion: 1, sourceId: id });
|
|
98
|
-
if (!Number.isSafeInteger(options.metadataMaxBytes) || Buffer.byteLength(data) > options.metadataMaxBytes)
|
|
99
|
-
error('COMPONENT_SOURCE_STATE_INVALID');
|
|
100
|
-
temp = join(directory, '.component-source-' + randomUUID());
|
|
101
|
-
const handle = await open(temp, 'wx', 0o600);
|
|
102
|
-
try {
|
|
103
|
-
await handle.writeFile(data);
|
|
104
|
-
await handle.sync();
|
|
105
|
-
}
|
|
106
|
-
finally {
|
|
107
|
-
await handle.close();
|
|
108
|
-
}
|
|
109
|
-
if (disposed)
|
|
110
|
-
error('COMPONENT_SOURCE_DISPOSED');
|
|
111
|
-
if (options.busy())
|
|
112
|
-
error('COMPONENT_SOURCE_BUSY');
|
|
113
|
-
await rename(temp, file);
|
|
114
|
-
temp = undefined;
|
|
115
|
-
const parent = await open(directory, 'r');
|
|
116
|
-
try {
|
|
117
|
-
await parent.sync();
|
|
118
|
-
}
|
|
119
|
-
finally {
|
|
120
|
-
await parent.close();
|
|
121
|
-
}
|
|
122
|
-
selected = id;
|
|
123
|
-
source = COMPONENT_SOURCES[id].source;
|
|
124
|
-
state = { ...state, selectedId: id, selectedLabel: COMPONENT_SOURCES[id].label, reason: '你在本设置节显式选择并保存了此下载源;未自动切源。', errorCode: null, selectionErrorCode: null };
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
if (!(e instanceof ComponentDownloadError)) {
|
|
128
|
-
blocked('COMPONENT_SOURCE_STATE_INVALID');
|
|
129
|
-
error('COMPONENT_SOURCE_STATE_INVALID');
|
|
130
|
-
}
|
|
131
|
-
state = { ...state, selectionErrorCode: e.message };
|
|
132
|
-
throw e;
|
|
133
|
-
}
|
|
134
|
-
finally {
|
|
135
|
-
if (temp)
|
|
136
|
-
await rm(temp, { force: true });
|
|
137
|
-
changing = false;
|
|
138
|
-
notify();
|
|
139
|
-
}
|
|
140
|
-
})();
|
|
141
|
-
pending.add(task);
|
|
142
|
-
void task.then(() => pending.delete(task), () => pending.delete(task));
|
|
143
|
-
return task;
|
|
144
|
-
}
|
|
145
|
-
return { ready, getState: () => structuredClone({ ...state, changing }), onState(fn) { listeners.add(fn); return () => { listeners.delete(fn); }; }, resolve: resolveSource, select, async dispose() { disposed = true; listeners.clear(); await ready; await Promise.allSettled([...pending]); } };
|
|
13
|
+
throw new ComponentDownloadError('COMPONENT_SOURCE_DISPOSED');
|
|
14
|
+
if (options.sha256 !== ELECTRON_PIN.sha256)
|
|
15
|
+
throw new ComponentDownloadError('COMPONENT_PIN_MISMATCH');
|
|
16
|
+
return { source: COMPONENT_SOURCES.npmmirror.source, id: state.selectedId, label: state.selectedLabel, reason: state.reason };
|
|
17
|
+
}, async dispose() { disposed = true; } };
|
|
146
18
|
}
|
package/lib/components.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export interface ComponentInventory {
|
|
|
7
7
|
claude: string;
|
|
8
8
|
codex?: string;
|
|
9
9
|
}
|
|
10
|
-
export declare function registerComponents(ctx: Context, inventory?: ComponentInventory, temporaryDataParent?: string, component?: ComponentProgressStore, sources?: ComponentSources, observationIntervalMs?: number, metadataMaxBytes?: number
|
|
10
|
+
export declare function registerComponents(ctx: Context, inventory?: ComponentInventory, temporaryDataParent?: string, component?: ComponentProgressStore, sources?: ComponentSources, observationIntervalMs?: number, metadataMaxBytes?: number): void;
|