30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
/**
|
|
* Append text to the current session's composer draft through the
|
|
* conversation service — the shared path behind the explorer's @-reference
|
|
* button and the viewer selection popup. The service is resolved lazily
|
|
* through `ctx.get` (the inject-free read the app's own plugins use); a
|
|
* missing service or scope degrades to a logged no-op, never a crash.
|
|
*/
|
|
import type { Context, SidebarConversation } from '../context-types.ts'
|
|
|
|
/**
|
|
* Append `text` to the session's composer draft (space-separated, like the
|
|
* @-mentions). Returns false — and logs — when the conversation service or
|
|
* the session scope is unavailable.
|
|
*/
|
|
export function appendToDraft(ctx: Context, sessionId: string, text: string): boolean {
|
|
try {
|
|
const actx = ctx.sessions.scope(sessionId)
|
|
if (actx === undefined) return false
|
|
const conversation = ctx.get('conversation') as SidebarConversation | undefined
|
|
if (conversation === undefined) return false
|
|
const input = conversation.input.for(actx)
|
|
const draft = input.state.getSnapshot().draft
|
|
input.setDraft(draft.trim() === '' ? text : `${draft} ${text}`)
|
|
return true
|
|
} catch (error) {
|
|
console.warn('[dsh-better-sidebar] draft insert failed:', error)
|
|
return false
|
|
}
|
|
}
|