"代码更新:确保在flush=false时,重新加载时不会刷新新实体。此修复遵循指定的flush参数,以前新实体实例会刷新,现在只有在flush=true时才会刷新。"

This commit is contained in:
ivamp 2024-08-06 03:46:02 +08:00
parent 54bef3d8e5
commit 9b39c1a5e7
15 changed files with 4743 additions and 4320 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -5,18 +5,19 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import type { Configuration } from "./configuration";
import type { Configuration } from './configuration';
// Some imports not used depending on template conditions
// @ts-ignore
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from "axios";
import globalAxios from "axios";
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
import globalAxios from 'axios';
export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
@ -25,10 +26,10 @@ export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
* @export
*/
export const COLLECTION_FORMATS = {
csv: ",",
ssv: " ",
tsv: "\t",
pipes: "|",
csv: ",",
ssv: " ",
tsv: "\t",
pipes: "|",
};
/**
@ -37,8 +38,8 @@ export const COLLECTION_FORMATS = {
* @interface RequestArgs
*/
export interface RequestArgs {
url: string;
options: RawAxiosRequestConfig;
url: string;
options: RawAxiosRequestConfig;
}
/**
@ -47,19 +48,15 @@ export interface RequestArgs {
* @class BaseAPI
*/
export class BaseAPI {
protected configuration: Configuration | undefined;
protected configuration: Configuration | undefined;
constructor(
configuration?: Configuration,
protected basePath: string = BASE_PATH,
protected axios: AxiosInstance = globalAxios,
) {
if (configuration) {
this.configuration = configuration;
this.basePath = configuration.basePath ?? basePath;
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
if (configuration) {
this.configuration = configuration;
this.basePath = configuration.basePath ?? basePath;
}
}
}
}
};
/**
*
@ -68,24 +65,22 @@ export class BaseAPI {
* @extends {Error}
*/
export class RequiredError extends Error {
constructor(
public field: string,
msg?: string,
) {
super(msg);
this.name = "RequiredError";
}
constructor(public field: string, msg?: string) {
super(msg);
this.name = "RequiredError"
}
}
interface ServerMap {
[key: string]: {
url: string;
description: string;
}[];
[key: string]: {
url: string,
description: string,
}[];
}
/**
*
* @export
*/
export const operationServerMap: ServerMap = {};
export const operationServerMap: ServerMap = {
}

View File

@ -5,139 +5,105 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import type { Configuration } from "./configuration";
import type { RequestArgs } from "./base";
import type { AxiosInstance, AxiosResponse } from "axios";
import type { AxiosInstance, AxiosResponse } from 'axios';
import { RequiredError } from "./base";
/**
*
* @export
*/
export const DUMMY_BASE_URL = "https://example.com";
export const DUMMY_BASE_URL = 'https://example.com'
/**
*
* @throws {RequiredError}
* @export
*/
export const assertParamExists = function (
functionName: string,
paramName: string,
paramValue: unknown,
) {
if (paramValue === null || paramValue === undefined) {
throw new RequiredError(
paramName,
`Required parameter ${paramName} was null or undefined when calling ${functionName}.`,
);
}
};
/**
*
* @export
*/
export const setApiKeyToObject = async function (
object: any,
keyParamName: string,
configuration?: Configuration,
) {
if (configuration && configuration.apiKey) {
const localVarApiKeyValue =
typeof configuration.apiKey === "function"
? await configuration.apiKey(keyParamName)
: await configuration.apiKey;
object[keyParamName] = localVarApiKeyValue;
}
};
/**
*
* @export
*/
export const setBasicAuthToObject = function (
object: any,
configuration?: Configuration,
) {
if (configuration && (configuration.username || configuration.password)) {
object["auth"] = {
username: configuration.username,
password: configuration.password,
};
}
};
/**
*
* @export
*/
export const setBearerAuthToObject = async function (
object: any,
configuration?: Configuration,
) {
if (configuration && configuration.accessToken) {
const accessToken =
typeof configuration.accessToken === "function"
? await configuration.accessToken()
: await configuration.accessToken;
object["Authorization"] = "Bearer " + accessToken;
}
};
/**
*
* @export
*/
export const setOAuthToObject = async function (
object: any,
name: string,
scopes: string[],
configuration?: Configuration,
) {
if (configuration && configuration.accessToken) {
const localVarAccessTokenValue =
typeof configuration.accessToken === "function"
? await configuration.accessToken(name, scopes)
: await configuration.accessToken;
object["Authorization"] = "Bearer " + localVarAccessTokenValue;
}
};
function setFlattenedQueryParams(
urlSearchParams: URLSearchParams,
parameter: any,
key: string = "",
): void {
if (parameter == null) return;
if (typeof parameter === "object") {
if (Array.isArray(parameter)) {
(parameter as any[]).forEach((item) =>
setFlattenedQueryParams(urlSearchParams, item, key),
);
} else {
Object.keys(parameter).forEach((currentKey) =>
setFlattenedQueryParams(
urlSearchParams,
parameter[currentKey],
`${key}${key !== "" ? "." : ""}${currentKey}`,
),
);
export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
if (paramValue === null || paramValue === undefined) {
throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
}
} else {
if (urlSearchParams.has(key)) {
urlSearchParams.append(key, parameter);
} else {
urlSearchParams.set(key, parameter);
}
/**
*
* @export
*/
export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
if (configuration && configuration.apiKey) {
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
? await configuration.apiKey(keyParamName)
: await configuration.apiKey;
object[keyParamName] = localVarApiKeyValue;
}
}
/**
*
* @export
*/
export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
if (configuration && (configuration.username || configuration.password)) {
object["auth"] = { username: configuration.username, password: configuration.password };
}
}
/**
*
* @export
*/
export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
if (configuration && configuration.accessToken) {
const accessToken = typeof configuration.accessToken === 'function'
? await configuration.accessToken()
: await configuration.accessToken;
object["Authorization"] = "Bearer " + accessToken;
}
}
/**
*
* @export
*/
export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) {
if (configuration && configuration.accessToken) {
const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
? await configuration.accessToken(name, scopes)
: await configuration.accessToken;
object["Authorization"] = "Bearer " + localVarAccessTokenValue;
}
}
function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void {
if (parameter == null) return;
if (typeof parameter === "object") {
if (Array.isArray(parameter)) {
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
}
else {
Object.keys(parameter).forEach(currentKey =>
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
);
}
}
else {
if (urlSearchParams.has(key)) {
urlSearchParams.append(key, parameter);
}
else {
urlSearchParams.set(key, parameter);
}
}
}
}
/**
@ -145,58 +111,40 @@ function setFlattenedQueryParams(
* @export
*/
export const setSearchParams = function (url: URL, ...objects: any[]) {
const searchParams = new URLSearchParams(url.search);
setFlattenedQueryParams(searchParams, objects);
url.search = searchParams.toString();
};
const searchParams = new URLSearchParams(url.search);
setFlattenedQueryParams(searchParams, objects);
url.search = searchParams.toString();
}
/**
*
* @export
*/
export const serializeDataIfNeeded = function (
value: any,
requestOptions: any,
configuration?: Configuration,
) {
const nonString = typeof value !== "string";
const needsSerialization =
nonString && configuration && configuration.isJsonMime
? configuration.isJsonMime(requestOptions.headers["Content-Type"])
: nonString;
return needsSerialization
? JSON.stringify(value !== undefined ? value : {})
: value || "";
};
export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
const nonString = typeof value !== 'string';
const needsSerialization = nonString && configuration && configuration.isJsonMime
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
: nonString;
return needsSerialization
? JSON.stringify(value !== undefined ? value : {})
: (value || "");
}
/**
*
* @export
*/
export const toPathString = function (url: URL) {
return url.pathname + url.search + url.hash;
};
return url.pathname + url.search + url.hash
}
/**
*
* @export
*/
export const createRequestFunction = function (
axiosArgs: RequestArgs,
globalAxios: AxiosInstance,
BASE_PATH: string,
configuration?: Configuration,
) {
return <T = unknown, R = AxiosResponse<T>>(
axios: AxiosInstance = globalAxios,
basePath: string = BASE_PATH,
) => {
const axiosRequestArgs = {
...axiosArgs.options,
url:
(axios.defaults.baseURL ? "" : (configuration?.basePath ?? basePath)) +
axiosArgs.url,
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
return axios.request<T, R>(axiosRequestArgs);
};
return axios.request<T, R>(axiosRequestArgs);
};
};
}

