fb3f1df13e
- Remove all learnship references: Decision.learnship_equivalent field,
agent persona prompts, opencode.json permissions, test fixtures
- Migrate verification layers from .planning/ to .ci/: structural
checks .ci/ dir + ROADMAP.md, behavioral checks ROADMAP.md
- Fix ollama-local: remove sync require+curl blocking, use async
fetchAvailableModels() in callModel
- Fix opencode.json: use __OPENCODE_DIR__ template tokens, remove
legacy learnship permission entries
- Remove duplicate install script from package.json (keep postinstall)
- Fix quality any-regex false positives (target type annotations only)
- Add backends test coverage: backends.test.ts, tool-registry.test.ts
- Version bump 0.3.0 → 0.4.0
- Artifacts module: rename .planning→.ci internal paths
- Remove dead TODO_PATTERN/FIXME_PATTERN constants
---ci---
phase: 3
milestone: v0.4
status: complete
requirements:
covered: [REQ-09, REQ-10, REQ-11, REQ-13, REQ-14, REQ-17]
partial: []
decisions:
- id: D-001
decision: purge all learnship references from codebase
rationale: project is CI-only, learnship is no longer a dependency
confidence: 0.99
category: scope
alternatives: [keep for historical reference]
- id: D-002
decision: migrate verification from .planning/ to .ci/ paths
rationale: .planning/ is removed schema, all current state lives in .ci/
confidence: 0.95
category: architecture
alternatives: [keep dual-path support]
- id: D-003
decision: use __OPENCODE_DIR__ template tokens in opencode.json
rationale: hardcoded ~ paths fail in containers and non-standard homes
confidence: 0.90
category: implementation_approach
alternatives: [keep tilde expansion]
---/ci---
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import { OllamaBaseBackend, OllamaMessage, OllamaChatResponse } from "./ollama-base.js";
|
|
import { OllamaLocalConfig } from "./types.js";
|
|
import { ToolRegistry } from "./tool-registry.js";
|
|
|
|
export class OllamaLocalBackend extends OllamaBaseBackend {
|
|
readonly name = "ollama-local";
|
|
|
|
private localConfig: OllamaLocalConfig;
|
|
|
|
constructor(config?: OllamaLocalConfig) {
|
|
super(config);
|
|
this.localConfig = config || { base_url: "http://localhost:11434", model_profile: "balanced" };
|
|
}
|
|
|
|
async isAvailable(): Promise<boolean> {
|
|
try {
|
|
const response = await fetch(`${this.localConfig.base_url}/api/tags`, {
|
|
signal: AbortSignal.timeout(5000),
|
|
});
|
|
return response.ok;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
protected resolveModel(): string {
|
|
if (this.localConfig.model) return this.localConfig.model;
|
|
return this.modelProfileToModel(this.localConfig.model_profile, []);
|
|
}
|
|
|
|
protected async callModel(
|
|
messages: OllamaMessage[],
|
|
model: string,
|
|
toolRegistry: ToolRegistry
|
|
): Promise<OllamaChatResponse> {
|
|
let resolvedModel = model;
|
|
if (!this.localConfig.model) {
|
|
const models = await this.fetchAvailableModels();
|
|
resolvedModel = this.modelProfileToModel(this.localConfig.model_profile, models);
|
|
}
|
|
const url = `${this.localConfig.base_url}/v1/chat/completions`;
|
|
|
|
const body: Record<string, unknown> = {
|
|
model: resolvedModel,
|
|
messages: messages.map((m) => {
|
|
const msg: Record<string, unknown> = { role: m.role, content: m.content };
|
|
if (m.name) msg.name = m.name;
|
|
if (m.tool_calls) msg.tool_calls = m.tool_calls;
|
|
return msg;
|
|
}),
|
|
tools: toolRegistry.getOpenAIToolSchema(),
|
|
stream: false,
|
|
};
|
|
|
|
const timeout = this.localConfig.timeout_ms || 10000;
|
|
|
|
const response = await fetch(url, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(body),
|
|
signal: AbortSignal.timeout(timeout),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorText = await response.text().catch(() => "unknown error");
|
|
throw new Error(`Ollama local API error (${response.status}): ${errorText}`);
|
|
}
|
|
|
|
return (await response.json()) as OllamaChatResponse;
|
|
}
|
|
|
|
} |