@blocklet/pages-kit 0.2.291 → 0.2.292

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 (137) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/api/assistant.js +2 -1
  2. package/lib/cjs/builtin/async/ai-runtime/api/message.js +14 -1
  3. package/lib/cjs/builtin/async/ai-runtime/api/request.js +5 -3
  4. package/lib/cjs/builtin/async/ai-runtime/api/session.js +2 -2
  5. package/lib/cjs/builtin/async/ai-runtime/components/PoweredBy.js +1 -9
  6. package/lib/cjs/builtin/async/ai-runtime/components/RuntimeProvider.js +1 -1
  7. package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +1 -1
  8. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +4 -4
  9. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormFields.js +5 -1
  10. package/lib/cjs/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
  11. package/lib/cjs/builtin/async/ai-runtime/components/form/SettingButton.js +16 -9
  12. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +14 -3
  13. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +65 -29
  14. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +6 -5
  15. package/lib/cjs/builtin/async/ai-runtime/components/parameters/RadioField.js +39 -0
  16. package/lib/cjs/builtin/async/ai-runtime/components/parameters/SelectField.js +1 -1
  17. package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +5 -1
  18. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.js +153 -0
  19. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.js +19 -0
  20. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.js +179 -0
  21. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.js +13 -0
  22. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.js +129 -0
  23. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.js +117 -0
  24. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.js +109 -0
  25. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.js +17 -0
  26. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.js +87 -0
  27. package/lib/cjs/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.js +27 -0
  28. package/lib/cjs/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.js +19 -0
  29. package/lib/cjs/builtin/async/ai-runtime/components/runtime/index.js +42 -0
  30. package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/assistant.js +61 -0
  31. package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/runtime.js +56 -0
  32. package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/session.js +213 -0
  33. package/lib/cjs/builtin/async/ai-runtime/components/runtime/utils/map-right.js +10 -0
  34. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +42 -20
  35. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +12 -5
  36. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +5 -6
  37. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +3 -6
  38. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +4 -0
  39. package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +16 -7
  40. package/lib/cjs/builtin/async/ai-runtime/hooks/auth.js +31 -0
  41. package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +29 -19
  42. package/lib/cjs/builtin/async/ai-runtime/hooks/subscribe.js +6 -4
  43. package/lib/cjs/builtin/async/ai-runtime/index.js +38 -30
  44. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +28 -0
  45. package/lib/cjs/builtin/async/ai-runtime/state/session.js +15 -18
  46. package/lib/cjs/builtin/async/ai-runtime/state/subscription.js +4 -4
  47. package/lib/cjs/components/CustomComponentRenderer/index.js +0 -1
  48. package/lib/cjs/components/CustomComponentRenderer/state.js +64 -57
  49. package/lib/cjs/components/index.js +1 -0
  50. package/lib/esm/builtin/async/ai-runtime/api/assistant.js +2 -1
  51. package/lib/esm/builtin/async/ai-runtime/api/message.js +14 -1
  52. package/lib/esm/builtin/async/ai-runtime/api/request.js +5 -3
  53. package/lib/esm/builtin/async/ai-runtime/api/session.js +2 -2
  54. package/lib/esm/builtin/async/ai-runtime/components/PoweredBy.js +2 -10
  55. package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +1 -1
  56. package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +2 -2
  57. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +4 -4
  58. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +5 -1
  59. package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
  60. package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +16 -9
  61. package/lib/esm/builtin/async/ai-runtime/components/message/MessageErrorView.js +14 -3
  62. package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +65 -31
  63. package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +6 -5
  64. package/lib/esm/builtin/async/ai-runtime/components/parameters/RadioField.js +37 -0
  65. package/lib/esm/builtin/async/ai-runtime/components/parameters/SelectField.js +1 -1
  66. package/lib/esm/builtin/async/ai-runtime/components/parameters/index.js +5 -1
  67. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.js +146 -0
  68. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.js +13 -0
  69. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.js +149 -0
  70. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.js +7 -0
  71. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.js +100 -0
  72. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.js +114 -0
  73. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.js +80 -0
  74. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.js +11 -0
  75. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.js +58 -0
  76. package/lib/esm/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.js +22 -0
  77. package/lib/esm/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.js +14 -0
  78. package/lib/esm/builtin/async/ai-runtime/components/runtime/index.js +36 -0
  79. package/lib/esm/builtin/async/ai-runtime/components/runtime/state/assistant.js +56 -0
  80. package/lib/esm/builtin/async/ai-runtime/components/runtime/state/runtime.js +52 -0
  81. package/lib/esm/builtin/async/ai-runtime/components/runtime/state/session.js +209 -0
  82. package/lib/esm/builtin/async/ai-runtime/components/runtime/utils/map-right.js +7 -0
  83. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +21 -22
  84. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +13 -6
  85. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +5 -6
  86. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +3 -6
  87. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +4 -0
  88. package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +9 -0
  89. package/lib/esm/builtin/async/ai-runtime/hooks/auth.js +27 -0
  90. package/lib/esm/builtin/async/ai-runtime/hooks/header.js +30 -20
  91. package/lib/esm/builtin/async/ai-runtime/hooks/subscribe.js +6 -4
  92. package/lib/esm/builtin/async/ai-runtime/index.js +15 -29
  93. package/lib/esm/builtin/async/ai-runtime/locales/index.js +28 -0
  94. package/lib/esm/builtin/async/ai-runtime/state/session.js +17 -20
  95. package/lib/esm/builtin/async/ai-runtime/state/subscription.js +2 -2
  96. package/lib/esm/components/CustomComponentRenderer/index.js +0 -1
  97. package/lib/esm/components/CustomComponentRenderer/state.js +63 -57
  98. package/lib/esm/components/index.js +1 -0
  99. package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +4 -2
  100. package/lib/types/builtin/async/ai-runtime/api/message.d.ts +9 -2
  101. package/lib/types/builtin/async/ai-runtime/api/request.d.ts +4 -1
  102. package/lib/types/builtin/async/ai-runtime/api/session.d.ts +2 -1
  103. package/lib/types/builtin/async/ai-runtime/components/form/ParameterForm.d.ts +3 -2
  104. package/lib/types/builtin/async/ai-runtime/components/form/QuestionField.d.ts +3 -2
  105. package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +5 -2
  106. package/lib/types/builtin/async/ai-runtime/components/message/MessageErrorView.d.ts +4 -5
  107. package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +11 -4
  108. package/lib/types/builtin/async/ai-runtime/components/message/MessageListView.d.ts +5 -3
  109. package/lib/types/builtin/async/ai-runtime/components/parameters/RadioField.d.ts +9 -0
  110. package/lib/types/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.d.ts +9 -0
  111. package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.d.ts +3 -0
  112. package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.d.ts +12 -0
  113. package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.d.ts +1 -0
  114. package/lib/types/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.d.ts +5 -0
  115. package/lib/types/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.d.ts +1 -0
  116. package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.d.ts +3 -0
  117. package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.d.ts +1 -0
  118. package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.d.ts +4 -0
  119. package/lib/types/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.d.ts +12 -0
  120. package/lib/types/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.d.ts +10 -0
  121. package/lib/types/builtin/async/ai-runtime/components/runtime/index.d.ts +1 -0
  122. package/lib/types/builtin/async/ai-runtime/components/runtime/state/assistant.d.ts +17 -0
  123. package/lib/types/builtin/async/ai-runtime/components/runtime/state/runtime.d.ts +14 -0
  124. package/lib/types/builtin/async/ai-runtime/components/runtime/state/session.d.ts +29 -0
  125. package/lib/types/builtin/async/ai-runtime/components/runtime/utils/map-right.d.ts +1 -0
  126. package/lib/types/builtin/async/ai-runtime/hooks/auth.d.ts +4 -0
  127. package/lib/types/builtin/async/ai-runtime/hooks/subscribe.d.ts +1 -0
  128. package/lib/types/builtin/async/ai-runtime/index.d.ts +15 -8
  129. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +22 -0
  130. package/lib/types/builtin/async/ai-runtime/state/assistant.d.ts +0 -2
  131. package/lib/types/builtin/async/ai-runtime/state/session.d.ts +0 -3
  132. package/lib/types/builtin/async/ai-runtime/state/subscription.d.ts +1 -1
  133. package/lib/types/components/CustomComponentRenderer/index.d.ts +0 -1
  134. package/lib/types/components/CustomComponentRenderer/state.d.ts +2 -3
  135. package/lib/types/components/index.d.ts +1 -0
  136. package/lib/types/types/core.d.ts +1 -0
  137. package/package.json +9 -7
