@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.
- package/lib/cjs/builtin/async/ai-runtime/api/assistant.js +2 -1
- package/lib/cjs/builtin/async/ai-runtime/api/message.js +14 -1
- package/lib/cjs/builtin/async/ai-runtime/api/request.js +5 -3
- package/lib/cjs/builtin/async/ai-runtime/api/session.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/components/PoweredBy.js +1 -9
- package/lib/cjs/builtin/async/ai-runtime/components/RuntimeProvider.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +4 -4
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormFields.js +5 -1
- package/lib/cjs/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/components/form/SettingButton.js +16 -9
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +14 -3
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +65 -29
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +6 -5
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/RadioField.js +39 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/SelectField.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +5 -1
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.js +153 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.js +19 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.js +179 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.js +13 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.js +129 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.js +117 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.js +109 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.js +17 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.js +87 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.js +27 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.js +19 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/index.js +42 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/assistant.js +61 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/runtime.js +56 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/session.js +213 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/utils/map-right.js +10 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +42 -20
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +12 -5
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +5 -6
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +3 -6
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +4 -0
- package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +16 -7
- package/lib/cjs/builtin/async/ai-runtime/hooks/auth.js +31 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +29 -19
- package/lib/cjs/builtin/async/ai-runtime/hooks/subscribe.js +6 -4
- package/lib/cjs/builtin/async/ai-runtime/index.js +38 -30
- package/lib/cjs/builtin/async/ai-runtime/locales/index.js +28 -0
- package/lib/cjs/builtin/async/ai-runtime/state/session.js +15 -18
- package/lib/cjs/builtin/async/ai-runtime/state/subscription.js +4 -4
- package/lib/cjs/components/CustomComponentRenderer/index.js +0 -1
- package/lib/cjs/components/CustomComponentRenderer/state.js +64 -57
- package/lib/cjs/components/index.js +1 -0
- package/lib/esm/builtin/async/ai-runtime/api/assistant.js +2 -1
- package/lib/esm/builtin/async/ai-runtime/api/message.js +14 -1
- package/lib/esm/builtin/async/ai-runtime/api/request.js +5 -3
- package/lib/esm/builtin/async/ai-runtime/api/session.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/PoweredBy.js +2 -10
- package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +4 -4
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +5 -1
- package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +16 -9
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageErrorView.js +14 -3
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +65 -31
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +6 -5
- package/lib/esm/builtin/async/ai-runtime/components/parameters/RadioField.js +37 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/SelectField.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/parameters/index.js +5 -1
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.js +146 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.js +13 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.js +149 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.js +7 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.js +100 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.js +114 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.js +80 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.js +11 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.js +58 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.js +14 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/index.js +36 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/state/assistant.js +56 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/state/runtime.js +52 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/state/session.js +209 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/utils/map-right.js +7 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +21 -22
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +13 -6
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +5 -6
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +3 -6
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +4 -0
- package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +9 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/auth.js +27 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/header.js +30 -20
- package/lib/esm/builtin/async/ai-runtime/hooks/subscribe.js +6 -4
- package/lib/esm/builtin/async/ai-runtime/index.js +15 -29
- package/lib/esm/builtin/async/ai-runtime/locales/index.js +28 -0
- package/lib/esm/builtin/async/ai-runtime/state/session.js +17 -20
- package/lib/esm/builtin/async/ai-runtime/state/subscription.js +2 -2
- package/lib/esm/components/CustomComponentRenderer/index.js +0 -1
- package/lib/esm/components/CustomComponentRenderer/state.js +63 -57
- package/lib/esm/components/index.js +1 -0
- package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +4 -2
- package/lib/types/builtin/async/ai-runtime/api/message.d.ts +9 -2
- package/lib/types/builtin/async/ai-runtime/api/request.d.ts +4 -1
- package/lib/types/builtin/async/ai-runtime/api/session.d.ts +2 -1
- package/lib/types/builtin/async/ai-runtime/components/form/ParameterForm.d.ts +3 -2
- package/lib/types/builtin/async/ai-runtime/components/form/QuestionField.d.ts +3 -2
- package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +5 -2
- package/lib/types/builtin/async/ai-runtime/components/message/MessageErrorView.d.ts +4 -5
- package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +11 -4
- package/lib/types/builtin/async/ai-runtime/components/message/MessageListView.d.ts +5 -3
- package/lib/types/builtin/async/ai-runtime/components/parameters/RadioField.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.d.ts +12 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.d.ts +12 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.d.ts +10 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/state/assistant.d.ts +17 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/state/runtime.d.ts +14 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/state/session.d.ts +29 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/utils/map-right.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/hooks/auth.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/hooks/subscribe.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +15 -8
- package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +22 -0
- package/lib/types/builtin/async/ai-runtime/state/assistant.d.ts +0 -2
- package/lib/types/builtin/async/ai-runtime/state/session.d.ts +0 -3
- package/lib/types/builtin/async/ai-runtime/state/subscription.d.ts +1 -1
- package/lib/types/components/CustomComponentRenderer/index.d.ts +0 -1
- package/lib/types/components/CustomComponentRenderer/state.d.ts +2 -3
- package/lib/types/components/index.d.ts +1 -0
- package/lib/types/types/core.d.ts +1 -0
- package/package.json +9 -7
|
@@ -0,0 +1,209 @@
|
|
|
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
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
11
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
12
|
+
var m = o[Symbol.asyncIterator], i;
|
|
13
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
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
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
|
+
};
|
|
17
|
+
import { create } from 'zustand';
|
|
18
|
+
import { immer } from 'zustand/middleware/immer';
|
|
19
|
+
import { getMessages } from '../../../api/message';
|
|
20
|
+
import { createSession, getSessions, runAssistant } from '../../../api/session';
|
|
21
|
+
import { parseIdentity } from '../../../utils';
|
|
22
|
+
const STATES = {};
|
|
23
|
+
const GET_MESSAGES_LIMIT = 100;
|
|
24
|
+
const GET_MESSAGES_ORDER_DIRECTION = 'desc';
|
|
25
|
+
export const createSessionState = ({ aid }) => {
|
|
26
|
+
var _a;
|
|
27
|
+
(_a = STATES[aid]) !== null && _a !== void 0 ? _a : (STATES[aid] = create()(immer((set, get) => ({
|
|
28
|
+
reset: () => {
|
|
29
|
+
set((state) => {
|
|
30
|
+
state.loading = undefined;
|
|
31
|
+
state.loaded = undefined;
|
|
32
|
+
state.running = undefined;
|
|
33
|
+
state.session = undefined;
|
|
34
|
+
state.messages = undefined;
|
|
35
|
+
state.noMoreMessage = undefined;
|
|
36
|
+
state.messageLoading = undefined;
|
|
37
|
+
state.error = undefined;
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
load: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
var _b;
|
|
42
|
+
set((state) => {
|
|
43
|
+
state.loading = true;
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
const { sessions } = yield getSessions(parseIdentity(aid, { rejectWhenError: true }));
|
|
47
|
+
const session = (_b = sessions[0]) !== null && _b !== void 0 ? _b : (yield createSession({ assistantId: aid })).created;
|
|
48
|
+
const { messages } = yield getMessages({
|
|
49
|
+
sessionId: session.id,
|
|
50
|
+
orderDirection: GET_MESSAGES_ORDER_DIRECTION,
|
|
51
|
+
limit: GET_MESSAGES_LIMIT,
|
|
52
|
+
});
|
|
53
|
+
set((state) => {
|
|
54
|
+
state.session = session;
|
|
55
|
+
state.messages = messages.toReversed();
|
|
56
|
+
state.noMoreMessage = messages.length < GET_MESSAGES_LIMIT;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
set((state) => {
|
|
61
|
+
state.error = error;
|
|
62
|
+
});
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
set((state) => {
|
|
67
|
+
state.loaded = true;
|
|
68
|
+
state.loading = false;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
loadMoreMessages: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
var _c;
|
|
74
|
+
set((state) => {
|
|
75
|
+
state.messageLoading = true;
|
|
76
|
+
});
|
|
77
|
+
const { session, messages } = get();
|
|
78
|
+
if (!session)
|
|
79
|
+
return;
|
|
80
|
+
try {
|
|
81
|
+
const result = yield getMessages({
|
|
82
|
+
sessionId: session.id,
|
|
83
|
+
before: (_c = messages === null || messages === void 0 ? void 0 : messages.slice(-1)[0]) === null || _c === void 0 ? void 0 : _c.id,
|
|
84
|
+
orderDirection: GET_MESSAGES_ORDER_DIRECTION,
|
|
85
|
+
limit: GET_MESSAGES_LIMIT,
|
|
86
|
+
});
|
|
87
|
+
set((state) => {
|
|
88
|
+
var _a;
|
|
89
|
+
state.messages = ((_a = state.messages) !== null && _a !== void 0 ? _a : []).concat(result.messages.toReversed());
|
|
90
|
+
state.noMoreMessage = result.messages.length < GET_MESSAGES_LIMIT;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
set((state) => {
|
|
95
|
+
state.messageLoading = false;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
execute: (_d) => __awaiter(void 0, [_d], void 0, function* ({ aid, working, parameters, onResponseStart, }) {
|
|
100
|
+
var _e, e_1, _f, _g;
|
|
101
|
+
let { session } = get();
|
|
102
|
+
if (!session) {
|
|
103
|
+
yield get().load();
|
|
104
|
+
session = get().session;
|
|
105
|
+
}
|
|
106
|
+
if (!session)
|
|
107
|
+
throw new Error('This session is not initialized');
|
|
108
|
+
const { id: sessionId } = session;
|
|
109
|
+
const identity = parseIdentity(aid, { rejectWhenError: true });
|
|
110
|
+
let message;
|
|
111
|
+
set((state) => {
|
|
112
|
+
state.running = true;
|
|
113
|
+
state.error = undefined;
|
|
114
|
+
});
|
|
115
|
+
try {
|
|
116
|
+
const stream = runAssistant({
|
|
117
|
+
sessionId,
|
|
118
|
+
identity,
|
|
119
|
+
working,
|
|
120
|
+
parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
|
|
121
|
+
});
|
|
122
|
+
let responseStarted = false;
|
|
123
|
+
try {
|
|
124
|
+
for (var _h = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _e = stream_1_1.done, !_e; _h = true) {
|
|
125
|
+
_g = stream_1_1.value;
|
|
126
|
+
_h = false;
|
|
127
|
+
const value = _g;
|
|
128
|
+
if (!responseStarted) {
|
|
129
|
+
responseStarted = true;
|
|
130
|
+
onResponseStart === null || onResponseStart === void 0 ? void 0 : onResponseStart();
|
|
131
|
+
}
|
|
132
|
+
if ((value === null || value === void 0 ? void 0 : value.type) === 'CHUNK') {
|
|
133
|
+
if (!message) {
|
|
134
|
+
message = {
|
|
135
|
+
taskId: value.taskId,
|
|
136
|
+
assistantId: identity.assistantId,
|
|
137
|
+
sessionId,
|
|
138
|
+
parameters,
|
|
139
|
+
createdAt: new Date().toISOString(),
|
|
140
|
+
updatedAt: new Date().toISOString(),
|
|
141
|
+
loading: true,
|
|
142
|
+
};
|
|
143
|
+
set((state) => {
|
|
144
|
+
var _a;
|
|
145
|
+
(_a = state.messages) !== null && _a !== void 0 ? _a : (state.messages = []);
|
|
146
|
+
state.messages.push(message);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (message.taskId === value.taskId) {
|
|
150
|
+
requestAnimationFrame(() => {
|
|
151
|
+
set((state) => {
|
|
152
|
+
var _a, _b, _c, _d, _e, _f;
|
|
153
|
+
var _g;
|
|
154
|
+
const msg = (_a = state.messages) === null || _a === void 0 ? void 0 : _a.findLast((i) => i.taskId === message.taskId);
|
|
155
|
+
if (!msg)
|
|
156
|
+
return;
|
|
157
|
+
(_b = msg.result) !== null && _b !== void 0 ? _b : (msg.result = {});
|
|
158
|
+
msg.result.content = (msg.result.content || '') + (value.delta.content || '');
|
|
159
|
+
if ((_d = (_c = value.delta) === null || _c === void 0 ? void 0 : _c.images) === null || _d === void 0 ? void 0 : _d.length) {
|
|
160
|
+
msg.result.images = ((_e = msg.result.images) !== null && _e !== void 0 ? _e : []).concat(value.delta.images);
|
|
161
|
+
}
|
|
162
|
+
if (value.delta.object) {
|
|
163
|
+
(_f = (_g = msg.result).objects) !== null && _f !== void 0 ? _f : (_g.objects = []);
|
|
164
|
+
msg.result.objects.push({ taskId: value.taskId, data: value.delta.object });
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if ((value === null || value === void 0 ? void 0 : value.type) === 'ERROR') {
|
|
171
|
+
set((state) => {
|
|
172
|
+
var _a;
|
|
173
|
+
const msg = (_a = state.messages) === null || _a === void 0 ? void 0 : _a.findLast((i) => i.taskId === message.taskId);
|
|
174
|
+
if (msg)
|
|
175
|
+
msg.error = value.error;
|
|
176
|
+
else
|
|
177
|
+
throw new Error(value.error.message);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
183
|
+
finally {
|
|
184
|
+
try {
|
|
185
|
+
if (!_h && !_e && (_f = stream_1.return)) yield _f.call(stream_1);
|
|
186
|
+
}
|
|
187
|
+
finally { if (e_1) throw e_1.error; }
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
set((state) => {
|
|
192
|
+
state.error = error;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
set((state) => {
|
|
197
|
+
var _a;
|
|
198
|
+
state.running = false;
|
|
199
|
+
if (message) {
|
|
200
|
+
const msg = (_a = state.messages) === null || _a === void 0 ? void 0 : _a.findLast((i) => i.taskId === message.taskId);
|
|
201
|
+
if (msg)
|
|
202
|
+
msg.loading = false;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}),
|
|
207
|
+
}))));
|
|
208
|
+
return STATES[aid];
|
|
209
|
+
};
|
|
@@ -19,9 +19,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
21
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
22
|
-
import {
|
|
23
|
-
import
|
|
24
|
-
import { useMemo, useState } from 'react';
|
|
22
|
+
import { Box, Stack, alpha } from '@mui/material';
|
|
23
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
25
24
|
import { useSessionContext } from '../../../../session';
|
|
26
25
|
import { createSession } from '../../api/session';
|
|
27
26
|
import { useAssistantState } from '../../state/assistant';
|
|
@@ -29,16 +28,22 @@ import { globalLoadingState } from '../../state/loading';
|
|
|
29
28
|
import { createSessionState } from '../../state/session';
|
|
30
29
|
import { MessageSuggestedQuestion } from '../common/MessageSuggestedQuestions';
|
|
31
30
|
import ParameterForm from '../form/ParameterForm';
|
|
32
|
-
import
|
|
31
|
+
import MessageErrorView from '../message/MessageErrorView';
|
|
32
|
+
import MessageItemView, { MessageItemWrapper } from '../message/MessageItemView';
|
|
33
33
|
import PoweredBy from '../PoweredBy';
|
|
34
34
|
export default function InitialForm({ page }) {
|
|
35
|
-
var _a;
|
|
35
|
+
var _a, _b;
|
|
36
36
|
const { assistantId } = page;
|
|
37
37
|
const { session: authSession } = useSessionContext();
|
|
38
38
|
const [assistant] = useAssistantState({ assistantId: page.assistantId });
|
|
39
|
-
const { parameters } = assistant;
|
|
40
39
|
const [error, setError] = useState();
|
|
41
|
-
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
var _a;
|
|
42
|
+
if (error && authSession.user && ((_a = error === null || error === void 0 ? void 0 : error.error) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
43
|
+
onSubmit(error.parameters);
|
|
44
|
+
setError(undefined);
|
|
45
|
+
}
|
|
46
|
+
}, [authSession.user]);
|
|
42
47
|
const opener = useMemo(() => {
|
|
43
48
|
var _a;
|
|
44
49
|
const { openerMessage } = (_a = assistant.release) !== null && _a !== void 0 ? _a : {};
|
|
@@ -46,6 +51,7 @@ export default function InitialForm({ page }) {
|
|
|
46
51
|
return {
|
|
47
52
|
taskId: '',
|
|
48
53
|
sessionId: '',
|
|
54
|
+
assistantId: '',
|
|
49
55
|
createdAt: new Date().toISOString(),
|
|
50
56
|
updatedAt: new Date().toISOString(),
|
|
51
57
|
result: { content: openerMessage },
|
|
@@ -54,14 +60,7 @@ export default function InitialForm({ page }) {
|
|
|
54
60
|
return undefined;
|
|
55
61
|
}, [assistant.release]);
|
|
56
62
|
const [creating, setCreating] = useState(false);
|
|
57
|
-
const onSubmit = (
|
|
58
|
-
if (!authSession.user) {
|
|
59
|
-
yield new Promise((resolve) => {
|
|
60
|
-
authSession.login(() => {
|
|
61
|
-
resolve();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
63
|
+
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
65
64
|
if (creating)
|
|
66
65
|
return;
|
|
67
66
|
setCreating(true);
|
|
@@ -69,20 +68,20 @@ export default function InitialForm({ page }) {
|
|
|
69
68
|
yield globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
|
|
70
69
|
const { created: session } = yield createSession({
|
|
71
70
|
assistantId,
|
|
72
|
-
name: parameters.question,
|
|
73
|
-
parameters
|
|
74
|
-
entry,
|
|
71
|
+
name: typeof (parameters === null || parameters === void 0 ? void 0 : parameters.question) === 'string' ? parameters.question : undefined,
|
|
72
|
+
parameters,
|
|
75
73
|
});
|
|
76
74
|
createSessionState({ sessionId: session.id, session }).getState().execute({
|
|
77
75
|
assistantId,
|
|
78
76
|
parameters,
|
|
79
77
|
});
|
|
80
|
-
setError(undefined);
|
|
81
78
|
page.navigate({ page: 'session', assistantId, sessionId: session.id });
|
|
82
79
|
}));
|
|
80
|
+
setError(undefined);
|
|
83
81
|
}
|
|
84
82
|
catch (error) {
|
|
85
|
-
setError(error);
|
|
83
|
+
setError({ error, parameters });
|
|
84
|
+
throw error;
|
|
86
85
|
}
|
|
87
86
|
finally {
|
|
88
87
|
setCreating(false);
|
|
@@ -90,11 +89,11 @@ export default function InitialForm({ page }) {
|
|
|
90
89
|
});
|
|
91
90
|
if (authSession.loading)
|
|
92
91
|
return null;
|
|
93
|
-
return (_jsxs(_Fragment, { children: [
|
|
92
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Box, { sx: { mt: 5, mb: 5, px: 2 }, children: [opener && (_jsx(Box, { mb: 2, children: _jsx(MessageItemView, { page: page, message: opener }) })), ((_a = assistant.entries) === null || _a === void 0 ? void 0 : _a.length) && (_jsx(EntryListView, { assistant: assistant, onEntryClick: (entry) => onSubmit(entry.parameters), sx: { pl: 6.5, pr: 2.5 } })), error && (_jsx(MessageItemWrapper, { assistant: assistant, agentMessage: _jsx(MessageErrorView, { error: error.error, page: page }), sx: { mt: 2 } }))] }), _jsx(Box, { flex: 1 }), _jsxs(Box, { className: "ai-runtime-form-container", sx: {
|
|
94
93
|
position: 'sticky',
|
|
95
94
|
bottom: 0,
|
|
96
95
|
background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)} 16px)`,
|
|
97
|
-
}, children: [_jsx(ParameterForm, {
|
|
96
|
+
}, children: [_jsx(ParameterForm, { disabled: ((_b = error === null || error === void 0 ? void 0 : error.error) === null || _b === void 0 ? void 0 : _b.status) === 401, page: page, assistant: assistant, onSubmit: onSubmit }), _jsx(PoweredBy, { assistantId: page.assistantId, sx: { my: 1, px: 2 } })] })] }));
|
|
98
97
|
}
|
|
99
98
|
export function EntryListView(_a) {
|
|
100
99
|
var _b;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
3
|
-
import {
|
|
3
|
+
import { Box, alpha } from '@mui/material';
|
|
4
4
|
import { useState } from 'react';
|
|
5
5
|
import { useAssistantState } from '../../state/assistant';
|
|
6
6
|
import { useSessionState } from '../../state/session';
|
|
7
7
|
import { MessageSuggestedQuestions } from '../common';
|
|
8
8
|
import ParameterForm from '../form/ParameterForm';
|
|
9
|
+
import MessageErrorView from '../message/MessageErrorView';
|
|
10
|
+
import { MessageItemWrapper } from '../message/MessageItemView';
|
|
9
11
|
import MessageListView from '../message/MessageListView';
|
|
10
12
|
import PoweredBy from '../PoweredBy';
|
|
11
13
|
import { useScrollToBottomModule } from '../ScrollView';
|
|
@@ -31,16 +33,21 @@ export default function RuntimeChatSession({ page }) {
|
|
|
31
33
|
setError(undefined);
|
|
32
34
|
})
|
|
33
35
|
.catch((error) => {
|
|
34
|
-
setError(error);
|
|
36
|
+
setError({ error, parameters });
|
|
35
37
|
});
|
|
36
38
|
};
|
|
37
|
-
return (_jsxs(_Fragment, { children: [
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Box, { sx: {
|
|
40
|
+
mb: {
|
|
41
|
+
xs: 1,
|
|
42
|
+
md: 2,
|
|
43
|
+
},
|
|
44
|
+
}, children: [_jsx(MessageListView, { className: "ai-chat-message-list", my: 5, px: 2, page: page }), _jsx(Box, { ml: 6.5, mr: 2.5, mt: -4, px: 2, children: (suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) ? (_jsx(MessageSuggestedQuestions, { dataSource: suggestedQuestions, onClick: (item) => {
|
|
45
|
+
onSubmit(Object.assign(Object.assign({}, lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters), { question: item.question }));
|
|
46
|
+
} })) : !((_e = state.messages) === null || _e === void 0 ? void 0 : _e.length) && ((_f = assistant.entries) === null || _f === void 0 ? void 0 : _f.length) ? (_jsx(EntryListView, { assistant: assistant, onEntryClick: (entry) => onSubmit(Object.assign(Object.assign({}, lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters), entry.parameters)) })) : null }), error && (_jsx(MessageItemWrapper, { assistant: assistant, agentMessage: _jsx(MessageErrorView, { error: error.error, page: page }), sx: { mt: 2, px: 2 } }))] }), _jsx(Box, { flex: 1 }), _jsxs(Box, { className: "ai-runtime-form-container", sx: {
|
|
40
47
|
pt: 2,
|
|
41
48
|
position: 'sticky',
|
|
42
49
|
bottom: 0,
|
|
43
50
|
// 从上透明到白色 0.72 的径向渐变
|
|
44
51
|
background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)} 16px)`,
|
|
45
|
-
}, children: [_jsx(ParameterForm, {
|
|
52
|
+
}, children: [_jsx(ParameterForm, { page: page, defaultValues: lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters, assistant: assistant, onSubmit: onSubmit, isSubmitting: state.running }), _jsx(PoweredBy, { assistantId: page.assistantId, sx: { my: 0.5, px: 2 } })] })] }));
|
|
46
53
|
}
|
|
@@ -62,12 +62,16 @@ export default function RuntimeFormForms(_a) {
|
|
|
62
62
|
const form = useForm({ defaultValues: defaultForm });
|
|
63
63
|
const [error, setError] = useState();
|
|
64
64
|
const [expand, setExpand] = useState(false);
|
|
65
|
-
const { session } = useSessionContext();
|
|
65
|
+
const { session: authSession } = useSessionContext();
|
|
66
66
|
const [submitting, setSubmitting] = useState(false);
|
|
67
67
|
useEffect(() => {
|
|
68
68
|
form.reset(defaultForm);
|
|
69
69
|
}, [defaultForm]);
|
|
70
70
|
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
if (!authSession.user) {
|
|
72
|
+
// TODO:
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
71
75
|
try {
|
|
72
76
|
setSubmitting(true);
|
|
73
77
|
let { sessionId } = page;
|
|
@@ -99,11 +103,6 @@ export default function RuntimeFormForms(_a) {
|
|
|
99
103
|
const handleSubmit = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
100
104
|
var _e;
|
|
101
105
|
e.preventDefault();
|
|
102
|
-
if (!session.user) {
|
|
103
|
-
yield new Promise((resolve) => {
|
|
104
|
-
session.login(() => resolve());
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
106
|
(_e = agent.parameters) === null || _e === void 0 ? void 0 : _e.some((parameter) => {
|
|
108
107
|
if (parameter.required && isEmpty(form.getValues(parameter.key))) {
|
|
109
108
|
setExpand(true);
|
|
@@ -12,17 +12,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { Box, Stack } from '@mui/material';
|
|
14
14
|
import { Suspense } from 'react';
|
|
15
|
-
import { useAssistantState } from '../../state/assistant';
|
|
16
15
|
import { useSessionState } from '../../state/session';
|
|
17
16
|
import MessageItemView from '../message/MessageItemView';
|
|
18
17
|
export default function RuntimeFormResult(_a) {
|
|
19
18
|
var { page } = _a, props = __rest(_a, ["page"]);
|
|
20
|
-
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(Box, { children: _jsx(Suspense, { children: page.
|
|
19
|
+
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(Box, { children: _jsx(Suspense, { children: page.page === 'session' && _jsx(ResultView, { page: page }) }) }) })));
|
|
21
20
|
}
|
|
22
21
|
function ResultView({ page }) {
|
|
23
|
-
const {
|
|
24
|
-
const [assistant] = useAssistantState({ assistantId });
|
|
25
|
-
const [, { messages = [] }] = useSessionState({ sessionId });
|
|
22
|
+
const [, { messages = [] }] = useSessionState(page);
|
|
26
23
|
const message = messages[messages.length - 1];
|
|
27
|
-
return (_jsx(Stack, { gap: 2, children: message &&
|
|
24
|
+
return (_jsx(Stack, { gap: 2, children: message && _jsx(MessageItemView, { hideAvatar: true, page: page, message: message }, message.taskId) }));
|
|
28
25
|
}
|
|
@@ -30,6 +30,10 @@ export default function RuntimeForm({ page }) {
|
|
|
30
30
|
display: 'flex',
|
|
31
31
|
flexDirection: 'column',
|
|
32
32
|
justifyContent: 'space-between',
|
|
33
|
+
mb: {
|
|
34
|
+
xs: 1,
|
|
35
|
+
md: 0,
|
|
36
|
+
},
|
|
33
37
|
}, children: [_jsxs(Stack, { gap: isMobile ? spacing : 1, spacing: spacing, children: [_jsx(RuntimeFormHeader, { agent: agent }), _jsx(RuntimeFormResult, { page: page })] }), !isMobile && _jsx(PoweredBy, { assistantId: page.assistantId, sx: { mt: spacing, mb: 0.5, px: 2, pt: 0 } })] }), _jsxs(Box, { sx: {
|
|
34
38
|
flex: {
|
|
35
39
|
md: 1,
|
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { useEffect } from 'react';
|
|
11
|
+
import { useSessionContext } from '../../../../session';
|
|
11
12
|
import { createSession, getSessions } from '../../api/session';
|
|
12
13
|
import useAsync from '../../hooks/useAsync';
|
|
13
14
|
import { useAssistantState } from '../../state/assistant';
|
|
@@ -15,6 +16,7 @@ import { globalLoadingState } from '../../state/loading';
|
|
|
15
16
|
import { createSessionState } from '../../state/session';
|
|
16
17
|
import { parseIdentity } from '../../utils';
|
|
17
18
|
export default function CheckSession({ cacheId, page, autoCreateSession, children, }) {
|
|
19
|
+
var _a;
|
|
18
20
|
const { assistantId, sessionId } = page;
|
|
19
21
|
useAssistantState({ assistantId });
|
|
20
22
|
const result = useAsync(() => {
|
|
@@ -53,6 +55,13 @@ export default function CheckSession({ cacheId, page, autoCreateSession, childre
|
|
|
53
55
|
if (result)
|
|
54
56
|
page.navigate(...result);
|
|
55
57
|
}, [result, page.navigate]);
|
|
58
|
+
const { session: authSession } = useSessionContext();
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
var _a;
|
|
61
|
+
if (!((_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did)) {
|
|
62
|
+
page.navigate({ page: 'assistant', assistantId: page.assistantId, sessionId: undefined }, { replace: true });
|
|
63
|
+
}
|
|
64
|
+
}, [(_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did]);
|
|
56
65
|
if (result)
|
|
57
66
|
return null;
|
|
58
67
|
return children;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
import { useCallback } from 'react';
|
|
11
|
+
import { useSessionContext } from '../../../session';
|
|
12
|
+
import { createAssistantState } from '../state/assistant';
|
|
13
|
+
import { createSessionState } from '../state/session';
|
|
14
|
+
import { createSubscriptionState } from '../state/subscription';
|
|
15
|
+
export function useLogin({ page }) {
|
|
16
|
+
const { session: authSession } = useSessionContext();
|
|
17
|
+
return useCallback(() => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
yield new Promise((resolve) => {
|
|
19
|
+
authSession.login(() => resolve());
|
|
20
|
+
});
|
|
21
|
+
yield Promise.all([
|
|
22
|
+
createAssistantState({ assistantId: page.assistantId }).getState().load(),
|
|
23
|
+
createSubscriptionState({ aid: page.assistantId }).getState().load(),
|
|
24
|
+
page.sessionId && createSessionState({ sessionId: page.sessionId }).getState().load(),
|
|
25
|
+
]);
|
|
26
|
+
}), [authSession, page]);
|
|
27
|
+
}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import DID from '@arcblock/ux/lib/DID';
|
|
3
|
-
import { Box, Button } from '@mui/material';
|
|
3
|
+
import { Box, Button, useMediaQuery, useTheme } from '@mui/material';
|
|
4
4
|
import { useEffect } from 'react';
|
|
5
5
|
import { Avatar } from '../../../arcblock/ux';
|
|
6
6
|
import { useLocaleContext } from '../../../locale';
|
|
7
7
|
import { useHeaderState } from '../../../page/header';
|
|
8
|
+
import { useSessionContext } from '../../../session';
|
|
8
9
|
import SocialShare from '../components/SocialShare';
|
|
9
10
|
import ThemeProvider from '../components/ThemeProvider';
|
|
10
11
|
import { useSubscribeLink } from './subscribe';
|
|
11
12
|
const logoSize = 44;
|
|
12
13
|
export function useSetHeader({ assistant, assistantId }) {
|
|
13
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
const { subscribeLink, isPaymentProject } = useSubscribeLink({ assistantId });
|
|
16
|
+
const theme = useTheme();
|
|
17
|
+
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
|
14
18
|
const { t, locale } = useLocaleContext();
|
|
19
|
+
const { session: authSession } = useSessionContext();
|
|
15
20
|
// set logo
|
|
16
21
|
useEffect(() => {
|
|
17
22
|
const { release } = assistant;
|
|
@@ -20,27 +25,32 @@ export function useSetHeader({ assistant, assistantId }) {
|
|
|
20
25
|
width: logoSize,
|
|
21
26
|
height: logoSize,
|
|
22
27
|
} }));
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (!isMobile) {
|
|
29
|
+
state.brand = (release === null || release === void 0 ? void 0 : release.title) || assistant.name;
|
|
30
|
+
state.description = assistant.createdBy && (_jsxs(Box, { sx: {
|
|
31
|
+
display: 'inline-flex',
|
|
32
|
+
alignItems: 'center',
|
|
33
|
+
gap: 0.5,
|
|
34
|
+
mt: 0.5,
|
|
35
|
+
}, children: [t('by'), " ", _jsx(DID, { did: assistant.createdBy, copyable: false })] }));
|
|
36
|
+
}
|
|
30
37
|
const shareContent = `${(release === null || release === void 0 ? void 0 : release.title) || assistant.name}
|
|
31
38
|
|
|
32
39
|
${release === null || release === void 0 ? void 0 : release.description}
|
|
33
40
|
`;
|
|
34
|
-
state.addons = (...exists) =>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
state.addons = (...exists) => {
|
|
42
|
+
var _a;
|
|
43
|
+
return [
|
|
44
|
+
((_a = authSession === null || authSession === void 0 ? void 0 : authSession.user) === null || _a === void 0 ? void 0 : _a.did) && isPaymentProject && (_jsx(ThemeProvider, { children: _jsx(Button, { disabled: !subscribeLink, variant: "outlined", href: subscribeLink,
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
color: "black", sx: {
|
|
47
|
+
// 字母不大写
|
|
48
|
+
textTransform: 'none',
|
|
49
|
+
}, children: subscribeLink ? t('subscribe') : t('subscribed') }) })),
|
|
50
|
+
_jsx(SocialShare, { content: shareContent }),
|
|
51
|
+
...exists,
|
|
52
|
+
].filter(Boolean);
|
|
53
|
+
};
|
|
44
54
|
});
|
|
45
55
|
return () => useHeaderState.setState((state) => {
|
|
46
56
|
state.logo = undefined;
|
|
@@ -48,5 +58,5 @@ ${release === null || release === void 0 ? void 0 : release.description}
|
|
|
48
58
|
state.description = undefined;
|
|
49
59
|
state.addons = (...exists) => [...exists];
|
|
50
60
|
});
|
|
51
|
-
}, [locale]);
|
|
61
|
+
}, [locale, isMobile, (_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did]);
|
|
52
62
|
}
|
|
@@ -5,21 +5,23 @@ import { PAYMENT_KIT_DID } from '../constants';
|
|
|
5
5
|
import { useAssistantState } from '../state/assistant';
|
|
6
6
|
import { useSubscriptionState } from '../state/subscription';
|
|
7
7
|
export function useSubscribeLink({ assistantId }) {
|
|
8
|
-
var _a, _b, _c;
|
|
8
|
+
var _a, _b, _c, _d, _e;
|
|
9
9
|
const [, state] = useSubscriptionState({ aid: assistantId });
|
|
10
10
|
const [assistant] = useAssistantState({ assistantId });
|
|
11
|
-
const { session } = useSessionContext();
|
|
11
|
+
const { session: authSession } = useSessionContext();
|
|
12
12
|
const requireSubscribe = ((_b = (_a = assistant.release) === null || _a === void 0 ? void 0 : _a.payment) === null || _b === void 0 ? void 0 : _b.enable) && !state.subscription;
|
|
13
|
-
const
|
|
13
|
+
const isPaymentProject = (_d = (_c = assistant.release) === null || _c === void 0 ? void 0 : _c.payment) === null || _d === void 0 ? void 0 : _d.enable;
|
|
14
|
+
const subscribeLink = requireSubscribe && authSession.user && ((_e = state.release) === null || _e === void 0 ? void 0 : _e.paymentLinkId)
|
|
14
15
|
? getSubscribeLink({
|
|
15
16
|
aid: assistantId,
|
|
16
|
-
userId:
|
|
17
|
+
userId: authSession.user.did,
|
|
17
18
|
paymentLinkId: state.release.paymentLinkId,
|
|
18
19
|
})
|
|
19
20
|
: undefined;
|
|
20
21
|
return {
|
|
21
22
|
requireSubscribe,
|
|
22
23
|
subscribeLink,
|
|
24
|
+
isPaymentProject,
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
27
|
function getSubscribeLink({ aid, userId, paymentLinkId }) {
|