mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
feat(app): ship the media panel without the session_media flag
This commit is contained in:
-1
@@ -2551,7 +2551,6 @@ export type ConfigEntry =
|
||||
media_blob?: boolean
|
||||
schedules?: boolean
|
||||
artifacts?: boolean
|
||||
session_media?: boolean
|
||||
part_rows?: boolean
|
||||
image_generate?: boolean | { model?: string | { providerID: string; model: string; variant?: string } }
|
||||
subagent_depth?: number
|
||||
|
||||
@@ -4,7 +4,6 @@ import { define } from "@opencode/plugin/effect/plugin"
|
||||
import { SessionMedia } from "@opencode/schema/session-media"
|
||||
import { SessionMessage } from "@opencode/schema/session-message"
|
||||
import { DateTime, Effect } from "effect"
|
||||
import { Flag } from "../flag.js"
|
||||
import { Session } from "../session.js"
|
||||
import { SessionSchema } from "../session/schema.js"
|
||||
import { collect } from "./media/collect.js"
|
||||
@@ -13,13 +12,12 @@ import { collect } from "./media/collect.js"
|
||||
export const DEFAULT_LIMIT = 200
|
||||
|
||||
/**
|
||||
* The Media panel's server half, behind the `session_media` flag: it reads a session's history a page at a time and
|
||||
* The Media panel's server half: it reads a session's history a page at a time and
|
||||
* returns the images, videos and links in it, so the app lists a whole session without loading its messages.
|
||||
*/
|
||||
export const Plugin = define({
|
||||
id: "opencode.media",
|
||||
effect: Effect.fn(function* (ctx) {
|
||||
if (!(yield* Flag.enabled("session_media"))) return
|
||||
const session = yield* Session.Service
|
||||
|
||||
yield* ctx.rpc
|
||||
|
||||
@@ -1,26 +1,13 @@
|
||||
import { lazy, onCleanup, Suspense } from "solid-js"
|
||||
import { Icon } from "@opencode/ui/icon"
|
||||
import type { ConfigEntry } from "@opencode/client/promise"
|
||||
import {
|
||||
Command,
|
||||
createKeyed,
|
||||
MenuItem,
|
||||
Panel,
|
||||
Style,
|
||||
type MountedSession,
|
||||
type PanelTab,
|
||||
type Plugin,
|
||||
} from "@opencode/plugin/gui"
|
||||
import { Command, MenuItem, Panel, Style, type PanelTab, type Plugin } from "@opencode/plugin/gui"
|
||||
import { onIdle } from "@opencode/plugin/gui/builtin"
|
||||
import type Media from "./index"
|
||||
import styles from "./media.css?inline"
|
||||
|
||||
const TAB = "main"
|
||||
|
||||
/**
|
||||
* The session's Media panel: the images, videos and links the user and the agent shared, behind the
|
||||
* `session_media` feature flag of the session's directory. Turning the flag off stops listing the tab, which closes it.
|
||||
*/
|
||||
/** The session's Media panel: the images, videos and links the user and the agent shared. */
|
||||
const setup: Plugin.Setup<typeof Media> = (ctx) => {
|
||||
const layout = ctx.layout
|
||||
const sessions = ctx.sessions
|
||||
@@ -31,31 +18,12 @@ const setup: Plugin.Setup<typeof Media> = (ctx) => {
|
||||
onIdle(() => {
|
||||
const session = sessions.current()
|
||||
|
||||
if (session && enabled(session)) void MediaPanel.preload()
|
||||
if (session) void MediaPanel.preload()
|
||||
}),
|
||||
)
|
||||
|
||||
ctx.add(Style, styles)
|
||||
|
||||
// The flag lives in the session directory's config, which only some screens load; the panel needs it on every one.
|
||||
createKeyed(
|
||||
() => {
|
||||
const session = sessions.current()
|
||||
|
||||
return session && { server: session.server, directory: session.directory, connected: session.server.connected }
|
||||
},
|
||||
(current) => {
|
||||
if (current?.connected)
|
||||
void current.server.data.location.config.sync({ directory: current.directory }).catch(() => {})
|
||||
},
|
||||
{
|
||||
equals: (previous, next) =>
|
||||
previous?.server === next?.server &&
|
||||
previous?.directory === next?.directory &&
|
||||
previous?.connected === next?.connected,
|
||||
},
|
||||
)
|
||||
|
||||
// One tab object for every session, so a session switch never renders its trigger again.
|
||||
const tab: PanelTab = {
|
||||
id: TAB,
|
||||
@@ -73,7 +41,7 @@ const setup: Plugin.Setup<typeof Media> = (ctx) => {
|
||||
ctx.add(Panel, {
|
||||
id: TAB,
|
||||
region: "side",
|
||||
list: (input) => (input.open.includes(TAB) && enabled(input.session) ? [tab] : []),
|
||||
list: (input) => (input.open.includes(TAB) ? [tab] : []),
|
||||
render: (props) => (
|
||||
<Suspense>
|
||||
<MediaPanel session={props.session} />
|
||||
@@ -84,7 +52,7 @@ const setup: Plugin.Setup<typeof Media> = (ctx) => {
|
||||
const available = () => {
|
||||
const session = sessions.current()
|
||||
|
||||
return !!session && !layout.narrow() && enabled(session)
|
||||
return !!session && !layout.narrow()
|
||||
}
|
||||
|
||||
const show = () => {
|
||||
@@ -93,7 +61,6 @@ const setup: Plugin.Setup<typeof Media> = (ctx) => {
|
||||
if (session && available()) layout.open(key, session, { tab: "select" })
|
||||
}
|
||||
|
||||
// Listed only while the flag is on, so a release build never offers it.
|
||||
ctx.add(Command, (): Command | undefined =>
|
||||
available()
|
||||
? { id: "open", title: ctx.t("command.open"), group: ctx.t("command.category.view"), editable: true, run: show }
|
||||
@@ -118,28 +85,4 @@ const setup: Plugin.Setup<typeof Media> = (ctx) => {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether `session_media` is on where the session lives, as Core's `Flag.resolve` decides it from config: the
|
||||
* highest-priority document that sets `experimental` names it, else `all_flags`, else it is on in local and dev
|
||||
* builds. `OPENCODE_FLAGS` only reaches the server, so the app cannot see it.
|
||||
*/
|
||||
function enabled(session: MountedSession) {
|
||||
const entries = session.server.data.location.config.list({ directory: session.directory }) ?? []
|
||||
const configured = latest(entries, () => true)?.session_media
|
||||
|
||||
if (configured !== undefined) return configured
|
||||
|
||||
if (latest(entries, (experimental) => experimental.all_flags !== undefined)?.all_flags === true) return true
|
||||
|
||||
return import.meta.env.DEV || ["local", "dev"].includes(import.meta.env.VITE_OPENCODE_CHANNEL ?? "")
|
||||
}
|
||||
|
||||
type Experimental = NonNullable<Extract<ConfigEntry, { type: "document" }>["info"]["experimental"]>
|
||||
|
||||
function latest(entries: readonly ConfigEntry[], match: (experimental: Experimental) => boolean) {
|
||||
return entries
|
||||
.flatMap((entry) => (entry.type === "document" && entry.info.experimental ? [entry.info.experimental] : []))
|
||||
.findLast(match)
|
||||
}
|
||||
|
||||
export default setup
|
||||
|
||||
Generated
-3
@@ -16673,9 +16673,6 @@
|
||||
"artifacts": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"session_media": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"part_rows": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
@@ -15,7 +15,5 @@ export const registry = {
|
||||
media_blob: "Store new session media once in a deduplicated blob table instead of inline in every message row.",
|
||||
schedules: "Enable experimental scheduled tasks that wake a session with a prompt.",
|
||||
artifacts: "Enable experimental artifacts backed by pluggable providers.",
|
||||
session_media:
|
||||
"Show a Media panel in the desktop and web app that lists the images, videos and links shared in a session, by you or the agent.",
|
||||
} as const satisfies Record<string, string>
|
||||
export type Key = keyof typeof registry
|
||||
|
||||
@@ -80,7 +80,7 @@ export const MAX_LIMIT = 500
|
||||
/**
|
||||
* Experimental: may change without compatibility guarantees.
|
||||
*
|
||||
* The Media panel's RPC, behind the `session_media` flag. `list` reads up to `limit` of a session's messages, newest
|
||||
* The Media panel's RPC. `list` reads up to `limit` of a session's messages, newest
|
||||
* first, from the newest or from `cursor` (a page's `next`), and returns the images, videos and links they carry. The
|
||||
* schemas are Standard Schemas too, so Promise clients can call it.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user