Initial Coworker app scaffold
Some checks failed
Codex Template Compliance / compliance (push) Successful in 7s
Release Dry Run / release-dry-run (push) Failing after 44s
Build / build (push) Failing after 45s

This commit is contained in:
2026-06-19 01:07:16 +02:00
commit 2ec18964b7
46 changed files with 2582 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
import { ModelProvider, ProviderProbeResult } from "./types";
import { createId, nowIso } from "./ids";
export function createProvider(
kind: ModelProvider["kind"],
name: string,
baseUrl: string
): ModelProvider {
const createdAt = nowIso();
return {
id: createId("provider"),
name: name.trim(),
kind,
baseUrl: normalizeBaseUrl(baseUrl),
enabled: true,
supportsTools: kind !== "ollama",
contextWindow: 8192,
defaults: {},
createdAt,
updatedAt: createdAt
};
}
export function normalizeBaseUrl(baseUrl: string): string {
return baseUrl.trim().replace(/\/+$/, "");
}
export async function probeOpenAiCompatibleProvider(
provider: ModelProvider,
fetchImpl: typeof fetch = fetch
): Promise<ProviderProbeResult> {
const url = `${normalizeBaseUrl(provider.baseUrl)}/models`;
try {
const response = await fetchImpl(url, {
headers: provider.apiKey ? { Authorization: `Bearer ${provider.apiKey}` } : undefined
});
if (!response.ok) {
return {
ok: false,
providerId: provider.id,
models: [],
message: `Provider returned HTTP ${response.status}`
};
}
const body = await response.json() as { data?: Array<{ id?: string }>; models?: string[] };
const models = Array.isArray(body.data)
? body.data.map((model) => model.id).filter(Boolean) as string[]
: Array.isArray(body.models)
? body.models
: [];
return {
ok: models.length > 0,
providerId: provider.id,
models,
message: models.length > 0 ? "Provider is reachable." : "Provider responded without model ids."
};
} catch (error) {
return {
ok: false,
providerId: provider.id,
models: [],
message: error instanceof Error ? error.message : "Provider probe failed."
};
}
}