@odysx/codemind 0.0.0-stage → 0.1.1
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 +293 -2
- package/dist/commands/agents.d.ts +2 -0
- package/dist/commands/agents.js +91 -0
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.js +35 -0
- package/dist/commands/chat.d.ts +2 -0
- package/dist/commands/chat.js +180 -0
- package/dist/commands/keys.d.ts +2 -0
- package/dist/commands/keys.js +81 -0
- package/dist/commands/local.d.ts +2 -0
- package/dist/commands/local.js +325 -0
- package/dist/commands/mcp.d.ts +2 -0
- package/dist/commands/mcp.js +73 -0
- package/dist/commands/prompts.d.ts +2 -0
- package/dist/commands/prompts.js +59 -0
- package/dist/commands/skills.d.ts +2 -0
- package/dist/commands/skills.js +41 -0
- package/dist/core/auth/index.d.ts +10 -0
- package/dist/core/auth/index.js +82 -0
- package/dist/core/config/index.d.ts +47 -0
- package/dist/core/config/index.js +118 -0
- package/dist/core/history.d.ts +14 -0
- package/dist/core/history.js +80 -0
- package/dist/core/markdown-renderer.d.ts +47 -0
- package/dist/core/markdown-renderer.js +385 -0
- package/dist/core/permissions/index.d.ts +31 -0
- package/dist/core/permissions/index.js +64 -0
- package/dist/core/provider/external.d.ts +28 -0
- package/dist/core/provider/external.js +248 -0
- package/dist/core/provider/index.d.ts +138 -0
- package/dist/core/provider/index.js +510 -0
- package/dist/core/registry/index.d.ts +25 -0
- package/dist/core/registry/index.js +216 -0
- package/dist/core/schema/types.d.ts +93 -0
- package/dist/core/schema/types.js +12 -0
- package/dist/core/terminal.d.ts +40 -0
- package/dist/core/terminal.js +134 -0
- package/dist/core/workspace/index.d.ts +35 -0
- package/dist/core/workspace/index.js +194 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +393 -0
- package/dist/ui/app.d.ts +3 -0
- package/dist/ui/app.js +554 -0
- package/dist/ui/commands/cases/catalog.d.ts +11 -0
- package/dist/ui/commands/cases/catalog.js +62 -0
- package/dist/ui/commands/cases/misc.d.ts +35 -0
- package/dist/ui/commands/cases/misc.js +245 -0
- package/dist/ui/commands/cases/tasks.d.ts +13 -0
- package/dist/ui/commands/cases/tasks.js +91 -0
- package/dist/ui/commands/runCommand.d.ts +22 -0
- package/dist/ui/commands/runCommand.js +136 -0
- package/dist/ui/components/AgentPicker.d.ts +11 -0
- package/dist/ui/components/AgentPicker.js +7 -0
- package/dist/ui/components/AuthPicker.d.ts +14 -0
- package/dist/ui/components/AuthPicker.js +7 -0
- package/dist/ui/components/Banner.d.ts +8 -0
- package/dist/ui/components/Banner.js +24 -0
- package/dist/ui/components/CommandMenu.d.ts +17 -0
- package/dist/ui/components/CommandMenu.js +21 -0
- package/dist/ui/components/ErrorBoundary.d.ts +24 -0
- package/dist/ui/components/ErrorBoundary.js +51 -0
- package/dist/ui/components/InputBar.d.ts +28 -0
- package/dist/ui/components/InputBar.js +108 -0
- package/dist/ui/components/KeysPanel.d.ts +12 -0
- package/dist/ui/components/KeysPanel.js +25 -0
- package/dist/ui/components/MessageView.d.ts +29 -0
- package/dist/ui/components/MessageView.js +107 -0
- package/dist/ui/components/PermissionPrompt.d.ts +10 -0
- package/dist/ui/components/PermissionPrompt.js +4 -0
- package/dist/ui/components/Pickers.d.ts +43 -0
- package/dist/ui/components/Pickers.js +33 -0
- package/dist/ui/components/SearchOverlay.d.ts +21 -0
- package/dist/ui/components/SearchOverlay.js +14 -0
- package/dist/ui/components/SessionPicker.d.ts +12 -0
- package/dist/ui/components/SessionPicker.js +8 -0
- package/dist/ui/components/WorkingIndicator.d.ts +10 -0
- package/dist/ui/components/WorkingIndicator.js +23 -0
- package/dist/ui/controls/ApiKeyEntry.d.ts +8 -0
- package/dist/ui/controls/ApiKeyEntry.js +5 -0
- package/dist/ui/controls/MultiSelect.d.ts +18 -0
- package/dist/ui/controls/MultiSelect.js +9 -0
- package/dist/ui/hooks/useAgentPicker.d.ts +14 -0
- package/dist/ui/hooks/useAgentPicker.js +53 -0
- package/dist/ui/hooks/useAuthFlow.d.ts +14 -0
- package/dist/ui/hooks/useAuthFlow.js +31 -0
- package/dist/ui/hooks/useKeysFlow.d.ts +17 -0
- package/dist/ui/hooks/useKeysFlow.js +130 -0
- package/dist/ui/hooks/useSessionPicker.d.ts +29 -0
- package/dist/ui/hooks/useSessionPicker.js +58 -0
- package/dist/ui/hooks/useTerminalSize.d.ts +6 -0
- package/dist/ui/hooks/useTerminalSize.js +29 -0
- package/dist/ui/input/keyRouter.d.ts +125 -0
- package/dist/ui/input/keyRouter.js +574 -0
- package/dist/ui/layouts/ScreenLayout.d.ts +98 -0
- package/dist/ui/layouts/ScreenLayout.js +56 -0
- package/dist/ui/shared/types.d.ts +143 -0
- package/dist/ui/shared/types.js +38 -0
- package/dist/ui/theme.d.ts +29 -0
- package/dist/ui/theme.js +54 -0
- package/dist/ui/utils/markdown.d.ts +74 -0
- package/dist/ui/utils/markdown.js +187 -0
- package/dist/ui/utils/mentions.d.ts +12 -0
- package/dist/ui/utils/mentions.js +28 -0
- package/dist/ui/utils/terminal-text.d.ts +33 -0
- package/dist/ui/utils/terminal-text.js +123 -0
- package/dist/ui/utils/text.d.ts +72 -0
- package/dist/ui/utils/text.js +171 -0
- package/package.json +50 -6
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MultiSelect — checkbox list for picking multiple options.
|
|
3
|
+
* space toggles a row · enter confirms · esc cancels (via parent).
|
|
4
|
+
*/
|
|
5
|
+
import React from "react";
|
|
6
|
+
export interface MultiSelectProps {
|
|
7
|
+
title: string;
|
|
8
|
+
options: Array<{
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
}>;
|
|
13
|
+
selectedIds: ReadonlySet<string>;
|
|
14
|
+
cursorIndex: number;
|
|
15
|
+
busy?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const MultiSelect: ({ title, options, selectedIds, cursorIndex, busy, }: MultiSelectProps) => React.JSX.Element;
|
|
18
|
+
//# sourceMappingURL=MultiSelect.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { theme } from "../theme.js";
|
|
4
|
+
export const MultiSelect = ({ title, options, selectedIds, cursorIndex, busy, }) => (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: theme.color.accent, paddingX: 1, marginBottom: 1, children: [_jsx(Text, { bold: true, color: theme.color.accent, children: title }), _jsx(Text, { dimColor: true, children: "\u2191/\u2193 to move \u00B7 space to toggle \u00B7 enter to confirm \u00B7 esc to cancel" }), _jsx(Box, { marginTop: 1, flexDirection: "column", children: busy ? (_jsx(Text, { dimColor: true, children: "Loading\u2026" })) : (options.map((opt, idx) => {
|
|
5
|
+
const isCursor = idx === cursorIndex;
|
|
6
|
+
const checked = selectedIds.has(opt.id);
|
|
7
|
+
return (_jsx(Box, { children: _jsxs(Text, { color: isCursor ? theme.color.accent : theme.color.muted, bold: isCursor, children: [isCursor ? `${theme.glyph.pointer} ` : " ", "[", checked ? theme.glyph.check : " ", "] ", opt.label, opt.description && _jsxs(Text, { dimColor: true, children: [" \u2014 ", opt.description] })] }) }, opt.id));
|
|
8
|
+
})) })] }));
|
|
9
|
+
//# sourceMappingURL=MultiSelect.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AgentOption } from "../shared/types.js";
|
|
2
|
+
export interface AgentPickerState {
|
|
3
|
+
open: boolean;
|
|
4
|
+
busy: boolean;
|
|
5
|
+
options: AgentOption[];
|
|
6
|
+
index: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const useAgentPicker: (addMessage: (text: string) => void) => {
|
|
9
|
+
agentPick: AgentPickerState;
|
|
10
|
+
setAgentPick: import("react").Dispatch<import("react").SetStateAction<AgentPickerState>>;
|
|
11
|
+
openAgentPicker: (currentAgentId: string) => Promise<void>;
|
|
12
|
+
agentNames: import("react").RefObject<Map<string, string>>;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=useAgentPicker.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /agent picker — option list + the id→display-name cache used by the footer.
|
|
3
|
+
*/
|
|
4
|
+
import { useCallback, useRef, useState } from "react";
|
|
5
|
+
const CLOSED = { open: false, busy: false, options: [], index: 0 };
|
|
6
|
+
export const useAgentPicker = (addMessage) => {
|
|
7
|
+
const [agentPick, setAgentPick] = useState(CLOSED);
|
|
8
|
+
/* id → display-name cache for the agent footer */
|
|
9
|
+
const agentNames = useRef(new Map([["master", "Master"]]));
|
|
10
|
+
const openAgentPicker = useCallback(async (currentAgentId) => {
|
|
11
|
+
setAgentPick({ open: true, busy: true, options: [], index: 0 });
|
|
12
|
+
let rows = [];
|
|
13
|
+
try {
|
|
14
|
+
const { apiCall } = await import("../../core/provider/index.js");
|
|
15
|
+
const res = await apiCall("/api/v1/agents");
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
addMessage(`✗ ${res.error}`);
|
|
18
|
+
setAgentPick(CLOSED);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
rows = Array.isArray(res.data) ? res.data : [];
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
addMessage(`✗ ${err instanceof Error ? err.message : String(err)}`);
|
|
25
|
+
setAgentPick(CLOSED);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Master first (auto-routing), then the user's published agents.
|
|
29
|
+
const names = new Map([["master", "Master"]]);
|
|
30
|
+
for (const a of rows) {
|
|
31
|
+
const id = (a.id ?? a.agent_id ?? "");
|
|
32
|
+
if (id && a.name)
|
|
33
|
+
names.set(id, a.name);
|
|
34
|
+
}
|
|
35
|
+
agentNames.current = names;
|
|
36
|
+
const options = [
|
|
37
|
+
{ id: "master", label: "master", description: "Auto-route to the best sub-agent" },
|
|
38
|
+
...rows
|
|
39
|
+
.filter((a) => (a.status ?? a.is_live ?? "published") !== "disabled")
|
|
40
|
+
.map((a) => ({
|
|
41
|
+
id: (a.id ?? a.agent_id ?? ""),
|
|
42
|
+
label: (a.name ?? (a.id ?? a.agent_id ?? "agent")),
|
|
43
|
+
description: (a.description ?? "").slice(0, 60),
|
|
44
|
+
}))
|
|
45
|
+
.filter((a) => a.id),
|
|
46
|
+
];
|
|
47
|
+
// Preselect the currently-active agent.
|
|
48
|
+
const idx = Math.max(0, options.findIndex((o) => o.id === currentAgentId));
|
|
49
|
+
setAgentPick({ open: true, busy: false, options, index: idx });
|
|
50
|
+
}, [addMessage]);
|
|
51
|
+
return { agentPick, setAgentPick, openAgentPicker, agentNames };
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=useAgentPicker.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type AuthMode = "closed" | "picker" | "api-key";
|
|
2
|
+
export interface AuthFlow {
|
|
3
|
+
authMode: AuthMode;
|
|
4
|
+
setAuthMode: React.Dispatch<React.SetStateAction<AuthMode>>;
|
|
5
|
+
authIndex: number;
|
|
6
|
+
setAuthIndex: React.Dispatch<React.SetStateAction<number>>;
|
|
7
|
+
apiKeyDraft: string;
|
|
8
|
+
setApiKeyDraft: React.Dispatch<React.SetStateAction<string>>;
|
|
9
|
+
authBusy: boolean;
|
|
10
|
+
/** Save the entered API key via core/auth, reporting the outcome. */
|
|
11
|
+
submitApiKey: (keyVal: string) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare const useAuthFlow: (addMessage: (text: string) => void) => AuthFlow;
|
|
14
|
+
//# sourceMappingURL=useAuthFlow.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /signin flow — method picker + masked API-key entry state and submission.
|
|
3
|
+
*/
|
|
4
|
+
import { useCallback, useState } from "react";
|
|
5
|
+
export const useAuthFlow = (addMessage) => {
|
|
6
|
+
const [authMode, setAuthMode] = useState("closed");
|
|
7
|
+
const [authIndex, setAuthIndex] = useState(0);
|
|
8
|
+
const [apiKeyDraft, setApiKeyDraft] = useState("");
|
|
9
|
+
const [authBusy, setAuthBusy] = useState(false);
|
|
10
|
+
const submitApiKey = useCallback(async (keyVal) => {
|
|
11
|
+
setAuthBusy(true);
|
|
12
|
+
try {
|
|
13
|
+
const { setApiKey } = await import("../../core/auth/index.js");
|
|
14
|
+
const r = await setApiKey(keyVal);
|
|
15
|
+
addMessage(r.error ? `✗ ${r.error}` : `✓ ${r.message ?? "API key saved"}`);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
const text = err instanceof Error ? err.message : String(err);
|
|
19
|
+
addMessage(`✗ ${text}`);
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
setAuthBusy(false);
|
|
23
|
+
setAuthMode("closed");
|
|
24
|
+
}
|
|
25
|
+
}, [addMessage]);
|
|
26
|
+
return {
|
|
27
|
+
authMode, setAuthMode, authIndex, setAuthIndex,
|
|
28
|
+
apiKeyDraft, setApiKeyDraft, authBusy, submitApiKey,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=useAuthFlow.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ApiKeyRow, ChatMessage, KeysState } from "../shared/types.js";
|
|
2
|
+
export interface KeysFlow {
|
|
3
|
+
keys: KeysState;
|
|
4
|
+
setKeys: React.Dispatch<React.SetStateAction<KeysState>>;
|
|
5
|
+
openKeysPanel: () => Promise<void>;
|
|
6
|
+
createKey: (name: string, scopes: string[]) => Promise<void>;
|
|
7
|
+
revokeSelected: () => Promise<void>;
|
|
8
|
+
showUsage: () => Promise<void>;
|
|
9
|
+
/** Record which listed key is active (label from key_prefix). Does not
|
|
10
|
+
* change the credential sent on requests — the backend only reveals a
|
|
11
|
+
* key's secret at creation time. */
|
|
12
|
+
selectKey: (row: ApiKeyRow) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare const useKeysFlow: (addMessage: (text: string) => void) => KeysFlow;
|
|
15
|
+
/** Convenience type re-export so callers don't import react types directly. */
|
|
16
|
+
export type { ChatMessage };
|
|
17
|
+
//# sourceMappingURL=useKeysFlow.d.ts.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /keys flow — panel state + the four API actions (list, create, revoke, usage).
|
|
3
|
+
*/
|
|
4
|
+
import { useCallback, useState } from "react";
|
|
5
|
+
const INITIAL = {
|
|
6
|
+
mode: "closed",
|
|
7
|
+
busy: false,
|
|
8
|
+
rows: [],
|
|
9
|
+
selectedIndex: 0,
|
|
10
|
+
draftName: "",
|
|
11
|
+
scopeCursor: 0,
|
|
12
|
+
scopeSelection: new Set(["chat"]),
|
|
13
|
+
createdKey: null,
|
|
14
|
+
activeKeyLabel: null,
|
|
15
|
+
};
|
|
16
|
+
export const useKeysFlow = (addMessage) => {
|
|
17
|
+
const [keys, setKeys] = useState(INITIAL);
|
|
18
|
+
const openKeysPanel = useCallback(async () => {
|
|
19
|
+
setKeys((k) => ({ ...k, mode: "menu", busy: true }));
|
|
20
|
+
try {
|
|
21
|
+
const { apiCall } = await import("../../core/provider/index.js");
|
|
22
|
+
const { getConfig } = await import("../../core/config/index.js");
|
|
23
|
+
const res = await apiCall("/api/v1/api-keys");
|
|
24
|
+
if (!res.ok) {
|
|
25
|
+
addMessage(`✗ ${res.error}`);
|
|
26
|
+
setKeys((k) => ({ ...k, mode: "closed", busy: false }));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const rows = Array.isArray(res.data) ? res.data : [];
|
|
30
|
+
setKeys((k) => ({
|
|
31
|
+
...k,
|
|
32
|
+
rows,
|
|
33
|
+
busy: false,
|
|
34
|
+
selectedIndex: 0,
|
|
35
|
+
activeKeyLabel: getConfig().activeKeyLabel ?? null,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
addMessage(`✗ ${err instanceof Error ? err.message : String(err)}`);
|
|
40
|
+
setKeys((k) => ({ ...k, mode: "closed", busy: false }));
|
|
41
|
+
}
|
|
42
|
+
}, [addMessage]);
|
|
43
|
+
const createKey = useCallback(async (name, scopes) => {
|
|
44
|
+
setKeys((k) => ({ ...k, busy: true }));
|
|
45
|
+
try {
|
|
46
|
+
const { apiCall } = await import("../../core/provider/index.js");
|
|
47
|
+
const res = await apiCall("/api/v1/api-keys", {
|
|
48
|
+
method: "POST",
|
|
49
|
+
body: { name, scopes },
|
|
50
|
+
});
|
|
51
|
+
if (!res.ok || !res.data?.key) {
|
|
52
|
+
addMessage(`✗ ${res.error ?? "Server did not return a key"}`);
|
|
53
|
+
setKeys((k) => ({ ...k, mode: "menu", busy: false }));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
setKeys((k) => ({
|
|
57
|
+
...k,
|
|
58
|
+
mode: "created",
|
|
59
|
+
busy: false,
|
|
60
|
+
createdKey: { key: res.data.key, name },
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
addMessage(`✗ ${err instanceof Error ? err.message : String(err)}`);
|
|
65
|
+
setKeys((k) => ({ ...k, mode: "menu", busy: false }));
|
|
66
|
+
}
|
|
67
|
+
}, [addMessage]);
|
|
68
|
+
const revokeSelected = useCallback(async () => {
|
|
69
|
+
const row = keys.rows[keys.selectedIndex];
|
|
70
|
+
if (!row || keys.busy)
|
|
71
|
+
return;
|
|
72
|
+
setKeys((k) => ({ ...k, busy: true }));
|
|
73
|
+
try {
|
|
74
|
+
const { apiCall } = await import("../../core/provider/index.js");
|
|
75
|
+
const res = await apiCall(`/api/v1/api-keys/${row.id}`, { method: "DELETE" });
|
|
76
|
+
if (!res.ok) {
|
|
77
|
+
addMessage(`✗ ${res.error}`);
|
|
78
|
+
setKeys((k) => ({ ...k, busy: false }));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
addMessage(`✓ Key revoked: ${row.name}`);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
addMessage(`✗ ${err instanceof Error ? err.message : String(err)}`);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
void openKeysPanel();
|
|
88
|
+
}
|
|
89
|
+
}, [keys.rows, keys.selectedIndex, keys.busy, openKeysPanel, addMessage]);
|
|
90
|
+
const showUsage = useCallback(async () => {
|
|
91
|
+
const row = keys.rows[keys.selectedIndex];
|
|
92
|
+
if (!row || keys.busy)
|
|
93
|
+
return;
|
|
94
|
+
setKeys((k) => ({ ...k, busy: true }));
|
|
95
|
+
try {
|
|
96
|
+
const { apiCall } = await import("../../core/provider/index.js");
|
|
97
|
+
const res = await apiCall(`/api/v1/api-keys/${row.id}/usage/summary`);
|
|
98
|
+
if (!res.ok) {
|
|
99
|
+
addMessage(`✗ ${res.error}`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const d = res.data ?? {};
|
|
103
|
+
addMessage(`Usage for ${row.name}:\n` +
|
|
104
|
+
` requests: ${d.total_requests ?? 0}\n` +
|
|
105
|
+
` tokens: ${d.total_tokens ?? 0}\n` +
|
|
106
|
+
` cost: $${Number(d.total_cost_usd ?? 0).toFixed(4)}\n` +
|
|
107
|
+
` avg lat: ${Math.round(Number(d.avg_latency_ms ?? 0))}ms`);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
addMessage(`✗ ${err instanceof Error ? err.message : String(err)}`);
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
setKeys((k) => ({ ...k, busy: false }));
|
|
114
|
+
}
|
|
115
|
+
}, [keys.rows, keys.selectedIndex, keys.busy, addMessage]);
|
|
116
|
+
const selectKey = useCallback(async (row) => {
|
|
117
|
+
if (!row?.key_prefix) {
|
|
118
|
+
addMessage("✗ Key has no prefix — cannot label it as active.");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const label = row.key_prefix.slice(0, 12);
|
|
122
|
+
const { updateConfig } = await import("../../core/config/index.js");
|
|
123
|
+
updateConfig({ activeKeyLabel: label });
|
|
124
|
+
setKeys((k) => ({ ...k, activeKeyLabel: label }));
|
|
125
|
+
addMessage(`Active key label → ${label}… (${row.name}). ` +
|
|
126
|
+
"This is a local marker; requests still use the credential saved with `odysx auth set-key`.");
|
|
127
|
+
}, [addMessage]);
|
|
128
|
+
return { keys, setKeys, openKeysPanel, createKey, revokeSelected, showUsage, selectKey };
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=useKeysFlow.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
import type { Role } from "../shared/types.js";
|
|
3
|
+
export interface SessionRow {
|
|
4
|
+
session_id: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
agent_name?: string;
|
|
7
|
+
agent_id?: string;
|
|
8
|
+
updated_at?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SessionPickerState {
|
|
11
|
+
open: boolean;
|
|
12
|
+
busy: boolean;
|
|
13
|
+
rows: SessionRow[];
|
|
14
|
+
index: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const useSessionPicker: (addMessage: (text: string) => void, sessionIdRef: RefObject<string>, setMessages: React.Dispatch<React.SetStateAction<Array<{
|
|
17
|
+
role: Role;
|
|
18
|
+
text: string;
|
|
19
|
+
agentName?: string;
|
|
20
|
+
}>>>, loadHistoryMessages: (msgs: Array<{
|
|
21
|
+
role: string;
|
|
22
|
+
content: string;
|
|
23
|
+
}>) => void) => {
|
|
24
|
+
sessionPick: SessionPickerState;
|
|
25
|
+
setSessionPick: import("react").Dispatch<import("react").SetStateAction<SessionPickerState>>;
|
|
26
|
+
resumeSession: (sid: string) => Promise<void>;
|
|
27
|
+
openSessionPicker: () => Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=useSessionPicker.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /sessions picker — list state + resume flow.
|
|
3
|
+
* `sessionId` lives in a ref owned by app.tsx; this hook reads/writes it via
|
|
4
|
+
* the passed-in ref so command cases never touch a module-level mutable.
|
|
5
|
+
*/
|
|
6
|
+
import { useCallback, useState } from "react";
|
|
7
|
+
const CLOSED = { open: false, busy: false, rows: [], index: 0 };
|
|
8
|
+
export const useSessionPicker = (addMessage, sessionIdRef, setMessages, loadHistoryMessages) => {
|
|
9
|
+
const [sessionPick, setSessionPick] = useState(CLOSED);
|
|
10
|
+
/** Resume the given session: swap sessionId and load its history. */
|
|
11
|
+
const resumeSession = useCallback(async (sid) => {
|
|
12
|
+
setSessionPick((p) => ({ ...p, open: false, busy: true }));
|
|
13
|
+
try {
|
|
14
|
+
const { apiCall } = await import("../../core/provider/index.js");
|
|
15
|
+
const res = await apiCall(`/api/v1/llm/history/${encodeURIComponent(sid)}`);
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
addMessage(`✗ ${res.error}`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const messages = Array.isArray(res.data?.messages) ? res.data.messages : [];
|
|
21
|
+
sessionIdRef.current = res.data?.session_id || sid;
|
|
22
|
+
loadHistoryMessages(messages);
|
|
23
|
+
addMessage(`✓ Resumed session ${sid.slice(0, 12)} — ${messages.length} messages restored`);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
addMessage(`✗ Could not resume session: ${err instanceof Error ? err.message : String(err)}`);
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
setSessionPick(CLOSED);
|
|
30
|
+
}
|
|
31
|
+
}, [addMessage, sessionIdRef, loadHistoryMessages]);
|
|
32
|
+
const openSessionPicker = useCallback(async () => {
|
|
33
|
+
setSessionPick({ open: true, busy: true, rows: [], index: 0 });
|
|
34
|
+
try {
|
|
35
|
+
const { apiCall } = await import("../../core/provider/index.js");
|
|
36
|
+
// API wraps the list: { sessions: [...] }
|
|
37
|
+
const res = await apiCall("/api/v1/llm/sessions");
|
|
38
|
+
if (!res.ok) {
|
|
39
|
+
addMessage(`✗ ${res.error}`);
|
|
40
|
+
setSessionPick(CLOSED);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const rows = Array.isArray(res.data?.sessions) ? res.data.sessions : [];
|
|
44
|
+
if (!rows.length) {
|
|
45
|
+
addMessage("No past sessions. Start chatting to create one.");
|
|
46
|
+
setSessionPick(CLOSED);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
setSessionPick({ open: true, busy: false, rows: rows.slice(0, 15), index: 0 });
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
addMessage(`✗ ${err instanceof Error ? err.message : String(err)}`);
|
|
53
|
+
setSessionPick(CLOSED);
|
|
54
|
+
}
|
|
55
|
+
}, [addMessage]);
|
|
56
|
+
return { sessionPick, setSessionPick, resumeSession, openSessionPicker };
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=useSessionPicker.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal-size hook.
|
|
3
|
+
*
|
|
4
|
+
* Ink only re-renders on input/state changes; a window resize would otherwise
|
|
5
|
+
* leave the footer and command menu laid out for the old width until the next
|
|
6
|
+
* keystroke. Subscribing to the stream's `resize` event keeps the layout live.
|
|
7
|
+
*/
|
|
8
|
+
import { useEffect, useState } from "react";
|
|
9
|
+
import { useStdout } from "ink";
|
|
10
|
+
const read = (stdout) => ({
|
|
11
|
+
columns: stdout?.columns ?? 80,
|
|
12
|
+
rows: stdout?.rows ?? 24,
|
|
13
|
+
});
|
|
14
|
+
export const useTerminalSize = () => {
|
|
15
|
+
const { stdout } = useStdout();
|
|
16
|
+
const [size, setSize] = useState(() => read(stdout));
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!stdout)
|
|
19
|
+
return;
|
|
20
|
+
const onResize = () => setSize(read(stdout));
|
|
21
|
+
stdout.on("resize", onResize);
|
|
22
|
+
onResize();
|
|
23
|
+
return () => {
|
|
24
|
+
stdout.off("resize", onResize);
|
|
25
|
+
};
|
|
26
|
+
}, [stdout]);
|
|
27
|
+
return size;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=useTerminalSize.js.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global keyboard router. One function, checked top-to-bottom — the ORDER is
|
|
3
|
+
* behavior-critical (most-specific overlay first, base editing last):
|
|
4
|
+
* pendingOp → keys modes → sessions picker → agent picker →
|
|
5
|
+
* auth picker → api-key entry → streaming → base editing/menu/history.
|
|
6
|
+
*/
|
|
7
|
+
import type { RefObject } from "react";
|
|
8
|
+
import type { AgentOption, ChatMessage, KeysState, PendingOp } from "../shared/types.js";
|
|
9
|
+
import type { AuthMode } from "../hooks/useAuthFlow.js";
|
|
10
|
+
import type { SearchRow } from "../components/SearchOverlay.js";
|
|
11
|
+
export interface KeyRouterDeps {
|
|
12
|
+
/** Folder trust gate. Nothing else is interactive until it is resolved. */
|
|
13
|
+
trust: {
|
|
14
|
+
pending: boolean;
|
|
15
|
+
index: number;
|
|
16
|
+
};
|
|
17
|
+
setTrust: React.Dispatch<React.SetStateAction<{
|
|
18
|
+
pending: boolean;
|
|
19
|
+
index: number;
|
|
20
|
+
}>>;
|
|
21
|
+
/** Ctrl+/ command palette and Ctrl+R history search. null = closed. */
|
|
22
|
+
search: {
|
|
23
|
+
mode: "commands" | "history" | null;
|
|
24
|
+
query: string;
|
|
25
|
+
index: number;
|
|
26
|
+
};
|
|
27
|
+
commandRows: SearchRow[];
|
|
28
|
+
historyRows: SearchRow[];
|
|
29
|
+
pendingOp: PendingOp | null;
|
|
30
|
+
keys: KeysState;
|
|
31
|
+
sessionPick: {
|
|
32
|
+
open: boolean;
|
|
33
|
+
busy: boolean;
|
|
34
|
+
rows: Array<{
|
|
35
|
+
session_id: string;
|
|
36
|
+
}>;
|
|
37
|
+
index: number;
|
|
38
|
+
};
|
|
39
|
+
agentPick: {
|
|
40
|
+
open: boolean;
|
|
41
|
+
busy: boolean;
|
|
42
|
+
options: AgentOption[];
|
|
43
|
+
index: number;
|
|
44
|
+
};
|
|
45
|
+
authMode: AuthMode;
|
|
46
|
+
authIndex: number;
|
|
47
|
+
authBusy: boolean;
|
|
48
|
+
apiKeyDraft: string;
|
|
49
|
+
streaming: boolean;
|
|
50
|
+
input: string;
|
|
51
|
+
/** Caret position within `input` (character index). */
|
|
52
|
+
cursor: number;
|
|
53
|
+
history: string[];
|
|
54
|
+
historyIndex: number;
|
|
55
|
+
menuOpen: boolean;
|
|
56
|
+
filteredCommands: Array<{
|
|
57
|
+
name: string;
|
|
58
|
+
}>;
|
|
59
|
+
clampedMenuIndex: number;
|
|
60
|
+
menuWordLength: number;
|
|
61
|
+
setSearch: React.Dispatch<React.SetStateAction<{
|
|
62
|
+
mode: "commands" | "history" | null;
|
|
63
|
+
query: string;
|
|
64
|
+
index: number;
|
|
65
|
+
}>>;
|
|
66
|
+
trustFolder: () => void;
|
|
67
|
+
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>;
|
|
68
|
+
setPendingOp: (op: PendingOp | null) => void;
|
|
69
|
+
setKeys: React.Dispatch<React.SetStateAction<KeysState>>;
|
|
70
|
+
openKeysPanel: () => Promise<void>;
|
|
71
|
+
createKey: (name: string, scopes: string[]) => Promise<void>;
|
|
72
|
+
resumeSession: (sid: string) => Promise<void>;
|
|
73
|
+
setSessionPick: React.Dispatch<React.SetStateAction<{
|
|
74
|
+
open: boolean;
|
|
75
|
+
busy: boolean;
|
|
76
|
+
rows: Array<{
|
|
77
|
+
session_id: string;
|
|
78
|
+
}>;
|
|
79
|
+
index: number;
|
|
80
|
+
}>>;
|
|
81
|
+
setAgentId: (id: string) => void;
|
|
82
|
+
setAgentPick: React.Dispatch<React.SetStateAction<{
|
|
83
|
+
open: boolean;
|
|
84
|
+
busy: boolean;
|
|
85
|
+
options: AgentOption[];
|
|
86
|
+
index: number;
|
|
87
|
+
}>>;
|
|
88
|
+
setAuthMode: React.Dispatch<React.SetStateAction<AuthMode>>;
|
|
89
|
+
setAuthIndex: React.Dispatch<React.SetStateAction<number>>;
|
|
90
|
+
setApiKeyDraft: React.Dispatch<React.SetStateAction<string>>;
|
|
91
|
+
submitApiKey: (keyVal: string) => Promise<void>;
|
|
92
|
+
runLocal: (cliArgs: string[]) => Promise<void>;
|
|
93
|
+
revokeSelected: () => Promise<void>;
|
|
94
|
+
showUsage: () => Promise<void>;
|
|
95
|
+
/** Set the persisted local active-key label from the selected row. */
|
|
96
|
+
selectKey: (row: KeysState["rows"][number]) => void;
|
|
97
|
+
submit: () => Promise<void> | void;
|
|
98
|
+
setMenuIndex: React.Dispatch<React.SetStateAction<number>>;
|
|
99
|
+
setInput: React.Dispatch<React.SetStateAction<string>>;
|
|
100
|
+
setCursor: React.Dispatch<React.SetStateAction<number>>;
|
|
101
|
+
setHistory: React.Dispatch<React.SetStateAction<string[]>>;
|
|
102
|
+
setHistoryIndex: React.Dispatch<React.SetStateAction<number>>;
|
|
103
|
+
historyDraftRef: RefObject<string>;
|
|
104
|
+
abortRef: RefObject<AbortController | null>;
|
|
105
|
+
queuedSubmitRef: RefObject<string | null>;
|
|
106
|
+
runCommand: (raw: string) => void;
|
|
107
|
+
requestExit: () => void;
|
|
108
|
+
}
|
|
109
|
+
type InkKey = {
|
|
110
|
+
upArrow: boolean;
|
|
111
|
+
downArrow: boolean;
|
|
112
|
+
leftArrow?: boolean;
|
|
113
|
+
rightArrow?: boolean;
|
|
114
|
+
return: boolean;
|
|
115
|
+
escape: boolean;
|
|
116
|
+
backspace?: boolean;
|
|
117
|
+
delete?: boolean;
|
|
118
|
+
tab?: boolean;
|
|
119
|
+
ctrl?: boolean;
|
|
120
|
+
meta?: boolean;
|
|
121
|
+
shift?: boolean;
|
|
122
|
+
};
|
|
123
|
+
export declare const handleKey: (chunk: string, key: InkKey, d: KeyRouterDeps) => void;
|
|
124
|
+
export {};
|
|
125
|
+
//# sourceMappingURL=keyRouter.d.ts.map
|