Files
pi_harness/packages/ai/test/openai-responses-message-id.test.ts
T
Mario Zechner 8a0903ebf2 feat(ai): compat entrypoint, core-only root barrel (phase 5)
The root barrel is now core-only and side-effect free: types,
createModels/createProvider, auth substrate, lazyStream/lazyApi, faux,
utils. Generated catalogs, api-registry, env-api-keys, images, global
stream functions, and per-API lazy wrappers leave the root.

New @earendil-works/pi-ai/compat preserves the old surface verbatim as
a strict superset of the root: api-dispatch stream/complete with env
key injection, the builtin registration side effect (skip-if-present so
it cannot clobber earlier overrides), deprecated getModel/getModels/
getProviders aliases of the new getBuiltin* reads in providers/all,
lazy api wrappers + setBedrockProviderModule, and image generation.
Compat dies with the coding-agent ModelManager migration.

Packaging: exports map gains ./compat, ./providers/*, ./api/*;
sideEffects array lists only the effectful modules.

Old-global imports across agent/coding-agent/examples and pi-ai tests
switch to /compat (path-only; compat is a superset). The coding-agent
extension loader resolves the pi-ai ROOT specifier to compat, so
existing user extensions using the old global API keep working at
runtime until compat is removed. vitest configs alias /compat to src;
browser smoke imports old globals from /compat.
2026-06-10 21:17:12 +02:00

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/compat.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);
});
});