Closed pelikhan closed 2 weeks ago
The changes look good overall, they add a new feature to parse and display a trace tree from the markdown content. This is accomplished by adding two functions in markdown.ts
to parse the markdown content, and then use the parsed result in newly introduced tracetree.ts
to display the tree.
However, there are some potential issues:
In markdown.ts
, the function parseDetailsTree
does not handle the cases when the markdown syntax format is incorrect, such as mismatching <details>
and </details>
tags. This may cause issues in runtime.
In tracetree.ts
, the TraceTree
class does not seem to handle the case when state.aiRequest?.trace?.content
is undefined
. This might cause the application to crash when the data is not available.
There is no null or undefined check for the element
in the getChildren
function, which could possibly lead to a runtime error when element
is undefined
.
To mitigate these concerns, consider adding error handling or checks for undefined values where necessary.
Here is the suggested code fix for getChildren
function:
+ getChildren(element?: TraceNode): vscode.ProviderResult<TraceNode[]> {
+ if (!element) return [];
+ if (element === undefined)
+ element = parseDetailsTree(this.state.aiRequest?.trace?.content) || '';
+ if (typeof element === "object") return element?.content || [];
+ return undefined
+}
And a possible improvement for parseDetailsTree
:
+ export function parseDetailsTree(text: string): DetailsNode {
+ if (!text || typeof text !== 'string') return { label: "root", content: [] };
+ const stack: DetailsNode[] = [{ label: "root", content: [] }]
+ const lines = text.split("\n")
+ for (let i = 0; i < lines.length; ++i) {
+ const startDetails = /^\s*<details( open)>\s*$/m.exec(lines[i])
+ if (startDetails) {
+ const parent = stack.at(-1)
+ const current: DetailsNode = { label: "", content: [] }
+ parent.content.push(current)
+ stack.push(current)
+ continue
+ }
+ const endDetails = /^\s*<\/details>\s*$/m.exec(lines[i])
+ if (endDetails) {
+ if (stack.length === 1) throw new Error("Mismatching </details> tag at line " + i);
+ stack.pop()
+ continue
+ }
+ const summary = /^\s*<summary>(.*)<\/summary>\s*$/m.exec(lines[i])
+ if (summary) {
+ const current = stack.at(-1)
+ current.label = summary[1]
+ continue
+ }
+
+ const contents = stack.at(-1).content
+ const content = lines[i]
+ const lastContent = contents.at(-1)
+ if (typeof lastContent === "string")
+ contents[contents.length - 1] = lastContent + "\n" + content
+ else contents.push(content)
+ }
+
+ if (stack.length > 1) throw new Error("Missing </details> tag");
+
+ return stack[0]
+}
If these improvements are applied, then LGTM :rocket:.
generated by pr-review
/genai-describe
๐ป Code in the
core/src/chat.ts
andcore/src/promptrunner.ts
files has been rearranged to show the fenced variables in the trace only when the fences are present.๐ Links in the
core/src/clihelp.ts
file have been modified changing their format from[command line interface \
run`]to
command line interface [run]`.๐ Cache prefixes and Trace node prefixes in
core/src/constants.ts
have been adjusted to use a more specific genaiscript path.๐งช A new file
core/src/markdown.test.ts
, has been added which contains tests for trace tree, including flat, single node, multi node, and nested node scenarios.๐ New functionalities have been added in
core/src/markdown.ts
to parse and render trace trees.๐จ Display of prompt nodes in
core/src/promptdom.ts
has been changed to combine title and value in a single line.๐ Error reporting has been adjusted in
core/src/trace.ts
to be under a details section in the markdown trace.๐ ๏ธ The
packages/sample/genaisrc/summary-of-summary-gpt35.genai.js
file has been updated adding thefiles
property.๐ In the
vscode
package, thegenaiscript
views have been updated inpackage.json
to include a newgenaiscript.trace
view and adjustments have been made to the names and visibility of other views.โก The file
openairequesttree.ts
has been renamed tollmrequesttree.ts
and its corresponding changes have been made in theextension.ts
file.๐ A new file
tracetree.ts
has been introduced in thevscode
package to handle the logic of the newgenaiscript.trace
view.๐ก Improvements have been made in the markdown preview functionality in
markdowndocumentprovider.ts
, adding an auto refresh command and incorporating logic to preview trace nodes.