@gaoding/cli 2.1.0 → 2.1.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.
- package/README.md +30 -0
- package/contracts/operations/agent.send/input.schema.json +8 -84
- package/contracts/operations/agent.send/output.schema.json +6 -6
- package/contracts/operations/dam.folder.list/input.schema.json +1 -1
- package/contracts/operations/dam.folder.list/output.schema.json +1 -1
- package/contracts/operations/dam.list/input.schema.json +2 -5
- package/contracts/operations/dam.list/output.schema.json +1 -1
- package/contracts/operations/dam.search/input.schema.json +2 -5
- package/contracts/operations/dam.search/output.schema.json +1 -1
- package/contracts/operations/model.get/output.schema.json +6 -5
- package/contracts/operations/model.list/output.schema.json +5 -4
- package/contracts/operations/task.get/output.schema.json +22 -11
- package/contracts/operations/tool.call/models/image-edit-smart.schema.json +7 -5
- package/contracts/operations/tool.call/models/image-edit-standard.schema.json +6 -4
- package/contracts/operations/tool.call/models/image-enhance-smart.schema.json +5 -3
- package/contracts/operations/tool.call/models/image-enhance-standard.schema.json +3 -2
- package/contracts/operations/tool.call/models/image-expand-smart.schema.json +16 -10
- package/contracts/operations/tool.call/models/image-expand-standard.schema.json +13 -8
- package/contracts/operations/tool.call/models/image-layers-layout.schema.json +3 -2
- package/contracts/operations/tool.call/models/image-layers-smart.schema.json +3 -4
- package/contracts/operations/tool.call/models/image-matting-smart.schema.json +6 -4
- package/contracts/operations/tool.call/models/image-matting-standard.schema.json +3 -2
- package/contracts/operations/tool.call/models/image-ocr.schema.json +3 -2
- package/contracts/operations/tool.call/models/image-remove-smart.schema.json +6 -4
- package/contracts/operations/tool.call/models/image-remove-standard.schema.json +4 -3
- package/contracts/operations/tool.call/models/image-text-edit.schema.json +5 -3
- package/contracts/operations/tool.call/models/image-vectorize.schema.json +3 -2
- package/contracts/operations/tool.call/models/video-edit-smart.schema.json +6 -6
- package/contracts/operations/tool.call/models/video-enhance-smart.schema.json +7 -4
- package/contracts/operations/tool.call/models/video-enhance-standard.schema.json +5 -3
- package/contracts/operations/tool.call/ocr-payload.schema.json +4 -5
- package/contracts/operations/tool.call/output.schema.json +9 -8
- package/dist/bin/postinstall.js +22 -6
- package/dist/bin/sync-skill.js +33 -0
- package/dist/bin/task-worker.js +2 -2
- package/dist/src/bootstrap/create-cli.js +13 -6
- package/dist/src/bootstrap/create-runtime.js +103 -29
- package/dist/src/bootstrap/run-task-worker.js +6 -2
- package/dist/src/bootstrap/validators.js +87 -151
- package/dist/src/cli/action-binding.js +14 -37
- package/dist/src/cli/agent-commands.js +13 -13
- package/dist/src/cli/auth-commands.js +2 -1
- package/dist/src/cli/creation-help.js +9 -0
- package/dist/src/cli/dam-commands.js +10 -14
- package/dist/src/cli/editor-commands.js +16 -12
- package/dist/src/cli/errors.js +84 -26
- package/dist/src/cli/host-input.js +62 -5
- package/dist/src/cli/model-commands.js +9 -3
- package/dist/src/cli/observed-errors.js +7 -3
- package/dist/src/cli/org-commands.js +3 -1
- package/dist/src/cli/presenter.js +4 -5
- package/dist/src/cli/task-commands.js +6 -2
- package/dist/src/cli/tool-commands.js +12 -11
- package/dist/src/contracts/creation-input.js +20 -17
- package/dist/src/features/agent/creative-agent-adapter.js +6 -2
- package/dist/src/features/agent/creative-protocol.js +8 -29
- package/dist/src/features/agent/resource-authorizer.js +25 -17
- package/dist/src/features/agent/result-reader.js +31 -14
- package/dist/src/features/agent/use-cases.js +6 -31
- package/dist/src/features/auth/credential-store.js +1 -0
- package/dist/src/features/credits/use-cases.js +55 -28
- package/dist/src/features/dam/asset-projection.js +3 -6
- package/dist/src/features/dam/dam-api-adapter.js +30 -15
- package/dist/src/features/dam/object-storage.js +2 -1
- package/dist/src/features/dam/repository-catalog.js +30 -21
- package/dist/src/features/dam/use-cases.js +14 -9
- package/dist/src/features/editor/bridge-client.js +0 -2
- package/dist/src/features/editor/bridge-process.js +3 -2
- package/dist/src/features/editor/public-url.js +1 -36
- package/dist/src/features/editor/session-state.js +1 -0
- package/dist/src/features/editor/session.js +3 -2
- package/dist/src/features/editor/use-cases.js +27 -2
- package/dist/src/features/org/org-service.js +10 -1
- package/dist/src/features/org/use-cases.js +18 -4
- package/dist/src/features/task/process-owner.js +54 -0
- package/dist/src/features/task/store.js +102 -32
- package/dist/src/features/task/task-background.js +8 -4
- package/dist/src/features/task/use-cases.js +184 -84
- package/dist/src/features/tool/argument-paths.js +14 -0
- package/dist/src/features/tool/canvas-copy.js +28 -15
- package/dist/src/features/tool/canvas-matting.js +123 -0
- package/dist/src/features/tool/canvas-media.js +102 -55
- package/dist/src/features/tool/canvas-models.js +66 -33
- package/dist/src/features/tool/canvas-pricing.js +12 -0
- package/dist/src/features/tool/canvas-recovery.js +13 -30
- package/dist/src/features/tool/canvas-results.js +92 -93
- package/dist/src/features/tool/canvas-tool-adapter.js +134 -157
- package/dist/src/features/tool/canvas-video.js +44 -37
- package/dist/src/features/tool/catalog.js +2 -23
- package/dist/src/features/tool/dynamic-schema.js +42 -46
- package/dist/src/features/tool/ffprobe-executable.js +21 -0
- package/dist/src/features/tool/mns-catalog-adapter.js +61 -24
- package/dist/src/features/tool/resource-authorizer.js +11 -3
- package/dist/src/features/tool/tool-api-adapter.js +73 -82
- package/dist/src/features/tool/tool-definitions.js +23 -0
- package/dist/src/features/tool/tool-errors.js +25 -0
- package/dist/src/features/tool/tool-output.js +15 -0
- package/dist/src/features/tool/use-cases.js +74 -98
- package/dist/src/features/update/package-manager.js +124 -0
- package/dist/src/features/update/update-service.js +195 -55
- 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/media-type.js +46 -0
- package/dist/src/platform/open-browser.js +5 -2
- package/dist/src/platform/public-url.js +35 -0
- package/dist/src/platform/remote-error-evidence.js +33 -6
- package/dist/src/platform/resource-auth-key.js +35 -1
- package/dist/src/platform/safe-upload-file.js +38 -44
- package/dist/src/platform/schema-compiler.js +16 -0
- package/dist/src/platform/signature.js +2 -2
- package/dist/src/platform/signed-http-transport.js +4 -1
- package/dist/src/platform/url-safety.js +6 -1
- package/dist/src/platform/webm-header.js +41 -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/command-route.js +38 -0
- package/dist/src/telemetry/command-routes.json +1 -0
- package/dist/src/telemetry/failure-summary.js +3 -3
- package/dist/src/telemetry/invocation.js +1 -2
- package/dist/src/telemetry/process-errors.js +17 -33
- package/dist/src/telemetry/sanitize.js +19 -4
- package/dist/src/telemetry/sls-sink.js +45 -20
- package/package.json +4 -4
- package/skills/gd-cli/SKILL.md +18 -5
- package/skills/gd-cli/references/agent.md +9 -4
- package/skills/gd-cli/references/creation.md +3 -1
- package/skills/gd-cli/references/editor.md +7 -5
- package/skills/gd-cli/references/errors.md +19 -8
- package/skills/gd-cli/references/matting.md +3 -5
- package/skills/gd-cli/references/media-tools.md +10 -4
- package/skills/gd-cli/references/tool.md +9 -15
|
@@ -35,8 +35,8 @@ export function createCli(runtime, options) {
|
|
|
35
35
|
writeErr: () => undefined
|
|
36
36
|
});
|
|
37
37
|
program.addHelpText("after", runtime.product.id === "insmind"
|
|
38
|
-
? "\nstdout contains command results; human-readable views can include an update notice. stderr contains progress, warnings and errors. Fixed JSON commands, --json and --json-errors use {error:{code,message,details?,trace_id?}} for final errors. stderr may contain multiple messages.\nExit codes: 0 success, 1 execution failure, 2 invalid input, 130 local interruption; dispatched work may still be active.\n"
|
|
39
|
-
: "\nstdout 输出命令结果,人类可读视图可以附带升级提醒;stderr 输出进度、警告和错误。固定 JSON 命令、--json 和 --json-errors 的最终错误使用 {error:{code,message,details?,trace_id?}},stderr 可能包含多条信息。\n退出码:0
|
|
38
|
+
? "\nChoose by the object and goal: tool list discovers generation and processing of attached images/videos (including text replacement, layers and vectors); editor operates elements in a connected work; agent send handles planning and multi-turn creation. A capability absent from Editor may be available as a Tool.\nRead the selected command's --help. Use its advertised --schema for JSON structure and model get for live model inputs. --input takes a JSON file path or - with complete JSON on stdin; media URI fields inside JSON take URLs.\nstdout contains command results; human-readable views can include an update notice. stderr contains progress, warnings and errors. Fixed JSON commands, --json and --json-errors use {error:{code,message,details?,trace_id?}} for final errors. stderr may contain multiple messages.\nExit codes: 0 command success (async acceptance and successful queries still require checking task state), 1 execution failure, 2 invalid input, 130 local interruption; dispatched work may still be active.\n"
|
|
39
|
+
: "\n按对象和目标选入口:tool list 发现生成及附件图片/视频处理能力(含改字、分层、矢量化);editor 操作已连接作品的元素;agent send 负责策划和持续多轮创作。Editor 未提供的操作仍可能由 Tool 提供。\n先读所选命令 --help;结构化输入从其公开的 --schema 发现,模型参数从 model get 查询。--input 接收 JSON 文件路径,或用 - 从 stdin 传完整 JSON;JSON 内的媒体 URI 字段接收 URL。\nstdout 输出命令结果,人类可读视图可以附带升级提醒;stderr 输出进度、警告和错误。固定 JSON 命令、--json 和 --json-errors 的最终错误使用 {error:{code,message,details?,trace_id?}},stderr 可能包含多条信息。\n退出码:0 命令成功(异步受理、查询成功仍须查看任务状态),1 执行失败,2 输入无效,130 本地中断;已派发的工作可能仍在继续。\n");
|
|
40
40
|
if (runtime.product.id === "insmind") {
|
|
41
41
|
program.option("--locale <locale>", "locale for service-owned business descriptions");
|
|
42
42
|
}
|
|
@@ -109,12 +109,19 @@ export async function executeCli(options) {
|
|
|
109
109
|
const { cli_task_id: taskId, operation } = options.telemetry.creationContext();
|
|
110
110
|
if (taskId && outcome.failure && ["agent.send", "tool.call"].includes(operation)) {
|
|
111
111
|
const details = outcome.failure.details;
|
|
112
|
-
|
|
112
|
+
const refused = ["TOOL_TASK_FAILED", "INSUFFICIENT_CREDITS"].includes(outcome.failure.code)
|
|
113
|
+
|| ["audit_rejected", "input_audit_rejected", "output_audit_rejected"].includes(details?.reason ?? "");
|
|
114
|
+
const recovery = { ...details, cli_task_id: taskId };
|
|
115
|
+
if (outcome.exitCode !== 2 && !refused && details?.phase !== "input_upload_before_dispatch") {
|
|
116
|
+
recovery.next_steps = [
|
|
113
117
|
...(details?.next_steps ?? []),
|
|
114
118
|
`${options.product?.commandName ?? "gd-cli"} task get ${taskId}`,
|
|
115
|
-
options.product?.id === "insmind"
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
options.product?.id === "insmind"
|
|
120
|
+
? "If the outcome is still unknown, tell the user and keep this ID for recovery. Do not start another creation."
|
|
121
|
+
: "原任务结果仍未知时,向用户说明并保留此 ID 供取回。不要另发创作。"
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
outcome.failure.details = recovery;
|
|
118
125
|
}
|
|
119
126
|
const telemetryError = classifyTelemetryError(error, { aborted: isInterruption(error, options.signal),
|
|
120
127
|
operation: options.telemetry.creationContext().operation, failureStage: options.telemetry.failureStage(error), ...(options.product ? { product: options.product } : {}) });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { canvasModelBindings } from "../features/tool/canvas-models.js";
|
|
1
2
|
import { createWindAnalytics } from "../analytics/wind.js";
|
|
2
3
|
import { taskScope } from "../features/task/store.js";
|
|
3
4
|
import { noticeWriter, sameTerminal } from "../features/update/notice-output.js";
|
|
@@ -6,8 +7,10 @@ import { TaskNotFoundError } from "../features/task/use-cases.js";
|
|
|
6
7
|
import { homedir } from "node:os";
|
|
7
8
|
import { createTaskBackgroundLauncher, TaskBackgroundError } from "../features/task/task-background.js";
|
|
8
9
|
import { createTaskStore } from "../features/task/store.js";
|
|
9
|
-
import { createTaskUseCases } from "../features/task/use-cases.js";
|
|
10
|
+
import { createTaskUseCases, taskStartedNotice } from "../features/task/use-cases.js";
|
|
10
11
|
import { readAgentResult } from "../features/agent/result-reader.js";
|
|
12
|
+
import { createToolOutputVerifier, presentToolContent } from "../features/tool/tool-output.js";
|
|
13
|
+
import { RemoteProtocolError } from "../platform/remote-protocol.js";
|
|
11
14
|
import { queryToolResult, ToolTaskFailedError, ToolTaskCanceledError } from "../features/tool/tool-api-adapter.js";
|
|
12
15
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
13
16
|
import { dirname, join } from "node:path";
|
|
@@ -91,9 +94,13 @@ export function createProductionRuntime(options = {}) {
|
|
|
91
94
|
} : undefined;
|
|
92
95
|
const now = options.now ?? (() => new Date());
|
|
93
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");
|
|
94
100
|
const telemetrySink = options.telemetrySink ?? createSlsTelemetrySink({
|
|
95
101
|
fetch, trackingUrl: options.telemetryTrackingUrl ?? product.telemetryUrl,
|
|
96
102
|
background: options.telemetryBackground ?? true,
|
|
103
|
+
reporterFlushes,
|
|
97
104
|
directory: join(options.homeDirectory ?? homedir(), product.stateDirectory, "telemetry", "v6"),
|
|
98
105
|
now: () => now().getTime()
|
|
99
106
|
});
|
|
@@ -108,7 +115,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
108
115
|
classifyError: error => classifyTelemetryError(error, { product, operation: telemetry.creationContext().operation, failureStage: telemetry.failureStage(error) }),
|
|
109
116
|
...(telemetrySink.enqueue ? { onEvent: (event) => telemetrySink.enqueue([event]) } : {})
|
|
110
117
|
});
|
|
111
|
-
telemetry.annotate({ installation_owner: installationOwner, ...
|
|
118
|
+
telemetry.annotate({ installation_owner: installationOwner, ...host });
|
|
112
119
|
// Explicit test transport enables SDK tests; test-mode child processes never emit real analytics.
|
|
113
120
|
const analytics = options.analytics ?? (telemetryEnvironment === "production" || options.windFetch
|
|
114
121
|
? createWindAnalytics({ product: product.id, version: options.telemetryVersion ?? primarySkill.version,
|
|
@@ -189,7 +196,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
189
196
|
});
|
|
190
197
|
const org = createOrgUseCases({
|
|
191
198
|
store,
|
|
192
|
-
org: createOrgService({ transport: orgTransport }),
|
|
199
|
+
org: createOrgService({ transport: orgTransport, onPartial: count => partialWarning("ORG_LIST_PARTIAL", `有 ${count} 条组织记录无法读取,已返回可确认的组织。`, `${count} organization record(s) could not be read.`) }),
|
|
193
200
|
sso,
|
|
194
201
|
telemetry,
|
|
195
202
|
...(product.exposesOrganizations
|
|
@@ -214,6 +221,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
214
221
|
});
|
|
215
222
|
const credits = createCreditsUseCases({
|
|
216
223
|
transport: creditsTransport,
|
|
224
|
+
onPartial: () => partialWarning("CREDITS_RECORDS_PARTIAL", "部分账单记录或可选字段无法表示,已返回可确认的流水;不要据此推算完整账单。", "Some billing records or optional fields could not be represented. Known records are included; do not infer a complete bill."),
|
|
217
225
|
billingUnit: product.billingUnit,
|
|
218
226
|
now
|
|
219
227
|
});
|
|
@@ -227,6 +235,10 @@ export function createProductionRuntime(options = {}) {
|
|
|
227
235
|
writeError: io.writeError,
|
|
228
236
|
product
|
|
229
237
|
});
|
|
238
|
+
function partialWarning(code, zh, en) {
|
|
239
|
+
telemetry.annotate({ warning_codes: [code] });
|
|
240
|
+
presenter.warning(text(zh, en));
|
|
241
|
+
}
|
|
230
242
|
const browser = createBrowserOpener();
|
|
231
243
|
const validators = createContractValidators({
|
|
232
244
|
organizations: product.exposesOrganizations
|
|
@@ -238,8 +250,15 @@ export function createProductionRuntime(options = {}) {
|
|
|
238
250
|
? { invalidModelWarning: (count) => `Ignored ${count} invalid model configuration${count === 1 ? "" : "s"}.` }
|
|
239
251
|
: {})
|
|
240
252
|
}) });
|
|
241
|
-
const damApi = createDamApiAdapter({
|
|
242
|
-
|
|
253
|
+
const damApi = createDamApiAdapter({
|
|
254
|
+
transport: damTransport,
|
|
255
|
+
onPartial: count => partialWarning("DAM_LIST_PARTIAL", `有 ${count} 条素材库记录无法表示,已返回其余记录。`, `${count} unreadable record(s); the other records are included.`),
|
|
256
|
+
onPaginationFallback: () => partialWarning("DAM_PAGINATION_INCOMPLETE", "服务未提供完整分页信息;缺失的总数或结束标记按本页结果推导。", "The service omitted pagination information; a missing total or end marker was inferred from this page.")
|
|
257
|
+
});
|
|
258
|
+
const damRepositories = createDamRepositoryCatalog({ transport: damTransport, onPartial: source => {
|
|
259
|
+
const label = source === "team" ? "团队" : source === "personal" ? "个人" : "企业";
|
|
260
|
+
partialWarning("DAM_REPOSITORIES_PARTIAL", `${label}库来源或其中部分记录无法读取,已列出可确认的资源库。`, `The ${source} repository source was unavailable or incomplete. Known repositories are included.`);
|
|
261
|
+
} });
|
|
243
262
|
const damOperations = createDamOperationExecutor({
|
|
244
263
|
now: () => now().getTime(),
|
|
245
264
|
sleep: async (milliseconds, signal) => {
|
|
@@ -292,7 +311,14 @@ export function createProductionRuntime(options = {}) {
|
|
|
292
311
|
traceparent: () => telemetry.traceparent(),
|
|
293
312
|
...(businessHeaders ? { businessHeaders } : {})
|
|
294
313
|
}) });
|
|
295
|
-
const
|
|
314
|
+
const onPartialResourceFailure = (error) => {
|
|
315
|
+
if (!(error instanceof RemoteRequestError || error instanceof RemoteProtocolError)
|
|
316
|
+
|| !["RESOURCE_AUTH_REQUEST_FAILED", "RESOURCE_AUTH_INVALID_RESPONSE"].includes(error.diagnosticReason ?? ""))
|
|
317
|
+
return false;
|
|
318
|
+
partialWarning("RESOURCE_AUTH_PARTIAL", "部分私有资源链接尚未取得访问授权;已保留原链接及其他可用内容,请使用原任务再次取件,不要重做。", "Some private links could not be authorized. The original links and other content are included. Query the same task; do not resubmit.");
|
|
319
|
+
return true;
|
|
320
|
+
};
|
|
321
|
+
const resourceAuthorizer = createAgentResourceAuthorizer({ authKeys: resourceAuthKeys, onPartialResourceFailure });
|
|
296
322
|
const accessPolicies = createAccessPolicies({ store, now, refreshCurrentOrganization: org.refreshCurrentOrganization });
|
|
297
323
|
const authorizeTaskAccess = async (state, signal) => {
|
|
298
324
|
await telemetry.stage("access", async () => {
|
|
@@ -304,24 +330,59 @@ export function createProductionRuntime(options = {}) {
|
|
|
304
330
|
}
|
|
305
331
|
});
|
|
306
332
|
};
|
|
307
|
-
const authorizeTaskResult = async (result, state, signal,
|
|
333
|
+
const authorizeTaskResult = async (result, state, signal, source = "stored") => {
|
|
308
334
|
if ("message" in result)
|
|
309
335
|
validators.agentSendOutput(result);
|
|
310
336
|
else
|
|
311
337
|
validators.toolCallOutput(result);
|
|
312
338
|
// Bind only if this result actually needs a fresh resource token.
|
|
313
|
-
const taskAuthorizer = createAgentResourceAuthorizer({
|
|
339
|
+
const taskAuthorizer = createAgentResourceAuthorizer({
|
|
340
|
+
onPartialResourceFailure,
|
|
341
|
+
// Re-reading an existing result can repair an expired official link without probing anyone's URLs.
|
|
342
|
+
...(source !== "upstream" ? { onSignedRefreshFailure(error) {
|
|
343
|
+
if (!(error instanceof RemoteRequestError || error instanceof RemoteProtocolError)
|
|
344
|
+
|| !["RESOURCE_AUTH_REQUEST_FAILED", "RESOURCE_AUTH_INVALID_RESPONSE"].includes(error.diagnosticReason ?? ""))
|
|
345
|
+
return false;
|
|
346
|
+
telemetry.annotate({ warning_codes: ["TASK_RESOURCE_REFRESH_UNAVAILABLE"] });
|
|
347
|
+
presenter.warning(text("资源授权暂未更新,已返回原签名链接;如仍无法打开,请稍后用原任务 ID 查询。", "The resource key could not be refreshed. The original signed URL is included; if it cannot be opened, query the same task ID later."));
|
|
348
|
+
return true;
|
|
349
|
+
} } : {}),
|
|
350
|
+
authKeys: {
|
|
314
351
|
async getAuthKey(access, tokenSignal) {
|
|
315
|
-
if (
|
|
352
|
+
if (source === "stored")
|
|
316
353
|
await authorizeTaskAccess(state, tokenSignal);
|
|
317
354
|
return resourceAuthKeys.getAuthKey(access, tokenSignal);
|
|
318
355
|
}
|
|
319
|
-
}
|
|
356
|
+
}
|
|
357
|
+
});
|
|
320
358
|
const access = { credential: state.credential, organizationId: state.organization.id };
|
|
321
359
|
if ("message" in result)
|
|
322
360
|
return taskAuthorizer.authorize(result, access, signal);
|
|
323
361
|
return authorizeToolResources(result, taskAuthorizer, access, signal);
|
|
324
362
|
};
|
|
363
|
+
const canvasMedia = (access) => createCanvasMedia({ fetch, uploader: transientUploader,
|
|
364
|
+
...(access ? { filems: { access, authKeys: resourceAuthKeys } } : {}) });
|
|
365
|
+
const onMissingMedia = (kind) => {
|
|
366
|
+
telemetry.annotate({ warning_codes: ["TOOL_EXPECTED_MEDIA_UNIDENTIFIED"] });
|
|
367
|
+
presenter.warning(text(`已交付服务返回的内容,未发现明确标记为${kind === "video" ? "视频" : "图片"}的资源;请按实际内容交付,勿重新提交。`, `The returned content is included. No resource was identified as ${kind}; report what was received and do not resubmit.`));
|
|
368
|
+
};
|
|
369
|
+
const onUnrepresented = () => {
|
|
370
|
+
telemetry.annotate({ warning_codes: ["TOOL_PART_UNREPRESENTABLE"] });
|
|
371
|
+
presenter.warning(text("已返回可表示的内容,另有无法读取的附件。", "The representable content is included; another attachment could not be read."));
|
|
372
|
+
};
|
|
373
|
+
const verifyToolOutput = createToolOutputVerifier(resourceAuthorizer, onMissingMedia);
|
|
374
|
+
const canvasTools = createCanvasToolAdapter({
|
|
375
|
+
transport: toolTransport, recordTransport: damTransport, resourceAuthorizer, telemetry, media: canvasMedia, onMissingMedia, onUnrepresented, english: product.id === "insmind",
|
|
376
|
+
fallback: createToolApiAdapter({ transport: toolTransport, telemetry, onUnrepresented, verifyOutput: verifyToolOutput }),
|
|
377
|
+
standardMatting: createStandardMatting({ transport: toolTransport, recordTransport: damTransport, media: canvasMedia() })
|
|
378
|
+
});
|
|
379
|
+
const taskFailureNote = (error, operation = telemetry.creationContext().operation) => {
|
|
380
|
+
const outcome = mapCliError(error, { aborted: false, product, operation, failureStage: telemetry.failureStage(error) });
|
|
381
|
+
if (outcome.kind !== "failure")
|
|
382
|
+
return "";
|
|
383
|
+
const details = outcome.failure.details;
|
|
384
|
+
return [outcome.failure.message, details?.remote_code, details?.remote_message].filter(Boolean).join(" ");
|
|
385
|
+
};
|
|
325
386
|
const tasks = createTaskUseCases({
|
|
326
387
|
telemetry,
|
|
327
388
|
...(analytics ? { analytics } : {}),
|
|
@@ -335,6 +396,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
335
396
|
store: createTaskStore({
|
|
336
397
|
...(options.homeDirectory ? { homeDirectory: options.homeDirectory } : {}),
|
|
337
398
|
stateDirectory: product.stateDirectory,
|
|
399
|
+
onUnreadableRecords: count => partialWarning("TASK_LIST_PARTIAL", `有 ${count} 条本地任务记录无法读取,已列出可读取的记录。`, `${count} local task record(s) could not be read. Readable records are included.`),
|
|
338
400
|
validateSummary: task => validators.taskListResult({ tasks: [task] }),
|
|
339
401
|
validate: validators.taskResult
|
|
340
402
|
}),
|
|
@@ -344,12 +406,19 @@ export function createProductionRuntime(options = {}) {
|
|
|
344
406
|
warning: message => presenter.warning(message),
|
|
345
407
|
commandName: product.commandName,
|
|
346
408
|
text,
|
|
347
|
-
failureNote:
|
|
348
|
-
const outcome = mapCliError(error, { aborted: false, product, operation: telemetry.creationContext().operation, failureStage: telemetry.failureStage(error) });
|
|
349
|
-
return outcome.kind === "failure" ? outcome.failure.message : "";
|
|
350
|
-
},
|
|
409
|
+
failureNote: taskFailureNote,
|
|
351
410
|
recovery: {
|
|
352
|
-
authorize
|
|
411
|
+
async authorize(result, state, signal, progress) {
|
|
412
|
+
const authorized = await authorizeTaskResult(result, state, signal);
|
|
413
|
+
const tool = progress?.generation?.tool ?? canvasModelBindings.find(binding => binding[1] === progress?.toolPipeline?.model)?.[0];
|
|
414
|
+
if ("content" in authorized && tool && tool !== "image.ocr" && tool !== "image.layers") {
|
|
415
|
+
if (tool.startsWith("video."))
|
|
416
|
+
presentToolContent(authorized.content, "video", onMissingMedia);
|
|
417
|
+
else if (tool.startsWith("image."))
|
|
418
|
+
presentToolContent(authorized.content, "image", onMissingMedia);
|
|
419
|
+
}
|
|
420
|
+
return authorized;
|
|
421
|
+
},
|
|
353
422
|
async agent(progress, state, signal) {
|
|
354
423
|
if (!progress.contextId || !progress.localMessageId)
|
|
355
424
|
return {
|
|
@@ -361,14 +430,18 @@ export function createProductionRuntime(options = {}) {
|
|
|
361
430
|
credential: state.credential, organizationId: state.organization.id, signal
|
|
362
431
|
});
|
|
363
432
|
return { state: "unknown",
|
|
433
|
+
...(snapshot.usageAmountMissing ? { usageAmountMissing: true } : {}),
|
|
364
434
|
...(snapshot.usageModelMissing ? { usageModelMissing: true } : {}),
|
|
365
435
|
note: snapshot.partialResult
|
|
366
436
|
? text("已找到部分内容,尚未取得完整结果。", "Some content was found, but the complete result has not been received.")
|
|
367
437
|
: text("尚未取得任务结果。", "The task result has not been received."),
|
|
368
|
-
...(snapshot.partialResult ? { partialResult: await authorizeTaskResult(agentOutputWithBillingUnit(snapshot.partialResult, product.billingUnit), state, signal,
|
|
438
|
+
...(snapshot.partialResult ? { partialResult: await authorizeTaskResult(agentOutputWithBillingUnit(snapshot.partialResult, product.billingUnit), state, signal, "upstream") } : {})
|
|
369
439
|
};
|
|
370
440
|
},
|
|
371
441
|
async tool(progress, state, signal) {
|
|
442
|
+
// Never interpret an unpublished candidate's Run receipt as a Dify task.
|
|
443
|
+
if (Object.hasOwn(progress, "toolRun"))
|
|
444
|
+
return { state: "unknown", note: text("该实验版本任务不支持继续远端查询。请保留原任务记录用于排查,不要重复提交。", "Remote recovery is unavailable for this experimental task. Keep its original record for diagnosis; do not resubmit.") };
|
|
372
445
|
if (progress.toolPipeline) {
|
|
373
446
|
const pipeline = progress.toolPipeline;
|
|
374
447
|
await authorizeTaskAccess(state, signal);
|
|
@@ -376,7 +449,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
376
449
|
try {
|
|
377
450
|
recovered = await telemetry.stage("task.query", () => recoverCanvasTool(progress, {
|
|
378
451
|
access: { credential: state.credential, organizationId: state.organization.id }, signal
|
|
379
|
-
}, { transport: toolTransport, media: canvasMedia, english: product.id === "insmind" }));
|
|
452
|
+
}, { transport: toolTransport, onMissingMedia, onUnrepresented, media: canvasMedia({ credential: state.credential, organizationId: state.organization.id }), english: product.id === "insmind" }));
|
|
380
453
|
}
|
|
381
454
|
catch (error) {
|
|
382
455
|
if (!(error instanceof ToolTaskFailedError) && !(error instanceof ToolTaskCanceledError))
|
|
@@ -384,17 +457,18 @@ export function createProductionRuntime(options = {}) {
|
|
|
384
457
|
const outcome = mapCliError(error, { aborted: false, product, operation: "task.get", failureStage: "task.query" });
|
|
385
458
|
return { state: "failed", note: outcome.failure?.message ?? text("本次处理未能完成。", "This processing could not be completed."), failure: error };
|
|
386
459
|
}
|
|
460
|
+
const source = "fromCheckpoint" in recovered && recovered.fromCheckpoint ? "checkpoint" : "upstream";
|
|
387
461
|
if (recovered.state === "complete" && progress.toolUsage)
|
|
388
462
|
return { state: "completed", result: await authorizeTaskResult(toolOutputWithBillingUnit({
|
|
389
463
|
content: recovered.content, usage: progress.toolUsage
|
|
390
|
-
}, product.billingUnit), state, signal,
|
|
464
|
+
}, product.billingUnit), state, signal, source) };
|
|
391
465
|
if (recovered.state === "pending")
|
|
392
466
|
return { state: "running", note: text("任务仍在处理中。", "The task is still processing.") };
|
|
393
467
|
const partialContent = recovered.state === "unknown" ? recovered.content : undefined;
|
|
394
468
|
return { state: "unknown", note: text(`处理停留在 ${pipeline.stage} 阶段,尚未交付完整结果。查询不会重新处理、上传或结算;请保留任务 ID 排查,勿重复提交。`, `Processing reached ${pipeline.stage}; no complete result was delivered. Querying does not process, upload, or settle again. Keep the task ID for diagnosis; do not resubmit.`),
|
|
395
469
|
...(partialContent && progress.toolUsage ? { partialResult: await authorizeTaskResult(toolOutputWithBillingUnit({
|
|
396
470
|
content: partialContent, usage: progress.toolUsage
|
|
397
|
-
}, product.billingUnit), state, signal,
|
|
471
|
+
}, product.billingUnit), state, signal, source) } : {}) };
|
|
398
472
|
}
|
|
399
473
|
if (!progress.remoteTaskId || !progress.toolUsage)
|
|
400
474
|
return {
|
|
@@ -406,7 +480,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
406
480
|
try {
|
|
407
481
|
response = await telemetry.stage("task.query", async () => {
|
|
408
482
|
const result = await queryToolResult(toolTransport, {
|
|
409
|
-
taskId, credential: state.credential, organizationId: state.organization.id, signal,
|
|
483
|
+
taskId, credential: state.credential, organizationId: state.organization.id, signal, onUnrepresented,
|
|
410
484
|
onDifyTaskId: id => telemetry.annotate({ dify_task_id: id })
|
|
411
485
|
});
|
|
412
486
|
if (result.difyTaskId)
|
|
@@ -425,8 +499,8 @@ export function createProductionRuntime(options = {}) {
|
|
|
425
499
|
if (response.state === "pending")
|
|
426
500
|
return { state: "running", note: text("任务仍在处理中。", "The task is still processing.") };
|
|
427
501
|
return { state: "completed", result: await authorizeTaskResult(toolOutputWithBillingUnit({
|
|
428
|
-
content: response.content, usage: progress.toolUsage
|
|
429
|
-
}, product.billingUnit), state, signal,
|
|
502
|
+
content: await verifyToolOutput(response.content, progress.generation?.tool === "video.generate" ? "video" : "image", { access: { credential: state.credential, organizationId: state.organization.id }, signal }), usage: progress.toolUsage
|
|
503
|
+
}, product.billingUnit), state, signal, "upstream") };
|
|
430
504
|
}
|
|
431
505
|
}
|
|
432
506
|
});
|
|
@@ -440,19 +514,17 @@ export function createProductionRuntime(options = {}) {
|
|
|
440
514
|
}),
|
|
441
515
|
telemetry
|
|
442
516
|
}), product.billingUnit);
|
|
443
|
-
const canvasMedia = createCanvasMedia({ fetch, uploader: transientUploader });
|
|
444
517
|
const tool = withToolBillingUnit(createToolUseCases({
|
|
445
518
|
catalog: modelCatalog,
|
|
446
519
|
tools: product.tools,
|
|
447
520
|
...(product.id === "insmind" ? { modelDescription: "Model machine identifier from model list." } : {}),
|
|
448
|
-
execution:
|
|
449
|
-
fallback: createToolApiAdapter({ transport: toolTransport, telemetry }),
|
|
450
|
-
standardMatting: createStandardMatting({ transport: toolTransport, recordTransport: damTransport, media: canvasMedia }) }),
|
|
521
|
+
execution: canvasTools,
|
|
451
522
|
uploader: transientUploader,
|
|
452
523
|
warn: (message) => { presenter.warning(message); },
|
|
453
524
|
telemetry
|
|
454
525
|
}), product.billingUnit);
|
|
455
526
|
const editor = createEditorUseCases({
|
|
527
|
+
onPartial: count => partialWarning("EDITOR_SNAPSHOT_PARTIAL", `有 ${count} 个元素无法表示,已返回其余元素。`, `${count} unsupported element(s); the other elements are included.`),
|
|
456
528
|
session: createEditorSession({
|
|
457
529
|
store: createEditorSessionStateStore({
|
|
458
530
|
...(options.homeDirectory === undefined
|
|
@@ -533,11 +605,13 @@ export function createProductionRuntime(options = {}) {
|
|
|
533
605
|
telemetryEnvironment, telemetryVersion: options.telemetryVersion ?? primarySkill.version, origin: telemetry.creationContext(),
|
|
534
606
|
telemetryTrackingUrl: String(options.telemetryTrackingUrl ?? product.telemetryUrl),
|
|
535
607
|
locale: locale.locale, endpoints: Object.fromEntries(Object.entries(endpoints).map(([key, value]) => [key, String(value)]))
|
|
536
|
-
}, signal, task => {
|
|
608
|
+
}, signal, (task, creationTraceId) => {
|
|
537
609
|
startedId = task.taskId;
|
|
610
|
+
if (creationTraceId)
|
|
611
|
+
telemetry.annotate({ creation_trace_id: creationTraceId });
|
|
538
612
|
telemetry.annotate({ cli_task_id: task.taskId, execution_mode: "async", result_state: task.state });
|
|
539
|
-
presenter.notice(
|
|
540
|
-
});
|
|
613
|
+
presenter.notice(taskStartedNotice(task.taskId, product.commandName, "async", text));
|
|
614
|
+
}, facts => telemetry.annotate(facts));
|
|
541
615
|
}
|
|
542
616
|
catch (error) {
|
|
543
617
|
if (startedId)
|
|
@@ -8,7 +8,9 @@ export async function runTaskWorker(options) {
|
|
|
8
8
|
const { job, signal, send } = options;
|
|
9
9
|
runtime.telemetry.useSignal(signal);
|
|
10
10
|
runtime.telemetry.select({ operation: job.operation, mode: () => "execute" });
|
|
11
|
-
runtime.telemetry.annotate({ ...(job.origin ? {
|
|
11
|
+
runtime.telemetry.annotate({ ...(job.origin ? { host_application: job.origin.host_application ?? "unknown" } : {}),
|
|
12
|
+
...(job.origin ? { creation_trace_id: job.origin.trace_id } : {}),
|
|
13
|
+
account_id: job.state.account?.id, organization_id: job.state.organization.id,
|
|
12
14
|
parameters: { ...job.input }, execution_mode: "async" });
|
|
13
15
|
let completion = { outcome: "success" };
|
|
14
16
|
let started = false;
|
|
@@ -21,6 +23,7 @@ export async function runTaskWorker(options) {
|
|
|
21
23
|
runtime.validators.toolCallInput(job.input);
|
|
22
24
|
await runtime.tasks.track({
|
|
23
25
|
state: job.state,
|
|
26
|
+
signal,
|
|
24
27
|
operation: job.operation,
|
|
25
28
|
label: job.label,
|
|
26
29
|
executionMode: "async",
|
|
@@ -32,7 +35,8 @@ export async function runTaskWorker(options) {
|
|
|
32
35
|
}
|
|
33
36
|
if ((progress.accepted || progress.remoteTaskId) && !accepted) {
|
|
34
37
|
accepted = true;
|
|
35
|
-
send({ type: "accepted", task
|
|
38
|
+
send({ type: "accepted", task,
|
|
39
|
+
...(job.operation === "tool.call" ? { execution_protocol: progress.toolPipeline?.protocol ?? "dify" } : {}) });
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
run: async (observe) => {
|