reigncode-app 1.3.2
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/AGENTS.md +30 -0
- package/Dockerfile +21 -0
- package/README.md +51 -0
- package/bunfig.toml +3 -0
- package/create-effect-simplification-spec.md +515 -0
- package/e2e/AGENTS.md +226 -0
- package/e2e/actions.ts +1018 -0
- package/e2e/app/home.spec.ts +24 -0
- package/e2e/app/navigation.spec.ts +10 -0
- package/e2e/app/palette.spec.ts +20 -0
- package/e2e/app/server-default.spec.ts +58 -0
- package/e2e/app/session.spec.ts +16 -0
- package/e2e/app/titlebar-history.spec.ts +120 -0
- package/e2e/commands/input-focus.spec.ts +15 -0
- package/e2e/commands/panels.spec.ts +33 -0
- package/e2e/commands/tab-close.spec.ts +32 -0
- package/e2e/files/file-open.spec.ts +31 -0
- package/e2e/files/file-tree.spec.ts +56 -0
- package/e2e/files/file-viewer.spec.ts +156 -0
- package/e2e/fixtures.ts +154 -0
- package/e2e/models/model-picker.spec.ts +48 -0
- package/e2e/models/models-visibility.spec.ts +61 -0
- package/e2e/projects/project-edit.spec.ts +43 -0
- package/e2e/projects/projects-close.spec.ts +54 -0
- package/e2e/projects/projects-switch.spec.ts +116 -0
- package/e2e/projects/workspace-new-session.spec.ts +94 -0
- package/e2e/projects/workspaces.spec.ts +375 -0
- package/e2e/prompt/context.spec.ts +95 -0
- package/e2e/prompt/prompt-async.spec.ts +76 -0
- package/e2e/prompt/prompt-drop-file-uri.spec.ts +22 -0
- package/e2e/prompt/prompt-drop-file.spec.ts +30 -0
- package/e2e/prompt/prompt-history.spec.ts +184 -0
- package/e2e/prompt/prompt-mention.spec.ts +26 -0
- package/e2e/prompt/prompt-multiline.spec.ts +24 -0
- package/e2e/prompt/prompt-shell.spec.ts +62 -0
- package/e2e/prompt/prompt-slash-open.spec.ts +22 -0
- package/e2e/prompt/prompt-slash-share.spec.ts +64 -0
- package/e2e/prompt/prompt-slash-terminal.spec.ts +18 -0
- package/e2e/prompt/prompt.spec.ts +55 -0
- package/e2e/selectors.ts +75 -0
- package/e2e/session/session-child-navigation.spec.ts +37 -0
- package/e2e/session/session-composer-dock.spec.ts +530 -0
- package/e2e/session/session-model-persistence.spec.ts +359 -0
- package/e2e/session/session-review.spec.ts +426 -0
- package/e2e/session/session-undo-redo.spec.ts +233 -0
- package/e2e/session/session.spec.ts +174 -0
- package/e2e/settings/settings-keybinds.spec.ts +389 -0
- package/e2e/settings/settings-models.spec.ts +122 -0
- package/e2e/settings/settings-providers.spec.ts +136 -0
- package/e2e/settings/settings.spec.ts +519 -0
- package/e2e/sidebar/sidebar-popover-actions.spec.ts +118 -0
- package/e2e/sidebar/sidebar-session-links.spec.ts +30 -0
- package/e2e/sidebar/sidebar.spec.ts +40 -0
- package/e2e/status/status-popover.spec.ts +94 -0
- package/e2e/terminal/terminal-init.spec.ts +28 -0
- package/e2e/terminal/terminal-reconnect.spec.ts +46 -0
- package/e2e/terminal/terminal-tabs.spec.ts +168 -0
- package/e2e/terminal/terminal.spec.ts +18 -0
- package/e2e/thinking-level.spec.ts +25 -0
- package/e2e/tsconfig.json +9 -0
- package/e2e/utils.ts +63 -0
- package/happydom.ts +75 -0
- package/index.html +23 -0
- package/package.json +77 -0
- package/playwright.config.ts +45 -0
- package/public/_headers +17 -0
- package/public/oc-theme-preload.js +35 -0
- package/script/e2e-local.ts +180 -0
- package/src/addons/serialize.test.ts +319 -0
- package/src/addons/serialize.ts +634 -0
- package/src/app.tsx +308 -0
- package/src/components/debug-bar.tsx +443 -0
- package/src/components/dialog-connect-provider.tsx +617 -0
- package/src/components/dialog-custom-provider-form.ts +158 -0
- package/src/components/dialog-custom-provider.test.ts +80 -0
- package/src/components/dialog-custom-provider.tsx +329 -0
- package/src/components/dialog-edit-project.tsx +255 -0
- package/src/components/dialog-fork.tsx +108 -0
- package/src/components/dialog-manage-models.tsx +101 -0
- package/src/components/dialog-release-notes.tsx +144 -0
- package/src/components/dialog-select-directory.tsx +392 -0
- package/src/components/dialog-select-file.tsx +466 -0
- package/src/components/dialog-select-mcp.tsx +107 -0
- package/src/components/dialog-select-model-unpaid.tsx +137 -0
- package/src/components/dialog-select-model.tsx +220 -0
- package/src/components/dialog-select-provider.tsx +86 -0
- package/src/components/dialog-select-server.tsx +649 -0
- package/src/components/dialog-settings.tsx +73 -0
- package/src/components/file-tree.test.ts +78 -0
- package/src/components/file-tree.tsx +507 -0
- package/src/components/link.tsx +26 -0
- package/src/components/model-tooltip.tsx +91 -0
- package/src/components/prompt-input/attachments.test.ts +44 -0
- package/src/components/prompt-input/attachments.ts +201 -0
- package/src/components/prompt-input/build-request-parts.test.ts +312 -0
- package/src/components/prompt-input/build-request-parts.ts +175 -0
- package/src/components/prompt-input/context-items.tsx +88 -0
- package/src/components/prompt-input/drag-overlay.tsx +25 -0
- package/src/components/prompt-input/editor-dom.test.ts +99 -0
- package/src/components/prompt-input/editor-dom.ts +148 -0
- package/src/components/prompt-input/files.ts +66 -0
- package/src/components/prompt-input/history.test.ts +153 -0
- package/src/components/prompt-input/history.ts +256 -0
- package/src/components/prompt-input/image-attachments.tsx +58 -0
- package/src/components/prompt-input/paste.ts +24 -0
- package/src/components/prompt-input/placeholder.test.ts +48 -0
- package/src/components/prompt-input/placeholder.ts +15 -0
- package/src/components/prompt-input/slash-popover.tsx +141 -0
- package/src/components/prompt-input/submit.test.ts +346 -0
- package/src/components/prompt-input/submit.ts +579 -0
- package/src/components/prompt-input.tsx +1595 -0
- package/src/components/server/server-row.tsx +130 -0
- package/src/components/session/index.ts +5 -0
- package/src/components/session/session-context-breakdown.test.ts +61 -0
- package/src/components/session/session-context-breakdown.ts +132 -0
- package/src/components/session/session-context-format.ts +20 -0
- package/src/components/session/session-context-metrics.test.ts +101 -0
- package/src/components/session/session-context-metrics.ts +82 -0
- package/src/components/session/session-context-tab.tsx +339 -0
- package/src/components/session/session-header.tsx +486 -0
- package/src/components/session/session-new-view.tsx +91 -0
- package/src/components/session/session-sortable-tab.tsx +70 -0
- package/src/components/session/session-sortable-terminal-tab.tsx +193 -0
- package/src/components/session-context-usage.tsx +122 -0
- package/src/components/settings-general.tsx +585 -0
- package/src/components/settings-keybinds.tsx +453 -0
- package/src/components/settings-list.tsx +5 -0
- package/src/components/settings-models.tsx +137 -0
- package/src/components/settings-providers.tsx +251 -0
- package/src/components/status-popover.tsx +419 -0
- package/src/components/terminal.tsx +653 -0
- package/src/components/titlebar-history.test.ts +63 -0
- package/src/components/titlebar-history.ts +57 -0
- package/src/components/titlebar.tsx +312 -0
- package/src/constants/file-picker.ts +89 -0
- package/src/context/command-keybind.test.ts +69 -0
- package/src/context/command.test.ts +25 -0
- package/src/context/command.tsx +437 -0
- package/src/context/comments.test.ts +186 -0
- package/src/context/comments.tsx +243 -0
- package/src/context/file/content-cache.ts +88 -0
- package/src/context/file/path.test.ts +360 -0
- package/src/context/file/path.ts +151 -0
- package/src/context/file/tree-store.ts +170 -0
- package/src/context/file/types.ts +41 -0
- package/src/context/file/view-cache.ts +146 -0
- package/src/context/file/watcher.test.ts +149 -0
- package/src/context/file/watcher.ts +53 -0
- package/src/context/file-content-eviction-accounting.test.ts +65 -0
- package/src/context/file.tsx +280 -0
- package/src/context/global-sdk.tsx +232 -0
- package/src/context/global-sync/bootstrap.ts +206 -0
- package/src/context/global-sync/child-store.test.ts +38 -0
- package/src/context/global-sync/child-store.ts +281 -0
- package/src/context/global-sync/event-reducer.test.ts +552 -0
- package/src/context/global-sync/event-reducer.ts +359 -0
- package/src/context/global-sync/eviction.ts +28 -0
- package/src/context/global-sync/queue.ts +83 -0
- package/src/context/global-sync/session-cache.test.ts +102 -0
- package/src/context/global-sync/session-cache.ts +62 -0
- package/src/context/global-sync/session-load.ts +25 -0
- package/src/context/global-sync/session-prefetch.test.ts +96 -0
- package/src/context/global-sync/session-prefetch.ts +100 -0
- package/src/context/global-sync/session-trim.test.ts +59 -0
- package/src/context/global-sync/session-trim.ts +56 -0
- package/src/context/global-sync/types.ts +133 -0
- package/src/context/global-sync/utils.ts +25 -0
- package/src/context/global-sync.test.ts +122 -0
- package/src/context/global-sync.tsx +408 -0
- package/src/context/highlights.tsx +233 -0
- package/src/context/language.tsx +248 -0
- package/src/context/layout-scroll.test.ts +64 -0
- package/src/context/layout-scroll.ts +126 -0
- package/src/context/layout.test.ts +69 -0
- package/src/context/layout.tsx +937 -0
- package/src/context/local.tsx +422 -0
- package/src/context/model-variant.test.ts +86 -0
- package/src/context/model-variant.ts +52 -0
- package/src/context/models.tsx +163 -0
- package/src/context/notification.tsx +373 -0
- package/src/context/permission-auto-respond.test.ts +102 -0
- package/src/context/permission-auto-respond.ts +51 -0
- package/src/context/permission.tsx +277 -0
- package/src/context/platform.tsx +99 -0
- package/src/context/prompt.tsx +297 -0
- package/src/context/sdk.tsx +49 -0
- package/src/context/server.tsx +295 -0
- package/src/context/settings.tsx +241 -0
- package/src/context/sync-optimistic.test.ts +123 -0
- package/src/context/sync.tsx +618 -0
- package/src/context/terminal-title.ts +51 -0
- package/src/context/terminal.test.ts +82 -0
- package/src/context/terminal.tsx +437 -0
- package/src/entry.tsx +144 -0
- package/src/env.d.ts +18 -0
- package/src/hooks/use-providers.ts +44 -0
- package/src/i18n/ar.ts +855 -0
- package/src/i18n/br.ts +867 -0
- package/src/i18n/bs.ts +943 -0
- package/src/i18n/da.ts +937 -0
- package/src/i18n/de.ts +879 -0
- package/src/i18n/en.ts +948 -0
- package/src/i18n/es.ts +950 -0
- package/src/i18n/fr.ts +878 -0
- package/src/i18n/ja.ts +861 -0
- package/src/i18n/ko.ts +860 -0
- package/src/i18n/no.ts +944 -0
- package/src/i18n/parity.test.ts +32 -0
- package/src/i18n/pl.ts +865 -0
- package/src/i18n/ru.ts +946 -0
- package/src/i18n/th.ts +933 -0
- package/src/i18n/tr.ts +952 -0
- package/src/i18n/zh.ts +930 -0
- package/src/i18n/zht.ts +925 -0
- package/src/index.css +29 -0
- package/src/index.ts +6 -0
- package/src/pages/directory-layout.tsx +88 -0
- package/src/pages/error.tsx +327 -0
- package/src/pages/home.tsx +131 -0
- package/src/pages/layout/deep-links.ts +50 -0
- package/src/pages/layout/helpers.test.ts +211 -0
- package/src/pages/layout/helpers.ts +98 -0
- package/src/pages/layout/inline-editor.tsx +126 -0
- package/src/pages/layout/sidebar-items.tsx +437 -0
- package/src/pages/layout/sidebar-project.tsx +384 -0
- package/src/pages/layout/sidebar-shell.tsx +125 -0
- package/src/pages/layout/sidebar-workspace.tsx +504 -0
- package/src/pages/layout.tsx +2509 -0
- package/src/pages/session/composer/index.ts +2 -0
- package/src/pages/session/composer/session-composer-region.tsx +255 -0
- package/src/pages/session/composer/session-composer-state.test.ts +128 -0
- package/src/pages/session/composer/session-composer-state.ts +249 -0
- package/src/pages/session/composer/session-followup-dock.tsx +109 -0
- package/src/pages/session/composer/session-permission-dock.tsx +74 -0
- package/src/pages/session/composer/session-question-dock.tsx +449 -0
- package/src/pages/session/composer/session-request-tree.ts +52 -0
- package/src/pages/session/composer/session-revert-dock.tsx +99 -0
- package/src/pages/session/composer/session-todo-dock.tsx +330 -0
- package/src/pages/session/file-tab-scroll.test.ts +40 -0
- package/src/pages/session/file-tab-scroll.ts +67 -0
- package/src/pages/session/file-tabs.tsx +456 -0
- package/src/pages/session/handoff.ts +36 -0
- package/src/pages/session/helpers.test.ts +181 -0
- package/src/pages/session/helpers.ts +198 -0
- package/src/pages/session/message-gesture.test.ts +62 -0
- package/src/pages/session/message-gesture.ts +21 -0
- package/src/pages/session/message-id-from-hash.ts +6 -0
- package/src/pages/session/message-timeline.tsx +1013 -0
- package/src/pages/session/review-tab.tsx +170 -0
- package/src/pages/session/session-layout.ts +20 -0
- package/src/pages/session/session-model-helpers.test.ts +51 -0
- package/src/pages/session/session-model-helpers.ts +16 -0
- package/src/pages/session/session-side-panel.tsx +453 -0
- package/src/pages/session/terminal-label.ts +16 -0
- package/src/pages/session/terminal-panel.test.ts +25 -0
- package/src/pages/session/terminal-panel.tsx +326 -0
- package/src/pages/session/use-session-commands.tsx +495 -0
- package/src/pages/session/use-session-hash-scroll.test.ts +16 -0
- package/src/pages/session/use-session-hash-scroll.ts +197 -0
- package/src/pages/session.tsx +1841 -0
- package/src/sst-env.d.ts +12 -0
- package/src/testing/model-selection.ts +80 -0
- package/src/testing/prompt.ts +56 -0
- package/src/testing/session-composer.ts +84 -0
- package/src/testing/terminal.ts +118 -0
- package/src/theme-preload.test.ts +46 -0
- package/src/utils/agent.ts +23 -0
- package/src/utils/aim.ts +138 -0
- package/src/utils/base64.ts +10 -0
- package/src/utils/comment-note.ts +88 -0
- package/src/utils/id.ts +99 -0
- package/src/utils/notification-click.test.ts +27 -0
- package/src/utils/notification-click.ts +13 -0
- package/src/utils/persist.test.ts +115 -0
- package/src/utils/persist.ts +476 -0
- package/src/utils/prompt.test.ts +44 -0
- package/src/utils/prompt.ts +203 -0
- package/src/utils/runtime-adapters.test.ts +62 -0
- package/src/utils/runtime-adapters.ts +39 -0
- package/src/utils/same.ts +6 -0
- package/src/utils/scoped-cache.test.ts +69 -0
- package/src/utils/scoped-cache.ts +104 -0
- package/src/utils/server-errors.test.ts +131 -0
- package/src/utils/server-errors.ts +80 -0
- package/src/utils/server-health.test.ts +123 -0
- package/src/utils/server-health.ts +91 -0
- package/src/utils/server.ts +22 -0
- package/src/utils/solid-dnd.tsx +49 -0
- package/src/utils/sound.ts +117 -0
- package/src/utils/terminal-writer.test.ts +64 -0
- package/src/utils/terminal-writer.ts +65 -0
- package/src/utils/time.ts +22 -0
- package/src/utils/uuid.test.ts +78 -0
- package/src/utils/uuid.ts +12 -0
- package/src/utils/worktree.test.ts +46 -0
- package/src/utils/worktree.ts +73 -0
- package/sst-env.d.ts +10 -0
- package/tsconfig.json +26 -0
- package/vite.config.ts +15 -0
- package/vite.js +26 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { createSimpleContext } from "@reign-labs/ui/context"
|
|
2
|
+
import { base64Encode } from "@reign-labs/util/encode"
|
|
3
|
+
import { useParams } from "@solidjs/router"
|
|
4
|
+
import { batch, createEffect, createMemo, onCleanup } from "solid-js"
|
|
5
|
+
import { createStore } from "solid-js/store"
|
|
6
|
+
import { useModels } from "@/context/models"
|
|
7
|
+
import { useProviders } from "@/hooks/use-providers"
|
|
8
|
+
import { modelEnabled, modelProbe } from "@/testing/model-selection"
|
|
9
|
+
import { Persist, persisted } from "@/utils/persist"
|
|
10
|
+
import { cycleModelVariant, getConfiguredAgentVariant, resolveModelVariant } from "./model-variant"
|
|
11
|
+
import { useSDK } from "./sdk"
|
|
12
|
+
import { useSync } from "./sync"
|
|
13
|
+
|
|
14
|
+
export type ModelKey = { providerID: string; modelID: string }
|
|
15
|
+
|
|
16
|
+
type State = {
|
|
17
|
+
agent?: string
|
|
18
|
+
model?: ModelKey
|
|
19
|
+
variant?: string | null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Saved = {
|
|
23
|
+
session: Record<string, State | undefined>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const WORKSPACE_KEY = "__workspace__"
|
|
27
|
+
const handoff = new Map<string, State>()
|
|
28
|
+
|
|
29
|
+
const handoffKey = (dir: string, id: string) => `${dir}\n${id}`
|
|
30
|
+
|
|
31
|
+
const migrate = (value: unknown) => {
|
|
32
|
+
if (!value || typeof value !== "object") return { session: {} }
|
|
33
|
+
|
|
34
|
+
const item = value as {
|
|
35
|
+
session?: Record<string, State | undefined>
|
|
36
|
+
pick?: Record<string, State | undefined>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (item.session && typeof item.session === "object") return { session: item.session }
|
|
40
|
+
if (!item.pick || typeof item.pick !== "object") return { session: {} }
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
session: Object.fromEntries(Object.entries(item.pick).filter(([key]) => key !== WORKSPACE_KEY)),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const clone = (value: State | undefined) => {
|
|
48
|
+
if (!value) return undefined
|
|
49
|
+
return {
|
|
50
|
+
...value,
|
|
51
|
+
model: value.model ? { ...value.model } : undefined,
|
|
52
|
+
} satisfies State
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
|
|
56
|
+
name: "Local",
|
|
57
|
+
init: () => {
|
|
58
|
+
const params = useParams()
|
|
59
|
+
const sdk = useSDK()
|
|
60
|
+
const sync = useSync()
|
|
61
|
+
const providers = useProviders()
|
|
62
|
+
const models = useModels()
|
|
63
|
+
|
|
64
|
+
const id = createMemo(() => params.id || undefined)
|
|
65
|
+
const list = createMemo(() => sync.data.agent.filter((item) => item.mode !== "subagent" && !item.hidden))
|
|
66
|
+
const connected = createMemo(() => new Set(providers.connected().map((item) => item.id)))
|
|
67
|
+
|
|
68
|
+
const [saved, setSaved] = persisted(
|
|
69
|
+
{
|
|
70
|
+
...Persist.workspace(sdk.directory, "model-selection", ["model-selection.v1"]),
|
|
71
|
+
migrate,
|
|
72
|
+
},
|
|
73
|
+
createStore<Saved>({
|
|
74
|
+
session: {},
|
|
75
|
+
}),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const [store, setStore] = createStore<{
|
|
79
|
+
current?: string
|
|
80
|
+
draft?: State
|
|
81
|
+
last?: {
|
|
82
|
+
type: "agent" | "model" | "variant"
|
|
83
|
+
agent?: string
|
|
84
|
+
model?: ModelKey | null
|
|
85
|
+
variant?: string | null
|
|
86
|
+
}
|
|
87
|
+
}>({
|
|
88
|
+
current: list()[0]?.name,
|
|
89
|
+
draft: undefined,
|
|
90
|
+
last: undefined,
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const validModel = (model: ModelKey) => {
|
|
94
|
+
const provider = providers.all().find((item) => item.id === model.providerID)
|
|
95
|
+
return !!provider?.models[model.modelID] && connected().has(model.providerID)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const firstModel = (...items: Array<() => ModelKey | undefined>) => {
|
|
99
|
+
for (const item of items) {
|
|
100
|
+
const model = item()
|
|
101
|
+
if (!model) continue
|
|
102
|
+
if (validModel(model)) return model
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const pickAgent = (name: string | undefined) => {
|
|
107
|
+
const items = list()
|
|
108
|
+
if (items.length === 0) return undefined
|
|
109
|
+
return items.find((item) => item.name === name) ?? items[0]
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
createEffect(() => {
|
|
113
|
+
const items = list()
|
|
114
|
+
if (items.length === 0) {
|
|
115
|
+
if (store.current !== undefined) setStore("current", undefined)
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
if (items.some((item) => item.name === store.current)) return
|
|
119
|
+
setStore("current", items[0]?.name)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
const scope = createMemo<State | undefined>(() => {
|
|
123
|
+
const session = id()
|
|
124
|
+
if (!session) return store.draft
|
|
125
|
+
return saved.session[session] ?? handoff.get(handoffKey(sdk.directory, session))
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
createEffect(() => {
|
|
129
|
+
const session = id()
|
|
130
|
+
if (!session) return
|
|
131
|
+
|
|
132
|
+
const key = handoffKey(sdk.directory, session)
|
|
133
|
+
const next = handoff.get(key)
|
|
134
|
+
if (!next) return
|
|
135
|
+
if (saved.session[session] !== undefined) {
|
|
136
|
+
handoff.delete(key)
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
setSaved("session", session, clone(next))
|
|
141
|
+
handoff.delete(key)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
const configuredModel = () => {
|
|
145
|
+
if (!sync.data.config.model) return
|
|
146
|
+
const [providerID, modelID] = sync.data.config.model.split("/")
|
|
147
|
+
const model = { providerID, modelID }
|
|
148
|
+
if (validModel(model)) return model
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const recentModel = () => {
|
|
152
|
+
for (const item of models.recent.list()) {
|
|
153
|
+
if (validModel(item)) return item
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const defaultModel = () => {
|
|
158
|
+
const defaults = providers.default()
|
|
159
|
+
for (const provider of providers.connected()) {
|
|
160
|
+
const configured = defaults[provider.id]
|
|
161
|
+
if (configured) {
|
|
162
|
+
const model = { providerID: provider.id, modelID: configured }
|
|
163
|
+
if (validModel(model)) return model
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const first = Object.values(provider.models)[0]
|
|
167
|
+
if (!first) continue
|
|
168
|
+
const model = { providerID: provider.id, modelID: first.id }
|
|
169
|
+
if (validModel(model)) return model
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const fallback = createMemo<ModelKey | undefined>(() => configuredModel() ?? recentModel() ?? defaultModel())
|
|
174
|
+
|
|
175
|
+
const agent = {
|
|
176
|
+
list,
|
|
177
|
+
current() {
|
|
178
|
+
return pickAgent(scope()?.agent ?? store.current)
|
|
179
|
+
},
|
|
180
|
+
set(name: string | undefined) {
|
|
181
|
+
const item = pickAgent(name)
|
|
182
|
+
if (!item) {
|
|
183
|
+
setStore("current", undefined)
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
batch(() => {
|
|
188
|
+
setStore("current", item.name)
|
|
189
|
+
setStore("last", {
|
|
190
|
+
type: "agent",
|
|
191
|
+
agent: item.name,
|
|
192
|
+
model: item.model,
|
|
193
|
+
variant: item.variant ?? null,
|
|
194
|
+
})
|
|
195
|
+
const prev = scope()
|
|
196
|
+
const next = {
|
|
197
|
+
agent: item.name,
|
|
198
|
+
model: item.model ?? prev?.model,
|
|
199
|
+
variant: item.variant ?? prev?.variant,
|
|
200
|
+
} satisfies State
|
|
201
|
+
const session = id()
|
|
202
|
+
if (session) {
|
|
203
|
+
setSaved("session", session, next)
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
setStore("draft", next)
|
|
207
|
+
})
|
|
208
|
+
},
|
|
209
|
+
move(direction: 1 | -1) {
|
|
210
|
+
const items = list()
|
|
211
|
+
if (items.length === 0) {
|
|
212
|
+
setStore("current", undefined)
|
|
213
|
+
return
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let next = items.findIndex((item) => item.name === agent.current()?.name) + direction
|
|
217
|
+
if (next < 0) next = items.length - 1
|
|
218
|
+
if (next >= items.length) next = 0
|
|
219
|
+
const item = items[next]
|
|
220
|
+
if (!item) return
|
|
221
|
+
agent.set(item.name)
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const current = () => {
|
|
226
|
+
const item = firstModel(
|
|
227
|
+
() => scope()?.model,
|
|
228
|
+
() => agent.current()?.model,
|
|
229
|
+
fallback,
|
|
230
|
+
)
|
|
231
|
+
if (!item) return undefined
|
|
232
|
+
return models.find(item)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const configured = () => {
|
|
236
|
+
const item = agent.current()
|
|
237
|
+
const model = current()
|
|
238
|
+
if (!item || !model) return undefined
|
|
239
|
+
return getConfiguredAgentVariant({
|
|
240
|
+
agent: { model: item.model, variant: item.variant },
|
|
241
|
+
model: { providerID: model.provider.id, modelID: model.id, variants: model.variants },
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const selected = () => scope()?.variant
|
|
246
|
+
|
|
247
|
+
const snapshot = () => {
|
|
248
|
+
const model = current()
|
|
249
|
+
return {
|
|
250
|
+
agent: agent.current()?.name,
|
|
251
|
+
model: model ? { providerID: model.provider.id, modelID: model.id } : undefined,
|
|
252
|
+
variant: selected(),
|
|
253
|
+
} satisfies State
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const write = (next: Partial<State>) => {
|
|
257
|
+
const state = {
|
|
258
|
+
...(scope() ?? { agent: agent.current()?.name }),
|
|
259
|
+
...next,
|
|
260
|
+
} satisfies State
|
|
261
|
+
|
|
262
|
+
const session = id()
|
|
263
|
+
if (session) {
|
|
264
|
+
setSaved("session", session, state)
|
|
265
|
+
return
|
|
266
|
+
}
|
|
267
|
+
setStore("draft", state)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const recent = createMemo(() => models.recent.list().map(models.find).filter(Boolean))
|
|
271
|
+
|
|
272
|
+
const model = {
|
|
273
|
+
ready: models.ready,
|
|
274
|
+
current,
|
|
275
|
+
recent,
|
|
276
|
+
list: models.list,
|
|
277
|
+
cycle(direction: 1 | -1) {
|
|
278
|
+
const items = recent()
|
|
279
|
+
const item = current()
|
|
280
|
+
if (!item) return
|
|
281
|
+
|
|
282
|
+
const index = items.findIndex((entry) => entry?.provider.id === item.provider.id && entry?.id === item.id)
|
|
283
|
+
if (index === -1) return
|
|
284
|
+
|
|
285
|
+
let next = index + direction
|
|
286
|
+
if (next < 0) next = items.length - 1
|
|
287
|
+
if (next >= items.length) next = 0
|
|
288
|
+
|
|
289
|
+
const entry = items[next]
|
|
290
|
+
if (!entry) return
|
|
291
|
+
model.set({ providerID: entry.provider.id, modelID: entry.id })
|
|
292
|
+
},
|
|
293
|
+
set(item: ModelKey | undefined, options?: { recent?: boolean }) {
|
|
294
|
+
batch(() => {
|
|
295
|
+
setStore("last", {
|
|
296
|
+
type: "model",
|
|
297
|
+
agent: agent.current()?.name,
|
|
298
|
+
model: item ?? null,
|
|
299
|
+
variant: selected(),
|
|
300
|
+
})
|
|
301
|
+
write({ model: item })
|
|
302
|
+
if (!item) return
|
|
303
|
+
models.setVisibility(item, true)
|
|
304
|
+
if (!options?.recent) return
|
|
305
|
+
models.recent.push(item)
|
|
306
|
+
})
|
|
307
|
+
},
|
|
308
|
+
visible(item: ModelKey) {
|
|
309
|
+
return models.visible(item)
|
|
310
|
+
},
|
|
311
|
+
setVisibility(item: ModelKey, visible: boolean) {
|
|
312
|
+
models.setVisibility(item, visible)
|
|
313
|
+
},
|
|
314
|
+
variant: {
|
|
315
|
+
configured,
|
|
316
|
+
selected,
|
|
317
|
+
current() {
|
|
318
|
+
return resolveModelVariant({
|
|
319
|
+
variants: this.list(),
|
|
320
|
+
selected: this.selected(),
|
|
321
|
+
configured: this.configured(),
|
|
322
|
+
})
|
|
323
|
+
},
|
|
324
|
+
list() {
|
|
325
|
+
const item = current()
|
|
326
|
+
if (!item?.variants) return []
|
|
327
|
+
return Object.keys(item.variants)
|
|
328
|
+
},
|
|
329
|
+
set(value: string | undefined) {
|
|
330
|
+
batch(() => {
|
|
331
|
+
const model = current()
|
|
332
|
+
setStore("last", {
|
|
333
|
+
type: "variant",
|
|
334
|
+
agent: agent.current()?.name,
|
|
335
|
+
model: model ? { providerID: model.provider.id, modelID: model.id } : null,
|
|
336
|
+
variant: value ?? null,
|
|
337
|
+
})
|
|
338
|
+
write({ variant: value ?? null })
|
|
339
|
+
})
|
|
340
|
+
},
|
|
341
|
+
cycle() {
|
|
342
|
+
const items = this.list()
|
|
343
|
+
if (items.length === 0) return
|
|
344
|
+
this.set(
|
|
345
|
+
cycleModelVariant({
|
|
346
|
+
variants: items,
|
|
347
|
+
selected: this.selected(),
|
|
348
|
+
configured: this.configured(),
|
|
349
|
+
}),
|
|
350
|
+
)
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const result = {
|
|
356
|
+
slug: createMemo(() => base64Encode(sdk.directory)),
|
|
357
|
+
model,
|
|
358
|
+
agent,
|
|
359
|
+
session: {
|
|
360
|
+
reset() {
|
|
361
|
+
setStore("draft", undefined)
|
|
362
|
+
},
|
|
363
|
+
promote(dir: string, session: string) {
|
|
364
|
+
const next = clone(snapshot())
|
|
365
|
+
if (!next) return
|
|
366
|
+
|
|
367
|
+
if (dir === sdk.directory) {
|
|
368
|
+
setSaved("session", session, next)
|
|
369
|
+
setStore("draft", undefined)
|
|
370
|
+
return
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
handoff.set(handoffKey(dir, session), next)
|
|
374
|
+
setStore("draft", undefined)
|
|
375
|
+
},
|
|
376
|
+
restore(msg: { sessionID: string; agent: string; model: ModelKey; variant?: string }) {
|
|
377
|
+
const session = id()
|
|
378
|
+
if (!session) return
|
|
379
|
+
if (msg.sessionID !== session) return
|
|
380
|
+
if (saved.session[session] !== undefined) return
|
|
381
|
+
if (handoff.has(handoffKey(sdk.directory, session))) return
|
|
382
|
+
|
|
383
|
+
setSaved("session", session, {
|
|
384
|
+
agent: msg.agent,
|
|
385
|
+
model: msg.model,
|
|
386
|
+
variant: msg.variant ?? null,
|
|
387
|
+
})
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (modelEnabled()) {
|
|
393
|
+
createEffect(() => {
|
|
394
|
+
const agent = result.agent.current()
|
|
395
|
+
const model = result.model.current()
|
|
396
|
+
modelProbe.set({
|
|
397
|
+
dir: sdk.directory,
|
|
398
|
+
sessionID: id(),
|
|
399
|
+
last: store.last,
|
|
400
|
+
agent: agent?.name,
|
|
401
|
+
model: model
|
|
402
|
+
? {
|
|
403
|
+
providerID: model.provider.id,
|
|
404
|
+
modelID: model.id,
|
|
405
|
+
name: model.name,
|
|
406
|
+
}
|
|
407
|
+
: undefined,
|
|
408
|
+
variant: result.model.variant.current() ?? null,
|
|
409
|
+
selected: result.model.variant.selected(),
|
|
410
|
+
configured: result.model.variant.configured(),
|
|
411
|
+
pick: scope(),
|
|
412
|
+
base: undefined,
|
|
413
|
+
current: store.current,
|
|
414
|
+
})
|
|
415
|
+
})
|
|
416
|
+
|
|
417
|
+
onCleanup(() => modelProbe.clear())
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return result
|
|
421
|
+
},
|
|
422
|
+
})
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { cycleModelVariant, getConfiguredAgentVariant, resolveModelVariant } from "./model-variant"
|
|
3
|
+
|
|
4
|
+
describe("model variant", () => {
|
|
5
|
+
test("resolves configured agent variant when model matches", () => {
|
|
6
|
+
const value = getConfiguredAgentVariant({
|
|
7
|
+
agent: {
|
|
8
|
+
model: { providerID: "openai", modelID: "gpt-5.2" },
|
|
9
|
+
variant: "xhigh",
|
|
10
|
+
},
|
|
11
|
+
model: {
|
|
12
|
+
providerID: "openai",
|
|
13
|
+
modelID: "gpt-5.2",
|
|
14
|
+
variants: { low: {}, high: {}, xhigh: {} },
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
expect(value).toBe("xhigh")
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test("ignores configured variant when model does not match", () => {
|
|
22
|
+
const value = getConfiguredAgentVariant({
|
|
23
|
+
agent: {
|
|
24
|
+
model: { providerID: "openai", modelID: "gpt-5.2" },
|
|
25
|
+
variant: "xhigh",
|
|
26
|
+
},
|
|
27
|
+
model: {
|
|
28
|
+
providerID: "anthropic",
|
|
29
|
+
modelID: "claude-sonnet-4",
|
|
30
|
+
variants: { low: {}, high: {}, xhigh: {} },
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
expect(value).toBeUndefined()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test("prefers selected variant over configured variant", () => {
|
|
38
|
+
const value = resolveModelVariant({
|
|
39
|
+
variants: ["low", "high", "xhigh"],
|
|
40
|
+
selected: "high",
|
|
41
|
+
configured: "xhigh",
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
expect(value).toBe("high")
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test("lets an explicit default override the configured variant", () => {
|
|
48
|
+
const value = resolveModelVariant({
|
|
49
|
+
variants: ["low", "high", "xhigh"],
|
|
50
|
+
selected: null,
|
|
51
|
+
configured: "xhigh",
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
expect(value).toBeUndefined()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test("cycles from configured variant to next", () => {
|
|
58
|
+
const value = cycleModelVariant({
|
|
59
|
+
variants: ["low", "high", "xhigh"],
|
|
60
|
+
selected: undefined,
|
|
61
|
+
configured: "high",
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
expect(value).toBe("xhigh")
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test("wraps from configured last variant to first", () => {
|
|
68
|
+
const value = cycleModelVariant({
|
|
69
|
+
variants: ["low", "high", "xhigh"],
|
|
70
|
+
selected: undefined,
|
|
71
|
+
configured: "xhigh",
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
expect(value).toBe("low")
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test("cycles from an explicit default to the first variant", () => {
|
|
78
|
+
const value = cycleModelVariant({
|
|
79
|
+
variants: ["low", "high", "xhigh"],
|
|
80
|
+
selected: null,
|
|
81
|
+
configured: "xhigh",
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
expect(value).toBe("low")
|
|
85
|
+
})
|
|
86
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
type AgentModel = {
|
|
2
|
+
providerID: string
|
|
3
|
+
modelID: string
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
type Agent = {
|
|
7
|
+
model?: AgentModel
|
|
8
|
+
variant?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type Model = AgentModel & {
|
|
12
|
+
variants?: Record<string, unknown>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type VariantInput = {
|
|
16
|
+
variants: string[]
|
|
17
|
+
selected: string | null | undefined
|
|
18
|
+
configured: string | undefined
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getConfiguredAgentVariant(input: { agent: Agent | undefined; model: Model | undefined }) {
|
|
22
|
+
if (!input.agent?.variant) return undefined
|
|
23
|
+
if (!input.agent.model) return undefined
|
|
24
|
+
if (!input.model?.variants) return undefined
|
|
25
|
+
if (input.agent.model.providerID !== input.model.providerID) return undefined
|
|
26
|
+
if (input.agent.model.modelID !== input.model.modelID) return undefined
|
|
27
|
+
if (!(input.agent.variant in input.model.variants)) return undefined
|
|
28
|
+
return input.agent.variant
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function resolveModelVariant(input: VariantInput) {
|
|
32
|
+
if (input.selected === null) return undefined
|
|
33
|
+
if (input.selected && input.variants.includes(input.selected)) return input.selected
|
|
34
|
+
if (input.configured && input.variants.includes(input.configured)) return input.configured
|
|
35
|
+
return undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function cycleModelVariant(input: VariantInput) {
|
|
39
|
+
if (input.variants.length === 0) return undefined
|
|
40
|
+
if (input.selected === null) return input.variants[0]
|
|
41
|
+
if (input.selected && input.variants.includes(input.selected)) {
|
|
42
|
+
const index = input.variants.indexOf(input.selected)
|
|
43
|
+
if (index === input.variants.length - 1) return undefined
|
|
44
|
+
return input.variants[index + 1]
|
|
45
|
+
}
|
|
46
|
+
if (input.configured && input.variants.includes(input.configured)) {
|
|
47
|
+
const index = input.variants.indexOf(input.configured)
|
|
48
|
+
if (index === input.variants.length - 1) return input.variants[0]
|
|
49
|
+
return input.variants[index + 1]
|
|
50
|
+
}
|
|
51
|
+
return input.variants[0]
|
|
52
|
+
}
|