@asgard-js/core 0.0.3 → 0.0.5
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 +67 -0
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1055 -948
- package/dist/index.mjs.map +1 -1
- package/dist/lib/channel.d.ts +19 -0
- package/dist/lib/channel.d.ts.map +1 -0
- package/dist/lib/client.d.ts +4 -4
- package/dist/lib/client.d.ts.map +1 -1
- package/dist/lib/conversation.d.ts +10 -19
- package/dist/lib/conversation.d.ts.map +1 -1
- package/dist/types/channel.d.ts +35 -0
- package/dist/types/channel.d.ts.map +1 -0
- package/dist/types/client.d.ts +7 -25
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ChannelConfig, FetchSseOptions, FetchSsePayload } from '../types';
|
|
2
|
+
|
|
3
|
+
export default class Channel {
|
|
4
|
+
private client;
|
|
5
|
+
customChannelId: string;
|
|
6
|
+
customMessageId?: string;
|
|
7
|
+
private isConnecting$;
|
|
8
|
+
private conversation$;
|
|
9
|
+
private statesObserver?;
|
|
10
|
+
private statesSubscription?;
|
|
11
|
+
private constructor();
|
|
12
|
+
static reset(config: ChannelConfig, options?: FetchSseOptions): Promise<Channel>;
|
|
13
|
+
private subscribe;
|
|
14
|
+
private fetchSse;
|
|
15
|
+
private resetChannel;
|
|
16
|
+
sendMessage(payload: Pick<FetchSsePayload, 'customMessageId' | 'text'>, options?: FetchSseOptions): Promise<void>;
|
|
17
|
+
close(): void;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/lib/channel.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EAEb,eAAe,EACf,eAAe,EAGhB,MAAM,WAAW,CAAC;AAInB,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,OAAO,CAAC,MAAM,CAAuB;IAE9B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IAEhC,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,aAAa,CAAgC;IACrD,OAAO,CAAC,cAAc,CAAC,CAAgC;IACvD,OAAO,CAAC,kBAAkB,CAAC,CAAe;IAE1C,OAAO;WAkBa,KAAK,CACvB,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,CAAC;IAgBnB,OAAO,CAAC,SAAS;IAcjB,OAAO,CAAC,QAAQ;IA2BhB,OAAO,CAAC,YAAY;IAYb,WAAW,CAChB,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,iBAAiB,GAAG,MAAM,CAAC,EAC1D,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC;IAwBT,KAAK,IAAI,IAAI;CAKrB"}
|
package/dist/lib/client.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ClientConfig,
|
|
1
|
+
import { ClientConfig, IAsgardServiceClient, FetchSsePayload, FetchSseOptions } from '../types';
|
|
2
2
|
|
|
3
|
-
export default class AsgardServiceClient {
|
|
3
|
+
export default class AsgardServiceClient implements IAsgardServiceClient {
|
|
4
4
|
private apiKey;
|
|
5
5
|
private endpoint;
|
|
6
6
|
private destroy$;
|
|
7
|
+
private transformSsePayload?;
|
|
7
8
|
constructor(config: ClientConfig);
|
|
8
|
-
|
|
9
|
-
sendMessage(payload: SendMessagePayload, options?: SendMessageOptions): void;
|
|
9
|
+
fetchSse(payload: FetchSsePayload, options?: FetchSseOptions): void;
|
|
10
10
|
close(): void;
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/lib/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/lib/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/lib/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,eAAe,EACf,eAAe,EAChB,MAAM,WAAW,CAAC;AAInB,MAAM,CAAC,OAAO,OAAO,mBAAoB,YAAW,oBAAoB;IACtE,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,mBAAmB,CAAC,CAAgD;gBAEhE,MAAM,EAAE,YAAY;IAchC,QAAQ,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI;IA0BnE,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -1,29 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConversationMessage, SseResponse } from '../types';
|
|
2
2
|
import { EventType } from '../constants/enum';
|
|
3
3
|
|
|
4
4
|
interface IConversation {
|
|
5
5
|
messages: Map<string, ConversationMessage> | null;
|
|
6
|
-
|
|
6
|
+
showDebugMessage?: boolean;
|
|
7
7
|
}
|
|
8
8
|
export default class Conversation implements IConversation {
|
|
9
|
+
showDebugMessage: boolean;
|
|
9
10
|
messages: Map<string, ConversationMessage> | null;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
onMessageStart(prev: Conversation, response: SseResponse<EventType.MESSAGE_START>, options: {
|
|
18
|
-
showDebugMessage: boolean;
|
|
19
|
-
}): Conversation;
|
|
20
|
-
onMessageDelta(prev: Conversation, response: SseResponse<EventType.MESSAGE_DELTA>, options: {
|
|
21
|
-
showDebugMessage: boolean;
|
|
22
|
-
}): Conversation;
|
|
23
|
-
onMessageComplete(prev: Conversation, response: SseResponse<EventType.MESSAGE_COMPLETE>, options: {
|
|
24
|
-
showDebugMessage: boolean;
|
|
25
|
-
}): Conversation;
|
|
26
|
-
onMessageDone(prev: Conversation): Conversation;
|
|
11
|
+
constructor({ messages, showDebugMessage }: IConversation);
|
|
12
|
+
private create;
|
|
13
|
+
pushMessage(message: ConversationMessage): Conversation;
|
|
14
|
+
onMessage(response: SseResponse<EventType>): Conversation;
|
|
15
|
+
onMessageStart(response: SseResponse<EventType.MESSAGE_START>): Conversation;
|
|
16
|
+
onMessageDelta(response: SseResponse<EventType.MESSAGE_DELTA>): Conversation;
|
|
17
|
+
onMessageComplete(response: SseResponse<EventType.MESSAGE_COMPLETE>): Conversation;
|
|
27
18
|
}
|
|
28
19
|
export {};
|
|
29
20
|
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../src/lib/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../src/lib/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7D,UAAU,aAAa;IACrB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,GAAG,IAAI,CAAC;IAClD,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,CAAC,OAAO,OAAO,YAAa,YAAW,aAAa;IACjD,gBAAgB,UAAS;IACzB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,GAAG,IAAI,CAAQ;gBAEpD,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,aAAa;IAKzD,OAAO,CAAC,MAAM;IAOd,WAAW,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY;IAOvD,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,SAAS,CAAC,GAAG,YAAY;IAmBzD,cAAc,CAAC,QAAQ,EAAE,WAAW,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,YAAY;IAwB5E,cAAc,CAAC,QAAQ,EAAE,WAAW,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,YAAY;IA+B5E,iBAAiB,CACf,QAAQ,EAAE,WAAW,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAChD,YAAY;CAqBhB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Message } from './sse-response';
|
|
2
|
+
import { IAsgardServiceClient } from './client';
|
|
3
|
+
import { default as Conversation } from '../lib/conversation';
|
|
4
|
+
import { EventType } from '../constants/enum';
|
|
5
|
+
import { Observer } from 'rxjs';
|
|
6
|
+
|
|
7
|
+
export type ObserverOrNext<T> = Partial<Observer<T>> | ((value: T) => void);
|
|
8
|
+
export interface ChannelStates {
|
|
9
|
+
isConnecting: boolean;
|
|
10
|
+
conversation: Conversation;
|
|
11
|
+
}
|
|
12
|
+
export interface ChannelConfig {
|
|
13
|
+
client: IAsgardServiceClient;
|
|
14
|
+
customChannelId: string;
|
|
15
|
+
customMessageId?: string;
|
|
16
|
+
conversation: Conversation;
|
|
17
|
+
statesObserver?: ObserverOrNext<ChannelStates>;
|
|
18
|
+
}
|
|
19
|
+
export type ConversationUserMessage = {
|
|
20
|
+
type: 'user';
|
|
21
|
+
messageId: string;
|
|
22
|
+
text: string;
|
|
23
|
+
time: Date;
|
|
24
|
+
};
|
|
25
|
+
export type ConversationBotMessage = {
|
|
26
|
+
type: 'bot';
|
|
27
|
+
messageId: string;
|
|
28
|
+
eventType: EventType;
|
|
29
|
+
isTyping: boolean;
|
|
30
|
+
typingText: string | null;
|
|
31
|
+
message: Message;
|
|
32
|
+
time: Date;
|
|
33
|
+
};
|
|
34
|
+
export type ConversationMessage = ConversationUserMessage | ConversationBotMessage;
|
|
35
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/types/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,YAAY,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC;AAE5E,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,oBAAoB,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;IAC3B,cAAc,CAAC,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC;CAChD;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,KAAK,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAC3B,uBAAuB,GACvB,sBAAsB,CAAC"}
|
package/dist/types/client.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SseResponse } from './sse-response';
|
|
2
2
|
import { EventType, FetchSseAction } from '../constants/enum';
|
|
3
3
|
|
|
4
|
+
export interface IAsgardServiceClient {
|
|
5
|
+
fetchSse(payload: FetchSsePayload, options?: FetchSseOptions): void;
|
|
6
|
+
}
|
|
4
7
|
export interface ClientConfig {
|
|
5
8
|
endpoint: string;
|
|
6
9
|
apiKey: string;
|
|
7
|
-
|
|
10
|
+
transformSsePayload?: (payload: FetchSsePayload) => FetchSsePayload;
|
|
8
11
|
}
|
|
9
12
|
export interface FetchSsePayload {
|
|
10
13
|
customChannelId: string;
|
|
@@ -12,32 +15,11 @@ export interface FetchSsePayload {
|
|
|
12
15
|
text: string;
|
|
13
16
|
action: FetchSseAction;
|
|
14
17
|
}
|
|
15
|
-
export interface
|
|
18
|
+
export interface FetchSseOptions {
|
|
19
|
+
delayTime?: number;
|
|
16
20
|
onSseStart?: () => void;
|
|
17
21
|
onSseMessage?: (response: SseResponse<EventType>) => void;
|
|
18
22
|
onSseError?: (error: unknown) => void;
|
|
19
23
|
onSseCompleted?: () => void;
|
|
20
24
|
}
|
|
21
|
-
export type SetChannelPayload = Pick<FetchSsePayload, 'customChannelId' | 'customMessageId'>;
|
|
22
|
-
export type SetChannelOptions = ConnectionOptions;
|
|
23
|
-
export type SendMessagePayload = Pick<FetchSsePayload, 'customChannelId' | 'customMessageId' | 'text'>;
|
|
24
|
-
export type SendMessageOptions = ConnectionOptions & {
|
|
25
|
-
delayTime?: number;
|
|
26
|
-
};
|
|
27
|
-
export type ConversationUserMessage = {
|
|
28
|
-
type: 'user';
|
|
29
|
-
messageId: string;
|
|
30
|
-
text: string;
|
|
31
|
-
time: Date;
|
|
32
|
-
};
|
|
33
|
-
export type ConversationBotMessage = {
|
|
34
|
-
type: 'bot';
|
|
35
|
-
messageId: string;
|
|
36
|
-
eventType: EventType;
|
|
37
|
-
isTyping: boolean;
|
|
38
|
-
typingText: string | null;
|
|
39
|
-
message: Message;
|
|
40
|
-
time: Date;
|
|
41
|
-
};
|
|
42
|
-
export type ConversationMessage = ConversationUserMessage | ConversationBotMessage;
|
|
43
25
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/types/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/types/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;CACrE;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,eAAe,CAAC;CACrE;AAED,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;IAC1D,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,UAAU,CAAC;AAC9B,mBAAmB,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,UAAU,CAAC;AAC9B,mBAAmB,WAAW,CAAC;AAC/B,mBAAmB,gBAAgB,CAAC"}
|