@evomap/evolver-adapter-public 2.0.33 → 2.0.35
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/auth/credentialStore.js +53 -34
- package/dist/auth/windowsPowerShell.d.ts +1 -1
- package/dist/auth/windowsPowerShell.js +4 -4
- package/dist/connect.js +9 -2
- package/dist/hubCapability.d.ts +6 -2
- package/dist/hubCapability.js +44 -6
- package/dist/hubFetch.d.ts +4 -0
- package/dist/hubFetch.js +16 -0
- package/dist/hubReuse.js +5 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
2
2
|
import { execFileSync } from 'node:child_process';
|
|
3
3
|
import { constants, closeSync, fchmodSync, fstatSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
4
4
|
import { basename, dirname, resolve, win32 } from 'node:path';
|
|
5
|
-
import {
|
|
5
|
+
import { POWERSHELL_ENV_SCRIPT_COMMAND, windowsAclFailureDetail, } from './windowsPowerShell.js';
|
|
6
6
|
const DIRECTORY_MODE = 0o700;
|
|
7
7
|
const FILE_MODE = 0o600;
|
|
8
8
|
export class CredentialStoreError extends Error {
|
|
@@ -805,17 +805,22 @@ function Assert-TrustedParent([string]$ParentPath, [bool]$StrictCreate) {
|
|
|
805
805
|
$finalParent,
|
|
806
806
|
[System.StringComparison]::OrdinalIgnoreCase
|
|
807
807
|
)
|
|
808
|
-
$
|
|
809
|
-
if (-
|
|
810
|
-
(($
|
|
808
|
+
$attributes = [System.IO.File]::GetAttributes($current)
|
|
809
|
+
if ((($attributes -band [System.IO.FileAttributes]::Directory) -eq 0) -or
|
|
810
|
+
(($attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) {
|
|
811
811
|
Throw-CredentialAclFailure -Reason 'Credential parent contains a reparse point or non-directory' -Path $current
|
|
812
812
|
}
|
|
813
|
-
$parentAcl =
|
|
813
|
+
$parentAcl = [System.IO.Directory]::GetAccessControl($current)
|
|
814
814
|
$ownerSid = $parentAcl.GetOwner([System.Security.Principal.SecurityIdentifier])
|
|
815
815
|
if ($trustedSids -notcontains $ownerSid.Value) {
|
|
816
816
|
Throw-CredentialAclFailure -Reason 'Credential parent has an untrusted owner' -Path $current -Sid $ownerSid.Value
|
|
817
817
|
}
|
|
818
|
-
|
|
818
|
+
$parentRules = @($parentAcl.GetAccessRules(
|
|
819
|
+
$true,
|
|
820
|
+
$true,
|
|
821
|
+
[System.Security.Principal.SecurityIdentifier]
|
|
822
|
+
))
|
|
823
|
+
foreach ($parentRule in $parentRules) {
|
|
819
824
|
if ($parentRule.AccessControlType -ne [System.Security.AccessControl.AccessControlType]::Allow) {
|
|
820
825
|
continue
|
|
821
826
|
}
|
|
@@ -845,11 +850,8 @@ function Assert-TrustedParent([string]$ParentPath, [bool]$StrictCreate) {
|
|
|
845
850
|
$dangerousGrant = $hasGranularDanger -or ($isCreateParent -and $hasCreateDanger)
|
|
846
851
|
}
|
|
847
852
|
if (-not $dangerousGrant) { continue }
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
[System.Security.Principal.SecurityIdentifier]
|
|
851
|
-
)
|
|
852
|
-
} catch {
|
|
853
|
+
$parentRuleSid = $parentRule.IdentityReference
|
|
854
|
+
if (-not ($parentRuleSid -is [System.Security.Principal.SecurityIdentifier])) {
|
|
853
855
|
Throw-CredentialAclFailure -Reason 'Credential parent contains an unresolvable write principal' -Path $current -Principal $parentRule.IdentityReference.Value -Rights $rights
|
|
854
856
|
}
|
|
855
857
|
if ($trustedSids -notcontains $parentRuleSid.Value) {
|
|
@@ -860,17 +862,22 @@ function Assert-TrustedParent([string]$ParentPath, [bool]$StrictCreate) {
|
|
|
860
862
|
}
|
|
861
863
|
|
|
862
864
|
function Assert-TrustedFile([string]$FilePath) {
|
|
863
|
-
$
|
|
864
|
-
if ($
|
|
865
|
-
(($
|
|
865
|
+
$attributes = [System.IO.File]::GetAttributes($FilePath)
|
|
866
|
+
if ((($attributes -band [System.IO.FileAttributes]::Directory) -ne 0) -or
|
|
867
|
+
(($attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) {
|
|
866
868
|
Throw-CredentialAclFailure -Reason 'Credential file is a reparse point or not a regular file' -Path $FilePath
|
|
867
869
|
}
|
|
868
|
-
$fileAcl =
|
|
870
|
+
$fileAcl = [System.IO.File]::GetAccessControl($FilePath)
|
|
869
871
|
$ownerSid = $fileAcl.GetOwner([System.Security.Principal.SecurityIdentifier])
|
|
870
872
|
if ($trustedSids -notcontains $ownerSid.Value) {
|
|
871
873
|
Throw-CredentialAclFailure -Reason 'Credential file has an untrusted owner' -Path $FilePath -Sid $ownerSid.Value
|
|
872
874
|
}
|
|
873
|
-
|
|
875
|
+
$fileRules = @($fileAcl.GetAccessRules(
|
|
876
|
+
$true,
|
|
877
|
+
$true,
|
|
878
|
+
[System.Security.Principal.SecurityIdentifier]
|
|
879
|
+
))
|
|
880
|
+
foreach ($fileRule in $fileRules) {
|
|
874
881
|
if ($fileRule.AccessControlType -ne [System.Security.AccessControl.AccessControlType]::Allow) {
|
|
875
882
|
continue
|
|
876
883
|
}
|
|
@@ -884,11 +891,8 @@ function Assert-TrustedFile([string]$FilePath) {
|
|
|
884
891
|
(($rights -band [System.Security.AccessControl.FileSystemRights]::FullControl) -eq
|
|
885
892
|
[System.Security.AccessControl.FileSystemRights]::FullControl)
|
|
886
893
|
if (-not ($hasGranularDanger -or $hasCompositeDanger)) { continue }
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
[System.Security.Principal.SecurityIdentifier]
|
|
890
|
-
)
|
|
891
|
-
} catch {
|
|
894
|
+
$fileRuleSid = $fileRule.IdentityReference
|
|
895
|
+
if (-not ($fileRuleSid -is [System.Security.Principal.SecurityIdentifier])) {
|
|
892
896
|
Throw-CredentialAclFailure -Reason 'Credential file contains an unresolvable write principal' -Path $FilePath -Principal $fileRule.IdentityReference.Value -Rights $rights
|
|
893
897
|
}
|
|
894
898
|
if ($trustedSids -notcontains $fileRuleSid.Value) {
|
|
@@ -903,15 +907,17 @@ function Test-CanonicalCredentialAcl(
|
|
|
903
907
|
[System.Security.AccessControl.InheritanceFlags]$ExpectedInheritance
|
|
904
908
|
) {
|
|
905
909
|
try {
|
|
906
|
-
$candidateRules = @($CandidateAcl.
|
|
910
|
+
$candidateRules = @($CandidateAcl.GetAccessRules(
|
|
911
|
+
$true,
|
|
912
|
+
$true,
|
|
913
|
+
[System.Security.Principal.SecurityIdentifier]
|
|
914
|
+
))
|
|
907
915
|
if (-not $CandidateAcl.AreAccessRulesProtected -or $candidateRules.Count -ne 1) {
|
|
908
916
|
return $false
|
|
909
917
|
}
|
|
910
918
|
$candidateOwner = $CandidateAcl.GetOwner([System.Security.Principal.SecurityIdentifier])
|
|
911
919
|
$candidateRule = $candidateRules[0]
|
|
912
|
-
$candidateRuleSid = $candidateRule.IdentityReference
|
|
913
|
-
[System.Security.Principal.SecurityIdentifier]
|
|
914
|
-
)
|
|
920
|
+
$candidateRuleSid = $candidateRule.IdentityReference
|
|
915
921
|
return (
|
|
916
922
|
$candidateOwner.Value -eq $ExpectedOwner.Value -and
|
|
917
923
|
$candidateRuleSid.Value -eq $ExpectedOwner.Value -and
|
|
@@ -945,13 +951,21 @@ $expectedInheritance = if ($Kind -eq 'directory') {
|
|
|
945
951
|
} else {
|
|
946
952
|
[System.Security.AccessControl.InheritanceFlags]::None
|
|
947
953
|
}
|
|
948
|
-
$acl =
|
|
954
|
+
$acl = if ($Kind -eq 'directory') {
|
|
955
|
+
[System.IO.Directory]::GetAccessControl($Target)
|
|
956
|
+
} else {
|
|
957
|
+
[System.IO.File]::GetAccessControl($Target)
|
|
958
|
+
}
|
|
949
959
|
if (Test-CanonicalCredentialAcl $acl $sid $expectedInheritance) {
|
|
950
960
|
exit 0
|
|
951
961
|
}
|
|
952
962
|
$acl.SetOwner($sid)
|
|
953
963
|
$acl.SetAccessRuleProtection($true, $false)
|
|
954
|
-
foreach ($rule in @($acl.
|
|
964
|
+
foreach ($rule in @($acl.GetAccessRules(
|
|
965
|
+
$true,
|
|
966
|
+
$true,
|
|
967
|
+
[System.Security.Principal.SecurityIdentifier]
|
|
968
|
+
))) { [void]$acl.RemoveAccessRuleSpecific($rule) }
|
|
955
969
|
$access = [System.Security.AccessControl.FileSystemAccessRule]::new(
|
|
956
970
|
$sid,
|
|
957
971
|
[System.Security.AccessControl.FileSystemRights]::FullControl,
|
|
@@ -960,8 +974,13 @@ $access = [System.Security.AccessControl.FileSystemAccessRule]::new(
|
|
|
960
974
|
[System.Security.AccessControl.AccessControlType]::Allow
|
|
961
975
|
)
|
|
962
976
|
[void]$acl.AddAccessRule($access)
|
|
963
|
-
|
|
964
|
-
$
|
|
977
|
+
if ($Kind -eq 'directory') {
|
|
978
|
+
[System.IO.Directory]::SetAccessControl($Target, $acl)
|
|
979
|
+
$verified = [System.IO.Directory]::GetAccessControl($Target)
|
|
980
|
+
} else {
|
|
981
|
+
[System.IO.File]::SetAccessControl($Target, $acl)
|
|
982
|
+
$verified = [System.IO.File]::GetAccessControl($Target)
|
|
983
|
+
}
|
|
965
984
|
if (-not (Test-CanonicalCredentialAcl $verified $sid $expectedInheritance)) {
|
|
966
985
|
Throw-CredentialAclFailure -Reason 'Credential ACL verification failed' -Path $Target -Sid $sid.Value
|
|
967
986
|
}
|
|
@@ -996,23 +1015,23 @@ class PowerShellWindowsAclOps {
|
|
|
996
1015
|
'-NoProfile',
|
|
997
1016
|
'-NonInteractive',
|
|
998
1017
|
'-ExecutionPolicy', 'Bypass',
|
|
999
|
-
//
|
|
1000
|
-
//
|
|
1001
|
-
'-Command',
|
|
1018
|
+
// Keep the trusted constant script out of stdin: Windows PowerShell 5.1
|
|
1019
|
+
// can wait indefinitely for redirected stdin on hosted runners.
|
|
1020
|
+
'-Command', POWERSHELL_ENV_SCRIPT_COMMAND,
|
|
1002
1021
|
], {
|
|
1003
1022
|
encoding: 'utf8',
|
|
1004
1023
|
env: {
|
|
1005
1024
|
SystemRoot: this.systemRoot,
|
|
1006
1025
|
EVOMAP_CREDENTIAL_ACL_TARGET: path,
|
|
1007
1026
|
EVOMAP_CREDENTIAL_ACL_KIND: kind,
|
|
1027
|
+
EVOMAP_CREDENTIAL_ACL_SCRIPT: WINDOWS_ACL_SCRIPT,
|
|
1008
1028
|
},
|
|
1009
1029
|
shell: false,
|
|
1010
1030
|
// Capture both streams rather than discarding them: the script's own
|
|
1011
1031
|
// message names which path level and which SID failed, and without it
|
|
1012
1032
|
// every rejection is indistinguishable from "PowerShell is missing".
|
|
1013
1033
|
// The script prints nothing on success, so this stays quiet normally.
|
|
1014
|
-
|
|
1015
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
1034
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
1016
1035
|
timeout: 15_000,
|
|
1017
1036
|
windowsHide: true,
|
|
1018
1037
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const POWERSHELL_ENV_SCRIPT_COMMAND = "& ([scriptblock]::Create($env:EVOMAP_CREDENTIAL_ACL_SCRIPT))";
|
|
2
2
|
export declare function windowsAclFailureDetail(cause: unknown): string;
|
|
3
3
|
export declare function stripPowerShellClixml(text: string): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const POWERSHELL_ENV_SCRIPT_COMMAND = '& ([scriptblock]::Create($env:EVOMAP_CREDENTIAL_ACL_SCRIPT))';
|
|
2
2
|
export function windowsAclFailureDetail(cause) {
|
|
3
3
|
const error = cause;
|
|
4
4
|
const parts = [];
|
|
@@ -10,12 +10,12 @@ export function windowsAclFailureDetail(cause) {
|
|
|
10
10
|
if (typeof error?.signal === 'string' && error.signal) {
|
|
11
11
|
parts.push('signal ' + normalizePowerShellDiagnostic(error.signal));
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const [stderr, stdout] = [error?.stderr, error?.stdout]
|
|
14
14
|
.map((stream) => (typeof stream === 'string'
|
|
15
15
|
? stream
|
|
16
16
|
: Buffer.isBuffer(stream) ? stream.toString('utf8') : ''))
|
|
17
|
-
.map(stripPowerShellClixml)
|
|
18
|
-
|
|
17
|
+
.map(stripPowerShellClixml);
|
|
18
|
+
const streams = stderr ? [stderr] : stdout ? [stdout] : [];
|
|
19
19
|
if (streams.length > 0) {
|
|
20
20
|
parts.push(streams.join(' | '));
|
|
21
21
|
}
|
package/dist/connect.js
CHANGED
|
@@ -21,13 +21,20 @@ export function connectPublicHub(opts) {
|
|
|
21
21
|
case 'keypair':
|
|
22
22
|
if (!opts.registerPublicKey)
|
|
23
23
|
throw new Error('keypair 模式需 registerPublicKey');
|
|
24
|
-
auth = new KeypairProvider({
|
|
24
|
+
auth = new KeypairProvider({
|
|
25
|
+
credPath: join(dir, 'keys', 'keypair.json'),
|
|
26
|
+
registerPublicKey: opts.registerPublicKey,
|
|
27
|
+
});
|
|
25
28
|
break;
|
|
26
29
|
case 'oauth': {
|
|
27
30
|
// Default to the real HTTP device-flow transport derived from hubUrl;
|
|
28
31
|
// tests/embedders may still inject their own.
|
|
29
32
|
const transport = opts.oauthTransport ?? createOAuthHttpTransport({ hubUrl: opts.hubUrl, fetchFn });
|
|
30
|
-
auth = new PublicOAuthProvider({
|
|
33
|
+
auth = new PublicOAuthProvider({
|
|
34
|
+
credPath: join(dir, 'token.json'),
|
|
35
|
+
machine: { softIdPath: join(dir, 'machine-id') },
|
|
36
|
+
transport,
|
|
37
|
+
});
|
|
31
38
|
break;
|
|
32
39
|
}
|
|
33
40
|
default: {
|
package/dist/hubCapability.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type hub } from '@evomap/evolver-core';
|
|
1
|
+
import { reference, type hub } from '@evomap/evolver-core';
|
|
2
2
|
import { type FetchLike } from './hubFetch.js';
|
|
3
3
|
import { type AntiAbuseTelemetryOptions } from './antiAbuseTelemetry.js';
|
|
4
4
|
export declare const INBOUND_LIMIT = 100;
|
|
@@ -147,6 +147,7 @@ export declare function outboundMaxBodyBytes(env?: Record<string, string | undef
|
|
|
147
147
|
*/
|
|
148
148
|
export declare class PublicHubCapability implements hub.HubCapability {
|
|
149
149
|
private readonly opts;
|
|
150
|
+
readonly referenceScope: reference.ReferenceSessionScope;
|
|
150
151
|
private readonly http;
|
|
151
152
|
private malformedPublish2xxCount;
|
|
152
153
|
private lastMalformedPublish2xxAt;
|
|
@@ -162,6 +163,7 @@ export declare class PublicHubCapability implements hub.HubCapability {
|
|
|
162
163
|
publish(bundle: hub.AssetRecord[], options?: hub.PublishOptions): Promise<hub.PublishReceipt>;
|
|
163
164
|
publishDiagnostics(): hub.PublishReceiptDiagnostics;
|
|
164
165
|
private recordMalformedPublishReceipt;
|
|
166
|
+
readonly references: reference.ReferenceCapability;
|
|
165
167
|
fetch(query: hub.HubQuery): Promise<hub.AssetRecord[]>;
|
|
166
168
|
/**
|
|
167
169
|
* Fetch one asset AND say why, when the answer is not an asset. `fetchAssetById` collapses every outcome to
|
|
@@ -232,4 +234,6 @@ export declare class PublicHubCapability implements hub.HubCapability {
|
|
|
232
234
|
}>;
|
|
233
235
|
};
|
|
234
236
|
capabilities(): Promise<hub.HubManifest>;
|
|
235
|
-
}
|
|
237
|
+
}
|
|
238
|
+
/** Public Hub contract is narrower than local storage; reject, never silently truncate. */
|
|
239
|
+
export declare function normalizePublicReferenceQuery(query: reference.ReferenceQuery): reference.ReferenceQuery;
|
package/dist/hubCapability.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { bootstrap, hub as hubNs, signals, wire } from '@evomap/evolver-core';
|
|
3
|
-
import { AuthError, HubFetch, HubClientError, isHubUnreachableError } from './hubFetch.js';
|
|
2
|
+
import { bootstrap, reference, hub as hubNs, signals, wire } from '@evomap/evolver-core';
|
|
3
|
+
import { AuthError, HubFetch, HubClientError, globalFetchLike, referenceFetchLike, isHubUnreachableError } from './hubFetch.js';
|
|
4
4
|
import { isNodeSecret, parseNodeSecretVersion } from './auth/legacyShim.js';
|
|
5
5
|
import { inboundToAgentEvent, agentEventToOutbound, publishRespToReceipt, searchQueryToFetchWire, searchQueryToSearchOnlyWire, } from './wireMap.js';
|
|
6
6
|
import { antiAbuseTelemetryMode, buildHeartbeatAntiAbuseTelemetry, } from './antiAbuseTelemetry.js';
|
|
@@ -96,6 +96,7 @@ function traceOutboundMaxBodyBytes(env = process.env) {
|
|
|
96
96
|
*/
|
|
97
97
|
export class PublicHubCapability {
|
|
98
98
|
opts;
|
|
99
|
+
referenceScope = new reference.ReferenceSessionScope();
|
|
99
100
|
http;
|
|
100
101
|
malformedPublish2xxCount = 0;
|
|
101
102
|
lastMalformedPublish2xxAt;
|
|
@@ -259,6 +260,7 @@ export class PublicHubCapability {
|
|
|
259
260
|
return Object.keys(meta).length > 0 ? meta : undefined;
|
|
260
261
|
}
|
|
261
262
|
async publish(bundle, options = {}) {
|
|
263
|
+
reference.assertExecutionEligible(bundle, this.referenceScope);
|
|
262
264
|
const normalizedIdempotencyKey = options.idempotencyKey?.trim();
|
|
263
265
|
if (options.idempotencyKey !== undefined && !normalizedIdempotencyKey) {
|
|
264
266
|
return {
|
|
@@ -307,12 +309,26 @@ export class PublicHubCapability {
|
|
|
307
309
|
// Observability must never change publish outcome or retry behavior.
|
|
308
310
|
}
|
|
309
311
|
}
|
|
312
|
+
references = {
|
|
313
|
+
fetch: async (query) => {
|
|
314
|
+
const normalized = normalizePublicReferenceQuery(query);
|
|
315
|
+
const http = new HubFetch({ baseUrl: this.opts.baseUrl, auth: this.auth, senderId: this.opts.senderId,
|
|
316
|
+
fetchFn: this.opts.fetchFn === globalFetchLike ? referenceFetchLike : this.opts.fetchFn });
|
|
317
|
+
const body = await http.call('POST', '/a2a/fetch', gepEnvelope('fetch', {
|
|
318
|
+
...normalized, evidence_mode: 'reference_only',
|
|
319
|
+
}));
|
|
320
|
+
const page = reference.decodeReferencePage(body, true);
|
|
321
|
+
this.referenceScope.remember(page.results.flatMap((p) => [p.gene.asset_id, p.capsule.asset_id, String(p.gene['id']), String(p.capsule['id'])]));
|
|
322
|
+
return page;
|
|
323
|
+
},
|
|
324
|
+
};
|
|
310
325
|
async fetch(query) {
|
|
326
|
+
reference.assertExecutionEligible(query, this.referenceScope);
|
|
311
327
|
// #69: map camelCase SearchQuery → hub snake_case wire (signalsAny → signals) before sending.
|
|
312
328
|
// /a2a/fetch responses are FULL GEP envelopes (buildResponse('fetch', …)); the rows live at payload.results,
|
|
313
329
|
// NOT at the top level. Reading body.results here always yielded [] — every fetch silently returned nothing.
|
|
314
330
|
const body = await this.http.call('POST', '/a2a/fetch', gepEnvelope('fetch', searchQueryToFetchWire(query)));
|
|
315
|
-
return assetsFromBody(body);
|
|
331
|
+
return reference.withReferenceScope(this.referenceScope, () => assetsFromBody(body));
|
|
316
332
|
}
|
|
317
333
|
/**
|
|
318
334
|
* Fetch one asset AND say why, when the answer is not an asset. `fetchAssetById` collapses every outcome to
|
|
@@ -320,12 +336,13 @@ export class PublicHubCapability {
|
|
|
320
336
|
* client refuses" — and the CLI reported both as `not_found` on assets that demonstrably exist (#964).
|
|
321
337
|
*/
|
|
322
338
|
async fetchAssetDeliveryById(assetId, options) {
|
|
339
|
+
reference.assertExecutionEligible(assetId, this.referenceScope);
|
|
323
340
|
const id = assetId.trim();
|
|
324
341
|
if (!id)
|
|
325
342
|
return { status: 'absent' };
|
|
326
343
|
const body = await this.http.call('POST', '/a2a/fetch', gepEnvelope('fetch', { asset_ids: [id] }));
|
|
327
344
|
const matches = [];
|
|
328
|
-
for (const row of assetCandidatesFromBody(body)) {
|
|
345
|
+
for (const row of reference.withReferenceScope(this.referenceScope, () => assetCandidatesFromBody(body))) {
|
|
329
346
|
const asset = unwrapFetchDeliveryRow(row);
|
|
330
347
|
if (!fetchDeliveryIdentityConsistent(row, asset))
|
|
331
348
|
return { status: 'rejected', reason: 'identity_mismatch' };
|
|
@@ -371,6 +388,7 @@ export class PublicHubCapability {
|
|
|
371
388
|
* so text must not go there and paid/full fetch must remain an explicit follow-up.
|
|
372
389
|
*/
|
|
373
390
|
async search(query) {
|
|
391
|
+
reference.assertExecutionEligible(query, this.referenceScope);
|
|
374
392
|
if (query.text && query.text.trim()) {
|
|
375
393
|
// GET /a2a/assets/semantic-search returns a FLAT object keyed `assets` (no GEP envelope), plus a
|
|
376
394
|
// `search_status` (found / degraded(retryable) / low_confidence_only / no_match). Only an explicit
|
|
@@ -381,10 +399,10 @@ export class PublicHubCapability {
|
|
|
381
399
|
...(query.domain !== undefined ? { domain: query.domain } : {}),
|
|
382
400
|
...(query.limit !== undefined ? { limit: query.limit } : {}),
|
|
383
401
|
});
|
|
384
|
-
return semanticSearchAssets(body);
|
|
402
|
+
return reference.withReferenceScope(this.referenceScope, () => semanticSearchAssets(body));
|
|
385
403
|
}
|
|
386
404
|
const body = await this.http.call('POST', '/a2a/fetch', gepEnvelope('fetch', searchQueryToSearchOnlyWire(query)));
|
|
387
|
-
return signalSearchAssets(body);
|
|
405
|
+
return reference.withReferenceScope(this.referenceScope, () => signalSearchAssets(body));
|
|
388
406
|
}
|
|
389
407
|
agentDirectory = {
|
|
390
408
|
search: async (request) => {
|
|
@@ -469,6 +487,8 @@ export class PublicHubCapability {
|
|
|
469
487
|
* Costs hub credits per the hub's memory pricing (caller gates on enablement).
|
|
470
488
|
*/
|
|
471
489
|
async recordOutcome(report) {
|
|
490
|
+
if (!reference.isExecutionEligible(report, this.referenceScope))
|
|
491
|
+
return { recorded: false, reason: 'reference_not_execution_evidence' };
|
|
472
492
|
const signals = report.signals.map((s) => String(s).trim()).filter(Boolean);
|
|
473
493
|
if (signals.length === 0)
|
|
474
494
|
return { recorded: false, reason: 'no_signals' }; // hub rejects empty signals; skip the paid call
|
|
@@ -489,6 +509,8 @@ export class PublicHubCapability {
|
|
|
489
509
|
}
|
|
490
510
|
}
|
|
491
511
|
async recordMemoryEvent(report) {
|
|
512
|
+
if (!reference.isExecutionEligible(report, this.referenceScope))
|
|
513
|
+
return { recorded: false, reason: 'reference_not_execution_evidence' };
|
|
492
514
|
const sender = this.opts.senderId()?.trim();
|
|
493
515
|
if (!sender)
|
|
494
516
|
return { recorded: false, reason: 'sender_id_required' };
|
|
@@ -507,6 +529,8 @@ export class PublicHubCapability {
|
|
|
507
529
|
}
|
|
508
530
|
}
|
|
509
531
|
async recordReuseResult(report) {
|
|
532
|
+
if (!reference.isExecutionEligible(report, this.referenceScope))
|
|
533
|
+
return { recorded: false, reason: 'reference_not_execution_evidence' };
|
|
510
534
|
const assetId = report.assetId.trim();
|
|
511
535
|
if (!assetId)
|
|
512
536
|
return { recorded: false, reason: 'asset_id_required' };
|
|
@@ -553,6 +577,8 @@ export class PublicHubCapability {
|
|
|
553
577
|
}
|
|
554
578
|
}
|
|
555
579
|
async recordLearningAssetUsage(report) {
|
|
580
|
+
if (!reference.isExecutionEligible(report, this.referenceScope))
|
|
581
|
+
return { recorded: false, results: [], reason: 'reference_not_execution_evidence' };
|
|
556
582
|
if (!this.opts.senderId()?.trim())
|
|
557
583
|
return { recorded: false, reason: 'sender_id_required', results: [] };
|
|
558
584
|
const sourceEventId = trimStringField(report.sourceEventId, 160);
|
|
@@ -707,6 +733,7 @@ export class PublicHubCapability {
|
|
|
707
733
|
return { claimId: event.id };
|
|
708
734
|
},
|
|
709
735
|
complete: async (claimId, _result, context) => {
|
|
736
|
+
reference.assertExecutionEligible({ result: _result, payload: context }, this.referenceScope);
|
|
710
737
|
if (typeof context?.taskId !== 'string' || !context.taskId.trim()
|
|
711
738
|
|| typeof context.assetId !== 'string' || !context.assetId.trim()) {
|
|
712
739
|
throw new hubNs.PublishRejectedError('invalid_task_completion', true, 'task completion requires explicit taskId and assetId', undefined, false);
|
|
@@ -867,6 +894,7 @@ function searchAssets(value, source) {
|
|
|
867
894
|
});
|
|
868
895
|
}
|
|
869
896
|
function semanticSearchAssets(body) {
|
|
897
|
+
reference.assertExecutionEligible(body);
|
|
870
898
|
const status = stringField(body, 'search_status');
|
|
871
899
|
if (status === 'degraded' || body['retryable'] === true)
|
|
872
900
|
throw new Error('semantic_search_degraded');
|
|
@@ -887,6 +915,7 @@ function semanticSearchAssets(body) {
|
|
|
887
915
|
throw new Error('semantic_search_status_invalid');
|
|
888
916
|
}
|
|
889
917
|
function signalSearchAssets(body) {
|
|
918
|
+
reference.assertExecutionEligible(body);
|
|
890
919
|
const payload = asRecord(body['payload']);
|
|
891
920
|
return searchAssets(payload?.['results'], 'signal_search');
|
|
892
921
|
}
|
|
@@ -997,6 +1026,7 @@ function dryRunRecipeReceipt(action, recipeId, extra = {}) {
|
|
|
997
1026
|
};
|
|
998
1027
|
}
|
|
999
1028
|
function assetCandidatesFromBody(body) {
|
|
1029
|
+
reference.assertExecutionEligible(body);
|
|
1000
1030
|
const payload = asRecord(body['payload']);
|
|
1001
1031
|
const candidates = [
|
|
1002
1032
|
body['asset'],
|
|
@@ -1606,4 +1636,12 @@ function forceUpdateFromRecord(value) {
|
|
|
1606
1636
|
...(staggerWindowMs !== undefined ? { stagger_window_ms: staggerWindowMs } : {}),
|
|
1607
1637
|
};
|
|
1608
1638
|
return directive.required_version || directive.manifest !== undefined ? directive : undefined;
|
|
1639
|
+
}
|
|
1640
|
+
/** Public Hub contract is narrower than local storage; reject, never silently truncate. */
|
|
1641
|
+
export function normalizePublicReferenceQuery(query) {
|
|
1642
|
+
const normalized = reference.normalizeReferenceQuery(query);
|
|
1643
|
+
if ((normalized.max_assets ?? 20) > 50 || (normalized.query?.length ?? 0) > 500 || (normalized.signals?.length ?? 0) > 50) {
|
|
1644
|
+
throw new Error('reference_public_query_limit: max_assets<=50, query<=500, signals<=50');
|
|
1645
|
+
}
|
|
1646
|
+
return normalized;
|
|
1609
1647
|
}
|
package/dist/hubFetch.d.ts
CHANGED
|
@@ -144,6 +144,10 @@ type RawFetch = (url: string, init: Record<string, unknown>) => Promise<HubFetch
|
|
|
144
144
|
export declare function _setFetchImplForTest(fn?: RawFetch): void;
|
|
145
145
|
/** Test seam: reset the one-time insecure-warning latch. */
|
|
146
146
|
export declare function _resetInsecureWarningForTest(): void;
|
|
147
|
+
/** Reference pages carry full pairs and can exceed Bun's npm-undici response-stream boundary.
|
|
148
|
+
* Use Bun's native stream implementation there, retaining the shared authenticated HubFetch,
|
|
149
|
+
* redirect refusal, body/deadline limits and explicit TLS verification. Node stays on undici. */
|
|
150
|
+
export declare const referenceFetchLike: FetchLike;
|
|
147
151
|
/** Default production transport: secure mode = https guard + forced TLS dispatcher; escape-hatch mode = skip both (local dev). */
|
|
148
152
|
export declare const globalFetchLike: FetchLike;
|
|
149
153
|
export {};
|
package/dist/hubFetch.js
CHANGED
|
@@ -751,6 +751,22 @@ function warnInsecureOnce() {
|
|
|
751
751
|
}
|
|
752
752
|
/** Test seam: reset the one-time insecure-warning latch. */
|
|
753
753
|
export function _resetInsecureWarningForTest() { _insecureWarned = false; }
|
|
754
|
+
/** Reference pages carry full pairs and can exceed Bun's npm-undici response-stream boundary.
|
|
755
|
+
* Use Bun's native stream implementation there, retaining the shared authenticated HubFetch,
|
|
756
|
+
* redirect refusal, body/deadline limits and explicit TLS verification. Node stays on undici. */
|
|
757
|
+
export const referenceFetchLike = async (url, init) => {
|
|
758
|
+
if (!globalThis.Bun)
|
|
759
|
+
return globalFetchLike(url, init);
|
|
760
|
+
const insecure = insecureAllowed(process.env);
|
|
761
|
+
if (insecure)
|
|
762
|
+
warnInsecureOnce();
|
|
763
|
+
else
|
|
764
|
+
assertHubUrlSecure(url);
|
|
765
|
+
const response = await globalThis.fetch(url, { ...init, redirect: 'manual',
|
|
766
|
+
...(!insecure ? { tls: { rejectUnauthorized: true } } : {}),
|
|
767
|
+
});
|
|
768
|
+
return response;
|
|
769
|
+
};
|
|
754
770
|
/** Default production transport: secure mode = https guard + forced TLS dispatcher; escape-hatch mode = skip both (local dev). */
|
|
755
771
|
export const globalFetchLike = async (url, init) => {
|
|
756
772
|
const raw = { ...init, redirect: 'manual' };
|
package/dist/hubReuse.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// - payload cache: assetId → phase-3 payload (content-addressed, long/permanent, bounded LRU). A cached
|
|
14
14
|
// payload → ZERO fetch. Both clocks are injected so TTL/eviction is deterministic and testable.
|
|
15
15
|
import { createHash } from 'node:crypto';
|
|
16
|
-
import { hub, algo, signals as signalNs, wire } from '@evomap/evolver-core';
|
|
16
|
+
import { reference, hub, algo, signals as signalNs, wire } from '@evomap/evolver-core';
|
|
17
17
|
const { scoreSearchResults, decideReuse, DEFAULT_MIN_REUSE_SCORE, } = hub;
|
|
18
18
|
const GENE_WIRE_KEYS = new Set([
|
|
19
19
|
'type',
|
|
@@ -280,6 +280,7 @@ export function stripHubDeliveryMetadataForIntegrity(rec) {
|
|
|
280
280
|
* price/credit field by simply not reading it — the core HubMetadata has no slot for cost.
|
|
281
281
|
*/
|
|
282
282
|
export function toHubMetadata(rec) {
|
|
283
|
+
reference.assertExecutionEligible(rec);
|
|
283
284
|
const r = rec;
|
|
284
285
|
const assetId = String(r['asset_id'] ?? r['assetId'] ?? '');
|
|
285
286
|
const updatedAt = ts(r['updated_at'] ?? r['updatedAt'] ?? r['created_at'] ?? r['createdAt']);
|
|
@@ -303,6 +304,7 @@ export function toHubMetadata(rec) {
|
|
|
303
304
|
}
|
|
304
305
|
/** Map a fetched hub asset (full payload) → a selection candidate so it competes in candidateAssembly. */
|
|
305
306
|
export function toGeneCandidate(rec) {
|
|
307
|
+
reference.assertExecutionEligible(rec);
|
|
306
308
|
const r = rec;
|
|
307
309
|
const assetId = String(r['asset_id'] ?? r['assetId'] ?? '');
|
|
308
310
|
const geneId = typeof r['id'] === 'string' ? r['id'] : assetId;
|
|
@@ -562,6 +564,8 @@ function normalizeMatchedAssetId(asset, assetId) {
|
|
|
562
564
|
return normalized;
|
|
563
565
|
}
|
|
564
566
|
export function assetMatchesId(asset, assetId) {
|
|
567
|
+
if (!reference.isExecutionEligible(asset) || !reference.isExecutionEligible(assetId))
|
|
568
|
+
return false;
|
|
565
569
|
if (!asset)
|
|
566
570
|
return false;
|
|
567
571
|
const record = asset;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evomap/evolver-adapter-public",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.35",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@evomap/atp-sdk": "^0.1.0",
|
|
20
|
-
"@evomap/evolver-core": "2.0.
|
|
20
|
+
"@evomap/evolver-core": "2.0.35",
|
|
21
21
|
"undici": "^6.27.0"
|
|
22
22
|
},
|
|
23
23
|
"optionalDependencies": {
|