genkit
Version:
Genkit AI framework
90 lines • 2.99 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var agent_exports = {};
__export(agent_exports, {
AgentError: () => import_agent_core2.AgentError,
applyPatch: () => import_json_patch.applyPatch,
remoteAgent: () => remoteAgent
});
module.exports = __toCommonJS(agent_exports);
var import_agent_core = require("@genkit-ai/ai/agent-core");
var import_client = require("./client.js");
var import_agent_core2 = require("@genkit-ai/ai/agent-core");
var import_json_patch = require("@genkit-ai/ai/json-patch");
function remoteAgent(options) {
const { url } = options;
const getSnapshotUrl = options.getSnapshotUrl ?? `${url}/getSnapshot`;
const abortUrl = options.abortUrl ?? `${url}/abort`;
const resolveHeaders = async () => {
if (!options.headers) return void 0;
if (typeof options.headers === "function") {
return options.headers();
}
return options.headers;
};
const transport = {
stateManagement: options.stateManagement,
runTurn(input, init, opts) {
const started = (async () => {
const headers = await resolveHeaders();
return (0, import_client.streamFlow)({
url,
input,
init,
headers,
abortSignal: opts.abortSignal
});
})();
const output = (async () => {
const { output: output2 } = await started;
return output2;
})();
const stream = (async function* () {
const { stream: rawStream } = await started;
yield* rawStream;
})();
return { stream, output };
},
async getSnapshot(lookup) {
const headers = await resolveHeaders();
return (0, import_client.runFlow)({
url: getSnapshotUrl,
input: lookup,
headers
});
},
async abort(snapshotId) {
const headers = await resolveHeaders();
const result = await (0, import_client.runFlow)({
url: abortUrl,
input: { snapshotId },
headers
});
return result?.status;
}
};
return (0, import_agent_core.createAgentAPI)(transport);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AgentError,
applyPatch,
remoteAgent
});
//# sourceMappingURL=agent.js.map