dsh-sidenote 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/lib/client.js +1131 -606
- package/lib/types/client/annotations/NativeComposer.d.ts +10 -0
- package/lib/types/client/annotations/NativeUserContext.d.ts +33 -2
- package/lib/types/client/annotations/chip.d.ts +2 -12
- package/lib/types/client/host/chat.d.ts +34 -0
- package/lib/types/client/host/contracts.d.ts +14 -1
- package/lib/types/client/host/dom.d.ts +5 -0
- package/lib/types/client/locales.d.ts +13 -0
- package/lib/types/client/sidechat/NativeConversation.d.ts +7 -0
- package/lib/types/client/sidechat/identity.d.ts +1 -1
- package/lib/types/client/sidechat/snapshot.d.ts +2 -0
- package/package.json +9 -4
- package/src/client/annotate/index.tsx +7 -16
- package/src/client/annotations/NativeComposer.tsx +110 -0
- package/src/client/annotations/NativeUserContext.tsx +168 -36
- package/src/client/annotations/annotations.module.css +60 -157
- package/src/client/annotations/chip.tsx +122 -118
- package/src/client/host/chat.ts +23 -19
- package/src/client/host/contracts.ts +5 -0
- package/src/client/host/dom.ts +13 -1
- package/src/client/locales.ts +30 -4
- package/src/client/reflow.ts +1 -1
- package/src/client/sidechat/NativeConversation.tsx +33 -16
- package/src/client/sidechat/SideChatPanel.tsx +8 -3
- package/src/client/sidechat/identity.ts +5 -1
- package/src/client/sidechat/sidechat.module.css +15 -1
- package/src/client/sidechat/snapshot.ts +7 -0
- package/lib/types/client/annotate/chip.d.ts +0 -10
- package/lib/types/client/annotate/send.d.ts +0 -8
- package/src/client/annotate/chip.tsx +0 -94
- package/src/client/annotate/send.ts +0 -155
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context } from '../host/contracts.ts';
|
|
2
|
+
import type { AnnotationStore } from './model.ts';
|
|
3
|
+
import type { ReflowStore } from '../reflow.ts';
|
|
4
|
+
type Submit = (mode?: 'queue' | 'steer', source?: 'click' | 'enter') => void;
|
|
5
|
+
/** The host has already resolved Enter/click, menus, IME and busy delivery mode. */
|
|
6
|
+
export declare function submitNativeWithContext(ctx: Context, annotations: AnnotationStore, reflow: ReflowStore, sessionId: string, native: Submit, mode?: 'queue' | 'steer', source?: 'click' | 'enter'): void;
|
|
7
|
+
/** Keep the native editor and controls; replace only its empty submit seat
|
|
8
|
+
* while plugin-owned context exists, and retain a separate native Stop. */
|
|
9
|
+
export declare function registerNativeComposer(ctx: Context, annotations: AnnotationStore, reflow: ReflowStore): void;
|
|
10
|
+
export {};
|
|
@@ -1,4 +1,35 @@
|
|
|
1
1
|
import type { Context } from '../host/contracts.ts';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { type ProtocolPrefix } from './format.ts';
|
|
3
|
+
interface HistoryNode {
|
|
4
|
+
kind: string;
|
|
5
|
+
seq: number;
|
|
6
|
+
source?: {
|
|
7
|
+
kind?: string;
|
|
8
|
+
};
|
|
9
|
+
content?: readonly {
|
|
10
|
+
type: string;
|
|
11
|
+
text?: string;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
/** Injected notices and their following human input are one admitted batch.
|
|
15
|
+
* Project its reflows into that bubble without changing or resending history. */
|
|
16
|
+
export declare function injectedReflowPrefix(nodes: readonly HistoryNode[], seq: number): string;
|
|
17
|
+
/** One prefix node leaves the body, @ references and attachments to the host. */
|
|
18
|
+
export declare const sentContextRule: {
|
|
19
|
+
id: string;
|
|
20
|
+
order: number;
|
|
21
|
+
match(text: string, from: number): {
|
|
22
|
+
id: string;
|
|
23
|
+
start: number;
|
|
24
|
+
end: number;
|
|
25
|
+
data: ProtocolPrefix;
|
|
26
|
+
} | undefined;
|
|
27
|
+
};
|
|
28
|
+
export declare function SentContext({ protocol, interactive }: {
|
|
29
|
+
protocol: ProtocolPrefix;
|
|
30
|
+
interactive?: boolean;
|
|
31
|
+
}): import("react").JSX.Element;
|
|
32
|
+
/** Keep contextual chips inside the native bubble on both main and side chat.
|
|
33
|
+
* Only the progress snapshot remains outside its owning user message. */
|
|
4
34
|
export declare function registerUserContext(ctx: Context): void;
|
|
35
|
+
export {};
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
1
|
import type { Context, InputZone } from '../host/contracts.ts';
|
|
3
|
-
import type { ReflowStore } from '../reflow.ts';
|
|
4
2
|
import type { AnnotationStore } from './model.ts';
|
|
5
|
-
|
|
3
|
+
import type { ReflowStore } from '../reflow.ts';
|
|
6
4
|
interface ChipProps {
|
|
7
5
|
readonly session: InputZone['session'];
|
|
8
6
|
readonly input: InputZone['input'];
|
|
9
7
|
}
|
|
10
|
-
export declare function
|
|
11
|
-
store: AnnotationStore;
|
|
12
|
-
targetSessionId: string;
|
|
13
|
-
side?: boolean;
|
|
14
|
-
onSend?: () => void;
|
|
15
|
-
blocked?: boolean;
|
|
16
|
-
}): ReactNode;
|
|
17
|
-
/** The same native dock entry is rendered in main and embedded conversations. */
|
|
18
|
-
export declare function createAnnotationChip(ctx: Context, store: AnnotationStore, reflow: ReflowStore): (props: ChipProps) => ReactNode;
|
|
8
|
+
export declare function createContextChips(ctx: Context, store: AnnotationStore, reflow: ReflowStore): (props: ChipProps) => import("react").JSX.Element;
|
|
19
9
|
export {};
|
|
@@ -14,6 +14,40 @@ export interface ChatSource {
|
|
|
14
14
|
} | undefined;
|
|
15
15
|
getCompletedReplySeqs?(): readonly number[];
|
|
16
16
|
}
|
|
17
|
+
export interface ChatReplySnapshot {
|
|
18
|
+
legacy?: ConversationSnapshot;
|
|
19
|
+
timeline: {
|
|
20
|
+
turnOrder: readonly number[];
|
|
21
|
+
turns: ReadonlyMap<number, {
|
|
22
|
+
end?: {
|
|
23
|
+
data: {
|
|
24
|
+
reason: {
|
|
25
|
+
kind: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
locations: {
|
|
32
|
+
getTurn(turn: number): readonly string[];
|
|
33
|
+
};
|
|
34
|
+
nodes: {
|
|
35
|
+
get(key: string): {
|
|
36
|
+
kind: string;
|
|
37
|
+
data: {
|
|
38
|
+
status?: string;
|
|
39
|
+
finalNode?: {
|
|
40
|
+
seq: number;
|
|
41
|
+
};
|
|
42
|
+
blocks?: readonly {
|
|
43
|
+
kind: string;
|
|
44
|
+
text?: string;
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
47
|
+
} | undefined;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export declare function completedReplySeqsOf(state: ChatReplySnapshot): number[];
|
|
17
51
|
export declare function chatSourceOf(ctx: Context, binding: SessionBinding | undefined): ChatSource | undefined;
|
|
18
52
|
/** Retain the exact target generation on hosts that expose session ownership. */
|
|
19
53
|
export declare function retainSession(ctx: Context, sessionId: string, signal?: AbortSignal): SessionReference | undefined;
|
|
@@ -195,6 +195,19 @@ export interface UiConversationLike {
|
|
|
195
195
|
getSnapshot(): unknown;
|
|
196
196
|
} | undefined;
|
|
197
197
|
} | undefined;
|
|
198
|
+
/** 0.2.1+: pure original-text rules, rendered by conversation.user.text.node. */
|
|
199
|
+
userText?: {
|
|
200
|
+
register(rule: {
|
|
201
|
+
id: string;
|
|
202
|
+
order: number;
|
|
203
|
+
match(text: string, from: number): {
|
|
204
|
+
id: string;
|
|
205
|
+
start: number;
|
|
206
|
+
end: number;
|
|
207
|
+
data: unknown;
|
|
208
|
+
} | undefined;
|
|
209
|
+
}): () => void;
|
|
210
|
+
};
|
|
198
211
|
}
|
|
199
212
|
export interface SessionsService {
|
|
200
213
|
list: ObservableSnapshot<SessionListSnapshot>;
|
|
@@ -394,7 +407,7 @@ export interface SlotRegisterOptions {
|
|
|
394
407
|
* 收窄为显式清单:拼错编译期即红;启用新槽位 = 先在这里加一行(刻意的
|
|
395
408
|
* 显式 opt-in,arch-audit §4.1-4 修法)。
|
|
396
409
|
*/
|
|
397
|
-
export type KnownSlotKey = 'sidebar.workspaces' | 'conversation.input.dock' | 'conversation.session.header.utilities' | 'settings.general.item' | 'sidebar.right.pane.tab' | 'sidebar.right.pane.tab.title' | 'sidenote.conversation' | 'conversation.view' | 'conversation.chat.node' | 'conversation.chat.turnTail';
|
|
410
|
+
export type KnownSlotKey = 'sidebar.workspaces' | 'conversation.input.dock' | 'conversation.session.header.utilities' | 'settings.general.item' | 'sidebar.right.pane.tab' | 'sidebar.right.pane.tab.title' | 'sidenote.conversation' | 'conversation.view' | 'conversation.chat.node' | 'conversation.chat.turnTail' | 'conversation.chat.assistant-actions' | 'conversation.composer.bar' | 'conversation.user.text.node';
|
|
398
411
|
/** The client slots service face (register returns the disposer). */
|
|
399
412
|
export interface SlotsService {
|
|
400
413
|
register(options: SlotRegisterOptions, component: unknown): () => void;
|
|
@@ -30,6 +30,11 @@ export declare function composerSeat(): HTMLElement | null;
|
|
|
30
30
|
* 且只在非运行态作为识别面——运行态主按钮变身「停止」,整个 click 路径不拦)。 */
|
|
31
31
|
export declare function findSendButtonInCard(root?: ParentNode): HTMLButtonElement | null;
|
|
32
32
|
export declare function composerSessionId(seat: HTMLElement, fallback: string): string;
|
|
33
|
+
/** Bound message hover details to their native conversation pane. */
|
|
34
|
+
export declare function conversationViewOf(node: Element): HTMLElement;
|
|
33
35
|
export declare function isMainComposerInput(target: EventTarget | null): boolean;
|
|
34
36
|
export declare function composerHasMenu(seat: HTMLElement): boolean;
|
|
35
37
|
export declare function hasConversationMessages(): boolean;
|
|
38
|
+
/** 0.2.0 has no UserText extension. Only add our own portal seat; never move
|
|
39
|
+
* or replace host-owned children. The CSS-module suffix is checked by E2E. */
|
|
40
|
+
export declare function mountUserBubbleAddon(root: HTMLElement, addon: HTMLElement): () => void;
|
|
@@ -46,6 +46,14 @@ export declare const en: {
|
|
|
46
46
|
diagSideAcceptance: string;
|
|
47
47
|
inputUnavailable: string;
|
|
48
48
|
snapshotContext: string;
|
|
49
|
+
mainContext: string;
|
|
50
|
+
contextAtSend: string;
|
|
51
|
+
contextAsOf: string;
|
|
52
|
+
contextInherited: string;
|
|
53
|
+
contextrequest: string;
|
|
54
|
+
contextreply: string;
|
|
55
|
+
contextthinking: string;
|
|
56
|
+
contextstreaming: string;
|
|
49
57
|
inputWaiting: string;
|
|
50
58
|
draftRecoveryConflict: string;
|
|
51
59
|
quoteWorkflowWaiting: string;
|
|
@@ -136,6 +144,9 @@ export declare const en: {
|
|
|
136
144
|
notePlaceholder: string;
|
|
137
145
|
confirmTitle: string;
|
|
138
146
|
saveNoteAria: string;
|
|
147
|
+
editNoteAria: string;
|
|
148
|
+
selectedText: string;
|
|
149
|
+
userComment: string;
|
|
139
150
|
sideNotePlaceholder: string;
|
|
140
151
|
sideNoteAria: string;
|
|
141
152
|
confirmAskAria: string;
|
|
@@ -156,6 +167,8 @@ export declare const en: {
|
|
|
156
167
|
sentBadgeTitle: string;
|
|
157
168
|
sentCardTitle: string;
|
|
158
169
|
clearAll: string;
|
|
170
|
+
clearAnnotations: string;
|
|
171
|
+
clearReflows: string;
|
|
159
172
|
chipNote: string;
|
|
160
173
|
headerSide: string;
|
|
161
174
|
headerSideTitle: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ComponentType, type ReactNode } from 'react';
|
|
2
2
|
import type { Context, SessionReference } from '../host/contracts.ts';
|
|
3
3
|
import { type ChatMessage } from '../chat/transcript.ts';
|
|
4
|
+
import type { SnapshotEntry } from './snapshot.ts';
|
|
4
5
|
import type { ReflowStore } from '../reflow.ts';
|
|
5
6
|
export interface SideConversation {
|
|
6
7
|
sessionId: string;
|
|
@@ -8,6 +9,12 @@ export interface SideConversation {
|
|
|
8
9
|
title: string;
|
|
9
10
|
boundarySeq?: number;
|
|
10
11
|
reflow: ReflowStore;
|
|
12
|
+
contextExpanded?: boolean;
|
|
13
|
+
contextPending?: boolean;
|
|
14
|
+
progress?: {
|
|
15
|
+
entries: SnapshotEntry[];
|
|
16
|
+
takenAt?: string | null;
|
|
17
|
+
};
|
|
11
18
|
}
|
|
12
19
|
export interface ConversationRendererProps {
|
|
13
20
|
SessionProvider: ComponentType<{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 首条用户消息 → topic。折叠全部空白(含换行)为单空格,截 20 码点,
|
|
3
3
|
* 超长加省略号;清洗后为空返回 undefined(调用方回退编号标题)。
|
|
4
|
-
*
|
|
4
|
+
* 已落盘消息也会用于恢复主题;先剥离快照及批注/回流协议。
|
|
5
5
|
* 划选提问的种子草稿是「> 引用行 + note 行」(buildSideChatQuote):
|
|
6
6
|
* 引用行剥除(用户自己的话才是主题),机械占位行(noNote)丢弃;
|
|
7
7
|
* 剥完为空(未补充直接发送)时退回引用内容——引用即主题。
|
|
@@ -22,6 +22,8 @@ export interface SnapshotEntry {
|
|
|
22
22
|
/** tool 拍携带工具名。 */
|
|
23
23
|
toolName?: string;
|
|
24
24
|
}
|
|
25
|
+
/** Read the plugin's persisted progress block as plain, expandable content. */
|
|
26
|
+
export declare function snapshotEntriesFromText(text: string): SnapshotEntry[];
|
|
25
27
|
/**
|
|
26
28
|
* 投影 nodes → 当前 turn 的快照拍序列。纯函数(node 可测)。
|
|
27
29
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sidenote",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Follow the tangent. Keep the thread. Annotate, explore on the side, and bring answers back to DeepSeek Harness. / 思路可以分岔,主线始终向前。划选注释、侧边追问,再把结论带回正在推进的任务。",
|
|
5
5
|
"icon": "docs/assets/logo.svg",
|
|
6
6
|
"type": "module",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=20",
|
|
24
|
-
"dsh": "=0.2.0-rc.2 || =0.2.1-rc.2"
|
|
24
|
+
"dsh": "=0.2.0-rc.2 || =0.2.1-rc.2 || =0.2.1-rc.3"
|
|
25
25
|
},
|
|
26
26
|
"dsh": {
|
|
27
27
|
"bundle": {
|
|
@@ -37,9 +37,14 @@
|
|
|
37
37
|
"platform": "web"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
|
-
"dsh": "=0.2.0-rc.2 || =0.2.1-rc.2"
|
|
40
|
+
"dsh": "=0.2.0-rc.2 || =0.2.1-rc.2 || =0.2.1-rc.3"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
+
"dshSupport": {
|
|
44
|
+
"current": "0.2.1-rc.2",
|
|
45
|
+
"previous": "0.2.0-rc.2",
|
|
46
|
+
"preview": "0.2.1-rc.3"
|
|
47
|
+
},
|
|
43
48
|
"files": [
|
|
44
49
|
"lib/index.js",
|
|
45
50
|
"lib/client.js",
|
|
@@ -51,7 +56,7 @@
|
|
|
51
56
|
"LICENSE"
|
|
52
57
|
],
|
|
53
58
|
"peerDependencies": {
|
|
54
|
-
"@deepseek-ai/dsh-client-ui-primitives": "=0.2.0-rc.2 || =0.2.1-rc.2",
|
|
59
|
+
"@deepseek-ai/dsh-client-ui-primitives": "=0.2.0-rc.2 || =0.2.1-rc.2 || =0.2.1-rc.3",
|
|
55
60
|
"cordis": "^4.0.2",
|
|
56
61
|
"react": "^18.2.0",
|
|
57
62
|
"react-dom": "^18.2.0"
|
|
@@ -17,9 +17,8 @@ import type { Context } from '../host/contracts.ts'
|
|
|
17
17
|
import type { AnnotationStore } from '../annotations/model.ts'
|
|
18
18
|
import { createSelectionController } from './selection.ts'
|
|
19
19
|
import { AnnotateOverlay } from './overlay.tsx'
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { installSendInterceptor } from './send.ts'
|
|
20
|
+
import { createContextChips } from '../annotations/chip.tsx'
|
|
21
|
+
import { registerNativeComposer } from '../annotations/NativeComposer.tsx'
|
|
23
22
|
import { registerUserContext } from '../annotations/NativeUserContext.tsx'
|
|
24
23
|
import type { ReflowStore } from '../reflow.ts'
|
|
25
24
|
|
|
@@ -41,8 +40,8 @@ export function registerAnnotations(ctx: Context, reflow: ReflowStore, store: An
|
|
|
41
40
|
const root = createRoot(host)
|
|
42
41
|
root.render(<AnnotateOverlay ctx={ctx} store={store} controller={controller} />)
|
|
43
42
|
|
|
44
|
-
//
|
|
45
|
-
|
|
43
|
+
// 发送携带:原生提交入口在提交瞬间把协议块(注释 + 回流)拼入正文(草稿零污染)。
|
|
44
|
+
registerNativeComposer(ctx, store, reflow)
|
|
46
45
|
// 发送后留痕:用户气泡里的协议块隐藏为「批注 ×N」标签。
|
|
47
46
|
registerUserContext(ctx)
|
|
48
47
|
|
|
@@ -51,27 +50,19 @@ export function registerAnnotations(ctx: Context, reflow: ReflowStore, store: An
|
|
|
51
50
|
// ui-conversation todo/queue docks register the same way)。disposer 由
|
|
52
51
|
// cordis 服务代理级联进本 fiber,随 effect 撤销自动回收。
|
|
53
52
|
ctx.slots.inject('conversation.input.dock', () => {
|
|
54
|
-
const
|
|
53
|
+
const offContext = ctx.slots.register({
|
|
55
54
|
name: 'conversation.input.dock',
|
|
56
55
|
id: 'dsh-sidenote-annotations',
|
|
57
56
|
order: 10,
|
|
58
57
|
registrant: 'dsh-sidenote',
|
|
59
|
-
},
|
|
60
|
-
const offReflow = ctx.slots.register({
|
|
61
|
-
name: 'conversation.input.dock',
|
|
62
|
-
id: 'dsh-sidenote-reflow',
|
|
63
|
-
order: 11,
|
|
64
|
-
registrant: 'dsh-sidenote',
|
|
65
|
-
}, createReflowChip(reflow))
|
|
58
|
+
}, createContextChips(ctx, store, reflow))
|
|
66
59
|
hostDiagnostics(ctx).dockRegistered()
|
|
67
60
|
return () => {
|
|
68
|
-
|
|
69
|
-
offReflow()
|
|
61
|
+
offContext()
|
|
70
62
|
}
|
|
71
63
|
})
|
|
72
64
|
|
|
73
65
|
return () => {
|
|
74
|
-
offInterceptor()
|
|
75
66
|
controller.dispose()
|
|
76
67
|
// 同帧 render/unmount 会触发 React 警告——推迟到下一帧。
|
|
77
68
|
setTimeout(() => { root.unmount() })
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createElement, useCallback, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, type ComponentType } from 'react'
|
|
2
|
+
import { createPortal } from 'react-dom'
|
|
3
|
+
import type { Context, InputStateSnapshot } from '../host/contracts.ts'
|
|
4
|
+
import { inputAttachmentIds, resolveInput } from '../host/input.ts'
|
|
5
|
+
import { findSendButtonInCard } from '../host/dom.ts'
|
|
6
|
+
import type { AnnotationStore } from './model.ts'
|
|
7
|
+
import type { ReflowStore } from '../reflow.ts'
|
|
8
|
+
import { submissionExtrasOf } from './submissionExtras.ts'
|
|
9
|
+
import { submitControlledInput } from './send.ts'
|
|
10
|
+
import { t } from '../locales.ts'
|
|
11
|
+
import css from './annotations.module.css'
|
|
12
|
+
|
|
13
|
+
type Submit = (mode?: 'queue' | 'steer', source?: 'click' | 'enter') => void
|
|
14
|
+
interface Keyboard { submit: Submit }
|
|
15
|
+
interface Session { running: boolean; removed?: boolean; subagent?: { address: { mode: string }; parentAvailable?: boolean } }
|
|
16
|
+
interface ComposerProps {
|
|
17
|
+
sessionId?: string
|
|
18
|
+
keyboard?: Keyboard
|
|
19
|
+
inputActions?: unknown
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
blocked?: unknown
|
|
22
|
+
variant: string
|
|
23
|
+
useInput<T>(select: (state: InputStateSnapshot | undefined) => T): T
|
|
24
|
+
useSession<T>(select: (state: Session | undefined) => T): T
|
|
25
|
+
useBusyEnter<T>(select: (mode: 'queue' | 'steer') => T): T
|
|
26
|
+
t(key: string): string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The host has already resolved Enter/click, menus, IME and busy delivery mode. */
|
|
30
|
+
export function submitNativeWithContext(ctx: Context, annotations: AnnotationStore, reflow: ReflowStore, sessionId: string, native: Submit, mode?: 'queue' | 'steer', source?: 'click' | 'enter'): void {
|
|
31
|
+
if (annotations.getSubmission(sessionId).pending) return
|
|
32
|
+
const hasContext = annotations.countActive(sessionId) > 0 || reflow.list(sessionId).length > 0
|
|
33
|
+
const input = resolveInput(ctx, sessionId)
|
|
34
|
+
if (!input) {
|
|
35
|
+
if (hasContext || submissionExtrasOf(sessionId)?.firstSendPrefix()) annotations.setSubmission(sessionId, { pending: false, error: t('inputUnavailable') })
|
|
36
|
+
else native(mode, source)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
const draft = input.state.getSnapshot()
|
|
40
|
+
if (draft.phase !== 'plain' || draft.draft.trimStart().startsWith('/')) { native(mode, source); return }
|
|
41
|
+
const hasMessage = draft.draft.trim() !== '' || inputAttachmentIds(input).length > 0
|
|
42
|
+
if (hasContext || hasMessage && submissionExtrasOf(sessionId)?.firstSendPrefix()) {
|
|
43
|
+
void submitControlledInput(ctx, annotations, reflow, sessionId, mode)
|
|
44
|
+
} else native(mode, source)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function ContextComposer({ Original, props, ctx, annotations, reflow }: { Original: ComponentType<ComposerProps>; props: ComposerProps; ctx: Context; annotations: AnnotationStore; reflow: ReflowStore }) {
|
|
48
|
+
useSyncExternalStore(annotations.subscribe, annotations.getSnapshot)
|
|
49
|
+
useSyncExternalStore(reflow.subscribe, reflow.getSnapshot)
|
|
50
|
+
const input = props.useInput(state => state)
|
|
51
|
+
const session = props.useSession(state => state)
|
|
52
|
+
const busyMode = props.useBusyEnter(mode => mode)
|
|
53
|
+
const sessionId = props.sessionId ?? ''
|
|
54
|
+
const pending = annotations.getSubmission(sessionId).pending
|
|
55
|
+
const hasContext = annotations.countActive(sessionId) > 0 || reflow.list(sessionId).length > 0
|
|
56
|
+
const contextOnly = hasContext && input?.draft.trim() === '' && (input.attachmentIds ?? input.imageIds ?? []).length === 0
|
|
57
|
+
const root = useRef<HTMLDivElement>(null)
|
|
58
|
+
const [seat] = useState(() => document.createElement('span'))
|
|
59
|
+
const [nativeButton, setNativeButton] = useState<HTMLButtonElement | null>(null)
|
|
60
|
+
const keyboard = useMemo(() => props.keyboard && new Proxy(props.keyboard, {
|
|
61
|
+
get(target, property) {
|
|
62
|
+
if (property === 'submit') return (mode?: 'queue' | 'steer', source?: 'click' | 'enter') => submitNativeWithContext(ctx, annotations, reflow, sessionId, target.submit.bind(target), mode, source)
|
|
63
|
+
const value = Reflect.get(target, property, target)
|
|
64
|
+
return typeof value === 'function' ? value.bind(target) : value
|
|
65
|
+
},
|
|
66
|
+
}), [props.keyboard, ctx, annotations, reflow, sessionId])
|
|
67
|
+
const useInput = useCallback(<T,>(select: (state: InputStateSnapshot | undefined) => T): T => props.useInput(state => select(pending && state?.phase === 'plain' ? { ...state, phase: 'submitting' } : state)), [props.useInput, pending])
|
|
68
|
+
useLayoutEffect(() => {
|
|
69
|
+
if (!contextOnly || !root.current) return
|
|
70
|
+
const button = findSendButtonInCard(root.current)
|
|
71
|
+
if (!button) return
|
|
72
|
+
setNativeButton(button)
|
|
73
|
+
seat.style.display = 'contents'
|
|
74
|
+
button.parentElement!.append(seat)
|
|
75
|
+
if (!session?.running) button.dataset.sidenoteContextReplaced = ''
|
|
76
|
+
return () => { delete button.dataset.sidenoteContextReplaced; seat.remove() }
|
|
77
|
+
}, [contextOnly, session?.running, sessionId, props.variant, seat])
|
|
78
|
+
const offline = session?.subagent?.address.mode === 'continuable' && session.subagent.parentAvailable !== true
|
|
79
|
+
const disabled = pending || input?.phase !== 'plain' || props.disabled || props.blocked !== undefined || session?.removed || offline || !keyboard || !props.inputActions
|
|
80
|
+
const mode = session?.running ? busyMode : undefined
|
|
81
|
+
const label = props.t(session?.running ? mode === 'steer' ? 'input.send.steer' : 'input.send.queue' : 'input.send')
|
|
82
|
+
return <div className={css.userContextHost} ref={root}>
|
|
83
|
+
{createElement(Original, { ...props, keyboard, useInput })}
|
|
84
|
+
{contextOnly && nativeButton && createPortal(<button type="button" data-sidenote-submit className={nativeButton.className} disabled={disabled} aria-label={label} title={label} onClick={() => { keyboard?.submit(mode, 'click') }}>
|
|
85
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M12 19V5m-6 6 6-6 6 6" /></svg>
|
|
86
|
+
</button>, seat)}
|
|
87
|
+
</div>
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Keep the native editor and controls; replace only its empty submit seat
|
|
91
|
+
* while plugin-owned context exists, and retain a separate native Stop. */
|
|
92
|
+
export function registerNativeComposer(ctx: Context, annotations: AnnotationStore, reflow: ReflowStore): void {
|
|
93
|
+
type Entry = { component: ComponentType<ComposerProps> }
|
|
94
|
+
const slots = ctx.slots as Context['slots'] & { entries(name: string): readonly Entry[]; subscribe(name: string, notify: () => void): () => void }
|
|
95
|
+
ctx.slots.inject('conversation.composer.bar', () => {
|
|
96
|
+
const patched = new Map<Entry, { original: ComponentType<ComposerProps>; wrapped: ComponentType<ComposerProps> }>()
|
|
97
|
+
const patch = (): void => {
|
|
98
|
+
for (const entry of slots.entries('conversation.composer.bar')) {
|
|
99
|
+
if (patched.has(entry)) continue
|
|
100
|
+
const Original = entry.component
|
|
101
|
+
const Wrapped = (props: ComposerProps) => <ContextComposer Original={Original} props={props} ctx={ctx} annotations={annotations} reflow={reflow} />
|
|
102
|
+
entry.component = Wrapped
|
|
103
|
+
patched.set(entry, { original: Original, wrapped: Wrapped })
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
patch()
|
|
107
|
+
const off = slots.subscribe('conversation.composer.bar', patch)
|
|
108
|
+
return () => { off(); for (const [entry, value] of patched) if (entry.component === value.wrapped) entry.component = value.original }
|
|
109
|
+
})
|
|
110
|
+
}
|