@covia/covia-sdk 1.0.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Covia AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # @covia/covia-sdk
2
+
3
+ [![npm version](https://badge.fury.io/js/@covia%2Fcovia-sdk.svg)](https://www.npmjs.com/package/@covia/covia-sdk)
4
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ TypeScript SDK for [Covia.ai](https://covia.ai) - The Universal Grid for AI Orchestration & Multi-Agent Workflows.
8
+
9
+ Covia.ai provides federated execution, cryptographic verification, and shared state management for AI agents across organizations, clouds, and platforms.
10
+
11
+ ## Features
12
+
13
+ - 🔒 **Type-Safe API** - Full TypeScript support with complete type definitions
14
+ - 🎯 **Asset Management** - Work with Operations and Data Assets through a unified interface
15
+ - 🔄 **Streaming Support** - Built-in support for streaming content and responses
16
+ - 💾 **Intelligent Caching** - Automatic caching for improved performance
17
+ - 🛡️ **Error Handling** - Comprehensive error handling with typed exceptions
18
+ - 🌐 **Federated Execution** - Connect to Covia venues for cross-organizational workflows
19
+ - 📦 **Dual Module Support** - Works with both CommonJS and ES Modules
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install @covia/covia-sdk
25
+ ```
26
+
27
+ Or with yarn:
28
+
29
+ ```bash
30
+ yarn add @covia/covia-sdk
31
+ ```
32
+
33
+ Or with pnpm:
34
+
35
+ ```bash
36
+ pnpm add @covia/covia-sdk
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ```typescript
42
+ import { Grid } from '@covia/covia-sdk';
43
+
44
+ // Connect to a venue
45
+ const venue = await Grid.connect("venue-did");
46
+
47
+ // Get assets (returns Operation or DataAsset based on metadata)
48
+ const operation = await venue.getAsset('op-id');
49
+ const dataAsset = await venue.getAsset('data-id');
50
+
51
+ // Invoke an operation
52
+ await operation.invoke({ param: 'value' });
53
+
54
+ // Upload data to a data asset
55
+ await dataAsset.uploadContent(content);
56
+ ```
57
+
58
+ ## Requirements
59
+
60
+ - Node.js >= 18.0.0
61
+ - TypeScript >= 5.0.0 (for TypeScript users)
62
+
63
+ ## TypeScript Support
64
+
65
+ `@covia/covia-sdk` is written in TypeScript and ships with full type declarations. No `@types/` package is needed.
66
+
67
+ ```typescript
68
+ import { Venue, Operation, DataAsset, CoviaError, AssetMetadata } from '@covia/covia-sdk';
69
+ ```
70
+
71
+ ## Testing
72
+
73
+ ```bash
74
+ npm test
75
+ ```
76
+
77
+ ## Resources
78
+
79
+ - [Covia.ai Platform](https://covia.ai)
80
+ - [Official Documentation](https://docs.covia.ai/)
81
+ - [GitHub Repository](https://github.com/covia-ai/covia-sdk)
82
+ - [Issue Tracker](https://github.com/covia-ai/covia-sdk/issues)
83
+ - [npm Package](https://www.npmjs.com/package/@covia/covia-sdk)
84
+
85
+ ## License
86
+
87
+ MIT © Covia AI
88
+
89
+ ## Support
90
+
91
+ For questions, issues, or feature requests:
92
+
93
+ - 📧 Email: info@covia.ai
94
+ - 💬 GitHub Issues: [github.com/covia-ai/covia-sdk/issues](https://github.com/covia-ai/covia-sdk/issues)
95
+ - 📚 Documentation: [docs.covia.ai](https://docs.covia.ai/)
96
+
97
+ ---
98
+
99
+ Built with ❤️ by [Covia Labs](https://covia.ai) - Foundational infrastructure for the agent economy
@@ -0,0 +1,343 @@
1
+ declare class Job {
2
+ id: string;
3
+ venue: VenueInterface;
4
+ metadata: JobMetadata;
5
+ constructor(id: string, venue: VenueInterface, metadata: JobMetadata);
6
+ /**
7
+ * Cancels the execution of the job
8
+ * @returns {Promise<number>}
9
+ */
10
+ cancelJob(): Promise<number>;
11
+ /**
12
+ * Delete the job
13
+ * @returns {Promise<number>}
14
+ */
15
+ deleteJob(): Promise<number>;
16
+ }
17
+
18
+ declare abstract class Asset {
19
+ id: AssetID;
20
+ venue: VenueInterface;
21
+ metadata: AssetMetadata;
22
+ status?: RunStatus;
23
+ error?: string;
24
+ constructor(id: AssetID, venue: VenueInterface, metadata?: AssetMetadata);
25
+ /**
26
+ * Get asset metadata
27
+ * @returns {Promise<AssetMetadata>}
28
+ */
29
+ getMetadata(): Promise<AssetMetadata>;
30
+ /**
31
+ * Read stream from asset
32
+ * @param reader - ReadableStreamDefaultReader
33
+ */
34
+ readStream(reader: ReadableStreamDefaultReader<Uint8Array>): Promise<void>;
35
+ /**
36
+ * Upload content to asset
37
+ * @param content - Content to upload
38
+ * @returns {Promise<ReadableStream<Uint8Array> | null>}
39
+ */
40
+ uploadContent(content: BodyInit): Promise<ReadableStream<Uint8Array> | null>;
41
+ /**
42
+ * Get asset content
43
+ * @returns {Promise<ReadableStream<Uint8Array> | null>}
44
+ */
45
+ getContent(): Promise<ReadableStream<Uint8Array> | null>;
46
+ /**
47
+ * Get the URL for downloading asset content
48
+ * @returns {string} The URL for downloading the asset content
49
+ */
50
+ getContentURL(): string;
51
+ /**
52
+ * Execute the operation
53
+ * @param input - Operation input parameters
54
+ * @returns {Promise<any>}
55
+ */
56
+ run(input: any): Promise<any>;
57
+ /**
58
+ * Execute the operation
59
+ * @param input - Operation input parameters
60
+ * @returns {Promise<any>}
61
+ */
62
+ invoke(input: any): Promise<Job>;
63
+ }
64
+
65
+ interface Credentials {
66
+ venueId: string;
67
+ apiKey: string;
68
+ userId: string;
69
+ }
70
+ declare class CredentialsHTTP implements Credentials {
71
+ venueId: string;
72
+ apiKey: string;
73
+ userId: string;
74
+ constructor(venueId: string, apiKey: string, userId: string);
75
+ }
76
+
77
+ declare class Venue implements VenueInterface {
78
+ baseUrl: string;
79
+ venueId: string;
80
+ credentials: Credentials;
81
+ metadata: VenueData;
82
+ constructor(options?: VenueOptions);
83
+ /**
84
+ * Static method to connect to a venue
85
+ * @param venueId - Can be a HTTP base URL, DNS name, or existing Venue instance
86
+ * @param credentials - Optional credentials for venue authentication
87
+ * @returns {Promise<Venue>} A new Venue instance configured appropriately
88
+ */
89
+ static connect(venueId: string | Venue, credentials?: CredentialsHTTP): Promise<Venue>;
90
+ /**
91
+ * Create a new asset
92
+ * @param assetData - Asset configuration
93
+ * @returns {Promise<Asset>}
94
+ */
95
+ createAsset(assetData: any): Promise<Asset>;
96
+ /**
97
+ * Read stream from asset
98
+ * @param reader - ReadableStreamDefaultReader
99
+ */
100
+ readStream(reader: ReadableStreamDefaultReader<Uint8Array>): Promise<void>;
101
+ /**
102
+ * Get asset by ID
103
+ * @param assetId - Asset identifier
104
+ * @returns {Promise<Asset>} Returns either an Operation or DataAsset based on the asset's metadata
105
+ */
106
+ getAsset(assetId: AssetID): Promise<Asset>;
107
+ /**
108
+ * Get all assets
109
+ * @returns {Promise<Asset[]>}
110
+ */
111
+ getAssets(): Promise<Asset[]>;
112
+ /**
113
+ * Get all jobs
114
+ * @returns {Promise<string[]>}
115
+ */
116
+ getJobs(): Promise<string[]>;
117
+ /**
118
+ * Get job by ID
119
+ * @param jobId - Job identifier
120
+ * @returns {Promise<Job>}
121
+ */
122
+ getJob(jobId: string): Promise<Job>;
123
+ /**
124
+ * Cancel job by ID
125
+ * @param jobId - Job identifier
126
+ * @returns {Promise<number>}
127
+ */
128
+ cancelJob(jobId: string): Promise<number>;
129
+ /**
130
+ * Delete job by ID
131
+ * @param jobId - Job identifier
132
+ * @returns {Promise<number>}
133
+ */
134
+ deleteJob(jobId: string): Promise<number>;
135
+ /**
136
+ * Get the DID (Decentralized Identifier) for this venue
137
+ * @returns {string} DID in the format did:web:domain
138
+ */
139
+ getStats(): Promise<StatusData>;
140
+ /**
141
+ * Get asset metadata
142
+ * @returns {Promise<AssetMetadata>}
143
+ */
144
+ getMetadata(assetId: string): Promise<AssetMetadata>;
145
+ /**
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>;
151
+ /**
152
+ * Get asset content
153
+ * @returns {Promise<ReadableStream<Uint8Array> | null>}
154
+ */
155
+ getContent(assetId: string): Promise<ReadableStream<Uint8Array> | null>;
156
+ /**
157
+ * Execute the operation
158
+ * @param input - Operation input parameters
159
+ * @returns {Promise<any>}
160
+ */
161
+ run(assetId: string, input: any): Promise<any>;
162
+ /**
163
+ * Execute the operation
164
+ * @param input - Operation input parameters
165
+ * @returns {Promise<Job>}
166
+ */
167
+ invoke(assetId: string, input: any): Promise<Job>;
168
+ private setCredentialsInHeader;
169
+ }
170
+
171
+ interface VenueOptions {
172
+ baseUrl?: string;
173
+ venueId?: string;
174
+ name?: string;
175
+ description?: string;
176
+ credentials?: Credentials;
177
+ }
178
+ interface VenueConstructor {
179
+ new (): VenueInterface;
180
+ connect(venueId: string | Venue, credentials?: CredentialsHTTP): Promise<Venue>;
181
+ }
182
+ interface VenueInterface {
183
+ baseUrl: string;
184
+ venueId: string;
185
+ metadata: VenueData;
186
+ cancelJob(jobId: string): Promise<number>;
187
+ deleteJob(jobId: string): Promise<number>;
188
+ getStats(): Promise<StatusData>;
189
+ getJob(jobId: string): Promise<Job>;
190
+ getJobs(): Promise<string[]>;
191
+ getAsset(assetId: AssetID): Promise<Asset>;
192
+ createAsset(assetData: any, userEmail: string): Promise<Asset>;
193
+ getAssets(): Promise<Asset[]>;
194
+ getMetadata(assetId: string): Promise<AssetMetadata>;
195
+ readStream(reader: ReadableStreamDefaultReader<Uint8Array>): Promise<void>;
196
+ uploadContent(assetId: string, content: BodyInit): Promise<ReadableStream<Uint8Array> | null>;
197
+ getContent(assetId: string): Promise<ReadableStream<Uint8Array> | null>;
198
+ run(assetId: string, input: any): Promise<any>;
199
+ invoke(assetId: string, input: any): Promise<Job>;
200
+ }
201
+ type AssetID = string;
202
+ interface AssetMetadata {
203
+ [key: string]: any;
204
+ name?: string;
205
+ description?: string;
206
+ type?: string;
207
+ created?: string;
208
+ updated?: string;
209
+ operation?: OperationDetails;
210
+ content?: ContentDetails;
211
+ input?: any;
212
+ output?: any;
213
+ }
214
+ interface VenueData {
215
+ description?: string;
216
+ name?: string;
217
+ }
218
+ /** Type for metadata.operation */
219
+ interface OperationDetails {
220
+ [key: string]: any;
221
+ adapter?: string;
222
+ input?: any;
223
+ output?: any;
224
+ steps?: any[];
225
+ result?: any;
226
+ }
227
+ /** Type for metadata.content */
228
+ interface ContentDetails {
229
+ [key: string]: any;
230
+ }
231
+ interface OperationPayload {
232
+ [key: string]: any;
233
+ }
234
+ interface JobMetadata {
235
+ name?: string;
236
+ status?: RunStatus;
237
+ created?: string;
238
+ updated?: string;
239
+ input?: any;
240
+ output?: any;
241
+ op?: string;
242
+ [key: string]: any;
243
+ }
244
+ interface InvokePayload {
245
+ assetId: AssetID;
246
+ payload: OperationPayload;
247
+ }
248
+ declare enum RunStatus {
249
+ COMPLETE = "COMPLETE",
250
+ FAILED = "FAILED",
251
+ PENDING = "PENDING",
252
+ STARTED = "STARTED",
253
+ CANCELLED = "CANCELLED",
254
+ TIMEOUT = "TIMEOUT",
255
+ REJECTED = "REJECTED",
256
+ INPUT_REQUIRED = "INPUT_REQUIRED",
257
+ AUTH_REQUIRED = "AUTH_REQUIRED",
258
+ PAUSED = "PAUSED"
259
+ }
260
+ interface StatusData {
261
+ url?: string;
262
+ ts?: string;
263
+ status?: string;
264
+ did?: string;
265
+ name?: string;
266
+ stats?: StatsData;
267
+ }
268
+ interface StatsData {
269
+ assets?: number;
270
+ users?: number;
271
+ ops?: number;
272
+ jobs?: number;
273
+ }
274
+ declare class CoviaError extends Error {
275
+ code: number | null;
276
+ constructor(message: string, code?: number | null);
277
+ }
278
+
279
+ /**
280
+ * Utility function to handle API calls with consistent error handling
281
+ * @param url - The URL to fetch
282
+ * @param options - Fetch options
283
+ * @returns {Promise<T>} The response data
284
+ */
285
+ declare function fetchWithError<T>(url: string, options?: RequestInit): Promise<T>;
286
+ /**
287
+ * Utility function to handle fetch requests that return streams
288
+ * @param url - The URL to fetch
289
+ * @param options - Fetch options
290
+ * @returns {Promise<Response>} The fetch response
291
+ */
292
+ declare function fetchStreamWithError(url: string, options?: RequestInit): Promise<Response>;
293
+ /**
294
+ * Utility function to check if job is considered completed
295
+ * @param jobStatus - The status of the job
296
+ * @returns {boolean} - Returns false if job is not completed , else returns true
297
+ */
298
+ declare function isJobComplete(jobStatus: RunStatus): boolean;
299
+ /**
300
+ * Utility function to check if job is considered paused
301
+ * @param jobStatus - The status of the job
302
+ * @returns {boolean} - Returns false if job is not paused , else returns true
303
+ */
304
+ declare function isJobPaused(jobStatus: RunStatus): boolean;
305
+ /**
306
+ * Utility function to check if job is considered finished
307
+ * @param jobStatus - The status of the job
308
+ * @returns {boolean} - Returns false if job is not finished , else returns true
309
+ */
310
+ declare function isJobFinished(jobStatus: RunStatus): boolean;
311
+ /**
312
+ * Utility function to parse the asset hex from the compelte assetId
313
+ * @param assetId - The complete assetId
314
+ * @returns {string} - Returns the parsed hexIdof the asset
315
+ */
316
+ declare function getParsedAssetId(assetId: string): string;
317
+ /**
318
+ * Utility function to return complete assetId from hex and path
319
+ * @param assetHex - The asset hex
320
+ * @param assetPath - The asset path
321
+ * @returns {string} - Returns the complete assetId
322
+ */
323
+ declare function getAssetIdFromPath(assetHex: string, assetPath: string): string;
324
+ declare function getAssetIdFromVenueId(assetHex: string, venueId: string): string;
325
+
326
+ declare class Grid {
327
+ /**
328
+ * Static method to connect to a venue
329
+ * @param venueId - Can be a HTTP base URL, DNS name, or existing Venue instance
330
+ * @returns {Promise<Venue>} A new Venue instance configured appropriately
331
+ */
332
+ static connect(venueId: string, credentials?: CredentialsHTTP): Promise<Venue>;
333
+ }
334
+
335
+ declare class Operation extends Asset {
336
+ constructor(id: AssetID, venue: VenueInterface, metadata?: AssetMetadata);
337
+ }
338
+
339
+ declare class DataAsset extends Asset {
340
+ constructor(id: AssetID, venue: VenueInterface, metadata?: AssetMetadata);
341
+ }
342
+
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 };