View File

@ -5,128 +5,106 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
export interface ConfigurationParameters {
apiKey?:
| string
| Promise<string>
| ((name: string) => string)
| ((name: string) => Promise<string>);
username?: string;
password?: string;
accessToken?:
| string
| Promise<string>
| ((name?: string, scopes?: string[]) => string)
| ((name?: string, scopes?: string[]) => Promise<string>);
basePath?: string;
serverIndex?: number;
baseOptions?: any;
formDataCtor?: new () => any;
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
username?: string;
password?: string;
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
basePath?: string;
serverIndex?: number;
baseOptions?: any;
formDataCtor?: new () => any;
}
export class Configuration {
/**
* parameter for apiKey security
* @param name security name
* @memberof Configuration
*/
apiKey?:
| string
| Promise<string>
| ((name: string) => string)
| ((name: string) => Promise<string>);
/**
* parameter for basic security
*
* @type {string}
* @memberof Configuration
*/
username?: string;
/**
* parameter for basic security
*
* @type {string}
* @memberof Configuration
*/
password?: string;
/**
* parameter for oauth2 security
* @param name security name
* @param scopes oauth2 scope
* @memberof Configuration
*/
accessToken?:
| string
| Promise<string>
| ((name?: string, scopes?: string[]) => string)
| ((name?: string, scopes?: string[]) => Promise<string>);
/**
* override base path
*
* @type {string}
* @memberof Configuration
*/
basePath?: string;
/**
* override server index
*
* @type {number}
* @memberof Configuration
*/
serverIndex?: number;
/**
* base options for axios calls
*
* @type {any}
* @memberof Configuration
*/
baseOptions?: any;
/**
* The FormData constructor that will be used to create multipart form data
* requests. You can inject this here so that execution environments that
* do not support the FormData class can still run the generated client.
*
* @type {new () => FormData}
*/
formDataCtor?: new () => any;
/**
* parameter for apiKey security
* @param name security name
* @memberof Configuration
*/
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
/**
* parameter for basic security
*
* @type {string}
* @memberof Configuration
*/
username?: string;
/**
* parameter for basic security
*
* @type {string}
* @memberof Configuration
*/
password?: string;
/**
* parameter for oauth2 security
* @param name security name
* @param scopes oauth2 scope
* @memberof Configuration
*/
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
/**
* override base path
*
* @type {string}
* @memberof Configuration
*/
basePath?: string;
/**
* override server index
*
* @type {number}
* @memberof Configuration
*/
serverIndex?: number;
/**
* base options for axios calls
*
* @type {any}
* @memberof Configuration
*/
baseOptions?: any;
/**
* The FormData constructor that will be used to create multipart form data
* requests. You can inject this here so that execution environments that
* do not support the FormData class can still run the generated client.
*
* @type {new () => FormData}
*/
formDataCtor?: new () => any;
constructor(param: ConfigurationParameters = {}) {
this.apiKey = param.apiKey;
this.username = param.username;
this.password = param.password;
this.accessToken = param.accessToken;
this.basePath = param.basePath;
this.serverIndex = param.serverIndex;
this.baseOptions = param.baseOptions;
this.formDataCtor = param.formDataCtor;
}
constructor(param: ConfigurationParameters = {}) {
this.apiKey = param.apiKey;
this.username = param.username;
this.password = param.password;
this.accessToken = param.accessToken;
this.basePath = param.basePath;
this.serverIndex = param.serverIndex;
this.baseOptions = param.baseOptions;
this.formDataCtor = param.formDataCtor;
}
/**
* Check if the given MIME is a JSON MIME.
* JSON MIME examples:
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* @param mime - MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public isJsonMime(mime: string): boolean {
const jsonMime: RegExp = new RegExp(
"^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$",
"i",
);
return (
mime !== null &&
(jsonMime.test(mime) ||
mime.toLowerCase() === "application/json-patch+json")
);
}
/**
* Check if the given MIME is a JSON MIME.
* JSON MIME examples:
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* @param mime - MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public isJsonMime(mime: string): boolean {
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
}
}

View File

@ -5,12 +5,14 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
export * from "./api";
export * from "./configuration";

424
src/auto-imports.d.ts vendored
View File

@ -5,271 +5,187 @@
// Generated by unplugin-auto-import
export {}
declare global {
const EffectScope: (typeof import("vue"))["EffectScope"];
const computed: (typeof import("vue"))["computed"];
const createApp: (typeof import("vue"))["createApp"];
const customRef: (typeof import("vue"))["customRef"];
const defineAsyncComponent: (typeof import("vue"))["defineAsyncComponent"];
const defineComponent: (typeof import("vue"))["defineComponent"];
const effectScope: (typeof import("vue"))["effectScope"];
const getCurrentInstance: (typeof import("vue"))["getCurrentInstance"];
const getCurrentScope: (typeof import("vue"))["getCurrentScope"];
const h: (typeof import("vue"))["h"];
const inject: (typeof import("vue"))["inject"];
const isProxy: (typeof import("vue"))["isProxy"];
const isReactive: (typeof import("vue"))["isReactive"];
const isReadonly: (typeof import("vue"))["isReadonly"];
const isRef: (typeof import("vue"))["isRef"];
const markRaw: (typeof import("vue"))["markRaw"];
const nextTick: (typeof import("vue"))["nextTick"];
const onActivated: (typeof import("vue"))["onActivated"];
const onBeforeMount: (typeof import("vue"))["onBeforeMount"];
const onBeforeRouteLeave: (typeof import("vue-router"))["onBeforeRouteLeave"];
const onBeforeRouteUpdate: (typeof import("vue-router"))["onBeforeRouteUpdate"];
const onBeforeUnmount: (typeof import("vue"))["onBeforeUnmount"];
const onBeforeUpdate: (typeof import("vue"))["onBeforeUpdate"];
const onDeactivated: (typeof import("vue"))["onDeactivated"];
const onErrorCaptured: (typeof import("vue"))["onErrorCaptured"];
const onMounted: (typeof import("vue"))["onMounted"];
const onRenderTracked: (typeof import("vue"))["onRenderTracked"];
const onRenderTriggered: (typeof import("vue"))["onRenderTriggered"];
const onScopeDispose: (typeof import("vue"))["onScopeDispose"];
const onServerPrefetch: (typeof import("vue"))["onServerPrefetch"];
const onUnmounted: (typeof import("vue"))["onUnmounted"];
const onUpdated: (typeof import("vue"))["onUpdated"];
const provide: (typeof import("vue"))["provide"];
const reactive: (typeof import("vue"))["reactive"];
const readonly: (typeof import("vue"))["readonly"];
const ref: (typeof import("vue"))["ref"];
const resolveComponent: (typeof import("vue"))["resolveComponent"];
const shallowReactive: (typeof import("vue"))["shallowReactive"];
const shallowReadonly: (typeof import("vue"))["shallowReadonly"];
const shallowRef: (typeof import("vue"))["shallowRef"];
const toRaw: (typeof import("vue"))["toRaw"];
const toRef: (typeof import("vue"))["toRef"];
const toRefs: (typeof import("vue"))["toRefs"];
const toValue: (typeof import("vue"))["toValue"];
const triggerRef: (typeof import("vue"))["triggerRef"];
const unref: (typeof import("vue"))["unref"];
const useAttrs: (typeof import("vue"))["useAttrs"];
const useCssModule: (typeof import("vue"))["useCssModule"];
const useCssVars: (typeof import("vue"))["useCssVars"];
const useLink: (typeof import("vue-router"))["useLink"];
const useRoute: (typeof import("vue-router/auto"))["useRoute"];
const useRouter: (typeof import("vue-router/auto"))["useRouter"];
const useSlots: (typeof import("vue"))["useSlots"];
const watch: (typeof import("vue"))["watch"];
const watchEffect: (typeof import("vue"))["watchEffect"];
const watchPostEffect: (typeof import("vue"))["watchPostEffect"];
const watchSyncEffect: (typeof import("vue"))["watchSyncEffect"];
const EffectScope: typeof import('vue')['EffectScope']
const computed: typeof import('vue')['computed']
const createApp: typeof import('vue')['createApp']
const customRef: typeof import('vue')['customRef']
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
const defineComponent: typeof import('vue')['defineComponent']
const effectScope: typeof import('vue')['effectScope']
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
const getCurrentScope: typeof import('vue')['getCurrentScope']
const h: typeof import('vue')['h']
const inject: typeof import('vue')['inject']
const isProxy: typeof import('vue')['isProxy']
const isReactive: typeof import('vue')['isReactive']
const isReadonly: typeof import('vue')['isReadonly']
const isRef: typeof import('vue')['isRef']
const markRaw: typeof import('vue')['markRaw']
const nextTick: typeof import('vue')['nextTick']
const onActivated: typeof import('vue')['onActivated']
const onBeforeMount: typeof import('vue')['onBeforeMount']
const onBeforeRouteLeave: (typeof import("vue-router"))["onBeforeRouteLeave"]
const onBeforeRouteUpdate: (typeof import("vue-router"))["onBeforeRouteUpdate"]
const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']
const onDeactivated: typeof import('vue')['onDeactivated']
const onErrorCaptured: typeof import('vue')['onErrorCaptured']
const onMounted: typeof import('vue')['onMounted']
const onRenderTracked: typeof import('vue')['onRenderTracked']
const onRenderTriggered: typeof import('vue')['onRenderTriggered']
const onScopeDispose: typeof import('vue')['onScopeDispose']
const onServerPrefetch: typeof import('vue')['onServerPrefetch']
const onUnmounted: typeof import('vue')['onUnmounted']
const onUpdated: typeof import('vue')['onUpdated']
const provide: typeof import('vue')['provide']
const reactive: typeof import('vue')['reactive']
const readonly: typeof import('vue')['readonly']
const ref: typeof import('vue')['ref']
const resolveComponent: typeof import('vue')['resolveComponent']
const shallowReactive: typeof import('vue')['shallowReactive']
const shallowReadonly: typeof import('vue')['shallowReadonly']
const shallowRef: typeof import('vue')['shallowRef']
const toRaw: typeof import('vue')['toRaw']
const toRef: typeof import('vue')['toRef']
const toRefs: typeof import('vue')['toRefs']
const toValue: typeof import('vue')['toValue']
const triggerRef: typeof import('vue')['triggerRef']
const unref: typeof import('vue')['unref']
const useAttrs: typeof import('vue')['useAttrs']
const useCssModule: typeof import('vue')['useCssModule']
const useCssVars: typeof import('vue')['useCssVars']
const useLink: (typeof import("vue-router"))["useLink"]
const useRoute: typeof import('vue-router/auto')['useRoute']
const useRouter: typeof import('vue-router/auto')['useRouter']
const useSlots: typeof import('vue')['useSlots']
const watch: typeof import('vue')['watch']
const watchEffect: typeof import('vue')['watchEffect']
const watchPostEffect: typeof import('vue')['watchPostEffect']
const watchSyncEffect: typeof import('vue')['watchSyncEffect']
}
// for type re-export
declare global {
// @ts-ignore
export type {
Component,
ComponentPublicInstance,
ComputedRef,
ExtractDefaultPropTypes,
ExtractPropTypes,
ExtractPublicPropTypes,
InjectionKey,
PropType,
Ref,
VNode,
WritableComputedRef,
} from "vue";
import("vue");
export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
import('vue')
}
// for vue template auto import
import { UnwrapRef } from "vue";
declare module "vue" {
import { UnwrapRef } from 'vue'
declare module 'vue' {
interface GlobalComponents {}
interface ComponentCustomProperties {
readonly EffectScope: UnwrapRef<(typeof import("vue"))["EffectScope"]>;
readonly computed: UnwrapRef<(typeof import("vue"))["computed"]>;
readonly createApp: UnwrapRef<(typeof import("vue"))["createApp"]>;
readonly customRef: UnwrapRef<(typeof import("vue"))["customRef"]>;
readonly defineAsyncComponent: UnwrapRef<
(typeof import("vue"))["defineAsyncComponent"]
>;
readonly defineComponent: UnwrapRef<
(typeof import("vue"))["defineComponent"]
>;
readonly effectScope: UnwrapRef<(typeof import("vue"))["effectScope"]>;
readonly getCurrentInstance: UnwrapRef<
(typeof import("vue"))["getCurrentInstance"]
>;
readonly getCurrentScope: UnwrapRef<
(typeof import("vue"))["getCurrentScope"]
>;
readonly h: UnwrapRef<(typeof import("vue"))["h"]>;
readonly inject: UnwrapRef<(typeof import("vue"))["inject"]>;
readonly isProxy: UnwrapRef<(typeof import("vue"))["isProxy"]>;
readonly isReactive: UnwrapRef<(typeof import("vue"))["isReactive"]>;
readonly isReadonly: UnwrapRef<(typeof import("vue"))["isReadonly"]>;
readonly isRef: UnwrapRef<(typeof import("vue"))["isRef"]>;
readonly markRaw: UnwrapRef<(typeof import("vue"))["markRaw"]>;
readonly nextTick: UnwrapRef<(typeof import("vue"))["nextTick"]>;
readonly onActivated: UnwrapRef<(typeof import("vue"))["onActivated"]>;
readonly onBeforeMount: UnwrapRef<(typeof import("vue"))["onBeforeMount"]>;
readonly onBeforeUnmount: UnwrapRef<
(typeof import("vue"))["onBeforeUnmount"]
>;
readonly onBeforeUpdate: UnwrapRef<
(typeof import("vue"))["onBeforeUpdate"]
>;
readonly onDeactivated: UnwrapRef<(typeof import("vue"))["onDeactivated"]>;
readonly onErrorCaptured: UnwrapRef<
(typeof import("vue"))["onErrorCaptured"]
>;
readonly onMounted: UnwrapRef<(typeof import("vue"))["onMounted"]>;
readonly onRenderTracked: UnwrapRef<
(typeof import("vue"))["onRenderTracked"]
>;
readonly onRenderTriggered: UnwrapRef<
(typeof import("vue"))["onRenderTriggered"]
>;
readonly onScopeDispose: UnwrapRef<
(typeof import("vue"))["onScopeDispose"]
>;
readonly onServerPrefetch: UnwrapRef<
(typeof import("vue"))["onServerPrefetch"]
>;
readonly onUnmounted: UnwrapRef<(typeof import("vue"))["onUnmounted"]>;
readonly onUpdated: UnwrapRef<(typeof import("vue"))["onUpdated"]>;
readonly provide: UnwrapRef<(typeof import("vue"))["provide"]>;
readonly reactive: UnwrapRef<(typeof import("vue"))["reactive"]>;
readonly readonly: UnwrapRef<(typeof import("vue"))["readonly"]>;
readonly ref: UnwrapRef<(typeof import("vue"))["ref"]>;
readonly resolveComponent: UnwrapRef<
(typeof import("vue"))["resolveComponent"]
>;
readonly shallowReactive: UnwrapRef<
(typeof import("vue"))["shallowReactive"]
>;
readonly shallowReadonly: UnwrapRef<
(typeof import("vue"))["shallowReadonly"]
>;
readonly shallowRef: UnwrapRef<(typeof import("vue"))["shallowRef"]>;
readonly toRaw: UnwrapRef<(typeof import("vue"))["toRaw"]>;
readonly toRef: UnwrapRef<(typeof import("vue"))["toRef"]>;
readonly toRefs: UnwrapRef<(typeof import("vue"))["toRefs"]>;
readonly toValue: UnwrapRef<(typeof import("vue"))["toValue"]>;
readonly triggerRef: UnwrapRef<(typeof import("vue"))["triggerRef"]>;
readonly unref: UnwrapRef<(typeof import("vue"))["unref"]>;
readonly useAttrs: UnwrapRef<(typeof import("vue"))["useAttrs"]>;
readonly useCssModule: UnwrapRef<(typeof import("vue"))["useCssModule"]>;
readonly useCssVars: UnwrapRef<(typeof import("vue"))["useCssVars"]>;
readonly useRoute: UnwrapRef<
(typeof import("vue-router/auto"))["useRoute"]
>;
readonly useRouter: UnwrapRef<
(typeof import("vue-router/auto"))["useRouter"]
>;
readonly useSlots: UnwrapRef<(typeof import("vue"))["useSlots"]>;
readonly watch: UnwrapRef<(typeof import("vue"))["watch"]>;
readonly watchEffect: UnwrapRef<(typeof import("vue"))["watchEffect"]>;
readonly watchPostEffect: UnwrapRef<
(typeof import("vue"))["watchPostEffect"]
>;
readonly watchSyncEffect: UnwrapRef<
(typeof import("vue"))["watchSyncEffect"]
>;
readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
readonly computed: UnwrapRef<typeof import('vue')['computed']>
readonly createApp: UnwrapRef<typeof import('vue')['createApp']>
readonly customRef: UnwrapRef<typeof import('vue')['customRef']>
readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
readonly defineComponent: UnwrapRef<typeof import('vue')['defineComponent']>
readonly effectScope: UnwrapRef<typeof import('vue')['effectScope']>
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
readonly h: UnwrapRef<typeof import('vue')['h']>
readonly inject: UnwrapRef<typeof import('vue')['inject']>
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
readonly isReadonly: UnwrapRef<typeof import('vue')['isReadonly']>
readonly isRef: UnwrapRef<typeof import('vue')['isRef']>
readonly markRaw: UnwrapRef<typeof import('vue')['markRaw']>
readonly nextTick: UnwrapRef<typeof import('vue')['nextTick']>
readonly onActivated: UnwrapRef<typeof import('vue')['onActivated']>
readonly onBeforeMount: UnwrapRef<typeof import('vue')['onBeforeMount']>
readonly onBeforeUnmount: UnwrapRef<typeof import('vue')['onBeforeUnmount']>
readonly onBeforeUpdate: UnwrapRef<typeof import('vue')['onBeforeUpdate']>
readonly onDeactivated: UnwrapRef<typeof import('vue')['onDeactivated']>
readonly onErrorCaptured: UnwrapRef<typeof import('vue')['onErrorCaptured']>
readonly onMounted: UnwrapRef<typeof import('vue')['onMounted']>
readonly onRenderTracked: UnwrapRef<typeof import('vue')['onRenderTracked']>
readonly onRenderTriggered: UnwrapRef<typeof import('vue')['onRenderTriggered']>
readonly onScopeDispose: UnwrapRef<typeof import('vue')['onScopeDispose']>
readonly onServerPrefetch: UnwrapRef<typeof import('vue')['onServerPrefetch']>
readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
readonly provide: UnwrapRef<typeof import('vue')['provide']>
readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
readonly readonly: UnwrapRef<typeof import('vue')['readonly']>
readonly ref: UnwrapRef<typeof import('vue')['ref']>
readonly resolveComponent: UnwrapRef<typeof import('vue')['resolveComponent']>
readonly shallowReactive: UnwrapRef<typeof import('vue')['shallowReactive']>
readonly shallowReadonly: UnwrapRef<typeof import('vue')['shallowReadonly']>
readonly shallowRef: UnwrapRef<typeof import('vue')['shallowRef']>
readonly toRaw: UnwrapRef<typeof import('vue')['toRaw']>
readonly toRef: UnwrapRef<typeof import('vue')['toRef']>
readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
readonly unref: UnwrapRef<typeof import('vue')['unref']>
readonly useAttrs: UnwrapRef<typeof import('vue')['useAttrs']>
readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
readonly useRoute: UnwrapRef<typeof import('vue-router/auto')['useRoute']>
readonly useRouter: UnwrapRef<typeof import('vue-router/auto')['useRouter']>
readonly useSlots: UnwrapRef<typeof import('vue')['useSlots']>
readonly watch: UnwrapRef<typeof import('vue')['watch']>
readonly watchEffect: UnwrapRef<typeof import('vue')['watchEffect']>
readonly watchPostEffect: UnwrapRef<typeof import('vue')['watchPostEffect']>
readonly watchSyncEffect: UnwrapRef<typeof import('vue')['watchSyncEffect']>
}
}
declare module "@vue/runtime-core" {
declare module '@vue/runtime-core' {
interface GlobalComponents {}
interface ComponentCustomProperties {
readonly EffectScope: UnwrapRef<(typeof import("vue"))["EffectScope"]>;
readonly computed: UnwrapRef<(typeof import("vue"))["computed"]>;
readonly createApp: UnwrapRef<(typeof import("vue"))["createApp"]>;
readonly customRef: UnwrapRef<(typeof import("vue"))["customRef"]>;
readonly defineAsyncComponent: UnwrapRef<
(typeof import("vue"))["defineAsyncComponent"]
>;
readonly defineComponent: UnwrapRef<
(typeof import("vue"))["defineComponent"]
>;
readonly effectScope: UnwrapRef<(typeof import("vue"))["effectScope"]>;
readonly getCurrentInstance: UnwrapRef<
(typeof import("vue"))["getCurrentInstance"]
>;
readonly getCurrentScope: UnwrapRef<
(typeof import("vue"))["getCurrentScope"]
>;
readonly h: UnwrapRef<(typeof import("vue"))["h"]>;
readonly inject: UnwrapRef<(typeof import("vue"))["inject"]>;
readonly isProxy: UnwrapRef<(typeof import("vue"))["isProxy"]>;
readonly isReactive: UnwrapRef<(typeof import("vue"))["isReactive"]>;
readonly isReadonly: UnwrapRef<(typeof import("vue"))["isReadonly"]>;
readonly isRef: UnwrapRef<(typeof import("vue"))["isRef"]>;
readonly markRaw: UnwrapRef<(typeof import("vue"))["markRaw"]>;
readonly nextTick: UnwrapRef<(typeof import("vue"))["nextTick"]>;
readonly onActivated: UnwrapRef<(typeof import("vue"))["onActivated"]>;
readonly onBeforeMount: UnwrapRef<(typeof import("vue"))["onBeforeMount"]>;
readonly onBeforeUnmount: UnwrapRef<
(typeof import("vue"))["onBeforeUnmount"]
>;
readonly onBeforeUpdate: UnwrapRef<
(typeof import("vue"))["onBeforeUpdate"]
>;
readonly onDeactivated: UnwrapRef<(typeof import("vue"))["onDeactivated"]>;
readonly onErrorCaptured: UnwrapRef<
(typeof import("vue"))["onErrorCaptured"]
>;
readonly onMounted: UnwrapRef<(typeof import("vue"))["onMounted"]>;
readonly onRenderTracked: UnwrapRef<
(typeof import("vue"))["onRenderTracked"]
>;
readonly onRenderTriggered: UnwrapRef<
(typeof import("vue"))["onRenderTriggered"]
>;
readonly onScopeDispose: UnwrapRef<
(typeof import("vue"))["onScopeDispose"]
>;
readonly onServerPrefetch: UnwrapRef<
(typeof import("vue"))["onServerPrefetch"]
>;
readonly onUnmounted: UnwrapRef<(typeof import("vue"))["onUnmounted"]>;
readonly onUpdated: UnwrapRef<(typeof import("vue"))["onUpdated"]>;
readonly provide: UnwrapRef<(typeof import("vue"))["provide"]>;
readonly reactive: UnwrapRef<(typeof import("vue"))["reactive"]>;
readonly readonly: UnwrapRef<(typeof import("vue"))["readonly"]>;
readonly ref: UnwrapRef<(typeof import("vue"))["ref"]>;
readonly resolveComponent: UnwrapRef<
(typeof import("vue"))["resolveComponent"]
>;
readonly shallowReactive: UnwrapRef<
(typeof import("vue"))["shallowReactive"]
>;
readonly shallowReadonly: UnwrapRef<
(typeof import("vue"))["shallowReadonly"]
>;
readonly shallowRef: UnwrapRef<(typeof import("vue"))["shallowRef"]>;
readonly toRaw: UnwrapRef<(typeof import("vue"))["toRaw"]>;
readonly toRef: UnwrapRef<(typeof import("vue"))["toRef"]>;
readonly toRefs: UnwrapRef<(typeof import("vue"))["toRefs"]>;
readonly toValue: UnwrapRef<(typeof import("vue"))["toValue"]>;
readonly triggerRef: UnwrapRef<(typeof import("vue"))["triggerRef"]>;
readonly unref: UnwrapRef<(typeof import("vue"))["unref"]>;
readonly useAttrs: UnwrapRef<(typeof import("vue"))["useAttrs"]>;
readonly useCssModule: UnwrapRef<(typeof import("vue"))["useCssModule"]>;
readonly useCssVars: UnwrapRef<(typeof import("vue"))["useCssVars"]>;
readonly useRoute: UnwrapRef<
(typeof import("vue-router/auto"))["useRoute"]
>;
readonly useRouter: UnwrapRef<
(typeof import("vue-router/auto"))["useRouter"]
>;
readonly useSlots: UnwrapRef<(typeof import("vue"))["useSlots"]>;
readonly watch: UnwrapRef<(typeof import("vue"))["watch"]>;
readonly watchEffect: UnwrapRef<(typeof import("vue"))["watchEffect"]>;
readonly watchPostEffect: UnwrapRef<
(typeof import("vue"))["watchPostEffect"]
>;
readonly watchSyncEffect: UnwrapRef<
(typeof import("vue"))["watchSyncEffect"]
>;
readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
readonly computed: UnwrapRef<typeof import('vue')['computed']>
readonly createApp: UnwrapRef<typeof import('vue')['createApp']>
readonly customRef: UnwrapRef<typeof import('vue')['customRef']>
readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
readonly defineComponent: UnwrapRef<typeof import('vue')['defineComponent']>
readonly effectScope: UnwrapRef<typeof import('vue')['effectScope']>
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
readonly h: UnwrapRef<typeof import('vue')['h']>
readonly inject: UnwrapRef<typeof import('vue')['inject']>
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
readonly isReadonly: UnwrapRef<typeof import('vue')['isReadonly']>
readonly isRef: UnwrapRef<typeof import('vue')['isRef']>
readonly markRaw: UnwrapRef<typeof import('vue')['markRaw']>
readonly nextTick: UnwrapRef<typeof import('vue')['nextTick']>
readonly onActivated: UnwrapRef<typeof import('vue')['onActivated']>
readonly onBeforeMount: UnwrapRef<typeof import('vue')['onBeforeMount']>
readonly onBeforeUnmount: UnwrapRef<typeof import('vue')['onBeforeUnmount']>
readonly onBeforeUpdate: UnwrapRef<typeof import('vue')['onBeforeUpdate']>
readonly onDeactivated: UnwrapRef<typeof import('vue')['onDeactivated']>
readonly onErrorCaptured: UnwrapRef<typeof import('vue')['onErrorCaptured']>
readonly onMounted: UnwrapRef<typeof import('vue')['onMounted']>
readonly onRenderTracked: UnwrapRef<typeof import('vue')['onRenderTracked']>
readonly onRenderTriggered: UnwrapRef<typeof import('vue')['onRenderTriggered']>
readonly onScopeDispose: UnwrapRef<typeof import('vue')['onScopeDispose']>
readonly onServerPrefetch: UnwrapRef<typeof import('vue')['onServerPrefetch']>
readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
readonly provide: UnwrapRef<typeof import('vue')['provide']>
readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
readonly readonly: UnwrapRef<typeof import('vue')['readonly']>
readonly ref: UnwrapRef<typeof import('vue')['ref']>
readonly resolveComponent: UnwrapRef<typeof import('vue')['resolveComponent']>
readonly shallowReactive: UnwrapRef<typeof import('vue')['shallowReactive']>
readonly shallowReadonly: UnwrapRef<typeof import('vue')['shallowReadonly']>
readonly shallowRef: UnwrapRef<typeof import('vue')['shallowRef']>
readonly toRaw: UnwrapRef<typeof import('vue')['toRaw']>
readonly toRef: UnwrapRef<typeof import('vue')['toRef']>
readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
readonly unref: UnwrapRef<typeof import('vue')['unref']>
readonly useAttrs: UnwrapRef<typeof import('vue')['useAttrs']>
readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
readonly useRoute: UnwrapRef<typeof import('vue-router/auto')['useRoute']>
readonly useRouter: UnwrapRef<typeof import('vue-router/auto')['useRouter']>
readonly useSlots: UnwrapRef<typeof import('vue')['useSlots']>
readonly watch: UnwrapRef<typeof import('vue')['watch']>
readonly watchEffect: UnwrapRef<typeof import('vue')['watchEffect']>
readonly watchPostEffect: UnwrapRef<typeof import('vue')['watchPostEffect']>
readonly watchSyncEffect: UnwrapRef<typeof import('vue')['watchSyncEffect']>
}
}

View File

@ -11,7 +11,13 @@
</v-avatar>
</template>
<v-list-item-title>{{ c.name }}</v-list-item-title>
<v-list-item-subtitle>{{ c.created_at }}</v-list-item-subtitle>
<v-list-item-subtitle>
<span>{{ c.created_at }}</span>
&nbsp;
<span v-if="c.owner == 'guest'">访客对话</span>
<span v-else-if="c.owner == 'user'">用户对话</span>
<span v-else>{{ c.owner }}</span>
</v-list-item-subtitle>
</v-list-item>
</v-slide-y-transition>
</div>
@ -37,7 +43,7 @@ import { ref } from "vue";
import { api } from "@/plugins/api";
import {
ApiV1AssistantsPost200Response,
ApiV1ChatsGet200Response,
ApiV1ChatPublicGet200Response,
RagNewInternalSchemaChatCreateRequest,
} from "@/api";
import router from "@/router";
@ -45,7 +51,7 @@ import { useChatStore } from "../../../stores/chat";
// @ts-ignore
const assistantId = router.currentRoute.value.params.id as number;
const assistant: Ref<ApiV1AssistantsPost200Response> = ref({});
const chats = ref<ApiV1ChatsGet200Response>({});
const chats = ref<ApiV1ChatPublicGet200Response>({});
const dialog = ref(false);
const chat: Ref<RagNewInternalSchemaChatCreateRequest> = ref({

View File

@ -1,6 +1,12 @@
<template>
<h3>助理 {{ assistant.data?.name }}</h3>
<div class="mb-3">
<v-btn color="primary" @click="to('/assistants/' + assistantId + '/shares')"
>公开发布助理</v-btn
>
</div>
<v-text-field
v-if="assistant.data != null"
v-model="assistant.data.name"
@ -164,5 +170,9 @@ function updateAssistant() {
api.Assistant.apiV1AssistantsIdPatch(assistantId, assistantUpdate);
}
function to(path: string) {
router.push(path);
}
refresh();
</script>

View File

@ -0,0 +1,91 @@
<template>
<h3>共享助理 {{ assistant.data?.name }}</h3>
<v-btn color="primary" @click="createShare">创建共享</v-btn>
<div class="mt-3">
<p class="mb-3">共享列表</p>
<v-row>
<v-col
v-for="s in assistantShares.data"
:key="s.id"
cols="12"
md="4"
sm="6"
>
<v-card>
<v-card-text>
<p>Api Key: {{ s.token }}</p>
</v-card-text>
<v-card-actions>
<v-btn color="primary" @click="goto(s.token ?? 0)">访问共享</v-btn>
<v-btn color="error" @click="deleteShare(s.id ?? 0)"
>删除共享</v-btn
>
</v-card-actions>
</v-card>
</v-col>
</v-row>
</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { api } from "@/plugins/api";
import router from "@/router";
import {
ApiV1AssistantsIdSharesGet200Response,
ApiV1AssistantsPost200Response,
} from "@/api";
// @ts-ignore
const assistantId = router.currentRoute.value.params.id as number;
const assistant: Ref<ApiV1AssistantsPost200Response> = ref({
data: {
name: "",
description: "",
prompt: "",
},
});
const assistantShares: Ref<ApiV1AssistantsIdSharesGet200Response> = ref({});
function getAssistant() {
api.Assistant.apiV1AssistantsIdGet(assistantId).then((res) => {
assistant.value = res.data;
});
}
function getAssistantShare() {
api.Assistant.apiV1AssistantsIdSharesGet(assistantId).then((res) => {
assistantShares.value = res.data;
});
}
function refresh() {
getAssistant();
getAssistantShare();
}
function createShare() {
api.Assistant.apiV1AssistantsIdSharesPost(assistantId).then(() => {
getAssistantShare();
});
}
function deleteShare(shareId: number) {
api.Assistant.apiV1AssistantsIdSharesShareIdDelete(assistantId, shareId).then(
() => {
getAssistantShare();
},
);
}
function goto(token: any) {
const a = document.createElement("a");
a.target = "_blank";
a.href = `/public_chat?assistant_token=${token}`;
a.click();
}
refresh();
</script>

View File

@ -69,18 +69,18 @@
</template>
<script setup lang="ts">
import { ApiV1ChatsIdMessagesGet200Response } from "@/api";
import { ref } from "vue";
import { api, conf } from "@/plugins/api";
import VueMarkdown from "vue-markdown-render";
import router from "@/router";
import { useChatStore } from "@/stores/chat";
import { ApiV1ChatPublicChatIdMessagesGet200Response } from "@/api";
const chatStore = useChatStore();
// @ts-ignore
const chatId = parseInt(useRoute().params.id as string);
const messages: Ref<ApiV1ChatsIdMessagesGet200Response> = ref({
const messages: Ref<ApiV1ChatPublicChatIdMessagesGet200Response> = ref({
data: [],
});
const input = ref("");

View File

@ -0,0 +1,267 @@
<template>
<div>
<h3 class="mb-3">聊天记录</h3>
<v-card
v-for="message in messages.data"
:key="message.id"
class="mx-auto mt-3"
width="100%"
>
<template #title>
<div class="font-weight-black">
<div v-if="message.role == 'assistant'">AI</div>
<div v-else-if="message.role == 'system'">系统</div>
<div v-else-if="message.role == 'user'" class="text-right">用户</div>
<div v-else>
{{ message.role }}
</div>
</div>
</template>
<v-card-text class="bg-surface-light pt-4">
<div
v-if="message.role == 'assistant' || message.role == 'system'"
class="text-left"
>
<vue-markdown :source="message.content" />
</div>
<div v-else-if="message.role == 'user'" class="text-right">
<vue-markdown :source="message.content" />
</div>
<div v-else>
{{ message.content }}
</div>
</v-card-text>
</v-card>
<div class="mt-3">
<div v-if="toolError" class="mb-3">
<v-alert
density="compact"
text="这个工具出现了异常,这应该不是我们的问题,如果你是此工具的开发者,请打开开发者控制台查看具体错误。"
:title="'工具 ' + toolName + ' 出现异常'"
type="warning"
></v-alert>
</div>
<div v-show="toolCalling">
<v-progress-circular
color="primary"
indeterminate
:size="16"
></v-progress-circular>
正在执行 {{ toolName }}
</div>
<v-text-field
v-model="input"
label="输入消息"
@keyup.enter="sendMessage"
></v-text-field>
<v-btn color="primary" @click="sendMessage">发送</v-btn>
<v-btn class="ml-2" color="primary" @click="clearMessages">清空</v-btn>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { api, conf } from "@/plugins/api";
import VueMarkdown from "vue-markdown-render";
import router from "@/router";
import {
ApiV1ChatPublicChatIdMessagesGet200Response,
RagNewInternalSchemaChatPublicRequest,
RagNewInternalSchemaGetPublicChatMessageRequest,
} from "@/api";
import { usePublicChatStore } from "@/stores/public_chat";
const publicChatStore = usePublicChatStore();
if (publicChatStore.guest_id === "") {
publicChatStore.generateGuestId();
}
const chatId = ref(0);
//
const queries = new URLSearchParams(window.location.search);
const requiredQuries = ["assistant_token"];
for (const query of requiredQuries) {
if (!queries.has(query)) {
router.push("/");
}
}
const messages: Ref<ApiV1ChatPublicChatIdMessagesGet200Response> = ref({
data: [],
});
const publicChatInfo: Ref<RagNewInternalSchemaGetPublicChatMessageRequest> =
ref({
assistant_token: queries.get("assistant_token") as string,
guest_id: publicChatStore.guest_id,
});
const currentDate = new Date();
const publicNewChat: Ref<RagNewInternalSchemaChatPublicRequest> = ref({
assistant_token: publicChatInfo.value.assistant_token,
name: currentDate.toLocaleDateString() + " 时的对话",
guest_id: publicChatStore.guest_id,
});
const input = ref("");
const toolName = ref("");
const toolError = ref(false);
const toolCalling = ref(false);
function sendMessage() {
if (input.value !== "") {
toolError.value = false;
api.ChatPublic.apiV1ChatPublicChatIdMessagesPost(chatId.value, {
message: input.value,
assistant_token: publicChatInfo.value.assistant_token,
guest_id: publicChatStore.guest_id,
})
.then((res) => {
const newMessage = {
content: input.value,
role: "user",
};
if (messages.value.data == null) {
messages.value.data = [newMessage];
} else {
messages.value.data?.push(newMessage);
}
const streamId = res.data.data?.stream_id;
if (streamId) {
streamChat(streamId);
}
})
.catch((err) => {
// if 409
if (err.response.status === 409) {
const streamId = err.response.data.data?.stream_id;
if (streamId) {
streamChat(streamId);
}
}
});
}
}
function streamChat(streamId: String) {
const url = conf.basePath + "/api/v1/stream/" + streamId;
const evtSource = new EventSource(url);
let messageAdded = false;
//
window.scrollTo(0, document.body.scrollHeight);
let i = 0;
evtSource.addEventListener("data", (e) => {
const data = JSON.parse(e.data);
console.log(data.state);
let append = true;
switch (data.state) {
case "tool_calling":
toolCalling.value = true;
toolName.value =
data.tool_call_message.tool_name +
" 中的 " +
data.tool_call_message.function_name;
break;
case "tool_response":
setTimeout(() => {
toolName.value = "";
toolCalling.value = false;
}, 300);
break;
case "tool_failed":
toolName.value =
data.tool_response_message.tool_name +
" 中的 " +
data.tool_response_message.function_name;
toolError.value = true;
append = false;
setTimeout(() => {
toolCalling.value = false;
}, 300);
break;
case "chunk":
if (!messageAdded) {
const newMessage = {
content: "",
role: "assistant",
};
if (messages.value.data == null) {
messages.value.data = [newMessage];
} else {
// add to messages
messages.value.data?.push(newMessage);
}
messageAdded = true;
append = true;
// set index
i = (messages.value.data?.length ?? 1) - 1;
}
}
if (append && messageAdded) {
// @ts-ignore
messages.value.data[i].content += data.content;
}
});
// close
evtSource.addEventListener("close", () => {
evtSource.close();
});
}
const getMessages = () => {
api.ChatPublic.apiV1ChatPublicChatIdMessagesGet(
chatId.value,
publicChatInfo.value.assistant_token,
publicChatInfo.value.guest_id,
).then((res) => {
messages.value = res.data;
});
};
const clearMessages = () => {
api.ChatPublic.apiV1ChatPublicChatIdClearPost(
chatId.value,
publicChatInfo.value,
).then(() => {
getMessages();
});
};
const createChat = () => {
api.ChatPublic.apiV1ChatPublicPost(publicNewChat.value).then((res) => {
if (res.data.data?.id) {
chatId.value = res.data.data.id;
}
getMessages();
});
};
createChat();
</script>

View File

@ -2,6 +2,7 @@ import {
AssistantApi,
ChatApi,
ChatMessageApi,
ChatPublicApi,
Configuration,
PingApi,
ToolApi,
@ -29,6 +30,7 @@ const api = {
Ping: new PingApi(conf),
Tool: new ToolApi(conf),
ChatMessage: new ChatMessageApi(conf),
ChatPublic: new ChatPublicApi(conf),
};
export { api, conf };

13
src/stores/public_chat.ts Normal file
View File

@ -0,0 +1,13 @@
import { defineStore } from "pinia";
export const usePublicChatStore = defineStore("public_chat", {
persist: true,
state: () => ({
guest_id: "",
}),
actions: {
generateGuestId() {
this.guest_id = Math.random().toString(36).substring(2, 12);
},
},
});

View File

@ -22,11 +22,13 @@ declare module 'vue-router/auto-routes' {
'/assistants/': RouteRecordInfo<'/assistants/', '/assistants', Record<never, never>, Record<never, never>>,
'/assistants/[id]/chats': RouteRecordInfo<'/assistants/[id]/chats', '/assistants/:id/chats', { id: ParamValue<true> }, { id: ParamValue<false> }>,
'/assistants/[id]/edit': RouteRecordInfo<'/assistants/[id]/edit', '/assistants/:id/edit', { id: ParamValue<true> }, { id: ParamValue<false> }>,
'/assistants/[id]/shares': RouteRecordInfo<'/assistants/[id]/shares', '/assistants/:id/shares', { id: ParamValue<true> }, { id: ParamValue<false> }>,
'/assistants/create': RouteRecordInfo<'/assistants/create', '/assistants/create', Record<never, never>, Record<never, never>>,
'/auth/callback': RouteRecordInfo<'/auth/callback', '/auth/callback', Record<never, never>, Record<never, never>>,
'/auth/login': RouteRecordInfo<'/auth/login', '/auth/login', Record<never, never>, Record<never, never>>,
'/chats/[id]/': RouteRecordInfo<'/chats/[id]/', '/chats/:id', { id: ParamValue<true> }, { id: ParamValue<false> }>,
'/ping/': RouteRecordInfo<'/ping/', '/ping', Record<never, never>, Record<never, never>>,
'/public_chat/': RouteRecordInfo<'/public_chat/', '/public_chat', Record<never, never>, Record<never, never>>,
'/tools/': RouteRecordInfo<'/tools/', '/tools', Record<never, never>, Record<never, never>>,
'/tools/create': RouteRecordInfo<'/tools/create', '/tools/create', Record<never, never>, Record<never, never>>,
'/tools/validate': RouteRecordInfo<'/tools/validate', '/tools/validate', Record<never, never>, Record<never, never>>,