@kieksme/csp-plugin-chat 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,3 +21,5 @@ Der Assistent unterscheidet das Unternehmen von seinem Serviceportal: „Service
21
21
  Der System-Prompt begrenzt den Chat auf Support und Portalbedienung. Fachfremde Aufgaben werden kurz zum Support-Zweck zurückgeführt; unklare Anliegen werden durch eine Rückfrage eingeordnet.
22
22
 
23
23
  Optional persisted conversations and real human support are available through the Teams plugin. The UI uses `chatSupport` from the public profile and identifies real support separately from the digital assistant. See [Teams support](../../docs/teams-support.md).
24
+
25
+ For portals with an existing same-origin authenticated gateway, set `chatSupport.auth` to `session` to reuse the login without browser tokens. The API still requires a validated delegated access token supplied by the internal gateway. See [Teams support](../../docs/teams-support.md#vorhandene-portal-anmeldung-verwenden).
package/dist/browser.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  cspPlugin
3
- } from "./chunk-ALGUQ3T5.js";
3
+ } from "./chunk-NHJR47VI.js";
4
4
 
5
5
  // src/browser.tsx
6
6
  import { useEffect as useEffect2, useLayoutEffect, useRef as useRef2, useState as useState2 } from "react";
@@ -35,8 +35,9 @@ function answerParts(text, sources, streaming = false) {
35
35
 
36
36
  // src/support-chat.tsx
37
37
  import { useEffect, useRef, useState } from "react";
38
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
39
- async function session(ctx) {
38
+
39
+ // src/support-session.ts
40
+ async function supportSession(ctx) {
40
41
  const c = ctx.config.chatSupport;
41
42
  if (c.mode === "demo")
42
43
  return {
@@ -45,6 +46,7 @@ async function session(ctx) {
45
46
  },
46
47
  name: "Portal-Nutzer Demo"
47
48
  };
49
+ if (c.auth === "session") return cookieSession(ctx);
48
50
  const { PublicClientApplication } = await import("@azure/msal-browser");
49
51
  const client = new PublicClientApplication({
50
52
  auth: {
@@ -68,6 +70,37 @@ async function session(ctx) {
68
70
  }
69
71
  };
70
72
  }
73
+ function cookieSession(ctx) {
74
+ let loaded = false;
75
+ const current = {
76
+ name: "Portal-Nutzer",
77
+ async token() {
78
+ if (!loaded) {
79
+ const response = await (ctx.request ?? fetch)(
80
+ ctx.config.apiUrl + "/api/v1/conversations/identity",
81
+ { credentials: "same-origin", cache: "no-store" }
82
+ );
83
+ if (!response.ok)
84
+ throw new Error(
85
+ response.status === 401 ? "Bitte erneuern Sie Ihre Portal-Anmeldung." : "Portal-Anmeldung derzeit nicht verf\xFCgbar."
86
+ );
87
+ const identity = await response.json();
88
+ if (typeof identity.name !== "string" || !identity.name.trim() || identity.name.length > 200)
89
+ throw new Error("Portal-Anmeldung derzeit nicht verf\xFCgbar.");
90
+ current.name = identity.name;
91
+ loaded = true;
92
+ }
93
+ return "";
94
+ },
95
+ async login() {
96
+ window.location.reload();
97
+ }
98
+ };
99
+ return current;
100
+ }
101
+
102
+ // src/support-chat.tsx
103
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
71
104
  function SupportChat(ctx) {
72
105
  const [current, setCurrent] = useState(null), [input, setInput] = useState(""), [error, setError] = useState(""), [busy, setBusy] = useState(false), [ready, setReady] = useState(false), [auth, setAuth] = useState(null);
73
106
  const seq = useRef(0), requestRef = useRef(null);
@@ -77,7 +110,7 @@ function SupportChat(ctx) {
77
110
  const controller = new AbortController();
78
111
  async function init() {
79
112
  try {
80
- const identity = await session(ctx);
113
+ const identity = await supportSession(ctx);
81
114
  if (!alive) return;
82
115
  setAuth(identity);
83
116
  const request = async (path, init2 = {}) => {
@@ -86,6 +119,7 @@ function SupportChat(ctx) {
86
119
  ctx.config.apiUrl + "/api/v1/conversations" + path,
87
120
  {
88
121
  ...init2,
122
+ credentials: "same-origin",
89
123
  headers: {
90
124
  ...token ? { Authorization: `Bearer ${token}` } : {},
91
125
  ...init2.body !== void 0 ? { "Content-Type": "application/json" } : {},
@@ -273,7 +307,7 @@ function SupportChat(ctx) {
273
307
  onClick: () => void auth?.login().catch(
274
308
  () => setError("Microsoft-Anmeldung konnte nicht gestartet werden.")
275
309
  ),
276
- children: "Mit Microsoft anmelden"
310
+ children: ctx.config.chatSupport?.auth === "session" ? "Portal-Anmeldung erneuern" : "Mit Microsoft anmelden"
277
311
  }
278
312
  ),
279
313
  ready && /* @__PURE__ */ jsxs("form", { onSubmit: submit, className: "chat-form flex gap-2.5 items-end", children: [
@@ -362,7 +396,7 @@ function SupportChat(ctx) {
362
396
  onClick: () => void auth.login().catch(
363
397
  () => setError("Microsoft-Anmeldung konnte nicht gestartet werden.")
364
398
  ),
365
- children: "Microsoft-Anmeldung erneuern"
399
+ children: ctx.config.chatSupport?.auth === "session" ? "Portal-Anmeldung erneuern" : "Microsoft-Anmeldung erneuern"
366
400
  }
367
401
  ),
368
402
  error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-danger text-[0.75rem] mt-3", children: error })
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var cspPlugin = {
3
3
  id: "chat",
4
- sdkVersion: "^0.7.0",
4
+ sdkVersion: "^0.8.0",
5
5
  browser: "./browser",
6
6
  server: "./server"
7
7
  };
package/dist/server.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  cspPlugin
3
- } from "./chunk-ALGUQ3T5.js";
3
+ } from "./chunk-NHJR47VI.js";
4
4
 
5
5
  // src/server.ts
6
6
  import { z as z2 } from "zod";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kieksme/csp-plugin-chat",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@azure/msal-browser": "^5.25.0",
26
- "@kieksme/csp-sdk": "^0.7.0",
26
+ "@kieksme/csp-sdk": "^0.8.0",
27
27
  "openai": "^6.3.0",
28
28
  "zod": "^3.25.76"
29
29
  },
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "cspPlugin": {
37
37
  "id": "chat",
38
- "sdkVersion": "^0.7.0",
38
+ "sdkVersion": "^0.8.0",
39
39
  "browser": "./browser",
40
40
  "server": "./server"
41
41
  },