@@ -16,10 +16,11 @@ const constants_1 = require("../constants");
16
16
  const utils_2 = require("../utils");
17
17
  const request_1 = require("./request");
18
18
  function getAssistant(_a) {
19
- return __awaiter(this, arguments, void 0, function* ({ assistantId: id }) {
19
+ return __awaiter(this, arguments, void 0, function* ({ assistantId: id, working, }) {
20
20
  const { projectId, projectRef, assistantId } = (0, utils_2.parseIdentity)(id, { rejectWhenError: true });
21
21
  return (0, request_1.request)({
22
22
  url: (0, ufo_1.joinURL)((0, utils_1.getComponentMountPoint)(constants_1.AI_STUDIO_DID), '/api/projects', projectId, 'refs', projectRef, 'assistants', assistantId),
23
+ query: { working },
23
24
  });
24
25
  });
25
26
  }
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.deleteMessages = exports.getMessages = void 0;
13
24
  const ufo_1 = require("ufo");
@@ -15,9 +26,11 @@ const utils_1 = require("../../../utils");
15
26
  const constants_1 = require("../constants");
16
27
  const request_1 = require("./request");
17
28
  function getMessages(_a) {
18
- return __awaiter(this, arguments, void 0, function* ({ sessionId, }) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ var { sessionId } = _a, query = __rest(_a, ["sessionId"]);
19
31
  return (0, request_1.request)({
20
32
  url: (0, ufo_1.joinURL)((0, utils_1.getComponentMountPoint)(constants_1.AI_STUDIO_DID), '/api/sessions', sessionId, 'messages'),
33
+ query,
21
34
  });
22
35
  });
23
36
  }
@@ -22,6 +22,8 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.request = exports.fetch = void 0;
24
24
  const js_sdk_1 = require("@blocklet/js-sdk");
25
+ const ufo_1 = require("ufo");
26
+ const error_1 = require("../error");
25
27
  let isDEV = false;
26
28
  try {
27
29
  // @ts-ignore
@@ -34,8 +36,8 @@ exports.fetch = (0, js_sdk_1.createFetch)({}, { lazy: isDEV, lazyTime: 1000 });
34
36
  function request(_a) {
35
37
  return __awaiter(this, void 0, void 0, function* () {
36
38
  var _b, _c, _d;
37
- var { url, body } = _a, init = __rest(_a, ["url", "body"]);
38
- const result = yield (0, exports.fetch)(url, Object.assign(Object.assign({}, init), { headers: {
39
+ var { url, query, body } = _a, init = __rest(_a, ["url", "query", "body"]);
40
+ const result = yield (0, exports.fetch)((0, ufo_1.withQuery)(url, query !== null && query !== void 0 ? query : {}), Object.assign(Object.assign({}, init), { headers: {
39
41
  'Content-Type': 'application/json',
40
42
  }, body: typeof body === 'object' ? JSON.stringify(body) : body }));
41
43
  if (!(result.status >= 200 && result.status < 300)) {
@@ -47,7 +49,7 @@ function request(_a) {
47
49
  console.error('parse response error', error);
48
50
  }
49
51
  const message = (_d = (_c = (_b = json === null || json === void 0 ? void 0 : json.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : json === null || json === void 0 ? void 0 : json.message) !== null && _d !== void 0 ? _d : json === null || json === void 0 ? void 0 : json.error;
50
- throw new Error(typeof message === 'string' ? message : `request error ${result.status}`);
52
+ throw new error_1.CustomError(result.status, typeof message === 'string' ? message : `request error ${result.status}`);
51
53
  }
52
54
  return result.json();
53
55
  });
@@ -81,7 +81,7 @@ function deleteSession(_a) {
81
81
  }
82
82
  exports.deleteSession = deleteSession;
83
83
  function runAssistant(_a) {
84
- return __asyncGenerator(this, arguments, function* runAssistant_1({ sessionId, identity, parameters, }) {
84
+ return __asyncGenerator(this, arguments, function* runAssistant_1({ sessionId, identity, working, parameters, }) {
85
85
  var _b;
86
86
  const res = yield __await((0, request_1.fetch)((0, ufo_1.joinURL)((0, utils_1.getComponentMountPoint)(constants_1.AI_STUDIO_DID), '/api/ai/call'), {
87
87
  method: 'POST',
@@ -89,7 +89,7 @@ function runAssistant(_a) {
89
89
  'Content-Type': 'application/json',
90
90
  Accept: 'text/event-stream',
91
91
  },
92
- body: JSON.stringify(Object.assign(Object.assign({ sessionId, parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }) }, identity), { ref: identity.projectRef, working: true })),
92
+ body: JSON.stringify(Object.assign(Object.assign({ sessionId, parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }) }, identity), { ref: identity.projectRef, working })),
93
93
  }));
94
94
  if (!(res.status >= 200 && res.status < 300)) {
95
95
  let json;
@@ -14,17 +14,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  const jsx_runtime_1 = require("react/jsx-runtime");
15
15
  const material_1 = require("@mui/material");
16
16
  const locale_1 = require("../../../locale");
17
- const subscribe_1 = require("../hooks/subscribe");
18
17
  function PoweredBy(_a) {
19
18
  var { assistantId } = _a, props = __rest(_a, ["assistantId"]);
20
19
  const { t } = (0, locale_1.useLocaleContext)();
21
- const { subscribeLink } = (0, subscribe_1.useSubscribeLink)({ assistantId });
22
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ py: 0.5 }, props, { children: [subscribeLink && ((0, jsx_runtime_1.jsxs)(material_1.Box, { className: "ai-chat-require-subscribe-footer", sx: {
23
- px: 2,
24
- fontSize: 12,
25
- lineHeight: '20px',
26
- textAlign: 'center',
27
- color: 'rgba(75, 85, 99, 1)',
28
- }, children: [t('requireNewSubscriptionFooter'), (0, jsx_runtime_1.jsx)(material_1.Link, { href: subscribeLink, sx: { ml: 0.5 }, children: t('subscribeNow') })] })), (0, jsx_runtime_1.jsx)(material_1.Stack, { className: "ai-chat-powered-by", direction: "row", justifyContent: "center", children: (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "caption", sx: { display: 'inline-flex', alignItems: 'center', a: { display: 'inline-flex', alignItems: 'center' } }, children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { component: "span", fontSize: 12, color: "text.poweredBy", children: [t('poweredBy'), ' '] }), "\u00A0", (0, jsx_runtime_1.jsxs)(material_1.Link, { href: "https://www.arcblock.io", target: "_blank", color: "text.poweredBy", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { component: "img", src: "https://www.arcblock.io/.well-known/service/blocklet/logo", sx: { height: 16, verticalAlign: 'middle', mr: 0.5, borderRadius: 0.5 } }), "ArcBlock"] }), "\u00A0\u00B7\u00A0", (0, jsx_runtime_1.jsxs)(material_1.Link, { href: "https://www.aigne.io", target: "_blank", color: "text.poweredBy", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { component: "img", src: "https://www.aigne.io/.well-known/service/blocklet/logo", sx: { height: 16, verticalAlign: 'middle', mr: 0.5, borderRadius: 0.5 } }), "AIGNE"] })] }) })] })));
20
+ return ((0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ py: 0.5 }, props, { children: (0, jsx_runtime_1.jsx)(material_1.Stack, { className: "ai-chat-powered-by", direction: "row", justifyContent: "center", children: (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "caption", sx: { display: 'inline-flex', alignItems: 'center', a: { display: 'inline-flex', alignItems: 'center' } }, children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { component: "span", fontSize: 12, color: "text.poweredBy", children: [t('poweredBy'), ' '] }), "\u00A0", (0, jsx_runtime_1.jsxs)(material_1.Link, { href: "https://www.arcblock.io", target: "_blank", color: "text.poweredBy", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { component: "img", src: "https://www.arcblock.io/.well-known/service/blocklet/logo", sx: { height: 16, verticalAlign: 'middle', mr: 0.5, borderRadius: 0.5 } }), "ArcBlock"] }), "\u00A0\u00B7\u00A0", (0, jsx_runtime_1.jsxs)(material_1.Link, { href: "https://www.aigne.io", target: "_blank", color: "text.poweredBy", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { component: "img", src: "https://www.aigne.io/.well-known/service/blocklet/logo", sx: { height: 16, verticalAlign: 'middle', mr: 0.5, borderRadius: 0.5 } }), "AIGNE"] })] }) }) })));
29
21
  }
