@gaoding/cli 2.1.1 → 2.1.3
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.
- package/README.md +30 -0
- package/dist/bin/sync-skill.js +33 -0
- package/dist/src/bootstrap/create-runtime.js +5 -1
- package/dist/src/bootstrap/validators.js +88 -152
- package/dist/src/cli/agent-commands.js +2 -2
- package/dist/src/cli/editor-commands.js +9 -7
- package/dist/src/cli/errors.js +4 -5
- package/dist/src/cli/host-input.js +3 -5
- package/dist/src/cli/observed-errors.js +7 -3
- package/dist/src/cli/presenter.js +4 -5
- package/dist/src/contracts/creation-input.js +20 -17
- package/dist/src/features/auth/credential-store.js +1 -0
- package/dist/src/features/dam/object-storage.js +2 -1
- package/dist/src/features/dam/use-cases.js +2 -2
- package/dist/src/features/editor/bridge-process.js +3 -2
- package/dist/src/features/editor/session-state.js +1 -0
- package/dist/src/features/task/creation-refusal.js +3 -1
- package/dist/src/features/task/store.js +65 -22
- package/dist/src/features/task/task-background.js +3 -2
- package/dist/src/features/tool/canvas-media.js +2 -3
- package/dist/src/features/tool/canvas-results.js +13 -6
- package/dist/src/features/tool/catalog.js +2 -23
- package/dist/src/features/tool/dynamic-schema.js +3 -6
- package/dist/src/features/tool/tool-definitions.js +23 -0
- package/dist/src/features/update/package-manager.js +124 -0
- package/dist/src/features/update/update-service.js +133 -67
- package/dist/src/platform/detached-spawn.js +9 -0
- package/dist/src/platform/file-lock.js +12 -4
- package/dist/src/platform/input-uri.js +23 -1
- package/dist/src/platform/local-json-file.js +97 -15
- package/dist/src/platform/open-browser.js +5 -2
- package/dist/src/platform/safe-upload-file.js +2 -3
- package/dist/src/platform/schema-compiler.js +16 -0
- package/dist/src/platform/windows-acl/LICENSE-mingw-w64 +43 -0
- package/dist/src/platform/windows-acl/arm64.node +0 -0
- package/dist/src/platform/windows-acl/ia32.node +0 -0
- package/dist/src/platform/windows-acl/x64.node +0 -0
- package/dist/src/platform/windows-host-job/arm64.exe +0 -0
- package/dist/src/platform/windows-host-job/ia32.exe +0 -0
- package/dist/src/platform/windows-host-job/sha256.json +7 -0
- package/dist/src/platform/windows-host-job/x64.exe +0 -0
- package/dist/src/platform/windows-private-state.js +72 -0
- package/dist/src/product/config.js +1 -1
- package/dist/src/telemetry/failure-summary.js +2 -2
- package/dist/src/telemetry/sls-sink.js +48 -29
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -12,12 +12,42 @@ npm install --global --allow-scripts=@gaoding/cli @gaoding/cli
|
|
|
12
12
|
pnpm add --global --allow-build=@gaoding/cli @gaoding/cli
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
Windows PowerShell 如果提示系统禁止运行 `gd-cli.ps1`,请直接运行同一安装提供的 `gd-cli.cmd`,例如 `gd-cli.cmd --help`。其他参数与命令相同。
|
|
16
|
+
|
|
17
|
+
Windows 共享文件可直接把 UNC 路径传给 `dam upload`。Tool 和 Agent 的媒体字段使用 `file://主机/共享名/文件`。当共享主机写作 `localhost` 时,Node 的 `pathToFileURL` 会省略主机名,可用 Python 的 `PureWindowsPath(path).as_uri()` 保留它。
|
|
18
|
+
|
|
19
|
+
如果 pnpm 生成的 Windows 启动器报 `MODULE_NOT_FOUND`,且错误中的中文安装路径已乱码,可在当前 CMD 执行 `chcp 65001`,再运行 `gd-cli.cmd`。npm 自定义目录含 `&` 等字符时,若启动器截断了路径,可以直接运行 `node "<原 npm prefix>\node_modules\@gaoding\cli\dist\bin\gd-cli.js" update`,再用同一入口执行 `--version` 核对。
|
|
20
|
+
|
|
15
21
|
全局安装和后续包升级会自动同步随包 `gd-cli` Agent Skill 到 canonical 目录,并连接已检测到的 Agent 宿主。npm 的 `--allow-scripts=@gaoding/cli` 与 pnpm 的 `--allow-build=@gaoding/cli` 分别只允许本包执行安装脚本。若安装时使用了 `--ignore-scripts`,执行以下命令补齐:
|
|
16
22
|
|
|
17
23
|
```bash
|
|
18
24
|
gd-cli update
|
|
19
25
|
```
|
|
20
26
|
|
|
27
|
+
提前准备 tarball 和 pnpm 依赖缓存;直接离线安装固定版本的 pnpm tarball 后,如安装脚本未执行,可通过已安装的 pnpm 启动器同步并验收该版本的 Skill(不会联网或升级 CLI):
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
node -e 'const f=require("fs"),p=require("path"),c=require("child_process"),d=process.argv[1],s=p.join(d,process.platform==="win32"?"gd-cli.cmd":"gd-cli"),v=f.readFileSync(s,"utf8"),m=v.match(/cmd-shim-target=(.+)/i)||v.match(/"\$basedir\/([^"\r\n]+\.js)"/);if(!m)throw Error("Cannot identify pnpm launcher target");const t=p.resolve(d,m[1].trim()),r=c.spawnSync(process.execPath,[p.join(p.dirname(t),"sync-skill.js")],{stdio:"inherit"});process.exit(r.status??1)' "$(pnpm bin --global)"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Windows PowerShell:
|
|
34
|
+
|
|
35
|
+
```powershell
|
|
36
|
+
$previousEncoding = [Console]::OutputEncoding
|
|
37
|
+
try { [Console]::OutputEncoding = [Text.UTF8Encoding]::new(); $bin = (pnpm bin --global).Trim() }
|
|
38
|
+
finally { [Console]::OutputEncoding = $previousEncoding }
|
|
39
|
+
$shim = Get-Content -Encoding UTF8 -LiteralPath (Join-Path $bin "gd-cli.cmd") -Raw
|
|
40
|
+
if ($shim -match 'cmd-shim-target=(.+)') { $entry = $Matches[1].Trim() }
|
|
41
|
+
elseif ($shim -match '"%~dp0\\([^"\r\n]+\.js)"') { $entry = $Matches[1] }
|
|
42
|
+
else { throw "Cannot identify pnpm launcher target" }
|
|
43
|
+
if ([IO.Path]::IsPathRooted($entry)) { $target = [IO.Path]::GetFullPath($entry) }
|
|
44
|
+
else { $target = [IO.Path]::GetFullPath((Join-Path $bin $entry)) }
|
|
45
|
+
node (Join-Path (Split-Path $target) "sync-skill.js")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
宿主管理的安装不使用此步骤;已有外来 Skill 不会被覆盖。
|
|
50
|
+
|
|
21
51
|
## 开始使用
|
|
22
52
|
|
|
23
53
|
```bash
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Explicit offline recovery for pnpm installs whose lifecycle was skipped.
|
|
2
|
+
// This is an internal package entry, not a CLI command or an ordinary-start hook.
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { loadBundledSkills } from "../src/features/skill/bundled-skills.js";
|
|
7
|
+
import { syncBundledSkills, verifyBundledSkills } from "../src/features/skill/installer.js";
|
|
8
|
+
import { detectInstallSource, pnpmLauncherTargets } from "../src/features/update/update-service.js";
|
|
9
|
+
import { readInstallationOwner } from "../src/platform/installation-owner.js";
|
|
10
|
+
async function main() {
|
|
11
|
+
const start = process.argv[1];
|
|
12
|
+
if (!start)
|
|
13
|
+
throw new Error("Cannot identify the installed package entry.");
|
|
14
|
+
const skills = loadBundledSkills(start);
|
|
15
|
+
const skill = skills[0];
|
|
16
|
+
if (!skill)
|
|
17
|
+
throw new Error("Bundled Skill is missing.");
|
|
18
|
+
const root = realpathSync(dirname(dirname(skill.sourceDirectory)));
|
|
19
|
+
const binary = join(dirname(resolve(start)), `${skill.skill}.js`);
|
|
20
|
+
const source = detectInstallSource({ binaryPath: binary, realBinaryPath: realpathSync(binary), packageRoot: root,
|
|
21
|
+
cwd: process.cwd(), env: process.env, packageName: skill.skill === "gd-cli" ? "@gaoding/cli" : "@insmind/cli", binaryName: skill.skill });
|
|
22
|
+
if (source.kind !== "global" || source.manager !== "pnpm"
|
|
23
|
+
|| !pnpmLauncherTargets(process.env, skill.skill).includes(resolve(binary))
|
|
24
|
+
|| readInstallationOwner(root) !== "user") {
|
|
25
|
+
throw new Error("Cannot confirm a user-managed pnpm global installation; no Skill was changed.");
|
|
26
|
+
}
|
|
27
|
+
await syncBundledSkills(skills);
|
|
28
|
+
await verifyBundledSkills(skills);
|
|
29
|
+
process.stdout.write(`Agent Skill ${skill.skill} ${skill.version} synchronized.\n`);
|
|
30
|
+
}
|
|
31
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
32
|
+
void main().catch(error => { process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`); process.exitCode = 1; });
|
|
33
|
+
}
|
|
@@ -94,9 +94,13 @@ export function createProductionRuntime(options = {}) {
|
|
|
94
94
|
} : undefined;
|
|
95
95
|
const now = options.now ?? (() => new Date());
|
|
96
96
|
const telemetryEnvironment = options.telemetryEnvironment ?? (env.CLI_TELEMETRY_ENV === "test" ? "test" : "production");
|
|
97
|
+
const host = hostTelemetryContext(env);
|
|
98
|
+
const reporterFlushes = env.CLI_INTERNAL_HOST_REPORTER_FLUSH === "1" && host.host_application === "workbuddy"
|
|
99
|
+
&& !!host.host_invocation_id && (host.invocation_purpose === "auth_status" || host.invocation_purpose === "version_check");
|
|
97
100
|
const telemetrySink = options.telemetrySink ?? createSlsTelemetrySink({
|
|
98
101
|
fetch, trackingUrl: options.telemetryTrackingUrl ?? product.telemetryUrl,
|
|
99
102
|
background: options.telemetryBackground ?? true,
|
|
103
|
+
reporterFlushes,
|
|
100
104
|
directory: join(options.homeDirectory ?? homedir(), product.stateDirectory, "telemetry", "v6"),
|
|
101
105
|
now: () => now().getTime()
|
|
102
106
|
});
|
|
@@ -111,7 +115,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
111
115
|
classifyError: error => classifyTelemetryError(error, { product, operation: telemetry.creationContext().operation, failureStage: telemetry.failureStage(error) }),
|
|
112
116
|
...(telemetrySink.enqueue ? { onEvent: (event) => telemetrySink.enqueue([event]) } : {})
|
|
113
117
|
});
|
|
114
|
-
telemetry.annotate({ installation_owner: installationOwner, ...
|
|
118
|
+
telemetry.annotate({ installation_owner: installationOwner, ...host });
|
|
115
119
|
// Explicit test transport enables SDK tests; test-mode child processes never emit real analytics.
|
|
116
120
|
const analytics = options.analytics ?? (telemetryEnvironment === "production" || options.windFetch
|
|
117
121
|
? createWindAnalytics({ product: product.id, version: options.telemetryVersion ?? primarySkill.version,
|
|
@@ -1,51 +1,8 @@
|
|
|
1
1
|
import { inputValidationSummary, validationIssues } from "../platform/schema-issues.js";
|
|
2
2
|
import { canonicalizeInputFileUris } from "../platform/input-uri.js";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { contractDocument, contractSchema } from "../contracts/schema.js";
|
|
7
|
-
const agentSendOutputSchema = contractSchema("agent.send", "output");
|
|
8
|
-
const authStatusSchema = contractSchema("auth.status", "output");
|
|
9
|
-
const damDeleteInputSchema = contractSchema("dam.delete", "input");
|
|
10
|
-
const damDeleteOutputSchema = contractSchema("dam.delete", "output");
|
|
11
|
-
const damCopyInputSchema = contractSchema("dam.copy", "input");
|
|
12
|
-
const damCopyOutputSchema = contractSchema("dam.copy", "output");
|
|
13
|
-
const damDownloadInputSchema = contractSchema("dam.download", "input");
|
|
14
|
-
const damDownloadOutputSchema = contractSchema("dam.download", "output");
|
|
15
|
-
const damFolderListInputSchema = contractSchema("dam.folder.list", "input");
|
|
16
|
-
const damFolderListOutputSchema = contractSchema("dam.folder.list", "output");
|
|
17
|
-
const damGetInputSchema = contractSchema("dam.get", "input");
|
|
18
|
-
const damGetOutputSchema = contractSchema("dam.get", "output");
|
|
19
|
-
const damListInputSchema = contractSchema("dam.list", "input");
|
|
20
|
-
const damListOutputSchema = contractSchema("dam.list", "output");
|
|
21
|
-
const damMoveInputSchema = contractSchema("dam.move", "input");
|
|
22
|
-
const damMoveOutputSchema = contractSchema("dam.move", "output");
|
|
23
|
-
const damRepositoryListOutputSchema = contractSchema("dam.repository.list", "output");
|
|
24
|
-
const damRenameInputSchema = contractSchema("dam.rename", "input");
|
|
25
|
-
// The service owns the character limit. The CLI only needs a title to send.
|
|
26
|
-
delete (damRenameInputSchema.properties.title).maxLength;
|
|
27
|
-
const damRenameOutputSchema = contractSchema("dam.rename", "output");
|
|
28
|
-
const damSearchInputSchema = contractSchema("dam.search", "input");
|
|
29
|
-
const damSearchOutputSchema = contractSchema("dam.search", "output");
|
|
30
|
-
const damTagListInputSchema = contractSchema("dam.tag.list", "input");
|
|
31
|
-
const damTagListOutputSchema = contractSchema("dam.tag.list", "output");
|
|
32
|
-
const damUploadInputSchema = contractSchema("dam.upload", "input");
|
|
33
|
-
const damUploadOutputSchema = contractSchema("dam.upload", "output");
|
|
34
|
-
const editorApplyInputSchema = contractSchema("editor.apply", "input");
|
|
35
|
-
const editorApplyOutputSchema = contractSchema("editor.apply", "output");
|
|
36
|
-
const editorConnectInputSchema = contractSchema("editor.connect", "input");
|
|
37
|
-
const editorConnectOutputSchema = contractSchema("editor.connect", "output");
|
|
38
|
-
const editorDisconnectOutputSchema = contractSchema("editor.disconnect", "output");
|
|
39
|
-
const editorSaveOutputSchema = contractSchema("editor.save", "output");
|
|
40
|
-
const editorScreenshotOutputSchema = contractSchema("editor.screenshot", "output");
|
|
41
|
-
const editorSnapshotOutputSchema = contractSchema("editor.snapshot", "output");
|
|
42
|
-
const modelGetInputSchema = contractSchema("model.get", "input");
|
|
43
|
-
const modelGetOutputSchema = contractSchema("model.get", "output");
|
|
44
|
-
const modelListInputSchema = contractSchema("model.list", "input");
|
|
45
|
-
const modelListOutputSchema = contractSchema("model.list", "output");
|
|
46
|
-
const toolCallInputSchema = contractSchema("tool.call", "input");
|
|
47
|
-
const toolCallOutputSchema = contractSchema("tool.call", "output");
|
|
48
|
-
const toolListOutputSchema = contractSchema("tool.list", "output");
|
|
3
|
+
import { lazySchemaCompiler } from "../platform/schema-compiler.js";
|
|
4
|
+
import { readAgentInputSchema } from "../contracts/creation-input.js";
|
|
5
|
+
import { contractSchema } from "../contracts/schema.js";
|
|
49
6
|
export class InputContractError extends Error {
|
|
50
7
|
issues;
|
|
51
8
|
diagnosticSummary;
|
|
@@ -65,117 +22,96 @@ export class OutputContractError extends Error {
|
|
|
65
22
|
}
|
|
66
23
|
}
|
|
67
24
|
export function createContractValidators(options = {}) {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
const editorApplyOutput = ajv.compile(editorApplyOutputSchema);
|
|
103
|
-
const editorScreenshotOutput = ajv.compile(editorScreenshotOutputSchema);
|
|
104
|
-
const editorSaveOutput = ajv.compile(editorSaveOutputSchema);
|
|
105
|
-
const organizations = options.organizations !== false;
|
|
106
|
-
const orgList = organizations
|
|
107
|
-
? ajv.compile(contractSchema("org.list", "output"))
|
|
108
|
-
: unavailableValidator;
|
|
109
|
-
const orgCurrent = organizations
|
|
110
|
-
? ajv.compile(contractSchema("org.current", "output"))
|
|
111
|
-
: unavailableValidator;
|
|
112
|
-
const toolListOutput = ajv.compile(toolListOutputSchema);
|
|
113
|
-
const modelListInput = ajv.compile(modelListInputSchema);
|
|
114
|
-
const modelListOutput = ajv.compile(modelListOutputSchema);
|
|
115
|
-
const modelGetInput = ajv.compile(modelGetInputSchema);
|
|
116
|
-
const modelGetOutput = ajv.compile(modelGetOutputSchema);
|
|
117
|
-
const toolCallInput = ajv.compile(toolCallInputSchema);
|
|
118
|
-
const toolCallOutput = ajv.compile(toolCallOutputSchema);
|
|
119
|
-
const runOutputSchema = contractSchema("task.get", "output");
|
|
120
|
-
const runSchemaId = runOutputSchema.$id;
|
|
121
|
-
ajv.addSchema(agentSendOutputSchema, new URL("../agent.send/output.schema.json", runSchemaId).href);
|
|
122
|
-
ajv.addSchema(toolCallOutputSchema, new URL("../tool.call/output.schema.json", runSchemaId).href);
|
|
123
|
-
const taskResult = ajv.compile(runOutputSchema);
|
|
124
|
-
const taskListResult = ajv.compile(contractSchema("task.list", "output"));
|
|
25
|
+
const compiler = lazySchemaCompiler({ allErrors: true, strict: true });
|
|
26
|
+
// Only the task contracts reference both producer outputs. Reading them for
|
|
27
|
+
// auth.status or --version adds filesystem work to every cold Windows probe.
|
|
28
|
+
let taskSchemas;
|
|
29
|
+
function taskOutput(operation) {
|
|
30
|
+
return assertion(() => {
|
|
31
|
+
const engine = compiler();
|
|
32
|
+
if (!taskSchemas) {
|
|
33
|
+
const task = contractSchema("task.get", "output");
|
|
34
|
+
const agent = contractSchema("agent.send", "output");
|
|
35
|
+
const tool = contractSchema("tool.call", "output");
|
|
36
|
+
const id = String(task.$id);
|
|
37
|
+
engine.addSchema(agent, new URL("../agent.send/output.schema.json", id).href);
|
|
38
|
+
engine.addSchema(tool, new URL("../tool.call/output.schema.json", id).href);
|
|
39
|
+
engine.addSchema(task);
|
|
40
|
+
taskSchemas = { "task.get": task, "agent.send": agent, "tool.call": tool };
|
|
41
|
+
}
|
|
42
|
+
return engine.compile(operation === "task.list" ? contractSchema(operation, "output") : taskSchemas[operation]);
|
|
43
|
+
}, OutputContractError);
|
|
44
|
+
}
|
|
45
|
+
function output(operation) {
|
|
46
|
+
return assertion(() => compiler().compile(contractSchema(operation, "output")), OutputContractError);
|
|
47
|
+
}
|
|
48
|
+
function input(operation) {
|
|
49
|
+
return assertion(() => {
|
|
50
|
+
const schema = contractSchema(operation, "input");
|
|
51
|
+
if (operation === "dam.rename") {
|
|
52
|
+
// The service owns the character limit. The CLI only needs a title to send.
|
|
53
|
+
delete (schema.properties.title).maxLength;
|
|
54
|
+
}
|
|
55
|
+
return compiler().compile(schema);
|
|
56
|
+
}, InputContractError);
|
|
57
|
+
}
|
|
58
|
+
const unavailable = assertion(() => unavailableValidator, OutputContractError);
|
|
125
59
|
return {
|
|
126
|
-
creditsOutput:
|
|
127
|
-
creditsUsageListOutput:
|
|
128
|
-
creditsUsageGetOutput:
|
|
129
|
-
taskResult:
|
|
130
|
-
taskListResult:
|
|
131
|
-
agentSendInput: assertion(
|
|
132
|
-
agentSendOutput:
|
|
133
|
-
authStatus:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
toolListOutput:
|
|
168
|
-
modelListInput:
|
|
169
|
-
modelListOutput:
|
|
170
|
-
modelGetInput:
|
|
171
|
-
modelGetOutput:
|
|
172
|
-
toolCallInput:
|
|
173
|
-
toolCallOutput:
|
|
60
|
+
creditsOutput: output("credits.get"),
|
|
61
|
+
creditsUsageListOutput: output("credits.usage.list"),
|
|
62
|
+
creditsUsageGetOutput: output("credits.usage.get"),
|
|
63
|
+
taskResult: taskOutput("task.get"),
|
|
64
|
+
taskListResult: taskOutput("task.list"),
|
|
65
|
+
agentSendInput: assertion(() => compiler().compile(readAgentInputSchema()), InputContractError),
|
|
66
|
+
agentSendOutput: taskOutput("agent.send"),
|
|
67
|
+
authStatus: output("auth.status"),
|
|
68
|
+
orgList: options.organizations === false ? unavailable : output("org.list"),
|
|
69
|
+
orgCurrent: options.organizations === false ? unavailable : output("org.current"),
|
|
70
|
+
damRepositoryListOutput: output("dam.repository.list"),
|
|
71
|
+
damListInput: input("dam.list"),
|
|
72
|
+
damListOutput: output("dam.list"),
|
|
73
|
+
damSearchInput: input("dam.search"),
|
|
74
|
+
damSearchOutput: output("dam.search"),
|
|
75
|
+
damFolderListInput: input("dam.folder.list"),
|
|
76
|
+
damFolderListOutput: output("dam.folder.list"),
|
|
77
|
+
damTagListInput: input("dam.tag.list"),
|
|
78
|
+
damTagListOutput: output("dam.tag.list"),
|
|
79
|
+
damGetInput: input("dam.get"),
|
|
80
|
+
damGetOutput: output("dam.get"),
|
|
81
|
+
damUploadInput: input("dam.upload"),
|
|
82
|
+
damUploadOutput: output("dam.upload"),
|
|
83
|
+
damDeleteInput: input("dam.delete"),
|
|
84
|
+
damDeleteOutput: output("dam.delete"),
|
|
85
|
+
damDownloadInput: input("dam.download"),
|
|
86
|
+
damDownloadOutput: output("dam.download"),
|
|
87
|
+
damRenameInput: input("dam.rename"),
|
|
88
|
+
damRenameOutput: output("dam.rename"),
|
|
89
|
+
damMoveInput: input("dam.move"),
|
|
90
|
+
damMoveOutput: output("dam.move"),
|
|
91
|
+
damCopyInput: input("dam.copy"),
|
|
92
|
+
damCopyOutput: output("dam.copy"),
|
|
93
|
+
editorConnectInput: input("editor.connect"),
|
|
94
|
+
editorConnectOutput: output("editor.connect"),
|
|
95
|
+
editorDisconnectOutput: output("editor.disconnect"),
|
|
96
|
+
editorSnapshotOutput: output("editor.snapshot"),
|
|
97
|
+
editorApplyInput: input("editor.apply"),
|
|
98
|
+
editorApplyOutput: output("editor.apply"),
|
|
99
|
+
editorScreenshotOutput: output("editor.screenshot"),
|
|
100
|
+
editorSaveOutput: output("editor.save"),
|
|
101
|
+
toolListOutput: output("tool.list"),
|
|
102
|
+
modelListInput: input("model.list"),
|
|
103
|
+
modelListOutput: output("model.list"),
|
|
104
|
+
modelGetInput: input("model.get"),
|
|
105
|
+
modelGetOutput: output("model.get"),
|
|
106
|
+
toolCallInput: input("tool.call"),
|
|
107
|
+
toolCallOutput: taskOutput("tool.call"),
|
|
174
108
|
};
|
|
175
109
|
}
|
|
176
110
|
const unavailableValidator = Object.assign(() => false, { errors: null, schema: false, schemaEnv: undefined });
|
|
177
|
-
function assertion(
|
|
111
|
+
function assertion(compile, ErrorType) {
|
|
112
|
+
let validate;
|
|
178
113
|
return (value) => {
|
|
114
|
+
validate ??= compile();
|
|
179
115
|
if (ErrorType === InputContractError)
|
|
180
116
|
canonicalizeInputFileUris(value, validate.schema);
|
|
181
117
|
if (!validate(value)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { creationTaskHelp } from "./creation-help.js";
|
|
2
2
|
import { hostSchema, readHostInput } from "./host-input.js";
|
|
3
|
-
import {
|
|
3
|
+
import { readAgentInputSchema } from "../contracts/creation-input.js";
|
|
4
4
|
import { jsonOutput, bindPreparedAction } from "./action-binding.js";
|
|
5
5
|
import { CliUsageError } from "./errors.js";
|
|
6
6
|
import { productText as text } from "../product/text.js";
|
|
@@ -39,7 +39,7 @@ export function registerAgentCommands(program, runtime) {
|
|
|
39
39
|
throw new CliUsageError();
|
|
40
40
|
if (options.schema === true) {
|
|
41
41
|
await runtime.telemetry.stage("output", async () => {
|
|
42
|
-
runtime.io.writeOut(`${JSON.stringify(hostSchema(runtime,
|
|
42
|
+
runtime.io.writeOut(`${JSON.stringify(hostSchema(runtime, readAgentInputSchema()))}\n`);
|
|
43
43
|
});
|
|
44
44
|
return { handled: true };
|
|
45
45
|
}
|
|
@@ -3,12 +3,14 @@ import { jsonOutput, bindAction, bindPreparedAction } from "./action-binding.js"
|
|
|
3
3
|
import { contractSchema } from "../contracts/schema.js";
|
|
4
4
|
import { CliUsageError } from "./errors.js";
|
|
5
5
|
import { productText as text } from "../product/text.js";
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.
|
|
11
|
-
}
|
|
6
|
+
function editorApplyInputSchema() {
|
|
7
|
+
const { $defs, ...actionArray } = contractSchema("editor.apply", "input");
|
|
8
|
+
return {
|
|
9
|
+
type: "object", additionalProperties: false, required: ["actions"], properties: { actions: actionArray },
|
|
10
|
+
$defs: Object.fromEntries(Object.entries($defs)
|
|
11
|
+
.map(([name, definition]) => [name, { ...definition, additionalProperties: true }]))
|
|
12
|
+
};
|
|
13
|
+
}
|
|
12
14
|
export function registerEditorCommands(program, runtime) {
|
|
13
15
|
const editor = program.command("editor")
|
|
14
16
|
.description(text(runtime.product, "连接并操作 AI+ Editor", "Connect to and operate insMind Editor"))
|
|
@@ -86,7 +88,7 @@ export function registerEditorCommands(program, runtime) {
|
|
|
86
88
|
if (Number(options.schema === true) + Number(options.input !== undefined) !== 1)
|
|
87
89
|
throw new CliUsageError();
|
|
88
90
|
if (options.schema === true) {
|
|
89
|
-
await runtime.telemetry.stage("output", () => { writeJson(runtime, hostSchema(runtime, editorApplyInputSchema)); });
|
|
91
|
+
await runtime.telemetry.stage("output", () => { writeJson(runtime, hostSchema(runtime, editorApplyInputSchema())); });
|
|
90
92
|
return { handled: true };
|
|
91
93
|
}
|
|
92
94
|
const input = editorActions(readHostInput(runtime, await runtime.jsonInput.read(options.input, signal)));
|
package/dist/src/cli/errors.js
CHANGED
|
@@ -59,7 +59,7 @@ export function mapCliError(error, options) {
|
|
|
59
59
|
: "输入素材上传失败,本次创作请求尚未派发。", outcome.exitCode, [en ? "Tell the user which step failed. Once the connection is available, the same request and original files can be used again."
|
|
60
60
|
: "向用户说明失败发生在上传原素材时。网络可用后,可用原需求和原素材再次发起。"], { ...outcome.failure.details, phase: "input_upload_before_dispatch" });
|
|
61
61
|
}
|
|
62
|
-
if (error instanceof TaskBackgroundError || (error instanceof ToolTaskFailedError && error.imagePixelRequirement))
|
|
62
|
+
if (error instanceof UpdateError || error instanceof TaskBackgroundError || (error instanceof ToolTaskFailedError && error.imagePixelRequirement))
|
|
63
63
|
return outcome;
|
|
64
64
|
const remote = remoteCause(error);
|
|
65
65
|
const evidence = {
|
|
@@ -114,6 +114,8 @@ function mapBaseCliError(error, options) {
|
|
|
114
114
|
if (error instanceof ToolTaskCanceledError)
|
|
115
115
|
return { kind: "interrupted", exitCode: 130,
|
|
116
116
|
failure: { code: "INTERRUPTED", message: text("生成任务已取消。", "The creation task was canceled.") } };
|
|
117
|
+
if (error instanceof UpdateError)
|
|
118
|
+
return failure(error.code, error.message, 1, error.nextSteps, error.details);
|
|
117
119
|
if (options.aborted)
|
|
118
120
|
return { kind: "interrupted", exitCode: 130, failure: {
|
|
119
121
|
code: "INTERRUPTED", message: text("已停止本地等待;已派发的任务或写操作可能仍在继续。", "Local waiting stopped; dispatched tasks or writes may still be active."),
|
|
@@ -157,9 +159,6 @@ function mapBaseCliError(error, options) {
|
|
|
157
159
|
return failure("AUTH_STATE_INVALID", "The account context is unavailable. Sign out and sign in again.", 1, [`${command} auth logout`, `${command} auth login`]);
|
|
158
160
|
return failure("ORG_INVALID", "所选组织不可用,请重新选择组织。", 1, ["gd-cli org list", "gd-cli org switch --org <org-id>"]);
|
|
159
161
|
}
|
|
160
|
-
if (error instanceof UpdateError) {
|
|
161
|
-
return failure(error.code, error.message, 1, error.nextSteps, error.details);
|
|
162
|
-
}
|
|
163
162
|
if (error instanceof EditorTargetError) {
|
|
164
163
|
if (insmind)
|
|
165
164
|
return failure(error.code, "Editor target must be a work ID or a complete trusted insMind Editor URL.", 2);
|
|
@@ -188,7 +187,7 @@ function mapBaseCliError(error, options) {
|
|
|
188
187
|
}
|
|
189
188
|
if (error instanceof LocalFileInputError) {
|
|
190
189
|
const message = error.reason === "invalid_file_uri"
|
|
191
|
-
? text("本地文件地址格式不正确。Windows
|
|
190
|
+
? text("本地文件地址格式不正确。Windows 盘符用 file:///C:/目录/文件,共享文件用 file://主机/共享名/文件。", "Invalid local file URL. Use file:///C:/folder/file for a Windows drive or file://server/share/file for a share.")
|
|
192
191
|
: error.reason === "file_read_failed" && systemErrorCode(error) === "ENOENT"
|
|
193
192
|
? text("找不到指定的本地文件,请核对完整路径。", "The local file was not found. Check its full path.")
|
|
194
193
|
: error.reason === "invalid_media_type_header"
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import addFormats, {} from "ajv-formats";
|
|
1
|
+
import { lazySchemaCompiler } from "../platform/schema-compiler.js";
|
|
3
2
|
import { InputContractError } from "../bootstrap/validators.js";
|
|
4
3
|
import { productText } from "../product/text.js";
|
|
5
4
|
function object(value) {
|
|
@@ -13,8 +12,7 @@ export function readHostInput(runtime, raw) {
|
|
|
13
12
|
runtime.telemetry.observeHost(host_application);
|
|
14
13
|
return input;
|
|
15
14
|
}
|
|
16
|
-
const examples =
|
|
17
|
-
addFormats(examples);
|
|
15
|
+
const examples = lazySchemaCompiler({ strict: false, addUsedSchema: false });
|
|
18
16
|
function toolExample(runtime, source, properties, required, tool) {
|
|
19
17
|
const sample = { host_application: "terminal" };
|
|
20
18
|
const english = runtime.product.id === "insmind";
|
|
@@ -48,7 +46,7 @@ function toolExample(runtime, source, properties, required, tool) {
|
|
|
48
46
|
sample.prompt ??= values.prompt;
|
|
49
47
|
}
|
|
50
48
|
// Directory extensions can introduce requirements we cannot illustrate faithfully.
|
|
51
|
-
return examples.validate(source, sample) ? sample : undefined;
|
|
49
|
+
return examples().validate(source, sample) ? sample : undefined;
|
|
52
50
|
}
|
|
53
51
|
export function hostSchema(runtime, schema, tool) {
|
|
54
52
|
const localMedia = productText(runtime.product, "本地附件用 Path(path).resolve().as_uri() 或 pathToFileURL(path).href 生成标准 file URI,转义中文、空格和 #;已有 HTTP(S) URL 原样使用。", "Generate local file URIs with Path(path).resolve().as_uri() or pathToFileURL(path).href to escape Unicode, spaces and #; preserve existing HTTP(S) URLs.");
|
|
@@ -27,21 +27,22 @@ const messages = {
|
|
|
27
27
|
request: ["本次请求未能完成。", "This request could not be completed."],
|
|
28
28
|
client: ["程序运行遇到问题,本次操作未能完成。", "The app encountered a problem and could not complete this operation."]
|
|
29
29
|
};
|
|
30
|
-
const reviewCodes = new Set(["12020751", "12020752", "12020757", "12020758", "12020760", "12020790"]);
|
|
30
|
+
const reviewCodes = new Set(["12020751", "12020752", "12020756", "12020757", "12020758", "12020760", "12020790"]);
|
|
31
31
|
export function observedErrorCategory(e) {
|
|
32
32
|
const gd = e.product === "gaoding", ins = e.product === "insmind";
|
|
33
33
|
const toolOrQuery = e.operation === "tool.call" || e.operation === "task.get";
|
|
34
34
|
if (e.code === "INSUFFICIENT_CREDITS" || gd && e.operation === "tool.call" && e.remoteCode === "12020770")
|
|
35
35
|
return "credits";
|
|
36
36
|
if (e.errorType === "AgentAuditRejectedError" || e.diagnosticReason === "AGENT_INPUT_AUDIT_REJECTED"
|
|
37
|
-
|| gd && (toolOrQuery && reviewCodes.has(e.remoteCode ?? "") || e.operation === "agent.send" && e.remoteCode === "-1006")
|
|
38
|
-
|
|
37
|
+
|| e.diagnosticReason !== "TASK_QUERY_FAILED" && (gd && (toolOrQuery && reviewCodes.has(e.remoteCode ?? "") || e.operation === "agent.send" && e.remoteCode === "-1006")
|
|
38
|
+
|| ins && toolOrQuery && e.remoteCode === "12020760"))
|
|
39
39
|
return "review";
|
|
40
40
|
if (gd && e.operation === "agent.send" && e.httpStatus === 409)
|
|
41
41
|
return "session_busy";
|
|
42
42
|
if (gd && e.operation === "agent.send" && e.httpStatus === 429)
|
|
43
43
|
return "service_busy";
|
|
44
44
|
if (gd && e.operation === "auth.login" && e.httpStatus === 504 || e.code === "EDITOR_RPC_TIMEOUT"
|
|
45
|
+
|| gd && toolOrQuery && e.remoteCode === "12020792"
|
|
45
46
|
|| (gd || ins) && e.operation === "tool.call" && e.remoteCode === "-31994" && e.diagnosticReason === "IMAGE_AUDIT_TIMEOUT")
|
|
46
47
|
return "timeout";
|
|
47
48
|
if (ins && e.operation === "tool.call" && e.remoteCode === "-31993")
|
|
@@ -106,6 +107,9 @@ export function observedErrorMessage(category, e) {
|
|
|
106
107
|
return text("已收到本页流水,但服务未返回可用的下一页游标。请查看 details.partial_result,本次无法续页。", "This page was received without a usable cursor. Its records are in details.partial_result; the next page cannot be requested.");
|
|
107
108
|
if (category === "timeout" && e.diagnosticReason === "IMAGE_AUDIT_TIMEOUT")
|
|
108
109
|
return text("图片审核处理超时,尚未取得结果。", "The image check did not finish in time.");
|
|
110
|
+
if (category === "timeout" && e.product === "gaoding" && (e.operation === "tool.call" || e.operation === "task.get")
|
|
111
|
+
&& e.remoteCode === "12020792")
|
|
112
|
+
return "内容审核处理超时,尚未取得结果。";
|
|
109
113
|
if (category === "login" && e.errorType === "DeviceAuthorizationExpiredError")
|
|
110
114
|
return text("本次登录已超时,请重新登录。", "This sign-in timed out. Please sign in again.");
|
|
111
115
|
if (category === "account" && e.code === "ORG_INVALID")
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import * as QRCode from "qrcode";
|
|
2
1
|
export function createPresenter(options) {
|
|
3
2
|
const insmind = options.product?.id === "insmind";
|
|
4
|
-
const qrCode = options.qrCode ?? ((text) =>
|
|
5
|
-
|
|
6
|
-
small: true
|
|
7
|
-
})
|
|
3
|
+
const qrCode = options.qrCode ?? (async (text) => {
|
|
4
|
+
const QRCode = await import("qrcode");
|
|
5
|
+
return QRCode.toString(text, { type: "terminal", small: true });
|
|
6
|
+
});
|
|
8
7
|
let humanResult = false;
|
|
9
8
|
return {
|
|
10
9
|
get humanResult() { return humanResult; },
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { contractSchema } from "./schema.js";
|
|
2
2
|
// Media alone is a prompt. The service has one scene/parameter map and rewrites a
|
|
3
3
|
// question reply into a function response, discarding any accompanying prompt.
|
|
4
|
-
export
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
delete definitions.
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
model.description
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
]
|
|
4
|
+
export function readAgentInputSchema() {
|
|
5
|
+
const agentInputSchema = contractSchema("agent.send", "input");
|
|
6
|
+
const definitions = agentInputSchema.$defs;
|
|
7
|
+
delete definitions.FirstFramePart;
|
|
8
|
+
delete definitions.LastFramePart;
|
|
9
|
+
const generation = definitions.GenerationConstraintsPart.properties.data;
|
|
10
|
+
const model = generation.properties.model;
|
|
11
|
+
if (model.description)
|
|
12
|
+
model.description = "可选创作模型标识;已知编辑模型别名会映射到服务端 code,其余标识原样发送。";
|
|
13
|
+
delete generation.properties.arguments.minProperties;
|
|
14
|
+
const question = { $ref: "#/$defs/QuestionAnswerPart" };
|
|
15
|
+
definitions.UserMessage.allOf = [
|
|
16
|
+
...["GenerationConstraintsPart", "QuestionAnswerPart"].map(part => ({
|
|
17
|
+
properties: { parts: { type: "array", contains: { $ref: "#/$defs/" + part }, minContains: 0, maxContains: 1 } }
|
|
18
|
+
})),
|
|
19
|
+
{ if: { properties: { parts: { type: "array", contains: question } } },
|
|
20
|
+
then: { required: ["contextId"], properties: { contextId: { type: "string" }, parts: { type: "array", maxItems: 1 } } } }
|
|
21
|
+
];
|
|
22
|
+
return agentInputSchema;
|
|
23
|
+
}
|
|
@@ -5,6 +5,7 @@ import { AuthStateInvalidError, AuthStateUnavailableError, parseStoredAuthState
|
|
|
5
5
|
export function createLocalCredentialStore(options = {}) {
|
|
6
6
|
const file = options.file ?? createLocalJsonFile({
|
|
7
7
|
directory: join(options.homeDirectory ?? homedir(), options.stateDirectory ?? ".gd"),
|
|
8
|
+
protectWindowsAcl: true,
|
|
8
9
|
filename: "credentials.json",
|
|
9
10
|
role: "credentials"
|
|
10
11
|
});
|
|
@@ -3,7 +3,6 @@ import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
|
3
3
|
import { createHmac } from "node:crypto";
|
|
4
4
|
import { createReadStream } from "node:fs";
|
|
5
5
|
import { stat } from "node:fs/promises";
|
|
6
|
-
import OSS from "ali-oss";
|
|
7
6
|
export class ObjectStorageUploadError extends Error {
|
|
8
7
|
constructor(cause) {
|
|
9
8
|
super("素材上传失败。", { cause });
|
|
@@ -63,6 +62,8 @@ function sleepWithSignal(milliseconds, signal) {
|
|
|
63
62
|
});
|
|
64
63
|
}
|
|
65
64
|
const defaultPutOss = async (input) => {
|
|
65
|
+
input.signal.throwIfAborted();
|
|
66
|
+
const { default: OSS } = await import("ali-oss");
|
|
66
67
|
input.signal.throwIfAborted();
|
|
67
68
|
const client = new OSS({
|
|
68
69
|
accessKeyId: input.token.accessKeyId,
|