@sixb/app 0.1.12 → 0.1.13
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/README.md +3 -8
- package/dist/agent/activity-label.d.ts.map +1 -1
- package/dist/agent/agent-chat.d.ts +9 -8
- package/dist/agent/agent-chat.d.ts.map +1 -1
- package/dist/agent/agent-panel.d.ts +5 -8
- package/dist/agent/agent-panel.d.ts.map +1 -1
- package/dist/agent/agents-page.d.ts +4 -0
- package/dist/agent/agents-page.d.ts.map +1 -0
- package/dist/agent/artifact-card.d.ts +9 -0
- package/dist/agent/artifact-card.d.ts.map +1 -0
- package/dist/agent/artifact-panel-state.d.ts +16 -0
- package/dist/agent/artifact-panel-state.d.ts.map +1 -0
- package/dist/agent/artifact-panel.d.ts +38 -0
- package/dist/agent/artifact-panel.d.ts.map +1 -0
- package/dist/agent/components/file-attachment-card.d.ts +3 -3
- package/dist/agent/components/file-attachment-card.d.ts.map +1 -1
- package/dist/agent/components/message-parts.d.ts +2 -1
- package/dist/agent/components/message-parts.d.ts.map +1 -1
- package/dist/agent/components/message-view.d.ts +3 -3
- package/dist/agent/components/message-view.d.ts.map +1 -1
- package/dist/agent/components/thread-artifacts-menu.d.ts +8 -0
- package/dist/agent/components/thread-artifacts-menu.d.ts.map +1 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts +3 -4
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/i18n/en.d.ts +10 -49
- package/dist/agent/i18n/en.d.ts.map +1 -1
- package/dist/agent/i18n/fr.d.ts.map +1 -1
- package/dist/agent/i18n/index.d.ts +16 -98
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/parts.d.ts +4 -4
- package/dist/agent/parts.d.ts.map +1 -1
- package/dist/agent/publish-artifact/interpret.d.ts +32 -0
- package/dist/agent/publish-artifact/interpret.d.ts.map +1 -0
- package/dist/agent/publish-artifact/publish-artifact-tool-view.d.ts +9 -0
- package/dist/agent/publish-artifact/publish-artifact-tool-view.d.ts.map +1 -0
- package/dist/agent/publish-artifact/use-live-publishes.d.ts +10 -0
- package/dist/agent/publish-artifact/use-live-publishes.d.ts.map +1 -0
- package/dist/agent/react-router.d.ts +1 -2
- package/dist/agent/react-router.d.ts.map +1 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts +1 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts.map +1 -1
- package/dist/artifacts/artifact-page.d.ts +7 -0
- package/dist/artifacts/artifact-page.d.ts.map +1 -0
- package/dist/artifacts/card-details.d.ts +15 -0
- package/dist/artifacts/card-details.d.ts.map +1 -0
- package/dist/artifacts/card-preview.d.ts +59 -0
- package/dist/artifacts/card-preview.d.ts.map +1 -0
- package/dist/artifacts/copy-feedback.d.ts +6 -0
- package/dist/artifacts/copy-feedback.d.ts.map +1 -0
- package/dist/artifacts/file-size.d.ts +11 -0
- package/dist/artifacts/file-size.d.ts.map +1 -0
- package/dist/artifacts/file-source.d.ts +45 -0
- package/dist/artifacts/file-source.d.ts.map +1 -0
- package/dist/artifacts/file-view.d.ts +9 -0
- package/dist/artifacts/file-view.d.ts.map +1 -0
- package/dist/artifacts/frame.d.ts +45 -0
- package/dist/artifacts/frame.d.ts.map +1 -0
- package/dist/artifacts/gallery.d.ts +6 -0
- package/dist/artifacts/gallery.d.ts.map +1 -0
- package/dist/artifacts/kind-icon.d.ts +8 -0
- package/dist/artifacts/kind-icon.d.ts.map +1 -0
- package/dist/artifacts/markdown-tree.d.ts +22 -0
- package/dist/artifacts/markdown-tree.d.ts.map +1 -0
- package/dist/artifacts/messages.d.ts +301 -0
- package/dist/artifacts/messages.d.ts.map +1 -0
- package/dist/artifacts/queries.d.ts +21 -0
- package/dist/artifacts/queries.d.ts.map +1 -0
- package/dist/artifacts/references/embed-tree.d.ts +17 -0
- package/dist/artifacts/references/embed-tree.d.ts.map +1 -0
- package/dist/artifacts/references/references.d.ts +50 -0
- package/dist/artifacts/references/references.d.ts.map +1 -0
- package/dist/artifacts/renderers/document-tree.d.ts +11 -0
- package/dist/artifacts/renderers/document-tree.d.ts.map +1 -0
- package/dist/artifacts/renderers/document.d.ts +17 -0
- package/dist/artifacts/renderers/document.d.ts.map +1 -0
- package/dist/artifacts/renderers/file.d.ts +10 -0
- package/dist/artifacts/renderers/file.d.ts.map +1 -0
- package/dist/artifacts/renderers/notice.d.ts +12 -0
- package/dist/artifacts/renderers/notice.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/chart-data.d.ts +33 -0
- package/dist/artifacts/renderers/sheet/chart-data.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/chart.d.ts +15 -0
- package/dist/artifacts/renderers/sheet/chart.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/format.d.ts +35 -0
- package/dist/artifacts/renderers/sheet/format.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/grid.d.ts +25 -0
- package/dist/artifacts/renderers/sheet/grid.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/mini-chart.d.ts +7 -0
- package/dist/artifacts/renderers/sheet/mini-chart.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/model.d.ts +29 -0
- package/dist/artifacts/renderers/sheet/model.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/selection.d.ts +42 -0
- package/dist/artifacts/renderers/sheet/selection.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/sheet.d.ts +17 -0
- package/dist/artifacts/renderers/sheet/sheet.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/virtual.d.ts +13 -0
- package/dist/artifacts/renderers/sheet/virtual.d.ts.map +1 -0
- package/dist/artifacts/renderers/sheet/workbook.d.ts +24 -0
- package/dist/artifacts/renderers/sheet/workbook.d.ts.map +1 -0
- package/dist/artifacts/renderers/slides/navigation.d.ts +17 -0
- package/dist/artifacts/renderers/slides/navigation.d.ts.map +1 -0
- package/dist/artifacts/renderers/slides/slides.d.ts +14 -0
- package/dist/artifacts/renderers/slides/slides.d.ts.map +1 -0
- package/dist/artifacts/target.d.ts +29 -0
- package/dist/artifacts/target.d.ts.map +1 -0
- package/dist/artifacts/theme.d.ts +18 -0
- package/dist/artifacts/theme.d.ts.map +1 -0
- package/dist/artifacts/viewer.d.ts +19 -0
- package/dist/artifacts/viewer.d.ts.map +1 -0
- package/dist/{chunk-shmw3f8t.js → chunk-3schcf10.js} +1 -1
- package/dist/chunk-c7gy61rx.js +276 -0
- package/dist/chunk-c7gy61rx.js.map +10 -0
- package/dist/{chunk-48pkffj6.js → chunk-g3f4cm8x.js} +1 -1
- package/dist/{chunk-zcxrt24m.js → chunk-gn3k23q5.js} +3 -2
- package/dist/{chunk-zcxrt24m.js.map → chunk-gn3k23q5.js.map} +3 -3
- package/dist/{chunk-3a99tmwg.js → chunk-ng0hdnrq.js} +10 -3
- package/dist/chunk-ng0hdnrq.js.map +10 -0
- package/dist/{chunk-j97e06rg.js → chunk-xxpdn63v.js} +7224 -2874
- package/dist/chunk-xxpdn63v.js.map +105 -0
- package/dist/codegen.d.ts +2 -0
- package/dist/codegen.d.ts.map +1 -1
- package/dist/createCustomApp.d.ts.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -31
- package/dist/index.js.map +7 -7
- package/dist/locale-messages.d.ts +2 -0
- package/dist/locale-messages.d.ts.map +1 -1
- package/dist/locale.d.ts +2 -0
- package/dist/locale.d.ts.map +1 -1
- package/dist/locale.js +1 -1
- package/dist/pages/observability/activity/calendar.d.ts +9 -0
- package/dist/pages/observability/activity/calendar.d.ts.map +1 -0
- package/dist/pages/observability/activity/connections.d.ts +7 -0
- package/dist/pages/observability/activity/connections.d.ts.map +1 -0
- package/dist/pages/observability/activity/format.d.ts +11 -0
- package/dist/pages/observability/activity/format.d.ts.map +1 -0
- package/dist/pages/observability/activity/messages.d.ts +231 -0
- package/dist/pages/observability/activity/messages.d.ts.map +1 -0
- package/dist/pages/observability/activity/meta-items.d.ts +10 -0
- package/dist/pages/observability/activity/meta-items.d.ts.map +1 -0
- package/dist/pages/observability/activity/page.d.ts +6 -0
- package/dist/pages/observability/activity/page.d.ts.map +1 -0
- package/dist/pages/observability/activity/period.d.ts +31 -0
- package/dist/pages/observability/activity/period.d.ts.map +1 -0
- package/dist/pages/observability/activity/steps.d.ts +44 -0
- package/dist/pages/observability/activity/steps.d.ts.map +1 -0
- package/dist/pages/observability/activity/timeline.d.ts +36 -0
- package/dist/pages/observability/activity/timeline.d.ts.map +1 -0
- package/dist/pages/observability/activity/users.d.ts +18 -0
- package/dist/pages/observability/activity/users.d.ts.map +1 -0
- package/dist/pages/routes.d.ts +7 -0
- package/dist/pages/routes.d.ts.map +1 -1
- package/dist/pages/section-ui.d.ts +2 -1
- package/dist/pages/section-ui.d.ts.map +1 -1
- package/dist/pages.d.ts +4 -1
- package/dist/pages.d.ts.map +1 -1
- package/dist/pages.js +5852 -3754
- package/dist/pages.js.map +20 -7
- package/dist/sections/catalog.d.ts.map +1 -1
- package/dist/sections/sections.d.ts.map +1 -1
- package/dist/server.js +63 -10
- package/dist/server.js.map +5 -5
- package/dist/shell/search-command.d.ts.map +1 -1
- package/dist/shell/user-menu.d.ts +3 -3
- package/dist/shell/user-menu.d.ts.map +1 -1
- package/package.json +4 -6
- package/src/agent/activity-label.ts +7 -0
- package/src/agent/agent-chat.tsx +29 -18
- package/src/agent/agent-execution-trace.tsx +1 -1
- package/src/agent/agent-panel.tsx +8 -13
- package/src/agent/agent-surface.tsx +4 -4
- package/src/agent/agents-page.ts +7 -0
- package/src/agent/artifact-card.tsx +190 -0
- package/src/agent/artifact-panel-state.ts +38 -0
- package/src/agent/artifact-panel.tsx +320 -0
- package/src/agent/components/file-attachment-card.tsx +13 -14
- package/src/agent/components/message-parts.tsx +30 -5
- package/src/agent/components/message-view.tsx +13 -19
- package/src/agent/components/thread-artifacts-menu.tsx +77 -0
- package/src/agent/i18n/en.ts +16 -58
- package/src/agent/i18n/fr.ts +15 -59
- package/src/agent/parts.ts +6 -6
- package/src/agent/publish-artifact/interpret.ts +110 -0
- package/src/agent/publish-artifact/publish-artifact-tool-view.tsx +62 -0
- package/src/agent/publish-artifact/use-live-publishes.ts +45 -0
- package/src/agent/react-router.tsx +26 -7
- package/src/agent/view-file/view-file-tool-view.tsx +21 -18
- package/src/artifacts/artifact-page.tsx +61 -0
- package/src/artifacts/artifacts.css +172 -0
- package/src/artifacts/card-details.ts +92 -0
- package/src/artifacts/card-preview.tsx +612 -0
- package/src/artifacts/copy-feedback.ts +25 -0
- package/src/artifacts/file-size.ts +24 -0
- package/src/artifacts/file-source.ts +109 -0
- package/src/artifacts/file-view.ts +57 -0
- package/src/artifacts/frame.tsx +288 -0
- package/src/artifacts/gallery.tsx +405 -0
- package/src/artifacts/kind-icon.tsx +23 -0
- package/src/artifacts/markdown-tree.ts +32 -0
- package/src/artifacts/messages.ts +317 -0
- package/src/artifacts/queries.ts +85 -0
- package/src/artifacts/references/embed-tree.ts +86 -0
- package/src/artifacts/references/references.tsx +739 -0
- package/src/artifacts/renderers/document-tree.ts +157 -0
- package/src/artifacts/renderers/document.tsx +334 -0
- package/src/artifacts/renderers/file.tsx +160 -0
- package/src/artifacts/renderers/notice.tsx +38 -0
- package/src/artifacts/renderers/sheet/chart-data.ts +73 -0
- package/src/artifacts/renderers/sheet/chart.tsx +288 -0
- package/src/artifacts/renderers/sheet/format.ts +142 -0
- package/src/artifacts/renderers/sheet/grid.tsx +709 -0
- package/src/artifacts/renderers/sheet/mini-chart.tsx +241 -0
- package/src/artifacts/renderers/sheet/model.ts +136 -0
- package/src/artifacts/renderers/sheet/selection.ts +152 -0
- package/src/artifacts/renderers/sheet/sheet.tsx +471 -0
- package/src/artifacts/renderers/sheet/virtual.ts +49 -0
- package/src/artifacts/renderers/sheet/workbook.ts +57 -0
- package/src/artifacts/renderers/slides/navigation.ts +38 -0
- package/src/artifacts/renderers/slides/slides.tsx +441 -0
- package/src/artifacts/target.ts +76 -0
- package/src/artifacts/theme.ts +29 -0
- package/src/artifacts/viewer.tsx +476 -0
- package/src/build.ts +13 -2
- package/src/codegen.ts +38 -2
- package/src/createCustomApp.ts +21 -1
- package/src/index.ts +0 -5
- package/src/locale-messages.ts +9 -2
- package/src/pages/observability/activity/calendar.tsx +239 -0
- package/src/pages/observability/activity/connections.tsx +144 -0
- package/src/pages/observability/activity/format.ts +49 -0
- package/src/pages/observability/activity/messages.ts +255 -0
- package/src/pages/observability/activity/meta-items.tsx +23 -0
- package/src/pages/observability/activity/page.tsx +605 -0
- package/src/pages/observability/activity/period.ts +63 -0
- package/src/pages/observability/activity/steps.ts +102 -0
- package/src/pages/observability/activity/timeline.tsx +411 -0
- package/src/pages/observability/activity/users.tsx +133 -0
- package/src/pages/observability/messages.ts +2 -2
- package/src/pages/routes.ts +15 -0
- package/src/pages/section-ui.tsx +3 -1
- package/src/pages.ts +4 -1
- package/src/sections/catalog.ts +1 -0
- package/src/sections/sections.tsx +2 -0
- package/src/shell/search-command.tsx +8 -6
- package/src/shell/user-menu.tsx +22 -22
- package/dist/agent/document-preview/classify.d.ts +0 -4
- package/dist/agent/document-preview/classify.d.ts.map +0 -1
- package/dist/agent/document-preview/content-policy.d.ts +0 -10
- package/dist/agent/document-preview/content-policy.d.ts.map +0 -1
- package/dist/agent/document-preview/content.d.ts +0 -26
- package/dist/agent/document-preview/content.d.ts.map +0 -1
- package/dist/agent/document-preview/delimited.d.ts +0 -19
- package/dist/agent/document-preview/delimited.d.ts.map +0 -1
- package/dist/agent/document-preview/document-preview-root.d.ts +0 -24
- package/dist/agent/document-preview/document-preview-root.d.ts.map +0 -1
- package/dist/agent/document-preview/file-size.d.ts +0 -3
- package/dist/agent/document-preview/file-size.d.ts.map +0 -1
- package/dist/agent/document-preview/html.d.ts +0 -9
- package/dist/agent/document-preview/html.d.ts.map +0 -1
- package/dist/agent/document-preview/persistence.d.ts +0 -6
- package/dist/agent/document-preview/persistence.d.ts.map +0 -1
- package/dist/agent/document-preview/presentation.d.ts +0 -3
- package/dist/agent/document-preview/presentation.d.ts.map +0 -1
- package/dist/agent/document-preview/rendering.d.ts +0 -14
- package/dist/agent/document-preview/rendering.d.ts.map +0 -1
- package/dist/agent/document-preview/source.d.ts +0 -13
- package/dist/agent/document-preview/source.d.ts.map +0 -1
- package/dist/agent/document-preview/state.d.ts +0 -27
- package/dist/agent/document-preview/state.d.ts.map +0 -1
- package/dist/agent/document-preview/types.d.ts +0 -33
- package/dist/agent/document-preview/types.d.ts.map +0 -1
- package/dist/agent/workspace.d.ts +0 -11
- package/dist/agent/workspace.d.ts.map +0 -1
- package/dist/chunk-3a99tmwg.js.map +0 -10
- package/dist/chunk-j97e06rg.js.map +0 -80
- package/src/agent/document-preview/classify.ts +0 -55
- package/src/agent/document-preview/content-policy.ts +0 -37
- package/src/agent/document-preview/content.ts +0 -82
- package/src/agent/document-preview/delimited.ts +0 -118
- package/src/agent/document-preview/document-preview-root.tsx +0 -1017
- package/src/agent/document-preview/file-size.ts +0 -26
- package/src/agent/document-preview/html.ts +0 -67
- package/src/agent/document-preview/persistence.ts +0 -115
- package/src/agent/document-preview/presentation.ts +0 -13
- package/src/agent/document-preview/rendering.ts +0 -48
- package/src/agent/document-preview/source.ts +0 -48
- package/src/agent/document-preview/state.ts +0 -77
- package/src/agent/document-preview/types.ts +0 -36
- package/src/agent/workspace.ts +0 -33
- /package/dist/{chunk-shmw3f8t.js.map → chunk-3schcf10.js.map} +0 -0
- /package/dist/{chunk-48pkffj6.js.map → chunk-g3f4cm8x.js.map} +0 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { client, getAgentMessageFileContent, getArtifactFileContent } from "@sixb/client"
|
|
2
|
+
import { useArtifactMessages } from "./messages"
|
|
3
|
+
|
|
4
|
+
/** The parts of a stored file reference the viewer reads. */
|
|
5
|
+
export interface ViewerFileRef {
|
|
6
|
+
readonly blobId: string
|
|
7
|
+
readonly digest: string
|
|
8
|
+
readonly sizeBytes: number
|
|
9
|
+
readonly fileName?: string
|
|
10
|
+
readonly mediaType?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A file the viewer can show, tied to the route that authorizes reading it: a file of an artifact
|
|
15
|
+
* version, or a file in a conversation message.
|
|
16
|
+
*/
|
|
17
|
+
export interface FileSource {
|
|
18
|
+
readonly id: string
|
|
19
|
+
readonly fileRef: ViewerFileRef
|
|
20
|
+
/**
|
|
21
|
+
* The file's name: its path in an artifact, else its own name. Empty for a message file that
|
|
22
|
+
* has none, which a view names in the reader's language with {@link useFileName}.
|
|
23
|
+
*/
|
|
24
|
+
readonly name: string
|
|
25
|
+
readonly inlineUrl: string
|
|
26
|
+
readonly downloadUrl: string
|
|
27
|
+
/** Identity of its bytes in the query cache. */
|
|
28
|
+
readonly queryKey: readonly unknown[]
|
|
29
|
+
readonly load: (signal: AbortSignal) => Promise<Blob>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function artifactFileSource(input: {
|
|
33
|
+
readonly artifactId: string
|
|
34
|
+
readonly version: number
|
|
35
|
+
readonly path: string
|
|
36
|
+
readonly fileRef: ViewerFileRef
|
|
37
|
+
/** Explicit base URL for pure callers and tests. Defaults to the configured Sixb client URL. */
|
|
38
|
+
readonly baseUrl?: string
|
|
39
|
+
}): FileSource {
|
|
40
|
+
const routePath = `/api/artifacts/${encodeURIComponent(input.artifactId)}/versions/${input.version}/content`
|
|
41
|
+
const url = (disposition: "inline" | "attachment") =>
|
|
42
|
+
contentUrl(routePath, { path: input.path, disposition }, input.baseUrl)
|
|
43
|
+
return {
|
|
44
|
+
id: `artifact:${input.artifactId}@${input.version}/${input.path}`,
|
|
45
|
+
fileRef: input.fileRef,
|
|
46
|
+
name: input.path,
|
|
47
|
+
inlineUrl: url("inline"),
|
|
48
|
+
downloadUrl: url("attachment"),
|
|
49
|
+
queryKey: ["artifact-file", input.artifactId, input.version, input.path, input.fileRef.digest],
|
|
50
|
+
load: async (signal) => {
|
|
51
|
+
const response = await getArtifactFileContent({
|
|
52
|
+
path: { artifactId: input.artifactId, version: String(input.version) },
|
|
53
|
+
query: { path: input.path, disposition: "inline" },
|
|
54
|
+
parseAs: "blob",
|
|
55
|
+
throwOnError: true,
|
|
56
|
+
signal,
|
|
57
|
+
})
|
|
58
|
+
return response.data
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function messageFileSource(input: {
|
|
64
|
+
readonly threadId: string
|
|
65
|
+
readonly messageId: string
|
|
66
|
+
/** JSON pointer to the file reference in the message, such as `/parts/2/fileRef`. */
|
|
67
|
+
readonly path: string
|
|
68
|
+
readonly fileRef: ViewerFileRef
|
|
69
|
+
readonly baseUrl?: string
|
|
70
|
+
}): FileSource {
|
|
71
|
+
const routePath = `/api/agent-threads/${encodeURIComponent(input.threadId)}/messages/${encodeURIComponent(
|
|
72
|
+
input.messageId
|
|
73
|
+
)}/files/content`
|
|
74
|
+
const url = (disposition: "inline" | "attachment") =>
|
|
75
|
+
contentUrl(routePath, { path: input.path, disposition }, input.baseUrl)
|
|
76
|
+
return {
|
|
77
|
+
id: `message:${input.messageId}${input.path}`,
|
|
78
|
+
fileRef: input.fileRef,
|
|
79
|
+
name: input.fileRef.fileName?.trim() ?? "",
|
|
80
|
+
inlineUrl: url("inline"),
|
|
81
|
+
downloadUrl: url("attachment"),
|
|
82
|
+
queryKey: ["message-file", input.threadId, input.messageId, input.path, input.fileRef.digest],
|
|
83
|
+
load: async (signal) => {
|
|
84
|
+
const response = await getAgentMessageFileContent({
|
|
85
|
+
path: { threadId: input.threadId, messageId: input.messageId },
|
|
86
|
+
query: { path: input.path, disposition: "inline" },
|
|
87
|
+
parseAs: "blob",
|
|
88
|
+
throwOnError: true,
|
|
89
|
+
signal,
|
|
90
|
+
})
|
|
91
|
+
return response.data
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The file's name to show: its own, or a word for a file in the reader's language. */
|
|
97
|
+
export function useFileName(source: FileSource): string {
|
|
98
|
+
const messages = useArtifactMessages().files
|
|
99
|
+
return source.name || messages.file
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function contentUrl(routePath: string, query: Record<string, string>, baseUrl?: string): string {
|
|
103
|
+
const params = new URLSearchParams(query)
|
|
104
|
+
const base = baseUrl ?? client.getConfig().baseUrl
|
|
105
|
+
if (!base && typeof window === "undefined") return `${routePath}?${params}`
|
|
106
|
+
const url = new URL(routePath, base ?? window.location.origin)
|
|
107
|
+
url.search = params.toString()
|
|
108
|
+
return url.toString()
|
|
109
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// How the viewer shows a file, decided from its metadata alone, before reading any bytes.
|
|
2
|
+
import { isSixbApiError } from "@sixb/client"
|
|
3
|
+
import type { ViewerFileRef } from "./file-source"
|
|
4
|
+
|
|
5
|
+
export type FileView = "image" | "pdf" | "markdown" | "csv" | "tsv" | "text" | "download"
|
|
6
|
+
|
|
7
|
+
/** Text files are read whole; larger ones offer the download instead. */
|
|
8
|
+
export const MAX_TEXT_PREVIEW_BYTES = 5 * 1024 * 1024
|
|
9
|
+
|
|
10
|
+
const GENERIC_MEDIA_TYPES = new Set(["application/octet-stream", "binary/octet-stream"])
|
|
11
|
+
const IMAGE_TYPES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif", "image/svg+xml"])
|
|
12
|
+
const TEXT_TYPES = new Set([
|
|
13
|
+
"text/plain",
|
|
14
|
+
"application/json",
|
|
15
|
+
"application/x-ndjson",
|
|
16
|
+
"application/xml",
|
|
17
|
+
"application/yaml",
|
|
18
|
+
"text/css",
|
|
19
|
+
"text/xml",
|
|
20
|
+
])
|
|
21
|
+
|
|
22
|
+
export function fileView(fileRef: Pick<ViewerFileRef, "mediaType" | "fileName">): FileView {
|
|
23
|
+
const mediaType = fileRef.mediaType?.split(";", 1)[0]?.trim().toLowerCase()
|
|
24
|
+
if (mediaType && !GENERIC_MEDIA_TYPES.has(mediaType)) return viewFromMediaType(mediaType)
|
|
25
|
+
return viewFromFileName(fileRef.fileName?.trim().toLowerCase() ?? "")
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Why a file could not load, as a key of the viewer's `files` messages. */
|
|
29
|
+
export type FileLoadError = "gone" | "storageUnavailable" | "loadFailed"
|
|
30
|
+
|
|
31
|
+
export function fileLoadError(error: unknown): FileLoadError {
|
|
32
|
+
if (isSixbApiError(error)) {
|
|
33
|
+
if (error.status === 404) return "gone"
|
|
34
|
+
if (error.status === 501) return "storageUnavailable"
|
|
35
|
+
}
|
|
36
|
+
return "loadFailed"
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function viewFromMediaType(mediaType: string): FileView {
|
|
40
|
+
if (IMAGE_TYPES.has(mediaType)) return "image"
|
|
41
|
+
if (mediaType === "application/pdf") return "pdf"
|
|
42
|
+
if (mediaType === "text/markdown") return "markdown"
|
|
43
|
+
if (mediaType === "text/csv") return "csv"
|
|
44
|
+
if (mediaType === "text/tab-separated-values") return "tsv"
|
|
45
|
+
if (TEXT_TYPES.has(mediaType)) return "text"
|
|
46
|
+
return "download"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function viewFromFileName(name: string): FileView {
|
|
50
|
+
if (/\.(png|jpe?g|webp|gif|svg)$/.test(name)) return "image"
|
|
51
|
+
if (name.endsWith(".pdf")) return "pdf"
|
|
52
|
+
if (/\.(md|markdown)$/.test(name)) return "markdown"
|
|
53
|
+
if (name.endsWith(".csv")) return "csv"
|
|
54
|
+
if (name.endsWith(".tsv")) return "tsv"
|
|
55
|
+
if (/\.(txt|json|jsonl|xml|ya?ml|css|log)$/.test(name)) return "text"
|
|
56
|
+
return "download"
|
|
57
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { client, createArtifactFrame } from "@sixb/client"
|
|
2
|
+
import {
|
|
3
|
+
FRAME_PROTOCOL,
|
|
4
|
+
FRAME_THEME_TOKENS,
|
|
5
|
+
type FrameEvent,
|
|
6
|
+
type FrameRequest,
|
|
7
|
+
type FrameStart,
|
|
8
|
+
frameStartHash,
|
|
9
|
+
parseFrameEvent,
|
|
10
|
+
} from "@sixb/core/artifacts"
|
|
11
|
+
import { cn } from "@sixb/ui/lib/utils"
|
|
12
|
+
import { useQuery } from "@tanstack/react-query"
|
|
13
|
+
import {
|
|
14
|
+
type ReactNode,
|
|
15
|
+
type Ref,
|
|
16
|
+
useCallback,
|
|
17
|
+
useEffect,
|
|
18
|
+
useImperativeHandle,
|
|
19
|
+
useRef,
|
|
20
|
+
useState,
|
|
21
|
+
} from "react"
|
|
22
|
+
import { type ArtifactVersion, useArtifactTheme } from "./queries"
|
|
23
|
+
|
|
24
|
+
/** Asks the deck in the frame to do something; resolves when it has. */
|
|
25
|
+
export interface ArtifactFrameHandle {
|
|
26
|
+
send<Method extends FrameRequest["method"]>(
|
|
27
|
+
method: Method,
|
|
28
|
+
params: Extract<FrameRequest, { method: Method }>["params"]
|
|
29
|
+
): Promise<void>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A frame link lasts an hour; one is reused while it has most of that left. */
|
|
33
|
+
const FRAME_REUSE_MS = 40 * 60 * 1000
|
|
34
|
+
|
|
35
|
+
/** How long a deck has to say it is ready before a frame that reports failure gives up on it. */
|
|
36
|
+
const READY_TIMEOUT_MS = 20_000
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A version in a sandboxed frame, served from the API under a short-lived link. The frame has an
|
|
40
|
+
* opaque origin, so its page cannot read the app's cookies or call the API as the reader: it
|
|
41
|
+
* talks to the app only in messages, and the app listens only to its own frame and reads only
|
|
42
|
+
* events of the protocol's shape. The app's theme goes in as tokens, read where the frame is
|
|
43
|
+
* mounted, so an artifact's theme applies too.
|
|
44
|
+
*
|
|
45
|
+
* The frame stays hidden until its theme is applied, then fades in over `fallback`: until the
|
|
46
|
+
* tokens arrive, a deck paints in the kit's light defaults, which flash on a dark page.
|
|
47
|
+
*/
|
|
48
|
+
export function ArtifactFrame({
|
|
49
|
+
version,
|
|
50
|
+
title,
|
|
51
|
+
onEvent,
|
|
52
|
+
className,
|
|
53
|
+
handle,
|
|
54
|
+
start,
|
|
55
|
+
decorative = false,
|
|
56
|
+
fallback,
|
|
57
|
+
failure,
|
|
58
|
+
overlay,
|
|
59
|
+
}: {
|
|
60
|
+
readonly version: ArtifactVersion
|
|
61
|
+
readonly title: string
|
|
62
|
+
/** How it opens; a change loads the frame again, so this is for where it starts. */
|
|
63
|
+
readonly start?: FrameStart
|
|
64
|
+
/** A picture of the deck, as a thumbnail is: it takes no focus, clicks, or reading. */
|
|
65
|
+
readonly decorative?: boolean
|
|
66
|
+
readonly onEvent?: (event: FrameEvent) => void
|
|
67
|
+
readonly className?: string
|
|
68
|
+
/** What shows where the frame will be while it loads, and under it as it fades in. */
|
|
69
|
+
readonly fallback?: ReactNode
|
|
70
|
+
/**
|
|
71
|
+
* What shows instead when the deck cannot open: no link could be had for it, or it never said
|
|
72
|
+
* it was ready. A frame that reports failure loads at once; others wait until they near the
|
|
73
|
+
* viewport.
|
|
74
|
+
*/
|
|
75
|
+
readonly failure?: ReactNode
|
|
76
|
+
/**
|
|
77
|
+
* What the app draws over the frame, in the frame's own pixels, once the frame shows: another
|
|
78
|
+
* artifact a deck embeds. Clicks reach the frame except where the overlay draws.
|
|
79
|
+
*/
|
|
80
|
+
readonly overlay?: ReactNode
|
|
81
|
+
/** Where to put the handle that asks the frame for things (`ref` is not a prop in React 18). */
|
|
82
|
+
readonly handle?: Ref<ArtifactFrameHandle>
|
|
83
|
+
}) {
|
|
84
|
+
const iframe = useRef<HTMLIFrameElement | null>(null)
|
|
85
|
+
const pending = useRef(new Map<number, { resolve: () => void; reject: (error: Error) => void }>())
|
|
86
|
+
const nextId = useRef(0)
|
|
87
|
+
const onEventRef = useRef(onEvent)
|
|
88
|
+
onEventRef.current = onEvent
|
|
89
|
+
// The source that has said it is ready, and the one it has shown, themed: a new source starts
|
|
90
|
+
// hidden again.
|
|
91
|
+
const [ready, setReady] = useState<string | null>(null)
|
|
92
|
+
const [shown, setShown] = useState<string | null>(null)
|
|
93
|
+
const [timedOut, setTimedOut] = useState<string | null>(null)
|
|
94
|
+
const reportsFailure = failure !== undefined
|
|
95
|
+
|
|
96
|
+
const frame = useQuery({
|
|
97
|
+
queryKey: ["artifact-frame", version.artifactId, version.version],
|
|
98
|
+
queryFn: async () => {
|
|
99
|
+
const { data } = await createArtifactFrame({
|
|
100
|
+
path: { artifactId: version.artifactId, version: String(version.version) },
|
|
101
|
+
throwOnError: true,
|
|
102
|
+
})
|
|
103
|
+
return data
|
|
104
|
+
},
|
|
105
|
+
staleTime: FRAME_REUSE_MS,
|
|
106
|
+
gcTime: FRAME_REUSE_MS,
|
|
107
|
+
retry: false,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
// Each frame keeps the link it first loaded: every frame of a version shares the query, and a
|
|
111
|
+
// link minted for a later mount would otherwise load every mounted frame again, at its start.
|
|
112
|
+
const identity = `${version.artifactId}@${version.version}`
|
|
113
|
+
const [kept, setKept] = useState<{ readonly identity: string; readonly path: string } | null>(
|
|
114
|
+
null
|
|
115
|
+
)
|
|
116
|
+
if (frame.data && kept?.identity !== identity) setKept({ identity, path: frame.data.path })
|
|
117
|
+
const path = kept?.identity === identity ? kept.path : undefined
|
|
118
|
+
const source = path ? `${frameUrl(path, version.entry)}${frameStartHash(start ?? {})}` : undefined
|
|
119
|
+
const sourceRef = useRef(source)
|
|
120
|
+
sourceRef.current = source
|
|
121
|
+
|
|
122
|
+
const send = useCallback<ArtifactFrameHandle["send"]>((method, params) => {
|
|
123
|
+
const target = iframe.current?.contentWindow
|
|
124
|
+
if (!target) return Promise.reject(new Error("[SixbApp] The frame is not loaded."))
|
|
125
|
+
nextId.current += 1
|
|
126
|
+
const id = nextId.current
|
|
127
|
+
return new Promise<void>((resolve, reject) => {
|
|
128
|
+
pending.current.set(id, { resolve, reject })
|
|
129
|
+
// The frame's origin is opaque, so a target origin cannot name it.
|
|
130
|
+
target.postMessage({ protocol: FRAME_PROTOCOL, id, method, params }, "*")
|
|
131
|
+
})
|
|
132
|
+
}, [])
|
|
133
|
+
useImperativeHandle(handle, () => ({ send }), [send])
|
|
134
|
+
|
|
135
|
+
// A frame that loads again, or goes, answers nothing it was asked before.
|
|
136
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: each new source is a new frame.
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
const requests = pending.current
|
|
139
|
+
return () => {
|
|
140
|
+
for (const request of requests.values()) {
|
|
141
|
+
request.reject(new Error("[SixbApp] The frame closed before it answered."))
|
|
142
|
+
}
|
|
143
|
+
requests.clear()
|
|
144
|
+
}
|
|
145
|
+
}, [source])
|
|
146
|
+
|
|
147
|
+
const sendTheme = useCallback(async () => {
|
|
148
|
+
const host = iframe.current?.parentElement
|
|
149
|
+
if (!host) return
|
|
150
|
+
const style = getComputedStyle(host)
|
|
151
|
+
const tokens: Record<string, string> = {}
|
|
152
|
+
for (const token of FRAME_THEME_TOKENS) {
|
|
153
|
+
const value = style.getPropertyValue(token).trim()
|
|
154
|
+
if (value) tokens[token] = value
|
|
155
|
+
}
|
|
156
|
+
const dark = host.closest(".dark, .light")?.classList.contains("dark") ?? false
|
|
157
|
+
await send("theme", { tokens, dark }).catch(() => {})
|
|
158
|
+
}, [send])
|
|
159
|
+
|
|
160
|
+
useEffect(
|
|
161
|
+
() =>
|
|
162
|
+
onFrameMessage((message) => {
|
|
163
|
+
// Only the frame this component holds speaks to it.
|
|
164
|
+
if (!iframe.current || message.source !== iframe.current.contentWindow) return
|
|
165
|
+
const data = message.data as Record<string, unknown> | null
|
|
166
|
+
if (!data || data.protocol !== FRAME_PROTOCOL) return
|
|
167
|
+
if (typeof data.id === "number") {
|
|
168
|
+
const request = pending.current.get(data.id)
|
|
169
|
+
pending.current.delete(data.id)
|
|
170
|
+
if (typeof data.error === "string") request?.reject(new Error(data.error))
|
|
171
|
+
else request?.resolve()
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
const event = parseFrameEvent(data)
|
|
175
|
+
if (!event) return
|
|
176
|
+
if (event.event === "ready") {
|
|
177
|
+
const loaded = sourceRef.current ?? null
|
|
178
|
+
setReady(loaded)
|
|
179
|
+
sendTheme().then(() => setShown(loaded))
|
|
180
|
+
}
|
|
181
|
+
onEventRef.current?.(event)
|
|
182
|
+
}),
|
|
183
|
+
[sendTheme]
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
// A ready frame has the theme as it was then. The app's mode changes the class on <html>, and an
|
|
187
|
+
// artifact's own theme arrives with its file and changes the classes and tokens around the
|
|
188
|
+
// frame: either sends it again.
|
|
189
|
+
const isReady = source !== undefined && ready === source
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
if (!isReady) return
|
|
192
|
+
return onAppThemeChange(() => {
|
|
193
|
+
sendTheme()
|
|
194
|
+
})
|
|
195
|
+
}, [isReady, sendTheme])
|
|
196
|
+
const artifactTheme = useArtifactTheme(version)
|
|
197
|
+
const themed = useRef(artifactTheme)
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
if (themed.current === artifactTheme) return
|
|
200
|
+
themed.current = artifactTheme
|
|
201
|
+
if (isReady) sendTheme()
|
|
202
|
+
}, [artifactTheme, isReady, sendTheme])
|
|
203
|
+
|
|
204
|
+
// A picture of the deck takes no focus, and neither does what it holds: `tabIndex` alone would
|
|
205
|
+
// leave its links in the page's tab order.
|
|
206
|
+
const attach = useCallback(
|
|
207
|
+
(element: HTMLIFrameElement | null) => {
|
|
208
|
+
iframe.current = element
|
|
209
|
+
if (element && decorative) element.inert = true
|
|
210
|
+
},
|
|
211
|
+
[decorative]
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
if (!reportsFailure || !source || ready === source) return
|
|
216
|
+
const timer = setTimeout(() => setTimedOut(source), READY_TIMEOUT_MS)
|
|
217
|
+
return () => clearTimeout(timer)
|
|
218
|
+
}, [reportsFailure, source, ready])
|
|
219
|
+
// A link that fails for a later mount leaves a frame that has one as it is.
|
|
220
|
+
const failed =
|
|
221
|
+
reportsFailure && (source === undefined ? frame.isError : timedOut === source && !isReady)
|
|
222
|
+
|
|
223
|
+
return (
|
|
224
|
+
<div className={cn("relative min-h-0 min-w-0", className)}>
|
|
225
|
+
{failed ? <div className="absolute inset-0 flex">{failure}</div> : fallback}
|
|
226
|
+
{source ? (
|
|
227
|
+
<iframe
|
|
228
|
+
ref={attach}
|
|
229
|
+
key={source}
|
|
230
|
+
src={source}
|
|
231
|
+
title={title}
|
|
232
|
+
loading={reportsFailure ? "eager" : "lazy"}
|
|
233
|
+
className={cn(
|
|
234
|
+
"absolute inset-0 size-full border-0 bg-transparent transition-opacity duration-200 ease-out motion-reduce:transition-none",
|
|
235
|
+
shown === source ? "opacity-100" : "opacity-0"
|
|
236
|
+
)}
|
|
237
|
+
sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox allow-modals"
|
|
238
|
+
referrerPolicy="no-referrer"
|
|
239
|
+
allow="fullscreen"
|
|
240
|
+
{...(decorative
|
|
241
|
+
? { tabIndex: -1, "aria-hidden": true, style: { pointerEvents: "none" } }
|
|
242
|
+
: {})}
|
|
243
|
+
/>
|
|
244
|
+
) : null}
|
|
245
|
+
{overlay && source && shown === source ? (
|
|
246
|
+
<div className="pointer-events-none absolute inset-0 overflow-hidden">{overlay}</div>
|
|
247
|
+
) : null}
|
|
248
|
+
</div>
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** The frame's entry on the API, which may be another origin than the app's. */
|
|
253
|
+
function frameUrl(path: string, entry: string): string {
|
|
254
|
+
const base = client.getConfig().baseUrl || window.location.origin
|
|
255
|
+
return new URL(`${path}${entry.split("/").map(encodeURIComponent).join("/")}`, base).toString()
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* One listener on the page for every frame mounted, however many a deck's filmstrip holds: the
|
|
260
|
+
* first subscriber attaches it, and the last to leave takes it away.
|
|
261
|
+
*/
|
|
262
|
+
function shared<Value>(attach: (dispatch: (value: Value) => void) => () => void) {
|
|
263
|
+
const listeners = new Set<(value: Value) => void>()
|
|
264
|
+
let detach: (() => void) | null = null
|
|
265
|
+
return (listener: (value: Value) => void): (() => void) => {
|
|
266
|
+
listeners.add(listener)
|
|
267
|
+
detach ??= attach((value) => {
|
|
268
|
+
for (const each of listeners) each(value)
|
|
269
|
+
})
|
|
270
|
+
return () => {
|
|
271
|
+
listeners.delete(listener)
|
|
272
|
+
if (listeners.size > 0) return
|
|
273
|
+
detach?.()
|
|
274
|
+
detach = null
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const onFrameMessage = shared<MessageEvent>((dispatch) => {
|
|
280
|
+
window.addEventListener("message", dispatch)
|
|
281
|
+
return () => window.removeEventListener("message", dispatch)
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
const onAppThemeChange = shared<void>((dispatch) => {
|
|
285
|
+
const observer = new MutationObserver(() => dispatch())
|
|
286
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] })
|
|
287
|
+
return () => observer.disconnect()
|
|
288
|
+
})
|