Elffuss BraidHub

kikocis/continue public

e9ecc1af12bb · 2.3 KiBRawPermalink
1import { render } from "ink";
2import React from "react";
3
4import { PermissionMode } from "../permissions/types.js";
5import { initializeServices } from "../services/index.js";
6import { ServiceContainerProvider } from "../services/ServiceContainerContext.js";
7
8import { AppRoot } from "./AppRoot.js";
9
10export { MarkdownRenderer } from "./MarkdownRenderer.js";
11
12interface StartTUIChatOptions {
13 initialPrompt?: string;
14 resume?: boolean;
15 config?: string;
16 org?: string;
17 rule?: string[];
18 prompt?: string[];
19 toolPermissionOverrides?: {
20 allow?: string[];
21 ask?: string[];
22 exclude?: string[];
23 mode?: PermissionMode;
24 };
25 skipOnboarding?: boolean;
26}
27
28export async function startTUIChat(
29 options: StartTUIChatOptions & { customStdin?: NodeJS.ReadStream },
30) {
31 const {
32 initialPrompt,
33 resume,
34 config,
35 org,
36 rule,
37 prompt,
38 toolPermissionOverrides,
39 skipOnboarding,
40 customStdin,
41 } = options;
42
43 // Initialize services only if not already done (skipOnboarding means already initialized)
44 if (!skipOnboarding) {
45 await initializeServices({
46 options: { config, org, rule, prompt },
47 headless: false,
48 toolPermissionOverrides,
49 });
50 }
51
52 // Use static imports since we're always loading TUI when there's piped input
53
54 // Start the TUI immediately - it will handle loading states
55 const renderOptions: any = {};
56 if (customStdin) {
57 renderOptions.stdin = customStdin;
58 }
59
60 const { unmount } = render(
61 React.createElement(ServiceContainerProvider, {
62 children: React.createElement(AppRoot, {
63 configPath: config,
64 initialPrompt,
65 resume,
66 additionalRules: rule,
67 additionalPrompts: prompt,
68 }),
69 }),
70 renderOptions,
71 );
72
73 // Handle cleanup
74 process.on("SIGINT", () => {
75 unmount();
76 process.exit(0);
77 });
78
79 return { unmount };
80}
81
82export async function startRemoteTUIChat(
83 remoteUrl: string,
84 initialPrompt?: string,
85) {
86 // Start the TUI in remote mode - no services needed
87 const { unmount } = render(
88 React.createElement(ServiceContainerProvider, {
89 children: React.createElement(AppRoot, {
90 remoteUrl,
91 initialPrompt,
92 }),
93 }),
94 );
95
96 // Handle cleanup
97 process.on("SIGINT", () => {
98 unmount();
99 process.exit(0);
100 });
101
102 return { unmount };
103}