@gaoding/cli 3.0.1 → 3.0.2

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.
Files changed (45) hide show
  1. package/README.md +4 -2
  2. package/contracts/operations/agent.send/input.schema.json +1 -1
  3. package/contracts/operations/credits.get/output.schema.json +3 -3
  4. package/contracts/operations/dam.copy/input.schema.json +3 -3
  5. package/contracts/operations/dam.copy/output.schema.json +1 -1
  6. package/contracts/operations/dam.list/output.schema.json +2 -2
  7. package/contracts/operations/dam.move/input.schema.json +3 -3
  8. package/contracts/operations/dam.search/output.schema.json +2 -2
  9. package/contracts/operations/task.get/output.schema.json +2 -2
  10. package/contracts/presentations/task.get.schema.json +2 -2
  11. package/dist/bin/gd-cli.js +1 -6
  12. package/dist/bin/insmind-cli.js +1 -6
  13. package/dist/src/bootstrap/create-cli.js +32 -19
  14. package/dist/src/bootstrap/create-runtime.js +6 -2
  15. package/dist/src/bootstrap/run-task-worker.js +6 -2
  16. package/dist/src/bootstrap/validators.js +0 -8
  17. package/dist/src/cli/agent-commands.js +3 -3
  18. package/dist/src/cli/dam-commands.js +14 -6
  19. package/dist/src/cli/errors.js +17 -6
  20. package/dist/src/cli/task-commands.js +1 -1
  21. package/dist/src/cli/update-command.js +3 -3
  22. package/dist/src/contracts/creation-input.js +0 -3
  23. package/dist/src/features/dam/file-downloader.js +19 -9
  24. package/dist/src/features/dam/operation-executor.js +2 -0
  25. package/dist/src/features/dam/use-cases.js +53 -29
  26. package/dist/src/features/skill/manual.js +37 -31
  27. package/dist/src/features/task/store.js +7 -0
  28. package/dist/src/features/task/use-cases.js +66 -10
  29. package/dist/src/features/update/check-schema.js +22 -16
  30. package/dist/src/features/update/update-notification.js +8 -4
  31. package/dist/src/features/update/update-service.js +37 -16
  32. package/dist/src/telemetry/invocation.js +8 -4
  33. package/dist/src/telemetry/process-errors.js +7 -2
  34. package/dist/src/telemetry/sanitize.js +18 -7
  35. package/dist/src/telemetry/sls-sink.js +38 -15
  36. package/package.json +7 -7
  37. package/skills/gd-cli/SKILL.md +1 -1
  38. package/dist/src/features/editor/bridge-client.js +0 -107
  39. package/dist/src/features/editor/bridge-process.js +0 -237
  40. package/dist/src/features/editor/bridge-server.js +0 -339
  41. package/dist/src/features/editor/protocol.js +0 -1
  42. package/dist/src/features/editor/public-url.js +0 -1
  43. package/dist/src/features/editor/session-state.js +0 -81
  44. package/dist/src/features/editor/session.js +0 -232
  45. package/dist/src/features/editor/use-cases.js +0 -118
@@ -25,7 +25,8 @@ export class UpdateError extends Error {
25
25
  }
