refactor: remove dead code

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim 2026-02-06 02:51:53 +09:00
parent f468effd47
commit 2224183b5c
4 changed files with 0 additions and 246 deletions

View File

@ -9,22 +9,3 @@ export function createModelCacheState(): ModelCacheState {
anthropicContext1MEnabled: false,
};
}
export function getModelLimit(
state: ModelCacheState,
providerID: string,
modelID: string
): number | undefined {
const key = `${providerID}/${modelID}`;
const cached = state.modelContextLimitsCache.get(key);
if (cached) return cached;
if (
providerID === "anthropic" &&
state.anthropicContext1MEnabled &&
modelID.includes("sonnet")
) {
return 1_000_000;
}
return undefined;
}

View File

@ -1,198 +0,0 @@
/**
* Ollama NDJSON Parser
*
* Parses newline-delimited JSON (NDJSON) responses from Ollama API.
*
* @module ollama-ndjson-parser
* @see https://github.com/code-yeongyu/oh-my-opencode/issues/1124
* @see https://github.com/ollama/ollama/blob/main/docs/api.md
*/
import { log } from "./logger"
/**
* Ollama message structure
*/
export interface OllamaMessage {
tool_calls?: Array<{
function: {
name: string
arguments: Record<string, unknown>
}
}>
content?: string
}
/**
* Ollama NDJSON line structure
*/
export interface OllamaNDJSONLine {
message?: OllamaMessage
done: boolean
total_duration?: number
load_duration?: number
prompt_eval_count?: number
prompt_eval_duration?: number
eval_count?: number
eval_duration?: number
}
/**
* Merged Ollama response
*/
export interface OllamaMergedResponse {
message: OllamaMessage
done: boolean
stats?: {
total_duration?: number
load_duration?: number
prompt_eval_count?: number
prompt_eval_duration?: number
eval_count?: number
eval_duration?: number
}
}
/**
* Parse Ollama streaming NDJSON response into a single merged object.
*
* Ollama returns streaming responses as newline-delimited JSON (NDJSON):
* ```
* {"message":{"tool_calls":[...]}, "done":false}
* {"message":{"content":""}, "done":true}
* ```
*
* This function:
* 1. Splits the response by newlines
* 2. Parses each line as JSON
* 3. Merges tool_calls and content from all lines
* 4. Returns a single merged response
*
* @param response - Raw NDJSON response string from Ollama API
* @returns Merged response with all tool_calls and content combined
* @throws {Error} If no valid JSON lines are found
*
* @example
* ```typescript
* const ndjsonResponse = `
* {"message":{"tool_calls":[{"function":{"name":"read","arguments":{"filePath":"README.md"}}}]}, "done":false}
* {"message":{"content":""}, "done":true}
* `;
*
* const merged = parseOllamaStreamResponse(ndjsonResponse);
* // Result:
* // {
* // message: {
* // tool_calls: [{ function: { name: "read", arguments: { filePath: "README.md" } } }],
* // content: ""
* // },
* // done: true
* // }
* ```
*/
export function parseOllamaStreamResponse(response: string): OllamaMergedResponse {
const lines = response.split("\n").filter((line) => line.trim())
if (lines.length === 0) {
throw new Error("No valid NDJSON lines found in response")
}
const mergedMessage: OllamaMessage = {
tool_calls: [],
content: "",
}
let done = false
let stats: OllamaMergedResponse["stats"] = {}
for (const line of lines) {
try {
const json = JSON.parse(line) as OllamaNDJSONLine
// Merge tool_calls
if (json.message?.tool_calls) {
mergedMessage.tool_calls = [
...(mergedMessage.tool_calls || []),
...json.message.tool_calls,
]
}
// Merge content (concatenate)
if (json.message?.content) {
mergedMessage.content = (mergedMessage.content || "") + json.message.content
}
// Update done flag (final line has done: true)
if (json.done) {
done = true
// Capture stats from final line
stats = {
total_duration: json.total_duration,
load_duration: json.load_duration,
prompt_eval_count: json.prompt_eval_count,
prompt_eval_duration: json.prompt_eval_duration,
eval_count: json.eval_count,
eval_duration: json.eval_duration,
}
}
} catch (error) {
log(`[ollama-ndjson-parser] Skipping malformed NDJSON line: ${line}`, { error })
continue
}
}
return {
message: mergedMessage,
done,
...(Object.keys(stats).length > 0 ? { stats } : {}),
}
}
/**
* Check if a response string is NDJSON format.
*
* NDJSON is identified by:
* - Multiple lines
* - Each line is valid JSON
* - At least one line has "done" field
*
* @param response - Response string to check
* @returns true if response appears to be NDJSON
*
* @example
* ```typescript
* const ndjson = '{"done":false}\n{"done":true}';
* const singleJson = '{"done":true}';
*
* isNDJSONResponse(ndjson); // true
* isNDJSONResponse(singleJson); // false
* ```
*/
export function isNDJSONResponse(response: string): boolean {
const lines = response.split("\n").filter((line) => line.trim())
// Single line is not NDJSON
if (lines.length <= 1) {
return false
}
let hasValidJSON = false
let hasDoneField = false
for (const line of lines) {
try {
const json = JSON.parse(line) as Record<string, unknown>
hasValidJSON = true
if ("done" in json) {
hasDoneField = true
}
} catch {
// If any line fails to parse, it's not NDJSON
return false
}
}
return hasValidJSON && hasDoneField
}

View File

@ -1,5 +0,0 @@
declare global {
type RequestInfo = string | URL
}
export {}

View File

@ -1,24 +0,0 @@
declare global {
const describe: (name: string, fn: () => void) => void
const test: (name: string, fn: () => void | Promise<void>) => void
const beforeEach: (fn: () => void | Promise<void>) => void
const afterEach: (fn: () => void | Promise<void>) => void
const expect: (value: unknown) => {
toBe: (expected: unknown) => void
toContain: (expected: unknown) => void
not: {
toBe: (expected: unknown) => void
toContain: (expected: unknown) => void
}
}
const spyOn: <T extends object, K extends keyof T>(
target: T,
key: K
) => {
mockReturnValue: (value: T[K]) => void
mockImplementation: (impl: T[K]) => void
mockRestore: () => void
}
}
export {}