dsh-plugin-opc 0.1.9 → 0.1.11
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/lib/client.js +774 -246
- package/lib/index.js +468 -144
- package/package.json +1 -1
- package/runtime/worker.py +41 -18
package/lib/index.js
CHANGED
|
@@ -128,17 +128,37 @@ var ContextStore = class {
|
|
|
128
128
|
};
|
|
129
129
|
|
|
130
130
|
// src/host/http.ts
|
|
131
|
+
function parsePlatformBaseUrl(base) {
|
|
132
|
+
let url;
|
|
133
|
+
try {
|
|
134
|
+
url = new URL(base.trim());
|
|
135
|
+
} catch {
|
|
136
|
+
throw new OpcError("INVALID_PLATFORM_URL", "\u5E73\u53F0\u7F51\u5173\u5730\u5740\u683C\u5F0F\u65E0\u6548\uFF0C\u8BF7\u8F93\u5165\u5B8C\u6574\u7684 https:// \u670D\u52A1\u5730\u5740\u3002");
|
|
137
|
+
}
|
|
138
|
+
if (url.username || url.password || url.search || url.hash) {
|
|
139
|
+
throw new OpcError("INVALID_PLATFORM_URL", "\u5E73\u53F0\u7F51\u5173\u5730\u5740\u4E0D\u80FD\u5305\u542B\u7528\u6237\u540D\u3001\u5BC6\u7801\u3001\u67E5\u8BE2\u53C2\u6570\u6216\u951A\u70B9\u3002");
|
|
140
|
+
}
|
|
141
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && ["127.0.0.1", "localhost"].includes(url.hostname))) {
|
|
142
|
+
throw new OpcError("INSECURE_PLATFORM_URL", "\u5E73\u53F0\u7F51\u5173\u5730\u5740\u5FC5\u987B\u4F7F\u7528 https://\uFF08\u672C\u673A\u8C03\u8BD5\u53EF\u4F7F\u7528 http://localhost \u6216 http://127.0.0.1\uFF09\u3002");
|
|
143
|
+
}
|
|
144
|
+
return url;
|
|
145
|
+
}
|
|
131
146
|
var PlatformHttp = class {
|
|
132
147
|
constructor(base, timeoutMs = 15e3, fetcher = fetch) {
|
|
133
148
|
this.timeoutMs = timeoutMs;
|
|
134
149
|
this.fetcher = fetcher;
|
|
135
|
-
this
|
|
136
|
-
if (this.base.username || this.base.password || this.base.search || this.base.hash) throw new OpcError("INVALID_PLATFORM_URL");
|
|
137
|
-
if (this.base.protocol !== "https:" && !(this.base.protocol === "http:" && ["127.0.0.1", "localhost"].includes(this.base.hostname))) throw new OpcError("INSECURE_PLATFORM_URL");
|
|
150
|
+
this.#base = parsePlatformBaseUrl(base);
|
|
138
151
|
}
|
|
139
152
|
timeoutMs;
|
|
140
153
|
fetcher;
|
|
141
|
-
base;
|
|
154
|
+
#base;
|
|
155
|
+
get base() {
|
|
156
|
+
return this.#base;
|
|
157
|
+
}
|
|
158
|
+
setBase(base) {
|
|
159
|
+
this.#base = parsePlatformBaseUrl(base);
|
|
160
|
+
return this.#base;
|
|
161
|
+
}
|
|
142
162
|
async archive(path, token, signal) {
|
|
143
163
|
if (!path.startsWith("/integration/v1/resources/skills/")) throw new OpcError("INVALID_PLATFORM_PATH");
|
|
144
164
|
const response = await this.fetcher(new URL(path, this.base), { redirect: "error", signal: AbortSignal.any([signal, AbortSignal.timeout(12e4)]), headers: { Authorization: `Bearer ${token}`, Accept: "application/zip" } });
|
|
@@ -319,6 +339,14 @@ var AuthManager = class extends EventEmitter {
|
|
|
319
339
|
async invalidateSession() {
|
|
320
340
|
await this.clear();
|
|
321
341
|
}
|
|
342
|
+
async setPlatformBase(baseUrl) {
|
|
343
|
+
const next = parsePlatformBaseUrl(baseUrl);
|
|
344
|
+
if (next.href === this.http.base.href) return false;
|
|
345
|
+
await this.invalidateSession();
|
|
346
|
+
this.http.setBase(next.href);
|
|
347
|
+
this.changed();
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
322
350
|
async logout() {
|
|
323
351
|
const refresh = this.#refresh, access = this.#access;
|
|
324
352
|
await this.clear();
|
|
@@ -1219,9 +1247,192 @@ var ManagedMcpMounts = class {
|
|
|
1219
1247
|
import { execFile } from "node:child_process";
|
|
1220
1248
|
import { promisify } from "node:util";
|
|
1221
1249
|
import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
1250
|
+
|
|
1251
|
+
// src/host/opc-config.ts
|
|
1252
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
1253
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
1254
|
+
import { mkdir as mkdir2, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
|
|
1255
|
+
import { join as join2 } from "node:path";
|
|
1256
|
+
var DEFAULT_PLATFORM_BASE = "https://shtokendance.benlai.com";
|
|
1257
|
+
var DEFAULT_APP_DOMAIN_ROOT = "10.101.102.116.nip.io:8080";
|
|
1258
|
+
var DEFAULT_APP_DEFAULT_PORT = 8080;
|
|
1259
|
+
function normalizePlatformBaseUrl(raw) {
|
|
1260
|
+
const input = typeof raw === "string" ? raw.trim() : "";
|
|
1261
|
+
if (!input) throw new Error("\u5E73\u53F0\u7F51\u5173\u5730\u5740\u4E0D\u80FD\u4E3A\u7A7A");
|
|
1262
|
+
return parsePlatformBaseUrl(input).href.replace(/\/+$/, "");
|
|
1263
|
+
}
|
|
1264
|
+
function sanitizeDomainRoot(raw) {
|
|
1265
|
+
const trimmed = String(raw ?? "").trim().replace(/^https?:\/\//i, "").replace(/\/+$/, "").trim();
|
|
1266
|
+
if (trimmed && /[\s/?#]/.test(trimmed)) {
|
|
1267
|
+
throw new Error("\u5E94\u7528\u5185\u7F51\u6839\u57DF\u540D\u540E\u7F00\u683C\u5F0F\u65E0\u6548\uFF0C\u8BF7\u586B\u5199\u5982 10.101.102.116.nip.io:8080");
|
|
1268
|
+
}
|
|
1269
|
+
return trimmed;
|
|
1270
|
+
}
|
|
1271
|
+
function validateAppDefaultPort(raw) {
|
|
1272
|
+
const num = typeof raw === "number" ? raw : Number(String(raw ?? "").trim());
|
|
1273
|
+
if (!Number.isInteger(num) || num < 1 || num > 65535) {
|
|
1274
|
+
throw new Error("\u5E94\u7528\u9ED8\u8BA4\u5BB9\u5668\u7AEF\u53E3\u5FC5\u987B\u4E3A 1 \u81F3 65535 \u7684\u6574\u6570");
|
|
1275
|
+
}
|
|
1276
|
+
return num;
|
|
1277
|
+
}
|
|
1278
|
+
var OpcConfigStore = class {
|
|
1279
|
+
constructor(home, initial = {}, fetcher = fetch) {
|
|
1280
|
+
this.home = home;
|
|
1281
|
+
this.fetcher = fetcher;
|
|
1282
|
+
this.filePath = join2(this.home, "opc", "platform-config.json");
|
|
1283
|
+
let platformBase = DEFAULT_PLATFORM_BASE;
|
|
1284
|
+
try {
|
|
1285
|
+
if (initial.platformBaseUrl?.trim()) platformBase = normalizePlatformBaseUrl(initial.platformBaseUrl);
|
|
1286
|
+
} catch {
|
|
1287
|
+
platformBase = DEFAULT_PLATFORM_BASE;
|
|
1288
|
+
}
|
|
1289
|
+
let domainRoot = "";
|
|
1290
|
+
try {
|
|
1291
|
+
if (initial.appDomainRoot?.trim()) domainRoot = sanitizeDomainRoot(initial.appDomainRoot);
|
|
1292
|
+
} catch {
|
|
1293
|
+
domainRoot = "";
|
|
1294
|
+
}
|
|
1295
|
+
let defaultPort = DEFAULT_APP_DEFAULT_PORT;
|
|
1296
|
+
try {
|
|
1297
|
+
if (initial.appDefaultPort !== void 0) defaultPort = validateAppDefaultPort(initial.appDefaultPort);
|
|
1298
|
+
} catch {
|
|
1299
|
+
defaultPort = DEFAULT_APP_DEFAULT_PORT;
|
|
1300
|
+
}
|
|
1301
|
+
this.#fallback = {
|
|
1302
|
+
platform_base: platformBase,
|
|
1303
|
+
app_domain_root: domainRoot,
|
|
1304
|
+
app_default_port: defaultPort
|
|
1305
|
+
};
|
|
1306
|
+
this.#current = { ...this.#fallback };
|
|
1307
|
+
}
|
|
1308
|
+
home;
|
|
1309
|
+
fetcher;
|
|
1310
|
+
filePath;
|
|
1311
|
+
#fallback;
|
|
1312
|
+
#current;
|
|
1313
|
+
loadSync() {
|
|
1314
|
+
if (!existsSync(this.filePath)) {
|
|
1315
|
+
this.#current = { ...this.#fallback };
|
|
1316
|
+
return this.current;
|
|
1317
|
+
}
|
|
1318
|
+
try {
|
|
1319
|
+
const parsed = JSON.parse(readFileSync(this.filePath, "utf8"));
|
|
1320
|
+
let platform_base = this.#fallback.platform_base;
|
|
1321
|
+
try {
|
|
1322
|
+
if (typeof parsed.platform_base === "string" && parsed.platform_base.trim()) {
|
|
1323
|
+
platform_base = normalizePlatformBaseUrl(parsed.platform_base);
|
|
1324
|
+
}
|
|
1325
|
+
} catch {
|
|
1326
|
+
}
|
|
1327
|
+
let app_domain_root = this.#fallback.app_domain_root;
|
|
1328
|
+
try {
|
|
1329
|
+
if (typeof parsed.app_domain_root === "string") {
|
|
1330
|
+
app_domain_root = sanitizeDomainRoot(parsed.app_domain_root);
|
|
1331
|
+
}
|
|
1332
|
+
} catch {
|
|
1333
|
+
}
|
|
1334
|
+
let app_default_port = this.#fallback.app_default_port;
|
|
1335
|
+
try {
|
|
1336
|
+
if (parsed.app_default_port !== void 0) {
|
|
1337
|
+
app_default_port = validateAppDefaultPort(parsed.app_default_port);
|
|
1338
|
+
}
|
|
1339
|
+
} catch {
|
|
1340
|
+
}
|
|
1341
|
+
this.#current = { platform_base, app_domain_root, app_default_port };
|
|
1342
|
+
} catch {
|
|
1343
|
+
this.#current = { ...this.#fallback };
|
|
1344
|
+
}
|
|
1345
|
+
return this.current;
|
|
1346
|
+
}
|
|
1347
|
+
get current() {
|
|
1348
|
+
return { ...this.#current };
|
|
1349
|
+
}
|
|
1350
|
+
getPayload(livePlatformBase) {
|
|
1351
|
+
const platform_base = livePlatformBase?.trim() ? livePlatformBase.replace(/\/+$/, "") : this.#current.platform_base;
|
|
1352
|
+
return {
|
|
1353
|
+
platform_base,
|
|
1354
|
+
app_domain_root: this.#current.app_domain_root,
|
|
1355
|
+
app_default_port: this.#current.app_default_port,
|
|
1356
|
+
default_platform_base: DEFAULT_PLATFORM_BASE,
|
|
1357
|
+
default_app_domain_root: DEFAULT_APP_DOMAIN_ROOT,
|
|
1358
|
+
default_app_default_port: DEFAULT_APP_DEFAULT_PORT,
|
|
1359
|
+
effective_app_domain_root: this.#current.app_domain_root || DEFAULT_APP_DOMAIN_ROOT
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
async persist(value) {
|
|
1363
|
+
const dir = join2(this.home, "opc");
|
|
1364
|
+
await mkdir2(dir, { recursive: true, mode: 448 });
|
|
1365
|
+
const temp = join2(dir, `platform-config-${randomUUID3()}.tmp`);
|
|
1366
|
+
await writeFile2(temp, `${JSON.stringify(value, null, 2)}
|
|
1367
|
+
`, { mode: 384 });
|
|
1368
|
+
await rename2(temp, this.filePath);
|
|
1369
|
+
}
|
|
1370
|
+
async update(patch) {
|
|
1371
|
+
const prevBase = this.#current.platform_base;
|
|
1372
|
+
const nextBase = patch.platform_base !== void 0 ? normalizePlatformBaseUrl(patch.platform_base) : this.#current.platform_base;
|
|
1373
|
+
const nextDomainRoot = patch.app_domain_root !== void 0 ? sanitizeDomainRoot(patch.app_domain_root) : this.#current.app_domain_root;
|
|
1374
|
+
const nextDefaultPort = patch.app_default_port !== void 0 ? validateAppDefaultPort(patch.app_default_port) : this.#current.app_default_port;
|
|
1375
|
+
const next = {
|
|
1376
|
+
platform_base: nextBase,
|
|
1377
|
+
app_domain_root: nextDomainRoot,
|
|
1378
|
+
app_default_port: nextDefaultPort
|
|
1379
|
+
};
|
|
1380
|
+
await this.persist(next);
|
|
1381
|
+
this.#current = next;
|
|
1382
|
+
return {
|
|
1383
|
+
config: this.getPayload(),
|
|
1384
|
+
platform_base_changed: nextBase !== prevBase
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
async reset() {
|
|
1388
|
+
return this.update({
|
|
1389
|
+
platform_base: DEFAULT_PLATFORM_BASE,
|
|
1390
|
+
app_domain_root: "",
|
|
1391
|
+
app_default_port: DEFAULT_APP_DEFAULT_PORT
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
async testConnection(rawUrl) {
|
|
1395
|
+
let url;
|
|
1396
|
+
try {
|
|
1397
|
+
url = parsePlatformBaseUrl(String(rawUrl ?? ""));
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
return {
|
|
1400
|
+
ok: false,
|
|
1401
|
+
error: error instanceof Error ? error.message : "\u670D\u52A1\u5730\u5740\u65E0\u6548"
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
const started = performance.now();
|
|
1405
|
+
try {
|
|
1406
|
+
const response = await this.fetcher(url.href, {
|
|
1407
|
+
method: "GET",
|
|
1408
|
+
signal: AbortSignal.timeout(5e3),
|
|
1409
|
+
redirect: "manual"
|
|
1410
|
+
});
|
|
1411
|
+
const latency_ms = Math.max(0, Math.round(performance.now() - started));
|
|
1412
|
+
if (response.status < 500) {
|
|
1413
|
+
return { ok: true, status_code: response.status, latency_ms };
|
|
1414
|
+
}
|
|
1415
|
+
return {
|
|
1416
|
+
ok: false,
|
|
1417
|
+
status_code: response.status,
|
|
1418
|
+
latency_ms,
|
|
1419
|
+
error: `HTTP ${response.status}`
|
|
1420
|
+
};
|
|
1421
|
+
} catch (error) {
|
|
1422
|
+
const latency_ms = Math.max(0, Math.round(performance.now() - started));
|
|
1423
|
+
return {
|
|
1424
|
+
ok: false,
|
|
1425
|
+
latency_ms,
|
|
1426
|
+
error: error instanceof Error ? error.message : "\u65E0\u6CD5\u8FDE\u63A5\u5230\u670D\u52A1\u5668"
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1432
|
+
// src/host/remote-service.ts
|
|
1222
1433
|
var execFileAsync = promisify(execFile);
|
|
1223
|
-
var _decideDebugInvocation_dec, _unmountMcpService_dec, _mountMcpService_dec, _invokeMcpTool_dec, _listMcpServices_dec, _readKnowledgeDocument_dec, _searchKnowledge_dec, _setPinnedKnowledgeScope_dec, _uninstallSkill_dec, _setSkillEnabled_dec, _installSkill_dec, _listSkillsCatalog_dec, _listKnowledgeBases_dec, _switchTenant_dec, _logout_dec, _cancelLogin_dec, _startLogin_dec, _watchState_dec, _state_dec, _appRollback_dec, _appDelete_dec, _appUpdateConfig_dec, _appRecheck_dec, _appSaveDownload_dec, _appDownload_dec, _appStorage_dec, _appLogs_dec, _appVersions_dec, _appDetails_dec, _appResources_dec, _appSetSkillEnabled_dec, _appVerifyWithOptions_dec, _appVerify_dec, _appPublish_dec, _appConfirmDeployment_dec, _appSkillPreview_dec, _appHandoff_dec, _appSaveLocalArtifact_dec, _appLocalArtifact_dec, _appSaveConfigDraft_dec, _appConfigDraft_dec, _appCancelAnalysis_dec, _appReopenDeployment_dec, _appReopenReview_dec, _appPrepare_dec, _appAnalyzeWithMode_dec, _appAnalyze_dec, _appCreate_dec, _appCatalog_dec, _appModels_dec, _appPickSourceFolder_dec, _appOpcConfig_dec, _appCheckSlug_dec, _appJob_dec, _appList_dec, _a, _init;
|
|
1224
|
-
var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [Remote], _appJob_dec = [Remote], _appCheckSlug_dec = [Remote], _appOpcConfig_dec = [Remote], _appPickSourceFolder_dec = [Remote], _appModels_dec = [Remote], _appCatalog_dec = [Remote], _appCreate_dec = [Remote], _appAnalyze_dec = [Remote], _appAnalyzeWithMode_dec = [Remote], _appPrepare_dec = [Remote], _appReopenReview_dec = [Remote], _appReopenDeployment_dec = [Remote], _appCancelAnalysis_dec = [Remote], _appConfigDraft_dec = [Remote], _appSaveConfigDraft_dec = [Remote], _appLocalArtifact_dec = [Remote], _appSaveLocalArtifact_dec = [Remote], _appHandoff_dec = [Remote], _appSkillPreview_dec = [Remote], _appConfirmDeployment_dec = [Remote], _appPublish_dec = [Remote], _appVerify_dec = [Remote], _appVerifyWithOptions_dec = [Remote], _appSetSkillEnabled_dec = [Remote], _appResources_dec = [Remote], _appDetails_dec = [Remote], _appVersions_dec = [Remote], _appLogs_dec = [Remote], _appStorage_dec = [Remote], _appDownload_dec = [Remote], _appSaveDownload_dec = [Remote], _appRecheck_dec = [Remote], _appUpdateConfig_dec = [Remote], _appDelete_dec = [Remote], _appRollback_dec = [Remote], _state_dec = [Remote], _watchState_dec = [Remote({ mode: "stream" })], _startLogin_dec = [Remote], _cancelLogin_dec = [Remote], _logout_dec = [Remote], _switchTenant_dec = [Remote], _listKnowledgeBases_dec = [Remote], _listSkillsCatalog_dec = [Remote], _installSkill_dec = [Remote], _setSkillEnabled_dec = [Remote], _uninstallSkill_dec = [Remote], _setPinnedKnowledgeScope_dec = [Remote], _searchKnowledge_dec = [Remote], _readKnowledgeDocument_dec = [Remote], _listMcpServices_dec = [Remote], _invokeMcpTool_dec = [Remote], _mountMcpService_dec = [Remote], _unmountMcpService_dec = [Remote], _decideDebugInvocation_dec = [Remote], _a) {
|
|
1434
|
+
var _decideDebugInvocation_dec, _unmountMcpService_dec, _mountMcpService_dec, _invokeMcpTool_dec, _listMcpServices_dec, _readKnowledgeDocument_dec, _searchKnowledge_dec, _setPinnedKnowledgeScope_dec, _uninstallSkill_dec, _setSkillEnabled_dec, _installSkill_dec, _listSkillsCatalog_dec, _listKnowledgeBases_dec, _switchTenant_dec, _logout_dec, _cancelLogin_dec, _startLogin_dec, _watchState_dec, _state_dec, _opcConfigTest_dec, _opcConfigReset_dec, _opcConfigUpdate_dec, _opcConfigGet_dec, _appRollback_dec, _appDelete_dec, _appUpdateConfig_dec, _appRecheck_dec, _appSaveDownload_dec, _appDownload_dec, _appStorage_dec, _appLogs_dec, _appVersions_dec, _appDetails_dec, _appResources_dec, _appSetSkillEnabled_dec, _appVerifyWithOptions_dec, _appVerify_dec, _appPublish_dec, _appConfirmDeployment_dec, _appSkillPreview_dec, _appHandoff_dec, _appSaveLocalArtifact_dec, _appLocalArtifact_dec, _appSaveConfigDraft_dec, _appConfigDraft_dec, _appCancelAnalysis_dec, _appReopenDeployment_dec, _appReopenReview_dec, _appPrepare_dec, _appAnalyzeWithMode_dec, _appAnalyze_dec, _appCreate_dec, _appCatalog_dec, _appModels_dec, _appPickSourceFolder_dec, _appOpcConfig_dec, _appCheckSlug_dec, _appJob_dec, _appList_dec, _a, _init;
|
|
1435
|
+
var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [Remote], _appJob_dec = [Remote], _appCheckSlug_dec = [Remote], _appOpcConfig_dec = [Remote], _appPickSourceFolder_dec = [Remote], _appModels_dec = [Remote], _appCatalog_dec = [Remote], _appCreate_dec = [Remote], _appAnalyze_dec = [Remote], _appAnalyzeWithMode_dec = [Remote], _appPrepare_dec = [Remote], _appReopenReview_dec = [Remote], _appReopenDeployment_dec = [Remote], _appCancelAnalysis_dec = [Remote], _appConfigDraft_dec = [Remote], _appSaveConfigDraft_dec = [Remote], _appLocalArtifact_dec = [Remote], _appSaveLocalArtifact_dec = [Remote], _appHandoff_dec = [Remote], _appSkillPreview_dec = [Remote], _appConfirmDeployment_dec = [Remote], _appPublish_dec = [Remote], _appVerify_dec = [Remote], _appVerifyWithOptions_dec = [Remote], _appSetSkillEnabled_dec = [Remote], _appResources_dec = [Remote], _appDetails_dec = [Remote], _appVersions_dec = [Remote], _appLogs_dec = [Remote], _appStorage_dec = [Remote], _appDownload_dec = [Remote], _appSaveDownload_dec = [Remote], _appRecheck_dec = [Remote], _appUpdateConfig_dec = [Remote], _appDelete_dec = [Remote], _appRollback_dec = [Remote], _opcConfigGet_dec = [Remote], _opcConfigUpdate_dec = [Remote], _opcConfigReset_dec = [Remote], _opcConfigTest_dec = [Remote], _state_dec = [Remote], _watchState_dec = [Remote({ mode: "stream" })], _startLogin_dec = [Remote], _cancelLogin_dec = [Remote], _logout_dec = [Remote], _switchTenant_dec = [Remote], _listKnowledgeBases_dec = [Remote], _listSkillsCatalog_dec = [Remote], _installSkill_dec = [Remote], _setSkillEnabled_dec = [Remote], _uninstallSkill_dec = [Remote], _setPinnedKnowledgeScope_dec = [Remote], _searchKnowledge_dec = [Remote], _readKnowledgeDocument_dec = [Remote], _listMcpServices_dec = [Remote], _invokeMcpTool_dec = [Remote], _mountMcpService_dec = [Remote], _unmountMcpService_dec = [Remote], _decideDebugInvocation_dec = [Remote], _a) {
|
|
1225
1436
|
constructor(ctx, options) {
|
|
1226
1437
|
super(ctx, "opc");
|
|
1227
1438
|
__runInitializers(_init, 5, this);
|
|
@@ -1230,14 +1441,19 @@ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [
|
|
|
1230
1441
|
__publicField(this, "manager");
|
|
1231
1442
|
__publicField(this, "core");
|
|
1232
1443
|
__publicField(this, "delivery");
|
|
1444
|
+
__publicField(this, "configStore");
|
|
1233
1445
|
__publicField(this, "host");
|
|
1234
1446
|
__publicField(this, "requestApproval", async () => {
|
|
1235
1447
|
return "allowed-once";
|
|
1236
1448
|
});
|
|
1237
|
-
const { core, delivery } = options;
|
|
1449
|
+
const { core, delivery, configStore } = options;
|
|
1238
1450
|
this.host = ctx;
|
|
1239
1451
|
this.core = core;
|
|
1240
1452
|
this.delivery = delivery;
|
|
1453
|
+
this.configStore = configStore ?? new OpcConfigStore(delivery.home, {
|
|
1454
|
+
platformBaseUrl: core.auth.http.base.href,
|
|
1455
|
+
...delivery.getOptions()
|
|
1456
|
+
});
|
|
1241
1457
|
ctx.inject(["mcpManager"], (child) => {
|
|
1242
1458
|
const manager = child.mcpManager;
|
|
1243
1459
|
const mounts = new ManagedMcpMounts(core, (name2, entry) => manager.register(name2, entry), this.requestApproval, { autoMount: true });
|
|
@@ -1410,13 +1626,41 @@ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [
|
|
|
1410
1626
|
const parsed = JSON.parse(payloadJson);
|
|
1411
1627
|
return JSON.stringify(await this.delivery.rollback(slug, Number(parsed.targetVersion ?? parsed.target_version ?? 0), String(parsed.reason ?? ""), expectedContextId));
|
|
1412
1628
|
}
|
|
1629
|
+
async applyConfigChange(result) {
|
|
1630
|
+
const { config, platform_base_changed } = result;
|
|
1631
|
+
await this.core.auth.setPlatformBase(config.platform_base);
|
|
1632
|
+
this.delivery.updateOptions({
|
|
1633
|
+
appDomainRoot: config.app_domain_root,
|
|
1634
|
+
appDefaultPort: config.app_default_port
|
|
1635
|
+
});
|
|
1636
|
+
if (platform_base_changed) this.core.emit("skills-changed");
|
|
1637
|
+
return JSON.stringify({ ...config, platform_base_changed });
|
|
1638
|
+
}
|
|
1639
|
+
async opcConfigGet() {
|
|
1640
|
+
return JSON.stringify(this.configStore.getPayload(this.core.auth.http.base.href));
|
|
1641
|
+
}
|
|
1642
|
+
async opcConfigUpdate(payloadJson) {
|
|
1643
|
+
const parsed = JSON.parse(payloadJson);
|
|
1644
|
+
return this.applyConfigChange(await this.configStore.update({
|
|
1645
|
+
platform_base: parsed.platform_base,
|
|
1646
|
+
app_domain_root: parsed.app_domain_root,
|
|
1647
|
+
app_default_port: parsed.app_default_port
|
|
1648
|
+
}));
|
|
1649
|
+
}
|
|
1650
|
+
async opcConfigReset() {
|
|
1651
|
+
return this.applyConfigChange(await this.configStore.reset());
|
|
1652
|
+
}
|
|
1653
|
+
async opcConfigTest(url) {
|
|
1654
|
+
return JSON.stringify(await this.configStore.testConnection(url));
|
|
1655
|
+
}
|
|
1413
1656
|
async state() {
|
|
1414
1657
|
const state = this.core.auth.state;
|
|
1415
1658
|
const mounted = this.mounts?.list() ?? [];
|
|
1659
|
+
const cfg = this.configStore.getPayload(this.core.auth.http.base.href);
|
|
1416
1660
|
return JSON.stringify({ ...state, knowledgeMentionScopeVersion: 1, mountAvailable: !!this.mounts, mcpConnections: Object.fromEntries(mounted.map((id) => {
|
|
1417
1661
|
const status = this.manager?.list().find((item) => item.name === mcpMountName(id))?.status;
|
|
1418
1662
|
return [id, { state: status?.state ?? "connecting", toolCount: status?.state === "connected" ? status.toolCount : 0 }];
|
|
1419
|
-
})), pinnedScopes: this.core.scopes.pins(), mountedServices: mounted, approvals: [...this.pendingApprovals].map(([id, pending]) => ({ id, contextId: pending.contextId, ...pending.prompt })), context: state.context ? { ...state.context, contextId: contextId(state.context), applicationContextId: this.core.auth.contexts.applicationContextId, epoch: this.core.auth.contexts.epoch } : null });
|
|
1663
|
+
})), pinnedScopes: this.core.scopes.pins(), mountedServices: mounted, approvals: [...this.pendingApprovals].map(([id, pending]) => ({ id, contextId: pending.contextId, ...pending.prompt })), opcConfig: { platformBaseUrl: cfg.platform_base, appDomainRoot: cfg.effective_app_domain_root, rawAppDomainRoot: cfg.app_domain_root, defaultPort: cfg.app_default_port }, context: state.context ? { ...state.context, contextId: contextId(state.context), applicationContextId: this.core.auth.contexts.applicationContextId, epoch: this.core.auth.contexts.epoch } : null });
|
|
1420
1664
|
}
|
|
1421
1665
|
async *watchState(signal) {
|
|
1422
1666
|
let wake, dirty = true;
|
|
@@ -1562,6 +1806,10 @@ __decorateElement(_init, 1, "appRecheck", _appRecheck_dec, OpcRemoteService);
|
|
|
1562
1806
|
__decorateElement(_init, 1, "appUpdateConfig", _appUpdateConfig_dec, OpcRemoteService);
|
|
1563
1807
|
__decorateElement(_init, 1, "appDelete", _appDelete_dec, OpcRemoteService);
|
|
1564
1808
|
__decorateElement(_init, 1, "appRollback", _appRollback_dec, OpcRemoteService);
|
|
1809
|
+
__decorateElement(_init, 1, "opcConfigGet", _opcConfigGet_dec, OpcRemoteService);
|
|
1810
|
+
__decorateElement(_init, 1, "opcConfigUpdate", _opcConfigUpdate_dec, OpcRemoteService);
|
|
1811
|
+
__decorateElement(_init, 1, "opcConfigReset", _opcConfigReset_dec, OpcRemoteService);
|
|
1812
|
+
__decorateElement(_init, 1, "opcConfigTest", _opcConfigTest_dec, OpcRemoteService);
|
|
1565
1813
|
__decorateElement(_init, 1, "state", _state_dec, OpcRemoteService);
|
|
1566
1814
|
__decorateElement(_init, 1, "watchState", _watchState_dec, OpcRemoteService);
|
|
1567
1815
|
__decorateElement(_init, 1, "startLogin", _startLogin_dec, OpcRemoteService);
|
|
@@ -1638,11 +1886,11 @@ function registerTools(ctx, core) {
|
|
|
1638
1886
|
}
|
|
1639
1887
|
|
|
1640
1888
|
// src/host/app-delivery.ts
|
|
1641
|
-
import { createWriteStream, existsSync } from "node:fs";
|
|
1889
|
+
import { createWriteStream, existsSync as existsSync2 } from "node:fs";
|
|
1642
1890
|
import { spawn } from "node:child_process";
|
|
1643
|
-
import { createHash as createHash5, randomUUID as
|
|
1644
|
-
import { copyFile, link, lstat as lstat2, mkdir as
|
|
1645
|
-
import { dirname as dirname3, isAbsolute, join as
|
|
1891
|
+
import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
|
|
1892
|
+
import { copyFile, link, lstat as lstat2, mkdir as mkdir3, readFile as readFile2, readdir as readdir2, stat, writeFile as writeFile3, rename as rename3, rm as rm2 } from "node:fs/promises";
|
|
1893
|
+
import { dirname as dirname3, isAbsolute, join as join3 } from "node:path";
|
|
1646
1894
|
import { homedir } from "node:os";
|
|
1647
1895
|
import { Transform } from "node:stream";
|
|
1648
1896
|
import { pipeline } from "node:stream/promises";
|
|
@@ -1700,9 +1948,9 @@ function worker(input, signal) {
|
|
|
1700
1948
|
const runtime = import.meta.url.endsWith("/lib/index.js") ? fileURLToPath(new URL("../runtime/worker.py", import.meta.url)) : path;
|
|
1701
1949
|
const executable = dirname3(process.execPath);
|
|
1702
1950
|
const bundled = [
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
].find((candidate) =>
|
|
1951
|
+
join3(executable, "../Resources/runtime/primary-runtime/dependencies/python/bin/python3"),
|
|
1952
|
+
join3(executable, "../../python/bin/python3")
|
|
1953
|
+
].find((candidate) => existsSync2(candidate));
|
|
1706
1954
|
return new Promise((resolve, reject) => {
|
|
1707
1955
|
const child = spawn(bundled ?? "python3", ["-I", "-B", runtime], { stdio: ["pipe", "pipe", "pipe"], env: { PATH: process.env.PATH, HOME: process.env.HOME, LANG: "en_US.UTF-8" }, signal, timeout: 12e4 });
|
|
1708
1956
|
let stdout = "", stderr = "", exceeded = false;
|
|
@@ -1753,21 +2001,32 @@ var AppDelivery = class {
|
|
|
1753
2001
|
busy = /* @__PURE__ */ new Set();
|
|
1754
2002
|
analyses = /* @__PURE__ */ new Map();
|
|
1755
2003
|
analyze;
|
|
2004
|
+
getOptions() {
|
|
2005
|
+
return { ...this.options };
|
|
2006
|
+
}
|
|
2007
|
+
updateOptions(next) {
|
|
2008
|
+
this.options = {
|
|
2009
|
+
...this.options,
|
|
2010
|
+
...next.appDomainRoot !== void 0 ? { appDomainRoot: next.appDomainRoot } : {},
|
|
2011
|
+
...next.appDefaultPort !== void 0 ? { appDefaultPort: next.appDefaultPort } : {}
|
|
2012
|
+
};
|
|
2013
|
+
this.core.emit("change");
|
|
2014
|
+
}
|
|
1756
2015
|
scope(expected) {
|
|
1757
2016
|
const captured = this.core.auth.contexts.captureApplication(expected);
|
|
1758
|
-
const directory =
|
|
2017
|
+
const directory = join3(this.home, "opc", "apps", identityHash(captured.context));
|
|
1759
2018
|
return { ...captured, directory };
|
|
1760
2019
|
}
|
|
1761
2020
|
async save(root, job) {
|
|
1762
|
-
await
|
|
1763
|
-
const temp =
|
|
1764
|
-
await
|
|
1765
|
-
await
|
|
2021
|
+
await mkdir3(root, { recursive: true, mode: 448 });
|
|
2022
|
+
const temp = join3(root, `job-${randomUUID4()}.tmp`);
|
|
2023
|
+
await writeFile3(temp, JSON.stringify(job), { mode: 384 });
|
|
2024
|
+
await rename3(temp, join3(root, "job.json"));
|
|
1766
2025
|
this.core.emit("change");
|
|
1767
2026
|
}
|
|
1768
2027
|
skillPreferencePath(directory, slug) {
|
|
1769
2028
|
if (!/^[a-z][a-z0-9-]{2,39}$/.test(slug)) throw new Error("\u65E0\u6548\u5E94\u7528\u6807\u8BC6");
|
|
1770
|
-
return
|
|
2029
|
+
return join3(directory, "skill-preferences", slug);
|
|
1771
2030
|
}
|
|
1772
2031
|
async isSkillDisabled(directory, slug) {
|
|
1773
2032
|
return readFile2(this.skillPreferencePath(directory, slug), "utf8").then((value) => value === "disabled", (error) => {
|
|
@@ -1780,14 +2039,14 @@ var AppDelivery = class {
|
|
|
1780
2039
|
if (error.code === "ENOENT") return [];
|
|
1781
2040
|
throw error;
|
|
1782
2041
|
});
|
|
1783
|
-
return [directory, ...entries.filter((id) => /^[a-f0-9]{64}$/.test(id)).map((id) =>
|
|
2042
|
+
return [directory, ...entries.filter((id) => /^[a-f0-9]{64}$/.test(id)).map((id) => join3(directory, id))];
|
|
1784
2043
|
}
|
|
1785
2044
|
async open(directory, id) {
|
|
1786
2045
|
if (!/^[a-f0-9-]{36}$/.test(id)) throw new Error("\u65E0\u6548\u4EFB\u52A1");
|
|
1787
2046
|
for (const parent of await this.directories(directory)) {
|
|
1788
|
-
const root =
|
|
2047
|
+
const root = join3(parent, id);
|
|
1789
2048
|
try {
|
|
1790
|
-
const job = JSON.parse(await readFile2(
|
|
2049
|
+
const job = JSON.parse(await readFile2(join3(root, "job.json"), "utf8"));
|
|
1791
2050
|
return { root, job };
|
|
1792
2051
|
} catch (error) {
|
|
1793
2052
|
if (error.code !== "ENOENT") throw error;
|
|
@@ -1795,8 +2054,9 @@ var AppDelivery = class {
|
|
|
1795
2054
|
}
|
|
1796
2055
|
throw Object.assign(new Error("\u5E94\u7528\u4EFB\u52A1\u4E0D\u5B58\u5728"), { code: "ENOENT" });
|
|
1797
2056
|
}
|
|
1798
|
-
recordFailureState(job, errorMsg, extraLog, remoteVersion) {
|
|
2057
|
+
recordFailureState(job, errorMsg, extraLog, remoteVersion, stage = "deployment") {
|
|
1799
2058
|
job.status = "failed";
|
|
2059
|
+
job.failureStage = stage;
|
|
1800
2060
|
job.error = errorMsg;
|
|
1801
2061
|
job.failedRevision = job.revision || job.failedRevision;
|
|
1802
2062
|
const combinedLog = [errorMsg, extraLog].filter(Boolean).join("\n");
|
|
@@ -1811,16 +2071,28 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1811
2071
|
verificationError: errorMsg
|
|
1812
2072
|
};
|
|
1813
2073
|
}
|
|
2074
|
+
async recoverInterrupted(root, job) {
|
|
2075
|
+
const interrupted = { importing: "import", analyzing: "analysis", preparing: "preparation", verifying: "verification" };
|
|
2076
|
+
if (job.status === "publishing") {
|
|
2077
|
+
job.status = "unknown";
|
|
2078
|
+
job.error = "\u53D1\u5E03\u7ED3\u679C\u672A\u77E5\uFF0C\u8BF7\u67E5\u8BE2\u72B6\u6001\uFF0C\u4E0D\u8981\u91CD\u590D\u53D1\u5E03";
|
|
2079
|
+
} else if (job.status in interrupted) {
|
|
2080
|
+
job.failureStage = interrupted[job.status];
|
|
2081
|
+
job.status = "failed";
|
|
2082
|
+
job.error = "\u4E0A\u6B21\u4EFB\u52A1\u4E2D\u65AD\uFF0C\u53EF\u4ECE\u5F53\u524D\u6B65\u9AA4\u7EE7\u7EED";
|
|
2083
|
+
} else return;
|
|
2084
|
+
await this.save(root, job);
|
|
2085
|
+
}
|
|
1814
2086
|
async archivePublishedVersion(scopeDir, job, bundleDir) {
|
|
1815
2087
|
const { slug, version, requestId, id: jobId } = job;
|
|
1816
2088
|
if (!/^[a-z][a-z0-9-]{2,39}$/.test(slug) || !version || version <= 0) return;
|
|
1817
|
-
const verDir =
|
|
1818
|
-
await
|
|
2089
|
+
const verDir = join3(scopeDir, "versions", slug, `v${version}`);
|
|
2090
|
+
await mkdir3(verDir, { recursive: true, mode: 448 });
|
|
1819
2091
|
const hashes = {};
|
|
1820
2092
|
for (const name2 of ["app.tar", "skill.zip", "app-manifest.json", "summary.json"]) {
|
|
1821
2093
|
try {
|
|
1822
|
-
const src =
|
|
1823
|
-
await copyFile(src,
|
|
2094
|
+
const src = join3(bundleDir, name2);
|
|
2095
|
+
await copyFile(src, join3(verDir, name2));
|
|
1824
2096
|
if (name2 === "app.tar" || name2 === "skill.zip") {
|
|
1825
2097
|
hashes[name2] = hash(await readFile2(src));
|
|
1826
2098
|
}
|
|
@@ -1828,7 +2100,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1828
2100
|
}
|
|
1829
2101
|
}
|
|
1830
2102
|
if (Object.keys(hashes).length > 0) {
|
|
1831
|
-
await
|
|
2103
|
+
await writeFile3(join3(verDir, "summary.json"), JSON.stringify({ version, hashes, jobId, requestId }, null, 2), { mode: 384 }).catch(() => {
|
|
1832
2104
|
});
|
|
1833
2105
|
}
|
|
1834
2106
|
}
|
|
@@ -1863,15 +2135,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1863
2135
|
if (!this.busy.has(id) && ["importing", "analyzing", "preparing", "verifying", "publishing"].includes(job.status)) {
|
|
1864
2136
|
await this.exclusive(id, async () => {
|
|
1865
2137
|
job = (await this.open(scope.directory, id)).job;
|
|
1866
|
-
|
|
1867
|
-
job.status = "failed";
|
|
1868
|
-
job.error = "\u4E0A\u6B21\u4EFB\u52A1\u4E2D\u65AD\uFF0C\u53EF\u91CD\u65B0\u5206\u6790\u6216\u9A8C\u8BC1";
|
|
1869
|
-
await this.save(root, job);
|
|
1870
|
-
} else if (job.status === "publishing") {
|
|
1871
|
-
job.status = "unknown";
|
|
1872
|
-
job.error = "\u53D1\u5E03\u7ED3\u679C\u672A\u77E5\uFF0C\u8BF7\u67E5\u8BE2\u72B6\u6001\uFF0C\u4E0D\u8981\u91CD\u590D\u53D1\u5E03";
|
|
1873
|
-
await this.save(root, job);
|
|
1874
|
-
}
|
|
2138
|
+
await this.recoverInterrupted(root, job);
|
|
1875
2139
|
});
|
|
1876
2140
|
}
|
|
1877
2141
|
if (!this.busy.has(id) && ["unknown", "building"].includes(job.status)) {
|
|
@@ -1894,7 +2158,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1894
2158
|
job.status = "building";
|
|
1895
2159
|
job.error = void 0;
|
|
1896
2160
|
if (job.revision && job.version) {
|
|
1897
|
-
await this.archivePublishedVersion(scope.directory, job,
|
|
2161
|
+
await this.archivePublishedVersion(scope.directory, job, join3(root, job.revision, "bundle"));
|
|
1898
2162
|
}
|
|
1899
2163
|
}
|
|
1900
2164
|
await this.save(root, job);
|
|
@@ -1929,15 +2193,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1929
2193
|
if (!this.busy.has(id) && ["importing", "analyzing", "preparing", "verifying", "publishing"].includes(job.status)) {
|
|
1930
2194
|
await this.exclusive(id, async () => {
|
|
1931
2195
|
job = (await this.open(scope.directory, id)).job;
|
|
1932
|
-
|
|
1933
|
-
job.status = "failed";
|
|
1934
|
-
job.error = "\u4E0A\u6B21\u4EFB\u52A1\u4E2D\u65AD\uFF0C\u53EF\u91CD\u65B0\u5206\u6790\u6216\u9A8C\u8BC1";
|
|
1935
|
-
await this.save(root, job);
|
|
1936
|
-
} else if (job.status === "publishing") {
|
|
1937
|
-
job.status = "unknown";
|
|
1938
|
-
job.error = "\u53D1\u5E03\u7ED3\u679C\u672A\u77E5\uFF0C\u8BF7\u67E5\u8BE2\u72B6\u6001\uFF0C\u4E0D\u8981\u91CD\u590D\u53D1\u5E03";
|
|
1939
|
-
await this.save(root, job);
|
|
1940
|
-
}
|
|
2196
|
+
await this.recoverInterrupted(root, job);
|
|
1941
2197
|
});
|
|
1942
2198
|
}
|
|
1943
2199
|
scope.assertCurrent();
|
|
@@ -1994,7 +2250,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1994
2250
|
source_label: c.source?.path ? `\u6765\u81EA\u539F\u9879\u76EE ${c.source.path}` : void 0
|
|
1995
2251
|
};
|
|
1996
2252
|
});
|
|
1997
|
-
const artifactFiles = job.hashes && job.revision && /^[a-z0-9]+$/i.test(job.revision) ? Object.fromEntries(["app.tar", "skill.zip", "app-manifest.json", "summary.json"].filter((name2) => name2 in job.hashes || name2 === "summary.json").map((name2) => [name2, root ?
|
|
2253
|
+
const artifactFiles = job.hashes && job.revision && /^[a-z0-9]+$/i.test(job.revision) ? Object.fromEntries(["app.tar", "skill.zip", "app-manifest.json", "summary.json"].filter((name2) => name2 in job.hashes || name2 === "summary.json").map((name2) => [name2, root ? join3(root, job.revision, "bundle", name2) : join3(job.revision, "bundle", name2)])) : void 0;
|
|
1998
2254
|
return {
|
|
1999
2255
|
...rest,
|
|
2000
2256
|
model: job.modelSelection?.model ?? "",
|
|
@@ -2015,7 +2271,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2015
2271
|
proposal: proposal && {
|
|
2016
2272
|
summary: proposal.summary,
|
|
2017
2273
|
issues: proposal.issues ?? [],
|
|
2018
|
-
unresolved: proposal.unresolved ?? [],
|
|
2274
|
+
unresolved: [.../* @__PURE__ */ new Set([...proposal.unresolved ?? [], ...proposal.contract.unresolved ?? []])],
|
|
2019
2275
|
decisions: proposal.decisions ?? [],
|
|
2020
2276
|
changes: proposal.changes?.map((change) => ({
|
|
2021
2277
|
id: change.id,
|
|
@@ -2121,7 +2377,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2121
2377
|
if (previous && previous.url !== targetUrl) throw new Error("\u91CD\u65B0\u5BFC\u5165\u987B\u4FDD\u6301\u539F\u5E94\u7528\u5730\u5740");
|
|
2122
2378
|
scope.assertCurrent();
|
|
2123
2379
|
const job = {
|
|
2124
|
-
id:
|
|
2380
|
+
id: randomUUID4(),
|
|
2125
2381
|
name: targetName,
|
|
2126
2382
|
slug: input.slug,
|
|
2127
2383
|
url: targetUrl,
|
|
@@ -2131,12 +2387,12 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2131
2387
|
versionNote: defaultVersionNote,
|
|
2132
2388
|
modelSelection: input.modelSelection && typeof input.modelSelection.provider === "string" && typeof input.modelSelection.model === "string" ? { provider: input.modelSelection.provider, model: input.modelSelection.model, reasoningEffort: typeof input.modelSelection.reasoningEffort === "string" ? input.modelSelection.reasoningEffort : void 0 } : void 0,
|
|
2133
2389
|
feedbackHistory: previous?.feedbackHistory,
|
|
2134
|
-
conversation: previous?.conversation,
|
|
2390
|
+
conversation: previous?.conversation?.filter((message) => message.role === "user"),
|
|
2135
2391
|
session,
|
|
2136
2392
|
status: "importing",
|
|
2137
2393
|
events: ["\u6B63\u5728\u521B\u5EFA\u6E90\u7801\u9694\u79BB\u526F\u672C"]
|
|
2138
2394
|
};
|
|
2139
|
-
const root =
|
|
2395
|
+
const root = join3(scope.directory, job.id);
|
|
2140
2396
|
await this.exclusive(job.id, async () => {
|
|
2141
2397
|
await this.save(root, job);
|
|
2142
2398
|
try {
|
|
@@ -2145,8 +2401,8 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2145
2401
|
if (typeof input.zip !== "string" || input.zip.length > 9e7) throw new Error("ZIP \u4E0D\u80FD\u8D85\u8FC7 64 MiB");
|
|
2146
2402
|
const bytes = Buffer.from(input.zip, "base64");
|
|
2147
2403
|
if (bytes.length > 64 * 1024 * 1024) throw new Error("ZIP \u4E0D\u80FD\u8D85\u8FC7 64 MiB");
|
|
2148
|
-
source =
|
|
2149
|
-
await
|
|
2404
|
+
source = join3(root, "uploaded.zip");
|
|
2405
|
+
await writeFile3(source, bytes, { mode: 384 });
|
|
2150
2406
|
} else {
|
|
2151
2407
|
if (typeof input.source !== "string" || !isAbsolute(input.source)) throw new Error("\u8BF7\u9009\u62E9 ZIP \u6216\u586B\u5199\u672C\u673A\u6E90\u7801\u76EE\u5F55\u7684\u5B8C\u6574\u8DEF\u5F84");
|
|
2152
2408
|
source = input.source;
|
|
@@ -2162,6 +2418,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2162
2418
|
job.events.push("\u5DF2\u5BFC\u5165\u72EC\u7ACB\u526F\u672C\uFF0C\u539F\u9879\u76EE\u4FDD\u6301\u4E0D\u53D8");
|
|
2163
2419
|
} catch (error) {
|
|
2164
2420
|
job.status = "failed";
|
|
2421
|
+
job.failureStage = "import";
|
|
2165
2422
|
job.error = String(error);
|
|
2166
2423
|
}
|
|
2167
2424
|
await this.save(root, job);
|
|
@@ -2247,7 +2504,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2247
2504
|
if (!resume) {
|
|
2248
2505
|
job.analysisFailure = void 0;
|
|
2249
2506
|
if (!job.proposal) {
|
|
2250
|
-
await rm2(
|
|
2507
|
+
await rm2(join3(root, "draft_files.json"), { force: true }).catch(() => {
|
|
2251
2508
|
});
|
|
2252
2509
|
}
|
|
2253
2510
|
}
|
|
@@ -2281,12 +2538,14 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2281
2538
|
}
|
|
2282
2539
|
}
|
|
2283
2540
|
job.status = "analyzing";
|
|
2541
|
+
job.failureStage = void 0;
|
|
2284
2542
|
job.error = void 0;
|
|
2285
2543
|
job.checks = void 0;
|
|
2286
2544
|
job.events.push(
|
|
2287
2545
|
resume ? "\u{1F504} \u6B63\u5728\u7EE7\u7EED\u51C6\u5907\u5E94\u7528" : job.analysisMode === "repair" ? "\u{1F527} AI \u6B63\u5728\u8BFB\u53D6\u5931\u8D25\u5236\u54C1\u4E0E\u65E5\u5FD7\u8FDB\u884C\u4E13\u9879\u4FEE\u590D\u5206\u6790" : "\u{1F680} AI \u6B63\u5728\u5206\u6790\u6E90\u7801\uFF1B\u5C1A\u672A\u6267\u884C\u53D1\u5E03"
|
|
2288
2546
|
);
|
|
2289
2547
|
try {
|
|
2548
|
+
await rm2(join3(root, "failed_files_read.json"), { force: true });
|
|
2290
2549
|
await this.save(root, job);
|
|
2291
2550
|
} catch (error) {
|
|
2292
2551
|
this.analyses.delete(id);
|
|
@@ -2303,6 +2562,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2303
2562
|
} catch (error) {
|
|
2304
2563
|
const msg = controller.signal.aborted ? "\u7528\u6237\u53D6\u6D88\u5206\u6790" : error instanceof Error ? error.message : String(error);
|
|
2305
2564
|
job.status = controller.signal.aborted ? "cancelled" : "failed";
|
|
2565
|
+
if (!controller.signal.aborted) job.failureStage = "analysis";
|
|
2306
2566
|
job.error = msg;
|
|
2307
2567
|
if (!controller.signal.aborted && !job.analysisFailure) job.analysisFailure = msg;
|
|
2308
2568
|
}
|
|
@@ -2355,7 +2615,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2355
2615
|
const scope = this.scope(expected);
|
|
2356
2616
|
const { root, job } = await this.open(scope.directory, id);
|
|
2357
2617
|
if (!["ready", "building", "verifying", "awaiting_page_verification", "verified", "failed"].includes(job.status) || !job.revision || !/^[a-z0-9]+$/i.test(job.revision) || !["app.tar", "skill.zip", "app-manifest.json", "summary.json"].includes(filename)) throw new Error("\u5F53\u524D\u4EA4\u4ED8\u6587\u4EF6\u4E0D\u53EF\u7528");
|
|
2358
|
-
const path =
|
|
2618
|
+
const path = join3(root, job.revision, "bundle", filename);
|
|
2359
2619
|
const size = (await stat(path)).size;
|
|
2360
2620
|
if (size > 64 * 1024 * 1024) throw new Error("\u6587\u4EF6\u8D85\u8FC7\u63D2\u4EF6\u4E0B\u8F7D\u4E0A\u9650 64 MiB");
|
|
2361
2621
|
const bytes = await readFile2(path);
|
|
@@ -2363,26 +2623,26 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2363
2623
|
if (filename !== "summary.json" && hash(bytes) !== job.hashes?.[filename]) throw new Error("\u4EA4\u4ED8\u6587\u4EF6\u5DF2\u53D1\u751F\u53D8\u5316");
|
|
2364
2624
|
return { filename: `${job.slug}-${filename}`, base64: bytes.toString("base64") };
|
|
2365
2625
|
}
|
|
2366
|
-
async saveLocalArtifact(id, filename, expected, downloads =
|
|
2626
|
+
async saveLocalArtifact(id, filename, expected, downloads = join3(homedir(), "Downloads")) {
|
|
2367
2627
|
const scope = this.scope(expected);
|
|
2368
2628
|
const { root, job } = await this.open(scope.directory, id);
|
|
2369
2629
|
if (!["ready", "building", "verifying", "awaiting_page_verification", "verified", "failed"].includes(job.status) || !job.revision || !/^[a-z0-9]+$/i.test(job.revision) || !["app.tar", "skill.zip", "app-manifest.json", "summary.json"].includes(filename)) throw new Error("\u5F53\u524D\u4EA4\u4ED8\u6587\u4EF6\u4E0D\u53EF\u7528");
|
|
2370
|
-
const src =
|
|
2630
|
+
const src = join3(root, job.revision, "bundle", filename);
|
|
2371
2631
|
const bytes = await readFile2(src);
|
|
2372
2632
|
scope.assertCurrent();
|
|
2373
2633
|
if (filename !== "summary.json" && hash(bytes) !== job.hashes?.[filename]) throw new Error("\u4EA4\u4ED8\u6587\u4EF6\u5DF2\u53D1\u751F\u53D8\u5316");
|
|
2374
|
-
await
|
|
2634
|
+
await mkdir3(downloads, { recursive: true, mode: 448 });
|
|
2375
2635
|
const outName = `${job.slug}-${filename}`;
|
|
2376
|
-
const temp =
|
|
2377
|
-
await
|
|
2636
|
+
const temp = join3(downloads, `.opc-${randomUUID4()}.artifact`);
|
|
2637
|
+
await writeFile3(temp, bytes, { mode: 384 });
|
|
2378
2638
|
try {
|
|
2379
|
-
const preferred =
|
|
2639
|
+
const preferred = join3(downloads, outName);
|
|
2380
2640
|
let dest = preferred;
|
|
2381
2641
|
try {
|
|
2382
2642
|
await link(temp, dest);
|
|
2383
2643
|
} catch (error) {
|
|
2384
2644
|
if (error.code !== "EEXIST") throw error;
|
|
2385
|
-
dest =
|
|
2645
|
+
dest = join3(downloads, `${randomUUID4().slice(0, 8)}-${outName}`);
|
|
2386
2646
|
await link(temp, dest);
|
|
2387
2647
|
}
|
|
2388
2648
|
return { filename: outName, path: dest };
|
|
@@ -2395,7 +2655,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2395
2655
|
const scope = this.scope(expected);
|
|
2396
2656
|
const { root, job } = await this.open(scope.directory, id);
|
|
2397
2657
|
if (job.status !== "ready" || !job.skillMarkdown || !job.hashes?.["skill.zip"] || !job.revision) throw new Error("\u6280\u80FD\u5C1A\u672A\u751F\u6210");
|
|
2398
|
-
const bytes = await readFile2(
|
|
2658
|
+
const bytes = await readFile2(join3(root, job.revision, "bundle", "skill.zip"));
|
|
2399
2659
|
scope.assertCurrent();
|
|
2400
2660
|
const result = await worker({
|
|
2401
2661
|
action: "extract_skill_contract",
|
|
@@ -2419,19 +2679,24 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2419
2679
|
port: job.port,
|
|
2420
2680
|
revision: job.status === "ready" ? job.revision : void 0,
|
|
2421
2681
|
status: job.status,
|
|
2422
|
-
proposal: job.proposal
|
|
2682
|
+
proposal: this.public(job).proposal,
|
|
2683
|
+
revision_count: job.revisionCount ?? 1,
|
|
2684
|
+
feedback: job.feedbackHistory ?? ""
|
|
2423
2685
|
} }, scope.signal);
|
|
2424
2686
|
}
|
|
2425
2687
|
async submit(job, root, proposal, signal) {
|
|
2426
2688
|
if (proposal.contract?.slug !== job.slug || proposal.contract?.base_url !== job.url) throw new Error("\u5E94\u7528\u6807\u8BC6\u6216\u5730\u5740\u4E0E\u5BFC\u5165\u65F6\u4E0D\u4E00\u81F4");
|
|
2427
2689
|
if (job.status !== "analyzing") throw new Error("\u672C\u8F6E\u5DF2\u63D0\u4EA4\u65B9\u6848");
|
|
2428
|
-
if (!Array.isArray(proposal.unresolved)
|
|
2429
|
-
|
|
2690
|
+
if (!Array.isArray(proposal.unresolved) || proposal.contract.unresolved !== void 0 && !Array.isArray(proposal.contract.unresolved)) {
|
|
2691
|
+
throw new Error("unresolved \u5FC5\u987B\u4E3A\u6570\u7EC4");
|
|
2692
|
+
}
|
|
2693
|
+
const hasQuestions = Boolean(proposal.unresolved.length || proposal.contract.unresolved?.length);
|
|
2694
|
+
if (!hasQuestions && proposal.contract.runtime?.port !== (job.port ?? 8080)) throw new Error("\u6A21\u578B\u4E0D\u80FD\u9759\u9ED8\u6539\u53D8\u7528\u6237\u9009\u62E9\u7684\u5BB9\u5668\u7AEF\u53E3");
|
|
2430
2695
|
const validated = await worker({
|
|
2431
2696
|
action: "validate",
|
|
2432
2697
|
root,
|
|
2433
2698
|
proposal,
|
|
2434
|
-
allow_unresolved:
|
|
2699
|
+
allow_unresolved: hasQuestions,
|
|
2435
2700
|
repair: Boolean(job.failedRevision),
|
|
2436
2701
|
failed_revision: job.failedRevision ?? "",
|
|
2437
2702
|
failure_feedback: job.failureContext ?? "",
|
|
@@ -2450,7 +2715,9 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2450
2715
|
job.conversation = [...job.conversation ?? [], { role: "assistant", text: job.proposal.summary, revision: job.revisionCount ?? 1 }];
|
|
2451
2716
|
}
|
|
2452
2717
|
job.status = "review";
|
|
2453
|
-
job.
|
|
2718
|
+
job.analysisFailure = void 0;
|
|
2719
|
+
job.events.push(job.proposal.unresolved.length || job.proposal.contract.unresolved?.length ? "AI \u5206\u6790\u5B8C\u6210\uFF0C\u8BF7\u56DE\u7B54\u5F85\u786E\u8BA4\u4E8B\u9879" : "\u65B9\u6848\u6821\u9A8C\u901A\u8FC7\uFF0C\u8BF7\u6838\u5BF9\u6539\u9020\u5185\u5BB9\u5E76\u751F\u6210\u90E8\u7F72\u5305");
|
|
2720
|
+
await this.save(root, job);
|
|
2454
2721
|
}
|
|
2455
2722
|
async prepare(id, proposalHash, expected) {
|
|
2456
2723
|
const scope = this.scope(expected);
|
|
@@ -2458,10 +2725,11 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2458
2725
|
return this.exclusive(id, async () => {
|
|
2459
2726
|
if (job.status !== "review" || !job.proposal || fingerprint(job.proposal) !== proposalHash) throw new Error("\u65B9\u6848\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u6838\u5BF9");
|
|
2460
2727
|
job.status = "preparing";
|
|
2728
|
+
job.failureStage = void 0;
|
|
2461
2729
|
job.error = void 0;
|
|
2462
2730
|
await this.save(root, job);
|
|
2463
2731
|
try {
|
|
2464
|
-
const revision =
|
|
2732
|
+
const revision = randomUUID4().replaceAll("-", "");
|
|
2465
2733
|
const result = await worker({
|
|
2466
2734
|
action: "bundle",
|
|
2467
2735
|
root,
|
|
@@ -2491,11 +2759,13 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2491
2759
|
job.status = "ready";
|
|
2492
2760
|
job.version = void 0;
|
|
2493
2761
|
job.published = void 0;
|
|
2494
|
-
job.
|
|
2762
|
+
job.restoredVersion = void 0;
|
|
2763
|
+
job.requestId = randomUUID4().replaceAll("-", "");
|
|
2495
2764
|
job.confirmationToken = void 0;
|
|
2496
2765
|
job.events.push("\u90E8\u7F72\u5305\u5DF2\u751F\u6210\uFF0C\u670D\u52A1\u5668\u6784\u5EFA\u548C\u4E1A\u52A1\u9A8C\u8BC1\u5C1A\u672A\u6267\u884C");
|
|
2497
2766
|
} catch (error) {
|
|
2498
2767
|
job.status = "failed";
|
|
2768
|
+
job.failureStage = "preparation";
|
|
2499
2769
|
job.error = String(error);
|
|
2500
2770
|
}
|
|
2501
2771
|
await this.save(root, job);
|
|
@@ -2549,8 +2819,8 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2549
2819
|
const prior = await this.credentials.read(`confirm-${id}`);
|
|
2550
2820
|
scope.assertCurrent();
|
|
2551
2821
|
if (!job.confirmationToken || prior.digest !== digest) {
|
|
2552
|
-
job.confirmationToken =
|
|
2553
|
-
job.requestId =
|
|
2822
|
+
job.confirmationToken = randomUUID4();
|
|
2823
|
+
job.requestId = randomUUID4().replaceAll("-", "");
|
|
2554
2824
|
await this.credentials.write(`confirm-${id}`, { digest });
|
|
2555
2825
|
await this.save(root, job);
|
|
2556
2826
|
}
|
|
@@ -2569,21 +2839,21 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2569
2839
|
if (!job.confirmationToken || input.confirmationToken !== job.confirmationToken || (await this.credentials.read(`confirm-${id}`)).digest !== digest) {
|
|
2570
2840
|
throw new Error("\u4EA4\u4ED8\u5305\u3001\u914D\u7F6E\u6216\u8D44\u6E90\u4E0E\u6700\u7EC8\u786E\u8BA4\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u786E\u8BA4");
|
|
2571
2841
|
}
|
|
2572
|
-
const requestId = job.requestId ||
|
|
2842
|
+
const requestId = job.requestId || randomUUID4().replaceAll("-", "");
|
|
2573
2843
|
job.versionNote = versionNote;
|
|
2574
2844
|
job.requestId = requestId;
|
|
2575
2845
|
job.configKeys = bindings.map((c) => c.key);
|
|
2576
2846
|
job.resourceIds = ids;
|
|
2577
2847
|
const form = new FormData(), contract = job.proposal.contract;
|
|
2578
|
-
const folder =
|
|
2848
|
+
const folder = join3(root, job.revision, "bundle");
|
|
2579
2849
|
for (const name2 of ["app.tar", "skill.zip"]) {
|
|
2580
|
-
const bytes = await readFile2(
|
|
2850
|
+
const bytes = await readFile2(join3(folder, name2));
|
|
2581
2851
|
if (hash(bytes) !== job.hashes?.[name2]) throw new Error("\u5236\u54C1\u6458\u8981\u4E0D\u4E00\u81F4\uFF0C\u62D2\u7EDD\u53D1\u5E03");
|
|
2582
2852
|
form.append(name2 === "app.tar" ? "app_tar" : "skill_zip", new Blob([new Uint8Array(bytes)]), name2);
|
|
2583
2853
|
}
|
|
2584
2854
|
let dockerfileContent = job.dockerfileContent ?? "";
|
|
2585
2855
|
if (!dockerfileContent) {
|
|
2586
|
-
dockerfileContent = await readFile2(
|
|
2856
|
+
dockerfileContent = await readFile2(join3(root, job.revision, "approved/source/Dockerfile"), "utf8").catch(() => "");
|
|
2587
2857
|
}
|
|
2588
2858
|
for (const [key, value] of Object.entries({
|
|
2589
2859
|
slug: job.slug,
|
|
@@ -2604,6 +2874,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2604
2874
|
await this.credentials.write(`publish-config-${requestId}`, { rows: JSON.stringify(configs) });
|
|
2605
2875
|
scope.assertCurrent();
|
|
2606
2876
|
job.status = "publishing";
|
|
2877
|
+
job.failureStage = void 0;
|
|
2607
2878
|
job.error = void 0;
|
|
2608
2879
|
job.checks = void 0;
|
|
2609
2880
|
await this.save(root, job);
|
|
@@ -2656,8 +2927,17 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2656
2927
|
}
|
|
2657
2928
|
async verify(id, expected, options) {
|
|
2658
2929
|
const scope = this.scope(expected);
|
|
2659
|
-
|
|
2930
|
+
if (options?.automatic === true && this.busy.has(id)) {
|
|
2931
|
+
const { root, job } = await this.open(scope.directory, id);
|
|
2932
|
+
return this.public(job, root);
|
|
2933
|
+
}
|
|
2660
2934
|
return this.exclusive(id, async () => {
|
|
2935
|
+
const { root, job } = await this.open(scope.directory, id);
|
|
2936
|
+
if (options?.automatic === true && !["building", "unknown"].includes(job.status)) {
|
|
2937
|
+
const view2 = this.public(job, root);
|
|
2938
|
+
if (job.status === "verified") view2.userDisabled = await this.isSkillDisabled(scope.directory, job.slug);
|
|
2939
|
+
return view2;
|
|
2940
|
+
}
|
|
2661
2941
|
if (!["building", "unknown", "awaiting_page_verification", "verified", "failed", "publishing", "verifying"].includes(job.status) || !job.hashes || !job.proposal) throw new Error("\u5E94\u7528\u5C1A\u672A\u53D1\u5E03");
|
|
2662
2942
|
if (job.status === "unknown" || job.status === "publishing") {
|
|
2663
2943
|
if (!job.requestId) throw new Error("\u7F3A\u5C11\u4E0A\u6B21\u53D1\u5E03\u8BF7\u6C42\u53F7\uFF0C\u65E0\u6CD5\u6838\u5BF9\u7ED3\u679C");
|
|
@@ -2670,15 +2950,14 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2670
2950
|
await this.save(root, job);
|
|
2671
2951
|
return this.public(job, root);
|
|
2672
2952
|
}
|
|
2673
|
-
if (!["accepted", "building", "running"].includes(receipt.status))
|
|
2953
|
+
if (!["accepted", "building", "running"].includes(receipt.status)) return this.public(job, root);
|
|
2674
2954
|
job.published = true;
|
|
2675
2955
|
job.version = receipt.version;
|
|
2676
2956
|
job.status = "building";
|
|
2677
|
-
if (job.revision) await this.archivePublishedVersion(scope.directory, job,
|
|
2957
|
+
if (job.revision) await this.archivePublishedVersion(scope.directory, job, join3(root, job.revision, "bundle"));
|
|
2678
2958
|
await this.save(root, job);
|
|
2679
2959
|
}
|
|
2680
2960
|
const contract = job.proposal.contract;
|
|
2681
|
-
await worker({ action: "validate_verification_contract", root, contract }, scope.signal);
|
|
2682
2961
|
const supplied = {};
|
|
2683
2962
|
if (options?.credentials !== void 0) {
|
|
2684
2963
|
if (!options.credentials || typeof options.credentials !== "object" || Array.isArray(options.credentials)) {
|
|
@@ -2692,29 +2971,24 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2692
2971
|
supplied[key] = value;
|
|
2693
2972
|
}
|
|
2694
2973
|
}
|
|
2695
|
-
|
|
2696
|
-
try {
|
|
2697
|
-
remote = await this.platform("/" + job.slug, expected);
|
|
2698
|
-
} catch (error) {
|
|
2699
|
-
throw error;
|
|
2700
|
-
}
|
|
2974
|
+
const remote = await this.platform("/" + job.slug, expected);
|
|
2701
2975
|
if (remote.status === "running" && job.version && remote.current_version !== job.version) {
|
|
2702
2976
|
const history = await this.platform("/" + job.slug + "/versions", expected);
|
|
2703
2977
|
const attempted = history.versions?.find((version) => version.version === job.version);
|
|
2704
2978
|
if (attempted?.status === "failed" && attempted.app_tar_sha256 === job.hashes["app.tar"] && attempted.skill_zip_sha256 === job.hashes["skill.zip"]) {
|
|
2705
|
-
this.recordFailureState(job, attempted.error_message || "\u672C\u6B21\u53D1\u5E03\u5931\u8D25\uFF0C\u65E7\u7248\u672C\u4ECD\u5728\u8FD0\u884C",
|
|
2979
|
+
this.recordFailureState(job, attempted.error_message || "\u672C\u6B21\u53D1\u5E03\u5931\u8D25\uFF0C\u65E7\u7248\u672C\u4ECD\u5728\u8FD0\u884C", attempted.build_log?.slice(-8e3), job.version);
|
|
2706
2980
|
await this.save(root, job);
|
|
2707
2981
|
this.core.emit("skills-changed");
|
|
2708
2982
|
return this.public(job, root);
|
|
2709
2983
|
}
|
|
2984
|
+
if (attempted && ["accepted", "building"].includes(attempted.status) && attempted.app_tar_sha256 === job.hashes["app.tar"] && attempted.skill_zip_sha256 === job.hashes["skill.zip"]) {
|
|
2985
|
+
return this.public(job, root);
|
|
2986
|
+
}
|
|
2710
2987
|
}
|
|
2711
2988
|
if (remote.status !== "running") {
|
|
2712
|
-
if (remote.status
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
job.status = "building";
|
|
2716
|
-
job.error = remote.error_message;
|
|
2717
|
-
}
|
|
2989
|
+
if (!["failed", "unhealthy"].includes(remote.status)) return this.public(job, root);
|
|
2990
|
+
if (job.version && remote.current_version !== job.version) throw new Error("\u7EBF\u4E0A\u7248\u672C\u53D1\u751F\u53D8\u5316\uFF0C\u65E0\u6CD5\u9A8C\u8BC1\u6B64\u4EA4\u4ED8\u4EFB\u52A1");
|
|
2991
|
+
this.recordFailureState(job, remote.error_message || "\u6784\u5EFA\u6216\u5065\u5EB7\u68C0\u67E5\u672A\u901A\u8FC7", remote.build_log?.slice(-8e3), job.version);
|
|
2718
2992
|
await this.save(root, job);
|
|
2719
2993
|
this.core.emit("skills-changed");
|
|
2720
2994
|
return this.public(job, root);
|
|
@@ -2722,11 +2996,13 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2722
2996
|
if (remote.app_url !== job.url || job.version && remote.current_version !== job.version) throw new Error("\u7EBF\u4E0A\u7248\u672C\u6216\u5730\u5740\u4E0D\u4E00\u81F4\uFF0C\u62D2\u7EDD\u542F\u7528\u6280\u80FD");
|
|
2723
2997
|
if (!matchesReceipt(remote.build_log, job.hashes)) throw new Error("\u670D\u52A1\u5668\u5236\u54C1\u56DE\u6267\u4E0D\u4E00\u81F4");
|
|
2724
2998
|
job.status = "verifying";
|
|
2999
|
+
job.failureStage = void 0;
|
|
2725
3000
|
job.error = void 0;
|
|
2726
3001
|
job.checks = void 0;
|
|
2727
3002
|
job.pagesVerified = void 0;
|
|
2728
3003
|
await this.save(root, job);
|
|
2729
3004
|
try {
|
|
3005
|
+
await worker({ action: "validate_verification_contract", root, contract }, scope.signal);
|
|
2730
3006
|
const credentials = { ...await this.readVersionCredentials(job), ...supplied };
|
|
2731
3007
|
const healthPath = contract.health?.path ?? "/healthz";
|
|
2732
3008
|
const health = { base_url: job.url, apis: [{ id: "health", path: healthPath, method: "GET", effect: "read", parameters: [], auth: { type: "none" } }] };
|
|
@@ -2736,7 +3012,10 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2736
3012
|
for (const test of contract.verification?.cases ?? []) {
|
|
2737
3013
|
const api = contract.apis.find((a) => a.id === test.operation);
|
|
2738
3014
|
if (!api) throw new Error(`\u4E1A\u52A1\u9A8C\u8BC1\u63A5\u53E3\u4E0D\u5B58\u5728\uFF1A${test.operation}`);
|
|
2739
|
-
if (api.path === healthPath)
|
|
3015
|
+
if (api.path === healthPath) {
|
|
3016
|
+
if (job.restoredVersion) throw new Error("\u56DE\u6EDA\u540E\u5FC5\u987B\u4F7F\u7528\u6709\u6548\u7684\u53EA\u8BFB\u4E1A\u52A1\u63A5\u53E3\u9A8C\u8BC1");
|
|
3017
|
+
continue;
|
|
3018
|
+
}
|
|
2740
3019
|
if (api.effect !== "read") throw new Error("\u4E1A\u52A1\u9A8C\u8BC1\u53EA\u80FD\u4F7F\u7528\u53EA\u8BFB\u63A5\u53E3");
|
|
2741
3020
|
const result = await worker({ action: "probe", root, contract, operation: test.operation, params: test.params ?? {}, body: test.body, credentials }, scope.signal);
|
|
2742
3021
|
if (!probeMatches(result, test.status ?? 200, test.json_contains)) throw new Error(`\u4E1A\u52A1\u9A8C\u8BC1\u5931\u8D25\uFF1A${test.operation}`);
|
|
@@ -2783,7 +3062,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2783
3062
|
job.events.push("\u5065\u5EB7\u8EAB\u4EFD\u548C\u53EA\u8BFB\u4E1A\u52A1\u9A8C\u8BC1\u901A\u8FC7\uFF1B\u9875\u9762\u5C1A\u672A\u9A8C\u8BC1");
|
|
2784
3063
|
}
|
|
2785
3064
|
} catch (error) {
|
|
2786
|
-
this.recordFailureState(job, String(error), remote.build_log?.slice(-8e3), remote.current_version ?? job.version);
|
|
3065
|
+
this.recordFailureState(job, String(error), remote.build_log?.slice(-8e3), remote.current_version ?? job.version, "verification");
|
|
2787
3066
|
}
|
|
2788
3067
|
await this.save(root, job);
|
|
2789
3068
|
this.core.emit("skills-changed");
|
|
@@ -2829,11 +3108,11 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2829
3108
|
}
|
|
2830
3109
|
return { filename, base64: result.bytes.toString("base64") };
|
|
2831
3110
|
}
|
|
2832
|
-
async saveDownload(slug, selection, expected, downloads =
|
|
3111
|
+
async saveDownload(slug, selection, expected, downloads = join3(homedir(), "Downloads")) {
|
|
2833
3112
|
const scope = this.scope(expected);
|
|
2834
3113
|
const { filename, path, query } = this.downloadTarget(slug, selection);
|
|
2835
|
-
await
|
|
2836
|
-
const temp =
|
|
3114
|
+
await mkdir3(downloads, { recursive: true, mode: 448 });
|
|
3115
|
+
const temp = join3(downloads, `.opc-${randomUUID4()}.download`);
|
|
2837
3116
|
const response = await this.platform(path, expected, { query, stream: true });
|
|
2838
3117
|
if (!response.body) throw new Error("\u5E73\u53F0\u672A\u8FD4\u56DE\u6587\u4EF6\u5185\u5BB9");
|
|
2839
3118
|
try {
|
|
@@ -2848,13 +3127,13 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2848
3127
|
const expectedHash = response.headers.get("x-artifact-sha256");
|
|
2849
3128
|
if (!bytes || expectedHash && digest.digest("hex") !== expectedHash) throw new Error("\u5E73\u53F0\u8FD4\u56DE\u6587\u4EF6\u4E3A\u7A7A\u6216\u6458\u8981\u4E0D\u5339\u914D");
|
|
2850
3129
|
scope.assertCurrent();
|
|
2851
|
-
const preferred =
|
|
3130
|
+
const preferred = join3(downloads, filename);
|
|
2852
3131
|
let dest = preferred;
|
|
2853
3132
|
try {
|
|
2854
3133
|
await link(temp, dest);
|
|
2855
3134
|
} catch (error) {
|
|
2856
3135
|
if (error.code !== "EEXIST") throw error;
|
|
2857
|
-
dest =
|
|
3136
|
+
dest = join3(downloads, `${randomUUID4().slice(0, 8)}-${filename}`);
|
|
2858
3137
|
await link(temp, dest);
|
|
2859
3138
|
}
|
|
2860
3139
|
return { path: dest };
|
|
@@ -2899,6 +3178,22 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2899
3178
|
method: "POST",
|
|
2900
3179
|
body: { target_version: targetVersion, reason: reason || `\u56DE\u9000\u81F3\u7248\u672C v${targetVersion}` }
|
|
2901
3180
|
});
|
|
3181
|
+
try {
|
|
3182
|
+
return await this.syncRolledBackSkill(slug, targetVersion, expected, rbResult, scope);
|
|
3183
|
+
} catch (error) {
|
|
3184
|
+
scope.assertCurrent();
|
|
3185
|
+
return {
|
|
3186
|
+
...rbResult,
|
|
3187
|
+
active_version: targetVersion,
|
|
3188
|
+
local_skill_synced: false,
|
|
3189
|
+
local_skill_verified: false,
|
|
3190
|
+
skill_enabled: false,
|
|
3191
|
+
verification: { status: "probe-warning", detail: `\u5E94\u7528\u5DF2\u56DE\u9000\uFF0C\u6280\u80FD\u672A\u540C\u6B65\u6216\u672A\u9A8C\u8BC1\uFF1A${String(error)}` },
|
|
3192
|
+
rollback_notice: ROLLBACK_NOTICE
|
|
3193
|
+
};
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
async syncRolledBackSkill(slug, targetVersion, expected, rbResult, scope) {
|
|
2902
3197
|
const current = await this.platform(`/${slug}`, expected);
|
|
2903
3198
|
if (current.status !== "running" || current.current_version !== targetVersion) {
|
|
2904
3199
|
throw new Error("\u56DE\u6EDA\u540E\u7EBF\u4E0A\u7248\u672C\u72B6\u6001\u4E0D\u4E00\u81F4");
|
|
@@ -2909,7 +3204,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2909
3204
|
const verInfo = rbResult.version ?? {};
|
|
2910
3205
|
let expectedSkillSha = String(rbResult.skill_zip_sha256 || verInfo.skill_zip_sha256 || "").trim();
|
|
2911
3206
|
let expectedAppTarSha = String(verInfo.app_tar_sha256 || "").trim();
|
|
2912
|
-
const localMeta = await readFile2(
|
|
3207
|
+
const localMeta = await readFile2(join3(scope.directory, "versions", slug, `v${targetVersion}`, "summary.json"), "utf8").then((s) => JSON.parse(s)).catch(() => void 0);
|
|
2913
3208
|
let skillZipBytes;
|
|
2914
3209
|
try {
|
|
2915
3210
|
const dl = await this.platform(`/${slug}/versions/${targetVersion}/artifacts/skill.zip`, expected);
|
|
@@ -2920,9 +3215,9 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2920
3215
|
}
|
|
2921
3216
|
} catch (error) {
|
|
2922
3217
|
if (!(error instanceof AppRequestError) || error.status !== 404) throw error;
|
|
2923
|
-
const verDir =
|
|
2924
|
-
const localFallback =
|
|
2925
|
-
if (
|
|
3218
|
+
const verDir = join3(scope.directory, "versions", slug, `v${targetVersion}`);
|
|
3219
|
+
const localFallback = join3(verDir, "skill.zip");
|
|
3220
|
+
if (existsSync2(localFallback)) {
|
|
2926
3221
|
skillZipBytes = await readFile2(localFallback).catch(() => void 0);
|
|
2927
3222
|
}
|
|
2928
3223
|
if (localMeta) {
|
|
@@ -2934,9 +3229,9 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2934
3229
|
if (!expectedSkillSha || hash(skillZipBytes) !== expectedSkillSha) {
|
|
2935
3230
|
throw new Error("\u56DE\u6EDA\u6280\u80FD\u5305\u6458\u8981\u4E0D\u4E00\u81F4\uFF0C\u62D2\u7EDD\u542F\u7528");
|
|
2936
3231
|
}
|
|
2937
|
-
const verDir =
|
|
2938
|
-
await
|
|
2939
|
-
await
|
|
3232
|
+
const verDir = join3(scope.directory, "versions", slug, `v${targetVersion}`);
|
|
3233
|
+
await mkdir3(verDir, { recursive: true, mode: 448 });
|
|
3234
|
+
await writeFile3(join3(verDir, "skill.zip"), skillZipBytes, { mode: 384 }).catch(() => {
|
|
2940
3235
|
});
|
|
2941
3236
|
}
|
|
2942
3237
|
const matchingJobs = [];
|
|
@@ -2951,8 +3246,8 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2951
3246
|
}
|
|
2952
3247
|
let primary = matchingJobs.find(({ job }) => job.published && job.version === targetVersion && job.hashes?.["app.tar"] === expectedAppTarSha && job.hashes?.["skill.zip"] === expectedSkillSha);
|
|
2953
3248
|
if (!primary && skillZipBytes) {
|
|
2954
|
-
const newId =
|
|
2955
|
-
const newRoot =
|
|
3249
|
+
const newId = randomUUID4();
|
|
3250
|
+
const newRoot = join3(scope.directory, newId);
|
|
2956
3251
|
const newJob = {
|
|
2957
3252
|
id: newId,
|
|
2958
3253
|
name: current.name || slug,
|
|
@@ -2985,7 +3280,9 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2985
3280
|
}
|
|
2986
3281
|
opened.job.version = targetVersion;
|
|
2987
3282
|
opened.job.published = true;
|
|
3283
|
+
opened.job.restoredVersion = true;
|
|
2988
3284
|
opened.job.pagesVerified = void 0;
|
|
3285
|
+
opened.job.checks = void 0;
|
|
2989
3286
|
opened.job.configFingerprint = current.config_fingerprint ?? rbResult.config_fingerprint;
|
|
2990
3287
|
if (expectedAppTarSha && expectedSkillSha) {
|
|
2991
3288
|
opened.job.hashes = {
|
|
@@ -3017,6 +3314,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
3017
3314
|
if (localSkillSynced && opened.job.proposal?.contract && matchesReceipt(current.build_log, opened.job.hashes)) {
|
|
3018
3315
|
try {
|
|
3019
3316
|
const contract = opened.job.proposal.contract;
|
|
3317
|
+
await worker({ action: "validate_verification_contract", root: opened.root, contract }, scope.signal);
|
|
3020
3318
|
const archivedJobId = localMeta?.hashes?.["skill.zip"] === expectedSkillSha && localMeta?.hashes?.["app.tar"] === expectedAppTarSha && typeof localMeta.jobId === "string" && /^[a-f0-9-]{36}$/.test(localMeta.jobId) ? localMeta.jobId : void 0;
|
|
3021
3319
|
if (archivedJobId && archivedJobId !== opened.job.id) {
|
|
3022
3320
|
const saved = await this.credentials.read(`version-${archivedJobId}-${targetVersion}`);
|
|
@@ -3031,8 +3329,9 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
3031
3329
|
const checks = [];
|
|
3032
3330
|
for (const test of contract.verification?.cases ?? []) {
|
|
3033
3331
|
const api = (contract.apis ?? []).find((a) => a.id === test.operation);
|
|
3034
|
-
if (!api || api.path === "/healthz")
|
|
3035
|
-
|
|
3332
|
+
if (!api || api.path === (contract.health?.path ?? "/healthz") || api.effect !== "read") {
|
|
3333
|
+
throw new Error("\u56DE\u6EDA\u540E\u5FC5\u987B\u4F7F\u7528\u6709\u6548\u7684\u53EA\u8BFB\u4E1A\u52A1\u63A5\u53E3\u9A8C\u8BC1");
|
|
3334
|
+
}
|
|
3036
3335
|
const res = await worker({ action: "probe", root: opened.root, contract, operation: test.operation, params: test.params ?? {}, body: test.body, credentials }, scope.signal);
|
|
3037
3336
|
if (!probeMatches(res, test.status ?? 200, test.json_contains)) {
|
|
3038
3337
|
throw new Error(`\u56DE\u6EDA\u540E\u4E1A\u52A1\u9A8C\u8BC1\u5931\u8D25\uFF1A${test.operation}`);
|
|
@@ -3040,40 +3339,45 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
3040
3339
|
checks.push({ operation: test.operation, status: res.status });
|
|
3041
3340
|
}
|
|
3042
3341
|
const latest = await this.platform(`/${slug}`, expected);
|
|
3043
|
-
if (latest.status !== "running" || latest.current_version !== targetVersion || latest.config_fingerprint !== current.config_fingerprint || !matchesReceipt(latest.build_log, opened.job.hashes)) {
|
|
3342
|
+
if (latest.status !== "running" || latest.current_version !== targetVersion || latest.app_url !== opened.job.url || latest.config_fingerprint !== current.config_fingerprint || !matchesReceipt(latest.build_log, opened.job.hashes)) {
|
|
3044
3343
|
throw new Error("\u56DE\u6EDA\u9A8C\u8BC1\u671F\u95F4\u7EBF\u4E0A\u7248\u672C\u6216\u914D\u7F6E\u53D1\u751F\u53D8\u5316");
|
|
3045
3344
|
}
|
|
3046
3345
|
if (checks.length > 0) {
|
|
3047
3346
|
opened.job.checks = checks;
|
|
3347
|
+
opened.job.failureStage = void 0;
|
|
3348
|
+
opened.job.error = void 0;
|
|
3048
3349
|
opened.job.status = "verified";
|
|
3049
3350
|
opened.job.events.push(`\u5DF2\u56DE\u9000\u81F3 v${targetVersion}\uFF0C\u5386\u53F2\u6280\u80FD\u4E0E\u4E1A\u52A1\u63A2\u9488\u9A8C\u8BC1\u901A\u8FC7`);
|
|
3050
3351
|
localSkillVerified = true;
|
|
3051
3352
|
verification = { status: "verified-rolled-back" };
|
|
3052
|
-
} else if (Array.isArray(contract.pages) && contract.pages.length > 0 && !(contract.apis ?? []).some((a) => a.path !== "/healthz")) {
|
|
3353
|
+
} else if (Array.isArray(contract.pages) && contract.pages.length > 0 && !(contract.apis ?? []).some((a) => a.path !== (contract.health?.path ?? "/healthz"))) {
|
|
3053
3354
|
opened.job.status = "awaiting_page_verification";
|
|
3355
|
+
opened.job.failureStage = void 0;
|
|
3356
|
+
opened.job.error = void 0;
|
|
3054
3357
|
verification = { status: "awaiting_page_verification", detail: "\u8BF7\u6253\u5F00\u9875\u9762\u5B8C\u6210\u4EBA\u5DE5\u9A8C\u6536" };
|
|
3055
3358
|
opened.job.events.push(`\u5DF2\u56DE\u9000\u81F3 v${targetVersion}\uFF0C\u8BF7\u6253\u5F00\u9875\u9762\u5B8C\u6210\u4EBA\u5DE5\u9A8C\u6536\u540E\u542F\u7528\u6280\u80FD`);
|
|
3056
3359
|
} else {
|
|
3057
|
-
|
|
3058
|
-
opened.job.events.push(`\u5DF2\u56DE\u9000\u81F3 v${targetVersion}\uFF0C\u8BF7\u91CD\u65B0\u9A8C\u8BC1\u4E1A\u52A1\u540E\u542F\u7528\u6280\u80FD`);
|
|
3360
|
+
throw new Error("\u7F3A\u5C11\u53EA\u8BFB\u4E1A\u52A1\u9A8C\u8BC1\uFF0C\u5E94\u7528\u6280\u80FD\u5C1A\u672A\u542F\u7528");
|
|
3059
3361
|
}
|
|
3060
3362
|
} catch (error) {
|
|
3061
|
-
opened.job
|
|
3062
|
-
opened.job.error = String(error);
|
|
3363
|
+
this.recordFailureState(opened.job, String(error), void 0, targetVersion, "verification");
|
|
3063
3364
|
verification = { status: "probe-warning", detail: opened.job.error };
|
|
3064
3365
|
opened.job.events.push(`\u5DF2\u56DE\u9000\u81F3 v${targetVersion}\uFF0C\u8BF7\u91CD\u65B0\u9A8C\u8BC1\u4E1A\u52A1\u540E\u542F\u7528\u6280\u80FD`);
|
|
3065
3366
|
}
|
|
3066
|
-
} else
|
|
3067
|
-
opened.job
|
|
3068
|
-
opened.job.
|
|
3367
|
+
} else {
|
|
3368
|
+
this.recordFailureState(opened.job, "\u56DE\u6EDA\u5B8C\u6210\uFF0C\u6280\u80FD\u5305\u6216\u7EBF\u4E0A\u5236\u54C1\u56DE\u6267\u5C1A\u672A\u6838\u5B9E", void 0, targetVersion, "verification");
|
|
3369
|
+
verification = { status: "probe-warning", detail: opened.job.error };
|
|
3069
3370
|
}
|
|
3371
|
+
scope.assertCurrent();
|
|
3070
3372
|
await this.save(opened.root, opened.job);
|
|
3071
3373
|
}
|
|
3072
3374
|
this.core.emit("skills-changed");
|
|
3073
3375
|
return {
|
|
3074
3376
|
...rbResult,
|
|
3377
|
+
active_version: targetVersion,
|
|
3075
3378
|
local_skill_synced: localSkillSynced,
|
|
3076
3379
|
local_skill_verified: localSkillVerified,
|
|
3380
|
+
skill_enabled: localSkillVerified && !await this.isSkillDisabled(scope.directory, slug),
|
|
3077
3381
|
verification,
|
|
3078
3382
|
job_id: primary?.job.id,
|
|
3079
3383
|
rollback_notice: ROLLBACK_NOTICE
|
|
@@ -3086,12 +3390,12 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
3086
3390
|
if (job.status !== "verified") throw new Error("\u5E94\u7528\u5C1A\u672A\u901A\u8FC7\u4E1A\u52A1\u9A8C\u8BC1");
|
|
3087
3391
|
if (enabled) await this.verifiedJob(id, expected, true);
|
|
3088
3392
|
const path = this.skillPreferencePath(scope.directory, job.slug);
|
|
3089
|
-
await
|
|
3090
|
-
const temp =
|
|
3393
|
+
await mkdir3(dirname3(path), { recursive: true, mode: 448 });
|
|
3394
|
+
const temp = join3(dirname3(path), randomUUID4());
|
|
3091
3395
|
try {
|
|
3092
|
-
await
|
|
3396
|
+
await writeFile3(temp, enabled ? "enabled" : "disabled", { mode: 384 });
|
|
3093
3397
|
scope.assertCurrent();
|
|
3094
|
-
await
|
|
3398
|
+
await rename3(temp, path);
|
|
3095
3399
|
} finally {
|
|
3096
3400
|
await rm2(temp, { force: true });
|
|
3097
3401
|
}
|
|
@@ -3154,9 +3458,9 @@ ${JSON.stringify({ params, body })}`);
|
|
|
3154
3458
|
};
|
|
3155
3459
|
|
|
3156
3460
|
// src/host/app-agent.ts
|
|
3157
|
-
import { randomUUID as
|
|
3158
|
-
import { readFileSync } from "node:fs";
|
|
3159
|
-
import { join as
|
|
3461
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
3462
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
3463
|
+
import { join as join4 } from "node:path";
|
|
3160
3464
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3161
3465
|
import { defineTool as defineTool2 } from "@deepseek-ai/dsh-tools";
|
|
3162
3466
|
import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
@@ -3165,9 +3469,9 @@ function loadBundledSkillText(relativePath) {
|
|
|
3165
3469
|
const fromLib = fileURLToPath2(new URL(`../runtime/app_delivery/${relativePath}`, import.meta.url));
|
|
3166
3470
|
const target = import.meta.url.endsWith("/lib/index.js") ? fromLib : fromSrc;
|
|
3167
3471
|
try {
|
|
3168
|
-
return
|
|
3472
|
+
return readFileSync2(target, "utf8");
|
|
3169
3473
|
} catch {
|
|
3170
|
-
return
|
|
3474
|
+
return readFileSync2(fromSrc, "utf8");
|
|
3171
3475
|
}
|
|
3172
3476
|
}
|
|
3173
3477
|
function normalizeDisplayPath(raw) {
|
|
@@ -3247,7 +3551,7 @@ ${contractDoc}
|
|
|
3247
3551
|
4. \u63D0\u4F9B\u5B8C\u6574 Dockerfile\u30010.0.0.0 \u76D1\u542C\u548C\u540C\u4E00\u670D\u52A1\u7684 /healthz \u8FD4\u56DE {service:slug}\uFF0C\u5E76\u786E\u8BA4\u62DF\u63D0\u4EA4\u7684\u8FD0\u884C\u6E90\u7801\u91CC\u786E\u5B9E\u5305\u542B /healthz \u8DEF\u7531\u5904\u7406\uFF08\u5373\u4F7F\u539F\u5E94\u7528\u5DF2\u6709\u5176\u4ED6\u5065\u5EB7\u7AEF\u70B9\uFF1B\u4EC5\u4FEE\u6539 contract.health \u4E0D\u4F1A\u751F\u6210\u8DEF\u7531\uFF09\u3002\u6CBF\u7528\u5DF2\u786E\u8BA4\u7684 container_port\uFF0C\u4FDD\u7559\u539F\u542F\u52A8\u811A\u672C\u7684\u6267\u884C\u6743\u9650\u3002build_context \u5305\u542B\u5FC5\u8981\u6E90\u7801\uFF0C\u6392\u9664\u6784\u5EFA\u7F13\u5B58\u3002
|
|
3248
3552
|
5. \u6240\u6709\u5DF2\u6620\u5C04\u4E3A\u8FD0\u884C\u65F6\u73AF\u5883\u53D8\u91CF\u7684\u539F\u914D\u7F6E\u9879\uFF0C\u8BF7\u5C06 configs[].source \u8BBE\u4E3A read \u8FD4\u56DE\u7684 Original configuration references \u5143\u6570\u636E\u4E2D\u7684\u7CBE\u786E {"path":..., "keys":[...]} \u5F15\u7528\uFF08\u7CFB\u7EDF\u4F1A\u5728\u672C\u5730\u5B89\u5168\u4FDD\u7559\u539F\u503C\u5E76\u5728\u90E8\u7F72\u65F6\u6CE8\u5165\uFF0C\u4FEE\u6539\u914D\u7F6E\u6587\u4EF6\u65F6\u4E25\u7981\u4E22\u5931\u539F\u6709\u654F\u611F\u5B57\u6BB5\uFF09\u3002
|
|
3249
3553
|
6. \u8BA4\u8BC1\u53EA\u4F7F\u7528\u8FD0\u884C\u914D\u7F6E\u7684\u73AF\u5883\u53D8\u91CF\u5F15\u7528\uFF08auth_profile / auth_profiles \u7684 username_env/password_env/token_env\uFF0C\u4EE5\u53CA auth_rules \u6709\u8BC1\u636E\u7684\u7EE7\u627F\u89C4\u5219\uFF09\uFF0C\u7EDD\u4E0D\u628A\u660E\u6587\u5BC6\u7801\u3001\u4EE4\u724C\u653E\u8FDB\u62A5\u544A\u3001\u5951\u7EA6\u6216\u6280\u80FD\u3002scanner \u7684 auth=unknown \u4EE3\u8868\u5C1A\u672A\u5206\u6790\uFF0C\u7EDD\u4E0D\u80FD\u5F53\u6210\u516C\u5F00\u63A5\u53E3\uFF1B\u8BFB\u53D6\u5B9E\u9645\u767B\u5F55\u3001\u4F1A\u8BDD\u4E0E\u89D2\u8272\u4EE3\u7801\uFF0C\u5F15\u7528 read \u8FD4\u56DE\u7684\u771F\u5B9E\u884C\u53F7\u3002\u5982\u679C\u67D0\u6587\u4EF6\u5DF2\u901A\u8FC7 opc_delivery_propose_file \u6682\u5B58\u4FEE\u6539\uFF0C\u8BF7\u7528 action=read \u4E14 proposed=true \u8BFB\u53D6\u62DF\u4EA4\u4ED8\u7248\u672C\u5E76\u5F15\u7528\u5176\u4E2D\u7684\u771F\u5B9E\u884C\u53F7\uFF1B\u82E5\u62DF\u4EA4\u4ED8\u6587\u4EF6\u9057\u6F0F\u4E86\u539F\u8BA4\u8BC1\u6216\u4E1A\u52A1\u5904\u7406\u51FD\u6570\uFF0C\u5148\u8865\u5168\u518D\u4FEE\u6B63\u5F15\u7528\u3002\u82E5\u8BC1\u636E\u65E0\u6548\uFF0C\u9488\u5BF9\u76F8\u5173\u6587\u4EF6\u91CD\u65B0\u8BFB\u53D6\u5E76\u4FEE\u6B63\u3002\u5E38\u89C4\u4E1A\u52A1\u9A8C\u8BC1\u6240\u9700\u8D26\u53F7\u3001\u5BC6\u7801\u6216\u4F1A\u8BDD\u5728\u90E8\u7F72\u540E\u586B\u5199\uFF0C\u53EA\u6709\u771F\u5B9E\u963B\u585E\u6539\u9020\u7684\u5916\u90E8\u6388\u6743\u6216\u89D2\u8272\u51B3\u5B9A\u624D\u5E26 auth_blockers \u63D0\u95EE\u3002
|
|
3250
|
-
7. \u5BF9\u4E8E\u8981\u65B0\u589E\u6216\u4FEE\u6539\u7684\u6587\u4EF6\uFF0C\u4F18\u5148\u4F7F\u7528 opc_delivery_propose_file \u9010\u4E2A\
|
|
3554
|
+
7. \u5BF9\u4E8E\u8981\u65B0\u589E\u6216\u4FEE\u6539\u7684\u6587\u4EF6\uFF0C\u4F18\u5148\u4F7F\u7528 opc_delivery_propose_file \u9010\u4E2A\u6682\u5B58\u5B8C\u6574\u6587\u4EF6\u5185\u5BB9\uFF0C\u7136\u540E\u5728 opc_delivery_submit \u7684\u7ED3\u6784\u5316 changes \u4E2D\u6309 {id, path, reason, group} \u5F15\u7528\u3002\u5C0F\u6539\u52A8\u53EF\u76F4\u63A5\u5728 changes \u4E2D\u63D0\u4F9B\u5B8C\u6574 content\u3002
|
|
3251
3555
|
8. scan_routes_and_pages \u5DF2\u5728\u540E\u7AEF\u81EA\u52A8\u7F13\u5B58\u5168\u90E8\u626B\u63CF\u5230\u7684 API \u4E0E\u9875\u9762\uFF0C\u5E76\u5728 opc_delivery_submit \u65F6\u81EA\u52A8\u5408\u5E76\u8FDB contract.apis \u4E0E contract.pages\uFF1B\u4E25\u7981\u628A\u201C\u63A5\u53E3\u6570\u91CF\u591A/\u626B\u63CF\u622A\u65AD/\u6DFB\u52A0 healthz/\u521B\u5EFA Dockerfile\u201D\u7B49\u5185\u90E8\u6280\u672F\u52A8\u4F5C\u653E\u8FDB unresolved\u3002
|
|
3252
3556
|
9. verification.cases \u4E3A\u771F\u5B9E\u53EA\u8BFB\u4E1A\u52A1\u63A2\u9488\uFF08\u6BCF\u79CD\u53D7\u4FDD\u62A4\u8BA4\u8BC1\u8EAB\u4EFD\u5747\u9700\u8986\u76D6\uFF09\uFF0C\u4E0D\u80FD\u7F16\u9020\u4E1A\u52A1\u8BB0\u5F55\u6216\u4EE5\u5065\u5EB7\u63A2\u9488\u4EE3\u66FF\u3002
|
|
3253
3557
|
10. \u6709\u9700\u8981\u7528\u6237\u51B3\u5B9A\u7684\u771F\u5B9E\u963B\u585E\uFF08\u5982\u5916\u90E8\u8FDE\u63A5\u66FF\u6362\u3001\u7F3A\u5931\u5916\u90E8\u6388\u6743\uFF09\u65F6\u63D0\u4EA4 unresolved\uFF0C\u5E76\u53EF\u5728 decisions \u4E2D\u63D0\u4F9B [{id, question, impact, options}]\uFF08\u6700\u591A 4 \u4E2A\u7B80\u77ED\u9009\u9879\uFF09\uFF1B\u6CA1\u6709\u963B\u585E\u65F6 unresolved \u8BBE\u4E3A\u7A7A\u6570\u7EC4 [] \u5E76\u63D0\u4EA4\u5B8C\u6574\u53EF\u6821\u9A8C\u63D0\u6848\u3002summary \u8BF7\u6309\u591A\u6BB5\u3010\u5E94\u7528\u5B9A\u4F4D\u3011\u3001\u3010\u8FD0\u884C\u73AF\u5883\u3011\u3001\u3010\u63A5\u53E3\u4E0E\u9875\u9762\u3011\u3001\u3010\u767B\u5F55\u4E0E\u9274\u6743\u3011\u3001\u3010\u6570\u636E\u4E0E\u5B58\u50A8\u3011\u3001\u3010\u6539\u9020\u4E0E\u6280\u80FD\u3011\u6E05\u6670\u6362\u884C\u6392\u7248\u3002\u5DE5\u5177\u6821\u9A8C\u5931\u8D25\u5E94\u4FEE\u6B63\u540E\u91CD\u63D0\uFF0C\u63D0\u4EA4\u6210\u529F\u540E\u7ED3\u675F\u672C\u8F6E\u3002`;
|
|
@@ -3299,14 +3603,14 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3299
3603
|
let repeatedProposal = false;
|
|
3300
3604
|
let draftFileChanges = [];
|
|
3301
3605
|
try {
|
|
3302
|
-
const draftsRaw = JSON.parse(
|
|
3606
|
+
const draftsRaw = JSON.parse(readFileSync2(join4(root, "draft_files.json"), "utf8"));
|
|
3303
3607
|
if (draftsRaw && typeof draftsRaw === "object") {
|
|
3304
3608
|
draftFileChanges = Object.values(draftsRaw).map((c) => ({ id: c?.id, path: c?.path, reason: c?.reason }));
|
|
3305
3609
|
}
|
|
3306
3610
|
} catch {
|
|
3307
3611
|
}
|
|
3308
3612
|
const handle = await ctx.agents.create({
|
|
3309
|
-
sessionId:
|
|
3613
|
+
sessionId: randomUUID5(),
|
|
3310
3614
|
meta: { cwd: root },
|
|
3311
3615
|
agentOptions: selection ? { provider: selection.provider, model: selection.model, reasoningEffort: selection.reasoningEffort } : { ...parent.options },
|
|
3312
3616
|
signal: abort,
|
|
@@ -3373,8 +3677,17 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3373
3677
|
}));
|
|
3374
3678
|
child.tools.register(defineTool2({
|
|
3375
3679
|
name: "opc_delivery_submit",
|
|
3376
|
-
description: "\u63D0\u4EA4\u5B8C\u6574\u6539\u9020\u63D0\u6848
|
|
3377
|
-
parameters: {
|
|
3680
|
+
description: "\u4EE5\u7ED3\u6784\u5316\u5B57\u6BB5\u63D0\u4EA4\u5B8C\u6574\u6539\u9020\u63D0\u6848\u3002\u82E5\u5DF2\u6682\u5B58\u6587\u4EF6\uFF0Cchanges \u53EF\u4EC5\u4F20 {id, path, reason, group}\u3002\u65E7\u7248\u53EF\u7528 proposal JSON \u5B57\u7B26\u4E32\u3002",
|
|
3681
|
+
parameters: {
|
|
3682
|
+
summary: { type: "string" },
|
|
3683
|
+
issues: { type: "array", items: { type: "object", additionalProperties: true } },
|
|
3684
|
+
unresolved: { type: "array", items: { type: "string" } },
|
|
3685
|
+
changes: { type: "array", items: { type: "object", additionalProperties: true } },
|
|
3686
|
+
contract: { type: "object", additionalProperties: true },
|
|
3687
|
+
decisions: { type: "array", items: { type: "object", additionalProperties: true } },
|
|
3688
|
+
four_step_report: { type: "object", additionalProperties: true },
|
|
3689
|
+
proposal: { type: "string" }
|
|
3690
|
+
},
|
|
3378
3691
|
output,
|
|
3379
3692
|
async execute(args) {
|
|
3380
3693
|
if (job.status !== "analyzing") throw new Error("\u672C\u8F6E\u5DF2\u63D0\u4EA4\u65B9\u6848");
|
|
@@ -3383,10 +3696,10 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3383
3696
|
delivery.core.emit("change");
|
|
3384
3697
|
let candidate;
|
|
3385
3698
|
try {
|
|
3386
|
-
|
|
3699
|
+
const { proposal, ...fields } = args;
|
|
3700
|
+
candidate = proposal ? JSON.parse(proposal) : { issues: [], unresolved: [], changes: [], decisions: [], ...fields };
|
|
3387
3701
|
if (candidate && typeof candidate.contract === "object" && candidate.contract !== null) {
|
|
3388
|
-
candidate.contract.slug
|
|
3389
|
-
candidate.contract.base_url = job.url;
|
|
3702
|
+
candidate.contract = { ...candidate.contract, slug: job.slug, base_url: job.url };
|
|
3390
3703
|
}
|
|
3391
3704
|
await delivery.submit(job, root, candidate, abort);
|
|
3392
3705
|
} catch (error) {
|
|
@@ -3423,7 +3736,7 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3423
3736
|
abort.addEventListener("abort", cancel, { once: true });
|
|
3424
3737
|
const send = (text2) => {
|
|
3425
3738
|
handle.agent.followup({
|
|
3426
|
-
id:
|
|
3739
|
+
id: randomUUID5(),
|
|
3427
3740
|
role: "user",
|
|
3428
3741
|
source: { kind: "user" },
|
|
3429
3742
|
content: [{
|
|
@@ -3618,6 +3931,10 @@ var contribution = { package: "dsh-plugin-opc", descriptors: [
|
|
|
3618
3931
|
{ id: "dsh-plugin-opc#opc/appUpdateConfig", service: "opc", namespace: "opc", method: "appUpdateConfig", invocation: { kind: "direct" }, parameters: [{ name: "slug", wire: "slug", source: "json", codec: { mode: "strict", typeSymbol: "opc/appUpdateConfig:slug", create: () => z.string() } }, { name: "bodyJson", wire: "bodyJson", source: "json", codec: { mode: "strict", typeSymbol: "opc/appUpdateConfig:bodyJson", create: () => z.string() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appUpdateConfig:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appUpdateConfig:result", create: () => z.string() } },
|
|
3619
3932
|
{ id: "dsh-plugin-opc#opc/appDelete", service: "opc", namespace: "opc", method: "appDelete", invocation: { kind: "direct" }, parameters: [{ name: "slug", wire: "slug", source: "json", codec: { mode: "strict", typeSymbol: "opc/appDelete:slug", create: () => z.string() } }, { name: "purgeVolumes", wire: "purgeVolumes", source: "json", codec: { mode: "strict", typeSymbol: "opc/appDelete:purgeVolumes", create: () => z.boolean() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appDelete:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appDelete:result", create: () => z.string() } },
|
|
3620
3933
|
{ id: "dsh-plugin-opc#opc/appRollback", service: "opc", namespace: "opc", method: "appRollback", invocation: { kind: "direct" }, parameters: [{ name: "slug", wire: "slug", source: "json", codec: { mode: "strict", typeSymbol: "opc/appRollback:slug", create: () => z.string() } }, { name: "payloadJson", wire: "payloadJson", source: "json", codec: { mode: "strict", typeSymbol: "opc/appRollback:payloadJson", create: () => z.string() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appRollback:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appRollback:result", create: () => z.string() } },
|
|
3934
|
+
{ id: "dsh-plugin-opc#opc/opcConfigGet", service: "opc", namespace: "opc", method: "opcConfigGet", invocation: { kind: "direct" }, parameters: [], result: { mode: "strict", typeSymbol: "opc/opcConfigGet:result", create: () => z.string() } },
|
|
3935
|
+
{ id: "dsh-plugin-opc#opc/opcConfigUpdate", service: "opc", namespace: "opc", method: "opcConfigUpdate", invocation: { kind: "direct" }, parameters: [{ name: "payloadJson", wire: "payloadJson", source: "json", codec: { mode: "strict", typeSymbol: "opc/opcConfigUpdate:payloadJson", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/opcConfigUpdate:result", create: () => z.string() } },
|
|
3936
|
+
{ id: "dsh-plugin-opc#opc/opcConfigReset", service: "opc", namespace: "opc", method: "opcConfigReset", invocation: { kind: "direct" }, parameters: [], result: { mode: "strict", typeSymbol: "opc/opcConfigReset:result", create: () => z.string() } },
|
|
3937
|
+
{ id: "dsh-plugin-opc#opc/opcConfigTest", service: "opc", namespace: "opc", method: "opcConfigTest", invocation: { kind: "direct" }, parameters: [{ name: "url", wire: "url", source: "json", codec: { mode: "strict", typeSymbol: "opc/opcConfigTest:url", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/opcConfigTest:result", create: () => z.string() } },
|
|
3621
3938
|
{ id: "dsh-plugin-opc#opc/state", service: "opc", namespace: "opc", method: "state", invocation: { kind: "direct" }, parameters: [], result: { mode: "strict", typeSymbol: "opc/state:result", create: () => z.string() } },
|
|
3622
3939
|
{ id: "dsh-plugin-opc#opc/watchState", service: "opc", namespace: "opc", method: "watchState", invocation: { kind: "direct" }, mode: "stream", cancellation: { parameter: "signal" }, parameters: [], result: { mode: "strict", typeSymbol: "opc/watchState:result", create: () => z.string() } },
|
|
3623
3940
|
{ id: "dsh-plugin-opc#opc/startLogin", service: "opc", namespace: "opc", method: "startLogin", invocation: { kind: "direct" }, parameters: [], result: { mode: "strict", typeSymbol: "opc/startLogin:result", create: () => z.string() } },
|
|
@@ -3646,7 +3963,14 @@ var inject = ["credentials", "authorization", "skills", "tools", "agents", "appr
|
|
|
3646
3963
|
var Config = z2.object({ platformBaseUrl: z2.string().default("https://shtokendance.benlai.com"), clientId: z2.string().default("work-desktop"), dataHome: z2.string().default(""), appDomainRoot: z2.string().default(""), appDefaultPort: z2.number().default(8080) });
|
|
3647
3964
|
function apply(ctx, config) {
|
|
3648
3965
|
const key = credentialKey(name, "enterprise");
|
|
3649
|
-
const
|
|
3966
|
+
const home = config.dataHome || resolveDshHome();
|
|
3967
|
+
const configStore = new OpcConfigStore(home, {
|
|
3968
|
+
platformBaseUrl: config.platformBaseUrl,
|
|
3969
|
+
appDomainRoot: config.appDomainRoot,
|
|
3970
|
+
appDefaultPort: config.appDefaultPort
|
|
3971
|
+
});
|
|
3972
|
+
const initialConfig = configStore.loadSync();
|
|
3973
|
+
const auth = new AuthManager(new PlatformHttp(initialConfig.platform_base), {
|
|
3650
3974
|
async read() {
|
|
3651
3975
|
const record2 = await ctx.credentials.readRecord(key);
|
|
3652
3976
|
if (record2?.kind !== "grant") return void 0;
|
|
@@ -3672,8 +3996,8 @@ function apply(ctx, config) {
|
|
|
3672
3996
|
async write(id, payload) {
|
|
3673
3997
|
await ctx.credentials.modifyRecord(credentialKey(name, `app-${id}`), async () => ({ kind: "grant", payload }));
|
|
3674
3998
|
}
|
|
3675
|
-
}, { appDomainRoot:
|
|
3676
|
-
ctx.plugin(OpcRemoteService, { core, delivery });
|
|
3999
|
+
}, { appDomainRoot: initialConfig.app_domain_root, appDefaultPort: initialConfig.app_default_port });
|
|
4000
|
+
ctx.plugin(OpcRemoteService, { core, delivery, configStore });
|
|
3677
4001
|
ctx.inject(["systemPrompt"], (child) => attachAppAgent(child, delivery));
|
|
3678
4002
|
ctx.effect(() => ctx.skills.registerProvider((control) => new AppSkillProvider(delivery, control)));
|
|
3679
4003
|
registerAppTools(ctx, delivery);
|