@happyvertical/smrt-agents 0.45.0 → 0.45.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -131,7 +131,7 @@ AgentConfig = __decorateClass([TenantScoped({ mode: "optional" }), smrt({
131
131
  "delete"
132
132
  ] },
133
133
  mcp: { include: ["list", "get"] },
134
- cli: true
134
+ cli: { skipApiCheck: true }
135
135
  })], AgentConfig);
136
136
  var AgentConfigCollection = class extends SmrtCollection {
137
137
  static _itemClass = AgentConfig;
@@ -232,4 +232,4 @@ async function executeAsPrincipal(options, fn) {
232
232
  //#endregion
233
233
  export { getAgentClassName as a, instanceScopedSubscriber as c, AgentConfigCollection as i, executeAsPrincipal as n, getAgentTypeAliases as o, AgentConfig as r, getAgentTypeName as s, PrincipalToolNotAllowedError as t };
234
234
 
235
- //# sourceMappingURL=execute-as-principal-DltxRqN2.js.map
235
+ //# sourceMappingURL=execute-as-principal-DIyBp1oE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-as-principal-DIyBp1oE.js","names":["tenantId"],"sources":["../../src/identity.ts","../../src/config.ts","../../src/execute-as-principal.ts"],"sourcesContent":["import { getClassName, ObjectRegistry } from '@happyvertical/smrt-core';\n\n/**\n * Return the canonical agent type identifier for storage and dispatch routing.\n *\n * Uses the registry's qualified name when available and falls back to the input\n * name for dynamically defined or unregistered classes.\n */\nexport function getAgentTypeName(name: string): string {\n const registered = ObjectRegistry.getClass(name);\n return registered?.qualifiedName || registered?.name || name;\n}\n\n/**\n * Return the human-readable class name for UI and logs.\n */\nexport function getAgentClassName(name: string): string {\n const registered = ObjectRegistry.getClass(name);\n return registered?.name || getClassName(name);\n}\n\n/**\n * Return all meaningful aliases for an agent type.\n *\n * The qualified name is first so persistence lookups prefer canonical rows,\n * while the simple class name keeps legacy rows discoverable during migration.\n */\nexport function getAgentTypeAliases(name: string): string[] {\n return Array.from(\n new Set([getAgentTypeName(name), getAgentClassName(name)].filter(Boolean)),\n );\n}\n\n/**\n * Compose a per-instance dispatch subscriber identity from an agent type and an\n * optional instance key (#1890).\n *\n * Multiple durable instances of one agent class each need their own subscriber\n * name so their dispatch subscriptions and pending dispatches never collide —\n * that is what keeps two instances from double-processing each other's work.\n *\n * Returns the bare `agentType` when `instanceKey` is nullish/empty, so a\n * **singleton** agent's subscriber is byte-for-byte unchanged (the N=1 default).\n * When a key is present the identity is `` `${agentType}#${instanceKey}` `` — a\n * stable, reversible composition (the type never contains `#`).\n */\nexport function instanceScopedSubscriber(\n agentType: string,\n instanceKey?: string | null,\n): string {\n return instanceKey ? `${agentType}#${instanceKey}` : agentType;\n}\n","/**\n * AgentConfig - Persistent configuration storage for agents\n *\n * This module provides database-backed configuration for agents,\n * enabling consuming apps to persist agent settings.\n *\n * @module\n */\n\nimport {\n field,\n type SmrtClassOptions,\n SmrtCollection,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport {\n queryGlobal,\n queryWithGlobals,\n TenantScoped,\n tenantId,\n} from '@happyvertical/smrt-tenancy';\nimport { getAgentTypeName } from './identity.js';\n\n/**\n * AgentConfig stores agent configuration in the database\n *\n * Each config record maps to a UI slot for an agent configuration owner:\n * - agentId: The durable config owner ID (persona ID for persona-backed\n * instances; Agent STI row ID for legacy/singleton instances)\n * - agentClass: The canonical agent type (qualified name when available)\n * - slotId: The configuration slot (e.g., 'sources', 'settings')\n * - configData: JSON object containing the configuration\n *\n * @example\n * ```typescript\n * // Save config for an agent slot\n * const config = new AgentConfig({\n * agentId: agent.id,\n * agentClass: 'Praeco',\n * slotId: 'sources',\n * configData: { scrapers: ['civicweb', 'govstack'] },\n * db: options.db\n * });\n * await config.initialize();\n * await config.save();\n * ```\n */\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: 'agent_configs',\n api: { include: ['list', 'get', 'create', 'update', 'delete'] },\n mcp: { include: ['list', 'get'] },\n cli: { skipApiCheck: true },\n})\nexport class AgentConfig extends SmrtObject {\n /**\n * Tenant ID for multi-tenant isolation\n * Nullable to support both tenant-scoped and global agent configs\n */\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n /**\n * Durable configuration owner ID.\n *\n * The database column retains the historical `agent_id` name for backward\n * compatibility. Persona-backed runtimes store their `AgentPersona.id` here;\n * legacy runtimes store the persisted Agent STI row id.\n */\n @field({ type: 'text' })\n agentId: string = '';\n\n /**\n * Canonical agent type for this config (qualified name when available)\n */\n @field({ type: 'text' })\n agentClass: string = '';\n\n /**\n * UI slot ID (e.g., 'sources', 'settings', 'reports')\n */\n @field({ type: 'text' })\n slotId: string = '';\n\n /**\n * Configuration data stored as JSON\n *\n * Sensitive (#1540) for backward compatibility with legacy blobs, so this is\n * excluded from generated API/MCP responses and rejected as a `where` filter\n * key. New settings schemas must keep credentials in a dedicated secrets\n * service rather than this field.\n */\n @field({ type: 'json', sensitive: true })\n configData: Record<string, unknown> = {};\n\n /**\n * Schema version for future migrations\n */\n @field({ type: 'integer' })\n schemaVersion: number = 1;\n\n /**\n * Load all configs for a specific agent\n *\n * @param agentId - Agent instance ID\n * @param options - Database options\n * @returns Map of slotId → configData\n */\n static async forAgent(\n agentId: string,\n options: SmrtClassOptions,\n ): Promise<Map<string, Record<string, unknown>>> {\n const configsByAgent = await AgentConfig.forAgents([agentId], options);\n return configsByAgent.get(agentId) ?? new Map();\n }\n\n /**\n * Load configs for multiple agents in a single query.\n *\n * @param agentIds - Agent instance IDs\n * @param options - Database options\n * @returns Map of agentId -> (slotId -> configData)\n */\n static async forAgents(\n agentIds: string[],\n options: SmrtClassOptions,\n ): Promise<Map<string, Map<string, Record<string, unknown>>>> {\n const configsByAgent = new Map<\n string,\n Map<string, Record<string, unknown>>\n >();\n if (agentIds.length === 0) {\n return configsByAgent;\n }\n\n const collection = await AgentConfigCollection.create(options);\n const configs = await collection.list({\n where: { 'agentId in': agentIds },\n });\n\n for (const config of configs) {\n if (!configsByAgent.has(config.agentId)) {\n configsByAgent.set(config.agentId, new Map());\n }\n configsByAgent.get(config.agentId)?.set(config.slotId, config.configData);\n }\n\n return configsByAgent;\n }\n\n /**\n * Load config for a specific agent and slot\n *\n * @param agentId - Agent instance ID\n * @param slotId - UI slot ID\n * @param options - Database options\n * @returns Config data or undefined if not found\n */\n static async forSlot(\n agentId: string,\n slotId: string,\n options: SmrtClassOptions,\n ): Promise<Record<string, unknown> | undefined> {\n const collection = await AgentConfigCollection.create(options);\n const configs = await collection.list({\n where: { agentId, slotId },\n limit: 1,\n });\n return configs[0]?.configData;\n }\n\n /**\n * Save or update config for an agent slot\n *\n * @param data - Config data including agentId, agentClass, slotId, configData\n * @param options - Database options\n * @returns Saved AgentConfig instance\n */\n static async saveSlot(\n data: {\n agentId: string;\n agentClass: string;\n slotId: string;\n configData: Record<string, unknown>;\n },\n options: SmrtClassOptions,\n ): Promise<AgentConfig> {\n const normalizedAgentClass = getAgentTypeName(data.agentClass);\n const collection = await AgentConfigCollection.create(options);\n\n // Check for existing config using list with where clause\n const existingConfigs = await collection.list({\n where: { agentId: data.agentId, slotId: data.slotId },\n limit: 1,\n });\n\n if (existingConfigs.length > 0) {\n // Update existing\n const existing = existingConfigs[0];\n existing.configData = data.configData;\n existing.agentClass = normalizedAgentClass;\n await existing.save();\n return existing;\n }\n\n // Create new\n const config = await collection.create({\n agentId: data.agentId,\n agentClass: normalizedAgentClass,\n slotId: data.slotId,\n configData: data.configData,\n slug: `${data.agentId}-${data.slotId}`,\n });\n await config.save();\n return config;\n }\n}\n\n/**\n * Collection for AgentConfig objects\n */\nexport class AgentConfigCollection extends SmrtCollection<AgentConfig> {\n static readonly _itemClass = AgentConfig;\n\n /**\n * Find all configs for a specific tenant\n * @param tenantId - Tenant ID to filter by\n * @returns Array of AgentConfig objects for the tenant\n */\n async findByTenant(tenantId: string): Promise<AgentConfig[]> {\n return this.list({ where: { tenantId } });\n }\n\n /**\n * Find all global configs (not associated with any tenant).\n *\n * Routes through the shared tenant-global helper so it does not throw under\n * an active tenant context (an explicit `tenant_id IS NULL` filter would be\n * flagged as an isolation violation). (#1600)\n *\n * @returns Array of global AgentConfig objects\n */\n async findGlobal(): Promise<AgentConfig[]> {\n return queryGlobal<AgentConfig>(this);\n }\n\n /**\n * Find configs for a tenant including global configs.\n *\n * Fails closed if an active tenant context requests a different tenant's\n * rows; the admin/system path keeps the cross-tenant capability. (#1600)\n *\n * @param tenantId - Tenant ID to include\n * @returns Array of AgentConfig objects for the tenant and global configs\n */\n async findWithGlobals(tenantId: string): Promise<AgentConfig[]> {\n return queryWithGlobals<AgentConfig>(\n this,\n tenantId,\n 'AgentConfig.findWithGlobals',\n );\n }\n}\n","/**\n * ExecuteAsPrincipal — run an agent's work AS its persona's bound user.\n *\n * This is deliberately NOT a new authorization layer. It reuses the framework's\n * existing principal-context machinery:\n *\n * - {@link withPrincipalPermissionContext} resolves the bound user's *live*\n * permission set (the standard {@link PermissionResolver} cascade) and\n * publishes `(smrt.user_id, smrt.tenant_id, smrt.permissions[])` onto the DB\n * session. With Postgres RLS enabled, the manifest-derived policies then bound\n * every query the agent makes per-`(table, action)` and per-tenant — through\n * any door (in-process \"side door\", REST, MCP), with no per-call re-checking.\n *\n * - Because RLS is Postgres-only and opt-in, the exec/tool seam must ALSO assert\n * the catalog permission for the `(collection, action)` when RLS is off\n * (SQLite/dev). {@link PrincipalRun.assertOperation} wraps\n * `assertOperationPermission` for exactly that, so the authority bound holds\n * on every adapter.\n *\n * The effective authority of an agent action is therefore:\n *\n * bound-user RBAC ∩ agent-class capability ceiling ∩ persona allowedTools\n *\n * where the RBAC half is enforced at the data layer (RLS) or the catalog seam\n * (`assertOperation`), and the tool half is enforced by\n * {@link PrincipalRun.assertToolAllowed} against `allowedTools` — which a\n * resolved persona has already intersected with the `TenantAgent` ceiling.\n *\n * Actions audit as on-behalf-of the originating user (see {@link PrincipalAuditEntry}).\n *\n * @packageDocumentation\n */\n\nimport { createLogger, type Logger } from '@happyvertical/logger';\nimport type { SmrtClassOptions } from '@happyvertical/smrt-core';\nimport {\n assertOperationPermission,\n type OperationPermissionCollectionInput,\n type OperationPermissionDecision,\n type PermissionResolver,\n type SessionPermissionRuntimeContext,\n withPrincipalPermissionContext,\n} from '@happyvertical/smrt-users';\n\n/**\n * The bound principal an agent runs as. A resolved persona structurally\n * satisfies this once its optional `runAsUserId` has been narrowed to a\n * concrete id — `allowedTools` on a `ResolvedPersona` is already the persona's\n * tools intersected with the `TenantAgent` capability ceiling.\n */\nexport interface PrincipalBinding {\n /** The user whose live permissions bound this execution. Required. */\n runAsUserId: string;\n /** Tenant the principal acts within. */\n tenantId: string | null;\n /**\n * The persona's tool allow-list (already capped by the agent-class ceiling).\n * This is a **fail-closed** whitelist, mirroring\n * `@happyvertical/smrt-chat`'s `AgentSession.isToolAllowed()` (S5 #1392): an\n * absent (`undefined`) or empty allow-list permits **NO** tools, never all of\n * them, so forgetting to pass it can only tighten authority. Resolved personas\n * always provide a concrete `string[]`.\n */\n allowedTools?: string[];\n /** Optional acting `Bot` profile id, recorded in the audit entry. */\n actsAsProfileId?: string | null;\n}\n\n/**\n * A single audit record describing an agent action performed by the bound\n * principal (`actorUserId`) on behalf of the originating user\n * (`onBehalfOfUserId`).\n */\nexport interface PrincipalAuditEntry {\n /** Action label, e.g. `'agent.run'`. */\n action: string;\n /** The persona's bound user the work ran as. */\n actorUserId: string;\n /** The user who triggered the agent, if known. */\n onBehalfOfUserId: string | null;\n /** Tenant the action ran within. */\n tenantId: string | null;\n /** Canonical agent class, when the caller supplies it. */\n agentClass?: string;\n /** Acting profile id, when the persona sets one. */\n actsAsProfileId?: string | null;\n /** Free-form additional context. */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Sink that records a {@link PrincipalAuditEntry}. Provide one to persist audit\n * rows (e.g. via `AuditLog.record`); when omitted, the entry is emitted as a\n * structured log line.\n */\nexport type PrincipalAuditSink = (\n entry: PrincipalAuditEntry,\n) => void | Promise<void>;\n\n/**\n * Options for {@link executeAsPrincipal}.\n */\nexport interface ExecuteAsPrincipalOptions extends SmrtClassOptions {\n /** The bound principal to run as. */\n principal: PrincipalBinding;\n /** The originating user the action is performed on behalf of (for audit). */\n onBehalfOfUserId?: string | null;\n /** Canonical agent class, recorded in the audit entry. */\n agentClass?: string;\n /** Audit action label. Defaults to `'agent.run'`. */\n action?: string;\n /** Extra audit metadata merged into the emitted entry. */\n auditMetadata?: Record<string, unknown>;\n /**\n * Pre-resolved permission slugs. When omitted, the principal's permissions\n * are resolved live so role changes reflect on the next execution.\n */\n permissions?: string[];\n /** Reuse an initialized resolver across executions. */\n resolver?: PermissionResolver;\n /** Opt into Postgres RLS transaction wrapping (defaults to package config). */\n postgresRls?: boolean;\n /**\n * Enter tenant context so tenant auto-filtering applies on every adapter.\n * Defaults to `true` whenever the principal has a tenant.\n */\n enterTenantContext?: boolean;\n /** Audit sink. Defaults to a structured log line. */\n audit?: PrincipalAuditSink;\n /** Logger used for the default audit sink. */\n logger?: Logger;\n}\n\n/**\n * Thrown when the persona attempts a tool outside its `allowedTools`.\n */\nexport class PrincipalToolNotAllowedError extends Error {\n readonly tool: string;\n readonly status = 403;\n\n constructor(tool: string) {\n super(`Tool '${tool}' is not permitted for this persona.`);\n this.name = 'PrincipalToolNotAllowedError';\n this.tool = tool;\n }\n}\n\n/**\n * The handle passed to the {@link executeAsPrincipal} body. Its\n * session-permission {@link context} is already published for the principal, so\n * data operations are bounded by RLS on Postgres. The assertions enforce the\n * remaining two authority dimensions.\n */\nexport interface PrincipalRun {\n /** The published session-permission runtime context for the principal. */\n context: SessionPermissionRuntimeContext;\n /** The principal's published (snapshot) permission slugs. */\n permissions: string[];\n /**\n * The effective, fail-closed tool allow-list — always a concrete array (an\n * absent binding allow-list normalizes to `[]`, i.e. no tools).\n */\n allowedTools: string[];\n /**\n * Whether `tool` is within the fail-closed allow-list. An empty allow-list,\n * or an empty/non-string tool name, permits nothing.\n */\n isToolAllowed(tool: string): boolean;\n /** Throw {@link PrincipalToolNotAllowedError} unless `tool` is allowed. */\n assertToolAllowed(tool: string): void;\n /**\n * Assert the principal holds the catalog permission for `(collection,\n * action)`, authorizing against the **published** principal set\n * (`context.permissionSet`) — the same snapshot the RLS session enforces — so\n * the bound is adapter-independent. This is the door-agnostic teeth for the\n * RLS-off adapters; under Postgres RLS it is a redundant (but harmless)\n * second gate. Throws `OperationPermissionError` on denial.\n */\n assertOperation(\n collection: OperationPermissionCollectionInput,\n action: string,\n extraOptions?: SmrtClassOptions,\n ): Promise<OperationPermissionDecision>;\n}\n\nasync function emitAudit(\n entry: PrincipalAuditEntry,\n audit: PrincipalAuditSink | undefined,\n logger: Logger | undefined,\n): Promise<void> {\n if (audit) {\n await audit(entry);\n return;\n }\n const log = logger ?? createLogger({ level: 'info' });\n log.info('agent action executed on behalf of originating user', {\n ...entry,\n });\n}\n\n/**\n * Run `fn` AS the persona's bound principal.\n *\n * Resolves the bound user's live permissions, publishes them onto the DB\n * session (so Postgres RLS bounds every query per-`(table, action)`), emits an\n * on-behalf-of audit entry, and hands `fn` a {@link PrincipalRun} whose\n * assertions enforce the persona tool ceiling and the RLS-off catalog gate.\n *\n * @example\n * ```typescript\n * await executeAsPrincipal(\n * {\n * db,\n * principal: {\n * runAsUserId: persona.runAsUserId,\n * tenantId: persona.tenantId,\n * allowedTools: persona.allowedTools,\n * },\n * onBehalfOfUserId: triggeringUserId,\n * agentClass: persona.agentClass,\n * },\n * async (run) => {\n * run.assertToolAllowed('articles.publish');\n * await run.assertOperation('articles', 'update');\n * await agent.run();\n * },\n * );\n * ```\n */\nexport async function executeAsPrincipal<T>(\n options: ExecuteAsPrincipalOptions,\n fn: (run: PrincipalRun) => Promise<T>,\n): Promise<T> {\n const {\n principal,\n onBehalfOfUserId = null,\n agentClass,\n action = 'agent.run',\n auditMetadata,\n permissions,\n resolver,\n postgresRls,\n enterTenantContext,\n audit,\n logger,\n ...smrtOptions\n } = options;\n\n const { runAsUserId, tenantId, actsAsProfileId = null } = principal;\n\n // Fail-closed tool allow-list (mirrors chat's AgentSession, S5 #1392): an\n // absent or non-array binding allow-list normalizes to `[]` — no tools — so a\n // missing ceiling can only tighten authority, never open it up.\n const toolWhitelist = Array.isArray(principal.allowedTools)\n ? principal.allowedTools\n : [];\n const isToolAllowed = (tool: string): boolean =>\n typeof tool === 'string' && tool.length > 0 && toolWhitelist.includes(tool);\n\n await emitAudit(\n {\n action,\n actorUserId: runAsUserId,\n onBehalfOfUserId,\n tenantId,\n agentClass,\n actsAsProfileId,\n metadata: auditMetadata,\n },\n audit,\n logger,\n );\n\n return withPrincipalPermissionContext(\n {\n ...smrtOptions,\n userId: runAsUserId,\n tenantId,\n permissions,\n resolver,\n postgresRls,\n enterTenantContext: enterTenantContext ?? tenantId !== null,\n },\n async (context) => {\n const run: PrincipalRun = {\n context,\n permissions: context.permissions,\n allowedTools: toolWhitelist,\n isToolAllowed,\n assertToolAllowed(tool: string): void {\n if (!isToolAllowed(tool)) {\n throw new PrincipalToolNotAllowedError(tool);\n }\n },\n async assertOperation(\n collection: OperationPermissionCollectionInput,\n operationAction: string,\n extraOptions?: SmrtClassOptions,\n ): Promise<OperationPermissionDecision> {\n return assertOperationPermission({\n ...smrtOptions,\n ...extraOptions,\n collection,\n action: operationAction,\n // Authorize against the PUBLISHED principal set (the same snapshot\n // Postgres RLS enforces for this context), not a fresh live\n // re-resolve — keeps the RLS-off gate adapter-independent.\n permissionSet: context.permissionSet,\n });\n },\n };\n return fn(run);\n },\n );\n}\n"],"mappings":"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"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as getAgentClassName, c as instanceScopedSubscriber, i as AgentConfigCollection, n as executeAsPrincipal, o as getAgentTypeAliases, r as AgentConfig, s as getAgentTypeName, t as PrincipalToolNotAllowedError } from "./chunks/execute-as-principal-DltxRqN2.js";
1
+ import { a as getAgentClassName, c as instanceScopedSubscriber, i as AgentConfigCollection, n as executeAsPrincipal, o as getAgentTypeAliases, r as AgentConfig, s as getAgentTypeName, t as PrincipalToolNotAllowedError } from "./chunks/execute-as-principal-DIyBp1oE.js";
2
2
  import { AgentUIRegistry, createUIRegistry } from "./ui.js";
3
3
  import { DEFAULT_DATA_QUERY_RESULT_BYTES, DataQueryValidationError, LearningMemory, MAX_DATA_QUERY_FILTERS, MAX_DATA_QUERY_REQUEST_BYTES, ObjectRegistry, SmrtCollection, SmrtObject, createDataQueryFingerprint, createDispatchBus, field, getClassConfigResolvers, getConfigResolver, isLazyConfigSentinel, listConfigResolvers, normalizeDataQueryRequest, normalizeDataQueryResult, normalizeDataQuerySchema, registerConfigResolver, resetConfigResolvers, resolveDispatchTenantScope, resolveLazyConfig, smrt, unregisterConfigResolver } from "@happyvertical/smrt-core";
4
4
  import { createLogger } from "@happyvertical/logger";
@@ -10,7 +10,7 @@ import { createHash, randomUUID } from "node:crypto";
10
10
  import { createServerStepEvaluator, preflightPlaybook } from "@happyvertical/smrt-playbooks";
11
11
  import { applyReportExport, applyReportRefresh, buildReportAdapterDescriptor, buildReportDrilldownQuery, createReportExportRequest, createReportExportSnapshot, previewReportExport, previewReportRefresh, queryReportMaterializedRows } from "@happyvertical/smrt-reports";
12
12
  //#region src/__smrt-register__.ts
13
- ObjectRegistry.registerPackageManifest(JSON.parse("{\"version\":\"1.0.0\",\"timestamp\":0,\"packageName\":\"@happyvertical/smrt-agents\",\"packageVersion\":\"0.45.0\",\"objects\":{\"@happyvertical/smrt-agents:Agent\":{\"name\":\"agent\",\"className\":\"Agent\",\"qualifiedName\":\"@happyvertical/smrt-agents:Agent\",\"collection\":\"agents\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/agent.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{\"created_at\":{\"type\":\"datetime\",\"required\":false},\"updated_at\":{\"type\":\"datetime\",\"required\":false},\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"status\":{\"type\":\"text\",\"required\":false,\"default\":\"idle\"}},\"methods\":{\"getInstanceKey\":{\"name\":\"getInstanceKey\",\"async\":false,\"parameters\":[],\"returnType\":\"string | null\",\"isStatic\":false,\"isPublic\":true},\"getConfigOwnerId\":{\"name\":\"getConfigOwnerId\",\"async\":false,\"parameters\":[{\"name\":\"slotId\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"string | null\",\"isStatic\":false,\"isPublic\":true},\"getDispatchSubscriber\":{\"name\":\"getDispatchSubscriber\",\"async\":false,\"parameters\":[],\"returnType\":\"string\",\"isStatic\":false,\"isPublic\":true},\"getUISlots\":{\"name\":\"getUISlots\",\"async\":false,\"parameters\":[],\"returnType\":\"AgentUISlots\",\"isStatic\":false,\"isPublic\":true},\"loadConfigs\":{\"name\":\"loadConfigs\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<Map<string, Record<string>>>\",\"isStatic\":false,\"isPublic\":true},\"saveSlotConfig\":{\"name\":\"saveSlotConfig\",\"async\":true,\"parameters\":[{\"name\":\"slotId\",\"type\":\"string\",\"optional\":false},{\"name\":\"data\",\"type\":\"Record<string>\",\"optional\":false}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"getMergedConfig\":{\"name\":\"getMergedConfig\",\"async\":true,\"parameters\":[{\"name\":\"slotId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Record<string>>\",\"isStatic\":false,\"isPublic\":true},\"exportConfig\":{\"name\":\"exportConfig\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":true}],\"returnType\":\"Promise<Record<string>>\",\"isStatic\":false,\"isPublic\":true},\"getDispatch\":{\"name\":\"getDispatch\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<DispatchBus>\",\"isStatic\":false,\"isPublic\":true},\"handleDispatch\":{\"name\":\"handleDispatch\",\"async\":true,\"parameters\":[{\"name\":\"_payload\",\"type\":\"any\",\"optional\":false},{\"name\":\"_metadata\",\"type\":\"DispatchMetadata\",\"optional\":false}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"processDispatches\":{\"name\":\"processDispatches\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<number>\",\"isStatic\":false,\"isPublic\":true},\"getLearningMemory\":{\"name\":\"getLearningMemory\",\"async\":false,\"parameters\":[],\"returnType\":\"LearningMemory | null\",\"isStatic\":false,\"isPublic\":true},\"initialize\":{\"name\":\"initialize\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise\",\"isStatic\":false,\"isPublic\":true},\"validate\":{\"name\":\"validate\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"shutdown\":{\"name\":\"shutdown\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"execute\":{\"name\":\"execute\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"interesting\":{\"name\":\"interesting\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<InterestResult[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"cli\":false,\"api\":false,\"mcp\":false,\"tableStrategy\":\"sti\",\"tenantScoped\":{\"mode\":\"optional\"},\"conflictColumns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"]},\"extends\":\"SmrtObject\",\"exportName\":\"Agent\",\"collectionExportName\":\"AgentCollection\",\"staticProperties\":{\"uiSlots\":{},\"adminRoutes\":[],\"signalSubscriptions\":[]},\"schema\":{\"tableName\":\"agents\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"agents\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"status\\\" TEXT DEFAULT 'idle'\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false},\"status\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"idle\"}},\"indexes\":[{\"name\":\"agents_slug_context_meta_type_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"],\"unique\":true},{\"name\":\"agents_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"agents_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"dde8777b\"}},\"@happyvertical/smrt-agents:AgentConfig\":{\"name\":\"agentconfig\",\"className\":\"AgentConfig\",\"qualifiedName\":\"@happyvertical/smrt-agents:AgentConfig\",\"collection\":\"agentconfigs\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/config.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"agentId\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"agentClass\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"slotId\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"configData\":{\"type\":\"json\",\"required\":false,\"_meta\":{\"sensitive\":true},\"sensitive\":true},\"schemaVersion\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}}},\"methods\":{\"forAgent\":{\"name\":\"forAgent\",\"async\":true,\"parameters\":[{\"name\":\"agentId\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"SmrtClassOptions\",\"optional\":false}],\"returnType\":\"Promise<Map<string, Record<string>>>\",\"isStatic\":true,\"isPublic\":true},\"forAgents\":{\"name\":\"forAgents\",\"async\":true,\"parameters\":[{\"name\":\"agentIds\",\"type\":\"string[]\",\"optional\":false},{\"name\":\"options\",\"type\":\"SmrtClassOptions\",\"optional\":false}],\"returnType\":\"Promise<Map<string, Map<string, Record<string>>>>\",\"isStatic\":true,\"isPublic\":true},\"forSlot\":{\"name\":\"forSlot\",\"async\":true,\"parameters\":[{\"name\":\"agentId\",\"type\":\"string\",\"optional\":false},{\"name\":\"slotId\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"SmrtClassOptions\",\"optional\":false}],\"returnType\":\"Promise<Record<string> | undefined>\",\"isStatic\":true,\"isPublic\":true},\"saveSlot\":{\"name\":\"saveSlot\",\"async\":true,\"parameters\":[{\"name\":\"data\",\"type\":\"object\",\"optional\":false},{\"name\":\"options\",\"type\":\"SmrtClassOptions\",\"optional\":false}],\"returnType\":\"Promise<AgentConfig>\",\"isStatic\":true,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"agent_configs\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"mcp\":{\"include\":[\"list\",\"get\"]},\"cli\":true,\"tenantScoped\":{\"mode\":\"optional\"},\"conflictColumns\":[\"tenant_id\",\"slug\",\"context\"]},\"extends\":\"SmrtObject\",\"exportName\":\"AgentConfig\",\"collectionExportName\":\"AgentConfigCollection\",\"schema\":{\"tableName\":\"agent_configs\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"agent_configs\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"agent_id\\\" TEXT,\\n \\\"agent_class\\\" TEXT,\\n \\\"slot_id\\\" TEXT,\\n \\\"config_data\\\" JSON,\\n \\\"schema_version\\\" INTEGER\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"agent_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"agent_class\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"slot_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"config_data\":{\"type\":\"JSON\",\"notNull\":false,\"unique\":false},\"schema_version\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"agent_configs_slug_context_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\"],\"unique\":true},{\"name\":\"agent_configs_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"25c6ac4c\"}},\"@happyvertical/smrt-agents:AgentConfigCollection\":{\"name\":\"agentconfigcollection\",\"className\":\"AgentConfigCollection\",\"qualifiedName\":\"@happyvertical/smrt-agents:AgentConfigCollection\",\"collection\":\"agentconfigs\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/config.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{},\"methods\":{\"findByTenant\":{\"name\":\"findByTenant\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<AgentConfig[]>\",\"isStatic\":false,\"isPublic\":true},\"findGlobal\":{\"name\":\"findGlobal\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<AgentConfig[]>\",\"isStatic\":false,\"isPublic\":true},\"findWithGlobals\":{\"name\":\"findWithGlobals\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<AgentConfig[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"agent_configs\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"AgentConfig\",\"exportName\":\"AgentConfigCollection\",\"collectionExportName\":\"AgentConfigCollectionCollection\",\"schema\":{\"tableName\":\"agent_configs\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"agent_configs\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"}},\"indexes\":[{\"name\":\"agent_configs_slug_context_idx\",\"columns\":[\"slug\",\"context\"],\"unique\":true},{\"name\":\"agent_configs_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"9162bcd3\"}},\"@happyvertical/smrt-agents:AgentSchedule\":{\"name\":\"agentschedule\",\"className\":\"AgentSchedule\",\"qualifiedName\":\"@happyvertical/smrt-agents:AgentSchedule\",\"collection\":\"agentschedules\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/schedule.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"agentType\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"agentId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"nullable\":true}},\"agentConfig\":{\"type\":\"json\",\"required\":false,\"_meta\":{\"sqlType\":\"TEXT\",\"sensitive\":true},\"sensitive\":true},\"cron\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"timezone\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"enabled\":{\"type\":\"boolean\",\"required\":false,\"_meta\":{}},\"status\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"lastRun\":{\"type\":\"datetime\",\"required\":false,\"_meta\":{\"nullable\":true}},\"nextRun\":{\"type\":\"datetime\",\"required\":false,\"_meta\":{\"nullable\":true}},\"lastStatus\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"nullable\":true}},\"lastError\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"nullable\":true}},\"runCount\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"successCount\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"failureCount\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"maxConcurrent\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"runningCount\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"timeout\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"method\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"methodArgs\":{\"type\":\"json\",\"required\":false,\"_meta\":{\"sqlType\":\"TEXT\"}}},\"methods\":{\"enable\":{\"name\":\"enable\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"disable\":{\"name\":\"disable\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"pause\":{\"name\":\"pause\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"resume\":{\"name\":\"resume\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"calculateNextRun\":{\"name\":\"calculateNextRun\",\"async\":false,\"parameters\":[],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"getDescription\":{\"name\":\"getDescription\",\"async\":false,\"parameters\":[],\"returnType\":\"string\",\"isStatic\":false,\"isPublic\":true},\"beforeSave\":{\"name\":\"beforeSave\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"_smrt_agent_schedules\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"cli\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\",\"enable\",\"disable\"],\"skipApiCheck\":true},\"mcp\":{\"include\":[\"list\",\"get\"]},\"indexes\":[{\"name\":\"_smrt_agent_schedules_enabled_status_next_run_idx\",\"columns\":[\"enabled\",\"status\",\"nextRun\"]}],\"tenantScoped\":{\"mode\":\"optional\"},\"conflictColumns\":[\"tenant_id\",\"slug\",\"context\"]},\"extends\":\"SmrtObject\",\"exportName\":\"AgentSchedule\",\"collectionExportName\":\"AgentScheduleCollection\",\"schema\":{\"tableName\":\"_smrt_agent_schedules\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"_smrt_agent_schedules\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"agent_type\\\" TEXT,\\n \\\"agent_id\\\" TEXT,\\n \\\"agent_config\\\" TEXT,\\n \\\"cron\\\" TEXT,\\n \\\"timezone\\\" TEXT,\\n \\\"enabled\\\" BOOLEAN,\\n \\\"status\\\" TEXT,\\n \\\"last_run\\\" TIMESTAMP,\\n \\\"next_run\\\" TIMESTAMP,\\n \\\"last_status\\\" TEXT,\\n \\\"last_error\\\" TEXT,\\n \\\"run_count\\\" INTEGER,\\n \\\"success_count\\\" INTEGER,\\n \\\"failure_count\\\" INTEGER,\\n \\\"max_concurrent\\\" INTEGER,\\n \\\"running_count\\\" INTEGER,\\n \\\"timeout\\\" INTEGER,\\n \\\"method\\\" TEXT,\\n \\\"method_args\\\" TEXT\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"agent_type\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"agent_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"agent_config\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"cron\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"timezone\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"enabled\":{\"type\":\"BOOLEAN\",\"notNull\":false,\"unique\":false},\"status\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"last_run\":{\"type\":\"TIMESTAMP\",\"notNull\":false,\"unique\":false},\"next_run\":{\"type\":\"TIMESTAMP\",\"notNull\":false,\"unique\":false},\"last_status\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"last_error\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"run_count\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"success_count\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"failure_count\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"max_concurrent\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"running_count\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"timeout\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"method\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"method_args\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"_smrt_agent_schedules_slug_context_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\"],\"unique\":true},{\"name\":\"_smrt_agent_schedules_enabled_status_next_run_idx\",\"columns\":[\"enabled\",\"status\",\"next_run\"]},{\"name\":\"_smrt_agent_schedules_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"c21a1f29\"}},\"@happyvertical/smrt-agents:AgentScheduleCollection\":{\"name\":\"agentschedulecollection\",\"className\":\"AgentScheduleCollection\",\"qualifiedName\":\"@happyvertical/smrt-agents:AgentScheduleCollection\",\"collection\":\"agentschedules\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/schedule.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{},\"methods\":{\"findByTenant\":{\"name\":\"findByTenant\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<AgentSchedule[]>\",\"isStatic\":false,\"isPublic\":true},\"findGlobal\":{\"name\":\"findGlobal\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<AgentSchedule[]>\",\"isStatic\":false,\"isPublic\":true},\"findWithGlobals\":{\"name\":\"findWithGlobals\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<AgentSchedule[]>\",\"isStatic\":false,\"isPublic\":true},\"listByStatus\":{\"name\":\"listByStatus\",\"async\":true,\"parameters\":[{\"name\":\"status\",\"type\":\"ScheduleStatus | ScheduleStatus[]\",\"optional\":false},{\"name\":\"options\",\"type\":\"object\",\"optional\":true}],\"returnType\":\"Promise<AgentSchedule[]>\",\"isStatic\":false,\"isPublic\":true},\"listByAgentType\":{\"name\":\"listByAgentType\",\"async\":true,\"parameters\":[{\"name\":\"agentType\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"object\",\"optional\":true}],\"returnType\":\"Promise<AgentSchedule[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"_smrt_agent_schedules\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"AgentSchedule\",\"exportName\":\"AgentScheduleCollection\",\"collectionExportName\":\"AgentScheduleCollectionCollection\",\"schema\":{\"tableName\":\"_smrt_agent_schedules\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"_smrt_agent_schedules\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"}},\"indexes\":[{\"name\":\"_smrt_agent_schedules_slug_context_idx\",\"columns\":[\"slug\",\"context\"],\"unique\":true},{\"name\":\"_smrt_agent_schedules_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"d45601b0\"}},\"@happyvertical/smrt-agents:TenantAgent\":{\"name\":\"tenantagent\",\"className\":\"TenantAgent\",\"qualifiedName\":\"@happyvertical/smrt-agents:TenantAgent\",\"collection\":\"tenantagents\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/tenant-agent.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":true,\"_meta\":{\"sqlType\":\"UUID\",\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":true,\"autoPopulate\":true,\"nullable\":false,\"mode\":\"required\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"agentClass\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"status\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"permissions\":{\"type\":\"json\",\"required\":false,\"_meta\":{\"nullable\":true}},\"config\":{\"type\":\"json\",\"required\":false,\"_meta\":{\"nullable\":true,\"sensitive\":true},\"sensitive\":true}},\"methods\":{},\"decoratorConfig\":{\"tableName\":\"tenant_agents\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"cli\":{\"include\":[\"list\",\"get\"]},\"mcp\":{\"include\":[\"list\",\"get\"]},\"conflictColumns\":[\"tenant_id\",\"agent_class\"],\"tenantScoped\":{\"mode\":\"required\"}},\"extends\":\"SmrtObject\",\"exportName\":\"TenantAgent\",\"collectionExportName\":\"TenantAgentCollection\",\"validationRules\":[],\"schema\":{\"tableName\":\"tenant_agents\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"tenant_agents\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID NOT NULL,\\n \\\"agent_class\\\" TEXT,\\n \\\"status\\\" TEXT,\\n \\\"permissions\\\" JSON,\\n \\\"config\\\" JSON\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":true,\"unique\":false},\"agent_class\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"status\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"permissions\":{\"type\":\"JSON\",\"notNull\":false,\"unique\":false},\"config\":{\"type\":\"JSON\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"tenant_agents_tenant_id_agent_class_idx\",\"columns\":[\"tenant_id\",\"agent_class\"],\"unique\":true},{\"name\":\"tenant_agents_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"tenant_agents_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"9892a054\"}},\"@happyvertical/smrt-agents:TenantAgentCollection\":{\"name\":\"tenantagentcollection\",\"className\":\"TenantAgentCollection\",\"qualifiedName\":\"@happyvertical/smrt-agents:TenantAgentCollection\",\"collection\":\"tenantagents\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/tenant-agent.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{},\"methods\":{\"resolveForTenant\":{\"name\":\"resolveForTenant\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"getAncestorIds\",\"type\":\"Function\",\"optional\":false},{\"name\":\"manifests\",\"type\":\"Map<string, AgentManifestInfo>\",\"optional\":true}],\"returnType\":\"Promise<ResolvedAgentAvailability[]>\",\"isStatic\":false,\"isPublic\":true},\"enableAgent\":{\"name\":\"enableAgent\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"agentClass\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<TenantAgent>\",\"isStatic\":false,\"isPublic\":true},\"disableAgent\":{\"name\":\"disableAgent\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"agentClass\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<TenantAgent>\",\"isStatic\":false,\"isPublic\":true},\"clearOverride\":{\"name\":\"clearOverride\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"agentClass\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"setPermissions\":{\"name\":\"setPermissions\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"agentClass\",\"type\":\"string\",\"optional\":false},{\"name\":\"permissions\",\"type\":\"Record<string, boolean>\",\"optional\":false}],\"returnType\":\"Promise<TenantAgent>\",\"isStatic\":false,\"isPublic\":true},\"findByTenantAndClass\":{\"name\":\"findByTenantAndClass\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"agentClass\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<TenantAgent | null>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"tenant_agents\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"TenantAgent\",\"exportName\":\"TenantAgentCollection\",\"collectionExportName\":\"TenantAgentCollectionCollection\",\"schema\":{\"tableName\":\"tenant_agents\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"tenant_agents\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"}},\"indexes\":[{\"name\":\"tenant_agents_slug_context_idx\",\"columns\":[\"slug\",\"context\"],\"unique\":true},{\"name\":\"tenant_agents_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"fbe7be99\"}}},\"moduleType\":\"smrt\",\"smrtDependencies\":[\"@happyvertical/smrt-core\",\"@happyvertical/smrt-playbooks\",\"@happyvertical/smrt-reports\",\"@happyvertical/smrt-secrets\",\"@happyvertical/smrt-tenancy\",\"@happyvertical/smrt-users\"]}"));
13
+ ObjectRegistry.registerPackageManifest(JSON.parse("{\"version\":\"1.0.0\",\"timestamp\":0,\"packageName\":\"@happyvertical/smrt-agents\",\"packageVersion\":\"0.45.2\",\"objects\":{\"@happyvertical/smrt-agents:Agent\":{\"name\":\"agent\",\"className\":\"Agent\",\"qualifiedName\":\"@happyvertical/smrt-agents:Agent\",\"collection\":\"agents\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/agent.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{\"created_at\":{\"type\":\"datetime\",\"required\":false},\"updated_at\":{\"type\":\"datetime\",\"required\":false},\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"status\":{\"type\":\"text\",\"required\":false,\"default\":\"idle\"}},\"methods\":{\"getInstanceKey\":{\"name\":\"getInstanceKey\",\"async\":false,\"parameters\":[],\"returnType\":\"string | null\",\"isStatic\":false,\"isPublic\":true},\"getConfigOwnerId\":{\"name\":\"getConfigOwnerId\",\"async\":false,\"parameters\":[{\"name\":\"slotId\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"string | null\",\"isStatic\":false,\"isPublic\":true},\"getDispatchSubscriber\":{\"name\":\"getDispatchSubscriber\",\"async\":false,\"parameters\":[],\"returnType\":\"string\",\"isStatic\":false,\"isPublic\":true},\"getUISlots\":{\"name\":\"getUISlots\",\"async\":false,\"parameters\":[],\"returnType\":\"AgentUISlots\",\"isStatic\":false,\"isPublic\":true},\"loadConfigs\":{\"name\":\"loadConfigs\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<Map<string, Record<string>>>\",\"isStatic\":false,\"isPublic\":true},\"saveSlotConfig\":{\"name\":\"saveSlotConfig\",\"async\":true,\"parameters\":[{\"name\":\"slotId\",\"type\":\"string\",\"optional\":false},{\"name\":\"data\",\"type\":\"Record<string>\",\"optional\":false}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"getMergedConfig\":{\"name\":\"getMergedConfig\",\"async\":true,\"parameters\":[{\"name\":\"slotId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Record<string>>\",\"isStatic\":false,\"isPublic\":true},\"exportConfig\":{\"name\":\"exportConfig\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":true}],\"returnType\":\"Promise<Record<string>>\",\"isStatic\":false,\"isPublic\":true},\"getDispatch\":{\"name\":\"getDispatch\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<DispatchBus>\",\"isStatic\":false,\"isPublic\":true},\"handleDispatch\":{\"name\":\"handleDispatch\",\"async\":true,\"parameters\":[{\"name\":\"_payload\",\"type\":\"any\",\"optional\":false},{\"name\":\"_metadata\",\"type\":\"DispatchMetadata\",\"optional\":false}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"processDispatches\":{\"name\":\"processDispatches\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<number>\",\"isStatic\":false,\"isPublic\":true},\"getLearningMemory\":{\"name\":\"getLearningMemory\",\"async\":false,\"parameters\":[],\"returnType\":\"LearningMemory | null\",\"isStatic\":false,\"isPublic\":true},\"initialize\":{\"name\":\"initialize\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise\",\"isStatic\":false,\"isPublic\":true},\"validate\":{\"name\":\"validate\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"shutdown\":{\"name\":\"shutdown\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"execute\":{\"name\":\"execute\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"interesting\":{\"name\":\"interesting\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<InterestResult[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"cli\":false,\"api\":false,\"mcp\":false,\"tableStrategy\":\"sti\",\"tenantScoped\":{\"mode\":\"optional\"},\"conflictColumns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"]},\"extends\":\"SmrtObject\",\"exportName\":\"Agent\",\"collectionExportName\":\"AgentCollection\",\"staticProperties\":{\"uiSlots\":{},\"adminRoutes\":[],\"signalSubscriptions\":[]},\"schema\":{\"tableName\":\"agents\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"agents\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"status\\\" TEXT DEFAULT 'idle'\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false},\"status\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"idle\"}},\"indexes\":[{\"name\":\"agents_slug_context_meta_type_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"],\"unique\":true},{\"name\":\"agents_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"agents_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"dde8777b\"}},\"@happyvertical/smrt-agents:AgentConfig\":{\"name\":\"agentconfig\",\"className\":\"AgentConfig\",\"qualifiedName\":\"@happyvertical/smrt-agents:AgentConfig\",\"collection\":\"agentconfigs\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/config.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"agentId\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"agentClass\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"slotId\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"configData\":{\"type\":\"json\",\"required\":false,\"_meta\":{\"sensitive\":true},\"sensitive\":true},\"schemaVersion\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}}},\"methods\":{\"forAgent\":{\"name\":\"forAgent\",\"async\":true,\"parameters\":[{\"name\":\"agentId\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"SmrtClassOptions\",\"optional\":false}],\"returnType\":\"Promise<Map<string, Record<string>>>\",\"isStatic\":true,\"isPublic\":true},\"forAgents\":{\"name\":\"forAgents\",\"async\":true,\"parameters\":[{\"name\":\"agentIds\",\"type\":\"string[]\",\"optional\":false},{\"name\":\"options\",\"type\":\"SmrtClassOptions\",\"optional\":false}],\"returnType\":\"Promise<Map<string, Map<string, Record<string>>>>\",\"isStatic\":true,\"isPublic\":true},\"forSlot\":{\"name\":\"forSlot\",\"async\":true,\"parameters\":[{\"name\":\"agentId\",\"type\":\"string\",\"optional\":false},{\"name\":\"slotId\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"SmrtClassOptions\",\"optional\":false}],\"returnType\":\"Promise<Record<string> | undefined>\",\"isStatic\":true,\"isPublic\":true},\"saveSlot\":{\"name\":\"saveSlot\",\"async\":true,\"parameters\":[{\"name\":\"data\",\"type\":\"object\",\"optional\":false},{\"name\":\"options\",\"type\":\"SmrtClassOptions\",\"optional\":false}],\"returnType\":\"Promise<AgentConfig>\",\"isStatic\":true,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"agent_configs\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"mcp\":{\"include\":[\"list\",\"get\"]},\"cli\":{\"skipApiCheck\":true},\"tenantScoped\":{\"mode\":\"optional\"},\"conflictColumns\":[\"tenant_id\",\"slug\",\"context\"]},\"extends\":\"SmrtObject\",\"exportName\":\"AgentConfig\",\"collectionExportName\":\"AgentConfigCollection\",\"schema\":{\"tableName\":\"agent_configs\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"agent_configs\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"agent_id\\\" TEXT,\\n \\\"agent_class\\\" TEXT,\\n \\\"slot_id\\\" TEXT,\\n \\\"config_data\\\" JSON,\\n \\\"schema_version\\\" INTEGER\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"agent_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"agent_class\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"slot_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"config_data\":{\"type\":\"JSON\",\"notNull\":false,\"unique\":false},\"schema_version\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"agent_configs_slug_context_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\"],\"unique\":true},{\"name\":\"agent_configs_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"25c6ac4c\"}},\"@happyvertical/smrt-agents:AgentConfigCollection\":{\"name\":\"agentconfigcollection\",\"className\":\"AgentConfigCollection\",\"qualifiedName\":\"@happyvertical/smrt-agents:AgentConfigCollection\",\"collection\":\"agentconfigs\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/config.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{},\"methods\":{\"findByTenant\":{\"name\":\"findByTenant\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<AgentConfig[]>\",\"isStatic\":false,\"isPublic\":true},\"findGlobal\":{\"name\":\"findGlobal\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<AgentConfig[]>\",\"isStatic\":false,\"isPublic\":true},\"findWithGlobals\":{\"name\":\"findWithGlobals\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<AgentConfig[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"agent_configs\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"AgentConfig\",\"exportName\":\"AgentConfigCollection\",\"collectionExportName\":\"AgentConfigCollectionCollection\",\"schema\":{\"tableName\":\"agent_configs\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"agent_configs\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"}},\"indexes\":[{\"name\":\"agent_configs_slug_context_idx\",\"columns\":[\"slug\",\"context\"],\"unique\":true},{\"name\":\"agent_configs_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"9162bcd3\"}},\"@happyvertical/smrt-agents:AgentSchedule\":{\"name\":\"agentschedule\",\"className\":\"AgentSchedule\",\"qualifiedName\":\"@happyvertical/smrt-agents:AgentSchedule\",\"collection\":\"agentschedules\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/schedule.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"agentType\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"agentId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"nullable\":true}},\"agentConfig\":{\"type\":\"json\",\"required\":false,\"_meta\":{\"sqlType\":\"TEXT\",\"sensitive\":true},\"sensitive\":true},\"cron\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"timezone\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"enabled\":{\"type\":\"boolean\",\"required\":false,\"_meta\":{}},\"status\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"lastRun\":{\"type\":\"datetime\",\"required\":false,\"_meta\":{\"nullable\":true}},\"nextRun\":{\"type\":\"datetime\",\"required\":false,\"_meta\":{\"nullable\":true}},\"lastStatus\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"nullable\":true}},\"lastError\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"nullable\":true}},\"runCount\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"successCount\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"failureCount\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"maxConcurrent\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"runningCount\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"timeout\":{\"type\":\"integer\",\"required\":false,\"_meta\":{}},\"method\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"methodArgs\":{\"type\":\"json\",\"required\":false,\"_meta\":{\"sqlType\":\"TEXT\"}}},\"methods\":{\"enable\":{\"name\":\"enable\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"disable\":{\"name\":\"disable\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"pause\":{\"name\":\"pause\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"resume\":{\"name\":\"resume\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"calculateNextRun\":{\"name\":\"calculateNextRun\",\"async\":false,\"parameters\":[],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"getDescription\":{\"name\":\"getDescription\",\"async\":false,\"parameters\":[],\"returnType\":\"string\",\"isStatic\":false,\"isPublic\":true},\"beforeSave\":{\"name\":\"beforeSave\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"_smrt_agent_schedules\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"cli\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\",\"enable\",\"disable\"],\"skipApiCheck\":true},\"mcp\":{\"include\":[\"list\",\"get\"]},\"indexes\":[{\"name\":\"_smrt_agent_schedules_enabled_status_next_run_idx\",\"columns\":[\"enabled\",\"status\",\"nextRun\"]}],\"tenantScoped\":{\"mode\":\"optional\"},\"conflictColumns\":[\"tenant_id\",\"slug\",\"context\"]},\"extends\":\"SmrtObject\",\"exportName\":\"AgentSchedule\",\"collectionExportName\":\"AgentScheduleCollection\",\"schema\":{\"tableName\":\"_smrt_agent_schedules\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"_smrt_agent_schedules\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"agent_type\\\" TEXT,\\n \\\"agent_id\\\" TEXT,\\n \\\"agent_config\\\" TEXT,\\n \\\"cron\\\" TEXT,\\n \\\"timezone\\\" TEXT,\\n \\\"enabled\\\" BOOLEAN,\\n \\\"status\\\" TEXT,\\n \\\"last_run\\\" TIMESTAMP,\\n \\\"next_run\\\" TIMESTAMP,\\n \\\"last_status\\\" TEXT,\\n \\\"last_error\\\" TEXT,\\n \\\"run_count\\\" INTEGER,\\n \\\"success_count\\\" INTEGER,\\n \\\"failure_count\\\" INTEGER,\\n \\\"max_concurrent\\\" INTEGER,\\n \\\"running_count\\\" INTEGER,\\n \\\"timeout\\\" INTEGER,\\n \\\"method\\\" TEXT,\\n \\\"method_args\\\" TEXT\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"agent_type\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"agent_id\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"agent_config\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"cron\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"timezone\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"enabled\":{\"type\":\"BOOLEAN\",\"notNull\":false,\"unique\":false},\"status\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"last_run\":{\"type\":\"TIMESTAMP\",\"notNull\":false,\"unique\":false},\"next_run\":{\"type\":\"TIMESTAMP\",\"notNull\":false,\"unique\":false},\"last_status\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"last_error\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"run_count\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"success_count\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"failure_count\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"max_concurrent\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"running_count\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"timeout\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false},\"method\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"method_args\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"_smrt_agent_schedules_slug_context_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\"],\"unique\":true},{\"name\":\"_smrt_agent_schedules_enabled_status_next_run_idx\",\"columns\":[\"enabled\",\"status\",\"next_run\"]},{\"name\":\"_smrt_agent_schedules_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"c21a1f29\"}},\"@happyvertical/smrt-agents:AgentScheduleCollection\":{\"name\":\"agentschedulecollection\",\"className\":\"AgentScheduleCollection\",\"qualifiedName\":\"@happyvertical/smrt-agents:AgentScheduleCollection\",\"collection\":\"agentschedules\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/schedule.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{},\"methods\":{\"findByTenant\":{\"name\":\"findByTenant\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<AgentSchedule[]>\",\"isStatic\":false,\"isPublic\":true},\"findGlobal\":{\"name\":\"findGlobal\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<AgentSchedule[]>\",\"isStatic\":false,\"isPublic\":true},\"findWithGlobals\":{\"name\":\"findWithGlobals\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<AgentSchedule[]>\",\"isStatic\":false,\"isPublic\":true},\"listByStatus\":{\"name\":\"listByStatus\",\"async\":true,\"parameters\":[{\"name\":\"status\",\"type\":\"ScheduleStatus | ScheduleStatus[]\",\"optional\":false},{\"name\":\"options\",\"type\":\"object\",\"optional\":true}],\"returnType\":\"Promise<AgentSchedule[]>\",\"isStatic\":false,\"isPublic\":true},\"listByAgentType\":{\"name\":\"listByAgentType\",\"async\":true,\"parameters\":[{\"name\":\"agentType\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"object\",\"optional\":true}],\"returnType\":\"Promise<AgentSchedule[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"_smrt_agent_schedules\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"AgentSchedule\",\"exportName\":\"AgentScheduleCollection\",\"collectionExportName\":\"AgentScheduleCollectionCollection\",\"schema\":{\"tableName\":\"_smrt_agent_schedules\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"_smrt_agent_schedules\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"}},\"indexes\":[{\"name\":\"_smrt_agent_schedules_slug_context_idx\",\"columns\":[\"slug\",\"context\"],\"unique\":true},{\"name\":\"_smrt_agent_schedules_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"d45601b0\"}},\"@happyvertical/smrt-agents:TenantAgent\":{\"name\":\"tenantagent\",\"className\":\"TenantAgent\",\"qualifiedName\":\"@happyvertical/smrt-agents:TenantAgent\",\"collection\":\"tenantagents\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/tenant-agent.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":true,\"_meta\":{\"sqlType\":\"UUID\",\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":true,\"autoPopulate\":true,\"nullable\":false,\"mode\":\"required\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"agentClass\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"status\":{\"type\":\"text\",\"required\":false,\"_meta\":{}},\"permissions\":{\"type\":\"json\",\"required\":false,\"_meta\":{\"nullable\":true}},\"config\":{\"type\":\"json\",\"required\":false,\"_meta\":{\"nullable\":true,\"sensitive\":true},\"sensitive\":true}},\"methods\":{},\"decoratorConfig\":{\"tableName\":\"tenant_agents\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"cli\":{\"include\":[\"list\",\"get\"]},\"mcp\":{\"include\":[\"list\",\"get\"]},\"conflictColumns\":[\"tenant_id\",\"agent_class\"],\"tenantScoped\":{\"mode\":\"required\"}},\"extends\":\"SmrtObject\",\"exportName\":\"TenantAgent\",\"collectionExportName\":\"TenantAgentCollection\",\"validationRules\":[],\"schema\":{\"tableName\":\"tenant_agents\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"tenant_agents\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID NOT NULL,\\n \\\"agent_class\\\" TEXT,\\n \\\"status\\\" TEXT,\\n \\\"permissions\\\" JSON,\\n \\\"config\\\" JSON\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":true,\"unique\":false},\"agent_class\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"status\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"permissions\":{\"type\":\"JSON\",\"notNull\":false,\"unique\":false},\"config\":{\"type\":\"JSON\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"tenant_agents_tenant_id_agent_class_idx\",\"columns\":[\"tenant_id\",\"agent_class\"],\"unique\":true},{\"name\":\"tenant_agents_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"tenant_agents_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"9892a054\"}},\"@happyvertical/smrt-agents:TenantAgentCollection\":{\"name\":\"tenantagentcollection\",\"className\":\"TenantAgentCollection\",\"qualifiedName\":\"@happyvertical/smrt-agents:TenantAgentCollection\",\"collection\":\"tenantagents\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/agents/src/tenant-agent.ts\",\"packageName\":\"@happyvertical/smrt-agents\",\"fields\":{},\"methods\":{\"resolveForTenant\":{\"name\":\"resolveForTenant\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"getAncestorIds\",\"type\":\"Function\",\"optional\":false},{\"name\":\"manifests\",\"type\":\"Map<string, AgentManifestInfo>\",\"optional\":true}],\"returnType\":\"Promise<ResolvedAgentAvailability[]>\",\"isStatic\":false,\"isPublic\":true},\"enableAgent\":{\"name\":\"enableAgent\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"agentClass\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<TenantAgent>\",\"isStatic\":false,\"isPublic\":true},\"disableAgent\":{\"name\":\"disableAgent\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"agentClass\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<TenantAgent>\",\"isStatic\":false,\"isPublic\":true},\"clearOverride\":{\"name\":\"clearOverride\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"agentClass\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"setPermissions\":{\"name\":\"setPermissions\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"agentClass\",\"type\":\"string\",\"optional\":false},{\"name\":\"permissions\",\"type\":\"Record<string, boolean>\",\"optional\":false}],\"returnType\":\"Promise<TenantAgent>\",\"isStatic\":false,\"isPublic\":true},\"findByTenantAndClass\":{\"name\":\"findByTenantAndClass\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false},{\"name\":\"agentClass\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<TenantAgent | null>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"tenant_agents\"},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"TenantAgent\",\"exportName\":\"TenantAgentCollection\",\"collectionExportName\":\"TenantAgentCollectionCollection\",\"schema\":{\"tableName\":\"tenant_agents\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"tenant_agents\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"}},\"indexes\":[{\"name\":\"tenant_agents_slug_context_idx\",\"columns\":[\"slug\",\"context\"],\"unique\":true},{\"name\":\"tenant_agents_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"fbe7be99\"}}},\"moduleType\":\"smrt\",\"smrtDependencies\":[\"@happyvertical/smrt-core\",\"@happyvertical/smrt-playbooks\",\"@happyvertical/smrt-reports\",\"@happyvertical/smrt-secrets\",\"@happyvertical/smrt-tenancy\",\"@happyvertical/smrt-users\"]}"));
14
14
  //#endregion
