@contextvm/ctxcn 1.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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +178 -0
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +47 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/src/__mocks__/mock-server.d.ts +2 -0
  8. package/dist/src/__mocks__/mock-server.d.ts.map +1 -0
  9. package/dist/src/__mocks__/mock-server.js +24 -0
  10. package/dist/src/__mocks__/mock-server.js.map +1 -0
  11. package/dist/src/commands/add.d.ts +2 -0
  12. package/dist/src/commands/add.d.ts.map +1 -0
  13. package/dist/src/commands/add.js +106 -0
  14. package/dist/src/commands/add.js.map +1 -0
  15. package/dist/src/commands/help.d.ts +2 -0
  16. package/dist/src/commands/help.d.ts.map +1 -0
  17. package/dist/src/commands/help.js +15 -0
  18. package/dist/src/commands/help.js.map +1 -0
  19. package/dist/src/commands/init.d.ts +2 -0
  20. package/dist/src/commands/init.d.ts.map +1 -0
  21. package/dist/src/commands/init.js +61 -0
  22. package/dist/src/commands/init.js.map +1 -0
  23. package/dist/src/commands/update.d.ts +2 -0
  24. package/dist/src/commands/update.d.ts.map +1 -0
  25. package/dist/src/commands/update.js +145 -0
  26. package/dist/src/commands/update.js.map +1 -0
  27. package/dist/src/config.d.ts +10 -0
  28. package/dist/src/config.d.ts.map +1 -0
  29. package/dist/src/config.js +31 -0
  30. package/dist/src/config.js.map +1 -0
  31. package/dist/src/ctxcn/DemoServerClient.d.ts +38 -0
  32. package/dist/src/ctxcn/DemoServerClient.d.ts.map +1 -0
  33. package/dist/src/ctxcn/DemoServerClient.js +53 -0
  34. package/dist/src/ctxcn/DemoServerClient.js.map +1 -0
  35. package/dist/src/ctxcn/ExampleServersEverythingClient.d.ts +149 -0
  36. package/dist/src/ctxcn/ExampleServersEverythingClient.d.ts.map +1 -0
  37. package/dist/src/ctxcn/ExampleServersEverythingClient.js +118 -0
  38. package/dist/src/ctxcn/ExampleServersEverythingClient.js.map +1 -0
  39. package/dist/src/ctxcn/TestClient.d.ts +149 -0
  40. package/dist/src/ctxcn/TestClient.d.ts.map +1 -0
  41. package/dist/src/ctxcn/TestClient.js +118 -0
  42. package/dist/src/ctxcn/TestClient.js.map +1 -0
  43. package/dist/src/utils/cli.d.ts +7 -0
  44. package/dist/src/utils/cli.d.ts.map +1 -0
  45. package/dist/src/utils/cli.js +77 -0
  46. package/dist/src/utils/cli.js.map +1 -0
  47. package/dist/src/utils/schema.d.ts +11 -0
  48. package/dist/src/utils/schema.d.ts.map +1 -0
  49. package/dist/src/utils/schema.js +333 -0
  50. package/dist/src/utils/schema.js.map +1 -0
  51. package/dist/src/utils.d.ts +2 -0
  52. package/dist/src/utils.d.ts.map +1 -0
  53. package/dist/src/utils.js +12 -0
  54. package/dist/src/utils.js.map +1 -0
  55. package/package.json +51 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ContextVM
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # ctxcn
2
+
3
+ `ctxcn` is a command-line utility inspired by `shadcn` that streamlines the integration of ContextVM (CVM) servers into your TypeScript projects. It generates a type-safe client from a CVM server's tool definitions, allowing you to call CVM tools as if they were native TypeScript functions.
4
+
5
+ ## Overview
6
+
7
+ The `ctxcn` utility provides the following features:
8
+
9
+ - **Interactive Project Initialization**: Sets up your project with the necessary configuration to connect to CVM servers through an interactive command-line interface.
10
+ - **Code Generation**: Generates a TypeScript client from a CVM server's tool definitions, providing a seamless and type-safe development experience.
11
+ - **Configuration**: Allows you to configure the output directory for the generated client, as well as the relays and private key to use when connecting to CVM servers.
12
+
13
+ ## Installation
14
+
15
+ ### Global Installation
16
+
17
+ Install ctxcn globally using npm:
18
+
19
+ ```bash
20
+ npm install -g @contextvm/ctxcn
21
+ ```
22
+
23
+ ### Local Installation
24
+
25
+ Install ctxcn as a dev dependency in your project:
26
+
27
+ ```bash
28
+ npm install --save-dev @contextvm/ctxcn
29
+ ```
30
+
31
+ ### Development Installation
32
+
33
+ To get started with the source code, clone the repository and install the dependencies:
34
+
35
+ ```bash
36
+ git clone https://github.com/your-username/ctxcn.git
37
+ cd ctxcn
38
+ bun install
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ The `ctxcn` utility provides four main commands: `init`, `add`, `update`, and `help`.
44
+
45
+ ### `init`
46
+
47
+ The `init` command initializes your project with a `ctxcn.config.json` file. This command will guide you through the process of creating the configuration file, asking for the source directory and relays.
48
+
49
+ To run the `init` command, execute the following command in your project's root directory:
50
+
51
+ ```bash
52
+ ctxcn init
53
+ ```
54
+
55
+ If you've installed locally or are working with the source code:
56
+
57
+ ```bash
58
+ npx @contextvm/ctxcn init
59
+ # or
60
+ bun run index.ts init
61
+ ```
62
+
63
+ This will start the interactive initialization process.
64
+
65
+ ### `add`
66
+
67
+ The `add` command generates a TypeScript client from a CVM server's tool definitions. It takes a CVM server's pubkey as an argument and provides an interactive experience for configuring the client.
68
+
69
+ To run the `add` command, execute the following command in your project's root directory:
70
+
71
+ ```bash
72
+ ctxcn add <pubkey>
73
+ ```
74
+
75
+ If you've installed locally or are working with the source code:
76
+
77
+ ```bash
78
+ npx @contextvm/ctxcn add <pubkey>
79
+ # or
80
+ bun run index.ts add <pubkey>
81
+ ```
82
+
83
+ This will:
84
+
85
+ 1. Connect to the specified CVM server
86
+ 2. Display server information and available tools
87
+ 3. Allow you to customize the client name
88
+ 4. Provide options to:
89
+ - Generate and save the client file
90
+ - Print the generated code to console only
91
+ - Cancel the operation
92
+
93
+ ### `update`
94
+
95
+ The `update` command refreshes existing CVM server clients with the latest tool definitions. You can update a specific client or all clients at once.
96
+
97
+ To update a specific client:
98
+
99
+ ```bash
100
+ ctxcn update <pubkey>
101
+ ```
102
+
103
+ To update all clients or select from a list:
104
+
105
+ ```bash
106
+ ctxcn update
107
+ ```
108
+
109
+ If you've installed locally or are working with the source code:
110
+
111
+ ```bash
112
+ npx @contextvm/ctxcn update <pubkey>
113
+ # or
114
+ bun run index.ts update
115
+ ```
116
+
117
+ The update command will:
118
+
119
+ 1. Check if the server name has changed
120
+ 2. Ask if you want to use the new server name or keep the existing one
121
+ 3. Display updated server information and tools
122
+ 4. Allow you to confirm before updating
123
+
124
+ ### `help`
125
+
126
+ The `help` command displays a help message with information about the available commands and options.
127
+
128
+ To run the `help` command, execute the following command:
129
+
130
+ ```bash
131
+ ctxcn help
132
+ ```
133
+
134
+ If you've installed locally or are working with the source code:
135
+
136
+ ```bash
137
+ npx @contextvm/ctxcn help
138
+ # or
139
+ bun run index.ts help
140
+ ```
141
+
142
+ ## Configuration
143
+
144
+ The `ctxcn` utility can be configured via a `ctxcn.config.json` file in your project's root directory. The following options are available:
145
+
146
+ - `source`: The source directory for the generated client.
147
+ - `relays`: An array of relays to use when connecting to CVM servers.
148
+ - `privateKey`: The private key to use when connecting to CVM servers. If not provided, a new private key will be generated on the fly.
149
+ - `addedClients`: An array of public keys of the clients that have been added. This is automatically managed by the CLI.
150
+
151
+ ## Example
152
+
153
+ Here is an example of how to use the generated client:
154
+
155
+ ```typescript
156
+ import { AdditionClient } from "./src/ctxcn/AdditionClient.ts";
157
+ import {
158
+ NostrClientTransport,
159
+ PrivateKeySigner,
160
+ ApplesauceRelayPool,
161
+ } from "@contextvm/sdk";
162
+
163
+ const transport = new NostrClientTransport({
164
+ signer: new PrivateKeySigner(),
165
+ relayHandler: new ApplesauceRelayPool(["ws://localhost:10547"]),
166
+ serverPubkey: "<pubkey>",
167
+ isStateless: true,
168
+ });
169
+
170
+ const mcpClient = new AdditionClient(transport);
171
+ await mcpClient.connect();
172
+
173
+ const result = await mcpClient.add({ a: 5, b: 10 });
174
+
175
+ console.log(result.result); // 15
176
+
177
+ await mcpClient.disconnect();
178
+ ```
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ import { handleInit } from "./src/commands/init";
3
+ import { handleAdd } from "./src/commands/add";
4
+ import { handleUpdate } from "./src/commands/update";
5
+ import { handleHelp } from "./src/commands/help";
6
+ async function main() {
7
+ try {
8
+ const args = process.argv.slice(2);
9
+ const command = args[0];
10
+ if (!command) {
11
+ handleHelp();
12
+ return;
13
+ }
14
+ switch (command) {
15
+ case "init":
16
+ await handleInit(process.cwd());
17
+ break;
18
+ case "add":
19
+ const pubkey = args[1];
20
+ if (!pubkey) {
21
+ console.error("Error: Missing pubkey for 'add' command.");
22
+ console.error("Usage: ctxcn add <pubkey>");
23
+ process.exit(1);
24
+ }
25
+ await handleAdd(pubkey, process.cwd());
26
+ break;
27
+ case "update":
28
+ const updatePubkey = args[1];
29
+ await handleUpdate(process.cwd(), updatePubkey);
30
+ break;
31
+ case "help":
32
+ handleHelp();
33
+ break;
34
+ default:
35
+ console.error(`Error: Unknown command '${command}'`);
36
+ handleHelp();
37
+ process.exit(1);
38
+ break;
39
+ }
40
+ }
41
+ catch (error) {
42
+ console.error("An unexpected error occurred:", error);
43
+ process.exit(1);
44
+ }
45
+ }
46
+ main();
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAExB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,UAAU,EAAE,CAAC;YACb,OAAO;QACT,CAAC;QAED,QAAQ,OAAO,EAAE,CAAC;YAChB,KAAK,MAAM;gBACT,MAAM,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;gBAChC,MAAM;YACR,KAAK,KAAK;gBACR,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;gBACvB,IAAI,CAAC,MAAM,EAAE,CAAC;oBACZ,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;oBAC1D,OAAO,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;oBAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAClB,CAAC;gBACD,MAAM,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;gBACvC,MAAM;YACR,KAAK,QAAQ;gBACX,MAAM,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;gBAC7B,MAAM,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;gBAChD,MAAM;YACR,KAAK,MAAM;gBACT,UAAU,EAAE,CAAC;gBACb,MAAM;YACR;gBACE,OAAO,CAAC,KAAK,CAAC,2BAA2B,OAAO,GAAG,CAAC,CAAC;gBACrD,UAAU,EAAE,CAAC;gBACb,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAChB,MAAM;QACV,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mock-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-server.d.ts","sourceRoot":"","sources":["../../../src/__mocks__/mock-server.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { z } from "zod";
4
+ const server = new McpServer({
5
+ name: "math-server",
6
+ version: "1.0.0",
7
+ });
8
+ const outputSchema = z.object({
9
+ result: z.number(),
10
+ });
11
+ // Add an addition tool
12
+ server.registerTool("add", {
13
+ title: "Addition Tool",
14
+ description: "Add two numbers",
15
+ inputSchema: { a: z.number(), b: z.number() },
16
+ outputSchema: outputSchema.shape,
17
+ }, async ({ a, b }) => ({
18
+ content: [{ type: "text", text: String(a + b) }],
19
+ structuredContent: { result: a + b },
20
+ }));
21
+ // Start receiving messages on stdin and sending messages on stdout
22
+ const transport = new StdioServerTransport();
23
+ await server.connect(transport);
24
+ //# sourceMappingURL=mock-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-server.js","sourceRoot":"","sources":["../../../src/__mocks__/mock-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAC3B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,OAAO;CACjB,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC;AACH,uBAAuB;AACvB,MAAM,CAAC,YAAY,CACjB,KAAK,EACL;IACE,KAAK,EAAE,eAAe;IACtB,WAAW,EAAE,iBAAiB;IAC9B,WAAW,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;IAC7C,YAAY,EAAE,YAAY,CAAC,KAAK;CACjC,EACD,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACnB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IAChD,iBAAiB,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE;CACrC,CAAC,CACH,CAAC;AAEF,mEAAmE;AACnE,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;AAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function handleAdd(pubkey: string, cwd: string): Promise<void>;
2
+ //# sourceMappingURL=add.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../../src/commands/add.ts"],"names":[],"mappings":"AAaA,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,iBA+H1D"}
@@ -0,0 +1,106 @@
1
+ import { Client } from "@modelcontextprotocol/sdk/client";
2
+ import { mkdir, writeFile, access } from "fs/promises";
3
+ import path from "path";
4
+ import { toPascalCase } from "../utils";
5
+ import { loadConfig, saveConfig } from "../config";
6
+ import { askQuestion, closeReadlineInterface } from "../utils/cli";
7
+ import { generateClientCode } from "../utils/schema";
8
+ import { ApplesauceRelayPool, NostrClientTransport, PrivateKeySigner, } from "@contextvm/sdk";
9
+ export async function handleAdd(pubkey, cwd) {
10
+ console.log("šŸ” Checking for configuration file...");
11
+ // Check if config file exists
12
+ const configPath = path.join(cwd, "ctxcn.config.json");
13
+ try {
14
+ await access(configPath);
15
+ }
16
+ catch (error) {
17
+ console.error("āŒ Error: Configuration file 'ctxcn.config.json' not found.");
18
+ console.error("Please run 'ctxcn init' first to create a configuration file.");
19
+ closeReadlineInterface();
20
+ process.exit(1);
21
+ }
22
+ const config = await loadConfig(cwd);
23
+ // Check if client is already added
24
+ if (config.addedClients && config.addedClients.includes(pubkey)) {
25
+ console.log(`āš ļø Client with pubkey ${pubkey} is already added.`);
26
+ console.log("Use 'ctxcn update' to refresh the client if needed.");
27
+ closeReadlineInterface();
28
+ process.exit(0);
29
+ }
30
+ console.log(`šŸ”— Connecting to server ${pubkey}...`);
31
+ const client = new Client({
32
+ name: `generator-client`,
33
+ version: "1.0.0",
34
+ });
35
+ const transport = new NostrClientTransport({
36
+ signer: new PrivateKeySigner(config.privateKey),
37
+ relayHandler: new ApplesauceRelayPool(config.relays),
38
+ serverPubkey: pubkey,
39
+ // isStateless: true,
40
+ });
41
+ try {
42
+ await client.connect(transport);
43
+ const serverDetails = client.getServerVersion();
44
+ const toolListResult = await client.listTools();
45
+ await transport.close();
46
+ let serverName = toPascalCase(serverDetails?.name || "UnknownServer");
47
+ // Interactive confirmation
48
+ console.log(`\nšŸ“‹ Server Information:`);
49
+ console.log(` Name: ${serverDetails?.name || "Unknown"}`);
50
+ console.log(` Version: ${serverDetails?.version || "Unknown"}`);
51
+ console.log(` Tools found: ${toolListResult.tools.length}`);
52
+ console.log(`\nšŸ”§ Available Tools:`);
53
+ toolListResult.tools.forEach((tool, index) => {
54
+ console.log(` ${index + 1}. ${tool.name}: ${tool.description || "No description"}`);
55
+ });
56
+ console.log(`\nāš™ļø Client Configuration:`);
57
+ console.log(` Client Name: ${serverName}Client`);
58
+ console.log(` Output Directory: ${config.source}`);
59
+ // Allow user to change client name
60
+ const customName = await askQuestion("Enter custom client name (leave empty to use default)", "");
61
+ if (customName.trim()) {
62
+ serverName = toPascalCase(customName.trim());
63
+ }
64
+ // Confirmation options
65
+ console.log("\nšŸ¤” What would you like to do?");
66
+ console.log("1. Generate and save the client file");
67
+ console.log("2. Print the generated code to console only");
68
+ console.log("3. Cancel");
69
+ const choice = await askQuestion("Choose an option (1-3)", "1");
70
+ if (choice === "3") {
71
+ console.log("āŒ Operation cancelled.");
72
+ closeReadlineInterface();
73
+ process.exit(0);
74
+ }
75
+ const printOnly = choice === "2";
76
+ const clientName = `${serverName}Client`;
77
+ const clientCode = await generateClientCode(pubkey, serverDetails, toolListResult, serverName);
78
+ if (printOnly) {
79
+ console.log("\nšŸ“„ Generated Client Code:");
80
+ console.log("=".repeat(50));
81
+ console.log(clientCode);
82
+ console.log("=".repeat(50));
83
+ }
84
+ else {
85
+ const outputDir = path.join(cwd, config.source);
86
+ await mkdir(outputDir, { recursive: true });
87
+ const outputPath = path.join(outputDir, `${clientName}.ts`);
88
+ await writeFile(outputPath, clientCode);
89
+ // Add the client to the config
90
+ if (!config.addedClients) {
91
+ config.addedClients = [];
92
+ }
93
+ config.addedClients.push(pubkey);
94
+ await saveConfig(cwd, config);
95
+ console.log(`āœ… Generated client for ${serverName} at ${outputPath}`);
96
+ }
97
+ closeReadlineInterface();
98
+ process.exit(0);
99
+ }
100
+ catch (error) {
101
+ console.error("āŒ Error connecting to server:", error);
102
+ closeReadlineInterface();
103
+ process.exit(1);
104
+ }
105
+ }
106
+ //# sourceMappingURL=add.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add.js","sourceRoot":"","sources":["../../../src/commands/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAExB,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAc,EAAE,GAAW;IACzD,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IAErD,8BAA8B;IAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IACvD,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CACX,4DAA4D,CAC7D,CAAC;QACF,OAAO,CAAC,KAAK,CACX,+DAA+D,CAChE,CAAC;QACF,sBAAsB,E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,OAAO,CAAC,GAAG,CAAC,0BAA0B,UAAU,OAAO,UAAU,EAAE,CAAC,CAAC;QACvE,CAAC;QAED,sBAAsB,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACtD,sBAAsB,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function handleHelp(): void;
2
+ //# sourceMappingURL=help.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../../src/commands/help.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,SAazB"}
@@ -0,0 +1,15 @@
1
+ export function handleHelp() {
2
+ console.log(`
3
+ Usage: ctxcn <command> [options]
4
+
5
+ Commands:
6
+ init Initialize a new project and create a ctxcn.config.json file.
7
+ add Add a new CVM server client to your project.
8
+ update Update existing CVM server clients with the latest tool definitions.
9
+ help Display this help message.
10
+
11
+ Options:
12
+ --help Display help for a specific command.
13
+ `);
14
+ }
15
+ //# sourceMappingURL=help.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.js","sourceRoot":"","sources":["../../../src/commands/help.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU;IACxB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;GAWX,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function handleInit(cwd: string): Promise<void>;
2
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AAKA,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,iBAgF3C"}
@@ -0,0 +1,61 @@
1
+ import { promises as fs } from "fs";
2
+ import path from "path";
3
+ import { DEFAULT_CONFIG } from "../config";
4
+ import { askQuestion, closeReadlineInterface } from "../utils/cli";
5
+ export async function handleInit(cwd) {
6
+ console.log("šŸš€ Initializing project for ctxcn...");
7
+ console.log("\nšŸ” Verifying project structure...");
8
+ const packageJsonPath = path.join(cwd, "package.json");
9
+ try {
10
+ await fs.access(packageJsonPath);
11
+ console.log("āœ”ļø Project structure seems valid (package.json found).");
12
+ }
13
+ catch (error) {
14
+ console.error("āŒ Error: No package.json found. Please run this command in a valid project root directory.");
15
+ process.exit(1);
16
+ }
17
+ const configPath = path.join(cwd, "ctxcn.config.json");
18
+ try {
19
+ await fs.access(configPath);
20
+ const overwrite = await askQuestion("A `ctxcn.config.json` file already exists. Do you want to overwrite it?", "n");
21
+ if (overwrite.toLowerCase() !== "y") {
22
+ console.log("Aborting initialization. Your existing configuration is safe.");
23
+ process.exit(0);
24
+ }
25
+ }
26
+ catch (error) {
27
+ // Config file doesn't exist, so we can proceed.
28
+ }
29
+ console.log("\nāš™ļø Please provide your configuration details:");
30
+ const source = await askQuestion("Enter the source directory for generated clients", DEFAULT_CONFIG.source);
31
+ const relaysStr = await askQuestion("Enter the relays to connect to (comma-separated)", DEFAULT_CONFIG.relays.join(", "));
32
+ const relays = relaysStr.split(",").map((r) => r.trim());
33
+ closeReadlineInterface();
34
+ const config = {
35
+ source,
36
+ relays,
37
+ };
38
+ await fs.writeFile(configPath, JSON.stringify(config, null, 2));
39
+ console.log("\nāœ”ļø Configuration file `ctxcn.config.json` created successfully.");
40
+ const sourceDir = path.join(cwd, config.source);
41
+ try {
42
+ await fs.access(sourceDir);
43
+ }
44
+ catch (error) {
45
+ await fs.mkdir(sourceDir, { recursive: true });
46
+ console.log(`āœ”ļø Source directory \`${config.source}\` created.`);
47
+ }
48
+ console.log("\nšŸ“¦ Checking for required dependencies...");
49
+ const packageJsonContent = await fs.readFile(packageJsonPath, "utf-8");
50
+ const packageJson = JSON.parse(packageJsonContent);
51
+ const dependencies = packageJson.dependencies || {};
52
+ const devDependencies = packageJson.devDependencies || {};
53
+ if (!dependencies["@contextvm/sdk"] && !devDependencies["@contextvm/sdk"]) {
54
+ console.warn("āš ļø The `@contextvm/sdk` dependency is not found in your `package.json`. Please install it to ensure the generated client works correctly.");
55
+ }
56
+ else {
57
+ console.log("āœ”ļø The `@contextvm/sdk` dependency is already installed.");
58
+ }
59
+ console.log("\nāœ… Project initialization complete. You can now use the `add` command.");
60
+ }
61
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAe,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEnE,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW;IAC1C,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IAEpD,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;IACnD,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IACvD,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAC;IACxE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CACX,4FAA4F,CAC7F,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IACvD,IAAI,CAAC;QACH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,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,OAAO,CAAC,GAAG,CAAC,yBAAyB,MAAM,CAAC,MAAM,aAAa,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAC1D,MAAM,kBAAkB,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACnD,MAAM,YAAY,GAAG,WAAW,CAAC,YAAY,IAAI,EAAE,CAAC;IACpD,MAAM,eAAe,GAAG,WAAW,CAAC,eAAe,IAAI,EAAE,CAAC;IAE1D,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC1E,OAAO,CAAC,IAAI,CACV,2IAA2I,CAC5I,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO,CAAC,GAAG,CACT,yEAAyE,CAC1E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function handleUpdate(cwd: string, pubkey?: string): Promise<void>;
2
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/commands/update.ts"],"names":[],"mappings":"AA6BA,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,iBA8E9D"}