@kodaris/krubble-app-components 1.0.77 → 1.0.78

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.
@@ -5620,10 +5620,18 @@
5620
5620
  /** Monotonic id source for pending attachments. */
5621
5621
  this._pendingSeq = 0;
5622
5622
  /**
5623
- * Request-id guard for skill searches — bumped on each search so out-of-order
5624
- * responses are dropped (mirrors the kr-combo-box `_requestId` pattern).
5623
+ * Request-id guards for skill searches — bumped on each search so out-of-order
5624
+ * responses are dropped (mirrors the kr-combo-box `_requestId` pattern). Org and
5625
+ * global searches run concurrently into separate buffers, so each has its own.
5625
5626
  */
5626
5627
  this._skillRequestId = 0;
5628
+ this._globalSkillRequestId = 0;
5629
+ /**
5630
+ * Codes of global skills with an in-flight enable/disable request. The `+`
5631
+ * button reads this to show a pending state and ignore repeat clicks. Mutated
5632
+ * in place; call requestUpdate() after changing it to re-render.
5633
+ */
5634
+ this._globalSkillPending = new Set();
5627
5635
  // --- @property (public API) ---
5628
5636
  /**
5629
5637
  * Callback function for sending messages. Receives the user's message and
@@ -5729,10 +5737,24 @@
5729
5737
  /** Current `/` query (text after the slash), sent to `_searchSkills`. */
5730
5738
  this._skillQuery = '';
5731
5739
  /**
5732
- * Latest skill search results. Shared by the `/` menu and the browse dialog —
5733
- * they're mutually exclusive (opening browse closes the menu), so one buffer.
5740
+ * Latest org skill search results (this instance's own skills). Backs the `/`
5741
+ * menu and the browse dialog's "Your Org" tab.
5734
5742
  */
5735
5743
  this._skillResults = [];
5744
+ /**
5745
+ * Latest shared-Kodaris (global) skill results, for the browse dialog's
5746
+ * "Kodaris" tab. Kept separate from `_skillResults` so switching tabs shows
5747
+ * fresh results immediately instead of the other tab's stale list — the browse
5748
+ * search fills both buffers at once.
5749
+ */
5750
+ this._globalSkillResults = [];
5751
+ /**
5752
+ * AI framework UI config flags fetched from `aiFrameworkConfig` on connect.
5753
+ * `debugTelemetryEnabled` (same server-side gate as TOKEN_USAGE emission) turns
5754
+ * on the debug drawer toggle and the `/test-warning` / `/test-limit` composer
5755
+ * options — known up front, before any message.
5756
+ */
5757
+ this._aiFrameworkConfig = {};
5736
5758
  /** Highlighted item in the skill menu for keyboard navigation (-1 = none). */
5737
5759
  this._skillHighlighted = 0;
5738
5760
  /** Index of the message whose copy button just flashed "Copied" (-1 = none). */
@@ -5740,11 +5762,11 @@
5740
5762
  /** Whether the "Browse all skills" dialog is open. */
5741
5763
  this._skillBrowseOpened = false;
5742
5764
  /**
5743
- * Active tab in the browse dialog. `org` lists this org's skills (searched via
5744
- * `_searchSkills`); `kodaris` is the shared global catalog, added later.
5765
+ * Active tab in the browse dialog. `org` shows `_skillResults` (this instance's
5766
+ * skills); `kodaris` shows `_globalSkillResults` (the shared global catalog).
5745
5767
  */
5746
5768
  this._skillBrowseSource = 'org';
5747
- /** Search text in the browse dialog, sent to `_searchSkills`. */
5769
+ /** Search text in the browse dialog, routed to the active tab's search. */
5748
5770
  this._skillBrowseQuery = '';
5749
5771
  this._handleMouseMove = (e) => {
5750
5772
  if (this._isDragging) {
@@ -5842,6 +5864,17 @@
5842
5864
  this.messages = messages;
5843
5865
  }
5844
5866
  }).catch(() => { });