15
15
  //#region src/ai-config.ts
16
16
  var DEFAULT_SECRET_NAMES = {
@@ -2,7 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "timestamp": 0,
4
4
  "packageName": "@happyvertical/smrt-agents",
5
- "packageVersion": "0.45.0",
5
+ "packageVersion": "0.45.2",
6
6
  "objects": {
7
7
  "@happyvertical/smrt-agents:Agent": {
8
8
  "name": "agent",
@@ -476,7 +476,9 @@
476
476
  "get"
477
477
  ]
478
478
  },
479
- "cli": true,
479
+ "cli": {
480
+ "skipApiCheck": true
481
+ },
480
482
  "tenantScoped": {
481
483
  "mode": "optional"
482
484
  },
package/dist/server.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as executeAsPrincipal, r as AgentConfig } from "./chunks/execute-as-principal-DltxRqN2.js";
1
+ import { n as executeAsPrincipal, r as AgentConfig } from "./chunks/execute-as-principal-DIyBp1oE.js";
2
2
  import { i as loadManifestsFromPackages, n as extractAgentPackagesFromConfig, r as loadManifestsFromConfig, t as extractAgentManifest } from "./chunks/manifest-utils-CtMyFQDx.js";
3
3
  import { sanitizeConfig } from "@happyvertical/smrt-config";
