@evomap/evolver-proxy 2.0.37 → 2.0.39
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/dist/bin/evolver-proxy.d.ts +2 -0
- package/dist/bin/evolver-proxy.js +15 -2
- package/dist/daemon/proxyDaemon.d.ts +6 -0
- package/dist/daemon/proxyDaemon.js +232 -55
- package/dist/daemon/publishBindingLedger.d.ts +17 -0
- package/dist/daemon/publishBindingLedger.js +79 -0
- package/dist/daemon/recipeExecution.d.ts +6 -0
- package/dist/daemon/recipeExecution.js +38 -0
- package/dist/lifecycle/claimNudge.js +1 -1
- package/dist/lifecycle/deployGuard.js +1 -1
- package/dist/lifecycle/legacyNodeId.js +1 -1
- package/dist/lifecycle/manager.d.ts +6 -0
- package/dist/lifecycle/manager.js +1 -1
- package/dist/llm/bodyCapture.js +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/server.js +1 -1
- package/dist/llm/traceBackfill.js +1 -1
- package/dist/llm/traceConfig.js +1 -1
- package/dist/llm/traceControl.js +1 -1
- package/dist/llm/traceEnvelope.js +1 -1
- package/dist/llm/traceSink.js +1 -1
- package/dist/llm/traceUploadPayload.js +1 -1
- package/dist/llm/upstream.js +1 -1
- package/dist/router/cachePassthrough.js +1 -1
- package/dist/router/features.js +1 -1
- package/dist/router/index.js +1 -1
- package/dist/router/messagesRoute.js +1 -1
- package/dist/router/modelRouter.js +1 -1
- package/dist/router/providerRoutes.js +1 -1
- package/dist/router/sseScan.js +1 -1
- package/dist/sync/engine.js +1 -1
- package/package.json +3 -3
|
@@ -106,6 +106,8 @@ export declare function createVerifiedPublicSender(initialNodeId?: string): Veri
|
|
|
106
106
|
export declare function adoptVerifiedPublicNodeId(store: mailbox.MailboxStore, selection: PublicNodeSecretSelection, sender: VerifiedPublicSender, nodeId: string): void;
|
|
107
107
|
export interface HubRuntime {
|
|
108
108
|
hub: ProxyDaemonDeps['hub'];
|
|
109
|
+
/** Identity used by this connected runtime, including explicit credential overrides not yet persisted to the store. */
|
|
110
|
+
currentNodeId?: () => string | undefined;
|
|
109
111
|
hello: (opts: {
|
|
110
112
|
rotate: boolean;
|
|
111
113
|
evolverVersion?: string;
|
|
@@ -662,6 +662,7 @@ export function createProxyDaemonDeps(options) {
|
|
|
662
662
|
const hubAuthFailurePolicy = resolveHubAuthFailurePolicy(env);
|
|
663
663
|
return {
|
|
664
664
|
hub: options.runtime.hub,
|
|
665
|
+
...(options.runtime.currentNodeId ? { currentNodeId: options.runtime.currentNodeId } : {}),
|
|
665
666
|
...(options.hubMode ? { hubMode: options.hubMode } : {}),
|
|
666
667
|
store: options.store,
|
|
667
668
|
ipcToken: options.ipcToken,
|
|
@@ -703,7 +704,14 @@ function resolveNativePublishExecutionVerifier(env) {
|
|
|
703
704
|
const configuredRoot = env['EVOLVER_PUBLISH_VALIDATION_ROOT']?.trim();
|
|
704
705
|
if (!configuredRoot)
|
|
705
706
|
return undefined;
|
|
706
|
-
|
|
707
|
+
let validationRoot;
|
|
708
|
+
try {
|
|
709
|
+
validationRoot = realpathSync(resolve(configuredRoot));
|
|
710
|
+
}
|
|
711
|
+
catch {
|
|
712
|
+
return undefined;
|
|
713
|
+
}
|
|
714
|
+
const rootFingerprint = hubNs.publishBindingDigest('publish-validation-root.v1', validationRoot);
|
|
707
715
|
return async (input, signal) => {
|
|
708
716
|
const commands = Array.isArray(input.validation)
|
|
709
717
|
? input.validation.filter((value) => typeof value === 'string').map((value) => value.trim()).filter(Boolean)
|
|
@@ -715,7 +723,9 @@ function resolveNativePublishExecutionVerifier(env) {
|
|
|
715
723
|
|| commands.some((command) => command.length > 180
|
|
716
724
|
|| !verify.isValidationCommandAllowed(command)
|
|
717
725
|
|| verify.sanitizeExecutionCommand(command).blocked)
|
|
718
|
-
|| signal.aborted
|
|
726
|
+
|| signal.aborted
|
|
727
|
+
|| !hubNs.isPublishVerificationRequest(input['verification_request'])
|
|
728
|
+
|| input['verification_request'].validationDigest !== hubNs.publishBindingDigest('publish-validation.v1', commands))
|
|
719
729
|
return null;
|
|
720
730
|
const result = await verify.runSandboxedValidation(commands, validationRoot, {
|
|
721
731
|
requireIsolation: true,
|
|
@@ -724,6 +734,7 @@ function resolveNativePublishExecutionVerifier(env) {
|
|
|
724
734
|
if (signal.aborted || !result.passed || result.results.length !== commands.length)
|
|
725
735
|
return null;
|
|
726
736
|
return {
|
|
737
|
+
binding: { request: structuredClone(input['verification_request']), rootFingerprint },
|
|
727
738
|
validation: commands,
|
|
728
739
|
trace: result.results.map((row) => ({
|
|
729
740
|
command: row.cmd,
|
|
@@ -1210,6 +1221,7 @@ export async function connectHubRuntime(deps) {
|
|
|
1210
1221
|
});
|
|
1211
1222
|
return {
|
|
1212
1223
|
hub: runtime.hub,
|
|
1224
|
+
currentNodeId: deps.senderId,
|
|
1213
1225
|
hello: runtime.hello,
|
|
1214
1226
|
heartbeat: (opts) => runtime.hub.heartbeat(opts),
|
|
1215
1227
|
helloMode: 'enterprise_token',
|
|
@@ -1254,6 +1266,7 @@ export async function connectHubRuntime(deps) {
|
|
|
1254
1266
|
}));
|
|
1255
1267
|
return {
|
|
1256
1268
|
hub,
|
|
1269
|
+
currentNodeId: senderId,
|
|
1257
1270
|
atp: new AtpHubClient({ baseUrl: deps.hubUrl, auth, fetchFn: globalFetchLike, senderId }),
|
|
1258
1271
|
hello,
|
|
1259
1272
|
heartbeat: (opts) => hub.heartbeat(opts),
|
|
@@ -11,12 +11,15 @@ export declare const DEFAULT_IPC_PORT = 19820;
|
|
|
11
11
|
export type HubAuthFailurePolicy = 'deny' | 'warn';
|
|
12
12
|
export declare function resolveHubAuthFailurePolicy(env?: Record<string, string | undefined>): HubAuthFailurePolicy;
|
|
13
13
|
export interface ProxyDaemonDeps {
|
|
14
|
+
recipeExecutionDirectory?: string;
|
|
14
15
|
/** operator配置,不能由单次搜索请求关闭。 */
|
|
15
16
|
benchmarkId?: string;
|
|
16
17
|
sourceProvenance?: assetstore.ProvenanceStore;
|
|
17
18
|
/** benchmark自定义provider必须接入审核账本;缺账本不等于Gene没有审核记录。 */
|
|
18
19
|
sourceReview?: assetstore.ReviewLedger;
|
|
19
20
|
hub: HubCapability;
|
|
21
|
+
/** Identity actually presented by the connected Hub runtime; terminal lifecycle state is scoped to it. */
|
|
22
|
+
currentNodeId?: () => string | undefined;
|
|
20
23
|
/** Immutable Hub selection for IPC callers that must fail closed across public/private runtimes. */
|
|
21
24
|
hubMode?: 'public' | 'private';
|
|
22
25
|
/** 二选一: 传 storePath 让 ProxyDaemon 建 store, 或传已建 store(供 hub senderId 共享同一 node_id). */
|
|
@@ -165,6 +168,7 @@ export declare class ProxyDaemon {
|
|
|
165
168
|
private readonly publishRecallVerifier;
|
|
166
169
|
private readonly proxyHandler;
|
|
167
170
|
private readonly hub;
|
|
171
|
+
private readonly recipeGovernance;
|
|
168
172
|
private readonly recipeComposeStarted;
|
|
169
173
|
private ipc;
|
|
170
174
|
private readonly now;
|
|
@@ -175,6 +179,7 @@ export declare class ProxyDaemon {
|
|
|
175
179
|
private readonly assetSubmitResponseTimeoutMs;
|
|
176
180
|
private readonly hubAuthFailurePolicy;
|
|
177
181
|
private readonly synchronousAssetSubmitScope;
|
|
182
|
+
private readonly publishBindingLedger;
|
|
178
183
|
private readonly shadowMode;
|
|
179
184
|
private readonly assetSearchCache;
|
|
180
185
|
private readonly assetSearchInflight;
|
|
@@ -257,6 +262,7 @@ export declare class ProxyDaemon {
|
|
|
257
262
|
private qualifyAssets;
|
|
258
263
|
private respondAssetSearch;
|
|
259
264
|
private qualifyFetch;
|
|
265
|
+
private recallAssets;
|
|
260
266
|
private localFetchAssets;
|
|
261
267
|
private handleProxyRoute;
|
|
262
268
|
private searchAssets;
|
|
@@ -7,8 +7,10 @@ import { LifecycleManager } from '../lifecycle/manager.js';
|
|
|
7
7
|
import { executeForceUpdate } from '../selfUpdate/executor.js';
|
|
8
8
|
import { reportPendingSelfUpdateLastUpdate, reportSelfUpdateLastUpdate } from '../selfUpdate/lastUpdate.js';
|
|
9
9
|
import { backfillProxyTraceUploads } from '../llm/traceBackfill.js';
|
|
10
|
+
import { invokeRecipeIpc, recipeIpcScope } from './recipeExecution.js';
|
|
10
11
|
import { hubAuthFailureHint } from './selectHub.js';
|
|
11
12
|
import { CollaborationFacade } from './collaborationFacade.js';
|
|
13
|
+
import { PublishBindingLedger } from './publishBindingLedger.js';
|
|
12
14
|
import { PublishRecallVerifier, resolvePublishRecallConfig, } from './publishRecallVerifier.js';
|
|
13
15
|
const DEFAULT_PUBLISH_EXECUTION_VERIFY_TIMEOUT_MS = 30_000;
|
|
14
16
|
export const DEFAULT_IPC_PORT = 19820;
|
|
@@ -102,6 +104,7 @@ export class ProxyDaemon {
|
|
|
102
104
|
publishRecallVerifier;
|
|
103
105
|
proxyHandler;
|
|
104
106
|
hub;
|
|
107
|
+
recipeGovernance;
|
|
105
108
|
recipeComposeStarted = new Set();
|
|
106
109
|
ipc;
|
|
107
110
|
now;
|
|
@@ -112,6 +115,7 @@ export class ProxyDaemon {
|
|
|
112
115
|
assetSubmitResponseTimeoutMs;
|
|
113
116
|
hubAuthFailurePolicy;
|
|
114
117
|
synchronousAssetSubmitScope;
|
|
118
|
+
publishBindingLedger;
|
|
115
119
|
shadowMode;
|
|
116
120
|
assetSearchCache = new Map();
|
|
117
121
|
assetSearchInflight = new Map();
|
|
@@ -142,6 +146,7 @@ export class ProxyDaemon {
|
|
|
142
146
|
publishAbortController = new AbortController();
|
|
143
147
|
constructor(deps) {
|
|
144
148
|
this.deps = deps;
|
|
149
|
+
this.recipeGovernance = new hubNs.RecipeExecutionGovernance(deps.recipeExecutionDirectory);
|
|
145
150
|
this.benchmark = assetstore.benchmarkContext(deps.benchmarkId ?? process.env['EVOLVER_BENCHMARK_ID']);
|
|
146
151
|
this.now = deps.now ?? (() => Date.now());
|
|
147
152
|
this.random = deps.random ?? Math.random;
|
|
@@ -164,6 +169,11 @@ export class ProxyDaemon {
|
|
|
164
169
|
if (!existingSynchronousAssetSubmitScope) {
|
|
165
170
|
this.store.setState(SYNC_ASSET_SUBMIT_SCOPE_STATE_KEY, this.synchronousAssetSubmitScope);
|
|
166
171
|
}
|
|
172
|
+
this.publishBindingLedger = new PublishBindingLedger(this.store, JSON.stringify([
|
|
173
|
+
this.synchronousAssetSubmitScope, deps.runtimeNamespace ?? 'default', deps.hubMode ?? 'public',
|
|
174
|
+
// 保留既有 enforce 域;shadow 签发记录不能在切换模式后成为真实发布授权。
|
|
175
|
+
...(shadow ? ['shadow'] : []),
|
|
176
|
+
]));
|
|
167
177
|
const assetStoreDir = deps.assetStoreDir ?? (deps.storePath ? join(dirname(deps.storePath), 'assets') : undefined);
|
|
168
178
|
this.assetStore = deps.assetStore ?? (assetStoreDir ? new assetstore.LocalJsonlProvider(assetStoreDir) : undefined);
|
|
169
179
|
this.sourceProvenance = deps.sourceProvenance ?? (this.benchmark && this.assetStore instanceof assetstore.LocalJsonlProvider
|
|
@@ -179,6 +189,7 @@ export class ProxyDaemon {
|
|
|
179
189
|
const hubBindings = hubNs.makeHubBindings(hubToUse, {
|
|
180
190
|
referenceScope: this.referenceStore?.scope,
|
|
181
191
|
...(deps.publishSanitizeEnv ? { sanitize: { env: deps.publishSanitizeEnv } } : {}),
|
|
192
|
+
verifyPublishBinding: (bundle, receipt) => { this.publishBindingLedger.verify(bundle, receipt); },
|
|
182
193
|
});
|
|
183
194
|
this.proxyHandler = hubBindings.asProxyHandler();
|
|
184
195
|
const proxyHandler = this.proxyHandler;
|
|
@@ -276,6 +287,7 @@ export class ProxyDaemon {
|
|
|
276
287
|
});
|
|
277
288
|
this.lifecycle = new LifecycleManager({
|
|
278
289
|
store: this.store, auth: hubToUse.auth, hello: deps.hello, heartbeat: deps.heartbeat, now: this.now,
|
|
290
|
+
...(deps.currentNodeId ? { currentNodeId: deps.currentNodeId } : {}),
|
|
279
291
|
...(deps.heartbeatIntervalMs !== undefined ? { heartbeatIntervalMs: deps.heartbeatIntervalMs } : {}),
|
|
280
292
|
...(deps.evolverVersion ? { evolverVersion: deps.evolverVersion } : {}),
|
|
281
293
|
...(deps.helloMode ? { helloMode: deps.helloMode } : {}),
|
|
@@ -328,7 +340,14 @@ export class ProxyDaemon {
|
|
|
328
340
|
if (result.stored && env.handler === 'proxy')
|
|
329
341
|
this.notifyNewOutbound();
|
|
330
342
|
},
|
|
343
|
+
beforeSend: (envelope) => {
|
|
344
|
+
if (envelope.type !== 'asset_submit')
|
|
345
|
+
return;
|
|
346
|
+
const { assets, publishReceipt } = hubNs.splitAssetSubmitPayload(envelope.payload);
|
|
347
|
+
this.publishBindingLedger.verify(assets, publishReceipt);
|
|
348
|
+
},
|
|
331
349
|
...(this.deps.onIpcAuthFailure ? { onAuthFailure: this.deps.onIpcAuthFailure } : {}),
|
|
350
|
+
routeBodyLimits: hubNs.recipeIpcBodyLimits,
|
|
332
351
|
extraRoutes: [(ctx) => reference.withReferenceScope(this.referenceStore?.scope, () => this.handleProxyRoute(ctx))],
|
|
333
352
|
});
|
|
334
353
|
const port = await this.listenIpc(this.ipc);
|
|
@@ -337,6 +356,8 @@ export class ProxyDaemon {
|
|
|
337
356
|
}
|
|
338
357
|
catch { /* local discovery publishing must not block daemon startup */ }
|
|
339
358
|
await this.lifecycle.doHello();
|
|
359
|
+
if (this.lifecycle.isTerminal)
|
|
360
|
+
this.nextHeartbeatAt = Number.POSITIVE_INFINITY;
|
|
340
361
|
this.lifecycleArmed = true;
|
|
341
362
|
this.drainProxyTraceBackfill();
|
|
342
363
|
try {
|
|
@@ -512,7 +533,7 @@ export class ProxyDaemon {
|
|
|
512
533
|
* flight from overwriting this reschedule. No-op until the daemon is started.
|
|
513
534
|
*/
|
|
514
535
|
pokeHeartbeatLoop() {
|
|
515
|
-
if (!this.started)
|
|
536
|
+
if (!this.started || this.lifecycle.isTerminal)
|
|
516
537
|
return;
|
|
517
538
|
this.heartbeatGeneration += 1;
|
|
518
539
|
this.heartbeatFailures = 0;
|
|
@@ -843,6 +864,17 @@ export class ProxyDaemon {
|
|
|
843
864
|
const qualified = this.qualifyAssets(assets);
|
|
844
865
|
return { ...qualified, missing: ids.filter((id) => !qualified.assets.some((asset) => assetMatchesId(asset, id))) };
|
|
845
866
|
}
|
|
867
|
+
async recallAssets(query) {
|
|
868
|
+
try {
|
|
869
|
+
return await this.deps.hub.fetch(query);
|
|
870
|
+
}
|
|
871
|
+
catch (error) {
|
|
872
|
+
if (!isAuthLikeError(error))
|
|
873
|
+
throw error;
|
|
874
|
+
this.markHubAuthFailed(error);
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
846
878
|
async localFetchAssets(ids) {
|
|
847
879
|
const assets = [];
|
|
848
880
|
const missing = [];
|
|
@@ -875,6 +907,7 @@ export class ProxyDaemon {
|
|
|
875
907
|
hub_mode: this.deps.hubMode ?? 'public',
|
|
876
908
|
runtime_namespace: this.deps.runtimeNamespace ?? 'default',
|
|
877
909
|
node_id: this.lifecycle.nodeId ?? null,
|
|
910
|
+
recipe_execution_scope: recipeIpcScope(this.hub.recipes?.execution),
|
|
878
911
|
outbound_pending: this.store.countPending('proxy', this.deps.runtimeNamespace),
|
|
879
912
|
inbound_pending: this.store.countPending('agent', this.deps.runtimeNamespace) + this.store.countPending('core', this.deps.runtimeNamespace),
|
|
880
913
|
last_sync_at: this.store.getState('sync:last_sync_at') ?? null,
|
|
@@ -1061,29 +1094,10 @@ export class ProxyDaemon {
|
|
|
1061
1094
|
});
|
|
1062
1095
|
return true;
|
|
1063
1096
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
return true;
|
|
1069
|
-
}
|
|
1070
|
-
const recipes = this.hub.recipes;
|
|
1071
|
-
if (!recipes) {
|
|
1072
|
-
ctx.json(501, { error: 'recipe_unsupported' });
|
|
1073
|
-
return true;
|
|
1074
|
-
}
|
|
1075
|
-
const recipeId = typeof body['recipe_id'] === 'string'
|
|
1076
|
-
? body['recipe_id']
|
|
1077
|
-
: typeof body['recipeId'] === 'string'
|
|
1078
|
-
? body['recipeId']
|
|
1079
|
-
: '';
|
|
1080
|
-
if (!recipeId.trim()) {
|
|
1081
|
-
ctx.json(400, { error: 'recipe_id_required' });
|
|
1082
|
-
return true;
|
|
1083
|
-
}
|
|
1084
|
-
const inputPayload = asRecord(body['input_payload']) ?? asRecord(body['inputPayload']) ?? {};
|
|
1085
|
-
const receipt = await recipes.express(recipeId.trim(), { inputPayload });
|
|
1086
|
-
ctx.json(200, receipt);
|
|
1097
|
+
const recipeOperation = ctx.route.startsWith('POST /recipe/') ? ctx.route.slice('POST /recipe/'.length) : '';
|
|
1098
|
+
if (Object.hasOwn(hubNs.recipeExecutionSchemas, recipeOperation)) {
|
|
1099
|
+
const receipt = await invokeRecipeIpc(this.hub.recipes, this.recipeGovernance, recipeOperation, await ctx.readJson(), this.deps.hubMode);
|
|
1100
|
+
ctx.json(receipt.status, receipt.body);
|
|
1087
1101
|
return true;
|
|
1088
1102
|
}
|
|
1089
1103
|
if (ctx.route === 'POST /asset/fetch') {
|
|
@@ -1120,6 +1134,29 @@ export class ProxyDaemon {
|
|
|
1120
1134
|
});
|
|
1121
1135
|
return true;
|
|
1122
1136
|
}
|
|
1137
|
+
const recallText = typeof body.text === 'string' && body.text.trim() ? body.text.trim() : undefined;
|
|
1138
|
+
const recallSignals = Array.isArray(body.signals) ? body.signals.filter((s) => typeof s === 'string') : [];
|
|
1139
|
+
if (ids.length === 0 && (recallText !== undefined || recallSignals.length > 0)) {
|
|
1140
|
+
const recalled = await this.recallAssets({
|
|
1141
|
+
...(recallText !== undefined ? { text: recallText } : {}),
|
|
1142
|
+
...(recallSignals.length > 0 ? { signalsAny: recallSignals } : {}),
|
|
1143
|
+
...(typeof body.limit === 'number' ? { limit: body.limit } : {}),
|
|
1144
|
+
});
|
|
1145
|
+
if (recalled === null) {
|
|
1146
|
+
if (this.hubAuthFailurePolicy === 'deny') {
|
|
1147
|
+
ctx.json(401, this.hubAuthFailureBody());
|
|
1148
|
+
return true;
|
|
1149
|
+
}
|
|
1150
|
+
ctx.json(200, {
|
|
1151
|
+
assets: [], missing: [], query: body,
|
|
1152
|
+
degraded: true, local_fallback: true,
|
|
1153
|
+
auth_status: HUB_AUTH_FAILED, warning: HUB_AUTH_FAILURE_WARNING,
|
|
1154
|
+
});
|
|
1155
|
+
return true;
|
|
1156
|
+
}
|
|
1157
|
+
ctx.json(200, { ...this.qualifyFetch([], recalled, []), query: body, recalled_by: recallText !== undefined ? 'text' : 'signals' });
|
|
1158
|
+
return true;
|
|
1159
|
+
}
|
|
1123
1160
|
const assets = [];
|
|
1124
1161
|
const missing = [];
|
|
1125
1162
|
for (const id of ids) {
|
|
@@ -1207,11 +1244,29 @@ export class ProxyDaemon {
|
|
|
1207
1244
|
ctx.json(400, { error: 'mode=sync requires a full asset bundle' });
|
|
1208
1245
|
return true;
|
|
1209
1246
|
}
|
|
1247
|
+
if (body['publish_receipt'] !== undefined) {
|
|
1248
|
+
try {
|
|
1249
|
+
this.publishBindingLedger.verify(outboundBundle, body['publish_receipt']);
|
|
1250
|
+
}
|
|
1251
|
+
catch {
|
|
1252
|
+
ctx.json(422, { error: 'publish_binding_invalid', stored: false, queued: false });
|
|
1253
|
+
return true;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1210
1256
|
await this.publishAssetSubmitSynchronously(ctx, outboundBundle, hubNs.recipeComposeRequested(body));
|
|
1211
1257
|
return true;
|
|
1212
1258
|
}
|
|
1259
|
+
let publishReceipt;
|
|
1260
|
+
try {
|
|
1261
|
+
publishReceipt = this.publishBindingLedger.verify(outboundBundle, body['publish_receipt']);
|
|
1262
|
+
}
|
|
1263
|
+
catch {
|
|
1264
|
+
ctx.json(422, { error: 'publish_binding_invalid', stored: false, queued: false });
|
|
1265
|
+
return true;
|
|
1266
|
+
}
|
|
1213
1267
|
const payload = {
|
|
1214
1268
|
assets: outboundBundle,
|
|
1269
|
+
...(publishReceipt ? { publish_receipt: publishReceipt } : {}),
|
|
1215
1270
|
compose_recipe: hubNs.recipeComposeRequested(body),
|
|
1216
1271
|
[OUTBOUND_HUB_MODE_FIELD]: this.currentHubMode(),
|
|
1217
1272
|
};
|
|
@@ -1301,6 +1356,110 @@ export class ProxyDaemon {
|
|
|
1301
1356
|
}
|
|
1302
1357
|
return true;
|
|
1303
1358
|
}
|
|
1359
|
+
if (ctx.route === 'POST /asset/authorize-publish') {
|
|
1360
|
+
const body = asRecord(await ctx.readJson());
|
|
1361
|
+
if (hubModeMismatch(body['expected_hub_mode'], this.deps.hubMode)) {
|
|
1362
|
+
ctx.json(409, { error: 'proxy_hub_mode_mismatch', binding_verified: false });
|
|
1363
|
+
return true;
|
|
1364
|
+
}
|
|
1365
|
+
if (ctx.signal?.aborted || this.publishAbortController.signal.aborted) {
|
|
1366
|
+
ctx.json(503, { ok: false, error: 'publish_binding_aborted', binding_verified: false, stored: false, queued: false });
|
|
1367
|
+
return true;
|
|
1368
|
+
}
|
|
1369
|
+
try {
|
|
1370
|
+
if (!Array.isArray(body['assets']) || body['assets'].length === 0 || body['assets'].length > MAX_ASSET_SUBMIT_ITEMS) {
|
|
1371
|
+
throw new Error('publish_binding_invalid_bundle');
|
|
1372
|
+
}
|
|
1373
|
+
const bundle = body['assets'].map((asset) => {
|
|
1374
|
+
const normalized = assetstore.normalizeForPut(asset);
|
|
1375
|
+
// SDK 检查不包含本地 Gene 注解;ledger 仍绑定未删减的完整规范化记录。
|
|
1376
|
+
if (!normalized.verified || !wire.validateWireDeep(normalized.record.type === 'Gene' ? wire.stripGeneHints(normalized.record) : normalized.record).ok) {
|
|
1377
|
+
throw new Error('publish_binding_invalid_bundle');
|
|
1378
|
+
}
|
|
1379
|
+
return normalized.record;
|
|
1380
|
+
});
|
|
1381
|
+
const authorization = this.publishBindingLedger.verify(bundle);
|
|
1382
|
+
ctx.json(200, { ok: true, binding_verified: authorization !== undefined,
|
|
1383
|
+
binding_required: hubNs.requiresPublishBinding(bundle), bundle_digest: hubNs.publishBundleDigest(bundle) });
|
|
1384
|
+
}
|
|
1385
|
+
catch {
|
|
1386
|
+
ctx.json(422, { ok: false, error: 'publish_binding_invalid', binding_verified: false, stored: false, queued: false });
|
|
1387
|
+
}
|
|
1388
|
+
return true;
|
|
1389
|
+
}
|
|
1390
|
+
if (ctx.route === 'POST /asset/reverify') {
|
|
1391
|
+
const body = asRecord(await ctx.readJson());
|
|
1392
|
+
let stored = false;
|
|
1393
|
+
let bindingRegistered = false;
|
|
1394
|
+
let sourceAssetIds = [];
|
|
1395
|
+
let assetIds = [];
|
|
1396
|
+
const safeIds = (ids) => ids.slice(0, 2).filter((id) => /^sha256:[0-9a-f]{64}$/.test(id));
|
|
1397
|
+
const fail = (status, error) => {
|
|
1398
|
+
if (!ctx.signal?.aborted)
|
|
1399
|
+
ctx.json(status, {
|
|
1400
|
+
ok: false, error, publishable: false, stored, queued: false,
|
|
1401
|
+
binding_registered: bindingRegistered, source_asset_ids: sourceAssetIds, asset_ids: assetIds,
|
|
1402
|
+
});
|
|
1403
|
+
return true;
|
|
1404
|
+
};
|
|
1405
|
+
if (hubModeMismatch(body['expected_hub_mode'], this.deps.hubMode)) {
|
|
1406
|
+
return fail(409, 'proxy_hub_mode_mismatch');
|
|
1407
|
+
}
|
|
1408
|
+
if (Object.keys(body).some((key) => !['assets', 'persist', 'expected_hub_mode'].includes(key))
|
|
1409
|
+
|| (body['persist'] !== undefined && typeof body['persist'] !== 'boolean')) {
|
|
1410
|
+
return fail(422, 'publish_reverification_invalid_options');
|
|
1411
|
+
}
|
|
1412
|
+
if (!Array.isArray(body['assets']))
|
|
1413
|
+
return fail(422, 'publish_reverification_pair_required');
|
|
1414
|
+
if (!this.deps.publishExecutionVerifier)
|
|
1415
|
+
return fail(409, 'publish_reverification_unavailable');
|
|
1416
|
+
const signal = AbortSignal.any([this.publishAbortController.signal, ...(ctx.signal ? [ctx.signal] : [])]);
|
|
1417
|
+
if (signal.aborted)
|
|
1418
|
+
return fail(503, 'publish_reverification_aborted');
|
|
1419
|
+
if (body['persist'] === true && typeof this.assetStore?.putBundle !== 'function') {
|
|
1420
|
+
return fail(422, 'bundle_persistence_unsupported');
|
|
1421
|
+
}
|
|
1422
|
+
const sanitizeEnv = this.deps.publishSanitizeEnv ?? process.env;
|
|
1423
|
+
let candidate;
|
|
1424
|
+
try {
|
|
1425
|
+
candidate = hubNs.preparePublishReverification(body['assets'], sanitizeEnv);
|
|
1426
|
+
}
|
|
1427
|
+
catch (error) {
|
|
1428
|
+
return fail(422, error instanceof Error && /^publish_reverification_[a-z_]{1,70}$/.test(error.message)
|
|
1429
|
+
? error.message : 'publish_reverification_invalid_wire');
|
|
1430
|
+
}
|
|
1431
|
+
sourceAssetIds = safeIds(candidate.sourceAssetIds);
|
|
1432
|
+
const request = hubNs.createPublishVerificationRequest(candidate.input, candidate.validation, this.publishBindingLedger.runtimeDomain, randomUUID());
|
|
1433
|
+
const verified = await resolveVerifiedExecution(this.deps.publishExecutionVerifier, { validation: candidate.validation, verification_request: Object.freeze(request) }, candidate.validation, this.deps.publishExecutionVerifierTimeoutMs, [signal]);
|
|
1434
|
+
if (signal.aborted)
|
|
1435
|
+
return fail(503, 'publish_reverification_aborted');
|
|
1436
|
+
if (!verified)
|
|
1437
|
+
return fail(422, 'publish_reverification_execution_failed');
|
|
1438
|
+
try {
|
|
1439
|
+
const result = hubNs.completePublishReverification(candidate, verified, sanitizeEnv);
|
|
1440
|
+
assetIds = safeIds(result.assets.map((asset) => asset.asset_id));
|
|
1441
|
+
// 登记与资产持久化是独立状态,写入抛错后不得声称没有副作用或撤销合法回执。
|
|
1442
|
+
bindingRegistered = null;
|
|
1443
|
+
this.publishBindingLedger.register(result.publish_receipt, result.assets);
|
|
1444
|
+
bindingRegistered = true;
|
|
1445
|
+
if (signal.aborted)
|
|
1446
|
+
return fail(503, 'publish_reverification_aborted');
|
|
1447
|
+
if (body['persist'] === true) {
|
|
1448
|
+
stored = null;
|
|
1449
|
+
await this.assetStore.putBundle(result.assets);
|
|
1450
|
+
stored = true;
|
|
1451
|
+
}
|
|
1452
|
+
if (signal.aborted)
|
|
1453
|
+
return fail(503, 'publish_reverification_aborted');
|
|
1454
|
+
this.publishBindingLedger.verify(result.assets, result.publish_receipt);
|
|
1455
|
+
ctx.json(200, { ok: true, status: 'reverified', ...result, stored, binding_registered: bindingRegistered, queued: false, publishable: true });
|
|
1456
|
+
return true;
|
|
1457
|
+
}
|
|
1458
|
+
catch (error) {
|
|
1459
|
+
return fail(422, error instanceof Error && /^publish_reverification_[a-z_]{1,70}$/.test(error.message)
|
|
1460
|
+
? error.message : 'publish_reverification_failed');
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1304
1463
|
if (ctx.route === 'POST /conversation/distill') {
|
|
1305
1464
|
const body = (await ctx.readJson());
|
|
1306
1465
|
const publishRequested = body['publish'] === true;
|
|
@@ -1325,7 +1484,7 @@ export class ProxyDaemon {
|
|
|
1325
1484
|
if (publishRequested && abortPublish())
|
|
1326
1485
|
return true;
|
|
1327
1486
|
const verifiedExecution = publishRequested
|
|
1328
|
-
? await resolveVerifiedExecutionAfterPreflight(this.deps.publishExecutionVerifier, body, this.deps.publishExecutionVerifierTimeoutMs, [this.publishAbortController.signal, ...(ctx.signal ? [ctx.signal] : [])])
|
|
1487
|
+
? await resolveVerifiedExecutionAfterPreflight(this.deps.publishExecutionVerifier, body, this.deps.publishExecutionVerifierTimeoutMs, [this.publishAbortController.signal, ...(ctx.signal ? [ctx.signal] : [])], this.publishBindingLedger.runtimeDomain)
|
|
1329
1488
|
: undefined;
|
|
1330
1489
|
if (publishRequested && abortPublish())
|
|
1331
1490
|
return true;
|
|
@@ -1334,6 +1493,9 @@ export class ProxyDaemon {
|
|
|
1334
1493
|
persist: body.persist === true,
|
|
1335
1494
|
store: this.assetStore,
|
|
1336
1495
|
...(verifiedExecution ? { verifiedExecution } : {}),
|
|
1496
|
+
registerPublishReceipt: (receipt, bundle) => this.publishBindingLedger.register(receipt, bundle),
|
|
1497
|
+
...(publishRequested ? { publishSignal: AbortSignal.any([this.publishAbortController.signal, ...(ctx.signal ? [ctx.signal] : [])]) } : {}),
|
|
1498
|
+
...(this.deps.publishSanitizeEnv ? { publishSanitizeEnv: this.deps.publishSanitizeEnv } : {}),
|
|
1337
1499
|
});
|
|
1338
1500
|
if (publishRequested && abortPublish())
|
|
1339
1501
|
return true;
|
|
@@ -1369,12 +1531,19 @@ export class ProxyDaemon {
|
|
|
1369
1531
|
ctx.json(401, this.hubAuthFailureBody({ publish_status: 'failed', queued: false, stored: false }));
|
|
1370
1532
|
return true;
|
|
1371
1533
|
}
|
|
1534
|
+
if (!distill.publish_receipt) {
|
|
1535
|
+
ctx.json(422, { error: 'publish_binding_missing', stored: false, queued: false });
|
|
1536
|
+
return true;
|
|
1537
|
+
}
|
|
1538
|
+
this.publishBindingLedger.register(distill.publish_receipt, [distill.gene, distill.capsule]);
|
|
1539
|
+
this.publishBindingLedger.verify([distill.gene, distill.capsule], distill.publish_receipt);
|
|
1372
1540
|
const env = mailbox.createEnvelope({
|
|
1373
1541
|
type: 'asset_submit',
|
|
1374
1542
|
payload: {
|
|
1375
1543
|
source: 'conversation_distillation',
|
|
1376
1544
|
distill_id: distill.distill_id,
|
|
1377
1545
|
assets: [distill.gene, distill.capsule],
|
|
1546
|
+
publish_receipt: distill.publish_receipt,
|
|
1378
1547
|
compose_recipe: body['publish_recipe'] !== false,
|
|
1379
1548
|
title: typeof body.title === 'string' ? body.title : undefined,
|
|
1380
1549
|
description: typeof body.summary === 'string' ? body.summary : undefined,
|
|
@@ -1568,7 +1737,7 @@ export class ProxyDaemon {
|
|
|
1568
1737
|
}
|
|
1569
1738
|
const results = [];
|
|
1570
1739
|
for (const item of classified.items) {
|
|
1571
|
-
const converted = await convertLegacyLooseAsset(item, this.deps.publishExecutionVerifier, this.deps.publishExecutionVerifierTimeoutMs, ctx.signal, this.publishAbortController.signal);
|
|
1740
|
+
const converted = await convertLegacyLooseAsset(item, this.deps.publishExecutionVerifier, this.deps.publishExecutionVerifierTimeoutMs, this.publishBindingLedger, this.deps.publishSanitizeEnv, ctx.signal, this.publishAbortController.signal);
|
|
1572
1741
|
if (!converted.ok) {
|
|
1573
1742
|
results.push({ ok: false, error: converted.error, statusCode: 422 });
|
|
1574
1743
|
continue;
|
|
@@ -1615,6 +1784,7 @@ export class ProxyDaemon {
|
|
|
1615
1784
|
}
|
|
1616
1785
|
createSynchronousAssetSubmitEnvelope(bundle, source, now, composeRecipe = true) {
|
|
1617
1786
|
const canonicalBundle = [...bundle].sort(compareSynchronousAssetSubmitAssets);
|
|
1787
|
+
const publishReceipt = this.publishBindingLedger.verify(canonicalBundle);
|
|
1618
1788
|
const runtimeNamespace = this.deps.runtimeNamespace ?? 'default';
|
|
1619
1789
|
const idempotencyKey = synchronousAssetSubmitKey(this.synchronousAssetSubmitScope, runtimeNamespace, this.currentHubMode(), canonicalBundle);
|
|
1620
1790
|
return mailbox.createEnvelope({
|
|
@@ -1623,6 +1793,7 @@ export class ProxyDaemon {
|
|
|
1623
1793
|
payload: {
|
|
1624
1794
|
...(source ? { source } : {}),
|
|
1625
1795
|
assets: canonicalBundle,
|
|
1796
|
+
...(publishReceipt ? { publish_receipt: publishReceipt } : {}),
|
|
1626
1797
|
compose_recipe: composeRecipe,
|
|
1627
1798
|
[OUTBOUND_HUB_MODE_FIELD]: this.currentHubMode(),
|
|
1628
1799
|
},
|
|
@@ -2101,7 +2272,9 @@ function classifySynchronousAssetSubmit(items) {
|
|
|
2101
2272
|
const bundle = [];
|
|
2102
2273
|
for (let index = 0; index < items.length; index += 1) {
|
|
2103
2274
|
const item = items[index];
|
|
2104
|
-
|
|
2275
|
+
// 保持既有人工 wire 的结构分类合同;完整 schema/执行授权属于各自明确的准入门。
|
|
2276
|
+
// Gene 本地 hints 只从检查副本剥离,不改变 ledger 绑定的实际记录。
|
|
2277
|
+
if (!wire.validateWire(item['type'] === 'Gene' ? wire.stripGeneHints(item) : item).ok) {
|
|
2105
2278
|
return { ok: false, error: `asset ${index}: malformed V2 wire asset` };
|
|
2106
2279
|
}
|
|
2107
2280
|
try {
|
|
@@ -2182,10 +2355,17 @@ async function resolveVerifiedExecution(verifier, input, expectedValidation, tim
|
|
|
2182
2355
|
return undefined;
|
|
2183
2356
|
if (candidate.trace.some((row, index) => row.command.trim() !== expectedValidation[index]))
|
|
2184
2357
|
return undefined;
|
|
2358
|
+
if (!hubNs.isPublishVerificationRequest(input['verification_request'])
|
|
2359
|
+
|| !hubNs.isPublishVerificationEvidence(candidate.binding)
|
|
2360
|
+
|| wire.canonicalize(candidate.binding.request) !== wire.canonicalize(input['verification_request']))
|
|
2361
|
+
return undefined;
|
|
2185
2362
|
// Compare the authoritative raw receipt first, then cross the common execution-evidence outlet exactly once.
|
|
2186
2363
|
// A command that required redaction no longer identifies the executed program and must not unlock publication.
|
|
2187
|
-
const sanitized = verify.sanitizeExecutionPayload({
|
|
2188
|
-
|
|
2364
|
+
const sanitized = verify.sanitizeExecutionPayload({
|
|
2365
|
+
trace: candidate.trace, validation: expectedValidation,
|
|
2366
|
+
...(candidate.blast_radius ? { blast_radius: candidate.blast_radius } : {}),
|
|
2367
|
+
});
|
|
2368
|
+
return sanitized.blocked ? undefined : { ...sanitized.value, binding: structuredClone(candidate.binding) };
|
|
2189
2369
|
}
|
|
2190
2370
|
catch {
|
|
2191
2371
|
return undefined;
|
|
@@ -2214,28 +2394,35 @@ function declaredValidationCommands(input) {
|
|
|
2214
2394
|
}
|
|
2215
2395
|
return commands;
|
|
2216
2396
|
}
|
|
2217
|
-
async function resolveVerifiedExecutionAfterPreflight(verifier, input, timeoutMs, parentSignals = []) {
|
|
2397
|
+
async function resolveVerifiedExecutionAfterPreflight(verifier, input, timeoutMs, parentSignals = [], runtimeDomain = 'standalone', genePolicy) {
|
|
2218
2398
|
if (!verifier)
|
|
2219
2399
|
return undefined;
|
|
2220
2400
|
if (parentSignals.some((signal) => signal.aborted))
|
|
2221
2401
|
return undefined;
|
|
2222
|
-
const preflight = await hubNs.distillConversation(input, { persist: false });
|
|
2402
|
+
const preflight = await hubNs.distillConversation(input, { persist: false, ...(genePolicy ? { genePolicy } : {}) });
|
|
2223
2403
|
if (parentSignals.some((signal) => signal.aborted) || !preflight.ok || !preflight.quality.ok)
|
|
2224
2404
|
return undefined;
|
|
2225
2405
|
const validation = declaredValidationCommands(input);
|
|
2226
2406
|
if (!validation)
|
|
2227
2407
|
return undefined;
|
|
2228
2408
|
// 只把通过质量与命令策略预检的最小验证输入交给宿主,绝不转发调用方的 execution/status/trace。
|
|
2229
|
-
|
|
2409
|
+
const verificationRequest = Object.freeze(hubNs.createConversationVerificationRequest(input, validation, runtimeDomain, randomUUID(), genePolicy));
|
|
2410
|
+
return resolveVerifiedExecution(verifier, { validation, verification_request: verificationRequest }, validation, timeoutMs, parentSignals);
|
|
2230
2411
|
}
|
|
2231
|
-
async function convertLegacyLooseAsset(value, verifyExecution, verifyExecutionTimeoutMs, ...parentSignals) {
|
|
2412
|
+
async function convertLegacyLooseAsset(value, verifyExecution, verifyExecutionTimeoutMs, ledger, sanitizeEnv = process.env, ...parentSignals) {
|
|
2232
2413
|
const normalized = legacyLooseDistillInput(value);
|
|
2233
2414
|
if (!normalized.ok)
|
|
2234
2415
|
return normalized;
|
|
2416
|
+
const genePolicy = {
|
|
2417
|
+
...(normalized.constraints ? { constraints: normalized.constraints } : {}),
|
|
2418
|
+
...(normalized.category ? { category: normalized.category } : {}),
|
|
2419
|
+
};
|
|
2235
2420
|
try {
|
|
2236
|
-
const verifiedExecution = await resolveVerifiedExecutionAfterPreflight(verifyExecution, normalized.input, verifyExecutionTimeoutMs, parentSignals.filter((signal) => signal !== undefined));
|
|
2421
|
+
const verifiedExecution = await resolveVerifiedExecutionAfterPreflight(verifyExecution, normalized.input, verifyExecutionTimeoutMs, parentSignals.filter((signal) => signal !== undefined), ledger?.runtimeDomain, genePolicy);
|
|
2237
2422
|
const distilled = await hubNs.distillConversation(normalized.input, {
|
|
2238
2423
|
persist: false,
|
|
2424
|
+
publishSanitizeEnv: sanitizeEnv,
|
|
2425
|
+
genePolicy,
|
|
2239
2426
|
...(verifiedExecution ? { verifiedExecution } : {}),
|
|
2240
2427
|
});
|
|
2241
2428
|
if (!distilled.ok)
|
|
@@ -2251,17 +2438,20 @@ async function convertLegacyLooseAsset(value, verifyExecution, verifyExecutionTi
|
|
|
2251
2438
|
: 'legacy_distill_quality_gate',
|
|
2252
2439
|
};
|
|
2253
2440
|
}
|
|
2254
|
-
const
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
: {}),
|
|
2259
|
-
...(normalized.category ? { category: normalized.category } : {}),
|
|
2260
|
-
};
|
|
2261
|
-
const bundle = [gene, distilled.capsule].map(deterministicDistilledAsset);
|
|
2441
|
+
const sanitized = hubNs.sanitizeBundle([distilled.gene, distilled.capsule].map(deterministicDistilledAsset), { env: sanitizeEnv });
|
|
2442
|
+
if (sanitized.blocked)
|
|
2443
|
+
return { ok: false, error: 'legacy_distill_leak_blocked' };
|
|
2444
|
+
const bundle = sanitized.bundle;
|
|
2262
2445
|
if (!bundle.every((asset) => wire.validateWire(asset).ok)) {
|
|
2263
2446
|
return { ok: false, error: 'legacy_distill_invalid_wire_output' };
|
|
2264
2447
|
}
|
|
2448
|
+
if (!verifiedExecution?.binding || !ledger)
|
|
2449
|
+
return { ok: false, error: 'legacy_distill_binding_missing' };
|
|
2450
|
+
const receipt = hubNs.createPublishBindingReceipt(bundle, verifiedExecution.binding, {
|
|
2451
|
+
validation: verifiedExecution.validation, trace: verifiedExecution.trace,
|
|
2452
|
+
});
|
|
2453
|
+
ledger.register(receipt, bundle);
|
|
2454
|
+
ledger.verify(bundle, receipt);
|
|
2265
2455
|
return { ok: true, bundle };
|
|
2266
2456
|
}
|
|
2267
2457
|
catch {
|
|
@@ -2359,19 +2549,6 @@ function parseLegacyConstraints(value) {
|
|
|
2359
2549
|
},
|
|
2360
2550
|
};
|
|
2361
2551
|
}
|
|
2362
|
-
function mergeLegacyConstraints(base, legacy) {
|
|
2363
|
-
const current = isRecordValue(base) ? base : {};
|
|
2364
|
-
const currentMax = Number.isInteger(current['max_files']) && Number(current['max_files']) > 0
|
|
2365
|
-
? Number(current['max_files'])
|
|
2366
|
-
: 20;
|
|
2367
|
-
const currentPaths = Array.isArray(current['forbidden_paths'])
|
|
2368
|
-
? current['forbidden_paths'].filter((path) => typeof path === 'string')
|
|
2369
|
-
: [];
|
|
2370
|
-
return {
|
|
2371
|
-
max_files: Math.min(currentMax, legacy.max_files ?? currentMax),
|
|
2372
|
-
forbidden_paths: uniqueStrings([...currentPaths, ...(legacy.forbidden_paths ?? [])]),
|
|
2373
|
-
};
|
|
2374
|
-
}
|
|
2375
2552
|
function parseLegacyCategory(value) {
|
|
2376
2553
|
if (value === undefined)
|
|
2377
2554
|
return { ok: true };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { hub, type assetstore } from '@evomap/evolver-core';
|
|
2
|
+
interface StateStore {
|
|
3
|
+
getState(key: string): string | undefined;
|
|
4
|
+
setState(key: string, value: string): void;
|
|
5
|
+
}
|
|
6
|
+
/** 与 durable mailbox 同位;不信任 HTTP 提交的自签名/hash receipt。 */
|
|
7
|
+
export declare class PublishBindingLedger {
|
|
8
|
+
private readonly store;
|
|
9
|
+
readonly runtimeDomain: string;
|
|
10
|
+
readonly runtimeDigest: string;
|
|
11
|
+
constructor(store: StateStore, runtimeDomain: string);
|
|
12
|
+
register(receipt: hub.PublishBindingReceipt, bundle: readonly assetstore.AssetRecord[]): void;
|
|
13
|
+
verify(bundle: readonly assetstore.AssetRecord[], supplied?: unknown): hub.PublishBindingAuthorization | undefined;
|
|
14
|
+
private key;
|
|
15
|
+
private memberKey;
|
|
16
|
+
}
|
|
17
|
+
export {};
|