humanlayer-vercel-ai-sdk
Version:
typescript client for humanlayer.dev
53 lines (52 loc) • 1.72 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.HumanLayer = exports.humanlayer = void 0;
const humanlayer_1 = require("humanlayer");
const ai_1 = require("ai");
const zod_1 = require("zod");
const humanlayer = (params) => {
return new HumanLayer(params);
};
exports.humanlayer = humanlayer;
class HumanLayer {
constructor(params) {
this.internal = new humanlayer_1.HumanLayer(params);
}
_requireApproval(...args) {
return this.internal.requireApproval(...args);
}
requireApproval(toolInput) {
const toolName = Object.keys(toolInput)[0];
const toolObject = toolInput[toolName];
const execute = async (args, options) => {
const approvalResult = await this.internal.fetchHumanApproval({
spec: {
fn: toolName,
kwargs: args,
}
});
if (approvalResult.approved) {
return toolObject.execute(args, options);
}
else {
return `User denied tool ${toolName} with comment: ${approvalResult.comment}`;
}
};
return (0, ai_1.tool)({
...toolObject,
execute,
});
}
humanAsTool(contactChannel) {
return (0, ai_1.tool)({
parameters: zod_1.z.object({
message: zod_1.z.string(),
}),
description: "contact a human", // todo read the human's details off the contact channel
execute: async (args) => {
return this.internal.humanAsTool(contactChannel)(args);
}
});
}
}
exports.HumanLayer = HumanLayer;
;