ba93da9a93
Stream implementations move from src/providers/ to src/api/, renamed by API id (anthropic.ts -> anthropic-messages.ts, google.ts -> google-generative-ai.ts, mistral.ts -> mistral-conversations.ts, amazon-bedrock.ts -> bedrock-converse-stream.ts). Every module now exports exactly stream/streamSimple; shared helpers move alongside. New ProviderStreams dispatch contract in types.ts, lazyApi() wrapper in api/lazy.ts, and one .lazy.ts wrapper per API. Bedrock's wrapper keeps the node-only variable-specifier import and setBedrockProviderModule() (now taking ProviderStreams). providers/register-builtins.ts deleted; interim until the compat entrypoint lands, builtin api-registry registration lives in stream.ts and lazy wrappers are exported from the root barrel. Old per-API lazy exports (streamAnthropic, ...) are gone; package.json subpaths retarget to dist/api/.
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import type { ResponseOutputMessage } from "openai/resources/responses/responses.js";
|
|
import { describe, expect, it } from "vitest";
|
|
import { convertResponsesMessages } from "../src/api/openai-responses-shared.ts";
|
|
import { getModel } from "../src/models.ts";
|
|
import type { AssistantMessage, Context, Usage } from "../src/types.ts";
|
|
|
|
const usage: Usage = {
|
|
input: 0,
|
|
output: 0,
|
|
cacheRead: 0,
|
|
cacheWrite: 0,
|
|
totalTokens: 0,
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
};
|
|
|
|
describe("OpenAI Responses message ID conversion", () => {
|
|
it("generates unique fallback message IDs for multiple text blocks in one assistant turn", () => {
|
|
const model = getModel("openai-codex", "gpt-5.5");
|
|
const assistant: AssistantMessage = {
|
|
role: "assistant",
|
|
content: [
|
|
{ type: "thinking", thinking: "private reasoning" },
|
|
{ type: "text", text: "visible answer" },
|
|
],
|
|
api: "anthropic-messages",
|
|
provider: "anthropic",
|
|
model: "claude-opus-4-8",
|
|
usage,
|
|
stopReason: "stop",
|
|
timestamp: Date.now() - 1000,
|
|
};
|
|
const context: Context = {
|
|
systemPrompt: "You are concise.",
|
|
messages: [{ role: "user", content: "hello", timestamp: Date.now() - 2000 }, assistant],
|
|
};
|
|
|
|
const input = convertResponsesMessages(model, context, new Set(["openai", "openai-codex", "opencode"]));
|
|
const messageIds = input
|
|
.filter(
|
|
(item): item is ResponseOutputMessage =>
|
|
item.type === "message" && "id" in item && typeof item.id === "string",
|
|
)
|
|
.map((item) => item.id);
|
|
|
|
expect(messageIds).toEqual(["msg_pi_1", "msg_pi_1_1"]);
|
|
expect(new Set(messageIds).size).toBe(messageIds.length);
|
|
});
|
|
});
|