@amaster.ai/client 1.0.0-alpha.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/LICENSE +21 -0
- package/README.md +847 -0
- package/dist/index.cjs +162 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +421 -0
- package/dist/index.d.ts +421 -0
- package/dist/index.js +160 -0
- package/dist/index.js.map +1 -0
- package/package.json +108 -0
- package/types/__tests__/type-checks.test-d.ts +163 -0
- package/types/asr.d.ts +237 -0
- package/types/auth/code-auth.d.ts +105 -0
- package/types/auth/index.d.ts +138 -0
- package/types/auth/oauth.d.ts +143 -0
- package/types/auth/password-auth.d.ts +226 -0
- package/types/auth/profile.d.ts +64 -0
- package/types/auth/user.d.ts +73 -0
- package/types/bpm.d.ts +621 -0
- package/types/common.d.ts +140 -0
- package/types/copilot.d.ts +49 -0
- package/types/entity.d.ts +433 -0
- package/types/function.d.ts +41 -0
- package/types/http.d.ts +95 -0
- package/types/index.d.ts +338 -0
- package/types/s3.d.ts +96 -0
- package/types/tts.d.ts +88 -0
- package/types/workflow.d.ts +142 -0
package/package.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amaster.ai/client",
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"description": "Unified API client for Amaster platform - All services in one package",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"typesVersions": {
|
|
10
|
+
"*": {
|
|
11
|
+
"*": [
|
|
12
|
+
"./types/index.d.ts"
|
|
13
|
+
],
|
|
14
|
+
"auth": [
|
|
15
|
+
"./types/auth/index.d.ts"
|
|
16
|
+
],
|
|
17
|
+
"auth/*": [
|
|
18
|
+
"./types/auth/*.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"entity": [
|
|
21
|
+
"./types/entity.d.ts"
|
|
22
|
+
],
|
|
23
|
+
"bpm": [
|
|
24
|
+
"./types/bpm.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"workflow": [
|
|
27
|
+
"./types/workflow.d.ts"
|
|
28
|
+
],
|
|
29
|
+
"asr": [
|
|
30
|
+
"./types/asr.d.ts"
|
|
31
|
+
],
|
|
32
|
+
"copilot": [
|
|
33
|
+
"./types/copilot.d.ts"
|
|
34
|
+
],
|
|
35
|
+
"function": [
|
|
36
|
+
"./types/function.d.ts"
|
|
37
|
+
],
|
|
38
|
+
"tts": [
|
|
39
|
+
"./types/tts.d.ts"
|
|
40
|
+
],
|
|
41
|
+
"s3": [
|
|
42
|
+
"./types/s3.d.ts"
|
|
43
|
+
],
|
|
44
|
+
"common": [
|
|
45
|
+
"./types/common.d.ts"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"exports": {
|
|
50
|
+
".": {
|
|
51
|
+
"types": "./dist/index.d.ts",
|
|
52
|
+
"import": "./dist/index.js",
|
|
53
|
+
"require": "./dist/index.cjs"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"types",
|
|
59
|
+
"README.md"
|
|
60
|
+
],
|
|
61
|
+
"keywords": [
|
|
62
|
+
"amaster",
|
|
63
|
+
"client",
|
|
64
|
+
"sdk",
|
|
65
|
+
"unified-api",
|
|
66
|
+
"typescript"
|
|
67
|
+
],
|
|
68
|
+
"author": "Amaster Team",
|
|
69
|
+
"license": "MIT",
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public",
|
|
72
|
+
"registry": "https://registry.npmjs.org/"
|
|
73
|
+
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@amaster.ai/asr-client": "1.0.0-alpha.1",
|
|
76
|
+
"@amaster.ai/bpm-client": "1.0.0-alpha.1",
|
|
77
|
+
"@amaster.ai/copilot-client": "1.0.0-alpha.1",
|
|
78
|
+
"@amaster.ai/auth-client": "1.0.0-alpha.1",
|
|
79
|
+
"@amaster.ai/http-client": "1.0.0-alpha.1",
|
|
80
|
+
"@amaster.ai/function-client": "1.0.0-alpha.1",
|
|
81
|
+
"@amaster.ai/entity-client": "1.0.0-alpha.1",
|
|
82
|
+
"@amaster.ai/tts-client": "1.0.0-alpha.1",
|
|
83
|
+
"@amaster.ai/workflow-client": "1.0.0-alpha.1",
|
|
84
|
+
"@amaster.ai/s3-client": "1.0.0-alpha.1"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"axios": "^1.11.0"
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"@a2a-js/sdk": "^0.3.7",
|
|
91
|
+
"@vitest/ui": "^1.0.0",
|
|
92
|
+
"axios": "^1.11.0",
|
|
93
|
+
"axios-mock-adapter": "^1.22.0",
|
|
94
|
+
"tsup": "^8.3.5",
|
|
95
|
+
"typescript": "~5.7.2",
|
|
96
|
+
"vitest": "^1.0.0"
|
|
97
|
+
},
|
|
98
|
+
"scripts": {
|
|
99
|
+
"build": "./scripts/build.sh",
|
|
100
|
+
"build:types": "tsc --emitDeclarationOnly --outDir types-generated",
|
|
101
|
+
"dev": "tsup --watch",
|
|
102
|
+
"clean": "rm -rf dist types-generated *.tsbuildinfo",
|
|
103
|
+
"type-check": "tsc --noEmit",
|
|
104
|
+
"validate-types": "tsc --noEmit --project tsconfig.types.json",
|
|
105
|
+
"test": "vitest run",
|
|
106
|
+
"test:watch": "vitest"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level tests for @amaster.ai/client
|
|
3
|
+
*
|
|
4
|
+
* These tests verify type inference and type safety at compile time.
|
|
5
|
+
* They ensure that the type definitions work correctly with TypeScript.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, it, expectTypeOf } from 'vitest';
|
|
9
|
+
import type {
|
|
10
|
+
AmasterClient,
|
|
11
|
+
AmasterClientOptions,
|
|
12
|
+
ClientResult,
|
|
13
|
+
ClientError,
|
|
14
|
+
EntityListResponse,
|
|
15
|
+
LoginParams,
|
|
16
|
+
User,
|
|
17
|
+
Task,
|
|
18
|
+
ProcessInstance,
|
|
19
|
+
} from '../index';
|
|
20
|
+
|
|
21
|
+
describe('Type Tests', () => {
|
|
22
|
+
describe('ClientResult', () => {
|
|
23
|
+
it('should have correct structure', () => {
|
|
24
|
+
type Result = ClientResult<{ id: number; name: string }>;
|
|
25
|
+
|
|
26
|
+
expectTypeOf<Result>().toMatchTypeOf<{
|
|
27
|
+
data: { id: number; name: string } | null;
|
|
28
|
+
error: ClientError | null;
|
|
29
|
+
status: number;
|
|
30
|
+
success: boolean;
|
|
31
|
+
}>();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should infer data type correctly', () => {
|
|
35
|
+
type UserResult = ClientResult<User>;
|
|
36
|
+
|
|
37
|
+
expectTypeOf<UserResult['data']>().toEqualTypeOf<User | null>();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should have success field', () => {
|
|
41
|
+
type Result = ClientResult<unknown>;
|
|
42
|
+
|
|
43
|
+
expectTypeOf<Result['success']>().toEqualTypeOf<boolean>();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('ClientError', () => {
|
|
48
|
+
it('should have all required fields', () => {
|
|
49
|
+
expectTypeOf<ClientError>().toMatchTypeOf<{
|
|
50
|
+
status: number;
|
|
51
|
+
message: string;
|
|
52
|
+
code?: string;
|
|
53
|
+
details?: unknown;
|
|
54
|
+
timestamp?: string;
|
|
55
|
+
}>();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('EntityListResponse', () => {
|
|
60
|
+
it('should infer item type correctly', () => {
|
|
61
|
+
type UserListResponse = EntityListResponse<{ id: number; name: string }>;
|
|
62
|
+
|
|
63
|
+
expectTypeOf<UserListResponse['items']>().toEqualTypeOf<Array<{ id: number; name: string }>>();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should have pagination fields', () => {
|
|
67
|
+
type Response = EntityListResponse<unknown>;
|
|
68
|
+
|
|
69
|
+
expectTypeOf<Response>().toMatchTypeOf<{
|
|
70
|
+
items: unknown[];
|
|
71
|
+
total: number;
|
|
72
|
+
page?: number;
|
|
73
|
+
perPage?: number;
|
|
74
|
+
}>();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('AmasterClient', () => {
|
|
79
|
+
it('should have all service modules', () => {
|
|
80
|
+
expectTypeOf<AmasterClient>().toHaveProperty('auth');
|
|
81
|
+
expectTypeOf<AmasterClient>().toHaveProperty('entity');
|
|
82
|
+
expectTypeOf<AmasterClient>().toHaveProperty('bpm');
|
|
83
|
+
expectTypeOf<AmasterClient>().toHaveProperty('workflow');
|
|
84
|
+
expectTypeOf<AmasterClient>().toHaveProperty('asr');
|
|
85
|
+
expectTypeOf<AmasterClient>().toHaveProperty('copilot');
|
|
86
|
+
expectTypeOf<AmasterClient>().toHaveProperty('function');
|
|
87
|
+
expectTypeOf<AmasterClient>().toHaveProperty('tts');
|
|
88
|
+
expectTypeOf<AmasterClient>().toHaveProperty('s3');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should have utility methods', () => {
|
|
92
|
+
expectTypeOf<AmasterClient>().toHaveProperty('isAuthenticated');
|
|
93
|
+
expectTypeOf<AmasterClient>().toHaveProperty('getAccessToken');
|
|
94
|
+
expectTypeOf<AmasterClient>().toHaveProperty('setAccessToken');
|
|
95
|
+
expectTypeOf<AmasterClient>().toHaveProperty('clearAuth');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('LoginParams', () => {
|
|
100
|
+
it('should accept email login', () => {
|
|
101
|
+
const params: LoginParams = {
|
|
102
|
+
email: 'user@example.com',
|
|
103
|
+
password: 'password123'
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
expectTypeOf(params).toMatchTypeOf<LoginParams>();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should accept username login', () => {
|
|
110
|
+
const params: LoginParams = {
|
|
111
|
+
username: 'johndoe',
|
|
112
|
+
password: 'password123'
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
expectTypeOf(params).toMatchTypeOf<LoginParams>();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should accept phone login', () => {
|
|
119
|
+
const params: LoginParams = {
|
|
120
|
+
phone: '+1234567890',
|
|
121
|
+
password: 'password123'
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
expectTypeOf(params).toMatchTypeOf<LoginParams>();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe('Generic Type Inference', () => {
|
|
129
|
+
it('should infer entity list result type', () => {
|
|
130
|
+
type User = { id: number; name: string; email: string };
|
|
131
|
+
type Result = ClientResult<EntityListResponse<User>>;
|
|
132
|
+
|
|
133
|
+
// If success, data.items should be User[]
|
|
134
|
+
expectTypeOf<NonNullable<Result['data']>['items']>().toEqualTypeOf<User[]>();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should infer entity get result type', () => {
|
|
138
|
+
type Product = { id: number; title: string; price: number };
|
|
139
|
+
type Result = ClientResult<Product>;
|
|
140
|
+
|
|
141
|
+
expectTypeOf<NonNullable<Result['data']>>().toEqualTypeOf<Product>();
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('BPM Types', () => {
|
|
146
|
+
it('should have correct Task structure', () => {
|
|
147
|
+
expectTypeOf<Task>().toMatchTypeOf<{
|
|
148
|
+
id: string;
|
|
149
|
+
name: string;
|
|
150
|
+
assignee: string | null;
|
|
151
|
+
processInstanceId: string;
|
|
152
|
+
}>();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should have correct ProcessInstance structure', () => {
|
|
156
|
+
expectTypeOf<ProcessInstance>().toMatchTypeOf<{
|
|
157
|
+
id: string;
|
|
158
|
+
definitionId?: string;
|
|
159
|
+
businessKey?: string;
|
|
160
|
+
}>();
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
package/types/asr.d.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ASR Realtime WebSocket Client for Qwen-ASR Realtime API
|
|
3
|
+
*
|
|
4
|
+
* WebSocket-based real-time speech recognition for streaming transcription.
|
|
5
|
+
* Follows the Qwen-ASR Realtime API protocol with proper event handling.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const asrClient = client.asr({
|
|
10
|
+
* language: "zh",
|
|
11
|
+
* enableVAD: true,
|
|
12
|
+
* onReady() {
|
|
13
|
+
* console.log("ASR connected");
|
|
14
|
+
* },
|
|
15
|
+
* onTranscript(text, isFinal) {
|
|
16
|
+
* console.log(isFinal ? "[Final]" : "[Interim]", text);
|
|
17
|
+
* },
|
|
18
|
+
* onError(err) {
|
|
19
|
+
* console.error("ASR error:", err);
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* await asrClient.connect();
|
|
24
|
+
* await asrClient.startRecording();
|
|
25
|
+
* // ... stop ...
|
|
26
|
+
* await asrClient.stopRecording();
|
|
27
|
+
* await asrClient.close();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type ASRLanguage = "zh" | "yue" | "en" | "ja" | "de" | "ko" | "ru" | "fr" | "pt" | "ar" | "it" | "es" | "hi" | "id" | "th" | "tr" | "uk" | "vi" | "cs" | "da" | "fil" | "fi" | "is" | "ms" | "no" | "pl" | "sv";
|
|
31
|
+
export type ClientEventType = "session.update" | "input_audio_buffer.append" | "input_audio_buffer.commit" | "session.finish";
|
|
32
|
+
export type ServerEventType = "session.created" | "session.updated" | "input_audio_buffer.speech_started" | "input_audio_buffer.speech_stopped" | "input_audio_buffer.committed" | "conversation.item.input_audio_transcription.text" | "conversation.item.input_audio_transcription.completed" | "session.finished" | "error";
|
|
33
|
+
export interface BaseEvent {
|
|
34
|
+
event_id: string;
|
|
35
|
+
type: ClientEventType | ServerEventType;
|
|
36
|
+
}
|
|
37
|
+
export interface SessionUpdateEvent extends BaseEvent {
|
|
38
|
+
type: "session.update";
|
|
39
|
+
session: SessionConfig;
|
|
40
|
+
}
|
|
41
|
+
export interface InputAudioBufferAppendEvent extends BaseEvent {
|
|
42
|
+
type: "input_audio_buffer.append";
|
|
43
|
+
audio: string;
|
|
44
|
+
}
|
|
45
|
+
export interface InputAudioBufferCommitEvent extends BaseEvent {
|
|
46
|
+
type: "input_audio_buffer.commit";
|
|
47
|
+
}
|
|
48
|
+
export interface SessionFinishEvent extends BaseEvent {
|
|
49
|
+
type: "session.finish";
|
|
50
|
+
}
|
|
51
|
+
type ClientEvent = SessionUpdateEvent | InputAudioBufferAppendEvent | InputAudioBufferCommitEvent | SessionFinishEvent;
|
|
52
|
+
export interface SessionCreatedEvent extends BaseEvent {
|
|
53
|
+
type: "session.created";
|
|
54
|
+
session: {
|
|
55
|
+
id: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface SessionUpdatedEvent extends BaseEvent {
|
|
59
|
+
type: "session.updated";
|
|
60
|
+
session: SessionConfig;
|
|
61
|
+
}
|
|
62
|
+
export interface SpeechStartedEvent extends BaseEvent {
|
|
63
|
+
type: "input_audio_buffer.speech_started";
|
|
64
|
+
}
|
|
65
|
+
export interface SpeechStoppedEvent extends BaseEvent {
|
|
66
|
+
type: "input_audio_buffer.speech_stopped";
|
|
67
|
+
}
|
|
68
|
+
export interface InputAudioBufferCommittedEvent extends BaseEvent {
|
|
69
|
+
type: "input_audio_buffer.committed";
|
|
70
|
+
}
|
|
71
|
+
export interface TranscriptionTextEvent extends BaseEvent {
|
|
72
|
+
type: "conversation.item.input_audio_transcription.text";
|
|
73
|
+
text?: string;
|
|
74
|
+
stash?: string;
|
|
75
|
+
transcript?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface TranscriptionCompletedEvent extends BaseEvent {
|
|
78
|
+
type: "conversation.item.input_audio_transcription.completed";
|
|
79
|
+
text?: string;
|
|
80
|
+
transcript?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface SessionFinishedEvent extends BaseEvent {
|
|
83
|
+
type: "session.finished";
|
|
84
|
+
}
|
|
85
|
+
export interface ErrorEvent extends BaseEvent {
|
|
86
|
+
type: "error";
|
|
87
|
+
error: {
|
|
88
|
+
message: string;
|
|
89
|
+
code?: string;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export type ServerEvent = SessionCreatedEvent | SessionUpdatedEvent | SpeechStartedEvent | SpeechStoppedEvent | InputAudioBufferCommittedEvent | TranscriptionTextEvent | TranscriptionCompletedEvent | SessionFinishedEvent | ErrorEvent;
|
|
93
|
+
export interface TurnDetectionConfig {
|
|
94
|
+
type: "server_vad";
|
|
95
|
+
/** VAD检测阈值,推荐设为 0.0,默认值 0.2,范围 [-1, 1] */
|
|
96
|
+
threshold?: number;
|
|
97
|
+
/** VAD断句检测阈值(ms),推荐设为 400,默认值 800,范围 [200, 6000] */
|
|
98
|
+
silence_duration_ms?: number;
|
|
99
|
+
}
|
|
100
|
+
export interface InputAudioTranscriptionConfig {
|
|
101
|
+
language?: ASRLanguage;
|
|
102
|
+
}
|
|
103
|
+
export interface SessionConfig {
|
|
104
|
+
input_audio_format?: "pcm" | "opus";
|
|
105
|
+
sample_rate?: 16000 | 8000;
|
|
106
|
+
input_audio_transcription?: InputAudioTranscriptionConfig;
|
|
107
|
+
turn_detection?: TurnDetectionConfig | null;
|
|
108
|
+
}
|
|
109
|
+
export interface ASRClientConfig {
|
|
110
|
+
/**
|
|
111
|
+
* Audio format
|
|
112
|
+
* @default "pcm"
|
|
113
|
+
*/
|
|
114
|
+
audioFormat?: "pcm" | "opus";
|
|
115
|
+
/**
|
|
116
|
+
* Sample rate in Hz
|
|
117
|
+
* @default 16000
|
|
118
|
+
* @description 支持 16000 和 8000。设置为 8000 时,服务端会先升采样到16000Hz再进行识别,可能引入微小延迟。
|
|
119
|
+
*/
|
|
120
|
+
sampleRate?: 16000 | 8000;
|
|
121
|
+
/**
|
|
122
|
+
* Audio source language
|
|
123
|
+
* @default "zh"
|
|
124
|
+
* @description 支持多种语言,包括 zh(中文)、yue(粤语)、en(英文)、ja(日语)等
|
|
125
|
+
*/
|
|
126
|
+
language?: ASRLanguage;
|
|
127
|
+
/**
|
|
128
|
+
* Enable VAD (Voice Activity Detection) mode
|
|
129
|
+
* @default true
|
|
130
|
+
* @description true = VAD模式(服务端自动检测语音开始/结束),false = Manual模式(客户端手动控制)
|
|
131
|
+
*/
|
|
132
|
+
enableVAD?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* VAD detection threshold
|
|
135
|
+
* @default 0.2
|
|
136
|
+
* @description 推荐设为 0.0。取值范围 [-1, 1]。较低的阈值会提高 VAD 的灵敏度。
|
|
137
|
+
*/
|
|
138
|
+
vadThreshold?: number;
|
|
139
|
+
/**
|
|
140
|
+
* VAD silence duration threshold in milliseconds
|
|
141
|
+
* @default 800
|
|
142
|
+
* @description 推荐设为 400。取值范围 [200, 6000]。静音持续时长超过该阈值将被认为是语句结束。
|
|
143
|
+
*/
|
|
144
|
+
vadSilenceDurationMs?: number;
|
|
145
|
+
/**
|
|
146
|
+
* Get access token for WebSocket authentication
|
|
147
|
+
*/
|
|
148
|
+
getAccessToken?: () => string | null;
|
|
149
|
+
/**
|
|
150
|
+
* Called when connection is ready (session.created received and session.update sent)
|
|
151
|
+
*/
|
|
152
|
+
onReady?: () => void;
|
|
153
|
+
/**
|
|
154
|
+
* Called when speech is detected (VAD mode only)
|
|
155
|
+
*/
|
|
156
|
+
onSpeechStart?: () => void;
|
|
157
|
+
/**
|
|
158
|
+
* Called when speech stops (VAD mode only)
|
|
159
|
+
*/
|
|
160
|
+
onSpeechEnd?: () => void;
|
|
161
|
+
/**
|
|
162
|
+
* Called on transcript result
|
|
163
|
+
* @param text - Transcribed text
|
|
164
|
+
* @param isFinal - Whether this is the final result
|
|
165
|
+
*/
|
|
166
|
+
onTranscript?: (text: string, isFinal: boolean) => void;
|
|
167
|
+
/**
|
|
168
|
+
* Called when audio buffer is committed (non-VAD mode only)
|
|
169
|
+
*/
|
|
170
|
+
onAudioBufferCommitted?: () => void;
|
|
171
|
+
/**
|
|
172
|
+
* Called when session is finished
|
|
173
|
+
*/
|
|
174
|
+
onSessionFinished?: () => void;
|
|
175
|
+
/**
|
|
176
|
+
* Called on error
|
|
177
|
+
*/
|
|
178
|
+
onError?: (error: Error) => void;
|
|
179
|
+
/**
|
|
180
|
+
* Called on close
|
|
181
|
+
*/
|
|
182
|
+
onClose?: () => void;
|
|
183
|
+
}
|
|
184
|
+
export interface ASRClient {
|
|
185
|
+
/** Connect to ASR service and establish session */
|
|
186
|
+
connect(): Promise<void>;
|
|
187
|
+
/** Start recording from microphone */
|
|
188
|
+
startRecording(): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* Stop recording
|
|
191
|
+
* @description In non-VAD mode, this triggers recognition by sending input_audio_buffer.commit
|
|
192
|
+
*/
|
|
193
|
+
stopRecording(): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Close connection gracefully
|
|
196
|
+
* @description Sends session.finish and waits for session.finished before closing
|
|
197
|
+
*/
|
|
198
|
+
close(): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Check if currently recording
|
|
201
|
+
*/
|
|
202
|
+
isRecording(): boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Check if connected to server
|
|
205
|
+
*/
|
|
206
|
+
isConnected(): boolean;
|
|
207
|
+
}
|
|
208
|
+
declare const _default$1: (authConfig: Pick<ASRClientConfig, "getAccessToken">) => (config: ASRClientConfig) => ASRClient;
|
|
209
|
+
|
|
210
|
+
export interface ASRHttpClientConfig {
|
|
211
|
+
/** Get access token */
|
|
212
|
+
getAccessToken?(): string | null;
|
|
213
|
+
/** Language, default 'zh' */
|
|
214
|
+
language?: string;
|
|
215
|
+
/** Sample rate, default 16000 */
|
|
216
|
+
sampleRate?: number;
|
|
217
|
+
/** Called when recording starts */
|
|
218
|
+
onRecordingStart?: () => void;
|
|
219
|
+
/** Called when recording stops */
|
|
220
|
+
onRecordingStop?: () => void;
|
|
221
|
+
/** Called with recognition result */
|
|
222
|
+
onResult?: (text: string) => void;
|
|
223
|
+
/** Called on error */
|
|
224
|
+
onError?: (error: Error) => void;
|
|
225
|
+
}
|
|
226
|
+
export interface ASRHttpClient {
|
|
227
|
+
/** Start recording (press-to-talk) */
|
|
228
|
+
startRecording(): Promise<void>;
|
|
229
|
+
/** Stop recording and get result */
|
|
230
|
+
stopRecording(): Promise<string>;
|
|
231
|
+
/** Record for specific duration then recognize */
|
|
232
|
+
recordAndRecognize(durationMs: number): Promise<string>;
|
|
233
|
+
/** Recognize audio file (File or Blob) */
|
|
234
|
+
recognizeFile(file: File | Blob): Promise<string>;
|
|
235
|
+
/** Recognize audio from URL */
|
|
236
|
+
recognizeUrl(audioUrl: string): Promise<string>;
|
|
237
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * Verification code-based authentication including:
|
|
3
|
+
* - Email verification code login
|
|
4
|
+
* - SMS verification code login
|
|
5
|
+
* - Send verification code
|
|
6
|
+
* - Captcha verification
|
|
7
|
+
*
|
|
8
|
+
* @module auth/code-auth
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { ClientResult } from '../common';
|
|
12
|
+
import type { LoginResponse, SuccessResponse } from './password-auth';
|
|
13
|
+
|
|
14
|
+
// ==================== Parameters ====================
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Verification code login type
|
|
18
|
+
*/
|
|
19
|
+
export type CodeLoginType = 'email' | 'phone';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Verification code login parameters
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
export interface CodeLoginParams {
|
|
26
|
+
/** Login method (optional, auto-detected) */
|
|
27
|
+
loginType?: CodeLoginType;
|
|
28
|
+
|
|
29
|
+
/** Email (required if using email code) */
|
|
30
|
+
email?: string;
|
|
31
|
+
|
|
32
|
+
/** Phone (required if using phone code) */
|
|
33
|
+
phone?: string;
|
|
34
|
+
|
|
35
|
+
/** Verification code received via email/SMS */
|
|
36
|
+
code: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Send verification code parameters
|
|
41
|
+
*/
|
|
42
|
+
export interface SendCodeParams {
|
|
43
|
+
/** Delivery method */
|
|
44
|
+
type: 'email' | 'phone';
|
|
45
|
+
|
|
46
|
+
/** Email address (required if type='email') */
|
|
47
|
+
email?: string;
|
|
48
|
+
|
|
49
|
+
/** Phone number (required if type='phone') */
|
|
50
|
+
phone?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Captcha response data
|
|
55
|
+
*/
|
|
56
|
+
export interface CaptchaResponse {
|
|
57
|
+
/** Unique captcha identifier */
|
|
58
|
+
captchaId: string;
|
|
59
|
+
|
|
60
|
+
/** Base64 encoded captcha image */
|
|
61
|
+
captchaImage: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ==================== API ====================
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Verification Code Authentication API
|
|
68
|
+
*
|
|
69
|
+
* Methods for code-based authentication and verification.
|
|
70
|
+
*/
|
|
71
|
+
export interface CodeAuthAPI {
|
|
72
|
+
/**
|
|
73
|
+
* Login with verification code
|
|
74
|
+
*
|
|
75
|
+
* Authenticates using a verification code sent to email or phone.
|
|
76
|
+
*
|
|
77
|
+
* @param params - Email/phone and verification code
|
|
78
|
+
* @returns User info and access token
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
codeLogin(params: CodeLoginParams): Promise<ClientResult<LoginResponse>>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Send verification code
|
|
85
|
+
*
|
|
86
|
+
* Sends a verification code to the specified email or phone.
|
|
87
|
+
* Used for code login or account verification.
|
|
88
|
+
*
|
|
89
|
+
* @param params - Email or phone to send code to
|
|
90
|
+
* @returns Success status
|
|
91
|
+
*
|
|
92
|
+
*/
|
|
93
|
+
sendCode(params: SendCodeParams): Promise<ClientResult<SuccessResponse>>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get captcha image
|
|
97
|
+
*
|
|
98
|
+
* Retrieves a captcha challenge for verification.
|
|
99
|
+
* Used during registration or sensitive operations.
|
|
100
|
+
*
|
|
101
|
+
* @returns Captcha ID and image (base64)
|
|
102
|
+
*
|
|
103
|
+
*/
|
|
104
|
+
getCaptcha(): Promise<ClientResult<CaptchaResponse>>;
|
|
105
|
+
}
|