@covia/covia-sdk 1.0.0 → 1.1.0

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
@@ -4,9 +4,52 @@ declare class Job {
4
4
  metadata: JobMetadata;
5
5
  constructor(id: string, venue: VenueInterface, metadata: JobMetadata);
6
6
  /**
7
- * Cancels the execution of the job
8
- * @returns {Promise<number>}
9
- */
7
+ * Whether the job has reached a terminal state
8
+ */
9
+ get isFinished(): boolean;
10
+ /**
11
+ * Whether the job completed successfully
12
+ */
13
+ get isComplete(): boolean;
14
+ /**
15
+ * The job output.
16
+ * @throws {Error} If the job has not finished yet.
17
+ * @throws {JobFailedError} If the job finished with a non-COMPLETE status.
18
+ */
19
+ get output(): any;
20
+ /**
21
+ * Poll the venue for the latest job status.
22
+ * @throws {Error} If the job has no ID.
23
+ */
24
+ refresh(): Promise<void>;
25
+ /**
26
+ * Wait until the job reaches a terminal state.
27
+ * Uses exponential backoff polling (initial 300ms, factor 1.5, max 10s).
28
+ * @param options.timeout - Maximum milliseconds to wait. Undefined waits indefinitely.
29
+ * @throws {CoviaTimeoutError} If timeout is exceeded.
30
+ */
31
+ wait(options?: {
32
+ timeout?: number;
33
+ }): Promise<void>;
34
+ /**
35
+ * Wait for the job to complete and return its output.
36
+ * @param options.timeout - Maximum milliseconds to wait.
37
+ * @returns The job output.
38
+ * @throws {JobFailedError} If the job finishes with a non-COMPLETE status.
39
+ * @throws {CoviaTimeoutError} If timeout is exceeded.
40
+ */
41
+ result(options?: {
42
+ timeout?: number;
43
+ }): Promise<any>;
44
+ /**
45
+ * Stream server-sent events for this job.
46
+ * @returns AsyncGenerator yielding SSEEvent objects
47
+ */
48
+ stream(): AsyncGenerator<SSEEvent>;
49
+ /**
50
+ * Cancels the execution of the job
51
+ * @returns {Promise<number>}
52
+ */
10
53
  cancelJob(): Promise<number>;
11
54
  /**
12
55
  * Delete the job
@@ -33,11 +76,11 @@ declare abstract class Asset {
33
76
  */
34
77
  readStream(reader: ReadableStreamDefaultReader<Uint8Array>): Promise<void>;
35
78
  /**
36
- * Upload content to asset
79
+ * Put content to asset
37
80
  * @param content - Content to upload
38
81
  * @returns {Promise<ReadableStream<Uint8Array> | null>}
39
82
  */
40
- uploadContent(content: BodyInit): Promise<ReadableStream<Uint8Array> | null>;
83
+ putContent(content: BodyInit): Promise<ReadableStream<Uint8Array> | null>;
41
84
  /**
42
85
  * Get asset content
43
86
  * @returns {Promise<ReadableStream<Uint8Array> | null>}
@@ -62,11 +105,63 @@ declare abstract class Asset {
62
105
  invoke(input: any): Promise<Job>;
63
106
  }
64
107
 
108
+ /**
109
+ * Abstract base class for authentication strategies.
110
+ * Subclass this to implement custom authentication.
111
+ *
112
+ * Example — custom API-key auth:
113
+ *
114
+ * class ApiKeyAuth extends Auth {
115
+ * constructor(private key: string) { super(); }
116
+ * apply(headers: Record<string, string>): void {
117
+ * headers["X-Api-Key"] = this.key;
118
+ * }
119
+ * }
120
+ */
121
+ declare abstract class Auth {
122
+ /** Apply authentication credentials to request headers (mutates in place). */
123
+ abstract apply(headers: Record<string, string>): void;
124
+ }
125
+ /** No-op authentication provider. Sends no credentials. */
126
+ declare class NoAuth extends Auth {
127
+ apply(_headers: Record<string, string>): void;
128
+ }
129
+ /**
130
+ * Bearer token authentication.
131
+ * Adds `Authorization: Bearer <token>` to every request.
132
+ *
133
+ * Example:
134
+ * const venue = await Grid.connect("https://venue.covia.ai", new BearerAuth("my-token"));
135
+ */
136
+ declare class BearerAuth extends Auth {
137
+ private _token;
138
+ constructor(token: string);
139
+ apply(headers: Record<string, string>): void;
140
+ }
141
+ /**
142
+ * HTTP Basic authentication.
143
+ * Adds `Authorization: Basic <base64(username:password)>` to every request.
144
+ */
145
+ declare class BasicAuth extends Auth {
146
+ private _encoded;
147
+ constructor(username: string, password: string);
148
+ apply(headers: Record<string, string>): void;
149
+ }
150
+ /**
151
+ * Custom auth that sets the X-Covia-User header for user identity tracking.
152
+ */
153
+ declare class CoviaUserAuth extends Auth {
154
+ private _userId;
155
+ constructor(userId: string);
156
+ apply(headers: Record<string, string>): void;
157
+ }
158
+ /** @deprecated Use Auth subclasses instead (NoAuth, BearerAuth, BasicAuth, CoviaUserAuth). */
65
159
  interface Credentials {
66
160
  venueId: string;
67
161
  apiKey: string;
68
162
  userId: string;
69
163
  }
164
+ /** @deprecated Use Auth subclasses instead (NoAuth, BearerAuth, BasicAuth, CoviaUserAuth). */
70
165
  declare class CredentialsHTTP implements Credentials {
71
166
  venueId: string;
72
167
  apiKey: string;
@@ -77,7 +172,7 @@ declare class CredentialsHTTP implements Credentials {
77
172
  declare class Venue implements VenueInterface {
78
173
  baseUrl: string;
79
174
  venueId: string;
80
- credentials: Credentials;
175
+ auth: Auth;
81
176
  metadata: VenueData;
82
177
  constructor(options?: VenueOptions);
83
178
  /**
@@ -86,13 +181,13 @@ declare class Venue implements VenueInterface {
86
181
  * @param credentials - Optional credentials for venue authentication
87
182
  * @returns {Promise<Venue>} A new Venue instance configured appropriately
88
183
  */
89
- static connect(venueId: string | Venue, credentials?: CredentialsHTTP): Promise<Venue>;
184
+ static connect(venueId: string | Venue, auth?: Auth): Promise<Venue>;
90
185
  /**
91
- * Create a new asset
186
+ * Register a new asset
92
187
  * @param assetData - Asset configuration
93
188
  * @returns {Promise<Asset>}
94
189
  */
95
- createAsset(assetData: any): Promise<Asset>;
190
+ register(assetData: any): Promise<Asset>;
96
191
  /**
97
192
  * Read stream from asset
98
193
  * @param reader - ReadableStreamDefaultReader
@@ -105,15 +200,16 @@ declare class Venue implements VenueInterface {
105
200
  */
106
201
  getAsset(assetId: AssetID): Promise<Asset>;
107
202
  /**
108
- * Get all assets
109
- * @returns {Promise<Asset[]>}
203
+ * List assets with pagination support
204
+ * @param options - Pagination options (offset, limit)
205
+ * @returns {Promise<AssetList>} Paginated list of asset IDs with metadata
110
206
  */
111
- getAssets(): Promise<Asset[]>;
207
+ listAssets(options?: AssetListOptions): Promise<AssetList>;
112
208
  /**
113
- * Get all jobs
209
+ * List all jobs
114
210
  * @returns {Promise<string[]>}
115
211
  */
116
- getJobs(): Promise<string[]>;
212
+ listJobs(): Promise<string[]>;
117
213
  /**
118
214
  * Get job by ID
119
215
  * @param jobId - Job identifier
@@ -133,21 +229,47 @@ declare class Venue implements VenueInterface {
133
229
  */
134
230
  deleteJob(jobId: string): Promise<number>;
135
231
  /**
136
- * Get the DID (Decentralized Identifier) for this venue
137
- * @returns {string} DID in the format did:web:domain
138
- */
139
- getStats(): Promise<StatusData>;
232
+ * Get venue status
233
+ * @returns {Promise<StatusData>}
234
+ */
235
+ status(): Promise<StatusData>;
236
+ /**
237
+ * List all named operations available on this venue
238
+ * @returns {Promise<OperationInfo[]>}
239
+ */
240
+ listOperations(): Promise<OperationInfo[]>;
241
+ /**
242
+ * Get details of a named operation
243
+ * @param name - Operation name (e.g., "test:echo")
244
+ * @returns {Promise<OperationInfo>}
245
+ */
246
+ getOperation(name: string): Promise<OperationInfo>;
247
+ /**
248
+ * Get the full DID document for this venue
249
+ * @returns {Promise<DIDDocument>}
250
+ */
251
+ didDocument(): Promise<DIDDocument>;
252
+ /**
253
+ * Get MCP (Model Context Protocol) discovery information
254
+ * @returns {Promise<MCPDiscovery>}
255
+ */
256
+ mcpDiscovery(): Promise<MCPDiscovery>;
257
+ /**
258
+ * Get the A2A (Agent-to-Agent) agent card
259
+ * @returns {Promise<AgentCard>}
260
+ */
261
+ agentCard(): Promise<AgentCard>;
140
262
  /**
141
263
  * Get asset metadata
142
264
  * @returns {Promise<AssetMetadata>}
143
265
  */
144
266
  getMetadata(assetId: string): Promise<AssetMetadata>;
145
267
  /**
146
- * Upload content to asset
147
- * @param content - Content to upload
148
- * @returns {Promise<ReadableStream<Uint8Array> | null>}
149
- */
150
- uploadContent(assetId: string, content: BodyInit): Promise<ReadableStream<Uint8Array> | null>;
268
+ * Put content to asset
269
+ * @param content - Content to upload
270
+ * @returns {Promise<ReadableStream<Uint8Array> | null>}
271
+ */
272
+ putContent(assetId: string, content: BodyInit): Promise<ReadableStream<Uint8Array> | null>;
151
273
  /**
152
274
  * Get asset content
153
275
  * @returns {Promise<ReadableStream<Uint8Array> | null>}
@@ -165,7 +287,22 @@ declare class Venue implements VenueInterface {
165
287
  * @returns {Promise<Job>}
166
288
  */
167
289
  invoke(assetId: string, input: any): Promise<Job>;
168
- private setCredentialsInHeader;
290
+ /**
291
+ * Stream server-sent events for a job.
292
+ * @param jobId - Job identifier
293
+ * @returns AsyncGenerator yielding SSEEvent objects
294
+ */
295
+ streamJobEvents(jobId: string): AsyncGenerator<SSEEvent>;
296
+ /**
297
+ * Close the venue and release resources.
298
+ * Clears cached asset data for this venue.
299
+ */
300
+ close(): void;
301
+ /**
302
+ * Disposable support — allows `using venue = await Grid.connect(...)` in TS 5.2+.
303
+ */
304
+ [Symbol.dispose](): void;
305
+ private _buildHeaders;
169
306
  }
170
307
 
171
308
  interface VenueOptions {
@@ -173,11 +310,11 @@ interface VenueOptions {
173
310
  venueId?: string;
174
311
  name?: string;
175
312
  description?: string;
176
- credentials?: Credentials;
313
+ auth?: Auth;
177
314
  }
178
315
  interface VenueConstructor {
179
316
  new (): VenueInterface;
180
- connect(venueId: string | Venue, credentials?: CredentialsHTTP): Promise<Venue>;
317
+ connect(venueId: string | Venue, auth?: Auth): Promise<Venue>;
181
318
  }
182
319
  interface VenueInterface {
183
320
  baseUrl: string;
@@ -185,18 +322,25 @@ interface VenueInterface {
185
322
  metadata: VenueData;
186
323
  cancelJob(jobId: string): Promise<number>;
187
324
  deleteJob(jobId: string): Promise<number>;
188
- getStats(): Promise<StatusData>;
325
+ status(): Promise<StatusData>;
189
326
  getJob(jobId: string): Promise<Job>;
190
- getJobs(): Promise<string[]>;
327
+ listJobs(): Promise<string[]>;
191
328
  getAsset(assetId: AssetID): Promise<Asset>;
192
- createAsset(assetData: any, userEmail: string): Promise<Asset>;
193
- getAssets(): Promise<Asset[]>;
329
+ register(assetData: any): Promise<Asset>;
194
330
  getMetadata(assetId: string): Promise<AssetMetadata>;
195
331
  readStream(reader: ReadableStreamDefaultReader<Uint8Array>): Promise<void>;
196
- uploadContent(assetId: string, content: BodyInit): Promise<ReadableStream<Uint8Array> | null>;
332
+ putContent(assetId: string, content: BodyInit): Promise<ReadableStream<Uint8Array> | null>;
197
333
  getContent(assetId: string): Promise<ReadableStream<Uint8Array> | null>;
198
334
  run(assetId: string, input: any): Promise<any>;
199
335
  invoke(assetId: string, input: any): Promise<Job>;
336
+ listAssets(options?: AssetListOptions): Promise<AssetList>;
337
+ listOperations(): Promise<OperationInfo[]>;
338
+ getOperation(name: string): Promise<OperationInfo>;
339
+ didDocument(): Promise<DIDDocument>;
340
+ mcpDiscovery(): Promise<MCPDiscovery>;
341
+ agentCard(): Promise<AgentCard>;
342
+ streamJobEvents(jobId: string): AsyncGenerator<SSEEvent>;
343
+ close(): void;
200
344
  }
201
345
  type AssetID = string;
202
346
  interface AssetMetadata {
@@ -257,6 +401,9 @@ declare enum RunStatus {
257
401
  AUTH_REQUIRED = "AUTH_REQUIRED",
258
402
  PAUSED = "PAUSED"
259
403
  }
404
+ /** Alias for RunStatus — matches Python SDK naming */
405
+ declare const JobStatus: typeof RunStatus;
406
+ type JobStatus = RunStatus;
260
407
  interface StatusData {
261
408
  url?: string;
262
409
  ts?: string;
@@ -271,10 +418,92 @@ interface StatsData {
271
418
  ops?: number;
272
419
  jobs?: number;
273
420
  }
421
+ interface AssetListOptions {
422
+ offset?: number;
423
+ limit?: number;
424
+ }
425
+ interface AssetList {
426
+ items: string[];
427
+ total: number;
428
+ offset: number;
429
+ limit: number;
430
+ }
431
+ interface MCPDiscovery {
432
+ mcp_version?: string;
433
+ server_url?: string;
434
+ description?: string;
435
+ tools_endpoint?: string;
436
+ endpoint?: Record<string, any> | string;
437
+ [key: string]: any;
438
+ }
439
+ interface AgentCard {
440
+ agentProvider?: Record<string, any>;
441
+ agentCapabilities?: Record<string, any>;
442
+ agentSkills?: Record<string, any>[];
443
+ agentInterfaces?: Record<string, any>[];
444
+ securityScheme?: Record<string, any>;
445
+ preferredTransport?: Record<string, any>;
446
+ [key: string]: any;
447
+ }
448
+ interface DIDDocument {
449
+ id: string;
450
+ '@context'?: string | string[];
451
+ [key: string]: any;
452
+ }
453
+ interface OperationInfo {
454
+ name: string;
455
+ asset: string;
456
+ description?: string;
457
+ input?: any;
458
+ output?: any;
459
+ [key: string]: any;
460
+ }
461
+ /** A single server-sent event received from a Covia venue. */
462
+ interface SSEEvent {
463
+ event: string | null;
464
+ data: string;
465
+ id: string | null;
466
+ retry: number | null;
467
+ /** Parse the event data as JSON. */
468
+ json: () => any;
469
+ }
274
470
  declare class CoviaError extends Error {
275
471
  code: number | null;
276
472
  constructor(message: string, code?: number | null);
277
473
  }
474
+ /** Raised when the Covia API returns an error response (4xx/5xx). */
475
+ declare class GridError extends CoviaError {
476
+ statusCode: number;
477
+ responseBody: any;
478
+ constructor(statusCode: number, message: string, responseBody?: any);
479
+ }
480
+ /** Raised when the SDK cannot connect to the venue. */
481
+ declare class CoviaConnectionError extends CoviaError {
482
+ constructor(message: string);
483
+ }
484
+ /** Raised when an operation or polling loop times out. */
485
+ declare class CoviaTimeoutError extends CoviaError {
486
+ constructor(message: string);
487
+ }
488
+ /** Raised when a job finishes with a non-COMPLETE status. */
489
+ declare class JobFailedError extends CoviaError {
490
+ jobData: JobMetadata;
491
+ constructor(jobData: JobMetadata);
492
+ }
493
+ /** Raised when a requested resource is not found (404). */
494
+ declare class NotFoundError extends GridError {
495
+ constructor(message: string);
496
+ }
497
+ /** Raised when an asset is not found (404). */
498
+ declare class AssetNotFoundError extends NotFoundError {
499
+ assetId: string;
500
+ constructor(assetId: string);
501
+ }
502
+ /** Raised when a job is not found (404). */
503
+ declare class JobNotFoundError extends NotFoundError {
504
+ jobId: string;
505
+ constructor(jobId: string);
506
+ }
278
507
 
279
508
  /**
280
509
  * Utility function to handle API calls with consistent error handling
@@ -322,14 +551,47 @@ declare function getParsedAssetId(assetId: string): string;
322
551
  */
323
552
  declare function getAssetIdFromPath(assetHex: string, assetPath: string): string;
324
553
  declare function getAssetIdFromVenueId(assetHex: string, venueId: string): string;
554
+ /**
555
+ * Create an SSEEvent object from parsed fields.
556
+ */
557
+ declare function createSSEEvent(fields: {
558
+ event?: string;
559
+ data?: string;
560
+ id?: string;
561
+ retry?: number;
562
+ }): SSEEvent;
563
+ /**
564
+ * Parse an SSE stream from a fetch Response body.
565
+ * Yields SSEEvent objects as they arrive.
566
+ */
567
+ declare function parseSSEStream(response: Response): AsyncGenerator<SSEEvent>;
568
+
569
+ /**
570
+ * Simple logger for the Covia SDK.
571
+ *
572
+ * By default logging is disabled (level = 'none'). Enable debug output with:
573
+ * import { logger } from '@covia/covia-sdk';
574
+ * logger.level = 'debug';
575
+ *
576
+ * Or provide a custom log function:
577
+ * logger.handler = (level, msg) => myLogger.log(level, msg);
578
+ */
579
+ type LogLevel = 'debug' | 'none';
580
+ type LogHandler = (level: string, message: string) => void;
581
+ declare const logger: {
582
+ level: LogLevel;
583
+ handler: LogHandler;
584
+ debug(message: string): void;
585
+ };
325
586
 
326
587
  declare class Grid {
327
588
  /**
328
589
  * Static method to connect to a venue
329
590
  * @param venueId - Can be a HTTP base URL, DNS name, or existing Venue instance
591
+ * @param auth - Optional authentication provider (BearerAuth, BasicAuth, etc.)
330
592
  * @returns {Promise<Venue>} A new Venue instance configured appropriately
331
593
  */
332
- static connect(venueId: string, credentials?: CredentialsHTTP): Promise<Venue>;
594
+ static connect(venueId: string, auth?: Auth): Promise<Venue>;
333
595
  }
334
596
 
335
597
  declare class Operation extends Asset {
@@ -340,4 +602,4 @@ declare class DataAsset extends Asset {
340
602
  constructor(id: AssetID, venue: VenueInterface, metadata?: AssetMetadata);
341
603
  }
342
604
 
343
- export { Asset, type AssetID, type AssetMetadata, type ContentDetails, CoviaError, type Credentials, CredentialsHTTP, DataAsset, Grid, type InvokePayload, Job, type JobMetadata, Operation, type OperationDetails, type OperationPayload, RunStatus, type StatsData, type StatusData, Venue, type VenueConstructor, type VenueData, type VenueInterface, type VenueOptions, fetchStreamWithError, fetchWithError, getAssetIdFromPath, getAssetIdFromVenueId, getParsedAssetId, isJobComplete, isJobFinished, isJobPaused };
605
+ export { type AgentCard, Asset, type AssetID, type AssetList, type AssetListOptions, type AssetMetadata, AssetNotFoundError, Auth, BasicAuth, BearerAuth, type ContentDetails, CoviaConnectionError, CoviaError, CoviaTimeoutError, CoviaUserAuth, type Credentials, CredentialsHTTP, type DIDDocument, DataAsset, Grid, GridError, type InvokePayload, Job, JobFailedError, type JobMetadata, JobNotFoundError, JobStatus, type MCPDiscovery, NoAuth, NotFoundError, Operation, type OperationDetails, type OperationInfo, type OperationPayload, RunStatus, type SSEEvent, type StatsData, type StatusData, Venue, type VenueConstructor, type VenueData, type VenueInterface, type VenueOptions, createSSEEvent, fetchStreamWithError, fetchWithError, getAssetIdFromPath, getAssetIdFromVenueId, getParsedAssetId, isJobComplete, isJobFinished, isJobPaused, logger, parseSSEStream };