30
22
  exports.default = PoweredBy;
@@ -18,5 +18,5 @@ function RuntimeProvider({ children }) {
18
18
  }
19
19
  exports.default = RuntimeProvider;
20
20
  function ErrorRender({ error }) {
21
- return ((0, jsx_runtime_1.jsx)(ux_1.Result, Object.assign({ status: error.status || 'error' }, (Number(error.status) === 404 ? { message: error.message } : {}), { sx: { bgcolor: 'transparent', mt: '20%' } })));
21
+ return ((0, jsx_runtime_1.jsx)(ux_1.Result, { status: error.status || 'error', description: error.message, sx: { bgcolor: 'transparent', mt: '20%' } }));
22
22
  }
@@ -54,7 +54,7 @@ function ThemeProvider({ children, template, transparentHeaderBg, }) {
54
54
  style: ({ theme }) => theme.unstable_sx({
55
55
  '.MuiInputBase-root': {
56
56
  fieldset: { borderColor: 'rgba(229, 231, 235, 1)' },
57
- '&:hover': {
57
+ [`:not(.${material_1.inputBaseClasses.disabled}):hover`]: {
58
58
  fieldset: {
59
59
  border: 'none',
60
60
  boxShadow: `0px 0px 0px 4px ${(0, material_1.alpha)(theme.palette.primary.main, 0.2)}, 0px 0px 0px 1px ${theme.palette.primary.main}`,
@@ -49,8 +49,9 @@ const QuestionField_1 = __importDefault(require("./QuestionField"));
49
49
  const SettingButton_1 = __importDefault(require("./SettingButton"));
50
50
  function ParameterForm(_a) {
51
51
  var _b, _c, _d;
52
- var { sessionId, disabled, readOnly, onSubmit, defaultValues, hideSubmit, isSubmitting, assistant, submitButtonTitle = (_c = (_b = assistant.release) === null || _b === void 0 ? void 0 : _b.submitButton) === null || _c === void 0 ? void 0 : _c.title, } = _a;
52
+ var { page, disabled, readOnly, onSubmit, defaultValues, hideSubmit, isSubmitting, assistant, submitButtonTitle = (_c = (_b = assistant.release) === null || _b === void 0 ? void 0 : _b.submitButton) === null || _c === void 0 ? void 0 : _c.title, } = _a;
53
53
  const { t } = (0, locale_1.useLocaleContext)();
54
+ const { sessionId } = page;
54
55
  const parameters = (0, react_2.useMemo)(() => {
55
56
  var _a;
56
57
  return (_a = assistant.parameters) === null || _a === void 0 ? void 0 : _a.filter((i) => i.key && !['question', 'datasetId'].includes(i.key) && ParameterFormFields_1.SUPPORTED_PARAMETER_TYPES.includes(i.type || 'string'));
@@ -69,9 +70,8 @@ function ParameterForm(_a) {
69
70
  }, [defaultForm]);
70
71
  const handleSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
71
72
  if (onSubmit) {
72
- form.setFocus('question');
73
73
  yield onSubmit(parameters);
74
- form.reset((0, omit_1.default)(parameters, 'question'));
74
+ form.reset(Object.assign(Object.assign({}, parameters), { question: '' }));
75
75
  }
76
76
  });
77
77
  const [expand, setExpand] = (0, react_2.useState)(false);
@@ -84,6 +84,6 @@ function ParameterForm(_a) {
84
84
  transform: `rotateX(${expand ? '180deg' : '0deg'})`,
85
85
  transition: 'transform .3s ease-in-out',
86
86
  } }) }) }), (0, jsx_runtime_1.jsx)(material_1.Collapse, { in: expand, orientation: "vertical", sx: { maxHeight: '40vh', overflowY: 'auto' }, children: (0, jsx_runtime_1.jsx)(ParameterFormFields_1.default, { autoFocus: !sessionId, disabled: disabled, readOnly: readOnly, parameters: parameters, form: form, sx: { pb: 2, px: 2 } }) })] })), (0, jsx_runtime_1.jsx)(material_1.Box, { px: 2, children: !hideSubmit &&
87
- (isChat ? ((0, jsx_runtime_1.jsx)(QuestionField_1.default, { sessionId: sessionId, showSettingButton: !!sessionId, assistant: assistant, disabled: disabled, submitButtonTitle: submitButtonTitle || t('send'), readOnly: readOnly, isSubmitting: isSubmitting, form: form, autoFocus: !!sessionId })) : ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-generation-bar", direction: "row", alignItems: "center", justifyContent: "flex-end", gap: 2, children: [sessionId && (0, jsx_runtime_1.jsx)(SettingButton_1.default, { form: form, sessionId: sessionId }), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), (0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { disabled: disabled, type: "submit", variant: "contained", color: "secondary", loading: form.formState.isSubmitting || isSubmitting, children: submitButtonTitle || t('send') }) }) })] }))) })] }));
87
+ (isChat ? ((0, jsx_runtime_1.jsx)(QuestionField_1.default, { page: page, showSettingButton: !!sessionId, assistant: assistant, disabled: disabled, submitButtonTitle: submitButtonTitle || t('send'), readOnly: readOnly, isSubmitting: isSubmitting, form: form, autoFocus: !!sessionId })) : ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-generation-bar", direction: "row", alignItems: "center", justifyContent: "flex-end", gap: 2, children: [page.page === 'session' && (0, jsx_runtime_1.jsx)(SettingButton_1.default, { form: form, page: page }), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), (0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { disabled: disabled, type: "submit", variant: "contained", color: "secondary", loading: form.formState.isSubmitting || isSubmitting, children: submitButtonTitle || t('send') }) }) })] }))) })] }));
88
88
  }
89
89
  exports.default = ParameterForm;
@@ -50,7 +50,11 @@ function ParameterFormFields(_a) {
50
50
  mb: 0.5,
51
51
  fontWeight: 500,
52
52
  color: 'rgba(18, 22, 24, 1)',
53
- }, children: (parameter === null || parameter === void 0 ? void 0 : parameter.label) || parameter.key }), (0, jsx_runtime_1.jsx)(parameters_1.default, { inputRef: field.ref, autoFocus: autoFocus && isFirstParameter, readOnly: readOnly, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), sx: { bgcolor: 'background.paper' } })] }));
53
+ }, children: (parameter === null || parameter === void 0 ? void 0 : parameter.label) || parameter.key }), (0, jsx_runtime_1.jsx)(parameters_1.default, { inputRef: field.ref, autoFocus: autoFocus && isFirstParameter, readOnly: readOnly, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), sx: {
54
+ '& .MuiInputBase-root': {
55
+ bgcolor: 'background.paper',
56
+ },
57
+ } })] }));
54
58
  } }) }, parameter.id));
