comfy-ts 2.11.0 → 2.13.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/README.md +1 -0
- package/dist/{LogsSt-qtFzOKpu.js → LogsSt-CUeo843w.js} +51 -7
- package/dist/LogsSt-CUeo843w.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +595 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +286 -46
- package/dist/index.d.ts +286 -46
- package/dist/index.js +591 -74
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-BK7BA2dn.js → run-serve-DlRBv_Nk.js} +738 -58
- package/dist/run-serve-DlRBv_Nk.js.map +1 -0
- package/dist/{run-tui-CQyvMf0N.js → run-tui-B5uxm2_l.js} +43 -18
- package/dist/run-tui-B5uxm2_l.js.map +1 -0
- package/dist/{schemaDrift-DjjEtwfx.js → schemaDrift-E95iTF7E.js} +473 -60
- package/dist/schemaDrift-E95iTF7E.js.map +1 -0
- package/dist/serve-web.js +710 -174
- package/dist/{state--wrz0BQc.js → state-CUp2J1Zy.js} +126 -14
- package/dist/state-CUp2J1Zy.js.map +1 -0
- package/dist/web.d.ts +286 -46
- package/dist/web.js +591 -74
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/sdk.d.ts +163 -163
- package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
- package/examples/rvion/10-anima-t2i.cflow.ts +252 -0
- package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
- package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
- package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
- package/examples/rvion/stableAudio3Prompts.ts +19 -0
- package/extra/README.md +4 -0
- package/extra/comfyui-fresh-model-lists/README.md +25 -0
- package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
- package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
- package/package.json +15 -7
- package/src/cli/draftMeta.ts +39 -0
- package/src/cli/serve/ServeApp.ts +305 -30
- package/src/cli/serve/applyVarPayload.ts +50 -22
- package/src/cli/serve/byteRange.ts +48 -0
- package/src/cli/serve/describeVar.ts +42 -6
- package/src/cli/serve/llmConfigShape.ts +51 -0
- package/src/cli/serve/llmConfigs.ts +52 -0
- package/src/cli/serve/run-serve.ts +12 -3
- package/src/cli/serve/tagList.ts +92 -0
- package/src/cli/serve/tagSource.ts +69 -0
- package/src/cli/serve/web/api.ts +72 -0
- package/src/cli/serve/web/components/App.tsx +485 -44
- package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
- package/src/cli/serve/web/components/Gallery.tsx +133 -31
- package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
- package/src/cli/serve/web/components/Icon.tsx +58 -2
- package/src/cli/serve/web/components/MenuButton.tsx +53 -0
- package/src/cli/serve/web/components/Omnibox.tsx +135 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
- package/src/cli/serve/web/components/SideMenu.tsx +414 -0
- package/src/cli/serve/web/components/TooltipLayer.tsx +46 -0
- package/src/cli/serve/web/components/VarIcon.tsx +24 -0
- package/src/cli/serve/web/components/VarsForm.tsx +223 -351
- package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
- package/src/cli/serve/web/components/controls/LorasControl.tsx +646 -317
- package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
- package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
- package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
- package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
- package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
- package/src/cli/serve/web/components/modKey.ts +2 -0
- package/src/cli/serve/web/llm.ts +23 -12
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +284 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +431 -101
- package/src/cli/serve/web/state/FormSt.ts +214 -30
- package/src/cli/serve/web/state/OmniboxSt.ts +59 -0
- package/src/cli/serve/web/state/WebSt.ts +364 -80
- package/src/cli/serve/web/state/choiceButtons.ts +61 -0
- package/src/cli/serve/web/state/draftNames.ts +16 -0
- package/src/cli/serve/web/state/draftTabs.ts +75 -0
- package/src/cli/serve/web/state/generateButton.ts +16 -0
- package/src/cli/serve/web/state/history.ts +54 -0
- package/src/cli/serve/web/state/host.ts +5 -2
- package/src/cli/serve/web/state/keptLines.ts +53 -0
- package/src/cli/serve/web/state/latentMode.ts +20 -0
- package/src/cli/serve/web/state/loraSort.ts +18 -0
- package/src/cli/serve/web/state/moduleTree.ts +2 -2
- package/src/cli/serve/web/state/omnibox.ts +133 -0
- package/src/cli/serve/web/state/payload.ts +38 -58
- package/src/cli/serve/web/state/shortcuts.ts +103 -0
- package/src/cli/serve/web/state/sizeStars.ts +31 -0
- package/src/cli/serve/web/state/stableSlots.ts +21 -0
- package/src/cli/serve/web/state/varGroups.ts +24 -0
- package/src/cli/serve/web/styles.ts +653 -154
- package/src/cli/serve/webBundle.ts +54 -10
- package/src/cli/serve/workflowTags.ts +42 -0
- package/src/cli/serve/workspaceLabels.ts +23 -0
- package/src/cli/tui/components/PickerOverlays.tsx +9 -2
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
- package/src/cli/tui/state/DraftsSt.ts +28 -8
- package/src/cli/tui/state/EditorSt.ts +1 -1
- package/src/cli/tui/state/LorasSt.ts +1 -1
- package/src/cli/tui/state/PickerSt.ts +25 -7
- package/src/cli/tui/state/SettingsSt.ts +1 -1
- package/src/cli/tui/state/TuiSt.ts +10 -0
- package/src/coreExports.ts +21 -0
- package/src/host/ComfyHost.ts +17 -2
- package/src/host/ResilientWebsocket.ts +54 -4
- package/src/host/loraInfoCache.ts +6 -0
- package/src/runner/ComfyExecution.ts +60 -0
- package/src/runner/ComfyWorkflow.ts +4 -0
- package/src/runner/ComfyWsApi.ts +2 -0
- package/src/runner/MediaImage.ts +2 -2
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
- package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
- package/src/state.ts +5 -0
- package/src/utils/copyName.ts +12 -0
- package/src/vars/ComfyVars.ts +337 -67
- package/src/vars/DefinedWorkflow.ts +47 -20
- package/src/vars/lanes.ts +238 -0
- package/src/vars/loraEntry.ts +101 -0
- package/src/vars/promptSyntax.ts +382 -0
- package/dist/LogsSt-qtFzOKpu.js.map +0 -1
- package/dist/run-serve-BK7BA2dn.js.map +0 -1
- package/dist/run-tui-CQyvMf0N.js.map +0 -1
- package/dist/schemaDrift-DjjEtwfx.js.map +0 -1
- package/dist/state--wrz0BQc.js.map +0 -1
- package/src/cli/serve/web/components/Sidebar.tsx +0 -66
package/src/cli/serve/web/llm.ts
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
// browser → an OpenAI-wire LLM.
|
|
2
|
-
// (a local box). The second http module after api.ts, and the only one that leaves
|
|
1
|
+
// browser → an OpenAI-wire LLM. Three providers: openrouter (cloud), open webui
|
|
2
|
+
// (a local box), and any openai-compatible server (llama.cpp, ollama, vllm). The second http module after api.ts, and the only one that leaves
|
|
3
3
|
// this origin. Keys are parameters, never module state: they live in localStorage
|
|
4
4
|
// (EnhancerSt) and never reach the serve process.
|
|
5
5
|
// parsing is pure and DOM-free so tests/serve-web-enhancer.test.ts covers it.
|
|
6
6
|
|
|
7
|
-
export type ProviderId = 'openrouter' | 'openwebui'
|
|
7
|
+
export type ProviderId = 'openrouter' | 'openwebui' | 'openai'
|
|
8
8
|
|
|
9
9
|
export type Endpoint = { provider: ProviderId; baseUrl: string; key: string }
|
|
10
10
|
|
|
11
11
|
export const OPENROUTER_BASE = 'https://openrouter.ai/api/v1'
|
|
12
12
|
export const OPENWEBUI_BASE = 'http://localhost:3000'
|
|
13
|
+
export const OPENAI_COMPAT_BASE = 'http://localhost:8080/v1'
|
|
13
14
|
|
|
14
15
|
export function defaultBaseUrl(provider: ProviderId): string {
|
|
15
|
-
|
|
16
|
+
if (provider === 'openrouter') return OPENROUTER_BASE
|
|
17
|
+
return provider === 'openwebui' ? OPENWEBUI_BASE : OPENAI_COMPAT_BASE
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
function trimSlash(url: string): string {
|
|
19
21
|
return url.trim().replace(/\/+$/, '')
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
/** open webui hangs its OpenAI-compatible api under /api,
|
|
23
|
-
|
|
24
|
+
/** open webui hangs its OpenAI-compatible api under /api, every other base already carries /v1 */
|
|
25
|
+
function apiBase(e: Endpoint): string {
|
|
24
26
|
const base = trimSlash(e.baseUrl) === '' ? defaultBaseUrl(e.provider) : trimSlash(e.baseUrl)
|
|
25
|
-
return e.provider === '
|
|
27
|
+
return e.provider === 'openwebui' ? `${base}/api` : base
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function modelsUrl(e: Endpoint): string {
|
|
31
|
+
return `${apiBase(e)}/models`
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
export function chatUrl(e: Endpoint): string {
|
|
29
|
-
|
|
30
|
-
return e.provider === 'openrouter' ? `${base}/chat/completions` : `${base}/api/chat/completions`
|
|
35
|
+
return `${apiBase(e)}/chat/completions`
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
/** reasoning: true = says so · false = says it cannot · null = the provider does not tell
|
|
@@ -96,10 +101,16 @@ function authHeaders(e: Endpoint): Record<string, string> {
|
|
|
96
101
|
|
|
97
102
|
export type RefineRequest = { model: string; system: string; user: string; effort: ReasoningEffort }
|
|
98
103
|
|
|
99
|
-
/** the chat body. `reasoning` rides OPENROUTER only: a local backend rejects the unknown field
|
|
100
|
-
*
|
|
104
|
+
/** the chat body. `reasoning` rides OPENROUTER only: a local backend rejects the unknown field.
|
|
105
|
+
* an openai-compatible server gets the chat template's thinking switch instead: a local thinking
|
|
106
|
+
* model left on can spend the whole budget reasoning and answer nothing */
|
|
101
107
|
export function buildRefineBody(p: RefineRequest & { provider: ProviderId }): Record<string, unknown> {
|
|
102
|
-
const reasoning =
|
|
108
|
+
const reasoning =
|
|
109
|
+
p.provider === 'openrouter' && p.effort !== 'off'
|
|
110
|
+
? { reasoning: { effort: p.effort } }
|
|
111
|
+
: p.provider === 'openai'
|
|
112
|
+
? { chat_template_kwargs: { enable_thinking: p.effort !== 'off' } }
|
|
113
|
+
: {}
|
|
103
114
|
return {
|
|
104
115
|
model: p.model,
|
|
105
116
|
stream: true,
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// the CodeMirror side of the prompt editor: colors, keys and completion, every rule taken from
|
|
2
|
+
// src/vars/promptSyntax.ts so the editor shows exactly what a run will send
|
|
3
|
+
import {
|
|
4
|
+
autocompletion,
|
|
5
|
+
type Completion,
|
|
6
|
+
type CompletionContext,
|
|
7
|
+
type CompletionResult,
|
|
8
|
+
} from '@codemirror/autocomplete'
|
|
9
|
+
import { defaultKeymap, history, historyKeymap, moveLineDown, moveLineUp } from '@codemirror/commands'
|
|
10
|
+
import { EditorSelection, Prec, StateEffect, type Extension } from '@codemirror/state'
|
|
11
|
+
import {
|
|
12
|
+
Decoration,
|
|
13
|
+
EditorView,
|
|
14
|
+
keymap,
|
|
15
|
+
placeholder,
|
|
16
|
+
ViewPlugin,
|
|
17
|
+
type Command,
|
|
18
|
+
type DecorationSet,
|
|
19
|
+
type ViewUpdate,
|
|
20
|
+
} from '@codemirror/view'
|
|
21
|
+
import type { TagHit } from 'src/cli/serve/web/api.ts'
|
|
22
|
+
import {
|
|
23
|
+
adjustWeight,
|
|
24
|
+
completionCandidates,
|
|
25
|
+
formatTag,
|
|
26
|
+
promptMarks,
|
|
27
|
+
TAG_CATEGORY_NAMES,
|
|
28
|
+
tagIssues,
|
|
29
|
+
toggleComment,
|
|
30
|
+
toggleNegative,
|
|
31
|
+
type PromptMarkKind,
|
|
32
|
+
type TextChange,
|
|
33
|
+
} from 'src/vars/promptSyntax.ts'
|
|
34
|
+
|
|
35
|
+
export const WEIGHT_STEP = 0.05
|
|
36
|
+
|
|
37
|
+
/** what the editor needs from the form, read fresh on every use: the loras change while you type */
|
|
38
|
+
export type PromptEditorCtx = {
|
|
39
|
+
weights: boolean
|
|
40
|
+
tags: { underscores: boolean; artistPrefix?: string } | null
|
|
41
|
+
searchTags: (q: string, signal: AbortSignal) => Promise<TagHit[]>
|
|
42
|
+
injected: () => { tag: string; source: string }[]
|
|
43
|
+
loraWords: () => { word: string; source: string }[]
|
|
44
|
+
/** a tag list error, or null once a query works again */
|
|
45
|
+
onTagError: (message: string | null) => void
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** dispatched when the context changed outside the document (a lora toggled): redo the marks */
|
|
49
|
+
export const refreshMarks = StateEffect.define<null>()
|
|
50
|
+
|
|
51
|
+
const MARK_CLASS: Record<PromptMarkKind, string> = {
|
|
52
|
+
comment: 'pe-comment',
|
|
53
|
+
negative: 'pe-negative',
|
|
54
|
+
'negative-dash': 'pe-negative-dash',
|
|
55
|
+
'weight-paren': 'pe-weight-paren',
|
|
56
|
+
'weight-num': 'pe-weight-num',
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function decorationsFor(view: EditorView, ctx: () => PromptEditorCtx): DecorationSet {
|
|
60
|
+
const text = view.state.doc.toString()
|
|
61
|
+
const c = ctx()
|
|
62
|
+
const ranges = promptMarks(text)
|
|
63
|
+
.filter((m) => m.to > m.from)
|
|
64
|
+
.map((m) => Decoration.mark({ class: MARK_CLASS[m.kind] }).range(m.from, m.to))
|
|
65
|
+
for (const issue of tagIssues(text, { injected: c.injected(), weights: c.weights }))
|
|
66
|
+
if (issue.to > issue.from)
|
|
67
|
+
ranges.push(
|
|
68
|
+
Decoration.mark({ class: 'pe-issue', attributes: { 'data-tip': issue.message } }).range(
|
|
69
|
+
issue.from,
|
|
70
|
+
issue.to,
|
|
71
|
+
),
|
|
72
|
+
)
|
|
73
|
+
return Decoration.set(ranges, true)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function highlighter(ctx: () => PromptEditorCtx): Extension {
|
|
77
|
+
return ViewPlugin.fromClass(
|
|
78
|
+
class {
|
|
79
|
+
decorations: DecorationSet
|
|
80
|
+
constructor(view: EditorView) {
|
|
81
|
+
this.decorations = decorationsFor(view, ctx)
|
|
82
|
+
}
|
|
83
|
+
update(u: ViewUpdate): void {
|
|
84
|
+
const refreshed = u.transactions.some((t) => t.effects.some((e) => e.is(refreshMarks)))
|
|
85
|
+
if (u.docChanged || refreshed) this.decorations = decorationsFor(u.view, ctx)
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{ decorations: (v) => v.decorations },
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function applyChanges(view: EditorView, changes: TextChange[]): boolean {
|
|
93
|
+
if (changes.length === 0) return false
|
|
94
|
+
view.dispatch({ changes, userEvent: 'input' })
|
|
95
|
+
return true
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function weightCommand(ctx: () => PromptEditorCtx, delta: number): Command {
|
|
99
|
+
return (view) => {
|
|
100
|
+
if (!ctx().weights) return false
|
|
101
|
+
const sel = view.state.selection.main
|
|
102
|
+
const r = adjustWeight(view.state.doc.toString(), sel.from, sel.to, delta)
|
|
103
|
+
if (r == null) return false
|
|
104
|
+
view.dispatch({
|
|
105
|
+
changes: r.changes,
|
|
106
|
+
selection: EditorSelection.single(r.selection.anchor, r.selection.head),
|
|
107
|
+
userEvent: 'input',
|
|
108
|
+
})
|
|
109
|
+
return true
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const lineCommand =
|
|
114
|
+
(fn: (text: string, from: number, to: number) => TextChange[]): Command =>
|
|
115
|
+
(view) => {
|
|
116
|
+
const sel = view.state.selection.main
|
|
117
|
+
return applyChanges(view, fn(view.state.doc.toString(), sel.from, sel.to))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function promptKeymap(ctx: () => PromptEditorCtx): Extension {
|
|
121
|
+
const up = weightCommand(ctx, WEIGHT_STEP)
|
|
122
|
+
const down = weightCommand(ctx, -WEIGHT_STEP)
|
|
123
|
+
const negative = lineCommand(toggleNegative)
|
|
124
|
+
return Prec.high(
|
|
125
|
+
keymap.of([
|
|
126
|
+
// ⌘↑ on macOS (⌃↑ belongs to Mission Control there), ⌃↑ elsewhere, both everywhere
|
|
127
|
+
{ key: 'Mod-ArrowUp', run: up },
|
|
128
|
+
{ key: 'Ctrl-ArrowUp', run: up },
|
|
129
|
+
{ key: 'Mod-ArrowDown', run: down },
|
|
130
|
+
{ key: 'Ctrl-ArrowDown', run: down },
|
|
131
|
+
{ key: 'Mod-/', run: lineCommand(toggleComment) },
|
|
132
|
+
{ key: 'Mod-Shift--', run: negative },
|
|
133
|
+
{ key: 'Mod-_', run: negative },
|
|
134
|
+
{ key: 'Alt-ArrowUp', run: moveLineUp },
|
|
135
|
+
{ key: 'Alt-ArrowDown', run: moveLineDown },
|
|
136
|
+
]),
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const compactCount = (n: number): string =>
|
|
141
|
+
n >= 1_000_000 ? `${(n / 1_000_000).toFixed(1)}M` : n >= 1000 ? `${Math.round(n / 1000)}k` : String(n)
|
|
142
|
+
|
|
143
|
+
/** the insert: the tag, then `, ` unless a separator already follows */
|
|
144
|
+
function applyTag(insert: string): Completion['apply'] {
|
|
145
|
+
return (view, _completion, from, to) => {
|
|
146
|
+
const next = view.state.sliceDoc(to, to + 1)
|
|
147
|
+
const tail = next === '' || next === '\n' ? ', ' : ''
|
|
148
|
+
view.dispatch({
|
|
149
|
+
changes: { from, to, insert: insert + tail },
|
|
150
|
+
selection: { anchor: from + insert.length + tail.length },
|
|
151
|
+
userEvent: 'input.complete',
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** the options for one search text: lora words containing it, then the tag list's hits. Only
|
|
157
|
+
* for a prompt that declares a tag list (v.prompt(…, { tags })): completion is opt in per
|
|
158
|
+
* workflow, the loras words included */
|
|
159
|
+
export async function optionsFor(c: PromptEditorCtx, text: string, signal: AbortSignal): Promise<Completion[]> {
|
|
160
|
+
if (c.tags == null) return []
|
|
161
|
+
const q = text.trim().toLowerCase()
|
|
162
|
+
const options: Completion[] = []
|
|
163
|
+
const seenWords = new Set<string>()
|
|
164
|
+
for (const w of c.loraWords()) {
|
|
165
|
+
const lower = w.word.toLowerCase()
|
|
166
|
+
if (seenWords.has(lower) || (q !== '' && !lower.includes(q))) continue
|
|
167
|
+
seenWords.add(lower)
|
|
168
|
+
options.push({ label: w.word, detail: w.source, type: 'lora', boost: 50, apply: applyTag(w.word) })
|
|
169
|
+
}
|
|
170
|
+
if (q === '') return options
|
|
171
|
+
const hits = await c.searchTags(text.trim(), signal)
|
|
172
|
+
c.onTagError(null)
|
|
173
|
+
hits.forEach((h, ix) => {
|
|
174
|
+
const insert = formatTag(h.name, h.category, { ...c.tags, weights: c.weights })
|
|
175
|
+
options.push({
|
|
176
|
+
label: insert,
|
|
177
|
+
detail: `${h.alias == null ? '' : `← ${h.alias} · `}${compactCount(h.count)}`,
|
|
178
|
+
type: `tag-${TAG_CATEGORY_NAMES[h.category ?? -1] ?? 'plain'}`,
|
|
179
|
+
boost: -ix,
|
|
180
|
+
apply: applyTag(insert),
|
|
181
|
+
})
|
|
182
|
+
})
|
|
183
|
+
return options
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function completionSource(ctx: () => PromptEditorCtx) {
|
|
187
|
+
return async (context: CompletionContext): Promise<CompletionResult | null> => {
|
|
188
|
+
const line = context.state.doc.lineAt(context.pos)
|
|
189
|
+
const c = ctx()
|
|
190
|
+
const abort = new AbortController()
|
|
191
|
+
context.addEventListener('abort', () => abort.abort())
|
|
192
|
+
// the whole chunk first, then its last words: the first one that finds something wins
|
|
193
|
+
for (const cand of completionCandidates(line.text, context.pos - line.from)) {
|
|
194
|
+
if (cand.text.trim().length < 2 && !context.explicit) continue
|
|
195
|
+
try {
|
|
196
|
+
const options = await optionsFor(c, cand.text, abort.signal)
|
|
197
|
+
if (options.length > 0) return { from: line.from + cand.from, options, filter: false }
|
|
198
|
+
} catch (e) {
|
|
199
|
+
if (abort.signal.aborted) return null
|
|
200
|
+
c.onTagError(e instanceof Error ? e.message : String(e))
|
|
201
|
+
return null
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return null
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const theme = EditorView.theme(
|
|
209
|
+
{
|
|
210
|
+
'&': {
|
|
211
|
+
background: 'var(--panel-2)',
|
|
212
|
+
border: '1px solid var(--border)',
|
|
213
|
+
borderRadius: '6px',
|
|
214
|
+
color: 'var(--text)',
|
|
215
|
+
fontSize: '13px',
|
|
216
|
+
},
|
|
217
|
+
'&.cm-focused': { outline: 'none', borderColor: 'var(--accent)' },
|
|
218
|
+
'.cm-scroller': {
|
|
219
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
|
|
220
|
+
lineHeight: '1.5',
|
|
221
|
+
maxHeight: '18em',
|
|
222
|
+
overflow: 'auto',
|
|
223
|
+
},
|
|
224
|
+
'.cm-content': { padding: '6px 0', caretColor: 'var(--text)' },
|
|
225
|
+
'.cm-line': { padding: '0 8px' },
|
|
226
|
+
'.cm-cursor': { borderLeftColor: 'var(--text)' },
|
|
227
|
+
'&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection': {
|
|
228
|
+
background: 'var(--accent-dim) !important',
|
|
229
|
+
},
|
|
230
|
+
'.cm-placeholder': { color: 'var(--dim)' },
|
|
231
|
+
'.pe-comment': { color: 'var(--dim)', fontStyle: 'italic' },
|
|
232
|
+
'.pe-comment *': { color: 'var(--dim)' },
|
|
233
|
+
'.pe-negative': { color: 'var(--red)' },
|
|
234
|
+
'.pe-negative-dash': { color: 'var(--red)', fontWeight: '700' },
|
|
235
|
+
'.pe-weight-paren': { opacity: '0.45' },
|
|
236
|
+
'.pe-weight-num': { color: 'var(--amber)', fontWeight: '700' },
|
|
237
|
+
'.pe-issue': { textDecoration: 'underline wavy var(--amber)', textUnderlineOffset: '3px' },
|
|
238
|
+
'.cm-tooltip.cm-tooltip-autocomplete': {
|
|
239
|
+
background: 'var(--panel)',
|
|
240
|
+
border: '1px solid var(--border)',
|
|
241
|
+
borderRadius: '6px',
|
|
242
|
+
overflow: 'hidden',
|
|
243
|
+
},
|
|
244
|
+
'.cm-tooltip-autocomplete > ul': { fontFamily: 'inherit', maxHeight: '16em' },
|
|
245
|
+
'.cm-tooltip-autocomplete > ul > li': { padding: '2px 8px', display: 'flex', gap: '10px' },
|
|
246
|
+
'.cm-tooltip-autocomplete > ul > li[aria-selected]': { background: 'var(--accent-dim)', color: '#fff' },
|
|
247
|
+
'.cm-completionDetail': { marginLeft: 'auto', color: 'var(--dim)', fontStyle: 'normal' },
|
|
248
|
+
'.cm-completionIcon': { display: 'none' },
|
|
249
|
+
'.cm-completionLabel': { whiteSpace: 'nowrap' },
|
|
250
|
+
// danbooru category colors, the ones every booru site uses
|
|
251
|
+
'.cm-completionIcon-tag-artist + .cm-completionLabel': { color: '#ff8a8b' },
|
|
252
|
+
'.cm-completionIcon-tag-copyright + .cm-completionLabel': { color: '#c797ff' },
|
|
253
|
+
'.cm-completionIcon-tag-character + .cm-completionLabel': { color: '#35c64a' },
|
|
254
|
+
'.cm-completionIcon-tag-meta + .cm-completionLabel': { color: '#ead084' },
|
|
255
|
+
'.cm-completionIcon-lora + .cm-completionLabel': { color: 'var(--accent)' },
|
|
256
|
+
},
|
|
257
|
+
{ dark: true },
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
/** ⌘⏎ is the panel's generate, from any focus: the default keymap's own ⌘⏎ is left out */
|
|
261
|
+
const baseKeymap = defaultKeymap.filter((b) => b.key !== 'Mod-Enter')
|
|
262
|
+
|
|
263
|
+
export function promptExtensions(p: {
|
|
264
|
+
ctx: () => PromptEditorCtx
|
|
265
|
+
onChange: (text: string) => void
|
|
266
|
+
/** the box never gets shorter than this, so an empty prompt still looks like a box */
|
|
267
|
+
minLines: number
|
|
268
|
+
placeholder?: string
|
|
269
|
+
}): Extension[] {
|
|
270
|
+
return [
|
|
271
|
+
EditorView.theme({ '.cm-content': { minHeight: `${p.minLines * 1.5}em` } }),
|
|
272
|
+
history(),
|
|
273
|
+
promptKeymap(p.ctx),
|
|
274
|
+
keymap.of([...baseKeymap, ...historyKeymap]),
|
|
275
|
+
EditorView.lineWrapping,
|
|
276
|
+
highlighter(p.ctx),
|
|
277
|
+
autocompletion({ override: [completionSource(p.ctx)], icons: true, activateOnTyping: true }),
|
|
278
|
+
theme,
|
|
279
|
+
placeholder(p.placeholder ?? ''),
|
|
280
|
+
EditorView.updateListener.of((u) => {
|
|
281
|
+
if (u.docChanged) p.onChange(u.state.doc.toString())
|
|
282
|
+
}),
|
|
283
|
+
]
|
|
284
|
+
}
|