@hybrd/types 0.7.5 → 1.4.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.
@@ -0,0 +1,418 @@
1
+ import { UIMessage, LanguageModel, generateText, TelemetrySettings, streamText, UIMessageStreamOnFinishCallback } from 'ai';
2
+ import { Conversation, DecodedMessage, Client } from '@xmtp/node-sdk';
3
+ import { Hono } from 'hono';
4
+ import { z } from 'zod';
5
+
6
+ /**
7
+ * Resolver interface for address resolution
8
+ */
9
+ interface Resolver {
10
+ resolve: (address: string) => Promise<string | null>;
11
+ }
12
+
13
+ /**
14
+ * @fileoverview XMTP Types
15
+ *
16
+ * Type definitions for both the XMTP core client and service client library.
17
+ */
18
+
19
+ type HonoVariables = {
20
+ xmtpClient: XmtpClient;
21
+ resolver?: Resolver;
22
+ };
23
+ type XmtpClient = Client<unknown>;
24
+ type XmtpConversation = Conversation<unknown>;
25
+ type XmtpMessage = DecodedMessage<unknown>;
26
+ type XmtpSender = {
27
+ address: string;
28
+ inboxId: string;
29
+ name: string;
30
+ basename?: string;
31
+ };
32
+ type XmtpSubjects = Record<string, `0x${string}`>;
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
+ interface AgentRuntime {
43
+ conversation: XmtpConversation;
44
+ message: XmtpMessage;
45
+ xmtpClient: XmtpClient;
46
+ }
47
+
48
+ /**
49
+ * Configuration options for a behavior
50
+ */
51
+ interface BehaviorConfig {
52
+ /** Whether the behavior is enabled */
53
+ enabled?: boolean;
54
+ /** Optional configuration data for the behavior */
55
+ config?: Record<string, unknown>;
56
+ }
57
+ /**
58
+ * Context provided to behaviors when they execute
59
+ */
60
+ interface BehaviorContext<TRuntimeExtension = Record<string, never>> {
61
+ /** The base runtime context */
62
+ runtime: AgentRuntime & TRuntimeExtension;
63
+ /** The XMTP client instance */
64
+ client: XmtpClient;
65
+ /** The conversation the message came from */
66
+ conversation: XmtpConversation;
67
+ /** The message that triggered the behavior */
68
+ message: XmtpMessage;
69
+ /** The agent's response (available in post-response behaviors) */
70
+ response?: string;
71
+ /** Send options that behaviors can modify */
72
+ sendOptions?: {
73
+ /** Whether to thread the reply to the original message */
74
+ threaded?: boolean;
75
+ /** Content type override */
76
+ contentType?: string;
77
+ /** Whether this message should be filtered out and not processed */
78
+ filtered?: boolean;
79
+ /** Additional metadata */
80
+ metadata?: Record<string, unknown>;
81
+ };
82
+ /**
83
+ * Continue to the next behavior in the middleware chain
84
+ * If not called, the behavior chain stops processing
85
+ */
86
+ next?: () => Promise<void>;
87
+ /**
88
+ * Whether the middleware chain was stopped early
89
+ * This gets set to true when a behavior doesn't call next()
90
+ */
91
+ stopped?: boolean;
92
+ }
93
+ /**
94
+ * A behavior that can be executed before or after agent responses
95
+ */
96
+ interface BehaviorObject<TRuntimeExtension = Record<string, never>> {
97
+ /** Unique identifier for the behavior */
98
+ id: string;
99
+ /** Configuration for the behavior */
100
+ config: BehaviorConfig;
101
+ /**
102
+ * Execute the behavior before the agent responds
103
+ * @param context - The context in which to execute the behavior
104
+ */
105
+ before?(context: BehaviorContext<TRuntimeExtension>): Promise<void> | void;
106
+ /**
107
+ * Execute the behavior after the agent responds
108
+ * @param context - The context in which to execute the behavior
109
+ */
110
+ after?(context: BehaviorContext<TRuntimeExtension>): Promise<void> | void;
111
+ }
112
+ /**
113
+ * Factory function to create a behavior instance
114
+ */
115
+ type Behavior<TConfig = Record<string, unknown>> = (config: TConfig & BehaviorConfig) => BehaviorObject;
116
+ /**
117
+ * Pre-configured behavior instance that can be used directly
118
+ */
119
+ type BehaviorInstance = Behavior;
120
+ /**
121
+ * Behavior registry for managing and executing behaviors
122
+ */
123
+ interface BehaviorRegistry {
124
+ /**
125
+ * Register a behavior with the registry
126
+ */
127
+ register(behavior: BehaviorObject): void;
128
+ /**
129
+ * Register multiple behaviors at once
130
+ */
131
+ registerAll(behaviors: BehaviorObject[]): void;
132
+ /**
133
+ * Get all registered behaviors
134
+ */
135
+ getAll(): BehaviorObject[];
136
+ /**
137
+ * Get behaviors that should run before the agent responds
138
+ */
139
+ getBeforeBehaviors(): BehaviorObject[];
140
+ /**
141
+ * Get behaviors that should run after the agent responds
142
+ */
143
+ getAfterBehaviors(): BehaviorObject[];
144
+ /**
145
+ * Execute all before-response behaviors as a middleware chain
146
+ */
147
+ executeBefore(context: BehaviorContext): Promise<void>;
148
+ /**
149
+ * Execute all after-response behaviors as a middleware chain
150
+ */
151
+ executeAfter(context: BehaviorContext): Promise<void>;
152
+ /**
153
+ * Clear all registered behaviors
154
+ */
155
+ clear(): void;
156
+ }
157
+ /**
158
+ * Concrete implementation of the BehaviorRegistry interface
159
+ */
160
+ declare class BehaviorRegistryImpl implements BehaviorRegistry {
161
+ private behaviors;
162
+ /**
163
+ * Register a behavior with the registry
164
+ */
165
+ register(behavior: BehaviorObject): void;
166
+ /**
167
+ * Register multiple behaviors at once
168
+ */
169
+ registerAll(behaviors: BehaviorObject[]): void;
170
+ /**
171
+ * Get all registered behaviors
172
+ */
173
+ getAll(): BehaviorObject[];
174
+ /**
175
+ * Get behaviors that should run before the agent responds
176
+ */
177
+ getBeforeBehaviors(): BehaviorObject[];
178
+ /**
179
+ * Get behaviors that should run after the agent responds
180
+ */
181
+ getAfterBehaviors(): BehaviorObject[];
182
+ /**
183
+ * Execute all before-response behaviors as a middleware chain
184
+ */
185
+ executeBefore(context: BehaviorContext): Promise<void>;
186
+ /**
187
+ * Execute all after-response behaviors as a middleware chain
188
+ */
189
+ executeAfter(context: BehaviorContext): Promise<void>;
190
+ /**
191
+ * Clear all registered behaviors
192
+ */
193
+ clear(): void;
194
+ }
195
+
196
+ /**
197
+ * Plugin interface for extending the agent's Hono app
198
+ *
199
+ * @description
200
+ * Plugins allow you to extend the agent's HTTP server with additional
201
+ * routes, middleware, and functionality. Each plugin receives the Hono
202
+ * app instance and can modify it as needed.
203
+ *
204
+ * @template T - Optional context type that can be passed to the plugin
205
+ */
206
+ interface Plugin<T = Record<string, never>> {
207
+ /**
208
+ * Unique identifier for the plugin
209
+ */
210
+ name: string;
211
+ /**
212
+ * Optional description of what the plugin does
213
+ */
214
+ description?: string;
215
+ /**
216
+ * Function that applies the plugin to the Hono app
217
+ *
218
+ * @param app - The Hono app instance to extend
219
+ * @param context - Optional context data passed to the plugin
220
+ */
221
+ apply: (app: Hono<{
222
+ Variables: HonoVariables;
223
+ }>, context: T) => void | Promise<void>;
224
+ }
225
+ /**
226
+ * Plugin registry that manages all registered plugins
227
+ *
228
+ * @description
229
+ * The plugin registry allows you to register, configure, and apply
230
+ * plugins to Hono apps. It provides a centralized way to manage
231
+ * plugin dependencies and execution order.
232
+ */
233
+ interface PluginRegistry<TContext = unknown> {
234
+ register: (plugin: Plugin<TContext>) => void;
235
+ applyAll: (app: Hono<{
236
+ Variables: HonoVariables;
237
+ }>, context: TContext) => Promise<void>;
238
+ }
239
+ interface PluginContext {
240
+ agent: Agent;
241
+ behaviors?: BehaviorRegistry;
242
+ }
243
+
244
+ /**
245
+ * Configuration interface for creating custom tools that integrate with AI SDK.
246
+ */
247
+ interface ToolConfig<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny, TRuntimeExtension = DefaultRuntimeExtension> {
248
+ /** Unique identifier for the tool */
249
+ id: string;
250
+ /** Human-readable description of what the tool does */
251
+ description: string;
252
+ /** Zod schema for validating tool input */
253
+ inputSchema: TInput;
254
+ /** Optional Zod schema for validating tool output */
255
+ outputSchema?: TOutput;
256
+ /** Function that executes the tool's logic */
257
+ execute: (args: {
258
+ input: z.infer<TInput>;
259
+ runtime: AgentRuntime & TRuntimeExtension;
260
+ messages: UIMessage[];
261
+ }) => Promise<z.infer<TOutput>>;
262
+ }
263
+ /**
264
+ * Internal tool interface used throughout the agent framework.
265
+ * Similar to ToolConfig but without the ID field, used after tool creation.
266
+ */
267
+ interface Tool<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.ZodTypeAny = z.ZodTypeAny, TRuntimeExtension = DefaultRuntimeExtension> {
268
+ /** Human-readable description of what the tool does */
269
+ description: string;
270
+ /** Zod schema for validating tool input */
271
+ inputSchema: TInput;
272
+ /** Optional Zod schema for validating tool output */
273
+ outputSchema?: TOutput;
274
+ /** Function that executes the tool's logic */
275
+ execute: (args: {
276
+ input: z.infer<TInput>;
277
+ runtime: AgentRuntime & TRuntimeExtension;
278
+ messages: UIMessage[];
279
+ }) => Promise<z.infer<TOutput>>;
280
+ }
281
+ type AnyTool<TRuntimeExtension = DefaultRuntimeExtension> = Tool<any, any, TRuntimeExtension>;
282
+
283
+ type AgentMessage = UIMessage;
284
+ interface Agent<TRuntimeExtension = Record<string, never>, TPluginContext = unknown> {
285
+ /** Agent's unique identifier */
286
+ readonly name: string;
287
+ /** Plugin registry for extending the agent's HTTP server */
288
+ readonly plugins: PluginRegistry<TPluginContext>;
289
+ /**
290
+ * Generates a text completion using the agent's configuration.
291
+ * @param messages - Conversation messages to generate from
292
+ * @param options - Generation options including runtime context
293
+ * @returns Generated text completion result
294
+ */
295
+ generate(messages: AgentMessage[], options: GenerateOptions<TRuntimeExtension>): Promise<Awaited<ReturnType<typeof generateText>>>;
296
+ /**
297
+ * Streams a text completion using the agent's configuration.
298
+ * @param messages - Conversation messages to generate from
299
+ * @param options - Streaming options including runtime context
300
+ * @returns Streaming response that can be consumed
301
+ */
302
+ stream(messages: AgentMessage[], options: StreamOptions<TRuntimeExtension>): Promise<Response>;
303
+ /**
304
+ * Gets the agent's configuration for debugging and inspection.
305
+ * @returns Object containing agent configuration details
306
+ */
307
+ getConfig(): {
308
+ name: string;
309
+ hasModel: boolean;
310
+ hasTools: boolean;
311
+ hasInstructions: boolean;
312
+ };
313
+ /**
314
+ * Gets the agent's instructions without running generation.
315
+ * Useful for external integrations that need instructions separately.
316
+ * @param options - Options containing runtime context and optional messages
317
+ * @returns Resolved instructions string
318
+ */
319
+ getInstructions(options: {
320
+ runtime: AgentRuntime & TRuntimeExtension;
321
+ messages?: AgentMessage[];
322
+ }): Promise<string | undefined>;
323
+ /**
324
+ * Gets the agent's tools without running generation.
325
+ * Useful for external integrations that need tools separately.
326
+ * @param options - Options containing runtime context and optional messages
327
+ * @returns Resolved tools object
328
+ */
329
+ getTools(options: {
330
+ runtime: AgentRuntime & TRuntimeExtension;
331
+ messages?: AgentMessage[];
332
+ }): Promise<Record<string, AnyTool<TRuntimeExtension>> | undefined>;
333
+ /**
334
+ * Creates the complete runtime context by merging base runtime with custom extension.
335
+ * @param baseRuntime - The base runtime context containing XMTP properties
336
+ * @returns Complete runtime context with custom extensions applied
337
+ */
338
+ createRuntimeContext(baseRuntime: AgentRuntime): Promise<AgentRuntime & TRuntimeExtension>;
339
+ /**
340
+ * Registers a plugin with the agent
341
+ * @param plugin - The plugin to register
342
+ */
343
+ use(plugin: Plugin<TPluginContext>): void;
344
+ /**
345
+ * Starts listening for messages and events using the agent instance.
346
+ * @param opts - Configuration options for the listener, excluding the agent property
347
+ */
348
+ listen(opts: Omit<ListenOptions, "agent">): Promise<void>;
349
+ }
350
+ type DefaultRuntimeExtension = Record<string, never>;
351
+ type ToolGenerator<TRuntimeExtension = DefaultRuntimeExtension> = (props: {
352
+ runtime: AgentRuntime & TRuntimeExtension;
353
+ messages: AgentMessage[];
354
+ }) => Record<string, AnyTool<TRuntimeExtension>> | Promise<Record<string, AnyTool<TRuntimeExtension>>>;
355
+ /**
356
+ * Configuration interface for creating an Agent instance.
357
+ * Supports both static and dynamic configuration through functions.
358
+ */
359
+ interface AgentConfig<TRuntimeExtension = DefaultRuntimeExtension> {
360
+ /** Unique identifier for the agent */
361
+ name: string;
362
+ /** Language model to use, can be static or dynamically resolved */
363
+ model: LanguageModel | ((props: {
364
+ runtime: AgentRuntime & TRuntimeExtension;
365
+ }) => LanguageModel | Promise<LanguageModel>);
366
+ /** Tools available to the agent, can be static or dynamically generated */
367
+ tools?: Record<string, AnyTool<TRuntimeExtension>> | ToolGenerator<TRuntimeExtension>;
368
+ /** Instructions for the agent, can be static or dynamically resolved */
369
+ instructions: string | ((props: {
370
+ messages: AgentMessage[];
371
+ runtime: AgentRuntime & TRuntimeExtension;
372
+ }) => string | Promise<string>);
373
+ /** Function to create the runtime extension, type will be inferred */
374
+ createRuntime?: (runtime: AgentRuntime) => TRuntimeExtension | Promise<TRuntimeExtension>;
375
+ /** Maximum number of steps the agent can take */
376
+ maxSteps?: number;
377
+ /** Maximum tokens for generation */
378
+ maxTokens?: number;
379
+ /** Temperature for generation (0.0 to 2.0) */
380
+ temperature?: number;
381
+ }
382
+ /**
383
+ * Options for text generation with the agent.
384
+ * Extends AI SDK parameters while adding agent-specific options.
385
+ */
386
+ interface GenerateOptions<TRuntimeExtension = DefaultRuntimeExtension> extends Omit<Parameters<typeof generateText>[0], "model" | "tools" | "instructions" | "onFinish"> {
387
+ /** Maximum tokens for generation */
388
+ maxTokens?: number;
389
+ /** Runtime context for the agent */
390
+ runtime: AgentRuntime & TRuntimeExtension;
391
+ /** Optional telemetry configuration */
392
+ telemetry?: NonNullable<TelemetrySettings>;
393
+ }
394
+ interface StreamOptions<TRuntimeExtension = DefaultRuntimeExtension> extends Omit<Parameters<typeof streamText>[0], "model" | "tools" | "instructions" | "onFinish"> {
395
+ /** Maximum tokens for generation */
396
+ maxTokens?: number;
397
+ /** Runtime context for the agent */
398
+ runtime: AgentRuntime & TRuntimeExtension;
399
+ /** Optional telemetry configuration */
400
+ telemetry?: NonNullable<TelemetrySettings>;
401
+ /** Callback when streaming finishes */
402
+ onFinish?: UIMessageStreamOnFinishCallback<AgentMessage>;
403
+ }
404
+ /**
405
+ * Options for starting the agent listener
406
+ * @property agent - The agent instance to use
407
+ * @property port - The port number to listen on (defaults to 8454)
408
+ * @property plugins - Optional array of plugins to apply to the server
409
+ * @property behaviors - Optional array of behaviors to apply to message processing
410
+ */
411
+ interface ListenOptions {
412
+ agent: Agent<unknown, unknown>;
413
+ port: string;
414
+ plugins?: Plugin<unknown>[];
415
+ behaviors?: BehaviorObject[];
416
+ }
417
+
418
+ 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 DefaultRuntimeExtension, type GenerateOptions, type HonoVariables, type ListenOptions, type Plugin, type PluginContext, type PluginRegistry, type Resolver, type StreamOptions, type Tool, type ToolConfig, type ToolGenerator, type XmtpClient, type XmtpConversation, type XmtpMessage, type XmtpSender, type XmtpSubjects };
package/dist/index.js ADDED
@@ -0,0 +1,97 @@
1
+ // src/behavior.ts
2
+ var BehaviorRegistryImpl = class {
3
+ behaviors = [];
4
+ /**
5
+ * Register a behavior with the registry
6
+ */
7
+ register(behavior) {
8
+ this.behaviors.push(behavior);
9
+ }
10
+ /**
11
+ * Register multiple behaviors at once
12
+ */
13
+ registerAll(behaviors) {
14
+ this.behaviors.push(...behaviors);
15
+ }
16
+ /**
17
+ * Get all registered behaviors
18
+ */
19
+ getAll() {
20
+ return [...this.behaviors];
21
+ }
22
+ /**
23
+ * Get behaviors that should run before the agent responds
24
+ */
25
+ getBeforeBehaviors() {
26
+ return this.behaviors.filter((behavior) => behavior.before);
27
+ }
28
+ /**
29
+ * Get behaviors that should run after the agent responds
30
+ */
31
+ getAfterBehaviors() {
32
+ return this.behaviors.filter((behavior) => behavior.after);
33
+ }
34
+ /**
35
+ * Execute all before-response behaviors as a middleware chain
36
+ */
37
+ async executeBefore(context) {
38
+ const behaviors = this.getBeforeBehaviors();
39
+ let currentIndex = 0;
40
+ const next = async () => {
41
+ if (currentIndex >= behaviors.length) {
42
+ return;
43
+ }
44
+ const behavior = behaviors[currentIndex];
45
+ if (!behavior) {
46
+ return;
47
+ }
48
+ currentIndex++;
49
+ try {
50
+ await behavior.before?.(context);
51
+ } catch (error) {
52
+ console.error(
53
+ `Error executing before behavior "${behavior.id}":`,
54
+ error
55
+ );
56
+ }
57
+ };
58
+ context.next = next;
59
+ await next();
60
+ context.stopped = currentIndex < behaviors.length;
61
+ }
62
+ /**
63
+ * Execute all after-response behaviors as a middleware chain
64
+ */
65
+ async executeAfter(context) {
66
+ const behaviors = this.getAfterBehaviors();
67
+ let currentIndex = 0;
68
+ const next = async () => {
69
+ if (currentIndex >= behaviors.length) {
70
+ return;
71
+ }
72
+ const behavior = behaviors[currentIndex];
73
+ if (!behavior) {
74
+ return;
75
+ }
76
+ currentIndex++;
77
+ try {
78
+ await behavior.after?.(context);
79
+ } catch (error) {
80
+ console.error(`Error executing after behavior "${behavior.id}":`, error);
81
+ }
82
+ };
83
+ context.next = next;
84
+ await next();
85
+ context.stopped = currentIndex < behaviors.length;
86
+ }
87
+ /**
88
+ * Clear all registered behaviors
89
+ */
90
+ clear() {
91
+ this.behaviors = [];
92
+ }
93
+ };
94
+ export {
95
+ BehaviorRegistryImpl
96
+ };
97
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/behavior.ts"],"sourcesContent":["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":";AAkIO,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/package.json CHANGED
@@ -1,45 +1,55 @@
1
1
  {
2
2
  "name": "@hybrd/types",
3
- "version": "0.7.5",
4
- "description": "Solidity + TypeScript Framework for Web3 Development",
5
- "author": "Ian Hunter <ian@ianh.xyz>",
6
- "homepage": "https://github.com/hybridhq/hybrid#readme",
7
- "license": "ISC",
3
+ "version": "1.4.0",
4
+ "keywords": [
5
+ "xmtp",
6
+ "agent",
7
+ "ai",
8
+ "hybrid",
9
+ "types",
10
+ "typescript"
11
+ ],
8
12
  "type": "module",
9
- "types": "./dist/types.d.ts",
10
- "exports": {
11
- ".": {
12
- "module": "./dist/types.cjs",
13
- "default": "./dist/types.js"
14
- },
15
- "./package.json": "./package.json"
16
- },
17
13
  "files": [
18
- "dist"
14
+ "dist",
15
+ "src"
19
16
  ],
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/hybridhq/hybrid.git"
23
- },
24
- "scripts": {
25
- "clean": "rm -rf dist",
26
- "build": "tsup",
27
- "dev": "nodemon"
28
- },
29
- "bugs": {
30
- "url": "https://github.com/hybridhq/hybrid/issues"
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs"
22
+ }
31
23
  },
