@happyvertical/smrt-agents 0.30.0
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 +96 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +7 -0
- package/README.md +139 -0
- package/dist/__smrt-register__.d.ts +2 -0
- package/dist/__smrt-register__.d.ts.map +1 -0
- package/dist/agent.d.ts +545 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/ai-config.d.ts +27 -0
- package/dist/ai-config.d.ts.map +1 -0
- package/dist/chunks/config-BYbOxt24.js +179 -0
- package/dist/chunks/config-BYbOxt24.js.map +1 -0
- package/dist/chunks/manifest-utils-DLXfTOq0.js +69 -0
- package/dist/chunks/manifest-utils-DLXfTOq0.js.map +1 -0
- package/dist/config.d.ts +117 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/identity.d.ts +19 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1477 -0
- package/dist/index.js.map +1 -0
- package/dist/interests.d.ts +291 -0
- package/dist/interests.d.ts.map +1 -0
- package/dist/manifest.json +2012 -0
- package/dist/playground.d.ts +2 -0
- package/dist/playground.d.ts.map +1 -0
- package/dist/playground.js +156 -0
- package/dist/playground.js.map +1 -0
- package/dist/schedule.d.ts +168 -0
- package/dist/schedule.d.ts.map +1 -0
- package/dist/server/action-types.d.ts +65 -0
- package/dist/server/action-types.d.ts.map +1 -0
- package/dist/server/action-types.js +2 -0
- package/dist/server/action-types.js.map +1 -0
- package/dist/server/api-routes.d.ts +57 -0
- package/dist/server/api-routes.d.ts.map +1 -0
- package/dist/server/config-loader.d.ts +17 -0
- package/dist/server/config-loader.d.ts.map +1 -0
- package/dist/server/index.d.ts +34 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/manifest-utils.d.ts +63 -0
- package/dist/server/manifest-utils.d.ts.map +1 -0
- package/dist/server/serialization.d.ts +58 -0
- package/dist/server/serialization.d.ts.map +1 -0
- package/dist/server.js +105 -0
- package/dist/server.js.map +1 -0
- package/dist/smrt-knowledge.json +983 -0
- package/dist/summary-article.d.ts +30 -0
- package/dist/summary-article.d.ts.map +1 -0
- package/dist/summary-article.js +2 -0
- package/dist/summary-article.js.map +1 -0
- package/dist/svelte/components/AgentDashboard.svelte +250 -0
- package/dist/svelte/components/AgentDashboard.svelte.d.ts +21 -0
- package/dist/svelte/components/AgentDashboard.svelte.d.ts.map +1 -0
- package/dist/svelte/components/AgentRunHistory.svelte +225 -0
- package/dist/svelte/components/AgentRunHistory.svelte.d.ts +16 -0
- package/dist/svelte/components/AgentRunHistory.svelte.d.ts.map +1 -0
- package/dist/svelte/components/AgentScheduleForm.svelte +381 -0
- package/dist/svelte/components/AgentScheduleForm.svelte.d.ts +19 -0
- package/dist/svelte/components/AgentScheduleForm.svelte.d.ts.map +1 -0
- package/dist/svelte/components/AgentScheduleList.svelte +370 -0
- package/dist/svelte/components/AgentScheduleList.svelte.d.ts +24 -0
- package/dist/svelte/components/AgentScheduleList.svelte.d.ts.map +1 -0
- package/dist/svelte/components/ScheduleStatusBadge.svelte +23 -0
- package/dist/svelte/components/ScheduleStatusBadge.svelte.d.ts +9 -0
- package/dist/svelte/components/ScheduleStatusBadge.svelte.d.ts.map +1 -0
- package/dist/svelte/i18n.d.ts +33 -0
- package/dist/svelte/i18n.d.ts.map +1 -0
- package/dist/svelte/i18n.js +37 -0
- package/dist/svelte/index.d.ts +23 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +26 -0
- package/dist/svelte/playground.d.ts +196 -0
- package/dist/svelte/playground.d.ts.map +1 -0
- package/dist/svelte/playground.js +151 -0
- package/dist/svelte/types.d.ts +155 -0
- package/dist/svelte/types.d.ts.map +1 -0
- package/dist/svelte/types.js +116 -0
- package/dist/tenant-agent.d.ts +106 -0
- package/dist/tenant-agent.d.ts.map +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ui.d.ts +298 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +133 -0
- package/dist/ui.js.map +1 -0
- package/dist/vite-plugin.d.ts +61 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +173 -0
- package/dist/vite-plugin.js.map +1 -0
- package/package.json +104 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @happyvertical/smrt-agents
|
|
2
|
+
|
|
3
|
+
Agent framework for autonomous actors with inter-agent messaging, interest-based object discovery, scheduling, and multi-tenant bindings.
|
|
4
|
+
|
|
5
|
+
## Agent Lifecycle
|
|
6
|
+
|
|
7
|
+
`initialize()` → `validate()` → `run()` → `shutdown()`
|
|
8
|
+
|
|
9
|
+
- Extend `Agent` (which extends `SmrtObject`) and implement `run()`
|
|
10
|
+
- Status tracking: `idle → initializing → running → error/shutdown`
|
|
11
|
+
- `execute()` runs the full lifecycle automatically
|
|
12
|
+
- Process signal handling is opt-in via `manageProcessSignals: true` and is intended for single-agent processes
|
|
13
|
+
|
|
14
|
+
## DispatchBus — Inter-Agent Communication
|
|
15
|
+
|
|
16
|
+
Agents communicate via persistent async messaging through core's DispatchBus:
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
// Emitting (in any agent)
|
|
20
|
+
const bus = await this.getDispatch();
|
|
21
|
+
await bus.emit('campaign.completed', { campaignId: '123' }, { source: 'Suasor' });
|
|
22
|
+
|
|
23
|
+
// Subscribing (in receiving agent)
|
|
24
|
+
async handleDispatch(payload: unknown, metadata: DispatchMetadata): Promise<void> {
|
|
25
|
+
if (metadata.type === 'campaign.completed') await this.recordRevenue(payload);
|
|
26
|
+
}
|
|
27
|
+
async run() { await this.processDispatches(); } // processes via handleDispatch()
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
CLI: `smrt dispatch:list`, `dispatch:process --subscriber Fiscus`, `dispatch:retry`, `dispatch:cleanup`
|
|
31
|
+
|
|
32
|
+
## Interests — Object Discovery
|
|
33
|
+
|
|
34
|
+
Agents query objects they care about via declarative filters:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
constructor(options) {
|
|
38
|
+
super({ ...options, interests: {
|
|
39
|
+
objects: { Meeting: { filter: { status: 'upcoming' }, handler: async (m) => ({ action: 'recap' }) } },
|
|
40
|
+
qualify: async (items) => items.filter(/* AI-based post-filter */),
|
|
41
|
+
}});
|
|
42
|
+
}
|
|
43
|
+
async run() { for (const { type, data } of await this.interesting()) { ... } }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
- **File-based**: `getModuleConfig('agent-name', defaults)` from `smrt.config.ts`
|
|
49
|
+
- **DB-persisted**: `saveSlotConfig(slotId, data)` for UI overrides
|
|
50
|
+
- **Merged**: `getMergedConfig('slotId')` — DB overrides file config
|
|
51
|
+
- **UI slots**: `static uiSlots` declares admin panels (id, label, icon, order)
|
|
52
|
+
|
|
53
|
+
## TenantAgent — Multi-Tenant Bindings
|
|
54
|
+
|
|
55
|
+
Junction table (`tenant_agents`) binding agents to tenants with permission overrides and hierarchy resolution:
|
|
56
|
+
- Explicit binding: row exists for tenant (source: 'explicit')
|
|
57
|
+
- Inherited: walks up tenant hierarchy (source: 'inherited')
|
|
58
|
+
- Permissions: manifest defaults merged with per-tenant overrides
|
|
59
|
+
|
|
60
|
+
## AgentSchedule
|
|
61
|
+
|
|
62
|
+
Cron-based scheduling stored in `_smrt_agent_schedules`. Fields: `agentType`, `cron`, `method` (default: 'run'), `maxConcurrent`, `timeout`. Executed by ScheduleRunner from smrt-jobs.
|
|
63
|
+
|
|
64
|
+
## Lazy agent_config Resolution (issue #1161)
|
|
65
|
+
|
|
66
|
+
Persisted `agent_config` snapshots env-derived values at sync time, so rotated env vars don't reach already-stored schedule rows. Two complementary mechanisms unfreeze them:
|
|
67
|
+
|
|
68
|
+
1. **`$env` sentinels in persisted config** — register a global resolver and reference it from the JSON:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { registerConfigResolver } from '@happyvertical/smrt-agents';
|
|
72
|
+
registerConfigResolver('sharedAssetStorage', () => resolveSharedAssetStorage());
|
|
73
|
+
// persisted: { "assetStorage": { "$env": "sharedAssetStorage" } }
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
2. **`static configResolvers` on the agent class** — declarative, discoverable via the class itself:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
class Praeco extends Agent {
|
|
80
|
+
static override configResolvers = {
|
|
81
|
+
assetStorage: () => resolveSharedAssetStorage(),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The TaskRunner calls `resolveLazyConfig()` immediately before constructing the agent, so live values always win over snapshotted ones. Re-exported from `@happyvertical/smrt-core` (`resolveLazyConfig`, `registerConfigResolver`, `getClassConfigResolvers`, …) for cases where agents isn't on the import path.
|
|
87
|
+
|
|
88
|
+
## Key Files
|
|
89
|
+
|
|
90
|
+
| File | Purpose |
|
|
91
|
+
|------|---------|
|
|
92
|
+
| `src/agent.ts` | Base Agent class — lifecycle, dispatch, interests, config |
|
|
93
|
+
| `src/schedule.ts` | AgentSchedule model — cron, execution tracking |
|
|
94
|
+
| `src/tenant-agent.ts` | TenantAgent — junction table, hierarchical resolution |
|
|
95
|
+
| `src/interests.ts` | Interest filter types and configuration |
|
|
96
|
+
| `src/config.ts` | File + DB config management, UI slots |
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright <2025> <Happy Vertical Corporation>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# @happyvertical/smrt-agents
|
|
2
|
+
|
|
3
|
+
Agent framework for building autonomous actors with lifecycle management, inter-agent messaging, interest-based discovery, scheduling, and multi-tenant bindings.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @happyvertical/smrt-agents
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Agent, type AgentOptions } from '@happyvertical/smrt-agents';
|
|
15
|
+
import { smrt } from '@happyvertical/smrt-core';
|
|
16
|
+
import { getModuleConfig } from '@happyvertical/smrt-config';
|
|
17
|
+
|
|
18
|
+
@smrt()
|
|
19
|
+
class MyAgent extends Agent {
|
|
20
|
+
protected config = getModuleConfig('my-agent', {
|
|
21
|
+
cronSchedule: '0 2 * * *',
|
|
22
|
+
maxRetries: 3,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
itemsProcessed: number = 0;
|
|
26
|
+
|
|
27
|
+
constructor(options: AgentOptions = {}) {
|
|
28
|
+
super({
|
|
29
|
+
...options,
|
|
30
|
+
interests: {
|
|
31
|
+
objects: {
|
|
32
|
+
Meeting: { filter: { status: 'upcoming' } },
|
|
33
|
+
Document: { filter: { 'type in': ['agenda', 'minutes'] } },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async validate(): Promise<void> {
|
|
40
|
+
if (!this.config.cronSchedule) throw new Error('cronSchedule required');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async run(): Promise<void> {
|
|
44
|
+
const items = await this.interesting();
|
|
45
|
+
for (const { type, data } of items) {
|
|
46
|
+
this.logger.info(`Processing ${type}: ${data.id}`);
|
|
47
|
+
}
|
|
48
|
+
this.itemsProcessed = items.length;
|
|
49
|
+
await this.save();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const agent = new MyAgent({ name: 'my-agent' });
|
|
54
|
+
await agent.execute(); // initialize() -> validate() -> run() -> shutdown()
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
If you are running a single-agent CLI or script and want built-in
|
|
58
|
+
`SIGTERM`/`SIGINT` handling, pass `manageProcessSignals: true` to the
|
|
59
|
+
constructor. Multi-agent hosts should leave that off and coordinate process
|
|
60
|
+
shutdown themselves.
|
|
61
|
+
|
|
62
|
+
## Scheduled Methods Vs Operator Actions
|
|
63
|
+
|
|
64
|
+
Use scheduled agent methods for the regular, repeatable maintenance path: the
|
|
65
|
+
work that should happen automatically every time the schedule fires. Keep those
|
|
66
|
+
methods idempotent and safe to rerun.
|
|
67
|
+
|
|
68
|
+
When operators need a composite catch-up or repair flow, expose that as an
|
|
69
|
+
explicit method such as `forage()`, `backfill()`, or `rebuildIndex()` instead of
|
|
70
|
+
overloading `run()` with manual-only behavior. Those operator actions can still
|
|
71
|
+
be enqueued through `@happyvertical/smrt-jobs`, but they should remain distinct
|
|
72
|
+
from the normal scheduled loop so it stays obvious which work is automatic and
|
|
73
|
+
which work is an intentional intervention.
|
|
74
|
+
|
|
75
|
+
## API
|
|
76
|
+
|
|
77
|
+
### Main Export (`@happyvertical/smrt-agents`)
|
|
78
|
+
|
|
79
|
+
| Export | Description |
|
|
80
|
+
|--------|------------|
|
|
81
|
+
| `Agent` | Base agent class with lifecycle and interests |
|
|
82
|
+
| `AgentOptions` | Constructor options type |
|
|
83
|
+
| `AgentStatusType` | Status enum: idle/initializing/running/error/shutdown |
|
|
84
|
+
| `AgentConfig` | DB-persisted agent configuration model |
|
|
85
|
+
| `AgentConfigCollection` | Collection for AgentConfig |
|
|
86
|
+
| `AgentSchedule` | Cron-based schedule model (`_smrt_agent_schedules`) |
|
|
87
|
+
| `AgentScheduleCollection` | Collection for AgentSchedule |
|
|
88
|
+
| `ScheduleStatus` | Schedule status type |
|
|
89
|
+
| `TenantAgent` | Agent-to-tenant junction with hierarchy resolution |
|
|
90
|
+
| `TenantAgentCollection` | Collection for TenantAgent |
|
|
91
|
+
| `TenantAgentStatus` | Tenant agent status type |
|
|
92
|
+
| `ResolvedAgentAvailability` | Resolved availability after hierarchy walk |
|
|
93
|
+
| `mergeFilters` | Combine interest filters |
|
|
94
|
+
| `normalizeSort` | Normalize sort expressions |
|
|
95
|
+
| `InterestOptions` | Interest configuration type |
|
|
96
|
+
| `InterestFilter` | Filter definition type |
|
|
97
|
+
| `InterestResult` | Discovery result type |
|
|
98
|
+
| `ObjectInterestConfig` | Per-object interest config type |
|
|
99
|
+
| `ObjectFilter` | Object filter type |
|
|
100
|
+
| `InterestHandlerFn` | Interest handler function type |
|
|
101
|
+
| `AsyncQualifierFn` | Async post-filter qualifier type |
|
|
102
|
+
| `QueryFn` | Query function type |
|
|
103
|
+
| `AgentWithInterestsOptions` | Agent options with interests |
|
|
104
|
+
|
|
105
|
+
### UI Export (`@happyvertical/smrt-agents/ui`)
|
|
106
|
+
|
|
107
|
+
| Export | Description |
|
|
108
|
+
|--------|------------|
|
|
109
|
+
| `AgentUIRegistry` | Singleton registry for agent admin panels |
|
|
110
|
+
| `createUIRegistry` | Factory for UI registries |
|
|
111
|
+
| `AgentUISlot` | UI slot definition type |
|
|
112
|
+
| `AgentUISlots` | Map of UI slots |
|
|
113
|
+
| `AgentAdminRoute` | Admin route metadata (path, component, load) |
|
|
114
|
+
| `AgentAdminExport` | Agent admin module export shape |
|
|
115
|
+
| `AgentAdminNavItem` | Navigation item for admin sidebar |
|
|
116
|
+
| `AgentAdminRootProps` | Props for admin root component |
|
|
117
|
+
| `AdminPanelBaseProps` | Props for admin panel components |
|
|
118
|
+
| `AgentManifestInfo` | Agent manifest metadata |
|
|
119
|
+
| `AgentRouteLoadContext` | Normalized SvelteKit load context |
|
|
120
|
+
| `AgentRouteLoadFn` | Server load function type |
|
|
121
|
+
| `AgentUIComponentRegistry` | Component registry type |
|
|
122
|
+
| `ComponentType` | Generic component type |
|
|
123
|
+
|
|
124
|
+
### Vite Export (`@happyvertical/smrt-agents/vite`)
|
|
125
|
+
|
|
126
|
+
| Export | Description |
|
|
127
|
+
|--------|------------|
|
|
128
|
+
| `vitePluginAgentRoutes` | Vite plugin for `virtual:smrt-agent-registrations` |
|
|
129
|
+
| `AgentRoutesPluginOptions` | Plugin options type |
|
|
130
|
+
|
|
131
|
+
## Dependencies
|
|
132
|
+
|
|
133
|
+
- `@happyvertical/smrt-core` -- ORM base classes
|
|
134
|
+
- `@happyvertical/smrt-config` -- Configuration management
|
|
135
|
+
- `@happyvertical/smrt-tenancy` -- Multi-tenant context
|
|
136
|
+
- `@happyvertical/ai` -- AI client (SDK)
|
|
137
|
+
- `@happyvertical/files` -- Filesystem utilities (SDK)
|
|
138
|
+
- `@happyvertical/utils` -- Shared utilities (SDK)
|
|
139
|
+
- Peer (optional): `@happyvertical/smrt-svelte`, `svelte`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__smrt-register__.d.ts","sourceRoot":"","sources":["../src/__smrt-register__.ts"],"names":[],"mappings":""}
|