* refactor(shared): unify binary downloader and session path storage - Create binary-downloader.ts for common download/extract logic - Create session-injected-paths.ts for unified path tracking - Refactor comment-checker, ast-grep, grep downloaders to use shared util - Consolidate directory injector types into shared module * feat(shared): implement unified model resolution pipeline - Create ModelResolutionPipeline for centralized model selection - Refactor model-resolver to use pipeline - Update delegate-task and config-handler to use unified logic - Ensure consistent model resolution across all agent types * refactor(agents): simplify agent utils and metadata management - Extract helper functions for config merging and env context - Register prompt metadata for all agents - Simplify agent variant detection logic * cleanup: inline utilities and remove unused exports - Remove case-insensitive.ts (inline with native JS) - Simplify opencode-version helpers - Remove unused getModelLimit, createCompactionContextInjector exports - Inline transcript entry creation in claude-code-hooks - Update tests accordingly --------- Co-authored-by: justsisyphus <justsisyphus@users.noreply.github.com>
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { isPlainObject } from "./deep-merge"
|
|
|
|
export function camelToSnake(str: string): string {
|
|
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)
|
|
}
|
|
|
|
export function snakeToCamel(str: string): string {
|
|
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())
|
|
}
|
|
|
|
export function transformObjectKeys(
|
|
obj: Record<string, unknown>,
|
|
transformer: (key: string) => string,
|
|
deep: boolean = true
|
|
): Record<string, unknown> {
|
|
const result: Record<string, unknown> = {}
|
|
for (const [key, value] of Object.entries(obj)) {
|
|
const transformedKey = transformer(key)
|
|
if (deep && isPlainObject(value)) {
|
|
result[transformedKey] = transformObjectKeys(value, transformer, true)
|
|
} else if (deep && Array.isArray(value)) {
|
|
result[transformedKey] = value.map((item) =>
|
|
isPlainObject(item) ? transformObjectKeys(item, transformer, true) : item
|
|
)
|
|
} else {
|
|
result[transformedKey] = value
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
export function objectToSnakeCase(
|
|
obj: Record<string, unknown>,
|
|
deep: boolean = true
|
|
): Record<string, unknown> {
|
|
return transformObjectKeys(obj, camelToSnake, deep)
|
|
}
|
|
|
|
export function objectToCamelCase(
|
|
obj: Record<string, unknown>,
|
|
deep: boolean = true
|
|
): Record<string, unknown> {
|
|
return transformObjectKeys(obj, snakeToCamel, deep)
|
|
}
|