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

Function onExtensionMessage

apps/cli/src/commands/cli/stdin-stream.ts:445–567  ·  view source on GitHub ↗
(message: {
		type?: string
		text?: unknown
		state?: {
			currentTaskId?: unknown
			currentTaskItem?: { id?: unknown }
			messageQueue?: unknown
		}
	})

Source from the content-addressed store, hash-verified

443 })
444
445 const onExtensionMessage = (message: {
446 type?: string
447 text?: unknown
448 state?: {
449 currentTaskId?: unknown
450 currentTaskItem?: { id?: unknown }
451 messageQueue?: unknown
452 }
453 }) => {
454 if (message.type === "commandExecutionStatus") {
455 if (typeof message.text !== "string") {
456 return
457 }
458
459 let parsedStatus: unknown
460 try {
461 parsedStatus = JSON.parse(message.text)
462 } catch {
463 return
464 }
465
466 if (!isRecord(parsedStatus) || typeof parsedStatus.status !== "string") {
467 return
468 }
469
470 if (parsedStatus.status === "output" && typeof parsedStatus.output === "string") {
471 jsonEmitter.emitCommandOutputChunk(parsedStatus.output)
472 return
473 }
474
475 if (parsedStatus.status === "exited") {
476 const exitCode =
477 parsedStatus.status === "exited" && typeof parsedStatus.exitCode === "number"
478 ? parsedStatus.exitCode
479 : undefined
480
481 if (typeof parsedStatus.output === "string") {
482 jsonEmitter.emitCommandOutputChunk(parsedStatus.output)
483 }
484
485 jsonEmitter.markCommandOutputExited(exitCode)
486 return
487 }
488
489 if (parsedStatus.status === "timeout" || parsedStatus.status === "fallback") {
490 jsonEmitter.emitCommandOutputDone(undefined)
491 return
492 }
493
494 return
495 }
496
497 if (message.type !== "state") {
498 return
499 }
500
501 const currentTaskId = message.state?.currentTaskId ?? message.state?.currentTaskItem?.id
502 if (typeof currentTaskId === "string" && currentTaskId.trim().length > 0) {

Callers 1

initFunction · 0.85

Calls 10

parseQueueSnapshotFunction · 0.85
areStringArraysEqualFunction · 0.85
parseMethod · 0.80
emitCommandOutputDoneMethod · 0.80
emitQueueMethod · 0.80
isRecordFunction · 0.50

Tested by

no test coverage detected