55
59
  }) })));
56
60
  }
@@ -11,7 +11,7 @@ const react_hook_form_1 = require("react-hook-form");
11
11
  const locale_1 = require("../../../../locale");
12
12
  const LoadingButton_1 = __importDefault(require("../LoadingButton"));
13
13
  const SettingButton_1 = __importDefault(require("./SettingButton"));
14
- function QuestionField({ sessionId, assistant, showSettingButton, form, isSubmitting, autoFocus, readOnly, disabled, submitButtonTitle, }) {
14
+ function QuestionField({ page, assistant, showSettingButton, form, isSubmitting, autoFocus, readOnly, disabled, submitButtonTitle, }) {
15
15
  const { t } = (0, locale_1.useLocaleContext)();
16
16
  const defaultPlaceholder = t('questionPlaceholder');
17
17
  const placeholder = (0, react_2.useMemo)(() => { var _a, _b; return ((_b = (_a = assistant.parameters) === null || _a === void 0 ? void 0 : _a.find((i) => i.key === 'question')) === null || _b === void 0 ? void 0 : _b.placeholder) || defaultPlaceholder; }, [submitButtonTitle, assistant, defaultPlaceholder]);
@@ -28,7 +28,7 @@ function QuestionField({ sessionId, assistant, showSettingButton, form, isSubmit
28
28
  }, InputProps: {
29
29
  readOnly,
30
30
  sx: { p: 1, bgcolor: 'white', borderRadius: 1 },
31
- startAdornment: showSettingButton && sessionId && ((0, jsx_runtime_1.jsx)(SettingButton_1.default, { form: form, sessionId: sessionId, sx: { minWidth: 32, minHeight: 32 }, tabIndex: -1 })),
31
+ startAdornment: showSettingButton && page.page === 'session' && ((0, jsx_runtime_1.jsx)(SettingButton_1.default, { form: form, page: page, sx: { minWidth: 32, minHeight: 32 }, tabIndex: -1 })),
32
32
  className: 'ai-chat-question-field',
33
33
  endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { disabled: disabled, id: "question-submit", ref: submitRef, type: "submit", variant: "contained",
34
34
  // @ts-ignore
@@ -28,12 +28,12 @@ const react_1 = require("@iconify/react");
28
28
  const material_1 = require("@mui/material");
29
29
  const react_2 = require("react");
30
30
  const locale_1 = require("../../../../locale");
31
- const session_1 = require("../../state/session");
31
+ const session_1 = require("../../api/session");
32
+ const loading_1 = require("../../state/loading");
32
33
  const LoadingListItemButton_1 = __importDefault(require("../LoadingListItemButton"));
33
34
  function SettingButton(_a) {
34
- var { sessionId, form } = _a, props = __rest(_a, ["sessionId", "form"]);
35
+ var { page, form } = _a, props = __rest(_a, ["page", "form"]);
35
36
  const { t } = (0, locale_1.useLocaleContext)();
36
- const [, state] = (0, session_1.useSessionState)({ sessionId, required: true });
37
37
  const [openSetting, setOpenSetting] = (0, react_2.useState)(false);
38
38
  const settingOptions = [
39
39
  // {
@@ -46,15 +46,22 @@ function SettingButton(_a) {
46
46
  // },
47
47
  // },
48
48
  {
49
- key: 'clearSession',
50
- label: t('clearSession'),
49
+ key: 'newSession',
50
+ label: t('newObject', { object: t('session') }),
51
51
  onClick: () => __awaiter(this, void 0, void 0, function* () {
52
52
  form.setFocus('question');
53
- yield state.clearSession({
54
- sessionId,
55
- });
53
+ yield loading_1.globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
54
+ const { created: session } = yield (0, session_1.createSession)({
55
+ assistantId: page.assistantId,
56
+ });
57
+ page.navigate({
58
+ page: 'session',
59
+ assistantId: page.assistantId,
60
+ sessionId: session.id,
61
+ });
62
+ }));
56
63
  }),
57
- icon: 'tabler:eraser',
64
+ icon: 'tabler:plus',
58
65
  sx: {
59
66
  color: 'rgba(225, 29, 72, 1)',
60
67
  },
@@ -6,12 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const jsx_runtime_1 = require("react/jsx-runtime");
7
7
  const material_1 = require("@mui/material");
8
8
  const locale_1 = require("../../../../locale");
9
+ const auth_1 = require("../../hooks/auth");
9
10
  const subscribe_1 = require("../../hooks/subscribe");
11
+ const assistant_1 = require("../../state/assistant");
10
12
  const MarkdownRenderer_1 = __importDefault(require("../MarkdownRenderer"));
11
- function MessageErrorView({ assistantId, assistant, error, }) {
13
+ function MessageErrorView({ page, error }) {
12
14
  var _a, _b, _c;
13
15
  const { t } = (0, locale_1.useLocaleContext)();
14
- const { subscribeLink } = (0, subscribe_1.useSubscribeLink)({ assistantId });
16
+ const [assistant] = (0, assistant_1.useAssistantState)(page);
17
+ const { subscribeLink } = (0, subscribe_1.useSubscribeLink)(page);
18
+ const login = (0, auth_1.useLogin)({ page });
19
+ if (!error)
20
+ return null;
15
21
  if (error.type === 'InvalidSubscriptionError') {
16
22
  return ((0, jsx_runtime_1.jsxs)(material_1.Box, { className: "ai-chat-message-error", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { className: "message-response", children: (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children: t('requireNewSubscription', {
17
23
  price: (_b = (_a = assistant.release) === null || _a === void 0 ? void 0 : _a.payment) === null || _b === void 0 ? void 0 : _b.price,
@@ -19,6 +25,11 @@ function MessageErrorView({ assistantId, assistant, error, }) {
19
25
  // @ts-ignore
20
26
  (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", color: "black", href: subscribeLink, children: t('subscribeNow') })) : ((0, jsx_runtime_1.jsx)(material_1.Box, { className: "message-response", children: t('thanksForSubscription') })) })] }));
21
27
  }
22
- return ((0, jsx_runtime_1.jsx)(material_1.Alert, { className: "ai-chat-message-error", severity: "error", children: (error.type === 'ReachMaxRoundLimitError' && ((_c = assistant === null || assistant === void 0 ? void 0 : assistant.release) === null || _c === void 0 ? void 0 : _c.reachMaxRoundLimitTip)) || error.message }));
28
+ if (error.status === 401) {
29
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, { className: "ai-chat-message-error", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { className: "message-response", children: (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children: t('requireLogin') }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { mt: 1, children: (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained",
30
+ // @ts-ignore
31
+ color: "black", onClick: login, children: t('loginNow') }) })] }));
32
+ }
33
+ return ((0, jsx_runtime_1.jsx)(material_1.Alert, { className: "ai-chat-message-error", severity: "error", sx: { mr: 5 }, children: (error.type === 'ReachMaxRoundLimitError' && ((_c = assistant === null || assistant === void 0 ? void 0 : assistant.release) === null || _c === void 0 ? void 0 : _c.reachMaxRoundLimitTip)) || error.message }));
23
34
  }
24
35
  exports.default = MessageErrorView;
@@ -22,49 +22,77 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
25
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
38
  };
28
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.MessageItemWrapper = void 0;
29
41
  const jsx_runtime_1 = require("react/jsx-runtime");
30
42
  const image_preview_1 = __importDefault(require("@blocklet/ai-kit/components/image-preview"));
43
+ const css_1 = require("@emotion/css");
31
44
  const material_1 = require("@mui/material");
32
45
  const dayjs_1 = __importDefault(require("dayjs"));
33
46
  const react_1 = __importStar(require("react"));
34
47
  const ux_1 = require("../../../../arcblock/ux");
35
48
  const session_1 = require("../../../../session");
49
+ const assistant_1 = require("../../state/assistant");
36
50
  const common_1 = require("../common");
37
51
  const MarkdownRenderer_1 = __importDefault(require("../MarkdownRenderer"));
38
52
  const MessageActions_1 = __importDefault(require("./MessageActions"));
39
53
  const MessageErrorView_1 = __importDefault(require("./MessageErrorView"));
40
- function MessageItemView({ assistantId, assistant, message, hideAvatar, }) {
41
- var _a, _b;
42
- const showUserMessage = ((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.template) !== 'form' && !!((_b = message.parameters) === null || _b === void 0 ? void 0 : _b.question);
43
- const commonMessageSx = {
44
- position: 'relative',
45
- borderRadius: 1,
46
- py: 1,
47
- px: 2,
48
- mt: 0.5,
49
- // without logo width
50
- maxWidth: 'calc(100% - 40px)',
51
- };
52
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-item", gap: 2.5, overflow: "hidden",
53
- // @ts-ignore
54
- sx: {
55
- '.message-question': Object.assign(Object.assign(Object.assign({}, commonMessageSx), (!hideAvatar
56
- ? {
57
- borderTopRightRadius: '2px',
58
- }
59
- : {})), { borderTopRightRadius: !hideAvatar && '2px', backgroundColor: 'rgba(239, 246, 255, 1)' }),
60
- '.message-response': Object.assign(Object.assign(Object.assign({}, commonMessageSx), (!hideAvatar
61
- ? {
62
- borderTopLeftRadius: '2px',
63
- }
64
- : {})), { backgroundColor: 'rgba(229, 231, 235, 1)' }),
65
- }, children: [showUserMessage && (0, jsx_runtime_1.jsx)(UserMessage, { message: message }), (0, jsx_runtime_1.jsx)(AgentMessage, { assistantId: assistantId, assistant: assistant, message: message, hideAvatar: hideAvatar })] }));
54
+ function MessageItemView(_a) {
55
+ var _b, _c;
56
+ var { page, message, hideAvatar } = _a, props = __rest(_a, ["page", "message", "hideAvatar"]);
57
+ const [assistant] = (0, assistant_1.useAssistantState)(page);
58
+ const showUserMessage = ((_b = assistant.release) === null || _b === void 0 ? void 0 : _b.template) !== 'form' && !!((_c = message.parameters) === null || _c === void 0 ? void 0 : _c.question);
59
+ return ((0, jsx_runtime_1.jsxs)(MessageItemContainer, Object.assign({}, props, { className: (0, css_1.cx)('ai-chat-message-item', hideAvatar && 'hide-avatar', props.className), children: [showUserMessage && (0, jsx_runtime_1.jsx)(UserMessage, { message: message }), (0, jsx_runtime_1.jsx)(AgentMessage, { page: page, message: message, hideAvatar: hideAvatar })] })));
66
60
  }
67
61
  exports.default = MessageItemView;
62
+ const MessageItemContainer = (0, material_1.styled)(material_1.Stack) `
63
+ gap: 2.5;
64
+ overflow: hidden;
65
+
66
+ .message-question {
67
+ position: relative;
68
+ border-radius: ${({ theme }) => theme.shape.borderRadius}px;
69
+ border-top-right-radius: 2px;
70
+ padding: ${({ theme }) => theme.spacing(1, 2)};
71
+ margin-top: ${({ theme }) => theme.spacing(0.5)};
72
+ // without logo width
73
+ max-width: calc(100% - 40px);
74
+ background-color: rgba(239, 246, 255, 1);
75
+
76
+ &.hide-avatar {
77
+ border-top-right-radius: ${({ theme }) => theme.shape.borderRadius}px;
78
+ }
79
+ }
80
+
81
+ .message-response {
82
+ position: relative;
83
+ border-radius: ${({ theme }) => theme.shape.borderRadius}px;
84
+ border-top-left-radius: 2px;
85
+ padding: ${({ theme }) => theme.spacing(1, 2)};
86
+ margin-top: ${({ theme }) => theme.spacing(0.5)};
87
+ // without logo width
88
+ max-width: calc(100% - 40px);
89
+ background-color: rgba(229, 231, 235, 1);
90
+
91
+ &.hide-avatar {
92
+ border-top-left-radius: ${({ theme }) => theme.shape.borderRadius}px;
93
+ }
94
+ }
95
+ `;
68
96
  function UserMessage({ message }) {
69
97
  var _a, _b, _c, _d;
70
98
  const { session: authSession } = (0, session_1.useSessionContext)();
@@ -79,14 +107,15 @@ function UserMessage({ message }) {
79
107
  alignItems: 'flex-end',
80
108
  }, children: [(0, jsx_runtime_1.jsxs)(MessageUserName, { children: [(_c = authSession.user) === null || _c === void 0 ? void 0 : _c.fullName, (0, jsx_runtime_1.jsx)(MessageTime, { time: message.createdAt })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { className: "message-question", sx: { whiteSpace: 'pre-wrap', wordBreak: 'break-word', textAlign: 'left' }, children: (_d = message.parameters) === null || _d === void 0 ? void 0 : _d.question })] })] }));
81
109
  }
82
- function AgentMessage({ assistantId, assistant, message, hideAvatar, }) {
110
+ function AgentMessage({ page, message, hideAvatar }) {
83
111
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
112
+ const [assistant] = (0, assistant_1.useAssistantState)(page);
84
113
  const showMainMessage = !!(((_a = message.result) === null || _a === void 0 ? void 0 : _a.content) || ((_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.messages) === null || _c === void 0 ? void 0 : _c.length));
85
114
  const isMessageLoading = (message.loading || !message.result) && !message.error;
86
115
  const theme = (0, material_1.useTheme)();
87
116
  const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
88
117
  const isFormTemplate = ((_d = assistant.release) === null || _d === void 0 ? void 0 : _d.template) === 'form';
89
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_e = globalThis.blocklet) === null || _e === void 0 ? void 0 : _e.appId, variant: "circle", shape: "circle", src: (_f = assistant.release) === null || _f === void 0 ? void 0 : _f.logo }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, overflow: "hidden", children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [((_g = assistant.release) === null || _g === void 0 ? void 0 : _g.title) || assistant.name, (0, jsx_runtime_1.jsx)(MessageTime, { time: message.createdAt })] })), (0, jsx_runtime_1.jsxs)(react_1.default.Suspense, { children: [showMainMessage ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({}, (isFormTemplate && {
118
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_e = globalThis.blocklet) === null || _e === void 0 ? void 0 : _e.appId, variant: "circle", shape: "circle", src: (_f = assistant.release) === null || _f === void 0 ? void 0 : _f.logo }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, width: 0, children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [((_g = assistant.release) === null || _g === void 0 ? void 0 : _g.title) || assistant.name, (0, jsx_runtime_1.jsx)(MessageTime, { time: message.createdAt })] })), (0, jsx_runtime_1.jsxs)(react_1.default.Suspense, { children: [showMainMessage ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({}, (isFormTemplate && {
90
119
  open: true,
91
120
  }), { placement: "right-start", PopperProps: {
92
121
  className: 'white-tooltip',
@@ -112,8 +141,15 @@ function AgentMessage({ assistantId, assistant, message, hideAvatar, }) {
112
141
  }), ((_l = message.result) === null || _l === void 0 ? void 0 : _l.content) && ((0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: isMessageLoading ? 'writing' : '', children: message.result.content }))] }) }))) : (isMessageLoading && ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
113
142
  // only response with loading
114
143
  className: "message-response" }))), !!((_o = (_m = message.result) === null || _m === void 0 ? void 0 : _m.objects) === null || _o === void 0 ? void 0 : _o.length) &&
