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

Method submitAndWait

packages/server-e2e/src/client.ts:607–630  ·  view source on GitHub ↗

* Submit a prompt and wait for its terminal event. `waitFor` defaults to * the synthesized `prompt.completed` event (broadcast after `turn.ended` * lands for the same prompt). Returns `prompt_id` and the matching frame.

(
    sid: string,
    input: PromptSubmitInput,
    opts: SubmitAndWaitOptions = {},
  )

Source from the content-addressed store, hash-verified

605 * lands for the same prompt). Returns `prompt_id` and the matching frame.
606 */
607 async submitAndWait(
608 sid: string,
609 input: PromptSubmitInput,
610 opts: SubmitAndWaitOptions = {},
611 ): Promise<{ prompt_id: string; user_message_id: string; finalFrame: AnyFrame }> {
612 const ws = this._requireWs();
613 const waitFor = opts.waitFor ?? 'prompt.completed';
614 const timeoutMs = opts.timeoutMs ?? DEFAULT_FRAME_TIMEOUT_MS;
615
616 // POST the prompt FIRST — without `prompt_id` we have nothing to match on.
617 // The WS layer queues every frame from the moment we open, so any events
618 // that arrive between this POST and the `waitForFrame` below are still
619 // there to be matched (they're drained from the queue, not dropped).
620 const submit = await this.http.submitPrompt(sid, fillPromptDefaults(input));
621
622 const finalFrame = await ws.waitForFrame((f) => {
623 if (f.type !== waitFor) return false;
624 const payload = (f.payload as { promptId?: string; prompt_id?: string } | undefined) ?? {};
625 const pid = payload.promptId ?? payload.prompt_id;
626 return pid === submit.prompt_id;
627 }, timeoutMs);
628
629 return { prompt_id: submit.prompt_id, user_message_id: submit.user_message_id, finalFrame };
630 }
631
632 /**
633 * Stateful-session companion to `submitAndWait` — POSTs `body` verbatim

Callers 11

mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
client.test.tsFile · 0.80

Calls 4

_requireWsMethod · 0.95
fillPromptDefaultsFunction · 0.85
submitPromptMethod · 0.65
waitForFrameMethod · 0.45

Tested by

no test coverage detected