@dsh-workbench/adapter-supply 1.5.5-rc.0 → 1.5.6

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.
@@ -57,6 +57,7 @@ export interface PluginCatalogOptions {
57
57
  readonly timeoutMs?: number;
58
58
  }
59
59
  export declare function parsePluginRows(stdout: string): PluginRow[] | undefined;
60
+ export declare function parseSiteCommands(stdout: string, site: string): CommandRow[] | undefined;
60
61
  export declare function parseCommandRows(stdout: string): CommandRow[] | undefined;
61
62
  export declare function attributeCommands(plugins: readonly PluginRow[], rows: readonly CommandRow[]): {
62
63
  readonly sets: PluginCommandSet[];
@@ -1,39 +1,53 @@
1
- import { OPENCLI_TIMEOUT_MS, now, productWrite } from '@dsh-workbench/shared/host';
1
+ import { OPENCLI_TIMEOUT_MS, now, productWrite, quoteShellArgFor, text, texts, } from '@dsh-workbench/shared/host';
2
2
  import { opencliResultOf } from '@dsh-workbench/adapter-runtime';
3
3
  function recordOf(value) {
4
4
  return typeof value === 'object' && value !== null ? value : undefined;
5
5
  }
6
- function textOf(value) {
7
- return typeof value === 'string' ? value : '';
8
- }
9
- function stringsOf(value) {
10
- return Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [];
11
- }
12
- function argsOf(raw) {
6
+ function argsOf(raw, positionalAs) {
13
7
  if (!Array.isArray(raw))
14
8
  return [];
15
9
  return raw.flatMap((item) => {
16
10
  const record = recordOf(item);
17
11
  if (record === undefined)
18
12
  return [];
19
- const name = textOf(record['name']).trim();
13
+ const name = text(record['name']).trim();
20
14
  if (name === '')
21
15
  return [];
22
16
  const fallback = record['default'];
17
+ const positional = positionalAs ?? record['positional'] === true;
23
18
  return [
24
19
  {
25
20
  name,
26
- type: textOf(record['type']) || 'string',
21
+ type: text(record['type']) || 'string',
27
22
  required: record['required'] === true,
28
- positional: record['positional'] === true,
29
- valueRequired: record['valueRequired'] === true,
30
- choices: stringsOf(record['choices']),
23
+ positional,
24
+ valueRequired: positional || record['valueRequired'] === true,
25
+ choices: texts(record['choices']),
31
26
  ...(fallback === undefined || fallback === null ? {} : { defaultValue: fallback }),
32
- help: textOf(record['help']),
27
+ help: text(record['help']),
33
28
  },
34
29
  ];
35
30
  });
36
31
  }
32
+ function commandRowOf(record, site) {
33
+ const name = text(record['name']).trim();
34
+ if (site === '' || name === '')
35
+ return undefined;
36
+ return {
37
+ site,
38
+ name,
39
+ description: text(record['description']),
40
+ access: text(record['access']),
41
+ browser: record['browser'] === true,
42
+ siteSession: text(record['siteSession']),
43
+ ...(text(record['domain']) === '' ? {} : { domain: text(record['domain']) }),
44
+ args: [
45
+ ...argsOf(record['args']),
46
+ ...argsOf(record['command_options']),
47
+ ...argsOf(record['positionals'], true),
48
+ ],
49
+ };
50
+ }
37
51
  function rowsOf(parsed) {
38
52
  if (Array.isArray(parsed))
39
53
  return parsed;
@@ -70,29 +84,23 @@ function pickRows(stdout, pick) {
70
84
  }
71
85
  export function parsePluginRows(stdout) {
72
86
  return pickRows(stdout, (record) => {
73
- const name = textOf(record['name']).trim();
87
+ const name = text(record['name']).trim();
74
88
  if (name === '')
75
89
  return undefined;
76
- return { name, version: textOf(record['version']), commands: stringsOf(record['commands']) };
90
+ return { name, version: text(record['version']), commands: texts(record['commands']) };
77
91
  });
78
92
  }
93
+ export function parseSiteCommands(stdout, site) {
94
+ return pickRows(stdout, (record) => commandRowOf(record, site));
95
+ }
96
+ function indexedRowsOf(stdout) {
97
+ const records = recordsOf(stdout);
98
+ return (records !== undefined &&
99
+ records.length > 0 &&
100
+ records.every((record) => text(record['command']).trim() !== ''));
101
+ }
79
102
  export function parseCommandRows(stdout) {
80
- return pickRows(stdout, (record) => {
81
- const site = textOf(record['site']).trim();
82
- const name = textOf(record['name']).trim();
83
- if (site === '' || name === '')
84
- return undefined;
85
- return {
86
- site,
87
- name,
88
- description: textOf(record['description']),
89
- access: textOf(record['access']),
90
- browser: record['browser'] === true,
91
- siteSession: textOf(record['siteSession']),
92
- ...(textOf(record['domain']) === '' ? {} : { domain: textOf(record['domain']) }),
93
- args: argsOf(record['args']),
94
- };
95
- });
103
+ return pickRows(stdout, (record) => commandRowOf(record, text(record['site']).trim()));
96
104
  }
97
105
  function commandOf(plugin, row) {
98
106
  return {
@@ -182,6 +190,24 @@ export function createPluginCatalog(options) {
182
190
  current = { ok: false, at: now(), sets: current.sets, problems: [problem] };
183
191
  return current;
184
192
  }
193
+ async function siteRowsOf(plugins, problems) {
194
+ const rows = [];
195
+ for (const plugin of plugins) {
196
+ const line = `${options.command} ${quoteShellArgFor(plugin.name)} --help -f json`;
197
+ const run = await read(line);
198
+ if (!run.ok) {
199
+ problems.push(`「${plugin.name}」的站点说明没读出来(${run.problem})—— 它这次不合成工具`);
200
+ continue;
201
+ }
202
+ const parsed = parseSiteCommands(run.stdout, plugin.name);
203
+ if (parsed === undefined) {
204
+ problems.push(`「${plugin.name}」的站点说明读不懂(不是带 name 的 commands)—— 它这次不合成工具`);
205
+ continue;
206
+ }
207
+ rows.push(...parsed);
208
+ }
209
+ return rows;
210
+ }
185
211
  async function refresh(callOptions = {}) {
186
212
  const pluginsRun = await read(`${options.command} plugin list -f json`);
187
213
  if (!pluginsRun.ok)
@@ -198,13 +224,17 @@ export function createPluginCatalog(options) {
198
224
  const commandsRun = await read(`${options.command} list -f json`);
199
225
  if (!commandsRun.ok)
200
226
  return fail(commandsRun.problem);
201
- const rows = parseCommandRows(commandsRun.stdout);
202
- if (rows === undefined) {
203
- return fail('opencli list -f json 的输出读不懂(不是带 site / name 的 JSON 数组)');
227
+ const direct = parseCommandRows(commandsRun.stdout);
228
+ const indexed = direct === undefined && indexedRowsOf(commandsRun.stdout);
229
+ if (direct === undefined && !indexed) {
230
+ return fail('opencli list -f json 的输出读不懂(既不是带 site / name 的命令,也不是带 command 的索引)');
204
231
  }
232
+ const siteProblems = [];
233
+ const rows = direct ?? (await siteRowsOf(plugins, siteProblems));
205
234
  const attributed = attributeCommands(plugins, rows);
206
- heavy = { fingerprint, sets: attributed.sets, problems: attributed.problems };
207
- current = { ok: true, at: now(), sets: attributed.sets, problems: attributed.problems };
235
+ const problems = [...siteProblems, ...attributed.problems];
236
+ heavy = { fingerprint, sets: attributed.sets, problems };
237
+ current = { ok: true, at: now(), sets: attributed.sets, problems };
208
238
  return current;
209
239
  }
210
240
  return { refresh, snapshot: () => current };
@@ -97,6 +97,7 @@ function faceOf(unit, opencliFor, note) {
97
97
  const byTool = new Map(unit.tools.map((tool) => [tool.name, tool.command]));
98
98
  const manifest = {
99
99
  id: unit.id,
100
+ skillId: unit.plugin,
100
101
  title: { zh: unit.plugin, en: unit.plugin },
101
102
  titleKey: unitTitleKey(unit.id),
102
103
  card: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/adapter-supply",
3
- "version": "1.5.5-rc.0",
3
+ "version": "1.5.6",
4
4
  "description": "Workbench supply adapter package.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -22,8 +22,8 @@
22
22
  "directory": "packages/adapter-supply"
23
23
  },
24
24
  "dependencies": {
25
- "@dsh-workbench/shared": "1.5.5-rc.0",
26
- "@dsh-workbench/adapter-runtime": "1.5.5-rc.0"
25
+ "@dsh-workbench/adapter-runtime": "1.5.6",
26
+ "@dsh-workbench/shared": "1.5.6"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^24.19.0",