@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,111 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Id as MemoryId, type Node as Memory } from '@axium/ai/memory';
|
|
3
|
+
import { text } from '@axium/client';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
memory,
|
|
7
|
+
maxLength,
|
|
8
|
+
onsave,
|
|
9
|
+
oncancel,
|
|
10
|
+
}: {
|
|
11
|
+
/** The memory being edited, if any */
|
|
12
|
+
memory?: Memory;
|
|
13
|
+
maxLength: number;
|
|
14
|
+
onsave(values: { id: string; description: string; content: string }): Promise<unknown>;
|
|
15
|
+
oncancel?(): void;
|
|
16
|
+
} = $props();
|
|
17
|
+
|
|
18
|
+
let id = $state(memory?.id ?? ''),
|
|
19
|
+
description = $state(memory?.description ?? ''),
|
|
20
|
+
content = $state(memory?.content ?? ''),
|
|
21
|
+
saving = $state(false),
|
|
22
|
+
idEdited = $state(!!memory);
|
|
23
|
+
|
|
24
|
+
const idError = $derived(id && !MemoryId.safeParse(id).success ? text('ai.memory.id_invalid') : undefined);
|
|
25
|
+
const valid = $derived(!!id && !idError && !!description.trim());
|
|
26
|
+
|
|
27
|
+
function suggestId(from: string): string {
|
|
28
|
+
return from
|
|
29
|
+
.toLowerCase()
|
|
30
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
31
|
+
.replace(/^-+|-+$/g, '')
|
|
32
|
+
.split('-')
|
|
33
|
+
.slice(0, 5)
|
|
34
|
+
.join('-')
|
|
35
|
+
.slice(0, 64);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function submit() {
|
|
39
|
+
if (!valid || saving) return;
|
|
40
|
+
saving = true;
|
|
41
|
+
try {
|
|
42
|
+
await onsave({ id, description: description.trim(), content: content.trim() });
|
|
43
|
+
if (memory) return;
|
|
44
|
+
id = description = content = '';
|
|
45
|
+
idEdited = false;
|
|
46
|
+
} finally {
|
|
47
|
+
saving = false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<form
|
|
53
|
+
class="MemoryForm"
|
|
54
|
+
onsubmit={e => {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
void submit();
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
<input
|
|
60
|
+
bind:value={description}
|
|
61
|
+
placeholder={text('ai.memory.description_placeholder')}
|
|
62
|
+
maxlength="200"
|
|
63
|
+
oninput={() => {
|
|
64
|
+
if (!idEdited) id = suggestId(description);
|
|
65
|
+
}}
|
|
66
|
+
/>
|
|
67
|
+
<input
|
|
68
|
+
bind:value={id}
|
|
69
|
+
class={['id', idError && 'error']}
|
|
70
|
+
placeholder={text('ai.memory.id_placeholder')}
|
|
71
|
+
maxlength="64"
|
|
72
|
+
title={idError}
|
|
73
|
+
oninput={() => (idEdited = true)}
|
|
74
|
+
/>
|
|
75
|
+
<textarea bind:value={content} placeholder={text('ai.memory.content_placeholder')} maxlength={maxLength}></textarea>
|
|
76
|
+
<div class="actions">
|
|
77
|
+
{#if oncancel}
|
|
78
|
+
<button type="button" onclick={oncancel}>{text('generic.cancel')}</button>
|
|
79
|
+
{/if}
|
|
80
|
+
<button type="submit" class="primary" disabled={!valid || saving}>{memory ? text('ai.memory.save') : text('ai.memory.add')}</button>
|
|
81
|
+
</div>
|
|
82
|
+
</form>
|
|
83
|
+
|
|
84
|
+
<style>
|
|
85
|
+
.MemoryForm {
|
|
86
|
+
display: flex;
|
|
87
|
+
flex-direction: column;
|
|
88
|
+
gap: 0.5em;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.id {
|
|
92
|
+
font-family: monospace;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
textarea {
|
|
96
|
+
field-sizing: content;
|
|
97
|
+
resize: none;
|
|
98
|
+
min-height: 2lh;
|
|
99
|
+
max-height: 12lh;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.actions {
|
|
103
|
+
display: flex;
|
|
104
|
+
justify-content: flex-end;
|
|
105
|
+
gap: 0.5em;
|
|
106
|
+
|
|
107
|
+
.primary {
|
|
108
|
+
background-color: var(--bg-accent);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
</style>
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ModelActions, ModelStatus } from '@axium/ai/components';
|
|
3
|
+
import { withUpdates } from '@axium/ai/live';
|
|
4
|
+
import { fetchAPI, text } from '@axium/client';
|
|
5
|
+
import { Icon } from '@axium/client/components';
|
|
6
|
+
import { bytes } from 'utilium/format';
|
|
7
|
+
import * as ai from '@axium/ai/common';
|
|
8
|
+
import AddModel from './AddModel.svelte';
|
|
9
|
+
import MemoryMeter from './MemoryMeter.svelte';
|
|
10
|
+
import Roles from './Roles.svelte';
|
|
11
|
+
|
|
12
|
+
const { data } = $props();
|
|
13
|
+
|
|
14
|
+
let current = $state(data.models);
|
|
15
|
+
let addDialog = $state<HTMLDialogElement>();
|
|
16
|
+
|
|
17
|
+
const models = $derived(withUpdates(current.models));
|
|
18
|
+
const isAdmin = $derived(!!data.session.user.isAdmin);
|
|
19
|
+
|
|
20
|
+
async function refresh() {
|
|
21
|
+
if (document.hidden) return;
|
|
22
|
+
current = await fetchAPI('GET', 'ai/models').catch(() => current);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
$effect(() => {
|
|
26
|
+
const interval = setInterval(refresh, 5000);
|
|
27
|
+
return () => clearInterval(interval);
|
|
28
|
+
});
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<svelte:head>
|
|
32
|
+
<title>{text('ai.models_title')}</title>
|
|
33
|
+
</svelte:head>
|
|
34
|
+
|
|
35
|
+
<div class="models-page">
|
|
36
|
+
<div class="header">
|
|
37
|
+
<h2>{text('ai.models')}</h2>
|
|
38
|
+
{#if isAdmin}
|
|
39
|
+
<button class="icon-text" onclick={() => addDialog?.showModal()}>
|
|
40
|
+
<Icon i="plus" />
|
|
41
|
+
<span>{text('ai.add.title')}</span>
|
|
42
|
+
</button>
|
|
43
|
+
{/if}
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
{#if !current.running}
|
|
47
|
+
<p class="error">{text('ai.not_running')}</p>
|
|
48
|
+
{/if}
|
|
49
|
+
|
|
50
|
+
<section>
|
|
51
|
+
<h3>{text('ai.ram.title')}</h3>
|
|
52
|
+
<MemoryMeter memory={current.memory} {models} />
|
|
53
|
+
</section>
|
|
54
|
+
|
|
55
|
+
<section class="list">
|
|
56
|
+
{#each models as model (model.id)}
|
|
57
|
+
<div class="model">
|
|
58
|
+
<div class="info">
|
|
59
|
+
<div class="title">
|
|
60
|
+
<a href="/ai/models/{model.id}" class="name">{model.name}</a>
|
|
61
|
+
{#each ai.roles.filter(role => ai.resolveRole(models, current.roles, role)?.id == model.id) as role (role)}
|
|
62
|
+
<span class="badge">{text(`ai.role.name.${role}`)}</span>
|
|
63
|
+
{/each}
|
|
64
|
+
</div>
|
|
65
|
+
<span class="subtle">{model.id}</span>
|
|
66
|
+
</div>
|
|
67
|
+
<ModelStatus {model} />
|
|
68
|
+
<span class="subtle size">{bytes(model.size)}</span>
|
|
69
|
+
<div class="actions">
|
|
70
|
+
{#if isAdmin}
|
|
71
|
+
<ModelActions {model} onremove={refresh} />
|
|
72
|
+
{/if}
|
|
73
|
+
</div>
|
|
74
|
+
<Icon i="chevron-right" />
|
|
75
|
+
</div>
|
|
76
|
+
{:else}
|
|
77
|
+
<p class="subtle">{text(isAdmin ? 'ai.no_models_admin' : 'ai.no_models')}</p>
|
|
78
|
+
{/each}
|
|
79
|
+
</section>
|
|
80
|
+
|
|
81
|
+
<section>
|
|
82
|
+
<h3>{text('ai.role.title')}</h3>
|
|
83
|
+
<p class="subtle">{text('ai.role.description')}</p>
|
|
84
|
+
<Roles {models} bind:roles={current.roles} editable={isAdmin} />
|
|
85
|
+
</section>
|
|
86
|
+
</div>
|
|
87
|
+
|
|
88
|
+
{#if isAdmin}
|
|
89
|
+
<AddModel bind:dialog={addDialog} {models} />
|
|
90
|
+
{/if}
|
|
91
|
+
|
|
92
|
+
<style>
|
|
93
|
+
.models-page {
|
|
94
|
+
display: flex;
|
|
95
|
+
flex-direction: column;
|
|
96
|
+
gap: 1.5em;
|
|
97
|
+
max-width: 60em;
|
|
98
|
+
height: 100%;
|
|
99
|
+
margin: 0 auto;
|
|
100
|
+
padding: 1em 1.5em;
|
|
101
|
+
overflow-y: auto;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.header {
|
|
105
|
+
display: flex;
|
|
106
|
+
flex-wrap: wrap;
|
|
107
|
+
align-items: center;
|
|
108
|
+
justify-content: space-between;
|
|
109
|
+
gap: 1em;
|
|
110
|
+
|
|
111
|
+
h2 {
|
|
112
|
+
margin: 0;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
h3 {
|
|
117
|
+
margin: 0 0 0.75em;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
h3 + p {
|
|
121
|
+
margin: -0.5em 0 0.75em;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.list {
|
|
125
|
+
display: grid;
|
|
126
|
+
grid-template-columns: minmax(0, 1fr) minmax(8em, max-content) max-content max-content max-content;
|
|
127
|
+
gap: 0.5em 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.model {
|
|
131
|
+
position: relative;
|
|
132
|
+
display: grid;
|
|
133
|
+
grid-column: 1 / -1;
|
|
134
|
+
grid-template-columns: subgrid;
|
|
135
|
+
align-items: center;
|
|
136
|
+
gap: 0.5em 1.5em;
|
|
137
|
+
padding: 0.75em 1em;
|
|
138
|
+
border-radius: 0.75em;
|
|
139
|
+
background-color: var(--bg-alt);
|
|
140
|
+
|
|
141
|
+
&:hover {
|
|
142
|
+
background-color: var(--bg-strong);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.info {
|
|
147
|
+
display: flex;
|
|
148
|
+
flex-direction: column;
|
|
149
|
+
gap: 0.25em;
|
|
150
|
+
min-width: 0;
|
|
151
|
+
|
|
152
|
+
.title {
|
|
153
|
+
display: flex;
|
|
154
|
+
flex-wrap: wrap;
|
|
155
|
+
align-items: center;
|
|
156
|
+
gap: 0.25em 0.75em;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.name {
|
|
160
|
+
font-weight: bold;
|
|
161
|
+
|
|
162
|
+
&::after {
|
|
163
|
+
content: '';
|
|
164
|
+
position: absolute;
|
|
165
|
+
inset: 0;
|
|
166
|
+
border-radius: inherit;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.actions {
|
|
172
|
+
position: relative;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.badge {
|
|
176
|
+
padding: 0.1em 0.5em;
|
|
177
|
+
border-radius: 0.5em;
|
|
178
|
+
background-color: var(--bg-accent);
|
|
179
|
+
font-size: 0.8em;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.size {
|
|
183
|
+
text-align: end;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.error {
|
|
187
|
+
color: var(--fg-error);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
@media (width < 800px) {
|
|
191
|
+
.list {
|
|
192
|
+
grid-template-columns: minmax(0, 1fr) max-content max-content;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.actions {
|
|
196
|
+
grid-column: 1 / 3;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
</style>
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import * 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
|
+
import { bytes } from 'utilium/format';
|
|
7
|
+
|
|
8
|
+
let { dialog = $bindable(), models }: { dialog?: HTMLDialogElement; models: ai.Model[] } = $props();
|
|
9
|
+
|
|
10
|
+
const id = $props.id();
|
|
11
|
+
|
|
12
|
+
let query = $state(''),
|
|
13
|
+
results = $state<ai.HubRepo[]>(),
|
|
14
|
+
searching = $state(false),
|
|
15
|
+
details = $state<ai.HubDetails>(),
|
|
16
|
+
loadingDetails = $state<string>(),
|
|
17
|
+
quant = $state<string>(),
|
|
18
|
+
modelId = $state(''),
|
|
19
|
+
name = $state('');
|
|
20
|
+
|
|
21
|
+
const idError = $derived.by(() => {
|
|
22
|
+
if (!modelId) return;
|
|
23
|
+
const result = ai.ModelId.safeParse(modelId);
|
|
24
|
+
if (!result.success) return result.error.issues[0].message;
|
|
25
|
+
if (models.some(model => model.id == modelId)) return text('ai.add.id_taken');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
async function search() {
|
|
29
|
+
if (!query.trim()) return;
|
|
30
|
+
searching = true;
|
|
31
|
+
try {
|
|
32
|
+
results = await fetchAPI('GET', 'ai/hub', { search: query.trim() });
|
|
33
|
+
} catch (error) {
|
|
34
|
+
toast('error', error);
|
|
35
|
+
} finally {
|
|
36
|
+
searching = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A readable name from a repository name */
|
|
41
|
+
async function select(repo: string) {
|
|
42
|
+
loadingDetails = repo;
|
|
43
|
+
try {
|
|
44
|
+
details = await fetchAPI('GET', 'ai/hub/details', { repo });
|
|
45
|
+
} catch (error) {
|
|
46
|
+
toast('error', error);
|
|
47
|
+
return;
|
|
48
|
+
} finally {
|
|
49
|
+
loadingDetails = undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const fitting = details.quants.filter(option => option.fit == 'device');
|
|
53
|
+
quant = (fitting.at(-1) ?? details.quants.find(option => option.fit == 'host') ?? details.quants[0])?.tag;
|
|
54
|
+
|
|
55
|
+
name = ai.nameFromRepo(details.base ?? details.repo);
|
|
56
|
+
modelId = ai.modelIdFrom(name);
|
|
57
|
+
if (models.some(model => model.id == modelId) && quant) modelId = ai.modelIdFrom(`${name} ${quant}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function reset() {
|
|
61
|
+
details = undefined;
|
|
62
|
+
quant = undefined;
|
|
63
|
+
modelId = '';
|
|
64
|
+
name = '';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function submit() {
|
|
68
|
+
if (!details || !quant) throw text('ai.add.pick_quant');
|
|
69
|
+
if (idError) throw idError;
|
|
70
|
+
await fetchAPI('PUT', 'ai/models', { id: modelId, name: name.trim() || modelId, repo: details.repo, quant });
|
|
71
|
+
toast('success', text('ai.add.started', { name: name.trim() || modelId }));
|
|
72
|
+
reset();
|
|
73
|
+
results = undefined;
|
|
74
|
+
query = '';
|
|
75
|
+
}
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<FormDialog bind:dialog submitText={text('ai.add.download')} {submit} cancel={reset}>
|
|
79
|
+
{#snippet header()}
|
|
80
|
+
<h3>{text('ai.add.title')}</h3>
|
|
81
|
+
{/snippet}
|
|
82
|
+
|
|
83
|
+
{#if !details}
|
|
84
|
+
<div class="search">
|
|
85
|
+
<input
|
|
86
|
+
type="search"
|
|
87
|
+
bind:value={query}
|
|
88
|
+
placeholder={text('ai.add.search')}
|
|
89
|
+
onkeydown={e => {
|
|
90
|
+
if (e.key != 'Enter') return;
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
void search();
|
|
93
|
+
}}
|
|
94
|
+
/>
|
|
95
|
+
<button type="button" class="icon-text" onclick={search} disabled={searching}>
|
|
96
|
+
<Icon i="magnifying-glass" />
|
|
97
|
+
<span>{text('ai.add.search_button')}</span>
|
|
98
|
+
</button>
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
{#if results && !results.length}
|
|
102
|
+
<p class="subtle">{text('ai.add.no_results')}</p>
|
|
103
|
+
{:else if results}
|
|
104
|
+
<div class="results">
|
|
105
|
+
{#each results as result (result.id)}
|
|
106
|
+
<button type="button" class="reset result" onclick={() => select(result.id)} disabled={!!loadingDetails}>
|
|
107
|
+
<span class="repo">{result.id}</span>
|
|
108
|
+
<span class="subtle stats">
|
|
109
|
+
<span class="icon-text"><Icon i="download" --size="12px" />{result.downloads.toLocaleString()}</span>
|
|
110
|
+
<span class="icon-text"><Icon i="heart" --size="12px" />{result.likes.toLocaleString()}</span>
|
|
111
|
+
{#if result.modified}<span>{result.modified.toLocaleDateString()}</span>{/if}
|
|
112
|
+
</span>
|
|
113
|
+
</button>
|
|
114
|
+
{/each}
|
|
115
|
+
</div>
|
|
116
|
+
{/if}
|
|
117
|
+
{:else}
|
|
118
|
+
<button type="button" class="reset back icon-text subtle" onclick={reset}>
|
|
119
|
+
<Icon i="arrow-left" --size="12px" />
|
|
120
|
+
<span>{details.repo}</span>
|
|
121
|
+
</button>
|
|
122
|
+
|
|
123
|
+
{#if !details.quants.length}
|
|
124
|
+
<p class="subtle">{text('ai.add.no_quants')}</p>
|
|
125
|
+
{:else}
|
|
126
|
+
<div class="quants" role="radiogroup">
|
|
127
|
+
{#each details.quants as option (option.tag)}
|
|
128
|
+
<label class={['quant', quant == option.tag && 'selected']}>
|
|
129
|
+
<input type="radio" name="{id}:quant" value={option.tag} bind:group={quant} />
|
|
130
|
+
<span class="tag">{option.tag}</span>
|
|
131
|
+
<span class="subtle">{bytes(option.size)}</span>
|
|
132
|
+
<span class={['fit', option.fit]}>{text(`ai.fit.${option.fit}`)}</span>
|
|
133
|
+
</label>
|
|
134
|
+
{/each}
|
|
135
|
+
</div>
|
|
136
|
+
{/if}
|
|
137
|
+
|
|
138
|
+
<div class="field">
|
|
139
|
+
<label for="{id}:name">{text('ai.add.name')}</label>
|
|
140
|
+
<input id="{id}:name" bind:value={name} maxlength="100" />
|
|
141
|
+
</div>
|
|
142
|
+
<div class="field">
|
|
143
|
+
<label for="{id}:id">{text('ai.add.id')}</label>
|
|
144
|
+
<input id="{id}:id" bind:value={modelId} maxlength="64" />
|
|
145
|
+
{#if idError}<span class="error">{idError}</span>{/if}
|
|
146
|
+
</div>
|
|
147
|
+
{/if}
|
|
148
|
+
</FormDialog>
|
|
149
|
+
|
|
150
|
+
<style>
|
|
151
|
+
.search {
|
|
152
|
+
display: flex;
|
|
153
|
+
gap: 0.5em;
|
|
154
|
+
|
|
155
|
+
input {
|
|
156
|
+
flex: 1;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.results,
|
|
161
|
+
.quants {
|
|
162
|
+
display: flex;
|
|
163
|
+
flex-direction: column;
|
|
164
|
+
gap: 0.25em;
|
|
165
|
+
max-height: 50vh;
|
|
166
|
+
overflow-y: auto;
|
|
167
|
+
margin-top: 0.5em;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.result,
|
|
171
|
+
.quant {
|
|
172
|
+
display: flex;
|
|
173
|
+
align-items: center;
|
|
174
|
+
flex-wrap: wrap;
|
|
175
|
+
gap: 0.5em 1em;
|
|
176
|
+
padding: 0.5em 0.75em;
|
|
177
|
+
border-radius: 0.5em;
|
|
178
|
+
cursor: pointer;
|
|
179
|
+
|
|
180
|
+
&:hover,
|
|
181
|
+
&.selected {
|
|
182
|
+
background-color: var(--bg-alt);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.result {
|
|
187
|
+
justify-content: space-between;
|
|
188
|
+
text-align: start;
|
|
189
|
+
|
|
190
|
+
.repo {
|
|
191
|
+
overflow-wrap: anywhere;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.stats {
|
|
195
|
+
display: flex;
|
|
196
|
+
gap: 1em;
|
|
197
|
+
font-size: 0.85em;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.quant {
|
|
202
|
+
input {
|
|
203
|
+
display: none;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.tag {
|
|
207
|
+
font-family: monospace;
|
|
208
|
+
min-width: 8em;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.fit {
|
|
212
|
+
margin-left: auto;
|
|
213
|
+
font-size: 0.85em;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.fit.host {
|
|
217
|
+
color: var(--fg-warning);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.fit.none {
|
|
221
|
+
color: var(--fg-error);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.back {
|
|
226
|
+
margin-bottom: 0.5em;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.field {
|
|
230
|
+
display: flex;
|
|
231
|
+
flex-direction: column;
|
|
232
|
+
gap: 0.25em;
|
|
233
|
+
margin-top: 0.75em;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.error {
|
|
237
|
+
color: var(--fg-error);
|
|
238
|
+
font-size: 0.85em;
|
|
239
|
+
}
|
|
240
|
+
</style>
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type * as ai from '@axium/ai/common';
|
|
3
|
+
import { text } from '@axium/client';
|
|
4
|
+
import { bytes } from 'utilium/format';
|
|
5
|
+
|
|
6
|
+
const { memory, models }: { memory: ai.DRAM; models: ai.Model[] } = $props();
|
|
7
|
+
|
|
8
|
+
const loaded = $derived(models.filter(model => model.memory?.current));
|
|
9
|
+
|
|
10
|
+
interface Segment {
|
|
11
|
+
label: string;
|
|
12
|
+
size: number;
|
|
13
|
+
kind: 'model' | 'other';
|
|
14
|
+
index?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Splits used memory into loaded models, when `showModels`, and everything else */
|
|
18
|
+
function segments(device: ai.Device, kind: 'device' | 'host', showModels: boolean): Segment[] {
|
|
19
|
+
const used: Segment[] = !showModels
|
|
20
|
+
? []
|
|
21
|
+
: loaded.map((model, index) => ({ label: model.name, size: model.memory!.current![kind], kind: 'model', index }));
|
|
22
|
+
|
|
23
|
+
const ours = used.reduce((sum, segment) => sum + segment.size, 0);
|
|
24
|
+
if (device.used !== undefined && device.used > ours) {
|
|
25
|
+
used.push({ label: text('ai.ram.other'), size: device.used - ours, kind: 'other' });
|
|
26
|
+
}
|
|
27
|
+
return used.filter(segment => segment.size > 0);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function bar(device: ai.Device, kind: 'device' | 'host', showModels: boolean) {
|
|
31
|
+
const parts = segments(device, kind, showModels);
|
|
32
|
+
return { device, segments: parts, used: parts.reduce((sum, segment) => sum + segment.size, 0) };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const bars = $derived([
|
|
36
|
+
...memory.devices.map(device => bar(device, 'device', memory.devices.length == 1)),
|
|
37
|
+
bar({ ...memory.host, name: text('ai.ram.host') }, 'host', true),
|
|
38
|
+
]);
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<div class="MemoryMeter">
|
|
42
|
+
{#each bars as { device, segments, used }}
|
|
43
|
+
<div class="device">
|
|
44
|
+
<div class="label">
|
|
45
|
+
<span>{device.name}</span>
|
|
46
|
+
<span class="subtle">{text('ai.ram.usage', { used: bytes(used), total: bytes(device.total) })}</span>
|
|
47
|
+
</div>
|
|
48
|
+
<div class="bar">
|
|
49
|
+
{#each segments as segment}
|
|
50
|
+
<div
|
|
51
|
+
class={['segment', segment.kind]}
|
|
52
|
+
style:width="{(segment.size / device.total) * 100}%"
|
|
53
|
+
style:--index={segment.index ?? 0}
|
|
54
|
+
title="{segment.label}: {bytes(segment.size)}"
|
|
55
|
+
></div>
|
|
56
|
+
{/each}
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
{/each}
|
|
60
|
+
|
|
61
|
+
{#if loaded.length}
|
|
62
|
+
<div class="legend">
|
|
63
|
+
{#each loaded as model, index}
|
|
64
|
+
<span class="item"><span class="swatch segment model" style:--index={index}></span>{model.name}</span>
|
|
65
|
+
{/each}
|
|
66
|
+
<span class="item"><span class="swatch segment other"></span>{text('ai.ram.other')}</span>
|
|
67
|
+
</div>
|
|
68
|
+
{/if}
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<style>
|
|
72
|
+
.MemoryMeter {
|
|
73
|
+
display: flex;
|
|
74
|
+
flex-direction: column;
|
|
75
|
+
gap: 0.75em;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.label {
|
|
79
|
+
display: flex;
|
|
80
|
+
justify-content: space-between;
|
|
81
|
+
gap: 1em;
|
|
82
|
+
margin-bottom: 0.25em;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.bar {
|
|
86
|
+
display: flex;
|
|
87
|
+
height: 0.75em;
|
|
88
|
+
border-radius: 0.375em;
|
|
89
|
+
background-color: var(--bg-strong);
|
|
90
|
+
overflow: hidden;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.segment.model {
|
|
94
|
+
background-color: hsl(from var(--fg-accent) calc(h + var(--index) * 67) 55 62);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.segment.other {
|
|
98
|
+
background-color: hsl(0 0 50);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.legend {
|
|
102
|
+
display: flex;
|
|
103
|
+
flex-wrap: wrap;
|
|
104
|
+
gap: 1em;
|
|
105
|
+
font-size: 0.85em;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.item {
|
|
109
|
+
display: inline-flex;
|
|
110
|
+
align-items: center;
|
|
111
|
+
gap: 0.4em;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.swatch {
|
|
115
|
+
display: inline-block;
|
|
116
|
+
width: 0.75em;
|
|
117
|
+
height: 0.75em;
|
|
118
|
+
border-radius: 0.2em;
|
|
119
|
+
}
|
|
120
|
+
</style>
|