@agent-native/toolkit 0.6.0 → 0.7.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/README.md +17 -1
- package/dist/chat-history/ChatHistoryList.d.ts +103 -0
- package/dist/chat-history/ChatHistoryList.d.ts.map +1 -0
- package/dist/chat-history/ChatHistoryList.js +109 -0
- package/dist/chat-history/ChatHistoryList.js.map +1 -0
- package/dist/chat-history/ChatHistoryList.spec.d.ts +2 -0
- package/dist/chat-history/ChatHistoryList.spec.d.ts.map +1 -0
- package/dist/chat-history/ChatHistoryList.spec.js +283 -0
- package/dist/chat-history/ChatHistoryList.spec.js.map +1 -0
- package/dist/chat-history/index.d.ts +2 -0
- package/dist/chat-history/index.d.ts.map +1 -0
- package/dist/chat-history/index.js +2 -0
- package/dist/chat-history/index.js.map +1 -0
- package/dist/chat-history.css +314 -0
- package/package.json +17 -1
- package/src/app-shell/header-actions.tsx +84 -0
- package/src/app-shell/index.ts +1 -0
- package/src/chat-history/ChatHistoryList.spec.tsx +453 -0
- package/src/chat-history/ChatHistoryList.tsx +469 -0
- package/src/chat-history/index.ts +7 -0
- package/src/chat-history.css +314 -0
- package/src/collab-ui/AgentPresenceChip.tsx +69 -0
- package/src/collab-ui/LiveCursorOverlay.tsx +241 -0
- package/src/collab-ui/PresenceBar.tsx +346 -0
- package/src/collab-ui/RecentEditHighlights.tsx +225 -0
- package/src/collab-ui/RemoteSelectionRings.tsx +227 -0
- package/src/collab-ui/agent-identity.ts +16 -0
- package/src/collab-ui/index.ts +39 -0
- package/src/collab-ui/lead-client.ts +32 -0
- package/src/collab-ui/types.spec.ts +18 -0
- package/src/collab-ui/types.ts +96 -0
- package/src/composer/AgentComposerFrame.tsx +59 -0
- package/src/composer/ComposerPlusMenu.tsx +983 -0
- package/src/composer/MentionPopover.tsx +412 -0
- package/src/composer/PastedTextChip.tsx +150 -0
- package/src/composer/PromptComposer.spec.ts +73 -0
- package/src/composer/PromptComposer.tsx +718 -0
- package/src/composer/RealtimeVoiceMode.spec.tsx +771 -0
- package/src/composer/RealtimeVoiceMode.tsx +856 -0
- package/src/composer/TiptapComposer.spec.ts +390 -0
- package/src/composer/TiptapComposer.tsx +2936 -0
- package/src/composer/VoiceButton.spec.ts +33 -0
- package/src/composer/VoiceButton.tsx +255 -0
- package/src/composer/asset-picker-url.spec.ts +56 -0
- package/src/composer/asset-picker-url.ts +80 -0
- package/src/composer/attachment-accept.spec.ts +22 -0
- package/src/composer/attachment-accept.ts +71 -0
- package/src/composer/draft-key.spec.ts +19 -0
- package/src/composer/draft-key.ts +7 -0
- package/src/composer/extensions/FileReference.tsx +55 -0
- package/src/composer/extensions/MentionReference.tsx +93 -0
- package/src/composer/extensions/SkillReference.tsx +56 -0
- package/src/composer/index.ts +79 -0
- package/src/composer/pasted-text.spec.ts +162 -0
- package/src/composer/pasted-text.ts +160 -0
- package/src/composer/prompt-attachments.spec.ts +80 -0
- package/src/composer/prompt-attachments.ts +93 -0
- package/src/composer/realtime-voice-audio-level.spec.ts +32 -0
- package/src/composer/realtime-voice-audio-level.ts +64 -0
- package/src/composer/realtime-voice-transcript.spec.ts +95 -0
- package/src/composer/realtime-voice-transcript.ts +134 -0
- package/src/composer/runtime-adapters.tsx +343 -0
- package/src/composer/types.ts +66 -0
- package/src/composer/use-file-search.ts +64 -0
- package/src/composer/use-mention-search.ts +90 -0
- package/src/composer/use-skills.ts +45 -0
- package/src/composer/useRealtimeVoiceMode.spec.ts +818 -0
- package/src/composer/useRealtimeVoiceMode.tsx +2117 -0
- package/src/composer/useVoiceDictation.spec.ts +45 -0
- package/src/composer/useVoiceDictation.ts +1191 -0
- package/src/context-ui/ContextMeter.tsx +101 -0
- package/src/context-ui/ContextSegmentRow.tsx +184 -0
- package/src/context-ui/ContextTreemap.tsx +125 -0
- package/src/context-ui/ContextXRayPanel.tsx +377 -0
- package/src/context-ui/format.ts +42 -0
- package/src/context-ui/index.ts +15 -0
- package/src/context-ui/types.ts +43 -0
- package/src/design-tweaks/index.ts +1 -0
- package/src/design-tweaks/visual-style-controls.tsx +1084 -0
- package/src/editor/BubbleToolbar.tsx +253 -0
- package/src/editor/CodeBlockNode.tsx +254 -0
- package/src/editor/DragHandle.spec.ts +588 -0
- package/src/editor/DragHandle.ts +1437 -0
- package/src/editor/ImageExtension.roundtrip.spec.ts +117 -0
- package/src/editor/ImageExtension.ts +306 -0
- package/src/editor/RegistryBlockContext.tsx +107 -0
- package/src/editor/RegistryBlockNode.spec.ts +279 -0
- package/src/editor/RegistryBlockNode.tsx +652 -0
- package/src/editor/RichMarkdownEditor.collab.spec.ts +79 -0
- package/src/editor/RichMarkdownEditor.roundtrip.spec.ts +226 -0
- package/src/editor/RichMarkdownEditor.tsx +81 -0
- package/src/editor/RunId.ts +61 -0
- package/src/editor/SharedRichEditor.tsx +321 -0
- package/src/editor/SlashCommandMenu.tsx +310 -0
- package/src/editor/disableHistory.spec.ts +85 -0
- package/src/editor/extensions.ts +402 -0
- package/src/editor/gfmDoc.spec.ts +230 -0
- package/src/editor/gfmDoc.ts +92 -0
- package/src/editor/index.ts +93 -0
- package/src/editor/registrySlashCommands.ts +131 -0
- package/src/editor/structuralReorderUndo.spec.ts +144 -0
- package/src/editor/surgical-apply.spec.ts +279 -0
- package/src/editor/surgical-apply.ts +192 -0
- package/src/editor/useCollabReconcile.concurrent.spec.ts +422 -0
- package/src/editor/useCollabReconcile.idempotent.spec.ts +324 -0
- package/src/editor/useCollabReconcile.ts +589 -0
- package/src/editor.css +510 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/use-mobile.tsx +21 -0
- package/src/hooks/use-toast.ts +188 -0
- package/src/index.ts +8 -0
- package/src/onboarding/index.ts +1 -0
- package/src/provider.tsx +47 -0
- package/src/sharing/VisibilityBadge.spec.ts +96 -0
- package/src/sharing/VisibilityBadge.tsx +37 -0
- package/src/sharing/index.ts +4 -0
- package/src/styles.css +21 -0
- package/src/ui/accordion.tsx +56 -0
- package/src/ui/alert-dialog.tsx +141 -0
- package/src/ui/alert.tsx +59 -0
- package/src/ui/aspect-ratio.tsx +5 -0
- package/src/ui/avatar.tsx +48 -0
- package/src/ui/badge.tsx +37 -0
- package/src/ui/breadcrumb.tsx +115 -0
- package/src/ui/button.tsx +78 -0
- package/src/ui/calendar.tsx +214 -0
- package/src/ui/card.tsx +86 -0
- package/src/ui/carousel.tsx +260 -0
- package/src/ui/chart.tsx +375 -0
- package/src/ui/checkbox.tsx +28 -0
- package/src/ui/collapsible.tsx +9 -0
- package/src/ui/command.spec.tsx +51 -0
- package/src/ui/command.tsx +174 -0
- package/src/ui/context-menu.tsx +202 -0
- package/src/ui/date-picker.tsx +64 -0
- package/src/ui/dialog.spec.tsx +43 -0
- package/src/ui/dialog.tsx +146 -0
- package/src/ui/drawer.tsx +126 -0
- package/src/ui/dropdown-menu.tsx +218 -0
- package/src/ui/form.tsx +177 -0
- package/src/ui/hover-card.tsx +27 -0
- package/src/ui/index.ts +52 -0
- package/src/ui/input-otp.tsx +69 -0
- package/src/ui/input.tsx +22 -0
- package/src/ui/label.tsx +24 -0
- package/src/ui/logo.tsx +36 -0
- package/src/ui/menubar.tsx +235 -0
- package/src/ui/navigation-menu.tsx +128 -0
- package/src/ui/pagination.tsx +121 -0
- package/src/ui/popover.tsx +44 -0
- package/src/ui/progress.tsx +26 -0
- package/src/ui/radio-group.tsx +42 -0
- package/src/ui/resizable.tsx +43 -0
- package/src/ui/scroll-area.tsx +46 -0
- package/src/ui/select.tsx +158 -0
- package/src/ui/separator.tsx +29 -0
- package/src/ui/sheet.tsx +160 -0
- package/src/ui/sidebar.tsx +777 -0
- package/src/ui/skeleton.tsx +18 -0
- package/src/ui/slider.tsx +26 -0
- package/src/ui/sonner.tsx +58 -0
- package/src/ui/spinner.tsx +17 -0
- package/src/ui/switch.tsx +27 -0
- package/src/ui/table.tsx +117 -0
- package/src/ui/tabs.tsx +53 -0
- package/src/ui/textarea.tsx +23 -0
- package/src/ui/toast.tsx +127 -0
- package/src/ui/toaster.tsx +33 -0
- package/src/ui/toggle-group.tsx +59 -0
- package/src/ui/toggle.tsx +43 -0
- package/src/ui/tooltip.tsx +53 -0
- package/src/ui/use-toast.ts +3 -0
- package/src/utils.ts +8 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { Editor } from "@tiptap/core";
|
|
4
|
+
import { Slice } from "@tiptap/pm/model";
|
|
5
|
+
import { NodeSelection } from "@tiptap/pm/state";
|
|
6
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
7
|
+
import React, { act } from "react";
|
|
8
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
createRegistryBlockNode,
|
|
13
|
+
LegacyJsonEditSurface,
|
|
14
|
+
type RegistryBlockSideMapBlock,
|
|
15
|
+
} from "./RegistryBlockNode.js";
|
|
16
|
+
|
|
17
|
+
const PlanBlockNode = createRegistryBlockNode({
|
|
18
|
+
nodeName: "planBlock",
|
|
19
|
+
dataTag: "data-plan-block",
|
|
20
|
+
mintId: (blockType) => `${blockType}-fresh`,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function createEditor(): Editor {
|
|
24
|
+
const element = document.createElement("div");
|
|
25
|
+
document.body.appendChild(element);
|
|
26
|
+
return new Editor({
|
|
27
|
+
element,
|
|
28
|
+
extensions: [StarterKit, PlanBlockNode],
|
|
29
|
+
content: {
|
|
30
|
+
type: "doc",
|
|
31
|
+
content: [
|
|
32
|
+
{
|
|
33
|
+
type: "paragraph",
|
|
34
|
+
content: [{ type: "text", text: "Before" }],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: "planBlock",
|
|
38
|
+
attrs: {
|
|
39
|
+
blockType: "diagram",
|
|
40
|
+
blockId: "diagram-1",
|
|
41
|
+
title: "Architecture diagram",
|
|
42
|
+
summary: null,
|
|
43
|
+
sourceBlockId: null,
|
|
44
|
+
__raw: null,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: "paragraph",
|
|
49
|
+
content: [{ type: "text", text: "After" }],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function findPlanBlockPos(editor: Editor): number {
|
|
57
|
+
let found = -1;
|
|
58
|
+
editor.state.doc.descendants((node, pos) => {
|
|
59
|
+
if (node.type.name === "planBlock") {
|
|
60
|
+
found = pos;
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
});
|
|
65
|
+
if (found < 0) throw new Error("Expected planBlock node");
|
|
66
|
+
return found;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function selectPlanBlock(editor: Editor): void {
|
|
70
|
+
const pos = findPlanBlockPos(editor);
|
|
71
|
+
editor.view.dispatch(
|
|
72
|
+
editor.state.tr.setSelection(NodeSelection.create(editor.state.doc, pos)),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function planBlockSnapshot(editor: Editor): unknown {
|
|
77
|
+
return editor.state.doc.nodeAt(findPlanBlockPos(editor))?.toJSON();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function runKeyDown(editor: Editor, key: string): KeyboardEvent {
|
|
81
|
+
const event = new KeyboardEvent("keydown", {
|
|
82
|
+
key,
|
|
83
|
+
bubbles: true,
|
|
84
|
+
cancelable: true,
|
|
85
|
+
});
|
|
86
|
+
const handled = editor.view.someProp("handleKeyDown", (handler) =>
|
|
87
|
+
handler(editor.view, event),
|
|
88
|
+
);
|
|
89
|
+
expect(handled).toBe(true);
|
|
90
|
+
return event;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
afterEach(() => {
|
|
94
|
+
document.body.innerHTML = "";
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("RegistryBlockNode keyboard guard", () => {
|
|
98
|
+
it("keeps selected registry atoms immutable for text entry and preserves undo history", () => {
|
|
99
|
+
const editor = createEditor();
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
editor.commands.setTextSelection(7);
|
|
103
|
+
editor.commands.insertContent("!");
|
|
104
|
+
expect(editor.state.doc.child(0).textContent).toBe("Before!");
|
|
105
|
+
|
|
106
|
+
selectPlanBlock(editor);
|
|
107
|
+
const beforeAtom = planBlockSnapshot(editor);
|
|
108
|
+
|
|
109
|
+
const keyEvent = runKeyDown(editor, "x");
|
|
110
|
+
expect(keyEvent.defaultPrevented).toBe(true);
|
|
111
|
+
expect(planBlockSnapshot(editor)).toEqual(beforeAtom);
|
|
112
|
+
|
|
113
|
+
const enterEvent = runKeyDown(editor, "Enter");
|
|
114
|
+
expect(enterEvent.defaultPrevented).toBe(true);
|
|
115
|
+
expect(planBlockSnapshot(editor)).toEqual(beforeAtom);
|
|
116
|
+
|
|
117
|
+
const textInputHandled = editor.view.someProp(
|
|
118
|
+
"handleTextInput",
|
|
119
|
+
(handler) => handler(editor.view, 0, 0, "typed", () => editor.state.tr),
|
|
120
|
+
);
|
|
121
|
+
expect(textInputHandled).toBe(true);
|
|
122
|
+
expect(planBlockSnapshot(editor)).toEqual(beforeAtom);
|
|
123
|
+
|
|
124
|
+
const pasteEvent = new Event("paste", {
|
|
125
|
+
bubbles: true,
|
|
126
|
+
cancelable: true,
|
|
127
|
+
}) as ClipboardEvent;
|
|
128
|
+
const pasteHandled = editor.view.someProp("handlePaste", (handler) =>
|
|
129
|
+
handler(editor.view, pasteEvent, Slice.empty),
|
|
130
|
+
);
|
|
131
|
+
expect(pasteHandled).toBe(true);
|
|
132
|
+
expect(pasteEvent.defaultPrevented).toBe(true);
|
|
133
|
+
expect(planBlockSnapshot(editor)).toEqual(beforeAtom);
|
|
134
|
+
|
|
135
|
+
const beforeInputEvent = new InputEvent("beforeinput", {
|
|
136
|
+
data: "z",
|
|
137
|
+
inputType: "insertText",
|
|
138
|
+
bubbles: true,
|
|
139
|
+
cancelable: true,
|
|
140
|
+
});
|
|
141
|
+
const beforeInputHandled = editor.view.someProp(
|
|
142
|
+
"handleDOMEvents",
|
|
143
|
+
(handlers) => handlers.beforeinput?.(editor.view, beforeInputEvent),
|
|
144
|
+
);
|
|
145
|
+
expect(beforeInputHandled).toBe(true);
|
|
146
|
+
expect(beforeInputEvent.defaultPrevented).toBe(true);
|
|
147
|
+
expect(planBlockSnapshot(editor)).toEqual(beforeAtom);
|
|
148
|
+
|
|
149
|
+
expect(editor.commands.undo()).toBe(true);
|
|
150
|
+
expect(editor.state.doc.child(0).textContent).toBe("Before");
|
|
151
|
+
expect(editor.state.doc.textContent).not.toContain("Module");
|
|
152
|
+
expect(planBlockSnapshot(editor)).toEqual(beforeAtom);
|
|
153
|
+
} finally {
|
|
154
|
+
editor.destroy();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe("LegacyJsonEditSurface", () => {
|
|
160
|
+
let container: HTMLDivElement;
|
|
161
|
+
let root: Root;
|
|
162
|
+
|
|
163
|
+
beforeEach(() => {
|
|
164
|
+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
|
165
|
+
container = document.createElement("div");
|
|
166
|
+
document.body.appendChild(container);
|
|
167
|
+
root = createRoot(container);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
afterEach(() => {
|
|
171
|
+
act(() => {
|
|
172
|
+
root.unmount();
|
|
173
|
+
});
|
|
174
|
+
container.remove();
|
|
175
|
+
vi.unstubAllGlobals();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
function renderLegacyEditor(
|
|
179
|
+
block: RegistryBlockSideMapBlock,
|
|
180
|
+
onChange = vi.fn(),
|
|
181
|
+
) {
|
|
182
|
+
const onOpenChange = vi.fn();
|
|
183
|
+
act(() => {
|
|
184
|
+
root.render(
|
|
185
|
+
React.createElement(LegacyJsonEditSurface, {
|
|
186
|
+
block,
|
|
187
|
+
open: true,
|
|
188
|
+
onOpenChange,
|
|
189
|
+
onChange,
|
|
190
|
+
selected: false,
|
|
191
|
+
}),
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
return { onChange, onOpenChange };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function textarea(): HTMLTextAreaElement {
|
|
198
|
+
const element = container.querySelector("textarea");
|
|
199
|
+
if (!element) throw new Error("Expected textarea");
|
|
200
|
+
return element;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function saveButton(): HTMLButtonElement {
|
|
204
|
+
const element = Array.from(container.querySelectorAll("button")).find(
|
|
205
|
+
(button) => button.textContent === "Save",
|
|
206
|
+
);
|
|
207
|
+
if (!element) throw new Error("Expected Save button");
|
|
208
|
+
return element;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function setTextareaValue(value: string): void {
|
|
212
|
+
const element = textarea();
|
|
213
|
+
const setter = Object.getOwnPropertyDescriptor(
|
|
214
|
+
HTMLTextAreaElement.prototype,
|
|
215
|
+
"value",
|
|
216
|
+
)?.set;
|
|
217
|
+
setter?.call(element, value);
|
|
218
|
+
element.dispatchEvent(new Event("input", { bubbles: true }));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
it("shows an inline error instead of throwing on malformed JSON", () => {
|
|
222
|
+
const onChange = vi.fn();
|
|
223
|
+
const { onOpenChange } = renderLegacyEditor(
|
|
224
|
+
{
|
|
225
|
+
id: "legacy-1",
|
|
226
|
+
data: { ok: true },
|
|
227
|
+
},
|
|
228
|
+
onChange,
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
act(() => {
|
|
232
|
+
setTextareaValue("{ nope");
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
expect(() => {
|
|
236
|
+
act(() => {
|
|
237
|
+
saveButton().dispatchEvent(
|
|
238
|
+
new MouseEvent("click", { bubbles: true, cancelable: true }),
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
}).not.toThrow();
|
|
242
|
+
|
|
243
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
244
|
+
expect(onOpenChange).not.toHaveBeenCalledWith(false);
|
|
245
|
+
expect(container.textContent).toContain("Invalid JSON");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("resyncs the draft when block data changes before saving", () => {
|
|
249
|
+
const onChange = vi.fn();
|
|
250
|
+
const block: RegistryBlockSideMapBlock = {
|
|
251
|
+
id: "legacy-1",
|
|
252
|
+
data: { value: "initial" },
|
|
253
|
+
};
|
|
254
|
+
renderLegacyEditor(block, onChange);
|
|
255
|
+
expect(textarea().value).toContain("initial");
|
|
256
|
+
|
|
257
|
+
act(() => {
|
|
258
|
+
root.render(
|
|
259
|
+
React.createElement(LegacyJsonEditSurface, {
|
|
260
|
+
block: { ...block, data: { value: "updated" } },
|
|
261
|
+
open: true,
|
|
262
|
+
onOpenChange: vi.fn(),
|
|
263
|
+
onChange,
|
|
264
|
+
selected: false,
|
|
265
|
+
}),
|
|
266
|
+
);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
expect(textarea().value).toContain("updated");
|
|
270
|
+
|
|
271
|
+
act(() => {
|
|
272
|
+
saveButton().dispatchEvent(
|
|
273
|
+
new MouseEvent("click", { bubbles: true, cancelable: true }),
|
|
274
|
+
);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
expect(onChange).toHaveBeenCalledWith({ value: "updated" });
|
|
278
|
+
});
|
|
279
|
+
});
|