Files
openclaw/extensions/together/together.live.test.ts
T
Peter Steinberger b080dd1e76 refactor: consolidate coercion contracts (#122458)
* refactor: consolidate coercion contracts

Centralize exact string, record, numeric, date, Boolean, argument, and structured-error coercions while preserving call-site semantics.

Migrate canonical-name collisions and deprecated internal SDK bypasses, deleting 55 net production/tooling lines. Expand declaration ownership enforcement to 101 allowed helpers and add a narrow export-completeness audit.

* fix: preserve standalone script coercions

Keep copied Control UI tooling self-contained and retain the trusted release harness module-relative source seam when the harness runs against an old target cwd.
2026-08-11 23:26:37 -07:00

81 lines
2.4 KiB
TypeScript

// Together tests cover together plugin behavior.
import { completeSimple, type Model } from "openclaw/plugin-sdk/llm";
import { isTruthyEnvValue } from "openclaw/plugin-sdk/runtime-env";
import { describe, expect, it } from "vitest";
import { TOGETHER_BASE_URL, TOGETHER_MODEL_CATALOG } from "./models.js";
const TOGETHER_KEY = process.env.TOGETHER_API_KEY ?? "";
const LIVE = ["LIVE", "OPENCLAW_LIVE_TEST", "TOGETHER_LIVE_TEST"].some((name) =>
isTruthyEnvValue(process.env[name]),
);
const TOGETHER_LIVE_TIMEOUT_MS = 45_000;
const describeLive = LIVE && TOGETHER_KEY ? describe : describe.skip;
function normalizeOpenAiCompletionInput(
input: (typeof TOGETHER_MODEL_CATALOG)[number]["input"],
): Array<"text" | "image"> {
const supported = input.filter((value): value is "text" | "image" => {
return value === "text" || value === "image";
});
return supported.length > 0 ? supported : ["text"];
}
function buildLiveModel(model: (typeof TOGETHER_MODEL_CATALOG)[number]) {
return {
...model,
api: "openai-completions",
provider: "together",
baseUrl: TOGETHER_BASE_URL,
input: normalizeOpenAiCompletionInput(model.input),
cost: { ...model.cost },
} satisfies Model<"openai-completions">;
}
function extractAssistantText(
content: Array<{
type?: string;
text?: string;
}>,
) {
return content
.filter((block) => block.type === "text")
.map((block) => block.text?.trim() ?? "")
.filter(Boolean)
.join(" ");
}
describeLive("together live catalog", () => {
for (const catalogModel of TOGETHER_MODEL_CATALOG) {
it(
`${catalogModel.id} returns assistant text`,
async () => {
const model = buildLiveModel(catalogModel);
const context = {
messages: [
{
role: "user" as const,
content: "Reply with the word ok.",
timestamp: Date.now(),
},
],
};
let response = await completeSimple(model, context, {
apiKey: TOGETHER_KEY,
maxTokens: 128,
});
let text = extractAssistantText(response.content);
if (text.length === 0 && response.stopReason === "length") {
response = await completeSimple(model, context, {
apiKey: TOGETHER_KEY,
maxTokens: 512,
});
text = extractAssistantText(response.content);
}
expect(text.length).toBeGreaterThan(0);
},
TOGETHER_LIVE_TIMEOUT_MS,
);
}
});