@huyooo/ai-chat-bridge-elysia 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,653 @@
1
+ import * as _huyooo_ai_chat_storage from '@huyooo/ai-chat-storage';
2
+ import { StorageConfig, SessionRecord, MessageRecord, StorageContext } from '@huyooo/ai-chat-storage';
3
+ export { MessageRecord, SessionRecord, StorageAdapter, StorageContext } from '@huyooo/ai-chat-storage';
4
+ import * as _huyooo_ai_chat_core from '@huyooo/ai-chat-core';
5
+ import { AgentConfig, ChatProgress, ChatOptions } from '@huyooo/ai-chat-core';
6
+ export { AVAILABLE_MODELS, AgentConfig, ChatMode, ChatOptions, ChatProgress, ModelProvider } from '@huyooo/ai-chat-core';
7
+ import { Elysia } from 'elysia';
8
+
9
+ interface ElysiaBridgeOptions extends AgentConfig {
10
+ /** API 路由前缀 */
11
+ prefix?: string;
12
+ /** 存储配置 */
13
+ storage?: StorageConfig;
14
+ }
15
+ /**
16
+ * 创建 Elysia AI Chat 插件
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { Elysia } from 'elysia';
21
+ * import { createElysiaBridge } from '@huyooo/ai-chat-bridge-elysia';
22
+ *
23
+ * new Elysia()
24
+ * .use(await createElysiaBridge({
25
+ * arkApiKey: 'xxx',
26
+ * geminiApiKey: 'xxx',
27
+ * storage: {
28
+ * type: 'postgres',
29
+ * postgresUrl: 'postgres://...',
30
+ * }
31
+ * }))
32
+ * .listen(3000);
33
+ * ```
34
+ */
35
+ declare function createElysiaBridge(options: ElysiaBridgeOptions): Promise<Elysia<string, {
36
+ decorator: {};
37
+ store: {};
38
+ derive: {};
39
+ resolve: {};
40
+ }, {
41
+ typebox: {};
42
+ error: {};
43
+ }, {
44
+ schema: {};
45
+ standaloneSchema: {};
46
+ macro: {};
47
+ macroFn: {};
48
+ parser: {};
49
+ response: {};
50
+ }, {
51
+ [x: string]: {
52
+ models: {
53
+ get: {
54
+ body: unknown;
55
+ params: {};
56
+ query: unknown;
57
+ headers: unknown;
58
+ response: {
59
+ 200: {
60
+ models: _huyooo_ai_chat_core.ModelConfig[];
61
+ };
62
+ };
63
+ };
64
+ };
65
+ };
66
+ } & {
67
+ [x: string]: {
68
+ stream: {
69
+ get: {
70
+ body: unknown;
71
+ params: {};
72
+ query: {
73
+ images?: string | undefined;
74
+ mode?: string | undefined;
75
+ model?: string | undefined;
76
+ provider?: string | undefined;
77
+ enableWebSearch?: string | undefined;
78
+ thinkingBudget?: string | undefined;
79
+ thinkingMode?: string | undefined;
80
+ message: string;
81
+ };
82
+ headers: unknown;
83
+ response: {
84
+ 200: AsyncGenerator<string, void, unknown>;
85
+ 422: {
86
+ type: "validation";
87
+ on: string;
88
+ summary?: string;
89
+ message?: string;
90
+ found?: unknown;
91
+ property?: string;
92
+ expected?: string;
93
+ };
94
+ };
95
+ };
96
+ };
97
+ };
98
+ } & {
99
+ [x: string]: {
100
+ ws: {
101
+ subscribe: {
102
+ body: {
103
+ message?: string | undefined;
104
+ images?: string[] | undefined;
105
+ options?: {
106
+ mode?: string | undefined;
107
+ model?: string | undefined;
108
+ provider?: string | undefined;
109
+ enableWebSearch?: boolean | undefined;
110
+ thinkingBudget?: number | undefined;
111
+ thinkingMode?: string | undefined;
112
+ } | undefined;
113
+ type: "chat" | "abort";
114
+ };
115
+ params: {};
116
+ query: {};
117
+ headers: {};
118
+ response: {
119
+ 422: {
120
+ type: "validation";
121
+ on: string;
122
+ summary?: string;
123
+ message?: string;
124
+ found?: unknown;
125
+ property?: string;
126
+ expected?: string;
127
+ };
128
+ };
129
+ };
130
+ };
131
+ };
132
+ } & {
133
+ [x: string]: {
134
+ send: {
135
+ post: {
136
+ body: {
137
+ sessionId?: string | undefined;
138
+ images?: string[] | undefined;
139
+ options?: {
140
+ mode?: "agent" | "plan" | "ask" | undefined;
141
+ model?: string | undefined;
142
+ provider?: "doubao" | "deepseek" | undefined;
143
+ enableWebSearch?: boolean | undefined;
144
+ enableDeepThinking?: boolean | undefined;
145
+ thinkingBudget?: number | undefined;
146
+ } | undefined;
147
+ message: string;
148
+ };
149
+ params: {};
150
+ query: unknown;
151
+ headers: unknown;
152
+ response: {
153
+ 200: {
154
+ success: boolean;
155
+ results: ChatProgress[];
156
+ };
157
+ 422: {
158
+ type: "validation";
159
+ on: string;
160
+ summary?: string;
161
+ message?: string;
162
+ found?: unknown;
163
+ property?: string;
164
+ expected?: string;
165
+ };
166
+ };
167
+ };
168
+ };
169
+ };
170
+ } & {
171
+ [x: string]: {
172
+ abort: {
173
+ post: {
174
+ body: unknown;
175
+ params: {};
176
+ query: unknown;
177
+ headers: unknown;
178
+ response: {
179
+ 200: {
180
+ success: boolean;
181
+ message: string;
182
+ };
183
+ };
184
+ };
185
+ };
186
+ };
187
+ } & {
188
+ [x: string]: {
189
+ "clear-agent": {
190
+ post: {
191
+ body: unknown;
192
+ params: {};
193
+ query: unknown;
194
+ headers: unknown;
195
+ response: {
196
+ 200: {
197
+ success: boolean;
198
+ };
199
+ };
200
+ };
201
+ };
202
+ };
203
+ } & {
204
+ [x: string]: {
205
+ "agent-history": {
206
+ get: {
207
+ body: unknown;
208
+ params: {};
209
+ query: unknown;
210
+ headers: unknown;
211
+ response: {
212
+ 200: {
213
+ history: _huyooo_ai_chat_core.ChatMessage[];
214
+ };
215
+ };
216
+ };
217
+ };
218
+ };
219
+ } & {
220
+ [x: string]: {
221
+ "working-dir": {
222
+ post: {
223
+ body: {
224
+ dir: string;
225
+ };
226
+ params: {};
227
+ query: unknown;
228
+ headers: unknown;
229
+ response: {
230
+ 200: {
231
+ success: boolean;
232
+ };
233
+ 422: {
234
+ type: "validation";
235
+ on: string;
236
+ summary?: string;
237
+ message?: string;
238
+ found?: unknown;
239
+ property?: string;
240
+ expected?: string;
241
+ };
242
+ };
243
+ };
244
+ };
245
+ };
246
+ } & {
247
+ [x: string]: {
248
+ config: {
249
+ get: {
250
+ body: unknown;
251
+ params: {};
252
+ query: unknown;
253
+ headers: unknown;
254
+ response: {
255
+ 200: {
256
+ config: Required<AgentConfig>;
257
+ };
258
+ };
259
+ };
260
+ };
261
+ };
262
+ } & {
263
+ [x: string]: {
264
+ sessions: {
265
+ get: {
266
+ body: unknown;
267
+ params: {};
268
+ query: unknown;
269
+ headers: unknown;
270
+ response: {
271
+ 200: {
272
+ sessions: SessionRecord[];
273
+ };
274
+ };
275
+ };
276
+ };
277
+ };
278
+ } & {
279
+ [x: string]: {
280
+ sessions: {
281
+ ":id": {
282
+ get: {
283
+ body: unknown;
284
+ params: {
285
+ id: string;
286
+ } & {};
287
+ query: unknown;
288
+ headers: unknown;
289
+ response: {
290
+ 200: {
291
+ error: string;
292
+ session?: undefined;
293
+ } | {
294
+ session: SessionRecord;
295
+ error?: undefined;
296
+ };
297
+ 422: {
298
+ type: "validation";
299
+ on: string;
300
+ summary?: string;
301
+ message?: string;
302
+ found?: unknown;
303
+ property?: string;
304
+ expected?: string;
305
+ };
306
+ };
307
+ };
308
+ };
309
+ };
310
+ };
311
+ } & {
312
+ [x: string]: {
313
+ sessions: {
314
+ post: {
315
+ body: {
316
+ mode?: "agent" | "plan" | "ask" | undefined;
317
+ model?: string | undefined;
318
+ title?: string | undefined;
319
+ };
320
+ params: {};
321
+ query: unknown;
322
+ headers: unknown;
323
+ response: {
324
+ 200: {
325
+ session: SessionRecord;
326
+ };
327
+ 422: {
328
+ type: "validation";
329
+ on: string;
330
+ summary?: string;
331
+ message?: string;
332
+ found?: unknown;
333
+ property?: string;
334
+ expected?: string;
335
+ };
336
+ };
337
+ };
338
+ };
339
+ };
340
+ } & {
341
+ [x: string]: {
342
+ sessions: {
343
+ ":id": {
344
+ patch: {
345
+ body: {
346
+ mode?: "agent" | "plan" | "ask" | undefined;
347
+ model?: string | undefined;
348
+ title?: string | undefined;
349
+ };
350
+ params: {
351
+ id: string;
352
+ } & {};
353
+ query: unknown;
354
+ headers: unknown;
355
+ response: {
356
+ 200: {
357
+ session: SessionRecord | null;
358
+ };
359
+ 422: {
360
+ type: "validation";
361
+ on: string;
362
+ summary?: string;
363
+ message?: string;
364
+ found?: unknown;
365
+ property?: string;
366
+ expected?: string;
367
+ };
368
+ };
369
+ };
370
+ };
371
+ };
372
+ };
373
+ } & {
374
+ [x: string]: {
375
+ sessions: {
376
+ ":id": {
377
+ delete: {
378
+ body: unknown;
379
+ params: {
380
+ id: string;
381
+ } & {};
382
+ query: unknown;
383
+ headers: unknown;
384
+ response: {
385
+ 200: {
386
+ success: boolean;
387
+ };
388
+ 422: {
389
+ type: "validation";
390
+ on: string;
391
+ summary?: string;
392
+ message?: string;
393
+ found?: unknown;
394
+ property?: string;
395
+ expected?: string;
396
+ };
397
+ };
398
+ };
399
+ };
400
+ };
401
+ };
402
+ } & {
403
+ [x: string]: {
404
+ sessions: {
405
+ ":id": {
406
+ messages: {
407
+ get: {
408
+ body: unknown;
409
+ params: {
410
+ id: string;
411
+ } & {};
412
+ query: unknown;
413
+ headers: unknown;
414
+ response: {
415
+ 200: {
416
+ messages: MessageRecord[];
417
+ };
418
+ 422: {
419
+ type: "validation";
420
+ on: string;
421
+ summary?: string;
422
+ message?: string;
423
+ found?: unknown;
424
+ property?: string;
425
+ expected?: string;
426
+ };
427
+ };
428
+ };
429
+ };
430
+ };
431
+ };
432
+ };
433
+ } & {
434
+ [x: string]: {
435
+ messages: {
436
+ post: {
437
+ body: {
438
+ thinking?: string | undefined;
439
+ toolCalls?: string | undefined;
440
+ searchResults?: string | undefined;
441
+ operationIds?: string | undefined;
442
+ sessionId: string;
443
+ role: "user" | "assistant";
444
+ content: string;
445
+ };
446
+ params: {};
447
+ query: unknown;
448
+ headers: unknown;
449
+ response: {
450
+ 200: {
451
+ message: MessageRecord;
452
+ };
453
+ 422: {
454
+ type: "validation";
455
+ on: string;
456
+ summary?: string;
457
+ message?: string;
458
+ found?: unknown;
459
+ property?: string;
460
+ expected?: string;
461
+ };
462
+ };
463
+ };
464
+ };
465
+ };
466
+ } & {
467
+ [x: string]: {
468
+ sessions: {
469
+ ":id": {
470
+ messages: {
471
+ delete: {
472
+ body: unknown;
473
+ params: {
474
+ id: string;
475
+ } & {};
476
+ query: {
477
+ afterTimestamp?: string | undefined;
478
+ };
479
+ headers: unknown;
480
+ response: {
481
+ 200: {
482
+ success: boolean;
483
+ };
484
+ 422: {
485
+ type: "validation";
486
+ on: string;
487
+ summary?: string;
488
+ message?: string;
489
+ found?: unknown;
490
+ property?: string;
491
+ expected?: string;
492
+ };
493
+ };
494
+ };
495
+ };
496
+ };
497
+ };
498
+ };
499
+ } & {
500
+ [x: string]: {
501
+ sessions: {
502
+ ":id": {
503
+ operations: {
504
+ get: {
505
+ body: unknown;
506
+ params: {
507
+ id: string;
508
+ } & {};
509
+ query: unknown;
510
+ headers: unknown;
511
+ response: {
512
+ 200: {
513
+ operations: _huyooo_ai_chat_storage.OperationRecord[];
514
+ };
515
+ 422: {
516
+ type: "validation";
517
+ on: string;
518
+ summary?: string;
519
+ message?: string;
520
+ found?: unknown;
521
+ property?: string;
522
+ expected?: string;
523
+ };
524
+ };
525
+ };
526
+ };
527
+ };
528
+ };
529
+ };
530
+ } & {
531
+ [x: string]: {
532
+ trash: {
533
+ get: {
534
+ body: unknown;
535
+ params: {};
536
+ query: unknown;
537
+ headers: unknown;
538
+ response: {
539
+ 200: {
540
+ items: _huyooo_ai_chat_storage.TrashRecord[];
541
+ };
542
+ };
543
+ };
544
+ };
545
+ };
546
+ } & {
547
+ [x: string]: {
548
+ trash: {
549
+ ":id": {
550
+ restore: {
551
+ post: {
552
+ body: unknown;
553
+ params: {
554
+ id: string;
555
+ } & {};
556
+ query: unknown;
557
+ headers: unknown;
558
+ response: {
559
+ 200: {
560
+ item: _huyooo_ai_chat_storage.TrashRecord | undefined;
561
+ };
562
+ 422: {
563
+ type: "validation";
564
+ on: string;
565
+ summary?: string;
566
+ message?: string;
567
+ found?: unknown;
568
+ property?: string;
569
+ expected?: string;
570
+ };
571
+ };
572
+ };
573
+ };
574
+ };
575
+ };
576
+ };
577
+ } & {
578
+ [x: string]: {
579
+ health: {
580
+ get: {
581
+ body: unknown;
582
+ params: {};
583
+ query: unknown;
584
+ headers: unknown;
585
+ response: {
586
+ 200: {
587
+ status: string;
588
+ };
589
+ };
590
+ };
591
+ };
592
+ };
593
+ }, {
594
+ derive: {};
595
+ resolve: {};
596
+ schema: {};
597
+ standaloneSchema: {};
598
+ response: {};
599
+ }, {
600
+ derive: {};
601
+ resolve: {};
602
+ schema: {};
603
+ standaloneSchema: {};
604
+ response: {};
605
+ }>>;
606
+ /**
607
+ * 创建 Web Adapter(前端使用)
608
+ */
609
+ declare function createWebAdapter(baseUrl: string): {
610
+ /** 获取可用模型 */
611
+ getModels(): Promise<unknown>;
612
+ /** 发送消息(流式) */
613
+ sendMessage(message: string, options?: ChatOptions, images?: string[]): AsyncGenerator<ChatProgress>;
614
+ /** 中断当前请求 */
615
+ cancel(): Promise<void>;
616
+ /** 清空 Agent 对话历史 */
617
+ clearAgentHistory(): Promise<void>;
618
+ /** 获取 Agent 对话历史 */
619
+ getAgentHistory(): Promise<unknown>;
620
+ /** 设置工作目录 */
621
+ setWorkingDir(dir: string): Promise<void>;
622
+ /** 获取会话列表 */
623
+ getSessions(ctx?: StorageContext): Promise<unknown>;
624
+ /** 获取单个会话 */
625
+ getSession(id: string, ctx?: StorageContext): Promise<unknown>;
626
+ /** 创建会话 */
627
+ createSession(data: {
628
+ title?: string;
629
+ model?: string;
630
+ mode?: string;
631
+ }, ctx?: StorageContext): Promise<unknown>;
632
+ /** 更新会话 */
633
+ updateSession(id: string, data: {
634
+ title?: string;
635
+ model?: string;
636
+ mode?: string;
637
+ }, ctx?: StorageContext): Promise<unknown>;
638
+ /** 删除会话 */
639
+ deleteSession(id: string, ctx?: StorageContext): Promise<void>;
640
+ /** 获取会话消息 */
641
+ getMessages(sessionId: string, ctx?: StorageContext): Promise<unknown>;
642
+ /** 保存消息 */
643
+ saveMessage(data: {
644
+ sessionId: string;
645
+ role: "user" | "assistant";
646
+ content: string;
647
+ thinking?: string;
648
+ toolCalls?: string;
649
+ searchResults?: string;
650
+ }, ctx?: StorageContext): Promise<unknown>;
651
+ };
652
+
653
+ export { type ElysiaBridgeOptions, createElysiaBridge, createWebAdapter };