@elizaos/core 1.5.3-beta.3 → 1.5.5-alpha.10

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 (181) hide show
  1. package/dist/actions.d.ts +23 -0
  2. package/dist/actions.d.ts.map +1 -0
  3. package/dist/browser/index.browser.js +172 -179
  4. package/dist/browser/index.browser.js.map +6 -197
  5. package/dist/browser/index.d.ts +2 -2
  6. package/dist/database.d.ts +481 -0
  7. package/dist/database.d.ts.map +1 -0
  8. package/dist/entities.d.ts +49 -0
  9. package/dist/entities.d.ts.map +1 -0
  10. package/{src/index.browser.ts → dist/index.browser.d.ts} +9 -21
  11. package/dist/index.browser.d.ts.map +1 -0
  12. package/dist/index.d.ts +27 -3
  13. package/dist/index.d.ts.map +1 -0
  14. package/{src/index.node.ts → dist/index.node.d.ts} +3 -16
  15. package/dist/index.node.d.ts.map +1 -0
  16. package/dist/logger.d.ts +47 -0
  17. package/dist/logger.d.ts.map +1 -0
  18. package/dist/node/index.d.ts +2 -2
  19. package/dist/node/index.node.js +15514 -439
  20. package/dist/node/index.node.js.map +139 -8
  21. package/dist/prompts.d.ts +8 -0
  22. package/dist/prompts.d.ts.map +1 -0
  23. package/dist/roles.d.ts +30 -0
  24. package/dist/roles.d.ts.map +1 -0
  25. package/dist/runtime.d.ts +328 -0
  26. package/dist/runtime.d.ts.map +1 -0
  27. package/dist/schemas/character.d.ts +228 -0
  28. package/dist/schemas/character.d.ts.map +1 -0
  29. package/dist/search.d.ts +317 -0
  30. package/dist/search.d.ts.map +1 -0
  31. package/dist/sentry/instrument.browser.d.ts +12 -0
  32. package/dist/sentry/instrument.browser.d.ts.map +1 -0
  33. package/dist/sentry/instrument.d.ts +12 -0
  34. package/dist/sentry/instrument.d.ts.map +1 -0
  35. package/dist/sentry/instrument.node.d.ts +11 -0
  36. package/dist/sentry/instrument.node.d.ts.map +1 -0
  37. package/dist/services.d.ts +49 -0
  38. package/dist/services.d.ts.map +1 -0
  39. package/dist/settings.d.ts +87 -0
  40. package/dist/settings.d.ts.map +1 -0
  41. package/{src/types/agent.ts → dist/types/agent.d.ts} +60 -74
  42. package/dist/types/agent.d.ts.map +1 -0
  43. package/dist/types/browser.d.ts +127 -0
  44. package/dist/types/browser.d.ts.map +1 -0
  45. package/dist/types/components.d.ts +135 -0
  46. package/dist/types/components.d.ts.map +1 -0
  47. package/dist/types/database.d.ts +278 -0
  48. package/dist/types/database.d.ts.map +1 -0
  49. package/dist/types/email.d.ts +143 -0
  50. package/dist/types/email.d.ts.map +1 -0
  51. package/dist/types/environment.d.ts +109 -0
  52. package/dist/types/environment.d.ts.map +1 -0
  53. package/dist/types/events.d.ts +207 -0
  54. package/dist/types/events.d.ts.map +1 -0
  55. package/{src/types/index.ts → dist/types/index.d.ts} +1 -0
  56. package/dist/types/index.d.ts.map +1 -0
  57. package/{src/types/knowledge.ts → dist/types/knowledge.d.ts} +18 -23
  58. package/dist/types/knowledge.d.ts.map +1 -0
  59. package/dist/types/lp.d.ts +115 -0
  60. package/dist/types/lp.d.ts.map +1 -0
  61. package/{src/types/memory.ts → dist/types/memory.d.ts} +69 -132
  62. package/dist/types/memory.d.ts.map +1 -0
  63. package/dist/types/message.d.ts +202 -0
  64. package/dist/types/message.d.ts.map +1 -0
  65. package/dist/types/messaging.d.ts +45 -0
  66. package/dist/types/messaging.d.ts.map +1 -0
  67. package/dist/types/model.d.ts +319 -0
  68. package/dist/types/model.d.ts.map +1 -0
  69. package/dist/types/pdf.d.ts +68 -0
  70. package/dist/types/pdf.d.ts.map +1 -0
  71. package/dist/types/plugin.d.ts +64 -0
  72. package/dist/types/plugin.d.ts.map +1 -0
  73. package/dist/types/post.d.ts +242 -0
  74. package/dist/types/post.d.ts.map +1 -0
  75. package/dist/types/primitives.d.ts +72 -0
  76. package/dist/types/primitives.d.ts.map +1 -0
  77. package/dist/types/runtime.d.ts +106 -0
  78. package/dist/types/runtime.d.ts.map +1 -0
  79. package/{src/types/service.ts → dist/types/service.d.ts} +69 -120
  80. package/dist/types/service.d.ts.map +1 -0
  81. package/dist/types/settings.d.ts +30 -0
  82. package/dist/types/settings.d.ts.map +1 -0
  83. package/{src/types/state.ts → dist/types/state.d.ts} +18 -19
  84. package/dist/types/state.d.ts.map +1 -0
  85. package/dist/types/task.d.ts +68 -0
  86. package/dist/types/task.d.ts.map +1 -0
  87. package/dist/types/tee.d.ts +97 -0
  88. package/dist/types/tee.d.ts.map +1 -0
  89. package/dist/types/testing.d.ts +29 -0
  90. package/dist/types/testing.d.ts.map +1 -0
  91. package/dist/types/token.d.ts +73 -0
  92. package/dist/types/token.d.ts.map +1 -0
  93. package/dist/types/transcription.d.ts +108 -0
  94. package/dist/types/transcription.d.ts.map +1 -0
  95. package/dist/types/video.d.ts +93 -0
  96. package/dist/types/video.d.ts.map +1 -0
  97. package/dist/types/wallet.d.ts +49 -0
  98. package/dist/types/wallet.d.ts.map +1 -0
  99. package/dist/types/web-search.d.ts +112 -0
  100. package/dist/types/web-search.d.ts.map +1 -0
  101. package/dist/utils/buffer.d.ts +105 -0
  102. package/dist/utils/buffer.d.ts.map +1 -0
  103. package/dist/utils/environment.d.ts +106 -0
  104. package/dist/utils/environment.d.ts.map +1 -0
  105. package/dist/utils/server-health.d.ts +23 -0
  106. package/dist/utils/server-health.d.ts.map +1 -0
  107. package/dist/utils.d.ts +177 -0
  108. package/dist/utils.d.ts.map +1 -0
  109. package/package.json +5 -5
  110. package/src/__tests__/action-chaining-simple.test.ts +0 -203
  111. package/src/__tests__/actions.test.ts +0 -218
  112. package/src/__tests__/buffer.test.ts +0 -337
  113. package/src/__tests__/character-validation.test.ts +0 -309
  114. package/src/__tests__/database.test.ts +0 -750
  115. package/src/__tests__/entities.test.ts +0 -727
  116. package/src/__tests__/env.test.ts +0 -23
  117. package/src/__tests__/environment.test.ts +0 -285
  118. package/src/__tests__/logger-browser-node.test.ts +0 -716
  119. package/src/__tests__/logger.test.ts +0 -403
  120. package/src/__tests__/messages.test.ts +0 -196
  121. package/src/__tests__/mockCharacter.ts +0 -544
  122. package/src/__tests__/parsing.test.ts +0 -58
  123. package/src/__tests__/prompts.test.ts +0 -159
  124. package/src/__tests__/roles.test.ts +0 -331
  125. package/src/__tests__/runtime-embedding.test.ts +0 -343
  126. package/src/__tests__/runtime.test.ts +0 -978
  127. package/src/__tests__/search.test.ts +0 -15
  128. package/src/__tests__/services-by-type.test.ts +0 -204
  129. package/src/__tests__/services.test.ts +0 -136
  130. package/src/__tests__/settings.test.ts +0 -810
  131. package/src/__tests__/utils.test.ts +0 -1105
  132. package/src/__tests__/uuid.test.ts +0 -94
  133. package/src/actions.ts +0 -122
  134. package/src/database.ts +0 -579
  135. package/src/entities.ts +0 -406
  136. package/src/index.ts +0 -50
  137. package/src/logger.ts +0 -527
  138. package/src/prompts.ts +0 -243
  139. package/src/roles.ts +0 -85
  140. package/src/runtime.ts +0 -2514
  141. package/src/schemas/character.ts +0 -149
  142. package/src/search.ts +0 -1543
  143. package/src/sentry/instrument.browser.ts +0 -65
  144. package/src/sentry/instrument.node.ts +0 -57
  145. package/src/sentry/instrument.ts +0 -82
  146. package/src/services.ts +0 -105
  147. package/src/settings.ts +0 -409
  148. package/src/test_resources/constants.ts +0 -12
  149. package/src/test_resources/testSetup.ts +0 -21
  150. package/src/test_resources/types.ts +0 -22
  151. package/src/types/browser.ts +0 -145
  152. package/src/types/components.ts +0 -184
  153. package/src/types/database.ts +0 -348
  154. package/src/types/email.ts +0 -162
  155. package/src/types/environment.ts +0 -129
  156. package/src/types/events.ts +0 -249
  157. package/src/types/lp.ts +0 -124
  158. package/src/types/message.ts +0 -233
  159. package/src/types/messaging.ts +0 -57
  160. package/src/types/model.ts +0 -359
  161. package/src/types/pdf.ts +0 -77
  162. package/src/types/plugin.ts +0 -78
  163. package/src/types/post.ts +0 -271
  164. package/src/types/primitives.ts +0 -97
  165. package/src/types/runtime.ts +0 -190
  166. package/src/types/settings.ts +0 -30
  167. package/src/types/task.ts +0 -72
  168. package/src/types/tee.ts +0 -107
  169. package/src/types/testing.ts +0 -30
  170. package/src/types/token.ts +0 -96
  171. package/src/types/transcription.ts +0 -133
  172. package/src/types/video.ts +0 -108
  173. package/src/types/wallet.ts +0 -56
  174. package/src/types/web-search.ts +0 -146
  175. package/src/utils/__tests__/buffer.test.ts +0 -80
  176. package/src/utils/__tests__/environment.test.ts +0 -58
  177. package/src/utils/__tests__/stringToUuid.test.ts +0 -88
  178. package/src/utils/buffer.ts +0 -312
  179. package/src/utils/environment.ts +0 -316
  180. package/src/utils/server-health.ts +0 -117
  181. package/src/utils.ts +0 -1076
