Merge branch 'feat/session-workspace-root' into feat/session-workspace-root-consumers
This commit is contained in:
commit
f9eb524891
1155 files changed
+31527
-9869
No files matched your search
@@ -1,13 +1,22 @@
|
||||
/** File navigation feedback belongs to the individual inline reference that requested it. */
|
||||
import { useState } from 'react'
|
||||
import type { UserTextNodeProps } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
||||
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import { Button, Modal, ReferenceChip } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { HostObservable, InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import { Button, Modal, ReferenceChip, UserTextRun } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { NS } from './locales.ts'
|
||||
import type { PathPresence } from './path-presence.ts'
|
||||
import type {} from './user-text-rules.ts'
|
||||
|
||||
/** Host-confirmed presence of mention paths in the rendering Session. */
|
||||
export interface PathPresenceInjected {
|
||||
readonly keyedHooks: {
|
||||
/** Presence of one decoded mention path; subscribing starts its Host stat. */
|
||||
readonly pathPresence: (path: string) => HostObservable<PathPresence | undefined>
|
||||
}
|
||||
}
|
||||
|
||||
/** Session-authorized synchronous navigation; document reading belongs to the preview host. */
|
||||
export interface FileReferenceInjected {
|
||||
export interface FileReferenceInjected extends PathPresenceInjected {
|
||||
/**
|
||||
* Open or reveal a file in the current Sidebar using the originating Session's authority.
|
||||
* @param path - decoded path from the reference.
|
||||
@@ -20,15 +29,21 @@ export interface FileReferenceInjected {
|
||||
|
||||
type FileReferenceProps = UserTextNodeProps<'file'> & InjectFace<FileReferenceInjected> & PropsLocale<typeof NS>
|
||||
|
||||
type FolderReferenceProps = UserTextNodeProps<'folder'> & InjectFace<PathPresenceInjected>
|
||||
|
||||
/**
|
||||
* Render a file chip and contain synchronous navigation failures without hiding the reference.
|
||||
* @param props - JSON node, interaction policy, Session-authorized navigation, and locale seat.
|
||||
* @returns an inline chip and, after a navigation failure, its body-portaled dialog.
|
||||
* Render a file chip once the Host confirms its path exists, and contain synchronous navigation failures without hiding the reference.
|
||||
* @param props - JSON node, interaction policy, Session-authorized navigation and presence, and locale seat.
|
||||
* @returns the original spelling until confirmation; afterwards an inline chip and, after a navigation failure, its body-portaled dialog.
|
||||
*/
|
||||
export function FileReference({ node, raw, interactive, openFile, resolveFilePath, sessionId, useContextMenu, t }: FileReferenceProps) {
|
||||
export function FileReference({
|
||||
node, raw, interactive, openFile, resolveFilePath, sessionId, useContextMenu, usePathPresence, t,
|
||||
}: FileReferenceProps) {
|
||||
const { getTriggerProps } = useContextMenu()
|
||||
const [failedPath, setFailedPath] = useState<string | null>(null)
|
||||
const { path, label } = node.data
|
||||
const presence = usePathPresence(path)
|
||||
if (presence !== 'present') return <UserTextRun text={raw} />
|
||||
const close = () => { setFailedPath(null) }
|
||||
const open = () => {
|
||||
try {
|
||||
@@ -62,10 +77,12 @@ export function FileReference({ node, raw, interactive, openFile, resolveFilePat
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a directory as a label, even when the containing text permits file navigation.
|
||||
* @param props - resolved directory data and the original reference spelling.
|
||||
* @returns an inline non-interactive chip.
|
||||
* Render a directory as a label once the Host confirms its path exists, even when the containing text permits file navigation.
|
||||
* @param props - directory data, the original reference spelling, and Session-scoped presence.
|
||||
* @returns the original spelling until confirmation, then an inline non-interactive chip.
|
||||
*/
|
||||
export function FolderReference({ node, raw }: UserTextNodeProps<'folder'>) {
|
||||
return <ReferenceChip appearance="folder" label={node.data.label} title={raw} />
|
||||
export function FolderReference({ node, raw, usePathPresence }: FolderReferenceProps) {
|
||||
return usePathPresence(node.data.path) === 'present'
|
||||
? <ReferenceChip appearance="folder" label={node.data.label} title={raw} />
|
||||
: <UserTextRun text={raw} />
|
||||
}
|
||||
@@ -11,6 +11,11 @@
|
||||
* workspace is not the current one. A session is dated from the Host session
|
||||
* list, so the `@` menu and the session list never disagree about its age.
|
||||
*
|
||||
* A file or folder mention in sent text renders as a chip only after the
|
||||
* Session's filesystem confirms the path exists; picking a listed candidate
|
||||
* confirms it, and any other mention stays original text until a Host stat
|
||||
* answers.
|
||||
*
|
||||
* @module @deepseek-ai/dsh-client-ui-reference/client
|
||||
*/
|
||||
// Type-only: pulls the generated Remote API and ctx.remote merge through the Client assembly boundary.
|
||||
@@ -24,8 +29,11 @@ import type { ISessions } from '@deepseek-ai/dsh-api-session-controller/client'
|
||||
import { sessionDirectory } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import { relativeTime } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { UserTextNodeProps } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
||||
import { FileReference, FolderReference, type FileReferenceInjected } from './FileReference.tsx'
|
||||
import { fileReferenceRule, folderReferenceRule } from './user-text-rules.ts'
|
||||
import {
|
||||
FileReference, FolderReference, type FileReferenceInjected, type PathPresenceInjected,
|
||||
} from './FileReference.tsx'
|
||||
import { createPathPresence, type MentionSessionId } from './path-presence.ts'
|
||||
import { fileReferenceRule, folderReferenceRule, mentionPath } from './user-text-rules.ts'
|
||||
export type {} from './user-text-rules.ts'
|
||||
import type {
|
||||
ClientSessionContext, InputTriggerCrumb, InputTriggerServiceContract, InputTriggerSource,
|
||||
@@ -46,7 +54,7 @@ declare module '@deepseek-ai/dsh-api-session-controller/client' {
|
||||
/** Required services: the trigger registry, the Remote namespaces, and the copy. */
|
||||
export const inject = [
|
||||
'inputTriggers', 'locale', 'sessions', 'remote', 'remote.fileReferences',
|
||||
'remote.sessionReferenceResolver', 'sidebarRight', 'slots', 'uiConversation',
|
||||
'remote.sessionReferenceResolver', 'remote.workspaceFiles', 'sidebarRight', 'slots', 'uiConversation',
|
||||
]
|
||||
|
||||
/**
|
||||
@@ -57,19 +65,27 @@ export function apply(ctx: ClientContext): void {
|
||||
ctx.effect(() => ctx.locale.register(NS, { zh, en, ja, es, fr, de, ru, pt }), 'ui-reference: dictionaries')
|
||||
const t = ctx.locale.bind(NS)
|
||||
const sessions = ctx.get('sessions') as ISessions
|
||||
const presence = createPathPresence((sessionId, path, signal) => ctx.remote.workspaceFiles.stat(sessionId, path, signal))
|
||||
ctx.effect(() => () => { presence.dispose() }, 'ui-reference: mention path stats')
|
||||
const presenceFor = (sessionId: MentionSessionId): PathPresenceInjected => ({
|
||||
keyedHooks: { pathPresence: path => presence.source(sessionId, path) },
|
||||
})
|
||||
ctx.uiConversation.userText.register(fileReferenceRule)
|
||||
ctx.uiConversation.userText.register(folderReferenceRule)
|
||||
ctx.slots.inject('conversation.user.text.node', function* () {
|
||||
yield ctx.slots.register({
|
||||
name: 'conversation.user.text.node', key: 'file', priority: 100, locale: NS,
|
||||
inject: (sessionId: UserTextNodeProps<'file'>['sessionId']): FileReferenceInjected => ({
|
||||
...presenceFor(sessionId),
|
||||
resolveFilePath: path => resolveWorkspacePath(sessionDirectory(sessions, sessionId), path),
|
||||
openFile: (path) => {
|
||||
ctx.sidebarRight.openResource(fileAddressFor(sessionId, sessionDirectory(sessions, sessionId), path))
|
||||
},
|
||||
}),
|
||||
}, FileReference)
|
||||
yield ctx.slots.register({ name: 'conversation.user.text.node', key: 'folder', priority: 100 }, FolderReference)
|
||||
yield ctx.slots.register({
|
||||
name: 'conversation.user.text.node', key: 'folder', priority: 100, inject: presenceFor,
|
||||
}, FolderReference)
|
||||
})
|
||||
const source: InputTriggerSource = {
|
||||
trigger: '@',
|
||||
@@ -129,7 +145,7 @@ export function apply(ctx: ClientContext): void {
|
||||
header(_session: ClientSessionContext, req) {
|
||||
return crumbsFor(req.query, req.quoted === true, req.drilled, t)
|
||||
},
|
||||
onPick({ candidate, action }) {
|
||||
onPick({ candidate, session, action }) {
|
||||
const value = parseCandidate(candidate.value)
|
||||
if (value?.kind === 'file') {
|
||||
// A directory row carries two verbs: the settling pick resolves the
|
||||
@@ -139,6 +155,8 @@ export function apply(ctx: ClientContext): void {
|
||||
if (value.fileKind === 'directory' && action === 'drill') {
|
||||
return { text: value.mention, continue: true }
|
||||
}
|
||||
// The Host has just listed this path, so its sent echo renders as a chip without a stat.
|
||||
presence.confirm(session.sessionId, mentionPath(value.mention))
|
||||
return {
|
||||
insert: {
|
||||
source: 'reference',
|
||||
@@ -164,7 +182,7 @@ export function apply(ctx: ClientContext): void {
|
||||
},
|
||||
openReference(session, { ref, appearance }) {
|
||||
if (appearance !== 'file') return false
|
||||
const path = ref.startsWith('@"') ? ref.slice(2, -1) : ref.slice(1)
|
||||
const path = mentionPath(ref)
|
||||
ctx.sidebarRight.openResource(fileAddressFor(session.sessionId, sessionDirectory(sessions, session.sessionId), path))
|
||||
return true
|
||||
},
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* Session-scoped Host confirmation that a mentioned path exists.
|
||||
*
|
||||
* Each Session and path pair is stat'ed at most once while the owning plugin
|
||||
* is live. Only a definitive Host answer is retained; any other failure leaves
|
||||
* the pair unconfirmed, and the next subscriber asks again. Retained answers
|
||||
* are not refreshed when the path is created or removed later. Entries live as
|
||||
* long as the plugin, one per distinct mention the client has rendered. Each
|
||||
* unconfirmed pair starts its own Host request when first subscribed; nothing
|
||||
* bounds how many are outstanding at once.
|
||||
*/
|
||||
import type { UserTextNodeProps } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
||||
import type { WorkspaceFileStat } from '@deepseek-ai/dsh-api-remotes/client'
|
||||
import type { HostObservable } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
||||
|
||||
/** Session whose filesystem resolves a mention. */
|
||||
export type MentionSessionId = UserTextNodeProps<'file'>['sessionId']
|
||||
|
||||
/** Host answer for one mentioned path; `undefined` means unconfirmed. */
|
||||
export type PathPresence = 'present' | 'absent'
|
||||
|
||||
/**
|
||||
* Session-authorized stat of one path, absolute or relative to the Session's workspace root.
|
||||
* @param sessionId - Session whose filesystem resolves the path.
|
||||
* @param path - path as the mention spells it.
|
||||
* @param signal - cancellation owned by the presence sources.
|
||||
* @returns the regular file's metadata, or the Host's typed failure.
|
||||
*/
|
||||
export type PathStat = (
|
||||
sessionId: MentionSessionId,
|
||||
path: string,
|
||||
signal: AbortSignal,
|
||||
) => Promise<RemoteResult<WorkspaceFileStat>>
|
||||
|
||||
/** Presence sources shared by every mention one plugin instance renders. */
|
||||
export interface PathPresenceSources {
|
||||
/**
|
||||
* Observe one path; the first subscription to an unconfirmed path starts its Host stat.
|
||||
* @param sessionId - Session whose filesystem resolves the path.
|
||||
* @param path - decoded mention path.
|
||||
* @returns the same source for the same pair until disposal.
|
||||
*/
|
||||
source(sessionId: MentionSessionId, path: string): HostObservable<PathPresence | undefined>
|
||||
/**
|
||||
* Record a path the Host has just listed, such as a picked completion candidate.
|
||||
* @param sessionId - Session whose filesystem listed the path.
|
||||
* @param path - decoded mention path.
|
||||
*/
|
||||
confirm(sessionId: MentionSessionId, path: string): void
|
||||
/** Abort outstanding stats; later subscriptions start none. */
|
||||
dispose(): void
|
||||
}
|
||||
|
||||
interface Entry {
|
||||
presence: PathPresence | undefined
|
||||
probing: boolean
|
||||
readonly listeners: Set<() => void>
|
||||
readonly source: HostObservable<PathPresence | undefined>
|
||||
}
|
||||
|
||||
/**
|
||||
* Classify one stat. A directory, a symbolic link whatever it points to, or
|
||||
* another non-regular entry still exists; failures that do not describe the
|
||||
* path leave it unconfirmed.
|
||||
* @param result - Host stat result.
|
||||
* @returns the definitive presence, or undefined.
|
||||
*/
|
||||
function presenceOf(result: RemoteResult<WorkspaceFileStat>): PathPresence | undefined {
|
||||
if (result.ok) return 'present'
|
||||
switch (result.error.code) {
|
||||
case 'workspace-file/not-regular-file':
|
||||
return 'present'
|
||||
case 'workspace-file/not-found':
|
||||
return 'absent'
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create presence sources over one stat function.
|
||||
* @param stat - Session-authorized Host stat.
|
||||
* @returns sources the caller disposes with its plugin.
|
||||
*/
|
||||
export function createPathPresence(stat: PathStat): PathPresenceSources {
|
||||
const lifetime = new AbortController()
|
||||
const entries = new Map<string, Entry>()
|
||||
|
||||
const publish = (entry: Entry, presence: PathPresence) => {
|
||||
entry.presence = presence
|
||||
for (const listener of [...entry.listeners]) listener()
|
||||
}
|
||||
|
||||
const probe = (entry: Entry, sessionId: MentionSessionId, path: string) => {
|
||||
if (entry.probing || entry.presence !== undefined || lifetime.signal.aborted) return
|
||||
entry.probing = true
|
||||
// Cancellation and carrier faults resolve as failures. Only a Remote
|
||||
// assembly fault rejects: it stays an unhandled rejection so the fault is
|
||||
// reported, and the pair stays unconfirmed for the next subscriber.
|
||||
void stat(sessionId, path, lifetime.signal).then((result) => {
|
||||
const presence = presenceOf(result)
|
||||
// A confirmation recorded while this stat was outstanding is newer.
|
||||
if (presence === undefined || entry.presence !== undefined || lifetime.signal.aborted) return
|
||||
publish(entry, presence)
|
||||
}).finally(() => { entry.probing = false })
|
||||
}
|
||||
|
||||
const entryFor = (sessionId: MentionSessionId, path: string): Entry => {
|
||||
const key = JSON.stringify([sessionId, path])
|
||||
const existing = entries.get(key)
|
||||
if (existing !== undefined) return existing
|
||||
const entry: Entry = {
|
||||
presence: undefined,
|
||||
probing: false,
|
||||
listeners: new Set(),
|
||||
source: {
|
||||
getSnapshot: () => entry.presence,
|
||||
subscribe: (listener) => {
|
||||
entry.listeners.add(listener)
|
||||
probe(entry, sessionId, path)
|
||||
return () => { entry.listeners.delete(listener) }
|
||||
},
|
||||
},
|
||||
}
|
||||
entries.set(key, entry)
|
||||
return entry
|
||||
}
|
||||
|
||||
return {
|
||||
source: (sessionId, path) => entryFor(sessionId, path).source,
|
||||
confirm(sessionId, path) {
|
||||
const entry = entryFor(sessionId, path)
|
||||
if (entry.presence !== 'present') publish(entry, 'present')
|
||||
},
|
||||
dispose() {
|
||||
lifetime.abort()
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
/** Forward file and folder recognition in original text, without Facts or discovery. */
|
||||
/**
|
||||
* Forward file and folder mention candidates in original text, without Facts or discovery.
|
||||
* The node components decide whether a candidate names an existing path.
|
||||
*/
|
||||
import type { UserTextRule } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
||||
|
||||
interface PathReferenceData {
|
||||
@@ -13,6 +16,15 @@ declare module '@deepseek-ai/dsh-client-ui-conversation/client' {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the path a complete `@path` or `@"quoted path"` mention names.
|
||||
* @param mention - mention spelling starting with `@`, without trailing sentence punctuation.
|
||||
* @returns the path that file and folder nodes carry.
|
||||
*/
|
||||
export function mentionPath(mention: string): string {
|
||||
return mention.slice(1).replace(/^"|"$/gu, '')
|
||||
}
|
||||
|
||||
function nextPath(text: string, from: number, folder: boolean) {
|
||||
const tokens = /(?<!\S)(@"[^"\n]+"|@[^\s]+)/gu
|
||||
tokens.lastIndex = from
|
||||
@@ -20,7 +32,7 @@ function nextPath(text: string, from: number, folder: boolean) {
|
||||
const token = match[0]
|
||||
const raw = token.startsWith('@"') ? token : token.replace(/[.,;:!?,。;:!?]+$/u, '')
|
||||
if (raw.length <= 1) continue
|
||||
const path = raw.slice(1).replace(/^"|"$/gu, '')
|
||||
const path = mentionPath(raw)
|
||||
if (path.endsWith('/') !== folder) continue
|
||||
const label = path.split(/[\\/]/u).filter(Boolean).at(-1) ?? raw.slice(1)
|
||||
return { start: match.index, end: match.index + raw.length, data: { path, label } }
|
||||
|
||||
Reference in new issue
Block a user