Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,40 @@ jobs:
timeout-minutes: 5
run: node scripts/workbench/e2e-git-view.mjs

- name: Verify session project binding across two owner browsers
if: ${{ !cancelled() && steps.host_tests.outcome == 'success' }}
timeout-minutes: 5
run: node scripts/workbench/e2e-session-workspaces.mjs

- name: Select the same installed Chrome for UI and worker
run: bash scripts/workbench/ci-select-chromium.sh

- name: Verify workbench UI controlling a second sandboxed browser
timeout-minutes: 5
run: node scripts/workbench/e2e-manual-browser.mjs

packaged-session-workspaces:
name: Packaged session workspace on native amd64 Docker
if: ${{ github.event_name == 'pull_request' && github.head_ref == 'feat/web-workbench-session-workspaces' }}
runs-on: ubuntu-latest
timeout-minutes: 12
steps:
- uses: actions/checkout@v5
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v5
with:
node-version: 22
package-manager-cache: false
- name: Build the actual amd64 workbench runtime
timeout-minutes: 8
run: |
set -eu
test "$(uname -m)" = x86_64
docker build --platform linux/amd64 --target runtime -t deva-workbench:focus-verify .
- name: Verify owner bindings across new containers and a removed grant
timeout-minutes: 3
run: node scripts/workbench/container-focus-ci.mjs

sandbox:
name: Private human browser worker
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ When memory is full, the next write by the model first consolidates the existing

## Headless server workbench (fork development)

The [amd64 Docker Compose workbench](apps/headless/README.md) supports browser enrollment, the original desktop model settings, and general text conversations with shared desktop UI, streaming, cancellation and reconnect. It also includes profile and role editing, avatar management, and notes scoped to the owner, a role, or a registered project. Manual workspaces and explicit chat attachments are separate: browsing a project does not send its files to a model. Separately approved projects also have a manually activated Git view for tracked changes, branches, first-parent history and staged versus working-tree comparisons. The workbench accepts supported UTF-8 text, static images and PDFs for compatible adapters. Confirmed replies can be exported as Markdown or plain text. Desktop delivery cards are reused for scoped downloads and project file reveal. An [optional human-operated browser](apps/browser-worker/README.md) uses a separate sandboxed worker and an explicit list of sites. The base app requires neither that worker nor a running desktop. This is separate from the mobile relay; see the [parity inventory](docs/development/web-workbench/README.md) for the remaining desktop workflows.
The [amd64 Docker Compose workbench](apps/headless/README.md) supports browser enrollment, the original desktop model settings, and general text conversations with shared desktop UI, streaming, cancellation and reconnect. It also includes profile and role editing, avatar management, and notes scoped to the owner, a role, or a registered project. A conversation may keep an explicitly attached project or inherit its role’s registered project at creation. Browsing another folder is separate from changing this binding; neither operation sends files or notes to a model. Separately approved projects also have a manually activated Git view for tracked changes, branches, first-parent history and staged versus working-tree comparisons. The workbench accepts supported UTF-8 text, static images and PDFs for compatible adapters. Confirmed replies can be exported as Markdown or plain text. Desktop delivery cards are reused for scoped downloads and project file reveal. An [optional human-operated browser](apps/browser-worker/README.md) uses a separate sandboxed worker and an explicit list of sites. The base app requires neither that worker nor a running desktop. This is separate from the mobile relay; see the [parity inventory](docs/development/web-workbench/README.md) for the remaining desktop workflows.

## Build from Source

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ IM 机器人支持 `/new [角色名]`、`/list`、`/stop`、`/status`、`/help`

## 无 GUI 服务器工作台(本分支开发中)

