UNPKG

@autobe/agent

Version:

AI backend server code generator

395 lines 16.1 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.orchestrateAnalyzeReviewer = void 0; const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport.js")); const core_1 = require("@agentica/core"); const typia_1 = __importDefault(require("typia")); const assertSchemaModel_1 = require("../../context/assertSchemaModel"); const enforceToolCall_1 = require("../../utils/enforceToolCall"); const transformAnalyzeReviewerHistories_1 = require("./transformAnalyzeReviewerHistories"); const orchestrateAnalyzeReviewer = (ctx, input) => __awaiter(void 0, void 0, void 0, function* () { const fnCalled = { value: { type: "reject", value: "reviewer is not working because of unknown reason.", }, }; const controller = createController({ model: ctx.model, setResult: (result) => { fnCalled.value = result; }, }); const agent = new core_1.MicroAgentica({ model: ctx.model, vendor: ctx.vendor, controllers: [controller], config: Object.assign(Object.assign({}, ctx.config), { executor: { describe: null, } }), histories: [...(0, transformAnalyzeReviewerHistories_1.transformAnalyzeReviewerHistories)(input)], }); (0, enforceToolCall_1.enforceToolCall)(agent); const command = `proceed with the review of these files only.`; yield agent.conversate(command).finally(() => { const tokenUsage = agent.getTokenUsage(); ctx.usage().record(tokenUsage, ["analyze"]); }); return fnCalled.value; }); exports.orchestrateAnalyzeReviewer = orchestrateAnalyzeReviewer; function createController(props) { (0, assertSchemaModel_1.assertSchemaModel)(props.model); const application = collection[props.model]; return { protocol: "class", name: "Reviewer", application, execute: { accept: () => __awaiter(this, void 0, void 0, function* () { props.setResult({ type: "accept", }); return "OK"; }), reject: (input) => __awaiter(this, void 0, void 0, function* () { props.setResult({ type: "reject", value: input.reason, }); return "OK"; }), }, }; } const claude = { model: "claude", options: { reference: true, separate: null }, functions: [ { name: "reject", parameters: { type: "object", properties: { reason: { description: "The reason why you reject the document and the suggestion for the\nmodification. You can write the reason in detail.", type: "string" } }, required: [ "reason" ], additionalProperties: false, $defs: { OK: { description: "Represents the completion of an asynchronous operation", type: "object", properties: { "__@toStringTag@1672": { type: "string" } }, required: [ "__@toStringTag@1672" ] } } }, output: { oneOf: [ { "const": "OK" }, { $ref: "#/$defs/OK" } ] }, description: "If there is anything that needs to be modified, you can call it, This\nfunction is to reject the document for to try rewriting document with your\nadvice or suggestion.", validate: (() => { const _io0 = input => "string" === typeof input.reason; const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.reason || _report(_exceptionable, { path: _path + ".reason", expected: "string", value: input.reason })].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => { if (false === __is(input)) { errors = []; _report = __typia_transform__validateReport._validateReport(errors); ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, { path: _path + "", expected: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "accept", parameters: { type: "object", properties: {}, additionalProperties: false, required: [], $defs: { OK: { description: "Represents the completion of an asynchronous operation", type: "object", properties: { "__@toStringTag@1672": { type: "string" } }, required: [ "__@toStringTag@1672" ] } } }, output: { oneOf: [ { "const": "OK" }, { $ref: "#/$defs/OK" } ] }, description: "If you decide that you no longer need any reviews, call accept. This is a\nfunction to end document creation and review, and to respond to users.", validate: (() => { const __is = input => true; let errors; let _report; return input => { if (false === __is(input)) { errors = []; _report = __typia_transform__validateReport._validateReport(errors); ((input, _path, _exceptionable = true) => true)(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() } ] }; const collection = { chatgpt: { model: "chatgpt", options: { reference: true, strict: false, separate: null }, functions: [ { name: "reject", parameters: { type: "object", properties: { reason: { description: "The reason why you reject the document and the suggestion for the\nmodification. You can write the reason in detail.", type: "string" } }, required: [ "reason" ], additionalProperties: false, $defs: { OK: { description: "Represents the completion of an asynchronous operation", type: "object", properties: { "__@toStringTag@1672": { type: "string" } }, required: [ "__@toStringTag@1672" ] } } }, output: { anyOf: [ { $ref: "#/$defs/OK" }, { type: "string", "enum": [ "OK" ] } ] }, description: "If there is anything that needs to be modified, you can call it, This\nfunction is to reject the document for to try rewriting document with your\nadvice or suggestion.", validate: (() => { const _io0 = input => "string" === typeof input.reason; const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.reason || _report(_exceptionable, { path: _path + ".reason", expected: "string", value: input.reason })].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => { if (false === __is(input)) { errors = []; _report = __typia_transform__validateReport._validateReport(errors); ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, { path: _path + "", expected: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "accept", parameters: { type: "object", properties: {}, additionalProperties: false, required: [], $defs: { OK: { description: "Represents the completion of an asynchronous operation", type: "object", properties: { "__@toStringTag@1672": { type: "string" } }, required: [ "__@toStringTag@1672" ] } } }, output: { anyOf: [ { $ref: "#/$defs/OK" }, { type: "string", "enum": [ "OK" ] } ] }, description: "If you decide that you no longer need any reviews, call accept. This is a\nfunction to end document creation and review, and to respond to users.", validate: (() => { const __is = input => true; let errors; let _report; return input => { if (false === __is(input)) { errors = []; _report = __typia_transform__validateReport._validateReport(errors); ((input, _path, _exceptionable = true) => true)(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() } ] }, claude, llama: claude, deepseek: claude, "3.1": claude, }; //# sourceMappingURL=orchestrateAnalyzeReviewer.js.map