@happyvertical/smrt-agents 0.43.9 → 0.43.10
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.
- package/dist/index.js +1 -1
- package/dist/manifest.json +36 -2
- package/dist/server/data-surface-actions.d.ts +19 -0
- package/dist/server/data-surface-actions.d.ts.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server.js +106 -41
- package/dist/server.js.map +1 -1
- package/dist/smrt-knowledge.json +25 -4
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { TenantCollection } from "@happyvertical/smrt-users";
|
|
|
9
9
|
import { createHash, randomUUID } from "node:crypto";
|
|
10
10
|
import { applyReportExport, applyReportRefresh, buildReportAdapterDescriptor, buildReportDrilldownQuery, createReportExportRequest, createReportExportSnapshot, previewReportExport, previewReportRefresh, queryReportMaterializedRows } from "@happyvertical/smrt-reports";
|
|
11
11
|
//#region src/__smrt-register__.ts
|
|
12
|
-
ObjectRegistry.registerPackageManifest(JSON.parse("{\"version\":\"1.0.0\",\"timestamp\":0,\"packageName\":\"@happyvertical/smrt-agents\",\"packageVersion\":\"0.43.9\",\"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\":{\"withDatabase\":{\"name\":\"withDatabase\",\"async\":true,\"parameters\":[{\"name\":\"db\",\"type\":\"DatabaseInterface\",\"optional\":false},{\"name\":\"operation\",\"type\":\"Function\",\"optional\":false}],\"returnType\":\"Promise<T>\",\"isStatic\":false,\"isPublic\":true},\"getAiUsageSnapshot\":{\"name\":\"getAiUsageSnapshot\",\"async\":false,\"parameters\":[],\"returnType\":\"AiUsageSnapshot | undefined\",\"isStatic\":false,\"isPublic\":true},\"resetAiUsage\":{\"name\":\"resetAiUsage\",\"async\":false,\"parameters\":[],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"listAiUsage\":{\"name\":\"listAiUsage\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"AiUsageListOptions\",\"optional\":true}],\"returnType\":\"Promise<SmrtAiUsageRecord[]>\",\"isStatic\":false,\"isPublic\":true},\"summarizeAiUsage\":{\"name\":\"summarizeAiUsage\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"AiUsageSummaryOptions\",\"optional\":true}],\"returnType\":\"Promise<Record<string, AiUsageStats>>\",\"isStatic\":false,\"isPublic\":true},\"destroy\":{\"name\":\"destroy\",\"async\":false,\"parameters\":[],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"markAsPersisted\":{\"name\":\"markAsPersisted\",\"async\":false,\"parameters\":[],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"requireInsertOnSave\":{\"name\":\"requireInsertOnSave\",\"async\":false,\"parameters\":[],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"initialize\":{\"name\":\"initialize\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise\",\"isStatic\":false,\"isPublic\":true},\"loadDataFromDb\":{\"name\":\"loadDataFromDb\",\"async\":true,\"parameters\":[{\"name\":\"data\",\"type\":\"Record<string>\",\"optional\":false}],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"getFields\":{\"name\":\"getFields\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<any>\",\"isStatic\":false,\"isPublic\":true},\"toJSON\":{\"name\":\"toJSON\",\"async\":false,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"toPlainObject\":{\"name\":\"toPlainObject\",\"async\":false,\"parameters\":[],\"returnType\":\"Record<string>\",\"isStatic\":false,\"isPublic\":true},\"toPublicJSON\":{\"name\":\"toPublicJSON\",\"async\":false,\"parameters\":[{\"name\":\"options\",\"type\":\"PublicJsonOptions\",\"optional\":true}],\"returnType\":\"Record<string>\",\"isStatic\":false,\"isPublic\":true},\"getId\":{\"name\":\"getId\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"getSlug\":{\"name\":\"getSlug\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"getSavedId\":{\"name\":\"getSavedId\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"isSaved\":{\"name\":\"isSaved\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"save\":{\"name\":\"save\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"classifyConstraintError\":{\"name\":\"classifyConstraintError\",\"async\":false,\"parameters\":[{\"name\":\"message\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"'unique' | 'not_null' | null\",\"isStatic\":true,\"isPublic\":true},\"loadFromId\":{\"name\":\"loadFromId\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"loadFromSlug\":{\"name\":\"loadFromSlug\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"is\":{\"name\":\"is\",\"async\":true,\"parameters\":[{\"name\":\"criteria\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"AiOperationOptions\",\"optional\":true}],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"do\":{\"name\":\"do\",\"async\":true,\"parameters\":[{\"name\":\"instructions\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"AiOperationOptions\",\"optional\":true}],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"describe\":{\"name\":\"describe\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"AiOperationOptions\",\"optional\":true}],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"delete\":{\"name\":\"delete\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"isRelatedLoaded\":{\"name\":\"isRelatedLoaded\",\"async\":false,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"boolean\",\"isStatic\":false,\"isPublic\":true},\"_setLoadedRelationship\":{\"name\":\"_setLoadedRelationship\",\"async\":false,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false},{\"name\":\"value\",\"type\":\"any\",\"optional\":false}],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"loadRelated\":{\"name\":\"loadRelated\",\"async\":true,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"LoadRelatedOptions\",\"optional\":true}],\"returnType\":\"Promise<any>\",\"isStatic\":false,\"isPublic\":true},\"loadRelatedMany\":{\"name\":\"loadRelatedMany\",\"async\":true,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"LoadRelatedOptions\",\"optional\":true}],\"returnType\":\"Promise<any[]>\",\"isStatic\":false,\"isPublic\":true},\"getRelated\":{\"name\":\"getRelated\",\"async\":true,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"LoadRelatedOptions\",\"optional\":true}],\"returnType\":\"Promise<any>\",\"isStatic\":false,\"isPublic\":true},\"getAvailableTools\":{\"name\":\"getAvailableTools\",\"async\":false,\"parameters\":[],\"returnType\":\"AITool[]\",\"isStatic\":false,\"isPublic\":true},\"executeToolCall\":{\"name\":\"executeToolCall\",\"async\":true,\"parameters\":[{\"name\":\"toolCall\",\"type\":\"ToolCall\",\"optional\":false}],\"returnType\":\"Promise<ToolCallResult>\",\"isStatic\":false,\"isPublic\":true},\"remember\":{\"name\":\"remember\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":false}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"recall\":{\"name\":\"recall\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":false}],\"returnType\":\"Promise\",\"isStatic\":false,\"isPublic\":true},\"recallAll\":{\"name\":\"recallAll\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":true}],\"returnType\":\"Promise<Map<string>>\",\"isStatic\":false,\"isPublic\":true},\"forget\":{\"name\":\"forget\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":false}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"forgetScope\":{\"name\":\"forgetScope\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":false}],\"returnType\":\"Promise<number>\",\"isStatic\":false,\"isPublic\":true},\"generateEmbeddings\":{\"name\":\"generateEmbeddings\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"GenerateEmbeddingsOptions\",\"optional\":true}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"getEmbedding\":{\"name\":\"getEmbedding\",\"async\":true,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false},{\"name\":\"model\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<number[] | null>\",\"isStatic\":false,\"isPublic\":true},\"hasStaleEmbeddings\":{\"name\":\"hasStaleEmbeddings\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<boolean>\",\"isStatic\":false,\"isPublic\":true},\"clearEmbeddings\":{\"name\":\"clearEmbeddings\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"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},\"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-reports\",\"@happyvertical/smrt-secrets\",\"@happyvertical/smrt-tenancy\",\"@happyvertical/smrt-users\"]}"));
|
|
12
|
+
ObjectRegistry.registerPackageManifest(JSON.parse("{\"version\":\"1.0.0\",\"timestamp\":0,\"packageName\":\"@happyvertical/smrt-agents\",\"packageVersion\":\"0.43.10\",\"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\":{\"withDatabase\":{\"name\":\"withDatabase\",\"async\":true,\"parameters\":[{\"name\":\"db\",\"type\":\"DatabaseInterface\",\"optional\":false},{\"name\":\"operation\",\"type\":\"Function\",\"optional\":false}],\"returnType\":\"Promise<T>\",\"isStatic\":false,\"isPublic\":true},\"getAiUsageSnapshot\":{\"name\":\"getAiUsageSnapshot\",\"async\":false,\"parameters\":[],\"returnType\":\"AiUsageSnapshot | undefined\",\"isStatic\":false,\"isPublic\":true},\"resetAiUsage\":{\"name\":\"resetAiUsage\",\"async\":false,\"parameters\":[],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"listAiUsage\":{\"name\":\"listAiUsage\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"AiUsageListOptions\",\"optional\":true}],\"returnType\":\"Promise<SmrtAiUsageRecord[]>\",\"isStatic\":false,\"isPublic\":true},\"summarizeAiUsage\":{\"name\":\"summarizeAiUsage\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"AiUsageSummaryOptions\",\"optional\":true}],\"returnType\":\"Promise<Record<string, AiUsageStats>>\",\"isStatic\":false,\"isPublic\":true},\"destroy\":{\"name\":\"destroy\",\"async\":false,\"parameters\":[],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"markAsPersisted\":{\"name\":\"markAsPersisted\",\"async\":false,\"parameters\":[],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"requireInsertOnSave\":{\"name\":\"requireInsertOnSave\",\"async\":false,\"parameters\":[],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"withTransaction\":{\"name\":\"withTransaction\",\"async\":true,\"parameters\":[{\"name\":\"operation\",\"type\":\"Function\",\"optional\":false}],\"returnType\":\"Promise<T>\",\"isStatic\":false,\"isPublic\":true},\"initialize\":{\"name\":\"initialize\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise\",\"isStatic\":false,\"isPublic\":true},\"loadDataFromDb\":{\"name\":\"loadDataFromDb\",\"async\":true,\"parameters\":[{\"name\":\"data\",\"type\":\"Record<string>\",\"optional\":false}],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"getFields\":{\"name\":\"getFields\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<any>\",\"isStatic\":false,\"isPublic\":true},\"toJSON\":{\"name\":\"toJSON\",\"async\":false,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"toPlainObject\":{\"name\":\"toPlainObject\",\"async\":false,\"parameters\":[],\"returnType\":\"Record<string>\",\"isStatic\":false,\"isPublic\":true},\"toPublicJSON\":{\"name\":\"toPublicJSON\",\"async\":false,\"parameters\":[{\"name\":\"options\",\"type\":\"PublicJsonOptions\",\"optional\":true}],\"returnType\":\"Record<string>\",\"isStatic\":false,\"isPublic\":true},\"getId\":{\"name\":\"getId\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"getSlug\":{\"name\":\"getSlug\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"getSavedId\":{\"name\":\"getSavedId\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"isSaved\":{\"name\":\"isSaved\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"save\":{\"name\":\"save\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"SmrtSaveOptions\",\"optional\":true}],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"claimRevision\":{\"name\":\"claimRevision\",\"async\":true,\"parameters\":[{\"name\":\"expectedUpdatedAt\",\"type\":\"Date | string\",\"optional\":false}],\"returnType\":\"Promise\",\"isStatic\":false,\"isPublic\":true},\"classifyConstraintError\":{\"name\":\"classifyConstraintError\",\"async\":false,\"parameters\":[{\"name\":\"message\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"'unique' | 'not_null' | null\",\"isStatic\":true,\"isPublic\":true},\"loadFromId\":{\"name\":\"loadFromId\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"loadFromSlug\":{\"name\":\"loadFromSlug\",\"async\":true,\"parameters\":[],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"is\":{\"name\":\"is\",\"async\":true,\"parameters\":[{\"name\":\"criteria\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"AiOperationOptions\",\"optional\":true}],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"do\":{\"name\":\"do\",\"async\":true,\"parameters\":[{\"name\":\"instructions\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"AiOperationOptions\",\"optional\":true}],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"describe\":{\"name\":\"describe\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"AiOperationOptions\",\"optional\":true}],\"returnType\":\"any\",\"isStatic\":false,\"isPublic\":true},\"delete\":{\"name\":\"delete\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"isRelatedLoaded\":{\"name\":\"isRelatedLoaded\",\"async\":false,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"boolean\",\"isStatic\":false,\"isPublic\":true},\"_setLoadedRelationship\":{\"name\":\"_setLoadedRelationship\",\"async\":false,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false},{\"name\":\"value\",\"type\":\"any\",\"optional\":false}],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"loadRelated\":{\"name\":\"loadRelated\",\"async\":true,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"LoadRelatedOptions\",\"optional\":true}],\"returnType\":\"Promise<any>\",\"isStatic\":false,\"isPublic\":true},\"loadRelatedMany\":{\"name\":\"loadRelatedMany\",\"async\":true,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"LoadRelatedOptions\",\"optional\":true}],\"returnType\":\"Promise<any[]>\",\"isStatic\":false,\"isPublic\":true},\"getRelated\":{\"name\":\"getRelated\",\"async\":true,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"LoadRelatedOptions\",\"optional\":true}],\"returnType\":\"Promise<any>\",\"isStatic\":false,\"isPublic\":true},\"getAvailableTools\":{\"name\":\"getAvailableTools\",\"async\":false,\"parameters\":[],\"returnType\":\"AITool[]\",\"isStatic\":false,\"isPublic\":true},\"executeToolCall\":{\"name\":\"executeToolCall\",\"async\":true,\"parameters\":[{\"name\":\"toolCall\",\"type\":\"ToolCall\",\"optional\":false}],\"returnType\":\"Promise<ToolCallResult>\",\"isStatic\":false,\"isPublic\":true},\"remember\":{\"name\":\"remember\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":false}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"recall\":{\"name\":\"recall\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":false}],\"returnType\":\"Promise\",\"isStatic\":false,\"isPublic\":true},\"recallAll\":{\"name\":\"recallAll\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":true}],\"returnType\":\"Promise<Map<string>>\",\"isStatic\":false,\"isPublic\":true},\"forget\":{\"name\":\"forget\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":false}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"forgetScope\":{\"name\":\"forgetScope\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"object\",\"optional\":false}],\"returnType\":\"Promise<number>\",\"isStatic\":false,\"isPublic\":true},\"generateEmbeddings\":{\"name\":\"generateEmbeddings\",\"async\":true,\"parameters\":[{\"name\":\"options\",\"type\":\"GenerateEmbeddingsOptions\",\"optional\":true}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"getEmbedding\":{\"name\":\"getEmbedding\",\"async\":true,\"parameters\":[{\"name\":\"fieldName\",\"type\":\"string\",\"optional\":false},{\"name\":\"model\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<number[] | null>\",\"isStatic\":false,\"isPublic\":true},\"hasStaleEmbeddings\":{\"name\":\"hasStaleEmbeddings\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<boolean>\",\"isStatic\":false,\"isPublic\":true},\"clearEmbeddings\":{\"name\":\"clearEmbeddings\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"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},\"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-reports\",\"@happyvertical/smrt-secrets\",\"@happyvertical/smrt-tenancy\",\"@happyvertical/smrt-users\"]}"));
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/ai-config.ts
|
|
15
15
|
var DEFAULT_SECRET_NAMES = {
|
package/dist/manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": "1.0.0",
|
|
3
3
|
"timestamp": 0,
|
|
4
4
|
"packageName": "@happyvertical/smrt-agents",
|
|
5
|
-
"packageVersion": "0.43.
|
|
5
|
+
"packageVersion": "0.43.10",
|
|
6
6
|
"objects": {
|
|
7
7
|
"@happyvertical/smrt-agents:Agent": {
|
|
8
8
|
"name": "agent",
|
|
@@ -132,6 +132,20 @@
|
|
|
132
132
|
"isStatic": false,
|
|
133
133
|
"isPublic": true
|
|
134
134
|
},
|
|
135
|
+
"withTransaction": {
|
|
136
|
+
"name": "withTransaction",
|
|
137
|
+
"async": true,
|
|
138
|
+
"parameters": [
|
|
139
|
+
{
|
|
140
|
+
"name": "operation",
|
|
141
|
+
"type": "Function",
|
|
142
|
+
"optional": false
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
"returnType": "Promise<T>",
|
|
146
|
+
"isStatic": false,
|
|
147
|
+
"isPublic": true
|
|
148
|
+
},
|
|
135
149
|
"initialize": {
|
|
136
150
|
"name": "initialize",
|
|
137
151
|
"async": true,
|
|
@@ -227,11 +241,31 @@
|
|
|
227
241
|
"save": {
|
|
228
242
|
"name": "save",
|
|
229
243
|
"async": true,
|
|
230
|
-
"parameters": [
|
|
244
|
+
"parameters": [
|
|
245
|
+
{
|
|
246
|
+
"name": "options",
|
|
247
|
+
"type": "SmrtSaveOptions",
|
|
248
|
+
"optional": true
|
|
249
|
+
}
|
|
250
|
+
],
|
|
231
251
|
"returnType": "any",
|
|
232
252
|
"isStatic": false,
|
|
233
253
|
"isPublic": true
|
|
234
254
|
},
|
|
255
|
+
"claimRevision": {
|
|
256
|
+
"name": "claimRevision",
|
|
257
|
+
"async": true,
|
|
258
|
+
"parameters": [
|
|
259
|
+
{
|
|
260
|
+
"name": "expectedUpdatedAt",
|
|
261
|
+
"type": "Date | string",
|
|
262
|
+
"optional": false
|
|
263
|
+
}
|
|
264
|
+
],
|
|
265
|
+
"returnType": "Promise",
|
|
266
|
+
"isStatic": false,
|
|
267
|
+
"isPublic": true
|
|
268
|
+
},
|
|
235
269
|
"classifyConstraintError": {
|
|
236
270
|
"name": "classifyConstraintError",
|
|
237
271
|
"async": false,
|
|
@@ -95,6 +95,7 @@ export interface DataSurfacePreviewTokenRecord {
|
|
|
95
95
|
tenantId: string | null;
|
|
96
96
|
onBehalfOfUserId: string | null;
|
|
97
97
|
actsAsProfileId: string | null;
|
|
98
|
+
agentClass: string | null;
|
|
98
99
|
identityKey: string;
|
|
99
100
|
actionId: string;
|
|
100
101
|
actionFingerprint: string;
|
|
@@ -152,13 +153,31 @@ export interface DataSurfaceActionAdapterOptions {
|
|
|
152
153
|
now?: () => number;
|
|
153
154
|
createToken?: () => string;
|
|
154
155
|
runAsPrincipal?: typeof executeAsPrincipal;
|
|
156
|
+
/**
|
|
157
|
+
* Re-resolve the complete current binding immediately before deferred work.
|
|
158
|
+
* Background execution fails closed when this seam is absent or returns a
|
|
159
|
+
* binding for a different principal.
|
|
160
|
+
*/
|
|
161
|
+
resolveDeferredPrincipal?(reference: Readonly<{
|
|
162
|
+
runAsUserId: string;
|
|
163
|
+
tenantId: string | null;
|
|
164
|
+
actsAsProfileId: string | null;
|
|
165
|
+
onBehalfOfUserId: string | null;
|
|
166
|
+
agentClass?: string;
|
|
167
|
+
}>): ExecuteAsPrincipalOptions | Promise<ExecuteAsPrincipalOptions>;
|
|
155
168
|
idempotencyPollIntervalMs?: number;
|
|
156
169
|
idempotencyWaitTimeoutMs?: number;
|
|
170
|
+
/** Domain-specific request input that must participate in confirmation/idempotency. */
|
|
171
|
+
requestFingerprintExtension?(request: DataSurfaceServerActionRequest): DataSurfaceJsonValue | undefined;
|
|
172
|
+
/** Maps terminal domain failures; return undefined to preserve queue retries. */
|
|
173
|
+
mapError?(error: unknown, request: DataSurfaceServerActionRequest): string | undefined;
|
|
157
174
|
}
|
|
158
175
|
export interface DataSurfaceActionAdapter {
|
|
159
176
|
preview(request: DataSurfaceServerActionRequest, context: DataSurfaceActionContext): Promise<DataSurfaceActionResult>;
|
|
160
177
|
apply(request: DataSurfaceServerActionRequest, context: DataSurfaceActionContext): Promise<DataSurfaceActionResult>;
|
|
161
178
|
}
|
|
179
|
+
/** Validates untrusted extension values before they enter canonical hashing. */
|
|
180
|
+
export declare function isBoundedDataSurfaceJsonValue(value: unknown): value is DataSurfaceJsonValue;
|
|
162
181
|
/** Create a transport-neutral, principal-bound data-surface action adapter. */
|
|
163
182
|
export declare function createDataSurfaceActionAdapter(options: DataSurfaceActionAdapterOptions): DataSurfaceActionAdapter;
|
|
164
183
|
//# sourceMappingURL=data-surface-actions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-surface-actions.d.ts","sourceRoot":"","sources":["../../src/server/data-surface-actions.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,2BAA2B,EAC3B,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,6BAA6B,EAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,KAAK,YAAY,EAClB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,MAAM,6BAA6B,GAAG,UAAU,GAAG,MAAM,CAAC;AAChE,MAAM,MAAM,0BAA0B,GAAG,YAAY,GAAG,YAAY,CAAC;AAErE,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,kCAAkC,GAC1C;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GACf;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAA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EAAE,WAAW,CAAC,EAC1D,SAAS,EAAE,6BAA6B,GACvC,OAAO,CAAC,4BAA4B,CAAC,CAAC;IACzC,eAAe,CAAC,EAAE,0BAA0B,CAAC;IAC7C,gFAAgF;IAChF,KAAK,EAAE,2BAA2B,CAAC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,kBAAkB,CAAC;IAC3C,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,wBAAwB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"data-surface-actions.d.ts","sourceRoot":"","sources":["../../src/server/data-surface-actions.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,2BAA2B,EAC3B,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,6BAA6B,EAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,KAAK,YAAY,EAClB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,MAAM,6BAA6B,GAAG,UAAU,GAAG,MAAM,CAAC;AAChE,MAAM,MAAM,0BAA0B,GAAG,YAAY,GAAG,YAAY,CAAC;AAErE,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,kCAAkC,GAC1C;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GACf;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE,UAAU,GAAG,S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iPD,+EAA+E;AAC/E,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,+BAA+B,GACvC,wBAAwB,CAyf1B"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
export type { AgentActionContext, AgentActionHandler, AgentActionMap, } from './action-types.js';
|
|
30
30
|
export { type AgentAPIRouteInfo, buildRouteMap, type ResolvedAPIRoute, resolveAPIRoute, } from './api-routes.js';
|
|
31
31
|
export { loadSlotConfigs } from './config-loader.js';
|
|
32
|
-
export { createDataSurfaceActionAdapter, type DataSurfaceActionAdapter, type DataSurfaceActionAdapterOptions, type DataSurfaceActionContext as DataSurfaceServerActionContext, type DataSurfaceActionEligibility, type DataSurfaceActionExecution, type DataSurfaceActionPayloadValidation, type DataSurfaceActionRowOutcome, type DataSurfaceActionStateStore, type DataSurfaceBackgroundActionJob, type DataSurfaceBackgroundQueue, type DataSurfaceConfirmationPolicy, type DataSurfaceIdempotencyRecord, type DataSurfaceIdempotencyReservation, type DataSurfacePreviewTokenRecord, type DataSurfaceServerActionDefinition, type DataSurfaceServerActionRequest, InMemoryDataSurfaceActionStateStore, type ResolvedDataSurfaceActions, type ResolvedDataSurfaceSelection, } from './data-surface-actions.js';
|
|
32
|
+
export { createDataSurfaceActionAdapter, type DataSurfaceActionAdapter, type DataSurfaceActionAdapterOptions, type DataSurfaceActionContext as DataSurfaceServerActionContext, type DataSurfaceActionEligibility, type DataSurfaceActionExecution, type DataSurfaceActionPayloadValidation, type DataSurfaceActionRowOutcome, type DataSurfaceActionStateStore, type DataSurfaceBackgroundActionJob, type DataSurfaceBackgroundQueue, type DataSurfaceConfirmationPolicy, type DataSurfaceIdempotencyRecord, type DataSurfaceIdempotencyReservation, type DataSurfacePreviewTokenRecord, type DataSurfaceServerActionDefinition, type DataSurfaceServerActionRequest, InMemoryDataSurfaceActionStateStore, isBoundedDataSurfaceJsonValue, type ResolvedDataSurfaceActions, type ResolvedDataSurfaceSelection, } from './data-surface-actions.js';
|
|
33
33
|
export { extractAgentManifest, extractAgentPackagesFromConfig, loadManifestsFromConfig, loadManifestsFromPackages, type PackageManifest, } from './manifest-utils.js';
|
|
34
34
|
export { type SerializedAgent, serializeResolvedAgent, } from './serialization.js';
|
|
35
35
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,iBAAiB,EACtB,aAAa,EACb,KAAK,gBAAgB,EACrB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,8BAA8B,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,+BAA+B,EACpC,KAAK,wBAAwB,IAAI,8BAA8B,EAC/D,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,EAC/B,KAAK,kCAAkC,EACvC,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAC/B,KAAK,6BAA6B,EAClC,KAAK,4BAA4B,EACjC,KAAK,iCAAiC,EACtC,KAAK,6BAA6B,EAClC,KAAK,iCAAiC,EACtC,KAAK,8BAA8B,EACnC,mCAAmC,EACnC,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,GAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,oBAAoB,EACpB,8BAA8B,EAC9B,uBAAuB,EACvB,yBAAyB,EACzB,KAAK,eAAe,GACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,eAAe,EACpB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,iBAAiB,EACtB,aAAa,EACb,KAAK,gBAAgB,EACrB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,8BAA8B,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,+BAA+B,EACpC,KAAK,wBAAwB,IAAI,8BAA8B,EAC/D,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,EAC/B,KAAK,kCAAkC,EACvC,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAC/B,KAAK,6BAA6B,EAClC,KAAK,4BAA4B,EACjC,KAAK,iCAAiC,EACtC,KAAK,6BAA6B,EAClC,KAAK,iCAAiC,EACtC,KAAK,8BAA8B,EACnC,mCAAmC,EACnC,6BAA6B,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,GAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,oBAAoB,EACpB,8BAA8B,EAC9B,uBAAuB,EACvB,yBAAyB,EACzB,KAAK,eAAe,GACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,eAAe,EACpB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC"}
|
package/dist/server.js
CHANGED
|
@@ -146,6 +146,9 @@ function isBoundedJsonValue(value, depth = 0, seen = /* @__PURE__ */ new Set())
|
|
|
146
146
|
if (entries.length > MAX_JSON_ITEMS) return false;
|
|
147
147
|
return entries.every(([key, item]) => !FORBIDDEN_JSON_KEYS.has(key) && isBoundedJsonValue(item, depth + 1, seen));
|
|
148
148
|
}
|
|
149
|
+
function isBoundedDataSurfaceJsonValue(value) {
|
|
150
|
+
return isBoundedJsonValue(value);
|
|
151
|
+
}
|
|
149
152
|
function validIdentifier(value) {
|
|
150
153
|
return typeof value === "string" && value.length > 0 && value.length <= MAX_IDENTIFIER_LENGTH;
|
|
151
154
|
}
|
|
@@ -199,15 +202,45 @@ function canonicalSelection(selection) {
|
|
|
199
202
|
rowIds: canonicalRowIds(selection.rowIds)
|
|
200
203
|
};
|
|
201
204
|
}
|
|
202
|
-
function requestFingerprint(request) {
|
|
205
|
+
function requestFingerprint(request, extension) {
|
|
203
206
|
return fingerprint({
|
|
204
207
|
identity: canonicalIdentity(request.identity),
|
|
205
208
|
actionId: request.actionId,
|
|
206
209
|
selection: canonicalSelection(request.selection),
|
|
207
210
|
payload: request.payload,
|
|
208
|
-
expectedRevision: request.expectedRevision
|
|
211
|
+
expectedRevision: request.expectedRevision,
|
|
212
|
+
...extension === void 0 ? {} : { extension }
|
|
209
213
|
});
|
|
210
214
|
}
|
|
215
|
+
function deepFreeze(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
216
|
+
if (!value || typeof value !== "object" || seen.has(value)) return value;
|
|
217
|
+
seen.add(value);
|
|
218
|
+
for (const nested of Object.values(value)) deepFreeze(nested, seen);
|
|
219
|
+
Object.freeze(value);
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
function snapshotRequest(request) {
|
|
223
|
+
return deepFreeze(structuredClone(request));
|
|
224
|
+
}
|
|
225
|
+
function snapshotActionContext(context) {
|
|
226
|
+
const principal = {
|
|
227
|
+
...context.principal.principal,
|
|
228
|
+
...context.principal.principal.allowedTools ? { allowedTools: [...context.principal.principal.allowedTools] } : {}
|
|
229
|
+
};
|
|
230
|
+
if (principal.allowedTools) Object.freeze(principal.allowedTools);
|
|
231
|
+
Object.freeze(principal);
|
|
232
|
+
const permissions = context.principal.permissions ? [...context.principal.permissions] : void 0;
|
|
233
|
+
if (permissions) Object.freeze(permissions);
|
|
234
|
+
const auditMetadata = context.principal.auditMetadata ? deepFreeze(structuredClone(context.principal.auditMetadata)) : void 0;
|
|
235
|
+
const principalOptions = {
|
|
236
|
+
...context.principal,
|
|
237
|
+
principal,
|
|
238
|
+
...permissions ? { permissions } : {},
|
|
239
|
+
...auditMetadata ? { auditMetadata } : {}
|
|
240
|
+
};
|
|
241
|
+
Object.freeze(principalOptions);
|
|
242
|
+
return Object.freeze({ principal: principalOptions });
|
|
243
|
+
}
|
|
211
244
|
function actionFingerprint(action) {
|
|
212
245
|
return fingerprint({
|
|
213
246
|
descriptor: action.descriptor,
|
|
@@ -233,6 +266,12 @@ function result(request, ok, reason, details, confirmationToken) {
|
|
|
233
266
|
...confirmationToken ? { confirmationToken } : {}
|
|
234
267
|
};
|
|
235
268
|
}
|
|
269
|
+
function replayResult(request, stored) {
|
|
270
|
+
return {
|
|
271
|
+
...stored,
|
|
272
|
+
requestId: request.requestId
|
|
273
|
+
};
|
|
274
|
+
}
|
|
236
275
|
function outcomesDetails(outcomes, extra = {}) {
|
|
237
276
|
return {
|
|
238
277
|
accepted: outcomes.filter(({ status }) => status === "accepted").length,
|
|
@@ -266,6 +305,7 @@ function createDataSurfaceActionAdapter(options) {
|
|
|
266
305
|
const runAsPrincipal = options.runAsPrincipal ?? executeAsPrincipal;
|
|
267
306
|
const idempotencyPollIntervalMs = Math.max(1, options.idempotencyPollIntervalMs ?? 10);
|
|
268
307
|
const idempotencyWaitTimeoutMs = Math.max(0, options.idempotencyWaitTimeoutMs ?? 5e3);
|
|
308
|
+
const fingerprintRequest = (request) => requestFingerprint(request, options.requestFingerprintExtension?.(request));
|
|
269
309
|
async function resolveInvocation(request, run) {
|
|
270
310
|
const surface = await options.resolveSurface(run, request.identity);
|
|
271
311
|
if (identityKey(surface.descriptor.identity) !== identityKey(request.identity)) return result(request, false, "not_found");
|
|
@@ -277,7 +317,7 @@ function createDataSurfaceActionAdapter(options) {
|
|
|
277
317
|
await run.assertOperation(action.operation.collection, action.operation.action);
|
|
278
318
|
const payloadValidation = await action.validatePayload(request.payload);
|
|
279
319
|
if (!payloadValidation.valid) return result(request, false, payloadValidation.reason ?? "invalid_payload");
|
|
280
|
-
if (!action.descriptor.selectionScopes.includes(request.selection.scope)) return result(request, false, "selection_not_supported");
|
|
320
|
+
if (!declared.selectionScopes.includes(request.selection.scope) || !action.descriptor.selectionScopes.includes(request.selection.scope)) return result(request, false, "selection_not_supported");
|
|
281
321
|
const base = {
|
|
282
322
|
run,
|
|
283
323
|
request,
|
|
@@ -300,11 +340,12 @@ function createDataSurfaceActionAdapter(options) {
|
|
|
300
340
|
async function preview(request, context) {
|
|
301
341
|
const invalid = validateRequest(request, "preview");
|
|
302
342
|
if (invalid) return result(request, false, invalid);
|
|
343
|
+
const boundContext = snapshotActionContext(context);
|
|
303
344
|
return runAsPrincipal({
|
|
304
|
-
...
|
|
345
|
+
...boundContext.principal,
|
|
305
346
|
action: "data_surface.action.preview",
|
|
306
347
|
auditMetadata: {
|
|
307
|
-
...
|
|
348
|
+
...boundContext.principal.auditMetadata,
|
|
308
349
|
surfaceId: request.identity.surfaceId,
|
|
309
350
|
actionId: request.actionId,
|
|
310
351
|
requestId: request.requestId
|
|
@@ -324,14 +365,15 @@ function createDataSurfaceActionAdapter(options) {
|
|
|
324
365
|
}
|
|
325
366
|
const confirmationToken = createToken();
|
|
326
367
|
const selectionFingerprint = fingerprint(canonicalSelection(request.selection));
|
|
327
|
-
const requestFingerprintValue =
|
|
368
|
+
const requestFingerprintValue = fingerprintRequest(request);
|
|
328
369
|
const expiresAt = now() + tokenTtlMs;
|
|
329
370
|
await state.putToken(confirmationToken, {
|
|
330
371
|
expiresAt,
|
|
331
|
-
actorUserId:
|
|
332
|
-
tenantId:
|
|
333
|
-
onBehalfOfUserId:
|
|
334
|
-
actsAsProfileId:
|
|
372
|
+
actorUserId: boundContext.principal.principal.runAsUserId,
|
|
373
|
+
tenantId: boundContext.principal.principal.tenantId,
|
|
374
|
+
onBehalfOfUserId: boundContext.principal.onBehalfOfUserId ?? null,
|
|
375
|
+
actsAsProfileId: boundContext.principal.principal.actsAsProfileId ?? null,
|
|
376
|
+
agentClass: boundContext.principal.agentClass ?? null,
|
|
335
377
|
identityKey: identityKey(request.identity),
|
|
336
378
|
actionId: request.actionId,
|
|
337
379
|
actionFingerprint: actionFingerprint(invocation.action),
|
|
@@ -366,28 +408,29 @@ function createDataSurfaceActionAdapter(options) {
|
|
|
366
408
|
rowId,
|
|
367
409
|
status: "accepted"
|
|
368
410
|
});
|
|
369
|
-
} catch {
|
|
411
|
+
} catch (error) {
|
|
370
412
|
outcomes.push({
|
|
371
413
|
rowId,
|
|
372
414
|
status: "failed",
|
|
373
|
-
reason: "execution_failed"
|
|
415
|
+
reason: options.mapError?.(error, request) ?? "execution_failed"
|
|
374
416
|
});
|
|
375
417
|
}
|
|
376
418
|
return result(request, true, void 0, outcomesDetails(outcomes));
|
|
377
419
|
}
|
|
378
|
-
async function executeBackgroundOnce(request, context, token) {
|
|
420
|
+
async function executeBackgroundOnce(request, context, token, reference) {
|
|
379
421
|
const ownerToken = randomBytes(16).toString("base64url");
|
|
380
422
|
const executionFingerprint = fingerprint({
|
|
381
423
|
kind: "background-execution",
|
|
382
|
-
request: token?.requestFingerprint ??
|
|
424
|
+
request: token?.requestFingerprint ?? fingerprintRequest(request),
|
|
383
425
|
action: token?.actionFingerprint ?? request.actionId
|
|
384
426
|
});
|
|
385
427
|
const executionScope = fingerprint({
|
|
386
428
|
kind: "background-execution",
|
|
387
|
-
actorUserId:
|
|
388
|
-
tenantId:
|
|
389
|
-
onBehalfOfUserId:
|
|
390
|
-
actsAsProfileId:
|
|
429
|
+
actorUserId: reference.runAsUserId,
|
|
430
|
+
tenantId: reference.tenantId,
|
|
431
|
+
onBehalfOfUserId: reference.onBehalfOfUserId,
|
|
432
|
+
actsAsProfileId: reference.actsAsProfileId,
|
|
433
|
+
agentClass: reference.agentClass ?? null,
|
|
391
434
|
identity: canonicalIdentity(request.identity),
|
|
392
435
|
actionId: request.actionId,
|
|
393
436
|
idempotencyKey: request.idempotencyKey
|
|
@@ -400,14 +443,24 @@ function createDataSurfaceActionAdapter(options) {
|
|
|
400
443
|
reservedAt: now()
|
|
401
444
|
});
|
|
402
445
|
if (winner.requestFingerprint !== executionFingerprint) return result(request, false, "idempotency_conflict");
|
|
403
|
-
if (winner.status === "completed") return winner.result;
|
|
446
|
+
if (winner.status === "completed") return replayResult(request, winner.result);
|
|
404
447
|
if (winner.ownerToken === ownerToken) {
|
|
405
448
|
let executed;
|
|
406
449
|
try {
|
|
407
|
-
|
|
450
|
+
const refreshed = await options.resolveDeferredPrincipal?.(reference);
|
|
451
|
+
if (!refreshed || refreshed.principal.runAsUserId !== reference.runAsUserId || refreshed.principal.tenantId !== reference.tenantId || (refreshed.principal.actsAsProfileId ?? null) !== reference.actsAsProfileId || (refreshed.onBehalfOfUserId ?? null) !== reference.onBehalfOfUserId || (refreshed.agentClass ?? null) !== (reference.agentClass ?? null) || !Array.isArray(refreshed.principal.allowedTools)) throw new Error("Deferred data-surface action principal binding could not be resolved safely");
|
|
452
|
+
const { permissions: _permissions, ...livePrincipal } = refreshed;
|
|
453
|
+
executed = await authorizedApply(request, {
|
|
454
|
+
...context,
|
|
455
|
+
principal: livePrincipal
|
|
456
|
+
}, token, false);
|
|
408
457
|
} catch (error) {
|
|
409
|
-
|
|
410
|
-
|
|
458
|
+
const reason = options.mapError?.(error, request);
|
|
459
|
+
if (!reason) {
|
|
460
|
+
await state.releaseIdempotency(executionScope, ownerToken);
|
|
461
|
+
throw error;
|
|
462
|
+
}
|
|
463
|
+
executed = result(request, false, reason);
|
|
411
464
|
}
|
|
412
465
|
if (!await state.completeIdempotency(executionScope, ownerToken, executed)) throw new Error("Lost background action idempotency reservation");
|
|
413
466
|
return executed;
|
|
@@ -415,7 +468,7 @@ function createDataSurfaceActionAdapter(options) {
|
|
|
415
468
|
if (poll < maxPolls) {
|
|
416
469
|
await new Promise((resolve) => setTimeout(resolve, idempotencyPollIntervalMs));
|
|
417
470
|
const current = await state.getIdempotency(executionScope);
|
|
418
|
-
if (current?.status === "completed") return current.result;
|
|
471
|
+
if (current?.status === "completed") return replayResult(request, current.result);
|
|
419
472
|
}
|
|
420
473
|
}
|
|
421
474
|
return result(request, false, "idempotency_in_progress");
|
|
@@ -423,6 +476,13 @@ function createDataSurfaceActionAdapter(options) {
|
|
|
423
476
|
async function authorizedApply(request, context, token, allowBackground) {
|
|
424
477
|
const idempotencyKey = request.idempotencyKey;
|
|
425
478
|
if (!idempotencyKey) return result(request, false, "invalid_request");
|
|
479
|
+
const deferredPrincipalReference = Object.freeze({
|
|
480
|
+
runAsUserId: context.principal.principal.runAsUserId,
|
|
481
|
+
tenantId: context.principal.principal.tenantId,
|
|
482
|
+
actsAsProfileId: context.principal.principal.actsAsProfileId ?? null,
|
|
483
|
+
onBehalfOfUserId: context.principal.onBehalfOfUserId ?? null,
|
|
484
|
+
...context.principal.agentClass ? { agentClass: context.principal.agentClass } : {}
|
|
485
|
+
});
|
|
426
486
|
return runAsPrincipal({
|
|
427
487
|
...context.principal,
|
|
428
488
|
action: "data_surface.action.apply",
|
|
@@ -437,58 +497,63 @@ function createDataSurfaceActionAdapter(options) {
|
|
|
437
497
|
const invocation = await resolveInvocation(request, run);
|
|
438
498
|
if ("ok" in invocation) return invocation;
|
|
439
499
|
if (token) {
|
|
440
|
-
if (invocation.selection.revision !== token.revision || invocation.selection.revision !== request.expectedRevision || invocation.selection.queryFingerprint !== token.queryFingerprint || fingerprint(canonicalSelection(request.selection)) !== token.selectionFingerprint || actionFingerprint(invocation.action) !== token.actionFingerprint || fingerprint(canonicalRowIds(invocation.selection.rowIds)) !== token.resolvedRowsFingerprint) return result(request, false, "stale_preview");
|
|
500
|
+
if (fingerprintRequest(request) !== token.requestFingerprint || invocation.selection.revision !== token.revision || invocation.selection.revision !== request.expectedRevision || invocation.selection.queryFingerprint !== token.queryFingerprint || fingerprint(canonicalSelection(request.selection)) !== token.selectionFingerprint || actionFingerprint(invocation.action) !== token.actionFingerprint || fingerprint(canonicalRowIds(invocation.selection.rowIds)) !== token.resolvedRowsFingerprint) return result(request, false, "stale_preview");
|
|
441
501
|
} else if (invocation.action.confirmation === "required") return result(request, false, "confirmation_required");
|
|
442
502
|
else if (invocation.selection.revision !== request.expectedRevision) return result(request, false, "stale_revision");
|
|
443
503
|
if (invocation.action.execution === "background" && allowBackground) {
|
|
444
|
-
if (!options.backgroundQueue) return result(request, false, "background_unavailable");
|
|
504
|
+
if (!options.backgroundQueue || !options.resolveDeferredPrincipal) return result(request, false, "background_unavailable");
|
|
445
505
|
const queued = await options.backgroundQueue.enqueue({
|
|
446
506
|
idempotencyKey,
|
|
447
507
|
identity: request.identity,
|
|
448
508
|
actionId: request.actionId,
|
|
449
509
|
rowIds: invocation.selection.rowIds,
|
|
450
|
-
run: () => executeBackgroundOnce(request, context, token)
|
|
510
|
+
run: () => executeBackgroundOnce(request, context, token, deferredPrincipalReference)
|
|
451
511
|
});
|
|
452
512
|
return result(request, true, void 0, {
|
|
453
513
|
accepted: invocation.selection.rowIds.length,
|
|
454
514
|
skipped: 0,
|
|
455
515
|
failed: 0,
|
|
516
|
+
...queued.details ?? {},
|
|
456
517
|
background: true,
|
|
457
518
|
jobId: queued.jobId,
|
|
458
|
-
|
|
519
|
+
jobRequestId: request.requestId
|
|
459
520
|
});
|
|
460
521
|
}
|
|
461
522
|
return executeForeground(request, invocation);
|
|
462
523
|
});
|
|
463
524
|
}
|
|
464
|
-
async function apply(
|
|
465
|
-
const invalid = validateRequest(
|
|
466
|
-
if (invalid) return result(
|
|
525
|
+
async function apply(input, context) {
|
|
526
|
+
const invalid = validateRequest(input, "apply");
|
|
527
|
+
if (invalid) return result(input, false, invalid);
|
|
528
|
+
const request = snapshotRequest(input);
|
|
529
|
+
const boundContext = snapshotActionContext(context);
|
|
467
530
|
const confirmationToken = request.confirmationToken;
|
|
468
531
|
const idempotencyKey = request.idempotencyKey;
|
|
469
532
|
if (!idempotencyKey) return result(request, false, "invalid_request");
|
|
470
|
-
const actorUserId =
|
|
471
|
-
const tenantId =
|
|
472
|
-
const onBehalfOfUserId =
|
|
473
|
-
const actsAsProfileId =
|
|
474
|
-
const
|
|
533
|
+
const actorUserId = boundContext.principal.principal.runAsUserId;
|
|
534
|
+
const tenantId = boundContext.principal.principal.tenantId;
|
|
535
|
+
const onBehalfOfUserId = boundContext.principal.onBehalfOfUserId ?? null;
|
|
536
|
+
const actsAsProfileId = boundContext.principal.principal.actsAsProfileId ?? null;
|
|
537
|
+
const agentClass = boundContext.principal.agentClass ?? null;
|
|
538
|
+
const requestFingerprintValue = fingerprintRequest(request);
|
|
475
539
|
const idempotencyScope = fingerprint({
|
|
476
540
|
actorUserId,
|
|
477
541
|
tenantId,
|
|
478
542
|
onBehalfOfUserId,
|
|
479
543
|
actsAsProfileId,
|
|
544
|
+
agentClass,
|
|
480
545
|
identity: canonicalIdentity(request.identity),
|
|
481
546
|
actionId: request.actionId,
|
|
482
547
|
idempotencyKey
|
|
483
548
|
});
|
|
484
549
|
const prior = await state.getIdempotency(idempotencyScope);
|
|
485
550
|
if (prior && prior.requestFingerprint !== requestFingerprintValue) return result(request, false, "idempotency_conflict");
|
|
486
|
-
if (prior?.status === "completed") return prior.result;
|
|
551
|
+
if (prior?.status === "completed") return replayResult(request, prior.result);
|
|
487
552
|
let token;
|
|
488
553
|
if (confirmationToken) {
|
|
489
554
|
token = await state.getToken(confirmationToken);
|
|
490
555
|
if (!token || token.expiresAt <= now()) return result(request, false, "invalid_or_expired_confirmation");
|
|
491
|
-
if (token.actorUserId !== actorUserId || token.tenantId !== tenantId || token.onBehalfOfUserId !== onBehalfOfUserId || token.actsAsProfileId !== actsAsProfileId || token.identityKey !== identityKey(request.identity) || token.actionId !== request.actionId || token.requestFingerprint !== requestFingerprintValue) return result(request, false, "confirmation_mismatch");
|
|
556
|
+
if (token.actorUserId !== actorUserId || token.tenantId !== tenantId || token.onBehalfOfUserId !== onBehalfOfUserId || token.actsAsProfileId !== actsAsProfileId || token.agentClass !== agentClass || token.identityKey !== identityKey(request.identity) || token.actionId !== request.actionId || token.requestFingerprint !== requestFingerprintValue) return result(request, false, "confirmation_mismatch");
|
|
492
557
|
if (!await state.markTokenConsumed(confirmationToken, idempotencyKey)) return result(request, false, "confirmation_replayed");
|
|
493
558
|
}
|
|
494
559
|
const ownerToken = randomBytes(16).toString("base64url");
|
|
@@ -500,11 +565,11 @@ function createDataSurfaceActionAdapter(options) {
|
|
|
500
565
|
reservedAt: now()
|
|
501
566
|
});
|
|
502
567
|
if (winner.requestFingerprint !== requestFingerprintValue) return result(request, false, "idempotency_conflict");
|
|
503
|
-
if (winner.status === "completed") return winner.result;
|
|
568
|
+
if (winner.status === "completed") return replayResult(request, winner.result);
|
|
504
569
|
if (winner.ownerToken === ownerToken) {
|
|
505
570
|
let applied;
|
|
506
571
|
try {
|
|
507
|
-
applied = await authorizedApply(request,
|
|
572
|
+
applied = await authorizedApply(request, boundContext, token, true);
|
|
508
573
|
} catch (error) {
|
|
509
574
|
await state.releaseIdempotency(idempotencyScope, ownerToken);
|
|
510
575
|
throw error;
|
|
@@ -519,7 +584,7 @@ function createDataSurfaceActionAdapter(options) {
|
|
|
519
584
|
if (poll < maxPolls) {
|
|
520
585
|
await new Promise((resolve) => setTimeout(resolve, idempotencyPollIntervalMs));
|
|
521
586
|
const current = await state.getIdempotency(idempotencyScope);
|
|
522
|
-
if (current?.status === "completed") return current.result;
|
|
587
|
+
if (current?.status === "completed") return replayResult(request, current.result);
|
|
523
588
|
}
|
|
524
589
|
}
|
|
525
590
|
return result(request, false, "idempotency_in_progress");
|
|
@@ -549,6 +614,6 @@ function serializeResolvedAgent(resolved) {
|
|
|
549
614
|
};
|
|
550
615
|
}
|
|
551
616
|
//#endregion
|
|
552
|
-
export { InMemoryDataSurfaceActionStateStore, buildRouteMap, createDataSurfaceActionAdapter, extractAgentManifest, extractAgentPackagesFromConfig, loadManifestsFromConfig, loadManifestsFromPackages, loadSlotConfigs, resolveAPIRoute, serializeResolvedAgent };
|
|
617
|
+
export { InMemoryDataSurfaceActionStateStore, buildRouteMap, createDataSurfaceActionAdapter, extractAgentManifest, extractAgentPackagesFromConfig, isBoundedDataSurfaceJsonValue, loadManifestsFromConfig, loadManifestsFromPackages, loadSlotConfigs, resolveAPIRoute, serializeResolvedAgent };
|
|
553
618
|
|
|
554
619
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":["result"],"sources":["../src/server/api-routes.ts","../src/server/config-loader.ts","../src/server/data-surface-actions.ts","../src/server/serialization.ts"],"sourcesContent":["/**\n * Server-side API route resolution for SMRT agents\n *\n * Reads agent package manifests and builds a route map from resource\n * paths (e.g., 'performers', 'video-contents') to SmrtObject class\n * names and allowed CRUD actions. The catch-all API handler uses this\n * to resolve incoming requests.\n *\n * @module @happyvertical/smrt-agents/server\n */\n\nimport type { PackageManifest } from './manifest-utils.js';\n\n/**\n * Info about a single API route (one SmrtObject with api.include)\n */\nexport interface AgentAPIRouteInfo {\n /** SmrtObject class name (e.g., 'Performer') */\n className: string;\n /** Allowed CRUD actions (e.g., ['list', 'get', 'create', 'update', 'delete']) */\n allowedActions: string[];\n /** Package that owns this resource */\n packageName?: string;\n}\n\n/**\n * Result of resolving a URL path against the route map\n */\nexport interface ResolvedAPIRoute {\n /** The matched route info */\n route: AgentAPIRouteInfo;\n /** Resource ID if path includes one (e.g., 'performers/abc-123') */\n id?: string;\n /** Custom action name if path includes one (e.g., 'performers/abc-123/generate-image') */\n action?: string;\n}\n\n/**\n * Build a route map from loaded package manifests.\n *\n * Iterates all objects in each manifest, and for any object with a\n * `decoratorConfig.api.include` array, registers a route. The route\n * path is derived from `decoratorConfig.api.path` if set, otherwise\n * from the table name with underscores converted to hyphens.\n *\n * @param manifests - Array of parsed package manifest JSON objects\n * @returns Map of resource path -> route info\n *\n * @example\n * ```typescript\n * const manifests = [histrioManifest, praecoManifest];\n * const routes = buildRouteMap(manifests);\n * // routes.get('performers') => { className: 'Performer', allowedActions: ['list', 'get', 'create', 'update', 'delete'] }\n * // routes.get('video-contents') => { className: 'VideoShot', allowedActions: ['list', 'get', 'create', 'update'] }\n * ```\n */\nexport function buildRouteMap(\n manifests: PackageManifest[],\n): Map<string, AgentAPIRouteInfo> {\n const routes = new Map<string, AgentAPIRouteInfo>();\n\n for (const manifest of manifests) {\n const packageName = (manifest as Record<string, unknown>).packageName as\n | string\n | undefined;\n\n for (const obj of Object.values(manifest.objects)) {\n const config = obj.decoratorConfig as Record<string, unknown> | undefined;\n if (!config) continue;\n\n const api = config.api as\n | { include?: string[]; path?: string }\n | undefined;\n if (!api?.include || api.include.length === 0) continue;\n\n // Derive the URL path: explicit api.path, or table name with _ -> -\n const tableName = config.tableName as string | undefined;\n const path =\n api.path || (tableName ? tableName.replace(/_/g, '-') : null);\n if (!path) continue;\n\n routes.set(path, {\n className: obj.className,\n allowedActions: api.include,\n packageName,\n });\n }\n }\n\n return routes;\n}\n\n/**\n * Resolve a URL resource path against a route map.\n *\n * Handles three URL patterns:\n * - `performers` → list/create (no id)\n * - `performers/abc-123` → get/update/delete (with id)\n * - `performers/abc-123/generate-image` → custom action\n *\n * @param urlPath - The resource portion of the URL (after `/api/agents/{agentId}/`)\n * @param routes - Route map from {@link buildRouteMap}\n * @returns Resolved route with optional id/action, or null if no match\n */\nexport function resolveAPIRoute(\n urlPath: string,\n routes: Map<string, AgentAPIRouteInfo>,\n): ResolvedAPIRoute | null {\n // Normalize: strip leading/trailing slashes\n const normalized = urlPath.replace(/^\\/+|\\/+$/g, '');\n if (!normalized) return null;\n\n const segments = normalized.split('/');\n\n // Try 1-segment: \"performers\"\n if (segments.length === 1) {\n const route = routes.get(segments[0]);\n if (route) return { route };\n return null;\n }\n\n // Try 2-segment: \"performers/{id}\"\n if (segments.length === 2) {\n const route = routes.get(segments[0]);\n if (route) return { route, id: segments[1] };\n return null;\n }\n\n // Try 3-segment: \"performers/{id}/{action}\"\n if (segments.length === 3) {\n const route = routes.get(segments[0]);\n if (route) return { route, id: segments[1], action: segments[2] };\n return null;\n }\n\n return null;\n}\n","/**\n * Server-side agent config loading utilities\n *\n * Loads slot configurations from the agent_configs table for a set of agents.\n * Agent-specific table loading (e.g., praeco_sources) stays in the host app.\n *\n * @module @happyvertical/smrt-agents/server\n */\n\nimport type { SmrtClassOptions } from '@happyvertical/smrt-core';\nimport { AgentConfig } from '../config.js';\n\n/**\n * Load slot configs for multiple agents from the agent_configs table.\n *\n * Returns a nested map: agentId -> slotId -> configData.\n * Agent-specific tables (e.g., praeco_sources, praeco_reports)\n * are NOT loaded here — those stay in the host application.\n *\n * @param agents - Array of agent identifiers (id + agentClass)\n * @param dbOptions - Database options for SmrtCollection.create()\n * @returns Map of agentId -> slotId -> config data\n */\nexport async function loadSlotConfigs(\n agents: Array<{ id: string; agentClass: string }>,\n dbOptions: SmrtClassOptions,\n): Promise<Record<string, Record<string, unknown>>> {\n if (agents.length === 0) {\n return {};\n }\n\n try {\n const configsByAgent = await AgentConfig.forAgents(\n agents.map((agent) => agent.id),\n dbOptions,\n );\n\n const configs: Record<string, Record<string, unknown>> = {};\n for (const [agentId, slotConfigs] of configsByAgent) {\n const agentConfig: Record<string, unknown> = {};\n for (const [slotId, configData] of slotConfigs) {\n agentConfig[slotId] = configData;\n }\n if (Object.keys(agentConfig).length > 0) {\n configs[agentId] = agentConfig;\n }\n }\n\n return configs;\n } catch (error) {\n if (isMissingAgentConfigTableError(error)) {\n return {};\n }\n throw error;\n }\n}\n\nfunction isMissingAgentConfigTableError(error: unknown): boolean {\n const message = String((error as Error)?.message || error || '');\n\n return (\n message.includes(\"Run 'smrt db:migrate'\") ||\n /no such table[:\\s]+agent_configs/i.test(message) ||\n /relation .*agent_configs.*does not exist/i.test(message) ||\n /table .*agent_configs.*doesn'?t exist/i.test(message)\n );\n}\n","/**\n * Principal-bound preview/apply orchestration for data-surface actions.\n *\n * Browser state is treated only as an input hint. Every preview and apply is\n * executed under the bound principal, resolves the surface and selection\n * afresh, and delegates durable work only after authorization and eligibility\n * checks have passed.\n */\nimport { createHash, randomBytes } from 'node:crypto';\nimport type {\n DataSurfaceActionDescriptor,\n DataSurfaceActionRequest,\n DataSurfaceActionResult,\n DataSurfaceDescriptor,\n DataSurfaceIdentity,\n DataSurfaceJsonObject,\n DataSurfaceJsonValue,\n DataSurfaceRowId,\n DataSurfaceSelectionReference,\n} from '@happyvertical/smrt-ui/data';\nimport {\n type ExecuteAsPrincipalOptions,\n executeAsPrincipal,\n type PrincipalRun,\n} from '../execute-as-principal.js';\n\nexport type DataSurfaceConfirmationPolicy = 'required' | 'none';\nexport type DataSurfaceActionExecution = 'foreground' | 'background';\n\nexport interface DataSurfaceActionEligibility {\n eligible: boolean;\n reason?: string;\n}\n\nexport type DataSurfaceActionPayloadValidation =\n | { valid: true }\n | { valid: false; reason?: string };\n\nexport interface DataSurfaceActionRowOutcome {\n rowId: DataSurfaceRowId;\n status: 'accepted' | 'skipped' | 'failed';\n reason?: string;\n}\n\nexport interface ResolvedDataSurfaceSelection {\n /** Fresh server-side revision of the selected surface/query. */\n revision: number;\n /** Canonical fingerprint of the frozen query represented by the selection. */\n queryFingerprint: string;\n /** Authoritatively resolved row ids. Browser-provided ids are only hints. */\n rowIds: DataSurfaceRowId[];\n}\n\nexport interface DataSurfaceActionInvocation {\n run: PrincipalRun;\n request: DataSurfaceServerActionRequest;\n descriptor: DataSurfaceDescriptor;\n action: DataSurfaceServerActionDefinition;\n selection: ResolvedDataSurfaceSelection;\n}\n\nexport interface DataSurfaceServerActionDefinition {\n descriptor: DataSurfaceActionDescriptor;\n /** Serializable declaration for transport/schema generators; null means no input. */\n inputSchema: DataSurfaceJsonObject | null;\n /** Runtime enforcement for the declared schema; absence is never permissive. */\n validatePayload(\n payload: DataSurfaceJsonValue | undefined,\n ):\n | DataSurfaceActionPayloadValidation\n | Promise<DataSurfaceActionPayloadValidation>;\n /** Explicit for every action, including sensitive/public/destructive ones. */\n confirmation: DataSurfaceConfirmationPolicy;\n execution: DataSurfaceActionExecution;\n /** Fail-closed persona capability checked by PrincipalRun. */\n tool: string;\n /** Explicit RBAC catalog gate, enforced independently of callback convention. */\n operation: {\n id: string;\n collection: Parameters<PrincipalRun['assertOperation']>[0];\n action: string;\n };\n /** Fresh permission/domain authorization check, run for preview and apply. */\n authorize(\n invocation: DataSurfaceActionInvocation,\n ): boolean | Promise<boolean>;\n /** Fresh per-row domain precondition check, repeated at apply time. */\n eligible(\n invocation: DataSurfaceActionInvocation,\n rowId: DataSurfaceRowId,\n ): DataSurfaceActionEligibility | Promise<DataSurfaceActionEligibility>;\n /** Foreground mutation. Background definitions are run by the injected queue. */\n apply(\n invocation: DataSurfaceActionInvocation,\n rowId: DataSurfaceRowId,\n ):\n | undefined\n | DataSurfaceJsonValue\n | Promise<undefined | DataSurfaceJsonValue>;\n}\n\nexport interface ResolvedDataSurfaceActions {\n descriptor: DataSurfaceDescriptor;\n /** Current server-side revision, never trusted from the browser. */\n revision: number;\n actions: Record<string, DataSurfaceServerActionDefinition>;\n}\n\nexport interface DataSurfaceServerActionRequest\n extends DataSurfaceActionRequest {\n /** Required on apply and bound into the preview token. */\n expectedRevision: number;\n /** Required on apply. Identical retries replay the first terminal result. */\n idempotencyKey?: string;\n}\n\nexport interface DataSurfaceActionContext {\n principal: ExecuteAsPrincipalOptions;\n}\n\nexport interface DataSurfaceBackgroundActionJob {\n idempotencyKey: string;\n identity: DataSurfaceIdentity;\n actionId: string;\n rowIds: DataSurfaceRowId[];\n /**\n * The queue must call this task to perform the work. It re-enters the bound\n * principal and repeats descriptor, authorization, selection, and eligibility\n * checks before any mutation.\n */\n run: () => Promise<DataSurfaceActionResult>;\n}\n\nexport interface DataSurfaceBackgroundQueue {\n enqueue(\n job: DataSurfaceBackgroundActionJob,\n ): Promise<{ jobId: string; details?: DataSurfaceJsonObject }>;\n}\n\nexport interface DataSurfacePreviewTokenRecord {\n expiresAt: number;\n actorUserId: string;\n tenantId: string | null;\n onBehalfOfUserId: string | null;\n actsAsProfileId: string | null;\n identityKey: string;\n actionId: string;\n actionFingerprint: string;\n revision: number;\n queryFingerprint: string;\n selectionFingerprint: string;\n resolvedRowsFingerprint: string;\n requestFingerprint: string;\n consumedBy?: string;\n}\n\nexport type DataSurfaceIdempotencyRecord =\n | {\n status: 'reserved';\n requestFingerprint: string;\n ownerToken: string;\n reservedAt: number;\n }\n | {\n status: 'completed';\n requestFingerprint: string;\n result: DataSurfaceActionResult;\n };\n\nexport interface DataSurfaceIdempotencyReservation {\n requestFingerprint: string;\n ownerToken: string;\n reservedAt: number;\n}\n\nexport interface DataSurfaceActionStateStore {\n putToken(\n token: string,\n record: DataSurfacePreviewTokenRecord,\n ): Promise<void> | void;\n getToken(\n token: string,\n ):\n | Promise<DataSurfacePreviewTokenRecord | undefined>\n | DataSurfacePreviewTokenRecord\n | undefined;\n markTokenConsumed(\n token: string,\n idempotencyKey: string,\n ): Promise<boolean> | boolean;\n getIdempotency(\n key: string,\n ):\n | Promise<DataSurfaceIdempotencyRecord | undefined>\n | DataSurfaceIdempotencyRecord\n | undefined;\n /** Atomically create a durable reservation or return the existing record. */\n reserveIdempotency(\n key: string,\n reservation: DataSurfaceIdempotencyReservation,\n ): Promise<DataSurfaceIdempotencyRecord> | DataSurfaceIdempotencyRecord;\n completeIdempotency(\n key: string,\n ownerToken: string,\n result: DataSurfaceActionResult,\n ): Promise<boolean> | boolean;\n releaseIdempotency(\n key: string,\n ownerToken: string,\n ): Promise<boolean> | boolean;\n}\n\n/** Explicit single-process/testing store; production callers inject shared state. */\nexport class InMemoryDataSurfaceActionStateStore\n implements DataSurfaceActionStateStore\n{\n private readonly tokens = new Map<string, DataSurfacePreviewTokenRecord>();\n private readonly idempotency = new Map<\n string,\n DataSurfaceIdempotencyRecord\n >();\n\n putToken(token: string, record: DataSurfacePreviewTokenRecord): void {\n this.tokens.set(token, record);\n }\n\n getToken(token: string): DataSurfacePreviewTokenRecord | undefined {\n return this.tokens.get(token);\n }\n\n markTokenConsumed(token: string, idempotencyKey: string): boolean {\n const record = this.tokens.get(token);\n if (!record) return false;\n if (record.consumedBy && record.consumedBy !== idempotencyKey) return false;\n record.consumedBy = idempotencyKey;\n return true;\n }\n\n getIdempotency(key: string): DataSurfaceIdempotencyRecord | undefined {\n return this.idempotency.get(key);\n }\n\n reserveIdempotency(\n key: string,\n reservation: DataSurfaceIdempotencyReservation,\n ): DataSurfaceIdempotencyRecord {\n const existing = this.idempotency.get(key);\n if (existing) return existing;\n const record: DataSurfaceIdempotencyRecord = {\n status: 'reserved',\n ...reservation,\n };\n this.idempotency.set(key, record);\n return record;\n }\n\n completeIdempotency(\n key: string,\n ownerToken: string,\n result: DataSurfaceActionResult,\n ): boolean {\n const existing = this.idempotency.get(key);\n if (existing?.status !== 'reserved' || existing.ownerToken !== ownerToken)\n return false;\n this.idempotency.set(key, {\n status: 'completed',\n requestFingerprint: existing.requestFingerprint,\n result,\n });\n return true;\n }\n\n releaseIdempotency(key: string, ownerToken: string): boolean {\n const existing = this.idempotency.get(key);\n if (existing?.status !== 'reserved' || existing.ownerToken !== ownerToken)\n return false;\n return this.idempotency.delete(key);\n }\n}\n\nexport interface DataSurfaceActionAdapterOptions {\n resolveSurface(\n run: PrincipalRun,\n identity: DataSurfaceIdentity,\n ): Promise<ResolvedDataSurfaceActions>;\n resolveSelection(\n invocation: Omit<DataSurfaceActionInvocation, 'selection'>,\n selection: DataSurfaceSelectionReference,\n ): Promise<ResolvedDataSurfaceSelection>;\n backgroundQueue?: DataSurfaceBackgroundQueue;\n /** Required durable, shared backend in production; memory storage is opt-in. */\n state: DataSurfaceActionStateStore;\n tokenTtlMs?: number;\n now?: () => number;\n createToken?: () => string;\n runAsPrincipal?: typeof executeAsPrincipal;\n idempotencyPollIntervalMs?: number;\n idempotencyWaitTimeoutMs?: number;\n}\n\nexport interface DataSurfaceActionAdapter {\n preview(\n request: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n ): Promise<DataSurfaceActionResult>;\n apply(\n request: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n ): Promise<DataSurfaceActionResult>;\n}\n\nconst DEFAULT_TOKEN_TTL_MS = 5 * 60 * 1_000;\nconst MAX_IDENTIFIER_LENGTH = 256;\nconst MAX_JSON_DEPTH = 16;\nconst MAX_JSON_ITEMS = 1_000;\nconst FORBIDDEN_JSON_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\nfunction isBoundedJsonValue(\n value: unknown,\n depth = 0,\n seen = new Set<object>(),\n): value is DataSurfaceJsonValue {\n if (value === null) return true;\n if (['string', 'boolean'].includes(typeof value)) return true;\n if (typeof value === 'number') return Number.isFinite(value);\n if (typeof value !== 'object' || depth >= MAX_JSON_DEPTH || seen.has(value))\n return false;\n seen.add(value);\n if (Array.isArray(value)) {\n if (value.length > MAX_JSON_ITEMS) return false;\n return value.every((item) => isBoundedJsonValue(item, depth + 1, seen));\n }\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) return false;\n const entries = Object.entries(value);\n if (entries.length > MAX_JSON_ITEMS) return false;\n return entries.every(\n ([key, item]) =>\n !FORBIDDEN_JSON_KEYS.has(key) &&\n isBoundedJsonValue(item, depth + 1, seen),\n );\n}\n\nfunction validIdentifier(value: unknown): value is string {\n return (\n typeof value === 'string' &&\n value.length > 0 &&\n value.length <= MAX_IDENTIFIER_LENGTH\n );\n}\n\nfunction validSelection(\n selection: unknown,\n): selection is DataSurfaceSelectionReference {\n if (!selection || typeof selection !== 'object') return false;\n const candidate = selection as Record<string, unknown>;\n if (candidate.scope === 'current-page') return true;\n if (candidate.scope === 'all-matching')\n return validIdentifier(candidate.queryFingerprint);\n if (candidate.scope !== 'explicit-ids' || !Array.isArray(candidate.rowIds))\n return false;\n if (candidate.rowIds.length > MAX_JSON_ITEMS) return false;\n return candidate.rowIds.every(\n (rowId) =>\n (typeof rowId === 'string' && rowId.length > 0) ||\n (typeof rowId === 'number' && Number.isFinite(rowId)),\n );\n}\n\nfunction stable(value: unknown): string {\n if (value === null || typeof value !== 'object') return JSON.stringify(value);\n if (Array.isArray(value)) return `[${value.map(stable).join(',')}]`;\n return `{${Object.entries(value as Record<string, unknown>)\n .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))\n .map(([key, item]) => `${JSON.stringify(key)}:${stable(item)}`)\n .join(',')}}`;\n}\n\nfunction fingerprint(value: unknown): string {\n return createHash('sha256').update(stable(value)).digest('hex');\n}\n\nfunction identityKey(identity: DataSurfaceIdentity): string {\n return stable(canonicalIdentity(identity));\n}\n\nfunction canonicalIdentity(identity: DataSurfaceIdentity): DataSurfaceIdentity {\n return {\n kind: identity.kind,\n surfaceId: identity.surfaceId,\n ...(identity.subject\n ? {\n subject: {\n type: identity.subject.type,\n id: identity.subject.id,\n },\n }\n : {}),\n };\n}\n\nfunction rowIdKey(rowId: DataSurfaceRowId): string {\n return `${typeof rowId}:${String(rowId)}`;\n}\n\nfunction compareRowIds(\n left: DataSurfaceRowId,\n right: DataSurfaceRowId,\n): number {\n if (typeof left !== typeof right) return typeof left === 'number' ? -1 : 1;\n if (typeof left === 'number' && typeof right === 'number')\n return left - right;\n return left < right ? -1 : left > right ? 1 : 0;\n}\n\nfunction canonicalRowIds(\n rowIds: readonly DataSurfaceRowId[],\n): DataSurfaceRowId[] {\n const ids = new Map<string, DataSurfaceRowId>();\n for (const rowId of rowIds) ids.set(rowIdKey(rowId), rowId);\n return [...ids.values()].sort(compareRowIds);\n}\n\nfunction canonicalSelection(\n selection: DataSurfaceSelectionReference,\n): DataSurfaceSelectionReference {\n if (selection.scope !== 'explicit-ids') return selection;\n return { scope: selection.scope, rowIds: canonicalRowIds(selection.rowIds) };\n}\n\nfunction requestFingerprint(request: DataSurfaceServerActionRequest): string {\n return fingerprint({\n identity: canonicalIdentity(request.identity),\n actionId: request.actionId,\n selection: canonicalSelection(request.selection),\n payload: request.payload,\n expectedRevision: request.expectedRevision,\n });\n}\n\nfunction actionFingerprint(action: DataSurfaceServerActionDefinition): string {\n return fingerprint({\n descriptor: action.descriptor,\n inputSchema: action.inputSchema,\n confirmation: action.confirmation,\n execution: action.execution,\n tool: action.tool,\n operationId: action.operation.id,\n operationCollection: action.operation.collection,\n operationAction: action.operation.action,\n });\n}\n\nfunction result(\n request: DataSurfaceServerActionRequest,\n ok: boolean,\n reason?: string,\n details?: DataSurfaceJsonObject,\n confirmationToken?: string,\n): DataSurfaceActionResult {\n return {\n version: 1,\n requestId: request.requestId,\n identity: request.identity,\n actionId: request.actionId,\n phase: request.phase,\n ok,\n ...(reason ? { reason } : {}),\n ...(details ? { details } : {}),\n ...(confirmationToken ? { confirmationToken } : {}),\n };\n}\n\nfunction outcomesDetails(\n outcomes: DataSurfaceActionRowOutcome[],\n extra: DataSurfaceJsonObject = {},\n): DataSurfaceJsonObject {\n const accepted = outcomes.filter(\n ({ status }) => status === 'accepted',\n ).length;\n const skipped = outcomes.filter(({ status }) => status === 'skipped').length;\n const failed = outcomes.filter(({ status }) => status === 'failed').length;\n return {\n accepted,\n skipped,\n failed,\n outcomes: outcomes.map(({ rowId, status, reason }) => ({\n rowId,\n status,\n ...(reason ? { reason } : {}),\n })),\n ...extra,\n };\n}\n\nfunction validateRequest(\n request: DataSurfaceServerActionRequest,\n phase: 'preview' | 'apply',\n): string | undefined {\n if (!request || typeof request !== 'object') return 'invalid_request';\n if (request.version !== 1 || request.phase !== phase)\n return 'invalid_request';\n if (\n !validIdentifier(request.requestId) ||\n !validIdentifier(request.actionId) ||\n !validIdentifier(request.identity?.surfaceId) ||\n !['table', 'list', 'report', 'custom'].includes(request.identity?.kind) ||\n !validSelection(request.selection) ||\n (request.payload !== undefined && !isBoundedJsonValue(request.payload))\n )\n return 'invalid_request';\n if (\n !Number.isSafeInteger(request.expectedRevision) ||\n request.expectedRevision < 0\n )\n return 'invalid_request';\n if (\n phase === 'apply' &&\n (!validIdentifier(request.idempotencyKey) ||\n (request.confirmationToken !== undefined &&\n !validIdentifier(request.confirmationToken)))\n )\n return 'invalid_request';\n return undefined;\n}\n\n/** Create a transport-neutral, principal-bound data-surface action adapter. */\nexport function createDataSurfaceActionAdapter(\n options: DataSurfaceActionAdapterOptions,\n): DataSurfaceActionAdapter {\n const state = options.state;\n const now = options.now ?? Date.now;\n const createToken =\n options.createToken ?? (() => randomBytes(32).toString('base64url'));\n const tokenTtlMs = options.tokenTtlMs ?? DEFAULT_TOKEN_TTL_MS;\n const runAsPrincipal = options.runAsPrincipal ?? executeAsPrincipal;\n const idempotencyPollIntervalMs = Math.max(\n 1,\n options.idempotencyPollIntervalMs ?? 10,\n );\n const idempotencyWaitTimeoutMs = Math.max(\n 0,\n options.idempotencyWaitTimeoutMs ?? 5_000,\n );\n\n async function resolveInvocation(\n request: DataSurfaceServerActionRequest,\n run: PrincipalRun,\n ): Promise<DataSurfaceActionInvocation | DataSurfaceActionResult> {\n const surface = await options.resolveSurface(run, request.identity);\n if (\n identityKey(surface.descriptor.identity) !== identityKey(request.identity)\n ) {\n return result(request, false, 'not_found');\n }\n const action = surface.actions[request.actionId];\n const declared = surface.descriptor.actions.find(\n ({ id }) => id === request.actionId,\n );\n if (\n !action ||\n !declared ||\n action.descriptor.id !== declared.id ||\n Boolean(declared.requiresConfirmation) !==\n (action.confirmation === 'required')\n ) {\n return result(request, false, 'unsupported');\n }\n if (\n !action.tool ||\n !validIdentifier(action.operation?.id) ||\n !validIdentifier(action.operation?.action)\n )\n return result(request, false, 'denied');\n run.assertToolAllowed(action.tool);\n await run.assertOperation(\n action.operation.collection,\n action.operation.action,\n );\n const payloadValidation = await action.validatePayload(request.payload);\n if (!payloadValidation.valid)\n return result(\n request,\n false,\n payloadValidation.reason ?? 'invalid_payload',\n );\n if (!action.descriptor.selectionScopes.includes(request.selection.scope)) {\n return result(request, false, 'selection_not_supported');\n }\n const base = {\n run,\n request,\n descriptor: surface.descriptor,\n action,\n };\n const resolvedSelection = await options.resolveSelection(\n base,\n canonicalSelection(request.selection),\n );\n const selection = {\n ...resolvedSelection,\n rowIds: canonicalRowIds(resolvedSelection.rowIds),\n };\n const invocation = { ...base, selection };\n if (!(await action.authorize(invocation))) {\n return result(request, false, 'denied');\n }\n if (selection.rowIds.length > surface.descriptor.limits.maxSelectionSize) {\n return result(request, false, 'limit_exceeded');\n }\n return invocation;\n }\n\n async function preview(\n request: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n ): Promise<DataSurfaceActionResult> {\n const invalid = validateRequest(request, 'preview');\n if (invalid) return result(request, false, invalid);\n return runAsPrincipal(\n {\n ...context.principal,\n action: 'data_surface.action.preview',\n auditMetadata: {\n ...context.principal.auditMetadata,\n surfaceId: request.identity.surfaceId,\n actionId: request.actionId,\n requestId: request.requestId,\n },\n },\n async (run) => {\n const invocation = await resolveInvocation(request, run);\n if ('ok' in invocation) return invocation;\n if (invocation.selection.revision !== request.expectedRevision) {\n return result(request, false, 'stale_revision');\n }\n const outcomes: DataSurfaceActionRowOutcome[] = [];\n for (const rowId of invocation.selection.rowIds) {\n const eligibility = await invocation.action.eligible(\n invocation,\n rowId,\n );\n outcomes.push({\n rowId,\n status: eligibility.eligible ? 'accepted' : 'skipped',\n ...(eligibility.reason ? { reason: eligibility.reason } : {}),\n });\n }\n const confirmationToken = createToken();\n const selectionFingerprint = fingerprint(\n canonicalSelection(request.selection),\n );\n const requestFingerprintValue = requestFingerprint(request);\n const expiresAt = now() + tokenTtlMs;\n await state.putToken(confirmationToken, {\n expiresAt,\n actorUserId: context.principal.principal.runAsUserId,\n tenantId: context.principal.principal.tenantId,\n onBehalfOfUserId: context.principal.onBehalfOfUserId ?? null,\n actsAsProfileId: context.principal.principal.actsAsProfileId ?? null,\n identityKey: identityKey(request.identity),\n actionId: request.actionId,\n actionFingerprint: actionFingerprint(invocation.action),\n revision: invocation.selection.revision,\n queryFingerprint: invocation.selection.queryFingerprint,\n selectionFingerprint,\n resolvedRowsFingerprint: fingerprint(\n canonicalRowIds(invocation.selection.rowIds),\n ),\n requestFingerprint: requestFingerprintValue,\n });\n return result(\n request,\n true,\n undefined,\n outcomesDetails(outcomes, {\n count: invocation.selection.rowIds.length,\n revision: invocation.selection.revision,\n queryFingerprint: invocation.selection.queryFingerprint,\n expiresAt,\n }),\n confirmationToken,\n );\n },\n );\n }\n\n async function executeForeground(\n request: DataSurfaceServerActionRequest,\n invocation: DataSurfaceActionInvocation,\n ): Promise<DataSurfaceActionResult> {\n const outcomes: DataSurfaceActionRowOutcome[] = [];\n for (const rowId of invocation.selection.rowIds) {\n try {\n const eligibility = await invocation.action.eligible(invocation, rowId);\n if (!eligibility.eligible) {\n outcomes.push({\n rowId,\n status: 'skipped',\n ...(eligibility.reason ? { reason: eligibility.reason } : {}),\n });\n continue;\n }\n await invocation.action.apply(invocation, rowId);\n outcomes.push({ rowId, status: 'accepted' });\n } catch {\n outcomes.push({\n rowId,\n status: 'failed',\n reason: 'execution_failed',\n });\n }\n }\n return result(request, true, undefined, outcomesDetails(outcomes));\n }\n\n async function executeBackgroundOnce(\n request: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n token: DataSurfacePreviewTokenRecord | undefined,\n ): Promise<DataSurfaceActionResult> {\n const ownerToken = randomBytes(16).toString('base64url');\n const executionFingerprint = fingerprint({\n kind: 'background-execution',\n request: token?.requestFingerprint ?? requestFingerprint(request),\n action: token?.actionFingerprint ?? request.actionId,\n });\n const executionScope = fingerprint({\n kind: 'background-execution',\n actorUserId:\n token?.actorUserId ?? context.principal.principal.runAsUserId,\n tenantId: token?.tenantId ?? context.principal.principal.tenantId,\n onBehalfOfUserId:\n token?.onBehalfOfUserId ?? context.principal.onBehalfOfUserId ?? null,\n actsAsProfileId:\n token?.actsAsProfileId ??\n context.principal.principal.actsAsProfileId ??\n null,\n identity: canonicalIdentity(request.identity),\n actionId: request.actionId,\n idempotencyKey: request.idempotencyKey,\n });\n const maxPolls = Math.max(\n 1,\n Math.ceil(idempotencyWaitTimeoutMs / idempotencyPollIntervalMs),\n );\n for (let poll = 0; poll <= maxPolls; poll += 1) {\n const winner = await state.reserveIdempotency(executionScope, {\n requestFingerprint: executionFingerprint,\n ownerToken,\n reservedAt: now(),\n });\n if (winner.requestFingerprint !== executionFingerprint)\n return result(request, false, 'idempotency_conflict');\n if (winner.status === 'completed') return winner.result;\n if (winner.ownerToken === ownerToken) {\n let executed: DataSurfaceActionResult;\n try {\n executed = await authorizedApply(request, context, token, false);\n } catch (error) {\n await state.releaseIdempotency(executionScope, ownerToken);\n throw error;\n }\n if (\n !(await state.completeIdempotency(\n executionScope,\n ownerToken,\n executed,\n ))\n ) {\n throw new Error('Lost background action idempotency reservation');\n }\n return executed;\n }\n if (poll < maxPolls) {\n await new Promise<void>((resolve) =>\n setTimeout(resolve, idempotencyPollIntervalMs),\n );\n const current = await state.getIdempotency(executionScope);\n if (current?.status === 'completed') return current.result;\n }\n }\n return result(request, false, 'idempotency_in_progress');\n }\n\n async function authorizedApply(\n request: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n token: DataSurfacePreviewTokenRecord | undefined,\n allowBackground: boolean,\n ): Promise<DataSurfaceActionResult> {\n const idempotencyKey = request.idempotencyKey;\n if (!idempotencyKey) return result(request, false, 'invalid_request');\n return runAsPrincipal(\n {\n ...context.principal,\n action: 'data_surface.action.apply',\n auditMetadata: {\n ...context.principal.auditMetadata,\n surfaceId: request.identity.surfaceId,\n actionId: request.actionId,\n requestId: request.requestId,\n idempotencyKey: request.idempotencyKey,\n },\n },\n async (run) => {\n const invocation = await resolveInvocation(request, run);\n if ('ok' in invocation) return invocation;\n if (token) {\n if (\n invocation.selection.revision !== token.revision ||\n invocation.selection.revision !== request.expectedRevision ||\n invocation.selection.queryFingerprint !== token.queryFingerprint ||\n fingerprint(canonicalSelection(request.selection)) !==\n token.selectionFingerprint ||\n actionFingerprint(invocation.action) !== token.actionFingerprint ||\n fingerprint(canonicalRowIds(invocation.selection.rowIds)) !==\n token.resolvedRowsFingerprint\n ) {\n return result(request, false, 'stale_preview');\n }\n } else if (invocation.action.confirmation === 'required') {\n return result(request, false, 'confirmation_required');\n } else if (invocation.selection.revision !== request.expectedRevision) {\n return result(request, false, 'stale_revision');\n }\n if (invocation.action.execution === 'background' && allowBackground) {\n if (!options.backgroundQueue) {\n return result(request, false, 'background_unavailable');\n }\n const queued = await options.backgroundQueue.enqueue({\n idempotencyKey,\n identity: request.identity,\n actionId: request.actionId,\n rowIds: invocation.selection.rowIds,\n run: () => executeBackgroundOnce(request, context, token),\n });\n return result(request, true, undefined, {\n accepted: invocation.selection.rowIds.length,\n skipped: 0,\n failed: 0,\n background: true,\n jobId: queued.jobId,\n ...(queued.details ?? {}),\n });\n }\n return executeForeground(request, invocation);\n },\n );\n }\n\n async function apply(\n request: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n ): Promise<DataSurfaceActionResult> {\n const invalid = validateRequest(request, 'apply');\n if (invalid) return result(request, false, invalid);\n const confirmationToken = request.confirmationToken;\n const idempotencyKey = request.idempotencyKey;\n if (!idempotencyKey) return result(request, false, 'invalid_request');\n const actorUserId = context.principal.principal.runAsUserId;\n const tenantId = context.principal.principal.tenantId;\n const onBehalfOfUserId = context.principal.onBehalfOfUserId ?? null;\n const actsAsProfileId = context.principal.principal.actsAsProfileId ?? null;\n const requestFingerprintValue = requestFingerprint(request);\n const idempotencyScope = fingerprint({\n actorUserId,\n tenantId,\n onBehalfOfUserId,\n actsAsProfileId,\n identity: canonicalIdentity(request.identity),\n actionId: request.actionId,\n idempotencyKey,\n });\n const prior = await state.getIdempotency(idempotencyScope);\n if (prior && prior.requestFingerprint !== requestFingerprintValue)\n return result(request, false, 'idempotency_conflict');\n // A completed durable result is safe to replay from its actor/tenant-bound\n // idempotency scope even when the one-time confirmation has expired.\n if (prior?.status === 'completed') return prior.result;\n\n let token: DataSurfacePreviewTokenRecord | undefined;\n if (confirmationToken) {\n token = await state.getToken(confirmationToken);\n if (!token || token.expiresAt <= now()) {\n return result(request, false, 'invalid_or_expired_confirmation');\n }\n if (\n token.actorUserId !== actorUserId ||\n token.tenantId !== tenantId ||\n token.onBehalfOfUserId !== onBehalfOfUserId ||\n token.actsAsProfileId !== actsAsProfileId ||\n token.identityKey !== identityKey(request.identity) ||\n token.actionId !== request.actionId ||\n token.requestFingerprint !== requestFingerprintValue\n ) {\n return result(request, false, 'confirmation_mismatch');\n }\n if (!(await state.markTokenConsumed(confirmationToken, idempotencyKey))) {\n return result(request, false, 'confirmation_replayed');\n }\n }\n // Ownership is an internal compare-and-set nonce. Keep it independent of\n // the injectable preview-token factory, which tests or callers may make\n // deterministic without weakening concurrent winner selection.\n const ownerToken = randomBytes(16).toString('base64url');\n const maxPolls = Math.max(\n 1,\n Math.ceil(idempotencyWaitTimeoutMs / idempotencyPollIntervalMs),\n );\n for (let poll = 0; poll <= maxPolls; poll += 1) {\n const winner = await state.reserveIdempotency(idempotencyScope, {\n requestFingerprint: requestFingerprintValue,\n ownerToken,\n reservedAt: now(),\n });\n if (winner.requestFingerprint !== requestFingerprintValue)\n return result(request, false, 'idempotency_conflict');\n if (winner.status === 'completed') return winner.result;\n if (winner.ownerToken === ownerToken) {\n let applied: DataSurfaceActionResult;\n try {\n applied = await authorizedApply(request, context, token, true);\n } catch (error) {\n await state.releaseIdempotency(idempotencyScope, ownerToken);\n throw error;\n }\n // A confirmation-required request without a token is a recoverable\n // precondition failure. Do not consume its idempotency key: the caller\n // may preview and retry with the same key.\n if (!applied.ok && applied.reason === 'confirmation_required') {\n await state.releaseIdempotency(idempotencyScope, ownerToken);\n return applied;\n }\n // Once execution returns, never release on a persistence failure: a\n // durable reservation is safer than allowing duplicate side effects.\n if (\n !(await state.completeIdempotency(\n idempotencyScope,\n ownerToken,\n applied,\n ))\n ) {\n throw new Error('Lost data-surface idempotency reservation');\n }\n return applied;\n }\n if (poll < maxPolls) {\n await new Promise<void>((resolve) =>\n setTimeout(resolve, idempotencyPollIntervalMs),\n );\n const current = await state.getIdempotency(idempotencyScope);\n if (current?.status === 'completed') return current.result;\n }\n }\n return result(request, false, 'idempotency_in_progress');\n }\n\n return { preview, apply };\n}\n","/**\n * Serialization utilities for resolved agents\n *\n * Converts ResolvedAgentAvailability (database + manifest data) into\n * a JSON-safe shape suitable for passing to client components.\n *\n * @module @happyvertical/smrt-agents/server\n */\n\nimport { sanitizeConfig } from '@happyvertical/smrt-config';\nimport type { ResolvedAgentAvailability } from '../tenant-agent.js';\nimport type { AgentAdminRoute, AgentUISlots } from '../ui.js';\n\n/**\n * Serialized agent data for passing to client components.\n *\n * Includes manifest-derived fields (icon, permissions, slots)\n * alongside resolution metadata (source, sourceTenantId).\n */\nexport interface SerializedAgent {\n /** Agent instance ID, or a synthetic key if no instance exists */\n id: string;\n /** Human-readable name from manifest */\n name?: string;\n /** Human-readable agent class name (e.g., 'Praeco') */\n agentClass: string;\n /** Canonical agent type (qualified name when available) */\n agentType: string;\n /** STI type discriminator (same as agentType) */\n _meta_type?: string;\n /** UI slot definitions from manifest */\n slots?: AgentUISlots;\n /** Admin route declarations from manifest */\n adminRoutes?: AgentAdminRoute[];\n /** How this agent was resolved for the tenant */\n source?: 'explicit' | 'inherited';\n /** Which tenant the binding came from */\n sourceTenantId?: string;\n /** Merged permissions from manifest + tenant overrides */\n permissions?: Record<string, boolean>;\n /** Agent icon from manifest */\n icon?: string;\n /**\n * Tenant-level config overrides, **secret-sanitized** for client transport.\n *\n * SECURITY (#1553, follow-up to #1552): the raw `TenantAgent.config` is the\n * tenant's own override blob and is `@field({ sensitive: true })` (stripped\n * from the generated CRUD api/mcp surfaces). This hand-written admin\n * serialization runs it through `sanitizeConfig()` from\n * `@happyvertical/smrt-config` before it leaves the server, so secret-shaped\n * keys (apiKey/token/password/…) are dropped and secret-shaped values\n * (`sk-…`, `AKIA…`, `Bearer …`, URL credentials, PEM blocks) are masked —\n * non-secret config still reaches the authorized admin UI for display.\n *\n * This is **display-only**: do not edit-round-trip it back to the server\n * (a masked value would overwrite the real secret). Best practice remains to\n * reference secrets by id via `@happyvertical/smrt-secrets` so only an opaque\n * handle is ever stored in tenant config.\n */\n config?: Record<string, unknown>;\n}\n\n/**\n * Convert a ResolvedAgentAvailability to a serializable shape for the UI.\n *\n * @param resolved - Output from TenantAgentCollection.resolveForTenant()\n * @returns Serialized agent data safe for JSON transport\n */\nexport function serializeResolvedAgent(\n resolved: ResolvedAgentAvailability,\n): SerializedAgent {\n const manifest = resolved.manifest;\n\n return {\n id: resolved.agentId || `${resolved.sourceTenantId}:${resolved.agentType}`,\n name: manifest?.name || resolved.agentClass,\n agentClass: resolved.agentClass,\n agentType: resolved.agentType,\n _meta_type: resolved.agentType,\n slots: manifest?.uiSlots as AgentUISlots | undefined,\n adminRoutes: manifest?.adminRoutes as AgentAdminRoute[] | undefined,\n source: resolved.source,\n sourceTenantId: resolved.sourceTenantId,\n permissions: resolved.permissions,\n icon: manifest?.icon,\n // Secret-sanitize before the blob crosses into the client payload (#1553).\n config: sanitizeConfig(resolved.config) as SerializedAgent['config'],\n };\n}\n"],"mappings":";;;;;AAwDO,SAAS,cACd,WACgC;CAChC,MAAM,yBAAS,IAAI,IAA+B;CAElD,KAAA,MAAW,YAAY,WAAW;EAChC,MAAM,cAAe,SAAqC;EAI1D,KAAA,MAAW,OAAO,OAAO,OAAO,SAAS,OAAO,GAAG;GACjD,MAAM,SAAS,IAAI;GACnB,IAAI,CAAC,QAAQ;GAEb,MAAM,MAAM,OAAO;GAGnB,IAAI,CAAC,KAAK,WAAW,IAAI,QAAQ,WAAW,GAAG;GAG/C,MAAM,YAAY,OAAO;GACzB,MAAM,OACJ,IAAI,SAAS,YAAY,UAAU,QAAQ,MAAM,GAAG,IAAI;GAC1D,IAAI,CAAC,MAAM;GAEX,OAAO,IAAI,MAAM;IACf,WAAW,IAAI;IACf,gBAAgB,IAAI;IACpB;GACF,CAAC;EACH;CACF;CAEA,OAAO;AACT;AAcO,SAAS,gBACd,SACA,QACyB;CAEzB,MAAM,aAAa,QAAQ,QAAQ,cAAc,EAAE;CACnD,IAAI,CAAC,YAAY,OAAO;CAExB,MAAM,WAAW,WAAW,MAAM,GAAG;CAGrC,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;KACF,UAAU,MAAM,gBAAgB,SAAS,SAAS,OAAO,IAAI;IAC/D,SAAS,OAAO;KACd,MAAM,MAAM,mBAAmB,kBAAkB,UAAU;KAC3D,MAAM;IACR;IAIA,IAAI,CAAC,QAAQ,MAAM,QAAQ,WAAW,yBAAyB;KAC7D,MAAM,MAAM,mBAAmB,kBAAkB,UAAU;KAC3D,OAAO;IACT;IAGA,IACE,CAAE,MAAM,MAAM,oBACZ,kBACA,YACA,OACF,GAEA,MAAM,IAAI,MAAM,2CAA2C;IAE7D,OAAO;GACT;GACA,IAAI,OAAO,UAAU;IACnB,MAAM,IAAI,SAAe,YACvB,WAAW,SAAS,yBAAyB,CAC/C;IACA,MAAM,UAAU,MAAM,MAAM,eAAe,gBAAgB;IAC3D,IAAI,SAAS,WAAW,aAAa,OAAO,QAAQ;GACtD;EACF;EACA,OAAO,OAAO,SAAS,OAAO,yBAAyB;CACzD;CAEA,OAAO;EAAE;EAAS;CAAM;AAC1B;;;AC33BO,SAAS,uBACd,UACiB;CACjB,MAAM,WAAW,SAAS;CAE1B,OAAO;EACL,IAAI,SAAS,WAAW,GAAG,SAAS,eAAc,GAAI,SAAS;EAC/D,MAAM,UAAU,QAAQ,SAAS;EACjC,YAAY,SAAS;EACrB,WAAW,SAAS;EACpB,YAAY,SAAS;EACrB,OAAO,UAAU;EACjB,aAAa,UAAU;EACvB,QAAQ,SAAS;EACjB,gBAAgB,SAAS;EACzB,aAAa,SAAS;EACtB,MAAM,UAAU;EAEhB,QAAQ,eAAe,SAAS,MAAM;CACxC;AACF"}
|
|
1
|
+
{"version":3,"file":"server.js","names":["result"],"sources":["../src/server/api-routes.ts","../src/server/config-loader.ts","../src/server/data-surface-actions.ts","../src/server/serialization.ts"],"sourcesContent":["/**\n * Server-side API route resolution for SMRT agents\n *\n * Reads agent package manifests and builds a route map from resource\n * paths (e.g., 'performers', 'video-contents') to SmrtObject class\n * names and allowed CRUD actions. The catch-all API handler uses this\n * to resolve incoming requests.\n *\n * @module @happyvertical/smrt-agents/server\n */\n\nimport type { PackageManifest } from './manifest-utils.js';\n\n/**\n * Info about a single API route (one SmrtObject with api.include)\n */\nexport interface AgentAPIRouteInfo {\n /** SmrtObject class name (e.g., 'Performer') */\n className: string;\n /** Allowed CRUD actions (e.g., ['list', 'get', 'create', 'update', 'delete']) */\n allowedActions: string[];\n /** Package that owns this resource */\n packageName?: string;\n}\n\n/**\n * Result of resolving a URL path against the route map\n */\nexport interface ResolvedAPIRoute {\n /** The matched route info */\n route: AgentAPIRouteInfo;\n /** Resource ID if path includes one (e.g., 'performers/abc-123') */\n id?: string;\n /** Custom action name if path includes one (e.g., 'performers/abc-123/generate-image') */\n action?: string;\n}\n\n/**\n * Build a route map from loaded package manifests.\n *\n * Iterates all objects in each manifest, and for any object with a\n * `decoratorConfig.api.include` array, registers a route. The route\n * path is derived from `decoratorConfig.api.path` if set, otherwise\n * from the table name with underscores converted to hyphens.\n *\n * @param manifests - Array of parsed package manifest JSON objects\n * @returns Map of resource path -> route info\n *\n * @example\n * ```typescript\n * const manifests = [histrioManifest, praecoManifest];\n * const routes = buildRouteMap(manifests);\n * // routes.get('performers') => { className: 'Performer', allowedActions: ['list', 'get', 'create', 'update', 'delete'] }\n * // routes.get('video-contents') => { className: 'VideoShot', allowedActions: ['list', 'get', 'create', 'update'] }\n * ```\n */\nexport function buildRouteMap(\n manifests: PackageManifest[],\n): Map<string, AgentAPIRouteInfo> {\n const routes = new Map<string, AgentAPIRouteInfo>();\n\n for (const manifest of manifests) {\n const packageName = (manifest as Record<string, unknown>).packageName as\n | string\n | undefined;\n\n for (const obj of Object.values(manifest.objects)) {\n const config = obj.decoratorConfig as Record<string, unknown> | undefined;\n if (!config) continue;\n\n const api = config.api as\n | { include?: string[]; path?: string }\n | undefined;\n if (!api?.include || api.include.length === 0) continue;\n\n // Derive the URL path: explicit api.path, or table name with _ -> -\n const tableName = config.tableName as string | undefined;\n const path =\n api.path || (tableName ? tableName.replace(/_/g, '-') : null);\n if (!path) continue;\n\n routes.set(path, {\n className: obj.className,\n allowedActions: api.include,\n packageName,\n });\n }\n }\n\n return routes;\n}\n\n/**\n * Resolve a URL resource path against a route map.\n *\n * Handles three URL patterns:\n * - `performers` → list/create (no id)\n * - `performers/abc-123` → get/update/delete (with id)\n * - `performers/abc-123/generate-image` → custom action\n *\n * @param urlPath - The resource portion of the URL (after `/api/agents/{agentId}/`)\n * @param routes - Route map from {@link buildRouteMap}\n * @returns Resolved route with optional id/action, or null if no match\n */\nexport function resolveAPIRoute(\n urlPath: string,\n routes: Map<string, AgentAPIRouteInfo>,\n): ResolvedAPIRoute | null {\n // Normalize: strip leading/trailing slashes\n const normalized = urlPath.replace(/^\\/+|\\/+$/g, '');\n if (!normalized) return null;\n\n const segments = normalized.split('/');\n\n // Try 1-segment: \"performers\"\n if (segments.length === 1) {\n const route = routes.get(segments[0]);\n if (route) return { route };\n return null;\n }\n\n // Try 2-segment: \"performers/{id}\"\n if (segments.length === 2) {\n const route = routes.get(segments[0]);\n if (route) return { route, id: segments[1] };\n return null;\n }\n\n // Try 3-segment: \"performers/{id}/{action}\"\n if (segments.length === 3) {\n const route = routes.get(segments[0]);\n if (route) return { route, id: segments[1], action: segments[2] };\n return null;\n }\n\n return null;\n}\n","/**\n * Server-side agent config loading utilities\n *\n * Loads slot configurations from the agent_configs table for a set of agents.\n * Agent-specific table loading (e.g., praeco_sources) stays in the host app.\n *\n * @module @happyvertical/smrt-agents/server\n */\n\nimport type { SmrtClassOptions } from '@happyvertical/smrt-core';\nimport { AgentConfig } from '../config.js';\n\n/**\n * Load slot configs for multiple agents from the agent_configs table.\n *\n * Returns a nested map: agentId -> slotId -> configData.\n * Agent-specific tables (e.g., praeco_sources, praeco_reports)\n * are NOT loaded here — those stay in the host application.\n *\n * @param agents - Array of agent identifiers (id + agentClass)\n * @param dbOptions - Database options for SmrtCollection.create()\n * @returns Map of agentId -> slotId -> config data\n */\nexport async function loadSlotConfigs(\n agents: Array<{ id: string; agentClass: string }>,\n dbOptions: SmrtClassOptions,\n): Promise<Record<string, Record<string, unknown>>> {\n if (agents.length === 0) {\n return {};\n }\n\n try {\n const configsByAgent = await AgentConfig.forAgents(\n agents.map((agent) => agent.id),\n dbOptions,\n );\n\n const configs: Record<string, Record<string, unknown>> = {};\n for (const [agentId, slotConfigs] of configsByAgent) {\n const agentConfig: Record<string, unknown> = {};\n for (const [slotId, configData] of slotConfigs) {\n agentConfig[slotId] = configData;\n }\n if (Object.keys(agentConfig).length > 0) {\n configs[agentId] = agentConfig;\n }\n }\n\n return configs;\n } catch (error) {\n if (isMissingAgentConfigTableError(error)) {\n return {};\n }\n throw error;\n }\n}\n\nfunction isMissingAgentConfigTableError(error: unknown): boolean {\n const message = String((error as Error)?.message || error || '');\n\n return (\n message.includes(\"Run 'smrt db:migrate'\") ||\n /no such table[:\\s]+agent_configs/i.test(message) ||\n /relation .*agent_configs.*does not exist/i.test(message) ||\n /table .*agent_configs.*doesn'?t exist/i.test(message)\n );\n}\n","/**\n * Principal-bound preview/apply orchestration for data-surface actions.\n *\n * Browser state is treated only as an input hint. Every preview and apply is\n * executed under the bound principal, resolves the surface and selection\n * afresh, and delegates durable work only after authorization and eligibility\n * checks have passed.\n */\nimport { createHash, randomBytes } from 'node:crypto';\nimport type {\n DataSurfaceActionDescriptor,\n DataSurfaceActionRequest,\n DataSurfaceActionResult,\n DataSurfaceDescriptor,\n DataSurfaceIdentity,\n DataSurfaceJsonObject,\n DataSurfaceJsonValue,\n DataSurfaceRowId,\n DataSurfaceSelectionReference,\n} from '@happyvertical/smrt-ui/data';\nimport {\n type ExecuteAsPrincipalOptions,\n executeAsPrincipal,\n type PrincipalRun,\n} from '../execute-as-principal.js';\n\nexport type DataSurfaceConfirmationPolicy = 'required' | 'none';\nexport type DataSurfaceActionExecution = 'foreground' | 'background';\n\nexport interface DataSurfaceActionEligibility {\n eligible: boolean;\n reason?: string;\n}\n\nexport type DataSurfaceActionPayloadValidation =\n | { valid: true }\n | { valid: false; reason?: string };\n\nexport interface DataSurfaceActionRowOutcome {\n rowId: DataSurfaceRowId;\n status: 'accepted' | 'skipped' | 'failed';\n reason?: string;\n}\n\nexport interface ResolvedDataSurfaceSelection {\n /** Fresh server-side revision of the selected surface/query. */\n revision: number;\n /** Canonical fingerprint of the frozen query represented by the selection. */\n queryFingerprint: string;\n /** Authoritatively resolved row ids. Browser-provided ids are only hints. */\n rowIds: DataSurfaceRowId[];\n}\n\nexport interface DataSurfaceActionInvocation {\n run: PrincipalRun;\n request: DataSurfaceServerActionRequest;\n descriptor: DataSurfaceDescriptor;\n action: DataSurfaceServerActionDefinition;\n selection: ResolvedDataSurfaceSelection;\n}\n\nexport interface DataSurfaceServerActionDefinition {\n descriptor: DataSurfaceActionDescriptor;\n /** Serializable declaration for transport/schema generators; null means no input. */\n inputSchema: DataSurfaceJsonObject | null;\n /** Runtime enforcement for the declared schema; absence is never permissive. */\n validatePayload(\n payload: DataSurfaceJsonValue | undefined,\n ):\n | DataSurfaceActionPayloadValidation\n | Promise<DataSurfaceActionPayloadValidation>;\n /** Explicit for every action, including sensitive/public/destructive ones. */\n confirmation: DataSurfaceConfirmationPolicy;\n execution: DataSurfaceActionExecution;\n /** Fail-closed persona capability checked by PrincipalRun. */\n tool: string;\n /** Explicit RBAC catalog gate, enforced independently of callback convention. */\n operation: {\n id: string;\n collection: Parameters<PrincipalRun['assertOperation']>[0];\n action: string;\n };\n /** Fresh permission/domain authorization check, run for preview and apply. */\n authorize(\n invocation: DataSurfaceActionInvocation,\n ): boolean | Promise<boolean>;\n /** Fresh per-row domain precondition check, repeated at apply time. */\n eligible(\n invocation: DataSurfaceActionInvocation,\n rowId: DataSurfaceRowId,\n ): DataSurfaceActionEligibility | Promise<DataSurfaceActionEligibility>;\n /** Foreground mutation. Background definitions are run by the injected queue. */\n apply(\n invocation: DataSurfaceActionInvocation,\n rowId: DataSurfaceRowId,\n ):\n | undefined\n | DataSurfaceJsonValue\n | Promise<undefined | DataSurfaceJsonValue>;\n}\n\nexport interface ResolvedDataSurfaceActions {\n descriptor: DataSurfaceDescriptor;\n /** Current server-side revision, never trusted from the browser. */\n revision: number;\n actions: Record<string, DataSurfaceServerActionDefinition>;\n}\n\nexport interface DataSurfaceServerActionRequest\n extends DataSurfaceActionRequest {\n /** Required on apply and bound into the preview token. */\n expectedRevision: number;\n /** Required on apply. Identical retries replay the first terminal result. */\n idempotencyKey?: string;\n}\n\nexport interface DataSurfaceActionContext {\n principal: ExecuteAsPrincipalOptions;\n}\n\nexport interface DataSurfaceBackgroundActionJob {\n idempotencyKey: string;\n identity: DataSurfaceIdentity;\n actionId: string;\n rowIds: DataSurfaceRowId[];\n /**\n * The queue must call this task to perform the work. It re-enters the bound\n * principal and repeats descriptor, authorization, selection, and eligibility\n * checks before any mutation.\n */\n run: () => Promise<DataSurfaceActionResult>;\n}\n\nexport interface DataSurfaceBackgroundQueue {\n enqueue(\n job: DataSurfaceBackgroundActionJob,\n ): Promise<{ jobId: string; details?: DataSurfaceJsonObject }>;\n}\n\nexport interface DataSurfacePreviewTokenRecord {\n expiresAt: number;\n actorUserId: string;\n tenantId: string | null;\n onBehalfOfUserId: string | null;\n actsAsProfileId: string | null;\n agentClass: string | null;\n identityKey: string;\n actionId: string;\n actionFingerprint: string;\n revision: number;\n queryFingerprint: string;\n selectionFingerprint: string;\n resolvedRowsFingerprint: string;\n requestFingerprint: string;\n consumedBy?: string;\n}\n\nexport type DataSurfaceIdempotencyRecord =\n | {\n status: 'reserved';\n requestFingerprint: string;\n ownerToken: string;\n reservedAt: number;\n }\n | {\n status: 'completed';\n requestFingerprint: string;\n result: DataSurfaceActionResult;\n };\n\nexport interface DataSurfaceIdempotencyReservation {\n requestFingerprint: string;\n ownerToken: string;\n reservedAt: number;\n}\n\nexport interface DataSurfaceActionStateStore {\n putToken(\n token: string,\n record: DataSurfacePreviewTokenRecord,\n ): Promise<void> | void;\n getToken(\n token: string,\n ):\n | Promise<DataSurfacePreviewTokenRecord | undefined>\n | DataSurfacePreviewTokenRecord\n | undefined;\n markTokenConsumed(\n token: string,\n idempotencyKey: string,\n ): Promise<boolean> | boolean;\n getIdempotency(\n key: string,\n ):\n | Promise<DataSurfaceIdempotencyRecord | undefined>\n | DataSurfaceIdempotencyRecord\n | undefined;\n /** Atomically create a durable reservation or return the existing record. */\n reserveIdempotency(\n key: string,\n reservation: DataSurfaceIdempotencyReservation,\n ): Promise<DataSurfaceIdempotencyRecord> | DataSurfaceIdempotencyRecord;\n completeIdempotency(\n key: string,\n ownerToken: string,\n result: DataSurfaceActionResult,\n ): Promise<boolean> | boolean;\n releaseIdempotency(\n key: string,\n ownerToken: string,\n ): Promise<boolean> | boolean;\n}\n\n/** Explicit single-process/testing store; production callers inject shared state. */\nexport class InMemoryDataSurfaceActionStateStore\n implements DataSurfaceActionStateStore\n{\n private readonly tokens = new Map<string, DataSurfacePreviewTokenRecord>();\n private readonly idempotency = new Map<\n string,\n DataSurfaceIdempotencyRecord\n >();\n\n putToken(token: string, record: DataSurfacePreviewTokenRecord): void {\n this.tokens.set(token, record);\n }\n\n getToken(token: string): DataSurfacePreviewTokenRecord | undefined {\n return this.tokens.get(token);\n }\n\n markTokenConsumed(token: string, idempotencyKey: string): boolean {\n const record = this.tokens.get(token);\n if (!record) return false;\n if (record.consumedBy && record.consumedBy !== idempotencyKey) return false;\n record.consumedBy = idempotencyKey;\n return true;\n }\n\n getIdempotency(key: string): DataSurfaceIdempotencyRecord | undefined {\n return this.idempotency.get(key);\n }\n\n reserveIdempotency(\n key: string,\n reservation: DataSurfaceIdempotencyReservation,\n ): DataSurfaceIdempotencyRecord {\n const existing = this.idempotency.get(key);\n if (existing) return existing;\n const record: DataSurfaceIdempotencyRecord = {\n status: 'reserved',\n ...reservation,\n };\n this.idempotency.set(key, record);\n return record;\n }\n\n completeIdempotency(\n key: string,\n ownerToken: string,\n result: DataSurfaceActionResult,\n ): boolean {\n const existing = this.idempotency.get(key);\n if (existing?.status !== 'reserved' || existing.ownerToken !== ownerToken)\n return false;\n this.idempotency.set(key, {\n status: 'completed',\n requestFingerprint: existing.requestFingerprint,\n result,\n });\n return true;\n }\n\n releaseIdempotency(key: string, ownerToken: string): boolean {\n const existing = this.idempotency.get(key);\n if (existing?.status !== 'reserved' || existing.ownerToken !== ownerToken)\n return false;\n return this.idempotency.delete(key);\n }\n}\n\nexport interface DataSurfaceActionAdapterOptions {\n resolveSurface(\n run: PrincipalRun,\n identity: DataSurfaceIdentity,\n ): Promise<ResolvedDataSurfaceActions>;\n resolveSelection(\n invocation: Omit<DataSurfaceActionInvocation, 'selection'>,\n selection: DataSurfaceSelectionReference,\n ): Promise<ResolvedDataSurfaceSelection>;\n backgroundQueue?: DataSurfaceBackgroundQueue;\n /** Required durable, shared backend in production; memory storage is opt-in. */\n state: DataSurfaceActionStateStore;\n tokenTtlMs?: number;\n now?: () => number;\n createToken?: () => string;\n runAsPrincipal?: typeof executeAsPrincipal;\n /**\n * Re-resolve the complete current binding immediately before deferred work.\n * Background execution fails closed when this seam is absent or returns a\n * binding for a different principal.\n */\n resolveDeferredPrincipal?(\n reference: Readonly<{\n runAsUserId: string;\n tenantId: string | null;\n actsAsProfileId: string | null;\n onBehalfOfUserId: string | null;\n agentClass?: string;\n }>,\n ): ExecuteAsPrincipalOptions | Promise<ExecuteAsPrincipalOptions>;\n idempotencyPollIntervalMs?: number;\n idempotencyWaitTimeoutMs?: number;\n /** Domain-specific request input that must participate in confirmation/idempotency. */\n requestFingerprintExtension?(\n request: DataSurfaceServerActionRequest,\n ): DataSurfaceJsonValue | undefined;\n /** Maps terminal domain failures; return undefined to preserve queue retries. */\n mapError?(\n error: unknown,\n request: DataSurfaceServerActionRequest,\n ): string | undefined;\n}\n\nexport interface DataSurfaceActionAdapter {\n preview(\n request: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n ): Promise<DataSurfaceActionResult>;\n apply(\n request: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n ): Promise<DataSurfaceActionResult>;\n}\n\nconst DEFAULT_TOKEN_TTL_MS = 5 * 60 * 1_000;\nconst MAX_IDENTIFIER_LENGTH = 256;\nconst MAX_JSON_DEPTH = 16;\nconst MAX_JSON_ITEMS = 1_000;\nconst FORBIDDEN_JSON_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\nfunction isBoundedJsonValue(\n value: unknown,\n depth = 0,\n seen = new Set<object>(),\n): value is DataSurfaceJsonValue {\n if (value === null) return true;\n if (['string', 'boolean'].includes(typeof value)) return true;\n if (typeof value === 'number') return Number.isFinite(value);\n if (typeof value !== 'object' || depth >= MAX_JSON_DEPTH || seen.has(value))\n return false;\n seen.add(value);\n if (Array.isArray(value)) {\n if (value.length > MAX_JSON_ITEMS) return false;\n return value.every((item) => isBoundedJsonValue(item, depth + 1, seen));\n }\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) return false;\n const entries = Object.entries(value);\n if (entries.length > MAX_JSON_ITEMS) return false;\n return entries.every(\n ([key, item]) =>\n !FORBIDDEN_JSON_KEYS.has(key) &&\n isBoundedJsonValue(item, depth + 1, seen),\n );\n}\n\n/** Validates untrusted extension values before they enter canonical hashing. */\nexport function isBoundedDataSurfaceJsonValue(\n value: unknown,\n): value is DataSurfaceJsonValue {\n return isBoundedJsonValue(value);\n}\n\nfunction validIdentifier(value: unknown): value is string {\n return (\n typeof value === 'string' &&\n value.length > 0 &&\n value.length <= MAX_IDENTIFIER_LENGTH\n );\n}\n\nfunction validSelection(\n selection: unknown,\n): selection is DataSurfaceSelectionReference {\n if (!selection || typeof selection !== 'object') return false;\n const candidate = selection as Record<string, unknown>;\n if (candidate.scope === 'current-page') return true;\n if (candidate.scope === 'all-matching')\n return validIdentifier(candidate.queryFingerprint);\n if (candidate.scope !== 'explicit-ids' || !Array.isArray(candidate.rowIds))\n return false;\n if (candidate.rowIds.length > MAX_JSON_ITEMS) return false;\n return candidate.rowIds.every(\n (rowId) =>\n (typeof rowId === 'string' && rowId.length > 0) ||\n (typeof rowId === 'number' && Number.isFinite(rowId)),\n );\n}\n\nfunction stable(value: unknown): string {\n if (value === null || typeof value !== 'object') return JSON.stringify(value);\n if (Array.isArray(value)) return `[${value.map(stable).join(',')}]`;\n return `{${Object.entries(value as Record<string, unknown>)\n .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))\n .map(([key, item]) => `${JSON.stringify(key)}:${stable(item)}`)\n .join(',')}}`;\n}\n\nfunction fingerprint(value: unknown): string {\n return createHash('sha256').update(stable(value)).digest('hex');\n}\n\nfunction identityKey(identity: DataSurfaceIdentity): string {\n return stable(canonicalIdentity(identity));\n}\n\nfunction canonicalIdentity(identity: DataSurfaceIdentity): DataSurfaceIdentity {\n return {\n kind: identity.kind,\n surfaceId: identity.surfaceId,\n ...(identity.subject\n ? {\n subject: {\n type: identity.subject.type,\n id: identity.subject.id,\n },\n }\n : {}),\n };\n}\n\nfunction rowIdKey(rowId: DataSurfaceRowId): string {\n return `${typeof rowId}:${String(rowId)}`;\n}\n\nfunction compareRowIds(\n left: DataSurfaceRowId,\n right: DataSurfaceRowId,\n): number {\n if (typeof left !== typeof right) return typeof left === 'number' ? -1 : 1;\n if (typeof left === 'number' && typeof right === 'number')\n return left - right;\n return left < right ? -1 : left > right ? 1 : 0;\n}\n\nfunction canonicalRowIds(\n rowIds: readonly DataSurfaceRowId[],\n): DataSurfaceRowId[] {\n const ids = new Map<string, DataSurfaceRowId>();\n for (const rowId of rowIds) ids.set(rowIdKey(rowId), rowId);\n return [...ids.values()].sort(compareRowIds);\n}\n\nfunction canonicalSelection(\n selection: DataSurfaceSelectionReference,\n): DataSurfaceSelectionReference {\n if (selection.scope !== 'explicit-ids') return selection;\n return { scope: selection.scope, rowIds: canonicalRowIds(selection.rowIds) };\n}\n\nfunction requestFingerprint(\n request: DataSurfaceServerActionRequest,\n extension?: DataSurfaceJsonValue,\n): string {\n return fingerprint({\n identity: canonicalIdentity(request.identity),\n actionId: request.actionId,\n selection: canonicalSelection(request.selection),\n payload: request.payload,\n expectedRevision: request.expectedRevision,\n ...(extension === undefined ? {} : { extension }),\n });\n}\n\nfunction deepFreeze<T>(value: T, seen = new WeakSet<object>()): T {\n if (!value || typeof value !== 'object' || seen.has(value)) return value;\n seen.add(value);\n for (const nested of Object.values(value)) deepFreeze(nested, seen);\n Object.freeze(value);\n return value;\n}\n\nfunction snapshotRequest(\n request: DataSurfaceServerActionRequest,\n): DataSurfaceServerActionRequest {\n return deepFreeze(structuredClone(request));\n}\n\nfunction snapshotActionContext(\n context: DataSurfaceActionContext,\n): DataSurfaceActionContext {\n const principal = {\n ...context.principal.principal,\n ...(context.principal.principal.allowedTools\n ? { allowedTools: [...context.principal.principal.allowedTools] }\n : {}),\n };\n if (principal.allowedTools) Object.freeze(principal.allowedTools);\n Object.freeze(principal);\n const permissions = context.principal.permissions\n ? [...context.principal.permissions]\n : undefined;\n if (permissions) Object.freeze(permissions);\n const auditMetadata = context.principal.auditMetadata\n ? deepFreeze(structuredClone(context.principal.auditMetadata))\n : undefined;\n const principalOptions: ExecuteAsPrincipalOptions = {\n ...context.principal,\n principal,\n ...(permissions ? { permissions } : {}),\n ...(auditMetadata ? { auditMetadata } : {}),\n };\n Object.freeze(principalOptions);\n return Object.freeze({ principal: principalOptions });\n}\n\nfunction actionFingerprint(action: DataSurfaceServerActionDefinition): string {\n return fingerprint({\n descriptor: action.descriptor,\n inputSchema: action.inputSchema,\n confirmation: action.confirmation,\n execution: action.execution,\n tool: action.tool,\n operationId: action.operation.id,\n operationCollection: action.operation.collection,\n operationAction: action.operation.action,\n });\n}\n\nfunction result(\n request: DataSurfaceServerActionRequest,\n ok: boolean,\n reason?: string,\n details?: DataSurfaceJsonObject,\n confirmationToken?: string,\n): DataSurfaceActionResult {\n return {\n version: 1,\n requestId: request.requestId,\n identity: request.identity,\n actionId: request.actionId,\n phase: request.phase,\n ok,\n ...(reason ? { reason } : {}),\n ...(details ? { details } : {}),\n ...(confirmationToken ? { confirmationToken } : {}),\n };\n}\n\nfunction replayResult(\n request: DataSurfaceServerActionRequest,\n stored: DataSurfaceActionResult,\n): DataSurfaceActionResult {\n // Idempotency keys identify one logical execution, but each transport retry\n // has its own correlation id. Preserve the stored outcome while binding the\n // replay envelope to the request that is receiving it.\n return { ...stored, requestId: request.requestId };\n}\n\nfunction outcomesDetails(\n outcomes: DataSurfaceActionRowOutcome[],\n extra: DataSurfaceJsonObject = {},\n): DataSurfaceJsonObject {\n const accepted = outcomes.filter(\n ({ status }) => status === 'accepted',\n ).length;\n const skipped = outcomes.filter(({ status }) => status === 'skipped').length;\n const failed = outcomes.filter(({ status }) => status === 'failed').length;\n return {\n accepted,\n skipped,\n failed,\n outcomes: outcomes.map(({ rowId, status, reason }) => ({\n rowId,\n status,\n ...(reason ? { reason } : {}),\n })),\n ...extra,\n };\n}\n\nfunction validateRequest(\n request: DataSurfaceServerActionRequest,\n phase: 'preview' | 'apply',\n): string | undefined {\n if (!request || typeof request !== 'object') return 'invalid_request';\n if (request.version !== 1 || request.phase !== phase)\n return 'invalid_request';\n if (\n !validIdentifier(request.requestId) ||\n !validIdentifier(request.actionId) ||\n !validIdentifier(request.identity?.surfaceId) ||\n !['table', 'list', 'report', 'custom'].includes(request.identity?.kind) ||\n !validSelection(request.selection) ||\n (request.payload !== undefined && !isBoundedJsonValue(request.payload))\n )\n return 'invalid_request';\n if (\n !Number.isSafeInteger(request.expectedRevision) ||\n request.expectedRevision < 0\n )\n return 'invalid_request';\n if (\n phase === 'apply' &&\n (!validIdentifier(request.idempotencyKey) ||\n (request.confirmationToken !== undefined &&\n !validIdentifier(request.confirmationToken)))\n )\n return 'invalid_request';\n return undefined;\n}\n\n/** Create a transport-neutral, principal-bound data-surface action adapter. */\nexport function createDataSurfaceActionAdapter(\n options: DataSurfaceActionAdapterOptions,\n): DataSurfaceActionAdapter {\n const state = options.state;\n const now = options.now ?? Date.now;\n const createToken =\n options.createToken ?? (() => randomBytes(32).toString('base64url'));\n const tokenTtlMs = options.tokenTtlMs ?? DEFAULT_TOKEN_TTL_MS;\n const runAsPrincipal = options.runAsPrincipal ?? executeAsPrincipal;\n const idempotencyPollIntervalMs = Math.max(\n 1,\n options.idempotencyPollIntervalMs ?? 10,\n );\n const idempotencyWaitTimeoutMs = Math.max(\n 0,\n options.idempotencyWaitTimeoutMs ?? 5_000,\n );\n const fingerprintRequest = (request: DataSurfaceServerActionRequest) =>\n requestFingerprint(request, options.requestFingerprintExtension?.(request));\n\n async function resolveInvocation(\n request: DataSurfaceServerActionRequest,\n run: PrincipalRun,\n ): Promise<DataSurfaceActionInvocation | DataSurfaceActionResult> {\n const surface = await options.resolveSurface(run, request.identity);\n if (\n identityKey(surface.descriptor.identity) !== identityKey(request.identity)\n ) {\n return result(request, false, 'not_found');\n }\n const action = surface.actions[request.actionId];\n const declared = surface.descriptor.actions.find(\n ({ id }) => id === request.actionId,\n );\n if (\n !action ||\n !declared ||\n action.descriptor.id !== declared.id ||\n Boolean(declared.requiresConfirmation) !==\n (action.confirmation === 'required')\n ) {\n return result(request, false, 'unsupported');\n }\n if (\n !action.tool ||\n !validIdentifier(action.operation?.id) ||\n !validIdentifier(action.operation?.action)\n )\n return result(request, false, 'denied');\n run.assertToolAllowed(action.tool);\n await run.assertOperation(\n action.operation.collection,\n action.operation.action,\n );\n const payloadValidation = await action.validatePayload(request.payload);\n if (!payloadValidation.valid)\n return result(\n request,\n false,\n payloadValidation.reason ?? 'invalid_payload',\n );\n if (\n !declared.selectionScopes.includes(request.selection.scope) ||\n !action.descriptor.selectionScopes.includes(request.selection.scope)\n ) {\n return result(request, false, 'selection_not_supported');\n }\n const base = {\n run,\n request,\n descriptor: surface.descriptor,\n action,\n };\n const resolvedSelection = await options.resolveSelection(\n base,\n canonicalSelection(request.selection),\n );\n const selection = {\n ...resolvedSelection,\n rowIds: canonicalRowIds(resolvedSelection.rowIds),\n };\n const invocation = { ...base, selection };\n if (!(await action.authorize(invocation))) {\n return result(request, false, 'denied');\n }\n if (selection.rowIds.length > surface.descriptor.limits.maxSelectionSize) {\n return result(request, false, 'limit_exceeded');\n }\n return invocation;\n }\n\n async function preview(\n request: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n ): Promise<DataSurfaceActionResult> {\n const invalid = validateRequest(request, 'preview');\n if (invalid) return result(request, false, invalid);\n const boundContext = snapshotActionContext(context);\n return runAsPrincipal(\n {\n ...boundContext.principal,\n action: 'data_surface.action.preview',\n auditMetadata: {\n ...boundContext.principal.auditMetadata,\n surfaceId: request.identity.surfaceId,\n actionId: request.actionId,\n requestId: request.requestId,\n },\n },\n async (run) => {\n const invocation = await resolveInvocation(request, run);\n if ('ok' in invocation) return invocation;\n if (invocation.selection.revision !== request.expectedRevision) {\n return result(request, false, 'stale_revision');\n }\n const outcomes: DataSurfaceActionRowOutcome[] = [];\n for (const rowId of invocation.selection.rowIds) {\n const eligibility = await invocation.action.eligible(\n invocation,\n rowId,\n );\n outcomes.push({\n rowId,\n status: eligibility.eligible ? 'accepted' : 'skipped',\n ...(eligibility.reason ? { reason: eligibility.reason } : {}),\n });\n }\n const confirmationToken = createToken();\n const selectionFingerprint = fingerprint(\n canonicalSelection(request.selection),\n );\n const requestFingerprintValue = fingerprintRequest(request);\n const expiresAt = now() + tokenTtlMs;\n await state.putToken(confirmationToken, {\n expiresAt,\n actorUserId: boundContext.principal.principal.runAsUserId,\n tenantId: boundContext.principal.principal.tenantId,\n onBehalfOfUserId: boundContext.principal.onBehalfOfUserId ?? null,\n actsAsProfileId:\n boundContext.principal.principal.actsAsProfileId ?? null,\n agentClass: boundContext.principal.agentClass ?? null,\n identityKey: identityKey(request.identity),\n actionId: request.actionId,\n actionFingerprint: actionFingerprint(invocation.action),\n revision: invocation.selection.revision,\n queryFingerprint: invocation.selection.queryFingerprint,\n selectionFingerprint,\n resolvedRowsFingerprint: fingerprint(\n canonicalRowIds(invocation.selection.rowIds),\n ),\n requestFingerprint: requestFingerprintValue,\n });\n return result(\n request,\n true,\n undefined,\n outcomesDetails(outcomes, {\n count: invocation.selection.rowIds.length,\n revision: invocation.selection.revision,\n queryFingerprint: invocation.selection.queryFingerprint,\n expiresAt,\n }),\n confirmationToken,\n );\n },\n );\n }\n\n async function executeForeground(\n request: DataSurfaceServerActionRequest,\n invocation: DataSurfaceActionInvocation,\n ): Promise<DataSurfaceActionResult> {\n const outcomes: DataSurfaceActionRowOutcome[] = [];\n for (const rowId of invocation.selection.rowIds) {\n try {\n const eligibility = await invocation.action.eligible(invocation, rowId);\n if (!eligibility.eligible) {\n outcomes.push({\n rowId,\n status: 'skipped',\n ...(eligibility.reason ? { reason: eligibility.reason } : {}),\n });\n continue;\n }\n await invocation.action.apply(invocation, rowId);\n outcomes.push({ rowId, status: 'accepted' });\n } catch (error) {\n outcomes.push({\n rowId,\n status: 'failed',\n reason: options.mapError?.(error, request) ?? 'execution_failed',\n });\n }\n }\n return result(request, true, undefined, outcomesDetails(outcomes));\n }\n\n async function executeBackgroundOnce(\n request: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n token: DataSurfacePreviewTokenRecord | undefined,\n reference: Readonly<{\n runAsUserId: string;\n tenantId: string | null;\n actsAsProfileId: string | null;\n onBehalfOfUserId: string | null;\n agentClass?: string;\n }>,\n ): Promise<DataSurfaceActionResult> {\n const ownerToken = randomBytes(16).toString('base64url');\n const executionFingerprint = fingerprint({\n kind: 'background-execution',\n request: token?.requestFingerprint ?? fingerprintRequest(request),\n action: token?.actionFingerprint ?? request.actionId,\n });\n const executionScope = fingerprint({\n kind: 'background-execution',\n actorUserId: reference.runAsUserId,\n tenantId: reference.tenantId,\n onBehalfOfUserId: reference.onBehalfOfUserId,\n actsAsProfileId: reference.actsAsProfileId,\n agentClass: reference.agentClass ?? null,\n identity: canonicalIdentity(request.identity),\n actionId: request.actionId,\n idempotencyKey: request.idempotencyKey,\n });\n const maxPolls = Math.max(\n 1,\n Math.ceil(idempotencyWaitTimeoutMs / idempotencyPollIntervalMs),\n );\n for (let poll = 0; poll <= maxPolls; poll += 1) {\n const winner = await state.reserveIdempotency(executionScope, {\n requestFingerprint: executionFingerprint,\n ownerToken,\n reservedAt: now(),\n });\n if (winner.requestFingerprint !== executionFingerprint)\n return result(request, false, 'idempotency_conflict');\n if (winner.status === 'completed')\n return replayResult(request, winner.result);\n if (winner.ownerToken === ownerToken) {\n let executed: DataSurfaceActionResult;\n try {\n // A queued job may run long after the request that created it. The\n // complete persona binding (including the TenantAgent-capped tool\n // allow-list) must therefore be resolved again at execution time.\n const refreshed = await options.resolveDeferredPrincipal?.(reference);\n if (\n !refreshed ||\n refreshed.principal.runAsUserId !== reference.runAsUserId ||\n refreshed.principal.tenantId !== reference.tenantId ||\n (refreshed.principal.actsAsProfileId ?? null) !==\n reference.actsAsProfileId ||\n (refreshed.onBehalfOfUserId ?? null) !==\n reference.onBehalfOfUserId ||\n (refreshed.agentClass ?? null) !== (reference.agentClass ?? null) ||\n !Array.isArray(refreshed.principal.allowedTools)\n ) {\n throw new Error(\n 'Deferred data-surface action principal binding could not be resolved safely',\n );\n }\n // Permission snapshots are never carried across the queue boundary;\n // executeAsPrincipal resolves current RBAC/membership immediately.\n const { permissions: _permissions, ...livePrincipal } = refreshed;\n executed = await authorizedApply(\n request,\n { ...context, principal: livePrincipal },\n token,\n false,\n );\n } catch (error) {\n const reason = options.mapError?.(error, request);\n if (!reason) {\n await state.releaseIdempotency(executionScope, ownerToken);\n throw error;\n }\n executed = result(request, false, reason);\n }\n if (\n !(await state.completeIdempotency(\n executionScope,\n ownerToken,\n executed,\n ))\n ) {\n throw new Error('Lost background action idempotency reservation');\n }\n return executed;\n }\n if (poll < maxPolls) {\n await new Promise<void>((resolve) =>\n setTimeout(resolve, idempotencyPollIntervalMs),\n );\n const current = await state.getIdempotency(executionScope);\n if (current?.status === 'completed')\n return replayResult(request, current.result);\n }\n }\n return result(request, false, 'idempotency_in_progress');\n }\n\n async function authorizedApply(\n request: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n token: DataSurfacePreviewTokenRecord | undefined,\n allowBackground: boolean,\n ): Promise<DataSurfaceActionResult> {\n const idempotencyKey = request.idempotencyKey;\n if (!idempotencyKey) return result(request, false, 'invalid_request');\n // Capture the immutable binding before any asynchronous authorization.\n // The host may reuse or mutate its request context after enqueue returns.\n const deferredPrincipalReference = Object.freeze({\n runAsUserId: context.principal.principal.runAsUserId,\n tenantId: context.principal.principal.tenantId,\n actsAsProfileId: context.principal.principal.actsAsProfileId ?? null,\n onBehalfOfUserId: context.principal.onBehalfOfUserId ?? null,\n ...(context.principal.agentClass\n ? { agentClass: context.principal.agentClass }\n : {}),\n });\n return runAsPrincipal(\n {\n ...context.principal,\n action: 'data_surface.action.apply',\n auditMetadata: {\n ...context.principal.auditMetadata,\n surfaceId: request.identity.surfaceId,\n actionId: request.actionId,\n requestId: request.requestId,\n idempotencyKey: request.idempotencyKey,\n },\n },\n async (run) => {\n const invocation = await resolveInvocation(request, run);\n if ('ok' in invocation) return invocation;\n if (token) {\n if (\n fingerprintRequest(request) !== token.requestFingerprint ||\n invocation.selection.revision !== token.revision ||\n invocation.selection.revision !== request.expectedRevision ||\n invocation.selection.queryFingerprint !== token.queryFingerprint ||\n fingerprint(canonicalSelection(request.selection)) !==\n token.selectionFingerprint ||\n actionFingerprint(invocation.action) !== token.actionFingerprint ||\n fingerprint(canonicalRowIds(invocation.selection.rowIds)) !==\n token.resolvedRowsFingerprint\n ) {\n return result(request, false, 'stale_preview');\n }\n } else if (invocation.action.confirmation === 'required') {\n return result(request, false, 'confirmation_required');\n } else if (invocation.selection.revision !== request.expectedRevision) {\n return result(request, false, 'stale_revision');\n }\n if (invocation.action.execution === 'background' && allowBackground) {\n if (!options.backgroundQueue || !options.resolveDeferredPrincipal) {\n return result(request, false, 'background_unavailable');\n }\n const queued = await options.backgroundQueue.enqueue({\n idempotencyKey,\n identity: request.identity,\n actionId: request.actionId,\n rowIds: invocation.selection.rowIds,\n run: () =>\n executeBackgroundOnce(\n request,\n context,\n token,\n deferredPrincipalReference,\n ),\n });\n return result(request, true, undefined, {\n accepted: invocation.selection.rowIds.length,\n skipped: 0,\n failed: 0,\n ...(queued.details ?? {}),\n background: true,\n jobId: queued.jobId,\n // A replayed apply has a new transport request id, while the\n // already-queued job still returns the original execution result.\n // Preserve that correlation id across the replay envelope.\n jobRequestId: request.requestId,\n });\n }\n return executeForeground(request, invocation);\n },\n );\n }\n\n async function apply(\n input: DataSurfaceServerActionRequest,\n context: DataSurfaceActionContext,\n ): Promise<DataSurfaceActionResult> {\n const invalid = validateRequest(input, 'apply');\n if (invalid) return result(input, false, invalid);\n const request = snapshotRequest(input);\n const boundContext = snapshotActionContext(context);\n const confirmationToken = request.confirmationToken;\n const idempotencyKey = request.idempotencyKey;\n if (!idempotencyKey) return result(request, false, 'invalid_request');\n const actorUserId = boundContext.principal.principal.runAsUserId;\n const tenantId = boundContext.principal.principal.tenantId;\n const onBehalfOfUserId = boundContext.principal.onBehalfOfUserId ?? null;\n const actsAsProfileId =\n boundContext.principal.principal.actsAsProfileId ?? null;\n const agentClass = boundContext.principal.agentClass ?? null;\n const requestFingerprintValue = fingerprintRequest(request);\n const idempotencyScope = fingerprint({\n actorUserId,\n tenantId,\n onBehalfOfUserId,\n actsAsProfileId,\n agentClass,\n identity: canonicalIdentity(request.identity),\n actionId: request.actionId,\n idempotencyKey,\n });\n const prior = await state.getIdempotency(idempotencyScope);\n if (prior && prior.requestFingerprint !== requestFingerprintValue)\n return result(request, false, 'idempotency_conflict');\n // A completed durable result is safe to replay from its actor/tenant-bound\n // idempotency scope even when the one-time confirmation has expired.\n if (prior?.status === 'completed')\n return replayResult(request, prior.result);\n\n let token: DataSurfacePreviewTokenRecord | undefined;\n if (confirmationToken) {\n token = await state.getToken(confirmationToken);\n if (!token || token.expiresAt <= now()) {\n return result(request, false, 'invalid_or_expired_confirmation');\n }\n if (\n token.actorUserId !== actorUserId ||\n token.tenantId !== tenantId ||\n token.onBehalfOfUserId !== onBehalfOfUserId ||\n token.actsAsProfileId !== actsAsProfileId ||\n token.agentClass !== agentClass ||\n token.identityKey !== identityKey(request.identity) ||\n token.actionId !== request.actionId ||\n token.requestFingerprint !== requestFingerprintValue\n ) {\n return result(request, false, 'confirmation_mismatch');\n }\n if (!(await state.markTokenConsumed(confirmationToken, idempotencyKey))) {\n return result(request, false, 'confirmation_replayed');\n }\n }\n // Ownership is an internal compare-and-set nonce. Keep it independent of\n // the injectable preview-token factory, which tests or callers may make\n // deterministic without weakening concurrent winner selection.\n const ownerToken = randomBytes(16).toString('base64url');\n const maxPolls = Math.max(\n 1,\n Math.ceil(idempotencyWaitTimeoutMs / idempotencyPollIntervalMs),\n );\n for (let poll = 0; poll <= maxPolls; poll += 1) {\n const winner = await state.reserveIdempotency(idempotencyScope, {\n requestFingerprint: requestFingerprintValue,\n ownerToken,\n reservedAt: now(),\n });\n if (winner.requestFingerprint !== requestFingerprintValue)\n return result(request, false, 'idempotency_conflict');\n if (winner.status === 'completed')\n return replayResult(request, winner.result);\n if (winner.ownerToken === ownerToken) {\n let applied: DataSurfaceActionResult;\n try {\n applied = await authorizedApply(request, boundContext, token, true);\n } catch (error) {\n await state.releaseIdempotency(idempotencyScope, ownerToken);\n throw error;\n }\n // A confirmation-required request without a token is a recoverable\n // precondition failure. Do not consume its idempotency key: the caller\n // may preview and retry with the same key.\n if (!applied.ok && applied.reason === 'confirmation_required') {\n await state.releaseIdempotency(idempotencyScope, ownerToken);\n return applied;\n }\n // Once execution returns, never release on a persistence failure: a\n // durable reservation is safer than allowing duplicate side effects.\n if (\n !(await state.completeIdempotency(\n idempotencyScope,\n ownerToken,\n applied,\n ))\n ) {\n throw new Error('Lost data-surface idempotency reservation');\n }\n return applied;\n }\n if (poll < maxPolls) {\n await new Promise<void>((resolve) =>\n setTimeout(resolve, idempotencyPollIntervalMs),\n );\n const current = await state.getIdempotency(idempotencyScope);\n if (current?.status === 'completed')\n return replayResult(request, current.result);\n }\n }\n return result(request, false, 'idempotency_in_progress');\n }\n\n return { preview, apply };\n}\n","/**\n * Serialization utilities for resolved agents\n *\n * Converts ResolvedAgentAvailability (database + manifest data) into\n * a JSON-safe shape suitable for passing to client components.\n *\n * @module @happyvertical/smrt-agents/server\n */\n\nimport { sanitizeConfig } from '@happyvertical/smrt-config';\nimport type { ResolvedAgentAvailability } from '../tenant-agent.js';\nimport type { AgentAdminRoute, AgentUISlots } from '../ui.js';\n\n/**\n * Serialized agent data for passing to client components.\n *\n * Includes manifest-derived fields (icon, permissions, slots)\n * alongside resolution metadata (source, sourceTenantId).\n */\nexport interface SerializedAgent {\n /** Agent instance ID, or a synthetic key if no instance exists */\n id: string;\n /** Human-readable name from manifest */\n name?: string;\n /** Human-readable agent class name (e.g., 'Praeco') */\n agentClass: string;\n /** Canonical agent type (qualified name when available) */\n agentType: string;\n /** STI type discriminator (same as agentType) */\n _meta_type?: string;\n /** UI slot definitions from manifest */\n slots?: AgentUISlots;\n /** Admin route declarations from manifest */\n adminRoutes?: AgentAdminRoute[];\n /** How this agent was resolved for the tenant */\n source?: 'explicit' | 'inherited';\n /** Which tenant the binding came from */\n sourceTenantId?: string;\n /** Merged permissions from manifest + tenant overrides */\n permissions?: Record<string, boolean>;\n /** Agent icon from manifest */\n icon?: string;\n /**\n * Tenant-level config overrides, **secret-sanitized** for client transport.\n *\n * SECURITY (#1553, follow-up to #1552): the raw `TenantAgent.config` is the\n * tenant's own override blob and is `@field({ sensitive: true })` (stripped\n * from the generated CRUD api/mcp surfaces). This hand-written admin\n * serialization runs it through `sanitizeConfig()` from\n * `@happyvertical/smrt-config` before it leaves the server, so secret-shaped\n * keys (apiKey/token/password/…) are dropped and secret-shaped values\n * (`sk-…`, `AKIA…`, `Bearer …`, URL credentials, PEM blocks) are masked —\n * non-secret config still reaches the authorized admin UI for display.\n *\n * This is **display-only**: do not edit-round-trip it back to the server\n * (a masked value would overwrite the real secret). Best practice remains to\n * reference secrets by id via `@happyvertical/smrt-secrets` so only an opaque\n * handle is ever stored in tenant config.\n */\n config?: Record<string, unknown>;\n}\n\n/**\n * Convert a ResolvedAgentAvailability to a serializable shape for the UI.\n *\n * @param resolved - Output from TenantAgentCollection.resolveForTenant()\n * @returns Serialized agent data safe for JSON transport\n */\nexport function serializeResolvedAgent(\n resolved: ResolvedAgentAvailability,\n): SerializedAgent {\n const manifest = resolved.manifest;\n\n return {\n id: resolved.agentId || `${resolved.sourceTenantId}:${resolved.agentType}`,\n name: manifest?.name || resolved.agentClass,\n agentClass: resolved.agentClass,\n agentType: resolved.agentType,\n _meta_type: resolved.agentType,\n slots: manifest?.uiSlots as AgentUISlots | undefined,\n adminRoutes: manifest?.adminRoutes as AgentAdminRoute[] | undefined,\n source: resolved.source,\n sourceTenantId: resolved.sourceTenantId,\n permissions: resolved.permissions,\n icon: manifest?.icon,\n // Secret-sanitize before the blob crosses into the client payload (#1553).\n config: sanitizeConfig(resolved.config) as SerializedAgent['config'],\n };\n}\n"],"mappings":";;;;;AAwDO,SAAS,cACd,WACgC;CAChC,MAAM,yBAAS,IAAI,IAA+B;CAElD,KAAA,MAAW,YAAY,WAAW;EAChC,MAAM,cAAe,SAAqC;EAI1D,KAAA,MAAW,OAAO,OAAO,OAAO,SAAS,OAAO,GAAG;GACjD,MAAM,SAAS,IAAI;GACnB,IAAI,CAAC,QAAQ;GAEb,MAAM,MAAM,OAAO;GAGnB,IAAI,CAAC,KAAK,WAAW,IAAI,QAAQ,WAAW,GAAG;GAG/C,MAAM,YAAY,OAAO;GACzB,MAAM,OACJ,IAAI,SAAS,YAAY,UAAU,QAAQ,MAAM,GAAG,IAAI;GAC1D,IAAI,CAAC,MAAM;GAEX,OAAO,IAAI,MAAM;IACf,WAAW,IAAI;IACf,gBAAgB,IAAI;IACpB;GACF,CAAC;EACH;CACF;CAEA,OAAO;AACT;AAcO,SAAS,gBACd,SACA,QACyB;CAEzB,MAAM,aAAa,QAAQ,QAAQ,cAAc,EAAE;CACnD,IAAI,CAAC,YAAY,OAAO;CAExB,MAAM,WAAW,WAAW,MAAM,GAAG;CAGrC,IAAI,SAAS,WAAW,GAAG;EACzB,MAAM,QAAQ,OAAO,IAAI,SAAS,EAA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WAAW,yBAAyB;KAC7D,MAAM,MAAM,mBAAmB,kBAAkB,UAAU;KAC3D,OAAO;IACT;IAGA,IACE,CAAE,MAAM,MAAM,oBACZ,kBACA,YACA,OACF,GAEA,MAAM,IAAI,MAAM,2CAA2C;IAE7D,OAAO;GACT;GACA,IAAI,OAAO,UAAU;IACnB,MAAM,IAAI,SAAe,YACvB,WAAW,SAAS,yBAAyB,CAC/C;IACA,MAAM,UAAU,MAAM,MAAM,eAAe,gBAAgB;IAC3D,IAAI,SAAS,WAAW,aACtB,OAAO,aAAa,SAAS,QAAQ,MAAM;GAC/C;EACF;EACA,OAAO,OAAO,SAAS,OAAO,yBAAyB;CACzD;CAEA,OAAO;EAAE;EAAS;CAAM;AAC1B;;;AC7hCO,SAAS,uBACd,UACiB;CACjB,MAAM,WAAW,SAAS;CAE1B,OAAO;EACL,IAAI,SAAS,WAAW,GAAG,SAAS,eAAc,GAAI,SAAS;EAC/D,MAAM,UAAU,QAAQ,SAAS;EACjC,YAAY,SAAS;EACrB,WAAW,SAAS;EACpB,YAAY,SAAS;EACrB,OAAO,UAAU;EACjB,aAAa,UAAU;EACvB,QAAQ,SAAS;EACjB,gBAAgB,SAAS;EACzB,aAAa,SAAS;EACtB,MAAM,UAAU;EAEhB,QAAQ,eAAe,SAAS,MAAM;CACxC;AACF"}
|
package/dist/smrt-knowledge.json
CHANGED
|
@@ -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.43.
|
|
6
|
+
"packageVersion": "0.43.10",
|
|
7
7
|
"sourceManifestPath": "dist/manifest.json",
|
|
8
8
|
"agentDocPath": "AGENTS.md",
|
|
9
9
|
"sourceHashes": {
|
|
10
|
-
"manifest": "
|
|
11
|
-
"packageJson": "
|
|
10
|
+
"manifest": "0f213b55aeb6fd5fa10765987d985715c43e2ef297f6a2ec456a7a8d206e9839",
|
|
11
|
+
"packageJson": "0628635cae6fbffd91b0dc193fbfbcfa25df653865adbe2865136f9daaee48d0",
|
|
12
12
|
"agents": "6ce7da109ba71d3e767ee0091d7ac28528c422310f5031f46f65e93814ee0a86"
|
|
13
13
|
},
|
|
14
14
|
"exports": [
|
|
@@ -108,6 +108,7 @@
|
|
|
108
108
|
"relationships": [],
|
|
109
109
|
"methods": [
|
|
110
110
|
"_setLoadedRelationship",
|
|
111
|
+
"claimRevision",
|
|
111
112
|
"classifyConstraintError",
|
|
112
113
|
"clearEmbeddings",
|
|
113
114
|
"delete",
|
|
@@ -164,7 +165,8 @@
|
|
|
164
165
|
"toPlainObject",
|
|
165
166
|
"toPublicJSON",
|
|
166
167
|
"validate",
|
|
167
|
-
"withDatabase"
|
|
168
|
+
"withDatabase",
|
|
169
|
+
"withTransaction"
|
|
168
170
|
],
|
|
169
171
|
"methodSignatures": [
|
|
170
172
|
{
|
|
@@ -175,6 +177,14 @@
|
|
|
175
177
|
],
|
|
176
178
|
"returns": "void"
|
|
177
179
|
},
|
|
180
|
+
{
|
|
181
|
+
"name": "claimRevision",
|
|
182
|
+
"async": true,
|
|
183
|
+
"params": [
|
|
184
|
+
"expectedUpdatedAt: Date | string"
|
|
185
|
+
],
|
|
186
|
+
"returns": "Promise"
|
|
187
|
+
},
|
|
178
188
|
{
|
|
179
189
|
"name": "classifyConstraintError",
|
|
180
190
|
"static": true,
|
|
@@ -479,6 +489,9 @@
|
|
|
479
489
|
{
|
|
480
490
|
"name": "save",
|
|
481
491
|
"async": true,
|
|
492
|
+
"params": [
|
|
493
|
+
"options?: SmrtSaveOptions"
|
|
494
|
+
],
|
|
482
495
|
"returns": "any"
|
|
483
496
|
},
|
|
484
497
|
{
|
|
@@ -531,6 +544,14 @@
|
|
|
531
544
|
"operation: Function"
|
|
532
545
|
],
|
|
533
546
|
"returns": "Promise<T>"
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
"name": "withTransaction",
|
|
550
|
+
"async": true,
|
|
551
|
+
"params": [
|
|
552
|
+
"operation: Function"
|
|
553
|
+
],
|
|
554
|
+
"returns": "Promise<T>"
|
|
534
555
|
}
|
|
535
556
|
],
|
|
536
557
|
"tenant": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-agents",
|
|
3
|
-
"version": "0.43.
|
|
3
|
+
"version": "0.43.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"smrtRawPrimitives": "strict",
|
|
6
6
|
"description": "Agent framework for building autonomous actors in the SMRT ecosystem",
|
|
@@ -59,14 +59,14 @@
|
|
|
59
59
|
"@happyvertical/ai": "^0.89.4",
|
|
60
60
|
"@happyvertical/files": "^0.89.4",
|
|
61
61
|
"@happyvertical/utils": "^0.89.4",
|
|
62
|
-
"@happyvertical/smrt-config": "0.43.
|
|
63
|
-
"@happyvertical/smrt-core": "0.43.
|
|
64
|
-
"@happyvertical/smrt-reports": "0.43.
|
|
65
|
-
"@happyvertical/smrt-
|
|
66
|
-
"@happyvertical/smrt-
|
|
67
|
-
"@happyvertical/smrt-
|
|
68
|
-
"@happyvertical/smrt-
|
|
69
|
-
"@happyvertical/smrt-
|
|
62
|
+
"@happyvertical/smrt-config": "0.43.10",
|
|
63
|
+
"@happyvertical/smrt-core": "0.43.10",
|
|
64
|
+
"@happyvertical/smrt-reports": "0.43.10",
|
|
65
|
+
"@happyvertical/smrt-types": "0.43.10",
|
|
66
|
+
"@happyvertical/smrt-ui": "0.43.10",
|
|
67
|
+
"@happyvertical/smrt-users": "0.43.10",
|
|
68
|
+
"@happyvertical/smrt-secrets": "0.43.10",
|
|
69
|
+
"@happyvertical/smrt-tenancy": "0.43.10"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@happyvertical/logger": "^0.89.4",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"typescript": "5.9.3",
|
|
84
84
|
"vite": "8.1.4",
|
|
85
85
|
"vitest": "4.1.10",
|
|
86
|
-
"@happyvertical/smrt-vitest": "0.43.
|
|
86
|
+
"@happyvertical/smrt-vitest": "0.43.10"
|
|
87
87
|
},
|
|
88
88
|
"keywords": [
|
|
89
89
|
"agent",
|