@happyvertical/smrt-agents 0.38.19 → 0.38.21
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/AGENTS.md +17 -1
- package/dist/agent.d.ts +82 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/chunks/{config-C73buv9Y.js → config-BRQLhsFp.js} +5 -2
- package/dist/chunks/config-BRQLhsFp.js.map +1 -0
- package/dist/execute-as-principal.d.ts +158 -0
- package/dist/execute-as-principal.d.ts.map +1 -0
- package/dist/identity.d.ts +14 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +152 -10
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +18 -2
- package/dist/server.js +1 -1
- package/dist/smrt-knowledge.json +8 -6
- package/package.json +9 -9
- package/dist/chunks/config-C73buv9Y.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -114,11 +114,27 @@ class InvoiceAgent extends Agent {
|
|
|
114
114
|
- **Seams to override**: `learningScope()`, `recallForRun(memory)`, `captureForRun(memory, outcome)`, `getLearningSemanticSearch()`. Helpers for `run()`: `stageLearning(episode)`, `reportLearningOutcome(outcome)`, `getLearningMemory()`, and the `recalledMemories` field.
|
|
115
115
|
- **Config**: `static learning: boolean | AgentLearningConfig` — `{ enabled?, scope?, minConfidence?, successConfidence?, failureConfidence?, reinforcement?, decayHalfLifeMs? }`. `LearningMemory` and its types are re-exported from `@happyvertical/smrt-core`.
|
|
116
116
|
|
|
117
|
+
## Multi-Instance Agents (issue #1890) — opt-in
|
|
118
|
+
|
|
119
|
+
`static multiInstance = false` by default: a class is a **singleton** (the N=1 case) and is byte-for-byte unchanged — one dispatch subscriber keyed by the agent type, one memory scope, class-wide interests. Set `static multiInstance = true` to run N durable instances (personas, from `@happyvertical/smrt-personas`) of one class per tenant, each independent.
|
|
120
|
+
|
|
121
|
+
The framework provides only the per-instance **identity**; a package scopes its own dispatch/interests to the instance's config by overriding the seams.
|
|
122
|
+
|
|
123
|
+
- **`AgentOptions.instanceKey`** — the durable per-instance key (typically the persona id). Honored **only** when `multiInstance` is true, so passing it to a non-opted agent is a no-op.
|
|
124
|
+
- **`getInstanceKey()`** → the key, or `null` for a singleton (opt-in off, or no key).
|
|
125
|
+
- **`getDispatchSubscriber()`** → `` `${agentType}#${key}` `` for a multi-instance agent, the bare `agentType` for a singleton. Used everywhere the agent subscribes/seeds/processes, so each instance has its own subscription rows and pending-dispatch queue — two instances never compete for or double-process each other's dispatches. Composed by the exported `instanceScopedSubscriber(agentType, key)`.
|
|
126
|
+
- **`learningScope()`** — suffixed with `#<key>` for a multi-instance agent, so instances learn independently (singleton scope unchanged).
|
|
127
|
+
- **Seams to override** (both default to singleton behavior):
|
|
128
|
+
- `resolveSignalSubscriptions()` — derive **instance-scoped** signal types from the instance config so an emit meant for one instance only matches its subscription.
|
|
129
|
+
- `instanceInterestFilter()` — an `ObjectFilter` AND-merged (as the base layer) into every `interesting()` query so instances partition the objects they process.
|
|
130
|
+
|
|
131
|
+
The **`default` persona reuses the singleton identity** (a `null` key), which is what makes the singleton→multi upgrade non-destructive — see `@happyvertical/smrt-personas` (`personaInstanceKey`, `upgradeSingletonToDefaultPersona`).
|
|
132
|
+
|
|
117
133
|
## Key Files
|
|
118
134
|
|
|
119
135
|
| File | Purpose |
|
|
120
136
|
|------|---------|
|
|
121
|
-
| `src/agent.ts` | Base Agent class — lifecycle, dispatch, interests, config, opt-in learning trait |
|
|
137
|
+
| `src/agent.ts` | Base Agent class — lifecycle, dispatch, interests, config, opt-in learning trait, multi-instance identity |
|
|
122
138
|
| `src/learning.ts` | `AgentLearningConfig` + `resolveAgentLearning()` declaration normalisation |
|
|
123
139
|
| `src/schedule.ts` | AgentSchedule model — cron, execution tracking |
|
|
124
140
|
| `src/tenant-agent.ts` | TenantAgent — junction table, hierarchical resolution |
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger } from '@happyvertical/logger';
|
|
2
2
|
import { ConfigResolver, DispatchBus, DispatchMetadata, LearningEpisode, LearningMemory, LearningMemoryRecord, LearningOutcome, LearningSemanticSearch, SmrtObject, SmrtObjectOptions } from '@happyvertical/smrt-core';
|
|
3
3
|
import { AgentAIOptions } from './ai-config.js';
|
|
4
|
-
import { AgentWithInterestsOptions, InterestOptions, InterestResult } from './interests.js';
|
|
4
|
+
import { AgentWithInterestsOptions, InterestOptions, InterestResult, ObjectFilter } from './interests.js';
|
|
5
5
|
import { AgentLearningDeclaration } from './learning.js';
|
|
6
6
|
import { AgentStatusType } from './types.js';
|
|
7
7
|
import { AgentAdminRoute, AgentUISlots } from './ui.js';
|
|
@@ -30,6 +30,18 @@ export interface AgentOptions extends SmrtObjectOptions, AgentWithInterestsOptio
|
|
|
30
30
|
* shutdown itself; the first handler to finish exits the process.
|
|
31
31
|
*/
|
|
32
32
|
manageProcessSignals?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Durable per-instance key for multi-instance agents (#1890).
|
|
35
|
+
*
|
|
36
|
+
* Only honored when the agent class opts into multi-instance
|
|
37
|
+
* (`static multiInstance = true`); a singleton agent (the default) ignores it,
|
|
38
|
+
* so passing a key can never change a non-opted agent's behavior. When honored
|
|
39
|
+
* it becomes the per-instance dispatch subscriber suffix and memory partition
|
|
40
|
+
* (see {@link Agent.getDispatchSubscriber} / {@link Agent.learningScope}) so N
|
|
41
|
+
* instances of one class run independently. Typically the persona id from
|
|
42
|
+
* `@happyvertical/smrt-personas` (a persona is a durable instance).
|
|
43
|
+
*/
|
|
44
|
+
instanceKey?: string | null;
|
|
33
45
|
}
|
|
34
46
|
/**
|
|
35
47
|
* Base Agent class for building autonomous actors in the SMRT ecosystem
|
|
@@ -221,6 +233,26 @@ export declare abstract class Agent extends SmrtObject {
|
|
|
221
233
|
* ```
|
|
222
234
|
*/
|
|
223
235
|
static learning: AgentLearningDeclaration;
|
|
236
|
+
/**
|
|
237
|
+
* Opt into multiple durable instances of this agent class per tenant (#1890).
|
|
238
|
+
*
|
|
239
|
+
* **Off by default** — a non-opted class is a **singleton** (the N=1 case) and
|
|
240
|
+
* behaves byte-for-byte as it does today: one dispatch subscriber keyed by the
|
|
241
|
+
* agent type, one memory scope, class-wide interests. Setting this to `true`
|
|
242
|
+
* lets N configured instances (personas, from `@happyvertical/smrt-personas`)
|
|
243
|
+
* run independently: each is constructed with its own {@link AgentOptions.instanceKey},
|
|
244
|
+
* which the framework folds into a per-instance dispatch subscriber
|
|
245
|
+
* ({@link getDispatchSubscriber}), memory partition ({@link learningScope}),
|
|
246
|
+
* and interest/subscription scoping seams ({@link instanceInterestFilter} /
|
|
247
|
+
* {@link resolveSignalSubscriptions}) so two instances never double-process
|
|
248
|
+
* each other's dispatches or interests.
|
|
249
|
+
*
|
|
250
|
+
* The framework provides the per-instance *identity*; a package scopes its own
|
|
251
|
+
* dispatch/interests to the instance's config by overriding the seams. The
|
|
252
|
+
* `default` persona reuses the singleton identity (null key), which makes the
|
|
253
|
+
* singleton→multi upgrade non-destructive.
|
|
254
|
+
*/
|
|
255
|
+
static multiInstance: boolean;
|
|
224
256
|
/**
|
|
225
257
|
* Current agent status
|
|
226
258
|
*/
|
|
@@ -298,6 +330,55 @@ export declare abstract class Agent extends SmrtObject {
|
|
|
298
330
|
* Human-readable class name for logs and UI.
|
|
299
331
|
*/
|
|
300
332
|
protected getAgentClassName(): string;
|
|
333
|
+
/**
|
|
334
|
+
* Whether this agent class opted into multiple durable instances per tenant.
|
|
335
|
+
*/
|
|
336
|
+
protected isMultiInstance(): boolean;
|
|
337
|
+
/**
|
|
338
|
+
* The durable per-instance key for this agent, or `null` for a singleton.
|
|
339
|
+
*
|
|
340
|
+
* Returns `null` unless the class opts in (`static multiInstance = true`) AND a
|
|
341
|
+
* non-empty {@link AgentOptions.instanceKey} was supplied — so a non-opted
|
|
342
|
+
* agent is always singleton-identified even if a key is passed. This is the
|
|
343
|
+
* anchor the framework folds into the dispatch subscriber, memory scope, and
|
|
344
|
+
* scoping seams below.
|
|
345
|
+
*/
|
|
346
|
+
getInstanceKey(): string | null;
|
|
347
|
+
/**
|
|
348
|
+
* Canonical dispatch subscriber identity for this agent.
|
|
349
|
+
*
|
|
350
|
+
* A singleton (no instance key) is the bare agent type — **unchanged** from the
|
|
351
|
+
* class-keyed behavior. A multi-instance agent is `` `${agentType}#${key}` ``,
|
|
352
|
+
* giving each instance its own subscription rows and its own pending-dispatch
|
|
353
|
+
* queue so instances don't compete for or double-process each other's
|
|
354
|
+
* dispatches. Used everywhere the agent subscribes, seeds, and processes.
|
|
355
|
+
*/
|
|
356
|
+
getDispatchSubscriber(): string;
|
|
357
|
+
/**
|
|
358
|
+
* The signal types this instance should seed as dispatch subscriptions.
|
|
359
|
+
*
|
|
360
|
+
* Defaults to the class's static {@link Agent.signalSubscriptions} unchanged.
|
|
361
|
+
* A multi-instance package overrides this to derive **instance-scoped** signal
|
|
362
|
+
* types from the persona/instance config (e.g. append the instance key or a
|
|
363
|
+
* routing dimension), so an emit meant for one instance only matches that
|
|
364
|
+
* instance's subscription and the other never processes it.
|
|
365
|
+
*/
|
|
366
|
+
protected resolveSignalSubscriptions(): string[];
|
|
367
|
+
/**
|
|
368
|
+
* An optional filter AND-merged (as the base layer) into every
|
|
369
|
+
* {@link interesting} query for this instance.
|
|
370
|
+
*
|
|
371
|
+
* `undefined` by default (no scoping — singleton behavior unchanged). A
|
|
372
|
+
* multi-instance package overrides it to return an instance-discriminating
|
|
373
|
+
* filter derived from the persona/instance config, so two instances of one
|
|
374
|
+
* class partition the objects they process and never double-handle the same
|
|
375
|
+
* row. Global and per-object interest filters layer on top (and win on key
|
|
376
|
+
* collision), so choose a dedicated discriminator key here.
|
|
377
|
+
*
|
|
378
|
+
* Applies to the standard filter path; custom `query` interest filters own
|
|
379
|
+
* their SQL and should incorporate {@link getInstanceKey} themselves.
|
|
380
|
+
*/
|
|
381
|
+
protected instanceInterestFilter(): ObjectFilter | undefined;
|
|
301
382
|
/**
|
|
302
383
|
* Get UI slot definitions for this agent instance
|
|
303
384
|
*
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAErB,KAAK,eAAe,EACpB,cAAc,EACd,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAI3B,UAAU,EACV,KAAK,iBAAiB,EAEvB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAErB,KAAK,eAAe,EACpB,cAAc,EACd,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAI3B,UAAU,EACV,KAAK,iBAAiB,EAEvB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,gBAAgB,CAAC;AAO5E,OAAO,KAAK,EACV,yBAAyB,EAEzB,eAAe,EACf,cAAc,EACd,YAAY,EAEb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,KAAK,wBAAwB,EAE9B,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,YACf,SA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OAEG;IACH,OAAO,CAAC,qBAAqB;IAO7B;;;;;;;;;;;;;;OAcG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAK/B;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,QAAQ,CAAC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAE7B;;;;;;;;;;;;;;OAcG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAmC9B;;;;;;;;;;;;;;;;;OAiBG;IACG,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAuD9C;;;;;;OAMG;YACW,uBAAuB;IAoDrC;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAM/B;;;;;OAKG;YACW,mBAAmB;IAoJjC;;OAEG;IACH,OAAO,CAAC,WAAW;CA4BpB"}
|
|
@@ -11,6 +11,9 @@ function getAgentClassName(name) {
|
|
|
11
11
|
function getAgentTypeAliases(name) {
|
|
12
12
|
return Array.from(new Set([getAgentTypeName(name), getAgentClassName(name)].filter(Boolean)));
|
|
13
13
|
}
|
|
14
|
+
function instanceScopedSubscriber(agentType, instanceKey) {
|
|
15
|
+
return instanceKey ? `${agentType}#${instanceKey}` : agentType;
|
|
16
|
+
}
|
|
14
17
|
//#endregion
|
|
15
18
|
//#region src/config.ts
|
|
16
19
|
var __defProp = Object.defineProperty;
|
|
@@ -164,6 +167,6 @@ var AgentConfigCollection = class extends SmrtCollection {
|
|
|
164
167
|
}
|
|
165
168
|
};
|
|
166
169
|
//#endregion
|
|
167
|
-
export { getAgentTypeName as a, getAgentTypeAliases as i, AgentConfigCollection as n, getAgentClassName as r, AgentConfig as t };
|
|
170
|
+
export { getAgentTypeName as a, getAgentTypeAliases as i, AgentConfigCollection as n, instanceScopedSubscriber as o, getAgentClassName as r, AgentConfig as t };
|
|
168
171
|
|
|
169
|
-
//# sourceMappingURL=config-
|
|
172
|
+
//# sourceMappingURL=config-BRQLhsFp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-BRQLhsFp.js","names":["tenantId"],"sources":["../../src/identity.ts","../../src/config.ts"],"sourcesContent":["import { getClassName, ObjectRegistry } from '@happyvertical/smrt-core';\n\n/**\n * Return the canonical agent type identifier for storage and dispatch routing.\n *\n * Uses the registry's qualified name when available and falls back to the input\n * name for dynamically defined or unregistered classes.\n */\nexport function getAgentTypeName(name: string): string {\n const registered = ObjectRegistry.getClass(name);\n return registered?.qualifiedName || registered?.name || name;\n}\n\n/**\n * Return the human-readable class name for UI and logs.\n */\nexport function getAgentClassName(name: string): string {\n const registered = ObjectRegistry.getClass(name);\n return registered?.name || getClassName(name);\n}\n\n/**\n * Return all meaningful aliases for an agent type.\n *\n * The qualified name is first so persistence lookups prefer canonical rows,\n * while the simple class name keeps legacy rows discoverable during migration.\n */\nexport function getAgentTypeAliases(name: string): string[] {\n return Array.from(\n new Set([getAgentTypeName(name), getAgentClassName(name)].filter(Boolean)),\n );\n}\n\n/**\n * Compose a per-instance dispatch subscriber identity from an agent type and an\n * optional instance key (#1890).\n *\n * Multiple durable instances of one agent class each need their own subscriber\n * name so their dispatch subscriptions and pending dispatches never collide —\n * that is what keeps two instances from double-processing each other's work.\n *\n * Returns the bare `agentType` when `instanceKey` is nullish/empty, so a\n * **singleton** agent's subscriber is byte-for-byte unchanged (the N=1 default).\n * When a key is present the identity is `` `${agentType}#${instanceKey}` `` — a\n * stable, reversible composition (the type never contains `#`).\n */\nexport function instanceScopedSubscriber(\n agentType: string,\n instanceKey?: string | null,\n): string {\n return instanceKey ? `${agentType}#${instanceKey}` : agentType;\n}\n","/**\n * AgentConfig - Persistent configuration storage for agents\n *\n * This module provides database-backed configuration for agents,\n * enabling consuming apps to persist agent settings.\n *\n * @module\n */\n\nimport {\n field,\n type SmrtClassOptions,\n SmrtCollection,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport {\n queryGlobal,\n queryWithGlobals,\n TenantScoped,\n tenantId,\n} from '@happyvertical/smrt-tenancy';\nimport { getAgentTypeName } from './identity.js';\n\n/**\n * AgentConfig stores agent configuration in the database\n *\n * Each config record maps to a UI slot for an agent instance:\n * - agentId: The agent instance's ID\n * - agentClass: The canonical agent type (qualified name when available)\n * - slotId: The configuration slot (e.g., 'sources', 'settings')\n * - configData: JSON object containing the configuration\n *\n * @example\n * ```typescript\n * // Save config for an agent slot\n * const config = new AgentConfig({\n * agentId: agent.id,\n * agentClass: 'Praeco',\n * slotId: 'sources',\n * configData: { scrapers: ['civicweb', 'govstack'] },\n * db: options.db\n * });\n * await config.initialize();\n * await config.save();\n * ```\n */\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: 'agent_configs',\n api: { include: ['list', 'get', 'create', 'update', 'delete'] },\n mcp: { include: ['list', 'get'] },\n cli: true,\n})\nexport class AgentConfig extends SmrtObject {\n /**\n * Tenant ID for multi-tenant isolation\n * Nullable to support both tenant-scoped and global agent configs\n */\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n /**\n * ID of the agent instance this config belongs to\n */\n @field({ type: 'text' })\n agentId: string = '';\n\n /**\n * Canonical agent type for this config (qualified name when available)\n */\n @field({ type: 'text' })\n agentClass: string = '';\n\n /**\n * UI slot ID (e.g., 'sources', 'settings', 'reports')\n */\n @field({ type: 'text' })\n slotId: string = '';\n\n /**\n * Configuration data stored as JSON\n *\n * Sensitive (#1540): agent config blobs routinely carry API keys/credentials,\n * so this is excluded from generated API/MCP responses and rejected as a\n * `where` filter key.\n */\n @field({ type: 'json', sensitive: true })\n configData: Record<string, unknown> = {};\n\n /**\n * Schema version for future migrations\n */\n @field({ type: 'integer' })\n schemaVersion: number = 1;\n\n /**\n * Load all configs for a specific agent\n *\n * @param agentId - Agent instance ID\n * @param options - Database options\n * @returns Map of slotId → configData\n */\n static async forAgent(\n agentId: string,\n options: SmrtClassOptions,\n ): Promise<Map<string, Record<string, unknown>>> {\n const configsByAgent = await AgentConfig.forAgents([agentId], options);\n return configsByAgent.get(agentId) ?? new Map();\n }\n\n /**\n * Load configs for multiple agents in a single query.\n *\n * @param agentIds - Agent instance IDs\n * @param options - Database options\n * @returns Map of agentId -> (slotId -> configData)\n */\n static async forAgents(\n agentIds: string[],\n options: SmrtClassOptions,\n ): Promise<Map<string, Map<string, Record<string, unknown>>>> {\n const configsByAgent = new Map<\n string,\n Map<string, Record<string, unknown>>\n >();\n if (agentIds.length === 0) {\n return configsByAgent;\n }\n\n const collection = await AgentConfigCollection.create(options);\n const configs = await collection.list({\n where: { 'agentId in': agentIds },\n });\n\n for (const config of configs) {\n if (!configsByAgent.has(config.agentId)) {\n configsByAgent.set(config.agentId, new Map());\n }\n configsByAgent.get(config.agentId)?.set(config.slotId, config.configData);\n }\n\n return configsByAgent;\n }\n\n /**\n * Load config for a specific agent and slot\n *\n * @param agentId - Agent instance ID\n * @param slotId - UI slot ID\n * @param options - Database options\n * @returns Config data or undefined if not found\n */\n static async forSlot(\n agentId: string,\n slotId: string,\n options: SmrtClassOptions,\n ): Promise<Record<string, unknown> | undefined> {\n const collection = await AgentConfigCollection.create(options);\n const configs = await collection.list({\n where: { agentId, slotId },\n limit: 1,\n });\n return configs[0]?.configData;\n }\n\n /**\n * Save or update config for an agent slot\n *\n * @param data - Config data including agentId, agentClass, slotId, configData\n * @param options - Database options\n * @returns Saved AgentConfig instance\n */\n static async saveSlot(\n data: {\n agentId: string;\n agentClass: string;\n slotId: string;\n configData: Record<string, unknown>;\n },\n options: SmrtClassOptions,\n ): Promise<AgentConfig> {\n const normalizedAgentClass = getAgentTypeName(data.agentClass);\n const collection = await AgentConfigCollection.create(options);\n\n // Check for existing config using list with where clause\n const existingConfigs = await collection.list({\n where: { agentId: data.agentId, slotId: data.slotId },\n limit: 1,\n });\n\n if (existingConfigs.length > 0) {\n // Update existing\n const existing = existingConfigs[0];\n existing.configData = data.configData;\n existing.agentClass = normalizedAgentClass;\n await existing.save();\n return existing;\n }\n\n // Create new\n const config = await collection.create({\n agentId: data.agentId,\n agentClass: normalizedAgentClass,\n slotId: data.slotId,\n configData: data.configData,\n slug: `${data.agentId}-${data.slotId}`,\n });\n await config.save();\n return config;\n }\n}\n\n/**\n * Collection for AgentConfig objects\n */\nexport class AgentConfigCollection extends SmrtCollection<AgentConfig> {\n static readonly _itemClass = AgentConfig;\n\n /**\n * Find all configs for a specific tenant\n * @param tenantId - Tenant ID to filter by\n * @returns Array of AgentConfig objects for the tenant\n */\n async findByTenant(tenantId: string): Promise<AgentConfig[]> {\n return this.list({ where: { tenantId } });\n }\n\n /**\n * Find all global configs (not associated with any tenant).\n *\n * Routes through the shared tenant-global helper so it does not throw under\n * an active tenant context (an explicit `tenant_id IS NULL` filter would be\n * flagged as an isolation violation). (#1600)\n *\n * @returns Array of global AgentConfig objects\n */\n async findGlobal(): Promise<AgentConfig[]> {\n return queryGlobal<AgentConfig>(this);\n }\n\n /**\n * Find configs for a tenant including global configs.\n *\n * Fails closed if an active tenant context requests a different tenant's\n * rows; the admin/system path keeps the cross-tenant capability. (#1600)\n *\n * @param tenantId - Tenant ID to include\n * @returns Array of AgentConfig objects for the tenant and global configs\n */\n async findWithGlobals(tenantId: string): Promise<AgentConfig[]> {\n return queryWithGlobals<AgentConfig>(\n this,\n tenantId,\n 'AgentConfig.findWithGlobals',\n );\n }\n}\n"],"mappings":";;;AAQO,SAAS,iBAAiB,MAAsB;CACrD,MAAM,aAAa,eAAe,SAAS,IAAI;CAC/C,OAAO,YAAY,iBAAiB,YAAY,QAAQ;AAC1D;AAKO,SAAS,kBAAkB,MAAsB;CAEtD,OADmB,eAAe,SAAS,IACpC,CAAA,EAAY,QAAQ,aAAa,IAAI;AAC9C;AAQO,SAAS,oBAAoB,MAAwB;CAC1D,OAAO,MAAM,KACX,IAAI,IAAI,CAAC,iBAAiB,IAAI,GAAG,kBAAkB,IAAI,CAAC,CAAA,CAAE,OAAO,OAAO,CAAC,CAC3E;AACF;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AO,EAAE,UAAAA,UAAS,EAAE,CAAC;CAC1C;;;;;;;;;;CAWA,MAAM,aAAqC;EACzC,OAAO,YAAyB,IAAI;CACtC;;;;;;;;;;CAWA,MAAM,gBAAgBA,WAA0C;EAC9D,OAAO,iBACL,MACAA,WACA,6BACF;CACF;AACF"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Logger } from '@happyvertical/logger';
|
|
2
|
+
import { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
3
|
+
import { OperationPermissionCollectionInput, OperationPermissionDecision, PermissionResolver, SessionPermissionRuntimeContext } from '@happyvertical/smrt-users';
|
|
4
|
+
/**
|
|
5
|
+
* The bound principal an agent runs as. A resolved persona structurally
|
|
6
|
+
* satisfies this once its optional `runAsUserId` has been narrowed to a
|
|
7
|
+
* concrete id — `allowedTools` on a `ResolvedPersona` is already the persona's
|
|
8
|
+
* tools intersected with the `TenantAgent` capability ceiling.
|
|
9
|
+
*/
|
|
10
|
+
export interface PrincipalBinding {
|
|
11
|
+
/** The user whose live permissions bound this execution. Required. */
|
|
12
|
+
runAsUserId: string;
|
|
13
|
+
/** Tenant the principal acts within. */
|
|
14
|
+
tenantId: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* The persona's tool allow-list (already capped by the agent-class ceiling).
|
|
17
|
+
* This is a **fail-closed** whitelist, mirroring
|
|
18
|
+
* `@happyvertical/smrt-chat`'s `AgentSession.isToolAllowed()` (S5 #1392): an
|
|
19
|
+
* absent (`undefined`) or empty allow-list permits **NO** tools, never all of
|
|
20
|
+
* them, so forgetting to pass it can only tighten authority. Resolved personas
|
|
21
|
+
* always provide a concrete `string[]`.
|
|
22
|
+
*/
|
|
23
|
+
allowedTools?: string[];
|
|
24
|
+
/** Optional acting `Bot` profile id, recorded in the audit entry. */
|
|
25
|
+
actsAsProfileId?: string | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A single audit record describing an agent action performed by the bound
|
|
29
|
+
* principal (`actorUserId`) on behalf of the originating user
|
|
30
|
+
* (`onBehalfOfUserId`).
|
|
31
|
+
*/
|
|
32
|
+
export interface PrincipalAuditEntry {
|
|
33
|
+
/** Action label, e.g. `'agent.run'`. */
|
|
34
|
+
action: string;
|
|
35
|
+
/** The persona's bound user the work ran as. */
|
|
36
|
+
actorUserId: string;
|
|
37
|
+
/** The user who triggered the agent, if known. */
|
|
38
|
+
onBehalfOfUserId: string | null;
|
|
39
|
+
/** Tenant the action ran within. */
|
|
40
|
+
tenantId: string | null;
|
|
41
|
+
/** Canonical agent class, when the caller supplies it. */
|
|
42
|
+
agentClass?: string;
|
|
43
|
+
/** Acting profile id, when the persona sets one. */
|
|
44
|
+
actsAsProfileId?: string | null;
|
|
45
|
+
/** Free-form additional context. */
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sink that records a {@link PrincipalAuditEntry}. Provide one to persist audit
|
|
50
|
+
* rows (e.g. via `AuditLog.record`); when omitted, the entry is emitted as a
|
|
51
|
+
* structured log line.
|
|
52
|
+
*/
|
|
53
|
+
export type PrincipalAuditSink = (entry: PrincipalAuditEntry) => void | Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Options for {@link executeAsPrincipal}.
|
|
56
|
+
*/
|
|
57
|
+
export interface ExecuteAsPrincipalOptions extends SmrtClassOptions {
|
|
58
|
+
/** The bound principal to run as. */
|
|
59
|
+
principal: PrincipalBinding;
|
|
60
|
+
/** The originating user the action is performed on behalf of (for audit). */
|
|
61
|
+
onBehalfOfUserId?: string | null;
|
|
62
|
+
/** Canonical agent class, recorded in the audit entry. */
|
|
63
|
+
agentClass?: string;
|
|
64
|
+
/** Audit action label. Defaults to `'agent.run'`. */
|
|
65
|
+
action?: string;
|
|
66
|
+
/** Extra audit metadata merged into the emitted entry. */
|
|
67
|
+
auditMetadata?: Record<string, unknown>;
|
|
68
|
+
/**
|
|
69
|
+
* Pre-resolved permission slugs. When omitted, the principal's permissions
|
|
70
|
+
* are resolved live so role changes reflect on the next execution.
|
|
71
|
+
*/
|
|
72
|
+
permissions?: string[];
|
|
73
|
+
/** Reuse an initialized resolver across executions. */
|
|
74
|
+
resolver?: PermissionResolver;
|
|
75
|
+
/** Opt into Postgres RLS transaction wrapping (defaults to package config). */
|
|
76
|
+
postgresRls?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Enter tenant context so tenant auto-filtering applies on every adapter.
|
|
79
|
+
* Defaults to `true` whenever the principal has a tenant.
|
|
80
|
+
*/
|
|
81
|
+
enterTenantContext?: boolean;
|
|
82
|
+
/** Audit sink. Defaults to a structured log line. */
|
|
83
|
+
audit?: PrincipalAuditSink;
|
|
84
|
+
/** Logger used for the default audit sink. */
|
|
85
|
+
logger?: Logger;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Thrown when the persona attempts a tool outside its `allowedTools`.
|
|
89
|
+
*/
|
|
90
|
+
export declare class PrincipalToolNotAllowedError extends Error {
|
|
91
|
+
readonly tool: string;
|
|
92
|
+
readonly status = 403;
|
|
93
|
+
constructor(tool: string);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The handle passed to the {@link executeAsPrincipal} body. Its
|
|
97
|
+
* session-permission {@link context} is already published for the principal, so
|
|
98
|
+
* data operations are bounded by RLS on Postgres. The assertions enforce the
|
|
99
|
+
* remaining two authority dimensions.
|
|
100
|
+
*/
|
|
101
|
+
export interface PrincipalRun {
|
|
102
|
+
/** The published session-permission runtime context for the principal. */
|
|
103
|
+
context: SessionPermissionRuntimeContext;
|
|
104
|
+
/** The principal's published (snapshot) permission slugs. */
|
|
105
|
+
permissions: string[];
|
|
106
|
+
/**
|
|
107
|
+
* The effective, fail-closed tool allow-list — always a concrete array (an
|
|
108
|
+
* absent binding allow-list normalizes to `[]`, i.e. no tools).
|
|
109
|
+
*/
|
|
110
|
+
allowedTools: string[];
|
|
111
|
+
/**
|
|
112
|
+
* Whether `tool` is within the fail-closed allow-list. An empty allow-list,
|
|
113
|
+
* or an empty/non-string tool name, permits nothing.
|
|
114
|
+
*/
|
|
115
|
+
isToolAllowed(tool: string): boolean;
|
|
116
|
+
/** Throw {@link PrincipalToolNotAllowedError} unless `tool` is allowed. */
|
|
117
|
+
assertToolAllowed(tool: string): void;
|
|
118
|
+
/**
|
|
119
|
+
* Assert the principal holds the catalog permission for `(collection,
|
|
120
|
+
* action)`, authorizing against the **published** principal set
|
|
121
|
+
* (`context.permissionSet`) — the same snapshot the RLS session enforces — so
|
|
122
|
+
* the bound is adapter-independent. This is the door-agnostic teeth for the
|
|
123
|
+
* RLS-off adapters; under Postgres RLS it is a redundant (but harmless)
|
|
124
|
+
* second gate. Throws `OperationPermissionError` on denial.
|
|
125
|
+
*/
|
|
126
|
+
assertOperation(collection: OperationPermissionCollectionInput, action: string, extraOptions?: SmrtClassOptions): Promise<OperationPermissionDecision>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Run `fn` AS the persona's bound principal.
|
|
130
|
+
*
|
|
131
|
+
* Resolves the bound user's live permissions, publishes them onto the DB
|
|
132
|
+
* session (so Postgres RLS bounds every query per-`(table, action)`), emits an
|
|
133
|
+
* on-behalf-of audit entry, and hands `fn` a {@link PrincipalRun} whose
|
|
134
|
+
* assertions enforce the persona tool ceiling and the RLS-off catalog gate.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* await executeAsPrincipal(
|
|
139
|
+
* {
|
|
140
|
+
* db,
|
|
141
|
+
* principal: {
|
|
142
|
+
* runAsUserId: persona.runAsUserId,
|
|
143
|
+
* tenantId: persona.tenantId,
|
|
144
|
+
* allowedTools: persona.allowedTools,
|
|
145
|
+
* },
|
|
146
|
+
* onBehalfOfUserId: triggeringUserId,
|
|
147
|
+
* agentClass: persona.agentClass,
|
|
148
|
+
* },
|
|
149
|
+
* async (run) => {
|
|
150
|
+
* run.assertToolAllowed('articles.publish');
|
|
151
|
+
* await run.assertOperation('articles', 'update');
|
|
152
|
+
* await agent.run();
|
|
153
|
+
* },
|
|
154
|
+
* );
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare function executeAsPrincipal<T>(options: ExecuteAsPrincipalOptions, fn: (run: PrincipalRun) => Promise<T>): Promise<T>;
|
|
158
|
+
//# sourceMappingURL=execute-as-principal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-as-principal.d.ts","sourceRoot":"","sources":["../src/execute-as-principal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAEL,KAAK,kCAAkC,EACvC,KAAK,2BAA2B,EAChC,KAAK,kBAAkB,EACvB,KAAK,+BAA+B,EAErC,MAAM,2BAA2B,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,WAAW,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,qEAAqE;IACrE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,oCAAoC;IACpC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,eAAe,CAAC,EAAE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,EAAE,MAAM,EAAE,CAAC;IACvB;;;OAGG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACrC,2EAA2E;IAC3E,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC;;;;;;;OAOG;IACH,eAAe,CACb,UAAU,EAAE,kCAAkC,EAC9C,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,gBAAgB,GAC9B,OAAO,CAAC,2BAA2B,CAAC,CAAC;CACzC;AAiBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,OAAO,EAAE,yBAAyB,EAClC,EAAE,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,GACpC,OAAO,CAAC,CAAC,CAAC,CAkFZ"}
|
package/dist/identity.d.ts
CHANGED
|
@@ -16,4 +16,18 @@ export declare function getAgentClassName(name: string): string;
|
|
|
16
16
|
* while the simple class name keeps legacy rows discoverable during migration.
|
|
17
17
|
*/
|
|
18
18
|
export declare function getAgentTypeAliases(name: string): string[];
|
|
19
|
+
/**
|
|
20
|
+
* Compose a per-instance dispatch subscriber identity from an agent type and an
|
|
21
|
+
* optional instance key (#1890).
|
|
22
|
+
*
|
|
23
|
+
* Multiple durable instances of one agent class each need their own subscriber
|
|
24
|
+
* name so their dispatch subscriptions and pending dispatches never collide —
|
|
25
|
+
* that is what keeps two instances from double-processing each other's work.
|
|
26
|
+
*
|
|
27
|
+
* Returns the bare `agentType` when `instanceKey` is nullish/empty, so a
|
|
28
|
+
* **singleton** agent's subscriber is byte-for-byte unchanged (the N=1 default).
|
|
29
|
+
* When a key is present the identity is `` `${agentType}#${instanceKey}` `` — a
|
|
30
|
+
* stable, reversible composition (the type never contains `#`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function instanceScopedSubscriber(agentType: string, instanceKey?: string | null): string;
|
|
19
33
|
//# sourceMappingURL=identity.d.ts.map
|
package/dist/identity.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAI1D"}
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAI1D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,GAC1B,MAAM,CAER"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export { getClassConfigResolvers, getConfigResolver, isLazyConfigSentinel, listC
|
|
|
3
3
|
export { Agent, type AgentOptions } from './agent.js';
|
|
4
4
|
export { type AgentAIOptions, type AgentAISecretFallback, resolveAgentAIOptions, } from './ai-config.js';
|
|
5
5
|
export { AgentConfig, AgentConfigCollection } from './config.js';
|
|
6
|
+
export { type ExecuteAsPrincipalOptions, executeAsPrincipal, type PrincipalAuditEntry, type PrincipalAuditSink, type PrincipalBinding, type PrincipalRun, PrincipalToolNotAllowedError, } from './execute-as-principal.js';
|
|
7
|
+
export { instanceScopedSubscriber } from './identity.js';
|
|
6
8
|
export type { AgentWithInterestsOptions, AsyncQualifierFn, InterestFilter, InterestHandlerFn, InterestOptions, InterestResult, ObjectFilter, ObjectInterestConfig, QueryFn, } from './interests.js';
|
|
7
9
|
export { mergeFilters, normalizeSort } from './interests.js';
|
|
8
10
|
export { type AgentLearningConfig, type AgentLearningDeclaration, type ResolvedAgentLearning, resolveAgentLearning, } from './learning.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAKH,OAAO,wBAAwB,CAAC;AAIhC,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACjE,YAAY,EACV,yBAAyB,EACzB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,OAAO,GACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG7D,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB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