[amd64 Docker Compose 与 Web 工作台说明](apps/headless/README.md):当前可在浏览器认领服务器、配置模型,并使用桌面同源的会话列表、编辑器及消息区进行通用文本对话;支持停止与刷新续接。网页还可以编辑个人资料、普通角色及其头像,并分别管理全局、角色和已授权项目的记忆。可手动浏览获准项目的文件,也可显式把所选文本、静态图片或兼容协议的 PDF 作为会话附件发送;浏览项目不会自动上传。管理员另外批准的仓库可手动查看已跟踪文件的改动、分支、首父提交历史,以及暂存和工作树的差异。已确认的回复可导出为 Markdown 或纯文本;桌面交付卡复用于 Web,支持按授权项目下载文件和定位。还可配置[独立人工浏览器面板](apps/browser-worker/README.md),由当前登录者接管已登记站点;实际工作器须通过 Chromium 沙箱就绪检查。它和手机版中转是两个不同部署目标;完整业务进度见[对等清单](docs/development/web-workbench/README.md)。
[amd64 Docker Compose 与 Web 工作台说明](apps/headless/README.md):当前可在浏览器认领服务器、配置模型,并使用桌面同源的会话列表、编辑器及消息区进行通用文本对话;支持停止与刷新续接。网页还可以编辑个人资料、普通角色及其头像,并分别管理全局、角色和已授权项目的记忆。可手动浏览获准项目的文件,也可显式把所选文本、静态图片或兼容协议的 PDF 作为会话附件发送;浏览项目不会自动上传。每段对话可独立关联或解除项目;从已关联标签打开文件和项目记忆,角色的新对话可继承已登记的默认项目。管理员另外批准的仓库可手动查看已跟踪文件的改动、分支、首父提交历史,以及暂存和工作树的差异。已确认的回复可导出为 Markdown 或纯文本;桌面交付卡复用于 Web,支持按授权项目下载文件和定位。还可配置[独立人工浏览器面板](apps/browser-worker/README.md),由当前登录者接管已登记站点;实际工作器须通过 Chromium 沙箱就绪检查。它和手机版中转是两个不同部署目标;完整业务进度见[对等清单](docs/development/web-workbench/README.md)。

## 从源码构建

Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/src/workbench/chat-transport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Transport } from './transport'

export const isWorkspaceRevision = (value: unknown): value is string => typeof value === 'string' && value.length === 64 && /^[a-f0-9]+$/u.test(value)

