@covia/covia-sdk 1.7.0 → 1.7.2

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/index.d.mts CHANGED
@@ -431,6 +431,7 @@ declare class AssetManager {
431
431
  * @returns Returns either an Operation or DataAsset based on the asset's metadata
432
432
  */
433
433
  get(assetId: AssetID): Promise<Asset>;
434
+ private _wrap;
434
435
  /**
435
436
  * List assets with pagination support
436
437
  * @param options - Pagination options (offset, limit)
@@ -1006,6 +1007,14 @@ interface AgentCreateResult {
1006
1007
  agentId: string;
1007
1008
  status: string;
1008
1009
  created: boolean;
1010
+ /** True when an existing SLEEPING/SUSPENDED record was updated in place
1011
+ * (mutually exclusive with created). Absent on venues before 0.4. */
1012
+ updated?: boolean;
1013
+ /** Non-fatal advisories (venue 0.5+): present only when the config looks
1014
+ * misconfigured but create still succeeded — e.g. an Ollama model whose
1015
+ * tool-calling can't be confirmed, or declared tools that don't resolve
1016
+ * on the venue. Each entry is a human-readable message. */
1017
+ warnings?: string[];
1009
1018
  }
1010
1019
  interface AgentRequestInput {
1011
1020
  agentId: string;
@@ -1048,10 +1057,13 @@ interface AgentListInput {
1048
1057
  includeTerminated?: boolean;
1049
1058
  }
1050
1059
  interface AgentListResult {
1060
+ /** Always objects. The invoke op returns enriched entries; the job-free GET
1061
+ * returns bare id strings, which the SDK normalises to `{agentId}` — so
1062
+ * `status`/`tasks` are present only when the venue supplied them. */
1051
1063
  agents: Array<{
1052
1064
  agentId: string;
1053
- status: string;
1054
- tasks: number;
1065
+ status?: string;
1066
+ tasks?: number;
1055
1067
  }>;
1056
1068
  }
1057
1069
  interface AgentDeleteInput {
@@ -1466,6 +1478,33 @@ declare function didUrl(did: string | null, namespace: string, ...segments: stri
1466
1478
  */
1467
1479
  declare function assetHash(ref: string): string | null;
1468
1480
 
1481
+ /**
1482
+ * Pluggable persistent store for content-addressed asset metadata.
1483
+ *
1484
+ * An asset id is the Convex value hash of its metadata (`AMap.getHash()`
1485
+ * venue-side), so hash → metadata is immutable: entries never go stale and are
1486
+ * safe to cache indefinitely, across sessions and across venues. Keys are the
1487
+ * normalised bare hash (lowercase, no `0x`), so `<hash>`, `0x<hash>` and
1488
+ * `<DID>/a/<hash>` refs all share one entry.
1489
+ *
1490
+ * Trust model: entries are cached as returned by the venue that served them.
1491
+ * Provable verification — recomputing the Convex value hash of the metadata
1492
+ * and rejecting mismatches — requires a canonical CVM cell encoder in
1493
+ * TypeScript, which does not exist yet; when it lands, verification will gate
1494
+ * admission to this cache so entries are correct by construction rather than
1495
+ * by trust. Until then this is a availability/performance cache with the same
1496
+ * trust as an uncached fetch from the same venue.
1497
+ */
1498
+ interface AssetMetadataStore {
1499
+ get(hash: string): AssetMetadata | undefined;
1500
+ put(hash: string, metadata: AssetMetadata): void;
1501
+ clear(): void;
1502
+ }
1503
+ /** Replace the persistent metadata store (e.g. a file-backed store in Node),
1504
+ * or pass `null` to disable persistence. Browsers default to localStorage. */
1505
+ declare function setAssetMetadataStore(s: AssetMetadataStore | null): void;
1506
+ declare function getAssetMetadataStore(): AssetMetadataStore | null;
1507
+
1469
1508
  /**
1470
1509
  * Simple logger for the Covia SDK.
1471
1510
  *
@@ -1599,4 +1638,4 @@ declare function grant(ownerPrivateKey: Uint8Array, audienceDID: string, withRes
1599
1638
  */
1600
1639
  declare function relayDelegation(privateKey: Uint8Array, venueDID: string, lifetimeSeconds: number, caps?: UCANCapability[]): string;
1601
1640
 
1602
- 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, 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, getParsedAssetId, grant, hexToPrivateKey, identityToken, isDid, isJobComplete, isJobFinished, isJobPaused, logger, parseDidUrl, parseRetryAfterMs, parseSSEStream, privateKeyToHex, relayDelegation, retryDelayMs, venueBaseUrlCandidates };
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 };
package/dist/index.d.ts CHANGED
@@ -431,6 +431,7 @@ declare class AssetManager {
431
431
  * @returns Returns either an Operation or DataAsset based on the asset's metadata
432
432
  */
433
433
  get(assetId: AssetID): Promise<Asset>;
434
+ private _wrap;
434
435
  /**
435
436
  * List assets with pagination support
436
437
  * @param options - Pagination options (offset, limit)
@@ -1006,6 +1007,14 @@ interface AgentCreateResult {
1006
1007
  agentId: string;
1007
1008
  status: string;
1008
1009
  created: boolean;
1010
+ /** True when an existing SLEEPING/SUSPENDED record was updated in place
1011
+ * (mutually exclusive with created). Absent on venues before 0.4. */
1012
+ updated?: boolean;
1013
+ /** Non-fatal advisories (venue 0.5+): present only when the config looks
1014
+ * misconfigured but create still succeeded — e.g. an Ollama model whose
1015
+ * tool-calling can't be confirmed, or declared tools that don't resolve
1016
+ * on the venue. Each entry is a human-readable message. */
1017
+ warnings?: string[];
1009
1018
  }
1010
1019
  interface AgentRequestInput {
1011
1020
  agentId: string;
@@ -1048,10 +1057,13 @@ interface AgentListInput {
1048
1057
  includeTerminated?: boolean;
1049
1058
  }
1050
1059
  interface AgentListResult {
1060
+ /** Always objects. The invoke op returns enriched entries; the job-free GET
1061
+ * returns bare id strings, which the SDK normalises to `{agentId}` — so
1062
+ * `status`/`tasks` are present only when the venue supplied them. */
1051
1063
  agents: Array<{
1052
1064
  agentId: string;
1053
- status: string;
1054
- tasks: number;
1065
+ status?: string;
1066
+ tasks?: number;
1055
1067
  }>;
1056
1068
  }
1057
1069
  interface AgentDeleteInput {
@@ -1466,6 +1478,33 @@ declare function didUrl(did: string | null, namespace: string, ...segments: stri
1466
1478
  */
1467
1479
  declare function assetHash(ref: string): string | null;
1468
1480
 
1481
+ /**
1482
+ * Pluggable persistent store for content-addressed asset metadata.
1483
+ *
1484
+ * An asset id is the Convex value hash of its metadata (`AMap.getHash()`
1485
+ * venue-side), so hash → metadata is immutable: entries never go stale and are
1486
+ * safe to cache indefinitely, across sessions and across venues. Keys are the
1487
+ * normalised bare hash (lowercase, no `0x`), so `<hash>`, `0x<hash>` and
1488
+ * `<DID>/a/<hash>` refs all share one entry.
1489
+ *
1490
+ * Trust model: entries are cached as returned by the venue that served them.
1491
+ * Provable verification — recomputing the Convex value hash of the metadata
1492
+ * and rejecting mismatches — requires a canonical CVM cell encoder in
1493
+ * TypeScript, which does not exist yet; when it lands, verification will gate
1494
+ * admission to this cache so entries are correct by construction rather than
1495
+ * by trust. Until then this is a availability/performance cache with the same
1496
+ * trust as an uncached fetch from the same venue.
1497
+ */
1498
+ interface AssetMetadataStore {
1499
+ get(hash: string): AssetMetadata | undefined;
1500
+ put(hash: string, metadata: AssetMetadata): void;
1501
+ clear(): void;
1502
+ }
1503
+ /** Replace the persistent metadata store (e.g. a file-backed store in Node),
1504
+ * or pass `null` to disable persistence. Browsers default to localStorage. */
1505
+ declare function setAssetMetadataStore(s: AssetMetadataStore | null): void;
1506
+ declare function getAssetMetadataStore(): AssetMetadataStore | null;
1507
+
1469
1508
  /**
1470
1509
  * Simple logger for the Covia SDK.
1471
1510
  *
@@ -1599,4 +1638,4 @@ declare function grant(ownerPrivateKey: Uint8Array, audienceDID: string, withRes
1599
1638
  */
1600
1639
  declare function relayDelegation(privateKey: Uint8Array, venueDID: string, lifetimeSeconds: number, caps?: UCANCapability[]): string;
1601
1640
 
1602
- 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, 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, getParsedAssetId, grant, hexToPrivateKey, identityToken, isDid, isJobComplete, isJobFinished, isJobPaused, logger, parseDidUrl, parseRetryAfterMs, parseSSEStream, privateKeyToHex, relayDelegation, retryDelayMs, venueBaseUrlCandidates };
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 };
package/dist/index.js CHANGED
@@ -1499,6 +1499,53 @@ async function* parseSSEStream(response) {
1499
1499
  }
1500
1500
  }
1501
1501
 
1502
+ // src/asset-cache.ts
1503
+ var PREFIX = "covia:asset-meta:";
1504
+ var LocalStorageMetadataStore = class {
1505
+ get(hash) {
1506
+ try {
1507
+ const raw = localStorage.getItem(PREFIX + hash);
1508
+ return raw ? JSON.parse(raw) : void 0;
1509
+ } catch {
1510
+ return void 0;
1511
+ }
1512
+ }
1513
+ put(hash, metadata) {
1514
+ try {
1515
+ localStorage.setItem(PREFIX + hash, JSON.stringify(metadata));
1516
+ } catch {
1517
+ }
1518
+ }
1519
+ clear() {
1520
+ try {
1521
+ const doomed = [];
1522
+ for (let i = 0; i < localStorage.length; i++) {
1523
+ const key = localStorage.key(i);
1524
+ if (key?.startsWith(PREFIX)) doomed.push(key);
1525
+ }
1526
+ doomed.forEach((k) => localStorage.removeItem(k));
1527
+ } catch {
1528
+ }
1529
+ }
1530
+ };
1531
+ function detectDefaultStore() {
1532
+ try {
1533
+ return typeof localStorage !== "undefined" ? new LocalStorageMetadataStore() : null;
1534
+ } catch {
1535
+ return null;
1536
+ }
1537
+ }
1538
+ var store = detectDefaultStore();
1539
+ function setAssetMetadataStore(s) {
1540
+ store = s;
1541
+ }
1542
+ function getAssetMetadataStore() {
1543
+ return store;
1544
+ }
1545
+ function normaliseHash(hash) {
1546
+ return (hash.startsWith("0x") ? hash.slice(2) : hash).toLowerCase();
1547
+ }
1548
+
1502
1549
  // src/AdapterManager.ts
1503
1550
  var ADAPTERS_PATH = "v/info/adapters";
1504
1551
  var LIST_LIMIT = 1e3;
@@ -1585,6 +1632,8 @@ var AgentManager = class {
1585
1632
  );
1586
1633
  } catch (e) {
1587
1634
  if (!(e instanceof NotFoundError)) throw e;
1635
+ const routeMissing = path === "" || /\bEndpoint (GET|POST|PUT|DELETE|PATCH|HEAD) /.test(e.message);
1636
+ if (!routeMissing) throw e;
1588
1637
  this.agentsGetSupported = false;
1589
1638
  }
