@difizen/libro-ai-native 0.2.41-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/es/ai-native-code-block.d.ts +4 -0
  4. package/es/ai-native-code-block.d.ts.map +1 -0
  5. package/es/ai-native-code-block.js +176 -0
  6. package/es/ai-native-command-contribution.d.ts +16 -0
  7. package/es/ai-native-command-contribution.d.ts.map +1 -0
  8. package/es/ai-native-command-contribution.js +297 -0
  9. package/es/ai-native-command.d.ts +5 -0
  10. package/es/ai-native-command.d.ts.map +1 -0
  11. package/es/ai-native-command.js +17 -0
  12. package/es/ai-native-for-cell-view.d.ts +20 -0
  13. package/es/ai-native-for-cell-view.d.ts.map +1 -0
  14. package/es/ai-native-for-cell-view.js +190 -0
  15. package/es/ai-native-output-top.d.ts +6 -0
  16. package/es/ai-native-output-top.d.ts.map +1 -0
  17. package/es/ai-native-output-top.js +37 -0
  18. package/es/ai-native-service.d.ts +13 -0
  19. package/es/ai-native-service.d.ts.map +1 -0
  20. package/es/ai-native-service.js +75 -0
  21. package/es/ai-side-toolbar-selector.d.ts +3 -0
  22. package/es/ai-side-toolbar-selector.d.ts.map +1 -0
  23. package/es/ai-side-toolbar-selector.js +47 -0
  24. package/es/chat-slot-contribution.d.ts +15 -0
  25. package/es/chat-slot-contribution.d.ts.map +1 -0
  26. package/es/chat-slot-contribution.js +71 -0
  27. package/es/chat-view.d.ts +15 -0
  28. package/es/chat-view.d.ts.map +1 -0
  29. package/es/chat-view.js +114 -0
  30. package/es/error-output-model.d.ts +8 -0
  31. package/es/error-output-model.d.ts.map +1 -0
  32. package/es/error-output-model.js +140 -0
  33. package/es/icon.d.ts +4 -0
  34. package/es/icon.d.ts.map +1 -0
  35. package/es/icon.js +92 -0
  36. package/es/index.d.ts +6 -0
  37. package/es/index.d.ts.map +1 -0
  38. package/es/index.js +5 -0
  39. package/es/index.less +297 -0
  40. package/es/libro-ai-msg-item-model.d.ts +18 -0
  41. package/es/libro-ai-msg-item-model.d.ts.map +1 -0
  42. package/es/libro-ai-msg-item-model.js +85 -0
  43. package/es/libro-ai-native-chat-service.d.ts +8 -0
  44. package/es/libro-ai-native-chat-service.d.ts.map +1 -0
  45. package/es/libro-ai-native-chat-service.js +157 -0
  46. package/es/libro-ai-native-chat-view.d.ts +42 -0
  47. package/es/libro-ai-native-chat-view.d.ts.map +1 -0
  48. package/es/libro-ai-native-chat-view.js +88 -0
  49. package/es/libro-ai-native-color-registry.d.ts +6 -0
  50. package/es/libro-ai-native-color-registry.d.ts.map +1 -0
  51. package/es/libro-ai-native-color-registry.js +46 -0
  52. package/es/module.d.ts +3 -0
  53. package/es/module.d.ts.map +1 -0
  54. package/es/module.js +28 -0
  55. package/es/protocol.d.ts +10 -0
  56. package/es/protocol.d.ts.map +1 -0
  57. package/es/protocol.js +1 -0
  58. package/es/utils.js +114 -0
  59. package/package.json +74 -0
  60. package/src/ai-native-code-block.tsx +138 -0
  61. package/src/ai-native-command-contribution.tsx +248 -0
  62. package/src/ai-native-command.ts +23 -0
  63. package/src/ai-native-for-cell-view.tsx +156 -0
  64. package/src/ai-native-output-top.tsx +43 -0
  65. package/src/ai-native-service.ts +39 -0
  66. package/src/ai-side-toolbar-selector.tsx +51 -0
  67. package/src/chat-slot-contribution.ts +36 -0
  68. package/src/chat-view.tsx +141 -0
  69. package/src/error-output-model.tsx +103 -0
  70. package/src/icon.tsx +80 -0
  71. package/src/index.less +330 -0
  72. package/src/index.spec.ts +8 -0
  73. package/src/index.ts +5 -0
  74. package/src/libro-ai-msg-item-model.ts +69 -0
  75. package/src/libro-ai-native-chat-service.ts +95 -0
  76. package/src/libro-ai-native-chat-view.tsx +54 -0
  77. package/src/libro-ai-native-color-registry.ts +33 -0
  78. package/src/module.ts +44 -0
  79. package/src/protocol.ts +18 -0
  80. package/src/utils.tsx +115 -0
