@kubohiroya/turbowarp-plus-editor-workbench 0.8.0 → 0.10.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.ja.md +1 -0
- package/README.md +1 -0
- package/dist/ai-agent-settings.d.ts +7 -5
- package/dist/ai-agent-settings.js +14 -11
- package/dist/ai-agents.d.ts +5 -2
- package/dist/ai-agents.js +41 -8
- package/dist/desktop-ai-agents.d.ts +80 -0
- package/dist/desktop-ai-agents.js +235 -0
- package/dist/dockview-stage.js +3 -2
- package/dist/drawer-views.d.ts +1 -0
- package/dist/drawer-views.js +4 -0
- package/dist/stage-launcher.d.ts +6 -0
- package/dist/stage-launcher.js +16 -2
- package/dist/stage-surface.d.ts +2 -1
- package/dist/stage-surface.js +3 -2
- package/dist/standard-layout.d.ts +2 -1
- package/dist/standard-layout.js +32 -7
- package/dist/workspace-layout.d.ts +2 -0
- package/dist/workspace-layout.js +2 -1
- package/package.json +1 -1
- package/src/ai-agent-settings.ts +17 -12
- package/src/ai-agents.ts +43 -9
- package/src/desktop-ai-agents.ts +263 -0
- package/src/dockview-stage.ts +3 -2
- package/src/drawer-views.ts +7 -0
- package/src/editor.css +2 -1
- package/src/stage-launcher.ts +17 -2
- package/src/stage-surface.ts +5 -2
- package/src/standard-layout.ts +29 -9
- package/src/workspace-layout.ts +4 -1
package/dist/dockview-stage.js
CHANGED
|
@@ -23,9 +23,10 @@ export function useDockviewStage(enabled, locale) {
|
|
|
23
23
|
const previous = savedDrawer.current;
|
|
24
24
|
const next = { open: false, selected: false, ...previous, ...patch };
|
|
25
25
|
if (next.open === Boolean(previous?.open) && next.selected === Boolean(previous?.selected) &&
|
|
26
|
-
next.position === previous?.position && next.width === previous?.width)
|
|
26
|
+
next.pinned === previous?.pinned && next.position === previous?.position && next.width === previous?.width)
|
|
27
27
|
return;
|
|
28
|
-
restoreDrawer(next.open || next.selected || next.position || next.width ?
|
|
28
|
+
restoreDrawer(next.open || next.selected || next.pinned !== undefined || next.position || next.width ?
|
|
29
|
+
next : undefined);
|
|
29
30
|
for (const listener of drawerListeners)
|
|
30
31
|
listener();
|
|
31
32
|
}, [drawerListeners, restoreDrawer]);
|
package/dist/drawer-views.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ declare const names: {
|
|
|
47
47
|
export declare const agentsIconPath = "M8 1.5 9.4 6.6 14.5 8 9.4 9.4 8 14.5 6.6 9.4 1.5 8 6.6 6.6Z";
|
|
48
48
|
export declare const isJapanese: (locale: string) => boolean;
|
|
49
49
|
export declare const drawerLabel: (id: keyof typeof names, locale: string) => "スプライト一覧" | "Sprites" | "プロジェクトフォルダ" | "Project folder" | "Git 履歴" | "Git history" | "AI エージェント" | "AI agents" | "ドロワーの表示" | "Drawer views";
|
|
50
|
+
export declare function drawerPinIcon(element: typeof import('react').createElement, pinned: boolean): import("react").ReactSVGElement;
|
|
50
51
|
/** The supported host views in button order, without unknown or repeated ids. */
|
|
51
52
|
export declare function availableDrawerViews(drawerViews: DrawerViews | undefined): DrawerView[];
|
|
52
53
|
/** The bar is shown only when the host supplies something besides the sprite list. */
|
package/dist/drawer-views.js
CHANGED
|
@@ -11,6 +11,10 @@ const names = {
|
|
|
11
11
|
export const agentsIconPath = 'M8 1.5 9.4 6.6 14.5 8 9.4 9.4 8 14.5 6.6 9.4 1.5 8 6.6 6.6Z';
|
|
12
12
|
export const isJapanese = (locale) => /^ja(?:-|$)/i.test(locale ?? '');
|
|
13
13
|
export const drawerLabel = (id, locale) => names[id][isJapanese(locale) ? 0 : 1];
|
|
14
|
+
export function drawerPinIcon(element, pinned) {
|
|
15
|
+
return element('svg', { 'aria-hidden': true, width: 14, height: 14, viewBox: '0 0 16 16',
|
|
16
|
+
fill: pinned ? 'currentColor' : 'none', stroke: 'currentColor', strokeWidth: 1.2, strokeLinejoin: 'round' }, element('path', { d: 'M9 2 14 7 12 8l-2 3-5-5 3-2 1-2Z' }), element('path', { d: 'm7.5 8.5-4 4' }), !pinned && element('path', { d: 'M2 2l12 12', strokeLinecap: 'round' }));
|
|
17
|
+
}
|
|
14
18
|
/** The supported host views in button order, without unknown or repeated ids. */
|
|
15
19
|
export function availableDrawerViews(drawerViews) {
|
|
16
20
|
const views = drawerViews?.views ?? [];
|
package/dist/stage-launcher.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import React, { type ComponentType } from 'react';
|
|
|
2
2
|
declare const modes: readonly ["window", "tab", "drawer"];
|
|
3
3
|
type StageMode = typeof modes[number];
|
|
4
4
|
export declare function stagePresentationItems(locale: string, current: StageMode | null, actions: Partial<Record<StageMode, () => void>>): MenuItem[];
|
|
5
|
+
export declare function stageDrawerPinItem(locale: string, pinned: boolean, setPinned: (pinned: boolean) => void): {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
icon: React.ReactSVGElement;
|
|
9
|
+
onSelect: () => void;
|
|
10
|
+
};
|
|
5
11
|
export declare function useStageDocumentFullscreen(doc?: Document): boolean;
|
|
6
12
|
export interface StageDockAction {
|
|
7
13
|
kind: 'docked' | 'opening' | 'external';
|
package/dist/stage-launcher.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import React, { createElement as element } from 'react';
|
|
2
|
+
import { drawerPinIcon } from "./drawer-views.js";
|
|
2
3
|
const labels = {
|
|
3
4
|
ja: {
|
|
4
5
|
open: 'ステージを開く',
|
|
5
6
|
menu: 'ステージの開き方',
|
|
6
7
|
window: '別ウィンドウで表示',
|
|
7
8
|
tab: 'タブで表示',
|
|
8
|
-
drawer: '引出しで表示'
|
|
9
|
+
drawer: '引出しで表示',
|
|
10
|
+
pinDrawer: '引出しを常時表示する',
|
|
11
|
+
autoHideDrawer: '引出しを自動的に隠す'
|
|
9
12
|
},
|
|
10
13
|
en: {
|
|
11
14
|
open: 'Open stage',
|
|
12
15
|
menu: 'Stage opening options',
|
|
13
16
|
window: 'Show in a separate window',
|
|
14
17
|
tab: 'Show in a tab',
|
|
15
|
-
drawer: 'Show in the drawer'
|
|
18
|
+
drawer: 'Show in the drawer',
|
|
19
|
+
pinDrawer: 'Keep the drawer open',
|
|
20
|
+
autoHideDrawer: 'Automatically hide the drawer'
|
|
16
21
|
}
|
|
17
22
|
};
|
|
18
23
|
const modes = ['window', 'tab', 'drawer'];
|
|
@@ -30,6 +35,15 @@ export function stagePresentationItems(locale, current, actions) {
|
|
|
30
35
|
strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true }, element('path', { d: icons[id] }))
|
|
31
36
|
}));
|
|
32
37
|
}
|
|
38
|
+
export function stageDrawerPinItem(locale, pinned, setPinned) {
|
|
39
|
+
const text = textFor(locale);
|
|
40
|
+
return {
|
|
41
|
+
id: 'drawer-pin',
|
|
42
|
+
label: pinned ? text.autoHideDrawer : text.pinDrawer,
|
|
43
|
+
icon: drawerPinIcon(element, !pinned),
|
|
44
|
+
onSelect: () => setPinned(!pinned)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
33
47
|
export function useStageDocumentFullscreen(doc) {
|
|
34
48
|
const [fullscreenDocument, setFullscreenDocument] = React.useState();
|
|
35
49
|
React.useLayoutEffect(() => {
|
package/dist/stage-surface.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Context, ElementType } from 'react';
|
|
|
2
2
|
import type { useDockviewStage } from './dockview-stage.ts';
|
|
3
3
|
import { type StageDockAction, type StageLauncherOptions } from './stage-launcher.ts';
|
|
4
4
|
export type { StageDockAction, StageLauncherOptions } from './stage-launcher.ts';
|
|
5
|
-
export { stagePresentationItems, useStageDocumentFullscreen } from './stage-launcher.ts';
|
|
5
|
+
export { stageDrawerPinItem, stagePresentationItems, useStageDocumentFullscreen } from './stage-launcher.ts';
|
|
6
6
|
export { StageResizeHandle } from './stage-resize-handle.ts';
|
|
7
7
|
interface StageWindowConnection<Target> {
|
|
8
8
|
ready: Promise<Target>;
|
|
@@ -26,6 +26,7 @@ export declare function createStageSurface(React: typeof import('react'), { cont
|
|
|
26
26
|
context: Context<{
|
|
27
27
|
locale: string;
|
|
28
28
|
stageDrawer?: boolean;
|
|
29
|
+
stageDrawerPinned?: boolean;
|
|
29
30
|
stageHidden?: boolean;
|
|
30
31
|
setStageDrawerOpen?(open: boolean): void;
|
|
31
32
|
setStageVisible?(visible: boolean): void;
|
package/dist/stage-surface.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createPortal } from 'react-dom';
|
|
2
2
|
import { createDockview, themeLight } from 'dockview';
|
|
3
3
|
import { StageLauncher } from "./stage-launcher.js";
|
|
4
|
-
export { stagePresentationItems, useStageDocumentFullscreen } from "./stage-launcher.js";
|
|
4
|
+
export { stageDrawerPinItem, stagePresentationItems, useStageDocumentFullscreen } from "./stage-launcher.js";
|
|
5
5
|
export { StageResizeHandle } from "./stage-resize-handle.js";
|
|
6
6
|
export function createStagePopoutHost(host, title) {
|
|
7
7
|
return {
|
|
@@ -84,7 +84,7 @@ export function stageDockActionLabel(locale, { drawer, detached, external }) {
|
|
|
84
84
|
}
|
|
85
85
|
export function createStageSurface(React, { context, EdgeDrawer, Panel }) {
|
|
86
86
|
return function StageSurface({ externalHost, onDockActionChange, placement, dockAction, launcher, openDrawerRef, closeDrawerRef, editorFullscreen, ...props }) {
|
|
87
|
-
const { locale, stageDrawer, stageHidden, setStageDrawerOpen, setStageVisible } = React.useContext(context);
|
|
87
|
+
const { locale, stageDrawer, stageDrawerPinned = true, stageHidden, setStageDrawerOpen, setStageVisible } = React.useContext(context);
|
|
88
88
|
const [drawerOpen, setDrawerOpen] = React.useState(false);
|
|
89
89
|
const localDrawerRef = React.useRef(null);
|
|
90
90
|
const focusDrawer = openDrawerRef ?? localDrawerRef;
|
|
@@ -119,6 +119,7 @@ export function createStageSurface(React, { context, EdgeDrawer, Panel }) {
|
|
|
119
119
|
const dock = stageDrawer ? React.createElement(EdgeDrawer, {
|
|
120
120
|
edge: 'right',
|
|
121
121
|
movableStage: true,
|
|
122
|
+
keepOpenOnBlur: stageDrawerPinned,
|
|
122
123
|
available: !placement?.docked && (!dockAction || dockAction.kind === 'docked'),
|
|
123
124
|
stageDrawerLayout: drawerLayout,
|
|
124
125
|
updateStageDrawer: updateDrawer,
|
|
@@ -22,7 +22,7 @@ export declare function createStandardLayout(React: any, { styles, targetStyles,
|
|
|
22
22
|
stageDrawerLayout?: StageDrawerLayout;
|
|
23
23
|
updateStageDrawer?: (patch: Partial<StageDrawerLayout>) => void;
|
|
24
24
|
}) => any;
|
|
25
|
-
EdgeDrawer: ({ edge, label, pinned, onOpenChange, portalContent, holdOpenSelector, focusPanelRef, closePanelRef, focusBoundary, showTrigger, movableStage, available, stageDrawerLayout, updateStageDrawer, children }: {
|
|
25
|
+
EdgeDrawer: ({ edge, label, pinned, onOpenChange, portalContent, holdOpenSelector, focusPanelRef, closePanelRef, focusBoundary, showTrigger, movableStage, available, keepOpenOnBlur, stageDrawerLayout, updateStageDrawer, children }: {
|
|
26
26
|
edge: any;
|
|
27
27
|
label: any;
|
|
28
28
|
pinned?: boolean;
|
|
@@ -35,6 +35,7 @@ export declare function createStandardLayout(React: any, { styles, targetStyles,
|
|
|
35
35
|
showTrigger?: boolean;
|
|
36
36
|
movableStage?: boolean;
|
|
37
37
|
available?: boolean;
|
|
38
|
+
keepOpenOnBlur?: boolean;
|
|
38
39
|
stageDrawerLayout?: StageDrawerLayout;
|
|
39
40
|
updateStageDrawer?: (patch: Partial<StageDrawerLayout>) => void;
|
|
40
41
|
children: any;
|
package/dist/standard-layout.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createLayout, createSplitter, splitAxis } from "./index.js";
|
|
2
2
|
import { createTargetList } from "./targets.js";
|
|
3
|
-
import { availableDrawerViews, createDrawerViewBar, hasDrawerBar, readDrawerView, writeDrawerView } from "./drawer-views.js";
|
|
3
|
+
import { availableDrawerViews, createDrawerViewBar, drawerPinIcon, hasDrawerBar, readDrawerView, writeDrawerView } from "./drawer-views.js";
|
|
4
4
|
import { attachStageDrawerDrag } from "./stage-drawer-drag.js";
|
|
5
5
|
const isJapanese = locale => /^ja(?:-|$)/i.test(locale);
|
|
6
6
|
const singleColumnTargetWidth = 108;
|
|
@@ -21,6 +21,7 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
21
21
|
const [targetsPinned, setTargetsPinned] = useState(true);
|
|
22
22
|
const [showStage, setShowStage] = useState(true);
|
|
23
23
|
const [stageDrawerOpen, setStageDrawerOpen] = useState(false);
|
|
24
|
+
const [localStageDrawerPinned, setLocalStageDrawerPinned] = useState(true);
|
|
24
25
|
const [size, setSize] = useState(null);
|
|
25
26
|
const [targetRatio, setTargetRatio] = useState(null);
|
|
26
27
|
const [viewRatio, setViewRatio] = useState(null);
|
|
@@ -37,6 +38,13 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
37
38
|
const body = useRef(null);
|
|
38
39
|
const plusLayout = enabled && !props.fullscreen;
|
|
39
40
|
const stageHidden = plusLayout && !showStage;
|
|
41
|
+
const stageDrawerPinned = updateStageDrawer ? stageDrawerLayout?.pinned !== false : localStageDrawerPinned;
|
|
42
|
+
const setStageDrawerPinned = (pinned) => {
|
|
43
|
+
if (updateStageDrawer)
|
|
44
|
+
updateStageDrawer({ pinned });
|
|
45
|
+
else
|
|
46
|
+
setLocalStageDrawerPinned(pinned);
|
|
47
|
+
};
|
|
40
48
|
const japanese = isJapanese(props.locale);
|
|
41
49
|
const undockLabel = japanese ? 'アンドックボタンを表示' : 'Show undock buttons';
|
|
42
50
|
const layoutMenuLabel = japanese ? '配置メニュー' : 'Layout options';
|
|
@@ -171,11 +179,12 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
171
179
|
});
|
|
172
180
|
return element(context.Provider, { value: {
|
|
173
181
|
showUndock, plusLayout, targetsPinned, setTargetsPinned, stageHidden, setStageVisible: setShowStage, stageResize, stageActionMount,
|
|
174
|
-
stageDrawer: plusLayout && stageDrawer,
|
|
182
|
+
stageDrawer: plusLayout && stageDrawer, stageDrawerPinned, setStageDrawerPinned, setStageDrawerOpen,
|
|
183
|
+
locale: props.locale,
|
|
175
184
|
drawerViews, drawerView, selectDrawerView
|
|
176
185
|
} }, Container ? element(Container, { locale: props.locale }, layout) : layout);
|
|
177
186
|
}
|
|
178
|
-
function EdgeDrawer({ edge, label, pinned = false, onOpenChange, portalContent = false, holdOpenSelector = '', focusPanelRef = undefined, closePanelRef = undefined, focusBoundary = undefined, showTrigger = true, movableStage = false, available = true, stageDrawerLayout = undefined, updateStageDrawer = undefined, children }) {
|
|
187
|
+
function EdgeDrawer({ edge, label, pinned = false, onOpenChange, portalContent = false, holdOpenSelector = '', focusPanelRef = undefined, closePanelRef = undefined, focusBoundary = undefined, showTrigger = true, movableStage = false, available = true, keepOpenOnBlur = false, stageDrawerLayout = undefined, updateStageDrawer = undefined, children }) {
|
|
179
188
|
const [hovered, setHovered] = useState(false);
|
|
180
189
|
const [localEngaged, setLocalEngaged] = useState(false);
|
|
181
190
|
const [heldOpen, setHeldOpen] = useState(false);
|
|
@@ -253,6 +262,8 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
253
262
|
setEngaged(true);
|
|
254
263
|
};
|
|
255
264
|
const blur = (event) => {
|
|
265
|
+
if (keepOpenOnBlur)
|
|
266
|
+
return;
|
|
256
267
|
const target = event.relatedTarget;
|
|
257
268
|
const source = event.target;
|
|
258
269
|
// Opening the stage disables the launcher before focus moves into the drawer.
|
|
@@ -305,7 +316,7 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
305
316
|
return;
|
|
306
317
|
focusBoundary.addEventListener('focusout', blur);
|
|
307
318
|
return () => focusBoundary.removeEventListener('focusout', blur);
|
|
308
|
-
}, [focusBoundary, setEngaged]);
|
|
319
|
+
}, [focusBoundary, keepOpenOnBlur, setEngaged]);
|
|
309
320
|
useLayoutEffect(() => {
|
|
310
321
|
if (!portalContent)
|
|
311
322
|
return;
|
|
@@ -321,7 +332,22 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
321
332
|
node.removeEventListener('focusin', focus);
|
|
322
333
|
node.removeEventListener('focusout', blur);
|
|
323
334
|
};
|
|
324
|
-
}, [portalContent, focusBoundary, open, showTrigger, movableStage, setEngaged]);
|
|
335
|
+
}, [portalContent, focusBoundary, open, showTrigger, movableStage, keepOpenOnBlur, setEngaged]);
|
|
336
|
+
useLayoutEffect(() => {
|
|
337
|
+
if (!movableStage || keepOpenOnBlur || !open)
|
|
338
|
+
return;
|
|
339
|
+
const node = drawer.current;
|
|
340
|
+
const dismiss = (event) => {
|
|
341
|
+
const target = event.target;
|
|
342
|
+
if (node.contains(target) || focusBoundary?.contains(target))
|
|
343
|
+
return;
|
|
344
|
+
setHovered(false);
|
|
345
|
+
setEngaged(false);
|
|
346
|
+
};
|
|
347
|
+
// The restored drawer may be open without having received focus.
|
|
348
|
+
node.ownerDocument.addEventListener('pointerdown', dismiss, true);
|
|
349
|
+
return () => node.ownerDocument.removeEventListener('pointerdown', dismiss, true);
|
|
350
|
+
}, [movableStage, keepOpenOnBlur, open, focusBoundary, setEngaged]);
|
|
325
351
|
useLayoutEffect(() => {
|
|
326
352
|
if (!portalContent || !movableStage || !open)
|
|
327
353
|
return;
|
|
@@ -415,8 +441,7 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
415
441
|
function DrawerPinButton({ label }) {
|
|
416
442
|
const { targetsPinned, setTargetsPinned } = useContext(context);
|
|
417
443
|
return element('button', { type: 'button', className: styles.drawerPin, 'aria-label': label, 'aria-pressed': targetsPinned,
|
|
418
|
-
title: label, onClick: () => setTargetsPinned(value => !value) }, element
|
|
419
|
-
fill: targetsPinned ? 'currentColor' : 'none', stroke: 'currentColor', strokeWidth: 1.2, strokeLinejoin: 'round' }, element('path', { d: 'M9 2 14 7 12 8l-2 3-5-5 3-2 1-2Z' }), element('path', { d: 'm7.5 8.5-4 4' }), !targetsPinned && element('path', { d: 'M2 2l12 12', strokeLinecap: 'round' })));
|
|
444
|
+
title: label, onClick: () => setTargetsPinned(value => !value) }, drawerPinIcon(element, targetsPinned));
|
|
420
445
|
}
|
|
421
446
|
function useSpriteListTools() {
|
|
422
447
|
const { locale } = useContext(context);
|
|
@@ -32,6 +32,8 @@ export interface StageDrawerLayout {
|
|
|
32
32
|
open: boolean;
|
|
33
33
|
/** Keep the drawer selected after it folds into the edge. */
|
|
34
34
|
selected: boolean;
|
|
35
|
+
/** Missing in older records, which use the default pinned behavior. */
|
|
36
|
+
pinned?: boolean;
|
|
35
37
|
position?: StageDrawerPosition;
|
|
36
38
|
width?: number;
|
|
37
39
|
}
|
package/dist/workspace-layout.js
CHANGED
|
@@ -198,12 +198,13 @@ export function readWorkspaceLayout(raw, project) {
|
|
|
198
198
|
function readStageDrawer(input) {
|
|
199
199
|
if (!record(input) || typeof input.open !== 'boolean' || typeof input.selected !== 'boolean')
|
|
200
200
|
return;
|
|
201
|
-
const { position, width } = input;
|
|
201
|
+
const { position, width, pinned } = input;
|
|
202
202
|
const fraction = (value) => size(value) && value <= 1;
|
|
203
203
|
const edge = (value) => value === 0 || value === 1;
|
|
204
204
|
return {
|
|
205
205
|
open: input.open,
|
|
206
206
|
selected: input.open || input.selected,
|
|
207
|
+
...(typeof pinned === 'boolean' && { pinned }),
|
|
207
208
|
...(size(width) && width > 0 && { width }),
|
|
208
209
|
...(record(position) && fraction(position.x) && fraction(position.y) &&
|
|
209
210
|
(edge(position.x) || edge(position.y)) && { position: { x: position.x, y: position.y } })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-plus-editor-workbench",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "The TurboWarp Plus Editor workbench: layout, dockable sprite tabs, stage, debugger tab and file menu",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MPL-2.0",
|
package/src/ai-agent-settings.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {isJapanese} from './drawer-views.ts';
|
|
2
|
+
import {desktopAgentSettings, type DesktopAiAgentsPort} from './desktop-ai-agents.ts';
|
|
2
3
|
|
|
3
4
|
/** The services the Editor knows by name. Their name and icon are fixed; their address can be replaced. */
|
|
4
5
|
export type AgentPresetId = 'chatgpt' | 'claude';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
* as another `kind`, which this version ignores when it reads the settings.
|
|
8
|
+
* A web service. Desktop applications are stored separately by the Desktop host.
|
|
9
9
|
*/
|
|
10
10
|
export interface AgentUrlTarget {
|
|
11
11
|
kind: 'url';
|
|
@@ -26,6 +26,7 @@ export interface AgentSettings {
|
|
|
26
26
|
version: 1;
|
|
27
27
|
/** The presets in their fixed order, then the user's own services. */
|
|
28
28
|
services: AgentService[];
|
|
29
|
+
unknownServices?: unknown[];
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
export type AgentStorage = Pick<Storage, 'getItem' | 'setItem'>;
|
|
@@ -65,7 +66,7 @@ const presetService = (preset: (typeof agentPresets)[number], saved?: {enabled?:
|
|
|
65
66
|
|
|
66
67
|
export const defaultAgentSettings = (): AgentSettings => ({version: 1, services: agentPresets.map(preset => presetService(preset))});
|
|
67
68
|
|
|
68
|
-
/**
|
|
69
|
+
/** Reads usable web services and preserves settings for target kinds this version cannot open. */
|
|
69
70
|
export function parseAgentSettings(raw: string | null | undefined): AgentSettings {
|
|
70
71
|
let saved: unknown;
|
|
71
72
|
try {
|
|
@@ -77,9 +78,11 @@ export function parseAgentSettings(raw: string | null | undefined): AgentSetting
|
|
|
77
78
|
!Array.isArray((saved as {services?: unknown}).services)) return defaultAgentSettings();
|
|
78
79
|
const entries = (saved as {services: unknown[]}).services.filter(entry => entry && typeof entry === 'object') as
|
|
79
80
|
{id?: unknown; preset?: unknown; name?: unknown; enabled?: unknown; target?: {kind?: unknown; url?: unknown}}[];
|
|
80
|
-
const presets = agentPresets.map(preset => presetService(preset, entries.find(entry => entry.preset === preset.id
|
|
81
|
+
const presets = agentPresets.map(preset => presetService(preset, entries.find(entry => entry.preset === preset.id &&
|
|
82
|
+
(entry.target?.kind === 'url' || entry.target?.kind === undefined))));
|
|
81
83
|
const ids = new Set<string>(presets.map(service => service.id));
|
|
82
84
|
const custom: AgentService[] = [];
|
|
85
|
+
const unknownServices = entries.filter(entry => typeof entry.target?.kind === 'string' && entry.target.kind !== 'url');
|
|
83
86
|
for (const entry of entries) {
|
|
84
87
|
if (entry.preset !== undefined || entry.target?.kind !== 'url') continue;
|
|
85
88
|
const name = typeof entry.name === 'string' ? entry.name.trim() : '';
|
|
@@ -90,7 +93,7 @@ export function parseAgentSettings(raw: string | null | undefined): AgentSetting
|
|
|
90
93
|
ids.add(id);
|
|
91
94
|
custom.push({id, name, enabled: entry.enabled !== false, target: {kind: 'url', url: checked.url}});
|
|
92
95
|
}
|
|
93
|
-
return {version: 1, services: [...presets, ...custom]};
|
|
96
|
+
return {version: 1, services: [...presets, ...custom], ...(unknownServices.length ? {unknownServices} : {})};
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
export const browserStorage = (): AgentStorage | null => {
|
|
@@ -114,9 +117,9 @@ export function writeAgentSettings(settings: AgentSettings, storage: AgentStorag
|
|
|
114
117
|
key = agentSettingsKey): boolean {
|
|
115
118
|
if (!storage) return false;
|
|
116
119
|
try {
|
|
117
|
-
storage.setItem(key, JSON.stringify({version: 1, services: settings.services.map(service => service.preset ?
|
|
120
|
+
storage.setItem(key, JSON.stringify({version: 1, services: [...settings.services.map(service => service.preset ?
|
|
118
121
|
{preset: service.preset, enabled: service.enabled, target: service.target} :
|
|
119
|
-
{id: service.id, name: service.name, enabled: service.enabled, target: service.target})}));
|
|
122
|
+
{id: service.id, name: service.name, enabled: service.enabled, target: service.target}), ...(settings.unknownServices ?? [])]}));
|
|
120
123
|
return true;
|
|
121
124
|
} catch {
|
|
122
125
|
return false;
|
|
@@ -172,6 +175,7 @@ export interface AgentSettingsDialogOptions {
|
|
|
172
175
|
/** Where focus goes when the dialog closes. Defaults to the element focused when it opened. */
|
|
173
176
|
returnFocus?: HTMLElement | null;
|
|
174
177
|
onSave?(settings: AgentSettings): void;
|
|
178
|
+
desktop?: DesktopAiAgentsPort | null;
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
export interface AgentSettingsDialog {
|
|
@@ -189,7 +193,7 @@ interface Row {
|
|
|
189
193
|
|
|
190
194
|
let openDialog: AgentSettingsDialog | null = null;
|
|
191
195
|
let nextDialog = 0;
|
|
192
|
-
const focusable = 'button:not([disabled]), input:not([disabled]), [href], [tabindex]:not([tabindex="-1"])';
|
|
196
|
+
const focusable = 'button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [href], [tabindex]:not([tabindex="-1"])';
|
|
193
197
|
const urlProblems = {empty: 'urlEmpty', invalid: 'urlInvalid', 'not-https': 'urlNotHttps'} as const;
|
|
194
198
|
|
|
195
199
|
/**
|
|
@@ -197,7 +201,7 @@ const urlProblems = {empty: 'urlEmpty', invalid: 'urlInvalid', 'not-https': 'url
|
|
|
197
201
|
* user's own services. It is plain DOM so that any part of the Editor can open it, with or without React.
|
|
198
202
|
*/
|
|
199
203
|
export function openAgentSettingsDialog({document: doc = globalThis.document, locale, styles = {}, storage = browserStorage(),
|
|
200
|
-
storageKey = agentSettingsKey, returnFocus, onSave}: AgentSettingsDialogOptions): AgentSettingsDialog {
|
|
204
|
+
storageKey = agentSettingsKey, returnFocus, onSave, desktop}: AgentSettingsDialogOptions): AgentSettingsDialog {
|
|
201
205
|
if (openDialog?.element.isConnected) {
|
|
202
206
|
(openDialog.element.querySelector(focusable) as HTMLElement)?.focus();
|
|
203
207
|
return openDialog;
|
|
@@ -301,7 +305,8 @@ export function openAgentSettingsDialog({document: doc = globalThis.document, lo
|
|
|
301
305
|
const cancel = make('button', {type: 'button', class: styles.aiAgentDialogButton}, text('cancel'));
|
|
302
306
|
const save = make('button', {type: 'submit', class: `${styles.aiAgentDialogButton ?? ''} ${styles.aiAgentDialogPrimary ?? ''}`.trim()},
|
|
303
307
|
text('save'));
|
|
304
|
-
const form = make('form', {novalidate: '', class: styles.aiAgentDialogForm}, presetGroup, customGroup,
|
|
308
|
+
const form = make('form', {novalidate: '', class: styles.aiAgentDialogForm}, presetGroup, customGroup,
|
|
309
|
+
desktop && desktopAgentSettings(doc, desktop, locale, styles), status,
|
|
305
310
|
make('div', {class: styles.aiAgentDialogActions}, cancel, save));
|
|
306
311
|
const element = make('div', {
|
|
307
312
|
role: 'dialog', 'aria-modal': 'true', 'aria-labelledby': `${prefix}-title`,
|
|
@@ -327,7 +332,7 @@ export function openAgentSettingsDialog({document: doc = globalThis.document, lo
|
|
|
327
332
|
return;
|
|
328
333
|
}
|
|
329
334
|
if (event.key !== 'Tab') return;
|
|
330
|
-
const items = [...element.querySelectorAll<HTMLElement>(focusable)];
|
|
335
|
+
const items = [...element.querySelectorAll<HTMLElement>(focusable)].filter(item => !item.matches(':disabled'));
|
|
331
336
|
const first = items[0];
|
|
332
337
|
const last = items[items.length - 1];
|
|
333
338
|
if (event.shiftKey && doc.activeElement === first) {
|
|
@@ -363,7 +368,7 @@ export function openAgentSettingsDialog({document: doc = globalThis.document, lo
|
|
|
363
368
|
}
|
|
364
369
|
let count = 0;
|
|
365
370
|
for (const service of services) if (!service.preset) service.id = `custom-${++count}`;
|
|
366
|
-
const saved: AgentSettings = {
|
|
371
|
+
const saved: AgentSettings = {...settings, services};
|
|
367
372
|
if (!writeAgentSettings(saved, storage, storageKey)) {
|
|
368
373
|
status.textContent = text('saveFailed');
|
|
369
374
|
status.hidden = false;
|
package/src/ai-agents.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type {DrawerMenu, DrawerMenuRenderProps} from './drawer-views.ts';
|
|
2
2
|
import {agentsIconPath} from './drawer-views.ts';
|
|
3
3
|
import {
|
|
4
|
-
agentPresets, agentSettingsKey, agentText, browserStorage, enabledAgentServices, openAgentService,
|
|
4
|
+
agentPresets, agentSettingsKey, agentText, browserStorage, checkAgentUrl, enabledAgentServices, openAgentService,
|
|
5
5
|
openAgentSettingsDialog, readAgentSettings, type AgentService, type AgentStorage, type Opener
|
|
6
6
|
} from './ai-agent-settings.ts';
|
|
7
7
|
|
|
8
|
+
import {agentRequest, desktopAgentError, desktopAgentText, type DesktopAgent, type DesktopAiAgentsPort} from './desktop-ai-agents.ts';
|
|
9
|
+
|
|
8
10
|
export * from './ai-agent-settings.ts';
|
|
11
|
+
export type {DesktopAiAgentsPort} from './desktop-ai-agents.ts';
|
|
9
12
|
|
|
10
13
|
export interface AiAgentsOptions {
|
|
11
14
|
/** The workbench stylesheet's class names (`editor.css`), for the menu and the settings dialog. */
|
|
@@ -14,6 +17,7 @@ export interface AiAgentsOptions {
|
|
|
14
17
|
storageKey?: string;
|
|
15
18
|
/** Opens a service; defaults to a new browser tab. */
|
|
16
19
|
open?: Opener;
|
|
20
|
+
desktop?: DesktopAiAgentsPort | null;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
/**
|
|
@@ -21,8 +25,8 @@ export interface AiAgentsOptions {
|
|
|
21
25
|
* its own entry for the dialog. Every part reads the saved settings when it opens.
|
|
22
26
|
*/
|
|
23
27
|
export function createAiAgents(React, {styles = {}, storage = browserStorage(), storageKey = agentSettingsKey,
|
|
24
|
-
open}: AiAgentsOptions = {}) {
|
|
25
|
-
const {createElement: element, useRef, useState} = React;
|
|
28
|
+
open = (...args) => window.open(...args), desktop}: AiAgentsOptions = {}) {
|
|
29
|
+
const {createElement: element, useEffect, useRef, useState} = React;
|
|
26
30
|
const svg = (...children) => element('svg', {
|
|
27
31
|
'aria-hidden': true, focusable: false, width: 16, height: 16, viewBox: '0 0 16 16',
|
|
28
32
|
fill: 'none', stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round', strokeLinejoin: 'round'
|
|
@@ -34,8 +38,8 @@ export function createAiAgents(React, {styles = {}, storage = browserStorage(),
|
|
|
34
38
|
G: 'M9.9 5.6A2.4 2.4 0 1 0 10.4 7H8.4'
|
|
35
39
|
};
|
|
36
40
|
/** A plain chat bubble with the service's initial for a preset; a globe for the user's own address. */
|
|
37
|
-
const serviceIcon = (service
|
|
38
|
-
const preset = agentPresets.find(item => item.id === service
|
|
41
|
+
const serviceIcon = (service?: AgentService) => {
|
|
42
|
+
const preset = agentPresets.find(item => item.id === service?.preset);
|
|
39
43
|
if (preset) {
|
|
40
44
|
const svgElement = svg(element('path', {d: bubble}), element('path', {d: initials[preset.letter]}));
|
|
41
45
|
return React.cloneElement(svgElement, {'data-initial': preset.letter});
|
|
@@ -45,10 +49,22 @@ export function createAiAgents(React, {styles = {}, storage = browserStorage(),
|
|
|
45
49
|
const settingsIcon = () => svg(element('path', {d: agentsIconPath}));
|
|
46
50
|
|
|
47
51
|
const openSettings = ({locale, returnFocus}: {locale: string; returnFocus?: HTMLElement | null}) =>
|
|
48
|
-
openAgentSettingsDialog({document, locale, styles, storage, storageKey, returnFocus});
|
|
52
|
+
openAgentSettingsDialog({document, locale, styles, storage, storageKey, returnFocus, desktop});
|
|
49
53
|
|
|
50
54
|
function AgentMenu({locale, close}: DrawerMenuRenderProps) {
|
|
51
55
|
const [services] = useState(() => enabledAgentServices(readAgentSettings(storage, storageKey)));
|
|
56
|
+
const [applications, setApplications] = useState([] as DesktopAgent[]);
|
|
57
|
+
const [error, setError] = useState(null as {code: string; url?: string} | null);
|
|
58
|
+
const active = useRef(true);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
active.current = true;
|
|
61
|
+
if (desktop) void agentRequest(() => desktop.list()).then(result => {
|
|
62
|
+
if (!active.current) return;
|
|
63
|
+
if ('value' in result) setApplications(result.value.entries);
|
|
64
|
+
else setError({code: result.code});
|
|
65
|
+
});
|
|
66
|
+
return () => { active.current = false; };
|
|
67
|
+
}, []);
|
|
52
68
|
const list = useRef(null);
|
|
53
69
|
const hintId = useRef(null);
|
|
54
70
|
if (!hintId.current) hintId.current = `plus-agent-menu-hint-${++nextId}`;
|
|
@@ -69,17 +85,35 @@ export function createAiAgents(React, {styles = {}, storage = browserStorage(),
|
|
|
69
85
|
const item = (key: string, icon, text: string, onClick: () => void, title?: string) => element('button', {
|
|
70
86
|
key, type: 'button', role: 'menuitem', tabIndex: -1, className: styles.aiAgentMenuItem, title, onClick
|
|
71
87
|
}, icon, element('span', null, text));
|
|
88
|
+
const hasEntries = services.length + applications.length > 0;
|
|
89
|
+
const launch = async (application: DesktopAgent) => {
|
|
90
|
+
setError(null);
|
|
91
|
+
const result = await agentRequest(() => desktop.launch(application.id));
|
|
92
|
+
if (!active.current) return;
|
|
93
|
+
if ('value' in result) close();
|
|
94
|
+
else {
|
|
95
|
+
const checked = checkAgentUrl(application.url);
|
|
96
|
+
setError({code: result.code, ...('url' in checked ? checked : {})});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
72
99
|
return element(React.Fragment, null,
|
|
73
|
-
|
|
100
|
+
error && element('p', {role: 'alert', className: styles.aiAgentMenuHint}, desktopAgentError(error.code, locale)),
|
|
101
|
+
!hasEntries && element('p', {id: hintId.current, className: styles.aiAgentMenuHint}, agentText('empty', locale)),
|
|
74
102
|
element('div', {
|
|
75
103
|
role: 'menu', 'aria-label': label, ref: list, className: styles.aiAgentMenu, onKeyDown: move,
|
|
76
|
-
'aria-describedby':
|
|
104
|
+
'aria-describedby': hasEntries ? undefined : hintId.current
|
|
77
105
|
},
|
|
78
106
|
services.map(service => item(service.id, serviceIcon(service), service.name, () => {
|
|
79
107
|
openAgentService(service, open);
|
|
80
108
|
close();
|
|
81
109
|
}, newTab)),
|
|
82
|
-
|
|
110
|
+
applications.map(application => item(`desktop-${application.id}`, settingsIcon(), application.name,
|
|
111
|
+
() => void launch(application), desktopAgentText('opensApp', locale))),
|
|
112
|
+
error?.url && item('fallback', serviceIcon(), desktopAgentText('openFallback', locale), () => {
|
|
113
|
+
open(error.url, '_blank', 'noopener,noreferrer');
|
|
114
|
+
close();
|
|
115
|
+
}, newTab),
|
|
116
|
+
hasEntries && element('div', {role: 'separator', className: styles.aiAgentMenuSeparator}),
|
|
83
117
|
item('settings', settingsIcon(), agentText('settings', locale), () => {
|
|
84
118
|
close();
|
|
85
119
|
openSettings({locale, returnFocus: document.activeElement as HTMLElement});
|