5867
+ // Fetch the framework config on load (debugTelemetryEnabled, v2ChatEnabled,
5868
+ // registryServer). debugTelemetryEnabled gates the debug affordances and is
5869
+ // known before any message.
5870
+ krubbleHttp.Http.fetch({
5871
+ url: '/api/system/integration/aws/bedrock/aiFrameworkConfig',
5872
+ })
5873
+ .then((r) => r.json())
5874
+ .then((res) => {
5875
+ this._aiFrameworkConfig = res?.data || {};
5876
+ })
5877
+ .catch(() => { });
5845
5878
  // Inline mode fills its container and is always open — the floating widget's
5846
5879
  // toggle/drag/resize state doesn't apply, but the composer message and debug
5847
5880
  // drawer state (restored inside _restoreState) do.
@@ -6206,17 +6239,33 @@
6206
6239
  // specials so user input is treated literally, then wrap with `*...*`.
6207
6240
  let must = { match_all: {} };
6208
6241
  if (trimmed) {
6209
- const pattern = `*${trimmed.replace(/([*?\\])/g, '\\$1')}*`;
6210
- const value = {
6211
- value: pattern,
6212
- case_insensitive: true,
6213
- };
6214
6242
  must = {
6215
6243
  bool: {
6216
6244
  should: [
6217
- { wildcard: { 'name.raw': value } },
6218
- { wildcard: { 'code.raw': value } },
6219
- { wildcard: { 'description.raw': value } },
6245
+ {
6246
+ wildcard: {
6247
+ 'name.raw': {
6248
+ value: `*${trimmed.replace(/([*?\\])/g, '\\$1')}*`,
6249
+ case_insensitive: true,
6250
+ }
6251
+ }
6252
+ },
6253
+ {
6254
+ wildcard: {
6255
+ 'code.raw': {
6256
+ value: `*${trimmed.replace(/([*?\\])/g, '\\$1')}*`,
6257
+ case_insensitive: true,
6258
+ }
6259
+ }
6260
+ },
6261
+ {
6262
+ wildcard: {
6263
+ 'description.raw': {
6264
+ value: `*${trimmed.replace(/([*?\\])/g, '\\$1')}*`,
6265
+ case_insensitive: true,
6266
+ }
6267
+ }
6268
+ },
6220
6269
  ],
6221
6270
  minimum_should_match: 1,
6222
6271
  },
@@ -6247,6 +6296,66 @@
6247
6296
  console.error('kr-chatbot: skill search failed', error);
6248
6297
  });
6249
6298
  }
6299
+ /**
6300
+ * Search the shared Kodaris global-skill registry into `_globalSkillResults`
6301
+ * (the browse dialog's "Kodaris" tab). Unlike `/aiskills/search`,
6302
+ * `/aiskills/global/search` returns a digested list
6303
+ * (`data: [{ code, name, description, enabled }]`) already in `KRChatbotSkill`
6304
+ * shape, so no `_source` lifting is needed. Only the browse dialog calls this
6305
+ * (the `/` menu is org-only), so it isn't run per slash keystroke.
6306
+ */
6307
+ _searchGlobalSkills(query) {
6308
+ this._globalSkillRequestId++;
6309
+ const requestId = this._globalSkillRequestId;
6310
+ krubbleHttp.Http.fetch({
6311
+ url: '/api/system/opensearch/aiskills/global/search',
6312
+ method: 'POST',
6313
+ body: { query: query.trim() },
6314
+ })
6315
+ .then((r) => r.json())
6316
+ .then((res) => {
6317
+ // Ignore a stale response superseded by a newer search.
6318
+ if (requestId !== this._globalSkillRequestId) {
6319
+ return;
6320
+ }
6321
+ this._globalSkillResults = (res?.data || []);
6322
+ })
6323
+ .catch((error) => {
6324
+ console.error('kr-chatbot: global skill search failed', error);
6325
+ });
6326
+ }
6327
+ /**
6328
+ * Enable or disable a global skill on this instance via
6329
+ * `/aiskills/global/{code}/enabled`, then reflect the server's result on the
6330
+ * matching card. Ignores clicks while a request for the same code is pending.
6331
+ */
6332
+ _handleGlobalSkillEnable(skill, e) {
6333
+ // The card body inserts the skill; the `+` button must not also do that.
6334
+ e.stopPropagation();
6335
+ if (this._globalSkillPending.has(skill.code)) {
6336
+ return;
6337
+ }
6338
+ this._globalSkillPending.add(skill.code);
6339
+ this.requestUpdate();
6340
+ krubbleHttp.Http.fetch({
6341
+ url: `/api/system/opensearch/aiskills/global/${encodeURIComponent(skill.code)}/enabled`,
6342
+ method: 'POST',
6343
+ body: { enabled: !skill.enabled },
6344
+ })
6345
+ .then((r) => r.json())
6346
+ .then((res) => {
6347
+ // Reflect the server's returned flag on the card.
6348
+ skill.enabled = res?.data?.enabled;
6349
+ this.requestUpdate();
6350
+ })
6351
+ .catch((error) => {
6352
+ console.error('kr-chatbot: global skill enable failed', error);
6353
+ })
6354
+ .finally(() => {
6355
+ this._globalSkillPending.delete(skill.code);
6356
+ this.requestUpdate();
6357
+ });
6358
+ }
6250
6359
  /** The `+` button toggles the skill/attachment menu open (showing all skills). */
