mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-18 02:03:09 +00:00
chore: sync workspace changes
This commit is contained in:
parent
d24f983e2c
commit
bf58891edf
139 changed files with 5454 additions and 8986 deletions
18
frontend/packages/inspector/src/utils/format.ts
Normal file
18
frontend/packages/inspector/src/utils/format.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
export const formatJson = (value: unknown) => {
|
||||
if (value === null || value === undefined) return "";
|
||||
if (typeof value === "string") return value;
|
||||
try {
|
||||
return JSON.stringify(value, null, 2);
|
||||
} catch {
|
||||
return String(value);
|
||||
}
|
||||
};
|
||||
|
||||
export const formatTime = (value: string) => {
|
||||
if (!value) return "";
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return value;
|
||||
return date.toLocaleTimeString();
|
||||
};
|
||||
|
||||
export const escapeSingleQuotes = (value: string) => value.replace(/'/g, `'\\''`);
|
||||
15
frontend/packages/inspector/src/utils/http.ts
Normal file
15
frontend/packages/inspector/src/utils/http.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { escapeSingleQuotes } from "./format";
|
||||
|
||||
export const buildCurl = (method: string, url: string, body?: string, token?: string) => {
|
||||
const headers: string[] = [];
|
||||
if (token) {
|
||||
headers.push(`-H 'Authorization: Bearer ${escapeSingleQuotes(token)}'`);
|
||||
}
|
||||
if (body) {
|
||||
headers.push(`-H 'Content-Type: application/json'`);
|
||||
}
|
||||
const data = body ? `-d '${escapeSingleQuotes(body)}'` : "";
|
||||
return `curl -X ${method} ${headers.join(" ")} ${data} '${escapeSingleQuotes(url)}'`
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue