kanna-code 0.35.1 → 0.35.2

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.
@@ -5,7 +5,7 @@ import { cp as copyPath, copyFile, mkdir, readFile, readdir, stat, writeFile } f
5
5
  import type {
6
6
  StandaloneTranscriptAttachmentMode,
7
7
  StandaloneTranscriptBundle,
8
- StandaloneTranscriptExportResult,
8
+ StandaloneTranscriptExportCommandResult,
9
9
  StandaloneTranscriptTheme,
10
10
  TranscriptEntry,
11
11
  } from "../shared/types"
@@ -76,7 +76,7 @@ export function getStandaloneViewerDistDir() {
76
76
  export async function writeStandaloneTranscriptExport(
77
77
  args: WriteStandaloneTranscriptExportArgs,
78
78
  deps: StandaloneExportDeps = {},
79
- ): Promise<StandaloneTranscriptExportResult> {
79
+ ): Promise<StandaloneTranscriptExportCommandResult> {
80
80
  const viewerDistDir = deps.viewerDistDir ?? getStandaloneViewerDistDir()
81
81
  const ensureDir = deps.mkdir ?? mkdir
82
82
  const writeFileImpl = deps.writeFile ?? writeFile
@@ -124,21 +124,38 @@ export async function writeStandaloneTranscriptExport(
124
124
  messages: prepared.messages,
125
125
  }
126
126
 
127
+ const transcriptJson = `${JSON.stringify(bundle, null, 2)}\n`
127
128
  const transcriptJsonPath = path.join(outputDir, "transcript.json")
128
- await writeFileImpl(transcriptJsonPath, `${JSON.stringify(bundle, null, 2)}\n`, "utf8")
129
+ await writeFileImpl(transcriptJsonPath, transcriptJson, "utf8")
129
130
  const shareSlug = buildStandaloneShareSlug(args.title || args.chatId, deps.shareSlugSuffix)
130
131
  const shareUrl = buildStandaloneShareUrl(sharePublicBaseUrl, shareSlug)
131
- const uploadedFileCount = await uploadStandaloneExportDirectory({
132
- outputDir,
133
- shareSlug,
134
- uploadBaseUrl: shareUploadBaseUrl,
135
- fetch: fetchImpl,
136
- pathExists,
137
- readDir,
138
- readFile: readFileImpl,
139
- })
132
+ let uploadedFileCount = 0
133
+
134
+ try {
135
+ uploadedFileCount = await uploadStandaloneExportDirectory({
136
+ outputDir,
137
+ shareSlug,
138
+ uploadBaseUrl: shareUploadBaseUrl,
139
+ fetch: fetchImpl,
140
+ pathExists,
141
+ readDir,
142
+ readFile: readFileImpl,
143
+ })
144
+ } catch (error) {
145
+ return {
146
+ ok: false,
147
+ error: error instanceof Error ? error.message : String(error),
148
+ outputDir,
149
+ transcriptJsonPath,
150
+ transcriptFileName: `${path.basename(outputDir)}-transcript.json`,
151
+ transcriptJson,
152
+ shareSlug,
153
+ shareUrl,
154
+ }
155
+ }
140
156
 
141
157
  return {
158
+ ok: true,
142
159
  outputDir,
143
160
  indexHtmlPath: path.join(outputDir, "index.html"),
144
161
  transcriptJsonPath,
@@ -34,6 +34,7 @@ export interface StandaloneTranscriptBundle {
34
34
  }
35
35
 
36
36
  export interface StandaloneTranscriptExportResult {
37
+ ok: true
37
38
  outputDir: string
38
39
  indexHtmlPath: string
39
40
  transcriptJsonPath: string
@@ -45,6 +46,21 @@ export interface StandaloneTranscriptExportResult {
45
46
  uploadedFileCount: number
46
47
  }
47
48
 
49
+ export interface StandaloneTranscriptExportFailureResult {
50
+ ok: false
51
+ error: string
52
+ outputDir: string
53
+ transcriptJsonPath: string
54
+ transcriptFileName: string
55
+ transcriptJson: string
56
+ shareSlug: string
57
+ shareUrl: string
58
+ }
59
+
60
+ export type StandaloneTranscriptExportCommandResult =
61
+ | StandaloneTranscriptExportResult
62
+ | StandaloneTranscriptExportFailureResult
63
+
48
64
  export interface QueuedChatMessage {
49
65
  id: string
50
66
  content: string