MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / normalizePromptInput

Function normalizePromptInput

packages/node-sdk/src/session.ts:555–596  ·  view source on GitHub ↗
(input: string | PromptInput)

Source from the content-addressed store, hash-verified

553}
554
555function normalizePromptInput(input: string | PromptInput): PromptInput {
556 if (typeof input === 'string') {
557 if (input.trim().length === 0) {
558 throw new KimiError(ErrorCodes.REQUEST_PROMPT_INPUT_EMPTY, 'Prompt input cannot be empty');
559 }
560 return [{ type: 'text', text: input }];
561 }
562
563 if (input.length === 0) {
564 throw new KimiError(ErrorCodes.REQUEST_PROMPT_INPUT_EMPTY, 'Prompt input cannot be empty');
565 }
566
567 for (const part of input) {
568 switch (part.type) {
569 case 'text':
570 if (part.text.trim().length === 0) {
571 throw new KimiError(
572 ErrorCodes.REQUEST_PROMPT_INPUT_EMPTY,
573 'Prompt input cannot contain empty text parts',
574 );
575 }
576 break;
577 case 'image_url':
578 if (part.imageUrl.url.trim().length === 0) {
579 throw new KimiError(
580 ErrorCodes.REQUEST_PROMPT_INPUT_EMPTY,
581 'Prompt input cannot contain empty image URLs',
582 );
583 }
584 break;
585 case 'video_url':
586 if (part.videoUrl.url.trim().length === 0) {
587 throw new KimiError(
588 ErrorCodes.REQUEST_PROMPT_INPUT_EMPTY,
589 'Prompt input cannot contain empty video URLs',
590 );
591 }
592 break;
593 }
594 }
595 return input;
596}
597
598function normalizeRequiredString(
599 value: string,

Callers 3

promptMethod · 0.85
steerMethod · 0.85
swarmMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected