dsh-plugin-opc 0.1.10 → 0.1.12
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 +620 -90
- package/lib/index.js +435 -123
- package/package.json +1 -1
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, _appJobByAnalysisSession_dec, _appJob_dec, _appList_dec, _a, _init;
|
|
1435
|
+
var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [Remote], _appJob_dec = [Remote], _appJobByAnalysisSession_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 });
|
|
@@ -1261,6 +1477,9 @@ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [
|
|
|
1261
1477
|
async appJob(id, expectedContextId) {
|
|
1262
1478
|
return JSON.stringify(await this.delivery.getJob(id, expectedContextId));
|
|
1263
1479
|
}
|
|
1480
|
+
async appJobByAnalysisSession(sessionId, expectedContextId) {
|
|
1481
|
+
return JSON.stringify(await this.delivery.getJobByAnalysisSession(sessionId, expectedContextId));
|
|
1482
|
+
}
|
|
1264
1483
|
async appCheckSlug(slug, expectedContextId) {
|
|
1265
1484
|
return JSON.stringify(await this.delivery.checkSlug(slug, expectedContextId));
|
|
1266
1485
|
}
|
|
@@ -1410,13 +1629,41 @@ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [
|
|
|
1410
1629
|
const parsed = JSON.parse(payloadJson);
|
|
1411
1630
|
return JSON.stringify(await this.delivery.rollback(slug, Number(parsed.targetVersion ?? parsed.target_version ?? 0), String(parsed.reason ?? ""), expectedContextId));
|
|
1412
1631
|
}
|
|
1632
|
+
async applyConfigChange(result) {
|
|
1633
|
+
const { config, platform_base_changed } = result;
|
|
1634
|
+
await this.core.auth.setPlatformBase(config.platform_base);
|
|
1635
|
+
this.delivery.updateOptions({
|
|
1636
|
+
appDomainRoot: config.app_domain_root,
|
|
1637
|
+
appDefaultPort: config.app_default_port
|
|
1638
|
+
});
|
|
1639
|
+
if (platform_base_changed) this.core.emit("skills-changed");
|
|
1640
|
+
return JSON.stringify({ ...config, platform_base_changed });
|
|
1641
|
+
}
|
|
1642
|
+
async opcConfigGet() {
|
|
1643
|
+
return JSON.stringify(this.configStore.getPayload(this.core.auth.http.base.href));
|
|
1644
|
+
}
|
|
1645
|
+
async opcConfigUpdate(payloadJson) {
|
|
1646
|
+
const parsed = JSON.parse(payloadJson);
|
|
1647
|
+
return this.applyConfigChange(await this.configStore.update({
|
|
1648
|
+
platform_base: parsed.platform_base,
|
|
1649
|
+
app_domain_root: parsed.app_domain_root,
|
|
1650
|
+
app_default_port: parsed.app_default_port
|
|
1651
|
+
}));
|
|
1652
|
+
}
|
|
1653
|
+
async opcConfigReset() {
|
|
1654
|
+
return this.applyConfigChange(await this.configStore.reset());
|
|
1655
|
+
}
|
|
1656
|
+
async opcConfigTest(url) {
|
|
1657
|
+
return JSON.stringify(await this.configStore.testConnection(url));
|
|
1658
|
+
}
|
|
1413
1659
|
async state() {
|
|
1414
1660
|
const state = this.core.auth.state;
|
|
1415
1661
|
const mounted = this.mounts?.list() ?? [];
|
|
1662
|
+
const cfg = this.configStore.getPayload(this.core.auth.http.base.href);
|
|
1416
1663
|
return JSON.stringify({ ...state, knowledgeMentionScopeVersion: 1, mountAvailable: !!this.mounts, mcpConnections: Object.fromEntries(mounted.map((id) => {
|
|
1417
1664
|
const status = this.manager?.list().find((item) => item.name === mcpMountName(id))?.status;
|
|
1418
1665
|
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 });
|
|
1666
|
+
})), 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
1667
|
}
|
|
1421
1668
|
async *watchState(signal) {
|
|
1422
1669
|
let wake, dirty = true;
|
|
@@ -1528,6 +1775,7 @@ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [
|
|
|
1528
1775
|
_init = __decoratorStart(_a);
|
|
1529
1776
|
__decorateElement(_init, 1, "appList", _appList_dec, OpcRemoteService);
|
|
1530
1777
|
__decorateElement(_init, 1, "appJob", _appJob_dec, OpcRemoteService);
|
|
1778
|
+
__decorateElement(_init, 1, "appJobByAnalysisSession", _appJobByAnalysisSession_dec, OpcRemoteService);
|
|
1531
1779
|
__decorateElement(_init, 1, "appCheckSlug", _appCheckSlug_dec, OpcRemoteService);
|
|
1532
1780
|
__decorateElement(_init, 1, "appOpcConfig", _appOpcConfig_dec, OpcRemoteService);
|
|
1533
1781
|
__decorateElement(_init, 1, "appPickSourceFolder", _appPickSourceFolder_dec, OpcRemoteService);
|
|
@@ -1562,6 +1810,10 @@ __decorateElement(_init, 1, "appRecheck", _appRecheck_dec, OpcRemoteService);
|
|
|
1562
1810
|
__decorateElement(_init, 1, "appUpdateConfig", _appUpdateConfig_dec, OpcRemoteService);
|
|
1563
1811
|
__decorateElement(_init, 1, "appDelete", _appDelete_dec, OpcRemoteService);
|
|
1564
1812
|
__decorateElement(_init, 1, "appRollback", _appRollback_dec, OpcRemoteService);
|
|
1813
|
+
__decorateElement(_init, 1, "opcConfigGet", _opcConfigGet_dec, OpcRemoteService);
|
|
1814
|
+
__decorateElement(_init, 1, "opcConfigUpdate", _opcConfigUpdate_dec, OpcRemoteService);
|
|
1815
|
+
__decorateElement(_init, 1, "opcConfigReset", _opcConfigReset_dec, OpcRemoteService);
|
|
1816
|
+
__decorateElement(_init, 1, "opcConfigTest", _opcConfigTest_dec, OpcRemoteService);
|
|
1565
1817
|
__decorateElement(_init, 1, "state", _state_dec, OpcRemoteService);
|
|
1566
1818
|
__decorateElement(_init, 1, "watchState", _watchState_dec, OpcRemoteService);
|
|
1567
1819
|
__decorateElement(_init, 1, "startLogin", _startLogin_dec, OpcRemoteService);
|
|
@@ -1638,11 +1890,11 @@ function registerTools(ctx, core) {
|
|
|
1638
1890
|
}
|
|
1639
1891
|
|
|
1640
1892
|
// src/host/app-delivery.ts
|
|
1641
|
-
import { createWriteStream, existsSync } from "node:fs";
|
|
1893
|
+
import { createWriteStream, existsSync as existsSync2 } from "node:fs";
|
|
1642
1894
|
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
|
|
1895
|
+
import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
|
|
1896
|
+
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";
|
|
1897
|
+
import { dirname as dirname3, isAbsolute, join as join3 } from "node:path";
|
|
1646
1898
|
import { homedir } from "node:os";
|
|
1647
1899
|
import { Transform } from "node:stream";
|
|
1648
1900
|
import { pipeline } from "node:stream/promises";
|
|
@@ -1700,9 +1952,9 @@ function worker(input, signal) {
|
|
|
1700
1952
|
const runtime = import.meta.url.endsWith("/lib/index.js") ? fileURLToPath(new URL("../runtime/worker.py", import.meta.url)) : path;
|
|
1701
1953
|
const executable = dirname3(process.execPath);
|
|
1702
1954
|
const bundled = [
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
].find((candidate) =>
|
|
1955
|
+
join3(executable, "../Resources/runtime/primary-runtime/dependencies/python/bin/python3"),
|
|
1956
|
+
join3(executable, "../../python/bin/python3")
|
|
1957
|
+
].find((candidate) => existsSync2(candidate));
|
|
1706
1958
|
return new Promise((resolve, reject) => {
|
|
1707
1959
|
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
1960
|
let stdout = "", stderr = "", exceeded = false;
|
|
@@ -1753,21 +2005,32 @@ var AppDelivery = class {
|
|
|
1753
2005
|
busy = /* @__PURE__ */ new Set();
|
|
1754
2006
|
analyses = /* @__PURE__ */ new Map();
|
|
1755
2007
|
analyze;
|
|
2008
|
+
getOptions() {
|
|
2009
|
+
return { ...this.options };
|
|
2010
|
+
}
|
|
2011
|
+
updateOptions(next) {
|
|
2012
|
+
this.options = {
|
|
2013
|
+
...this.options,
|
|
2014
|
+
...next.appDomainRoot !== void 0 ? { appDomainRoot: next.appDomainRoot } : {},
|
|
2015
|
+
...next.appDefaultPort !== void 0 ? { appDefaultPort: next.appDefaultPort } : {}
|
|
2016
|
+
};
|
|
2017
|
+
this.core.emit("change");
|
|
2018
|
+
}
|
|
1756
2019
|
scope(expected) {
|
|
1757
2020
|
const captured = this.core.auth.contexts.captureApplication(expected);
|
|
1758
|
-
const directory =
|
|
2021
|
+
const directory = join3(this.home, "opc", "apps", identityHash(captured.context));
|
|
1759
2022
|
return { ...captured, directory };
|
|
1760
2023
|
}
|
|
1761
2024
|
async save(root, job) {
|
|
1762
|
-
await
|
|
1763
|
-
const temp =
|
|
1764
|
-
await
|
|
1765
|
-
await
|
|
2025
|
+
await mkdir3(root, { recursive: true, mode: 448 });
|
|
2026
|
+
const temp = join3(root, `job-${randomUUID4()}.tmp`);
|
|
2027
|
+
await writeFile3(temp, JSON.stringify(job), { mode: 384 });
|
|
2028
|
+
await rename3(temp, join3(root, "job.json"));
|
|
1766
2029
|
this.core.emit("change");
|
|
1767
2030
|
}
|
|
1768
2031
|
skillPreferencePath(directory, slug) {
|
|
1769
2032
|
if (!/^[a-z][a-z0-9-]{2,39}$/.test(slug)) throw new Error("\u65E0\u6548\u5E94\u7528\u6807\u8BC6");
|
|
1770
|
-
return
|
|
2033
|
+
return join3(directory, "skill-preferences", slug);
|
|
1771
2034
|
}
|
|
1772
2035
|
async isSkillDisabled(directory, slug) {
|
|
1773
2036
|
return readFile2(this.skillPreferencePath(directory, slug), "utf8").then((value) => value === "disabled", (error) => {
|
|
@@ -1780,14 +2043,14 @@ var AppDelivery = class {
|
|
|
1780
2043
|
if (error.code === "ENOENT") return [];
|
|
1781
2044
|
throw error;
|
|
1782
2045
|
});
|
|
1783
|
-
return [directory, ...entries.filter((id) => /^[a-f0-9]{64}$/.test(id)).map((id) =>
|
|
2046
|
+
return [directory, ...entries.filter((id) => /^[a-f0-9]{64}$/.test(id)).map((id) => join3(directory, id))];
|
|
1784
2047
|
}
|
|
1785
2048
|
async open(directory, id) {
|
|
1786
2049
|
if (!/^[a-f0-9-]{36}$/.test(id)) throw new Error("\u65E0\u6548\u4EFB\u52A1");
|
|
1787
2050
|
for (const parent of await this.directories(directory)) {
|
|
1788
|
-
const root =
|
|
2051
|
+
const root = join3(parent, id);
|
|
1789
2052
|
try {
|
|
1790
|
-
const job = JSON.parse(await readFile2(
|
|
2053
|
+
const job = JSON.parse(await readFile2(join3(root, "job.json"), "utf8"));
|
|
1791
2054
|
return { root, job };
|
|
1792
2055
|
} catch (error) {
|
|
1793
2056
|
if (error.code !== "ENOENT") throw error;
|
|
@@ -1827,13 +2090,13 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1827
2090
|
async archivePublishedVersion(scopeDir, job, bundleDir) {
|
|
1828
2091
|
const { slug, version, requestId, id: jobId } = job;
|
|
1829
2092
|
if (!/^[a-z][a-z0-9-]{2,39}$/.test(slug) || !version || version <= 0) return;
|
|
1830
|
-
const verDir =
|
|
1831
|
-
await
|
|
2093
|
+
const verDir = join3(scopeDir, "versions", slug, `v${version}`);
|
|
2094
|
+
await mkdir3(verDir, { recursive: true, mode: 448 });
|
|
1832
2095
|
const hashes = {};
|
|
1833
2096
|
for (const name2 of ["app.tar", "skill.zip", "app-manifest.json", "summary.json"]) {
|
|
1834
2097
|
try {
|
|
1835
|
-
const src =
|
|
1836
|
-
await copyFile(src,
|
|
2098
|
+
const src = join3(bundleDir, name2);
|
|
2099
|
+
await copyFile(src, join3(verDir, name2));
|
|
1837
2100
|
if (name2 === "app.tar" || name2 === "skill.zip") {
|
|
1838
2101
|
hashes[name2] = hash(await readFile2(src));
|
|
1839
2102
|
}
|
|
@@ -1841,7 +2104,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1841
2104
|
}
|
|
1842
2105
|
}
|
|
1843
2106
|
if (Object.keys(hashes).length > 0) {
|
|
1844
|
-
await
|
|
2107
|
+
await writeFile3(join3(verDir, "summary.json"), JSON.stringify({ version, hashes, jobId, requestId }, null, 2), { mode: 384 }).catch(() => {
|
|
1845
2108
|
});
|
|
1846
2109
|
}
|
|
1847
2110
|
}
|
|
@@ -1858,14 +2121,17 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1858
2121
|
}
|
|
1859
2122
|
}
|
|
1860
2123
|
}
|
|
1861
|
-
async
|
|
1862
|
-
const
|
|
1863
|
-
const
|
|
1864
|
-
const entries = (await Promise.all(directories.map((directory) => readdir2(directory).catch((error) => {
|
|
2124
|
+
async localJobIds(directory) {
|
|
2125
|
+
const directories = await this.directories(directory);
|
|
2126
|
+
const entries = (await Promise.all(directories.map((directory2) => readdir2(directory2).catch((error) => {
|
|
1865
2127
|
if (error.code === "ENOENT") return [];
|
|
1866
2128
|
throw error;
|
|
1867
2129
|
})))).flat();
|
|
1868
|
-
|
|
2130
|
+
return [...new Set(entries.filter((id) => /^[a-f0-9-]{36}$/.test(id)))];
|
|
2131
|
+
}
|
|
2132
|
+
async list(expected) {
|
|
2133
|
+
const scope = this.scope(expected);
|
|
2134
|
+
const jobs = await Promise.all((await this.localJobIds(scope.directory)).map(async (id) => {
|
|
1869
2135
|
const result = await this.open(scope.directory, id).catch((error) => {
|
|
1870
2136
|
if (error.code !== "ENOENT") throw error;
|
|
1871
2137
|
return void 0;
|
|
@@ -1899,7 +2165,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1899
2165
|
job.status = "building";
|
|
1900
2166
|
job.error = void 0;
|
|
1901
2167
|
if (job.revision && job.version) {
|
|
1902
|
-
await this.archivePublishedVersion(scope.directory, job,
|
|
2168
|
+
await this.archivePublishedVersion(scope.directory, job, join3(root, job.revision, "bundle"));
|
|
1903
2169
|
}
|
|
1904
2170
|
}
|
|
1905
2171
|
await this.save(root, job);
|
|
@@ -1942,6 +2208,17 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1942
2208
|
if (job.status === "verified") view.userDisabled = await this.isSkillDisabled(scope.directory, job.slug);
|
|
1943
2209
|
return view;
|
|
1944
2210
|
}
|
|
2211
|
+
async getJobByAnalysisSession(sessionId, expected) {
|
|
2212
|
+
const scope = this.scope(expected);
|
|
2213
|
+
if (!/^[a-f0-9-]{36}$/.test(sessionId)) return null;
|
|
2214
|
+
const jobs = await Promise.all((await this.localJobIds(scope.directory)).map((id) => this.open(scope.directory, id).catch((error) => {
|
|
2215
|
+
if (error.code !== "ENOENT") throw error;
|
|
2216
|
+
return void 0;
|
|
2217
|
+
})));
|
|
2218
|
+
scope.assertCurrent();
|
|
2219
|
+
const match = jobs.find((entry) => entry?.job.analysisSessions?.includes(sessionId));
|
|
2220
|
+
return match ? this.getJob(match.job.id, expected) : null;
|
|
2221
|
+
}
|
|
1945
2222
|
async checkSlug(slug, expected) {
|
|
1946
2223
|
const trimmed = slug.trim();
|
|
1947
2224
|
if (!/^[a-z][a-z0-9-]{2,39}$/.test(trimmed)) throw new Error("\u5E94\u7528\u552F\u4E00\u6807\u8BC6\u9700\u4E3A 3\u201340 \u4F4D\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u6216\u8FDE\u5B57\u7B26\uFF0C\u4E14\u4EE5\u5B57\u6BCD\u5F00\u5934");
|
|
@@ -1976,7 +2253,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1976
2253
|
};
|
|
1977
2254
|
}
|
|
1978
2255
|
public(job, root) {
|
|
1979
|
-
const { proposal, skillMarkdown: _sm, dockerfileContent: _df, configDraft: _draft, confirmationToken: _token, ...rest } = job;
|
|
2256
|
+
const { proposal, skillMarkdown: _sm, dockerfileContent: _df, configDraft: _draft, confirmationToken: _token, analysisSessions: _analysisSessions, ...rest } = job;
|
|
1980
2257
|
const hasOrigSet = new Set(job.hasOriginalKeys ?? []);
|
|
1981
2258
|
const runtimeConfigs = (proposal?.contract?.configs ?? []).map((c) => {
|
|
1982
2259
|
const hasOrig = hasOrigSet.has(c.key) || Boolean(c.has_original_value);
|
|
@@ -1991,7 +2268,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1991
2268
|
source_label: c.source?.path ? `\u6765\u81EA\u539F\u9879\u76EE ${c.source.path}` : void 0
|
|
1992
2269
|
};
|
|
1993
2270
|
});
|
|
1994
|
-
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 ?
|
|
2271
|
+
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;
|
|
1995
2272
|
return {
|
|
1996
2273
|
...rest,
|
|
1997
2274
|
model: job.modelSelection?.model ?? "",
|
|
@@ -2118,7 +2395,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2118
2395
|
if (previous && previous.url !== targetUrl) throw new Error("\u91CD\u65B0\u5BFC\u5165\u987B\u4FDD\u6301\u539F\u5E94\u7528\u5730\u5740");
|
|
2119
2396
|
scope.assertCurrent();
|
|
2120
2397
|
const job = {
|
|
2121
|
-
id:
|
|
2398
|
+
id: randomUUID4(),
|
|
2122
2399
|
name: targetName,
|
|
2123
2400
|
slug: input.slug,
|
|
2124
2401
|
url: targetUrl,
|
|
@@ -2133,7 +2410,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2133
2410
|
status: "importing",
|
|
2134
2411
|
events: ["\u6B63\u5728\u521B\u5EFA\u6E90\u7801\u9694\u79BB\u526F\u672C"]
|
|
2135
2412
|
};
|
|
2136
|
-
const root =
|
|
2413
|
+
const root = join3(scope.directory, job.id);
|
|
2137
2414
|
await this.exclusive(job.id, async () => {
|
|
2138
2415
|
await this.save(root, job);
|
|
2139
2416
|
try {
|
|
@@ -2142,8 +2419,8 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2142
2419
|
if (typeof input.zip !== "string" || input.zip.length > 9e7) throw new Error("ZIP \u4E0D\u80FD\u8D85\u8FC7 64 MiB");
|
|
2143
2420
|
const bytes = Buffer.from(input.zip, "base64");
|
|
2144
2421
|
if (bytes.length > 64 * 1024 * 1024) throw new Error("ZIP \u4E0D\u80FD\u8D85\u8FC7 64 MiB");
|
|
2145
|
-
source =
|
|
2146
|
-
await
|
|
2422
|
+
source = join3(root, "uploaded.zip");
|
|
2423
|
+
await writeFile3(source, bytes, { mode: 384 });
|
|
2147
2424
|
} else {
|
|
2148
2425
|
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");
|
|
2149
2426
|
source = input.source;
|
|
@@ -2231,7 +2508,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2231
2508
|
const resume = options?.mode === "resume";
|
|
2232
2509
|
if (resume && (job.status !== "failed" || feedback.trim())) throw new Error("\u53EA\u80FD\u7EE7\u7EED\u5DF2\u6682\u505C\u7684\u5E94\u7528\u51C6\u5907");
|
|
2233
2510
|
this.busy.add(id);
|
|
2234
|
-
|
|
2511
|
+
if (session && !job.analysisSessions?.includes(session)) job.session = session;
|
|
2235
2512
|
let trimmedFeedback;
|
|
2236
2513
|
try {
|
|
2237
2514
|
trimmedFeedback = await worker({ action: "redact_feedback", root, text: feedback.slice(0, 2e4) }, scope.signal);
|
|
@@ -2245,7 +2522,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2245
2522
|
if (!resume) {
|
|
2246
2523
|
job.analysisFailure = void 0;
|
|
2247
2524
|
if (!job.proposal) {
|
|
2248
|
-
await rm2(
|
|
2525
|
+
await rm2(join3(root, "draft_files.json"), { force: true }).catch(() => {
|
|
2249
2526
|
});
|
|
2250
2527
|
}
|
|
2251
2528
|
}
|
|
@@ -2279,6 +2556,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2279
2556
|
}
|
|
2280
2557
|
}
|
|
2281
2558
|
job.status = "analyzing";
|
|
2559
|
+
delete job.analysisSessionId;
|
|
2282
2560
|
job.failureStage = void 0;
|
|
2283
2561
|
job.error = void 0;
|
|
2284
2562
|
job.checks = void 0;
|
|
@@ -2286,7 +2564,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2286
2564
|
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"
|
|
2287
2565
|
);
|
|
2288
2566
|
try {
|
|
2289
|
-
await rm2(
|
|
2567
|
+
await rm2(join3(root, "failed_files_read.json"), { force: true });
|
|
2290
2568
|
await this.save(root, job);
|
|
2291
2569
|
} catch (error) {
|
|
2292
2570
|
this.analyses.delete(id);
|
|
@@ -2296,7 +2574,14 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2296
2574
|
this.core.emit("skills-changed");
|
|
2297
2575
|
void (async () => {
|
|
2298
2576
|
try {
|
|
2299
|
-
await this.analyze(job, root, trimmedFeedback, analysisSignal)
|
|
2577
|
+
await this.analyze(job, root, trimmedFeedback, analysisSignal, async (sessionId) => {
|
|
2578
|
+
analysisSignal.throwIfAborted();
|
|
2579
|
+
scope.assertCurrent();
|
|
2580
|
+
const analysisSessions = [...(job.analysisSessions ?? []).filter((id2) => id2 !== sessionId), sessionId];
|
|
2581
|
+
await this.save(root, { ...job, analysisSessions, analysisSessionId: sessionId });
|
|
2582
|
+
job.analysisSessions = analysisSessions;
|
|
2583
|
+
job.analysisSessionId = sessionId;
|
|
2584
|
+
});
|
|
2300
2585
|
analysisSignal.throwIfAborted();
|
|
2301
2586
|
scope.assertCurrent();
|
|
2302
2587
|
if (!job.proposal || job.status === "analyzing") throw new Error("AI \u672A\u63D0\u4EA4\u6709\u6548\u6539\u9020\u65B9\u6848\uFF0C\u8BF7\u8865\u5145\u8BF4\u660E\u540E\u91CD\u8BD5");
|
|
@@ -2356,7 +2641,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2356
2641
|
const scope = this.scope(expected);
|
|
2357
2642
|
const { root, job } = await this.open(scope.directory, id);
|
|
2358
2643
|
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");
|
|
2359
|
-
const path =
|
|
2644
|
+
const path = join3(root, job.revision, "bundle", filename);
|
|
2360
2645
|
const size = (await stat(path)).size;
|
|
2361
2646
|
if (size > 64 * 1024 * 1024) throw new Error("\u6587\u4EF6\u8D85\u8FC7\u63D2\u4EF6\u4E0B\u8F7D\u4E0A\u9650 64 MiB");
|
|
2362
2647
|
const bytes = await readFile2(path);
|
|
@@ -2364,26 +2649,26 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2364
2649
|
if (filename !== "summary.json" && hash(bytes) !== job.hashes?.[filename]) throw new Error("\u4EA4\u4ED8\u6587\u4EF6\u5DF2\u53D1\u751F\u53D8\u5316");
|
|
2365
2650
|
return { filename: `${job.slug}-${filename}`, base64: bytes.toString("base64") };
|
|
2366
2651
|
}
|
|
2367
|
-
async saveLocalArtifact(id, filename, expected, downloads =
|
|
2652
|
+
async saveLocalArtifact(id, filename, expected, downloads = join3(homedir(), "Downloads")) {
|
|
2368
2653
|
const scope = this.scope(expected);
|
|
2369
2654
|
const { root, job } = await this.open(scope.directory, id);
|
|
2370
2655
|
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");
|
|
2371
|
-
const src =
|
|
2656
|
+
const src = join3(root, job.revision, "bundle", filename);
|
|
2372
2657
|
const bytes = await readFile2(src);
|
|
2373
2658
|
scope.assertCurrent();
|
|
2374
2659
|
if (filename !== "summary.json" && hash(bytes) !== job.hashes?.[filename]) throw new Error("\u4EA4\u4ED8\u6587\u4EF6\u5DF2\u53D1\u751F\u53D8\u5316");
|
|
2375
|
-
await
|
|
2660
|
+
await mkdir3(downloads, { recursive: true, mode: 448 });
|
|
2376
2661
|
const outName = `${job.slug}-${filename}`;
|
|
2377
|
-
const temp =
|
|
2378
|
-
await
|
|
2662
|
+
const temp = join3(downloads, `.opc-${randomUUID4()}.artifact`);
|
|
2663
|
+
await writeFile3(temp, bytes, { mode: 384 });
|
|
2379
2664
|
try {
|
|
2380
|
-
const preferred =
|
|
2665
|
+
const preferred = join3(downloads, outName);
|
|
2381
2666
|
let dest = preferred;
|
|
2382
2667
|
try {
|
|
2383
2668
|
await link(temp, dest);
|
|
2384
2669
|
} catch (error) {
|
|
2385
2670
|
if (error.code !== "EEXIST") throw error;
|
|
2386
|
-
dest =
|
|
2671
|
+
dest = join3(downloads, `${randomUUID4().slice(0, 8)}-${outName}`);
|
|
2387
2672
|
await link(temp, dest);
|
|
2388
2673
|
}
|
|
2389
2674
|
return { filename: outName, path: dest };
|
|
@@ -2396,7 +2681,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2396
2681
|
const scope = this.scope(expected);
|
|
2397
2682
|
const { root, job } = await this.open(scope.directory, id);
|
|
2398
2683
|
if (job.status !== "ready" || !job.skillMarkdown || !job.hashes?.["skill.zip"] || !job.revision) throw new Error("\u6280\u80FD\u5C1A\u672A\u751F\u6210");
|
|
2399
|
-
const bytes = await readFile2(
|
|
2684
|
+
const bytes = await readFile2(join3(root, job.revision, "bundle", "skill.zip"));
|
|
2400
2685
|
scope.assertCurrent();
|
|
2401
2686
|
const result = await worker({
|
|
2402
2687
|
action: "extract_skill_contract",
|
|
@@ -2470,7 +2755,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2470
2755
|
job.error = void 0;
|
|
2471
2756
|
await this.save(root, job);
|
|
2472
2757
|
try {
|
|
2473
|
-
const revision =
|
|
2758
|
+
const revision = randomUUID4().replaceAll("-", "");
|
|
2474
2759
|
const result = await worker({
|
|
2475
2760
|
action: "bundle",
|
|
2476
2761
|
root,
|
|
@@ -2501,7 +2786,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2501
2786
|
job.version = void 0;
|
|
2502
2787
|
job.published = void 0;
|
|
2503
2788
|
job.restoredVersion = void 0;
|
|
2504
|
-
job.requestId =
|
|
2789
|
+
job.requestId = randomUUID4().replaceAll("-", "");
|
|
2505
2790
|
job.confirmationToken = void 0;
|
|
2506
2791
|
job.events.push("\u90E8\u7F72\u5305\u5DF2\u751F\u6210\uFF0C\u670D\u52A1\u5668\u6784\u5EFA\u548C\u4E1A\u52A1\u9A8C\u8BC1\u5C1A\u672A\u6267\u884C");
|
|
2507
2792
|
} catch (error) {
|
|
@@ -2560,8 +2845,8 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2560
2845
|
const prior = await this.credentials.read(`confirm-${id}`);
|
|
2561
2846
|
scope.assertCurrent();
|
|
2562
2847
|
if (!job.confirmationToken || prior.digest !== digest) {
|
|
2563
|
-
job.confirmationToken =
|
|
2564
|
-
job.requestId =
|
|
2848
|
+
job.confirmationToken = randomUUID4();
|
|
2849
|
+
job.requestId = randomUUID4().replaceAll("-", "");
|
|
2565
2850
|
await this.credentials.write(`confirm-${id}`, { digest });
|
|
2566
2851
|
await this.save(root, job);
|
|
2567
2852
|
}
|
|
@@ -2580,21 +2865,21 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2580
2865
|
if (!job.confirmationToken || input.confirmationToken !== job.confirmationToken || (await this.credentials.read(`confirm-${id}`)).digest !== digest) {
|
|
2581
2866
|
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");
|
|
2582
2867
|
}
|
|
2583
|
-
const requestId = job.requestId ||
|
|
2868
|
+
const requestId = job.requestId || randomUUID4().replaceAll("-", "");
|
|
2584
2869
|
job.versionNote = versionNote;
|
|
2585
2870
|
job.requestId = requestId;
|
|
2586
2871
|
job.configKeys = bindings.map((c) => c.key);
|
|
2587
2872
|
job.resourceIds = ids;
|
|
2588
2873
|
const form = new FormData(), contract = job.proposal.contract;
|
|
2589
|
-
const folder =
|
|
2874
|
+
const folder = join3(root, job.revision, "bundle");
|
|
2590
2875
|
for (const name2 of ["app.tar", "skill.zip"]) {
|
|
2591
|
-
const bytes = await readFile2(
|
|
2876
|
+
const bytes = await readFile2(join3(folder, name2));
|
|
2592
2877
|
if (hash(bytes) !== job.hashes?.[name2]) throw new Error("\u5236\u54C1\u6458\u8981\u4E0D\u4E00\u81F4\uFF0C\u62D2\u7EDD\u53D1\u5E03");
|
|
2593
2878
|
form.append(name2 === "app.tar" ? "app_tar" : "skill_zip", new Blob([new Uint8Array(bytes)]), name2);
|
|
2594
2879
|
}
|
|
2595
2880
|
let dockerfileContent = job.dockerfileContent ?? "";
|
|
2596
2881
|
if (!dockerfileContent) {
|
|
2597
|
-
dockerfileContent = await readFile2(
|
|
2882
|
+
dockerfileContent = await readFile2(join3(root, job.revision, "approved/source/Dockerfile"), "utf8").catch(() => "");
|
|
2598
2883
|
}
|
|
2599
2884
|
for (const [key, value] of Object.entries({
|
|
2600
2885
|
slug: job.slug,
|
|
@@ -2695,7 +2980,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2695
2980
|
job.published = true;
|
|
2696
2981
|
job.version = receipt.version;
|
|
2697
2982
|
job.status = "building";
|
|
2698
|
-
if (job.revision) await this.archivePublishedVersion(scope.directory, job,
|
|
2983
|
+
if (job.revision) await this.archivePublishedVersion(scope.directory, job, join3(root, job.revision, "bundle"));
|
|
2699
2984
|
await this.save(root, job);
|
|
2700
2985
|
}
|
|
2701
2986
|
const contract = job.proposal.contract;
|
|
@@ -2849,11 +3134,11 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2849
3134
|
}
|
|
2850
3135
|
return { filename, base64: result.bytes.toString("base64") };
|
|
2851
3136
|
}
|
|
2852
|
-
async saveDownload(slug, selection, expected, downloads =
|
|
3137
|
+
async saveDownload(slug, selection, expected, downloads = join3(homedir(), "Downloads")) {
|
|
2853
3138
|
const scope = this.scope(expected);
|
|
2854
3139
|
const { filename, path, query } = this.downloadTarget(slug, selection);
|
|
2855
|
-
await
|
|
2856
|
-
const temp =
|
|
3140
|
+
await mkdir3(downloads, { recursive: true, mode: 448 });
|
|
3141
|
+
const temp = join3(downloads, `.opc-${randomUUID4()}.download`);
|
|
2857
3142
|
const response = await this.platform(path, expected, { query, stream: true });
|
|
2858
3143
|
if (!response.body) throw new Error("\u5E73\u53F0\u672A\u8FD4\u56DE\u6587\u4EF6\u5185\u5BB9");
|
|
2859
3144
|
try {
|
|
@@ -2868,13 +3153,13 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2868
3153
|
const expectedHash = response.headers.get("x-artifact-sha256");
|
|
2869
3154
|
if (!bytes || expectedHash && digest.digest("hex") !== expectedHash) throw new Error("\u5E73\u53F0\u8FD4\u56DE\u6587\u4EF6\u4E3A\u7A7A\u6216\u6458\u8981\u4E0D\u5339\u914D");
|
|
2870
3155
|
scope.assertCurrent();
|
|
2871
|
-
const preferred =
|
|
3156
|
+
const preferred = join3(downloads, filename);
|
|
2872
3157
|
let dest = preferred;
|
|
2873
3158
|
try {
|
|
2874
3159
|
await link(temp, dest);
|
|
2875
3160
|
} catch (error) {
|
|
2876
3161
|
if (error.code !== "EEXIST") throw error;
|
|
2877
|
-
dest =
|
|
3162
|
+
dest = join3(downloads, `${randomUUID4().slice(0, 8)}-${filename}`);
|
|
2878
3163
|
await link(temp, dest);
|
|
2879
3164
|
}
|
|
2880
3165
|
return { path: dest };
|
|
@@ -2945,7 +3230,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2945
3230
|
const verInfo = rbResult.version ?? {};
|
|
2946
3231
|
let expectedSkillSha = String(rbResult.skill_zip_sha256 || verInfo.skill_zip_sha256 || "").trim();
|
|
2947
3232
|
let expectedAppTarSha = String(verInfo.app_tar_sha256 || "").trim();
|
|
2948
|
-
const localMeta = await readFile2(
|
|
3233
|
+
const localMeta = await readFile2(join3(scope.directory, "versions", slug, `v${targetVersion}`, "summary.json"), "utf8").then((s) => JSON.parse(s)).catch(() => void 0);
|
|
2949
3234
|
let skillZipBytes;
|
|
2950
3235
|
try {
|
|
2951
3236
|
const dl = await this.platform(`/${slug}/versions/${targetVersion}/artifacts/skill.zip`, expected);
|
|
@@ -2956,9 +3241,9 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2956
3241
|
}
|
|
2957
3242
|
} catch (error) {
|
|
2958
3243
|
if (!(error instanceof AppRequestError) || error.status !== 404) throw error;
|
|
2959
|
-
const verDir =
|
|
2960
|
-
const localFallback =
|
|
2961
|
-
if (
|
|
3244
|
+
const verDir = join3(scope.directory, "versions", slug, `v${targetVersion}`);
|
|
3245
|
+
const localFallback = join3(verDir, "skill.zip");
|
|
3246
|
+
if (existsSync2(localFallback)) {
|
|
2962
3247
|
skillZipBytes = await readFile2(localFallback).catch(() => void 0);
|
|
2963
3248
|
}
|
|
2964
3249
|
if (localMeta) {
|
|
@@ -2970,9 +3255,9 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2970
3255
|
if (!expectedSkillSha || hash(skillZipBytes) !== expectedSkillSha) {
|
|
2971
3256
|
throw new Error("\u56DE\u6EDA\u6280\u80FD\u5305\u6458\u8981\u4E0D\u4E00\u81F4\uFF0C\u62D2\u7EDD\u542F\u7528");
|
|
2972
3257
|
}
|
|
2973
|
-
const verDir =
|
|
2974
|
-
await
|
|
2975
|
-
await
|
|
3258
|
+
const verDir = join3(scope.directory, "versions", slug, `v${targetVersion}`);
|
|
3259
|
+
await mkdir3(verDir, { recursive: true, mode: 448 });
|
|
3260
|
+
await writeFile3(join3(verDir, "skill.zip"), skillZipBytes, { mode: 384 }).catch(() => {
|
|
2976
3261
|
});
|
|
2977
3262
|
}
|
|
2978
3263
|
const matchingJobs = [];
|
|
@@ -2987,8 +3272,8 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2987
3272
|
}
|
|
2988
3273
|
let primary = matchingJobs.find(({ job }) => job.published && job.version === targetVersion && job.hashes?.["app.tar"] === expectedAppTarSha && job.hashes?.["skill.zip"] === expectedSkillSha);
|
|
2989
3274
|
if (!primary && skillZipBytes) {
|
|
2990
|
-
const newId =
|
|
2991
|
-
const newRoot =
|
|
3275
|
+
const newId = randomUUID4();
|
|
3276
|
+
const newRoot = join3(scope.directory, newId);
|
|
2992
3277
|
const newJob = {
|
|
2993
3278
|
id: newId,
|
|
2994
3279
|
name: current.name || slug,
|
|
@@ -3131,12 +3416,12 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
3131
3416
|
if (job.status !== "verified") throw new Error("\u5E94\u7528\u5C1A\u672A\u901A\u8FC7\u4E1A\u52A1\u9A8C\u8BC1");
|
|
3132
3417
|
if (enabled) await this.verifiedJob(id, expected, true);
|
|
3133
3418
|
const path = this.skillPreferencePath(scope.directory, job.slug);
|
|
3134
|
-
await
|
|
3135
|
-
const temp =
|
|
3419
|
+
await mkdir3(dirname3(path), { recursive: true, mode: 448 });
|
|
3420
|
+
const temp = join3(dirname3(path), randomUUID4());
|
|
3136
3421
|
try {
|
|
3137
|
-
await
|
|
3422
|
+
await writeFile3(temp, enabled ? "enabled" : "disabled", { mode: 384 });
|
|
3138
3423
|
scope.assertCurrent();
|
|
3139
|
-
await
|
|
3424
|
+
await rename3(temp, path);
|
|
3140
3425
|
} finally {
|
|
3141
3426
|
await rm2(temp, { force: true });
|
|
3142
3427
|
}
|
|
@@ -3199,9 +3484,9 @@ ${JSON.stringify({ params, body })}`);
|
|
|
3199
3484
|
};
|
|
3200
3485
|
|
|
3201
3486
|
// src/host/app-agent.ts
|
|
3202
|
-
import { randomUUID as
|
|
3203
|
-
import { readFileSync } from "node:fs";
|
|
3204
|
-
import { join as
|
|
3487
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
3488
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
3489
|
+
import { join as join4 } from "node:path";
|
|
3205
3490
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3206
3491
|
import { defineTool as defineTool2 } from "@deepseek-ai/dsh-tools";
|
|
3207
3492
|
import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
@@ -3210,9 +3495,9 @@ function loadBundledSkillText(relativePath) {
|
|
|
3210
3495
|
const fromLib = fileURLToPath2(new URL(`../runtime/app_delivery/${relativePath}`, import.meta.url));
|
|
3211
3496
|
const target = import.meta.url.endsWith("/lib/index.js") ? fromLib : fromSrc;
|
|
3212
3497
|
try {
|
|
3213
|
-
return
|
|
3498
|
+
return readFileSync2(target, "utf8");
|
|
3214
3499
|
} catch {
|
|
3215
|
-
return
|
|
3500
|
+
return readFileSync2(fromSrc, "utf8");
|
|
3216
3501
|
}
|
|
3217
3502
|
}
|
|
3218
3503
|
function normalizeDisplayPath(raw) {
|
|
@@ -3303,38 +3588,16 @@ DEPLOYMENT REPAIR\uFF08\u90E8\u7F72/\u9A8C\u8BC1\u5931\u8D25\u4E13\u9879\u4FEE\u
|
|
|
3303
3588
|
return text2;
|
|
3304
3589
|
}
|
|
3305
3590
|
function attachAppAgent(ctx, delivery) {
|
|
3306
|
-
delivery.analyze = async (job, root, feedback, signal) => {
|
|
3591
|
+
delivery.analyze = async (job, root, feedback, signal, onSessionReady) => {
|
|
3307
3592
|
const parent = ctx.agents.get(job.session);
|
|
3308
|
-
if (!parent) throw new Error("\u8BF7\u5148\u5728\u5F53\u524D\u5DE5\u4F5C\u533A\u521B\u5EFA\u5BF9\u8BDD\uFF0C\u518D\u6253\u5F00 OPC \u5E94\u7528\u8FDB\u884C\u5206\u6790");
|
|
3309
3593
|
const configured = job.modelSelection;
|
|
3310
3594
|
const selection = configured ? {
|
|
3311
3595
|
provider: configured.provider,
|
|
3312
3596
|
model: configured.model,
|
|
3313
3597
|
reasoningEffort: configured.reasoningEffort ? ReasoningEffortId(configured.reasoningEffort) : void 0
|
|
3314
|
-
} : parent
|
|
3598
|
+
} : parent?.model.current() ?? parent?.session.requestHeader()?.config;
|
|
3315
3599
|
const appCtxId = delivery.core.auth.contexts.applicationContextId;
|
|
3316
|
-
const previous = job.published ? await delivery.platform("/" + job.slug, appCtxId).catch(() => void 0) : void 0;
|
|
3317
|
-
const runtimeLogs = job.published ? await delivery.platform("/" + job.slug + "/logs", appCtxId).catch(() => void 0) : void 0;
|
|
3318
|
-
const rawResources = await delivery.platform("/resources", appCtxId).catch(() => ({ resources: [] }));
|
|
3319
|
-
const filteredRes = await worker({
|
|
3320
|
-
action: "filter_resources",
|
|
3321
|
-
root,
|
|
3322
|
-
resources: rawResources?.resources ?? [],
|
|
3323
|
-
slug: job.slug,
|
|
3324
|
-
default_only: true
|
|
3325
|
-
}, signal).catch(() => ({ resources: [] }));
|
|
3326
3600
|
const isRepair = Boolean(job.failedRevision || job.failedSnapshot || job.failureContext || job.analysisMode === "repair");
|
|
3327
|
-
if (isRepair || previous?.error_message || previous?.build_log || runtimeLogs?.runtime_logs) {
|
|
3328
|
-
const mergedFailure = [
|
|
3329
|
-
job.failureContext,
|
|
3330
|
-
previous?.error_message,
|
|
3331
|
-
previous?.build_log?.slice(-8e3),
|
|
3332
|
-
runtimeLogs?.runtime_logs?.slice(-4e3)
|
|
3333
|
-
].filter(Boolean).join("\n");
|
|
3334
|
-
if (mergedFailure) {
|
|
3335
|
-
job.failureContext = await worker({ action: "redact_feedback", root, text: mergedFailure.slice(-24e3) }, signal);
|
|
3336
|
-
}
|
|
3337
|
-
}
|
|
3338
3601
|
const instructions = buildInstructions(isRepair);
|
|
3339
3602
|
const prevPlan = compactPreviousPlan(job.proposal);
|
|
3340
3603
|
const taskInstruction = isRepair ? "\u90E8\u7F72\u5931\u8D25\u4E13\u9879\u4FEE\u590D\uFF1A\u8BFB\u53D6\u5B9E\u9645\u5931\u8D25\u5236\u54C1\u4E0E\u539F\u59CB\u6E90\u7801\uFF0C\u5BF9\u6BD4\u65E7\u4FEE\u6539\uFF0C\u4FEE\u590D\u6839\u56E0\u3002\u4E0D\u80FD\u628A\u672C\u8F6E\u5F53\u6210\u914D\u7F6E\u786E\u8BA4\uFF0C\u4E0D\u80FD\u65E0\u4F9D\u636E\u590D\u7528\u9519\u8BEF\u4EE3\u7801\u3002" : prevPlan && feedback.trim() ? "\u8FD9\u662F\u57FA\u4E8E\u4E0A\u4E00\u8F6E\u5206\u6790\u7ED3\u679C\uFF08previous_plan\uFF09\u7684\u7528\u6237\u786E\u8BA4/\u8865\u5145\u8F6E\u6B21\u3002\u4E0A\u4E00\u8F6E\u6682\u5B58\u7684\u6587\u4EF6\u4FEE\u6539\uFF08changes\uFF09\u5DF2\u9884\u8F7D\u5165\u6682\u5B58\u533A\uFF08\u672A\u6539\u52A8\u7684\u6587\u4EF6\u53EF\u76F4\u63A5\u6309\u539F id \u5F15\u7528\uFF0C\u65E0\u9700\u91CD\u590D\u8BFB\u53D6\u6E90\u7801\u6216\u91CD\u65B0\u8C03\u7528 propose_file\uFF09\uFF0C\u626B\u63CF\u7684\u5168\u90E8\u63A5\u53E3\u4E0E\u9875\u9762\u4E5F\u5DF2\u7531\u540E\u7AEF\u7F13\u5B58\u5E76\u81EA\u52A8\u5408\u5E76\u3002\u8BF7\u4EC5\u9488\u5BF9 user_answers \u8FDB\u884C\u5FC5\u8981\u7684\u589E\u91CF\u8C03\u6574\u5E76\u76F4\u63A5\u8C03\u7528 opc_delivery_submit\uFF08unresolved \u4EC5\u4FDD\u7559\u771F\u6B63\u963B\u585E\u6539\u9020\u7684\u4E8B\u9879\uFF09\u3002\u672C\u8F6E summary \u53EA\u9700\u7B80\u660E\u8BF4\u660E\u5DF2\u6309\u7528\u6237\u786E\u8BA4\u5B8C\u6210\u4E86\u54EA\u4E9B\u8C03\u6574\uFF0C\u4E25\u7981\u91CD\u590D\u8F93\u51FA\u5168\u91CF\u6478\u5E95\u5185\u5BB9\uFF01" : "\u5206\u6790\u5E94\u7528\u5E76\u63D0\u4EA4\u5B8C\u6574\u4FEE\u6539\u63D0\u6848\u548C\u4E1A\u52A1\u5951\u7EA6\u3002\u5148\u8C03\u7528 scan_routes_and_pages \u4E0E\u8BFB\u53D6\u6E90\u7801\u5DE5\u5177\u5168\u9762\u6478\u6E05\u5E94\u7528\uFF0C\u5B8C\u6574\u6536\u5F55\u6240\u6709\u9875\u9762\u4E0E\u6240\u6709\u63A5\u53E3\uFF0C\u6309\u56DB\u6B65\u89C4\u8303\u5206\u6BB5\u6E05\u6670\u8F93\u51FA\u5206\u6790\u4E0E\u6539\u9020\u65B9\u6848\u3002";
|
|
@@ -3344,16 +3607,15 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3344
3607
|
let repeatedProposal = false;
|
|
3345
3608
|
let draftFileChanges = [];
|
|
3346
3609
|
try {
|
|
3347
|
-
const draftsRaw = JSON.parse(
|
|
3610
|
+
const draftsRaw = JSON.parse(readFileSync2(join4(root, "draft_files.json"), "utf8"));
|
|
3348
3611
|
if (draftsRaw && typeof draftsRaw === "object") {
|
|
3349
3612
|
draftFileChanges = Object.values(draftsRaw).map((c) => ({ id: c?.id, path: c?.path, reason: c?.reason }));
|
|
3350
3613
|
}
|
|
3351
3614
|
} catch {
|
|
3352
3615
|
}
|
|
3353
|
-
const
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
agentOptions: selection ? { provider: selection.provider, model: selection.model, reasoningEffort: selection.reasoningEffort } : { ...parent.options },
|
|
3616
|
+
const agentOptions = selection ? { provider: selection.provider, model: selection.model, reasoningEffort: selection.reasoningEffort } : { ...parent?.options };
|
|
3617
|
+
const options = {
|
|
3618
|
+
agentOptions,
|
|
3357
3619
|
signal: abort,
|
|
3358
3620
|
setup(child) {
|
|
3359
3621
|
child.tools.restrict({ allow: [] });
|
|
@@ -3470,14 +3732,28 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3470
3732
|
}
|
|
3471
3733
|
}));
|
|
3472
3734
|
}
|
|
3735
|
+
};
|
|
3736
|
+
const previousSessionId = job.analysisSessions?.at(-1);
|
|
3737
|
+
let handle;
|
|
3738
|
+
if (previousSessionId && !ctx.agents.get(previousSessionId)) {
|
|
3739
|
+
try {
|
|
3740
|
+
handle = await ctx.agents.resume({ ...options, resumeSessionId: previousSessionId });
|
|
3741
|
+
} catch {
|
|
3742
|
+
abort.throwIfAborted();
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
const analysis = handle ?? await ctx.agents.create({
|
|
3746
|
+
...options,
|
|
3747
|
+
sessionId: randomUUID5(),
|
|
3748
|
+
meta: { cwd: root }
|
|
3473
3749
|
});
|
|
3474
3750
|
const cancel = () => {
|
|
3475
|
-
|
|
3751
|
+
analysis.agent.cancel({ kind: "user" });
|
|
3476
3752
|
};
|
|
3477
3753
|
abort.addEventListener("abort", cancel, { once: true });
|
|
3478
3754
|
const send = (text2) => {
|
|
3479
|
-
|
|
3480
|
-
id:
|
|
3755
|
+
analysis.agent.followup({
|
|
3756
|
+
id: randomUUID5(),
|
|
3481
3757
|
role: "user",
|
|
3482
3758
|
source: { kind: "user" },
|
|
3483
3759
|
content: [{
|
|
@@ -3487,6 +3763,30 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3487
3763
|
});
|
|
3488
3764
|
};
|
|
3489
3765
|
try {
|
|
3766
|
+
abort.throwIfAborted();
|
|
3767
|
+
await onSessionReady(String(analysis.agent.session.id));
|
|
3768
|
+
abort.throwIfAborted();
|
|
3769
|
+
const previous = job.published ? await delivery.platform("/" + job.slug, appCtxId).catch(() => void 0) : void 0;
|
|
3770
|
+
const runtimeLogs = job.published ? await delivery.platform("/" + job.slug + "/logs", appCtxId).catch(() => void 0) : void 0;
|
|
3771
|
+
const rawResources = await delivery.platform("/resources", appCtxId).catch(() => ({ resources: [] }));
|
|
3772
|
+
const filteredRes = await worker({
|
|
3773
|
+
action: "filter_resources",
|
|
3774
|
+
root,
|
|
3775
|
+
resources: rawResources?.resources ?? [],
|
|
3776
|
+
slug: job.slug,
|
|
3777
|
+
default_only: true
|
|
3778
|
+
}, signal).catch(() => ({ resources: [] }));
|
|
3779
|
+
if (isRepair || previous?.error_message || previous?.build_log || runtimeLogs?.runtime_logs) {
|
|
3780
|
+
const mergedFailure = [
|
|
3781
|
+
job.failureContext,
|
|
3782
|
+
previous?.error_message,
|
|
3783
|
+
previous?.build_log?.slice(-8e3),
|
|
3784
|
+
runtimeLogs?.runtime_logs?.slice(-4e3)
|
|
3785
|
+
].filter(Boolean).join("\n");
|
|
3786
|
+
if (mergedFailure) {
|
|
3787
|
+
job.failureContext = await worker({ action: "redact_feedback", root, text: mergedFailure.slice(-24e3) }, signal);
|
|
3788
|
+
}
|
|
3789
|
+
}
|
|
3490
3790
|
abort.throwIfAborted();
|
|
3491
3791
|
let prompt = JSON.stringify({
|
|
3492
3792
|
name: job.name,
|
|
@@ -3509,7 +3809,7 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3509
3809
|
let transientError = "";
|
|
3510
3810
|
try {
|
|
3511
3811
|
send(prompt);
|
|
3512
|
-
await
|
|
3812
|
+
await analysis.agent.whenIdle();
|
|
3513
3813
|
} catch (err) {
|
|
3514
3814
|
if (signal.aborted || abort.aborted && !repeatedProposal) throw err;
|
|
3515
3815
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -3541,7 +3841,7 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3541
3841
|
}
|
|
3542
3842
|
} finally {
|
|
3543
3843
|
abort.removeEventListener("abort", cancel);
|
|
3544
|
-
await
|
|
3844
|
+
await analysis.dispose();
|
|
3545
3845
|
}
|
|
3546
3846
|
};
|
|
3547
3847
|
ctx.effect(() => () => {
|
|
@@ -3638,6 +3938,7 @@ import { z } from "zod";
|
|
|
3638
3938
|
var contribution = { package: "dsh-plugin-opc", descriptors: [
|
|
3639
3939
|
{ id: "dsh-plugin-opc#opc/appList", service: "opc", namespace: "opc", method: "appList", invocation: { kind: "direct" }, parameters: [{ name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appList:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appList:result", create: () => z.string() } },
|
|
3640
3940
|
{ id: "dsh-plugin-opc#opc/appJob", service: "opc", namespace: "opc", method: "appJob", invocation: { kind: "direct" }, parameters: [{ name: "id", wire: "id", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJob:id", create: () => z.string() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJob:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appJob:result", create: () => z.string() } },
|
|
3941
|
+
{ id: "dsh-plugin-opc#opc/appJobByAnalysisSession", service: "opc", namespace: "opc", method: "appJobByAnalysisSession", invocation: { kind: "direct" }, parameters: [{ name: "sessionId", wire: "sessionId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJobByAnalysisSession:sessionId", create: () => z.string() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appJobByAnalysisSession:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appJobByAnalysisSession:result", create: () => z.string() } },
|
|
3641
3942
|
{ id: "dsh-plugin-opc#opc/appCheckSlug", service: "opc", namespace: "opc", method: "appCheckSlug", invocation: { kind: "direct" }, parameters: [{ name: "slug", wire: "slug", source: "json", codec: { mode: "strict", typeSymbol: "opc/appCheckSlug:slug", create: () => z.string() } }, { name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appCheckSlug:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appCheckSlug:result", create: () => z.string() } },
|
|
3642
3943
|
{ id: "dsh-plugin-opc#opc/appOpcConfig", service: "opc", namespace: "opc", method: "appOpcConfig", invocation: { kind: "direct" }, parameters: [{ name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appOpcConfig:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appOpcConfig:result", create: () => z.string() } },
|
|
3643
3944
|
{ id: "dsh-plugin-opc#opc/appPickSourceFolder", service: "opc", namespace: "opc", method: "appPickSourceFolder", invocation: { kind: "direct" }, parameters: [{ name: "expectedContextId", wire: "expectedContextId", source: "json", codec: { mode: "strict", typeSymbol: "opc/appPickSourceFolder:expectedContextId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/appPickSourceFolder:result", create: () => z.string() } },
|
|
@@ -3672,6 +3973,10 @@ var contribution = { package: "dsh-plugin-opc", descriptors: [
|
|
|
3672
3973
|
{ 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() } },
|
|
3673
3974
|
{ 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() } },
|
|
3674
3975
|
{ 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() } },
|
|
3976
|
+
{ 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() } },
|
|
3977
|
+
{ 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() } },
|
|
3978
|
+
{ 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() } },
|
|
3979
|
+
{ 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() } },
|
|
3675
3980
|
{ 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() } },
|
|
3676
3981
|
{ 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() } },
|
|
3677
3982
|
{ 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() } },
|
|
@@ -3700,7 +4005,14 @@ var inject = ["credentials", "authorization", "skills", "tools", "agents", "appr
|
|
|
3700
4005
|
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) });
|
|
3701
4006
|
function apply(ctx, config) {
|
|
3702
4007
|
const key = credentialKey(name, "enterprise");
|
|
3703
|
-
const
|
|
4008
|
+
const home = config.dataHome || resolveDshHome();
|
|
4009
|
+
const configStore = new OpcConfigStore(home, {
|
|
4010
|
+
platformBaseUrl: config.platformBaseUrl,
|
|
4011
|
+
appDomainRoot: config.appDomainRoot,
|
|
4012
|
+
appDefaultPort: config.appDefaultPort
|
|
4013
|
+
});
|
|
4014
|
+
const initialConfig = configStore.loadSync();
|
|
4015
|
+
const auth = new AuthManager(new PlatformHttp(initialConfig.platform_base), {
|
|
3704
4016
|
async read() {
|
|
3705
4017
|
const record2 = await ctx.credentials.readRecord(key);
|
|
3706
4018
|
if (record2?.kind !== "grant") return void 0;
|
|
@@ -3726,8 +4038,8 @@ function apply(ctx, config) {
|
|
|
3726
4038
|
async write(id, payload) {
|
|
3727
4039
|
await ctx.credentials.modifyRecord(credentialKey(name, `app-${id}`), async () => ({ kind: "grant", payload }));
|
|
3728
4040
|
}
|
|
3729
|
-
}, { appDomainRoot:
|
|
3730
|
-
ctx.plugin(OpcRemoteService, { core, delivery });
|
|
4041
|
+
}, { appDomainRoot: initialConfig.app_domain_root, appDefaultPort: initialConfig.app_default_port });
|
|
4042
|
+
ctx.plugin(OpcRemoteService, { core, delivery, configStore });
|
|
3731
4043
|
ctx.inject(["systemPrompt"], (child) => attachAppAgent(child, delivery));
|
|
3732
4044
|
ctx.effect(() => ctx.skills.registerProvider((control) => new AppSkillProvider(delivery, control)));
|
|
3733
4045
|
registerAppTools(ctx, delivery);
|