6251
6360
  _handlePlusClick() {
6252
6361
  if (this._skillMenuOpened) {
@@ -6266,6 +6375,13 @@
6266
6375
  this._skillBrowseOpened = false;
6267
6376
  this._inputEl?.focus();
6268
6377
  }
6378
+ /** Activate a skill card via keyboard (Enter/Space), since it's a div role=button. */
6379
+ _handleSkillCardKeydown(e, skill) {
6380
+ if (e.key === 'Enter' || e.key === ' ') {
6381
+ e.preventDefault();
6382
+ this._handleSkillSelect(skill);
6383
+ }
6384
+ }
6269
6385
  /** Copy a message's text to the clipboard and briefly flash "Copied". */
6270
6386
  _handleCopyMessage(content, index) {
6271
6387
  navigator.clipboard.writeText(content).then(() => {
@@ -6281,16 +6397,22 @@
6281
6397
  this._skillMenuOpened = false;
6282
6398
  this._skillBrowseQuery = '';
6283
6399
  this._skillBrowseOpened = true;
6400
+ // Fill both tabs up front so switching between them is instant, not stale.
6284
6401
  this._searchSkills('');
6402
+ this._searchGlobalSkills('');
6285
6403
  }
6286
6404
  _handleSkillBrowseClose() {
6287
6405
  this._skillBrowseOpened = false;
6288
6406
  }
6289
6407
  _handleSkillBrowseSearch(e) {
6290
6408
  this._skillBrowseQuery = e.target.value;
6409
+ // Filter both catalogs so whichever tab the user switches to is already current.
6291
6410
  this._searchSkills(this._skillBrowseQuery);
6411
+ this._searchGlobalSkills(this._skillBrowseQuery);
6292
6412
  }
6293
6413
  _handleSkillBrowseTabChange(e) {
6414
+ // Both buffers are kept current by open/search, so switching just swaps which
6415
+ // one is shown — no re-search needed.
6294
6416
  this._skillBrowseSource = e.detail.activeTabId;
6295
6417
  }
6296
6418
  // --- Attachments ---
@@ -6787,35 +6909,79 @@
6787
6909
  ${this._renderSkillGrid()}
6788
6910
  </kr-tab>
6789
6911
  <kr-tab id="kodaris" label="Kodaris">
6790
- <div class="skill-browse__empty">
6791
- Shared Kodaris skills are coming soon.
6792
- </div>
6912
+ ${this._renderSkillGrid(true)}
6793
6913
  </kr-tab>
6794
6914
  </kr-tab-group>
6795
6915
  </div>
6796
6916
  </kr-dialog>
6797
6917
  `;
6798
6918
  }
6799
- /** The card grid of this org's skill search results for the browse dialog. */
6800
- _renderSkillGrid() {
6801
- const skills = this._skillResults;
6919
+ /**
6920
+ * The card grid of skill search results for the browse dialog. Clicking a card
6921
+ * inserts `/code ` into the composer. In the shared-Kodaris (`global`) tab each
6922
+ * card also gets a `+` install button that enables the skill on this instance
6923
+ * (turning into a ✓ once installed).
6924
+ */
6925
+ _renderSkillGrid(global = false) {
6926
+ let skills = this._skillResults;
6927
+ if (global) {
6928
+ skills = this._globalSkillResults;
6929
+ }
6802
6930
  if (!skills.length) {
6803
6931
  return A;
6804
6932
  }
6805
6933
  return b `
6806
6934
  <div class="skill-browse__grid">
6807
6935
  ${skills.map((skill) => b `
6808
- <button
6936
+ <div
6809
6937
  class="skill-card"
6938
+ role="button"
6939
+ tabindex="0"
6810
6940
  @click=${() => this._handleSkillSelect(skill)}
6941
+ @keydown=${(e) => this._handleSkillCardKeydown(e, skill)}
6811
6942
  >
6812
6943
  <span class="skill-card__name">${skill.name}</span>
6813
6944
  ${skill.description ? b `
6814
6945
  <span class="skill-card__desc">${skill.description}</span>
6815
6946
  ` : A}
6816
- </button>
6947
+ ${global ? this._renderSkillInstall(skill) : A}
6948
+ </div>
6817
6949
  `)}
6818
6950
  </div>
6951
+ `;
6952
+ }
6953
+ /**
6954
+ * The install affordance on a global skill card: a `+` button that enables the
6955
+ * skill on this instance, showing a ✓ once installed and a disabled state
6956
+ * while the enable/disable request is in flight.
6957
+ */
6958
+ _renderSkillInstall(skill) {
6959
+ return b `
6960
+ <button
6961
+ class=${e({
6962
+ 'skill-card__install': true,
6963
+ 'skill-card__install--installed': !!skill.enabled,
6964
+ })}
6965
+ ?disabled=${this._globalSkillPending.has(skill.code)}
6966
+ title=${!!skill.enabled ? 'Installed — click to remove' : 'Install this skill'}
6967
+ aria-label=${!!skill.enabled ? 'Remove skill' : 'Install skill'}
6968
+ @click=${(e) => this._handleGlobalSkillEnable(skill, e)}
6969
+ >
6970
+ <svg
6971
+ xmlns="http://www.w3.org/2000/svg"
6972
+ fill="none"
6973
+ viewBox="0 0 24 24"
6974
+ stroke-width="2"
6975
+ stroke="currentColor"
6976
+ class="skill-card__install-icon"
6977
+ >
6978
+ <path
6979
+ stroke-linecap="round"
6980
+ stroke-linejoin="round"
6981
+ d=${!!skill.enabled ? 'm4.5 12.75 6 6 9-13.5' : 'M12 4.5v15m7.5-7.5h-15'}
6982
+ />
6983
+ </svg>
6984
+ </button>
6819
6985
  `;
6820
6986
  }
6821
6987
  /**
@@ -6983,6 +7149,9 @@
6983
7149
  `;
6984
7150
  }
6985
7151
  render() {
7152
+ // Debug affordances (drawer toggle, drawer, /test-* options) require the
7153
+ // inline variant AND the server-side debug flag from aiFrameworkConfig.
7154
+ const isDebugEnabled = this.variant === 'inline' && this._aiFrameworkConfig.debugTelemetryEnabled === true;
6986
7155
  return b `
6987
7156
  ${(this.hideToggle || this.variant === 'inline') ? A : b `
6988
7157
  <button
@@ -7013,7 +7182,7 @@
7013
7182
  'panel--opened': this.opened,
7014
7183
  'panel--resizing-debug': this._isDebugResizing,
7015
7184
  })}
