Sign In Sign Up

Optimize observeThreadGuidanceFiles return type

sqs ·
4mo ago
+8 -2 ~2
Unlisted
Make observeThreadGuidanceFiles return Omit<ResolvedGuidanceFile, 'content'>[] and remove that field from its return value, and update the tests. Note that it is omitted because this is used in places that do not need the file contents, and this saves on data transferred over the webview API.

I'll help you modify observeThreadGuidanceFiles to omit the content field and update the tests accordingly.

Updated TODOs
Updated TODOs
Updated TODOs

Now I'll modify the observeThreadGuidanceFiles function to return the type without the content field and update its implementation:

@@ -302,9 +302,9 @@
 */
export function observeThreadGuidanceFiles(
	deps: GuidanceFilesDeps,
	threadID: ThreadID,
): Observable<ResolvedGuidanceFile[]> {
): Observable<Omit<ResolvedGuidanceFile, 'content'>[]> {
	const { filesystem, configService, threadService } = deps

	// Global guidance files (which don't change based on thread content).
	const globalFiles = observeThreadGlobalGuidanceFiles({ filesystem, configService })

Now I need to update the implementation to map the resolved guidance files to exclude the content field:

@@ -341,8 +341,14 @@
				createGuidanceFileParser(filesystem),
				signal,
			),
		),
		map((resolvedFiles) =>
			resolvedFiles.map((file) => {
				const { content, ...fileWithoutContent } = file
				return fileWithoutContent
			}),
		),
	)
}

const GUIDANCE_FILE_TYPE_ORDER: Record<GuidanceFile['type'], number> = {
Updated TODOs