@sparkelf/dsh-dataops-managed 0.3.50 → 0.3.52

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.
@@ -0,0 +1,349 @@
1
+ /**
2
+ * The DataOps browser bridge session: one MCP connection, many short-lived control tokens.
3
+ *
4
+ * A workspace reaches the user's local companion only through the DataOps gateway. The plugin
5
+ * therefore asks DataOps for a session with the current user JWT, and the answer carries an
6
+ * `mcpUrl` whose ticket is the connection capability plus a short-lived `bridgeToken` for the
7
+ * control plane. The MCP client is created once from that URL; token expiry is refreshed in
8
+ * memory, and only session closure (logout, device revoke, explicit close) releases the
9
+ * connection.
10
+ *
11
+ * This module owns that lifecycle so `apply` only supplies callbacks. It never reads a bridge
12
+ * address from the profile or the environment: the session API is the only production entry.
13
+ *
14
+ * @module browser-bridge-session
15
+ */
16
+ /** Control-plane request timeout. A container network can be slow, but not unbounded. */
17
+ export declare const REQUEST_TIMEOUT_MS = 15000;
18
+ /**
19
+ * Close is best-effort on the shutdown path, so it gets a shorter budget than a request whose
20
+ * answer the user is waiting for. A session left open is cleaned up by the gateway; a plugin
21
+ * disposal that hangs is visible immediately.
22
+ */
23
+ export declare const CLOSE_TIMEOUT_MS = 3000;
24
+ /** Retry delay after the companion is offline or a control-plane call failed. */
25
+ export declare const RETRY_DELAY_MS = 60000;
26
+ /** How often an expiring `bridgeToken` is checked. */
27
+ export declare const REFRESH_INTERVAL_MS = 60000;
28
+ /** Refresh ahead of expiry: a token with less than this left is rotated. */
29
+ export declare const REFRESH_AHEAD_MS: number;
30
+ /** How often the gateway is asked whether the session is still active. */
31
+ export declare const STATUS_INTERVAL_MS = 30000;
32
+ /** Where the bridge currently stands, as the connector row reports it. */
33
+ export type BrowserBridgePhase = 'disabled' | 'idle' | 'connecting' | 'connected' | 'offline' | 'expired' | 'closed' | 'error';
34
+ /** The session the gateway handed out; `expiresAt` covers `bridgeToken`, not the MCP ticket. */
35
+ export interface BrowserBridgeSessionInfo {
36
+ sessionId: string;
37
+ deviceId: string;
38
+ /** Ticket-bearing endpoint the MCP client connects to once. */
39
+ mcpUrl: string;
40
+ /** Short-lived control-plane credential; rotated without touching the MCP connection. */
41
+ bridgeToken: string;
42
+ /** Epoch milliseconds at which `bridgeToken` expires. */
43
+ expiresAt: number;
44
+ /**
45
+ * Which gateway process holds this session's MCP tunnel.
46
+ *
47
+ * A new value means DataOps restarted: the local MCP `session-id` from the previous process
48
+ * is gone, so the plugin must rebuild its MCP client. Token refresh never changes it.
49
+ * Omitted by older backends, in which case restart detection stays off.
50
+ */
51
+ gatewayInstanceId?: string;
52
+ /**
53
+ * The device-side tunnel generation; Companion increments it on every reconnect.
54
+ *
55
+ * A change means the companion's local MCP may have restarted, so the client must be rebuilt
56
+ * as well. Omitted by older backends.
57
+ */
58
+ tunnelGeneration?: number;
59
+ }
60
+ /** One live MCP client this session owns. */
61
+ export interface BrowserBridgeMcpHandle {
62
+ /** Whether the underlying plugin fiber is still loaded. */
63
+ alive(): boolean;
64
+ /** Disconnect and unregister the `browser-bridge` tool namespace. */
65
+ dispose(): Promise<void>;
66
+ }
67
+ /** What the connector catalogue can show about the live bridge. */
68
+ export interface BrowserBridgeStatus {
69
+ phase: BrowserBridgePhase;
70
+ /** The connector switch was on when this status was produced. */
71
+ enabled: boolean;
72
+ /** MCP fiber alive and the gateway reports the session active. */
73
+ connected: boolean;
74
+ sessionId?: string;
75
+ deviceId?: string;
76
+ /** ISO timestamp for the current `bridgeToken`; informational only. */
77
+ expiresAt?: string;
78
+ /** Product-language hint for the connector row, without tokens or URLs. */
79
+ detail?: string;
80
+ }
81
+ /** The narrow logger this module needs; it never receives a URL or a token. */
82
+ export interface BrowserBridgeLogger {
83
+ warn(message: string): void;
84
+ }
85
+ /** Everything the session needs from the host, so the state machine is testable on its own. */
86
+ export interface BrowserBridgeSessionDeps {
87
+ /** DataOps origin, already reduced to its origin by the caller. */
88
+ baseUrl: string;
89
+ /** Read the current DataOps JWT; resolution is per call, never cached. */
90
+ resolveToken(): Promise<string | undefined>;
91
+ /** Read the persisted connector switch. */
92
+ isEnabled(): Promise<boolean>;
93
+ /** Create the one MCP client for this session; reject when the connection fails. */
94
+ connectMcp(mcpUrl: string, bridgeToken: string): Promise<BrowserBridgeMcpHandle>;
95
+ logger: BrowserBridgeLogger;
96
+ /** Injectable clock, so expiry decisions are testable. */
97
+ now?: () => number;
98
+ /** Injectable fetch, so control-plane traffic is testable. */
99
+ fetch?: typeof fetch;
100
+ }
101
+ /** Parsed answer to `POST /session`. */
102
+ export type SessionAnswer = {
103
+ kind: 'active';
104
+ session: BrowserBridgeSessionInfo;
105
+ } | {
106
+ kind: 'offline';
107
+ } | {
108
+ kind: 'unauthorized';
109
+ } | {
110
+ kind: 'closed';
111
+ } | {
112
+ kind: 'error';
113
+ message: string;
114
+ };
115
+ /** Parsed answer to `POST /session/:id/refresh`. */
116
+ export type RefreshAnswer = {
117
+ kind: 'refreshed';
118
+ bridgeToken: string;
119
+ expiresAt: number;
120
+ } | {
121
+ kind: 'unauthorized';
122
+ } | {
123
+ kind: 'closed';
124
+ } | {
125
+ kind: 'error';
126
+ message: string;
127
+ };
128
+ /** Parsed answer to `GET /session/:id`. */
129
+ export type StatusAnswer = {
130
+ kind: 'active';
131
+ gatewayInstanceId?: string;
132
+ tunnelGeneration?: number;
133
+ deviceOnline?: boolean;
134
+ } | {
135
+ kind: 'closed';
136
+ } | {
137
+ kind: 'unauthorized';
138
+ } | {
139
+ kind: 'error';
140
+ message: string;
141
+ };
142
+ /**
143
+ * Whether a control token is close enough to expiry to rotate.
144
+ * @param expiresAt - Epoch milliseconds from the session answer.
145
+ * @param now - Current epoch milliseconds.
146
+ * @returns True when less than {@link REFRESH_AHEAD_MS} remains.
147
+ */
148
+ export declare function expiresSoon(expiresAt: number, now: number): boolean;
149
+ /**
150
+ * Drop the query from an MCP URL before it can reach a log line.
151
+ *
152
+ * The `mcpUrl` carries the session ticket in its query string, so it is a credential and must
153
+ * never be printed whole. The origin and path are enough to correlate a log entry.
154
+ * @param url - Any URL, possibly already stripped of its query.
155
+ * @returns Origin plus path, or a fixed marker when the value is not a URL.
156
+ */
157
+ export declare function redactMcpUrl(url: string): string;
158
+ /**
159
+ * Replace every URL in a diagnostic with its redacted form.
160
+ *
161
+ * MCP client failures often embed the endpoint they tried, and that endpoint carries a ticket.
162
+ * Diagnostics pass through here so a log line cannot leak it.
163
+ * @param text - Diagnostic text.
164
+ * @returns The same text with each absolute URL reduced to origin plus path.
165
+ */
166
+ export declare function redactUrls(text: string): string;
167
+ /**
168
+ * Describe one thrown value without assuming it is an Error and without echoing a URL.
169
+ * @param error - The value a failed call rejected with.
170
+ * @returns A single-line diagnostic safe to log.
171
+ */
172
+ export declare function describeError(error: unknown): string;
173
+ /** The pair that identifies the live gateway tunnel behind a session. */
174
+ export interface BrowserBridgeTunnelIdentity {
175
+ gatewayInstanceId?: string;
176
+ tunnelGeneration?: number;
177
+ }
178
+ /**
179
+ * Whether the gateway or the companion that serves this session changed.
180
+ *
181
+ * Only components present on both sides are compared: an older backend that omits a field
182
+ * cannot produce a false rebuild, and a value that appears for the first time is adopted
183
+ * without a rebuild.
184
+ * @param previous - Identity recorded from the session create answer.
185
+ * @param next - Identity read from a status poll.
186
+ * @returns True when any comparable component differs.
187
+ */
188
+ export declare function tunnelIdentityChanged(previous: BrowserBridgeTunnelIdentity, next: BrowserBridgeTunnelIdentity): boolean;
189
+ /**
190
+ * Carry forward identity components the new answer did not repeat.
191
+ *
192
+ * A field that appears later is recorded so the *next* change is observable, without treating
193
+ * its first appearance as a change.
194
+ * @param previous - Recorded identity, when there is one.
195
+ * @param next - Identity read from the session or status answer.
196
+ * @returns The identity to remember.
197
+ */
198
+ export declare function mergeTunnelIdentity(previous: BrowserBridgeTunnelIdentity | undefined, next: BrowserBridgeTunnelIdentity): BrowserBridgeTunnelIdentity;
199
+ /**
200
+ * Classify `POST /session`.
201
+ * @param status - HTTP status.
202
+ * @param body - Parsed JSON body, if any.
203
+ * @returns The answer the session state machine acts on.
204
+ */
205
+ export declare function parseSessionAnswer(status: number, body: unknown): SessionAnswer;
206
+ /**
207
+ * Classify `POST /session/:id/refresh`.
208
+ * @param status - HTTP status.
209
+ * @param body - Parsed JSON body, if any.
210
+ * @returns The answer the session state machine acts on.
211
+ */
212
+ export declare function parseRefreshAnswer(status: number, body: unknown): RefreshAnswer;
213
+ /**
214
+ * Classify `GET /session/:id`.
215
+ * @param status - HTTP status.
216
+ * @param body - Parsed JSON body, if any.
217
+ * @returns The answer the session state machine acts on.
218
+ */
219
+ export declare function parseStatusAnswer(status: number, body: unknown): StatusAnswer;
220
+ /**
221
+ * The long-lived browser bridge connection for one workspace.
222
+ *
223
+ * Lifecycle:
224
+ * 1. `start` reads the persisted connector switch; off means no call at all.
225
+ * 2. `POST /session` with the current JWT. 200 opens the one MCP client, 409
226
+ * `COMPANION_OFFLINE` retries in a minute, 401 records the expired credential and waits for
227
+ * the next login.
228
+ * 3. Every minute the control token is rotated in memory when it is close to expiry. The MCP
229
+ * client is never recreated for a token refresh.
230
+ * 4. Every thirty seconds the gateway is asked whether the session is still active. `closed`
231
+ * is the one server state that disposes the MCP client.
232
+ * 5. `dispose` closes the session best-effort and clears every timer.
233
+ */
234
+ export declare class BrowserBridgeSession {
235
+ private readonly deps;
236
+ private enabled;
237
+ private phase;
238
+ private session;
239
+ private mcp;
240
+ /** The saved `mcpUrl` may have been rotated away; the next attempt reopens the session. */
241
+ private ticketStale;
242
+ /** The gateway/companion pair the current MCP client was initialized against. */
243
+ private tunnelIdentity;
244
+ private detail;
245
+ private refreshTimer;
246
+ private statusTimer;
247
+ private connectPollTimer;
248
+ private retryTimer;
249
+ private ensuring;
250
+ private refreshing;
251
+ private checking;
252
+ private disposed;
253
+ private readonly fetchImpl;
254
+ private readonly now;
255
+ constructor(deps: BrowserBridgeSessionDeps);
256
+ /**
257
+ * Read the connector switch and connect when it is on.
258
+ *
259
+ * Called once from plugin activation. It is fire-and-forget from `apply`'s point of view: an
260
+ * offline companion is a normal state, not an activation failure.
261
+ * @returns Readiness after the first attempt settles.
262
+ */
263
+ start(): Promise<void>;
264
+ /**
265
+ * Apply a connector toggle without a restart.
266
+ *
267
+ * Enabling opens a session now; disabling closes the one this workspace holds so the tool
268
+ * namespace goes away with the switch. The caller does not await the network attempt.
269
+ * @param enabled - New persisted connector state.
270
+ */
271
+ setEnabled(enabled: boolean): Promise<void>;
272
+ /**
273
+ * React to a newly stored DataOps JWT.
274
+ *
275
+ * A 401 pauses the session without disposing the MCP connection, because the ticket in
276
+ * `mcpUrl` outlives the JWT. The next login is what lets the control plane resume; if no
277
+ * session exists yet, it is also the moment to open one.
278
+ * @returns Readiness after any resumed or new work settles.
279
+ */
280
+ onCredentialRefresh(): Promise<void>;
281
+ /**
282
+ * The live status the connector catalogue renders.
283
+ * @returns Phase, connection truth, and a token-free hint.
284
+ */
285
+ status(): BrowserBridgeStatus;
286
+ /**
287
+ * Close the session best-effort, dispose the MCP client, and clear every timer.
288
+ *
289
+ * Called from the plugin's effect disposer. A failed close is ignored: the gateway prunes
290
+ * stale sessions, and shutdown must not wait on a control-plane call.
291
+ * @returns Readiness after cleanup settles.
292
+ */
293
+ dispose(): Promise<void>;
294
+ /** Serialize connection attempts; a retry, a toggle, and a new JWT must not race. */
295
+ private ensure;
296
+ /** One connection attempt: reuse the session when one exists, otherwise open one. */
297
+ private ensureNow;
298
+ /** Ask the gateway for a session, then connect the MCP client it names. */
299
+ private openSession;
300
+ /** Create the one MCP client for the current session; failure reopens for a fresh ticket. */
301
+ private connectMcp;
302
+ /** Rotate the control token in memory when it is close to expiry. Never touches the MCP. */
303
+ private checkRefresh;
304
+ /**
305
+ * Rebuild the MCP client after the gateway restarted or the companion reconnected.
306
+ *
307
+ * Both events invalidate the local MCP `session-id` held by the client, and the client does
308
+ * not re-initialize on its own. Disposing it and asking the gateway for a session again is
309
+ * the recovery; the returned ticket is current even when the gateway reuses the row.
310
+ * @param previous - Identity the current client was initialized against.
311
+ * @param next - Identity read from the status poll.
312
+ * @returns Readiness after the rebuild attempt settles.
313
+ */
314
+ private reconnectForTunnelChange;
315
+ /** Ask the gateway whether the session is still active; `closed` releases the MCP client. */
316
+ private checkStatus;
317
+ /** Start the refresh and status clocks; idempotent so a resumed session cannot double them. */
318
+ /**
319
+ * 连接探测时钟:未连接时每 30 秒问一次网关「有在线设备/有人请求连接吗」。
320
+ *
321
+ * 这条路径不依赖已有 session:设备撤销、重新配对、Gateway 重启后插件都能自己恢复,
322
+ * 不需要重启 DSH;已有健康会话时什么都不做,避免无谓请求。
323
+ */
324
+ private startConnectPoll;
325
+ private stopConnectPoll;
326
+ /** 没有健康会话时读取网关连接摘要;有在线设备或 connectRequested 就重新建会话。 */
327
+ private checkConnectionOffer;
328
+ private startSchedule;
329
+ /** Stop both clocks; a paused session resumes them after the next JWT. */
330
+ private stopSchedule;
331
+ /** Ask for one retry after {@link RETRY_DELAY_MS}; only while the connector is on. */
332
+ private scheduleRetry;
333
+ /** Cancel a pending retry, including on the success path. */
334
+ private clearRetry;
335
+ /** Stop every clock this session owns. */
336
+ private stopTimers;
337
+ /** Close the current session: best-effort remote close, then local disposal. */
338
+ private closeSession;
339
+ /** Release an MCP client and state the server already closed; no close call needed. */
340
+ private dropLocal;
341
+ /** Best-effort `POST /session/:id/close`; every failure is ignored by design. */
342
+ private closeRemote;
343
+ /** Resolve the current JWT, tolerating a host that is already tearing down. */
344
+ private token;
345
+ /** Absolute control-plane URL below the DataOps origin. */
346
+ private endpoint;
347
+ /** Log one sanitized diagnostic. */
348
+ private warn;
349
+ }
@@ -16,14 +16,4 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
16
16
  }
