refactor: clean up code formatting and update package dependencies

- Removed unnecessary blank lines and improved formatting for better readability in index.ts and converters.ts.
- Updated package-lock.json to downgrade several dependencies for compatibility, including @protobufjs/eventemitter, @protobufjs/fetch, and others.
- Enhanced error message in core.ts to clarify configuration options for the Command Code API key.
- Added a test to ensure the correct handling of environment variable values in test-stream.ts.
This commit is contained in:
wh.huajieyu
2026-05-28 06:23:28 -04:00
parent c2497ed098
commit e78875f532
6 changed files with 67 additions and 37 deletions
+15 -4
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, ".omp", "agent", "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 {
@@ -288,7 +292,11 @@ export function mapFinishReason(reason: unknown): StopReason {
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 (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
@@ -300,7 +308,10 @@ function promptPartToText(value: unknown, depth = 0): string {
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")
if (Array.isArray(value))
return value
.map((v) => promptPartToText(v, 0))
.filter(Boolean)
.join("\n\n")
return promptPartToText(value, 0)
}
+3 -5
View File
@@ -18,7 +18,7 @@ import {
recordOrEmpty,
stringValue,
toolsToJson,
systemPromptToText
systemPromptToText,
} from "./converters.ts"
import type {
AssistantMessageEventStreamLike,
@@ -135,9 +135,7 @@ export function createStreamCommandCode(deps: CoreDependencies) {
// 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
options?.apiKey && options.apiKey !== "COMMANDCODE_API_KEY" ? options.apiKey : undefined
const apiKey =
hostKey ??
@@ -157,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 })