feat: add OMP (Oh My Pi) provider compatibility
Support OMP as a host alongside pi: - Convert OMP's array-format system prompts to string via systemPromptToText - Guard against OMP passing the literal env-var name as the API key value - Add ~/.omp/agent/auth.json to default auth path lookup - Fix --list-models output to check both stdout and stderr - Add OMP compatibility smoke test with isolated temp HOME and mock server - Deduplicate usage section in README, add OMP install and usage docs
This commit is contained in:
+21
-1
@@ -39,7 +39,7 @@ export function numberValue(value: unknown): number | undefined {
|
||||
}
|
||||
|
||||
function defaultAuthPaths(home: string): string[] {
|
||||
return [join(home, ".commandcode", "auth.json"), join(home, ".pi", "agent", "auth.json")]
|
||||
return [join(home, ".commandcode", "auth.json"), join(home, ".omp", "agent", "auth.json"), join(home, ".pi", "agent", "auth.json")]
|
||||
}
|
||||
|
||||
function apiKeyFromCredentialRecord(value: unknown): string | undefined {
|
||||
@@ -284,3 +284,23 @@ export function mapFinishReason(reason: unknown): StopReason {
|
||||
}
|
||||
return "stop"
|
||||
}
|
||||
|
||||
function promptPartToText(value: unknown, depth = 0): string {
|
||||
if (depth > 10) return ""
|
||||
if (typeof value === "string") return value
|
||||
if (Array.isArray(value)) return value.map((v) => promptPartToText(v, depth + 1)).filter(Boolean).join("\n")
|
||||
if (!isRecord(value)) return ""
|
||||
const text = stringValue(value.text)
|
||||
if (text) return text
|
||||
const content = promptPartToText(value.content, depth + 1)
|
||||
if (content) return content
|
||||
return ""
|
||||
}
|
||||
|
||||
export function systemPromptToText(value: unknown): string {
|
||||
if (value === undefined || value === null) return ""
|
||||
if (typeof value === "string") return value
|
||||
if (Array.isArray(value)) return value.map((v) => promptPartToText(v, 0)).filter(Boolean).join("\n\n")
|
||||
return promptPartToText(value, 0)
|
||||
}
|
||||
|
||||
|
||||
+10
-2
@@ -18,6 +18,7 @@ import {
|
||||
recordOrEmpty,
|
||||
stringValue,
|
||||
toolsToJson,
|
||||
systemPromptToText
|
||||
} from "./converters.ts"
|
||||
import type {
|
||||
AssistantMessageEventStreamLike,
|
||||
@@ -131,8 +132,15 @@ export function createStreamCommandCode(deps: CoreDependencies) {
|
||||
const stream = deps.createStream()
|
||||
|
||||
async function run() {
|
||||
// OMP may pass the env-var name "COMMANDCODE_API_KEY" as the apiKey
|
||||
// value instead of resolving it. Filter out this specific string.
|
||||
const hostKey =
|
||||
options?.apiKey && options.apiKey !== "COMMANDCODE_API_KEY"
|
||||
? options.apiKey
|
||||
: undefined
|
||||
|
||||
const apiKey =
|
||||
options?.apiKey ??
|
||||
hostKey ??
|
||||
getApiKey({
|
||||
env: deps.env,
|
||||
authPaths: deps.authPaths,
|
||||
@@ -355,7 +363,7 @@ export function createStreamCommandCode(deps: CoreDependencies) {
|
||||
model: model.id,
|
||||
messages: messagesToCC(context.messages),
|
||||
tools: toolsToJson(context.tools),
|
||||
system: context.systemPrompt ?? "",
|
||||
system: systemPromptToText(context.systemPrompt),
|
||||
max_tokens: generateMaxTokens(model, options),
|
||||
temperature: 0.3,
|
||||
stream: true,
|
||||
|
||||
Reference in New Issue
Block a user