@resourcexjs/cli 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 +92 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +81 -0
- package/dist/index.js.map +10 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @resourcexjs/cli
|
|
2
|
+
|
|
3
|
+
Command-line interface for ResourceX - Agent Resource Protocol.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @resourcexjs/cli
|
|
9
|
+
# or
|
|
10
|
+
bun add -g @resourcexjs/cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Resolve an ARP URL and print content
|
|
17
|
+
arp "arp:text:https://example.com/file.txt"
|
|
18
|
+
|
|
19
|
+
# Explicit resolve command
|
|
20
|
+
arp resolve "arp:text:https://example.com/file.txt"
|
|
21
|
+
|
|
22
|
+
# Parse URL without fetching
|
|
23
|
+
arp parse "arp:text:https://example.com/file.txt"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Options
|
|
27
|
+
|
|
28
|
+
| Option | Description |
|
|
29
|
+
| --------------- | -------------- |
|
|
30
|
+
| `-h, --help` | Show help |
|
|
31
|
+
| `-v, --version` | Show version |
|
|
32
|
+
| `-j, --json` | Output as JSON |
|
|
33
|
+
|
|
34
|
+
## Examples
|
|
35
|
+
|
|
36
|
+
### Fetch remote text
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
$ arp "arp:text:https://example.com/"
|
|
40
|
+
<!doctype html>
|
|
41
|
+
<html>
|
|
42
|
+
...
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Fetch local file
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
$ arp "arp:text:file:///path/to/file.txt"
|
|
49
|
+
Hello, World!
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Parse URL components
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
$ arp parse "arp:text:https://example.com/file.txt"
|
|
56
|
+
semantic: text
|
|
57
|
+
transport: https
|
|
58
|
+
location: example.com/file.txt
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### JSON output
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
$ arp "arp:text:file:///tmp/test.txt" --json
|
|
65
|
+
{
|
|
66
|
+
"type": "text",
|
|
67
|
+
"content": "Hello, World!",
|
|
68
|
+
"meta": {
|
|
69
|
+
"url": "arp:text:file:///tmp/test.txt",
|
|
70
|
+
"semantic": "text",
|
|
71
|
+
"transport": "file",
|
|
72
|
+
"location": "/tmp/test.txt",
|
|
73
|
+
"size": 13,
|
|
74
|
+
"encoding": "utf-8",
|
|
75
|
+
"fetchedAt": "2025-01-15T03:22:07.917Z"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## ARP URL Format
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
arp:{semantic}:{transport}://{location}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- **semantic**: Resource type (`text`, etc.)
|
|
87
|
+
- **transport**: Protocol (`https`, `http`, `file`)
|
|
88
|
+
- **location**: Resource location
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
File without changes
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// src/index.ts
|
|
3
|
+
import { createResourceX, ResourceXError } from "resourcexjs";
|
|
4
|
+
var VERSION = "0.0.1";
|
|
5
|
+
var HELP = `
|
|
6
|
+
arp - Agent Resource Protocol CLI
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
arp <url> Resolve an ARP URL and print the content
|
|
10
|
+
arp resolve <url> Same as above
|
|
11
|
+
arp parse <url> Parse an ARP URL and print components
|
|
12
|
+
|
|
13
|
+
Options:
|
|
14
|
+
-h, --help Show this help
|
|
15
|
+
-v, --version Show version
|
|
16
|
+
-j, --json Output as JSON
|
|
17
|
+
|
|
18
|
+
Examples:
|
|
19
|
+
arp "arp:text:https://example.com/file.txt"
|
|
20
|
+
arp parse "arp:text:https://example.com/file.txt"
|
|
21
|
+
arp resolve "arp:text:file:///path/to/file.txt" --json
|
|
22
|
+
`.trim();
|
|
23
|
+
async function main() {
|
|
24
|
+
const args = process.argv.slice(2);
|
|
25
|
+
if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
|
|
26
|
+
console.log(HELP);
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
if (args.includes("-v") || args.includes("--version")) {
|
|
30
|
+
console.log(VERSION);
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
const jsonOutput = args.includes("-j") || args.includes("--json");
|
|
34
|
+
const filteredArgs = args.filter((a) => !a.startsWith("-"));
|
|
35
|
+
const command = filteredArgs[0];
|
|
36
|
+
const rx = createResourceX();
|
|
37
|
+
try {
|
|
38
|
+
if (command === "parse") {
|
|
39
|
+
const url = filteredArgs[1];
|
|
40
|
+
if (!url) {
|
|
41
|
+
console.error("Error: Missing ARP URL");
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
const parsed = rx.parse(url);
|
|
45
|
+
if (jsonOutput) {
|
|
46
|
+
console.log(JSON.stringify(parsed, null, 2));
|
|
47
|
+
} else {
|
|
48
|
+
console.log(`semantic: ${parsed.semantic}`);
|
|
49
|
+
console.log(`transport: ${parsed.transport}`);
|
|
50
|
+
console.log(`location: ${parsed.location}`);
|
|
51
|
+
}
|
|
52
|
+
} else if (command === "resolve") {
|
|
53
|
+
const url = filteredArgs[1];
|
|
54
|
+
if (!url) {
|
|
55
|
+
console.error("Error: Missing ARP URL");
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
await resolve(rx, url, jsonOutput);
|
|
59
|
+
} else {
|
|
60
|
+
await resolve(rx, command, jsonOutput);
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (error instanceof ResourceXError) {
|
|
64
|
+
console.error(`Error: ${error.message}`);
|
|
65
|
+
} else {
|
|
66
|
+
console.error(`Error: ${error.message}`);
|
|
67
|
+
}
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function resolve(rx, url, jsonOutput) {
|
|
72
|
+
const resource = await rx.resolve(url);
|
|
73
|
+
if (jsonOutput) {
|
|
74
|
+
console.log(JSON.stringify(resource, null, 2));
|
|
75
|
+
} else {
|
|
76
|
+
console.log(resource.content);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
main();
|
|
80
|
+
|
|
81
|
+
//# debugId=6A9892B90A1C2BBC64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { createResourceX, ResourceXError } from \"resourcexjs\";\n\nconst VERSION = \"0.0.1\";\n\nconst HELP = `\narp - Agent Resource Protocol CLI\n\nUsage:\n arp <url> Resolve an ARP URL and print the content\n arp resolve <url> Same as above\n arp parse <url> Parse an ARP URL and print components\n\nOptions:\n -h, --help Show this help\n -v, --version Show version\n -j, --json Output as JSON\n\nExamples:\n arp \"arp:text:https://example.com/file.txt\"\n arp parse \"arp:text:https://example.com/file.txt\"\n arp resolve \"arp:text:file:///path/to/file.txt\" --json\n`.trim();\n\nasync function main() {\n const args = process.argv.slice(2);\n\n if (args.length === 0 || args.includes(\"-h\") || args.includes(\"--help\")) {\n console.log(HELP);\n process.exit(0);\n }\n\n if (args.includes(\"-v\") || args.includes(\"--version\")) {\n console.log(VERSION);\n process.exit(0);\n }\n\n const jsonOutput = args.includes(\"-j\") || args.includes(\"--json\");\n const filteredArgs = args.filter((a) => !a.startsWith(\"-\"));\n\n const command = filteredArgs[0];\n const rx = createResourceX();\n\n try {\n if (command === \"parse\") {\n const url = filteredArgs[1];\n if (!url) {\n console.error(\"Error: Missing ARP URL\");\n process.exit(1);\n }\n const parsed = rx.parse(url);\n if (jsonOutput) {\n console.log(JSON.stringify(parsed, null, 2));\n } else {\n console.log(`semantic: ${parsed.semantic}`);\n console.log(`transport: ${parsed.transport}`);\n console.log(`location: ${parsed.location}`);\n }\n } else if (command === \"resolve\") {\n const url = filteredArgs[1];\n if (!url) {\n console.error(\"Error: Missing ARP URL\");\n process.exit(1);\n }\n await resolve(rx, url, jsonOutput);\n } else {\n // Default: treat first arg as URL to resolve\n await resolve(rx, command, jsonOutput);\n }\n } catch (error) {\n if (error instanceof ResourceXError) {\n console.error(`Error: ${error.message}`);\n } else {\n console.error(`Error: ${(error as Error).message}`);\n }\n process.exit(1);\n }\n}\n\nasync function resolve(rx: ReturnType<typeof createResourceX>, url: string, jsonOutput: boolean) {\n const resource = await rx.resolve(url);\n\n if (jsonOutput) {\n console.log(JSON.stringify(resource, null, 2));\n } else {\n console.log(resource.content);\n }\n}\n\nmain();\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAAA;AAEA,IAAM,UAAU;AAEhB,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBX,KAAK;AAEP,eAAe,IAAI,GAAG;AAAA,EACpB,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAAA,EAEjC,IAAI,KAAK,WAAW,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,QAAQ,GAAG;AAAA,IACvE,QAAQ,IAAI,IAAI;AAAA,IAChB,QAAQ,KAAK,CAAC;AAAA,EAChB;AAAA,EAEA,IAAI,KAAK,SAAS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AAS;AAAA;AAAA,IAEpD,QAAQ,KAAK,CAAC;AAAA;AAAA;AAIlB,eAAe,OAAO,CAAC,IAAwC,KAAa,YAAqB;AAAA,EAC/F,MAAM,WAAW,MAAM,GAAG,QAAQ,GAAG;AAAA,EAErC,IAAI,YAAY;AAAA,IACd,QAAQ,IAAI,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AAAA,EAC/C,EAAO;AAAA,IACL,QAAQ,IAAI,SAAS,OAAO;AAAA;AAAA;AAIhC,KAAK;",
|
|
8
|
+
"debugId": "6A9892B90A1C2BBC64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@resourcexjs/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "CLI for ResourceX - Agent Resource Protocol",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"resourcex",
|
|
7
|
+
"arp",
|
|
8
|
+
"cli",
|
|
9
|
+
"agent",
|
|
10
|
+
"resource"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/Deepractice/ResourceX.git",
|
|
15
|
+
"directory": "packages/cli"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"bin": {
|
|
20
|
+
"arp": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "bun run build.ts",
|
|
27
|
+
"dev": "bun run src/index.ts",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"clean": "rm -rf dist"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"resourcexjs": "workspace:*"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=22.0.0"
|
|
40
|
+
}
|
|
41
|
+
}
|