package/es/index.less ADDED
@@ -0,0 +1,297 @@
1
+ @ant-prefix: ant;
2
+
3
+ .libro-error-output-btn-container {
4
+ display: flex;
5
+
6
+ .libro-ai-native-fix-button {
7
+ height: 24px;
8
+ width: 118px;
9
+ margin-top: 16px;
10
+ margin-right: 16px;
11
+ padding: unset;
12
+ background: var(--mana-color-bg-container);
13
+ border-color: var(--mana-libro-ai-native-color);
14
+
15
+ span {
16
+ display: flex;
17
+ font-family: ArialMT;
18
+ font-size: 12px;
19
+ color: var(--mana-libro-ai-native-color);
20
+ line-height: 22px;
21
+ }
22
+
23
+ &:hover {
24
+ color: var(--mana-libro-ai-native-color) !important;
25
+ border-color: var(--mana-libro-ai-native-color) !important;
26
+ }
27
+ }
28
+ }
29
+
30
+ .libro-cell-right-toolbar {
31
+ .libro-ai-icon {
32
+ g {
33
+ fill: none !important;
34
+ }
35
+
36
+ .libro-ai-inner-icon {
37
+ fill: var(--mana-libro-ai-native-color) !important;
38
+ }
39
+ }
40
+ }
41
+
42
+ .libro-side-toolbar-ai-select-menu {
43
+ .@{ant-prefix}-popover-content {
44
+ width: 120px;
45
+ height: 72px;
46
+ }
47
+ }
48
+
49
+ .libro-view-content-right {
50
+ height: calc(100% - 46px);
51
+
52
+ .libro-slot-container {
53
+ height: 100%;
54
+ }
55
+ }
56
+
57
+ .chat-header {
58
+ padding: 8px 16px;
59
+ height: 40px;
60
+ display: flex;
61
+ justify-content: space-between;
62
+
63
+ .chat-title {
64
+ font-size: 16px;
65
+ font-weight: 600;
66
+ }
67
+ }
68
+
69
+ .chat-container {
70
+ border: 1px solid var(--mana-libro-ai-native-color);
71
+ box-shadow: var(--mana-libro-ai-native-box-shadow) 0 0 0 2px;
72
+ border-radius: 6px;
73
+ height: 100%;
74
+ width: 460px;
75
+
76
+ .chat {
77
+ height: calc(100% - 40px);
78
+ }
79
+ }
80
+
81
+ .chat-type {
82
+ margin-right: 6px;
83
+ }
84
+
85
+ .chat-close-icon {
86
+ cursor: pointer;
87
+ }
88
+
89
+ .chat-input-searchInput:focus-within {
90
+ border-color: var(--mana-libro-ai-native-color);
91
+ }
92
+
93
+ .chat-input-sendButton {
94
+ background-color: var(--mana-libro-ai-native-color);
95
+ }
96
+
97
+ .chat-right-toolbar {
98
+ display: flex;
99
+ color: var(--mana-libro-tip-font-color);
100
+
101
+ .@{ant-prefix}-switch.@{ant-prefix}-switch-checked {
102
+ background: var(--mana-libro-ai-native-color);
103
+
104
+ &:hover {
105
+ background: var(--mana-libro-ai-native-color);
106
+ }
107
+ }
108
+ }
109
+
110
+ .ai-cell-chat {
111
+ .libro-dnd-cell {
112
+ &.active {
113
+ border: 1px solid var(--mana-libro-ai-native-color);
114
+ box-shadow: var(--mana-libro-ai-native-box-shadow) 0 0 0 2px;
115
+
116
+ .libro-cell-input-collapser,
117
+ .libro-cell-output-collapser,
118
+ .libro-cell-collapser {
119
+ background: var(--mana-libro-ai-native-color);
120
+ opacity: 1;
121
+ }
122
+
123
+ &.error {
124
+ border: 1px solid var(--mana-libro-ai-native-color) !important;
125
+ box-shadow: var(--mana-libro-ai-native-box-shadow) 0 0 0 2px;
126
+
127
+ .libro-cell-input-collapser,
128
+ .libro-cell-output-collapser,
129
+ .libro-cell-collapser {
130
+ background: var(--mana-libro-ai-native-color);
131
+ opacity: 1;
132
+ }
133
+ }
134
+ }
135
+
136
+ &.active.command-mode {
137
+ border: 1px solid var(--mana-libro-ai-native-color);
138
+ box-shadow: unset;
139
+ }
140
+ }
141
+ }
142
+
143
+ .libro-ai-native-debug-code-btn-container {
144
+ margin-top: 12px;
145
+
146
+ .@{ant-prefix}-btn-variant-outlined {
147
+ height: 24px;
148
+ margin-right: 6px;
149
+ font-size: 13px;
150
+ border-color: var(--mana-libro-ai-native-color);
151
+ color: var(--mana-libro-ai-native-color);
152
+ &.@{ant-prefix}-btn-color-primary {
153
+ box-shadow: unset;
154
+
155
+ &:hover {
156
+ border-color: var(--mana-libro-ai-native-color) !important;
157
+ color: var(--mana-libro-ai-native-color) !important;
158
+ }
159
+ }
160
+ }
161
+ }
162
+
163
+ .libro-ai-native-for-cell-cancel-btn {
164
+ width: 78px;
165
+
166
+ &.@{ant-prefix}-btn-variant-outlined {
167
+ border-color: var(--mana-libro-ai-native-color);
168
+ color: var(--mana-libro-ai-native-color);
169
+
170
+ &:hover {
171
+ border-color: var(--mana-libro-ai-native-color) !important;
172
+ color: var(--mana-libro-ai-native-color) !important;
173
+ }
174
+ }
175
+ }
176
+
177
+ .libro-ai-native-output-top {
178
+ padding: 0 24px;
179
+
180
+ .chat-msg-md-message {
181
+ color: var(--mana-libro-llm-response-output-text-color);
182
+ width: calc(100% - 78px);
183
+ margin-right: 12px;
184
+
185
+ code {
186
+ font-size: 13px;
187
+ }
188
+ }
189
+ }
190
+
191
+ .chat-msg-md-code-pre {
192
+ :global {
193
+ .md-code-pre {
194
+ margin: 0 !important;
195
+ padding: 1.5em !important;
196
+ }
197
+ }
198
+ }
199
+
200
+ .chat-msg-md-code-wrap {
201
+ border-radius: 4px;
202
+ position: relative;
203
+ margin: 12px 0;
204
+
205
+ pre {
206
+ overflow-x: auto;
207
+ }
208
+ }
209
+
210
+ .chat-msg-md-code-lang {
211
+ position: absolute;
212
+ top: 9px;
213
+ right: 28px;
214
+ color: var(--mana-libro-llm-response-output-text-color);
215
+ opacity: 0.8;
216
+ font-size: 13px;
217
+ line-height: 16px;
218
+ }
219
+
220
+ .chat-msg-md-code-copy {
221
+ font-size: 13px;
222
+ cursor: pointer;
223
+ position: absolute;
224
+ top: 9px;
225
+ right: 4px;
226
+ color: var(--mana-libro-llm-response-output-text-color);
227
+ opacity: 0.8;
228
+
229
+ &:hover {
230
+ opacity: 1;
231
+ }
232
+ }
233
+
234
+ .chat-msg-md-code-code {
235
+ display: inline;
236
+ }
237
+
238
+ .libro-ai-native-for-cell-container {
239
+ display: flex;
240
+ justify-content: space-between;
241
+ }
242
+
243
+ .libro-llm-syntax-highlighter {
244
+ code {
245
+ background-color: unset;
246
+ padding: unset;
247
+ }
248
+
249
+ padding: 12px;
250
+ background-color: var(--mana-libro-input-background) !important;
251
+ color: var(--mana-libro-llm-response-output-text-color);
252
+ font-family:
253
+ system-ui,
254
+ -apple-system,
255
+ blinkmacsystemfont,
256
+ 'Segoe UI',
257
+ helvetica,
258
+ arial,
259
+ sans-serif,
260
+ 'Apple Color Emoji',
261
+ 'Segoe UI Emoji',
262
+ 'Segoe UI Symbol';
263
+ font-size: 13px;
264
+
265
+ .token.comment {
266
+ color: var(--mana-libro-editor-comment-color);
267
+ font-style: italic;
268
+ }
269
+
270
+ .token.string {
271
+ color: var(--mana-libro-editor-string-color) !important;
272
+ }
273
+
274
+ .token.keyword {
275
+ color: var(--mana-libro-editor-keyword-color);
276
+ }
277
+
278
+ .token.function {
279
+ color: var(--mana-libro-editor-def-color);
280
+ }
281
+
282
+ .token.number {
283
+ color: var(--mana-libro-editor-number-color);
284
+ }
285
+
286
+ .token.operator {
287
+ color: var(--mana-libro-editor-operator-color);
288
+ }
289
+
290
+ .token.class-name {
291
+ color: var(--mana-libro-editor-class-color);
292
+ }
293
+
294
+ .token.constant {
295
+ color: var(--mana-libro-editor-class-color);
296
+ }
297
+ }
@@ -0,0 +1,18 @@
1
+ import { AnswerState } from '@difizen/magent-chat';
2
+ import type { IChatMessageSender, ErrorMessage, IChatEvent, ChatEventChunk, ChatEventError, ChatEventResult, IChatMessageItem } from '@difizen/magent-chat';
3
+ export declare class LibroAIChatMessageItemModel {
4
+ id?: string;
5
+ sender: IChatMessageSender;
6
+ state: AnswerState;
7
+ protected _content: string;
8
+ get content(): string;
9
+ set content(v: string);
10
+ option: IChatMessageItem;
11
+ error?: ErrorMessage;
12
+ constructor(option: IChatMessageItem);
13
+ handleEventData(e: IChatEvent): void;
14
+ appendChunk(e: ChatEventChunk): void;
15
+ handleResult(e: ChatEventResult): void;
16
+ handleError(e: ChatEventError): void;
17
+ }
18
+ //# sourceMappingURL=libro-ai-msg-item-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libro-ai-msg-item-model.d.ts","sourceRoot":"","sources":["../src/libro-ai-msg-item-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAa,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAI9B,qBACa,2BAA2B;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,kBAAkB,CAAC;IAG3B,KAAK,EAAE,WAAW,CAAC;IAGnB,SAAS,CAAC,QAAQ,SAAM;IACxB,IAAI,OAAO,IAAI,MAAM,CAEpB;IACD,IAAI,OAAO,CAAC,CAAC,EAHE,MAGF,EAEZ;IAED,MAAM,EAAE,gBAAgB,CAAC;IAGzB,KAAK,CAAC,EAAE,YAAY,CAAC;gBAEkB,MAAM,EAAE,gBAAgB;IAQ/D,eAAe,CAAC,CAAC,EAAE,UAAU;IAY7B,WAAW,CAAC,CAAC,EAAE,cAAc;IAI7B,YAAY,CAAC,CAAC,EAAE,eAAe;IAK/B,WAAW,CAAC,CAAC,EAAE,cAAc;CAG9B"}
@@ -0,0 +1,85 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2, _descriptor3;
3
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
+ function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
10
+ function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
11
+ import { AnswerState, ChatEvent } from '@difizen/magent-chat';
12
+ import { autoFactory, AutoFactoryOption } from '@difizen/magent-core';
13
+ import { inject, prop } from '@difizen/mana-app';
14
+ export var LibroAIChatMessageItemModel = (_dec = autoFactory(), _dec2 = prop(), _dec3 = prop(), _dec4 = prop(), _dec(_class = (_class2 = /*#__PURE__*/function () {
15
+ function LibroAIChatMessageItemModel(option) {
16
+ _classCallCheck(this, LibroAIChatMessageItemModel);
17
+ _initializerDefineProperty(this, "state", _descriptor, this);
18
+ _initializerDefineProperty(this, "_content", _descriptor2, this);
19
+ _initializerDefineProperty(this, "error", _descriptor3, this);
20
+ if (option.content) {
21
+ this.state = AnswerState.SUCCESS;
22
+ } else {
23
+ this.state = AnswerState.WAITING;
24
+ }
25
+ }
26
+ LibroAIChatMessageItemModel = inject(AutoFactoryOption)(LibroAIChatMessageItemModel, undefined, 0) || LibroAIChatMessageItemModel;
27
+ _createClass(LibroAIChatMessageItemModel, [{
28
+ key: "content",
29
+ get: function get() {
30
+ return this._content;
31
+ },
32
+ set: function set(v) {
33
+ this._content = v;
34
+ }
35
+ }, {
36
+ key: "handleEventData",
37
+ value: function handleEventData(e) {
38
+ if (ChatEvent.isChunk(e)) {
39
+ this.appendChunk(e);
40
+ }
41
+ if (ChatEvent.isError(e)) {
42
+ this.handleError(e);
43
+ }
44
+ if (ChatEvent.isResult(e)) {
45
+ this.handleResult(e);
46
+ }
47
+ }
48
+ }, {
49
+ key: "appendChunk",
50
+ value: function appendChunk(e) {
51
+ this.content = "".concat(this.content).concat(e.output);
52
+ }
53
+ }, {
54
+ key: "handleResult",
55
+ value: function handleResult(e) {
56
+ this.content = e.output;
57
+ this.state = AnswerState.SUCCESS;
58
+ }
59
+ }, {
60
+ key: "handleError",
61
+ value: function handleError(e) {
62
+ this.error = {
63
+ message: e.message
64
+ };
65
+ }
66
+ }]);
67
+ return LibroAIChatMessageItemModel;
68
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "state", [_dec2], {
69
+ configurable: true,
70
+ enumerable: true,
71
+ writable: true,
72
+ initializer: null
73
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "_content", [_dec3], {
74
+ configurable: true,
75
+ enumerable: true,
76
+ writable: true,
77
+ initializer: function initializer() {
78
+ return '';
79
+ }
80
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "error", [_dec4], {
81
+ configurable: true,
82
+ enumerable: true,
83
+ writable: true,
84
+ initializer: null
85
+ })), _class2)) || _class);
@@ -0,0 +1,8 @@
1
+ import type { IChatEvent, IChatMessageItem } from '@difizen/magent-chat';
2
+ import { LibroChatService } from '@difizen/magent-libro';
3
+ import type { LibroAINativeChatMessageItemOption } from './protocol.js';
4
+ export declare class LibroAINativeChatService extends LibroChatService {
5
+ chat: (option: LibroAINativeChatMessageItemOption) => Promise<IChatMessageItem[]>;
6
+ chatStream: (option: LibroAINativeChatMessageItemOption, messgeCallback: (event: IChatMessageItem) => void, eventCallback: (event: IChatEvent) => void) => Promise<void>;
7
+ }
8
+ //# sourceMappingURL=libro-ai-native-chat-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libro-ai-native-chat-service.d.ts","sourceRoot":"","sources":["../src/libro-ai-native-chat-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,eAAe,CAAC;AAGxE,qBACa,wBAAyB,SAAQ,gBAAgB;IACnD,IAAI,WACH,kCAAkC,KACzC,QAAQ,gBAAgB,EAAE,CAAC,CAmB5B;IACO,UAAU,WACT,kCAAkC,0BAClB,gBAAgB,KAAK,IAAI,yBAC1B,UAAU,KAAK,IAAI,mBAqD1C;CACH"}
@@ -0,0 +1,157 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _class;
3
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
4
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
5
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
12
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
13
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
15
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
16
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
17
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
18
+ import { ChatEvent } from '@difizen/magent-chat';
19
+ import { LibroChatService } from '@difizen/magent-libro';
20
+ import { singleton } from '@difizen/mana-app';
21
+ import { EventSourceParserStream } from 'eventsource-parser/stream';
22
+ import { stringToReadableStream } from "./utils.js";
23
+ export var LibroAINativeChatService = (_dec = singleton(), _dec(_class = /*#__PURE__*/function (_LibroChatService) {
24
+ _inherits(LibroAINativeChatService, _LibroChatService);
25
+ var _super = _createSuper(LibroAINativeChatService);
26
+ function LibroAINativeChatService() {
27
+ var _this;
28
+ _classCallCheck(this, LibroAINativeChatService);
29
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
30
+ args[_key] = arguments[_key];
31
+ }
32
+ _this = _super.call.apply(_super, [this].concat(args));
33
+ _this.chat = /*#__PURE__*/function () {
34
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(option) {
35
+ var chat_key, content, system_prompt, res;
36
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
37
+ while (1) switch (_context.prev = _context.next) {
38
+ case 0:
39
+ chat_key = option.chat_key, content = option.content, system_prompt = option.system_prompt;
40
+ _context.next = 3;
41
+ return _this.fetcher.post("/libro/api/chat", {
42
+ chat_key: chat_key,
43
+ prompt: content,
44
+ system_prompt: system_prompt
45
+ });
46
+ case 3:
47
+ res = _context.sent;
48
+ if (!(res.status === 200)) {
49
+ _context.next = 7;
50
+ break;
51
+ }
52
+ if (!res.data.output) {
53
+ _context.next = 7;
54
+ break;
55
+ }
56
+ return _context.abrupt("return", [{
57
+ sender: {
58
+ type: 'AI',
59
+ id: chat_key
60
+ },
61
+ content: res.data.output
62
+ }]);
63
+ case 7:
64
+ return _context.abrupt("return", []);
65
+ case 8:
66
+ case "end":
67
+ return _context.stop();
68
+ }
69
+ }, _callee);
70
+ }));
71
+ return function (_x) {
72
+ return _ref.apply(this, arguments);
73
+ };
74
+ }();
75
+ _this.chatStream = /*#__PURE__*/function () {
76
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(option, messgeCallback, eventCallback) {
77
+ var chat_key, content, system_prompt, url, msg, res, reader, stream, alreayDone, _yield$reader$read, value, done, data, _event;
78
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
79
+ while (1) switch (_context2.prev = _context2.next) {
80
+ case 0:
81
+ chat_key = option.chat_key, content = option.content, system_prompt = option.system_prompt;
82
+ url = "/libro/api/chatstream";
83
+ msg = {
84
+ chat_key: chat_key,
85
+ prompt: content,
86
+ system_prompt: system_prompt
87
+ };
88
+ _context2.next = 5;
89
+ return _this.fetcher.post(url, msg, {
90
+ headers: {
91
+ Accept: 'text/event-stream'
92
+ },
93
+ responseType: 'stream',
94
+ adapter: 'fetch'
95
+ });
96
+ case 5:
97
+ res = _context2.sent;
98
+ if (!(res.status === 200)) {
99
+ _context2.next = 26;
100
+ break;
101
+ }
102
+ if (typeof res.data === 'string') {
103
+ reader = stringToReadableStream(res.data).pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).getReader();
104
+ } else {
105
+ stream = res.data;
106
+ reader = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).getReader();
107
+ }
108
+ messgeCallback({
109
+ sender: {
110
+ type: 'AI',
111
+ id: chat_key
112
+ },
113
+ content: ''
114
+ });
115
+ alreayDone = false;
116
+ case 10:
117
+ if (alreayDone) {
118
+ _context2.next = 25;
119
+ break;
120
+ }
121
+ _context2.next = 13;
122
+ return reader.read();
123
+ case 13:
124
+ _yield$reader$read = _context2.sent;
125
+ value = _yield$reader$read.value;
126
+ done = _yield$reader$read.done;
127
+ if (!done) {
128
+ _context2.next = 20;
129
+ break;
130
+ }
131
+ alreayDone = true;
132
+ eventCallback({
133
+ type: 'done'
134
+ });
135
+ return _context2.abrupt("break", 25);
136
+ case 20:
137
+ data = JSON.parse(value.data);
138
+ _event = ChatEvent.format(value.event || 'chunk', data);
139
+ eventCallback(_event);
140
+ _context2.next = 10;
141
+ break;
142
+ case 25:
143
+ return _context2.abrupt("return");
144
+ case 26:
145
+ case "end":
146
+ return _context2.stop();
147
+ }
148
+ }, _callee2);
149
+ }));
150
+ return function (_x2, _x3, _x4) {
151
+ return _ref2.apply(this, arguments);
152
+ };
153
+ }();
154
+ return _this;
155
+ }
156
+ return _createClass(LibroAINativeChatService);
157
+ }(LibroChatService)) || _class);
@@ -0,0 +1,42 @@
1
+ import type { LibroView } from '@difizen/libro-jupyter';
2
+ import { ChatView } from '@difizen/magent-chat';
3
+ import breaks from 'remark-breaks';
4
+ import remarkGfm from 'remark-gfm';
5
+ import './index.less';
6
+ import { ImageModal } from './utils.js';
7
+ export declare class LibroAiNativeChatView extends ChatView {
8
+ isCellChat: boolean;
9
+ libro?: LibroView;
10
+ getMarkdownProps(): {
11
+ components: {
12
+ code: (props: any) => import("react/jsx-runtime").JSX.Element;
13
+ img: typeof ImageModal;
14
+ };
15
+ remarkPlugins: (typeof remarkGfm | typeof breaks)[];
16
+ };
17
+ protected toMessageOption(msgContent: string): {
18
+ sender: {
19
+ type: string;
20
+ };
21
+ input: string;
22
+ system_prompt: string;
23
+ id: string;
24
+ created?: string | undefined;
25
+ messages?: import("@difizen/magent-chat").IChatMessageItem[] | undefined;
26
+ modified?: string | undefined;
27
+ stream: boolean;
28
+ token?: any;
29
+ } | {
30
+ sender: {
31
+ type: string;
32
+ };
33
+ input: string;
34
+ id: string;
35
+ created?: string | undefined;
36
+ messages?: import("@difizen/magent-chat").IChatMessageItem[] | undefined;
37
+ modified?: string | undefined;
38
+ stream: boolean;
39
+ token?: any;
40
+ };
41
+ }
42
+ //# sourceMappingURL=libro-ai-native-chat-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libro-ai-native-chat-view.d.ts","sourceRoot":"","sources":["../src/libro-ai-native-chat-view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAKxC,qBAEa,qBAAsB,SAAQ,QAAQ;IAEjD,UAAU,UAAS;IAEnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAET,gBAAgB;;;;;;;cAON,eAAe,CAAC,UAAU,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;CAiBtD"}