@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
@@ -0,0 +1,433 @@
1
+ <script lang="ts">
2
+ import { beforeNavigate, goto, invalidate } from '$app/navigation';
3
+ import * as ai from '@axium/ai/common';
4
+ import { watchConversation } from '@axium/ai/live';
5
+ import { fetchAPI, text } from '@axium/client';
6
+ import { Icon, InlineEdit } from '@axium/client/components';
7
+ import { confirm } from '@axium/client/dialogs';
8
+ import { toast } from '@axium/client/toast';
9
+ import { tick, type Snippet } from 'svelte';
10
+ import { renameConversation } from './actions.js';
11
+ import ChatMessage from './ChatMessage.svelte';
12
+ import Composer from './Composer.svelte';
13
+ import ConversationMenu from './ConversationMenu.svelte';
14
+ import { viewTransition } from './transition.js';
15
+ import * as voice from './voice.svelte.js';
16
+
17
+ const {
18
+ conversation,
19
+ models,
20
+ title,
21
+ ctrlEnter,
22
+ temporary = false,
23
+ actions,
24
+ }: {
25
+ conversation: Pick<ai.Conversation, 'id' | 'model' | 'reasoning'> & { messages: ai.Message[] };
26
+ models: ai.Models;
27
+ title: string;
28
+ ctrlEnter?: boolean;
29
+ /** Nothing is saved: the messages only exist here, and the server forgets each response once it is sent */
30
+ temporary?: boolean;
31
+ /** Shown in the header of temporary conversations */
32
+ actions?: Snippet;
33
+ } = $props();
34
+
35
+ let messages = $state(conversation.messages),
36
+ model = $state(conversation.model ?? ai.resolveRole(models.models, models.roles, 'chat')?.id ?? ''),
37
+ reasoning = $state(conversation.reasoning),
38
+ renaming = $state(false),
39
+ container = $state<HTMLDivElement>(),
40
+ anonymous = $state(false),
41
+ decisions = $state<ai.Decisions>({}),
42
+ allowedTools = $state<string[]>([]);
43
+
44
+ const generating = $derived(messages.some(message => message.status == 'pending'));
45
+ const visible = $derived(messages.filter(message => message.role != 'tool'));
46
+ const results = $derived(new Map(messages.filter(message => message.toolCallId).map(message => [message.toolCallId!, message])));
47
+ const awaiting = $derived(messages.filter(message => message.status == 'awaiting'));
48
+
49
+ function isNearBottom(): boolean {
50
+ if (!container) return true;
51
+ return container.scrollHeight - container.scrollTop - container.clientHeight < 100;
52
+ }
53
+
54
+ function scrollToBottom(): void {
55
+ container?.scrollTo({ top: container.scrollHeight });
56
+ }
57
+
58
+ function update(change: () => void): void {
59
+ const stick = isNearBottom();
60
+ change();
61
+ if (stick) void tick().then(scrollToBottom);
62
+ }
63
+
64
+ function upsert(message: ai.Message): void {
65
+ update(() => {
66
+ const index = messages.findIndex(existing => existing.id == message.id);
67
+ if (index == -1) messages.push(message);
68
+ else messages[index] = message;
69
+ });
70
+ }
71
+
72
+ /** Adds `message` unless a live update already did, which would carry newer text */
73
+ function add(message: ai.Message): void {
74
+ if (!messages.some(existing => existing.id == message.id)) upsert(message);
75
+ }
76
+
77
+ function remove(ids: string[]): void {
78
+ messages = messages.filter(message => !ids.includes(message.id));
79
+ }
80
+
81
+ /** Deltas received during a reload, applied once it finishes */
82
+ let buffered: ai.Delta[] | null = null;
83
+
84
+ async function reload(): Promise<void> {
85
+ if (buffered || temporary) return;
86
+ buffered = [];
87
+ try {
88
+ const latest = await fetchAPI('GET', 'ai/conversations/:id', {}, conversation.id);
89
+ messages = latest.messages;
90
+ } catch (error) {
91
+ toast('error', error);
92
+ }
93
+ const received = buffered;
94
+ buffered = null;
95
+ for (const delta of received) applyDelta(delta);
96
+ }
97
+
98
+ /** Reloads when text is missing, e.g. after opening a conversation mid-response. Temporary conversations wait for the finished message instead. */
99
+ function applyDelta(delta: ai.Delta): void {
100
+ if (buffered) {
101
+ buffered.push(delta);
102
+ return;
103
+ }
104
+
105
+ const message = messages.find(message => message.id == delta.messageId);
106
+ const current = message?.[delta.field] ?? '';
107
+ if (!message || delta.position > current.length) return void reload();
108
+
109
+ update(() => (message[delta.field] = current.slice(0, delta.position) + delta.text));
110
+ }
111
+
112
+ $effect(() => watchConversation(conversation.id, { message: upsert, delta: applyDelta, remove, reconnect: reload }));
113
+
114
+ $effect(() => void tick().then(scrollToBottom));
115
+
116
+ /** Reads replies aloud in conversation mode */
117
+ $effect(() => {
118
+ const index = messages.findLastIndex(message => message.role == 'user');
119
+ const turn = messages[index];
120
+ if (!turn?.voice || !voice.isTurn(turn.id)) return;
121
+
122
+ const after = messages.slice(index + 1);
123
+ const replies = after.filter(message => message.role == 'assistant');
124
+ voice.follow(turn.id, replies.map(message => message.content).join('\n'), voice.isSettled(after));
125
+ });
126
+
127
+ /** The history a temporary conversation sends with each request, which the server filters as it would a saved one */
128
+ function temporaryHistory(): ai.TemporaryMessage[] {
129
+ return messages
130
+ .filter(message => message.status != 'pending')
131
+ .map(({ id, role, content, toolCalls, toolCallId, status, voice, created }) => ({
132
+ id,
133
+ role,
134
+ content,
135
+ toolCalls,
136
+ toolCallId,
137
+ status,
138
+ voice,
139
+ created,
140
+ }));
141
+ }
142
+
143
+ async function respondTemporary(decided?: ai.Decisions): Promise<void> {
144
+ const pending = await fetchAPI(
145
+ 'PUT',
146
+ 'ai/temporary/:id',
147
+ { model: model || null, reasoning, anonymous, messages: temporaryHistory(), decisions: decided, allowedTools },
148
+ conversation.id
149
+ );
150
+ add(pending);
151
+ }
152
+
153
+ /** Records a choice for a call awaiting approval, and continues the response once every awaiting call has one */
154
+ async function decide(call: ai.ToolCall, decision: ai.Decision) {
155
+ decisions[call.id] = decision;
156
+ if (decision == 'chat' && temporary && !allowedTools.includes(call.name)) allowedTools.push(call.name);
157
+ if (!awaiting.every(message => message.toolCallId! in decisions)) return;
158
+
159
+ const decided = $state.snapshot(decisions);
160
+ try {
161
+ if (temporary) await respondTemporary(decided);
162
+ else {
163
+ const { message } = await fetchAPI(
164
+ 'POST',
165
+ 'ai/conversations/:id',
166
+ { action: 'decide', decisions: decided },
167
+ conversation.id
168
+ );
169
+ if (message) add(message);
170
+ }
171
+ decisions = {};
172
+ } catch (error) {
173
+ toast('error', error);
174
+ }
175
+ }
176
+
177
+ async function sendTemporary(content: string, spoken: boolean): Promise<void> {
178
+ const message: ai.Message = {
179
+ id: crypto.randomUUID(),
180
+ conversationId: conversation.id,
181
+ created: new Date(),
182
+ role: 'user',
183
+ content: content.trim(),
184
+ reasoning: null,
185
+ toolCalls: null,
186
+ toolCallId: null,
187
+ status: 'done',
188
+ error: null,
189
+ usage: null,
190
+ voice: spoken,
191
+ };
192
+ if (spoken) voice.addTurn(message.id);
193
+ if (messages.length) upsert(message);
194
+ else await viewTransition(() => upsert(message));
195
+
196
+ try {
197
+ await respondTemporary();
198
+ } catch (error) {
199
+ messages = messages.filter(existing => existing.id != message.id);
200
+ throw error;
201
+ }
202
+ }
203
+
204
+ async function send(content: string, spoken = false) {
205
+ try {
206
+ if (temporary) return await sendTemporary(content, spoken);
207
+ const sent = await fetchAPI('PUT', 'ai/conversations/:id', { content, voice: spoken }, conversation.id);
208
+ for (const message of sent) {
209
+ if (message.role == 'user' && spoken) voice.addTurn(message.id);
210
+ upsert(message);
211
+ }
212
+ await invalidate('ai:conversations');
213
+ } catch (error) {
214
+ toast('error', error);
215
+ throw error;
216
+ }
217
+ }
218
+
219
+ async function retry() {
220
+ try {
221
+ if (temporary) {
222
+ const previous = messages;
223
+ const lastUser = messages.findLastIndex(message => message.role == 'user');
224
+ messages = messages.slice(0, lastUser + 1);
225
+ try {
226
+ await respondTemporary();
227
+ } catch (error) {
228
+ messages = previous;
229
+ throw error;
230
+ }
231
+ return;
232
+ }
233
+ const { message } = await fetchAPI('POST', 'ai/conversations/:id', { action: 'retry' }, conversation.id);
234
+ if (message) upsert(message);
235
+ } catch (error) {
236
+ toast('error', error);
237
+ }
238
+ }
239
+
240
+ /** Replaces the content of one of the user's messages and responds again, dropping the messages after it */
241
+ async function edit(id: string, content: string) {
242
+ const index = messages.findIndex(message => message.id == id);
243
+ const later = messages.slice(index + 1).map(message => message.id);
244
+
245
+ try {
246
+ if (temporary) {
247
+ const previous = messages;
248
+ messages = [...messages.slice(0, index), { ...messages[index], content: content.trim() }];
249
+ try {
250
+ await respondTemporary();
251
+ } catch (error) {
252
+ messages = previous;
253
+ throw error;
254
+ }
255
+ return;
256
+ }
257
+
258
+ const { message } = await fetchAPI('POST', 'ai/conversations/:id', { action: 'edit', message: id, content }, conversation.id);
259
+ const edited = messages.find(message => message.id == id);
260
+ if (edited) edited.content = content.trim();
261
+ remove(later);
262
+ if (message) add(message);
263
+ } catch (error) {
264
+ toast('error', error);
265
+ throw error;
266
+ }
267
+ }
268
+
269
+ function stop() {
270
+ const request = temporary
271
+ ? fetchAPI('POST', 'ai/temporary/:id', { action: 'cancel' }, conversation.id)
272
+ : fetchAPI('POST', 'ai/conversations/:id', { action: 'cancel' }, conversation.id);
273
+ request.catch(error => toast('error', error));
274
+ }
275
+
276
+ /** Set once the user agreed to discard a temporary conversation */
277
+ let discarding = false;
278
+
279
+ beforeNavigate(navigation => {
280
+ if (!temporary || !messages.length || discarding) return;
281
+ navigation.cancel();
282
+ const destination = navigation.to?.url;
283
+ if (navigation.type == 'leave' || !destination) return;
284
+
285
+ void confirm(text('ai.temporary.discard_confirm'), { confirmText: text('ai.temporary.discard'), danger: true }).then(confirmed => {
286
+ if (!confirmed) return;
287
+ discarding = true;
288
+ void goto(destination);
289
+ });
290
+ });
291
+ </script>
292
+
293
+ <div class={['conversation', temporary && !messages.length && 'empty']}>
294
+ <div class="header">
295
+ {#if temporary}
296
+ <div class="title icon-text">
297
+ {#if messages.length}
298
+ <Icon i="ghost" />
299
+ <span>{text('ai.temporary.title')}</span>
300
+ {/if}
301
+ </div>
302
+ {@render actions?.()}
303
+ {:else}
304
+ <div class="title">
305
+ {#if renaming}
306
+ <InlineEdit
307
+ value={title}
308
+ schema={ai.ConversationInit.shape.title}
309
+ commit={value => renameConversation(conversation.id, value)}
310
+ close={() => (renaming = false)}
311
+ />
312
+ {:else}
313
+ <span>{title || text('ai.untitled')}</span>
314
+ {/if}
315
+ </div>
316
+ <ConversationMenu id={conversation.id} onrename={() => (renaming = true)} showToggle="always" />
317
+ {/if}
318
+ </div>
319
+
320
+ <div class="messages" bind:this={container}>
321
+ <div class="column">
322
+ {#if temporary && !messages.length}
323
+ <div class="empty">
324
+ <h2>{text('ai.temporary.title')}</h2>
325
+ <p class="subtle">{text('ai.temporary.description')}</p>
326
+ <div class="anonymous">
327
+ <input type="checkbox" id="ai-temporary-anonymous" bind:checked={anonymous} />
328
+ <label for="ai-temporary-anonymous" class="checkbox">
329
+ {#if anonymous}<Icon i="check" --size="1.3em" />{/if}
330
+ </label>
331
+ <label for="ai-temporary-anonymous">{text('ai.temporary.anonymous')}</label>
332
+ </div>
333
+ </div>
334
+ {/if}
335
+ {#each visible as message, index (message.id)}
336
+ <ChatMessage
337
+ {message}
338
+ {ctrlEnter}
339
+ {results}
340
+ {decisions}
341
+ onretry={index == visible.length - 1 && !generating ? retry : undefined}
342
+ onedit={message.role == 'user' && !generating ? content => edit(message.id, content) : undefined}
343
+ ondecide={generating ? undefined : decide}
344
+ />
345
+ {/each}
346
+ </div>
347
+ </div>
348
+
349
+ <div class="footer">
350
+ <Composer
351
+ {generating}
352
+ models={models.models}
353
+ {ctrlEnter}
354
+ bind:model
355
+ bind:reasoning
356
+ onsend={send}
357
+ onstop={stop}
358
+ onoptions={temporary
359
+ ? undefined
360
+ : () =>
361
+ fetchAPI('PATCH', 'ai/conversations/:id', { model, reasoning }, conversation.id).catch(error =>
362
+ toast('error', error)
363
+ )}
364
+ />
365
+ </div>
366
+ </div>
367
+
368
+ <style>
369
+ .conversation {
370
+ display: flex;
371
+ flex-direction: column;
372
+ height: 100%;
373
+ min-height: 0;
374
+ }
375
+
376
+ .header {
377
+ display: flex;
378
+ flex-wrap: wrap;
379
+ align-items: center;
380
+ gap: 1em;
381
+ padding: 0.75em 1em;
382
+
383
+ .title {
384
+ flex: 1;
385
+ min-width: 10em;
386
+ font-weight: bold;
387
+ overflow: hidden;
388
+ text-overflow: ellipsis;
389
+ white-space: nowrap;
390
+ }
391
+ }
392
+
393
+ .messages {
394
+ flex: 1;
395
+ padding: 1em;
396
+ overflow-y: auto;
397
+ }
398
+
399
+ .column {
400
+ display: flex;
401
+ flex-direction: column;
402
+ gap: 1.5em;
403
+ max-width: 50em;
404
+ margin: 0 auto;
405
+ }
406
+
407
+ .empty {
408
+ text-align: center;
409
+ }
410
+
411
+ .anonymous {
412
+ display: inline-flex;
413
+ align-items: center;
414
+ gap: 0.5em;
415
+ }
416
+
417
+ .footer {
418
+ display: flex;
419
+ justify-content: center;
420
+ padding: 1em;
421
+ }
422
+
423
+ .conversation.empty {
424
+ .messages {
425
+ flex: 0 0 auto;
426
+ margin-top: auto;
427
+ }
428
+
429
+ .footer {
430
+ margin-bottom: auto;
431
+ }
432
+ }
433
+ </style>
@@ -0,0 +1,18 @@
1
+ <script lang="ts">
2
+ import { text } from '@axium/client';
3
+ import { Icon, Popover } from '@axium/client/components';
4
+ import { deleteConversation } from './actions.js';
5
+
6
+ const { id, onrename, showToggle = 'hover' }: { id: string; onrename(): void; showToggle?: 'hover' | 'always' } = $props();
7
+ </script>
8
+
9
+ <Popover {showToggle}>
10
+ <button class="reset menu-item" onclick={onrename}>
11
+ <Icon i="pen" />
12
+ <span>{text('generic.rename')}</span>
13
+ </button>
14
+ <button class="reset menu-item" onclick={() => deleteConversation(id)}>
15
+ <Icon i="trash" />
16
+ <span>{text('generic.delete')}</span>
17
+ </button>
18
+ </Popover>
@@ -0,0 +1,71 @@
1
+ <script lang="ts">
2
+ import type * as ai from '@axium/ai/common';
3
+ import { fetchAPI, text } from '@axium/client';
4
+ import { FormDialog, Icon } from '@axium/client/components';
5
+ import { toast } from '@axium/client/toast';
6
+
7
+ const { model, onremove }: { model: ai.Model; onremove?(): void } = $props();
8
+
9
+ let confirmDelete = $state<HTMLDialogElement>();
10
+ let busy = $state(false);
11
+
12
+ async function act(action: 'load' | 'unload' | 'pause' | 'resume') {
13
+ busy = true;
14
+ try {
15
+ await fetchAPI('POST', 'ai/models/:id', { action }, model.id);
16
+ } catch (error) {
17
+ toast('error', error);
18
+ } finally {
19
+ busy = false;
20
+ }
21
+ }
22
+
23
+ async function remove() {
24
+ await fetchAPI('DELETE', 'ai/models/:id', {}, model.id);
25
+ toast('success', text('ai.model_deleted', { name: model.name }));
26
+ onremove?.();
27
+ }
28
+ </script>
29
+
30
+ <div class="ModelActions">
31
+ {#if model.status == 'downloading'}
32
+ <button class="icon-text" disabled={busy} onclick={() => act('pause')}>
33
+ <Icon i="pause" />
34
+ <span>{text('ai.action.pause')}</span>
35
+ </button>
36
+ {:else if model.status == 'incomplete'}
37
+ <button class="icon-text" disabled={busy} onclick={() => act('resume')}>
38
+ <Icon i="play" />
39
+ <span>{text('ai.action.resume')}</span>
40
+ </button>
41
+ {:else if model.status == 'loaded' || model.status == 'sleeping' || model.status == 'loading'}
42
+ <button class="icon-text" disabled={busy} onclick={() => act('unload')}>
43
+ <Icon i="eject" />
44
+ <span>{text('ai.action.unload')}</span>
45
+ </button>
46
+ {:else if model.status == 'unloaded'}
47
+ <button class="icon-text" disabled={busy} onclick={() => act('load')}>
48
+ <Icon i="upload" />
49
+ <span>{text('ai.action.load')}</span>
50
+ </button>
51
+ {/if}
52
+ <button class="icon-text danger" onclick={() => confirmDelete?.showModal()}>
53
+ <Icon i="trash" />
54
+ <span>{text('generic.delete')}</span>
55
+ </button>
56
+ </div>
57
+
58
+ <FormDialog bind:dialog={confirmDelete} submit={remove} submitText={text('generic.delete')} submitDanger>
59
+ {#snippet header()}
60
+ <h3>{text('ai.delete_title', { name: model.name })}</h3>
61
+ {/snippet}
62
+ <p>{text('ai.delete_body')}</p>
63
+ </FormDialog>
64
+
65
+ <style>
66
+ .ModelActions {
67
+ display: flex;
68
+ flex-wrap: wrap;
69
+ gap: 0.5em;
70
+ }
71
+ </style>
@@ -0,0 +1,101 @@
1
+ <script lang="ts">
2
+ import * as ai from '@axium/ai/common';
3
+ import { withUpdates } from '@axium/ai/live';
4
+ import { text } from '@axium/client';
5
+ import { Icon } from '@axium/client/components';
6
+
7
+ let {
8
+ models,
9
+ model = $bindable(),
10
+ reasoning = $bindable(),
11
+ onchange,
12
+ }: { models: ai.Model[]; model: string; reasoning: string; onchange?(): void } = $props();
13
+
14
+ const id = $props.id();
15
+
16
+ const namedLevels = ['default', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'] as const;
17
+
18
+ function levelName(level: string): string {
19
+ return (namedLevels as readonly string[]).includes(level)
20
+ ? text(`ai.reasoning_level.${level as (typeof namedLevels)[number]}`)
21
+ : level;
22
+ }
23
+
24
+ const available = $derived(withUpdates(models).filter(ai.isUsable));
25
+ const selected = $derived(available.find(option => option.id == model));
26
+ const levels = $derived(selected?.reasoningLevels ?? []);
27
+ const defaultLevel = $derived(selected && ai.defaultReasoning(selected));
28
+
29
+ /** The model's default level is selected as `default` */
30
+ const value = $derived(reasoning == defaultLevel ? 'default' : reasoning);
31
+
32
+ const options = $derived.by(() => {
33
+ const values = ['none', ...levels].map(level => (level == defaultLevel ? 'default' : level));
34
+ if (!values.includes('default')) values.unshift('default');
35
+ if (!values.includes(value)) values.push(value);
36
+ return values;
37
+ });
38
+
39
+ const enabled = $derived(value == 'default' ? defaultLevel != 'none' : value != 'none');
40
+
41
+ function optionLabel(option: string): string {
42
+ if (option != 'default' || !defaultLevel) return levelName(option);
43
+ return text('ai.reasoning_default', { level: levelName(defaultLevel) });
44
+ }
45
+
46
+ function change(update: () => void) {
47
+ update();
48
+ onchange?.();
49
+ }
50
+
51
+ /** Uses `default` whenever it already matches the requested state */
52
+ function setEnabled(on: boolean) {
53
+ const onByDefault = defaultLevel != 'none';
54
+ change(() => (reasoning = on == onByDefault ? 'default' : on ? 'high' : 'none'));
55
+ }
56
+ </script>
57
+
58
+ <select class="model" value={model} title={text('ai.model')} onchange={e => change(() => (model = e.currentTarget.value))}>
59
+ {#if !selected}
60
+ <option value={model}>{model}</option>
61
+ {/if}
62
+ {#each available as option (option.id)}
63
+ <option value={option.id}>{option.name}</option>
64
+ {/each}
65
+ </select>
66
+
67
+ {#if levels.length}
68
+ <select class="reasoning subtle" {value} title={text('ai.reasoning')} onchange={e => change(() => (reasoning = e.currentTarget.value))}>
69
+ {#each options as option}
70
+ <option value={option}>{optionLabel(option)}</option>
71
+ {/each}
72
+ </select>
73
+ {:else}
74
+ <span class="reasoning toggle subtle">
75
+ <input id="{id}:reasoning" type="checkbox" checked={enabled} onchange={e => setEnabled(e.currentTarget.checked)} />
76
+ <label for="{id}:reasoning" class="checkbox">
77
+ {#if enabled}<Icon i="check" --size="1.3em" />{/if}
78
+ </label>
79
+ <label for="{id}:reasoning">{text('ai.reasoning')}</label>
80
+ </span>
81
+ {/if}
82
+
83
+ <style>
84
+ select {
85
+ border: none;
86
+ background: none;
87
+ color: inherit;
88
+ cursor: pointer;
89
+ min-width: 0;
90
+ }
91
+
92
+ .toggle {
93
+ display: inline-flex;
94
+ align-items: center;
95
+ gap: 0.5em;
96
+
97
+ label {
98
+ cursor: pointer;
99
+ }
100
+ }
101
+ </style>
@@ -0,0 +1,49 @@
1
+ <script lang="ts">
2
+ import type * as ai from '@axium/ai/common';
3
+ import { text } from '@axium/client';
4
+ import { ProgressBar } from '@axium/client/components';
5
+ import { bytes } from 'utilium/format';
6
+
7
+ const { model }: { model: ai.Model } = $props();
8
+
9
+ const fraction = $derived(model.progress?.total ? model.progress.done / model.progress.total : null);
10
+ </script>
11
+
12
+ <div class={['ModelStatus', model.status]}>
13
+ <span class="label">
14
+ {text(`ai.status.${model.status}`)}
15
+ {#if model.failed && model.status == 'unloaded'}
16
+ <span class="failed">{text('ai.load_failed')}</span>
17
+ {/if}
18
+ </span>
19
+ {#if model.status == 'downloading' || model.status == 'incomplete'}
20
+ <ProgressBar value={model.status == 'downloading' ? fraction : (fraction ?? 0)} />
21
+ {#if model.progress?.total}
22
+ <span class="subtle">{bytes(model.progress.done)} / {bytes(model.progress.total)}</span>
23
+ {/if}
24
+ {/if}
25
+ </div>
26
+
27
+ <style>
28
+ .ModelStatus {
29
+ display: flex;
30
+ flex-direction: column;
31
+ gap: 0.25em;
32
+ min-width: 0;
33
+ }
34
+
35
+ .loaded .label,
36
+ .sleeping .label {
37
+ color: var(--fg-accent);
38
+ }
39
+
40
+ .unavailable .label,
41
+ .failed {
42
+ color: var(--fg-error);
43
+ }
44
+
45
+ .failed {
46
+ margin-left: 0.5em;
47
+ font-size: 0.85em;
48
+ }
49
+ </style>