@kodaris/krubble-app-components 1.0.157 → 1.0.158

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