@appthen/sdk-core 0.0.0
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/dist/index.d.ts +616 -0
- package/dist/index.js +789 -0
- package/dist-cjs/index.d.ts +616 -0
- package/dist-cjs/index.js +802 -0
- package/dist-cjs/package.json +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @appthen/sdk-core
|
|
3
|
+
*
|
|
4
|
+
* 平台无关的 Conversation Hub SDK 核心。
|
|
5
|
+
*
|
|
6
|
+
* V0 先对齐目前已经落地的 Hub API:
|
|
7
|
+
* - open-platform/token
|
|
8
|
+
* - subject-directory/open/*
|
|
9
|
+
* - conversation-runtime/open/*
|
|
10
|
+
* - 内部 JWT 保护的查询接口(messages / conversations)
|
|
11
|
+
*/
|
|
12
|
+
export declare const SDK_VERSION = "0.1.0";
|
|
13
|
+
export type RequestMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
14
|
+
export interface HttpRequestOptions {
|
|
15
|
+
method: RequestMethod;
|
|
16
|
+
path: string;
|
|
17
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
18
|
+
body?: unknown;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
export interface HttpResponse<T> {
|
|
22
|
+
status: number;
|
|
23
|
+
data: T;
|
|
24
|
+
headers: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
export interface HttpAdapter {
|
|
27
|
+
request<T>(options: HttpRequestOptions): Promise<HttpResponse<T>>;
|
|
28
|
+
}
|
|
29
|
+
export interface AuthProvider {
|
|
30
|
+
getToken(): Promise<string | null>;
|
|
31
|
+
setToken(token: string | null): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export interface RealtimeSubscription<TEvent = unknown> extends AsyncIterable<TEvent> {
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export interface RealtimeAdapter {
|
|
37
|
+
connect?(token?: string | null): Promise<void>;
|
|
38
|
+
disconnect?(): Promise<void>;
|
|
39
|
+
subscribeConversation?(_conversationId: string): Promise<RealtimeSubscription<unknown>>;
|
|
40
|
+
publishConversationEvent?(_conversationId: string, _event: Record<string, unknown>): Promise<void>;
|
|
41
|
+
joinRoom?(room: string): Promise<void>;
|
|
42
|
+
leaveRoom?(room: string): Promise<void>;
|
|
43
|
+
onGlobalEvent?(handler: (event: Record<string, unknown>) => void): () => void;
|
|
44
|
+
}
|
|
45
|
+
export interface ConversationTypingStateInput {
|
|
46
|
+
conversationId: string;
|
|
47
|
+
isTyping: boolean;
|
|
48
|
+
senderSubjectId?: string;
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
export interface ConversationReadStateInput {
|
|
52
|
+
conversationId: string;
|
|
53
|
+
messageId: string;
|
|
54
|
+
metadata?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
export interface TenantAppTokenPayload {
|
|
57
|
+
tenantId: string;
|
|
58
|
+
appId?: string;
|
|
59
|
+
appName?: string;
|
|
60
|
+
actingSubjectId?: string;
|
|
61
|
+
actingMode?: string;
|
|
62
|
+
scopes?: string[];
|
|
63
|
+
accessKey?: string;
|
|
64
|
+
exp?: number;
|
|
65
|
+
iat?: number;
|
|
66
|
+
[key: string]: unknown;
|
|
67
|
+
}
|
|
68
|
+
export interface IssueAppTokenInput {
|
|
69
|
+
accessKey: string;
|
|
70
|
+
accessSecret: string;
|
|
71
|
+
actingSubjectId?: string;
|
|
72
|
+
actingMode?: string;
|
|
73
|
+
requestedScopes?: string[];
|
|
74
|
+
}
|
|
75
|
+
export interface IssueAppTokenResult {
|
|
76
|
+
token: string;
|
|
77
|
+
tokenType?: string;
|
|
78
|
+
expiresIn?: number;
|
|
79
|
+
app?: TenantAppTokenPayload;
|
|
80
|
+
[key: string]: unknown;
|
|
81
|
+
}
|
|
82
|
+
export interface ExternalIdentityInput {
|
|
83
|
+
source: string;
|
|
84
|
+
externalKey: string;
|
|
85
|
+
identityKind?: string;
|
|
86
|
+
displayName?: string;
|
|
87
|
+
metadata?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
export interface CreateSubjectInput {
|
|
90
|
+
subjectId: string;
|
|
91
|
+
classId: string;
|
|
92
|
+
displayName: string;
|
|
93
|
+
avatar?: string;
|
|
94
|
+
avatarUrl?: string;
|
|
95
|
+
status?: string;
|
|
96
|
+
tags?: string[];
|
|
97
|
+
profile?: Record<string, unknown>;
|
|
98
|
+
searchableMeta?: Record<string, unknown>;
|
|
99
|
+
externalIdentity?: ExternalIdentityInput;
|
|
100
|
+
}
|
|
101
|
+
export interface CreateInternalSubjectInput extends CreateSubjectInput {
|
|
102
|
+
tenantId: string;
|
|
103
|
+
}
|
|
104
|
+
export interface CreateSubjectClassInput {
|
|
105
|
+
classId: string;
|
|
106
|
+
label: string;
|
|
107
|
+
ontology: string;
|
|
108
|
+
scope?: string;
|
|
109
|
+
lifecycle?: string;
|
|
110
|
+
status?: string;
|
|
111
|
+
description?: string;
|
|
112
|
+
notes?: string;
|
|
113
|
+
tags?: string[];
|
|
114
|
+
openRegistration?: boolean;
|
|
115
|
+
instanceMatcher?: Record<string, unknown>;
|
|
116
|
+
requiredExternalIdentity?: Record<string, unknown>;
|
|
117
|
+
capabilitySchema?: Record<string, unknown>;
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
export interface CreateInternalSubjectClassInput extends CreateSubjectClassInput {
|
|
121
|
+
tenantId: string;
|
|
122
|
+
}
|
|
123
|
+
export interface SubjectRecord {
|
|
124
|
+
tenantId: string;
|
|
125
|
+
subjectId: string;
|
|
126
|
+
classId: string;
|
|
127
|
+
kind: string;
|
|
128
|
+
displayName: string;
|
|
129
|
+
avatar?: string;
|
|
130
|
+
status?: string;
|
|
131
|
+
tags?: string[];
|
|
132
|
+
profile?: Record<string, unknown>;
|
|
133
|
+
searchableMeta?: Record<string, unknown>;
|
|
134
|
+
[key: string]: unknown;
|
|
135
|
+
}
|
|
136
|
+
export interface SubjectContext {
|
|
137
|
+
subject: SubjectRecord;
|
|
138
|
+
subjectClass?: Record<string, unknown>;
|
|
139
|
+
memberships?: Record<string, unknown>[];
|
|
140
|
+
organizationNodeIds?: string[];
|
|
141
|
+
membershipRelations?: string[];
|
|
142
|
+
[key: string]: unknown;
|
|
143
|
+
}
|
|
144
|
+
export interface QuerySubjectsInput {
|
|
145
|
+
tenantId: string;
|
|
146
|
+
classId?: string;
|
|
147
|
+
kind?: string;
|
|
148
|
+
status?: string;
|
|
149
|
+
tag?: string;
|
|
150
|
+
displayName?: string;
|
|
151
|
+
}
|
|
152
|
+
export interface ConversationTypeRecord {
|
|
153
|
+
tenantId: string;
|
|
154
|
+
typeId: string;
|
|
155
|
+
label?: string;
|
|
156
|
+
name?: string;
|
|
157
|
+
status?: string;
|
|
158
|
+
audiencePolicy?: Record<string, unknown>;
|
|
159
|
+
creatorPolicy?: Record<string, unknown>;
|
|
160
|
+
messagePolicy?: ChatHubMessagePolicy;
|
|
161
|
+
[key: string]: unknown;
|
|
162
|
+
}
|
|
163
|
+
export interface ChatHubMessagePolicy {
|
|
164
|
+
allowRichText?: boolean;
|
|
165
|
+
allowCopy?: boolean;
|
|
166
|
+
allowReply?: boolean;
|
|
167
|
+
allowForward?: boolean;
|
|
168
|
+
allowMultiForwardSelection?: boolean;
|
|
169
|
+
allowDelete?: boolean;
|
|
170
|
+
allowRevoke?: boolean;
|
|
171
|
+
[key: string]: unknown;
|
|
172
|
+
}
|
|
173
|
+
export interface CreateConversationTypeInput {
|
|
174
|
+
typeId: string;
|
|
175
|
+
label?: string;
|
|
176
|
+
name?: string;
|
|
177
|
+
conversationKind?: string;
|
|
178
|
+
status?: string;
|
|
179
|
+
welcomeMessage?: string;
|
|
180
|
+
audiencePolicy?: Record<string, unknown>;
|
|
181
|
+
creatorPolicy?: Record<string, unknown>;
|
|
182
|
+
messagePolicy?: ChatHubMessagePolicy;
|
|
183
|
+
defaultCapabilities?: Record<string, unknown>[];
|
|
184
|
+
optionalCapabilities?: Record<string, unknown>[];
|
|
185
|
+
restrictedCapabilities?: Record<string, unknown>[];
|
|
186
|
+
triggeredCapabilities?: Record<string, unknown>[];
|
|
187
|
+
capabilityTiers?: Record<string, string[]>;
|
|
188
|
+
metadata?: Record<string, unknown>;
|
|
189
|
+
[key: string]: unknown;
|
|
190
|
+
}
|
|
191
|
+
export interface CreateInternalConversationTypeInput extends CreateConversationTypeInput {
|
|
192
|
+
tenantId: string;
|
|
193
|
+
}
|
|
194
|
+
export interface ConversationRecord {
|
|
195
|
+
tenantId: string;
|
|
196
|
+
conversationId: string;
|
|
197
|
+
typeId?: string;
|
|
198
|
+
title: string;
|
|
199
|
+
createdBySubjectId?: string;
|
|
200
|
+
parentConversationId?: string;
|
|
201
|
+
type?: string;
|
|
202
|
+
status?: string;
|
|
203
|
+
relation?: string;
|
|
204
|
+
metadata?: Record<string, unknown>;
|
|
205
|
+
unreadCount?: number | null;
|
|
206
|
+
pinnedByMe?: boolean | null;
|
|
207
|
+
mutedByMe?: boolean | null;
|
|
208
|
+
[key: string]: unknown;
|
|
209
|
+
}
|
|
210
|
+
export interface CreateConversationInput {
|
|
211
|
+
conversationId: string;
|
|
212
|
+
typeId?: string;
|
|
213
|
+
title: string;
|
|
214
|
+
welcomeMessage?: string;
|
|
215
|
+
createdBySubjectId?: string;
|
|
216
|
+
parentConversationId?: string;
|
|
217
|
+
type?: string;
|
|
218
|
+
status?: string;
|
|
219
|
+
relation?: string;
|
|
220
|
+
visibilityPolicy?: Record<string, unknown>;
|
|
221
|
+
audienceSnapshot?: Record<string, unknown>;
|
|
222
|
+
contextPolicy?: Record<string, unknown>;
|
|
223
|
+
messagePolicy?: ChatHubMessagePolicy;
|
|
224
|
+
metadata?: Record<string, unknown>;
|
|
225
|
+
}
|
|
226
|
+
export interface CreateParticipantInput {
|
|
227
|
+
conversationId: string;
|
|
228
|
+
subjectId: string;
|
|
229
|
+
role?: string;
|
|
230
|
+
status?: string;
|
|
231
|
+
visibilityScope?: Record<string, unknown>;
|
|
232
|
+
capabilityScope?: Record<string, unknown>;
|
|
233
|
+
}
|
|
234
|
+
export interface ConversationParticipantRecord {
|
|
235
|
+
tenantId: string;
|
|
236
|
+
conversationId: string;
|
|
237
|
+
subjectId: string;
|
|
238
|
+
role?: string;
|
|
239
|
+
status?: string;
|
|
240
|
+
visibilityScope?: Record<string, unknown>;
|
|
241
|
+
capabilityScope?: Record<string, unknown>;
|
|
242
|
+
organizationNodeIds?: string[];
|
|
243
|
+
membershipRelations?: string[];
|
|
244
|
+
[key: string]: unknown;
|
|
245
|
+
}
|
|
246
|
+
export interface QueryParticipantsInput {
|
|
247
|
+
tenantId?: string;
|
|
248
|
+
conversationId: string;
|
|
249
|
+
status?: string;
|
|
250
|
+
}
|
|
251
|
+
export interface ConversationMessageRecord {
|
|
252
|
+
tenantId: string;
|
|
253
|
+
messageId: string;
|
|
254
|
+
conversationId: string;
|
|
255
|
+
sequence?: number;
|
|
256
|
+
senderSubjectId: string;
|
|
257
|
+
kind?: string;
|
|
258
|
+
content: Record<string, unknown>;
|
|
259
|
+
mentionedSubjectIds?: string[];
|
|
260
|
+
visibility?: Record<string, unknown>;
|
|
261
|
+
status?: string;
|
|
262
|
+
metadata?: Record<string, unknown>;
|
|
263
|
+
[key: string]: unknown;
|
|
264
|
+
}
|
|
265
|
+
export interface CreateMessageInput {
|
|
266
|
+
conversationId: string;
|
|
267
|
+
messageId: string;
|
|
268
|
+
senderSubjectId?: string;
|
|
269
|
+
kind?: string;
|
|
270
|
+
content: Record<string, unknown>;
|
|
271
|
+
mentionedSubjectIds?: string[];
|
|
272
|
+
visibility?: Record<string, unknown>;
|
|
273
|
+
status?: string;
|
|
274
|
+
metadata?: Record<string, unknown>;
|
|
275
|
+
}
|
|
276
|
+
export interface CreateInternalMessageInput extends CreateMessageInput {
|
|
277
|
+
tenantId: string;
|
|
278
|
+
}
|
|
279
|
+
export interface QueryMessagesInput {
|
|
280
|
+
tenantId?: string;
|
|
281
|
+
conversationId: string;
|
|
282
|
+
limit?: number;
|
|
283
|
+
beforeCreatedAt?: string;
|
|
284
|
+
afterSequence?: number;
|
|
285
|
+
}
|
|
286
|
+
export interface UpdateMessageInput {
|
|
287
|
+
status?: string;
|
|
288
|
+
content?: Record<string, unknown>;
|
|
289
|
+
metadata?: Record<string, unknown>;
|
|
290
|
+
actorSubjectId?: string;
|
|
291
|
+
}
|
|
292
|
+
export interface UpdateInternalMessageInput extends UpdateMessageInput {
|
|
293
|
+
tenantId: string;
|
|
294
|
+
}
|
|
295
|
+
export interface QueryConversationsInput {
|
|
296
|
+
tenantId?: string;
|
|
297
|
+
typeId?: string;
|
|
298
|
+
status?: string;
|
|
299
|
+
createdBySubjectId?: string;
|
|
300
|
+
subjectId?: string;
|
|
301
|
+
}
|
|
302
|
+
export interface CreateInternalConversationInput extends CreateConversationInput {
|
|
303
|
+
tenantId: string;
|
|
304
|
+
}
|
|
305
|
+
export interface CreateInternalParticipantInput extends CreateParticipantInput {
|
|
306
|
+
tenantId: string;
|
|
307
|
+
}
|
|
308
|
+
export interface ResolveCapabilitiesResult {
|
|
309
|
+
defaultCapabilities?: Record<string, unknown>[];
|
|
310
|
+
optionalCapabilities?: Record<string, unknown>[];
|
|
311
|
+
restrictedCapabilities?: Record<string, unknown>[];
|
|
312
|
+
triggeredCapabilities?: Record<string, unknown>[];
|
|
313
|
+
[key: string]: unknown;
|
|
314
|
+
}
|
|
315
|
+
export type ChatHubAuthMode = 'internal_jwt' | 'tenant_app_token';
|
|
316
|
+
export interface ChatHubAuthConfig {
|
|
317
|
+
mode: ChatHubAuthMode;
|
|
318
|
+
appTokenInput?: IssueAppTokenInput;
|
|
319
|
+
}
|
|
320
|
+
export interface ChatHubTenantConfig {
|
|
321
|
+
tenantId: string;
|
|
322
|
+
}
|
|
323
|
+
export interface ChatHubSubjectClassPreset {
|
|
324
|
+
classId: string;
|
|
325
|
+
label: string;
|
|
326
|
+
ontology: string;
|
|
327
|
+
scope: string;
|
|
328
|
+
lifecycle: string;
|
|
329
|
+
status?: string;
|
|
330
|
+
instanceMatcher: Record<string, unknown>;
|
|
331
|
+
openRegistration?: boolean;
|
|
332
|
+
requiredExternalIdentity?: Record<string, unknown>;
|
|
333
|
+
tags?: string[];
|
|
334
|
+
notes?: string;
|
|
335
|
+
}
|
|
336
|
+
export interface ChatHubSubjectPreset {
|
|
337
|
+
subjectId: string;
|
|
338
|
+
classId: string;
|
|
339
|
+
displayName: string;
|
|
340
|
+
status?: string;
|
|
341
|
+
avatarUrl?: string;
|
|
342
|
+
profile?: Record<string, unknown>;
|
|
343
|
+
tags?: string[];
|
|
344
|
+
}
|
|
345
|
+
export interface ChatHubConversationTypePreset {
|
|
346
|
+
typeId: string;
|
|
347
|
+
name: string;
|
|
348
|
+
label?: string;
|
|
349
|
+
conversationKind?: string;
|
|
350
|
+
status?: string;
|
|
351
|
+
welcomeMessage?: string;
|
|
352
|
+
creatorPolicy?: Record<string, unknown>;
|
|
353
|
+
audiencePolicy?: Record<string, unknown>;
|
|
354
|
+
messagePolicy?: ChatHubMessagePolicy;
|
|
355
|
+
defaultCapabilities?: Record<string, unknown>[];
|
|
356
|
+
optionalCapabilities?: Record<string, unknown>[];
|
|
357
|
+
restrictedCapabilities?: Record<string, unknown>[];
|
|
358
|
+
triggeredCapabilities?: Record<string, unknown>[];
|
|
359
|
+
capabilityTiers?: Record<string, string[]>;
|
|
360
|
+
metadata?: Record<string, unknown>;
|
|
361
|
+
}
|
|
362
|
+
export interface ChatHubConversationPreset {
|
|
363
|
+
title: string;
|
|
364
|
+
typeId: string;
|
|
365
|
+
createdBySubjectId: string;
|
|
366
|
+
status?: string;
|
|
367
|
+
relation?: string;
|
|
368
|
+
parentConversationId?: string;
|
|
369
|
+
metadata?: Record<string, unknown>;
|
|
370
|
+
participants: Array<{
|
|
371
|
+
subjectId: string;
|
|
372
|
+
role?: string;
|
|
373
|
+
status?: string;
|
|
374
|
+
}>;
|
|
375
|
+
}
|
|
376
|
+
export interface ChatHubAppConfig {
|
|
377
|
+
auth: ChatHubAuthConfig;
|
|
378
|
+
tenant: ChatHubTenantConfig;
|
|
379
|
+
subjectClasses?: ChatHubSubjectClassPreset[];
|
|
380
|
+
subjects?: ChatHubSubjectPreset[];
|
|
381
|
+
conversationType?: ChatHubConversationTypePreset;
|
|
382
|
+
conversation?: ChatHubConversationPreset;
|
|
383
|
+
}
|
|
384
|
+
export declare function resolveChatHubMessagePolicy(value: unknown): Required<Pick<ChatHubMessagePolicy, 'allowRichText' | 'allowCopy' | 'allowReply' | 'allowForward' | 'allowMultiForwardSelection' | 'allowDelete' | 'allowRevoke'>>;
|
|
385
|
+
export interface ChatHubBootstrapResult {
|
|
386
|
+
tenantId: string;
|
|
387
|
+
subjectClassIds: string[];
|
|
388
|
+
subjectIds: string[];
|
|
389
|
+
conversationTypeId?: string;
|
|
390
|
+
conversation?: ConversationRecord;
|
|
391
|
+
}
|
|
392
|
+
export interface SendTextMessageOptions {
|
|
393
|
+
conversationId: string;
|
|
394
|
+
senderSubjectId: string;
|
|
395
|
+
text: string;
|
|
396
|
+
attachments?: unknown[];
|
|
397
|
+
messageId?: string;
|
|
398
|
+
mentionedSubjectIds?: string[];
|
|
399
|
+
metadata?: Record<string, unknown>;
|
|
400
|
+
status?: string;
|
|
401
|
+
}
|
|
402
|
+
export interface SendChatHubMessageOptions {
|
|
403
|
+
conversationId: string;
|
|
404
|
+
senderSubjectId: string;
|
|
405
|
+
kind: string;
|
|
406
|
+
content: Record<string, unknown>;
|
|
407
|
+
messageId?: string;
|
|
408
|
+
mentionedSubjectIds?: string[];
|
|
409
|
+
metadata?: Record<string, unknown>;
|
|
410
|
+
status?: string;
|
|
411
|
+
}
|
|
412
|
+
export interface ListChatHubMessagesOptions {
|
|
413
|
+
conversationId: string;
|
|
414
|
+
limit?: number;
|
|
415
|
+
beforeCreatedAt?: string;
|
|
416
|
+
afterSequence?: number;
|
|
417
|
+
}
|
|
418
|
+
export interface UpdateChatHubMessageOptions {
|
|
419
|
+
messageId: string;
|
|
420
|
+
status?: string;
|
|
421
|
+
content?: Record<string, unknown>;
|
|
422
|
+
metadata?: Record<string, unknown>;
|
|
423
|
+
actorSubjectId?: string;
|
|
424
|
+
}
|
|
425
|
+
export interface ListChatHubMessagesPageResult {
|
|
426
|
+
items: ConversationMessageRecord[];
|
|
427
|
+
hasMore: boolean;
|
|
428
|
+
nextBeforeCreatedAt?: string;
|
|
429
|
+
}
|
|
430
|
+
export type ChatHubMessageWatchReason = 'initial' | 'realtime_event' | 'fallback' | 'manual';
|
|
431
|
+
export interface WatchConversationMessagesEvent {
|
|
432
|
+
reason: ChatHubMessageWatchReason;
|
|
433
|
+
messages: ConversationMessageRecord[];
|
|
434
|
+
rawEvent?: unknown;
|
|
435
|
+
afterSequence?: number;
|
|
436
|
+
}
|
|
437
|
+
export interface WatchConversationMessagesOptions {
|
|
438
|
+
conversationId: string;
|
|
439
|
+
limit?: number;
|
|
440
|
+
immediate?: boolean;
|
|
441
|
+
fallbackIntervalMs?: number;
|
|
442
|
+
healthcheckIntervalMs?: number;
|
|
443
|
+
pauseWhenHidden?: boolean;
|
|
444
|
+
initialLastSequence?: number;
|
|
445
|
+
onMessages: (event: WatchConversationMessagesEvent) => void | Promise<void>;
|
|
446
|
+
onEvent?: (event: unknown) => void | Promise<void>;
|
|
447
|
+
onError?: (error: unknown) => void;
|
|
448
|
+
}
|
|
449
|
+
export interface ChatHubMessageWatcher {
|
|
450
|
+
refresh(reason?: ChatHubMessageWatchReason): Promise<void>;
|
|
451
|
+
close(): Promise<void>;
|
|
452
|
+
}
|
|
453
|
+
declare class BaseApi {
|
|
454
|
+
protected readonly http: HttpAdapter;
|
|
455
|
+
protected readonly auth: AuthProvider;
|
|
456
|
+
constructor(http: HttpAdapter, auth: AuthProvider);
|
|
457
|
+
protected request<T>(options: HttpRequestOptions): Promise<T>;
|
|
458
|
+
}
|
|
459
|
+
export declare class OpenPlatformApi extends BaseApi {
|
|
460
|
+
issueToken(input: IssueAppTokenInput): Promise<IssueAppTokenResult>;
|
|
461
|
+
getCurrentTokenPayload(): Promise<TenantAppTokenPayload>;
|
|
462
|
+
}
|
|
463
|
+
export declare class SubjectDirectoryApi extends BaseApi {
|
|
464
|
+
createSubject(input: CreateSubjectInput): Promise<SubjectRecord>;
|
|
465
|
+
createSubjectClass(input: CreateSubjectClassInput): Promise<Record<string, unknown>>;
|
|
466
|
+
createSubjectInternal(input: CreateInternalSubjectInput): Promise<SubjectRecord>;
|
|
467
|
+
createSubjectClassInternal(input: CreateInternalSubjectClassInput): Promise<Record<string, unknown>>;
|
|
468
|
+
createExternalIdentity(input: ExternalIdentityInput & {
|
|
469
|
+
subjectId?: string;
|
|
470
|
+
}): Promise<Record<string, unknown>>;
|
|
471
|
+
findSubjectByExternalIdentity(query: {
|
|
472
|
+
source: string;
|
|
473
|
+
externalKey: string;
|
|
474
|
+
}): Promise<SubjectRecord | null>;
|
|
475
|
+
getSubjectContext(subjectId: string): Promise<SubjectContext>;
|
|
476
|
+
listSubjects(query: QuerySubjectsInput): Promise<SubjectRecord[]>;
|
|
477
|
+
getSubjectContextInternal(tenantId: string, subjectId: string): Promise<SubjectContext>;
|
|
478
|
+
}
|
|
479
|
+
export declare class ConversationTypesApi extends BaseApi {
|
|
480
|
+
create(input: CreateConversationTypeInput): Promise<ConversationTypeRecord>;
|
|
481
|
+
resolveCapabilities(typeId: string, query?: {
|
|
482
|
+
subjectId?: string;
|
|
483
|
+
}): Promise<ResolveCapabilitiesResult>;
|
|
484
|
+
createInternal(input: CreateInternalConversationTypeInput): Promise<ConversationTypeRecord>;
|
|
485
|
+
listInternal(query: {
|
|
486
|
+
tenantId: string;
|
|
487
|
+
status?: string;
|
|
488
|
+
}): Promise<ConversationTypeRecord[]>;
|
|
489
|
+
}
|
|
490
|
+
export declare class ConversationsApi extends BaseApi {
|
|
491
|
+
create(input: CreateConversationInput): Promise<ConversationRecord>;
|
|
492
|
+
createInternal(input: CreateInternalConversationInput): Promise<ConversationRecord>;
|
|
493
|
+
list(query?: QueryConversationsInput): Promise<ConversationRecord[]>;
|
|
494
|
+
addParticipant(input: CreateParticipantInput): Promise<Record<string, unknown>>;
|
|
495
|
+
addParticipantInternal(input: CreateInternalParticipantInput): Promise<Record<string, unknown>>;
|
|
496
|
+
listParticipants(query: QueryParticipantsInput): Promise<ConversationParticipantRecord[]>;
|
|
497
|
+
}
|
|
498
|
+
export declare class MessagesApi extends BaseApi {
|
|
499
|
+
create(input: CreateMessageInput): Promise<ConversationMessageRecord>;
|
|
500
|
+
createInternal(input: CreateInternalMessageInput): Promise<ConversationMessageRecord>;
|
|
501
|
+
list(query: QueryMessagesInput): Promise<ConversationMessageRecord[]>;
|
|
502
|
+
updateInternal(messageId: string, input: UpdateInternalMessageInput): Promise<ConversationMessageRecord>;
|
|
503
|
+
}
|
|
504
|
+
export interface ChatHubClientOptions {
|
|
505
|
+
http: HttpAdapter;
|
|
506
|
+
auth: AuthProvider;
|
|
507
|
+
realtime?: RealtimeAdapter;
|
|
508
|
+
}
|
|
509
|
+
export declare class ChatHubClient {
|
|
510
|
+
private readonly options;
|
|
511
|
+
readonly openPlatform: OpenPlatformApi;
|
|
512
|
+
readonly subjects: SubjectDirectoryApi;
|
|
513
|
+
readonly conversationTypes: ConversationTypesApi;
|
|
514
|
+
readonly conversations: ConversationsApi;
|
|
515
|
+
readonly messages: MessagesApi;
|
|
516
|
+
readonly realtime?: RealtimeAdapter;
|
|
517
|
+
constructor(options: ChatHubClientOptions);
|
|
518
|
+
setToken(token: string | null): Promise<void>;
|
|
519
|
+
getToken(): Promise<string | null>;
|
|
520
|
+
issueAppToken(input: IssueAppTokenInput): Promise<IssueAppTokenResult>;
|
|
521
|
+
connectRealtime(): Promise<void>;
|
|
522
|
+
disconnectRealtime(): Promise<void>;
|
|
523
|
+
}
|
|
524
|
+
export declare class ChatHubAppRuntime {
|
|
525
|
+
private readonly client;
|
|
526
|
+
private readonly config;
|
|
527
|
+
constructor(client: ChatHubClient, config: ChatHubAppConfig);
|
|
528
|
+
get tenantId(): string;
|
|
529
|
+
get appConfig(): ChatHubAppConfig;
|
|
530
|
+
/** 暴露底层实时适配器,供宿主加入自定义房间 / 监听全局事件(跨设备同步等)。 */
|
|
531
|
+
get realtime(): RealtimeAdapter | undefined;
|
|
532
|
+
connectRealtime(): Promise<void>;
|
|
533
|
+
disconnectRealtime(): Promise<void>;
|
|
534
|
+
subscribeConversation(conversationId: string): Promise<RealtimeSubscription<unknown> | null>;
|
|
535
|
+
publishConversationEvent(conversationId: string, event: Record<string, unknown>): Promise<void>;
|
|
536
|
+
updateConversationTyping(input: ConversationTypingStateInput): Promise<void>;
|
|
537
|
+
updateConversationRead(input: ConversationReadStateInput): Promise<void>;
|
|
538
|
+
ensureAuthenticated(): Promise<void>;
|
|
539
|
+
bootstrapConversation(): Promise<ChatHubBootstrapResult>;
|
|
540
|
+
listConversations(subjectId?: string): Promise<ConversationRecord[]>;
|
|
541
|
+
listMessages(input: string | ListChatHubMessagesOptions): Promise<ConversationMessageRecord[]>;
|
|
542
|
+
listMessagesPage(input: string | ListChatHubMessagesOptions): Promise<ListChatHubMessagesPageResult>;
|
|
543
|
+
ensureParticipant(input: CreateParticipantInput): Promise<Record<string, unknown>>;
|
|
544
|
+
watchConversationMessages(options: WatchConversationMessagesOptions): ChatHubMessageWatcher;
|
|
545
|
+
sendTextMessage(input: SendTextMessageOptions): Promise<ConversationMessageRecord>;
|
|
546
|
+
sendMessage(input: SendChatHubMessageOptions): Promise<ConversationMessageRecord>;
|
|
547
|
+
updateMessage(input: UpdateChatHubMessageOptions): Promise<ConversationMessageRecord>;
|
|
548
|
+
deleteMessage(input: Omit<UpdateChatHubMessageOptions, 'status' | 'content'>): Promise<ConversationMessageRecord>;
|
|
549
|
+
revokeMessage(input: Omit<UpdateChatHubMessageOptions, 'status' | 'content'>): Promise<ConversationMessageRecord>;
|
|
550
|
+
private ensureSubjectClasses;
|
|
551
|
+
private ensureSubjects;
|
|
552
|
+
private ensureConversationType;
|
|
553
|
+
private createConversationFromPreset;
|
|
554
|
+
}
|
|
555
|
+
export declare function createChatHubAppRuntime(client: ChatHubClient, config: ChatHubAppConfig): ChatHubAppRuntime;
|
|
556
|
+
export interface PlatformProvisionTenantInput {
|
|
557
|
+
name: string;
|
|
558
|
+
/** 对账锚:SaaS 侧机构标识 ↔ AppThen tenantId,必填。 */
|
|
559
|
+
externalCorrelationId: string;
|
|
560
|
+
/** 该租户被授予的 platform scope,缺省 ['platform:subject:sync']。 */
|
|
561
|
+
grantScopes?: string[];
|
|
562
|
+
}
|
|
563
|
+
export interface PlatformProvisionTenantResult {
|
|
564
|
+
tenantId: string;
|
|
565
|
+
status: string;
|
|
566
|
+
externalCorrelationId: string;
|
|
567
|
+
grantId: string;
|
|
568
|
+
/** 仅首次开通返回(7d 有效);认领激活时提交。 */
|
|
569
|
+
claimToken?: string;
|
|
570
|
+
/** false = 幂等命中(同 platformId + externalCorrelationId 已开通过)。 */
|
|
571
|
+
created: boolean;
|
|
572
|
+
[key: string]: unknown;
|
|
573
|
+
}
|
|
574
|
+
export interface PlatformExternalIdentityInput {
|
|
575
|
+
source: string;
|
|
576
|
+
externalKey: string;
|
|
577
|
+
displayLabel?: string;
|
|
578
|
+
metadata?: Record<string, unknown>;
|
|
579
|
+
}
|
|
580
|
+
export interface PlatformSyncSubjectInput {
|
|
581
|
+
classId: string;
|
|
582
|
+
displayName: string;
|
|
583
|
+
/** 传入且与已绑定主体不一致时返回 409。 */
|
|
584
|
+
subjectId?: string;
|
|
585
|
+
status?: string;
|
|
586
|
+
avatarUrl?: string;
|
|
587
|
+
profile?: Record<string, unknown>;
|
|
588
|
+
tags?: string[];
|
|
589
|
+
/** 命中已存在主体时是否更新其可写字段,默认 false(纯幂等)。 */
|
|
590
|
+
updateOnMatch?: boolean;
|
|
591
|
+
/** 幂等键:{source, externalKey}。重复推送只产生一个 Subject,可安全重试。 */
|
|
592
|
+
externalIdentity: PlatformExternalIdentityInput;
|
|
593
|
+
}
|
|
594
|
+
export interface PlatformSyncSubjectResult {
|
|
595
|
+
subjectId: string;
|
|
596
|
+
targetTenantId: string;
|
|
597
|
+
created: boolean;
|
|
598
|
+
[key: string]: unknown;
|
|
599
|
+
}
|
|
600
|
+
export interface PlatformResolveTenantResult {
|
|
601
|
+
tenantId: string;
|
|
602
|
+
tenantStatus: string | null;
|
|
603
|
+
externalCorrelationId: string;
|
|
604
|
+
grants: Array<{
|
|
605
|
+
grantId: string;
|
|
606
|
+
scopes: string[];
|
|
607
|
+
status: string;
|
|
608
|
+
}>;
|
|
609
|
+
}
|
|
610
|
+
export declare class PlatformApi extends BaseApi {
|
|
611
|
+
provisionTenant(input: PlatformProvisionTenantInput): Promise<PlatformProvisionTenantResult>;
|
|
612
|
+
syncSubject(targetTenantId: string, input: PlatformSyncSubjectInput): Promise<PlatformSyncSubjectResult>;
|
|
613
|
+
resolveTenant(externalCorrelationId: string): Promise<PlatformResolveTenantResult>;
|
|
614
|
+
toggleGrant(grantId: string, status: 'active' | 'revoked'): Promise<Record<string, unknown>>;
|
|
615
|
+
}
|
|
616
|
+
export {};
|