4
4
  import { createHash, randomBytes } from "node:crypto";
@@ -3,12 +3,12 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-agents",
6
- "packageVersion": "0.45.0",
6
+ "packageVersion": "0.45.2",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "0ed3aac25a2ffd0b47b7f873ad635cd219e804a84d6914971f4285c93a64dd78",
11
- "packageJson": "4513cb3d97c5dc7e5f4ab30f7badfff4dccdbd3f6597104b7192b2626d184f80",
10
+ "manifest": "f17879334e7b027b7049b8787971f26508ed76f37ab1eb128d6af4572e5ae9e9",
11
+ "packageJson": "3fe8942248fd415dbd30c591a787276370a80e6aa2db3c908e42771cd798541e",
12
12
  "agents": "14f3cf361f649432fe871988e13c8382fed295d2bd16f47a4502433322a5d8ed"
13
13
  },
14
14
  "exports": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-agents",
3
- "version": "0.45.0",
3
+ "version": "0.45.2",
4
4
  "smrtJsdoc": "strict",
5
5
  "type": "module",
6
6
  "smrtRawPrimitives": "strict",
@@ -60,15 +60,15 @@
60
60
  "@happyvertical/ai": "^0.89.4",
61
61
  "@happyvertical/files": "^0.89.4",
62
62
  "@happyvertical/utils": "^0.89.4",
