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:
@@ -33,7 +33,6 @@ const streamCommandCode = createStreamCommandCode({
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export default async function (pi: ExtensionAPI) {
|
export default async function (pi: ExtensionAPI) {
|
||||||
|
|
||||||
const models = await fetchCommandCodeModels({ url: MODELS_URL })
|
const models = await fetchCommandCodeModels({ url: MODELS_URL })
|
||||||
|
|
||||||
pi.registerProvider("commandcode", {
|
pi.registerProvider("commandcode", {
|
||||||
|
|||||||
Generated
+24
-23
@@ -1680,18 +1680,19 @@
|
|||||||
"license": "BSD-3-Clause"
|
"license": "BSD-3-Clause"
|
||||||
},
|
},
|
||||||
"node_modules/@protobufjs/eventemitter": {
|
"node_modules/@protobufjs/eventemitter": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz",
|
||||||
"integrity": "sha512-vW1GmwMZNnL+gMRaovlh9yZX74kc+TTU3FObkkurpMaRtBfLP3ldjS9KQWlwZgraRE0+dheEEoAxdzcJQ8eXZg==",
|
"integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==",
|
||||||
"license": "BSD-3-Clause"
|
"license": "BSD-3-Clause"
|
||||||
},
|
},
|
||||||
"node_modules/@protobufjs/fetch": {
|
"node_modules/@protobufjs/fetch": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz",
|
||||||
"integrity": "sha512-GpptLrs57adMSuHi3VNj0mAF8dwh36LMaYF6XyJ6JMWlVsc+t42tm1HSEDmOs3A8fC9yyeisgLhsTVQokOZ0zw==",
|
"integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@protobufjs/aspromise": "^1.1.1"
|
"@protobufjs/aspromise": "^1.1.1",
|
||||||
|
"@protobufjs/inquire": "^1.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@protobufjs/float": {
|
"node_modules/@protobufjs/float": {
|
||||||
@@ -1701,9 +1702,9 @@
|
|||||||
"license": "BSD-3-Clause"
|
"license": "BSD-3-Clause"
|
||||||
},
|
},
|
||||||
"node_modules/@protobufjs/inquire": {
|
"node_modules/@protobufjs/inquire": {
|
||||||
"version": "1.1.2",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.1.tgz",
|
||||||
"integrity": "sha512-pa0vFRuws4wkvaXKK1uXZMAwAX4/t8ANaJo45iw/oQHNQ9q5xUzwgFmVJGXiga2BeN+zpX7Vf9vmsiIa2J+MUw==",
|
"integrity": "sha512-mnzgDV26ueAvk7rsbt9L7bE0SuAoqyuys/sMMrmVcN5x9VsxpcG3rqAUSgDyLp0UZlmNfIbQ4fHfCtreVBk8Ew==",
|
||||||
"license": "BSD-3-Clause"
|
"license": "BSD-3-Clause"
|
||||||
},
|
},
|
||||||
"node_modules/@protobufjs/path": {
|
"node_modules/@protobufjs/path": {
|
||||||
@@ -2545,9 +2546,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/brace-expansion": {
|
"node_modules/brace-expansion": {
|
||||||
"version": "5.0.6",
|
"version": "5.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.5.tgz",
|
||||||
"integrity": "sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==",
|
"integrity": "sha512-VZznLgtwhn+Mact9tfiwx64fA9erHH/MCXEUfB/0bX/6Fz6ny5EGTXYltMocqg4xFAQZtnO3DHWWXi8RiuN7cQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -3660,24 +3661,24 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/protobufjs": {
|
"node_modules/protobufjs": {
|
||||||
"version": "7.6.1",
|
"version": "7.5.6",
|
||||||
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.5.6.tgz",
|
||||||
"integrity": "sha512-4K0myLaWL5EteuSAro91EGFgcfVgxb64Jx+7oDAY6GOkXD4M69yuSEljNcInGVCA5sOPxmZ/EqDLj2x0Q0+Ygg==",
|
"integrity": "sha512-M71sTMB146U3u0di3yup8iM+zv8yPRNQVr1KK4tyBitl3qFvEGucq/rGDRShD2rsJhtN02RJaJ7j5X5hmy8SJg==",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@protobufjs/aspromise": "^1.1.2",
|
"@protobufjs/aspromise": "^1.1.2",
|
||||||
"@protobufjs/base64": "^1.1.2",
|
"@protobufjs/base64": "^1.1.2",
|
||||||
"@protobufjs/codegen": "^2.0.5",
|
"@protobufjs/codegen": "^2.0.5",
|
||||||
"@protobufjs/eventemitter": "^1.1.1",
|
"@protobufjs/eventemitter": "^1.1.0",
|
||||||
"@protobufjs/fetch": "^1.1.1",
|
"@protobufjs/fetch": "^1.1.0",
|
||||||
"@protobufjs/float": "^1.0.2",
|
"@protobufjs/float": "^1.0.2",
|
||||||
"@protobufjs/inquire": "^1.1.2",
|
"@protobufjs/inquire": "^1.1.1",
|
||||||
"@protobufjs/path": "^1.1.2",
|
"@protobufjs/path": "^1.1.2",
|
||||||
"@protobufjs/pool": "^1.1.0",
|
"@protobufjs/pool": "^1.1.0",
|
||||||
"@protobufjs/utf8": "^1.1.1",
|
"@protobufjs/utf8": "^1.1.1",
|
||||||
"@types/node": ">=13.7.0",
|
"@types/node": ">=13.7.0",
|
||||||
"long": "^5.3.2"
|
"long": "^5.0.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12.0.0"
|
"node": ">=12.0.0"
|
||||||
@@ -4129,9 +4130,9 @@
|
|||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/ws": {
|
"node_modules/ws": {
|
||||||
"version": "8.21.0",
|
"version": "8.20.0",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.20.0.tgz",
|
||||||
"integrity": "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g==",
|
"integrity": "sha512-sAt8BhgNbzCtgGbt2OxmpuryO63ZoDk/sqaB/znQm94T4fCEsy/yV+7CdC1kJhOU9lboAEU7R3kquuycDoibVA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
|
|||||||
+15
-4
@@ -39,7 +39,11 @@ export function numberValue(value: unknown): number | undefined {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function defaultAuthPaths(home: string): string[] {
|
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 {
|
function apiKeyFromCredentialRecord(value: unknown): string | undefined {
|
||||||
@@ -288,7 +292,11 @@ export function mapFinishReason(reason: unknown): StopReason {
|
|||||||
function promptPartToText(value: unknown, depth = 0): string {
|
function promptPartToText(value: unknown, depth = 0): string {
|
||||||
if (depth > 10) return ""
|
if (depth > 10) return ""
|
||||||
if (typeof value === "string") return value
|
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 ""
|
if (!isRecord(value)) return ""
|
||||||
const text = stringValue(value.text)
|
const text = stringValue(value.text)
|
||||||
if (text) return text
|
if (text) return text
|
||||||
@@ -300,7 +308,10 @@ function promptPartToText(value: unknown, depth = 0): string {
|
|||||||
export function systemPromptToText(value: unknown): string {
|
export function systemPromptToText(value: unknown): string {
|
||||||
if (value === undefined || value === null) return ""
|
if (value === undefined || value === null) return ""
|
||||||
if (typeof value === "string") return value
|
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)
|
return promptPartToText(value, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-5
@@ -18,7 +18,7 @@ import {
|
|||||||
recordOrEmpty,
|
recordOrEmpty,
|
||||||
stringValue,
|
stringValue,
|
||||||
toolsToJson,
|
toolsToJson,
|
||||||
systemPromptToText
|
systemPromptToText,
|
||||||
} from "./converters.ts"
|
} from "./converters.ts"
|
||||||
import type {
|
import type {
|
||||||
AssistantMessageEventStreamLike,
|
AssistantMessageEventStreamLike,
|
||||||
@@ -135,9 +135,7 @@ export function createStreamCommandCode(deps: CoreDependencies) {
|
|||||||
// OMP may pass the env-var name "COMMANDCODE_API_KEY" as the apiKey
|
// OMP may pass the env-var name "COMMANDCODE_API_KEY" as the apiKey
|
||||||
// value instead of resolving it. Filter out this specific string.
|
// value instead of resolving it. Filter out this specific string.
|
||||||
const hostKey =
|
const hostKey =
|
||||||
options?.apiKey && options.apiKey !== "COMMANDCODE_API_KEY"
|
options?.apiKey && options.apiKey !== "COMMANDCODE_API_KEY" ? options.apiKey : undefined
|
||||||
? options.apiKey
|
|
||||||
: undefined
|
|
||||||
|
|
||||||
const apiKey =
|
const apiKey =
|
||||||
hostKey ??
|
hostKey ??
|
||||||
@@ -157,7 +155,7 @@ export function createStreamCommandCode(deps: CoreDependencies) {
|
|||||||
usage: defaultUsage(),
|
usage: defaultUsage(),
|
||||||
stopReason: "error",
|
stopReason: "error",
|
||||||
errorMessage:
|
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(),
|
timestamp: now(),
|
||||||
}
|
}
|
||||||
stream.push({ type: "error", reason: "error", error: msg })
|
stream.push({ type: "error", reason: "error", error: msg })
|
||||||
|
|||||||
@@ -177,10 +177,10 @@ try {
|
|||||||
assert.equal(print.code, 0, print.stderr)
|
assert.equal(print.code, 0, print.stderr)
|
||||||
assert.match(print.stdout, /mock-omp-ok/)
|
assert.match(print.stdout, /mock-omp-ok/)
|
||||||
assert.equal(requestCount, 1)
|
assert.equal(requestCount, 1)
|
||||||
assert.ok(
|
assert.equal(
|
||||||
typeof lastRequestHeaders.authorization === "string" &&
|
lastRequestHeaders.authorization,
|
||||||
lastRequestHeaders.authorization.startsWith("Bearer "),
|
"Bearer mock-key",
|
||||||
"should send a bearer Authorization header",
|
"should send the resolved env-var value, not the literal var name",
|
||||||
)
|
)
|
||||||
assert.equal(lastRequestBody?.params?.model, TEST_MODEL)
|
assert.equal(lastRequestBody?.params?.model, TEST_MODEL)
|
||||||
assert.equal(typeof lastRequestBody?.params?.system, "string")
|
assert.equal(typeof lastRequestBody?.params?.system, "string")
|
||||||
|
|||||||
@@ -54,6 +54,27 @@ describe("streamCommandCode — auth", () => {
|
|||||||
assert.equal(server.requestCount(), 0)
|
assert.equal(server.requestCount(), 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("ignores the literal env-var name and falls back to env", async () => {
|
||||||
|
server.mockResponse({
|
||||||
|
type: "success",
|
||||||
|
events: [JSON.stringify({ type: "finish", finishReason: "stop" })],
|
||||||
|
})
|
||||||
|
const { streamCommandCode } = createTestDeps({
|
||||||
|
apiBase: server.baseUrl(),
|
||||||
|
env: { COMMANDCODE_API_KEY: "env-key" },
|
||||||
|
})
|
||||||
|
|
||||||
|
await collectEvents(
|
||||||
|
streamCommandCode(makeModel(), makeContext(), { apiKey: "COMMANDCODE_API_KEY" }),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
server.lastRequestHeaders().authorization,
|
||||||
|
"Bearer env-key",
|
||||||
|
"should resolve from env, not send the literal var name as the token",
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("uses options.apiKey in the Authorization header", async () => {
|
it("uses options.apiKey in the Authorization header", async () => {
|
||||||
server.mockResponse({
|
server.mockResponse({
|
||||||
type: "success",
|
type: "success",
|
||||||
|
|||||||
Reference in New Issue
Block a user