@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,159 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import * as ai from '@axium/ai/common';
|
|
3
|
+
import { fetchAPI, text } from '@axium/client';
|
|
4
|
+
import { Icon } from '@axium/client/components';
|
|
5
|
+
import { toast } from '@axium/client/toast';
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
models,
|
|
9
|
+
roles = $bindable(),
|
|
10
|
+
editable,
|
|
11
|
+
}: {
|
|
12
|
+
models: ai.Model[];
|
|
13
|
+
roles: ai.Roles;
|
|
14
|
+
editable: boolean;
|
|
15
|
+
} = $props();
|
|
16
|
+
|
|
17
|
+
let saving = $state(false);
|
|
18
|
+
|
|
19
|
+
async function save(role: ai.Role, list: string[]) {
|
|
20
|
+
saving = true;
|
|
21
|
+
try {
|
|
22
|
+
roles = await fetchAPI('PATCH', 'ai/roles', { [role]: list });
|
|
23
|
+
} catch (error) {
|
|
24
|
+
toast('error', error);
|
|
25
|
+
} finally {
|
|
26
|
+
saving = false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function move(role: ai.Role, index: number, offset: number) {
|
|
31
|
+
const list = [...roles[role]];
|
|
32
|
+
[list[index], list[index + offset]] = [list[index + offset], list[index]];
|
|
33
|
+
void save(role, list);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function modelName(id: string): string {
|
|
37
|
+
return models.find(model => model.id == id)?.name ?? id;
|
|
38
|
+
}
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<div class="Roles">
|
|
42
|
+
{#each ai.roles as role (role)}
|
|
43
|
+
{const serving = $derived(ai.resolveRole(models, roles, role))}
|
|
44
|
+
{const list = $derived(roles[role])}
|
|
45
|
+
{const addable = $derived(models.filter(model => !list.includes(model.id) && ai.canServe(model, role)))}
|
|
46
|
+
<div class="role">
|
|
47
|
+
<span class="name" title={text(`ai.role.about.${role}`)}>{text(`ai.role.name.${role}`)}</span>
|
|
48
|
+
<div class="models">
|
|
49
|
+
{#each list as id, index (id)}
|
|
50
|
+
<span class={['model', serving?.id == id && 'serving']} title={serving?.id == id ? text('ai.role.serving') : undefined}>
|
|
51
|
+
{#if editable && index}
|
|
52
|
+
<button
|
|
53
|
+
class="reset"
|
|
54
|
+
disabled={saving}
|
|
55
|
+
title={text('ai.role.move_up')}
|
|
56
|
+
aria-label={text('ai.role.move_up')}
|
|
57
|
+
onclick={() => move(role, index, -1)}
|
|
58
|
+
>
|
|
59
|
+
<Icon i="chevron-left" --size="10px" />
|
|
60
|
+
</button>
|
|
61
|
+
{/if}
|
|
62
|
+
<span>{modelName(id)}</span>
|
|
63
|
+
{#if editable}
|
|
64
|
+
<button
|
|
65
|
+
class="reset"
|
|
66
|
+
disabled={saving}
|
|
67
|
+
title={text('ai.role.remove')}
|
|
68
|
+
aria-label={text('ai.role.remove')}
|
|
69
|
+
onclick={() => save(role, list.toSpliced(index, 1))}
|
|
70
|
+
>
|
|
71
|
+
<Icon i="xmark" --size="10px" />
|
|
72
|
+
</button>
|
|
73
|
+
{/if}
|
|
74
|
+
</span>
|
|
75
|
+
{/each}
|
|
76
|
+
|
|
77
|
+
{#if !serving}
|
|
78
|
+
<span class="subtle">{text('ai.role.unavailable')}</span>
|
|
79
|
+
{:else if !list.includes(serving.id)}
|
|
80
|
+
<span class="subtle">{text('ai.role.fallback', { name: serving.name })}</span>
|
|
81
|
+
{/if}
|
|
82
|
+
|
|
83
|
+
{#if editable && addable.length}
|
|
84
|
+
<select
|
|
85
|
+
class="add"
|
|
86
|
+
disabled={saving}
|
|
87
|
+
aria-label={text('ai.role.add')}
|
|
88
|
+
onchange={e => {
|
|
89
|
+
const id = e.currentTarget.value;
|
|
90
|
+
e.currentTarget.value = '';
|
|
91
|
+
if (id) void save(role, [...list, id]);
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
<option value="">+</option>
|
|
95
|
+
{#each addable as model (model.id)}
|
|
96
|
+
<option value={model.id}>{model.name}</option>
|
|
97
|
+
{/each}
|
|
98
|
+
</select>
|
|
99
|
+
{/if}
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
{/each}
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<style>
|
|
106
|
+
.Roles {
|
|
107
|
+
display: grid;
|
|
108
|
+
grid-template-columns: max-content 1fr;
|
|
109
|
+
gap: 0.5em 1.5em;
|
|
110
|
+
align-items: center;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.role {
|
|
114
|
+
display: grid;
|
|
115
|
+
grid-column: 1 / -1;
|
|
116
|
+
grid-template-columns: subgrid;
|
|
117
|
+
align-items: center;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.name {
|
|
121
|
+
cursor: help;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.models {
|
|
125
|
+
display: flex;
|
|
126
|
+
flex-wrap: wrap;
|
|
127
|
+
align-items: center;
|
|
128
|
+
gap: 0.4em;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.model {
|
|
132
|
+
display: inline-flex;
|
|
133
|
+
align-items: center;
|
|
134
|
+
gap: 0.4em;
|
|
135
|
+
padding: 0.15em 0.6em;
|
|
136
|
+
border-radius: 1em;
|
|
137
|
+
background-color: var(--bg-alt);
|
|
138
|
+
font-size: 0.9em;
|
|
139
|
+
|
|
140
|
+
&.serving {
|
|
141
|
+
background-color: var(--bg-accent);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
button:disabled {
|
|
145
|
+
opacity: 30%;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.add {
|
|
150
|
+
padding: 0.1em 0.4em;
|
|
151
|
+
font-size: 0.9em;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@media (width < 600px) {
|
|
155
|
+
.Roles {
|
|
156
|
+
grid-template-columns: 1fr;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
</style>
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { goto, invalidate } from '$app/navigation';
|
|
3
|
+
import * as ai from '@axium/ai/common';
|
|
4
|
+
import { ModelActions, ModelStatus } from '@axium/ai/components';
|
|
5
|
+
import { modelUpdates, withUpdates } from '@axium/ai/live';
|
|
6
|
+
import { fetchAPI, text } from '@axium/client';
|
|
7
|
+
import { Icon } from '@axium/client/components';
|
|
8
|
+
import { toast } from '@axium/client/toast';
|
|
9
|
+
import { bytes } from 'utilium/format';
|
|
10
|
+
|
|
11
|
+
const { data } = $props();
|
|
12
|
+
|
|
13
|
+
const id = $props.id();
|
|
14
|
+
|
|
15
|
+
const removed = $derived(modelUpdates.get(data.model.id) === null);
|
|
16
|
+
const model = $derived(withUpdates([data.model])[0] ?? data.model);
|
|
17
|
+
const isAdmin = $derived(!!data.session.user.isAdmin);
|
|
18
|
+
const serves = $derived(
|
|
19
|
+
ai.roles.filter(role => ai.resolveRole(withUpdates(data.models.models), data.models.roles, role)?.id == model.id)
|
|
20
|
+
);
|
|
21
|
+
const repo = $derived(model.source.split(':')[0]);
|
|
22
|
+
|
|
23
|
+
function levelName(level: string): string {
|
|
24
|
+
return ['none', ...ai.reasoningLevels].includes(level) ? text(`ai.reasoning_level.${level as 'none'}`) : level;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const reasoningOptions = $derived.by(() => {
|
|
28
|
+
if (!model.reasoningLevels) return ['none'];
|
|
29
|
+
return model.reasoningLevels.length ? ['none', ...model.reasoningLevels] : ['none', 'high'];
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function optionName(option: string): string {
|
|
33
|
+
if (option == 'high' && model.reasoningLevels?.length === 0) return text('ai.reasoning_on');
|
|
34
|
+
return levelName(option);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let name = $state(data.model.name),
|
|
38
|
+
reasoning = $state(data.model.reasoning ?? ''),
|
|
39
|
+
systemPrompt = $state(data.model.systemPrompt ?? ''),
|
|
40
|
+
device = $state(data.model.options.device ?? ''),
|
|
41
|
+
context = $state(data.model.options.context),
|
|
42
|
+
reserve = $state(data.model.options.reserve),
|
|
43
|
+
parallel = $state(data.model.options.parallel),
|
|
44
|
+
mmproj = $state(data.model.options.mmproj ?? ''),
|
|
45
|
+
saving = $state(false);
|
|
46
|
+
|
|
47
|
+
async function save(update: ai.ModelUpdate) {
|
|
48
|
+
saving = true;
|
|
49
|
+
try {
|
|
50
|
+
await fetchAPI('PATCH', 'ai/models/:id', update, model.id);
|
|
51
|
+
toast('success', text('ai.model_saved'));
|
|
52
|
+
await invalidate('ai:conversations');
|
|
53
|
+
} catch (error) {
|
|
54
|
+
toast('error', error);
|
|
55
|
+
} finally {
|
|
56
|
+
saving = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function submit(event: SubmitEvent) {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
void save({
|
|
63
|
+
name: name.trim() || model.name,
|
|
64
|
+
reasoning: reasoning || null,
|
|
65
|
+
systemPrompt: systemPrompt.trim() || null,
|
|
66
|
+
options: {
|
|
67
|
+
device: device.trim() || undefined,
|
|
68
|
+
context: context || undefined,
|
|
69
|
+
reserve: reserve ?? undefined,
|
|
70
|
+
parallel: parallel || undefined,
|
|
71
|
+
mmproj: mmproj.trim() || undefined,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function memoryText(use?: { device: number; host: number }): string {
|
|
77
|
+
if (!use) return text('ai.unknown');
|
|
78
|
+
return text('ai.ram.split', { device: bytes(use.device), host: bytes(use.host) });
|
|
79
|
+
}
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<svelte:head>
|
|
83
|
+
<title>{text('ai.model_title', { name: model.name })}</title>
|
|
84
|
+
</svelte:head>
|
|
85
|
+
|
|
86
|
+
<div class="model-page">
|
|
87
|
+
<a href="/ai/models" class="back icon-text subtle">
|
|
88
|
+
<Icon i="arrow-left" --size="12px" />
|
|
89
|
+
<span>{text('ai.models')}</span>
|
|
90
|
+
</a>
|
|
91
|
+
|
|
92
|
+
{#if removed}
|
|
93
|
+
<p>{text('ai.model_removed')}</p>
|
|
94
|
+
{:else}
|
|
95
|
+
<div class="header">
|
|
96
|
+
<div class="title">
|
|
97
|
+
<h2>{model.name}</h2>
|
|
98
|
+
<span class="subtle">{model.id}</span>
|
|
99
|
+
</div>
|
|
100
|
+
{#if isAdmin}
|
|
101
|
+
<ModelActions {model} onremove={() => goto('/ai/models')} />
|
|
102
|
+
{/if}
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<ModelStatus {model} />
|
|
106
|
+
|
|
107
|
+
<dl class="details">
|
|
108
|
+
<dt>{text('ai.detail.source')}</dt>
|
|
109
|
+
<dd>
|
|
110
|
+
<a href="https://huggingface.co/{repo}" target="_blank" rel="noreferrer">{model.source}</a>
|
|
111
|
+
</dd>
|
|
112
|
+
|
|
113
|
+
<dt>{text('ai.detail.size')}</dt>
|
|
114
|
+
<dd>{bytes(model.size)}</dd>
|
|
115
|
+
|
|
116
|
+
<dt>{text('ai.detail.added')}</dt>
|
|
117
|
+
<dd>{model.created.toLocaleString()}</dd>
|
|
118
|
+
|
|
119
|
+
<dt>{text('ai.detail.context')}</dt>
|
|
120
|
+
<dd>
|
|
121
|
+
{model.contextLength ? text('ai.tokens', { count: model.contextLength.toLocaleString() }) : text('ai.unknown')}
|
|
122
|
+
{#if model.memory?.context}
|
|
123
|
+
<span class="subtle">{text('ai.detail.context_loaded', { count: model.memory.context.toLocaleString() })}</span>
|
|
124
|
+
{/if}
|
|
125
|
+
</dd>
|
|
126
|
+
|
|
127
|
+
<dt>{text('ai.detail.inputs')}</dt>
|
|
128
|
+
<dd>{model.inputs?.map(input => text(`ai.modality.${input}`)).join(', ') ?? text('ai.unknown')}</dd>
|
|
129
|
+
|
|
130
|
+
<dt>{text('ai.detail.outputs')}</dt>
|
|
131
|
+
<dd>{model.outputs?.map(output => text(`ai.modality.${output}`)).join(', ') ?? text('ai.unknown')}</dd>
|
|
132
|
+
|
|
133
|
+
<dt>{text('ai.detail.roles')}</dt>
|
|
134
|
+
<dd>{serves.map(role => text(`ai.role.name.${role}`)).join(', ') || text('ai.role.none')}</dd>
|
|
135
|
+
|
|
136
|
+
<dt>{text('ai.reasoning')}</dt>
|
|
137
|
+
<dd>
|
|
138
|
+
{#if !model.reasoningLevels}
|
|
139
|
+
{text('ai.reasoning_unknown')}
|
|
140
|
+
{:else if model.reasoningLevels.length}
|
|
141
|
+
{model.reasoningLevels.map(levelName).join(', ')}
|
|
142
|
+
{:else}
|
|
143
|
+
{text('ai.reasoning_toggle')}
|
|
144
|
+
{/if}
|
|
145
|
+
{#if model.templateReasoning}
|
|
146
|
+
<span class="subtle">{text('ai.detail.template_default', { level: optionName(model.templateReasoning) })}</span>
|
|
147
|
+
{/if}
|
|
148
|
+
</dd>
|
|
149
|
+
|
|
150
|
+
<dt>{text('ai.detail.memory_minimum')}</dt>
|
|
151
|
+
<dd>{memoryText(model.memory?.minimum)}</dd>
|
|
152
|
+
|
|
153
|
+
{#if model.memory?.current}
|
|
154
|
+
<dt>{text('ai.detail.memory_current')}</dt>
|
|
155
|
+
<dd>{memoryText(model.memory.current)}</dd>
|
|
156
|
+
{/if}
|
|
157
|
+
</dl>
|
|
158
|
+
|
|
159
|
+
{#if isAdmin}
|
|
160
|
+
<form class="settings" onsubmit={submit}>
|
|
161
|
+
<h3>{text('ai.settings')}</h3>
|
|
162
|
+
|
|
163
|
+
<div class="field">
|
|
164
|
+
<label for="{id}:name">{text('ai.add.name')}</label>
|
|
165
|
+
<input id="{id}:name" bind:value={name} maxlength="100" />
|
|
166
|
+
</div>
|
|
167
|
+
|
|
168
|
+
<div class="field">
|
|
169
|
+
<label for="{id}:reasoning">{text('ai.detail.default_reasoning')}</label>
|
|
170
|
+
<select id="{id}:reasoning" bind:value={reasoning}>
|
|
171
|
+
<option value="">
|
|
172
|
+
{model.templateReasoning
|
|
173
|
+
? text('ai.reasoning_template', { level: optionName(model.templateReasoning) })
|
|
174
|
+
: text('ai.reasoning_level.default')}
|
|
175
|
+
</option>
|
|
176
|
+
{#each reasoningOptions as option}
|
|
177
|
+
<option value={option}>{optionName(option)}</option>
|
|
178
|
+
{/each}
|
|
179
|
+
</select>
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
<div class="field">
|
|
183
|
+
<label for="{id}:prompt">{text('ai.detail.system_prompt')}</label>
|
|
184
|
+
<textarea
|
|
185
|
+
id="{id}:prompt"
|
|
186
|
+
bind:value={systemPrompt}
|
|
187
|
+
rows="6"
|
|
188
|
+
maxlength="20000"
|
|
189
|
+
placeholder={text('ai.detail.system_prompt_default')}></textarea>
|
|
190
|
+
</div>
|
|
191
|
+
|
|
192
|
+
<h4>{text('ai.detail.loading')}</h4>
|
|
193
|
+
<p class="subtle">{text('ai.detail.loading_note')}</p>
|
|
194
|
+
<div class="options">
|
|
195
|
+
<div class="field">
|
|
196
|
+
<label for="{id}:device">{text('ai.option.device')}</label>
|
|
197
|
+
<input id="{id}:device" bind:value={device} placeholder={text('ai.option.automatic')} maxlength="64" />
|
|
198
|
+
</div>
|
|
199
|
+
<div class="field">
|
|
200
|
+
<label for="{id}:context">{text('ai.option.context')}</label>
|
|
201
|
+
<input id="{id}:context" type="number" min="1" bind:value={context} placeholder={text('ai.option.automatic')} />
|
|
202
|
+
</div>
|
|
203
|
+
<div class="field">
|
|
204
|
+
<label for="{id}:reserve">{text('ai.option.reserve')}</label>
|
|
205
|
+
<input id="{id}:reserve" type="number" min="0" bind:value={reserve} placeholder={text('ai.option.automatic')} />
|
|
206
|
+
</div>
|
|
207
|
+
<div class="field">
|
|
208
|
+
<label for="{id}:parallel">{text('ai.option.parallel')}</label>
|
|
209
|
+
<input
|
|
210
|
+
id="{id}:parallel"
|
|
211
|
+
type="number"
|
|
212
|
+
min="1"
|
|
213
|
+
max="64"
|
|
214
|
+
bind:value={parallel}
|
|
215
|
+
placeholder={text('ai.option.automatic')}
|
|
216
|
+
/>
|
|
217
|
+
</div>
|
|
218
|
+
<div class="field">
|
|
219
|
+
<label for="{id}:mmproj">{text('ai.option.mmproj')}</label>
|
|
220
|
+
<input id="{id}:mmproj" bind:value={mmproj} placeholder={text('ai.option.mmproj_default')} maxlength="4096" />
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
223
|
+
|
|
224
|
+
<div>
|
|
225
|
+
<button type="submit" disabled={saving}>{text('ai.save')}</button>
|
|
226
|
+
</div>
|
|
227
|
+
</form>
|
|
228
|
+
{:else}
|
|
229
|
+
<section>
|
|
230
|
+
<h3>{text('ai.detail.system_prompt')}</h3>
|
|
231
|
+
<p class="prompt">{model.systemPrompt ?? text('ai.detail.system_prompt_default')}</p>
|
|
232
|
+
</section>
|
|
233
|
+
{/if}
|
|
234
|
+
{/if}
|
|
235
|
+
</div>
|
|
236
|
+
|
|
237
|
+
<style>
|
|
238
|
+
.model-page {
|
|
239
|
+
display: flex;
|
|
240
|
+
flex-direction: column;
|
|
241
|
+
gap: 1em;
|
|
242
|
+
max-width: 60em;
|
|
243
|
+
height: 100%;
|
|
244
|
+
margin: 0 auto;
|
|
245
|
+
padding: 1em 1.5em;
|
|
246
|
+
overflow-y: auto;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.header {
|
|
250
|
+
display: flex;
|
|
251
|
+
flex-direction: column;
|
|
252
|
+
align-items: flex-start;
|
|
253
|
+
gap: 0.75em;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.title {
|
|
257
|
+
display: flex;
|
|
258
|
+
flex-wrap: wrap;
|
|
259
|
+
align-items: baseline;
|
|
260
|
+
gap: 0.25em 0.75em;
|
|
261
|
+
|
|
262
|
+
h2 {
|
|
263
|
+
margin: 0;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
.details {
|
|
268
|
+
display: grid;
|
|
269
|
+
grid-template-columns: max-content 1fr;
|
|
270
|
+
gap: 0.5em 1.5em;
|
|
271
|
+
margin: 0;
|
|
272
|
+
|
|
273
|
+
dt {
|
|
274
|
+
opacity: 69%;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
dd {
|
|
278
|
+
margin: 0;
|
|
279
|
+
overflow-wrap: anywhere;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.settings {
|
|
284
|
+
display: flex;
|
|
285
|
+
flex-direction: column;
|
|
286
|
+
gap: 0.75em;
|
|
287
|
+
align-items: flex-start;
|
|
288
|
+
|
|
289
|
+
h3,
|
|
290
|
+
h4,
|
|
291
|
+
p {
|
|
292
|
+
margin: 0.5em 0 0;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.field {
|
|
297
|
+
display: flex;
|
|
298
|
+
flex-direction: column;
|
|
299
|
+
gap: 0.25em;
|
|
300
|
+
width: 100%;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.options {
|
|
304
|
+
display: grid;
|
|
305
|
+
grid-template-columns: repeat(auto-fit, minmax(13em, 1fr));
|
|
306
|
+
gap: 0.25em 0.75em;
|
|
307
|
+
width: 100%;
|
|
308
|
+
|
|
309
|
+
.field {
|
|
310
|
+
display: grid;
|
|
311
|
+
grid-row: span 2;
|
|
312
|
+
grid-template-rows: subgrid;
|
|
313
|
+
align-items: end;
|
|
314
|
+
gap: 0.25em;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.prompt {
|
|
319
|
+
white-space: pre-wrap;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
@media (width < 500px) {
|
|
323
|
+
.details {
|
|
324
|
+
grid-template-columns: 1fr;
|
|
325
|
+
|
|
326
|
+
dd {
|
|
327
|
+
margin-bottom: 0.5em;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
</style>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type * as ai from '@axium/ai/common';
|
|
2
|
+
import { fetchAPI } from '@axium/client/requests';
|
|
3
|
+
import { addListener, connect, onConnect } from '@axium/client/socket';
|
|
4
|
+
import { SvelteMap } from 'svelte/reactivity';
|
|
5
|
+
|
|
6
|
+
/** Running timers, by ID */
|
|
7
|
+
export const running = new SvelteMap<string, ai.Timer>();
|
|
8
|
+
|
|
9
|
+
/** Timers that ended while the page was open and haven't been dismissed, by ID */
|
|
10
|
+
export const finished = new SvelteMap<string, ai.Timer>();
|
|
11
|
+
|
|
12
|
+
let userId: string | undefined;
|
|
13
|
+
let listening = false;
|
|
14
|
+
|
|
15
|
+
async function refresh(): Promise<void> {
|
|
16
|
+
if (!userId) return;
|
|
17
|
+
const timers = await fetchAPI('GET', 'users/:id/ai/timers', {}, userId);
|
|
18
|
+
running.clear();
|
|
19
|
+
for (const timer of timers) running.set(timer.id, timer);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Starts tracking the user's timers. Safe to call more than once. */
|
|
23
|
+
export function useTimers(id: string): void {
|
|
24
|
+
if (userId != id) {
|
|
25
|
+
userId = id;
|
|
26
|
+
void refresh().catch(() => null);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (listening) return;
|
|
30
|
+
listening = true;
|
|
31
|
+
|
|
32
|
+
addListener('ai.timer', timer => running.set(timer.id, timer));
|
|
33
|
+
|
|
34
|
+
addListener('ai.timer.remove', ({ id, done }) => {
|
|
35
|
+
const timer = running.get(id);
|
|
36
|
+
running.delete(id);
|
|
37
|
+
if (!done || !timer) return;
|
|
38
|
+
finished.set(id, timer);
|
|
39
|
+
ring();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
onConnect(() => void refresh().catch(() => null));
|
|
43
|
+
void connect().catch(() => null);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function cancel(id: string): Promise<void> {
|
|
47
|
+
if (!userId) return;
|
|
48
|
+
await fetchAPI('DELETE', 'users/:id/ai/timers/:timer', {}, userId, id);
|
|
49
|
+
running.delete(id);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function dismiss(id: string): void {
|
|
53
|
+
finished.delete(id);
|
|
54
|
+
if (!finished.size) stopRinging();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** How long the alarm sounds before stopping on its own, in milliseconds */
|
|
58
|
+
const ringDuration = 30_000;
|
|
59
|
+
|
|
60
|
+
let audio: AudioContext | undefined;
|
|
61
|
+
let ringing: ReturnType<typeof setInterval> | undefined;
|
|
62
|
+
|
|
63
|
+
function beep(): void {
|
|
64
|
+
audio ??= new AudioContext();
|
|
65
|
+
void audio.resume();
|
|
66
|
+
|
|
67
|
+
for (let i = 0; i < 3; i++) {
|
|
68
|
+
const start = audio.currentTime + i * 0.25;
|
|
69
|
+
const oscillator = audio.createOscillator();
|
|
70
|
+
const gain = audio.createGain();
|
|
71
|
+
oscillator.frequency.value = 880;
|
|
72
|
+
gain.gain.setValueAtTime(0.15, start);
|
|
73
|
+
gain.gain.exponentialRampToValueAtTime(0.001, start + 0.15);
|
|
74
|
+
oscillator.connect(gain).connect(audio.destination);
|
|
75
|
+
oscillator.start(start);
|
|
76
|
+
oscillator.stop(start + 0.15);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function ring(): void {
|
|
81
|
+
if (ringing) return;
|
|
82
|
+
|
|
83
|
+
const started = Date.now();
|
|
84
|
+
beep();
|
|
85
|
+
ringing = setInterval(() => {
|
|
86
|
+
if (Date.now() - started > ringDuration) stopRinging();
|
|
87
|
+
else beep();
|
|
88
|
+
}, 2000);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function stopRinging(): void {
|
|
92
|
+
clearInterval(ringing);
|
|
93
|
+
ringing = undefined;
|
|
94
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["../tsconfig.json", "$app/tsconfig"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"typeRoots": null,
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"module": "esnext",
|
|
7
|
+
"noEmit": true,
|
|
8
|
+
"target": "esnext",
|
|
9
|
+
"rootDir": "..",
|
|
10
|
+
"types": ["@sveltejs/kit"]
|
|
11
|
+
},
|
|
12
|
+
"include": ["**/*", "../lib/*", "../src/.*.ts", "../../client/dist/.*.ts"],
|
|
13
|
+
"references": [{ "path": ".." }]
|
|
14
|
+
}
|