xtralab 0.10.0 → 0.11.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 +23 -9
- package/lib/commandBar/index.d.ts +14 -0
- package/lib/commandBar/index.js +114 -0
- package/lib/fileBrowser/fileBrowser.js +6 -1
- package/lib/highlight/index.d.ts +15 -0
- package/lib/highlight/index.js +214 -0
- package/lib/index.js +13 -1
- package/lib/launcher/agents.d.ts +7 -0
- package/lib/launcher/agents.js +24 -0
- package/lib/launcher/editorRegistry.js +5 -3
- package/lib/launcher/editors.d.ts +8 -0
- package/lib/launcher/editors.js +17 -0
- package/lib/launcher/index.js +4 -0
- package/lib/launcher/schemaDefaults.d.ts +15 -0
- package/lib/launcher/schemaDefaults.js +44 -0
- package/lib/omnibox/files.d.ts +7 -0
- package/lib/omnibox/files.js +50 -0
- package/lib/omnibox/index.d.ts +14 -0
- package/lib/omnibox/index.js +83 -0
- package/lib/omnibox/model.d.ts +45 -0
- package/lib/omnibox/model.js +142 -0
- package/lib/omnibox/tokens.d.ts +23 -0
- package/lib/omnibox/tokens.js +11 -0
- package/lib/omnibox/widget.d.ts +36 -0
- package/lib/omnibox/widget.js +161 -0
- package/lib/searchReplace/index.d.ts +25 -0
- package/lib/searchReplace/index.js +68 -0
- package/lib/showOutput/index.d.ts +17 -0
- package/lib/showOutput/index.js +154 -0
- package/lib/terminals/index.d.ts +4 -0
- package/lib/terminals/index.js +65 -16
- package/lib/terminals/model.d.ts +56 -3
- package/lib/terminals/model.js +261 -5
- package/lib/terminals/widget.d.ts +3 -1
- package/lib/terminals/widget.js +11 -3
- package/lib/walkthrough/index.d.ts +14 -0
- package/lib/walkthrough/index.js +162 -0
- package/lib/walkthrough/panel.d.ts +54 -0
- package/lib/walkthrough/panel.js +98 -0
- package/package.json +1 -1
- package/schema/launcher.json +3 -2
- package/schema/terminals.json +15 -0
- package/src/commandBar/index.ts +165 -0
- package/src/fileBrowser/fileBrowser.tsx +8 -1
- package/src/highlight/index.ts +251 -0
- package/src/index.ts +13 -1
- package/src/launcher/agents.ts +25 -0
- package/src/launcher/editorRegistry.ts +8 -4
- package/src/launcher/editors.ts +18 -0
- package/src/launcher/index.ts +4 -0
- package/src/launcher/schemaDefaults.ts +53 -0
- package/src/omnibox/files.ts +68 -0
- package/src/omnibox/index.ts +105 -0
- package/src/omnibox/model.ts +210 -0
- package/src/omnibox/tokens.ts +29 -0
- package/src/omnibox/widget.tsx +322 -0
- package/src/searchReplace/index.ts +86 -0
- package/src/showOutput/index.ts +199 -0
- package/src/terminals/index.ts +79 -16
- package/src/terminals/model.ts +304 -3
- package/src/terminals/widget.tsx +21 -4
- package/src/walkthrough/index.ts +202 -0
- package/src/walkthrough/panel.ts +152 -0
- package/style/commandBar.css +104 -0
- package/style/highlight.css +11 -0
- package/style/index.css +5 -0
- package/style/index.js +5 -0
- package/style/omnibox.css +120 -0
- package/style/showOutput.css +11 -0
- package/style/terminals.css +54 -10
- package/style/walkthrough.css +80 -0
|
@@ -13,6 +13,10 @@ import {
|
|
|
13
13
|
type IEditor,
|
|
14
14
|
type IEditorSettings
|
|
15
15
|
} from './editors';
|
|
16
|
+
import {
|
|
17
|
+
LAUNCHER_PLUGIN_ID,
|
|
18
|
+
registerLauncherSchemaDefaults
|
|
19
|
+
} from './schemaDefaults';
|
|
16
20
|
|
|
17
21
|
/**
|
|
18
22
|
* A read-only, observable view of the launcher's terminal editors: xtralab's
|
|
@@ -80,9 +84,6 @@ class EditorRegistry implements IEditorRegistry {
|
|
|
80
84
|
private _changed = new Signal<IEditorRegistry, void>(this);
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
/** Schema id the `editors` setting lives under (shared with the launcher). */
|
|
84
|
-
const LAUNCHER_SETTINGS_ID = 'xtralab:launcher';
|
|
85
|
-
|
|
86
87
|
/**
|
|
87
88
|
* Provides {@link IEditorRegistry}: merges xtralab's built-in editors with the
|
|
88
89
|
* user's `editors` setting, probes the server's `$PATH` to resolve the launcher
|
|
@@ -124,8 +125,11 @@ export const editorRegistryPlugin: JupyterFrontEndPlugin<IEditorRegistry> = {
|
|
|
124
125
|
};
|
|
125
126
|
|
|
126
127
|
if (settingRegistry) {
|
|
128
|
+
// Must precede the first `load`: the schema defers loading until a
|
|
129
|
+
// transform is registered.
|
|
130
|
+
registerLauncherSchemaDefaults(settingRegistry);
|
|
127
131
|
try {
|
|
128
|
-
const settings = await settingRegistry.load(
|
|
132
|
+
const settings = await settingRegistry.load(LAUNCHER_PLUGIN_ID);
|
|
129
133
|
await apply(readOverrides(settings));
|
|
130
134
|
settings.changed.connect(async () => {
|
|
131
135
|
try {
|
package/src/launcher/editors.ts
CHANGED
|
@@ -88,6 +88,24 @@ const DEFAULTS: IEditor[] = [
|
|
|
88
88
|
}
|
|
89
89
|
];
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* The built-in editors projected into the JSON settings shape
|
|
93
|
+
* ({@link IEditorSettings}), dropping the runtime-only {@link LabIcon}. Mirrors
|
|
94
|
+
* {@link defaultAgentSettings}: {@link registerLauncherSchemaDefaults} injects
|
|
95
|
+
* this as the `editors` setting's schema default so the Settings Editor shows
|
|
96
|
+
* the shipped list.
|
|
97
|
+
*/
|
|
98
|
+
export function defaultEditorSettings(): IEditorSettings[] {
|
|
99
|
+
return DEFAULTS.map(editor => ({
|
|
100
|
+
id: editor.id,
|
|
101
|
+
label: editor.label,
|
|
102
|
+
caption: editor.caption,
|
|
103
|
+
command: editor.command,
|
|
104
|
+
rank: editor.rank,
|
|
105
|
+
requireAvailable: editor.requireAvailable
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
|
|
91
109
|
function resolveEditorIcon(id: string, iconSvg: string | undefined): LabIcon {
|
|
92
110
|
if (iconSvg) {
|
|
93
111
|
return new LabIcon({
|
package/src/launcher/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { CREATE_LAUNCHER_COMMAND, registerAgentCommands } from './commands';
|
|
|
19
19
|
import { LauncherDashboard } from './dashboard';
|
|
20
20
|
import { editorRegistryPlugin, IEditorRegistry } from './editorRegistry';
|
|
21
21
|
import { AgentRegistry } from './registry';
|
|
22
|
+
import { registerLauncherSchemaDefaults } from './schemaDefaults';
|
|
22
23
|
import { IAgentRegistry } from './tokens';
|
|
23
24
|
|
|
24
25
|
const PLUGIN_ID = 'xtralab:launcher';
|
|
@@ -110,6 +111,9 @@ const plugin: JupyterFrontEndPlugin<IAgentRegistry> = {
|
|
|
110
111
|
};
|
|
111
112
|
|
|
112
113
|
if (settingRegistry) {
|
|
114
|
+
// Must precede the first `load`: the schema defers loading until a
|
|
115
|
+
// transform is registered.
|
|
116
|
+
registerLauncherSchemaDefaults(settingRegistry);
|
|
113
117
|
try {
|
|
114
118
|
const settings = await settingRegistry.load(PLUGIN_ID);
|
|
115
119
|
await applyAgents(readOverrides(settings));
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PartialJSONValue } from '@lumino/coreutils';
|
|
2
|
+
import type { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
3
|
+
|
|
4
|
+
import { defaultAgentSettings } from './agents';
|
|
5
|
+
import { defaultEditorSettings } from './editors';
|
|
6
|
+
|
|
7
|
+
/** Schema id the launcher's `agents`/`editors` settings live under. */
|
|
8
|
+
export const LAUNCHER_PLUGIN_ID = 'xtralab:launcher';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Setting registries that already have the transform, so both callers skip
|
|
12
|
+
* re-registering (the registry rejects a duplicate transformer).
|
|
13
|
+
*/
|
|
14
|
+
const registered = new WeakSet<ISettingRegistry>();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Register a `fetch` transform that injects xtralab's built-in agent and
|
|
18
|
+
* editor lists as the schema defaults for the `xtralab:launcher` settings, so
|
|
19
|
+
* the Settings Editor shows the shipped list.
|
|
20
|
+
*
|
|
21
|
+
* The schema declares `jupyter.lab.transform: true`, so the registry defers
|
|
22
|
+
* loading the plugin until a transform is registered: callers must invoke this
|
|
23
|
+
* before their first `settingRegistry.load(LAUNCHER_PLUGIN_ID)`. Idempotent, so
|
|
24
|
+
* the two plugins that load these settings can both call it regardless of
|
|
25
|
+
* activation order.
|
|
26
|
+
*/
|
|
27
|
+
export function registerLauncherSchemaDefaults(
|
|
28
|
+
settingRegistry: ISettingRegistry
|
|
29
|
+
): void {
|
|
30
|
+
if (registered.has(settingRegistry)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
registered.add(settingRegistry);
|
|
34
|
+
|
|
35
|
+
settingRegistry.transform(LAUNCHER_PLUGIN_ID, {
|
|
36
|
+
fetch: plugin => {
|
|
37
|
+
const properties = plugin.schema.properties;
|
|
38
|
+
if (properties) {
|
|
39
|
+
// The settings shapes are plain JSON by construction, but their named
|
|
40
|
+
// interfaces lack an index signature, so cast at this TS→JSON boundary.
|
|
41
|
+
if (properties.agents) {
|
|
42
|
+
properties.agents.default =
|
|
43
|
+
defaultAgentSettings() as unknown as PartialJSONValue;
|
|
44
|
+
}
|
|
45
|
+
if (properties.editors) {
|
|
46
|
+
properties.editors.default =
|
|
47
|
+
defaultEditorSettings() as unknown as PartialJSONValue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return plugin;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { URLExt } from '@jupyterlab/coreutils';
|
|
2
|
+
import { ServerConnection } from '@jupyterlab/services';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shape of the `jupyterlab-quickopen` `api/files` response: a map from each
|
|
6
|
+
* directory (relative to the server root, `""` for the root itself) to the
|
|
7
|
+
* bare filenames it contains.
|
|
8
|
+
*/
|
|
9
|
+
interface IQuickOpenContents {
|
|
10
|
+
contents: { [dir: string]: string[] };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Fetch and flatten the workspace file list from `jupyterlab-quickopen`'s
|
|
15
|
+
* server endpoint (`GET {base}/jupyterlab-quickopen/api/files`).
|
|
16
|
+
*
|
|
17
|
+
* We reuse quickopen's endpoint rather than walking the contents API so the
|
|
18
|
+
* listing honors the same server-side `.gitignore` filtering quickopen does
|
|
19
|
+
* (xtralab ships `respectGitignore: true`) in a single request. The endpoint
|
|
20
|
+
* only exists when quickopen's server extension is installed and the server
|
|
21
|
+
* reads a local filesystem; callers treat a rejection as "no file results".
|
|
22
|
+
*/
|
|
23
|
+
async function fetchWorkspaceFiles(respectGitignore = true): Promise<string[]> {
|
|
24
|
+
const settings = ServerConnection.makeSettings();
|
|
25
|
+
const params = new URLSearchParams();
|
|
26
|
+
if (respectGitignore) {
|
|
27
|
+
params.append('respect_gitignore', '1');
|
|
28
|
+
}
|
|
29
|
+
// The handler requires a `path` argument; `""` scans from the root.
|
|
30
|
+
params.append('path', '');
|
|
31
|
+
const url =
|
|
32
|
+
URLExt.join(settings.baseUrl, 'jupyterlab-quickopen', 'api', 'files') +
|
|
33
|
+
`?${params.toString()}`;
|
|
34
|
+
|
|
35
|
+
const response = await ServerConnection.makeRequest(
|
|
36
|
+
url,
|
|
37
|
+
{ method: 'GET' },
|
|
38
|
+
settings
|
|
39
|
+
);
|
|
40
|
+
if (response.status !== 200) {
|
|
41
|
+
throw new ServerConnection.ResponseError(response);
|
|
42
|
+
}
|
|
43
|
+
const data = (await response.json()) as IQuickOpenContents;
|
|
44
|
+
const paths: string[] = [];
|
|
45
|
+
for (const dir in data.contents) {
|
|
46
|
+
for (const name of data.contents[dir]) {
|
|
47
|
+
paths.push(dir ? `${dir}/${name}` : name);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return paths;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const CACHE_TTL_MS = 15_000;
|
|
54
|
+
let cache: { at: number; files: Promise<string[]> } | null = null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The workspace file list, cached briefly so reopening the omnibox in quick
|
|
58
|
+
* succession reuses one scan. A failed fetch (e.g. quickopen's server
|
|
59
|
+
* extension is absent) resolves to an empty list so file search degrades to
|
|
60
|
+
* "no results" instead of surfacing an error.
|
|
61
|
+
*/
|
|
62
|
+
export function loadWorkspaceFiles(): Promise<string[]> {
|
|
63
|
+
const now = Date.now();
|
|
64
|
+
if (!cache || now - cache.at > CACHE_TTL_MS) {
|
|
65
|
+
cache = { at: now, files: fetchWorkspaceFiles().catch(() => []) };
|
|
66
|
+
}
|
|
67
|
+
return cache.files;
|
|
68
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JupyterFrontEnd,
|
|
3
|
+
JupyterFrontEndPlugin
|
|
4
|
+
} from '@jupyterlab/application';
|
|
5
|
+
import { ICommandPalette } from '@jupyterlab/apputils';
|
|
6
|
+
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
|
|
7
|
+
import { Widget } from '@lumino/widgets';
|
|
8
|
+
|
|
9
|
+
import { IAgentRegistry } from '../launcher/tokens';
|
|
10
|
+
|
|
11
|
+
import { IOmnibox, OMNIBOX_OPEN_COMMAND } from './tokens';
|
|
12
|
+
import { OmniboxWidget } from './widget';
|
|
13
|
+
|
|
14
|
+
const PLUGIN_ID = 'xtralab:omnibox';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The omnibox: a single launcher overlay that fuzzy-searches workspace files
|
|
18
|
+
* (via jupyterlab-quickopen's gitignore-aware endpoint) and JupyterLab
|
|
19
|
+
* commands, and routes a typed prompt to one of the configured agents (running
|
|
20
|
+
* it in a fresh terminal through the launcher's `xtralab:start-agent:<id>`
|
|
21
|
+
* commands). It is opened by the top-bar command bar.
|
|
22
|
+
*
|
|
23
|
+
* The agent rows come from the launcher's `IAgentRegistry`; when the launcher
|
|
24
|
+
* is disabled the omnibox still searches files and commands.
|
|
25
|
+
*/
|
|
26
|
+
const plugin: JupyterFrontEndPlugin<IOmnibox> = {
|
|
27
|
+
id: PLUGIN_ID,
|
|
28
|
+
description:
|
|
29
|
+
'A launcher overlay that searches files and commands and prompts agents.',
|
|
30
|
+
autoStart: true,
|
|
31
|
+
provides: IOmnibox,
|
|
32
|
+
optional: [IAgentRegistry, ICommandPalette, ITranslator],
|
|
33
|
+
activate: (
|
|
34
|
+
app: JupyterFrontEnd,
|
|
35
|
+
agentRegistry: IAgentRegistry | null,
|
|
36
|
+
palette: ICommandPalette | null,
|
|
37
|
+
translator: ITranslator | null
|
|
38
|
+
): IOmnibox => {
|
|
39
|
+
const { commands, docRegistry } = app;
|
|
40
|
+
const trans = (translator ?? nullTranslator).load('jupyterlab');
|
|
41
|
+
const placeholder = trans.__('Search files and commands, or ask an agent…');
|
|
42
|
+
|
|
43
|
+
let current: OmniboxWidget | null = null;
|
|
44
|
+
|
|
45
|
+
const close = (): void => {
|
|
46
|
+
const widget = current;
|
|
47
|
+
current = null;
|
|
48
|
+
widget?.dispose();
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const open = (query?: string): void => {
|
|
52
|
+
// Reopen fresh each time so the input resets and the agent snapshot is
|
|
53
|
+
// current; the file list is cached separately (see files.ts).
|
|
54
|
+
close();
|
|
55
|
+
const widget = new OmniboxWidget({
|
|
56
|
+
commands,
|
|
57
|
+
docRegistry,
|
|
58
|
+
agents: agentRegistry ? agentRegistry.agents : [],
|
|
59
|
+
placeholder,
|
|
60
|
+
initialQuery: query ?? '',
|
|
61
|
+
trans,
|
|
62
|
+
onClose: close
|
|
63
|
+
});
|
|
64
|
+
current = widget;
|
|
65
|
+
widget.disposed.connect(() => {
|
|
66
|
+
if (current === widget) {
|
|
67
|
+
current = null;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
Widget.attach(widget, document.body);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
commands.addCommand(OMNIBOX_OPEN_COMMAND, {
|
|
74
|
+
label: trans.__('Search…'),
|
|
75
|
+
caption: trans.__('Search files and commands, or ask an agent'),
|
|
76
|
+
execute: args => {
|
|
77
|
+
// Toggle: a second press (e.g. of the keyboard shortcut) closes it.
|
|
78
|
+
if (current && !current.isDisposed) {
|
|
79
|
+
close();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const query = args['query'];
|
|
83
|
+
open(typeof query === 'string' ? query : undefined);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Open the omnibox with Cmd/Ctrl+K, the common "command center" chord.
|
|
88
|
+
commands.addKeyBinding({
|
|
89
|
+
command: OMNIBOX_OPEN_COMMAND,
|
|
90
|
+
keys: ['Accel K'],
|
|
91
|
+
selector: 'body'
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (palette) {
|
|
95
|
+
palette.addItem({
|
|
96
|
+
command: OMNIBOX_OPEN_COMMAND,
|
|
97
|
+
category: trans.__('Other')
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return { open, close };
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export default plugin;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import type { DocumentRegistry } from '@jupyterlab/docregistry';
|
|
2
|
+
import type { TranslationBundle } from '@jupyterlab/translation';
|
|
3
|
+
import { fileIcon, LabIcon } from '@jupyterlab/ui-components';
|
|
4
|
+
import { StringExt } from '@lumino/algorithm';
|
|
5
|
+
import type { CommandRegistry } from '@lumino/commands';
|
|
6
|
+
|
|
7
|
+
import type { IAgent } from '../launcher/agents';
|
|
8
|
+
import { agentCommandId } from '../launcher/tokens';
|
|
9
|
+
|
|
10
|
+
/** The source a result row came from, used to group rows under a header. */
|
|
11
|
+
export type OmniboxItemKind = 'command' | 'file' | 'agent';
|
|
12
|
+
|
|
13
|
+
/** A single result row, with the action it runs when chosen. */
|
|
14
|
+
export interface IOmniboxItem {
|
|
15
|
+
kind: OmniboxItemKind;
|
|
16
|
+
/** Stable React key. */
|
|
17
|
+
key: string;
|
|
18
|
+
/** Primary text shown on the row. */
|
|
19
|
+
label: string;
|
|
20
|
+
/** Indices of matched characters in `label`, for highlighting. May be empty. */
|
|
21
|
+
matchIndices: readonly number[];
|
|
22
|
+
/** Optional secondary text shown trailing the label. */
|
|
23
|
+
caption?: string;
|
|
24
|
+
/** Optional leading icon. */
|
|
25
|
+
icon?: LabIcon;
|
|
26
|
+
/** Run the row's action. */
|
|
27
|
+
execute: () => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Results grouped by source; each group is already capped and sorted. */
|
|
31
|
+
export interface IOmniboxSections {
|
|
32
|
+
commands: IOmniboxItem[];
|
|
33
|
+
files: IOmniboxItem[];
|
|
34
|
+
agents: IOmniboxItem[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface IComputeOptions {
|
|
38
|
+
query: string;
|
|
39
|
+
commands: CommandRegistry;
|
|
40
|
+
docRegistry: DocumentRegistry;
|
|
41
|
+
agents: IAgent[];
|
|
42
|
+
files: string[];
|
|
43
|
+
trans: TranslationBundle;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const COMMAND_LIMIT = 7;
|
|
47
|
+
const FILE_LIMIT = 10;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Prefixes that narrow the search to a single source: a leading `>` to
|
|
51
|
+
* commands, a leading `/` to files (relative paths never start with `/`, so it
|
|
52
|
+
* is unambiguous). Without a prefix, every source is searched.
|
|
53
|
+
*/
|
|
54
|
+
const COMMAND_PREFIX = '>';
|
|
55
|
+
const FILE_PREFIX = '/';
|
|
56
|
+
|
|
57
|
+
type Mode = 'all' | 'commands' | 'files';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Build the grouped result set for a query. A leading `>` searches only
|
|
61
|
+
* commands and a leading `/` only files; otherwise commands and files are
|
|
62
|
+
* fuzzy-matched and every prompt-capable agent is offered an "Ask" row
|
|
63
|
+
* carrying the query as its prompt. An empty term yields no rows (the widget
|
|
64
|
+
* shows a hint instead).
|
|
65
|
+
*/
|
|
66
|
+
export function computeSections(options: IComputeOptions): IOmniboxSections {
|
|
67
|
+
const { query, commands, docRegistry, agents, files, trans } = options;
|
|
68
|
+
const trimmed = query.trim();
|
|
69
|
+
|
|
70
|
+
let mode: Mode = 'all';
|
|
71
|
+
let term = trimmed;
|
|
72
|
+
if (trimmed.startsWith(COMMAND_PREFIX)) {
|
|
73
|
+
mode = 'commands';
|
|
74
|
+
term = trimmed.slice(COMMAND_PREFIX.length).trim();
|
|
75
|
+
} else if (trimmed.startsWith(FILE_PREFIX)) {
|
|
76
|
+
mode = 'files';
|
|
77
|
+
term = trimmed.slice(FILE_PREFIX.length).trim();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!term) {
|
|
81
|
+
return { commands: [], files: [], agents: [] };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
commands: mode === 'files' ? [] : matchCommands(commands, term),
|
|
86
|
+
files:
|
|
87
|
+
mode === 'commands' ? [] : matchFiles(commands, docRegistry, files, term),
|
|
88
|
+
// Agents only in the unprefixed view; the prompt is the full typed query.
|
|
89
|
+
agents: mode === 'all' ? buildAgentItems(commands, agents, term, trans) : []
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function matchCommands(
|
|
94
|
+
commands: CommandRegistry,
|
|
95
|
+
term: string
|
|
96
|
+
): IOmniboxItem[] {
|
|
97
|
+
const query = term.toLowerCase();
|
|
98
|
+
const scored: Array<{ score: number; item: IOmniboxItem }> = [];
|
|
99
|
+
for (const id of commands.listCommands()) {
|
|
100
|
+
let label = '';
|
|
101
|
+
let visible = true;
|
|
102
|
+
let caption = '';
|
|
103
|
+
try {
|
|
104
|
+
// A command's accessors can throw if they assume a context (e.g. an
|
|
105
|
+
// active notebook) the omnibox doesn't provide; skip those.
|
|
106
|
+
label = commands.label(id);
|
|
107
|
+
visible = commands.isVisible(id);
|
|
108
|
+
caption = commands.caption(id);
|
|
109
|
+
} catch {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (!label || !visible) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const match = StringExt.matchSumOfSquares(label.toLowerCase(), query);
|
|
116
|
+
if (!match) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
scored.push({
|
|
120
|
+
score: match.score,
|
|
121
|
+
item: {
|
|
122
|
+
kind: 'command',
|
|
123
|
+
key: `command:${id}`,
|
|
124
|
+
label,
|
|
125
|
+
matchIndices: match.indices,
|
|
126
|
+
caption: caption || undefined,
|
|
127
|
+
execute: () => {
|
|
128
|
+
void commands.execute(id).catch(reason => {
|
|
129
|
+
console.error(`xtralab omnibox: command "${id}" failed`, reason);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
scored.sort((a, b) => a.score - b.score);
|
|
136
|
+
return scored.slice(0, COMMAND_LIMIT).map(entry => entry.item);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function matchFiles(
|
|
140
|
+
commands: CommandRegistry,
|
|
141
|
+
docRegistry: DocumentRegistry,
|
|
142
|
+
files: string[],
|
|
143
|
+
term: string
|
|
144
|
+
): IOmniboxItem[] {
|
|
145
|
+
const query = term.toLowerCase();
|
|
146
|
+
const scored: Array<{ score: number; path: string; indices: number[] }> = [];
|
|
147
|
+
for (const path of files) {
|
|
148
|
+
const match = StringExt.matchSumOfSquares(path.toLowerCase(), query);
|
|
149
|
+
if (match) {
|
|
150
|
+
scored.push({ score: match.score, path, indices: match.indices });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
scored.sort((a, b) => a.score - b.score);
|
|
154
|
+
return scored.slice(0, FILE_LIMIT).map(({ path, indices }) => ({
|
|
155
|
+
kind: 'file',
|
|
156
|
+
key: `file:${path}`,
|
|
157
|
+
label: path,
|
|
158
|
+
matchIndices: indices,
|
|
159
|
+
icon: fileIconForPath(docRegistry, path),
|
|
160
|
+
execute: () => {
|
|
161
|
+
void commands.execute('docmanager:open', { path }).catch(reason => {
|
|
162
|
+
console.error(`xtralab omnibox: failed to open "${path}"`, reason);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function fileIconForPath(docRegistry: DocumentRegistry, path: string): LabIcon {
|
|
169
|
+
for (const fileType of docRegistry.getFileTypesForPath(path)) {
|
|
170
|
+
if (fileType.icon) {
|
|
171
|
+
return fileType.icon;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return fileIcon;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function buildAgentItems(
|
|
178
|
+
commands: CommandRegistry,
|
|
179
|
+
agents: IAgent[],
|
|
180
|
+
prompt: string,
|
|
181
|
+
trans: TranslationBundle
|
|
182
|
+
): IOmniboxItem[] {
|
|
183
|
+
const items: IOmniboxItem[] = [];
|
|
184
|
+
for (const agent of agents) {
|
|
185
|
+
// Agents without `promptArgs` can't take an inline prompt (the launcher
|
|
186
|
+
// would drop it), so they don't belong in an "Ask …" row.
|
|
187
|
+
if (agent.promptArgs === undefined) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
items.push({
|
|
191
|
+
kind: 'agent',
|
|
192
|
+
key: `agent:${agent.id}`,
|
|
193
|
+
label: trans.__('Ask %1', agent.label),
|
|
194
|
+
matchIndices: [],
|
|
195
|
+
caption: trans.__('Run prompt in a new terminal'),
|
|
196
|
+
icon: agent.icon,
|
|
197
|
+
execute: () => {
|
|
198
|
+
void commands
|
|
199
|
+
.execute(agentCommandId(agent.id), { prompt })
|
|
200
|
+
.catch(reason => {
|
|
201
|
+
console.error(
|
|
202
|
+
`xtralab omnibox: failed to start agent "${agent.id}"`,
|
|
203
|
+
reason
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return items;
|
|
210
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Token } from '@lumino/coreutils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A launcher overlay that fuzzy-searches across multiple sources — workspace
|
|
5
|
+
* files, JupyterLab commands — and routes a typed prompt to one of the
|
|
6
|
+
* configured agents. Provided by `xtralab:omnibox` and consumed (optionally)
|
|
7
|
+
* by the top-bar command bar, which opens it on click.
|
|
8
|
+
*/
|
|
9
|
+
export interface IOmnibox {
|
|
10
|
+
/** Open the overlay, optionally seeding the input with `query`. */
|
|
11
|
+
open(query?: string): void;
|
|
12
|
+
/** Close the overlay if it is open. */
|
|
13
|
+
close(): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* DI token for {@link IOmnibox}. Provided by `xtralab:omnibox`; consumed by
|
|
18
|
+
* `xtralab:command-bar` so the top-bar pill opens the omnibox.
|
|
19
|
+
*/
|
|
20
|
+
export const IOmnibox = new Token<IOmnibox>(
|
|
21
|
+
'xtralab:IOmnibox',
|
|
22
|
+
'Opens the omnibox overlay that searches files and commands and prompts agents.'
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Command id that opens the omnibox (registered by `xtralab:omnibox`). Shared
|
|
27
|
+
* here so the command bar can look up its keybinding and show a shortcut hint.
|
|
28
|
+
*/
|
|
29
|
+
export const OMNIBOX_OPEN_COMMAND = 'xtralab:omnibox:open';
|