dsh-plugin-opc 0.1.30 → 0.1.32
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 +680 -154
- package/lib/index.js +122 -32
- package/package.json +1 -1
- package/runtime/app_delivery/SKILL.md +3 -3
- package/runtime/app_delivery/references/contract.md +2 -2
- package/runtime/app_delivery_admin.py +29 -3
- package/runtime/worker.py +57 -6
package/lib/index.js
CHANGED
|
@@ -259,6 +259,7 @@ var AuthManager = class extends EventEmitter {
|
|
|
259
259
|
#refresh = "";
|
|
260
260
|
#expiresAt = 0;
|
|
261
261
|
#revision = 0;
|
|
262
|
+
#sessionRequest = 0;
|
|
262
263
|
#writes = Promise.resolve();
|
|
263
264
|
#login;
|
|
264
265
|
#error;
|
|
@@ -276,24 +277,17 @@ var AuthManager = class extends EventEmitter {
|
|
|
276
277
|
});
|
|
277
278
|
return next;
|
|
278
279
|
}
|
|
279
|
-
|
|
280
|
-
if (revision !== this.#revision) throw new OpcError("CONTEXT_CHANGED");
|
|
281
|
-
const access = text(body.access_token), refresh = text(body.refresh_token);
|
|
282
|
-
if (!access || !refresh || typeof body.expires_in !== "number" || body.expires_in <= 0) throw new OpcError("INVALID_TOKEN_RESPONSE");
|
|
283
|
-
let view = body;
|
|
284
|
-
if (!text(view.subject) || !Array.isArray(view.spaces)) view = { ...body, ...check(await this.http.request("/integration/v1/session", { token: access })) };
|
|
285
|
-
if (revision !== this.#revision) throw new OpcError("CONTEXT_CHANGED");
|
|
280
|
+
sessionContext(view, old, newLogin = false) {
|
|
286
281
|
const subject = text(view.subject);
|
|
287
282
|
if (!subject || !Array.isArray(view.spaces) || !view.spaces.every((s) => typeof s === "string")) throw new OpcError("INVALID_SESSION_RESPONSE");
|
|
288
|
-
const old = this.contexts.current;
|
|
289
283
|
const spaces = view.spaces;
|
|
290
284
|
const tenant = old?.subject === subject && spaces.includes(old.tenant) ? old.tenant : spaces.includes(text(view.tenant)) ? text(view.tenant) : spaces[0] ?? "";
|
|
291
|
-
|
|
285
|
+
return {
|
|
292
286
|
issuer: this.http.base.origin,
|
|
293
287
|
subject,
|
|
294
288
|
tenant,
|
|
295
289
|
spaces,
|
|
296
|
-
generation: newLogin || !old ? this.contexts.epoch + 1 : old.generation,
|
|
290
|
+
generation: newLogin || !old ? this.contexts.epoch + 1 : old.generation + Number(old.tenant !== tenant),
|
|
297
291
|
displayName: text(view.name) || old?.displayName || "",
|
|
298
292
|
email: text(view.email) || old?.email || "",
|
|
299
293
|
spacesDetail: spaces.map((id) => {
|
|
@@ -302,6 +296,36 @@ var AuthManager = class extends EventEmitter {
|
|
|
302
296
|
return { id, name: detail && typeof detail.name === "string" ? detail.name : id };
|
|
303
297
|
})
|
|
304
298
|
};
|
|
299
|
+
}
|
|
300
|
+
async syncSession() {
|
|
301
|
+
const revision = this.#revision;
|
|
302
|
+
const request = ++this.#sessionRequest;
|
|
303
|
+
const token = await this.token();
|
|
304
|
+
const isCurrent = () => revision === this.#revision && request === this.#sessionRequest && token === this.#access;
|
|
305
|
+
if (!isCurrent()) throw new OpcError("CONTEXT_CHANGED");
|
|
306
|
+
const response = await this.http.request("/integration/v1/session", { token });
|
|
307
|
+
if (!isCurrent()) throw new OpcError("CONTEXT_CHANGED");
|
|
308
|
+
if (response.status === 401 || ["SESSION_REVOKED", "SUBJECT_NOT_PROVISIONED"].includes(text(response.body.error?.code))) {
|
|
309
|
+
await this.invalidateSession();
|
|
310
|
+
}
|
|
311
|
+
const view = check(response);
|
|
312
|
+
const current = this.contexts.current;
|
|
313
|
+
if (!current || view.subject !== current.subject) throw new OpcError("INVALID_SESSION_RESPONSE");
|
|
314
|
+
const updated = this.sessionContext(view, current);
|
|
315
|
+
if (JSON.stringify(current) !== JSON.stringify(updated)) {
|
|
316
|
+
this.contexts.replace(updated);
|
|
317
|
+
this.changed();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
async accept(body, revision, newLogin = false) {
|
|
321
|
+
if (revision !== this.#revision) throw new OpcError("CONTEXT_CHANGED");
|
|
322
|
+
const access = text(body.access_token), refresh = text(body.refresh_token);
|
|
323
|
+
if (!access || !refresh || typeof body.expires_in !== "number" || body.expires_in <= 0) throw new OpcError("INVALID_TOKEN_RESPONSE");
|
|
324
|
+
let view = body;
|
|
325
|
+
if (!text(view.subject) || !Array.isArray(view.spaces)) view = { ...body, ...check(await this.http.request("/integration/v1/session", { token: access })) };
|
|
326
|
+
if (revision !== this.#revision) throw new OpcError("CONTEXT_CHANGED");
|
|
327
|
+
const old = this.contexts.current;
|
|
328
|
+
const context = this.sessionContext(view, old, newLogin);
|
|
305
329
|
try {
|
|
306
330
|
await this.persist(async () => {
|
|
307
331
|
if (revision !== this.#revision) throw new OpcError("CONTEXT_CHANGED");
|
|
@@ -343,7 +367,7 @@ var AuthManager = class extends EventEmitter {
|
|
|
343
367
|
try {
|
|
344
368
|
return await this.accept(check(await this.http.request("/integration/v1/auth/refresh", { body: { refresh_token: this.#refresh, client_id: this.clientId, device: this.device } })), revision);
|
|
345
369
|
} catch (error) {
|
|
346
|
-
if (revision === this.#revision && error instanceof OpcError && ["REFRESH_REUSE_DETECTED", "SESSION_REVOKED"].includes(error.code)) await this.clear();
|
|
370
|
+
if (revision === this.#revision && error instanceof OpcError && ["REFRESH_REUSE_DETECTED", "SESSION_REVOKED", "SUBJECT_NOT_PROVISIONED"].includes(error.code)) await this.clear();
|
|
347
371
|
throw error;
|
|
348
372
|
}
|
|
349
373
|
}
|
|
@@ -1501,8 +1525,8 @@ async function pickSourceFolder(platform2 = process.platform, exec = execFileAsy
|
|
|
1501
1525
|
}
|
|
1502
1526
|
return { cancelled: true, unsupported: true };
|
|
1503
1527
|
}
|
|
1504
|
-
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;
|
|
1505
|
-
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) {
|
|
1528
|
+
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, _syncSession_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;
|
|
1529
|
+
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], _syncSession_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) {
|
|
1506
1530
|
constructor(ctx, options) {
|
|
1507
1531
|
super(ctx, "opc");
|
|
1508
1532
|
__runInitializers(_init, 5, this);
|
|
@@ -1760,6 +1784,9 @@ var OpcRemoteService = class extends (_a = TypertRemoteService, _appList_dec = [
|
|
|
1760
1784
|
async logout() {
|
|
1761
1785
|
await this.core.auth.logout();
|
|
1762
1786
|
}
|
|
1787
|
+
async syncSession() {
|
|
1788
|
+
await this.core.auth.syncSession();
|
|
1789
|
+
}
|
|
1763
1790
|
async switchTenant(tenantId) {
|
|
1764
1791
|
this.core.auth.switchTenant(tenantId);
|
|
1765
1792
|
}
|
|
@@ -1882,6 +1909,7 @@ __decorateElement(_init, 1, "watchState", _watchState_dec, OpcRemoteService);
|
|
|
1882
1909
|
__decorateElement(_init, 1, "startLogin", _startLogin_dec, OpcRemoteService);
|
|
1883
1910
|
__decorateElement(_init, 1, "cancelLogin", _cancelLogin_dec, OpcRemoteService);
|
|
1884
1911
|
__decorateElement(_init, 1, "logout", _logout_dec, OpcRemoteService);
|
|
1912
|
+
__decorateElement(_init, 1, "syncSession", _syncSession_dec, OpcRemoteService);
|
|
1885
1913
|
__decorateElement(_init, 1, "switchTenant", _switchTenant_dec, OpcRemoteService);
|
|
1886
1914
|
__decorateElement(_init, 1, "listKnowledgeBases", _listKnowledgeBases_dec, OpcRemoteService);
|
|
1887
1915
|
__decorateElement(_init, 1, "listSkillsCatalog", _listSkillsCatalog_dec, OpcRemoteService);
|
|
@@ -2399,12 +2427,23 @@ async function resolvePythonInterpreter(options = {}) {
|
|
|
2399
2427
|
// src/host/app-delivery.ts
|
|
2400
2428
|
var ROLLBACK_NOTICE = "\u56DE\u6EDA\u6062\u590D\u4EE3\u7801\u4E0E\u8FD0\u884C\u914D\u7F6E\uFF0C\u4E0D\u81EA\u52A8\u56DE\u9000\u6570\u636E\u5E93/\u5377\u4E2D\u7684\u4E1A\u52A1\u6570\u636E\uFF1B\u65E7\u4EE3\u7801\u548C\u65B0\u6570\u636E\u517C\u5BB9\u6027\u4ECD\u9700\u9A8C\u8BC1\u3002";
|
|
2401
2429
|
function analysisQuestions(proposal) {
|
|
2402
|
-
const pendingAccount = proposal?.adminAccountPending ? [`\u8BF7${proposal?.contract?.admin_account?.mode === "create" ? "\u8BBE\u7F6E" : "\u586B\u5199\u5DF2\u6709\u7684"}\u7BA1\u7406\u5458\u8D26\u53F7\u548C\u5BC6\u7801\uFF0C\u76F4\u63A5\u5728\u5F53\u524D\u5BF9\u8BDD\
|
|
2430
|
+
const pendingAccount = proposal?.adminAccountPending ? [`\u8BF7${proposal?.contract?.admin_account?.mode === "create" ? "\u8BBE\u7F6E" : "\u586B\u5199\u5DF2\u6709\u7684"}\u7BA1\u7406\u5458\u8D26\u53F7\u548C\u5BC6\u7801\uFF0C\u76F4\u63A5\u5728\u5F53\u524D\u5BF9\u8BDD\u56DE\u590D\u300C\u8D26\u53F7\uFF1A\u2026\u300D\u548C\u300C\u5BC6\u7801\uFF1A\u2026\u300D\uFF08\u53EF\u5206\u4E24\u884C\u6216\u540C\u884C\u7528\u7A7A\u683C\u9694\u5F00\uFF09\u3002`] : [];
|
|
2403
2431
|
return [.../* @__PURE__ */ new Set([...pendingAccount, ...proposal?.unresolved ?? [], ...proposal?.contract?.unresolved ?? []])];
|
|
2404
2432
|
}
|
|
2405
2433
|
function readAdminReply(plan, text3) {
|
|
2406
|
-
|
|
2407
|
-
|
|
2434
|
+
let username = text3.match(/^\s*(?:[-*•]\s*)?(?:账号|帐号|用户名|username)\s*[::=]\s*([^\r\n]+)$/im)?.[1]?.trim();
|
|
2435
|
+
let password = text3.match(/^\s*(?:[-*•]\s*)?(?:密码|password)\s*[::=]\s*([^\r\n]+)$/im)?.[1]?.trim();
|
|
2436
|
+
if (!username || !password) {
|
|
2437
|
+
const userFirst = text3.match(/(?:^|[\s,,;;])(?:账号|帐号|用户名|username)\s*[::=]\s*([^\r\n]+?)[\s,,;;]+(?:密码|password)\s*[::=]\s*([^\r\n]+)/i);
|
|
2438
|
+
const passFirst = userFirst ? void 0 : text3.match(/(?:^|[\s,,;;])(?:密码|password)\s*[::=]\s*([^\r\n]+?)[\s,,;;]+(?:账号|帐号|用户名|username)\s*[::=]\s*([^\r\n]+)/i);
|
|
2439
|
+
if (userFirst) {
|
|
2440
|
+
username = userFirst[1].replace(/[,,;;]+$/, "").trim();
|
|
2441
|
+
password = userFirst[2].trim();
|
|
2442
|
+
} else if (passFirst) {
|
|
2443
|
+
password = passFirst[1].replace(/[,,;;]+$/, "").trim();
|
|
2444
|
+
username = passFirst[2].trim();
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2408
2447
|
if (!username || !password || username.length > 4096 || password.length > 4096 || /\0/.test(username + password)) return void 0;
|
|
2409
2448
|
return { profile: plan.profile, mode: plan.mode, username, password };
|
|
2410
2449
|
}
|
|
@@ -2454,6 +2493,17 @@ function loopbackConnection(key, value) {
|
|
|
2454
2493
|
}
|
|
2455
2494
|
return /(?:^|:\/\/|@|tcp\(|(?:host|server)\s*=)(?:localhost|127\.\d+\.\d+\.\d+|\[::1\])(?=[:/,;)]|$)/i.test(value.trim());
|
|
2456
2495
|
}
|
|
2496
|
+
function isExampleConfigPath(relPath) {
|
|
2497
|
+
const normalized = relPath.replace(/\\/g, "/");
|
|
2498
|
+
const base = normalized.slice(normalized.lastIndexOf("/") + 1).toLowerCase();
|
|
2499
|
+
const dot = base.lastIndexOf(".");
|
|
2500
|
+
const stem = dot > 0 ? base.slice(0, dot) : base;
|
|
2501
|
+
const suffixRe = /(?:^|[._-])(?:example|sample|template)$/;
|
|
2502
|
+
return suffixRe.test(base) || suffixRe.test(stem);
|
|
2503
|
+
}
|
|
2504
|
+
function isSensitiveConfigKey(key) {
|
|
2505
|
+
return /password|passwd|secret|token|credential|api.?key|private.?key|dsn|connection.?string/i.test(key);
|
|
2506
|
+
}
|
|
2457
2507
|
var hash = (value) => createHash5("sha256").update(value).digest("hex");
|
|
2458
2508
|
var fingerprint = (value) => hash(JSON.stringify(value));
|
|
2459
2509
|
function contains(actual, expected) {
|
|
@@ -2870,15 +2920,19 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2870
2920
|
const hasOrigSet = new Set(job.hasOriginalKeys ?? []);
|
|
2871
2921
|
const runtimeConfigs = (proposal?.contract?.configs ?? []).map((c) => {
|
|
2872
2922
|
const hasOrig = hasOrigSet.has(c.key) && Boolean(c.source);
|
|
2923
|
+
const isExample = typeof c.source?.path === "string" && isExampleConfigPath(c.source.path);
|
|
2873
2924
|
return {
|
|
2874
2925
|
key: c.key,
|
|
2875
2926
|
value: c.secret ? "" : c.default ?? "",
|
|
2927
|
+
app_default: c.secret ? "" : typeof c.app_default === "string" ? c.app_default : "",
|
|
2876
2928
|
description: c.description ?? "",
|
|
2877
2929
|
required: Boolean(c.required),
|
|
2878
2930
|
secret: Boolean(c.secret),
|
|
2879
2931
|
has_value: hasOrig || Boolean(c.default),
|
|
2932
|
+
has_original_value: hasOrig,
|
|
2933
|
+
...isExample ? { is_example_source: true } : {},
|
|
2880
2934
|
value_source: hasOrig ? "original" : "manual",
|
|
2881
|
-
source_label: c.source?.path ?
|
|
2935
|
+
source_label: c.source?.path ? `${isExample ? "\u793A\u4F8B\u6A21\u677F\u53C2\u8003" : "\u6765\u81EA\u539F\u9879\u76EE"} ${c.source.path}` : void 0
|
|
2882
2936
|
};
|
|
2883
2937
|
});
|
|
2884
2938
|
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;
|
|
@@ -2987,7 +3041,8 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
2987
3041
|
let targetUrl;
|
|
2988
3042
|
let targetName = input.name.trim();
|
|
2989
3043
|
const defaultPort = Number.isInteger(this.options.appDefaultPort) && this.options.appDefaultPort >= 1 && this.options.appDefaultPort <= 65535 ? this.options.appDefaultPort : 8080;
|
|
2990
|
-
|
|
3044
|
+
const portAuto = input.container_port === void 0;
|
|
3045
|
+
let targetPort = portAuto ? defaultPort : input.container_port;
|
|
2991
3046
|
if (!Number.isInteger(targetPort) || targetPort < 1 || targetPort > 65535) throw new Error("\u5BB9\u5668\u7AEF\u53E3\u5FC5\u987B\u4E3A 1 \u81F3 65535 \u7684\u6574\u6570");
|
|
2992
3047
|
let targetDesc = typeof input.description === "string" ? input.description.trim() : "";
|
|
2993
3048
|
let defaultVersionNote = "";
|
|
@@ -3019,6 +3074,7 @@ ${combinedLog}` : combinedLog).slice(-24e3);
|
|
|
3019
3074
|
slug: input.slug,
|
|
3020
3075
|
url: targetUrl,
|
|
3021
3076
|
port: targetPort,
|
|
3077
|
+
portAuto,
|
|
3022
3078
|
description: targetDesc,
|
|
3023
3079
|
upgrade: isUpgrade,
|
|
3024
3080
|
versionNote: defaultVersionNote,
|
|
@@ -3274,10 +3330,16 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
|
|
|
3274
3330
|
if (job.status !== "ready") return null;
|
|
3275
3331
|
const sourceConfiguration = await worker({ action: "source_configuration", root }, scope.signal);
|
|
3276
3332
|
const values = job.configDraft ? await this.credentials.read(`draft-${id}`) : {};
|
|
3333
|
+
const origAll = await this.credentials.read(`orig-${id}`);
|
|
3277
3334
|
scope.assertCurrent();
|
|
3335
|
+
const secretKeys = new Set((job.proposal?.contract?.configs ?? []).filter((c) => c.secret).map((c) => c.key));
|
|
3336
|
+
const originalValues = Object.fromEntries(
|
|
3337
|
+
Object.entries(origAll).filter(([k, v]) => !secretKeys.has(k) && !isSensitiveConfigKey(k) && typeof v === "string")
|
|
3338
|
+
);
|
|
3278
3339
|
return {
|
|
3279
3340
|
...job.configDraft,
|
|
3280
3341
|
rows: (job.configDraft?.rows ?? []).map((row) => ({ ...row, value: values[row.key] ?? "" })),
|
|
3342
|
+
originalValues,
|
|
3281
3343
|
sourceConfiguration
|
|
3282
3344
|
};
|
|
3283
3345
|
}
|
|
@@ -3292,7 +3354,13 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
|
|
|
3292
3354
|
scope.assertCurrent();
|
|
3293
3355
|
job.configDraft = {
|
|
3294
3356
|
artifactHash: input.artifactHash,
|
|
3295
|
-
rows: rows.map((row) => ({
|
|
3357
|
+
rows: rows.map((row) => ({
|
|
3358
|
+
key: row.key,
|
|
3359
|
+
resource_id: row.resource_id,
|
|
3360
|
+
local_connection_confirmed: row.local_connection_confirmed === true,
|
|
3361
|
+
...row.value_source === "original" || row.value_source === "manual" || row.value_source === "resource" ? { value_source: row.value_source } : {},
|
|
3362
|
+
...row.secret === true ? { secret: true } : {}
|
|
3363
|
+
})),
|
|
3296
3364
|
storageBindings: readStorageBindings(input.storageBindings),
|
|
3297
3365
|
versionNote: typeof input.versionNote === "string" ? input.versionNote.slice(0, 1024) : ""
|
|
3298
3366
|
};
|
|
@@ -3393,9 +3461,13 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
|
|
|
3393
3461
|
const expectedPort = job.port ?? 8080;
|
|
3394
3462
|
const actualPort = proposal.contract.runtime?.port;
|
|
3395
3463
|
const field = "\u4EA4\u4ED8\u5951\u7EA6 runtime.port";
|
|
3396
|
-
if (actualPort == null)
|
|
3397
|
-
|
|
3398
|
-
|
|
3464
|
+
if (actualPort == null) {
|
|
3465
|
+
throw new Error(job.portAuto ? `${field} \u7F3A\u5931\u3002\u8BF7\u8865\u5168 runtime.port\uFF081\u201365535 \u6574\u6570\uFF0C\u4F18\u5148\u586B\u5E94\u7528\u9ED8\u8BA4\u7AEF\u53E3\uFF0C\u65E0\u9ED8\u8BA4\u7AEF\u53E3\u65F6\u586B ${expectedPort}\uFF09` : `${field} \u7F3A\u5931\u3002\u8BF7\u8865\u5168 runtime \u5E76\u586B\u5199\u5DF2\u9501\u5B9A\u7684\u6570\u5B57 ${expectedPort}`);
|
|
3466
|
+
}
|
|
3467
|
+
if (!Number.isInteger(actualPort) || actualPort < 1 || actualPort > 65535) {
|
|
3468
|
+
throw new Error(`${field} \u5FC5\u987B\u662F 1 \u81F3 65535 \u7684\u6574\u6570`);
|
|
3469
|
+
}
|
|
3470
|
+
if (!job.portAuto && actualPort !== expectedPort) throw new Error(`${field} \u586B\u4E86 ${actualPort}\uFF0C\u4E0E\u5DF2\u9501\u5B9A\u7684\u5BB9\u5668\u7AEF\u53E3 ${expectedPort} \u4E0D\u4E00\u81F4\u3002\u6A21\u578B\u4E0D\u80FD\u9759\u9ED8\u6539\u53D8\u7528\u6237\u9009\u62E9\u7684\u5BB9\u5668\u7AEF\u53E3`);
|
|
3399
3471
|
}
|
|
3400
3472
|
const validated = await worker({
|
|
3401
3473
|
action: "validate",
|
|
@@ -3409,11 +3481,15 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
|
|
|
3409
3481
|
failure_feedback: job.failureContext ?? "",
|
|
3410
3482
|
revision_count: job.revisionCount ?? 1,
|
|
3411
3483
|
feedback: job.feedbackHistory ?? "",
|
|
3412
|
-
expected_port: job.port ?? 8080
|
|
3484
|
+
expected_port: job.portAuto ? null : job.port ?? 8080
|
|
3413
3485
|
}, signal);
|
|
3414
3486
|
signal.throwIfAborted();
|
|
3415
3487
|
if (job.status !== "analyzing") throw new Error("\u672C\u8F6E\u5DF2\u63D0\u4EA4\u65B9\u6848");
|
|
3416
3488
|
job.proposal = validated?.proposal ?? proposal;
|
|
3489
|
+
const validatedPort = job.proposal?.contract?.runtime?.port;
|
|
3490
|
+
if (job.portAuto && Number.isInteger(validatedPort) && validatedPort >= 1 && validatedPort <= 65535) {
|
|
3491
|
+
job.port = validatedPort;
|
|
3492
|
+
}
|
|
3417
3493
|
if (adminAccountPending) job.proposal.adminAccountPending = true;
|
|
3418
3494
|
else delete job.proposal.adminAccountPending;
|
|
3419
3495
|
job.discoveryReport = validated?.discovery_report ?? job.discoveryReport;
|
|
@@ -3456,7 +3532,7 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
|
|
|
3456
3532
|
repair: Boolean(job.failedRevision),
|
|
3457
3533
|
failed_revision: job.failedRevision ?? "",
|
|
3458
3534
|
failure_feedback: job.failureContext ?? "",
|
|
3459
|
-
expected_port: job.port ?? 8080,
|
|
3535
|
+
expected_port: job.portAuto ? null : job.port ?? 8080,
|
|
3460
3536
|
revision_count: job.revisionCount ?? 1,
|
|
3461
3537
|
feedback: job.feedbackHistory ?? ""
|
|
3462
3538
|
}, signal);
|
|
@@ -3465,6 +3541,10 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
|
|
|
3465
3541
|
job.revision = revision;
|
|
3466
3542
|
job.hashes = result.summary.files;
|
|
3467
3543
|
job.proposal = result.proposal ?? job.proposal;
|
|
3544
|
+
const bundledPort = job.proposal?.contract?.runtime?.port;
|
|
3545
|
+
if (Number.isInteger(bundledPort) && bundledPort >= 1 && bundledPort <= 65535) {
|
|
3546
|
+
job.port = bundledPort;
|
|
3547
|
+
}
|
|
3468
3548
|
job.discoveryReport = result.discovery_report ?? job.discoveryReport;
|
|
3469
3549
|
job.transformationReport = result.transformation_report ?? job.transformationReport;
|
|
3470
3550
|
job.preparationChecks = result.preparation_checks ?? job.preparationChecks;
|
|
@@ -3518,7 +3598,7 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
|
|
|
3518
3598
|
if (!Array.isArray(rawConfigs) || rawConfigs.some((c) => !c || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(c.key) || typeof c.value !== "string" || c.resource_id !== void 0 && typeof c.resource_id !== "string") || new Set(rawConfigs.map((c) => c.key)).size !== rawConfigs.length) throw new Error("\u914D\u7F6E\u683C\u5F0F\u65E0\u6548");
|
|
3519
3599
|
const origValues = await this.credentials.read(`orig-${job.id}`);
|
|
3520
3600
|
const configs = rawConfigs.map((c) => {
|
|
3521
|
-
if (!c.resource_id && !c.value && origValues[c.key]) return { ...c, value: origValues[c.key], value_source: "original" };
|
|
3601
|
+
if (!c.resource_id && !c.value && c.value_source !== "manual" && origValues[c.key]) return { ...c, value: origValues[c.key], value_source: "original" };
|
|
3522
3602
|
return { ...c, value_source: c.resource_id ? "resource" : "manual" };
|
|
3523
3603
|
});
|
|
3524
3604
|
const storageBindings = readStorageBindings(input.storageBindings);
|
|
@@ -3567,7 +3647,7 @@ ${trimmedFeedback}` : trimmedFeedback || prevFailure).slice(-24e3);
|
|
|
3567
3647
|
for (const c of declarations) {
|
|
3568
3648
|
const selected = configs.find((i) => i.key === c.key);
|
|
3569
3649
|
const preservedOnlineSecret = Boolean((job.upgrade || job.published) && selected?.has_value);
|
|
3570
|
-
if (c.required && c.key !== "PORT" && !selected?.value && !selected?.resource_id && !preservedOnlineSecret) throw new Error(`\
|
|
3650
|
+
if (c.required && c.key !== "PORT" && !selected?.value && !selected?.resource_id && !preservedOnlineSecret) throw new Error(`\u8BF7\u586B\u5199\u5FC5\u586B\u914D\u7F6E ${c.key}\uFF0C\u6216\u9009\u62E9\u5339\u914D\u7684\u5E73\u53F0\u6258\u7BA1\u8D44\u6E90\u3002`);
|
|
3571
3651
|
}
|
|
3572
3652
|
const bindings = configs.map((c) => ({
|
|
3573
3653
|
key: c.key,
|
|
@@ -4315,7 +4395,7 @@ var objects = { type: "array", items: object2 };
|
|
|
4315
4395
|
var routeAuth = { ...object2, properties: {
|
|
4316
4396
|
evidence: { ...strings, description: "\u8BE5\u8DEF\u7531\u7684\u8BA4\u8BC1\u6E90\u7801\u4F4D\u7F6E\uFF0C\u4F7F\u7528\u6E90\u7801\u8BFB\u53D6\u5DE5\u5177\u8FD4\u56DE\u7684\u6587\u4EF6\u8DEF\u5F84\u548C\u884C\u53F7" }
|
|
4317
4397
|
} };
|
|
4318
|
-
function proposalParameters(port) {
|
|
4398
|
+
function proposalParameters(port, portLocked = true) {
|
|
4319
4399
|
return {
|
|
4320
4400
|
summary: { ...str, description: "\u4E2D\u6587\u6539\u9020\u6458\u8981\uFF1B\u4F7F\u7528\u7ED3\u6784\u5316\u53C2\u6570\u65F6\u5FC5\u586B" },
|
|
4321
4401
|
issues: { ...objects, items: { ...object2, properties: {
|
|
@@ -4342,16 +4422,21 @@ function proposalParameters(port) {
|
|
|
4342
4422
|
runtime: { ...object2, required: true, properties: {
|
|
4343
4423
|
language: text2,
|
|
4344
4424
|
version: text2,
|
|
4345
|
-
port: {
|
|
4425
|
+
port: {
|
|
4426
|
+
type: "integer",
|
|
4427
|
+
required: true,
|
|
4428
|
+
description: portLocked ? `\u5FC5\u987B\u662F\u5411\u5BFC\u5DF2\u9501\u5B9A\u7684\u6570\u5B57 ${port}\uFF0C\u4E0D\u662F\u5B57\u7B26\u4E32\u6216\u5BBF\u4E3B\u673A\u7AEF\u53E3` : `\u4F18\u5148\u586B\u5199\u5E94\u7528\u81EA\u8EAB\u9ED8\u8BA4\u76D1\u542C\u7AEF\u53E3\uFF08\u6574\u6570 1-65535\uFF09\uFF1B\u82E5\u5E94\u7528\u65E0\u9ED8\u8BA4\u7AEF\u53E3\uFF0C\u586B\u5199 OPC \u9ED8\u8BA4\u7AEF\u53E3 ${port}`
|
|
4429
|
+
}
|
|
4346
4430
|
} },
|
|
4347
4431
|
build_context: { ...strings, required: true },
|
|
4348
4432
|
health: { ...object2, required: true, properties: { path: text2, status: { type: "integer", required: true }, json_contains: { ...object2, required: true } } },
|
|
4349
|
-
configs: { ...objects, description: '\u4EC5\u586B\u5199\u6E90\u7801\u771F\u5B9E\u5B58\u5728\u7684\u914D\u7F6E\u952E\uFF08\u53C2\u8003 inventory.source_configuration\uFF09\uFF1Bdefault \u5FC5\u987B\u4E3A\u7A7A\u5B57\u7B26\u4E32 ""\uFF1Bsource \u4EC5\u652F\u6301 YAML/JSON/TOML/.env/properties \u6587\u4EF6\uFF0C\u4E0D\u652F\u6301\u4EE3\u7801\u6587\u4EF6', items: { ...object2, properties: {
|
|
4433
|
+
configs: { ...objects, description: '\u4EC5\u586B\u5199\u6E90\u7801\u771F\u5B9E\u5B58\u5728\u7684\u914D\u7F6E\u952E\uFF08\u53C2\u8003 inventory.source_configuration\uFF09\uFF1Bdefault \u5FC5\u987B\u4E3A\u7A7A\u5B57\u7B26\u4E32 ""\uFF1Bsource \u4EC5\u652F\u6301 YAML/JSON/TOML/.env/properties \u6587\u4EF6\uFF0C\u4E0D\u652F\u6301\u4EE3\u7801\u6587\u4EF6\uFF1B\u4E0D\u8981\u5C06 *.example/*.sample/*.template \u793A\u4F8B\u6587\u4EF6\u91CC\u7684 PORT \u6216\u5360\u4F4D\u5BC6\u94A5\u4F5C\u4E3A\u771F\u5B9E\u8FD0\u884C\u503C\u7ED1\u5B9A\uFF1B\u5982\u5E94\u7528\u5B58\u5728\u4EE3\u7801\u515C\u5E95\u9ED8\u8BA4\u503C\uFF08\u4EC5\u975E\u654F\u611F\uFF09\uFF0C\u53EF\u5199\u5165 app_default \u4F9B\u7B2C 3 \u6B65\u53C2\u8003\u5C55\u793A', items: { ...object2, properties: {
|
|
4350
4434
|
key: text2,
|
|
4351
4435
|
default: text2,
|
|
4352
4436
|
secret: { ...bool, required: true },
|
|
4353
4437
|
required: { ...bool, required: true },
|
|
4354
4438
|
description: str,
|
|
4439
|
+
app_default: { ...str, description: "\u4EC5\u975E\u654F\u611F\u914D\u7F6E\u53EF\u586B\u5199\u6E90\u7801\u4E2D\u7684\u515C\u5E95\u9ED8\u8BA4\u503C\uFF08\u53EA\u8BFB\u5C55\u793A\u53C2\u8003\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u6CE8\u5165\uFF09" },
|
|
4355
4440
|
source: { ...object2, description: "\u4F7F\u7528 path \u548C keys \u5F15\u7528\u6E90\u914D\u7F6E\uFF0C\u7981\u6B62\u5199\u5165\u771F\u5B9E\u79D8\u5BC6\u503C" }
|
|
4356
4441
|
} } },
|
|
4357
4442
|
resources: objects,
|
|
@@ -4371,7 +4456,7 @@ function proposalParameters(port) {
|
|
|
4371
4456
|
mode: { ...text2, enum: ["existing", "create"] },
|
|
4372
4457
|
profile: text2,
|
|
4373
4458
|
evidence: strings,
|
|
4374
|
-
source: { ...object2, description: "\u5DF2\u6709\u53EF\u590D\u7528\u660E\u6587\u7684 {username,password} \u5F15\u7528\uFF1A\u7ED3\u6784\u5316\u914D\u7F6E {path,keys}\u3001\u6E90\u7801\u5E38\u91CF {path,line,name} \u6216 SQLite \u660E\u6587\u5B57\u6BB5 {path,table,column,where}\u3002\u7F3A\u4EFB\u4F55\u4E00\u9879\u5219\u7701\u7565 source\u3002" },
|
|
4459
|
+
source: { ...object2, description: "\u5DF2\u6709\u53EF\u590D\u7528\u660E\u6587\u7684 {username,password} \u5F15\u7528\uFF1A\u7ED3\u6784\u5316\u914D\u7F6E {path,keys}\u3001\u6E90\u7801\u5E38\u91CF/\u5BF9\u8C61\u5C5E\u6027/\u9ED8\u8BA4\u503C/\u54C8\u5E0C\u51FD\u6570\u5B57\u7B26\u4E32\u5B57\u9762\u91CF\u53C2\u6570 {path,line,name} \u6216 SQLite \u660E\u6587\u5B57\u6BB5 {path,table,column,where}\u3002\u7F3A\u4EFB\u4F55\u4E00\u9879\u5219\u7701\u7565 source\u3002" },
|
|
4375
4460
|
storage: { ...object2, description: "\u9996\u6B21\u5EFA\u53F7\u4EC5\u5728\u4EA4\u4ED8\u526F\u672C\u4E2D\u5199\u5165\u5E94\u7528\u771F\u6B63\u8BFB\u53D6\u7684 SQLite \u6216 JSON/YAML \u6587\u4EF6\uFF0C\u5177\u4F53\u7ED3\u6784\u89C1 references/contract.md\u3002" }
|
|
4376
4461
|
} },
|
|
4377
4462
|
auth_rules: { ...objects, description: '\u6BCF\u6761\u89C4\u5219\u987B\u4E8C\u9009\u4E00\u586B\u5199 path \u6216 prefix\uFF1Bevidence \u662F\u89C4\u5219\u9876\u5C42\u5FC5\u586B\u6570\u7EC4\uFF08\u4E0E auth \u5E73\u7EA7\uFF0C\u4E0D\u8981\u653E\u5728 auth \u5185\u90E8\uFF09\uFF1B\u540C\u6743\u9650\u9875\u9762\u53EF\u7528 target="page" \u4E14 prefix="/" \u7EDF\u4E00\u8986\u76D6', items: { ...object2, properties: {
|
|
@@ -4508,10 +4593,12 @@ function attachAppAgent(ctx, delivery) {
|
|
|
4508
4593
|
const appCtxId = delivery.core.auth.contexts.applicationContextId;
|
|
4509
4594
|
const isRepair = Boolean(job.failedRevision || job.failedSnapshot || job.failureContext || job.analysisMode === "repair");
|
|
4510
4595
|
const port = job.port ?? 8080;
|
|
4596
|
+
const portLocked = job.portAuto !== true;
|
|
4511
4597
|
const skill = loadBundledSkillText("SKILL.md");
|
|
4512
4598
|
const repairInstructions = isRepair ? "\n\u4FEE\u590D\u5931\u8D25\u90E8\u7F72\u65F6\uFF0C\u5148\u6838\u5BF9\u5931\u8D25\u9636\u6BB5\u548C\u65E5\u5FD7\uFF0C\u7528 read_failed \u8BFB\u53D6\u5B9E\u9645\u5931\u8D25\u5236\u54C1\u5E76\u4E0E\u539F\u6E90\u7801\u6BD4\u5BF9\u3002\u53EA\u4FEE\u6B63\u6839\u56E0\uFF0C\u63D0\u4EA4\u5B8C\u6574\u66FF\u6362\u6587\u4EF6\u3002" : "";
|
|
4599
|
+
const portInstructions = portLocked ? `\u672C\u4EFB\u52A1\u9501\u5B9A\u7684\u5BB9\u5668\u7AEF\u53E3\u4E3A ${port}\u3002` : `\u5BB9\u5668\u7AEF\u53E3\u7B56\u7565\uFF1A\u4F18\u5148\u8BC6\u522B\u5E76\u6CBF\u7528\u5E94\u7528\u81EA\u8EAB\u9ED8\u8BA4\u76D1\u542C\u7AEF\u53E3\uFF08\u4ECE\u6E90\u7801\u3001\u73B0\u6709 Dockerfile \u6216\u771F\u5B9E\u914D\u7F6E\u6587\u4EF6\u6838\u5B9E\uFF09\uFF1B\u82E5\u5E94\u7528\u65E0\u9ED8\u8BA4\u7AEF\u53E3\uFF08\u6216\u4F9D\u8D56\u5916\u90E8\u6CE8\u5165 PORT \u4E14\u65E0\u515C\u5E95\u503C\uFF09\uFF0C\u5219\u4F7F\u7528 OPC \u9ED8\u8BA4\u7AEF\u53E3 ${port}\u3002${job.upgrade ? `\u672C\u6B21\u4E3A\u5347\u7EA7\u90E8\u7F72\uFF0C\u5982\u65B0\u7248\u672A\u53D8\u66F4\u7AEF\u53E3\u4F18\u5148\u6CBF\u7528\u7EBF\u4E0A\u5F53\u524D\u7AEF\u53E3 ${port}\u3002` : ""}\u5BB9\u5668\u5185\u5FC5\u987B\u76D1\u542C 0.0.0.0\uFF08\u7981\u6B62\u76D1\u542C 127.0.0.1\uFF09\uFF0C\u4E14\u5951\u7EA6 configs \u4E2D\u7684 PORT \u5FC5\u987B\u4E0E runtime.port \u4E00\u81F4\uFF0C\u4E0D\u8981\u5F15\u7528 *.example \u793A\u4F8B\u6587\u4EF6\u4E2D\u51B2\u7A81\u7684 PORT \u6216\u5360\u4F4D\u5BC6\u94A5\u3002`;
|
|
4513
4600
|
const instructions = `${skill}
|
|
4514
|
-
|
|
4601
|
+
${portInstructions}${repairInstructions}`;
|
|
4515
4602
|
const prevPlan = compactPreviousPlan(job.proposal);
|
|
4516
4603
|
const taskInstruction = "\u6309\u56DB\u6B65\u5B8C\u6210\u672C\u6B21\u5E94\u7528\u6539\u9020\u3002" + (isRepair ? "\u5148\u7528\u5931\u8D25\u5236\u54C1\u6838\u5B9E\u6839\u56E0\u3002" : prevPlan && feedback.trim() ? "\u7ED3\u5408\u7528\u6237\u8865\u5145\u590D\u6838\u4E0A\u4E00\u7248\u65B9\u6848\u3002" : "");
|
|
4517
4604
|
const timeout = new AbortController();
|
|
@@ -4625,7 +4712,7 @@ function attachAppAgent(ctx, delivery) {
|
|
|
4625
4712
|
child.tools.register(defineTool2({
|
|
4626
4713
|
name: "opc_delivery_submit",
|
|
4627
4714
|
description: "\u4EE5\u7ED3\u6784\u5316\u5B57\u6BB5\u63D0\u4EA4\u5B8C\u6574\u6539\u9020\u63D0\u6848\u3002\u82E5\u5DF2\u6682\u5B58\u6587\u4EF6\uFF0Cchanges \u53EF\u4EC5\u4F20 {id, path, reason, group}\u3002\u65E7\u7248\u53EF\u7528 proposal JSON \u5B57\u7B26\u4E32\u3002",
|
|
4628
|
-
parameters: proposalParameters(port),
|
|
4715
|
+
parameters: proposalParameters(port, portLocked),
|
|
4629
4716
|
output,
|
|
4630
4717
|
async execute(args) {
|
|
4631
4718
|
if (job.status !== "analyzing") throw new Error("\u672C\u8F6E\u5DF2\u63D0\u4EA4\u65B9\u6848");
|
|
@@ -4759,6 +4846,8 @@ ${questions.join("\n")}` : "\u5B8C\u6574\u65B9\u6848\u5DF2\u901A\u8FC7\u6821\u9A
|
|
|
4759
4846
|
slug: job.slug,
|
|
4760
4847
|
base_url: job.url,
|
|
4761
4848
|
container_port: port,
|
|
4849
|
+
port_policy: portLocked ? "locked" : "prefer_app_default_else_opc_default",
|
|
4850
|
+
default_container_port: port,
|
|
4762
4851
|
upgrade: Boolean(job.upgrade),
|
|
4763
4852
|
deployed_baseline: deployedBaseline,
|
|
4764
4853
|
available_resource_metadata: (filteredRes?.resources ?? []).map((resource) => ({
|
|
@@ -5007,6 +5096,7 @@ var contribution = { package: "dsh-plugin-opc", descriptors: [
|
|
|
5007
5096
|
{ 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() } },
|
|
5008
5097
|
{ id: "dsh-plugin-opc#opc/cancelLogin", service: "opc", namespace: "opc", method: "cancelLogin", invocation: { kind: "direct" }, parameters: [], result: { mode: "strict", typeSymbol: "opc/cancelLogin:result", create: () => z.void() } },
|
|
5009
5098
|
{ id: "dsh-plugin-opc#opc/logout", service: "opc", namespace: "opc", method: "logout", invocation: { kind: "direct" }, parameters: [], result: { mode: "strict", typeSymbol: "opc/logout:result", create: () => z.void() } },
|
|
5099
|
+
{ id: "dsh-plugin-opc#opc/syncSession", service: "opc", namespace: "opc", method: "syncSession", invocation: { kind: "direct" }, parameters: [], result: { mode: "strict", typeSymbol: "opc/syncSession:result", create: () => z.void() } },
|
|
5010
5100
|
{ id: "dsh-plugin-opc#opc/switchTenant", service: "opc", namespace: "opc", method: "switchTenant", invocation: { kind: "direct" }, parameters: [{ name: "tenantId", wire: "tenantId", source: "json", codec: { mode: "strict", typeSymbol: "opc/switchTenant:tenantId", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/switchTenant:result", create: () => z.void() } },
|
|
5011
5101
|
{ id: "dsh-plugin-opc#opc/listKnowledgeBases", service: "opc", namespace: "opc", method: "listKnowledgeBases", invocation: { kind: "direct" }, parameters: [{ name: "q", wire: "q", source: "json", codec: { mode: "strict", typeSymbol: "opc/listKnowledgeBases:q", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/listKnowledgeBases:result", create: () => z.string() } },
|
|
5012
5102
|
{ id: "dsh-plugin-opc#opc/listSkillsCatalog", service: "opc", namespace: "opc", method: "listSkillsCatalog", invocation: { kind: "direct" }, parameters: [{ name: "q", wire: "q", source: "json", codec: { mode: "strict", typeSymbol: "opc/listSkillsCatalog:q", create: () => z.string() } }], result: { mode: "strict", typeSymbol: "opc/listSkillsCatalog:result", create: () => z.string() } },
|
package/package.json
CHANGED
|
@@ -19,8 +19,8 @@ metadata:
|
|
|
19
19
|
|
|
20
20
|
## 2. 决定并实施改造
|
|
21
21
|
|
|
22
|
-
- 现有 Dockerfile 可用就沿用;缺失时按语言和版本查 `template`,只新增根目录 `Dockerfile`。保留真实启动命令和依赖,只在现有代码中修正已证实的监听和启动问题。平台使用应用原有入口探测,禁止新增健康检查接口、健康包装脚本或相关变量。每项改动说明原文件证据和部署影响。
|
|
23
|
-
- 沿用原配置文件和值。契约 `configs`
|
|
22
|
+
- 现有 Dockerfile 可用就沿用;缺失时按语言和版本查 `template`,只新增根目录 `Dockerfile`。`runtime.port` 优先沿用应用自身默认端口;应用无默认端口或依赖外部注入 `PORT` 且无兜底时使用任务给出的 OPC 默认端口。容器内服务须监听 `0.0.0.0`。保留真实启动命令和依赖,只在现有代码中修正已证实的监听和启动问题。平台使用应用原有入口探测,禁止新增健康检查接口、健康包装脚本或相关变量。每项改动说明原文件证据和部署影响。
|
|
23
|
+
- 沿用原配置文件和值。契约 `configs` 仅引用原应用可证实的键和来源,`default` 留空;`*.example` / `*.sample` / `*.template` 等示例文件仅作参考模板,不要绑定与 `runtime.port` 冲突的 `PORT` 或占位密钥,源码兜底的非敏感默认值可写入 `app_default`。禁止自行增加或替换环境变量、配置文件、模板、包装脚本、管理员初始化脚本、说明文件或依赖。确需补充时写入待确认事项,等用户在应用源工程处理后重新导入。
|
|
24
24
|
- SQLite、JSON、上传等本地文件使用持久化卷,SQLite 挂载整个数据目录(含 WAL/SHM),使用工具的快照。升级复用原卷。库表变化优先只增不删,涉及删除、改名或影响回滚时列为待确认事项。
|
|
25
25
|
- 远端数据库先沿用原连接,在部署后验证可达性。若源码连的是用户电脑上的数据库实例,暂停并请用户联系运维申请同引擎的企业数据库,由运维迁移后更新连接,再继续部署。真正与应用运行在同一容器内的依赖可以保留 loopback。
|
|
26
26
|
- 用户电脑上的 Redis、MQ 等按用途判断是否要迁数据。纯缓存可重建,持久状态、队列积压或需要保留的业务数据须先核对迁移。用平台资源元数据确认可用服务;由用户决定目标并更新应用原配置。需要迁数据的,说明数据范围、目标与验收条件,等授权迁移完成再继续。只有宿主提供并实际执行了受支持的迁移工具,才能报告已迁移。
|
|
@@ -37,4 +37,4 @@ metadata:
|
|
|
37
37
|
|
|
38
38
|
- 汇总分析依据、必要改造及技能验收范围。连接地址、数据迁移、缺失的账号等需要用户决定时,写入 `unresolved`,提示具体影响并等待用户确认。收到答复后只修订相关项。已有部署沿用应用原账号。
|
|
39
39
|
- 用 `opc_delivery_propose_file` 暂存允许的文件,再用 `opc_delivery_submit` 提交 `summary`、`changes`、`contract` 和 `unresolved`。按需查阅 `contract.md`。校验失败时按具体规则修复;源应用缺少必要配置或文件时请用户补齐。
|
|
40
|
-
-
|
|
40
|
+
- 待确认项处理完且提案通过后,由插件生成交付包。用户可在第 3 步核对或按需调整运行时环境变量、差异、应用技能与持久化挂载,再主动确认发布。分析结果只说明实际准备和校验到的阶段。
|
|
@@ -46,8 +46,8 @@ Work 自动技术准备记录 `kind: ai-technical`、`scope: deployment-adaptati
|
|
|
46
46
|
|
|
47
47
|
- URL 由用户在分析前确定,与 prepare 输入严格一致;不含凭据、路径前缀、query 或 fragment。内网 HTTP/HTTPS 按目标环境选择,不绑定 Cloudflare。
|
|
48
48
|
- build_context 是应用文件/目录白名单,包含真实锁文件、构建与运行资产,以及应用需要的原配置(包括 `.env`)、JSON、SQLite、账户与业务数据。由本机原样复制,不因含凭据而拒绝;不含 VCS、无关原 ZIP 或分析报告。业务技能内的管理员账密按 `admin_account` 规则由打包器写入。业务数据和其他秘密保留在原存储或运行时配置中,模型输出只引用位置。
|
|
49
|
-
- `configs` 只声明确有需要的原应用配置,键必须能在导入源码中找到。文件配置通过 `source: {"path":"config.yaml","keys":["service","url"]}`
|
|
50
|
-
- `secret` 和 `required` 为布尔值,`key` 唯一,`default`
|
|
49
|
+
- `configs` 只声明确有需要的原应用配置,键必须能在导入源码中找到。文件配置通过 `source: {"path":"config.yaml","keys":["service","url"]}` 引用原值;沿用原配置及读取方式;`*.example` / `*.sample` / `*.template` 仅作模板参考,勿绑定与 `runtime.port` 冲突的 `PORT` 或占位密钥。容器端口 `runtime.port` 优先沿用应用默认端口,无默认端口时使用 OPC 默认端口。
|
|
50
|
+
- `secret` 和 `required` 为布尔值,`key` 唯一,`default` 留空;非敏感源码兜底默认值可填写在 `app_default` 供第 3 步参考展示(不自动注入)。常见凭据字段(如 API_KEY、PASSWORD、TOKEN、DSN)标为秘密。第 3 步允许用户在发布前核对或修改运行时环境变量。
|
|
51
51
|
- 最终 `apis` / `pages` 收录应用实际部署的接口、页面与业务视图,至少一个数组非空。DSH 提交时可用 `[]` 或只补充、覆盖扫描项,插件合并完整清单。纯页面应用填写浏览器验证计划。
|
|
52
52
|
- 每个 API 必须含 purpose、源码 evidence、实际 parameters/request_body/responses、auth、effect。request_body 为 null 或包含 required、description、schema 的对象;完整 schema 与错误说明应保留,工具不声称完整实现 JSON Schema 验证。API 错误可能包含 HTTP 200 下的业务错误码,业务流程必须明确成功判断,不把 HTTP 成功等同业务成功。
|
|
53
53
|
- auth.type 为 none、bearer 或 header;非 none 必须声明 env 环境变量名或引用 auth_profiles 中的 profile,header 还要提供 header。原始账号密码不要填入契约,由打包器写进生成应用技能的 `SKILL.md`。其他密钥和令牌沿用运行时引用。
|
|
@@ -23,6 +23,32 @@ def sql_name(name):
|
|
|
23
23
|
return '"' + name + '"'
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
_STRING_LITERAL = r'"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\''
|
|
27
|
+
_LITERAL_TAIL = r'\s*(?:[,;]\s*)?(?:(?://|#).*)?$'
|
|
28
|
+
_LITERAL_EXTRACTORS = (
|
|
29
|
+
re.compile(rf"^(?P<lit>{_STRING_LITERAL}){_LITERAL_TAIL}"),
|
|
30
|
+
re.compile(rf"(?:\|\||\?\?|\bor\b)\s*(?P<lit>{_STRING_LITERAL}){_LITERAL_TAIL}"),
|
|
31
|
+
re.compile(rf"^[A-Za-z_][A-Za-z0-9_.]*(?:getenv|get)\(\s*(?:{_STRING_LITERAL})\s*,\s*(?P<lit>{_STRING_LITERAL})\s*\){_LITERAL_TAIL}"),
|
|
32
|
+
re.compile(rf"^[A-Za-z_][A-Za-z0-9_.]*\(\s*(?P<lit>{_STRING_LITERAL})\s*\){_LITERAL_TAIL}"),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _extract_literal_rhs(line, name):
|
|
37
|
+
escaped = re.escape(name)
|
|
38
|
+
match = (
|
|
39
|
+
re.fullmatch(r"\s*(?:export\s+)?(?:(?:const|let|var)\s+)?" + escaped + r"\s*(?::\s*[^=]+)?=\s*(.+?)\s*", line)
|
|
40
|
+
or re.fullmatch(r"\s*(?:[\"'])?" + escaped + r"(?:[\"'])?\s*:\s*(.+?)\s*", line)
|
|
41
|
+
)
|
|
42
|
+
if not match:
|
|
43
|
+
return None
|
|
44
|
+
rhs = match[1]
|
|
45
|
+
for pattern in _LITERAL_EXTRACTORS:
|
|
46
|
+
lit_match = pattern.search(rhs)
|
|
47
|
+
if lit_match:
|
|
48
|
+
return lit_match.group("lit")
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
|
|
26
52
|
def original_account_field(source, reference):
|
|
27
53
|
if "keys" in reference:
|
|
28
54
|
return original_value(source, reference)
|
|
@@ -40,10 +66,10 @@ def original_account_field(source, reference):
|
|
|
40
66
|
line_number, name = reference.get("line"), reference.get("name")
|
|
41
67
|
lines = (d.text_of(path) or "").splitlines()
|
|
42
68
|
d.require(type(line_number) is int and 1 <= line_number <= len(lines) and isinstance(name, str), "原始账号常量位置无效")
|
|
43
|
-
|
|
44
|
-
d.require(bool(
|
|
69
|
+
lit = _extract_literal_rhs(lines[line_number - 1], name)
|
|
70
|
+
d.require(bool(lit), "原始账号引用必须指向一个明确的字符串常量")
|
|
45
71
|
try:
|
|
46
|
-
value = ast.literal_eval(
|
|
72
|
+
value = ast.literal_eval(lit)
|
|
47
73
|
except (ValueError, SyntaxError):
|
|
48
74
|
raise ValueError("原始账号引用必须指向一个明确的字符串常量") from None
|
|
49
75
|
d.require(isinstance(value, str), "原始账号引用必须指向字符串")
|
package/runtime/worker.py
CHANGED
|
@@ -40,6 +40,19 @@ def _fingerprint(value) -> str:
|
|
|
40
40
|
return hashlib.sha256(json.dumps(value, sort_keys=True, ensure_ascii=False).encode("utf-8")).hexdigest()
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
SENSITIVE_KEY_RE = re.compile(r"password|passwd|secret|token|credential|api.?key|private.?key|dsn|connection.?string", re.I)
|
|
44
|
+
PLACEHOLDER_VALUE_RE = re.compile(r"(?i)^(?:<[^>]+>|\$\{[^}]+\}|your[-_\s].*|changeme|replace[-_\s]?me|example[-_\s]?.*|dummy[-_\s]?.*|todo[-_\s]?.*|xxx+|placeholder)$")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def is_example_config_path(rel_path: str) -> bool:
|
|
48
|
+
name = Path(rel_path).name.lower()
|
|
49
|
+
stem = Path(rel_path).stem.lower()
|
|
50
|
+
return bool(
|
|
51
|
+
re.search(r"(?:^|[._-])(?:example|sample|template)$", name)
|
|
52
|
+
or re.search(r"(?:^|[._-])(?:example|sample|template)$", stem)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
43
56
|
def redact(text: str, name: str = "") -> str:
|
|
44
57
|
hidden = set(d.secret_lines(text, name))
|
|
45
58
|
config = Path(name).suffix.lower() in {".yaml", ".yml", ".ini", ".toml", ".properties"} or Path(name).name.startswith(".env")
|
|
@@ -194,8 +207,13 @@ def resolve_and_enrich_proposal(
|
|
|
194
207
|
discovery_report = None
|
|
195
208
|
transformation_report = None
|
|
196
209
|
contract = proposal.get("contract")
|
|
197
|
-
if
|
|
198
|
-
|
|
210
|
+
if not (proposal.get("unresolved") or (isinstance(contract, dict) and contract.get("unresolved"))):
|
|
211
|
+
runtime = contract.get("runtime") if isinstance(contract, dict) else None
|
|
212
|
+
runtime_port = runtime.get("port") if isinstance(runtime, dict) else None
|
|
213
|
+
if type(runtime_port) is not int or not (1 <= runtime_port <= 65535):
|
|
214
|
+
raise ValueError("交付契约 runtime.port 必须是 1 至 65535 的整数")
|
|
215
|
+
if expected_port is not None and runtime_port != expected_port:
|
|
216
|
+
raise ValueError("模型不能静默改变用户选择的容器端口")
|
|
199
217
|
if isinstance(contract, dict) and source.is_dir():
|
|
200
218
|
job_meta = {
|
|
201
219
|
"slug": contract.get("slug", ""),
|
|
@@ -249,6 +267,15 @@ def resolve_and_enrich_proposal(
|
|
|
249
267
|
errors.append("配置必须声明 secret、required 和字符串默认值")
|
|
250
268
|
elif config["secret"] and config.get("default"):
|
|
251
269
|
errors.append(f"秘密配置 {config['key']} 不能包含默认值。原值仅通过 source 引用。")
|
|
270
|
+
if "app_default" in config and config["app_default"] is not None:
|
|
271
|
+
if not isinstance(config["app_default"], str):
|
|
272
|
+
errors.append("配置项 app_default 必须是字符串")
|
|
273
|
+
elif config["app_default"] and (
|
|
274
|
+
config.get("secret") is True
|
|
275
|
+
or SENSITIVE_KEY_RE.search(config["key"])
|
|
276
|
+
or d.secret_lines(f"{config['key']}={config['app_default']}", ".env")
|
|
277
|
+
):
|
|
278
|
+
errors.append(f"敏感配置 {config['key']} 不能填写 app_default")
|
|
252
279
|
if config.get("source") is not None:
|
|
253
280
|
try:
|
|
254
281
|
original_value(source, config["source"])
|
|
@@ -357,6 +384,17 @@ def extract_original_config_values(source: Path, configs: list[dict]) -> tuple[d
|
|
|
357
384
|
if isinstance(cfg, dict) and cfg.get("source"):
|
|
358
385
|
try:
|
|
359
386
|
val = original_value(source, cfg["source"])
|
|
387
|
+
src_path = str(cfg["source"].get("path", ""))
|
|
388
|
+
if is_example_config_path(src_path):
|
|
389
|
+
if cfg.get("key") == "PORT":
|
|
390
|
+
continue
|
|
391
|
+
if (
|
|
392
|
+
cfg.get("secret")
|
|
393
|
+
or SENSITIVE_KEY_RE.search(str(cfg.get("key", "")))
|
|
394
|
+
or PLACEHOLDER_VALUE_RE.match(val.strip())
|
|
395
|
+
or d.secret_lines(f"{cfg.get('key')}={val}", src_path)
|
|
396
|
+
):
|
|
397
|
+
continue
|
|
360
398
|
if val:
|
|
361
399
|
values[cfg["key"]] = val
|
|
362
400
|
has_original_keys.append(cfg["key"])
|
|
@@ -487,11 +525,14 @@ def source_configuration(root: Path, origins=None) -> dict:
|
|
|
487
525
|
continue
|
|
488
526
|
except ValueError:
|
|
489
527
|
continue
|
|
490
|
-
sensitive =
|
|
528
|
+
sensitive = SENSITIVE_KEY_RE.search(key)
|
|
491
529
|
if value and (sensitive or d.secret_lines(json.dumps(key) + ": " + json.dumps(value), name)):
|
|
492
530
|
value = "[REDACTED]"
|
|
493
531
|
fields.append({"key": key, "value": value})
|
|
494
|
-
|
|
532
|
+
entry = {"path": name, "fields": fields}
|
|
533
|
+
if is_example_config_path(name):
|
|
534
|
+
entry["is_example"] = True
|
|
535
|
+
files.append(entry)
|
|
495
536
|
if suffix in ENV_REFERENCE_SUFFIXES or path.name == "Dockerfile":
|
|
496
537
|
references.update(environment_references(path, source_text(path) or ""))
|
|
497
538
|
return {"files": files, "references": sorted(references - generated_keys)}
|
|
@@ -505,6 +546,7 @@ def validate_config_origins(root: Path, contract: dict):
|
|
|
505
546
|
origins = historical_config_origins(root, source)
|
|
506
547
|
generated_keys, _ = origins
|
|
507
548
|
references = set(source_configuration(root, origins)["references"])
|
|
549
|
+
runtime_port = (contract.get("runtime") or {}).get("port") if isinstance(contract.get("runtime"), dict) else None
|
|
508
550
|
errors = []
|
|
509
551
|
for config in configs:
|
|
510
552
|
key = config["key"]
|
|
@@ -514,11 +556,16 @@ def validate_config_origins(root: Path, contract: dict):
|
|
|
514
556
|
original_key = False
|
|
515
557
|
if ref is not None:
|
|
516
558
|
try:
|
|
517
|
-
original_value(source, ref)
|
|
559
|
+
val = original_value(source, ref)
|
|
518
560
|
original_key = ref["keys"][-1] == key
|
|
519
561
|
except ValueError as exc:
|
|
520
562
|
errors.append(str(exc))
|
|
521
563
|
continue
|
|
564
|
+
if key == "PORT" and type(runtime_port) is int and val.strip() and val.strip() != str(runtime_port):
|
|
565
|
+
errors.append(
|
|
566
|
+
f"配置项 PORT 引用的 {ref['path']} 值为 {val.strip()},与契约容器端口 {runtime_port} 不一致。"
|
|
567
|
+
"请优先将 runtime.port 改为应用实际默认端口,或移除示例文件对 PORT 的 source 引用"
|
|
568
|
+
)
|
|
522
569
|
if key in generated_keys or not (original_key or key in references):
|
|
523
570
|
errors.append("原应用没有可核实的配置键:" + key)
|
|
524
571
|
if errors:
|
|
@@ -597,7 +644,11 @@ def main(body):
|
|
|
597
644
|
cfg = source_configuration(root)
|
|
598
645
|
result["source_configuration"] = {
|
|
599
646
|
"config_files": [
|
|
600
|
-
{
|
|
647
|
+
{
|
|
648
|
+
"path": f["path"],
|
|
649
|
+
"keys": [field["key"] for field in f.get("fields", [])],
|
|
650
|
+
**({"is_example": True} if f.get("is_example") else {}),
|
|
651
|
+
}
|
|
601
652
|
for f in cfg.get("files", [])
|
|
602
653
|
],
|
|
603
654
|
"env_references": cfg.get("references", []),
|