Skip to content

Commit aa4eb0c

Browse files
committed
round 3
1 parent 0be6b75 commit aa4eb0c

11 files changed

Lines changed: 70 additions & 61 deletions

File tree

packages/core/src/annotations.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const SEV_EMOJI_MAP: Record<string, string> = Object.freeze({
5252
/**
5353
* Parses annotations from TypeScript, GitHub Actions, and Azure DevOps.
5454
*
55-
* @param text - Input text containing annotations to parse.
55+
* @param text Input text containing annotations to parse.
5656
* @returns Array of unique Diagnostic objects extracted from the input text.
5757
*/
5858
export function parseAnnotations(text: string): Diagnostic[] {
@@ -139,8 +139,8 @@ export function convertDiagnosticToGitHubActionCommand(d: Diagnostic) {
139139
/**
140140
* Converts a Diagnostic object to an Azure DevOps log issue command string.
141141
*
142-
* @param d - The Diagnostic object containing severity, message, filename, and range.
143-
* @returns A formatted Azure DevOps command string for warnings and errors, or a debug message for info severity.
142+
* @param d - Diagnostic object containing severity, message, filename, and range.
143+
* @returns Formatted Azure DevOps command string for warnings and errors, or a debug message for info severity.
144144
*/
145145
export function convertDiagnosticToAzureDevOpsCommand(d: Diagnostic) {
146146
// Handle 'info' severity separately with a debug message.
@@ -153,8 +153,8 @@ export function convertDiagnosticToAzureDevOpsCommand(d: Diagnostic) {
153153
/**
154154
* Converts annotations in text to a Markdown representation with severity-based admonitions.
155155
*
156-
* @param text Input text containing annotations to be converted.
157-
* @returns Formatted Markdown string with severity levels mapped to admonitions.
156+
* @param text Input text containing annotations to convert.
157+
* @returns Formatted Markdown string with severity levels mapped to admonitions, including file and line references.
158158
*/
159159
export function convertAnnotationsToMarkdown(text: string): string {
160160
// Maps severity levels to Markdown admonition types.

packages/core/src/ast.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export interface FileReference {
1818

1919
/**
2020
* Converts diagnostic data into a CSV-formatted string.
21-
* @param diagnostics - Array of diagnostic objects containing severity, filename, range, code, and message.
22-
* @param sep - String used as the separator for CSV fields.
23-
* @returns CSV string with each diagnostic entry on a separate line.
21+
* @param diagnostics - Array of diagnostic objects with severity, filename, range, code, and message.
22+
* @param sep - Separator string for CSV fields.
23+
* @returns CSV string with each diagnostic entry on a new line.
2424
*/
2525
export function diagnosticsToCSV(diagnostics: Diagnostic[], sep: string) {
2626
return diagnostics
@@ -40,9 +40,9 @@ export function diagnosticsToCSV(diagnostics: Diagnostic[], sep: string) {
4040

4141
/**
4242
* Determines the group name of a template.
43-
* @param template - The template to evaluate, containing an ID and optional group.
43+
* @param template - The template object to evaluate, containing an ID and an optional group property.
4444
* @returns The group name of the template. Returns "system" if the ID starts with "system",
45-
* the existing group if set, or "unassigned" if no group is determined.
45+
* the group property if set, or "unassigned" if no group is determined.
4646
*/
4747
export function templateGroup(template: PromptScript) {
4848
return (
@@ -57,8 +57,9 @@ export const eolPosition = 0x3fffffff // End of line position, a large constant
5757
export const eofPosition: CharPosition = [0x3fffffff, 0] // End of file position, a tuple with a large constant
5858

5959
/**
60-
* Organizes templates by directory and determines the presence of JavaScript or TypeScript files in each directory.
61-
* @param prj - The project containing the scripts to analyze.
60+
* Organizes templates by directory and identifies the presence of JavaScript or TypeScript files in each directory.
61+
* Filters out templates without filenames or matching the PROMPTY_REGEX.
62+
* @param prj - The project containing the scripts to process.
6263
* @returns An array of objects, each representing a directory with its name and flags indicating the presence of JavaScript and TypeScript files.
6364
*/
6465
export function collectFolders(prj: Project) {
@@ -79,10 +80,10 @@ export function collectFolders(prj: Project) {
7980
}
8081

8182
/**
82-
* Retrieves a script by its ID from the project's scripts list.
83+
* Finds a script in the project's scripts list by matching its ID with the system prompt instance.
8384
* @param prj - The project containing the scripts to search.
84-
* @param system - The system prompt instance containing the script ID to match.
85-
* @returns The matching script or undefined if no match is found.
85+
* @param system - The system prompt instance with the script ID to match.
86+
* @returns The matching script if found, otherwise undefined.
8687
*/
8788
export function resolveScript(prj: Project, system: SystemPromptInstance) {
8889
return prj?.scripts?.find((t) => t.id == system.id) // Find and return the template with the matching ID

packages/core/src/cancellation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class AbortSignalCancellationToken implements CancellationToken {
3333

3434
/**
3535
* Converts a CancellationToken to an AbortSignal if supported.
36-
* Returns undefined if the token does not have a compatible signal property.
36+
* If the token lacks a compatible signal property, returns undefined.
3737
*
3838
* @param token - The CancellationToken to convert.
3939
* @returns The associated AbortSignal or undefined if unsupported.

packages/core/src/chatrender.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ export function renderShellOutput(output: ShellOutput) {
5252
/**
5353
* Renders the content of a message into a formatted string.
5454
*
55-
* @param msg - The message object containing content, which may include text, images, audio, or other types.
56-
* @param options - Configuration options for rendering, including text formatting, image caching, and language.
57-
* @returns A formatted string representation of the message content, or undefined if the content is invalid.
55+
* @param msg - The message object containing content, which may include text, images, audio, or other types.
56+
* Supports both string and array-based content.
57+
* @param options - Configuration options for rendering, including text formatting, image caching, and language.
58+
* Includes optional functions for caching images.
59+
* @returns A formatted string representation of the message content, or undefined if the content is invalid or unsupported.
5860
*/
5961
export async function renderMessageContent(
6062
msg:
@@ -109,8 +111,9 @@ export function lastAssistantReasoning(messages: ChatCompletionMessageParam[]) {
109111

110112
/**
111113
* Renders a list of chat messages into a formatted markdown string.
112-
* @param messages - The list of chat messages to process and render.
113-
* @param options - Configuration options for filtering messages by roles, formatting, and tool inclusion.
114+
*
115+
* @param messages - The list of chat messages to render.
116+
* @param options - Configuration options for filtering messages by role, formatting language, cancellation, and tool inclusion.
114117
* @returns A markdown string representation of the chat messages.
115118
*/
116119
export async function renderMessagesToMarkdown(

packages/core/src/chunkers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { assert } from "./assert"
22

33
/**
4-
* // Splits a string into chunks of specified size.
5-
* // Parameters:
6-
* // - s: The input string to be chunked.
7-
* // - n: The maximum size of each chunk. Defaults to 2 << 14.
4+
* Splits a string into chunks of specified size.
5+
* Parameters:
6+
* - s: Input string to be split into chunks.
7+
* - n: Maximum size of each chunk. Defaults to 2 << 14.
88
*/
99
export function chunkString(s: string, n: number = 2 << 14) {
1010
if (!s?.length) return []

packages/core/src/cleaners.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export function unmarkdown(text: string) {
8383
}
8484

8585
/**
86-
* Collapses sequences of three or more consecutive newlines into two newlines.
87-
* @param res The input string to be processed.
86+
* Collapses sequences of three or more consecutive newlines into two consecutive newlines.
87+
* @param res Input string to process.
8888
*/
8989
export function collapseNewlines(res: string): string {
9090
return res?.replace(/(\r?\n){3,}/g, "\n\n")

packages/core/src/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,12 @@ export async function readConfig(
166166

167167
/**
168168
* Resolves and outputs environment information for language model providers.
169-
* @param provider - Specific provider to filter by (optional).
170-
* @param options - Configuration options, including whether to show tokens, errors, models, or hide hidden providers.
169+
* @param provider - Filters by specific provider (optional).
170+
* @param options - Configuration options:
171+
* - token: Whether to include tokens.
172+
* - error: Whether to include errors.
173+
* - models: Whether to list models.
174+
* - hide: Whether to exclude hidden providers.
171175
*/
172176
export async function resolveLanguageModelConfigurations(
173177
provider: string,

packages/core/src/consolecolor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export let consoleColors = !!stdout.isTTY
66

77
/**
88
* Enables or disables console color output.
9-
* @param enabled - Indicates whether to enable or disable color output.
9+
* @param enabled - Whether to enable or disable color output.
1010
*/
1111
export function setConsoleColors(enabled: boolean) {
1212
consoleColors = !!enabled
@@ -22,7 +22,7 @@ export function setConsoleColors(enabled: boolean) {
2222
/**
2323
* Wraps a message with ANSI escape codes for the specified color.
2424
* @param n - The ANSI color code or string to apply.
25-
* @param message - The text to wrap with color codes.
25+
* @param message - The text to wrap with ANSI escape codes.
2626
*/
2727
export function wrapColor(n: number | string, message: string) {
2828
if (consoleColors) return `\x1B[${n}m${message}\x1B[0m`
@@ -33,10 +33,10 @@ export function wrapColor(n: number | string, message: string) {
3333
/**
3434
* Wraps text with RGB ANSI color codes for foreground or background.
3535
* Converts an RGB integer to its red, green, and blue components and applies the corresponding ANSI escape codes.
36-
* Does nothing if color output is disabled.
37-
* @param rgb - The RGB color as a single integer
38-
* @param text - The text to which the color will be applied
39-
* @param background - Specifies if the color is for the background
36+
* Returns the original text if color output is disabled.
37+
* @param rgb - RGB color as a single integer.
38+
* @param text - Text to apply the color to.
39+
* @param background - Whether the color is for the background.
4040
*/
4141

4242
export function wrapRgbColor(

packages/core/src/crypto.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ async function digest(algorithm: string, data: Uint8Array) {
2828
/**
2929
* Generates a random hexadecimal string of the specified size.
3030
*
31-
* @param size - The number of random bytes to generate, which will be converted to a hexadecimal string.
32-
* @returns A hexadecimal string representation of the generated random bytes.
31+
* @param size - Number of random bytes to generate, converted to a hexadecimal string.
32+
* @returns Hexadecimal string representation of the generated random bytes.
3333
*/
3434
export function randomHex(size: number) {
3535
// Create a new Uint8Array with the specified size to hold random bytes
@@ -121,9 +121,9 @@ export async function hash(value: any, options?: HashOptions) {
121121
/**
122122
* Computes the hash of a file using a streaming approach.
123123
*
124-
* @param filePath - Path to the file for which the hash is calculated.
125-
* @param algorithm - Hashing algorithm to use, defaults to "sha-256".
126-
* @returns A promise resolving to the file's hash in hexadecimal format.
124+
* @param filePath - The path to the file to hash.
125+
* @param algorithm - The hashing algorithm to use, defaults to "sha-256".
126+
* @returns A promise that resolves to the file's hash in hexadecimal format.
127127
*/
128128
export async function hashFile(
129129
filePath: string,

packages/core/src/csv.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { filenameOrFileToContent } from "./unwrappers"
1414
* @param text - The CSV string or file to parse.
1515
* @param options - Optional configuration for parsing.
1616
* @param options.delimiter - The delimiter used in the CSV, defaults to a comma.
17-
* @param options.headers - Column headers for the CSV, as an array or single value.
17+
* @param options.headers - Column headers for the CSV, as an array or single value. If not provided, headers are inferred from the first line.
1818
* @param options.repair - Whether to repair common escape errors, defaults to false.
1919
* @returns An array of objects representing the parsed CSV data.
2020
*/
@@ -55,13 +55,13 @@ export function CSVParse(
5555
/**
5656
* Attempts to parse a CSV string into an array of objects, handling errors gracefully.
5757
*
58-
* @param text - The CSV string to parse.
58+
* @param text - The CSV string to parse. Returns an empty array if the input is empty.
5959
* @param options - Optional configuration for parsing and error handling.
60-
* @param options.delimiter - Delimiter to separate values, defaults to comma.
61-
* @param options.headers - Array of column headers for the parsed data.
62-
* @param options.repair - Flag to enable basic error correction in the input data.
63-
* @param options.trace - Optional trace function for logging errors during parsing.
64-
* @returns An array of objects representing the parsed CSV data, or undefined on error.
60+
* @param options.delimiter - The delimiter used to separate values, defaults to a comma.
61+
* @param options.headers - Column headers for the parsed data, as an array or single value.
62+
* @param options.repair - Enables basic error correction in the input data.
63+
* @param options.trace - Trace function for logging errors during parsing.
64+
* @returns An array of objects representing the parsed CSV data, or undefined if an error occurs.
6565
*/
6666
export function CSVTryParse(
6767
text: string,
@@ -87,7 +87,7 @@ export function CSVTryParse(
8787
* Converts an array of objects into a CSV string.
8888
*
8989
* @param csv - Array of objects to convert to CSV format. Returns an empty string if the input is null or undefined.
90-
* @param options - Optional configuration for CSV stringification, including headers and delimiter settings.
90+
* @param options - Configuration for CSV stringification, including headers and delimiter settings.
9191
* @returns A CSV formatted string representation of the input data.
9292
*/
9393
export function CSVStringify(csv: object[], options?: CSVStringifyOptions) {
@@ -97,12 +97,12 @@ export function CSVStringify(csv: object[], options?: CSVStringifyOptions) {
9797
}
9898

9999
/**
100-
* Converts an array of objects into a Markdown table format.
100+
* Converts an array of objects into a Markdown table.
101101
*
102-
* @param csv - The array of objects representing CSV data.
103-
* @param options - Options for formatting the table.
104-
* @param options.headers - Array of headers for the table columns.
105-
* @returns A string representing the CSV data in Markdown table format.
102+
* @param csv - Array of objects representing the data to convert.
103+
* @param options - Configuration options for the table.
104+
* @param options.headers - Headers for the table columns. If not provided, keys from the first object are used.
105+
* @returns A Markdown table as a string.
106106
*/
107107
export function dataToMarkdownTable(
108108
csv: object[],
@@ -154,9 +154,9 @@ export function objectToMarkdownTableRow(
154154
/**
155155
* Splits an array of objects into chunks of a specified size.
156156
*
157-
* @param rows - The array of objects to split into chunks.
158-
* @param size - The size of each chunk.
159-
* @returns An array of chunk objects with starting index and rows.
157+
* @param rows - Array of objects to be divided into chunks.
158+
* @param size - Number of objects per chunk. Must be at least 1.
159+
* @returns Array of chunk objects, each containing a starting index and rows.
160160
*/
161161
export function CSVChunk(
162162
rows: object[],

0 commit comments

Comments
 (0)