resourcexjs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +223 -0
- package/dist/index.js.map +12 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# resourcexjs
|
|
2
|
+
|
|
3
|
+
Agent Resource Protocol (ARP) for AI Agents.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install resourcexjs
|
|
9
|
+
# or
|
|
10
|
+
bun add resourcexjs
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createResourceX } from "resourcexjs";
|
|
17
|
+
|
|
18
|
+
const rx = createResourceX();
|
|
19
|
+
|
|
20
|
+
// Resolve a remote text resource
|
|
21
|
+
const resource = await rx.resolve("arp:text:https://example.com/file.txt");
|
|
22
|
+
|
|
23
|
+
console.log(resource.type); // "text"
|
|
24
|
+
console.log(resource.content); // file content as string
|
|
25
|
+
console.log(resource.meta); // { url, semantic, transport, ... }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## ARP URL Format
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
arp:{semantic}:{transport}://{location}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
- **semantic**: What the resource is (e.g., `text`)
|
|
35
|
+
- **transport**: How to fetch it (e.g., `https`, `http`, `file`)
|
|
36
|
+
- **location**: Where to find it
|
|
37
|
+
|
|
38
|
+
Examples:
|
|
39
|
+
|
|
40
|
+
- `arp:text:https://example.com/readme.txt`
|
|
41
|
+
- `arp:text:http://localhost:3000/data.txt`
|
|
42
|
+
- `arp:text:file:///path/to/local/file.txt`
|
|
43
|
+
|
|
44
|
+
## API
|
|
45
|
+
|
|
46
|
+
### `createResourceX(config?)`
|
|
47
|
+
|
|
48
|
+
Create a ResourceX instance.
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const rx = createResourceX({
|
|
52
|
+
timeout: 5000, // request timeout in ms
|
|
53
|
+
transports: [], // custom transport handlers
|
|
54
|
+
semantics: [], // custom semantic handlers
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### `rx.resolve(url)`
|
|
59
|
+
|
|
60
|
+
Resolve an ARP URL and return the resource.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
const resource = await rx.resolve("arp:text:https://example.com/file.txt");
|
|
64
|
+
// Returns: { type, content, meta }
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### `rx.parse(url)`
|
|
68
|
+
|
|
69
|
+
Parse an ARP URL without fetching.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const parsed = rx.parse("arp:text:https://example.com/file.txt");
|
|
73
|
+
// Returns: { semantic: "text", transport: "https", location: "example.com/file.txt" }
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### `rx.registerTransport(handler)`
|
|
77
|
+
|
|
78
|
+
Register a custom transport handler.
|
|
79
|
+
|
|
80
|
+
### `rx.registerSemantic(handler)`
|
|
81
|
+
|
|
82
|
+
Register a custom semantic handler.
|
|
83
|
+
|
|
84
|
+
## Resource Object
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
interface Resource {
|
|
88
|
+
type: string; // semantic type (e.g., "text")
|
|
89
|
+
content: unknown; // parsed content
|
|
90
|
+
meta: {
|
|
91
|
+
url: string; // original ARP URL
|
|
92
|
+
semantic: string; // semantic type
|
|
93
|
+
transport: string; // transport protocol
|
|
94
|
+
location: string; // resource location
|
|
95
|
+
size: number; // content size in bytes
|
|
96
|
+
encoding?: string; // content encoding
|
|
97
|
+
mimeType?: string; // MIME type
|
|
98
|
+
fetchedAt: string; // ISO timestamp
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Error Handling
|
|
104
|
+
|
|
105
|
+
All errors extend `ResourceXError`:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { createResourceX, ResourceXError } from "resourcexjs";
|
|
109
|
+
|
|
110
|
+
const rx = createResourceX();
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
await rx.resolve("arp:text:https://example.com/file.txt");
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (error instanceof ResourceXError) {
|
|
116
|
+
console.error("ResourceX error:", error.message);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
For fine-grained error handling, import specific error types from `@resourcexjs/core`:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { ParseError, TransportError, SemanticError } from "@resourcexjs/core";
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ParsedARP, Resource, TransportHandler, SemanticHandler } from "@resourcexjs/core";
|
|
2
|
+
/**
|
|
3
|
+
* ResourceX configuration
|
|
4
|
+
*/
|
|
5
|
+
interface ResourceXConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Request timeout in milliseconds
|
|
8
|
+
*/
|
|
9
|
+
timeout?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Custom transport handlers to register
|
|
12
|
+
*/
|
|
13
|
+
transports?: TransportHandler[];
|
|
14
|
+
/**
|
|
15
|
+
* Custom semantic handlers to register
|
|
16
|
+
*/
|
|
17
|
+
semantics?: SemanticHandler[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* ResourceX instance
|
|
21
|
+
*/
|
|
22
|
+
declare class ResourceX {
|
|
23
|
+
readonly timeout?: number;
|
|
24
|
+
constructor(config?: ResourceXConfig);
|
|
25
|
+
/**
|
|
26
|
+
* Parse an ARP URL without fetching
|
|
27
|
+
*/
|
|
28
|
+
parse(url: string): ParsedARP;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve an ARP URL to a resource
|
|
31
|
+
*/
|
|
32
|
+
resolve(url: string): Promise<Resource>;
|
|
33
|
+
/**
|
|
34
|
+
* Register a custom transport handler
|
|
35
|
+
*/
|
|
36
|
+
registerTransport(handler: TransportHandler): void;
|
|
37
|
+
/**
|
|
38
|
+
* Register a custom semantic handler
|
|
39
|
+
*/
|
|
40
|
+
registerSemantic(handler: SemanticHandler): void;
|
|
41
|
+
/**
|
|
42
|
+
* Get a transport handler by type
|
|
43
|
+
*/
|
|
44
|
+
getTransport(type: string): TransportHandler;
|
|
45
|
+
/**
|
|
46
|
+
* Get a semantic handler by type
|
|
47
|
+
*/
|
|
48
|
+
getSemantic(type: string): SemanticHandler;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a new ResourceX instance
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { createResourceX } from "resourcexjs";
|
|
56
|
+
*
|
|
57
|
+
* const rx = createResourceX();
|
|
58
|
+
* const resource = await rx.resolve("arp:text:https://example.com/file.txt");
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // With custom config
|
|
64
|
+
* const rx = createResourceX({
|
|
65
|
+
* timeout: 5000,
|
|
66
|
+
* transports: [myCustomTransport],
|
|
67
|
+
* semantics: [myCustomSemantic],
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function createResourceX(config?: ResourceXConfig): ResourceX;
|
|
72
|
+
import { Resource as Resource2, ResourceMeta, ParsedARP as ParsedARP2, ParseContext, TransportHandler as TransportHandler2, SemanticHandler as SemanticHandler2, TextResource } from "@resourcexjs/core";
|
|
73
|
+
import { ResourceXError, ParseError, TransportError, SemanticError } from "@resourcexjs/core";
|
|
74
|
+
export { createResourceX, TransportHandler2 as TransportHandler, TransportError, TextResource, SemanticHandler2 as SemanticHandler, SemanticError, ResourceXError, ResourceXConfig, ResourceX, ResourceMeta, Resource2 as Resource, ParsedARP2 as ParsedARP, ParseError, ParseContext };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// ../core/dist/index.js
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
class ResourceXError extends Error {
|
|
6
|
+
constructor(message, options) {
|
|
7
|
+
super(message, options);
|
|
8
|
+
this.name = "ResourceXError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class ParseError extends ResourceXError {
|
|
13
|
+
url;
|
|
14
|
+
constructor(message, url) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.url = url;
|
|
17
|
+
this.name = "ParseError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class TransportError extends ResourceXError {
|
|
22
|
+
transport;
|
|
23
|
+
constructor(message, transport, options) {
|
|
24
|
+
super(message, options);
|
|
25
|
+
this.transport = transport;
|
|
26
|
+
this.name = "TransportError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
class SemanticError extends ResourceXError {
|
|
31
|
+
semantic;
|
|
32
|
+
constructor(message, semantic, options) {
|
|
33
|
+
super(message, options);
|
|
34
|
+
this.semantic = semantic;
|
|
35
|
+
this.name = "SemanticError";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function parseARP(url) {
|
|
39
|
+
if (!url.startsWith("arp:")) {
|
|
40
|
+
throw new ParseError(`Invalid ARP URL: must start with "arp:"`, url);
|
|
41
|
+
}
|
|
42
|
+
const content = url.substring(4);
|
|
43
|
+
const separatorIndex = content.indexOf("://");
|
|
44
|
+
if (separatorIndex === -1) {
|
|
45
|
+
throw new ParseError(`Invalid ARP URL: missing "://"`, url);
|
|
46
|
+
}
|
|
47
|
+
const typePart = content.substring(0, separatorIndex);
|
|
48
|
+
const location = content.substring(separatorIndex + 3);
|
|
49
|
+
const colonIndex = typePart.indexOf(":");
|
|
50
|
+
if (colonIndex === -1) {
|
|
51
|
+
throw new ParseError(`Invalid ARP URL: must have exactly 2 types (semantic:transport)`, url);
|
|
52
|
+
}
|
|
53
|
+
const semantic = typePart.substring(0, colonIndex);
|
|
54
|
+
const transport = typePart.substring(colonIndex + 1);
|
|
55
|
+
if (!semantic) {
|
|
56
|
+
throw new ParseError(`Invalid ARP URL: semantic type cannot be empty`, url);
|
|
57
|
+
}
|
|
58
|
+
if (!transport) {
|
|
59
|
+
throw new ParseError(`Invalid ARP URL: transport type cannot be empty`, url);
|
|
60
|
+
}
|
|
61
|
+
if (!location) {
|
|
62
|
+
throw new ParseError(`Invalid ARP URL: location cannot be empty`, url);
|
|
63
|
+
}
|
|
64
|
+
return { semantic, transport, location };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
class HttpTransportHandler {
|
|
68
|
+
type;
|
|
69
|
+
protocol;
|
|
70
|
+
constructor(protocol = "https") {
|
|
71
|
+
this.protocol = protocol;
|
|
72
|
+
this.type = protocol;
|
|
73
|
+
}
|
|
74
|
+
async fetch(location) {
|
|
75
|
+
const url = `${this.protocol}://${location}`;
|
|
76
|
+
try {
|
|
77
|
+
const response = await fetch(url);
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
throw new TransportError(`HTTP ${response.status}: ${response.statusText} - ${url}`, this.type);
|
|
80
|
+
}
|
|
81
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
82
|
+
return Buffer.from(arrayBuffer);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof TransportError) {
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
throw new TransportError(`Network error: ${url}`, this.type, { cause: error });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
var httpsHandler = new HttpTransportHandler("https");
|
|
92
|
+
var httpHandler = new HttpTransportHandler("http");
|
|
93
|
+
|
|
94
|
+
class FileTransportHandler {
|
|
95
|
+
type = "file";
|
|
96
|
+
async fetch(location) {
|
|
97
|
+
const filePath = resolve(process.cwd(), location);
|
|
98
|
+
try {
|
|
99
|
+
return await readFile(filePath);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
const err = error;
|
|
102
|
+
throw new TransportError(`File read error: ${err.code} - ${filePath}`, this.type, {
|
|
103
|
+
cause: err
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
var fileHandler = new FileTransportHandler;
|
|
109
|
+
var handlers = new Map([
|
|
110
|
+
["https", httpsHandler],
|
|
111
|
+
["http", httpHandler],
|
|
112
|
+
["file", fileHandler]
|
|
113
|
+
]);
|
|
114
|
+
function getTransportHandler(type) {
|
|
115
|
+
const handler = handlers.get(type);
|
|
116
|
+
if (!handler) {
|
|
117
|
+
throw new TransportError(`Unsupported transport type: ${type}`, type);
|
|
118
|
+
}
|
|
119
|
+
return handler;
|
|
120
|
+
}
|
|
121
|
+
function registerTransportHandler(handler) {
|
|
122
|
+
handlers.set(handler.type, handler);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
class TextSemanticHandler {
|
|
126
|
+
type = "text";
|
|
127
|
+
parse(content, context) {
|
|
128
|
+
const text = content.toString("utf-8");
|
|
129
|
+
const meta = {
|
|
130
|
+
url: context.url,
|
|
131
|
+
semantic: context.semantic,
|
|
132
|
+
transport: context.transport,
|
|
133
|
+
location: context.location,
|
|
134
|
+
size: content.length,
|
|
135
|
+
encoding: "utf-8",
|
|
136
|
+
mimeType: "text/plain",
|
|
137
|
+
fetchedAt: context.fetchedAt.toISOString()
|
|
138
|
+
};
|
|
139
|
+
return {
|
|
140
|
+
type: "text",
|
|
141
|
+
content: text,
|
|
142
|
+
meta
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
var textHandler = new TextSemanticHandler;
|
|
147
|
+
var handlers2 = new Map([["text", textHandler]]);
|
|
148
|
+
function getSemanticHandler(type) {
|
|
149
|
+
const handler = handlers2.get(type);
|
|
150
|
+
if (!handler) {
|
|
151
|
+
throw new SemanticError(`Unsupported semantic type: ${type}`, type);
|
|
152
|
+
}
|
|
153
|
+
return handler;
|
|
154
|
+
}
|
|
155
|
+
function registerSemanticHandler(handler) {
|
|
156
|
+
handlers2.set(handler.type, handler);
|
|
157
|
+
}
|
|
158
|
+
async function resolve2(url) {
|
|
159
|
+
const fetchedAt = new Date;
|
|
160
|
+
const parsed = parseARP(url);
|
|
161
|
+
const transportHandler = getTransportHandler(parsed.transport);
|
|
162
|
+
const semanticHandler = getSemanticHandler(parsed.semantic);
|
|
163
|
+
const content = await transportHandler.fetch(parsed.location);
|
|
164
|
+
const context = {
|
|
165
|
+
url,
|
|
166
|
+
semantic: parsed.semantic,
|
|
167
|
+
transport: parsed.transport,
|
|
168
|
+
location: parsed.location,
|
|
169
|
+
fetchedAt
|
|
170
|
+
};
|
|
171
|
+
return semanticHandler.parse(content, context);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/ResourceX.ts
|
|
175
|
+
class ResourceX {
|
|
176
|
+
timeout;
|
|
177
|
+
constructor(config = {}) {
|
|
178
|
+
this.timeout = config.timeout;
|
|
179
|
+
if (config.transports) {
|
|
180
|
+
for (const handler of config.transports) {
|
|
181
|
+
registerTransportHandler(handler);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (config.semantics) {
|
|
185
|
+
for (const handler of config.semantics) {
|
|
186
|
+
registerSemanticHandler(handler);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
parse(url) {
|
|
191
|
+
return parseARP(url);
|
|
192
|
+
}
|
|
193
|
+
async resolve(url) {
|
|
194
|
+
return resolve2(url);
|
|
195
|
+
}
|
|
196
|
+
registerTransport(handler) {
|
|
197
|
+
registerTransportHandler(handler);
|
|
198
|
+
}
|
|
199
|
+
registerSemantic(handler) {
|
|
200
|
+
registerSemanticHandler(handler);
|
|
201
|
+
}
|
|
202
|
+
getTransport(type) {
|
|
203
|
+
return getTransportHandler(type);
|
|
204
|
+
}
|
|
205
|
+
getSemantic(type) {
|
|
206
|
+
return getSemanticHandler(type);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// src/createResourceX.ts
|
|
211
|
+
function createResourceX(config) {
|
|
212
|
+
return new ResourceX(config);
|
|
213
|
+
}
|
|
214
|
+
export {
|
|
215
|
+
createResourceX,
|
|
216
|
+
TransportError,
|
|
217
|
+
SemanticError,
|
|
218
|
+
ResourceXError,
|
|
219
|
+
ResourceX,
|
|
220
|
+
ParseError
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
//# debugId=ACA93DAB894BAF0C64756E2164756E21
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../core/dist/index.js", "../src/ResourceX.ts", "../src/createResourceX.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"// src/errors.ts\nclass ResourceXError extends Error {\n constructor(message, options) {\n super(message, options);\n this.name = \"ResourceXError\";\n }\n}\n\nclass ParseError extends ResourceXError {\n url;\n constructor(message, url) {\n super(message);\n this.url = url;\n this.name = \"ParseError\";\n }\n}\n\nclass TransportError extends ResourceXError {\n transport;\n constructor(message, transport, options) {\n super(message, options);\n this.transport = transport;\n this.name = \"TransportError\";\n }\n}\n\nclass SemanticError extends ResourceXError {\n semantic;\n constructor(message, semantic, options) {\n super(message, options);\n this.semantic = semantic;\n this.name = \"SemanticError\";\n }\n}\n// src/parser.ts\nfunction parseARP(url) {\n if (!url.startsWith(\"arp:\")) {\n throw new ParseError(`Invalid ARP URL: must start with \"arp:\"`, url);\n }\n const content = url.substring(4);\n const separatorIndex = content.indexOf(\"://\");\n if (separatorIndex === -1) {\n throw new ParseError(`Invalid ARP URL: missing \"://\"`, url);\n }\n const typePart = content.substring(0, separatorIndex);\n const location = content.substring(separatorIndex + 3);\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 const semantic = typePart.substring(0, colonIndex);\n const transport = typePart.substring(colonIndex + 1);\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 return { semantic, transport, location };\n}\n// src/transport/http.ts\nclass HttpTransportHandler {\n type;\n protocol;\n constructor(protocol = \"https\") {\n this.protocol = protocol;\n this.type = protocol;\n }\n async fetch(location) {\n const url = `${this.protocol}://${location}`;\n try {\n const response = await fetch(url);\n if (!response.ok) {\n throw new TransportError(`HTTP ${response.status}: ${response.statusText} - ${url}`, this.type);\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.type, { cause: error });\n }\n }\n}\nvar httpsHandler = new HttpTransportHandler(\"https\");\nvar httpHandler = new HttpTransportHandler(\"http\");\n// src/transport/file.ts\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nclass FileTransportHandler {\n type = \"file\";\n async fetch(location) {\n const filePath = resolve(process.cwd(), location);\n try {\n return await readFile(filePath);\n } catch (error) {\n const err = error;\n throw new TransportError(`File read error: ${err.code} - ${filePath}`, this.type, {\n cause: err\n });\n }\n }\n}\nvar fileHandler = new FileTransportHandler;\n// src/transport/index.ts\nvar handlers = new Map([\n [\"https\", httpsHandler],\n [\"http\", httpHandler],\n [\"file\", fileHandler]\n]);\nfunction getTransportHandler(type) {\n const handler = handlers.get(type);\n if (!handler) {\n throw new TransportError(`Unsupported transport type: ${type}`, type);\n }\n return handler;\n}\nfunction registerTransportHandler(handler) {\n handlers.set(handler.type, handler);\n}\n// src/semantic/text.ts\nclass TextSemanticHandler {\n type = \"text\";\n parse(content, context) {\n const text = content.toString(\"utf-8\");\n const meta = {\n url: context.url,\n semantic: context.semantic,\n transport: context.transport,\n location: context.location,\n size: content.length,\n encoding: \"utf-8\",\n mimeType: \"text/plain\",\n fetchedAt: context.fetchedAt.toISOString()\n };\n return {\n type: \"text\",\n content: text,\n meta\n };\n }\n}\nvar textHandler = new TextSemanticHandler;\n// src/semantic/index.ts\nvar handlers2 = new Map([[\"text\", textHandler]]);\nfunction getSemanticHandler(type) {\n const handler = handlers2.get(type);\n if (!handler) {\n throw new SemanticError(`Unsupported semantic type: ${type}`, type);\n }\n return handler;\n}\nfunction registerSemanticHandler(handler) {\n handlers2.set(handler.type, handler);\n}\n// src/resolve.ts\nasync function resolve2(url) {\n const fetchedAt = new Date;\n const parsed = parseARP(url);\n const transportHandler = getTransportHandler(parsed.transport);\n const semanticHandler = getSemanticHandler(parsed.semantic);\n const content = await transportHandler.fetch(parsed.location);\n const context = {\n url,\n semantic: parsed.semantic,\n transport: parsed.transport,\n location: parsed.location,\n fetchedAt\n };\n return semanticHandler.parse(content, context);\n}\n\n// src/index.ts\nvar VERSION = \"0.0.1\";\nexport {\n textHandler,\n resolve2 as resolve,\n registerTransportHandler,\n registerSemanticHandler,\n parseARP,\n httpsHandler,\n httpHandler,\n getTransportHandler,\n getSemanticHandler,\n fileHandler,\n VERSION,\n TransportError,\n SemanticError,\n ResourceXError,\n ParseError\n};\n\n//# debugId=7FDB8A773330183C64756E2164756E21\n",
|
|
6
|
+
"/**\n * ResourceX - Main API class\n */\n\nimport {\n parseARP,\n resolve as coreResolve,\n getTransportHandler,\n getSemanticHandler,\n registerTransportHandler,\n registerSemanticHandler,\n type ParsedARP,\n type Resource,\n type TransportHandler,\n type SemanticHandler,\n} from \"@resourcexjs/core\";\n\n/**\n * ResourceX configuration\n */\nexport interface ResourceXConfig {\n /**\n * Request timeout in milliseconds\n */\n timeout?: number;\n\n /**\n * Custom transport handlers to register\n */\n transports?: TransportHandler[];\n\n /**\n * Custom semantic handlers to register\n */\n semantics?: SemanticHandler[];\n}\n\n/**\n * ResourceX instance\n */\nexport class ResourceX {\n readonly timeout?: number;\n\n constructor(config: ResourceXConfig = {}) {\n this.timeout = config.timeout;\n\n // Register custom handlers from config\n if (config.transports) {\n for (const handler of config.transports) {\n registerTransportHandler(handler);\n }\n }\n\n if (config.semantics) {\n for (const handler of config.semantics) {\n registerSemanticHandler(handler);\n }\n }\n }\n\n /**\n * Parse an ARP URL without fetching\n */\n parse(url: string): ParsedARP {\n return parseARP(url);\n }\n\n /**\n * Resolve an ARP URL to a resource\n */\n async resolve(url: string): Promise<Resource> {\n // TODO: implement timeout using this.timeout\n return coreResolve(url);\n }\n\n /**\n * Register a custom transport handler\n */\n registerTransport(handler: TransportHandler): void {\n registerTransportHandler(handler);\n }\n\n /**\n * Register a custom semantic handler\n */\n registerSemantic(handler: SemanticHandler): void {\n registerSemanticHandler(handler);\n }\n\n /**\n * Get a transport handler by type\n */\n getTransport(type: string): TransportHandler {\n return getTransportHandler(type);\n }\n\n /**\n * Get a semantic handler by type\n */\n getSemantic(type: string): SemanticHandler {\n return getSemanticHandler(type);\n }\n}\n",
|
|
7
|
+
"/**\n * Factory function for creating ResourceX instances\n */\n\nimport { ResourceX, type ResourceXConfig } from \"./ResourceX.js\";\n\n/**\n * Create a new ResourceX instance\n *\n * @example\n * ```typescript\n * import { createResourceX } from \"resourcexjs\";\n *\n * const rx = createResourceX();\n * const resource = await rx.resolve(\"arp:text:https://example.com/file.txt\");\n * ```\n *\n * @example\n * ```typescript\n * // With custom config\n * const rx = createResourceX({\n * timeout: 5000,\n * transports: [myCustomTransport],\n * semantics: [myCustomSemantic],\n * });\n * ```\n */\nexport function createResourceX(config?: ResourceXConfig): ResourceX {\n return new ResourceX(config);\n}\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": ";A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A;AAAA,EAMlC,gBAAgB,CAAC,SAAgC;AAAA,IAC/C,wBAAwB,OAAO;AAAA;AAAA,EAMjC,YAAY,CAAC,MAAgC;AAAA,IAC3C,OAAO,oBAAoB,IAAI;AAAA;AAAA,EAMjC,WAAW,CAAC,MAA+B;AAAA,IACzC,OAAO,mBAAmB,IAAI;AAAA;AAElC;;;AC3EO,SAAS,eAAe,CAAC,QAAqC;AAAA,EACnE,OAAO,IAAI,UAAU,MAAM;AAAA;",
|
|
10
|
+
"debugId": "ACA93DAB894BAF0C64756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "resourcexjs",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "ResourceX - Agent Resource Protocol for AI Agents",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"resourcex",
|
|
7
|
+
"arp",
|
|
8
|
+
"agent",
|
|
9
|
+
"resource",
|
|
10
|
+
"protocol",
|
|
11
|
+
"ai"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/Deepractice/ResourceX.git"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/Deepractice/ResourceX",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22.0.0"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "bun run build.ts",
|
|
36
|
+
"lint": "eslint .",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"clean": "rm -rf dist"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@resourcexjs/core": "workspace:*"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
}
|
|
47
|
+
}
|