




























@@ -643,7 +643,7 @@ function execCommandFromToolProgressPrompt(prompt: string) {
643643);
644644}
645645646-function buildToolCallEventsWithArgs(name: string, args: Record<string, unknown>): StreamEvent[] {
646+function buildMockFunctionCall(name: string, args: Record<string, unknown>) {
647647const serialized = JSON.stringify(args);
648648const callSuffix = createHash("sha1")
649649.update(name)
@@ -653,42 +653,46 @@ function buildToolCallEventsWithArgs(name: string, args: Record<string, unknown>
653653.slice(0, 10);
654654const callId = `call_mock_${name}_${callSuffix}`;
655655const itemId = `fc_mock_${name}_${callSuffix}`;
656+const item = {
657+type: "function_call",
658+id: itemId,
659+call_id: callId,
660+ name,
661+arguments: serialized,
662+};
663+return {
664+ callId,
665+ item,
666+ itemId,
667+responseId: `resp_mock_${name}_${callSuffix}`,
668+ serialized,
669+};
670+}
671+672+function buildToolCallEventsWithArgs(name: string, args: Record<string, unknown>): StreamEvent[] {
673+const call = buildMockFunctionCall(name, args);
656674return [
657675{
658676type: "response.output_item.added",
659677item: {
660678type: "function_call",
661-id: itemId,
662-call_id: callId,
679+id: call.itemId,
680+call_id: call.callId,
663681 name,
664682arguments: "",
665683},
666684},
667-{ type: "response.function_call_arguments.delta", delta: serialized },
685+{ type: "response.function_call_arguments.delta", delta: call.serialized },
668686{
669687type: "response.output_item.done",
670-item: {
671-type: "function_call",
672-id: itemId,
673-call_id: callId,
674- name,
675-arguments: serialized,
676-},
688+item: call.item,
677689},
678690{
679691type: "response.completed",
680692response: {
681-id: `resp_mock_${name}_${callSuffix}`,
693+id: call.responseId,
682694status: "completed",
683-output: [
684-{
685-type: "function_call",
686-id: itemId,
687-call_id: callId,
688- name,
689-arguments: serialized,
690-},
691-],
695+output: [call.item],
692696usage: { input_tokens: 64, output_tokens: 16, total_tokens: 80 },
693697},
694698},
@@ -1449,6 +1453,78 @@ function buildAssistantOutputItem(spec: MockAssistantMessageSpec) {
14491453} as const;
14501454}
145114551456+function appendAssistantMessageEvents(events: StreamEvent[], spec: MockAssistantMessageSpec) {
1457+events.push({
1458+type: "response.output_item.added",
1459+item: {
1460+type: "message",
1461+id: spec.id,
1462+role: "assistant",
1463+ ...(spec.phase ? { phase: spec.phase } : {}),
1464+content: [],
1465+status: "in_progress",
1466+},
1467+});
1468+for (const delta of spec.streamDeltas ?? []) {
1469+events.push({
1470+type: "response.output_text.delta",
1471+item_id: spec.id,
1472+output_index: 0,
1473+content_index: 0,
1474+ delta,
1475+});
1476+}
1477+if ((spec.streamDeltas ?? []).length > 0) {
1478+events.push({
1479+type: "response.output_text.done",
1480+item_id: spec.id,
1481+output_index: 0,
1482+content_index: 0,
1483+text: spec.text,
1484+});
1485+}
1486+events.push({
1487+type: "response.output_item.done",
1488+item: buildAssistantOutputItem(spec),
1489+});
1490+}
1491+1492+function buildAssistantThenToolCallEvents(
1493+spec: MockAssistantMessageSpec,
1494+name: string,
1495+args: Record<string, unknown>,
1496+): StreamEvent[] {
1497+const call = buildMockFunctionCall(name, args);
1498+const message = buildAssistantOutputItem(spec);
1499+const events: StreamEvent[] = [];
1500+appendAssistantMessageEvents(events, spec);
1501+events.push({
1502+type: "response.output_item.added",
1503+item: {
1504+type: "function_call",
1505+id: call.itemId,
1506+call_id: call.callId,
1507+ name,
1508+arguments: "",
1509+},
1510+});
1511+events.push({ type: "response.function_call_arguments.delta", delta: call.serialized });
1512+events.push({
1513+type: "response.output_item.done",
1514+item: call.item,
1515+});
1516+events.push({
1517+type: "response.completed",
1518+response: {
1519+id: call.responseId,
1520+status: "completed",
1521+output: [message, call.item],
1522+usage: { input_tokens: 64, output_tokens: 32, total_tokens: 96 },
1523+},
1524+});
1525+return events;
1526+}
1527+14521528function buildAssistantEvents(specsOrText: MockAssistantMessageSpec[] | string): StreamEvent[] {
14531529const specs =
14541530typeof specsOrText === "string"
@@ -1861,13 +1937,21 @@ async function buildResponsesPayload(
18611937return buildAssistantEvents(toolProgressReplyDirective);
18621938}
18631939if (QA_BLOCK_STREAMING_PROMPT_RE.test(allInputText) && blockStreamingMarkers) {
1940+if (!toolOutput) {
1941+return buildAssistantThenToolCallEvents(
1942+{
1943+id: "msg_mock_block_1",
1944+phase: "final_answer",
1945+streamDeltas: splitMockStreamingText(blockStreamingMarkers.first),
1946+text: blockStreamingMarkers.first,
1947+},
1948+"read",
1949+{
1950+path: readTargetFromPrompt(blockStreamingPrompt),
1951+},
1952+);
1953+}
18641954return buildAssistantEvents([
1865-{
1866-id: "msg_mock_block_1",
1867-phase: "final_answer",
1868-streamDeltas: splitMockStreamingText(blockStreamingMarkers.first),
1869-text: blockStreamingMarkers.first,
1870-},
18711955{
18721956id: "msg_mock_block_2",
18731957phase: "final_answer",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。