MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / init

Function init

apps/cli/src/ui/hooks/useExtensionHost.ts:102–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100
101 useEffect(() => {
102 const init = async () => {
103 try {
104 const requestedSessionId = initialSessionId?.trim()
105 let taskHistorySnapshot: HistoryItem[] = []
106 let hasReceivedTaskHistory = false
107
108 const host = createExtensionHost({
109 mode,
110 user,
111 reasoningEffort,
112 provider,
113 apiKey,
114 model,
115 workspacePath,
116 extensionPath,
117 nonInteractive,
118 ephemeral,
119 debug,
120 exitOnComplete,
121 disableOutput: true,
122 })
123
124 hostRef.current = host
125 isReadyRef.current = true
126
127 host.on("extensionWebviewMessage", (msg) => {
128 const extensionMessage = msg as ExtensionMessage
129 const taskHistory = extractTaskHistory(extensionMessage)
130
131 if (taskHistory) {
132 taskHistorySnapshot = taskHistory
133 hasReceivedTaskHistory = true
134 }
135
136 onExtensionMessage(extensionMessage)
137 })
138
139 host.client.on("taskCompleted", async () => {
140 setComplete(true)
141 setLoading(false)
142
143 if (exitOnComplete) {
144 await cleanup()
145 exit()
146 setTimeout(() => process.exit(0), 100)
147 }
148 })
149
150 host.client.on("error", (err: Error) => {
151 setError(err.message)
152 setLoading(false)
153 })
154
155 await host.activate()
156
157 // Request initial state from extension (triggers
158 // postStateToWebview which includes taskHistory).
159 host.sendToExtension({ type: "requestCommands" })

Callers 1

useExtensionHostFunction · 0.85

Calls 9

extractTaskHistoryFunction · 0.85
onExtensionMessageFunction · 0.85
getMostRecentTaskIdFunction · 0.85
onMethod · 0.65
activateMethod · 0.65
sendToExtensionMethod · 0.65
runTaskMethod · 0.65
cleanupFunction · 0.50
StringInterface · 0.50

Tested by

no test coverage detected