@odysx/codemind 0.0.0-stage → 0.1.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 +293 -2
- package/dist/commands/agents.d.ts +2 -0
- package/dist/commands/agents.d.ts.map +1 -0
- package/dist/commands/agents.js +91 -0
- package/dist/commands/agents.js.map +1 -0
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +35 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/chat.d.ts +2 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +180 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/keys.d.ts +2 -0
- package/dist/commands/keys.d.ts.map +1 -0
- package/dist/commands/keys.js +81 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/local.d.ts +2 -0
- package/dist/commands/local.d.ts.map +1 -0
- package/dist/commands/local.js +325 -0
- package/dist/commands/local.js.map +1 -0
- package/dist/commands/mcp.d.ts +2 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +73 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/prompts.d.ts +2 -0
- package/dist/commands/prompts.d.ts.map +1 -0
- package/dist/commands/prompts.js +59 -0
- package/dist/commands/prompts.js.map +1 -0
- package/dist/commands/skills.d.ts +2 -0
- package/dist/commands/skills.d.ts.map +1 -0
- package/dist/commands/skills.js +41 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/core/auth/index.d.ts +10 -0
- package/dist/core/auth/index.d.ts.map +1 -0
- package/dist/core/auth/index.js +82 -0
- package/dist/core/auth/index.js.map +1 -0
- package/dist/core/config/index.d.ts +47 -0
- package/dist/core/config/index.d.ts.map +1 -0
- package/dist/core/config/index.js +118 -0
- package/dist/core/config/index.js.map +1 -0
- package/dist/core/history.d.ts +14 -0
- package/dist/core/history.d.ts.map +1 -0
- package/dist/core/history.js +80 -0
- package/dist/core/history.js.map +1 -0
- package/dist/core/markdown-renderer.d.ts +47 -0
- package/dist/core/markdown-renderer.d.ts.map +1 -0
- package/dist/core/markdown-renderer.js +385 -0
- package/dist/core/markdown-renderer.js.map +1 -0
- package/dist/core/permissions/index.d.ts +31 -0
- package/dist/core/permissions/index.d.ts.map +1 -0
- package/dist/core/permissions/index.js +64 -0
- package/dist/core/permissions/index.js.map +1 -0
- package/dist/core/provider/external.d.ts +28 -0
- package/dist/core/provider/external.d.ts.map +1 -0
- package/dist/core/provider/external.js +248 -0
- package/dist/core/provider/external.js.map +1 -0
- package/dist/core/provider/index.d.ts +96 -0
- package/dist/core/provider/index.d.ts.map +1 -0
- package/dist/core/provider/index.js +423 -0
- package/dist/core/provider/index.js.map +1 -0
- package/dist/core/registry/index.d.ts +25 -0
- package/dist/core/registry/index.d.ts.map +1 -0
- package/dist/core/registry/index.js +216 -0
- package/dist/core/registry/index.js.map +1 -0
- package/dist/core/schema/types.d.ts +93 -0
- package/dist/core/schema/types.d.ts.map +1 -0
- package/dist/core/schema/types.js +12 -0
- package/dist/core/schema/types.js.map +1 -0
- package/dist/core/terminal.d.ts +40 -0
- package/dist/core/terminal.d.ts.map +1 -0
- package/dist/core/terminal.js +134 -0
- package/dist/core/terminal.js.map +1 -0
- package/dist/core/workspace/index.d.ts +35 -0
- package/dist/core/workspace/index.d.ts.map +1 -0
- package/dist/core/workspace/index.js +194 -0
- package/dist/core/workspace/index.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +393 -0
- package/dist/index.js.map +1 -0
- package/dist/ui/app.d.ts +3 -0
- package/dist/ui/app.d.ts.map +1 -0
- package/dist/ui/app.js +554 -0
- package/dist/ui/app.js.map +1 -0
- package/dist/ui/commands/cases/catalog.d.ts +11 -0
- package/dist/ui/commands/cases/catalog.d.ts.map +1 -0
- package/dist/ui/commands/cases/catalog.js +62 -0
- package/dist/ui/commands/cases/catalog.js.map +1 -0
- package/dist/ui/commands/cases/misc.d.ts +35 -0
- package/dist/ui/commands/cases/misc.d.ts.map +1 -0
- package/dist/ui/commands/cases/misc.js +245 -0
- package/dist/ui/commands/cases/misc.js.map +1 -0
- package/dist/ui/commands/cases/tasks.d.ts +13 -0
- package/dist/ui/commands/cases/tasks.d.ts.map +1 -0
- package/dist/ui/commands/cases/tasks.js +91 -0
- package/dist/ui/commands/cases/tasks.js.map +1 -0
- package/dist/ui/commands/runCommand.d.ts +22 -0
- package/dist/ui/commands/runCommand.d.ts.map +1 -0
- package/dist/ui/commands/runCommand.js +136 -0
- package/dist/ui/commands/runCommand.js.map +1 -0
- package/dist/ui/components/AgentPicker.d.ts +11 -0
- package/dist/ui/components/AgentPicker.d.ts.map +1 -0
- package/dist/ui/components/AgentPicker.js +7 -0
- package/dist/ui/components/AgentPicker.js.map +1 -0
- package/dist/ui/components/AuthPicker.d.ts +14 -0
- package/dist/ui/components/AuthPicker.d.ts.map +1 -0
- package/dist/ui/components/AuthPicker.js +7 -0
- package/dist/ui/components/AuthPicker.js.map +1 -0
- package/dist/ui/components/Banner.d.ts +8 -0
- package/dist/ui/components/Banner.d.ts.map +1 -0
- package/dist/ui/components/Banner.js +24 -0
- package/dist/ui/components/Banner.js.map +1 -0
- package/dist/ui/components/CommandMenu.d.ts +17 -0
- package/dist/ui/components/CommandMenu.d.ts.map +1 -0
- package/dist/ui/components/CommandMenu.js +21 -0
- package/dist/ui/components/CommandMenu.js.map +1 -0
- package/dist/ui/components/ErrorBoundary.d.ts +24 -0
- package/dist/ui/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/ui/components/ErrorBoundary.js +51 -0
- package/dist/ui/components/ErrorBoundary.js.map +1 -0
- package/dist/ui/components/InputBar.d.ts +28 -0
- package/dist/ui/components/InputBar.d.ts.map +1 -0
- package/dist/ui/components/InputBar.js +108 -0
- package/dist/ui/components/InputBar.js.map +1 -0
- package/dist/ui/components/KeysPanel.d.ts +12 -0
- package/dist/ui/components/KeysPanel.d.ts.map +1 -0
- package/dist/ui/components/KeysPanel.js +25 -0
- package/dist/ui/components/KeysPanel.js.map +1 -0
- package/dist/ui/components/MessageView.d.ts +29 -0
- package/dist/ui/components/MessageView.d.ts.map +1 -0
- package/dist/ui/components/MessageView.js +107 -0
- package/dist/ui/components/MessageView.js.map +1 -0
- package/dist/ui/components/PermissionPrompt.d.ts +10 -0
- package/dist/ui/components/PermissionPrompt.d.ts.map +1 -0
- package/dist/ui/components/PermissionPrompt.js +4 -0
- package/dist/ui/components/PermissionPrompt.js.map +1 -0
- package/dist/ui/components/Pickers.d.ts +43 -0
- package/dist/ui/components/Pickers.d.ts.map +1 -0
- package/dist/ui/components/Pickers.js +33 -0
- package/dist/ui/components/Pickers.js.map +1 -0
- package/dist/ui/components/SearchOverlay.d.ts +21 -0
- package/dist/ui/components/SearchOverlay.d.ts.map +1 -0
- package/dist/ui/components/SearchOverlay.js +14 -0
- package/dist/ui/components/SearchOverlay.js.map +1 -0
- package/dist/ui/components/SessionPicker.d.ts +12 -0
- package/dist/ui/components/SessionPicker.d.ts.map +1 -0
- package/dist/ui/components/SessionPicker.js +8 -0
- package/dist/ui/components/SessionPicker.js.map +1 -0
- package/dist/ui/components/WorkingIndicator.d.ts +10 -0
- package/dist/ui/components/WorkingIndicator.d.ts.map +1 -0
- package/dist/ui/components/WorkingIndicator.js +23 -0
- package/dist/ui/components/WorkingIndicator.js.map +1 -0
- package/dist/ui/controls/ApiKeyEntry.d.ts +8 -0
- package/dist/ui/controls/ApiKeyEntry.d.ts.map +1 -0
- package/dist/ui/controls/ApiKeyEntry.js +5 -0
- package/dist/ui/controls/ApiKeyEntry.js.map +1 -0
- package/dist/ui/controls/MultiSelect.d.ts +18 -0
- package/dist/ui/controls/MultiSelect.d.ts.map +1 -0
- package/dist/ui/controls/MultiSelect.js +9 -0
- package/dist/ui/controls/MultiSelect.js.map +1 -0
- package/dist/ui/hooks/useAgentPicker.d.ts +14 -0
- package/dist/ui/hooks/useAgentPicker.d.ts.map +1 -0
- package/dist/ui/hooks/useAgentPicker.js +53 -0
- package/dist/ui/hooks/useAgentPicker.js.map +1 -0
- package/dist/ui/hooks/useAuthFlow.d.ts +14 -0
- package/dist/ui/hooks/useAuthFlow.d.ts.map +1 -0
- package/dist/ui/hooks/useAuthFlow.js +31 -0
- package/dist/ui/hooks/useAuthFlow.js.map +1 -0
- package/dist/ui/hooks/useKeysFlow.d.ts +17 -0
- package/dist/ui/hooks/useKeysFlow.d.ts.map +1 -0
- package/dist/ui/hooks/useKeysFlow.js +130 -0
- package/dist/ui/hooks/useKeysFlow.js.map +1 -0
- package/dist/ui/hooks/useSessionPicker.d.ts +29 -0
- package/dist/ui/hooks/useSessionPicker.d.ts.map +1 -0
- package/dist/ui/hooks/useSessionPicker.js +58 -0
- package/dist/ui/hooks/useSessionPicker.js.map +1 -0
- package/dist/ui/hooks/useTerminalSize.d.ts +6 -0
- package/dist/ui/hooks/useTerminalSize.d.ts.map +1 -0
- package/dist/ui/hooks/useTerminalSize.js +29 -0
- package/dist/ui/hooks/useTerminalSize.js.map +1 -0
- package/dist/ui/input/keyRouter.d.ts +125 -0
- package/dist/ui/input/keyRouter.d.ts.map +1 -0
- package/dist/ui/input/keyRouter.js +574 -0
- package/dist/ui/input/keyRouter.js.map +1 -0
- package/dist/ui/layouts/ScreenLayout.d.ts +98 -0
- package/dist/ui/layouts/ScreenLayout.d.ts.map +1 -0
- package/dist/ui/layouts/ScreenLayout.js +56 -0
- package/dist/ui/layouts/ScreenLayout.js.map +1 -0
- package/dist/ui/shared/types.d.ts +143 -0
- package/dist/ui/shared/types.d.ts.map +1 -0
- package/dist/ui/shared/types.js +38 -0
- package/dist/ui/shared/types.js.map +1 -0
- package/dist/ui/theme.d.ts +29 -0
- package/dist/ui/theme.d.ts.map +1 -0
- package/dist/ui/theme.js +54 -0
- package/dist/ui/theme.js.map +1 -0
- package/dist/ui/utils/markdown.d.ts +74 -0
- package/dist/ui/utils/markdown.d.ts.map +1 -0
- package/dist/ui/utils/markdown.js +187 -0
- package/dist/ui/utils/markdown.js.map +1 -0
- package/dist/ui/utils/mentions.d.ts +12 -0
- package/dist/ui/utils/mentions.d.ts.map +1 -0
- package/dist/ui/utils/mentions.js +28 -0
- package/dist/ui/utils/mentions.js.map +1 -0
- package/dist/ui/utils/terminal-text.d.ts +33 -0
- package/dist/ui/utils/terminal-text.d.ts.map +1 -0
- package/dist/ui/utils/terminal-text.js +123 -0
- package/dist/ui/utils/terminal-text.js.map +1 -0
- package/dist/ui/utils/text.d.ts +72 -0
- package/dist/ui/utils/text.d.ts.map +1 -0
- package/dist/ui/utils/text.js +171 -0
- package/dist/ui/utils/text.js.map +1 -0
- package/eslint.config.js +40 -0
- package/graphify-out/GRAPH_REPORT.md +140 -0
- package/graphify-out/cache/1236b1806943f8eb5c64fece9fb448149370f4a1b52b32f0977ad528d7911291.json +1 -0
- package/graphify-out/cache/15cbf641dcc0fd641c18da872214918203a1f64baa7ac8430e4702ef32d18b02.json +1 -0
- package/graphify-out/cache/1abc52745bb46f6cc5a528530e2bc1f368c26e348dff85cdde5cad6f275d7177.json +1 -0
- package/graphify-out/cache/1c7815c37c13177e98895e272285f6151a8d0807478fc843ec452634b3e9912d.json +1 -0
- package/graphify-out/cache/1ec38c39f044f329c78642b61d6394fb8e15d0014335f32947d1f5c7b88c02bc.json +1 -0
- package/graphify-out/cache/20c9b57ff76dbb9d57cbd00659b0a42d2b28dd2abacf1ef4143cc67a5b6fe7f4.json +1 -0
- package/graphify-out/cache/285e11876884eb619e779d540cd957b33e70f14c67ecc26c9b9755aa9cedd717.json +1 -0
- package/graphify-out/cache/2c0a9c49ab51f4e0f07543b4e941bf802b7db31fa607c4cee8e595575be68fe7.json +1 -0
- package/graphify-out/cache/3025e6c2756c79ccaadd51d611f25a8b6630a6a11ce1b4e6e261b3e033dc194f.json +1 -0
- package/graphify-out/cache/4801a686ddfa0a52824a4fc3d65443cbb0ab9f0b030af67d02fccb520c584a08.json +1 -0
- package/graphify-out/cache/4f8fd96f38aa7d0293b4fab60c4581c4f3e68f4533c664c9cd78d1c53bea1cba.json +1 -0
- package/graphify-out/cache/5928e562b0f5700184b810e2403f4aa685e2b93c3c584c10460562b514c40fdd.json +1 -0
- package/graphify-out/cache/66132486efb0a4cfaeea766448f1f15bb33635808714052e7e24e5b00fbc984f.json +1 -0
- package/graphify-out/cache/66ab27669e7ec685130063662af9f30018c267f7639b4af4b0504a98282c383a.json +1 -0
- package/graphify-out/cache/6ff6b3dd433b5ffe96e166263a203dd622397e419dc00bb676824988b7defeab.json +1 -0
- package/graphify-out/cache/7a00a49932177a6215e2590b1ddfd6f1d8494792f693068e9d427d16b165d370.json +1 -0
- package/graphify-out/cache/7b681bc5182f40f707f1c0b16b78af38efffa62a1df315d10878f4de888408ef.json +1 -0
- package/graphify-out/cache/81196d44e50ac0b276d826a531ed10c425a528b298e3fe18e8d5a3eec996e9d5.json +1 -0
- package/graphify-out/cache/8934e9b32dea6e66fdc34fa1681b287ff1335c389917e0fc6ee2fc573e23e87b.json +1 -0
- package/graphify-out/cache/975f6c99807f86b79c80ca40c783618e2080a927eaebe6ea3db37b869f048851.json +1 -0
- package/graphify-out/cache/9ab98f08626fd8190462595e38de828293ad184db8df5e1177b05a8fe290faa1.json +1 -0
- package/graphify-out/cache/9c434a6796d7932b6e87a908c155c09cb2b8d097fc55f141f0302b6600f94749.json +1 -0
- package/graphify-out/cache/ac5cf4c489dc417c1f6ea728d0b6ba12ac7087bc6c2e736697ff3024b4d4e534.json +1 -0
- package/graphify-out/cache/ae5083b5c1dca3e5c6af485e7f6eb8a08ff8b382cdecf92ab5e0902053442afe.json +1 -0
- package/graphify-out/cache/b274057fc2e0118cf2746d1d8060841122bb2a2b0305566fc3f32d3a51e08bcc.json +1 -0
- package/graphify-out/cache/b39beef31da682387f030c0d149f6cd5b3e66effbf936cc8430db15360759dda.json +1 -0
- package/graphify-out/cache/bf3c6a36bb72820bc11cbf4a5c49067d1f62013d4686c019a4dbd9951b1e980e.json +1 -0
- package/graphify-out/cache/c034e156028d1a58b89bce659726e9a4065ddc4d2b560d6bce7a206fdff8dad3.json +1 -0
- package/graphify-out/cache/c619b5bbe8d1f427fbd7816d1e9fcfaf90d7201b020ae6b578166aeb9cb20683.json +1 -0
- package/graphify-out/cache/c8db77a9da0b0f601acfa50a620f31155cdda0d0cc0f2285adcea19e77194ee6.json +1 -0
- package/graphify-out/cache/ca664791ec7741a2077d9e7c10384142d30e7a3b77b388df719c315da608d57d.json +1 -0
- package/graphify-out/cache/cba43a116186bd55c8a63368dea4eee4a8123b2bec0a42df6efb3254f89f9a7a.json +1 -0
- package/graphify-out/cache/cd51cbb3dad1cf34417b9761fe2eb184a9f57d23dc86e45630e63bfa2ecafddc.json +1 -0
- package/graphify-out/cache/d06738cde193b34a136b94104220c17e0212b814b3e4d7ff399105635cae1a03.json +1 -0
- package/graphify-out/cache/d093c19f0169c0398eeb1360895b1c16ecc50abc59f4be8eec3f6fd27c89a6e5.json +1 -0
- package/graphify-out/cache/da8f75c438531d232fe114d5cbf2374576ce842a5fb87c7e5a88b78fdb334e5e.json +1 -0
- package/graphify-out/cache/e35798fa04ddede548a6953bdea506bd7d0788dfed4e8a8ea6ae77b1b60ef5e0.json +1 -0
- package/graphify-out/cache/e5a38c254719000487098782125e15e2e982c07d66b99d359ed1781f30f9fc8c.json +1 -0
- package/graphify-out/cache/e6e4c4a5a7200ee0154585b5d6538f699b0a746dbded3164f8391f06ce7cb212.json +1 -0
- package/graphify-out/cache/ea8d0838df6309b673b031f616b253af957898ee7289d25a541fa6183b732e4e.json +1 -0
- package/graphify-out/cache/ebaee92b0e881efd7a08f3143e2c1803310396b4651d4f77532003c699cc6836.json +1 -0
- package/graphify-out/cache/edf8543318a9e60d56d04704078da6c37202ddd6fdfc83144fe2b94fe19b80ef.json +1 -0
- package/graphify-out/cache/efca19d3668035f11126fc9eccbeab290abfa94babf3f9a8706de81d17aba263.json +1 -0
- package/graphify-out/cache/f1480bb642025ebd6d99986cdd8a7d5726897ec038300e4b095c9c938435dfad.json +1 -0
- package/graphify-out/cache/f459f21277f03865f732affb175b1b092954dae5967f27b3cd1864466e3e24f4.json +1 -0
- package/graphify-out/cache/f899e37e864010b30f4c196e86082d7bd022a0df032005e0407883ebcec36514.json +1 -0
- package/graphify-out/cache/fb3cbe07fbcd97c536cff9c6bc343c35f22d49613f05c53ad30ef67a75c5d93e.json +1 -0
- package/graphify-out/cache/fd3dc682b1ca2f5ae03b50d6b0e045ae50f5701c0a21c5a388d77ef482939d3a.json +1 -0
- package/graphify-out/graph.html +257 -0
- package/graphify-out/graph.json +4396 -0
- package/package.json +45 -6
- package/scripts/e2e-external.mjs +65 -0
- package/scripts/live-agents.mjs +6 -0
- package/scripts/live-stream.mjs +51 -0
- package/src/commands/agents.ts +91 -0
- package/src/commands/auth.ts +39 -0
- package/src/commands/chat.ts +198 -0
- package/src/commands/keys.ts +83 -0
- package/src/commands/local.ts +302 -0
- package/src/commands/mcp.ts +74 -0
- package/src/commands/prompts.ts +58 -0
- package/src/commands/skills.ts +43 -0
- package/src/core/auth/index.ts +101 -0
- package/src/core/config/index.ts +152 -0
- package/src/core/history.ts +79 -0
- package/src/core/markdown-renderer.ts +420 -0
- package/src/core/permissions/index.ts +99 -0
- package/src/core/provider/external.ts +312 -0
- package/src/core/provider/index.ts +517 -0
- package/src/core/registry/index.ts +250 -0
- package/src/core/schema/types.ts +106 -0
- package/src/core/terminal.ts +124 -0
- package/src/core/workspace/index.ts +216 -0
- package/src/index.ts +401 -0
- package/src/ui/app.tsx +644 -0
- package/src/ui/commands/cases/catalog.ts +76 -0
- package/src/ui/commands/cases/misc.ts +293 -0
- package/src/ui/commands/cases/tasks.ts +115 -0
- package/src/ui/commands/runCommand.ts +178 -0
- package/src/ui/components/Banner.tsx +63 -0
- package/src/ui/components/CommandMenu.tsx +63 -0
- package/src/ui/components/ErrorBoundary.tsx +75 -0
- package/src/ui/components/InputBar.tsx +227 -0
- package/src/ui/components/KeysPanel.tsx +115 -0
- package/src/ui/components/MessageView.tsx +226 -0
- package/src/ui/components/Pickers.tsx +234 -0
- package/src/ui/components/SearchOverlay.tsx +65 -0
- package/src/ui/components/WorkingIndicator.tsx +35 -0
- package/src/ui/controls/ApiKeyEntry.tsx +29 -0
- package/src/ui/controls/MultiSelect.tsx +55 -0
- package/src/ui/hooks/useAgentPicker.ts +64 -0
- package/src/ui/hooks/useAuthFlow.ts +47 -0
- package/src/ui/hooks/useKeysFlow.ts +157 -0
- package/src/ui/hooks/useSessionPicker.ts +84 -0
- package/src/ui/hooks/useTerminalSize.ts +36 -0
- package/src/ui/input/keyRouter.ts +627 -0
- package/src/ui/layouts/ScreenLayout.tsx +202 -0
- package/src/ui/shared/types.ts +160 -0
- package/src/ui/theme.ts +53 -0
- package/src/ui/utils/markdown.ts +255 -0
- package/src/ui/utils/mentions.ts +40 -0
- package/src/ui/utils/terminal-text.ts +130 -0
- package/src/ui/utils/text.ts +174 -0
- package/test/commands.test.mjs +127 -0
- package/test/config.test.mjs +123 -0
- package/test/history.test.mjs +42 -0
- package/test/keyrouter.test.mjs +324 -0
- package/test/layout.test.mjs +271 -0
- package/test/markdown.test.mjs +92 -0
- package/test/mentions.test.mjs +51 -0
- package/test/permissions.test.mjs +130 -0
- package/test/provider.test.mjs +287 -0
- package/test/terminal-text.test.mjs +116 -0
- package/test/text.test.mjs +134 -0
- package/test/workspace.test.mjs +101 -0
- package/tsconfig.json +32 -0
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@odysx/codemind",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@odysx/codemind",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OdysX CLI — smart agents in your terminal",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"odysx": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsx src/index.ts",
|
|
13
|
+
"lint": "eslint test/",
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"test": "node --test test/*.mjs",
|
|
16
|
+
"link": "npm link"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22.12.0"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"cli",
|
|
23
|
+
"agents",
|
|
24
|
+
"ai",
|
|
25
|
+
"mcp",
|
|
26
|
+
"odysx"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@types/react": "^19.2.18",
|
|
31
|
+
"chalk": "^5.6.2",
|
|
32
|
+
"clipanion": "^4.0.0-rc.4",
|
|
33
|
+
"commander": "^15.0.0",
|
|
34
|
+
"ink": "^5.2.1",
|
|
35
|
+
"markdown-it": "^14.3.0",
|
|
36
|
+
"react": "^18.3.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@eslint/js": "^9.39.5",
|
|
40
|
+
"@types/markdown-it": "^14.2.0",
|
|
41
|
+
"@types/node": "^26.2.0",
|
|
42
|
+
"eslint": "^9.39.5",
|
|
43
|
+
"typescript": "^7.0.2"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// E2E: external OpenAI-compatible provider via the real streamExternalChat path.
|
|
2
|
+
// Spins a fake SSE server, points getActiveProvider at it, streams a turn,
|
|
3
|
+
// and asserts the tokens come back concatenated.
|
|
4
|
+
import http from "node:http";
|
|
5
|
+
import { writeFileSync, rmSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { pathToFileURL } from "node:url";
|
|
9
|
+
|
|
10
|
+
const PORT = 3939;
|
|
11
|
+
const BASE = `http://localhost:${PORT}/v1`;
|
|
12
|
+
const EXPECTED = "hello from the external provider";
|
|
13
|
+
|
|
14
|
+
const server = http.createServer((req, res) => {
|
|
15
|
+
if (!req.url?.includes("/chat/completions")) {
|
|
16
|
+
res.writeHead(404); res.end(); return;
|
|
17
|
+
}
|
|
18
|
+
res.writeHead(200, { "Content-Type": "text/event-stream" });
|
|
19
|
+
// Emit the reply as a few SSE chunks, then [DONE].
|
|
20
|
+
const tokens = EXPECTED.match(/.{1,5}/g) ?? [EXPECTED];
|
|
21
|
+
for (const t of tokens) {
|
|
22
|
+
res.write(`data: ${JSON.stringify({ choices: [{ delta: { content: t } }] })}\n\n`);
|
|
23
|
+
}
|
|
24
|
+
res.write("data: [DONE]\n\n");
|
|
25
|
+
res.end();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
await new Promise((r) => server.listen(PORT, r));
|
|
29
|
+
|
|
30
|
+
// Write a config that activates a local openai-compatible provider.
|
|
31
|
+
const cfgPath = join(homedir(), ".odysx", "config.json");
|
|
32
|
+
rmSync(cfgPath, { force: true });
|
|
33
|
+
writeFileSync(cfgPath, JSON.stringify({
|
|
34
|
+
provider: "local",
|
|
35
|
+
providers: {
|
|
36
|
+
local: { type: "openai", baseUrl: BASE, apiKey: "x", model: "fake" },
|
|
37
|
+
},
|
|
38
|
+
}, null, 2));
|
|
39
|
+
|
|
40
|
+
const { streamExternalChat, getActiveProvider } = await import(
|
|
41
|
+
pathToFileURL("./dist/core/provider/external.js").href
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const active = getActiveProvider();
|
|
45
|
+
if (!active || active.name !== "local") {
|
|
46
|
+
console.error("FAIL: provider not active:", active);
|
|
47
|
+
server.close(); process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const got = [];
|
|
51
|
+
await streamExternalChat(
|
|
52
|
+
[{ role: "user", content: "hi" }],
|
|
53
|
+
{ onToken: (t) => got.push(t) },
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const joined = got.join("");
|
|
57
|
+
console.log("streamed:", JSON.stringify(joined));
|
|
58
|
+
if (joined !== EXPECTED) {
|
|
59
|
+
console.error(`FAIL: expected "${EXPECTED}", got "${joined}"`);
|
|
60
|
+
server.close(); process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
console.log("PASS: external provider streamed the full reply");
|
|
63
|
+
server.close();
|
|
64
|
+
rmSync(cfgPath, { force: true });
|
|
65
|
+
process.exit(0);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { env } from "node:process";
|
|
2
|
+
env.ODYSX_API_URL = "http://localhost:8000";
|
|
3
|
+
env.ODYSX_API_KEY = "odx_7l7nntdKwU2NtuXglmaj83CHF8Jm2mv7du2BrevW8whYbvM1";
|
|
4
|
+
const { apiCall } = await import("../dist/core/provider/index.js");
|
|
5
|
+
const res = await apiCall("/api/v1/agents");
|
|
6
|
+
console.log("agents ok?", res.ok, "count:", (res.data ?? []).length, "first:", (res.data ?? [])[0]?.name);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Live integration smoke test against a running agent-hub backend.
|
|
2
|
+
// Verifies the REPL's real streamChat path end-to-end (auth, SSE parse, usage).
|
|
3
|
+
// Requires: backend on ODYSX_API_URL with ODYSX_API_KEY set to a chat-scoped key.
|
|
4
|
+
//
|
|
5
|
+
// NOTE: the backend's stream is sometimes flaky (it may emit only a guardrail
|
|
6
|
+
// annotation frame or nothing). This test retries a few times and only fails if
|
|
7
|
+
// EVERY attempt returns empty — that keeps it a useful signal, not flaky noise.
|
|
8
|
+
import { env } from "node:process";
|
|
9
|
+
|
|
10
|
+
const url = env.ODYSX_API_URL ?? "http://localhost:8000";
|
|
11
|
+
const key = env.ODYSX_API_KEY;
|
|
12
|
+
if (!key) {
|
|
13
|
+
console.error("FAIL: set ODYSX_API_KEY (chat-scoped) to run live-stream.mjs");
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
env.ODYSX_API_URL = url;
|
|
17
|
+
|
|
18
|
+
const { streamChat, apiCall } = await import("../dist/core/provider/index.js");
|
|
19
|
+
|
|
20
|
+
const agents = await apiCall("/api/v1/agents");
|
|
21
|
+
const agentId = (agents.data ?? [])[0]?.id;
|
|
22
|
+
if (!agentId) {
|
|
23
|
+
console.error("FAIL: no agents returned from", url);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const ATTEMPTS = 4;
|
|
28
|
+
for (let i = 1; i <= ATTEMPTS; i++) {
|
|
29
|
+
const got = [];
|
|
30
|
+
try {
|
|
31
|
+
await streamChat(
|
|
32
|
+
"/api/v1/llm/chat/stream",
|
|
33
|
+
{ agent_id: agentId, message: "Say hello in 5 words.", session_id: `live-${i}-${Date.now()}` },
|
|
34
|
+
(t) => got.push(t),
|
|
35
|
+
() => {},
|
|
36
|
+
undefined,
|
|
37
|
+
() => {},
|
|
38
|
+
);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error(`attempt ${i}: STREAM FAILED: ${e.message}`);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const reply = got.join("");
|
|
44
|
+
console.log(`attempt ${i}: got ${reply.length} chars -> ${JSON.stringify(reply)}`);
|
|
45
|
+
if (reply.trim()) {
|
|
46
|
+
console.log("PASS: live stream received a reply");
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
console.error("FAIL: all attempts returned empty (backend stream flaky?)");
|
|
51
|
+
process.exit(1);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent commands — list, get, create, delete agents.
|
|
3
|
+
*/
|
|
4
|
+
import { registerCommand } from "../core/registry/index.js";
|
|
5
|
+
import { apiCall, urlSegment } from "../core/provider/index.js";
|
|
6
|
+
import type { CommandSchema, CommandResult } from "../core/schema/types.js";
|
|
7
|
+
|
|
8
|
+
const schema: CommandSchema = {
|
|
9
|
+
name: "agents",
|
|
10
|
+
description: "Manage and interact with agents",
|
|
11
|
+
aliases: ["a"],
|
|
12
|
+
options: [],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
async function handleList(): Promise<CommandResult> {
|
|
16
|
+
const res = await apiCall("/api/v1/agents");
|
|
17
|
+
if (!res.ok) return { exitCode: 1, error: res.error };
|
|
18
|
+
return { exitCode: 0, data: res.data };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function handleGet(agentId: string): Promise<CommandResult> {
|
|
22
|
+
if (!agentId) return { exitCode: 1, error: "Usage: agents get <agent-id>" };
|
|
23
|
+
const res = await apiCall(`/api/v1/agents/${urlSegment(agentId)}`);
|
|
24
|
+
if (!res.ok) return { exitCode: 1, error: res.error };
|
|
25
|
+
return { exitCode: 0, data: res.data };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function handleCreate(args: string[]): Promise<CommandResult> {
|
|
29
|
+
const name = args.find((a) => !a.startsWith("-"));
|
|
30
|
+
if (!name) return { exitCode: 1, error: "Usage: agents create <name>" };
|
|
31
|
+
|
|
32
|
+
const type = args.includes("--type") ? args[args.indexOf("--type") + 1] : "simple";
|
|
33
|
+
const desc = args.includes("--description") ? args[args.indexOf("--description") + 1] : "";
|
|
34
|
+
|
|
35
|
+
const res = await apiCall("/api/v1/agents", {
|
|
36
|
+
method: "POST",
|
|
37
|
+
body: { name, agent_type: type, description: desc },
|
|
38
|
+
});
|
|
39
|
+
if (!res.ok) return { exitCode: 1, error: res.error };
|
|
40
|
+
return { exitCode: 0, data: res.data, message: `Agent created` };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Ask a yes/no question on the terminal.
|
|
45
|
+
*
|
|
46
|
+
* Resolves null when there is no terminal to ask (piped stdin, CI, EOF). The
|
|
47
|
+
* previous implementation waited for a `data` event that never arrives in
|
|
48
|
+
* those cases, so the process either hung or exited 0 having done nothing.
|
|
49
|
+
*/
|
|
50
|
+
async function confirm(question: string): Promise<string | null> {
|
|
51
|
+
if (!process.stdin.isTTY) return null;
|
|
52
|
+
process.stdout.write(question);
|
|
53
|
+
const readline = await import("node:readline/promises");
|
|
54
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
55
|
+
try {
|
|
56
|
+
return (await rl.question("")).trim();
|
|
57
|
+
} finally {
|
|
58
|
+
rl.close();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function handleDelete(agentId: string, force: boolean): Promise<CommandResult> {
|
|
63
|
+
if (!agentId) return { exitCode: 1, error: "Usage: agents delete <agent-id>" };
|
|
64
|
+
if (!force) {
|
|
65
|
+
const answer = await confirm(`Delete agent ${agentId}? [y/N] `);
|
|
66
|
+
if (answer === null) {
|
|
67
|
+
return {
|
|
68
|
+
exitCode: 1,
|
|
69
|
+
error: "Refusing to delete without confirmation: stdin is not a terminal (pass --force)",
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (answer !== "y" && answer !== "yes") return { exitCode: 0, message: "Cancelled" };
|
|
73
|
+
}
|
|
74
|
+
const res = await apiCall(`/api/v1/agents/${urlSegment(agentId)}`, { method: "DELETE" });
|
|
75
|
+
if (!res.ok) return { exitCode: 1, error: res.error };
|
|
76
|
+
return { exitCode: 0, message: `Agent ${agentId} deleted` };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
registerCommand(schema, async (_args, opts) => {
|
|
80
|
+
const sub = opts.args[0] as string | undefined;
|
|
81
|
+
const rest = (opts.args as string[]).slice(1);
|
|
82
|
+
const force = opts.force as boolean;
|
|
83
|
+
|
|
84
|
+
switch (sub) {
|
|
85
|
+
case "list": return handleList();
|
|
86
|
+
case "get": return handleGet(rest[0] ?? "");
|
|
87
|
+
case "create": return handleCreate(rest);
|
|
88
|
+
case "delete": return handleDelete(rest[0] ?? "", force);
|
|
89
|
+
default: return handleList();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth commands — login, logout, set-key, status.
|
|
3
|
+
*/
|
|
4
|
+
import { registerCommand } from "../core/registry/index.js";
|
|
5
|
+
import { login, setApiKey, logout, authStatus } from "../core/auth/index.js";
|
|
6
|
+
import type { CommandSchema } from "../core/schema/types.js";
|
|
7
|
+
|
|
8
|
+
const schema: CommandSchema = {
|
|
9
|
+
name: "auth",
|
|
10
|
+
description: "Authenticate with the OdysX platform",
|
|
11
|
+
group: "config",
|
|
12
|
+
options: [],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function parseFlag(args: string[], flag: string): string | undefined {
|
|
16
|
+
const idx = args.indexOf(flag);
|
|
17
|
+
return idx !== -1 ? args[idx + 1] : undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
registerCommand(schema, async (_args, opts) => {
|
|
21
|
+
const sub = opts.args[0] as string | undefined;
|
|
22
|
+
const rest = (opts.args as string[]).slice(1);
|
|
23
|
+
|
|
24
|
+
switch (sub) {
|
|
25
|
+
case "login": {
|
|
26
|
+
const username = parseFlag(rest, "--username") ?? parseFlag(rest, "-u");
|
|
27
|
+
const password = parseFlag(rest, "--password") ?? parseFlag(rest, "-p");
|
|
28
|
+
const apiUrl = parseFlag(rest, "--api-url");
|
|
29
|
+
return login(username ?? "", password ?? "", apiUrl);
|
|
30
|
+
}
|
|
31
|
+
case "set-key": {
|
|
32
|
+
const key = parseFlag(rest, "--key") ?? rest.find((a) => !a.startsWith("-"));
|
|
33
|
+
return setApiKey(key ?? "");
|
|
34
|
+
}
|
|
35
|
+
case "logout": return logout();
|
|
36
|
+
case "status": return authStatus();
|
|
37
|
+
default: return authStatus();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat commands — interactive and one-shot chat with agents.
|
|
3
|
+
*
|
|
4
|
+
* Uses the StreamingMarkdownRenderer for rich inline rendering of
|
|
5
|
+
* markdown responses with syntax highlighting and colorization.
|
|
6
|
+
*/
|
|
7
|
+
import { registerCommand } from "../core/registry/index.js";
|
|
8
|
+
import { streamTurn } from "../core/provider/index.js";
|
|
9
|
+
import { StreamingMarkdownRenderer } from "../core/markdown-renderer.js";
|
|
10
|
+
import { clearViewport } from "../core/terminal.js";
|
|
11
|
+
import type { CommandSchema, CommandResult } from "../core/schema/types.js";
|
|
12
|
+
import chalk from "chalk";
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
14
|
+
|
|
15
|
+
const schema: CommandSchema = {
|
|
16
|
+
name: "chat",
|
|
17
|
+
description: "Chat with an agent (interactive or one-shot)",
|
|
18
|
+
aliases: ["c"],
|
|
19
|
+
options: [],
|
|
20
|
+
examples: [
|
|
21
|
+
"odysx chat hello",
|
|
22
|
+
"odysx chat --agent-id research-agent what is quantum computing?",
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
let currentSessionId = "";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* One-shot chat: send a message and print the streamed response.
|
|
30
|
+
*/
|
|
31
|
+
async function oneShotChat(message: string, agentId: string): Promise<CommandResult> {
|
|
32
|
+
const sessionId = currentSessionId || randomUUID();
|
|
33
|
+
|
|
34
|
+
process.stdout.write("\n");
|
|
35
|
+
|
|
36
|
+
const renderer = new StreamingMarkdownRenderer();
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
await streamTurn(message, {
|
|
40
|
+
agentId,
|
|
41
|
+
sessionId,
|
|
42
|
+
onToken: (token: string) => renderer.processChunk(token),
|
|
43
|
+
onDone: () => {
|
|
44
|
+
renderer.flush();
|
|
45
|
+
process.stdout.write("\n");
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
} catch (err) {
|
|
49
|
+
return { exitCode: 1, error: err instanceof Error ? err.message : String(err) };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
currentSessionId = sessionId;
|
|
53
|
+
return { exitCode: 0, formatted: true };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Interactive chat loop with rich formatting.
|
|
58
|
+
*/
|
|
59
|
+
async function interactiveChat(agentId: string): Promise<CommandResult> {
|
|
60
|
+
const sessionId = randomUUID();
|
|
61
|
+
currentSessionId = sessionId;
|
|
62
|
+
// External providers are stateless — they need the transcript sent with
|
|
63
|
+
// every turn. The platform keeps history server-side keyed by session id.
|
|
64
|
+
const history: Array<{ role: "user" | "assistant"; content: string }> = [];
|
|
65
|
+
|
|
66
|
+
console.log(`\n${chalk.cyan('╔══════════════════════════════════════════════════════════════╗')}`);
|
|
67
|
+
console.log(`${chalk.cyan('║')} ${chalk.bold('OdysX Chat')} ${chalk.gray(`Agent: ${agentId}`)} ${chalk.gray(`Session: ${sessionId.slice(0, 8)}...`)} ${chalk.cyan('║')}`);
|
|
68
|
+
console.log(`${chalk.cyan('╚══════════════════════════════════════════════════════════════╝')}\n`);
|
|
69
|
+
console.log(chalk.gray('Type your message and press Enter. Use /help for commands, /quit to exit.\n'));
|
|
70
|
+
|
|
71
|
+
const readline = await import("node:readline");
|
|
72
|
+
const rl = readline.createInterface({
|
|
73
|
+
input: process.stdin,
|
|
74
|
+
output: process.stdout,
|
|
75
|
+
// Enable history and autocomplete
|
|
76
|
+
history: [],
|
|
77
|
+
removeHistoryDuplicates: true,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const prompt = (): void => {
|
|
81
|
+
rl.question(chalk.cyan("You: "), async (input: string) => {
|
|
82
|
+
const msg = input.trim();
|
|
83
|
+
|
|
84
|
+
// Handle slash commands
|
|
85
|
+
if (msg.startsWith("/")) {
|
|
86
|
+
const cmd = msg.slice(1).split(" ")[0];
|
|
87
|
+
switch (cmd) {
|
|
88
|
+
case "quit":
|
|
89
|
+
case "exit":
|
|
90
|
+
// Close the interface and let the command loop end normally.
|
|
91
|
+
// `process.exit` here skipped the stdout flush (truncating piped
|
|
92
|
+
// output) and bypassed the terminal-restore contract.
|
|
93
|
+
console.log(chalk.gray("\nGoodbye."));
|
|
94
|
+
rl.close();
|
|
95
|
+
return;
|
|
96
|
+
case "help":
|
|
97
|
+
console.log(chalk.gray("\nAvailable commands:"));
|
|
98
|
+
console.log(chalk.gray(" /help - Show this help"));
|
|
99
|
+
console.log(chalk.gray(" /quit - Exit the chat"));
|
|
100
|
+
console.log(chalk.gray(" /clear - Clear the screen"));
|
|
101
|
+
console.log(chalk.gray(" /history - Show conversation history"));
|
|
102
|
+
console.log(chalk.gray(" /stats - Show session statistics\n"));
|
|
103
|
+
prompt();
|
|
104
|
+
return;
|
|
105
|
+
case "clear":
|
|
106
|
+
// No-op when piped: a raw wipe would land in the captured output.
|
|
107
|
+
clearViewport();
|
|
108
|
+
prompt();
|
|
109
|
+
return;
|
|
110
|
+
case "history":
|
|
111
|
+
console.log(chalk.gray("\n[Conversation history is stored locally]"));
|
|
112
|
+
console.log(chalk.gray(` Session ID: ${sessionId}`));
|
|
113
|
+
console.log(chalk.gray(` Messages exchanged: use /stats for count\n`));
|
|
114
|
+
prompt();
|
|
115
|
+
return;
|
|
116
|
+
case "stats":
|
|
117
|
+
console.log(chalk.gray(`\n Session: ${sessionId}`));
|
|
118
|
+
console.log(chalk.gray(` Agent: ${agentId}\n`));
|
|
119
|
+
prompt();
|
|
120
|
+
return;
|
|
121
|
+
default:
|
|
122
|
+
console.log(chalk.gray(`\nUnknown command: /${cmd}. Type /help for available commands.\n`));
|
|
123
|
+
prompt();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!msg) {
|
|
129
|
+
prompt();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Display user message
|
|
134
|
+
console.log(chalk.gray("You: ") + chalk.white(msg) + "\n");
|
|
135
|
+
|
|
136
|
+
// Stream agent response with markdown rendering
|
|
137
|
+
process.stdout.write(chalk.cyan("Agent: "));
|
|
138
|
+
const renderer = new StreamingMarkdownRenderer();
|
|
139
|
+
const startTime = Date.now();
|
|
140
|
+
let reply = "";
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
await streamTurn(msg, {
|
|
144
|
+
agentId,
|
|
145
|
+
sessionId,
|
|
146
|
+
history,
|
|
147
|
+
onToken: (token: string) => {
|
|
148
|
+
reply += token;
|
|
149
|
+
renderer.processChunk(token);
|
|
150
|
+
},
|
|
151
|
+
onDone: () => {
|
|
152
|
+
renderer.flush();
|
|
153
|
+
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
154
|
+
console.log(chalk.gray(`\n (${elapsed}s)\n`));
|
|
155
|
+
prompt();
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
history.push({ role: "user", content: msg }, { role: "assistant", content: reply });
|
|
159
|
+
} catch (err) {
|
|
160
|
+
console.error(chalk.red(`\nError: ${err instanceof Error ? err.message : err}\n`));
|
|
161
|
+
prompt();
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// Show welcome message
|
|
167
|
+
console.log(chalk.gray("Tip: Type /help anytime for commands.\n"));
|
|
168
|
+
|
|
169
|
+
// Keep the process alive until the interface closes — and actually settle
|
|
170
|
+
// when it does. A never-resolving promise meant a closed stdin (Ctrl+D,
|
|
171
|
+
// a dropped pipe) let the process exit mid-stream with status 0.
|
|
172
|
+
return new Promise<CommandResult>((resolve) => {
|
|
173
|
+
rl.once("close", () => resolve({ exitCode: 0, formatted: true }));
|
|
174
|
+
prompt();
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Parse args, detect --agent-id, and route into interactive vs one-shot. */
|
|
179
|
+
registerCommand(schema, async (_args, opts) => {
|
|
180
|
+
const args = opts.args as string[];
|
|
181
|
+
|
|
182
|
+
// Parse --agent-id flag
|
|
183
|
+
const agentIdx = args.indexOf("--agent-id");
|
|
184
|
+
const agentId = agentIdx !== -1 ? args[agentIdx + 1] ?? "master" : "master";
|
|
185
|
+
|
|
186
|
+
// Everything else is the message (commander already strips "chat")
|
|
187
|
+
const messageParts = args.filter((a, i) => {
|
|
188
|
+
if (a === "--agent-id") return false;
|
|
189
|
+
if (agentIdx !== -1 && i === agentIdx + 1) return false;
|
|
190
|
+
return true;
|
|
191
|
+
});
|
|
192
|
+
const message = messageParts.join(" ").trim();
|
|
193
|
+
|
|
194
|
+
if (!message) {
|
|
195
|
+
return interactiveChat(agentId);
|
|
196
|
+
}
|
|
197
|
+
return oneShotChat(message, agentId);
|
|
198
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API key management commands — create, list, revoke, usage.
|
|
3
|
+
*/
|
|
4
|
+
import { registerCommand } from "../core/registry/index.js";
|
|
5
|
+
import { apiCall, urlSegment } from "../core/provider/index.js";
|
|
6
|
+
import type { CommandSchema, CommandResult } from "../core/schema/types.js";
|
|
7
|
+
|
|
8
|
+
const schema: CommandSchema = {
|
|
9
|
+
name: "keys",
|
|
10
|
+
description: "Manage API keys for CLI access",
|
|
11
|
+
aliases: ["k"],
|
|
12
|
+
options: [],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function parseFlag(args: string[], flag: string): string | undefined {
|
|
16
|
+
const idx = args.indexOf(flag);
|
|
17
|
+
return idx !== -1 ? args[idx + 1] : undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function handleCreate(args: string[]): Promise<CommandResult> {
|
|
21
|
+
const name = parseFlag(args, "--name") ?? args.find((a) => !a.startsWith("-"));
|
|
22
|
+
if (!name) return { exitCode: 1, error: "Usage: keys create --name <name>" };
|
|
23
|
+
|
|
24
|
+
const scopes = parseFlag(args, "--scopes");
|
|
25
|
+
const res = await apiCall<{ key: string; api_key: Record<string, unknown> }>("/api/v1/api-keys", {
|
|
26
|
+
method: "POST",
|
|
27
|
+
body: {
|
|
28
|
+
name,
|
|
29
|
+
scopes: scopes ? scopes.split(",").map((s) => s.trim()) : undefined,
|
|
30
|
+
rate_limit_rpm: parseFlag(args, "--rate-limit") ? Number(parseFlag(args, "--rate-limit")) : undefined,
|
|
31
|
+
daily_token_limit: parseFlag(args, "--daily-limit") ? Number(parseFlag(args, "--daily-limit")) : undefined,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
if (!res.ok) return { exitCode: 1, error: res.error };
|
|
35
|
+
// The secret is shown exactly once. If the server answers in a shape we
|
|
36
|
+
// don't recognise, say so — printing "undefined" as the key, next to a
|
|
37
|
+
// "save this key" warning, is worse than failing.
|
|
38
|
+
const key = res.data?.key;
|
|
39
|
+
if (typeof key !== "string" || !key) {
|
|
40
|
+
return {
|
|
41
|
+
exitCode: 1,
|
|
42
|
+
error: "Unexpected response: the server did not return the new key",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
exitCode: 0,
|
|
47
|
+
data: { ...(res.data.api_key ?? {}), key },
|
|
48
|
+
message: `\nKey created. Save this key — it cannot be retrieved later:\n\n ${key}\n`,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function handleList(): Promise<CommandResult> {
|
|
53
|
+
const res = await apiCall("/api/v1/api-keys");
|
|
54
|
+
if (!res.ok) return { exitCode: 1, error: res.error };
|
|
55
|
+
return { exitCode: 0, data: res.data };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function handleRevoke(keyId: string): Promise<CommandResult> {
|
|
59
|
+
if (!keyId) return { exitCode: 1, error: "Usage: keys revoke <key-id>" };
|
|
60
|
+
const res = await apiCall(`/api/v1/api-keys/${urlSegment(keyId)}`, { method: "DELETE" });
|
|
61
|
+
if (!res.ok) return { exitCode: 1, error: res.error };
|
|
62
|
+
return { exitCode: 0, message: `Key ${keyId} revoked` };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function handleUsage(keyId: string): Promise<CommandResult> {
|
|
66
|
+
if (!keyId) return { exitCode: 1, error: "Usage: keys usage <key-id>" };
|
|
67
|
+
const res = await apiCall(`/api/v1/api-keys/${urlSegment(keyId)}/usage/summary`);
|
|
68
|
+
if (!res.ok) return { exitCode: 1, error: res.error };
|
|
69
|
+
return { exitCode: 0, data: res.data };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
registerCommand(schema, async (_args, opts) => {
|
|
73
|
+
const sub = opts.args[0] as string | undefined;
|
|
74
|
+
const rest = (opts.args as string[]).slice(1);
|
|
75
|
+
|
|
76
|
+
switch (sub) {
|
|
77
|
+
case "create": return handleCreate(rest);
|
|
78
|
+
case "list": return handleList();
|
|
79
|
+
case "revoke": return handleRevoke(rest[0] ?? "");
|
|
80
|
+
case "usage": return handleUsage(rest[0] ?? "");
|
|
81
|
+
default: return handleList();
|
|
82
|
+
}
|
|
83
|
+
});
|