@kodaris/krubble-app-components 1.0.157 → 1.0.159

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.
@@ -3187,6 +3187,14 @@
3187
3187
  * while it is set and the request only fires once the user confirms.
3188
3188
  */
3189
3189
  this._skillInstallConfirm = null;
3190
+ /**
3191
+ * The transcript offer (an offer_skill tool_result) with paid skills awaiting the user's
3192
+ * install confirmation, else null. An offer IS that tool call: its result string is the offer
3193
+ * JSON (`{skills, canInstall, note}`) and, once the user acts, its row gains
3194
+ * `skillOfferOutcome` (`installed` or `declined`), which the server stores so a reload shows
3195
+ * the same outcome.
3196
+ */
3197
+ this._skillOfferConfirm = null;
3190
3198
  /**
3191
3199
  * Active tab in the browse dialog. `org` shows `_orgSkills` (this instance's
3192
3200
  * skills); `kodaris` shows `_globalSkills` (the shared global catalog).
@@ -4297,6 +4305,126 @@
4297
4305
  this._globalSkillPending.delete(skill.code);
4298
4306
  });
4299
4307
  }
4308
+ /**
4309
+ * Install on a transcript offer: install every skill the assistant offered, together. The
4310
+ * offer is all-or-nothing because the task needs all of them (one without the other would
4311
+ * not get it done). Same permission check and paid-skill confirmation as the Browse dialog's
4312
+ * Install button, applied to the set: without the role, say who to ask; with any paid skill
4313
+ * in the set, confirm the charges first (`_handleSkillOfferConfirm` runs the install once the
4314
+ * user accepts).
4315
+ */
4316
+ _handleOfferedSkillsInstall(msg, e) {
4317
+ const offer = JSON.parse(msg.data.toolResultString);
4318
+ if (!offer.canInstall) {
4319
+ krubbleComponents.Snackbar.show({
4320
+ title: 'Permission Required',
4321
+ message: 'You do not have permission to install skills. Please contact your site administrator.',
4322
+ type: 'error',
4323
+ });
4324
+ return;
4325
+ }
4326
+ if (offer.skills.some((skill) => this._globalSkillPending.has(skill.code))) {
4327
+ return;
4328
+ }
4329
+ if (offer.skills.some((skill) => skill.billable)) {
4330
+ this._skillOfferConfirm = msg;
4331
+ return;
4332
+ }
4333
+ this._installOfferedSkills(msg, e.currentTarget);
4334
+ }
4335
+ /** Cancel the offer's paid-skill confirmation without installing anything. */
4336
+ _handleSkillOfferCancel() {
4337
+ this._skillOfferConfirm = null;
4338
+ }
4339
+ /** The user accepted the charges: install the offered set with the dialog's own button spinning. */
4340
+ _handleSkillOfferConfirm(e) {
4341
+ if (!this._skillOfferConfirm) {
4342
+ return;
4343
+ }
4344
+ this._installOfferedSkills(this._skillOfferConfirm, e.currentTarget);
4345
+ }
4346
+ /**
4347
+ * Install the offered skills one after another through the same enable request the Browse
4348
+ * dialog's card uses, driving the clicked button's spinner. A skill already on (say, installed
4349
+ * from the Browse dialog meanwhile) is a no-op for the server, so none is skipped. When every
4350
+ * one is on: record the outcome on the offer's tool_result data (so this render updates at
4351
+ * once) and on its row (so a reload shows the same thing; best effort, the transcript already
4352
+ * shows it), close the paid confirmation if it was open, and tell the assistant, as the user,
4353
+ * that the skills are installed so it re-runs list_skills and carries on with the original
4354
+ * request. A failure stops the sequence: the ones already on stay on, the button shows the
4355
+ * error, and nothing is sent, so the user can retry the offer.
4356
+ */
4357
+ _installOfferedSkills(msg, btn) {
4358
+ const skills = JSON.parse(msg.data.toolResultString).skills;
4359
+ for (const skill of skills) {
4360
+ this._globalSkillPending.add(skill.code);
4361
+ }
4362
+ btn?.showLoading();
4363
+ let chain = Promise.resolve();
4364
+ for (const skill of skills) {
4365
+ chain = chain
4366
+ .then(() => krubbleHttp.Http.fetch({
4367
+ url: `/api/system/opensearch/aiskills/global/${encodeURIComponent(skill.code)}/enabled`,
4368
+ method: 'POST',
4369
+ body: { enabled: true },
4370
+ }));
4371
+ }
4372
+ chain
4373
+ .then(() => {
4374
+ btn?.reset();
4375
+ this._skillOfferConfirm = null;
4376
+ msg.data.skillOfferOutcome = 'installed';
4377
+ this.requestUpdate();
4378
+ if (this.conversationId != null) {
4379
+ krubbleHttp.Http.fetch({
4380
+ url: `/api/system/conversation/${this.conversationId}/skillOffer/${encodeURIComponent(msg.data.toolUseId)}`,
4381
+ method: 'POST',
4382
+ body: {
4383
+ outcome: 'installed',
4384
+ },
4385
+ }).catch((error) => {
4386
+ console.error('kr-chatbot: failed to record skill offer outcome', error);
4387
+ });
4388
+ }
4389
+ this._inputValue = `I installed ${skills.map((skill) => skill.name).join(' and ')}. Please continue.`;
4390
+ this._handleSubmit();
4391
+ })
4392
+ .catch((error) => {
4393
+ console.error('kr-chatbot: skill offer install failed', error);
4394
+ btn?.showError('Error');
4395
+ })
4396
+ .finally(() => {
4397
+ for (const skill of skills) {
4398
+ this._globalSkillPending.delete(skill.code);
4399
+ }
4400
+ });
4401
+ }
4402
+ /**
4403
+ * Not now on a transcript offer: record the decline (the box stays, showing Declined in
4404
+ * place of the buttons) and tell the assistant, as the user, that they declined, so it can
4405
+ * carry on without the skills instead of waiting for an install. The outcome is set on the
4406
+ * offer's tool_result data so this render updates at once, and written to that row on the
4407
+ * server so a reload shows the same thing. The write is best effort: the transcript already
4408
+ * shows the outcome, and the user message tells the assistant. The row is addressed by the
4409
+ * conversation and the tool call's own toolUseId, which every tool row already carries.
4410
+ */
4411
+ _handleOfferedSkillsDecline(msg) {
4412
+ msg.data.skillOfferOutcome = 'declined';
4413
+ this.requestUpdate();
4414
+ if (this.conversationId != null) {
4415
+ krubbleHttp.Http.fetch({
4416
+ url: `/api/system/conversation/${this.conversationId}/skillOffer/${encodeURIComponent(msg.data.toolUseId)}`,
4417
+ method: 'POST',
4418
+ body: {
4419
+ outcome: 'declined',
4420
+ },
4421
+ }).catch((error) => {
4422
+ console.error('kr-chatbot: failed to record skill offer outcome', error);
4423
+ });
4424
+ }
4425
+ this._inputValue = `I don't want to install ${JSON.parse(msg.data.toolResultString).skills.map((skill) => skill.name).join(' and ')} right now.`;
4426
+ this._handleSubmit();
4427
+ }
4300
4428
  /** The `+` button toggles the skill/attachment menu open (showing all skills). */
