resourcexjs 2.2.0 → 2.4.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/README.md CHANGED
@@ -5,23 +5,21 @@ ResourceX - Resource management protocol for AI Agents. Like npm for AI resource
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install resourcexjs @resourcexjs/registry
8
+ npm install resourcexjs
9
9
  # or
10
- bun add resourcexjs @resourcexjs/registry
10
+ bun add resourcexjs
11
11
  ```
12
12
 
13
13
  ## Quick Start
14
14
 
15
15
  ```typescript
16
- import { createRegistry } from "@resourcexjs/registry";
17
- import { createRXM, createRXC, parseRXL } from "resourcexjs";
16
+ import { createRegistry, parseRXL, createRXM, createRXA } from "resourcexjs";
18
17
 
19
18
  // Create registry
20
19
  const registry = createRegistry();
21
20
 
22
21
  // Prepare a resource
23
22
  const manifest = createRXM({
24
- domain: "localhost",
25
23
  name: "my-prompt",
26
24
  type: "text",
27
25
  version: "1.0.0",
@@ -30,18 +28,19 @@ const manifest = createRXM({
30
28
  const rxr = {
31
29
  locator: parseRXL(manifest.toLocator()),
32
30
  manifest,
33
- content: createRXC("You are a helpful assistant."),
31
+ archive: await createRXA({ content: "You are a helpful assistant." }),
34
32
  };
35
33
 
36
- // Link to local registry
37
- await registry.link(rxr);
34
+ // Add to registry
35
+ await registry.add(rxr);
38
36
 
39
- // Resolve resource
40
- const resource = await registry.resolve("localhost/my-prompt.text@1.0.0");
41
- console.log(await resource.content.text());
37
+ // Resolve and execute
38
+ const resolved = await registry.resolve("localhost/my-prompt.text@1.0.0");
39
+ const text = await resolved.execute();
40
+ console.log(text); // "You are a helpful assistant."
42
41
  ```
43
42
 
44
- ## API
43
+ ## Core Concepts
45
44
 
46
45
  ### RXL - Resource Locator
47
46
 
@@ -68,44 +67,41 @@ Create resource metadata:
68
67
  import { createRXM } from "resourcexjs";
69
68
 
70
69
  const manifest = createRXM({
71
- domain: "deepractice.ai",
70
+ domain: "deepractice.ai", // optional, defaults to "localhost"
72
71
  path: "sean", // optional
73
72
  name: "assistant",
74
73
  type: "prompt",
75
74
  version: "1.0.0",
76
75
  });
77
76
 
78
- manifest.toLocator(); // "deepractice.ai/sean/assistant.prompt@1.0.0"
79
- manifest.toJSON(); // plain object
77
+ manifest.toLocator(); // "deepractice.ai/sean/assistant.prompt@1.0.0"
78
+ manifest.toJSON(); // plain object
80
79
  ```
81
80
 
82
- ### RXC - Resource Content
81
+ ### RXA - Resource Archive
83
82
 
84
- Archive-based content (internally tar.gz), supports single or multi-file resources:
83
+ Archive container (tar.gz) for storage/transfer:
85
84
 
86
85
  ```typescript
87
- import { createRXC } from "resourcexjs";
86
+ import { createRXA } from "resourcexjs";
88
87
 
89
88
  // Single file
90
- const content = await createRXC({ content: "Hello, World!" });
89
+ const archive = await createRXA({ content: "Hello, World!" });
91
90
 
92
91
  // Multiple files
93
- const content = await createRXC({
92
+ const archive = await createRXA({
94
93
  "index.ts": "export default 1",
95
94
  "styles.css": "body {}",
96
95
  });
97
96
 
98
- // Nested directories
99
- const content = await createRXC({
100
- "src/index.ts": "main code",
101
- "src/utils/helper.ts": "helper code",
102
- });
97
+ // Extract to package for file access
98
+ const pkg = await archive.extract();
99
+ const buffer = await pkg.file("content"); // Buffer
100
+ const files = await pkg.files(); // Map<string, Buffer>
103
101
 
104
- // Read files
105
- const buffer = await content.file("content"); // single file → Buffer
106
- const files = await content.files(); // all files → Map<string, Buffer>
107
- const archiveBuffer = await content.buffer(); // raw tar.gz
108
- const stream = content.stream; // tar.gz ReadableStream
102
+ // Archive methods
103
+ const tarGzBuffer = await archive.buffer();
104
+ const stream = archive.stream;
109
105
  ```
110
106
 
111
107
  ### RXR - Resource
@@ -113,33 +109,41 @@ const stream = content.stream; // tar.gz ReadableStream
113
109
  Complete resource object (pure interface):
114
110
 
115
111
  ```typescript
116
- interface RXR {
117
- locator: RXL;
118
- manifest: RXM;
119
- content: RXC;
120
- }
121
-
122
- // Create from literals
123
- const rxr: RXR = { locator, manifest, content };
112
+ import type { RXR } from "resourcexjs";
113
+
114
+ const rxr: RXR = {
115
+ locator, // RXL
116
+ manifest, // RXM
117
+ archive, // RXA
118
+ };
124
119
  ```
125
120
 
126
121
  ### Registry
127
122
 
128
- Resource storage and retrieval (from `@resourcexjs/registry`):
123
+ Resource storage and retrieval:
129
124
 
130
125
  ```typescript
131
- import { createRegistry } from "@resourcexjs/registry";
126
+ import { createRegistry, loadResource } from "resourcexjs";
132
127
 
133
128
  const registry = createRegistry({
134
129
  path: "~/.resourcex", // optional
135
130
  types: [customType], // optional, defaults to built-in types
131
+ isolator: "srt", // optional sandbox isolation
136
132
  });
137
133
 
138
- // Link (local development/cache)
139
- await registry.link(rxr);
134
+ // Add from folder or RXR
135
+ await registry.add("./my-prompt");
136
+ await registry.add(rxr);
140
137
 
141
- // Resolve (local-first, then remote)
142
- const rxr = await registry.resolve("deepractice.ai/assistant.prompt@1.0.0");
138
+ // Link for development (symlink)
139
+ await registry.link("./my-prompt");
140
+
141
+ // Resolve and execute
142
+ const resolved = await registry.resolve("localhost/my-prompt.text@1.0.0");
143
+ const text = await resolved.execute();
144
+
145
+ // Get raw RXR
146
+ const rxr = await registry.get("localhost/my-prompt.text@1.0.0");
143
147
 
144
148
  // Check existence
145
149
  const exists = await registry.exists("localhost/test.text@1.0.0");
@@ -161,44 +165,34 @@ Built-in types:
161
165
  | `json` | config, manifest | JSON content |
162
166
  | `binary` | bin, blob, raw | Binary content |
163
167
 
164
- Define custom types:
168
+ Custom types (requires bundling):
165
169
 
166
170
  ```typescript
167
- import { defineResourceType } from "resourcexjs";
168
-
169
- defineResourceType({
170
- name: "prompt",
171
- aliases: ["deepractice-prompt"],
172
- description: "AI Prompt template",
173
- serializer: {
174
- serialize: async (rxr) => Buffer.from(await rxr.content.text()),
175
- deserialize: async (data, manifest) => ({
176
- locator: parseRXL(manifest.toLocator()),
177
- manifest,
178
- content: createRXC(data.toString()),
179
- }),
180
- },
181
- resolver: {
182
- resolve: async (rxr) => ({
183
- template: await rxr.content.text(),
184
- // ... custom methods
185
- }),
186
- },
171
+ import { bundleResourceType, createRegistry } from "resourcexjs";
172
+
173
+ // Bundle from source file
174
+ const promptType = await bundleResourceType("./prompt.type.ts");
175
+
176
+ // Create registry with type
177
+ const registry = createRegistry({
178
+ types: [promptType],
187
179
  });
188
180
  ```
189
181
 
190
- ### TypeHandlerChain
182
+ ### Load Resources
191
183
 
192
- Responsibility chain for type handling (used internally):
184
+ Load resources from folders:
193
185
 
194
186
  ```typescript
195
- import { createTypeHandlerChain, builtinTypes } from "resourcexjs";
187
+ import { loadResource, FolderLoader } from "resourcexjs";
196
188
 
197
- const chain = createTypeHandlerChain(builtinTypes);
189
+ // Load from folder (uses FolderLoader by default)
190
+ const rxr = await loadResource("./my-prompt");
198
191
 
199
- chain.serialize(rxr); // Buffer
200
- chain.deserialize(buffer, manifest); // RXR
201
- chain.resolve<T>(rxr); // → T (usable object)
192
+ // Use custom loader
193
+ const rxr = await loadResource("./my-prompt", {
194
+ loader: new CustomLoader(),
195
+ });
202
196
  ```
203
197
 
204
198
  ## ARP - Low-level I/O
@@ -208,7 +202,8 @@ For direct file/network operations:
208
202
  ```typescript
209
203
  import { createARP } from "resourcexjs/arp";
210
204
 
211
- const arp = createARP(); // Defaults include file, http, https, text, binary
205
+ // createARP() includes rxr transport for ResourceX resources
206
+ const arp = createARP();
212
207
 
213
208
  // Parse URL
214
209
  const arl = arp.parse("arp:text:file://./config.txt");
@@ -217,16 +212,16 @@ const arl = arp.parse("arp:text:file://./config.txt");
217
212
  const resource = await arl.resolve();
218
213
  console.log(resource.content); // string
219
214
 
220
- // Read with params (e.g., directory listing)
221
- const dirArl = arp.parse("arp:text:file://./data");
222
- const dir = await dirArl.resolve({ recursive: "true", pattern: "*.json" });
223
-
224
215
  // Write
225
216
  await arl.deposit("hello world");
226
217
 
227
218
  // Operations
228
- await arl.exists(); // boolean
219
+ await arl.exists(); // boolean
229
220
  await arl.delete();
221
+
222
+ // Access files inside resources
223
+ const rxrArl = arp.parse("arp:text:rxr://localhost/my-prompt.text@1.0.0/content");
224
+ const { content } = await rxrArl.resolve();
230
225
  ```
231
226
 
232
227
  ## Exports
@@ -235,7 +230,9 @@ await arl.delete();
235
230
 
236
231
  ```typescript
237
232
  // Errors
238
- export { ResourceXError, LocatorError, ManifestError, ContentError, ResourceTypeError };
233
+ export { ResourceXError, LocatorError, ManifestError, ContentError };
234
+ export { ResourceTypeError };
235
+ export { RegistryError };
239
236
 
240
237
  // RXL (Locator)
241
238
  export { parseRXL };
@@ -245,55 +242,96 @@ export type { RXL };
245
242
  export { createRXM };
246
243
  export type { RXM, ManifestData };
247
244
 
248
- // RXC (Content)
249
- export { createRXC, loadRXC };
250
- export type { RXC };
245
+ // RXA (Archive) and RXP (Package)
246
+ export { createRXA };
247
+ export type { RXA, RXP, RXAInput, PathNode };
251
248
 
252
249
  // RXR (Resource)
253
- export type { RXR, ResourceType, ResourceSerializer, ResourceResolver };
254
-
255
- // ResourceType
256
- export { defineResourceType, getResourceType, clearResourceTypes };
250
+ export type { RXR };
251
+
252
+ // Type System
253
+ export type {
254
+ ResourceType,
255
+ ResourceResolver,
256
+ ResolvedResource,
257
+ JSONSchema,
258
+ BundledType,
259
+ IsolatorType,
260
+ };
261
+ export { TypeHandlerChain, bundleResourceType };
257
262
  export { textType, jsonType, binaryType, builtinTypes };
258
- export { TypeHandlerChain, createTypeHandlerChain };
259
- ```
260
263
 
261
- ### Registry Package (`@resourcexjs/registry`)
264
+ // Resource Loading
265
+ export type { ResourceLoader, LoadResourceConfig };
266
+ export { loadResource, FolderLoader };
267
+
268
+ // Registry
269
+ export type {
270
+ Registry,
271
+ RegistryConfig,
272
+ ClientRegistryConfig,
273
+ ServerRegistryConfig,
274
+ CreateRegistryConfig,
275
+ };
276
+ export type { Storage, SearchOptions, DiscoveryResult, WellKnownResponse };
277
+ export { DefaultRegistry, createRegistry, discoverRegistry, LocalStorage };
262
278
 
263
- ```typescript
264
- export { createRegistry, ARPRegistry };
265
- export { RegistryError };
266
- export type { Registry, RegistryConfig };
279
+ // Middleware
280
+ export { RegistryMiddleware, DomainValidation, withDomainValidation };
281
+
282
+ // Version
283
+ export const VERSION: string;
267
284
  ```
268
285
 
269
286
  ### ARP Package (`resourcexjs/arp`)
270
287
 
271
288
  ```typescript
289
+ // Enhanced createARP with RxrTransport
272
290
  export { createARP, ARP, type ARPConfig };
291
+ export { VERSION };
273
292
  export { ARPError, ParseError, TransportError, SemanticError };
274
293
  export type { ARI, ARL };
275
- export { fileTransport, httpTransport, httpsTransport };
276
- export { textSemantic, binarySemantic };
294
+
295
+ // Transports
296
+ export type { TransportHandler, TransportResult, TransportParams };
297
+ export { FileTransportHandler, fileTransport };
298
+ export { HttpTransportHandler, httpTransport, httpsTransport };
299
+ export { RxrTransport, clearRegistryCache, type RxrTransportRegistry };
300
+
301
+ // Semantics
302
+ export type { Resource, SemanticHandler, ResourceMeta, SemanticContext };
303
+ export type { TextResource, BinaryResource, BinaryInput };
304
+ export { TextSemanticHandler, textSemantic };
305
+ export { BinarySemanticHandler, binarySemantic };
277
306
  ```
278
307
 
279
308
  ## Error Hierarchy
280
309
 
281
310
  ```
282
311
  Error
283
- └── ResourceXError
284
- ├── LocatorError (RXL parsing)
285
- ├── ManifestError (RXM validation)
286
- ├── ContentError (RXC consumption)
287
- └── ResourceTypeError (Type registration)
288
-
289
- └── RegistryError (Registry operations)
290
-
312
+ ├── ResourceXError
313
+ ├── LocatorError (RXL parsing)
314
+ ├── ManifestError (RXM validation)
315
+ │ └── ContentError (RXA/RXP operations)
316
+ ├── ResourceTypeError (Type registration)
317
+ ├── RegistryError (Registry operations)
291
318
  └── ARPError
292
319
  ├── ParseError (URL parsing)
293
- ├── TransportError (Transport not found)
294
- └── SemanticError (Semantic not found)
320
+ ├── TransportError (Transport operations)
321
+ └── SemanticError (Semantic operations)
295
322
  ```
296
323
 
324
+ ## Packages
325
+
326
+ | Package | Description |
327
+ | ----------------------- | ----------------------------- |
328
+ | `resourcexjs` | Main package (re-exports all) |
329
+ | `@resourcexjs/core` | RXL, RXM, RXA, RXP, RXR |
330
+ | `@resourcexjs/type` | Type system, bundler |
331
+ | `@resourcexjs/loader` | Resource loading |
332
+ | `@resourcexjs/registry` | Storage and retrieval |
333
+ | `@resourcexjs/arp` | Low-level I/O protocol |
334
+
297
335
  ## License
298
336
 
299
337
  MIT
package/dist/arp.d.ts CHANGED
@@ -12,8 +12,10 @@ import { TransportHandler, TransportResult, TransportParams } from "@resourcexjs
12
12
  */
13
13
  interface RxrTransportRegistry {
14
14
  get(locator: string): Promise<{
15
- content: {
16
- files(): Promise<Map<string, Buffer>>
15
+ archive: {
16
+ extract(): Promise<{
17
+ files(): Promise<Map<string, Buffer>>
18
+ }>
17
19
  }
18
20
  }>;
19
21
  }
@@ -24,10 +26,6 @@ interface RxrTransportRegistry {
24
26
  * Example: deepractice.ai/nuwa.role@1.0.0/thought/first-principles.md
25
27
  *
26
28
  * The RXL portion ends at @version, and the internal path follows.
27
- *
28
- * When no registry is provided, automatically creates one based on domain:
29
- * - localhost: LocalRegistry
30
- * - Other domains: RemoteRegistry with well-known discovery
31
29
  */
32
30
  declare class RxrTransport implements TransportHandler {
33
31
  private registry?;
@@ -50,25 +48,19 @@ declare class RxrTransport implements TransportHandler {
50
48
  */
51
49
  delete(_location: string): Promise<void>;
52
50
  /**
53
- * Get or create a registry for the given domain.
54
- * - If a registry was provided in constructor, use it
55
- * - localhost: create LocalRegistry
56
- * - Other domains: discover endpoint via well-known and create appropriate registry
51
+ * Get the registry instance.
52
+ * Uses injected registry if provided, otherwise creates/returns singleton.
57
53
  */
58
54
  private getRegistry;
59
55
  /**
60
- * Check if URL is a git repository URL.
61
- */
62
- private isGitUrl;
63
- /**
64
- * Parse location into domain, RXL and internal path.
56
+ * Parse location into RXL and internal path.
65
57
  * Format: {domain}/{path}/{name}.{type}@{version}/{internal-path}
66
58
  * Example: deepractice.ai/nuwa.role@1.0.0/thought/first-principles.md
67
59
  */
68
60
  private parseLocation;
69
61
  }
70
62
  /**
71
- * Clear the registry cache. Useful for testing.
63
+ * Clear the default registry. Useful for testing.
72
64
  */
73
65
  declare function clearRegistryCache(): void;
74
66
  /**