import {
type HarnessRunResult,
run,
} from "npm:@google-labs/breadboard/harness";
import {
asRuntimeKit,
createLoader,
inflateData,
inspect,
} from "npm:@google-labs/breadboard@latest";
import { fromManifest, KitManifest } from "npm:@google-labs/breadboard/kits";
import { getDataStore } from "npm:@breadboard-ai/data-store";
import AgentKit from "npm:@google-labs/agent-kit/agent.kit.json" with {
type: "json",
};
import Core from "npm:@google-labs/core-kit";
import GeminiKit from "npm:@google-labs/gemini-kit";
import JSONKit from "npm:@google-labs/json-kit";
import TemplateKit from "npm:@google-labs/template-kit";
export type ServiceOptions = {
private?: boolean;
inputs?: Record<string, any>;
};
const kits = [
asRuntimeKit(Core),
asRuntimeKit(JSONKit),
asRuntimeKit(TemplateKit),
asRuntimeKit(GeminiKit),
fromManifest(AgentKit as KitManifest),
];
import {
addKeyInput,
boardFromDescriberResult,
type NodeDescriberResult,
} from "https://esm.town/v/dglazkov/servicefactory";
const FRONTEND_MODULE = "https://esm.town/v/dglazkov/bbaasfe";
const formatRunError = (e: unknown) => {
if (typeof e === "string") {
return e;
}
if (e instanceof Error) {
return e.message;
}
const error = (e as { error: unknown }).error;
if (typeof error === "string") {
return error;
}
if (error instanceof Error) {
return error.message;
}
return JSON.stringify(error);
};
export const describe = async (url: string, options?: ServiceOptions) => {
const loader = createLoader();
const graph = await loader.load(url, { base: new URL(import.meta.url) });
const inspector = inspect(graph);
const { title, description, metadata } = graph;
const describeResult = await inspector.describe() as NodeDescriberResult;
if (options?.private) {
addKeyInput(describeResult);
}
return {
...describeResult,
title,
description,
metadata,
} as NodeDescriberResult;
};
export const invoke = async (
url: string,
inputs: Record<string, any>,
options?: ServiceOptions,
) => {
if (options?.private) {
if (!inputs.$key || inputs.$key != Deno.env.get("BB_SERVICE_KEY")) {
return {
$error: "Must provide an API key to access the service.",
};
}
delete inputs.$key;
}