@insmind/cli 1.3.0
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/LICENSE +21 -0
- package/README.md +11 -0
- package/contracts/operations/agent.send/input.schema.json +335 -0
- package/contracts/operations/agent.send/output.schema.json +248 -0
- package/contracts/operations/auth.status/input.schema.json +7 -0
- package/contracts/operations/auth.status/output.schema.json +119 -0
- package/contracts/operations/dam.copy/input.schema.json +42 -0
- package/contracts/operations/dam.copy/output.schema.json +43 -0
- package/contracts/operations/dam.delete/input.schema.json +24 -0
- package/contracts/operations/dam.delete/output.schema.json +5 -0
- package/contracts/operations/dam.download/input.schema.json +28 -0
- package/contracts/operations/dam.download/output.schema.json +51 -0
- package/contracts/operations/dam.folder.list/input.schema.json +36 -0
- package/contracts/operations/dam.folder.list/output.schema.json +104 -0
- package/contracts/operations/dam.get/input.schema.json +16 -0
- package/contracts/operations/dam.get/output.schema.json +107 -0
- package/contracts/operations/dam.list/input.schema.json +73 -0
- package/contracts/operations/dam.list/output.schema.json +145 -0
- package/contracts/operations/dam.move/input.schema.json +42 -0
- package/contracts/operations/dam.move/output.schema.json +40 -0
- package/contracts/operations/dam.rename/input.schema.json +42 -0
- package/contracts/operations/dam.rename/output.schema.json +43 -0
- package/contracts/operations/dam.repository.list/input.schema.json +7 -0
- package/contracts/operations/dam.repository.list/output.schema.json +65 -0
- package/contracts/operations/dam.search/input.schema.json +79 -0
- package/contracts/operations/dam.search/output.schema.json +145 -0
- package/contracts/operations/dam.tag.list/input.schema.json +21 -0
- package/contracts/operations/dam.tag.list/output.schema.json +52 -0
- package/contracts/operations/dam.upload/input.schema.json +43 -0
- package/contracts/operations/dam.upload/output.schema.json +107 -0
- package/contracts/operations/editor.apply/input.schema.json +177 -0
- package/contracts/operations/editor.apply/output.schema.json +15 -0
- package/contracts/operations/editor.connect/input.schema.json +13 -0
- package/contracts/operations/editor.connect/output.schema.json +17 -0
- package/contracts/operations/editor.disconnect/input.schema.json +7 -0
- package/contracts/operations/editor.disconnect/output.schema.json +14 -0
- package/contracts/operations/editor.save/input.schema.json +7 -0
- package/contracts/operations/editor.save/output.schema.json +23 -0
- package/contracts/operations/editor.screenshot/input.schema.json +7 -0
- package/contracts/operations/editor.screenshot/output.schema.json +16 -0
- package/contracts/operations/editor.snapshot/input.schema.json +7 -0
- package/contracts/operations/editor.snapshot/output.schema.json +148 -0
- package/contracts/operations/model.get/input.schema.json +16 -0
- package/contracts/operations/model.get/output.schema.json +167 -0
- package/contracts/operations/model.list/input.schema.json +13 -0
- package/contracts/operations/model.list/output.schema.json +97 -0
- package/contracts/operations/task.get/input.schema.json +14 -0
- package/contracts/operations/task.get/output.schema.json +103 -0
- package/contracts/operations/task.list/input.schema.json +18 -0
- package/contracts/operations/task.list/output.schema.json +53 -0
- package/contracts/operations/tool.call/input.schema.json +31 -0
- package/contracts/operations/tool.call/output.schema.json +115 -0
- package/contracts/operations/tool.list/input.schema.json +6 -0
- package/contracts/operations/tool.list/output.schema.json +40 -0
- package/dist/bin/agent-worker.js +41 -0
- package/dist/bin/insmind-cli.js +60 -0
- package/dist/bin/postinstall.js +69 -0
- package/dist/src/bootstrap/create-cli.js +124 -0
- package/dist/src/bootstrap/create-runtime.js +451 -0
- package/dist/src/bootstrap/run-agent-worker.js +37 -0
- package/dist/src/bootstrap/validators.js +169 -0
- package/dist/src/cli/action-binding.js +109 -0
- package/dist/src/cli/agent-commands.js +75 -0
- package/dist/src/cli/auth-commands.js +58 -0
- package/dist/src/cli/credits-command.js +23 -0
- package/dist/src/cli/dam-commands.js +470 -0
- package/dist/src/cli/editor-commands.js +74 -0
- package/dist/src/cli/errors.js +208 -0
- package/dist/src/cli/model-commands.js +62 -0
- package/dist/src/cli/org-commands.js +58 -0
- package/dist/src/cli/presenter.js +123 -0
- package/dist/src/cli/prompt.js +30 -0
- package/dist/src/cli/task-commands.js +48 -0
- package/dist/src/cli/tool-commands.js +101 -0
- package/dist/src/cli/update-command.js +15 -0
- package/dist/src/contracts/schema.js +4 -0
- package/dist/src/features/agent/creative-agent-adapter.js +42 -0
- package/dist/src/features/agent/creative-protocol.js +421 -0
- package/dist/src/features/agent/creative-stream.js +138 -0
- package/dist/src/features/agent/filems-resource-auth-key-provider.js +23 -0
- package/dist/src/features/agent/resource-authorizer.js +47 -0
- package/dist/src/features/agent/result-reader.js +30 -0
- package/dist/src/features/agent/use-cases.js +153 -0
- package/dist/src/features/auth/access-policy.js +101 -0
- package/dist/src/features/auth/credential-store.js +62 -0
- package/dist/src/features/auth/sso-service.js +196 -0
- package/dist/src/features/auth/state.js +129 -0
- package/dist/src/features/auth/use-cases.js +162 -0
- package/dist/src/features/credits/use-cases.js +52 -0
- package/dist/src/features/dam/asset-projection.js +278 -0
- package/dist/src/features/dam/dam-api-adapter.js +562 -0
- package/dist/src/features/dam/file-downloader.js +242 -0
- package/dist/src/features/dam/object-storage.js +193 -0
- package/dist/src/features/dam/operation-executor.js +72 -0
- package/dist/src/features/dam/registered-uploader.js +247 -0
- package/dist/src/features/dam/repository-catalog.js +127 -0
- package/dist/src/features/dam/storage-upload.js +141 -0
- package/dist/src/features/dam/transient-uploader.js +17 -0
- package/dist/src/features/dam/use-cases.js +470 -0
- package/dist/src/features/editor/bridge-client.js +109 -0
- package/dist/src/features/editor/bridge-process.js +229 -0
- package/dist/src/features/editor/bridge-server.js +337 -0
- package/dist/src/features/editor/protocol.js +1 -0
- package/dist/src/features/editor/public-url.js +36 -0
- package/dist/src/features/editor/session-state.js +78 -0
- package/dist/src/features/editor/session.js +213 -0
- package/dist/src/features/editor/use-cases.js +88 -0
- package/dist/src/features/org/org-service.js +76 -0
- package/dist/src/features/org/use-cases.js +163 -0
- package/dist/src/features/skill/bundled-skills.js +63 -0
- package/dist/src/features/skill/installer.js +271 -0
- package/dist/src/features/task/agent-background.js +63 -0
- package/dist/src/features/task/store.js +97 -0
- package/dist/src/features/task/types.js +1 -0
- package/dist/src/features/task/use-cases.js +139 -0
- package/dist/src/features/tool/catalog.js +83 -0
- package/dist/src/features/tool/dynamic-schema.js +128 -0
- package/dist/src/features/tool/mns-catalog-adapter.js +265 -0
- package/dist/src/features/tool/tool-api-adapter.js +369 -0
- package/dist/src/features/tool/use-cases.js +180 -0
- package/dist/src/features/update/latest-version.js +37 -0
- package/dist/src/features/update/update-notification.js +271 -0
- package/dist/src/features/update/update-service.js +226 -0
- package/dist/src/platform/installation-owner.js +81 -0
- package/dist/src/platform/json-input.js +67 -0
- package/dist/src/platform/local-json-file.js +59 -0
- package/dist/src/platform/open-browser.js +8 -0
- package/dist/src/platform/redact.js +80 -0
- package/dist/src/platform/remote-error-evidence.js +80 -0
- package/dist/src/platform/remote-protocol.js +10 -0
- package/dist/src/platform/resource-auth-key.js +1 -0
- package/dist/src/platform/safe-upload-file.js +146 -0
- package/dist/src/platform/signature.js +20 -0
- package/dist/src/platform/signed-http-transport.js +144 -0
- package/dist/src/platform/task-observer.js +1 -0
- package/dist/src/platform/url-safety.js +100 -0
- package/dist/src/product/billing.js +47 -0
- package/dist/src/product/config.js +85 -0
- package/dist/src/product/locale.js +38 -0
- package/dist/src/product/text.js +3 -0
- package/dist/src/telemetry/invocation.js +156 -0
- package/dist/src/telemetry/sls-sink.js +30 -0
- package/package.json +53 -0
- package/skills/insmind-cli/SKILL.md +15 -0
- package/skills/insmind-cli/references/agent.md +34 -0
- package/skills/insmind-cli/references/auth.md +8 -0
- package/skills/insmind-cli/references/creation.md +40 -0
- package/skills/insmind-cli/references/dam.md +51 -0
- package/skills/insmind-cli/references/editor.md +184 -0
- package/skills/insmind-cli/references/errors.md +29 -0
- package/skills/insmind-cli/references/generation-constraints.md +36 -0
- package/skills/insmind-cli/references/tool.md +31 -0
- package/skills/insmind-cli/references/update.md +11 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { createAgentBackgroundLauncher } from "../features/task/agent-background.js";
|
|
3
|
+
import { createTaskStore } from "../features/task/store.js";
|
|
4
|
+
import { createTaskUseCases } from "../features/task/use-cases.js";
|
|
5
|
+
import { readAgentResult } from "../features/agent/result-reader.js";
|
|
6
|
+
import { queryToolResult, ToolTaskFailedError } from "../features/tool/tool-api-adapter.js";
|
|
7
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { createAccessPolicies } from "../features/auth/access-policy.js";
|
|
12
|
+
import { createLocalCredentialStore } from "../features/auth/credential-store.js";
|
|
13
|
+
import { createAuthUseCases } from "../features/auth/use-cases.js";
|
|
14
|
+
import { createSsoService } from "../features/auth/sso-service.js";
|
|
15
|
+
import { createCreativeAgentAdapter } from "../features/agent/creative-agent-adapter.js";
|
|
16
|
+
import { createAgentResourceAuthorizer } from "../features/agent/resource-authorizer.js";
|
|
17
|
+
import { createFilemsResourceAuthKeyProvider } from "../features/agent/filems-resource-auth-key-provider.js";
|
|
18
|
+
import { createDamApiAdapter } from "../features/dam/dam-api-adapter.js";
|
|
19
|
+
import { createDamFileDownloader } from "../features/dam/file-downloader.js";
|
|
20
|
+
import { createDamOperationExecutor } from "../features/dam/operation-executor.js";
|
|
21
|
+
import { createDamRepositoryCatalog } from "../features/dam/repository-catalog.js";
|
|
22
|
+
import { createDamRegisteredUploader } from "../features/dam/registered-uploader.js";
|
|
23
|
+
import { createDamTransientUploader } from "../features/dam/transient-uploader.js";
|
|
24
|
+
import { createDamStorageUploader } from "../features/dam/storage-upload.js";
|
|
25
|
+
import { createDamUseCases } from "../features/dam/use-cases.js";
|
|
26
|
+
import { createEditorSession } from "../features/editor/session.js";
|
|
27
|
+
import { createEditorSessionStateStore } from "../features/editor/session-state.js";
|
|
28
|
+
import { createEditorUseCases } from "../features/editor/use-cases.js";
|
|
29
|
+
import { createObjectStorageUploader } from "../features/dam/object-storage.js";
|
|
30
|
+
import { createAgentUseCases } from "../features/agent/use-cases.js";
|
|
31
|
+
import { createMnsCatalogAdapter } from "../features/tool/mns-catalog-adapter.js";
|
|
32
|
+
import { createToolApiAdapter } from "../features/tool/tool-api-adapter.js";
|
|
33
|
+
import { createToolUseCases } from "../features/tool/use-cases.js";
|
|
34
|
+
import { createOrgUseCases } from "../features/org/use-cases.js";
|
|
35
|
+
import { createOrgService } from "../features/org/org-service.js";
|
|
36
|
+
import { createCreditsUseCases } from "../features/credits/use-cases.js";
|
|
37
|
+
import { createBrowserOpener } from "../platform/open-browser.js";
|
|
38
|
+
import { createSignedHttpTransport, RemoteRequestError } from "../platform/signed-http-transport.js";
|
|
39
|
+
import { createJsonInputReader } from "../platform/json-input.js";
|
|
40
|
+
import { createOrganizationPrompt } from "../cli/prompt.js";
|
|
41
|
+
import { createPresenter } from "../cli/presenter.js";
|
|
42
|
+
import { createContractValidators } from "./validators.js";
|
|
43
|
+
import { loadBundledSkills } from "../features/skill/bundled-skills.js";
|
|
44
|
+
import { createUpdateService } from "../features/update/update-service.js";
|
|
45
|
+
import { createUpdateNotificationService } from "../features/update/update-notification.js";
|
|
46
|
+
import { classifyTelemetryError, mapCliError } from "../cli/errors.js";
|
|
47
|
+
import { createTelemetryInvocation } from "../telemetry/invocation.js";
|
|
48
|
+
import { createSlsTelemetrySink } from "../telemetry/sls-sink.js";
|
|
49
|
+
import { gaodingProduct } from "../product/config.js";
|
|
50
|
+
import { resolveProductLocale, systemLocale } from "../product/locale.js";
|
|
51
|
+
import { productText } from "../product/text.js";
|
|
52
|
+
import { agentOutputWithBillingUnit, toolOutputWithBillingUnit, withAgentBillingUnit, withToolBillingUnit } from "../product/billing.js";
|
|
53
|
+
import { readInstallationOwner } from "../platform/installation-owner.js";
|
|
54
|
+
export function createProductionRuntime(options = {}) {
|
|
55
|
+
const product = options.product ?? gaodingProduct;
|
|
56
|
+
const text = (chinese, english) => productText(product, chinese, english);
|
|
57
|
+
const bundledSkills = loadBundledSkills(fileURLToPath(import.meta.url));
|
|
58
|
+
const primarySkill = bundledSkills.find((skill) => skill.skill === product.skillName);
|
|
59
|
+
if (!primarySkill)
|
|
60
|
+
throw new Error(`Bundled ${product.skillName} Skill is missing.`);
|
|
61
|
+
const packageRoot = dirname(dirname(primarySkill.sourceDirectory));
|
|
62
|
+
const installationOwner = readInstallationOwner(packageRoot);
|
|
63
|
+
const endpoints = options.endpoints ?? product.endpoints;
|
|
64
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
65
|
+
const env = options.env ?? process.env;
|
|
66
|
+
const environmentLocale = product.localeEnvironmentVariable
|
|
67
|
+
? env[product.localeEnvironmentVariable]
|
|
68
|
+
: undefined;
|
|
69
|
+
const localSystemLocale = systemLocale();
|
|
70
|
+
const locale = resolveProductLocale({
|
|
71
|
+
...(options.locale === undefined ? {} : { explicit: options.locale }),
|
|
72
|
+
...(environmentLocale === undefined ? {} : { environment: environmentLocale }),
|
|
73
|
+
...(localSystemLocale === undefined ? {} : { system: localSystemLocale })
|
|
74
|
+
});
|
|
75
|
+
const businessHeaders = product.id === "insmind" ? {
|
|
76
|
+
"X-Locale": locale.locale,
|
|
77
|
+
"X-Language": locale.language,
|
|
78
|
+
"X-Market": locale.market,
|
|
79
|
+
"X-Legal-Region": locale.legalRegion
|
|
80
|
+
} : undefined;
|
|
81
|
+
const now = options.now ?? (() => new Date());
|
|
82
|
+
const telemetry = createTelemetryInvocation({
|
|
83
|
+
cliVersion: primarySkill.version,
|
|
84
|
+
now: () => now().getTime(),
|
|
85
|
+
traceIdFactory: () => randomBytes(16).toString("hex"),
|
|
86
|
+
spanIdFactory: () => randomBytes(8).toString("hex"),
|
|
87
|
+
runtime: {
|
|
88
|
+
os: process.platform,
|
|
89
|
+
arch: process.arch,
|
|
90
|
+
nodeMajor: Number.parseInt(process.versions.node, 10)
|
|
91
|
+
},
|
|
92
|
+
classifyError: classifyTelemetryError
|
|
93
|
+
});
|
|
94
|
+
const telemetrySink = createSlsTelemetrySink({
|
|
95
|
+
fetch,
|
|
96
|
+
trackingUrl: product.telemetryUrl
|
|
97
|
+
});
|
|
98
|
+
const rawIo = options.io ?? {
|
|
99
|
+
input: process.stdin,
|
|
100
|
+
stdout: process.stdout,
|
|
101
|
+
stderr: process.stderr,
|
|
102
|
+
inputTerminal: process.stdin.isTTY === true,
|
|
103
|
+
stderrTerminal: process.stderr.isTTY === true
|
|
104
|
+
};
|
|
105
|
+
const io = {
|
|
106
|
+
writeOut: (text) => { rawIo.stdout.write(text); },
|
|
107
|
+
writeError: (text) => { rawIo.stderr.write(text); },
|
|
108
|
+
inputTerminal: rawIo.inputTerminal ?? hasTerminal(rawIo.input),
|
|
109
|
+
stderrTerminal: rawIo.stderrTerminal ?? hasTerminal(rawIo.stderr)
|
|
110
|
+
};
|
|
111
|
+
const store = createLocalCredentialStore({
|
|
112
|
+
...(options.homeDirectory ? { homeDirectory: options.homeDirectory } : {}),
|
|
113
|
+
stateDirectory: product.stateDirectory
|
|
114
|
+
});
|
|
115
|
+
const orgTransport = createSignedHttpTransport({
|
|
116
|
+
baseUrl: endpoints.orgApi,
|
|
117
|
+
fetch,
|
|
118
|
+
now,
|
|
119
|
+
traceparent: () => telemetry.traceparent(),
|
|
120
|
+
...(businessHeaders ? { businessHeaders } : {})
|
|
121
|
+
});
|
|
122
|
+
const creditsTransport = createSignedHttpTransport({
|
|
123
|
+
baseUrl: endpoints.creditsApi,
|
|
124
|
+
fetch,
|
|
125
|
+
now,
|
|
126
|
+
traceparent: () => telemetry.traceparent(),
|
|
127
|
+
...(businessHeaders ? { businessHeaders } : {})
|
|
128
|
+
});
|
|
129
|
+
const agentTransport = createSignedHttpTransport({
|
|
130
|
+
baseUrl: endpoints.agentApi,
|
|
131
|
+
fetch,
|
|
132
|
+
now,
|
|
133
|
+
traceparent: () => telemetry.traceparent(),
|
|
134
|
+
...(businessHeaders ? { businessHeaders } : {})
|
|
135
|
+
});
|
|
136
|
+
const mnsTransport = createSignedHttpTransport({
|
|
137
|
+
baseUrl: endpoints.mnsApi,
|
|
138
|
+
fetch,
|
|
139
|
+
now,
|
|
140
|
+
traceparent: () => telemetry.traceparent(),
|
|
141
|
+
...(businessHeaders ? { businessHeaders } : {})
|
|
142
|
+
});
|
|
143
|
+
const toolTransport = createSignedHttpTransport({
|
|
144
|
+
baseUrl: endpoints.toolApi,
|
|
145
|
+
fetch,
|
|
146
|
+
now,
|
|
147
|
+
traceparent: () => telemetry.traceparent(),
|
|
148
|
+
...(businessHeaders ? { businessHeaders } : {})
|
|
149
|
+
});
|
|
150
|
+
const damTransport = createSignedHttpTransport({
|
|
151
|
+
baseUrl: endpoints.damApi,
|
|
152
|
+
fetch,
|
|
153
|
+
now,
|
|
154
|
+
channelId: "32",
|
|
155
|
+
traceparent: () => telemetry.traceparent(),
|
|
156
|
+
...(businessHeaders ? { businessHeaders } : {})
|
|
157
|
+
});
|
|
158
|
+
const sso = createSsoService({
|
|
159
|
+
ssoApi: endpoints.ssoApi,
|
|
160
|
+
clientId: product.deviceClientId,
|
|
161
|
+
fetch,
|
|
162
|
+
now
|
|
163
|
+
});
|
|
164
|
+
const org = createOrgUseCases({
|
|
165
|
+
store,
|
|
166
|
+
org: createOrgService({ transport: orgTransport }),
|
|
167
|
+
sso,
|
|
168
|
+
telemetry,
|
|
169
|
+
...(product.exposesOrganizations
|
|
170
|
+
? {}
|
|
171
|
+
: { singleOrganizationName: product.displayName })
|
|
172
|
+
});
|
|
173
|
+
const auth = createAuthUseCases({
|
|
174
|
+
store,
|
|
175
|
+
sso,
|
|
176
|
+
organizationBinder: org,
|
|
177
|
+
authPageOrigin: endpoints.authPageOrigin,
|
|
178
|
+
commandName: product.commandName,
|
|
179
|
+
requireOrganization: !product.exposesOrganizations,
|
|
180
|
+
now,
|
|
181
|
+
telemetry,
|
|
182
|
+
sleep: async (milliseconds, signal) => {
|
|
183
|
+
await delay(milliseconds, undefined, { signal });
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
const storage = options.objectStorage ?? createObjectStorageUploader({ fetch, now });
|
|
187
|
+
const credits = createCreditsUseCases({
|
|
188
|
+
transport: creditsTransport,
|
|
189
|
+
billingUnit: product.billingUnit
|
|
190
|
+
});
|
|
191
|
+
const storageUpload = createDamStorageUploader({
|
|
192
|
+
transport: damTransport,
|
|
193
|
+
storage
|
|
194
|
+
});
|
|
195
|
+
const transientUploader = createDamTransientUploader({ storageUpload });
|
|
196
|
+
const presenter = createPresenter({
|
|
197
|
+
writeOut: io.writeOut,
|
|
198
|
+
writeError: io.writeError,
|
|
199
|
+
product
|
|
200
|
+
});
|
|
201
|
+
const browser = createBrowserOpener();
|
|
202
|
+
const validators = createContractValidators({
|
|
203
|
+
organizations: product.exposesOrganizations
|
|
204
|
+
});
|
|
205
|
+
const modelCatalog = createMnsCatalogAdapter({ transport: mnsTransport });
|
|
206
|
+
const damApi = createDamApiAdapter({ transport: damTransport });
|
|
207
|
+
const damRepositories = createDamRepositoryCatalog({ transport: damTransport });
|
|
208
|
+
const damOperations = createDamOperationExecutor({
|
|
209
|
+
now: () => now().getTime(),
|
|
210
|
+
sleep: async (milliseconds, signal) => {
|
|
211
|
+
await delay(milliseconds, undefined, { signal });
|
|
212
|
+
},
|
|
213
|
+
annotate: (context) => { telemetry.annotate(context); }
|
|
214
|
+
});
|
|
215
|
+
const dam = createDamUseCases({
|
|
216
|
+
api: damApi,
|
|
217
|
+
repositories: damRepositories,
|
|
218
|
+
storage: storageUpload,
|
|
219
|
+
uploader: createDamRegisteredUploader({
|
|
220
|
+
api: damApi,
|
|
221
|
+
storage: storageUpload,
|
|
222
|
+
warn: (message) => { presenter.warning(message); },
|
|
223
|
+
now,
|
|
224
|
+
telemetry
|
|
225
|
+
}),
|
|
226
|
+
downloader: createDamFileDownloader({ fetch }),
|
|
227
|
+
operations: damOperations,
|
|
228
|
+
sleep: async (milliseconds, signal) => {
|
|
229
|
+
await delay(milliseconds, undefined, { signal });
|
|
230
|
+
},
|
|
231
|
+
validate: {
|
|
232
|
+
repositoryList: validators.damRepositoryListOutput,
|
|
233
|
+
list: validators.damListOutput,
|
|
234
|
+
search: validators.damSearchOutput,
|
|
235
|
+
folderList: validators.damFolderListOutput,
|
|
236
|
+
tagList: validators.damTagListOutput,
|
|
237
|
+
download: validators.damDownloadOutput,
|
|
238
|
+
rename: validators.damRenameOutput,
|
|
239
|
+
move: validators.damMoveOutput,
|
|
240
|
+
copy: validators.damCopyOutput,
|
|
241
|
+
get: validators.damGetOutput,
|
|
242
|
+
upload: validators.damUploadOutput,
|
|
243
|
+
delete: validators.damDeleteOutput
|
|
244
|
+
},
|
|
245
|
+
telemetry
|
|
246
|
+
});
|
|
247
|
+
const resourceAuthorizer = createAgentResourceAuthorizer({
|
|
248
|
+
authKeys: options.resourceAuthKeys
|
|
249
|
+
?? createFilemsResourceAuthKeyProvider({ transport: createSignedHttpTransport({
|
|
250
|
+
baseUrl: endpoints.filemsApi,
|
|
251
|
+
fetch,
|
|
252
|
+
now,
|
|
253
|
+
channelId: "32",
|
|
254
|
+
traceparent: () => telemetry.traceparent(),
|
|
255
|
+
...(businessHeaders ? { businessHeaders } : {})
|
|
256
|
+
}) })
|
|
257
|
+
});
|
|
258
|
+
const authorizeTaskResult = async (result, state, signal) => {
|
|
259
|
+
const access = { credential: state.credential, organizationId: state.organization.id };
|
|
260
|
+
if ("message" in result)
|
|
261
|
+
return resourceAuthorizer.authorize(result, access, signal);
|
|
262
|
+
const links = result.content.filter(part => part.type === "resource_link");
|
|
263
|
+
if (links.length === 0)
|
|
264
|
+
return result;
|
|
265
|
+
const parts = links.map(part => ({ url: part.uri, mediaType: part.mimeType ?? "application/octet-stream" }));
|
|
266
|
+
const authorized = await resourceAuthorizer.authorize({
|
|
267
|
+
message: { contextId: "resource-authorization", parts: [parts[0], ...parts.slice(1)] },
|
|
268
|
+
usage: { cost: { unit: "gaodou", amount: 0 }, items: [] }
|
|
269
|
+
}, access, signal);
|
|
270
|
+
let index = 0;
|
|
271
|
+
return { ...result, content: result.content.map(part => {
|
|
272
|
+
if (part.type !== "resource_link")
|
|
273
|
+
return part;
|
|
274
|
+
const authorizedPart = authorized.message.parts[index++];
|
|
275
|
+
return authorizedPart && "url" in authorizedPart ? { ...part, uri: authorizedPart.url } : part;
|
|
276
|
+
}) };
|
|
277
|
+
};
|
|
278
|
+
const tasks = createTaskUseCases({
|
|
279
|
+
store: createTaskStore({
|
|
280
|
+
...(options.homeDirectory ? { homeDirectory: options.homeDirectory } : {}),
|
|
281
|
+
stateDirectory: product.stateDirectory,
|
|
282
|
+
validate: validators.taskResult
|
|
283
|
+
}),
|
|
284
|
+
idFactory: randomUUID,
|
|
285
|
+
now,
|
|
286
|
+
notice: message => presenter.notice(message),
|
|
287
|
+
commandName: product.commandName,
|
|
288
|
+
text,
|
|
289
|
+
failureNote: error => {
|
|
290
|
+
const outcome = mapCliError(error, { aborted: false, product });
|
|
291
|
+
const status = error instanceof RemoteRequestError && error.status !== undefined ? ` (HTTP ${error.status})` : "";
|
|
292
|
+
return outcome.kind === "failure" ? `${outcome.failure.code}${status}: ${outcome.failure.message}` : "";
|
|
293
|
+
},
|
|
294
|
+
recovery: {
|
|
295
|
+
authorize: authorizeTaskResult,
|
|
296
|
+
async agent(progress, state, signal) {
|
|
297
|
+
if (!progress.contextId || !progress.localMessageId)
|
|
298
|
+
return {
|
|
299
|
+
state: "unknown", note: text("本地记录未取得服务端会话标识;无法确认提交结果,不自动重新生成。", "No service context was recorded. The submission outcome is unknown; do not generate again.")
|
|
300
|
+
};
|
|
301
|
+
const snapshot = await readAgentResult(agentTransport, {
|
|
302
|
+
contextId: progress.contextId, localMessageId: progress.localMessageId,
|
|
303
|
+
credential: state.credential, organizationId: state.organization.id, signal
|
|
304
|
+
});
|
|
305
|
+
return { state: "unknown",
|
|
306
|
+
note: text(`会话连接为 ${snapshot.connectionState};这不是本次调用的完成凭据。已有内容仅作为消息快照。`, `The context connection is ${snapshot.connectionState}; this does not prove that the run completed. Available content is a message snapshot only.`),
|
|
307
|
+
...(snapshot.partialResult ? { partialResult: await authorizeTaskResult(agentOutputWithBillingUnit(snapshot.partialResult, product.billingUnit), state, signal) } : {})
|
|
308
|
+
};
|
|
309
|
+
},
|
|
310
|
+
async tool(progress, state, signal) {
|
|
311
|
+
if (!progress.remoteTaskId || !progress.toolUsage)
|
|
312
|
+
return {
|
|
313
|
+
state: "unknown", note: text("本地记录未取得可查询的 Tool 回执;不自动重新生成。", "No queryable Tool receipt was recorded; do not generate again.")
|
|
314
|
+
};
|
|
315
|
+
const response = await queryToolResult(toolTransport, {
|
|
316
|
+
taskId: progress.remoteTaskId, credential: state.credential,
|
|
317
|
+
organizationId: state.organization.id, signal
|
|
318
|
+
});
|
|
319
|
+
if (response.state === "pending")
|
|
320
|
+
return { state: "running", note: text("原 Tool 查询尚未返回最终结果。", "The original Tool is still processing.") };
|
|
321
|
+
if (response.state === "failed")
|
|
322
|
+
return { state: "failed", note: text(response.error.message, response.error instanceof ToolTaskFailedError ? "The Tool run failed." : "The Tool service response is incompatible with this CLI.") };
|
|
323
|
+
return { state: "completed", result: await authorizeTaskResult(toolOutputWithBillingUnit({
|
|
324
|
+
content: response.content, usage: progress.toolUsage
|
|
325
|
+
}, product.billingUnit), state, signal) };
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
const agent = withAgentBillingUnit(createAgentUseCases({
|
|
330
|
+
catalog: modelCatalog,
|
|
331
|
+
uploader: transientUploader,
|
|
332
|
+
completion: createCreativeAgentAdapter({
|
|
333
|
+
transport: agentTransport,
|
|
334
|
+
resourceAuthorizer,
|
|
335
|
+
idFactory: randomUUID,
|
|
336
|
+
telemetry
|
|
337
|
+
}),
|
|
338
|
+
warn: (message) => { presenter.warning(message); },
|
|
339
|
+
telemetry
|
|
340
|
+
}), product.billingUnit);
|
|
341
|
+
const tool = withToolBillingUnit(createToolUseCases({
|
|
342
|
+
catalog: modelCatalog,
|
|
343
|
+
tools: product.tools,
|
|
344
|
+
execution: createToolApiAdapter({ transport: toolTransport, telemetry }),
|
|
345
|
+
uploader: transientUploader,
|
|
346
|
+
warn: (message) => { presenter.warning(message); },
|
|
347
|
+
telemetry
|
|
348
|
+
}), product.billingUnit);
|
|
349
|
+
const editor = createEditorUseCases({
|
|
350
|
+
session: createEditorSession({
|
|
351
|
+
store: createEditorSessionStateStore({
|
|
352
|
+
...(options.homeDirectory === undefined
|
|
353
|
+
? {}
|
|
354
|
+
: { homeDirectory: options.homeDirectory }),
|
|
355
|
+
stateDirectory: product.stateDirectory
|
|
356
|
+
}),
|
|
357
|
+
browser,
|
|
358
|
+
defaultCreateUrl: product.defaultEditorCreateUrl,
|
|
359
|
+
workUrl: product.editorWorkUrl,
|
|
360
|
+
commandName: product.commandName,
|
|
361
|
+
restrictTargets: product.restrictEditorTargets,
|
|
362
|
+
stateDirectory: product.stateDirectory,
|
|
363
|
+
...(options.homeDirectory === undefined
|
|
364
|
+
? {}
|
|
365
|
+
: { homeDirectory: options.homeDirectory })
|
|
366
|
+
}),
|
|
367
|
+
validate: {
|
|
368
|
+
connect: validators.editorConnectOutput,
|
|
369
|
+
disconnect: validators.editorDisconnectOutput,
|
|
370
|
+
snapshot: validators.editorSnapshotOutput,
|
|
371
|
+
apply: validators.editorApplyOutput,
|
|
372
|
+
screenshot: validators.editorScreenshotOutput,
|
|
373
|
+
save: validators.editorSaveOutput
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
const update = {
|
|
377
|
+
run(signal) {
|
|
378
|
+
return createUpdateService({
|
|
379
|
+
currentVersion: primarySkill.version,
|
|
380
|
+
packageRoot,
|
|
381
|
+
bundledSkills,
|
|
382
|
+
fetch,
|
|
383
|
+
telemetry,
|
|
384
|
+
...(product.id === "insmind" ? {
|
|
385
|
+
packageName: product.npmPackage,
|
|
386
|
+
commandName: product.commandName,
|
|
387
|
+
registryUrl: `https://registry.npmjs.org/${encodeURIComponent(product.npmPackage)}`
|
|
388
|
+
} : {}),
|
|
389
|
+
installationOwner,
|
|
390
|
+
...(process.argv[1] ? { binaryPath: process.argv[1] } : {}),
|
|
391
|
+
...(options.homeDirectory ? { homeDirectory: options.homeDirectory } : {})
|
|
392
|
+
}).run(signal);
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const updateNotification = createUpdateNotificationService({
|
|
396
|
+
currentVersion: primarySkill.version,
|
|
397
|
+
fetch,
|
|
398
|
+
now,
|
|
399
|
+
installationOwner,
|
|
400
|
+
...(options.homeDirectory ? { homeDirectory: options.homeDirectory } : {}),
|
|
401
|
+
...(options.env ? { env: options.env } : {}),
|
|
402
|
+
notify: (message) => { presenter.notice(message); },
|
|
403
|
+
...(product.id === "insmind" ? {
|
|
404
|
+
stateDirectoryName: product.stateDirectory,
|
|
405
|
+
registryUrl: `https://registry.npmjs.org/${encodeURIComponent(product.npmPackage)}`,
|
|
406
|
+
commandName: product.commandName
|
|
407
|
+
} : {})
|
|
408
|
+
});
|
|
409
|
+
return {
|
|
410
|
+
product,
|
|
411
|
+
version: primarySkill.version,
|
|
412
|
+
telemetry,
|
|
413
|
+
telemetrySink,
|
|
414
|
+
accessPolicies: createAccessPolicies({
|
|
415
|
+
store,
|
|
416
|
+
now,
|
|
417
|
+
refreshCurrentOrganization: org.refreshCurrentOrganization
|
|
418
|
+
}),
|
|
419
|
+
auth,
|
|
420
|
+
org,
|
|
421
|
+
agent,
|
|
422
|
+
tasks,
|
|
423
|
+
startAgentTask: (input, signal) => (options.agentBackground ?? createAgentBackgroundLauncher({
|
|
424
|
+
workerPath: join(packageRoot, "dist", "bin", "agent-worker.js"), env
|
|
425
|
+
})).submit({ ...input, product: product.id, homeDirectory: options.homeDirectory ?? homedir(),
|
|
426
|
+
locale: locale.locale, endpoints: Object.fromEntries(Object.entries(endpoints).map(([key, value]) => [key, String(value)]))
|
|
427
|
+
}, signal, task => presenter.notice(text(`任务 ID: ${task.taskId};结果未收到时执行 ${product.commandName} task get ${task.taskId}`, `Task ID: ${task.taskId}; retrieve missing output with ${product.commandName} task get ${task.taskId}`))),
|
|
428
|
+
editor,
|
|
429
|
+
dam,
|
|
430
|
+
tool,
|
|
431
|
+
credits,
|
|
432
|
+
update,
|
|
433
|
+
updateNotification,
|
|
434
|
+
jsonInput: createJsonInputReader({
|
|
435
|
+
cwd: process.cwd(),
|
|
436
|
+
stdin: rawIo.input
|
|
437
|
+
}),
|
|
438
|
+
validators,
|
|
439
|
+
presenter,
|
|
440
|
+
prompt: createOrganizationPrompt({
|
|
441
|
+
input: rawIo.input,
|
|
442
|
+
output: rawIo.stderr
|
|
443
|
+
}),
|
|
444
|
+
browser,
|
|
445
|
+
now,
|
|
446
|
+
io
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
function hasTerminal(value) {
|
|
450
|
+
return "isTTY" in value && value.isTTY === true;
|
|
451
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { mapCliError } from "../cli/errors.js";
|
|
2
|
+
import { redact } from "../platform/redact.js";
|
|
3
|
+
export async function runAgentWorker(options) {
|
|
4
|
+
const runtime = options.runtime;
|
|
5
|
+
const { job, signal, send } = options;
|
|
6
|
+
let started = false;
|
|
7
|
+
let accepted = false;
|
|
8
|
+
try {
|
|
9
|
+
runtime.validators.agentSendInput(job.input);
|
|
10
|
+
await runtime.tasks.track({
|
|
11
|
+
state: job.state,
|
|
12
|
+
operation: "agent.send",
|
|
13
|
+
label: job.label,
|
|
14
|
+
onUpdate(task, progress) {
|
|
15
|
+
if (!started) {
|
|
16
|
+
started = true;
|
|
17
|
+
send({ type: "started", task });
|
|
18
|
+
}
|
|
19
|
+
if (progress.accepted && !accepted) {
|
|
20
|
+
accepted = true;
|
|
21
|
+
send({ type: "accepted", task });
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
run: async (observe) => {
|
|
25
|
+
const result = await runtime.agent.send({ input: job.input, signal, observe,
|
|
26
|
+
access: { credential: job.state.credential, organizationId: job.state.organization.id } });
|
|
27
|
+
runtime.validators.agentSendOutput(result);
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const outcome = redact(mapCliError(error, { aborted: signal.aborted, product: runtime.product }));
|
|
34
|
+
if (outcome.kind === "failure")
|
|
35
|
+
send({ type: "error", failure: outcome.failure, exitCode: outcome.exitCode });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
2
|
+
import addFormatsImport, {} from "ajv-formats";
|
|
3
|
+
import { contractSchema } from "../contracts/schema.js";
|
|
4
|
+
const agentSendInputSchema = contractSchema("agent.send", "input");
|
|
5
|
+
const agentSendOutputSchema = contractSchema("agent.send", "output");
|
|
6
|
+
const authStatusSchema = contractSchema("auth.status", "output");
|
|
7
|
+
const damDeleteInputSchema = contractSchema("dam.delete", "input");
|
|
8
|
+
const damDeleteOutputSchema = contractSchema("dam.delete", "output");
|
|
9
|
+
const damCopyInputSchema = contractSchema("dam.copy", "input");
|
|
10
|
+
const damCopyOutputSchema = contractSchema("dam.copy", "output");
|
|
11
|
+
const damDownloadInputSchema = contractSchema("dam.download", "input");
|
|
12
|
+
const damDownloadOutputSchema = contractSchema("dam.download", "output");
|
|
13
|
+
const damFolderListInputSchema = contractSchema("dam.folder.list", "input");
|
|
14
|
+
const damFolderListOutputSchema = contractSchema("dam.folder.list", "output");
|
|
15
|
+
const damGetInputSchema = contractSchema("dam.get", "input");
|
|
16
|
+
const damGetOutputSchema = contractSchema("dam.get", "output");
|
|
17
|
+
const damListInputSchema = contractSchema("dam.list", "input");
|
|
18
|
+
const damListOutputSchema = contractSchema("dam.list", "output");
|
|
19
|
+
const damMoveInputSchema = contractSchema("dam.move", "input");
|
|
20
|
+
const damMoveOutputSchema = contractSchema("dam.move", "output");
|
|
21
|
+
const damRepositoryListOutputSchema = contractSchema("dam.repository.list", "output");
|
|
22
|
+
const damRenameInputSchema = contractSchema("dam.rename", "input");
|
|
23
|
+
const damRenameOutputSchema = contractSchema("dam.rename", "output");
|
|
24
|
+
const damSearchInputSchema = contractSchema("dam.search", "input");
|
|
25
|
+
const damSearchOutputSchema = contractSchema("dam.search", "output");
|
|
26
|
+
const damTagListInputSchema = contractSchema("dam.tag.list", "input");
|
|
27
|
+
const damTagListOutputSchema = contractSchema("dam.tag.list", "output");
|
|
28
|
+
const damUploadInputSchema = contractSchema("dam.upload", "input");
|
|
29
|
+
const damUploadOutputSchema = contractSchema("dam.upload", "output");
|
|
30
|
+
const editorApplyInputSchema = contractSchema("editor.apply", "input");
|
|
31
|
+
const editorApplyOutputSchema = contractSchema("editor.apply", "output");
|
|
32
|
+
const editorConnectInputSchema = contractSchema("editor.connect", "input");
|
|
33
|
+
const editorConnectOutputSchema = contractSchema("editor.connect", "output");
|
|
34
|
+
const editorDisconnectOutputSchema = contractSchema("editor.disconnect", "output");
|
|
35
|
+
const editorSaveOutputSchema = contractSchema("editor.save", "output");
|
|
36
|
+
const editorScreenshotOutputSchema = contractSchema("editor.screenshot", "output");
|
|
37
|
+
const editorSnapshotOutputSchema = contractSchema("editor.snapshot", "output");
|
|
38
|
+
const modelGetInputSchema = contractSchema("model.get", "input");
|
|
39
|
+
const modelGetOutputSchema = contractSchema("model.get", "output");
|
|
40
|
+
const modelListInputSchema = contractSchema("model.list", "input");
|
|
41
|
+
const modelListOutputSchema = contractSchema("model.list", "output");
|
|
42
|
+
const toolCallInputSchema = contractSchema("tool.call", "input");
|
|
43
|
+
const toolCallOutputSchema = contractSchema("tool.call", "output");
|
|
44
|
+
const toolListOutputSchema = contractSchema("tool.list", "output");
|
|
45
|
+
export class InputContractError extends Error {
|
|
46
|
+
constructor() {
|
|
47
|
+
super("输入不符合命令契约。");
|
|
48
|
+
this.name = "InputContractError";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class OutputContractError extends Error {
|
|
52
|
+
constructor() {
|
|
53
|
+
super("命令结果不符合公开契约。");
|
|
54
|
+
this.name = "OutputContractError";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function createContractValidators(options = {}) {
|
|
58
|
+
const ajv = new Ajv2020({ allErrors: true, strict: true });
|
|
59
|
+
const addFormats = addFormatsImport;
|
|
60
|
+
addFormats(ajv);
|
|
61
|
+
const agentSendInput = ajv.compile(agentSendInputSchema);
|
|
62
|
+
const agentSendOutput = ajv.compile(agentSendOutputSchema);
|
|
63
|
+
const authStatus = ajv.compile(authStatusSchema);
|
|
64
|
+
const damFolderListInput = ajv.compile(damFolderListInputSchema);
|
|
65
|
+
const damFolderListOutput = ajv.compile(damFolderListOutputSchema);
|
|
66
|
+
const damListInput = ajv.compile(damListInputSchema);
|
|
67
|
+
const damListOutput = ajv.compile(damListOutputSchema);
|
|
68
|
+
const damRepositoryListOutput = ajv.compile(damRepositoryListOutputSchema);
|
|
69
|
+
const damRenameInput = ajv.compile(damRenameInputSchema);
|
|
70
|
+
const damRenameOutput = ajv.compile(damRenameOutputSchema);
|
|
71
|
+
const damMoveInput = ajv.compile(damMoveInputSchema);
|
|
72
|
+
const damMoveOutput = ajv.compile(damMoveOutputSchema);
|
|
73
|
+
const damCopyInput = ajv.compile(damCopyInputSchema);
|
|
74
|
+
const damCopyOutput = ajv.compile(damCopyOutputSchema);
|
|
75
|
+
const damSearchInput = ajv.compile(damSearchInputSchema);
|
|
76
|
+
const damSearchOutput = ajv.compile(damSearchOutputSchema);
|
|
77
|
+
const damTagListInput = ajv.compile(damTagListInputSchema);
|
|
78
|
+
const damTagListOutput = ajv.compile(damTagListOutputSchema);
|
|
79
|
+
const damGetInput = ajv.compile(damGetInputSchema);
|
|
80
|
+
const damGetOutput = ajv.compile(damGetOutputSchema);
|
|
81
|
+
const damUploadInput = ajv.compile(damUploadInputSchema);
|
|
82
|
+
const damUploadOutput = ajv.compile(damUploadOutputSchema);
|
|
83
|
+
const damDeleteInput = ajv.compile(damDeleteInputSchema);
|
|
84
|
+
const damDeleteOutput = ajv.compile(damDeleteOutputSchema);
|
|
85
|
+
const damDownloadInput = ajv.compile(damDownloadInputSchema);
|
|
86
|
+
const damDownloadOutput = ajv.compile(damDownloadOutputSchema);
|
|
87
|
+
const editorConnectInput = ajv.compile(editorConnectInputSchema);
|
|
88
|
+
const editorConnectOutput = ajv.compile(editorConnectOutputSchema);
|
|
89
|
+
const editorDisconnectOutput = ajv.compile(editorDisconnectOutputSchema);
|
|
90
|
+
const editorSnapshotOutput = ajv.compile(editorSnapshotOutputSchema);
|
|
91
|
+
const editorApplyInput = ajv.compile(editorApplyInputSchema);
|
|
92
|
+
const editorApplyOutput = ajv.compile(editorApplyOutputSchema);
|
|
93
|
+
const editorScreenshotOutput = ajv.compile(editorScreenshotOutputSchema);
|
|
94
|
+
const editorSaveOutput = ajv.compile(editorSaveOutputSchema);
|
|
95
|
+
const organizations = options.organizations !== false;
|
|
96
|
+
const orgList = organizations
|
|
97
|
+
? ajv.compile(contractSchema("org.list", "output"))
|
|
98
|
+
: unavailableValidator;
|
|
99
|
+
const orgCurrent = organizations
|
|
100
|
+
? ajv.compile(contractSchema("org.current", "output"))
|
|
101
|
+
: unavailableValidator;
|
|
102
|
+
const toolListOutput = ajv.compile(toolListOutputSchema);
|
|
103
|
+
const modelListInput = ajv.compile(modelListInputSchema);
|
|
104
|
+
const modelListOutput = ajv.compile(modelListOutputSchema);
|
|
105
|
+
const modelGetInput = ajv.compile(modelGetInputSchema);
|
|
106
|
+
const modelGetOutput = ajv.compile(modelGetOutputSchema);
|
|
107
|
+
const toolCallInput = ajv.compile(toolCallInputSchema);
|
|
108
|
+
const toolCallOutput = ajv.compile(toolCallOutputSchema);
|
|
109
|
+
const runOutputSchema = contractSchema("task.get", "output");
|
|
110
|
+
const runSchemaId = runOutputSchema.$id;
|
|
111
|
+
ajv.addSchema(agentSendOutputSchema, new URL("../agent.send/output.schema.json", runSchemaId).href);
|
|
112
|
+
ajv.addSchema(toolCallOutputSchema, new URL("../tool.call/output.schema.json", runSchemaId).href);
|
|
113
|
+
const taskResult = ajv.compile(runOutputSchema);
|
|
114
|
+
const taskListResult = ajv.compile(contractSchema("task.list", "output"));
|
|
115
|
+
return {
|
|
116
|
+
taskResult: assertion(taskResult, OutputContractError),
|
|
117
|
+
taskListResult: assertion(taskListResult, OutputContractError),
|
|
118
|
+
agentSendInput: assertion(agentSendInput, InputContractError),
|
|
119
|
+
agentSendOutput: assertion(agentSendOutput, OutputContractError),
|
|
120
|
+
authStatus: assertion(authStatus, OutputContractError),
|
|
121
|
+
damRepositoryListOutput: assertion(damRepositoryListOutput, OutputContractError),
|
|
122
|
+
damListInput: assertion(damListInput, InputContractError),
|
|
123
|
+
damListOutput: assertion(damListOutput, OutputContractError),
|
|
124
|
+
damSearchInput: assertion(damSearchInput, InputContractError),
|
|
125
|
+
damSearchOutput: assertion(damSearchOutput, OutputContractError),
|
|
126
|
+
damFolderListInput: assertion(damFolderListInput, InputContractError),
|
|
127
|
+
damFolderListOutput: assertion(damFolderListOutput, OutputContractError),
|
|
128
|
+
damTagListInput: assertion(damTagListInput, InputContractError),
|
|
129
|
+
damTagListOutput: assertion(damTagListOutput, OutputContractError),
|
|
130
|
+
damGetInput: assertion(damGetInput, InputContractError),
|
|
131
|
+
damGetOutput: assertion(damGetOutput, OutputContractError),
|
|
132
|
+
damUploadInput: assertion(damUploadInput, InputContractError),
|
|
133
|
+
damUploadOutput: assertion(damUploadOutput, OutputContractError),
|
|
134
|
+
damDeleteInput: assertion(damDeleteInput, InputContractError),
|
|
135
|
+
damDeleteOutput: assertion(damDeleteOutput, OutputContractError),
|
|
136
|
+
damDownloadInput: assertion(damDownloadInput, InputContractError),
|
|
137
|
+
damDownloadOutput: assertion(damDownloadOutput, OutputContractError),
|
|
138
|
+
damRenameInput: assertion(damRenameInput, InputContractError),
|
|
139
|
+
damRenameOutput: assertion(damRenameOutput, OutputContractError),
|
|
140
|
+
damMoveInput: assertion(damMoveInput, InputContractError),
|
|
141
|
+
damMoveOutput: assertion(damMoveOutput, OutputContractError),
|
|
142
|
+
damCopyInput: assertion(damCopyInput, InputContractError),
|
|
143
|
+
damCopyOutput: assertion(damCopyOutput, OutputContractError),
|
|
144
|
+
editorConnectInput: assertion(editorConnectInput, InputContractError),
|
|
145
|
+
editorConnectOutput: assertion(editorConnectOutput, OutputContractError),
|
|
146
|
+
editorDisconnectOutput: assertion(editorDisconnectOutput, OutputContractError),
|
|
147
|
+
editorSnapshotOutput: assertion(editorSnapshotOutput, OutputContractError),
|
|
148
|
+
editorApplyInput: assertion(editorApplyInput, InputContractError),
|
|
149
|
+
editorApplyOutput: assertion(editorApplyOutput, OutputContractError),
|
|
150
|
+
editorScreenshotOutput: assertion(editorScreenshotOutput, OutputContractError),
|
|
151
|
+
editorSaveOutput: assertion(editorSaveOutput, OutputContractError),
|
|
152
|
+
orgList: assertion(orgList, OutputContractError),
|
|
153
|
+
orgCurrent: assertion(orgCurrent, OutputContractError),
|
|
154
|
+
toolListOutput: assertion(toolListOutput, OutputContractError),
|
|
155
|
+
modelListInput: assertion(modelListInput, InputContractError),
|
|
156
|
+
modelListOutput: assertion(modelListOutput, OutputContractError),
|
|
157
|
+
modelGetInput: assertion(modelGetInput, InputContractError),
|
|
158
|
+
modelGetOutput: assertion(modelGetOutput, OutputContractError),
|
|
159
|
+
toolCallInput: assertion(toolCallInput, InputContractError),
|
|
160
|
+
toolCallOutput: assertion(toolCallOutput, OutputContractError)
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const unavailableValidator = Object.assign(() => false, { errors: null, schema: false, schemaEnv: undefined });
|
|
164
|
+
function assertion(validate, ErrorType) {
|
|
165
|
+
return (value) => {
|
|
166
|
+
if (!validate(value))
|
|
167
|
+
throw new ErrorType();
|
|
168
|
+
};
|
|
169
|
+
}
|