type Dictionary = Record<string, unknown>
const record = (x: unknown): x is Dictionary => typeof x === 'object' && x !== null && !Array.isArray(x)
const nullableString = (x: unknown): x is string | null => x === null || typeof x === 'string'
Expand Down Expand Up @@ -29,6 +31,7 @@ export interface ChatSummary {
personaId?: string
archived?: boolean
customTitle?: string
workspaceRevision?: string
compatibility: 'text' | 'legacy_text' | 'unsupported'
writable: boolean
}
Expand Down Expand Up @@ -83,6 +86,7 @@ function summary(value: unknown): value is Omit<ChatSummary, 'updatedAt'> {
(value.personaId === undefined || isRoleId(value.personaId)) &&
(value.archived === undefined || typeof value.archived === 'boolean') &&
(value.customTitle === undefined || typeof value.customTitle === 'string') &&
(value.workspaceRevision === undefined || isWorkspaceRevision(value.workspaceRevision)) &&
(value.compatibility === 'text' || value.compatibility === 'legacy_text' || value.compatibility === 'unsupported') &&
typeof value.writable === 'boolean'
}
Expand Down
13 changes: 11 additions & 2 deletions apps/desktop/src/workbench/library-memory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ export function LibraryMemoryPane({ api, scope, locked }: { api: Library; scope:
</div>
}

export function ProjectMemoryDialog({ api, locked, notice, onClose }: {
export function ProjectMemoryDialog({ api, locked, notice, onClose, lockedProject }: {
api: Library; locked: boolean; notice: React.ReactNode; onClose: () => void
lockedProject?: { id: string; name: string | null; signal: AbortSignal }
}): React.JSX.Element {
const { locale } = useI18n()
const c = libraryCopy(locale)
Expand All @@ -96,7 +97,15 @@ export function ProjectMemoryDialog({ api, locked, notice, onClose }: {
setWorkspaces(next)
setId((prev) => next.some((item) => item.id === prev) ? prev : '')
}))
useEffect(() => { load() }, [])
useEffect(() => { if (!lockedProject) load() }, [])
if (lockedProject) return <LibraryDialog title={c.projectMemory} testId="workbench-project-memory" onClose={onClose}>
{notice}
<div className="cf-editor wb-library__editor">
{lockedProject.name && <p className="wb-library__hint">{lockedProject.name}</p>}
{!lockedProject.signal.aborted && <LibraryMemoryPane key={lockedProject.id} api={api}
scope={{ kind: 'project', id: lockedProject.id, signal: lockedProject.signal }} locked={locked} />}
</div>
</LibraryDialog>
return <LibraryDialog title={c.projectMemory} testId="workbench-project-memory" onClose={onClose}>
{notice}
<div className="cf-editor wb-library__editor">
Expand Down
21 changes: 18 additions & 3 deletions apps/desktop/src/workbench/library-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HttpFailure, type LibraryQueue, type Revision, type Transport } from '.

export const MEMORY_TYPES = ['user', 'feedback', 'project', 'reference'] as const
export type MemoryInput = Pick<MemoryEntry, 'type' | 'title' | 'body'>
export type Scope = { kind: 'global' } | { kind: 'role' | 'project'; id: string }
export type Scope = { kind: 'global' } | { kind: 'role'; id: string } | { kind: 'project'; id: string; signal?: AbortSignal }
export type ProfileSnapshot = { profile: UserProfile; revision: Revision; imageRevision: Revision }
export type RoleImage = { image: string; revision: Revision; imageRevision: Revision }
export type MemoryState = { snapshot: MemorySnapshot; revision: Revision }
Expand Down Expand Up @@ -113,9 +113,24 @@ export function createLibrary(transport: Transport, queue: LibraryQueue) {
}
const getRoleImage = (id: string) => transport.request(`${rolePath(id)}/avatar-image`).then(parseRoleImage)

// A conversation-scoped editor may close while waiting in the owner library queue.
async function memoryRequest(scope: Scope, method: string, body?: unknown, token?: string): Promise<unknown> {
const signal = scope.kind === 'project' ? scope.signal : undefined
const ensureOpen = (): void => { if (signal?.aborted) throw new Error('Project view closed') }
ensureOpen()
try {
const value = await transport.request(memoryPath(scope), method, body, token, signal ? { signal, referrerPolicy: 'same-origin' } : undefined)
ensureOpen()
return value
} catch (error) {
ensureOpen()
throw error
}
}

function changeMemory(scope: Scope, method: 'POST' | 'DELETE', body: Record<string, unknown> & { revision: Revision }): Promise<MemoryResult> {
return queue<MemoryResult>('write', async (token) => {
const result = object(await transport.request(memoryPath(scope), method, body, token))
const result = object(await memoryRequest(scope, method, body, token))
const current = revision(result.revision)
if (result.ok === true) return { value: { ok: true, snapshot: parseMemory(result.snapshot), revision: current } }
const code = string(result.code) as MemoryErrorCode
Expand Down Expand Up @@ -174,7 +189,7 @@ export function createLibrary(transport: Transport, queue: LibraryQueue) {
workspaces: () => queue('read', async () => ({ value: array(object(await transport.request('/workspaces')).workspaces)
.map((item): WorkspaceOption => { const w = object(item); return { id: opaqueId(w.id), name: string(w.name) } }) })),
memory: (scope: Scope) => queue('read', async () => {
const result = object(await transport.request(memoryPath(scope)))
const result = object(await memoryRequest(scope, 'GET'))
return { value: { snapshot: parseMemory(result.snapshot), revision: revision(result.revision) } }
}),
writeMemory: (scope: Scope, input: MemoryInput, revision: Revision, id?: string) =>
Expand Down
70 changes: 70 additions & 0 deletions apps/desktop/src/workbench/session-workspace-transport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { isWorkspaceRevision } from './chat-transport'
import { HttpFailure, type Transport } from './transport'
import type { WorkspaceOption } from './workspace-transport'

export type AttachedWorkspace = {
id: string
name: string | null
state: 'available' | 'unavailable'
source: 'manual' | 'role'
}
export type WorkspaceBinding = { workspace: AttachedWorkspace | null; revision: string }

const record = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value)
const isWorkspaceId = (value: unknown): value is string => typeof value === 'string' && value.length === 34 &&
value.startsWith('w_') && !/[^a-f0-9]/u.test(value.slice(2))
const projectLabel = (value: unknown): value is string => typeof value === 'string' && value.length > 0 &&
value.length <= 255 && !/[\\/\x00-\x1f\x7f-\x9f]/u.test(value) && value !== '.' && value !== '..'

function parseBinding(value: unknown): WorkspaceBinding {
if (!record(value) || !isWorkspaceRevision(value.revision)) throw new Error('Invalid conversation workspace revision')
const { workspace, revision } = value
if (workspace === null) return { workspace, revision }
if (!record(workspace)) throw new Error('Invalid conversation workspace')
const { id, name, state, source } = workspace
if (!isWorkspaceId(id) || (state !== 'available' && state !== 'unavailable') ||
(source !== 'manual' && source !== 'role')) throw new Error('Invalid conversation workspace')
if (state === 'unavailable' && name === null) return { workspace: { id, name: null, state, source }, revision }
if (state !== 'available' || !projectLabel(name)) throw new Error('Invalid conversation workspace')
return { workspace: { id, name, state, source }, revision }
}

export function createSessionWorkspaceTransport(transport: Transport, csrf: string) {
function path(sid: string): string {
if (!sid || /^[A-Za-z0-9_-]{1,128}$/u.exec(sid)?.[0] !== sid) throw new Error('Invalid chat id')
return `/chats/${sid}/workspace`
}
const options = (signal: AbortSignal) => ({ signal, referrerPolicy: 'same-origin' as const })
return {
async read(sid: string, signal: AbortSignal): Promise<WorkspaceBinding> {
return parseBinding(await transport.request(path(sid), 'GET', undefined, undefined, options(signal)))
},
async patch(sid: string, revision: string, workspaceId: string | null, signal: AbortSignal): Promise<WorkspaceBinding> {
if (!csrf || !isWorkspaceRevision(revision) || (workspaceId !== null && !isWorkspaceId(workspaceId)))
throw new Error('Invalid conversation workspace selection')
const result = parseBinding(await transport.request(path(sid), 'PATCH', { revision, workspaceId }, csrf, options(signal)))
if (workspaceId === null ? result.workspace !== null : result.workspace?.id !== workspaceId || result.workspace.source !== 'manual')
throw new Error('Conversation workspace change not confirmed')
return result
},
async projects(signal: AbortSignal): Promise<WorkspaceOption[]> {
let value: unknown
try { value = await transport.request('/workspaces', 'GET', undefined, undefined, options(signal)) }
catch (error) {
// Older or unmounted catalogues may omit this route; the conversation resource is independent.
if (error instanceof HttpFailure && ([404, 405, 501].includes(error.status) || error.code === 'workspace_unavailable')) return []
throw error
}
if (!record(value) || !Array.isArray(value.workspaces)) throw new Error('Invalid workspace catalogue')
const seen = new Set<string>()
return value.workspaces.map((item) => {
if (!record(item) || !isWorkspaceId(item.id) || !projectLabel(item.name) || seen.has(item.id))
throw new Error('Invalid workspace catalogue entry')
seen.add(item.id)
return { id: item.id, name: item.name }
})
}
}
}

export type SessionWorkspaceTransport = ReturnType<typeof createSessionWorkspaceTransport>
Loading
Loading