@glodon-aiot/agent-cli-sdk 3.0.9 → 3.0.10-beta.1
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/cdn/agent-cli-sdk.js +34022 -0
- package/cdn/agent-cli-sdk.umd.cjs +145 -0
- package/cdn/src/AgentPlugin.d.ts +17 -0
- package/cdn/src/AgentSession.d.ts +9 -0
- package/cdn/src/BotClient.d.ts +48 -0
- package/cdn/src/Config.d.ts +32 -0
- package/cdn/src/DialogSession.d.ts +22 -0
- package/cdn/src/EventBus.d.ts +23 -0
- package/cdn/src/Logger.d.ts +12 -0
- package/cdn/src/PayloadTypes.d.ts +84 -0
- package/cdn/src/Session.d.ts +209 -0
- package/cdn/src/api/fetchEventSource/fetch.d.ts +44 -0
- package/cdn/src/api/fetchEventSource/index.d.ts +1 -0
- package/cdn/src/api/fetchEventSource/parse.d.ts +36 -0
- package/cdn/src/api/index.d.ts +2 -0
- package/cdn/src/index.d.ts +5 -0
- package/cdn/src/utils.d.ts +4 -0
- package/dist/es/AgentPlugin.mjs +20 -0
- package/dist/es/AgentSession.mjs +246 -0
- package/dist/es/BotClient.mjs +236 -0
- package/dist/es/Config.mjs +34 -0
- package/dist/es/DialogSession.mjs +274 -0
- package/dist/es/EventBus.mjs +64 -0
- package/dist/es/Logger.mjs +31 -0
- package/dist/es/PayloadTypes.mjs +4 -0
- package/dist/es/Session.mjs +690 -0
- package/dist/es/api/fetchEventSource/fetch.mjs +112 -0
- package/dist/es/api/fetchEventSource/parse.mjs +97 -0
- package/dist/es/api/index.mjs +41 -0
- package/dist/es/index.mjs +11 -0
- package/dist/es/node_modules/@socket.io/component-emitter/lib/esm/index.mjs +54 -0
- package/dist/es/node_modules/engine.io-client/build/esm/contrib/has-cors.mjs +9 -0
- package/dist/es/node_modules/engine.io-client/build/esm/contrib/parseqs.mjs +18 -0
- package/dist/es/node_modules/engine.io-client/build/esm/contrib/parseuri.mjs +24 -0
- package/dist/es/node_modules/engine.io-client/build/esm/contrib/yeast.mjs +19 -0
- package/dist/es/node_modules/engine.io-client/build/esm/globalThis.browser.mjs +4 -0
- package/dist/es/node_modules/engine.io-client/build/esm/socket.mjs +317 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transport.mjs +113 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/index.mjs +11 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/polling.mjs +273 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/websocket-constructor.browser.mjs +8 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/websocket.mjs +87 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/webtransport.mjs +52 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/xmlhttprequest.browser.mjs +21 -0
- package/dist/es/node_modules/engine.io-client/build/esm/util.mjs +23 -0
- package/dist/es/node_modules/engine.io-parser/build/esm/commons.mjs +21 -0
- package/dist/es/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.mjs +14 -0
- package/dist/es/node_modules/engine.io-parser/build/esm/decodePacket.browser.mjs +39 -0
- package/dist/es/node_modules/engine.io-parser/build/esm/encodePacket.browser.mjs +28 -0
- package/dist/es/node_modules/engine.io-parser/build/esm/index.mjs +105 -0
- package/dist/es/node_modules/js-base64/base64.mjs +31 -0
- package/dist/es/node_modules/socket.io-client/build/esm/contrib/backo2.mjs +26 -0
- package/dist/es/node_modules/socket.io-client/build/esm/index.mjs +25 -0
- package/dist/es/node_modules/socket.io-client/build/esm/manager.mjs +242 -0
- package/dist/es/node_modules/socket.io-client/build/esm/on.mjs +8 -0
- package/dist/es/node_modules/socket.io-client/build/esm/socket.mjs +608 -0
- package/dist/es/node_modules/socket.io-client/build/esm/url.mjs +19 -0
- package/dist/es/node_modules/socket.io-parser/build/esm/binary.mjs +52 -0
- package/dist/es/node_modules/socket.io-parser/build/esm/index.mjs +203 -0
- package/dist/es/node_modules/socket.io-parser/build/esm/is-binary.mjs +26 -0
- package/dist/es/node_modules/uuid/dist/esm-browser/native.mjs +6 -0
- package/dist/es/node_modules/uuid/dist/esm-browser/rng.mjs +10 -0
- package/dist/es/node_modules/uuid/dist/esm-browser/stringify.mjs +9 -0
- package/dist/es/node_modules/uuid/dist/esm-browser/v4.mjs +19 -0
- package/dist/es/utils.mjs +11 -0
- package/dist/lib/index.js +4 -0
- package/dist/src/AgentSession.d.ts +2 -2
- package/dist/src/BotClient.d.ts +2 -2
- package/dist/src/DialogSession.d.ts +2 -2
- package/dist/src/Session.d.ts +9 -11
- package/dist/src/api/fetchEventSource/fetch.d.ts +1 -1
- package/dist/src/api/fetchEventSource/index.d.ts +1 -1
- package/package.json +18 -11
- package/dist/agent-cli-sdk.js +0 -33144
- package/dist/agent-cli-sdk.umd.cjs +0 -140
- package/dist/src/__ tests __/AgentClient.spec.d.ts +0 -1
- package/dist/src/__ tests __/AgentSession.spec.d.ts +0 -1
- package/dist/src/__ tests __/DialogClient.spec.d.ts +0 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AgentPluginRegistor } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Class AgentPlugin
|
|
4
|
+
* 提供获取插件数据、检测客户端插件等功能
|
|
5
|
+
*/
|
|
6
|
+
interface AgentPluginDetails {
|
|
7
|
+
}
|
|
8
|
+
export default class AgentPlugin {
|
|
9
|
+
code: string;
|
|
10
|
+
description: string;
|
|
11
|
+
loaded: boolean;
|
|
12
|
+
functions: AgentPluginRegistor;
|
|
13
|
+
constructor(code: any, functions?: AgentPluginRegistor, initalData?: AgentPluginDetails);
|
|
14
|
+
fetchData(): void;
|
|
15
|
+
checkFunctions(): void;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IApplication, ISession } from '@glodon-aiot/apis';
|
|
2
|
+
import Session, { QuestionBody, QuestionConfig } from './Session';
|
|
3
|
+
import BotClient from './BotClient';
|
|
4
|
+
export default class AgentSession extends Session {
|
|
5
|
+
constructor(token: string, _id?: string, _data?: Partial<ISession>, lazyload?: boolean, application?: IApplication, client?: BotClient);
|
|
6
|
+
prepareConnection(): Promise<boolean>;
|
|
7
|
+
sendQuestion(questionBody: QuestionBody, configs: QuestionConfig): Promise<false | undefined>;
|
|
8
|
+
stopAnswer(): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import Session from './Session';
|
|
2
|
+
import { BotClientConfig } from './Config';
|
|
3
|
+
import { IApplication, IPrompt, ISession, ISessionPrompt, SessionQueryParams } from '@glodon-aiot/apis';
|
|
4
|
+
import EventBus from './EventBus';
|
|
5
|
+
export type ClientEventName = 'ready' | 'application:loaded';
|
|
6
|
+
export default class BotClient {
|
|
7
|
+
private _token;
|
|
8
|
+
private lazyload;
|
|
9
|
+
protected event: EventBus;
|
|
10
|
+
private cvforceApi;
|
|
11
|
+
private _applicationId;
|
|
12
|
+
private _application;
|
|
13
|
+
private _sessions;
|
|
14
|
+
private _activeSession?;
|
|
15
|
+
private _ready?;
|
|
16
|
+
private _questionContextMaxLength?;
|
|
17
|
+
private _promptVariables?;
|
|
18
|
+
constructor(_token: string, //AIoT resource token
|
|
19
|
+
configs: BotClientConfig, lazyload?: boolean);
|
|
20
|
+
private checkReady;
|
|
21
|
+
get ready(): boolean | undefined;
|
|
22
|
+
private set ready(value);
|
|
23
|
+
get questionContextMaxLength(): number | undefined;
|
|
24
|
+
get promptVariables(): IPrompt[] | undefined;
|
|
25
|
+
get knowledges(): any;
|
|
26
|
+
get sessions(): Session[];
|
|
27
|
+
set sessions(v: Session[]);
|
|
28
|
+
private loadApplication;
|
|
29
|
+
private getService;
|
|
30
|
+
get token(): string;
|
|
31
|
+
set token(v: string);
|
|
32
|
+
get applicationId(): string;
|
|
33
|
+
get application(): IApplication | null;
|
|
34
|
+
get activeSession(): string;
|
|
35
|
+
set activeSession(sessionId: string);
|
|
36
|
+
private createSession;
|
|
37
|
+
getSessions(queryParams?: SessionQueryParams): Promise<Session[]>;
|
|
38
|
+
loadSession(sessionId?: string, sessionParams?: Partial<ISession & {
|
|
39
|
+
promptVariables?: ISessionPrompt[];
|
|
40
|
+
}>): Promise<Session>;
|
|
41
|
+
reload(): Promise<this>;
|
|
42
|
+
reloadSession(sessionId?: string): Promise<Session | undefined>;
|
|
43
|
+
setTop(sessionId: string, top: boolean, order?: string): Promise<Session[] | undefined>;
|
|
44
|
+
addEventListener(eventName: ClientEventName, callback: any, once?: boolean): void;
|
|
45
|
+
removeEventListener(eventName: ClientEventName, callback: any): void;
|
|
46
|
+
removeSession(session: string | Session, deleteFromRemote?: boolean): Promise<void>;
|
|
47
|
+
clean(): void;
|
|
48
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface BotClientConfig {
|
|
2
|
+
debug?: boolean;
|
|
3
|
+
env?: Env;
|
|
4
|
+
applicationId?: string;
|
|
5
|
+
plugins?: AgentPluginMap;
|
|
6
|
+
apiRoot?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AgentPluginRegistor {
|
|
9
|
+
[key: string]: Function;
|
|
10
|
+
}
|
|
11
|
+
export interface AgentPluginMap {
|
|
12
|
+
[pluginCode: string]: AgentPluginRegistor;
|
|
13
|
+
}
|
|
14
|
+
export type Env = 'dev' | 'test' | 'prod' | 'local';
|
|
15
|
+
export declare enum ApiUrl {
|
|
16
|
+
dev = "https://aiot-dev.glodon.com/api/cvforcepd",
|
|
17
|
+
test = "https://aiot-dev.glodon.com/api/cvforce",
|
|
18
|
+
prod = "https://copilot.glodon.com/api/cvforce",
|
|
19
|
+
local = "http://localhost:3000/api/cvforcepd"
|
|
20
|
+
}
|
|
21
|
+
export declare let configuration: {
|
|
22
|
+
debug: boolean;
|
|
23
|
+
env: string;
|
|
24
|
+
apiRoot: string;
|
|
25
|
+
applicationId: string;
|
|
26
|
+
plugins: AgentPluginMap;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* 配置SDK,可以在SDK被使用前被调用,该方法被调用后将改变是否debug模式、是否测试环境等基本配置
|
|
30
|
+
* @param param {debug?: boolean; env?: 'dev' | 'test' | 'prod';}
|
|
31
|
+
*/
|
|
32
|
+
export declare function configure(param?: BotClientConfig): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IApplication, ISession } from '@glodon-aiot/apis';
|
|
2
|
+
import Session, { QuestionBody, QuestionConfig } from './Session';
|
|
3
|
+
import BotClient from './BotClient';
|
|
4
|
+
export default class DialogSession extends Session {
|
|
5
|
+
private ctrl;
|
|
6
|
+
constructor(token: string, _id?: string, _data?: Partial<ISession>, lazyload?: boolean, application?: IApplication, client?: BotClient);
|
|
7
|
+
prepareConnection(): Promise<boolean>;
|
|
8
|
+
postChatV2EventSource(applicationId: string, sessionId: string, params: any, signal: AbortSignal, options: {
|
|
9
|
+
onopen?: any;
|
|
10
|
+
onmessage?: any;
|
|
11
|
+
onerror?: any;
|
|
12
|
+
onclose?: any;
|
|
13
|
+
}, onAppStatusError?: (error: any) => void): Promise<void>;
|
|
14
|
+
postChatV3EventSource(applicationId: string, sessionId: string, params: any, signal: AbortSignal, options: {
|
|
15
|
+
onopen?: any;
|
|
16
|
+
onmessage?: any;
|
|
17
|
+
onerror?: any;
|
|
18
|
+
onclose?: any;
|
|
19
|
+
}, onAppStatusError?: (error: any) => void): Promise<void>;
|
|
20
|
+
sendQuestion(questionBody: QuestionBody, configs: QuestionConfig): Promise<void>;
|
|
21
|
+
stopAnswer(): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type Topic = string;
|
|
2
|
+
export interface ViewerEvent {
|
|
3
|
+
topic: Topic;
|
|
4
|
+
payload?: any;
|
|
5
|
+
}
|
|
6
|
+
export type EventListener = (e: any) => void;
|
|
7
|
+
interface SingleEventListener {
|
|
8
|
+
fn: EventListener;
|
|
9
|
+
once: true;
|
|
10
|
+
}
|
|
11
|
+
export default class EventBus {
|
|
12
|
+
private eventListenerMap;
|
|
13
|
+
constructor(disableLog?: boolean);
|
|
14
|
+
getEventListenerMap(): {
|
|
15
|
+
[x: string]: (SingleEventListener | EventListener)[];
|
|
16
|
+
};
|
|
17
|
+
on(topic: Topic, listener: EventListener, once?: boolean): void;
|
|
18
|
+
once(topic: Topic, listener: EventListener): void;
|
|
19
|
+
off(topic: Topic, listener: EventListener): void;
|
|
20
|
+
emit(topic: Topic, payload?: any): void;
|
|
21
|
+
removeAllListeners(): void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default class Logger {
|
|
2
|
+
private prefix;
|
|
3
|
+
private open;
|
|
4
|
+
static debug: boolean;
|
|
5
|
+
constructor(prefix: string, open?: boolean);
|
|
6
|
+
disable(): void;
|
|
7
|
+
enable(): void;
|
|
8
|
+
log(...rest: any[]): void;
|
|
9
|
+
info(...rest: any[]): void;
|
|
10
|
+
error(...rest: any[]): void;
|
|
11
|
+
warn(...rest: any[]): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare enum UserMode {
|
|
2
|
+
Normal = 0,
|
|
3
|
+
Debug = 1
|
|
4
|
+
}
|
|
5
|
+
export interface ReadyEventPayload {
|
|
6
|
+
/**
|
|
7
|
+
* 错误码如下:
|
|
8
|
+
* 200: 成功
|
|
9
|
+
* 11903: 密钥失效
|
|
10
|
+
* 11904: 参数异常
|
|
11
|
+
* 11905: token解析异常
|
|
12
|
+
* 11907: 未知错误
|
|
13
|
+
* 11913: 获取应用编排数据失败
|
|
14
|
+
* 11914: 获取大模型服务失败, 请检查
|
|
15
|
+
* 11924: 用户无此应用权限
|
|
16
|
+
*/
|
|
17
|
+
code: number;
|
|
18
|
+
message: string;
|
|
19
|
+
userMode: UserMode;
|
|
20
|
+
}
|
|
21
|
+
export interface PluginFunctionBasic {
|
|
22
|
+
pluginName: string;
|
|
23
|
+
pluginCode: string;
|
|
24
|
+
funcCode: string;
|
|
25
|
+
funcName: string;
|
|
26
|
+
parameters?: {
|
|
27
|
+
header: any;
|
|
28
|
+
query: any;
|
|
29
|
+
};
|
|
30
|
+
requestBody?: any;
|
|
31
|
+
runnerIsClient?: boolean;
|
|
32
|
+
result?: {
|
|
33
|
+
code: number;
|
|
34
|
+
message: string;
|
|
35
|
+
data: any;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface PluginFunctionBeforeCall extends PluginFunctionBasic {
|
|
39
|
+
parameters: {
|
|
40
|
+
header: any;
|
|
41
|
+
query: any;
|
|
42
|
+
};
|
|
43
|
+
requestBody: any;
|
|
44
|
+
}
|
|
45
|
+
export interface PluginFunctionCall extends PluginFunctionBasic {
|
|
46
|
+
parameters: {
|
|
47
|
+
header: any;
|
|
48
|
+
query: any;
|
|
49
|
+
};
|
|
50
|
+
requestBody: any;
|
|
51
|
+
runnerIsClient: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface PluginFunctionResult extends PluginFunctionBasic {
|
|
54
|
+
result: {
|
|
55
|
+
code: number;
|
|
56
|
+
message: string;
|
|
57
|
+
data: any;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface Thought {
|
|
61
|
+
step: number;
|
|
62
|
+
thought?: string;
|
|
63
|
+
observation?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface BeforeCalldData extends Thought, PluginFunctionBeforeCall {
|
|
66
|
+
thought: string;
|
|
67
|
+
observation: undefined;
|
|
68
|
+
}
|
|
69
|
+
export interface FunctionCallData extends Thought, PluginFunctionCall {
|
|
70
|
+
thought: string;
|
|
71
|
+
observation: undefined;
|
|
72
|
+
}
|
|
73
|
+
export interface CallResultData extends Thought, PluginFunctionResult {
|
|
74
|
+
thought: undefined;
|
|
75
|
+
observation: undefined;
|
|
76
|
+
}
|
|
77
|
+
export interface AfterCallData extends Thought, PluginFunctionBasic {
|
|
78
|
+
thought: undefined;
|
|
79
|
+
observation: string;
|
|
80
|
+
}
|
|
81
|
+
export interface ActionPayload<T> {
|
|
82
|
+
type: 'BEFORE_CALL' | 'FUNCTION_CALL' | 'RESULT' | 'AFTER_CALL';
|
|
83
|
+
data: T;
|
|
84
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { ChatMessageRole, IApplication, IChatMessage, ICommentParam, ISession, ISessionPrompt } from '@glodon-aiot/apis';
|
|
2
|
+
import { Socket } from 'socket.io-client';
|
|
3
|
+
import EventBus from './EventBus';
|
|
4
|
+
import { ActionPayload, PluginFunctionBasic, Thought } from './PayloadTypes';
|
|
5
|
+
import { CVForceApi } from '@glodon-aiot/apis';
|
|
6
|
+
import { ChatHistoryParams, IKnowledge } from '@glodon-aiot/apis';
|
|
7
|
+
import BotClient from './BotClient';
|
|
8
|
+
export declare enum NetOpen {
|
|
9
|
+
enable = 1,
|
|
10
|
+
disable = 2
|
|
11
|
+
}
|
|
12
|
+
export interface QuestionBody {
|
|
13
|
+
content: string;
|
|
14
|
+
stream: boolean;
|
|
15
|
+
requestId?: string;
|
|
16
|
+
fileIds?: string[];
|
|
17
|
+
oldMessageId?: string;
|
|
18
|
+
referenceFirst?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface QuestionConfig {
|
|
21
|
+
stream?: boolean;
|
|
22
|
+
referenceFirst?: boolean;
|
|
23
|
+
formatValues?: any;
|
|
24
|
+
oldMessageId?: string;
|
|
25
|
+
}
|
|
26
|
+
type ActionPayloadBasic = ActionPayload<PluginFunctionBasic & Thought>;
|
|
27
|
+
export type SessionEventName = 'init' | 'ready' | 'activated' | 'inactivated' | 'frozen' | 'data:loading' | 'data:loaded' | 'data:updating' | 'data:updated' | 'data:updated:promptVariables' | 'data:updated:knowledges' | 'data:creating' | 'data:created' | 'data:deleting' | 'data:deleted' | 'socket:connect' | 'socket:disconnect' | 'error' | 'destroy' | 'history:loading' | 'history:loaded' | 'history:moreloading' | 'history:moreloaded' | 'history:add' | 'message:new' | 'message:updated' | 'message:action' | 'message:content' | 'message:reference' | 'message:relatedQuesion:loading' | 'message:relatedQuesion:loaded' | 'message:comment' | 'message:error' | 'answer:finish';
|
|
28
|
+
export declare enum SessionErrors {
|
|
29
|
+
DataRequestFailed = "data request error",
|
|
30
|
+
SocketConnectionFailed = "socket error",
|
|
31
|
+
IdUndefined = "session id is not defined",
|
|
32
|
+
SendingEmptyContent = "failed at sending empty content",
|
|
33
|
+
Frozen = "session is frozen",
|
|
34
|
+
UserModeError = "failed at setting socket user mode",
|
|
35
|
+
Inactive = "session is inactive"
|
|
36
|
+
}
|
|
37
|
+
export declare const SESSION_ERROR_CAUSE: {
|
|
38
|
+
"session id is not defined": {
|
|
39
|
+
code: number;
|
|
40
|
+
message: string;
|
|
41
|
+
};
|
|
42
|
+
"failed at sending empty content": {
|
|
43
|
+
code: number;
|
|
44
|
+
message: string;
|
|
45
|
+
};
|
|
46
|
+
"session is frozen": {
|
|
47
|
+
code: number;
|
|
48
|
+
message: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export default abstract class Session {
|
|
52
|
+
protected token: string;
|
|
53
|
+
protected lazyload?: boolean | undefined;
|
|
54
|
+
protected _id?: string;
|
|
55
|
+
protected _frozen: boolean;
|
|
56
|
+
protected inactivating: boolean;
|
|
57
|
+
protected _ready: boolean;
|
|
58
|
+
protected event: EventBus;
|
|
59
|
+
_applicationId: string;
|
|
60
|
+
_application: IApplication | null;
|
|
61
|
+
data: ISession | null;
|
|
62
|
+
readonly client: BotClient | null;
|
|
63
|
+
messages: IChatMessage[];
|
|
64
|
+
protected _loadingMessages: boolean;
|
|
65
|
+
protected _loadingMessagesSize: number;
|
|
66
|
+
cvforceApi: CVForceApi;
|
|
67
|
+
socket: Socket | null;
|
|
68
|
+
protected _promptVariables: ISessionPrompt[];
|
|
69
|
+
protected active: boolean;
|
|
70
|
+
protected activing: boolean;
|
|
71
|
+
protected _stopAnswer: boolean;
|
|
72
|
+
private _dataLoading;
|
|
73
|
+
private _dataLoaded;
|
|
74
|
+
/**
|
|
75
|
+
* Session 类的构造函数,用于初始化会话实例。
|
|
76
|
+
* @param token - 用户的身份验证令牌,用于解析应用 ID。
|
|
77
|
+
* @param _id - 会话的 ID,可选参数,默认为空字符串。
|
|
78
|
+
* @param _data - 会话的初始数据,可选参数,包含提示变量、知识库等信息。
|
|
79
|
+
* @param lazyload - 是否懒加载数据,可选参数,默认为 undefined。
|
|
80
|
+
* @param _application - 应用信息,可选参数。
|
|
81
|
+
* @param client - Bot 客户端实例,可选参数。
|
|
82
|
+
*/
|
|
83
|
+
constructor(token: string, _id?: string, _data?: Partial<ISession & {
|
|
84
|
+
promptVariables?: Partial<ISessionPrompt>[];
|
|
85
|
+
}>, lazyload?: boolean | undefined, _application?: IApplication, client?: BotClient);
|
|
86
|
+
fetchData(): Promise<ISession>;
|
|
87
|
+
get id(): string;
|
|
88
|
+
get applicationId(): string;
|
|
89
|
+
get application(): IApplication | null;
|
|
90
|
+
loadApplicationInfo(): Promise<IApplication>;
|
|
91
|
+
get ready(): boolean;
|
|
92
|
+
get frozen(): boolean;
|
|
93
|
+
protected set frozen(v: boolean);
|
|
94
|
+
get knowledges(): IKnowledge[] | undefined;
|
|
95
|
+
setKnowledges(knowledges?: IKnowledge[]): Promise<IKnowledge[] | undefined>;
|
|
96
|
+
validateConfigs(): void;
|
|
97
|
+
get promptVariables(): ISessionPrompt[];
|
|
98
|
+
setPromptVariables(v: ISessionPrompt[]): Promise<ISessionPrompt[] | undefined>;
|
|
99
|
+
get netOpen(): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* 异步设置会话的网络访问开关状态
|
|
102
|
+
* @param v - 布尔值,表示是否开启网络访问,true 为开启,false 为关闭
|
|
103
|
+
* @returns 如果设置成功,返回最终的网络访问开关状态;若不满足设置条件,则提前返回 undefined
|
|
104
|
+
*/
|
|
105
|
+
setNetOpen(v: boolean): Promise<boolean | undefined>;
|
|
106
|
+
private getService;
|
|
107
|
+
addEventListener(eventName: SessionEventName, callback: any, once?: boolean): void;
|
|
108
|
+
removeEventListener(eventName: SessionEventName, callback: any): void;
|
|
109
|
+
/**
|
|
110
|
+
* 获取对话记录
|
|
111
|
+
* @param params ChatHistoryParams
|
|
112
|
+
* @returns Promise<false|Message[]>
|
|
113
|
+
*/
|
|
114
|
+
fetchMessages(params?: ChatHistoryParams): Promise<false | {
|
|
115
|
+
actions: ActionPayloadBasic[][];
|
|
116
|
+
relatedQuesion: string[] | undefined;
|
|
117
|
+
ts?: string | undefined;
|
|
118
|
+
messageId: string;
|
|
119
|
+
content: string;
|
|
120
|
+
role: ChatMessageRole;
|
|
121
|
+
userId?: string | undefined;
|
|
122
|
+
sessionId: string;
|
|
123
|
+
reference: import("@glodon-aiot/apis").IReference[];
|
|
124
|
+
searchReference: import("@glodon-aiot/apis").ISearchRefernce[];
|
|
125
|
+
comment?: import("@glodon-aiot/apis/dist/src/cvforce").ICommentParam | undefined;
|
|
126
|
+
knowledges?: IKnowledge[] | undefined;
|
|
127
|
+
isLoading?: boolean | undefined;
|
|
128
|
+
messageTime: string;
|
|
129
|
+
fileId?: string | undefined;
|
|
130
|
+
file?: import("@glodon-aiot/apis/dist/src/cvforce").KnowledgeFileMetadata | undefined;
|
|
131
|
+
chatMode?: import("@glodon-aiot/apis").ChatMode | undefined;
|
|
132
|
+
llmModel?: string | undefined;
|
|
133
|
+
isContext?: boolean | undefined;
|
|
134
|
+
index?: number | undefined;
|
|
135
|
+
agentHistoryList?: {
|
|
136
|
+
agentList: string;
|
|
137
|
+
createdAt: string;
|
|
138
|
+
creator: string;
|
|
139
|
+
deletedAt: string;
|
|
140
|
+
id: string;
|
|
141
|
+
updatedAt: string;
|
|
142
|
+
} | undefined;
|
|
143
|
+
finish?: boolean | undefined;
|
|
144
|
+
code?: number | undefined;
|
|
145
|
+
isSensitive?: boolean | undefined;
|
|
146
|
+
message?: string | undefined;
|
|
147
|
+
stream?: boolean | undefined;
|
|
148
|
+
fileIds?: string[] | undefined;
|
|
149
|
+
isReplying?: boolean | undefined;
|
|
150
|
+
files?: import("@glodon-aiot/apis").ChatMessageFile[] | undefined;
|
|
151
|
+
thinkingSecs?: number | undefined;
|
|
152
|
+
thinkingStatus?: "end" | "start" | undefined;
|
|
153
|
+
reasoningContent?: string | undefined;
|
|
154
|
+
}[]>;
|
|
155
|
+
rename(name: string): Promise<boolean>;
|
|
156
|
+
protected pushMessage(message: IChatMessage): Promise<void>;
|
|
157
|
+
reloadSessionInfo(): Promise<this>;
|
|
158
|
+
reload(): Promise<unknown>;
|
|
159
|
+
delete(): Promise<string | false>;
|
|
160
|
+
activate(): Promise<unknown>;
|
|
161
|
+
inactivate(immediately?: boolean): boolean;
|
|
162
|
+
abstract prepareConnection(): Promise<boolean>;
|
|
163
|
+
abstract sendQuestion(params: QuestionBody, configs: QuestionConfig): any;
|
|
164
|
+
abstract stopAnswer(): any;
|
|
165
|
+
get dataLoaded(): boolean;
|
|
166
|
+
get messagesLoading(): boolean;
|
|
167
|
+
send(params: {
|
|
168
|
+
text?: string;
|
|
169
|
+
uuid?: string;
|
|
170
|
+
fileIds?: string[];
|
|
171
|
+
}, configs?: QuestionConfig): Promise<false | {
|
|
172
|
+
sessionId: string;
|
|
173
|
+
role: number;
|
|
174
|
+
content: string;
|
|
175
|
+
messageId: string;
|
|
176
|
+
reference: never[];
|
|
177
|
+
searchReference: never[];
|
|
178
|
+
messageTime: string;
|
|
179
|
+
}>;
|
|
180
|
+
protected getRelatedQuesion(message: IChatMessage): Promise<IChatMessage>;
|
|
181
|
+
protected fillMessageReference(message: IChatMessage): Promise<IChatMessage>;
|
|
182
|
+
answerAgain(configs?: QuestionConfig): Promise<void>;
|
|
183
|
+
setTop(top: boolean): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* 暂停当前会话的回答过程
|
|
186
|
+
* 该方法会停止当前回答,标记回答停止状态,处理正在进行的消息和操作,
|
|
187
|
+
* 并根据情况更新消息内容或添加新的系统消息。
|
|
188
|
+
* @returns 返回当前会话实例
|
|
189
|
+
*/
|
|
190
|
+
suspend(): this | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* 异步提交评论信息
|
|
193
|
+
* @param params - 评论参数,包含评论相关的信息,如消息 ID 等
|
|
194
|
+
* @returns 返回调用 API 提交评论后的响应结果
|
|
195
|
+
*/
|
|
196
|
+
postMessageComment(params: ICommentParam): Promise<string>;
|
|
197
|
+
/**
|
|
198
|
+
* 清除当前会话的上下文信息
|
|
199
|
+
* 该方法会调用 API 清除指定会话的上下文,并在操作成功后触发相应事件
|
|
200
|
+
* @returns 如果会话 ID 存在且清除操作成功,返回一个解析为 true 的 Promise;若会话 ID 不存在,抛出错误
|
|
201
|
+
*/
|
|
202
|
+
clear(): Promise<boolean>;
|
|
203
|
+
/**
|
|
204
|
+
* 销毁当前会话实例,执行清理操作并触发销毁事件
|
|
205
|
+
* @returns 返回当前会话的 ID,如果会话 ID 不存在则返回空字符串
|
|
206
|
+
*/
|
|
207
|
+
destroy(): string;
|
|
208
|
+
}
|
|
209
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { EventSourceMessage } from "./parse";
|
|
2
|
+
export declare const EventStreamContentType = "text/event-stream";
|
|
3
|
+
export interface FetchEventSourceInit extends RequestInit {
|
|
4
|
+
/**
|
|
5
|
+
* The request headers. FetchEventSource only supports the Record<string,string> format.
|
|
6
|
+
*/
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
/**
|
|
9
|
+
* Called when a response is received. Use this to validate that the response
|
|
10
|
+
* actually matches what you expect (and throw if it doesn't.) If not provided,
|
|
11
|
+
* will default to a basic validation to ensure the content-type is text/event-stream.
|
|
12
|
+
*/
|
|
13
|
+
onopen?: (response: Response) => Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Called when a message is received. NOTE: Unlike the default browser
|
|
16
|
+
* EventSource.onmessage, this callback is called for _all_ events,
|
|
17
|
+
* even ones with a custom `event` field.
|
|
18
|
+
*/
|
|
19
|
+
onmessage?: (ev: EventSourceMessage) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Called when a response finishes. If you don't expect the server to kill
|
|
22
|
+
* the connection, you can throw an exception here and retry using onerror.
|
|
23
|
+
*/
|
|
24
|
+
onclose?: () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Called when there is any error making the request / processing messages /
|
|
27
|
+
* handling callbacks etc. Use this to control the retry strategy: if the
|
|
28
|
+
* error is fatal, rethrow the error inside the callback to stop the entire
|
|
29
|
+
* operation. Otherwise, you can return an interval (in milliseconds) after
|
|
30
|
+
* which the request will automatically retry (with the last-event-id).
|
|
31
|
+
* If this callback is not specified, or it returns undefined, fetchEventSource
|
|
32
|
+
* will treat every error as retriable and will try again after 1 second.
|
|
33
|
+
*/
|
|
34
|
+
onerror?: (err: any) => number | null | undefined | void;
|
|
35
|
+
/**
|
|
36
|
+
* If true, will keep the request open even if the document is hidden.
|
|
37
|
+
* By default, fetchEventSource will close the request and reopen it
|
|
38
|
+
* automatically when the document becomes visible again.
|
|
39
|
+
*/
|
|
40
|
+
openWhenHidden?: boolean;
|
|
41
|
+
/** The Fetch function to use. Defaults to window.fetch */
|
|
42
|
+
fetch?: typeof fetch;
|
|
43
|
+
}
|
|
44
|
+
export declare function fetchEventSource(input: RequestInfo, { signal: inputSignal, headers: inputHeaders, onopen: inputOnOpen, onmessage, onclose, onerror, openWhenHidden, fetch: inputFetch, ...rest }: FetchEventSourceInit): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./fetch";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a message sent in an event stream
|
|
3
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format
|
|
4
|
+
*/
|
|
5
|
+
export interface EventSourceMessage {
|
|
6
|
+
/** The event ID to set the EventSource object's last event ID value. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** A string identifying the type of event described. */
|
|
9
|
+
event: string;
|
|
10
|
+
/** The event data */
|
|
11
|
+
data: string;
|
|
12
|
+
/** The reconnection interval (in milliseconds) to wait before retrying the connection */
|
|
13
|
+
retry?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Converts a ReadableStream into a callback pattern.
|
|
17
|
+
* @param stream The input ReadableStream.
|
|
18
|
+
* @param onChunk A function that will be called on each new byte chunk in the stream.
|
|
19
|
+
* @returns {Promise<void>} A promise that will be resolved when the stream closes.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getBytes(stream: ReadableStream<Uint8Array>, onChunk: (arr: Uint8Array) => void): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Parses arbitary byte chunks into EventSource line buffers.
|
|
24
|
+
* Each line should be of the format "field: value" and ends with \r, \n, or \r\n.
|
|
25
|
+
* @param onLine A function that will be called on each new EventSource line.
|
|
26
|
+
* @returns A function that should be called for each incoming byte chunk.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getLines(onLine: (line: Uint8Array, fieldLength: number, isWrap: boolean) => void): (arr: Uint8Array) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Parses line buffers into EventSourceMessages.
|
|
31
|
+
* @param onId A function that will be called on each `id` field.
|
|
32
|
+
* @param onRetry A function that will be called on each `retry` field.
|
|
33
|
+
* @param onMessage A function that will be called on each message.
|
|
34
|
+
* @returns A function that should be called for each incoming line buffer.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getMessages(onId: (id: string) => void, onRetry: (retry: number) => void, onMessage?: (msg: EventSourceMessage) => void): (line: Uint8Array, fieldLength: number, isWrap: boolean) => void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { AgentPluginRegistor, AgentPluginMap } from './Config';
|
|
2
|
+
export { configure, configuration } from './Config';
|
|
3
|
+
export { default as BotClient } from './BotClient';
|
|
4
|
+
export { default as Session } from './Session';
|
|
5
|
+
export { default as AgentPlugin } from './AgentPlugin';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var c = Object.defineProperty;
|
|
2
|
+
var a = (e, t, i) => t in e ? c(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
|
|
3
|
+
var s = (e, t, i) => (a(e, typeof t != "symbol" ? t + "" : t, i), i);
|
|
4
|
+
class d {
|
|
5
|
+
constructor(t, i = {}, o) {
|
|
6
|
+
s(this, "code");
|
|
7
|
+
s(this, "description", "");
|
|
8
|
+
s(this, "loaded", !1);
|
|
9
|
+
s(this, "functions", {});
|
|
10
|
+
this.code = t, i && (this.functions = i);
|
|
11
|
+
}
|
|
12
|
+
fetchData() {
|
|
13
|
+
this.description = "描述", this.loaded = !0;
|
|
14
|
+
}
|
|
15
|
+
checkFunctions() {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
d as default
|
|
20
|
+
};
|