Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pdl-live-react/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,15 @@ export function extractStructuredModelResponse({
export function isArgs(block: ArgsBlock | CodeBlock): block is ArgsBlock {
return Array.isArray((block as ArgsBlock).args)
}

export function extractCode({ code }: CodeBlock): string {
if (
isNonScalarPdlBlock(code) &&
hasResult(code) &&
typeof code.pdl__result !== "object"
) {
return String(code.pdl__result)
}

return String(code)
}
2 changes: 1 addition & 1 deletion pdl-live-react/src/view/detail/DrawerContentBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function DrawerContentBody({

default: {
// some blocks have nothing interesting to show other than their result
const hasSummary = !(block.kind === "data" || block.kind === "code")
const hasSummary = !(block.kind === "data")

return [
...(!hasSummary
Expand Down
39 changes: 18 additions & 21 deletions pdl-live-react/src/view/detail/kind/Code.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Group from "../Group"

import Code from "../../code/Code"
import Result from "../../Result"
import { isArgs } from "../../../helpers"
import { isArgs, extractCode } from "../../../helpers"

export default function CodeItems({
block,
Expand All @@ -11,27 +10,25 @@ export default function CodeItems({
| import("../../../pdl_ast").ArgsBlock
| import("../../../pdl_ast").CodeBlock
}) {
const { lang, pdl__result } = block
const code = isArgs(block) ? block.args.join(" ") : block.code
const { lang } = block
const code = isArgs(block) ? block.args.join(" ") : extractCode(block)

return (
<>
{typeof code === "string" && (
<Group
term="Code"
description={
<Code
block={code.trim()}
showLineNumbers
language={
lang === "pdl" || lang === "jinja" || lang === "command"
? "plaintext"
: lang || "yaml"
}
/>
}
/>
)}
<Result result={pdl__result} term="Execution Output" />
<Group
term="Code"
description={
<Code
block={code.trim()}
showLineNumbers
language={
lang === "pdl" || lang === "jinja" || lang === "command"
? "plaintext"
: lang || "yaml"
}
/>
}
/>
</>
)
}