4301
4429
  _handlePlusClick() {
4302
4430
  if (this._skillMenuOpened) {
@@ -4486,9 +4614,10 @@
4486
4614
  this._skillBrowseQuery = '';
4487
4615
  this._skillBrowseOpened = true;
4488
4616
  // Fill both tabs up front so switching between them is instant, not stale.
4489
- // The Kodaris tab isn't rendered on the registry server, so skip its fetch there.
4617
+ // The Kodaris tab isn't rendered on the registry server (except a localhost dev box,
4618
+ // which is server and client at once), so skip its fetch there.
4490
4619
  this._searchOrgSkills('');
4491
- if (this._aiFrameworkConfig.registryServer !== true) {
4620
+ if (this._aiFrameworkConfig.registryServer !== true || krubbleHttp.Http.getBaseUrl().includes('localhost')) {
4492
4621
  this._searchGlobalSkills('');
4493
4622
  }
4494
4623
  }
@@ -4522,7 +4651,7 @@
4522
4651
  this._skillBrowseQuery = e.target.value;
4523
4652
  // Filter both catalogs so whichever tab the user switches to is already current.
4524
4653
  this._searchOrgSkills(this._skillBrowseQuery);
4525
- if (this._aiFrameworkConfig.registryServer !== true) {
4654
+ if (this._aiFrameworkConfig.registryServer !== true || krubbleHttp.Http.getBaseUrl().includes('localhost')) {
4526
4655
  this._searchGlobalSkills(this._skillBrowseQuery);
4527
4656
  }
4528
4657
  }
@@ -6031,7 +6160,9 @@
6031
6160
  * The Kodaris tab is omitted on the registry server (kodaris.com): that instance
6032
6161
  * IS the catalog source, so `globalSkillList` has no remote to pull and always
6033
6162
  * returns `[]`. Its own published skills appear on the Your Org tab instead,
6034
- * carrying a "Global" badge.
6163
+ * carrying a "Global" badge. A localhost backend is the exception: a dev box is
6164
+ * usually registry server and client at once (the self-loopback), and the server
6165
+ * flag alone would hide the catalog it pulls from itself.
6035
6166
  */
6036
6167
  _renderSkillBrowse() {
6037
6168
  return b `
@@ -6145,11 +6276,11 @@
6145
6276
  <kr-tab id="org" label="Your Org">
6146
6277
  ${this._renderSkillGrid()}
6147
6278
  </kr-tab>
6148
- ${this._aiFrameworkConfig.registryServer === true ? A : b `
6279
+ ${this._aiFrameworkConfig.registryServer !== true || krubbleHttp.Http.getBaseUrl().includes('localhost') ? b `
6149
6280
  <kr-tab id="kodaris" label="Kodaris">
6150
6281
  ${this._renderSkillGrid(true)}
6151
6282
  </kr-tab>
6152
- `}
6283
+ ` : A}
6153
6284
  </kr-tab-group>
6154
6285
  `}
6155
6286
  </div>
@@ -6968,12 +7099,25 @@
6968
7099
  // Tool visibility is user-controlled ("Show tools" in the settings
6969
7100
  // panel). When off, drop the whole tool row so it doesn't leave an
6970
7101
  // empty flex-gap slot in the transcript.
6971
- if ((msg.type === 'tool_use' || msg.type === 'tool_result') && !this._showTools) {
6972
- return A;
6973
- }
6974
7102
  // A tool_result renders nothing on its own — its tool_use line pulls
6975
7103
  // it in (matched by data.toolUseId) and renders it under the ⎿ cliff.
6976
- if (msg.type === 'tool_result') {
7104
+ // The exception is an offer_skill result: its result string is the
7105
+ // offer JSON ({skills, canInstall, note}) the model read too, and the
7106
+ // skills in it render as an Install box, even with tool rows hidden,
7107
+ // since installing is the user's action rather than tool activity.
7108
+ // Parsed here, where statements are allowed; an offer_skill error
7109
+ // result isn't JSON and renders like any other tool result.
7110
+ let offeredSkills = [];
7111
+ if (msg.type === 'tool_result' && msg.data?.toolName === 'offer_skill') {
7112
+ try {
7113
+ offeredSkills = JSON.parse(msg.data.toolResultString).skills || [];
7114
+ }
7115
+ catch { /* not an offer */ }
7116
+ }
7117
+ if ((msg.type === 'tool_use' || msg.type === 'tool_result') && !this._showTools && !offeredSkills.length) {
7118
+ return A;
7119
+ }
7120
+ if (msg.type === 'tool_result' && !offeredSkills.length) {
6977
7121
  return A;
6978
7122
  }
6979
7123
  // A tool_use line (Claude-CLI style): header "› ToolName(input)" and,
@@ -7072,6 +7216,61 @@
7072
7216
  ` : A}
7073
7217
  </div>
7074
7218
  ` : A}
7219
+ ${offeredSkills.length ? b `
7220
+ <div
7221
+ class="confirmation confirmation--inline skill-offer"
7222
+ role="group"
7223
+ aria-label="Install skills"
7224
+ >
7225
+ <div class="confirmation__title">
7226
+ ${offeredSkills.length > 1 ? 'Install These Skills?' : `Install "${offeredSkills[0].name}" Skill?`}
7227
+ </div>
7228
+ ${offeredSkills.length > 1 ? b `
7229
+ <ol class="confirmation__list">
7230
+ ${offeredSkills.map((skill) => b `
7231
+ <li class="confirmation__list-item">
7232
+ <span class="confirmation__list-name">${skill.name}</span>
7233
+ ${skill.summary ? b `
7234
+ <span class="confirmation__list-desc">${skill.summary}</span>
7235
+ ` : A}
7236
+ <span class="confirmation__list-desc">
7237
+ <strong>Price:</strong>
7238
+ ${skill.priceLabel}
7239
+ </span>
7240
+ </li>
7241
+ `)}
7242
+ </ol>
7243
+ ` : b `
7244
+ ${offeredSkills[0].summary ? b `
7245
+ <p class="confirmation__message">${offeredSkills[0].summary}</p>
7246
+ ` : A}
7247
+ <p class="confirmation__message">
7248
+ <strong>Price:</strong>
7249
+ ${offeredSkills[0].priceLabel}
7250
+ </p>
7251
+ `}
7252
+ <div class="confirmation__actions">
7253
+ ${msg.data.skillOfferOutcome === 'installed' ? b `
7254
+ <span class="skill-offer__installed">Installed</span>
7255
+ ` : msg.data.skillOfferOutcome === 'declined' ? b `
7256
+ <span class="skill-offer__declined">Declined</span>
7257
+ ` : b `
7258
+ <kr-button
7259
+ variant="flat"
7260
+ color="primary"
7261
+ size="small"
7262
+ @click=${(e) => this._handleOfferedSkillsInstall(msg, e)}
7263
+ >Install</kr-button>
7264
+ <kr-button
7265
+ variant="outline"
7266
+ color="secondary"
7267
+ size="small"
7268
+ @click=${() => this._handleOfferedSkillsDecline(msg)}
7269
+ >Not now</kr-button>
7270
+ `}
7271
+ </div>
7272
+ </div>
7273
+ ` : A}
7075
7274
  ${msg.type === 'action_decision' ? b `
7076
7275
  <div class=${e({
7077
7276
  'decision': true,
@@ -7201,15 +7400,25 @@
7201
7400
  </div>
7202
7401
  `;
7203
7402
  });
7204
- if (group[0].type === 'user') {
7205
- return items;
7206
- }
7207
7403
  // The inline confirmation is this turn's final step, so it renders
7208
7404
  // INSIDE the agent-turn wrapper (not as a sibling) — it sits right
7209
7405
  // after the last message and the runway falls below it naturally.
7210
7406
  // Only on the last group, which is the current (paused) turn.
7211
7407
  const isLastGroup = group === messageGroups[messageGroups.length - 1];
7212
7408
  const showConfirmation = isLastGroup && this._pendingActions.length && this._inlineConfirm;
7409
+ if (group[0].type === 'user') {
7410
+ // The model can pause for confirmation before writing any text. The
7411
+ // user's message is then the last group and there is no agent turn to
7412
+ // hold the card, so give the card its own wrapper right after it.
7413
+ return b `
7414
+ ${items}
7415
+ ${showConfirmation ? b `
7416
+ <div class="agent-turn">
7417
+ ${this._renderConfirmation()}
7418
+ </div>
7419
+ ` : A}
7420
+ `;
7421
+ }
7213
7422
  // Keep the "thinking" indicator visible while a tool is running or
7214
7423
  // the model is between steps with no text yet. The trailing empty
7215
7424
  // assistant bubble shows the dots itself; but once a tool line is
@@ -7484,6 +7693,37 @@
7484
7693
  </kr-dialog-footer>
7485
7694
  </kr-dialog>
7486
7695
  ` : A}
7696
+ ${this._skillOfferConfirm ? b `
7697
+ <kr-dialog
7698
+ opened
7699
+ label="Install Paid Skills"
7700
+ width="480px"
7701
+ @close=${this._handleSkillOfferCancel}
7702
+ >
7703
+ <kr-dialog-content>
7704
+ <div class="skill-install-confirm">
7705
+ <p>These are paid skills. Installing them will charge your account:</p>
7706
+ <ul class="skill-install-confirm__list">
7707
+ ${JSON.parse(this._skillOfferConfirm.data.toolResultString).skills.filter((skill) => skill.billable).map((skill) => b `
7708
+ <li>
7709
+ <strong>${skill.name}</strong>
7710
+ ${skill.priceLabel}
7711
+ </li>
7712
+ `)}
7713
+ </ul>
7714
+ <p>Please confirm you would like to proceed.</p>
7715
+ </div>
7716
+ </kr-dialog-content>
7717
+ <kr-dialog-footer>
7718
+ <kr-button color="secondary" @click=${this._handleSkillOfferCancel}>Cancel</kr-button>
7719
+ <kr-button
7720
+ variant="flat"
7721
+ color="primary"
7722
+ @click=${this._handleSkillOfferConfirm}
7723
+ >Install</kr-button>
7724
+ </kr-dialog-footer>
7725
+ </kr-dialog>
7726
+ ` : A}
7487
7727
  ${this._renderDrawer()}
7488
7728
  </div>
7489
7729
  `;
@@ -9365,7 +9605,7 @@
9365
9605
  align-items: center;
9366
9606
  justify-content: space-between;
9367
9607
  gap: 8px;
9368
- margin-top: 8px;
9608
+ margin-top: auto;
9369
9609
  margin-left: -14px;
9370
9610
  margin-right: -14px;
9371
9611
  padding: 14px 14px 0;
@@ -9378,6 +9618,41 @@
9378
9618
  color: #000000;
9379
9619
  }
