@dsh-workbench/adapter-runtime 1.4.0-rc.3 → 1.4.0-rc.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencli-plugin-workbench",
3
- "version": "1.4.0-rc.3",
3
+ "version": "1.4.0-rc.5",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "description": "DSH 工作台的公共通道:带浏览器登录态的 Node 侧 fetch,只服务 cookie / cookieValue 两种凭据来源",
@@ -1,5 +1,7 @@
1
1
  import { type Seam } from '@dsh-workbench/shared/host';
2
2
  import { BROWSER_READ_SESSION, BROWSER_RECORD_SESSION, BROWSER_SCREEN_SESSION } from '@dsh-workbench/shared/host';
3
+ import { evalScriptArgOf } from '@dsh-workbench/shared/host';
4
+ export { evalScriptArgOf };
3
5
  export { BROWSER_READ_SESSION, BROWSER_RECORD_SESSION, BROWSER_SCREEN_SESSION };
4
6
  export interface BrowserReadResult {
5
7
  readonly ok: boolean;
@@ -27,5 +29,4 @@ export interface BrowserReadOptions {
27
29
  readonly signal?: AbortSignal;
28
30
  readonly platform?: NodeJS.Platform;
29
31
  }
30
- export declare function evalScriptArgOf(script: string, platform?: NodeJS.Platform): string;
31
32
  export declare function browserRead(options: BrowserReadOptions): Promise<BrowserReadResult>;
@@ -5,6 +5,8 @@ import { noWrite } from '@dsh-workbench/shared/host';
5
5
  import { asRecord, textOf } from './page-value.js';
6
6
  import { BROWSER_READ_SESSION, BROWSER_RECORD_SESSION, BROWSER_SCREEN_SESSION } from '@dsh-workbench/shared/host';
7
7
  import { opencliResultOf } from '../cli/opencli-wire.js';
8
+ import { evalScriptArgOf } from '@dsh-workbench/shared/host';
9
+ export { evalScriptArgOf };
8
10
  export { BROWSER_READ_SESSION, BROWSER_RECORD_SESSION, BROWSER_SCREEN_SESSION };
9
11
  const DEFAULT_TIMEOUT_MS = 25000;
10
12
  const DEFAULT_RETRY_MS = 1200;
@@ -67,13 +69,6 @@ function sleep(ms, signal) {
67
69
  signal?.addEventListener('abort', onAbort, { once: true });
68
70
  });
69
71
  }
