@wix/legends-platform-sdk 1.34.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/hooks/useTextChat/chatFunctionCalls.js +24 -0
- package/dist/cjs/hooks/useTextChat/chatFunctionCalls.js.map +1 -0
- package/dist/cjs/hooks/useTextChat/useToolAwareSend.js +15 -3
- package/dist/cjs/hooks/useTextChat/useToolAwareSend.js.map +1 -1
- 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/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/service.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/hooks/useTextChat/chatFunctionCalls.js +19 -0
- package/dist/esm/hooks/useTextChat/chatFunctionCalls.js.map +1 -0
- package/dist/esm/hooks/useTextChat/useToolAwareSend.js +15 -3
- package/dist/esm/hooks/useTextChat/useToolAwareSend.js.map +1 -1
- 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/esm/types/index.js.map +1 -1
- package/dist/esm/types/service.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/hooks/useTextChat/chatFunctionCalls.d.ts +4 -0
- package/dist/types/hooks/useTextChat/chatFunctionCalls.d.ts.map +1 -0
- package/dist/types/hooks/useTextChat/useToolAwareSend.d.ts.map +1 -1
- 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 +13 -3
- package/dist/types/services/FetchPersonaChatService.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/service.d.ts +15 -2
- package/dist/types/types/service.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -80,7 +80,8 @@ The root context provider. Must wrap all SDK hooks and components.
|
|
|
80
80
|
|------|------|-------------|
|
|
81
81
|
| `chatId` | `string` | Required. The chat instance ID |
|
|
82
82
|
| `namespace` | `string` | Required. Your namespace |
|
|
83
|
-
| `apiKey` | `string` | Raw namespace API key — pass `lp_...` as-is, the SDK sends it as `Authorization: Api-Key <token
|
|
83
|
+
| `apiKey` | `string` | Raw namespace API key — pass `lp_...` as-is, the SDK sends it as `Authorization: Api-Key <token>`. **Server-side or trusted apps only: never put a namespace API key in a web page** |
|
|
84
|
+
| `baseUrl` | `string` | API host for the `apiKey` service. Defaults to `https://www.wixapis.com` |
|
|
84
85
|
| `personaChatService` | `IPersonaChatService` | Custom service for advanced use cases (see below) |
|
|
85
86
|
| `tools` | `ToolsRegistry` | Optional client-side tool handlers |
|
|
86
87
|
| `queryClient` | `QueryClient` | Optional TanStack Query client |
|
|
@@ -88,6 +89,22 @@ The root context provider. Must wrap all SDK hooks and components.
|
|
|
88
89
|
|
|
89
90
|
Either `apiKey` or `personaChatService` must be provided.
|
|
90
91
|
|
|
92
|
+
#### In a web page: a bearer token, never an API key
|
|
93
|
+
|
|
94
|
+
A page authenticates with the visitor's own access token (for example a visitor token minted by the Legend's sign-in app), through `BearerPersonaChatService`:
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import { BearerPersonaChatService, LegendsPlatformCore } from '@wix/legends-platform-sdk';
|
|
98
|
+
|
|
99
|
+
const service = new BearerPersonaChatService({
|
|
100
|
+
baseUrl: 'https://www.wixapis.com', // optional
|
|
101
|
+
getAccessToken: () => tokens.accessToken, // called for every request
|
|
102
|
+
onUnauthorized: () => tokens.refresh(), // optional: resolve true to retry once after a 401
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`LegendsPlatformCore` (main entry) provides the text-chat hooks without loading LiveKit. When a call starts, wrap it in `LegendsPlatform` from `@wix/legends-platform-sdk/livekit/sdk` and pass the same `store` and `queryClient` to keep the chat state.
|
|
107
|
+
|
|
91
108
|
---
|
|
92
109
|
|
|
93
110
|
### Hooks
|
|
@@ -21,6 +21,7 @@ function LegendsPlatform(props) {
|
|
|
21
21
|
className,
|
|
22
22
|
tools = {},
|
|
23
23
|
apiKey,
|
|
24
|
+
baseUrl,
|
|
24
25
|
personaChatService
|
|
25
26
|
} = props;
|
|
26
27
|
const store = (0, _react.useMemo)(() => props.store || (0, _jotai.createStore)(), [props.store]);
|
|
@@ -37,10 +38,12 @@ function LegendsPlatform(props) {
|
|
|
37
38
|
return personaChatService;
|
|
38
39
|
}
|
|
39
40
|
if (apiKey) {
|
|
40
|
-
return new _FetchPersonaChatService.FetchPersonaChatService(apiKey
|
|
41
|
+
return new _FetchPersonaChatService.FetchPersonaChatService(apiKey, {
|
|
42
|
+
baseUrl
|
|
43
|
+
});
|
|
41
44
|
}
|
|
42
45
|
return undefined;
|
|
43
|
-
}, [personaChatService, apiKey]);
|
|
46
|
+
}, [personaChatService, apiKey, baseUrl]);
|
|
44
47
|
const telemetryRef = (0, _react.useRef)(props.startupTelemetry);
|
|
45
48
|
telemetryRef.current = props.startupTelemetry;
|
|
46
49
|
const telemetryEnabled = (_props$startupTelemet = props.startupTelemetry) == null ? void 0 : _props$startupTelemet.enabled;
|
|
@@ -75,7 +78,7 @@ function LegendsPlatform(props) {
|
|
|
75
78
|
__self: this,
|
|
76
79
|
__source: {
|
|
77
80
|
fileName: _jsxFileName,
|
|
78
|
-
lineNumber:
|
|
81
|
+
lineNumber: 105,
|
|
79
82
|
columnNumber: 5
|
|
80
83
|
}
|
|
81
84
|
}, /*#__PURE__*/_react.default.createElement(_reactQuery.QueryClientProvider, {
|
|
@@ -83,7 +86,7 @@ function LegendsPlatform(props) {
|
|
|
83
86
|
__self: this,
|
|
84
87
|
__source: {
|
|
85
88
|
fileName: _jsxFileName,
|
|
86
|
-
lineNumber:
|
|
89
|
+
lineNumber: 106,
|
|
87
90
|
columnNumber: 7
|
|
88
91
|
}
|
|
89
92
|
}, /*#__PURE__*/_react.default.createElement(_jotai.Provider, {
|
|
@@ -91,14 +94,14 @@ function LegendsPlatform(props) {
|
|
|
91
94
|
__self: this,
|
|
92
95
|
__source: {
|
|
93
96
|
fileName: _jsxFileName,
|
|
94
|
-
lineNumber:
|
|
97
|
+
lineNumber: 107,
|
|
95
98
|
columnNumber: 9
|
|
96
99
|
}
|
|
97
100
|
}, /*#__PURE__*/_react.default.createElement(_reactBus.Provider, {
|
|
98
101
|
__self: this,
|
|
99
102
|
__source: {
|
|
100
103
|
fileName: _jsxFileName,
|
|
101
|
-
lineNumber:
|
|
104
|
+
lineNumber: 108,
|
|
102
105
|
columnNumber: 11
|
|
103
106
|
}
|
|
104
107
|
}, /*#__PURE__*/_react.default.createElement(_componentsReact.LiveKitRoom, {
|
|
@@ -108,7 +111,7 @@ function LegendsPlatform(props) {
|
|
|
108
111
|
__self: this,
|
|
109
112
|
__source: {
|
|
110
113
|
fileName: _jsxFileName,
|
|
111
|
-
lineNumber:
|
|
114
|
+
lineNumber: 109,
|
|
112
115
|
columnNumber: 13
|
|
113
116
|
}
|
|
114
117
|
}, children)))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_jotai","_componentsReact","_reactQuery","_reactBus","_FetchPersonaChatService","_sdkConsumer","_attempt","_jsxFileName","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","LegendsPlatform","props","_props$startupTelemet","_props$startupTelemet2","_props$startupTelemet3","chatId","namespace","children","className","tools","apiKey","personaChatService","store","useMemo","createStore","queryClient","QueryClient","defaultOptions","queries","refetchOnMount","refetchOnWindowFocus","resolvedService","FetchPersonaChatService","undefined","telemetryRef","useRef","startupTelemetry","current","telemetryEnabled","enabled","intentId","intent","id","attemptId","attempt","startupTelemetrySession","config","StartupTelemetrySession","report","event","_telemetryRef$current","consumer","createElement","SdkConsumerContext","Provider","value","__self","__source","fileName","lineNumber","columnNumber","QueryClientProvider","client","LiveKitRoom","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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAIA,IAAAK,wBAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AAGyC,IAAAQ,YAAA;AAAA,SAAAT,wBAAAU,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAZ,uBAAA,YAAAA,CAAAU,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_jotai","_componentsReact","_reactQuery","_reactBus","_FetchPersonaChatService","_sdkConsumer","_attempt","_jsxFileName","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","LegendsPlatform","props","_props$startupTelemet","_props$startupTelemet2","_props$startupTelemet3","chatId","namespace","children","className","tools","apiKey","baseUrl","personaChatService","store","useMemo","createStore","queryClient","QueryClient","defaultOptions","queries","refetchOnMount","refetchOnWindowFocus","resolvedService","FetchPersonaChatService","undefined","telemetryRef","useRef","startupTelemetry","current","telemetryEnabled","enabled","intentId","intent","id","attemptId","attempt","startupTelemetrySession","config","StartupTelemetrySession","report","event","_telemetryRef$current","consumer","createElement","SdkConsumerContext","Provider","value","__self","__source","fileName","lineNumber","columnNumber","QueryClientProvider","client","LiveKitRoom","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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAIA,IAAAK,wBAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AAGyC,IAAAQ,YAAA;AAAA,SAAAT,wBAAAU,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAZ,uBAAA,YAAAA,CAAAU,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAA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YAAA;MAAAsE,UAAA;MAAAC,YAAA;IAAA;EAAA,GAEhB5C,QACU,CACF,CACL,CACS,CACM,CAAC;AAElC","ignoreList":[]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.LegendsPlatformCore = LegendsPlatformCore;
|
|
5
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
6
|
+
var _jotai = require("jotai");
|
|
7
|
+
var _reactQuery = require("@tanstack/react-query");
|
|
8
|
+
var _reactBus = require("react-bus");
|
|
9
|
+
var _sdkConsumer = require("../../sdk-consumer");
|
|
10
|
+
var _jsxFileName = "/home/builduser/work/cfec65c05e11cc5b/packages/legends-platform-sdk/dist/cjs/components/LegendsPlatformCore/LegendsPlatformCore.tsx";
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
|
+
/**
|
|
13
|
+
* The text-chat providers without LiveKit, from the main entry: for a page that
|
|
14
|
+
* loads LiveKit only when a call starts (`@wix/legends-platform-sdk/livekit/sdk`'s
|
|
15
|
+
* LegendsPlatform then wraps the call, with the same store and query client).
|
|
16
|
+
*/
|
|
17
|
+
function LegendsPlatformCore(props) {
|
|
18
|
+
const {
|
|
19
|
+
chatId,
|
|
20
|
+
namespace,
|
|
21
|
+
personaChatService,
|
|
22
|
+
tools,
|
|
23
|
+
children
|
|
24
|
+
} = props;
|
|
25
|
+
const store = (0, _react.useMemo)(() => props.store || (0, _jotai.createStore)(), [props.store]);
|
|
26
|
+
const queryClient = (0, _react.useMemo)(() => props.queryClient || new _reactQuery.QueryClient({
|
|
27
|
+
defaultOptions: {
|
|
28
|
+
queries: {
|
|
29
|
+
refetchOnMount: false,
|
|
30
|
+
refetchOnWindowFocus: false
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}), [props.queryClient]);
|
|
34
|
+
const consumer = (0, _react.useMemo)(() => ({
|
|
35
|
+
chatId,
|
|
36
|
+
namespace,
|
|
37
|
+
tools: tools ?? {},
|
|
38
|
+
personaChatService
|
|
39
|
+
}), [chatId, namespace, tools, personaChatService]);
|
|
40
|
+
return /*#__PURE__*/_react.default.createElement(_sdkConsumer.SdkConsumerContext.Provider, {
|
|
41
|
+
value: consumer,
|
|
42
|
+
__self: this,
|
|
43
|
+
__source: {
|
|
44
|
+
fileName: _jsxFileName,
|
|
45
|
+
lineNumber: 49,
|
|
46
|
+
columnNumber: 5
|
|
47
|
+
}
|
|
48
|
+
}, /*#__PURE__*/_react.default.createElement(_reactQuery.QueryClientProvider, {
|
|
49
|
+
client: queryClient,
|
|
50
|
+
__self: this,
|
|
51
|
+
__source: {
|
|
52
|
+
fileName: _jsxFileName,
|
|
53
|
+
lineNumber: 50,
|
|
54
|
+
columnNumber: 7
|
|
55
|
+
}
|
|
56
|
+
}, /*#__PURE__*/_react.default.createElement(_jotai.Provider, {
|
|
57
|
+
store: store,
|
|
58
|
+
__self: this,
|
|
59
|
+
__source: {
|
|
60
|
+
fileName: _jsxFileName,
|
|
61
|
+
lineNumber: 51,
|
|
62
|
+
columnNumber: 9
|
|
63
|
+
}
|
|
64
|
+
}, /*#__PURE__*/_react.default.createElement(_reactBus.Provider, {
|
|
65
|
+
__self: this,
|
|
66
|
+
__source: {
|
|
67
|
+
fileName: _jsxFileName,
|
|
68
|
+
lineNumber: 52,
|
|
69
|
+
columnNumber: 11
|
|
70
|
+
}
|
|
71
|
+
}, children))));
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=LegendsPlatformCore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_jotai","_reactQuery","_reactBus","_sdkConsumer","_jsxFileName","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","LegendsPlatformCore","props","chatId","namespace","personaChatService","tools","children","store","useMemo","createStore","queryClient","QueryClient","defaultOptions","queries","refetchOnMount","refetchOnWindowFocus","consumer","createElement","SdkConsumerContext","Provider","value","__self","__source","fileName","lineNumber","columnNumber","QueryClientProvider","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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAIA,IAAAI,YAAA,GAAAJ,OAAA;AAAwD,IAAAK,YAAA;AAAA,SAAAN,wBAAAO,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,CAAAO,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,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AA,CAAAiD,mBAAmB;IAACC,MAAM,EAAEjB,WAAY;IAAAW,MAAA;IAAAC,QAAA;MAAAC,QAAA,EAAA3C,YAAA;MAAA4C,UAAA;MAAAC,YAAA;IAAA;EAAA,gBACvCpD,MAAA,CAAAkB,OAAA,CAAA0B,aAAA,CAACzC,MAAA,CAAA2C,QAAQ;IAACZ,KAAK,EAAEA,KAAM;IAAAc,MAAA;IAAAC,QAAA;MAAAC,QAAA,EAAA3C,YAAA;MAAA4C,UAAA;MAAAC,YAAA;IAAA;EAAA,gBACrBpD,MAAA,CAAAkB,OAAA,CAAA0B,aAAA,CAACvC,SAAA,CAAAyC,QAAW;IAAAE,MAAA;IAAAC,QAAA;MAAAC,QAAA,EAAA3C,YAAA;MAAA4C,UAAA;MAAAC,YAAA;IAAA;EAAA,GAAEnB,QAAsB,CAC5B,CACS,CACM,CAAC;AAElC","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
var _LegendsPlatformCore = require("./LegendsPlatformCore");
|
|
5
|
+
Object.keys(_LegendsPlatformCore).forEach(function (key) {
|
|
6
|
+
if (key === "default" || key === "__esModule") return;
|
|
7
|
+
if (key in exports && exports[key] === _LegendsPlatformCore[key]) return;
|
|
8
|
+
exports[key] = _LegendsPlatformCore[key];
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_LegendsPlatformCore","require","Object","keys","forEach","key","exports"],"sources":["../../../../src/components/LegendsPlatformCore/index.ts"],"sourcesContent":["export * from './LegendsPlatformCore';\n"],"mappings":";;;AAAA,IAAAA,oBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,oBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,oBAAA,CAAAK,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAL,oBAAA,CAAAK,GAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.fromChatFunctionCall = fromChatFunctionCall;
|
|
5
|
+
exports.toChatFunctionCallResult = toChatFunctionCallResult;
|
|
6
|
+
function fromChatFunctionCall(call) {
|
|
7
|
+
if ('functionCallId' in call) {
|
|
8
|
+
return call;
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
functionCallId: call.id,
|
|
12
|
+
name: call.name,
|
|
13
|
+
arguments: JSON.stringify(call.arguments ?? null)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function toChatFunctionCallResult(result, name) {
|
|
17
|
+
return {
|
|
18
|
+
id: result.functionCallId,
|
|
19
|
+
name,
|
|
20
|
+
content: result.error ?? result.result,
|
|
21
|
+
success: result.error === undefined
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=chatFunctionCalls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["fromChatFunctionCall","call","functionCallId","id","name","arguments","JSON","stringify","toChatFunctionCallResult","result","content","error","success","undefined"],"sources":["../../../../src/hooks/useTextChat/chatFunctionCalls.ts"],"sourcesContent":["import type {\n ChatFunctionCall,\n ChatFunctionCallResult,\n FunctionCall,\n FunctionCallResult,\n} from '../../types';\n\nexport function fromChatFunctionCall(\n call: FunctionCall | ChatFunctionCall,\n): FunctionCall {\n if ('functionCallId' in call) {\n return call;\n }\n\n return {\n functionCallId: call.id,\n name: call.name,\n arguments: JSON.stringify(call.arguments ?? null),\n };\n}\n\nexport function toChatFunctionCallResult(\n result: FunctionCallResult,\n name: string,\n): ChatFunctionCallResult {\n return {\n id: result.functionCallId,\n name,\n content: result.error ?? result.result,\n success: result.error === undefined,\n };\n}\n"],"mappings":";;;;;AAOO,SAASA,oBAAoBA,CAClCC,IAAqC,EACvB;EACd,IAAI,gBAAgB,IAAIA,IAAI,EAAE;IAC5B,OAAOA,IAAI;EACb;EAEA,OAAO;IACLC,cAAc,EAAED,IAAI,CAACE,EAAE;IACvBC,IAAI,EAAEH,IAAI,CAACG,IAAI;IACfC,SAAS,EAAEC,IAAI,CAACC,SAAS,CAACN,IAAI,CAACI,SAAS,IAAI,IAAI;EAClD,CAAC;AACH;AAEO,SAASG,wBAAwBA,CACtCC,MAA0B,EAC1BL,IAAY,EACY;EACxB,OAAO;IACLD,EAAE,EAAEM,MAAM,CAACP,cAAc;IACzBE,IAAI;IACJM,OAAO,EAAED,MAAM,CAACE,KAAK,IAAIF,MAAM,CAACA,MAAM;IACtCG,OAAO,EAAEH,MAAM,CAACE,KAAK,KAAKE;EAC5B,CAAC;AACH","ignoreList":[]}
|
|
@@ -7,6 +7,7 @@ var _sdkConsumer = require("../../sdk-consumer");
|
|
|
7
7
|
var _useTools = require("../useTools");
|
|
8
8
|
var _useToolCallingRuntime = require("../useTools/runtime/useToolCallingRuntime");
|
|
9
9
|
var _helpers = require("./helpers");
|
|
10
|
+
var _chatFunctionCalls = require("./chatFunctionCalls");
|
|
10
11
|
function useToolAwareSend(chatId, namespace, conversationLanguage) {
|
|
11
12
|
const {
|
|
12
13
|
personaChatService
|
|
@@ -41,7 +42,18 @@ function useToolAwareSend(chatId, namespace, conversationLanguage) {
|
|
|
41
42
|
if (toolRuntime.isRunning) {
|
|
42
43
|
throw new _useTools.ToolExecutionInProgressError();
|
|
43
44
|
}
|
|
44
|
-
const
|
|
45
|
+
const toolNames = new Map();
|
|
46
|
+
const sendAndReadCalls = async params => {
|
|
47
|
+
var _response$functionCal;
|
|
48
|
+
const response = await mutation.mutateAsync(params);
|
|
49
|
+
const functionCalls = (_response$functionCal = response.functionCalls) == null ? void 0 : _response$functionCal.map(_chatFunctionCalls.fromChatFunctionCall);
|
|
50
|
+
functionCalls == null || functionCalls.forEach(call => toolNames.set(call.functionCallId, call.name));
|
|
51
|
+
return {
|
|
52
|
+
...response,
|
|
53
|
+
functionCalls
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const initialResponse = await sendAndReadCalls({
|
|
45
57
|
chatId,
|
|
46
58
|
namespace,
|
|
47
59
|
message: message.message ?? '',
|
|
@@ -50,12 +62,12 @@ function useToolAwareSend(chatId, namespace, conversationLanguage) {
|
|
|
50
62
|
metadata: message.metadata,
|
|
51
63
|
conversationLanguage
|
|
52
64
|
});
|
|
53
|
-
return toolRuntime.resolveResponseToolCalls(initialResponse, functionCallResults =>
|
|
65
|
+
return toolRuntime.resolveResponseToolCalls(initialResponse, functionCallResults => sendAndReadCalls({
|
|
54
66
|
chatId,
|
|
55
67
|
namespace,
|
|
56
68
|
message: '',
|
|
57
69
|
chatConfig: message.chatConfig,
|
|
58
|
-
functionCallResults,
|
|
70
|
+
functionCallResults: functionCallResults.map(result => (0, _chatFunctionCalls.toChatFunctionCallResult)(result, toolNames.get(result.functionCallId) ?? '')),
|
|
59
71
|
conversationLanguage
|
|
60
72
|
}));
|
|
61
73
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactQuery","require","_sdkConsumer","_useTools","_useToolCallingRuntime","_helpers","useToolAwareSend","chatId","namespace","conversationLanguage","personaChatService","useSdkConsumer","toolRuntime","useToolCallingRuntime","queryClient","useQueryClient","mutation","useMutation","mutationKey","mutationFn","params","Error","sendChatMessage","onSuccess","data","variables","_data$messages","queryKey","message","setQueryData","append","id","Date","now","toString","content","role","attachments","messages","length","appendMany","send","isRunning","ToolExecutionInProgressError","
|
|
1
|
+
{"version":3,"names":["_reactQuery","require","_sdkConsumer","_useTools","_useToolCallingRuntime","_helpers","_chatFunctionCalls","useToolAwareSend","chatId","namespace","conversationLanguage","personaChatService","useSdkConsumer","toolRuntime","useToolCallingRuntime","queryClient","useQueryClient","mutation","useMutation","mutationKey","mutationFn","params","Error","sendChatMessage","onSuccess","data","variables","_data$messages","queryKey","message","setQueryData","append","id","Date","now","toString","content","role","attachments","messages","length","appendMany","send","isRunning","ToolExecutionInProgressError","toolNames","Map","sendAndReadCalls","_response$functionCal","response","mutateAsync","functionCalls","map","fromChatFunctionCall","forEach","call","set","functionCallId","name","initialResponse","chatConfig","metadata","resolveResponseToolCalls","functionCallResults","result","toChatFunctionCallResult","get"],"sources":["../../../../src/hooks/useTextChat/useToolAwareSend.ts"],"sourcesContent":["import { useMutation, useQueryClient } from '@tanstack/react-query';\nimport type {\n FunctionCall,\n ChatMessageAttachment,\n SendMessageParams,\n SendMessageMetadata,\n} from '../../types';\nimport { useSdkConsumer } from '../../sdk-consumer';\nimport { ToolExecutionInProgressError } from '../useTools';\nimport { useToolCallingRuntime } from '../useTools/runtime/useToolCallingRuntime';\nimport { append, appendMany } from './helpers';\nimport {\n fromChatFunctionCall,\n toChatFunctionCallResult,\n} from './chatFunctionCalls';\n\nexport interface SendChatMessageResponse {\n functionCalls?: FunctionCall[];\n}\n\nexport function useToolAwareSend(\n chatId: string,\n namespace: string,\n conversationLanguage?: string,\n) {\n const { personaChatService } = useSdkConsumer();\n const toolRuntime = useToolCallingRuntime<SendChatMessageResponse>();\n const queryClient = useQueryClient();\n\n const mutation = useMutation({\n mutationKey: ['pending-chat-message'],\n mutationFn: (params: SendMessageParams) => {\n if (!personaChatService) {\n throw new Error('personaChatService is required to send messages.');\n }\n return personaChatService.sendChatMessage(params);\n },\n onSuccess(data, variables) {\n const queryKey = ['chat-messages', chatId, namespace];\n\n if (variables.message) {\n queryClient.setQueryData(\n queryKey,\n append({\n id: Date.now().toString(),\n content: variables.message,\n role: 'USER' as const,\n attachments: variables.attachments,\n }),\n );\n }\n\n if (data.messages?.length) {\n queryClient.setQueryData(queryKey, appendMany(data.messages));\n }\n },\n });\n\n return async function send(message: {\n message?: string;\n chatConfig?: object;\n attachments?: ChatMessageAttachment[];\n metadata?: SendMessageMetadata;\n }) {\n if (toolRuntime.isRunning) {\n throw new ToolExecutionInProgressError();\n }\n\n const toolNames = new Map<string, string>();\n const sendAndReadCalls = async (params: SendMessageParams) => {\n const response = await mutation.mutateAsync(params);\n const functionCalls = response.functionCalls?.map(fromChatFunctionCall);\n functionCalls?.forEach((call) =>\n toolNames.set(call.functionCallId, call.name),\n );\n return { ...response, functionCalls };\n };\n\n const initialResponse = await sendAndReadCalls({\n chatId,\n namespace,\n message: message.message ?? '',\n chatConfig: message.chatConfig,\n attachments: message.attachments,\n metadata: message.metadata,\n conversationLanguage,\n });\n\n return toolRuntime.resolveResponseToolCalls(\n initialResponse,\n (functionCallResults) =>\n sendAndReadCalls({\n chatId,\n namespace,\n message: '',\n chatConfig: message.chatConfig,\n functionCallResults: functionCallResults.map((result) =>\n toChatFunctionCallResult(\n result,\n toolNames.get(result.functionCallId) ?? '',\n ),\n ),\n conversationLanguage,\n }),\n );\n };\n}\n"],"mappings":";;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAOA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,kBAAA,GAAAL,OAAA;AASO,SAASM,gBAAgBA,CAC9BC,MAAc,EACdC,SAAiB,EACjBC,oBAA6B,EAC7B;EACA,MAAM;IAAEC;EAAmB,CAAC,GAAG,IAAAC,2BAAc,EAAC,CAAC;EAC/C,MAAMC,WAAW,GAAG,IAAAC,4CAAqB,EAA0B,CAAC;EACpE,MAAMC,WAAW,GAAG,IAAAC,0BAAc,EAAC,CAAC;EAEpC,MAAMC,QAAQ,GAAG,IAAAC,uBAAW,EAAC;IAC3BC,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrCC,UAAU,EAAGC,MAAyB,IAAK;MACzC,IAAI,CAACV,kBAAkB,EAAE;QACvB,MAAM,IAAIW,KAAK,CAAC,kDAAkD,CAAC;MACr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AG,CAACD,IAAI,CAACE,cAAc,EAAEF,IAAI,CAACG,IAAI,CAC9C,CAAC;MACD,OAAO;QAAE,GAAGT,QAAQ;QAAEE;MAAc,CAAC;IACvC,CAAC;IAED,MAAMQ,eAAe,GAAG,MAAMZ,gBAAgB,CAAC;MAC7CvC,MAAM;MACNC,SAAS;MACToB,OAAO,EAAEA,OAAO,CAACA,OAAO,IAAI,EAAE;MAC9B+B,UAAU,EAAE/B,OAAO,CAAC+B,UAAU;MAC9BtB,WAAW,EAAET,OAAO,CAACS,WAAW;MAChCuB,QAAQ,EAAEhC,OAAO,CAACgC,QAAQ;MAC1BnD;IACF,CAAC,CAAC;IAEF,OAAOG,WAAW,CAACiD,wBAAwB,CACzCH,eAAe,EACdI,mBAAmB,IAClBhB,gBAAgB,CAAC;MACfvC,MAAM;MACNC,SAAS;MACToB,OAAO,EAAE,EAAE;MACX+B,UAAU,EAAE/B,OAAO,CAAC+B,UAAU;MAC9BG,mBAAmB,EAAEA,mBAAmB,CAACX,GAAG,CAAEY,MAAM,IAClD,IAAAC,2CAAwB,EACtBD,MAAM,EACNnB,SAAS,CAACqB,GAAG,CAACF,MAAM,CAACP,cAAc,CAAC,IAAI,EAC1C,CACF,CAAC;MACD/C;IACF,CAAC,CACL,CAAC;EACH,CAAC;AACH","ignoreList":[]}
|
package/dist/cjs/sdk.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
var _exportNames = {
|
|
5
|
+
BearerPersonaChatService: true,
|
|
6
|
+
LegendsPlatformCore: true,
|
|
5
7
|
createStartupIntent: true,
|
|
6
8
|
StartupAttempt: true
|
|
7
9
|
};
|
|
8
|
-
exports.createStartupIntent = exports.StartupAttempt = void 0;
|
|
10
|
+
exports.createStartupIntent = exports.StartupAttempt = exports.LegendsPlatformCore = exports.BearerPersonaChatService = void 0;
|
|
9
11
|
var _types = require("./types");
|
|
10
12
|
Object.keys(_types).forEach(function (key) {
|
|
11
13
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -132,6 +134,10 @@ Object.keys(_types2).forEach(function (key) {
|
|
|
132
134
|
if (key in exports && exports[key] === _types2[key]) return;
|
|
133
135
|
exports[key] = _types2[key];
|
|
134
136
|
});
|
|
137
|
+
var _BearerPersonaChatService = require("./services/BearerPersonaChatService");
|
|
138
|
+
exports.BearerPersonaChatService = _BearerPersonaChatService.BearerPersonaChatService;
|
|
139
|
+
var _LegendsPlatformCore = require("./components/LegendsPlatformCore");
|
|
140
|
+
exports.LegendsPlatformCore = _LegendsPlatformCore.LegendsPlatformCore;
|
|
135
141
|
var _attempt = require("./startup-telemetry/attempt");
|
|
136
142
|
exports.createStartupIntent = _attempt.createStartupIntent;
|
|
137
143
|
exports.StartupAttempt = _attempt.StartupAttempt;
|
package/dist/cjs/sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_types","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","_useTextChat","_useTranscriptions","_useConversationStatus","_useMicrophone","_useSpeaker","_useCamera","_useMediaRecorder","_useConversationTimer","_useConversationEvents","_useUserActivity","_useAudio","_useConnectionState","_useActivityState","_usePictureInPicture","_useMediaPermissions","_useTools","_types2","_attempt","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":"
|
|
1
|
+
{"version":3,"names":["_types","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","_useTextChat","_useTranscriptions","_useConversationStatus","_useMicrophone","_useSpeaker","_useCamera","_useMediaRecorder","_useConversationTimer","_useConversationEvents","_useUserActivity","_useAudio","_useConnectionState","_useActivityState","_usePictureInPicture","_useMediaPermissions","_useTools","_types2","_BearerPersonaChatService","BearerPersonaChatService","_LegendsPlatformCore","LegendsPlatformCore","_attempt","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,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAA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AA,CAAArB,GAAA;AAAA;AAEA,IAAAsB,OAAA,GAAA1B,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAwB,OAAA,EAAAvB,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAsB,OAAA,CAAAtB,GAAA;EAAAK,OAAA,CAAAL,GAAA,IAAAsB,OAAA,CAAAtB,GAAA;AAAA;AAEA,IAAAuB,yBAAA,GAAA3B,OAAA;AAA+ES,OAAA,CAAAmB,wBAAA,GAAAD,yBAAA,CAAAC,wBAAA;AAE/E,IAAAC,oBAAA,GAAA7B,OAAA;AAAuES,OAAA,CAAAqB,mBAAA,GAAAD,oBAAA,CAAAC,mBAAA;AAGvE,IAAAC,QAAA,GAAA/B,OAAA;AAGqCS,OAAA,CAAAuB,mBAAA,GAAAD,QAAA,CAAAC,mBAAA;AAAAvB,OAAA,CAAAwB,cAAA,GAAAF,QAAA,CAAAE,cAAA","ignoreList":[]}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.BearerPersonaChatService = void 0;
|
|
6
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
7
|
+
var _http = require("../types/http");
|
|
8
|
+
var _FetchPersonaChatService = require("./FetchPersonaChatService");
|
|
9
|
+
const PERSONA_CHAT = '/_api/persona-chat-service/v1';
|
|
10
|
+
function resolveLimitMs(limitation) {
|
|
11
|
+
if (!limitation) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
switch (limitation.type) {
|
|
15
|
+
case 'MINUTES':
|
|
16
|
+
return (limitation.limit ?? 0) * 60 * 1000;
|
|
17
|
+
case 'SECONDS':
|
|
18
|
+
return (limitation.limit ?? 0) * 1000;
|
|
19
|
+
case 'TOKENS':
|
|
20
|
+
default:
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function parseJson(text) {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(text);
|
|
27
|
+
} catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function toMessage(m) {
|
|
32
|
+
return {
|
|
33
|
+
id: m.id ?? '',
|
|
34
|
+
content: m.content ?? '',
|
|
35
|
+
role: m.role,
|
|
36
|
+
createdAt: m.createdAt ?? m.createdDate,
|
|
37
|
+
...(m.attachments ? {
|
|
38
|
+
attachments: m.attachments
|
|
39
|
+
} : {})
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The persona-chat service for a browser: authenticated with the caller's own
|
|
45
|
+
* bearer token (never a namespace API key), on the same REST paths the
|
|
46
|
+
* Legend's own page uses for a visitor.
|
|
47
|
+
*/
|
|
48
|
+
class BearerPersonaChatService {
|
|
49
|
+
constructor(options) {
|
|
50
|
+
this.options = options;
|
|
51
|
+
(0, _defineProperty2.default)(this, "baseUrl", void 0);
|
|
52
|
+
this.baseUrl = (options.baseUrl ?? _FetchPersonaChatService.DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
53
|
+
}
|
|
54
|
+
async request(method, path, body, retried = false) {
|
|
55
|
+
const token = await this.options.getAccessToken();
|
|
56
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
57
|
+
method,
|
|
58
|
+
headers: {
|
|
59
|
+
...(body === undefined ? {} : {
|
|
60
|
+
'Content-Type': 'application/json'
|
|
61
|
+
}),
|
|
62
|
+
Authorization: token
|
|
63
|
+
},
|
|
64
|
+
...(body === undefined ? {} : {
|
|
65
|
+
body: JSON.stringify(body)
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
if (response.status === 401 && !retried && this.options.onUnauthorized && (await this.options.onUnauthorized())) {
|
|
69
|
+
return this.request(method, path, body, true);
|
|
70
|
+
}
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
const text = await response.text().catch(() => '');
|
|
73
|
+
throw new _http.HttpError(response.status, `Request failed: ${response.status} ${text}`, parseJson(text));
|
|
74
|
+
}
|
|
75
|
+
return response.json();
|
|
76
|
+
}
|
|
77
|
+
async createConversation(kind, params) {
|
|
78
|
+
const {
|
|
79
|
+
chatId,
|
|
80
|
+
namespace,
|
|
81
|
+
chatConfig,
|
|
82
|
+
firstConversation,
|
|
83
|
+
lastConversationTopic,
|
|
84
|
+
conversationLanguage
|
|
85
|
+
} = params;
|
|
86
|
+
const data = await this.request('POST', `${PERSONA_CHAT}/chats/${encodeURIComponent(chatId)}/${kind}`, {
|
|
87
|
+
namespace,
|
|
88
|
+
...(chatConfig ? {
|
|
89
|
+
chatConfig
|
|
90
|
+
} : {}),
|
|
91
|
+
...(firstConversation !== undefined ? {
|
|
92
|
+
firstConversation
|
|
93
|
+
} : {}),
|
|
94
|
+
...(lastConversationTopic ? {
|
|
95
|
+
lastConversationTopic
|
|
96
|
+
} : {}),
|
|
97
|
+
...(conversationLanguage !== undefined ? {
|
|
98
|
+
conversationLanguage
|
|
99
|
+
} : {})
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
url: data.conversationUrl ?? '',
|
|
103
|
+
id: data.interactiveConversationId ?? '',
|
|
104
|
+
limit: resolveLimitMs(data.limitation)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
createVoiceConversation(params) {
|
|
108
|
+
return this.createConversation('create-voice-conversation', params);
|
|
109
|
+
}
|
|
110
|
+
createInteractiveConversation(params) {
|
|
111
|
+
return this.createConversation('create-interactive-conversation', params);
|
|
112
|
+
}
|
|
113
|
+
async endInteractiveConversation(params) {
|
|
114
|
+
const {
|
|
115
|
+
chatId,
|
|
116
|
+
conversationId,
|
|
117
|
+
namespace
|
|
118
|
+
} = params;
|
|
119
|
+
await this.request('POST', `${PERSONA_CHAT}/chats/${encodeURIComponent(chatId)}/end-interactive-conversation`, {
|
|
120
|
+
namespace,
|
|
121
|
+
interactiveConversationId: conversationId
|
|
122
|
+
}).catch(() => {
|
|
123
|
+
// best-effort
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async sendChatMessage(params) {
|
|
127
|
+
const {
|
|
128
|
+
chatId,
|
|
129
|
+
namespace,
|
|
130
|
+
message,
|
|
131
|
+
functionCallResults,
|
|
132
|
+
chatConfig,
|
|
133
|
+
attachments,
|
|
134
|
+
metadata,
|
|
135
|
+
conversationLanguage
|
|
136
|
+
} = params;
|
|
137
|
+
const data = await this.request('POST', `${PERSONA_CHAT}/chat/messages`, {
|
|
138
|
+
chatId,
|
|
139
|
+
namespace,
|
|
140
|
+
...(message ? {
|
|
141
|
+
message
|
|
142
|
+
} : {}),
|
|
143
|
+
...(functionCallResults ? {
|
|
144
|
+
functionCallResults
|
|
145
|
+
} : {}),
|
|
146
|
+
...(chatConfig ? {
|
|
147
|
+
chatConfig
|
|
148
|
+
} : {}),
|
|
149
|
+
...(attachments ? {
|
|
150
|
+
attachments
|
|
151
|
+
} : {}),
|
|
152
|
+
...(metadata ? {
|
|
153
|
+
metadata
|
|
154
|
+
} : {}),
|
|
155
|
+
...(conversationLanguage !== undefined ? {
|
|
156
|
+
conversationLanguage
|
|
157
|
+
} : {})
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
functionCalls: data.functionCalls,
|
|
161
|
+
messages: (data.messages ?? []).map(toMessage)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
async queryChatMessages(params) {
|
|
165
|
+
var _data$pagingMetadata;
|
|
166
|
+
const {
|
|
167
|
+
chatId,
|
|
168
|
+
namespace,
|
|
169
|
+
limit = 100,
|
|
170
|
+
cursor
|
|
171
|
+
} = params;
|
|
172
|
+
const query = new URLSearchParams({
|
|
173
|
+
namespace,
|
|
174
|
+
'query.cursorPaging.limit': String(limit),
|
|
175
|
+
...(cursor ? {
|
|
176
|
+
'query.cursorPaging.cursor': cursor
|
|
177
|
+
} : {})
|
|
178
|
+
});
|
|
179
|
+
const data = await this.request('GET', `${PERSONA_CHAT}/chats/${encodeURIComponent(chatId)}/messages?${query}`);
|
|
180
|
+
return {
|
|
181
|
+
messages: (data.chatMessages ?? []).map(toMessage),
|
|
182
|
+
nextCursor: (_data$pagingMetadata = data.pagingMetadata) == null || (_data$pagingMetadata = _data$pagingMetadata.cursors) == null ? void 0 : _data$pagingMetadata.next
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.BearerPersonaChatService = BearerPersonaChatService;
|
|
187
|
+
//# sourceMappingURL=BearerPersonaChatService.js.map
|