


















@@ -1,5 +1,5 @@
11import type { StreamFn } from "@mariozechner/pi-agent-core";
2-import { streamSimple } from "@mariozechner/pi-ai";
2+import { getApiProvider, streamSimple } from "@mariozechner/pi-ai";
33import { createAnthropicVertexStreamFnForModel } from "../anthropic-vertex-stream.js";
44import { createOpenAIWebSocketStreamFn } from "../openai-ws-stream.js";
55import { getModelProviderRequestTransport } from "../provider-request-config.js";
@@ -25,6 +25,21 @@ export function resetEmbeddedAgentBaseStreamFnCacheForTest(): void {
2525embeddedAgentBaseStreamFnCache = new WeakMap<object, StreamFn | undefined>();
2626}
272728+function isDefaultPiStreamFnForModel(
29+model: EmbeddedRunAttemptParams["model"],
30+streamFn: StreamFn | undefined,
31+): boolean {
32+if (!streamFn || streamFn === streamSimple) {
33+return true;
34+}
35+const api = typeof model.api === "string" ? model.api.trim() : "";
36+if (!api) {
37+return false;
38+}
39+const provider = getApiProvider(api as never);
40+return streamFn === provider?.streamSimple || streamFn === provider?.stream;
41+}
42+2843export function describeEmbeddedAgentStreamStrategy(params: {
2944currentStreamFn: StreamFn | undefined;
3045providerStreamFn?: StreamFn;
@@ -41,7 +56,7 @@ export function describeEmbeddedAgentStreamStrategy(params: {
4156if (params.model.provider === "anthropic-vertex") {
4257return "anthropic-vertex";
4358}
44-if (params.currentStreamFn === undefined || params.currentStreamFn === streamSimple) {
59+if (isDefaultPiStreamFnForModel(params.model, params.currentStreamFn)) {
4560return createBoundaryAwareStreamFnForModel(params.model)
4661 ? `boundary-aware:${params.model.api}`
4762 : "stream-simple";
@@ -104,7 +119,7 @@ export function resolveEmbeddedAgentStreamFn(params: {
104119return createAnthropicVertexStreamFnForModel(params.model);
105120}
106121107-if (params.currentStreamFn === undefined || params.currentStreamFn === streamSimple) {
122+if (isDefaultPiStreamFnForModel(params.model, params.currentStreamFn)) {
108123const boundaryAwareStreamFn = createBoundaryAwareStreamFnForModel(params.model);
109124if (boundaryAwareStreamFn) {
110125// Boundary-aware transports read credentials from options.apiKey just
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。