Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Code quality

on:
push:
pull_request:

jobs:
quality:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Setup Biome
uses: biomejs/setup-biome@v2
with:
version: latest
- name: Run Biome
run: biome ci .
37 changes: 37 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": false
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
},
"html": {
"experimentalFullSupportEnabled": true
},
"assist": {
"enabled": true,
"actions": {
"source": {
"organizeImports": "on"
}
}
}
}
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"type": "module",
"private": true,
"workspaces": {
"packages": [
"packages/*"
],
"catalog": {
"typescript": "5.8.2",
"@types/node": "22.13.9",
"@types/bun": "1.3.0",
"zod": "3.24.2",
"ai": "4.3.16",
"@tsconfig/bun": "^1.0.8"
}
},
"scripts": {
"validate": "bun ./packages/core/script/validate.ts"
},
"dependencies": {
"@cloudflare/workers-types": "^4.20250801.0",
"sst": "3.17.5"
}
"type": "module",
"private": true,
"workspaces": {
"packages": [
"packages/*"
],
"catalog": {
"typescript": "5.8.2",
"@types/node": "22.13.9",
"@types/bun": "1.3.0",
"zod": "3.24.2",
"ai": "4.3.16",
"@tsconfig/bun": "^1.0.8"
}
},
"scripts": {
"validate": "bun ./packages/core/script/validate.ts"
},
"dependencies": {
"@cloudflare/workers-types": "^4.20250801.0",
"sst": "3.17.5"
}
}
26 changes: 13 additions & 13 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "models.dev",
"version": "0.0.0",
"$schema": "https://json.schemastore.org/package.json",
"type": "module",
"dependencies": {
"zod": "catalog:"
},
"main": "./src/index.ts",
"devDependencies": {
"@tsconfig/bun": "catalog:",
"@types/bun": "catalog:",
"@types/node": "catalog:"
}
"name": "models.dev",
"version": "0.0.0",
"$schema": "https://json.schemastore.org/package.json",
"type": "module",
"dependencies": {
"zod": "catalog:"
},
"main": "./src/index.ts",
"devDependencies": {
"@tsconfig/bun": "catalog:",
"@types/bun": "catalog:",
"@types/node": "catalog:"
}
}
22 changes: 11 additions & 11 deletions packages/core/script/validate.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env bun

import { generate } from "../src/generate";
import path from "path";
import { ZodError } from "zod";
import { generate } from "../src/generate";

try {
const result = await generate(
path.join(import.meta.dirname, "..", "..", "..", "providers"),
);
console.log(JSON.stringify(result, null, 2));
const result = await generate(
path.join(import.meta.dirname, "..", "..", "..", "providers"),
);
console.log(JSON.stringify(result, null, 2));
} catch (e: any) {
if (e instanceof ZodError) {
console.error("Validation error:", e.errors);
console.error("When parsing:", e.cause);
process.exit(1);
}
throw e;
if (e instanceof ZodError) {
console.error("Validation error:", e.errors);
console.error("When parsing:", e.cause);
process.exit(1);
}
throw e;
}
84 changes: 42 additions & 42 deletions packages/core/src/generate.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import path from "path";

import { Provider, Model } from "./schema.js";
import { Model, Provider } from "./schema.js";

export async function generate(directory: string) {
const result = {} as Record<string, Provider>;
for await (const providerPath of new Bun.Glob("*/provider.toml").scan({
cwd: directory,
absolute: true,
})) {
const providerID = path.basename(path.dirname(providerPath));
const toml = await import(providerPath, {
with: {
type: "toml",
},
}).then((mod) => mod.default);
toml.id = providerID;
toml.models = {};
const provider = Provider.safeParse(toml);
if (!provider.success) {
provider.error.cause = { providerPath, toml };
throw provider.error;
}
const result = {} as Record<string, Provider>;
for await (const providerPath of new Bun.Glob("*/provider.toml").scan({
cwd: directory,
absolute: true,
})) {
const providerID = path.basename(path.dirname(providerPath));
const toml = await import(providerPath, {
with: {
type: "toml",
},
}).then((mod) => mod.default);
toml.id = providerID;
toml.models = {};
const provider = Provider.safeParse(toml);
if (!provider.success) {
provider.error.cause = { providerPath, toml };
throw provider.error;
}

const modelsPath = path.join(directory, providerID, "models");
for await (const modelPath of new Bun.Glob("**/*.toml").scan({
cwd: modelsPath,
absolute: true,
followSymlinks: true,
})) {
const modelID = path.relative(modelsPath, modelPath).slice(0, -5);
const toml = await import(modelPath, {
with: {
type: "toml",
},
}).then((mod) => mod.default);
toml.id = modelID;
const model = Model.safeParse(toml);
if (!model.success) {
model.error.cause = { modelPath, toml };
throw model.error;
}
provider.data.models[modelID] = model.data;
}
result[providerID] = provider.data;
}
const modelsPath = path.join(directory, providerID, "models");
for await (const modelPath of new Bun.Glob("**/*.toml").scan({
cwd: modelsPath,
absolute: true,
followSymlinks: true,
})) {
const modelID = path.relative(modelsPath, modelPath).slice(0, -5);
const toml = await import(modelPath, {
with: {
type: "toml",
},
}).then((mod) => mod.default);
toml.id = modelID;
const model = Model.safeParse(toml);
if (!model.success) {
model.error.cause = { modelPath, toml };
throw model.error;
}
provider.data.models[modelID] = model.data;
}
result[providerID] = provider.data;
}

return result;
return result;
}
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./schema.js";
export * from "./generate.js";
export * from "./schema.js";
Loading