Skip to content

Commit 7bac441

Browse files
committed
fix: update firstStringProp to use Record type and improve type safety in assertObject
1 parent 253c79f commit 7bac441

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

packages/cli-plugins/copilot/src/commands/app/attach-session-logger.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import chalk from 'chalk';
22
import ora from 'ora';
33

4-
import type { CopilotSession, JsonValue } from '@github/copilot-sdk';
4+
import type { CopilotSession } from '@github/copilot-sdk';
55

66
import { tryFormatMessage } from './try-format-message.js';
77

88
/**
99
* Extracts the first string-valued property found among `keys` on a tool-call's
10-
* JSON arguments, narrowing the untyped `JsonValue` union to its object branch first.
11-
* @param value - The tool-call arguments to inspect, as reported by the Copilot SDK
10+
* arguments record, as reported by the Copilot SDK.
11+
* @param value - The tool-call arguments to inspect
1212
* @param keys - Property names to check, in priority order
1313
* @returns The first matching string value, or `undefined` if none match
1414
*/
15-
function firstStringProp(value: JsonValue | undefined, keys: string[]): string | undefined {
16-
// Primitives and arrays have no named properties to read
17-
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
15+
function firstStringProp(
16+
value: Record<string, unknown> | undefined,
17+
keys: string[],
18+
): string | undefined {
19+
if (value === undefined) {
1820
return undefined;
1921
}
2022
// Return the first key present with a string value, in caller-specified priority order

packages/cli/src/lib/utils/assert-object.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ import { assert } from './assert.js';
2121
*/
2222
export function assertObject(value: object, message?: string | Error): asserts value {
2323
// typeof null is 'object', so this does not exclude null values
24-
assert(typeof value === 'object', message);
24+
// normalize to `Error | undefined` to match the `node:assert` overload
25+
assert(typeof value === 'object', typeof message === 'string' ? new Error(message) : message);
2526
}

0 commit comments

Comments
 (0)