@dsh-workbench/adapter-runtime 1.1.14 → 1.1.16

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.1.14",
3
+ "version": "1.1.16",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "description": "DSH 工作台的公共通道:带浏览器登录态的 Node 侧 fetch,只服务 cookie / cookieValue 两种凭据来源",
@@ -2,6 +2,7 @@ import { now, parseJsonLoose } from '@dsh-workbench/shared/host';
2
2
  import { BROWSER_READ_SESSION } from './browser-read.js';
3
3
  import { backgroundLine, OPENCLI_WINDOW_ENV } from '../cli/index.js';
4
4
  import { noWrite } from '@dsh-workbench/shared/host';
5
+ import { asRecord, textOf } from './page-value.js';
5
6
  const DEFAULT_TIMEOUT_MS = 25000;
6
7
  const DEFAULT_SETTLE_MS = 2500;
7
8
  const URL_TIMEOUT_MS = 8000;
@@ -26,12 +27,6 @@ export function cellRows(text) {
26
27
  .map((one) => one.trim())
27
28
  .filter((one) => one !== '');
28
29
  }
29
- function asRecord(value) {
30
- return typeof value === 'object' && value !== null ? value : undefined;
31
- }
32
- function textOf(value) {
33
- return typeof value === 'string' ? value.trim() : '';
34
- }
35
30
  export function entriesOf(value) {
36
31
  const record = asRecord(value);
37
32
  const raw = record === undefined ? undefined : record['entries'];
@@ -23,5 +23,7 @@ export interface BrowserReadOptions {
23
23
  readonly timeoutMs?: number;
24
24
  readonly retryMs?: number;
25
25
  readonly settleMs?: number;
26
+ readonly platform?: NodeJS.Platform;
26
27
  }
28
+ export declare function evalScriptArgOf(script: string, platform?: NodeJS.Platform): string;
27
29
  export declare function browserRead(options: BrowserReadOptions): Promise<BrowserReadResult>;
@@ -2,6 +2,7 @@ import { now, parseJsonLoose } from '@dsh-workbench/shared/host';
2
2
  import { tailLines } from '@dsh-workbench/shared/host';
3
3
  import { backgroundLine, OPENCLI_WINDOW_ENV } from '../cli/index.js';
4
4
  import { noWrite } from '@dsh-workbench/shared/host';
5
+ import { asRecord, textOf } from './page-value.js';
5
6
  import { BROWSER_READ_SESSION, BROWSER_RECORD_SESSION, BROWSER_SCREEN_SESSION } from '@dsh-workbench/shared/host';
6
7
  export { BROWSER_READ_SESSION, BROWSER_RECORD_SESSION, BROWSER_SCREEN_SESSION };
7
8
  const DEFAULT_TIMEOUT_MS = 25000;
@@ -17,12 +18,6 @@ const AUTH_CODES = new Set([
17
18
  'TOKEN_EXPIRED',
18
19
  ]);
19
20
  const PERMISSION_CODES = new Set(['FORBIDDEN', 'PERMISSION_DENIED', 'NO_PERMISSION', 'EACCES']);
20
- function asRecord(value) {
21
- return typeof value === 'object' && value !== null ? value : undefined;
22
- }
23
- function textOf(value) {
24
- return typeof value === 'string' ? value.trim() : '';
25
- }
26
21
  function codeOf(page) {
27
22
  const record = asRecord(page);
28
23
  return record === undefined ? '' : textOf(record['code']);
@@ -54,9 +49,16 @@ function blockerFor(code) {
54
49
  function sleep(ms) {
55
50
  return new Promise((resolve) => setTimeout(resolve, ms));
56
51
  }
57
- async function shellRun(seam, command, argv, timeoutMs) {
52
+ export function evalScriptArgOf(script, platform = process.platform) {
53
+ if (platform !== 'win32')
54
+ return script;
55
+ const bytes = Buffer.from(script, 'utf8').toString('base64');
56
+ const decoded = `eval(new TextDecoder().decode(Uint8Array.from(atob('${bytes}'), (one) => one.charCodeAt(0))))`;
57
+ return `(async () => { const value = ${decoded}; return typeof value === 'function' ? value() : value; })()`;
58
+ }
59
+ async function shellRun(seam, command, argv, timeoutMs, platform) {
58
60
  const result = await seam.run({
59
- command: backgroundLine(command, argv),
61
+ command: backgroundLine(command, argv, platform),
60
62
  intent: noWrite(),
61
63
  retry: 'safe',
62
64
  timeoutMs,
@@ -70,11 +72,11 @@ async function shellRun(seam, command, argv, timeoutMs) {
70
72
  }
71
73
  return { kind: 'ok', stdout: result.stdout };
72
74
  }
73
- async function evalOnce(seam, command, session, script, timeoutMs, retryMs) {
75
+ async function evalOnce(seam, command, session, script, timeoutMs, retryMs, platform) {
74
76
  const run = async () => {
75
77
  let attempt;
76
78
  try {
77
- attempt = await shellRun(seam, command, ['browser', session, 'eval', script, '--window', 'background'], timeoutMs);
79
+ attempt = await shellRun(seam, command, ['browser', session, 'eval', evalScriptArgOf(script, platform), '--window', 'background'], timeoutMs, platform);
78
80
  }
79
81
  catch (error) {
80
82
  return {
@@ -137,10 +139,10 @@ async function evalOnce(seam, command, session, script, timeoutMs, retryMs) {
137
139
  await sleep(retryMs);
138
140
  return run();
139
141
  }
140
- async function openOnce(seam, command, session, url, timeoutMs) {
142
+ async function openOnce(seam, command, session, url, timeoutMs, platform) {
141
143
  let attempt;
142
144
  try {
143
- attempt = await shellRun(seam, command, ['browser', session, 'open', url, '--window', 'background'], timeoutMs);
145
+ attempt = await shellRun(seam, command, ['browser', session, 'open', url, '--window', 'background'], timeoutMs, platform);
144
146
  }
145
147
  catch (error) {
146
148
  return {
@@ -170,8 +172,9 @@ export async function browserRead(options) {
170
172
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
171
173
  const retryMs = options.retryMs ?? DEFAULT_RETRY_MS;
172
174
  const settleMs = options.settleMs ?? DEFAULT_SETTLE_MS;
175
+ const platform = options.platform ?? process.platform;
173
176
  const at = now();
174
- const first = await evalOnce(seam, command, session, script, timeoutMs, retryMs);
177
+ const first = await evalOnce(seam, command, session, script, timeoutMs, retryMs, platform);
175
178
  if (first.kind === 'failure')
176
179
  return { ...first.result, at };
177
180
  let page = first.value;
@@ -187,11 +190,11 @@ export async function browserRead(options) {
187
190
  ...(url === undefined ? {} : { helpUrl: url }),
188
191
  };
189
192
  }
190
- const opened = await openOnce(seam, command, session, url, timeoutMs);
193
+ const opened = await openOnce(seam, command, session, url, timeoutMs, platform);
191
194
  if (opened !== undefined)
192
195
  return { ...opened, at };
193
196
  await sleep(settleMs);
194
- const second = await evalOnce(seam, command, session, script, timeoutMs, retryMs);
197
+ const second = await evalOnce(seam, command, session, script, timeoutMs, retryMs, platform);
195
198
  if (second.kind === 'failure')
196
199
  return { ...second.result, at };
197
200
  page = second.value;
@@ -0,0 +1,2 @@
1
+ export declare function asRecord(value: unknown): Record<string, unknown> | undefined;
2
+ export declare function textOf(value: unknown): string;
@@ -0,0 +1,6 @@
1
+ export function asRecord(value) {
2
+ return typeof value === 'object' && value !== null ? value : undefined;
3
+ }
4
+ export function textOf(value) {
5
+ return typeof value === 'string' ? value.trim() : '';
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/adapter-runtime",
3
- "version": "1.1.14",
3
+ "version": "1.1.16",
4
4
  "description": "Opencli, browser and data runtime adapters.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,7 +17,7 @@
17
17
  "bin"
18
18
  ],
19
19
  "dependencies": {
20
- "@dsh-workbench/shared": "1.1.14"
20
+ "@dsh-workbench/shared": "1.1.16"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "^24.19.0",