feat(artifacts): render agent HTML files inline in the session chat

This commit is contained in:
Chris Scott authored and Chris Scott committed 2026-10-12 16:43:04 -04:00
1 parent 377e3c2784
commit f7b2ffb865
17 files changed
+579 -10

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
import type { SessionMessageAssistantTool } from '@opencode/client'
import { MANAGER_TOOL_NAME, MANAGER_TOOL_SHOW_ARTIFACT_ACTION, ShowArtifactParamsSchema } from '../schemas/internal-assistant'
import type { ShowArtifactParams } from '../schemas/internal-assistant'
/**
* Reads an assistant tool part as a completed `ocm` `show_artifact` call, or undefined for every
* other tool, action, unfinished state, and set of parameters that does not validate.
*/
export function readShowArtifactCall(part: SessionMessageAssistantTool): ShowArtifactParams | undefined {
if (part.name !== MANAGER_TOOL_NAME || part.state.status !== 'completed') return undefined
if (part.state.input.action !== MANAGER_TOOL_SHOW_ARTIFACT_ACTION) return undefined
const parsed = ShowArtifactParamsSchema.safeParse(part.state.input.params)
return parsed.success ? parsed.data : undefined
}
+2
View File
@@ -48,6 +48,8 @@ export { ClientError, isIntegrationNotFoundError, isMcpServerNotFoundError, isSe
export { assistantText, sessionIDFromEvent, toolContentText } from './content'
export { readShowArtifactCall } from './artifact'
export { configModelRef, formatOpenCodeModelRef, parseOpenCodeModelRef, selectConfiguredModelRef } from './modelRef'
export {
+28 -1
View File
@@ -5,7 +5,34 @@ export const MANAGER_TOOL_NAME = 'ocm'
export const MANAGER_TOOL_OPEN_WALKTHROUGH_ACTION = 'open_walkthrough'
export const MANAGER_TOOL_ACTIONS = ['send_notification', 'request', MANAGER_TOOL_OPEN_WALKTHROUGH_ACTION] as const
export const MANAGER_TOOL_SHOW_ARTIFACT_ACTION = 'show_artifact'
export const MANAGER_TOOL_ACTIONS = [
'send_notification',
'request',
MANAGER_TOOL_OPEN_WALKTHROUGH_ACTION,
MANAGER_TOOL_SHOW_ARTIFACT_ACTION,
] as const
export const ARTIFACT_LIMITS = {
TITLE_MAX: 120,
FILE_MAX_BYTES: 5 * 1024 * 1024,
} as const
export const ShowArtifactParamsSchema = z
.object({
title: z.string().min(1).max(ARTIFACT_LIMITS.TITLE_MAX).describe('A short title shown above the artifact.'),
path: z
.string()
.min(1)
.max(1000)
.describe(
'Path of a self-contained .html file the agent wrote, relative to the session directory or absolute inside it. Inline your own CSS and JavaScript; libraries may load from public CDNs.',
),
})
.strict()
export type ShowArtifactParams = z.infer<typeof ShowArtifactParamsSchema>
export const AssistantNotificationPrioritySchema = z.enum(['normal', 'high'])