@open-document/core 0.13.3 → 0.14.0
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/dist/{build-CvsOak5B.js → build-CyBlmrjS.js} +1 -1
- package/dist/{check-CbUBwYmf.js → check-DUKDEem-.js} +3 -3
- package/dist/cli/bin.js +10 -21
- package/dist/{config-BWtOZ1jc.d.ts → config-cAV1OCuY.d.ts} +9 -1
- package/dist/{config-CltJJVsw.js → config-cNpYUpF6.js} +2746 -369
- package/dist/{context-CWgfsHoE.js → context-BPApOW9n.js} +1 -1
- package/dist/{dev-B8H2qT6G.js → dev-DrnOvsX3.js} +1 -1
- package/dist/{diff-BvIjjgnc.js → diff-BPMD2Knh.js} +2 -2
- package/dist/{export-DX30_s2q.js → export-DeVtL8aX.js} +3 -3
- package/dist/{import-DgsdJT5e.js → import-WAgWsuOv.js} +3 -2
- package/dist/index.d.ts +2 -2
- package/dist/ops/index.d.ts +3 -1
- package/dist/ops/index.js +2 -2
- package/dist/{ops-CSR5RlrE.js → ops-raK6424A.js} +2 -854
- package/dist/{preview-DYMUNjXL.js → preview-B8Vw9QCh.js} +1 -1
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/{templates-B5Tz0AKb.js → templates-D9jAFJ8R.js} +3 -3
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
- package/skills/create-doc/SKILL.md +1 -1
- package/skills/doc-authoring/SKILL.md +6 -0
- package/src/app/app.tsx +2 -0
- package/src/app/components/agent/agent-dock.tsx +75 -0
- package/src/app/components/agent/agent-markdown.tsx +45 -0
- package/src/app/components/agent/agent-panel.tsx +690 -0
- package/src/app/components/agent/agent-presence.tsx +74 -0
- package/src/app/components/agent/composer.tsx +120 -0
- package/src/app/components/agent/connect-view.tsx +183 -0
- package/src/app/components/agent/history-view.tsx +134 -0
- package/src/app/components/agent/provider-logo.tsx +23 -0
- package/src/app/components/agent/transcript.tsx +609 -0
- package/src/app/components/comments/comments-panel.tsx +26 -2
- package/src/app/components/inspector/inspector.tsx +17 -0
- package/src/app/components/note-markdown.tsx +85 -0
- package/src/app/components/page-error-boundary.tsx +84 -0
- package/src/app/components/page-frame.tsx +2 -1
- package/src/app/components/panel/resize-handle.tsx +129 -0
- package/src/app/components/ui/button.tsx +97 -0
- package/src/app/components/ui/popover.tsx +144 -0
- package/src/app/components/ui/tooltip.tsx +123 -0
- package/src/app/lib/agent/use-agent.ts +543 -0
- package/src/app/lib/diagnostics.ts +13 -0
- package/src/app/lib/export-dom.ts +2 -1
- package/src/app/lib/export-pdf.ts +2 -1
- package/src/app/lib/i18n-ja/agent-panel.ts +107 -0
- package/src/app/lib/i18n-ja/agent.ts +9 -0
- package/src/app/lib/i18n-ja/index.ts +9 -1
- package/src/app/lib/i18n-ko/agent-panel.ts +106 -0
- package/src/app/lib/i18n-ko/agent.ts +9 -0
- package/src/app/lib/i18n-ko/index.ts +9 -1
- package/src/app/lib/i18n-zh-cn/agent-panel.ts +105 -0
- package/src/app/lib/i18n-zh-cn/agent.ts +9 -0
- package/src/app/lib/i18n-zh-cn/index.ts +9 -1
- package/src/app/lib/i18n-zh-tw/agent-panel.ts +105 -0
- package/src/app/lib/i18n-zh-tw/agent.ts +9 -0
- package/src/app/lib/i18n-zh-tw/index.ts +9 -1
- package/src/app/lib/note-markdown.ts +116 -0
- package/src/app/lib/toast.ts +50 -0
- package/src/app/lib/use-auto-grow.ts +15 -0
- package/src/app/lib/use-doc-titles.ts +28 -0
- package/src/app/lib/use-locale.ts +144 -0
- package/src/app/lib/utils.ts +4 -0
- package/src/app/routes/doc-preview.tsx +103 -0
- package/src/app/routes/doc.tsx +118 -11
- package/src/app/routes/home.tsx +43 -8
- package/src/app/styles.css +193 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A short notice in the corner of the window — the few the agent panel raises
|
|
3
|
+
* when something it started from a click fails or finishes. Drawn straight into
|
|
4
|
+
* the DOM rather than through a toast library, since the runtime ships to
|
|
5
|
+
* users; the call shape matches `sonner`'s so the panel reads the same.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type Kind = 'error' | 'success';
|
|
9
|
+
type Options = { description?: string };
|
|
10
|
+
|
|
11
|
+
const SHOWN_MS = 5000;
|
|
12
|
+
|
|
13
|
+
function host(): HTMLElement {
|
|
14
|
+
let el = document.getElementById('od-toasts');
|
|
15
|
+
if (!el) {
|
|
16
|
+
el = document.createElement('div');
|
|
17
|
+
el.id = 'od-toasts';
|
|
18
|
+
el.setAttribute('role', 'status');
|
|
19
|
+
el.setAttribute('aria-live', 'polite');
|
|
20
|
+
el.className =
|
|
21
|
+
'pointer-events-none fixed right-4 bottom-4 z-[100] flex w-[320px] max-w-[calc(100vw-2rem)] flex-col gap-2';
|
|
22
|
+
document.body.append(el);
|
|
23
|
+
}
|
|
24
|
+
return el;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function show(kind: Kind, message: string, options?: Options): void {
|
|
28
|
+
if (typeof document === 'undefined') return;
|
|
29
|
+
const card = document.createElement('div');
|
|
30
|
+
card.className =
|
|
31
|
+
'island-enter pointer-events-auto rounded-[8px] border border-hairline bg-popover px-3 py-2.5 text-[12.5px] text-popover-foreground shadow-floating';
|
|
32
|
+
card.dataset.kind = kind;
|
|
33
|
+
const title = document.createElement('p');
|
|
34
|
+
title.className = kind === 'error' ? 'font-medium text-destructive' : 'font-medium';
|
|
35
|
+
title.textContent = message;
|
|
36
|
+
card.append(title);
|
|
37
|
+
if (options?.description) {
|
|
38
|
+
const body = document.createElement('p');
|
|
39
|
+
body.className = 'mt-0.5 break-words text-[11.5px] text-muted-foreground';
|
|
40
|
+
body.textContent = options.description;
|
|
41
|
+
card.append(body);
|
|
42
|
+
}
|
|
43
|
+
host().append(card);
|
|
44
|
+
setTimeout(() => card.remove(), SHOWN_MS);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const toast = {
|
|
48
|
+
error: (message: string, options?: Options) => show('error', message, options),
|
|
49
|
+
success: (message: string, options?: Options) => show('success', message, options),
|
|
50
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type RefObject, useLayoutEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useAutoGrow(
|
|
4
|
+
ref: RefObject<HTMLTextAreaElement | null>,
|
|
5
|
+
value: string,
|
|
6
|
+
max: number,
|
|
7
|
+
): void {
|
|
8
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: re-measure whenever the text changes
|
|
9
|
+
useLayoutEffect(() => {
|
|
10
|
+
const node = ref.current;
|
|
11
|
+
if (!node) return;
|
|
12
|
+
node.style.height = '0px';
|
|
13
|
+
node.style.height = `${Math.min(max, Math.max(40, node.scrollHeight))}px`;
|
|
14
|
+
}, [ref, value, max]);
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { docIds, loadDoc } from './docs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Every document's display title, resolved once `enabled` first turns true —
|
|
6
|
+
* kept lazy since it imports every document module.
|
|
7
|
+
*/
|
|
8
|
+
export function useDocTitles(enabled: boolean): Record<string, string> {
|
|
9
|
+
const [titles, setTitles] = useState<Record<string, string>>({});
|
|
10
|
+
const startedRef = useRef(false);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!enabled || startedRef.current) return;
|
|
14
|
+
startedRef.current = true;
|
|
15
|
+
void Promise.all(
|
|
16
|
+
docIds.map(async (id): Promise<[string, string]> => {
|
|
17
|
+
try {
|
|
18
|
+
const mod = await loadDoc(id);
|
|
19
|
+
return [id, mod.meta?.title ?? id];
|
|
20
|
+
} catch {
|
|
21
|
+
return [id, id];
|
|
22
|
+
}
|
|
23
|
+
}),
|
|
24
|
+
).then((entries) => setTitles(Object.fromEntries(entries)));
|
|
25
|
+
}, [enabled]);
|
|
26
|
+
|
|
27
|
+
return titles;
|
|
28
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useLocale as useAppLocale } from './i18n';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The agent panel's strings in the shape its components read them — `t.agent.x`,
|
|
6
|
+
* as in open-slide, so the panel stays easy to keep in step with it — each one
|
|
7
|
+
* translated through the app's own dictionaries, keyed by its English text.
|
|
8
|
+
*/
|
|
9
|
+
const AGENT = {
|
|
10
|
+
title: 'Agent',
|
|
11
|
+
beta: 'Beta',
|
|
12
|
+
betaTitle: 'Early preview',
|
|
13
|
+
betaHint: 'Replies, edits and tool calls can occasionally fail or do something unexpected.',
|
|
14
|
+
open: 'Agent',
|
|
15
|
+
openTitle: 'Open the agent panel',
|
|
16
|
+
close: 'Close agent panel',
|
|
17
|
+
newSession: 'New chat',
|
|
18
|
+
sessions: 'History',
|
|
19
|
+
noSessions: 'No conversations yet.',
|
|
20
|
+
deleteSession: 'Delete conversation',
|
|
21
|
+
historyThisDoc: 'This document',
|
|
22
|
+
historyOtherDocs: 'Other documents',
|
|
23
|
+
historyEmptyHint: 'Chats you start in this panel show up here.',
|
|
24
|
+
sessionRunning: 'Working',
|
|
25
|
+
composerPlaceholder: 'Ask {provider} to create or edit documents…',
|
|
26
|
+
send: 'Send',
|
|
27
|
+
stop: 'Stop',
|
|
28
|
+
working: 'Working',
|
|
29
|
+
contextPage: 'Page {n}',
|
|
30
|
+
contextSelection: 'Selection',
|
|
31
|
+
pendingComments: {
|
|
32
|
+
one: '{count} comment',
|
|
33
|
+
other: '{count} comments',
|
|
34
|
+
},
|
|
35
|
+
applyComments: 'Apply comments',
|
|
36
|
+
applyCommentsWith: 'Apply with {provider}',
|
|
37
|
+
createDoc: 'Draft with agent',
|
|
38
|
+
createDocWith: 'Create a document with {provider}',
|
|
39
|
+
quickCreate: 'Draft a new document',
|
|
40
|
+
quickCreateHint:
|
|
41
|
+
'Opens a blank document; describe it and the agent drafts it section by section.',
|
|
42
|
+
quickApply: 'Apply pending comments',
|
|
43
|
+
quickApplyHint: 'Resolves every @doc-comment marker in this document.',
|
|
44
|
+
quickTheme: 'Create a theme',
|
|
45
|
+
quickThemeHint: 'Extracts or designs a reusable theme under themes/.',
|
|
46
|
+
quickEdit: 'Edit this page',
|
|
47
|
+
quickEditHint: 'Describe a change to the page you are viewing.',
|
|
48
|
+
emptyTitle: 'What should we build?',
|
|
49
|
+
emptyHint: 'Describe a document, or pick a starting point.',
|
|
50
|
+
questionSubmit: 'Continue',
|
|
51
|
+
questionOther: 'Other',
|
|
52
|
+
questionOtherPlaceholder: 'Type your own answer',
|
|
53
|
+
questionCancelled: 'Dismissed',
|
|
54
|
+
permissionTitle: 'Needs approval',
|
|
55
|
+
allow: 'Allow',
|
|
56
|
+
deny: 'Deny',
|
|
57
|
+
allowed: 'Allowed',
|
|
58
|
+
denied: 'Denied',
|
|
59
|
+
autoApprove: 'Auto-approve',
|
|
60
|
+
autoApproveHint: 'Run commands without asking. Edits inside the workspace are always allowed.',
|
|
61
|
+
resultDone: 'Done',
|
|
62
|
+
resultStopped: 'Stopped',
|
|
63
|
+
resultSeconds: '{seconds}s',
|
|
64
|
+
errorEyebrow: 'Error',
|
|
65
|
+
statusLoading: 'Checking agents',
|
|
66
|
+
disabled: 'The agent panel is disabled in open-doc.config.ts.',
|
|
67
|
+
connectTitle: 'Connect an agent',
|
|
68
|
+
connectDescription:
|
|
69
|
+
'Drive your coding agent from here instead of a terminal. Agents installed on this machine connect automatically and reuse their sign-in.',
|
|
70
|
+
connect: 'Connect',
|
|
71
|
+
connecting: 'Connecting',
|
|
72
|
+
connected: 'Connected',
|
|
73
|
+
connectInstallHint: 'Adds {pkg} to this workspace with {pm}.',
|
|
74
|
+
cliFound: 'CLI found · v{version}',
|
|
75
|
+
cliFoundNoVersion: 'CLI found',
|
|
76
|
+
cliMissing: 'CLI not found on PATH',
|
|
77
|
+
cliHint: 'Install the {name} CLI and sign in once; the panel reuses its login.',
|
|
78
|
+
needCliTitle: 'Install Codex first',
|
|
79
|
+
needCliDescription:
|
|
80
|
+
'The panel drives the Codex CLI on this machine, and it was not found on your PATH. Install it, sign in once in a terminal with `codex`, then check again.',
|
|
81
|
+
checkAgain: 'Check again',
|
|
82
|
+
retry: 'Retry',
|
|
83
|
+
toastConnected: '{name} connected',
|
|
84
|
+
toastConnectFailed: 'Could not install {pkg}',
|
|
85
|
+
manageConnections: 'Manage agents',
|
|
86
|
+
backToChat: 'Back',
|
|
87
|
+
toastSendFailed: 'Could not send message',
|
|
88
|
+
newDocTitle: "What's this document about?",
|
|
89
|
+
newDocHint:
|
|
90
|
+
'Describe the topic, audience and tone. {provider} drafts it section by section while you watch.',
|
|
91
|
+
newDocPlaceholder: 'A two-page project brief on…',
|
|
92
|
+
toastCreateDocFailed: 'Could not create a document',
|
|
93
|
+
steps: {
|
|
94
|
+
one: '{count} step',
|
|
95
|
+
other: '{count} steps',
|
|
96
|
+
},
|
|
97
|
+
questionSkip: 'Skip',
|
|
98
|
+
copyMessage: 'Copy',
|
|
99
|
+
copied: 'Copied',
|
|
100
|
+
editMessage: 'Edit',
|
|
101
|
+
cancelEdit: 'Cancel',
|
|
102
|
+
sendEdit: 'Send',
|
|
103
|
+
editHint:
|
|
104
|
+
'Sending replaces the conversation after this message. Edits already made to files stay.',
|
|
105
|
+
modelDefault: 'Default',
|
|
106
|
+
reasoning: 'Reasoning',
|
|
107
|
+
effortAuto: 'Auto',
|
|
108
|
+
efforts: {
|
|
109
|
+
minimal: 'Minimal',
|
|
110
|
+
low: 'Low',
|
|
111
|
+
medium: 'Medium',
|
|
112
|
+
high: 'High',
|
|
113
|
+
xhigh: 'Extra high',
|
|
114
|
+
max: 'Max',
|
|
115
|
+
},
|
|
116
|
+
presenceEditing: '{provider} is editing',
|
|
117
|
+
presenceThinking: 'Thinking',
|
|
118
|
+
presenceWaiting: 'Waiting for you',
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
type Strings<T> = { [K in keyof T]: T[K] extends string ? string : Strings<T[K]> };
|
|
122
|
+
|
|
123
|
+
function translateTree<T extends object>(tree: T, t: (text: string) => string): Strings<T> {
|
|
124
|
+
const out: Record<string, unknown> = {};
|
|
125
|
+
for (const [key, value] of Object.entries(tree)) {
|
|
126
|
+
out[key] = typeof value === 'string' ? t(value) : translateTree(value as object, t);
|
|
127
|
+
}
|
|
128
|
+
return out as Strings<T>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function useLocale() {
|
|
132
|
+
const { locale, t } = useAppLocale();
|
|
133
|
+
return useMemo(() => ({ id: locale as string, agent: translateTree(AGENT, t) }), [locale, t]);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function format(template: string, vars: Record<string, string | number>): string {
|
|
137
|
+
return template.replace(/\{(\w+)\}/g, (whole, key: string) =>
|
|
138
|
+
vars[key] === undefined ? whole : String(vars[key]),
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function plural(count: number, forms: { one: string; other: string }): string {
|
|
143
|
+
return count === 1 ? forms.one : forms.other;
|
|
144
|
+
}
|
package/src/app/lib/utils.ts
CHANGED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { useParams, useSearchParams } from 'react-router-dom';
|
|
3
|
+
import { PageFrame } from '../components/page-frame';
|
|
4
|
+
import { nextFrame, waitForFonts } from '../lib/print-ready';
|
|
5
|
+
import { scanDocument } from '../lib/scan';
|
|
6
|
+
import { pageLang, resolvePageGeometry } from '../lib/sdk';
|
|
7
|
+
import { useDocModule } from '../lib/use-doc-module';
|
|
8
|
+
import { useDocPages } from '../lib/use-doc-pages';
|
|
9
|
+
|
|
10
|
+
/** Set on the page once it is laid out, numbered and in its fonts — the moment a screenshot is true. */
|
|
11
|
+
export const PREVIEW_READY_ATTR = 'data-od-preview-ready';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* One sheet at its true size with nothing around it: `/d/<id>/preview?p=3`.
|
|
15
|
+
* An agent screenshots it to see what it just changed. Every page is still
|
|
16
|
+
* drawn — contents, figure numbers and cross-references are counted across
|
|
17
|
+
* the whole document — but only the asked-for one is shown.
|
|
18
|
+
*/
|
|
19
|
+
export function DocPreview() {
|
|
20
|
+
const { docId } = useParams<{ docId: string }>();
|
|
21
|
+
const [params] = useSearchParams();
|
|
22
|
+
const state = useDocModule(docId);
|
|
23
|
+
const doc = state.doc;
|
|
24
|
+
const geometry = useMemo(() => resolvePageGeometry(doc?.meta), [doc?.meta]);
|
|
25
|
+
const { pages, measuring } = useDocPages(doc, geometry);
|
|
26
|
+
const pagesRef = useRef<HTMLDivElement>(null);
|
|
27
|
+
const [ready, setReady] = useState(false);
|
|
28
|
+
|
|
29
|
+
const asked = Number.parseInt(params.get('p') ?? '1', 10);
|
|
30
|
+
const page = Number.isFinite(asked) ? Math.min(Math.max(asked, 1), Math.max(pages.length, 1)) : 1;
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
setReady(false);
|
|
34
|
+
if (state.status !== 'ready' || measuring) return;
|
|
35
|
+
let cancelled = false;
|
|
36
|
+
(async () => {
|
|
37
|
+
await nextFrame();
|
|
38
|
+
await waitForFonts();
|
|
39
|
+
await nextFrame();
|
|
40
|
+
const root = pagesRef.current;
|
|
41
|
+
if (cancelled || !root) return;
|
|
42
|
+
scanDocument(root, doc?.meta);
|
|
43
|
+
// The numbers the scan resolved are drawn on the next commit.
|
|
44
|
+
await nextFrame();
|
|
45
|
+
await nextFrame();
|
|
46
|
+
if (!cancelled) setReady(true);
|
|
47
|
+
})();
|
|
48
|
+
return () => {
|
|
49
|
+
cancelled = true;
|
|
50
|
+
};
|
|
51
|
+
}, [state.status, doc, measuring]);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
document.title = doc ? `${doc.meta?.title ?? docId} · p. ${page}` : 'open-doc';
|
|
55
|
+
}, [doc, docId, page]);
|
|
56
|
+
|
|
57
|
+
if (state.status === 'error') {
|
|
58
|
+
return (
|
|
59
|
+
<p role="alert" className="p-6 font-mono text-sm">
|
|
60
|
+
{state.error.message}
|
|
61
|
+
</p>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div
|
|
67
|
+
className="min-h-screen bg-white"
|
|
68
|
+
{...{ [PREVIEW_READY_ATTR]: ready ? 'true' : 'false' }}
|
|
69
|
+
data-od-preview-page={page}
|
|
70
|
+
data-od-preview-pages={pages.length}
|
|
71
|
+
>
|
|
72
|
+
<div ref={pagesRef} data-od-viewer="">
|
|
73
|
+
{doc &&
|
|
74
|
+
pages.map((entry, index) => (
|
|
75
|
+
// The other sheets are laid out where they are, out of sight, so
|
|
76
|
+
// what the scan counts on them is counted as the viewer counts it.
|
|
77
|
+
<div
|
|
78
|
+
key={entry.key}
|
|
79
|
+
style={
|
|
80
|
+
index + 1 === page
|
|
81
|
+
? undefined
|
|
82
|
+
: { position: 'absolute', left: -99999, top: 0, visibility: 'hidden' }
|
|
83
|
+
}
|
|
84
|
+
aria-hidden={index + 1 === page ? undefined : true}
|
|
85
|
+
>
|
|
86
|
+
<PageFrame
|
|
87
|
+
index={index}
|
|
88
|
+
total={pages.length}
|
|
89
|
+
geometry={geometry}
|
|
90
|
+
scale={1}
|
|
91
|
+
design={doc.design}
|
|
92
|
+
lang={pageLang(doc.meta)}
|
|
93
|
+
watermark={doc.meta?.watermark}
|
|
94
|
+
flat
|
|
95
|
+
>
|
|
96
|
+
{entry.content}
|
|
97
|
+
</PageFrame>
|
|
98
|
+
</div>
|
|
99
|
+
))}
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
package/src/app/routes/doc.tsx
CHANGED
|
@@ -27,10 +27,16 @@ import {
|
|
|
27
27
|
Pencil,
|
|
28
28
|
Plus,
|
|
29
29
|
Rows3,
|
|
30
|
+
Sparkles,
|
|
30
31
|
} from 'lucide-react';
|
|
31
32
|
import { useTheme } from 'next-themes';
|
|
32
33
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
33
34
|
import { Link, useNavigate, useParams } from 'react-router-dom';
|
|
35
|
+
import { applyCommentsPrompt } from '../../agent/prompt';
|
|
36
|
+
import type { AgentTurnContext } from '../../agent/types';
|
|
37
|
+
import { AgentDockFrame } from '../components/agent/agent-dock';
|
|
38
|
+
import { AgentPanel } from '../components/agent/agent-panel';
|
|
39
|
+
import { AgentPresence } from '../components/agent/agent-presence';
|
|
34
40
|
import { ChangesOverlay, elementsOf } from '../components/changes/changes-overlay';
|
|
35
41
|
import { ChangesPanel } from '../components/changes/changes-panel';
|
|
36
42
|
import { type ChangeItem, itemsOf, useChanges } from '../components/changes/use-changes';
|
|
@@ -51,6 +57,13 @@ import { EditSaveCard } from '../components/panel/edit-save-card';
|
|
|
51
57
|
import { RecordPicker } from '../components/record-picker';
|
|
52
58
|
import { ThemeToggle } from '../components/theme-toggle';
|
|
53
59
|
import { Menu, MenuItem } from '../components/ui/menu';
|
|
60
|
+
import {
|
|
61
|
+
requestAgent,
|
|
62
|
+
setDockOpen as setAgentDockOpen,
|
|
63
|
+
useAgentActivity,
|
|
64
|
+
useAgentDock,
|
|
65
|
+
useAgentStatus,
|
|
66
|
+
} from '../lib/agent/use-agent';
|
|
54
67
|
import { useAgentBridge } from '../lib/agent-bridge';
|
|
55
68
|
import { exportDocAsDocx } from '../lib/export-docx';
|
|
56
69
|
import { exportDocAsHtml } from '../lib/export-html';
|
|
@@ -79,6 +92,8 @@ import {
|
|
|
79
92
|
writeViewMode,
|
|
80
93
|
} from '../lib/view-mode';
|
|
81
94
|
|
|
95
|
+
type PickedElement = { loc: string; tag: string; text?: string };
|
|
96
|
+
|
|
82
97
|
type DownloadFormat = 'pdf' | 'html' | 'png' | 'svg' | 'docx';
|
|
83
98
|
|
|
84
99
|
const DOWNLOAD_LABEL: Record<DownloadFormat, string> = {
|
|
@@ -216,16 +231,23 @@ export function Doc() {
|
|
|
216
231
|
const [customRange, setCustomRange] = useState('');
|
|
217
232
|
// One dock on the right, one panel in it at a time; the element panel takes
|
|
218
233
|
// it back whenever an element is picked.
|
|
219
|
-
|
|
234
|
+
// The agent's half of it is app-wide, as in open-slide: the comments panel,
|
|
235
|
+
// a new document and a reload all open it from outside this route.
|
|
236
|
+
const [panel, setPanel] = useState<'design' | 'changes' | 'comments' | null>(null);
|
|
237
|
+
const { open: agentOpen } = useAgentDock();
|
|
238
|
+
const dock = agentOpen ? 'agent' : panel;
|
|
220
239
|
const designOpen = dock === 'design';
|
|
221
240
|
const changesOpen = dock === 'changes';
|
|
222
241
|
const commentsOpen = dock === 'comments';
|
|
242
|
+
const setDock = useCallback((next: 'design' | 'changes' | 'comments' | 'agent' | null) => {
|
|
243
|
+
setAgentDockOpen(next === 'agent');
|
|
244
|
+
setPanel(next === 'agent' ? null : next);
|
|
245
|
+
}, []);
|
|
223
246
|
const toggleDock = useCallback(
|
|
224
|
-
(
|
|
225
|
-
|
|
226
|
-
[],
|
|
247
|
+
(next: 'design' | 'changes' | 'comments' | 'agent') => setDock(dock === next ? null : next),
|
|
248
|
+
[dock, setDock],
|
|
227
249
|
);
|
|
228
|
-
const closeDock = useCallback(() => setDock(null), []);
|
|
250
|
+
const closeDock = useCallback(() => setDock(null), [setDock]);
|
|
229
251
|
const [editing, setEditingState] = useState(readEditing);
|
|
230
252
|
// The dev server reloads every open viewer when a document is added or
|
|
231
253
|
// removed anywhere in the workspace. Edit mode is per tab and survives that.
|
|
@@ -291,6 +313,34 @@ export function Doc() {
|
|
|
291
313
|
() => new Set([...commentPlacement.values()].flat()),
|
|
292
314
|
[commentPlacement],
|
|
293
315
|
);
|
|
316
|
+
// The agent's dock exists whenever the dev server answers for it; until an
|
|
317
|
+
// agent is connected it explains how to connect one.
|
|
318
|
+
const agentStatus = useAgentStatus();
|
|
319
|
+
const agentAvailable = agentStatus.enabled;
|
|
320
|
+
const [pickedElement, setPickedElement] = useState<PickedElement | null>(null);
|
|
321
|
+
const agentContext = useMemo<AgentTurnContext>(() => {
|
|
322
|
+
const [line, column] = (pickedElement?.loc ?? '').split(':').map(Number);
|
|
323
|
+
return {
|
|
324
|
+
...(docId ? { docId } : {}),
|
|
325
|
+
...(doc?.meta?.title ? { docTitle: doc.meta.title } : {}),
|
|
326
|
+
...(pages.length > 0 ? { pageNumber: currentPage, totalPages: pages.length } : {}),
|
|
327
|
+
pendingComments: commentList.length,
|
|
328
|
+
selection:
|
|
329
|
+
pickedElement && line && column !== undefined && !Number.isNaN(column)
|
|
330
|
+
? { line, column, tagName: pickedElement.tag, text: pickedElement.text ?? '' }
|
|
331
|
+
: null,
|
|
332
|
+
};
|
|
333
|
+
}, [docId, doc?.meta?.title, pages.length, currentPage, commentList.length, pickedElement]);
|
|
334
|
+
// While an agent writes this document section by section, follow the pages
|
|
335
|
+
// as they appear so the reader watches it grow.
|
|
336
|
+
const scrollToPageRef = useRef<(page: number) => void>(() => {});
|
|
337
|
+
const agentActivity = useAgentActivity(docId ?? '');
|
|
338
|
+
const agentWriting = agentActivity !== null;
|
|
339
|
+
const seenPageCount = useRef(pages.length);
|
|
340
|
+
useEffect(() => {
|
|
341
|
+
if (agentWriting && pages.length > seenPageCount.current) scrollToPageRef.current(pages.length);
|
|
342
|
+
seenPageCount.current = pages.length;
|
|
343
|
+
}, [agentWriting, pages.length]);
|
|
294
344
|
const [activeComment, setActiveComment] = useState<string | null>(null);
|
|
295
345
|
const selectComment = useCallback((comment: DocComment) => {
|
|
296
346
|
setActiveComment(comment.id);
|
|
@@ -315,7 +365,7 @@ export function Doc() {
|
|
|
315
365
|
const pickElement = useCallback(() => {
|
|
316
366
|
setDock(null);
|
|
317
367
|
setPicking(false);
|
|
318
|
-
}, []);
|
|
368
|
+
}, [setDock]);
|
|
319
369
|
const cancelPick = useCallback(() => setPicking(false), []);
|
|
320
370
|
useEffect(() => {
|
|
321
371
|
if (!editing) {
|
|
@@ -460,6 +510,7 @@ export function Doc() {
|
|
|
460
510
|
const frame = pagesRef.current?.children[page - 1];
|
|
461
511
|
frame?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
462
512
|
}, []);
|
|
513
|
+
scrollToPageRef.current = scrollToPage;
|
|
463
514
|
|
|
464
515
|
// Land the heading near the top of the reading pane, not centred — the reader
|
|
465
516
|
// wants what follows the heading, and centring buries half of it.
|
|
@@ -670,6 +721,19 @@ export function Doc() {
|
|
|
670
721
|
icon: MessageSquare,
|
|
671
722
|
run: () => toggleDock('comments'),
|
|
672
723
|
},
|
|
724
|
+
...(agentAvailable
|
|
725
|
+
? [
|
|
726
|
+
{
|
|
727
|
+
id: 'agent',
|
|
728
|
+
group: t('Actions'),
|
|
729
|
+
label: agentOpen ? t('Close the agent panel') : t('Ask the agent'),
|
|
730
|
+
hint: 'A',
|
|
731
|
+
keywords: 'agent codex ai chat',
|
|
732
|
+
icon: Sparkles,
|
|
733
|
+
run: () => toggleDock('agent'),
|
|
734
|
+
},
|
|
735
|
+
]
|
|
736
|
+
: []),
|
|
673
737
|
);
|
|
674
738
|
}
|
|
675
739
|
return [
|
|
@@ -716,11 +780,14 @@ export function Doc() {
|
|
|
716
780
|
} else if (import.meta.env.DEV && (e.key === 'm' || e.key === 'M')) {
|
|
717
781
|
e.preventDefault();
|
|
718
782
|
toggleDock('comments');
|
|
783
|
+
} else if (agentAvailable && (e.key === 'a' || e.key === 'A')) {
|
|
784
|
+
e.preventDefault();
|
|
785
|
+
toggleDock('agent');
|
|
719
786
|
}
|
|
720
787
|
};
|
|
721
788
|
window.addEventListener('keydown', onKeyDown);
|
|
722
789
|
return () => window.removeEventListener('keydown', onKeyDown);
|
|
723
|
-
}, [toggleFullscreen, toggleDock]);
|
|
790
|
+
}, [toggleFullscreen, toggleDock, agentAvailable]);
|
|
724
791
|
|
|
725
792
|
if (state.status === 'error') {
|
|
726
793
|
return (
|
|
@@ -840,7 +907,7 @@ export function Doc() {
|
|
|
840
907
|
title={t('Design tokens (D)')}
|
|
841
908
|
onClick={() => toggleDock('design')}
|
|
842
909
|
className={cn(
|
|
843
|
-
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
910
|
+
'flex flex-none items-center gap-1.5 whitespace-nowrap rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
844
911
|
designOpen && 'bg-accent',
|
|
845
912
|
)}
|
|
846
913
|
>
|
|
@@ -867,7 +934,7 @@ export function Doc() {
|
|
|
867
934
|
title={`${t('Changes since the last commit')} (C)`}
|
|
868
935
|
onClick={() => toggleDock('changes')}
|
|
869
936
|
className={cn(
|
|
870
|
-
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
937
|
+
'flex flex-none items-center gap-1.5 whitespace-nowrap rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
871
938
|
changesOpen && 'bg-accent',
|
|
872
939
|
)}
|
|
873
940
|
>
|
|
@@ -897,7 +964,7 @@ export function Doc() {
|
|
|
897
964
|
title={`${t('Comments')} (M)`}
|
|
898
965
|
onClick={() => toggleDock('comments')}
|
|
899
966
|
className={cn(
|
|
900
|
-
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
967
|
+
'flex flex-none items-center gap-1.5 whitespace-nowrap rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
901
968
|
commentsOpen && 'bg-accent',
|
|
902
969
|
)}
|
|
903
970
|
>
|
|
@@ -914,6 +981,24 @@ export function Doc() {
|
|
|
914
981
|
)}
|
|
915
982
|
</button>
|
|
916
983
|
)}
|
|
984
|
+
{agentAvailable && (
|
|
985
|
+
<button
|
|
986
|
+
type="button"
|
|
987
|
+
aria-pressed={agentOpen}
|
|
988
|
+
aria-label={t('Agent')}
|
|
989
|
+
aria-keyshortcuts="A"
|
|
990
|
+
title={`${t('Agent')} (A)`}
|
|
991
|
+
onClick={() => toggleDock('agent')}
|
|
992
|
+
className="flex size-8 flex-none items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground aria-pressed:bg-accent aria-pressed:text-foreground"
|
|
993
|
+
>
|
|
994
|
+
<Sparkles
|
|
995
|
+
className={cn(
|
|
996
|
+
'size-4',
|
|
997
|
+
agentWriting && 'animate-pulse motion-reduce:animate-none',
|
|
998
|
+
)}
|
|
999
|
+
/>
|
|
1000
|
+
</button>
|
|
1001
|
+
)}
|
|
917
1002
|
|
|
918
1003
|
<CopyLink />
|
|
919
1004
|
|
|
@@ -928,7 +1013,7 @@ export function Doc() {
|
|
|
928
1013
|
<button
|
|
929
1014
|
type="button"
|
|
930
1015
|
disabled={download !== null}
|
|
931
|
-
className="flex items-center gap-1.5 rounded-md bg-primary px-2.5 py-1.5 text-primary-foreground text-xs transition-opacity hover:opacity-90 disabled:opacity-70 aria-expanded:opacity-90"
|
|
1016
|
+
className="flex flex-none items-center gap-1.5 whitespace-nowrap rounded-md bg-primary px-2.5 py-1.5 text-primary-foreground text-xs transition-opacity hover:opacity-90 disabled:opacity-70 aria-expanded:opacity-90"
|
|
932
1017
|
{...props}
|
|
933
1018
|
>
|
|
934
1019
|
{download ? (
|
|
@@ -1069,6 +1154,16 @@ export function Doc() {
|
|
|
1069
1154
|
onShownChange={setCardShown}
|
|
1070
1155
|
/>
|
|
1071
1156
|
)}
|
|
1157
|
+
{agentActivity && (
|
|
1158
|
+
// Over the pages, not in their scroll: the ring and the pill stay put
|
|
1159
|
+
// while the reader scrolls through what the agent writes.
|
|
1160
|
+
<div
|
|
1161
|
+
data-agent-provider={agentActivity.provider}
|
|
1162
|
+
className="pointer-events-none absolute inset-0 md:my-2 md:mr-2 md:rounded-xl [&_button]:pointer-events-auto"
|
|
1163
|
+
>
|
|
1164
|
+
<AgentPresence activity={agentActivity} revision={pages} />
|
|
1165
|
+
</div>
|
|
1166
|
+
)}
|
|
1072
1167
|
</div>
|
|
1073
1168
|
{editing && docId && (
|
|
1074
1169
|
// Keyed by document: a selection, or an editor carried across a
|
|
@@ -1088,9 +1183,15 @@ export function Doc() {
|
|
|
1088
1183
|
exitRef={leaveEditRef}
|
|
1089
1184
|
controlsRef={editControlsRef}
|
|
1090
1185
|
onPendingChange={setTextPending}
|
|
1186
|
+
onSelectionChange={setPickedElement}
|
|
1091
1187
|
/>
|
|
1092
1188
|
)}
|
|
1093
1189
|
{designOpen && <DesignPanel onClose={closeDock} />}
|
|
1190
|
+
{agentOpen && (
|
|
1191
|
+
<AgentDockFrame>
|
|
1192
|
+
<AgentPanel context={agentContext} onClose={closeDock} />
|
|
1193
|
+
</AgentDockFrame>
|
|
1194
|
+
)}
|
|
1094
1195
|
{commentsOpen && docId && (
|
|
1095
1196
|
<CommentsPanel
|
|
1096
1197
|
docId={docId}
|
|
@@ -1114,6 +1215,12 @@ export function Doc() {
|
|
|
1114
1215
|
onNew={startComment}
|
|
1115
1216
|
picking={picking}
|
|
1116
1217
|
onClose={closeDock}
|
|
1218
|
+
{...(agentStatus.connected && agentStatus.providerName
|
|
1219
|
+
? {
|
|
1220
|
+
agentName: agentStatus.providerName,
|
|
1221
|
+
onApplyWithAgent: () => requestAgent({ text: applyCommentsPrompt(docId) }),
|
|
1222
|
+
}
|
|
1223
|
+
: {})}
|
|
1117
1224
|
/>
|
|
1118
1225
|
)}
|
|
1119
1226
|
{changesOpen && (
|