@evomap/evolver-adapter-public 2.0.31 → 2.0.33

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/connect.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { hub } from '@evomap/evolver-core';
2
2
  import { PublicHubCapability } from './hubCapability.js';
3
3
  import type { AntiAbuseTelemetryOptions } from './antiAbuseTelemetry.js';
4
+ import type { MalformedPublishReceiptEvent } from './hubCapability.js';
4
5
  import { type FetchLike } from './hubFetch.js';
5
6
  import { type OAuthTransport } from './auth/oauthDeviceToken.js';
6
7
  export type AuthMode = 'oauth' | 'keypair' | 'legacy';
@@ -32,6 +33,8 @@ export interface ConnectPublicOptions {
32
33
  }>;
33
34
  /** Optional anti-abuse metadata context for heartbeat payloads. */
34
35
  antiAbuse?: AntiAbuseTelemetryOptions;
36
+ /** Optional non-sensitive notification when publish returns malformed 2xx JSON. */
37
+ onMalformedPublishReceipt?: (event: MalformedPublishReceiptEvent) => void;
35
38
  }
36
39
  /** 选址装配公版 hub(M6-7): 按 authMode 组 AuthProvider(M6-5) + PublicHubCapability(M6-6). */
37
40
  export declare function connectPublicHub(opts: ConnectPublicOptions): {
package/dist/connect.js CHANGED
@@ -35,7 +35,17 @@ export function connectPublicHub(opts) {
35
35
  throw new Error(`未知 authMode: ${String(_x)}`);
36
36
  }
37
37
  }
38
- return { hub: new PublicHubCapability({ baseUrl: opts.hubUrl, auth, fetchFn, senderId: opts.senderId, antiAbuse: withWorkspaceIdResolver(opts.antiAbuse) }), auth };
38
+ return {
39
+ hub: new PublicHubCapability({
40
+ baseUrl: opts.hubUrl,
41
+ auth,
42
+ fetchFn,
43
+ senderId: opts.senderId,
44
+ antiAbuse: withWorkspaceIdResolver(opts.antiAbuse),
45
+ ...(opts.onMalformedPublishReceipt ? { onMalformedPublishReceipt: opts.onMalformedPublishReceipt } : {}),
46
+ }),
47
+ auth,
48
+ };
39
49
  }