115
- ((_q = (_p = message.result) === null || _p === void 0 ? void 0 : _p.objects) === null || _q === void 0 ? void 0 : _q.map((object) => ((0, jsx_runtime_1.jsx)(common_1.MessageMetadataRenderer, { object: object.data }, object.taskId)))), message.error && (0, jsx_runtime_1.jsx)(MessageErrorView_1.default, { assistantId: assistantId, assistant: assistant, error: message.error })] })] })] }));
144
+ ((_q = (_p = message.result) === null || _p === void 0 ? void 0 : _p.objects) === null || _q === void 0 ? void 0 : _q.map((object) => ((0, jsx_runtime_1.jsx)(common_1.MessageMetadataRenderer, { object: object.data }, object.taskId)))), message.error && (0, jsx_runtime_1.jsx)(MessageErrorView_1.default, { page: page, error: message.error })] })] })] }));
145
+ }
146
+ function MessageItemWrapper(_a) {
147
+ var _b, _c, _d;
148
+ var { hideAvatar, assistant, agentMessage } = _a, props = __rest(_a, ["hideAvatar", "assistant", "agentMessage"]);
149
+ const [time] = (0, react_1.useState)(() => new Date().toISOString());
150
+ return ((0, jsx_runtime_1.jsx)(MessageItemContainer, Object.assign({}, props, { className: (0, css_1.cx)('ai-chat-message-item', hideAvatar && 'hide-avatar', props.className), children: agentMessage && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: (_c = assistant.release) === null || _c === void 0 ? void 0 : _c.logo }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, width: 0, children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [((_d = assistant.release) === null || _d === void 0 ? void 0 : _d.title) || assistant.name, (0, jsx_runtime_1.jsx)(MessageTime, { time: time })] })), agentMessage] })] })) })));
116
151
  }
