@runtypelabs/cli 0.2.4 → 0.2.6

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/dist/index.js CHANGED
@@ -158,6 +158,8 @@ init_cjs_shims();
158
158
  var import_commander20 = require("commander");
159
159
  var import_chalk24 = __toESM(require("chalk"));
160
160
  var import_dotenv = require("dotenv");
161
+ var import_fs7 = require("fs");
162
+ var import_path4 = require("path");
161
163
 
162
164
  // src/commands/auth.ts
163
165
  init_cjs_shims();
@@ -186,20 +188,19 @@ var CallbackServer = class {
186
188
  this.codeReject = reject;
187
189
  });
188
190
  this.app.get("/callback", (req, res) => {
189
- const { token, code, error } = req.query;
191
+ const { token, error } = req.query;
190
192
  if (error) {
191
193
  res.send(this.errorHTML(error));
192
194
  this.codeReject(new Error(error));
193
195
  return;
194
196
  }
195
- const authToken = token || code;
196
- if (!authToken) {
197
+ if (!token) {
197
198
  res.send(this.errorHTML("No authentication token received"));
198
199
  this.codeReject(new Error("No authentication token received"));
199
200
  return;
200
201
  }
201
202
  res.send(this.successHTML());
202
- this.codeResolve(authToken);
203
+ this.codeResolve(token);
203
204
  setTimeout(() => this.stop(), 1e3);
204
205
  });
205
206
  this.app.get("/health", (_req, res) => {
@@ -2136,7 +2137,9 @@ var talkCommand = new import_commander6.Command("talk").description("Start an in
2136
2137
  console.log(import_chalk10.default.gray("\nAssistant> ") + import_chalk10.default.gray("Thinking..."));
2137
2138
  try {
2138
2139
  const payload = session.buildDispatchPayload(trimmed);
2139
- const response = await fetch(`${apiUrl}/dispatch`, {
2140
+ const version = getApiVersion();
2141
+ const dispatchUrl = `${apiUrl.replace(/\/$/, "")}/${version}/dispatch`;
2142
+ const response = await fetch(dispatchUrl, {
2140
2143
  method: "POST",
2141
2144
  headers: {
2142
2145
  Authorization: `Bearer ${apiKey}`,
@@ -2158,7 +2161,16 @@ var talkCommand = new import_commander6.Command("talk").description("Start an in
2158
2161
  } catch (error) {
2159
2162
  process.stdout.write("\x1B[1A\x1B[2K");
2160
2163
  const message = error instanceof Error ? error.message : "Unknown error";
2161
- console.error(import_chalk10.default.red(`Error: ${message}`));
2164
+ const cause = error instanceof Error && error.cause instanceof Error ? error.cause.message : error instanceof Error && typeof error.cause === "string" ? error.cause : null;
2165
+ console.error(import_chalk10.default.red(`Error: ${message}${cause ? ` (${cause})` : ""}`));
2166
+ if (message === "fetch failed") {
2167
+ const apiUrl2 = getApiUrl();
2168
+ console.error(
2169
+ import_chalk10.default.gray(
2170
+ `Tip: Request to ${apiUrl2} failed. If using a local API, set RUNTYPE_API_URL (e.g. http://localhost:8787) and run \`pnpm dev:api\` or \`pnpm dev:bun\`.`
2171
+ )
2172
+ );
2173
+ }
2162
2174
  rl.prompt();
2163
2175
  }
2164
2176
  });
@@ -4498,8 +4510,17 @@ flowVersionsCommand.command("publish <flowId>").description("Publish a version")
4498
4510
  // src/index.ts
4499
4511
  init_credential_store();
4500
4512
  (0, import_dotenv.config)();
4513
+ function getPackageVersion() {
4514
+ try {
4515
+ const pkgPath = (0, import_path4.join)(__dirname, "..", "package.json");
4516
+ const pkg = JSON.parse((0, import_fs7.readFileSync)(pkgPath, "utf-8"));
4517
+ return pkg.version || "0.0.0";
4518
+ } catch {
4519
+ return "0.0.0";
4520
+ }
4521
+ }
4501
4522
  var program = new import_commander20.Command();
4502
- program.name("runtype").description("CLI for Runtype AI Platform").version("0.1.0").option("-v, --verbose", "Enable verbose output").option("--api-url <url>", "Override API URL").option("--json", "Output in JSON format");
4523
+ program.name("runtype").description("CLI for Runtype AI Platform").version(getPackageVersion()).option("-v, --verbose", "Enable verbose output").option("--api-url <url>", "Override API URL").option("--json", "Output in JSON format");
4503
4524
  program.addCommand(initCommand);
4504
4525
  program.addCommand(authCommand);
4505
4526
  program.addCommand(flowsCommand);
@@ -4536,7 +4557,7 @@ try {
4536
4557
  } else if (commanderError.code === "commander.unknownOption") {
4537
4558
  console.error(import_chalk24.default.red(`Error: ${commanderError.message}`));
4538
4559
  process.exit(1);
4539
- } else if (commanderError.code === "commander.help") {
4560
+ } else if (commanderError.code === "commander.help" || commanderError.code === "commander.version") {
4540
4561
  process.exit(0);
4541
4562
  } else {
4542
4563
  console.error(import_chalk24.default.red("An unexpected error occurred:"));