a2a-source-edit: write frontend/src/a2a.js
This commit is contained in:
@@ -33,43 +33,10 @@ export async function requireSession(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function callSkill(config, skillName, args) {
|
export async function callSkill(config, skillName, args) {
|
||||||
if (config.auth?.invokeRequiresSession) {
|
if (config.auth?.invokeRequiresSession) await requireSession(config);
|
||||||
await requireSession(config);
|
return requestJson(`${config.endpoints.invoke}/${encodeURIComponent(skillName)}`, {
|
||||||
}
|
method: "POST",
|
||||||
return requestJson(
|
headers: { "content-type": "application/json" },
|
||||||
`${config.endpoints.invoke}/${encodeURIComponent(skillName)}`,
|
body: JSON.stringify({ arguments: args }),
|
||||||
{
|
});
|
||||||
method: "POST",
|
|
||||||
headers: { "content-type": "application/json" },
|
|
||||||
body: JSON.stringify({ arguments: args }),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function sampleValue(schema) {
|
|
||||||
if (!schema || typeof schema !== "object") return null;
|
|
||||||
if ("default" in schema) return schema.default;
|
|
||||||
if ("const" in schema) return schema.const;
|
|
||||||
if (Array.isArray(schema.enum) && schema.enum.length) return schema.enum[0];
|
|
||||||
const type = Array.isArray(schema.type)
|
|
||||||
? schema.type.find((item) => item !== "null") || schema.type[0]
|
|
||||||
: schema.type;
|
|
||||||
if (type === "array") return [];
|
|
||||||
if (type === "boolean") return false;
|
|
||||||
if (type === "integer" || type === "number") return 0;
|
|
||||||
if (type === "string") return "";
|
|
||||||
const props = schema.properties || {};
|
|
||||||
if (type === "object" || Object.keys(props).length) {
|
|
||||||
const required = Array.isArray(schema.required) ? schema.required : Object.keys(props);
|
|
||||||
return Object.fromEntries(
|
|
||||||
required.map((key) => [key, sampleValue(props[key])]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function sampleArgs(skill) {
|
|
||||||
const schema = skill?.input_schema || skill?.inputSchema || {};
|
|
||||||
const value = sampleValue(schema);
|
|
||||||
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user