@axium/ai 0.0.0-stage → 0.1.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 (105) hide show
  1. package/LICENSE.md +157 -0
  2. package/README.md +2 -2
  3. package/db.json +114 -0
  4. package/dist/client/cli.d.ts +1 -0
  5. package/dist/client/cli.js +224 -0
  6. package/dist/client/config.d.ts +196 -0
  7. package/dist/client/config.js +55 -0
  8. package/dist/client/hooks.d.ts +3 -0
  9. package/dist/client/hooks.js +32 -0
  10. package/dist/client/local.d.ts +17 -0
  11. package/dist/client/local.js +112 -0
  12. package/dist/common.d.ts +1318 -0
  13. package/dist/common.js +569 -0
  14. package/dist/hooks.d.ts +13 -0
  15. package/dist/hooks.js +34 -0
  16. package/dist/hub.d.ts +4 -0
  17. package/dist/hub.js +75 -0
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +1 -0
  20. package/dist/integrations/notes.d.ts +1 -0
  21. package/dist/integrations/notes.js +104 -0
  22. package/dist/integrations/tasks.d.ts +1 -0
  23. package/dist/integrations/tasks.js +157 -0
  24. package/dist/loop.d.ts +75 -0
  25. package/dist/loop.js +239 -0
  26. package/dist/memory.d.ts +107 -0
  27. package/dist/memory.js +193 -0
  28. package/dist/node/chat.d.ts +50 -0
  29. package/dist/node/chat.js +60 -0
  30. package/dist/node/llama.d.ts +115 -0
  31. package/dist/node/llama.js +385 -0
  32. package/dist/node/markdown.d.ts +6 -0
  33. package/dist/node/markdown.js +285 -0
  34. package/dist/node/models.d.ts +34 -0
  35. package/dist/node/models.js +287 -0
  36. package/dist/node/web.d.ts +1 -0
  37. package/dist/node/web.js +203 -0
  38. package/dist/server/api/conversations.d.ts +1 -0
  39. package/dist/server/api/conversations.js +216 -0
  40. package/dist/server/api/gateway.d.ts +1 -0
  41. package/dist/server/api/gateway.js +113 -0
  42. package/dist/server/api/memories.d.ts +1 -0
  43. package/dist/server/api/memories.js +129 -0
  44. package/dist/server/api/models.d.ts +1 -0
  45. package/dist/server/api/models.js +161 -0
  46. package/dist/server/api/temporary.d.ts +1 -0
  47. package/dist/server/api/temporary.js +50 -0
  48. package/dist/server/api/timers.d.ts +1 -0
  49. package/dist/server/api/timers.js +27 -0
  50. package/dist/server/api/voice.d.ts +1 -0
  51. package/dist/server/api/voice.js +188 -0
  52. package/dist/server/generation.d.ts +38 -0
  53. package/dist/server/generation.js +299 -0
  54. package/dist/server/memory.d.ts +7 -0
  55. package/dist/server/memory.js +218 -0
  56. package/dist/server/models.d.ts +13 -0
  57. package/dist/server/models.js +59 -0
  58. package/dist/server/preferences.d.ts +3 -0
  59. package/dist/server/preferences.js +12 -0
  60. package/dist/server/timers.d.ts +7 -0
  61. package/dist/server/timers.js +66 -0
  62. package/dist/speech.d.ts +17 -0
  63. package/dist/speech.js +69 -0
  64. package/dist/timers.d.ts +1 -0
  65. package/dist/timers.js +67 -0
  66. package/dist/tools.d.ts +70 -0
  67. package/dist/tools.js +84 -0
  68. package/lib/ChatMessage.svelte +331 -0
  69. package/lib/Composer.svelte +234 -0
  70. package/lib/Conversation.svelte +433 -0
  71. package/lib/ConversationMenu.svelte +18 -0
  72. package/lib/ModelActions.svelte +71 -0
  73. package/lib/ModelOptions.svelte +101 -0
  74. package/lib/ModelStatus.svelte +49 -0
  75. package/lib/ToolCall.svelte +171 -0
  76. package/lib/VoiceMode.svelte +113 -0
  77. package/lib/actions.ts +21 -0
  78. package/lib/index.ts +7 -0
  79. package/lib/live.svelte.ts +113 -0
  80. package/lib/markdown.ts +40 -0
  81. package/lib/preferences.ts +13 -0
  82. package/lib/transition.ts +24 -0
  83. package/lib/tsconfig.json +14 -0
  84. package/lib/voice.svelte.ts +476 -0
  85. package/locales/en.json +316 -0
  86. package/package.json +139 -5
  87. package/routes/ai/+layout.svelte +177 -0
  88. package/routes/ai/+layout.ts +26 -0
  89. package/routes/ai/+page.svelte +109 -0
  90. package/routes/ai/TimerAlerts.svelte +51 -0
  91. package/routes/ai/Timers.svelte +121 -0
  92. package/routes/ai/[id]/+page.svelte +18 -0
  93. package/routes/ai/[id]/+page.ts +14 -0
  94. package/routes/ai/memory/+page.svelte +313 -0
  95. package/routes/ai/memory/+page.ts +10 -0
  96. package/routes/ai/memory/MemoryForm.svelte +111 -0
  97. package/routes/ai/models/+page.svelte +199 -0
  98. package/routes/ai/models/+page.ts +5 -0
  99. package/routes/ai/models/AddModel.svelte +240 -0
  100. package/routes/ai/models/MemoryMeter.svelte +120 -0
  101. package/routes/ai/models/Roles.svelte +159 -0
  102. package/routes/ai/models/[id]/+page.svelte +331 -0
  103. package/routes/ai/models/[id]/+page.ts +6 -0
  104. package/routes/ai/timers.svelte.ts +94 -0
  105. package/routes/tsconfig.json +14 -0
