@gntik-ai/templates 0.11.0 → 0.13.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.
Files changed (70) hide show
  1. package/dist/index.d.ts +24 -10
  2. package/dist/index.js +304 -266
  3. package/dist/index.js.map +1 -1
  4. package/package.json +8 -8
  5. package/src/assistant-chat/Page.test.tsx +37 -7
  6. package/src/assistant-chat/Page.tsx +98 -137
  7. package/src/assistant-chat/data.ts +69 -1
  8. package/src/assistant-chat/examples/AdapterChat.tsx +9 -0
  9. package/src/assistant-chat/template.meta.ts +1 -1
  10. package/src/board/Lane.tsx +1 -1
  11. package/src/code-editor/Page.test.tsx +12 -0
  12. package/src/code-editor/Page.tsx +2 -1
  13. package/src/code-editor/examples/PaletteTypography.tsx +130 -0
  14. package/src/code-editor/template.meta.ts +1 -1
  15. package/src/contact/Page.test.tsx +106 -0
  16. package/src/contact/Page.tsx +21 -3
  17. package/src/contact/PublicFrame.tsx +2 -17
  18. package/src/contact/examples/CustomFailure.tsx +24 -0
  19. package/src/contact/examples/FailedSend.tsx +19 -0
  20. package/src/contact/template.meta.ts +2 -2
  21. package/src/docs-article/Page.tsx +1 -1
  22. package/src/help-home/Page.test.tsx +10 -0
  23. package/src/help-home/Page.tsx +2 -4
  24. package/src/incident-console/Page.tsx +1 -1
  25. package/src/keyboard-shortcuts/Page.test.tsx +23 -1
  26. package/src/keyboard-shortcuts/Page.tsx +13 -3
  27. package/src/keyboard-shortcuts/ShortcutSheet.tsx +4 -5
  28. package/src/landing/Page.tsx +3 -17
  29. package/src/landing/template.meta.ts +1 -1
  30. package/src/messaging/Page.test.tsx +20 -3
  31. package/src/messaging/Page.tsx +15 -43
  32. package/src/messaging/template.meta.ts +1 -1
  33. package/src/notification-inbox/Page.tsx +1 -1
  34. package/src/pending-activation/Page.test.tsx +1 -1
  35. package/src/pricing/PublicFrame.tsx +2 -17
  36. package/src/pricing/template.meta.ts +1 -1
  37. package/src/resource-detail/Page.default.test.tsx +3 -2
  38. package/src/resource-detail/__snapshots__/Page.default.test.tsx.snap +2 -4
  39. package/src/resource-index/Page.test.tsx +178 -1
  40. package/src/resource-index/Page.tsx +59 -3
  41. package/src/resource-index/examples/UrlSynced.tsx +10 -0
  42. package/src/resource-index/template.meta.ts +1 -1
  43. package/src/resource-tree/Page.tsx +1 -1
  44. package/src/run-trace/Page.tsx +2 -2
  45. package/src/scorecard/Page.test.tsx +54 -0
  46. package/src/scorecard/Page.tsx +2 -0
  47. package/src/scorecard/data.ts +1 -1
  48. package/src/search-results/Page.tsx +3 -6
  49. package/src/settings-appearance/Page.test.tsx +36 -1
  50. package/src/settings-appearance/Page.tsx +15 -2
  51. package/src/settings-appearance/template.meta.ts +2 -1
  52. package/src/settings-profile/__tests__/dom.ts +4 -2
  53. package/src/settings-profile/fixtures/editable.snap +1 -1
  54. package/src/shared/ConsoleShell.context.test.tsx +125 -0
  55. package/src/shared/ConsoleShell.navigation.test.tsx +100 -0
  56. package/src/shared/ConsoleShell.tsx +38 -9
  57. package/src/shell-sidebar/Examples.test.tsx +73 -0
  58. package/src/shell-sidebar/examples/Brand.tsx +16 -0
  59. package/src/shell-sidebar/examples/ContextRegion.tsx +26 -0
  60. package/src/shell-sidebar/examples/PlatformWide.tsx +11 -0
  61. package/src/shell-sidebar/examples/Tenants.tsx +42 -0
  62. package/src/shell-sidebar/examples/UserMenuChildren.tsx +23 -0
  63. package/src/shell-sidebar/template.meta.ts +1 -1
  64. package/src/sign-in/BrandPanel.tsx +2 -2
  65. package/src/sign-in/Page.test.tsx +5 -0
  66. package/src/sso-login/Page.test.tsx +6 -0
  67. package/src/sso-login/Page.tsx +1 -0
  68. package/src/test/public-footer.test.tsx +44 -0
  69. package/src/test/without-forced-colors.test.ts +44 -0
  70. package/src/test/without-forced-colors.ts +14 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gntik-ai/templates",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "gntik-ui page templates: complete product pages (auth, dashboard, resources, settings, system) on the kit layouts and blocks.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,14 +35,14 @@
