dsh-univer-office 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/artifacts/gateway.cjs +8 -2
- package/docs/architecture.md +1 -1
- package/lib/index.js +16 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -185,11 +185,11 @@ The plugin also ships eight version-matched, lazily loaded skills: core orchestr
|
|
|
185
185
|
|
|
186
186
|
## Configuration
|
|
187
187
|
|
|
188
|
-
The defaults are designed for local use: the Gateway starts on the first file-state request
|
|
188
|
+
The defaults are designed for local use: the Gateway starts on the first file-state request at `9080`. If that port is occupied, it tries `9081`, then continues upward one port at a time. Configure the bundle's Cordis layer when you need different values:
|
|
189
189
|
|
|
190
190
|
| Field | Default | Purpose |
|
|
191
191
|
| --- | --- | --- |
|
|
192
|
-
| `
|
|
192
|
+
| `gatewayPort` | `9080` | Initial loopback port for the bundled Gateway; occupied ports advance by one |
|
|
193
193
|
| `autoStartGateway` | `true` | Start the Gateway on first use |
|
|
194
194
|
| `gatewayStartupTimeoutMs` | `10000` | Gateway startup timeout |
|
|
195
195
|
| `gatewayRequestTimeoutMs` | `3000` | State-read timeout |
|
package/README.zh-CN.md
CHANGED
|
@@ -185,11 +185,11 @@ Agent 会自动选择对应 Skills 和 `univer_*` 工具。通常会依次创建
|
|
|
185
185
|
|
|
186
186
|
## 配置
|
|
187
187
|
|
|
188
|
-
默认配置适合本地使用:Gateway
|
|
188
|
+
默认配置适合本地使用:Gateway 会在首次读取文件状态时从端口 `9080` 启动;若该端口被占用,则依次尝试 `9081`、`9082`。如需定制,可在 bundle 的 Cordis 配置层设置:
|
|
189
189
|
|
|
190
190
|
| 字段 | 默认值 | 说明 |
|
|
191
191
|
| --- | --- | --- |
|
|
192
|
-
| `
|
|
192
|
+
| `gatewayPort` | `9080` | 内置 Gateway 的起始本地端口;被占用时逐次加一 |
|
|
193
193
|
| `autoStartGateway` | `true` | 首次访问时自动启动 Gateway |
|
|
194
194
|
| `gatewayStartupTimeoutMs` | `10000` | Gateway 启动超时 |
|
|
195
195
|
| `gatewayRequestTimeoutMs` | `3000` | 状态读取超时 |
|
package/artifacts/gateway.cjs
CHANGED
|
@@ -315378,6 +315378,9 @@ var init_zh_latn_pinyin_BdYb_Ey = __esm({
|
|
|
315378
315378
|
// src/gateway-app/gateway-entry.ts
|
|
315379
315379
|
var import_node_process = __toESM(require("node:process"), 1);
|
|
315380
315380
|
|
|
315381
|
+
// src/shared/gateway-process-protocol.ts
|
|
315382
|
+
var GATEWAY_PORT_IN_USE_EXIT_CODE = 98;
|
|
315383
|
+
|
|
315381
315384
|
// src/gateway-app/server.ts
|
|
315382
315385
|
var import_promises = require("node:fs/promises");
|
|
315383
315386
|
var import_node_http = __toESM(require("node:http"), 1);
|
|
@@ -443397,7 +443400,7 @@ function listen(server, port) {
|
|
|
443397
443400
|
|
|
443398
443401
|
// src/gateway-app/gateway-entry.ts
|
|
443399
443402
|
async function main() {
|
|
443400
|
-
const port = Number(import_node_process.default.env.UNIVER_COLLAB_GATEWAY_PORT ??
|
|
443403
|
+
const port = Number(import_node_process.default.env.UNIVER_COLLAB_GATEWAY_PORT ?? 9080);
|
|
443401
443404
|
const viewAssetsRoot = import_node_process.default.env.UNIVER_VIEW_ASSETS_ROOT;
|
|
443402
443405
|
const allowedRoot = import_node_process.default.env.UNIVER_ALLOWED_ROOT;
|
|
443403
443406
|
const server = await startServer({
|
|
@@ -443411,5 +443414,8 @@ async function main() {
|
|
|
443411
443414
|
main().catch((error) => {
|
|
443412
443415
|
import_node_process.default.stderr.write(`[dsh-univer-gateway] failed to start: ${String(error)}
|
|
443413
443416
|
`);
|
|
443414
|
-
import_node_process.default.exitCode = 1;
|
|
443417
|
+
import_node_process.default.exitCode = isAddressInUse(error) ? GATEWAY_PORT_IN_USE_EXIT_CODE : 1;
|
|
443415
443418
|
});
|
|
443419
|
+
function isAddressInUse(error) {
|
|
443420
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "EADDRINUSE";
|
|
443421
|
+
}
|
package/docs/architecture.md
CHANGED
|
@@ -261,7 +261,7 @@ Gateway Supervisor 只负责:
|
|
|
261
261
|
|
|
262
262
|
Unit 的导入、检查、执行和导出由 Unit Content Adapter 启动一次性 Unit Content Worker。Worker 连接 Gateway Supervisor 提供的同一个 Gateway,操作完成或取消后退出,不拥有独立持久状态。Gateway 的 worktree 控制面直接提供 Unit 创建与移除端点,并通过 collaboration service 与 lifecycle event 完成操作。写操作只能针对显式 draft worktree;Gateway 是提交结果和 revision 的唯一依据。
|
|
263
263
|
|
|
264
|
-
它不得复用或终止外部启动的 Gateway
|
|
264
|
+
它不得复用或终止外部启动的 Gateway。内置 Gateway 默认从 `9080` 启动,端口被占用时逐次加一;只有结构化确认端口占用时才能继续尝试下一端口,其他启动失败必须立即返回。健康检查需要验证 Viewer 身份,不能把任意返回 HTTP 200 的本地服务误认为 Gateway。
|
|
265
265
|
|
|
266
266
|
## 8. webServer Consumer 与浏览器协议
|
|
267
267
|
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var __export = (target, all) => {
|
|
|
7
7
|
// src/host/config.ts
|
|
8
8
|
import z from "@deepseek-ai/schemastery";
|
|
9
9
|
var Config = z.object({
|
|
10
|
-
|
|
10
|
+
gatewayPort: z.natural().max(65535).default(9080),
|
|
11
11
|
autoStartGateway: z.boolean().default(true),
|
|
12
12
|
gatewayStartupTimeoutMs: z.natural().default(1e4),
|
|
13
13
|
gatewayRequestTimeoutMs: z.natural().default(3e3),
|
|
@@ -21,7 +21,7 @@ var Config = z.object({
|
|
|
21
21
|
});
|
|
22
22
|
function resolveConfig(config = {}) {
|
|
23
23
|
const resolved = {
|
|
24
|
-
|
|
24
|
+
gatewayPort: config.gatewayPort ?? 9080,
|
|
25
25
|
autoStartGateway: config.autoStartGateway ?? true,
|
|
26
26
|
gatewayStartupTimeoutMs: config.gatewayStartupTimeoutMs ?? 1e4,
|
|
27
27
|
gatewayRequestTimeoutMs: config.gatewayRequestTimeoutMs ?? 3e3,
|
|
@@ -33,11 +33,8 @@ function resolveConfig(config = {}) {
|
|
|
33
33
|
tools: config.tools ?? true,
|
|
34
34
|
skills: config.skills ?? true
|
|
35
35
|
};
|
|
36
|
-
if (resolved.
|
|
37
|
-
|
|
38
|
-
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
39
|
-
throw new Error("univer: every Gateway port must be an integer between 1 and 65535");
|
|
40
|
-
}
|
|
36
|
+
if (!Number.isInteger(resolved.gatewayPort) || resolved.gatewayPort < 1 || resolved.gatewayPort > 65535) {
|
|
37
|
+
throw new Error("univer: gatewayPort must be an integer between 1 and 65535");
|
|
41
38
|
}
|
|
42
39
|
for (const [name6, value] of Object.entries({
|
|
43
40
|
gatewayStartupTimeoutMs: resolved.gatewayStartupTimeoutMs,
|
|
@@ -589,6 +586,9 @@ function requireUniverExtension(value) {
|
|
|
589
586
|
// src/host/processes/gateway/gateway-process.ts
|
|
590
587
|
import { spawn } from "node:child_process";
|
|
591
588
|
|
|
589
|
+
// src/shared/gateway-process-protocol.ts
|
|
590
|
+
var GATEWAY_PORT_IN_USE_EXIT_CODE = 98;
|
|
591
|
+
|
|
592
592
|
// src/host/processes/gateway/launcher.ts
|
|
593
593
|
import { delimiter } from "node:path";
|
|
594
594
|
|
|
@@ -660,15 +660,20 @@ var GatewayProcess = class {
|
|
|
660
660
|
while (Date.now() - startedAt < startupTimeoutMs) {
|
|
661
661
|
if (child.exitCode !== null || child.signalCode !== null) {
|
|
662
662
|
if (this.child === child) this.child = null;
|
|
663
|
+
const portInUse = child.exitCode === GATEWAY_PORT_IN_USE_EXIT_CODE;
|
|
663
664
|
const detail = stderr.trim();
|
|
664
|
-
return {
|
|
665
|
+
return {
|
|
666
|
+
ok: false,
|
|
667
|
+
reason: portInUse ? `Gateway port ${String(port)} is already in use` : detail || `bundled Gateway exited (${String(child.signalCode ?? child.exitCode ?? "unknown")})`,
|
|
668
|
+
portInUse
|
|
669
|
+
};
|
|
665
670
|
}
|
|
666
671
|
await new Promise((resolve3) => setTimeout(resolve3, 200));
|
|
667
672
|
if (child.exitCode !== null || child.signalCode !== null) continue;
|
|
668
673
|
if (await gatewayIsHealthy(origin, probeTimeoutMs)) return { ok: true, gateway: origin, reused: false };
|
|
669
674
|
}
|
|
670
675
|
await this.stop();
|
|
671
|
-
return { ok: false, reason: `bundled Gateway did not become ready within ${String(startupTimeoutMs)}ms
|
|
676
|
+
return { ok: false, reason: `bundled Gateway did not become ready within ${String(startupTimeoutMs)}ms`, portInUse: false };
|
|
672
677
|
}
|
|
673
678
|
/** Stop only the child process this instance created. */
|
|
674
679
|
async stop() {
|
|
@@ -718,7 +723,7 @@ var GatewaySupervisor = class {
|
|
|
718
723
|
}
|
|
719
724
|
async start() {
|
|
720
725
|
let failure = "bundled Gateway did not start";
|
|
721
|
-
for (
|
|
726
|
+
for (let port = this.config.gatewayPort; port <= 65535; port += 1) {
|
|
722
727
|
const result = await this.process.start(port, this.config.gatewayStartupTimeoutMs, this.config.gatewayRequestTimeoutMs);
|
|
723
728
|
if (result.ok) {
|
|
724
729
|
this.ownedGateway = result.gateway;
|
|
@@ -726,6 +731,7 @@ var GatewaySupervisor = class {
|
|
|
726
731
|
return result;
|
|
727
732
|
}
|
|
728
733
|
failure = result.reason;
|
|
734
|
+
if (!result.portInUse) break;
|
|
729
735
|
}
|
|
730
736
|
this.lastFailure = failure;
|
|
731
737
|
return { ok: false, reason: failure };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-univer-office",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "DSH × Univer integration with a bundled collaboration Gateway and Viewer: inline previews, live floating Worktree windows, and session-end review actions in DeepSeek Harness.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|