@bdky/aaas-pilot-kit 1.0.2
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/README.md +222 -0
- package/dist/http.cjs.js +2 -0
- package/dist/http.cjs.js.LICENSE.txt +1 -0
- package/dist/http.esm.js +2 -0
- package/dist/http.esm.js.LICENSE.txt +1 -0
- package/dist/http.umd.js +2 -0
- package/dist/http.umd.js.LICENSE.txt +1 -0
- package/dist/index.cjs.js +44 -0
- package/dist/index.cjs.js.LICENSE.txt +45 -0
- package/dist/index.esm.js +44 -0
- package/dist/index.esm.js.LICENSE.txt +45 -0
- package/dist/index.umd.js +44 -0
- package/dist/index.umd.js.LICENSE.txt +45 -0
- package/dist/ky-aaas-pilot-kit.umd.js +44 -0
- package/dist/ky-aaas-pilot-kit.umd.js.LICENSE.txt +45 -0
- package/dist/libs/aaas-pilot-kit/src/http.d.ts +4 -0
- package/dist/libs/aaas-pilot-kit/src/index.d.ts +5 -0
- package/dist/libs/aaas-pilot-kit/src/lib/DI/types.d.ts +12 -0
- package/dist/libs/aaas-pilot-kit/src/lib/aaas-pilot-kit.d.ts +5 -0
- package/dist/libs/aaas-pilot-kit/src/lib/api/request.d.ts +9 -0
- package/dist/libs/aaas-pilot-kit/src/lib/constants/env.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/lib/controller.d.ts +107 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/BaseError.d.ts +12 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/ErrorEmitter.d.ts +54 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/ErrorHandler.d.ts +17 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/ErrorManager.d.ts +34 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/codes.d.ts +57 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/index.d.ts +16 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/monitoring/MonitoringError.d.ts +46 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/reporters/ConsoleReporter.d.ts +4 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/reporters/HttpReporter.d.ts +16 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/reporters/index.d.ts +2 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/services/AgentError.d.ts +17 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/services/AsrError.d.ts +23 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/services/ConversationError.d.ts +23 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/services/DigitalHumanError.d.ts +32 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/services/index.d.ts +4 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/types.d.ts +41 -0
- package/dist/libs/aaas-pilot-kit/src/lib/error/utils/ErrorUtils.d.ts +7 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/agent/aiobAgentService.d.ts +69 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/agent/baseAgentService.d.ts +65 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/agent/cspAgentService.d.ts +90 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/aiWorkerConversationBean.d.ts +39 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/clientConversationBean.d.ts +25 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/content/ImageContent.d.ts +25 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/content/MultimodalContent.d.ts +42 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/content/TextContent.d.ts +41 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/content/VideoContent.d.ts +26 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/content/index.d.ts +8 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/conversationBean.d.ts +25 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/conversationService.d.ts +36 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/conversation/index.d.ts +4 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/BaseDigitalHumanService.d.ts +62 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/CloudDigitalHumanService.d.ts +102 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/PictureClientDigitalHumanService.d.ts +85 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/digital-human/interface.d.ts +100 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/rtc-asr/asr/baseAsrService.d.ts +82 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/rtc-asr/asr/brtcAsrService.d.ts +38 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/rtc-asr/signal/base.d.ts +19 -0
- package/dist/libs/aaas-pilot-kit/src/lib/service/rtc-asr/signal/brtc.d.ts +69 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/applyTextReplacements.d.ts +15 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/customXmlParser.d.ts +46 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/isEmptyObject.d.ts +14 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/isPlainObject.d.ts +13 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/noop.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/sleep.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/toQueryString.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/lib/utils/ua.d.ts +3 -0
- package/dist/libs/aaas-pilot-kit/src/samples/react/Route/index.d.ts +3 -0
- package/dist/libs/aaas-pilot-kit/src/samples/react/conversation.d.ts +2 -0
- package/dist/libs/aaas-pilot-kit/src/samples/react/index.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/test-setup.d.ts +1 -0
- package/dist/libs/aaas-pilot-kit/src/types/agent.d.ts +8 -0
- package/dist/libs/aaas-pilot-kit/src/types/common.d.ts +5 -0
- package/dist/libs/aaas-pilot-kit/src/types/config.d.ts +552 -0
- package/package.json +64 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (C) Microsoft. All rights reserved.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
5
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
8
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
9
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
10
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
11
|
+
|
|
12
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
13
|
+
and limitations under the License.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
/*! *****************************************************************************
|
|
17
|
+
Copyright (c) Microsoft Corporation.
|
|
18
|
+
|
|
19
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
20
|
+
purpose with or without fee is hereby granted.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
23
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
24
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
25
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
26
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
27
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
28
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
29
|
+
***************************************************************************** */
|
|
30
|
+
|
|
31
|
+
/*! MIT License © Sindre Sorhus */
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* TraceKit - Cross brower stack traces
|
|
35
|
+
*
|
|
36
|
+
* This was originally forked from github.com/occ/TraceKit, but has since been
|
|
37
|
+
* largely modified and is now maintained as part of Sentry JS SDK.
|
|
38
|
+
*
|
|
39
|
+
* NOTE: Last merge with upstream repository
|
|
40
|
+
* Jul 11,2018 - #f03357c
|
|
41
|
+
*
|
|
42
|
+
* https://github.com/csnover/TraceKit
|
|
43
|
+
* @license MIT
|
|
44
|
+
* @namespace TraceKit
|
|
45
|
+
*/
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as ky } from 'ky';
|
|
2
|
+
export type { KyInstance, Input, Options, NormalizedOptions, RetryOptions, SearchParamsOption, Progress, Hooks, BeforeRequestHook, BeforeRetryHook, BeforeRetryState, BeforeErrorHook, AfterResponseHook, ResponsePromise, KyRequest, KyResponse } from 'ky';
|
|
3
|
+
export { HTTPError, TimeoutError } from 'ky';
|
|
4
|
+
export * as sseHook from '@baidu/ky-sse-hook';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const TYPES: {
|
|
2
|
+
readonly AaaSPilotKitController: symbol;
|
|
3
|
+
readonly SignalingService: symbol;
|
|
4
|
+
readonly ASRService: symbol;
|
|
5
|
+
readonly AgentService: symbol;
|
|
6
|
+
readonly DigitalHumanService: symbol;
|
|
7
|
+
readonly ConversationService: symbol;
|
|
8
|
+
readonly CommonRequest: symbol;
|
|
9
|
+
readonly ErrorManager: symbol;
|
|
10
|
+
readonly IOptions: symbol;
|
|
11
|
+
};
|
|
12
|
+
export type TypeKeys = keyof typeof TYPES;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { AaaSPilotKitController } from './controller';
|
|
3
|
+
import type { IOptions } from '../types/config';
|
|
4
|
+
import { BaseAgentService } from './service/agent/baseAgentService';
|
|
5
|
+
export declare const createAaaSPilotKit: <AS extends BaseAgentService = BaseAgentService>(opts: IOptions) => AaaSPilotKitController<AS>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { KyInstance } from 'ky';
|
|
2
|
+
import type { IOptions } from '../../types/config';
|
|
3
|
+
export declare class CommonRequest {
|
|
4
|
+
readonly opts: Required<IOptions>;
|
|
5
|
+
static ONLINE_HOST: string;
|
|
6
|
+
static SANDBOX_HOST: string;
|
|
7
|
+
client: KyInstance;
|
|
8
|
+
constructor(opts: Required<IOptions>);
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const WEIRWOOD_TOKEN = "8f3abab4743f4114bd632999224323af";
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import Emittery from 'emittery';
|
|
2
|
+
import { BaseAgentService } from './service/agent/baseAgentService';
|
|
3
|
+
import { BaseAsrService } from './service/rtc-asr/asr/baseAsrService';
|
|
4
|
+
import { BaseDigitalHumanService } from './service/digital-human/BaseDigitalHumanService';
|
|
5
|
+
import { ConversationService } from './service/conversation';
|
|
6
|
+
import { ErrorManager } from './error';
|
|
7
|
+
import type { IOptions, IAaaSPilotKitController, IAaaSPilotKitEmitter } from '../types/config';
|
|
8
|
+
export interface IAsrMessageEventPayload {
|
|
9
|
+
text: string;
|
|
10
|
+
completed: boolean;
|
|
11
|
+
id: string;
|
|
12
|
+
sessionId: string;
|
|
13
|
+
}
|
|
14
|
+
export interface IBusyEventPayload {
|
|
15
|
+
requestId?: string;
|
|
16
|
+
queryId?: string;
|
|
17
|
+
sessionId?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface IInterruptEventPayload {
|
|
20
|
+
requestId?: string;
|
|
21
|
+
queryId?: string;
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class AaaSPilotKitController<AS extends BaseAgentService = BaseAgentService> implements IAaaSPilotKitController {
|
|
25
|
+
private readonly opts;
|
|
26
|
+
private readonly errorManager;
|
|
27
|
+
readonly agentService: AS;
|
|
28
|
+
private readonly asrService;
|
|
29
|
+
private readonly digitalHumanService;
|
|
30
|
+
readonly conversationService: ConversationService;
|
|
31
|
+
static ENTRY_EMITTER_NAME: string;
|
|
32
|
+
emitter: Emittery<IAaaSPilotKitEmitter>;
|
|
33
|
+
interruptible: boolean;
|
|
34
|
+
private isRenderingMultiModConversation;
|
|
35
|
+
private isDigitalHumanServiceReady;
|
|
36
|
+
private isAsrServiceReady;
|
|
37
|
+
/** 缓存最新一条agent消息 */
|
|
38
|
+
private aiWorkerMessageCache;
|
|
39
|
+
/** 用于中断渲染中的多模态消息的signal */
|
|
40
|
+
private multiModAbortControllers;
|
|
41
|
+
/** playWaitFor监听listener */
|
|
42
|
+
private playWaitForListener;
|
|
43
|
+
private readonly weirwood;
|
|
44
|
+
constructor(opts: Required<IOptions>, errorManager: ErrorManager, agentService: AS, asrService: BaseAsrService, digitalHumanService: BaseDigitalHumanService, conversationService: ConversationService);
|
|
45
|
+
mount: ($container?: HTMLElement) => Promise<void>;
|
|
46
|
+
getOptions: () => Required<IOptions>;
|
|
47
|
+
checkNeedsManualActivation: () => boolean;
|
|
48
|
+
activateManually: () => Promise<void>;
|
|
49
|
+
keepAlive: () => IAaaSPilotKitController;
|
|
50
|
+
/**
|
|
51
|
+
* 请求播放文本
|
|
52
|
+
*
|
|
53
|
+
* 如果当前正在播放,则在当前播放内容结束之后再进行播放;否则直接播放
|
|
54
|
+
*
|
|
55
|
+
* 如果传入了 shouldStillPlay 函数,则会在播放前调用该函数,如果返回 false,则不会播放
|
|
56
|
+
*/
|
|
57
|
+
playWaitFor: (text: string, shouldStillPlay?: () => boolean) => Promise<boolean>;
|
|
58
|
+
playFromFullText: (_fullText: string) => IAaaSPilotKitController;
|
|
59
|
+
playFromStreamText: (_chunk: string, hasEnded?: boolean) => IAaaSPilotKitController;
|
|
60
|
+
mute: (muted: boolean) => IAaaSPilotKitController;
|
|
61
|
+
interrupt: () => IAaaSPilotKitController;
|
|
62
|
+
playPrologue: () => void;
|
|
63
|
+
/**
|
|
64
|
+
* query输入
|
|
65
|
+
*
|
|
66
|
+
* @param input 用户输入
|
|
67
|
+
* @param completed tue: 输入结束 false: 输入中间态
|
|
68
|
+
*/
|
|
69
|
+
query: (input: string, completed: boolean) => Promise<void>;
|
|
70
|
+
input: (text: string) => IAaaSPilotKitController;
|
|
71
|
+
dispose: () => IAaaSPilotKitController;
|
|
72
|
+
setInterruptible: (interruptible: boolean) => IAaaSPilotKitController;
|
|
73
|
+
private readonly bindAsrServiceEvents;
|
|
74
|
+
private readonly bindAgentServiceEvents;
|
|
75
|
+
private readonly bindDigitalHumanServiceEvents;
|
|
76
|
+
private readonly bindErrorEvents;
|
|
77
|
+
private readonly bindEvents;
|
|
78
|
+
private readonly registerFormatters;
|
|
79
|
+
/**
|
|
80
|
+
* 将数字员工播报的字幕转成conversation
|
|
81
|
+
*/
|
|
82
|
+
private readonly aiWorkerSubtitleToConversation;
|
|
83
|
+
private readonly handleAgentAnswer;
|
|
84
|
+
private readonly handleXmlAgentAnswer;
|
|
85
|
+
/**
|
|
86
|
+
* 当前对话不是AI Worker的对话,则创建新的对话
|
|
87
|
+
*/
|
|
88
|
+
private readonly createNewAIWorkerConversation;
|
|
89
|
+
private readonly handleAgentAnswerCompleted;
|
|
90
|
+
private readonly handleAgentInstructionReceived;
|
|
91
|
+
private readonly handleAsrServiceStarted;
|
|
92
|
+
/**
|
|
93
|
+
* 处理asr消息
|
|
94
|
+
*/
|
|
95
|
+
private readonly handleAsrMessage;
|
|
96
|
+
/**
|
|
97
|
+
* 处理client conversation
|
|
98
|
+
*/
|
|
99
|
+
private readonly handleClientConversation;
|
|
100
|
+
private readonly handleClientConversationCompleted;
|
|
101
|
+
/**
|
|
102
|
+
* 打断正在渲染的ai worker conversation
|
|
103
|
+
*/
|
|
104
|
+
private readonly interruptAIWorkerConversation;
|
|
105
|
+
private readonly checkServiceReady;
|
|
106
|
+
private readonly handleAIWorkerConversationChange;
|
|
107
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ErrorCategory, ErrorSeverity, IErrorMetadata, IErrorDetails } from './types';
|
|
2
|
+
export declare class BaseError extends Error implements IErrorDetails {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly category: ErrorCategory;
|
|
5
|
+
readonly severity: ErrorSeverity;
|
|
6
|
+
readonly metadata: IErrorMetadata;
|
|
7
|
+
readonly actionRequired?: string;
|
|
8
|
+
constructor(code: string, message: string, category: ErrorCategory, severity?: ErrorSeverity, metadata?: Partial<IErrorMetadata>, actionRequired?: string);
|
|
9
|
+
static fromError(error: Error, code: string, category: ErrorCategory, severity?: ErrorSeverity): BaseError;
|
|
10
|
+
toJSON(): IErrorDetails;
|
|
11
|
+
toString(): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BaseError } from './BaseError';
|
|
2
|
+
export interface IErrorEventPayload {
|
|
3
|
+
/** 错误代码 */
|
|
4
|
+
code: string;
|
|
5
|
+
/** 错误消息(包含 toString() 的内容) */
|
|
6
|
+
message: string;
|
|
7
|
+
/** 错误堆栈 */
|
|
8
|
+
stack?: string;
|
|
9
|
+
/** 用户操作指导 */
|
|
10
|
+
actionRequired: string | null;
|
|
11
|
+
/** 错误严重级别 */
|
|
12
|
+
severity: string;
|
|
13
|
+
/** 错误元数据 */
|
|
14
|
+
metadata: {
|
|
15
|
+
timestamp: number;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
requestId?: string;
|
|
18
|
+
userId?: string;
|
|
19
|
+
service?: string;
|
|
20
|
+
context?: Record<string, any>;
|
|
21
|
+
};
|
|
22
|
+
/** 原始错误对象(用于内部处理) */
|
|
23
|
+
originalError?: Error;
|
|
24
|
+
}
|
|
25
|
+
export interface IErrorEmitterEvents {
|
|
26
|
+
error: IErrorEventPayload;
|
|
27
|
+
}
|
|
28
|
+
export declare class ErrorEmitter {
|
|
29
|
+
private readonly emitter;
|
|
30
|
+
/**
|
|
31
|
+
* 上报错误到外层
|
|
32
|
+
*/
|
|
33
|
+
emit: (error: Error | BaseError) => void;
|
|
34
|
+
/**
|
|
35
|
+
* 监听错误事件
|
|
36
|
+
*/
|
|
37
|
+
on: (listener: (payload: IErrorEventPayload) => void) => void;
|
|
38
|
+
/**
|
|
39
|
+
* 移除错误监听
|
|
40
|
+
*/
|
|
41
|
+
off: (listener: (payload: IErrorEventPayload) => void) => void;
|
|
42
|
+
/**
|
|
43
|
+
* 清除所有监听器
|
|
44
|
+
*/
|
|
45
|
+
clearListeners: () => void;
|
|
46
|
+
/**
|
|
47
|
+
* 将错误对象转换为标准的事件载荷
|
|
48
|
+
*/
|
|
49
|
+
private readonly transformErrorToPayload;
|
|
50
|
+
/**
|
|
51
|
+
* 从错误对象中提取服务类型
|
|
52
|
+
*/
|
|
53
|
+
private readonly extractServiceFromError;
|
|
54
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IErrorHandler, IErrorReporter, IErrorDetails } from './types';
|
|
2
|
+
import { type IErrorManagerOptions } from './ErrorManager';
|
|
3
|
+
export declare class ErrorHandler implements IErrorHandler {
|
|
4
|
+
private readonly opts;
|
|
5
|
+
private readonly reporters;
|
|
6
|
+
constructor(opts: IErrorManagerOptions);
|
|
7
|
+
addReporter(reporter: IErrorReporter): void;
|
|
8
|
+
removeReporter(reporter: IErrorReporter): void;
|
|
9
|
+
handle(error: Error | IErrorDetails): Promise<void>;
|
|
10
|
+
private processError;
|
|
11
|
+
private shouldLogError;
|
|
12
|
+
private shouldReportError;
|
|
13
|
+
private logError;
|
|
14
|
+
private getLogLevel;
|
|
15
|
+
private reportError;
|
|
16
|
+
private isErrorDetails;
|
|
17
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ErrorHandler } from './ErrorHandler';
|
|
2
|
+
import { BaseError } from './BaseError';
|
|
3
|
+
import { ErrorEmitter, IErrorEventPayload } from './ErrorEmitter';
|
|
4
|
+
import { MonitoringError } from './monitoring/MonitoringError';
|
|
5
|
+
import type { IOptions } from '../../types/config';
|
|
6
|
+
export interface IErrorManagerOptions {
|
|
7
|
+
enableConsoleReporter?: boolean;
|
|
8
|
+
enableHttpReporter?: boolean;
|
|
9
|
+
httpReporterEndpoint?: string;
|
|
10
|
+
enableErrorLogging?: boolean;
|
|
11
|
+
enableErrorReporting?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class ErrorManager extends ErrorEmitter {
|
|
14
|
+
private readonly opts;
|
|
15
|
+
private readonly errorHandler;
|
|
16
|
+
private readonly options;
|
|
17
|
+
constructor(opts: IOptions);
|
|
18
|
+
handleError: (error: Error | BaseError) => Promise<void>;
|
|
19
|
+
getErrorHandler: () => ErrorHandler;
|
|
20
|
+
getActionRequired: (error: Error) => string | null;
|
|
21
|
+
/**
|
|
22
|
+
* 创建用于监控平台的错误实例
|
|
23
|
+
*/
|
|
24
|
+
createMonitoringError: (payload: IErrorEventPayload) => MonitoringError;
|
|
25
|
+
/**
|
|
26
|
+
* 构建增强的错误消息
|
|
27
|
+
*/
|
|
28
|
+
private readonly buildEnhancedMessage;
|
|
29
|
+
/**
|
|
30
|
+
* 序列化元数据,排除内部字段
|
|
31
|
+
*/
|
|
32
|
+
private readonly stringifyMetadata;
|
|
33
|
+
private readonly initializeReporters;
|
|
34
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export declare const ERROR_CODES: {
|
|
2
|
+
readonly COMMON_UNKNOWN: "1000";
|
|
3
|
+
readonly COMMON_NETWORK_ERROR: "1001";
|
|
4
|
+
readonly COMMON_TIMEOUT: "1002";
|
|
5
|
+
readonly COMMON_INVALID_CONFIG: "1003";
|
|
6
|
+
readonly COMMON_AUTHENTICATION_FAILED: "1004";
|
|
7
|
+
readonly COMMON_AUTHORIZATION_FAILED: "1005";
|
|
8
|
+
readonly COMMON_VALIDATION_ERROR: "1006";
|
|
9
|
+
readonly COMMON_RESOURCE_NOT_FOUND: "1007";
|
|
10
|
+
readonly COMMON_RESOURCE_UNAVAILABLE: "1008";
|
|
11
|
+
readonly COMMON_INTERNAL_ERROR: "1009";
|
|
12
|
+
readonly AGENT_QUERY_FAILED: "2001";
|
|
13
|
+
readonly AGENT_RESPONSE_PARSE_ERROR: "2002";
|
|
14
|
+
readonly AGENT_REQUEST_TIMEOUT: "2003";
|
|
15
|
+
readonly AGENT_INVALID_RESPONSE: "2004";
|
|
16
|
+
readonly AGENT_CONNECTION_FAILED: "2005";
|
|
17
|
+
readonly AGENT_INSTRUCTION_INVALID: "2006";
|
|
18
|
+
readonly ASR_INITIALIZATION_FAILED: "3001";
|
|
19
|
+
readonly ASR_START_FAILED: "3002";
|
|
20
|
+
readonly ASR_STOP_FAILED: "3003";
|
|
21
|
+
readonly ASR_SIGNALING_ERROR: "3004";
|
|
22
|
+
readonly ASR_AUDIO_CAPTURE_ERROR: "3005";
|
|
23
|
+
readonly ASR_RECOGNITION_ERROR: "3006";
|
|
24
|
+
readonly ASR_NETWORK_ERROR: "3007";
|
|
25
|
+
readonly ASR_PERMISSION_DENIED: "3008";
|
|
26
|
+
readonly ASR_DEVICE_NOT_FOUND: "3009";
|
|
27
|
+
readonly ASR_MESSAGE_PARSE_ERROR: "3010";
|
|
28
|
+
readonly ASR_SESSION_INVALID: "3011";
|
|
29
|
+
readonly ASR_MUTE_FAILED: "3012";
|
|
30
|
+
readonly ASR_MESSAGE_INTERVAL_TIMEOUT: "3013";
|
|
31
|
+
readonly DH_MOUNT_FAILED: "4001";
|
|
32
|
+
readonly DH_IFRAME_LOAD_ERROR: "4002";
|
|
33
|
+
readonly DH_RENDER_ERROR: "4003";
|
|
34
|
+
readonly DH_WEBSOCKET_ERROR: "4004";
|
|
35
|
+
readonly DH_RTC_ERROR: "4005";
|
|
36
|
+
readonly DH_AUTHENTICATION_ERROR: "4006";
|
|
37
|
+
readonly DH_REACH_SESSION_LIMIT: "4007";
|
|
38
|
+
readonly DH_RESOURCE_NOT_ENOUGH: "4008";
|
|
39
|
+
readonly DH_TIMEOUT: "4009";
|
|
40
|
+
readonly DH_INTERRUPT_FAILED: "4010";
|
|
41
|
+
readonly DH_SSML_PARSE_ERROR: "4011";
|
|
42
|
+
readonly DH_INVALID_FIGURE_ID: "4012";
|
|
43
|
+
readonly DH_INVALID_TOKEN: "4013";
|
|
44
|
+
readonly DH_STREAM_RENDER_ERROR: "4014";
|
|
45
|
+
readonly DH_CONTROLLER_NOT_READY: "4015";
|
|
46
|
+
readonly DH_TEXT_LENGTH_MISMATCH: "4016";
|
|
47
|
+
readonly CONVERSATION_CREATE_FAILED: "5001";
|
|
48
|
+
readonly CONVERSATION_INVALID_TYPE: "5002";
|
|
49
|
+
readonly CONVERSATION_SNAPSHOT_INVALID: "5003";
|
|
50
|
+
readonly CONVERSATION_BEAN_NOT_FOUND: "5004";
|
|
51
|
+
readonly CONVERSATION_SERIALIZE_ERROR: "5005";
|
|
52
|
+
readonly CONVERSATION_DESERIALIZE_ERROR: "5006";
|
|
53
|
+
readonly CONVERSATION_STATE_INVALID: "5007";
|
|
54
|
+
readonly CONVERSATION_CLEAR_FAILED: "5008";
|
|
55
|
+
};
|
|
56
|
+
export type ErrorCode = typeof ERROR_CODES[keyof typeof ERROR_CODES];
|
|
57
|
+
export declare const ERROR_MESSAGES: Record<ErrorCode, string>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AgentError, AsrError, DigitalHumanError, ConversationError } from './services';
|
|
2
|
+
export { BaseError } from './BaseError';
|
|
3
|
+
export { ErrorHandler } from './ErrorHandler';
|
|
4
|
+
export { ErrorManager } from './ErrorManager';
|
|
5
|
+
export type { IErrorMetadata, IErrorDetails, IErrorReporter, IErrorHandler } from './types';
|
|
6
|
+
export { ErrorCategory, ErrorSeverity } from './types';
|
|
7
|
+
export { ERROR_CODES, ERROR_MESSAGES } from './codes';
|
|
8
|
+
export type { ErrorCode } from './codes';
|
|
9
|
+
export * from './services';
|
|
10
|
+
export * from './reporters';
|
|
11
|
+
export { ErrorUtils } from './utils/ErrorUtils';
|
|
12
|
+
export { ErrorEmitter, type IErrorEventPayload, type IErrorEmitterEvents } from './ErrorEmitter';
|
|
13
|
+
export declare const createAgentError: (message: string, code?: string) => AgentError;
|
|
14
|
+
export declare const createAsrError: (message: string, code?: string) => AsrError;
|
|
15
|
+
export declare const createDigitalHumanError: (message: string, code?: string) => DigitalHumanError;
|
|
16
|
+
export declare const createConversationError: (message: string, code?: string) => ConversationError;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 监控平台自定义错误类
|
|
3
|
+
* 基于现代化 ES6+ 语法实现,符合监控平台要求
|
|
4
|
+
*/
|
|
5
|
+
export interface IMonitoringErrorData extends Record<any, any> {
|
|
6
|
+
page?: string;
|
|
7
|
+
userId?: string;
|
|
8
|
+
sessionId?: string;
|
|
9
|
+
requestId?: string;
|
|
10
|
+
context?: Record<string, any>;
|
|
11
|
+
severity?: string;
|
|
12
|
+
category?: string;
|
|
13
|
+
code?: string;
|
|
14
|
+
originalMessage?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 用于监控平台上报的自定义错误类
|
|
18
|
+
* 符合监控平台的自定义错误实现规范
|
|
19
|
+
*/
|
|
20
|
+
export declare class MonitoringError extends Error {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly message: string;
|
|
23
|
+
readonly stack: string | undefined;
|
|
24
|
+
readonly data: IMonitoringErrorData;
|
|
25
|
+
constructor(type: string, enhancedMessage: string, data?: IMonitoringErrorData);
|
|
26
|
+
/**
|
|
27
|
+
* 创建用于监控平台的错误实例
|
|
28
|
+
*/
|
|
29
|
+
static createForMonitoring(type: string, enhancedMessage: string, data: IMonitoringErrorData): MonitoringError;
|
|
30
|
+
/**
|
|
31
|
+
* 获取用于监控平台上报的数据
|
|
32
|
+
*/
|
|
33
|
+
getMonitoringData(): Record<string, any>;
|
|
34
|
+
/**
|
|
35
|
+
* 获取简化的上报数据(用于控制台输出)
|
|
36
|
+
*/
|
|
37
|
+
getSimplifiedData(): Record<string, any>;
|
|
38
|
+
/**
|
|
39
|
+
* 重写 toString 方法
|
|
40
|
+
*/
|
|
41
|
+
toString(): string;
|
|
42
|
+
/**
|
|
43
|
+
* 重写 toJSON 方法,用于序列化
|
|
44
|
+
*/
|
|
45
|
+
toJSON(): Record<string, any>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IErrorReporter, IErrorDetails } from '../types';
|
|
2
|
+
export interface IHttpReporterOptions {
|
|
3
|
+
endpoint: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
retryCount?: number;
|
|
7
|
+
retryDelay?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class HttpReporter implements IErrorReporter {
|
|
10
|
+
private readonly options;
|
|
11
|
+
constructor(options: IHttpReporterOptions);
|
|
12
|
+
report(error: IErrorDetails): Promise<void>;
|
|
13
|
+
private buildPayload;
|
|
14
|
+
private sendRequest;
|
|
15
|
+
private delay;
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseError } from '../BaseError';
|
|
2
|
+
import { ErrorSeverity, IErrorMetadata } from '../types';
|
|
3
|
+
export declare class AgentError extends BaseError {
|
|
4
|
+
constructor(code: string, message?: string, severity?: ErrorSeverity, metadata?: Partial<IErrorMetadata>, actionRequired?: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class AgentQueryError extends AgentError {
|
|
7
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
8
|
+
}
|
|
9
|
+
export declare class AgentResponseParseError extends AgentError {
|
|
10
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
11
|
+
}
|
|
12
|
+
export declare class AgentConnectionError extends AgentError {
|
|
13
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
14
|
+
}
|
|
15
|
+
export declare class AgentInstructionError extends AgentError {
|
|
16
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseError } from '../BaseError';
|
|
2
|
+
import { ErrorSeverity, IErrorMetadata } from '../types';
|
|
3
|
+
export declare class AsrError extends BaseError {
|
|
4
|
+
constructor(code: string, message?: string, severity?: ErrorSeverity, metadata?: Partial<IErrorMetadata>);
|
|
5
|
+
}
|
|
6
|
+
export declare class AsrInitializationError extends AsrError {
|
|
7
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
8
|
+
}
|
|
9
|
+
export declare class AsrStartError extends AsrError {
|
|
10
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
11
|
+
}
|
|
12
|
+
export declare class AsrStopError extends AsrError {
|
|
13
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
14
|
+
}
|
|
15
|
+
export declare class AsrPermissionError extends AsrError {
|
|
16
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
17
|
+
}
|
|
18
|
+
export declare class AsrMessageParseError extends AsrError {
|
|
19
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
20
|
+
}
|
|
21
|
+
export declare class AsrMessageIntervalTimeoutError extends AsrError {
|
|
22
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseError } from '../BaseError';
|
|
2
|
+
import { ErrorSeverity, IErrorMetadata } from '../types';
|
|
3
|
+
export declare class ConversationError extends BaseError {
|
|
4
|
+
constructor(code: string, message?: string, severity?: ErrorSeverity, metadata?: Partial<IErrorMetadata>);
|
|
5
|
+
}
|
|
6
|
+
export declare class ConversationCreateError extends ConversationError {
|
|
7
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
8
|
+
}
|
|
9
|
+
export declare class ConversationInvalidTypeError extends ConversationError {
|
|
10
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
11
|
+
}
|
|
12
|
+
export declare class ConversationSnapshotError extends ConversationError {
|
|
13
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
14
|
+
}
|
|
15
|
+
export declare class ConversationBeanNotFoundError extends ConversationError {
|
|
16
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
17
|
+
}
|
|
18
|
+
export declare class ConversationSerializeError extends ConversationError {
|
|
19
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
20
|
+
}
|
|
21
|
+
export declare class ConversationDeserializeError extends ConversationError {
|
|
22
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
23
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseError } from '../BaseError';
|
|
2
|
+
import { ErrorSeverity, IErrorMetadata } from '../types';
|
|
3
|
+
export declare class DigitalHumanError extends BaseError {
|
|
4
|
+
constructor(code: string, message?: string, severity?: ErrorSeverity, metadata?: Partial<IErrorMetadata>);
|
|
5
|
+
}
|
|
6
|
+
export declare class DigitalHumanMountError extends DigitalHumanError {
|
|
7
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
8
|
+
}
|
|
9
|
+
export declare class DigitalHumanIframeError extends DigitalHumanError {
|
|
10
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
11
|
+
}
|
|
12
|
+
export declare class DigitalHumanRenderError extends DigitalHumanError {
|
|
13
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
14
|
+
}
|
|
15
|
+
export declare class DigitalHumanWebSocketError extends DigitalHumanError {
|
|
16
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
17
|
+
}
|
|
18
|
+
export declare class DigitalHumanRtcError extends DigitalHumanError {
|
|
19
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
20
|
+
}
|
|
21
|
+
export declare class DigitalHumanAuthError extends DigitalHumanError {
|
|
22
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
23
|
+
}
|
|
24
|
+
export declare class DigitalHumanResourceError extends DigitalHumanError {
|
|
25
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
26
|
+
}
|
|
27
|
+
export declare class DigitalHumanSsmlError extends DigitalHumanError {
|
|
28
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
29
|
+
}
|
|
30
|
+
export declare class DigitalHumanInvalidTokenError extends DigitalHumanError {
|
|
31
|
+
constructor(message?: string, metadata?: Partial<IErrorMetadata>);
|
|
32
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare enum ErrorCategory {
|
|
2
|
+
NETWORK = "NETWORK",
|
|
3
|
+
TIMEOUT = "TIMEOUT",
|
|
4
|
+
AUTHENTICATION = "AUTHENTICATION",
|
|
5
|
+
AUTHORIZATION = "AUTHORIZATION",
|
|
6
|
+
RESOURCE = "RESOURCE",
|
|
7
|
+
CONFIGURATION = "CONFIGURATION",
|
|
8
|
+
PARSING = "PARSING",
|
|
9
|
+
SERVICE = "SERVICE",
|
|
10
|
+
VALIDATION = "VALIDATION",
|
|
11
|
+
INTERNAL = "INTERNAL"
|
|
12
|
+
}
|
|
13
|
+
export declare enum ErrorSeverity {
|
|
14
|
+
LOW = "LOW",
|
|
15
|
+
MEDIUM = "MEDIUM",
|
|
16
|
+
HIGH = "HIGH",
|
|
17
|
+
CRITICAL = "CRITICAL"
|
|
18
|
+
}
|
|
19
|
+
export interface IErrorMetadata {
|
|
20
|
+
timestamp: number;
|
|
21
|
+
sessionId?: string;
|
|
22
|
+
requestId?: string;
|
|
23
|
+
userId?: string;
|
|
24
|
+
context?: Record<string, any>;
|
|
25
|
+
stack?: string;
|
|
26
|
+
originalError?: Error;
|
|
27
|
+
}
|
|
28
|
+
export interface IErrorDetails {
|
|
29
|
+
code: string;
|
|
30
|
+
message: string;
|
|
31
|
+
category: ErrorCategory;
|
|
32
|
+
severity: ErrorSeverity;
|
|
33
|
+
metadata: IErrorMetadata;
|
|
34
|
+
actionRequired?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface IErrorReporter {
|
|
37
|
+
report(error: IErrorDetails): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
export interface IErrorHandler {
|
|
40
|
+
handle(error: Error | IErrorDetails): Promise<void>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ErrorSeverity, type IErrorMetadata } from '../types';
|
|
2
|
+
export declare class ErrorUtils {
|
|
3
|
+
static getErrorSeverity(error: Error): ErrorSeverity;
|
|
4
|
+
static shouldReport(error: Error): boolean;
|
|
5
|
+
static extractMetadata(error: Error, context?: Record<string, any>): IErrorMetadata;
|
|
6
|
+
static getActionRequired(error: Error): string | null;
|
|
7
|
+
}
|