Skip to content

Commit 3a588eb

Browse files
committed
✨ Improve fetch docstrings and AST docs update logic
Updated fetch function documentation for clarity and added precision to AST docs update with adjusted model and parsing logic.
1 parent b5f5149 commit 3a588eb

2 files changed

Lines changed: 31 additions & 28 deletions

File tree

packages/core/src/fetch.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ export type FetchType = (
2727
/**
2828
* Creates a fetch function with retry logic.
2929
*
30-
* This function wraps the `crossFetch` with retry capabilities based
31-
* on provided options. It allows configuring the number of retries,
32-
* delay between retries, and specific HTTP status codes to retry on.
30+
* Wraps `crossFetch` with retry capabilities based on provided options.
31+
* Configures the number of retries, delay between retries, and specific HTTP status codes to retry on.
32+
* Supports cancellation and proxy configuration.
3333
*
34-
* @param options - Options for retry configuration and tracing.
35-
* @returns A fetch function with retry capabilities.
34+
* @param options - Configuration for retries, delays, status codes, cancellation, and tracing.
35+
* @returns A fetch function with retry functionality.
3636
*/
3737
export async function createFetch(
3838
options?: {
@@ -118,12 +118,12 @@ export async function fetch(
118118
/**
119119
* Fetches text content from a URL or file.
120120
*
121-
* This function attempts to fetch content from either a URL or a local file.
122-
* It supports HTTP(S) URLs and reads directly from the file system for local files.
121+
* Attempts to fetch content from an HTTP(S) URL or read from the file system for local files.
122+
* Handles retries, delays, and tracing if configured. Supports binary content via base64 encoding.
123123
*
124-
* @param urlOrFile - The URL or file to fetch from.
125-
* @param fetchOptions - Optional fetch configuration.
126-
* @returns An object containing fetch status and content.
124+
* @param urlOrFile - URL or file path to fetch from.
125+
* @param fetchOptions - Optional configuration for retries, delays, and other fetch settings.
126+
* @returns Object containing fetch status, content, and metadata.
127127
*/
128128
export async function fetchText(
129129
urlOrFile: string | WorkspaceFile,
@@ -195,16 +195,17 @@ export async function fetchText(
195195
}
196196

197197
/**
198-
* Logs a POST request for tracing.
198+
* Logs a POST request for tracing purposes.
199199
*
200-
* Constructs a curl command representing the POST request with appropriate headers
201-
* and body, optionally masking sensitive information like authorization headers.
200+
* Constructs a curl command to represent the POST request, including headers
201+
* and body. Sensitive information in authorization headers can be masked
202+
* based on the provided options.
202203
*
203-
* @param trace - Markdown trace object for logging.
204-
* @param url - The URL of the request.
205-
* @param headers - The request headers.
206-
* @param body - The request body.
207-
* @param options - Options for displaying authorization header.
204+
* @param trace - Object used for logging trace details.
205+
* @param url - The target URL of the request.
206+
* @param headers - The headers to include in the request.
207+
* @param body - The request body, either as FormData or a raw object.
208+
* @param options - Configuration options, including whether to mask authorization headers.
208209
*/
209210
export function traceFetchPost(
210211
trace: MarkdownTrace,
@@ -245,13 +246,13 @@ ${Object.entries(headers)
245246
}
246247

247248
/**
248-
* Converts a response status to a message.
249+
* Converts the HTTP response status and status text into a string list.
249250
*
250-
* Converts the HTTP response status and status text into a string list
251-
* to facilitate logging and debugging.
251+
* Facilitates logging and debugging by converting the status information
252+
* from the response object.
252253
*
253-
* @param res - The response object.
254-
* @returns A list of status and status text.
254+
* @param res - The HTTP response object containing status and statusText.
255+
* @returns A string list with status and status text.
255256
*/
256257
export function statusToMessage(res?: {
257258
status?: number

packages/sample/genaisrc/ast-docs-update.genai.mts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ for (const match of matches) {
4040
_.def("FUNCTION", match.text(), { flex: 10 })
4141
// this needs more eval-ing
4242
_.$`Update the docstring <DOCSTRING> of function <FUNCTION>.
43-
- If the docstring is up to date, return <NOP>.
43+
- If the docstring is up to date, return /NOP/.
4444
- Make sure parameters are documented.
4545
- Be concise. Use technical tone.
4646
- do NOT include types, this is for TypeScript.
47-
- Use docstring syntax.
47+
- Use docstring syntax. do not wrap in markdown code section.
4848
- Minimize updates to the existing docstring.
4949
5050
The full source of the file is in <FILE> for reference.
@@ -53,7 +53,7 @@ for (const match of matches) {
5353
`
5454
},
5555
{
56-
model: "small",
56+
model: "large",
5757
responseType: "text",
5858
flexTokens: 12000,
5959
label: match.child(0).text(),
@@ -65,9 +65,11 @@ for (const match of matches) {
6565
continue
6666
}
6767

68-
if (res.text.includes("<NOP>")) continue
68+
if (res.text.includes("/NOP/")) continue
6969

70-
const docs = docify(res.text.trim())
70+
const docs = docify(
71+
parsers.unfence(res.text.trim(), ["", "typescript", "ts"])
72+
)
7173
replace(comment, docs)
7274
}
7375

0 commit comments

Comments
 (0)