chatbase 0.0.1 → 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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1524 -6
  3. package/bin/run.js +4 -0
  4. package/dist/base/agent-command.js +40 -0
  5. package/dist/base/agent-ref.js +16 -0
  6. package/dist/base/assert-file.js +21 -0
  7. package/dist/base/base-command.js +203 -0
  8. package/dist/base/body-input.js +77 -0
  9. package/dist/base/list-command.js +16 -0
  10. package/dist/base/sources.js +33 -0
  11. package/dist/client/chat-helpers.js +173 -0
  12. package/dist/client/client.js +175 -0
  13. package/dist/client/files.js +64 -0
  14. package/dist/client/paginate.js +40 -0
  15. package/dist/client/pairing.js +76 -0
  16. package/dist/client/retry.js +40 -0
  17. package/dist/client/signals.js +43 -0
  18. package/dist/client/stream.js +79 -0
  19. package/dist/commands/agents/auto-retrain.js +46 -0
  20. package/dist/commands/agents/clone.js +28 -0
  21. package/dist/commands/agents/create.js +43 -0
  22. package/dist/commands/agents/delete.js +41 -0
  23. package/dist/commands/agents/get.js +52 -0
  24. package/dist/commands/agents/list.js +48 -0
  25. package/dist/commands/agents/styles.js +44 -0
  26. package/dist/commands/agents/train.js +31 -0
  27. package/dist/commands/agents/update.js +47 -0
  28. package/dist/commands/api.js +69 -0
  29. package/dist/commands/auth/login.js +125 -0
  30. package/dist/commands/auth/logout.js +38 -0
  31. package/dist/commands/auth/status.js +86 -0
  32. package/dist/commands/chat/index.js +210 -0
  33. package/dist/commands/chat/retry.js +49 -0
  34. package/dist/commands/config/get.js +40 -0
  35. package/dist/commands/config/list.js +34 -0
  36. package/dist/commands/config/set.js +106 -0
  37. package/dist/commands/conversations/export.js +75 -0
  38. package/dist/commands/conversations/get.js +69 -0
  39. package/dist/commands/conversations/list.js +75 -0
  40. package/dist/commands/health.js +22 -0
  41. package/dist/commands/helpdesk/statuses.js +31 -0
  42. package/dist/commands/helpdesk/teams.js +25 -0
  43. package/dist/commands/messages/feedback.js +64 -0
  44. package/dist/commands/messages/list.js +55 -0
  45. package/dist/commands/sources/create.js +134 -0
  46. package/dist/commands/sources/delete.js +28 -0
  47. package/dist/commands/sources/get.js +35 -0
  48. package/dist/commands/sources/list.js +47 -0
  49. package/dist/commands/sources/restore.js +22 -0
  50. package/dist/commands/sources/summary.js +33 -0
  51. package/dist/commands/sources/update.js +76 -0
  52. package/dist/commands/tickets/create.js +58 -0
  53. package/dist/commands/tickets/get.js +44 -0
  54. package/dist/commands/tickets/list.js +96 -0
  55. package/dist/commands/tickets/messages.js +87 -0
  56. package/dist/commands/tickets/reply.js +66 -0
  57. package/dist/commands/tickets/search.js +53 -0
  58. package/dist/commands/tickets/update.js +38 -0
  59. package/dist/config/paths.js +22 -0
  60. package/dist/config/resolve.js +37 -0
  61. package/dist/config/store.js +38 -0
  62. package/dist/errors/errors.js +81 -0
  63. package/dist/hooks/chat-message-hint.js +21 -0
  64. package/dist/output/color.js +30 -0
  65. package/dist/output/mode.js +7 -0
  66. package/dist/output/render.js +0 -0
  67. package/dist/output/spinner.js +37 -0
  68. package/dist/repl/chat-repl.js +129 -0
  69. package/dist/version.js +3 -0
  70. package/oclif.manifest.json +3948 -0
  71. package/package.json +92 -4
  72. package/spec/openapi.json +11843 -0
