Skip to content

Commit a2e5d9f

Browse files
authored
Show UI element when no script is selected (#1551)
* show ui element when no script * ✨ refactor HTTP request building in traceFetchPost Revised traceFetchPost to generate detailed HTTP requests. * 🎨 refactor: update logging to use dbg instead of logVerbose Simplified logging by replacing logVerbose calls with dbg calls.
1 parent 51df602 commit a2e5d9f

4 files changed

Lines changed: 62 additions & 34 deletions

File tree

packages/core/src/fetchtext.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,40 @@ export function traceFetchPost(
168168
: "***") // Mask other authorization headers
169169
)
170170
}
171-
let cmd = `curl ${url} \\
172-
--no-buffer \\
173-
${Object.entries(headers)
174-
.map(([k, v]) => `-H "${k}: ${v}"`)
175-
.join(" \\\n")} \\
176-
`
171+
172+
// Start building the HTTP request
173+
let httpRequest = `POST ${url} HTTP/1.1\n`
174+
175+
// Add headers
176+
Object.entries(headers).forEach(([key, value]) => {
177+
httpRequest += `${key}: ${value}\n`
178+
})
179+
180+
// Add body
177181
if (body instanceof FormData) {
182+
const boundary = "------------------------" + Date.now().toString(16)
183+
httpRequest += `Content-Type: multipart/form-data; boundary=${boundary}\n\n`
184+
178185
body.forEach((value, key) => {
179-
cmd += `-F ${key}=${value instanceof File ? `... (${prettyBytes(value.size)})` : "" + value}\n`
186+
httpRequest += `--${boundary}\n`
187+
httpRequest += `Content-Disposition: form-data; name="${key}"`
188+
if (value instanceof File) {
189+
httpRequest += `; filename="${value.name}"\n`
190+
httpRequest += `Content-Type: ${value.type || "application/octet-stream"}\n\n`
191+
httpRequest += `... (${prettyBytes(value.size)})\n`
192+
} else {
193+
httpRequest += "\n\n" + value + "\n"
194+
}
180195
})
196+
httpRequest += `--${boundary}--\n`
181197
} else {
182-
cmd += `-d '${JSON.stringify(body, null, 2).replace(/'/g, "'\\''")}'
183-
`
198+
httpRequest += "Content-Type: application/json\n\n"
199+
httpRequest += JSON.stringify(body, null, 2)
184200
}
201+
185202
if (trace) {
186-
trace.detailsFenced(`🌐 fetch`, cmd, "bash")
203+
trace.detailsFenced(`🌐 fetch`, httpRequest, "http")
187204
} else {
188-
logVerbose(cmd)
205+
logVerbose(httpRequest)
189206
}
190207
}

packages/core/src/githubclient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export async function githubParseEnv(
168168
options
169169
)
170170
if (repoInfo.failed) {
171-
logVerbose(repoInfo.stderr)
171+
dbg(repoInfo.stderr)
172172
} else if (!repoInfo.failed) {
173173
const { name: repo, owner } = JSON.parse(repoInfo.stdout)
174174
dbg(`retrieved repository info via gh CLI: ${repoInfo.stdout}`)
@@ -200,7 +200,7 @@ export async function githubParseEnv(
200200
}
201201
}
202202
} catch (e) {
203-
logVerbose(errorMessage(e))
203+
dbg(errorMessage(e))
204204
}
205205

206206
deleteUndefinedValues(res)
Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
script({
2-
title: 'Simple Math Test',
3-
description: 'Validates that the model correctly calculates 1+1.',
4-
group: 'Basic Tests',
5-
temperature: 0,
6-
maxTokens: 10,
2+
title: "Simple Math Test",
3+
description: "Validates that the model correctly calculates 1+1.",
4+
group: "Basic Tests",
5+
temperature: 0,
6+
maxTokens: 10,
7+
accept: "none",
78
tests: [
8-
{
9-
files: [],
10-
// rubrics: ['output correctly calculates 1+1 as 2'],
11-
// facts: [`The model should return "2".`],
12-
asserts: [
13-
{
14-
type: 'icontains',
15-
value: '2',
16-
},
17-
],
18-
},
9+
{
10+
files: [],
11+
// rubrics: ['output correctly calculates 1+1 as 2'],
12+
// facts: [`The model should return "2".`],
13+
asserts: [
14+
{
15+
type: "icontains",
16+
value: "2",
17+
},
18+
],
19+
},
1920
],
20-
});
21-
22-
$`What is 1 + 1?`;
21+
})
22+
23+
$`What is 1 + 1?`

packages/web/src/App.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,18 @@ function acceptToAccept(accept: string | undefined) {
9999
function FilesFormInput() {
100100
const script = useScript()
101101
const { accept } = script || {}
102-
if (!script || accept === "none") return null
103-
102+
if (!script)
103+
return (
104+
<vscode-form-group>
105+
<vscode-label>Select a script to run.</vscode-label>
106+
</vscode-form-group>
107+
)
108+
if (accept === "none")
109+
return (
110+
<vscode-form-group>
111+
<vscode-label>No files accepted.</vscode-label>
112+
</vscode-form-group>
113+
)
104114
return <FilesDropZone script={script} />
105115
}
106116

0 commit comments

Comments
 (0)