7016
- style=${o(this.variant === 'inline' && this._debugPanelOpen ? { paddingRight: `${this._debugDrawerWidth}px` } : {})}
7185
+ style=${o(this._debugPanelOpen ? { paddingRight: `${this._debugDrawerWidth}px` } : {})}
7017
7186
  @dragenter=${this._handleDragEnter}
7018
7187
  @dragover=${this._handleDragOver}
7019
7188
  @dragleave=${this._handleDragLeave}
@@ -7086,7 +7255,7 @@
7086
7255
  </div>
7087
7256
  </div>
7088
7257
  <div class="header-actions">
7089
- ${this.variant === 'inline' ? b `
7258
+ ${isDebugEnabled ? b `
7090
7259
  <button
7091
7260
  class=${e({
7092
7261
  'header-action': true,
@@ -7405,7 +7574,7 @@
7405
7574
  </div>
7406
7575
  </div>
7407
7576
  ${this._skillBrowseOpened ? this._renderSkillBrowse() : A}
7408
- ${this.variant === 'inline' ? this._renderDebugPanel() : A}
7577
+ ${isDebugEnabled ? this._renderDebugPanel() : A}
7409
7578
  </div>
7410
7579
  `;
7411
7580
  }
@@ -8430,6 +8599,7 @@
8430
8599
  }
8431
8600
 
8432
8601
  .skill-card {
8602
+ position: relative;
8433
8603
  display: flex;
8434
8604
  flex-direction: column;
8435
8605
  gap: 6px;
@@ -8449,8 +8619,53 @@
8449
8619
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
8450
8620
  }
8451
8621
 
8622
+ /* Install button on global skill cards. Absolutely positioned in the corner
8623
+ so it sits above the card's own click target; leave room via the name's
8624
+ padding-right below. */
8625
+ .skill-card__install {
8626
+ position: absolute;
8627
+ top: 10px;
8628
+ right: 10px;
8629
+ display: inline-flex;
8630
+ align-items: center;
8631
+ justify-content: center;
8632
+ width: 24px;
8633
+ height: 24px;
8634
+ padding: 0;
8635
+ border: 1px solid #d1d5db;
8636
+ border-radius: 6px;
8637
+ background: white;
8638
+ color: #374151;
8639
+ cursor: pointer;
8640
+ transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
8641
+ }
8642
+
8643
+ .skill-card__install:hover:not(:disabled) {
8644
+ border-color: var(--kr-chatbot-primary);
8645
+ color: var(--kr-chatbot-primary);
8646
+ }
8647
+
8648
+ .skill-card__install:disabled {
8649
+ opacity: 0.5;
8650
+ cursor: default;
8651
+ }
8652
+
8653
+ /* Installed state: filled check. */
8654
+ .skill-card__install--installed {
8655
+ background: var(--kr-chatbot-primary);
8656
+ border-color: var(--kr-chatbot-primary);
8657
+ color: white;
8658
+ }
8659
+
8660
+ .skill-card__install-icon {
8661
+ width: 15px;
8662
+ height: 15px;
8663
+ }
8664
+
8452
8665
  .skill-card__name {
8453
8666
  font-weight: 600;
8667
+ /* Leave room for the corner install button on global cards. */
8668
+ padding-right: 28px;
8454
8669
  }
8455
8670
 
8456
8671
  .skill-card__desc {
@@ -8640,6 +8855,12 @@
8640
8855
  __decorate([
8641
8856
  r()
8642
8857
  ], exports.Chatbot.prototype, "_skillResults", void 0);
8858
+ __decorate([
8859
+ r()
8860
+ ], exports.Chatbot.prototype, "_globalSkillResults", void 0);
8861
+ __decorate([
8862
+ r()
8863
+ ], exports.Chatbot.prototype, "_aiFrameworkConfig", void 0);
8643
8864
  __decorate([
8644
8865
  r()
8645
8866
  ], exports.Chatbot.prototype, "_skillHighlighted", void 0);