17
17
  /** Required client services for the managed DataOps Settings section and the resource tab bridge. */
18
18
  export declare const inject: string[];
19
- /**
20
- * Register the managed DataOps surfaces and the sign-in prompt.
21
- *
22
- * The prompt rides a sidebar seat because the client needs *some* always-mounted surface for a
23
- * dialog that is about the whole workspace rather than one panel. The seat is a container: the
24
- * dialog itself portals to `document.body`, so this contributes no visible element to the
25
- * sidebar at rest and cannot disturb the regions that already live there.
26
- *
27
- * @param ctx - DSH client context with locale, slots and the sidebar foot.
28
- */
29
19
  export declare function apply(ctx: ClientContext): void;
@@ -1,6 +1,6 @@
1
1
  /** Same-origin model-sync calls from the DataOps settings surface. */
2
2
  /** Route the plugin's Host half serves for model sharing. */
3
- export declare const MODEL_SYNC_PATH = "/integrations/dataops/model-sync";
3
+ export declare const MODEL_SYNC_PATH = "integrations/dataops/model-sync";
4
4
  /** One model this workspace holds, and whether it is offered to other users. */
5
5
  export interface ModelSyncModel {
6
6
  /** Model id as the settings document stores it. */
@@ -7,17 +7,17 @@
7
7
  */
8
8
  import type { ReviewContext, ReviewNotification, RiskReport, ReviewStatus, ResourceVisibility } from './review-types.ts';
9
9
  /** Caller identity and review capability. */
10
- export declare const REVIEW_CONTEXT_PATH = "/integrations/dataops/review-context";
10
+ export declare const REVIEW_CONTEXT_PATH = "integrations/dataops/review-context";
11
11
  /** Notification list and read receipts. */
12
- export declare const NOTIFICATIONS_PATH = "/integrations/dataops/review-notifications";
12
+ export declare const NOTIFICATIONS_PATH = "integrations/dataops/review-notifications";
13
13
  /** AI scan and the human decision. */
14
- export declare const REVIEW_ACTION_PATH = "/integrations/dataops/review";
14
+ export declare const REVIEW_ACTION_PATH = "integrations/dataops/review";
15
15
  /** Role matrix, members, departments, and resource scopes. */
16
- export declare const RBAC_PATH = "/integrations/dataops/rbac";
16
+ export declare const RBAC_PATH = "integrations/dataops/rbac";
17
17
  /** The three plaza-review switches in the DataOps settings panel. */
18
- export declare const REVIEW_SETTINGS_PATH = "/integrations/dataops/review-settings";
18
+ export declare const REVIEW_SETTINGS_PATH = "integrations/dataops/review-settings";
19
19
  /** Department CRUD bridge (task-67). */
20
- export declare const DEPARTMENTS_PATH = "/integrations/dataops/departments";
20
+ export declare const DEPARTMENTS_PATH = "integrations/dataops/departments";
21
21
  /** One permission point in the role matrix. */
22
22
  export interface PermissionPoint {
23
23
  key: string;
@@ -1,7 +1,7 @@
1
1
  /** Same-origin skill plaza calls from the DataOps skill center section. */
2
2
  import type { ReviewStatus, ResourceVisibility } from './review-types.ts';
3
3
  /** Route the plugin's Host half serves for the plaza. */
4
- export declare const SKILL_PLAZA_PATH = "/integrations/dataops/skill-plaza";
4
+ export declare const SKILL_PLAZA_PATH = "integrations/dataops/skill-plaza";
5
5
  /** One plaza entry as the section reads it. */
6
6
  export interface PlazaSkill {
7
7
  id: number;
@@ -1,6 +1,6 @@
1
1
  /** Same-origin tool-call timeout calls from the DataOps settings surface. */
2
2
  /** Route the plugin's Host half serves for the tool-call timeout. */
3
- export declare const TOOL_TIMEOUT_PATH = "/integrations/dataops/tool-timeout";
3
+ export declare const TOOL_TIMEOUT_PATH = "integrations/dataops/tool-timeout";
4
4
  /** The two ends a timeout may take, in seconds, matching what the Host enforces. */
5
5
  export declare const TOOL_TIMEOUT_MIN_SECONDS = 1;
6
6
  export declare const TOOL_TIMEOUT_MAX_SECONDS = 3600;
@@ -1,6 +1,6 @@
1
1
  /** Same-origin workspace-limits calls from the DataOps settings surface. */
2
2
  /** Route the plugin's Host half serves for workspace limits. */
3
- export declare const WORKSPACE_LIMITS_PATH = "/integrations/dataops/workspace-limits";
3
+ export declare const WORKSPACE_LIMITS_PATH = "integrations/dataops/workspace-limits";
4
4
  /** The two byte ceilings, as the panel edits them. */
5
5
  export interface WorkspaceLimits {
6
6
  /** Largest file a sidebar download or agent read may carry. */
@@ -1,6 +1,6 @@
1
1
  /** Same-origin calls for the workspace image upgrade banner. */
2
2
  /** Route the plugin's Host half serves for upgrade detection and start. */
3
- export declare const WORKSPACE_UPGRADE_PATH = "/integrations/dataops/workspace-upgrade";
3
+ export declare const WORKSPACE_UPGRADE_PATH = "integrations/dataops/workspace-upgrade";
4
4
  /** A DSH session that will receive "继续" after the restart. */
5
5
  export interface WorkspaceUpgradeSession {
6
6
  sessionId: string;
@@ -10,11 +10,22 @@
10
10
  *
11
11
  * @module connector-state
12
12
  */
13
+ import type { BrowserBridgeStatus } from './browser-bridge-session.ts';
13
14
  import { type DataOpsScope } from './tool-scope.ts';
14
15
  /** Same-origin route the skill center's connector tab reads and writes. */
15
16
  export declare const CONNECTORS_PATH = "/api/dsh-skill-center/connectors";
16
17
  /** Connector id shown in the skill center. */
17
18
  export declare const DATAOPS_CONNECTOR_ID = "dataops-managed";
19
+ /** Connector id for the local browser bridge companion. */
20
+ export declare const BROWSER_BRIDGE_CONNECTOR_ID = "browser-bridge";
21
+ /** Same-origin route that serves the bridge installer file. */
22
+ export declare const BROWSER_BRIDGE_INSTALLER_PATH = "/api/dsh-skill-center/browser-bridge/installer";
23
+ /** Persisted enable state for the browser bridge connector. */
24
+ export interface BrowserBridgeConnectorState {
25
+ enabled: boolean;
26
+ }
27
+ /** State file for the browser bridge connector, beside the DataOps connector state. */
28
+ export declare const BROWSER_BRIDGE_STATE_PATH: string;
18
29
  /** Persisted enable state; a missing file means the connector is off. */
19
30
  export interface DataOpsConnectorState {
20
31
  enabled: boolean;
@@ -30,6 +41,14 @@ export interface ConnectorCapabilityView {
30
41
  unavailableReason?: string;
31
42
  }
32
43
  /** One connector row the skill center renders. */
44
+ export interface ConnectorInstallerView {
45
+ /** File name the browser saves the installer as. */
46
+ fileName: string;
47
+ /** Same-origin URL that streams the installer. */
48
+ downloadUrl: string;
49
+ /** Product-language explanation shown in the confirmation dialog. */
50
+ description: string;
51
+ }
33
52
  export interface ConnectorView {
34
53
  id: string;
35
54
  name: string;
@@ -38,6 +57,8 @@ export interface ConnectorView {
38
57
  enabled: boolean;
39
58
  connected: boolean;
40
59
  capabilities: ConnectorCapabilityView[];
60
+ /** Present when this connector has a downloadable local companion. */
61
+ installer?: ConnectorInstallerView;
41
62
  }
42
63
  /** Resolve the persisted state file without depending on a global DSH path. */
43
64
  export declare const CONNECTOR_STATE_PATH: string;
@@ -45,6 +66,20 @@ export declare const CONNECTOR_STATE_PATH: string;
45
66
  export declare function readConnectorState(path?: string): Promise<DataOpsConnectorState>;
46
67
  /** Persist state atomically. */
47
68
  export declare function writeConnectorState(state: DataOpsConnectorState, path?: string): Promise<void>;
69
+ /** Read browser-bridge state; a missing or corrupt file means disabled. */
70
+ export declare function readBrowserBridgeState(path?: string): Promise<BrowserBridgeConnectorState>;
71
+ /** Persist browser-bridge state atomically. */
72
+ export declare function writeBrowserBridgeState(state: BrowserBridgeConnectorState, path?: string): Promise<void>;
73
+ /**
74
+ * Build the browser-bridge connector row.
75
+ *
76
+ * `connected` is evidence, not intent: it is true only while the MCP client is loaded *and*
77
+ * the gateway reports the session active. `enabled` remains the persisted switch.
78
+ * @param state - Persisted connector switch.
79
+ * @param runtime - Live session status; omit when no session manager is active.
80
+ * @returns The connector row the skill center renders.
81
+ */
82
+ export declare function buildBrowserBridgeConnectorView(state: BrowserBridgeConnectorState, runtime?: BrowserBridgeStatus): ConnectorView;
48
83
  /** Build the connector row for one current scope. */
49
84
  export declare function buildConnectorView(scope: DataOpsScope | undefined, state: DataOpsConnectorState): ConnectorView;
50
85
  /** Whether one capability id is in the fixed catalogue. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-dataops-managed",
3
- "version": "0.3.50",
3
+ "version": "0.3.52",
4
4
  "description": "DataOps JWT intake and credential-backed MCP tools for managed DeepSeek Harness workspaces.",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: browser-bridge-companion
3
+ description: 用户要在自己的本地 Chrome/Edge 里打开内网系统、登录、点页面、填表、截图或做网页自动化时使用。先调用 browser_bridge_status 探测 Companion;未连接时调用 browser_bridge_connect 主动连接,仍失败再让用户打开门户「浏览器桥接」一键配对或启动托盘。不要向用户索取配对码、密码或 Cookie。
4
+ ---
5
+
6
+ # 浏览器桥接 Companion
7
+
8
+ 用户说「打开这个网页」「登录内网系统」「帮我点一下」「填这个表」「截个图」并涉及**用户本地浏览器**时,按本技能执行。
9
+
10
+ ## 触发
11
+
12
+ - 需要用户已登录的内网系统;
13
+ - 需要用户扫码、短信验证码、MFA;
14
+ - 需要看到真实浏览器窗口并人工接管;
15
+ - 需要把网页操作结果交给 AI 继续处理。
16
+
17
+ ## 连接探测(每次浏览器任务开始前)
18
+
19
+ 1. 先调用 `browser_bridge_status`:
20
+ - 返回「已连接」→ 直接进入标准流程;
21
+ - 返回「未建立会话」「离线」「未配对」→ 进入第 2 步。
22
+ 2. 调用 `browser_bridge_connect`,它会请求工作区主动建立桥接会话并等待几秒:
23
+ - 返回「已连接」→ 进入标准流程;
24
+ - 返回「未配对」→ 告诉用户:打开门户「账号菜单 → 浏览器桥接」页面,点「配对这台电脑」;如果本机还没装 Companion,先运行 Windows 离线安装包;
25
+ - 返回「Companion 未在线」→ 告诉用户:在 Windows 托盘里启动「万相浏览器桥接」,确认托盘显示「已连接」,然后让你重试。
26
+ 3. **不要向用户索取 8 位配对码**。一键配对由门户把配对码直接交给本机 Companion,用户只需要点按钮;配对码是内部一次性凭据,不是给用户抄写的。
27
+ 4. 探测/连接失败时,明确告诉用户下一步,不要编造页面内容,也不要退化成用 curl 抓页面冒充浏览器操作。
28
+
29
+ ## 标准流程
30
+
31
+ 1. 用 `browser_navigate` 打开目标地址。
32
+ 2. 用 `browser_snapshot` 读取页面结构,再决定点击/输入,不要盲点坐标。
33
+ 3. 需要登录、验证码、MFA 时,暂停自动化:
34
+ - 让用户在当前浏览器窗口完成;
35
+ - 不要向用户索取密码、验证码、配对码或 Cookie;
36
+ - 用户确认登录完成后再继续。
37
+ 4. 操作完成后用 `browser_take_screenshot` 或页面文本回传结果。
38
+ 5. 任务结束后释放会话,不要长期占用浏览器。
39
+
40
+ ## 安全边界
41
+
42
+ - 只操作用户明确授权的域名;不访问未授权站点。
43
+ - 不读取、不导出、不上传 Cookie、LocalStorage、密码。
44
+ - 不绕过验证码、风控或登录保护。
45
+ - 涉及支付、审批、删除等高风险动作,必须先让用户确认。
46
+ - 用户要求停止/接管时,立即暂停自动化。
47
+
48
+ ## 常见错误
49
+
50
+ - **`browser_*` 工具不存在**:连接器可能未启用或 Companion 未连接。先 `browser_bridge_status` → `browser_bridge_connect`;仍不行再让用户检查门户「浏览器桥接」页面和 Windows 托盘,不要猜端口。
51
+ - **连接器显示未配对**:让用户在门户「浏览器桥接」页面点「配对这台电脑」;不要手工输入配对码。
52
+ - **连接器显示离线**:让用户启动 Windows 托盘里的「万相浏览器桥接」;插件每 30 秒自动探测,托盘恢复后无需重启工作区。
53
+ - **设备已撤销**:在门户重新点「配对这台电脑」;旧设备需要重新授权。
54
+ - **浏览器没打开**:Companion 只在第一次工具调用时启动 Chromium;先调用一次 `browser_navigate`。
55
+ - **登录态丢失**:使用 Companion 的专用 profile,不要清空安装目录下的 `profile/`。
56
+ - **不要用本机 8931 端口判断生产连通性**:生产链路只认 DataOps 会话和 Companion 在线状态;本地 MCP 只监听 `127.0.0.1`。
57
+
58
+ ## 当前版本说明
59
+
60
+ 安装包是离线 Windows 包,内含 Chromium、Node 和 Playwright MCP;安装和启动不需要外网。
61
+ 本次交付未重打安装包,已安装机器通过替换 `companion.mjs` / `tray.ps1` 获得生产链路与托盘。