152
+ exports.MessageItemWrapper = MessageItemWrapper;
117
153
  function MessageUserName({ children }) {
118
154
  return ((0, jsx_runtime_1.jsx)(material_1.Typography, { component: "div", noWrap: true, sx: {
119
155
  fontSize: 14,
@@ -21,15 +21,16 @@ const assistant_1 = require("../../state/assistant");
21
21
  const session_1 = require("../../state/session");
22
22
  const MessageItemView_1 = __importDefault(require("./MessageItemView"));
23
23
  function MessageListView(_a) {
24
- var { assistantId, sessionId } = _a, props = __rest(_a, ["assistantId", "sessionId"]);
25
- const [assistant] = (0, assistant_1.useAssistantState)({ assistantId });
26
- const [session, { messages = [] }] = (0, session_1.useSessionState)({ sessionId, required: true });
24
+ var { page } = _a, props = __rest(_a, ["page"]);
25
+ const [assistant] = (0, assistant_1.useAssistantState)(page);
26
+ const [session, { messages = [] }] = (0, session_1.useSessionState)({ sessionId: page.sessionId, required: true });
27
27
  const opener = (0, react_1.useMemo)(() => {
28
28
  var _a;
29
29
  const { openerMessage } = (_a = assistant.release) !== null && _a !== void 0 ? _a : {};
30
30
  if (openerMessage) {
31
31
  return {
32
32
  taskId: '',
33
+ assistantId: assistant.id,
33
34
  sessionId: session.id,
34
35
  createdAt: session.createdAt,
35
36
  updatedAt: session.createdAt,
@@ -40,8 +41,8 @@ function MessageListView(_a) {
40
41
  }, [assistant.release]);
41
42
  if (!session)
42
43
  return null;
43
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2.5 }, props, { children: [opener && (0, jsx_runtime_1.jsx)(MessageItemView_1.default, { assistantId: assistantId, assistant: assistant, message: opener }), messages.map((message) => {
44
- return ((0, jsx_runtime_1.jsx)(MessageItemView_1.default, { assistantId: assistantId, assistant: assistant, message: message }, message.taskId));
44
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2.5 }, props, { children: [opener && (0, jsx_runtime_1.jsx)(MessageItemView_1.default, { page: page, message: opener }), messages.map((message) => {
45
+ return (0, jsx_runtime_1.jsx)(MessageItemView_1.default, { page: page, message: message }, message.taskId);
45
46
  })] })));
46
47
  }
47
48
  exports.default = MessageListView;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ const jsx_runtime_1 = require("react/jsx-runtime");
15
+ const material_1 = require("@mui/material");
16
+ const react_1 = require("react");
17
+ const RadioField = (0, react_1.forwardRef)((_a, ref) => {
18
+ var _b;
19
+ var { readOnly, parameter, onChange } = _a, props = __rest(_a, ["readOnly", "parameter", "onChange"]);
20
+ return ((0, jsx_runtime_1.jsx)(material_1.RadioGroup, Object.assign({ ref: ref, row: true, onChange: (e) => onChange(e.target.value) }, props, { children: (_b = parameter === null || parameter === void 0 ? void 0 : parameter.options) === null || _b === void 0 ? void 0 : _b.map((option) => {
21
+ const checked = option.value === props.value;
22
+ return ((0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { label: option.label, disabled: readOnly, value: option.value, checked: checked, control: (0, jsx_runtime_1.jsx)(material_1.Radio, {}), sx: {
23
+ transition: 'all 0.3s linear',
24
+ ml: 0,
25
+ mr: 1,
26
+ my: 0.5,
27
+ py: 0.5,
28
+ px: 2.5,
29
+ border: 2,
30
+ borderColor: (theme) => (checked ? theme.palette.primary.main : (0, material_1.alpha)(theme.palette.primary.main, 0.3)),
31
+ borderRadius: 8,
32
+ '.MuiRadio-root': {
33
+ // hidden radio button
34
+ display: 'none',
35
+ },
36
+ } }, option.id));
37
+ }) })));
38
+ });
39
+ exports.default = RadioField;
@@ -17,7 +17,7 @@ const react_1 = require("react");
17
17
  const SelectField = (0, react_1.forwardRef)((_a, ref) => {
18
18
  var _b, _c, _d, _e;
19
19
  var { readOnly, parameter, onChange } = _a, props = __rest(_a, ["readOnly", "parameter", "onChange"]);
20
- return ((0, jsx_runtime_1.jsx)(material_1.TextField, Object.assign({ ref: ref, select: true, onChange: (e) => onChange(e.target.value) }, props, { InputProps: Object.assign(Object.assign({}, props.InputProps), { readOnly }), SelectProps: Object.assign(Object.assign({}, props.SelectProps), { MenuProps: Object.assign(Object.assign({}, (_b = props.SelectProps) === null || _b === void 0 ? void 0 : _b.MenuProps), { sx: Object.assign(Object.assign({}, (_d = (_c = props.SelectProps) === null || _c === void 0 ? void 0 : _c.MenuProps) === null || _d === void 0 ? void 0 : _d.sx), { '.MuiMenuItem-root': {
20
+ return ((0, jsx_runtime_1.jsx)(material_1.TextField, Object.assign({ ref: ref, select: true, onChange: (e) => onChange(e.target.value) }, props, { InputProps: Object.assign(Object.assign({}, props.InputProps), { readOnly }), SelectProps: Object.assign(Object.assign({}, props.SelectProps), { MenuProps: Object.assign(Object.assign({ disableScrollLock: true }, (_b = props.SelectProps) === null || _b === void 0 ? void 0 : _b.MenuProps), { sx: Object.assign(Object.assign({}, (_d = (_c = props.SelectProps) === null || _c === void 0 ? void 0 : _c.MenuProps) === null || _d === void 0 ? void 0 : _d.sx), { '.MuiMenuItem-root': {
21
21
  whiteSpace: 'pre-wrap',
22
22
  } }) }) }), children: (_e = parameter === null || parameter === void 0 ? void 0 : parameter.options) === null || _e === void 0 ? void 0 : _e.map((option) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: option.value, children: option.label }, option.id))) })));
23
23
  });
@@ -17,9 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  const jsx_runtime_1 = require("react/jsx-runtime");
18
18
  const LanguageField_1 = __importDefault(require("./LanguageField"));
19
19
  const NumberField_1 = __importDefault(require("./NumberField"));
20
+ const RadioField_1 = __importDefault(require("./RadioField"));
20
21
  const SelectField_1 = __importDefault(require("./SelectField"));
21
22
  const StringField_1 = __importDefault(require("./StringField"));
22
23
  function ParameterField(_a) {
24
+ var _b;
23
25
  var { parameter } = _a, props = __rest(_a, ["parameter"]);
24
26
  if (parameter.type === 'source')
25
27
  return null;
@@ -29,7 +31,9 @@ function ParameterField(_a) {
29
31
  const Field = {
30
32
  number: NumberField_1.default,
31
33
  string: StringField_1.default,
32
- select: SelectField_1.default,
34
+ select: parameter.type === 'select' && ((_b = parameter.options) === null || _b === void 0 ? void 0 : _b.length) && parameter.options.length <= 8
35
+ ? RadioField_1.default
36
+ : SelectField_1.default,
33
37
  language: LanguageField_1.default,
34
38
  }[parameter.type || 'string'] || StringField_1.default;
35
39
  return ((0, jsx_runtime_1.jsx)(Field, Object.assign({ label: parameter === null || parameter === void 0 ? void 0 : parameter.label, helperText: parameter === null || parameter === void 0 ? void 0 : parameter.helper, placeholder: parameter === null || parameter === void 0 ? void 0 : parameter.placeholder }, { parameter }, { size: "small" }, props)));