react-detective 0.0.0-stage → 0.1.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.
@@ -0,0 +1,25 @@
1
+ import {
2
+ reloadingHandler
3
+ } from "./chunk-5TDNB3DH.js";
4
+
5
+ // src/server/index.ts
6
+ import http from "http";
7
+ var DEFAULT_PORT = 5899;
8
+ function startDetectiveServer(opts) {
9
+ const port = opts.port ?? DEFAULT_PORT;
10
+ const handler = reloadingHandler(opts);
11
+ const server = http.createServer((req, res) => void handler(req, res));
12
+ return new Promise((resolve, reject) => {
13
+ server.once("error", (err) => err.code === "EADDRINUSE" ? resolve(null) : reject(err));
14
+ server.listen(port, "127.0.0.1", () => {
15
+ server.unref();
16
+ if (!opts.silent) console.log(`[react-detective] explain server on http://127.0.0.1:${port}`);
17
+ resolve(server);
18
+ });
19
+ });
20
+ }
21
+
22
+ export {
23
+ DEFAULT_PORT,
24
+ startDetectiveServer
25
+ };
@@ -0,0 +1,43 @@
1
+ // src/server/env.ts
2
+ import fs from "fs";
3
+ import path from "path";
4
+ var ENV_FILES = [".env.development.local", ".env.local", ".env.development", ".env"];
5
+ function findApiKey(root) {
6
+ if (process.env.ANTHROPIC_API_KEY) return process.env.ANTHROPIC_API_KEY;
7
+ for (const name of ENV_FILES) {
8
+ let text;
9
+ try {
10
+ text = fs.readFileSync(path.join(root, name), "utf8");
11
+ } catch {
12
+ continue;
13
+ }
14
+ const value = parseEnv(text).ANTHROPIC_API_KEY;
15
+ if (value) return value;
16
+ }
17
+ return void 0;
18
+ }
19
+ function parseEnv(text) {
20
+ const out = {};
21
+ for (const raw of text.split(/\r?\n/)) {
22
+ const m = raw.match(/^\s*(?:export\s+)?([A-Za-z_][\w.]*)\s*=\s*(.*)$/);
23
+ if (!m) continue;
24
+ let value = m[2].trim();
25
+ const quoted = value.match(/^(["'`])([\s\S]*)\1$/);
26
+ if (quoted) value = quoted[2];
27
+ else value = value.replace(/\s+#.*$/, "");
28
+ out[m[1]] = value;
29
+ }
30
+ return out;
31
+ }
32
+ var MISSING_KEY_MESSAGE = (root) => `React Detective needs an Anthropic API key to write new explanations and answers.
33
+
34
+ Add this line to .env.local in ${root} (create the file if needed, and make sure it's in .gitignore):
35
+
36
+ ANTHROPIC_API_KEY=sk-ant-...
37
+
38
+ Get a key at https://console.anthropic.com/settings/keys. No restart needed: just try again. Saved explanations and answers keep working without a key.`;
39
+
40
+ export {
41
+ findApiKey,
42
+ MISSING_KEY_MESSAGE
43
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// node_modules/tsup/assets/cjs_shims.js
2
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
3
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
4
+
5
+
6
+
7
+ exports.importMetaUrl = importMetaUrl;
package/dist/cli.js ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ DEFAULT_PORT,
4
+ startDetectiveServer
5
+ } from "./chunk-6EJCTAJS.js";
6
+ import "./chunk-5TDNB3DH.js";
7
+ import "./chunk-E23QXCCY.js";
8
+
9
+ // src/cli.ts
10
+ import { parseArgs } from "util";
11
+ if (process.argv[2] === "init") {
12
+ const { runInit } = await import("./init-JUCWNJPS.js");
13
+ await runInit(process.argv.slice(3));
14
+ process.exit();
15
+ }
16
+ var { values } = parseArgs({
17
+ options: {
18
+ port: { type: "string", short: "p" },
19
+ root: { type: "string", short: "r" },
20
+ model: { type: "string", short: "m" },
21
+ help: { type: "boolean", short: "h" }
22
+ }
23
+ });
24
+ if (values.help) {
25
+ console.log(`Usage: react-detective init set up React Detective in this project
26
+ react-detective [--port ${DEFAULT_PORT}] [--root .] [--model sonnet|haiku|opus|<id>]`);
27
+ process.exit(0);
28
+ }
29
+ var port = values.port ? Number(values.port) : DEFAULT_PORT;
30
+ var server = await startDetectiveServer({ root: values.root ?? process.cwd(), port, model: values.model });
31
+ if (!server) {
32
+ console.error(`[react-detective] port ${port} is already in use`);
33
+ process.exit(1);
34
+ }
35
+ server.ref();
@@ -0,0 +1,9 @@
1
+ interface DetectiveClientOptions {
2
+ /** Base URL of the explain server, e.g. `/__detective` (Vite) or `http://127.0.0.1:5899/__detective`. */
3
+ endpoint: string;
4
+ /** Show the small launcher pill in the corner. Default true. */
5
+ showLauncher?: boolean;
6
+ }
7
+ declare function init(options: DetectiveClientOptions): () => void;
8
+
9
+ export { type DetectiveClientOptions, init };