@blocklet/pages-kit 0.2.291 → 0.2.293

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
@@ -1,19 +1,8 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { jsx as _jsx } from "react/jsx-runtime";
11
2
  import { Stack } from '@mui/material';
12
- import { Suspense, useCallback, useEffect, useId, useMemo, useState } from 'react';
3
+ import { Suspense, useCallback, useEffect, useId, useState } from 'react';
13
4
  import { ErrorBoundary } from 'react-error-boundary';
14
5
  import { Toast } from '../../arcblock/ux';
15
- import { getQuery } from '../../utils';
16
- import { getAssistant } from './api/assistant';
17
6
  import { ChatBot as ChatBotWrapper } from './components/common';
18
7
  import RuntimeChat from './components/runtime-chat';
19
8
  import RuntimeForm from './components/runtime-form';
@@ -22,32 +11,29 @@ import ScrollView from './components/ScrollView';
22
11
  import CheckSession from './components/session/CheckSession';
23
12
  import { useSetHeader } from './hooks/header';
24
13
  import { useCurrentPage } from './hooks/navigate';
25
- import { createAssistantState, useAssistantState } from './state/assistant';
26
- import { parseIdentity } from './utils';
27
- export function getServerSideProps() {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const query = getQuery(globalThis.location.href);
30
- const assistantId = typeof query.assistantId === 'string' ? query.assistantId : undefined;
31
- const identity = assistantId ? parseIdentity(assistantId) : undefined;
32
- const assistant = identity && (yield getAssistant(identity));
33
- return { props: { preload: assistantId ? { assistantId, assistant } : undefined } };
34
- });
35
- }
14
+ import { useAssistantState } from './state/assistant';
15
+ export * from './components/runtime/contexts/CurrentAgent';
16
+ export * from './components/runtime/contexts/CurrentMessage';
17
+ export * from './components/runtime/state/runtime';
18
+ export * from './components/runtime/state/session';
19
+ export { default as Runtime } from './components/runtime';
20
+ export { default as SimplePage } from './components/runtime/components/SimplePage';
21
+ export { default as SimpleChat } from './components/runtime/components/SimpleChat';
22
+ export { default as PhotoGallery } from './components/runtime/components/PhotoGallery';
23
+ export { default as AutoForm } from './components/runtime/components/AutoForm';
24
+ export { default as BaseOutputs } from './components/runtime/components/SimpleOutput';
25
+ export { default as ChatOutput } from './components/runtime/components/ChatOutput';
26
+ export { default as PhotoGalleryItem } from './components/runtime/components/PhotoGalleryItem';
36
27
  export default function App(props) {
37
28
  const cacheId = useId();
38
29
  return (_jsx(RuntimeProvider, { children: _jsx(AIRuntime, Object.assign({}, props, { cacheId: cacheId })) }));
39
30
  }
