@xiaohhhh1/canvas-agent 0.4.0 → 0.4.1
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/server/http.js +3 -2
- package/dist/utils/windows.d.ts +5 -0
- package/dist/utils/windows.js +14 -0
- package/dist/workflow/manager.js +2 -1
- package/package.json +2 -2
package/dist/server/http.js
CHANGED
|
@@ -8,6 +8,7 @@ import { CanvasSession } from "../canvas/session.js";
|
|
|
8
8
|
import { DEFAULT_PORT, ensureSiteWorkspace, loadConfig, saveConfig, updateSiteWorkspace } from "../config.js";
|
|
9
9
|
import { startRelayBridge } from "../relay-bridge.js";
|
|
10
10
|
import { logger } from "../utils/logger.js";
|
|
11
|
+
import { windowsRootExecutable, windowsSystemExecutable } from "../utils/windows.js";
|
|
11
12
|
import { WorkflowManager } from "../workflow/manager.js";
|
|
12
13
|
/** 启动仅监听本机的 Canvas Agent HTTP 服务。 */
|
|
13
14
|
export function startHttpServer() {
|
|
@@ -284,7 +285,7 @@ function permissionMode(value) {
|
|
|
284
285
|
}
|
|
285
286
|
/** 使用当前操作系统的文件管理器定位本地文件。 */
|
|
286
287
|
function revealLocalFile(filePath, isDirectory) {
|
|
287
|
-
const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "explorer.exe" : "xdg-open";
|
|
288
|
+
const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? windowsRootExecutable("explorer.exe") : "xdg-open";
|
|
288
289
|
const args = process.platform === "darwin"
|
|
289
290
|
? ["-R", filePath]
|
|
290
291
|
: process.platform === "win32"
|
|
@@ -301,7 +302,7 @@ function revealLocalFile(filePath, isDirectory) {
|
|
|
301
302
|
}
|
|
302
303
|
/** 在默认浏览器打开本机已经配对的网站;URL 内的连接参数会被网页立即移除。 */
|
|
303
304
|
function openExternalUrl(url) {
|
|
304
|
-
const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "rundll32.exe" : "xdg-open";
|
|
305
|
+
const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? windowsSystemExecutable("rundll32.exe") : "xdg-open";
|
|
305
306
|
const args = process.platform === "win32" ? ["url.dll,FileProtocolHandler", url] : [url];
|
|
306
307
|
return new Promise((resolve, reject) => {
|
|
307
308
|
const child = spawn(command, args, { detached: true, stdio: "ignore", windowsHide: true });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type WindowsEnvironment = NodeJS.ProcessEnv;
|
|
2
|
+
export declare function windowsRootExecutable(name: string, env?: WindowsEnvironment): string;
|
|
3
|
+
export declare function windowsSystemExecutable(name: string, env?: WindowsEnvironment): string;
|
|
4
|
+
export declare function windowsPowerShellExecutable(env?: WindowsEnvironment): string;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/** Resolve Windows inbox executables without relying on a possibly restricted PATH. */
|
|
3
|
+
function windowsRoot(env = process.env) {
|
|
4
|
+
return env.SystemRoot || env.SYSTEMROOT || env.WINDIR || "C:\\Windows";
|
|
5
|
+
}
|
|
6
|
+
export function windowsRootExecutable(name, env = process.env) {
|
|
7
|
+
return path.win32.join(windowsRoot(env), name);
|
|
8
|
+
}
|
|
9
|
+
export function windowsSystemExecutable(name, env = process.env) {
|
|
10
|
+
return path.win32.join(windowsRoot(env), "System32", name);
|
|
11
|
+
}
|
|
12
|
+
export function windowsPowerShellExecutable(env = process.env) {
|
|
13
|
+
return path.win32.join(windowsRoot(env), "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
14
|
+
}
|
package/dist/workflow/manager.js
CHANGED
|
@@ -8,6 +8,7 @@ import { pipeline } from "node:stream/promises";
|
|
|
8
8
|
import { runCodexTurn, startCodexThread } from "../agent/codex.js";
|
|
9
9
|
import { CONFIG_DIR, ensureSiteWorkspace } from "../config.js";
|
|
10
10
|
import { logger } from "../utils/logger.js";
|
|
11
|
+
import { windowsPowerShellExecutable } from "../utils/windows.js";
|
|
11
12
|
const STATE_FILE = path.join(CONFIG_DIR, "workflow-state.json");
|
|
12
13
|
const SCRIPT_CHUNK_SIZE = 10;
|
|
13
14
|
const DOWNLOAD_POLL_MS = 10_000;
|
|
@@ -442,7 +443,7 @@ async function isExistingFile(filePath, expectedBytes, expectedSha256 = "") {
|
|
|
442
443
|
function selectNativeDirectory() {
|
|
443
444
|
if (process.platform === "win32") {
|
|
444
445
|
const script = "$ErrorActionPreference='Stop'; Add-Type -AssemblyName System.Windows.Forms; $d=New-Object System.Windows.Forms.FolderBrowserDialog; $d.Description='选择抖音小辉跨境工具的本机视频保存位置'; $d.ShowNewFolderButton=$true; if($d.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK){[Console]::OutputEncoding=[Text.Encoding]::UTF8; Write-Output $d.SelectedPath}";
|
|
445
|
-
return commandOutput(
|
|
446
|
+
return commandOutput(windowsPowerShellExecutable(), ["-NoProfile", "-STA", "-Command", script]);
|
|
446
447
|
}
|
|
447
448
|
if (process.platform === "darwin")
|
|
448
449
|
return commandOutput("osascript", ["-e", "POSIX path of (choose folder with prompt \"选择视频保存位置\")"]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiaohhhh1/canvas-agent",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"dev": "tsx src/index.ts",
|
|
17
17
|
"debug": "tsx src/index.ts --debug",
|
|
18
|
-
"test": "tsx --test src
|
|
18
|
+
"test": "tsx --test src/**/*.test.ts",
|
|
19
19
|
"build": "tsc -p tsconfig.json",
|
|
20
20
|
"start": "node dist/index.js",
|
|
21
21
|
"prepack": "npm run build"
|