@@ -0,0 +1,129 @@
1
+ import readline from 'node:readline';
2
+ const GREETING = 'Type /exit or press Ctrl-D to quit. Ctrl-C cancels a response. /help for commands.';
3
+ const HELP_LINES = [
4
+ '/exit Quit the REPL (same as Ctrl-D)',
5
+ '/new Start a fresh conversation (clears the current conversation id)',
6
+ '/retry Regenerate the last response (replaces it in the conversation)',
7
+ '/id Print the current conversation id',
8
+ '/help Show this list'
9
+ ];
10
+ /** True for the AbortError a cancelled `send`/`retry` call rejects with —
11
+ * matches the same duck-typed check `classifyError` uses in base-command.ts. */
12
+ function isAbortError(err) {
13
+ return err?.name === 'AbortError';
14
+ }
15
+ /**
16
+ * Runs the interactive chat REPL. Dependency-injected (send/retry/input/
17
+ * output/info) so tests can drive it with fake streams and fake network
18
+ * calls — the `chat` command wires real stdin/stdout and `sendChat`.
19
+ *
20
+ * Ctrl-C semantics: readline is created with `terminal: true` so it parses
21
+ * Ctrl-C (byte 0x03) itself and emits its own 'SIGINT' event, distinct from
22
+ * the process-wide SIGINT the rest of the CLI listens for (see
23
+ * client/signals.ts) — forcing `terminal: true` is what makes this
24
+ * intercept work even over the plain PassThrough streams used in tests,
25
+ * not just a real TTY. While a `send`/`retry` call is in flight, that event
26
+ * aborts *that call's own* AbortController only; at an idle prompt (nothing
27
+ * in flight) it exits the REPL, same as /exit.
28
+ */
29
+ export async function runChatRepl(deps) {
30
+ const { send, retry, input, output, info } = deps;
31
+ let conversationId = deps.initialConversationId;
32
+ let currentController;
33
+ const rl = readline.createInterface({
34
+ input,
35
+ output,
36
+ terminal: true,
37
+ prompt: '> '
38
+ });
39
+ rl.on('SIGINT', () => {
40
+ if (currentController) {
41
+ currentController.abort();
42
+ return;
43
+ }
44
+ rl.close();
45
+ });
46
+ // Readline closes the moment its input ends (Ctrl-D, or a piped stream
47
+ // finishing), but the `for await` loop below may still be draining lines
48
+ // readline buffered before that. prompt() on a closed interface is a
49
+ // silent no-op on Node 20/22 but throws ERR_USE_AFTER_CLOSE on Node 24+,
50
+ // so every prompt goes through this close-aware wrapper.
51
+ let closed = false;
52
+ rl.once('close', () => {
53
+ closed = true;
54
+ });
55
+ const prompt = () => {
56
+ if (!closed)
57
+ rl.prompt();
58
+ };
59
+ /** Runs `fn` under a fresh per-call AbortController wired to the
60
+ * readline-level Ctrl-C above. Swallows the resulting AbortError (and
61
+ * any other failure) so one bad turn never crashes the whole REPL —
62
+ * it prints a note via `info` and returns to the prompt either way. */
63
+ async function cancelable(fn) {
64
+ const controller = new AbortController();
65
+ currentController = controller;
66
+ try {
67
+ return await fn(controller.signal);
68
+ }
69
+ catch (err) {
70
+ // A cancelled or failed call may have already streamed partial
71
+ // text straight to `output` with no trailing newline (send/retry
72
+ // write tokens as they arrive) — start the note on its own line.
73
+ output.write('\n');
74
+ if (isAbortError(err)) {
75
+ info('[cancelled — response was interrupted]');
76
+ }
77
+ else {
78
+ info(`✗ ${err?.message ?? err}`);
79
+ }
80
+ return undefined;
81
+ }
82
+ finally {
83
+ currentController = undefined;
84
+ }
85
+ }
86
+ info(GREETING);
87
+ prompt();
88
+ for await (const rawLine of rl) {
89
+ const line = rawLine.trim();
90
+ if (line === '') {
91
+ prompt();
92
+ continue;
93
+ }
94
+ if (line.startsWith('/')) {
95
+ const cmd = line.split(/\s+/, 1)[0];
96
+ if (cmd === '/exit')
97
+ break;
98
+ if (cmd === '/new') {
99
+ conversationId = undefined;
100
+ }
101
+ else if (cmd === '/retry') {
102
+ if (!conversationId) {
103
+ info('No conversation yet — send a message first.');
104
+ }
105
+ else {
106
+ await cancelable((signal) => retry(conversationId, signal));
107
+ }
108
+ }
109
+ else if (cmd === '/id') {
110
+ info(conversationId ?? 'none');
111
+ }
112
+ else if (cmd === '/help') {
113
+ for (const helpLine of HELP_LINES)
114
+ info(helpLine);
115
+ }
116
+ else {
117
+ info(`Unknown command: ${cmd} — type /help for a list.`);
118
+ }
119
+ prompt();
120
+ continue;
121
+ }
122
+ const result = await cancelable((signal) => send(line, conversationId, signal));
123
+ if (result?.conversationId)
124
+ conversationId = result.conversationId;
125
+ prompt();
126
+ }
127
+ rl.close();
128
+ return { conversationId };
129
+ }
@@ -0,0 +1,3 @@
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
3
+ export const VERSION = require('../package.json').version;