dsh-plugin-opc 0.1.10 → 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 +472 -77
- package/lib/index.js +354 -84
- 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, _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;
|
|
@@ -1827,13 +2086,13 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1827
2086
|
async archivePublishedVersion(scopeDir, job, bundleDir) {
|
|
1828
2087
|
const { slug, version, requestId, id: jobId } = job;
|
|
1829
2088
|
if (!/^[a-z][a-z0-9-]{2,39}$/.test(slug) || !version || version <= 0) return;
|
|
1830
|
-
const verDir =
|
|
1831
|
-
await
|
|
2089
|
+
const verDir = join3(scopeDir, "versions", slug, `v${version}`);
|
|
2090
|
+
await mkdir3(verDir, { recursive: true, mode: 448 });
|
|
1832
2091
|
const hashes = {};
|
|
1833
2092
|
for (const name2 of ["app.tar", "skill.zip", "app-manifest.json", "summary.json"]) {
|
|
1834
2093
|
try {
|
|
1835
|
-
const src =
|
|
1836
|
-
await copyFile(src,
|
|
2094
|
+
const src = join3(bundleDir, name2);
|
|
2095
|
+
await copyFile(src, join3(verDir, name2));
|
|
1837
2096
|
if (name2 === "app.tar" || name2 === "skill.zip") {
|
|
1838
2097
|
hashes[name2] = hash(await readFile2(src));
|
|
1839
2098
|
}
|
|
@@ -1841,7 +2100,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1841
2100
|
}
|
|
1842
2101
|
}
|
|
1843
2102
|
if (Object.keys(hashes).length > 0) {
|
|
1844
|
-
await
|
|
2103
|
+
await writeFile3(join3(verDir, "summary.json"), JSON.stringify({ version, hashes, jobId, requestId }, null, 2), { mode: 384 }).catch(() => {
|
|
1845
2104
|
});
|
|
1846
2105
|
}
|
|
1847
2106
|
}
|
|
@@ -1899,7 +2158,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1899
2158
|
job.status = "building";
|
|
1900
2159
|
job.error = void 0;
|
|
1901
2160
|
if (job.revision && job.version) {
|
|
1902
|
-
await this.archivePublishedVersion(scope.directory, job,
|
|
2161
|
+
await this.archivePublishedVersion(scope.directory, job, join3(root, job.revision, "bundle"));
|
|
1903
2162
|
}
|
|
1904
2163
|
}
|
|
1905
2164
|
await this.save(root, job);
|
|
@@ -1991,7 +2250,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
1991
2250
|
source_label: c.source?.path ? `\u6765\u81EA\u539F\u9879\u76EE ${c.source.path}` : void 0
|
|
1992
2251
|
};
|
|
1993
2252
|
});
|
|
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 ?
|
|
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;
|
|
1995
2254
|
return {
|
|
1996
2255
|
...rest,
|
|
1997
2256
|
model: job.modelSelection?.model ?? "",
|
|
@@ -2118,7 +2377,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2118
2377
|
if (previous && previous.url !== targetUrl) throw new Error("\u91CD\u65B0\u5BFC\u5165\u987B\u4FDD\u6301\u539F\u5E94\u7528\u5730\u5740");
|
|
2119
2378
|
scope.assertCurrent();
|
|
2120
2379
|
const job = {
|
|
2121
|
-
id:
|
|
2380
|
+
id: randomUUID4(),
|
|
2122
2381
|
name: targetName,
|
|
2123
2382
|
slug: input.slug,
|
|
2124
2383
|
url: targetUrl,
|
|
@@ -2133,7 +2392,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2133
2392
|
status: "importing",
|
|
2134
2393
|
events: ["\u6B63\u5728\u521B\u5EFA\u6E90\u7801\u9694\u79BB\u526F\u672C"]
|
|
2135
2394
|
};
|
|
2136
|
-
const root =
|
|
2395
|
+
const root = join3(scope.directory, job.id);
|
|
2137
2396
|
await this.exclusive(job.id, async () => {
|
|
2138
2397
|
await this.save(root, job);
|
|
2139
2398
|
try {
|
|
@@ -2142,8 +2401,8 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2142
2401
|
if (typeof input.zip !== "string" || input.zip.length > 9e7) throw new Error("ZIP \u4E0D\u80FD\u8D85\u8FC7 64 MiB");
|
|
2143
2402
|
const bytes = Buffer.from(input.zip, "base64");
|
|
2144
2403
|
if (bytes.length > 64 * 1024 * 1024) throw new Error("ZIP \u4E0D\u80FD\u8D85\u8FC7 64 MiB");
|
|
2145
|
-
source =
|
|
2146
|
-
await
|
|
2404
|
+
source = join3(root, "uploaded.zip");
|
|
2405
|
+
await writeFile3(source, bytes, { mode: 384 });
|
|
2147
2406
|
} else {
|
|
2148
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");
|
|
2149
2408
|
source = input.source;
|
|
@@ -2245,7 +2504,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2245
2504
|
if (!resume) {
|
|
2246
2505
|
job.analysisFailure = void 0;
|
|
2247
2506
|
if (!job.proposal) {
|
|
2248
|
-
await rm2(
|
|
2507
|
+
await rm2(join3(root, "draft_files.json"), { force: true }).catch(() => {
|
|
2249
2508
|
});
|
|
2250
2509
|
}
|
|
2251
2510
|
}
|
|
@@ -2286,7 +2545,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2286
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"
|
|
2287
2546
|
);
|
|
2288
2547
|
try {
|
|
2289
|
-
await rm2(
|
|
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);
|
|
@@ -2356,7 +2615,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2356
2615
|
const scope = this.scope(expected);
|
|
2357
2616
|
const { root, job } = await this.open(scope.directory, id);
|
|
2358
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");
|
|
2359
|
-
const path =
|
|
2618
|
+
const path = join3(root, job.revision, "bundle", filename);
|
|
2360
2619
|
const size = (await stat(path)).size;
|
|
2361
2620
|
if (size > 64 * 1024 * 1024) throw new Error("\u6587\u4EF6\u8D85\u8FC7\u63D2\u4EF6\u4E0B\u8F7D\u4E0A\u9650 64 MiB");
|
|
2362
2621
|
const bytes = await readFile2(path);
|
|
@@ -2364,26 +2623,26 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2364
2623
|
if (filename !== "summary.json" && hash(bytes) !== job.hashes?.[filename]) throw new Error("\u4EA4\u4ED8\u6587\u4EF6\u5DF2\u53D1\u751F\u53D8\u5316");
|
|
2365
2624
|
return { filename: `${job.slug}-${filename}`, base64: bytes.toString("base64") };
|
|
2366
2625
|
}
|
|
2367
|
-
async saveLocalArtifact(id, filename, expected, downloads =
|
|
2626
|
+
async saveLocalArtifact(id, filename, expected, downloads = join3(homedir(), "Downloads")) {
|
|
2368
2627
|
const scope = this.scope(expected);
|
|
2369
2628
|
const { root, job } = await this.open(scope.directory, id);
|
|
2370
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");
|
|
2371
|
-
const src =
|
|
2630
|
+
const src = join3(root, job.revision, "bundle", filename);
|
|
2372
2631
|
const bytes = await readFile2(src);
|
|
2373
2632
|
scope.assertCurrent();
|
|
2374
2633
|
if (filename !== "summary.json" && hash(bytes) !== job.hashes?.[filename]) throw new Error("\u4EA4\u4ED8\u6587\u4EF6\u5DF2\u53D1\u751F\u53D8\u5316");
|
|
2375
|
-
await
|
|
2634
|
+
await mkdir3(downloads, { recursive: true, mode: 448 });
|
|
2376
2635
|
const outName = `${job.slug}-${filename}`;
|
|
2377
|
-
const temp =
|
|
2378
|
-
await
|
|
2636
|
+
const temp = join3(downloads, `.opc-${randomUUID4()}.artifact`);
|
|
2637
|
+
await writeFile3(temp, bytes, { mode: 384 });
|
|
2379
2638
|
try {
|
|
2380
|
-
const preferred =
|
|
2639
|
+
const preferred = join3(downloads, outName);
|
|
2381
2640
|
let dest = preferred;
|
|
2382
2641
|
try {
|
|
2383
2642
|
await link(temp, dest);
|
|
2384
2643
|
} catch (error) {
|
|
2385
2644
|
if (error.code !== "EEXIST") throw error;
|
|
2386
|
-
dest =
|
|
2645
|
+
dest = join3(downloads, `${randomUUID4().slice(0, 8)}-${outName}`);
|
|
2387
2646
|
await link(temp, dest);
|
|
2388
2647
|
}
|
|
2389
2648
|
return { filename: outName, path: dest };
|
|
@@ -2396,7 +2655,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2396
2655
|
const scope = this.scope(expected);
|
|
2397
2656
|
const { root, job } = await this.open(scope.directory, id);
|
|
2398
2657
|
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(
|
|
2658
|
+
const bytes = await readFile2(join3(root, job.revision, "bundle", "skill.zip"));
|
|
2400
2659
|
scope.assertCurrent();
|
|
2401
2660
|
const result = await worker({
|
|
2402
2661
|
action: "extract_skill_contract",
|
|
@@ -2470,7 +2729,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2470
2729
|
job.error = void 0;
|
|
2471
2730
|
await this.save(root, job);
|
|
2472
2731
|
try {
|
|
2473
|
-
const revision =
|
|
2732
|
+
const revision = randomUUID4().replaceAll("-", "");
|
|
2474
2733
|
const result = await worker({
|
|
2475
2734
|
action: "bundle",
|
|
2476
2735
|
root,
|
|
@@ -2501,7 +2760,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2501
2760
|
job.version = void 0;
|
|
2502
2761
|
job.published = void 0;
|
|
2503
2762
|
job.restoredVersion = void 0;
|
|
2504
|
-
job.requestId =
|
|
2763
|
+
job.requestId = randomUUID4().replaceAll("-", "");
|
|
2505
2764
|
job.confirmationToken = void 0;
|
|
2506
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");
|
|
2507
2766
|
} catch (error) {
|
|
@@ -2560,8 +2819,8 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2560
2819
|
const prior = await this.credentials.read(`confirm-${id}`);
|
|
2561
2820
|
scope.assertCurrent();
|
|
2562
2821
|
if (!job.confirmationToken || prior.digest !== digest) {
|
|
2563
|
-
job.confirmationToken =
|
|
2564
|
-
job.requestId =
|
|
2822
|
+
job.confirmationToken = randomUUID4();
|
|
2823
|
+
job.requestId = randomUUID4().replaceAll("-", "");
|
|
2565
2824
|
await this.credentials.write(`confirm-${id}`, { digest });
|
|
2566
2825
|
await this.save(root, job);
|
|
2567
2826
|
}
|
|
@@ -2580,21 +2839,21 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2580
2839
|
if (!job.confirmationToken || input.confirmationToken !== job.confirmationToken || (await this.credentials.read(`confirm-${id}`)).digest !== digest) {
|
|
2581
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");
|
|
2582
2841
|
}
|
|
2583
|
-
const requestId = job.requestId ||
|
|
2842
|
+
const requestId = job.requestId || randomUUID4().replaceAll("-", "");
|
|
2584
2843
|
job.versionNote = versionNote;
|
|
2585
2844
|
job.requestId = requestId;
|
|
2586
2845
|
job.configKeys = bindings.map((c) => c.key);
|
|
2587
2846
|
job.resourceIds = ids;
|
|
2588
2847
|
const form = new FormData(), contract = job.proposal.contract;
|
|
2589
|
-
const folder =
|
|
2848
|
+
const folder = join3(root, job.revision, "bundle");
|
|
2590
2849
|
for (const name2 of ["app.tar", "skill.zip"]) {
|
|
2591
|
-
const bytes = await readFile2(
|
|
2850
|
+
const bytes = await readFile2(join3(folder, name2));
|
|
2592
2851
|
if (hash(bytes) !== job.hashes?.[name2]) throw new Error("\u5236\u54C1\u6458\u8981\u4E0D\u4E00\u81F4\uFF0C\u62D2\u7EDD\u53D1\u5E03");
|
|
2593
2852
|
form.append(name2 === "app.tar" ? "app_tar" : "skill_zip", new Blob([new Uint8Array(bytes)]), name2);
|
|
2594
2853
|
}
|
|
2595
2854
|
let dockerfileContent = job.dockerfileContent ?? "";
|
|
2596
2855
|
if (!dockerfileContent) {
|
|
2597
|
-
dockerfileContent = await readFile2(
|
|
2856
|
+
dockerfileContent = await readFile2(join3(root, job.revision, "approved/source/Dockerfile"), "utf8").catch(() => "");
|
|
2598
2857
|
}
|
|
2599
2858
|
for (const [key, value] of Object.entries({
|
|
2600
2859
|
slug: job.slug,
|
|
@@ -2695,7 +2954,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2695
2954
|
job.published = true;
|
|
2696
2955
|
job.version = receipt.version;
|
|
2697
2956
|
job.status = "building";
|
|
2698
|
-
if (job.revision) await this.archivePublishedVersion(scope.directory, job,
|
|
2957
|
+
if (job.revision) await this.archivePublishedVersion(scope.directory, job, join3(root, job.revision, "bundle"));
|
|
2699
2958
|
await this.save(root, job);
|
|
2700
2959
|
}
|
|
2701
2960
|
const contract = job.proposal.contract;
|
|
@@ -2849,11 +3108,11 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2849
3108
|
}
|
|
2850
3109
|
return { filename, base64: result.bytes.toString("base64") };
|
|
2851
3110
|
}
|
|
2852
|
-
async saveDownload(slug, selection, expected, downloads =
|
|
3111
|
+
async saveDownload(slug, selection, expected, downloads = join3(homedir(), "Downloads")) {
|
|
2853
3112
|
const scope = this.scope(expected);
|
|
2854
3113
|
const { filename, path, query } = this.downloadTarget(slug, selection);
|
|
2855
|
-
await
|
|
2856
|
-
const temp =
|
|
3114
|
+
await mkdir3(downloads, { recursive: true, mode: 448 });
|
|
3115
|
+
const temp = join3(downloads, `.opc-${randomUUID4()}.download`);
|
|
2857
3116
|
const response = await this.platform(path, expected, { query, stream: true });
|
|
2858
3117
|
if (!response.body) throw new Error("\u5E73\u53F0\u672A\u8FD4\u56DE\u6587\u4EF6\u5185\u5BB9");
|
|
2859
3118
|
try {
|
|
@@ -2868,13 +3127,13 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2868
3127
|
const expectedHash = response.headers.get("x-artifact-sha256");
|
|
2869
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");
|
|
2870
3129
|
scope.assertCurrent();
|
|
2871
|
-
const preferred =
|
|
3130
|
+
const preferred = join3(downloads, filename);
|
|
2872
3131
|
let dest = preferred;
|
|
2873
3132
|
try {
|
|
2874
3133
|
await link(temp, dest);
|
|
2875
3134
|
} catch (error) {
|
|
2876
3135
|
if (error.code !== "EEXIST") throw error;
|
|
2877
|
-
dest =
|
|
3136
|
+
dest = join3(downloads, `${randomUUID4().slice(0, 8)}-${filename}`);
|
|
2878
3137
|
await link(temp, dest);
|
|
2879
3138
|
}
|
|
2880
3139
|
return { path: dest };
|
|
@@ -2945,7 +3204,7 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2945
3204
|
const verInfo = rbResult.version ?? {};
|
|
2946
3205
|
let expectedSkillSha = String(rbResult.skill_zip_sha256 || verInfo.skill_zip_sha256 || "").trim();
|
|
2947
3206
|
let expectedAppTarSha = String(verInfo.app_tar_sha256 || "").trim();
|
|
2948
|
-
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);
|
|
2949
3208
|
let skillZipBytes;
|
|
2950
3209
|
try {
|
|
2951
3210
|
const dl = await this.platform(`/${slug}/versions/${targetVersion}/artifacts/skill.zip`, expected);
|
|
@@ -2956,9 +3215,9 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2956
3215
|
}
|
|
2957
3216
|
} catch (error) {
|
|
2958
3217
|
if (!(error instanceof AppRequestError) || error.status !== 404) throw error;
|
|
2959
|
-
const verDir =
|
|
2960
|
-
const localFallback =
|
|
2961
|
-
if (
|
|
3218
|
+
const verDir = join3(scope.directory, "versions", slug, `v${targetVersion}`);
|
|
3219
|
+
const localFallback = join3(verDir, "skill.zip");
|
|
3220
|
+
if (existsSync2(localFallback)) {
|
|
2962
3221
|
skillZipBytes = await readFile2(localFallback).catch(() => void 0);
|
|
2963
3222
|
}
|
|
2964
3223
|
if (localMeta) {
|
|
@@ -2970,9 +3229,9 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2970
3229
|
if (!expectedSkillSha || hash(skillZipBytes) !== expectedSkillSha) {
|
|
2971
3230
|
throw new Error("\u56DE\u6EDA\u6280\u80FD\u5305\u6458\u8981\u4E0D\u4E00\u81F4\uFF0C\u62D2\u7EDD\u542F\u7528");
|
|
2972
3231
|
}
|
|
2973
|
-
const verDir =
|
|
2974
|
-
await
|
|
2975
|
-
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(() => {
|
|
2976
3235
|
});
|
|
2977
3236
|
}
|
|
2978
3237
|
const matchingJobs = [];
|
|
@@ -2987,8 +3246,8 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
2987
3246
|
}
|
|
2988
3247
|
let primary = matchingJobs.find(({ job }) => job.published && job.version === targetVersion && job.hashes?.["app.tar"] === expectedAppTarSha && job.hashes?.["skill.zip"] === expectedSkillSha);
|
|
2989
3248
|
if (!primary && skillZipBytes) {
|
|
2990
|
-
const newId =
|
|
2991
|
-
const newRoot =
|
|
3249
|
+
const newId = randomUUID4();
|
|
3250
|
+
const newRoot = join3(scope.directory, newId);
|
|
2992
3251
|
const newJob = {
|
|
2993
3252
|
id: newId,
|
|
2994
3253
|
name: current.name || slug,
|
|
@@ -3131,12 +3390,12 @@ ${trimmedFeedback.trim()}` : trimmedFeedback.trim();
|
|
|
3131
3390
|
if (job.status !== "verified") throw new Error("\u5E94\u7528\u5C1A\u672A\u901A\u8FC7\u4E1A\u52A1\u9A8C\u8BC1");
|
|
3132
3391
|
if (enabled) await this.verifiedJob(id, expected, true);
|
|
3133
3392
|
const path = this.skillPreferencePath(scope.directory, job.slug);
|
|
3134
|
-
await
|
|
3135
|
-
const temp =
|
|
3393
|
+
await mkdir3(dirname3(path), { recursive: true, mode: 448 });
|
|
3394
|
+
const temp = join3(dirname3(path), randomUUID4());
|
|
3136
3395
|
try {
|
|
3137
|
-
await
|
|
3396
|
+
await writeFile3(temp, enabled ? "enabled" : "disabled", { mode: 384 });
|
|
3138
3397
|
scope.assertCurrent();
|
|
3139
|
-
await
|
|
3398
|
+
await rename3(temp, path);
|
|
3140
3399
|
} finally {
|
|
3141
3400
|
await rm2(temp, { force: true });
|
|
3142
3401
|
}
|
|
@@ -3199,9 +3458,9 @@ ${JSON.stringify({ params, body })}`);
|
|
|
3199
3458
|
};
|
|
3200
3459
|
|
|
3201
3460
|
// src/host/app-agent.ts
|
|
3202
|
-
import { randomUUID as
|
|
3203
|
-
import { readFileSync } from "node:fs";
|
|
3204
|
-
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";
|
|
3205
3464
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3206
3465
|
import { defineTool as defineTool2 } from "@deepseek-ai/dsh-tools";
|
|
3207
3466
|
import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
@@ -3210,9 +3469,9 @@ function loadBundledSkillText(relativePath) {
|
|
|
3210
3469
|
const fromLib = fileURLToPath2(new URL(`../runtime/app_delivery/${relativePath}`, import.meta.url));
|
|
3211
3470
|
const target = import.meta.url.endsWith("/lib/index.js") ? fromLib : fromSrc;
|
|
3212
3471
|
try {
|
|
3213
|
-
return
|
|
3472
|
+
return readFileSync2(target, "utf8");
|
|
3214
3473
|
} catch {
|
|
3215
|
-
return
|
|
3474
|
+
return readFileSync2(fromSrc, "utf8");
|
|
3216
3475
|
}
|
|
3217
3476
|
}
|
|
3218
3477
|
function normalizeDisplayPath(raw) {
|
|
@@ -3344,14 +3603,14 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3344
3603
|
let repeatedProposal = false;
|
|
3345
3604
|
let draftFileChanges = [];
|
|
3346
3605
|
try {
|
|
3347
|
-
const draftsRaw = JSON.parse(
|
|
3606
|
+
const draftsRaw = JSON.parse(readFileSync2(join4(root, "draft_files.json"), "utf8"));
|
|
3348
3607
|
if (draftsRaw && typeof draftsRaw === "object") {
|
|
3349
3608
|
draftFileChanges = Object.values(draftsRaw).map((c) => ({ id: c?.id, path: c?.path, reason: c?.reason }));
|
|
3350
3609
|
}
|
|
3351
3610
|
} catch {
|
|
3352
3611
|
}
|
|
3353
3612
|
const handle = await ctx.agents.create({
|
|
3354
|
-
sessionId:
|
|
3613
|
+
sessionId: randomUUID5(),
|
|
3355
3614
|
meta: { cwd: root },
|
|
3356
3615
|
agentOptions: selection ? { provider: selection.provider, model: selection.model, reasoningEffort: selection.reasoningEffort } : { ...parent.options },
|
|
3357
3616
|
signal: abort,
|
|
@@ -3477,7 +3736,7 @@ function attachAppAgent(ctx, delivery) {
|
|
|
3477
3736
|
abort.addEventListener("abort", cancel, { once: true });
|
|
3478
3737
|
const send = (text2) => {
|
|
3479
3738
|
handle.agent.followup({
|
|
3480
|
-
id:
|
|
3739
|
+
id: randomUUID5(),
|
|
3481
3740
|
role: "user",
|
|
3482
3741
|
source: { kind: "user" },
|
|
3483
3742
|
content: [{
|
|
@@ -3672,6 +3931,10 @@ var contribution = { package: "dsh-plugin-opc", descriptors: [
|
|
|
3672
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() } },
|
|
3673
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() } },
|
|
3674
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() } },
|
|
3675
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() } },
|
|
3676
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() } },
|
|
3677
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() } },
|
|
@@ -3700,7 +3963,14 @@ var inject = ["credentials", "authorization", "skills", "tools", "agents", "appr
|
|
|
3700
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) });
|
|
3701
3964
|
function apply(ctx, config) {
|
|
3702
3965
|
const key = credentialKey(name, "enterprise");
|
|
3703
|
-
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), {
|
|
3704
3974
|
async read() {
|
|
3705
3975
|
const record2 = await ctx.credentials.readRecord(key);
|
|
3706
3976
|
if (record2?.kind !== "grant") return void 0;
|
|
@@ -3726,8 +3996,8 @@ function apply(ctx, config) {
|
|
|
3726
3996
|
async write(id, payload) {
|
|
3727
3997
|
await ctx.credentials.modifyRecord(credentialKey(name, `app-${id}`), async () => ({ kind: "grant", payload }));
|
|
3728
3998
|
}
|
|
3729
|
-
}, { appDomainRoot:
|
|
3730
|
-
ctx.plugin(OpcRemoteService, { core, delivery });
|
|
3999
|
+
}, { appDomainRoot: initialConfig.app_domain_root, appDefaultPort: initialConfig.app_default_port });
|
|
4000
|
+
ctx.plugin(OpcRemoteService, { core, delivery, configStore });
|
|
3731
4001
|
ctx.inject(["systemPrompt"], (child) => attachAppAgent(child, delivery));
|
|
3732
4002
|
ctx.effect(() => ctx.skills.registerProvider((control) => new AppSkillProvider(delivery, control)));
|
|
3733
4003
|
registerAppTools(ctx, delivery);
|