@blocklet/pages-kit 0.2.302 → 0.2.304
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/components/MarkdownRenderer.js +3 -31
- package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentAgent.js +14 -8
- package/lib/cjs/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +8 -9
- package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +2 -5
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +18 -19
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +11 -9
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +16 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +21 -20
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +8 -8
- package/lib/cjs/builtin/async/ai-runtime/state/agent.js +2 -4
- package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +9 -8
- package/lib/cjs/builtin/async/ai-runtime/state/session.js +29 -16
- package/lib/cjs/builtin/async/ai-runtime/utils/agent-inputs.js +8 -0
- package/lib/cjs/builtin/async/ai-runtime/utils/zustand.js +10 -0
- package/lib/esm/builtin/async/ai-runtime/components/MarkdownRenderer.js +3 -9
- package/lib/esm/builtin/async/ai-runtime/contexts/CurrentAgent.js +14 -8
- package/lib/esm/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +9 -10
- package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +2 -5
- package/lib/esm/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +18 -18
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +12 -10
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +17 -2
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +22 -21
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +9 -9
- package/lib/esm/builtin/async/ai-runtime/state/agent.js +2 -4
- package/lib/esm/builtin/async/ai-runtime/state/runtime.js +9 -8
- package/lib/esm/builtin/async/ai-runtime/state/session.js +27 -15
- package/lib/esm/builtin/async/ai-runtime/utils/agent-inputs.js +4 -0
- package/lib/esm/builtin/async/ai-runtime/utils/zustand.js +6 -0
- package/lib/types/builtin/async/ai-runtime/contexts/CurrentAgent.d.ts +5 -3
- package/lib/types/builtin/async/ai-runtime/runtime-components/AutoForm/index.d.ts +0 -2
- package/lib/types/builtin/async/ai-runtime/state/agent.d.ts +2 -3
- package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +1 -2
- package/lib/types/builtin/async/ai-runtime/state/session.d.ts +4 -2
- package/lib/types/builtin/async/ai-runtime/utils/agent-inputs.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/utils/zustand.d.ts +2 -0
- package/package.json +5 -4
|
@@ -17,27 +17,28 @@ export function useRuntimeState() {
|
|
|
17
17
|
var _a;
|
|
18
18
|
const { aid, working } = useRuntimeContext();
|
|
19
19
|
const [agent] = useAgentState({ aid, working });
|
|
20
|
-
const sessionState = createSessionState({ aid })();
|
|
21
20
|
const { session: authSession } = useSessionContext();
|
|
21
|
+
const sessionState = useMemo(() => createSessionState({ aid }), [aid]);
|
|
22
|
+
const exec = sessionState((s) => s.execute);
|
|
22
23
|
// reset state after logged out
|
|
23
24
|
useEffect(() => {
|
|
24
25
|
var _a;
|
|
25
26
|
if (!((_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did)) {
|
|
26
|
-
sessionState.reset();
|
|
27
|
+
sessionState.getState().reset();
|
|
27
28
|
}
|
|
28
|
-
}, [(_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did]);
|
|
29
|
+
}, [(_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did, sessionState]);
|
|
29
30
|
const login = useCallback(() => __awaiter(this, void 0, void 0, function* () {
|
|
30
31
|
yield new Promise((resolve) => {
|
|
31
32
|
authSession.login(() => resolve());
|
|
32
33
|
});
|
|
33
|
-
yield
|
|
34
|
-
}), [
|
|
34
|
+
yield sessionState.getState().load();
|
|
35
|
+
}), [authSession, sessionState]);
|
|
35
36
|
const execute = useCallback((args) => __awaiter(this, void 0, void 0, function* () {
|
|
36
37
|
if (!authSession.user) {
|
|
37
38
|
yield login();
|
|
38
39
|
}
|
|
39
|
-
return
|
|
40
|
-
}), [authSession.user,
|
|
40
|
+
return exec(Object.assign(Object.assign({}, args), { working }));
|
|
41
|
+
}), [authSession.user, exec, working, login]);
|
|
41
42
|
const appearancePage = useMemo(() => {
|
|
42
43
|
var _a, _b;
|
|
43
44
|
const initialValue = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearancePage)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
@@ -47,5 +48,5 @@ export function useRuntimeState() {
|
|
|
47
48
|
var _a, _b, _c, _d, _e, _f;
|
|
48
49
|
return ((_f = (_e = (_d = (_c = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.children)) === null || _b === void 0 ? void 0 : _b.initialValue) === null || _c === void 0 ? void 0 : _c.agents) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : agent.id);
|
|
49
50
|
}, [agent]);
|
|
50
|
-
return { aid, working, agent, appearancePage,
|
|
51
|
+
return { aid, working, agent, appearancePage, childAgentId, execute };
|
|
51
52
|
}
|
|
@@ -15,16 +15,17 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
15
15
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
16
|
};
|
|
17
17
|
import { parseIdentity } from '@blocklet/ai-runtime/common/aid';
|
|
18
|
+
import { useEffect, useMemo } from 'react';
|
|
18
19
|
import { create } from 'zustand';
|
|
19
20
|
import { immer } from 'zustand/middleware/immer';
|
|
20
21
|
import { getMessages } from '../api/message';
|
|
21
22
|
import { createSession, getSessions, runAgent } from '../api/session';
|
|
22
|
-
|
|
23
|
+
import { useRuntimeContext } from '../contexts/Runtime';
|
|
24
|
+
import { createCachedStore } from '../utils/zustand';
|
|
23
25
|
const GET_MESSAGES_LIMIT = 100;
|
|
24
26
|
const GET_MESSAGES_ORDER_DIRECTION = 'desc';
|
|
25
27
|
export const createSessionState = ({ aid }) => {
|
|
26
|
-
|
|
27
|
-
(_a = STATES[aid]) !== null && _a !== void 0 ? _a : (STATES[aid] = create()(immer((set, get) => ({
|
|
28
|
+
return createCachedStore(aid, () => create()(immer((set, get) => ({
|
|
28
29
|
reset: () => {
|
|
29
30
|
set((state) => {
|
|
30
31
|
state.loading = undefined;
|
|
@@ -38,13 +39,13 @@ export const createSessionState = ({ aid }) => {
|
|
|
38
39
|
});
|
|
39
40
|
},
|
|
40
41
|
load: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
-
var
|
|
42
|
+
var _a;
|
|
42
43
|
set((state) => {
|
|
43
44
|
state.loading = true;
|
|
44
45
|
});
|
|
45
46
|
try {
|
|
46
47
|
const { sessions } = yield getSessions({ aid });
|
|
47
|
-
const session = (
|
|
48
|
+
const session = (_a = sessions[0]) !== null && _a !== void 0 ? _a : (yield createSession({ aid })).created;
|
|
48
49
|
const { messages } = yield getMessages({
|
|
49
50
|
sessionId: session.id,
|
|
50
51
|
orderDirection: GET_MESSAGES_ORDER_DIRECTION,
|
|
@@ -70,7 +71,7 @@ export const createSessionState = ({ aid }) => {
|
|
|
70
71
|
}
|
|
71
72
|
}),
|
|
72
73
|
loadMoreMessages: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
-
var
|
|
74
|
+
var _b;
|
|
74
75
|
set((state) => {
|
|
75
76
|
state.messageLoading = true;
|
|
76
77
|
});
|
|
@@ -80,7 +81,7 @@ export const createSessionState = ({ aid }) => {
|
|
|
80
81
|
try {
|
|
81
82
|
const result = yield getMessages({
|
|
82
83
|
sessionId: session.id,
|
|
83
|
-
before: (
|
|
84
|
+
before: (_b = messages === null || messages === void 0 ? void 0 : messages.slice(-1)[0]) === null || _b === void 0 ? void 0 : _b.id,
|
|
84
85
|
orderDirection: GET_MESSAGES_ORDER_DIRECTION,
|
|
85
86
|
limit: GET_MESSAGES_LIMIT,
|
|
86
87
|
});
|
|
@@ -96,8 +97,8 @@ export const createSessionState = ({ aid }) => {
|
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
99
|
}),
|
|
99
|
-
execute: (
|
|
100
|
-
var
|
|
100
|
+
execute: (_c) => __awaiter(void 0, [_c], void 0, function* ({ aid, working, parameters, onResponseStart, }) {
|
|
101
|
+
var _d, e_1, _e, _f;
|
|
101
102
|
let { session } = get();
|
|
102
103
|
if (!session) {
|
|
103
104
|
yield get().load();
|
|
@@ -121,10 +122,10 @@ export const createSessionState = ({ aid }) => {
|
|
|
121
122
|
});
|
|
122
123
|
let responseStarted = false;
|
|
123
124
|
try {
|
|
124
|
-
for (var
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const value =
|
|
125
|
+
for (var _g = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _d = stream_1_1.done, !_d; _g = true) {
|
|
126
|
+
_f = stream_1_1.value;
|
|
127
|
+
_g = false;
|
|
128
|
+
const value = _f;
|
|
128
129
|
if (!responseStarted) {
|
|
129
130
|
responseStarted = true;
|
|
130
131
|
onResponseStart === null || onResponseStart === void 0 ? void 0 : onResponseStart();
|
|
@@ -182,7 +183,7 @@ export const createSessionState = ({ aid }) => {
|
|
|
182
183
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
183
184
|
finally {
|
|
184
185
|
try {
|
|
185
|
-
if (!
|
|
186
|
+
if (!_g && !_d && (_e = stream_1.return)) yield _e.call(stream_1);
|
|
186
187
|
}
|
|
187
188
|
finally { if (e_1) throw e_1.error; }
|
|
188
189
|
}
|
|
@@ -205,5 +206,16 @@ export const createSessionState = ({ aid }) => {
|
|
|
205
206
|
}
|
|
206
207
|
}),
|
|
207
208
|
}))));
|
|
208
|
-
return STATES[aid];
|
|
209
209
|
};
|
|
210
|
+
export function useSessionState({ autoLoad } = {}) {
|
|
211
|
+
const { aid } = useRuntimeContext();
|
|
212
|
+
const state = useMemo(() => createSessionState({ aid }), [aid]);
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
if (!autoLoad)
|
|
215
|
+
return;
|
|
216
|
+
const { loading, loaded, load } = state.getState();
|
|
217
|
+
if (!loading && !loaded)
|
|
218
|
+
load();
|
|
219
|
+
}, [state, autoLoad]);
|
|
220
|
+
return state;
|
|
221
|
+
}
|
|
@@ -7,9 +7,11 @@ export default function CurrentAgentProvider({ agentId, children }: {
|
|
|
7
7
|
agentId: string;
|
|
8
8
|
children?: ReactNode;
|
|
9
9
|
}): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export declare function useCurrentAgent(
|
|
11
|
-
|
|
10
|
+
export declare function useCurrentAgent({ agentId }?: {
|
|
11
|
+
agentId?: string;
|
|
12
|
+
}): {
|
|
13
|
+
aid: string;
|
|
14
|
+
agent: import("immer").WritableDraft<import("../api/agent").Agent>;
|
|
12
15
|
appearanceInput: RuntimeOutputAppearance;
|
|
13
16
|
appearanceOutput: RuntimeOutputAppearance;
|
|
14
|
-
aid: string;
|
|
15
17
|
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Parameter } from '@blocklet/ai-runtime/types';
|
|
2
|
-
export declare const SUPPORTED_PARAMETER_TYPES: NonNullable<Parameter['type']>[];
|
|
3
1
|
export default function AutoForm({ submitText, inlineLabel, autoFillLastForm, submitInQuestionField, chatMode, }: {
|
|
4
2
|
submitText?: string;
|
|
5
3
|
inlineLabel?: boolean;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { StoreApi, UseBoundStore } from 'zustand';
|
|
2
1
|
import { Agent } from '../api/agent';
|
|
3
2
|
export interface AgentState {
|
|
4
3
|
loading?: boolean;
|
|
@@ -10,8 +9,8 @@ export declare const createAgentState: ({ aid, working, agent }: {
|
|
|
10
9
|
aid: string;
|
|
11
10
|
working?: boolean;
|
|
12
11
|
agent?: Agent;
|
|
13
|
-
}) => UseBoundStore<StoreApi<AgentState
|
|
12
|
+
}) => import("zustand").UseBoundStore<import("zustand").StoreApi<import("immer").WritableDraft<AgentState>>>;
|
|
14
13
|
export declare function useAgentState({ aid, working }: {
|
|
15
14
|
aid: string;
|
|
16
15
|
working?: boolean;
|
|
17
|
-
}): readonly [Agent
|
|
16
|
+
}): readonly [import("immer").WritableDraft<Agent>, import("immer").WritableDraft<AgentState>];
|
|
@@ -2,9 +2,8 @@ import { RuntimeOutputAppearancePage } from '@blocklet/ai-runtime/types';
|
|
|
2
2
|
export declare function useRuntimeState(): {
|
|
3
3
|
aid: string;
|
|
4
4
|
working: boolean | undefined;
|
|
5
|
-
agent: import("../api/agent").Agent
|
|
5
|
+
agent: import("immer").WritableDraft<import("../api/agent").Agent>;
|
|
6
6
|
appearancePage: RuntimeOutputAppearancePage | undefined;
|
|
7
|
-
sessionState: import("./session").SessionState;
|
|
8
7
|
childAgentId: string;
|
|
9
8
|
execute: (options: {
|
|
10
9
|
aid: string;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { StoreApi, UseBoundStore } from 'zustand';
|
|
2
1
|
import { Message } from '../api/message';
|
|
3
2
|
import { Session } from '../api/session';
|
|
4
3
|
export interface MessageItem extends Omit<Message, 'id'> {
|
|
@@ -26,4 +25,7 @@ export interface SessionState {
|
|
|
26
25
|
}
|
|
27
26
|
export declare const createSessionState: ({ aid }: {
|
|
28
27
|
aid: string;
|
|
29
|
-
}) => UseBoundStore<StoreApi<SessionState
|
|
28
|
+
}) => import("zustand").UseBoundStore<import("zustand").StoreApi<import("immer").WritableDraft<SessionState>>>;
|
|
29
|
+
export declare function useSessionState({ autoLoad }?: {
|
|
30
|
+
autoLoad?: boolean;
|
|
31
|
+
}): import("zustand").UseBoundStore<import("zustand").StoreApi<import("immer").WritableDraft<SessionState>>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/pages-kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.304",
|
|
4
4
|
"description": "Pages Kit components and utils",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@arcblock/did-connect": "^2.9.77",
|
|
85
85
|
"@blocklet/ai-kit": "^0.1.30",
|
|
86
|
-
"@blocklet/ai-runtime": "^0.1.
|
|
86
|
+
"@blocklet/ai-runtime": "^0.1.376",
|
|
87
87
|
"@blocklet/js-sdk": "1.16.26",
|
|
88
88
|
"@blocklet/sdk": "^1.16.26",
|
|
89
89
|
"@iconify/react": "^4.1.1",
|
|
@@ -105,6 +105,7 @@
|
|
|
105
105
|
"react-share": "^5.1.0",
|
|
106
106
|
"react-syntax-highlighter": "^15.5.0",
|
|
107
107
|
"react-wrap-balancer": "^1.1.0",
|
|
108
|
+
"remark-gfm": "^4.0.0",
|
|
108
109
|
"typescript": "^5.4.5",
|
|
109
110
|
"ufo": "^1.5.3",
|
|
110
111
|
"zustand": "^4.5.2"
|
|
@@ -127,9 +128,9 @@
|
|
|
127
128
|
"@emotion/cache": "^11.11.0",
|
|
128
129
|
"@emotion/css": "^11.11.2",
|
|
129
130
|
"@emotion/react": "^11.11.4",
|
|
130
|
-
"@mui/icons-material": "^5.15.
|
|
131
|
+
"@mui/icons-material": "^5.15.17",
|
|
131
132
|
"@mui/lab": "^5.0.0-alpha.170",
|
|
132
|
-
"@mui/material": "^5.15.
|
|
133
|
+
"@mui/material": "^5.15.17",
|
|
133
134
|
"@types/lodash": "^4.17.1",
|
|
134
135
|
"@types/mustache": "^4.2.5",
|
|
135
136
|
"@types/node-fetch": "^2.6.11",
|