Merge remote-tracking branch 'origin/main' into fix/pr-7-review

# Conflicts:
#	index.ts
#	package.json
#	tests/test-pi-local.mjs
This commit is contained in:
Patrick Wozniak
2026-05-28 22:07:51 +02:00
8 changed files with 307 additions and 12 deletions
+32 -1
View File
@@ -39,7 +39,11 @@ 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 +288,30 @@ 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)
}
+9 -3
View File
@@ -18,6 +18,7 @@ import {
recordOrEmpty,
stringValue,
toolsToJson,
systemPromptToText,
} from "./converters.ts"
import type {
AssistantMessageEventStreamLike,
@@ -131,8 +132,13 @@ 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,
@@ -149,7 +155,7 @@ export function createStreamCommandCode(deps: CoreDependencies) {
usage: defaultUsage(),
stopReason: "error",
errorMessage:
"No Command Code API key. Run /login and select Command Code, set COMMANDCODE_API_KEY env var, or configure ~/.commandcode/auth.json or ~/.pi/agent/auth.json.",
"No Command Code API key. Run /login and select Command Code, set the COMMANDCODE_API_KEY env var, or configure ~/.commandcode/auth.json, ~/.pi/agent/auth.json or ~/.omp/agent/auth.json",
timestamp: now(),
}
stream.push({ type: "error", reason: "error", error: msg })
@@ -366,7 +372,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,