Skip to content

Commit 54a14b4

Browse files
committed
✨ feat: support triggerAIMessage and createAssistantMessage
1 parent 149dd68 commit 54a14b4

15 files changed

+230
-202
lines changed

src/client/const.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
export enum PluginChannel {
2+
createAssistantMessage = 'lobe-chat:create-assistant-message',
3+
24
fetchPluginMessage = 'lobe-chat:fetch-plugin-message',
35
fetchPluginSettings = 'lobe-chat:fetch-plugin-settings',
4-
fetchPluginState = 'lobe-chat:fetch-plugin-state',
56

7+
fetchPluginState = 'lobe-chat:fetch-plugin-state',
68
fillStandalonePluginContent = 'lobe-chat:fill-plugin-content',
79
initStandalonePlugin = 'lobe-chat:init-standalone-plugin',
10+
811
pluginReadyForRender = 'lobe-chat:plugin-ready-for-render',
912

1013
renderPlugin = 'lobe-chat:render-plugin',
1114
renderPluginSettings = 'lobe-chat:render-plugin-settings',
1215
renderPluginState = 'lobe-chat:render-plugin-state',
1316

17+
triggerAIMessage = 'lobe-chat:trigger-ai-message',
18+
1419
updatePluginSettings = 'lobe-chat:update-plugin-settings',
1520
updatePluginState = 'lobe-chat:update-plugin-state',
1621
}

src/client/deprecatedOnV2.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { lobeChat } from './lobeChat';
2+
3+
/**
4+
* @deprecated
5+
*/
6+
export const postToFillPluginContent = lobeChat.setPluginMessage;
7+
8+
/**
9+
* @deprecated
10+
*/
11+
export const postToUpdatePluginState = lobeChat.setPluginState;
12+
13+
/**
14+
* @deprecated
15+
*/
16+
export const postToUpdatePluginSettings = lobeChat.setPluginSettings;
17+
18+
/**
19+
* @deprecated
20+
*/
21+
export const fetchPluginState = lobeChat.getPluginState;
22+
/**
23+
* @deprecated
24+
*/
25+
export const fetchPluginMessage = lobeChat.getPluginMessage;
26+
/**
27+
* @deprecated
28+
*/
29+
export const fetchPluginPayload = lobeChat.getPluginPayload;
30+
/**
31+
* @deprecated
32+
*/
33+
export const fetchPluginSettings = lobeChat.getPluginSettings;

src/client/fetch/index.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/client/fetch/message.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/client/fetch/pluginPayload.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/client/fetch/pluginSettings.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/client/fetch/pluginState.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/client/hooks/useOnStandalonePluginInit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useEffect } from 'react';
22

3-
import { PluginPayload, fetchPluginPayload } from '../fetch/pluginPayload';
3+
import { PluginPayload, lobeChat } from '@/client';
44

55
export const useOnStandalonePluginInit = <T = any>(
66
callback: (payload: PluginPayload<T>) => void,
77
) => {
88
useEffect(() => {
9-
fetchPluginPayload().then((e) => {
9+
lobeChat.getPluginPayload().then((e) => {
1010
if (!e) return;
1111

1212
callback(e);

src/client/hooks/usePluginSettings.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { useCallback, useEffect, useState } from 'react';
22

3-
import { fetchPluginSettings } from '@/client/fetch';
4-
import { postToUpdatePluginSettings } from '@/client/postMessage';
3+
import { lobeChat } from '@/client';
54

65
export const usePluginSettings = <T>(initialValue: T) => {
76
const [value, setValue] = useState(initialValue);
87

98
useEffect(() => {
10-
fetchPluginSettings().then((e) => {
9+
lobeChat.getPluginSettings().then((e) => {
1110
if (!e) return;
1211

1312
setValue(e);
@@ -16,7 +15,7 @@ export const usePluginSettings = <T>(initialValue: T) => {
1615

1716
const updateValue = useCallback((value: T) => {
1817
setValue(value);
19-
postToUpdatePluginSettings(value);
18+
lobeChat.setPluginSettings(value);
2019
}, []);
2120

2221
return [value, updateValue] as const;

src/client/hooks/usePluginState.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { useCallback, useEffect, useState } from 'react';
22

3-
import { fetchPluginState } from '@/client/fetch';
4-
import { postToUpdatePluginState } from '@/client/postMessage';
3+
import { lobeChat } from '@/client';
54

65
export const usePluginState = <T>(key: string, initialValue: T) => {
76
const [value, setValue] = useState(initialValue);
87

98
useEffect(() => {
10-
fetchPluginState(key).then((e) => {
9+
lobeChat.getPluginState(key).then((e) => {
1110
if (!e) return;
1211

1312
setValue(e);
@@ -17,7 +16,7 @@ export const usePluginState = <T>(key: string, initialValue: T) => {
1716
const updateValue = useCallback(
1817
(value: T) => {
1918
setValue(value);
20-
postToUpdatePluginState(key, value);
19+
lobeChat.setPluginState(key, value);
2120
},
2221
[key],
2322
);

0 commit comments

Comments
 (0)