@skaile/forge-layer-core 1.0.1 → 1.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.
- package/CHANGELOG.md +16 -0
- package/README.md +20 -0
- package/app/app.config.ts +3 -0
- package/app/components/AiRoleStatus.vue +31 -6
- package/app/pages/settings/profile.vue +7 -1
- package/app/types/ai.ts +6 -1
- package/package.json +3 -3
- package/server/utils/actions/ai.ts +8 -1
- package/server/utils/ai/roles.ts +114 -12
- package/shared/messages/de.ts +2 -0
- package/shared/messages/en.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @skaile/forge-layer-core
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 12d3556: Hidden fallback model for the operator: set `NUXT_AI_FALLBACK_BASE_URL` (OpenAI-compatible, default `https://openrouter.ai/api/v1`), `NUXT_AI_FALLBACK_API_KEY` and `NUXT_AI_FALLBACK_MODEL` and every `chat` and `decision` model role that resolves its model in the app answers with it when nothing else does: after the assigned model and, for chat roles, the `NUXT_AI_*` environment model, and also when the assignment is not usable (bad selector, missing or refused key). When an assigned or environment model fails before any output (an error from the provider, a stream that fails before it starts), the call runs once more on the fallback; a stream that already started and an aborted call are not retried. The fallback stays on the server: `ai.status` and the Settings pages show it as "App default model" (`source: 'fallback'`, `selector: 'app/fallback'`), also to owners, never its model, URL or key; its key cannot be referenced by a provider entry or set with `ai.env.update`. Roles registered with `sdkModel: false` (the workspace agent) are unchanged, and so is `NUXT_AI_BASE_URL`/`NUXT_AI_API_KEY`/`NUXT_AI_MODEL`.
|
|
8
|
+
|
|
9
|
+
When the fallback stands in for an assignment that is not usable, `ai.status` gives owners a new `warning` (what is wrong with the assignment, and that the app's default model answers); everyone else gets `warning: null`. `AiRoleStatus` shows it as a warning line.
|
|
10
|
+
- 12d3556: New app config option `forgeCore.palettes` (default `true`). An app with a theme of its own sets it to `false`, and Settings > Profile no longer offers the forge palette picker.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [dc30563]
|
|
15
|
+
- Updated dependencies [acac8b8]
|
|
16
|
+
- @skaile/forge-app-actions@0.6.6
|
|
17
|
+
- @skaile/forge-settings@2.3.0
|
|
18
|
+
|
|
3
19
|
## 1.0.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -54,6 +54,26 @@ is the person record. On boot the server seeds the first owner from `APP_OWNER_E
|
|
|
54
54
|
`NUXT_AUTH_RP_NAME` say otherwise (set origin and id behind a proxy). Challenges live in process memory for five
|
|
55
55
|
minutes, so several web replicas need sticky sessions.
|
|
56
56
|
|
|
57
|
+
## AI models
|
|
58
|
+
|
|
59
|
+
A model role (`registerModelRole`, `resolveRoleModel` in `server/utils/ai/roles.ts`) answers with, in this order:
|
|
60
|
+
|
|
61
|
+
1. the model an owner assigned in Settings › Harness (`<provider>/<model>` of the provider registry in
|
|
62
|
+
`AI_PROVIDERS_DIR`, default `.data/ai`; keys `AI_PROVIDER_<NAME>` or `NUXT_AI_API_KEY`),
|
|
63
|
+
2. for a `chat` role without an assignment, the environment: `NUXT_AI_BASE_URL` (OpenAI-compatible, default
|
|
64
|
+
OpenRouter), `NUXT_AI_API_KEY`, `NUXT_AI_MODEL`; shown as `env:<model>`,
|
|
65
|
+
3. the operator's hidden fallback: `NUXT_AI_FALLBACK_BASE_URL` (OpenAI-compatible, default
|
|
66
|
+
`https://openrouter.ai/api/v1`), `NUXT_AI_FALLBACK_API_KEY`, `NUXT_AI_FALLBACK_MODEL`. It also answers when an
|
|
67
|
+
assignment is not usable, for `decision` roles too, and it takes over a call to the assigned or environment model
|
|
68
|
+
that fails before any output (not after a stream started, never on abort).
|
|
69
|
+
|
|
70
|
+
The fallback stays on the server: `ai.status` and the Settings pages show it only as "App default model"
|
|
71
|
+
(`source: 'fallback'`, `selector: 'app/fallback'`), owners included. Its key is outside the registry's credential
|
|
72
|
+
policy, so no provider entry can reference it and no key list shows it. A role registered with `sdkModel: false` (a
|
|
73
|
+
runner resolves the model itself, like the workspace agent) gets it as `source: 'fallback'` without call-time
|
|
74
|
+
failover; the runner builds its config from `NUXT_AI_FALLBACK_*` itself. When the fallback stands in for a broken
|
|
75
|
+
assignment, `ai.status` gives owners (only them) a `warning` with the assignment's problem; the role stays available.
|
|
76
|
+
|
|
57
77
|
## Importing core server code
|
|
58
78
|
|
|
59
79
|
Other layers and the app's CLI and tests import through the package's `exports`, never `~~/server/...`:
|
package/app/app.config.ts
CHANGED
|
@@ -9,6 +9,9 @@ export default defineAppConfig({
|
|
|
9
9
|
/** Single texts replaced, per locale, keys namespaced by layer: `{ de: { 'core.login.submit': 'Los' } }`.
|
|
10
10
|
* Keys: each layer's `en` catalog (core: `shared/i18n/core.en.ts`). */
|
|
11
11
|
messages: {} as Partial<Record<ForgeLocale, Record<string, string>>>,
|
|
12
|
+
/** Whether Settings › Profile offers the forge palettes. An app with a theme of its own (it sets `data-palette`
|
|
13
|
+
* to its own id, as `templates/mobile` does) turns the picker off: `forgeCore: { palettes: false }`. */
|
|
14
|
+
palettes: true as boolean,
|
|
12
15
|
},
|
|
13
16
|
appShell: {
|
|
14
17
|
// The sidebar: the app's own pages, the ones people work in every day. The app and each layer
|
|
@@ -5,17 +5,24 @@ import type { AiRoleStatusView } from '../types/ai'
|
|
|
5
5
|
* What `ai.status` says about one model role. Full (an agent's card in
|
|
6
6
|
* Settings › Agents): the model that answers, why the role is unavailable and
|
|
7
7
|
* its extra checks (a CLI on PATH, a definition file). `compact` (under the
|
|
8
|
-
* role's picker in Settings › Harness): only
|
|
9
|
-
* or the reason the role cannot answer.
|
|
8
|
+
* role's picker in Settings › Harness): only a fallback in use (the
|
|
9
|
+
* environment's or the app's default model) or the reason the role cannot answer.
|
|
10
10
|
*/
|
|
11
11
|
const props = defineProps<{ status: AiRoleStatusView; compact?: boolean }>()
|
|
12
12
|
const { t } = useCoreI18n()
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const source = computed(() => props.status.model?.source)
|
|
15
|
+
const fromEnv = computed(() => source.value === 'env')
|
|
16
|
+
// The app's default model is hidden: its label is a fixed text, never a model id.
|
|
17
|
+
const appDefault = computed(() => source.value === 'fallback')
|
|
15
18
|
// The env fallback's label is `env:<model id>`; the suffix says where it comes from.
|
|
16
19
|
const modelName = computed(() =>
|
|
17
20
|
fromEnv.value ? props.status.model?.label.replace(/^env:/, '') : props.status.model?.label,
|
|
18
21
|
)
|
|
22
|
+
// Compact: "Unassigned: uses …", unless an assignment exists and the default model stands in for it.
|
|
23
|
+
const prefix = computed(() =>
|
|
24
|
+
props.compact && !props.status.assigned ? t('core.aiStatus.fallback') : t('core.aiStatus.model'),
|
|
25
|
+
)
|
|
19
26
|
</script>
|
|
20
27
|
|
|
21
28
|
<template>
|
|
@@ -24,12 +31,19 @@ const modelName = computed(() =>
|
|
|
24
31
|
:data-testid="`ai-role-status-${status.id}`"
|
|
25
32
|
>
|
|
26
33
|
<p
|
|
27
|
-
v-if="status.model && (!compact || fromEnv)"
|
|
34
|
+
v-if="status.model && (!compact || fromEnv || appDefault)"
|
|
28
35
|
class="text-muted [overflow-wrap:anywhere]"
|
|
29
36
|
:data-testid="`ai-role-model-${status.id}`"
|
|
30
37
|
>
|
|
31
|
-
{{
|
|
32
|
-
<
|
|
38
|
+
{{ prefix }}
|
|
39
|
+
<span
|
|
40
|
+
v-if="appDefault"
|
|
41
|
+
class="text-default"
|
|
42
|
+
>{{ modelName }}</span>
|
|
43
|
+
<code
|
|
44
|
+
v-else
|
|
45
|
+
class="font-mono text-default"
|
|
46
|
+
>{{ modelName }}</code>
|
|
33
47
|
<template v-if="fromEnv">
|
|
34
48
|
{{ t('core.aiStatus.fromEnv') }}
|
|
35
49
|
</template>
|
|
@@ -45,6 +59,17 @@ const modelName = computed(() =>
|
|
|
45
59
|
/>
|
|
46
60
|
<span class="min-w-0 [overflow-wrap:anywhere]">{{ status.reason }}</span>
|
|
47
61
|
</p>
|
|
62
|
+
<p
|
|
63
|
+
v-if="status.warning"
|
|
64
|
+
class="flex items-start gap-1.5 text-warning"
|
|
65
|
+
:data-testid="`ai-role-warning-${status.id}`"
|
|
66
|
+
>
|
|
67
|
+
<UIcon
|
|
68
|
+
name="i-tabler-alert-triangle"
|
|
69
|
+
class="mt-0.5 size-3.5 shrink-0"
|
|
70
|
+
/>
|
|
71
|
+
<span class="min-w-0 [overflow-wrap:anywhere]">{{ status.warning }}</span>
|
|
72
|
+
</p>
|
|
48
73
|
<ul
|
|
49
74
|
v-if="!compact && status.checks.length"
|
|
50
75
|
class="flex flex-col gap-1"
|
|
@@ -6,6 +6,9 @@ const toast = useToast()
|
|
|
6
6
|
const { t } = useCoreI18n()
|
|
7
7
|
const { data: me } = await useMe()
|
|
8
8
|
const { setColorMode, modes, palette, isDark } = useAppearance()
|
|
9
|
+
// Off in an app with a theme of its own (`appConfig.forgeCore.palettes: false`).
|
|
10
|
+
const appConfig = useAppConfig()
|
|
11
|
+
const showPalettes = computed(() => appConfig.forgeCore?.palettes !== false)
|
|
9
12
|
|
|
10
13
|
const modeItems = computed(() => modes.map(({ value, label, icon }) => ({ value, label, icon })))
|
|
11
14
|
|
|
@@ -69,7 +72,10 @@ const accountLine = computed(() =>
|
|
|
69
72
|
variant="card"
|
|
70
73
|
:legend="t('core.profile.mode')"
|
|
71
74
|
/>
|
|
72
|
-
<div
|
|
75
|
+
<div
|
|
76
|
+
v-if="showPalettes"
|
|
77
|
+
class="flex flex-col gap-2"
|
|
78
|
+
>
|
|
73
79
|
<p class="text-sm font-medium text-highlighted">
|
|
74
80
|
{{ t('core.profile.palette') }}
|
|
75
81
|
</p>
|
package/app/types/ai.ts
CHANGED
|
@@ -3,6 +3,11 @@ export interface AiRoleStatusView {
|
|
|
3
3
|
id: string
|
|
4
4
|
available: boolean
|
|
5
5
|
reason: string | null
|
|
6
|
-
model
|
|
6
|
+
/** The assigned `<provider>/<model>`, `null` without one (absent where the caller does not pass it). */
|
|
7
|
+
assigned?: string | null
|
|
8
|
+
/** Owners only: the assigned model is not usable and the app's default model answers instead; `null` otherwise. */
|
|
9
|
+
warning?: string | null
|
|
10
|
+
/** `source: 'fallback'` is the app's hidden default model: `label` is a fixed text, never its model id. */
|
|
11
|
+
model: { selector: string; label: string; source: 'registry' | 'env' | 'fallback' } | null
|
|
7
12
|
checks: { id: string; label: string; ok: boolean; detail?: string }[]
|
|
8
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skaile/forge-layer-core",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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",
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@nuxt/ui": "^4.11.1",
|
|
67
|
-
"@skaile/forge-app-actions": "^0.6.
|
|
67
|
+
"@skaile/forge-app-actions": "^0.6.6",
|
|
68
68
|
"@skaile/forge-brand": "^0.5.0",
|
|
69
69
|
"@skaile/forge-data": "^0.2.1",
|
|
70
|
-
"@skaile/forge-settings": "^2.
|
|
70
|
+
"@skaile/forge-settings": "^2.3.0",
|
|
71
71
|
"@skaile/workspaces": "^10.3.0",
|
|
72
72
|
"@vueuse/core": "^15.0.0",
|
|
73
73
|
"ai": "^7.0.0",
|
|
@@ -69,7 +69,7 @@ export const aiActions = [
|
|
|
69
69
|
kind: 'query',
|
|
70
70
|
audience: ['user'],
|
|
71
71
|
description:
|
|
72
|
-
"Per model role the app offers (e.g. the in-app assistant, the workspace agent): which model is assigned, which model answers right now (registry selector
|
|
72
|
+
"Per model role the app offers (e.g. the in-app assistant, the workspace agent): which model is assigned, which model answers right now (registry selector, the NUXT_AI_* environment fallback, or the app's default model, shown only as source 'fallback' with selector 'app/fallback'), whether the role is available and, if not, why, plus the role's extra checks. warning (owners only, else null): the assigned model is not usable and the app's default model answers instead. Readable by every signed-in person; never contains a key. Only owners get the details of a check (paths, URLs); everyone else gets its label and result.",
|
|
73
73
|
input: z.object({}).strict(),
|
|
74
74
|
authorize: (_input, ctx) => {
|
|
75
75
|
if (ctx.principal.kind !== 'user')
|
|
@@ -108,6 +108,13 @@ export const aiActions = [
|
|
|
108
108
|
// Available = a model answers and every extra check of the role passes.
|
|
109
109
|
available: !!resolved.model && !failed,
|
|
110
110
|
reason: resolved.reason ?? failure ?? null,
|
|
111
|
+
// Owners only: the assignment is broken and the app's default model answers in its place.
|
|
112
|
+
warning:
|
|
113
|
+
owner && resolved.model?.assignmentFailure
|
|
114
|
+
? useForgeServerI18n(coreMessages).t('core.aiStatus.assignmentBroken', {
|
|
115
|
+
reason: resolved.model.assignmentFailure,
|
|
116
|
+
})
|
|
117
|
+
: null,
|
|
111
118
|
checks: owner ? checks : checks.map(({ detail: _detail, ...check }) => check),
|
|
112
119
|
}
|
|
113
120
|
}),
|
package/server/utils/ai/roles.ts
CHANGED
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
resolveModelRole,
|
|
8
8
|
STANDARD_MODEL_ROLES,
|
|
9
9
|
} from '@skaile/forge-settings/server'
|
|
10
|
-
import type { LanguageModel } from 'ai'
|
|
10
|
+
import type { LanguageModel, LanguageModelMiddleware } from 'ai'
|
|
11
|
+
import { wrapLanguageModel } from 'ai'
|
|
11
12
|
import { coreMessages } from '../../../shared/messages'
|
|
12
13
|
import { useForgeServerI18n } from '../i18n'
|
|
13
14
|
import { getSettings } from '../settings'
|
|
@@ -126,11 +127,14 @@ export class RoleNotConfigured extends Error {
|
|
|
126
127
|
|
|
127
128
|
export interface ResolvedRoleModel {
|
|
128
129
|
roleId: string
|
|
129
|
-
/** `<provider>/<model>` of the registry; for the environment fallback `app/<NUXT_AI_MODEL
|
|
130
|
+
/** `<provider>/<model>` of the registry; for the environment fallback `app/<NUXT_AI_MODEL>`; for the hidden fallback always `app/fallback`. */
|
|
130
131
|
selector: string
|
|
131
|
-
/**
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Where the model comes from: the assignment in the provider registry, the `NUXT_AI_*` environment, or the
|
|
134
|
+
* operator's hidden fallback (`NUXT_AI_FALLBACK_*`), whose model, URL and key never leave the server.
|
|
135
|
+
*/
|
|
136
|
+
source: 'registry' | 'env' | 'fallback'
|
|
137
|
+
/** What answers, for people: the registry selector, `env:<model>`, or for the hidden fallback a fixed text ("App default model"). */
|
|
134
138
|
label: string
|
|
135
139
|
/** The AI SDK model, already resolved (credentials checked). */
|
|
136
140
|
languageModel: () => LanguageModel
|
|
@@ -138,6 +142,11 @@ export interface ResolvedRoleModel {
|
|
|
138
142
|
registry?: MergedAIProviderRegistry
|
|
139
143
|
/** `source: 'registry'` only: the secrets of that entry as child-process environment variables. Server side only; never serialise it. */
|
|
140
144
|
credentialEnv?: Record<string, string>
|
|
145
|
+
/**
|
|
146
|
+
* `source: 'fallback'` only: why the assigned model is not usable (the `RoleNotConfigured` reason), when the
|
|
147
|
+
* fallback stands in for an assignment. Names the assignment, never the fallback.
|
|
148
|
+
*/
|
|
149
|
+
assignmentFailure?: string
|
|
141
150
|
}
|
|
142
151
|
|
|
143
152
|
const OPENROUTER_BASE_URL = 'https://openrouter.ai/api/v1'
|
|
@@ -231,30 +240,123 @@ function resolveFromEnv(role: ModelRoleDefinition, env: Env): ResolvedRoleModel
|
|
|
231
240
|
}
|
|
232
241
|
}
|
|
233
242
|
|
|
243
|
+
/**
|
|
244
|
+
* The operator's hidden fallback: OpenAI-compatible like {@link resolveFromEnv}, from `NUXT_AI_FALLBACK_BASE_URL`
|
|
245
|
+
* (default OpenRouter), `NUXT_AI_FALLBACK_API_KEY` and `NUXT_AI_FALLBACK_MODEL`, or `null`. Hidden: its selector
|
|
246
|
+
* and label are fixed, so no model id, URL, provider name or key reaches a person. Its key is outside
|
|
247
|
+
* {@link PROVIDER_POLICY}, so no registry entry can reference it and no key listing shows it.
|
|
248
|
+
*/
|
|
249
|
+
function resolveHiddenFallback(role: ModelRoleDefinition, env: Env): ResolvedRoleModel | null {
|
|
250
|
+
const baseUrl = env.NUXT_AI_FALLBACK_BASE_URL?.trim() ?? ''
|
|
251
|
+
const apiKey = env.NUXT_AI_FALLBACK_API_KEY?.trim() ?? ''
|
|
252
|
+
const modelId = env.NUXT_AI_FALLBACK_MODEL?.trim() ?? ''
|
|
253
|
+
if (!modelId || (!apiKey && !baseUrl)) return null
|
|
254
|
+
const provider = createOpenAICompatible({
|
|
255
|
+
name: 'app-fallback',
|
|
256
|
+
baseURL: baseUrl || OPENROUTER_BASE_URL,
|
|
257
|
+
...(apiKey ? { apiKey } : {}),
|
|
258
|
+
})
|
|
259
|
+
const model = provider.chatModel(modelId)
|
|
260
|
+
return {
|
|
261
|
+
roleId: role.id,
|
|
262
|
+
selector: FALLBACK_SELECTOR,
|
|
263
|
+
source: 'fallback',
|
|
264
|
+
label: useForgeServerI18n(coreMessages).t('core.aiStatus.appDefault'),
|
|
265
|
+
languageModel: () => model,
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** The selector `ai.status` shows for the hidden fallback; never the real model. */
|
|
270
|
+
export const FALLBACK_SELECTOR = 'app/fallback'
|
|
271
|
+
|
|
272
|
+
function fallbackUsed(roleId: string, why: string): void {
|
|
273
|
+
// Never the fallback's model id, URL or key: the log says only that it answered.
|
|
274
|
+
console.warn(`[ai] model role "${roleId}": ${why}; fallback model used`)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function isAbort(error: unknown, signal: AbortSignal | undefined): boolean {
|
|
278
|
+
return signal?.aborted === true || (error instanceof Error && error.name === 'AbortError')
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* The primary model with the hidden fallback as its runtime backup: a call that fails before any output
|
|
283
|
+
* (`doGenerate` throws, `doStream` throws before it returns the stream) runs once more on the fallback. An
|
|
284
|
+
* error inside a stream that already started is not retried, and neither is an abort.
|
|
285
|
+
*/
|
|
286
|
+
function withFailover(roleId: string, primary: LanguageModel, fallback: LanguageModel): LanguageModel {
|
|
287
|
+
if (typeof primary === 'string' || typeof fallback === 'string') return primary
|
|
288
|
+
const backup = wrapLanguageModel({ model: fallback, middleware: [] })
|
|
289
|
+
const middleware: LanguageModelMiddleware = {
|
|
290
|
+
wrapGenerate: async ({ doGenerate, params }) => {
|
|
291
|
+
try {
|
|
292
|
+
return await doGenerate()
|
|
293
|
+
} catch (error) {
|
|
294
|
+
if (isAbort(error, params.abortSignal)) throw error
|
|
295
|
+
fallbackUsed(roleId, 'the model failed')
|
|
296
|
+
return backup.doGenerate(params)
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
wrapStream: async ({ doStream, params }) => {
|
|
300
|
+
try {
|
|
301
|
+
return await doStream()
|
|
302
|
+
} catch (error) {
|
|
303
|
+
if (isAbort(error, params.abortSignal)) throw error
|
|
304
|
+
fallbackUsed(roleId, 'the model failed')
|
|
305
|
+
return backup.doStream(params)
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
}
|
|
309
|
+
return wrapLanguageModel({ model: primary, middleware })
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** `primary` whose `languageModel()` fails over to `fallback` at call time. */
|
|
313
|
+
function backedBy(roleId: string, primary: ResolvedRoleModel, fallback: ResolvedRoleModel): ResolvedRoleModel {
|
|
314
|
+
let wrapped: LanguageModel | undefined
|
|
315
|
+
return {
|
|
316
|
+
...primary,
|
|
317
|
+
languageModel: () => (wrapped ??= withFailover(roleId, primary.languageModel(), fallback.languageModel())),
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
234
321
|
/**
|
|
235
322
|
* The model that serves `roleId` right now: the registry selector assigned in
|
|
236
323
|
* Settings › Harness; without one, for a `chat` role the `NUXT_AI_*` environment
|
|
237
324
|
* (so a fresh clone with only `.env` still answers). `env` is where `NUXT_AI_*`
|
|
238
325
|
* and `AI_PROVIDERS_DIR` are read (default `process.env`).
|
|
239
326
|
*
|
|
327
|
+
* The operator's hidden fallback (`NUXT_AI_FALLBACK_*`) comes last: it answers when neither the assignment nor
|
|
328
|
+
* the environment gives a usable model (also when the assignment is broken). For a role that resolves an AI SDK
|
|
329
|
+
* model in this process it also backs the primary model up at call time. A runner role (`sdkModel: false`) gets
|
|
330
|
+
* it as `source: 'fallback'` without an SDK model: the runner builds its own config from `NUXT_AI_FALLBACK_*`
|
|
331
|
+
* (`@skaile/forge-layer-workspace-agent`), so the fallback stays on the server there too.
|
|
332
|
+
*
|
|
240
333
|
* Only language-model roles (`chat`, `decision`) resolve here; the standard
|
|
241
334
|
* `image`, `tts` and `stt` roles get their resolver together with a consumer.
|
|
242
335
|
* @throws {RoleNotConfigured} the role is unknown, disabled or has no usable model.
|
|
243
336
|
*/
|
|
244
337
|
export async function resolveRoleModel(roleId: string, options: { env?: Env } = {}): Promise<ResolvedRoleModel> {
|
|
245
338
|
const env = options.env ?? process.env
|
|
246
|
-
const
|
|
339
|
+
const registered = registry.get(roleId)
|
|
340
|
+
const role = registered?.definition
|
|
247
341
|
const { t } = useForgeServerI18n(coreMessages)
|
|
248
|
-
if (!role
|
|
342
|
+
if (!role?.enabled) throw new RoleNotConfigured(roleId, t('core.aiStatus.unknownRole', { role: roleId }))
|
|
249
343
|
if (role.kind !== 'chat' && role.kind !== 'decision') {
|
|
250
344
|
throw new RoleNotConfigured(roleId, t('core.aiStatus.noConsumer', { label: role.label, kind: role.kind }))
|
|
251
345
|
}
|
|
346
|
+
const sdk = registered?.sdkModel ?? true
|
|
347
|
+
const fallback = resolveHiddenFallback(role, env)
|
|
252
348
|
const assignment = (await getSettings(aiSettings)).models[roleId]?.trim()
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (
|
|
257
|
-
|
|
349
|
+
let primary: ResolvedRoleModel | null = null
|
|
350
|
+
try {
|
|
351
|
+
if (assignment) primary = await resolveAssigned(role, assignment, env)
|
|
352
|
+
else if (role.kind === 'chat') primary = resolveFromEnv(role, env)
|
|
353
|
+
} catch (error) {
|
|
354
|
+
if (!(error instanceof RoleNotConfigured) || !fallback) throw error
|
|
355
|
+
fallbackUsed(roleId, 'the assigned model is not usable')
|
|
356
|
+
return { ...fallback, assignmentFailure: error.reason }
|
|
258
357
|
}
|
|
358
|
+
if (primary) return fallback && sdk ? backedBy(roleId, primary, fallback) : primary
|
|
359
|
+
if (fallback) return fallback
|
|
360
|
+
if (role.kind === 'chat') throw new RoleNotConfigured(roleId, t('core.aiStatus.noModelEnv', { label: role.label }))
|
|
259
361
|
throw new RoleNotConfigured(roleId, t('core.aiStatus.noModel', { label: role.label }))
|
|
260
362
|
}
|
package/shared/messages/de.ts
CHANGED
|
@@ -103,6 +103,8 @@ export const de: CoreMessages = {
|
|
|
103
103
|
'core.aiStatus.fallback': 'Nicht zugewiesen: nutzt',
|
|
104
104
|
'core.aiStatus.model': 'Modell',
|
|
105
105
|
'core.aiStatus.fromEnv': 'aus NUXT_AI_*',
|
|
106
|
+
'core.aiStatus.appDefault': 'Standardmodell der App',
|
|
107
|
+
'core.aiStatus.assignmentBroken': '{reason}. Solange antwortet das Standardmodell der App',
|
|
106
108
|
'core.aiStatus.statusCheck': 'Statusprüfung',
|
|
107
109
|
'core.aiStatus.askOwner': '{label} ist nicht eingerichtet. Frag einen Inhaber.',
|
|
108
110
|
'core.aiStatus.unknownRole': 'Die Modellrolle „{role}“ gibt es in dieser App nicht, oder sie ist ausgeschaltet',
|
package/shared/messages/en.ts
CHANGED
|
@@ -104,6 +104,8 @@ export const en = {
|
|
|
104
104
|
'core.aiStatus.fallback': 'Unassigned: uses',
|
|
105
105
|
'core.aiStatus.model': 'Model',
|
|
106
106
|
'core.aiStatus.fromEnv': 'from NUXT_AI_*',
|
|
107
|
+
'core.aiStatus.appDefault': 'App default model',
|
|
108
|
+
'core.aiStatus.assignmentBroken': "{reason}; the app's default model answers instead",
|
|
107
109
|
'core.aiStatus.statusCheck': 'Status check',
|
|
108
110
|
'core.aiStatus.askOwner': '{label} is not set up; ask an owner',
|
|
109
111
|
'core.aiStatus.unknownRole': 'The model role "{role}" does not exist or is switched off in this app',
|