35
35
  "react-dom": "^19.0.0"
36
36
  },
37
37
  "dependencies": {
38
- "@gntik-ai/blocks": "0.11.0",
39
- "@gntik-ai/charts": "0.11.0",
40
- "@gntik-ai/chat": "0.11.0",
41
- "@gntik-ai/editor": "0.11.0",
42
- "@gntik-ai/flow": "0.11.0",
38
+ "@gntik-ai/blocks": "0.13.0",
39
+ "@gntik-ai/charts": "0.12.0",
40
+ "@gntik-ai/chat": "0.13.0",
41
+ "@gntik-ai/editor": "0.12.0",
42
+ "@gntik-ai/flow": "0.12.0",
43
43
  "@gntik-ai/icons": "0.5.0",
44
- "@gntik-ai/tokens": "0.3.0",
45
- "@gntik-ai/ui": "0.11.0",
44
+ "@gntik-ai/tokens": "0.4.0",
45
+ "@gntik-ai/ui": "0.13.0",
46
46
  "lucide-react": "^1.48.0"
47
47
  },
48
48
  "devDependencies": {
@@ -1,4 +1,5 @@
1
1
  import { act, fireEvent, render, screen } from '@testing-library/react';
2
+ import { createEchoAdapter } from '@gntik-ai/chat';
2
3
  import { expectNoAxeViolations } from '../test/a11y';
3
4
  import AssistantChatPage from './Page';
4
5
  import { assistantReply, assistantTool, chunkReply } from './data';
@@ -15,34 +16,63 @@ describe('AssistantChatPage', () => {
15
16
  await expectNoAxeViolations();
16
17
  });
17
18
 
19
+ it.each(['dark', 'light', 'high_contrast'])(
20
+ 'streams a custom adapter reply into the assistant Markdown in %s',
21
+ async (theme) => {
22
+ document.documentElement.className = theme;
23
+ render(<AssistantChatPage adapter={createEchoAdapter({ delayMs: 0 })} />);
24
+ const box = screen.getByRole('textbox', { name: 'Message' });
25
+ fireEvent.change(box, { target: { value: '**hello**' } });
26
+ fireEvent.keyDown(box, { key: 'Enter' });
27
+ const assistant = await screen.findByRole('article', { name: 'Assistant' });
28
+ expect(await screen.findByText('hello', { selector: 'strong' })).toBeInTheDocument();
29
+ expect(assistant).toHaveTextContent('hello');
30
+ expect(screen.queryByRole('button', { name: /list_deployments/ })).not.toBeInTheDocument();
31
+ await expectNoAxeViolations();
32
+ },
33
+ );
34
+
18
35
  describe('with fake timers', () => {
19
36
  beforeEach(() => vi.useFakeTimers());
20
37
  afterEach(() => vi.useRealTimers());
21
38
 
22
- it('streams a reply with a tool call and sources after a suggestion', { timeout: 15000 }, () => {
39
+ it('streams a reply with a tool call and sources after a suggestion', { timeout: 15000 }, async () => {
23
40
  const onSend = vi.fn();
24
41
  render(<AssistantChatPage onSend={onSend} />);
25
- fireEvent.click(screen.getByRole('button', { name: /Summarise this week/ }));
42
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: /Summarise this week/ })));
26
43
  expect(onSend).toHaveBeenCalledWith('Summarise this week’s deployments');
27
44
  expect(screen.getByRole('button', { name: /list_deployments/ })).toHaveTextContent('Running');
28
- act(() => vi.advanceTimersByTime(total));
45
+ await act(async () => vi.advanceTimersByTimeAsync(total));
29
46
  expect(screen.getByRole('button', { name: /list_deployments/ })).toHaveTextContent('Succeeded');
30
47
  expect(screen.getByRole('table')).toBeInTheDocument();
31
48
  expect(screen.getAllByRole('region', { name: 'Sources' }).length).toBeGreaterThan(0);
32
49
  });
33
50
 
34
- it('Stop ends the stream and unmounting clears pending timers', { timeout: 15000 }, () => {
51
+ it('keeps the stopped-tool error and retries with the adapter', async () => {
52
+ render(<AssistantChatPage />);
53
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: /Summarise this week/ })));
54
+ fireEvent.click(screen.getByRole('button', { name: 'Stop generating' }));
55
+ fireEvent.click(screen.getByRole('button', { name: /list_deployments/ }));
56
+ expect(screen.getByText('Stopped by the user.')).toHaveAttribute('role', 'alert');
57
+ expect(screen.getByText('0 ms')).toBeInTheDocument();
58
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Retry' })));
59
+ expect(screen.getByRole('button', { name: /list_deployments/ })).toHaveTextContent('Running');
60
+ await act(async () => vi.advanceTimersByTimeAsync(total));
61
+ expect(screen.getByRole('table')).toBeInTheDocument();
62
+ });
63
+
64
+ it('Stop ends the stream and unmounting clears pending timers', { timeout: 15000 }, async () => {
35
65
  const { unmount } = render(<AssistantChatPage />);
36
66
  const box = screen.getByRole('textbox', { name: 'Message' });
37
67
  fireEvent.change(box, { target: { value: 'How are deployments going?' } });
38
- fireEvent.keyDown(box, { key: 'Enter' });
39
- act(() => vi.advanceTimersByTime(assistantTool.durationMs + 90));
68
+ await act(async () => fireEvent.keyDown(box, { key: 'Enter' }));
69
+ await act(async () => vi.advanceTimersByTimeAsync(assistantTool.durationMs + 90));
40
70
  fireEvent.click(screen.getByRole('button', { name: 'Stop generating' }));
41
71
  expect(screen.getByRole('button', { name: 'Send message' })).toBeInTheDocument();
42
72
  expect(screen.getByRole('button', { name: /list_deployments/ })).toHaveTextContent('Succeeded');
43
73
 
44
74
  fireEvent.change(box, { target: { value: 'And invoices?' } });
45
- fireEvent.keyDown(box, { key: 'Enter' });
75
+ await act(async () => fireEvent.keyDown(box, { key: 'Enter' }));
46
76
  const pending = vi.getTimerCount();
47
77
  unmount();
48
78
  expect(vi.getTimerCount()).toBeLessThanOrEqual(pending - chunkReply(assistantReply).length);
@@ -1,5 +1,6 @@
1
1
  import { PageHeader } from '@gntik-ai/blocks';
2
2
  import {
3
+ AttachmentList,
3
4
  ChatAnnouncer,
4
5
  ChatComposer,
5
6
  ChatLayout,
@@ -7,16 +8,18 @@ import {
7
8
  CitationList,
8
9
  Markdown,
9
10
  SuggestionChips,
11
+ ReasoningBlock,
12
+ useChat,
13
+ type ChatAdapter,
14
+ type ChatAttachment,
10
15
  ToolCallCard,
11
16
  type ChatFeedback,
12
- type ChatRole,
13
17
  type CitationSource,
14
18
  type Suggestion,
15
- type ToolCallStatus,
16
19
  } from '@gntik-ai/chat';
17
20
  import { SquarePen } from '@gntik-ai/icons';
18
21
  import { Page, TooltipProvider, type BreadcrumbItem } from '@gntik-ai/ui';
19
- import { useEffect, useRef, useState } from 'react';
22
+ import { Fragment, useMemo, useState } from 'react';
20
23
  import { ConsoleShell, type ConsoleShellProps } from '../shared/ConsoleShell';
21
24
  import {
22
25
  assistantBreadcrumbs,
@@ -24,22 +27,13 @@ import {
24
27
  assistantSources,
25
28
  assistantSuggestions,
26
29
  assistantTool,
27
- chunkReply,
30
+ createScriptedAdapter,
28
31
  type AssistantTool,
29
32
  } from './data';
30
33
 
31
- interface Turn {
32
- id: number;
33
- role: ChatRole;
34
- text: string;
35
- time: Date;
36
- streaming?: boolean;
37
- tool?: { status: ToolCallStatus; durationMs?: number };
38
- sources?: boolean;
39
- feedback?: ChatFeedback;
40
- }
41
-
42
34
  export interface AssistantChatProps {
35
+ /** Experimental runtime adapter. Its URL must be the product backend; provider keys stay server-side. */
36
+ adapter?: ChatAdapter;
43
37
  title: string;
44
38
  suggestions: Suggestion[];
45
39
  /** Sources cited under the reply and listed in the details panel. */
@@ -61,9 +55,10 @@ export interface AssistantChatProps {
61
55
  shell: Omit<ConsoleShellProps, 'children'>;
62
56
  }
63
57
 
64
- /** Assistant chat: ConsoleShell + Page + ChatLayout with a mock-streamed reply (timers cleared on Stop and unmount). */
58
+ /** Assistant chat: streams a backend adapter, or an abortable scripted demo when no adapter is supplied. */
65
59
  export default function AssistantChatPage(props: Partial<AssistantChatProps>) {
66
60
  const {
61
+ adapter,
67
62
  title = 'Assistant',
68
63
  suggestions = assistantSuggestions,
69
64
  sources = assistantSources,
@@ -77,95 +72,32 @@ export default function AssistantChatPage(props: Partial<AssistantChatProps>) {
77
72
  currentHref = '/assistant',
78
73
  shell,
79
74
  } = props;
80
- const [turns, setTurns] = useState<Turn[]>([]);
81
- const [streaming, setStreaming] = useState(false);
82
- const nextId = useRef(1);
83
- const [timers] = useState(() => new Set<ReturnType<typeof setTimeout>>());
84
-
85
- const clearTimers = () => {
86
- timers.forEach((t) => clearTimeout(t));
87
- timers.clear();
88
- };
89
- useEffect(
90
- () => () => {
91
- timers.forEach((t) => clearTimeout(t));
92
- timers.clear();
93
- },
94
- [timers],
95
- );
96
- const later = (fn: () => void, ms: number) => {
97
- const t = setTimeout(() => {
98
- timers.delete(t);
99
- fn();
100
- }, ms);
101
- timers.add(t);
102
- };
103
-
104
- const patch = (id: number, fn: (t: Turn) => Turn) => setTurns((ts) => ts.map((t) => (t.id === id ? fn(t) : t)));
105
-
106
- const respond = () => {
107
- clearTimers();
108
- const toolId = nextId.current++;
109
- const replyId = nextId.current++;
110
- const now = new Date();
111
- setStreaming(true);
112
- setTurns((ts) => [
113
- ...ts,
114
- { id: toolId, role: 'tool', text: '', time: now, tool: { status: 'running' } },
115
- { id: replyId, role: 'assistant', text: '', time: now, streaming: true },
116
- ]);
117
- const pieces = chunkReply(reply);
118
- const startAt = tool.durationMs;
119
- later(() => patch(toolId, (t) => ({ ...t, tool: { status: 'succeeded', durationMs: tool.durationMs } })), startAt);
120
- pieces.forEach((piece, i) =>
121
- later(() => patch(replyId, (t) => ({ ...t, text: t.text + piece })), startAt + (i + 1) * tickMs),
122
- );
123
- later(
124
- () => {
125
- patch(replyId, (t) => ({ ...t, streaming: false, sources: true }));
126
- setStreaming(false);
127
- },
128
- startAt + (pieces.length + 1) * tickMs,
129
- );
130
- };
131
-
132
- const send = (text: string) => {
133
- setTurns((ts) => [...ts, { id: nextId.current++, role: 'user', text, time: new Date() }]);
75
+ const scripted = useMemo(() => createScriptedAdapter(reply, tool, tickMs, sources), [reply, tool, tickMs, sources]);
76
+ const {
77
+ messages: turns,
78
+ isStreaming: streaming,
79
+ sendMessage,
80
+ stop,
81
+ regenerate,
82
+ setMessages,
83
+ } = useChat({ adapter: adapter ?? scripted, flushIntervalMs: 0 });
84
+ const [feedback, setFeedback] = useState<Record<string, ChatFeedback>>({});
85
+ const send = (text: string, attachments: ChatAttachment[] = []) => {
86
+ if (streaming) return;
87
+ sendMessage(text, attachments);
134
88
  onSend?.(text);
135
- respond();
136
- };
137
-
138
- const stop = () => {
139
- clearTimers();
140
- setTurns((ts) =>
141
- ts.map((t) =>
142
- t.streaming
143
- ? { ...t, streaming: false }
144
- : t.tool?.status === 'running'
145
- ? { ...t, tool: { status: 'failed', durationMs: 0 } }
146
- : t,
147
- ),
148
- );
149
- setStreaming(false);
150
- };
151
-
152
- const retry = (id: number) => {
153
- setTurns((ts) => {
154
- const at = ts.findIndex((t) => t.id === id);
155
- // Drop the reply and the tool call that preceded it.
156
- const cut = at > 0 && ts[at - 1]?.role === 'tool' ? at - 1 : at;
157
- return ts.slice(0, cut);
158
- });
159
- respond();
160
89
  };
161
-
162
90
  const newConversation = () => {
163
- clearTimers();
164
- setTurns([]);
165
- setStreaming(false);
91
+ stop();
92
+ setMessages([]);
93
+ setFeedback({});
166
94
  };
167
-
168
- const lastReply = [...turns].reverse().find((t) => t.role === 'assistant' && !t.streaming)?.text;
95
+ const lastReply = [...turns]
96
+ .reverse()
97
+ .find((t) => t.role === 'assistant' && t.status === 'done')
98
+ ?.parts.filter((p) => p.type === 'text')
99
+ .map((p) => p.text)
100
+ .join('');
169
101
 
170
102
  return (
171
103
  <ConsoleShell breadcrumbs={breadcrumbs} currentHref={currentHref} {...shell}>
@@ -219,48 +151,77 @@ export default function AssistantChatPage(props: Partial<AssistantChatProps>) {
219
151
  <h3 className="text-center text-[20px] font-semibold tracking-tight text-foreground">
220
152
  How can I help?
221
153
  </h3>
222
- <SuggestionChips suggestions={suggestions} onSelect={send} />
154
+ <SuggestionChips suggestions={suggestions} onSelect={(text) => send(text)} />
223
155
  </div>
224
156
  )}
225
157
  {turns.map((t) => {
226
- if (t.role === 'tool' && t.tool) {
227
- return (
228
- <ChatMessage key={t.id} role="tool" author="Tool" timestamp={t.time}>
229
- <ToolCallCard
230
- name={tool.name}
231
- status={t.tool.status}
232
- durationMs={t.tool.durationMs}
233
- args={tool.args}
234
- result={t.tool.status === 'succeeded' ? tool.result : undefined}
235
- error={t.tool.status === 'failed' ? 'Stopped by the user.' : undefined}
236
- />
237
- </ChatMessage>
238
- );
239
- }
240
- if (t.role === 'assistant') {
241
- return (
158
+ const text = t.parts
159
+ .filter((p) => p.type === 'text')
160
+ .map((p) => p.text)
161
+ .join('');
162
+ const files = t.parts.filter((p) => p.type === 'file').map((p) => p.file);
163
+ const citations = t.parts.filter((p) => p.type === 'source').map((p) => p.source);
164
+ const busy = t.status === 'pending' || t.status === 'streaming';
165
+ return (
166
+ <Fragment key={t.id}>
167
+ {t.parts
168
+ .filter((p) => p.type === 'tool')
169
+ .map((part) => (
170
+ <ChatMessage key={part.toolCallId} role="tool" timestamp={t.createdAt}>
171
+ <ToolCallCard
172
+ name={part.toolName}
173
+ status={part.status}
174
+ durationMs={
175
+ !adapter
176
+ ? part.status === 'succeeded'
177
+ ? tool.durationMs
178
+ : part.status === 'failed'
179
+ ? 0
180
+ : undefined
181
+ : undefined
182
+ }
183
+ args={part.input}
184
+ result={part.output}
185
+ error={
186
+ part.errorText ??
187
+ (!adapter && part.status === 'failed' ? 'Stopped by the user.' : undefined)
188
+ }
189
+ />
190
+ </ChatMessage>
191
+ ))}
242
192
  <ChatMessage
243
- key={t.id}
244
- role="assistant"
245
- timestamp={t.time}
246
- streaming={t.streaming}
247
- copyText={t.text}
248
- onRetry={streaming ? undefined : () => retry(t.id)}
249
- feedback={t.feedback ?? null}
250
- onFeedback={(f) => {
251
- patch(t.id, (x) => ({ ...x, feedback: f }));
252
- onFeedback?.(f);
253
- }}
193
+ role={t.role}
194
+ timestamp={t.createdAt}
195
+ streaming={busy}
196
+ copyText={t.role === 'assistant' ? text : undefined}
197
+ onRetry={t.role === 'assistant' && !streaming ? () => regenerate(t.id) : undefined}
198
+ feedback={feedback[t.id] ?? null}
199
+ onFeedback={
200
+ t.role === 'assistant'
201
+ ? (f) => {
202
+ setFeedback((previous) => ({ ...previous, [t.id]: f }));
203
+ onFeedback?.(f);
204
+ }
205
+ : undefined
206
+ }
254
207
  >
255
- {t.text && <Markdown streaming={t.streaming}>{t.text}</Markdown>}
256
- {t.sources && <CitationList sources={sources} className="mt-3" />}
208
+ {t.parts
209
+ .filter((p) => p.type === 'reasoning')
210
+ .map((part) => (
211
+ <ReasoningBlock key={part.id} streaming={busy && part.state === 'streaming'}>
212
+ {part.text}
213
+ </ReasoningBlock>
214
+ ))}
215
+ {text && (t.role === 'assistant' ? <Markdown streaming={busy}>{text}</Markdown> : text)}
216
+ {files.length > 0 && <AttachmentList attachments={files} />}
217
+ {citations.length > 0 && <CitationList sources={citations} className="mt-3" />}
218
+ {t.error && (
219
+ <p role="alert" className="text-destructive-text">
220
+ {t.error}
221
+ </p>
222
+ )}
257
223
  </ChatMessage>
258
- );
259
- }
260
- return (
261
- <ChatMessage key={t.id} role={t.role} timestamp={t.time}>
262
- {t.text}
263
- </ChatMessage>
224
+ </Fragment>
264
225
  );
265
226
  })}
266
227
  <ChatAnnouncer streaming={streaming} lastReply={lastReply} />
@@ -1,4 +1,4 @@
1
- import type { CitationSource, Suggestion } from '@gntik-ai/chat';
1
+ import type { ChatAdapter, ChatChunk, CitationSource, Suggestion } from '@gntik-ai/chat';
2
2
  import type { BreadcrumbItem } from '@gntik-ai/ui';
3
3
 
4
4
  /** Mock tool call the assistant runs before answering. */
@@ -69,3 +69,71 @@ export function chunkReply(text: string, size = 6): string[] {
69
69
  for (let i = 0; i < text.length; i += size) out.push(text.slice(i, i + size));
70
70
  return out;
71
71
  }
72
+
73
+ /** Demo-only backend substitute. All chunk timers are scheduled eagerly and cleared on abort. */
74
+ export function createScriptedAdapter(
75
+ reply: string,
76
+ tool: AssistantTool,
77
+ tickMs: number,
78
+ sources: CitationSource[],
79
+ ): ChatAdapter {
80
+ return {
81
+ async sendMessage({ signal }) {
82
+ const timers = new Set<ReturnType<typeof setTimeout>>();
83
+ let close: (() => void) | undefined;
84
+ const clear = () => {
85
+ timers.forEach(clearTimeout);
86
+ timers.clear();
87
+ signal.removeEventListener('abort', abort);
88
+ };
89
+ const abort = () => {
90
+ clear();
91
+ close?.();
92
+ close = undefined;
93
+ };
94
+ return new ReadableStream<ChatChunk>({
95
+ start(controller) {
96
+ close = () => controller.close();
97
+ if (signal.aborted) {
98
+ abort();
99
+ return;
100
+ }
101
+ signal.addEventListener('abort', abort, { once: true });
102
+ const later = (chunk: ChatChunk, ms: number) => {
103
+ const timer = setTimeout(() => {
104
+ timers.delete(timer);
105
+ controller.enqueue(chunk);
106
+ if (chunk.type === 'finish') {
107
+ clear();
108
+ close?.();
109
+ close = undefined;
110
+ }
111
+ }, ms);
112
+ timers.add(timer);
113
+ };
114
+ controller.enqueue({ type: 'start' });
115
+ controller.enqueue({
116
+ type: 'tool-input-available',
117
+ toolCallId: 'scripted-tool',
118
+ toolName: tool.name,
119
+ input: tool.args,
120
+ });
121
+ later({ type: 'tool-output-available', toolCallId: 'scripted-tool', output: tool.result }, tool.durationMs);
122
+ const pieces = chunkReply(reply);
123
+ pieces.forEach((delta, i) =>
124
+ later({ type: 'text-delta', id: 'reply', delta }, tool.durationMs + (i + 1) * tickMs),
125
+ );
126
+ const end = tool.durationMs + (pieces.length + 1) * tickMs;
127
+ sources.forEach((source, i) =>
128
+ later({ type: 'source-url', sourceId: String(i), title: source.title, url: source.url ?? '' }, end),
129
+ );
130
+ later({ type: 'finish' }, end);
131
+ },
132
+ cancel() {
133
+ clear();
134
+ close = undefined;
135
+ },
136
+ });
137
+ },
138
+ };
139
+ }
@@ -0,0 +1,9 @@
1
+ import { createEchoAdapter } from '@gntik-ai/chat';
2
+ import AssistantChatPage from '../Page';
3
+
4
+ const adapter = createEchoAdapter();
5
+
6
+ /** The template's optional adapter streams the prompt back instead of running the scripted tool. */
7
+ export default function AdapterChat() {
8
+ return <AssistantChatPage adapter={adapter} withPanel={false} />;
9
+ }
@@ -6,7 +6,7 @@ export const meta: TemplateMeta = {
6
6
  priority: 'P3',
7
7
  status: 'experimental',
8
8
  description:
9
- 'Workspace assistant in the console: @gntik-ai/chat ChatLayout with suggestions, ChatMessage turns, a ToolCallCard, a mock-streamed markdown reply with Citations, Stop / Retry / feedback and a ChatComposer; a details panel lists the context sources. Streaming timers are cleared on Stop and unmount.',
9
+ 'Workspace assistant in the console: @gntik-ai/chat ChatLayout with suggestions, ChatMessage turns, a ToolCallCard, adapter-streamed markdown replies with Citations, Stop / Retry / feedback and a ChatComposer; a details panel lists the context sources. Pass an optional adapter for a backend, or use the scripted demo; Stop and unmount abort both.',
10
10
  layout: 'SidebarLayout · Page · ChatLayout',
11
11
  blocks: ['app-sidebar', 'app-topbar', 'page-header'],
12
12
  };
@@ -69,7 +69,7 @@ export function Lane({
69
69
  onDragStart={onDragStart(card.id)}
70
70
  onDragEnd={onDragEnd}
71
71
  className={cn(
72
- 'group flex w-full cursor-grab flex-col gap-2 rounded-lg border border-border bg-card p-3 text-start shadow-sm transition-colors motion-reduce:transition-none hover:border-primary/40 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring',
72
+ 'group flex w-full cursor-grab flex-col gap-2 rounded-lg border border-border bg-card p-3 text-start shadow-sm transition-colors motion-reduce:transition-none hover:border-primary/40 focus-ring',
73
73
  'aria-pressed:border-primary aria-pressed:bg-accent',
74
74
  draggingId === card.id && 'opacity-50',
75
75
  )}
@@ -81,3 +81,15 @@ describe('CodeEditorPage', () => {
81
81
  expect(filesToTree(['b.md', 'src/a.ts', 'src/lib/c.ts']).map((n) => n.id)).toEqual(['src/', 'b.md']);
82
82
  });
83
83
  });
84
+
85
+ it.each([true, false])('copies a file path through the fallback only when it succeeds (%s)', async (success) => {
86
+ const user = userEvent.setup();
87
+ Object.defineProperty(navigator, 'clipboard', { configurable: true, value: undefined });
88
+ const exec = vi.fn(() => success);
89
+ Object.defineProperty(document, 'execCommand', { configurable: true, value: exec });
90
+ render(<CodeEditorPage loader={mockMonaco().loader} />);
91
+ fireEvent.contextMenu(within(screen.getByRole('treeitem', { name: /query\.ts/ })).getByText('query.ts'));
92
+ await user.click(await screen.findByRole('menuitem', { name: 'Copy path' }));
93
+ expect(exec).toHaveBeenCalledWith('copy');
94
+ expect(await screen.findByText(success ? 'Copied src/query.ts' : 'Copy failed')).toBeInTheDocument();
95
+ });
@@ -6,6 +6,7 @@ import {
6
6
  Breadcrumbs,
7
7
  Button,
8
8
  CanvasLayout,
9
+ copyToClipboard,
9
10
  ContextMenu,
10
11
  ContextMenuContent,
11
12
  ContextMenuTrigger,
@@ -96,7 +97,7 @@ export default function CodeEditorPage(props: Partial<CodeEditorPageProps>) {
96
97
  };
97
98
  const copyPath = async (path: string) => {
98
99
  try {
99
- await navigator.clipboard.writeText(path);
100
+ await copyToClipboard(path);
100
101
  setNote(`Copied ${path}`);
101
102
  } catch {
102
103
  setNote('Copy failed');