(host: HostConnection, message: RuntimeHostMainRequestMessage)
| 269 | if (message.type === 'response') handleHostResponseMessage(host, message) |
| 270 | } |
| 271 | async function handleHostMainRequest(host: HostConnection, message: RuntimeHostMainRequestMessage) { |
| 272 | try { |
| 273 | let result: unknown |
| 274 | switch (message.name) { |
| 275 | case 'getSessionNativeExtensions': { |
| 276 | const payload = message.payload as { sessionPath: string } |
| 277 | result = getSessionNativeExtensions(payload.sessionPath) |
| 278 | break |
| 279 | } |
| 280 | case 'setSessionNativeExtensions': { |
| 281 | const payload = message.payload as { sessionPath: string; enabled: string[] } |
| 282 | setSessionNativeExtensions(payload.sessionPath, payload.enabled) |
| 283 | result = { ok: true } |
| 284 | break |
| 285 | } |
| 286 | case 'snapshotDefaultNativeExtensions': { |
| 287 | result = loadAppSettings().howcodeNativeAskQuestions ? ['askQuestions'] : [] |
| 288 | break |
| 289 | } |
| 290 | case 'createArtifact': { |
| 291 | const payload = message.payload as Parameters<typeof createArtifact>[0] |
| 292 | result = createArtifact(payload) |
| 293 | break |
| 294 | } |
| 295 | case 'updateArtifact': { |
| 296 | const payload = message.payload as Parameters<typeof updateArtifact>[0] |
| 297 | result = updateArtifact(payload) |
| 298 | break |
| 299 | } |
| 300 | case 'editArtifact': { |
| 301 | const payload = message.payload as Parameters<typeof editArtifact>[0] |
| 302 | result = editArtifact(payload) |
| 303 | break |
| 304 | } |
| 305 | case 'getArtifact': { |
| 306 | const payload = message.payload as { |
| 307 | artifactSlug: string |
| 308 | conversationId?: string | undefined | null | undefined |
| 309 | } |
| 310 | result = getArtifact(payload.artifactSlug, payload.conversationId) |
| 311 | break |
| 312 | } |
| 313 | case 'listArtifacts': { |
| 314 | const payload = message.payload as { conversationId: string } |
| 315 | result = listArtifacts(payload.conversationId) |
| 316 | break |
| 317 | } |
| 318 | default: |
| 319 | throw new Error(`Unknown runtime host main request: ${message.name}`) |
| 320 | } |
| 321 | host.process?.send?.({ type: 'main-response', id: message.id, ok: true, result }) |
| 322 | } catch (error) { |
| 323 | host.process?.send?.({ |
| 324 | type: 'main-response', |
| 325 | id: message.id, |
| 326 | ok: false, |
| 327 | error: error instanceof Error ? error.message : String(error), |
| 328 | stack: error instanceof Error ? error.stack : undefined, |
no test coverage detected