@wix/legends-platform-sdk 1.35.0 → 1.36.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 +18 -1
- package/dist/cjs/components/LegendsPlatform/LegendsPlatform.js +10 -7
- package/dist/cjs/components/LegendsPlatform/LegendsPlatform.js.map +1 -1
- package/dist/cjs/components/LegendsPlatformCore/LegendsPlatformCore.js +73 -0
- package/dist/cjs/components/LegendsPlatformCore/LegendsPlatformCore.js.map +1 -0
- package/dist/cjs/components/LegendsPlatformCore/index.js +10 -0
- package/dist/cjs/components/LegendsPlatformCore/index.js.map +1 -0
- package/dist/cjs/sdk.js +7 -1
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/cjs/services/BearerPersonaChatService.js +187 -0
- package/dist/cjs/services/BearerPersonaChatService.js.map +1 -0
- package/dist/cjs/services/FetchPersonaChatService.js +10 -4
- package/dist/cjs/services/FetchPersonaChatService.js.map +1 -1
- package/dist/esm/components/LegendsPlatform/LegendsPlatform.js +5 -2
- package/dist/esm/components/LegendsPlatform/LegendsPlatform.js.map +1 -1
- package/dist/esm/components/LegendsPlatformCore/LegendsPlatformCore.js +40 -0
- package/dist/esm/components/LegendsPlatformCore/LegendsPlatformCore.js.map +1 -0
- package/dist/esm/components/LegendsPlatformCore/index.js +2 -0
- package/dist/esm/components/LegendsPlatformCore/index.js.map +1 -0
- package/dist/esm/sdk.js +2 -0
- package/dist/esm/sdk.js.map +1 -1
- package/dist/esm/services/BearerPersonaChatService.js +177 -0
- package/dist/esm/services/BearerPersonaChatService.js.map +1 -0
- package/dist/esm/services/FetchPersonaChatService.js +12 -3
- package/dist/esm/services/FetchPersonaChatService.js.map +1 -1
- package/dist/types/components/LegendsPlatform/LegendsPlatform.d.ts +3 -0
- package/dist/types/components/LegendsPlatform/LegendsPlatform.d.ts.map +1 -1
- package/dist/types/components/LegendsPlatformCore/LegendsPlatformCore.d.ts +23 -0
- package/dist/types/components/LegendsPlatformCore/LegendsPlatformCore.d.ts.map +1 -0
- package/dist/types/components/LegendsPlatformCore/index.d.ts +2 -0
- package/dist/types/components/LegendsPlatformCore/index.d.ts.map +1 -0
- package/dist/types/sdk.d.ts +4 -0
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/services/BearerPersonaChatService.d.ts +37 -0
- package/dist/types/services/BearerPersonaChatService.d.ts.map +1 -0
- package/dist/types/services/FetchPersonaChatService.d.ts +11 -1
- package/dist/types/services/FetchPersonaChatService.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -15,6 +15,7 @@ export function LegendsPlatform(props) {
|
|
|
15
15
|
_props$tools = props.tools,
|
|
16
16
|
tools = _props$tools === void 0 ? {} : _props$tools,
|
|
17
17
|
apiKey = props.apiKey,
|
|
18
|
+
baseUrl = props.baseUrl,
|
|
18
19
|
personaChatService = props.personaChatService;
|
|
19
20
|
const store = useMemo(() => props.store || createStore(), [props.store]);
|
|
20
21
|
const queryClient = useMemo(() => props.queryClient || new QueryClient({
|
|
@@ -30,10 +31,12 @@ export function LegendsPlatform(props) {
|
|
|
30
31
|
return personaChatService;
|
|
31
32
|
}
|
|
32
33
|
if (apiKey) {
|
|
33
|
-
return new FetchPersonaChatService(apiKey
|
|
34
|
+
return new FetchPersonaChatService(apiKey, {
|
|
35
|
+
baseUrl
|
|
36
|
+
});
|
|
34
37
|
}
|
|
35
38
|
return undefined;
|
|
36
|
-
}, [personaChatService, apiKey]);
|
|
39
|
+
}, [personaChatService, apiKey, baseUrl]);
|
|
37
40
|
const telemetryRef = useRef(props.startupTelemetry);
|
|
38
41
|
telemetryRef.current = props.startupTelemetry;
|
|
39
42
|
const telemetryEnabled = (_props$startupTelemet = props.startupTelemetry) == null ? void 0 : _props$startupTelemet.enabled;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useMemo","useRef","Provider","createStore","LiveKitRoom","QueryClientProvider","QueryClient","BusProvider","FetchPersonaChatService","SdkConsumerContext","StartupTelemetrySession","LegendsPlatform","props","_props$startupTelemet","_props$startupTelemet2","_props$startupTelemet3","chatId","namespace","children","className","_props$tools","tools","apiKey","personaChatService","store","queryClient","defaultOptions","queries","refetchOnMount","refetchOnWindowFocus","resolvedService","undefined","telemetryRef","startupTelemetry","current","telemetryEnabled","enabled","intentId","intent","id","attemptId","attempt","startupTelemetrySession","config","report","event","_telemetryRef$current","consumer","createElement","value","client","serverUrl","token"],"sources":["../../../../src/components/LegendsPlatform/LegendsPlatform.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { Provider, createStore } from 'jotai';\nimport { type Store } from 'jotai/vanilla/store';\nimport { LiveKitRoom } from '@livekit/components-react';\nimport { QueryClientProvider, QueryClient } from '@tanstack/react-query';\nimport { Provider as BusProvider } from 'react-bus';\n\nimport type { ToolsRegistry } from '../../hooks/useTools/model/types';\nimport type { IPersonaChatService } from '../../types/service';\nimport { FetchPersonaChatService } from '../../services/FetchPersonaChatService';\nimport { SdkConsumerContext } from '../../sdk-consumer';\nimport {\n StartupTelemetrySession,\n type StartupTelemetryOptions,\n} from '../../startup-telemetry/attempt';\n\nexport type LegendsPlatformProps = {\n startupTelemetry?: StartupTelemetryOptions;\n chatId: string;\n namespace: string;\n apiKey?: string;\n personaChatService?: IPersonaChatService;\n store?: Store;\n tools?: ToolsRegistry;\n children: React.ReactNode;\n queryClient?: QueryClient;\n className?: string;\n};\n\nexport function LegendsPlatform(props: LegendsPlatformProps) {\n const {\n chatId,\n namespace,\n children,\n className,\n tools = {},\n apiKey,\n personaChatService,\n } = props;\n\n const store = useMemo(() => props.store || createStore(), [props.store]);\n\n const queryClient = useMemo(\n () =>\n props.queryClient ||\n new QueryClient({\n defaultOptions: {\n queries: { refetchOnMount: false, refetchOnWindowFocus: false },\n },\n }),\n [props.queryClient],\n );\n\n const resolvedService = useMemo<IPersonaChatService | undefined>(() => {\n if (personaChatService) {\n return personaChatService;\n }\n if (apiKey) {\n return new FetchPersonaChatService(apiKey);\n }\n return undefined;\n }, [personaChatService, apiKey]);\n\n const telemetryRef = useRef(props.startupTelemetry);\n telemetryRef.current = props.startupTelemetry;\n const telemetryEnabled = props.startupTelemetry?.enabled;\n const intentId = props.startupTelemetry?.intent?.id;\n const attemptId = props.startupTelemetry?.attempt?.id;\n const startupTelemetrySession = useMemo(() => {\n const config = telemetryRef.current;\n if (!telemetryEnabled || !config) {\n return undefined;\n }\n return new StartupTelemetrySession(\n {\n ...config,\n report: (event) => {\n if (telemetryRef.current?.enabled) {\n return telemetryRef.current.report?.(event);\n }\n return undefined;\n },\n },\n chatId,\n );\n // A new intent/attempt changes ownership; report callbacks stay live via the ref.\n }, [chatId, telemetryEnabled, intentId, attemptId]);\n\n const consumer = useMemo(\n () => ({\n chatId,\n namespace,\n tools,\n personaChatService: resolvedService,\n startupTelemetrySession,\n }),\n [chatId, namespace, tools, resolvedService, startupTelemetrySession],\n );\n\n return (\n <SdkConsumerContext.Provider value={consumer}>\n <QueryClientProvider client={queryClient}>\n <Provider store={store}>\n <BusProvider>\n <LiveKitRoom\n className={className}\n serverUrl={undefined}\n token={undefined}\n >\n {children}\n </LiveKitRoom>\n </BusProvider>\n </Provider>\n </QueryClientProvider>\n </SdkConsumerContext.Provider>\n );\n}\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAC9C,SAASC,QAAQ,EAAEC,WAAW,QAAQ,OAAO;AAE7C,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SAASC,mBAAmB,EAAEC,WAAW,QAAQ,uBAAuB;AACxE,SAASJ,QAAQ,IAAIK,WAAW,QAAQ,WAAW;AAInD,SAASC,uBAAuB,QAAQ,wCAAwC;AAChF,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SACEC,uBAAuB,QAElB,iCAAiC;
|
|
1
|
+
{"version":3,"names":["React","useMemo","useRef","Provider","createStore","LiveKitRoom","QueryClientProvider","QueryClient","BusProvider","FetchPersonaChatService","SdkConsumerContext","StartupTelemetrySession","LegendsPlatform","props","_props$startupTelemet","_props$startupTelemet2","_props$startupTelemet3","chatId","namespace","children","className","_props$tools","tools","apiKey","baseUrl","personaChatService","store","queryClient","defaultOptions","queries","refetchOnMount","refetchOnWindowFocus","resolvedService","undefined","telemetryRef","startupTelemetry","current","telemetryEnabled","enabled","intentId","intent","id","attemptId","attempt","startupTelemetrySession","config","report","event","_telemetryRef$current","consumer","createElement","value","client","serverUrl","token"],"sources":["../../../../src/components/LegendsPlatform/LegendsPlatform.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { Provider, createStore } from 'jotai';\nimport { type Store } from 'jotai/vanilla/store';\nimport { LiveKitRoom } from '@livekit/components-react';\nimport { QueryClientProvider, QueryClient } from '@tanstack/react-query';\nimport { Provider as BusProvider } from 'react-bus';\n\nimport type { ToolsRegistry } from '../../hooks/useTools/model/types';\nimport type { IPersonaChatService } from '../../types/service';\nimport { FetchPersonaChatService } from '../../services/FetchPersonaChatService';\nimport { SdkConsumerContext } from '../../sdk-consumer';\nimport {\n StartupTelemetrySession,\n type StartupTelemetryOptions,\n} from '../../startup-telemetry/attempt';\n\nexport type LegendsPlatformProps = {\n startupTelemetry?: StartupTelemetryOptions;\n chatId: string;\n namespace: string;\n /** Server-side only: a namespace API key never reaches a browser (use personaChatService with a BearerPersonaChatService there). */\n apiKey?: string;\n /** API host for the apiKey service. Defaults to https://www.wixapis.com. */\n baseUrl?: string;\n personaChatService?: IPersonaChatService;\n store?: Store;\n tools?: ToolsRegistry;\n children: React.ReactNode;\n queryClient?: QueryClient;\n className?: string;\n};\n\nexport function LegendsPlatform(props: LegendsPlatformProps) {\n const {\n chatId,\n namespace,\n children,\n className,\n tools = {},\n apiKey,\n baseUrl,\n personaChatService,\n } = props;\n\n const store = useMemo(() => props.store || createStore(), [props.store]);\n\n const queryClient = useMemo(\n () =>\n props.queryClient ||\n new QueryClient({\n defaultOptions: {\n queries: { refetchOnMount: false, refetchOnWindowFocus: false },\n },\n }),\n [props.queryClient],\n );\n\n const resolvedService = useMemo<IPersonaChatService | undefined>(() => {\n if (personaChatService) {\n return personaChatService;\n }\n if (apiKey) {\n return new FetchPersonaChatService(apiKey, { baseUrl });\n }\n return undefined;\n }, [personaChatService, apiKey, baseUrl]);\n\n const telemetryRef = useRef(props.startupTelemetry);\n telemetryRef.current = props.startupTelemetry;\n const telemetryEnabled = props.startupTelemetry?.enabled;\n const intentId = props.startupTelemetry?.intent?.id;\n const attemptId = props.startupTelemetry?.attempt?.id;\n const startupTelemetrySession = useMemo(() => {\n const config = telemetryRef.current;\n if (!telemetryEnabled || !config) {\n return undefined;\n }\n return new StartupTelemetrySession(\n {\n ...config,\n report: (event) => {\n if (telemetryRef.current?.enabled) {\n return telemetryRef.current.report?.(event);\n }\n return undefined;\n },\n },\n chatId,\n );\n // A new intent/attempt changes ownership; report callbacks stay live via the ref.\n }, [chatId, telemetryEnabled, intentId, attemptId]);\n\n const consumer = useMemo(\n () => ({\n chatId,\n namespace,\n tools,\n personaChatService: resolvedService,\n startupTelemetrySession,\n }),\n [chatId, namespace, tools, resolvedService, startupTelemetrySession],\n );\n\n return (\n <SdkConsumerContext.Provider value={consumer}>\n <QueryClientProvider client={queryClient}>\n <Provider store={store}>\n <BusProvider>\n <LiveKitRoom\n className={className}\n serverUrl={undefined}\n token={undefined}\n >\n {children}\n </LiveKitRoom>\n </BusProvider>\n </Provider>\n </QueryClientProvider>\n </SdkConsumerContext.Provider>\n );\n}\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAC9C,SAASC,QAAQ,EAAEC,WAAW,QAAQ,OAAO;AAE7C,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SAASC,mBAAmB,EAAEC,WAAW,QAAQ,uBAAuB;AACxE,SAASJ,QAAQ,IAAIK,WAAW,QAAQ,WAAW;AAInD,SAASC,uBAAuB,QAAQ,wCAAwC;AAChF,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SACE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AAEI,KAAK,EAAEU,eAAe,EAAEY,uBAAuB,CACrE,CAAC;EAED,oBACE5C,KAAA,CAAAkD,aAAA,CAACxC,kBAAkB,CAACP,QAAQ;IAACgD,KAAK,EAAEF;EAAS,gBAC3CjD,KAAA,CAAAkD,aAAA,CAAC5C,mBAAmB;IAAC8C,MAAM,EAAEzB;EAAY,gBACvC3B,KAAA,CAAAkD,aAAA,CAAC/C,QAAQ;IAACuB,KAAK,EAAEA;EAAM,gBACrB1B,KAAA,CAAAkD,aAAA,CAAC1C,WAAW,qBACVR,KAAA,CAAAkD,aAAA,CAAC7C,WAAW;IACVe,SAAS,EAAEA,SAAU;IACrBiC,SAAS,EAAEpB,SAAU;IACrBqB,KAAK,EAAErB;EAAU,GAEhBd,QACU,CACF,CACL,CACS,CACM,CAAC;AAElC","ignoreList":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { Provider, createStore } from 'jotai';
|
|
3
|
+
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { Provider as BusProvider } from 'react-bus';
|
|
5
|
+
import { SdkConsumerContext } from '../../sdk-consumer';
|
|
6
|
+
/**
|
|
7
|
+
* The text-chat providers without LiveKit, from the main entry: for a page that
|
|
8
|
+
* loads LiveKit only when a call starts (`@wix/legends-platform-sdk/livekit/sdk`'s
|
|
9
|
+
* LegendsPlatform then wraps the call, with the same store and query client).
|
|
10
|
+
*/
|
|
11
|
+
export function LegendsPlatformCore(props) {
|
|
12
|
+
const chatId = props.chatId,
|
|
13
|
+
namespace = props.namespace,
|
|
14
|
+
personaChatService = props.personaChatService,
|
|
15
|
+
tools = props.tools,
|
|
16
|
+
children = props.children;
|
|
17
|
+
const store = useMemo(() => props.store || createStore(), [props.store]);
|
|
18
|
+
const queryClient = useMemo(() => props.queryClient || new QueryClient({
|
|
19
|
+
defaultOptions: {
|
|
20
|
+
queries: {
|
|
21
|
+
refetchOnMount: false,
|
|
22
|
+
refetchOnWindowFocus: false
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}), [props.queryClient]);
|
|
26
|
+
const consumer = useMemo(() => ({
|
|
27
|
+
chatId,
|
|
28
|
+
namespace,
|
|
29
|
+
tools: tools ?? {},
|
|
30
|
+
personaChatService
|
|
31
|
+
}), [chatId, namespace, tools, personaChatService]);
|
|
32
|
+
return /*#__PURE__*/React.createElement(SdkConsumerContext.Provider, {
|
|
33
|
+
value: consumer
|
|
34
|
+
}, /*#__PURE__*/React.createElement(QueryClientProvider, {
|
|
35
|
+
client: queryClient
|
|
36
|
+
}, /*#__PURE__*/React.createElement(Provider, {
|
|
37
|
+
store: store
|
|
38
|
+
}, /*#__PURE__*/React.createElement(BusProvider, null, children))));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=LegendsPlatformCore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useMemo","Provider","createStore","QueryClientProvider","QueryClient","BusProvider","SdkConsumerContext","LegendsPlatformCore","props","chatId","namespace","personaChatService","tools","children","store","queryClient","defaultOptions","queries","refetchOnMount","refetchOnWindowFocus","consumer","createElement","value","client"],"sources":["../../../../src/components/LegendsPlatformCore/LegendsPlatformCore.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { Provider, createStore } from 'jotai';\nimport { type Store } from 'jotai/vanilla/store';\nimport { QueryClientProvider, QueryClient } from '@tanstack/react-query';\nimport { Provider as BusProvider } from 'react-bus';\n\nimport type { ToolsRegistry } from '../../hooks/useTools/model/types';\nimport type { IPersonaChatService } from '../../types/service';\nimport { SdkConsumerContext } from '../../sdk-consumer';\n\nexport type LegendsPlatformCoreProps = {\n chatId: string;\n namespace: string;\n /** Required: in a browser, a BearerPersonaChatService with the caller's own token. */\n personaChatService: IPersonaChatService;\n tools?: ToolsRegistry;\n /** Pass the same store and query client to LegendsPlatform when a call starts, to keep the chat state. */\n store?: Store;\n queryClient?: QueryClient;\n children: React.ReactNode;\n};\n\n/**\n * The text-chat providers without LiveKit, from the main entry: for a page that\n * loads LiveKit only when a call starts (`@wix/legends-platform-sdk/livekit/sdk`'s\n * LegendsPlatform then wraps the call, with the same store and query client).\n */\nexport function LegendsPlatformCore(props: LegendsPlatformCoreProps) {\n const { chatId, namespace, personaChatService, tools, children } = props;\n\n const store = useMemo(() => props.store || createStore(), [props.store]);\n const queryClient = useMemo(\n () =>\n props.queryClient ||\n new QueryClient({\n defaultOptions: {\n queries: { refetchOnMount: false, refetchOnWindowFocus: false },\n },\n }),\n [props.queryClient],\n );\n\n const consumer = useMemo(\n () => ({ chatId, namespace, tools: tools ?? {}, personaChatService }),\n [chatId, namespace, tools, personaChatService],\n );\n\n return (\n <SdkConsumerContext.Provider value={consumer}>\n <QueryClientProvider client={queryClient}>\n <Provider store={store}>\n <BusProvider>{children}</BusProvider>\n </Provider>\n </QueryClientProvider>\n </SdkConsumerContext.Provider>\n );\n}\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,QAAQ,EAAEC,WAAW,QAAQ,OAAO;AAE7C,SAASC,mBAAmB,EAAEC,WAAW,QAAQ,uBAAuB;AACxE,SAASH,QAAQ,IAAII,WAAW,QAAQ,WAAW;AAInD,SAASC,kBAAkB,QAAQ,oBAAoB;AAcvD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAACC,KAA+B,EAAE;EACnE,MAAQC,MAAM,GAAqDD,KAAK,CAAhEC,MAAM;IAAEC,SAAS,GAA0CF,KAAK,CAAxDE,SAAS;IAAEC,kBAAkB,GAAsBH,KAAK,CAA7CG,kBAAkB;IAAEC,KAAK,GAAeJ,KAAK,CAAzBI,KAAK;IAAEC,QAAQ,GAAKL,KAAK,CAAlBK,QAAQ;EAE9D,MAAMC,KAAK,GAAGd,OAAO,CAAC,MAAMQ,KAAK,CAACM,KAAK,IAAIZ,WAAW,CAAC,CAAC,EAAE,CAACM,KAAK,CAACM,KAAK,CAAC,CAAC;EACxE,MAAMC,WAAW,GAAGf,OAAO,CACzB,MACEQ,KAAK,CAACO,WAAW,IACjB,IAAIX,WAAW,CAAC;IACdY,cAAc,EAAE;MACdC,OAAO,EAAE;QAAEC,cAAc,EAAE,KAAK;QAAEC,oBAAoB,EAAE;MAAM;IAChE;EACF,CAAC,CAAC,EACJ,CAACX,KAAK,CAACO,WAAW,CACpB,CAAC;EAED,MAAMK,QAAQ,GAAGpB,OAAO,CACtB,OAAO;IAAES,MAAM;IAAEC,SAAS;IAAEE,KAAK,EAAEA,KAAK,IAAI,CAAC,CAAC;IAAED;EAAmB,CAAC,CAAC,EACrE,CAACF,MAAM,EAAEC,SAAS,EAAEE,KAAK,EAAED,kBAAkB,CAC/C,CAAC;EAED,oBACEZ,KAAA,CAAAsB,aAAA,CAACf,kBAAkB,CAACL,QAAQ;IAACqB,KAAK,EAAEF;EAAS,gBAC3CrB,KAAA,CAAAsB,aAAA,CAAClB,mBAAmB;IAACoB,MAAM,EAAER;EAAY,gBACvChB,KAAA,CAAAsB,aAAA,CAACpB,QAAQ;IAACa,KAAK,EAAEA;EAAM,gBACrBf,KAAA,CAAAsB,aAAA,CAAChB,WAAW,QAAEQ,QAAsB,CAC5B,CACS,CACM,CAAC;AAElC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../../src/components/LegendsPlatformCore/index.ts"],"sourcesContent":["export * from './LegendsPlatformCore';\n"],"mappings":"AAAA,cAAc,uBAAuB","ignoreList":[]}
|
package/dist/esm/sdk.js
CHANGED
|
@@ -16,5 +16,7 @@ export * from './hooks/usePictureInPicture';
|
|
|
16
16
|
export * from './hooks/useMediaPermissions';
|
|
17
17
|
export * from './hooks/useTools';
|
|
18
18
|
export * from './conversation/types';
|
|
19
|
+
export { BearerPersonaChatService } from './services/BearerPersonaChatService';
|
|
20
|
+
export { LegendsPlatformCore } from './components/LegendsPlatformCore';
|
|
19
21
|
export { createStartupIntent, StartupAttempt } from './startup-telemetry/attempt';
|
|
20
22
|
//# sourceMappingURL=sdk.js.map
|
package/dist/esm/sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createStartupIntent","StartupAttempt"],"sources":["../../src/sdk.ts"],"sourcesContent":["export * from './types';\n\nexport * from './hooks/useTextChat';\nexport * from './hooks/useTranscriptions';\nexport * from './hooks/useConversationStatus';\nexport * from './hooks/useMicrophone';\nexport * from './hooks/useSpeaker';\nexport * from './hooks/useCamera';\nexport * from './hooks/useMediaRecorder';\nexport * from './hooks/useConversationTimer';\nexport * from './hooks/useConversationEvents';\nexport * from './hooks/useUserActivity';\nexport * from './hooks/useAudio';\nexport * from './hooks/useConnectionState';\nexport * from './hooks/useActivityState';\nexport * from './hooks/usePictureInPicture';\nexport * from './hooks/useMediaPermissions';\nexport * from './hooks/useTools';\n\nexport * from './conversation/types';\n\nexport {\n createStartupIntent,\n StartupAttempt,\n} from './startup-telemetry/attempt';\nexport type {\n StartupIntent,\n StartupReport,\n StartupTelemetryOptions,\n} from './startup-telemetry/attempt';\n"],"mappings":"AAAA,cAAc,SAAS;AAEvB,cAAc,qBAAqB;AACnC,cAAc,2BAA2B;AACzC,cAAc,+BAA+B;AAC7C,cAAc,uBAAuB;AACrC,cAAc,oBAAoB;AAClC,cAAc,mBAAmB;AACjC,cAAc,0BAA0B;AACxC,cAAc,8BAA8B;AAC5C,cAAc,+BAA+B;AAC7C,cAAc,yBAAyB;AACvC,cAAc,kBAAkB;AAChC,cAAc,4BAA4B;AAC1C,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,6BAA6B;AAC3C,cAAc,kBAAkB;AAEhC,cAAc,sBAAsB;AAEpC,
|
|
1
|
+
{"version":3,"names":["BearerPersonaChatService","LegendsPlatformCore","createStartupIntent","StartupAttempt"],"sources":["../../src/sdk.ts"],"sourcesContent":["export * from './types';\n\nexport * from './hooks/useTextChat';\nexport * from './hooks/useTranscriptions';\nexport * from './hooks/useConversationStatus';\nexport * from './hooks/useMicrophone';\nexport * from './hooks/useSpeaker';\nexport * from './hooks/useCamera';\nexport * from './hooks/useMediaRecorder';\nexport * from './hooks/useConversationTimer';\nexport * from './hooks/useConversationEvents';\nexport * from './hooks/useUserActivity';\nexport * from './hooks/useAudio';\nexport * from './hooks/useConnectionState';\nexport * from './hooks/useActivityState';\nexport * from './hooks/usePictureInPicture';\nexport * from './hooks/useMediaPermissions';\nexport * from './hooks/useTools';\n\nexport * from './conversation/types';\n\nexport { BearerPersonaChatService } from './services/BearerPersonaChatService';\nexport type { BearerPersonaChatServiceOptions } from './services/BearerPersonaChatService';\nexport { LegendsPlatformCore } from './components/LegendsPlatformCore';\nexport type { LegendsPlatformCoreProps } from './components/LegendsPlatformCore';\n\nexport {\n createStartupIntent,\n StartupAttempt,\n} from './startup-telemetry/attempt';\nexport type {\n StartupIntent,\n StartupReport,\n StartupTelemetryOptions,\n} from './startup-telemetry/attempt';\n"],"mappings":"AAAA,cAAc,SAAS;AAEvB,cAAc,qBAAqB;AACnC,cAAc,2BAA2B;AACzC,cAAc,+BAA+B;AAC7C,cAAc,uBAAuB;AACrC,cAAc,oBAAoB;AAClC,cAAc,mBAAmB;AACjC,cAAc,0BAA0B;AACxC,cAAc,8BAA8B;AAC5C,cAAc,+BAA+B;AAC7C,cAAc,yBAAyB;AACvC,cAAc,kBAAkB;AAChC,cAAc,4BAA4B;AAC1C,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,6BAA6B;AAC3C,cAAc,kBAAkB;AAEhC,cAAc,sBAAsB;AAEpC,SAASA,wBAAwB,QAAQ,qCAAqC;AAE9E,SAASC,mBAAmB,QAAQ,kCAAkC;AAGtE,SACEC,mBAAmB,EACnBC,cAAc,QACT,6BAA6B","ignoreList":[]}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import { HttpError } from '../types/http';
|
|
3
|
+
import { DEFAULT_BASE_URL } from './FetchPersonaChatService';
|
|
4
|
+
const PERSONA_CHAT = '/_api/persona-chat-service/v1';
|
|
5
|
+
function resolveLimitMs(limitation) {
|
|
6
|
+
if (!limitation) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
switch (limitation.type) {
|
|
10
|
+
case 'MINUTES':
|
|
11
|
+
return (limitation.limit ?? 0) * 60 * 1000;
|
|
12
|
+
case 'SECONDS':
|
|
13
|
+
return (limitation.limit ?? 0) * 1000;
|
|
14
|
+
case 'TOKENS':
|
|
15
|
+
default:
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function parseJson(text) {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(text);
|
|
22
|
+
} catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function toMessage(m) {
|
|
27
|
+
return {
|
|
28
|
+
id: m.id ?? '',
|
|
29
|
+
content: m.content ?? '',
|
|
30
|
+
role: m.role,
|
|
31
|
+
createdAt: m.createdAt ?? m.createdDate,
|
|
32
|
+
...(m.attachments ? {
|
|
33
|
+
attachments: m.attachments
|
|
34
|
+
} : {})
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The persona-chat service for a browser: authenticated with the caller's own
|
|
40
|
+
* bearer token (never a namespace API key), on the same REST paths the
|
|
41
|
+
* Legend's own page uses for a visitor.
|
|
42
|
+
*/
|
|
43
|
+
export class BearerPersonaChatService {
|
|
44
|
+
constructor(options) {
|
|
45
|
+
this.options = options;
|
|
46
|
+
_defineProperty(this, "baseUrl", void 0);
|
|
47
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
48
|
+
}
|
|
49
|
+
async request(method, path, body, retried) {
|
|
50
|
+
if (retried === void 0) {
|
|
51
|
+
retried = false;
|
|
52
|
+
}
|
|
53
|
+
const token = await this.options.getAccessToken();
|
|
54
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
55
|
+
method,
|
|
56
|
+
headers: {
|
|
57
|
+
...(body === undefined ? {} : {
|
|
58
|
+
'Content-Type': 'application/json'
|
|
59
|
+
}),
|
|
60
|
+
Authorization: token
|
|
61
|
+
},
|
|
62
|
+
...(body === undefined ? {} : {
|
|
63
|
+
body: JSON.stringify(body)
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
if (response.status === 401 && !retried && this.options.onUnauthorized && (await this.options.onUnauthorized())) {
|
|
67
|
+
return this.request(method, path, body, true);
|
|
68
|
+
}
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
const text = await response.text().catch(() => '');
|
|
71
|
+
throw new HttpError(response.status, `Request failed: ${response.status} ${text}`, parseJson(text));
|
|
72
|
+
}
|
|
73
|
+
return response.json();
|
|
74
|
+
}
|
|
75
|
+
async createConversation(kind, params) {
|
|
76
|
+
const chatId = params.chatId,
|
|
77
|
+
namespace = params.namespace,
|
|
78
|
+
chatConfig = params.chatConfig,
|
|
79
|
+
firstConversation = params.firstConversation,
|
|
80
|
+
lastConversationTopic = params.lastConversationTopic,
|
|
81
|
+
conversationLanguage = params.conversationLanguage;
|
|
82
|
+
const data = await this.request('POST', `${PERSONA_CHAT}/chats/${encodeURIComponent(chatId)}/${kind}`, {
|
|
83
|
+
namespace,
|
|
84
|
+
...(chatConfig ? {
|
|
85
|
+
chatConfig
|
|
86
|
+
} : {}),
|
|
87
|
+
...(firstConversation !== undefined ? {
|
|
88
|
+
firstConversation
|
|
89
|
+
} : {}),
|
|
90
|
+
...(lastConversationTopic ? {
|
|
91
|
+
lastConversationTopic
|
|
92
|
+
} : {}),
|
|
93
|
+
...(conversationLanguage !== undefined ? {
|
|
94
|
+
conversationLanguage
|
|
95
|
+
} : {})
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
url: data.conversationUrl ?? '',
|
|
99
|
+
id: data.interactiveConversationId ?? '',
|
|
100
|
+
limit: resolveLimitMs(data.limitation)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
createVoiceConversation(params) {
|
|
104
|
+
return this.createConversation('create-voice-conversation', params);
|
|
105
|
+
}
|
|
106
|
+
createInteractiveConversation(params) {
|
|
107
|
+
return this.createConversation('create-interactive-conversation', params);
|
|
108
|
+
}
|
|
109
|
+
async endInteractiveConversation(params) {
|
|
110
|
+
const chatId = params.chatId,
|
|
111
|
+
conversationId = params.conversationId,
|
|
112
|
+
namespace = params.namespace;
|
|
113
|
+
await this.request('POST', `${PERSONA_CHAT}/chats/${encodeURIComponent(chatId)}/end-interactive-conversation`, {
|
|
114
|
+
namespace,
|
|
115
|
+
interactiveConversationId: conversationId
|
|
116
|
+
}).catch(() => {
|
|
117
|
+
// best-effort
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async sendChatMessage(params) {
|
|
121
|
+
const chatId = params.chatId,
|
|
122
|
+
namespace = params.namespace,
|
|
123
|
+
message = params.message,
|
|
124
|
+
functionCallResults = params.functionCallResults,
|
|
125
|
+
chatConfig = params.chatConfig,
|
|
126
|
+
attachments = params.attachments,
|
|
127
|
+
metadata = params.metadata,
|
|
128
|
+
conversationLanguage = params.conversationLanguage;
|
|
129
|
+
const data = await this.request('POST', `${PERSONA_CHAT}/chat/messages`, {
|
|
130
|
+
chatId,
|
|
131
|
+
namespace,
|
|
132
|
+
...(message ? {
|
|
133
|
+
message
|
|
134
|
+
} : {}),
|
|
135
|
+
...(functionCallResults ? {
|
|
136
|
+
functionCallResults
|
|
137
|
+
} : {}),
|
|
138
|
+
...(chatConfig ? {
|
|
139
|
+
chatConfig
|
|
140
|
+
} : {}),
|
|
141
|
+
...(attachments ? {
|
|
142
|
+
attachments
|
|
143
|
+
} : {}),
|
|
144
|
+
...(metadata ? {
|
|
145
|
+
metadata
|
|
146
|
+
} : {}),
|
|
147
|
+
...(conversationLanguage !== undefined ? {
|
|
148
|
+
conversationLanguage
|
|
149
|
+
} : {})
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
functionCalls: data.functionCalls,
|
|
153
|
+
messages: (data.messages ?? []).map(toMessage)
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async queryChatMessages(params) {
|
|
157
|
+
var _data$pagingMetadata;
|
|
158
|
+
const chatId = params.chatId,
|
|
159
|
+
namespace = params.namespace,
|
|
160
|
+
_params$limit = params.limit,
|
|
161
|
+
limit = _params$limit === void 0 ? 100 : _params$limit,
|
|
162
|
+
cursor = params.cursor;
|
|
163
|
+
const query = new URLSearchParams({
|
|
164
|
+
namespace,
|
|
165
|
+
'query.cursorPaging.limit': String(limit),
|
|
166
|
+
...(cursor ? {
|
|
167
|
+
'query.cursorPaging.cursor': cursor
|
|
168
|
+
} : {})
|
|
169
|
+
});
|
|
170
|
+
const data = await this.request('GET', `${PERSONA_CHAT}/chats/${encodeURIComponent(chatId)}/messages?${query}`);
|
|
171
|
+
return {
|
|
172
|
+
messages: (data.chatMessages ?? []).map(toMessage),
|
|
173
|
+
nextCursor: (_data$pagingMetadata = data.pagingMetadata) == null || (_data$pagingMetadata = _data$pagingMetadata.cursors) == null ? void 0 : _data$pagingMetadata.next
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=BearerPersonaChatService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["HttpError","DEFAULT_BASE_URL","PERSONA_CHAT","resolveLimitMs","limitation","undefined","type","limit","parseJson","text","JSON","parse","toMessage","m","id","content","role","createdAt","createdDate","attachments","BearerPersonaChatService","constructor","options","_defineProperty","baseUrl","replace","request","method","path","body","retried","token","getAccessToken","response","fetch","headers","Authorization","stringify","status","onUnauthorized","ok","catch","json","createConversation","kind","params","chatId","namespace","chatConfig","firstConversation","lastConversationTopic","conversationLanguage","data","encodeURIComponent","url","conversationUrl","interactiveConversationId","createVoiceConversation","createInteractiveConversation","endInteractiveConversation","conversationId","sendChatMessage","message","functionCallResults","metadata","functionCalls","messages","map","queryChatMessages","_data$pagingMetadata","_params$limit","cursor","query","URLSearchParams","String","chatMessages","nextCursor","pagingMetadata","cursors","next"],"sources":["../../../src/services/BearerPersonaChatService.ts"],"sourcesContent":["import { HttpError } from '../types/http';\nimport type {\n IPersonaChatService,\n CreateConversationParams,\n ConversationResult,\n EndConversationParams,\n SendMessageParams,\n QueryMessagesParams,\n QueryMessagesResult,\n ChatFunctionCall,\n ChatMessage,\n Limitation,\n} from '../types';\nimport { DEFAULT_BASE_URL } from './FetchPersonaChatService';\n\nexport interface BearerPersonaChatServiceOptions {\n /** API host. Defaults to https://www.wixapis.com. */\n baseUrl?: string;\n /**\n * The caller's own access token, e.g. a visitor token minted by the Legend's\n * sign-in app. Sent as the Authorization header, the way Wix's headless\n * clients send it. Called for every request, so a refreshed token is used.\n */\n getAccessToken: () => string | Promise<string>;\n /**\n * Called once when a request answers 401. Refresh the token and resolve true\n * to retry the request with the new token; resolve false to fail it.\n */\n onUnauthorized?: () => Promise<boolean>;\n}\n\nconst PERSONA_CHAT = '/_api/persona-chat-service/v1';\n\nfunction resolveLimitMs(limitation?: Limitation): number | undefined {\n if (!limitation) {\n return undefined;\n }\n switch (limitation.type) {\n case 'MINUTES':\n return (limitation.limit ?? 0) * 60 * 1000;\n case 'SECONDS':\n return (limitation.limit ?? 0) * 1000;\n case 'TOKENS':\n default:\n return 0;\n }\n}\n\nfunction parseJson(text: string): unknown {\n try {\n return JSON.parse(text);\n } catch {\n return undefined;\n }\n}\n\ntype RawMessage = {\n id?: string;\n content?: string;\n role?: string;\n createdAt?: string;\n createdDate?: string;\n attachments?: ChatMessage['attachments'];\n};\n\nfunction toMessage(m: RawMessage): ChatMessage {\n return {\n id: m.id ?? '',\n content: m.content ?? '',\n role: m.role as 'USER' | 'ASSISTANT',\n createdAt: m.createdAt ?? m.createdDate,\n ...(m.attachments ? { attachments: m.attachments } : {}),\n };\n}\n\n/**\n * The persona-chat service for a browser: authenticated with the caller's own\n * bearer token (never a namespace API key), on the same REST paths the\n * Legend's own page uses for a visitor.\n */\nexport class BearerPersonaChatService implements IPersonaChatService {\n private readonly baseUrl: string;\n\n constructor(private readonly options: BearerPersonaChatServiceOptions) {\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, '');\n }\n\n private async request<T>(\n method: 'GET' | 'POST',\n path: string,\n body?: unknown,\n retried = false,\n ): Promise<T> {\n const token = await this.options.getAccessToken();\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n ...(body === undefined ? {} : { 'Content-Type': 'application/json' }),\n Authorization: token,\n },\n ...(body === undefined ? {} : { body: JSON.stringify(body) }),\n });\n\n if (\n response.status === 401 &&\n !retried &&\n this.options.onUnauthorized &&\n (await this.options.onUnauthorized())\n ) {\n return this.request<T>(method, path, body, true);\n }\n\n if (!response.ok) {\n const text = await response.text().catch(() => '');\n throw new HttpError(\n response.status,\n `Request failed: ${response.status} ${text}`,\n parseJson(text),\n );\n }\n\n return response.json() as Promise<T>;\n }\n\n private async createConversation(\n kind: 'create-voice-conversation' | 'create-interactive-conversation',\n params: CreateConversationParams,\n ): Promise<ConversationResult> {\n const {\n chatId,\n namespace,\n chatConfig,\n firstConversation,\n lastConversationTopic,\n conversationLanguage,\n } = params;\n const data = await this.request<{\n conversationUrl?: string;\n interactiveConversationId?: string;\n limitation?: Limitation;\n }>('POST', `${PERSONA_CHAT}/chats/${encodeURIComponent(chatId)}/${kind}`, {\n namespace,\n ...(chatConfig ? { chatConfig } : {}),\n ...(firstConversation !== undefined ? { firstConversation } : {}),\n ...(lastConversationTopic ? { lastConversationTopic } : {}),\n ...(conversationLanguage !== undefined ? { conversationLanguage } : {}),\n });\n return {\n url: data.conversationUrl ?? '',\n id: data.interactiveConversationId ?? '',\n limit: resolveLimitMs(data.limitation),\n };\n }\n\n createVoiceConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult> {\n return this.createConversation('create-voice-conversation', params);\n }\n\n createInteractiveConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult> {\n return this.createConversation('create-interactive-conversation', params);\n }\n\n async endInteractiveConversation(\n params: EndConversationParams,\n ): Promise<void> {\n const { chatId, conversationId, namespace } = params;\n await this.request(\n 'POST',\n `${PERSONA_CHAT}/chats/${encodeURIComponent(\n chatId,\n )}/end-interactive-conversation`,\n { namespace, interactiveConversationId: conversationId },\n ).catch(() => {\n // best-effort\n });\n }\n\n async sendChatMessage(params: SendMessageParams): Promise<{\n functionCalls?: ChatFunctionCall[];\n messages?: ChatMessage[];\n }> {\n const {\n chatId,\n namespace,\n message,\n functionCallResults,\n chatConfig,\n attachments,\n metadata,\n conversationLanguage,\n } = params;\n const data = await this.request<{\n functionCalls?: ChatFunctionCall[];\n messages?: RawMessage[];\n }>('POST', `${PERSONA_CHAT}/chat/messages`, {\n chatId,\n namespace,\n ...(message ? { message } : {}),\n ...(functionCallResults ? { functionCallResults } : {}),\n ...(chatConfig ? { chatConfig } : {}),\n ...(attachments ? { attachments } : {}),\n ...(metadata ? { metadata } : {}),\n ...(conversationLanguage !== undefined ? { conversationLanguage } : {}),\n });\n return {\n functionCalls: data.functionCalls,\n messages: (data.messages ?? []).map(toMessage),\n };\n }\n\n async queryChatMessages(\n params: QueryMessagesParams,\n ): Promise<QueryMessagesResult> {\n const { chatId, namespace, limit = 100, cursor } = params;\n const query = new URLSearchParams({\n namespace,\n 'query.cursorPaging.limit': String(limit),\n ...(cursor ? { 'query.cursorPaging.cursor': cursor } : {}),\n });\n const data = await this.request<{\n chatMessages?: RawMessage[];\n pagingMetadata?: { cursors?: { next?: string } };\n }>(\n 'GET',\n `${PERSONA_CHAT}/chats/${encodeURIComponent(chatId)}/messages?${query}`,\n );\n return {\n messages: (data.chatMessages ?? []).map(toMessage),\n nextCursor: data.pagingMetadata?.cursors?.next,\n };\n }\n}\n"],"mappings":";AAAA,SAASA,SAAS,QAAQ,eAAe;AAazC,SAASC,gBAAgB,QAAQ,2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AAC;IACxE,CAAC,CAAC;IACF,OAAO;MACLc,aAAa,EAAEb,IAAI,CAACa,aAAa;MACjCC,QAAQ,EAAE,CAACd,IAAI,CAACc,QAAQ,IAAI,EAAE,EAAEC,GAAG,CAACvD,SAAS;IAC/C,CAAC;EACH;EAEA,MAAMwD,iBAAiBA,CACrBvB,MAA2B,EACG;IAAA,IAAAwB,oBAAA;IAC9B,MAAQvB,MAAM,GAAqCD,MAAM,CAAjDC,MAAM;MAAEC,SAAS,GAA0BF,MAAM,CAAzCE,SAAS;MAAAuB,aAAA,GAA0BzB,MAAM,CAA9BtC,KAAK;MAALA,KAAK,GAAA+D,aAAA,cAAG,GAAG,GAAAA,aAAA;MAAEC,MAAM,GAAK1B,MAAM,CAAjB0B,MAAM;IAC9C,MAAMC,KAAK,GAAG,IAAIC,eAAe,CAAC;MAChC1B,SAAS;MACT,0BAA0B,EAAE2B,MAAM,CAACnE,KAAK,CAAC;MACzC,IAAIgE,MAAM,GAAG;QAAE,2BAA2B,EAAEA;MAAO,CAAC,GAAG,CAAC,CAAC;IAC3D,CAAC,CAAC;IACF,MAAMnB,IAAI,GAAG,MAAM,IAAI,CAAC1B,OAAO,CAI7B,KAAK,EACL,GAAGxB,YAAY,UAAUmD,kBAAkB,CAACP,MAAM,CAAC,aAAa0B,KAAK,EACvE,CAAC;IACD,OAAO;MACLN,QAAQ,EAAE,CAACd,IAAI,CAACuB,YAAY,IAAI,EAAE,EAAER,GAAG,CAACvD,SAAS,CAAC;MAClDgE,UAAU,GAAAP,oBAAA,GAAEjB,IAAI,CAACyB,cAAc,cAAAR,oBAAA,GAAnBA,oBAAA,CAAqBS,OAAO,qBAA5BT,oBAAA,CAA8BU;IAC5C,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { HttpError } from '../types/http';
|
|
3
|
-
const
|
|
3
|
+
export const DEFAULT_BASE_URL = 'https://www.wixapis.com';
|
|
4
4
|
function resolveLimitMs(limitation) {
|
|
5
5
|
if (!limitation) {
|
|
6
6
|
return undefined;
|
|
@@ -16,9 +16,18 @@ function resolveLimitMs(limitation) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
export class FetchPersonaChatService {
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Server side only: a namespace API key skips owner checks and must never
|
|
21
|
+
* reach a browser. A browser uses BearerPersonaChatService with a visitor token.
|
|
22
|
+
*/
|
|
23
|
+
constructor(apiKey, options) {
|
|
24
|
+
if (options === void 0) {
|
|
25
|
+
options = {};
|
|
26
|
+
}
|
|
20
27
|
_defineProperty(this, "apiKey", void 0);
|
|
28
|
+
_defineProperty(this, "baseUrl", void 0);
|
|
21
29
|
this.apiKey = apiKey;
|
|
30
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
22
31
|
}
|
|
23
32
|
headers() {
|
|
24
33
|
return {
|
|
@@ -27,7 +36,7 @@ export class FetchPersonaChatService {
|
|
|
27
36
|
};
|
|
28
37
|
}
|
|
29
38
|
async post(path, body) {
|
|
30
|
-
const response = await fetch(`${
|
|
39
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
31
40
|
method: 'POST',
|
|
32
41
|
headers: this.headers(),
|
|
33
42
|
body: JSON.stringify(body)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HttpError","BASE_URL","resolveLimitMs","limitation","undefined","type","limit","FetchPersonaChatService","constructor","apiKey","_defineProperty","headers","Authorization","post","path","body","response","fetch","method","JSON","stringify","ok","text","catch","status","parseJson","json","createVoiceConversation","params","chatId","namespace","chatConfig","conversationLanguage","data","url","conversationUrl","id","interactiveConversationId","createInteractiveConversation","endInteractiveConversation","conversationId","sendChatMessage","message","functionCallResults","attachments","queryChatMessages","_data$pagingMetadata","_params$limit","cursor","query","cursorPaging","messages","chatMessages","map","m","content","role","createdAt","nextCursor","pagingMetadata","cursors","next","parse"],"sources":["../../../src/services/FetchPersonaChatService.ts"],"sourcesContent":["import { HttpError } from '../types/http';\nimport type {\n IPersonaChatService,\n CreateConversationParams,\n ConversationResult,\n EndConversationParams,\n SendMessageParams,\n QueryMessagesParams,\n QueryMessagesResult,\n FunctionCall,\n ChatFunctionCall,\n ChatMessage,\n Limitation,\n} from '../types';\n\nconst BASE_URL = 'https://www.wixapis.com';\n\nfunction resolveLimitMs(limitation?: Limitation): number | undefined {\n if (!limitation) {\n return undefined;\n }\n switch (limitation.type) {\n case 'MINUTES':\n return (limitation.limit ?? 0) * 60 * 1000;\n case 'SECONDS':\n return (limitation.limit ?? 0) * 1000;\n case 'TOKENS':\n default:\n return 0;\n }\n}\n\nexport class FetchPersonaChatService implements IPersonaChatService {\n private readonly apiKey: string;\n\n constructor(apiKey: string) {\n this.apiKey = apiKey;\n }\n\n private headers(): Record<string, string> {\n return {\n 'Content-Type': 'application/json',\n Authorization: `Api-Key ${this.apiKey}`,\n };\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const response = await fetch(`${BASE_URL}${path}`, {\n method: 'POST',\n headers: this.headers(),\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const text = await response.text().catch(() => '');\n throw new HttpError(\n response.status,\n `Request failed: ${response.status} ${text}`,\n parseJson(text),\n );\n }\n\n return response.json() as Promise<T>;\n }\n\n async createVoiceConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult> {\n const { chatId, namespace, chatConfig, conversationLanguage } = params;\n\n const data = await this.post<{\n conversationUrl?: string;\n interactiveConversationId?: string;\n limitation?: Limitation;\n }>(\n `/_api/persona-chat-service/v1/chats/${chatId}/create-voice-conversation`,\n {\n namespace,\n ...(chatConfig ? { chatConfig } : {}),\n ...(conversationLanguage !== undefined ? { conversationLanguage } : {}),\n },\n );\n\n return {\n url: data.conversationUrl ?? '',\n id: data.interactiveConversationId ?? '',\n limit: resolveLimitMs(data.limitation),\n };\n }\n\n async createInteractiveConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult> {\n const { chatId, namespace, chatConfig, conversationLanguage } = params;\n\n const data = await this.post<{\n conversationUrl?: string;\n interactiveConversationId?: string;\n limitation?: Limitation;\n }>(\n `/_api/persona-chat-service/v1/chats/${chatId}/create-interactive-conversation`,\n {\n namespace,\n ...(chatConfig ? { chatConfig } : {}),\n ...(conversationLanguage !== undefined ? { conversationLanguage } : {}),\n },\n );\n\n return {\n url: data.conversationUrl ?? '',\n id: data.interactiveConversationId ?? '',\n limit: resolveLimitMs(data.limitation),\n };\n }\n\n async endInteractiveConversation(\n params: EndConversationParams,\n ): Promise<void> {\n const { chatId, conversationId, namespace } = params;\n\n await this.post(\n `/_api/persona-chat-service/v1/chats/${chatId}/end-interactive-conversation`,\n { namespace, interactiveConversationId: conversationId },\n ).catch(() => {\n // best-effort\n });\n }\n\n async sendChatMessage(params: SendMessageParams): Promise<{\n functionCalls?: (FunctionCall | ChatFunctionCall)[];\n messages?: ChatMessage[];\n }> {\n const {\n chatId,\n namespace,\n message,\n functionCallResults,\n chatConfig,\n attachments,\n conversationLanguage,\n } = params;\n\n return this.post<{\n functionCalls?: ChatFunctionCall[];\n messages?: ChatMessage[];\n }>(`/_api/persona-chat-service/v1/chats/${chatId}/messages`, {\n namespace,\n message,\n ...(functionCallResults ? { functionCallResults } : {}),\n ...(chatConfig ? { chatConfig } : {}),\n ...(attachments ? { attachments } : {}),\n ...(conversationLanguage !== undefined ? { conversationLanguage } : {}),\n });\n }\n\n async queryChatMessages(\n params: QueryMessagesParams,\n ): Promise<QueryMessagesResult> {\n const { chatId, namespace, limit = 100, cursor } = params;\n\n const data = await this.post<{\n chatMessages?: {\n id: string;\n content: string;\n role: string;\n createdAt?: string;\n }[];\n pagingMetadata?: { cursors?: { next?: string } };\n }>(`/_api/persona-chat-service/v1/chats/${chatId}/messages/query`, {\n namespace,\n query: { cursorPaging: { limit, ...(cursor ? { cursor } : {}) } },\n });\n\n return {\n messages: (data.chatMessages ?? []).map((m) => ({\n id: m.id,\n content: m.content,\n role: m.role as 'USER' | 'ASSISTANT',\n createdAt: m.createdAt,\n })),\n nextCursor: data.pagingMetadata?.cursors?.next,\n };\n }\n}\n\nfunction parseJson(text: string): unknown {\n try {\n return JSON.parse(text);\n } catch {\n return undefined;\n }\n}\n"],"mappings":";AAAA,SAASA,SAAS,QAAQ,eAAe;AAezC,MAAMC,QAAQ,GAAG,yBAAyB;AAE1C,SAASC,cAAcA,CAACC,UAAuB,EAAsB;EACnE,IAAI,CAACA,UAAU,EAAE;IACf,OAAOC,SAAS;EAClB;EACA,QAAQD,UAAU,CAACE,IAAI;IACrB,KAAK,SAAS;MACZ,OAAO,CAACF,UAAU,CAACG,KAAK,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI;IAC5C,KAAK,SAAS;MACZ,OAAO,CAACH,UAAU,CAACG,KAAK,IAAI,CAAC,IAAI,IAAI;IACvC,KAAK,QAAQ;IACb;MACE,OAAO,CAAC;EACZ;AACF;AAEA,OAAO,MAAMC,uBAAuB,CAAgC;EAGlEC,WAAWA,CAACC,MAAc,EAAE;IAAAC,eAAA;IAC1B,IAAI,CAACD,MAAM,GAAGA,MAAM;EACtB;EAEQE,OAAOA,CAAA,EAA2B;IACxC,OAAO;MACL,cAAc,EAAE,kBAAkB;MAClCC,aAAa,EAAE,WAAW,IAAI,CAACH,MAAM;IACvC,CAAC;EACH;EAEA,MAAcI,IAAIA,CAAIC,IAAY,EAAEC,IAAa,EAAc;IAC7D,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAAC,GAAGhB,QAAQ,GAAGa,IAAI,EAAE,EAAE;MACjDI,MAAM,EAAE,MAAM;MACdP,OAAO,EAAE,IAAI,CAACA,OAAO,CAAC,CAAC;MACvBI,IAAI,EAAEI,IAAI,CAACC,SAAS,CAACL,IAAI;IAC3B,CAAC,CAAC;IAEF,IAAI,CAACC,QAAQ,CAACK,EAAE,EAAE;MAChB,MAAMC,IAAI,GAAG,MAAMN,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;AAEA,SAASpC,SAASA,CAACH,IAAY,EAAW;EACxC,IAAI;IACF,OAAOH,IAAI,CAAC2C,KAAK,CAACxC,IAAI,CAAC;EACzB,CAAC,CAAC,MAAM;IACN,OAAOlB,SAAS;EAClB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["HttpError","DEFAULT_BASE_URL","resolveLimitMs","limitation","undefined","type","limit","FetchPersonaChatService","constructor","apiKey","options","_defineProperty","baseUrl","replace","headers","Authorization","post","path","body","response","fetch","method","JSON","stringify","ok","text","catch","status","parseJson","json","createVoiceConversation","params","chatId","namespace","chatConfig","conversationLanguage","data","url","conversationUrl","id","interactiveConversationId","createInteractiveConversation","endInteractiveConversation","conversationId","sendChatMessage","message","functionCallResults","attachments","queryChatMessages","_data$pagingMetadata","_params$limit","cursor","query","cursorPaging","messages","chatMessages","map","m","content","role","createdAt","nextCursor","pagingMetadata","cursors","next","parse"],"sources":["../../../src/services/FetchPersonaChatService.ts"],"sourcesContent":["import { HttpError } from '../types/http';\nimport type {\n IPersonaChatService,\n CreateConversationParams,\n ConversationResult,\n EndConversationParams,\n SendMessageParams,\n QueryMessagesParams,\n QueryMessagesResult,\n FunctionCall,\n ChatFunctionCall,\n ChatMessage,\n Limitation,\n} from '../types';\n\nexport const DEFAULT_BASE_URL = 'https://www.wixapis.com';\n\nexport interface FetchPersonaChatServiceOptions {\n /** API host, e.g. a local or test gateway. Defaults to https://www.wixapis.com. */\n baseUrl?: string;\n}\n\nfunction resolveLimitMs(limitation?: Limitation): number | undefined {\n if (!limitation) {\n return undefined;\n }\n switch (limitation.type) {\n case 'MINUTES':\n return (limitation.limit ?? 0) * 60 * 1000;\n case 'SECONDS':\n return (limitation.limit ?? 0) * 1000;\n case 'TOKENS':\n default:\n return 0;\n }\n}\n\nexport class FetchPersonaChatService implements IPersonaChatService {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n\n /**\n * Server side only: a namespace API key skips owner checks and must never\n * reach a browser. A browser uses BearerPersonaChatService with a visitor token.\n */\n constructor(apiKey: string, options: FetchPersonaChatServiceOptions = {}) {\n this.apiKey = apiKey;\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, '');\n }\n\n private headers(): Record<string, string> {\n return {\n 'Content-Type': 'application/json',\n Authorization: `Api-Key ${this.apiKey}`,\n };\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method: 'POST',\n headers: this.headers(),\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const text = await response.text().catch(() => '');\n throw new HttpError(\n response.status,\n `Request failed: ${response.status} ${text}`,\n parseJson(text),\n );\n }\n\n return response.json() as Promise<T>;\n }\n\n async createVoiceConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult> {\n const { chatId, namespace, chatConfig, conversationLanguage } = params;\n\n const data = await this.post<{\n conversationUrl?: string;\n interactiveConversationId?: string;\n limitation?: Limitation;\n }>(\n `/_api/persona-chat-service/v1/chats/${chatId}/create-voice-conversation`,\n {\n namespace,\n ...(chatConfig ? { chatConfig } : {}),\n ...(conversationLanguage !== undefined ? { conversationLanguage } : {}),\n },\n );\n\n return {\n url: data.conversationUrl ?? '',\n id: data.interactiveConversationId ?? '',\n limit: resolveLimitMs(data.limitation),\n };\n }\n\n async createInteractiveConversation(\n params: CreateConversationParams,\n ): Promise<ConversationResult> {\n const { chatId, namespace, chatConfig, conversationLanguage } = params;\n\n const data = await this.post<{\n conversationUrl?: string;\n interactiveConversationId?: string;\n limitation?: Limitation;\n }>(\n `/_api/persona-chat-service/v1/chats/${chatId}/create-interactive-conversation`,\n {\n namespace,\n ...(chatConfig ? { chatConfig } : {}),\n ...(conversationLanguage !== undefined ? { conversationLanguage } : {}),\n },\n );\n\n return {\n url: data.conversationUrl ?? '',\n id: data.interactiveConversationId ?? '',\n limit: resolveLimitMs(data.limitation),\n };\n }\n\n async endInteractiveConversation(\n params: EndConversationParams,\n ): Promise<void> {\n const { chatId, conversationId, namespace } = params;\n\n await this.post(\n `/_api/persona-chat-service/v1/chats/${chatId}/end-interactive-conversation`,\n { namespace, interactiveConversationId: conversationId },\n ).catch(() => {\n // best-effort\n });\n }\n\n async sendChatMessage(params: SendMessageParams): Promise<{\n functionCalls?: (FunctionCall | ChatFunctionCall)[];\n messages?: ChatMessage[];\n }> {\n const {\n chatId,\n namespace,\n message,\n functionCallResults,\n chatConfig,\n attachments,\n conversationLanguage,\n } = params;\n\n return this.post<{\n functionCalls?: ChatFunctionCall[];\n messages?: ChatMessage[];\n }>(`/_api/persona-chat-service/v1/chats/${chatId}/messages`, {\n namespace,\n message,\n ...(functionCallResults ? { functionCallResults } : {}),\n ...(chatConfig ? { chatConfig } : {}),\n ...(attachments ? { attachments } : {}),\n ...(conversationLanguage !== undefined ? { conversationLanguage } : {}),\n });\n }\n\n async queryChatMessages(\n params: QueryMessagesParams,\n ): Promise<QueryMessagesResult> {\n const { chatId, namespace, limit = 100, cursor } = params;\n\n const data = await this.post<{\n chatMessages?: {\n id: string;\n content: string;\n role: string;\n createdAt?: string;\n }[];\n pagingMetadata?: { cursors?: { next?: string } };\n }>(`/_api/persona-chat-service/v1/chats/${chatId}/messages/query`, {\n namespace,\n query: { cursorPaging: { limit, ...(cursor ? { cursor } : {}) } },\n });\n\n return {\n messages: (data.chatMessages ?? []).map((m) => ({\n id: m.id,\n content: m.content,\n role: m.role as 'USER' | 'ASSISTANT',\n createdAt: m.createdAt,\n })),\n nextCursor: data.pagingMetadata?.cursors?.next,\n };\n }\n}\n\nfunction parseJson(text: string): unknown {\n try {\n return JSON.parse(text);\n } catch {\n return undefined;\n }\n}\n"],"mappings":";AAAA,SAASA,SAAS,QAAQ,eAAe;AAezC,OAAO,MAAMC,gBAAgB,GAAG,yBAAyB;AAOzD,SAASC,cAAcA,CAACC,UAAuB,EAAsB;EACnE,IAAI,CAACA,UAAU,EAAE;IACf,OAAOC,SAAS;EAClB;EACA,QAAQD,UAAU,CAACE,IAAI;IACrB,KAAK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 @@ export type LegendsPlatformProps = {
|
|
|
8
8
|
startupTelemetry?: StartupTelemetryOptions;
|
|
9
9
|
chatId: string;
|
|
10
10
|
namespace: string;
|
|
11
|
+
/** Server-side only: a namespace API key never reaches a browser (use personaChatService with a BearerPersonaChatService there). */
|
|
11
12
|
apiKey?: string;
|
|
13
|
+
/** API host for the apiKey service. Defaults to https://www.wixapis.com. */
|
|
14
|
+
baseUrl?: string;
|
|
12
15
|
personaChatService?: IPersonaChatService;
|
|
13
16
|
store?: Store;
|
|
14
17
|
tools?: ToolsRegistry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LegendsPlatform.d.ts","sourceRoot":"","sources":["../../../../src/components/LegendsPlatform/LegendsPlatform.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0B,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAuB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG/D,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,iCAAiC,CAAC;AAEzC,MAAM,MAAM,oBAAoB,GAAG;IACjC,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,mBAAmB,CAAC;IACzC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"LegendsPlatform.d.ts","sourceRoot":"","sources":["../../../../src/components/LegendsPlatform/LegendsPlatform.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0B,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAuB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG/D,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,iCAAiC,CAAC;AAEzC,MAAM,MAAM,oBAAoB,GAAG;IACjC,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,oIAAoI;IACpI,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,mBAAmB,CAAC;IACzC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qBAwF1D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type Store } from 'jotai/vanilla/store';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import type { ToolsRegistry } from '../../hooks/useTools/model/types';
|
|
5
|
+
import type { IPersonaChatService } from '../../types/service';
|
|
6
|
+
export type LegendsPlatformCoreProps = {
|
|
7
|
+
chatId: string;
|
|
8
|
+
namespace: string;
|
|
9
|
+
/** Required: in a browser, a BearerPersonaChatService with the caller's own token. */
|
|
10
|
+
personaChatService: IPersonaChatService;
|
|
11
|
+
tools?: ToolsRegistry;
|
|
12
|
+
/** Pass the same store and query client to LegendsPlatform when a call starts, to keep the chat state. */
|
|
13
|
+
store?: Store;
|
|
14
|
+
queryClient?: QueryClient;
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The text-chat providers without LiveKit, from the main entry: for a page that
|
|
19
|
+
* loads LiveKit only when a call starts (`@wix/legends-platform-sdk/livekit/sdk`'s
|
|
20
|
+
* LegendsPlatform then wraps the call, with the same store and query client).
|
|
21
|
+
*/
|
|
22
|
+
export declare function LegendsPlatformCore(props: LegendsPlatformCoreProps): React.JSX.Element;
|
|
23
|
+
//# sourceMappingURL=LegendsPlatformCore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LegendsPlatformCore.d.ts","sourceRoot":"","sources":["../../../../src/components/LegendsPlatformCore/LegendsPlatformCore.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAuB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG/D,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,kBAAkB,EAAE,mBAAmB,CAAC;IACxC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,0GAA0G;IAC1G,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,qBA6BlE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/LegendsPlatformCore/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
package/dist/types/sdk.d.ts
CHANGED
|
@@ -16,6 +16,10 @@ export * from './hooks/usePictureInPicture';
|
|
|
16
16
|
export * from './hooks/useMediaPermissions';
|
|
17
17
|
export * from './hooks/useTools';
|
|
18
18
|
export * from './conversation/types';
|
|
19
|
+
export { BearerPersonaChatService } from './services/BearerPersonaChatService';
|
|
20
|
+
export type { BearerPersonaChatServiceOptions } from './services/BearerPersonaChatService';
|
|
21
|
+
export { LegendsPlatformCore } from './components/LegendsPlatformCore';
|
|
22
|
+
export type { LegendsPlatformCoreProps } from './components/LegendsPlatformCore';
|
|
19
23
|
export { createStartupIntent, StartupAttempt, } from './startup-telemetry/attempt';
|
|
20
24
|
export type { StartupIntent, StartupReport, StartupTelemetryOptions, } from './startup-telemetry/attempt';
|
|
21
25
|
//# sourceMappingURL=sdk.d.ts.map
|
package/dist/types/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AAExB,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAA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AAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IPersonaChatService, CreateConversationParams, ConversationResult, EndConversationParams, SendMessageParams, QueryMessagesParams, QueryMessagesResult, ChatFunctionCall, ChatMessage } from '../types';
|
|
2
|
+
export interface BearerPersonaChatServiceOptions {
|
|
3
|
+
/** API host. Defaults to https://www.wixapis.com. */
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
/**
|
|
6
|
+
* The caller's own access token, e.g. a visitor token minted by the Legend's
|
|
7
|
+
* sign-in app. Sent as the Authorization header, the way Wix's headless
|
|
8
|
+
* clients send it. Called for every request, so a refreshed token is used.
|
|
9
|
+
*/
|
|
10
|
+
getAccessToken: () => string | Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Called once when a request answers 401. Refresh the token and resolve true
|
|
13
|
+
* to retry the request with the new token; resolve false to fail it.
|
|
14
|
+
*/
|
|
15
|
+
onUnauthorized?: () => Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The persona-chat service for a browser: authenticated with the caller's own
|
|
19
|
+
* bearer token (never a namespace API key), on the same REST paths the
|
|
20
|
+
* Legend's own page uses for a visitor.
|
|
21
|
+
*/
|
|
22
|
+
export declare class BearerPersonaChatService implements IPersonaChatService {
|
|
23
|
+
private readonly options;
|
|
24
|
+
private readonly baseUrl;
|
|
25
|
+
constructor(options: BearerPersonaChatServiceOptions);
|
|
26
|
+
private request;
|
|
27
|
+
private createConversation;
|
|
28
|
+
createVoiceConversation(params: CreateConversationParams): Promise<ConversationResult>;
|
|
29
|
+
createInteractiveConversation(params: CreateConversationParams): Promise<ConversationResult>;
|
|
30
|
+
endInteractiveConversation(params: EndConversationParams): Promise<void>;
|
|
31
|
+
sendChatMessage(params: SendMessageParams): Promise<{
|
|
32
|
+
functionCalls?: ChatFunctionCall[];
|
|
33
|
+
messages?: ChatMessage[];
|
|
34
|
+
}>;
|
|
35
|
+
queryChatMessages(params: QueryMessagesParams): Promise<QueryMessagesResult>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=BearerPersonaChatService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BearerPersonaChatService.d.ts","sourceRoot":"","sources":["../../../src/services/BearerPersonaChatService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EAEZ,MAAM,UAAU,CAAC;AAGlB,MAAM,WAAW,+BAA+B;IAC9C,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,cAAc,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CACzC;AA8CD;;;;GAIG;AACH,qBAAa,wBAAyB,YAAW,mBAAmB;IAGtD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAEJ,OAAO,EAAE,+BAA+B;YAIvD,OAAO;YAqCP,kBAAkB;IA8BhC,uBAAuB,CACrB,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC;IAI9B,6BAA6B,CAC3B,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC;IAIxB,0BAA0B,CAC9B,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,IAAI,CAAC;IAaV,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC;QACxD,aAAa,CAAC,EAAE,gBAAgB,EAAE,CAAC;QACnC,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;KAC1B,CAAC;IA8BI,iBAAiB,CACrB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,mBAAmB,CAAC;CAmBhC"}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import type { IPersonaChatService, CreateConversationParams, ConversationResult, EndConversationParams, SendMessageParams, QueryMessagesParams, QueryMessagesResult, FunctionCall, ChatFunctionCall, ChatMessage } from '../types';
|
|
2
|
+
export declare const DEFAULT_BASE_URL = "https://www.wixapis.com";
|
|
3
|
+
export interface FetchPersonaChatServiceOptions {
|
|
4
|
+
/** API host, e.g. a local or test gateway. Defaults to https://www.wixapis.com. */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
}
|
|
2
7
|
export declare class FetchPersonaChatService implements IPersonaChatService {
|
|
3
8
|
private readonly apiKey;
|
|
4
|
-
|
|
9
|
+
private readonly baseUrl;
|
|
10
|
+
/**
|
|
11
|
+
* Server side only: a namespace API key skips owner checks and must never
|
|
12
|
+
* reach a browser. A browser uses BearerPersonaChatService with a visitor token.
|
|
13
|
+
*/
|
|
14
|
+
constructor(apiKey: string, options?: FetchPersonaChatServiceOptions);
|
|
5
15
|
private headers;
|
|
6
16
|
private post;
|
|
7
17
|
createVoiceConversation(params: CreateConversationParams): Promise<ConversationResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchPersonaChatService.d.ts","sourceRoot":"","sources":["../../../src/services/FetchPersonaChatService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,WAAW,EAEZ,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"FetchPersonaChatService.d.ts","sourceRoot":"","sources":["../../../src/services/FetchPersonaChatService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,WAAW,EAEZ,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,gBAAgB,4BAA4B,CAAC;AAE1D,MAAM,WAAW,8BAA8B;IAC7C,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAiBD,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC;;;OAGG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,8BAAmC;IAKxE,OAAO,CAAC,OAAO;YAOD,IAAI;IAmBZ,uBAAuB,CAC3B,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC;IAuBxB,6BAA6B,CACjC,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC;IAuBxB,0BAA0B,CAC9B,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,IAAI,CAAC;IAWV,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC;QACxD,aAAa,CAAC,EAAE,CAAC,YAAY,GAAG,gBAAgB,CAAC,EAAE,CAAC;QACpD,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;KAC1B,CAAC;IAwBI,iBAAiB,CACrB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,mBAAmB,CAAC;CA0BhC"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.36.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": "
|
|
106
|
+
"falconPackageHash": "4f974d90de9401ebfbe0a6cd71f0ee0242f5fa87cb45ad31825e1c22"
|
|
107
107
|
}
|