63
- "@happyvertical/smrt-config": "0.45.0",
64
- "@happyvertical/smrt-core": "0.45.0",
65
- "@happyvertical/smrt-reports": "0.45.0",
66
- "@happyvertical/smrt-playbooks": "0.45.0",
67
- "@happyvertical/smrt-secrets": "0.45.0",
68
- "@happyvertical/smrt-tenancy": "0.45.0",
69
- "@happyvertical/smrt-types": "0.45.0",
70
- "@happyvertical/smrt-users": "0.45.0",
71
- "@happyvertical/smrt-ui": "0.45.0"
63
+ "@happyvertical/smrt-reports": "0.45.2",
64
+ "@happyvertical/smrt-secrets": "0.45.2",
65
+ "@happyvertical/smrt-config": "0.45.2",
66
+ "@happyvertical/smrt-playbooks": "0.45.2",
67
+ "@happyvertical/smrt-tenancy": "0.45.2",
68
+ "@happyvertical/smrt-core": "0.45.2",
69
+ "@happyvertical/smrt-ui": "0.45.2",
70
+ "@happyvertical/smrt-types": "0.45.2",
71
+ "@happyvertical/smrt-users": "0.45.2"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@happyvertical/logger": "^0.89.4",
@@ -85,7 +85,7 @@
85
85
  "typescript": "5.9.3",