32
24
  "dependencies": {
33
- "abitype": "^0.7.1"
25
+ "ai": "^5.0.28",
26
+ "zod": "^3.23.8"
34
27
  },
35
28
  "peerDependencies": {
36
- "wagmi": "^0.12.8"
29
+ "@xmtp/content-type-group-updated": "*",
30
+ "@xmtp/content-type-reaction": "*",
31
+ "@xmtp/content-type-reply": "*",
32
+ "@xmtp/content-type-transaction-reference": "*",
33
+ "@xmtp/content-type-wallet-send-calls": "*",
34
+ "@xmtp/node-sdk": "*",
35
+ "hono": "*"
37
36
  },
38
37
  "devDependencies": {
39
- "@types/node": "^18.14.6",
40
- "nodemon": "^2.0.21",
41
- "tsup": "^6.6.3",
42
- "typescript": "^4.9.5"
38
+ "@types/node": "22.8.6",
39
+ "tsup": "^8.5.0",
40
+ "vitest": "^3.2.4",
41
+ "@config/tsconfig": "0.0.0",
42
+ "@config/biome": "0.0.0"
43
43
  },
44
- "gitHead": "5065a984fffb5e752f1d61af3b988dad15d00e37"
45
- }
44
+ "scripts": {
45
+ "build": "tsup",
46
+ "build:watch": "tsup --watch",
47
+ "clean": "rm -rf .turbo dist",
48
+ "test": "vitest run",
49
+ "test:watch": "vitest",
50
+ "typecheck": "tsc --noEmit",
51
+ "lint": "biome lint --unsafe",
52
+ "lint:fix": "biome lint --write --unsafe",
53
+ "format": "biome format --write"
54
+ }
55
+ }