@nuraly/lumenui 0.3.8 → 0.3.9

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.
@@ -26884,7 +26884,7 @@ var Kh=function(e,t,i,n){return new(i||(i=Promise))(function(s,a){function o(e){
26884
26884
  * @license
26885
26885
  * Copyright 2023 Nuraly, Laabidi Aymen
26886
26886
  * SPDX-License-Identifier: MIT
26887
- */var Dp=function(e,t,i,n){return new(i||(i=Promise))(function(s,a){function o(e){try{l(n.next(e))}catch(e){a(e)}}function r(e){try{l(n.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(o,r)}l((n=n.apply(e,t||[])).next())})};class zp extends Mp{constructor(){super(...arguments),this.id="artifact",this.name="Artifact Plugin",this.version="1.0.0",this.artifacts=new Map}onInit(e){this.controller=e,e&&"function"==typeof e.on&&e.on("processing:end",()=>{var t,i;try{const n=[...(null===(t=e.getMessages)||void 0===t?void 0:t.call(e))||[]].reverse().find(e=>e.sender===Xi.Bot);n&&!(null===(i=n.metadata)||void 0===i?void 0:i.hasArtifacts)&&this.processMessage(n)}catch(e){}})}onMessageReceived(e){return Dp(this,void 0,void 0,function*(){e.sender===Xi.Bot&&this.processMessage(e)})}processMessage(e){var t;if(null===(t=e.metadata)||void 0===t?void 0:t.hasArtifacts)return void this.rebuildArtifactsFromMetadata(e);const i=e.text;if(!i)return;const n=/```(\w*)\n([\s\S]*?)```/g;let s;const a=[];let o=0;for(;null!==(s=n.exec(i));){const t=(s[1]||"text").toLowerCase(),i=s[2],n=`artifact-${e.id}-${o}`,r={id:n,language:t,content:i,title:this.extractTitle(i,t,o),messageId:e.id,index:o};a.push(r),this.artifacts.set(n,r),o++}if(0===a.length)return;let r=i,l=0;r=r.replaceAll(n,()=>`\0ARTIFACT_CARD_${a[l++].id}\0`),r=gn(r);for(const e of a)r=r.replace(`\0ARTIFACT_CARD_${e.id}\0`,this.renderPlaceholderCard(e));const d=this.getOncePerConversationStyleTag(this.getStyles());this.controller&&"function"==typeof this.controller.updateMessage&&this.controller.updateMessage(e.id,{text:d+r,metadata:Object.assign(Object.assign({},e.metadata),{renderAsHtml:!0,hasArtifacts:!0,artifactIds:a.map(e=>e.id),artifactOriginalText:i})})}rebuildArtifactsFromMetadata(e){var t,i;const n=null===(t=e.metadata)||void 0===t?void 0:t.artifactIds;if(!(null==n?void 0:n.length))return;if(n.every(e=>this.artifacts.has(e)))return;const s=null===(i=e.metadata)||void 0===i?void 0:i.artifactOriginalText;if(!s)return;const a=/```(\w*)\n([\s\S]*?)```/g;let o,r=0;for(;null!==(o=a.exec(s));){const t=(o[1]||"text").toLowerCase(),i=o[2],n=`artifact-${e.id}-${r}`,s=this.extractTitle(i,t,r);this.artifacts.set(n,{id:n,language:t,content:i,title:s,messageId:e.id,index:r}),r++}}getArtifact(e){return this.artifacts.get(e)}getAllArtifacts(){return Array.from(this.artifacts.values())}getArtifactsForMessage(e){return Array.from(this.artifacts.values()).filter(t=>t.messageId===e)}extractTitle(e,t,i){const n=e.trimStart().split("\n")[0]||"",s=[/^\/\/\s*(.+)/,/^#\s*(.+)/,/^--\s*(.+)/,/^\/\*\s*(.*?)\*\//,/^<!--\s*(.*?)-->/];for(const e of s){const t=e.exec(n);if(null==t?void 0:t[1]){const e=t[1].trim();if(e.length>0&&e.length<=60)return e}}return`${bn(t)} Snippet ${i+1}`}renderPlaceholderCard(e){const t=bn(e.language),i=mn(e.title);return`<div class="nr-artifact-card" data-artifact-id="${e.id}" role="button" tabindex="0" aria-label="View ${i}">\n <nr-icon name="code" size="small" class="nr-artifact-card__icon"></nr-icon>\n <span class="nr-artifact-card__info">\n <span class="nr-artifact-card__title">${i}</span>\n <nr-tag size="small" class="nr-artifact-card__lang">${t}</nr-tag>\n </span>\n <nr-icon name="chevron-right" size="small" class="nr-artifact-card__chevron"></nr-icon>\n</div>`}getStyles(){return"\n .nr-artifact-card {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 10px 14px;\n margin: 8px 0;\n background: #f6f8fa;\n border: 1px solid #d0d7de;\n border-radius: 8px;\n cursor: pointer;\n transition: background 0.15s ease, border-color 0.15s ease;\n user-select: none;\n max-width: 100%;\n }\n .nr-artifact-card:hover {\n background: #eaeef2;\n border-color: #8b949e;\n }\n .nr-artifact-card:focus-visible {\n outline: 2px solid #0b5fff;\n outline-offset: 2px;\n }\n .nr-artifact-card__icon {\n flex-shrink: 0;\n color: #57606a;\n }\n .nr-artifact-card__info {\n display: flex;\n flex-direction: column;\n gap: 4px;\n min-width: 0;\n flex: 1;\n }\n .nr-artifact-card__title {\n font-size: 13px;\n font-weight: 500;\n color: #1f2937;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n line-height: 1.3;\n }\n .nr-artifact-card__lang {\n align-self: flex-start;\n }\n .nr-artifact-card__chevron {\n flex-shrink: 0;\n color: #6c757d;\n }\n "}}
26887
+ */var Dp=function(e,t,i,n){return new(i||(i=Promise))(function(s,a){function o(e){try{l(n.next(e))}catch(e){a(e)}}function r(e){try{l(n.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(o,r)}l((n=n.apply(e,t||[])).next())})};class zp extends Mp{constructor(){super(...arguments),this.id="artifact",this.name="Artifact Plugin",this.version="1.0.0",this.artifacts=new Map}onInit(e){this.controller=e,e&&"function"==typeof e.on&&e.on("processing:end",()=>{var t,i;try{const n=[...(null===(t=e.getMessages)||void 0===t?void 0:t.call(e))||[]].reverse().find(e=>e.sender===Xi.Bot);n&&!(null===(i=n.metadata)||void 0===i?void 0:i.hasArtifacts)&&this.processMessage(n)}catch(e){}})}onMessageReceived(e){return Dp(this,void 0,void 0,function*(){e.sender===Xi.Bot&&this.processMessage(e)})}processMessage(e){var t;if(null===(t=e.metadata)||void 0===t?void 0:t.hasArtifacts)return void this.rebuildArtifactsFromMetadata(e);const i=e.text;if(!i)return;const n=/```(\w*)\n([\s\S]*?)```/g;let s;const a=[];let o=0;for(;null!==(s=n.exec(i));){const t=(s[1]||"text").toLowerCase(),i=s[2],n=`artifact-${e.id}-${o}`,r={id:n,language:t,content:i,title:this.extractTitle(i,t,o),messageId:e.id,index:o};a.push(r),this.artifacts.set(n,r),o++}if(0===a.length)return;let r=i,l=0;r=r.replaceAll(n,()=>`\0ARTIFACT_CARD_${a[l++].id}\0`),r=gn(r);for(const e of a)r=r.replace(`\0ARTIFACT_CARD_${e.id}\0`,this.renderPlaceholderCard(e));const d=this.getOncePerConversationStyleTag(this.getStyles());this.controller&&"function"==typeof this.controller.updateMessage&&this.controller.updateMessage(e.id,{text:d+r,metadata:Object.assign(Object.assign({},e.metadata),{renderAsHtml:!0,hasArtifacts:!0,artifactIds:a.map(e=>e.id),artifactOriginalText:i})})}rebuildArtifactsFromMetadata(e){var t,i;const n=null===(t=e.metadata)||void 0===t?void 0:t.artifactIds;if(!(null==n?void 0:n.length))return;if(n.every(e=>this.artifacts.has(e)))return;const s=null===(i=e.metadata)||void 0===i?void 0:i.artifactOriginalText;if(!s)return;const a=/```(\w*)\n([\s\S]*?)```/g;let o,r=0;for(;null!==(o=a.exec(s));){const t=(o[1]||"text").toLowerCase(),i=o[2],n=`artifact-${e.id}-${r}`,s=this.extractTitle(i,t,r);this.artifacts.set(n,{id:n,language:t,content:i,title:s,messageId:e.id,index:r}),r++}}getArtifact(e){return this.artifacts.get(e)}getAllArtifacts(){return Array.from(this.artifacts.values())}getArtifactsForMessage(e){return Array.from(this.artifacts.values()).filter(t=>t.messageId===e)}processNow(e){var t;if(!this.controller||"function"!=typeof this.controller.getMessages)return!1;const i=(this.controller.getMessages()||[]).find(t=>t.id===e);return!(!i||i.sender!==Xi.Bot)&&((null===(t=i.metadata)||void 0===t?void 0:t.hasArtifacts)?(this.rebuildArtifactsFromMetadata(i),!0):(this.processMessage(i),!0))}extractTitle(e,t,i){const n=e.trimStart().split("\n")[0]||"",s=[/^\/\/\s*(.+)/,/^#\s*(.+)/,/^--\s*(.+)/,/^\/\*\s*(.*?)\*\//,/^<!--\s*(.*?)-->/];for(const e of s){const t=e.exec(n);if(null==t?void 0:t[1]){const e=t[1].trim();if(e.length>0&&e.length<=60)return e}}return`${bn(t)} Snippet ${i+1}`}renderPlaceholderCard(e){const t=bn(e.language),i=mn(e.title);return`<div class="nr-artifact-card" data-artifact-id="${e.id}" role="button" tabindex="0" aria-label="View ${i}">\n <nr-icon name="code" size="small" class="nr-artifact-card__icon"></nr-icon>\n <span class="nr-artifact-card__info">\n <span class="nr-artifact-card__title">${i}</span>\n <nr-tag size="small" class="nr-artifact-card__lang">${t}</nr-tag>\n </span>\n <nr-icon name="chevron-right" size="small" class="nr-artifact-card__chevron"></nr-icon>\n</div>`}getStyles(){return"\n .nr-artifact-card {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 10px 14px;\n margin: 8px 0;\n background: #f6f8fa;\n border: 1px solid #d0d7de;\n border-radius: 8px;\n cursor: pointer;\n transition: background 0.15s ease, border-color 0.15s ease;\n user-select: none;\n max-width: 100%;\n }\n .nr-artifact-card:hover {\n background: #eaeef2;\n border-color: #8b949e;\n }\n .nr-artifact-card:focus-visible {\n outline: 2px solid #0b5fff;\n outline-offset: 2px;\n }\n .nr-artifact-card__icon {\n flex-shrink: 0;\n color: #57606a;\n }\n .nr-artifact-card__info {\n display: flex;\n flex-direction: column;\n gap: 4px;\n min-width: 0;\n flex: 1;\n }\n .nr-artifact-card__title {\n font-size: 13px;\n font-weight: 500;\n color: #1f2937;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n line-height: 1.3;\n }\n .nr-artifact-card__lang {\n align-self: flex-start;\n }\n .nr-artifact-card__chevron {\n flex-shrink: 0;\n color: #6c757d;\n }\n "}}
26888
26888
  /**
26889
26889
  * @license
26890
26890
  * Copyright 2023 Nuraly, Laabidi Aymen
Binary file
@@ -2910,7 +2910,7 @@ var Yt=function(t,e,i,n){return new(i||(i=Promise))(function(o,s){function r(t){
2910
2910
  * @license
2911
2911
  * Copyright 2023 Nuraly, Laabidi Aymen
2912
2912
  * SPDX-License-Identifier: MIT
2913
- */var Fe=function(t,e,i,n){return new(i||(i=Promise))(function(o,s){function r(t){try{l(n.next(t))}catch(t){s(t)}}function a(t){try{l(n.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(r,a)}l((n=n.apply(t,e||[])).next())})};class De extends ze{constructor(){super(...arguments),this.id="artifact",this.name="Artifact Plugin",this.version="1.0.0",this.artifacts=new Map}onInit(t){this.controller=t,t&&"function"==typeof t.on&&t.on("processing:end",()=>{var e,i;try{const n=[...(null===(e=t.getMessages)||void 0===e?void 0:e.call(t))||[]].reverse().find(t=>t.sender===q.Bot);n&&!(null===(i=n.metadata)||void 0===i?void 0:i.hasArtifacts)&&this.processMessage(n)}catch(t){}})}onMessageReceived(t){return Fe(this,void 0,void 0,function*(){t.sender===q.Bot&&this.processMessage(t)})}processMessage(t){var e;if(null===(e=t.metadata)||void 0===e?void 0:e.hasArtifacts)return void this.rebuildArtifactsFromMetadata(t);const i=t.text;if(!i)return;const n=/```(\w*)\n([\s\S]*?)```/g;let o;const s=[];let r=0;for(;null!==(o=n.exec(i));){const e=(o[1]||"text").toLowerCase(),i=o[2],n=`artifact-${t.id}-${r}`,a={id:n,language:e,content:i,title:this.extractTitle(i,e,r),messageId:t.id,index:r};s.push(a),this.artifacts.set(n,a),r++}if(0===s.length)return;let a=i,l=0;a=a.replaceAll(n,()=>`\0ARTIFACT_CARD_${s[l++].id}\0`),a=ct(a);for(const t of s)a=a.replace(`\0ARTIFACT_CARD_${t.id}\0`,this.renderPlaceholderCard(t));const d=this.getOncePerConversationStyleTag(this.getStyles());this.controller&&"function"==typeof this.controller.updateMessage&&this.controller.updateMessage(t.id,{text:d+a,metadata:Object.assign(Object.assign({},t.metadata),{renderAsHtml:!0,hasArtifacts:!0,artifactIds:s.map(t=>t.id),artifactOriginalText:i})})}rebuildArtifactsFromMetadata(t){var e,i;const n=null===(e=t.metadata)||void 0===e?void 0:e.artifactIds;if(!(null==n?void 0:n.length))return;if(n.every(t=>this.artifacts.has(t)))return;const o=null===(i=t.metadata)||void 0===i?void 0:i.artifactOriginalText;if(!o)return;const s=/```(\w*)\n([\s\S]*?)```/g;let r,a=0;for(;null!==(r=s.exec(o));){const e=(r[1]||"text").toLowerCase(),i=r[2],n=`artifact-${t.id}-${a}`,o=this.extractTitle(i,e,a);this.artifacts.set(n,{id:n,language:e,content:i,title:o,messageId:t.id,index:a}),a++}}getArtifact(t){return this.artifacts.get(t)}getAllArtifacts(){return Array.from(this.artifacts.values())}getArtifactsForMessage(t){return Array.from(this.artifacts.values()).filter(e=>e.messageId===t)}extractTitle(t,e,i){const n=t.trimStart().split("\n")[0]||"",o=[/^\/\/\s*(.+)/,/^#\s*(.+)/,/^--\s*(.+)/,/^\/\*\s*(.*?)\*\//,/^<!--\s*(.*?)-->/];for(const t of o){const e=t.exec(n);if(null==e?void 0:e[1]){const t=e[1].trim();if(t.length>0&&t.length<=60)return t}}return`${dt(e)} Snippet ${i+1}`}renderPlaceholderCard(t){const e=dt(t.language),i=at(t.title);return`<div class="nr-artifact-card" data-artifact-id="${t.id}" role="button" tabindex="0" aria-label="View ${i}">\n <nr-icon name="code" size="small" class="nr-artifact-card__icon"></nr-icon>\n <span class="nr-artifact-card__info">\n <span class="nr-artifact-card__title">${i}</span>\n <nr-tag size="small" class="nr-artifact-card__lang">${e}</nr-tag>\n </span>\n <nr-icon name="chevron-right" size="small" class="nr-artifact-card__chevron"></nr-icon>\n</div>`}getStyles(){return"\n .nr-artifact-card {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 10px 14px;\n margin: 8px 0;\n background: #f6f8fa;\n border: 1px solid #d0d7de;\n border-radius: 8px;\n cursor: pointer;\n transition: background 0.15s ease, border-color 0.15s ease;\n user-select: none;\n max-width: 100%;\n }\n .nr-artifact-card:hover {\n background: #eaeef2;\n border-color: #8b949e;\n }\n .nr-artifact-card:focus-visible {\n outline: 2px solid #0b5fff;\n outline-offset: 2px;\n }\n .nr-artifact-card__icon {\n flex-shrink: 0;\n color: #57606a;\n }\n .nr-artifact-card__info {\n display: flex;\n flex-direction: column;\n gap: 4px;\n min-width: 0;\n flex: 1;\n }\n .nr-artifact-card__title {\n font-size: 13px;\n font-weight: 500;\n color: #1f2937;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n line-height: 1.3;\n }\n .nr-artifact-card__lang {\n align-self: flex-start;\n }\n .nr-artifact-card__chevron {\n flex-shrink: 0;\n color: #6c757d;\n }\n "}}
2913
+ */var Fe=function(t,e,i,n){return new(i||(i=Promise))(function(o,s){function r(t){try{l(n.next(t))}catch(t){s(t)}}function a(t){try{l(n.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(r,a)}l((n=n.apply(t,e||[])).next())})};class De extends ze{constructor(){super(...arguments),this.id="artifact",this.name="Artifact Plugin",this.version="1.0.0",this.artifacts=new Map}onInit(t){this.controller=t,t&&"function"==typeof t.on&&t.on("processing:end",()=>{var e,i;try{const n=[...(null===(e=t.getMessages)||void 0===e?void 0:e.call(t))||[]].reverse().find(t=>t.sender===q.Bot);n&&!(null===(i=n.metadata)||void 0===i?void 0:i.hasArtifacts)&&this.processMessage(n)}catch(t){}})}onMessageReceived(t){return Fe(this,void 0,void 0,function*(){t.sender===q.Bot&&this.processMessage(t)})}processMessage(t){var e;if(null===(e=t.metadata)||void 0===e?void 0:e.hasArtifacts)return void this.rebuildArtifactsFromMetadata(t);const i=t.text;if(!i)return;const n=/```(\w*)\n([\s\S]*?)```/g;let o;const s=[];let r=0;for(;null!==(o=n.exec(i));){const e=(o[1]||"text").toLowerCase(),i=o[2],n=`artifact-${t.id}-${r}`,a={id:n,language:e,content:i,title:this.extractTitle(i,e,r),messageId:t.id,index:r};s.push(a),this.artifacts.set(n,a),r++}if(0===s.length)return;let a=i,l=0;a=a.replaceAll(n,()=>`\0ARTIFACT_CARD_${s[l++].id}\0`),a=ct(a);for(const t of s)a=a.replace(`\0ARTIFACT_CARD_${t.id}\0`,this.renderPlaceholderCard(t));const d=this.getOncePerConversationStyleTag(this.getStyles());this.controller&&"function"==typeof this.controller.updateMessage&&this.controller.updateMessage(t.id,{text:d+a,metadata:Object.assign(Object.assign({},t.metadata),{renderAsHtml:!0,hasArtifacts:!0,artifactIds:s.map(t=>t.id),artifactOriginalText:i})})}rebuildArtifactsFromMetadata(t){var e,i;const n=null===(e=t.metadata)||void 0===e?void 0:e.artifactIds;if(!(null==n?void 0:n.length))return;if(n.every(t=>this.artifacts.has(t)))return;const o=null===(i=t.metadata)||void 0===i?void 0:i.artifactOriginalText;if(!o)return;const s=/```(\w*)\n([\s\S]*?)```/g;let r,a=0;for(;null!==(r=s.exec(o));){const e=(r[1]||"text").toLowerCase(),i=r[2],n=`artifact-${t.id}-${a}`,o=this.extractTitle(i,e,a);this.artifacts.set(n,{id:n,language:e,content:i,title:o,messageId:t.id,index:a}),a++}}getArtifact(t){return this.artifacts.get(t)}getAllArtifacts(){return Array.from(this.artifacts.values())}getArtifactsForMessage(t){return Array.from(this.artifacts.values()).filter(e=>e.messageId===t)}processNow(t){var e;if(!this.controller||"function"!=typeof this.controller.getMessages)return!1;const i=(this.controller.getMessages()||[]).find(e=>e.id===t);return!(!i||i.sender!==q.Bot)&&((null===(e=i.metadata)||void 0===e?void 0:e.hasArtifacts)?(this.rebuildArtifactsFromMetadata(i),!0):(this.processMessage(i),!0))}extractTitle(t,e,i){const n=t.trimStart().split("\n")[0]||"",o=[/^\/\/\s*(.+)/,/^#\s*(.+)/,/^--\s*(.+)/,/^\/\*\s*(.*?)\*\//,/^<!--\s*(.*?)-->/];for(const t of o){const e=t.exec(n);if(null==e?void 0:e[1]){const t=e[1].trim();if(t.length>0&&t.length<=60)return t}}return`${dt(e)} Snippet ${i+1}`}renderPlaceholderCard(t){const e=dt(t.language),i=at(t.title);return`<div class="nr-artifact-card" data-artifact-id="${t.id}" role="button" tabindex="0" aria-label="View ${i}">\n <nr-icon name="code" size="small" class="nr-artifact-card__icon"></nr-icon>\n <span class="nr-artifact-card__info">\n <span class="nr-artifact-card__title">${i}</span>\n <nr-tag size="small" class="nr-artifact-card__lang">${e}</nr-tag>\n </span>\n <nr-icon name="chevron-right" size="small" class="nr-artifact-card__chevron"></nr-icon>\n</div>`}getStyles(){return"\n .nr-artifact-card {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 10px 14px;\n margin: 8px 0;\n background: #f6f8fa;\n border: 1px solid #d0d7de;\n border-radius: 8px;\n cursor: pointer;\n transition: background 0.15s ease, border-color 0.15s ease;\n user-select: none;\n max-width: 100%;\n }\n .nr-artifact-card:hover {\n background: #eaeef2;\n border-color: #8b949e;\n }\n .nr-artifact-card:focus-visible {\n outline: 2px solid #0b5fff;\n outline-offset: 2px;\n }\n .nr-artifact-card__icon {\n flex-shrink: 0;\n color: #57606a;\n }\n .nr-artifact-card__info {\n display: flex;\n flex-direction: column;\n gap: 4px;\n min-width: 0;\n flex: 1;\n }\n .nr-artifact-card__title {\n font-size: 13px;\n font-weight: 500;\n color: #1f2937;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n line-height: 1.3;\n }\n .nr-artifact-card__lang {\n align-self: flex-start;\n }\n .nr-artifact-card__chevron {\n flex-shrink: 0;\n color: #6c757d;\n }\n "}}
2914
2914
  /**
2915
2915
  * @license
2916
2916
  * Copyright 2023 Nuraly, Laabidi Aymen
@@ -58,6 +58,50 @@ export declare class ArtifactPlugin extends ChatPluginBase implements ChatbotPlu
58
58
  getAllArtifacts(): ChatbotArtifact[];
59
59
  /** Get all artifacts belonging to a specific message */
60
60
  getArtifactsForMessage(messageId: string): ChatbotArtifact[];
61
+ /**
62
+ * Force artifact extraction on a specific message NOW, regardless of
63
+ * streaming state. Useful when structured content arrives via a
64
+ * side-channel (e.g. tool result events delivered out-of-band) and the
65
+ * caller wants the artifact card to appear before the stream's
66
+ * `processing:end` fires.
67
+ *
68
+ * <p>Idempotent: if the message has already been processed
69
+ * (`metadata.hasArtifacts === true`), this is a no-op. The regular
70
+ * `processing:end` handler will also skip the message later for the
71
+ * same reason, so calling this method early does NOT cause duplicate
72
+ * processing on stream completion.
73
+ *
74
+ * <p>Typical usage from outside the plugin:
75
+ * ```typescript
76
+ * const artifactPlugin = new ArtifactPlugin();
77
+ * const controller = new ChatbotCoreController({
78
+ * plugins: [new MarkdownPlugin(), artifactPlugin],
79
+ * // ...
80
+ * });
81
+ *
82
+ * // When a tool result arrives via a custom side-channel:
83
+ * provider.onMessage('TOOL_RESULT_JSON', (msg) => {
84
+ * const messages = controller.getMessages();
85
+ * const lastBotMsg = [...messages].reverse()
86
+ * .find(m => m.sender === ChatbotSender.Bot);
87
+ * if (lastBotMsg) {
88
+ * // 1) Append the fenced content to the bot message text
89
+ * controller.messageHandler.appendToBotMessage(
90
+ * lastBotMsg.id,
91
+ * '\n\n```json\n' + msg.content + '\n```\n\n'
92
+ * );
93
+ * // 2) Trigger artifact extraction right away
94
+ * artifactPlugin.processNow(lastBotMsg.id);
95
+ * }
96
+ * });
97
+ * ```
98
+ *
99
+ * @param messageId id of the bot message to process. If not found, or
100
+ * not a bot message, returns false.
101
+ * @returns true when the message was processed (or rebuilt from
102
+ * metadata); false when skipped or message not found.
103
+ */
104
+ processNow(messageId: string): boolean;
61
105
  /**
62
106
  * Try to extract a meaningful title from the first comment line of the code.
63
107
  * Falls back to a generic "Code Snippet #N" title.
@@ -196,6 +196,68 @@ export class ArtifactPlugin extends ChatPluginBase {
196
196
  getArtifactsForMessage(messageId) {
197
197
  return Array.from(this.artifacts.values()).filter(a => a.messageId === messageId);
198
198
  }
199
+ /**
200
+ * Force artifact extraction on a specific message NOW, regardless of
201
+ * streaming state. Useful when structured content arrives via a
202
+ * side-channel (e.g. tool result events delivered out-of-band) and the
203
+ * caller wants the artifact card to appear before the stream's
204
+ * `processing:end` fires.
205
+ *
206
+ * <p>Idempotent: if the message has already been processed
207
+ * (`metadata.hasArtifacts === true`), this is a no-op. The regular
208
+ * `processing:end` handler will also skip the message later for the
209
+ * same reason, so calling this method early does NOT cause duplicate
210
+ * processing on stream completion.
211
+ *
212
+ * <p>Typical usage from outside the plugin:
213
+ * ```typescript
214
+ * const artifactPlugin = new ArtifactPlugin();
215
+ * const controller = new ChatbotCoreController({
216
+ * plugins: [new MarkdownPlugin(), artifactPlugin],
217
+ * // ...
218
+ * });
219
+ *
220
+ * // When a tool result arrives via a custom side-channel:
221
+ * provider.onMessage('TOOL_RESULT_JSON', (msg) => {
222
+ * const messages = controller.getMessages();
223
+ * const lastBotMsg = [...messages].reverse()
224
+ * .find(m => m.sender === ChatbotSender.Bot);
225
+ * if (lastBotMsg) {
226
+ * // 1) Append the fenced content to the bot message text
227
+ * controller.messageHandler.appendToBotMessage(
228
+ * lastBotMsg.id,
229
+ * '\n\n```json\n' + msg.content + '\n```\n\n'
230
+ * );
231
+ * // 2) Trigger artifact extraction right away
232
+ * artifactPlugin.processNow(lastBotMsg.id);
233
+ * }
234
+ * });
235
+ * ```
236
+ *
237
+ * @param messageId id of the bot message to process. If not found, or
238
+ * not a bot message, returns false.
239
+ * @returns true when the message was processed (or rebuilt from
240
+ * metadata); false when skipped or message not found.
241
+ */
242
+ processNow(messageId) {
243
+ var _a;
244
+ if (!this.controller || typeof this.controller.getMessages !== 'function') {
245
+ return false;
246
+ }
247
+ const messages = this.controller.getMessages() || [];
248
+ const message = messages.find(m => m.id === messageId);
249
+ if (!message || message.sender !== ChatbotSender.Bot) {
250
+ return false;
251
+ }
252
+ if ((_a = message.metadata) === null || _a === void 0 ? void 0 : _a.hasArtifacts) {
253
+ // Already processed — but rebuild the in-memory artifacts Map so
254
+ // callers can immediately resolve artifact IDs via getArtifact().
255
+ this.rebuildArtifactsFromMetadata(message);
256
+ return true;
257
+ }
258
+ this.processMessage(message);
259
+ return true;
260
+ }
199
261
  // ── Private helpers ────────────────────────────────────────────────
200
262
  /**
201
263
  * Try to extract a meaningful title from the first comment line of the code.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuraly/lumenui",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "A comprehensive collection of enterprise-class web components built with Lit and TypeScript",
5
5
  "type": "module",
6
6
  "main": "dist/nuralyui.bundle.js",
@@ -1,4 +1,4 @@
1
1
  # @nuralyui/common
2
2
 
3
3
  Version: 0.1.5
4
- Build Date: 2026-05-22
4
+ Build Date: 2026-05-29