86
86
  "vite": "8.1.4",
87
87
  "vitest": "4.1.10",
88
- "@happyvertical/smrt-vitest": "0.45.0"
88
+ "@happyvertical/smrt-vitest": "0.45.2"
89
89
  },
90
90
  "keywords": [
91
91
  "agent",
@@ -1 +0,0 @@
1
- {"version":3,"file":"execute-as-principal-DltxRqN2.js","names":["tenantId"],"sources":["../../src/identity.ts","../../src/config.ts","../../src/execute-as-principal.ts"],"sourcesContent":["import { getClassName, ObjectRegistry } from '@happyvertical/smrt-core';\n\n/**\n * Return the canonical agent type identifier for storage and dispatch routing.\n *\n * Uses the registry's qualified name when available and falls back to the input\n * name for dynamically defined or unregistered classes.\n */\nexport function getAgentTypeName(name: string): string {\n const registered = ObjectRegistry.getClass(name);\n return registered?.qualifiedName || registered?.name || name;\n}\n\n/**\n * Return the human-readable class name for UI and logs.\n */\nexport function getAgentClassName(name: string): string {\n const registered = ObjectRegistry.getClass(name);\n return registered?.name || getClassName(name);\n}\n\n/**\n * Return all meaningful aliases for an agent type.\n *\n * The qualified name is first so persistence lookups prefer canonical rows,\n * while the simple class name keeps legacy rows discoverable during migration.\n */\nexport function getAgentTypeAliases(name: string): string[] {\n return Array.from(\n new Set([getAgentTypeName(name), getAgentClassName(name)].filter(Boolean)),\n );\n}\n\n/**\n * Compose a per-instance dispatch subscriber identity from an agent type and an\n * optional instance key (#1890).\n *\n * Multiple durable instances of one agent class each need their own subscriber\n * name so their dispatch subscriptions and pending dispatches never collide —\n * that is what keeps two instances from double-processing each other's work.\n *\n * Returns the bare `agentType` when `instanceKey` is nullish/empty, so a\n * **singleton** agent's subscriber is byte-for-byte unchanged (the N=1 default).\n * When a key is present the identity is `` `${agentType}#${instanceKey}` `` — a\n * stable, reversible composition (the type never contains `#`).\n */\nexport function instanceScopedSubscriber(\n agentType: string,\n instanceKey?: string | null,\n): string {\n return instanceKey ? `${agentType}#${instanceKey}` : agentType;\n}\n","/**\n * AgentConfig - Persistent configuration storage for agents\n *\n * This module provides database-backed configuration for agents,\n * enabling consuming apps to persist agent settings.\n *\n * @module\n */\n\nimport {\n field,\n type SmrtClassOptions,\n SmrtCollection,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport {\n queryGlobal,\n queryWithGlobals,\n TenantScoped,\n tenantId,\n} from '@happyvertical/smrt-tenancy';\nimport { getAgentTypeName } from './identity.js';\n\n/**\n * AgentConfig stores agent configuration in the database\n *\n * Each config record maps to a UI slot for an agent configuration owner:\n * - agentId: The durable config owner ID (persona ID for persona-backed\n * instances; Agent STI row ID for legacy/singleton instances)\n * - agentClass: The canonical agent type (qualified name when available)\n * - slotId: The configuration slot (e.g., 'sources', 'settings')\n * - configData: JSON object containing the configuration\n *\n * @example\n * ```typescript\n * // Save config for an agent slot\n * const config = new AgentConfig({\n * agentId: agent.id,\n * agentClass: 'Praeco',\n * slotId: 'sources',\n * configData: { scrapers: ['civicweb', 'govstack'] },\n * db: options.db\n * });\n * await config.initialize();\n * await config.save();\n * ```\n */\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: 'agent_configs',\n api: { include: ['list', 'get', 'create', 'update', 'delete'] },\n mcp: { include: ['list', 'get'] },\n cli: true,\n})\nexport class AgentConfig extends SmrtObject {\n /**\n * Tenant ID for multi-tenant isolation\n * Nullable to support both tenant-scoped and global agent configs\n */\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n /**\n * Durable configuration owner ID.\n *\n * The database column retains the historical `agent_id` name for backward\n * compatibility. Persona-backed runtimes store their `AgentPersona.id` here;\n * legacy runtimes store the persisted Agent STI row id.\n */\n @field({ type: 'text' })\n agentId: string = '';\n\n /**\n * Canonical agent type for this config (qualified name when available)\n */\n @field({ type: 'text' })\n agentClass: string = '';\n\n /**\n * UI slot ID (e.g., 'sources', 'settings', 'reports')\n */\n @field({ type: 'text' })\n slotId: string = '';\n\n /**\n * Configuration data stored as JSON\n *\n * Sensitive (#1540) for backward compatibility with legacy blobs, so this is\n * excluded from generated API/MCP responses and rejected as a `where` filter\n * key. New settings schemas must keep credentials in a dedicated secrets\n * service rather than this field.\n */\n @field({ type: 'json', sensitive: true })\n configData: Record<string, unknown> = {};\n\n /**\n * Schema version for future migrations\n */\n @field({ type: 'integer' })\n schemaVersion: number = 1;\n\n /**\n * Load all configs for a specific agent\n *\n * @param agentId - Agent instance ID\n * @param options - Database options\n * @returns Map of slotId → configData\n */\n static async forAgent(\n agentId: string,\n options: SmrtClassOptions,\n ): Promise<Map<string, Record<string, unknown>>> {\n const configsByAgent = await AgentConfig.forAgents([agentId], options);\n return configsByAgent.get(agentId) ?? new Map();\n }\n\n /**\n * Load configs for multiple agents in a single query.\n *\n * @param agentIds - Agent instance IDs\n * @param options - Database options\n * @returns Map of agentId -> (slotId -> configData)\n */\n static async forAgents(\n agentIds: string[],\n options: SmrtClassOptions,\n ): Promise<Map<string, Map<string, Record<string, unknown>>>> {\n const configsByAgent = new Map<\n string,\n Map<string, Record<string, unknown>>\n >();\n if (agentIds.length === 0) {\n return configsByAgent;\n }\n\n const collection = await AgentConfigCollection.create(options);\n const configs = await collection.list({\n where: { 'agentId in': agentIds },\n });\n\n for (const config of configs) {\n if (!configsByAgent.has(config.agentId)) {\n configsByAgent.set(config.agentId, new Map());\n }\n configsByAgent.get(config.agentId)?.set(config.slotId, config.configData);\n }\n\n return configsByAgent;\n }\n\n /**\n * Load config for a specific agent and slot\n *\n * @param agentId - Agent instance ID\n * @param slotId - UI slot ID\n * @param options - Database options\n * @returns Config data or undefined if not found\n */\n static async forSlot(\n agentId: string,\n slotId: string,\n options: SmrtClassOptions,\n ): Promise<Record<string, unknown> | undefined> {\n const collection = await AgentConfigCollection.create(options);\n const configs = await collection.list({\n where: { agentId, slotId },\n limit: 1,\n });\n return configs[0]?.configData;\n }\n\n /**\n * Save or update config for an agent slot\n *\n * @param data - Config data including agentId, agentClass, slotId, configData\n * @param options - Database options\n * @returns Saved AgentConfig instance\n */\n static async saveSlot(\n data: {\n agentId: string;\n agentClass: string;\n slotId: string;\n configData: Record<string, unknown>;\n },\n options: SmrtClassOptions,\n ): Promise<AgentConfig> {\n const normalizedAgentClass = getAgentTypeName(data.agentClass);\n const collection = await AgentConfigCollection.create(options);\n\n // Check for existing config using list with where clause\n const existingConfigs = await collection.list({\n where: { agentId: data.agentId, slotId: data.slotId },\n limit: 1,\n });\n\n if (existingConfigs.length > 0) {\n // Update existing\n const existing = existingConfigs[0];\n existing.configData = data.configData;\n existing.agentClass = normalizedAgentClass;\n await existing.save();\n return existing;\n }\n\n // Create new\n const config = await collection.create({\n agentId: data.agentId,\n agentClass: normalizedAgentClass,\n slotId: data.slotId,\n configData: data.configData,\n slug: `${data.agentId}-${data.slotId}`,\n });\n await config.save();\n return config;\n }\n}\n\n/**\n * Collection for AgentConfig objects\n */\nexport class AgentConfigCollection extends SmrtCollection<AgentConfig> {\n static readonly _itemClass = AgentConfig;\n\n /**\n * Find all configs for a specific tenant\n * @param tenantId - Tenant ID to filter by\n * @returns Array of AgentConfig objects for the tenant\n */\n async findByTenant(tenantId: string): Promise<AgentConfig[]> {\n return this.list({ where: { tenantId } });\n }\n\n /**\n * Find all global configs (not associated with any tenant).\n *\n * Routes through the shared tenant-global helper so it does not throw under\n * an active tenant context (an explicit `tenant_id IS NULL` filter would be\n * flagged as an isolation violation). (#1600)\n *\n * @returns Array of global AgentConfig objects\n */\n async findGlobal(): Promise<AgentConfig[]> {\n return queryGlobal<AgentConfig>(this);\n }\n\n /**\n * Find configs for a tenant including global configs.\n *\n * Fails closed if an active tenant context requests a different tenant's\n * rows; the admin/system path keeps the cross-tenant capability. (#1600)\n *\n * @param tenantId - Tenant ID to include\n * @returns Array of AgentConfig objects for the tenant and global configs\n */\n async findWithGlobals(tenantId: string): Promise<AgentConfig[]> {\n return queryWithGlobals<AgentConfig>(\n this,\n tenantId,\n 'AgentConfig.findWithGlobals',\n );\n }\n}\n","/**\n * ExecuteAsPrincipal — run an agent's work AS its persona's bound user.\n *\n * This is deliberately NOT a new authorization layer. It reuses the framework's\n * existing principal-context machinery:\n *\n * - {@link withPrincipalPermissionContext} resolves the bound user's *live*\n * permission set (the standard {@link PermissionResolver} cascade) and\n * publishes `(smrt.user_id, smrt.tenant_id, smrt.permissions[])` onto the DB\n * session. With Postgres RLS enabled, the manifest-derived policies then bound\n * every query the agent makes per-`(table, action)` and per-tenant — through\n * any door (in-process \"side door\", REST, MCP), with no per-call re-checking.\n *\n * - Because RLS is Postgres-only and opt-in, the exec/tool seam must ALSO assert\n * the catalog permission for the `(collection, action)` when RLS is off\n * (SQLite/dev). {@link PrincipalRun.assertOperation} wraps\n * `assertOperationPermission` for exactly that, so the authority bound holds\n * on every adapter.\n *\n * The effective authority of an agent action is therefore:\n *\n * bound-user RBAC ∩ agent-class capability ceiling ∩ persona allowedTools\n *\n * where the RBAC half is enforced at the data layer (RLS) or the catalog seam\n * (`assertOperation`), and the tool half is enforced by\n * {@link PrincipalRun.assertToolAllowed} against `allowedTools` — which a\n * resolved persona has already intersected with the `TenantAgent` ceiling.\n *\n * Actions audit as on-behalf-of the originating user (see {@link PrincipalAuditEntry}).\n *\n * @packageDocumentation\n */\n\nimport { createLogger, type Logger } from '@happyvertical/logger';\nimport type { SmrtClassOptions } from '@happyvertical/smrt-core';\nimport {\n assertOperationPermission,\n type OperationPermissionCollectionInput,\n type OperationPermissionDecision,\n type PermissionResolver,\n type SessionPermissionRuntimeContext,\n withPrincipalPermissionContext,\n} from '@happyvertical/smrt-users';\n\n/**\n * The bound principal an agent runs as. A resolved persona structurally\n * satisfies this once its optional `runAsUserId` has been narrowed to a\n * concrete id — `allowedTools` on a `ResolvedPersona` is already the persona's\n * tools intersected with the `TenantAgent` capability ceiling.\n */\nexport interface PrincipalBinding {\n /** The user whose live permissions bound this execution. Required. */\n runAsUserId: string;\n /** Tenant the principal acts within. */\n tenantId: string | null;\n /**\n * The persona's tool allow-list (already capped by the agent-class ceiling).\n * This is a **fail-closed** whitelist, mirroring\n * `@happyvertical/smrt-chat`'s `AgentSession.isToolAllowed()` (S5 #1392): an\n * absent (`undefined`) or empty allow-list permits **NO** tools, never all of\n * them, so forgetting to pass it can only tighten authority. Resolved personas\n * always provide a concrete `string[]`.\n */\n allowedTools?: string[];\n /** Optional acting `Bot` profile id, recorded in the audit entry. */\n actsAsProfileId?: string | null;\n}\n\n/**\n * A single audit record describing an agent action performed by the bound\n * principal (`actorUserId`) on behalf of the originating user\n * (`onBehalfOfUserId`).\n */\nexport interface PrincipalAuditEntry {\n /** Action label, e.g. `'agent.run'`. */\n action: string;\n /** The persona's bound user the work ran as. */\n actorUserId: string;\n /** The user who triggered the agent, if known. */\n onBehalfOfUserId: string | null;\n /** Tenant the action ran within. */\n tenantId: string | null;\n /** Canonical agent class, when the caller supplies it. */\n agentClass?: string;\n /** Acting profile id, when the persona sets one. */\n actsAsProfileId?: string | null;\n /** Free-form additional context. */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Sink that records a {@link PrincipalAuditEntry}. Provide one to persist audit\n * rows (e.g. via `AuditLog.record`); when omitted, the entry is emitted as a\n * structured log line.\n */\nexport type PrincipalAuditSink = (\n entry: PrincipalAuditEntry,\n) => void | Promise<void>;\n\n/**\n * Options for {@link executeAsPrincipal}.\n */\nexport interface ExecuteAsPrincipalOptions extends SmrtClassOptions {\n /** The bound principal to run as. */\n principal: PrincipalBinding;\n /** The originating user the action is performed on behalf of (for audit). */\n onBehalfOfUserId?: string | null;\n /** Canonical agent class, recorded in the audit entry. */\n agentClass?: string;\n /** Audit action label. Defaults to `'agent.run'`. */\n action?: string;\n /** Extra audit metadata merged into the emitted entry. */\n auditMetadata?: Record<string, unknown>;\n /**\n * Pre-resolved permission slugs. When omitted, the principal's permissions\n * are resolved live so role changes reflect on the next execution.\n */\n permissions?: string[];\n /** Reuse an initialized resolver across executions. */\n resolver?: PermissionResolver;\n /** Opt into Postgres RLS transaction wrapping (defaults to package config). */\n postgresRls?: boolean;\n /**\n * Enter tenant context so tenant auto-filtering applies on every adapter.\n * Defaults to `true` whenever the principal has a tenant.\n */\n enterTenantContext?: boolean;\n /** Audit sink. Defaults to a structured log line. */\n audit?: PrincipalAuditSink;\n /** Logger used for the default audit sink. */\n logger?: Logger;\n}\n\n/**\n * Thrown when the persona attempts a tool outside its `allowedTools`.\n */\nexport class PrincipalToolNotAllowedError extends Error {\n readonly tool: string;\n readonly status = 403;\n\n constructor(tool: string) {\n super(`Tool '${tool}' is not permitted for this persona.`);\n this.name = 'PrincipalToolNotAllowedError';\n this.tool = tool;\n }\n}\n\n/**\n * The handle passed to the {@link executeAsPrincipal} body. Its\n * session-permission {@link context} is already published for the principal, so\n * data operations are bounded by RLS on Postgres. The assertions enforce the\n * remaining two authority dimensions.\n */\nexport interface PrincipalRun {\n /** The published session-permission runtime context for the principal. */\n context: SessionPermissionRuntimeContext;\n /** The principal's published (snapshot) permission slugs. */\n permissions: string[];\n /**\n * The effective, fail-closed tool allow-list — always a concrete array (an\n * absent binding allow-list normalizes to `[]`, i.e. no tools).\n */\n allowedTools: string[];\n /**\n * Whether `tool` is within the fail-closed allow-list. An empty allow-list,\n * or an empty/non-string tool name, permits nothing.\n */\n isToolAllowed(tool: string): boolean;\n /** Throw {@link PrincipalToolNotAllowedError} unless `tool` is allowed. */\n assertToolAllowed(tool: string): void;\n /**\n * Assert the principal holds the catalog permission for `(collection,\n * action)`, authorizing against the **published** principal set\n * (`context.permissionSet`) — the same snapshot the RLS session enforces — so\n * the bound is adapter-independent. This is the door-agnostic teeth for the\n * RLS-off adapters; under Postgres RLS it is a redundant (but harmless)\n * second gate. Throws `OperationPermissionError` on denial.\n */\n assertOperation(\n collection: OperationPermissionCollectionInput,\n action: string,\n extraOptions?: SmrtClassOptions,\n ): Promise<OperationPermissionDecision>;\n}\n\nasync function emitAudit(\n entry: PrincipalAuditEntry,\n audit: PrincipalAuditSink | undefined,\n logger: Logger | undefined,\n): Promise<void> {\n if (audit) {\n await audit(entry);\n return;\n }\n const log = logger ?? createLogger({ level: 'info' });\n log.info('agent action executed on behalf of originating user', {\n ...entry,\n });\n}\n\n/**\n * Run `fn` AS the persona's bound principal.\n *\n * Resolves the bound user's live permissions, publishes them onto the DB\n * session (so Postgres RLS bounds every query per-`(table, action)`), emits an\n * on-behalf-of audit entry, and hands `fn` a {@link PrincipalRun} whose\n * assertions enforce the persona tool ceiling and the RLS-off catalog gate.\n *\n * @example\n * ```typescript\n * await executeAsPrincipal(\n * {\n * db,\n * principal: {\n * runAsUserId: persona.runAsUserId,\n * tenantId: persona.tenantId,\n * allowedTools: persona.allowedTools,\n * },\n * onBehalfOfUserId: triggeringUserId,\n * agentClass: persona.agentClass,\n * },\n * async (run) => {\n * run.assertToolAllowed('articles.publish');\n * await run.assertOperation('articles', 'update');\n * await agent.run();\n * },\n * );\n * ```\n */\nexport async function executeAsPrincipal<T>(\n options: ExecuteAsPrincipalOptions,\n fn: (run: PrincipalRun) => Promise<T>,\n): Promise<T> {\n const {\n principal,\n onBehalfOfUserId = null,\n agentClass,\n action = 'agent.run',\n auditMetadata,\n permissions,\n resolver,\n postgresRls,\n enterTenantContext,\n audit,\n logger,\n ...smrtOptions\n } = options;\n\n const { runAsUserId, tenantId, actsAsProfileId = null } = principal;\n\n // Fail-closed tool allow-list (mirrors chat's AgentSession, S5 #1392): an\n // absent or non-array binding allow-list normalizes to `[]` — no tools — so a\n // missing ceiling can only tighten authority, never open it up.\n const toolWhitelist = Array.isArray(principal.allowedTools)\n ? principal.allowedTools\n : [];\n const isToolAllowed = (tool: string): boolean =>\n typeof tool === 'string' && tool.length > 0 && toolWhitelist.includes(tool);\n\n await emitAudit(\n {\n action,\n actorUserId: runAsUserId,\n onBehalfOfUserId,\n tenantId,\n agentClass,\n actsAsProfileId,\n metadata: auditMetadata,\n },\n audit,\n logger,\n );\n\n return withPrincipalPermissionContext(\n {\n ...smrtOptions,\n userId: runAsUserId,\n tenantId,\n permissions,\n resolver,\n postgresRls,\n enterTenantContext: enterTenantContext ?? tenantId !== null,\n },\n async (context) => {\n const run: PrincipalRun = {\n context,\n permissions: context.permissions,\n allowedTools: toolWhitelist,\n isToolAllowed,\n assertToolAllowed(tool: string): void {\n if (!isToolAllowed(tool)) {\n throw new PrincipalToolNotAllowedError(tool);\n }\n },\n async assertOperation(\n collection: OperationPermissionCollectionInput,\n operationAction: string,\n extraOptions?: SmrtClassOptions,\n ): Promise<OperationPermissionDecision> {\n return assertOperationPermission({\n ...smrtOptions,\n ...extraOptions,\n collection,\n action: operationAction,\n // Authorize against the PUBLISHED principal set (the same snapshot\n // Postgres RLS enforces for this context), not a fresh live\n // re-resolve — keeps the RLS-off gate adapter-independent.\n permissionSet: context.permissionSet,\n });\n },\n };\n return fn(run);\n },\n );\n}\n"],"mappings":"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"}