@covia/covia-sdk 1.7.2 → 1.7.3

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/README.md CHANGED
@@ -577,12 +577,14 @@ The SDK provides a hierarchy of typed errors:
577
577
 
578
578
  ```typescript
579
579
  import {
580
+ Venue,
580
581
  CoviaError, // Base error
581
582
  GridError, // HTTP API errors (4xx/5xx)
582
583
  NotFoundError, // 404 responses
583
584
  AssetNotFoundError, // Asset not found
584
585
  JobNotFoundError, // Job not found
585
- CoviaConnectionError,// Connection failures
586
+ CoviaConnectionError,// Transport/connect failures (url, method, attempts)
587
+ VenueIdentityChangedError, // Same address now reports a different DID
586
588
  CoviaTimeoutError, // Timeout exceeded
587
589
  JobFailedError, // Job finished with non-COMPLETE status
588
590
  RateLimitError, // 429 after bounded retries (carries retryAfterSeconds)
@@ -609,6 +611,32 @@ try {
609
611
  }
610
612
  ```
611
613
 
614
+ Transport failures include the exact request target and method. A failed
615
+ `Venue.connect()` additionally includes every candidate and failed validation
616
+ request:
617
+
618
+ ```typescript
619
+ try {
620
+ await Venue.connect("localhost:8080");
621
+ } catch (err) {
622
+ if (err instanceof CoviaConnectionError) {
623
+ console.error(err.candidates);
624
+ for (const attempt of err.attempts) {
625
+ console.error(attempt.method, attempt.url, attempt.error.message);
626
+ }
627
+ }
628
+ }
629
+
630
+ try {
631
+ await venue.status();
632
+ } catch (err) {
633
+ if (err instanceof VenueIdentityChangedError) {
634
+ console.error(`Venue changed from ${err.oldDid} to ${err.newDid}`);
635
+ // Reconnect and re-authorise explicitly; the old handle is not rebound.
636
+ }
637
+ }
638
+ ```
639
+
612
640
  ## Job Status
613
641
 
