@towns-labs/app-framework 4.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.
Files changed (42) hide show
  1. package/README.md +147 -0
  2. package/dist/app.d.ts +680 -0
  3. package/dist/app.d.ts.map +1 -0
  4. package/dist/app.js +2324 -0
  5. package/dist/app.js.map +1 -0
  6. package/dist/app.test.d.ts +2 -0
  7. package/dist/app.test.d.ts.map +1 -0
  8. package/dist/app.test.js +2070 -0
  9. package/dist/app.test.js.map +1 -0
  10. package/dist/identity-types.d.ts +43 -0
  11. package/dist/identity-types.d.ts.map +1 -0
  12. package/dist/identity-types.js +2 -0
  13. package/dist/identity-types.js.map +1 -0
  14. package/dist/index.d.ts +9 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +9 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/modules/eventDedup.d.ts +73 -0
  19. package/dist/modules/eventDedup.d.ts.map +1 -0
  20. package/dist/modules/eventDedup.js +105 -0
  21. package/dist/modules/eventDedup.js.map +1 -0
  22. package/dist/modules/eventDedup.test.d.ts +2 -0
  23. package/dist/modules/eventDedup.test.d.ts.map +1 -0
  24. package/dist/modules/eventDedup.test.js +222 -0
  25. package/dist/modules/eventDedup.test.js.map +1 -0
  26. package/dist/modules/interaction-api.d.ts +101 -0
  27. package/dist/modules/interaction-api.d.ts.map +1 -0
  28. package/dist/modules/interaction-api.js +213 -0
  29. package/dist/modules/interaction-api.js.map +1 -0
  30. package/dist/modules/payments.d.ts +89 -0
  31. package/dist/modules/payments.d.ts.map +1 -0
  32. package/dist/modules/payments.js +139 -0
  33. package/dist/modules/payments.js.map +1 -0
  34. package/dist/modules/user.d.ts +17 -0
  35. package/dist/modules/user.d.ts.map +1 -0
  36. package/dist/modules/user.js +54 -0
  37. package/dist/modules/user.js.map +1 -0
  38. package/dist/snapshot-getter.d.ts +21 -0
  39. package/dist/snapshot-getter.d.ts.map +1 -0
  40. package/dist/snapshot-getter.js +27 -0
  41. package/dist/snapshot-getter.js.map +1 -0
  42. package/package.json +66 -0
