Add native LLM core foundation (#24712)

This commit is contained in:
Kit Langton
2026-05-08 16:56:20 -04:00
committed by GitHub
parent dc7d665e94
commit 5bb7b23440
144 changed files with 17052 additions and 2 deletions
+58
View File
@@ -0,0 +1,58 @@
import { describe, expect, test } from "bun:test"
import { Schema } from "effect"
import {
ContentPart,
LLMEvent,
LLMRequest,
ModelID,
ModelLimits,
ModelRef,
ProviderID,
} from "../src/schema"
const model = new ModelRef({
id: ModelID.make("fake-model"),
provider: ProviderID.make("fake-provider"),
route: "openai-chat",
baseURL: "https://fake.local",
limits: new ModelLimits({}),
})
describe("llm schema", () => {
test("decodes a minimal request", () => {
const input: unknown = {
id: "req_1",
model,
system: [{ type: "text", text: "You are terse." }],
messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
tools: [],
generation: {},
}
const decoded = Schema.decodeUnknownSync(LLMRequest)(input)
expect(decoded.id).toBe("req_1")
expect(decoded.messages[0]?.content[0]?.type).toBe("text")
})
test("accepts custom route ids", () => {
const decoded = Schema.decodeUnknownSync(LLMRequest)({
model: { ...model, route: "custom-route" },
system: [],
messages: [],
tools: [],
generation: {},
})
expect(decoded.model.route).toBe("custom-route")
})
test("rejects invalid event type", () => {
expect(() => Schema.decodeUnknownSync(LLMEvent)({ type: "bogus" })).toThrow()
})
test("content part tagged union exposes guards", () => {
expect(ContentPart.guards.text({ type: "text", text: "hi" })).toBe(true)
expect(ContentPart.guards.media({ type: "text", text: "hi" })).toBe(false)
})
})