1590
1639
  }
@@ -1627,7 +1676,10 @@ var AgentManager = class {
1627
1676
  * venues transparently fall back to the invoke path (one probe, remembered).
1628
1677
  */
1629
1678
  async list(includeTerminated) {
1630
- return this._agentsOr("", { includeTerminated }, () => this.venue.operations.run("v/ops/agent/list", { includeTerminated }));
1679
+ const result = await this._agentsOr("", { includeTerminated }, () => this.venue.operations.run("v/ops/agent/list", { includeTerminated }));
1680
+ const raw = result?.agents ?? [];
1681
+ const agents = raw.map((a) => typeof a === "string" ? { agentId: a } : a);
1682
+ return { agents };
1631
1683
  }
1632
1684
  async delete(agentId, remove) {
1633
1685
  return this.venue.operations.run("v/ops/agent/delete", { agentId, remove });
@@ -1814,9 +1866,12 @@ var JobManager = class {
1814
1866
  this.venue = venue;
1815
1867
  }
1816
1868
  async list() {
1817
- return fetchWithError(`${this.venue.baseUrl}/api/v1/jobs`, {
1869
+ const body = await fetchWithError(`${this.venue.baseUrl}/api/v1/jobs`, {
1818
1870
  headers: this._buildHeaders()
1819
1871
  });
1872
+ if (Array.isArray(body)) return body;
1873
+ const items = body?.items;
1874
+ return Array.isArray(items) ? items : [];
1820
1875
  }
1821
1876
  async get(jobId) {
1822
1877
  try {
@@ -2004,21 +2059,23 @@ var AssetManager = class {
2004
2059
  */
2005
2060
  async get(assetId) {
2006
2061
  if (cache.has(assetId)) {
2007
- const cachedData = cache.get(assetId);
2008
- if (cachedData.operation) {
2009
- return new Operation(assetId, this.venue, cachedData);
2010
- } else {
2011
- return new DataAsset(assetId, this.venue, cachedData);
2062
+ return this._wrap(assetId, cache.get(assetId));
2063
+ }
2064
+ const hash = assetHash(assetId);
2065
+ if (hash) {
2066
+ const persisted = getAssetMetadataStore()?.get(normaliseHash(hash));
2067
+ if (persisted) {
2068
+ cache.set(assetId, persisted);
2069
+ return this._wrap(assetId, persisted);
2012
2070
  }
2013
2071
  }
2014
2072
  try {
2015
2073
  const data = await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`);
2016
- if (assetHash(assetId)) cache.set(assetId, data);
2017
- if (data.operation) {
2018
- return new Operation(assetId, this.venue, data);
2019
- } else {
2020
- return new DataAsset(assetId, this.venue, data);
2074
+ if (hash) {
2075
+ cache.set(assetId, data);
2076
+ getAssetMetadataStore()?.put(normaliseHash(hash), data);
2021
2077
  }
2078
+ return this._wrap(assetId, data);
2022
2079
  } catch (error) {
2023
2080
  if (error instanceof NotFoundError) {
2024
2081
  throw new AssetNotFoundError(assetId);
@@ -2026,6 +2083,12 @@ var AssetManager = class {
2026
2083
  throw error;
2027
2084
  }
2028
2085
  }
2086
+ _wrap(assetId, data) {
2087
+ if (data.operation) {
2088
+ return new Operation(assetId, this.venue, data);
2089
+ }
2090
+ return new DataAsset(assetId, this.venue, data);
2091
+ }
2029
2092
  /**
2030
2093
  * List assets with pagination support
2031
2094
  * @param options - Pagination options (offset, limit)
@@ -2111,6 +2174,7 @@ var AssetManager = class {
2111
2174
  */
2112
2175
  clearCache() {
2113
2176
  cache.clear();
2177
+ getAssetMetadataStore()?.clear();
2114
2178
  }
2115
2179
  // `contentType` defaults to JSON for the metadata/register endpoints. Pass
2116
2180
  // `undefined` for binary content upload so fetch infers the type from the
@@ -2279,7 +2343,8 @@ var WorkspaceManager = class {
2279
2343
  return this._valuesOr("read", { path, maxSize }, () => this.venue.operations.run("v/ops/covia/read", { path, maxSize }));
2280
2344
  }
2281
2345
  async list(path, limit, offset, ucans) {
2282
- if (ucans?.length || !path) return this.venue.operations.run("v/ops/covia/list", { path, limit, offset }, { ucans });
2346
+ path = path || "/";
2347
+ if (ucans?.length) return this.venue.operations.run("v/ops/covia/list", { path, limit, offset }, { ucans });
2283
2348
  return this._valuesOr("list", { path, limit, offset }, () => this.venue.operations.run("v/ops/covia/list", { path, limit, offset }));
2284
2349
  }
2285
2350
  async slice(path, offset, limit, ucans) {
@@ -2854,6 +2919,7 @@ exports.fetchWithError = fetchWithError;
2854
2919
  exports.generateKeyPair = generateKeyPair;
2855
2920
  exports.getAssetIdFromPath = getAssetIdFromPath;
2856
2921
  exports.getAssetIdFromVenueId = getAssetIdFromVenueId;
2922
+ exports.getAssetMetadataStore = getAssetMetadataStore;
2857
2923
  exports.getParsedAssetId = getParsedAssetId;
2858
2924
  exports.grant = grant;
2859
2925
  exports.hexToPrivateKey = hexToPrivateKey;
@@ -2869,4 +2935,5 @@ exports.parseSSEStream = parseSSEStream;
2869
2935
  exports.privateKeyToHex = privateKeyToHex;
2870
2936
  exports.relayDelegation = relayDelegation;
2871
2937
  exports.retryDelayMs = retryDelayMs;
2938
+ exports.setAssetMetadataStore = setAssetMetadataStore;
2872
2939
  exports.venueBaseUrlCandidates = venueBaseUrlCandidates;
package/dist/index.mjs CHANGED
@@ -1497,6 +1497,53 @@ async function* parseSSEStream(response) {
1497
1497
  }
1498
1498
  }
1499
1499
 
1500
+ // src/asset-cache.ts
1501
+ var PREFIX = "covia:asset-meta:";
1502
+ var LocalStorageMetadataStore = class {
1503
+ get(hash) {
1504
+ try {
1505
+ const raw = localStorage.getItem(PREFIX + hash);
1506
+ return raw ? JSON.parse(raw) : void 0;
1507
+ } catch {
1508
+ return void 0;
1509
+ }
1510
+ }
1511
+ put(hash, metadata) {
1512
+ try {
1513
+ localStorage.setItem(PREFIX + hash, JSON.stringify(metadata));
1514
+ } catch {
1515
+ }
1516
+ }
1517
+ clear() {
1518
+ try {
1519
+ const doomed = [];
1520
+ for (let i = 0; i < localStorage.length; i++) {
1521
+ const key = localStorage.key(i);
1522
+ if (key?.startsWith(PREFIX)) doomed.push(key);
1523
+ }
1524
+ doomed.forEach((k) => localStorage.removeItem(k));
1525
+ } catch {
1526
+ }
1527
+ }
1528
+ };
1529
+ function detectDefaultStore() {
1530
+ try {
1531
+ return typeof localStorage !== "undefined" ? new LocalStorageMetadataStore() : null;
1532
+ } catch {
1533
+ return null;
1534
+ }
1535
+ }
1536
+ var store = detectDefaultStore();
1537
+ function setAssetMetadataStore(s) {
1538
+ store = s;
1539
+ }
1540
+ function getAssetMetadataStore() {
1541
+ return store;
1542
+ }
1543
+ function normaliseHash(hash) {
1544
+ return (hash.startsWith("0x") ? hash.slice(2) : hash).toLowerCase();
1545
+ }
1546
+
1500
1547
  // src/AdapterManager.ts
1501
1548
  var ADAPTERS_PATH = "v/info/adapters";
1502
1549
  var LIST_LIMIT = 1e3;
@@ -1583,6 +1630,8 @@ var AgentManager = class {
1583
1630
  );
1584
1631
  } catch (e) {
1585
1632
  if (!(e instanceof NotFoundError)) throw e;
1633
+ const routeMissing = path === "" || /\bEndpoint (GET|POST|PUT|DELETE|PATCH|HEAD) /.test(e.message);
1634
+ if (!routeMissing) throw e;
1586
1635
  this.agentsGetSupported = false;
1587
1636
  }
1588
1637
  }
@@ -1625,7 +1674,10 @@ var AgentManager = class {
1625
1674
  * venues transparently fall back to the invoke path (one probe, remembered).
1626
1675
  */
1627
1676
  async list(includeTerminated) {
1628
- return this._agentsOr("", { includeTerminated }, () => this.venue.operations.run("v/ops/agent/list", { includeTerminated }));
1677
+ const result = await this._agentsOr("", { includeTerminated }, () => this.venue.operations.run("v/ops/agent/list", { includeTerminated }));
1678
+ const raw = result?.agents ?? [];
1679
+ const agents = raw.map((a) => typeof a === "string" ? { agentId: a } : a);
1680
+ return { agents };
1629
1681
  }
1630
1682
  async delete(agentId, remove) {
1631
1683
  return this.venue.operations.run("v/ops/agent/delete", { agentId, remove });
@@ -1812,9 +1864,12 @@ var JobManager = class {
1812
1864
  this.venue = venue;
1813
1865
  }
1814
1866
  async list() {
1815
- return fetchWithError(`${this.venue.baseUrl}/api/v1/jobs`, {
1867
+ const body = await fetchWithError(`${this.venue.baseUrl}/api/v1/jobs`, {
1816
1868
  headers: this._buildHeaders()
1817
1869
  });
1870
+ if (Array.isArray(body)) return body;
1871
+ const items = body?.items;
1872
+ return Array.isArray(items) ? items : [];
1818
1873
  }
1819
1874
  async get(jobId) {
1820
1875
  try {
@@ -2002,21 +2057,23 @@ var AssetManager = class {
2002
2057
  */
2003
2058
  async get(assetId) {
2004
2059
  if (cache.has(assetId)) {
2005
- const cachedData = cache.get(assetId);
2006
- if (cachedData.operation) {
2007
- return new Operation(assetId, this.venue, cachedData);
2008
- } else {
2009
- return new DataAsset(assetId, this.venue, cachedData);
2060
+ return this._wrap(assetId, cache.get(assetId));
2061
+ }
2062
+ const hash = assetHash(assetId);
2063
+ if (hash) {
2064
+ const persisted = getAssetMetadataStore()?.get(normaliseHash(hash));
2065
+ if (persisted) {
2066
+ cache.set(assetId, persisted);
2067
+ return this._wrap(assetId, persisted);
2010
2068
  }
2011
2069
  }
2012
2070
  try {
2013
2071
  const data = await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`);
2014
- if (assetHash(assetId)) cache.set(assetId, data);
2015
- if (data.operation) {
2016
- return new Operation(assetId, this.venue, data);
2017
- } else {
2018
- return new DataAsset(assetId, this.venue, data);
2072
+ if (hash) {
2073
+ cache.set(assetId, data);
2074
+ getAssetMetadataStore()?.put(normaliseHash(hash), data);
2019
2075
  }
2076
+ return this._wrap(assetId, data);
2020
2077
  } catch (error) {
2021
2078
  if (error instanceof NotFoundError) {
2022
2079
  throw new AssetNotFoundError(assetId);
@@ -2024,6 +2081,12 @@ var AssetManager = class {
2024
2081
  throw error;
2025
2082
  }
2026
2083
  }
2084
+ _wrap(assetId, data) {
2085
+ if (data.operation) {
2086
+ return new Operation(assetId, this.venue, data);
2087
+ }
2088
+ return new DataAsset(assetId, this.venue, data);
2089
+ }
2027
2090
  /**
2028
2091
  * List assets with pagination support
2029
2092
  * @param options - Pagination options (offset, limit)
@@ -2109,6 +2172,7 @@ var AssetManager = class {
2109
2172
  */
2110
2173
  clearCache() {
2111
2174
  cache.clear();
2175
+ getAssetMetadataStore()?.clear();
2112
2176
  }
2113
2177
  // `contentType` defaults to JSON for the metadata/register endpoints. Pass
2114
2178
  // `undefined` for binary content upload so fetch infers the type from the
@@ -2277,7 +2341,8 @@ var WorkspaceManager = class {
2277
2341
  return this._valuesOr("read", { path, maxSize }, () => this.venue.operations.run("v/ops/covia/read", { path, maxSize }));
2278
2342
  }
2279
2343
  async list(path, limit, offset, ucans) {
2280
- if (ucans?.length || !path) return this.venue.operations.run("v/ops/covia/list", { path, limit, offset }, { ucans });
2344
+ path = path || "/";
2345
+ if (ucans?.length) return this.venue.operations.run("v/ops/covia/list", { path, limit, offset }, { ucans });
2281
2346
  return this._valuesOr("list", { path, limit, offset }, () => this.venue.operations.run("v/ops/covia/list", { path, limit, offset }));
2282
2347
  }
2283
2348
  async slice(path, offset, limit, ucans) {
@@ -2801,4 +2866,4 @@ function relayDelegation(privateKey, venueDID, lifetimeSeconds, caps = []) {
2801
2866
  (*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
2802
2867
  */
2803
2868
 
2804
- 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, getParsedAssetId, grant, hexToPrivateKey, identityToken, isDid, isJobComplete, isJobFinished, isJobPaused, logger, parseDidUrl, parseRetryAfterMs, parseSSEStream, privateKeyToHex, relayDelegation, retryDelayMs, venueBaseUrlCandidates };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@covia/covia-sdk",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Typescript library for covia-ai",
5
5
  "packageManager": "pnpm@11.9.0",
6
6
  "main": "./dist/index.js",