UNPKG

agentlang

Version:

The easiest way to build the most reliable AI agents - enterprise-grade teams of AI agents that collaborate with each other and humans

298 lines 9.51 kB
export const PathAttributeName = '__path__'; export const PathAttributeNameQuery = '__path__?'; export const ParentAttributeName = '__parent__'; export const DeletedFlagAttributeName = '__is_deleted__'; export function isPathAttribute(n) { return n.startsWith(PathAttributeName); } function asUnauthMessage(obj) { if (typeof obj == 'string') { return obj; } else { return `User not authorised to perform '${obj.opr}' on ${obj.entity}`; } } export class UnauthorisedError extends Error { constructor(message, options) { super(message ? asUnauthMessage(message) : 'User not authorised to perform this operation', options); } } export class BadRequestError extends Error { constructor(message, options) { super(message ? asUnauthMessage(message) : 'BadRequest', options); } } export class UserNotFoundError extends Error { constructor(message, options) { super(message || 'User not found', options); } } export class UserNotConfirmedError extends Error { constructor(message, options) { super(message || 'User account is not confirmed. Please check your email for verification code.', options); } } export class PasswordResetRequiredError extends Error { constructor(message, options) { super(message || 'Password reset is required for this account', options); } } export class TooManyRequestsError extends Error { constructor(message, options) { super(message || 'Too many requests. Please try again later.', options); } } export class InvalidParameterError extends Error { constructor(message, options) { super(message || 'Invalid parameters provided', options); } } export class ExpiredCodeError extends Error { constructor(message, options) { super(message || 'The verification code has expired. Please request a new one.', options); } } export class CodeMismatchError extends Error { constructor(message, options) { super(message || 'The verification code is incorrect. Please try again.', options); } } export let FetchModuleFn = undefined; export function setModuleFnFetcher(f) { FetchModuleFn = f; } export let SetSubscription = undefined; export function setSubscriptionFn(f) { SetSubscription = f; } export const ForceReadPermFlag = 'f-r-f'; export const FlowSuspensionTag = `--`; export var SubGraphType; (function (SubGraphType) { SubGraphType[SubGraphType["EVENT"] = 0] = "EVENT"; SubGraphType[SubGraphType["IF"] = 1] = "IF"; SubGraphType[SubGraphType["FOR_EACH"] = 2] = "FOR_EACH"; SubGraphType[SubGraphType["DELETE"] = 3] = "DELETE"; SubGraphType[SubGraphType["PURGE"] = 4] = "PURGE"; SubGraphType[SubGraphType["RETURN"] = 5] = "RETURN"; SubGraphType[SubGraphType["AGENT"] = 6] = "AGENT"; SubGraphType[SubGraphType["NONE"] = 7] = "NONE"; })(SubGraphType || (SubGraphType = {})); export class ExecGraphNode { constructor(statement, subGraphIndex = -1, subGraphType = SubGraphType.NONE) { var _a; this.code = statement; this.codeStr = (_a = this.code.$cstNode) === null || _a === void 0 ? void 0 : _a.text; this.subGraphType = subGraphType; this.subGraphIndex = subGraphIndex; } asObject() { const r = { code: this.codeStr }; if (this.subGraphType != SubGraphType.NONE) { r.type = SubGraphType[this.subGraphType]; } return r; } } export class ExecGraph { static isEmpty(g) { return Object.is(ExecGraph.Empty, g); } constructor() { this.parentGraph = undefined; this.hasAgentsFlag = false; this.loopBody = false; this.rootNodes = new Array(); this.subGraphs = new Array(); } pushNode(node) { this.rootNodes.push(node); return this; } pushSubGraph(execGraph) { execGraph.parentGraph = this; this.subGraphs.push(execGraph); return this; } getSubGraphsLength() { return this.subGraphs.length; } getLastSubGraphIndex() { return this.subGraphs.length - 1; } fetchSubGraphAt(index) { if (index < 0 || index >= this.subGraphs.length) { throw new Error(`Invalid sub-graph index: ${index}`); } return this.subGraphs[index]; } fetchForEachBodySubGraph() { return this.fetchSubGraphAt(this.subGraphs.length - 1); } fetchIfConsequentSubGraph() { if (this.subGraphs.length >= 2) { return this.fetchSubGraphAt(this.subGraphs.length - 2); } else { return this.fetchSubGraphAt(this.subGraphs.length - 1); } } fetchIfAlternativeSubGraph() { if (this.subGraphs.length >= 2) { return this.fetchSubGraphAt(this.subGraphs.length - 1); } else { return undefined; } } getRootNodes() { return this.rootNodes; } setActiveModuleName(moduleName) { if (moduleName) this.activeModuleName = moduleName; return this; } getActiveModuleName() { return this.activeModuleName; } getParentGraph() { return this.parentGraph; } setEventName(eventName) { if (eventName !== undefined) { this.eventName = eventName; } return this; } getEventName() { return this.eventName; } setHasAgents(flag) { this.hasAgentsFlag = flag; if (this.parentGraph) { this.parentGraph.setHasAgents(flag); } return this; } hasAgents() { return this.hasAgentsFlag; } canCache() { return !this.hasAgentsFlag; } setIsLoopBody() { this.loopBody = true; return this; } isLoopBody() { return this.loopBody; } asObject() { const nodeObjs = new Array(); this.rootNodes.forEach((node) => { var _a; const n = node.asObject(); if (node.subGraphIndex >= 0) { const g = this.subGraphs[node.subGraphIndex]; const gobj = g.asObject(); if (node.subGraphType == SubGraphType.FOR_EACH) { const stmt = node.code; n.var = (_a = stmt.pattern.forEach) === null || _a === void 0 ? void 0 : _a.var; n.source = gobj; n.body = g.fetchForEachBodySubGraph().asObject(); } else if (node.subGraphType == SubGraphType.IF) { n.condition = gobj; n.body = g.fetchIfConsequentSubGraph().asObject(); const a = g.fetchIfAlternativeSubGraph(); if (a) { n.else = a.asObject(); } } else { n.subGraph = gobj; } } nodeObjs.push(n); }); return nodeObjs; } } ExecGraph.Empty = new ExecGraph(); export class ExecGraphWalker { constructor(execGraph) { this.offset = 0; this.rootNodes = execGraph.getRootNodes(); this.maxOffset = this.rootNodes.length; } hasNext() { return this.offset < this.maxOffset; } nextNode() { if (this.offset < this.maxOffset) { return this.rootNodes[this.offset++]; } throw new Error('End of execution-graph'); } currentNode() { if (this.offset > 0) { return this.rootNodes[this.offset - 1]; } else { return this.rootNodes[0]; } } reset() { this.offset = 0; return this; } } var RuntimeModeTag; (function (RuntimeModeTag) { RuntimeModeTag[RuntimeModeTag["DEV"] = 0] = "DEV"; RuntimeModeTag[RuntimeModeTag["PROD"] = 1] = "PROD"; RuntimeModeTag[RuntimeModeTag["INIT_SCHEMA"] = 2] = "INIT_SCHEMA"; RuntimeModeTag[RuntimeModeTag["RUN_MIGRATION"] = 3] = "RUN_MIGRATION"; RuntimeModeTag[RuntimeModeTag["UNDO_MIGRATION"] = 4] = "UNDO_MIGRATION"; RuntimeModeTag[RuntimeModeTag["GENERATE_MIGRATION"] = 5] = "GENERATE_MIGRATION"; })(RuntimeModeTag || (RuntimeModeTag = {})); let RuntimeMode = RuntimeModeTag.DEV; export function setRuntimeMode_dev() { RuntimeMode = RuntimeModeTag.DEV; } export function setRuntimeMode_prod() { RuntimeMode = RuntimeModeTag.PROD; } export function setRuntimeMode_init_schema() { RuntimeMode = RuntimeModeTag.INIT_SCHEMA; } export function setRuntimeMode_migration() { RuntimeMode = RuntimeModeTag.RUN_MIGRATION; } export function setRuntimeMode_undo_migration() { RuntimeMode = RuntimeModeTag.UNDO_MIGRATION; } export function setRuntimeMode_generate_migration() { RuntimeMode = RuntimeModeTag.GENERATE_MIGRATION; } export function isRuntimeMode_dev() { return RuntimeMode === RuntimeModeTag.DEV; } export function isRuntimeMode_prod() { return RuntimeMode === RuntimeModeTag.PROD; } export function isRuntimeMode_init_schema() { return RuntimeMode === RuntimeModeTag.INIT_SCHEMA; } export function isRuntimeMode_migration() { return RuntimeMode === RuntimeModeTag.RUN_MIGRATION; } export function isRuntimeMode_generate_migration() { return RuntimeMode === RuntimeModeTag.GENERATE_MIGRATION; } export function isRuntimeMode_undo_migration() { return RuntimeMode === RuntimeModeTag.UNDO_MIGRATION; } //# sourceMappingURL=defs.js.map