@odysx/codemind 0.1.0 → 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.
Files changed (226) hide show
  1. package/dist/core/provider/index.d.ts +52 -10
  2. package/dist/core/provider/index.js +99 -12
  3. package/package.json +6 -1
  4. package/dist/commands/agents.d.ts.map +0 -1
  5. package/dist/commands/agents.js.map +0 -1
  6. package/dist/commands/auth.d.ts.map +0 -1
  7. package/dist/commands/auth.js.map +0 -1
  8. package/dist/commands/chat.d.ts.map +0 -1
  9. package/dist/commands/chat.js.map +0 -1
  10. package/dist/commands/keys.d.ts.map +0 -1
  11. package/dist/commands/keys.js.map +0 -1
  12. package/dist/commands/local.d.ts.map +0 -1
  13. package/dist/commands/local.js.map +0 -1
  14. package/dist/commands/mcp.d.ts.map +0 -1
  15. package/dist/commands/mcp.js.map +0 -1
  16. package/dist/commands/prompts.d.ts.map +0 -1
  17. package/dist/commands/prompts.js.map +0 -1
  18. package/dist/commands/skills.d.ts.map +0 -1
  19. package/dist/commands/skills.js.map +0 -1
  20. package/dist/core/auth/index.d.ts.map +0 -1
  21. package/dist/core/auth/index.js.map +0 -1
  22. package/dist/core/config/index.d.ts.map +0 -1
  23. package/dist/core/config/index.js.map +0 -1
  24. package/dist/core/history.d.ts.map +0 -1
  25. package/dist/core/history.js.map +0 -1
  26. package/dist/core/markdown-renderer.d.ts.map +0 -1
  27. package/dist/core/markdown-renderer.js.map +0 -1
  28. package/dist/core/permissions/index.d.ts.map +0 -1
  29. package/dist/core/permissions/index.js.map +0 -1
  30. package/dist/core/provider/external.d.ts.map +0 -1
  31. package/dist/core/provider/external.js.map +0 -1
  32. package/dist/core/provider/index.d.ts.map +0 -1
  33. package/dist/core/provider/index.js.map +0 -1
  34. package/dist/core/registry/index.d.ts.map +0 -1
  35. package/dist/core/registry/index.js.map +0 -1
  36. package/dist/core/schema/types.d.ts.map +0 -1
  37. package/dist/core/schema/types.js.map +0 -1
  38. package/dist/core/terminal.d.ts.map +0 -1
  39. package/dist/core/terminal.js.map +0 -1
  40. package/dist/core/workspace/index.d.ts.map +0 -1
  41. package/dist/core/workspace/index.js.map +0 -1
  42. package/dist/index.d.ts.map +0 -1
  43. package/dist/index.js.map +0 -1
  44. package/dist/ui/app.d.ts.map +0 -1
  45. package/dist/ui/app.js.map +0 -1
  46. package/dist/ui/commands/cases/catalog.d.ts.map +0 -1
  47. package/dist/ui/commands/cases/catalog.js.map +0 -1
  48. package/dist/ui/commands/cases/misc.d.ts.map +0 -1
  49. package/dist/ui/commands/cases/misc.js.map +0 -1
  50. package/dist/ui/commands/cases/tasks.d.ts.map +0 -1
  51. package/dist/ui/commands/cases/tasks.js.map +0 -1
  52. package/dist/ui/commands/runCommand.d.ts.map +0 -1
  53. package/dist/ui/commands/runCommand.js.map +0 -1
  54. package/dist/ui/components/AgentPicker.d.ts.map +0 -1
  55. package/dist/ui/components/AgentPicker.js.map +0 -1
  56. package/dist/ui/components/AuthPicker.d.ts.map +0 -1
  57. package/dist/ui/components/AuthPicker.js.map +0 -1
  58. package/dist/ui/components/Banner.d.ts.map +0 -1
  59. package/dist/ui/components/Banner.js.map +0 -1
  60. package/dist/ui/components/CommandMenu.d.ts.map +0 -1
  61. package/dist/ui/components/CommandMenu.js.map +0 -1
  62. package/dist/ui/components/ErrorBoundary.d.ts.map +0 -1
  63. package/dist/ui/components/ErrorBoundary.js.map +0 -1
  64. package/dist/ui/components/InputBar.d.ts.map +0 -1
  65. package/dist/ui/components/InputBar.js.map +0 -1
  66. package/dist/ui/components/KeysPanel.d.ts.map +0 -1
  67. package/dist/ui/components/KeysPanel.js.map +0 -1
  68. package/dist/ui/components/MessageView.d.ts.map +0 -1
  69. package/dist/ui/components/MessageView.js.map +0 -1
  70. package/dist/ui/components/PermissionPrompt.d.ts.map +0 -1
  71. package/dist/ui/components/PermissionPrompt.js.map +0 -1
  72. package/dist/ui/components/Pickers.d.ts.map +0 -1
  73. package/dist/ui/components/Pickers.js.map +0 -1
  74. package/dist/ui/components/SearchOverlay.d.ts.map +0 -1
  75. package/dist/ui/components/SearchOverlay.js.map +0 -1
  76. package/dist/ui/components/SessionPicker.d.ts.map +0 -1
  77. package/dist/ui/components/SessionPicker.js.map +0 -1
  78. package/dist/ui/components/WorkingIndicator.d.ts.map +0 -1
  79. package/dist/ui/components/WorkingIndicator.js.map +0 -1
  80. package/dist/ui/controls/ApiKeyEntry.d.ts.map +0 -1
  81. package/dist/ui/controls/ApiKeyEntry.js.map +0 -1
  82. package/dist/ui/controls/MultiSelect.d.ts.map +0 -1
  83. package/dist/ui/controls/MultiSelect.js.map +0 -1
  84. package/dist/ui/hooks/useAgentPicker.d.ts.map +0 -1
  85. package/dist/ui/hooks/useAgentPicker.js.map +0 -1
  86. package/dist/ui/hooks/useAuthFlow.d.ts.map +0 -1
  87. package/dist/ui/hooks/useAuthFlow.js.map +0 -1
  88. package/dist/ui/hooks/useKeysFlow.d.ts.map +0 -1
  89. package/dist/ui/hooks/useKeysFlow.js.map +0 -1
  90. package/dist/ui/hooks/useSessionPicker.d.ts.map +0 -1
  91. package/dist/ui/hooks/useSessionPicker.js.map +0 -1
  92. package/dist/ui/hooks/useTerminalSize.d.ts.map +0 -1
  93. package/dist/ui/hooks/useTerminalSize.js.map +0 -1
  94. package/dist/ui/input/keyRouter.d.ts.map +0 -1
  95. package/dist/ui/input/keyRouter.js.map +0 -1
  96. package/dist/ui/layouts/ScreenLayout.d.ts.map +0 -1
  97. package/dist/ui/layouts/ScreenLayout.js.map +0 -1
  98. package/dist/ui/shared/types.d.ts.map +0 -1
  99. package/dist/ui/shared/types.js.map +0 -1
  100. package/dist/ui/theme.d.ts.map +0 -1
  101. package/dist/ui/theme.js.map +0 -1
  102. package/dist/ui/utils/markdown.d.ts.map +0 -1
  103. package/dist/ui/utils/markdown.js.map +0 -1
  104. package/dist/ui/utils/mentions.d.ts.map +0 -1
  105. package/dist/ui/utils/mentions.js.map +0 -1
  106. package/dist/ui/utils/terminal-text.d.ts.map +0 -1
  107. package/dist/ui/utils/terminal-text.js.map +0 -1
  108. package/dist/ui/utils/text.d.ts.map +0 -1
  109. package/dist/ui/utils/text.js.map +0 -1
  110. package/eslint.config.js +0 -40
  111. package/graphify-out/GRAPH_REPORT.md +0 -140
  112. package/graphify-out/cache/1236b1806943f8eb5c64fece9fb448149370f4a1b52b32f0977ad528d7911291.json +0 -1
  113. package/graphify-out/cache/15cbf641dcc0fd641c18da872214918203a1f64baa7ac8430e4702ef32d18b02.json +0 -1
  114. package/graphify-out/cache/1abc52745bb46f6cc5a528530e2bc1f368c26e348dff85cdde5cad6f275d7177.json +0 -1
  115. package/graphify-out/cache/1c7815c37c13177e98895e272285f6151a8d0807478fc843ec452634b3e9912d.json +0 -1
  116. package/graphify-out/cache/1ec38c39f044f329c78642b61d6394fb8e15d0014335f32947d1f5c7b88c02bc.json +0 -1
  117. package/graphify-out/cache/20c9b57ff76dbb9d57cbd00659b0a42d2b28dd2abacf1ef4143cc67a5b6fe7f4.json +0 -1
  118. package/graphify-out/cache/285e11876884eb619e779d540cd957b33e70f14c67ecc26c9b9755aa9cedd717.json +0 -1
  119. package/graphify-out/cache/2c0a9c49ab51f4e0f07543b4e941bf802b7db31fa607c4cee8e595575be68fe7.json +0 -1
  120. package/graphify-out/cache/3025e6c2756c79ccaadd51d611f25a8b6630a6a11ce1b4e6e261b3e033dc194f.json +0 -1
  121. package/graphify-out/cache/4801a686ddfa0a52824a4fc3d65443cbb0ab9f0b030af67d02fccb520c584a08.json +0 -1
  122. package/graphify-out/cache/4f8fd96f38aa7d0293b4fab60c4581c4f3e68f4533c664c9cd78d1c53bea1cba.json +0 -1
  123. package/graphify-out/cache/5928e562b0f5700184b810e2403f4aa685e2b93c3c584c10460562b514c40fdd.json +0 -1
  124. package/graphify-out/cache/66132486efb0a4cfaeea766448f1f15bb33635808714052e7e24e5b00fbc984f.json +0 -1
  125. package/graphify-out/cache/66ab27669e7ec685130063662af9f30018c267f7639b4af4b0504a98282c383a.json +0 -1
  126. package/graphify-out/cache/6ff6b3dd433b5ffe96e166263a203dd622397e419dc00bb676824988b7defeab.json +0 -1
  127. package/graphify-out/cache/7a00a49932177a6215e2590b1ddfd6f1d8494792f693068e9d427d16b165d370.json +0 -1
  128. package/graphify-out/cache/7b681bc5182f40f707f1c0b16b78af38efffa62a1df315d10878f4de888408ef.json +0 -1
  129. package/graphify-out/cache/81196d44e50ac0b276d826a531ed10c425a528b298e3fe18e8d5a3eec996e9d5.json +0 -1
  130. package/graphify-out/cache/8934e9b32dea6e66fdc34fa1681b287ff1335c389917e0fc6ee2fc573e23e87b.json +0 -1
  131. package/graphify-out/cache/975f6c99807f86b79c80ca40c783618e2080a927eaebe6ea3db37b869f048851.json +0 -1
  132. package/graphify-out/cache/9ab98f08626fd8190462595e38de828293ad184db8df5e1177b05a8fe290faa1.json +0 -1
  133. package/graphify-out/cache/9c434a6796d7932b6e87a908c155c09cb2b8d097fc55f141f0302b6600f94749.json +0 -1
  134. package/graphify-out/cache/ac5cf4c489dc417c1f6ea728d0b6ba12ac7087bc6c2e736697ff3024b4d4e534.json +0 -1
  135. package/graphify-out/cache/ae5083b5c1dca3e5c6af485e7f6eb8a08ff8b382cdecf92ab5e0902053442afe.json +0 -1
  136. package/graphify-out/cache/b274057fc2e0118cf2746d1d8060841122bb2a2b0305566fc3f32d3a51e08bcc.json +0 -1
  137. package/graphify-out/cache/b39beef31da682387f030c0d149f6cd5b3e66effbf936cc8430db15360759dda.json +0 -1
  138. package/graphify-out/cache/bf3c6a36bb72820bc11cbf4a5c49067d1f62013d4686c019a4dbd9951b1e980e.json +0 -1
  139. package/graphify-out/cache/c034e156028d1a58b89bce659726e9a4065ddc4d2b560d6bce7a206fdff8dad3.json +0 -1
  140. package/graphify-out/cache/c619b5bbe8d1f427fbd7816d1e9fcfaf90d7201b020ae6b578166aeb9cb20683.json +0 -1
  141. package/graphify-out/cache/c8db77a9da0b0f601acfa50a620f31155cdda0d0cc0f2285adcea19e77194ee6.json +0 -1
  142. package/graphify-out/cache/ca664791ec7741a2077d9e7c10384142d30e7a3b77b388df719c315da608d57d.json +0 -1
  143. package/graphify-out/cache/cba43a116186bd55c8a63368dea4eee4a8123b2bec0a42df6efb3254f89f9a7a.json +0 -1
  144. package/graphify-out/cache/cd51cbb3dad1cf34417b9761fe2eb184a9f57d23dc86e45630e63bfa2ecafddc.json +0 -1
  145. package/graphify-out/cache/d06738cde193b34a136b94104220c17e0212b814b3e4d7ff399105635cae1a03.json +0 -1
  146. package/graphify-out/cache/d093c19f0169c0398eeb1360895b1c16ecc50abc59f4be8eec3f6fd27c89a6e5.json +0 -1
  147. package/graphify-out/cache/da8f75c438531d232fe114d5cbf2374576ce842a5fb87c7e5a88b78fdb334e5e.json +0 -1
  148. package/graphify-out/cache/e35798fa04ddede548a6953bdea506bd7d0788dfed4e8a8ea6ae77b1b60ef5e0.json +0 -1
  149. package/graphify-out/cache/e5a38c254719000487098782125e15e2e982c07d66b99d359ed1781f30f9fc8c.json +0 -1
  150. package/graphify-out/cache/e6e4c4a5a7200ee0154585b5d6538f699b0a746dbded3164f8391f06ce7cb212.json +0 -1
  151. package/graphify-out/cache/ea8d0838df6309b673b031f616b253af957898ee7289d25a541fa6183b732e4e.json +0 -1
  152. package/graphify-out/cache/ebaee92b0e881efd7a08f3143e2c1803310396b4651d4f77532003c699cc6836.json +0 -1
  153. package/graphify-out/cache/edf8543318a9e60d56d04704078da6c37202ddd6fdfc83144fe2b94fe19b80ef.json +0 -1
  154. package/graphify-out/cache/efca19d3668035f11126fc9eccbeab290abfa94babf3f9a8706de81d17aba263.json +0 -1
  155. package/graphify-out/cache/f1480bb642025ebd6d99986cdd8a7d5726897ec038300e4b095c9c938435dfad.json +0 -1
  156. package/graphify-out/cache/f459f21277f03865f732affb175b1b092954dae5967f27b3cd1864466e3e24f4.json +0 -1
  157. package/graphify-out/cache/f899e37e864010b30f4c196e86082d7bd022a0df032005e0407883ebcec36514.json +0 -1
  158. package/graphify-out/cache/fb3cbe07fbcd97c536cff9c6bc343c35f22d49613f05c53ad30ef67a75c5d93e.json +0 -1
  159. package/graphify-out/cache/fd3dc682b1ca2f5ae03b50d6b0e045ae50f5701c0a21c5a388d77ef482939d3a.json +0 -1
  160. package/graphify-out/graph.html +0 -257
  161. package/graphify-out/graph.json +0 -4396
  162. package/scripts/e2e-external.mjs +0 -65
  163. package/scripts/live-agents.mjs +0 -6
  164. package/scripts/live-stream.mjs +0 -51
  165. package/src/commands/agents.ts +0 -91
  166. package/src/commands/auth.ts +0 -39
  167. package/src/commands/chat.ts +0 -198
  168. package/src/commands/keys.ts +0 -83
  169. package/src/commands/local.ts +0 -302
  170. package/src/commands/mcp.ts +0 -74
  171. package/src/commands/prompts.ts +0 -58
  172. package/src/commands/skills.ts +0 -43
  173. package/src/core/auth/index.ts +0 -101
  174. package/src/core/config/index.ts +0 -152
  175. package/src/core/history.ts +0 -79
  176. package/src/core/markdown-renderer.ts +0 -420
  177. package/src/core/permissions/index.ts +0 -99
  178. package/src/core/provider/external.ts +0 -312
  179. package/src/core/provider/index.ts +0 -517
  180. package/src/core/registry/index.ts +0 -250
  181. package/src/core/schema/types.ts +0 -106
  182. package/src/core/terminal.ts +0 -124
  183. package/src/core/workspace/index.ts +0 -216
  184. package/src/index.ts +0 -401
  185. package/src/ui/app.tsx +0 -644
  186. package/src/ui/commands/cases/catalog.ts +0 -76
  187. package/src/ui/commands/cases/misc.ts +0 -293
  188. package/src/ui/commands/cases/tasks.ts +0 -115
  189. package/src/ui/commands/runCommand.ts +0 -178
  190. package/src/ui/components/Banner.tsx +0 -63
  191. package/src/ui/components/CommandMenu.tsx +0 -63
  192. package/src/ui/components/ErrorBoundary.tsx +0 -75
  193. package/src/ui/components/InputBar.tsx +0 -227
  194. package/src/ui/components/KeysPanel.tsx +0 -115
  195. package/src/ui/components/MessageView.tsx +0 -226
  196. package/src/ui/components/Pickers.tsx +0 -234
  197. package/src/ui/components/SearchOverlay.tsx +0 -65
  198. package/src/ui/components/WorkingIndicator.tsx +0 -35
  199. package/src/ui/controls/ApiKeyEntry.tsx +0 -29
  200. package/src/ui/controls/MultiSelect.tsx +0 -55
  201. package/src/ui/hooks/useAgentPicker.ts +0 -64
  202. package/src/ui/hooks/useAuthFlow.ts +0 -47
  203. package/src/ui/hooks/useKeysFlow.ts +0 -157
  204. package/src/ui/hooks/useSessionPicker.ts +0 -84
  205. package/src/ui/hooks/useTerminalSize.ts +0 -36
  206. package/src/ui/input/keyRouter.ts +0 -627
  207. package/src/ui/layouts/ScreenLayout.tsx +0 -202
  208. package/src/ui/shared/types.ts +0 -160
  209. package/src/ui/theme.ts +0 -53
  210. package/src/ui/utils/markdown.ts +0 -255
  211. package/src/ui/utils/mentions.ts +0 -40
  212. package/src/ui/utils/terminal-text.ts +0 -130
  213. package/src/ui/utils/text.ts +0 -174
  214. package/test/commands.test.mjs +0 -127
  215. package/test/config.test.mjs +0 -123
  216. package/test/history.test.mjs +0 -42
  217. package/test/keyrouter.test.mjs +0 -324
  218. package/test/layout.test.mjs +0 -271
  219. package/test/markdown.test.mjs +0 -92
  220. package/test/mentions.test.mjs +0 -51
  221. package/test/permissions.test.mjs +0 -130
  222. package/test/provider.test.mjs +0 -287
  223. package/test/terminal-text.test.mjs +0 -116
  224. package/test/text.test.mjs +0 -134
  225. package/test/workspace.test.mjs +0 -101
  226. package/tsconfig.json +0 -32
@@ -1,65 +0,0 @@
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);
@@ -1,6 +0,0 @@
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);
@@ -1,51 +0,0 @@
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);
@@ -1,91 +0,0 @@
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
- });
@@ -1,39 +0,0 @@
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
- });
@@ -1,198 +0,0 @@
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
- });
@@ -1,83 +0,0 @@
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
- });