pith-ui 0.1.4 → 0.2.0-app.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/AI.md +21 -7
- package/API.md +263 -262
- package/APP-API.md +2023 -0
- package/APP.md +141 -0
- package/README.md +35 -4
- package/dist/app/files.d.ts +68 -0
- package/dist/app/files.d.ts.map +1 -0
- package/dist/app/files.js +177 -0
- package/dist/app/files.js.map +1 -0
- package/dist/app/index.d.ts +57 -0
- package/dist/app/index.d.ts.map +1 -0
- package/dist/app/index.js +300 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/internal.d.ts +31 -0
- package/dist/app/internal.d.ts.map +1 -0
- package/dist/app/internal.js +2 -0
- package/dist/app/internal.js.map +1 -0
- package/dist/app/resources.d.ts +89 -0
- package/dist/app/resources.d.ts.map +1 -0
- package/dist/app/resources.js +190 -0
- package/dist/app/resources.js.map +1 -0
- package/dist/app/session.d.ts +14 -0
- package/dist/app/session.d.ts.map +1 -0
- package/dist/app/session.js +12 -0
- package/dist/app/session.js.map +1 -0
- package/dist/app/settings.d.ts +109 -0
- package/dist/app/settings.d.ts.map +1 -0
- package/dist/app/settings.js +283 -0
- package/dist/app/settings.js.map +1 -0
- package/dist/app/workspace.d.ts +232 -0
- package/dist/app/workspace.d.ts.map +1 -0
- package/dist/app/workspace.js +413 -0
- package/dist/app/workspace.js.map +1 -0
- package/dist/forms/actions.d.ts +1 -0
- package/dist/forms/actions.d.ts.map +1 -1
- package/dist/forms/actions.js +3 -2
- package/dist/forms/actions.js.map +1 -1
- package/dist/styles.css +4 -1
- package/dist/tasks/runtime.js +2 -2
- package/dist/tasks/runtime.js.map +1 -1
- package/package.json +42 -8
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { createResourcesPanel, createFileActions } from '../files/panels.js';
|
|
2
|
+
import { createResourceActions } from '../forms/actions.js';
|
|
3
|
+
import { createResourceEditor } from '../forms/resource-editor.js';
|
|
4
|
+
import { createOperation } from '../operation.js';
|
|
5
|
+
import { createLoadingSession } from './session.js';
|
|
6
|
+
/** Compose the existing resource views; callers never own their DOM or slots. */
|
|
7
|
+
export function createResourcesScene(env) {
|
|
8
|
+
let disposed = false;
|
|
9
|
+
let inventory;
|
|
10
|
+
let editor;
|
|
11
|
+
let loading;
|
|
12
|
+
return {
|
|
13
|
+
openEditorLoading(state, callbacks = {}) {
|
|
14
|
+
loading?.destroy();
|
|
15
|
+
loading = createLoadingSession(env, state.path ? 'Edit workspace resource' : `Create ${state.kind}`, state, callbacks.onClose);
|
|
16
|
+
if (disposed)
|
|
17
|
+
loading.destroy();
|
|
18
|
+
return loading;
|
|
19
|
+
},
|
|
20
|
+
open(initial, callbacks = {}) {
|
|
21
|
+
inventory?.destroy();
|
|
22
|
+
let state = initial, released = disposed;
|
|
23
|
+
let rendered = false;
|
|
24
|
+
let surface;
|
|
25
|
+
const owner = initial.workspace.id;
|
|
26
|
+
const rows = new Map();
|
|
27
|
+
const current = () => !disposed && !released && !!surface?.isOpen();
|
|
28
|
+
const fail = (message) => { if (current())
|
|
29
|
+
panel.setError(message); };
|
|
30
|
+
const refresh = createOperation({ unavailable: () => !current(), onError: fail });
|
|
31
|
+
const create = createOperation({ unavailable: () => !current() || !!state.busy, onPending: () => panel.setCreateDisabled(!!state.busy || create.pending), onError: fail });
|
|
32
|
+
const accept = (result) => { if (result && !result.ok)
|
|
33
|
+
fail(result.error); };
|
|
34
|
+
const panel = createResourcesPanel({
|
|
35
|
+
titleId: env.idPrefix + 'resources-title', dialogId: env.idPrefix + 'resources-dialog',
|
|
36
|
+
listId: env.idPrefix + 'resources-list', errorId: env.idPrefix + 'resources-error',
|
|
37
|
+
onClose: () => surface?.close(),
|
|
38
|
+
onRefresh: () => { if (callbacks.onRefresh)
|
|
39
|
+
refresh.run(callbacks.onRefresh, accept); },
|
|
40
|
+
onCreate: kind => { if (callbacks.onCreate)
|
|
41
|
+
create.run(() => callbacks.onCreate(kind), accept); },
|
|
42
|
+
});
|
|
43
|
+
const release = () => {
|
|
44
|
+
if (released)
|
|
45
|
+
return;
|
|
46
|
+
released = true;
|
|
47
|
+
refresh.destroy();
|
|
48
|
+
create.destroy();
|
|
49
|
+
for (const row of rows.values()) {
|
|
50
|
+
row.operation.destroy();
|
|
51
|
+
row.actions.destroy();
|
|
52
|
+
row.files?.destroy();
|
|
53
|
+
}
|
|
54
|
+
rows.clear();
|
|
55
|
+
panel.destroy();
|
|
56
|
+
};
|
|
57
|
+
panel.open(initial.workspace.name);
|
|
58
|
+
const session = {
|
|
59
|
+
read: () => state,
|
|
60
|
+
update(next) {
|
|
61
|
+
if (!current() || next.workspace.id !== owner)
|
|
62
|
+
return;
|
|
63
|
+
state = next;
|
|
64
|
+
if (next.loading && !rendered && !next.instructions.length && !next.skills.length && !next.templates.length) {
|
|
65
|
+
panel.setCreateDisabled(!!next.busy || create.pending);
|
|
66
|
+
panel.setError(next.error || '');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const keep = new Set();
|
|
70
|
+
const entries = (kind, values) => values.map(value => {
|
|
71
|
+
const key = JSON.stringify([kind, value.path]);
|
|
72
|
+
keep.add(key);
|
|
73
|
+
const target = Object.freeze({ workspaceId: owner, kind, name: value.name, path: value.path });
|
|
74
|
+
let row = rows.get(key);
|
|
75
|
+
if (!row) {
|
|
76
|
+
const actions = createResourceActions({ kind, resource: value, workspaceId: owner }, {
|
|
77
|
+
onResourceAction: action => {
|
|
78
|
+
if (!current())
|
|
79
|
+
return;
|
|
80
|
+
const target = rows.get(key).target;
|
|
81
|
+
return action === 'use-resource' ? callbacks.onUse?.(target) : callbacks.onEdit?.(target);
|
|
82
|
+
}, onError: fail,
|
|
83
|
+
});
|
|
84
|
+
const operation = createOperation({ unavailable: () => !current() || !!state.busy,
|
|
85
|
+
onPending: pending => rows.get(key)?.files?.setDisabled(!!state.busy || pending), onError: fail });
|
|
86
|
+
const files = kind === 'template' ? undefined : createFileActions({ kind: 'resource', ownerId: owner, path: value.path, copyMode: 'none', onAction: action => {
|
|
87
|
+
if (action !== 'open' && action !== 'reveal')
|
|
88
|
+
return;
|
|
89
|
+
if (callbacks.onFileAction)
|
|
90
|
+
operation.run(() => callbacks.onFileAction(action, rows.get(key).target), accept);
|
|
91
|
+
} });
|
|
92
|
+
row = { actions, files, operation, target };
|
|
93
|
+
rows.set(key, row);
|
|
94
|
+
}
|
|
95
|
+
row.target = target;
|
|
96
|
+
row.actions.update({ kind, resource: value, workspaceId: owner });
|
|
97
|
+
row.files?.setDisabled(!!state.busy || row.operation.pending);
|
|
98
|
+
return { ...value, actions: row.actions.element, fileActions: row.files?.element };
|
|
99
|
+
});
|
|
100
|
+
panel.update({ instructions: entries('instructions', next.instructions), skills: entries('skill', next.skills), templates: entries('template', next.templates), diagnostics: next.diagnostics, canCreateInstructions: next.canCreateInstructions });
|
|
101
|
+
rendered = true;
|
|
102
|
+
for (const [key, row] of rows)
|
|
103
|
+
if (!keep.has(key)) {
|
|
104
|
+
row.operation.destroy();
|
|
105
|
+
row.actions.destroy();
|
|
106
|
+
row.files?.destroy();
|
|
107
|
+
rows.delete(key);
|
|
108
|
+
}
|
|
109
|
+
panel.setCreateDisabled(!!next.busy || create.pending);
|
|
110
|
+
panel.setError(next.error || '');
|
|
111
|
+
},
|
|
112
|
+
fail,
|
|
113
|
+
close() { if (current())
|
|
114
|
+
surface.close(); },
|
|
115
|
+
isOpen: current,
|
|
116
|
+
destroy() { if (released)
|
|
117
|
+
return; if (surface?.isOpen())
|
|
118
|
+
surface.destroy(); release(); },
|
|
119
|
+
};
|
|
120
|
+
if (!disposed) {
|
|
121
|
+
surface = env.openDialog('resources', { element: panel.element, destroy: release }, () => { release(); callbacks.onClose?.(); });
|
|
122
|
+
inventory = session;
|
|
123
|
+
session.update(initial);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
released = false;
|
|
127
|
+
release();
|
|
128
|
+
}
|
|
129
|
+
return session;
|
|
130
|
+
},
|
|
131
|
+
openEditor(initial, callbacks = {}) {
|
|
132
|
+
editor?.destroy();
|
|
133
|
+
let state = initial, released = disposed;
|
|
134
|
+
let surface;
|
|
135
|
+
let saved = { name: initial.name || '', content: initial.content };
|
|
136
|
+
const identity = JSON.stringify([initial.workspaceId, initial.workspacePath, initial.kind, initial.path]);
|
|
137
|
+
const current = () => !disposed && !released && !!surface?.isOpen();
|
|
138
|
+
const fail = (message) => { if (current()) {
|
|
139
|
+
state = { ...state, error: message };
|
|
140
|
+
block.update(state);
|
|
141
|
+
} };
|
|
142
|
+
const deletion = createOperation({ unavailable: () => !current() || !!state.disabled || !state.editable || state.workspaceBusy, onError: fail });
|
|
143
|
+
const block = createResourceEditor(initial, { idPrefix: env.idPrefix,
|
|
144
|
+
onSubmit: async (draft) => {
|
|
145
|
+
saved = draft;
|
|
146
|
+
if (!current() || !callbacks.onSubmit)
|
|
147
|
+
return { ok: false, error: 'Saving is unavailable.' };
|
|
148
|
+
const result = await callbacks.onSubmit(draft);
|
|
149
|
+
if (current() && result.ok)
|
|
150
|
+
surface.close();
|
|
151
|
+
return result;
|
|
152
|
+
},
|
|
153
|
+
onDelete: () => {
|
|
154
|
+
if (!callbacks.onDelete)
|
|
155
|
+
return;
|
|
156
|
+
const target = Object.freeze({ workspaceId: state.workspaceId, kind: state.kind, name: state.name || state.path?.split('/').pop() || '', path: state.path || '' });
|
|
157
|
+
deletion.run(() => callbacks.onDelete(target), result => { if (result && !result.ok)
|
|
158
|
+
fail(result.error); });
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
const release = () => { if (released)
|
|
162
|
+
return; saved = block.read(); released = true; deletion.destroy(); block.destroy(); };
|
|
163
|
+
const session = {
|
|
164
|
+
read() { return current() ? block.read() : { ...saved }; },
|
|
165
|
+
update(next) { if (!current() || JSON.stringify([next.workspaceId, next.workspacePath, next.kind, next.path]) !== identity)
|
|
166
|
+
return; state = next; block.update(next); },
|
|
167
|
+
fail,
|
|
168
|
+
close() { if (current())
|
|
169
|
+
surface.close(); },
|
|
170
|
+
isOpen: current,
|
|
171
|
+
destroy() { if (released)
|
|
172
|
+
return; if (surface?.isOpen())
|
|
173
|
+
surface.destroy(); release(); },
|
|
174
|
+
};
|
|
175
|
+
if (!disposed) {
|
|
176
|
+
const title = !initial.editable ? 'Workspace resource' : initial.path ? 'Edit workspace resource' : `Create ${initial.kind}`;
|
|
177
|
+
surface = env.openFeature(title, { element: block.element, destroy: release }, () => { release(); callbacks.onClose?.(); });
|
|
178
|
+
editor = session;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
released = false;
|
|
182
|
+
release();
|
|
183
|
+
}
|
|
184
|
+
return session;
|
|
185
|
+
},
|
|
186
|
+
destroy() { if (disposed)
|
|
187
|
+
return; disposed = true; loading?.destroy(); inventory?.destroy(); editor?.destroy(); },
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/app/resources.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAC,qBAAqB,EAAC,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAC,oBAAoB,EAAqB,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAC,eAAe,EAAC,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAC,oBAAoB,EAAyC,MAAM,cAAc,CAAC;AA6E1F,iFAAiF;AACjF,MAAM,UAAU,oBAAoB,CAAC,GAAmB;IACtD,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,SAAuC,CAAC;IAC5C,IAAI,MAAyC,CAAC;IAC9C,IAAI,OAAmC,CAAC;IACxC,OAAO;QACL,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,EAAE;YACrC,OAAO,EAAE,OAAO,EAAE,CAAC;YACnB,OAAO,GAAG,oBAAoB,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AE,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA,CAAC,CAAC,CAAC;gBACxH,MAAM,GAAG,OAAO,CAAC;YACnB,CAAC;iBAAM,CAAC;gBAAA,QAAQ,GAAG,KAAK,CAAC;gBAAC,OAAO,EAAE,CAAC;YAAA,CAAC;YACrC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,OAAO,KAAI,IAAI,QAAQ;YAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA,CAAC;KAChH,CAAC;AACJ,CAAC","sourcesContent":["import type {ActionResult} from '../core.js';\nimport {createResourcesPanel, createFileActions} from '../files/panels.js';\nimport {createResourceActions} from '../forms/actions.js';\nimport {createResourceEditor, type ResourceDraft} from '../forms/resource-editor.js';\nimport {createOperation} from '../operation.js';\nimport type {AppEnvironment, OwnedSurface} from './internal.js';\nimport {createLoadingSession, type LoadingState, type LoadingSession} from './session.js';\n\nexport type {ResourceDraft} from '../forms/resource-editor.js';\n\nexport type AppResourceKind = 'instructions' | 'skill' | 'template';\nexport type ResourceActionResult = void | ActionResult | Promise<void | ActionResult>;\nexport interface AppResourceEntry {\n readonly name: string;\n readonly path: string;\n readonly description?: string;\n readonly content?: string;\n}\nexport interface AppResourceTarget {\n readonly workspaceId: string;\n readonly kind: AppResourceKind;\n readonly name: string;\n readonly path: string;\n}\nexport interface ResourcesState {\n readonly workspace: {readonly id: string; readonly name: string; readonly path: string};\n readonly instructions: readonly AppResourceEntry[];\n readonly skills: readonly AppResourceEntry[];\n readonly templates: readonly AppResourceEntry[];\n readonly diagnostics: readonly string[];\n readonly canCreateInstructions?: boolean;\n readonly loading?: boolean;\n readonly error?: string;\n readonly busy?: boolean;\n}\nexport interface ResourcesCallbacks {\n onRefresh?: () => ResourceActionResult;\n onCreate?: (kind: AppResourceKind) => ResourceActionResult;\n onUse?: (target: AppResourceTarget) => ResourceActionResult;\n onEdit?: (target: AppResourceTarget) => ResourceActionResult;\n onFileAction?: (action: 'open' | 'reveal', target: AppResourceTarget) => ResourceActionResult;\n onClose?: () => void;\n}\nexport interface ResourcesSession {\n read(): Readonly<ResourcesState>;\n update(state: Readonly<ResourcesState>): void;\n fail(message: string): void;\n close(): void;\n isOpen(): boolean;\n destroy(): void;\n}\nexport interface AppResourceEditorState {\n readonly workspaceId: string;\n readonly workspacePath: string;\n readonly path?: string;\n readonly kind: AppResourceKind;\n readonly name?: string;\n readonly content: string;\n readonly editable: boolean;\n readonly workspaceBusy: boolean;\n readonly error?: string;\n readonly disabled?: boolean;\n}\nexport interface ResourceEditorCallbacks {\n onSubmit?: (draft: ResourceDraft) => ActionResult | Promise<ActionResult>;\n onDelete?: (target: AppResourceTarget) => ResourceActionResult;\n onClose?: () => void;\n}\nexport interface ResourceEditorSession {\n read(): ResourceDraft;\n update(state: Readonly<AppResourceEditorState>): void;\n fail(message: string): void;\n close(): void;\n isOpen(): boolean;\n destroy(): void;\n}\nexport interface ResourcesScene {\n openEditorLoading(state: Readonly<LoadingState> & {readonly kind: AppResourceKind; readonly path?: string}, callbacks?: {onClose?: () => void}): LoadingSession;\n open(state: Readonly<ResourcesState>, callbacks?: ResourcesCallbacks): ResourcesSession;\n openEditor(state: Readonly<AppResourceEditorState>, callbacks?: ResourceEditorCallbacks): ResourceEditorSession;\n destroy(): void;\n}\n\n/** Compose the existing resource views; callers never own their DOM or slots. */\nexport function createResourcesScene(env: AppEnvironment): ResourcesScene {\n let disposed = false;\n let inventory: ResourcesSession | undefined;\n let editor: ResourceEditorSession | undefined;\n let loading: LoadingSession | undefined;\n return {\n openEditorLoading(state, callbacks = {}) {\n loading?.destroy();\n loading = createLoadingSession(env, state.path ? 'Edit workspace resource' : `Create ${state.kind}`, state, callbacks.onClose);\n if (disposed) loading.destroy();\n return loading;\n },\n open(initial, callbacks = {}) {\n inventory?.destroy();\n let state = initial, released = disposed;\n let rendered = false;\n let surface: OwnedSurface | undefined;\n const owner = initial.workspace.id;\n const rows = new Map<string, {\n actions: ReturnType<typeof createResourceActions>;\n files?: ReturnType<typeof createFileActions>;\n operation: ReturnType<typeof createOperation>;\n target: AppResourceTarget;\n }>();\n const current = () => !disposed && !released && !!surface?.isOpen();\n const fail = (message: string) => {if (current()) panel.setError(message);};\n const refresh = createOperation({unavailable: () => !current(), onError: fail});\n const create = createOperation({unavailable: () => !current() || !!state.busy, onPending: () => panel.setCreateDisabled(!!state.busy || create.pending), onError: fail});\n const accept = (result: void | ActionResult) => {if (result && !result.ok) fail(result.error);};\n const panel = createResourcesPanel({\n titleId: env.idPrefix + 'resources-title', dialogId: env.idPrefix + 'resources-dialog',\n listId: env.idPrefix + 'resources-list', errorId: env.idPrefix + 'resources-error',\n onClose: () => surface?.close(),\n onRefresh: () => {if (callbacks.onRefresh) refresh.run(callbacks.onRefresh, accept);},\n onCreate: kind => {if (callbacks.onCreate) create.run(() => callbacks.onCreate!(kind), accept);},\n });\n const release = () => {\n if (released) return;\n released = true; refresh.destroy(); create.destroy();\n for (const row of rows.values()) {row.operation.destroy(); row.actions.destroy(); row.files?.destroy();}\n rows.clear(); panel.destroy();\n };\n panel.open(initial.workspace.name);\n const session: ResourcesSession = {\n read: () => state,\n update(next) {\n if (!current() || next.workspace.id !== owner) return;\n state = next;\n if (next.loading && !rendered && !next.instructions.length && !next.skills.length && !next.templates.length) {\n panel.setCreateDisabled(!!next.busy || create.pending); panel.setError(next.error || ''); return;\n }\n const keep = new Set<string>();\n const entries = (kind: AppResourceKind, values: readonly AppResourceEntry[]) => values.map(value => {\n const key = JSON.stringify([kind, value.path]); keep.add(key);\n const target: AppResourceTarget = Object.freeze({workspaceId: owner, kind, name: value.name, path: value.path});\n let row = rows.get(key);\n if (!row) {\n const actions = createResourceActions({kind, resource: value, workspaceId: owner}, {\n onResourceAction: action => {\n if (!current()) return;\n const target = rows.get(key)!.target;\n return action === 'use-resource' ? callbacks.onUse?.(target) : callbacks.onEdit?.(target);\n }, onError: fail,\n });\n const operation = createOperation({unavailable: () => !current() || !!state.busy,\n onPending: pending => rows.get(key)?.files?.setDisabled(!!state.busy || pending), onError: fail});\n const files = kind === 'template' ? undefined : createFileActions({kind: 'resource', ownerId: owner, path: value.path, copyMode: 'none', onAction: action => {\n if (action !== 'open' && action !== 'reveal') return;\n if (callbacks.onFileAction) operation.run(() => callbacks.onFileAction!(action, rows.get(key)!.target), accept);\n }});\n row = {actions, files, operation, target}; rows.set(key, row);\n }\n row.target = target;\n row.actions.update({kind, resource: value, workspaceId: owner});\n row.files?.setDisabled(!!state.busy || row.operation.pending);\n return {...value, actions: row.actions.element, fileActions: row.files?.element};\n });\n panel.update({instructions: entries('instructions', next.instructions), skills: entries('skill', next.skills), templates: entries('template', next.templates), diagnostics: next.diagnostics, canCreateInstructions: next.canCreateInstructions});\n rendered = true;\n for (const [key, row] of rows) if (!keep.has(key)) {row.operation.destroy(); row.actions.destroy(); row.files?.destroy(); rows.delete(key);}\n panel.setCreateDisabled(!!next.busy || create.pending);\n panel.setError(next.error || '');\n },\n fail,\n close() {if (current()) surface!.close();},\n isOpen: current,\n destroy() {if (released) return; if (surface?.isOpen()) surface.destroy(); release();},\n };\n if (!disposed) {\n surface = env.openDialog('resources', {element: panel.element, destroy: release}, () => {release(); callbacks.onClose?.();});\n inventory = session; session.update(initial);\n } else {released = false; release();}\n return session;\n },\n openEditor(initial, callbacks = {}) {\n editor?.destroy();\n let state = initial, released = disposed;\n let surface: OwnedSurface | undefined;\n let saved = {name: initial.name || '', content: initial.content};\n const identity = JSON.stringify([initial.workspaceId, initial.workspacePath, initial.kind, initial.path]);\n const current = () => !disposed && !released && !!surface?.isOpen();\n const fail = (message: string) => {if (current()) {state = {...state, error: message}; block.update(state);}};\n const deletion = createOperation({unavailable: () => !current() || !!state.disabled || !state.editable || state.workspaceBusy, onError: fail});\n const block = createResourceEditor(initial, {idPrefix: env.idPrefix,\n onSubmit: async draft => {\n saved = draft;\n if (!current() || !callbacks.onSubmit) return {ok: false, error: 'Saving is unavailable.'};\n const result = await callbacks.onSubmit(draft);\n if (current() && result.ok) surface!.close();\n return result;\n },\n onDelete: () => {\n if (!callbacks.onDelete) return;\n const target = Object.freeze({workspaceId: state.workspaceId, kind: state.kind, name: state.name || state.path?.split('/').pop() || '', path: state.path || ''});\n deletion.run(() => callbacks.onDelete!(target), result => {if (result && !result.ok) fail(result.error);});\n },\n });\n const release = () => {if (released) return; saved = block.read(); released = true; deletion.destroy(); block.destroy();};\n const session: ResourceEditorSession = {\n read() {return current() ? block.read() : {...saved};},\n update(next) {if (!current() || JSON.stringify([next.workspaceId, next.workspacePath, next.kind, next.path]) !== identity) return; state = next; block.update(next);},\n fail,\n close() {if (current()) surface!.close();},\n isOpen: current,\n destroy() {if (released) return; if (surface?.isOpen()) surface.destroy(); release();},\n };\n if (!disposed) {\n const title = !initial.editable ? 'Workspace resource' : initial.path ? 'Edit workspace resource' : `Create ${initial.kind}`;\n surface = env.openFeature(title, {element: block.element, destroy: release}, () => {release(); callbacks.onClose?.();});\n editor = session;\n } else {released = false; release();}\n return session;\n },\n destroy() {if (disposed) return; disposed = true; loading?.destroy(); inventory?.destroy(); editor?.destroy();},\n };\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AppEnvironment } from './internal.js';
|
|
2
|
+
export interface LoadingState {
|
|
3
|
+
readonly error?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface LoadingSession {
|
|
6
|
+
update(state: Readonly<LoadingState>): void;
|
|
7
|
+
fail(message: string): void;
|
|
8
|
+
isOpen(): boolean;
|
|
9
|
+
close(): void;
|
|
10
|
+
destroy(): void;
|
|
11
|
+
}
|
|
12
|
+
/** Private shared implementation for the named scenes' existing loading phase. */
|
|
13
|
+
export declare function createLoadingSession(env: AppEnvironment, title: string, initial: LoadingState, onClose?: () => void): LoadingSession;
|
|
14
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/app/session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAElD,MAAM,WAAW,YAAY;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAC;AACvD,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,IAAI,OAAO,CAAC;IAClB,KAAK,IAAI,IAAI,CAAC;IACd,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,kFAAkF;AAClF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,MAAM,IAAI,GAAG,cAAc,CAOpI"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createFeatureStatus } from '../forms/dialog-frame.js';
|
|
2
|
+
/** Private shared implementation for the named scenes' existing loading phase. */
|
|
3
|
+
export function createLoadingSession(env, title, initial, onClose) {
|
|
4
|
+
const block = createFeatureStatus({ message: initial.error || 'Loading…', error: !!initial.error });
|
|
5
|
+
const owner = env.openFeature(title, block, onClose);
|
|
6
|
+
return {
|
|
7
|
+
update(state) { if (owner.isOpen())
|
|
8
|
+
block.update({ message: state.error || 'Loading…', error: !!state.error }); },
|
|
9
|
+
fail: owner.fail, isOpen: owner.isOpen, close: owner.close, destroy: owner.destroy,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/app/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,0BAA0B,CAAC;AAY7D,kFAAkF;AAClF,MAAM,UAAU,oBAAoB,CAAC,GAAmB,EAAE,KAAa,EAAE,OAAqB,EAAE,OAAoB;IAClH,MAAM,KAAK,GAAG,mBAAmB,CAAC,EAAC,OAAO,EAAE,OAAO,CAAC,KAAK,IAAI,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAC,CAAC,CAAC;IAClG,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACrD,OAAO;QACL,MAAM,CAAC,KAAK,IAAG,IAAI,KAAK,CAAC,MAAM,EAAE;YAAE,KAAK,CAAC,MAAM,CAAC,EAAC,OAAO,EAAE,KAAK,CAAC,KAAK,IAAI,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,EAAC,CAAC,CAAC,CAAA,CAAC;QAC7G,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO;KACnF,CAAC;AACJ,CAAC","sourcesContent":["import {createFeatureStatus} from '../forms/dialog-frame.js';\nimport type {AppEnvironment} from './internal.js';\n\nexport interface LoadingState {readonly error?: string}\nexport interface LoadingSession {\n update(state: Readonly<LoadingState>): void;\n fail(message: string): void;\n isOpen(): boolean;\n close(): void;\n destroy(): void;\n}\n\n/** Private shared implementation for the named scenes' existing loading phase. */\nexport function createLoadingSession(env: AppEnvironment, title: string, initial: LoadingState, onClose?: () => void): LoadingSession {\n const block = createFeatureStatus({message: initial.error || 'Loading…', error: !!initial.error});\n const owner = env.openFeature(title, block, onClose);\n return {\n update(state) {if (owner.isOpen()) block.update({message: state.error || 'Loading…', error: !!state.error});},\n fail: owner.fail, isOpen: owner.isOpen, close: owner.close, destroy: owner.destroy,\n };\n}\n"]}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type ActionResult } from '../core.js';
|
|
2
|
+
import { type ProviderAction, type ProviderActionsState, type ProviderActionTarget } from '../forms/actions.js';
|
|
3
|
+
import type { SettingsPanelState, SettingsDraft, SettingsProviderOption, SettingsCredentialView, MCPConnectionsState, MCPConnectionDraft, MCPEditorValue, MCPConnectionItem, MCPConnectionAction, MCPConnectionTarget, ModelPickerState } from '../forms/panels.js';
|
|
4
|
+
import { type CustomConnectionState, type CustomConnectionDraft } from '../forms/custom-connection.js';
|
|
5
|
+
import { type ProviderLoginState } from '../forms/provider-login.js';
|
|
6
|
+
import type { ModelSelection } from '../forms/model-editor.js';
|
|
7
|
+
import { type UpdatePanelState } from '../files/systems.js';
|
|
8
|
+
import type { Appearance } from '../theme.js';
|
|
9
|
+
import type { AppEnvironment, HostResult } from './internal.js';
|
|
10
|
+
import { type LoadingState, type LoadingSession } from './session.js';
|
|
11
|
+
export type { SettingsPanelState, SettingsDraft, SettingsProviderOption, MCPConnectionsState, MCPConnectionDraft, MCPEditorValue, MCPConnectionItem, ModelPickerState, ModelSelection, CustomConnectionState, CustomConnectionDraft, ProviderLoginState, UpdatePanelState, ProviderAction, ProviderActionsState, ProviderActionTarget, MCPConnectionAction, MCPConnectionTarget };
|
|
12
|
+
type Submission<Value> = (value: Value) => ActionResult | Promise<ActionResult>;
|
|
13
|
+
/** Session methods address one owned opening, never a later use of its window. */
|
|
14
|
+
export interface SettingsViewSession<State> {
|
|
15
|
+
update(state: Readonly<State>): void;
|
|
16
|
+
fail(message: string): void;
|
|
17
|
+
close(): void;
|
|
18
|
+
isOpen(): boolean;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
}
|
|
21
|
+
export interface SettingsCredential extends Omit<SettingsCredentialView, 'actions'> {
|
|
22
|
+
providerActions?: Readonly<ProviderActionsState>;
|
|
23
|
+
}
|
|
24
|
+
export type UpdateAction = 'check' | 'install';
|
|
25
|
+
export interface SettingsCallbacks {
|
|
26
|
+
onSubmit?: Submission<SettingsDraft>;
|
|
27
|
+
onRemoveKey?: Submission<SettingsDraft>;
|
|
28
|
+
onTest?: (draft: SettingsDraft) => HostResult;
|
|
29
|
+
onCancelTest?: () => HostResult;
|
|
30
|
+
onAppearanceChange?: (appearance: Appearance) => HostResult;
|
|
31
|
+
onProviderChange?: (provider: string) => HostResult;
|
|
32
|
+
onDraftChange?: (draft: SettingsDraft) => void;
|
|
33
|
+
onProviderAction?: (action: ProviderAction, target: ProviderActionTarget) => HostResult;
|
|
34
|
+
onUpdateAction?: (action: UpdateAction) => HostResult;
|
|
35
|
+
onCreateConnection?: () => HostResult;
|
|
36
|
+
onDiagnostics?: () => HostResult;
|
|
37
|
+
onClose?: () => void;
|
|
38
|
+
}
|
|
39
|
+
export interface SettingsSession extends SettingsViewSession<SettingsPanelState> {
|
|
40
|
+
read(): SettingsDraft;
|
|
41
|
+
setProviders(providers: readonly SettingsProviderOption[], selected?: string): void;
|
|
42
|
+
resetProvider(value: {
|
|
43
|
+
provider: string;
|
|
44
|
+
baseUrl: string;
|
|
45
|
+
clearKey?: boolean;
|
|
46
|
+
collapseAdvanced?: boolean;
|
|
47
|
+
}): void;
|
|
48
|
+
setCredential(view: Readonly<SettingsCredential>): void;
|
|
49
|
+
updateUpdates(state: Readonly<UpdatePanelState>): void;
|
|
50
|
+
setUpdatePending(pending: boolean): void;
|
|
51
|
+
setUpdateError(message: string, options?: {
|
|
52
|
+
allowCheckRetry?: boolean;
|
|
53
|
+
}): void;
|
|
54
|
+
clearSecrets(): void;
|
|
55
|
+
}
|
|
56
|
+
export interface MCPCallbacks {
|
|
57
|
+
onSubmit?: Submission<MCPConnectionDraft>;
|
|
58
|
+
onConnectionAction?: (action: MCPConnectionAction, target: MCPConnectionTarget) => HostResult;
|
|
59
|
+
onRefresh?: () => HostResult;
|
|
60
|
+
onNew?: () => HostResult;
|
|
61
|
+
onClose?: () => void;
|
|
62
|
+
}
|
|
63
|
+
export interface MCPSession extends SettingsViewSession<MCPConnectionsState> {
|
|
64
|
+
read(): MCPConnectionDraft;
|
|
65
|
+
edit(value?: Readonly<MCPEditorValue>): void;
|
|
66
|
+
setConnections(entries: readonly MCPConnectionItem[]): void;
|
|
67
|
+
clearBearerToken(): void;
|
|
68
|
+
clearSecrets(): void;
|
|
69
|
+
}
|
|
70
|
+
export interface ModelCallbacks {
|
|
71
|
+
onSubmit?: Submission<ModelSelection>;
|
|
72
|
+
onClose?: () => void;
|
|
73
|
+
}
|
|
74
|
+
export interface ModelSession extends SettingsViewSession<ModelPickerState> {
|
|
75
|
+
read(): ModelSelection;
|
|
76
|
+
reset(selection: Readonly<ModelSelection>): void;
|
|
77
|
+
focus(): void;
|
|
78
|
+
}
|
|
79
|
+
export interface CustomConnectionCallbacks {
|
|
80
|
+
onSubmit?: Submission<CustomConnectionDraft>;
|
|
81
|
+
onClose?: () => void;
|
|
82
|
+
}
|
|
83
|
+
export interface CustomConnectionSession extends SettingsViewSession<CustomConnectionState> {
|
|
84
|
+
read(): CustomConnectionDraft;
|
|
85
|
+
clearSecrets(): void;
|
|
86
|
+
}
|
|
87
|
+
export interface ProviderLoginCallbacks {
|
|
88
|
+
onAnswer?: (answer: string) => HostResult;
|
|
89
|
+
onCancel?: () => HostResult;
|
|
90
|
+
onClose?: () => void;
|
|
91
|
+
}
|
|
92
|
+
export interface ProviderLoginSession extends SettingsViewSession<ProviderLoginState> {
|
|
93
|
+
}
|
|
94
|
+
export interface SettingsScene {
|
|
95
|
+
openConnectionLoading(state: Readonly<LoadingState> & {
|
|
96
|
+
readonly editing: boolean;
|
|
97
|
+
}, callbacks?: {
|
|
98
|
+
onClose?: () => void;
|
|
99
|
+
}): LoadingSession;
|
|
100
|
+
openSettings(state: Readonly<SettingsPanelState>, callbacks?: SettingsCallbacks): SettingsSession;
|
|
101
|
+
openConnections(state?: Readonly<MCPConnectionsState>, callbacks?: MCPCallbacks): MCPSession;
|
|
102
|
+
openModels(state: Readonly<ModelPickerState>, callbacks?: ModelCallbacks): ModelSession;
|
|
103
|
+
openCustomConnection(state: Readonly<CustomConnectionState>, callbacks?: CustomConnectionCallbacks): CustomConnectionSession;
|
|
104
|
+
openProviderLogin(state: Readonly<ProviderLoginState>, callbacks?: ProviderLoginCallbacks): ProviderLoginSession;
|
|
105
|
+
destroy(): void;
|
|
106
|
+
}
|
|
107
|
+
/** Compose existing product blocks behind data-only application sessions. */
|
|
108
|
+
export declare function createSettingsScene(env: AppEnvironment): SettingsScene;
|
|
109
|
+
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/app/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,YAAY,EAAC,MAAM,YAAY,CAAC;AAGtD,OAAO,EAAuB,KAAK,cAAc,EAAC,KAAK,oBAAoB,EAAC,KAAK,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAElI,OAAO,KAAK,EAAC,kBAAkB,EAAC,aAAa,EAAC,sBAAsB,EAAC,sBAAsB,EAAC,mBAAmB,EAAC,kBAAkB,EAAC,cAAc,EAAC,iBAAiB,EAAC,mBAAmB,EAAC,mBAAmB,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACxP,OAAO,EAA8B,KAAK,qBAAqB,EAAC,KAAK,qBAAqB,EAAC,MAAM,+BAA+B,CAAC;AACjI,OAAO,EAA0B,KAAK,kBAAkB,EAAC,MAAM,4BAA4B,CAAC;AAC5F,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAmB,KAAK,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAC,cAAc,EAAC,UAAU,EAA2B,MAAM,eAAe,CAAC;AACvF,OAAO,EAAsB,KAAK,YAAY,EAAC,KAAK,cAAc,EAAC,M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