@mind-harness/mh-browser 0.2.2 → 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/extension/welcome.css +94 -0
- package/extension/welcome.html +40 -0
- package/extension/welcome.js +15 -0
- package/lib/client.cjs +446 -0
- package/lib/index.js +117 -31
- package/lib/typert.host.js +3 -3
- package/lib/typert.remote-client.js +1 -1
- 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/browser.d.ts +11 -0
- package/lib/types/service/extension.d.ts +5 -1
- package/lib/types/service/service.d.ts +4 -1
- package/lib/types/service/test-hooks.d.ts +4 -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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* Keep in step with the sign-in callback page in packages/mh-cloud/src/page.ts. */
|
|
2
|
+
:root {
|
|
3
|
+
--bg: #f4f4f6;
|
|
4
|
+
--card: #fff;
|
|
5
|
+
--stroke: rgba(0, 0, 0, 0.08);
|
|
6
|
+
--text: #18181b;
|
|
7
|
+
--muted: #6b6b73;
|
|
8
|
+
--accent: #4d6bfe;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@media (prefers-color-scheme: dark) {
|
|
12
|
+
:root {
|
|
13
|
+
--bg: #161618;
|
|
14
|
+
--card: #202023;
|
|
15
|
+
--stroke: rgba(255, 255, 255, 0.08);
|
|
16
|
+
--text: #ededf0;
|
|
17
|
+
--muted: #9a9aa3;
|
|
18
|
+
--accent: #7f95ff;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
* {
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
html,
|
|
27
|
+
body {
|
|
28
|
+
height: 100%;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
body {
|
|
32
|
+
margin: 0;
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: center;
|
|
36
|
+
padding: 24px;
|
|
37
|
+
background: var(--bg);
|
|
38
|
+
color: var(--text);
|
|
39
|
+
font:
|
|
40
|
+
15px/1.6 -apple-system,
|
|
41
|
+
BlinkMacSystemFont,
|
|
42
|
+
'Segoe UI',
|
|
43
|
+
'PingFang SC',
|
|
44
|
+
'Hiragino Sans GB',
|
|
45
|
+
'Microsoft YaHei',
|
|
46
|
+
sans-serif;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.card {
|
|
50
|
+
width: 100%;
|
|
51
|
+
max-width: 420px;
|
|
52
|
+
padding: 36px 32px 28px;
|
|
53
|
+
border: 1px solid var(--stroke);
|
|
54
|
+
border-radius: 20px;
|
|
55
|
+
background: var(--card);
|
|
56
|
+
text-align: center;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.product {
|
|
60
|
+
margin: 0 0 24px;
|
|
61
|
+
font-size: 12px;
|
|
62
|
+
letter-spacing: 0.06em;
|
|
63
|
+
text-transform: uppercase;
|
|
64
|
+
color: var(--muted);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.mark {
|
|
68
|
+
width: 56px;
|
|
69
|
+
height: 56px;
|
|
70
|
+
margin: 0 auto 16px;
|
|
71
|
+
border-radius: 50%;
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
justify-content: center;
|
|
75
|
+
color: var(--accent);
|
|
76
|
+
background: color-mix(in srgb, var(--accent) 14%, transparent);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
h1 {
|
|
80
|
+
margin: 0 0 8px;
|
|
81
|
+
font-size: 20px;
|
|
82
|
+
font-weight: 600;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.line {
|
|
86
|
+
margin: 0 0 4px;
|
|
87
|
+
color: var(--muted);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.hint {
|
|
91
|
+
margin: 12px 0 0;
|
|
92
|
+
font-size: 13px;
|
|
93
|
+
color: var(--muted);
|
|
94
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<meta name="color-scheme" content="light dark" />
|
|
7
|
+
<title data-text="tab">Mind Harness browser</title>
|
|
8
|
+
<link rel="stylesheet" href="welcome.css" />
|
|
9
|
+
<script src="welcome.js" defer></script>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<main class="card">
|
|
13
|
+
<p class="product">Mind Harness</p>
|
|
14
|
+
<div class="mark" aria-hidden="true">
|
|
15
|
+
<svg
|
|
16
|
+
viewBox="0 0 24 24"
|
|
17
|
+
width="28"
|
|
18
|
+
height="28"
|
|
19
|
+
fill="none"
|
|
20
|
+
stroke="currentColor"
|
|
21
|
+
stroke-width="2.2"
|
|
22
|
+
stroke-linecap="round"
|
|
23
|
+
stroke-linejoin="round"
|
|
24
|
+
>
|
|
25
|
+
<rect x="3.5" y="5" width="17" height="14" rx="2.5" />
|
|
26
|
+
<path d="M3.5 9.5h17" />
|
|
27
|
+
</svg>
|
|
28
|
+
</div>
|
|
29
|
+
<h1 data-text="title">This is the Mind Harness browser</h1>
|
|
30
|
+
<p class="line" data-text="what">
|
|
31
|
+
The agent opens pages, reads them, and acts on them here. Sites you sign in to here stay
|
|
32
|
+
signed in for the agent.
|
|
33
|
+
</p>
|
|
34
|
+
<p class="line" data-text="keep">
|
|
35
|
+
Please keep this browser running. When the agent needs you, the conversation will tell you.
|
|
36
|
+
</p>
|
|
37
|
+
<p class="hint" data-text="closes">This window closes when the agent opens its first page.</p>
|
|
38
|
+
</main>
|
|
39
|
+
</body>
|
|
40
|
+
</html>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const ZH = {
|
|
2
|
+
tab: 'Mind Harness 浏览器',
|
|
3
|
+
title: '这是 Mind\u00a0Harness 的浏览器',
|
|
4
|
+
what: 'Agent 在这里替你打开网页、读取内容、完成操作。你在这里登录过的网站,Agent 之后也能用上。',
|
|
5
|
+
keep: '请不要退出这个浏览器。需要你来接手时,对话里会提示你。',
|
|
6
|
+
closes: 'Agent 打开第一个网页后,这个窗口会自动关闭。',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (navigator.language.toLowerCase().startsWith('zh')) {
|
|
10
|
+
document.documentElement.lang = 'zh-CN'
|
|
11
|
+
for (const node of document.querySelectorAll('[data-text]')) {
|
|
12
|
+
const text = ZH[node.getAttribute('data-text')]
|
|
13
|
+
if (text !== undefined) node.textContent = text
|
|
14
|
+
}
|
|
15
|
+
}
|
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
|
@@ -7,7 +7,7 @@ import { assertSupportedJsonSchema, defineTool, validateJsonSchemaValue } from "
|
|
|
7
7
|
import { createHash, randomUUID } from "node:crypto";
|
|
8
8
|
import { parse } from "yaml";
|
|
9
9
|
import { constants, readFileSync } from "node:fs";
|
|
10
|
-
import { lstat, mkdir, open, readFile, realpath, unlink, writeFile } from "node:fs/promises";
|
|
10
|
+
import { lstat, mkdir, open, readFile, readlink, realpath, unlink, writeFile } from "node:fs/promises";
|
|
11
11
|
import { z as z$1 } from "zod";
|
|
12
12
|
import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
13
13
|
import { chromium } from "playwright";
|
|
@@ -2979,6 +2979,50 @@ async function launchBrowser(options) {
|
|
|
2979
2979
|
throw error;
|
|
2980
2980
|
}
|
|
2981
2981
|
}
|
|
2982
|
+
/**
|
|
2983
|
+
* Process id of the browser's main process. Playwright gives none for a
|
|
2984
|
+
* persistent context. Asks the browser first; on POSIX the profile's
|
|
2985
|
+
* `SingletonLock` link names it as `<host>-<pid>`.
|
|
2986
|
+
*/
|
|
2987
|
+
async function browserPid(context, profileDir) {
|
|
2988
|
+
const browser = context.browser();
|
|
2989
|
+
if (browser !== null) try {
|
|
2990
|
+
const session = await browser.newBrowserCDPSession();
|
|
2991
|
+
try {
|
|
2992
|
+
const main = (await session.send("SystemInfo.getProcessInfo")).processInfo.find((item) => item.type === "browser");
|
|
2993
|
+
if (main !== void 0 && main.id > 0) return main.id;
|
|
2994
|
+
} finally {
|
|
2995
|
+
await session.detach().catch(() => void 0);
|
|
2996
|
+
}
|
|
2997
|
+
} catch {}
|
|
2998
|
+
if (process.platform === "win32") return void 0;
|
|
2999
|
+
try {
|
|
3000
|
+
const target = await readlink(join(profileDir, "SingletonLock"));
|
|
3001
|
+
const pid = Number(target.slice(target.lastIndexOf("-") + 1));
|
|
3002
|
+
return Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
3003
|
+
} catch {
|
|
3004
|
+
return;
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
/**
|
|
3008
|
+
* Ask the browser to close; kill `pid` when that fails or takes longer than
|
|
3009
|
+
* `waitMs`, so a stuck browser does not keep the profile locked.
|
|
3010
|
+
*/
|
|
3011
|
+
async function closeOrKill(close, pid, waitMs = 1e3, kill = (target) => {
|
|
3012
|
+
process.kill(target, "SIGKILL");
|
|
3013
|
+
}) {
|
|
3014
|
+
let timer;
|
|
3015
|
+
const outcome = await Promise.race([close().then(() => "closed", () => "failed"), new Promise((resolve) => {
|
|
3016
|
+
timer = setTimeout(() => resolve("timeout"), waitMs);
|
|
3017
|
+
})]);
|
|
3018
|
+
clearTimeout(timer);
|
|
3019
|
+
if (outcome === "closed") return "closed";
|
|
3020
|
+
if (pid === void 0) return "stuck";
|
|
3021
|
+
try {
|
|
3022
|
+
kill(pid);
|
|
3023
|
+
} catch {}
|
|
3024
|
+
return "killed";
|
|
3025
|
+
}
|
|
2982
3026
|
//#endregion
|
|
2983
3027
|
//#region lib/types/service/control.js
|
|
2984
3028
|
/**
|
|
@@ -4121,7 +4165,7 @@ const REPLIED = "继续";
|
|
|
4121
4165
|
//#endregion
|
|
4122
4166
|
//#region lib/types/service/extension.js
|
|
4123
4167
|
const PACKAGE = "@mind-harness/mh-browser";
|
|
4124
|
-
const WORKER_MS =
|
|
4168
|
+
const WORKER_MS = 15e3;
|
|
4125
4169
|
/**
|
|
4126
4170
|
* Directory of the unpacked extension shipped with this package.
|
|
4127
4171
|
* Walks up from this module: sources live in `src/`, the bundle in `lib/`.
|
|
@@ -4156,6 +4200,10 @@ var Extension = class Extension {
|
|
|
4156
4200
|
const worker = await findWorker(context, loaded.id);
|
|
4157
4201
|
return new Extension(context, loaded.id, worker);
|
|
4158
4202
|
}
|
|
4203
|
+
/** Address of a page shipped in the extension directory. */
|
|
4204
|
+
pageUrl(name) {
|
|
4205
|
+
return `chrome-extension://${this.id}/${name}`;
|
|
4206
|
+
}
|
|
4159
4207
|
/** `chrome.tabs.create` in the named window. Returns the extension's tab id. */
|
|
4160
4208
|
async createTab(windowId, url) {
|
|
4161
4209
|
return (await this.worker()).evaluate(async (arg) => {
|
|
@@ -4231,13 +4279,21 @@ var Extension = class Extension {
|
|
|
4231
4279
|
return worker;
|
|
4232
4280
|
}
|
|
4233
4281
|
};
|
|
4234
|
-
|
|
4235
|
-
|
|
4282
|
+
/** The extension's service worker. Looks once more after the wait times out. */
|
|
4283
|
+
async function findWorker(context, id, timeoutMs = WORKER_MS) {
|
|
4284
|
+
const find = () => context.serviceWorkers().find((worker) => worker.url().includes(id));
|
|
4285
|
+
const open = find();
|
|
4236
4286
|
if (open !== void 0) return open;
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4287
|
+
try {
|
|
4288
|
+
return await context.waitForEvent("serviceworker", {
|
|
4289
|
+
predicate: (worker) => worker.url().includes(id),
|
|
4290
|
+
timeout: timeoutMs
|
|
4291
|
+
});
|
|
4292
|
+
} catch (error) {
|
|
4293
|
+
const late = find();
|
|
4294
|
+
if (late !== void 0) return late;
|
|
4295
|
+
throw new Error(`the browser extension did not start within ${String(timeoutMs / 1e3)} s`, { cause: error });
|
|
4296
|
+
}
|
|
4241
4297
|
}
|
|
4242
4298
|
//#endregion
|
|
4243
4299
|
//#region lib/types/service/windows.js
|
|
@@ -4319,9 +4375,14 @@ var Windows = class {
|
|
|
4319
4375
|
this.browserSession = await browser.newBrowserCDPSession();
|
|
4320
4376
|
if (options.headed) this.extension = await Extension.load(context, this.browserSession);
|
|
4321
4377
|
const launched = context.pages().filter((page) => page.url() === "about:blank");
|
|
4378
|
+
const extension = this.extension;
|
|
4379
|
+
if (extension !== void 0) for (const page of launched) await page.goto(extension.pageUrl("welcome.html")).catch(() => void 0);
|
|
4322
4380
|
context.on("page", (page) => {
|
|
4323
4381
|
for (const blank of launched.splice(0)) blank.close().catch(() => void 0);
|
|
4324
|
-
this.ingest(page)
|
|
4382
|
+
this.ingest(page).catch((error) => {
|
|
4383
|
+
if (closedTarget(error)) return;
|
|
4384
|
+
throw error;
|
|
4385
|
+
});
|
|
4325
4386
|
});
|
|
4326
4387
|
}
|
|
4327
4388
|
setPersonInput(fn) {
|
|
@@ -4865,19 +4926,29 @@ var Windows = class {
|
|
|
4865
4926
|
const known = this.byPage.get(page);
|
|
4866
4927
|
if (known !== void 0) this.forget(known);
|
|
4867
4928
|
});
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
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
|
+
}
|
|
4881
4952
|
session.on("Runtime.bindingCalled", () => {
|
|
4882
4953
|
this.report(owner, tab, page);
|
|
4883
4954
|
});
|
|
@@ -4921,6 +4992,11 @@ var Windows = class {
|
|
|
4921
4992
|
});
|
|
4922
4993
|
});
|
|
4923
4994
|
}
|
|
4995
|
+
dropSession(page) {
|
|
4996
|
+
const session = this.sessions.get(page);
|
|
4997
|
+
this.sessions.delete(page);
|
|
4998
|
+
session?.detach().catch(() => void 0);
|
|
4999
|
+
}
|
|
4924
5000
|
async targetIdOf(page) {
|
|
4925
5001
|
const context = this.context;
|
|
4926
5002
|
if (context === void 0) throw new Error("browser is not running");
|
|
@@ -4938,6 +5014,10 @@ var Windows = class {
|
|
|
4938
5014
|
return (await session.send("Browser.getWindowForTarget", { targetId })).windowId;
|
|
4939
5015
|
}
|
|
4940
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
|
+
}
|
|
4941
5021
|
function idleTab() {
|
|
4942
5022
|
return {
|
|
4943
5023
|
title: "",
|
|
@@ -5066,6 +5146,7 @@ let MhBrowserService = (() => {
|
|
|
5066
5146
|
windows = (__runInitializers(this, _instanceExtraInitializers), new Windows());
|
|
5067
5147
|
launchOptions;
|
|
5068
5148
|
context;
|
|
5149
|
+
pids = /* @__PURE__ */ new WeakMap();
|
|
5069
5150
|
ready = Promise.resolve();
|
|
5070
5151
|
closing = false;
|
|
5071
5152
|
/** The browser is not running. The next call that needs a page starts it. */
|
|
@@ -5123,7 +5204,8 @@ let MhBrowserService = (() => {
|
|
|
5123
5204
|
this.agentViewOrigins.add(parsed.origin);
|
|
5124
5205
|
} catch {}
|
|
5125
5206
|
}
|
|
5126
|
-
async open(owner, items, signal) {
|
|
5207
|
+
async open(owner, items, signal, options) {
|
|
5208
|
+
const reveal = options?.reveal === true;
|
|
5127
5209
|
return this.exclusive(owner, async () => {
|
|
5128
5210
|
await this.up(owner === PERSON_OWNER);
|
|
5129
5211
|
const views = [];
|
|
@@ -5135,7 +5217,7 @@ let MhBrowserService = (() => {
|
|
|
5135
5217
|
});
|
|
5136
5218
|
continue;
|
|
5137
5219
|
}
|
|
5138
|
-
views.push(await this.openAddress(owner, item, signal));
|
|
5220
|
+
views.push(await this.openAddress(owner, item, signal, reveal));
|
|
5139
5221
|
}
|
|
5140
5222
|
await this.enforceCap(owner);
|
|
5141
5223
|
return views;
|
|
@@ -5298,7 +5380,9 @@ let MhBrowserService = (() => {
|
|
|
5298
5380
|
await (this.context?.browser())?.close();
|
|
5299
5381
|
},
|
|
5300
5382
|
page: (owner, tab) => this.windows.get(owner, tab)?.page,
|
|
5301
|
-
running: () => this.context !== void 0
|
|
5383
|
+
running: () => this.context !== void 0,
|
|
5384
|
+
pages: () => this.context?.pages() ?? [],
|
|
5385
|
+
pid: () => this.context === void 0 ? void 0 : this.pids.get(this.context)
|
|
5302
5386
|
};
|
|
5303
5387
|
}
|
|
5304
5388
|
async act(owner, tab, op, signal) {
|
|
@@ -5503,7 +5587,7 @@ let MhBrowserService = (() => {
|
|
|
5503
5587
|
* A readable Agent View found on a tab this call opened is returned without
|
|
5504
5588
|
* the tab, and that tab is not listed as closed.
|
|
5505
5589
|
*/
|
|
5506
|
-
async openAddress(owner, item, signal) {
|
|
5590
|
+
async openAddress(owner, item, signal, reveal = false) {
|
|
5507
5591
|
if (!openableAddress(item.url)) return {
|
|
5508
5592
|
url: item.url,
|
|
5509
5593
|
reason: OPEN_ADDRESS_REASON
|
|
@@ -5517,7 +5601,7 @@ let MhBrowserService = (() => {
|
|
|
5517
5601
|
};
|
|
5518
5602
|
if (via !== void 0) return via;
|
|
5519
5603
|
}
|
|
5520
|
-
const opened = await this.openOne(owner, item.url, item.waitFor, signal, item.snapshot === true);
|
|
5604
|
+
const opened = await this.openOne(owner, item.url, item.waitFor, signal, item.snapshot === true, reveal);
|
|
5521
5605
|
this.keepAgentView(opened);
|
|
5522
5606
|
if (!wantsTab && opened.fresh && this.closable(owner, opened.live) && "representation" in opened.view && opened.view.representation.kind === "agent-view") {
|
|
5523
5607
|
await this.windows.closeTab(opened.live);
|
|
@@ -5686,12 +5770,13 @@ let MhBrowserService = (() => {
|
|
|
5686
5770
|
return body;
|
|
5687
5771
|
}
|
|
5688
5772
|
}
|
|
5689
|
-
async openOne(owner, url, waitFor, signal, snapshot = false) {
|
|
5773
|
+
async openOne(owner, url, waitFor, signal, snapshot = false, reveal = false) {
|
|
5690
5774
|
assertWaitFor(waitFor);
|
|
5691
5775
|
const reused = this.idleTabOn(owner, url);
|
|
5692
5776
|
const live = reused ?? await this.windows.openBlank(owner);
|
|
5693
5777
|
const fresh = reused === void 0;
|
|
5694
5778
|
const linked = this.control.link(owner, signal, live.id);
|
|
5779
|
+
if (reveal && !linked.signal.aborted) await live.page.bringToFront().catch(() => void 0);
|
|
5695
5780
|
const nextDialog = this.windows.nextDialog(live);
|
|
5696
5781
|
try {
|
|
5697
5782
|
let seenDialog;
|
|
@@ -6365,6 +6450,8 @@ let MhBrowserService = (() => {
|
|
|
6365
6450
|
}
|
|
6366
6451
|
async start() {
|
|
6367
6452
|
const context = await launchBrowser(this.launchOptions);
|
|
6453
|
+
const pid = await browserPid(context, this.launchOptions.profileDir);
|
|
6454
|
+
if (pid !== void 0) this.pids.set(context, pid);
|
|
6368
6455
|
if (this.closing) {
|
|
6369
6456
|
await this.closeContext(context);
|
|
6370
6457
|
return;
|
|
@@ -6423,9 +6510,8 @@ let MhBrowserService = (() => {
|
|
|
6423
6510
|
}
|
|
6424
6511
|
/** Close a context the service is done with, and kill it if close stalls. */
|
|
6425
6512
|
async closeContext(context) {
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
(browser?.process?.())?.kill("SIGKILL");
|
|
6513
|
+
await closeOrKill(() => context.close(), this.pids.get(context));
|
|
6514
|
+
this.pids.delete(context);
|
|
6429
6515
|
}
|
|
6430
6516
|
refuseIfPerson(owner, tab) {
|
|
6431
6517
|
if (this.control.ofTab(owner, tab) !== "person") return;
|
package/lib/typert.host.js
CHANGED
|
@@ -44,7 +44,7 @@ const $remote = createTypertRemoteInfo({
|
|
|
44
44
|
create: _mind_harness_mh_browser_mhBrowser_revealHandover_result$schema,
|
|
45
45
|
jsonSchema: {"type":"object","properties":{"status":{"type":"string","enum":["revealed","not-handing-over","no-tab"]}},"required":["status"],"additionalProperties":true},
|
|
46
46
|
},
|
|
47
|
-
sourceLocation: {"file":"packages/mh-browser/src/service/service.ts","line":
|
|
47
|
+
sourceLocation: {"file":"packages/mh-browser/src/service/service.ts","line":624,"column":9},
|
|
48
48
|
},
|
|
49
49
|
},
|
|
50
50
|
}, z)
|
|
@@ -75,7 +75,7 @@ export const TYPERT = {
|
|
|
75
75
|
{
|
|
76
76
|
"kind": "method",
|
|
77
77
|
"name": "open",
|
|
78
|
-
"signature": "async open( owner: string, items: { url: string; waitFor?: WaitFor; snapshot?: boolean }[], signal?: AbortSignal, ): Promise<(PageView | PageError)[]>"
|
|
78
|
+
"signature": "async open( owner: string, items: { url: string; waitFor?: WaitFor; snapshot?: boolean }[], signal?: AbortSignal, options?: { reveal?: boolean }, ): Promise<(PageView | PageError)[]>"
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
81
|
"kind": "method",
|
|
@@ -359,7 +359,7 @@ export const TYPERT = {
|
|
|
359
359
|
},
|
|
360
360
|
{
|
|
361
361
|
"name": "TestHooks",
|
|
362
|
-
"declaration": "export interface TestHooks {\n crash(): Promise<void>;\n page(owner: string, tab: string): unknown;\n running(): boolean;\n}"
|
|
362
|
+
"declaration": "export interface TestHooks {\n crash(): Promise<void>;\n page(owner: string, tab: string): unknown;\n running(): boolean;\n pages(): unknown[];\n pid(): number | undefined;\n}"
|
|
363
363
|
},
|
|
364
364
|
{
|
|
365
365
|
"name": "WaitFor",
|
|
@@ -44,7 +44,7 @@ export const TYPERT_REMOTE = createTypertRemoteInfo({
|
|
|
44
44
|
create: _mind_harness_mh_browser_mhBrowser_revealHandover_result$schema,
|
|
45
45
|
jsonSchema: {"type":"object","properties":{"status":{"type":"string","enum":["revealed","not-handing-over","no-tab"]}},"required":["status"],"additionalProperties":true},
|
|
46
46
|
},
|
|
47
|
-
sourceLocation: {"file":"packages/mh-browser/src/service/service.ts","line":
|
|
47
|
+
sourceLocation: {"file":"packages/mh-browser/src/service/service.ts","line":624,"column":9},
|
|
48
48
|
},
|
|
49
49
|
},
|
|
50
50
|
}, z)
|
|
@@ -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
|
|
@@ -20,4 +20,15 @@ export declare function chromiumSandboxEnabled(browser: BrowserName, platform?:
|
|
|
20
20
|
* A missing browser is reported and not downloaded.
|
|
21
21
|
*/
|
|
22
22
|
export declare function launchBrowser(options: LaunchOptions): Promise<BrowserContext>;
|
|
23
|
+
/**
|
|
24
|
+
* Process id of the browser's main process. Playwright gives none for a
|
|
25
|
+
* persistent context. Asks the browser first; on POSIX the profile's
|
|
26
|
+
* `SingletonLock` link names it as `<host>-<pid>`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function browserPid(context: BrowserContext, profileDir: string): Promise<number | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Ask the browser to close; kill `pid` when that fails or takes longer than
|
|
31
|
+
* `waitMs`, so a stuck browser does not keep the profile locked.
|
|
32
|
+
*/
|
|
33
|
+
export declare function closeOrKill(close: () => Promise<void>, pid: number | undefined, waitMs?: number, kill?: (target: number) => void): Promise<'closed' | 'killed' | 'stuck'>;
|
|
23
34
|
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BrowserContext, CDPSession } from 'playwright';
|
|
1
|
+
import type { BrowserContext, CDPSession, Worker } from 'playwright';
|
|
2
2
|
/**
|
|
3
3
|
* Directory of the unpacked extension shipped with this package.
|
|
4
4
|
* Walks up from this module: sources live in `src/`, the bundle in `lib/`.
|
|
@@ -14,6 +14,8 @@ export declare class Extension {
|
|
|
14
14
|
private workerPage;
|
|
15
15
|
private constructor();
|
|
16
16
|
static load(context: BrowserContext, browserSession: CDPSession): Promise<Extension>;
|
|
17
|
+
/** Address of a page shipped in the extension directory. */
|
|
18
|
+
pageUrl(name: string): string;
|
|
17
19
|
/** `chrome.tabs.create` in the named window. Returns the extension's tab id. */
|
|
18
20
|
createTab(windowId: number, url: string): Promise<number>;
|
|
19
21
|
tabIdsIn(windowId: number): Promise<number[]>;
|
|
@@ -27,4 +29,6 @@ export declare class Extension {
|
|
|
27
29
|
ungroup(tabId: number): Promise<void>;
|
|
28
30
|
private worker;
|
|
29
31
|
}
|
|
32
|
+
/** The extension's service worker. Looks once more after the wait times out. */
|
|
33
|
+
export declare function findWorker(context: BrowserContext, id: string, timeoutMs?: number): Promise<Worker>;
|
|
30
34
|
//# sourceMappingURL=extension.d.ts.map
|
|
@@ -34,6 +34,7 @@ export declare class MhBrowserService extends TypertRemoteService {
|
|
|
34
34
|
private readonly windows;
|
|
35
35
|
private readonly launchOptions;
|
|
36
36
|
private context;
|
|
37
|
+
private readonly pids;
|
|
37
38
|
private ready;
|
|
38
39
|
private closing;
|
|
39
40
|
/** The browser is not running. The next call that needs a page starts it. */
|
|
@@ -58,7 +59,9 @@ export declare class MhBrowserService extends TypertRemoteService {
|
|
|
58
59
|
url: string;
|
|
59
60
|
waitFor?: WaitFor;
|
|
60
61
|
snapshot?: boolean;
|
|
61
|
-
}[], signal?: AbortSignal
|
|
62
|
+
}[], signal?: AbortSignal, options?: {
|
|
63
|
+
reveal?: boolean;
|
|
64
|
+
}): Promise<(PageView | PageError)[]>;
|
|
62
65
|
view(owner: string, tab: string, signal?: AbortSignal): Promise<PageView | PageError>;
|
|
63
66
|
/** Pages whose current representation is already in the model's presence. */
|
|
64
67
|
rememberPresence(owner: string, urls: string[]): void;
|
|
@@ -5,5 +5,9 @@ export interface TestHooks {
|
|
|
5
5
|
page(owner: string, tab: string): unknown;
|
|
6
6
|
/** A browser process is up. */
|
|
7
7
|
running(): boolean;
|
|
8
|
+
/** Every page of the running browser, launch page included. */
|
|
9
|
+
pages(): unknown[];
|
|
10
|
+
/** The main browser process id recorded at start. */
|
|
11
|
+
pid(): number | undefined;
|
|
8
12
|
}
|
|
9
13
|
//# sourceMappingURL=test-hooks.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
|
}
|