site-operator-react 0.2.1 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -119,3 +119,43 @@ function App() {
119
119
  // - once ready, it returns the live ChatController instance
120
120
  // controller?.sendMessage('Hola');
121
121
  ```
122
+
123
+ ### AgentChatProvider + AgentChatMount + useAgentChatController
124
+
125
+ If you prefer a React Context approach, wrap your app (or a subtree) with `AgentChatProvider`. It manages the `ref` and exposes the `ChatController` via `useAgentChatController`. Place `<AgentChatMount />` where you want the chat UI to render.
126
+
127
+ ```tsx
128
+ import { AgentChatProvider, AgentChatMount, useAgentChatController, type AppContext } from 'site-operator-react';
129
+
130
+ const context: AppContext = {
131
+ v: "1.1",
132
+ site: { name: "Mi Portal" },
133
+ user: { id: "u-123" },
134
+ nav: { routes: [] }
135
+ };
136
+
137
+ function ChatActions() {
138
+ const controller = useAgentChatController();
139
+ return (
140
+ <button onClick={() => controller?.startNewThread()}>
141
+ Nuevo chat
142
+ </button>
143
+ );
144
+ }
145
+
146
+ function App() {
147
+ return (
148
+ <AgentChatProvider
149
+ backendUrl="http://localhost:8001/ag_ui"
150
+ appName="My React App"
151
+ context={{ appContext: context }}
152
+ >
153
+ <header>Mi App</header>
154
+ <main>
155
+ <AgentChatMount className="chat-root" />
156
+ </main>
157
+ <ChatActions />
158
+ </AgentChatProvider>
159
+ );
160
+ }
161
+ ```
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Action } from 'site-operator';
1
2
  import { AgentChat as AgentChat_2 } from 'site-operator';
2
3
  import { AgentState } from 'site-operator';
3
4
  import { AppContext } from 'site-operator';
@@ -5,9 +6,14 @@ import { AppState } from 'site-operator';
5
6
  import { ChatController } from 'site-operator';
6
7
  import { ClickTarget } from 'site-operator';
7
8
  import { default as default_2 } from 'react';
9
+ import { ExecutePlanResult } from 'site-operator';
8
10
  import { RefObject } from 'react';
9
11
 
10
- export declare const AgentChat: default_2.ForwardRefExoticComponent<AgentChatProps & default_2.RefAttributes<AgentChat_2 | null>>;
12
+ export declare const AgentChat: default_2.ForwardRefExoticComponent<AgentChatProps & default_2.RefAttributes<AgentChat_2>>;
13
+
14
+ export declare const AgentChatMount: default_2.FC<AgentChatMountProps>;
15
+
16
+ export declare type AgentChatMountProps = default_2.HTMLAttributes<HTMLDivElement>;
11
17
 
12
18
  export declare interface AgentChatProps {
13
19
  backendUrl?: string;
@@ -23,6 +29,15 @@ export declare interface AgentChatProps {
23
29
  context?: ContextProps;
24
30
  }
25
31
 
32
+ export declare const AgentChatProvider: default_2.FC<AgentChatProviderProps>;
33
+
34
+ export declare type AgentChatProviderProps = AgentChatProps & {
35
+ children?: default_2.ReactNode;
36
+ handlers?: {
37
+ executePlan?: (plan: Action) => Promise<ExecutePlanResult>;
38
+ };
39
+ };
40
+
26
41
  export { AgentState }
27
42
 
28
43
  export { AppContext }
@@ -50,17 +65,24 @@ export declare interface ThreadViewProps {
50
65
  emptyText?: string;
51
66
  }
52
67
 
68
+ export declare function useAgentChatController(): ChatController | null;
69
+
53
70
  /**
54
71
  * A hook to register a Chat Portal specification for the agent.
55
72
  * This allows the agent to navigate and control the host application.
56
73
  * @param context The AppContext defining site, user and navigation.
57
- * @param options Optional refs for accessing the AgentChat controller.
74
+ * If null/undefined, registration is skipped.
75
+ * @param options Optional refs for accessing the AgentChat controller and custom handlers.
58
76
  * @returns ChatController instance if an AgentChat ref is provided.
59
77
  */
60
- export declare function useChatPortal(context: AppContext, options?: UseChatPortalOptions): ChatController | null;
78
+ export declare function useChatPortal(context: AppContext | null | undefined, options?: UseChatPortalOptions & {
79
+ handlers?: {
80
+ executePlan?: (plan: Action) => Promise<ExecutePlanResult>;
81
+ };
82
+ }): ChatController | null;
61
83
 
62
84
  export declare type UseChatPortalOptions = {
63
- chatRef?: RefObject<AgentChat_2>;
85
+ chatRef?: RefObject<AgentChat_2 | null>;
64
86
  };
65
87
 
66
88
  export { }
@@ -1,6 +1,7 @@
1
- import W, { useRef as re, useImperativeHandle as te, useEffect as y, useState as ae } from "react";
2
- import { chatPortalService as ne } from "site-operator";
3
- var A = { exports: {} }, p = {};
1
+ import q, { useRef as N, useImperativeHandle as ce, useEffect as A, useState as J, createContext as V, useContext as z } from "react";
2
+ import { chatPortalService as ie } from "site-operator";
3
+ import { createPortal as fe } from "react-dom";
4
+ var C = { exports: {} }, b = {};
4
5
  /**
5
6
  * @license React
6
7
  * react-jsx-runtime.production.js
@@ -10,29 +11,29 @@ var A = { exports: {} }, p = {};
10
11
  * This source code is licensed under the MIT license found in the
11
12
  * LICENSE file in the root directory of this source tree.
12
13
  */
13
- var D;
14
- function le() {
15
- if (D) return p;
16
- D = 1;
17
- var c = Symbol.for("react.transitional.element"), i = Symbol.for("react.fragment");
18
- function m(f, a, u) {
19
- var d = null;
20
- if (u !== void 0 && (d = "" + u), a.key !== void 0 && (d = "" + a.key), "key" in a) {
21
- u = {};
22
- for (var s in a)
23
- s !== "key" && (u[s] = a[s]);
24
- } else u = a;
25
- return a = u.ref, {
26
- $$typeof: c,
27
- type: f,
28
- key: d,
29
- ref: a !== void 0 ? a : null,
30
- props: u
14
+ var L;
15
+ function de() {
16
+ if (L) return b;
17
+ L = 1;
18
+ var o = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
19
+ function i(d, n, s) {
20
+ var m = null;
21
+ if (s !== void 0 && (m = "" + s), n.key !== void 0 && (m = "" + n.key), "key" in n) {
22
+ s = {};
23
+ for (var f in n)
24
+ f !== "key" && (s[f] = n[f]);
25
+ } else s = n;
26
+ return n = s.ref, {
27
+ $$typeof: o,
28
+ type: d,
29
+ key: m,
30
+ ref: n !== void 0 ? n : null,
31
+ props: s
31
32
  };
32
33
  }
33
- return p.Fragment = i, p.jsx = m, p.jsxs = m, p;
34
+ return b.Fragment = t, b.jsx = i, b.jsxs = i, b;
34
35
  }
35
- var b = {};
36
+ var T = {};
36
37
  /**
37
38
  * @license React
38
39
  * react-jsx-runtime.development.js
@@ -42,126 +43,126 @@ var b = {};
42
43
  * This source code is licensed under the MIT license found in the
43
44
  * LICENSE file in the root directory of this source tree.
44
45
  */
45
- var L;
46
- function oe() {
47
- return L || (L = 1, process.env.NODE_ENV !== "production" && (function() {
48
- function c(e) {
46
+ var W;
47
+ function me() {
48
+ return W || (W = 1, process.env.NODE_ENV !== "production" && (function() {
49
+ function o(e) {
49
50
  if (e == null) return null;
50
51
  if (typeof e == "function")
51
- return e.$$typeof === Q ? null : e.displayName || e.name || null;
52
+ return e.$$typeof === ue ? null : e.displayName || e.name || null;
52
53
  if (typeof e == "string") return e;
53
54
  switch (e) {
54
- case O:
55
+ case g:
55
56
  return "Fragment";
56
- case J:
57
+ case Q:
57
58
  return "Profiler";
58
- case q:
59
+ case Z:
59
60
  return "StrictMode";
60
- case X:
61
+ case te:
61
62
  return "Suspense";
62
- case H:
63
+ case ne:
63
64
  return "SuspenseList";
64
- case Z:
65
+ case le:
65
66
  return "Activity";
66
67
  }
67
68
  if (typeof e == "object")
68
69
  switch (typeof e.tag == "number" && console.error(
69
70
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
70
71
  ), e.$$typeof) {
71
- case U:
72
+ case B:
72
73
  return "Portal";
73
- case z:
74
+ case ee:
74
75
  return e.displayName || "Context";
75
- case V:
76
+ case K:
76
77
  return (e._context.displayName || "Context") + ".Consumer";
77
- case G:
78
+ case re:
78
79
  var r = e.render;
79
80
  return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
80
- case B:
81
- return r = e.displayName || null, r !== null ? r : c(e.type) || "Memo";
82
- case P:
81
+ case ae:
82
+ return r = e.displayName || null, r !== null ? r : o(e.type) || "Memo";
83
+ case h:
83
84
  r = e._payload, e = e._init;
84
85
  try {
85
- return c(e(r));
86
+ return o(e(r));
86
87
  } catch {
87
88
  }
88
89
  }
89
90
  return null;
90
91
  }
91
- function i(e) {
92
+ function t(e) {
92
93
  return "" + e;
93
94
  }
94
- function m(e) {
95
+ function i(e) {
95
96
  try {
96
- i(e);
97
+ t(e);
97
98
  var r = !1;
98
99
  } catch {
99
100
  r = !0;
100
101
  }
101
102
  if (r) {
102
103
  r = console;
103
- var t = r.error, n = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
104
- return t.call(
104
+ var a = r.error, l = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
105
+ return a.call(
105
106
  r,
106
107
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
107
- n
108
- ), i(e);
108
+ l
109
+ ), t(e);
109
110
  }
110
111
  }
111
- function f(e) {
112
- if (e === O) return "<>";
113
- if (typeof e == "object" && e !== null && e.$$typeof === P)
112
+ function d(e) {
113
+ if (e === g) return "<>";
114
+ if (typeof e == "object" && e !== null && e.$$typeof === h)
114
115
  return "<...>";
115
116
  try {
116
- var r = c(e);
117
+ var r = o(e);
117
118
  return r ? "<" + r + ">" : "<...>";
118
119
  } catch {
119
120
  return "<...>";
120
121
  }
121
122
  }
122
- function a() {
123
- var e = g.A;
123
+ function n() {
124
+ var e = y.A;
124
125
  return e === null ? null : e.getOwner();
125
126
  }
126
- function u() {
127
+ function s() {
127
128
  return Error("react-stack-top-frame");
128
129
  }
129
- function d(e) {
130
- if (N.call(e, "key")) {
130
+ function m(e) {
131
+ if (Y.call(e, "key")) {
131
132
  var r = Object.getOwnPropertyDescriptor(e, "key").get;
132
133
  if (r && r.isReactWarning) return !1;
133
134
  }
134
135
  return e.key !== void 0;
135
136
  }
136
- function s(e, r) {
137
- function t() {
138
- x || (x = !0, console.error(
137
+ function f(e, r) {
138
+ function a() {
139
+ $ || ($ = !0, console.error(
139
140
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
140
141
  r
141
142
  ));
142
143
  }
143
- t.isReactWarning = !0, Object.defineProperty(e, "key", {
144
- get: t,
144
+ a.isReactWarning = !0, Object.defineProperty(e, "key", {
145
+ get: a,
145
146
  configurable: !0
146
147
  });
147
148
  }
148
- function v() {
149
- var e = c(this.type);
150
- return Y[e] || (Y[e] = !0, console.error(
149
+ function R() {
150
+ var e = o(this.type);
151
+ return I[e] || (I[e] = !0, console.error(
151
152
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
152
153
  )), e = this.props.ref, e !== void 0 ? e : null;
153
154
  }
154
- function _(e, r, t, n, S, j) {
155
- var l = t.ref;
155
+ function v(e, r, a, l, S, j) {
156
+ var u = a.ref;
156
157
  return e = {
157
- $$typeof: C,
158
+ $$typeof: x,
158
159
  type: e,
159
160
  key: r,
160
- props: t,
161
- _owner: n
162
- }, (l !== void 0 ? l : null) !== null ? Object.defineProperty(e, "ref", {
161
+ props: a,
162
+ _owner: l
163
+ }, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
163
164
  enumerable: !1,
164
- get: v
165
+ get: R
165
166
  }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
166
167
  configurable: !1,
167
168
  enumerable: !1,
@@ -184,159 +185,186 @@ function oe() {
184
185
  value: j
185
186
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
186
187
  }
187
- function o(e, r, t, n, S, j) {
188
- var l = r.children;
189
- if (l !== void 0)
190
- if (n)
191
- if (K(l)) {
192
- for (n = 0; n < l.length; n++)
193
- T(l[n]);
194
- Object.freeze && Object.freeze(l);
188
+ function c(e, r, a, l, S, j) {
189
+ var u = r.children;
190
+ if (u !== void 0)
191
+ if (l)
192
+ if (oe(u)) {
193
+ for (l = 0; l < u.length; l++)
194
+ k(u[l]);
195
+ Object.freeze && Object.freeze(u);
195
196
  } else
196
197
  console.error(
197
198
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
198
199
  );
199
- else T(l);
200
- if (N.call(r, "key")) {
201
- l = c(e);
202
- var R = Object.keys(r).filter(function(ee) {
203
- return ee !== "key";
200
+ else k(u);
201
+ if (Y.call(r, "key")) {
202
+ u = o(e);
203
+ var _ = Object.keys(r).filter(function(se) {
204
+ return se !== "key";
204
205
  });
205
- n = 0 < R.length ? "{key: someKey, " + R.join(": ..., ") + ": ...}" : "{key: someKey}", F[l + n] || (R = 0 < R.length ? "{" + R.join(": ..., ") + ": ...}" : "{}", console.error(
206
+ l = 0 < _.length ? "{key: someKey, " + _.join(": ..., ") + ": ...}" : "{key: someKey}", D[u + l] || (_ = 0 < _.length ? "{" + _.join(": ..., ") + ": ...}" : "{}", console.error(
206
207
  `A props object containing a "key" prop is being spread into JSX:
207
208
  let props = %s;
208
209
  <%s {...props} />
209
210
  React keys must be passed directly to JSX without using spread:
210
211
  let props = %s;
211
212
  <%s key={someKey} {...props} />`,
212
- n,
213
213
  l,
214
- R,
215
- l
216
- ), F[l + n] = !0);
214
+ u,
215
+ _,
216
+ u
217
+ ), D[u + l] = !0);
217
218
  }
218
- if (l = null, t !== void 0 && (m(t), l = "" + t), d(r) && (m(r.key), l = "" + r.key), "key" in r) {
219
- t = {};
220
- for (var h in r)
221
- h !== "key" && (t[h] = r[h]);
222
- } else t = r;
223
- return l && s(
224
- t,
219
+ if (u = null, a !== void 0 && (i(a), u = "" + a), m(r) && (i(r.key), u = "" + r.key), "key" in r) {
220
+ a = {};
221
+ for (var w in r)
222
+ w !== "key" && (a[w] = r[w]);
223
+ } else a = r;
224
+ return u && f(
225
+ a,
225
226
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
226
- ), _(
227
+ ), v(
227
228
  e,
228
- l,
229
- t,
230
- a(),
229
+ u,
230
+ a,
231
+ n(),
231
232
  S,
232
233
  j
233
234
  );
234
235
  }
235
- function T(e) {
236
- E(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === P && (e._payload.status === "fulfilled" ? E(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
236
+ function k(e) {
237
+ E(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === h && (e._payload.status === "fulfilled" ? E(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
237
238
  }
238
239
  function E(e) {
239
- return typeof e == "object" && e !== null && e.$$typeof === C;
240
+ return typeof e == "object" && e !== null && e.$$typeof === x;
240
241
  }
241
- var k = W, C = Symbol.for("react.transitional.element"), U = Symbol.for("react.portal"), O = Symbol.for("react.fragment"), q = Symbol.for("react.strict_mode"), J = Symbol.for("react.profiler"), V = Symbol.for("react.consumer"), z = Symbol.for("react.context"), G = Symbol.for("react.forward_ref"), X = Symbol.for("react.suspense"), H = Symbol.for("react.suspense_list"), B = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), Z = Symbol.for("react.activity"), Q = Symbol.for("react.client.reference"), g = k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, N = Object.prototype.hasOwnProperty, K = Array.isArray, w = console.createTask ? console.createTask : function() {
242
+ var P = q, x = Symbol.for("react.transitional.element"), B = Symbol.for("react.portal"), g = Symbol.for("react.fragment"), Z = Symbol.for("react.strict_mode"), Q = Symbol.for("react.profiler"), K = Symbol.for("react.consumer"), ee = Symbol.for("react.context"), re = Symbol.for("react.forward_ref"), te = Symbol.for("react.suspense"), ne = Symbol.for("react.suspense_list"), ae = Symbol.for("react.memo"), h = Symbol.for("react.lazy"), le = Symbol.for("react.activity"), ue = Symbol.for("react.client.reference"), y = P.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Y = Object.prototype.hasOwnProperty, oe = Array.isArray, O = console.createTask ? console.createTask : function() {
242
243
  return null;
243
244
  };
244
- k = {
245
+ P = {
245
246
  react_stack_bottom_frame: function(e) {
246
247
  return e();
247
248
  }
248
249
  };
249
- var x, Y = {}, $ = k.react_stack_bottom_frame.bind(
250
- k,
251
- u
252
- )(), I = w(f(u)), F = {};
253
- b.Fragment = O, b.jsx = function(e, r, t) {
254
- var n = 1e4 > g.recentlyCreatedOwnerStacks++;
255
- return o(
250
+ var $, I = {}, M = P.react_stack_bottom_frame.bind(
251
+ P,
252
+ s
253
+ )(), F = O(d(s)), D = {};
254
+ T.Fragment = g, T.jsx = function(e, r, a) {
255
+ var l = 1e4 > y.recentlyCreatedOwnerStacks++;
256
+ return c(
256
257
  e,
257
258
  r,
258
- t,
259
+ a,
259
260
  !1,
260
- n ? Error("react-stack-top-frame") : $,
261
- n ? w(f(e)) : I
261
+ l ? Error("react-stack-top-frame") : M,
262
+ l ? O(d(e)) : F
262
263
  );
263
- }, b.jsxs = function(e, r, t) {
264
- var n = 1e4 > g.recentlyCreatedOwnerStacks++;
265
- return o(
264
+ }, T.jsxs = function(e, r, a) {
265
+ var l = 1e4 > y.recentlyCreatedOwnerStacks++;
266
+ return c(
266
267
  e,
267
268
  r,
268
- t,
269
+ a,
269
270
  !0,
270
- n ? Error("react-stack-top-frame") : $,
271
- n ? w(f(e)) : I
271
+ l ? Error("react-stack-top-frame") : M,
272
+ l ? O(d(e)) : F
272
273
  );
273
274
  };
274
- })()), b;
275
+ })()), T;
275
276
  }
276
- var M;
277
- function ue() {
278
- return M || (M = 1, process.env.NODE_ENV === "production" ? A.exports = le() : A.exports = oe()), A.exports;
277
+ var U;
278
+ function Ee() {
279
+ return U || (U = 1, process.env.NODE_ENV === "production" ? C.exports = de() : C.exports = me()), C.exports;
279
280
  }
280
- var se = ue();
281
- const ie = W.forwardRef(({
282
- backendUrl: c,
283
- conversationUrl: i,
284
- appName: m,
285
- agentAvatar: f,
286
- inspector: a,
287
- interceptor: u,
288
- className: d,
289
- composer: s,
290
- thread: v,
291
- header: _,
292
- context: o
293
- }, T) => {
294
- const E = re(null);
295
- return te(T, () => E.current), y(() => {
296
- E.current && (o != null && o.appContext) && E.current.setAppContext(o.appContext);
297
- }, [o == null ? void 0 : o.appContext]), y(() => {
298
- E.current && (o != null && o.appState) && E.current.setAppState(o.appState);
299
- }, [o == null ? void 0 : o.appState]), /* @__PURE__ */ se.jsx(
281
+ var p = Ee();
282
+ const G = q.forwardRef(({
283
+ backendUrl: o,
284
+ conversationUrl: t,
285
+ appName: i,
286
+ agentAvatar: d,
287
+ inspector: n,
288
+ interceptor: s,
289
+ className: m,
290
+ composer: f,
291
+ thread: R,
292
+ header: v,
293
+ context: c
294
+ }, k) => {
295
+ const E = N(null);
296
+ return ce(k, () => E.current), A(() => {
297
+ E.current && (c != null && c.appContext) && E.current.setAppContext(c.appContext);
298
+ }, [c == null ? void 0 : c.appContext]), A(() => {
299
+ E.current && (c != null && c.appState) && E.current.setAppState(c.appState);
300
+ }, [c == null ? void 0 : c.appState]), /* @__PURE__ */ p.jsx(
300
301
  "agent-chat",
301
302
  {
302
303
  ref: E,
303
- backendUrl: c,
304
- conversationUrl: i,
305
- appName: m,
306
- agentAvatar: f,
307
- disclaimer: s == null ? void 0 : s.disclaimer,
308
- placeholder: s == null ? void 0 : s.placeholder,
309
- emptyText: v == null ? void 0 : v.emptyText,
310
- headerTitle: _ == null ? void 0 : _.title,
311
- hideHeader: _ == null ? void 0 : _.hide,
312
- inspector: a ? "true" : void 0,
313
- interceptor: u ? !0 : void 0,
314
- class: d
304
+ backendUrl: o,
305
+ conversationUrl: t,
306
+ appName: i,
307
+ agentAvatar: d,
308
+ disclaimer: f == null ? void 0 : f.disclaimer,
309
+ placeholder: f == null ? void 0 : f.placeholder,
310
+ emptyText: R == null ? void 0 : R.emptyText,
311
+ headerTitle: v == null ? void 0 : v.title,
312
+ hideHeader: v == null ? void 0 : v.hide,
313
+ inspector: n ? "true" : void 0,
314
+ interceptor: s ? !0 : void 0,
315
+ class: m
315
316
  }
316
317
  );
317
318
  });
318
- ie.displayName = "AgentChat";
319
- function de(c, i) {
320
- const [m, f] = ae(null);
321
- return y(() => {
322
- ne.registerPortal(c);
323
- }, [c]), y(() => {
324
- var d;
325
- const a = (d = i == null ? void 0 : i.chatRef) == null ? void 0 : d.current;
326
- if (!a) return;
327
- if (a.controller) {
328
- f(a.controller);
319
+ G.displayName = "AgentChat";
320
+ function ve(o, t) {
321
+ const [i, d] = J(null);
322
+ return A(() => {
323
+ o && ie.registerPortal(o, t == null ? void 0 : t.handlers);
324
+ }, [o, t == null ? void 0 : t.handlers]), A(() => {
325
+ var m;
326
+ const n = (m = t == null ? void 0 : t.chatRef) == null ? void 0 : m.current;
327
+ if (!n) return;
328
+ if (n.controller) {
329
+ d(n.controller);
329
330
  return;
330
331
  }
331
- const u = (s) => {
332
- f(s.detail ?? null);
332
+ const s = (f) => {
333
+ d(f.detail ?? null);
333
334
  };
334
- return a.addEventListener("controller-ready", u), () => {
335
- a.removeEventListener("controller-ready", u);
335
+ return n.addEventListener("controller-ready", s), () => {
336
+ n.removeEventListener("controller-ready", s);
336
337
  };
337
- }, [i == null ? void 0 : i.chatRef]), m;
338
+ }, [t == null ? void 0 : t.chatRef]), i;
338
339
  }
340
+ const X = V(null), H = V(null);
341
+ function Te() {
342
+ return z(X);
343
+ }
344
+ const pe = ({ children: o, ...t }) => {
345
+ const i = z(H), d = N(null);
346
+ return A(() => {
347
+ if (i)
348
+ return i(d.current), () => {
349
+ i(null);
350
+ };
351
+ }, [i]), /* @__PURE__ */ p.jsx("div", { ref: d, ...t, children: o });
352
+ }, Ae = ({
353
+ children: o,
354
+ context: t,
355
+ handlers: i,
356
+ ...d
357
+ }) => {
358
+ const n = N(null), s = ve(t == null ? void 0 : t.appContext, { chatRef: n, handlers: i }), [m, f] = J(null);
359
+ return /* @__PURE__ */ p.jsx(X.Provider, { value: s, children: /* @__PURE__ */ p.jsxs(H.Provider, { value: f, children: [
360
+ o,
361
+ m ? fe(/* @__PURE__ */ p.jsx(G, { ref: n, context: t, ...d }), m) : null
362
+ ] }) });
363
+ };
339
364
  export {
340
- ie as AgentChat,
341
- de as useChatPortal
365
+ G as AgentChat,
366
+ pe as AgentChatMount,
367
+ Ae as AgentChatProvider,
368
+ Te as useAgentChatController,
369
+ ve as useChatPortal
342
370
  };
@@ -1,4 +1,4 @@
1
- (function(m,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react"),require("site-operator")):typeof define=="function"&&define.amd?define(["exports","react","site-operator"],i):(m=typeof globalThis<"u"?globalThis:m||self,i(m.SiteOperatorReact={},m.React,m.SiteOperator))})(this,(function(m,i,V){"use strict";var k={exports:{}},b={};/**
1
+ (function(E,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("react"),require("site-operator"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","site-operator","react-dom"],l):(E=typeof globalThis<"u"?globalThis:E||self,l(E.SiteOperatorReact={},E.React,E.SiteOperator,E.ReactDOM))})(this,(function(E,l,H,B){"use strict";var h={exports:{}},b={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var N;function z(){if(N)return b;N=1;var f=Symbol.for("react.transitional.element"),c=Symbol.for("react.fragment");function _(d,a,u){var E=null;if(u!==void 0&&(E=""+u),a.key!==void 0&&(E=""+a.key),"key"in a){u={};for(var s in a)s!=="key"&&(u[s]=a[s])}else u=a;return a=u.ref,{$$typeof:f,type:d,key:E,ref:a!==void 0?a:null,props:u}}return b.Fragment=c,b.jsx=_,b.jsxs=_,b}var T={};/**
9
+ */var Y;function Z(){if(Y)return b;Y=1;var s=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function i(m,n,c){var v=null;if(c!==void 0&&(v=""+c),n.key!==void 0&&(v=""+n.key),"key"in n){c={};for(var d in n)d!=="key"&&(c[d]=n[d])}else c=n;return n=c.ref,{$$typeof:s,type:m,key:v,ref:n!==void 0?n:null,props:c}}return b.Fragment=t,b.jsx=i,b.jsxs=i,b}var p={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,9 +14,9 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var x;function G(){return x||(x=1,process.env.NODE_ENV!=="production"&&(function(){function f(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===oe?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case P:return"Fragment";case Q:return"Profiler";case q:return"StrictMode";case re:return"Suspense";case te:return"SuspenseList";case ne:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case Z:return"Portal";case K:return e.displayName||"Context";case $:return(e._context.displayName||"Context")+".Consumer";case ee:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ae:return r=e.displayName||null,r!==null?r:f(e.type)||"Memo";case g:r=e._payload,e=e._init;try{return f(e(r))}catch{}}return null}function c(e){return""+e}function _(e){try{c(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,n=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",n),c(e)}}function d(e){if(e===P)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===g)return"<...>";try{var r=f(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function a(){var e=h.A;return e===null?null:e.getOwner()}function u(){return Error("react-stack-top-frame")}function E(e){if(D.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function s(e,r){function t(){L||(L=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}function S(){var e=f(this.type);return M[e]||(M[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function R(e,r,t,n,O,w){var o=t.ref;return e={$$typeof:F,type:e,key:r,props:t,_owner:n},(o!==void 0?o:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:S}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:O}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:w}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function l(e,r,t,n,O,w){var o=r.children;if(o!==void 0)if(n)if(le(o)){for(n=0;n<o.length;n++)y(o[n]);Object.freeze&&Object.freeze(o)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else y(o);if(D.call(r,"key")){o=f(e);var v=Object.keys(r).filter(function(ue){return ue!=="key"});n=0<v.length?"{key: someKey, "+v.join(": ..., ")+": ...}":"{key: someKey}",J[o+n]||(v=0<v.length?"{"+v.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var M;function Q(){return M||(M=1,process.env.NODE_ENV!=="production"&&(function(){function s(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ie?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case O:return"Fragment";case ne:return"Profiler";case te:return"StrictMode";case ue:return"Suspense";case se:return"SuspenseList";case fe:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case re:return"Portal";case le:return e.displayName||"Context";case ae:return(e._context.displayName||"Context")+".Consumer";case oe:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ce:return r=e.displayName||null,r!==null?r:s(e.type)||"Memo";case g:r=e._payload,e=e._init;try{return s(e(r))}catch{}}return null}function t(e){return""+e}function i(e){try{t(e);var r=!1}catch{r=!0}if(r){r=console;var a=r.error,o=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return a.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),t(e)}}function m(e){if(e===O)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===g)return"<...>";try{var r=s(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function n(){var e=j.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function v(e){if(U.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function d(e,r){function a(){J||(J=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}a.isReactWarning=!0,Object.defineProperty(e,"key",{get:a,configurable:!0})}function C(){var e=s(this.type);return V[e]||(V[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function _(e,r,a,o,k,N){var u=a.ref;return e={$$typeof:W,type:e,key:r,props:a,_owner:o},(u!==void 0?u:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:C}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:k}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:N}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function f(e,r,a,o,k,N){var u=r.children;if(u!==void 0)if(o)if(de(u)){for(o=0;o<u.length;o++)S(u[o]);Object.freeze&&Object.freeze(u)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else S(u);if(U.call(r,"key")){u=s(e);var T=Object.keys(r).filter(function(me){return me!=="key"});o=0<T.length?"{key: someKey, "+T.join(": ..., ")+": ...}":"{key: someKey}",X[u+o]||(T=0<T.length?"{"+T.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
18
  let props = %s;
19
19
  <%s {...props} />
20
20
  React keys must be passed directly to JSX without using spread:
21
21
  let props = %s;
22
- <%s key={someKey} {...props} />`,n,o,v,o),J[o+n]=!0)}if(o=null,t!==void 0&&(_(t),o=""+t),E(r)&&(_(r.key),o=""+r.key),"key"in r){t={};for(var C in r)C!=="key"&&(t[C]=r[C])}else t=r;return o&&s(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,o,t,a(),O,w)}function y(e){p(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===g&&(e._payload.status==="fulfilled"?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e=="object"&&e!==null&&e.$$typeof===F}var A=i,F=Symbol.for("react.transitional.element"),Z=Symbol.for("react.portal"),P=Symbol.for("react.fragment"),q=Symbol.for("react.strict_mode"),Q=Symbol.for("react.profiler"),$=Symbol.for("react.consumer"),K=Symbol.for("react.context"),ee=Symbol.for("react.forward_ref"),re=Symbol.for("react.suspense"),te=Symbol.for("react.suspense_list"),ae=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),ne=Symbol.for("react.activity"),oe=Symbol.for("react.client.reference"),h=A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,D=Object.prototype.hasOwnProperty,le=Array.isArray,j=console.createTask?console.createTask:function(){return null};A={react_stack_bottom_frame:function(e){return e()}};var L,M={},W=A.react_stack_bottom_frame.bind(A,u)(),U=j(d(u)),J={};T.Fragment=P,T.jsx=function(e,r,t){var n=1e4>h.recentlyCreatedOwnerStacks++;return l(e,r,t,!1,n?Error("react-stack-top-frame"):W,n?j(d(e)):U)},T.jsxs=function(e,r,t){var n=1e4>h.recentlyCreatedOwnerStacks++;return l(e,r,t,!0,n?Error("react-stack-top-frame"):W,n?j(d(e)):U)}})()),T}var Y;function X(){return Y||(Y=1,process.env.NODE_ENV==="production"?k.exports=z():k.exports=G()),k.exports}var H=X();const I=i.forwardRef(({backendUrl:f,conversationUrl:c,appName:_,agentAvatar:d,inspector:a,interceptor:u,className:E,composer:s,thread:S,header:R,context:l},y)=>{const p=i.useRef(null);return i.useImperativeHandle(y,()=>p.current),i.useEffect(()=>{p.current&&(l!=null&&l.appContext)&&p.current.setAppContext(l.appContext)},[l==null?void 0:l.appContext]),i.useEffect(()=>{p.current&&(l!=null&&l.appState)&&p.current.setAppState(l.appState)},[l==null?void 0:l.appState]),H.jsx("agent-chat",{ref:p,backendUrl:f,conversationUrl:c,appName:_,agentAvatar:d,disclaimer:s==null?void 0:s.disclaimer,placeholder:s==null?void 0:s.placeholder,emptyText:S==null?void 0:S.emptyText,headerTitle:R==null?void 0:R.title,hideHeader:R==null?void 0:R.hide,inspector:a?"true":void 0,interceptor:u?!0:void 0,class:E})});I.displayName="AgentChat";function B(f,c){const[_,d]=i.useState(null);return i.useEffect(()=>{V.chatPortalService.registerPortal(f)},[f]),i.useEffect(()=>{var E;const a=(E=c==null?void 0:c.chatRef)==null?void 0:E.current;if(!a)return;if(a.controller){d(a.controller);return}const u=s=>{d(s.detail??null)};return a.addEventListener("controller-ready",u),()=>{a.removeEventListener("controller-ready",u)}},[c==null?void 0:c.chatRef]),_}m.AgentChat=I,m.useChatPortal=B,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
22
+ <%s key={someKey} {...props} />`,o,u,T,u),X[u+o]=!0)}if(u=null,a!==void 0&&(i(a),u=""+a),v(r)&&(i(r.key),u=""+r.key),"key"in r){a={};for(var x in r)x!=="key"&&(a[x]=r[x])}else a=r;return u&&d(a,typeof e=="function"?e.displayName||e.name||"Unknown":e),_(e,u,a,n(),k,N)}function S(e){R(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===g&&(e._payload.status==="fulfilled"?R(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function R(e){return typeof e=="object"&&e!==null&&e.$$typeof===W}var P=l,W=Symbol.for("react.transitional.element"),re=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),te=Symbol.for("react.strict_mode"),ne=Symbol.for("react.profiler"),ae=Symbol.for("react.consumer"),le=Symbol.for("react.context"),oe=Symbol.for("react.forward_ref"),ue=Symbol.for("react.suspense"),se=Symbol.for("react.suspense_list"),ce=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),fe=Symbol.for("react.activity"),ie=Symbol.for("react.client.reference"),j=P.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,U=Object.prototype.hasOwnProperty,de=Array.isArray,w=console.createTask?console.createTask:function(){return null};P={react_stack_bottom_frame:function(e){return e()}};var J,V={},z=P.react_stack_bottom_frame.bind(P,c)(),G=w(m(c)),X={};p.Fragment=O,p.jsx=function(e,r,a){var o=1e4>j.recentlyCreatedOwnerStacks++;return f(e,r,a,!1,o?Error("react-stack-top-frame"):z,o?w(m(e)):G)},p.jsxs=function(e,r,a){var o=1e4>j.recentlyCreatedOwnerStacks++;return f(e,r,a,!0,o?Error("react-stack-top-frame"):z,o?w(m(e)):G)}})()),p}var I;function K(){return I||(I=1,process.env.NODE_ENV==="production"?h.exports=Z():h.exports=Q()),h.exports}var A=K();const y=l.forwardRef(({backendUrl:s,conversationUrl:t,appName:i,agentAvatar:m,inspector:n,interceptor:c,className:v,composer:d,thread:C,header:_,context:f},S)=>{const R=l.useRef(null);return l.useImperativeHandle(S,()=>R.current),l.useEffect(()=>{R.current&&(f!=null&&f.appContext)&&R.current.setAppContext(f.appContext)},[f==null?void 0:f.appContext]),l.useEffect(()=>{R.current&&(f!=null&&f.appState)&&R.current.setAppState(f.appState)},[f==null?void 0:f.appState]),A.jsx("agent-chat",{ref:R,backendUrl:s,conversationUrl:t,appName:i,agentAvatar:m,disclaimer:d==null?void 0:d.disclaimer,placeholder:d==null?void 0:d.placeholder,emptyText:C==null?void 0:C.emptyText,headerTitle:_==null?void 0:_.title,hideHeader:_==null?void 0:_.hide,inspector:n?"true":void 0,interceptor:c?!0:void 0,class:v})});y.displayName="AgentChat";function D(s,t){const[i,m]=l.useState(null);return l.useEffect(()=>{s&&H.chatPortalService.registerPortal(s,t==null?void 0:t.handlers)},[s,t==null?void 0:t.handlers]),l.useEffect(()=>{var v;const n=(v=t==null?void 0:t.chatRef)==null?void 0:v.current;if(!n)return;if(n.controller){m(n.controller);return}const c=d=>{m(d.detail??null)};return n.addEventListener("controller-ready",c),()=>{n.removeEventListener("controller-ready",c)}},[t==null?void 0:t.chatRef]),i}const F=l.createContext(null),L=l.createContext(null);function q(){return l.useContext(F)}const $=({children:s,...t})=>{const i=l.useContext(L),m=l.useRef(null);return l.useEffect(()=>{if(i)return i(m.current),()=>{i(null)}},[i]),A.jsx("div",{ref:m,...t,children:s})},ee=({children:s,context:t,handlers:i,...m})=>{const n=l.useRef(null),c=D(t==null?void 0:t.appContext,{chatRef:n,handlers:i}),[v,d]=l.useState(null);return A.jsx(F.Provider,{value:c,children:A.jsxs(L.Provider,{value:d,children:[s,v?B.createPortal(A.jsx(y,{ref:n,context:t,...m}),v):null]})})};E.AgentChat=y,E.AgentChatMount=$,E.AgentChatProvider=ee,E.useAgentChatController=q,E.useChatPortal=D,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "site-operator-react",
3
- "version": "0.2.1",
3
+ "version": "0.2.4",
4
4
  "description": "React wrapper for site-operator, providing AgentChat component and hooks.",
5
5
  "type": "module",
6
6
  "author": "jostvian",
@@ -32,7 +32,7 @@
32
32
  "dev": "vite build --watch"
33
33
  },
34
34
  "dependencies": {
35
- "site-operator": "^0.1.14"
35
+ "site-operator": "^0.2.4"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "react": "^19.0.0",
@@ -47,4 +47,4 @@
47
47
  "vite": "^6.0.0",
48
48
  "vite-plugin-dts": "^4.5.0"
49
49
  }
50
- }
50
+ }