@useago/sdk 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{createMockClient-BZKh_1em.cjs → AgoClient-BDO4avLq.cjs} +219 -124
- package/dist/AgoClient-BDO4avLq.cjs.map +1 -0
- package/dist/{createMockClient-uGlVyjbL.js → AgoClient-D-c91tx5.js} +221 -126
- package/dist/AgoClient-D-c91tx5.js.map +1 -0
- package/dist/angular/ago.service.d.ts +98 -0
- package/dist/angular/index.d.ts +4 -0
- package/dist/angular/provide.d.ts +27 -0
- package/dist/angular.cjs +105 -0
- package/dist/angular.cjs.map +1 -0
- package/dist/angular.d.ts +1 -0
- package/dist/angular.js +105 -0
- package/dist/angular.js.map +1 -0
- package/dist/auto/createAgo.d.ts +39 -0
- package/dist/auto/index.d.ts +1 -0
- package/dist/client/AgoClient.d.ts +56 -0
- package/dist/client/types.d.ts +4 -6
- package/dist/createMockClient-B1DcBiIK.js +94 -0
- package/dist/createMockClient-B1DcBiIK.js.map +1 -0
- package/dist/createMockClient-BqNSJUu4.cjs +93 -0
- package/dist/createMockClient-BqNSJUu4.cjs.map +1 -0
- package/dist/functions-B0Z0rNQW.cjs +306 -0
- package/dist/functions-B0Z0rNQW.cjs.map +1 -0
- package/dist/functions-C-wLEc8b.js +306 -0
- package/dist/functions-C-wLEc8b.js.map +1 -0
- package/dist/helpers/factory.d.ts +20 -0
- package/dist/helpers/functions.d.ts +62 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers.cjs +17 -0
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +17 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.cjs +179 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +173 -5
- package/dist/index.js.map +1 -1
- package/dist/react/context/AgoContext.d.ts +30 -4
- package/dist/react/context/index.d.ts +1 -1
- package/dist/react/hooks/index.d.ts +1 -0
- package/dist/react/hooks/useAgoContext.d.ts +40 -0
- package/dist/react/hooks/useAgoFunction.d.ts +14 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react.cjs +76 -11
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +81 -17
- package/dist/react.js.map +1 -1
- package/dist/state/ClientContextRegistry.d.ts +64 -0
- package/dist/streaming/helpers.d.ts +67 -0
- package/dist/vue/composables/useAgo.d.ts +17 -0
- package/dist/vue/composables/useAgoEvents.d.ts +11 -0
- package/dist/vue/composables/useAgoFunction.d.ts +34 -0
- package/dist/vue/composables/useChat.d.ts +251 -0
- package/dist/vue/composables/useConversation.d.ts +178 -0
- package/dist/vue/composables/useMessages.d.ts +89 -0
- package/dist/vue/index.d.ts +10 -0
- package/dist/vue/plugin.d.ts +16 -0
- package/dist/vue/symbols.d.ts +3 -0
- package/dist/vue.cjs +232 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.ts +1 -0
- package/dist/vue.js +232 -0
- package/dist/vue.js.map +1 -0
- package/dist/widget/types.d.ts +1 -0
- package/package.json +23 -3
- package/dist/createMockClient-BZKh_1em.cjs.map +0 -1
- package/dist/createMockClient-uGlVyjbL.js.map +0 -1
package/dist/react.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useRef, useMemo, useEffect, createContext, useContext, useCallback } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { useState, useRef, useMemo, useEffect, createContext, useContext, useCallback, useId } from "react";
|
|
3
|
+
import { A as AgoClient } from "./AgoClient-D-c91tx5.js";
|
|
4
|
+
import { c } from "./createMockClient-B1DcBiIK.js";
|
|
5
5
|
function useAgo(config) {
|
|
6
6
|
const [isReady, setIsReady] = useState(false);
|
|
7
7
|
const clientRef = useRef(null);
|
|
@@ -12,7 +12,7 @@ function useAgo(config) {
|
|
|
12
12
|
const newClient = new AgoClient(config);
|
|
13
13
|
clientRef.current = newClient;
|
|
14
14
|
return newClient;
|
|
15
|
-
}, [config.
|
|
15
|
+
}, [config.baseUrl, config.widgetId]);
|
|
16
16
|
useEffect(() => {
|
|
17
17
|
setIsReady(true);
|
|
18
18
|
return () => {
|
|
@@ -40,19 +40,59 @@ const AgoContext = createContext(null);
|
|
|
40
40
|
const AgoProvider = ({
|
|
41
41
|
children,
|
|
42
42
|
client: externalClient,
|
|
43
|
+
tools,
|
|
44
|
+
helpers,
|
|
45
|
+
pageContext,
|
|
43
46
|
...config
|
|
44
47
|
}) => {
|
|
45
48
|
const { client: internalClient } = useAgo(
|
|
46
|
-
externalClient ? {
|
|
49
|
+
externalClient ? { baseUrl: "" } : config
|
|
47
50
|
);
|
|
48
51
|
const client = externalClient || internalClient;
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!tools || tools.length === 0) return;
|
|
54
|
+
for (const tool of tools) {
|
|
55
|
+
client.register(tool);
|
|
56
|
+
}
|
|
57
|
+
return () => {
|
|
58
|
+
for (const tool of tools) {
|
|
59
|
+
client.unregisterFunction(tool.name);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}, [client, tools]);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!helpers) return;
|
|
65
|
+
const registered = [];
|
|
66
|
+
import("./functions-C-wLEc8b.js").then((mod) => {
|
|
67
|
+
for (const [name2, handlerOrTrue] of Object.entries(helpers)) {
|
|
68
|
+
const helper = mod[name2];
|
|
69
|
+
if (!helper) {
|
|
70
|
+
console.warn(`[AGO] Unknown helper: "${name2}"`);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const definition2 = handlerOrTrue === true ? helper : { ...helper, handler: handlerOrTrue };
|
|
74
|
+
client.register(definition2);
|
|
75
|
+
registered.push(definition2.name);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return () => {
|
|
79
|
+
for (const name2 of registered) {
|
|
80
|
+
client.unregisterFunction(name2);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}, [client, helpers]);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (pageContext === "auto") {
|
|
86
|
+
client.enableAutoPageContext();
|
|
87
|
+
}
|
|
88
|
+
}, [client, pageContext]);
|
|
49
89
|
return /* @__PURE__ */ jsx(AgoContext.Provider, { value: client, children });
|
|
50
90
|
};
|
|
51
91
|
function useAgoClient() {
|
|
52
92
|
const client = useContext(AgoContext);
|
|
53
93
|
if (!client) {
|
|
54
94
|
throw new Error(
|
|
55
|
-
'useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider
|
|
95
|
+
'useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.'
|
|
56
96
|
);
|
|
57
97
|
}
|
|
58
98
|
return client;
|
|
@@ -1509,11 +1549,11 @@ function index$1(style, options) {
|
|
|
1509
1549
|
match(WHITESPACE_REGEX);
|
|
1510
1550
|
}
|
|
1511
1551
|
function comments(rules) {
|
|
1512
|
-
var
|
|
1552
|
+
var c2;
|
|
1513
1553
|
rules = rules || [];
|
|
1514
|
-
while (
|
|
1515
|
-
if (
|
|
1516
|
-
rules.push(
|
|
1554
|
+
while (c2 = comment()) {
|
|
1555
|
+
if (c2 !== false) {
|
|
1556
|
+
rules.push(c2);
|
|
1517
1557
|
}
|
|
1518
1558
|
}
|
|
1519
1559
|
return rules;
|
|
@@ -10539,20 +10579,21 @@ function useChat(options = {}) {
|
|
|
10539
10579
|
refreshConversations: conversationResult.refreshConversations
|
|
10540
10580
|
};
|
|
10541
10581
|
}
|
|
10542
|
-
function useAgoFunction(
|
|
10582
|
+
function useAgoFunction(nameOrDef, options) {
|
|
10543
10583
|
const client = useAgoClient();
|
|
10544
|
-
const
|
|
10545
|
-
handlerRef
|
|
10584
|
+
const { name: name2, description, parameters, handler } = typeof nameOrDef === "string" ? { name: nameOrDef, ...options } : nameOrDef;
|
|
10585
|
+
const handlerRef = useRef(handler);
|
|
10586
|
+
handlerRef.current = handler;
|
|
10546
10587
|
useEffect(() => {
|
|
10547
10588
|
const stableHandler = (args) => handlerRef.current(args);
|
|
10548
10589
|
client.registerFunction(name2, stableHandler, {
|
|
10549
|
-
description
|
|
10550
|
-
parameters
|
|
10590
|
+
description,
|
|
10591
|
+
parameters
|
|
10551
10592
|
});
|
|
10552
10593
|
return () => {
|
|
10553
10594
|
client.unregisterFunction(name2);
|
|
10554
10595
|
};
|
|
10555
|
-
}, [client, name2,
|
|
10596
|
+
}, [client, name2, description, parameters]);
|
|
10556
10597
|
}
|
|
10557
10598
|
function useAgoNavigation(navigate, routes) {
|
|
10558
10599
|
const client = useAgoClient();
|
|
@@ -10568,14 +10609,37 @@ function useAgoNavigation(navigate, routes) {
|
|
|
10568
10609
|
};
|
|
10569
10610
|
}, [client, routes]);
|
|
10570
10611
|
}
|
|
10612
|
+
function useAgoContext(entryOrProvider, key) {
|
|
10613
|
+
const client = useAgoClient();
|
|
10614
|
+
const autoKey = useId();
|
|
10615
|
+
const effectiveKey = key ?? autoKey;
|
|
10616
|
+
const providerRef = useRef(entryOrProvider);
|
|
10617
|
+
providerRef.current = entryOrProvider;
|
|
10618
|
+
const isDynamic = typeof entryOrProvider === "function";
|
|
10619
|
+
const serialized = isDynamic ? "" : JSON.stringify(entryOrProvider);
|
|
10620
|
+
useEffect(() => {
|
|
10621
|
+
if (typeof providerRef.current === "function") {
|
|
10622
|
+
const stableProvider = () => providerRef.current();
|
|
10623
|
+
client.addDynamicContext(effectiveKey, stableProvider);
|
|
10624
|
+
return () => {
|
|
10625
|
+
client.removeDynamicContext(effectiveKey);
|
|
10626
|
+
};
|
|
10627
|
+
}
|
|
10628
|
+
client.setContext(effectiveKey, providerRef.current);
|
|
10629
|
+
return () => {
|
|
10630
|
+
client.removeContext(effectiveKey);
|
|
10631
|
+
};
|
|
10632
|
+
}, [client, effectiveKey, isDynamic, serialized]);
|
|
10633
|
+
}
|
|
10571
10634
|
export {
|
|
10572
10635
|
AgoProvider,
|
|
10573
10636
|
ChatInput,
|
|
10574
10637
|
ChatWidget,
|
|
10575
10638
|
Message,
|
|
10576
|
-
|
|
10639
|
+
c as createMockClient,
|
|
10577
10640
|
useAgo,
|
|
10578
10641
|
useAgoClient,
|
|
10642
|
+
useAgoContext,
|
|
10579
10643
|
useAgoFunction,
|
|
10580
10644
|
useAgoNavigation,
|
|
10581
10645
|
useChat,
|