@tuturuuu/ai 0.0.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.
- package/README.md +76 -0
- package/package.json +106 -0
- package/src/api-key-hash.ts +28 -0
- package/src/calendar/events.ts +34 -0
- package/src/calendar/route.ts +114 -0
- package/src/chat/credit-source.ts +1 -0
- package/src/chat/google/chat-request-schema.ts +150 -0
- package/src/chat/google/default-system-instruction.ts +198 -0
- package/src/chat/google/message-file-processing.ts +212 -0
- package/src/chat/google/mira-step-preparation.ts +221 -0
- package/src/chat/google/new/route.ts +368 -0
- package/src/chat/google/route-auth.ts +81 -0
- package/src/chat/google/route-chat-resolution.ts +98 -0
- package/src/chat/google/route-credits.ts +61 -0
- package/src/chat/google/route-message-preparation.ts +331 -0
- package/src/chat/google/route-mira-runtime.ts +206 -0
- package/src/chat/google/route.ts +632 -0
- package/src/chat/google/stream-finish-persistence.ts +722 -0
- package/src/chat/google/summary/route.ts +153 -0
- package/src/chat/mira-render-ui-policy.ts +540 -0
- package/src/chat/mira-system-instruction.ts +484 -0
- package/src/chat-sdk/adapters.ts +389 -0
- package/src/chat-sdk/registry.ts +197 -0
- package/src/chat-sdk.ts +33 -0
- package/src/core.ts +3 -0
- package/src/credits/cap-output-tokens.ts +90 -0
- package/src/credits/check-credits.ts +232 -0
- package/src/credits/constants.ts +30 -0
- package/src/credits/index.ts +46 -0
- package/src/credits/model-mapping.ts +92 -0
- package/src/credits/reservations.ts +514 -0
- package/src/credits/resolve-plan-model.ts +219 -0
- package/src/credits/sync-gateway-models.ts +351 -0
- package/src/credits/types.ts +109 -0
- package/src/credits/use-ai-credits.ts +3 -0
- package/src/embeddings/metered.ts +283 -0
- package/src/executions/route.ts +137 -0
- package/src/generate/route.ts +411 -0
- package/src/hooks.ts +7 -0
- package/src/meetings/summary/route.ts +7 -0
- package/src/meetings/transcription/route.ts +134 -0
- package/src/memory/client.ts +158 -0
- package/src/memory/config.ts +38 -0
- package/src/memory/index.ts +32 -0
- package/src/memory/ingest.ts +51 -0
- package/src/memory/middleware.ts +35 -0
- package/src/memory/operations.ts +480 -0
- package/src/memory/scope.ts +102 -0
- package/src/memory/settings.ts +121 -0
- package/src/memory/types.ts +101 -0
- package/src/memory/workspace.ts +36 -0
- package/src/memory.ts +1 -0
- package/src/mind/patch.ts +146 -0
- package/src/mind/route.ts +687 -0
- package/src/mind/tools.ts +1500 -0
- package/src/mind/types.ts +20 -0
- package/src/object/core.ts +3 -0
- package/src/object/flashcards/route.ts +140 -0
- package/src/object/quizzes/explanation/route.ts +145 -0
- package/src/object/quizzes/route.ts +142 -0
- package/src/object/types.ts +187 -0
- package/src/object/year-plan/route.ts +196 -0
- package/src/react.ts +1 -0
- package/src/scheduling/algorithm.ts +791 -0
- package/src/scheduling/default.ts +36 -0
- package/src/scheduling/duration-optimizer.ts +689 -0
- package/src/scheduling/index.ts +79 -0
- package/src/scheduling/priority-calculator.ts +187 -0
- package/src/scheduling/recurrence-calculator.ts +621 -0
- package/src/scheduling/templates.ts +892 -0
- package/src/scheduling/types.ts +136 -0
- package/src/scheduling/web-adapter.ts +308 -0
- package/src/scheduling.ts +6 -0
- package/src/supported-actions.ts +1 -0
- package/src/supported-providers.ts +6 -0
- package/src/tools/context-builder.ts +372 -0
- package/src/tools/core.ts +1 -0
- package/src/tools/definitions/calendar.ts +106 -0
- package/src/tools/definitions/finance.ts +197 -0
- package/src/tools/definitions/image.ts +74 -0
- package/src/tools/definitions/memory.ts +83 -0
- package/src/tools/definitions/meta.ts +154 -0
- package/src/tools/definitions/render-ui.ts +81 -0
- package/src/tools/definitions/tasks.ts +343 -0
- package/src/tools/definitions/time-tracking.ts +381 -0
- package/src/tools/definitions/workspace-context.ts +45 -0
- package/src/tools/definitions/workspace-user-chat.ts +111 -0
- package/src/tools/executors/calendar.ts +371 -0
- package/src/tools/executors/chat.ts +15 -0
- package/src/tools/executors/finance.ts +638 -0
- package/src/tools/executors/helpers/encryption.ts +107 -0
- package/src/tools/executors/image.ts +247 -0
- package/src/tools/executors/markitdown.ts +684 -0
- package/src/tools/executors/memory.ts +277 -0
- package/src/tools/executors/parallel-checks.ts +176 -0
- package/src/tools/executors/qr.ts +170 -0
- package/src/tools/executors/scope-helpers.ts +192 -0
- package/src/tools/executors/search.ts +149 -0
- package/src/tools/executors/settings.ts +40 -0
- package/src/tools/executors/tasks.ts +1087 -0
- package/src/tools/executors/theme.ts +23 -0
- package/src/tools/executors/timer/timer-categories-executor.ts +110 -0
- package/src/tools/executors/timer/timer-category-mutations.ts +240 -0
- package/src/tools/executors/timer/timer-goal-mutations.ts +323 -0
- package/src/tools/executors/timer/timer-goals-executor.ts +272 -0
- package/src/tools/executors/timer/timer-helpers.ts +372 -0
- package/src/tools/executors/timer/timer-mutation-schemas.ts +160 -0
- package/src/tools/executors/timer/timer-mutation-types.ts +212 -0
- package/src/tools/executors/timer/timer-mutations.ts +19 -0
- package/src/tools/executors/timer/timer-queries.ts +18 -0
- package/src/tools/executors/timer/timer-session-lifecycle.ts +299 -0
- package/src/tools/executors/timer/timer-session-mutations.ts +10 -0
- package/src/tools/executors/timer/timer-session-queries.ts +153 -0
- package/src/tools/executors/timer/timer-session-updates.ts +200 -0
- package/src/tools/executors/timer/timer-sessions-executor.ts +91 -0
- package/src/tools/executors/timer/timer-stats-executor.ts +157 -0
- package/src/tools/executors/timer.ts +22 -0
- package/src/tools/executors/user.ts +60 -0
- package/src/tools/executors/workspace.ts +135 -0
- package/src/tools/json-render-catalog.ts +875 -0
- package/src/tools/mira-tool-definitions.ts +55 -0
- package/src/tools/mira-tool-dispatcher.ts +265 -0
- package/src/tools/mira-tool-metadata.ts +164 -0
- package/src/tools/mira-tool-names.ts +95 -0
- package/src/tools/mira-tool-render-ui.ts +54 -0
- package/src/tools/mira-tool-types.ts +17 -0
- package/src/tools/mira-tools.ts +167 -0
- package/src/tools/normalize-render-ui-input.ts +321 -0
- package/src/tools/workspace-context.ts +233 -0
- package/src/types.ts +38 -0
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
export type ChatSdkAdapterTier = 'official' | 'vendor-official' | 'community';
|
|
2
|
+
|
|
3
|
+
export type ChatSdkAdapterKind = 'platform' | 'state';
|
|
4
|
+
|
|
5
|
+
export type ChatSdkAdapterRuntime =
|
|
6
|
+
| 'node'
|
|
7
|
+
| 'browser'
|
|
8
|
+
| 'cloudflare-workers'
|
|
9
|
+
| 'platform-native';
|
|
10
|
+
|
|
11
|
+
export interface ChatSdkAdapterDefinition {
|
|
12
|
+
readonly description: string;
|
|
13
|
+
readonly displayName: string;
|
|
14
|
+
readonly docsUrl: string;
|
|
15
|
+
readonly factoryExport: string;
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly kind: ChatSdkAdapterKind;
|
|
18
|
+
readonly packageName: string;
|
|
19
|
+
readonly runtime: ChatSdkAdapterRuntime;
|
|
20
|
+
readonly tier: ChatSdkAdapterTier;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const CHAT_SDK_PLATFORM_ADAPTERS = [
|
|
24
|
+
{
|
|
25
|
+
description:
|
|
26
|
+
'Slack workspace bots with threads, reactions, interactive messages, and native streaming.',
|
|
27
|
+
displayName: 'Slack',
|
|
28
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
29
|
+
factoryExport: 'createSlackAdapter',
|
|
30
|
+
id: 'slack',
|
|
31
|
+
kind: 'platform',
|
|
32
|
+
packageName: '@chat-adapter/slack',
|
|
33
|
+
runtime: 'node',
|
|
34
|
+
tier: 'official',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
description:
|
|
38
|
+
'Microsoft Teams bots with adaptive cards, mentions, conversation threading, and Teams streaming support.',
|
|
39
|
+
displayName: 'Microsoft Teams',
|
|
40
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
41
|
+
factoryExport: 'createTeamsAdapter',
|
|
42
|
+
id: 'teams',
|
|
43
|
+
kind: 'platform',
|
|
44
|
+
packageName: '@chat-adapter/teams',
|
|
45
|
+
runtime: 'node',
|
|
46
|
+
tier: 'official',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
description:
|
|
50
|
+
'Google Chat spaces and direct messages with Google Chat cards and Workspace Events support.',
|
|
51
|
+
displayName: 'Google Chat',
|
|
52
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
53
|
+
factoryExport: 'createGoogleChatAdapter',
|
|
54
|
+
id: 'gchat',
|
|
55
|
+
kind: 'platform',
|
|
56
|
+
packageName: '@chat-adapter/gchat',
|
|
57
|
+
runtime: 'node',
|
|
58
|
+
tier: 'official',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
description:
|
|
62
|
+
'Discord bots with slash commands, gateway forwarding, threads, reactions, and rich embeds.',
|
|
63
|
+
displayName: 'Discord',
|
|
64
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
65
|
+
factoryExport: 'createDiscordAdapter',
|
|
66
|
+
id: 'discord',
|
|
67
|
+
kind: 'platform',
|
|
68
|
+
packageName: '@chat-adapter/discord',
|
|
69
|
+
runtime: 'node',
|
|
70
|
+
tier: 'official',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
description:
|
|
74
|
+
'GitHub issue and pull request comment threads backed by GitHub App or PAT authentication.',
|
|
75
|
+
displayName: 'GitHub',
|
|
76
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
77
|
+
factoryExport: 'createGitHubAdapter',
|
|
78
|
+
id: 'github',
|
|
79
|
+
kind: 'platform',
|
|
80
|
+
packageName: '@chat-adapter/github',
|
|
81
|
+
runtime: 'node',
|
|
82
|
+
tier: 'official',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
description:
|
|
86
|
+
'Linear issue comments and agent sessions for workspace automation and project workflows.',
|
|
87
|
+
displayName: 'Linear',
|
|
88
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
89
|
+
factoryExport: 'createLinearAdapter',
|
|
90
|
+
id: 'linear',
|
|
91
|
+
kind: 'platform',
|
|
92
|
+
packageName: '@chat-adapter/linear',
|
|
93
|
+
runtime: 'node',
|
|
94
|
+
tier: 'official',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
description:
|
|
98
|
+
'Telegram groups, channels, direct chats, inline keyboards, and post/edit streaming.',
|
|
99
|
+
displayName: 'Telegram',
|
|
100
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
101
|
+
factoryExport: 'createTelegramAdapter',
|
|
102
|
+
id: 'telegram',
|
|
103
|
+
kind: 'platform',
|
|
104
|
+
packageName: '@chat-adapter/telegram',
|
|
105
|
+
runtime: 'node',
|
|
106
|
+
tier: 'official',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
description:
|
|
110
|
+
'WhatsApp Business Cloud customer messaging with buffered streaming, templates, and media handling.',
|
|
111
|
+
displayName: 'WhatsApp Business Cloud',
|
|
112
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
113
|
+
factoryExport: 'createWhatsAppAdapter',
|
|
114
|
+
id: 'whatsapp',
|
|
115
|
+
kind: 'platform',
|
|
116
|
+
packageName: '@chat-adapter/whatsapp',
|
|
117
|
+
runtime: 'node',
|
|
118
|
+
tier: 'official',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
description:
|
|
122
|
+
'Facebook Messenger conversations with templates, buttons, reactions, and postbacks.',
|
|
123
|
+
displayName: 'Messenger',
|
|
124
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
125
|
+
factoryExport: 'createMessengerAdapter',
|
|
126
|
+
id: 'messenger',
|
|
127
|
+
kind: 'platform',
|
|
128
|
+
packageName: '@chat-adapter/messenger',
|
|
129
|
+
runtime: 'node',
|
|
130
|
+
tier: 'official',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
description:
|
|
134
|
+
'Browser chat UI adapter that speaks the AI SDK UI stream protocol for React, Vue, and Svelte clients.',
|
|
135
|
+
displayName: 'Web',
|
|
136
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
137
|
+
factoryExport: 'createWebAdapter',
|
|
138
|
+
id: 'web',
|
|
139
|
+
kind: 'platform',
|
|
140
|
+
packageName: '@chat-adapter/web',
|
|
141
|
+
runtime: 'browser',
|
|
142
|
+
tier: 'official',
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
description:
|
|
146
|
+
'Matrix adapter built and maintained by Beeper for Matrix rooms and threads.',
|
|
147
|
+
displayName: 'Beeper Matrix',
|
|
148
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
149
|
+
factoryExport: 'createMatrixAdapter',
|
|
150
|
+
id: 'matrix',
|
|
151
|
+
kind: 'platform',
|
|
152
|
+
packageName: '@beeper/chat-adapter-matrix',
|
|
153
|
+
runtime: 'node',
|
|
154
|
+
tier: 'vendor-official',
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
description:
|
|
158
|
+
'Photon iMessage adapter for local on-device and Photon-hosted iMessage integrations.',
|
|
159
|
+
displayName: 'Photon iMessage',
|
|
160
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
161
|
+
factoryExport: 'createiMessageAdapter',
|
|
162
|
+
id: 'imessage',
|
|
163
|
+
kind: 'platform',
|
|
164
|
+
packageName: 'chat-adapter-imessage',
|
|
165
|
+
runtime: 'platform-native',
|
|
166
|
+
tier: 'vendor-official',
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
description:
|
|
170
|
+
'Resend email adapter for bidirectional threaded email, rich HTML, and attachments.',
|
|
171
|
+
displayName: 'Resend Email',
|
|
172
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
173
|
+
factoryExport: 'createResendAdapter',
|
|
174
|
+
id: 'resend',
|
|
175
|
+
kind: 'platform',
|
|
176
|
+
packageName: '@resend/chat-sdk-adapter',
|
|
177
|
+
runtime: 'node',
|
|
178
|
+
tier: 'vendor-official',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
description:
|
|
182
|
+
'Unified Zernio social DM adapter for Instagram, Facebook, Telegram, WhatsApp, X, Bluesky, and Reddit.',
|
|
183
|
+
displayName: 'Zernio',
|
|
184
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
185
|
+
factoryExport: 'createZernioAdapter',
|
|
186
|
+
id: 'zernio',
|
|
187
|
+
kind: 'platform',
|
|
188
|
+
packageName: '@zernio/chat-sdk-adapter',
|
|
189
|
+
runtime: 'node',
|
|
190
|
+
tier: 'vendor-official',
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
description:
|
|
194
|
+
'Liveblocks Comments adapter for conversational bots over rooms, threads, and comments.',
|
|
195
|
+
displayName: 'Liveblocks',
|
|
196
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
197
|
+
factoryExport: 'createLiveblocksAdapter',
|
|
198
|
+
id: 'liveblocks',
|
|
199
|
+
kind: 'platform',
|
|
200
|
+
packageName: '@liveblocks/chat-sdk-adapter',
|
|
201
|
+
runtime: 'node',
|
|
202
|
+
tier: 'vendor-official',
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
description:
|
|
206
|
+
'Webex spaces and threads with adaptive-card oriented message handling.',
|
|
207
|
+
displayName: 'Webex',
|
|
208
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
209
|
+
factoryExport: 'createWebexAdapter',
|
|
210
|
+
id: 'webex',
|
|
211
|
+
kind: 'platform',
|
|
212
|
+
packageName: '@bitbasti/chat-adapter-webex',
|
|
213
|
+
runtime: 'node',
|
|
214
|
+
tier: 'community',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
description:
|
|
218
|
+
'Unofficial WhatsApp adapter powered by Baileys for WhatsApp-native messaging.',
|
|
219
|
+
displayName: 'Baileys WhatsApp',
|
|
220
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
221
|
+
factoryExport: 'createBaileysAdapter',
|
|
222
|
+
id: 'baileys',
|
|
223
|
+
kind: 'platform',
|
|
224
|
+
packageName: 'chat-adapter-baileys',
|
|
225
|
+
runtime: 'node',
|
|
226
|
+
tier: 'community',
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
description:
|
|
230
|
+
'Sendblue iMessage adapter for building iMessage bots through Sendblue.',
|
|
231
|
+
displayName: 'Sendblue iMessage',
|
|
232
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
233
|
+
factoryExport: 'createSendblueAdapter',
|
|
234
|
+
id: 'sendblue',
|
|
235
|
+
kind: 'platform',
|
|
236
|
+
packageName: 'chat-adapter-sendblue',
|
|
237
|
+
runtime: 'node',
|
|
238
|
+
tier: 'community',
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
description:
|
|
242
|
+
'Blooio adapter for iMessage, RCS, and SMS conversations from the same bot.',
|
|
243
|
+
displayName: 'Blooio iMessage/RCS/SMS',
|
|
244
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
245
|
+
factoryExport: 'createBlooioAdapter',
|
|
246
|
+
id: 'blooio',
|
|
247
|
+
kind: 'platform',
|
|
248
|
+
packageName: 'chat-adapter-blooio',
|
|
249
|
+
runtime: 'node',
|
|
250
|
+
tier: 'community',
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
description:
|
|
254
|
+
'Zalo Bot Platform adapter with webhook signature verification, buffered streaming, and typing indicators.',
|
|
255
|
+
displayName: 'Zalo',
|
|
256
|
+
docsUrl: 'https://chat-sdk.dev/adapters/community/zalo',
|
|
257
|
+
factoryExport: 'createZaloAdapter',
|
|
258
|
+
id: 'zalo',
|
|
259
|
+
kind: 'platform',
|
|
260
|
+
packageName: 'chat-adapter-zalo',
|
|
261
|
+
runtime: 'node',
|
|
262
|
+
tier: 'community',
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
description:
|
|
266
|
+
'Mattermost posts, reactions, slash commands, and threaded workspace conversations.',
|
|
267
|
+
displayName: 'Mattermost',
|
|
268
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
269
|
+
factoryExport: 'createMattermostAdapter',
|
|
270
|
+
id: 'mattermost',
|
|
271
|
+
kind: 'platform',
|
|
272
|
+
packageName: 'chat-adapter-mattermost',
|
|
273
|
+
runtime: 'node',
|
|
274
|
+
tier: 'community',
|
|
275
|
+
},
|
|
276
|
+
] as const satisfies readonly ChatSdkAdapterDefinition[];
|
|
277
|
+
|
|
278
|
+
export const CHAT_SDK_STATE_ADAPTERS = [
|
|
279
|
+
{
|
|
280
|
+
description:
|
|
281
|
+
'In-memory state for local development and tests. Do not use for multi-instance production bots.',
|
|
282
|
+
displayName: 'Memory',
|
|
283
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
284
|
+
factoryExport: 'createMemoryState',
|
|
285
|
+
id: 'memory',
|
|
286
|
+
kind: 'state',
|
|
287
|
+
packageName: '@chat-adapter/state-memory',
|
|
288
|
+
runtime: 'node',
|
|
289
|
+
tier: 'official',
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
description:
|
|
293
|
+
'Redis state adapter for subscriptions, dedupe, caching, and distributed webhook locks.',
|
|
294
|
+
displayName: 'Redis',
|
|
295
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
296
|
+
factoryExport: 'createRedisState',
|
|
297
|
+
id: 'redis',
|
|
298
|
+
kind: 'state',
|
|
299
|
+
packageName: '@chat-adapter/state-redis',
|
|
300
|
+
runtime: 'node',
|
|
301
|
+
tier: 'official',
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
description:
|
|
305
|
+
'ioredis state adapter for Redis clusters and sentinel-backed deployments.',
|
|
306
|
+
displayName: 'ioredis',
|
|
307
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
308
|
+
factoryExport: 'createIoRedisState',
|
|
309
|
+
id: 'ioredis',
|
|
310
|
+
kind: 'state',
|
|
311
|
+
packageName: '@chat-adapter/state-ioredis',
|
|
312
|
+
runtime: 'node',
|
|
313
|
+
tier: 'official',
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
description:
|
|
317
|
+
'PostgreSQL state adapter for durable subscriptions, cache entries, and distributed locks.',
|
|
318
|
+
displayName: 'PostgreSQL',
|
|
319
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
320
|
+
factoryExport: 'createPostgresState',
|
|
321
|
+
id: 'postgres',
|
|
322
|
+
kind: 'state',
|
|
323
|
+
packageName: '@chat-adapter/state-pg',
|
|
324
|
+
runtime: 'node',
|
|
325
|
+
tier: 'official',
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
description:
|
|
329
|
+
'Cloudflare Durable Objects state adapter with SQLite-backed persistence and distributed locking.',
|
|
330
|
+
displayName: 'Cloudflare Durable Objects',
|
|
331
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
332
|
+
factoryExport: 'createCloudflareState',
|
|
333
|
+
id: 'cloudflare-do',
|
|
334
|
+
kind: 'state',
|
|
335
|
+
packageName: 'chat-state-cloudflare-do',
|
|
336
|
+
runtime: 'cloudflare-workers',
|
|
337
|
+
tier: 'community',
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
description:
|
|
341
|
+
'MySQL state adapter for persistence, distributed locks, caching, lists, and queues.',
|
|
342
|
+
displayName: 'MySQL',
|
|
343
|
+
docsUrl: 'https://chat-sdk.dev/adapters',
|
|
344
|
+
factoryExport: 'createMySqlState',
|
|
345
|
+
id: 'mysql',
|
|
346
|
+
kind: 'state',
|
|
347
|
+
packageName: 'chat-state-mysql',
|
|
348
|
+
runtime: 'node',
|
|
349
|
+
tier: 'community',
|
|
350
|
+
},
|
|
351
|
+
] as const satisfies readonly ChatSdkAdapterDefinition[];
|
|
352
|
+
|
|
353
|
+
export const CHAT_SDK_ADAPTERS = [
|
|
354
|
+
...CHAT_SDK_PLATFORM_ADAPTERS,
|
|
355
|
+
...CHAT_SDK_STATE_ADAPTERS,
|
|
356
|
+
] as const;
|
|
357
|
+
|
|
358
|
+
export type ChatSdkPlatformAdapterDefinition =
|
|
359
|
+
(typeof CHAT_SDK_PLATFORM_ADAPTERS)[number];
|
|
360
|
+
export type ChatSdkPlatformAdapterId = ChatSdkPlatformAdapterDefinition['id'];
|
|
361
|
+
export type ChatSdkStateAdapterDefinition =
|
|
362
|
+
(typeof CHAT_SDK_STATE_ADAPTERS)[number];
|
|
363
|
+
export type ChatSdkStateAdapterId = ChatSdkStateAdapterDefinition['id'];
|
|
364
|
+
export type ChatSdkKnownAdapterDefinition = (typeof CHAT_SDK_ADAPTERS)[number];
|
|
365
|
+
export type ChatSdkKnownAdapterId = ChatSdkKnownAdapterDefinition['id'];
|
|
366
|
+
|
|
367
|
+
export function isChatSdkPlatformAdapterId(
|
|
368
|
+
value: string
|
|
369
|
+
): value is ChatSdkPlatformAdapterId {
|
|
370
|
+
return CHAT_SDK_PLATFORM_ADAPTERS.some((adapter) => adapter.id === value);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export function isChatSdkStateAdapterId(
|
|
374
|
+
value: string
|
|
375
|
+
): value is ChatSdkStateAdapterId {
|
|
376
|
+
return CHAT_SDK_STATE_ADAPTERS.some((adapter) => adapter.id === value);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export function getChatSdkPlatformAdapterDefinition(
|
|
380
|
+
id: ChatSdkPlatformAdapterId
|
|
381
|
+
): ChatSdkPlatformAdapterDefinition {
|
|
382
|
+
return CHAT_SDK_PLATFORM_ADAPTERS.find((adapter) => adapter.id === id)!;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export function getChatSdkStateAdapterDefinition(
|
|
386
|
+
id: ChatSdkStateAdapterId
|
|
387
|
+
): ChatSdkStateAdapterDefinition {
|
|
388
|
+
return CHAT_SDK_STATE_ADAPTERS.find((adapter) => adapter.id === id)!;
|
|
389
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { Adapter, ChatConfig, StateAdapter } from 'chat';
|
|
2
|
+
import { Chat } from 'chat';
|
|
3
|
+
import {
|
|
4
|
+
CHAT_SDK_PLATFORM_ADAPTERS,
|
|
5
|
+
CHAT_SDK_STATE_ADAPTERS,
|
|
6
|
+
type ChatSdkPlatformAdapterId,
|
|
7
|
+
type ChatSdkStateAdapterId,
|
|
8
|
+
getChatSdkPlatformAdapterDefinition,
|
|
9
|
+
getChatSdkStateAdapterDefinition,
|
|
10
|
+
} from './adapters';
|
|
11
|
+
|
|
12
|
+
export type ChatSdkPlatformAdapterFactory = (config?: unknown) => Adapter;
|
|
13
|
+
export type ChatSdkStateAdapterFactory = (config?: unknown) => StateAdapter;
|
|
14
|
+
export type ChatSdkAdapterModule = Record<string, unknown>;
|
|
15
|
+
|
|
16
|
+
export type ChatSdkPlatformAdapterInput =
|
|
17
|
+
| Adapter
|
|
18
|
+
| boolean
|
|
19
|
+
| null
|
|
20
|
+
| object
|
|
21
|
+
| undefined;
|
|
22
|
+
export type ChatSdkPlatformAdapterConfigMap = Partial<
|
|
23
|
+
Record<ChatSdkPlatformAdapterId, ChatSdkPlatformAdapterInput>
|
|
24
|
+
>;
|
|
25
|
+
|
|
26
|
+
export type ChatSdkStateAdapterInput =
|
|
27
|
+
| StateAdapter
|
|
28
|
+
| ChatSdkStateAdapterId
|
|
29
|
+
| {
|
|
30
|
+
config?: unknown;
|
|
31
|
+
id: ChatSdkStateAdapterId;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface CreateChatSdkRuntimeOptions
|
|
35
|
+
extends Omit<ChatConfig, 'adapters' | 'state'> {
|
|
36
|
+
adapters: ChatSdkPlatformAdapterConfigMap;
|
|
37
|
+
state: ChatSdkStateAdapterInput;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function loadChatSdkFactory(
|
|
41
|
+
packageName: string,
|
|
42
|
+
factoryExport: string
|
|
43
|
+
): Promise<(config?: unknown) => unknown> {
|
|
44
|
+
let adapterModule: ChatSdkAdapterModule;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
adapterModule = (await import(packageName)) as ChatSdkAdapterModule;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
50
|
+
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Failed to load Chat SDK adapter package "${packageName}". ${message}`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const factory = adapterModule[factoryExport];
|
|
57
|
+
|
|
58
|
+
if (typeof factory !== 'function') {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Chat SDK adapter package "${packageName}" does not export "${factoryExport}".`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return factory as (config?: unknown) => unknown;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isAdapter(value: unknown): value is Adapter {
|
|
68
|
+
return (
|
|
69
|
+
typeof value === 'object' &&
|
|
70
|
+
value !== null &&
|
|
71
|
+
'handleWebhook' in value &&
|
|
72
|
+
'name' in value
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function isStateAdapter(value: unknown): value is StateAdapter {
|
|
77
|
+
return (
|
|
78
|
+
typeof value === 'object' &&
|
|
79
|
+
value !== null &&
|
|
80
|
+
'get' in value &&
|
|
81
|
+
'set' in value &&
|
|
82
|
+
'delete' in value
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function loadChatSdkPlatformAdapterFactory(
|
|
87
|
+
id: ChatSdkPlatformAdapterId
|
|
88
|
+
): Promise<ChatSdkPlatformAdapterFactory> {
|
|
89
|
+
const definition = getChatSdkPlatformAdapterDefinition(id);
|
|
90
|
+
const factory = await loadChatSdkFactory(
|
|
91
|
+
definition.packageName,
|
|
92
|
+
definition.factoryExport
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return factory as ChatSdkPlatformAdapterFactory;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function loadChatSdkStateAdapterFactory(
|
|
99
|
+
id: ChatSdkStateAdapterId
|
|
100
|
+
): Promise<ChatSdkStateAdapterFactory> {
|
|
101
|
+
const definition = getChatSdkStateAdapterDefinition(id);
|
|
102
|
+
const factory = await loadChatSdkFactory(
|
|
103
|
+
definition.packageName,
|
|
104
|
+
definition.factoryExport
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return factory as ChatSdkStateAdapterFactory;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function createChatSdkPlatformAdapter(
|
|
111
|
+
id: ChatSdkPlatformAdapterId,
|
|
112
|
+
config?: unknown
|
|
113
|
+
): Promise<Adapter> {
|
|
114
|
+
const factory = await loadChatSdkPlatformAdapterFactory(id);
|
|
115
|
+
|
|
116
|
+
return factory(config);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function createChatSdkStateAdapter(
|
|
120
|
+
id: ChatSdkStateAdapterId,
|
|
121
|
+
config?: unknown
|
|
122
|
+
): Promise<StateAdapter> {
|
|
123
|
+
const factory = await loadChatSdkStateAdapterFactory(id);
|
|
124
|
+
|
|
125
|
+
return factory(config);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function createChatSdkAdapterMap(
|
|
129
|
+
adapterConfigs: ChatSdkPlatformAdapterConfigMap
|
|
130
|
+
): Promise<Partial<Record<ChatSdkPlatformAdapterId, Adapter>>> {
|
|
131
|
+
const entries = Object.entries(adapterConfigs) as [
|
|
132
|
+
ChatSdkPlatformAdapterId,
|
|
133
|
+
ChatSdkPlatformAdapterInput,
|
|
134
|
+
][];
|
|
135
|
+
|
|
136
|
+
const adapters = await Promise.all(
|
|
137
|
+
entries.flatMap(([id, input]) => {
|
|
138
|
+
if (input === false || input === null || input === undefined) {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return [
|
|
143
|
+
Promise.resolve(
|
|
144
|
+
isAdapter(input)
|
|
145
|
+
? input
|
|
146
|
+
: createChatSdkPlatformAdapter(
|
|
147
|
+
id,
|
|
148
|
+
input === true ? undefined : input
|
|
149
|
+
)
|
|
150
|
+
).then((adapter) => [id, adapter] as const),
|
|
151
|
+
];
|
|
152
|
+
})
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
return Object.fromEntries(adapters) as Partial<
|
|
156
|
+
Record<ChatSdkPlatformAdapterId, Adapter>
|
|
157
|
+
>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export async function resolveChatSdkStateAdapter(
|
|
161
|
+
input: ChatSdkStateAdapterInput
|
|
162
|
+
): Promise<StateAdapter> {
|
|
163
|
+
if (typeof input === 'string') {
|
|
164
|
+
return createChatSdkStateAdapter(input);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (isStateAdapter(input)) {
|
|
168
|
+
return input;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return createChatSdkStateAdapter(input.id, input.config);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export async function createChatSdkRuntime({
|
|
175
|
+
adapters,
|
|
176
|
+
state,
|
|
177
|
+
...chatConfig
|
|
178
|
+
}: CreateChatSdkRuntimeOptions): Promise<Chat> {
|
|
179
|
+
const [adapterMap, stateAdapter] = await Promise.all([
|
|
180
|
+
createChatSdkAdapterMap(adapters),
|
|
181
|
+
resolveChatSdkStateAdapter(state),
|
|
182
|
+
]);
|
|
183
|
+
|
|
184
|
+
return new Chat({
|
|
185
|
+
...chatConfig,
|
|
186
|
+
adapters: adapterMap,
|
|
187
|
+
state: stateAdapter,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export const chatSdkPlatformAdapterIds = CHAT_SDK_PLATFORM_ADAPTERS.map(
|
|
192
|
+
(adapter) => adapter.id
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
export const chatSdkStateAdapterIds = CHAT_SDK_STATE_ADAPTERS.map(
|
|
196
|
+
(adapter) => adapter.id
|
|
197
|
+
);
|
package/src/chat-sdk.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export * from 'chat';
|
|
2
|
+
export {
|
|
3
|
+
type ApprovalConfig,
|
|
4
|
+
addReaction,
|
|
5
|
+
type ChatBinding,
|
|
6
|
+
type ChatToolName,
|
|
7
|
+
type ChatToolPreset,
|
|
8
|
+
type ChatTools,
|
|
9
|
+
type ChatToolsOptions,
|
|
10
|
+
type ChatWriteToolName,
|
|
11
|
+
createChatTools,
|
|
12
|
+
deleteMessage,
|
|
13
|
+
editMessage,
|
|
14
|
+
fetchChannelMessages,
|
|
15
|
+
fetchMessages,
|
|
16
|
+
fetchThread,
|
|
17
|
+
getChannelInfo,
|
|
18
|
+
getThreadParticipants,
|
|
19
|
+
getUser,
|
|
20
|
+
listThreads,
|
|
21
|
+
postChannelMessage,
|
|
22
|
+
postMessage,
|
|
23
|
+
removeReaction,
|
|
24
|
+
sendDirectMessage,
|
|
25
|
+
startTyping,
|
|
26
|
+
subscribeThread,
|
|
27
|
+
type ToolOptions,
|
|
28
|
+
type ToolOverrides,
|
|
29
|
+
unsubscribeThread,
|
|
30
|
+
} from 'chat/ai';
|
|
31
|
+
|
|
32
|
+
export * from './chat-sdk/adapters';
|
|
33
|
+
export * from './chat-sdk/registry';
|
package/src/core.ts
ADDED