Skip to content

Commit

Permalink
Update lib
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Actions Bot committed May 8, 2024
1 parent 78e12f1 commit ec95d51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lib/experimental_agents/service_agents/fetch_agent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import { AgentFunction } from "../../graphai";
export declare const fetchAgent: AgentFunction<{
debug?: boolean;
type?: string;
returnErrorResult?: boolean;
}, any, any>;
declare const fetchAgentInfo: {
name: string;
agent: AgentFunction<{
debug?: boolean | undefined;
type?: string | undefined;
returnErrorResult?: boolean | undefined;
}, any, any>;
mock: AgentFunction<{
debug?: boolean | undefined;
type?: string | undefined;
returnErrorResult?: boolean | undefined;
}, any, any>;
samples: ({
inputs: (string | {
Expand Down
22 changes: 14 additions & 8 deletions lib/experimental_agents/service_agents/fetch_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@ const fetchAgent = async ({ inputs, params }) => {
}
const response = await fetch(url.toString(), fetchOptions);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status} ${await response.text()} ${url.toString()}`);
}
const type = params?.type ?? "json";
if (type === "json") {
return await response.json();
const status = response.status;
const error = await response.text();
if (params?.returnErrorResult) {
return { status, error };
}
throw new Error(`HTTP error! Status: ${status} ${error} ${url.toString()}`);
}
else {
if (type === "xml") {
const result = await (async () => {
const type = params?.type ?? "json";
if (type === "json") {
return await response.json();
}
else if (type === "xml") {
const xmlData = await response.text();
return await (0, xml2js_1.parseStringPromise)(xmlData, { explicitArray: false, mergeAttrs: true });
}
else if (type === "text") {
return response.text();
}
throw new Error(`Unknown Type! ${type}`);
}
})();
return result;
};
exports.fetchAgent = fetchAgent;
const fetchAgentInfo = {
Expand Down

0 comments on commit ec95d51

Please sign in to comment.