@skaile/forge-layer-core 1.1.0 → 1.2.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.
- package/CHANGELOG.md +6 -0
- package/README.md +18 -0
- package/app/components/AssistantAccountSettings.vue +41 -15
- package/app/pages/settings/agents.vue +36 -9
- package/package.json +1 -1
- package/server/utils/actions/assistant.ts +18 -7
- package/server/utils/assistant/account.ts +53 -9
- package/server/utils/assistant/engines.ts +18 -12
- package/server/utils/assistant/policy.ts +36 -0
- package/shared/messages/de.ts +12 -3
- package/shared/messages/en.ts +14 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @skaile/forge-layer-core
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7367ff9: Owners decide whether people may run the assistant on their own model: the settings scope `assistant-policy` (`ownModels`, default on, in Settings › Agents in the assistant's card; `ownModelsAllowed()`). Off, Profil shows no mode or key fields, just "The assistant uses the app's model", `assistant.account.update` refuses mode `byok` and own-key changes (403; removing a stored key still works) and stored keys are ignored, not deleted. New `personalModel(userId)` gives the person's provider, model, base URL and key when they chose "Own key" and the app allows it, so the SKAILE agent can run on it; `byokLanguageModel` builds on it and refuses while own models are off. `effectiveAssistantMode` now picks `skaile` whenever it is available to the person (with their own key under "Own key"), else `byok`. `assistant.account.get` reports `ownModels`. Profil names the modes "App's model" and "Own key", and offers "Own key" when either the SKAILE or the chat engine is installed. The Settings › Agents assistant card renders the form of every scope its parts name.
|
|
8
|
+
|
|
3
9
|
## 1.1.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -74,6 +74,24 @@ runner resolves the model itself, like the workspace agent) gets it as `source:
|
|
|
74
74
|
failover; the runner builds its config from `NUXT_AI_FALLBACK_*` itself. When the fallback stands in for a broken
|
|
75
75
|
assignment, `ai.status` gives owners (only them) a `warning` with the assignment's problem; the role stays available.
|
|
76
76
|
|
|
77
|
+
## The assistant's model
|
|
78
|
+
|
|
79
|
+
The app has one assistant, the SKAILE workspace agent (`skaile` engine, from layer-workspace-agent). It runs on the
|
|
80
|
+
app's model (the `assistant` role above) unless the person uses their own:
|
|
81
|
+
|
|
82
|
+
- **Own models** (settings scope `assistant-policy`, field `ownModels`, default on; `server/utils/assistant/policy.ts`,
|
|
83
|
+
`ownModelsAllowed()`): owners switch it in Settings › Agents, in the assistant's card. On, each person may pick
|
|
84
|
+
"Own key" (mode `byok`) in Settings › Profile and store provider, model and key (sealed under `NUXT_APP_SECRET`).
|
|
85
|
+
Off, nobody can pick it (`assistant.account.update` answers 403; `clearKey` still works), stored keys are kept but
|
|
86
|
+
ignored, and Profile shows one line: the assistant uses the app's model.
|
|
87
|
+
- `personalModel(userId)` (`server/utils/assistant/account.ts`): the person's provider, model, absolute base URL and
|
|
88
|
+
unsealed key when own models are allowed, they chose `byok` and stored all of it, else `null`. The SKAILE engine
|
|
89
|
+
runs on it; `byokLanguageModel(userId)` builds the plain chat engine's model (layer-chat) and refuses while own
|
|
90
|
+
models are off.
|
|
91
|
+
- `effectiveAssistantMode(principal)` (`server/utils/assistant/engines.ts`), the engine a new conversation uses:
|
|
92
|
+
`skaile` whenever it is available to the person (with their own key when they chose `byok`), else `byok` (the plain
|
|
93
|
+
chat, only the open page) when own models are allowed and the person can use it, else `null`.
|
|
94
|
+
|
|
77
95
|
## Importing core server code
|
|
78
96
|
|
|
79
97
|
Other layers and the app's CLI and tests import through the package's `exports`, never `~~/server/...`:
|
|
@@ -3,11 +3,13 @@ import * as z from 'zod'
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Settings › Profile › Assistant: how the app's assistant works for the signed-in person
|
|
6
|
-
* (`assistant.account.get` / `assistant.account.update`).
|
|
7
|
-
* the
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* (`assistant.account.get` / `assistant.account.update`). Whether people may pick their own model
|
|
7
|
+
* is the owner's call (`assistant-policy.ownModels`, Settings › Agents). Allowed: mode `skaile`
|
|
8
|
+
* ("App's model") runs the SKAILE agent on the app's model; mode `byok` ("Own key") runs the same
|
|
9
|
+
* agent on the person's provider, model and key, or, without SKAILE in the app, the plain chat
|
|
10
|
+
* that sees only the record of the open page. Not allowed: one line says the assistant uses the
|
|
11
|
+
* app's model, and a saved key can still be removed. One form, one explicit Save (EDIT-2); the key
|
|
12
|
+
* is write-only: the page only learns whether one is saved (`hasKey`) and removes it through `clearKey`.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
const actions = useActions()
|
|
@@ -76,19 +78,32 @@ useLeaveGuard(dirty)
|
|
|
76
78
|
const missing = computed(() => missingFields(schema.value, state, labels.value))
|
|
77
79
|
const form = useTemplateRef('form')
|
|
78
80
|
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
// "App's model" needs the SKAILE engine. "Own key" runs on the SKAILE engine or, without it, on the plain chat
|
|
82
|
+
// engine, so it is offered when either is installed, and it stays choosable without a key, because this form is
|
|
83
|
+
// where the key is entered (so its reason, which points here, is not repeated).
|
|
84
|
+
const modeItems = computed(() => {
|
|
85
|
+
const modes = account.value?.modes ?? []
|
|
86
|
+
const skaile = modes.find(entry => entry.mode === 'skaile')
|
|
87
|
+
const byokInstalled = Boolean(skaile?.installed || modes.find(entry => entry.mode === 'byok')?.installed)
|
|
88
|
+
return modes.map(({ mode, available, installed, reason }) => {
|
|
89
|
+
if (mode === 'byok')
|
|
90
|
+
return {
|
|
91
|
+
value: mode,
|
|
92
|
+
label: t('core.assistant.mode.byok'),
|
|
93
|
+
description: byokInstalled
|
|
94
|
+
? t(skaile?.installed ? 'core.assistant.modeHint.byok' : 'core.assistant.modeHint.byokChat')
|
|
95
|
+
: `${t('core.assistant.modeHint.byok')} ${t('core.assistant.notInstalled')}`,
|
|
96
|
+
disabled: !byokInstalled,
|
|
97
|
+
}
|
|
83
98
|
const hint = t(`core.assistant.modeHint.${mode}`)
|
|
84
99
|
return {
|
|
85
100
|
value: mode,
|
|
86
101
|
label: t(`core.assistant.mode.${mode}`),
|
|
87
|
-
description: available || !reason
|
|
88
|
-
disabled: !installed ||
|
|
102
|
+
description: available || !reason ? hint : `${hint} ${reason}`,
|
|
103
|
+
disabled: !installed || !available,
|
|
89
104
|
}
|
|
90
|
-
})
|
|
91
|
-
)
|
|
105
|
+
})
|
|
106
|
+
})
|
|
92
107
|
const presetItems = computed(() =>
|
|
93
108
|
PRESETS.map(({ value, label }) => ({
|
|
94
109
|
value,
|
|
@@ -178,7 +193,17 @@ async function removeKey() {
|
|
|
178
193
|
@submit="onSave"
|
|
179
194
|
@error="focusFirstError"
|
|
180
195
|
>
|
|
181
|
-
<
|
|
196
|
+
<p
|
|
197
|
+
v-if="!account.ownModels"
|
|
198
|
+
class="text-sm text-muted"
|
|
199
|
+
data-testid="assistant-app-model-only"
|
|
200
|
+
>
|
|
201
|
+
{{ t('core.assistant.appModelOnly') }}
|
|
202
|
+
</p>
|
|
203
|
+
<UFormField
|
|
204
|
+
v-else
|
|
205
|
+
name="mode"
|
|
206
|
+
>
|
|
182
207
|
<URadioGroup
|
|
183
208
|
v-model="state.mode"
|
|
184
209
|
:items="modeItems"
|
|
@@ -188,7 +213,7 @@ async function removeKey() {
|
|
|
188
213
|
/>
|
|
189
214
|
</UFormField>
|
|
190
215
|
|
|
191
|
-
<template v-if="state.mode === 'byok'">
|
|
216
|
+
<template v-if="account.ownModels && state.mode === 'byok'">
|
|
192
217
|
<UFormField
|
|
193
218
|
name="preset"
|
|
194
219
|
:label="labels.preset"
|
|
@@ -271,6 +296,7 @@ async function removeKey() {
|
|
|
271
296
|
</div>
|
|
272
297
|
|
|
273
298
|
<SettingsSave
|
|
299
|
+
v-if="account?.ownModels"
|
|
274
300
|
:dirty="dirty"
|
|
275
301
|
:loading="saving"
|
|
276
302
|
:missing="missing"
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { defineComponent, h } from 'vue'
|
|
3
|
+
// From `#components`, so an app's own `SettingsScopeForm` replaces the layer's here too.
|
|
4
|
+
import { SettingsScopeForm } from '#components'
|
|
3
5
|
import type { AppShellSettingsSection } from '../../types/app-shell'
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -7,11 +9,15 @@ import type { AppShellSettingsSection } from '../../types/app-shell'
|
|
|
7
9
|
* with this route): its model's status and checks, its settings and its own
|
|
8
10
|
* content. The app has one assistant: every section of role or scope
|
|
9
11
|
* `assistant` (the chat layer's settings, the SKAILE runs and tokens) is drawn
|
|
10
|
-
* as one card, titled with the assistant's name
|
|
11
|
-
*
|
|
12
|
+
* as one card, titled with the assistant's name, with the form of every scope
|
|
13
|
+
* its parts name. The core's `assistant-policy` scope (whether people may use
|
|
14
|
+
* their own models) joins that card whenever there is one, so no layer has to
|
|
15
|
+
* contribute it. Models are chosen in Settings › Harness. Owners edit;
|
|
16
|
+
* everyone else reads.
|
|
12
17
|
*/
|
|
13
18
|
const ROUTE = '/settings/agents'
|
|
14
19
|
const ASSISTANT = 'assistant'
|
|
20
|
+
const ASSISTANT_POLICY = 'assistant-policy'
|
|
15
21
|
|
|
16
22
|
const { t } = useCoreI18n()
|
|
17
23
|
useHead({ title: () => t('core.agents.title') })
|
|
@@ -28,13 +34,37 @@ const onPage = computed(() =>
|
|
|
28
34
|
)
|
|
29
35
|
const isAssistant = (section: AppShellSettingsSection) => section.role === ASSISTANT || section.scope === ASSISTANT
|
|
30
36
|
const assistantParts = computed(() => onPage.value.filter(isAssistant))
|
|
31
|
-
//
|
|
37
|
+
// Every scope of the parts once, in their order, then the policy; the first is the card's own form.
|
|
38
|
+
const assistantScopes = computed(() => [
|
|
39
|
+
...new Set([...assistantParts.value.flatMap(part => (part.scope ? [part.scope] : [])), ASSISTANT_POLICY]),
|
|
40
|
+
])
|
|
41
|
+
|
|
42
|
+
// Unsaved state per form on the page (one card's form under its role or scope, further scope forms under their
|
|
43
|
+
// scope), so the leave guard asks once for all of them.
|
|
44
|
+
const sectionDirty = reactive<Record<string, boolean>>({})
|
|
45
|
+
useLeaveGuard(computed(() => Object.values(sectionDirty).some(Boolean)))
|
|
46
|
+
|
|
47
|
+
// The forms of the further scopes, then the parts' own components, one after another; its own computed, so a new
|
|
48
|
+
// name does not remount them.
|
|
32
49
|
const assistantComponent = computed(() => {
|
|
50
|
+
const moreScopes = assistantScopes.value.slice(1)
|
|
33
51
|
const components = assistantParts.value.flatMap(part => (part.component ? [part.component] : []))
|
|
34
|
-
if (components.length < 2) return components[0]
|
|
52
|
+
if (moreScopes.length === 0 && components.length < 2) return components[0]
|
|
35
53
|
return defineComponent({
|
|
36
54
|
name: 'AssistantSectionParts',
|
|
37
|
-
setup: () => () =>
|
|
55
|
+
setup: () => () => [
|
|
56
|
+
...moreScopes.map(scope =>
|
|
57
|
+
h(SettingsScopeForm, {
|
|
58
|
+
key: scope,
|
|
59
|
+
scope,
|
|
60
|
+
readOnly: !canEdit.value,
|
|
61
|
+
onDirty: (value: boolean) => {
|
|
62
|
+
sectionDirty[scope] = value
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
),
|
|
66
|
+
...components.map(component => h(component)),
|
|
67
|
+
],
|
|
38
68
|
})
|
|
39
69
|
})
|
|
40
70
|
|
|
@@ -46,7 +76,7 @@ const sections = computed<AppShellSettingsSection[]>(() => {
|
|
|
46
76
|
title: account.value?.name ?? parts[0]!.title,
|
|
47
77
|
order: parts[0]!.order,
|
|
48
78
|
role: parts.find(part => part.role)?.role,
|
|
49
|
-
scope:
|
|
79
|
+
scope: assistantScopes.value[0],
|
|
50
80
|
component: assistantComponent.value,
|
|
51
81
|
}
|
|
52
82
|
return [assistant, ...onPage.value.filter(section => !isAssistant(section))].sort((a, b) => a.order - b.order)
|
|
@@ -54,9 +84,6 @@ const sections = computed<AppShellSettingsSection[]>(() => {
|
|
|
54
84
|
|
|
55
85
|
const { data: status } = await useAsyncData('ai:status', () => actions.call('ai.status', {}))
|
|
56
86
|
const statusOf = (roleId?: string) => (roleId ? status.value?.roles.find(role => role.id === roleId) : undefined)
|
|
57
|
-
|
|
58
|
-
const sectionDirty = reactive<Record<string, boolean>>({})
|
|
59
|
-
useLeaveGuard(computed(() => Object.values(sectionDirty).some(Boolean)))
|
|
60
87
|
</script>
|
|
61
88
|
|
|
62
89
|
<template>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skaile/forge-layer-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Nuxt layer every app built on forge-template-app (and forge-template-mobile) stands on: sign-in, principals and API tokens, settings, the server-action catalogue with /api/actions and /mcp, the data model, AI model roles and providers, the assistant's account, engines and definition, the database with its core migrations, and the generic settings and form UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -4,17 +4,24 @@ import type { AssistantAccount } from '../assistant/account'
|
|
|
4
4
|
import { BYOK_PRESETS, getAssistantAccount, updateAssistantAccount } from '../assistant/account'
|
|
5
5
|
import { ASSISTANT_MODES, assistantModes, effectiveAssistantMode } from '../assistant/engines'
|
|
6
6
|
import { assistantName } from '../assistant/name'
|
|
7
|
+
// Importing the policy declares its scope, so `settings.get`/`settings.update` know "assistant-policy".
|
|
8
|
+
import { ownModelsAllowed } from '../assistant/policy'
|
|
9
|
+
import { useCoreServerI18n } from '../i18n'
|
|
7
10
|
import type { Principal } from '../principal'
|
|
8
11
|
import { defineAppAction } from './define'
|
|
9
12
|
|
|
10
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* What both actions answer: the account without its key, the modes, the engine a new conversation
|
|
15
|
+
* uses, and whether the app lets people choose their own model (`ownModels`).
|
|
16
|
+
*/
|
|
11
17
|
async function accountView(principal: Principal, account: AssistantAccount) {
|
|
12
|
-
const [name, modes, effectiveMode] = await Promise.all([
|
|
18
|
+
const [name, modes, effectiveMode, ownModels] = await Promise.all([
|
|
13
19
|
assistantName(),
|
|
14
20
|
assistantModes(principal),
|
|
15
21
|
effectiveAssistantMode(principal),
|
|
22
|
+
ownModelsAllowed(),
|
|
16
23
|
])
|
|
17
|
-
return { name, mode: account.mode, effectiveMode, modes, byok: account.byok }
|
|
24
|
+
return { name, mode: account.mode, effectiveMode, modes, byok: account.byok, ownModels }
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
export const assistantActions = [
|
|
@@ -23,7 +30,7 @@ export const assistantActions = [
|
|
|
23
30
|
kind: 'query',
|
|
24
31
|
audience: ['user'],
|
|
25
32
|
description:
|
|
26
|
-
"Your assistant account: the assistant's name, the mode you chose (skaile, byok
|
|
33
|
+
"Your assistant account: the assistant's name, the mode you chose (skaile = the app's model, byok = your own key, null = not chosen), the engine new conversations use, every engine with whether it is installed and available to you, whether the app allows own models (ownModels), and your own-key provider, model and base URL (whether a key is stored, never the key).",
|
|
27
34
|
input: z.object({}).strict(),
|
|
28
35
|
authorize: (_input, ctx) => {
|
|
29
36
|
if (ctx.principal.kind === 'system')
|
|
@@ -39,7 +46,7 @@ export const assistantActions = [
|
|
|
39
46
|
idempotent: true,
|
|
40
47
|
audience: ['user'],
|
|
41
48
|
description:
|
|
42
|
-
|
|
49
|
+
"Change your assistant account: mode (skaile = the app's model, byok = your own key, or null to let the app pick), your own-key provider, model, base URL (openai-compatible only) and key, or clearKey to remove the stored key. Mode byok and own-key changes are refused while the app does not allow own models (ownModels in assistant.account.get); clearKey always works. Changing provider or base URL without a new key removes the stored key. Returns the account like assistant.account.get.",
|
|
43
50
|
input: z
|
|
44
51
|
.object({
|
|
45
52
|
mode: z.enum(ASSISTANT_MODES).nullable().optional().describe('skaile, byok, or null to let the app pick'),
|
|
@@ -65,9 +72,13 @@ export const assistantActions = [
|
|
|
65
72
|
throw createError({ statusCode: 403, statusMessage: 'The system principal has no assistant account' })
|
|
66
73
|
},
|
|
67
74
|
run: async (input, ctx) => {
|
|
75
|
+
if ((input.mode === 'byok' || input.byok) && !(await ownModelsAllowed()))
|
|
76
|
+
throw createError({ statusCode: 403, statusMessage: useCoreServerI18n().t('core.assistant.ownModelsOff') })
|
|
68
77
|
if (input.mode) {
|
|
69
|
-
const
|
|
70
|
-
|
|
78
|
+
const modes = await assistantModes(ctx.principal)
|
|
79
|
+
const installed = (mode: string) => modes.some(entry => entry.mode === mode && entry.installed)
|
|
80
|
+
// An own key runs the SKAILE agent, so `byok` needs either engine; the plain chat engine is only its fallback.
|
|
81
|
+
if (!(installed(input.mode) || (input.mode === 'byok' && installed('skaile'))))
|
|
71
82
|
throw createError({
|
|
72
83
|
statusCode: 400,
|
|
73
84
|
statusMessage: `The assistant mode ${input.mode} is not installed in this app`,
|
|
@@ -8,6 +8,7 @@ import { assistantAccounts } from '../../db/schema'
|
|
|
8
8
|
import { useDb } from '../db'
|
|
9
9
|
import { useCoreServerI18n } from '../i18n'
|
|
10
10
|
import type { AssistantMode } from './engines'
|
|
11
|
+
import { ownModelsAllowed } from './policy'
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* A person's assistant account (Settings › Profile): the mode they chose and,
|
|
@@ -20,8 +21,9 @@ export type ByokPreset = 'anthropic' | 'openai' | 'openrouter' | 'openai-compati
|
|
|
20
21
|
|
|
21
22
|
export const BYOK_PRESETS: readonly ByokPreset[] = ['anthropic', 'openai', 'openrouter', 'openai-compatible']
|
|
22
23
|
|
|
23
|
-
/** Base URL of
|
|
24
|
+
/** Base URL of each preset; `openai-compatible` brings its own. */
|
|
24
25
|
const PRESET_BASE_URLS: Partial<Record<ByokPreset, string>> = {
|
|
26
|
+
anthropic: 'https://api.anthropic.com',
|
|
25
27
|
openai: 'https://api.openai.com/v1',
|
|
26
28
|
openrouter: 'https://openrouter.ai/api/v1',
|
|
27
29
|
}
|
|
@@ -32,6 +34,17 @@ export interface AssistantAccount {
|
|
|
32
34
|
byok: { preset: ByokPreset | null; model: string | null; baseUrl: string | null; hasKey: boolean }
|
|
33
35
|
}
|
|
34
36
|
|
|
37
|
+
/** A person's own model, ready to call. Server only: it carries the unsealed key. */
|
|
38
|
+
export interface PersonalModel {
|
|
39
|
+
preset: ByokPreset
|
|
40
|
+
/** Provider model id as the person typed it. */
|
|
41
|
+
model: string
|
|
42
|
+
/** Absolute base URL of the provider's API (the preset's, or the person's for `openai-compatible`). */
|
|
43
|
+
baseUrl: string
|
|
44
|
+
/** Unsealed key. Never log, return or persist it. */
|
|
45
|
+
apiKey: string
|
|
46
|
+
}
|
|
47
|
+
|
|
35
48
|
/** The person cannot use `byok` yet; `reason` says what to set in Settings › Profile and never carries a key. */
|
|
36
49
|
export class AssistantNotConfigured extends Error {
|
|
37
50
|
constructor(
|
|
@@ -134,13 +147,18 @@ export async function updateAssistantAccount(
|
|
|
134
147
|
return toAccount(row)
|
|
135
148
|
}
|
|
136
149
|
|
|
137
|
-
/**
|
|
138
|
-
|
|
139
|
-
|
|
150
|
+
/**
|
|
151
|
+
* The stored own model, whatever mode the person chose. Throws AssistantNotConfigured naming what is
|
|
152
|
+
* missing, so the `byok` engine can tell the person what to set.
|
|
153
|
+
*/
|
|
154
|
+
function storedModel(row: typeof assistantAccounts.$inferSelect | undefined): PersonalModel {
|
|
140
155
|
const preset = row?.byokPreset
|
|
141
156
|
if (!preset || !row.byokModel)
|
|
142
157
|
throw new AssistantNotConfigured('Choose a provider and model for your own key in Settings › Profile.')
|
|
143
158
|
if (!row.byokKeySealed) throw new AssistantNotConfigured('Enter your API key in Settings › Profile.')
|
|
159
|
+
const baseUrl = PRESET_BASE_URLS[preset] ?? row.byokBaseUrl
|
|
160
|
+
if (!baseUrl)
|
|
161
|
+
throw new AssistantNotConfigured('Enter the base URL of your OpenAI-compatible provider in Settings › Profile.')
|
|
144
162
|
let apiKey: string
|
|
145
163
|
try {
|
|
146
164
|
apiKey = unseal(row.byokKeySealed)
|
|
@@ -150,9 +168,35 @@ export async function byokLanguageModel(userId: string): Promise<LanguageModel>
|
|
|
150
168
|
{ cause: error },
|
|
151
169
|
)
|
|
152
170
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
171
|
+
return { preset, model: row.byokModel, baseUrl, apiKey }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The person's own model when it should be used: the app allows own models (`assistant-policy`), the
|
|
176
|
+
* person chose mode `byok`, and preset, model and key are stored. `null` otherwise, so the caller runs
|
|
177
|
+
* on the app's model. Read per call, so a changed account or policy needs no restart.
|
|
178
|
+
* @throws AssistantNotConfigured when the stored key cannot be unsealed (its reason is for people).
|
|
179
|
+
*/
|
|
180
|
+
export async function personalModel(userId: string): Promise<PersonalModel | null> {
|
|
181
|
+
if (!(await ownModelsAllowed())) return null
|
|
182
|
+
const row = await accountRow(userId)
|
|
183
|
+
if (row?.mode !== 'byok' || !row.byokPreset || !row.byokModel || !row.byokKeySealed) return null
|
|
184
|
+
if (row.byokPreset === 'openai-compatible' && !row.byokBaseUrl) return null
|
|
185
|
+
return storedModel(row)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The person's own model for the plain chat engine (`byok`), built per call so a changed account needs
|
|
190
|
+
* no restart. Unlike {@link personalModel} it does not ask for mode `byok`: the chat engine only runs
|
|
191
|
+
* when the SKAILE engine cannot, and then any stored key serves.
|
|
192
|
+
* @throws AssistantNotConfigured when own models are switched off or the account lacks a part.
|
|
193
|
+
*/
|
|
194
|
+
export async function byokLanguageModel(userId: string): Promise<LanguageModel> {
|
|
195
|
+
if (!(await ownModelsAllowed()))
|
|
196
|
+
throw new AssistantNotConfigured(useCoreServerI18n().t('core.assistant.ownModelsOff'))
|
|
197
|
+
const own = storedModel(await accountRow(userId))
|
|
198
|
+
if (own.preset === 'anthropic') return createAnthropic({ apiKey: own.apiKey })(own.model)
|
|
199
|
+
return createOpenAICompatible({ name: `byok-${own.preset}`, baseURL: own.baseUrl, apiKey: own.apiKey }).chatModel(
|
|
200
|
+
own.model,
|
|
201
|
+
)
|
|
158
202
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { coreMessages } from '../../../shared/messages'
|
|
2
2
|
import { useForgeServerI18n } from '../i18n'
|
|
3
3
|
import type { Principal } from '../principal'
|
|
4
|
-
import {
|
|
4
|
+
import { ownModelsAllowed } from './policy'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* The app has one assistant
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
7
|
+
* The app has one assistant, the SKAILE workspace agent (`skaile`: a
|
|
8
|
+
* `skaile serve` process per person, full access with the person's rights).
|
|
9
|
+
* It runs on the app's model, or on the person's own model when the app
|
|
10
|
+
* allows own models (`assistant-policy`) and they chose mode `byok` in
|
|
11
|
+
* Settings › Profile. Only when the SKAILE engine cannot run does an own key
|
|
12
|
+
* fall back to the plain chat engine (`byok`: the AI SDK, the open page only).
|
|
13
|
+
* The layer that implements an engine registers it from a server plugin; an
|
|
14
|
+
* engine no layer registers is not installed.
|
|
13
15
|
*/
|
|
14
16
|
|
|
15
17
|
export type AssistantMode = 'skaile' | 'byok'
|
|
@@ -70,11 +72,15 @@ export async function assistantModes(
|
|
|
70
72
|
)
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* The engine a new conversation of this person uses: `skaile` whenever it is available to them (with
|
|
77
|
+
* mode `byok` it runs on their own model), else `byok` when the app allows own models and the person
|
|
78
|
+
* can use it, else `null` (nothing usable).
|
|
79
|
+
*/
|
|
74
80
|
export async function effectiveAssistantMode(principal: Principal): Promise<AssistantMode | null> {
|
|
75
81
|
const modes = await assistantModes(principal)
|
|
76
|
-
const usable = (mode: AssistantMode
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
return
|
|
82
|
+
const usable = (mode: AssistantMode) => modes.some(entry => entry.mode === mode && entry.available)
|
|
83
|
+
if (usable('skaile')) return 'skaile'
|
|
84
|
+
if (usable('byok') && (await ownModelsAllowed())) return 'byok'
|
|
85
|
+
return null
|
|
80
86
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as z from 'zod'
|
|
2
|
+
import { coreMessages } from '../../../shared/messages'
|
|
3
|
+
import { defineSettingsScope, getSettings } from '../settings'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The owner's rules for the app's one assistant (`settings.get`/`settings.update`
|
|
7
|
+
* with `scope: "assistant-policy"`, Settings › Agents in the assistant's card).
|
|
8
|
+
* `ownModels` decides whether people may run the assistant on their own
|
|
9
|
+
* provider, model and key (Settings › Profile, mode `byok`). Off: nobody can
|
|
10
|
+
* choose it, stored keys stay stored but are ignored, and everyone's
|
|
11
|
+
* assistant runs on the app's model.
|
|
12
|
+
*/
|
|
13
|
+
export const assistantPolicy = defineSettingsScope(
|
|
14
|
+
'assistant-policy',
|
|
15
|
+
z
|
|
16
|
+
.object({
|
|
17
|
+
ownModels: z
|
|
18
|
+
.boolean()
|
|
19
|
+
.describe(
|
|
20
|
+
"People may run the assistant on their own provider, model and key (Settings › Profile). Off: everyone uses the app's model",
|
|
21
|
+
),
|
|
22
|
+
})
|
|
23
|
+
.strict(),
|
|
24
|
+
// On by default: what apps did before the switch existed.
|
|
25
|
+
{ ownModels: true },
|
|
26
|
+
{
|
|
27
|
+
label: 'Assistant: models',
|
|
28
|
+
description: 'Which models people may run the assistant on',
|
|
29
|
+
i18n: { catalogs: coreMessages, prefix: 'core.settings.assistantPolicy' },
|
|
30
|
+
},
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
/** Whether people may run the assistant on their own model (`assistant-policy.ownModels`). */
|
|
34
|
+
export async function ownModelsAllowed(): Promise<boolean> {
|
|
35
|
+
return (await getSettings(assistantPolicy)).ownModels
|
|
36
|
+
}
|
package/shared/messages/de.ts
CHANGED
|
@@ -84,6 +84,11 @@ export const de: CoreMessages = {
|
|
|
84
84
|
'core.settings.app.timezone': 'IANA-Zeitzone für Datumsangaben und Übersichten, z. B. Europe/Berlin',
|
|
85
85
|
'core.settings.app.appName.title': 'Name der App',
|
|
86
86
|
'core.settings.app.timezone.title': 'Zeitzone',
|
|
87
|
+
'core.settings.assistantPolicy.label': 'Assistent: Modelle',
|
|
88
|
+
'core.settings.assistantPolicy.description': 'Auf welchen Modellen Personen den Assistenten nutzen dürfen',
|
|
89
|
+
'core.settings.assistantPolicy.ownModels':
|
|
90
|
+
'Personen können den Assistenten im Profil mit eigenem Anbieter, Modell und Schlüssel nutzen. Aus: alle nutzen das Modell der App.',
|
|
91
|
+
'core.settings.assistantPolicy.ownModels.title': 'Eigene Modelle erlauben',
|
|
87
92
|
|
|
88
93
|
'core.agents.title': 'Agenten',
|
|
89
94
|
'core.agents.empty': 'Keine Agenten installiert',
|
|
@@ -153,14 +158,18 @@ export const de: CoreMessages = {
|
|
|
153
158
|
'core.assistant.defaultName': 'Assistent',
|
|
154
159
|
'core.assistant.description': 'Wie {name} für dich arbeitet. Nur du siehst diese Einstellungen.',
|
|
155
160
|
'core.assistant.fallbackName': 'der Assistent',
|
|
156
|
-
'core.assistant.mode': '
|
|
157
|
-
'core.assistant.mode.skaile': '
|
|
161
|
+
'core.assistant.mode': 'Modell',
|
|
162
|
+
'core.assistant.mode.skaile': 'Modell der App',
|
|
158
163
|
'core.assistant.mode.byok': 'Eigener Schlüssel',
|
|
159
164
|
'core.assistant.modeHint.skaile':
|
|
160
|
-
'
|
|
165
|
+
'Läuft auf dem Modell, das die App stellt, mit vollem Zugriff auf die App und deinen Rechten. Vor dem Löschen fragt er dich im Posteingang.',
|
|
161
166
|
'core.assistant.modeHint.byok':
|
|
167
|
+
'Derselbe Assistent läuft mit deinem eigenen Anbieter, Modell und Schlüssel: dieselben Werkzeuge, deine Rechte.',
|
|
168
|
+
'core.assistant.modeHint.byokChat':
|
|
162
169
|
'Läuft mit deinem eigenen Anbieter-Schlüssel und sieht nur die Seite, die du offen hast.',
|
|
163
170
|
'core.assistant.notInstalled': 'In dieser App nicht installiert.',
|
|
171
|
+
'core.assistant.appModelOnly': 'Der Assistent nutzt das Modell der App.',
|
|
172
|
+
'core.assistant.ownModelsOff': 'Eigene Modelle sind in dieser App ausgeschaltet.',
|
|
164
173
|
'core.assistant.provider': 'Anbieter',
|
|
165
174
|
'core.assistant.providerRequired': 'Wähle einen Anbieter',
|
|
166
175
|
'core.assistant.openaiCompatible': 'OpenAI-kompatibel',
|
package/shared/messages/en.ts
CHANGED
|
@@ -86,6 +86,11 @@ export const en = {
|
|
|
86
86
|
'core.settings.app.timezone': 'IANA time zone for dates and digests, e.g. Europe/Berlin',
|
|
87
87
|
'core.settings.app.appName.title': 'App name',
|
|
88
88
|
'core.settings.app.timezone.title': 'Time zone',
|
|
89
|
+
'core.settings.assistantPolicy.label': 'Assistant: models',
|
|
90
|
+
'core.settings.assistantPolicy.description': 'Which models people may run the assistant on',
|
|
91
|
+
'core.settings.assistantPolicy.ownModels':
|
|
92
|
+
"People can use the assistant with their own provider, model and key in their profile. Off: everyone uses the app's model.",
|
|
93
|
+
'core.settings.assistantPolicy.ownModels.title': 'Allow own models',
|
|
89
94
|
|
|
90
95
|
'core.agents.title': 'Agents',
|
|
91
96
|
'core.agents.empty': 'No agents installed',
|
|
@@ -154,12 +159,17 @@ export const en = {
|
|
|
154
159
|
'core.assistant.defaultName': 'Assistant',
|
|
155
160
|
'core.assistant.description': 'How {name} works for you. Only you see these settings.',
|
|
156
161
|
'core.assistant.fallbackName': 'the assistant',
|
|
157
|
-
'core.assistant.mode': '
|
|
158
|
-
'core.assistant.mode.skaile': '
|
|
162
|
+
'core.assistant.mode': 'Model',
|
|
163
|
+
'core.assistant.mode.skaile': "App's model",
|
|
159
164
|
'core.assistant.mode.byok': 'Own key',
|
|
160
|
-
'core.assistant.modeHint.skaile':
|
|
161
|
-
|
|
165
|
+
'core.assistant.modeHint.skaile':
|
|
166
|
+
'Runs on the model the app provides, with full access to the app and your rights. Deleting asks you first in the Inbox.',
|
|
167
|
+
'core.assistant.modeHint.byok':
|
|
168
|
+
'Runs the same assistant on your own provider, model and key: the same tools, your rights.',
|
|
169
|
+
'core.assistant.modeHint.byokChat': 'Runs on your own provider key and sees only the page you have open.',
|
|
162
170
|
'core.assistant.notInstalled': 'Not installed in this app.',
|
|
171
|
+
'core.assistant.appModelOnly': "The assistant uses the app's model.",
|
|
172
|
+
'core.assistant.ownModelsOff': 'Own models are switched off in this app.',
|
|
163
173
|
'core.assistant.provider': 'Provider',
|
|
164
174
|
'core.assistant.providerRequired': 'Pick a provider',
|
|
165
175
|
'core.assistant.openaiCompatible': 'OpenAI-compatible',
|