9380
9620
 
9621
+ /* The install offer in the transcript for the registry skill the assistant offered
9622
+ (offer_skill) because it isn't installed here. Styled as the inline run-tool
9623
+ confirmation (title, plain-language lines, button row) so asking the user to
9624
+ install reads the same as asking them to approve an action. */
9625
+ /* Boxed, unlike the inline run-tool confirmation: the same border, radius and
9626
+ background as the floating confirmation card so it reads as one of them, but
9627
+ flowing in the transcript. */
9628
+ .skill-offer {
9629
+ padding: 20px 24px;
9630
+ border: 1px solid #d8d8d8;
9631
+ border-radius: 8px;
9632
+ background: var(--kr-chatbot-bg);
9633
+ }
9634
+
9635
+ .skill-offer .confirmation__message + .confirmation__message {
9636
+ margin-top: 8px;
9637
+ }
9638
+
9639
+ /* The offer's recorded outcome, shown in place of the buttons. */
9640
+ .skill-offer__installed,
9641
+ .skill-offer__declined {
9642
+ font-size: 14px;
9643
+ font-weight: 600;
9644
+ }
9645
+
9646
+ .skill-offer__installed {
9647
+ /* Darker than the alert's success green (#16a34a) so a bold 14px label on white
9648
+ keeps text-level contrast. */
9649
+ color: #15803d;
9650
+ }
9651
+
9652
+ .skill-offer__declined {
9653
+ color: var(--kr-chatbot-text-secondary);
9654
+ }
9655
+
9381
9656
  .skill-install-confirm {
9382
9657
  display: flex;
9383
9658
  flex-direction: column;
@@ -9390,6 +9665,11 @@
9390
9665
  margin: 0;
9391
9666
  }
9392
9667
 
9668
+ .skill-install-confirm__list {
9669
+ margin: 0;
9670
+ padding-left: 20px;
9671
+ }
9672
+
9393
9673
  .skill-card__name {
9394
9674
  font-weight: 600;
9395
9675
  }
@@ -9790,6 +10070,9 @@
9790
10070
  __decorate$5([
9791
10071
  r()
9792
10072
  ], KRChatbot.prototype, "_skillInstallConfirm", void 0);
10073
+ __decorate$5([
10074
+ r()
10075
+ ], KRChatbot.prototype, "_skillOfferConfirm", void 0);
9793
10076
  __decorate$5([
9794
10077
  r()
9795
10078
  ], KRChatbot.prototype, "_skillBrowseSource", void 0);