toolcraft-openapi 0.0.20 → 0.0.21
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/node_modules/@poe-code/design-system/dist/components/browser.d.ts +15 -0
- package/node_modules/@poe-code/design-system/dist/components/browser.js +26 -0
- package/node_modules/@poe-code/design-system/dist/explorer/index.d.ts +1 -1
- package/node_modules/@poe-code/design-system/dist/explorer/keymap.js +6 -3
- package/node_modules/@poe-code/design-system/dist/explorer/render/footer.js +14 -0
- package/node_modules/@poe-code/design-system/dist/explorer/runtime.js +11 -4
- package/node_modules/@poe-code/design-system/dist/explorer/state.d.ts +6 -1
- package/node_modules/@poe-code/design-system/dist/index.d.ts +2 -1
- package/node_modules/@poe-code/design-system/dist/index.js +1 -0
- package/node_modules/auth-store/dist/provider-store.js +4 -2
- package/package.json +2 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface BrowserProcess {
|
|
2
|
+
once(event: "error", listener: (error: Error) => void): this;
|
|
3
|
+
once(event: "spawn", listener: () => void): this;
|
|
4
|
+
unref(): void;
|
|
5
|
+
}
|
|
6
|
+
type SpawnBrowserProcess = (command: string, args: string[], options: {
|
|
7
|
+
detached: true;
|
|
8
|
+
stdio: "ignore";
|
|
9
|
+
}) => BrowserProcess;
|
|
10
|
+
export interface OpenExternalOptions {
|
|
11
|
+
platform?: NodeJS.Platform;
|
|
12
|
+
spawnProcess?: SpawnBrowserProcess;
|
|
13
|
+
}
|
|
14
|
+
export declare function openExternal(url: string, options?: OpenExternalOptions): Promise<void>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
export async function openExternal(url, options = {}) {
|
|
4
|
+
const parsed = new URL(url);
|
|
5
|
+
const { command, args } = browserCommand(parsed.href, options.platform ?? process.platform);
|
|
6
|
+
await launchBrowser(command, args, options.spawnProcess ?? spawn);
|
|
7
|
+
}
|
|
8
|
+
function browserCommand(url, platform) {
|
|
9
|
+
if (platform === "darwin") {
|
|
10
|
+
return { command: "open", args: [url] };
|
|
11
|
+
}
|
|
12
|
+
if (platform === "win32") {
|
|
13
|
+
return { command: "cmd", args: ["/c", "start", "", url] };
|
|
14
|
+
}
|
|
15
|
+
return { command: "xdg-open", args: [url] };
|
|
16
|
+
}
|
|
17
|
+
function launchBrowser(command, args, spawnProcess) {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const child = spawnProcess(command, args, { detached: true, stdio: "ignore" });
|
|
20
|
+
child.once("error", reject);
|
|
21
|
+
child.once("spawn", () => {
|
|
22
|
+
child.unref();
|
|
23
|
+
resolve();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -4,5 +4,5 @@ export { createInitialState } from "./state.js";
|
|
|
4
4
|
export { resolveBindings } from "./keymap.js";
|
|
5
5
|
export type { Effect, ExplorerEvent } from "./events.js";
|
|
6
6
|
export type { BindingTarget, ExplorerBindingDefaults, ExplorerBuiltinCommand, ResolvedBindings } from "./keymap.js";
|
|
7
|
-
export type { Action, ActionContext, Detail, DetailCtx, DetailItem, Dirty, ExplorerConfig, ExplorerLayoutMode, ExplorerSize, ExplorerState, Row, Tone } from "./state.js";
|
|
7
|
+
export type { Action, ActionContext, Detail, DetailCtx, DetailItem, Dirty, ExplorerConfig, ExplorerLayoutMode, ExplorerSize, ExplorerState, ReorderContext, Row, Tone } from "./state.js";
|
|
8
8
|
export declare function singleDetail<R>(fn: (row: Row, ctx: DetailCtx) => string | Promise<string>): Detail<R>;
|
|
@@ -19,8 +19,8 @@ const builtinBindings = {
|
|
|
19
19
|
detailScrollUp: ["Ctrl+b"],
|
|
20
20
|
extendSelectionUp: ["Shift+up"],
|
|
21
21
|
extendSelectionDown: ["Shift+down"],
|
|
22
|
-
reorderUp: ["
|
|
23
|
-
reorderDown: ["
|
|
22
|
+
reorderUp: ["Shift+up", "K"],
|
|
23
|
+
reorderDown: ["Shift+down", "J"]
|
|
24
24
|
};
|
|
25
25
|
const baseBuiltinCommands = [
|
|
26
26
|
"quit",
|
|
@@ -49,7 +49,10 @@ const reservedActionIds = new Set(["quit"]);
|
|
|
49
49
|
export function resolveBindings(config, defaults = {}) {
|
|
50
50
|
const commands = config.reorder === undefined
|
|
51
51
|
? baseBuiltinCommands
|
|
52
|
-
: [
|
|
52
|
+
: [
|
|
53
|
+
...baseBuiltinCommands.filter((command) => command !== "extendSelectionUp" && command !== "extendSelectionDown"),
|
|
54
|
+
...reorderCommands
|
|
55
|
+
];
|
|
53
56
|
const commandBindings = new Map();
|
|
54
57
|
const flatBindings = new Map();
|
|
55
58
|
const targetKeys = new Map();
|
|
@@ -13,6 +13,12 @@ export function renderFooter(state, screen, layout) {
|
|
|
13
13
|
if (x >= rect.x + rect.width) {
|
|
14
14
|
break;
|
|
15
15
|
}
|
|
16
|
+
if (hint.bracketed === false) {
|
|
17
|
+
const text = `${hint.key} ${hint.label}`;
|
|
18
|
+
screen.put(x, y, text, hint.running ? styles.muted : {});
|
|
19
|
+
x += text.length + 2;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
16
22
|
screen.put(x, y, `[${hint.key}]`, hint.running ? styles.muted : styles.accent);
|
|
17
23
|
x += hint.key.length + 2;
|
|
18
24
|
screen.put(x, y, ` ${hint.label}`, hint.running ? styles.muted : {});
|
|
@@ -37,9 +43,17 @@ function footerHints(state) {
|
|
|
37
43
|
}
|
|
38
44
|
hints.push({ key: "?", label: "help", running: false });
|
|
39
45
|
hints.push({ key: "Ctrl+P", label: "palette", running: false });
|
|
46
|
+
if (hasShiftReorderBindings(state)) {
|
|
47
|
+
hints.push({ key: "⇧↑↓", label: "reorder (within state)", running: false, bracketed: false });
|
|
48
|
+
}
|
|
40
49
|
hints.push({ key: "q", label: "quit", running: false });
|
|
41
50
|
return hints;
|
|
42
51
|
}
|
|
52
|
+
function hasShiftReorderBindings(state) {
|
|
53
|
+
const up = state.bindings.keysByTarget.get("builtin:reorderUp") ?? [];
|
|
54
|
+
const down = state.bindings.keysByTarget.get("builtin:reorderDown") ?? [];
|
|
55
|
+
return up.includes("Shift+up") && down.includes("Shift+down");
|
|
56
|
+
}
|
|
43
57
|
function actionKey(entry, fallback) {
|
|
44
58
|
const key = entry.action?.key;
|
|
45
59
|
if (Array.isArray(key)) {
|
|
@@ -36,7 +36,7 @@ class ExplorerRuntime {
|
|
|
36
36
|
});
|
|
37
37
|
this.runtimeHandles = {
|
|
38
38
|
refresh: async () => {
|
|
39
|
-
await this.
|
|
39
|
+
await this.refreshRowsFromSource();
|
|
40
40
|
},
|
|
41
41
|
suspendAnd: async (fn) => this.suspendAnd(fn),
|
|
42
42
|
toast: (msg, tone) => {
|
|
@@ -54,7 +54,7 @@ class ExplorerRuntime {
|
|
|
54
54
|
try {
|
|
55
55
|
this.startTerminal();
|
|
56
56
|
this.render();
|
|
57
|
-
this.
|
|
57
|
+
this.loadRows().catch((error) => {
|
|
58
58
|
this.fail(error);
|
|
59
59
|
});
|
|
60
60
|
}
|
|
@@ -76,10 +76,14 @@ class ExplorerRuntime {
|
|
|
76
76
|
this.dispatch({ type: "resize", cols: size.cols, rows: size.rows });
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
-
async
|
|
79
|
+
async loadRows() {
|
|
80
80
|
const rows = await this.config.rows();
|
|
81
81
|
this.dispatch({ type: "rowsLoaded", rows });
|
|
82
82
|
}
|
|
83
|
+
async refreshRowsFromSource() {
|
|
84
|
+
await this.config.refresh?.();
|
|
85
|
+
await this.loadRows();
|
|
86
|
+
}
|
|
83
87
|
dispatch(event) {
|
|
84
88
|
if (this.stopped) {
|
|
85
89
|
return;
|
|
@@ -128,7 +132,10 @@ class ExplorerRuntime {
|
|
|
128
132
|
}
|
|
129
133
|
async persistOrder(orderedIds, previousRows) {
|
|
130
134
|
try {
|
|
131
|
-
await this.config.reorder?.onReorder(orderedIds
|
|
135
|
+
await this.config.reorder?.onReorder(orderedIds, {
|
|
136
|
+
refresh: this.runtimeHandles.refresh,
|
|
137
|
+
toast: this.runtimeHandles.toast
|
|
138
|
+
});
|
|
132
139
|
}
|
|
133
140
|
catch (error) {
|
|
134
141
|
this.showToast(error instanceof Error ? error.message : "Could not persist order", "error");
|
|
@@ -51,13 +51,18 @@ export interface ActionContext<R> {
|
|
|
51
51
|
confirm: (prompt: string) => Promise<boolean>;
|
|
52
52
|
exit: (after?: () => void | Promise<void>) => void;
|
|
53
53
|
}
|
|
54
|
+
export interface ReorderContext {
|
|
55
|
+
refresh: () => Promise<void>;
|
|
56
|
+
toast: (msg: string, tone?: Tone) => void;
|
|
57
|
+
}
|
|
54
58
|
export interface ExplorerConfig<R> {
|
|
55
59
|
title: string;
|
|
56
60
|
rows: () => Promise<Row[]>;
|
|
61
|
+
refresh?: () => Promise<void>;
|
|
57
62
|
detail: Detail<R>;
|
|
58
63
|
actions: Action<R>[];
|
|
59
64
|
reorder?: {
|
|
60
|
-
onReorder: (orderedIds: string[]) => void | Promise<void>;
|
|
65
|
+
onReorder: (orderedIds: string[], ctx?: ReorderContext) => void | Promise<void>;
|
|
61
66
|
};
|
|
62
67
|
multiSelect?: boolean;
|
|
63
68
|
keybindOverrides?: Record<string, string | string[]>;
|
|
@@ -19,13 +19,14 @@ export { renderTable } from "./components/table.js";
|
|
|
19
19
|
export type { TableColumn, RenderTableOptions } from "./components/table.js";
|
|
20
20
|
export { renderTemplate } from "./components/template.js";
|
|
21
21
|
export type { RenderTemplateOptions, TemplateEscape } from "./components/template.js";
|
|
22
|
+
export { openExternal } from "./components/browser.js";
|
|
22
23
|
export * as acp from "./acp/index.js";
|
|
23
24
|
export * as dashboard from "./dashboard/index.js";
|
|
24
25
|
export { createDashboard, shouldUseInteractiveDashboard } from "./dashboard/index.js";
|
|
25
26
|
export type { Dashboard, DashboardOptions } from "./dashboard/index.js";
|
|
26
27
|
export * as explorer from "./explorer/index.js";
|
|
27
28
|
export { runExplorer, singleDetail } from "./explorer/index.js";
|
|
28
|
-
export type { Row, DetailItem, Detail, DetailCtx, Action, ActionContext, ExplorerConfig, Tone, } from "./explorer/index.js";
|
|
29
|
+
export type { Row, DetailItem, Detail, DetailCtx, Action, ActionContext, ExplorerConfig, ReorderContext, Tone, } from "./explorer/index.js";
|
|
29
30
|
export * as prompts from "./prompts/index.js";
|
|
30
31
|
export { intro, introPlain, outro, note, select, multiselect, text as promptText, confirm, confirmOrCancel, password, spinner, withSpinner, isCancel, cancel, log, PromptCancelledError } from "./prompts/index.js";
|
|
31
32
|
export type { SelectOptions, MultiselectOptions, TextOptions, ConfirmOptions, PasswordOptions, SpinnerOptions, WithSpinnerOptions } from "./prompts/index.js";
|
|
@@ -15,6 +15,7 @@ export { formatCommandNotFound } from "./components/command-errors.js";
|
|
|
15
15
|
export { formatCommandNotFoundPanel } from "./components/command-errors.js";
|
|
16
16
|
export { renderTable } from "./components/table.js";
|
|
17
17
|
export { renderTemplate } from "./components/template.js";
|
|
18
|
+
export { openExternal } from "./components/browser.js";
|
|
18
19
|
// ACP rendering
|
|
19
20
|
export * as acp from "./acp/index.js";
|
|
20
21
|
// Dashboard
|
|
@@ -20,9 +20,11 @@ export class MigratingSecretStore {
|
|
|
20
20
|
return legacyValue;
|
|
21
21
|
}
|
|
22
22
|
async set(value) {
|
|
23
|
-
|
|
23
|
+
await this.store.set(value);
|
|
24
|
+
await this.legacyStore?.set(value);
|
|
24
25
|
}
|
|
25
26
|
async delete() {
|
|
26
|
-
|
|
27
|
+
await this.store.delete();
|
|
28
|
+
await this.legacyStore?.delete();
|
|
27
29
|
}
|
|
28
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toolcraft-openapi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@clack/prompts": "^1.0.0",
|
|
33
33
|
"@poe-code/design-system": "^0.0.2",
|
|
34
34
|
"auth-store": "^0.0.1",
|
|
35
|
-
"toolcraft": "^0.0.
|
|
35
|
+
"toolcraft": "^0.0.21",
|
|
36
36
|
"yaml": "^2.8.2"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|