Elffuss BraidHub

kikocis/continue public

0a1f7aa3091d · 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 configPath?: string;
16 organizationSlug?: string;
17 additionalRules?: string[];
18 toolPermissionOverrides?: {
19 allow?: string[];
20 ask?: string[];
21 exclude?: string[];
22 mode?: PermissionMode;
23 };
24 skipOnboarding?: boolean;
25}
26
27export async function startTUIChat(
28 options: StartTUIChatOptions & { customStdin?: NodeJS.ReadStream },
29) {
30 const {
31 initialPrompt,
32 resume,
33 configPath,
34 organizationSlug,
35 additionalRules,
36 toolPermissionOverrides,
37 skipOnboarding,
38 customStdin,
39 } = options;
40
41 // Initialize services only if not already done (skipOnboarding means already initialized)
42 if (!skipOnboarding) {
43 await initializeServices({
44 configPath,
45 organizationSlug,
46 rules: additionalRules,
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,
64 initialPrompt,
65 resume,
66 additionalRules,
67 }),
68 }),
69 renderOptions,
70 );
71
72 // Handle cleanup
73 process.on("SIGINT", () => {
74 unmount();
75 process.exit(0);
76 });
77
78 return { unmount };
79}
80
81export async function startRemoteTUIChat(
82 remoteUrl: string,
83 initialPrompt?: string,
84) {
85 // Start the TUI in remote mode - no services needed
86 const { unmount } = render(
87 React.createElement(ServiceContainerProvider, {
88 children: React.createElement(AppRoot, {
89 remoteUrl,
90 initialPrompt,
91 }),
92 }),
93 );
94
95 // Handle cleanup
96 process.on("SIGINT", () => {
97 unmount();
98 process.exit(0);
99 });
100
101 return { unmount };
102}