@evomap/evolver-adapter-public 2.0.34 → 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.
@@ -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;
@@ -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
  }
@@ -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.34",
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.34",
20
+ "@evomap/evolver-core": "2.0.35",
21
21
  "undici": "^6.27.0"
22
22
  },
23
23
  "optionalDependencies": {