package/dist/app.d.ts ADDED
@@ -0,0 +1,680 @@
1
+ import { type SendTipMemberParams } from '@towns-labs/web3';
2
+ import type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
3
+ import { type ClientV2, type ParsedEvent, type CreateTownsClientParams } from '@towns-labs/sdk';
4
+ import { Hono } from 'hono';
5
+ import { ChannelMessage, Tags, InteractionRequestPayload, InteractionResponsePayload, StreamEvent } from '@towns-labs/proto';
6
+ import type { ChannelMessage_Post_Mention, PlainMessage, SlashCommand, BlockchainTransaction, AppMetadata, ConversationSeed, Proposal, PositionsResponse } from '@towns-labs/proto';
7
+ import { type EventDedupConfig } from './modules/eventDedup';
8
+ import { type UserInfo } from './modules/user';
9
+ export type { UserInfo } from './modules/user';
10
+ import { type FlattenedInteractionRequest } from './modules/interaction-api';
11
+ import type { FacilitatorConfig, RouteConfig } from 'x402/types';
12
+ import { type Chain, type Transport, type Address, type Account, type WalletClient, type TransactionReceipt } from 'viem';
13
+ import type { AgentIdentityConfig, AgentIdentityMetadata } from './identity-types';
14
+ type AgentActions = ReturnType<typeof buildAgentActions>;
15
+ export type AgentCommand = PlainMessage<SlashCommand> & {
16
+ paid?: RouteConfig;
17
+ };
18
+ export type AgentCapability = {
19
+ name: string;
20
+ description: string;
21
+ input: StandardJSONSchemaV1;
22
+ examples?: Array<{
23
+ userQuery: string;
24
+ parameters: string;
25
+ }>;
26
+ };
27
+ export type ProposalResult = {
28
+ title: string;
29
+ explanation: string;
30
+ confidence: number;
31
+ parameters?: string;
32
+ expiresAt?: Date;
33
+ warnings?: string[];
34
+ expectedOutcome?: string;
35
+ };
36
+ type InferCapabilityParameters<Caps extends AgentCapability[], Name extends string> = Extract<Caps[number], {
37
+ name: Name;
38
+ }> extends {
39
+ input: infer S extends StandardJSONSchemaV1;
40
+ } ? NonNullable<S['~standard']['types']>['output'] : unknown;
41
+ export type AgentHandler = ReturnType<typeof buildAgentActions>;
42
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
43
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
44
+ export type AgentPayload<T extends keyof AgentEvents<Commands>, Commands extends AgentCommand[] = []> = Parameters<AgentEvents<Commands>[T]>[1];
45
+ type ImageAttachment = {
46
+ type: 'image';
47
+ alt?: string;
48
+ url: string;
49
+ };
50
+ type ChunkedMediaAttachment = {
51
+ type: 'chunked';
52
+ data: Blob;
53
+ width?: number;
54
+ height?: number;
55
+ filename: string;
56
+ } | {
57
+ type: 'chunked';
58
+ data: Uint8Array;
59
+ width?: number;
60
+ height?: number;
61
+ filename: string;
62
+ mimetype: string;
63
+ };
64
+ type LinkAttachment = {
65
+ type: 'link';
66
+ url: string;
67
+ title?: string;
68
+ description?: string;
69
+ image?: {
70
+ width: number;
71
+ height: number;
72
+ url: string;
73
+ };
74
+ };
75
+ type MiniAppAttachment = {
76
+ type: 'miniapp';
77
+ url: string;
78
+ };
79
+ type TickerAttachment = {
80
+ type: 'ticker';
81
+ address: string;
82
+ chainId: string;
83
+ };
84
+ type InfoCardAttachment = {
85
+ type: 'infoCard';
86
+ title: {
87
+ icon?: 'check' | 'x' | 'warning' | 'info';
88
+ text: string;
89
+ badge?: {
90
+ text: string;
91
+ variant?: 'positive' | 'negative';
92
+ };
93
+ };
94
+ fields: Array<{
95
+ label?: string;
96
+ value: {
97
+ type: 'text';
98
+ icon?: 'check' | 'x' | 'warning' | 'info';
99
+ text: string;
100
+ badge?: {
101
+ text: string;
102
+ variant?: 'positive' | 'negative';
103
+ };
104
+ } | {
105
+ type: 'user';
106
+ userId: Uint8Array;
107
+ } | {
108
+ type: 'token';
109
+ chainId: string;
110
+ address: string;
111
+ amount: string;
112
+ } | {
113
+ type: 'contract';
114
+ chainId: string;
115
+ address: string;
116
+ } | {
117
+ type: 'marketItem';
118
+ name: string;
119
+ price: string;
120
+ iconUrl?: string;
121
+ subtitle?: string;
122
+ change?: string;
123
+ changePct?: string;
124
+ direction?: 'positive' | 'negative';
125
+ outcomes?: Array<{
126
+ label: string;
127
+ value: string;
128
+ variant?: 'positive' | 'negative';
129
+ }>;
130
+ };
131
+ }>;
132
+ };
133
+ export type MessageOpts = {
134
+ threadId?: string;
135
+ replyId?: string;
136
+ ephemeral?: boolean;
137
+ };
138
+ export type PostMessageOpts = MessageOpts & {
139
+ mentions?: Array<{
140
+ userId: string;
141
+ displayName: string;
142
+ } | {
143
+ roleId: number;
144
+ } | {
145
+ atChannel: true;
146
+ }>;
147
+ attachments?: Array<ImageAttachment | ChunkedMediaAttachment | LinkAttachment | TickerAttachment | MiniAppAttachment | InfoCardAttachment>;
148
+ };
149
+ export type DecryptedInteractionResponse = {
150
+ recipient: Uint8Array;
151
+ payload: PlainMessage<InteractionResponsePayload>;
152
+ };
153
+ export type MentionPayload = Pick<ChannelMessage_Post_Mention, 'userId' | 'displayName'>;
154
+ export type MessagePayload = BasePayload & {
155
+ /** The decrypted message content */
156
+ message: string;
157
+ /** In case of a reply, that's the eventId of the message that got replied */
158
+ replyId: string | undefined;
159
+ /** In case of a thread, that's the thread id where the message belongs to */
160
+ threadId: string | undefined;
161
+ /** Users mentioned in the message */
162
+ mentions: MentionPayload[];
163
+ /** Convenience flag to check if the agent was mentioned */
164
+ isMentioned: boolean;
165
+ };
166
+ export type RedactionPayload = BasePayload & {
167
+ /** The event ID that got redacted */
168
+ refEventId: string;
169
+ };
170
+ export type MessageEditPayload = BasePayload & {
171
+ /** The event ID of the message that got edited */
172
+ refEventId: string;
173
+ /** New message */
174
+ message: string;
175
+ /** In case of a reply, that's the eventId of the message that got replied */
176
+ replyId: string | undefined;
177
+ /** In case of a thread, that's the thread id where the message belongs to */
178
+ threadId: string | undefined;
179
+ /** Users mentioned in the message */
180
+ mentions: MentionPayload[];
181
+ /** Convenience flag to check if the agent was mentioned */
182
+ isMentioned: boolean;
183
+ };
184
+ export type ReactionPayload = BasePayload & {
185
+ /** The reaction that was added */
186
+ reaction: string;
187
+ /** The event ID of the message that got reacted to */
188
+ messageId: string;
189
+ /** The user ID of the user that added the reaction */
190
+ userId: string;
191
+ };
192
+ export type EventRevokePayload = BasePayload & {
193
+ /** The event ID of the message that got revoked */
194
+ refEventId: string;
195
+ };
196
+ export type TipPayload = BasePayload & {
197
+ /** The message ID of the parent of the tip */
198
+ messageId: string;
199
+ /** The address that sent the tip */
200
+ senderAddress: Address;
201
+ /** The address that received the tip */
202
+ receiverAddress: Address;
203
+ /** The user ID that received the tip */
204
+ receiverUserId: string;
205
+ /** The amount of the tip */
206
+ amount: bigint;
207
+ /** The currency of the tip */
208
+ currency: Address;
209
+ };
210
+ export type StreamEventPayload = BasePayload & {
211
+ parsed: ParsedEvent;
212
+ };
213
+ export type SlashCommandPayload<Commands extends AgentCommand[] = []> = BasePayload & {
214
+ /** The slash command that was invoked (without the /) */
215
+ command: Commands[number]['name'];
216
+ /** Arguments passed after the command
217
+ * @example
218
+ * ```
219
+ * /help
220
+ * args: []
221
+ * ```
222
+ * ```
223
+ * /sum 1 2
224
+ * args: ['1', '2']
225
+ * ```
226
+ */
227
+ args: string[];
228
+ /** Users mentioned in the command */
229
+ mentions: MentionPayload[];
230
+ /** The eventId of the message that got replied */
231
+ replyId: string | undefined;
232
+ /** The thread id where the message belongs to */
233
+ threadId: string | undefined;
234
+ };
235
+ export type RawGmMessagePayload = BasePayload & {
236
+ typeUrl: string;
237
+ message: Uint8Array;
238
+ };
239
+ export type GmPayload<Schema extends StandardSchemaV1> = BasePayload & {
240
+ typeUrl: string;
241
+ schema: Schema;
242
+ data: InferOutput<Schema>;
243
+ };
244
+ export type InteractionResponseEventPayload = BasePayload & {
245
+ /** The interaction response that was received */
246
+ response: DecryptedInteractionResponse;
247
+ threadId: string | undefined;
248
+ };
249
+ export type ConversationSeedResponsePayload = BasePayload & {
250
+ seedId: string;
251
+ seed: ConversationSeed | undefined;
252
+ response: {
253
+ case: 'selectedProposal';
254
+ value: Proposal;
255
+ } | {
256
+ case: 'userMessage';
257
+ value: string;
258
+ };
259
+ replyId: string | undefined;
260
+ threadId: string | undefined;
261
+ };
262
+ export type SelectedProposalPayload = BasePayload & {
263
+ seedId: string;
264
+ seed: ConversationSeed | undefined;
265
+ proposal: Proposal;
266
+ replyId: string | undefined;
267
+ threadId: string | undefined;
268
+ };
269
+ export type AgentEvents<Commands extends AgentCommand[] = []> = {
270
+ message: (handler: AgentActions, event: MessagePayload) => void | Promise<void>;
271
+ redaction: (handler: AgentActions, event: RedactionPayload) => void | Promise<void>;
272
+ messageEdit: (handler: AgentActions, event: MessageEditPayload) => void | Promise<void>;
273
+ reaction: (handler: AgentActions, event: ReactionPayload) => Promise<void> | void;
274
+ eventRevoke: (handler: AgentActions, event: EventRevokePayload) => Promise<void> | void;
275
+ tip: (handler: AgentActions, event: TipPayload) => Promise<void> | void;
276
+ channelJoin: (handler: AgentActions, event: BasePayload) => Promise<void> | void;
277
+ channelLeave: (handler: AgentActions, event: BasePayload) => Promise<void> | void;
278
+ streamEvent: (handler: AgentActions, event: StreamEventPayload) => Promise<void> | void;
279
+ slashCommand: (handler: AgentActions, event: SlashCommandPayload<Commands>) => Promise<void> | void;
280
+ rawGmMessage: (handler: AgentActions, event: RawGmMessagePayload) => void | Promise<void>;
281
+ gm: <Schema extends StandardSchemaV1>(handler: AgentActions, event: GmPayload<Schema>) => void | Promise<void>;
282
+ interactionResponse: (handler: AgentActions, event: InteractionResponseEventPayload) => void | Promise<void>;
283
+ conversationSeedResponse: (handler: AgentActions, event: ConversationSeedResponsePayload) => void | Promise<void>;
284
+ selectedProposal: (handler: AgentActions, event: SelectedProposalPayload) => void | Promise<void>;
285
+ };
286
+ export type BasePayload = {
287
+ /** The user ID of the user that triggered the event */
288
+ userId: Address;
289
+ /** channelId that the event was triggered in */
290
+ channelId: string;
291
+ /** The ID of the event that triggered */
292
+ eventId: string;
293
+ /** The creation time of the event */
294
+ createdAt: Date;
295
+ /** The raw event payload */
296
+ event: StreamEvent;
297
+ /** Convenience flag to check if the event triggered on a DM channel */
298
+ isDm: boolean;
299
+ /** Convenience flag to check if the event triggered on a GDM channel */
300
+ isGdm: boolean;
301
+ /** Resolved user info from the app registry (display name, username) */
302
+ user: UserInfo;
303
+ };
304
+ export declare class App<Commands extends AgentCommand[] = [], Capabilities extends AgentCapability[] = []> {
305
+ readonly client: ClientV2<AgentActions>;
306
+ readonly appAddress: Address;
307
+ agentUserId: string;
308
+ viem: WalletClient<Transport, Chain, Account>;
309
+ private readonly jwtSecret;
310
+ private currentMessageTags;
311
+ private readonly emitter;
312
+ private readonly slashCommandHandlers;
313
+ private readonly gmTypedHandlers;
314
+ private readonly commands;
315
+ private readonly capabilities;
316
+ private readonly capabilityHandlers;
317
+ private conciergeRequestHandler?;
318
+ private positionsHandler?;
319
+ metadata: PlainMessage<AppMetadata>;
320
+ private readonly identityConfig?;
321
+ private readonly eventDedup;
322
+ private readonly paymentConfig?;
323
+ private readonly pendingPayments;
324
+ private readonly paymentCommands;
325
+ private readonly userInfoCache;
326
+ constructor(clientV2: ClientV2<AgentActions>, viem: WalletClient<Transport, Chain, Account>, jwtSecretBase64: string, appAddress: Address, commands?: Commands, capabilities?: Capabilities, identityConfig?: AgentIdentityConfig, dedupConfig?: EventDedupConfig, paymentConfig?: FacilitatorConfig, metadata?: PlainMessage<AppMetadata>);
327
+ getUser(userId: Address): Promise<UserInfo | undefined>;
328
+ getUser(userIds: Address[]): Promise<Map<Address, UserInfo | undefined>>;
329
+ start(): Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
330
+ private jwtMiddleware;
331
+ private webhookHandler;
332
+ private processProposals;
333
+ private handleEvent;
334
+ private isGroupEncryptionSession;
335
+ private handleKeySolicitation;
336
+ private handleChannelMessage;
337
+ private handlePaymentResponse;
338
+ /**
339
+ * get the public device key of the agent
340
+ * @returns the public device key of the agent
341
+ */
342
+ getUserDevice(): import("@towns-labs/encryption").UserDevice;
343
+ /**
344
+ * Send a message to a stream
345
+ * @param streamId - Id of the stream. Usually channelId or userId
346
+ * @param message - The cleartext of the message
347
+ * @param opts - The options for the message
348
+ */
349
+ sendMessage(streamId: string, message: string, opts?: PostMessageOpts): Promise<{
350
+ eventId: string;
351
+ prevMiniblockHash: Uint8Array;
352
+ envelope: import("@towns-labs/proto").Envelope;
353
+ }>;
354
+ /**
355
+ * Send a reaction to a stream
356
+ * @param streamId - Id of the stream. Usually channelId or userId
357
+ * @param refEventId - The eventId of the event to react to
358
+ * @param reaction - The reaction to send
359
+ */
360
+ sendReaction(streamId: string, refEventId: string, reaction: string): Promise<{
361
+ eventId: string;
362
+ prevMiniblockHash: Uint8Array;
363
+ envelope: import("@towns-labs/proto").Envelope;
364
+ }>;
365
+ /**
366
+ * Remove an specific event from a stream
367
+ * @param streamId - Id of the stream. Usually channelId or userId
368
+ * @param refEventId - The eventId of the event to remove
369
+ */
370
+ removeEvent(streamId: string, refEventId: string): Promise<{
371
+ eventId: string;
372
+ prevMiniblockHash: Uint8Array;
373
+ envelope: import("@towns-labs/proto").Envelope;
374
+ }>;
375
+ /**
376
+ * Add a user (or app) to a stream via user membership action.
377
+ * Requires the agent to already be a member of the stream.
378
+ * @param streamId - Id of the stream to join (channel, space, gdm)
379
+ * @param userId - User ID to add
380
+ */
381
+ joinUser(streamId: string, userId: string): Promise<{
382
+ eventId: string;
383
+ prevMiniblockHash: Uint8Array;
384
+ envelope: import("@towns-labs/proto").Envelope;
385
+ }>;
386
+ /**
387
+ * Edit an specific message from a stream
388
+ * @param streamId - Id of the stream. Usually channelId or userId
389
+ * @param messageId - The eventId of the message to edit
390
+ * @param message - The new message text
391
+ */
392
+ editMessage(streamId: string, messageId: string, message: string, opts?: PostMessageOpts): Promise<{
393
+ eventId: string;
394
+ prevMiniblockHash: Uint8Array;
395
+ envelope: import("@towns-labs/proto").Envelope;
396
+ }>;
397
+ /**
398
+ * Send a GM (generic message) to a stream with schema validation
399
+ * @param streamId - Id of the stream. Usually channelId or userId
400
+ * @param typeUrl - The type URL identifying the message format
401
+ * @param schema - StandardSchema for validation
402
+ * @param data - Data to validate and send
403
+ */
404
+ sendGM<Schema extends StandardSchemaV1>(streamId: string, typeUrl: string, schema: Schema, data: InferInput<Schema>, opts?: MessageOpts): Promise<{
405
+ eventId: string;
406
+ prevMiniblockHash: Uint8Array;
407
+ envelope: import("@towns-labs/proto").Envelope;
408
+ }>;
409
+ /**
410
+ * Send a raw GM (generic message) to a stream without schema validation
411
+ * @param streamId - Id of the stream. Usually channelId or userId
412
+ * @param typeUrl - The type URL identifying the message format
413
+ * @param message - Optional raw message data as bytes
414
+ * @param opts - The options for the message
415
+ */
416
+ sendRawGM(streamId: string, typeUrl: string, message: Uint8Array, opts?: MessageOpts): Promise<{
417
+ eventId: string;
418
+ prevMiniblockHash: Uint8Array;
419
+ envelope: import("@towns-labs/proto").Envelope;
420
+ }>;
421
+ /**
422
+ * Send a conversation seed to a stream
423
+ * @param streamId - Id of the stream. Usually channelId
424
+ * @param seed - The conversation seed payload
425
+ * @param opts - The options for the message
426
+ */
427
+ sendConversationSeed(streamId: string, seed: PlainMessage<ConversationSeed>, opts?: MessageOpts): Promise<{
428
+ eventId: string;
429
+ prevMiniblockHash: Uint8Array;
430
+ envelope: import("@towns-labs/proto").Envelope;
431
+ }>;
432
+ /**
433
+ * Send an interaction request to a stream
434
+ * @param streamId - Id of the stream. Usually channelId or userId
435
+ * @param contentOrPayload - The interaction request content (old format) or flattened payload (new format)
436
+ * @param recipientOrOpts - Recipient bytes (old format) or message options (new format)
437
+ * @param opts - The options for the interaction request (old format only)
438
+ * @returns The eventId of the interaction request
439
+ */
440
+ sendInteractionRequest(streamId: string, content: PlainMessage<InteractionRequestPayload['content']>, recipient?: Uint8Array, opts?: MessageOpts): Promise<{
441
+ eventId: string;
442
+ requestId: string;
443
+ }>;
444
+ sendInteractionRequest(streamId: string, payload: FlattenedInteractionRequest, opts?: MessageOpts): Promise<{
445
+ eventId: string;
446
+ requestId: string;
447
+ }>;
448
+ /**
449
+ * Send an AddMember interaction request to add a user to a GDM
450
+ * @param streamId - Id of the GDM stream
451
+ * @param userId - The user ID to add to the GDM
452
+ * @param opts - Optional message and other options
453
+ * @returns The eventId and requestId of the interaction request
454
+ */
455
+ sendAddMemberRequest(streamId: string, userId: Address, opts?: {
456
+ message?: string;
457
+ } & MessageOpts): Promise<{
458
+ eventId: string;
459
+ requestId: string;
460
+ }>;
461
+ pinMessage(streamId: string, eventId: string, streamEvent: StreamEvent): Promise<{
462
+ eventId: string;
463
+ prevMiniblockHash: Uint8Array;
464
+ envelope: import("@towns-labs/proto").Envelope;
465
+ }>;
466
+ unpinMessage(streamId: string, eventId: string): Promise<{
467
+ eventId: string;
468
+ prevMiniblockHash: Uint8Array;
469
+ envelope: import("@towns-labs/proto").Envelope;
470
+ }>;
471
+ /** Sends a tip to a user by looking up their smart account.
472
+ * Tip will always get funds from the app account balance.
473
+ * @param params - Tip parameters including userId, amount, messageId, channelId, currency.
474
+ * @returns The transaction hash and event ID
475
+ */
476
+ sendTip(params: Omit<SendTipMemberParams, 'spaceId' | 'tokenId' | 'currency' | 'receiver'> & {
477
+ currency?: Address;
478
+ userId: Address;
479
+ }): Promise<{
480
+ txHash: string;
481
+ eventId: string;
482
+ }>;
483
+ /**
484
+ * Triggered when someone sends a message.
485
+ * This is triggered for all messages, including direct messages and group messages.
486
+ */
487
+ onMessage(fn: AgentEvents['message']): import("nanoevents").Unsubscribe;
488
+ onRedaction(fn: AgentEvents['redaction']): import("nanoevents").Unsubscribe;
489
+ /**
490
+ * Triggered when a message gets edited
491
+ */
492
+ onMessageEdit(fn: AgentEvents['messageEdit']): import("nanoevents").Unsubscribe;
493
+ /**
494
+ * Triggered when someone reacts to a message
495
+ */
496
+ onReaction(fn: AgentEvents['reaction']): import("nanoevents").Unsubscribe;
497
+ /**
498
+ * Triggered when a message is revoked by a moderator
499
+ */
500
+ onEventRevoke(fn: AgentEvents['eventRevoke']): import("nanoevents").Unsubscribe;
501
+ /**
502
+ * Triggered when someone tips the agent
503
+ */
504
+ onTip(fn: AgentEvents['tip']): import("nanoevents").Unsubscribe;
505
+ /**
506
+ * Triggered when someone joins a channel
507
+ */
508
+ onChannelJoin(fn: AgentEvents['channelJoin']): import("nanoevents").Unsubscribe;
509
+ /**
510
+ * Triggered when someone leaves a channel
511
+ */
512
+ onChannelLeave(fn: AgentEvents['channelLeave']): import("nanoevents").Unsubscribe;
513
+ onStreamEvent(fn: AgentEvents['streamEvent']): import("nanoevents").Unsubscribe;
514
+ onSlashCommand(command: Commands[number]['name'], fn: AgentEvents<Commands>['slashCommand']): () => void;
515
+ onCapability<Name extends Capabilities[number]['name'] | (string & {})>(name: Name, fn: (handler: AgentActions, event: {
516
+ capabilityName: Name;
517
+ parameters: InferCapabilityParameters<Capabilities, Name>;
518
+ userQuery: string;
519
+ context: string | undefined;
520
+ timeoutMs: number | undefined;
521
+ }) => ProposalResult[] | Promise<ProposalResult[]>): () => void;
522
+ onPositions(handler: (handler: AgentActions, event: {
523
+ userId: string;
524
+ }) => Promise<PlainMessage<PositionsResponse>> | PlainMessage<PositionsResponse>): () => void;
525
+ onConciergeRequest(fn: (handler: AgentActions, event: {
526
+ conversationSeedId: string;
527
+ userQuery: string;
528
+ context?: string;
529
+ externalRef?: string;
530
+ proposalTimeoutMs?: bigint;
531
+ conciergeTimeoutMs?: bigint;
532
+ }) => Promise<Partial<PlainMessage<ConversationSeed>> | void>): () => void;
533
+ /**
534
+ * Triggered when someone sends a GM (generic message) with type validation using StandardSchema
535
+ * @param typeUrl - The type URL to listen for
536
+ * @param schema - The StandardSchema to validate the message data
537
+ * @param handler - The handler function to call when a message is received
538
+ */
539
+ onGmMessage<Schema extends StandardSchemaV1>(typeUrl: string, schema: Schema, handler: (handler: AgentActions, event: BasePayload & {
540
+ typeUrl: string;
541
+ data: InferOutput<Schema>;
542
+ }) => void | Promise<void>): () => void;
543
+ onRawGmMessage(handler: AgentEvents['rawGmMessage']): import("nanoevents").Unsubscribe;
544
+ /**
545
+ * Triggered when someone sends an interaction response
546
+ * @param fn - The handler function to call when an interaction response is received
547
+ */
548
+ onInteractionResponse(fn: AgentEvents['interactionResponse']): import("nanoevents").Unsubscribe;
549
+ /**
550
+ * Triggered when someone sends a conversation seed response
551
+ */
552
+ onConversationSeedResponse(fn: AgentEvents['conversationSeedResponse']): import("nanoevents").Unsubscribe;
553
+ /**
554
+ * Triggered when a user selects a proposal that targets this bot.
555
+ * Only fires for selectedProposal responses where targetAgentId matches this bot's appAddress.
556
+ */
557
+ onSelectedProposal(fn: AgentEvents['selectedProposal']): import("nanoevents").Unsubscribe;
558
+ /**
559
+ * Get the stream view for a stream
560
+ * Stream views contain contextual information about the stream (space, channel, etc)
561
+ * Stream views contain member data for all streams - you can iterate over all members in a channel via: `streamView.getMembers().joined.keys()`
562
+ * note: potentially expensive operation because streams can be large, fine to use in small streams
563
+ * @param streamId - The stream ID to get the view for
564
+ * @returns The stream view
565
+ */
566
+ getStreamView(streamId: string): Promise<import("@towns-labs/sdk").StreamStateView>;
567
+ /**
568
+ * Get the ERC-8004 compliant metadata JSON
569
+ * This should be hosted at /.well-known/agent-metadata.json
570
+ * Merges cached app metadata with local identity config
571
+ * @returns The ERC-8004 compliant metadata object or null
572
+ */
573
+ getIdentityMetadata(): Promise<AgentIdentityMetadata | null>;
574
+ /**
575
+ * Get the tokenURI that would be used for ERC-8004 registration
576
+ * Returns null if no domain is configured
577
+ * @returns The .well-known URL or null
578
+ */
579
+ getTokenURI(): string | null;
580
+ }
581
+ export declare const makeTownsApp: <Commands extends AgentCommand[] = [], Capabilities extends AgentCapability[] = []>(appPrivateData: string, opts?: {
582
+ /** In case you need to override the embedded JWT token from app private data */
583
+ jwtSecret?: string;
584
+ baseRpcUrl?: string;
585
+ commands?: Commands;
586
+ capabilities?: Capabilities;
587
+ identity?: AgentIdentityConfig;
588
+ dedup?: EventDedupConfig;
589
+ paymentConfig?: FacilitatorConfig;
590
+ } & Partial<Omit<CreateTownsClientParams, "env" | "encryptionDevice">>) => Promise<App<Commands, Capabilities>>;
591
+ declare const buildAgentActions: (client: ClientV2, viem: WalletClient<Transport, Chain, Account>, appAddress: Address) => {
592
+ sendMessage: (streamId: string, message: string, opts?: PostMessageOpts, tags?: PlainMessage<Tags>) => Promise<{
593
+ eventId: string;
594
+ prevMiniblockHash: Uint8Array;
595
+ envelope: import("@towns-labs/proto").Envelope;
596
+ }>;
597
+ editMessage: (streamId: string, messageId: string, message: string, opts?: PostMessageOpts, tags?: PlainMessage<Tags>) => Promise<{
598
+ eventId: string;
599
+ prevMiniblockHash: Uint8Array;
600
+ envelope: import("@towns-labs/proto").Envelope;
601
+ }>;
602
+ sendReaction: (streamId: string, messageId: string, reaction: string, tags?: PlainMessage<Tags>) => Promise<{
603
+ eventId: string;
604
+ prevMiniblockHash: Uint8Array;
605
+ envelope: import("@towns-labs/proto").Envelope;
606
+ }>;
607
+ sendInteractionRequest: {
608
+ (streamId: string, content: PlainMessage<InteractionRequestPayload["content"]>, recipient?: Uint8Array, opts?: MessageOpts, tags?: PlainMessage<Tags>): Promise<{
609
+ eventId: string;
610
+ requestId: string;
611
+ }>;
612
+ (streamId: string, payload: FlattenedInteractionRequest, opts?: MessageOpts, tags?: PlainMessage<Tags>): Promise<{
613
+ eventId: string;
614
+ requestId: string;
615
+ }>;
616
+ };
617
+ sendGM: <Schema extends StandardSchemaV1>(streamId: string, typeUrl: string, schema: Schema, data: InferInput<Schema>, opts?: MessageOpts, tags?: PlainMessage<Tags>) => ReturnType<({ streamId, payload, tags, ephemeral, }: {
618
+ streamId: string;
619
+ payload: ChannelMessage;
620
+ tags?: PlainMessage<Tags>;
621
+ ephemeral?: boolean;
622
+ }) => Promise<{
623
+ eventId: string;
624
+ prevMiniblockHash: Uint8Array;
625
+ envelope: import("@towns-labs/proto").Envelope;
626
+ }>>;
627
+ sendRawGM: (streamId: string, typeUrl: string, message: Uint8Array, opts?: MessageOpts, tags?: PlainMessage<Tags>) => Promise<{
628
+ eventId: string;
629
+ prevMiniblockHash: Uint8Array;
630
+ envelope: import("@towns-labs/proto").Envelope;
631
+ }>;
632
+ sendConversationSeed: (streamId: string, seed: PlainMessage<ConversationSeed>, opts?: MessageOpts, tags?: PlainMessage<Tags>) => Promise<{
633
+ eventId: string;
634
+ prevMiniblockHash: Uint8Array;
635
+ envelope: import("@towns-labs/proto").Envelope;
636
+ }>;
637
+ removeEvent: (streamId: string, messageId: string, tags?: PlainMessage<Tags>) => Promise<{
638
+ eventId: string;
639
+ prevMiniblockHash: Uint8Array;
640
+ envelope: import("@towns-labs/proto").Envelope;
641
+ }>;
642
+ sendKeySolicitation: (streamId: string, sessionIds: string[]) => Promise<{
643
+ eventId: string;
644
+ prevMiniblockHash: Uint8Array;
645
+ envelope: import("@towns-labs/proto").Envelope;
646
+ }>;
647
+ uploadDeviceKeys: () => Promise<{
648
+ eventId: string;
649
+ prevMiniblockHash: Uint8Array;
650
+ envelope: import("@towns-labs/proto").Envelope;
651
+ }>;
652
+ pinMessage: (streamId: string, eventId: string, streamEvent: StreamEvent) => Promise<{
653
+ eventId: string;
654
+ prevMiniblockHash: Uint8Array;
655
+ envelope: import("@towns-labs/proto").Envelope;
656
+ }>;
657
+ unpinMessage: (streamId: string, eventId: string) => Promise<{
658
+ eventId: string;
659
+ prevMiniblockHash: Uint8Array;
660
+ envelope: import("@towns-labs/proto").Envelope;
661
+ }>;
662
+ getChannelSettings: (_channelId: string) => Promise<never>;
663
+ sendBlockchainTransaction: (chainId: number, receipt: TransactionReceipt, content?: PlainMessage<BlockchainTransaction>["content"], tags?: PlainMessage<Tags>) => Promise<{
664
+ txHash: string;
665
+ eventId: string;
666
+ }>;
667
+ sendTip: (params: Omit<SendTipMemberParams, "spaceId" | "tokenId" | "currency" | "receiver"> & {
668
+ currency?: Address;
669
+ userId: Address;
670
+ }, tags?: PlainMessage<Tags>) => Promise<{
671
+ txHash: string;
672
+ eventId: string;
673
+ }>;
674
+ joinUser: (streamId: string, userId: string) => Promise<{
675
+ eventId: string;
676
+ prevMiniblockHash: Uint8Array;
677
+ envelope: import("@towns-labs/proto").Envelope;
678
+ }>;
679
+ };
680
+ //# sourceMappingURL=app.d.ts.map