@lemoncloud/eureka-agents-api 0.26.108

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,602 @@
1
+ /**
2
+ * `chatbots/model.ts`
3
+ * - model definitions per account data
4
+ *
5
+ * @author Steve <steve@lemoncloud.io>
6
+ * @date 2022-08-29 initial version.
7
+ * @author Aiden <aiden@lemoncloud.io>
8
+ * @date 2025-03-18 refactoring for chatbot service.
9
+ * @Copyright (C) 2025 LemonCloud Co Ltd. - All Rights Reserved.
10
+ */
11
+ import { CoreModel } from 'lemon-model';
12
+ import $LUT, { AgentConfigSet, AgentProfileMeta, AgentStereo, BrainStereo, ChatRoleType, ChatStereo, ChatUserProfile, DocumentExternalType, DocumentResourceType, DocumentStereo, DocumentStrategyType, EmbeddingStereo, ImageStereo, PromptStereo, UsageStereo, ChatStrategyType, ChatEmbeddingType, DocumentMeta, TokenUsageType, ChatModelProviderType, ChatModelType, MetaInfo, TokenUsageDetail, GenAIContent } from './types';
13
+ /**
14
+ * type: boolean style number.
15
+ */
16
+ declare type BoolFlag = 0 | 1;
17
+ /**
18
+ * type: `ModelType`
19
+ */
20
+ export declare type ModelType = keyof typeof $LUT.ModelType;
21
+ /**
22
+ * type: `Model`: common model
23
+ */
24
+ export declare type Model = CoreModel<ModelType>;
25
+ /**
26
+ * type: `AgentHead`
27
+ */
28
+ export interface AgentHead {
29
+ /** id of agent */
30
+ id?: string;
31
+ /** name of agent */
32
+ name?: string;
33
+ /** stereo */
34
+ stereo?: AgentStereo;
35
+ }
36
+ /**
37
+ * type: `AgentModel`
38
+ * - model for agent (에이전트)
39
+ * - set of configuration for agent
40
+ * - (추가) 페르소나에 대한 컨텍스 정보를 담는다.
41
+ */
42
+ export interface AgentModel extends Model, AgentHead {
43
+ /** id of agent */
44
+ id?: string;
45
+ /** stereo */
46
+ stereo?: AgentStereo;
47
+ /** (linked) id of prompt (system) */
48
+ systemId?: string;
49
+ /** (linked) partial of prompt (system) */
50
+ system$?: PromptHead;
51
+ /** (linked) id of prompt (system) */
52
+ promptId?: string;
53
+ /** (linked) partial of prompt (system) */
54
+ prompt$?: PromptHead;
55
+ /** (linked) id of brain (language model) */
56
+ brainId?: string;
57
+ /** (linked) partial of brain */
58
+ brain$?: BrainHead;
59
+ /** (optional) id of agent to rewrite */
60
+ rewriteId?: string;
61
+ /** (optional) partial of agent to rewrite */
62
+ rewrite$?: AgentHead;
63
+ /** (optional) id of parent */
64
+ parentId?: string;
65
+ /** (optional) partial of parent */
66
+ parent$?: AgentHead;
67
+ /** (optional) vector embedding of document */
68
+ embedding?: ChatEmbeddingType;
69
+ /** (optional) strategy to build document */
70
+ strategy?: ChatStrategyType;
71
+ /** profile meta data */
72
+ meta$?: AgentProfileMeta;
73
+ /** configuration set */
74
+ conf$?: AgentConfigSet;
75
+ /** (integer) temperature in 0~100 */
76
+ temperature?: number;
77
+ /** max-tokens in 0~4096 */
78
+ maxTokens?: number;
79
+ /** (flag) enables or disables RAG (Retrieval-Augmented Generation) */
80
+ useRag?: BoolFlag;
81
+ /** (flag) whether this is public or not. */
82
+ public?: BoolFlag;
83
+ /** system prompt content */
84
+ readonly $system?: GenAIContent<any>;
85
+ /** user prompt content */
86
+ readonly $prompt?: GenAIContent<any>;
87
+ }
88
+ /**
89
+ * type: `ChatHead`
90
+ */
91
+ export interface ChatHead {
92
+ /** id of chat */
93
+ id?: string;
94
+ /** name of chat */
95
+ name?: string;
96
+ /** stereo */
97
+ stereo?: ChatStereo;
98
+ }
99
+ /**
100
+ * type: `ChatModel`
101
+ * - model for chat (채팅)
102
+ *
103
+ * **flow**
104
+ * 1. 채팅은 다음과 같은 구조를 가짐 (thread 단위)
105
+ * - `id`: root(parent): auto-seq (ex: `1001`)
106
+ * - `id`: child: combination of parent-id and idx (ex: `1001:1`)
107
+ * 2. 1개의 질문에 대해서 여러개의 채팅을 가짐
108
+ * - `group` 으로 묶어서 관리
109
+ */
110
+ export interface ChatModel extends Model, ChatHead {
111
+ /**
112
+ * id of model
113
+ * - root(parent): auto-seq (ex: `1001`)
114
+ * - child: combination of parent-id and idx (ex: `1001:1`)
115
+ */
116
+ id?: string;
117
+ /** (internal) number in child */
118
+ no?: number;
119
+ /** (internal) depth in child */
120
+ depth?: number;
121
+ /** name */
122
+ name?: string;
123
+ /** stereo */
124
+ stereo?: ChatStereo;
125
+ /** role */
126
+ role?: ChatRoleType;
127
+ /** (flag) is hidden */
128
+ hidden?: number;
129
+ /** took time interval (msec) */
130
+ took?: number;
131
+ /** id of parent */
132
+ parentId?: string;
133
+ /** partial of parent */
134
+ parent$?: ChatHead;
135
+ /** (linked) id of agent */
136
+ agentId?: string;
137
+ /** (linked) partial of agent */
138
+ agent$?: AgentHead;
139
+ /** (linked) id of user-prompt (system) */
140
+ systemId?: string;
141
+ /** (linked) partial of user-prompt (system) */
142
+ system$?: PromptHead;
143
+ /** (linked) id of prompt (user) */
144
+ promptId?: string;
145
+ /** (linked) partial of prompt (user) */
146
+ prompt$?: PromptHead;
147
+ /** (linked) id of brain (language model) */
148
+ brainId?: string;
149
+ /** (linked) partial of brain */
150
+ brain$?: BrainHead;
151
+ /** (optional) id of agent to rewrite */
152
+ rewriteId?: string;
153
+ /** (optional) partial of agent to rewrite */
154
+ rewrite$?: AgentHead;
155
+ /** (linked) id of embedding of this (:= id) */
156
+ embeddingId?: string;
157
+ /** (linked) partial of embedding of this (:= id) */
158
+ embedding$?: EmbeddingHead;
159
+ /** (immutable) embedding type for chat */
160
+ embedding?: ChatEmbeddingType;
161
+ /** (immutable) strategy type for chat */
162
+ strategy?: ChatStrategyType;
163
+ /** (linked) id of usage (can be null) */
164
+ usageIds?: string[];
165
+ /** (linked) partial of usage */
166
+ usage$$?: UsageHead[];
167
+ /** content of the prompt (must be in `md` format) */
168
+ content?: string;
169
+ /** (copied) the token usage in detail */
170
+ usage$?: TokenUsageDetail;
171
+ /**
172
+ * (optional) number of child nodes
173
+ * - if > 0, then this has child nodes.
174
+ */
175
+ childNo?: number;
176
+ /**
177
+ * (internal) api version when created.
178
+ * ex) `0.25.618`
179
+ */
180
+ _version?: string;
181
+ /** context of chat-user */
182
+ profile$?: ChatUserProfile;
183
+ /** (optional) 이용된 문서 ID 항목 */
184
+ documentIds?: string[];
185
+ /** (optional) 찾아진 원본 문서의 일부 내용 */
186
+ document$$?: DocumentHead[];
187
+ /** 게시물 링크 정보 @deprecated refactoring under progress */
188
+ link?: {
189
+ text?: string;
190
+ link?: string;
191
+ }[];
192
+ /** 이미지 링크 정보 @deprecated refactoring under progress. */
193
+ image?: {
194
+ src?: string;
195
+ href?: string;
196
+ }[];
197
+ /** 전화번호 @deprecated refactoring under progress. */
198
+ phone?: string[];
199
+ /** 답변의 메타 정보 */
200
+ meta$$?: MetaInfo[];
201
+ /** */
202
+ readonly $childs?: ChatModel[];
203
+ }
204
+ /**
205
+ * type: `PromptHead`
206
+ * - common head of prompt-model
207
+ */
208
+ export interface PromptHead {
209
+ /** id of chat */
210
+ id?: string;
211
+ /** name of chat */
212
+ name?: string;
213
+ /** stereo */
214
+ stereo?: PromptStereo;
215
+ }
216
+ /**
217
+ * type: `PromptModel`
218
+ * - model for prompt (including user and system prompt)
219
+ * - prompt is a part of chat.
220
+ */
221
+ export interface PromptModel extends Model, PromptHead {
222
+ /** id of model (auto-seq) */
223
+ id?: string;
224
+ /** name */
225
+ name?: string;
226
+ /** stereo */
227
+ stereo?: PromptStereo;
228
+ /** text of prompt */
229
+ content?: string;
230
+ /** (optional) id of parent */
231
+ parentId?: string;
232
+ /** (optional) partial of parent */
233
+ parent$?: PromptHead;
234
+ /** (flag) is hidden */
235
+ hidden?: BoolFlag;
236
+ /**
237
+ * (optional) number of revisions
238
+ * - [parent] no-of-revision
239
+ * - [child] no-in-revision
240
+ */
241
+ revisionNo?: number;
242
+ /**
243
+ * (optional) number of child nodes
244
+ * - [parent] no-of-child
245
+ * - [child] no-in-child
246
+ */
247
+ childNo?: number;
248
+ }
249
+ /**
250
+ * type: `BrainHead`
251
+ * - common head of brain-model
252
+ */
253
+ export interface BrainHead {
254
+ /** id of chat */
255
+ id?: string;
256
+ /** name of chat */
257
+ name?: string;
258
+ /** stereo */
259
+ stereo?: BrainStereo;
260
+ /** type of chat */
261
+ model?: ChatModelType;
262
+ }
263
+ /**
264
+ * type: `BrainModel`
265
+ * - model for brain (LLM: large language model)
266
+ */
267
+ export interface BrainModel extends Model, BrainHead {
268
+ /** id of model (auto-seq) */
269
+ id?: string;
270
+ /** name */
271
+ name?: string;
272
+ /** stereo */
273
+ stereo?: BrainStereo;
274
+ /** provider of llm model */
275
+ provider?: ChatModelProviderType;
276
+ /** version info */
277
+ version?: string;
278
+ /** description */
279
+ description?: string;
280
+ }
281
+ /**
282
+ * type: `DocumentHead`
283
+ * - common head of `DocumentModel`
284
+ */
285
+ export interface DocumentHead {
286
+ /** id of model */
287
+ id?: string;
288
+ /** stereo */
289
+ stereo?: DocumentStereo;
290
+ /** name of document */
291
+ name?: string;
292
+ /** score of rate */
293
+ score?: number;
294
+ }
295
+ /**
296
+ * type: `DocumentModel`
297
+ * - model for document (문서) in markdown format
298
+ *
299
+ * **[시나리오]**
300
+ * 1. `sync-pull` 으로 원본 문서를 가져온다.
301
+ * 2. 간단한 변환을 거쳐서 `content` + `meta$` 를 생성한다.
302
+ */
303
+ export interface DocumentModel extends Omit<Model, 'meta'>, DocumentHead {
304
+ /** stereo */
305
+ stereo?: DocumentStereo;
306
+ /** name of document */
307
+ name?: string;
308
+ /** (internal) alias-id */
309
+ aliasId?: string;
310
+ /** title */
311
+ title?: string;
312
+ /** (optional) summary in short */
313
+ summary?: string;
314
+ /** (internal) error if has */
315
+ error?: string;
316
+ /**
317
+ * transform from `contents` by joining with '\n'.
318
+ * - this is not a part of `DocumentInput` but for convenience.
319
+ */
320
+ content?: string;
321
+ /** meta data */
322
+ meta$?: DocumentMeta;
323
+ /** tags: array of each tag */
324
+ tags?: string[];
325
+ /** image linked id */
326
+ imageIds?: string[];
327
+ /** (optional) image partial info */
328
+ image$$?: ImageHead[];
329
+ /** id of site */
330
+ siteId?: string;
331
+ /** name of site */
332
+ siteName?: string;
333
+ /** (external) model type of source document */
334
+ externalType?: DocumentExternalType;
335
+ /**
336
+ * (external) id of external document
337
+ * - this is used to link with external document.
338
+ * - id := `type:id`
339
+ * - ex: `pdf:1234567890` or `md:abcdefg`
340
+ */
341
+ externalId?: string;
342
+ /**
343
+ * (external) stereo of source document
344
+ * - can be like `notice`, `faq`, `blog`, etc.
345
+ */
346
+ externalStereo?: string;
347
+ /** (external) original document created at */
348
+ docCreatedAt?: number;
349
+ /** (external) original document updated at */
350
+ docUpdatedAt?: number;
351
+ /** type of strategy */
352
+ strategy?: DocumentStrategyType;
353
+ /** type of embedding */
354
+ embedding?: ChatEmbeddingType;
355
+ /** (optional) embedding vector if stereo=embedding */
356
+ vector?: number[];
357
+ /** (optional) embedding dimensions */
358
+ dimension?: number;
359
+ /** (optional) id of parent */
360
+ parentId?: string;
361
+ /** (optional) partial of parent */
362
+ parent$?: DocumentHead;
363
+ /**
364
+ * (optional) number of child nodes
365
+ * - [parent] no-of-child
366
+ * - [child] no-in-child
367
+ */
368
+ childNo?: number;
369
+ /** document version number (see `DocumentSyncPullParam.version`) */
370
+ version?: number;
371
+ /** document revision number (inc by pulling again) */
372
+ revision?: number;
373
+ /**
374
+ * @deprecated use `.meta$` object instead.
375
+ */
376
+ meta?: DocumentMeta | string;
377
+ /**
378
+ * (external) model type of source document
379
+ *
380
+ * @deprecated use `originalType` instead.
381
+ */
382
+ resourceType?: DocumentResourceType;
383
+ /**
384
+ * (external) id of resource
385
+ *
386
+ * @deprecated use `originalId` instead.
387
+ */
388
+ resourceId?: string;
389
+ /** (internal) the linked alias */
390
+ readonly $alias?: DocumentModel;
391
+ /** (internal) the linked images */
392
+ readonly $images?: ImageModel[];
393
+ /** (internal) the linked childs */
394
+ readonly $childs?: DocumentModel[];
395
+ /** (internal) the linked embeddings */
396
+ readonly $embeddings?: EmbeddingModel[];
397
+ /** (internal) the used tokens */
398
+ readonly $usage?: TokenUsageDetail;
399
+ }
400
+ /**
401
+ * type: `EmbeddingHead`
402
+ * - common head of `EmbeddingModel`
403
+ */
404
+ export interface EmbeddingHead {
405
+ /** id of model */
406
+ id?: string;
407
+ /** name of model */
408
+ name?: string;
409
+ /** stereo */
410
+ stereo?: EmbeddingStereo;
411
+ }
412
+ export interface EmbeddingVectorSet {
413
+ /** (v2) embedding vector by ad2 (float; dim=1536) */
414
+ ad2?: number[];
415
+ /** (v2) embedding vector by sm3 (float; dim=256) */
416
+ sm3?: number[];
417
+ /** (v2) embedding vector by lg3 (float; dim=1024) */
418
+ lg3?: number[];
419
+ /** (v2) embedding vector by gm1 (float; dim=3072) */
420
+ gm1?: number[];
421
+ }
422
+ /**
423
+ * type: `EmbeddingModel`
424
+ * - model for embedding (임베딩) used for RAG (Retrieval-Augmented Generation) search.
425
+ * - 1 document has 1 or more embedding models.
426
+ *
427
+ * - (v2) save the remote model in json format with vector set.
428
+ */
429
+ export interface EmbeddingModel extends Model, EmbeddingHead {
430
+ /**
431
+ * id of model
432
+ * - system: default auto-seq, or user defined. (ex: 'sg1')
433
+ * - unit: combination of documentId and parentId (ex: `2001:md1:sg1`)
434
+ */
435
+ id?: string;
436
+ /** stereo */
437
+ stereo?: EmbeddingStereo;
438
+ /** model */
439
+ model?: ChatEmbeddingType;
440
+ /**
441
+ * (internal) revision number
442
+ */
443
+ revision?: number;
444
+ /**
445
+ * typeof strategy
446
+ */
447
+ strategy?: DocumentStrategyType;
448
+ /**
449
+ * json stringified meta info
450
+ * - save the original json
451
+ */
452
+ meta?: string;
453
+ /**
454
+ * (v2) vectors of the embedding
455
+ * ex: vector$.ad2
456
+ */
457
+ vector$?: EmbeddingVectorSet;
458
+ /** (optional) id of parent */
459
+ parentId?: string;
460
+ /** (optional) partial of parent */
461
+ parent$?: EmbeddingHead;
462
+ /** (optional) id of document */
463
+ documentId?: string;
464
+ /** (optional) partial of document */
465
+ document$?: DocumentHead;
466
+ /** (optional) id of usage */
467
+ usageId?: string;
468
+ /** (optional) partial of usage */
469
+ usage$?: UsageHead;
470
+ /** (internal) score by search */
471
+ readonly _score?: number;
472
+ /** (internal) document to use */
473
+ readonly $document?: DocumentModel;
474
+ }
475
+ /**
476
+ * type: `UsageHead`
477
+ * - common head of `UsageModel`
478
+ */
479
+ export interface UsageHead {
480
+ /** id of model */
481
+ id?: string;
482
+ /** name of model */
483
+ name?: string;
484
+ /** stereo */
485
+ stereo?: UsageStereo;
486
+ /** type of usage */
487
+ usage?: TokenUsageType;
488
+ }
489
+ /**
490
+ * type: `UsageModel`
491
+ * - model for usage (임베딩) used for RAG (Retrieval-Augmented Generation) search.
492
+ */
493
+ export interface UsageModel extends Model, UsageHead {
494
+ /** id of usage */
495
+ id?: string;
496
+ /** name of usage */
497
+ name?: string;
498
+ /** stereo */
499
+ stereo?: UsageStereo;
500
+ /** type of usage */
501
+ usage?: TokenUsageType;
502
+ /**
503
+ * used tokens (must be number/integer)
504
+ */
505
+ usage$?: TokenUsageDetail;
506
+ }
507
+ /**
508
+ * type: `ImageHead`
509
+ * - common head of `ImageModel`
510
+ */
511
+ export interface ImageHead {
512
+ /** id of model */
513
+ id?: string;
514
+ /** stereo */
515
+ stereo?: ImageStereo;
516
+ /** hash of image url */
517
+ hash?: string;
518
+ /** url of image */
519
+ url?: string;
520
+ /** (internal) error if has */
521
+ error?: string;
522
+ /** (optional) content after described */
523
+ content?: string;
524
+ }
525
+ /**
526
+ * type: `ImageModel`
527
+ * - manage each image referenced in documents.
528
+ */
529
+ export interface ImageModel extends Model, ImageHead {
530
+ /** id of image */
531
+ id?: string;
532
+ /** stereo */
533
+ stereo?: ImageStereo;
534
+ /** (optional) alias of image */
535
+ aliasId?: string;
536
+ /** (optional) alias of image */
537
+ alias$?: ImageHead;
538
+ /** name of image */
539
+ name?: string;
540
+ /** hash of image url */
541
+ hash?: string;
542
+ /** original image url */
543
+ url?: string;
544
+ /** image content in text */
545
+ content?: string;
546
+ /** referenced document-id */
547
+ documentId?: string;
548
+ /** (optional) partial of document */
549
+ document$?: DocumentHead;
550
+ /** (copied) the token usage in detail */
551
+ usage$?: TokenUsageDetail;
552
+ }
553
+ /**
554
+ * extract field names from models
555
+ * - only fields start with lowercase, or all upper.
556
+ */
557
+ export declare const filterFields: (fields: string[], base?: string[]) => string[];
558
+ /** field names from head */
559
+ export declare const $HEAD: {
560
+ agent: string[];
561
+ chat: string[];
562
+ prompt: string[];
563
+ brain: string[];
564
+ document: string[];
565
+ embedding: string[];
566
+ usage: string[];
567
+ image: string[];
568
+ };
569
+ export declare const $FIELD: {
570
+ agent: string[];
571
+ chat: string[];
572
+ prompt: string[];
573
+ brain: string[];
574
+ document: string[];
575
+ embedding: string[];
576
+ usage: string[];
577
+ image: string[];
578
+ };
579
+ /** must export default as below */
580
+ declare const _default: {
581
+ $HEAD: {
582
+ agent: string[];
583
+ chat: string[];
584
+ prompt: string[];
585
+ brain: string[];
586
+ document: string[];
587
+ embedding: string[];
588
+ usage: string[];
589
+ image: string[];
590
+ };
591
+ $FIELD: {
592
+ agent: string[];
593
+ chat: string[];
594
+ prompt: string[];
595
+ brain: string[];
596
+ document: string[];
597
+ embedding: string[];
598
+ usage: string[];
599
+ image: string[];
600
+ };
601
+ };
602
+ export default _default;