@@ -1,233 +0,0 @@
1
- import { Service, ServiceType } from './service';
2
- import type { UUID } from './primitives';
3
-
4
- export interface MessageParticipant {
5
- id: UUID;
6
- name: string;
7
- username?: string;
8
- avatar?: string;
9
- status?: 'online' | 'offline' | 'away' | 'busy';
10
- }
11
-
12
- export interface MessageAttachment {
13
- id: UUID;
14
- filename: string;
15
- url: string;
16
- mimeType: string;
17
- size: number;
18
- width?: number;
19
- height?: number;
20
- duration?: number;
21
- thumbnail?: string;
22
- }
23
-
24
- export interface MessageReaction {
25
- emoji: string;
26
- count: number;
27
- users: UUID[];
28
- hasReacted: boolean;
29
- }
30
-
31
- export interface MessageReference {
32
- messageId: UUID;
33
- channelId: UUID;
34
- type: 'reply' | 'forward' | 'quote';
35
- }
36
-
37
- export interface MessageContent {
38
- text?: string;
39
- html?: string;
40
- markdown?: string;
41
- attachments?: MessageAttachment[];
42
- reactions?: MessageReaction[];
43
- reference?: MessageReference;
44
- mentions?: UUID[];
45
- embeds?: Array<{
46
- title?: string;
47
- description?: string;
48
- url?: string;
49
- image?: string;
50
- fields?: Array<{
51
- name: string;
52
- value: string;
53
- inline?: boolean;
54
- }>;
55
- }>;
56
- }
57
-
58
- export interface MessageInfo {
59
- id: UUID;
60
- channelId: UUID;
61
- senderId: UUID;
62
- content: MessageContent;
63
- timestamp: Date;
64
- edited?: Date;
65
- deleted?: Date;
66
- pinned?: boolean;
67
- thread?: {
68
- id: UUID;
69
- messageCount: number;
70
- participants: UUID[];
71
- lastMessageAt: Date;
72
- };
73
- }
74
-
75
- export interface MessageSendOptions {
76
- replyTo?: UUID;
77
- ephemeral?: boolean;
78
- silent?: boolean;
79
- scheduled?: Date;
80
- thread?: UUID;
81
- nonce?: string;
82
- }
83
-
84
- export interface MessageSearchOptions {
85
- query?: string;
86
- channelId?: UUID;
87
- senderId?: UUID;
88
- before?: Date;
89
- after?: Date;
90
- limit?: number;
91
- offset?: number;
92
- hasAttachments?: boolean;
93
- pinned?: boolean;
94
- mentions?: UUID;
95
- }
96
-
97
- export interface MessageChannel {
98
- id: UUID;
99
- name: string;
100
- type: 'text' | 'voice' | 'dm' | 'group' | 'announcement' | 'thread';
101
- description?: string;
102
- participants?: MessageParticipant[];
103
- permissions?: {
104
- canSend: boolean;
105
- canRead: boolean;
106
- canDelete: boolean;
107
- canPin: boolean;
108
- canManage: boolean;
109
- };
110
- lastMessageAt?: Date;
111
- messageCount?: number;
112
- unreadCount?: number;
113
- }
114
-
115
- /**
116
- * Interface for messaging services
117
- */
118
- export abstract class IMessageService extends Service {
119
- static override readonly serviceType = ServiceType.MESSAGE;
120
-
121
- public readonly capabilityDescription = 'Message sending, receiving, and management capabilities';
122
-
123
- /**
124
- * Send a message to a channel
125
- * @param channelId - Channel ID
126
- * @param content - Message content
127
- * @param options - Send options
128
- * @returns Promise resolving to message ID
129
- */
130
- abstract sendMessage(
131
- channelId: UUID,
132
- content: MessageContent,
133
- options?: MessageSendOptions
134
- ): Promise<UUID>;
135
-
136
- /**
137
- * Get messages from a channel
138
- * @param channelId - Channel ID
139
- * @param options - Search options
140
- * @returns Promise resolving to array of messages
141
- */
142
- abstract getMessages(channelId: UUID, options?: MessageSearchOptions): Promise<MessageInfo[]>;
143
-
144
- /**
145
- * Get a specific message by ID
146
- * @param messageId - Message ID
147
- * @returns Promise resolving to message
148
- */
149
- abstract getMessage(messageId: UUID): Promise<MessageInfo>;
150
-
151
- /**
152
- * Edit a message
153
- * @param messageId - Message ID
154
- * @param content - New message content
155
- * @returns Promise resolving when edit completes
156
- */
157
- abstract editMessage(messageId: UUID, content: MessageContent): Promise<void>;
158
-
159
- /**
160
- * Delete a message
161
- * @param messageId - Message ID
162
- * @returns Promise resolving when deletion completes
163
- */
164
- abstract deleteMessage(messageId: UUID): Promise<void>;
165
-
166
- /**
167
- * Add a reaction to a message
168
- * @param messageId - Message ID
169
- * @param emoji - Reaction emoji
170
- * @returns Promise resolving when reaction is added
171
- */
172
- abstract addReaction(messageId: UUID, emoji: string): Promise<void>;
173
-
174
- /**
175
- * Remove a reaction from a message
176
- * @param messageId - Message ID
177
- * @param emoji - Reaction emoji
178
- * @returns Promise resolving when reaction is removed
179
- */
180
- abstract removeReaction(messageId: UUID, emoji: string): Promise<void>;
181
-
182
- /**
183
- * Pin a message
184
- * @param messageId - Message ID
185
- * @returns Promise resolving when message is pinned
186
- */
187
- abstract pinMessage(messageId: UUID): Promise<void>;
188
-
189
- /**
190
- * Unpin a message
191
- * @param messageId - Message ID
192
- * @returns Promise resolving when message is unpinned
193
- */
194
- abstract unpinMessage(messageId: UUID): Promise<void>;
195
-
196
- /**
197
- * Get available channels
198
- * @returns Promise resolving to array of channels
199
- */
200
- abstract getChannels(): Promise<MessageChannel[]>;
201
-
202
- /**
203
- * Get channel information
204
- * @param channelId - Channel ID
205
- * @returns Promise resolving to channel info
206
- */
207
- abstract getChannel(channelId: UUID): Promise<MessageChannel>;
208
-
209
- /**
210
- * Create a new channel
211
- * @param name - Channel name
212
- * @param type - Channel type
213
- * @param options - Channel options
214
- * @returns Promise resolving to new channel ID
215
- */
216
- abstract createChannel(
217
- name: string,
218
- type: MessageChannel['type'],
219
- options?: {
220
- description?: string;
221
- participants?: UUID[];
222
- private?: boolean;
223
- }
224
- ): Promise<UUID>;
225
-
226
- /**
227
- * Search messages across channels
228
- * @param query - Search query
229
- * @param options - Search options
230
- * @returns Promise resolving to search results
231
- */
232
- abstract searchMessages(query: string, options?: MessageSearchOptions): Promise<MessageInfo[]>;
233
- }
@@ -1,57 +0,0 @@
1
- import type { Content, UUID } from './primitives';
2
- import type { IAgentRuntime } from './runtime';
3
-
4
- /**
5
- * Information describing the target of a message.
6
- */
7
- export interface TargetInfo {
8
- source: string; // Platform identifier (e.g., 'discord', 'telegram', 'websocket-api')
9
- roomId?: UUID; // Target room ID (platform-specific or runtime-specific)
10
- channelId?: string; // Platform-specific channel/chat ID
11
- serverId?: string; // Platform-specific server/guild ID
12
- entityId?: UUID; // Target user ID (for DMs)
13
- threadId?: string; // Platform-specific thread ID (e.g., Telegram topics)
14
- // Add other relevant platform-specific identifiers as needed
15
- }
16
-
17
- /**
18
- * Function signature for handlers responsible for sending messages to specific platforms.
19
- */
20
- export type SendHandlerFunction = (
21
- runtime: IAgentRuntime,
22
- target: TargetInfo,
23
- content: Content
24
- ) => Promise<void>;
25
-
26
- export enum SOCKET_MESSAGE_TYPE {
27
- ROOM_JOINING = 1,
28
- SEND_MESSAGE = 2,
29
- MESSAGE = 3,
30
- ACK = 4,
31
- THINKING = 5,
32
- CONTROL = 6,
33
- }
34
-
35
- /**
36
- * Interface for control messages sent from the backend to the frontend
37
- * to manage UI state and interaction capabilities
38
- */
39
- export interface ControlMessage {
40
- /** Message type identifier */
41
- type: 'control';
42
-
43
- /** Control message payload */
44
- payload: {
45
- /** Action to perform */
46
- action: 'disable_input' | 'enable_input';
47
-
48
- /** Optional target element identifier */
49
- target?: string;
50
-
51
- /** Additional optional parameters */
52
- [key: string]: unknown;
53
- };
54
-
55
- /** Room ID to ensure signal is directed to the correct chat window */
56
- roomId: UUID;
57
- }
@@ -1,359 +0,0 @@
1
- import type { IAgentRuntime } from './runtime';
2
-
3
- export type ModelTypeName = (typeof ModelType)[keyof typeof ModelType] | string;
4
-
5
- /**
6
- * Defines the recognized types of models that the agent runtime can use.
7
- * These include models for text generation (small, large, reasoning, completion),
8
- * text embedding, tokenization (encode/decode), image generation and description,
9
- * audio transcription, text-to-speech, and generic object generation.
10
- * This constant is used throughout the system, particularly in `AgentRuntime.useModel`,
11
- * `AgentRuntime.registerModel`, and in `ModelParamsMap` / `ModelResultMap` to ensure
12
- * type safety and clarity when working with different AI models.
13
- * String values are used for extensibility with custom model types.
14
- */
15
- export const ModelType = {
16
- SMALL: 'TEXT_SMALL', // kept for backwards compatibility
17
- MEDIUM: 'TEXT_LARGE', // kept for backwards compatibility
18
- LARGE: 'TEXT_LARGE', // kept for backwards compatibility
19
- TEXT_SMALL: 'TEXT_SMALL',
20
- TEXT_LARGE: 'TEXT_LARGE',
21
- TEXT_EMBEDDING: 'TEXT_EMBEDDING',
22
- TEXT_TOKENIZER_ENCODE: 'TEXT_TOKENIZER_ENCODE',
23
- TEXT_TOKENIZER_DECODE: 'TEXT_TOKENIZER_DECODE',
24
- TEXT_REASONING_SMALL: 'REASONING_SMALL',
25
- TEXT_REASONING_LARGE: 'REASONING_LARGE',
26
- TEXT_COMPLETION: 'TEXT_COMPLETION',
27
- IMAGE: 'IMAGE',
28
- IMAGE_DESCRIPTION: 'IMAGE_DESCRIPTION',
29
- TRANSCRIPTION: 'TRANSCRIPTION',
30
- TEXT_TO_SPEECH: 'TEXT_TO_SPEECH',
31
- AUDIO: 'AUDIO',
32
- VIDEO: 'VIDEO',
33
- OBJECT_SMALL: 'OBJECT_SMALL',
34
- OBJECT_LARGE: 'OBJECT_LARGE',
35
- } as const;
36
-
37
- /**
38
- * Model configuration setting keys used in character settings.
39
- * These constants define the keys for accessing model parameters
40
- * from character configuration with support for per-model-type settings.
41
- *
42
- * Setting Precedence (highest to lowest):
43
- * 1. Parameters passed directly to useModel()
44
- * 2. Model-specific settings (e.g., TEXT_SMALL_TEMPERATURE)
45
- * 3. Default settings (e.g., DEFAULT_TEMPERATURE)
46
- *
47
- * Example character settings:
48
- * ```
49
- * settings: {
50
- * DEFAULT_TEMPERATURE: 0.7, // Applies to all models
51
- * TEXT_SMALL_TEMPERATURE: 0.5, // Overrides default for TEXT_SMALL
52
- * TEXT_LARGE_MAX_TOKENS: 4096, // Specific to TEXT_LARGE
53
- * OBJECT_SMALL_TEMPERATURE: 0.3, // Specific to OBJECT_SMALL
54
- * }
55
- * ```
56
- */
57
- export const MODEL_SETTINGS = {
58
- // Default settings - apply to all model types unless overridden
59
- DEFAULT_MAX_TOKENS: 'DEFAULT_MAX_TOKENS',
60
- DEFAULT_TEMPERATURE: 'DEFAULT_TEMPERATURE',
61
- DEFAULT_FREQUENCY_PENALTY: 'DEFAULT_FREQUENCY_PENALTY',
62
- DEFAULT_PRESENCE_PENALTY: 'DEFAULT_PRESENCE_PENALTY',
63
-
64
- // TEXT_SMALL specific settings
65
- TEXT_SMALL_MAX_TOKENS: 'TEXT_SMALL_MAX_TOKENS',
66
- TEXT_SMALL_TEMPERATURE: 'TEXT_SMALL_TEMPERATURE',
67
- TEXT_SMALL_FREQUENCY_PENALTY: 'TEXT_SMALL_FREQUENCY_PENALTY',
68
- TEXT_SMALL_PRESENCE_PENALTY: 'TEXT_SMALL_PRESENCE_PENALTY',
69
-
70
- // TEXT_LARGE specific settings
71
- TEXT_LARGE_MAX_TOKENS: 'TEXT_LARGE_MAX_TOKENS',
72
- TEXT_LARGE_TEMPERATURE: 'TEXT_LARGE_TEMPERATURE',
73
- TEXT_LARGE_FREQUENCY_PENALTY: 'TEXT_LARGE_FREQUENCY_PENALTY',
74
- TEXT_LARGE_PRESENCE_PENALTY: 'TEXT_LARGE_PRESENCE_PENALTY',
75
-
76
- // OBJECT_SMALL specific settings
77
- OBJECT_SMALL_MAX_TOKENS: 'OBJECT_SMALL_MAX_TOKENS',
78
- OBJECT_SMALL_TEMPERATURE: 'OBJECT_SMALL_TEMPERATURE',
79
- OBJECT_SMALL_FREQUENCY_PENALTY: 'OBJECT_SMALL_FREQUENCY_PENALTY',
80
- OBJECT_SMALL_PRESENCE_PENALTY: 'OBJECT_SMALL_PRESENCE_PENALTY',
81
-
82
- // OBJECT_LARGE specific settings
83
- OBJECT_LARGE_MAX_TOKENS: 'OBJECT_LARGE_MAX_TOKENS',
84
- OBJECT_LARGE_TEMPERATURE: 'OBJECT_LARGE_TEMPERATURE',
85
- OBJECT_LARGE_FREQUENCY_PENALTY: 'OBJECT_LARGE_FREQUENCY_PENALTY',
86
- OBJECT_LARGE_PRESENCE_PENALTY: 'OBJECT_LARGE_PRESENCE_PENALTY',
87
-
88
- // Legacy keys for backwards compatibility (will be treated as defaults)
89
- MODEL_MAX_TOKEN: 'MODEL_MAX_TOKEN',
90
- MODEL_TEMPERATURE: 'MODEL_TEMPERATURE',
91
- MODEL_FREQ_PENALTY: 'MODEL_FREQ_PENALTY',
92
- MODEL_PRESENCE_PENALTY: 'MODEL_PRESENCE_PENALTY',
93
- } as const;
94
-
95
- /**
96
- * Helper to get the model-specific setting key for a given model type and parameter.
97
- * @param modelType The model type (e.g., TEXT_SMALL, TEXT_LARGE)
98
- * @param param The parameter name (e.g., MAX_TOKENS, TEMPERATURE)
99
- * @returns The appropriate setting key or null if not a supported model type
100
- */
101
- export function getModelSpecificSettingKey(
102
- modelType: ModelTypeName,
103
- param: 'MAX_TOKENS' | 'TEMPERATURE' | 'FREQUENCY_PENALTY' | 'PRESENCE_PENALTY'
104
- ): string | null {
105
- const supportedModelTypes = ['TEXT_SMALL', 'TEXT_LARGE', 'OBJECT_SMALL', 'OBJECT_LARGE'];
106
-
107
- if (!supportedModelTypes.includes(modelType)) {
108
- return null;
109
- }
110
-
111
- return `${modelType}_${param}`;
112
- }
113
-
114
- /**
115
- * Parameters for generating text using a language model.
116
- * This structure is typically passed to `AgentRuntime.useModel` when the `modelType` is one of
117
- * `ModelType.TEXT_SMALL`, `ModelType.TEXT_LARGE`, `ModelType.TEXT_REASONING_SMALL`,
118
- * `ModelType.TEXT_REASONING_LARGE`, or `ModelType.TEXT_COMPLETION`.
119
- * It includes essential information like the prompt, model type, and various generation controls.
120
- */
121
- export type GenerateTextParams = {
122
- /** The `AgentRuntime` instance, providing access to models and other services. */
123
- runtime: IAgentRuntime;
124
- /** The input string or prompt that the language model will use to generate text. */
125
- prompt: string;
126
- /** Specifies the type of text generation model to use (e.g., TEXT_LARGE, REASONING_SMALL). */
127
- modelType: ModelTypeName;
128
- /** Optional. The maximum number of tokens to generate in the response. */
129
- maxTokens?: number;
130
- /** Optional. Controls randomness (0.0-1.0). Lower values are more deterministic, higher are more creative. */
131
- temperature?: number;
132
- /** Optional. Penalizes new tokens based on their existing frequency in the text so far. */
133
- frequencyPenalty?: number;
134
- /** Optional. Penalizes new tokens based on whether they appear in the text so far. */
135
- presencePenalty?: number;
136
- /** Optional. A list of sequences at which the model will stop generating further tokens. */
137
- stopSequences?: string[];
138
- };
139
-
140
- /**
141
- * Parameters for detokenizing text, i.e., converting a sequence of numerical tokens back into a string.
142
- * This is the reverse operation of tokenization.
143
- * This structure is used with `AgentRuntime.useModel` when the `modelType` is `ModelType.TEXT_TOKENIZER_DECODE`.
144
- */
145
- export interface DetokenizeTextParams {
146
- /** An array of numerical tokens to be converted back into text. */
147
- tokens: number[];
148
- /** The model type used for detokenization, ensuring consistency with the original tokenization. */
149
- modelType: ModelTypeName;
150
- }
151
-
152
- /**
153
- * Base parameters common to all model types
154
- */
155
- export interface BaseModelParams {
156
- /** The agent runtime for accessing services and utilities */
157
- runtime: IAgentRuntime;
158
- }
159
-
160
- /**
161
- * Parameters for text generation models
162
- */
163
- export interface TextGenerationParams extends BaseModelParams {
164
- /** The prompt to generate text from */
165
- prompt: string;
166
- /** Model temperature (0.0 to 1.0, lower is more deterministic) */
167
- temperature?: number;
168
- /** Maximum number of tokens to generate */
169
- maxTokens?: number;
170
- /** Sequences that should stop generation when encountered */
171
- stopSequences?: string[];
172
- /** Frequency penalty to apply */
173
- frequencyPenalty?: number;
174
- /** Presence penalty to apply */
175
- presencePenalty?: number;
176
- }
177
-
178
- /**
179
- * Parameters for text embedding models
180
- */
181
- export interface TextEmbeddingParams extends BaseModelParams {
182
- /** The text to create embeddings for */
183
- text: string;
184
- }
185
-
186
- /**
187
- * Parameters for text tokenization models
188
- */
189
- export interface TokenizeTextParams extends BaseModelParams {
190
- /** The text to tokenize */
191
- prompt: string;
192
- /** The model type to use for tokenization */
193
- modelType: ModelTypeName;
194
- }
195
-
196
- /**
197
- * Parameters for image generation models
198
- */
199
- export interface ImageGenerationParams extends BaseModelParams {
200
- /** The prompt describing the image to generate */
201
- prompt: string;
202
- /** The dimensions of the image to generate */
203
- size?: string;
204
- /** Number of images to generate */
205
- count?: number;
206
- }
207
-
208
- /**
209
- * Parameters for image description models
210
- */
211
- export interface ImageDescriptionParams extends BaseModelParams {
212
- /** The URL or path of the image to describe */
213
- imageUrl: string;
214
- /** Optional prompt to guide the description */
215
- prompt?: string;
216
- }
217
-
218
- /**
219
- * Parameters for transcription models
220
- */
221
- export interface TranscriptionParams extends BaseModelParams {
222
- /** The URL or path of the audio file to transcribe */
223
- audioUrl: string;
224
- /** Optional prompt to guide transcription */
225
- prompt?: string;
226
- }
227
-
228
- /**
229
- * Parameters for text-to-speech models
230
- */
231
- export interface TextToSpeechParams extends BaseModelParams {
232
- /** The text to convert to speech */
233
- text: string;
234
- /** The voice to use */
235
- voice?: string;
236
- /** The speaking speed */
237
- speed?: number;
238
- }
239
-
240
- /**
241
- * Parameters for audio processing models
242
- */
243
- export interface AudioProcessingParams extends BaseModelParams {
244
- /** The URL or path of the audio file to process */
245
- audioUrl: string;
246
- /** The type of audio processing to perform */
247
- processingType: string;
248
- }
249
-
250
- /**
251
- * Parameters for video processing models
252
- */
253
- export interface VideoProcessingParams extends BaseModelParams {
254
- /** The URL or path of the video file to process */
255
- videoUrl: string;
256
- /** The type of video processing to perform */
257
- processingType: string;
258
- }
259
-
260
- /**
261
- * Optional JSON schema for validating generated objects
262
- */
263
- export type JSONSchema = {
264
- type: string;
265
- properties?: Record<string, any>;
266
- required?: string[];
267
- items?: JSONSchema;
268
- [key: string]: any;
269
- };
270
-
271
- /**
272
- * Parameters for object generation models
273
- * @template T - The expected return type, inferred from schema if provided
274
- */
275
- export interface ObjectGenerationParams extends BaseModelParams {
276
- /** The prompt describing the object to generate */
277
- prompt: string;
278
- /** Optional JSON schema for validation */
279
- schema?: JSONSchema;
280
- /** Type of object to generate */
281
- output?: 'object' | 'array' | 'enum';
282
- /** For enum type, the allowed values */
283
- enumValues?: string[];
284
- /** Model type to use */
285
- modelType?: ModelTypeName;
286
- /** Model temperature (0.0 to 1.0) */
287
- temperature?: number;
288
- /** Sequences that should stop generation */
289
- stopSequences?: string[];
290
- }
291
-
292
- /**
293
- * Map of model types to their parameter types
294
- */
295
- export interface ModelParamsMap {
296
- [ModelType.TEXT_SMALL]: TextGenerationParams;
297
- [ModelType.TEXT_LARGE]: TextGenerationParams;
298
- [ModelType.TEXT_EMBEDDING]: TextEmbeddingParams | string | null;
299
- [ModelType.TEXT_TOKENIZER_ENCODE]: TokenizeTextParams;
300
- [ModelType.TEXT_TOKENIZER_DECODE]: DetokenizeTextParams;
301
- [ModelType.TEXT_REASONING_SMALL]: TextGenerationParams;
302
- [ModelType.TEXT_REASONING_LARGE]: TextGenerationParams;
303
- [ModelType.IMAGE]: ImageGenerationParams;
304
- [ModelType.IMAGE_DESCRIPTION]: ImageDescriptionParams | string;
305
- [ModelType.TRANSCRIPTION]: TranscriptionParams | Buffer | string;
306
- [ModelType.TEXT_TO_SPEECH]: TextToSpeechParams | string;
307
- [ModelType.AUDIO]: AudioProcessingParams;
308
- [ModelType.VIDEO]: VideoProcessingParams;
309
- [ModelType.OBJECT_SMALL]: ObjectGenerationParams;
310
- [ModelType.OBJECT_LARGE]: ObjectGenerationParams;
311
- // Allow string index for custom model types
312
- [key: string]: BaseModelParams | any;
313
- }
314
-
315
- /**
316
- * Map of model types to their return value types
317
- */
318
- export interface ModelResultMap {
319
- [ModelType.TEXT_SMALL]: string;
320
- [ModelType.TEXT_LARGE]: string;
321
- [ModelType.TEXT_EMBEDDING]: number[];
322
- [ModelType.TEXT_TOKENIZER_ENCODE]: number[];
323
- [ModelType.TEXT_TOKENIZER_DECODE]: string;
324
- [ModelType.TEXT_REASONING_SMALL]: string;
325
- [ModelType.TEXT_REASONING_LARGE]: string;
326
- [ModelType.IMAGE]: { url: string }[];
327
- [ModelType.IMAGE_DESCRIPTION]: { title: string; description: string };
328
- [ModelType.TRANSCRIPTION]: string;
329
- [ModelType.TEXT_TO_SPEECH]: any | Buffer;
330
- [ModelType.AUDIO]: any; // Specific return type depends on processing type
331
- [ModelType.VIDEO]: any; // Specific return type depends on processing type
332
- [ModelType.OBJECT_SMALL]: any;
333
- [ModelType.OBJECT_LARGE]: any;
334
- // Allow string index for custom model types
335
- [key: string]: any;
336
- }
337
-
338
- /**
339
- * Defines the structure for a model handler registration within the `AgentRuntime`.
340
- * Each model (e.g., for text generation, embedding) is associated with a handler function,
341
- * the name of the provider (plugin or system) that registered it, and an optional priority.
342
- * The `priority` (higher is more preferred) helps in selecting which handler to use if multiple
343
- * handlers are registered for the same model type. The `registrationOrder` (not in type, but used in runtime)
344
- * serves as a tie-breaker. See `AgentRuntime.registerModel` and `AgentRuntime.getModel`.
345
- */
346
- export interface ModelHandler {
347
- /** The function that executes the model, taking runtime and parameters, and returning a Promise. */
348
- handler: (runtime: IAgentRuntime, params: Record<string, unknown>) => Promise<unknown>;
349
- /** The name of the provider (e.g., plugin name) that registered this model handler. */
350
- provider: string;
351
- /**
352
- * Optional priority for this model handler. Higher numbers indicate higher priority.
353
- * This is used by `AgentRuntime.getModel` to select the most appropriate handler
354
- * when multiple are available for a given model type. Defaults to 0 if not specified.
355
- */
356
- priority?: number; // Optional priority for selection order
357
-
358
- registrationOrder?: number;
359
- }