mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
This change makes system prompt text and tool changes part of the transcript rather than silently rewriting its starting conditions. This lets Pi record when instructions changed or tools became available, restore that state after resuming or navigating branches, and preserve cached prompt prefixes where the upstream supports it.
66 lines
2 KiB
TypeScript
66 lines
2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { cloudflareStreams } from "../src/providers/cloudflare-stream.ts";
|
|
import type { Api, Model } from "../src/types.ts";
|
|
import { AssistantMessageEventStream } from "../src/utils/event-stream.ts";
|
|
import { normalizeContext } from "../src/utils/transcript.ts";
|
|
|
|
const model: Model<Api> = {
|
|
id: "model",
|
|
name: "model",
|
|
api: "openai-completions",
|
|
provider: "cloudflare-ai-gateway",
|
|
baseUrl: "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/openai",
|
|
reasoning: false,
|
|
input: ["text"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 1000,
|
|
maxTokens: 100,
|
|
};
|
|
|
|
const context = normalizeContext({ messages: [] });
|
|
|
|
describe("Cloudflare provider streams", () => {
|
|
it("materializes the model endpoint before dispatch", () => {
|
|
const captured: string[] = [];
|
|
const streams = cloudflareStreams({
|
|
stream: (requestModel) => {
|
|
captured.push(requestModel.baseUrl);
|
|
return new AssistantMessageEventStream();
|
|
},
|
|
streamSimple: (requestModel) => {
|
|
captured.push(requestModel.baseUrl);
|
|
return new AssistantMessageEventStream();
|
|
},
|
|
});
|
|
const env = {
|
|
CLOUDFLARE_ACCOUNT_ID: "account",
|
|
CLOUDFLARE_GATEWAY_ID: "gateway",
|
|
};
|
|
|
|
streams.stream(model, context, { env });
|
|
streams.streamSimple(model, context, { env });
|
|
|
|
expect(captured).toEqual([
|
|
"https://gateway.ai.cloudflare.com/v1/account/gateway/openai",
|
|
"https://gateway.ai.cloudflare.com/v1/account/gateway/openai",
|
|
]);
|
|
});
|
|
|
|
it("keeps placeholders when the provider env does not resolve them", () => {
|
|
let captured: string | undefined;
|
|
const streams = cloudflareStreams({
|
|
stream: (requestModel) => {
|
|
captured = requestModel.baseUrl;
|
|
return new AssistantMessageEventStream();
|
|
},
|
|
streamSimple: (requestModel) => {
|
|
captured = requestModel.baseUrl;
|
|
return new AssistantMessageEventStream();
|
|
},
|
|
});
|
|
|
|
streams.streamSimple(model, context, {});
|
|
|
|
expect(captured).toBe(model.baseUrl);
|
|
});
|
|
});
|