40
- function AIRuntime({ cacheId, preload }) {
31
+ export function AIRuntime({ cacheId }) {
41
32
  var _a;
42
33
  const page = useCurrentPage();
43
34
  const { assistantId } = page;
44
35
  const [assistant] = useAssistantState({ assistantId });
45
36
  useSetHeader({ assistant, assistantId });
46
- useMemo(() => {
47
- // preload assistant from server side props
48
- if (preload)
49
- createAssistantState(preload);
50
- }, []);
51
37
  return (_jsx(CheckSession, { cacheId: cacheId, page: page, children: _jsx(ScrollView, { scroller: "window", initialScrollBehavior: "auto", children: _jsx(Stack, { flexGrow: 1, height: "100%", className: "ai-runtime-root", children: ((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.template) === 'form' ? _jsx(RuntimeForm, { page: page }) : _jsx(RuntimeChat, { page: page }) }) }) }));
52
38
  }
53
39
  export function ChatBot(props) {
@@ -11,6 +11,12 @@ export const translations = {
11
11
  shareToLinkedin: 'Share to Linkedin',
12
12
  copyLink: 'Copy Link',
13
13
  },
14
+ photoWall: {
15
+ dialog: {
16
+ title: 'AI Art Image',
17
+ prompt: 'Prompt',
18
+ },
19
+ },
14
20
  questionPlaceholder: 'Ask Anything...',
15
21
  parameters: 'Parameters',
16
22
  parametersTitle: 'Tell me what do you want?',
@@ -50,6 +56,12 @@ export const translations = {
50
56
  Subscribe now to unlock more possibilities!`,
51
57
  requireNewSubscriptionFooter: 'You need to subscribe to access this feature:',
52
58
  thanksForSubscription: 'Thanks for subscribing, now you can start enjoying it!',
59
+ requireLogin: `Thank you for using our service!
60
+
61
+ In order to use our service properly, please click below to log in now!
62
+ `,
63
+ thanksForLogin: 'Now you can start experiencing it to the fullest!',
64
+ loginNow: 'Login Now',
53
65
  clickTheButton: 'Click The Button 👉',
54
66
  cleanSessionTip: 'Clean conversation messages',
55
67
  poweredBy: 'Powered by',
@@ -74,6 +86,8 @@ export const translations = {
74
86
  uploadFile: 'Upload File',
75
87
  submit: 'Submit',
76
88
  send: 'Send',
89
+ session: 'Session',
90
+ loadMore: 'Load More',
77
91
  },
78
92
  zh: {
79
93
  by: '来自',
@@ -87,6 +101,12 @@ export const translations = {
87
101
  shareToLinkedin: '分享到 Linkedin',
88
102
  copyLink: '复制链接',
89
103
  },
104
+ photoWall: {
105
+ dialog: {
106
+ title: 'AI 艺术图片',
107
+ prompt: '提示词',
108
+ },
109
+ },
90
110
  questionPlaceholder: '问点什么...',
91
111
  parameters: '参数',
92
112
  parametersTitle: '告诉我你想要什么?',
@@ -126,6 +146,12 @@ export const translations = {
126
146
  立即订阅以解锁更多可能性!`,
127
147
  requireNewSubscriptionFooter: '您需要订阅才能访问此功能:',
128
148
  thanksForSubscription: '感谢您的订阅,现在,您可以开始尽情体验了!',
149
+ requireLogin: `感谢您使用我们的服务!
150
+
151
+ 为了能正常使用我们的服务,请点击下方立即登录!
152
+ `,
153
+ thanksForLogin: '现在,您可以开始尽情体验了!',
154
+ loginNow: '立即登录',
129
155
  clickTheButton: '点我生成 👉',
130
156
  cleanSessionTip: '清除会话消息记录',
131
157
  poweredBy: '技术支持来自',
@@ -150,5 +176,7 @@ export const translations = {
150
176
  uploadFile: '上传文件',
151
177
  submit: '提交',
152
178
  send: '发送',
179
+ session: '会话',
180
+ loadMore: '加载更多',
153
181
  },
154
182
  };
@@ -14,11 +14,11 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
14
14
  function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
15
15
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
16
16
  };
17
- import { RuntimeOutputVariableNames } from '@blocklet/ai-runtime/types';
17
+ import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
18
18
  import pick from 'lodash/pick';
19
19
  import { create } from 'zustand';
20
20
  import { immer } from 'zustand/middleware/immer';
21
- import { deleteMessages, getMessages } from '../api/message';
21
+ import { getMessages } from '../api/message';
22
22
  import { getSession, runAssistant, updateSession } from '../api/session';
23
23
  import { deepMerge, parseIdentity } from '../utils';
24
24
  const STATES = {};
@@ -26,11 +26,7 @@ export const createSessionState = ({ sessionId, session }) => {
26
26
  var _a;
27
27
  (_a = STATES[sessionId]) !== null && _a !== void 0 ? _a : (STATES[sessionId] = create()(immer((set, get) => ({
28
28
  session,
29
- clearSession: (_b) => __awaiter(void 0, [_b], void 0, function* ({ sessionId }) {
30
- yield deleteMessages({ sessionId });
31
- yield get().load();
32
- }),
33
- updateSession: (_c) => __awaiter(void 0, [_c], void 0, function* ({ parameters }) {
29
+ updateSession: (_b) => __awaiter(void 0, [_b], void 0, function* ({ parameters }) {
34
30
  const { updated } = yield updateSession({ sessionId, parameters });
35
31
  set((state) => {
36
32
  state.session = updated;
@@ -62,9 +58,9 @@ export const createSessionState = ({ sessionId, session }) => {
62
58
  });
63
59
  }
64
60
  }),
65
- execute: (_d) => __awaiter(void 0, [_d], void 0, function* ({ assistantId, parameters, onResponseStart, includeSessionParameters, }) {
66
- var _e, e_1, _f, _g;
67
- var _h, _j, _k, _l, _m;
61
+ execute: (_c) => __awaiter(void 0, [_c], void 0, function* ({ assistantId, parameters, onResponseStart, includeSessionParameters, }) {
62
+ var _d, e_1, _e, _f;
63
+ var _g, _h, _j, _k, _l;
68
64
  const identity = parseIdentity(assistantId, { rejectWhenError: true });
69
65
  let message;
70
66
  const childMessages = [];
@@ -75,7 +71,7 @@ export const createSessionState = ({ sessionId, session }) => {
75
71
  });
76
72
  let realParameters = Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() });
77
73
  if (includeSessionParameters) {
78
- realParameters = Object.assign(Object.assign({}, (_h = get().session) === null || _h === void 0 ? void 0 : _h.parameters), parameters);
74
+ realParameters = Object.assign(Object.assign({}, (_g = get().session) === null || _g === void 0 ? void 0 : _g.parameters), parameters);
79
75
  }
80
76
  try {
81
77
  const stream = runAssistant({
@@ -85,10 +81,10 @@ export const createSessionState = ({ sessionId, session }) => {
85
81
  });
86
82
  let responseStarted = false;
87
83
  try {
88
- for (var _o = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _e = stream_1_1.done, !_e; _o = true) {
89
- _g = stream_1_1.value;
90
- _o = false;
91
- const value = _g;
84
+ for (var _m = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _d = stream_1_1.done, !_d; _m = true) {
85
+ _f = stream_1_1.value;
86
+ _m = false;
87
+ const value = _f;
92
88
  if (!responseStarted) {
93
89
  responseStarted = true;
94
90
  onResponseStart === null || onResponseStart === void 0 ? void 0 : onResponseStart();
@@ -98,6 +94,7 @@ export const createSessionState = ({ sessionId, session }) => {
98
94
  message = {
99
95
  taskId: value.taskId,
100
96
  sessionId,
97
+ assistantId: identity.assistantId,
101
98
  parameters,
102
99
  createdAt: new Date().toISOString(),
103
100
  updatedAt: new Date().toISOString(),
@@ -126,7 +123,7 @@ export const createSessionState = ({ sessionId, session }) => {
126
123
  msg.result.objects.push({ taskId: value.taskId, data: value.delta.object });
127
124
  if (value.delta.object) {
128
125
  (_g = state.metadata) !== null && _g !== void 0 ? _g : (state.metadata = {});
129
- deepMerge(state.metadata, pick(value.delta.object, RuntimeOutputVariableNames));
126
+ deepMerge(state.metadata, pick(value.delta.object, Object.values(RuntimeOutputVariable)));
130
127
  }
131
128
  }
132
129
  });
@@ -141,10 +138,10 @@ export const createSessionState = ({ sessionId, session }) => {
141
138
  childMessagesMap[value.taskId] = childMessage;
142
139
  childMessages.push(childMessage);
143
140
  }
144
- (_j = childMessage.result) !== null && _j !== void 0 ? _j : (childMessage.result = {});
141
+ (_h = childMessage.result) !== null && _h !== void 0 ? _h : (childMessage.result = {});
145
142
  childMessage.result.content = (childMessage.result.content || '') + (value.delta.content || '');
146
- if ((_l = (_k = value.delta) === null || _k === void 0 ? void 0 : _k.images) === null || _l === void 0 ? void 0 : _l.length) {
147
- childMessage.result.images = ((_m = childMessage.result.images) !== null && _m !== void 0 ? _m : []).concat(value.delta.images);
143
+ if ((_k = (_j = value.delta) === null || _j === void 0 ? void 0 : _j.images) === null || _k === void 0 ? void 0 : _k.length) {
144
+ childMessage.result.images = ((_l = childMessage.result.images) !== null && _l !== void 0 ? _l : []).concat(value.delta.images);
148
145
  }
149
146
  set((state) => {
150
147
  var _a, _b;
@@ -171,7 +168,7 @@ export const createSessionState = ({ sessionId, session }) => {
171
168
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
172
169
  finally {
173
170
  try {
174
- if (!_o && !_e && (_f = stream_1.return)) yield _f.call(stream_1);
171
+ if (!_m && !_d && (_e = stream_1.return)) yield _e.call(stream_1);
175
172
  }
176
173
  finally { if (e_1) throw e_1.error; }
177
174
  }
@@ -11,7 +11,7 @@ import { create } from 'zustand';
11
11
  import { immer } from 'zustand/middleware/immer';
12
12
  import { getRelease, getSubscription } from '../api/subscription';
13
13
  const STATES = {};
14
- export const createAssistantState = ({ aid }) => {
14
+ export const createSubscriptionState = ({ aid }) => {
15
15
  var _a;
16
16
  (_a = STATES[aid]) !== null && _a !== void 0 ? _a : (STATES[aid] = create()(immer((set) => ({
17
17
  load: () => __awaiter(void 0, void 0, void 0, function* () {
@@ -38,7 +38,7 @@ export const createAssistantState = ({ aid }) => {
38
38
  const LOADING_TASKS = {};
39
39
  export function useSubscriptionState({ aid }) {
40
40
  var _a;
41
- const state = createAssistantState({ aid })();
41
+ const state = createSubscriptionState({ aid })();
42
42
  if (!state.loaded && !state.subscription) {
43
43
  (_a = LOADING_TASKS[aid]) !== null && _a !== void 0 ? _a : (LOADING_TASKS[aid] = state.load());
44
44
  throw LOADING_TASKS[aid];
@@ -10,7 +10,6 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import '../../utils/inject-global-components';
14
13
  import { Alert, Box } from '@mui/material';
15
14
  import { ErrorBoundary } from 'react-error-boundary';
16
15
  import { RenderNestedComponent } from '../../utils/property';
@@ -26,61 +26,65 @@ import { PreloadComponentScriptModule } from '../../types';
26
26
  import { PreloadComponentsStateGlobalVariableName } from '../../types/preload';
27
27
  import { mergeComponent } from '../../utils/property';
28
28
  const PRELOAD_COMPONENTS_STATE = window[PreloadComponentsStateGlobalVariableName];
29
- export const customComponentStates = create()(immer((set, get) => ({
30
- state: {
31
- config: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.config),
32
- components: Object.fromEntries(Object.entries(Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.components)).map(([componentId, preload]) => {
33
- let Component;
34
- if (preload.componentModuleGlobalVariable) {
35
- const m = window[preload.componentModuleGlobalVariable];
36
- if (typeof m === 'function')
37
- Component = m();
29
+ let states;
30
+ export const customComponentStates = () => {
31
+ states !== null && states !== void 0 ? states : (states = create()(immer((set, get) => ({
32
+ state: {
33
+ config: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.config),
34
+ components: Object.fromEntries(Object.entries(Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.components)).map(([componentId, preload]) => {
35
+ let Component;
36
+ if (preload.componentModuleGlobalVariable) {
37
+ const m = window[preload.componentModuleGlobalVariable];
38
+ if (typeof m === 'function')
39
+ Component = m();
40
+ }
41
+ return [componentId, Object.assign(Object.assign({}, preload), { Component })];
42
+ })),
43
+ instances: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.instances),
44
+ },
45
+ getComponent({ instanceId, componentId, locale }) {
46
+ var _a, _b;
47
+ const { config: { supportedLocales }, components, instances, } = get().state;
48
+ if (!(supportedLocales === null || supportedLocales === void 0 ? void 0 : supportedLocales.some((i) => i.locale === locale)))
49
+ return null;
50
+ const c = components[componentId];
51
+ if (!c)
52
+ return null;
53
+ const { component, Component } = c;
54
+ if (!Component)
55
+ return null;
56
+ if (!instanceId) {
57
+ return { component, Component };
38
58
  }
39
- return [componentId, Object.assign(Object.assign({}, preload), { Component })];
40
- })),
41
- instances: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.instances),
42
- },
43
- getComponent({ instanceId, componentId, locale }) {
44
- var _a, _b;
45
- const { config: { supportedLocales }, components, instances, } = get().state;
46
- if (!(supportedLocales === null || supportedLocales === void 0 ? void 0 : supportedLocales.some((i) => i.locale === locale)))
47
- return null;
48
- const c = components[componentId];
49
- if (!c)
50
- return null;
51
- const { component, Component } = c;
52
- if (!Component)
53
- return null;
54
- if (!instanceId) {
55
- return { component, Component };
56
- }
57
- const instance = instances[instanceId];
58
- if (!instance)
59
- return null;
60
- const props = (_b = (_a = instance.locales) === null || _a === void 0 ? void 0 : _a[locale]) === null || _b === void 0 ? void 0 : _b.props;
61
- if (!props)
62
- return null;
63
- return { component, Component, props };
64
- },
65
- loadComponents(input) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const result = yield loadComponents(input);
68
- if (result) {
69
- set((s) => {
70
- s.state.config = result.config;
71
- Object.assign(s.state.components, result.components);
72
- Object.entries(result.instances).forEach(([instanceId, instance]) => {
73
- var _a, _b;
74
- var _c, _d;
75
- (_a = (_c = s.state.instances)[instanceId]) !== null && _a !== void 0 ? _a : (_c[instanceId] = { componentId: instance.componentId });
76
- (_b = (_d = s.state.instances[instanceId]).locales) !== null && _b !== void 0 ? _b : (_d.locales = {});
77
- Object.assign(s.state.instances[instanceId].locales, instance.locales);
59
+ const instance = instances[instanceId];
60
+ if (!instance)
61
+ return null;
62
+ const props = (_b = (_a = instance.locales) === null || _a === void 0 ? void 0 : _a[locale]) === null || _b === void 0 ? void 0 : _b.props;
63
+ if (!props)
64
+ return null;
65
+ return { component, Component, props };
66
+ },
67
+ loadComponents(input) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const result = yield loadComponents(input);
70
+ if (result) {
71
+ set((s) => {
72
+ s.state.config = result.config;
73
+ Object.assign(s.state.components, result.components);
74
+ Object.entries(result.instances).forEach(([instanceId, instance]) => {
75
+ var _a, _b;
76
+ var _c, _d;
77
+ (_a = (_c = s.state.instances)[instanceId]) !== null && _a !== void 0 ? _a : (_c[instanceId] = { componentId: instance.componentId });
78
+ (_b = (_d = s.state.instances[instanceId]).locales) !== null && _b !== void 0 ? _b : (_d.locales = {});
79
+ Object.assign(s.state.instances[instanceId].locales, instance.locales);
80
+ });
78
81
  });
79
- });
80
- }
81
- });
82
- },
83
- })));
82
+ }
83
+ });
84
+ },
85
+ }))));
86
+ return states;
87
+ };
84
88
  function loadComponents(input) {
85
89
  return __awaiter(this, void 0, void 0, function* () {
86
90
  const result = yield preloadComponents(Object.assign(Object.assign({}, input), { module: PreloadComponentScriptModule.ESM }));
@@ -123,17 +127,19 @@ const COMPONENT_LOADER_MAP = {};
123
127
  function usePreloadComponent({ instanceId, componentId, properties, locale, dev }) {
124
128
  var _a;
125
129
  const previousRef = useRef();
126
- const requestLocale = customComponentStates((s) => { var _a; return ((_a = s.state.config.supportedLocales) === null || _a === void 0 ? void 0 : _a.some((i) => i.locale === locale)) ? locale : undefined; });
127
- const defaultLocale = customComponentStates((s) => s.state.config.defaultLocale);
130
+ const requestLocale = customComponentStates()((s) => { var _a; return ((_a = s.state.config.supportedLocales) === null || _a === void 0 ? void 0 : _a.some((i) => i.locale === locale)) ? locale : undefined; });
131
+ const defaultLocale = customComponentStates()((s) => s.state.config.defaultLocale);
128
132
  const realLocale = requestLocale || defaultLocale;
129
- const result = customComponentStates((s) => realLocale ? s.getComponent({ instanceId, componentId, locale: realLocale }) : undefined);
133
+ const result = customComponentStates()((s) => realLocale ? s.getComponent({ instanceId, componentId, locale: realLocale }) : undefined);
130
134
  if (result) {
131
135
  previousRef.current = result;
132
136
  return result;
133
137
  }
134
138
  if (realLocale && instanceId) {
135
139
  const key = [instanceId, realLocale].join('-');
136
- (_a = COMPONENT_LOADER_MAP[key]) !== null && _a !== void 0 ? _a : (COMPONENT_LOADER_MAP[key] = customComponentStates.getState().loadComponents({
140
+ (_a = COMPONENT_LOADER_MAP[key]) !== null && _a !== void 0 ? _a : (COMPONENT_LOADER_MAP[key] = customComponentStates()
141
+ .getState()
142
+ .loadComponents({
137
143
  mode: dev === null || dev === void 0 ? void 0 : dev.mode,
138
144
  locale: realLocale,
139
145
  instances: [{ id: instanceId, component: { id: componentId }, properties }],
@@ -1,2 +1,3 @@
1
+ import '../utils/inject-global-components';
1
2
  export { default as CustomComponentRenderer } from './CustomComponentRenderer';
2
3
  export * from './CustomComponentRenderer';
@@ -1,9 +1,10 @@
1
- import { AssistantBase, Parameter } from '@blocklet/ai-runtime/types';
1
+ import { AssistantBase, OutputVariable, Parameter } from '@blocklet/ai-runtime/types';
2
2
  export interface Assistant {
3
3
  id: string;
4
4
  name?: string;
5
5
  description?: string;
6
6
  parameters?: Parameter[];
7
+ outputVariables?: OutputVariable[];
7
8
  entries?: {
8
9
  id: string;
9
10
  title?: string;
@@ -14,6 +15,7 @@ export interface Assistant {
14
15
  release?: AssistantBase['release'];
15
16
  createdBy?: string;
16
17
  }
17
- export declare function getAssistant({ assistantId: id }: {
18
+ export declare function getAssistant({ assistantId: id, working, }: {
18
19
  assistantId: string;
20
+ working?: boolean;
19
21
  }): Promise<Assistant>;
@@ -2,6 +2,7 @@ import { ExecuteBlock, RuntimeOutputVariablesSchema } from '@blocklet/ai-runtime
2
2
  export interface Message {
3
3
  id: string;
4
4
  taskId: string;
5
+ assistantId: string;
5
6
  sessionId: string;
6
7
  createdAt: string;
7
8
  updatedAt: string;
@@ -28,9 +29,15 @@ export interface Message {
28
29
  message: string;
29
30
  };
30
31
  }
31
- export declare function getMessages({ sessionId, }: {
32
+ export interface GetMessagesQuery {
33
+ limit?: number;
34
+ before?: string;
35
+ after?: string;
36
+ orderDirection?: 'asc' | 'desc';
37
+ }
38
+ export declare function getMessages({ sessionId, ...query }: {
32
39
  sessionId: string;
33
- }): Promise<{
40
+ } & GetMessagesQuery): Promise<{
34
41
  messages: Message[];
35
42
  count: number;
36
43
  }>;
@@ -1,5 +1,8 @@
1
1
  export declare const fetch: (input: string | URL | Request, options?: RequestInit | undefined) => Promise<Response>;
2
- export declare function request<T>({ url, body, ...init }: {
2
+ export declare function request<T>({ url, query, body, ...init }: {
3
3
  url: string;
4
+ query?: {
5
+ [key: string]: any;
6
+ };
4
7
  body?: any;
5
8
  } & Omit<RequestInit, 'body'>): Promise<T>;
@@ -47,8 +47,9 @@ export declare function deleteSession({ sessionId, }: {
47
47
  deleted: Session;
48
48
  sessions: Session[];
49
49
  }>;
50
- export declare function runAssistant({ sessionId, identity, parameters, }: {
50
+ export declare function runAssistant({ sessionId, identity, working, parameters, }: {
51
51
  sessionId: string;
52
52
  identity: Identity;
53
+ working?: boolean;
53
54
  parameters: any;
54
55
  }): AsyncGenerator<RunAssistantResponse, void, unknown>;
@@ -1,6 +1,7 @@
1
1
  import { Assistant } from '../../api/assistant';
2
- export default function ParameterForm({ sessionId, disabled, readOnly, onSubmit, defaultValues, hideSubmit, isSubmitting, assistant, submitButtonTitle, }: {
3
- sessionId?: string;
2
+ import { PageState } from '../../hooks/navigate';
3
+ export default function ParameterForm({ page, disabled, readOnly, onSubmit, defaultValues, hideSubmit, isSubmitting, assistant, submitButtonTitle, }: {
4
+ page: PageState;
4
5
  disabled?: boolean;
5
6
  readOnly?: boolean;
6
7
  onSubmit?: (parameters: any) => any;
@@ -1,7 +1,8 @@
1
1
  import { UseFormReturn } from 'react-hook-form';
2
2
  import { Assistant } from '../../api/assistant';
3
- export default function QuestionField({ sessionId, assistant, showSettingButton, form, isSubmitting, autoFocus, readOnly, disabled, submitButtonTitle, }: {
4
- sessionId?: string;
3
+ import { PageState } from '../../hooks/navigate';
4
+ export default function QuestionField({ page, assistant, showSettingButton, form, isSubmitting, autoFocus, readOnly, disabled, submitButtonTitle, }: {
5
+ page: PageState;
5
6
  assistant: Assistant;
6
7
  readOnly?: boolean;
7
8
  disabled?: boolean;
@@ -1,6 +1,9 @@
1
1
  import { ButtonProps } from '@mui/material';
2
2
  import { UseFormReturn } from 'react-hook-form';
3
- export default function SettingButton({ sessionId, form, ...props }: {
4
- sessionId: string;
3
+ import { PageState } from '../../hooks/navigate';
4
+ export default function SettingButton({ page, form, ...props }: {
5
+ page: PageState & {
6
+ sessionId: string;
7
+ };
5
8
  form: UseFormReturn<any>;
6
9
  } & Omit<ButtonProps, 'form'>): import("react/jsx-runtime").JSX.Element[];
@@ -1,6 +1,5 @@
1
- import { Assistant } from '../../api/assistant';
2
- export default function MessageErrorView({ assistantId, assistant, error, }: {
3
- assistantId: string;
4
- assistant: Assistant;
1
+ import { PageState } from '../../hooks/navigate';
2
+ export default function MessageErrorView({ page, error }: {
3
+ page: PageState;
5
4
  error: any;
6
- }): import("react/jsx-runtime").JSX.Element;
5
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -1,8 +1,15 @@
1
+ import { StackProps } from '@mui/material';
2
+ import { ReactNode } from 'react';
1
3
  import { Assistant } from '../../api/assistant';
4
+ import { PageState } from '../../hooks/navigate';
2
5
  import { MessageItem } from '../../state/session';
3
- export default function MessageItemView({ assistantId, assistant, message, hideAvatar, }: {
4
- assistantId: string;
5
- assistant: Assistant;
6
+ export default function MessageItemView({ page, message, hideAvatar, ...props }: {
7
+ page: PageState;
6
8
  message: MessageItem;
7
9
  hideAvatar?: boolean;
8
- }): import("react/jsx-runtime").JSX.Element;
10
+ } & StackProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function MessageItemWrapper({ hideAvatar, assistant, agentMessage, ...props }: {
12
+ hideAvatar?: boolean;
13
+ assistant: Assistant;
14
+ agentMessage?: ReactNode;
15
+ } & StackProps): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,7 @@
1
1
  import { StackProps } from '@mui/material';
2
- export default function MessageListView({ assistantId, sessionId, ...props }: {
3
- assistantId: string;
4
- sessionId: string;
2
+ import { PageState } from '../../hooks/navigate';
3
+ export default function MessageListView({ page, ...props }: {
4
+ page: PageState & {
5
+ page: 'session';
6
+ };
5
7
  } & StackProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { SelectParameter } from '@blocklet/ai-runtime/types';
3
+ import { RadioGroupProps } from '@mui/material';
4
+ declare const RadioField: import("react").ForwardRefExoticComponent<Omit<{
5
+ readOnly?: boolean | undefined;
6
+ parameter?: SelectParameter | undefined;
7
+ onChange: (value: string) => void;
8
+ } & Omit<RadioGroupProps, "onChange">, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
9
+ export default RadioField;
@@ -0,0 +1,9 @@
1
+ import { Parameter } from '@blocklet/ai-runtime/types';
2
+ export declare const SUPPORTED_PARAMETER_TYPES: NonNullable<Parameter['type']>[];
3
+ export default function AutoForm({ submitText, inlineLabel, autoFillLastForm, submitInQuestionField, chatMode, }: {
4
+ submitText?: string;
5
+ inlineLabel?: boolean;
6
+ autoFillLastForm?: boolean;
7
+ submitInQuestionField?: boolean;
8
+ chatMode?: boolean;
9
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ export default function MessageErrorView({ error }: {
2
+ error: any;
3
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,12 @@
1
+ import { StackProps } from '@mui/material';
2
+ import React, { ReactNode } from 'react';
3
+ import { MessageItem } from '../../state/session';
4
+ declare const MessageItemView: React.MemoExoticComponent<({ message, hideAvatar, ...props }: {
5
+ message: MessageItem;
6
+ hideAvatar?: boolean;
7
+ } & StackProps) => import("react/jsx-runtime").JSX.Element>;
8
+ export default MessageItemView;
9
+ export declare function MessageItemWrapper({ hideAvatar, agentMessage, ...props }: {
10
+ hideAvatar?: boolean;
11
+ agentMessage?: ReactNode;
12
+ } & StackProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export default function ChatOutput(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,5 @@
1
+ export default function PhotoGallery({ resultTitle, background, primaryColor, }: {
2
+ resultTitle?: string;
3
+ background?: string;
4
+ primaryColor?: string;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export default function PhotoGalleryItem(): import("react/jsx-runtime").JSX.Element[];
@@ -0,0 +1,3 @@
1
+ export default function SimpleChat({ primaryColor }: {
2
+ primaryColor?: string;
3
+ }): import("react/jsx-runtime").JSX.Element;