@insmind/cli 1.8.0 → 1.9.1
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/contracts/operations/model.get/input.schema.json +5 -0
- package/contracts/operations/model.get/output.schema.json +9 -1
- package/contracts/operations/tool.call/canvas-input.schema.json +60 -0
- package/contracts/operations/tool.call/models/image-edit-smart.schema.json +39 -0
- package/contracts/operations/tool.call/models/image-edit-standard.schema.json +31 -0
- package/contracts/operations/tool.call/models/image-enhance-smart.schema.json +26 -0
- package/contracts/operations/tool.call/models/image-enhance-standard.schema.json +25 -0
- package/contracts/operations/tool.call/models/image-expand-smart.schema.json +72 -0
- package/contracts/operations/tool.call/models/image-expand-standard.schema.json +58 -0
- package/contracts/operations/tool.call/models/image-layers-layout.schema.json +20 -0
- package/contracts/operations/tool.call/models/image-layers-smart.schema.json +26 -0
- package/contracts/operations/tool.call/models/image-matting-smart.schema.json +34 -0
- package/contracts/operations/tool.call/models/image-matting-standard.schema.json +24 -0
- package/contracts/operations/tool.call/models/image-ocr.schema.json +20 -0
- package/contracts/operations/tool.call/models/image-remove-smart.schema.json +30 -0
- package/contracts/operations/tool.call/models/image-remove-standard.schema.json +25 -0
- package/contracts/operations/tool.call/models/image-text-edit.schema.json +43 -0
- package/contracts/operations/tool.call/models/image-vectorize.schema.json +20 -0
- package/contracts/operations/tool.call/models/video-edit-smart.schema.json +68 -0
- package/contracts/operations/tool.call/models/video-enhance-smart.schema.json +32 -0
- package/contracts/operations/tool.call/models/video-enhance-standard.schema.json +26 -0
- package/contracts/operations/tool.call/ocr-payload.schema.json +65 -0
- package/contracts/operations/tool.call/output.schema.json +38 -0
- package/contracts/operations/tool.call/template-payload.schema.json +95 -0
- package/dist/bin/insmind-cli.js +31 -24
- package/dist/bin/task-worker.js +4 -1
- package/dist/src/analytics/device.js +2 -2
- package/dist/src/bootstrap/create-cli.js +7 -0
- package/dist/src/bootstrap/create-runtime.js +53 -30
- package/dist/src/bootstrap/run-task-worker.js +5 -1
- package/dist/src/bootstrap/validators.js +11 -4
- package/dist/src/cli/agent-commands.js +1 -0
- package/dist/src/cli/dam-commands.js +3 -3
- package/dist/src/cli/errors.js +63 -15
- package/dist/src/cli/model-commands.js +6 -3
- package/dist/src/cli/observed-errors.js +3 -1
- package/dist/src/cli/tool-commands.js +2 -0
- package/dist/src/contracts/schema.js +4 -1
- package/dist/src/features/agent/creative-agent-adapter.js +37 -11
- package/dist/src/features/agent/creative-protocol.js +31 -10
- package/dist/src/features/agent/creative-stream.js +54 -6
- package/dist/src/features/agent/resource-authorizer.js +1 -0
- package/dist/src/features/agent/result-reader.js +3 -1
- package/dist/src/features/agent/use-cases.js +15 -5
- package/dist/src/features/auth/credential-store.js +6 -10
- package/dist/src/features/auth/sso-service.js +22 -6
- package/dist/src/features/auth/state.js +6 -0
- package/dist/src/features/auth/use-cases.js +90 -32
- package/dist/src/features/dam/asset-projection.js +10 -1
- package/dist/src/features/dam/dam-api-adapter.js +30 -15
- package/dist/src/features/dam/input.js +23 -0
- package/dist/src/features/dam/use-cases.js +32 -22
- package/dist/src/features/task/store.js +5 -5
- package/dist/src/features/task/task-background.js +67 -19
- package/dist/src/features/task/use-cases.js +38 -9
- package/dist/src/features/tool/canvas-copy.js +61 -0
- package/dist/src/features/tool/canvas-media.js +248 -0
- package/dist/src/features/tool/canvas-models.js +109 -0
- package/dist/src/features/tool/canvas-pricing.js +81 -0
- package/dist/src/features/tool/canvas-recovery.js +68 -0
- package/dist/src/features/tool/canvas-results.js +144 -0
- package/dist/src/features/tool/canvas-tool-adapter.js +366 -0
- package/dist/src/features/tool/canvas-video.js +84 -0
- package/dist/src/features/tool/catalog.js +35 -13
- package/dist/src/features/tool/dynamic-schema.js +55 -25
- package/dist/src/features/tool/matting-billing.js +115 -0
- package/dist/src/features/tool/mns-catalog-adapter.js +66 -19
- package/dist/src/features/tool/resource-authorizer.js +34 -0
- package/dist/src/features/tool/scene-catalog-adapter.js +35 -0
- package/dist/src/features/tool/tool-api-adapter.js +29 -17
- package/dist/src/features/tool/use-cases.js +28 -3
- package/dist/src/platform/file-lock.js +58 -15
- package/dist/src/platform/input-uri.js +105 -0
- package/dist/src/platform/local-json-file.js +7 -4
- package/dist/src/platform/remote-error-evidence.js +23 -1
- package/dist/src/platform/safe-upload-file.js +18 -4
- package/dist/src/platform/schema-issues.js +18 -0
- package/dist/src/platform/signed-http-transport.js +77 -16
- package/dist/src/platform/text-output.js +55 -13
- package/dist/src/product/config.js +12 -1
- package/dist/src/telemetry/failure-summary.js +53 -2
- package/dist/src/telemetry/host-diagnostics.js +95 -0
- package/dist/src/telemetry/invocation.js +24 -3
- package/dist/src/telemetry/process-errors.js +2 -1
- package/dist/src/telemetry/sls-sink.js +66 -18
- package/package.json +5 -4
- package/skills/insmind-cli/SKILL.md +2 -0
- package/skills/insmind-cli/references/creation.md +2 -0
- package/skills/insmind-cli/references/generation-constraints.md +3 -1
- package/skills/insmind-cli/references/matting.md +29 -0
- package/skills/insmind-cli/references/media-tools.md +40 -0
- package/skills/insmind-cli/references/tool.md +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
2
2
|
import addFormatsImport, {} from "ajv-formats";
|
|
3
|
-
import {
|
|
3
|
+
import { canvasControlParameterNames } from "./canvas-models.js";
|
|
4
|
+
import { inputValidationSummary, validationIssues } from "../../platform/schema-issues.js";
|
|
5
|
+
import { canonicalizeInputFileUris } from "../../platform/input-uri.js";
|
|
4
6
|
import { ToolInputError } from "./catalog.js";
|
|
5
7
|
function parameterSchema(parameter, includeBounds = false) {
|
|
6
8
|
const common = {
|
|
@@ -12,9 +14,9 @@ function parameterSchema(parameter, includeBounds = false) {
|
|
|
12
14
|
if (parameter.type === "uri[]") {
|
|
13
15
|
return { type: "array", items: { type: "string", format: "uri" }, ...common };
|
|
14
16
|
}
|
|
15
|
-
if (parameter.type === "number") {
|
|
17
|
+
if (parameter.type === "number" || parameter.type === "integer") {
|
|
16
18
|
return {
|
|
17
|
-
type:
|
|
19
|
+
type: parameter.type,
|
|
18
20
|
...(includeBounds && parameter.minimum !== undefined
|
|
19
21
|
? { minimum: parameter.minimum }
|
|
20
22
|
: {}),
|
|
@@ -24,6 +26,9 @@ function parameterSchema(parameter, includeBounds = false) {
|
|
|
24
26
|
...common
|
|
25
27
|
};
|
|
26
28
|
}
|
|
29
|
+
if (["boolean", "object", "array"].includes(parameter.type)) {
|
|
30
|
+
return { type: parameter.type, ...common };
|
|
31
|
+
}
|
|
27
32
|
return {
|
|
28
33
|
type: "string",
|
|
29
34
|
...(parameter.options === undefined
|
|
@@ -33,6 +38,9 @@ function parameterSchema(parameter, includeBounds = false) {
|
|
|
33
38
|
};
|
|
34
39
|
}
|
|
35
40
|
function sameShape(left, right) {
|
|
41
|
+
if (left.type === "object" || left.type === "array" || right.type === "object" || right.type === "array") {
|
|
42
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
43
|
+
}
|
|
36
44
|
return left.type === right.type
|
|
37
45
|
&& left.format === right.format
|
|
38
46
|
&& left.items?.format === right.items?.format;
|
|
@@ -68,10 +76,13 @@ export function buildToolArgumentsSchema(catalog, tool, modelDescription = "要
|
|
|
68
76
|
}
|
|
69
77
|
};
|
|
70
78
|
for (const model of models) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
const selected = model.inputSchema ? buildModelArgumentsSchema(model).properties
|
|
80
|
+
: Object.fromEntries(model.parameters.map(parameter => [parameter.name, parameterSchema(parameter)]));
|
|
81
|
+
for (const [name, next] of Object.entries(selected)) {
|
|
82
|
+
if (name === "model")
|
|
83
|
+
continue;
|
|
84
|
+
const current = properties[name];
|
|
85
|
+
properties[name] = current === undefined ? next : mergeSchema(current, next);
|
|
75
86
|
}
|
|
76
87
|
}
|
|
77
88
|
return {
|
|
@@ -84,6 +95,8 @@ export function buildToolArgumentsSchema(catalog, tool, modelDescription = "要
|
|
|
84
95
|
};
|
|
85
96
|
}
|
|
86
97
|
export function buildModelArgumentsSchema(model) {
|
|
98
|
+
if (model.inputSchema)
|
|
99
|
+
return structuredClone(model.inputSchema);
|
|
87
100
|
const properties = {
|
|
88
101
|
model: {
|
|
89
102
|
type: "string",
|
|
@@ -117,9 +130,10 @@ function controlArgumentsValidator(model) {
|
|
|
117
130
|
for (const parameter of model.parameters) {
|
|
118
131
|
if (parameter.name === "prompt"
|
|
119
132
|
|| parameter.type === "uri"
|
|
120
|
-
|| parameter.type === "uri[]"
|
|
133
|
+
|| parameter.type === "uri[]"
|
|
134
|
+
|| (model.execution?.kind === "canvas" && !canvasControlParameterNames.has(parameter.name)))
|
|
121
135
|
continue;
|
|
122
|
-
properties[parameter.name] =
|
|
136
|
+
properties[parameter.name] = buildModelArgumentsSchema(model).properties[parameter.name];
|
|
123
137
|
}
|
|
124
138
|
return ajv.compile({
|
|
125
139
|
type: "object",
|
|
@@ -130,32 +144,48 @@ function controlArgumentsValidator(model) {
|
|
|
130
144
|
}
|
|
131
145
|
export function assertModelArguments(model, value) {
|
|
132
146
|
const validate = validator(model);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
throw new ToolInputError("model_parameters", "/arguments");
|
|
147
|
+
canonicalizeInputFileUris(value, validate.schema);
|
|
148
|
+
if (!validate(value)) {
|
|
149
|
+
const issues = validationIssues(validate.errors, value, validate.schema);
|
|
150
|
+
throw Object.assign(new ToolInputError("model_parameters", "/arguments", issues), { diagnosticSummary: inputValidationSummary(issues, value, "/arguments") });
|
|
151
|
+
}
|
|
152
|
+
const stepIssues = sliderStepIssues(model, value);
|
|
153
|
+
if (stepIssues.length) {
|
|
154
|
+
throw Object.assign(new ToolInputError("model_parameters", "/arguments", stepIssues), { diagnosticSummary: inputValidationSummary(stepIssues, value, "/arguments") });
|
|
137
155
|
}
|
|
138
156
|
}
|
|
139
|
-
function
|
|
140
|
-
|
|
157
|
+
function sliderStepIssues(model, value) {
|
|
158
|
+
const issues = [];
|
|
159
|
+
for (const parameter of model.parameters) {
|
|
141
160
|
if (parameter.step === undefined || !Object.hasOwn(value, parameter.name))
|
|
142
|
-
|
|
161
|
+
continue;
|
|
143
162
|
const candidate = value[parameter.name];
|
|
144
163
|
const minimum = parameter.minimum;
|
|
145
|
-
|
|
146
|
-
|
|
164
|
+
let valid = false;
|
|
165
|
+
if (typeof candidate === "number" && minimum !== undefined && parameter.step > 0) {
|
|
166
|
+
const steps = (candidate - minimum) / parameter.step;
|
|
167
|
+
const nearestStep = Math.round(steps);
|
|
168
|
+
const expected = minimum + nearestStep * parameter.step;
|
|
169
|
+
const tolerance = Number.EPSILON * Math.max(1, Math.abs(candidate), Math.abs(expected), Math.abs(minimum), Math.abs(nearestStep * parameter.step)) * 2;
|
|
170
|
+
valid = Math.abs(candidate - expected) <= tolerance;
|
|
147
171
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
172
|
+
if (!valid)
|
|
173
|
+
issues.push({
|
|
174
|
+
field: `/${parameter.name.replace(/~/gu, "~0").replace(/\//gu, "~1")}`.slice(0, 256),
|
|
175
|
+
rule: "step",
|
|
176
|
+
message: minimum === undefined || parameter.step <= 0
|
|
177
|
+
? "must match the model's slider configuration"
|
|
178
|
+
: `must be ${minimum} plus a whole number of steps of ${parameter.step}`
|
|
179
|
+
});
|
|
180
|
+
if (issues.length === 8)
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
return issues;
|
|
154
184
|
}
|
|
155
185
|
export function modelControlArgumentsAreValid(model, value) {
|
|
156
186
|
return typeof value === "object"
|
|
157
187
|
&& value !== null
|
|
158
188
|
&& !Array.isArray(value)
|
|
159
189
|
&& controlArgumentsValidator(model)(value)
|
|
160
|
-
&&
|
|
190
|
+
&& sliderStepIssues(model, value).length === 0;
|
|
161
191
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { constants, createPublicKey, publicEncrypt, randomBytes, verify } from "node:crypto";
|
|
2
|
+
import { withResponseDiagnostics } from "../../platform/signed-http-transport.js";
|
|
3
|
+
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
4
|
+
import { remoteErrorEvidence } from "../../platform/remote-error-evidence.js";
|
|
5
|
+
import { record } from "./canvas-results.js";
|
|
6
|
+
import { ToolTaskFailedError, ToolInsufficientCreditsError } from "./tool-api-adapter.js";
|
|
7
|
+
// Public verification/encryption key used by the existing matting rights service.
|
|
8
|
+
const serviceKey = `-----BEGIN RSA PUBLIC KEY-----
|
|
9
|
+
MIGJAoGBANVv3G1++sfQjoTLN6pOU0ooMzAdRf3W1SItK1MJbXcg6tdBRTfvraso
|
|
10
|
+
4MBNJ6TDOKB2ffO7MtaFHHCo2mxS7/WQF1IJbojXzXt35pja+SsMnuI+050Piwwy
|
|
11
|
+
O/YHzh9Idr3qaXCzOnkfs6JNOKT50pp4xs3b0U5ZXytg4eRTQ1eXAgMBAAE=
|
|
12
|
+
-----END RSA PUBLIC KEY-----`;
|
|
13
|
+
/** NodeRSA's OAEP/SHA-1 chunking, retained at the service boundary. */
|
|
14
|
+
export function encryptMattingParameters(text, key = serviceKey) {
|
|
15
|
+
const publicKey = createPublicKey(key);
|
|
16
|
+
const keyBytes = Math.ceil(publicKey.asymmetricKeyDetails.modulusLength / 8);
|
|
17
|
+
const data = Buffer.from(text);
|
|
18
|
+
const blocks = Math.ceil(data.length / (keyBytes - 42));
|
|
19
|
+
const blockSize = Math.ceil(data.length / blocks);
|
|
20
|
+
const encrypted = [];
|
|
21
|
+
for (let offset = 0; offset < data.length; offset += blockSize) {
|
|
22
|
+
encrypted.push(publicEncrypt({ key: publicKey, padding: constants.RSA_PKCS1_OAEP_PADDING, oaepHash: "sha1" }, data.subarray(offset, offset + blockSize)));
|
|
23
|
+
}
|
|
24
|
+
return Buffer.concat(encrypted).toString("base64");
|
|
25
|
+
}
|
|
26
|
+
export function createMattingRights(dependencies) {
|
|
27
|
+
const { transport } = dependencies;
|
|
28
|
+
return async function rights(path, parameters, context) {
|
|
29
|
+
return withResponseDiagnostics(async (onResponse) => {
|
|
30
|
+
const code = `0.${randomBytes(12).readBigUInt64BE().toString()}`;
|
|
31
|
+
const plaintext = `gaoding?key=${randomBytes(18).toString("base64url")}×tamp=${Date.now()}&verify_code=${code}&${parameters}`;
|
|
32
|
+
const result = await transport.postJson({ path, body: { data: encryptMattingParameters(plaintext, dependencies.key ?? serviceKey) },
|
|
33
|
+
...context.access, signal: context.signal, onResponse });
|
|
34
|
+
if (!record(result))
|
|
35
|
+
throw new RemoteProtocolError();
|
|
36
|
+
if (result.code !== undefined && result.code !== 0 && result.code !== "0")
|
|
37
|
+
throw new ToolTaskFailedError(remoteErrorEvidence(result));
|
|
38
|
+
if (typeof result.export_permit !== "string" || !verify("RSA-SHA256", Buffer.from(code), dependencies.key ?? serviceKey, Buffer.from(result.export_permit, "base64"))
|
|
39
|
+
|| typeof result.used_count !== "number" || !Number.isFinite(result.used_count) || result.used_count < 0) {
|
|
40
|
+
throw new RemoteProtocolError({}, undefined, "MATTING_BILLING_VERIFICATION_FAILED");
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function createStandardMatting(dependencies) {
|
|
47
|
+
const { transport, media, recordTransport } = dependencies;
|
|
48
|
+
const rights = createMattingRights(dependencies);
|
|
49
|
+
return async (source, context, useCount, compute) => {
|
|
50
|
+
const precheck = () => rights("/open/editor/mattings/billing/precheck/v2", `use_count=${useCount}&image_quality=standard`, context);
|
|
51
|
+
const quote = await precheck();
|
|
52
|
+
if (quote.need_deduct !== undefined && typeof quote.need_deduct !== "boolean")
|
|
53
|
+
throw new RemoteProtocolError();
|
|
54
|
+
if (quote.need_deduct === true || quote.need_deduct === undefined && Number(quote.used_count) > 0) {
|
|
55
|
+
await withResponseDiagnostics(async (onResponse) => {
|
|
56
|
+
const balances = await transport.getJson({ path: "/trade/rights-overview", query: { goods_type_enums: "GAODOU" }, ...context.access, signal: context.signal, onResponse });
|
|
57
|
+
if (!Array.isArray(balances))
|
|
58
|
+
throw new RemoteProtocolError();
|
|
59
|
+
const item = balances.find(item => record(item) && item.goods_type_enum === "GAODOU" && item.identifier === "GAODOU");
|
|
60
|
+
if (!record(item))
|
|
61
|
+
throw new RemoteProtocolError();
|
|
62
|
+
const value = (raw) => { if ((typeof raw !== "number" && typeof raw !== "string") || raw === "" || !Number.isFinite(Number(raw)))
|
|
63
|
+
throw new RemoteProtocolError(); return Number(raw); };
|
|
64
|
+
const total = value(item.total), used = value(item.used), pending = value(item.wait);
|
|
65
|
+
const accountAvailable = total - used - pending;
|
|
66
|
+
const memberLimit = item.member_period_limit === undefined || item.member_period_limit === null ? undefined : value(item.member_period_limit);
|
|
67
|
+
const memberUsed = memberLimit === undefined ? undefined : value(item.member_period_used ?? 0);
|
|
68
|
+
const available = memberLimit === undefined ? accountAvailable : Math.min(accountAvailable, memberLimit - memberUsed);
|
|
69
|
+
if (available < Number(quote.used_count))
|
|
70
|
+
throw Object.assign(new ToolInsufficientCreditsError(), {
|
|
71
|
+
diagnosticSummary: { quotaDecisionSource: "cli_precheck", quotaUnit: "gaodou",
|
|
72
|
+
quotaLimitScope: memberLimit !== undefined && memberLimit - memberUsed < accountAvailable ? "member_period" : "account",
|
|
73
|
+
quotaTotal: total, quotaUsed: used, quotaPending: pending, quotaAvailable: available, quotaRequired: Number(quote.used_count),
|
|
74
|
+
...(memberLimit === undefined ? {} : { quotaMemberLimit: memberLimit, quotaMemberUsed: memberUsed }) }
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const repositories = await recordTransport.getJson({ path: "/tb-dam/repositories", ...context.access, signal: context.signal });
|
|
79
|
+
if (!Array.isArray(repositories))
|
|
80
|
+
throw new RemoteProtocolError();
|
|
81
|
+
const draft = repositories.find(item => record(item) && item.type === 6);
|
|
82
|
+
if (!record(draft) || typeof draft.repository_id !== "string")
|
|
83
|
+
throw new RemoteProtocolError({}, undefined, "MATTING_DRAFT_REPOSITORY_MISSING");
|
|
84
|
+
const computation = await compute();
|
|
85
|
+
await context.observe?.({ toolPipeline: { protocol: "sync", model: "image-matting-standard", stage: "recording", requiresFinalization: true, partialContent: computation.content } });
|
|
86
|
+
const inputUri = await media.upload(source.bytes, "png", context.access, context.signal);
|
|
87
|
+
const base = { title: "CLI 抠图", description: "CLI 标准抠图", type: "matting", preview_lock: 0, dpi: 72, remark: "", content: "",
|
|
88
|
+
preview: { source_preview: { url: inputUri, width: source.width, height: source.height } }, pri_classify: "MATERIAL", content_format: "gdmatting",
|
|
89
|
+
url: inputUri, repository_id: draft.repository_id, is_hide: true, un_record_recent: true };
|
|
90
|
+
const postRecord = async (body) => {
|
|
91
|
+
const result = await recordTransport.postJson({ path: "/tb-dam/editors/template", body, ...context.access, signal: context.signal });
|
|
92
|
+
if (!record(result) || typeof result.id !== "string" || !result.id)
|
|
93
|
+
throw new RemoteProtocolError({}, undefined, "MATTING_RECORD_INVALID");
|
|
94
|
+
return result.id;
|
|
95
|
+
};
|
|
96
|
+
const refId = await postRecord({ ...base, type: "image" });
|
|
97
|
+
const { width, height } = source;
|
|
98
|
+
const template = { version: "2.16.5", type: "matting", global: { source: "koutu", unit: "px", dpi: 72, showWatermark: false },
|
|
99
|
+
layouts: [{ elements: [{ type: "image", metaInfo: { thirdParty: { matting: { id: refId, refId } } } }] }],
|
|
100
|
+
refs: { [refId]: { id: refId, sourceImage: inputUri, imageHeight: height, imageWidth: width, featheringRadius: 2, lines: [], hairLines: [],
|
|
101
|
+
hairDropColors: [], hairKeepColors: [], pen: [], backgroundColor: null, recoArea: [], recoLines: [], scene: computation.scene,
|
|
102
|
+
crop: { scale: 1, top: 0, left: 0, width, height }, shadow: { offsetX: 0, offsetY: 0, blur: 0, color: "rgba(0,0,0,0)" },
|
|
103
|
+
background: { color: null, image: null, position: ["center", "center"], size: "cover", repeat: "no-repeat" }, outline: [],
|
|
104
|
+
filter: { url: "", strong: 1, name: "", id: 0 }, filename: "CLI 抠图", transform: { rotate: 0 } } } };
|
|
105
|
+
const contentId = await postRecord({ ...base, width, height, origin_url: new URL(inputUri).origin + new URL(inputUri).pathname, content: JSON.stringify(template) });
|
|
106
|
+
const settlement = { contentId, refIds: [refId] };
|
|
107
|
+
await context.observe?.({ toolPipeline: { protocol: "sync", model: "image-matting-standard", stage: "settling", requiresFinalization: true,
|
|
108
|
+
partialContent: computation.content, settlement } });
|
|
109
|
+
await precheck();
|
|
110
|
+
// Never retry this write: an uncertain response must be reconciled through the original record.
|
|
111
|
+
await rights("/open/editor/mattings/complete/v2", `content_id=${contentId}&ref_ids=${refId}&image_quality=standard`, context);
|
|
112
|
+
// The adapter records the validated final result; late cache errors must not discard it.
|
|
113
|
+
return computation.content;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
2
|
+
import { defaultToolDefinitions } from "./catalog.js";
|
|
3
|
+
import { canvasModel, canvasModelBindings, canvasSceneCodes } from "./canvas-models.js";
|
|
4
|
+
import { canvasPricingSupported } from "./canvas-pricing.js";
|
|
2
5
|
export const ROOT_SCENE_CODES = [
|
|
3
6
|
"image-model-art",
|
|
4
7
|
"AI-video-generation"
|
|
5
8
|
];
|
|
9
|
+
export const CATALOG_SCENE_CODES = [...ROOT_SCENE_CODES, ...canvasSceneCodes];
|
|
6
10
|
const rootTools = {
|
|
7
11
|
"image-model-art": "image.generate",
|
|
8
12
|
"AI-video-generation": "video.generate"
|
|
9
13
|
};
|
|
10
|
-
const toolOrder =
|
|
11
|
-
"image.generate": 0,
|
|
12
|
-
"video.generate": 1
|
|
13
|
-
};
|
|
14
|
+
const toolOrder = Object.fromEntries(defaultToolDefinitions.map((tool, index) => [tool.name, index]));
|
|
14
15
|
const multiUriKeys = new Set([
|
|
15
16
|
"image_urls",
|
|
16
17
|
"reference_images",
|
|
@@ -61,8 +62,19 @@ function collectScenes(raw) {
|
|
|
61
62
|
scenes.push({ code: rootCode, tool: rootTools[rootCode], sort: number(root.sort) });
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
for (const rootCode of canvasSceneCodes) {
|
|
66
|
+
const root = roots.get(rootCode);
|
|
67
|
+
if (!root)
|
|
68
|
+
continue;
|
|
69
|
+
const binding = canvasModelBindings.find(binding => binding[3] === rootCode);
|
|
70
|
+
scenes.push({ code: rootCode, tool: binding[0], sort: number(root.sort) });
|
|
71
|
+
// Canvas pickers include first-level children; generic generation keeps its existing root membership.
|
|
72
|
+
for (const child of roots.values()) {
|
|
73
|
+
if (child.parent_id === root.id && child !== root) {
|
|
74
|
+
scenes.push({ code: requiredText(child.code), tool: binding[0], sort: number(child.sort) });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
66
78
|
return scenes;
|
|
67
79
|
}
|
|
68
80
|
function parameter(value) {
|
|
@@ -144,7 +156,7 @@ function range(values, unit) {
|
|
|
144
156
|
const bounds = { minimum: Math.min(...values), maximum: Math.max(...values) };
|
|
145
157
|
return unit === "gaodou" ? { unit, ...bounds } : { unit, ...bounds };
|
|
146
158
|
}
|
|
147
|
-
function normalizeModel(value, scenes) {
|
|
159
|
+
function normalizeModel(value, scenes, english = false) {
|
|
148
160
|
const item = record(value);
|
|
149
161
|
const model = record(item?.model);
|
|
150
162
|
if (item === undefined || model === undefined || !Array.isArray(item.skus)) {
|
|
@@ -152,7 +164,7 @@ function normalizeModel(value, scenes) {
|
|
|
152
164
|
}
|
|
153
165
|
const activeSkus = item.skus.map(record).filter((sku) => sku !== undefined && sku.status === 1);
|
|
154
166
|
if (activeSkus.length === 0)
|
|
155
|
-
return
|
|
167
|
+
return [];
|
|
156
168
|
const code = requiredText(model.code);
|
|
157
169
|
const title = requiredText(model.name);
|
|
158
170
|
if (!Array.isArray(model.scene_categories))
|
|
@@ -164,7 +176,7 @@ function normalizeModel(value, scenes) {
|
|
|
164
176
|
|| left.sort - right.sort);
|
|
165
177
|
const scene = matches[0];
|
|
166
178
|
if (scene === undefined)
|
|
167
|
-
return
|
|
179
|
+
return [];
|
|
168
180
|
if (typeof model.input_field_settings !== "string")
|
|
169
181
|
throw new Error("missing settings");
|
|
170
182
|
const settings = JSON.parse(model.input_field_settings);
|
|
@@ -175,9 +187,10 @@ function normalizeModel(value, scenes) {
|
|
|
175
187
|
.filter((item) => item !== undefined);
|
|
176
188
|
const description = cleanText(model.description);
|
|
177
189
|
const usageDescription = cleanText(model.tool_description);
|
|
178
|
-
const
|
|
179
|
-
? model.output_mime_types
|
|
180
|
-
|
|
190
|
+
const mimeTypes = typeof model.output_mime_types === "string"
|
|
191
|
+
? JSON.parse(model.output_mime_types) : model.output_mime_types;
|
|
192
|
+
const outputMediaTypes = Array.isArray(mimeTypes)
|
|
193
|
+
? mimeTypes.map(text).filter((item) => item !== undefined) : [];
|
|
181
194
|
const costs = activeSkus
|
|
182
195
|
.map((sku) => sku.point_cost)
|
|
183
196
|
.filter((value) => typeof value === "number"
|
|
@@ -188,7 +201,7 @@ function normalizeModel(value, scenes) {
|
|
|
188
201
|
&& Number.isFinite(value) && value >= 0);
|
|
189
202
|
const cost = range(costs, "gaodou");
|
|
190
203
|
const estimatedTime = range(times, "second");
|
|
191
|
-
|
|
204
|
+
const normalized = {
|
|
192
205
|
tool: scene.tool,
|
|
193
206
|
model: code,
|
|
194
207
|
title,
|
|
@@ -201,6 +214,36 @@ function normalizeModel(value, scenes) {
|
|
|
201
214
|
sceneSort: scene.sort,
|
|
202
215
|
modelSort: number(model.sort)
|
|
203
216
|
};
|
|
217
|
+
const result = [];
|
|
218
|
+
for (const match of matches) {
|
|
219
|
+
if (ROOT_SCENE_CODES.some(root => root === match.code)) {
|
|
220
|
+
result.push({ ...normalized, tool: match.tool, sceneSort: match.sort });
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const binding = canvasModelBindings.find(binding => binding[2] === code
|
|
224
|
+
&& (binding[3] === match.code || binding[0] === match.tool));
|
|
225
|
+
if (!binding)
|
|
226
|
+
continue; // A category association is insufficient to execute an unknown protocol.
|
|
227
|
+
if (!cost)
|
|
228
|
+
throw new Error("canvas pricing unavailable");
|
|
229
|
+
if (!canvasPricingSupported(binding[1], { billingComponents: item.billing_components }))
|
|
230
|
+
throw new Error("canvas component pricing unsupported");
|
|
231
|
+
if (binding[1] === "image-layers-smart") {
|
|
232
|
+
const components = Array.isArray(item.billing_components) ? item.billing_components.map(record) : [];
|
|
233
|
+
if (settings.some(value => record(value)?.key === "max_layers" && record(value)?.sku_enable === true)
|
|
234
|
+
|| !components.some(component => component?.parameter_key === "max_layers"
|
|
235
|
+
&& component.quantity_mode === "METERED" && component.price_source === "SKU"
|
|
236
|
+
&& (component.min_quantity === undefined || component.min_quantity === null || component.min_quantity === 0)
|
|
237
|
+
&& (component.max_quantity === undefined || component.max_quantity === null || Number(component.max_quantity) >= 17))) {
|
|
238
|
+
throw new Error("layer metered pricing unavailable");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
result.push(canvasModel({ ...normalized, sceneSort: match.sort }, binding, {
|
|
242
|
+
fields: settings,
|
|
243
|
+
...(item.billing_components === undefined ? {} : { billingComponents: item.billing_components })
|
|
244
|
+
}, english));
|
|
245
|
+
}
|
|
246
|
+
return result;
|
|
204
247
|
}
|
|
205
248
|
export function createMnsCatalogAdapter(dependencies) {
|
|
206
249
|
return {
|
|
@@ -209,7 +252,7 @@ export function createMnsCatalogAdapter(dependencies) {
|
|
|
209
252
|
try {
|
|
210
253
|
const rawScenes = await dependencies.transport.getJson({
|
|
211
254
|
path: "/mns/scene-categories",
|
|
212
|
-
query: { codes:
|
|
255
|
+
query: { codes: CATALOG_SCENE_CODES.join(",") },
|
|
213
256
|
credential: access.credential,
|
|
214
257
|
organizationId: access.organizationId,
|
|
215
258
|
signal
|
|
@@ -217,6 +260,8 @@ export function createMnsCatalogAdapter(dependencies) {
|
|
|
217
260
|
if (!Array.isArray(rawScenes))
|
|
218
261
|
throw new Error("invalid scene response");
|
|
219
262
|
const scenes = collectScenes(rawScenes);
|
|
263
|
+
if (scenes.length === 0)
|
|
264
|
+
return { models: [], warnings: [] };
|
|
220
265
|
const rawModels = await dependencies.transport.getJson({
|
|
221
266
|
path: "/mns/models",
|
|
222
267
|
query: { codes: scenes.map((scene) => scene.code).join(",") },
|
|
@@ -232,11 +277,13 @@ export function createMnsCatalogAdapter(dependencies) {
|
|
|
232
277
|
let invalidCount = 0;
|
|
233
278
|
for (const rawModel of rawModels) {
|
|
234
279
|
try {
|
|
235
|
-
const model
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
280
|
+
for (const model of normalizeModel(rawModel, sceneMap, dependencies.english)) {
|
|
281
|
+
const key = `${model.tool}\0${model.model}`;
|
|
282
|
+
if (seen.has(key))
|
|
283
|
+
continue;
|
|
284
|
+
seen.add(key);
|
|
285
|
+
models.push(model);
|
|
286
|
+
}
|
|
240
287
|
}
|
|
241
288
|
catch {
|
|
242
289
|
invalidCount += 1;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { readOcrPayload } from "./canvas-results.js";
|
|
2
|
+
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
3
|
+
/** Reauthorize both top-level media and the OCR image reference, without interpreting arbitrary text as URLs. */
|
|
4
|
+
export async function authorizeToolResources(output, authorizer, access, signal) {
|
|
5
|
+
const references = [];
|
|
6
|
+
for (const [index, part] of output.content.entries()) {
|
|
7
|
+
if (part.type === "resource_link")
|
|
8
|
+
references.push({ index, uri: part.uri, mediaType: part.mimeType ?? "application/octet-stream" });
|
|
9
|
+
else if (output.usage.model === "image-ocr" && part.type === "resource") {
|
|
10
|
+
const ocr = readOcrPayload(part.resource.text);
|
|
11
|
+
references.push({ index, uri: ocr.image.uri, mediaType: "image/jpeg", ocr });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (!references.length)
|
|
15
|
+
return output;
|
|
16
|
+
const parts = references.map(reference => ({ url: reference.uri, mediaType: reference.mediaType }));
|
|
17
|
+
const authorized = await authorizer.authorize({
|
|
18
|
+
message: { contextId: "resource-authorization", parts: [parts[0], ...parts.slice(1)] },
|
|
19
|
+
usage: { cost: { unit: "gaodou", amount: 0 }, items: [] }
|
|
20
|
+
}, access, signal);
|
|
21
|
+
const content = [...output.content];
|
|
22
|
+
for (const [index, reference] of references.entries()) {
|
|
23
|
+
const part = content[reference.index];
|
|
24
|
+
const authorizedPart = authorized.message.parts[index];
|
|
25
|
+
if (!authorizedPart || !("url" in authorizedPart))
|
|
26
|
+
throw new RemoteProtocolError();
|
|
27
|
+
if (part.type === "resource_link")
|
|
28
|
+
content[reference.index] = { ...part, uri: authorizedPart.url };
|
|
29
|
+
else if (part.type === "resource" && reference.ocr)
|
|
30
|
+
content[reference.index] = { ...part, resource: { ...part.resource,
|
|
31
|
+
text: JSON.stringify({ ...reference.ocr, image: { ...reference.ocr.image, uri: authorizedPart.url } }) } };
|
|
32
|
+
}
|
|
33
|
+
return { ...output, content };
|
|
34
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { canvasModel, canvasModelBindings } from "./canvas-models.js";
|
|
2
|
+
import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
3
|
+
import { record } from "./canvas-results.js";
|
|
4
|
+
const bindingForCode = (code) => canvasModelBindings.find(binding => binding[2] === code)[1];
|
|
5
|
+
/** Legacy scenes have fixed protocols, unlike the MNS model pickers. Availability is read separately. */
|
|
6
|
+
export function createSceneCatalogAdapter(dependencies) {
|
|
7
|
+
return { async load(input) {
|
|
8
|
+
const catalog = await dependencies.catalog.load(input);
|
|
9
|
+
for (const code of ["TextEdit", "new-image-ocr"]) {
|
|
10
|
+
try {
|
|
11
|
+
const scene = await dependencies.transport.getJson({ path: `/gdesign/tool/manage/scenes/code/${code}`, ...input.access, signal: input.signal });
|
|
12
|
+
if (!record(scene) || scene.scene_code !== code || scene.status !== 1)
|
|
13
|
+
continue;
|
|
14
|
+
const binding = canvasModelBindings.find(binding => binding[2] === code);
|
|
15
|
+
const cost = scene.is_free === true ? 0 : typeof scene.point_rights === "number" && Number.isFinite(scene.point_rights) && scene.point_rights >= 0 ? scene.point_rights : undefined;
|
|
16
|
+
if (cost === undefined) {
|
|
17
|
+
catalog.warnings.push(dependencies.english ? `Current pricing is unavailable for ${binding[1]}.` : `${binding[1]} 的当前报价不可用。`);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const raw = { tool: binding[0], model: code, title: binding[4], sceneSort: 0, modelSort: 0, parameters: [],
|
|
21
|
+
...(cost === undefined ? {} : { cost: { unit: "gaodou", minimum: cost, maximum: cost } }),
|
|
22
|
+
outputMediaTypes: code === "new-image-ocr" ? ["application/json"] : ["image/jpeg", "image/png"] };
|
|
23
|
+
catalog.models.push(canvasModel(raw, binding, {}, dependencies.english));
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
input.signal.throwIfAborted();
|
|
27
|
+
if (error instanceof RemoteRequestError && error.status === 404)
|
|
28
|
+
continue;
|
|
29
|
+
// Do not misreport a network failure as a published offline state.
|
|
30
|
+
catalog.warnings.push(dependencies.english ? `Unable to verify the current availability of ${bindingForCode(code)}.` : `暂时无法核实 ${bindingForCode(code)} 的当前可用性。`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return catalog;
|
|
34
|
+
} };
|
|
35
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isInterruption } from "../../platform/interruption.js";
|
|
2
2
|
import { randomInt } from "node:crypto";
|
|
3
3
|
import { setTimeout as delay } from "node:timers/promises";
|
|
4
|
-
import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
4
|
+
import { RemoteRequestError, withResponseDiagnostics } from "../../platform/signed-http-transport.js";
|
|
5
5
|
import { remoteErrorEvidence } from "../../platform/remote-error-evidence.js";
|
|
6
6
|
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
7
7
|
const MAX_JAVA_LONG = 9223372036854775807n;
|
|
@@ -97,7 +97,7 @@ function resourceName(uri) {
|
|
|
97
97
|
return protocolFailure(uri);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
function
|
|
100
|
+
export function normalizeToolContent(value) {
|
|
101
101
|
if (!isRecord(value))
|
|
102
102
|
return protocolFailure(value);
|
|
103
103
|
if (value.type === "text") {
|
|
@@ -138,23 +138,33 @@ export class ToolTaskFailedError extends Error {
|
|
|
138
138
|
this.diagnosticReason = evidence.diagnosticReason;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
+
export class ToolInsufficientCreditsError extends ToolTaskFailedError {
|
|
142
|
+
diagnosticReason = "INSUFFICIENT_CREDITS";
|
|
143
|
+
constructor() {
|
|
144
|
+
super();
|
|
145
|
+
this.name = "ToolInsufficientCreditsError";
|
|
146
|
+
}
|
|
147
|
+
}
|
|
141
148
|
export class ToolTaskCanceledError extends Error {
|
|
142
149
|
diagnosticReason = "TASK_CANCELED";
|
|
143
150
|
constructor() { super("用户已取消生成任务。"); this.name = "ToolTaskCanceledError"; }
|
|
144
151
|
}
|
|
145
152
|
export async function queryToolResult(transport, request) {
|
|
153
|
+
let difyTaskId;
|
|
146
154
|
try {
|
|
147
|
-
return
|
|
155
|
+
return await safePost(transport, {
|
|
148
156
|
credential: request.credential,
|
|
149
157
|
...(request.organizationId === undefined ? {} : { organizationId: request.organizationId }),
|
|
150
158
|
signal: request.signal,
|
|
151
159
|
path: "/gdesign/tool/v1/dify/process/batch",
|
|
152
160
|
body: { task_ids: [request.taskId] }
|
|
153
|
-
}
|
|
161
|
+
}, value => pollResult(value, request.taskId, id => { difyTaskId = id; request.onDifyTaskId?.(id); }, request.normalize));
|
|
154
162
|
}
|
|
155
163
|
catch (error) {
|
|
156
164
|
if (isInterruption(error, request.signal) || error instanceof ToolTaskCanceledError)
|
|
157
165
|
throw error;
|
|
166
|
+
if (error instanceof ToolTaskFailedError)
|
|
167
|
+
return failedPoll(error, difyTaskId);
|
|
158
168
|
const evidence = error instanceof RemoteRequestError || error instanceof RemoteProtocolError
|
|
159
169
|
? { ...(error.remoteCode === undefined ? {} : { remoteCode: error.remoteCode }),
|
|
160
170
|
...(error.remoteBody === undefined ? {} : { remoteBody: error.remoteBody }) } : {};
|
|
@@ -189,7 +199,7 @@ function isJsonRpcError(value) {
|
|
|
189
199
|
&& typeof value.error.message === "string"
|
|
190
200
|
&& value.error.message.trim() !== "";
|
|
191
201
|
}
|
|
192
|
-
function pollResult(value, taskId, onDifyTaskId) {
|
|
202
|
+
function pollResult(value, taskId, onDifyTaskId, normalize = normalizeToolContent) {
|
|
193
203
|
if (!Array.isArray(value))
|
|
194
204
|
return protocolFailure(value);
|
|
195
205
|
const item = value.find((candidate) => isRecord(candidate) && candidate.task_id === taskId);
|
|
@@ -225,15 +235,15 @@ function pollResult(value, taskId, onDifyTaskId) {
|
|
|
225
235
|
if (typeof difyTaskId === "string")
|
|
226
236
|
onDifyTaskId?.(difyTaskId);
|
|
227
237
|
if (Object.prototype.hasOwnProperty.call(inner, "error")) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
238
|
+
if (isJsonRpcError(inner))
|
|
239
|
+
throw new ToolTaskFailedError(remoteErrorEvidence(inner));
|
|
240
|
+
throw new RemoteProtocolError(remoteErrorEvidence(inner));
|
|
231
241
|
}
|
|
232
242
|
if (!isRecord(inner.result)) {
|
|
233
243
|
return failedPoll(new RemoteProtocolError(remoteErrorEvidence(inner)), difyTaskId);
|
|
234
244
|
}
|
|
235
245
|
if (inner.result.isError === true) {
|
|
236
|
-
|
|
246
|
+
throw new ToolTaskFailedError(remoteErrorEvidence(inner));
|
|
237
247
|
}
|
|
238
248
|
if (inner.result.isError !== false) {
|
|
239
249
|
return failedPoll(new RemoteProtocolError(remoteErrorEvidence(inner)), difyTaskId);
|
|
@@ -257,7 +267,7 @@ function pollResult(value, taskId, onDifyTaskId) {
|
|
|
257
267
|
try {
|
|
258
268
|
return {
|
|
259
269
|
state: "complete",
|
|
260
|
-
content: content.map(
|
|
270
|
+
content: content.map(normalize),
|
|
261
271
|
...(difyTaskId === undefined ? {} : { difyTaskId })
|
|
262
272
|
};
|
|
263
273
|
}
|
|
@@ -267,14 +277,14 @@ function pollResult(value, taskId, onDifyTaskId) {
|
|
|
267
277
|
throw error;
|
|
268
278
|
}
|
|
269
279
|
}
|
|
270
|
-
async function safePost(transport, request) {
|
|
280
|
+
async function safePost(transport, request, interpret) {
|
|
271
281
|
try {
|
|
272
|
-
return await transport.postJson(request);
|
|
282
|
+
return await withResponseDiagnostics(async (onResponse) => interpret(await transport.postJson({ ...request, onResponse })));
|
|
273
283
|
}
|
|
274
284
|
catch (error) {
|
|
275
285
|
if (isInterruption(error, request.signal))
|
|
276
286
|
throw request.signal.reason;
|
|
277
|
-
if (error instanceof RemoteRequestError || error instanceof RemoteProtocolError)
|
|
287
|
+
if (error instanceof RemoteRequestError || error instanceof RemoteProtocolError || error instanceof ToolTaskFailedError || error instanceof ToolTaskCanceledError)
|
|
278
288
|
throw error;
|
|
279
289
|
throw new RemoteRequestError(undefined, false, {}, error);
|
|
280
290
|
}
|
|
@@ -298,11 +308,13 @@ export function createToolApiAdapter(dependencies) {
|
|
|
298
308
|
const sleep = dependencies.sleep ?? defaultSleep;
|
|
299
309
|
async function submit({ invocation, access, signal, observe }) {
|
|
300
310
|
signal.throwIfAborted();
|
|
311
|
+
if (invocation.kind === "canvas")
|
|
312
|
+
throw new RemoteProtocolError({}, undefined, "TOOL_ADAPTER_MISSING");
|
|
301
313
|
const managedContentId = contentId(createContentId());
|
|
302
314
|
const resolved = invocation.kind === "direct"
|
|
303
315
|
? { name: invocation.name, arguments: invocation.arguments }
|
|
304
316
|
: await dependencies.telemetry.stage("intent", async () => {
|
|
305
|
-
const intent =
|
|
317
|
+
const intent = await safePost(dependencies.transport, {
|
|
306
318
|
path: "/ai-agent/v1/tool-intent",
|
|
307
319
|
body: {
|
|
308
320
|
prompt: invocation.prompt,
|
|
@@ -312,7 +324,7 @@ export function createToolApiAdapter(dependencies) {
|
|
|
312
324
|
credential: access.credential,
|
|
313
325
|
organizationId: access.organizationId,
|
|
314
326
|
signal
|
|
315
|
-
})
|
|
327
|
+
}, parseIntent);
|
|
316
328
|
return {
|
|
317
329
|
...intent,
|
|
318
330
|
arguments: withoutEmptyOptionalMedia(intent.arguments, invocation.optionalMediaParameters)
|
|
@@ -322,7 +334,7 @@ export function createToolApiAdapter(dependencies) {
|
|
|
322
334
|
await observe?.({ submissionStarted: true });
|
|
323
335
|
const taskId = await dependencies.telemetry.stage("submit", async () => {
|
|
324
336
|
dependencies.telemetry.annotate({ content_id: managedContentId });
|
|
325
|
-
return
|
|
337
|
+
return safePost(dependencies.transport, {
|
|
326
338
|
path: "/gdesign/tool/v1/dify/call_async",
|
|
327
339
|
...(observe ? { onDispatch: (dispatchedAt) => observe({ dispatchedAt }) } : {}),
|
|
328
340
|
body: {
|
|
@@ -337,7 +349,7 @@ export function createToolApiAdapter(dependencies) {
|
|
|
337
349
|
credential: access.credential,
|
|
338
350
|
organizationId: access.organizationId,
|
|
339
351
|
signal
|
|
340
|
-
})
|
|
352
|
+
}, submittedTask);
|
|
341
353
|
});
|
|
342
354
|
await observe?.({ remoteTaskId: taskId });
|
|
343
355
|
dependencies.telemetry.annotate({ task_id: taskId });
|