40
50
  function withWorkspaceIdResolver(antiAbuse) {
41
51
  if (antiAbuse?.workspaceId || antiAbuse?.workspaceIdResolver)
@@ -65,6 +65,10 @@ export declare class MalformedAccountAssetPageError extends Error {
65
65
  export declare function gepEnvelope(messageType: string, payload: unknown, options?: {
66
66
  messageId?: string;
67
67
  }): Record<string, unknown>;
68
+ export interface MalformedPublishReceiptEvent {
69
+ httpStatus: number;
70
+ occurredAt: number;
71
+ }
68
72
  export interface PublicHubOptions {
69
73
  baseUrl: string;
70
74
  auth: hub.AuthProvider;
@@ -74,6 +78,8 @@ export interface PublicHubOptions {
74
78
  subscribePollMs?: number;
75
79
  /** Public Hub anti-abuse heartbeat metadata. Defaults to env-controlled heartbeat mode. */
76
80
  antiAbuse?: AntiAbuseTelemetryOptions;
81
+ /** Best-effort notification for malformed 2xx publish responses; receives no Hub body or credential data. */
82
+ onMalformedPublishReceipt?: (event: MalformedPublishReceiptEvent) => void;
77
83
  }
78
84
  export interface PublicHelloResult {
79
85
  ok: boolean;
@@ -142,6 +148,9 @@ export declare function outboundMaxBodyBytes(env?: Record<string, string | undef
142
148
  export declare class PublicHubCapability implements hub.HubCapability {
143
149
  private readonly opts;
144
150
  private readonly http;
151
+ private malformedPublish2xxCount;
152
+ private lastMalformedPublish2xxAt;
153
+ private lastMalformedPublish2xxStatus;
145
154
  readonly auth: hub.AuthProvider;
146
155
  readonly recipes: hub.RecipeCapability;
147
156
  constructor(opts: PublicHubOptions);
@@ -151,6 +160,8 @@ export declare class PublicHubCapability implements hub.HubCapability {
151
160
  heartbeat(opts?: PublicHeartbeatOptions): Promise<PublicHeartbeatResult>;
152
161
  private heartbeatMeta;
153
162
  publish(bundle: hub.AssetRecord[], options?: hub.PublishOptions): Promise<hub.PublishReceipt>;
163
+ publishDiagnostics(): hub.PublishReceiptDiagnostics;
164
+ private recordMalformedPublishReceipt;
154
165
  fetch(query: hub.HubQuery): Promise<hub.AssetRecord[]>;
155
166
  /**
156
167
  * Fetch one asset AND say why, when the answer is not an asset. `fetchAssetById` collapses every outcome to
@@ -97,6 +97,9 @@ function traceOutboundMaxBodyBytes(env = process.env) {
97
97
  export class PublicHubCapability {
98
98
  opts;
99
99
  http;
100
+ malformedPublish2xxCount = 0;
101
+ lastMalformedPublish2xxAt;
102
+ lastMalformedPublish2xxStatus;
100
103
  auth;
101
104
  recipes = {
102
105
  create: async (request) => this.createRecipe(request),
@@ -272,15 +275,38 @@ export class PublicHubCapability {
272
275
  ? stablePublishMessageId(idempotencyKey)
273
276
  : undefined;
274
277
  const body = await this.http.call('POST', '/a2a/publish', gepEnvelope('publish', { assets: bundle }, messageId ? { messageId } : {}));
275
- return publishRespToReceipt(200, body);
278
+ const receipt = publishRespToReceipt(200, body);
279
+ if (receipt.rejection?.code === 'invalid_payload')
280
+ this.recordMalformedPublishReceipt(200);
281
+ return receipt;
276
282
  }
277
283
  catch (e) {
278
284
  if (e instanceof HubClientError) {
279
- return publishRespToReceipt(e.status, e.body ?? {}, e.retryAfterMs);
285
+ const receipt = publishRespToReceipt(e.status, e.body ?? {}, e.retryAfterMs);
286
+ return receipt;
280
287
  }
281
288
  throw e; // 5xx/网络 → 重试
282
289
  }
283
290
  }
291
+ publishDiagnostics() {
292
+ return {
293
+ malformed2xxCount: this.malformedPublish2xxCount,
294
+ ...(this.lastMalformedPublish2xxAt !== undefined ? { lastMalformed2xxAt: this.lastMalformedPublish2xxAt } : {}),
295
+ ...(this.lastMalformedPublish2xxStatus !== undefined ? { lastMalformed2xxStatus: this.lastMalformedPublish2xxStatus } : {}),
296
+ };
297
+ }
298
+ recordMalformedPublishReceipt(httpStatus) {
299
+ const occurredAt = Date.now();
300
+ this.malformedPublish2xxCount += 1;
301
+ this.lastMalformedPublish2xxAt = occurredAt;
302
+ this.lastMalformedPublish2xxStatus = httpStatus;
303
+ try {
304
+ this.opts.onMalformedPublishReceipt?.({ httpStatus, occurredAt });
305
+ }
306
+ catch {
307
+ // Observability must never change publish outcome or retry behavior.
308
+ }
309
+ }
284
310
  async fetch(query) {
285
311
  // #69: map camelCase SearchQuery → hub snake_case wire (signalsAny → signals) before sending.
286
312
  // /a2a/fetch responses are FULL GEP envelopes (buildResponse('fetch', …)); the rows live at payload.results,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evomap/evolver-adapter-public",
3
- "version": "2.0.31",
3
+ "version": "2.0.33",
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.31",
20
+ "@evomap/evolver-core": "2.0.33",
21
21
  "undici": "^6.27.0"
22
22
  },
23
23
  "optionalDependencies": {