@dsh-workbench/adapter-runtime 1.1.14 → 1.1.15

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.15",
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,15 @@ 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
+ return `eval(new TextDecoder().decode(Uint8Array.from(atob('${bytes}'), (one) => one.charCodeAt(0))))`;
57
+ }
58
+ async function shellRun(seam, command, argv, timeoutMs, platform) {
58
59
  const result = await seam.run({
59
- command: backgroundLine(command, argv),
60
+ command: backgroundLine(command, argv, platform),
60
61
  intent: noWrite(),
61
62
  retry: 'safe',
62
63
  timeoutMs,
@@ -70,11 +71,11 @@ async function shellRun(seam, command, argv, timeoutMs) {
70
71
  }
71
72
  return { kind: 'ok', stdout: result.stdout };
72
73
  }
73
- async function evalOnce(seam, command, session, script, timeoutMs, retryMs) {
74
+ async function evalOnce(seam, command, session, script, timeoutMs, retryMs, platform) {
74
75
  const run = async () => {
75
76
  let attempt;
76
77
  try {
77
- attempt = await shellRun(seam, command, ['browser', session, 'eval', script, '--window', 'background'], timeoutMs);
78
+ attempt = await shellRun(seam, command, ['browser', session, 'eval', evalScriptArgOf(script, platform), '--window', 'background'], timeoutMs, platform);
78
79
  }
79
80
  catch (error) {
80
81
  return {
@@ -137,10 +138,10 @@ async function evalOnce(seam, command, session, script, timeoutMs, retryMs) {
137
138
  await sleep(retryMs);
138
139
  return run();
139
140
  }
140
- async function openOnce(seam, command, session, url, timeoutMs) {
141
+ async function openOnce(seam, command, session, url, timeoutMs, platform) {
141
142
  let attempt;
142
143
  try {
143
- attempt = await shellRun(seam, command, ['browser', session, 'open', url, '--window', 'background'], timeoutMs);
144
+ attempt = await shellRun(seam, command, ['browser', session, 'open', url, '--window', 'background'], timeoutMs, platform);
144
145
  }
145
146
  catch (error) {
146
147
  return {
@@ -170,8 +171,9 @@ export async function browserRead(options) {
170
171
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
171
172
  const retryMs = options.retryMs ?? DEFAULT_RETRY_MS;
172
173
  const settleMs = options.settleMs ?? DEFAULT_SETTLE_MS;
174
+ const platform = options.platform ?? process.platform;
173
175
  const at = now();
174
- const first = await evalOnce(seam, command, session, script, timeoutMs, retryMs);
176
+ const first = await evalOnce(seam, command, session, script, timeoutMs, retryMs, platform);
175
177
  if (first.kind === 'failure')
176
178
  return { ...first.result, at };
177
179
  let page = first.value;
@@ -187,11 +189,11 @@ export async function browserRead(options) {
187
189
  ...(url === undefined ? {} : { helpUrl: url }),
188
190
  };
189
191
  }
190
- const opened = await openOnce(seam, command, session, url, timeoutMs);
192
+ const opened = await openOnce(seam, command, session, url, timeoutMs, platform);
191
193
  if (opened !== undefined)
192
194
  return { ...opened, at };
193
195
  await sleep(settleMs);
194
- const second = await evalOnce(seam, command, session, script, timeoutMs, retryMs);
196
+ const second = await evalOnce(seam, command, session, script, timeoutMs, retryMs, platform);
195
197
  if (second.kind === 'failure')
196
198
  return { ...second.result, at };
197
199
  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.15",
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.15"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "^24.19.0",