614
642
  ```typescript
package/dist/index.d.mts CHANGED
@@ -715,6 +715,8 @@ declare class Venue implements VenueInterface {
715
715
  * responded (the https candidate if an http fallback failed; the resolved
716
716
  * endpoint for a did:web id), and `venue.venueId` is the DID the venue
717
717
  * reported. The validated API root is `${venue.baseUrl}/api/v1`.
718
+ * @throws {CoviaConnectionError} If no candidate can be validated.
719
+ * @throws {VenueIdentityChangedError} If a known/resolved DID reports a different identity.
718
720
  */
719
721
  static connect(venueId: string | Venue, auth?: Auth): Promise<Venue>;
720
722
  /**
@@ -760,6 +762,7 @@ declare class Venue implements VenueInterface {
760
762
  /**
761
763
  * Get venue status
762
764
  * @returns {Promise<StatusData>}
765
+ * @throws {VenueIdentityChangedError} If this address reports a different known DID.
763
766
  */
764
767
  status(): Promise<StatusData>;
765
768
  /**
@@ -774,6 +777,7 @@ declare class Venue implements VenueInterface {
774
777
  * @param options.pollIntervalMs - Delay between polls (default 1000).
775
778
  * @returns The ready {@link StatusData}.
776
779
  * @throws {CoviaTimeoutError} If the venue is not ready within the timeout.
780
+ * @throws {VenueIdentityChangedError} Immediately if the venue's DID changed.
777
781
  */
778
782
  waitUntilReady(options?: {
779
783
  timeoutMs?: number;
@@ -1323,9 +1327,47 @@ declare class GridError extends CoviaError {
1323
1327
  responseBody: unknown;
1324
1328
  constructor(statusCode: number, message: string, responseBody?: unknown);
1325
1329
  }
1326
- /** Raised when the SDK cannot connect to the venue. */
1330
+ /** One failed HTTP request made while resolving/validating a venue connection. */
1331
+ interface ConnectionAttempt {
1332
+ readonly url: string;
1333
+ readonly method: string;
1334
+ readonly error: CoviaError;
1335
+ }
1336
+ interface CoviaConnectionErrorOptions {
1337
+ /** Exact request target for a single transport failure. */
1338
+ url?: string;
1339
+ /** HTTP method for a single transport failure. */
1340
+ method?: string;
1341
+ /** Original exception, or the final failed attempt for an aggregate error. */
1342
+ cause?: unknown;
1343
+ /** Ordered venue base URLs considered by `Venue.connect()`. */
1344
+ candidates?: readonly string[];
1345
+ /** Ordered failed requests made while validating those candidates. */
1346
+ attempts?: readonly ConnectionAttempt[];
1347
+ }
1348
+ /**
1349
+ * Raised when an HTTP request cannot be made, or when `Venue.connect()` cannot
1350
+ * validate any candidate. HTTP responses still use `GridError`; this class is
1351
+ * for transport failures and connection-attempt aggregation.
1352
+ */
1327
1353
  declare class CoviaConnectionError extends CoviaError {
1328
- constructor(message: string);
1354
+ readonly url: string | null;
1355
+ readonly method: string | null;
1356
+ readonly cause: unknown;
1357
+ readonly candidates: readonly string[];
1358
+ readonly attempts: readonly ConnectionAttempt[];
1359
+ constructor(message: string, options?: CoviaConnectionErrorOptions);
1360
+ }
1361
+ /**
1362
+ * Raised when a known venue address reports a different DID. The instance
1363
+ * remains bound to `oldDid`; callers must explicitly reconnect/re-authorise
1364
+ * against `newDid` rather than silently continuing under a new identity.
1365
+ */
1366
+ declare class VenueIdentityChangedError extends CoviaError {
1367
+ readonly oldDid: string;
1368
+ readonly newDid: string;
1369
+ readonly baseUrl: string;
1370
+ constructor(oldDid: string, newDid: string, baseUrl: string);
1329
1371
  }
1330
1372
  /** Raised when an operation or polling loop times out. */
1331
1373
  declare class CoviaTimeoutError extends CoviaError {
@@ -1638,4 +1680,4 @@ declare function grant(ownerPrivateKey: Uint8Array, audienceDID: string, withRes
1638
1680
  */
1639
1681
  declare function relayDelegation(privateKey: Uint8Array, venueDID: string, lifetimeSeconds: number, caps?: UCANCapability[]): string;
1640
1682
 
1641
- export { type AdapterInfo, AdapterManager, type AdaptersResult, Agent, type AgentCancelTaskInput, type AgentCard, type AgentChatInput, type AgentChatResult, type AgentCompleteTaskResult, type AgentContextInput, type AgentCreateInput, type AgentCreateResult, type AgentDeleteInput, type AgentDeleteResult, type AgentFailTaskResult, type AgentForkInput, type AgentForkResult, type AgentInfoResult, type AgentListInput, type AgentListResult, AgentManager, type AgentMessageInput, type AgentMessageResult, type AgentRequestInput, type AgentRequestResult, type AgentResumeInput, AgentStatus, type AgentSuspendResult, type AgentTriggerInput, type AgentTriggerResult, type AgentUpdateInput, Asset, type AssetID, type AssetList, type AssetListOptions, AssetManager, type AssetMetadata, type AssetMetadataStore, AssetNotFoundError, type AssetPinResult, Auth, BasicAuth, BearerAuth, ChatSession, type ContentDetails, type ContentHashResult, CoviaConnectionError, CoviaError, CoviaTimeoutError, type Credentials, CredentialsHTTP, type DIDDocument, type DIDURL, DataAsset, Ed25519Auth, type FunctionInfo, type FunctionsResult, Grid, GridError, type GroupCount, type InvokeOptions, type InvokePayload, Job, JobFailedError, JobManager, type JobMetadata, JobNotFoundError, JobStatus, KeyPairAuth, type MCPDiscovery, Namespace, NoAuth, NotFoundError, Operation, type OperationDetails, type OperationInfo, OperationManager, type OperationPayload, type OperationRunner, RateLimitError, RunStatus, type SSEEvent, type SecretExtractInput, type SecretExtractResult, SecretManager, type SecretSetInput, type SecretSetResult, type StatsData, type StatusData, type UCANAttenuation, type UCANCapability, type UCANIssueInput, type UCANIssueResult, UCANManager, type UCANVerifyResult, VENUE_RELAY, Venue, type VenueConstructor, type VenueData, type VenueInterface, type VenueOptions, type WorkspaceAggregateResult, type WorkspaceAppendInput, type WorkspaceAppendResult, type WorkspaceCopyResult, type WorkspaceCountResult, type WorkspaceDeleteInput, type WorkspaceDeleteResult, type WorkspaceInspectInput, type WorkspaceInspectResult, type WorkspaceListInput, type WorkspaceListResult, WorkspaceManager, type WorkspaceReadInput, type WorkspaceReadResult, type WorkspaceSliceInput, type WorkspaceSliceResult, type WorkspaceWriteInput, type WorkspaceWriteResult, assetHash, createSSEEvent, createUCANJWT, decodePublicKey, didFor, didFromPublicKey, didMethod, didUrl, encodePublicKey, fetchStreamWithError, fetchWithError, generateKeyPair, getAssetIdFromPath, getAssetIdFromVenueId, getAssetMetadataStore, getParsedAssetId, grant, hexToPrivateKey, identityToken, isDid, isJobComplete, isJobFinished, isJobPaused, logger, parseDidUrl, parseRetryAfterMs, parseSSEStream, privateKeyToHex, relayDelegation, retryDelayMs, setAssetMetadataStore, venueBaseUrlCandidates };
1683
+ export { type AdapterInfo, AdapterManager, type AdaptersResult, Agent, type AgentCancelTaskInput, type AgentCard, type AgentChatInput, type AgentChatResult, type AgentCompleteTaskResult, type AgentContextInput, type AgentCreateInput, type AgentCreateResult, type AgentDeleteInput, type AgentDeleteResult, type AgentFailTaskResult, type AgentForkInput, type AgentForkResult, type AgentInfoResult, type AgentListInput, type AgentListResult, AgentManager, type AgentMessageInput, type AgentMessageResult, type AgentRequestInput, type AgentRequestResult, type AgentResumeInput, AgentStatus, type AgentSuspendResult, type AgentTriggerInput, type AgentTriggerResult, type AgentUpdateInput, Asset, type AssetID, type AssetList, type AssetListOptions, AssetManager, type AssetMetadata, type AssetMetadataStore, AssetNotFoundError, type AssetPinResult, Auth, BasicAuth, BearerAuth, ChatSession, type ConnectionAttempt, type ContentDetails, type ContentHashResult, CoviaConnectionError, type CoviaConnectionErrorOptions, CoviaError, CoviaTimeoutError, type Credentials, CredentialsHTTP, type DIDDocument, type DIDURL, DataAsset, Ed25519Auth, type FunctionInfo, type FunctionsResult, Grid, GridError, type GroupCount, type InvokeOptions, type InvokePayload, Job, JobFailedError, JobManager, type JobMetadata, JobNotFoundError, JobStatus, KeyPairAuth, type MCPDiscovery, Namespace, NoAuth, NotFoundError, Operation, type OperationDetails, type OperationInfo, OperationManager, type OperationPayload, type OperationRunner, RateLimitError, RunStatus, type SSEEvent, type SecretExtractInput, type SecretExtractResult, SecretManager, type SecretSetInput, type SecretSetResult, type StatsData, type StatusData, type UCANAttenuation, type UCANCapability, type UCANIssueInput, type UCANIssueResult, UCANManager, type UCANVerifyResult, VENUE_RELAY, Venue, type VenueConstructor, type VenueData, VenueIdentityChangedError, type VenueInterface, type VenueOptions, type WorkspaceAggregateResult, type WorkspaceAppendInput, type WorkspaceAppendResult, type WorkspaceCopyResult, type WorkspaceCountResult, type WorkspaceDeleteInput, type WorkspaceDeleteResult, type WorkspaceInspectInput, type WorkspaceInspectResult, type WorkspaceListInput, type WorkspaceListResult, WorkspaceManager, type WorkspaceReadInput, type WorkspaceReadResult, type WorkspaceSliceInput, type WorkspaceSliceResult, type WorkspaceWriteInput, type WorkspaceWriteResult, assetHash, createSSEEvent, createUCANJWT, decodePublicKey, didFor, didFromPublicKey, didMethod, didUrl, encodePublicKey, fetchStreamWithError, fetchWithError, generateKeyPair, getAssetIdFromPath, getAssetIdFromVenueId, getAssetMetadataStore, getParsedAssetId, grant, hexToPrivateKey, identityToken, isDid, isJobComplete, isJobFinished, isJobPaused, logger, parseDidUrl, parseRetryAfterMs, parseSSEStream, privateKeyToHex, relayDelegation, retryDelayMs, setAssetMetadataStore, venueBaseUrlCandidates };
package/dist/index.d.ts CHANGED
@@ -715,6 +715,8 @@ declare class Venue implements VenueInterface {
715
715
  * responded (the https candidate if an http fallback failed; the resolved
716
716
  * endpoint for a did:web id), and `venue.venueId` is the DID the venue
717
717
  * reported. The validated API root is `${venue.baseUrl}/api/v1`.
718
+ * @throws {CoviaConnectionError} If no candidate can be validated.
719
+ * @throws {VenueIdentityChangedError} If a known/resolved DID reports a different identity.
718
720
  */
719
721
  static connect(venueId: string | Venue, auth?: Auth): Promise<Venue>;
720
722
  /**
@@ -760,6 +762,7 @@ declare class Venue implements VenueInterface {
760
762
  /**
761
763
  * Get venue status
762
764
  * @returns {Promise<StatusData>}
765
+ * @throws {VenueIdentityChangedError} If this address reports a different known DID.
763
766
  */
764
767
  status(): Promise<StatusData>;
765
768
  /**
@@ -774,6 +777,7 @@ declare class Venue implements VenueInterface {
774
777
  * @param options.pollIntervalMs - Delay between polls (default 1000).
775
778
  * @returns The ready {@link StatusData}.
776
779
  * @throws {CoviaTimeoutError} If the venue is not ready within the timeout.
780
+ * @throws {VenueIdentityChangedError} Immediately if the venue's DID changed.
777
781
  */
778
782
  waitUntilReady(options?: {
779
783
  timeoutMs?: number;
@@ -1323,9 +1327,47 @@ declare class GridError extends CoviaError {
1323
1327
  responseBody: unknown;
1324
1328
  constructor(statusCode: number, message: string, responseBody?: unknown);
1325
1329
  }
1326
- /** Raised when the SDK cannot connect to the venue. */
1330
+ /** One failed HTTP request made while resolving/validating a venue connection. */
1331
+ interface ConnectionAttempt {
1332
+ readonly url: string;
1333
+ readonly method: string;
1334
+ readonly error: CoviaError;
1335
+ }
1336
+ interface CoviaConnectionErrorOptions {
1337
+ /** Exact request target for a single transport failure. */
1338
+ url?: string;
1339
+ /** HTTP method for a single transport failure. */
1340
+ method?: string;
1341
+ /** Original exception, or the final failed attempt for an aggregate error. */
1342
+ cause?: unknown;
1343
+ /** Ordered venue base URLs considered by `Venue.connect()`. */
1344
+ candidates?: readonly string[];
1345
+ /** Ordered failed requests made while validating those candidates. */
1346
+ attempts?: readonly ConnectionAttempt[];
1347
+ }
1348
+ /**
1349
+ * Raised when an HTTP request cannot be made, or when `Venue.connect()` cannot
1350
+ * validate any candidate. HTTP responses still use `GridError`; this class is
1351
+ * for transport failures and connection-attempt aggregation.
1352
+ */
1327
1353
  declare class CoviaConnectionError extends CoviaError {
1328
- constructor(message: string);
1354
+ readonly url: string | null;
1355
+ readonly method: string | null;
1356
+ readonly cause: unknown;
1357
+ readonly candidates: readonly string[];
1358
+ readonly attempts: readonly ConnectionAttempt[];
1359
+ constructor(message: string, options?: CoviaConnectionErrorOptions);
1360
+ }
1361
+ /**
1362
+ * Raised when a known venue address reports a different DID. The instance
1363
+ * remains bound to `oldDid`; callers must explicitly reconnect/re-authorise
1364
+ * against `newDid` rather than silently continuing under a new identity.
1365
+ */
1366
+ declare class VenueIdentityChangedError extends CoviaError {
1367
+ readonly oldDid: string;
1368
+ readonly newDid: string;
1369
+ readonly baseUrl: string;
1370
+ constructor(oldDid: string, newDid: string, baseUrl: string);
1329
1371
  }
1330
1372
  /** Raised when an operation or polling loop times out. */
1331
1373
  declare class CoviaTimeoutError extends CoviaError {
@@ -1638,4 +1680,4 @@ declare function grant(ownerPrivateKey: Uint8Array, audienceDID: string, withRes
1638
1680
  */
1639
1681
  declare function relayDelegation(privateKey: Uint8Array, venueDID: string, lifetimeSeconds: number, caps?: UCANCapability[]): string;
1640
1682
 
1641
- export { type AdapterInfo, AdapterManager, type AdaptersResult, Agent, type AgentCancelTaskInput, type AgentCard, type AgentChatInput, type AgentChatResult, type AgentCompleteTaskResult, type AgentContextInput, type AgentCreateInput, type AgentCreateResult, type AgentDeleteInput, type AgentDeleteResult, type AgentFailTaskResult, type AgentForkInput, type AgentForkResult, type AgentInfoResult, type AgentListInput, type AgentListResult, AgentManager, type AgentMessageInput, type AgentMessageResult, type AgentRequestInput, type AgentRequestResult, type AgentResumeInput, AgentStatus, type AgentSuspendResult, type AgentTriggerInput, type AgentTriggerResult, type AgentUpdateInput, Asset, type AssetID, type AssetList, type AssetListOptions, AssetManager, type AssetMetadata, type AssetMetadataStore, AssetNotFoundError, type AssetPinResult, Auth, BasicAuth, BearerAuth, ChatSession, type ContentDetails, type ContentHashResult, CoviaConnectionError, CoviaError, CoviaTimeoutError, type Credentials, CredentialsHTTP, type DIDDocument, type DIDURL, DataAsset, Ed25519Auth, type FunctionInfo, type FunctionsResult, Grid, GridError, type GroupCount, type InvokeOptions, type InvokePayload, Job, JobFailedError, JobManager, type JobMetadata, JobNotFoundError, JobStatus, KeyPairAuth, type MCPDiscovery, Namespace, NoAuth, NotFoundError, Operation, type OperationDetails, type OperationInfo, OperationManager, type OperationPayload, type OperationRunner, RateLimitError, RunStatus, type SSEEvent, type SecretExtractInput, type SecretExtractResult, SecretManager, type SecretSetInput, type SecretSetResult, type StatsData, type StatusData, type UCANAttenuation, type UCANCapability, type UCANIssueInput, type UCANIssueResult, UCANManager, type UCANVerifyResult, VENUE_RELAY, Venue, type VenueConstructor, type VenueData, type VenueInterface, type VenueOptions, type WorkspaceAggregateResult, type WorkspaceAppendInput, type WorkspaceAppendResult, type WorkspaceCopyResult, type WorkspaceCountResult, type WorkspaceDeleteInput, type WorkspaceDeleteResult, type WorkspaceInspectInput, type WorkspaceInspectResult, type WorkspaceListInput, type WorkspaceListResult, WorkspaceManager, type WorkspaceReadInput, type WorkspaceReadResult, type WorkspaceSliceInput, type WorkspaceSliceResult, type WorkspaceWriteInput, type WorkspaceWriteResult, assetHash, createSSEEvent, createUCANJWT, decodePublicKey, didFor, didFromPublicKey, didMethod, didUrl, encodePublicKey, fetchStreamWithError, fetchWithError, generateKeyPair, getAssetIdFromPath, getAssetIdFromVenueId, getAssetMetadataStore, getParsedAssetId, grant, hexToPrivateKey, identityToken, isDid, isJobComplete, isJobFinished, isJobPaused, logger, parseDidUrl, parseRetryAfterMs, parseSSEStream, privateKeyToHex, relayDelegation, retryDelayMs, setAssetMetadataStore, venueBaseUrlCandidates };
1683
+ export { type AdapterInfo, AdapterManager, type AdaptersResult, Agent, type AgentCancelTaskInput, type AgentCard, type AgentChatInput, type AgentChatResult, type AgentCompleteTaskResult, type AgentContextInput, type AgentCreateInput, type AgentCreateResult, type AgentDeleteInput, type AgentDeleteResult, type AgentFailTaskResult, type AgentForkInput, type AgentForkResult, type AgentInfoResult, type AgentListInput, type AgentListResult, AgentManager, type AgentMessageInput, type AgentMessageResult, type AgentRequestInput, type AgentRequestResult, type AgentResumeInput, AgentStatus, type AgentSuspendResult, type AgentTriggerInput, type AgentTriggerResult, type AgentUpdateInput, Asset, type AssetID, type AssetList, type AssetListOptions, AssetManager, type AssetMetadata, type AssetMetadataStore, AssetNotFoundError, type AssetPinResult, Auth, BasicAuth, BearerAuth, ChatSession, type ConnectionAttempt, type ContentDetails, type ContentHashResult, CoviaConnectionError, type CoviaConnectionErrorOptions, CoviaError, CoviaTimeoutError, type Credentials, CredentialsHTTP, type DIDDocument, type DIDURL, DataAsset, Ed25519Auth, type FunctionInfo, type FunctionsResult, Grid, GridError, type GroupCount, type InvokeOptions, type InvokePayload, Job, JobFailedError, JobManager, type JobMetadata, JobNotFoundError, JobStatus, KeyPairAuth, type MCPDiscovery, Namespace, NoAuth, NotFoundError, Operation, type OperationDetails, type OperationInfo, OperationManager, type OperationPayload, type OperationRunner, RateLimitError, RunStatus, type SSEEvent, type SecretExtractInput, type SecretExtractResult, SecretManager, type SecretSetInput, type SecretSetResult, type StatsData, type StatusData, type UCANAttenuation, type UCANCapability, type UCANIssueInput, type UCANIssueResult, UCANManager, type UCANVerifyResult, VENUE_RELAY, Venue, type VenueConstructor, type VenueData, VenueIdentityChangedError, type VenueInterface, type VenueOptions, type WorkspaceAggregateResult, type WorkspaceAppendInput, type WorkspaceAppendResult, type WorkspaceCopyResult, type WorkspaceCountResult, type WorkspaceDeleteInput, type WorkspaceDeleteResult, type WorkspaceInspectInput, type WorkspaceInspectResult, type WorkspaceListInput, type WorkspaceListResult, WorkspaceManager, type WorkspaceReadInput, type WorkspaceReadResult, type WorkspaceSliceInput, type WorkspaceSliceResult, type WorkspaceWriteInput, type WorkspaceWriteResult, assetHash, createSSEEvent, createUCANJWT, decodePublicKey, didFor, didFromPublicKey, didMethod, didUrl, encodePublicKey, fetchStreamWithError, fetchWithError, generateKeyPair, getAssetIdFromPath, getAssetIdFromVenueId, getAssetMetadataStore, getParsedAssetId, grant, hexToPrivateKey, identityToken, isDid, isJobComplete, isJobFinished, isJobPaused, logger, parseDidUrl, parseRetryAfterMs, parseSSEStream, privateKeyToHex, relayDelegation, retryDelayMs, setAssetMetadataStore, venueBaseUrlCandidates };
package/dist/index.js CHANGED
@@ -46,9 +46,23 @@ var GridError = class extends CoviaError {
46
46
  }
47
47
  };
48
48
  var CoviaConnectionError = class extends CoviaError {
49
- constructor(message) {
49
+ constructor(message, options = {}) {
50
50
  super(message);
51
51
  this.name = "CoviaConnectionError";
52
+ this.url = options.url ?? null;
53
+ this.method = options.method?.toUpperCase() ?? null;
54
+ this.cause = options.cause;
55
+ this.candidates = [...options.candidates ?? []];
56
+ this.attempts = [...options.attempts ?? []];
57
+ }
58
+ };
59
+ var VenueIdentityChangedError = class extends CoviaError {
60
+ constructor(oldDid, newDid, baseUrl) {
61
+ super(`Venue identity changed at ${baseUrl}: expected ${oldDid}, received ${newDid}`);
62
+ this.oldDid = oldDid;
63
+ this.newDid = newDid;
64
+ this.baseUrl = baseUrl;
65
+ this.name = "VenueIdentityChangedError";
52
66
  }
53
67
  };
54
68
  var CoviaTimeoutError = class extends CoviaError {
@@ -1308,13 +1322,14 @@ async function throwHttpError(response) {
1308
1322
  }
1309
1323
  throw new GridError(response.status, message, body);
1310
1324
  }
1311
- function wrapError(error) {
1312
- if (error instanceof CoviaError) return error;
1313
- const msg = error.message ?? String(error);
1314
- if (error instanceof TypeError) {
1315
- return new CoviaConnectionError(msg);
1316
- }
1317
- return new CoviaError(`Request failed: ${msg}`);
1325
+ function wrapConnectionError(error, url, method) {
1326
+ if (error instanceof CoviaConnectionError && error.url && error.method) return error;
1327
+ const detail = error instanceof Error ? error.message : String(error);
1328
+ return new CoviaConnectionError(`${method} ${url} failed: ${detail}`, {
1329
+ url,
1330
+ method,
1331
+ cause: error
1332
+ });
1318
1333
  }
1319
1334
  var RETRY_MAX_ATTEMPTS = 4;
1320
1335
  var RETRY_BASE_MS = 200;
@@ -1335,7 +1350,7 @@ function retryDelayMs(attempt, retryAfterMs, remainingBudgetMs, random) {
1335
1350
  }
1336
1351
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
1337
1352
  async function fetchWithError(url, options) {
1338
- const method = options?.method ?? "GET";
1353
+ const method = (options?.method ?? "GET").toUpperCase();
1339
1354
  const deadline = Date.now() + RETRY_BUDGET_MS;
1340
1355
  for (let attempt = 1; ; attempt++) {
1341
1356
  logger.debug(`${method} ${url}`);
@@ -1345,7 +1360,7 @@ async function fetchWithError(url, options) {
1345
1360
  } catch (error) {
1346
1361
  const msg = error.message ?? String(error);
1347
1362
  logger.debug(`Connection failed: ${method} ${url} \u2014 ${msg}`);
1348
- throw wrapError(error);
1363
+ throw wrapConnectionError(error, url, method);
1349
1364
  }
1350
1365
  logger.debug(`${method} ${url} \u2192 ${response.status}`);
1351
1366
  if (response.status === 429) {
@@ -1367,7 +1382,7 @@ async function fetchWithError(url, options) {
1367
1382
  }
1368
1383
  }
1369
1384
  async function fetchStreamWithError(url, options) {
1370
- const method = options?.method ?? "GET";
1385
+ const method = (options?.method ?? "GET").toUpperCase();
1371
1386
  logger.debug(`${method} ${url}`);
1372
1387
  let response;
1373
1388
  try {
@@ -1375,7 +1390,7 @@ async function fetchStreamWithError(url, options) {
1375
1390
  } catch (error) {
1376
1391
  const msg = error.message ?? String(error);
1377
1392
  logger.debug(`Connection failed: ${method} ${url} \u2014 ${msg}`);
1378
- throw wrapError(error);
1393
+ throw wrapConnectionError(error, url, method);
1379
1394
  }
1380
1395
  logger.debug(`${method} ${url} \u2192 ${response.status}`);
1381
1396
  if (!response.ok) {
@@ -2070,7 +2085,9 @@ var AssetManager = class {
2070
2085
  }
2071
2086
  }
2072
2087
  try {
2073
- const data = await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`);
2088
+ const data = await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`, {
2089
+ headers: this._buildHeaders(null)
2090
+ });
2074
2091
  if (hash) {
2075
2092
  cache.set(assetId, data);
2076
2093
  getAssetMetadataStore()?.put(normaliseHash(hash), data);
@@ -2099,7 +2116,9 @@ var AssetManager = class {
2099
2116
  if (options.limit !== void 0) {
2100
2117
  params.set("limit", String(options.limit));
2101
2118
  }
2102
- return fetchWithError(`${this.venue.baseUrl}/api/v1/assets?${params.toString()}`);
2119
+ return fetchWithError(`${this.venue.baseUrl}/api/v1/assets?${params.toString()}`, {
2120
+ headers: this._buildHeaders(null)
2121
+ });
2103
2122
  }
2104
2123
  /**
2105
2124
  * Register a new asset
@@ -2118,7 +2137,9 @@ var AssetManager = class {
2118
2137
  */
2119
2138
  async getMetadata(assetId) {
2120
2139
  try {
2121
- return await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`);
2140
+ return await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`, {
2141
+ headers: this._buildHeaders(null)
2142
+ });
2122
2143
  } catch (error) {
2123
2144
  if (error instanceof NotFoundError) {
2124
2145
  throw new AssetNotFoundError(assetId);
@@ -2152,7 +2173,9 @@ var AssetManager = class {
2152
2173
  */
2153
2174
  async getContent(assetId) {
2154
2175
  try {
2155
- const response = await fetchStreamWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}/content`);
2176
+ const response = await fetchStreamWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}/content`, {
2177
+ headers: this._buildHeaders(null)
2178
+ });
2156
2179
  return response.body;
2157
2180
  } catch (error) {
2158
2181
  if (error instanceof NotFoundError) {
@@ -2549,6 +2572,20 @@ function venueBaseUrlCandidates(venueId) {
2549
2572
  }
2550
2573
  return schemelessVenueCandidates(venueId);
2551
2574
  }
2575
+ function asCoviaError(error) {
2576
+ if (error instanceof CoviaError) return error;
2577
+ const message = error instanceof Error ? error.message : String(error);
2578
+ return new CoviaError(message);
2579
+ }
2580
+ function assertVenueIdentity(expectedDid, actualDid, baseUrl) {
2581
+ if (expectedDid && actualDid && expectedDid !== actualDid) {
2582
+ throw new VenueIdentityChangedError(expectedDid, actualDid, baseUrl);
2583
+ }
2584
+ }
2585
+ function connectionFailureMessage(venueId, attempts) {
2586
+ const detail = attempts.map(({ method, url, error }) => `${method} ${url}: ${error.message}`).join("; ");
2587
+ return `Could not connect to venue ${venueId}${detail ? `. Attempts: ${detail}` : ""}`;
2588
+ }
2552
2589
  var Venue = class _Venue {
2553
2590
  constructor(options = {}) {
2554
2591
  /** Connection-level private-jobs mode — see {@link setPrivate}. */
@@ -2619,20 +2656,26 @@ var Venue = class _Venue {
2619
2656
  * responded (the https candidate if an http fallback failed; the resolved
2620
2657
  * endpoint for a did:web id), and `venue.venueId` is the DID the venue
2621
2658
  * reported. The validated API root is `${venue.baseUrl}/api/v1`.
2659
+ * @throws {CoviaConnectionError} If no candidate can be validated.
2660
+ * @throws {VenueIdentityChangedError} If a known/resolved DID reports a different identity.
2622
2661
  */
2623
2662
  static async connect(venueId, auth) {
2624
2663
  if (venueId instanceof _Venue) {
2625
- return new _Venue({
2664
+ const connected = new _Venue({
2626
2665
  baseUrl: venueId.baseUrl,
2627
2666
  venueId: venueId.venueId,
2628
2667
  name: venueId.metadata.name,
2629
2668
  auth,
2630
2669
  status: venueId.lastKnownStatus
2631
2670
  });
2671
+ await connected.status();
2672
+ return connected;
2632
2673
  }
2633
2674
  if (typeof venueId === "string") {
2634
2675
  let candidates;
2676
+ let expectedDid;
2635
2677
  if (venueId.startsWith("did:web:")) {
2678
+ expectedDid = venueId;
2636
2679
  const didDoc = await resolver.resolve(venueId);
2637
2680
  if (!didDoc.didDocument) {
2638
2681
  throw new CoviaError("Invalid DID document");
@@ -2645,10 +2688,15 @@ var Venue = class _Venue {
2645
2688
  } else {
2646
2689
  candidates = venueBaseUrlCandidates(venueId);
2647
2690
  }
2648
- let lastError;
2691
+ const attempts = [];
2649
2692
  for (const baseUrl of candidates) {
2693
+ const statusUrl = baseUrl + "/api/v1/status";
2650
2694
  try {
2651
- const data = await fetchWithError(baseUrl + "/api/v1/status");
2695
+ const data = await fetchWithError(statusUrl);
2696
+ if (!data.did) {
2697
+ throw new CoviaError(`Venue status at ${statusUrl} did not include a DID`);
2698
+ }
2699
+ assertVenueIdentity(expectedDid, data.did, baseUrl);
2652
2700
  return new _Venue({
2653
2701
  baseUrl,
2654
2702
  venueId: data.did,
@@ -2657,19 +2705,30 @@ var Venue = class _Venue {
2657
2705
  status: data
2658
2706
  });
2659
2707
  } catch (error) {
2660
- if (error instanceof GridError && (error.statusCode === 401 || error.statusCode === 403)) {
2708
+ if (error instanceof VenueIdentityChangedError) throw error;
2709
+ const statusError = asCoviaError(error);
2710
+ attempts.push({ url: statusUrl, method: "GET", error: statusError });
2711
+ if (statusError instanceof GridError && (statusError.statusCode === 401 || statusError.statusCode === 403)) {
2712
+ const didDocumentUrl = baseUrl + "/.well-known/did.json";
2661
2713
  try {
2662
- const doc = await fetchWithError(baseUrl + "/.well-known/did.json");
2714
+ const doc = await fetchWithError(didDocumentUrl);
2663
2715
  if (doc?.id) {
2716
+ assertVenueIdentity(expectedDid, doc.id, baseUrl);
2664
2717
  return new _Venue({ baseUrl, venueId: doc.id, auth });
2665
2718
  }
2666
- } catch {
2719
+ throw new CoviaError(`DID document at ${didDocumentUrl} did not include an id`);
2720
+ } catch (fallbackError) {
2721
+ if (fallbackError instanceof VenueIdentityChangedError) throw fallbackError;
2722
+ attempts.push({ url: didDocumentUrl, method: "GET", error: asCoviaError(fallbackError) });
2667
2723
  }
2668
2724
  }
2669
- lastError = error;
2670
2725
  }
2671
2726
  }
2672
- throw lastError instanceof Error ? lastError : new CoviaError(`Could not connect to venue: ${venueId}`);
2727
+ throw new CoviaConnectionError(connectionFailureMessage(venueId, attempts), {
2728
+ candidates,
2729
+ attempts,
2730
+ cause: attempts.length > 0 ? attempts[attempts.length - 1].error : void 0
2731
+ });
2673
2732
  }
2674
2733
  throw new CoviaError("Invalid venue ID parameter. Must be a string (URL/DNS) or Venue instance.");
2675
2734
  }
@@ -2736,9 +2795,17 @@ var Venue = class _Venue {
2736
2795
  /**
2737
2796
  * Get venue status
2738
2797
  * @returns {Promise<StatusData>}
2798
+ * @throws {VenueIdentityChangedError} If this address reports a different known DID.
2739
2799
  */
2740
2800
  async status() {
2741
2801
  const data = await fetchWithError(`${this.baseUrl}/api/v1/status`);
2802
+ if (data.did) {
2803
+ if (this.venueId) {
2804
+ assertVenueIdentity(this.venueId, data.did, this.baseUrl);
2805
+ } else {
2806
+ this.venueId = data.did;
2807
+ }
2808
+ }
2742
2809
  this.lastKnownStatus = data;
2743
2810
  return data;
2744
2811
  }
@@ -2754,6 +2821,7 @@ var Venue = class _Venue {
2754
2821
  * @param options.pollIntervalMs - Delay between polls (default 1000).
2755
2822
  * @returns The ready {@link StatusData}.
2756
2823
  * @throws {CoviaTimeoutError} If the venue is not ready within the timeout.
2824
+ * @throws {VenueIdentityChangedError} Immediately if the venue's DID changed.
2757
2825
  */
2758
2826
  async waitUntilReady(options = {}) {
2759
2827
  const timeoutMs = options.timeoutMs ?? 6e4;
@@ -2763,7 +2831,8 @@ var Venue = class _Venue {
2763
2831
  try {
2764
2832
  const data = await this.status();
2765
2833
  if (data.status == null || data.status.toUpperCase() === "OK") return data;
2766
- } catch {
2834
+ } catch (error) {
2835
+ if (error instanceof VenueIdentityChangedError) throw error;
2767
2836
  }
2768
2837
  if (Date.now() - start >= timeoutMs) {
2769
2838
  throw new CoviaTimeoutError(`Venue ${this.baseUrl} not ready within ${timeoutMs}ms`);
@@ -2904,6 +2973,7 @@ exports.SecretManager = SecretManager;
2904
2973
  exports.UCANManager = UCANManager;
2905
2974
  exports.VENUE_RELAY = VENUE_RELAY;
2906
2975
  exports.Venue = Venue;
2976
+ exports.VenueIdentityChangedError = VenueIdentityChangedError;
2907
2977
  exports.WorkspaceManager = WorkspaceManager;
2908
2978
  exports.assetHash = assetHash;
2909
2979
  exports.createSSEEvent = createSSEEvent;
package/dist/index.mjs CHANGED
@@ -44,9 +44,23 @@ var GridError = class extends CoviaError {
44
44
  }
45
45
  };
46
46
  var CoviaConnectionError = class extends CoviaError {
47
- constructor(message) {
47
+ constructor(message, options = {}) {
48
48
  super(message);
49
49
  this.name = "CoviaConnectionError";
50
+ this.url = options.url ?? null;
51
+ this.method = options.method?.toUpperCase() ?? null;
52
+ this.cause = options.cause;
53
+ this.candidates = [...options.candidates ?? []];
54
+ this.attempts = [...options.attempts ?? []];
55
+ }
56
+ };
57
+ var VenueIdentityChangedError = class extends CoviaError {
58
+ constructor(oldDid, newDid, baseUrl) {
59
+ super(`Venue identity changed at ${baseUrl}: expected ${oldDid}, received ${newDid}`);
60
+ this.oldDid = oldDid;
61
+ this.newDid = newDid;
62
+ this.baseUrl = baseUrl;
63
+ this.name = "VenueIdentityChangedError";
50
64
  }
51
65
  };
52
66
  var CoviaTimeoutError = class extends CoviaError {
@@ -1306,13 +1320,14 @@ async function throwHttpError(response) {
1306
1320
  }
1307
1321
  throw new GridError(response.status, message, body);
1308
1322
  }
1309
- function wrapError(error) {
1310
- if (error instanceof CoviaError) return error;
1311
- const msg = error.message ?? String(error);
1312
- if (error instanceof TypeError) {
1313
- return new CoviaConnectionError(msg);
1314
- }
1315
- return new CoviaError(`Request failed: ${msg}`);
1323
+ function wrapConnectionError(error, url, method) {
1324
+ if (error instanceof CoviaConnectionError && error.url && error.method) return error;
1325
+ const detail = error instanceof Error ? error.message : String(error);
1326
+ return new CoviaConnectionError(`${method} ${url} failed: ${detail}`, {
1327
+ url,
1328
+ method,
1329
+ cause: error
1330
+ });
1316
1331
  }
1317
1332
  var RETRY_MAX_ATTEMPTS = 4;
1318
1333
  var RETRY_BASE_MS = 200;
@@ -1333,7 +1348,7 @@ function retryDelayMs(attempt, retryAfterMs, remainingBudgetMs, random) {
1333
1348
  }
1334
1349
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
1335
1350
  async function fetchWithError(url, options) {
1336
- const method = options?.method ?? "GET";
1351
+ const method = (options?.method ?? "GET").toUpperCase();
1337
1352
  const deadline = Date.now() + RETRY_BUDGET_MS;
1338
1353
  for (let attempt = 1; ; attempt++) {
1339
1354
  logger.debug(`${method} ${url}`);
@@ -1343,7 +1358,7 @@ async function fetchWithError(url, options) {
1343
1358
  } catch (error) {
1344
1359
  const msg = error.message ?? String(error);
1345
1360
  logger.debug(`Connection failed: ${method} ${url} \u2014 ${msg}`);
1346
- throw wrapError(error);
1361
+ throw wrapConnectionError(error, url, method);
1347
1362
  }
1348
1363
  logger.debug(`${method} ${url} \u2192 ${response.status}`);
1349
1364
  if (response.status === 429) {
@@ -1365,7 +1380,7 @@ async function fetchWithError(url, options) {
1365
1380
  }
1366
1381
  }
1367
1382
  async function fetchStreamWithError(url, options) {
1368
- const method = options?.method ?? "GET";
1383
+ const method = (options?.method ?? "GET").toUpperCase();
1369
1384
  logger.debug(`${method} ${url}`);
1370
1385
  let response;
1371
1386
  try {
@@ -1373,7 +1388,7 @@ async function fetchStreamWithError(url, options) {
1373
1388
  } catch (error) {
1374
1389
  const msg = error.message ?? String(error);
1375
1390
  logger.debug(`Connection failed: ${method} ${url} \u2014 ${msg}`);
1376
- throw wrapError(error);
1391
+ throw wrapConnectionError(error, url, method);
1377
1392
  }
1378
1393
  logger.debug(`${method} ${url} \u2192 ${response.status}`);
1379
1394
  if (!response.ok) {
@@ -2068,7 +2083,9 @@ var AssetManager = class {
2068
2083
  }
2069
2084
  }
2070
2085
  try {
2071
- const data = await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`);
2086
+ const data = await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`, {
2087
+ headers: this._buildHeaders(null)
2088
+ });
2072
2089
  if (hash) {
2073
2090
  cache.set(assetId, data);
2074
2091
  getAssetMetadataStore()?.put(normaliseHash(hash), data);
@@ -2097,7 +2114,9 @@ var AssetManager = class {
2097
2114
  if (options.limit !== void 0) {
2098
2115
  params.set("limit", String(options.limit));
2099
2116
  }
2100
- return fetchWithError(`${this.venue.baseUrl}/api/v1/assets?${params.toString()}`);
2117
+ return fetchWithError(`${this.venue.baseUrl}/api/v1/assets?${params.toString()}`, {
2118
+ headers: this._buildHeaders(null)
2119
+ });
2101
2120
  }
2102
2121
  /**
2103
2122
  * Register a new asset
@@ -2116,7 +2135,9 @@ var AssetManager = class {
2116
2135
  */
2117
2136
  async getMetadata(assetId) {
2118
2137
  try {
2119
- return await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`);
2138
+ return await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`, {
2139
+ headers: this._buildHeaders(null)
2140
+ });
2120
2141
  } catch (error) {
2121
2142
  if (error instanceof NotFoundError) {
2122
2143
  throw new AssetNotFoundError(assetId);
@@ -2150,7 +2171,9 @@ var AssetManager = class {
2150
2171
  */
2151
2172
  async getContent(assetId) {
2152
2173
  try {
2153
- const response = await fetchStreamWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}/content`);
2174
+ const response = await fetchStreamWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}/content`, {
2175
+ headers: this._buildHeaders(null)
2176
+ });
2154
2177
  return response.body;
2155
2178
  } catch (error) {
2156
2179
  if (error instanceof NotFoundError) {
@@ -2547,6 +2570,20 @@ function venueBaseUrlCandidates(venueId) {
2547
2570
  }
2548
2571
  return schemelessVenueCandidates(venueId);
2549
2572
  }
2573
+ function asCoviaError(error) {
2574
+ if (error instanceof CoviaError) return error;
2575
+ const message = error instanceof Error ? error.message : String(error);
2576
+ return new CoviaError(message);
2577
+ }
2578
+ function assertVenueIdentity(expectedDid, actualDid, baseUrl) {
2579
+ if (expectedDid && actualDid && expectedDid !== actualDid) {
2580
+ throw new VenueIdentityChangedError(expectedDid, actualDid, baseUrl);
2581
+ }
2582
+ }
2583
+ function connectionFailureMessage(venueId, attempts) {
2584
+ const detail = attempts.map(({ method, url, error }) => `${method} ${url}: ${error.message}`).join("; ");
2585
+ return `Could not connect to venue ${venueId}${detail ? `. Attempts: ${detail}` : ""}`;
2586
+ }
2550
2587
  var Venue = class _Venue {
2551
2588
  constructor(options = {}) {
2552
2589
  /** Connection-level private-jobs mode — see {@link setPrivate}. */
@@ -2617,20 +2654,26 @@ var Venue = class _Venue {
2617
2654
  * responded (the https candidate if an http fallback failed; the resolved
2618
2655
  * endpoint for a did:web id), and `venue.venueId` is the DID the venue
2619
2656
  * reported. The validated API root is `${venue.baseUrl}/api/v1`.
2657
+ * @throws {CoviaConnectionError} If no candidate can be validated.
2658
+ * @throws {VenueIdentityChangedError} If a known/resolved DID reports a different identity.
2620
2659
  */
2621
2660
  static async connect(venueId, auth) {
2622
2661
  if (venueId instanceof _Venue) {
2623
- return new _Venue({
2662
+ const connected = new _Venue({
2624
2663
  baseUrl: venueId.baseUrl,
2625
2664
  venueId: venueId.venueId,
2626
2665
  name: venueId.metadata.name,
2627
2666
  auth,
2628
2667
  status: venueId.lastKnownStatus
2629
2668
  });
2669
+ await connected.status();
2670
+ return connected;
2630
2671
  }
2631
2672
  if (typeof venueId === "string") {
2632
2673
  let candidates;
2674
+ let expectedDid;
2633
2675
  if (venueId.startsWith("did:web:")) {
2676
+ expectedDid = venueId;
2634
2677
  const didDoc = await resolver.resolve(venueId);
2635
2678
  if (!didDoc.didDocument) {
2636
2679
  throw new CoviaError("Invalid DID document");
@@ -2643,10 +2686,15 @@ var Venue = class _Venue {
2643
2686
  } else {
2644
2687
  candidates = venueBaseUrlCandidates(venueId);
2645
2688
  }
2646
- let lastError;
2689
+ const attempts = [];
2647
2690
  for (const baseUrl of candidates) {
2691
+ const statusUrl = baseUrl + "/api/v1/status";
2648
2692
  try {
2649
- const data = await fetchWithError(baseUrl + "/api/v1/status");
2693
+ const data = await fetchWithError(statusUrl);
2694
+ if (!data.did) {
2695
+ throw new CoviaError(`Venue status at ${statusUrl} did not include a DID`);
2696
+ }
2697
+ assertVenueIdentity(expectedDid, data.did, baseUrl);
2650
2698
  return new _Venue({
2651
2699
  baseUrl,
2652
2700
  venueId: data.did,
@@ -2655,19 +2703,30 @@ var Venue = class _Venue {
2655
2703
  status: data
2656
2704
  });
2657
2705
  } catch (error) {
2658
- if (error instanceof GridError && (error.statusCode === 401 || error.statusCode === 403)) {
2706
+ if (error instanceof VenueIdentityChangedError) throw error;
2707
+ const statusError = asCoviaError(error);
2708
+ attempts.push({ url: statusUrl, method: "GET", error: statusError });
2709
+ if (statusError instanceof GridError && (statusError.statusCode === 401 || statusError.statusCode === 403)) {
2710
+ const didDocumentUrl = baseUrl + "/.well-known/did.json";
2659
2711
  try {
2660
- const doc = await fetchWithError(baseUrl + "/.well-known/did.json");
2712
+ const doc = await fetchWithError(didDocumentUrl);
2661
2713
  if (doc?.id) {
2714
+ assertVenueIdentity(expectedDid, doc.id, baseUrl);
2662
2715
  return new _Venue({ baseUrl, venueId: doc.id, auth });
2663
2716
  }
2664
- } catch {
2717
+ throw new CoviaError(`DID document at ${didDocumentUrl} did not include an id`);
2718
+ } catch (fallbackError) {
2719
+ if (fallbackError instanceof VenueIdentityChangedError) throw fallbackError;
2720
+ attempts.push({ url: didDocumentUrl, method: "GET", error: asCoviaError(fallbackError) });
2665
2721
  }
2666
2722
  }
2667
- lastError = error;
2668
2723
  }
2669
2724
  }
2670
- throw lastError instanceof Error ? lastError : new CoviaError(`Could not connect to venue: ${venueId}`);
2725
+ throw new CoviaConnectionError(connectionFailureMessage(venueId, attempts), {
2726
+ candidates,
2727
+ attempts,
2728
+ cause: attempts.length > 0 ? attempts[attempts.length - 1].error : void 0
2729
+ });
2671
2730
  }
2672
2731
  throw new CoviaError("Invalid venue ID parameter. Must be a string (URL/DNS) or Venue instance.");
2673
2732
  }
@@ -2734,9 +2793,17 @@ var Venue = class _Venue {
2734
2793
  /**
2735
2794
  * Get venue status
2736
2795
  * @returns {Promise<StatusData>}
2796
+ * @throws {VenueIdentityChangedError} If this address reports a different known DID.
2737
2797
  */
2738
2798
  async status() {
2739
2799
  const data = await fetchWithError(`${this.baseUrl}/api/v1/status`);
2800
+ if (data.did) {
2801
+ if (this.venueId) {
2802
+ assertVenueIdentity(this.venueId, data.did, this.baseUrl);
2803
+ } else {
2804
+ this.venueId = data.did;
2805
+ }
2806
+ }
2740
2807
  this.lastKnownStatus = data;
2741
2808
  return data;
2742
2809
  }
@@ -2752,6 +2819,7 @@ var Venue = class _Venue {
2752
2819
  * @param options.pollIntervalMs - Delay between polls (default 1000).
2753
2820
  * @returns The ready {@link StatusData}.
2754
2821
  * @throws {CoviaTimeoutError} If the venue is not ready within the timeout.
2822
+ * @throws {VenueIdentityChangedError} Immediately if the venue's DID changed.
2755
2823
  */
2756
2824
  async waitUntilReady(options = {}) {
2757
2825
  const timeoutMs = options.timeoutMs ?? 6e4;
@@ -2761,7 +2829,8 @@ var Venue = class _Venue {
2761
2829
  try {
2762
2830
  const data = await this.status();
2763
2831
  if (data.status == null || data.status.toUpperCase() === "OK") return data;
2764
- } catch {
2832
+ } catch (error) {
2833
+ if (error instanceof VenueIdentityChangedError) throw error;
2765
2834
  }
2766
2835
  if (Date.now() - start >= timeoutMs) {
2767
2836
  throw new CoviaTimeoutError(`Venue ${this.baseUrl} not ready within ${timeoutMs}ms`);
@@ -2866,4 +2935,4 @@ function relayDelegation(privateKey, venueDID, lifetimeSeconds, caps = []) {
2866
2935
  (*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
2867
2936
  */
2868
2937
 
2869
- export { AdapterManager, Agent, AgentManager, AgentStatus, Asset, AssetManager, AssetNotFoundError, Auth, BasicAuth, BearerAuth, ChatSession, CoviaConnectionError, CoviaError, CoviaTimeoutError, CredentialsHTTP, DataAsset, Ed25519Auth, Grid, GridError, Job, JobFailedError, JobManager, JobNotFoundError, JobStatus, KeyPairAuth, Namespace, NoAuth, NotFoundError, Operation, OperationManager, RateLimitError, RunStatus, SecretManager, UCANManager, VENUE_RELAY, Venue, WorkspaceManager, assetHash, createSSEEvent, createUCANJWT, decodePublicKey, didFor, didFromPublicKey, didMethod, didUrl, encodePublicKey, fetchStreamWithError, fetchWithError, generateKeyPair, getAssetIdFromPath, getAssetIdFromVenueId, getAssetMetadataStore, getParsedAssetId, grant, hexToPrivateKey, identityToken, isDid, isJobComplete, isJobFinished, isJobPaused, logger, parseDidUrl, parseRetryAfterMs, parseSSEStream, privateKeyToHex, relayDelegation, retryDelayMs, setAssetMetadataStore, venueBaseUrlCandidates };
2938
+ export { AdapterManager, Agent, AgentManager, AgentStatus, Asset, AssetManager, AssetNotFoundError, Auth, BasicAuth, BearerAuth, ChatSession, CoviaConnectionError, CoviaError, CoviaTimeoutError, CredentialsHTTP, DataAsset, Ed25519Auth, Grid, GridError, Job, JobFailedError, JobManager, JobNotFoundError, JobStatus, KeyPairAuth, Namespace, NoAuth, NotFoundError, Operation, OperationManager, RateLimitError, RunStatus, SecretManager, UCANManager, VENUE_RELAY, Venue, VenueIdentityChangedError, WorkspaceManager, assetHash, createSSEEvent, createUCANJWT, decodePublicKey, didFor, didFromPublicKey, didMethod, didUrl, encodePublicKey, fetchStreamWithError, fetchWithError, generateKeyPair, getAssetIdFromPath, getAssetIdFromVenueId, getAssetMetadataStore, getParsedAssetId, grant, hexToPrivateKey, identityToken, isDid, isJobComplete, isJobFinished, isJobPaused, logger, parseDidUrl, parseRetryAfterMs, parseSSEStream, privateKeyToHex, relayDelegation, retryDelayMs, setAssetMetadataStore, venueBaseUrlCandidates };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@covia/covia-sdk",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "Typescript library for covia-ai",
5
5
  "packageManager": "pnpm@11.9.0",
6
6
  "main": "./dist/index.js",