@optima-chat/browser-cli 0.1.0 → 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.
Files changed (2) hide show
  1. package/dist/index.js +25 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,7 +4,26 @@
4
4
  import { Command } from "commander";
5
5
 
6
6
  // src/config.ts
7
- var BROWSER_API_URL = process.env.BROWSER_API_URL || "http://localhost:7292";
7
+ import { readFileSync, existsSync } from "fs";
8
+ import { join } from "path";
9
+ import { homedir } from "os";
10
+ var TOKEN_PATH = join(homedir(), ".optima", "token.json");
11
+ var BACKEND_URLS = {
12
+ ci: "https://browser-api.stage.optima.onl",
13
+ stage: "https://browser-api.stage.optima.onl",
14
+ prod: "https://browser-api.optima.onl"
15
+ };
16
+ function loadTokenData() {
17
+ if (!existsSync(TOKEN_PATH)) return null;
18
+ try {
19
+ return JSON.parse(readFileSync(TOKEN_PATH, "utf-8"));
20
+ } catch {
21
+ return null;
22
+ }
23
+ }
24
+ var tokenData = loadTokenData();
25
+ var BROWSER_API_URL = process.env.BROWSER_API_URL || (tokenData ? BACKEND_URLS[tokenData.env] : null) || "http://localhost:7292";
26
+ var ACCESS_TOKEN = tokenData?.access_token || null;
8
27
 
9
28
  // src/api.ts
10
29
  var BrowserAPIError = class extends Error {
@@ -23,6 +42,7 @@ async function request(path, options = {}) {
23
42
  ...options,
24
43
  headers: {
25
44
  "Content-Type": "application/json",
45
+ ...ACCESS_TOKEN ? { Authorization: `Bearer ${ACCESS_TOKEN}` } : {},
26
46
  ...options.headers
27
47
  }
28
48
  });
@@ -171,21 +191,21 @@ var BrowserAPI = class {
171
191
  var api = new BrowserAPI();
172
192
 
173
193
  // src/session.ts
174
- import { readFileSync, writeFileSync, unlinkSync, existsSync } from "fs";
194
+ import { readFileSync as readFileSync2, writeFileSync, unlinkSync, existsSync as existsSync2 } from "fs";
175
195
  var SESSION_FILE = "/tmp/browser-session-id";
176
196
  function saveSessionId(id) {
177
197
  writeFileSync(SESSION_FILE, id, "utf-8");
178
198
  }
179
199
  function loadSessionId() {
180
- if (!existsSync(SESSION_FILE)) {
200
+ if (!existsSync2(SESSION_FILE)) {
181
201
  throw new Error(
182
202
  "No active browser session. Run 'browser-cli launch' first."
183
203
  );
184
204
  }
185
- return readFileSync(SESSION_FILE, "utf-8").trim();
205
+ return readFileSync2(SESSION_FILE, "utf-8").trim();
186
206
  }
187
207
  function clearSessionId() {
188
- if (existsSync(SESSION_FILE)) {
208
+ if (existsSync2(SESSION_FILE)) {
189
209
  unlinkSync(SESSION_FILE);
190
210
  }
191
211
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optima-chat/browser-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "browser-cli": "./dist/index.js"