@conduction/nextcloud-vue 2.171.0 → 2.173.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/dist/esm/components/CnActionDialog/CnActionDialog.vue.js +1 -1
- package/dist/esm/components/CnActionDialog/CnActionDialog.vue2.js.map +1 -1
- package/dist/esm/components/CnActionDialog/CnActionDialog.vue3.js.map +1 -1
- package/dist/esm/components/CnAiCompanion/CnAiChatWidget.vue2.js +3 -2
- package/dist/esm/components/CnAiCompanion/CnAiChatWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnAiCompanion/CnAiChatWidget.vue3.js +2 -1
- package/dist/esm/components/CnAiCompanion/CnAiChatWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnAiCompanion/CnAiCompanion.vue2.js +39 -0
- package/dist/esm/components/CnAiCompanion/CnAiCompanion.vue2.js.map +1 -1
- package/dist/esm/components/CnAiCompanion/CnAiCompanion.vue3.js.map +1 -1
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue.js +1 -1
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue2.js +22 -3
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnDashboardGrid/CnDashboardGrid.vue.js +1 -1
- package/dist/esm/components/CnDashboardGrid/CnDashboardGrid.vue2.js.map +1 -1
- package/dist/esm/components/CnDashboardGrid/CnDashboardGrid.vue3.js.map +1 -1
- package/dist/esm/components/CnDeviceFramesWidget/CnDeviceFramesWidget.vue.js +1 -1
- package/dist/esm/components/CnDeviceFramesWidget/CnDeviceFramesWidget.vue2.js +75 -4
- package/dist/esm/components/CnDeviceFramesWidget/CnDeviceFramesWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnDeviceFramesWidget/CnDeviceFramesWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnFactsWidget/CnFactsWidget.vue.js +1 -1
- package/dist/esm/components/CnFactsWidget/CnFactsWidget.vue2.js +7 -3
- package/dist/esm/components/CnFactsWidget/CnFactsWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnFactsWidget/CnFactsWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnFilesBrowser/CnFilesBrowser.vue.js +1 -1
- package/dist/esm/components/CnFilesBrowser/CnFilesBrowser.vue2.js +34 -4
- package/dist/esm/components/CnFilesBrowser/CnFilesBrowser.vue2.js.map +1 -1
- package/dist/esm/components/CnFilesBrowser/CnFilesBrowser.vue3.js +42 -34
- package/dist/esm/components/CnFilesBrowser/CnFilesBrowser.vue3.js.map +1 -1
- package/dist/esm/components/CnFlowsPage/CnFlowBoard.vue.js +1 -1
- package/dist/esm/components/CnFlowsPage/CnFlowBoard.vue2.js +21 -6
- package/dist/esm/components/CnFlowsPage/CnFlowBoard.vue2.js.map +1 -1
- package/dist/esm/components/CnFlowsPage/CnFlowBoard.vue3.js.map +1 -1
- package/dist/esm/components/CnTreeView/CnTreeNode.vue.js +1 -1
- package/dist/esm/components/CnTreeView/CnTreeNode.vue2.js +54 -4
- package/dist/esm/components/CnTreeView/CnTreeNode.vue2.js.map +1 -1
- package/dist/esm/components/CnTreeView/CnTreeNode.vue3.js +32 -26
- package/dist/esm/components/CnTreeView/CnTreeNode.vue3.js.map +1 -1
- package/dist/esm/components/CnTreeView/CnTreeView.vue.js +1 -1
- package/dist/esm/components/CnTreeView/CnTreeView.vue2.js +28 -4
- package/dist/esm/components/CnTreeView/CnTreeView.vue2.js.map +1 -1
- package/dist/esm/components/CnTreeView/CnTreeView.vue3.js +4 -1
- package/dist/esm/components/CnTreeView/CnTreeView.vue3.js.map +1 -1
- package/dist/esm/composables/aiChatConfig.js +13 -1
- package/dist/esm/composables/aiChatConfig.js.map +1 -1
- package/dist/esm/composables/useAiChatStream.js +53 -1
- package/dist/esm/composables/useAiChatStream.js.map +1 -1
- package/dist/esm/library-style.js +1 -1
- package/dist/esm/nextcloud-vue.css +745 -403
- package/dist/esm/utils/builtInFormatters.js +19 -1
- package/dist/esm/utils/builtInFormatters.js.map +1 -1
- package/dist/nextcloud-vue.cjs.js +919 -569
- package/dist/nextcloud-vue.cjs.js.map +2 -2
- package/dist/nextcloud-vue.css +745 -403
- package/package.json +1 -1
- package/src/components/CnActionDialog/CnActionDialog.vue +4 -1
- package/src/components/CnAiCompanion/CnAiChatWidget.md +1 -0
- package/src/components/CnAiCompanion/CnAiChatWidget.vue +4 -2
- package/src/components/CnAiCompanion/CnAiCompanion.md +1 -0
- package/src/components/CnAiCompanion/CnAiCompanion.vue +39 -0
- package/src/components/CnChecklistRunWidget/CnChecklistRunWidget.vue +24 -3
- package/src/components/CnDashboardGrid/CnDashboardGrid.vue +5 -2
- package/src/components/CnDeviceFramesWidget/CnDeviceFramesWidget.vue +75 -4
- package/src/components/CnFactsWidget/CnFactsWidget.vue +7 -3
- package/src/components/CnFilesBrowser/CnFilesBrowser.vue +45 -4
- package/src/components/CnFlowsPage/CnFlowBoard.vue +27 -6
- package/src/components/CnTreeView/CnTreeNode.vue +69 -6
- package/src/components/CnTreeView/CnTreeView.vue +31 -4
- package/src/composables/aiChatConfig.js +12 -0
- package/src/composables/useAiChatStream.js +53 -0
- package/src/css/look-board-detail.css +200 -6
- package/src/css/look-board-index.css +7 -6
- package/src/css/look-board.css +118 -0
- package/src/css/patches.css +4 -1
- package/src/utils/builtInFormatters.js +18 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CnAiChatWidget.vue2.js","sources":["../../../../src/components/CnAiCompanion/CnAiChatWidget.vue"],"sourcesContent":["<!--\n - SPDX-FileCopyrightText: 2026 Conduction B.V.\n - SPDX-License-Identifier: EUPL-1.2\n-->\n\n<!--\n CnAiChatWidget — the AI Chat Companion as a widget (`type: \"ai-chat\"`), so a\n page can place the assistant in its own flow: a detail page tab, a card. It is\n the same companion as the launcher's floating window, embedded: the same\n health probe, agents, sessions and stream, always open and without the hex.\n The floating companion keeps working beside it.\n\n The host draws the widget's titled card; the widget reports a pill\n (`content.pill`, e.g. the assistant's name) and the session controls for the\n card's menu through the `header` event. `content.note` is a line above the\n input, `content.placeholder` and `content.sendLabel` word the input.\n\n The page context (record, register, schema) is the one CnAppRoot provides and\n the detail page fills in, so the agents offered are the ones relevant here.\n Renders nothing when the chat backend does not answer.\n-->\n<template>\n\t<div class=\"cn-ai-chat-widget\" data-testid=\"cn-ai-chat-widget\">\n\t\t<CnAiCompanion\n\t\t\t:embedded=\"true\"\n\t\t\t:titled=\"true\"\n\t\t\t:note=\"tr(content.note)\"\n\t\t\t:inputPlaceholder=\"tr(content.placeholder)\"\n\t\t\t:sendLabel=\"tr(content.sendLabel)\"\n\t\t\t:chatAppId=\"content.chatAppId || defaultChatAppId\"\n\t\t\t@menu=\"onMenu\" />\n\t</div>\n</template>\n\n<script>\nimport CnAiCompanion from './CnAiCompanion.vue'\nimport { DEFAULT_CHAT_APP_ID } from '../../composables/aiChatConfig.js'\n\nexport default {\n\tname: 'CnAiChatWidget',\n\n\tcomponents: {\n\t\tCnAiCompanion,\n\t},\n\n\tinject: {\n\t\tcnTranslate: { default: null },\n\t},\n\n\tprops: {\n\t\t/**\n\t\t * The widget's content: `chatAppId`, the backend app that answers the\n\t\t * chat (defaults to the companion's own); `pill` and `pillVariant`, a\n\t\t * pill in the card's title row; `note`, a line above the input;\n\t\t * `placeholder` and `sendLabel`, the input's wording
|
|
1
|
+
{"version":3,"file":"CnAiChatWidget.vue2.js","sources":["../../../../src/components/CnAiCompanion/CnAiChatWidget.vue"],"sourcesContent":["<!--\n - SPDX-FileCopyrightText: 2026 Conduction B.V.\n - SPDX-License-Identifier: EUPL-1.2\n-->\n\n<!--\n CnAiChatWidget — the AI Chat Companion as a widget (`type: \"ai-chat\"`), so a\n page can place the assistant in its own flow: a detail page tab, a card. It is\n the same companion as the launcher's floating window, embedded: the same\n health probe, agents, sessions and stream, always open and without the hex.\n The floating companion keeps working beside it.\n\n The host draws the widget's titled card; the widget reports a pill\n (`content.pill`, e.g. the assistant's name) and the session controls for the\n card's menu through the `header` event. `content.note` is a line above the\n input, `content.placeholder` and `content.sendLabel` word the input.\n\n The page context (record, register, schema) is the one CnAppRoot provides and\n the detail page fills in, so the agents offered are the ones relevant here.\n Renders nothing when the chat backend does not answer.\n-->\n<template>\n\t<div class=\"cn-ai-chat-widget\" data-testid=\"cn-ai-chat-widget\">\n\t\t<CnAiCompanion\n\t\t\t:embedded=\"true\"\n\t\t\t:titled=\"true\"\n\t\t\t:note=\"tr(content.note)\"\n\t\t\t:inputPlaceholder=\"tr(content.placeholder)\"\n\t\t\t:sendLabel=\"tr(content.sendLabel)\"\n\t\t\t:chatAppId=\"content.chatAppId || defaultChatAppId\"\n\t\t\t:openSubjectSession=\"content.openSubjectSession === true\"\n\t\t\t@menu=\"onMenu\" />\n\t</div>\n</template>\n\n<script>\nimport CnAiCompanion from './CnAiCompanion.vue'\nimport { DEFAULT_CHAT_APP_ID } from '../../composables/aiChatConfig.js'\n\nexport default {\n\tname: 'CnAiChatWidget',\n\n\tcomponents: {\n\t\tCnAiCompanion,\n\t},\n\n\tinject: {\n\t\tcnTranslate: { default: null },\n\t},\n\n\tprops: {\n\t\t/**\n\t\t * The widget's content: `chatAppId`, the backend app that answers the\n\t\t * chat (defaults to the companion's own); `pill` and `pillVariant`, a\n\t\t * pill in the card's title row; `note`, a line above the input;\n\t\t * `placeholder` and `sendLabel`, the input's wording; `openSubjectSession`,\n\t\t * open the user's latest session about the page's record instead of an\n\t\t * empty thread. Texts go through the host's translate.\n\t\t */\n\t\tcontent: {\n\t\t\ttype: Object,\n\t\t\tdefault: () => ({}),\n\t\t},\n\t},\n\n\temits: ['header'],\n\n\tdata() {\n\t\treturn {\n\t\t\tdefaultChatAppId: DEFAULT_CHAT_APP_ID,\n\t\t}\n\t},\n\n\tmounted() {\n\t\tthis.onMenu([])\n\t},\n\n\tmethods: {\n\t\t/**\n\t\t * A manifest text through the host's translate; '' for anything else.\n\t\t *\n\t\t * @param {string} text The text as written in the manifest.\n\t\t * @return {string} The text in the user's language.\n\t\t */\n\t\ttr(text) {\n\t\t\tif (typeof text !== 'string' || text === '') {\n\t\t\t\treturn ''\n\t\t\t}\n\t\t\treturn typeof this.cnTranslate === 'function' ? this.cnTranslate(text) : text\n\t\t},\n\n\t\t/**\n\t\t * Report the card header: the pill and the panel's session controls.\n\t\t *\n\t\t * @param {Array<object>} menuActions The panel's controls as menu items.\n\t\t * @return {void}\n\t\t */\n\t\tonMenu(menuActions) {\n\t\t\tconst label = this.tr(this.content.pill)\n\t\t\t/**\n\t\t\t * @event header The card's title row: `pill` and `menuActions`.\n\t\t\t * @type {{pill?: {label: string, variant: string}, menuActions: Array<object>}}\n\t\t\t */\n\t\t\tthis.$emit('header', {\n\t\t\t\t...(label ? { pill: { label, variant: this.content.pillVariant || 'purple' } } : {}),\n\t\t\t\tmenuActions: Array.isArray(menuActions) ? menuActions : [],\n\t\t\t})\n\t\t},\n\t},\n}\n</script>\n"],"names":["CnAiCompanion"],"mappings":";;;AAuCA,aAAe;AACd,CAAA,IAAI,EAAE,gBAAgB;;CAEtB,UAAU,EAAE;iBACXA,UAAa;EACb;;AAED,CAAA,MAAM,EAAE;EACP,WAAW,EAAE,EAAE,OAAO,EAAE,IAAG,EAAG;EAC9B;;AAED,CAAA,KAAK,EAAE;AACN;;;;AAIC;;AAEA;;AAED,EAAA,OAAO,EAAE;GACR,IAAI,EAAE,MAAM;AACZ,GAAA,OAAO,EAAE,OAAO,EAAE,CAAC;GACnB;EACD;;AAED,CAAA,KAAK,EAAE,CAAC,QAAQ,CAAC;;AAEjB,CAAA,IAAI,GAAG;AACN,EAAA,OAAO;AACN,GAAA,gBAAgB,EAAE,mBAAmB;AACtC,GAAA;EACA;;AAED,CAAA,OAAO,GAAG;AACT,EAAA,IAAI,CAAC,MAAM,CAAC,EAAE,EAAA;EACd;;AAED,CAAA,OAAO,EAAE;AACR;;AAEC;;AAEA;;AAED,EAAA,EAAE,CAAC,IAAI,EAAE;AACR,GAAA,IAAI,OAAO,IAAG,KAAM,QAAO,IAAK,SAAS,EAAE,EAAE;AAC5C,IAAA,OAAO,EAAC;AACT,IAAA;AACA,GAAA,OAAO,OAAO,IAAI,CAAC,WAAY,KAAI,UAAW,GAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA,GAAI,IAAG;GAC5E;;AAED;;AAEC;AACA;;;AAGD,EAAA,MAAM,CAAC,WAAW,EAAE;AACnB,GAAA,MAAM,KAAI,GAAI,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAA;AACvC;;AAEC;;AAED,GAAA,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;AACpB,IAAA,IAAI,KAAM,GAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,WAAU,IAAK,UAAW,EAAA,GAAI,EAAE,CAAC;IACpF,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW,CAAA,GAAI,WAAU,GAAI,EAAE;IAC1D,EAAA;GACD;EACD;AACF;;;;"}
|
|
@@ -16,8 +16,9 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
16
16
|
inputPlaceholder: $options.tr($props.content.placeholder),
|
|
17
17
|
sendLabel: $options.tr($props.content.sendLabel),
|
|
18
18
|
chatAppId: $props.content.chatAppId || $data.defaultChatAppId,
|
|
19
|
+
openSubjectSession: $props.content.openSubjectSession === true,
|
|
19
20
|
onMenu: $options.onMenu
|
|
20
|
-
}, null, 8 /* PROPS */, ["note", "inputPlaceholder", "sendLabel", "chatAppId", "onMenu"])
|
|
21
|
+
}, null, 8 /* PROPS */, ["note", "inputPlaceholder", "sendLabel", "chatAppId", "openSubjectSession", "onMenu"])
|
|
21
22
|
]))
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CnAiChatWidget.vue3.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CnAiChatWidget.vue3.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -149,6 +149,16 @@ var script = {
|
|
|
149
149
|
type: String,
|
|
150
150
|
default: '',
|
|
151
151
|
},
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Open the user's latest session about the page's record (the context's
|
|
155
|
+
* `objectUuid`) instead of an empty thread, with its pending approvals.
|
|
156
|
+
* No such session, or one about another record, leaves the thread empty.
|
|
157
|
+
*/
|
|
158
|
+
openSubjectSession: {
|
|
159
|
+
type: Boolean,
|
|
160
|
+
default: false,
|
|
161
|
+
},
|
|
152
162
|
},
|
|
153
163
|
|
|
154
164
|
emits: ['menu'],
|
|
@@ -161,6 +171,8 @@ var script = {
|
|
|
161
171
|
// Cleared on unmount so a torn-down companion cannot stand itself
|
|
162
172
|
// down after the fact.
|
|
163
173
|
legacySiblingTimer: null,
|
|
174
|
+
// The record whose session was last asked for, so it is asked once.
|
|
175
|
+
openedSubjectUuid: '',
|
|
164
176
|
stream: useAiChatStream(this, { chatAppId: this.chatAppId, context: this.context }),
|
|
165
177
|
}
|
|
166
178
|
},
|
|
@@ -201,6 +213,33 @@ var script = {
|
|
|
201
213
|
effectiveContext() {
|
|
202
214
|
return this.context || this.cnAiContext || null
|
|
203
215
|
},
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The record whose session to open: the context's `objectUuid` once the
|
|
219
|
+
* backend answered, when the companion opts in; '' otherwise.
|
|
220
|
+
*
|
|
221
|
+
* @return {string} The record's uuid or ''.
|
|
222
|
+
* @spec openspec/changes/ai-chat-opens-the-subject-session/specs/ai-companion/spec.md#requirement-an-embedded-chat-may-open-the-users-session-about-the-pages-record
|
|
223
|
+
*/
|
|
224
|
+
subjectUuid() {
|
|
225
|
+
const uuid = this.effectiveContext && this.effectiveContext.objectUuid;
|
|
226
|
+
return (this.openSubjectSession && this.probeSucceeded && typeof uuid === 'string') ? uuid : ''
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
watch: {
|
|
231
|
+
/**
|
|
232
|
+
* Open the session about the record once it is known, once per record.
|
|
233
|
+
*
|
|
234
|
+
* @param {string} uuid The record's uuid or ''.
|
|
235
|
+
* @spec openspec/changes/ai-chat-opens-the-subject-session/specs/ai-companion/spec.md#requirement-an-embedded-chat-may-open-the-users-session-about-the-pages-record
|
|
236
|
+
*/
|
|
237
|
+
subjectUuid(uuid) {
|
|
238
|
+
if (uuid !== '' && uuid !== this.openedSubjectUuid) {
|
|
239
|
+
this.openedSubjectUuid = uuid;
|
|
240
|
+
this.stream.loadSubjectSession(uuid);
|
|
241
|
+
}
|
|
242
|
+
},
|
|
204
243
|
},
|
|
205
244
|
|
|
206
245
|
created() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CnAiCompanion.vue2.js","sources":["../../../../src/components/CnAiCompanion/CnAiCompanion.vue"],"sourcesContent":["<!--\n CnAiCompanion — top-level mount for the AI Chat Companion widget.\n\n On created():\n - Issues GET /index.php/apps/{chatAppId}/api/chat/health via axios.\n - Renders nothing on non-2xx, network error, or timeout (5s).\n - Probe result cached for component lifetime.\n - Only console.info() on failure (never warn/error).\n\n When probe succeeds:\n - Renders CnAiFloatingButton ALWAYS — it toggles the window rather than only\n opening it, and stays visible while the window is open.\n - Renders CnAiChatPanel (when isPanelOpen) as a floating window anchored to the\n same corner as the hex, offset clear of it so both stay clickable.\n\n FAB and panel both hidden when cnAiContext.pageKind === 'chat'.\n-->\n<template>\n\t<div\n\t\tv-if=\"probeSucceeded && !isChatPage && (embedded || isPrimaryCompanion)\"\n\t\tclass=\"cn-ai-companion\"\n\t\t:class=\"{ 'cn-ai-companion--embedded': embedded }\"\n\t\t:data-testid=\"embedded ? 'cn-ai-companion-embedded' : 'cn-ai-companion'\">\n\t\t<!--\n\t\t The hex is rendered UNCONDITIONALLY and toggles the window.\n\n\t\t It used to be `:visible=\"!isPanelOpen\"` — the launcher vanished while\n\t\t the thing it launched was open. Three reasons it now stays, in order of\n\t\t weight:\n\n\t\t 1. It is the one control we can guarantee. The window's own close\n\t\t button lives in markup a host page's stylesheet could hide; the hex\n\t\t is fixed-position with explicit `!important` properties and has\n\t\t survived every host it has been dropped into, including third-party\n\t\t office editors.\n\t\t 2. A launcher that disappears is a dead end — the affordance you used\n\t\t to summon something should dismiss it.\n\t\t 3. It removes a state transition: no show/hide to coordinate with the\n\t\t window's own.\n\n\t\t ⚠️ This is why the window anchors 70px from the edge: the hex is 26x30\n\t\t at a 24px inset, and the two must not overlap or the guarantee above is\n\t\t worth nothing.\n\t\t-->\n\t\t<CnAiFloatingButton\n\t\t\tv-if=\"!embedded\"\n\t\t\t:visible=\"true\"\n\t\t\t:position=\"position\"\n\t\t\t@click=\"togglePanel\" />\n\t\t<CnAiChatPanel\n\t\t\tref=\"panel\"\n\t\t\t:visible=\"embedded || isPanelOpen\"\n\t\t\t:embedded=\"embedded\"\n\t\t\t:titled=\"titled\"\n\t\t\t:note=\"note\"\n\t\t\t:inputPlaceholder=\"inputPlaceholder\"\n\t\t\t:sendLabel=\"sendLabel\"\n\t\t\t:streamState=\"stream.state\"\n\t\t\t:chatAppId=\"chatAppId\"\n\t\t\t:context=\"effectiveContext\"\n\t\t\t:position=\"position\"\n\t\t\t:fabRef=\"$refs.fabButton\"\n\t\t\t@close=\"closePanel\"\n\t\t\t@send=\"onSend\"\n\t\t\t@newThread=\"onNewThread\"\n\t\t\t@loadConversation=\"onLoadConversation\"\n\t\t\t@menu=\"onMenu\" />\n\t</div>\n</template>\n\n<script>\nimport axios from '@nextcloud/axios'\nimport { translate as t } from '@nextcloud/l10n'\nimport CnAiChatPanel from './CnAiChatPanel.vue'\nimport CnAiFloatingButton from './CnAiFloatingButton.vue'\nimport { chatHealthUrl, DEFAULT_CHAT_APP_ID } from '../../composables/aiChatConfig.js'\nimport { useAiChatStream } from '../../composables/useAiChatStream.js'\nimport { ensureTranslations } from '../../l10n/index.js'\nimport { isAppInstalled } from '../../utils/appInstalled.js'\n\nconst HEALTH_TIMEOUT = 5000\n\n/** How many times the health probe may fail before the companion hides. */\nconst HEALTH_PROBE_ATTEMPTS = 3\n\n/** Base backoff between probe attempts, multiplied by the attempt number. */\nconst HEALTH_RETRY_DELAY = 750\n\n/**\n * The window key one companion claims so a second one stands down.\n *\n * On `window` rather than in module scope, because the two companions on a page\n * do not share a module instance: one comes from the host app's bundle and one\n * from a standalone bundle attached to every page. Two copies of this file are\n * loaded, so a module-level flag would be two flags and would guard nothing.\n */\nconst COMPANION_SINGLETON_KEY = '__cnAiCompanionPrimary'\n\n/**\n * How long to wait before looking for a companion that cannot stand down.\n *\n * Long enough for a host app's Vue tree to boot after a standalone mount at\n * DOMContentLoaded, short enough that a user never sees two hexes settle.\n */\nconst LEGACY_SIBLING_DELAY = 1200\n\nexport default {\n\tname: 'CnAiCompanion',\n\n\tcomponents: {\n\t\tCnAiFloatingButton,\n\t\tCnAiChatPanel,\n\t},\n\n\tinject: {\n\t\tcnAiContext: { default: null },\n\t\thostTranslate: { from: 'cnTranslate', default: null },\n\t},\n\n\t/**\n\t * The companion's buttons and panel ask `cnTranslate` for their labels.\n\t * Mounted on another app's page (Hermiq's companion on every page) no\n\t * host provides one, so a label the host leaves untranslated is read from\n\t * the library's own catalogue.\n\t *\n\t * @return {object} The provided values.\n\t * @spec openspec/changes/ai-companion-library-labels/specs/ai-chat-companion/spec.md#requirement-the-companion-reads-in-the-users-language-on-any-page\n\t */\n\tprovide() {\n\t\tensureTranslations()\n\t\tconst host = typeof this.hostTranslate === 'function' ? this.hostTranslate : null\n\t\treturn {\n\t\t\tcnTranslate: (text, vars) => {\n\t\t\t\tconst hosted = host ? host(text, vars) : text\n\t\t\t\treturn hosted !== text ? hosted : t('nextcloud-vue', text, vars)\n\t\t\t},\n\t\t}\n\t},\n\n\tprops: {\n\t\t/**\n\t\t * Default position for the FAB.\n\t\t *\n\t\t * @type {'bottom-right'|'bottom-left'|'top-right'|'top-left'}\n\t\t */\n\t\tposition: {\n\t\t\ttype: String,\n\t\t\tdefault: 'bottom-right',\n\t\t},\n\n\t\t/**\n\t\t * Backend app id that answers the chat/health/conversation HTTP calls\n\t\t * (`/index.php/apps/{chatAppId}/api/...`). Single configuration point for\n\t\t * the AI Chat Companion's backend — see composables/aiChatConfig.js.\n\t\t * Defaults to `hermiq` (the agent engine's home per hydra ADR-034\n\t\t * \"Amendment 2026-07-05\"); `CnAppRoot` forwards its own `chatAppId`\n\t\t * prop here so a consuming app can point the widget at another backend\n\t\t * (e.g. `openregister` during its compat window) in one place.\n\t\t *\n\t\t * @type {string}\n\t\t */\n\t\tchatAppId: {\n\t\t\ttype: String,\n\t\t\tdefault: DEFAULT_CHAT_APP_ID,\n\t\t},\n\n\t\t/**\n\t\t * What the user is looking at, stated by whoever mounted the companion.\n\t\t *\n\t\t * Inside a Conduction app, CnAppRoot provides this and the prop is\n\t\t * unnecessary. Mounted standalone on a page belonging to another app —\n\t\t * an office editor, the Files list — there is no provider, and the\n\t\t * injected fallback reports `appId: 'unknown'`. The agent then has no\n\t\t * idea what \"this document\" refers to and says so.\n\t\t *\n\t\t * Shape mirrors the injected context: `{ appId, pageKind, fileId,\n\t\t * objectUuid, registerSlug, schemaSlug, route }`. All optional; whatever\n\t\t * the host knows is better than 'unknown'.\n\t\t *\n\t\t * @type {object|null}\n\t\t */\n\t\tcontext: {\n\t\t\ttype: Object,\n\t\t\tdefault: null,\n\t\t},\n\n\t\t/**\n\t\t * Render the chat as a panel of the page (a tab, a card) instead of the\n\t\t * launcher hex and its floating window. An embedded chat is always\n\t\t * open, has no launcher, and does not take the page's single companion\n\t\t * slot, so the floating companion keeps working beside it.\n\t\t *\n\t\t * @type {boolean}\n\t\t */\n\t\tembedded: {\n\t\t\ttype: Boolean,\n\t\t\tdefault: false,\n\t\t},\n\n\t\t/** An embedded chat in a card that draws its title; see CnAiChatPanel `titled`. */\n\t\ttitled: {\n\t\t\ttype: Boolean,\n\t\t\tdefault: false,\n\t\t},\n\n\t\t/** A line above the input, already translated. */\n\t\tnote: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** The input's placeholder, already translated. */\n\t\tinputPlaceholder: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** A label on the send button, already translated. */\n\t\tsendLabel: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\t},\n\n\temits: ['menu'],\n\n\tdata() {\n\t\treturn {\n\t\t\tprobeSucceeded: false,\n\t\t\tisPanelOpen: false,\n\t\t\tisPrimaryCompanion: false,\n\t\t\t// Cleared on unmount so a torn-down companion cannot stand itself\n\t\t\t// down after the fact.\n\t\t\tlegacySiblingTimer: null,\n\t\t\tstream: useAiChatStream(this, { chatAppId: this.chatAppId, context: this.context }),\n\t\t}\n\t},\n\n\tcomputed: {\n\t\tisChatPage() {\n\t\t\tconst ctx = this.cnAiContext\n\t\t\treturn ctx && ctx.pageKind === 'chat'\n\t\t},\n\n\t\t/**\n\t\t * The page context the panel reasons with: the prop when a standalone\n\t\t * mount passed one, otherwise the context CnAppRoot provides.\n\t\t *\n\t\t * WHY THIS EXISTS\n\t\t * ---------------\n\t\t * `CnAppRoot` renders `<CnAiCompanion :chatAppId=\"chatAppId\" />` and\n\t\t * passes NO `:context`, because it already provides `cnAiContext` for\n\t\t * descendants to inject. This component injected it for `isChatPage`\n\t\t * but handed the panel the raw `context` PROP, which is `null` in that\n\t\t * arrangement — so inside every app shell the panel ran with no\n\t\t * context at all.\n\t\t *\n\t\t * The panel's `relevantAgentOptions` treats an empty context as \"no\n\t\t * page to be relevant to\" and returns EVERY agent, so it selected\n\t\t * whichever agent the API happened to list first. Measured on the\n\t\t * demo instance 2026-09-20: on `/apps/buildiq/` the companion opened\n\t\t * as \"Hydra Triage\", which holds only `hydra.*` tools, and its first\n\t\t * answer was \"This agent's tool grants resolve to no tools\" — while\n\t\t * \"Buildiq builder\", holding all eight `buildiq_*` tools, sat unused\n\t\t * at the bottom of the same list.\n\t\t *\n\t\t * A standalone mount that passes `context` explicitly still wins, so\n\t\t * Hermiq's cross-app companion is unaffected.\n\t\t *\n\t\t * @return {object|null} The context to reason with.\n\t\t */\n\t\teffectiveContext() {\n\t\t\treturn this.context || this.cnAiContext || null\n\t\t},\n\t},\n\n\tcreated() {\n\t\tthis.runHealthProbe()\n\t},\n\n\tbeforeUnmount() {\n\t\tif (this.legacySiblingTimer !== null) {\n\t\t\tclearTimeout(this.legacySiblingTimer)\n\t\t\tthis.legacySiblingTimer = null\n\t\t}\n\n\t\tthis.releaseSingleton()\n\t},\n\n\tmethods: {\n\t\t/**\n\t\t * Stand down if another companion is on the page that cannot stand down.\n\t\t *\n\t\t * 🔴 THE WINDOW FLAG ONLY BINDS INSTANCES THAT CHECK IT. Measured on a\n\t\t * live instance after shipping the flag: still TWO hexes, stacked at the\n\t\t * same coordinates — one from `#openregister` (the host app's own bundle,\n\t\t * built against an older version of this library) and one from\n\t\t * `#hermiq-companion-root` (the standalone mount, built against the new\n\t\t * one). The old bundle never reads the flag, so it renders regardless,\n\t\t * and the guarded instance had already claimed the slot and rendered too.\n\t\t *\n\t\t * The library fix alone therefore does not reach a page until EVERY app\n\t\t * on it has rebuilt — which is not something a user with a double hex\n\t\t * can wait for. So the instance that CAN yield does.\n\t\t *\n\t\t * Deferred rather than checked at mount, because order is against us: a\n\t\t * standalone companion mounts at DOMContentLoaded and the host app's Vue\n\t\t * tree boots after it, so at mount time there is nothing to see.\n\t\t *\n\t\t * When both companions carry this guard the flag has already stopped the\n\t\t * second one, so this never fires — it is strictly a bridge for mixed\n\t\t * versions, and it costs one timeout.\n\t\t */\n\t\tyieldToACompanionThatCannotYield() {\n\t\t\tif (typeof document === 'undefined' || this.isPrimaryCompanion !== true || this.embedded) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.legacySiblingTimer = setTimeout(() => {\n\t\t\t\tthis.legacySiblingTimer = null\n\n\t\t\t\tconst rendered = document.querySelectorAll('[data-testid=\"cn-ai-companion\"]')\n\t\t\t\tif (rendered.length <= 1) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tfor (const el of rendered) {\n\t\t\t\t\tif (el !== this.$el) {\n\t\t\t\t\t\t// Yield to it: the host app's own companion sits inside\n\t\t\t\t\t\t// that app's tree and carries its page context, which a\n\t\t\t\t\t\t// standalone mount can only approximate.\n\t\t\t\t\t\tthis.releaseSingleton()\n\t\t\t\t\t\tthis.isPrimaryCompanion = false\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, LEGACY_SIBLING_DELAY)\n\t\t},\n\n\t\t/**\n\t\t * Claim the page's single companion slot, or stand down.\n\t\t *\n\t\t * 🔴 TWO COMPANIONS ON ONE PAGE IS A REACHABLE STATE, and it was reached:\n\t\t * `CnAppRoot` renders a companion for any app that sets `aiCompanion`,\n\t\t * while a host app can also mount one standalone on every page of the\n\t\t * instance (Hermiq does exactly this, so the assistant reaches\n\t\t * third-party office editors that have no CnAppRoot of ours). On any\n\t\t * page that has both, the user saw TWO hexes stacked a few pixels apart\n\t\t * — the two mounts pick up different bundled stylesheets, so they do not\n\t\t * even land in the same place.\n\t\t *\n\t\t * The guard lives HERE, in the component, rather than in each host's\n\t\t * mount script, because only the component knows how many of itself\n\t\t * exist. A host-side check cannot see a sibling that mounts later: the\n\t\t * standalone script runs at DOMContentLoaded and the app's own Vue tree\n\t\t * boots after it, so whichever check runs first sees nothing and both\n\t\t * render.\n\t\t *\n\t\t * First to claim wins and the rest render nothing, except that the\n\t\t * app's own companion (with an injected `cnAiContext`) always takes the\n\t\t * slot from a standalone one: the health probes race, so \"first\" is\n\t\t * not stable, and the app's own carries the page context.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\tclaimSingleton() {\n\t\t\t// 🔴 CLAIMED ONLY WHEN THIS INSTANCE WOULD ACTUALLY RENDER.\n\t\t\t//\n\t\t\t// An earlier version claimed in `created()`, before the health probe\n\t\t\t// had answered — so a companion whose probe FAILED still took the\n\t\t\t// slot and stood the other one down, turning \"one companion\" into\n\t\t\t// NONE. Measured on a slow instance, where the probe's 3×5s budget\n\t\t\t// is genuinely marginal: the slot was claimed and nothing rendered.\n\t\t\t//\n\t\t\t// Claiming late is also why the claim is not in a `watch` on the\n\t\t\t// window key: the slot is contended exactly once per page, at the\n\t\t\t// moment each candidate learns it can render.\n\t\t\tif (this.probeSucceeded !== true || this.isChatPage === true || this.embedded) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst scope = typeof window !== 'undefined' ? window : null\n\t\t\tif (scope === null) {\n\t\t\t\t// No window (SSR, a bare unit test): nothing else can be\n\t\t\t\t// rendering, so this instance is the only one by definition.\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (scope[COMPANION_SINGLETON_KEY] === null || scope[COMPANION_SINGLETON_KEY] === undefined) {\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = this\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst holder = scope[COMPANION_SINGLETON_KEY]\n\t\t\tif (holder !== this && this.cnAiContext && !holder.cnAiContext) {\n\t\t\t\t// The app's own companion (inside a CnAppRoot, with the page's\n\t\t\t\t// context) outranks a standalone mount, whichever probe answered\n\t\t\t\t// first; the holder's flag is set directly so a standalone built\n\t\t\t\t// on an older copy of this library stands down too.\n\t\t\t\tholder.isPrimaryCompanion = false\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = this\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.isPrimaryCompanion = holder === this\n\t\t},\n\n\t\t/**\n\t\t * Give the slot back, but only if this instance is holding it.\n\t\t *\n\t\t * Checked rather than cleared unconditionally: a second, standing-down\n\t\t * instance unmounting must not release the slot the FIRST one is still\n\t\t * using, which would let a third mount render alongside it.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\treleaseSingleton() {\n\t\t\tconst scope = typeof window !== 'undefined' ? window : null\n\t\t\tif (scope !== null && scope[COMPANION_SINGLETON_KEY] === this) {\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = null\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Ask the chat backend whether it can answer, and render only if so.\n\t\t *\n\t\t * Skipped without a request when the backend app is not installed for\n\t\t * this user.\n\t\t *\n\t\t * @return {Promise<void>}\n\t\t * @spec openspec/changes/no-calls-to-missing-apps-and-presence-beacon/specs/ai-companion/spec.md#requirement-the-companion-does-not-probe-a-backend-that-is-not-installed\n\t\t */\n\t\tasync runHealthProbe() {\n\t\t\t// RETRY before hiding. A single probe makes the whole companion\n\t\t\t// disappear on one slow response, and \"slow\" is normal: measured on a\n\t\t\t// busy instance (load 48) the health endpoint answered in well under a\n\t\t\t// second, but the request still lost its 5s budget to contention. The\n\t\t\t// failure mode is the worst kind — the widget is simply absent, with\n\t\t\t// nothing on screen saying why, and a reload usually \"fixes\" it, which\n\t\t\t// is what makes it read as flakiness rather than as a probe result.\n\t\t\t//\n\t\t\t// A backend that is genuinely down fails all attempts and is still\n\t\t\t// reported; this only stops one unlucky request from deciding.\n\t\t\t//\n\t\t\t// 🔴 NO PROBE AT AN APP THAT IS NOT THERE. Nextcloud already tells\n\t\t\t// the page which apps the user has (`OC.appswebroots`), so asking a\n\t\t\t// missing backend for its health is a guaranteed 404, three times\n\t\t\t// per page, in every console. Measured on cloud.conduction.nl\n\t\t\t// (round-5 check): hermiq not installed, three\n\t\t\t// `/apps/hermiq/api/chat/health` 404s on every pipelinq and dossiq\n\t\t\t// page. Hidden either way; now hidden without the requests.\n\t\t\tif (!isAppInstalled(this.chatAppId || DEFAULT_CHAT_APP_ID)) {\n\t\t\t\tthis.probeSucceeded = false\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tfor (let attempt = 1; attempt <= HEALTH_PROBE_ATTEMPTS; attempt++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await axios.get(chatHealthUrl(this.chatAppId), {\n\t\t\t\t\t\ttimeout: HEALTH_TIMEOUT,\n\t\t\t\t\t\tvalidateStatus: (status) => status >= 200 && status < 300,\n\t\t\t\t\t})\n\t\t\t\t\tthis.probeSucceeded = response.status >= 200 && response.status < 300\n\t\t\t\t\t// Contend for the page's single slot only now, with a\n\t\t\t\t\t// backend that answered. See claimSingleton().\n\t\t\t\t\tthis.claimSingleton()\n\t\t\t\t\t// A companion built against an older version of this library\n\t\t\t\t\t// cannot read the flag above, so look for one shortly.\n\t\t\t\t\tthis.yieldToACompanionThatCannotYield()\n\t\t\t\t\treturn\n\t\t\t\t} catch {\n\t\t\t\t\tif (attempt < HEALTH_PROBE_ATTEMPTS) {\n\t\t\t\t\t\tawait new Promise((resolve) => {\n\t\t\t\t\t\t\tsetTimeout(resolve, HEALTH_RETRY_DELAY * attempt)\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.info(`[CnAiCompanion] chat backend \"${this.chatAppId}\" health probe did not return 2xx `\n\t\t\t\t\t\t+ `after ${HEALTH_PROBE_ATTEMPTS} attempts — widget hidden`)\n\t\t\t\t\tthis.probeSucceeded = false\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * The hex's own handler: open when closed, close when open.\n\t\t *\n\t\t * The launcher stays visible while the window is open (see the template),\n\t\t * so it has to answer for both directions rather than only opening.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\ttogglePanel() {\n\t\t\tif (this.isPanelOpen) {\n\t\t\t\tthis.closePanel()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.openPanel()\n\t\t},\n\n\t\topenPanel() {\n\t\t\tthis.isPanelOpen = true\n\t\t\tthis.$nextTick(() => {\n\t\t\t\tif (this.$refs.panel && this.$refs.panel.$refs.input) {\n\t\t\t\t\tthis.$refs.panel.$refs.input.focus()\n\t\t\t\t}\n\t\t\t})\n\t\t},\n\n\t\tclosePanel() {\n\t\t\tthis.isPanelOpen = false\n\t\t},\n\n\t\tonSend(text, agentUuid, attachments) {\n\t\t\tthis.stream.send(text, { agentUuid, attachments }).catch((err) => {\n\t\t\t\t// Stream errors are tracked in stream.state.error — no extra handling needed\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.info('[CnAiCompanion] send error:', err?.message)\n\t\t\t})\n\t\t},\n\n\t\tonNewThread() {\n\t\t\tthis.stream.startNewThread()\n\t\t},\n\n\t\tonLoadConversation(uuid) {\n\t\t\tthis.stream.loadConversation(uuid)\n\t\t},\n\n\t\t/**\n\t\t * Passes a titled panel's session controls on to the host card.\n\t\t *\n\t\t * @param {Array} actions The panel's controls as menu actions\n\t\t */\n\t\tonMenu(actions) {\n\t\t\t/**\n\t\t\t * @event menu The session controls of a titled panel, for its card's menu.\n\t\t\t */\n\t\t\tthis.$emit('menu', actions)\n\t\t},\n\t},\n}\n</script>\n\n<style>\n.cn-ai-companion {\n\t/*\n\t * display: contents removes this wrapper from the layout tree so the\n\t * embedded NcAppSidebar inherits NcContent as its flex parent — required\n\t * for the sidebar to slide in from the RIGHT edge. The FAB is itself\n\t * position:fixed so it positions independently of the wrapper's box.\n\t *\n\t * !important is intentional: webpack pulls in BOTH the old (position:\n\t * fixed) and new (display: contents) rules from the package's CJS and\n\t * ESM builds; without !important the old rule wins the cascade and the\n\t * sidebar renders at the left.\n\t */\n\tdisplay: contents !important;\n\tposition: static !important;\n}\n</style>\n"],"names":["CnAiFloatingButton","CnAiChatPanel","t","axios"],"mappings":";;;;;;;;;AAgFA,MAAM,cAAe,GAAE,KAAG;;AAE1B;AACA,MAAM,qBAAoB,GAAI,EAAA;;AAE9B;AACA,MAAM,kBAAiB,GAAI,IAAE;;AAE7B;;AAEC;AACA;AACA;AACA;A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AAC;AACpC,KAAA;IACA,EAAA;GACD;;EAED,UAAU,GAAG;AACZ,GAAA,IAAI,CAAC,WAAU,GAAI,MAAI;GACvB;;AAED,EAAA,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE;GACpC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,WAAY,EAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK;AACjE;AACA;IACA,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,GAAG,EAAE,OAAO,EAAA;IACxD,EAAA;GACD;;EAED,WAAW,GAAG;GACb,IAAI,CAAC,MAAM,CAAC,cAAc,GAAC;GAC3B;;EAED,kBAAkB,CAAC,IAAI,EAAE;AACxB,GAAA,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAA;GACjC;;AAED;;AAEC;;;AAGD,EAAA,MAAM,CAAC,OAAO,EAAE;AACf;;;GAGA,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAA;GAC1B;EACD;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"CnAiCompanion.vue2.js","sources":["../../../../src/components/CnAiCompanion/CnAiCompanion.vue"],"sourcesContent":["<!--\n CnAiCompanion — top-level mount for the AI Chat Companion widget.\n\n On created():\n - Issues GET /index.php/apps/{chatAppId}/api/chat/health via axios.\n - Renders nothing on non-2xx, network error, or timeout (5s).\n - Probe result cached for component lifetime.\n - Only console.info() on failure (never warn/error).\n\n When probe succeeds:\n - Renders CnAiFloatingButton ALWAYS — it toggles the window rather than only\n opening it, and stays visible while the window is open.\n - Renders CnAiChatPanel (when isPanelOpen) as a floating window anchored to the\n same corner as the hex, offset clear of it so both stay clickable.\n\n FAB and panel both hidden when cnAiContext.pageKind === 'chat'.\n-->\n<template>\n\t<div\n\t\tv-if=\"probeSucceeded && !isChatPage && (embedded || isPrimaryCompanion)\"\n\t\tclass=\"cn-ai-companion\"\n\t\t:class=\"{ 'cn-ai-companion--embedded': embedded }\"\n\t\t:data-testid=\"embedded ? 'cn-ai-companion-embedded' : 'cn-ai-companion'\">\n\t\t<!--\n\t\t The hex is rendered UNCONDITIONALLY and toggles the window.\n\n\t\t It used to be `:visible=\"!isPanelOpen\"` — the launcher vanished while\n\t\t the thing it launched was open. Three reasons it now stays, in order of\n\t\t weight:\n\n\t\t 1. It is the one control we can guarantee. The window's own close\n\t\t button lives in markup a host page's stylesheet could hide; the hex\n\t\t is fixed-position with explicit `!important` properties and has\n\t\t survived every host it has been dropped into, including third-party\n\t\t office editors.\n\t\t 2. A launcher that disappears is a dead end — the affordance you used\n\t\t to summon something should dismiss it.\n\t\t 3. It removes a state transition: no show/hide to coordinate with the\n\t\t window's own.\n\n\t\t ⚠️ This is why the window anchors 70px from the edge: the hex is 26x30\n\t\t at a 24px inset, and the two must not overlap or the guarantee above is\n\t\t worth nothing.\n\t\t-->\n\t\t<CnAiFloatingButton\n\t\t\tv-if=\"!embedded\"\n\t\t\t:visible=\"true\"\n\t\t\t:position=\"position\"\n\t\t\t@click=\"togglePanel\" />\n\t\t<CnAiChatPanel\n\t\t\tref=\"panel\"\n\t\t\t:visible=\"embedded || isPanelOpen\"\n\t\t\t:embedded=\"embedded\"\n\t\t\t:titled=\"titled\"\n\t\t\t:note=\"note\"\n\t\t\t:inputPlaceholder=\"inputPlaceholder\"\n\t\t\t:sendLabel=\"sendLabel\"\n\t\t\t:streamState=\"stream.state\"\n\t\t\t:chatAppId=\"chatAppId\"\n\t\t\t:context=\"effectiveContext\"\n\t\t\t:position=\"position\"\n\t\t\t:fabRef=\"$refs.fabButton\"\n\t\t\t@close=\"closePanel\"\n\t\t\t@send=\"onSend\"\n\t\t\t@newThread=\"onNewThread\"\n\t\t\t@loadConversation=\"onLoadConversation\"\n\t\t\t@menu=\"onMenu\" />\n\t</div>\n</template>\n\n<script>\nimport axios from '@nextcloud/axios'\nimport { translate as t } from '@nextcloud/l10n'\nimport CnAiChatPanel from './CnAiChatPanel.vue'\nimport CnAiFloatingButton from './CnAiFloatingButton.vue'\nimport { chatHealthUrl, DEFAULT_CHAT_APP_ID } from '../../composables/aiChatConfig.js'\nimport { useAiChatStream } from '../../composables/useAiChatStream.js'\nimport { ensureTranslations } from '../../l10n/index.js'\nimport { isAppInstalled } from '../../utils/appInstalled.js'\n\nconst HEALTH_TIMEOUT = 5000\n\n/** How many times the health probe may fail before the companion hides. */\nconst HEALTH_PROBE_ATTEMPTS = 3\n\n/** Base backoff between probe attempts, multiplied by the attempt number. */\nconst HEALTH_RETRY_DELAY = 750\n\n/**\n * The window key one companion claims so a second one stands down.\n *\n * On `window` rather than in module scope, because the two companions on a page\n * do not share a module instance: one comes from the host app's bundle and one\n * from a standalone bundle attached to every page. Two copies of this file are\n * loaded, so a module-level flag would be two flags and would guard nothing.\n */\nconst COMPANION_SINGLETON_KEY = '__cnAiCompanionPrimary'\n\n/**\n * How long to wait before looking for a companion that cannot stand down.\n *\n * Long enough for a host app's Vue tree to boot after a standalone mount at\n * DOMContentLoaded, short enough that a user never sees two hexes settle.\n */\nconst LEGACY_SIBLING_DELAY = 1200\n\nexport default {\n\tname: 'CnAiCompanion',\n\n\tcomponents: {\n\t\tCnAiFloatingButton,\n\t\tCnAiChatPanel,\n\t},\n\n\tinject: {\n\t\tcnAiContext: { default: null },\n\t\thostTranslate: { from: 'cnTranslate', default: null },\n\t},\n\n\t/**\n\t * The companion's buttons and panel ask `cnTranslate` for their labels.\n\t * Mounted on another app's page (Hermiq's companion on every page) no\n\t * host provides one, so a label the host leaves untranslated is read from\n\t * the library's own catalogue.\n\t *\n\t * @return {object} The provided values.\n\t * @spec openspec/changes/ai-companion-library-labels/specs/ai-chat-companion/spec.md#requirement-the-companion-reads-in-the-users-language-on-any-page\n\t */\n\tprovide() {\n\t\tensureTranslations()\n\t\tconst host = typeof this.hostTranslate === 'function' ? this.hostTranslate : null\n\t\treturn {\n\t\t\tcnTranslate: (text, vars) => {\n\t\t\t\tconst hosted = host ? host(text, vars) : text\n\t\t\t\treturn hosted !== text ? hosted : t('nextcloud-vue', text, vars)\n\t\t\t},\n\t\t}\n\t},\n\n\tprops: {\n\t\t/**\n\t\t * Default position for the FAB.\n\t\t *\n\t\t * @type {'bottom-right'|'bottom-left'|'top-right'|'top-left'}\n\t\t */\n\t\tposition: {\n\t\t\ttype: String,\n\t\t\tdefault: 'bottom-right',\n\t\t},\n\n\t\t/**\n\t\t * Backend app id that answers the chat/health/conversation HTTP calls\n\t\t * (`/index.php/apps/{chatAppId}/api/...`). Single configuration point for\n\t\t * the AI Chat Companion's backend — see composables/aiChatConfig.js.\n\t\t * Defaults to `hermiq` (the agent engine's home per hydra ADR-034\n\t\t * \"Amendment 2026-07-05\"); `CnAppRoot` forwards its own `chatAppId`\n\t\t * prop here so a consuming app can point the widget at another backend\n\t\t * (e.g. `openregister` during its compat window) in one place.\n\t\t *\n\t\t * @type {string}\n\t\t */\n\t\tchatAppId: {\n\t\t\ttype: String,\n\t\t\tdefault: DEFAULT_CHAT_APP_ID,\n\t\t},\n\n\t\t/**\n\t\t * What the user is looking at, stated by whoever mounted the companion.\n\t\t *\n\t\t * Inside a Conduction app, CnAppRoot provides this and the prop is\n\t\t * unnecessary. Mounted standalone on a page belonging to another app —\n\t\t * an office editor, the Files list — there is no provider, and the\n\t\t * injected fallback reports `appId: 'unknown'`. The agent then has no\n\t\t * idea what \"this document\" refers to and says so.\n\t\t *\n\t\t * Shape mirrors the injected context: `{ appId, pageKind, fileId,\n\t\t * objectUuid, registerSlug, schemaSlug, route }`. All optional; whatever\n\t\t * the host knows is better than 'unknown'.\n\t\t *\n\t\t * @type {object|null}\n\t\t */\n\t\tcontext: {\n\t\t\ttype: Object,\n\t\t\tdefault: null,\n\t\t},\n\n\t\t/**\n\t\t * Render the chat as a panel of the page (a tab, a card) instead of the\n\t\t * launcher hex and its floating window. An embedded chat is always\n\t\t * open, has no launcher, and does not take the page's single companion\n\t\t * slot, so the floating companion keeps working beside it.\n\t\t *\n\t\t * @type {boolean}\n\t\t */\n\t\tembedded: {\n\t\t\ttype: Boolean,\n\t\t\tdefault: false,\n\t\t},\n\n\t\t/** An embedded chat in a card that draws its title; see CnAiChatPanel `titled`. */\n\t\ttitled: {\n\t\t\ttype: Boolean,\n\t\t\tdefault: false,\n\t\t},\n\n\t\t/** A line above the input, already translated. */\n\t\tnote: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** The input's placeholder, already translated. */\n\t\tinputPlaceholder: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** A label on the send button, already translated. */\n\t\tsendLabel: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/**\n\t\t * Open the user's latest session about the page's record (the context's\n\t\t * `objectUuid`) instead of an empty thread, with its pending approvals.\n\t\t * No such session, or one about another record, leaves the thread empty.\n\t\t */\n\t\topenSubjectSession: {\n\t\t\ttype: Boolean,\n\t\t\tdefault: false,\n\t\t},\n\t},\n\n\temits: ['menu'],\n\n\tdata() {\n\t\treturn {\n\t\t\tprobeSucceeded: false,\n\t\t\tisPanelOpen: false,\n\t\t\tisPrimaryCompanion: false,\n\t\t\t// Cleared on unmount so a torn-down companion cannot stand itself\n\t\t\t// down after the fact.\n\t\t\tlegacySiblingTimer: null,\n\t\t\t// The record whose session was last asked for, so it is asked once.\n\t\t\topenedSubjectUuid: '',\n\t\t\tstream: useAiChatStream(this, { chatAppId: this.chatAppId, context: this.context }),\n\t\t}\n\t},\n\n\tcomputed: {\n\t\tisChatPage() {\n\t\t\tconst ctx = this.cnAiContext\n\t\t\treturn ctx && ctx.pageKind === 'chat'\n\t\t},\n\n\t\t/**\n\t\t * The page context the panel reasons with: the prop when a standalone\n\t\t * mount passed one, otherwise the context CnAppRoot provides.\n\t\t *\n\t\t * WHY THIS EXISTS\n\t\t * ---------------\n\t\t * `CnAppRoot` renders `<CnAiCompanion :chatAppId=\"chatAppId\" />` and\n\t\t * passes NO `:context`, because it already provides `cnAiContext` for\n\t\t * descendants to inject. This component injected it for `isChatPage`\n\t\t * but handed the panel the raw `context` PROP, which is `null` in that\n\t\t * arrangement — so inside every app shell the panel ran with no\n\t\t * context at all.\n\t\t *\n\t\t * The panel's `relevantAgentOptions` treats an empty context as \"no\n\t\t * page to be relevant to\" and returns EVERY agent, so it selected\n\t\t * whichever agent the API happened to list first. Measured on the\n\t\t * demo instance 2026-09-20: on `/apps/buildiq/` the companion opened\n\t\t * as \"Hydra Triage\", which holds only `hydra.*` tools, and its first\n\t\t * answer was \"This agent's tool grants resolve to no tools\" — while\n\t\t * \"Buildiq builder\", holding all eight `buildiq_*` tools, sat unused\n\t\t * at the bottom of the same list.\n\t\t *\n\t\t * A standalone mount that passes `context` explicitly still wins, so\n\t\t * Hermiq's cross-app companion is unaffected.\n\t\t *\n\t\t * @return {object|null} The context to reason with.\n\t\t */\n\t\teffectiveContext() {\n\t\t\treturn this.context || this.cnAiContext || null\n\t\t},\n\n\t\t/**\n\t\t * The record whose session to open: the context's `objectUuid` once the\n\t\t * backend answered, when the companion opts in; '' otherwise.\n\t\t *\n\t\t * @return {string} The record's uuid or ''.\n\t\t * @spec openspec/changes/ai-chat-opens-the-subject-session/specs/ai-companion/spec.md#requirement-an-embedded-chat-may-open-the-users-session-about-the-pages-record\n\t\t */\n\t\tsubjectUuid() {\n\t\t\tconst uuid = this.effectiveContext && this.effectiveContext.objectUuid\n\t\t\treturn (this.openSubjectSession && this.probeSucceeded && typeof uuid === 'string') ? uuid : ''\n\t\t},\n\t},\n\n\twatch: {\n\t\t/**\n\t\t * Open the session about the record once it is known, once per record.\n\t\t *\n\t\t * @param {string} uuid The record's uuid or ''.\n\t\t * @spec openspec/changes/ai-chat-opens-the-subject-session/specs/ai-companion/spec.md#requirement-an-embedded-chat-may-open-the-users-session-about-the-pages-record\n\t\t */\n\t\tsubjectUuid(uuid) {\n\t\t\tif (uuid !== '' && uuid !== this.openedSubjectUuid) {\n\t\t\t\tthis.openedSubjectUuid = uuid\n\t\t\t\tthis.stream.loadSubjectSession(uuid)\n\t\t\t}\n\t\t},\n\t},\n\n\tcreated() {\n\t\tthis.runHealthProbe()\n\t},\n\n\tbeforeUnmount() {\n\t\tif (this.legacySiblingTimer !== null) {\n\t\t\tclearTimeout(this.legacySiblingTimer)\n\t\t\tthis.legacySiblingTimer = null\n\t\t}\n\n\t\tthis.releaseSingleton()\n\t},\n\n\tmethods: {\n\t\t/**\n\t\t * Stand down if another companion is on the page that cannot stand down.\n\t\t *\n\t\t * 🔴 THE WINDOW FLAG ONLY BINDS INSTANCES THAT CHECK IT. Measured on a\n\t\t * live instance after shipping the flag: still TWO hexes, stacked at the\n\t\t * same coordinates — one from `#openregister` (the host app's own bundle,\n\t\t * built against an older version of this library) and one from\n\t\t * `#hermiq-companion-root` (the standalone mount, built against the new\n\t\t * one). The old bundle never reads the flag, so it renders regardless,\n\t\t * and the guarded instance had already claimed the slot and rendered too.\n\t\t *\n\t\t * The library fix alone therefore does not reach a page until EVERY app\n\t\t * on it has rebuilt — which is not something a user with a double hex\n\t\t * can wait for. So the instance that CAN yield does.\n\t\t *\n\t\t * Deferred rather than checked at mount, because order is against us: a\n\t\t * standalone companion mounts at DOMContentLoaded and the host app's Vue\n\t\t * tree boots after it, so at mount time there is nothing to see.\n\t\t *\n\t\t * When both companions carry this guard the flag has already stopped the\n\t\t * second one, so this never fires — it is strictly a bridge for mixed\n\t\t * versions, and it costs one timeout.\n\t\t */\n\t\tyieldToACompanionThatCannotYield() {\n\t\t\tif (typeof document === 'undefined' || this.isPrimaryCompanion !== true || this.embedded) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.legacySiblingTimer = setTimeout(() => {\n\t\t\t\tthis.legacySiblingTimer = null\n\n\t\t\t\tconst rendered = document.querySelectorAll('[data-testid=\"cn-ai-companion\"]')\n\t\t\t\tif (rendered.length <= 1) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tfor (const el of rendered) {\n\t\t\t\t\tif (el !== this.$el) {\n\t\t\t\t\t\t// Yield to it: the host app's own companion sits inside\n\t\t\t\t\t\t// that app's tree and carries its page context, which a\n\t\t\t\t\t\t// standalone mount can only approximate.\n\t\t\t\t\t\tthis.releaseSingleton()\n\t\t\t\t\t\tthis.isPrimaryCompanion = false\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, LEGACY_SIBLING_DELAY)\n\t\t},\n\n\t\t/**\n\t\t * Claim the page's single companion slot, or stand down.\n\t\t *\n\t\t * 🔴 TWO COMPANIONS ON ONE PAGE IS A REACHABLE STATE, and it was reached:\n\t\t * `CnAppRoot` renders a companion for any app that sets `aiCompanion`,\n\t\t * while a host app can also mount one standalone on every page of the\n\t\t * instance (Hermiq does exactly this, so the assistant reaches\n\t\t * third-party office editors that have no CnAppRoot of ours). On any\n\t\t * page that has both, the user saw TWO hexes stacked a few pixels apart\n\t\t * — the two mounts pick up different bundled stylesheets, so they do not\n\t\t * even land in the same place.\n\t\t *\n\t\t * The guard lives HERE, in the component, rather than in each host's\n\t\t * mount script, because only the component knows how many of itself\n\t\t * exist. A host-side check cannot see a sibling that mounts later: the\n\t\t * standalone script runs at DOMContentLoaded and the app's own Vue tree\n\t\t * boots after it, so whichever check runs first sees nothing and both\n\t\t * render.\n\t\t *\n\t\t * First to claim wins and the rest render nothing, except that the\n\t\t * app's own companion (with an injected `cnAiContext`) always takes the\n\t\t * slot from a standalone one: the health probes race, so \"first\" is\n\t\t * not stable, and the app's own carries the page context.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\tclaimSingleton() {\n\t\t\t// 🔴 CLAIMED ONLY WHEN THIS INSTANCE WOULD ACTUALLY RENDER.\n\t\t\t//\n\t\t\t// An earlier version claimed in `created()`, before the health probe\n\t\t\t// had answered — so a companion whose probe FAILED still took the\n\t\t\t// slot and stood the other one down, turning \"one companion\" into\n\t\t\t// NONE. Measured on a slow instance, where the probe's 3×5s budget\n\t\t\t// is genuinely marginal: the slot was claimed and nothing rendered.\n\t\t\t//\n\t\t\t// Claiming late is also why the claim is not in a `watch` on the\n\t\t\t// window key: the slot is contended exactly once per page, at the\n\t\t\t// moment each candidate learns it can render.\n\t\t\tif (this.probeSucceeded !== true || this.isChatPage === true || this.embedded) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst scope = typeof window !== 'undefined' ? window : null\n\t\t\tif (scope === null) {\n\t\t\t\t// No window (SSR, a bare unit test): nothing else can be\n\t\t\t\t// rendering, so this instance is the only one by definition.\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (scope[COMPANION_SINGLETON_KEY] === null || scope[COMPANION_SINGLETON_KEY] === undefined) {\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = this\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst holder = scope[COMPANION_SINGLETON_KEY]\n\t\t\tif (holder !== this && this.cnAiContext && !holder.cnAiContext) {\n\t\t\t\t// The app's own companion (inside a CnAppRoot, with the page's\n\t\t\t\t// context) outranks a standalone mount, whichever probe answered\n\t\t\t\t// first; the holder's flag is set directly so a standalone built\n\t\t\t\t// on an older copy of this library stands down too.\n\t\t\t\tholder.isPrimaryCompanion = false\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = this\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.isPrimaryCompanion = holder === this\n\t\t},\n\n\t\t/**\n\t\t * Give the slot back, but only if this instance is holding it.\n\t\t *\n\t\t * Checked rather than cleared unconditionally: a second, standing-down\n\t\t * instance unmounting must not release the slot the FIRST one is still\n\t\t * using, which would let a third mount render alongside it.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\treleaseSingleton() {\n\t\t\tconst scope = typeof window !== 'undefined' ? window : null\n\t\t\tif (scope !== null && scope[COMPANION_SINGLETON_KEY] === this) {\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = null\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Ask the chat backend whether it can answer, and render only if so.\n\t\t *\n\t\t * Skipped without a request when the backend app is not installed for\n\t\t * this user.\n\t\t *\n\t\t * @return {Promise<void>}\n\t\t * @spec openspec/changes/no-calls-to-missing-apps-and-presence-beacon/specs/ai-companion/spec.md#requirement-the-companion-does-not-probe-a-backend-that-is-not-installed\n\t\t */\n\t\tasync runHealthProbe() {\n\t\t\t// RETRY before hiding. A single probe makes the whole companion\n\t\t\t// disappear on one slow response, and \"slow\" is normal: measured on a\n\t\t\t// busy instance (load 48) the health endpoint answered in well under a\n\t\t\t// second, but the request still lost its 5s budget to contention. The\n\t\t\t// failure mode is the worst kind — the widget is simply absent, with\n\t\t\t// nothing on screen saying why, and a reload usually \"fixes\" it, which\n\t\t\t// is what makes it read as flakiness rather than as a probe result.\n\t\t\t//\n\t\t\t// A backend that is genuinely down fails all attempts and is still\n\t\t\t// reported; this only stops one unlucky request from deciding.\n\t\t\t//\n\t\t\t// 🔴 NO PROBE AT AN APP THAT IS NOT THERE. Nextcloud already tells\n\t\t\t// the page which apps the user has (`OC.appswebroots`), so asking a\n\t\t\t// missing backend for its health is a guaranteed 404, three times\n\t\t\t// per page, in every console. Measured on cloud.conduction.nl\n\t\t\t// (round-5 check): hermiq not installed, three\n\t\t\t// `/apps/hermiq/api/chat/health` 404s on every pipelinq and dossiq\n\t\t\t// page. Hidden either way; now hidden without the requests.\n\t\t\tif (!isAppInstalled(this.chatAppId || DEFAULT_CHAT_APP_ID)) {\n\t\t\t\tthis.probeSucceeded = false\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tfor (let attempt = 1; attempt <= HEALTH_PROBE_ATTEMPTS; attempt++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await axios.get(chatHealthUrl(this.chatAppId), {\n\t\t\t\t\t\ttimeout: HEALTH_TIMEOUT,\n\t\t\t\t\t\tvalidateStatus: (status) => status >= 200 && status < 300,\n\t\t\t\t\t})\n\t\t\t\t\tthis.probeSucceeded = response.status >= 200 && response.status < 300\n\t\t\t\t\t// Contend for the page's single slot only now, with a\n\t\t\t\t\t// backend that answered. See claimSingleton().\n\t\t\t\t\tthis.claimSingleton()\n\t\t\t\t\t// A companion built against an older version of this library\n\t\t\t\t\t// cannot read the flag above, so look for one shortly.\n\t\t\t\t\tthis.yieldToACompanionThatCannotYield()\n\t\t\t\t\treturn\n\t\t\t\t} catch {\n\t\t\t\t\tif (attempt < HEALTH_PROBE_ATTEMPTS) {\n\t\t\t\t\t\tawait new Promise((resolve) => {\n\t\t\t\t\t\t\tsetTimeout(resolve, HEALTH_RETRY_DELAY * attempt)\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.info(`[CnAiCompanion] chat backend \"${this.chatAppId}\" health probe did not return 2xx `\n\t\t\t\t\t\t+ `after ${HEALTH_PROBE_ATTEMPTS} attempts — widget hidden`)\n\t\t\t\t\tthis.probeSucceeded = false\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * The hex's own handler: open when closed, close when open.\n\t\t *\n\t\t * The launcher stays visible while the window is open (see the template),\n\t\t * so it has to answer for both directions rather than only opening.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\ttogglePanel() {\n\t\t\tif (this.isPanelOpen) {\n\t\t\t\tthis.closePanel()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.openPanel()\n\t\t},\n\n\t\topenPanel() {\n\t\t\tthis.isPanelOpen = true\n\t\t\tthis.$nextTick(() => {\n\t\t\t\tif (this.$refs.panel && this.$refs.panel.$refs.input) {\n\t\t\t\t\tthis.$refs.panel.$refs.input.focus()\n\t\t\t\t}\n\t\t\t})\n\t\t},\n\n\t\tclosePanel() {\n\t\t\tthis.isPanelOpen = false\n\t\t},\n\n\t\tonSend(text, agentUuid, attachments) {\n\t\t\tthis.stream.send(text, { agentUuid, attachments }).catch((err) => {\n\t\t\t\t// Stream errors are tracked in stream.state.error — no extra handling needed\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.info('[CnAiCompanion] send error:', err?.message)\n\t\t\t})\n\t\t},\n\n\t\tonNewThread() {\n\t\t\tthis.stream.startNewThread()\n\t\t},\n\n\t\tonLoadConversation(uuid) {\n\t\t\tthis.stream.loadConversation(uuid)\n\t\t},\n\n\t\t/**\n\t\t * Passes a titled panel's session controls on to the host card.\n\t\t *\n\t\t * @param {Array} actions The panel's controls as menu actions\n\t\t */\n\t\tonMenu(actions) {\n\t\t\t/**\n\t\t\t * @event menu The session controls of a titled panel, for its card's menu.\n\t\t\t */\n\t\t\tthis.$emit('menu', actions)\n\t\t},\n\t},\n}\n</script>\n\n<style>\n.cn-ai-companion {\n\t/*\n\t * display: contents removes this wrapper from the layout tree so the\n\t * embedded NcAppSidebar inherits NcContent as its flex parent — required\n\t * for the sidebar to slide in from the RIGHT edge. The FAB is itself\n\t * position:fixed so it positions independently of the wrapper's box.\n\t *\n\t * !important is intentional: webpack pulls in BOTH the old (position:\n\t * fixed) and new (display: contents) rules from the package's CJS and\n\t * ESM builds; without !important the old rule wins the cascade and the\n\t * sidebar renders at the left.\n\t */\n\tdisplay: contents !important;\n\tposition: static !important;\n}\n</style>\n"],"names":["CnAiFloatingButton","CnAiChatPanel","t","axios"],"mappings":";;;;;;;;;AAgFA,MAAM,cAAe,GAAE,KAAG;;AAE1B;AACA,MAAM,qBAAoB,GAAI,EAAA;;AAE9B;AACA,MAAM,kBAAiB,GAAI,IAAE;;AAE7B;;AAEC;AACA;AACA;AACA;AACA;;AAED,MAAM,uBAAwB,GAAE,yBAAuB;;AAEvD;;AAEC;;;;AAID,MAAM,oBAAqB,GAAE,KAAG;;AAEhC,aAAe;AACd,CAAA,IAAI,EAAE,eAAe;;CAErB,UAAU,EAAE;AACX,sBAAAA,UAAkB;iBAClBC,YAAa;EACb;;AA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../src/components/CnAiCompanion/CnAiCompanion.vue?vue&type=template&id=50e59b57&lang.js"],"sourcesContent":["<!--\n CnAiCompanion — top-level mount for the AI Chat Companion widget.\n\n On created():\n - Issues GET /index.php/apps/{chatAppId}/api/chat/health via axios.\n - Renders nothing on non-2xx, network error, or timeout (5s).\n - Probe result cached for component lifetime.\n - Only console.info() on failure (never warn/error).\n\n When probe succeeds:\n - Renders CnAiFloatingButton ALWAYS — it toggles the window rather than only\n opening it, and stays visible while the window is open.\n - Renders CnAiChatPanel (when isPanelOpen) as a floating window anchored to the\n same corner as the hex, offset clear of it so both stay clickable.\n\n FAB and panel both hidden when cnAiContext.pageKind === 'chat'.\n-->\n<template>\n\t<div\n\t\tv-if=\"probeSucceeded && !isChatPage && (embedded || isPrimaryCompanion)\"\n\t\tclass=\"cn-ai-companion\"\n\t\t:class=\"{ 'cn-ai-companion--embedded': embedded }\"\n\t\t:data-testid=\"embedded ? 'cn-ai-companion-embedded' : 'cn-ai-companion'\">\n\t\t<!--\n\t\t The hex is rendered UNCONDITIONALLY and toggles the window.\n\n\t\t It used to be `:visible=\"!isPanelOpen\"` — the launcher vanished while\n\t\t the thing it launched was open. Three reasons it now stays, in order of\n\t\t weight:\n\n\t\t 1. It is the one control we can guarantee. The window's own close\n\t\t button lives in markup a host page's stylesheet could hide; the hex\n\t\t is fixed-position with explicit `!important` properties and has\n\t\t survived every host it has been dropped into, including third-party\n\t\t office editors.\n\t\t 2. A launcher that disappears is a dead end — the affordance you used\n\t\t to summon something should dismiss it.\n\t\t 3. It removes a state transition: no show/hide to coordinate with the\n\t\t window's own.\n\n\t\t ⚠️ This is why the window anchors 70px from the edge: the hex is 26x30\n\t\t at a 24px inset, and the two must not overlap or the guarantee above is\n\t\t worth nothing.\n\t\t-->\n\t\t<CnAiFloatingButton\n\t\t\tv-if=\"!embedded\"\n\t\t\t:visible=\"true\"\n\t\t\t:position=\"position\"\n\t\t\t@click=\"togglePanel\" />\n\t\t<CnAiChatPanel\n\t\t\tref=\"panel\"\n\t\t\t:visible=\"embedded || isPanelOpen\"\n\t\t\t:embedded=\"embedded\"\n\t\t\t:titled=\"titled\"\n\t\t\t:note=\"note\"\n\t\t\t:inputPlaceholder=\"inputPlaceholder\"\n\t\t\t:sendLabel=\"sendLabel\"\n\t\t\t:streamState=\"stream.state\"\n\t\t\t:chatAppId=\"chatAppId\"\n\t\t\t:context=\"effectiveContext\"\n\t\t\t:position=\"position\"\n\t\t\t:fabRef=\"$refs.fabButton\"\n\t\t\t@close=\"closePanel\"\n\t\t\t@send=\"onSend\"\n\t\t\t@newThread=\"onNewThread\"\n\t\t\t@loadConversation=\"onLoadConversation\"\n\t\t\t@menu=\"onMenu\" />\n\t</div>\n</template>\n\n<script>\nimport axios from '@nextcloud/axios'\nimport { translate as t } from '@nextcloud/l10n'\nimport CnAiChatPanel from './CnAiChatPanel.vue'\nimport CnAiFloatingButton from './CnAiFloatingButton.vue'\nimport { chatHealthUrl, DEFAULT_CHAT_APP_ID } from '../../composables/aiChatConfig.js'\nimport { useAiChatStream } from '../../composables/useAiChatStream.js'\nimport { ensureTranslations } from '../../l10n/index.js'\nimport { isAppInstalled } from '../../utils/appInstalled.js'\n\nconst HEALTH_TIMEOUT = 5000\n\n/** How many times the health probe may fail before the companion hides. */\nconst HEALTH_PROBE_ATTEMPTS = 3\n\n/** Base backoff between probe attempts, multiplied by the attempt number. */\nconst HEALTH_RETRY_DELAY = 750\n\n/**\n * The window key one companion claims so a second one stands down.\n *\n * On `window` rather than in module scope, because the two companions on a page\n * do not share a module instance: one comes from the host app's bundle and one\n * from a standalone bundle attached to every page. Two copies of this file are\n * loaded, so a module-level flag would be two flags and would guard nothing.\n */\nconst COMPANION_SINGLETON_KEY = '__cnAiCompanionPrimary'\n\n/**\n * How long to wait before looking for a companion that cannot stand down.\n *\n * Long enough for a host app's Vue tree to boot after a standalone mount at\n * DOMContentLoaded, short enough that a user never sees two hexes settle.\n */\nconst LEGACY_SIBLING_DELAY = 1200\n\nexport default {\n\tname: 'CnAiCompanion',\n\n\tcomponents: {\n\t\tCnAiFloatingButton,\n\t\tCnAiChatPanel,\n\t},\n\n\tinject: {\n\t\tcnAiContext: { default: null },\n\t\thostTranslate: { from: 'cnTranslate', default: null },\n\t},\n\n\t/**\n\t * The companion's buttons and panel ask `cnTranslate` for their labels.\n\t * Mounted on another app's page (Hermiq's companion on every page) no\n\t * host provides one, so a label the host leaves untranslated is read from\n\t * the library's own catalogue.\n\t *\n\t * @return {object} The provided values.\n\t * @spec openspec/changes/ai-companion-library-labels/specs/ai-chat-companion/spec.md#requirement-the-companion-reads-in-the-users-language-on-any-page\n\t */\n\tprovide() {\n\t\tensureTranslations()\n\t\tconst host = typeof this.hostTranslate === 'function' ? this.hostTranslate : null\n\t\treturn {\n\t\t\tcnTranslate: (text, vars) => {\n\t\t\t\tconst hosted = host ? host(text, vars) : text\n\t\t\t\treturn hosted !== text ? hosted : t('nextcloud-vue', text, vars)\n\t\t\t},\n\t\t}\n\t},\n\n\tprops: {\n\t\t/**\n\t\t * Default position for the FAB.\n\t\t *\n\t\t * @type {'bottom-right'|'bottom-left'|'top-right'|'top-left'}\n\t\t */\n\t\tposition: {\n\t\t\ttype: String,\n\t\t\tdefault: 'bottom-right',\n\t\t},\n\n\t\t/**\n\t\t * Backend app id that answers the chat/health/conversation HTTP calls\n\t\t * (`/index.php/apps/{chatAppId}/api/...`). Single configuration point for\n\t\t * the AI Chat Companion's backend — see composables/aiChatConfig.js.\n\t\t * Defaults to `hermiq` (the agent engine's home per hydra ADR-034\n\t\t * \"Amendment 2026-07-05\"); `CnAppRoot` forwards its own `chatAppId`\n\t\t * prop here so a consuming app can point the widget at another backend\n\t\t * (e.g. `openregister` during its compat window) in one place.\n\t\t *\n\t\t * @type {string}\n\t\t */\n\t\tchatAppId: {\n\t\t\ttype: String,\n\t\t\tdefault: DEFAULT_CHAT_APP_ID,\n\t\t},\n\n\t\t/**\n\t\t * What the user is looking at, stated by whoever mounted the companion.\n\t\t *\n\t\t * Inside a Conduction app, CnAppRoot provides this and the prop is\n\t\t * unnecessary. Mounted standalone on a page belonging to another app —\n\t\t * an office editor, the Files list — there is no provider, and the\n\t\t * injected fallback reports `appId: 'unknown'`. The agent then has no\n\t\t * idea what \"this document\" refers to and says so.\n\t\t *\n\t\t * Shape mirrors the injected context: `{ appId, pageKind, fileId,\n\t\t * objectUuid, registerSlug, schemaSlug, route }`. All optional; whatever\n\t\t * the host knows is better than 'unknown'.\n\t\t *\n\t\t * @type {object|null}\n\t\t */\n\t\tcontext: {\n\t\t\ttype: Object,\n\t\t\tdefault: null,\n\t\t},\n\n\t\t/**\n\t\t * Render the chat as a panel of the page (a tab, a card) instead of the\n\t\t * launcher hex and its floating window. An embedded chat is always\n\t\t * open, has no launcher, and does not take the page's single companion\n\t\t * slot, so the floating companion keeps working beside it.\n\t\t *\n\t\t * @type {boolean}\n\t\t */\n\t\tembedded: {\n\t\t\ttype: Boolean,\n\t\t\tdefault: false,\n\t\t},\n\n\t\t/** An embedded chat in a card that draws its title; see CnAiChatPanel `titled`. */\n\t\ttitled: {\n\t\t\ttype: Boolean,\n\t\t\tdefault: false,\n\t\t},\n\n\t\t/** A line above the input, already translated. */\n\t\tnote: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** The input's placeholder, already translated. */\n\t\tinputPlaceholder: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** A label on the send button, already translated. */\n\t\tsendLabel: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\t},\n\n\temits: ['menu'],\n\n\tdata() {\n\t\treturn {\n\t\t\tprobeSucceeded: false,\n\t\t\tisPanelOpen: false,\n\t\t\tisPrimaryCompanion: false,\n\t\t\t// Cleared on unmount so a torn-down companion cannot stand itself\n\t\t\t// down after the fact.\n\t\t\tlegacySiblingTimer: null,\n\t\t\tstream: useAiChatStream(this, { chatAppId: this.chatAppId, context: this.context }),\n\t\t}\n\t},\n\n\tcomputed: {\n\t\tisChatPage() {\n\t\t\tconst ctx = this.cnAiContext\n\t\t\treturn ctx && ctx.pageKind === 'chat'\n\t\t},\n\n\t\t/**\n\t\t * The page context the panel reasons with: the prop when a standalone\n\t\t * mount passed one, otherwise the context CnAppRoot provides.\n\t\t *\n\t\t * WHY THIS EXISTS\n\t\t * ---------------\n\t\t * `CnAppRoot` renders `<CnAiCompanion :chatAppId=\"chatAppId\" />` and\n\t\t * passes NO `:context`, because it already provides `cnAiContext` for\n\t\t * descendants to inject. This component injected it for `isChatPage`\n\t\t * but handed the panel the raw `context` PROP, which is `null` in that\n\t\t * arrangement — so inside every app shell the panel ran with no\n\t\t * context at all.\n\t\t *\n\t\t * The panel's `relevantAgentOptions` treats an empty context as \"no\n\t\t * page to be relevant to\" and returns EVERY agent, so it selected\n\t\t * whichever agent the API happened to list first. Measured on the\n\t\t * demo instance 2026-09-20: on `/apps/buildiq/` the companion opened\n\t\t * as \"Hydra Triage\", which holds only `hydra.*` tools, and its first\n\t\t * answer was \"This agent's tool grants resolve to no tools\" — while\n\t\t * \"Buildiq builder\", holding all eight `buildiq_*` tools, sat unused\n\t\t * at the bottom of the same list.\n\t\t *\n\t\t * A standalone mount that passes `context` explicitly still wins, so\n\t\t * Hermiq's cross-app companion is unaffected.\n\t\t *\n\t\t * @return {object|null} The context to reason with.\n\t\t */\n\t\teffectiveContext() {\n\t\t\treturn this.context || this.cnAiContext || null\n\t\t},\n\t},\n\n\tcreated() {\n\t\tthis.runHealthProbe()\n\t},\n\n\tbeforeUnmount() {\n\t\tif (this.legacySiblingTimer !== null) {\n\t\t\tclearTimeout(this.legacySiblingTimer)\n\t\t\tthis.legacySiblingTimer = null\n\t\t}\n\n\t\tthis.releaseSingleton()\n\t},\n\n\tmethods: {\n\t\t/**\n\t\t * Stand down if another companion is on the page that cannot stand down.\n\t\t *\n\t\t * 🔴 THE WINDOW FLAG ONLY BINDS INSTANCES THAT CHECK IT. Measured on a\n\t\t * live instance after shipping the flag: still TWO hexes, stacked at the\n\t\t * same coordinates — one from `#openregister` (the host app's own bundle,\n\t\t * built against an older version of this library) and one from\n\t\t * `#hermiq-companion-root` (the standalone mount, built against the new\n\t\t * one). The old bundle never reads the flag, so it renders regardless,\n\t\t * and the guarded instance had already claimed the slot and rendered too.\n\t\t *\n\t\t * The library fix alone therefore does not reach a page until EVERY app\n\t\t * on it has rebuilt — which is not something a user with a double hex\n\t\t * can wait for. So the instance that CAN yield does.\n\t\t *\n\t\t * Deferred rather than checked at mount, because order is against us: a\n\t\t * standalone companion mounts at DOMContentLoaded and the host app's Vue\n\t\t * tree boots after it, so at mount time there is nothing to see.\n\t\t *\n\t\t * When both companions carry this guard the flag has already stopped the\n\t\t * second one, so this never fires — it is strictly a bridge for mixed\n\t\t * versions, and it costs one timeout.\n\t\t */\n\t\tyieldToACompanionThatCannotYield() {\n\t\t\tif (typeof document === 'undefined' || this.isPrimaryCompanion !== true || this.embedded) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.legacySiblingTimer = setTimeout(() => {\n\t\t\t\tthis.legacySiblingTimer = null\n\n\t\t\t\tconst rendered = document.querySelectorAll('[data-testid=\"cn-ai-companion\"]')\n\t\t\t\tif (rendered.length <= 1) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tfor (const el of rendered) {\n\t\t\t\t\tif (el !== this.$el) {\n\t\t\t\t\t\t// Yield to it: the host app's own companion sits inside\n\t\t\t\t\t\t// that app's tree and carries its page context, which a\n\t\t\t\t\t\t// standalone mount can only approximate.\n\t\t\t\t\t\tthis.releaseSingleton()\n\t\t\t\t\t\tthis.isPrimaryCompanion = false\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, LEGACY_SIBLING_DELAY)\n\t\t},\n\n\t\t/**\n\t\t * Claim the page's single companion slot, or stand down.\n\t\t *\n\t\t * 🔴 TWO COMPANIONS ON ONE PAGE IS A REACHABLE STATE, and it was reached:\n\t\t * `CnAppRoot` renders a companion for any app that sets `aiCompanion`,\n\t\t * while a host app can also mount one standalone on every page of the\n\t\t * instance (Hermiq does exactly this, so the assistant reaches\n\t\t * third-party office editors that have no CnAppRoot of ours). On any\n\t\t * page that has both, the user saw TWO hexes stacked a few pixels apart\n\t\t * — the two mounts pick up different bundled stylesheets, so they do not\n\t\t * even land in the same place.\n\t\t *\n\t\t * The guard lives HERE, in the component, rather than in each host's\n\t\t * mount script, because only the component knows how many of itself\n\t\t * exist. A host-side check cannot see a sibling that mounts later: the\n\t\t * standalone script runs at DOMContentLoaded and the app's own Vue tree\n\t\t * boots after it, so whichever check runs first sees nothing and both\n\t\t * render.\n\t\t *\n\t\t * First to claim wins and the rest render nothing, except that the\n\t\t * app's own companion (with an injected `cnAiContext`) always takes the\n\t\t * slot from a standalone one: the health probes race, so \"first\" is\n\t\t * not stable, and the app's own carries the page context.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\tclaimSingleton() {\n\t\t\t// 🔴 CLAIMED ONLY WHEN THIS INSTANCE WOULD ACTUALLY RENDER.\n\t\t\t//\n\t\t\t// An earlier version claimed in `created()`, before the health probe\n\t\t\t// had answered — so a companion whose probe FAILED still took the\n\t\t\t// slot and stood the other one down, turning \"one companion\" into\n\t\t\t// NONE. Measured on a slow instance, where the probe's 3×5s budget\n\t\t\t// is genuinely marginal: the slot was claimed and nothing rendered.\n\t\t\t//\n\t\t\t// Claiming late is also why the claim is not in a `watch` on the\n\t\t\t// window key: the slot is contended exactly once per page, at the\n\t\t\t// moment each candidate learns it can render.\n\t\t\tif (this.probeSucceeded !== true || this.isChatPage === true || this.embedded) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst scope = typeof window !== 'undefined' ? window : null\n\t\t\tif (scope === null) {\n\t\t\t\t// No window (SSR, a bare unit test): nothing else can be\n\t\t\t\t// rendering, so this instance is the only one by definition.\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (scope[COMPANION_SINGLETON_KEY] === null || scope[COMPANION_SINGLETON_KEY] === undefined) {\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = this\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst holder = scope[COMPANION_SINGLETON_KEY]\n\t\t\tif (holder !== this && this.cnAiContext && !holder.cnAiContext) {\n\t\t\t\t// The app's own companion (inside a CnAppRoot, with the page's\n\t\t\t\t// context) outranks a standalone mount, whichever probe answered\n\t\t\t\t// first; the holder's flag is set directly so a standalone built\n\t\t\t\t// on an older copy of this library stands down too.\n\t\t\t\tholder.isPrimaryCompanion = false\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = this\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.isPrimaryCompanion = holder === this\n\t\t},\n\n\t\t/**\n\t\t * Give the slot back, but only if this instance is holding it.\n\t\t *\n\t\t * Checked rather than cleared unconditionally: a second, standing-down\n\t\t * instance unmounting must not release the slot the FIRST one is still\n\t\t * using, which would let a third mount render alongside it.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\treleaseSingleton() {\n\t\t\tconst scope = typeof window !== 'undefined' ? window : null\n\t\t\tif (scope !== null && scope[COMPANION_SINGLETON_KEY] === this) {\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = null\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Ask the chat backend whether it can answer, and render only if so.\n\t\t *\n\t\t * Skipped without a request when the backend app is not installed for\n\t\t * this user.\n\t\t *\n\t\t * @return {Promise<void>}\n\t\t * @spec openspec/changes/no-calls-to-missing-apps-and-presence-beacon/specs/ai-companion/spec.md#requirement-the-companion-does-not-probe-a-backend-that-is-not-installed\n\t\t */\n\t\tasync runHealthProbe() {\n\t\t\t// RETRY before hiding. A single probe makes the whole companion\n\t\t\t// disappear on one slow response, and \"slow\" is normal: measured on a\n\t\t\t// busy instance (load 48) the health endpoint answered in well under a\n\t\t\t// second, but the request still lost its 5s budget to contention. The\n\t\t\t// failure mode is the worst kind — the widget is simply absent, with\n\t\t\t// nothing on screen saying why, and a reload usually \"fixes\" it, which\n\t\t\t// is what makes it read as flakiness rather than as a probe result.\n\t\t\t//\n\t\t\t// A backend that is genuinely down fails all attempts and is still\n\t\t\t// reported; this only stops one unlucky request from deciding.\n\t\t\t//\n\t\t\t// 🔴 NO PROBE AT AN APP THAT IS NOT THERE. Nextcloud already tells\n\t\t\t// the page which apps the user has (`OC.appswebroots`), so asking a\n\t\t\t// missing backend for its health is a guaranteed 404, three times\n\t\t\t// per page, in every console. Measured on cloud.conduction.nl\n\t\t\t// (round-5 check): hermiq not installed, three\n\t\t\t// `/apps/hermiq/api/chat/health` 404s on every pipelinq and dossiq\n\t\t\t// page. Hidden either way; now hidden without the requests.\n\t\t\tif (!isAppInstalled(this.chatAppId || DEFAULT_CHAT_APP_ID)) {\n\t\t\t\tthis.probeSucceeded = false\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tfor (let attempt = 1; attempt <= HEALTH_PROBE_ATTEMPTS; attempt++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await axios.get(chatHealthUrl(this.chatAppId), {\n\t\t\t\t\t\ttimeout: HEALTH_TIMEOUT,\n\t\t\t\t\t\tvalidateStatus: (status) => status >= 200 && status < 300,\n\t\t\t\t\t})\n\t\t\t\t\tthis.probeSucceeded = response.status >= 200 && response.status < 300\n\t\t\t\t\t// Contend for the page's single slot only now, with a\n\t\t\t\t\t// backend that answered. See claimSingleton().\n\t\t\t\t\tthis.claimSingleton()\n\t\t\t\t\t// A companion built against an older version of this library\n\t\t\t\t\t// cannot read the flag above, so look for one shortly.\n\t\t\t\t\tthis.yieldToACompanionThatCannotYield()\n\t\t\t\t\treturn\n\t\t\t\t} catch {\n\t\t\t\t\tif (attempt < HEALTH_PROBE_ATTEMPTS) {\n\t\t\t\t\t\tawait new Promise((resolve) => {\n\t\t\t\t\t\t\tsetTimeout(resolve, HEALTH_RETRY_DELAY * attempt)\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.info(`[CnAiCompanion] chat backend \"${this.chatAppId}\" health probe did not return 2xx `\n\t\t\t\t\t\t+ `after ${HEALTH_PROBE_ATTEMPTS} attempts — widget hidden`)\n\t\t\t\t\tthis.probeSucceeded = false\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * The hex's own handler: open when closed, close when open.\n\t\t *\n\t\t * The launcher stays visible while the window is open (see the template),\n\t\t * so it has to answer for both directions rather than only opening.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\ttogglePanel() {\n\t\t\tif (this.isPanelOpen) {\n\t\t\t\tthis.closePanel()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.openPanel()\n\t\t},\n\n\t\topenPanel() {\n\t\t\tthis.isPanelOpen = true\n\t\t\tthis.$nextTick(() => {\n\t\t\t\tif (this.$refs.panel && this.$refs.panel.$refs.input) {\n\t\t\t\t\tthis.$refs.panel.$refs.input.focus()\n\t\t\t\t}\n\t\t\t})\n\t\t},\n\n\t\tclosePanel() {\n\t\t\tthis.isPanelOpen = false\n\t\t},\n\n\t\tonSend(text, agentUuid, attachments) {\n\t\t\tthis.stream.send(text, { agentUuid, attachments }).catch((err) => {\n\t\t\t\t// Stream errors are tracked in stream.state.error — no extra handling needed\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.info('[CnAiCompanion] send error:', err?.message)\n\t\t\t})\n\t\t},\n\n\t\tonNewThread() {\n\t\t\tthis.stream.startNewThread()\n\t\t},\n\n\t\tonLoadConversation(uuid) {\n\t\t\tthis.stream.loadConversation(uuid)\n\t\t},\n\n\t\t/**\n\t\t * Passes a titled panel's session controls on to the host card.\n\t\t *\n\t\t * @param {Array} actions The panel's controls as menu actions\n\t\t */\n\t\tonMenu(actions) {\n\t\t\t/**\n\t\t\t * @event menu The session controls of a titled panel, for its card's menu.\n\t\t\t */\n\t\t\tthis.$emit('menu', actions)\n\t\t},\n\t},\n}\n</script>\n\n<style>\n.cn-ai-companion {\n\t/*\n\t * display: contents removes this wrapper from the layout tree so the\n\t * embedded NcAppSidebar inherits NcContent as its flex parent — required\n\t * for the sidebar to slide in from the RIGHT edge. The FAB is itself\n\t * position:fixed so it positions independently of the wrapper's box.\n\t *\n\t * !important is intentional: webpack pulls in BOTH the old (position:\n\t * fixed) and new (display: contents) rules from the package's CJS and\n\t * ESM builds; without !important the old rule wins the cascade and the\n\t * sidebar renders at the left.\n\t */\n\tdisplay: contents !important;\n\tposition: static !important;\n}\n</style>\n"],"names":["_normalizeClass","_createVNode"],"mappings":";;;;;;;;AAoCQ,EAAA,OAAA,CAAA,KAAA,CAAA,cAAc,IAAK,CAAA,QAAA,CAAA,UAAU,KAAK,MAAA,CAAA,QAAE,IAAA,KAAA,CAAA,kBAAA,CAAA;;;aACrC,EAAAA,cAAA,CAAA,CAAC,iBAAkB,EAAA,EAAA,2BAAA,EACP,MAAA,CAAA,QAAA,EAAA,CAAA,CAAA;;;UAwBT,MAAQ,CAAA,QAAA;qCAGQ,CAAA,6BAAA,EAAA;;AAFtB,cAAA,OAAO,EAAE,IAAG;AACZ,cAAA,QAAQ,EAAE,MAAQ,CAAA,QAAA;AAClB,cAAA,OAAK,EAAE,QAAW,CAAA,WAAA;;;QACnBC;AACA,UAAA,GAAG,EAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"CnAiCompanion.vue3.js","sources":["../../../../src/components/CnAiCompanion/CnAiCompanion.vue?vue&type=template&id=2228571d&lang.js"],"sourcesContent":["<!--\n CnAiCompanion — top-level mount for the AI Chat Companion widget.\n\n On created():\n - Issues GET /index.php/apps/{chatAppId}/api/chat/health via axios.\n - Renders nothing on non-2xx, network error, or timeout (5s).\n - Probe result cached for component lifetime.\n - Only console.info() on failure (never warn/error).\n\n When probe succeeds:\n - Renders CnAiFloatingButton ALWAYS — it toggles the window rather than only\n opening it, and stays visible while the window is open.\n - Renders CnAiChatPanel (when isPanelOpen) as a floating window anchored to the\n same corner as the hex, offset clear of it so both stay clickable.\n\n FAB and panel both hidden when cnAiContext.pageKind === 'chat'.\n-->\n<template>\n\t<div\n\t\tv-if=\"probeSucceeded && !isChatPage && (embedded || isPrimaryCompanion)\"\n\t\tclass=\"cn-ai-companion\"\n\t\t:class=\"{ 'cn-ai-companion--embedded': embedded }\"\n\t\t:data-testid=\"embedded ? 'cn-ai-companion-embedded' : 'cn-ai-companion'\">\n\t\t<!--\n\t\t The hex is rendered UNCONDITIONALLY and toggles the window.\n\n\t\t It used to be `:visible=\"!isPanelOpen\"` — the launcher vanished while\n\t\t the thing it launched was open. Three reasons it now stays, in order of\n\t\t weight:\n\n\t\t 1. It is the one control we can guarantee. The window's own close\n\t\t button lives in markup a host page's stylesheet could hide; the hex\n\t\t is fixed-position with explicit `!important` properties and has\n\t\t survived every host it has been dropped into, including third-party\n\t\t office editors.\n\t\t 2. A launcher that disappears is a dead end — the affordance you used\n\t\t to summon something should dismiss it.\n\t\t 3. It removes a state transition: no show/hide to coordinate with the\n\t\t window's own.\n\n\t\t ⚠️ This is why the window anchors 70px from the edge: the hex is 26x30\n\t\t at a 24px inset, and the two must not overlap or the guarantee above is\n\t\t worth nothing.\n\t\t-->\n\t\t<CnAiFloatingButton\n\t\t\tv-if=\"!embedded\"\n\t\t\t:visible=\"true\"\n\t\t\t:position=\"position\"\n\t\t\t@click=\"togglePanel\" />\n\t\t<CnAiChatPanel\n\t\t\tref=\"panel\"\n\t\t\t:visible=\"embedded || isPanelOpen\"\n\t\t\t:embedded=\"embedded\"\n\t\t\t:titled=\"titled\"\n\t\t\t:note=\"note\"\n\t\t\t:inputPlaceholder=\"inputPlaceholder\"\n\t\t\t:sendLabel=\"sendLabel\"\n\t\t\t:streamState=\"stream.state\"\n\t\t\t:chatAppId=\"chatAppId\"\n\t\t\t:context=\"effectiveContext\"\n\t\t\t:position=\"position\"\n\t\t\t:fabRef=\"$refs.fabButton\"\n\t\t\t@close=\"closePanel\"\n\t\t\t@send=\"onSend\"\n\t\t\t@newThread=\"onNewThread\"\n\t\t\t@loadConversation=\"onLoadConversation\"\n\t\t\t@menu=\"onMenu\" />\n\t</div>\n</template>\n\n<script>\nimport axios from '@nextcloud/axios'\nimport { translate as t } from '@nextcloud/l10n'\nimport CnAiChatPanel from './CnAiChatPanel.vue'\nimport CnAiFloatingButton from './CnAiFloatingButton.vue'\nimport { chatHealthUrl, DEFAULT_CHAT_APP_ID } from '../../composables/aiChatConfig.js'\nimport { useAiChatStream } from '../../composables/useAiChatStream.js'\nimport { ensureTranslations } from '../../l10n/index.js'\nimport { isAppInstalled } from '../../utils/appInstalled.js'\n\nconst HEALTH_TIMEOUT = 5000\n\n/** How many times the health probe may fail before the companion hides. */\nconst HEALTH_PROBE_ATTEMPTS = 3\n\n/** Base backoff between probe attempts, multiplied by the attempt number. */\nconst HEALTH_RETRY_DELAY = 750\n\n/**\n * The window key one companion claims so a second one stands down.\n *\n * On `window` rather than in module scope, because the two companions on a page\n * do not share a module instance: one comes from the host app's bundle and one\n * from a standalone bundle attached to every page. Two copies of this file are\n * loaded, so a module-level flag would be two flags and would guard nothing.\n */\nconst COMPANION_SINGLETON_KEY = '__cnAiCompanionPrimary'\n\n/**\n * How long to wait before looking for a companion that cannot stand down.\n *\n * Long enough for a host app's Vue tree to boot after a standalone mount at\n * DOMContentLoaded, short enough that a user never sees two hexes settle.\n */\nconst LEGACY_SIBLING_DELAY = 1200\n\nexport default {\n\tname: 'CnAiCompanion',\n\n\tcomponents: {\n\t\tCnAiFloatingButton,\n\t\tCnAiChatPanel,\n\t},\n\n\tinject: {\n\t\tcnAiContext: { default: null },\n\t\thostTranslate: { from: 'cnTranslate', default: null },\n\t},\n\n\t/**\n\t * The companion's buttons and panel ask `cnTranslate` for their labels.\n\t * Mounted on another app's page (Hermiq's companion on every page) no\n\t * host provides one, so a label the host leaves untranslated is read from\n\t * the library's own catalogue.\n\t *\n\t * @return {object} The provided values.\n\t * @spec openspec/changes/ai-companion-library-labels/specs/ai-chat-companion/spec.md#requirement-the-companion-reads-in-the-users-language-on-any-page\n\t */\n\tprovide() {\n\t\tensureTranslations()\n\t\tconst host = typeof this.hostTranslate === 'function' ? this.hostTranslate : null\n\t\treturn {\n\t\t\tcnTranslate: (text, vars) => {\n\t\t\t\tconst hosted = host ? host(text, vars) : text\n\t\t\t\treturn hosted !== text ? hosted : t('nextcloud-vue', text, vars)\n\t\t\t},\n\t\t}\n\t},\n\n\tprops: {\n\t\t/**\n\t\t * Default position for the FAB.\n\t\t *\n\t\t * @type {'bottom-right'|'bottom-left'|'top-right'|'top-left'}\n\t\t */\n\t\tposition: {\n\t\t\ttype: String,\n\t\t\tdefault: 'bottom-right',\n\t\t},\n\n\t\t/**\n\t\t * Backend app id that answers the chat/health/conversation HTTP calls\n\t\t * (`/index.php/apps/{chatAppId}/api/...`). Single configuration point for\n\t\t * the AI Chat Companion's backend — see composables/aiChatConfig.js.\n\t\t * Defaults to `hermiq` (the agent engine's home per hydra ADR-034\n\t\t * \"Amendment 2026-07-05\"); `CnAppRoot` forwards its own `chatAppId`\n\t\t * prop here so a consuming app can point the widget at another backend\n\t\t * (e.g. `openregister` during its compat window) in one place.\n\t\t *\n\t\t * @type {string}\n\t\t */\n\t\tchatAppId: {\n\t\t\ttype: String,\n\t\t\tdefault: DEFAULT_CHAT_APP_ID,\n\t\t},\n\n\t\t/**\n\t\t * What the user is looking at, stated by whoever mounted the companion.\n\t\t *\n\t\t * Inside a Conduction app, CnAppRoot provides this and the prop is\n\t\t * unnecessary. Mounted standalone on a page belonging to another app —\n\t\t * an office editor, the Files list — there is no provider, and the\n\t\t * injected fallback reports `appId: 'unknown'`. The agent then has no\n\t\t * idea what \"this document\" refers to and says so.\n\t\t *\n\t\t * Shape mirrors the injected context: `{ appId, pageKind, fileId,\n\t\t * objectUuid, registerSlug, schemaSlug, route }`. All optional; whatever\n\t\t * the host knows is better than 'unknown'.\n\t\t *\n\t\t * @type {object|null}\n\t\t */\n\t\tcontext: {\n\t\t\ttype: Object,\n\t\t\tdefault: null,\n\t\t},\n\n\t\t/**\n\t\t * Render the chat as a panel of the page (a tab, a card) instead of the\n\t\t * launcher hex and its floating window. An embedded chat is always\n\t\t * open, has no launcher, and does not take the page's single companion\n\t\t * slot, so the floating companion keeps working beside it.\n\t\t *\n\t\t * @type {boolean}\n\t\t */\n\t\tembedded: {\n\t\t\ttype: Boolean,\n\t\t\tdefault: false,\n\t\t},\n\n\t\t/** An embedded chat in a card that draws its title; see CnAiChatPanel `titled`. */\n\t\ttitled: {\n\t\t\ttype: Boolean,\n\t\t\tdefault: false,\n\t\t},\n\n\t\t/** A line above the input, already translated. */\n\t\tnote: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** The input's placeholder, already translated. */\n\t\tinputPlaceholder: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/** A label on the send button, already translated. */\n\t\tsendLabel: {\n\t\t\ttype: String,\n\t\t\tdefault: '',\n\t\t},\n\n\t\t/**\n\t\t * Open the user's latest session about the page's record (the context's\n\t\t * `objectUuid`) instead of an empty thread, with its pending approvals.\n\t\t * No such session, or one about another record, leaves the thread empty.\n\t\t */\n\t\topenSubjectSession: {\n\t\t\ttype: Boolean,\n\t\t\tdefault: false,\n\t\t},\n\t},\n\n\temits: ['menu'],\n\n\tdata() {\n\t\treturn {\n\t\t\tprobeSucceeded: false,\n\t\t\tisPanelOpen: false,\n\t\t\tisPrimaryCompanion: false,\n\t\t\t// Cleared on unmount so a torn-down companion cannot stand itself\n\t\t\t// down after the fact.\n\t\t\tlegacySiblingTimer: null,\n\t\t\t// The record whose session was last asked for, so it is asked once.\n\t\t\topenedSubjectUuid: '',\n\t\t\tstream: useAiChatStream(this, { chatAppId: this.chatAppId, context: this.context }),\n\t\t}\n\t},\n\n\tcomputed: {\n\t\tisChatPage() {\n\t\t\tconst ctx = this.cnAiContext\n\t\t\treturn ctx && ctx.pageKind === 'chat'\n\t\t},\n\n\t\t/**\n\t\t * The page context the panel reasons with: the prop when a standalone\n\t\t * mount passed one, otherwise the context CnAppRoot provides.\n\t\t *\n\t\t * WHY THIS EXISTS\n\t\t * ---------------\n\t\t * `CnAppRoot` renders `<CnAiCompanion :chatAppId=\"chatAppId\" />` and\n\t\t * passes NO `:context`, because it already provides `cnAiContext` for\n\t\t * descendants to inject. This component injected it for `isChatPage`\n\t\t * but handed the panel the raw `context` PROP, which is `null` in that\n\t\t * arrangement — so inside every app shell the panel ran with no\n\t\t * context at all.\n\t\t *\n\t\t * The panel's `relevantAgentOptions` treats an empty context as \"no\n\t\t * page to be relevant to\" and returns EVERY agent, so it selected\n\t\t * whichever agent the API happened to list first. Measured on the\n\t\t * demo instance 2026-09-20: on `/apps/buildiq/` the companion opened\n\t\t * as \"Hydra Triage\", which holds only `hydra.*` tools, and its first\n\t\t * answer was \"This agent's tool grants resolve to no tools\" — while\n\t\t * \"Buildiq builder\", holding all eight `buildiq_*` tools, sat unused\n\t\t * at the bottom of the same list.\n\t\t *\n\t\t * A standalone mount that passes `context` explicitly still wins, so\n\t\t * Hermiq's cross-app companion is unaffected.\n\t\t *\n\t\t * @return {object|null} The context to reason with.\n\t\t */\n\t\teffectiveContext() {\n\t\t\treturn this.context || this.cnAiContext || null\n\t\t},\n\n\t\t/**\n\t\t * The record whose session to open: the context's `objectUuid` once the\n\t\t * backend answered, when the companion opts in; '' otherwise.\n\t\t *\n\t\t * @return {string} The record's uuid or ''.\n\t\t * @spec openspec/changes/ai-chat-opens-the-subject-session/specs/ai-companion/spec.md#requirement-an-embedded-chat-may-open-the-users-session-about-the-pages-record\n\t\t */\n\t\tsubjectUuid() {\n\t\t\tconst uuid = this.effectiveContext && this.effectiveContext.objectUuid\n\t\t\treturn (this.openSubjectSession && this.probeSucceeded && typeof uuid === 'string') ? uuid : ''\n\t\t},\n\t},\n\n\twatch: {\n\t\t/**\n\t\t * Open the session about the record once it is known, once per record.\n\t\t *\n\t\t * @param {string} uuid The record's uuid or ''.\n\t\t * @spec openspec/changes/ai-chat-opens-the-subject-session/specs/ai-companion/spec.md#requirement-an-embedded-chat-may-open-the-users-session-about-the-pages-record\n\t\t */\n\t\tsubjectUuid(uuid) {\n\t\t\tif (uuid !== '' && uuid !== this.openedSubjectUuid) {\n\t\t\t\tthis.openedSubjectUuid = uuid\n\t\t\t\tthis.stream.loadSubjectSession(uuid)\n\t\t\t}\n\t\t},\n\t},\n\n\tcreated() {\n\t\tthis.runHealthProbe()\n\t},\n\n\tbeforeUnmount() {\n\t\tif (this.legacySiblingTimer !== null) {\n\t\t\tclearTimeout(this.legacySiblingTimer)\n\t\t\tthis.legacySiblingTimer = null\n\t\t}\n\n\t\tthis.releaseSingleton()\n\t},\n\n\tmethods: {\n\t\t/**\n\t\t * Stand down if another companion is on the page that cannot stand down.\n\t\t *\n\t\t * 🔴 THE WINDOW FLAG ONLY BINDS INSTANCES THAT CHECK IT. Measured on a\n\t\t * live instance after shipping the flag: still TWO hexes, stacked at the\n\t\t * same coordinates — one from `#openregister` (the host app's own bundle,\n\t\t * built against an older version of this library) and one from\n\t\t * `#hermiq-companion-root` (the standalone mount, built against the new\n\t\t * one). The old bundle never reads the flag, so it renders regardless,\n\t\t * and the guarded instance had already claimed the slot and rendered too.\n\t\t *\n\t\t * The library fix alone therefore does not reach a page until EVERY app\n\t\t * on it has rebuilt — which is not something a user with a double hex\n\t\t * can wait for. So the instance that CAN yield does.\n\t\t *\n\t\t * Deferred rather than checked at mount, because order is against us: a\n\t\t * standalone companion mounts at DOMContentLoaded and the host app's Vue\n\t\t * tree boots after it, so at mount time there is nothing to see.\n\t\t *\n\t\t * When both companions carry this guard the flag has already stopped the\n\t\t * second one, so this never fires — it is strictly a bridge for mixed\n\t\t * versions, and it costs one timeout.\n\t\t */\n\t\tyieldToACompanionThatCannotYield() {\n\t\t\tif (typeof document === 'undefined' || this.isPrimaryCompanion !== true || this.embedded) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.legacySiblingTimer = setTimeout(() => {\n\t\t\t\tthis.legacySiblingTimer = null\n\n\t\t\t\tconst rendered = document.querySelectorAll('[data-testid=\"cn-ai-companion\"]')\n\t\t\t\tif (rendered.length <= 1) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tfor (const el of rendered) {\n\t\t\t\t\tif (el !== this.$el) {\n\t\t\t\t\t\t// Yield to it: the host app's own companion sits inside\n\t\t\t\t\t\t// that app's tree and carries its page context, which a\n\t\t\t\t\t\t// standalone mount can only approximate.\n\t\t\t\t\t\tthis.releaseSingleton()\n\t\t\t\t\t\tthis.isPrimaryCompanion = false\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, LEGACY_SIBLING_DELAY)\n\t\t},\n\n\t\t/**\n\t\t * Claim the page's single companion slot, or stand down.\n\t\t *\n\t\t * 🔴 TWO COMPANIONS ON ONE PAGE IS A REACHABLE STATE, and it was reached:\n\t\t * `CnAppRoot` renders a companion for any app that sets `aiCompanion`,\n\t\t * while a host app can also mount one standalone on every page of the\n\t\t * instance (Hermiq does exactly this, so the assistant reaches\n\t\t * third-party office editors that have no CnAppRoot of ours). On any\n\t\t * page that has both, the user saw TWO hexes stacked a few pixels apart\n\t\t * — the two mounts pick up different bundled stylesheets, so they do not\n\t\t * even land in the same place.\n\t\t *\n\t\t * The guard lives HERE, in the component, rather than in each host's\n\t\t * mount script, because only the component knows how many of itself\n\t\t * exist. A host-side check cannot see a sibling that mounts later: the\n\t\t * standalone script runs at DOMContentLoaded and the app's own Vue tree\n\t\t * boots after it, so whichever check runs first sees nothing and both\n\t\t * render.\n\t\t *\n\t\t * First to claim wins and the rest render nothing, except that the\n\t\t * app's own companion (with an injected `cnAiContext`) always takes the\n\t\t * slot from a standalone one: the health probes race, so \"first\" is\n\t\t * not stable, and the app's own carries the page context.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\tclaimSingleton() {\n\t\t\t// 🔴 CLAIMED ONLY WHEN THIS INSTANCE WOULD ACTUALLY RENDER.\n\t\t\t//\n\t\t\t// An earlier version claimed in `created()`, before the health probe\n\t\t\t// had answered — so a companion whose probe FAILED still took the\n\t\t\t// slot and stood the other one down, turning \"one companion\" into\n\t\t\t// NONE. Measured on a slow instance, where the probe's 3×5s budget\n\t\t\t// is genuinely marginal: the slot was claimed and nothing rendered.\n\t\t\t//\n\t\t\t// Claiming late is also why the claim is not in a `watch` on the\n\t\t\t// window key: the slot is contended exactly once per page, at the\n\t\t\t// moment each candidate learns it can render.\n\t\t\tif (this.probeSucceeded !== true || this.isChatPage === true || this.embedded) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst scope = typeof window !== 'undefined' ? window : null\n\t\t\tif (scope === null) {\n\t\t\t\t// No window (SSR, a bare unit test): nothing else can be\n\t\t\t\t// rendering, so this instance is the only one by definition.\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (scope[COMPANION_SINGLETON_KEY] === null || scope[COMPANION_SINGLETON_KEY] === undefined) {\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = this\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst holder = scope[COMPANION_SINGLETON_KEY]\n\t\t\tif (holder !== this && this.cnAiContext && !holder.cnAiContext) {\n\t\t\t\t// The app's own companion (inside a CnAppRoot, with the page's\n\t\t\t\t// context) outranks a standalone mount, whichever probe answered\n\t\t\t\t// first; the holder's flag is set directly so a standalone built\n\t\t\t\t// on an older copy of this library stands down too.\n\t\t\t\tholder.isPrimaryCompanion = false\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = this\n\t\t\t\tthis.isPrimaryCompanion = true\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.isPrimaryCompanion = holder === this\n\t\t},\n\n\t\t/**\n\t\t * Give the slot back, but only if this instance is holding it.\n\t\t *\n\t\t * Checked rather than cleared unconditionally: a second, standing-down\n\t\t * instance unmounting must not release the slot the FIRST one is still\n\t\t * using, which would let a third mount render alongside it.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\treleaseSingleton() {\n\t\t\tconst scope = typeof window !== 'undefined' ? window : null\n\t\t\tif (scope !== null && scope[COMPANION_SINGLETON_KEY] === this) {\n\t\t\t\tscope[COMPANION_SINGLETON_KEY] = null\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Ask the chat backend whether it can answer, and render only if so.\n\t\t *\n\t\t * Skipped without a request when the backend app is not installed for\n\t\t * this user.\n\t\t *\n\t\t * @return {Promise<void>}\n\t\t * @spec openspec/changes/no-calls-to-missing-apps-and-presence-beacon/specs/ai-companion/spec.md#requirement-the-companion-does-not-probe-a-backend-that-is-not-installed\n\t\t */\n\t\tasync runHealthProbe() {\n\t\t\t// RETRY before hiding. A single probe makes the whole companion\n\t\t\t// disappear on one slow response, and \"slow\" is normal: measured on a\n\t\t\t// busy instance (load 48) the health endpoint answered in well under a\n\t\t\t// second, but the request still lost its 5s budget to contention. The\n\t\t\t// failure mode is the worst kind — the widget is simply absent, with\n\t\t\t// nothing on screen saying why, and a reload usually \"fixes\" it, which\n\t\t\t// is what makes it read as flakiness rather than as a probe result.\n\t\t\t//\n\t\t\t// A backend that is genuinely down fails all attempts and is still\n\t\t\t// reported; this only stops one unlucky request from deciding.\n\t\t\t//\n\t\t\t// 🔴 NO PROBE AT AN APP THAT IS NOT THERE. Nextcloud already tells\n\t\t\t// the page which apps the user has (`OC.appswebroots`), so asking a\n\t\t\t// missing backend for its health is a guaranteed 404, three times\n\t\t\t// per page, in every console. Measured on cloud.conduction.nl\n\t\t\t// (round-5 check): hermiq not installed, three\n\t\t\t// `/apps/hermiq/api/chat/health` 404s on every pipelinq and dossiq\n\t\t\t// page. Hidden either way; now hidden without the requests.\n\t\t\tif (!isAppInstalled(this.chatAppId || DEFAULT_CHAT_APP_ID)) {\n\t\t\t\tthis.probeSucceeded = false\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tfor (let attempt = 1; attempt <= HEALTH_PROBE_ATTEMPTS; attempt++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await axios.get(chatHealthUrl(this.chatAppId), {\n\t\t\t\t\t\ttimeout: HEALTH_TIMEOUT,\n\t\t\t\t\t\tvalidateStatus: (status) => status >= 200 && status < 300,\n\t\t\t\t\t})\n\t\t\t\t\tthis.probeSucceeded = response.status >= 200 && response.status < 300\n\t\t\t\t\t// Contend for the page's single slot only now, with a\n\t\t\t\t\t// backend that answered. See claimSingleton().\n\t\t\t\t\tthis.claimSingleton()\n\t\t\t\t\t// A companion built against an older version of this library\n\t\t\t\t\t// cannot read the flag above, so look for one shortly.\n\t\t\t\t\tthis.yieldToACompanionThatCannotYield()\n\t\t\t\t\treturn\n\t\t\t\t} catch {\n\t\t\t\t\tif (attempt < HEALTH_PROBE_ATTEMPTS) {\n\t\t\t\t\t\tawait new Promise((resolve) => {\n\t\t\t\t\t\t\tsetTimeout(resolve, HEALTH_RETRY_DELAY * attempt)\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.info(`[CnAiCompanion] chat backend \"${this.chatAppId}\" health probe did not return 2xx `\n\t\t\t\t\t\t+ `after ${HEALTH_PROBE_ATTEMPTS} attempts — widget hidden`)\n\t\t\t\t\tthis.probeSucceeded = false\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * The hex's own handler: open when closed, close when open.\n\t\t *\n\t\t * The launcher stays visible while the window is open (see the template),\n\t\t * so it has to answer for both directions rather than only opening.\n\t\t *\n\t\t * @return {void}\n\t\t */\n\t\ttogglePanel() {\n\t\t\tif (this.isPanelOpen) {\n\t\t\t\tthis.closePanel()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.openPanel()\n\t\t},\n\n\t\topenPanel() {\n\t\t\tthis.isPanelOpen = true\n\t\t\tthis.$nextTick(() => {\n\t\t\t\tif (this.$refs.panel && this.$refs.panel.$refs.input) {\n\t\t\t\t\tthis.$refs.panel.$refs.input.focus()\n\t\t\t\t}\n\t\t\t})\n\t\t},\n\n\t\tclosePanel() {\n\t\t\tthis.isPanelOpen = false\n\t\t},\n\n\t\tonSend(text, agentUuid, attachments) {\n\t\t\tthis.stream.send(text, { agentUuid, attachments }).catch((err) => {\n\t\t\t\t// Stream errors are tracked in stream.state.error — no extra handling needed\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.info('[CnAiCompanion] send error:', err?.message)\n\t\t\t})\n\t\t},\n\n\t\tonNewThread() {\n\t\t\tthis.stream.startNewThread()\n\t\t},\n\n\t\tonLoadConversation(uuid) {\n\t\t\tthis.stream.loadConversation(uuid)\n\t\t},\n\n\t\t/**\n\t\t * Passes a titled panel's session controls on to the host card.\n\t\t *\n\t\t * @param {Array} actions The panel's controls as menu actions\n\t\t */\n\t\tonMenu(actions) {\n\t\t\t/**\n\t\t\t * @event menu The session controls of a titled panel, for its card's menu.\n\t\t\t */\n\t\t\tthis.$emit('menu', actions)\n\t\t},\n\t},\n}\n</script>\n\n<style>\n.cn-ai-companion {\n\t/*\n\t * display: contents removes this wrapper from the layout tree so the\n\t * embedded NcAppSidebar inherits NcContent as its flex parent — required\n\t * for the sidebar to slide in from the RIGHT edge. The FAB is itself\n\t * position:fixed so it positions independently of the wrapper's box.\n\t *\n\t * !important is intentional: webpack pulls in BOTH the old (position:\n\t * fixed) and new (display: contents) rules from the package's CJS and\n\t * ESM builds; without !important the old rule wins the cascade and the\n\t * sidebar renders at the left.\n\t */\n\tdisplay: contents !important;\n\tposition: static !important;\n}\n</style>\n"],"names":["_normalizeClass","_createVNode"],"mappings":";;;;;;;;AAoCQ,EAAA,OAAA,CAAA,KAAA,CAAA,cAAc,IAAK,CAAA,QAAA,CAAA,UAAU,KAAK,MAAA,CAAA,QAAE,IAAA,KAAA,CAAA,kBAAA,CAAA;;;aACrC,EAAAA,cAAA,CAAA,CAAC,iBAAkB,EAAA,EAAA,2BAAA,EACP,MAAA,CAAA,QAAA,EAAA,CAAA,CAAA;;;UAwBT,MAAQ,CAAA,QAAA;qCAGQ,CAAA,6BAAA,EAAA;;AAFtB,cAAA,OAAO,EAAE,IAAG;AACZ,cAAA,QAAQ,EAAE,MAAQ,CAAA,QAAA;AAClB,cAAA,OAAK,EAAE,QAAW,CAAA,WAAA;;;QACnBC;AACA,UAAA,GAAG,EAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -2,7 +2,7 @@ import script from './CnChecklistRunWidget.vue2.js';
|
|
|
2
2
|
import { render } from './CnChecklistRunWidget.vue3.js';
|
|
3
3
|
|
|
4
4
|
script.render = render;
|
|
5
|
-
script.__scopeId = "data-v-
|
|
5
|
+
script.__scopeId = "data-v-05891472";
|
|
6
6
|
const __sfc_main = script;
|
|
7
7
|
|
|
8
8
|
export { __sfc_main as default };
|
|
@@ -123,7 +123,9 @@ function idOf(object) {
|
|
|
123
123
|
*
|
|
124
124
|
* `startAt: "firstOpen"` opens a run that was started earlier at the page of
|
|
125
125
|
* its first unanswered question (the last page when all are answered), once
|
|
126
|
-
* per record;
|
|
126
|
+
* per record; `startAt: "lastAnswered"` at the page of its last answered
|
|
127
|
+
* question, where the inspector was; without it the run opens at the first
|
|
128
|
+
* page.
|
|
127
129
|
*
|
|
128
130
|
* Question kinds: `yes_no`, `yes_no_na`, `choice` (the question's `options`,
|
|
129
131
|
* a list of strings or `{ value, label }`), `number`, `photo` and `text`.
|
|
@@ -341,7 +343,8 @@ var script = {
|
|
|
341
343
|
/**
|
|
342
344
|
* The questions of this page that get a photo control: with a
|
|
343
345
|
* `photoRequired` field, those whose rule is not never (and photo
|
|
344
|
-
* questions)
|
|
346
|
+
* questions), less a `{ whenAnswer }` question answered otherwise that
|
|
347
|
+
* holds no photo; without one, the first question of the page.
|
|
345
348
|
*
|
|
346
349
|
* @return {object[]} The questions.
|
|
347
350
|
* @spec openspec/changes/checklist-run-photo-rule/specs/checklist-run-photo-rule/spec.md#requirement-a-question-can-require-a-photo
|
|
@@ -351,7 +354,7 @@ var script = {
|
|
|
351
354
|
return []
|
|
352
355
|
}
|
|
353
356
|
if (this.fields.photoRequired) {
|
|
354
|
-
return this.pageQuestions.filter((q) => q.kind === 'photo' || q.photoRule !== 'never')
|
|
357
|
+
return this.pageQuestions.filter((q) => q.kind === 'photo' || (q.photoRule !== 'never' && !this.photoRuledOut(q)))
|
|
355
358
|
}
|
|
356
359
|
const first = this.currentQuestion;
|
|
357
360
|
const extra = this.pageQuestions.filter((q) => q.kind === 'photo' && q !== first);
|
|
@@ -566,6 +569,19 @@ var script = {
|
|
|
566
569
|
return Boolean(rule && typeof rule === 'object' && String(this.draft[question.id]?.value ?? '') === rule.whenAnswer)
|
|
567
570
|
},
|
|
568
571
|
|
|
572
|
+
/**
|
|
573
|
+
* Whether a question's answer rules its photo out: a `{ whenAnswer }`
|
|
574
|
+
* question answered with another value and holding no photo.
|
|
575
|
+
*
|
|
576
|
+
* @param {object} question The question.
|
|
577
|
+
* @return {boolean} True when no photo control is needed.
|
|
578
|
+
*/
|
|
579
|
+
photoRuledOut(question) {
|
|
580
|
+
const rule = question.photoRule;
|
|
581
|
+
const value = String(this.draft[question.id]?.value ?? '');
|
|
582
|
+
return Boolean(rule && typeof rule === 'object' && value !== '' && value !== rule.whenAnswer && !this.hasPhoto(question))
|
|
583
|
+
},
|
|
584
|
+
|
|
569
585
|
/**
|
|
570
586
|
* Whether a question has a photo, stored or held.
|
|
571
587
|
*
|
|
@@ -718,6 +734,9 @@ var script = {
|
|
|
718
734
|
if (this.positionedFor !== key && this.content?.startAt === 'firstOpen') {
|
|
719
735
|
const open = questions.findIndex((question) => !this.isAnswered(question));
|
|
720
736
|
this.page = open === -1 ? lastPage : Math.floor(open / this.pageSize);
|
|
737
|
+
} else if (this.positionedFor !== key && this.content?.startAt === 'lastAnswered') {
|
|
738
|
+
const last = questions.findLastIndex((question) => this.isAnswered(question));
|
|
739
|
+
this.page = last === -1 ? 0 : Math.floor(last / this.pageSize);
|
|
721
740
|
}
|
|
722
741
|
this.positionedFor = key;
|
|
723
742
|
this.page = Math.min(this.page, lastPage);
|