26
26
  export function detectInstallSource(input) {
27
27
  const binaryPath = normalizePath(input.binaryPath);
28
- const realBinaryPath = normalizePath(input.realBinaryPath);
28
+ const realPath = input.realBinaryPath ?? safeRealpath(input.binaryPath);
29
+ const realBinaryPath = normalizePath(realPath);
29
30
  const packageRoot = normalizePath(input.packageRoot);
30
31
  const cwd = normalizePath(resolve(input.cwd));
31
32
  const userAgent = input.env.npm_config_user_agent ?? "";
@@ -35,10 +36,10 @@ export function detectInstallSource(input) {
35
36
  return unsupported("Yarn 安装不支持自动更新");
36
37
  }
37
38
  if (containsTemporaryRunner(binaryPath) || containsTemporaryRunner(packageRoot)) {
38
- return unsupported("临时运行方式不支持自动更新");
39
+ return unsupported("临时运行方式不支持自动更新", "temporary");
39
40
  }
40
41
  if (binaryPath.includes("/node_modules/.bin/")) {
41
- return unsupported("项目依赖不支持自动更新");
42
+ return unsupported("项目依赖不支持自动更新", "project");
42
43
  }
43
44
  if (!isWithin(realBinaryPath, packageRoot)) {
44
45
  return unsupported("CLI binary 与 package 不匹配");
@@ -50,7 +51,7 @@ export function detectInstallSource(input) {
50
51
  const pnpmDirectory = pnpmSnapshotDirectory(binaryPath, packageName, command);
51
52
  const pnpmLauncher = pnpmLaunchers(input.env, command).find(entry => entry.target === resolve(input.binaryPath));
52
53
  if (realBinaryPath === `${packageRoot}/dist/bin/${command}.js` && pnpmDirectory && pnpmLauncher
53
- && safeRealpath(input.binaryPath) === input.realBinaryPath
54
+ && safeRealpath(input.binaryPath) === realPath
54
55
  && packageManifestMatches(input.packageRoot, packageName)
55
56
  && (!binaryPath.includes("/5/.pnpm/") || legacyManifestMatches(pnpmDirectory, packageName))) {
56
57
  return { kind: "global", manager: "pnpm", packageRoot: input.packageRoot, directory: pnpmDirectory, launcher: pnpmLauncher.launcher };
@@ -64,8 +65,8 @@ export function detectInstallSource(input) {
64
65
  try {
65
66
  const shim = readFileSync(launcher, "utf8");
66
67
  const target = windowsShimTarget(shim);
67
- if (target && realpathSync(resolve(prefix, target)) === input.realBinaryPath
68
- && safeRealpath(input.binaryPath) === input.realBinaryPath) {
68
+ if (target && realpathSync(resolve(prefix, target)) === realPath
69
+ && safeRealpath(input.binaryPath) === realPath) {
69
70
  return { kind: "global", manager: "npm", packageRoot: input.packageRoot, directory: prefix, launcher };
70
71
  }
71
72
  }
@@ -76,15 +77,15 @@ export function detectInstallSource(input) {
76
77
  const prefix = dirname(dirname(dirname(dirname(input.packageRoot))));
77
78
  try {
78
79
  const launcher = join(prefix, "bin", command);
79
- if (lstatSync(launcher).isSymbolicLink() && realpathSync(launcher) === input.realBinaryPath
80
- && safeRealpath(input.binaryPath) === input.realBinaryPath) {
80
+ if (lstatSync(launcher).isSymbolicLink() && realpathSync(launcher) === realPath
81
+ && safeRealpath(input.binaryPath) === realPath) {
81
82
  return { kind: "global", manager: "npm", packageRoot: input.packageRoot, directory: prefix, launcher };
82
83
  }
83
84
  }
84
85
  catch { /* no matching global launcher */ }
85
86
  }
86
87
  if (packageRoot.startsWith(`${cwd}/node_modules/`))
87
- return unsupported("项目依赖不支持自动更新");
88
+ return unsupported("项目依赖不支持自动更新", "project");
88
89
  return unsupported("无法确认 npm 或 pnpm 全局安装");
89
90
  }
90
91
  function pnpmSnapshotDirectory(binaryPath, name, command) {
@@ -160,6 +161,20 @@ function pnpmLaunchers(env, command) {
160
161
  export function pnpmLauncherTargets(env, command) {
161
162
  return pnpmLaunchers(env, command).map(entry => entry.target);
162
163
  }
164
+ export function legacyQwenBridge(env) {
165
+ return env.CLI_HOST_APPLICATION === "qwenwork" && env.CLI_INVOCATION_PURPOSE !== undefined;
166
+ }
167
+ export function updateGuidance(channel, command) {
168
+ const en = command === "insmind-cli";
169
+ switch (channel) {
170
+ case "global": return en ? `Run ${command} update to update.` : `运行 ${command} update 即可更新。`;
171
+ case "project": return en ? "Update this dependency in the project that installed it." : "请在安装这项依赖的项目中更新。";
172
+ case "temporary": return en ? "Select the new version in the runner used to launch this CLI." : "请用本次的临时运行器选择新版本。";
173
+ case "unknown": return en
174
+ ? `For a user-owned global npm or pnpm installation, run ${command} update. Otherwise update through the original project, host, or temporary runner.`
175
+ : `自己用 npm 或 pnpm 全局安装的,可运行 ${command} update。其他安装请通过原项目、宿主或临时运行器更新。`;
176
+ }
177
+ }
163
178
  export function createUpdateService(options) {
164
179
  const fetchPackage = options.fetch ?? globalThis.fetch;
165
180
  const runProcess = options.runProcess ?? spawnPackageManager;
@@ -174,12 +189,15 @@ export function createUpdateService(options) {
174
189
  signal.throwIfAborted();
175
190
  const owner = options.installationOwner
176
191
  ?? readInstallationOwner(options.packageRoot);
192
+ if (owner === "user" && !insmind && legacyQwenBridge(env)) {
193
+ throw new UpdateError("UPDATE_FAILED", "这是旧版千问办公连接器的 CLI 入口。", ["请在千问办公中更新或重新安装稿定连接器。"], undefined, "UPDATE_MANAGED_BY_HOST");
194
+ }
177
195
  if (owner === "workbuddy") {
178
196
  throw new UpdateError("UPDATE_FAILED", insmind
179
197
  ? "This insMind CLI installation is managed by WorkBuddy."
180
- : "此 gd-cli 由 WorkBuddy 连接器管理。", [insmind
198
+ : "此 gd-cli 由旧版 WorkBuddy 连接器管理。", [insmind
181
199
  ? "Update the insMind connector in WorkBuddy."
182
- : "请在 WorkBuddy 中更新「稿定」连接器。"], undefined, "UPDATE_MANAGED_BY_HOST");
200
+ : "请在 WorkBuddy 中更新「稿定AI」连接器,再使用宿主提供的稿定工具。"], undefined, "UPDATE_MANAGED_BY_HOST");
183
201
  }
184
202
  if (owner === "invalid") {
185
203
  throw new UpdateError("UPDATE_FAILED", insmind
@@ -224,11 +242,14 @@ export function createUpdateService(options) {
224
242
  packageName,
225
243
  binaryName: commandName
226
244
  });
227
- const nextSteps = [insmind ? "Choose the command for your original package manager:" : "按原安装工具选择下面一条命令执行:", ...manualCommands(latest, packageName)];
228
245
  if (source.kind === "unsupported") {
229
246
  throw new UpdateError("UPDATE_FAILED", insmind
230
247
  ? "The current installation method does not support automatic updates."
231
- : `当前安装方式不支持自动更新:${source.reason}。`, nextSteps);
248
+ : `当前安装方式不支持自动更新:${source.reason}。`, [source.channel === "unknown"
249
+ ? (insmind ? "Update through the channel that provided this installation." : "请通过最初提供这份 CLI 的渠道更新。")
250
+ : updateGuidance(source.channel, commandName), insmind
251
+ ? "To install a separate global CLI, choose one of these commands:"
252
+ : "若要另行安装全局 CLI,可选择以下命令:", ...manualCommands(latest, packageName)]);
232
253
  }
233
254
  if (!gt(latest, options.currentVersion)) {
234
255
  await options.telemetry.stage("sync", async () => {
@@ -280,7 +301,7 @@ export function createUpdateService(options) {
280
301
  catch (error) {
281
302
  throw new UpdateError("UPDATE_FAILED", insmind
282
303
  ? `The package manager finished, but the ${latest} installation could not be confirmed; the installation may have changed.`
283
- : `包管理器已结束,但无法确认原安装目录已更新到 ${latest};安装状态可能已改变。`, [installNextSteps[0], insmind ? `Check the original installation and run ${commandName} --version.` : "请检查原安装目录并执行 gd-cli --version。"], error);
304
+ : `包管理器已结束,但无法确认原安装目录已更新到 ${latest};安装状态可能已改变。`, [installNextSteps[0], insmind ? `Run the original launcher at ${source.launcher} with --version.` : `请用原启动文件 ${source.launcher} 执行 --version。`], error);
284
305
  }
285
306
  const targetSkills = options.bundledSkills.map((skill) => ({
286
307
  ...skill,
@@ -367,6 +388,6 @@ function safeRealpath(path) {
367
388
  return path;
368
389
  }
369
390
  }
370
- function unsupported(reason) {
371
- return { kind: "unsupported", reason };
391
+ function unsupported(reason, channel = "unknown") {
392
+ return { kind: "unsupported", reason, channel };
372
393
  }
@@ -5,8 +5,9 @@ export function hostName(value) {
5
5
  return typeof value === "string" && value.trim() ? value.trim().slice(0, 128) : undefined;
6
6
  }
7
7
  export function hostTelemetryContext(env) {
8
+ const host = hostName(env.CLI_HOST_APPLICATION) ?? "unknown";
8
9
  return {
9
- host_application: hostName(env.CLI_HOST_APPLICATION) ?? "unknown",
10
+ host_application: host, host_application_source: host === "unknown" ? "unknown" : "environment",
10
11
  ...(["auth_status", "version_check"].includes(env.CLI_INVOCATION_PURPOSE ?? "")
11
12
  ? { invocation_purpose: env.CLI_INVOCATION_PURPOSE } : {}),
12
13
  ...(/^[a-f0-9]{32}$/u.test(env.CLI_HOST_INVOCATION_ID ?? "") ? { host_invocation_id: env.CLI_HOST_INVOCATION_ID } : {}),
@@ -39,7 +40,7 @@ export function createTelemetryInvocation(options) {
39
40
  function identity() {
40
41
  const mode = definition?.mode?.();
41
42
  const creation = mode === "execute" && (definition?.operation === "agent.send" || definition?.operation === "tool.call");
42
- return { host_application: context.host_application ?? "unknown", schema_version: "6", started_at_ms: startedAt, command_kind: creation ? "creation" : "technical", cli_name: options.cliName ?? "gd-cli",
43
+ return { host_application: context.host_application ?? "unknown", host_application_source: context.host_application_source ?? "unknown", schema_version: "6", started_at_ms: startedAt, command_kind: creation ? "creation" : "technical", cli_name: options.cliName ?? "gd-cli",
43
44
  env: options.env ?? "production", process_role: options.processRole ?? "cli",
44
45
  trace_id: traceId,
45
46
  operation: definition?.operation ?? "unknown", ...(mode ? { mode } : {}),
@@ -123,8 +124,11 @@ export function createTelemetryInvocation(options) {
123
124
  await publish(remember({ ...base(), occurred_at_ms: startedAt, event_name: "command_step", step: "issued", outcome: "success" }));
124
125
  },
125
126
  observeHost(value) {
126
- if (!context.host_application || context.host_application === "unknown")
127
- context.host_application = hostName(value) ?? "unknown";
127
+ const host = hostName(value);
128
+ if (host && host !== "unknown" && (!context.host_application || context.host_application === "unknown")) {
129
+ context.host_application = host;
130
+ context.host_application_source = "input";
131
+ }
128
132
  },
129
133
  useSignal(next) { signal = next; },
130
134
  annotate(annotation) {
@@ -8,8 +8,13 @@ import { gaodingProduct, insmindProduct } from "../product/config.js";
8
8
  import { createTelemetryInvocation, hostTelemetryContext } from "./invocation.js";
9
9
  import { createSlsTelemetrySink } from "./sls-sink.js";
10
10
  // The normal runtime or even Commander may be unavailable. Only package-owned names may enter SLS.
11
- async function bootstrapDefinition(argv) {
11
+ async function bootstrapDefinition(argv, product) {
12
12
  try {
13
+ if (argv.includes("--skill")) {
14
+ const { skillManualArguments } = await import("../features/skill/manual.js");
15
+ if (skillManualArguments(argv, product))
16
+ return { operation: "skill", mode: () => "help" };
17
+ }
13
18
  const [{ identifyInvocation }, catalog] = await Promise.all([
14
19
  import("./command-route.js"), readFile(new URL("./command-routes.json", import.meta.url), "utf8")
15
20
  ]);
@@ -48,7 +53,7 @@ export async function reportProcessError(error, options) {
48
53
  traceIdFactory: () => options.traceId ?? randomBytes(16).toString("hex"), spanIdFactory: () => randomBytes(8).toString("hex"),
49
54
  runtime: { os: process.platform, arch: process.arch, nodeMajor: Number(process.versions.node.split(".")[0]) },
50
55
  classifyError: () => classification });
51
- const definition = options.argv ? await bootstrapDefinition(options.argv) : { operation: options.operation };
56
+ const definition = options.argv ? await bootstrapDefinition(options.argv, product.commandName) : { operation: options.operation };
52
57
  telemetry.select(definition);
53
58
  telemetry.annotate(hostTelemetryContext(process.env));
54
59
  if ((options.processRole ?? "cli") === "cli")
@@ -4,25 +4,26 @@ const ids = new Set(["account_id", "organization_id", "cli_task_id", "task_id",
4
4
  function sensitive(key) {
5
5
  return isSensitiveKey(key) || /(?:token|secret)$/iu.test(key) || /^(?:x[-_]?)?(?:bridge[-_]?token|signature|access[-_]?key|cookie|authorization)$/iu.test(key);
6
6
  }
7
- export function cleanText(value) {
7
+ export function cleanText(value, omitUrlPath = false) {
8
8
  try {
9
9
  const parsed = JSON.parse(value);
10
10
  if (parsed !== null && typeof parsed === "object")
11
11
  return JSON.stringify(cleanDiagnostic(parsed));
12
12
  }
13
13
  catch { /* Most messages are prose, not JSON. */ }
14
- return redactSensitiveText(value.replace(/https?:\/\/[^\s<>"`\]\)]+/gu, raw => {
14
+ return redactSensitiveText(value.replace(/https?:\/\/[^\s<>"`]+/giu, raw => {
15
15
  try {
16
16
  const url = new URL(raw);
17
+ if (omitUrlPath)
18
+ return url.origin;
17
19
  url.username = "";
18
20
  url.password = "";
19
- for (const key of [...url.searchParams.keys()])
20
- if (sensitive(key))
21
- url.searchParams.set(key, "[REDACTED]");
21
+ url.search = "";
22
+ url.hash = "";
22
23
  return url.href;
23
24
  }
24
25
  catch {
25
- return raw;
26
+ return "[Invalid URL]";
26
27
  }
27
28
  })).replace(/\b(?:Bearer\s+)[^\s,;"']+/giu, "Bearer [REDACTED]")
28
29
  .replace(/("(?:[^"\s]*token|[^"\s]*secret|(?:x[-_]?)?access[-_]?key(?:[-_]?id)?|authorization|cookie|signature|ak|sk)"\s*:\s*)"[^"\r\n]*"/giu, '$1"[REDACTED]"');
@@ -34,12 +35,22 @@ export function cleanDiagnostic(value) {
34
35
  const toolDiagnostic = (tool || (envelope.operation === "task.get" && ["dify", "toolkit", "sync"].includes(String(envelope.execution_protocol)))) && envelope.event_name === "stage_finished";
35
36
  function clean(item, depth, inParameters = false) {
36
37
  if (typeof item === "string" && inParameters) {
38
+ // Some adapters store nested arguments as JSON text. Keep the surrounding
39
+ // Tool context when redacting those fields, and retain the wire type.
40
+ if (/^\s*[\[{]/u.test(item)) {
41
+ if (depth > 20)
42
+ return "[Truncated]";
43
+ try {
44
+ return JSON.stringify(clean(JSON.parse(item), depth + 1, true));
45
+ }
46
+ catch { /* Ordinary parameter text may start with a bracket. */ }
47
+ }
37
48
  if (posix.isAbsolute(item) || win32.isAbsolute(item) || /^file:\/\//iu.test(item))
38
49
  return "[Local file]";
39
50
  item = item.replace(/file:\/\/[^\s<>"`]+/giu, "[Local file]");
40
51
  }
41
52
  if (typeof item === "string")
42
- return /^data:[^,]*;base64,/iu.test(item) ? "[Binary omitted]" : cleanText(item);
53
+ return /^data:[^,]*;base64,/iu.test(item) ? "[Binary omitted]" : cleanText(item, inParameters);
43
54
  if (typeof item === "bigint")
44
55
  return String(item);
45
56
  if (item === null || typeof item !== "object")
@@ -16,7 +16,31 @@ export function eventKey(event) {
16
16
  return createHash("sha256").update(JSON.stringify(key)).digest("hex");
17
17
  }
18
18
  export function wireEvent(event) {
19
- const safe = cleanDiagnostic(event);
19
+ const fields = { ...event };
20
+ const agent = fields.operation === "agent.send" || (fields.operation === "task.get" && !fields.execution_protocol);
21
+ if (fields.event_name === "stage_finished" && agent && Number(fields.http_status) >= 400)
22
+ delete fields.remote_error_body;
23
+ // Old queues store structured fields as JSON strings. Keep their event context
24
+ // when applying current rules for Tool prompts and failure evidence.
25
+ for (const key of ["parameters", "diagnostic_summary"]) {
26
+ const value = fields[key];
27
+ if (typeof value !== "string")
28
+ continue;
29
+ try {
30
+ fields[key] = JSON.parse(value);
31
+ }
32
+ catch {
33
+ delete fields[key];
34
+ }
35
+ }
36
+ const parameters = fields.parameters;
37
+ if (parameters !== undefined && (typeof parameters !== "object" || parameters === null || Array.isArray(parameters))) {
38
+ delete fields.parameters;
39
+ }
40
+ else if (typeof parameters === "object" && parameters && "truncated" in parameters && parameters.truncated === true && "preview" in parameters) {
41
+ fields.parameters = { truncated: true };
42
+ }
43
+ const safe = cleanDiagnostic(fields);
20
44
  if ("diagnostic_summary" in safe) {
21
45
  const summary = safeFailureSummary(safe.diagnostic_summary);
22
46
  if (summary)
@@ -24,9 +48,9 @@ export function wireEvent(event) {
24
48
  else
25
49
  delete safe.diagnostic_summary;
26
50
  }
27
- const wire = { event_id: eventKey(safe) };
51
+ const wire = { event_id: eventKey(event) };
28
52
  for (const [key, value] of Object.entries(safe)) {
29
- if (value !== undefined)
53
+ if (key !== "event_id" && value !== undefined)
30
54
  wire[key] = typeof value === "object" ? JSON.stringify(value) : String(value);
31
55
  }
32
56
  for (const key of ["error_stack", "remote_error_body", "error_message"]) {
@@ -36,7 +60,7 @@ export function wireEvent(event) {
36
60
  }
37
61
  }
38
62
  if (wire.parameters && Buffer.byteLength(wire.parameters) > 32 * 1024) {
39
- wire.parameters = JSON.stringify({ truncated: true, preview: utf8Prefix(wire.parameters, 8 * 1024) });
63
+ wire.parameters = JSON.stringify({ truncated: true });
40
64
  wire.truncated = "true";
41
65
  }
42
66
  if (Buffer.byteLength(JSON.stringify(wire)) > 64 * 1024) {
@@ -135,24 +159,23 @@ export function createSlsTelemetrySink(options) {
135
159
  }
136
160
  return;
137
161
  }
162
+ let entry;
138
163
  try {
139
- const entry = JSON.parse(raw);
164
+ entry = JSON.parse(raw);
140
165
  if (entry.event?.schema_version !== "6" || !Number.isFinite(entry.queuedAt) || eventKey(entry.event) !== name.slice(0, -5))
141
166
  throw new Error();
142
- // Earlier v6 clients could queue input parameters and echoed Agent HTTP errors.
143
- const event = entry.event;
144
- if (event.event_name === "stage_finished") {
145
- delete event.parameters;
146
- const agent = event.operation === "agent.send" || (event.operation === "task.get" && !event.execution_protocol);
147
- if (agent && Number(event.http_status) >= 400)
148
- delete event.remote_error_body;
149
- }
150
- entries.set(name.slice(0, -5), entry);
167
+ entry.event = wireEvent(entry.event);
151
168
  }
152
169
  catch {
153
170
  await unlink(join(directory, name)).catch(() => undefined);
154
171
  await dropped("corrupt", 1);
172
+ return;
155
173
  }
174
+ const id = name.slice(0, -5);
175
+ if (JSON.stringify(entry) !== raw)
176
+ await persist(id, entry);
177
+ else
178
+ entries.set(id, entry);
156
179
  }
157
180
  async function saveStatus() {
158
181
  // Health recording must never stop the original event acknowledgement/backoff path.
@@ -204,7 +227,7 @@ export function createSlsTelemetrySink(options) {
204
227
  const id = eventKey(event);
205
228
  if (entries.has(id))
206
229
  continue;
207
- // Persist the sanitized, bounded wire payload and replay it unchanged.
230
+ // Persist only the sanitized, bounded payload.
208
231
  await persist(id, { event: wireEvent(event), queuedAt: now(), nextAttempt: 0, attempts: 0 });
209
232
  }
210
233
  await trim(deadline);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaoding/cli",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Gaoding command-line interface for agents and people.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "tag": "latest"
11
11
  },
12
12
  "engines": {
13
- "node": ">=20.0.0"
13
+ "node": ">=20.10.0"
14
14
  },
15
15
  "bin": {
16
16
  "gd-cli": "dist/bin/gd-cli.js"
@@ -44,8 +44,7 @@
44
44
  "open": "11.0.0",
45
45
  "qrcode": "1.5.4",
46
46
  "semver": "7.8.5",
47
- "sharp": "0.35.5",
48
- "ws": "8.23.0"
47
+ "sharp": "0.35.5"
49
48
  },
50
49
  "devDependencies": {
51
50
  "@gaoding/gd-connector-contracts": "workspace:*",
@@ -56,6 +55,7 @@
56
55
  "@types/ws": "8.18.1",
57
56
  "typescript": "7.0.2",
58
57
  "vitest": "4.1.10",
58
+ "ws": "8.23.0",
59
59
  "@gaoding/model-catalog": "workspace:*"
60
60
  },
61
61
  "imports": {
@@ -65,8 +65,8 @@
65
65
  }
66
66
  },
67
67
  "gaodingRelease": {
68
- "sourceCommit": "aad4e8b151793b80e58b4e35cdc9df497214e198",
69
- "pipelineId": "288551",
70
- "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/288551"
68
+ "sourceCommit": "1690b3cbde556f5ba4cd19e035b442b7d1f78d5f",
69
+ "pipelineId": "289368",
70
+ "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/289368"
71
71
  }
72
72
  }
@@ -19,4 +19,4 @@ description: 用户希望通过稿定 CLI 创作或处理图片、视频、文
19
19
 
20
20
  ## 续作和交付
21
21
 
22
- 续作沿用上轮的上下文,取件用 `gd-cli task get` 查原任务。提交结果不明时先核对原单。交付实际返回的正文或完整成品链接,说明回执中的估价或实扣。
22
+ 续作沿用上轮的上下文,上次提交后如果没看到结果,先用 `gd-cli task get <上次返回的任务号>` 查进度。交付实际返回的正文或完整成品链接,说明回执中的估价或实扣。
@@ -1,107 +0,0 @@
1
- export class EditorBridgeError extends Error {
2
- code;
3
- constructor(code, message, options) {
4
- super(message, options);
5
- this.name = "EditorBridgeError";
6
- this.code = code;
7
- }
8
- }
9
- export class EditorBridgeUnavailableError extends Error {
10
- constructor(cause) {
11
- super("Editor Bridge is unavailable.", { cause });
12
- this.name = "EditorBridgeUnavailableError";
13
- }
14
- }
15
- export function createEditorBridgeClient(options) {
16
- const fetch = options.fetch ?? globalThis.fetch;
17
- const baseUrl = `http://127.0.0.1:${options.state.port}`;
18
- return {
19
- async health(signal) {
20
- const value = await request("/health", "GET", undefined, signal);
21
- if (!isRecord(value) ||
22
- value.status !== "ok" ||
23
- typeof value.pageConnected !== "boolean" ||
24
- typeof value.protocolVersion !== "number") {
25
- throw invalidResponse();
26
- }
27
- return {
28
- status: "ok",
29
- pageConnected: value.pageConnected,
30
- protocolVersion: value.protocolVersion
31
- };
32
- },
33
- async rpc(method, payload, signal) {
34
- const value = await request("/rpc", "POST", { method, ...(payload === undefined ? {} : { payload }) }, signal);
35
- if (!isRecord(value) ||
36
- (!hasExactKeys(value, []) && (!Object.hasOwn(value, "result") || Object.hasOwn(value, "error")))) {
37
- throw invalidResponse();
38
- }
39
- return value.result;
40
- },
41
- async disconnect(signal) {
42
- const value = await request("/disconnect", "POST", {}, signal);
43
- if (!isRecord(value) ||
44
- value.status !== "disconnected") {
45
- throw invalidResponse();
46
- }
47
- }
48
- };
49
- async function request(pathname, method, body, signal) {
50
- signal.throwIfAborted();
51
- let response;
52
- try {
53
- response = await fetch(`${baseUrl}${pathname}`, {
54
- method,
55
- headers: {
56
- Authorization: `Bearer ${options.state.token}`,
57
- ...(body === undefined ? {} : { "Content-Type": "application/json" })
58
- },
59
- redirect: "error",
60
- signal,
61
- ...(body === undefined ? {} : { body: JSON.stringify(body) })
62
- });
63
- }
64
- catch (error) {
65
- signal.throwIfAborted();
66
- throw new EditorBridgeUnavailableError(error);
67
- }
68
- let value;
69
- try {
70
- value = await response.json();
71
- }
72
- catch {
73
- throw invalidResponse();
74
- }
75
- if (!response.ok) {
76
- const error = readStructuredError(value);
77
- if (!error)
78
- throw invalidResponse();
79
- throw new EditorBridgeError(error.code, error.message);
80
- }
81
- return value;
82
- }
83
- }
84
- function readStructuredError(value) {
85
- if (!isRecord(value) || !isRecord(value.error))
86
- return null;
87
- const { code, message } = value.error;
88
- if (typeof code !== "string" ||
89
- !/^[A-Z][A-Z0-9_]*$/.test(code) ||
90
- typeof message !== "string" ||
91
- message.trim().length === 0) {
92
- return null;
93
- }
94
- return { code, message };
95
- }
96
- function invalidResponse() {
97
- return new EditorBridgeError("EDITOR_BRIDGE_INVALID_RESPONSE", "Editor Bridge 返回了无效响应。");
98
- }
99
- function isRecord(value) {
100
- return typeof value === "object" && value !== null && !Array.isArray(value);
101
- }
102
- function hasExactKeys(value, keys) {
103
- const actual = Object.keys(value).sort();
104
- const expected = [...keys].sort();
105
- return actual.length === expected.length &&
106
- actual.every((key, index) => key === expected[index]);
107
- }