MCPcopy Create free account
hub / github.com/apache/maka / isRuntimeEventContent

Function isRuntimeEventContent

packages/core/src/runtime-event.ts:636–693  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

634}
635
636function isRuntimeEventContent(value: unknown): value is RuntimeEventContent {
637 if (!isRecord(value)) return false;
638 switch (value.kind) {
639 case 'text':
640 if (
641 !hasExactShape(value, TEXT_CONTENT_SHAPE) ||
642 (value.origin !== undefined && !isTurnOrigin(value.origin)) ||
643 (value.steering !== undefined && value.steering !== true) ||
644 (value.providerOptions !== undefined && !isRecord(value.providerOptions))
645 ) {
646 return false;
647 }
648 return isMessageContent({
649 text: value.text,
650 ...(value.displayText !== undefined ? { displayText: value.displayText } : {}),
651 ...(value.attachments !== undefined ? { attachments: value.attachments } : {}),
652 ...(value.quotes !== undefined ? { quotes: value.quotes } : {}),
653 ...(value.inlineReferences !== undefined
654 ? { inlineReferences: value.inlineReferences }
655 : {}),
656 });
657 case 'thinking':
658 return (
659 hasExactShape(value, THINKING_CONTENT_SHAPE) &&
660 typeof value.text === 'string' &&
661 isOptionalString(value.signature) &&
662 (value.providerOptions === undefined || isRecord(value.providerOptions))
663 );
664 case 'function_call':
665 return (
666 hasExactShape(value, FUNCTION_CALL_CONTENT_SHAPE) &&
667 typeof value.id === 'string' &&
668 typeof value.name === 'string' &&
669 Object.hasOwn(value, 'args') &&
670 (value.providerOptions === undefined || isRecord(value.providerOptions)) &&
671 (value.providerExecuted === undefined || typeof value.providerExecuted === 'boolean')
672 );
673 case 'function_response':
674 return (
675 hasExactShape(value, FUNCTION_RESPONSE_CONTENT_SHAPE) &&
676 typeof value.id === 'string' &&
677 typeof value.name === 'string' &&
678 Object.hasOwn(value, 'result') &&
679 (value.isError === undefined || typeof value.isError === 'boolean') &&
680 (value.providerExecuted === undefined || typeof value.providerExecuted === 'boolean')
681 );
682 case 'error':
683 return (
684 hasExactShape(value, ERROR_CONTENT_SHAPE) &&
685 isOptionalString(value.code) &&
686 isOptionalString(value.reason) &&
687 typeof value.message === 'string' &&
688 (value.details === undefined || isStringArray(value.details) || isRecord(value.details))
689 );
690 default:
691 return false;
692 }
693}

Callers 1

decodeRuntimeEventFunction · 0.85

Calls 6

isRecordFunction · 0.90
hasExactShapeFunction · 0.85
isTurnOriginFunction · 0.85
isMessageContentFunction · 0.85
isOptionalStringFunction · 0.70
isStringArrayFunction · 0.70

Tested by

no test coverage detected