70
- export function evalScriptArgOf(script, platform = process.platform) {
71
- if (platform !== 'win32')
72
- return script;
73
- const bytes = Buffer.from(script, 'utf8').toString('base64');
74
- const decoded = `eval(new TextDecoder().decode(Uint8Array.from(atob('${bytes}'), (one) => one.charCodeAt(0))))`;
75
- return `(async () => { const value = ${decoded}; return typeof value === 'function' ? value() : value; })()`;
76
- }
77
72
  async function shellRun(seam, command, argv, timeoutMs, platform, signal) {
78
73
  if (signal?.aborted === true)
79
74
  return { kind: 'aborted', detail: '已停止', stderr: '' };
@@ -107,7 +102,7 @@ async function evalOnce(seam, command, session, script, timeoutMs, retryMs, retr
107
102
  result: {
108
103
  ok: false,
109
104
  code: 'cli-exec-failed',
110
- message: '读不了:后台服务起不来',
105
+ message: '无法读取:后台服务未启动',
111
106
  hint: '确认后台服务能跑起来,再重试',
112
107
  detail: error instanceof Error ? error.message : String(error),
113
108
  },
@@ -203,7 +198,7 @@ export async function browserRead(options) {
203
198
  const retryMs = options.retryMs ?? DEFAULT_RETRY_MS;
204
199
  const retry = options.retry ?? true;
205
200
  const settleMs = options.settleMs ?? DEFAULT_SETTLE_MS;
206
- const platform = options.platform ?? process.platform;
201
+ const platform = options.platform;
207
202
  const at = now();
208
203
  if (signal?.aborted === true) {
209
204
  return { ok: false, code: 'aborted', pageCode: 'aborted', at, message: '已停止' };
@@ -1,10 +1,10 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
- import { runtimeLayoutOf } from '@dsh-workbench/shared/host';
3
+ import { cmdNameOf, runtimeLayoutOf } from '@dsh-workbench/shared/host';
4
4
  import { OPENCLI_RUNTIME_ID } from '../foundation/paths.js';
5
5
  export const OPENCLI_PATH_FALLBACK = 'opencli';
6
- function binName(platform = process.platform) {
7
- return platform === 'win32' ? 'opencli.cmd' : 'opencli';
6
+ function binName(platform) {
7
+ return cmdNameOf('opencli', platform);
8
8
  }
9
9
  export function isolatedOpencliPathOf(_ctx) {
10
10
  return join(runtimeLayoutOf(OPENCLI_RUNTIME_ID).root, 'bin', binName());
@@ -1,5 +1,6 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { cmdNameOf } from '@dsh-workbench/shared/host';
3
4
  import { DEFAULT_NPM_REGISTRY, OPENCLI_CATALOG_ENV, OPENCLI_PIN, OPENCLI_PIN_ENV, OPENCLI_SUPPORTED_RANGE, OPENCLI_REGISTRY_ENV, checkVersionRange, runtimePinOf, } from '@dsh-workbench/shared/host';
4
5
  import { quoteShellArg } from '@dsh-workbench/shared/host';
5
6
  import { isolatedRoot, libsPrefix, storeDirFor, toolchainOpencliDir } from '../foundation/paths.js';
@@ -80,7 +81,7 @@ export function cliCatalogPath() {
80
81
  : override;
81
82
  }
82
83
  export function isolatedCommand() {
83
- const name = process.platform === 'win32' ? 'opencli.cmd' : 'opencli';
84
+ const name = cmdNameOf('opencli');
84
85
  return join(isolatedRoot(), 'bin', name);
85
86
  }
86
87
  export { libsPrefix } from '../foundation/paths.js';
@@ -5,7 +5,7 @@ export const OPENCLI_SITE_SESSION_ENV = {
5
5
  OPENCLI_SITE_SESSION: 'persistent',
6
6
  };
7
7
  export function backgroundLine(command, argv, options = {}) {
8
- const platform = options.platform ?? process.platform;
8
+ const platform = options.platform;
9
9
  return [
10
10
  quoteShellArgFor(command, platform),
11
11
  ...tabArgv(sessionArgv(argv, options.dialect ?? 'flag'), options.dialect ?? 'flag').map((arg) => quoteShellArgFor(arg, platform)),
@@ -8,7 +8,7 @@ import { SeamError } from '@dsh-workbench/shared/host';
8
8
  import { WorkbenchDataError } from '@dsh-workbench/shared/host';
9
9
  const FORBIDDEN_CODES = new Set(['FORBIDDEN', 'PERMISSION_DENIED']);
10
10
  const SITE_SESSION_ARGS = ['--site-session', 'persistent'];
11
- export function opencliCommandLine(command, argv, session = 'persistent', platform = process.platform) {
11
+ export function opencliCommandLine(command, argv, session = 'persistent', platform) {
12
12
  return [
13
13
  quoteShellArgFor(command, platform),
14
14
  ...argv.map((arg) => quoteShellArgFor(arg, platform)),
@@ -1,4 +1,4 @@
1
- import { BROWSER_READ_SESSIONS, BROWSER_SESSION_IDLE_MS, callsProblemOf, noWrite, now, planProblemOf, planResultsOf, recipeProblemOf, scriptOf, scriptOfMany, scriptOfPlan, allSame, } from '@dsh-workbench/shared/host';
1
+ import { BROWSER_READ_SESSIONS, BROWSER_SESSION_IDLE_MS, callsProblemOf, noWrite, now, planProblemOf, planResultsOf, recipeProblemOf, scriptOf, scriptOfMany, scriptOfPlan, allSame, scriptArgProblemOf, } from '@dsh-workbench/shared/host';
2
2
  import { opencliResultOf } from '../cli/opencli-wire.js';
3
3
  import { browserRead } from '../browser/index.js';
4
4
  import { attachOf } from './attachment.js';
@@ -11,14 +11,6 @@ import { readSessionOf, sessionOf, writeSessionOf } from './types.js';
11
11
  import { allFailure, asRecord, browserFailure, failure, pageFailure, pickOf, } from './result.js';
12
12
  import { channelCallOf, channelCommandLine, ensureChannel, } from './channel.js';
13
13
  export * from './channel-plugin.js';
14
- const MAX_WIN32_ARGV = 24_000;
15
- function scriptArgProblemOf(script) {
16
- if (typeof process === 'undefined' || process.platform !== 'win32')
17
- return undefined;
18
- if (Math.ceil(Buffer.byteLength(script, 'utf8') / 3) * 4 <= MAX_WIN32_ARGV)
19
- return undefined;
20
- return '这份计划在 Windows 上太长(脚本超过命令行上限):拆成几份计划,或把步骤写短一点';
21
- }
22
14
  export function createDataReader(options = {}) {
23
15
  const fetchOf = options.fetch ?? globalThis.fetch;
24
16
  const command = options.command ?? 'opencli';
@@ -1,13 +1,12 @@
1
1
  import { existsSync, mkdirSync, realpathSync } from 'node:fs';
2
2
  import { delimiter, dirname, join } from 'node:path';
3
- import { linkDir, removePath } from '@dsh-workbench/shared/host';
3
+ import { linkDir, pathWithBinsOf, removePath } from '@dsh-workbench/shared/host';
4
4
  import { OPENCLI_NPM_PACKAGE, libsBinDir, libsPrefix, toolchainOpencliDir, vendorPluginsDir, } from '../foundation/paths.js';
5
5
  export function ensureLibsBinOnPath(env = process.env) {
6
6
  const dir = libsBinDir();
7
- const parts = (env.PATH ?? '').split(delimiter).filter((one) => one !== '');
8
- if (parts.includes(dir))
7
+ if ((env.PATH ?? '').split(delimiter).includes(dir))
9
8
  return false;
10
- env.PATH = [dir, ...parts].join(delimiter);
9
+ env.PATH = pathWithBinsOf(env.PATH, [dir]);
11
10
  return true;
12
11
  }
13
12
  function pointsAt(link, target) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/adapter-runtime",
3
- "version": "1.4.0-rc.3",
3
+ "version": "1.4.0-rc.5",
4
4
  "description": "Opencli, browser and data runtime adapters.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "execa": "^10.2.0",
21
- "@dsh-workbench/shared": "1.4.0-rc.3"
21
+ "@dsh-workbench/shared": "1.4.0-rc.5"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "^24.19.0",