MCPcopy Create free account
hub / github.com/antirez/ds4 / parse_generated_message_for_response

Function parse_generated_message_for_response

ds4_server.c:4700–4737  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4698 * the chat completion / Anthropic parsers do, so the rest of the engine sees a
4699 * single conversation history shape.
4700 *
4701 * Protocol contract for stateless replay:
4702 * - The client must replay response.output items before tool outputs.
4703 * - For reasoning models, the replay must also include reasoning state. DS4
4704 * can render plain reasoning summaries/content, but it cannot decrypt
4705 * reasoning.encrypted_content. If live state is unavailable and the replay
4706 * only contains visible messages/tool calls, later validation marks it as a
4707 * lower-fidelity replay; generate_job() logs that and continues from the
4708 * visible transcript rather than killing a recoverable agent session.
4709 *
4710 * Reasoning items are merged into the next assistant message so
4711 * render_chat_prompt_text can wrap them in <think>. */
4712static bool parse_responses_input(const char **p, chat_msgs *msgs,
4713 buf *loaded_tool_schemas,
4714 tool_schema_orders *orders) {
4715 json_ws(p);
4716 if (**p != '[') return false;
4717 (*p)++;
4718
4719 buf pending_reasoning = {0};
4720
4721 json_ws(p);
4722 while (**p && **p != ']') {
4723 if (**p != '{') goto fail;
4724 (*p)++;
4725 char *type = NULL;
4726 char *role = NULL;
4727 char *content = NULL;
4728 char *name = NULL;
4729 char *namespace = NULL;
4730 char *call_id = NULL;
4731 char *item_id = NULL;
4732 char *arguments = NULL;
4733 char *output = NULL;
4734 char *input_str = NULL;
4735 char *summary = NULL;
4736 char *action = NULL;
4737 char *result = NULL;
4738 char *tools_json = NULL;
4739 char *status_str = NULL;
4740 server_image_inputs content_images = {0}, output_images = {0};

Calls 4

tool_calls_freeFunction · 0.85
xstrdupFunction · 0.70