chrome-relay 0.5.2 → 0.5.3
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/dist/cli.js +64 -21
- package/dist/index.js +1 -1
- package/dist/native-host.js +68 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4,15 +4,6 @@
|
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import { writeFileSync } from "fs";
|
|
6
6
|
|
|
7
|
-
// src/index.ts
|
|
8
|
-
var CHROME_RELAY_VERSION = true ? "0.5.2" : "0.0.0-dev";
|
|
9
|
-
|
|
10
|
-
// src/install/install.ts
|
|
11
|
-
import os from "os";
|
|
12
|
-
import path from "path";
|
|
13
|
-
import { chmod, mkdir, readFile, stat, writeFile } from "fs/promises";
|
|
14
|
-
import { fileURLToPath } from "url";
|
|
15
|
-
|
|
16
7
|
// ../protocol/dist/index.js
|
|
17
8
|
var NATIVE_HOST_NAME = "dev.chrome_relay.native_host";
|
|
18
9
|
var DEFAULT_HTTP_PORT = 12122;
|
|
@@ -24,8 +15,41 @@ var DEFAULT_EXTENSION_IDS = [
|
|
|
24
15
|
LEGACY_DEV_EXTENSION_ID,
|
|
25
16
|
LOCAL_UNPACKED_EXTENSION_ID
|
|
26
17
|
];
|
|
18
|
+
var RelayError = class extends Error {
|
|
19
|
+
code;
|
|
20
|
+
tool;
|
|
21
|
+
phase;
|
|
22
|
+
details;
|
|
23
|
+
retryable;
|
|
24
|
+
constructor(spec) {
|
|
25
|
+
super(spec.message);
|
|
26
|
+
this.name = "RelayError";
|
|
27
|
+
this.code = spec.code;
|
|
28
|
+
this.tool = spec.tool;
|
|
29
|
+
this.phase = spec.phase;
|
|
30
|
+
this.details = spec.details;
|
|
31
|
+
this.retryable = spec.retryable;
|
|
32
|
+
}
|
|
33
|
+
toBridgeError() {
|
|
34
|
+
return {
|
|
35
|
+
code: this.code,
|
|
36
|
+
message: this.message,
|
|
37
|
+
...this.tool ? { tool: this.tool } : {},
|
|
38
|
+
...this.phase ? { phase: this.phase } : {},
|
|
39
|
+
...this.details ? { details: this.details } : {},
|
|
40
|
+
...this.retryable !== void 0 ? { retryable: this.retryable } : {}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/index.ts
|
|
46
|
+
var CHROME_RELAY_VERSION = true ? "0.5.3" : "0.0.0-dev";
|
|
27
47
|
|
|
28
48
|
// src/install/install.ts
|
|
49
|
+
import os from "os";
|
|
50
|
+
import path from "path";
|
|
51
|
+
import { chmod, mkdir, readFile, stat, writeFile } from "fs/promises";
|
|
52
|
+
import { fileURLToPath } from "url";
|
|
29
53
|
var APP_DIR = path.join(os.homedir(), ".chrome-relay");
|
|
30
54
|
var KNOWN_EXTENSION_IDS = [
|
|
31
55
|
["Chrome Web Store", CHROME_WEB_STORE_EXTENSION_ID],
|
|
@@ -140,25 +164,30 @@ function emitNoticeOnce(notice) {
|
|
|
140
164
|
async function callToolWithMeta(name, args) {
|
|
141
165
|
const response = await fetch(`http://127.0.0.1:${DEFAULT_HTTP_PORT}/call`, {
|
|
142
166
|
method: "POST",
|
|
143
|
-
headers: {
|
|
144
|
-
"content-type": "application/json"
|
|
145
|
-
},
|
|
167
|
+
headers: { "content-type": "application/json" },
|
|
146
168
|
body: JSON.stringify({
|
|
147
169
|
name,
|
|
148
170
|
args
|
|
149
171
|
})
|
|
150
172
|
});
|
|
151
173
|
const payload = await response.json().catch(() => null);
|
|
174
|
+
const noticeString = payload?.notice ?? payload?.notices?.[0]?.message;
|
|
152
175
|
if (!response.ok) {
|
|
153
|
-
if (
|
|
154
|
-
throw
|
|
176
|
+
if (noticeString) emitNoticeOnce(noticeString);
|
|
177
|
+
throw rebuildError(payload, `Bridge request failed with ${response.status}`);
|
|
155
178
|
}
|
|
156
179
|
if (!payload?.ok) {
|
|
157
|
-
if (
|
|
158
|
-
throw
|
|
180
|
+
if (noticeString) emitNoticeOnce(noticeString);
|
|
181
|
+
throw rebuildError(payload, "Bridge call failed.");
|
|
159
182
|
}
|
|
160
|
-
if (
|
|
161
|
-
return { data: payload.data, notice: payload.notice };
|
|
183
|
+
if (noticeString) emitNoticeOnce(noticeString);
|
|
184
|
+
return { data: payload.data, notice: payload.notice, notices: payload.notices };
|
|
185
|
+
}
|
|
186
|
+
function rebuildError(payload, fallbackMessage) {
|
|
187
|
+
if (payload?.errorDetails) {
|
|
188
|
+
return new RelayError(payload.errorDetails);
|
|
189
|
+
}
|
|
190
|
+
return new Error(payload?.error || fallbackMessage);
|
|
162
191
|
}
|
|
163
192
|
async function callTool(name, args) {
|
|
164
193
|
const { data } = await callToolWithMeta(name, args);
|
|
@@ -167,6 +196,15 @@ async function callTool(name, args) {
|
|
|
167
196
|
|
|
168
197
|
// src/release-notes.ts
|
|
169
198
|
var RELEASE_NOTES = {
|
|
199
|
+
"0.5.3": [
|
|
200
|
+
"Structured errors and notices (code-quality-hardening PR 1). New `BridgeError` and `BridgeNotice` types in @chrome-relay/protocol carry a code, tool, phase, and details \u2014 agents can branch on `errorDetails.code === 'invalid_arguments'` instead of regex-matching message strings.",
|
|
201
|
+
"Tool result JSON now carries BOTH the legacy fields (`error: string`, `notice: string`) AND the new structured fields (`errorDetails: BridgeError`, `notices: BridgeNotice[]`). Old consumers keep working; new consumers prefer the structured shape.",
|
|
202
|
+
"The cli-outdated notice is now a `BridgeNotice` with `code:'cli_outdated'`, `details.currentVersion`, `details.expectedVersion`, and an `action.command` field.",
|
|
203
|
+
"Every strict parser (PR 0 strict enums) now throws `RelayError` with `code:'invalid_arguments'`, the offending tool, the phase that failed, and the list of valid choices.",
|
|
204
|
+
"All action-validator throws (chrome_console, chrome_network, chrome_viewport, chrome_workspace, chrome_group, chrome_screencast) carry the same structured shape.",
|
|
205
|
+
"Unknown tool dispatch now returns `code:'unsupported_tool'`.",
|
|
206
|
+
"CLI: when a RelayError flows back, stderr prints the human message AND a `relayError` JSON object so agents can parse the structured details from stderr without needing a separate flag."
|
|
207
|
+
],
|
|
170
208
|
"0.5.2": [
|
|
171
209
|
"Strict input parsers (code-quality-hardening PR 0). Invalid console levels, network status filters, tab-group colors, and tab-id lists now throw instead of being silently dropped \u2014 an agent that asks for `errors` (typo of `error`) gets a precise error rather than all levels back.",
|
|
172
210
|
"Affected tools: chrome_console (levels), chrome_network (status), chrome_group (color, tabIds), chrome_screencast (format, action), chrome_network (action).",
|
|
@@ -280,9 +318,14 @@ Notes:
|
|
|
280
318
|
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
281
319
|
}
|
|
282
320
|
} catch (error) {
|
|
283
|
-
|
|
284
|
-
(error
|
|
285
|
-
|
|
321
|
+
if (error instanceof RelayError) {
|
|
322
|
+
process.stderr.write(error.message + "\n");
|
|
323
|
+
process.stderr.write(JSON.stringify({ relayError: error.toBridgeError() }, null, 2) + "\n");
|
|
324
|
+
} else {
|
|
325
|
+
process.stderr.write(
|
|
326
|
+
(error instanceof Error ? error.message : String(error)) + "\n"
|
|
327
|
+
);
|
|
328
|
+
}
|
|
286
329
|
process.exit(1);
|
|
287
330
|
}
|
|
288
331
|
}
|
package/dist/index.js
CHANGED
package/dist/native-host.js
CHANGED
|
@@ -8,9 +8,47 @@ import Fastify from "fastify";
|
|
|
8
8
|
|
|
9
9
|
// ../protocol/dist/index.js
|
|
10
10
|
var DEFAULT_HTTP_PORT = 12122;
|
|
11
|
+
var RelayError = class extends Error {
|
|
12
|
+
code;
|
|
13
|
+
tool;
|
|
14
|
+
phase;
|
|
15
|
+
details;
|
|
16
|
+
retryable;
|
|
17
|
+
constructor(spec) {
|
|
18
|
+
super(spec.message);
|
|
19
|
+
this.name = "RelayError";
|
|
20
|
+
this.code = spec.code;
|
|
21
|
+
this.tool = spec.tool;
|
|
22
|
+
this.phase = spec.phase;
|
|
23
|
+
this.details = spec.details;
|
|
24
|
+
this.retryable = spec.retryable;
|
|
25
|
+
}
|
|
26
|
+
toBridgeError() {
|
|
27
|
+
return {
|
|
28
|
+
code: this.code,
|
|
29
|
+
message: this.message,
|
|
30
|
+
...this.tool ? { tool: this.tool } : {},
|
|
31
|
+
...this.phase ? { phase: this.phase } : {},
|
|
32
|
+
...this.details ? { details: this.details } : {},
|
|
33
|
+
...this.retryable !== void 0 ? { retryable: this.retryable } : {}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function toBridgeError(unknownErr, fallbackTool) {
|
|
38
|
+
if (unknownErr instanceof RelayError) {
|
|
39
|
+
const e = unknownErr.toBridgeError();
|
|
40
|
+
return fallbackTool && !e.tool ? { ...e, tool: fallbackTool } : e;
|
|
41
|
+
}
|
|
42
|
+
const message = unknownErr instanceof Error ? unknownErr.message : String(unknownErr);
|
|
43
|
+
return {
|
|
44
|
+
code: "internal_error",
|
|
45
|
+
message,
|
|
46
|
+
...fallbackTool ? { tool: fallbackTool } : {}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
11
49
|
|
|
12
50
|
// src/index.ts
|
|
13
|
-
var CHROME_RELAY_VERSION = true ? "0.5.
|
|
51
|
+
var CHROME_RELAY_VERSION = true ? "0.5.3" : "0.0.0-dev";
|
|
14
52
|
|
|
15
53
|
// src/release-notes.ts
|
|
16
54
|
function compareSemver(a, b) {
|
|
@@ -30,7 +68,20 @@ function buildOutdatedNotice(bridge2) {
|
|
|
30
68
|
const extVersion = bridge2.getExtensionVersion();
|
|
31
69
|
if (!extVersion) return void 0;
|
|
32
70
|
if (compareSemver(CHROME_RELAY_VERSION, extVersion) >= 0) return void 0;
|
|
33
|
-
return
|
|
71
|
+
return {
|
|
72
|
+
code: "cli_outdated",
|
|
73
|
+
message: `cli-outdated: ${CHROME_RELAY_VERSION} < extension ${extVersion}; run \`chrome-relay update\``,
|
|
74
|
+
details: {
|
|
75
|
+
currentVersion: CHROME_RELAY_VERSION,
|
|
76
|
+
expectedVersion: extVersion
|
|
77
|
+
},
|
|
78
|
+
action: { command: "chrome-relay update" }
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function attachNotices(payload, notice) {
|
|
82
|
+
if (!notice) return;
|
|
83
|
+
payload.notice = notice.message;
|
|
84
|
+
payload.notices = [notice];
|
|
34
85
|
}
|
|
35
86
|
var RelayHttpServer = class {
|
|
36
87
|
constructor(bridge2, port = DEFAULT_HTTP_PORT) {
|
|
@@ -63,15 +114,19 @@ var RelayHttpServer = class {
|
|
|
63
114
|
body.args ?? {}
|
|
64
115
|
);
|
|
65
116
|
const notice = buildOutdatedNotice(this.bridge);
|
|
66
|
-
|
|
117
|
+
const payload = { ok: true, data };
|
|
118
|
+
attachNotices(payload, notice);
|
|
119
|
+
reply.send(payload);
|
|
67
120
|
} catch (error) {
|
|
68
121
|
const notice = buildOutdatedNotice(this.bridge);
|
|
69
|
-
const
|
|
122
|
+
const errorDetails = error instanceof RelayError ? error.toBridgeError() : toBridgeError(error, body.name);
|
|
123
|
+
const payload = {
|
|
70
124
|
ok: false,
|
|
71
|
-
error:
|
|
125
|
+
error: errorDetails.message,
|
|
126
|
+
errorDetails
|
|
72
127
|
};
|
|
73
|
-
|
|
74
|
-
reply.code(500).send(
|
|
128
|
+
attachNotices(payload, notice);
|
|
129
|
+
reply.code(500).send(payload);
|
|
75
130
|
}
|
|
76
131
|
});
|
|
77
132
|
await this.app.listen({ port: this.port, host: "127.0.0.1" });
|
|
@@ -135,7 +190,12 @@ var ExtensionBridge = class {
|
|
|
135
190
|
pending.resolve(message.payload.data);
|
|
136
191
|
return;
|
|
137
192
|
}
|
|
138
|
-
|
|
193
|
+
const details = message.payload.errorDetails;
|
|
194
|
+
if (details) {
|
|
195
|
+
pending.reject(new RelayError(details));
|
|
196
|
+
} else {
|
|
197
|
+
pending.reject(new Error(message.payload.error));
|
|
198
|
+
}
|
|
139
199
|
}
|
|
140
200
|
async waitUntilReady(timeoutMs = 15e3) {
|
|
141
201
|
if (this.ready) {
|