@bastani/pi-ai 0.9.43 → 0.9.44-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +45 -58
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/azure-openai-responses.d.ts.map +1 -1
- package/dist/api/azure-openai-responses.js +0 -6
- package/dist/api/azure-openai-responses.js.map +1 -1
- package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/dist/api/bedrock-converse-stream.js +71 -78
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/constrained-sampling.d.ts +11 -1
- package/dist/api/constrained-sampling.d.ts.map +1 -1
- package/dist/api/constrained-sampling.js +33 -18
- package/dist/api/constrained-sampling.js.map +1 -1
- package/dist/api/google-generative-ai.d.ts.map +1 -1
- package/dist/api/google-generative-ai.js +0 -6
- package/dist/api/google-generative-ai.js.map +1 -1
- package/dist/api/google-shared.d.ts +2 -1
- package/dist/api/google-shared.d.ts.map +1 -1
- package/dist/api/google-shared.js +57 -2
- package/dist/api/google-shared.js.map +1 -1
- package/dist/api/google-vertex.d.ts.map +1 -1
- package/dist/api/google-vertex.js +0 -6
- package/dist/api/google-vertex.js.map +1 -1
- package/dist/api/mistral-conversations.d.ts.map +1 -1
- package/dist/api/mistral-conversations.js +17 -44
- package/dist/api/mistral-conversations.js.map +1 -1
- package/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.js +0 -5
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +34 -53
- package/dist/api/openai-completions.js.map +1 -1
- package/dist/api/openai-responses-shared.d.ts.map +1 -1
- package/dist/api/openai-responses-shared.js +58 -57
- package/dist/api/openai-responses-shared.js.map +1 -1
- package/dist/api/openai-responses.d.ts.map +1 -1
- package/dist/api/openai-responses.js +0 -6
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/api/pi-messages.d.ts +2 -0
- package/dist/api/pi-messages.d.ts.map +1 -1
- package/dist/api/pi-messages.js +15 -9
- package/dist/api/pi-messages.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/kimi-coding.json +1 -1
- package/dist/providers/data/moonshotai-cn.json +1 -1
- package/dist/providers/data/moonshotai.json +1 -1
- package/dist/providers/data/opencode-go.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/faux.d.ts.map +1 -1
- package/dist/providers/faux.js +7 -2
- package/dist/providers/faux.js.map +1 -1
- package/dist/providers/radius-config.d.ts.map +1 -1
- package/dist/providers/radius-config.js +2 -1
- package/dist/providers/radius-config.js.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/error-body.d.ts.map +1 -1
- package/dist/utils/error-body.js +2 -1
- package/dist/utils/error-body.js.map +1 -1
- package/dist/utils/streaming-json.d.ts +84 -0
- package/dist/utils/streaming-json.d.ts.map +1 -0
- package/dist/utils/streaming-json.js +513 -0
- package/dist/utils/streaming-json.js.map +1 -0
- package/dist/utils/text.d.ts +7 -0
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +9 -0
- package/dist/utils/text.js.map +1 -1
- package/dist/utils/version.d.ts +1 -1
- package/dist/utils/version.d.ts.map +1 -1
- package/dist/utils/version.js +1 -1
- package/dist/utils/version.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-responses-shared.d.ts","sourceRoot":"","sources":["../../src/api/openai-responses-shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,IAAI,IAAI,UAAU,EAElB,6BAA6B,EAC7B,aAA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,CAAC;IAC3C;;;;;;;;OAQG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,4BAA4B;IAC5C,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B;AAMD;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAChD,8BAA8B,CAAC,EAAE,OAAO,CAAC;IACzC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B,GAAG,qBAAqB,CAGxB;AAkBD,wBAAgB,wBAAwB,CAAC,IAAI,SAAS,GAAG,EACxD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,iBAAiB,EAC1B,wBAAwB,EAAE,WAAW,CAAC,MAAM,CAAC,EAC7C,OAAO,CAAC,EAAE,+BAA+B,GACvC,aAAa,CA+Of;AAMD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,4BAA4B,GAAG,UAAU,EAAE,CAqClH;AA2BD,wBAAsB,sBAAsB,CAAC,IAAI,SAAS,GAAG,EAC5D,YAAY,EAAE,aAAa,CAAC,mBAAmB,CAAC,EAChD,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,2BAA2B,EACnC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,CAAC,EAAE,4BAA4B,GACpC,OAAO,CAAC,IAAI,CAAC,CAsUf"}
|
|
@@ -3,11 +3,11 @@ import { normalizeProviderId } from "../provider-id.js";
|
|
|
3
3
|
import { appendAssistantMessageDiagnostic } from "../utils/diagnostics.js";
|
|
4
4
|
import { normalizeProviderError } from "../utils/error-body.js";
|
|
5
5
|
import { shortHash } from "../utils/hash.js";
|
|
6
|
-
import { parseStreamingJson, parseToolCallArguments } from "../utils/json-parse.js";
|
|
7
6
|
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
7
|
+
import { ToolCallArgumentsStream } from "../utils/streaming-json.js";
|
|
8
8
|
import { getSystemMessageText, renderSystemMessageUpdate } from "../utils/text.js";
|
|
9
9
|
import { resolveTranscript, resolveTranscriptTools } from "../utils/transcript.js";
|
|
10
|
-
import { appendGrammarToolInputJsonDelta, getGrammarToolInput, getJsonSchemaToolParameters, resolveGrammarConstrainedSampling, resolveJsonSchemaStrictSampling, } from "./constrained-sampling.js";
|
|
10
|
+
import { appendGrammarToolInputJsonDelta, closeGrammarToolInputJson, getGrammarToolInput, getJsonSchemaToolParameters, resolveGrammarConstrainedSampling, resolveJsonSchemaStrictSampling, } from "./constrained-sampling.js";
|
|
11
11
|
import { transformMessages } from "./transform-messages.js";
|
|
12
12
|
// =============================================================================
|
|
13
13
|
// Utilities
|
|
@@ -558,24 +558,11 @@ export function convertResponsesTools(tools, options) {
|
|
|
558
558
|
return functionTool;
|
|
559
559
|
});
|
|
560
560
|
}
|
|
561
|
-
function getCustomToolCallInput(block) {
|
|
562
|
-
const property = block.customInput?.property;
|
|
563
|
-
if (property === undefined)
|
|
564
|
-
return "";
|
|
565
|
-
const value = block.arguments[property];
|
|
566
|
-
return typeof value === "string" ? value : "";
|
|
567
|
-
}
|
|
568
|
-
function appendCustomToolCallInput(block, nextInput, close) {
|
|
569
|
-
const customInput = block.customInput;
|
|
570
|
-
if (!customInput)
|
|
571
|
-
return undefined;
|
|
572
|
-
const delta = appendGrammarToolInputJsonDelta(customInput.jsonBuffer, customInput.property, nextInput, close);
|
|
573
|
-
block.arguments = { [customInput.property]: nextInput };
|
|
574
|
-
return delta;
|
|
575
|
-
}
|
|
576
561
|
export async function processResponsesStream(openaiStream, output, stream, model, options) {
|
|
577
562
|
let sawTerminalResponseEvent = false;
|
|
578
563
|
const outputSlots = new Map();
|
|
564
|
+
// Tool calls whose output_item.done has not arrived yet.
|
|
565
|
+
const unfinishedToolCalls = new Set();
|
|
579
566
|
const reasoningBlocksById = new Map();
|
|
580
567
|
const applyMessagePhaseStopReason = (item) => {
|
|
581
568
|
if (item.type === "message" && item.phase === "final_answer") {
|
|
@@ -619,19 +606,21 @@ export async function processResponsesStream(openaiStream, output, stream, model
|
|
|
619
606
|
return slot;
|
|
620
607
|
}
|
|
621
608
|
if (item.type === "function_call") {
|
|
609
|
+
const args = new ToolCallArgumentsStream();
|
|
622
610
|
const block = {
|
|
623
611
|
type: "toolCall",
|
|
624
612
|
id: `${item.call_id}|${item.id}`,
|
|
625
613
|
name: item.name,
|
|
626
|
-
arguments: {},
|
|
614
|
+
arguments: item.arguments ? args.append(item.arguments) : {},
|
|
627
615
|
...(item.namespace !== undefined ? { namespace: item.namespace } : {}),
|
|
628
|
-
partialJson: item.arguments || "",
|
|
629
616
|
};
|
|
630
617
|
output.content.push(block);
|
|
618
|
+
unfinishedToolCalls.add(block);
|
|
631
619
|
const slot = {
|
|
632
620
|
type: "toolCall",
|
|
633
621
|
block,
|
|
634
622
|
contentIndex: output.content.length - 1,
|
|
623
|
+
input: { kind: "json", arguments: args },
|
|
635
624
|
};
|
|
636
625
|
outputSlots.set(outputIndex, slot);
|
|
637
626
|
stream.push({ type: "toolcall_start", contentIndex: slot.contentIndex, partial: output });
|
|
@@ -646,16 +635,14 @@ export async function processResponsesStream(openaiStream, output, stream, model
|
|
|
646
635
|
name: item.name,
|
|
647
636
|
arguments: { [inputProperty]: input },
|
|
648
637
|
...(item.namespace !== undefined ? { namespace: item.namespace } : {}),
|
|
649
|
-
customInput: {
|
|
650
|
-
property: inputProperty,
|
|
651
|
-
jsonBuffer: { input: "", started: false, closed: false },
|
|
652
|
-
},
|
|
653
638
|
};
|
|
654
639
|
output.content.push(block);
|
|
640
|
+
unfinishedToolCalls.add(block);
|
|
655
641
|
const slot = {
|
|
656
642
|
type: "toolCall",
|
|
657
643
|
block,
|
|
658
644
|
contentIndex: output.content.length - 1,
|
|
645
|
+
input: customInput(inputProperty, input),
|
|
659
646
|
};
|
|
660
647
|
outputSlots.set(outputIndex, slot);
|
|
661
648
|
stream.push({ type: "toolcall_start", contentIndex: slot.contentIndex, partial: output });
|
|
@@ -804,36 +791,31 @@ export async function processResponsesStream(openaiStream, output, stream, model
|
|
|
804
791
|
}
|
|
805
792
|
else if (event.type === "response.function_call_arguments.delta") {
|
|
806
793
|
const slot = getSlot(event.output_index, "toolCall");
|
|
807
|
-
if (
|
|
794
|
+
if (slot?.input.kind !== "json")
|
|
808
795
|
continue;
|
|
809
|
-
slot.block.
|
|
810
|
-
slot.block.arguments = parseStreamingJson(slot.block.partialJson);
|
|
796
|
+
slot.block.arguments = slot.input.arguments.append(event.delta);
|
|
811
797
|
pushToolCallDelta(slot, event.delta);
|
|
812
798
|
}
|
|
813
799
|
else if (event.type === "response.function_call_arguments.done") {
|
|
814
800
|
const slot = getSlot(event.output_index, "toolCall");
|
|
815
|
-
if (
|
|
801
|
+
if (slot?.input.kind !== "json")
|
|
816
802
|
continue;
|
|
817
|
-
const
|
|
818
|
-
slot.block.
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
const delta = event.arguments.slice(previousPartialJson.length);
|
|
822
|
-
if (delta.length > 0)
|
|
823
|
-
pushToolCallDelta(slot, delta);
|
|
824
|
-
}
|
|
803
|
+
const replaced = slot.input.arguments.replace(event.arguments);
|
|
804
|
+
slot.block.arguments = replaced.arguments;
|
|
805
|
+
if (replaced.delta)
|
|
806
|
+
pushToolCallDelta(slot, replaced.delta);
|
|
825
807
|
}
|
|
826
808
|
else if (event.type === "response.custom_tool_call_input.delta") {
|
|
827
809
|
const slot = getSlot(event.output_index, "toolCall");
|
|
828
|
-
if (
|
|
810
|
+
if (slot?.input.kind !== "custom")
|
|
829
811
|
continue;
|
|
830
|
-
pushToolCallDelta(slot,
|
|
812
|
+
pushToolCallDelta(slot, appendCustomInput(slot.block, slot.input, event.delta));
|
|
831
813
|
}
|
|
832
814
|
else if (event.type === "response.custom_tool_call_input.done") {
|
|
833
815
|
const slot = getSlot(event.output_index, "toolCall");
|
|
834
|
-
if (
|
|
816
|
+
if (slot?.input.kind !== "custom")
|
|
835
817
|
continue;
|
|
836
|
-
pushToolCallDelta(slot,
|
|
818
|
+
pushToolCallDelta(slot, closeCustomInput(slot.block, slot.input, event.input));
|
|
837
819
|
}
|
|
838
820
|
else if (event.type === "response.output_item.done") {
|
|
839
821
|
const item = event.item;
|
|
@@ -866,15 +848,13 @@ export async function processResponsesStream(openaiStream, output, stream, model
|
|
|
866
848
|
});
|
|
867
849
|
outputSlots.delete(event.output_index);
|
|
868
850
|
}
|
|
869
|
-
else if (item.type === "function_call" &&
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
Object.assign(slot.block,
|
|
851
|
+
else if (item.type === "function_call" && slot?.type === "toolCall" && slot.input.kind === "json") {
|
|
852
|
+
if (item.arguments)
|
|
853
|
+
slot.input.arguments.replace(item.arguments);
|
|
854
|
+
Object.assign(slot.block, slot.input.arguments.finish());
|
|
873
855
|
if (item.namespace !== undefined)
|
|
874
856
|
slot.block.namespace = item.namespace;
|
|
875
|
-
|
|
876
|
-
// carries parsed arguments.
|
|
877
|
-
delete slot.block.partialJson;
|
|
857
|
+
unfinishedToolCalls.delete(slot.block);
|
|
878
858
|
stream.push({
|
|
879
859
|
type: "toolcall_end",
|
|
880
860
|
contentIndex: slot.contentIndex,
|
|
@@ -883,11 +863,11 @@ export async function processResponsesStream(openaiStream, output, stream, model
|
|
|
883
863
|
});
|
|
884
864
|
outputSlots.delete(event.output_index);
|
|
885
865
|
}
|
|
886
|
-
else if (item.type === "custom_tool_call" && slot?.type === "toolCall" && slot.
|
|
887
|
-
pushToolCallDelta(slot,
|
|
866
|
+
else if (item.type === "custom_tool_call" && slot?.type === "toolCall" && slot.input.kind === "custom") {
|
|
867
|
+
pushToolCallDelta(slot, closeCustomInput(slot.block, slot.input, item.input));
|
|
888
868
|
if (item.namespace !== undefined)
|
|
889
869
|
slot.block.namespace = item.namespace;
|
|
890
|
-
delete
|
|
870
|
+
unfinishedToolCalls.delete(slot.block);
|
|
891
871
|
stream.push({
|
|
892
872
|
type: "toolcall_end",
|
|
893
873
|
contentIndex: slot.contentIndex,
|
|
@@ -921,18 +901,39 @@ export async function processResponsesStream(openaiStream, output, stream, model
|
|
|
921
901
|
}
|
|
922
902
|
// The agent runs every tool call in the final message. Refuse to hand over calls whose
|
|
923
903
|
// output_item.done never arrived: their arguments may be cut off or mixed up, e.g. when a
|
|
924
|
-
// non-compliant server omits output_index.
|
|
904
|
+
// non-compliant server omits output_index.
|
|
925
905
|
if (output.stopReason === "toolUse") {
|
|
926
|
-
for (const
|
|
927
|
-
|
|
928
|
-
continue;
|
|
929
|
-
const toolCall = block;
|
|
930
|
-
if (toolCall.partialJson !== undefined || toolCall.customInput !== undefined) {
|
|
931
|
-
throw new Error(`OpenAI Responses stream completed with an unfinished tool call: ${toolCall.name} (${toolCall.id})`);
|
|
932
|
-
}
|
|
906
|
+
for (const toolCall of unfinishedToolCalls) {
|
|
907
|
+
throw new Error(`OpenAI Responses stream completed with an unfinished tool call: ${toolCall.name} (${toolCall.id})`);
|
|
933
908
|
}
|
|
934
909
|
}
|
|
935
910
|
}
|
|
911
|
+
/** Stream state of a custom tool call that starts with `initialInput`. */
|
|
912
|
+
function customInput(property, initialInput) {
|
|
913
|
+
const buffer = { input: "", started: false, closed: false };
|
|
914
|
+
return {
|
|
915
|
+
kind: "custom",
|
|
916
|
+
property,
|
|
917
|
+
buffer,
|
|
918
|
+
unsent: appendGrammarToolInputJsonDelta(buffer, property, initialInput) ?? "",
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
/** Append to a streaming custom tool input; returns the matching piece of its JSON arguments text. */
|
|
922
|
+
function appendCustomInput(block, input, delta) {
|
|
923
|
+
return sendCustomInput(block, input, appendGrammarToolInputJsonDelta(input.buffer, input.property, delta));
|
|
924
|
+
}
|
|
925
|
+
/** Close a custom tool input with the provider's complete input, if it sent one. */
|
|
926
|
+
function closeCustomInput(block, input, finalInput) {
|
|
927
|
+
return sendCustomInput(block, input, closeGrammarToolInputJson(input.buffer, input.property, finalInput));
|
|
928
|
+
}
|
|
929
|
+
function sendCustomInput(block, input, jsonDelta) {
|
|
930
|
+
block.arguments = { [input.property]: input.buffer.input };
|
|
931
|
+
if (input.unsent === "")
|
|
932
|
+
return jsonDelta;
|
|
933
|
+
const sent = input.unsent + (jsonDelta ?? "");
|
|
934
|
+
input.unsent = "";
|
|
935
|
+
return sent;
|
|
936
|
+
}
|
|
936
937
|
function mapStopReason(status, incompleteReason) {
|
|
937
938
|
if (!status)
|
|
938
939
|
return { stopReason: "stop" };
|