package/dist/tools.js ADDED
@@ -0,0 +1,84 @@
1
+ import features from '@axium/core/features';
2
+ import * as io from 'ioium';
3
+ import * as z from 'zod';
4
+ const registry = new Map();
5
+ /** @throws if a tool with the same name exists */
6
+ export function add(tool) {
7
+ if (registry.has(tool.name))
8
+ throw new ReferenceError(`Tool "${tool.name}" already exists`);
9
+ registry.set(tool.name, tool);
10
+ }
11
+ export function allowed(preferences, { anonymous, temporary } = {}) {
12
+ return Array.from(registry.values()).filter(tool => {
13
+ if (tool.available && !tool.available())
14
+ return false;
15
+ switch (tool.environment) {
16
+ case null:
17
+ return true;
18
+ case 'web':
19
+ return preferences.web && features('ai-web-tools');
20
+ case 'account':
21
+ if (anonymous || !features('ai-account-access'))
22
+ return false;
23
+ return preferences.account_access == 'write' || (preferences.account_access == 'read' && tool.access == 'read');
24
+ case 'memory':
25
+ return preferences.memory && features('ai-memory') && !anonymous && (tool.access == 'read' || !temporary);
26
+ }
27
+ });
28
+ }
29
+ /**
30
+ * Whether a call must wait for the user's approval.
31
+ * @param allowed Tools the user allowed for the rest of the conversation
32
+ */
33
+ export function needsApproval(tool, preferences, allowed) {
34
+ if (tool?.access != 'write' || !preferences.confirm_writes || allowed.has(tool.name))
35
+ return false;
36
+ return (preferences.approvals[tool.name] ?? tool.approval ?? 'ask') == 'ask';
37
+ }
38
+ /** Tools in the OpenAI chat completions format */
39
+ export function definitions(offered) {
40
+ return offered.map(tool => ({
41
+ type: 'function',
42
+ function: { name: tool.name, description: tool.description, parameters: z.toJSONSchema(tool.input) },
43
+ }));
44
+ }
45
+ /** Characters of a result given to the model */
46
+ const maxResultLength = 32_000;
47
+ function failure(error) {
48
+ return { status: 'error', content: 'Error: ' + error, error };
49
+ }
50
+ /** Validates a call's arguments and runs it. Never throws: failures are described for the model. */
51
+ export async function run(tool, call, context) {
52
+ if (!tool)
53
+ return failure(`The tool "${call.name}" is not available`);
54
+ let input;
55
+ try {
56
+ input = JSON.parse(call.arguments || '{}');
57
+ }
58
+ catch {
59
+ return failure('The arguments are not valid JSON');
60
+ }
61
+ const parsed = tool.input.safeParse(input);
62
+ if (!parsed.success)
63
+ return failure('Invalid arguments:\n' + z.prettifyError(parsed.error));
64
+ try {
65
+ const result = await tool.run(parsed.data, context);
66
+ const text = typeof result == 'string' ? result : JSON.stringify(result);
67
+ if (text.length <= maxResultLength)
68
+ return { status: 'done', content: text, error: null };
69
+ if (typeof result != 'string')
70
+ return failure(`The result is too large (${text.length} characters); ask for less`);
71
+ return {
72
+ status: 'done',
73
+ content: text.slice(0, maxResultLength) + `\n[Truncated: showing ${maxResultLength} of ${text.length} characters]`,
74
+ error: null,
75
+ };
76
+ }
77
+ catch (error) {
78
+ io.debug('AI: tool', tool.name, 'failed:', io.errorText(error));
79
+ return failure(io.errorText(error));
80
+ }
81
+ }
82
+ export function get(name) {
83
+ return registry.get(name);
84
+ }
@@ -0,0 +1,331 @@
1
+ <script lang="ts" module>
2
+ import { SvelteSet } from 'svelte/reactivity';
3
+
4
+ /** IDs of messages whose reasoning the user expanded */
5
+ const expanded = new SvelteSet<string>();
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import type * as ai from '@axium/ai/common';
10
+ import { text } from '@axium/client';
11
+ import { ClipboardCopy, Icon } from '@axium/client/components';
12
+ import { toast } from '@axium/client/toast';
13
+ import { markdown } from './markdown.js';
14
+ import * as voice from './voice.svelte.js';
15
+ import ToolCall from './ToolCall.svelte';
16
+
17
+ const {
18
+ message,
19
+ ctrlEnter = false,
20
+ results,
21
+ decisions,
22
+ onretry,
23
+ onedit,
24
+ ondecide,
25
+ }: {
26
+ message: ai.Message;
27
+ /** Whether saving an edit needs Ctrl+Enter, leaving Enter for new lines */
28
+ ctrlEnter?: boolean;
29
+ /** Tool messages, by the ID of the call they answer */
30
+ results?: Map<string, ai.Message>;
31
+ /** Choices for calls awaiting approval, before they are sent */
32
+ decisions?: ai.Decisions;
33
+ onretry?(): void;
34
+ /** Replaces the message's content */
35
+ onedit?(content: string): Promise<unknown>;
36
+ ondecide?(call: ai.ToolCall, decision: ai.Decision): void;
37
+ } = $props();
38
+
39
+ let draft = $state<string>();
40
+ let saving = $state(false);
41
+
42
+ async function save() {
43
+ if (!onedit || !draft?.trim() || draft.trim() == message.content || saving) return;
44
+ saving = true;
45
+ try {
46
+ await onedit(draft);
47
+ draft = undefined;
48
+ } finally {
49
+ saving = false;
50
+ }
51
+ }
52
+
53
+ const retryable = $derived(!!onretry && message.role == 'assistant' && message.status != 'pending');
54
+
55
+ const pending = $derived(message.status == 'pending');
56
+
57
+ const latestLine = $derived(
58
+ message.reasoning
59
+ ?.split('\n')
60
+ .map(line => line.replace(/[*_#`]/g, '').trim())
61
+ .findLast(Boolean)
62
+ );
63
+ </script>
64
+
65
+ <div class={['message', message.role, draft !== undefined && 'editing']}>
66
+ {#if draft !== undefined}
67
+ <form
68
+ class="edit"
69
+ onsubmit={e => {
70
+ e.preventDefault();
71
+ void save();
72
+ }}
73
+ >
74
+ <textarea
75
+ bind:value={draft}
76
+ onkeydown={e => {
77
+ if (e.key == 'Escape') draft = undefined;
78
+ if (e.key != 'Enter' || e.shiftKey || e.isComposing) return;
79
+ if (ctrlEnter && !e.ctrlKey && !e.metaKey) return;
80
+ e.preventDefault();
81
+ void save();
82
+ }}
83
+ {@attach element => element.focus()}></textarea>
84
+ <div class="edit-actions">
85
+ <button type="button" onclick={() => (draft = undefined)}>{text('generic.cancel')}</button>
86
+ <button type="submit" class="send" disabled={saving || !draft.trim() || draft.trim() == message.content}>
87
+ {text('ai.send')}
88
+ </button>
89
+ </div>
90
+ </form>
91
+ {/if}
92
+
93
+ {#if message.reasoning}
94
+ <details
95
+ class="reasoning"
96
+ open={expanded.has(message.id)}
97
+ ontoggle={e => (e.currentTarget.open ? expanded.add(message.id) : expanded.delete(message.id))}
98
+ >
99
+ <summary class="subtle">
100
+ <span class="label">{pending && !message.content ? text('ai.thinking') : text('ai.reasoning')}</span>
101
+ <span class="latest">{latestLine}</span>
102
+ </summary>
103
+ <div class="text">{message.reasoning}</div>
104
+ </details>
105
+ {/if}
106
+
107
+ {#if message.content && message.role == 'assistant'}
108
+ <div class="markdown" {@attach markdown(message.content)}></div>
109
+ {:else if message.content && draft === undefined}
110
+ <div class="bubble text">{message.content}</div>
111
+ {:else if pending && !message.reasoning}
112
+ <div class="subtle">{text('ai.thinking')}</div>
113
+ {/if}
114
+
115
+ {#each message.toolCalls ?? [] as call (call.id)}
116
+ <ToolCall {call} result={results?.get(call.id)} decision={decisions?.[call.id]} ondecide={decision => ondecide?.(call, decision)} />
117
+ {/each}
118
+
119
+ {#if message.status == 'error'}
120
+ <div class="error">{text('ai.error', { error: message.error ?? '' })}</div>
121
+ {/if}
122
+
123
+ {#if !pending && draft === undefined && (message.content || retryable || message.status != 'done')}
124
+ <div class="actions subtle">
125
+ {#if message.content}
126
+ <ClipboardCopy value={message.content} --size="14px" />
127
+ {/if}
128
+ {#if message.content && message.role == 'assistant' && voice.available.speech}
129
+ {const speaking = $derived(voice.speaking() == message.id)}
130
+ <button
131
+ class="reset"
132
+ title={text(speaking ? 'ai.voice.stop_speaking' : 'ai.voice.speak')}
133
+ aria-label={text(speaking ? 'ai.voice.stop_speaking' : 'ai.voice.speak')}
134
+ onclick={() => {
135
+ if (speaking) voice.stopSpeaking();
136
+ else voice.speak(message.id, message.content).catch(error => toast('error', error));
137
+ }}
138
+ >
139
+ <Icon i={speaking ? 'stop' : 'volume-high'} --size="14px" />
140
+ </button>
141
+ {/if}
142
+ {#if onedit}
143
+ <button class="reset" title={text('ai.edit')} aria-label={text('ai.edit')} onclick={() => (draft = message.content)}>
144
+ <Icon i="pen" --size="14px" />
145
+ </button>
146
+ {/if}
147
+ {#if retryable && message.status == 'done'}
148
+ <button class="reset retry" title={text('ai.retry')} aria-label={text('ai.retry')} onclick={onretry}>
149
+ <Icon i="arrow-rotate-right" --size="14px" />
150
+ </button>
151
+ {:else if retryable}
152
+ <button class="retry icon-text" onclick={onretry}>
153
+ <Icon i="arrow-rotate-right" --size="14px" />
154
+ <span>{text('ai.retry')}</span>
155
+ </button>
156
+ {/if}
157
+ {#if message.status == 'cancelled'}
158
+ <span>{text('ai.stopped')}</span>
159
+ {:else if message.usage?.generationSpeed}
160
+ <span>{text('ai.speed', { speed: message.usage.generationSpeed.toFixed(1) })}</span>
161
+ {/if}
162
+ </div>
163
+ {/if}
164
+ </div>
165
+
166
+ <style>
167
+ .message {
168
+ display: flex;
169
+ flex-direction: column;
170
+ gap: 0.5em;
171
+
172
+ &.user {
173
+ align-self: flex-end;
174
+ align-items: flex-end;
175
+ max-width: 80%;
176
+ }
177
+
178
+ &.user.editing {
179
+ align-self: stretch;
180
+ max-width: none;
181
+ }
182
+ }
183
+
184
+ .bubble {
185
+ padding: 0.75em 1em;
186
+ border-radius: 1em;
187
+ background-color: var(--bg-alt);
188
+ }
189
+
190
+ .edit {
191
+ display: flex;
192
+ flex-direction: column;
193
+ gap: 0.5em;
194
+ width: 100%;
195
+ padding: 0.75em 1em;
196
+ border-radius: 1em;
197
+ background-color: var(--bg-alt);
198
+
199
+ textarea {
200
+ border: none;
201
+ background: none;
202
+ padding: 0;
203
+ field-sizing: content;
204
+ resize: none;
205
+ min-height: 1lh;
206
+ max-height: 20lh;
207
+ }
208
+ }
209
+
210
+ .edit-actions {
211
+ display: flex;
212
+ justify-content: flex-end;
213
+ gap: 0.5em;
214
+
215
+ .send {
216
+ background-color: var(--bg-accent);
217
+ }
218
+ }
219
+
220
+ .actions {
221
+ display: flex;
222
+ align-items: center;
223
+ gap: 1em;
224
+ font-size: 0.8em;
225
+ min-height: 1.5em;
226
+ }
227
+
228
+ @media (hover: hover) {
229
+ .message.user .actions {
230
+ visibility: hidden;
231
+ }
232
+
233
+ .message.user:hover .actions {
234
+ visibility: visible;
235
+ }
236
+
237
+ .markdown :global(.code-block:not(:hover) .code-copy) {
238
+ visibility: hidden;
239
+ }
240
+ }
241
+
242
+ .text {
243
+ white-space: pre-wrap;
244
+ overflow-wrap: anywhere;
245
+ }
246
+
247
+ .markdown {
248
+ overflow-wrap: anywhere;
249
+
250
+ :global(> :first-child) {
251
+ margin-top: 0;
252
+ }
253
+
254
+ :global(> :last-child) {
255
+ margin-bottom: 0;
256
+ }
257
+
258
+ :global(.code-block) {
259
+ position: relative;
260
+ margin: 1em 0;
261
+ }
262
+
263
+ :global(.code-copy) {
264
+ position: absolute;
265
+ top: 0.6em;
266
+ right: 0.75em;
267
+ font-size: 0.9em;
268
+ }
269
+
270
+ :global(pre) {
271
+ margin: 0;
272
+ padding: 0.75em 2.5em 0.75em 1em;
273
+ border-radius: 0.5em;
274
+ background-color: var(--bg-alt);
275
+ overflow-x: auto;
276
+ overflow-wrap: normal;
277
+ }
278
+
279
+ :global(pre code) {
280
+ padding: 0;
281
+ background: none;
282
+ }
283
+
284
+ :global(table) {
285
+ border-collapse: collapse;
286
+ }
287
+
288
+ :global(th),
289
+ :global(td) {
290
+ padding: 0.25em 0.75em;
291
+ border: 1px solid var(--bg-strong);
292
+ }
293
+
294
+ :global(blockquote) {
295
+ margin-left: 0;
296
+ padding-left: 1em;
297
+ border-left: 2px solid var(--bg-strong);
298
+ }
299
+ }
300
+
301
+ .reasoning .text {
302
+ padding-left: 1em;
303
+ border-left: 2px solid var(--bg-strong);
304
+ font-size: 0.9em;
305
+ opacity: 0.8;
306
+ }
307
+
308
+ summary {
309
+ cursor: pointer;
310
+ overflow: hidden;
311
+ text-overflow: ellipsis;
312
+ white-space: nowrap;
313
+
314
+ .latest {
315
+ margin-left: 0.5em;
316
+ opacity: 0.7;
317
+ }
318
+ }
319
+
320
+ details[open] .latest {
321
+ display: none;
322
+ }
323
+
324
+ .reasoning .text {
325
+ margin-top: 0.5em;
326
+ }
327
+
328
+ .error {
329
+ color: var(--fg-error);
330
+ }
331
+ </style>
@@ -0,0 +1,234 @@
1
+ <script lang="ts">
2
+ import type * as ai from '@axium/ai/common';
3
+ import { text } from '@axium/client';
4
+ import { Icon } from '@axium/client/components';
5
+ import { toast } from '@axium/client/toast';
6
+ import ModelOptions from './ModelOptions.svelte';
7
+ import VoiceMode from './VoiceMode.svelte';
8
+ import * as voice from './voice.svelte.js';
9
+
10
+ let {
11
+ generating = false,
12
+ models,
13
+ model = $bindable(),
14
+ reasoning = $bindable(),
15
+ onsend,
16
+ onstop,
17
+ onoptions,
18
+ ctrlEnter = false,
19
+ }: {
20
+ generating?: boolean;
21
+ /** Whether sending needs Ctrl+Enter, leaving Enter for new lines */
22
+ ctrlEnter?: boolean;
23
+ models: ai.Model[];
24
+ model: string;
25
+ reasoning: string;
26
+ /** @param voice Whether the content was spoken in conversation mode */
27
+ onsend(content: string, voice?: boolean): Promise<unknown>;
28
+ onstop?(): void;
29
+ /** Called after the model or reasoning changes */
30
+ onoptions?(): void;
31
+ } = $props();
32
+
33
+ let content = $state(''),
34
+ sending = $state(false),
35
+ recording = $state<voice.Recording>(),
36
+ transcribing = $state(false);
37
+
38
+ async function startDictation() {
39
+ voice.prepare();
40
+ try {
41
+ recording = await voice.record();
42
+ } catch (error) {
43
+ toast('error', text('ai.voice.microphone_error', { error: error instanceof Error ? error.message : String(error) }));
44
+ }
45
+ }
46
+
47
+ async function finishDictation() {
48
+ if (!recording) return;
49
+ const current = recording;
50
+ recording = undefined;
51
+ transcribing = true;
52
+ try {
53
+ const transcript = await voice.transcribe(await current.stop());
54
+ if (transcript) content = content.trim() ? content.trimEnd() + ' ' + transcript : transcript;
55
+ } catch (error) {
56
+ toast('error', error);
57
+ } finally {
58
+ transcribing = false;
59
+ }
60
+ }
61
+
62
+ function cancelDictation() {
63
+ recording?.cancel();
64
+ recording = undefined;
65
+ }
66
+
67
+ $effect(() => cancelDictation);
68
+
69
+ $effect(() => voice.useSender(async spoken => void (await onsend(spoken, true))));
70
+
71
+ async function send() {
72
+ if (!content.trim() || generating || sending) return;
73
+ sending = true;
74
+ try {
75
+ await onsend(content);
76
+ content = '';
77
+ } finally {
78
+ sending = false;
79
+ }
80
+ }
81
+ </script>
82
+
83
+ <form
84
+ class="composer"
85
+ onsubmit={e => {
86
+ e.preventDefault();
87
+ void send();
88
+ }}
89
+ >
90
+ {#if voice.conversation.active}
91
+ <VoiceMode {generating} {onstop} />
92
+ {:else}
93
+ <textarea
94
+ bind:value={content}
95
+ placeholder={transcribing ? text('ai.voice.transcribing') : recording ? text('ai.voice.listening') : text('ai.placeholder')}
96
+ onkeydown={e => {
97
+ if (e.key == 'Escape' && recording) return cancelDictation();
98
+ if (e.key != 'Enter' || e.shiftKey || e.isComposing) return;
99
+ if (ctrlEnter && !e.ctrlKey && !e.metaKey) return;
100
+ e.preventDefault();
101
+ void send();
102
+ }}></textarea>
103
+ <div class="controls">
104
+ <ModelOptions {models} bind:model bind:reasoning onchange={onoptions} />
105
+ {#if recording}
106
+ <button
107
+ type="button"
108
+ class="reset cancel"
109
+ title={text('ai.voice.cancel')}
110
+ aria-label={text('ai.voice.cancel')}
111
+ onclick={cancelDictation}
112
+ >
113
+ <Icon i="xmark" />
114
+ </button>
115
+ <button
116
+ type="button"
117
+ class="dictate recording"
118
+ title={text('ai.voice.finish')}
119
+ aria-label={text('ai.voice.finish')}
120
+ onclick={finishDictation}
121
+ >
122
+ <Icon i="check" />
123
+ </button>
124
+ {:else if voice.available.dictation}
125
+ {#if voice.available.speech}
126
+ <button
127
+ type="button"
128
+ class="dictate"
129
+ title={text('ai.voice.conversation')}
130
+ aria-label={text('ai.voice.conversation')}
131
+ onclick={voice.startConversation}
132
+ >
133
+ <Icon i="waveform-lines" />
134
+ </button>
135
+ {/if}
136
+ <button
137
+ type="button"
138
+ class="dictate"
139
+ title={text('ai.voice.dictate')}
140
+ aria-label={text('ai.voice.dictate')}
141
+ disabled={transcribing}
142
+ onclick={startDictation}
143
+ >
144
+ <Icon i="microphone" />
145
+ </button>
146
+ {/if}
147
+ {#if generating}
148
+ <button type="button" class="send" title={text('ai.stop')} onclick={() => onstop?.()}>
149
+ <Icon i="stop" />
150
+ </button>
151
+ {:else}
152
+ <button type="submit" class="send" title={text('ai.send')} disabled={sending || !content.trim()}>
153
+ <Icon i="arrow-up" />
154
+ </button>
155
+ {/if}
156
+ </div>
157
+ {/if}
158
+ </form>
159
+
160
+ <style>
161
+ .composer {
162
+ display: flex;
163
+ flex-direction: column;
164
+ gap: 0.5em;
165
+ padding: 0.75em 0.75em 0.75em 1em;
166
+ border-radius: 1.25em;
167
+ background-color: var(--bg-alt);
168
+ max-width: 50em;
169
+ width: 100%;
170
+ view-transition-name: ai-composer;
171
+ }
172
+
173
+ textarea {
174
+ border: none;
175
+ background: none;
176
+ padding: 0.25em 0;
177
+ field-sizing: content;
178
+ resize: none;
179
+ min-height: 1lh;
180
+ max-height: 12lh;
181
+ }
182
+
183
+ .controls {
184
+ display: flex;
185
+ flex-wrap: wrap;
186
+ align-items: center;
187
+ justify-content: flex-end;
188
+ gap: 0.75em;
189
+ }
190
+
191
+ .dictate {
192
+ display: inline-flex;
193
+ align-items: center;
194
+ justify-content: center;
195
+ padding: 0.5em;
196
+ border-radius: 0.5em;
197
+ border: none;
198
+ background: none;
199
+
200
+ &.recording {
201
+ background-color: var(--bg-error);
202
+ animation: pulse 1.5s ease-in-out infinite;
203
+ }
204
+
205
+ &:disabled {
206
+ opacity: 50%;
207
+ }
208
+ }
209
+
210
+ .cancel {
211
+ opacity: 69%;
212
+ }
213
+
214
+ @keyframes pulse {
215
+ 50% {
216
+ opacity: 60%;
217
+ }
218
+ }
219
+
220
+ @media (prefers-reduced-motion: reduce) {
221
+ .dictate.recording {
222
+ animation: none;
223
+ }
224
+ }
225
+
226
+ .send {
227
+ display: inline-flex;
228
+ align-items: center;
229
+ justify-content: center;
230
+ padding: 0.5em;
231
+ border-radius: 0.5em;
232
+ background-color: var(--bg-accent);
233
+ }
234
+ </style>