@mind-harness/mh-browser 0.2.3 → 0.2.4
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/THIRD-PARTY-NOTICES +23 -0
- package/extension/manifest.json +1 -1
- package/lib/client.cjs +446 -0
- package/lib/index.js +36 -14
- package/lib/types/card.d.ts +24 -0
- package/lib/types/client.d.ts +53 -0
- package/lib/types/locales.d.ts +15 -0
- package/lib/types/row.d.ts +69 -0
- package/lib/types/service/windows.d.ts +1 -0
- package/package.json +24 -4
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
lib/client.cjs includes code from @deepseek-ai/dsh-typert-protocol, distributed under the following license.
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2026 DeepSeek
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/extension/manifest.json
CHANGED
package/lib/client.cjs
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@mind-harness/mh-browser",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let zod = require("zod");
|
|
8
|
+
let react = require("react");
|
|
9
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.2-rc.1_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-typert-protocol/lib/types/remote-info.js
|
|
10
|
+
/** Lazy assembly of generated Remote definitions using caller-supplied Zod; no runtime imports. */
|
|
11
|
+
/**
|
|
12
|
+
* Retain one generated definition per endpoint without constructing parsers or projections.
|
|
13
|
+
* The class instance builds its shared descriptor/method index on first access;
|
|
14
|
+
* input schemas and JSON Schema projections are cached only when requested.
|
|
15
|
+
* @param spec - compiler-produced method facts and Zod factories.
|
|
16
|
+
* @param zod - the generated artifact's Zod runtime for named-input parsers.
|
|
17
|
+
* @returns a lazy, mountable info instance with no registration or transport effects.
|
|
18
|
+
*/
|
|
19
|
+
function createTypertRemoteInfo(spec, zod) {
|
|
20
|
+
return new RemoteInfo(spec, zod);
|
|
21
|
+
}
|
|
22
|
+
var RemoteInfo = class {
|
|
23
|
+
spec;
|
|
24
|
+
zod;
|
|
25
|
+
index;
|
|
26
|
+
constructor(spec, zod) {
|
|
27
|
+
this.spec = spec;
|
|
28
|
+
this.zod = zod;
|
|
29
|
+
}
|
|
30
|
+
get package() {
|
|
31
|
+
return this.spec.package;
|
|
32
|
+
}
|
|
33
|
+
get descriptors() {
|
|
34
|
+
return this.resolve().descriptors;
|
|
35
|
+
}
|
|
36
|
+
get methods() {
|
|
37
|
+
return this.resolve().methods;
|
|
38
|
+
}
|
|
39
|
+
resolve() {
|
|
40
|
+
if (this.index !== void 0) return this.index;
|
|
41
|
+
const zod = this.zod;
|
|
42
|
+
const descriptors = [];
|
|
43
|
+
const methods = Object.create(null);
|
|
44
|
+
for (const [endpoint, definition] of Object.entries(this.spec.methods)) {
|
|
45
|
+
const separator = endpoint.indexOf("/");
|
|
46
|
+
const namespace = endpoint.slice(0, separator);
|
|
47
|
+
const method = endpoint.slice(separator + 1);
|
|
48
|
+
const parameters = definition.parameters.map((parameter) => ({
|
|
49
|
+
...parameter,
|
|
50
|
+
wire: parameter.wire ?? parameter.name
|
|
51
|
+
}));
|
|
52
|
+
const descriptor = {
|
|
53
|
+
...definition,
|
|
54
|
+
id: `${this.spec.package}#${endpoint}`,
|
|
55
|
+
namespace,
|
|
56
|
+
method,
|
|
57
|
+
parameters,
|
|
58
|
+
result: definition.result.description === void 0 ? definition.result : new ResultValue(definition.result)
|
|
59
|
+
};
|
|
60
|
+
if (definition.invocation.kind === "direct") {
|
|
61
|
+
const inputs = [];
|
|
62
|
+
methods[endpoint] = Object.assign(descriptor, {
|
|
63
|
+
input(options) {
|
|
64
|
+
const strict = options?.strict === true;
|
|
65
|
+
return inputs[strict ? 1 : 0] ??= new NamedInput(parameters, strict, zod);
|
|
66
|
+
},
|
|
67
|
+
invoke(remote, input, signal) {
|
|
68
|
+
const named = input;
|
|
69
|
+
const values = parameters.map((parameter) => named[parameter.wire]);
|
|
70
|
+
if (definition.cancellation !== void 0) values.push(signal);
|
|
71
|
+
const receiver = Reflect.get(remote, namespace);
|
|
72
|
+
return Reflect.get(receiver, method).apply(receiver, values);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
descriptors.push(descriptor);
|
|
77
|
+
}
|
|
78
|
+
return this.index = {
|
|
79
|
+
descriptors,
|
|
80
|
+
methods
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
function optional(parameter) {
|
|
85
|
+
return parameter.source === "json" && parameter.acceptsUndefined === true;
|
|
86
|
+
}
|
|
87
|
+
var NamedInput = class {
|
|
88
|
+
parameters;
|
|
89
|
+
strict;
|
|
90
|
+
zod;
|
|
91
|
+
schema;
|
|
92
|
+
projection;
|
|
93
|
+
constructor(parameters, strict, zod) {
|
|
94
|
+
this.parameters = parameters;
|
|
95
|
+
this.strict = strict;
|
|
96
|
+
this.zod = zod;
|
|
97
|
+
}
|
|
98
|
+
codec(parameter) {
|
|
99
|
+
return this.strict ? parameter.strictCodec : parameter.codec;
|
|
100
|
+
}
|
|
101
|
+
create = () => this.schema ??= this.zod.strictObject(Object.fromEntries(this.parameters.map((parameter) => {
|
|
102
|
+
const value = this.codec(parameter).create();
|
|
103
|
+
return [parameter.wire, optional(parameter) ? value.optional() : value.nonoptional()];
|
|
104
|
+
})));
|
|
105
|
+
get jsonSchema() {
|
|
106
|
+
return this.project().jsonSchema;
|
|
107
|
+
}
|
|
108
|
+
get jsonSchemaError() {
|
|
109
|
+
return this.project().jsonSchemaError;
|
|
110
|
+
}
|
|
111
|
+
project() {
|
|
112
|
+
if (this.projection !== void 0) return this.projection;
|
|
113
|
+
const unavailable = this.parameters.find((parameter) => this.codec(parameter).jsonSchema === void 0);
|
|
114
|
+
if (unavailable !== void 0) return this.projection = { jsonSchemaError: this.codec(unavailable).jsonSchemaError ?? `No JSON Schema for parameter ${unavailable.wire}` };
|
|
115
|
+
return this.projection = { jsonSchema: {
|
|
116
|
+
type: "object",
|
|
117
|
+
properties: Object.fromEntries(this.parameters.map((parameter) => [parameter.wire, {
|
|
118
|
+
...this.codec(parameter).jsonSchema,
|
|
119
|
+
...parameter.description === void 0 ? {} : { description: parameter.description }
|
|
120
|
+
}])),
|
|
121
|
+
required: this.parameters.filter((parameter) => !optional(parameter)).map((parameter) => parameter.wire),
|
|
122
|
+
additionalProperties: false
|
|
123
|
+
} };
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var ResultValue = class {
|
|
127
|
+
spec;
|
|
128
|
+
projection;
|
|
129
|
+
constructor(spec) {
|
|
130
|
+
this.spec = spec;
|
|
131
|
+
}
|
|
132
|
+
get mode() {
|
|
133
|
+
return this.spec.mode;
|
|
134
|
+
}
|
|
135
|
+
get typeSymbol() {
|
|
136
|
+
return this.spec.typeSymbol;
|
|
137
|
+
}
|
|
138
|
+
get create() {
|
|
139
|
+
return this.spec.create;
|
|
140
|
+
}
|
|
141
|
+
get decode() {
|
|
142
|
+
return this.spec.decode;
|
|
143
|
+
}
|
|
144
|
+
get encode() {
|
|
145
|
+
return this.spec.encode;
|
|
146
|
+
}
|
|
147
|
+
get description() {
|
|
148
|
+
return this.spec.description;
|
|
149
|
+
}
|
|
150
|
+
get jsonSchemaError() {
|
|
151
|
+
return this.spec.jsonSchemaError;
|
|
152
|
+
}
|
|
153
|
+
get jsonSchema() {
|
|
154
|
+
if (this.projection === void 0) {
|
|
155
|
+
const schema = this.spec.jsonSchema;
|
|
156
|
+
this.projection = { value: schema === void 0 ? void 0 : {
|
|
157
|
+
...schema,
|
|
158
|
+
description: this.spec.description
|
|
159
|
+
} };
|
|
160
|
+
}
|
|
161
|
+
return this.projection.value;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region lib/typert.remote-client.js
|
|
166
|
+
let _mind_harness_mh_browser_mhBrowser_revealHandover_parameter_0$schema$value;
|
|
167
|
+
const _mind_harness_mh_browser_mhBrowser_revealHandover_parameter_0$schema = () => _mind_harness_mh_browser_mhBrowser_revealHandover_parameter_0$schema$value ??= zod.z.string();
|
|
168
|
+
let _mind_harness_mh_browser_mhBrowser_revealHandover_result$schema$value;
|
|
169
|
+
const _mind_harness_mh_browser_mhBrowser_revealHandover_result$schema = () => _mind_harness_mh_browser_mhBrowser_revealHandover_result$schema$value ??= zod.z.object({ "status": zod.z.union([
|
|
170
|
+
zod.z.literal("revealed"),
|
|
171
|
+
zod.z.literal("not-handing-over"),
|
|
172
|
+
zod.z.literal("no-tab")
|
|
173
|
+
]) });
|
|
174
|
+
let _mind_harness_mh_browser_mhBrowser_revealHandover_parameter_0_strict$schema$value;
|
|
175
|
+
const _mind_harness_mh_browser_mhBrowser_revealHandover_parameter_0_strict$schema = () => _mind_harness_mh_browser_mhBrowser_revealHandover_parameter_0_strict$schema$value ??= zod.z.string();
|
|
176
|
+
const TYPERT_REMOTE = createTypertRemoteInfo({
|
|
177
|
+
package: "@mind-harness/mh-browser",
|
|
178
|
+
methods: { "mhBrowser/revealHandover": {
|
|
179
|
+
service: "mhBrowser",
|
|
180
|
+
description: "The person asked to see the page this Session handed over.",
|
|
181
|
+
invocation: { kind: "direct" },
|
|
182
|
+
parameters: [{
|
|
183
|
+
name: "sessionId",
|
|
184
|
+
source: "json",
|
|
185
|
+
codec: {
|
|
186
|
+
mode: "strict",
|
|
187
|
+
typeSymbol: "@mind-harness/mh-browser#mhBrowser/revealHandover:sessionId",
|
|
188
|
+
create: _mind_harness_mh_browser_mhBrowser_revealHandover_parameter_0$schema,
|
|
189
|
+
jsonSchema: { "type": "string" }
|
|
190
|
+
},
|
|
191
|
+
strictCodec: {
|
|
192
|
+
mode: "strict",
|
|
193
|
+
typeSymbol: "@mind-harness/mh-browser#mhBrowser/revealHandover:sessionId",
|
|
194
|
+
create: _mind_harness_mh_browser_mhBrowser_revealHandover_parameter_0_strict$schema,
|
|
195
|
+
jsonSchema: { "type": "string" }
|
|
196
|
+
}
|
|
197
|
+
}],
|
|
198
|
+
cancellation: { parameter: "signal" },
|
|
199
|
+
result: {
|
|
200
|
+
mode: "strict",
|
|
201
|
+
typeSymbol: "@mind-harness/mh-browser#mhBrowser/revealHandover:result",
|
|
202
|
+
create: _mind_harness_mh_browser_mhBrowser_revealHandover_result$schema,
|
|
203
|
+
jsonSchema: {
|
|
204
|
+
"type": "object",
|
|
205
|
+
"properties": { "status": {
|
|
206
|
+
"type": "string",
|
|
207
|
+
"enum": [
|
|
208
|
+
"revealed",
|
|
209
|
+
"not-handing-over",
|
|
210
|
+
"no-tab"
|
|
211
|
+
]
|
|
212
|
+
} },
|
|
213
|
+
"required": ["status"],
|
|
214
|
+
"additionalProperties": true
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
sourceLocation: {
|
|
218
|
+
"file": "packages/mh-browser/src/service/service.ts",
|
|
219
|
+
"line": 624,
|
|
220
|
+
"column": 9
|
|
221
|
+
}
|
|
222
|
+
} }
|
|
223
|
+
}, zod.z);
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/client/card.ts
|
|
226
|
+
/** Host theme tokens only; the rules unmount with the row. */
|
|
227
|
+
const STYLE = `
|
|
228
|
+
.mh-br { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; color: var(--dsw-alias-label-primary); font-size: 14px; line-height: 20px; }
|
|
229
|
+
.mh-br-line { margin: 0; }
|
|
230
|
+
.mh-br-status { margin: 0; color: var(--dsw-alias-label-secondary); }
|
|
231
|
+
.mh-br-button { padding: 4px 10px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: var(--dsw-radius-md); background: transparent; color: var(--dsw-alias-label-primary); font: inherit; cursor: pointer; }
|
|
232
|
+
`;
|
|
233
|
+
/** The open handover: the reason and the button that raises its window. */
|
|
234
|
+
function HandoverRow(props) {
|
|
235
|
+
const [note, setNote] = (0, react.useState)(void 0);
|
|
236
|
+
return (0, react.createElement)("section", { className: "mh-br" }, (0, react.createElement)("style", null, STYLE), (0, react.createElement)("p", { className: "mh-br-line" }, props.t("waiting", { reason: props.reason })), (0, react.createElement)("button", {
|
|
237
|
+
type: "button",
|
|
238
|
+
className: "mh-br-button",
|
|
239
|
+
onClick: () => {
|
|
240
|
+
props.reveal(props.sessionId, new AbortController().signal).then((result) => {
|
|
241
|
+
setNote(noteFor(result, props.t));
|
|
242
|
+
}).catch(() => {
|
|
243
|
+
setNote(props.t("failed"));
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}, props.t("reveal")), note !== void 0 ? (0, react.createElement)("p", { className: "mh-br-status" }, note) : null);
|
|
247
|
+
}
|
|
248
|
+
/** `revealed` adds no status line. */
|
|
249
|
+
function noteFor(result, t) {
|
|
250
|
+
if (!result.ok) return t("failed");
|
|
251
|
+
if (result.value.status === "not-handing-over") return t("notHandingOver");
|
|
252
|
+
if (result.value.status === "no-tab") return t("noTab");
|
|
253
|
+
}
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/client/locales.ts
|
|
256
|
+
/** Dictionary namespace for the handover row. */
|
|
257
|
+
const NS = "mh-browser";
|
|
258
|
+
const zh = {
|
|
259
|
+
waiting: "浏览器交给你了:{reason}",
|
|
260
|
+
reveal: "去浏览器",
|
|
261
|
+
notHandingOver: "这次交接已经结束",
|
|
262
|
+
noTab: "没有可以去的页面",
|
|
263
|
+
failed: "没能切到浏览器"
|
|
264
|
+
};
|
|
265
|
+
const en = {
|
|
266
|
+
waiting: "The browser is yours: {reason}",
|
|
267
|
+
reveal: "Go to the browser",
|
|
268
|
+
notHandingOver: "This handover has already ended",
|
|
269
|
+
noTab: "There is no page to open",
|
|
270
|
+
failed: "Could not switch to the browser"
|
|
271
|
+
};
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/client/row.ts
|
|
274
|
+
/**
|
|
275
|
+
* One chat row for the open `browser_handover` in a turn.
|
|
276
|
+
* `groupTree: 'turn'` stands outside the process group. A settled call keeps
|
|
277
|
+
* the same key and hides the row; a hidden row is omitted from group order.
|
|
278
|
+
*/
|
|
279
|
+
const HANDOVER_KIND = "browser-handover";
|
|
280
|
+
const HANDOVER_TOOL = "browser_handover";
|
|
281
|
+
function isRecord(value) {
|
|
282
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
283
|
+
}
|
|
284
|
+
function turnOf(data) {
|
|
285
|
+
if (!isRecord(data) || typeof data.turn !== "number") return void 0;
|
|
286
|
+
return data.turn;
|
|
287
|
+
}
|
|
288
|
+
function reasonOf(value) {
|
|
289
|
+
if (typeof value !== "string") return "";
|
|
290
|
+
try {
|
|
291
|
+
const parsed = JSON.parse(value);
|
|
292
|
+
if (!isRecord(parsed) || typeof parsed.reason !== "string") return "";
|
|
293
|
+
return parsed.reason;
|
|
294
|
+
} catch {
|
|
295
|
+
return "";
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function callOf(data) {
|
|
299
|
+
if (!isRecord(data) || typeof data.callId !== "string" || typeof data.name !== "string") return void 0;
|
|
300
|
+
return {
|
|
301
|
+
callId: data.callId,
|
|
302
|
+
name: data.name,
|
|
303
|
+
arguments: data.arguments
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/** A result names its call on `message.source` and again on `message.toolCallId`. */
|
|
307
|
+
function callIdOf(data) {
|
|
308
|
+
if (!isRecord(data) || !isRecord(data.message)) return void 0;
|
|
309
|
+
const message = data.message;
|
|
310
|
+
if (isRecord(message.source) && typeof message.source.callId === "string" && message.source.callId !== "") return message.source.callId;
|
|
311
|
+
if (typeof message.toolCallId === "string" && message.toolCallId !== "") return message.toolCallId;
|
|
312
|
+
}
|
|
313
|
+
function hidden(current) {
|
|
314
|
+
return {
|
|
315
|
+
...current,
|
|
316
|
+
visibility: "hidden",
|
|
317
|
+
data: { reason: "" }
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* The row for one turn. Absent until a handover in that turn has been seen;
|
|
322
|
+
* hidden, with the same key, once the open call settles.
|
|
323
|
+
*/
|
|
324
|
+
function buildHandoverView(context) {
|
|
325
|
+
const current = context.current.get("chat") ?? null;
|
|
326
|
+
const anchorSeq = context.state?.anchorSeq;
|
|
327
|
+
if (anchorSeq === void 0) return current === null ? null : hidden(current);
|
|
328
|
+
const open = context.state?.open;
|
|
329
|
+
return {
|
|
330
|
+
key: context.key,
|
|
331
|
+
kind: HANDOVER_KIND,
|
|
332
|
+
id: context.id,
|
|
333
|
+
target: "chat",
|
|
334
|
+
anchorSeq,
|
|
335
|
+
location: context.start?.location ?? { kind: "unresolved" },
|
|
336
|
+
visibility: open === void 0 ? "hidden" : "visible",
|
|
337
|
+
groupTree: "turn",
|
|
338
|
+
data: { reason: open?.reason ?? "" }
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
const handoverRowDefinition = {
|
|
342
|
+
kind: HANDOVER_KIND,
|
|
343
|
+
target: "chat",
|
|
344
|
+
match(event) {
|
|
345
|
+
const turn = turnOf(event.data);
|
|
346
|
+
if (turn === void 0) return null;
|
|
347
|
+
const id = String(turn);
|
|
348
|
+
if (event.type === "turn/start") return {
|
|
349
|
+
id,
|
|
350
|
+
role: "start"
|
|
351
|
+
};
|
|
352
|
+
if (event.type === "tool/call") return callOf(event.data)?.name === HANDOVER_TOOL ? {
|
|
353
|
+
id,
|
|
354
|
+
role: "update"
|
|
355
|
+
} : null;
|
|
356
|
+
if (event.type === "tool/result" && callIdOf(event.data) !== void 0) return {
|
|
357
|
+
id,
|
|
358
|
+
role: "update"
|
|
359
|
+
};
|
|
360
|
+
return null;
|
|
361
|
+
},
|
|
362
|
+
start() {
|
|
363
|
+
return {
|
|
364
|
+
open: void 0,
|
|
365
|
+
anchorSeq: void 0
|
|
366
|
+
};
|
|
367
|
+
},
|
|
368
|
+
update(context, match) {
|
|
369
|
+
const event = match.event;
|
|
370
|
+
if (event.type === "tool/call") {
|
|
371
|
+
const call = callOf(event.data);
|
|
372
|
+
if (call === void 0 || call.name !== HANDOVER_TOOL) return context.state;
|
|
373
|
+
return {
|
|
374
|
+
open: {
|
|
375
|
+
callId: call.callId,
|
|
376
|
+
reason: reasonOf(call.arguments),
|
|
377
|
+
seq: event.seq
|
|
378
|
+
},
|
|
379
|
+
anchorSeq: event.seq
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
if (event.type === "tool/result") {
|
|
383
|
+
const callId = callIdOf(event.data);
|
|
384
|
+
if (context.state.open === void 0 || callId !== context.state.open.callId) return context.state;
|
|
385
|
+
return {
|
|
386
|
+
open: void 0,
|
|
387
|
+
anchorSeq: context.state.anchorSeq
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
return context.state;
|
|
391
|
+
},
|
|
392
|
+
buildViewNode(context) {
|
|
393
|
+
return buildHandoverView(context);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region src/client/client.ts
|
|
398
|
+
/**
|
|
399
|
+
* Cordis services this client reads. `dsh.client.inject` is package load
|
|
400
|
+
* order, not this list. `remote.mhBrowser` is absent until `$mount`.
|
|
401
|
+
*/
|
|
402
|
+
const inject = [
|
|
403
|
+
"slots",
|
|
404
|
+
"locale",
|
|
405
|
+
"remote",
|
|
406
|
+
"uiConversation"
|
|
407
|
+
];
|
|
408
|
+
const namespaceInject = [...inject, "remote.mhBrowser"];
|
|
409
|
+
async function apply(ctx) {
|
|
410
|
+
const unmount = await ctx.remote.$mount(TYPERT_REMOTE);
|
|
411
|
+
let release = () => void 0;
|
|
412
|
+
await ctx.inject(namespaceInject, (inner) => {
|
|
413
|
+
release = start(inner);
|
|
414
|
+
});
|
|
415
|
+
return async () => {
|
|
416
|
+
release();
|
|
417
|
+
await unmount();
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
/** Register the handover row. The tool call itself keeps the generic tool row. */
|
|
421
|
+
function start(ctx) {
|
|
422
|
+
ctx.effect(() => ctx.locale.register(NS, {
|
|
423
|
+
zh,
|
|
424
|
+
en
|
|
425
|
+
}));
|
|
426
|
+
ctx.effect(() => ctx.uiConversation.events.register(handoverRowDefinition));
|
|
427
|
+
const remote = ctx.remote.mhBrowser;
|
|
428
|
+
ctx.slots.inject("conversation.chat.node", () => ctx.slots.register({
|
|
429
|
+
name: "conversation.chat.node",
|
|
430
|
+
key: HANDOVER_KIND,
|
|
431
|
+
locale: NS
|
|
432
|
+
}, (props) => (0, react.createElement)(HandoverRow, {
|
|
433
|
+
sessionId: props.sessionId,
|
|
434
|
+
reason: props.node.data.reason,
|
|
435
|
+
t: props.t,
|
|
436
|
+
reveal: (sessionId, signal) => remote.revealHandover(sessionId, signal)
|
|
437
|
+
})));
|
|
438
|
+
return () => void 0;
|
|
439
|
+
}
|
|
440
|
+
//#endregion
|
|
441
|
+
exports.apply = apply;
|
|
442
|
+
exports.inject = inject;
|
|
443
|
+
exports.start = start;
|
|
444
|
+
return module.exports;
|
|
445
|
+
}
|
|
446
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -4379,7 +4379,10 @@ var Windows = class {
|
|
|
4379
4379
|
if (extension !== void 0) for (const page of launched) await page.goto(extension.pageUrl("welcome.html")).catch(() => void 0);
|
|
4380
4380
|
context.on("page", (page) => {
|
|
4381
4381
|
for (const blank of launched.splice(0)) blank.close().catch(() => void 0);
|
|
4382
|
-
this.ingest(page)
|
|
4382
|
+
this.ingest(page).catch((error) => {
|
|
4383
|
+
if (closedTarget(error)) return;
|
|
4384
|
+
throw error;
|
|
4385
|
+
});
|
|
4383
4386
|
});
|
|
4384
4387
|
}
|
|
4385
4388
|
setPersonInput(fn) {
|
|
@@ -4923,19 +4926,29 @@ var Windows = class {
|
|
|
4923
4926
|
const known = this.byPage.get(page);
|
|
4924
4927
|
if (known !== void 0) this.forget(known);
|
|
4925
4928
|
});
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4929
|
+
let session;
|
|
4930
|
+
try {
|
|
4931
|
+
session = await context.newCDPSession(page);
|
|
4932
|
+
this.sessions.set(page, session);
|
|
4933
|
+
await session.send("Runtime.enable");
|
|
4934
|
+
await session.send("Page.enable");
|
|
4935
|
+
await session.send("Runtime.addBinding", {
|
|
4936
|
+
name: BINDING,
|
|
4937
|
+
executionContextName: WORLD
|
|
4938
|
+
});
|
|
4939
|
+
await session.send("Page.addScriptToEvaluateOnNewDocument", {
|
|
4940
|
+
source: LISTENER,
|
|
4941
|
+
worldName: WORLD,
|
|
4942
|
+
runImmediately: true
|
|
4943
|
+
});
|
|
4944
|
+
} catch (error) {
|
|
4945
|
+
if (closedTarget(error)) {
|
|
4946
|
+
const known = this.byPage.get(page);
|
|
4947
|
+
if (known !== void 0) this.forget(known);
|
|
4948
|
+
else this.dropSession(page);
|
|
4949
|
+
}
|
|
4950
|
+
throw error;
|
|
4951
|
+
}
|
|
4939
4952
|
session.on("Runtime.bindingCalled", () => {
|
|
4940
4953
|
this.report(owner, tab, page);
|
|
4941
4954
|
});
|
|
@@ -4979,6 +4992,11 @@ var Windows = class {
|
|
|
4979
4992
|
});
|
|
4980
4993
|
});
|
|
4981
4994
|
}
|
|
4995
|
+
dropSession(page) {
|
|
4996
|
+
const session = this.sessions.get(page);
|
|
4997
|
+
this.sessions.delete(page);
|
|
4998
|
+
session?.detach().catch(() => void 0);
|
|
4999
|
+
}
|
|
4982
5000
|
async targetIdOf(page) {
|
|
4983
5001
|
const context = this.context;
|
|
4984
5002
|
if (context === void 0) throw new Error("browser is not running");
|
|
@@ -4996,6 +5014,10 @@ var Windows = class {
|
|
|
4996
5014
|
return (await session.send("Browser.getWindowForTarget", { targetId })).windowId;
|
|
4997
5015
|
}
|
|
4998
5016
|
};
|
|
5017
|
+
/** Playwright's error once the page, its context, or the browser has gone. */
|
|
5018
|
+
function closedTarget(error) {
|
|
5019
|
+
return error instanceof Error && (error.message.includes("has been closed") || error.message.includes("Target closed"));
|
|
5020
|
+
}
|
|
4999
5021
|
function idleTab() {
|
|
5000
5022
|
return {
|
|
5001
5023
|
title: "",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type Translate } from './locales.ts';
|
|
3
|
+
export type RevealStatus = 'revealed' | 'not-handing-over' | 'no-tab';
|
|
4
|
+
export type RevealResult = {
|
|
5
|
+
ok: true;
|
|
6
|
+
value: {
|
|
7
|
+
status: RevealStatus;
|
|
8
|
+
};
|
|
9
|
+
} | {
|
|
10
|
+
ok: false;
|
|
11
|
+
error: {
|
|
12
|
+
code: string;
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export interface HandoverRowProps {
|
|
17
|
+
sessionId: string;
|
|
18
|
+
reason: string;
|
|
19
|
+
t: Translate;
|
|
20
|
+
reveal: (sessionId: string, signal: AbortSignal) => Promise<RevealResult>;
|
|
21
|
+
}
|
|
22
|
+
/** The open handover: the reason and the button that raises its window. */
|
|
23
|
+
export declare function HandoverRow(props: HandoverRowProps): ReactElement;
|
|
24
|
+
//# sourceMappingURL=card.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type RevealResult } from './card.ts';
|
|
3
|
+
import { type Translate } from './locales.ts';
|
|
4
|
+
import { handoverRowDefinition } from './row.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Cordis services this client reads. `dsh.client.inject` is package load
|
|
7
|
+
* order, not this list. `remote.mhBrowser` is absent until `$mount`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const inject: readonly ["slots", "locale", "remote", "uiConversation"];
|
|
10
|
+
export interface MhBrowserRemote {
|
|
11
|
+
revealHandover(sessionId: string, signal?: AbortSignal): Promise<RevealResult>;
|
|
12
|
+
}
|
|
13
|
+
interface RemoteCarrier {
|
|
14
|
+
$mount(contribution: object): Promise<() => Promise<void>>;
|
|
15
|
+
}
|
|
16
|
+
/** Props the session-scoped chat-node seat passes in. The session id is that seat's. */
|
|
17
|
+
export interface HostRowProps {
|
|
18
|
+
sessionId: string;
|
|
19
|
+
node: {
|
|
20
|
+
readonly data: {
|
|
21
|
+
readonly reason: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
t: Translate;
|
|
25
|
+
}
|
|
26
|
+
export interface ClientHost {
|
|
27
|
+
slots: {
|
|
28
|
+
inject(name: string, register: () => unknown): unknown;
|
|
29
|
+
register(options: {
|
|
30
|
+
name: string;
|
|
31
|
+
key: string;
|
|
32
|
+
locale: string;
|
|
33
|
+
}, component: (props: HostRowProps) => ReactElement): () => void;
|
|
34
|
+
};
|
|
35
|
+
locale: {
|
|
36
|
+
register(ns: string, dicts: Record<'zh' | 'en', Record<string, string>>): () => void;
|
|
37
|
+
};
|
|
38
|
+
uiConversation: {
|
|
39
|
+
events: {
|
|
40
|
+
register(definition: typeof handoverRowDefinition): () => void;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
effect(execute: () => () => void): unknown;
|
|
44
|
+
remote: RemoteCarrier & {
|
|
45
|
+
mhBrowser: MhBrowserRemote;
|
|
46
|
+
};
|
|
47
|
+
inject(names: readonly string[], apply: (ctx: ClientHost) => void): PromiseLike<unknown>;
|
|
48
|
+
}
|
|
49
|
+
export declare function apply(ctx: ClientHost): Promise<() => Promise<void>>;
|
|
50
|
+
/** Register the handover row. The tool call itself keeps the generic tool row. */
|
|
51
|
+
export declare function start(ctx: ClientHost): () => void;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Dictionary namespace for the handover row. */
|
|
2
|
+
export declare const NS = "mh-browser";
|
|
3
|
+
export declare const zh: {
|
|
4
|
+
readonly waiting: "浏览器交给你了:{reason}";
|
|
5
|
+
readonly reveal: "去浏览器";
|
|
6
|
+
readonly notHandingOver: "这次交接已经结束";
|
|
7
|
+
readonly noTab: "没有可以去的页面";
|
|
8
|
+
readonly failed: "没能切到浏览器";
|
|
9
|
+
};
|
|
10
|
+
export type CardKey = keyof typeof zh;
|
|
11
|
+
export declare const en: Record<CardKey, string>;
|
|
12
|
+
export type Translate = (key: CardKey, params?: Record<string, unknown>) => string;
|
|
13
|
+
/** A translator over one dictionary, for rendering outside the host (tests). */
|
|
14
|
+
export declare function translator(dict: Record<CardKey, string>): Translate;
|
|
15
|
+
//# sourceMappingURL=locales.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One chat row for the open `browser_handover` in a turn.
|
|
3
|
+
* `groupTree: 'turn'` stands outside the process group. A settled call keeps
|
|
4
|
+
* the same key and hides the row; a hidden row is omitted from group order.
|
|
5
|
+
*/
|
|
6
|
+
export declare const HANDOVER_KIND = "browser-handover";
|
|
7
|
+
export interface HandoverRowData {
|
|
8
|
+
readonly reason: string;
|
|
9
|
+
}
|
|
10
|
+
interface OpenCall {
|
|
11
|
+
readonly callId: string;
|
|
12
|
+
readonly reason: string;
|
|
13
|
+
readonly seq: number;
|
|
14
|
+
}
|
|
15
|
+
export interface HandoverTurnState {
|
|
16
|
+
readonly open: OpenCall | undefined;
|
|
17
|
+
readonly anchorSeq: number | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** A session event this row reads. Other fields are ignored. */
|
|
20
|
+
export interface FoldEvent {
|
|
21
|
+
readonly type: string;
|
|
22
|
+
readonly seq: number;
|
|
23
|
+
readonly data: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface HandoverMatch {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly role: 'start' | 'update';
|
|
28
|
+
}
|
|
29
|
+
export interface HandoverChatNode {
|
|
30
|
+
readonly key: string;
|
|
31
|
+
readonly kind: typeof HANDOVER_KIND;
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly target: 'chat';
|
|
34
|
+
readonly anchorSeq: number;
|
|
35
|
+
readonly location: unknown;
|
|
36
|
+
readonly visibility: 'visible' | 'hidden';
|
|
37
|
+
readonly groupTree: 'turn';
|
|
38
|
+
readonly data: HandoverRowData;
|
|
39
|
+
}
|
|
40
|
+
export interface HandoverNodeContext {
|
|
41
|
+
readonly key: string;
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly state: HandoverTurnState | undefined;
|
|
44
|
+
readonly start: {
|
|
45
|
+
readonly location: unknown;
|
|
46
|
+
} | undefined;
|
|
47
|
+
readonly current: {
|
|
48
|
+
get(target: string): HandoverChatNode | null | undefined;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The row for one turn. Absent until a handover in that turn has been seen;
|
|
53
|
+
* hidden, with the same key, once the open call settles.
|
|
54
|
+
*/
|
|
55
|
+
export declare function buildHandoverView(context: HandoverNodeContext): HandoverChatNode | null;
|
|
56
|
+
export declare const handoverRowDefinition: {
|
|
57
|
+
kind: string;
|
|
58
|
+
target: "chat";
|
|
59
|
+
match(event: FoldEvent): HandoverMatch | null;
|
|
60
|
+
start(): HandoverTurnState;
|
|
61
|
+
update(context: {
|
|
62
|
+
readonly state: HandoverTurnState;
|
|
63
|
+
}, match: {
|
|
64
|
+
readonly event: FoldEvent;
|
|
65
|
+
}): HandoverTurnState;
|
|
66
|
+
buildViewNode(context: HandoverNodeContext): HandoverChatNode | null;
|
|
67
|
+
};
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=row.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mind-harness/mh-browser",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Opens pages in a real browser for the agent, keeps chosen Agent Views in context, and hands the browser to you when a person is needed.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"files": [
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
"lib/typert.host.d.ts",
|
|
12
12
|
"lib/typert.remote-client.js",
|
|
13
13
|
"lib/typert.remote-client.d.ts",
|
|
14
|
+
"lib/client.cjs",
|
|
14
15
|
"locale/*.json",
|
|
15
16
|
"icon.svg",
|
|
16
|
-
"extension/*"
|
|
17
|
+
"extension/*",
|
|
18
|
+
"THIRD-PARTY-NOTICES"
|
|
17
19
|
],
|
|
18
20
|
"type": "module",
|
|
19
21
|
"main": "./lib/index.js",
|
|
@@ -35,6 +37,10 @@
|
|
|
35
37
|
"types": "./lib/typert.remote-client.d.ts",
|
|
36
38
|
"default": "./lib/typert.remote-client.js"
|
|
37
39
|
},
|
|
40
|
+
"./client": {
|
|
41
|
+
"types": "./lib/types/client.d.ts",
|
|
42
|
+
"default": "./lib/client.cjs"
|
|
43
|
+
},
|
|
38
44
|
"./package.json": "./package.json",
|
|
39
45
|
"./locale/*.json": "./locale/*.json",
|
|
40
46
|
"./icon": "./icon.svg"
|
|
@@ -63,7 +69,11 @@
|
|
|
63
69
|
"@deepseek-ai/dsh-tools": "^0.2.2-rc.1",
|
|
64
70
|
"@deepseek-ai/dsh-typert-protocol": "^0.2.2-rc.1",
|
|
65
71
|
"@deepseek-ai/dsh-user-questions": "^0.2.2-rc.1",
|
|
66
|
-
"@deepseek-ai/schemastery": "~3.19.0"
|
|
72
|
+
"@deepseek-ai/schemastery": "~3.19.0",
|
|
73
|
+
"@types/react": "^19",
|
|
74
|
+
"@types/react-dom": "^19",
|
|
75
|
+
"react": "^19.2.8",
|
|
76
|
+
"react-dom": "^19.2.8"
|
|
67
77
|
},
|
|
68
78
|
"peerDependencies": {
|
|
69
79
|
"@deepseek-ai/cordis": "^4.1.0",
|
|
@@ -72,12 +82,22 @@
|
|
|
72
82
|
"@deepseek-ai/dsh-tools": ">=0.2.2-rc.1 <0.2.3-0",
|
|
73
83
|
"@deepseek-ai/dsh-typert-protocol": ">=0.2.2-rc.1 <0.2.3-0",
|
|
74
84
|
"@deepseek-ai/dsh-user-questions": ">=0.2.2-rc.1 <0.2.3-0",
|
|
75
|
-
"@deepseek-ai/schemastery": "^3.19.0"
|
|
85
|
+
"@deepseek-ai/schemastery": "^3.19.0",
|
|
86
|
+
"react": "^19.2.8"
|
|
76
87
|
},
|
|
77
88
|
"icon": "./icon.svg",
|
|
78
89
|
"engines": {
|
|
79
90
|
"dsh": ">=0.2.2-rc.1 <0.2.3-0"
|
|
80
91
|
},
|
|
92
|
+
"dsh": {
|
|
93
|
+
"client": {
|
|
94
|
+
"platform": "web",
|
|
95
|
+
"inject": [
|
|
96
|
+
"@deepseek-ai/dsh-client-locale",
|
|
97
|
+
"@deepseek-ai/dsh-client-ui-conversation"
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
},
|
|
81
101
|
"scripts": {
|
|
82
102
|
"version": "node ../../scripts/mh/sync-extension-version.ts"
|
|
83
103
|
}
|