Commit 98771284 by heheer Committed by GitHub

app list open-api & completion with appid & get history source (#3011)

* app list open-api & completion with appid & get history source

* change default value position
parent efc4e860
...@@ -526,7 +526,8 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/getHistories ...@@ -526,7 +526,8 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/getHistories
--data-raw '{ --data-raw '{
"appId": "appId", "appId": "appId",
"offset": 0, "offset": 0,
"pageSize": 20 "pageSize": 20,
"source: "api"
}' }'
``` ```
...@@ -540,6 +541,7 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/getHistories ...@@ -540,6 +541,7 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/getHistories
- appId - 应用 Id - appId - 应用 Id
- offset - 偏移量,即从第几条数据开始取 - offset - 偏移量,即从第几条数据开始取
- pageSize - 记录数量 - pageSize - 记录数量
- source - 对话源
{{% /alert %}} {{% /alert %}}
{{< /markdownify >}} {{< /markdownify >}}
......
...@@ -4,6 +4,7 @@ import type { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/ch ...@@ -4,6 +4,7 @@ import type { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/ch
import { AppTypeEnum } from '@fastgpt/global/core/app/constants'; import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { RequestPaging } from '@/types'; import { RequestPaging } from '@/types';
import { GetChatTypeEnum } from '@/global/core/chat/constants'; import { GetChatTypeEnum } from '@/global/core/chat/constants';
import { ChatSourceEnum } from '@fastgpt/global/core/chat/constants';
export type GetChatSpeechProps = { export type GetChatSpeechProps = {
ttsConfig: AppTTSConfigType; ttsConfig: AppTTSConfigType;
input: string; input: string;
...@@ -56,6 +57,7 @@ export type InitChatResponse = { ...@@ -56,6 +57,7 @@ export type InitChatResponse = {
/* ---------- history ----------- */ /* ---------- history ----------- */
export type GetHistoriesProps = OutLinkChatAuthProps & { export type GetHistoriesProps = OutLinkChatAuthProps & {
appId?: string; appId?: string;
source?: `${ChatSourceEnum}`;
}; };
export type UpdateHistoryProps = OutLinkChatAuthProps & { export type UpdateHistoryProps = OutLinkChatAuthProps & {
......
...@@ -39,6 +39,7 @@ async function handler(req: ApiRequestProps<ListAppBody>): Promise<AppListItemTy ...@@ -39,6 +39,7 @@ async function handler(req: ApiRequestProps<ListAppBody>): Promise<AppListItemTy
return await authApp({ return await authApp({
req, req,
authToken: true, authToken: true,
authApiKey: true,
appId: parentId, appId: parentId,
per: ReadPermissionVal per: ReadPermissionVal
}); });
...@@ -47,6 +48,7 @@ async function handler(req: ApiRequestProps<ListAppBody>): Promise<AppListItemTy ...@@ -47,6 +48,7 @@ async function handler(req: ApiRequestProps<ListAppBody>): Promise<AppListItemTy
...(await authUserPer({ ...(await authUserPer({
req, req,
authToken: true, authToken: true,
authApiKey: true,
per: ReadPermissionVal per: ReadPermissionVal
})), })),
app: undefined app: undefined
......
...@@ -17,8 +17,16 @@ async function handler( ...@@ -17,8 +17,16 @@ async function handler(
req: ApiRequestProps<getHistoriesBody, getHistoriesQuery>, req: ApiRequestProps<getHistoriesBody, getHistoriesQuery>,
res: ApiResponseType<any> res: ApiResponseType<any>
): Promise<PaginationResponse<getHistoriesResponse>> { ): Promise<PaginationResponse<getHistoriesResponse>> {
const { appId, shareId, outLinkUid, teamId, teamToken, offset, pageSize } = const {
req.body as getHistoriesBody; appId,
shareId,
outLinkUid,
teamId,
teamToken,
offset,
pageSize,
source = ChatSourceEnum.online
} = req.body as getHistoriesBody;
const match = await (async () => { const match = await (async () => {
if (shareId && outLinkUid) { if (shareId && outLinkUid) {
...@@ -47,7 +55,7 @@ async function handler( ...@@ -47,7 +55,7 @@ async function handler(
return { return {
tmbId, tmbId,
appId, appId,
source: ChatSourceEnum.online source: source
}; };
} }
})(); })();
......
...@@ -536,12 +536,13 @@ const authHeaderRequest = async ({ ...@@ -536,12 +536,13 @@ const authHeaderRequest = async ({
const { app } = await (async () => { const { app } = await (async () => {
if (authType === AuthUserTypeEnum.apikey) { if (authType === AuthUserTypeEnum.apikey) {
if (!apiKeyAppId) { const currentAppId = apiKeyAppId || appId;
if (!currentAppId) {
return Promise.reject( return Promise.reject(
'Key is error. You need to use the app key rather than the account key.' 'Key is error. You need to use the app key rather than the account key.'
); );
} }
const app = await MongoApp.findById(apiKeyAppId); const app = await MongoApp.findById(currentAppId);
if (!app) { if (!app) {
return Promise.reject('app is empty'); return Promise.reject('app is empty');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment