@axium/ai 0.0.0-stage → 0.0.1
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/LICENSE.md +157 -0
- package/README.md +2 -2
- package/db.json +114 -0
- package/dist/.locale.d.ts +300 -0
- package/dist/.locale.js +1 -0
- package/dist/client/cli.d.ts +1 -0
- package/dist/client/cli.js +224 -0
- package/dist/client/config.d.ts +196 -0
- package/dist/client/config.js +55 -0
- package/dist/client/hooks.d.ts +3 -0
- package/dist/client/hooks.js +32 -0
- package/dist/client/local.d.ts +17 -0
- package/dist/client/local.js +112 -0
- package/dist/common.d.ts +1318 -0
- package/dist/common.js +569 -0
- package/dist/hooks.d.ts +13 -0
- package/dist/hooks.js +34 -0
- package/dist/hub.d.ts +4 -0
- package/dist/hub.js +75 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/integrations/notes.d.ts +1 -0
- package/dist/integrations/notes.js +104 -0
- package/dist/integrations/tasks.d.ts +1 -0
- package/dist/integrations/tasks.js +157 -0
- package/dist/loop.d.ts +75 -0
- package/dist/loop.js +238 -0
- package/dist/memory.d.ts +107 -0
- package/dist/memory.js +193 -0
- package/dist/node/chat.d.ts +50 -0
- package/dist/node/chat.js +60 -0
- package/dist/node/llama.d.ts +115 -0
- package/dist/node/llama.js +385 -0
- package/dist/node/markdown.d.ts +6 -0
- package/dist/node/markdown.js +285 -0
- package/dist/node/models.d.ts +34 -0
- package/dist/node/models.js +287 -0
- package/dist/node/web.d.ts +1 -0
- package/dist/node/web.js +203 -0
- package/dist/server/api/conversations.d.ts +1 -0
- package/dist/server/api/conversations.js +216 -0
- package/dist/server/api/gateway.d.ts +1 -0
- package/dist/server/api/gateway.js +113 -0
- package/dist/server/api/memories.d.ts +1 -0
- package/dist/server/api/memories.js +129 -0
- package/dist/server/api/models.d.ts +1 -0
- package/dist/server/api/models.js +161 -0
- package/dist/server/api/temporary.d.ts +1 -0
- package/dist/server/api/temporary.js +50 -0
- package/dist/server/api/timers.d.ts +1 -0
- package/dist/server/api/timers.js +27 -0
- package/dist/server/api/voice.d.ts +1 -0
- package/dist/server/api/voice.js +188 -0
- package/dist/server/api.d.ts +1 -0
- package/dist/server/api.js +157 -0
- package/dist/server/generation.d.ts +38 -0
- package/dist/server/generation.js +299 -0
- package/dist/server/memory.d.ts +7 -0
- package/dist/server/memory.js +218 -0
- package/dist/server/models.d.ts +13 -0
- package/dist/server/models.js +59 -0
- package/dist/server/preferences.d.ts +3 -0
- package/dist/server/preferences.js +12 -0
- package/dist/server/timers.d.ts +7 -0
- package/dist/server/timers.js +66 -0
- package/dist/speech.d.ts +17 -0
- package/dist/speech.js +69 -0
- package/dist/timers.d.ts +1 -0
- package/dist/timers.js +67 -0
- package/dist/tools.d.ts +70 -0
- package/dist/tools.js +84 -0
- package/lib/ChatMessage.svelte +331 -0
- package/lib/Composer.svelte +234 -0
- package/lib/Conversation.svelte +433 -0
- package/lib/ConversationMenu.svelte +18 -0
- package/lib/ModelActions.svelte +71 -0
- package/lib/ModelOptions.svelte +101 -0
- package/lib/ModelStatus.svelte +49 -0
- package/lib/ToolCall.svelte +171 -0
- package/lib/VoiceMode.svelte +113 -0
- package/lib/actions.ts +21 -0
- package/lib/index.ts +7 -0
- package/lib/live.svelte.ts +113 -0
- package/lib/markdown.ts +40 -0
- package/lib/preferences.ts +13 -0
- package/lib/transition.ts +24 -0
- package/lib/tsconfig.json +14 -0
- package/lib/voice.svelte.ts +476 -0
- package/locales/en.json +316 -0
- package/package.json +139 -5
- package/routes/ai/+layout.svelte +177 -0
- package/routes/ai/+layout.ts +26 -0
- package/routes/ai/+page.svelte +109 -0
- package/routes/ai/TimerAlerts.svelte +51 -0
- package/routes/ai/Timers.svelte +121 -0
- package/routes/ai/[id]/+page.svelte +18 -0
- package/routes/ai/[id]/+page.ts +14 -0
- package/routes/ai/memory/+page.svelte +313 -0
- package/routes/ai/memory/+page.ts +10 -0
- package/routes/ai/memory/MemoryForm.svelte +111 -0
- package/routes/ai/models/+page.svelte +199 -0
- package/routes/ai/models/+page.ts +5 -0
- package/routes/ai/models/AddModel.svelte +240 -0
- package/routes/ai/models/MemoryMeter.svelte +120 -0
- package/routes/ai/models/Roles.svelte +159 -0
- package/routes/ai/models/[id]/+page.svelte +331 -0
- package/routes/ai/models/[id]/+page.ts +6 -0
- package/routes/ai/timers.svelte.ts +94 -0
- package/routes/tsconfig.json +14 -0
|
@@ -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>
|