flyspace-cli 0.1.18 → 0.1.19

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.
@@ -1,6 +1,28 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // src/profile.ts
3
+ // ../api/src/store/supabase-client.ts
4
+ var client;
5
+ var factory;
6
+ function setSupabaseClient(replacement) {
7
+ client = replacement;
8
+ }
9
+ function setSupabaseClientFactory(create) {
10
+ factory = create;
11
+ }
12
+ function hasSupabaseCredentials() {
13
+ return !!process.env["SUPABASE_URL"] && !!process.env["SUPABASE_SECRET_KEY"];
14
+ }
15
+ function databaseReachable() {
16
+ return !!client || !!factory && hasSupabaseCredentials();
17
+ }
18
+ function getSupabaseClient() {
19
+ if (client) return client;
20
+ if (!factory) throw new Error("No Supabase client installed in this process");
21
+ client = factory();
22
+ return client;
23
+ }
24
+
25
+ // ../api/src/profile.ts
4
26
  import { AsyncLocalStorage } from "async_hooks";
5
27
  var PROFILE_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
6
28
  var DEFAULT_PROFILE = "default";
@@ -24,13 +46,14 @@ function getProfile() {
24
46
  return validateProfile(process.env["FLYSPACE_WORKSPACE"]);
25
47
  }
26
48
 
27
- // src/paths.ts
49
+ // ../api/src/paths.ts
28
50
  import { existsSync, mkdirSync, readdirSync, rmSync, statSync } from "fs";
29
51
  import { homedir } from "os";
30
- import { join, resolve } from "path";
52
+ import { basename, join, resolve } from "path";
31
53
  var home = homedir();
32
54
  var XDG_CONFIG_HOME = process.env["XDG_CONFIG_HOME"] || join(home, ".config");
33
55
  var XDG_DATA_HOME = process.env["XDG_DATA_HOME"] || join(home, ".local", "share");
56
+ var OWN_ROOT = resolve(import.meta.dirname, "..");
34
57
  var paths = {
35
58
  /** Profile-independent config root: `~/.config/flyspace`. */
36
59
  get BASE_CONFIG_DIR() {
@@ -115,7 +138,15 @@ var paths = {
115
138
  get DASHBOARD_SETTINGS_FILE() {
116
139
  return join(this.CONFIG_DIR, "dashboard-settings.json");
117
140
  },
118
- PACKAGE_ROOT: resolve(import.meta.dirname, "..")
141
+ /** Where the CLI's shipped files live (`system.default.md`, `hooks/`,
142
+ * `templates/`, its `node_modules`): packages/host in a checkout, the
143
+ * installed `flyspace-cli` otherwise. This module lives in packages/api, so
144
+ * an unbundled run (tsx, vitest) resolves to the host package next to it;
145
+ * the Fly images ship no host package and keep their own root. */
146
+ PACKAGE_ROOT: basename(OWN_ROOT) === "api" && existsSync(join(OWN_ROOT, "..", "host", "package.json")) ? resolve(OWN_ROOT, "..", "host") : OWN_ROOT,
147
+ /** packages/ui: the SPA source and its `dist/`. Only a checkout (or the
148
+ * share image) has it; the npm-installed CLI ships no UI. */
149
+ WEB_ROOT: resolve(OWN_ROOT, "..", "ui")
119
150
  };
120
151
  function ensureDirs() {
121
152
  for (const dir of [
@@ -147,36 +178,7 @@ function sweepScratchDir(now = Date.now()) {
147
178
  return removed;
148
179
  }
149
180
 
150
- // src/store/supabase-client.ts
151
- import { createClient } from "@supabase/supabase-js";
152
- var REQUEST_TIMEOUT_MS = 15e3;
153
- var client;
154
- function setSupabaseClient(replacement) {
155
- client = replacement;
156
- }
157
- function hasSupabaseCredentials() {
158
- return !!process.env["SUPABASE_URL"] && !!process.env["SUPABASE_SECRET_KEY"];
159
- }
160
- function databaseReachable() {
161
- return !!client || hasSupabaseCredentials();
162
- }
163
- function getSupabaseClient() {
164
- if (client) return client;
165
- const url = process.env["SUPABASE_URL"];
166
- const key = process.env["SUPABASE_SECRET_KEY"];
167
- if (!url || !key) {
168
- throw new Error("SUPABASE_URL / SUPABASE_SECRET_KEY not set \u2014 check .env");
169
- }
170
- client = createClient(url, key, {
171
- auth: { persistSession: false },
172
- global: {
173
- fetch: (input, init) => fetch(input, { ...init, signal: init?.signal ?? AbortSignal.timeout(REQUEST_TIMEOUT_MS) })
174
- }
175
- });
176
- return client;
177
- }
178
-
179
- // src/store/authors.ts
181
+ // ../api/src/store/authors.ts
180
182
  var AGENT_AUTHOR = "agent";
181
183
  var SYNCED_BOT_AUTHOR = "Bot";
182
184
  var LEGACY_BOT_AUTHOR = "Custie";
@@ -187,13 +189,13 @@ function isHumanAuthor(author) {
187
189
  return !NON_HUMAN_AUTHORS.has(author.toLowerCase());
188
190
  }
189
191
 
190
- // src/dashboard/attachment-uploader.ts
192
+ // ../api/src/dashboard/attachment-uploader.ts
191
193
  import { randomUUID } from "crypto";
192
194
  import { readFile, stat } from "fs/promises";
193
- import { basename } from "path";
195
+ import { basename as basename2 } from "path";
194
196
  import { PutObjectCommand } from "@aws-sdk/client-s3";
195
197
 
196
- // src/store/r2-client.ts
198
+ // ../api/src/store/r2-client.ts
197
199
  import { ListObjectsV2Command, S3Client } from "@aws-sdk/client-s3";
198
200
  var client2;
199
201
  function getR2Client() {
@@ -229,7 +231,7 @@ async function sumR2PrefixBytes(prefix) {
229
231
  return total;
230
232
  }
231
233
 
232
- // src/dashboard/attachment-uploader.ts
234
+ // ../api/src/dashboard/attachment-uploader.ts
233
235
  var debug = process.env["DEBUG"] === "true";
234
236
  var LOCAL_IMAGE_LINK = /!\[([^\]]*)\]\((\/[^)\s]+)\)/g;
235
237
  var SCRATCH_VAR_IN_IMAGE_LINK = /(!\[[^\]]*\]\()\$\{?FLYSPACE_SCRATCH_DIR\}?(?=\/)/g;
@@ -277,7 +279,7 @@ async function uploadOne(path) {
277
279
  console.error(`[attachment-uploader] ${path} is ${info.size} bytes, over the ${MAX_FILE_BYTES} limit`);
278
280
  return null;
279
281
  }
280
- const key = `${SCRATCH_PREFIX}/${getProfile()}/${randomUUID()}-${sanitizeFilename(basename(path))}`;
282
+ const key = `${SCRATCH_PREFIX}/${getProfile()}/${randomUUID()}-${sanitizeFilename(basename2(path))}`;
281
283
  await getR2Client().send(
282
284
  new PutObjectCommand({
283
285
  Bucket: getR2Bucket(),
@@ -425,16 +427,17 @@ async function createThread(supabase, channelId, text, title) {
425
427
  }
426
428
 
427
429
  export {
430
+ setSupabaseClient,
431
+ setSupabaseClientFactory,
432
+ hasSupabaseCredentials,
433
+ databaseReachable,
434
+ getSupabaseClient,
428
435
  DEFAULT_PROFILE,
429
436
  runWithProfile,
430
437
  getProfile,
431
438
  paths,
432
439
  ensureDirs,
433
440
  sweepScratchDir,
434
- setSupabaseClient,
435
- hasSupabaseCredentials,
436
- databaseReachable,
437
- getSupabaseClient,
438
441
  AGENT_AUTHOR,
439
442
  SYNCED_BOT_AUTHOR,
440
443
  isHumanAuthor,