@wix/legends-platform-sdk 1.3.0 → 1.4.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/README.md CHANGED
@@ -94,7 +94,7 @@ const { status, join, leave } = useConversation({
94
94
 
95
95
  | Return | Type | Description |
96
96
  |--------|------|-------------|
97
- | `status` | `'pending' \| 'connecting' \| 'created' \| 'ended'` | Current conversation state |
97
+ | `status` | `'pending' \| 'created' \| 'destroying' \| 'destroyed' \| 'exceeded' \| 'inactivity-timeout' \| 'voice-not-found' \| 'initialization-error' \| 'error'` | Current conversation state |
98
98
  | `join()` | `() => void` | Start the conversation |
99
99
  | `leave()` | `(reason?) => void` | End the conversation |
100
100
 
@@ -130,7 +130,8 @@ await send({ message: 'Hello' });
130
130
 
131
131
  ```tsx
132
132
  const status = useConversationStatus();
133
- // 'pending' | 'connecting' | 'created' | 'ended'
133
+ // 'pending' | 'created' | 'destroying' | 'destroyed' | 'exceeded'
134
+ // | 'inactivity-timeout' | 'voice-not-found' | 'initialization-error' | 'error'
134
135
  ```
135
136
 
136
137
  #### `useConversationTimer()`
@@ -13,7 +13,9 @@ var _helpers = require("./helpers");
13
13
  function useCreateConversation(options) {
14
14
  const {
15
15
  type,
16
- config: chatConfig
16
+ config: chatConfig,
17
+ firstConversation,
18
+ lastConversationTopic
17
19
  } = options;
18
20
  const {
19
21
  chatId,
@@ -59,7 +61,9 @@ function useCreateConversation(options) {
59
61
  const result = await personaChatService.createInteractiveConversation({
60
62
  chatId,
61
63
  namespace,
62
- chatConfig
64
+ chatConfig,
65
+ firstConversation,
66
+ lastConversationTopic
63
67
  });
64
68
  setConversation({
65
69
  type: 'video',
@@ -74,7 +78,9 @@ function useCreateConversation(options) {
74
78
  const result = await personaChatService.createVoiceConversation({
75
79
  chatId,
76
80
  namespace,
77
- chatConfig
81
+ chatConfig,
82
+ firstConversation,
83
+ lastConversationTopic
78
84
  });
79
85
  setConversation({
80
86
  type: 'audio',
@@ -92,11 +98,13 @@ function useCreateConversation(options) {
92
98
  (0, _invariant.default)(conversation, 'Conversation is not ready');
93
99
  (0, _invariant.default)(personaChatService, 'personaChatService is required.');
94
100
  setConversationStatus('destroying');
95
- await personaChatService.endInteractiveConversation({
96
- chatId,
97
- conversationId: conversation.id,
98
- namespace
99
- }).catch(() => {});
101
+ if (conversation.type === 'video') {
102
+ await personaChatService.endInteractiveConversation({
103
+ chatId,
104
+ conversationId: conversation.id,
105
+ namespace
106
+ }).catch(() => {});
107
+ }
100
108
  setConversationStatus('destroyed');
101
109
  setConversation(undefined);
102
110
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_invariant","_interopRequireDefault","require","_react","_jotai","_reactUse","_conversation","_sdkConsumer","_helpers","useCreateConversation","options","type","config","chatConfig","chatId","namespace","personaChatService","useSdkConsumer","setConversationStatus","useSetAtom","state","conversationStatus","conversation","setConversation","useAtom","useEffect","create","then","catch","error","_err$message","err","status","message","includes","useUnmount","destroy","limit","data","invariant","result","createInteractiveConversation","url","id","createVoiceConversation","Error","endInteractiveConversation","conversationId","undefined"],"sources":["../../../../src/hooks/useCreateConversation/useCreateConversation.ts"],"sourcesContent":["import invariant from 'invariant';\nimport { useEffect } from 'react';\nimport { useAtom, useSetAtom } from 'jotai';\nimport { useUnmount } from 'react-use';\n\nimport {\n state,\n type ConversationType,\n type Conversation,\n} from '../../conversation';\nimport { useSdkConsumer } from '../../sdk-consumer';\nimport { limit } from './helpers';\n\nexport type UseCreateConversationOptions = {\n type: ConversationType;\n config?: object;\n};\n\nexport type UseCreateConversationResult = {\n data?: Conversation;\n destroy(): Promise<void>;\n};\n\nexport function useCreateConversation(\n options: UseCreateConversationOptions,\n): UseCreateConversationResult {\n const { type, config: chatConfig } = options;\n\n const { chatId, namespace, personaChatService } = useSdkConsumer();\n\n const setConversationStatus = useSetAtom(state.conversationStatus);\n const [conversation, setConversation] = useAtom(state.conversation);\n\n useEffect(() => {\n void create()\n .then(() => setConversationStatus('created'))\n .catch((error: unknown) => {\n const err = error as { status?: number; message?: string };\n if (err.status === 404 && err.message?.includes('not found')) {\n setConversationStatus('voice-not-found');\n } else {\n setConversationStatus('initialization-error');\n }\n });\n }, [type, chatId]);\n\n useUnmount(() => {\n if (!conversation) {\n return;\n }\n void destroy();\n });\n\n useEffect(() => {\n if (!conversation) {\n return;\n }\n if (conversation.limit === 0) {\n setConversationStatus('exceeded');\n }\n }, [conversation]);\n\n return { data: conversation, destroy };\n\n async function create() {\n invariant(\n personaChatService,\n 'personaChatService is required. Pass it as a prop to LegendsPlatform.',\n );\n\n switch (type) {\n case 'video': {\n const result = await personaChatService.createInteractiveConversation({\n chatId,\n namespace,\n chatConfig,\n });\n setConversation({\n type: 'video',\n url: result.url,\n id: result.id,\n limit: limit(result.limit),\n });\n break;\n }\n case 'audio': {\n const result = await personaChatService.createVoiceConversation({\n chatId,\n namespace,\n chatConfig,\n });\n setConversation({\n type: 'audio',\n url: result.url,\n id: result.id,\n limit: limit(result.limit),\n });\n break;\n }\n default:\n throw new Error(`Unsupported conversation type: ${type}`);\n }\n }\n\n async function destroy() {\n invariant(conversation, 'Conversation is not ready');\n invariant(personaChatService, 'personaChatService is required.');\n\n setConversationStatus('destroying');\n\n await personaChatService\n .endInteractiveConversation({\n chatId,\n conversationId: conversation.id,\n namespace,\n })\n .catch(() => {});\n\n setConversationStatus('destroyed');\n setConversation(undefined);\n }\n}\n"],"mappings":";;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAEA,IAAAI,aAAA,GAAAJ,OAAA;AAKA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAYO,SAASO,qBAAqBA,CACnCC,OAAqC,EACR;EAC7B,MAAM;IAAEC,IAAI;IAAEC,MAAM,EAAEC;EAAW,CAAC,GAAGH,OAAO;E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]}
1
+ {"version":3,"names":["_invariant","_interopRequireDefault","require","_react","_jotai","_reactUse","_conversation","_sdkConsumer","_helpers","useCreateConversation","options","type","config","chatConfig","firstConversation","lastConversationTopic","chatId","namespace","personaChatService","useSdkConsumer","setConversationStatus","useSetAtom","state","conversationStatus","conversation","setConversation","useAtom","useEffect","create","then","catch","error","_err$message","err","status","message","includes","useUnmount","destroy","limit","data","invariant","result","createInteractiveConversation","url","id","createVoiceConversation","Error","endInteractiveConversation","conversationId","undefined"],"sources":["../../../../src/hooks/useCreateConversation/useCreateConversation.ts"],"sourcesContent":["import invariant from 'invariant';\nimport { useEffect } from 'react';\nimport { useAtom, useSetAtom } from 'jotai';\nimport { useUnmount } from 'react-use';\n\nimport {\n state,\n type ConversationType,\n type Conversation,\n} from '../../conversation';\nimport { useSdkConsumer } from '../../sdk-consumer';\nimport { limit } from './helpers';\n\nexport type UseCreateConversationOptions = {\n type: ConversationType;\n config?: object;\n /** Whether this is the visitor's first-ever conversation with the persona (drives the opening message). */\n firstConversation?: boolean;\n /** Title of the visitor's last meaningful conversation, for a returning-visitor greeting. */\n lastConversationTopic?: string;\n};\n\nexport type UseCreateConversationResult = {\n data?: Conversation;\n destroy(): Promise<void>;\n};\n\nexport function useCreateConversation(\n options: UseCreateConversationOptions,\n): UseCreateConversationResult {\n const {\n type,\n config: chatConfig,\n firstConversation,\n lastConversationTopic,\n } = options;\n\n const { chatId, namespace, personaChatService } = useSdkConsumer();\n\n const setConversationStatus = useSetAtom(state.conversationStatus);\n const [conversation, setConversation] = useAtom(state.conversation);\n\n useEffect(() => {\n void create()\n .then(() => setConversationStatus('created'))\n .catch((error: unknown) => {\n const err = error as { status?: number; message?: string };\n if (err.status === 404 && err.message?.includes('not found')) {\n setConversationStatus('voice-not-found');\n } else {\n setConversationStatus('initialization-error');\n }\n });\n }, [type, chatId]);\n\n useUnmount(() => {\n if (!conversation) {\n return;\n }\n void destroy();\n });\n\n useEffect(() => {\n if (!conversation) {\n return;\n }\n if (conversation.limit === 0) {\n setConversationStatus('exceeded');\n }\n }, [conversation]);\n\n return { data: conversation, destroy };\n\n async function create() {\n invariant(\n personaChatService,\n 'personaChatService is required. Pass it as a prop to LegendsPlatform.',\n );\n\n switch (type) {\n case 'video': {\n const result = await personaChatService.createInteractiveConversation({\n chatId,\n namespace,\n chatConfig,\n firstConversation,\n lastConversationTopic,\n });\n setConversation({\n type: 'video',\n url: result.url,\n id: result.id,\n limit: limit(result.limit),\n });\n break;\n }\n case 'audio': {\n const result = await personaChatService.createVoiceConversation({\n chatId,\n namespace,\n chatConfig,\n firstConversation,\n lastConversationTopic,\n });\n setConversation({\n type: 'audio',\n url: result.url,\n id: result.id,\n limit: limit(result.limit),\n });\n break;\n }\n default:\n throw new Error(`Unsupported conversation type: ${type}`);\n }\n }\n\n async function destroy() {\n invariant(conversation, 'Conversation is not ready');\n invariant(personaChatService, 'personaChatService is required.');\n\n setConversationStatus('destroying');\n\n if (conversation.type === 'video') {\n await personaChatService\n .endInteractiveConversation({\n chatId,\n conversationId: conversation.id,\n namespace,\n })\n .catch(() => {});\n }\n\n setConversationStatus('destroyed');\n setConversation(undefined);\n }\n}\n"],"mappings":";;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAEA,IAAAI,aAAA,GAAAJ,OAAA;AAKA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAgBO,SAASO,qBAAqBA,CACnCC,OAAqC,EACR;EAC7B,MAAM;IACJC,IAAI;IACJC,MAAM,EAAEC,UAAU;IAClBC,iBAAiB;IACjBC;EACF,CAAC,GAAGL,OAAO;EAEX,MAAM;IAAEM,MAAM;IAAEC,SAAS;IAAEC;EAAmB,CAAC,GAAG,IAAAC,2BAAc,EAAC,CAAC;EAElE,MAAMC,qBAAqB,GAAG,IAAA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 @@
1
- {"version":3,"names":[],"sources":["../../../src/types/service.ts"],"sourcesContent":["export type FunctionCall = {\n functionCallId: string;\n name: string;\n arguments: string;\n};\n\nexport type FunctionCallResult = {\n functionCallId: string;\n result: string;\n error?: string;\n};\n\nexport type LimitationType = 'MINUTES' | 'SECONDS' | 'TOKENS';\n\nexport interface Limitation {\n type?: LimitationType;\n limit?: number;\n}\n\nexport interface ConversationResult {\n url: string;\n id: string;\n limit?: number;\n}\n\nexport interface CreateConversationParams {\n chatId: string;\n namespace: string;\n chatConfig?: object;\n}\n\nexport interface EndConversationParams {\n chatId: string;\n conversationId: string;\n namespace: string;\n}\n\nexport interface ChatMessageAttachment {\n fileName?: string;\n url?: string;\n mimeType?: string;\n textFileContent?: string;\n}\n\nexport interface SendMessageParams {\n chatId: string;\n namespace: string;\n message: string;\n functionCallResults?: FunctionCallResult[];\n chatConfig?: object;\n attachments?: ChatMessageAttachment[];\n}\n\nexport interface ChatMessage {\n id: string;\n content: string;\n role: 'user' | 'assistant';\n createdAt?: string;\n attachments?: ChatMessageAttachment[];\n}\n\nexport interface QueryMessagesParams {\n chatId: string;\n namespace: string;\n limit?: number;\n cursor?: string;\n}\n\nexport interface QueryMessagesResult {\n messages: ChatMessage[];\n nextCursor?: string;\n}\n\nexport interface IPersonaChatService {\n createVoiceConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult>;\n createInteractiveConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult>;\n endInteractiveConversation(params: EndConversationParams): Promise<void>;\n sendChatMessage(\n params: SendMessageParams,\n ): Promise<{ functionCalls?: FunctionCall[]; messages?: ChatMessage[] }>;\n queryChatMessages(params: QueryMessagesParams): Promise<QueryMessagesResult>;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["../../../src/types/service.ts"],"sourcesContent":["export type FunctionCall = {\n functionCallId: string;\n name: string;\n arguments: string;\n};\n\nexport type FunctionCallResult = {\n functionCallId: string;\n result: string;\n error?: string;\n};\n\nexport type LimitationType = 'MINUTES' | 'SECONDS' | 'TOKENS';\n\nexport interface Limitation {\n type?: LimitationType;\n limit?: number;\n}\n\nexport interface ConversationResult {\n url: string;\n id: string;\n limit?: number;\n}\n\nexport interface CreateConversationParams {\n chatId: string;\n namespace: string;\n chatConfig?: object;\n /** Whether this is the visitor's first-ever conversation with the persona (drives the opening message). */\n firstConversation?: boolean;\n /** Title of the visitor's last meaningful conversation, for a returning-visitor greeting. */\n lastConversationTopic?: string;\n}\n\nexport interface EndConversationParams {\n chatId: string;\n conversationId: string;\n namespace: string;\n}\n\nexport interface ChatMessageAttachment {\n fileName?: string;\n url?: string;\n mimeType?: string;\n textFileContent?: string;\n}\n\nexport interface SendMessageParams {\n chatId: string;\n namespace: string;\n message: string;\n functionCallResults?: FunctionCallResult[];\n chatConfig?: object;\n attachments?: ChatMessageAttachment[];\n}\n\nexport interface ChatMessage {\n id: string;\n content: string;\n role: 'user' | 'assistant';\n createdAt?: string;\n attachments?: ChatMessageAttachment[];\n}\n\nexport interface QueryMessagesParams {\n chatId: string;\n namespace: string;\n limit?: number;\n cursor?: string;\n}\n\nexport interface QueryMessagesResult {\n messages: ChatMessage[];\n nextCursor?: string;\n}\n\nexport interface IPersonaChatService {\n createVoiceConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult>;\n createInteractiveConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult>;\n endInteractiveConversation(params: EndConversationParams): Promise<void>;\n sendChatMessage(\n params: SendMessageParams,\n ): Promise<{ functionCalls?: FunctionCall[]; messages?: ChatMessage[] }>;\n queryChatMessages(params: QueryMessagesParams): Promise<QueryMessagesResult>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -7,7 +7,9 @@ import { useSdkConsumer } from '../../sdk-consumer';
7
7
  import { limit } from './helpers';
8
8
  export function useCreateConversation(options) {
9
9
  const type = options.type,
10
- chatConfig = options.config;
10
+ chatConfig = options.config,
11
+ firstConversation = options.firstConversation,
12
+ lastConversationTopic = options.lastConversationTopic;
11
13
  const _useSdkConsumer = useSdkConsumer(),
12
14
  chatId = _useSdkConsumer.chatId,
13
15
  namespace = _useSdkConsumer.namespace,
@@ -53,7 +55,9 @@ export function useCreateConversation(options) {
53
55
  const result = await personaChatService.createInteractiveConversation({
54
56
  chatId,
55
57
  namespace,
56
- chatConfig
58
+ chatConfig,
59
+ firstConversation,
60
+ lastConversationTopic
57
61
  });
58
62
  setConversation({
59
63
  type: 'video',
@@ -68,7 +72,9 @@ export function useCreateConversation(options) {
68
72
  const result = await personaChatService.createVoiceConversation({
69
73
  chatId,
70
74
  namespace,
71
- chatConfig
75
+ chatConfig,
76
+ firstConversation,
77
+ lastConversationTopic
72
78
  });
73
79
  setConversation({
74
80
  type: 'audio',
@@ -86,11 +92,13 @@ export function useCreateConversation(options) {
86
92
  invariant(conversation, 'Conversation is not ready');
87
93
  invariant(personaChatService, 'personaChatService is required.');
88
94
  setConversationStatus('destroying');
89
- await personaChatService.endInteractiveConversation({
90
- chatId,
91
- conversationId: conversation.id,
92
- namespace
93
- }).catch(() => {});
95
+ if (conversation.type === 'video') {
96
+ await personaChatService.endInteractiveConversation({
97
+ chatId,
98
+ conversationId: conversation.id,
99
+ namespace
100
+ }).catch(() => {});
101
+ }
94
102
  setConversationStatus('destroyed');
95
103
  setConversation(undefined);
96
104
  }
@@ -1 +1 @@
1
- {"version":3,"names":["invariant","useEffect","useAtom","useSetAtom","useUnmount","state","useSdkConsumer","limit","useCreateConversation","options","type","chatConfig","config","_useSdkConsumer","chatId","namespace","personaChatService","setConversationStatus","conversationStatus","_useAtom","conversation","setConversation","create","then","catch","error","_err$message","err","status","message","includes","destroy","data","result","createInteractiveConversation","url","id","createVoiceConversation","Error","endInteractiveConversation","conversationId","undefined"],"sources":["../../../../src/hooks/useCreateConversation/useCreateConversation.ts"],"sourcesContent":["import invariant from 'invariant';\nimport { useEffect } from 'react';\nimport { useAtom, useSetAtom } from 'jotai';\nimport { useUnmount } from 'react-use';\n\nimport {\n state,\n type ConversationType,\n type Conversation,\n} from '../../conversation';\nimport { useSdkConsumer } from '../../sdk-consumer';\nimport { limit } from './helpers';\n\nexport type UseCreateConversationOptions = {\n type: ConversationType;\n config?: object;\n};\n\nexport type UseCreateConversationResult = {\n data?: Conversation;\n destroy(): Promise<void>;\n};\n\nexport function useCreateConversation(\n options: UseCreateConversationOptions,\n): UseCreateConversationResult {\n const { type, config: chatConfig } = options;\n\n const { chatId, namespace, personaChatService } = useSdkConsumer();\n\n const setConversationStatus = useSetAtom(state.conversationStatus);\n const [conversation, setConversation] = useAtom(state.conversation);\n\n useEffect(() => {\n void create()\n .then(() => setConversationStatus('created'))\n .catch((error: unknown) => {\n const err = error as { status?: number; message?: string };\n if (err.status === 404 && err.message?.includes('not found')) {\n setConversationStatus('voice-not-found');\n } else {\n setConversationStatus('initialization-error');\n }\n });\n }, [type, chatId]);\n\n useUnmount(() => {\n if (!conversation) {\n return;\n }\n void destroy();\n });\n\n useEffect(() => {\n if (!conversation) {\n return;\n }\n if (conversation.limit === 0) {\n setConversationStatus('exceeded');\n }\n }, [conversation]);\n\n return { data: conversation, destroy };\n\n async function create() {\n invariant(\n personaChatService,\n 'personaChatService is required. Pass it as a prop to LegendsPlatform.',\n );\n\n switch (type) {\n case 'video': {\n const result = await personaChatService.createInteractiveConversation({\n chatId,\n namespace,\n chatConfig,\n });\n setConversation({\n type: 'video',\n url: result.url,\n id: result.id,\n limit: limit(result.limit),\n });\n break;\n }\n case 'audio': {\n const result = await personaChatService.createVoiceConversation({\n chatId,\n namespace,\n chatConfig,\n });\n setConversation({\n type: 'audio',\n url: result.url,\n id: result.id,\n limit: limit(result.limit),\n });\n break;\n }\n default:\n throw new Error(`Unsupported conversation type: ${type}`);\n }\n }\n\n async function destroy() {\n invariant(conversation, 'Conversation is not ready');\n invariant(personaChatService, 'personaChatService is required.');\n\n setConversationStatus('destroying');\n\n await personaChatService\n .endInteractiveConversation({\n chatId,\n conversationId: conversation.id,\n namespace,\n })\n .catch(() => {});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,IAAI+B,KAAK,CAAC,kCAAkC5B,IAAI,EAAE,CAAC;IAC7D;EACF;EAEA,eAAeqB,OAAOA,CAAA,EAAG;IACvB/B,SAAS,CAACoB,YAAY,EAAE,2BAA2B,CAAC;IACpDpB,SAAS,CAACgB,kBAAkB,EAAE,iCAAiC,CAAC;IAEhEC,qBAAqB,CAAC,YAAY,CAAC;IAEnC,MAAMD,kBAAkB,CACrBuB,0BAA0B,CAAC;MAC1BzB,MAAM;MACN0B,cAAc,EAAEpB,YAAY,CAACgB,EAAE;MAC/BrB;IACF,CAAC,CAAC,CACDS,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAElBP,qBAAqB,CAAC,WAAW,CAAC;IAClCI,eAAe,CAACoB,SAAS,CAAC;EAC5B;AACF","ignoreList":[]}
1
+ {"version":3,"names":["invariant","useEffect","useAtom","useSetAtom","useUnmount","state","useSdkConsumer","limit","useCreateConversation","options","type","chatConfig","config","firstConversation","lastConversationTopic","_useSdkConsumer","chatId","namespace","personaChatService","setConversationStatus","conversationStatus","_useAtom","conversation","setConversation","create","then","catch","error","_err$message","err","status","message","includes","destroy","data","result","createInteractiveConversation","url","id","createVoiceConversation","Error","endInteractiveConversation","conversationId","undefined"],"sources":["../../../../src/hooks/useCreateConversation/useCreateConversation.ts"],"sourcesContent":["import invariant from 'invariant';\nimport { useEffect } from 'react';\nimport { useAtom, useSetAtom } from 'jotai';\nimport { useUnmount } from 'react-use';\n\nimport {\n state,\n type ConversationType,\n type Conversation,\n} from '../../conversation';\nimport { useSdkConsumer } from '../../sdk-consumer';\nimport { limit } from './helpers';\n\nexport type UseCreateConversationOptions = {\n type: ConversationType;\n config?: object;\n /** Whether this is the visitor's first-ever conversation with the persona (drives the opening message). */\n firstConversation?: boolean;\n /** Title of the visitor's last meaningful conversation, for a returning-visitor greeting. */\n lastConversationTopic?: string;\n};\n\nexport type UseCreateConversationResult = {\n data?: Conversation;\n destroy(): Promise<void>;\n};\n\nexport function useCreateConversation(\n options: UseCreateConversationOptions,\n): UseCreateConversationResult {\n const {\n type,\n config: chatConfig,\n firstConversation,\n lastConversationTopic,\n } = options;\n\n const { chatId, namespace, personaChatService } = useSdkConsumer();\n\n const setConversationStatus = useSetAtom(state.conversationStatus);\n const [conversation, setConversation] = useAtom(state.conversation);\n\n useEffect(() => {\n void create()\n .then(() => setConversationStatus('created'))\n .catch((error: unknown) => {\n const err = error as { status?: number; message?: string };\n if (err.status === 404 && err.message?.includes('not found')) {\n setConversationStatus('voice-not-found');\n } else {\n setConversationStatus('initialization-error');\n }\n });\n }, [type, chatId]);\n\n useUnmount(() => {\n if (!conversation) {\n return;\n }\n void destroy();\n });\n\n useEffect(() => {\n if (!conversation) {\n return;\n }\n if (conversation.limit === 0) {\n setConversationStatus('exceeded');\n }\n }, [conversation]);\n\n return { data: conversation, destroy };\n\n async function create() {\n invariant(\n personaChatService,\n 'personaChatService is required. Pass it as a prop to LegendsPlatform.',\n );\n\n switch (type) {\n case 'video': {\n const result = await personaChatService.createInteractiveConversation({\n chatId,\n namespace,\n chatConfig,\n firstConversation,\n lastConversationTopic,\n });\n setConversation({\n type: 'video',\n url: result.url,\n id: result.id,\n limit: limit(result.limit),\n });\n break;\n }\n case 'audio': {\n const result = await personaChatService.createVoiceConversation({\n chatId,\n namespace,\n chatConfig,\n firstConversation,\n lastConversationTopic,\n });\n setConversation({\n type: 'audio',\n url: result.url,\n id: result.id,\n limit: limit(result.limit),\n });\n break;\n }\n default:\n throw new Error(`Unsupported conversation type: ${type}`);\n }\n }\n\n async function destroy() {\n invariant(conversation, 'Conversation is not ready');\n invariant(personaChatService, 'personaChatService is required.');\n\n setConversationStatus('destroying');\n\n if (conversation.type === 'video') {\n await personaChatService\n .endInteractiveConversation({\n chatId,\n conversationId: conversation.id,\n namespace,\n })\n .catch(() => {});\n }\n\n setConversationStatus('destroyed');\n setConversation(undefined);\n }\n}\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,WAAW;AACjC,SAASC,SAAS,QAAQ,OAA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AAC;UACF;QACF;MACA;QACE,MAAM,IAAIiC,KAAK,CAAC,kCAAkC9B,IAAI,EAAE,CAAC;IAC7D;EACF;EAEA,eAAeuB,OAAOA,CAAA,EAAG;IACvBjC,SAAS,CAACsB,YAAY,EAAE,2BAA2B,CAAC;IACpDtB,SAAS,CAACkB,kBAAkB,EAAE,iCAAiC,CAAC;IAEhEC,qBAAqB,CAAC,YAAY,CAAC;IAEnC,IAAIG,YAAY,CAACZ,IAAI,KAAK,OAAO,EAAE;MACjC,MAAMQ,kBAAkB,CACrBuB,0BAA0B,CAAC;QAC1BzB,MAAM;QACN0B,cAAc,EAAEpB,YAAY,CAACgB,EAAE;QAC/BrB;MACF,CAAC,CAAC,CACDS,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACpB;IAEAP,qBAAqB,CAAC,WAAW,CAAC;IAClCI,eAAe,CAACoB,SAAS,CAAC;EAC5B;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../../src/types/service.ts"],"sourcesContent":["export type FunctionCall = {\n functionCallId: string;\n name: string;\n arguments: string;\n};\n\nexport type FunctionCallResult = {\n functionCallId: string;\n result: string;\n error?: string;\n};\n\nexport type LimitationType = 'MINUTES' | 'SECONDS' | 'TOKENS';\n\nexport interface Limitation {\n type?: LimitationType;\n limit?: number;\n}\n\nexport interface ConversationResult {\n url: string;\n id: string;\n limit?: number;\n}\n\nexport interface CreateConversationParams {\n chatId: string;\n namespace: string;\n chatConfig?: object;\n}\n\nexport interface EndConversationParams {\n chatId: string;\n conversationId: string;\n namespace: string;\n}\n\nexport interface ChatMessageAttachment {\n fileName?: string;\n url?: string;\n mimeType?: string;\n textFileContent?: string;\n}\n\nexport interface SendMessageParams {\n chatId: string;\n namespace: string;\n message: string;\n functionCallResults?: FunctionCallResult[];\n chatConfig?: object;\n attachments?: ChatMessageAttachment[];\n}\n\nexport interface ChatMessage {\n id: string;\n content: string;\n role: 'user' | 'assistant';\n createdAt?: string;\n attachments?: ChatMessageAttachment[];\n}\n\nexport interface QueryMessagesParams {\n chatId: string;\n namespace: string;\n limit?: number;\n cursor?: string;\n}\n\nexport interface QueryMessagesResult {\n messages: ChatMessage[];\n nextCursor?: string;\n}\n\nexport interface IPersonaChatService {\n createVoiceConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult>;\n createInteractiveConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult>;\n endInteractiveConversation(params: EndConversationParams): Promise<void>;\n sendChatMessage(\n params: SendMessageParams,\n ): Promise<{ functionCalls?: FunctionCall[]; messages?: ChatMessage[] }>;\n queryChatMessages(params: QueryMessagesParams): Promise<QueryMessagesResult>;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["../../../src/types/service.ts"],"sourcesContent":["export type FunctionCall = {\n functionCallId: string;\n name: string;\n arguments: string;\n};\n\nexport type FunctionCallResult = {\n functionCallId: string;\n result: string;\n error?: string;\n};\n\nexport type LimitationType = 'MINUTES' | 'SECONDS' | 'TOKENS';\n\nexport interface Limitation {\n type?: LimitationType;\n limit?: number;\n}\n\nexport interface ConversationResult {\n url: string;\n id: string;\n limit?: number;\n}\n\nexport interface CreateConversationParams {\n chatId: string;\n namespace: string;\n chatConfig?: object;\n /** Whether this is the visitor's first-ever conversation with the persona (drives the opening message). */\n firstConversation?: boolean;\n /** Title of the visitor's last meaningful conversation, for a returning-visitor greeting. */\n lastConversationTopic?: string;\n}\n\nexport interface EndConversationParams {\n chatId: string;\n conversationId: string;\n namespace: string;\n}\n\nexport interface ChatMessageAttachment {\n fileName?: string;\n url?: string;\n mimeType?: string;\n textFileContent?: string;\n}\n\nexport interface SendMessageParams {\n chatId: string;\n namespace: string;\n message: string;\n functionCallResults?: FunctionCallResult[];\n chatConfig?: object;\n attachments?: ChatMessageAttachment[];\n}\n\nexport interface ChatMessage {\n id: string;\n content: string;\n role: 'user' | 'assistant';\n createdAt?: string;\n attachments?: ChatMessageAttachment[];\n}\n\nexport interface QueryMessagesParams {\n chatId: string;\n namespace: string;\n limit?: number;\n cursor?: string;\n}\n\nexport interface QueryMessagesResult {\n messages: ChatMessage[];\n nextCursor?: string;\n}\n\nexport interface IPersonaChatService {\n createVoiceConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult>;\n createInteractiveConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult>;\n endInteractiveConversation(params: EndConversationParams): Promise<void>;\n sendChatMessage(\n params: SendMessageParams,\n ): Promise<{ functionCalls?: FunctionCall[]; messages?: ChatMessage[] }>;\n queryChatMessages(params: QueryMessagesParams): Promise<QueryMessagesResult>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -2,6 +2,10 @@ import { type ConversationType, type Conversation } from '../../conversation';
2
2
  export type UseCreateConversationOptions = {
3
3
  type: ConversationType;
4
4
  config?: object;
5
+ /** Whether this is the visitor's first-ever conversation with the persona (drives the opening message). */
6
+ firstConversation?: boolean;
7
+ /** Title of the visitor's last meaningful conversation, for a returning-visitor greeting. */
8
+ lastConversationTopic?: string;
5
9
  };
6
10
  export type UseCreateConversationResult = {
7
11
  data?: Conversation;
@@ -1 +1 @@
1
- {"version":3,"file":"useCreateConversation.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useCreateConversation/useCreateConversation.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAI5B,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B,CAAC;AAEF,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,4BAA4B,GACpC,2BAA2B,CAgG7B"}
1
+ {"version":3,"file":"useCreateConversation.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useCreateConversation/useCreateConversation.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAI5B,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2GAA2G;IAC3G,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,6FAA6F;IAC7F,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B,CAAC;AAEF,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,4BAA4B,GACpC,2BAA2B,CA2G7B"}
@@ -22,6 +22,10 @@ export interface CreateConversationParams {
22
22
  chatId: string;
23
23
  namespace: string;
24
24
  chatConfig?: object;
25
+ /** Whether this is the visitor's first-ever conversation with the persona (drives the opening message). */
26
+ firstConversation?: boolean;
27
+ /** Title of the visitor's last meaningful conversation, for a returning-visitor greeting. */
28
+ lastConversationTopic?: string;
25
29
  }
26
30
  export interface EndConversationParams {
27
31
  chatId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/types/service.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ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ACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,uBAAuB,CACrB,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/B,6BAA6B,CAC3B,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/B,0BAA0B,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,eAAe,CACb,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC;QAAE,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC,CAAC;IACzE,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAC9E"}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.0",
2
+ "version": "1.4.0",
3
3
  "name": "@wix/legends-platform-sdk",
4
4
  "license": "MIT",
5
5
  "author": {
@@ -103,5 +103,5 @@
103
103
  "wallaby": {
104
104
  "autoDetect": true
105
105
  },
106
- "falconPackageHash": "2912768126618e9a95930f9b3c4d70496f04a0b284513cbcb4c66fce"
106
+ "falconPackageHash": "cabb2775e691affa4bd87a3dd5a9a935b59550a079414055406ed357"
107
107
  }