@resourcexjs/arp 0.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.
@@ -0,0 +1,370 @@
1
+ /**
2
+ * Transport Handler Interface
3
+ * Responsible for I/O primitives - read, write, list, exists, delete
4
+ * Transport only handles WHERE and HOW to access bytes, not WHAT they mean
5
+ */
6
+ /**
7
+ * Transport capabilities declaration
8
+ */
9
+ interface TransportCapabilities {
10
+ readonly canRead: boolean;
11
+ readonly canWrite: boolean;
12
+ readonly canList: boolean;
13
+ readonly canDelete: boolean;
14
+ readonly canStat: boolean;
15
+ }
16
+ /**
17
+ * Resource stat information
18
+ */
19
+ interface ResourceStat {
20
+ size: number;
21
+ modifiedAt?: Date;
22
+ isDirectory?: boolean;
23
+ }
24
+ /**
25
+ * Transport Handler - provides I/O primitives
26
+ */
27
+ interface TransportHandler {
28
+ /**
29
+ * Transport name (e.g., "https", "file", "s3")
30
+ */
31
+ readonly name: string;
32
+ /**
33
+ * Transport capabilities
34
+ */
35
+ readonly capabilities: TransportCapabilities;
36
+ /**
37
+ * Read content from location
38
+ * @param location - The location string after ://
39
+ * @returns Raw content as Buffer
40
+ */
41
+ read(location: string): Promise<Buffer>;
42
+ /**
43
+ * Write content to location
44
+ * @param location - The location string after ://
45
+ * @param content - Content to write
46
+ */
47
+ write?(location: string, content: Buffer): Promise<void>;
48
+ /**
49
+ * List entries at location (for directory-like transports)
50
+ * @param location - The location string after ://
51
+ * @returns Array of entry names
52
+ */
53
+ list?(location: string): Promise<string[]>;
54
+ /**
55
+ * Create directory at location
56
+ * @param location - The location string after ://
57
+ */
58
+ mkdir?(location: string): Promise<void>;
59
+ /**
60
+ * Check if resource exists at location
61
+ * @param location - The location string after ://
62
+ */
63
+ exists?(location: string): Promise<boolean>;
64
+ /**
65
+ * Get resource stat information
66
+ * @param location - The location string after ://
67
+ */
68
+ stat?(location: string): Promise<ResourceStat>;
69
+ /**
70
+ * Delete resource at location
71
+ * @param location - The location string after ://
72
+ */
73
+ delete?(location: string): Promise<void>;
74
+ }
75
+ /**
76
+ * Resource metadata
77
+ */
78
+ interface ResourceMeta {
79
+ url: string;
80
+ semantic: string;
81
+ transport: string;
82
+ location: string;
83
+ size: number;
84
+ encoding?: string;
85
+ mimeType?: string;
86
+ resolvedAt: string;
87
+ }
88
+ /**
89
+ * Context passed to semantic handler
90
+ */
91
+ interface SemanticContext {
92
+ url: string;
93
+ semantic: string;
94
+ transport: string;
95
+ location: string;
96
+ timestamp: Date;
97
+ }
98
+ /**
99
+ * Base resource interface
100
+ */
101
+ interface Resource<T = unknown> {
102
+ type: string;
103
+ content: T;
104
+ meta: ResourceMeta;
105
+ }
106
+ /**
107
+ * Semantic handler interface
108
+ * Semantic orchestrates Transport primitives to resolve/deposit resources
109
+ */
110
+ interface SemanticHandler<T = unknown> {
111
+ /**
112
+ * Semantic name (e.g., "text", "json", "package")
113
+ */
114
+ readonly name: string;
115
+ /**
116
+ * Resolve resource from location
117
+ * Semantic controls how to use transport primitives to fetch and parse resource
118
+ *
119
+ * @param transport - Transport handler for I/O operations
120
+ * @param location - Resource location
121
+ * @param context - Semantic context
122
+ */
123
+ resolve(transport: TransportHandler, location: string, context: SemanticContext): Promise<Resource<T>>;
124
+ /**
125
+ * Deposit resource to location
126
+ * Semantic controls how to serialize data and use transport primitives to store
127
+ *
128
+ * @param transport - Transport handler for I/O operations
129
+ * @param location - Resource location
130
+ * @param data - Data to deposit
131
+ * @param context - Semantic context
132
+ */
133
+ deposit?(transport: TransportHandler, location: string, data: T, context: SemanticContext): Promise<void>;
134
+ /**
135
+ * Check if resource exists at location
136
+ *
137
+ * @param transport - Transport handler for I/O operations
138
+ * @param location - Resource location
139
+ * @param context - Semantic context
140
+ */
141
+ exists?(transport: TransportHandler, location: string, context: SemanticContext): Promise<boolean>;
142
+ /**
143
+ * Delete resource at location
144
+ *
145
+ * @param transport - Transport handler for I/O operations
146
+ * @param location - Resource location
147
+ * @param context - Semantic context
148
+ */
149
+ delete?(transport: TransportHandler, location: string, context: SemanticContext): Promise<void>;
150
+ }
151
+ /**
152
+ * ARI - Agent Resource Identifier
153
+ * Identifies the type of resource without specifying location
154
+ */
155
+ interface ARI {
156
+ readonly semantic: string;
157
+ readonly transport: string;
158
+ }
159
+ /**
160
+ * ARL - Agent Resource Locator
161
+ * Full resource locator with operations
162
+ */
163
+ interface ARL extends ARI {
164
+ readonly location: string;
165
+ /**
166
+ * Resolve the resource
167
+ */
168
+ resolve(): Promise<Resource>;
169
+ /**
170
+ * Deposit data to the resource
171
+ */
172
+ deposit(data: unknown): Promise<void>;
173
+ /**
174
+ * Check if resource exists
175
+ */
176
+ exists(): Promise<boolean>;
177
+ /**
178
+ * Delete the resource
179
+ */
180
+ delete(): Promise<void>;
181
+ /**
182
+ * Convert to ARP URL string
183
+ */
184
+ toString(): string;
185
+ }
186
+ /**
187
+ * Handler resolver interface (implemented by ARP instance)
188
+ */
189
+ interface HandlerResolver {
190
+ getTransportHandler(name: string): TransportHandler;
191
+ getSemanticHandler(name: string): SemanticHandler;
192
+ }
193
+ /**
194
+ * ARL Implementation
195
+ */
196
+ declare class ARL2 implements ARL {
197
+ readonly semantic: string;
198
+ readonly transport: string;
199
+ readonly location: string;
200
+ private readonly resolver;
201
+ constructor(semantic: string, transport: string, location: string, resolver: HandlerResolver);
202
+ /**
203
+ * Create semantic context
204
+ */
205
+ private createContext;
206
+ /**
207
+ * Resolve the resource
208
+ */
209
+ resolve(): Promise<Resource>;
210
+ /**
211
+ * Deposit data to the resource
212
+ */
213
+ deposit(data: unknown): Promise<void>;
214
+ /**
215
+ * Check if resource exists
216
+ */
217
+ exists(): Promise<boolean>;
218
+ /**
219
+ * Delete the resource
220
+ */
221
+ delete(): Promise<void>;
222
+ /**
223
+ * Convert to ARP URL string
224
+ */
225
+ toString(): string;
226
+ }
227
+ /**
228
+ * ARP Configuration
229
+ */
230
+ interface ARPConfig {
231
+ /**
232
+ * Custom transport handlers
233
+ */
234
+ transports?: TransportHandler[];
235
+ /**
236
+ * Custom semantic handlers
237
+ */
238
+ semantics?: SemanticHandler[];
239
+ }
240
+ /**
241
+ * ARP Instance
242
+ */
243
+ declare class ARP implements HandlerResolver {
244
+ private readonly transports;
245
+ private readonly semantics;
246
+ constructor(config?: ARPConfig);
247
+ /**
248
+ * Register a transport handler
249
+ */
250
+ registerTransport(handler: TransportHandler): void;
251
+ /**
252
+ * Register a semantic handler
253
+ */
254
+ registerSemantic(handler: SemanticHandler): void;
255
+ /**
256
+ * Get transport handler by name
257
+ */
258
+ getTransportHandler(name: string): TransportHandler;
259
+ /**
260
+ * Get semantic handler by name
261
+ */
262
+ getSemanticHandler(name: string): SemanticHandler;
263
+ /**
264
+ * Parse an ARP URL into an ARL object
265
+ *
266
+ * @example
267
+ * const arl = arp.parse("arp:text:file:///path/to/file.txt");
268
+ * arl.semantic // "text"
269
+ * arl.transport // "file"
270
+ * arl.location // "/path/to/file.txt"
271
+ */
272
+ parse(url: string): ARL2;
273
+ }
274
+ /**
275
+ * Create a new ARP instance
276
+ *
277
+ * @example
278
+ * import { createARP, fileTransport, textSemantic } from "arpjs";
279
+ *
280
+ * const arp = createARP({
281
+ * transports: [fileTransport],
282
+ * semantics: [textSemantic],
283
+ * });
284
+ *
285
+ * const arl = arp.parse("arp:text:file:///path/to/file.txt");
286
+ * const resource = await arl.resolve();
287
+ */
288
+ declare function createARP(config?: ARPConfig): ARP;
289
+ /**
290
+ * ARP Error Types
291
+ */
292
+ /**
293
+ * Base error class for all ARP errors
294
+ */
295
+ declare class ARPError extends Error {
296
+ constructor(message: string, options?: ErrorOptions);
297
+ }
298
+ /**
299
+ * Error thrown when ARP URL parsing fails
300
+ */
301
+ declare class ParseError extends ARPError {
302
+ readonly url?: string;
303
+ constructor(message: string, url?: string);
304
+ }
305
+ /**
306
+ * Error thrown when transport layer fails
307
+ */
308
+ declare class TransportError extends ARPError {
309
+ readonly transport?: string;
310
+ constructor(message: string, transport?: string, options?: ErrorOptions);
311
+ }
312
+ /**
313
+ * Error thrown when semantic layer fails
314
+ */
315
+ declare class SemanticError extends ARPError {
316
+ readonly semantic?: string;
317
+ constructor(message: string, semantic?: string, options?: ErrorOptions);
318
+ }
319
+ declare class FileTransportHandler implements TransportHandler {
320
+ readonly name = "file";
321
+ readonly capabilities: TransportCapabilities;
322
+ private resolvePath;
323
+ read(location: string): Promise<Buffer>;
324
+ write(location: string, content: Buffer): Promise<void>;
325
+ list(location: string): Promise<string[]>;
326
+ mkdir(location: string): Promise<void>;
327
+ exists(location: string): Promise<boolean>;
328
+ stat(location: string): Promise<ResourceStat>;
329
+ delete(location: string): Promise<void>;
330
+ }
331
+ declare const fileTransport: FileTransportHandler;
332
+ declare class HttpTransportHandler implements TransportHandler {
333
+ readonly name: string;
334
+ private readonly protocol;
335
+ readonly capabilities: TransportCapabilities;
336
+ constructor(protocol?: "http" | "https");
337
+ read(location: string): Promise<Buffer>;
338
+ }
339
+ declare const httpsTransport: HttpTransportHandler;
340
+ declare const httpTransport: HttpTransportHandler;
341
+ interface TextResource extends Resource<string> {
342
+ type: "text";
343
+ content: string;
344
+ }
345
+ declare class TextSemanticHandler implements SemanticHandler<string> {
346
+ readonly name = "text";
347
+ resolve(transport: TransportHandler, location: string, context: SemanticContext): Promise<TextResource>;
348
+ deposit(transport: TransportHandler, location: string, data: string, _context: SemanticContext): Promise<void>;
349
+ exists(transport: TransportHandler, location: string, _context: SemanticContext): Promise<boolean>;
350
+ delete(transport: TransportHandler, location: string, _context: SemanticContext): Promise<void>;
351
+ }
352
+ declare const textSemantic: TextSemanticHandler;
353
+ interface BinaryResource extends Resource<Buffer> {
354
+ type: "binary";
355
+ content: Buffer;
356
+ }
357
+ /**
358
+ * Supported binary input types for deposit
359
+ */
360
+ type BinaryInput = Buffer | Uint8Array | ArrayBuffer | number[];
361
+ declare class BinarySemanticHandler implements SemanticHandler<Buffer> {
362
+ readonly name = "binary";
363
+ resolve(transport: TransportHandler, location: string, context: SemanticContext): Promise<BinaryResource>;
364
+ deposit(transport: TransportHandler, location: string, data: BinaryInput, _context: SemanticContext): Promise<void>;
365
+ exists(transport: TransportHandler, location: string, _context: SemanticContext): Promise<boolean>;
366
+ delete(transport: TransportHandler, location: string, _context: SemanticContext): Promise<void>;
367
+ }
368
+ declare const binarySemantic: BinarySemanticHandler;
369
+ declare const VERSION: string;
370
+ export { textSemantic, httpsTransport, httpTransport, fileTransport, createARP, binarySemantic, VERSION, TransportHandler, TransportError, TransportCapabilities, TextSemanticHandler, TextResource, SemanticHandler, SemanticError, SemanticContext, ResourceStat, ResourceMeta, Resource, ParseError, HttpTransportHandler, FileTransportHandler, BinarySemanticHandler, BinaryResource, BinaryInput, ARPError, ARPConfig, ARP, ARL, ARI };
package/dist/index.js ADDED
@@ -0,0 +1,451 @@
1
+ // src/errors.ts
2
+ class ARPError extends Error {
3
+ constructor(message, options) {
4
+ super(message, options);
5
+ this.name = "ARPError";
6
+ }
7
+ }
8
+
9
+ class ParseError extends ARPError {
10
+ url;
11
+ constructor(message, url) {
12
+ super(message);
13
+ this.url = url;
14
+ this.name = "ParseError";
15
+ }
16
+ }
17
+
18
+ class TransportError extends ARPError {
19
+ transport;
20
+ constructor(message, transport, options) {
21
+ super(message, options);
22
+ this.transport = transport;
23
+ this.name = "TransportError";
24
+ }
25
+ }
26
+
27
+ class SemanticError extends ARPError {
28
+ semantic;
29
+ constructor(message, semantic, options) {
30
+ super(message, options);
31
+ this.semantic = semantic;
32
+ this.name = "SemanticError";
33
+ }
34
+ }
35
+
36
+ // src/ARL.ts
37
+ class ARL {
38
+ semantic;
39
+ transport;
40
+ location;
41
+ resolver;
42
+ constructor(semantic, transport, location, resolver) {
43
+ this.semantic = semantic;
44
+ this.transport = transport;
45
+ this.location = location;
46
+ this.resolver = resolver;
47
+ }
48
+ createContext() {
49
+ return {
50
+ url: this.toString(),
51
+ semantic: this.semantic,
52
+ transport: this.transport,
53
+ location: this.location,
54
+ timestamp: new Date
55
+ };
56
+ }
57
+ async resolve() {
58
+ const transport = this.resolver.getTransportHandler(this.transport);
59
+ const semantic = this.resolver.getSemanticHandler(this.semantic);
60
+ const context = this.createContext();
61
+ return semantic.resolve(transport, this.location, context);
62
+ }
63
+ async deposit(data) {
64
+ const transport = this.resolver.getTransportHandler(this.transport);
65
+ const semantic = this.resolver.getSemanticHandler(this.semantic);
66
+ const context = this.createContext();
67
+ if (!semantic.deposit) {
68
+ throw new SemanticError(`Semantic "${semantic.name}" does not support deposit operation`, this.semantic);
69
+ }
70
+ await semantic.deposit(transport, this.location, data, context);
71
+ }
72
+ async exists() {
73
+ const transport = this.resolver.getTransportHandler(this.transport);
74
+ const semantic = this.resolver.getSemanticHandler(this.semantic);
75
+ const context = this.createContext();
76
+ if (semantic.exists) {
77
+ return semantic.exists(transport, this.location, context);
78
+ }
79
+ if (transport.exists) {
80
+ return transport.exists(this.location);
81
+ }
82
+ try {
83
+ await transport.read(this.location);
84
+ return true;
85
+ } catch {
86
+ return false;
87
+ }
88
+ }
89
+ async delete() {
90
+ const transport = this.resolver.getTransportHandler(this.transport);
91
+ const semantic = this.resolver.getSemanticHandler(this.semantic);
92
+ const context = this.createContext();
93
+ if (semantic.delete) {
94
+ return semantic.delete(transport, this.location, context);
95
+ }
96
+ if (!transport.delete) {
97
+ throw new SemanticError(`Neither semantic "${semantic.name}" nor transport "${transport.name}" supports delete operation`, this.semantic);
98
+ }
99
+ await transport.delete(this.location);
100
+ }
101
+ toString() {
102
+ return `arp:${this.semantic}:${this.transport}://${this.location}`;
103
+ }
104
+ }
105
+
106
+ // src/transport/file.ts
107
+ import { readFile, writeFile, readdir, mkdir, rm, access, stat as fsStat } from "node:fs/promises";
108
+ import { resolve, dirname } from "node:path";
109
+ class FileTransportHandler {
110
+ name = "file";
111
+ capabilities = {
112
+ canRead: true,
113
+ canWrite: true,
114
+ canList: true,
115
+ canDelete: true,
116
+ canStat: true
117
+ };
118
+ resolvePath(location) {
119
+ return resolve(process.cwd(), location);
120
+ }
121
+ async read(location) {
122
+ const filePath = this.resolvePath(location);
123
+ try {
124
+ return await readFile(filePath);
125
+ } catch (error) {
126
+ const err = error;
127
+ throw new TransportError(`File read error: ${err.code} - ${filePath}`, this.name, {
128
+ cause: err
129
+ });
130
+ }
131
+ }
132
+ async write(location, content) {
133
+ const filePath = this.resolvePath(location);
134
+ try {
135
+ await mkdir(dirname(filePath), { recursive: true });
136
+ await writeFile(filePath, content);
137
+ } catch (error) {
138
+ const err = error;
139
+ throw new TransportError(`File write error: ${err.code} - ${filePath}`, this.name, {
140
+ cause: err
141
+ });
142
+ }
143
+ }
144
+ async list(location) {
145
+ const dirPath = this.resolvePath(location);
146
+ try {
147
+ return await readdir(dirPath);
148
+ } catch (error) {
149
+ const err = error;
150
+ throw new TransportError(`Directory list error: ${err.code} - ${dirPath}`, this.name, {
151
+ cause: err
152
+ });
153
+ }
154
+ }
155
+ async mkdir(location) {
156
+ const dirPath = this.resolvePath(location);
157
+ try {
158
+ await mkdir(dirPath, { recursive: true });
159
+ } catch (error) {
160
+ const err = error;
161
+ throw new TransportError(`Directory create error: ${err.code} - ${dirPath}`, this.name, {
162
+ cause: err
163
+ });
164
+ }
165
+ }
166
+ async exists(location) {
167
+ const filePath = this.resolvePath(location);
168
+ try {
169
+ await access(filePath);
170
+ return true;
171
+ } catch {
172
+ return false;
173
+ }
174
+ }
175
+ async stat(location) {
176
+ const filePath = this.resolvePath(location);
177
+ try {
178
+ const stats = await fsStat(filePath);
179
+ return {
180
+ size: stats.size,
181
+ modifiedAt: stats.mtime,
182
+ isDirectory: stats.isDirectory()
183
+ };
184
+ } catch (error) {
185
+ const err = error;
186
+ throw new TransportError(`File stat error: ${err.code} - ${filePath}`, this.name, {
187
+ cause: err
188
+ });
189
+ }
190
+ }
191
+ async delete(location) {
192
+ const filePath = this.resolvePath(location);
193
+ try {
194
+ await rm(filePath, { recursive: true });
195
+ } catch (error) {
196
+ const err = error;
197
+ throw new TransportError(`File delete error: ${err.code} - ${filePath}`, this.name, {
198
+ cause: err
199
+ });
200
+ }
201
+ }
202
+ }
203
+ var fileTransport = new FileTransportHandler;
204
+ // src/transport/http.ts
205
+ class HttpTransportHandler {
206
+ name;
207
+ protocol;
208
+ capabilities = {
209
+ canRead: true,
210
+ canWrite: false,
211
+ canList: false,
212
+ canDelete: false,
213
+ canStat: false
214
+ };
215
+ constructor(protocol = "https") {
216
+ this.protocol = protocol;
217
+ this.name = protocol;
218
+ }
219
+ async read(location) {
220
+ const url = `${this.protocol}://${location}`;
221
+ try {
222
+ const response = await fetch(url);
223
+ if (!response.ok) {
224
+ throw new TransportError(`HTTP ${response.status}: ${response.statusText} - ${url}`, this.name);
225
+ }
226
+ const arrayBuffer = await response.arrayBuffer();
227
+ return Buffer.from(arrayBuffer);
228
+ } catch (error) {
229
+ if (error instanceof TransportError) {
230
+ throw error;
231
+ }
232
+ throw new TransportError(`Network error: ${url}`, this.name, {
233
+ cause: error
234
+ });
235
+ }
236
+ }
237
+ }
238
+ var httpsTransport = new HttpTransportHandler("https");
239
+ var httpTransport = new HttpTransportHandler("http");
240
+ // src/semantic/text.ts
241
+ class TextSemanticHandler {
242
+ name = "text";
243
+ async resolve(transport, location, context) {
244
+ const buffer = await transport.read(location);
245
+ const text = buffer.toString("utf-8");
246
+ const meta = {
247
+ url: context.url,
248
+ semantic: context.semantic,
249
+ transport: context.transport,
250
+ location: context.location,
251
+ size: buffer.length,
252
+ encoding: "utf-8",
253
+ mimeType: "text/plain",
254
+ resolvedAt: context.timestamp.toISOString()
255
+ };
256
+ return {
257
+ type: "text",
258
+ content: text,
259
+ meta
260
+ };
261
+ }
262
+ async deposit(transport, location, data, _context) {
263
+ if (!transport.write) {
264
+ throw new SemanticError(`Transport "${transport.name}" does not support write operation`, this.name);
265
+ }
266
+ const buffer = Buffer.from(data, "utf-8");
267
+ await transport.write(location, buffer);
268
+ }
269
+ async exists(transport, location, _context) {
270
+ if (transport.exists) {
271
+ return transport.exists(location);
272
+ }
273
+ try {
274
+ await transport.read(location);
275
+ return true;
276
+ } catch {
277
+ return false;
278
+ }
279
+ }
280
+ async delete(transport, location, _context) {
281
+ if (!transport.delete) {
282
+ throw new SemanticError(`Transport "${transport.name}" does not support delete operation`, this.name);
283
+ }
284
+ await transport.delete(location);
285
+ }
286
+ }
287
+ var textSemantic = new TextSemanticHandler;
288
+ // src/semantic/binary.ts
289
+ function toBuffer(data) {
290
+ if (Buffer.isBuffer(data)) {
291
+ return data;
292
+ }
293
+ if (data instanceof Uint8Array) {
294
+ return Buffer.from(data);
295
+ }
296
+ if (data instanceof ArrayBuffer) {
297
+ return Buffer.from(data);
298
+ }
299
+ if (Array.isArray(data)) {
300
+ return Buffer.from(data);
301
+ }
302
+ throw new SemanticError(`Unsupported binary input type`, "binary");
303
+ }
304
+
305
+ class BinarySemanticHandler {
306
+ name = "binary";
307
+ async resolve(transport, location, context) {
308
+ const buffer = await transport.read(location);
309
+ const meta = {
310
+ url: context.url,
311
+ semantic: context.semantic,
312
+ transport: context.transport,
313
+ location: context.location,
314
+ size: buffer.length,
315
+ resolvedAt: context.timestamp.toISOString()
316
+ };
317
+ return {
318
+ type: "binary",
319
+ content: buffer,
320
+ meta
321
+ };
322
+ }
323
+ async deposit(transport, location, data, _context) {
324
+ if (!transport.write) {
325
+ throw new SemanticError(`Transport "${transport.name}" does not support write operation`, this.name);
326
+ }
327
+ const buffer = toBuffer(data);
328
+ await transport.write(location, buffer);
329
+ }
330
+ async exists(transport, location, _context) {
331
+ if (transport.exists) {
332
+ return transport.exists(location);
333
+ }
334
+ try {
335
+ await transport.read(location);
336
+ return true;
337
+ } catch {
338
+ return false;
339
+ }
340
+ }
341
+ async delete(transport, location, _context) {
342
+ if (!transport.delete) {
343
+ throw new SemanticError(`Transport "${transport.name}" does not support delete operation`, this.name);
344
+ }
345
+ await transport.delete(location);
346
+ }
347
+ }
348
+ var binarySemantic = new BinarySemanticHandler;
349
+ // src/ARP.ts
350
+ class ARP {
351
+ transports;
352
+ semantics;
353
+ constructor(config = {}) {
354
+ this.transports = new Map;
355
+ this.semantics = new Map;
356
+ const defaultTransports = [fileTransport, httpTransport, httpsTransport];
357
+ const defaultSemantics = [textSemantic, binarySemantic];
358
+ for (const handler of defaultTransports) {
359
+ this.transports.set(handler.name, handler);
360
+ }
361
+ for (const handler of defaultSemantics) {
362
+ this.semantics.set(handler.name, handler);
363
+ }
364
+ if (config.transports) {
365
+ for (const handler of config.transports) {
366
+ this.transports.set(handler.name, handler);
367
+ }
368
+ }
369
+ if (config.semantics) {
370
+ for (const handler of config.semantics) {
371
+ this.semantics.set(handler.name, handler);
372
+ }
373
+ }
374
+ }
375
+ registerTransport(handler) {
376
+ this.transports.set(handler.name, handler);
377
+ }
378
+ registerSemantic(handler) {
379
+ this.semantics.set(handler.name, handler);
380
+ }
381
+ getTransportHandler(name) {
382
+ const handler = this.transports.get(name);
383
+ if (!handler) {
384
+ throw new TransportError(`Unsupported transport type: ${name}`, name);
385
+ }
386
+ return handler;
387
+ }
388
+ getSemanticHandler(name) {
389
+ const handler = this.semantics.get(name);
390
+ if (!handler) {
391
+ throw new SemanticError(`Unsupported semantic type: ${name}`, name);
392
+ }
393
+ return handler;
394
+ }
395
+ parse(url) {
396
+ if (!url.startsWith("arp:")) {
397
+ throw new ParseError(`Invalid ARP URL: must start with "arp:"`, url);
398
+ }
399
+ const content = url.substring(4);
400
+ const separatorIndex = content.indexOf("://");
401
+ if (separatorIndex === -1) {
402
+ throw new ParseError(`Invalid ARP URL: missing "://"`, url);
403
+ }
404
+ const typePart = content.substring(0, separatorIndex);
405
+ const location = content.substring(separatorIndex + 3);
406
+ const colonIndex = typePart.indexOf(":");
407
+ if (colonIndex === -1) {
408
+ throw new ParseError(`Invalid ARP URL: must have exactly 2 types (semantic:transport)`, url);
409
+ }
410
+ const semantic = typePart.substring(0, colonIndex);
411
+ const transport = typePart.substring(colonIndex + 1);
412
+ if (!semantic) {
413
+ throw new ParseError(`Invalid ARP URL: semantic type cannot be empty`, url);
414
+ }
415
+ if (!transport) {
416
+ throw new ParseError(`Invalid ARP URL: transport type cannot be empty`, url);
417
+ }
418
+ if (!location) {
419
+ throw new ParseError(`Invalid ARP URL: location cannot be empty`, url);
420
+ }
421
+ this.getTransportHandler(transport);
422
+ this.getSemanticHandler(semantic);
423
+ return new ARL(semantic, transport, location, this);
424
+ }
425
+ }
426
+ function createARP(config) {
427
+ return new ARP(config);
428
+ }
429
+
430
+ // src/index.ts
431
+ var VERSION = "0.1.0";
432
+ export {
433
+ textSemantic,
434
+ httpsTransport,
435
+ httpTransport,
436
+ fileTransport,
437
+ createARP,
438
+ binarySemantic,
439
+ VERSION,
440
+ TransportError,
441
+ TextSemanticHandler,
442
+ SemanticError,
443
+ ParseError,
444
+ HttpTransportHandler,
445
+ FileTransportHandler,
446
+ BinarySemanticHandler,
447
+ ARPError,
448
+ ARP
449
+ };
450
+
451
+ //# debugId=C42DE403B8D4732364756E2164756E21
@@ -0,0 +1,17 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/errors.ts", "../src/ARL.ts", "../src/transport/file.ts", "../src/transport/http.ts", "../src/semantic/text.ts", "../src/semantic/binary.ts", "../src/ARP.ts", "../src/index.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * ARP Error Types\n */\n\n/**\n * Base error class for all ARP errors\n */\nexport class ARPError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = \"ARPError\";\n }\n}\n\n/**\n * Error thrown when ARP URL parsing fails\n */\nexport class ParseError extends ARPError {\n constructor(\n message: string,\n public readonly url?: string\n ) {\n super(message);\n this.name = \"ParseError\";\n }\n}\n\n/**\n * Error thrown when transport layer fails\n */\nexport class TransportError extends ARPError {\n constructor(\n message: string,\n public readonly transport?: string,\n options?: ErrorOptions\n ) {\n super(message, options);\n this.name = \"TransportError\";\n }\n}\n\n/**\n * Error thrown when semantic layer fails\n */\nexport class SemanticError extends ARPError {\n constructor(\n message: string,\n public readonly semantic?: string,\n options?: ErrorOptions\n ) {\n super(message, options);\n this.name = \"SemanticError\";\n }\n}\n",
6
+ "/**\n * ARL - Agent Resource Locator Implementation\n */\n\nimport type { ARL as IARL } from \"./types.js\";\nimport type { Resource, SemanticContext, SemanticHandler } from \"./semantic/types.js\";\nimport type { TransportHandler } from \"./transport/types.js\";\nimport { SemanticError } from \"./errors.js\";\n\n/**\n * Handler resolver interface (implemented by ARP instance)\n */\nexport interface HandlerResolver {\n getTransportHandler(name: string): TransportHandler;\n getSemanticHandler(name: string): SemanticHandler;\n}\n\n/**\n * ARL Implementation\n */\nexport class ARL implements IARL {\n readonly semantic: string;\n readonly transport: string;\n readonly location: string;\n\n private readonly resolver: HandlerResolver;\n\n constructor(semantic: string, transport: string, location: string, resolver: HandlerResolver) {\n this.semantic = semantic;\n this.transport = transport;\n this.location = location;\n this.resolver = resolver;\n }\n\n /**\n * Create semantic context\n */\n private createContext(): SemanticContext {\n return {\n url: this.toString(),\n semantic: this.semantic,\n transport: this.transport,\n location: this.location,\n timestamp: new Date(),\n };\n }\n\n /**\n * Resolve the resource\n */\n async resolve(): Promise<Resource> {\n const transport = this.resolver.getTransportHandler(this.transport);\n const semantic = this.resolver.getSemanticHandler(this.semantic);\n const context = this.createContext();\n\n return semantic.resolve(transport, this.location, context);\n }\n\n /**\n * Deposit data to the resource\n */\n async deposit(data: unknown): Promise<void> {\n const transport = this.resolver.getTransportHandler(this.transport);\n const semantic = this.resolver.getSemanticHandler(this.semantic);\n const context = this.createContext();\n\n if (!semantic.deposit) {\n throw new SemanticError(\n `Semantic \"${semantic.name}\" does not support deposit operation`,\n this.semantic\n );\n }\n\n await semantic.deposit(transport, this.location, data, context);\n }\n\n /**\n * Check if resource exists\n */\n async exists(): Promise<boolean> {\n const transport = this.resolver.getTransportHandler(this.transport);\n const semantic = this.resolver.getSemanticHandler(this.semantic);\n const context = this.createContext();\n\n if (semantic.exists) {\n return semantic.exists(transport, this.location, context);\n }\n\n // Fallback to transport exists\n if (transport.exists) {\n return transport.exists(this.location);\n }\n\n // Fallback: try to read\n try {\n await transport.read(this.location);\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Delete the resource\n */\n async delete(): Promise<void> {\n const transport = this.resolver.getTransportHandler(this.transport);\n const semantic = this.resolver.getSemanticHandler(this.semantic);\n const context = this.createContext();\n\n if (semantic.delete) {\n return semantic.delete(transport, this.location, context);\n }\n\n // Fallback to transport delete\n if (!transport.delete) {\n throw new SemanticError(\n `Neither semantic \"${semantic.name}\" nor transport \"${transport.name}\" supports delete operation`,\n this.semantic\n );\n }\n\n await transport.delete(this.location);\n }\n\n /**\n * Convert to ARP URL string\n */\n toString(): string {\n return `arp:${this.semantic}:${this.transport}://${this.location}`;\n }\n}\n",
7
+ "/**\n * File Transport Handler\n * Provides I/O primitives for local filesystem\n */\n\nimport { readFile, writeFile, readdir, mkdir, rm, access, stat as fsStat } from \"node:fs/promises\";\nimport { resolve, dirname } from \"node:path\";\nimport { TransportError } from \"../errors.js\";\nimport type { TransportHandler, TransportCapabilities, ResourceStat } from \"./types.js\";\n\nexport class FileTransportHandler implements TransportHandler {\n readonly name = \"file\";\n\n readonly capabilities: TransportCapabilities = {\n canRead: true,\n canWrite: true,\n canList: true,\n canDelete: true,\n canStat: true,\n };\n\n private resolvePath(location: string): string {\n return resolve(process.cwd(), location);\n }\n\n async read(location: string): Promise<Buffer> {\n const filePath = this.resolvePath(location);\n\n try {\n return await readFile(filePath);\n } catch (error) {\n const err = error as Error & { code?: string };\n throw new TransportError(`File read error: ${err.code} - ${filePath}`, this.name, {\n cause: err,\n });\n }\n }\n\n async write(location: string, content: Buffer): Promise<void> {\n const filePath = this.resolvePath(location);\n\n try {\n // Ensure directory exists\n await mkdir(dirname(filePath), { recursive: true });\n await writeFile(filePath, content);\n } catch (error) {\n const err = error as Error & { code?: string };\n throw new TransportError(`File write error: ${err.code} - ${filePath}`, this.name, {\n cause: err,\n });\n }\n }\n\n async list(location: string): Promise<string[]> {\n const dirPath = this.resolvePath(location);\n\n try {\n return await readdir(dirPath);\n } catch (error) {\n const err = error as Error & { code?: string };\n throw new TransportError(`Directory list error: ${err.code} - ${dirPath}`, this.name, {\n cause: err,\n });\n }\n }\n\n async mkdir(location: string): Promise<void> {\n const dirPath = this.resolvePath(location);\n\n try {\n await mkdir(dirPath, { recursive: true });\n } catch (error) {\n const err = error as Error & { code?: string };\n throw new TransportError(`Directory create error: ${err.code} - ${dirPath}`, this.name, {\n cause: err,\n });\n }\n }\n\n async exists(location: string): Promise<boolean> {\n const filePath = this.resolvePath(location);\n\n try {\n await access(filePath);\n return true;\n } catch {\n return false;\n }\n }\n\n async stat(location: string): Promise<ResourceStat> {\n const filePath = this.resolvePath(location);\n\n try {\n const stats = await fsStat(filePath);\n return {\n size: stats.size,\n modifiedAt: stats.mtime,\n isDirectory: stats.isDirectory(),\n };\n } catch (error) {\n const err = error as Error & { code?: string };\n throw new TransportError(`File stat error: ${err.code} - ${filePath}`, this.name, {\n cause: err,\n });\n }\n }\n\n async delete(location: string): Promise<void> {\n const filePath = this.resolvePath(location);\n\n try {\n await rm(filePath, { recursive: true });\n } catch (error) {\n const err = error as Error & { code?: string };\n throw new TransportError(`File delete error: ${err.code} - ${filePath}`, this.name, {\n cause: err,\n });\n }\n }\n}\n\nexport const fileTransport: FileTransportHandler = new FileTransportHandler();\n",
8
+ "/**\n * HTTP/HTTPS Transport Handler\n * Provides read-only I/O primitives for HTTP resources\n */\n\nimport { TransportError } from \"../errors.js\";\nimport type { TransportHandler, TransportCapabilities } from \"./types.js\";\n\nexport class HttpTransportHandler implements TransportHandler {\n readonly name: string;\n private readonly protocol: \"http\" | \"https\";\n\n readonly capabilities: TransportCapabilities = {\n canRead: true,\n canWrite: false,\n canList: false,\n canDelete: false,\n canStat: false,\n };\n\n constructor(protocol: \"http\" | \"https\" = \"https\") {\n this.protocol = protocol;\n this.name = protocol;\n }\n\n async read(location: string): Promise<Buffer> {\n const url = `${this.protocol}://${location}`;\n\n try {\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new TransportError(\n `HTTP ${response.status}: ${response.statusText} - ${url}`,\n this.name\n );\n }\n\n const arrayBuffer = await response.arrayBuffer();\n return Buffer.from(arrayBuffer);\n } catch (error) {\n if (error instanceof TransportError) {\n throw error;\n }\n throw new TransportError(`Network error: ${url}`, this.name, {\n cause: error as Error,\n });\n }\n }\n\n // HTTP transport is read-only, write/list/delete are not implemented\n}\n\nexport const httpsTransport: HttpTransportHandler = new HttpTransportHandler(\"https\");\nexport const httpTransport: HttpTransportHandler = new HttpTransportHandler(\"http\");\n",
9
+ "/**\n * Text Semantic Handler\n * Handles plain text resources\n */\n\nimport { SemanticError } from \"../errors.js\";\nimport type { TransportHandler } from \"../transport/types.js\";\nimport type { Resource, SemanticHandler, SemanticContext, ResourceMeta } from \"./types.js\";\n\nexport interface TextResource extends Resource<string> {\n type: \"text\";\n content: string;\n}\n\nexport class TextSemanticHandler implements SemanticHandler<string> {\n readonly name = \"text\";\n\n async resolve(\n transport: TransportHandler,\n location: string,\n context: SemanticContext\n ): Promise<TextResource> {\n const buffer = await transport.read(location);\n const text = buffer.toString(\"utf-8\");\n\n const meta: ResourceMeta = {\n url: context.url,\n semantic: context.semantic,\n transport: context.transport,\n location: context.location,\n size: buffer.length,\n encoding: \"utf-8\",\n mimeType: \"text/plain\",\n resolvedAt: context.timestamp.toISOString(),\n };\n\n return {\n type: \"text\",\n content: text,\n meta,\n };\n }\n\n async deposit(\n transport: TransportHandler,\n location: string,\n data: string,\n _context: SemanticContext\n ): Promise<void> {\n if (!transport.write) {\n throw new SemanticError(\n `Transport \"${transport.name}\" does not support write operation`,\n this.name\n );\n }\n\n const buffer = Buffer.from(data, \"utf-8\");\n await transport.write(location, buffer);\n }\n\n async exists(\n transport: TransportHandler,\n location: string,\n _context: SemanticContext\n ): Promise<boolean> {\n if (transport.exists) {\n return transport.exists(location);\n }\n\n // Fallback: try to read\n try {\n await transport.read(location);\n return true;\n } catch {\n return false;\n }\n }\n\n async delete(\n transport: TransportHandler,\n location: string,\n _context: SemanticContext\n ): Promise<void> {\n if (!transport.delete) {\n throw new SemanticError(\n `Transport \"${transport.name}\" does not support delete operation`,\n this.name\n );\n }\n\n await transport.delete(location);\n }\n}\n\nexport const textSemantic: TextSemanticHandler = new TextSemanticHandler();\n",
10
+ "/**\n * Binary Semantic Handler\n * Handles raw binary resources without any transformation\n */\n\nimport { SemanticError } from \"../errors.js\";\nimport type { TransportHandler } from \"../transport/types.js\";\nimport type { Resource, SemanticHandler, SemanticContext, ResourceMeta } from \"./types.js\";\n\nexport interface BinaryResource extends Resource<Buffer> {\n type: \"binary\";\n content: Buffer;\n}\n\n/**\n * Supported binary input types for deposit\n */\nexport type BinaryInput = Buffer | Uint8Array | ArrayBuffer | number[];\n\n/**\n * Convert various binary input types to Buffer\n */\nfunction toBuffer(data: BinaryInput): Buffer {\n if (Buffer.isBuffer(data)) {\n return data;\n }\n if (data instanceof Uint8Array) {\n return Buffer.from(data);\n }\n if (data instanceof ArrayBuffer) {\n return Buffer.from(data);\n }\n if (Array.isArray(data)) {\n return Buffer.from(data);\n }\n throw new SemanticError(`Unsupported binary input type`, \"binary\");\n}\n\nexport class BinarySemanticHandler implements SemanticHandler<Buffer> {\n readonly name = \"binary\";\n\n async resolve(\n transport: TransportHandler,\n location: string,\n context: SemanticContext\n ): Promise<BinaryResource> {\n const buffer = await transport.read(location);\n\n const meta: ResourceMeta = {\n url: context.url,\n semantic: context.semantic,\n transport: context.transport,\n location: context.location,\n size: buffer.length,\n resolvedAt: context.timestamp.toISOString(),\n };\n\n return {\n type: \"binary\",\n content: buffer,\n meta,\n };\n }\n\n async deposit(\n transport: TransportHandler,\n location: string,\n data: BinaryInput,\n _context: SemanticContext\n ): Promise<void> {\n if (!transport.write) {\n throw new SemanticError(\n `Transport \"${transport.name}\" does not support write operation`,\n this.name\n );\n }\n\n const buffer = toBuffer(data);\n await transport.write(location, buffer);\n }\n\n async exists(\n transport: TransportHandler,\n location: string,\n _context: SemanticContext\n ): Promise<boolean> {\n if (transport.exists) {\n return transport.exists(location);\n }\n\n // Fallback: try to read\n try {\n await transport.read(location);\n return true;\n } catch {\n return false;\n }\n }\n\n async delete(\n transport: TransportHandler,\n location: string,\n _context: SemanticContext\n ): Promise<void> {\n if (!transport.delete) {\n throw new SemanticError(\n `Transport \"${transport.name}\" does not support delete operation`,\n this.name\n );\n }\n\n await transport.delete(location);\n }\n}\n\nexport const binarySemantic: BinarySemanticHandler = new BinarySemanticHandler();\n",
11
+ "/**\n * ARP - Agent Resource Protocol\n * Factory and instance for parsing ARP URLs\n */\n\nimport { ARL, type HandlerResolver } from \"./ARL.js\";\nimport { ParseError, TransportError, SemanticError } from \"./errors.js\";\nimport type { TransportHandler } from \"./transport/types.js\";\nimport type { SemanticHandler } from \"./semantic/types.js\";\nimport { fileTransport, httpTransport, httpsTransport } from \"./transport/index.js\";\nimport { textSemantic, binarySemantic } from \"./semantic/index.js\";\n\n/**\n * ARP Configuration\n */\nexport interface ARPConfig {\n /**\n * Custom transport handlers\n */\n transports?: TransportHandler[];\n\n /**\n * Custom semantic handlers\n */\n semantics?: SemanticHandler[];\n}\n\n/**\n * ARP Instance\n */\nexport class ARP implements HandlerResolver {\n private readonly transports: Map<string, TransportHandler>;\n private readonly semantics: Map<string, SemanticHandler>;\n\n constructor(config: ARPConfig = {}) {\n this.transports = new Map();\n this.semantics = new Map();\n\n // Register default handlers\n const defaultTransports = [fileTransport, httpTransport, httpsTransport];\n const defaultSemantics = [textSemantic, binarySemantic];\n\n for (const handler of defaultTransports) {\n this.transports.set(handler.name, handler);\n }\n for (const handler of defaultSemantics) {\n this.semantics.set(handler.name, handler);\n }\n\n // Register custom handlers (override defaults if same name)\n if (config.transports) {\n for (const handler of config.transports) {\n this.transports.set(handler.name, handler);\n }\n }\n\n if (config.semantics) {\n for (const handler of config.semantics) {\n this.semantics.set(handler.name, handler);\n }\n }\n }\n\n /**\n * Register a transport handler\n */\n registerTransport(handler: TransportHandler): void {\n this.transports.set(handler.name, handler);\n }\n\n /**\n * Register a semantic handler\n */\n registerSemantic(handler: SemanticHandler): void {\n this.semantics.set(handler.name, handler);\n }\n\n /**\n * Get transport handler by name\n */\n getTransportHandler(name: string): TransportHandler {\n const handler = this.transports.get(name);\n if (!handler) {\n throw new TransportError(`Unsupported transport type: ${name}`, name);\n }\n return handler;\n }\n\n /**\n * Get semantic handler by name\n */\n getSemanticHandler(name: string): SemanticHandler {\n const handler = this.semantics.get(name);\n if (!handler) {\n throw new SemanticError(`Unsupported semantic type: ${name}`, name);\n }\n return handler;\n }\n\n /**\n * Parse an ARP URL into an ARL object\n *\n * @example\n * const arl = arp.parse(\"arp:text:file:///path/to/file.txt\");\n * arl.semantic // \"text\"\n * arl.transport // \"file\"\n * arl.location // \"/path/to/file.txt\"\n */\n parse(url: string): ARL {\n // 1. Check protocol prefix\n if (!url.startsWith(\"arp:\")) {\n throw new ParseError(`Invalid ARP URL: must start with \"arp:\"`, url);\n }\n\n const content = url.substring(4); // Remove \"arp:\"\n\n // 2. Find :// separator\n const separatorIndex = content.indexOf(\"://\");\n if (separatorIndex === -1) {\n throw new ParseError(`Invalid ARP URL: missing \"://\"`, url);\n }\n\n const typePart = content.substring(0, separatorIndex);\n const location = content.substring(separatorIndex + 3);\n\n // 3. Split type part by :\n const colonIndex = typePart.indexOf(\":\");\n if (colonIndex === -1) {\n throw new ParseError(`Invalid ARP URL: must have exactly 2 types (semantic:transport)`, url);\n }\n\n const semantic = typePart.substring(0, colonIndex);\n const transport = typePart.substring(colonIndex + 1);\n\n // 4. Validate non-empty\n if (!semantic) {\n throw new ParseError(`Invalid ARP URL: semantic type cannot be empty`, url);\n }\n if (!transport) {\n throw new ParseError(`Invalid ARP URL: transport type cannot be empty`, url);\n }\n if (!location) {\n throw new ParseError(`Invalid ARP URL: location cannot be empty`, url);\n }\n\n // 5. Validate handlers exist\n this.getTransportHandler(transport);\n this.getSemanticHandler(semantic);\n\n return new ARL(semantic, transport, location, this);\n }\n}\n\n/**\n * Create a new ARP instance\n *\n * @example\n * import { createARP, fileTransport, textSemantic } from \"arpjs\";\n *\n * const arp = createARP({\n * transports: [fileTransport],\n * semantics: [textSemantic],\n * });\n *\n * const arl = arp.parse(\"arp:text:file:///path/to/file.txt\");\n * const resource = await arl.resolve();\n */\nexport function createARP(config?: ARPConfig): ARP {\n return new ARP(config);\n}\n",
12
+ "/**\n * arpjs - Agent Resource Protocol\n *\n * A URL protocol for AI agents to access resources\n * Format: arp:{semantic}:{transport}://{location}\n */\n\ndeclare const __VERSION__: string | undefined;\nexport const VERSION: string = typeof __VERSION__ !== \"undefined\" ? __VERSION__ : \"0.0.0-dev\";\n\n// Core types\nexport type { ARI, ARL } from \"./types.js\";\n\n// ARP factory and class\nexport { ARP, createARP, type ARPConfig } from \"./ARP.js\";\n\n// Errors\nexport { ARPError, ParseError, TransportError, SemanticError } from \"./errors.js\";\n\n// Transport\nexport {\n type TransportHandler,\n type TransportCapabilities,\n type ResourceStat,\n FileTransportHandler,\n fileTransport,\n HttpTransportHandler,\n httpsTransport,\n httpTransport,\n} from \"./transport/index.js\";\n\n// Semantic\nexport {\n type Resource,\n type SemanticHandler,\n type ResourceMeta,\n type SemanticContext,\n type TextResource,\n type BinaryResource,\n type BinaryInput,\n TextSemanticHandler,\n textSemantic,\n BinarySemanticHandler,\n binarySemantic,\n} from \"./semantic/index.js\";\n"
13
+ ],
14
+ "mappings": ";AAOO,MAAM,iBAAiB,MAAM;AAAA,EAClC,WAAW,CAAC,SAAiB,SAAwB;AAAA,IACnD,MAAM,SAAS,OAAO;AAAA,IACtB,KAAK,OAAO;AAAA;AAEhB;AAAA;AAKO,MAAM,mBAAmB,SAAS;AAAA,EAGrB;AAAA,EAFlB,WAAW,CACT,SACgB,KAChB;AAAA,IACA,MAAM,OAAO;AAAA,IAFG;AAAA,IAGhB,KAAK,OAAO;AAAA;AAEhB;AAAA;AAKO,MAAM,uBAAuB,SAAS;AAAA,EAGzB;AAAA,EAFlB,WAAW,CACT,SACgB,WAChB,SACA;AAAA,IACA,MAAM,SAAS,OAAO;AAAA,IAHN;AAAA,IAI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AI;AAAA,MACzB,MAAM,IAAI,WAAW,kCAAkC,GAAG;AAAA,IAC5D;AAAA,IAEA,MAAM,WAAW,QAAQ,UAAU,GAAG,cAAc;AAAA,IACpD,MAAM,WAAW,QAAQ,UAAU,iBAAiB,CAAC;AAAA,IAGrD,MAAM,aAAa,SAAS,QAAQ,GAAG;AAAA,IACvC,IAAI,eAAe,IAAI;AAAA,MACrB,MAAM,IAAI,WAAW,mEAAmE,GAAG;AAAA,IAC7F;AAAA,IAEA,MAAM,WAAW,SAAS,UAAU,GAAG,UAAU;AAAA,IACjD,MAAM,YAAY,SAAS,UAAU,aAAa,CAAC;AAAA,IAGnD,IAAI,CAAC,UAAU;AAAA,MACb,MAAM,IAAI,WAAW,kDAAkD,GAAG;AAAA,IAC5E;AAAA,IACA,IAAI,CAAC,WAAW;AAAA,MACd,MAAM,IAAI,WAAW,mDAAmD,GAAG;AAAA,IAC7E;AAAA,IACA,IAAI,CAAC,UAAU;AAAA,MACb,MAAM,IAAI,WAAW,6CAA6C,GAAG;AAAA,IACvE;AAAA,IAGA,KAAK,oBAAoB,SAAS;AAAA,IAClC,KAAK,mBAAmB,QAAQ;AAAA,IAEhC,OAAO,IAAI,IAAI,UAAU,WAAW,UAAU,IAAI;AAAA;AAEtD;AAgBO,SAAS,SAAS,CAAC,QAAyB;AAAA,EACjD,OAAO,IAAI,IAAI,MAAM;AAAA;;;AChKhB,IAAM,UAAuD;",
15
+ "debugId": "C42DE403B8D4732364756E2164756E21",
16
+ "names": []
17
+ }
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@resourcexjs/arp",
3
+ "version": "0.1.0",
4
+ "description": "ARP (Agent Resource Protocol) - A URL protocol for AI agents to access resources",
5
+ "keywords": [
6
+ "arp",
7
+ "agent",
8
+ "resource",
9
+ "protocol",
10
+ "ai"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/Deepractice/ResourceX.git",
15
+ "directory": "packages/arp"
16
+ },
17
+ "license": "MIT",
18
+ "engines": {
19
+ "node": ">=22.0.0"
20
+ },
21
+ "type": "module",
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md"
33
+ ],
34
+ "scripts": {
35
+ "build": "bun run build.ts",
36
+ "lint": "eslint .",
37
+ "typecheck": "tsc --noEmit",
38
+ "test": "bun test",
39
+ "clean": "rm -rf dist"
40
+ },
41
+ "devDependencies": {},
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }