flyspace-cli 0.1.59 → 0.1.60

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/cli.js CHANGED
@@ -2,7 +2,6 @@
2
2
  import { createRequire as __flyspaceCreateRequire } from 'node:module';
3
3
  const require = __flyspaceCreateRequire(import.meta.url);
4
4
  import {
5
- AuthApiError,
6
5
  AutomationManager,
7
6
  BOT_DM_KEY,
8
7
  BOT_LABEL,
@@ -11,30 +10,24 @@ import {
11
10
  BUILT_IN_OUTPUT_STYLES,
12
11
  CLI_VERSION,
13
12
  ChatAgent,
14
- DEFAULT_API_URL,
15
13
  DEFAULT_TIMEZONE,
16
14
  DocShareSlugTakenError,
17
15
  HANDLE_PATTERN,
18
16
  HandleTakenError,
19
17
  InvalidTransferError,
20
- LOCAL_DB_PATH,
21
18
  LastAdminError,
22
19
  MEMORY_TYPES,
23
20
  OutputStyleConflictError,
24
21
  PLATE,
25
22
  SKIP_SUBTYPES,
26
- SLACK_ENV,
27
23
  SUPPORT_AVATAR_URL,
28
24
  TRANSLATION_LANGUAGES,
29
25
  TRIAL_DAYS,
30
26
  UsageStore,
31
- acquireHostLock,
32
27
  agentViewer,
33
- apiUrl,
34
28
  authorFor,
35
29
  blockToFallbackText,
36
30
  bodyTextFor,
37
- boundWorkspaces,
38
31
  buildAuthorizeUrl,
39
32
  buildAutoTitle,
40
33
  cachedProfileConfig,
@@ -42,7 +35,6 @@ import {
42
35
  channelSkillsDir,
43
36
  claudeAuthFailed,
44
37
  clearClaudeAuthFailed,
45
- clearLocalAuth,
46
38
  clientKey,
47
39
  codexAuthAvailable,
48
40
  consumeOAuthState,
@@ -50,7 +42,6 @@ import {
50
42
  createDocShare,
51
43
  createDocsRouter,
52
44
  createFeatureFlagsRouter,
53
- createHostDbClient,
54
45
  createMembership,
55
46
  createOAuthState,
56
47
  createOutputStyle,
@@ -62,7 +53,6 @@ import {
62
53
  createStateToken,
63
54
  createTtsRouter,
64
55
  createWorkspace,
65
- credentialsPath,
66
56
  crossOriginShell,
67
57
  defaultClaudeCwd,
68
58
  defaultEffort,
@@ -78,25 +68,21 @@ import {
78
68
  deleteWorkspaceDomain,
79
69
  deriveConnectionSlug,
80
70
  detectSourceLanguage,
81
- deviceKeyPath,
82
71
  displayNameFor,
83
72
  dropShareAudio,
84
73
  dropShareLangAudioKeys,
85
74
  effectiveModel,
86
- ensureDeviceKey,
87
75
  ensureUsersCached,
88
76
  escalateToHuman,
89
77
  exchangeCode,
90
78
  explainCost,
91
79
  extractCategories,
92
80
  extractTitle,
93
- fetchWhoAmI,
94
81
  filterReadableDocsChannels,
95
82
  findDocShareBySource,
96
83
  findOwningProfile,
97
84
  findSkillDetail,
98
85
  flatDocs,
99
- getAccessToken,
100
86
  getAgentPaused,
101
87
  getAllowGuestAccess,
102
88
  getChannelDocsMemberAccess,
@@ -119,10 +105,6 @@ import {
119
105
  getWorkspaceOwnPersona,
120
106
  getWorkspacePermissionMode,
121
107
  getWorkspacePlanStatus,
122
- handleAttachmentUrlResult,
123
- handleHostDbResult,
124
- handlePluginSvgResult,
125
- handleShouldRespondResult,
126
108
  handleSupportMention,
127
109
  highlightLanguageOf,
128
110
  insertMcpConnection,
@@ -166,11 +148,8 @@ import {
166
148
  loadAutomations,
167
149
  loadBotIdentity,
168
150
  loadChatAgentConfig,
169
- loadConfig,
170
- loadCredentials,
171
151
  loadDashboardSettings,
172
152
  loadEffectiveAutomations,
173
- loadEnvFiles,
174
153
  loadFullDashboardSettings,
175
154
  loadWorkspaceBranding,
176
155
  loadWorkspacePrompt,
@@ -182,15 +161,12 @@ import {
182
161
  mentionedUserIds,
183
162
  onboardingPending,
184
163
  pinnedClaudeConfigDir,
185
- pollDeviceToken,
186
164
  profileClaudeConfigDir,
187
165
  profileEnv,
188
166
  profileFromHost,
189
167
  profileOauthToken,
190
168
  promoteChannelMemory,
191
- publishHostEndpoint,
192
169
  queueShareAudio,
193
- readHostEndpoint,
194
170
  readOAuthClient,
195
171
  readSkillFile,
196
172
  recentRunsForWorkspace,
@@ -199,10 +175,7 @@ import {
199
175
  refreshUserCache,
200
176
  removeChannelMember,
201
177
  renderAppIcon,
202
- requestDeviceCode,
203
- requestHostDb,
204
178
  requireDocsAccess,
205
- requireSlackBotToken,
206
179
  resetWorkspaceOnboarding,
207
180
  resetWorkspacePrompt,
208
181
  resolveAuthContext,
@@ -213,7 +186,6 @@ import {
213
186
  resolveRateCard,
214
187
  resolveRawPath,
215
188
  resolveUserId,
216
- revokeDevice,
217
189
  revokeDocShare,
218
190
  rowToMemory,
219
191
  runAutomation,
@@ -224,7 +196,6 @@ import {
224
196
  saveAgentProfile,
225
197
  saveBotIdentity,
226
198
  saveChannelMemory,
227
- saveCredentials,
228
199
  saveDashboardSettings,
229
200
  saveMemory,
230
201
  saveWorkspaceBranding,
@@ -237,7 +208,6 @@ import {
237
208
  setChannelDocsMemberAccess,
238
209
  setDocShareSlug,
239
210
  setDocShareTags,
240
- setHostDbSender,
241
211
  setMcpConnectionApiKey,
242
212
  setMembershipHandle,
243
213
  setMemoryAutoPaused,
@@ -248,7 +218,6 @@ import {
248
218
  setWorkspaceOwnPersona,
249
219
  setWorkspacePermissionMode,
250
220
  setWorkspaceStripeSubscription,
251
- slackConfigured,
252
221
  slackMrkdwnToMarkdown,
253
222
  startAutomationRegistryPolling,
254
223
  startServer,
@@ -274,13 +243,12 @@ import {
274
243
  usageLimitedModels,
275
244
  usageLimitedUntil,
276
245
  useDirectSupabase,
277
- useHostDbWithoutCredentials,
278
246
  useLocalCache,
279
247
  validateMemoryInput,
280
248
  workspaceHostname,
281
249
  workspaceSkillsDir,
282
250
  writeSkillFile
283
- } from "./chunk-7W5FEG63.js";
251
+ } from "./chunk-SIR6PTDT.js";
284
252
  import {
285
253
  canReadThread,
286
254
  firstReplyBody,
@@ -289,53 +257,89 @@ import {
289
257
  listThreads,
290
258
  moveThreadFully,
291
259
  resolveChannel,
292
- resolveThreadOwner
293
- } from "./chunk-44WHW7NK.js";
260
+ resolveThreadOwner,
261
+ runDocsCmd
262
+ } from "./chunk-PXZUNZ4S.js";
294
263
  import {
295
264
  AGENT_AUTHOR,
265
+ AuthApiError,
296
266
  ChannelCwdError,
267
+ DEFAULT_API_URL,
297
268
  DEFAULT_PROFILE,
298
269
  DefaultChannelError,
270
+ LOCAL_DB_PATH,
271
+ LOCAL_DOC_SHARE_PATH,
299
272
  SCRATCH_PREFIX,
273
+ SLACK_ENV,
300
274
  SessionStore,
275
+ acquireHostLock,
276
+ apiUrl,
301
277
  auditChannelCwds,
278
+ boundWorkspaces,
302
279
  canSeeChannel,
280
+ clearLocalAuth,
303
281
  createChannel,
282
+ createHostDbClient,
283
+ credentialsPath,
304
284
  databaseReachable,
285
+ deviceKeyPath,
305
286
  ensureAgentDmChannel,
287
+ ensureDeviceKey,
306
288
  ensureDirs,
307
289
  ensureGeneralChannel,
308
290
  ensureMemberDmChannel,
309
291
  expandPath,
292
+ fetchWhoAmI,
310
293
  findChannel,
311
294
  findChannelById,
295
+ getAccessToken,
312
296
  getChannelRegistry,
313
297
  getProfile,
314
298
  getProfileChannelRegistry,
315
299
  getR2Bucket,
316
300
  getR2Client,
317
301
  getSupabaseClient,
302
+ handleAttachmentUrlResult,
303
+ handleDocShareResult,
304
+ handleHostDbResult,
305
+ handlePluginSvgResult,
306
+ handleShouldRespondResult,
318
307
  isCwdUsable,
319
308
  isEffort,
320
309
  isHumanAuthor,
321
310
  isLogicalCwd,
322
311
  isPermissionMode,
323
312
  isUnderLogicalRoot,
313
+ loadConfig,
314
+ loadCredentials,
315
+ loadEnvFiles,
324
316
  markChannelGreeted,
325
317
  paths,
318
+ pollDeviceToken,
326
319
  postToDashboardChannel,
320
+ publishHostEndpoint,
321
+ readHostEndpoint,
327
322
  refreshChannelRegistry,
323
+ requestDeviceCode,
324
+ requestDocShare,
325
+ requestHostDb,
326
+ requireSlackBotToken,
328
327
  resolveCwd,
329
328
  resolveDashboardChannelId,
329
+ revokeDevice,
330
330
  runWithProfile,
331
+ saveCredentials,
332
+ setHostDbSender,
331
333
  setSupabaseClient,
334
+ slackConfigured,
332
335
  startChannelRegistryPolling,
333
336
  sumR2PrefixBytes,
334
337
  syncPostToDashboard,
335
338
  updateChannelById,
336
339
  updateChannelsMcpConnections,
340
+ useHostDbWithoutCredentials,
337
341
  warnOnBrokenChannelCwds
338
- } from "./chunk-XACRG7BO.js";
342
+ } from "./chunk-XYS7SVWC.js";
339
343
 
340
344
  // ../core/src/logger.ts
341
345
  var ALREADY_STAMPED = /^\[\d{4}-\d{2}-\d{2}T/;
@@ -2192,7 +2196,7 @@ function npmEnv(target) {
2192
2196
  return nodeBin ? { ...process.env, PATH: `${nodeBin}:${process.env.PATH ?? ""}` } : process.env;
2193
2197
  }
2194
2198
  async function runUpgrade() {
2195
- const current = "0.1.59";
2199
+ const current = "0.1.60";
2196
2200
  console.log(`Current version: ${current}`);
2197
2201
  console.log("Checking for updates...\n");
2198
2202
  try {
@@ -6104,7 +6108,7 @@ Usage: flyspace mcp <server>
6104
6108
  Servers:
6105
6109
  threads Search, read, and write this workspace's chat threads
6106
6110
  (search_threads, read_thread, list_channels, create_thread,
6107
- post_reply, move_thread)
6111
+ post_reply, move_thread, share_doc)
6108
6112
 
6109
6113
  Try it by hand (type a JSON-RPC line, or pipe one in):
6110
6114
  flyspace mcp threads
@@ -6120,7 +6124,7 @@ async function runMcpCmd(args) {
6120
6124
  useHostDbWithoutCredentials();
6121
6125
  switch (server) {
6122
6126
  case "threads": {
6123
- const { startThreadsServer } = await import("./threads-I52LSA5X.js");
6127
+ const { startThreadsServer } = await import("./threads-QQRWT3OM.js");
6124
6128
  await startThreadsServer();
6125
6129
  return;
6126
6130
  }
@@ -6537,7 +6541,7 @@ async function userEmail(userId) {
6537
6541
  }
6538
6542
 
6539
6543
  // ../api/src/dashboard/agent-bridge-data.ts
6540
- import { randomBytes as randomBytes4, randomUUID as randomUUID2, verify as verifyRaw } from "crypto";
6544
+ import { randomBytes as randomBytes5, randomUUID as randomUUID2, verify as verifyRaw } from "crypto";
6541
6545
  import { WebSocket, WebSocketServer } from "ws";
6542
6546
 
6543
6547
  // ../api/src/dashboard/host-identity.ts
@@ -6637,6 +6641,187 @@ function createUploadsRouter() {
6637
6641
  return app;
6638
6642
  }
6639
6643
 
6644
+ // ../api/src/dashboard/doc-share-publish.ts
6645
+ import { randomBytes as randomBytes4 } from "crypto";
6646
+ import { CopyObjectCommand, PutObjectCommand as PutObjectCommand2 } from "@aws-sdk/client-s3";
6647
+
6648
+ // ../api/src/dashboard/bridge-types.ts
6649
+ var SHARE_ASSET_PLACEHOLDER = "/share/{{flyspace-share-id}}/assets/";
6650
+
6651
+ // ../api/src/dashboard/doc-share-features.ts
6652
+ import { DeleteObjectCommand } from "@aws-sdk/client-s3";
6653
+ var DEFAULT_FEATURES = {
6654
+ audioEnabled: false,
6655
+ askEnabled: true,
6656
+ socialEnabled: false,
6657
+ brandingEnabled: true,
6658
+ translationEnabled: false,
6659
+ translationLangs: []
6660
+ };
6661
+ var HTML_FEATURES = {
6662
+ audioEnabled: false,
6663
+ askEnabled: false,
6664
+ socialEnabled: false,
6665
+ brandingEnabled: false,
6666
+ translationEnabled: false,
6667
+ translationLangs: []
6668
+ };
6669
+ function resolveFeatures(requested, existing) {
6670
+ const base = existing ?? DEFAULT_FEATURES;
6671
+ return {
6672
+ audioEnabled: requested?.audio ?? base.audioEnabled,
6673
+ askEnabled: requested?.ask ?? base.askEnabled,
6674
+ socialEnabled: requested?.social ?? base.socialEnabled,
6675
+ brandingEnabled: requested?.branding ?? base.brandingEnabled,
6676
+ translationEnabled: requested?.translation ?? base.translationEnabled,
6677
+ // Replaced wholesale, not merged: the allowlist IS the answer to "which
6678
+ // languages does this link offer", and a merge would make removing one
6679
+ // impossible.
6680
+ translationLangs: requested?.translationLangs ?? base.translationLangs
6681
+ };
6682
+ }
6683
+ async function deleteShareAssets(keys) {
6684
+ const client2 = getR2Client();
6685
+ const bucket = getR2Bucket();
6686
+ for (const key of keys) {
6687
+ try {
6688
+ await client2.send(new DeleteObjectCommand({ Bucket: bucket, Key: key }));
6689
+ } catch {
6690
+ }
6691
+ }
6692
+ }
6693
+ async function updateShareFeatures(share, requested) {
6694
+ if (share.kind === "html") return share;
6695
+ if (share.kind === "excalidraw") {
6696
+ if (requested.branding === void 0) return share;
6697
+ return updateDocShareFeatures(share.id, { ...share, brandingEnabled: requested.branding });
6698
+ }
6699
+ const features = resolveFeatures(requested, share);
6700
+ const updated = await updateDocShareFeatures(share.id, features);
6701
+ if (!updated) return null;
6702
+ if (features.audioEnabled) void queueShareAudio(updated);
6703
+ else if (share.audioEnabled) await dropShareAudio(share);
6704
+ return updated;
6705
+ }
6706
+
6707
+ // ../api/src/dashboard/doc-share-publish.ts
6708
+ var SHARE_KEY_PREFIX = "share";
6709
+ function generateShareId() {
6710
+ return randomBytes4(9).toString("base64url");
6711
+ }
6712
+ async function publishDocShare(input2, readBundle) {
6713
+ const bundle = await readBundle({ channelId: input2.channelId, cwd: input2.cwd, sourcePath: input2.sourcePath });
6714
+ if (bundle.status !== "ok") return bundle;
6715
+ const existing = await findDocShareBySource(input2.workspaceId, input2.channelId, input2.sourcePath);
6716
+ const shareId = existing?.id ?? generateShareId();
6717
+ const client2 = getR2Client();
6718
+ const bucket = getR2Bucket();
6719
+ const assetKeys = [];
6720
+ for (const asset of bundle.assets) {
6721
+ const key = `${SHARE_KEY_PREFIX}/${shareId}/${asset.name}`;
6722
+ if ("copyFrom" in asset) {
6723
+ await client2.send(
6724
+ new CopyObjectCommand({
6725
+ Bucket: bucket,
6726
+ Key: key,
6727
+ CopySource: `${bucket}/${asset.copyFrom}`.split("/").map(encodeURIComponent).join("/")
6728
+ })
6729
+ );
6730
+ } else {
6731
+ await client2.send(
6732
+ new PutObjectCommand2({
6733
+ Bucket: bucket,
6734
+ Key: key,
6735
+ Body: Buffer.from(asset.data, "base64"),
6736
+ ContentType: asset.contentType
6737
+ })
6738
+ );
6739
+ }
6740
+ assetKeys.push(key);
6741
+ }
6742
+ const built = {
6743
+ kind: bundle.kind,
6744
+ title: bundle.title,
6745
+ content: bundle.content.split(SHARE_ASSET_PLACEHOLDER).join(`/share/${shareId}/assets/`),
6746
+ assetKeys
6747
+ };
6748
+ const html = built.kind !== "markdown";
6749
+ const features = built.kind === "excalidraw" ? {
6750
+ ...HTML_FEATURES,
6751
+ brandingEnabled: resolveFeatures(input2.features, existing).brandingEnabled
6752
+ } : html ? HTML_FEATURES : resolveFeatures(input2.features, existing);
6753
+ const snapshot2 = {
6754
+ ...built,
6755
+ sourceLang: html ? null : await detectSourceLanguage(built.title, built.content)
6756
+ };
6757
+ const slug = input2.slug === void 0 ? existing?.slug ?? null : input2.slug;
6758
+ if (existing) {
6759
+ if (slug !== (existing.slug ?? null)) {
6760
+ const renamed = await setDocShareSlug(existing.id, slug);
6761
+ if (!renamed) return { status: "not-found" };
6762
+ }
6763
+ const share2 = await updateDocShareSnapshot(existing.id, snapshot2, features);
6764
+ const stale = existing.assetKeys.filter((key) => !snapshot2.assetKeys.includes(key));
6765
+ await deleteShareAssets(stale);
6766
+ if (!features.audioEnabled && existing.audioEnabled) await dropShareAudio(existing);
6767
+ void queueShareAudio(share2);
6768
+ return { status: "ok", share: share2 };
6769
+ }
6770
+ const share = await createDocShare({
6771
+ id: shareId,
6772
+ slug,
6773
+ workspaceId: input2.workspaceId,
6774
+ profile: input2.profile,
6775
+ channelId: input2.channelId,
6776
+ sourcePath: input2.sourcePath,
6777
+ createdBy: input2.createdBy,
6778
+ ...snapshot2,
6779
+ ...features
6780
+ });
6781
+ void queueShareAudio(share);
6782
+ return { status: "ok", share };
6783
+ }
6784
+
6785
+ // ../api/src/dashboard/share-slug.ts
6786
+ var MIN_SLUG = 2;
6787
+ var MAX_SLUG = 64;
6788
+ var SLUG_SHAPE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
6789
+ var RESERVED2 = /* @__PURE__ */ new Set([
6790
+ "admin",
6791
+ "api",
6792
+ "assets",
6793
+ "audio",
6794
+ "auth",
6795
+ "favicon",
6796
+ "login",
6797
+ "new",
6798
+ "og",
6799
+ "robots",
6800
+ "share",
6801
+ "sitemap",
6802
+ "static"
6803
+ ]);
6804
+ function normalizeSlug(raw) {
6805
+ const slug = raw.trim().toLowerCase();
6806
+ if (slug.length < MIN_SLUG) return { error: "too-short" };
6807
+ if (slug.length > MAX_SLUG) return { error: "too-long" };
6808
+ if (!SLUG_SHAPE.test(slug)) return { error: "shape" };
6809
+ if (RESERVED2.has(slug)) return { error: "reserved" };
6810
+ return { slug };
6811
+ }
6812
+ function slugErrorMessage(err) {
6813
+ switch (err) {
6814
+ case "too-short":
6815
+ return `Use at least ${MIN_SLUG} characters.`;
6816
+ case "too-long":
6817
+ return `Keep it under ${MAX_SLUG} characters.`;
6818
+ case "reserved":
6819
+ return "That word is reserved. Try something more specific.";
6820
+ default:
6821
+ return "Use lowercase letters, numbers and hyphens.";
6822
+ }
6823
+ }
6824
+
6640
6825
  // ../api/src/dashboard/agent-bridge-data.ts
6641
6826
  var hosts = /* @__PURE__ */ new Map();
6642
6827
  var hostStatusListeners = /* @__PURE__ */ new Set();
@@ -9032,147 +9217,6 @@ function createChatRouter(agent = {}) {
9032
9217
  // ../api/src/dashboard/doc-shares-routes.ts
9033
9218
  import { Hono as Hono14 } from "hono";
9034
9219
 
9035
- // ../api/src/dashboard/doc-share-features.ts
9036
- import { DeleteObjectCommand } from "@aws-sdk/client-s3";
9037
- var DEFAULT_FEATURES = {
9038
- audioEnabled: false,
9039
- askEnabled: true,
9040
- socialEnabled: false,
9041
- brandingEnabled: true,
9042
- translationEnabled: false,
9043
- translationLangs: []
9044
- };
9045
- var HTML_FEATURES = {
9046
- audioEnabled: false,
9047
- askEnabled: false,
9048
- socialEnabled: false,
9049
- brandingEnabled: false,
9050
- translationEnabled: false,
9051
- translationLangs: []
9052
- };
9053
- function resolveFeatures(requested, existing) {
9054
- const base = existing ?? DEFAULT_FEATURES;
9055
- return {
9056
- audioEnabled: requested?.audio ?? base.audioEnabled,
9057
- askEnabled: requested?.ask ?? base.askEnabled,
9058
- socialEnabled: requested?.social ?? base.socialEnabled,
9059
- brandingEnabled: requested?.branding ?? base.brandingEnabled,
9060
- translationEnabled: requested?.translation ?? base.translationEnabled,
9061
- // Replaced wholesale, not merged: the allowlist IS the answer to "which
9062
- // languages does this link offer", and a merge would make removing one
9063
- // impossible.
9064
- translationLangs: requested?.translationLangs ?? base.translationLangs
9065
- };
9066
- }
9067
- async function deleteShareAssets(keys) {
9068
- const client2 = getR2Client();
9069
- const bucket = getR2Bucket();
9070
- for (const key of keys) {
9071
- try {
9072
- await client2.send(new DeleteObjectCommand({ Bucket: bucket, Key: key }));
9073
- } catch {
9074
- }
9075
- }
9076
- }
9077
- async function updateShareFeatures(share, requested) {
9078
- if (share.kind === "html") return share;
9079
- if (share.kind === "excalidraw") {
9080
- if (requested.branding === void 0) return share;
9081
- return updateDocShareFeatures(share.id, { ...share, brandingEnabled: requested.branding });
9082
- }
9083
- const features = resolveFeatures(requested, share);
9084
- const updated = await updateDocShareFeatures(share.id, features);
9085
- if (!updated) return null;
9086
- if (features.audioEnabled) void queueShareAudio(updated);
9087
- else if (share.audioEnabled) await dropShareAudio(share);
9088
- return updated;
9089
- }
9090
-
9091
- // ../api/src/dashboard/doc-share-publish.ts
9092
- import { randomBytes as randomBytes5 } from "crypto";
9093
- import { CopyObjectCommand, PutObjectCommand as PutObjectCommand2 } from "@aws-sdk/client-s3";
9094
-
9095
- // ../api/src/dashboard/bridge-types.ts
9096
- var SHARE_ASSET_PLACEHOLDER = "/share/{{flyspace-share-id}}/assets/";
9097
-
9098
- // ../api/src/dashboard/doc-share-publish.ts
9099
- var SHARE_KEY_PREFIX = "share";
9100
- function generateShareId() {
9101
- return randomBytes5(9).toString("base64url");
9102
- }
9103
- async function publishDocShare(input2, readBundle) {
9104
- const bundle = await readBundle({ channelId: input2.channelId, cwd: input2.cwd, sourcePath: input2.sourcePath });
9105
- if (bundle.status !== "ok") return bundle;
9106
- const existing = await findDocShareBySource(input2.workspaceId, input2.channelId, input2.sourcePath);
9107
- const shareId = existing?.id ?? generateShareId();
9108
- const client2 = getR2Client();
9109
- const bucket = getR2Bucket();
9110
- const assetKeys = [];
9111
- for (const asset of bundle.assets) {
9112
- const key = `${SHARE_KEY_PREFIX}/${shareId}/${asset.name}`;
9113
- if ("copyFrom" in asset) {
9114
- await client2.send(
9115
- new CopyObjectCommand({
9116
- Bucket: bucket,
9117
- Key: key,
9118
- CopySource: `${bucket}/${asset.copyFrom}`.split("/").map(encodeURIComponent).join("/")
9119
- })
9120
- );
9121
- } else {
9122
- await client2.send(
9123
- new PutObjectCommand2({
9124
- Bucket: bucket,
9125
- Key: key,
9126
- Body: Buffer.from(asset.data, "base64"),
9127
- ContentType: asset.contentType
9128
- })
9129
- );
9130
- }
9131
- assetKeys.push(key);
9132
- }
9133
- const built = {
9134
- kind: bundle.kind,
9135
- title: bundle.title,
9136
- content: bundle.content.split(SHARE_ASSET_PLACEHOLDER).join(`/share/${shareId}/assets/`),
9137
- assetKeys
9138
- };
9139
- const html = built.kind !== "markdown";
9140
- const features = built.kind === "excalidraw" ? {
9141
- ...HTML_FEATURES,
9142
- brandingEnabled: resolveFeatures(input2.features, existing).brandingEnabled
9143
- } : html ? HTML_FEATURES : resolveFeatures(input2.features, existing);
9144
- const snapshot2 = {
9145
- ...built,
9146
- sourceLang: html ? null : await detectSourceLanguage(built.title, built.content)
9147
- };
9148
- const slug = input2.slug === void 0 ? existing?.slug ?? null : input2.slug;
9149
- if (existing) {
9150
- if (slug !== (existing.slug ?? null)) {
9151
- const renamed = await setDocShareSlug(existing.id, slug);
9152
- if (!renamed) return { status: "not-found" };
9153
- }
9154
- const share2 = await updateDocShareSnapshot(existing.id, snapshot2, features);
9155
- const stale = existing.assetKeys.filter((key) => !snapshot2.assetKeys.includes(key));
9156
- await deleteShareAssets(stale);
9157
- if (!features.audioEnabled && existing.audioEnabled) await dropShareAudio(existing);
9158
- void queueShareAudio(share2);
9159
- return { status: "ok", share: share2 };
9160
- }
9161
- const share = await createDocShare({
9162
- id: shareId,
9163
- slug,
9164
- workspaceId: input2.workspaceId,
9165
- profile: input2.profile,
9166
- channelId: input2.channelId,
9167
- sourcePath: input2.sourcePath,
9168
- createdBy: input2.createdBy,
9169
- ...snapshot2,
9170
- ...features
9171
- });
9172
- void queueShareAudio(share);
9173
- return { status: "ok", share };
9174
- }
9175
-
9176
9220
  // ../api/src/dashboard/share-tags.ts
9177
9221
  var MAX_TAGS = 10;
9178
9222
  var MAX_TAG_LENGTH = 30;
@@ -9192,46 +9236,6 @@ function normalizeTags(raw) {
9192
9236
  return [...tags];
9193
9237
  }
9194
9238
 
9195
- // ../api/src/dashboard/share-slug.ts
9196
- var MIN_SLUG = 2;
9197
- var MAX_SLUG = 64;
9198
- var SLUG_SHAPE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
9199
- var RESERVED2 = /* @__PURE__ */ new Set([
9200
- "admin",
9201
- "api",
9202
- "assets",
9203
- "audio",
9204
- "auth",
9205
- "favicon",
9206
- "login",
9207
- "new",
9208
- "og",
9209
- "robots",
9210
- "share",
9211
- "sitemap",
9212
- "static"
9213
- ]);
9214
- function normalizeSlug(raw) {
9215
- const slug = raw.trim().toLowerCase();
9216
- if (slug.length < MIN_SLUG) return { error: "too-short" };
9217
- if (slug.length > MAX_SLUG) return { error: "too-long" };
9218
- if (!SLUG_SHAPE.test(slug)) return { error: "shape" };
9219
- if (RESERVED2.has(slug)) return { error: "reserved" };
9220
- return { slug };
9221
- }
9222
- function slugErrorMessage(err) {
9223
- switch (err) {
9224
- case "too-short":
9225
- return `Use at least ${MIN_SLUG} characters.`;
9226
- case "too-long":
9227
- return `Keep it under ${MAX_SLUG} characters.`;
9228
- case "reserved":
9229
- return "That word is reserved. Try something more specific.";
9230
- default:
9231
- return "Use lowercase letters, numbers and hyphens.";
9232
- }
9233
- }
9234
-
9235
9239
  // ../api/src/dashboard/doc-shares-routes.ts
9236
9240
  function shareUrl(c, ref) {
9237
9241
  const proto = c.req.header("x-forwarded-proto") ?? "http";
@@ -14849,6 +14853,10 @@ function connectHostSocket(url, callbacks, onAuthenticated, onWorkspaces) {
14849
14853
  handlePluginSvgResult(msg.id, msg.url);
14850
14854
  return;
14851
14855
  }
14856
+ if (msg.type === "doc-share-result") {
14857
+ handleDocShareResult(msg.id, { url: msg.url, error: msg.error });
14858
+ return;
14859
+ }
14852
14860
  if (msg.type === "attachment-url-result") {
14853
14861
  handleAttachmentUrlResult(msg.id, msg.url);
14854
14862
  return;
@@ -15149,6 +15157,19 @@ async function startHostDashboard(preferredPort, host) {
15149
15157
  }
15150
15158
  });
15151
15159
  }
15160
+ app.post(LOCAL_DOC_SHARE_PATH, async (c) => {
15161
+ if (!relayAuthorized(c.req.raw, relayToken)) return c.json({ error: "unauthorized" }, 401);
15162
+ const body = await c.req.json().catch(() => null);
15163
+ if (!body || typeof body.channelId !== "string" || typeof body.path !== "string") {
15164
+ return c.json({ error: "bad request" }, 400);
15165
+ }
15166
+ try {
15167
+ const res = await requestDocShare(body.channelId, body.path, typeof body.slug === "string" ? body.slug : void 0);
15168
+ return c.json(res, res.url ? 200 : 400);
15169
+ } catch (err) {
15170
+ return c.json({ error: err.message }, 503);
15171
+ }
15172
+ });
15152
15173
  mountSpa(app);
15153
15174
  const { server, port, url } = await listen(app, preferredPort, host);
15154
15175
  relayToken = publishHostEndpoint(port);
@@ -15519,6 +15540,7 @@ var USAGE10 = `
15519
15540
  usage Show agent token usage and cost for this workspace
15520
15541
  chat Inspect dashboard chat channels and move threads between them
15521
15542
  memory Read and write a channel's persistent agent memory
15543
+ docs Publish a channel doc as a public link (docs share)
15522
15544
  persona Use a claudecafe character's faces as the bot's avatars
15523
15545
  profiles List local profiles (bound here? scheduler?) or remove one
15524
15546
  workspace Provision a workspace (Supabase rows + local profile dirs)
@@ -15622,6 +15644,9 @@ async function main() {
15622
15644
  case "memory":
15623
15645
  await runMemoryCmd(args.slice(1));
15624
15646
  break;
15647
+ case "docs":
15648
+ await runDocsCmd(args.slice(1));
15649
+ break;
15625
15650
  case "persona":
15626
15651
  await runPersonaCmd(args.slice(1));
15627
15652
  break;
@@ -15640,7 +15665,7 @@ async function main() {
15640
15665
  break;
15641
15666
  case "-v":
15642
15667
  case "--version":
15643
- printRaw("0.1.59");
15668
+ printRaw("0.1.60");
15644
15669
  break;
15645
15670
  case "-h":
15646
15671
  case "--help":