Add account-backed artifact sharing (#13012)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
export const REMOTE_ARTIFACT_INPUT_ENV = 'ORCA_REMOTE_ARTIFACT_INPUT'
|
||||
|
||||
export type RemoteArtifactInput = {
|
||||
sourceKey: string
|
||||
fileName: string
|
||||
contentType?: 'text/html' | 'text/markdown'
|
||||
}
|
||||
|
||||
export function normalizeRemoteArtifactInput(value: unknown): RemoteArtifactInput | null {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
||||
return null
|
||||
}
|
||||
const input = value as Partial<RemoteArtifactInput>
|
||||
if (
|
||||
typeof input.sourceKey !== 'string' ||
|
||||
!input.sourceKey ||
|
||||
typeof input.fileName !== 'string' ||
|
||||
!input.fileName ||
|
||||
(input.contentType !== undefined && !['text/html', 'text/markdown'].includes(input.contentType))
|
||||
) {
|
||||
return null
|
||||
}
|
||||
return input as RemoteArtifactInput
|
||||
}
|
||||
|
||||
export function parseRemoteArtifactInput(value: string | undefined): RemoteArtifactInput | null {
|
||||
if (!value) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
return normalizeRemoteArtifactInput(JSON.parse(value))
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { open } from 'node:fs/promises'
|
||||
|
||||
export type ArtifactFileReadResult =
|
||||
| { status: 'ok'; content: string }
|
||||
| { status: 'not-file' }
|
||||
| { status: 'empty' }
|
||||
| { status: 'too-large' }
|
||||
|
||||
export async function readArtifactFileWithinLimit(
|
||||
path: string,
|
||||
maxBytes: number
|
||||
): Promise<ArtifactFileReadResult> {
|
||||
const handle = await open(path, 'r').catch(() => null)
|
||||
if (!handle) {
|
||||
return { status: 'not-file' }
|
||||
}
|
||||
try {
|
||||
const fileStats = await handle.stat().catch(() => null)
|
||||
if (!fileStats?.isFile()) {
|
||||
return { status: 'not-file' }
|
||||
}
|
||||
if (fileStats.size > maxBytes) {
|
||||
return { status: 'too-large' }
|
||||
}
|
||||
const buffer = Buffer.allocUnsafe(maxBytes + 1)
|
||||
let bytesRead = 0
|
||||
while (bytesRead < buffer.length) {
|
||||
const result = await handle.read(buffer, bytesRead, buffer.length - bytesRead, null)
|
||||
if (result.bytesRead === 0) {
|
||||
break
|
||||
}
|
||||
bytesRead += result.bytesRead
|
||||
}
|
||||
if (bytesRead > maxBytes) {
|
||||
return { status: 'too-large' }
|
||||
}
|
||||
if (bytesRead === 0) {
|
||||
return { status: 'empty' }
|
||||
}
|
||||
return { status: 'ok', content: buffer.subarray(0, bytesRead).toString('utf8') }
|
||||
} finally {
|
||||
await handle.close()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
export const ARTIFACT_CLI_MAX_RPC_BYTES = 800 * 1024
|
||||
|
||||
export type ArtifactMetadata = {
|
||||
version: 1
|
||||
slug: string
|
||||
title: string | null
|
||||
originalFileName: string | null
|
||||
sourceContentType: string
|
||||
renderedContentType: 'text/html'
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
expiresAt: string
|
||||
byteSize: number
|
||||
deletedAt: string | null
|
||||
}
|
||||
|
||||
export type ArtifactListItem = {
|
||||
artifact: ArtifactMetadata
|
||||
shareUrl: string
|
||||
}
|
||||
|
||||
export type ArtifactListPage = {
|
||||
artifacts: readonly ArtifactListItem[]
|
||||
nextCursor?: string
|
||||
}
|
||||
|
||||
export type ArtifactWriteRequest = {
|
||||
sourceKey: string
|
||||
content: string
|
||||
contentType: 'text/html' | 'text/markdown'
|
||||
fileName: string
|
||||
title?: string
|
||||
apiUrl?: string
|
||||
authToken?: string
|
||||
}
|
||||
|
||||
export type ArtifactCloudOptions = {
|
||||
apiUrl?: string
|
||||
authToken?: string
|
||||
}
|
||||
|
||||
export type ArtifactListOptions = ArtifactCloudOptions & {
|
||||
cursor?: string
|
||||
}
|
||||
|
||||
export type ArtifactCloudOperation<T> =
|
||||
| { status: 'ok'; value: T }
|
||||
| { status: 'reconnect-required' }
|
||||
| { status: 'unconfigured'; message: string }
|
||||
@@ -277,6 +277,8 @@ export function getDefaultSettings(homedir: string): GlobalSettings {
|
||||
showTitlebarAppName: true,
|
||||
showTasksButton: true,
|
||||
showAutomationsButton: true,
|
||||
artifactsEnabled: true,
|
||||
showArtifactsButton: false,
|
||||
showMobileButton: true,
|
||||
showPinnedWorktreesInGroups: false,
|
||||
ctrlTabOrderMode: 'mru',
|
||||
|
||||
@@ -10,6 +10,7 @@ const TOP_LEVEL_VIEW_LOOKUP: Record<TopLevelView, true> = {
|
||||
automations: true,
|
||||
space: true,
|
||||
skills: true,
|
||||
artifacts: true,
|
||||
mobile: true
|
||||
}
|
||||
|
||||
|
||||
@@ -2901,6 +2901,10 @@ export type GlobalSettings = {
|
||||
showTasksButton: boolean
|
||||
/** Only toggles the sidebar shortcut; Automations stay reachable from Settings/View menu. */
|
||||
showAutomationsButton?: boolean
|
||||
/** Deprecated: Artifacts are always available. Use showArtifactsButton for sidebar visibility. */
|
||||
artifactsEnabled?: boolean
|
||||
/** Only toggles the sidebar shortcut; Artifacts stay reachable from Settings. */
|
||||
showArtifactsButton?: boolean
|
||||
/** Only toggles the sidebar shortcut; Orca Mobile stays reachable from Settings. */
|
||||
showMobileButton?: boolean
|
||||
/** Pinned workspaces show in one sidebar location by default; opt in to also show them in their natural groups. */
|
||||
@@ -3371,6 +3375,7 @@ export type TopLevelView =
|
||||
| 'automations'
|
||||
| 'space'
|
||||
| 'skills'
|
||||
| 'artifacts'
|
||||
| 'mobile'
|
||||
|
||||
export type PersistedUIState = {
|
||||
|
||||
Reference in New Issue
Block a user