@hybrd/types 1.4.4 → 2.0.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/README.md +261 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +198 -9
- package/dist/index.d.ts +198 -9
- package/package.json +4 -4
- package/src/agent.ts +2 -0
- package/src/channel.ts +44 -0
- package/src/index.ts +31 -0
- package/src/plugin.ts +2 -0
- package/src/runtime.ts +2 -25
- package/src/schedule.ts +159 -0
package/README.md
CHANGED
|
@@ -1,58 +1,290 @@
|
|
|
1
1
|
# @hybrd/types
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared TypeScript type definitions for the Hybrid AI agent framework. Zero runtime logic except for `BehaviorRegistryImpl`. All `@hybrd/*` packages import shared types from here.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Overview
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Every other package in the framework imports its shared interfaces from `@hybrd/types` rather than re-defining them. This package covers agents, tools, plugins, behaviors, channels, schedules, XMTP primitives, and runtime context.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Type Categories
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
### Agent Types
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
```typescript
|
|
14
|
+
interface Agent<TRuntimeExtension, TPluginContext> {
|
|
15
|
+
readonly name: string
|
|
16
|
+
readonly plugins: PluginRegistry<TPluginContext>
|
|
17
|
+
generate(messages, options): Promise<ReturnType<typeof generateText>>
|
|
18
|
+
stream(messages, options): Promise<Response>
|
|
19
|
+
getConfig(): { name, hasModel, hasTools, hasInstructions }
|
|
20
|
+
getInstructions(options): Promise<string | undefined>
|
|
21
|
+
getTools(options): Promise<Record<string, AnyTool> | undefined>
|
|
22
|
+
createRuntimeContext(baseRuntime): Promise<AgentRuntime & TRuntimeExtension>
|
|
23
|
+
use(plugin): void
|
|
24
|
+
listen(opts): Promise<void>
|
|
25
|
+
}
|
|
14
26
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
interface AgentConfig<TRuntimeExtension> {
|
|
28
|
+
name: string
|
|
29
|
+
model: LanguageModel | ((props) => LanguageModel | Promise<LanguageModel>)
|
|
30
|
+
tools?: Record<string, AnyTool> | ToolGenerator
|
|
31
|
+
instructions: string | ((props) => string | Promise<string>)
|
|
32
|
+
createRuntime?: (runtime: AgentRuntime) => TRuntimeExtension | Promise<TRuntimeExtension>
|
|
33
|
+
maxSteps?: number
|
|
34
|
+
maxTokens?: number
|
|
35
|
+
temperature?: number
|
|
36
|
+
onError?: (error: Error) => void | Promise<void>
|
|
37
|
+
}
|
|
18
38
|
```
|
|
19
39
|
|
|
20
|
-
|
|
40
|
+
`model`, `tools`, and `instructions` can all be static values or async factory functions, allowing dynamic configuration based on runtime context.
|
|
21
41
|
|
|
22
|
-
###
|
|
23
|
-
|
|
24
|
-
Visit [OpenRouter](https://openrouter.ai/keys), create an account and generate an API key
|
|
42
|
+
### Tool Types
|
|
25
43
|
|
|
26
|
-
|
|
44
|
+
```typescript
|
|
45
|
+
interface Tool<TInput, TOutput, TRuntimeExtension> {
|
|
46
|
+
description: string
|
|
47
|
+
inputSchema: TInput // Zod schema
|
|
48
|
+
outputSchema?: TOutput
|
|
49
|
+
execute: (args: { input, runtime, messages }) => Promise<z.infer<TOutput>>
|
|
50
|
+
}
|
|
27
51
|
|
|
28
|
-
|
|
29
|
-
OPENROUTER_API_KEY=your_openrouter_api_key_here
|
|
52
|
+
type AnyTool<TRuntimeExtension> = Tool<any, any, TRuntimeExtension>
|
|
30
53
|
```
|
|
31
54
|
|
|
32
|
-
###
|
|
55
|
+
### Plugin Types
|
|
33
56
|
|
|
34
|
-
|
|
35
|
-
|
|
57
|
+
Plugins are applied to the agent's Hono HTTP server. They can add routes, middleware, or other behavior.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
interface Plugin<T> {
|
|
61
|
+
name: string
|
|
62
|
+
description?: string
|
|
63
|
+
apply: (app: Hono<{ Variables: HonoVariables }>, context: T) => void | Promise<void>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface PluginRegistry<TContext> {
|
|
67
|
+
register: (plugin: Plugin<TContext>) => void
|
|
68
|
+
applyAll: (app, context) => Promise<void>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface PluginContext {
|
|
72
|
+
agent: Agent
|
|
73
|
+
behaviors?: BehaviorRegistry
|
|
74
|
+
scheduler?: unknown
|
|
75
|
+
xmtpClient?: unknown
|
|
76
|
+
}
|
|
36
77
|
```
|
|
37
78
|
|
|
38
|
-
|
|
79
|
+
### Behavior Types
|
|
39
80
|
|
|
40
|
-
|
|
41
|
-
|
|
81
|
+
Behaviors implement a **middleware chain** pattern. Each behavior can run logic before and after the agent generates a response, and can short-circuit the chain.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
interface BehaviorConfig {
|
|
85
|
+
enabled?: boolean
|
|
86
|
+
config?: unknown
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface BehaviorContext<TRuntimeExtension> {
|
|
90
|
+
runtime: AgentRuntime & TRuntimeExtension
|
|
91
|
+
client: XmtpClient
|
|
92
|
+
conversation: XmtpConversation
|
|
93
|
+
message: XmtpMessage
|
|
94
|
+
response?: string
|
|
95
|
+
sendOptions?: { threaded?, contentType?, filtered?, metadata? }
|
|
96
|
+
next?: () => Promise<void>
|
|
97
|
+
stopped?: boolean // Set to true to stop the chain
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface BehaviorObject<TRuntimeExtension> {
|
|
101
|
+
id: string
|
|
102
|
+
config: BehaviorConfig
|
|
103
|
+
before?(context: BehaviorContext): Promise<void> | void
|
|
104
|
+
after?(context: BehaviorContext): Promise<void> | void
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Factory function type: (config) => BehaviorObject
|
|
108
|
+
type Behavior<TConfig> = (config: TConfig & BehaviorConfig) => BehaviorObject
|
|
42
109
|
```
|
|
43
110
|
|
|
44
|
-
|
|
111
|
+
#### BehaviorRegistryImpl
|
|
45
112
|
|
|
46
|
-
|
|
47
|
-
|
|
113
|
+
The only runtime export in this package:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { BehaviorRegistryImpl } from "@hybrd/types"
|
|
117
|
+
|
|
118
|
+
const registry = new BehaviorRegistryImpl()
|
|
119
|
+
registry.register(myBehavior({ enabled: true }))
|
|
120
|
+
registry.registerAll([behaviorA(), behaviorB()])
|
|
121
|
+
|
|
122
|
+
// Executes chain — stops early if any behavior sets context.stopped = true
|
|
123
|
+
await registry.executeBefore(behaviorContext)
|
|
124
|
+
await registry.executeAfter(behaviorContext)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Runtime Types
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
interface AgentRuntime {
|
|
131
|
+
conversation: XmtpConversation
|
|
132
|
+
message: XmtpMessage
|
|
133
|
+
xmtpClient: XmtpClient
|
|
134
|
+
scheduler?: unknown
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The `TRuntimeExtension` generic threads through `Agent`, `AgentConfig`, `Tool`, and `BehaviorContext` to allow packages to extend the runtime context without losing type safety.
|
|
139
|
+
|
|
140
|
+
### XMTP Types
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
type XmtpClient = Client<unknown>
|
|
144
|
+
type XmtpConversation = Conversation<unknown>
|
|
145
|
+
type XmtpMessage = DecodedMessage<unknown>
|
|
146
|
+
|
|
147
|
+
type XmtpSender = {
|
|
148
|
+
address: string
|
|
149
|
+
inboxId: string
|
|
150
|
+
name: string
|
|
151
|
+
basename?: string
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type XmtpSubjects = Record<string, `0x${string}`>
|
|
155
|
+
|
|
156
|
+
// Hono context variable shape used by XMTP plugin
|
|
157
|
+
type HonoVariables = {
|
|
158
|
+
xmtpClient: XmtpClient
|
|
159
|
+
resolver?: Resolver
|
|
160
|
+
}
|
|
48
161
|
```
|
|
49
162
|
|
|
50
|
-
|
|
163
|
+
### Channel Types
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
type ChannelId = "xmtp" | (string & {})
|
|
51
167
|
|
|
52
|
-
|
|
168
|
+
type CronDeliveryMode = "none" | "announce"
|
|
169
|
+
|
|
170
|
+
interface CronDelivery {
|
|
171
|
+
mode: CronDeliveryMode
|
|
172
|
+
channel?: ChannelId
|
|
173
|
+
to?: string
|
|
174
|
+
accountId?: string
|
|
175
|
+
bestEffort?: boolean
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
interface TriggerRequest {
|
|
179
|
+
to: string
|
|
180
|
+
message: string
|
|
181
|
+
metadata?: { accountId?, threadId?, replyToId? }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
interface TriggerResponse {
|
|
185
|
+
delivered: boolean
|
|
186
|
+
messageId?: string
|
|
187
|
+
error?: string
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
interface ChannelAdapter {
|
|
191
|
+
channel: ChannelId
|
|
192
|
+
port: number
|
|
193
|
+
start(): Promise<void>
|
|
194
|
+
stop(): Promise<void>
|
|
195
|
+
trigger(req: TriggerRequest): Promise<TriggerResponse>
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
interface ChannelDispatcher {
|
|
199
|
+
dispatch(params: { channel, to, message, metadata? }): Promise<TriggerResponse>
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Schedule Types
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
type CronSchedule =
|
|
207
|
+
| { kind: "at"; at: string } // One-time at ISO timestamp
|
|
208
|
+
| { kind: "every"; everyMs: number; anchorMs?: number } // Recurring interval
|
|
209
|
+
| { kind: "cron"; expr: string; tz?: string; staggerMs?: number } // Cron expression
|
|
210
|
+
|
|
211
|
+
type CronPayload =
|
|
212
|
+
| { kind: "systemEvent"; text: string }
|
|
213
|
+
| { kind: "agentTurn"; message, model?, thinking?, timeoutSeconds?, allowUnsafeExternalContent? }
|
|
214
|
+
|
|
215
|
+
interface CronJob {
|
|
216
|
+
id: string
|
|
217
|
+
agentId?: string
|
|
218
|
+
sessionKey?: string
|
|
219
|
+
name: string
|
|
220
|
+
description?: string
|
|
221
|
+
enabled: boolean
|
|
222
|
+
deleteAfterRun?: boolean
|
|
223
|
+
createdAtMs: number
|
|
224
|
+
updatedAtMs: number
|
|
225
|
+
schedule: CronSchedule
|
|
226
|
+
sessionTarget: string
|
|
227
|
+
wakeMode: string
|
|
228
|
+
payload: CronPayload
|
|
229
|
+
delivery?: CronDelivery
|
|
230
|
+
state: CronJobState
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
interface SchedulerStatus {
|
|
234
|
+
enabled: boolean
|
|
235
|
+
storePath?: string
|
|
236
|
+
jobs: number
|
|
237
|
+
nextWakeAtMs?: number
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
type SchedulerEvent = {
|
|
241
|
+
jobId: string
|
|
242
|
+
action: "added" | "updated" | "removed" | "started" | "finished" | string
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Resolver Type
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
interface Resolver {
|
|
250
|
+
resolve: (address: string) => Promise<string | null>
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Architecture
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
@hybrd/types
|
|
258
|
+
│
|
|
259
|
+
├── agent.ts → Agent, AgentConfig, ListenOptions
|
|
260
|
+
├── tool.ts → Tool, AnyTool
|
|
261
|
+
├── plugin.ts → Plugin, PluginRegistry, PluginContext
|
|
262
|
+
├── behavior.ts → BehaviorObject, BehaviorRegistryImpl ← only runtime export
|
|
263
|
+
├── runtime.ts → AgentRuntime
|
|
264
|
+
├── xmtp.ts → XmtpClient, XmtpConversation, XmtpMessage, XmtpSender
|
|
265
|
+
├── channel.ts → ChannelAdapter, TriggerRequest, CronDelivery
|
|
266
|
+
├── schedule.ts → CronSchedule, CronJob, SchedulerStatus
|
|
267
|
+
└── resolver.ts → Resolver
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Package Consumers
|
|
271
|
+
|
|
272
|
+
| Package | Imports From Here |
|
|
273
|
+
|---------|:-----------------:|
|
|
274
|
+
| `@hybrd/xmtp` | ✅ |
|
|
275
|
+
| `@hybrd/channels` | ✅ |
|
|
276
|
+
| `@hybrd/scheduler` | ✅ |
|
|
277
|
+
| `@hybrd/memory` | ✅ |
|
|
278
|
+
| `hybrid/agent` | ✅ |
|
|
279
|
+
| `hybrid/gateway` | ✅ |
|
|
280
|
+
|
|
281
|
+
## Testing
|
|
53
282
|
|
|
54
283
|
```bash
|
|
55
|
-
|
|
284
|
+
cd packages/types
|
|
285
|
+
pnpm test
|
|
56
286
|
```
|
|
57
287
|
|
|
58
|
-
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
MIT
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/behavior.ts"],"sourcesContent":["// Agent types\nexport type {\n\tAgentConfig,\n\tDefaultRuntimeExtension,\n\tGenerateOptions,\n\tListenOptions,\n\tStreamOptions,\n\tToolGenerator\n} from \"./agent\"\n\nexport type { Agent, AgentMessage } from \"./agent\"\n\n// Tool types\nexport type {\n\tAnyTool,\n\tTool\n} from \"./tool\"\n\n// Plugin types\nexport type {\n\tPlugin,\n\tPluginContext,\n\tPluginRegistry\n} from \"./plugin\"\n\n// Runtime types\nexport type { AgentRuntime } from \"./runtime\"\n\n// XMTP types\nexport type {\n\tHonoVariables,\n\tXmtpClient,\n\tXmtpConversation,\n\tXmtpMessage,\n\tXmtpSender,\n\tXmtpSubjects\n} from \"./xmtp\"\n\n// Resolver types\nexport type { Resolver } from \"./resolver\"\n\n// Behavior types\nexport { BehaviorRegistryImpl } from \"./behavior\"\nexport type {\n\tBehavior,\n\tBehaviorConfig,\n\tBehaviorContext,\n\tBehaviorInstance,\n\tBehaviorObject,\n\tBehaviorRegistry\n} from \"./behavior\"\n","import type { AgentRuntime } from \"./runtime\"\nimport type { XmtpClient, XmtpConversation, XmtpMessage } from \"./xmtp\"\n\n/**\n * Configuration options for a behavior\n */\nexport interface BehaviorConfig {\n\t/** Whether the behavior is enabled */\n\tenabled?: boolean\n\t/** Optional configuration data for the behavior */\n\tconfig?: Record<string, unknown>\n}\n\n/**\n * Context provided to behaviors when they execute\n */\nexport interface BehaviorContext<TRuntimeExtension = Record<string, never>> {\n\t/** The base runtime context */\n\truntime: AgentRuntime & TRuntimeExtension\n\t/** The XMTP client instance */\n\tclient: XmtpClient\n\t/** The conversation the message came from */\n\tconversation: XmtpConversation\n\t/** The message that triggered the behavior */\n\tmessage: XmtpMessage\n\t/** The agent's response (available in post-response behaviors) */\n\tresponse?: string\n\t/** Send options that behaviors can modify */\n\tsendOptions?: {\n\t\t/** Whether to thread the reply to the original message */\n\t\tthreaded?: boolean\n\t\t/** Content type override */\n\t\tcontentType?: string\n\t\t/** Whether this message should be filtered out and not processed */\n\t\tfiltered?: boolean\n\t\t/** Additional metadata */\n\t\tmetadata?: Record<string, unknown>\n\t}\n\t/**\n\t * Continue to the next behavior in the middleware chain\n\t * If not called, the behavior chain stops processing\n\t */\n\tnext?: () => Promise<void>\n\t/**\n\t * Whether the middleware chain was stopped early\n\t * This gets set to true when a behavior doesn't call next()\n\t */\n\tstopped?: boolean\n}\n\n/**\n * A behavior that can be executed before or after agent responses\n */\nexport interface BehaviorObject<TRuntimeExtension = Record<string, never>> {\n\t/** Unique identifier for the behavior */\n\tid: string\n\t/** Configuration for the behavior */\n\tconfig: BehaviorConfig\n\t/**\n\t * Execute the behavior before the agent responds\n\t * @param context - The context in which to execute the behavior\n\t */\n\tbefore?(context: BehaviorContext<TRuntimeExtension>): Promise<void> | void\n\t/**\n\t * Execute the behavior after the agent responds\n\t * @param context - The context in which to execute the behavior\n\t */\n\tafter?(context: BehaviorContext<TRuntimeExtension>): Promise<void> | void\n}\n\n/**\n * Factory function to create a behavior instance\n */\nexport type Behavior<TConfig = Record<string, unknown>> = (\n\tconfig: TConfig & BehaviorConfig\n) => BehaviorObject\n\n/**\n * Pre-configured behavior instance that can be used directly\n */\nexport type BehaviorInstance = Behavior\n\n/**\n * Behavior registry for managing and executing behaviors\n */\nexport interface BehaviorRegistry {\n\t/**\n\t * Register a behavior with the registry\n\t */\n\tregister(behavior: BehaviorObject): void\n\n\t/**\n\t * Register multiple behaviors at once\n\t */\n\tregisterAll(behaviors: BehaviorObject[]): void\n\n\t/**\n\t * Get all registered behaviors\n\t */\n\tgetAll(): BehaviorObject[]\n\n\t/**\n\t * Get behaviors that should run before the agent responds\n\t */\n\tgetBeforeBehaviors(): BehaviorObject[]\n\n\t/**\n\t * Get behaviors that should run after the agent responds\n\t */\n\tgetAfterBehaviors(): BehaviorObject[]\n\n\t/**\n\t * Execute all before-response behaviors as a middleware chain\n\t */\n\texecuteBefore(context: BehaviorContext): Promise<void>\n\n\t/**\n\t * Execute all after-response behaviors as a middleware chain\n\t */\n\texecuteAfter(context: BehaviorContext): Promise<void>\n\n\t/**\n\t * Clear all registered behaviors\n\t */\n\tclear(): void\n}\n\n/**\n * Concrete implementation of the BehaviorRegistry interface\n */\nexport class BehaviorRegistryImpl implements BehaviorRegistry {\n\tprivate behaviors: BehaviorObject[] = []\n\n\t/**\n\t * Register a behavior with the registry\n\t */\n\tregister(behavior: BehaviorObject): void {\n\t\tthis.behaviors.push(behavior)\n\t}\n\n\t/**\n\t * Register multiple behaviors at once\n\t */\n\tregisterAll(behaviors: BehaviorObject[]): void {\n\t\t// Register behavior objects directly\n\t\tthis.behaviors.push(...behaviors)\n\t}\n\n\t/**\n\t * Get all registered behaviors\n\t */\n\tgetAll(): BehaviorObject[] {\n\t\treturn [...this.behaviors]\n\t}\n\n\t/**\n\t * Get behaviors that should run before the agent responds\n\t */\n\tgetBeforeBehaviors(): BehaviorObject[] {\n\t\treturn this.behaviors.filter((behavior) => behavior.before)\n\t}\n\n\t/**\n\t * Get behaviors that should run after the agent responds\n\t */\n\tgetAfterBehaviors(): BehaviorObject[] {\n\t\treturn this.behaviors.filter((behavior) => behavior.after)\n\t}\n\n\t/**\n\t * Execute all before-response behaviors as a middleware chain\n\t */\n\tasync executeBefore(context: BehaviorContext): Promise<void> {\n\t\tconst behaviors = this.getBeforeBehaviors()\n\n\t\t// Create a middleware chain\n\t\tlet currentIndex = 0\n\t\tconst next = async (): Promise<void> => {\n\t\t\tif (currentIndex >= behaviors.length) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst behavior = behaviors[currentIndex]\n\t\t\tif (!behavior) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcurrentIndex++\n\n\t\t\ttry {\n\t\t\t\tawait behavior.before?.(context)\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Error executing before behavior \"${behavior.id}\":`,\n\t\t\t\t\terror\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\t// Set the next function in the context\n\t\tcontext.next = next\n\n\t\t// Start the chain\n\t\tawait next()\n\n\t\t// Check if the chain was stopped early\n\t\tcontext.stopped = currentIndex < behaviors.length\n\t}\n\n\t/**\n\t * Execute all after-response behaviors as a middleware chain\n\t */\n\tasync executeAfter(context: BehaviorContext): Promise<void> {\n\t\tconst behaviors = this.getAfterBehaviors()\n\n\t\t// Create a middleware chain\n\t\tlet currentIndex = 0\n\t\tconst next = async (): Promise<void> => {\n\t\t\tif (currentIndex >= behaviors.length) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst behavior = behaviors[currentIndex]\n\t\t\tif (!behavior) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcurrentIndex++\n\n\t\t\ttry {\n\t\t\t\tawait behavior.after?.(context)\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(`Error executing after behavior \"${behavior.id}\":`, error)\n\t\t\t}\n\t\t}\n\n\t\t// Set the next function in the context\n\t\tcontext.next = next\n\n\t\t// Start the chain\n\t\tawait next()\n\n\t\t// Check if the chain was stopped early\n\t\tcontext.stopped = currentIndex < behaviors.length\n\t}\n\n\t/**\n\t * Clear all registered behaviors\n\t */\n\tclear(): void {\n\t\tthis.behaviors = []\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkIO,IAAM,uBAAN,MAAuD;AAAA,EACrD,YAA8B,CAAC;AAAA;AAAA;AAAA;AAAA,EAKvC,SAAS,UAAgC;AACxC,SAAK,UAAU,KAAK,QAAQ;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,WAAmC;AAE9C,SAAK,UAAU,KAAK,GAAG,SAAS;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKA,SAA2B;AAC1B,WAAO,CAAC,GAAG,KAAK,SAAS;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKA,qBAAuC;AACtC,WAAO,KAAK,UAAU,OAAO,CAAC,aAAa,SAAS,MAAM;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA,EAKA,oBAAsC;AACrC,WAAO,KAAK,UAAU,OAAO,CAAC,aAAa,SAAS,KAAK;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,SAAyC;AAC5D,UAAM,YAAY,KAAK,mBAAmB;AAG1C,QAAI,eAAe;AACnB,UAAM,OAAO,YAA2B;AACvC,UAAI,gBAAgB,UAAU,QAAQ;AACrC;AAAA,MACD;AAEA,YAAM,WAAW,UAAU,YAAY;AACvC,UAAI,CAAC,UAAU;AACd;AAAA,MACD;AACA;AAEA,UAAI;AACH,cAAM,SAAS,SAAS,OAAO;AAAA,MAChC,SAAS,OAAO;AACf,gBAAQ;AAAA,UACP,oCAAoC,SAAS,EAAE;AAAA,UAC/C;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAGA,YAAQ,OAAO;AAGf,UAAM,KAAK;AAGX,YAAQ,UAAU,eAAe,UAAU;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAAa,SAAyC;AAC3D,UAAM,YAAY,KAAK,kBAAkB;AAGzC,QAAI,eAAe;AACnB,UAAM,OAAO,YAA2B;AACvC,UAAI,gBAAgB,UAAU,QAAQ;AACrC;AAAA,MACD;AAEA,YAAM,WAAW,UAAU,YAAY;AACvC,UAAI,CAAC,UAAU;AACd;AAAA,MACD;AACA;AAEA,UAAI;AACH,cAAM,SAAS,QAAQ,OAAO;AAAA,MAC/B,SAAS,OAAO;AACf,gBAAQ,MAAM,mCAAmC,SAAS,EAAE,MAAM,KAAK;AAAA,MACxE;AAAA,IACD;AAGA,YAAQ,OAAO;AAGf,UAAM,KAAK;AAGX,YAAQ,UAAU,eAAe,UAAU;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACb,SAAK,YAAY,CAAC;AAAA,EACnB;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/behavior.ts"],"sourcesContent":["// Agent types\nexport type {\n\tAgentConfig,\n\tDefaultRuntimeExtension,\n\tGenerateOptions,\n\tListenOptions,\n\tStreamOptions,\n\tToolGenerator\n} from \"./agent\"\n\nexport type { Agent, AgentMessage } from \"./agent\"\n\n// Tool types\nexport type {\n\tAnyTool,\n\tTool\n} from \"./tool\"\n\n// Plugin types\nexport type {\n\tPlugin,\n\tPluginContext,\n\tPluginRegistry\n} from \"./plugin\"\n\n// Runtime types\nexport type { AgentRuntime } from \"./runtime\"\n\n// XMTP types\nexport type {\n\tHonoVariables,\n\tXmtpClient,\n\tXmtpConversation,\n\tXmtpMessage,\n\tXmtpSender,\n\tXmtpSubjects\n} from \"./xmtp\"\n\n// Resolver types\nexport type { Resolver } from \"./resolver\"\n\n// Behavior types\nexport { BehaviorRegistryImpl } from \"./behavior\"\nexport type {\n\tBehavior,\n\tBehaviorConfig,\n\tBehaviorContext,\n\tBehaviorInstance,\n\tBehaviorObject,\n\tBehaviorRegistry\n} from \"./behavior\"\n\n// Channel types\nexport type {\n\tChannelId,\n\tCronDeliveryMode,\n\tCronDelivery,\n\tTriggerRequest,\n\tTriggerResponse,\n\tChannelAdapter,\n\tChannelDispatcher\n} from \"./channel\"\n\n// Schedule types\nexport type {\n\tCronSchedule,\n\tCronRunStatus,\n\tCronDeliveryStatus,\n\tCronJobState,\n\tSessionTarget,\n\tWakeMode,\n\tCronPayload,\n\tCronJob,\n\tCronJobCreate,\n\tCronJobPatch,\n\tCronRun,\n\tSchedulerConfig,\n\tSchedulerStatus,\n\tListPageOptions,\n\tPaginatedResult,\n\tSchedulerEvent\n} from \"./schedule\"\n","import type { AgentRuntime } from \"./runtime\"\nimport type { XmtpClient, XmtpConversation, XmtpMessage } from \"./xmtp\"\n\n/**\n * Configuration options for a behavior\n */\nexport interface BehaviorConfig {\n\t/** Whether the behavior is enabled */\n\tenabled?: boolean\n\t/** Optional configuration data for the behavior */\n\tconfig?: Record<string, unknown>\n}\n\n/**\n * Context provided to behaviors when they execute\n */\nexport interface BehaviorContext<TRuntimeExtension = Record<string, never>> {\n\t/** The base runtime context */\n\truntime: AgentRuntime & TRuntimeExtension\n\t/** The XMTP client instance */\n\tclient: XmtpClient\n\t/** The conversation the message came from */\n\tconversation: XmtpConversation\n\t/** The message that triggered the behavior */\n\tmessage: XmtpMessage\n\t/** The agent's response (available in post-response behaviors) */\n\tresponse?: string\n\t/** Send options that behaviors can modify */\n\tsendOptions?: {\n\t\t/** Whether to thread the reply to the original message */\n\t\tthreaded?: boolean\n\t\t/** Content type override */\n\t\tcontentType?: string\n\t\t/** Whether this message should be filtered out and not processed */\n\t\tfiltered?: boolean\n\t\t/** Additional metadata */\n\t\tmetadata?: Record<string, unknown>\n\t}\n\t/**\n\t * Continue to the next behavior in the middleware chain\n\t * If not called, the behavior chain stops processing\n\t */\n\tnext?: () => Promise<void>\n\t/**\n\t * Whether the middleware chain was stopped early\n\t * This gets set to true when a behavior doesn't call next()\n\t */\n\tstopped?: boolean\n}\n\n/**\n * A behavior that can be executed before or after agent responses\n */\nexport interface BehaviorObject<TRuntimeExtension = Record<string, never>> {\n\t/** Unique identifier for the behavior */\n\tid: string\n\t/** Configuration for the behavior */\n\tconfig: BehaviorConfig\n\t/**\n\t * Execute the behavior before the agent responds\n\t * @param context - The context in which to execute the behavior\n\t */\n\tbefore?(context: BehaviorContext<TRuntimeExtension>): Promise<void> | void\n\t/**\n\t * Execute the behavior after the agent responds\n\t * @param context - The context in which to execute the behavior\n\t */\n\tafter?(context: BehaviorContext<TRuntimeExtension>): Promise<void> | void\n}\n\n/**\n * Factory function to create a behavior instance\n */\nexport type Behavior<TConfig = Record<string, unknown>> = (\n\tconfig: TConfig & BehaviorConfig\n) => BehaviorObject\n\n/**\n * Pre-configured behavior instance that can be used directly\n */\nexport type BehaviorInstance = Behavior\n\n/**\n * Behavior registry for managing and executing behaviors\n */\nexport interface BehaviorRegistry {\n\t/**\n\t * Register a behavior with the registry\n\t */\n\tregister(behavior: BehaviorObject): void\n\n\t/**\n\t * Register multiple behaviors at once\n\t */\n\tregisterAll(behaviors: BehaviorObject[]): void\n\n\t/**\n\t * Get all registered behaviors\n\t */\n\tgetAll(): BehaviorObject[]\n\n\t/**\n\t * Get behaviors that should run before the agent responds\n\t */\n\tgetBeforeBehaviors(): BehaviorObject[]\n\n\t/**\n\t * Get behaviors that should run after the agent responds\n\t */\n\tgetAfterBehaviors(): BehaviorObject[]\n\n\t/**\n\t * Execute all before-response behaviors as a middleware chain\n\t */\n\texecuteBefore(context: BehaviorContext): Promise<void>\n\n\t/**\n\t * Execute all after-response behaviors as a middleware chain\n\t */\n\texecuteAfter(context: BehaviorContext): Promise<void>\n\n\t/**\n\t * Clear all registered behaviors\n\t */\n\tclear(): void\n}\n\n/**\n * Concrete implementation of the BehaviorRegistry interface\n */\nexport class BehaviorRegistryImpl implements BehaviorRegistry {\n\tprivate behaviors: BehaviorObject[] = []\n\n\t/**\n\t * Register a behavior with the registry\n\t */\n\tregister(behavior: BehaviorObject): void {\n\t\tthis.behaviors.push(behavior)\n\t}\n\n\t/**\n\t * Register multiple behaviors at once\n\t */\n\tregisterAll(behaviors: BehaviorObject[]): void {\n\t\t// Register behavior objects directly\n\t\tthis.behaviors.push(...behaviors)\n\t}\n\n\t/**\n\t * Get all registered behaviors\n\t */\n\tgetAll(): BehaviorObject[] {\n\t\treturn [...this.behaviors]\n\t}\n\n\t/**\n\t * Get behaviors that should run before the agent responds\n\t */\n\tgetBeforeBehaviors(): BehaviorObject[] {\n\t\treturn this.behaviors.filter((behavior) => behavior.before)\n\t}\n\n\t/**\n\t * Get behaviors that should run after the agent responds\n\t */\n\tgetAfterBehaviors(): BehaviorObject[] {\n\t\treturn this.behaviors.filter((behavior) => behavior.after)\n\t}\n\n\t/**\n\t * Execute all before-response behaviors as a middleware chain\n\t */\n\tasync executeBefore(context: BehaviorContext): Promise<void> {\n\t\tconst behaviors = this.getBeforeBehaviors()\n\n\t\t// Create a middleware chain\n\t\tlet currentIndex = 0\n\t\tconst next = async (): Promise<void> => {\n\t\t\tif (currentIndex >= behaviors.length) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst behavior = behaviors[currentIndex]\n\t\t\tif (!behavior) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcurrentIndex++\n\n\t\t\ttry {\n\t\t\t\tawait behavior.before?.(context)\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Error executing before behavior \"${behavior.id}\":`,\n\t\t\t\t\terror\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\t// Set the next function in the context\n\t\tcontext.next = next\n\n\t\t// Start the chain\n\t\tawait next()\n\n\t\t// Check if the chain was stopped early\n\t\tcontext.stopped = currentIndex < behaviors.length\n\t}\n\n\t/**\n\t * Execute all after-response behaviors as a middleware chain\n\t */\n\tasync executeAfter(context: BehaviorContext): Promise<void> {\n\t\tconst behaviors = this.getAfterBehaviors()\n\n\t\t// Create a middleware chain\n\t\tlet currentIndex = 0\n\t\tconst next = async (): Promise<void> => {\n\t\t\tif (currentIndex >= behaviors.length) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst behavior = behaviors[currentIndex]\n\t\t\tif (!behavior) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcurrentIndex++\n\n\t\t\ttry {\n\t\t\t\tawait behavior.after?.(context)\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(`Error executing after behavior \"${behavior.id}\":`, error)\n\t\t\t}\n\t\t}\n\n\t\t// Set the next function in the context\n\t\tcontext.next = next\n\n\t\t// Start the chain\n\t\tawait next()\n\n\t\t// Check if the chain was stopped early\n\t\tcontext.stopped = currentIndex < behaviors.length\n\t}\n\n\t/**\n\t * Clear all registered behaviors\n\t */\n\tclear(): void {\n\t\tthis.behaviors = []\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkIO,IAAM,uBAAN,MAAuD;AAAA,EACrD,YAA8B,CAAC;AAAA;AAAA;AAAA;AAAA,EAKvC,SAAS,UAAgC;AACxC,SAAK,UAAU,KAAK,QAAQ;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,WAAmC;AAE9C,SAAK,UAAU,KAAK,GAAG,SAAS;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKA,SAA2B;AAC1B,WAAO,CAAC,GAAG,KAAK,SAAS;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKA,qBAAuC;AACtC,WAAO,KAAK,UAAU,OAAO,CAAC,aAAa,SAAS,MAAM;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA,EAKA,oBAAsC;AACrC,WAAO,KAAK,UAAU,OAAO,CAAC,aAAa,SAAS,KAAK;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,SAAyC;AAC5D,UAAM,YAAY,KAAK,mBAAmB;AAG1C,QAAI,eAAe;AACnB,UAAM,OAAO,YAA2B;AACvC,UAAI,gBAAgB,UAAU,QAAQ;AACrC;AAAA,MACD;AAEA,YAAM,WAAW,UAAU,YAAY;AACvC,UAAI,CAAC,UAAU;AACd;AAAA,MACD;AACA;AAEA,UAAI;AACH,cAAM,SAAS,SAAS,OAAO;AAAA,MAChC,SAAS,OAAO;AACf,gBAAQ;AAAA,UACP,oCAAoC,SAAS,EAAE;AAAA,UAC/C;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAGA,YAAQ,OAAO;AAGf,UAAM,KAAK;AAGX,YAAQ,UAAU,eAAe,UAAU;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAAa,SAAyC;AAC3D,UAAM,YAAY,KAAK,kBAAkB;AAGzC,QAAI,eAAe;AACnB,UAAM,OAAO,YAA2B;AACvC,UAAI,gBAAgB,UAAU,QAAQ;AACrC;AAAA,MACD;AAEA,YAAM,WAAW,UAAU,YAAY;AACvC,UAAI,CAAC,UAAU;AACd;AAAA,MACD;AACA;AAEA,UAAI;AACH,cAAM,SAAS,QAAQ,OAAO;AAAA,MAC/B,SAAS,OAAO;AACf,gBAAQ,MAAM,mCAAmC,SAAS,EAAE,MAAM,KAAK;AAAA,MACxE;AAAA,IACD;AAGA,YAAQ,OAAO;AAGf,UAAM,KAAK;AAGX,YAAQ,UAAU,eAAe,UAAU;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACb,SAAK,YAAY,CAAC;AAAA,EACnB;AACD;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -31,18 +31,11 @@ type XmtpSender = {
|
|
|
31
31
|
};
|
|
32
32
|
type XmtpSubjects = Record<string, `0x${string}`>;
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
* Base runtime that is always included in agents and tools.
|
|
36
|
-
* Additional fields can be added via generic type parameters as intersections.
|
|
37
|
-
*
|
|
38
|
-
* Example usage:
|
|
39
|
-
* - Basic: AgentRuntime (just chatId and messages)
|
|
40
|
-
* - Extended: AgentRuntime & { userId: string } (adds userId field)
|
|
41
|
-
*/
|
|
42
34
|
interface AgentRuntime {
|
|
43
35
|
conversation: XmtpConversation;
|
|
44
36
|
message: XmtpMessage;
|
|
45
37
|
xmtpClient: XmtpClient;
|
|
38
|
+
scheduler?: unknown;
|
|
46
39
|
}
|
|
47
40
|
|
|
48
41
|
/**
|
|
@@ -239,6 +232,8 @@ interface PluginRegistry<TContext = unknown> {
|
|
|
239
232
|
interface PluginContext {
|
|
240
233
|
agent: Agent;
|
|
241
234
|
behaviors?: BehaviorRegistry;
|
|
235
|
+
scheduler?: unknown;
|
|
236
|
+
xmtpClient?: unknown;
|
|
242
237
|
}
|
|
243
238
|
|
|
244
239
|
/**
|
|
@@ -358,6 +353,8 @@ interface AgentConfig<TRuntimeExtension = DefaultRuntimeExtension> {
|
|
|
358
353
|
maxTokens?: number;
|
|
359
354
|
/** Temperature for generation (0.0 to 2.0) */
|
|
360
355
|
temperature?: number;
|
|
356
|
+
/** Error handler callback for custom error handling (e.g., Sentry) */
|
|
357
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
361
358
|
}
|
|
362
359
|
/**
|
|
363
360
|
* Options for text generation with the agent.
|
|
@@ -395,4 +392,196 @@ interface ListenOptions {
|
|
|
395
392
|
behaviors?: BehaviorObject[];
|
|
396
393
|
}
|
|
397
394
|
|
|
398
|
-
|
|
395
|
+
type ChannelId = "xmtp" | (string & {});
|
|
396
|
+
type CronDeliveryMode = "none" | "announce";
|
|
397
|
+
interface CronDelivery {
|
|
398
|
+
mode: CronDeliveryMode;
|
|
399
|
+
channel?: ChannelId;
|
|
400
|
+
to?: string;
|
|
401
|
+
accountId?: string;
|
|
402
|
+
bestEffort?: boolean;
|
|
403
|
+
}
|
|
404
|
+
interface TriggerRequest {
|
|
405
|
+
to: string;
|
|
406
|
+
message: string;
|
|
407
|
+
metadata?: {
|
|
408
|
+
accountId?: string;
|
|
409
|
+
threadId?: string;
|
|
410
|
+
replyToId?: string;
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
interface TriggerResponse {
|
|
414
|
+
delivered: boolean;
|
|
415
|
+
messageId?: string;
|
|
416
|
+
error?: string;
|
|
417
|
+
}
|
|
418
|
+
interface ChannelAdapter {
|
|
419
|
+
readonly channel: ChannelId;
|
|
420
|
+
readonly port: number;
|
|
421
|
+
start(): Promise<void>;
|
|
422
|
+
stop(): Promise<void>;
|
|
423
|
+
trigger(req: TriggerRequest): Promise<TriggerResponse>;
|
|
424
|
+
}
|
|
425
|
+
interface ChannelDispatcher {
|
|
426
|
+
dispatch(params: {
|
|
427
|
+
channel: ChannelId;
|
|
428
|
+
to: string;
|
|
429
|
+
message: string;
|
|
430
|
+
metadata?: TriggerRequest["metadata"];
|
|
431
|
+
}): Promise<TriggerResponse>;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
type CronSchedule = {
|
|
435
|
+
kind: "at";
|
|
436
|
+
at: string;
|
|
437
|
+
} | {
|
|
438
|
+
kind: "every";
|
|
439
|
+
everyMs: number;
|
|
440
|
+
anchorMs?: number;
|
|
441
|
+
} | {
|
|
442
|
+
kind: "cron";
|
|
443
|
+
expr: string;
|
|
444
|
+
tz?: string;
|
|
445
|
+
staggerMs?: number;
|
|
446
|
+
};
|
|
447
|
+
type CronRunStatus = "ok" | "error" | "skipped";
|
|
448
|
+
type CronDeliveryStatus = "delivered" | "not-delivered" | "unknown" | "not-requested";
|
|
449
|
+
interface CronJobState {
|
|
450
|
+
nextRunAtMs?: number;
|
|
451
|
+
runningAtMs?: number;
|
|
452
|
+
lastRunAtMs?: number;
|
|
453
|
+
lastRunStatus?: CronRunStatus;
|
|
454
|
+
lastError?: string;
|
|
455
|
+
lastDurationMs?: number;
|
|
456
|
+
consecutiveErrors?: number;
|
|
457
|
+
scheduleErrorCount?: number;
|
|
458
|
+
lastDeliveryStatus?: CronDeliveryStatus;
|
|
459
|
+
lastDeliveryError?: string;
|
|
460
|
+
}
|
|
461
|
+
type SessionTarget = "main" | "isolated";
|
|
462
|
+
type WakeMode = "now" | "next-heartbeat";
|
|
463
|
+
type CronPayload = {
|
|
464
|
+
kind: "systemEvent";
|
|
465
|
+
text: string;
|
|
466
|
+
} | {
|
|
467
|
+
kind: "agentTurn";
|
|
468
|
+
message: string;
|
|
469
|
+
model?: string;
|
|
470
|
+
thinking?: string;
|
|
471
|
+
timeoutSeconds?: number;
|
|
472
|
+
allowUnsafeExternalContent?: boolean;
|
|
473
|
+
};
|
|
474
|
+
interface CronJob {
|
|
475
|
+
id: string;
|
|
476
|
+
agentId?: string;
|
|
477
|
+
sessionKey?: string;
|
|
478
|
+
name: string;
|
|
479
|
+
description?: string;
|
|
480
|
+
enabled: boolean;
|
|
481
|
+
deleteAfterRun?: boolean;
|
|
482
|
+
createdAtMs: number;
|
|
483
|
+
updatedAtMs: number;
|
|
484
|
+
schedule: CronSchedule;
|
|
485
|
+
sessionTarget: SessionTarget;
|
|
486
|
+
wakeMode: WakeMode;
|
|
487
|
+
payload: CronPayload;
|
|
488
|
+
delivery?: {
|
|
489
|
+
mode: "none" | "announce";
|
|
490
|
+
channel?: string;
|
|
491
|
+
to?: string;
|
|
492
|
+
accountId?: string;
|
|
493
|
+
bestEffort?: boolean;
|
|
494
|
+
};
|
|
495
|
+
state: CronJobState;
|
|
496
|
+
}
|
|
497
|
+
interface CronJobCreate {
|
|
498
|
+
id?: string;
|
|
499
|
+
agentId?: string;
|
|
500
|
+
sessionKey?: string;
|
|
501
|
+
name: string;
|
|
502
|
+
description?: string;
|
|
503
|
+
enabled?: boolean;
|
|
504
|
+
deleteAfterRun?: boolean;
|
|
505
|
+
schedule: CronSchedule;
|
|
506
|
+
sessionTarget?: SessionTarget;
|
|
507
|
+
wakeMode?: WakeMode;
|
|
508
|
+
payload: CronPayload;
|
|
509
|
+
delivery?: CronJob["delivery"];
|
|
510
|
+
state?: Partial<CronJobState>;
|
|
511
|
+
}
|
|
512
|
+
interface CronJobPatch {
|
|
513
|
+
name?: string;
|
|
514
|
+
description?: string;
|
|
515
|
+
enabled?: boolean;
|
|
516
|
+
deleteAfterRun?: boolean;
|
|
517
|
+
schedule?: CronSchedule;
|
|
518
|
+
sessionTarget?: SessionTarget;
|
|
519
|
+
wakeMode?: WakeMode;
|
|
520
|
+
payload?: CronPayload;
|
|
521
|
+
delivery?: CronJob["delivery"];
|
|
522
|
+
}
|
|
523
|
+
interface CronRun {
|
|
524
|
+
taskId: string;
|
|
525
|
+
scheduledAtMs: number;
|
|
526
|
+
startedAtMs: number;
|
|
527
|
+
completedAtMs?: number;
|
|
528
|
+
status?: CronRunStatus;
|
|
529
|
+
result?: string;
|
|
530
|
+
error?: string;
|
|
531
|
+
delivered?: boolean;
|
|
532
|
+
}
|
|
533
|
+
interface SchedulerConfig {
|
|
534
|
+
pollIntervalMs?: number;
|
|
535
|
+
maxConcurrentRuns?: number;
|
|
536
|
+
timezone?: string;
|
|
537
|
+
}
|
|
538
|
+
interface SchedulerStatus {
|
|
539
|
+
enabled: boolean;
|
|
540
|
+
storePath?: string;
|
|
541
|
+
jobs: number;
|
|
542
|
+
nextWakeAtMs: number | null;
|
|
543
|
+
}
|
|
544
|
+
interface ListPageOptions {
|
|
545
|
+
includeDisabled?: boolean;
|
|
546
|
+
limit?: number;
|
|
547
|
+
offset?: number;
|
|
548
|
+
query?: string;
|
|
549
|
+
enabled?: "all" | "enabled" | "disabled";
|
|
550
|
+
sortBy?: "nextRunAtMs" | "updatedAtMs" | "name";
|
|
551
|
+
sortDir?: "asc" | "desc";
|
|
552
|
+
}
|
|
553
|
+
interface PaginatedResult<T> {
|
|
554
|
+
items: T[];
|
|
555
|
+
total: number;
|
|
556
|
+
offset: number;
|
|
557
|
+
limit: number;
|
|
558
|
+
hasMore: boolean;
|
|
559
|
+
nextOffset: number | null;
|
|
560
|
+
}
|
|
561
|
+
type SchedulerEvent = {
|
|
562
|
+
jobId: string;
|
|
563
|
+
action: "added";
|
|
564
|
+
nextRunAtMs?: number;
|
|
565
|
+
} | {
|
|
566
|
+
jobId: string;
|
|
567
|
+
action: "updated";
|
|
568
|
+
nextRunAtMs?: number;
|
|
569
|
+
} | {
|
|
570
|
+
jobId: string;
|
|
571
|
+
action: "removed";
|
|
572
|
+
} | {
|
|
573
|
+
jobId: string;
|
|
574
|
+
action: "started";
|
|
575
|
+
runAtMs: number;
|
|
576
|
+
} | {
|
|
577
|
+
jobId: string;
|
|
578
|
+
action: "finished";
|
|
579
|
+
status: CronRunStatus;
|
|
580
|
+
error?: string;
|
|
581
|
+
delivered?: boolean;
|
|
582
|
+
runAtMs: number;
|
|
583
|
+
durationMs?: number;
|
|
584
|
+
nextRunAtMs?: number;
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
export { type Agent, type AgentConfig, type AgentMessage, type AgentRuntime, type AnyTool, type Behavior, type BehaviorConfig, type BehaviorContext, type BehaviorInstance, type BehaviorObject, type BehaviorRegistry, BehaviorRegistryImpl, type ChannelAdapter, type ChannelDispatcher, type ChannelId, type CronDelivery, type CronDeliveryMode, type CronDeliveryStatus, type CronJob, type CronJobCreate, type CronJobPatch, type CronJobState, type CronPayload, type CronRun, type CronRunStatus, type CronSchedule, type DefaultRuntimeExtension, type GenerateOptions, type HonoVariables, type ListPageOptions, type ListenOptions, type PaginatedResult, type Plugin, type PluginContext, type PluginRegistry, type Resolver, type SchedulerConfig, type SchedulerEvent, type SchedulerStatus, type SessionTarget, type StreamOptions, type Tool, type ToolGenerator, type TriggerRequest, type TriggerResponse, type WakeMode, type XmtpClient, type XmtpConversation, type XmtpMessage, type XmtpSender, type XmtpSubjects };
|
package/dist/index.d.ts
CHANGED
|
@@ -31,18 +31,11 @@ type XmtpSender = {
|
|
|
31
31
|
};
|
|
32
32
|
type XmtpSubjects = Record<string, `0x${string}`>;
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
* Base runtime that is always included in agents and tools.
|
|
36
|
-
* Additional fields can be added via generic type parameters as intersections.
|
|
37
|
-
*
|
|
38
|
-
* Example usage:
|
|
39
|
-
* - Basic: AgentRuntime (just chatId and messages)
|
|
40
|
-
* - Extended: AgentRuntime & { userId: string } (adds userId field)
|
|
41
|
-
*/
|
|
42
34
|
interface AgentRuntime {
|
|
43
35
|
conversation: XmtpConversation;
|
|
44
36
|
message: XmtpMessage;
|
|
45
37
|
xmtpClient: XmtpClient;
|
|
38
|
+
scheduler?: unknown;
|
|
46
39
|
}
|
|
47
40
|
|
|
48
41
|
/**
|
|
@@ -239,6 +232,8 @@ interface PluginRegistry<TContext = unknown> {
|
|
|
239
232
|
interface PluginContext {
|
|
240
233
|
agent: Agent;
|
|
241
234
|
behaviors?: BehaviorRegistry;
|
|
235
|
+
scheduler?: unknown;
|
|
236
|
+
xmtpClient?: unknown;
|
|
242
237
|
}
|
|
243
238
|
|
|
244
239
|
/**
|
|
@@ -358,6 +353,8 @@ interface AgentConfig<TRuntimeExtension = DefaultRuntimeExtension> {
|
|
|
358
353
|
maxTokens?: number;
|
|
359
354
|
/** Temperature for generation (0.0 to 2.0) */
|
|
360
355
|
temperature?: number;
|
|
356
|
+
/** Error handler callback for custom error handling (e.g., Sentry) */
|
|
357
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
361
358
|
}
|
|
362
359
|
/**
|
|
363
360
|
* Options for text generation with the agent.
|
|
@@ -395,4 +392,196 @@ interface ListenOptions {
|
|
|
395
392
|
behaviors?: BehaviorObject[];
|
|
396
393
|
}
|
|
397
394
|
|
|
398
|
-
|
|
395
|
+
type ChannelId = "xmtp" | (string & {});
|
|
396
|
+
type CronDeliveryMode = "none" | "announce";
|
|
397
|
+
interface CronDelivery {
|
|
398
|
+
mode: CronDeliveryMode;
|
|
399
|
+
channel?: ChannelId;
|
|
400
|
+
to?: string;
|
|
401
|
+
accountId?: string;
|
|
402
|
+
bestEffort?: boolean;
|
|
403
|
+
}
|
|
404
|
+
interface TriggerRequest {
|
|
405
|
+
to: string;
|
|
406
|
+
message: string;
|
|
407
|
+
metadata?: {
|
|
408
|
+
accountId?: string;
|
|
409
|
+
threadId?: string;
|
|
410
|
+
replyToId?: string;
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
interface TriggerResponse {
|
|
414
|
+
delivered: boolean;
|
|
415
|
+
messageId?: string;
|
|
416
|
+
error?: string;
|
|
417
|
+
}
|
|
418
|
+
interface ChannelAdapter {
|
|
419
|
+
readonly channel: ChannelId;
|
|
420
|
+
readonly port: number;
|
|
421
|
+
start(): Promise<void>;
|
|
422
|
+
stop(): Promise<void>;
|
|
423
|
+
trigger(req: TriggerRequest): Promise<TriggerResponse>;
|
|
424
|
+
}
|
|
425
|
+
interface ChannelDispatcher {
|
|
426
|
+
dispatch(params: {
|
|
427
|
+
channel: ChannelId;
|
|
428
|
+
to: string;
|
|
429
|
+
message: string;
|
|
430
|
+
metadata?: TriggerRequest["metadata"];
|
|
431
|
+
}): Promise<TriggerResponse>;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
type CronSchedule = {
|
|
435
|
+
kind: "at";
|
|
436
|
+
at: string;
|
|
437
|
+
} | {
|
|
438
|
+
kind: "every";
|
|
439
|
+
everyMs: number;
|
|
440
|
+
anchorMs?: number;
|
|
441
|
+
} | {
|
|
442
|
+
kind: "cron";
|
|
443
|
+
expr: string;
|
|
444
|
+
tz?: string;
|
|
445
|
+
staggerMs?: number;
|
|
446
|
+
};
|
|
447
|
+
type CronRunStatus = "ok" | "error" | "skipped";
|
|
448
|
+
type CronDeliveryStatus = "delivered" | "not-delivered" | "unknown" | "not-requested";
|
|
449
|
+
interface CronJobState {
|
|
450
|
+
nextRunAtMs?: number;
|
|
451
|
+
runningAtMs?: number;
|
|
452
|
+
lastRunAtMs?: number;
|
|
453
|
+
lastRunStatus?: CronRunStatus;
|
|
454
|
+
lastError?: string;
|
|
455
|
+
lastDurationMs?: number;
|
|
456
|
+
consecutiveErrors?: number;
|
|
457
|
+
scheduleErrorCount?: number;
|
|
458
|
+
lastDeliveryStatus?: CronDeliveryStatus;
|
|
459
|
+
lastDeliveryError?: string;
|
|
460
|
+
}
|
|
461
|
+
type SessionTarget = "main" | "isolated";
|
|
462
|
+
type WakeMode = "now" | "next-heartbeat";
|
|
463
|
+
type CronPayload = {
|
|
464
|
+
kind: "systemEvent";
|
|
465
|
+
text: string;
|
|
466
|
+
} | {
|
|
467
|
+
kind: "agentTurn";
|
|
468
|
+
message: string;
|
|
469
|
+
model?: string;
|
|
470
|
+
thinking?: string;
|
|
471
|
+
timeoutSeconds?: number;
|
|
472
|
+
allowUnsafeExternalContent?: boolean;
|
|
473
|
+
};
|
|
474
|
+
interface CronJob {
|
|
475
|
+
id: string;
|
|
476
|
+
agentId?: string;
|
|
477
|
+
sessionKey?: string;
|
|
478
|
+
name: string;
|
|
479
|
+
description?: string;
|
|
480
|
+
enabled: boolean;
|
|
481
|
+
deleteAfterRun?: boolean;
|
|
482
|
+
createdAtMs: number;
|
|
483
|
+
updatedAtMs: number;
|
|
484
|
+
schedule: CronSchedule;
|
|
485
|
+
sessionTarget: SessionTarget;
|
|
486
|
+
wakeMode: WakeMode;
|
|
487
|
+
payload: CronPayload;
|
|
488
|
+
delivery?: {
|
|
489
|
+
mode: "none" | "announce";
|
|
490
|
+
channel?: string;
|
|
491
|
+
to?: string;
|
|
492
|
+
accountId?: string;
|
|
493
|
+
bestEffort?: boolean;
|
|
494
|
+
};
|
|
495
|
+
state: CronJobState;
|
|
496
|
+
}
|
|
497
|
+
interface CronJobCreate {
|
|
498
|
+
id?: string;
|
|
499
|
+
agentId?: string;
|
|
500
|
+
sessionKey?: string;
|
|
501
|
+
name: string;
|
|
502
|
+
description?: string;
|
|
503
|
+
enabled?: boolean;
|
|
504
|
+
deleteAfterRun?: boolean;
|
|
505
|
+
schedule: CronSchedule;
|
|
506
|
+
sessionTarget?: SessionTarget;
|
|
507
|
+
wakeMode?: WakeMode;
|
|
508
|
+
payload: CronPayload;
|
|
509
|
+
delivery?: CronJob["delivery"];
|
|
510
|
+
state?: Partial<CronJobState>;
|
|
511
|
+
}
|
|
512
|
+
interface CronJobPatch {
|
|
513
|
+
name?: string;
|
|
514
|
+
description?: string;
|
|
515
|
+
enabled?: boolean;
|
|
516
|
+
deleteAfterRun?: boolean;
|
|
517
|
+
schedule?: CronSchedule;
|
|
518
|
+
sessionTarget?: SessionTarget;
|
|
519
|
+
wakeMode?: WakeMode;
|
|
520
|
+
payload?: CronPayload;
|
|
521
|
+
delivery?: CronJob["delivery"];
|
|
522
|
+
}
|
|
523
|
+
interface CronRun {
|
|
524
|
+
taskId: string;
|
|
525
|
+
scheduledAtMs: number;
|
|
526
|
+
startedAtMs: number;
|
|
527
|
+
completedAtMs?: number;
|
|
528
|
+
status?: CronRunStatus;
|
|
529
|
+
result?: string;
|
|
530
|
+
error?: string;
|
|
531
|
+
delivered?: boolean;
|
|
532
|
+
}
|
|
533
|
+
interface SchedulerConfig {
|
|
534
|
+
pollIntervalMs?: number;
|
|
535
|
+
maxConcurrentRuns?: number;
|
|
536
|
+
timezone?: string;
|
|
537
|
+
}
|
|
538
|
+
interface SchedulerStatus {
|
|
539
|
+
enabled: boolean;
|
|
540
|
+
storePath?: string;
|
|
541
|
+
jobs: number;
|
|
542
|
+
nextWakeAtMs: number | null;
|
|
543
|
+
}
|
|
544
|
+
interface ListPageOptions {
|
|
545
|
+
includeDisabled?: boolean;
|
|
546
|
+
limit?: number;
|
|
547
|
+
offset?: number;
|
|
548
|
+
query?: string;
|
|
549
|
+
enabled?: "all" | "enabled" | "disabled";
|
|
550
|
+
sortBy?: "nextRunAtMs" | "updatedAtMs" | "name";
|
|
551
|
+
sortDir?: "asc" | "desc";
|
|
552
|
+
}
|
|
553
|
+
interface PaginatedResult<T> {
|
|
554
|
+
items: T[];
|
|
555
|
+
total: number;
|
|
556
|
+
offset: number;
|
|
557
|
+
limit: number;
|
|
558
|
+
hasMore: boolean;
|
|
559
|
+
nextOffset: number | null;
|
|
560
|
+
}
|
|
561
|
+
type SchedulerEvent = {
|
|
562
|
+
jobId: string;
|
|
563
|
+
action: "added";
|
|
564
|
+
nextRunAtMs?: number;
|
|
565
|
+
} | {
|
|
566
|
+
jobId: string;
|
|
567
|
+
action: "updated";
|
|
568
|
+
nextRunAtMs?: number;
|
|
569
|
+
} | {
|
|
570
|
+
jobId: string;
|
|
571
|
+
action: "removed";
|
|
572
|
+
} | {
|
|
573
|
+
jobId: string;
|
|
574
|
+
action: "started";
|
|
575
|
+
runAtMs: number;
|
|
576
|
+
} | {
|
|
577
|
+
jobId: string;
|
|
578
|
+
action: "finished";
|
|
579
|
+
status: CronRunStatus;
|
|
580
|
+
error?: string;
|
|
581
|
+
delivered?: boolean;
|
|
582
|
+
runAtMs: number;
|
|
583
|
+
durationMs?: number;
|
|
584
|
+
nextRunAtMs?: number;
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
export { type Agent, type AgentConfig, type AgentMessage, type AgentRuntime, type AnyTool, type Behavior, type BehaviorConfig, type BehaviorContext, type BehaviorInstance, type BehaviorObject, type BehaviorRegistry, BehaviorRegistryImpl, type ChannelAdapter, type ChannelDispatcher, type ChannelId, type CronDelivery, type CronDeliveryMode, type CronDeliveryStatus, type CronJob, type CronJobCreate, type CronJobPatch, type CronJobState, type CronPayload, type CronRun, type CronRunStatus, type CronSchedule, type DefaultRuntimeExtension, type GenerateOptions, type HonoVariables, type ListPageOptions, type ListenOptions, type PaginatedResult, type Plugin, type PluginContext, type PluginRegistry, type Resolver, type SchedulerConfig, type SchedulerEvent, type SchedulerStatus, type SessionTarget, type StreamOptions, type Tool, type ToolGenerator, type TriggerRequest, type TriggerResponse, type WakeMode, type XmtpClient, type XmtpConversation, type XmtpMessage, type XmtpSender, type XmtpSubjects };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hybrd/types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"xmtp",
|
|
6
6
|
"agent",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"ai": "^
|
|
25
|
+
"ai": "^6.0.0",
|
|
26
26
|
"zod": "^3.22.0 || ^4"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@types/node": "22.8.6",
|
|
39
39
|
"tsup": "^8.5.0",
|
|
40
40
|
"vitest": "^3.2.4",
|
|
41
|
-
"@config/
|
|
42
|
-
"@config/
|
|
41
|
+
"@config/biome": "0.0.0",
|
|
42
|
+
"@config/tsconfig": "0.0.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsup",
|
package/src/agent.ts
CHANGED
|
@@ -143,6 +143,8 @@ export interface AgentConfig<TRuntimeExtension = DefaultRuntimeExtension> {
|
|
|
143
143
|
maxTokens?: number
|
|
144
144
|
/** Temperature for generation (0.0 to 2.0) */
|
|
145
145
|
temperature?: number
|
|
146
|
+
/** Error handler callback for custom error handling (e.g., Sentry) */
|
|
147
|
+
onError?: (error: Error) => void | Promise<void>
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
/**
|
package/src/channel.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type ChannelId = "xmtp" | (string & {})
|
|
2
|
+
|
|
3
|
+
export type CronDeliveryMode = "none" | "announce"
|
|
4
|
+
|
|
5
|
+
export interface CronDelivery {
|
|
6
|
+
mode: CronDeliveryMode
|
|
7
|
+
channel?: ChannelId
|
|
8
|
+
to?: string
|
|
9
|
+
accountId?: string
|
|
10
|
+
bestEffort?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface TriggerRequest {
|
|
14
|
+
to: string
|
|
15
|
+
message: string
|
|
16
|
+
metadata?: {
|
|
17
|
+
accountId?: string
|
|
18
|
+
threadId?: string
|
|
19
|
+
replyToId?: string
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TriggerResponse {
|
|
24
|
+
delivered: boolean
|
|
25
|
+
messageId?: string
|
|
26
|
+
error?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ChannelAdapter {
|
|
30
|
+
readonly channel: ChannelId
|
|
31
|
+
readonly port: number
|
|
32
|
+
start(): Promise<void>
|
|
33
|
+
stop(): Promise<void>
|
|
34
|
+
trigger(req: TriggerRequest): Promise<TriggerResponse>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ChannelDispatcher {
|
|
38
|
+
dispatch(params: {
|
|
39
|
+
channel: ChannelId
|
|
40
|
+
to: string
|
|
41
|
+
message: string
|
|
42
|
+
metadata?: TriggerRequest["metadata"]
|
|
43
|
+
}): Promise<TriggerResponse>
|
|
44
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -49,3 +49,34 @@ export type {
|
|
|
49
49
|
BehaviorObject,
|
|
50
50
|
BehaviorRegistry
|
|
51
51
|
} from "./behavior"
|
|
52
|
+
|
|
53
|
+
// Channel types
|
|
54
|
+
export type {
|
|
55
|
+
ChannelId,
|
|
56
|
+
CronDeliveryMode,
|
|
57
|
+
CronDelivery,
|
|
58
|
+
TriggerRequest,
|
|
59
|
+
TriggerResponse,
|
|
60
|
+
ChannelAdapter,
|
|
61
|
+
ChannelDispatcher
|
|
62
|
+
} from "./channel"
|
|
63
|
+
|
|
64
|
+
// Schedule types
|
|
65
|
+
export type {
|
|
66
|
+
CronSchedule,
|
|
67
|
+
CronRunStatus,
|
|
68
|
+
CronDeliveryStatus,
|
|
69
|
+
CronJobState,
|
|
70
|
+
SessionTarget,
|
|
71
|
+
WakeMode,
|
|
72
|
+
CronPayload,
|
|
73
|
+
CronJob,
|
|
74
|
+
CronJobCreate,
|
|
75
|
+
CronJobPatch,
|
|
76
|
+
CronRun,
|
|
77
|
+
SchedulerConfig,
|
|
78
|
+
SchedulerStatus,
|
|
79
|
+
ListPageOptions,
|
|
80
|
+
PaginatedResult,
|
|
81
|
+
SchedulerEvent
|
|
82
|
+
} from "./schedule"
|
package/src/plugin.ts
CHANGED
package/src/runtime.ts
CHANGED
|
@@ -1,31 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
XmtpClient,
|
|
3
|
-
// XmtpClient,
|
|
4
|
-
// XmtpSender,
|
|
5
|
-
// XmtpSubjects
|
|
6
|
-
XmtpConversation,
|
|
7
|
-
XmtpMessage
|
|
8
|
-
} from "./xmtp"
|
|
1
|
+
import type { XmtpClient, XmtpConversation, XmtpMessage } from "./xmtp"
|
|
9
2
|
|
|
10
|
-
/**
|
|
11
|
-
* Base runtime that is always included in agents and tools.
|
|
12
|
-
* Additional fields can be added via generic type parameters as intersections.
|
|
13
|
-
*
|
|
14
|
-
* Example usage:
|
|
15
|
-
* - Basic: AgentRuntime (just chatId and messages)
|
|
16
|
-
* - Extended: AgentRuntime & { userId: string } (adds userId field)
|
|
17
|
-
*/
|
|
18
3
|
export interface AgentRuntime {
|
|
19
4
|
conversation: XmtpConversation
|
|
20
5
|
message: XmtpMessage
|
|
21
|
-
// parentMessage?: XmtpMessage
|
|
22
|
-
// rootMessage: XmtpMessage
|
|
23
|
-
// sender: XmtpSender
|
|
24
|
-
// subjects: XmtpSubjects
|
|
25
6
|
xmtpClient: XmtpClient
|
|
7
|
+
scheduler?: unknown
|
|
26
8
|
}
|
|
27
|
-
|
|
28
|
-
// export type AgentRuntime = BaseRuntime & {
|
|
29
|
-
// chatId?: string
|
|
30
|
-
// messages: Array<UIMessage>
|
|
31
|
-
// }
|
package/src/schedule.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
export type CronSchedule =
|
|
2
|
+
| { kind: "at"; at: string }
|
|
3
|
+
| { kind: "every"; everyMs: number; anchorMs?: number }
|
|
4
|
+
| { kind: "cron"; expr: string; tz?: string; staggerMs?: number }
|
|
5
|
+
|
|
6
|
+
export type CronRunStatus = "ok" | "error" | "skipped"
|
|
7
|
+
export type CronDeliveryStatus =
|
|
8
|
+
| "delivered"
|
|
9
|
+
| "not-delivered"
|
|
10
|
+
| "unknown"
|
|
11
|
+
| "not-requested"
|
|
12
|
+
|
|
13
|
+
export interface CronJobState {
|
|
14
|
+
nextRunAtMs?: number
|
|
15
|
+
runningAtMs?: number
|
|
16
|
+
lastRunAtMs?: number
|
|
17
|
+
lastRunStatus?: CronRunStatus
|
|
18
|
+
lastError?: string
|
|
19
|
+
lastDurationMs?: number
|
|
20
|
+
consecutiveErrors?: number
|
|
21
|
+
scheduleErrorCount?: number
|
|
22
|
+
lastDeliveryStatus?: CronDeliveryStatus
|
|
23
|
+
lastDeliveryError?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type SessionTarget = "main" | "isolated"
|
|
27
|
+
export type WakeMode = "now" | "next-heartbeat"
|
|
28
|
+
|
|
29
|
+
export type CronPayload =
|
|
30
|
+
| { kind: "systemEvent"; text: string }
|
|
31
|
+
| {
|
|
32
|
+
kind: "agentTurn"
|
|
33
|
+
message: string
|
|
34
|
+
model?: string
|
|
35
|
+
thinking?: string
|
|
36
|
+
timeoutSeconds?: number
|
|
37
|
+
allowUnsafeExternalContent?: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface CronJob {
|
|
41
|
+
id: string
|
|
42
|
+
agentId?: string
|
|
43
|
+
sessionKey?: string
|
|
44
|
+
name: string
|
|
45
|
+
description?: string
|
|
46
|
+
enabled: boolean
|
|
47
|
+
deleteAfterRun?: boolean
|
|
48
|
+
createdAtMs: number
|
|
49
|
+
updatedAtMs: number
|
|
50
|
+
schedule: CronSchedule
|
|
51
|
+
sessionTarget: SessionTarget
|
|
52
|
+
wakeMode: WakeMode
|
|
53
|
+
payload: CronPayload
|
|
54
|
+
delivery?: {
|
|
55
|
+
mode: "none" | "announce"
|
|
56
|
+
channel?: string
|
|
57
|
+
to?: string
|
|
58
|
+
accountId?: string
|
|
59
|
+
bestEffort?: boolean
|
|
60
|
+
}
|
|
61
|
+
state: CronJobState
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface CronJobCreate {
|
|
65
|
+
id?: string
|
|
66
|
+
agentId?: string
|
|
67
|
+
sessionKey?: string
|
|
68
|
+
name: string
|
|
69
|
+
description?: string
|
|
70
|
+
enabled?: boolean
|
|
71
|
+
deleteAfterRun?: boolean
|
|
72
|
+
schedule: CronSchedule
|
|
73
|
+
sessionTarget?: SessionTarget
|
|
74
|
+
wakeMode?: WakeMode
|
|
75
|
+
payload: CronPayload
|
|
76
|
+
delivery?: CronJob["delivery"]
|
|
77
|
+
state?: Partial<CronJobState>
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface CronJobPatch {
|
|
81
|
+
name?: string
|
|
82
|
+
description?: string
|
|
83
|
+
enabled?: boolean
|
|
84
|
+
deleteAfterRun?: boolean
|
|
85
|
+
schedule?: CronSchedule
|
|
86
|
+
sessionTarget?: SessionTarget
|
|
87
|
+
wakeMode?: WakeMode
|
|
88
|
+
payload?: CronPayload
|
|
89
|
+
delivery?: CronJob["delivery"]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface CronRun {
|
|
93
|
+
taskId: string
|
|
94
|
+
scheduledAtMs: number
|
|
95
|
+
startedAtMs: number
|
|
96
|
+
completedAtMs?: number
|
|
97
|
+
status?: CronRunStatus
|
|
98
|
+
result?: string
|
|
99
|
+
error?: string
|
|
100
|
+
delivered?: boolean
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface SchedulerConfig {
|
|
104
|
+
pollIntervalMs?: number
|
|
105
|
+
maxConcurrentRuns?: number
|
|
106
|
+
timezone?: string
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface SchedulerStatus {
|
|
110
|
+
enabled: boolean
|
|
111
|
+
storePath?: string
|
|
112
|
+
jobs: number
|
|
113
|
+
nextWakeAtMs: number | null
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface ListPageOptions {
|
|
117
|
+
includeDisabled?: boolean
|
|
118
|
+
limit?: number
|
|
119
|
+
offset?: number
|
|
120
|
+
query?: string
|
|
121
|
+
enabled?: "all" | "enabled" | "disabled"
|
|
122
|
+
sortBy?: "nextRunAtMs" | "updatedAtMs" | "name"
|
|
123
|
+
sortDir?: "asc" | "desc"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface PaginatedResult<T> {
|
|
127
|
+
items: T[]
|
|
128
|
+
total: number
|
|
129
|
+
offset: number
|
|
130
|
+
limit: number
|
|
131
|
+
hasMore: boolean
|
|
132
|
+
nextOffset: number | null
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type SchedulerEvent =
|
|
136
|
+
| { jobId: string; action: "added"; nextRunAtMs?: number }
|
|
137
|
+
| { jobId: string; action: "updated"; nextRunAtMs?: number }
|
|
138
|
+
| { jobId: string; action: "removed" }
|
|
139
|
+
| { jobId: string; action: "started"; runAtMs: number }
|
|
140
|
+
| {
|
|
141
|
+
jobId: string
|
|
142
|
+
action: "finished"
|
|
143
|
+
status: CronRunStatus
|
|
144
|
+
error?: string
|
|
145
|
+
delivered?: boolean
|
|
146
|
+
runAtMs: number
|
|
147
|
+
durationMs?: number
|
|
148
|
+
nextRunAtMs?: number
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export type {
|
|
152
|
+
ChannelId,
|
|
153
|
+
CronDeliveryMode,
|
|
154
|
+
CronDelivery,
|
|
155
|
+
TriggerRequest,
|
|
156
|
+
TriggerResponse,
|
|
157
|
+
ChannelAdapter,
|
|
158
|
+
ChannelDispatcher
|
|
159
|
+
} from "./channel.js"
|