Skip to content

Commit

Permalink
DOC-847 Implement AI assistance with Bloblang playground errors (#256)
Browse files Browse the repository at this point in the history
* Get help with Bloblang playground

* DOC-847 Implement AI assistance with Bloblang playground errors

* Default display none

* Apply suggestions from code review

* Apply suggestions from code review
  • Loading branch information
JakeSCahill authored Feb 7, 2025
1 parent b1e0a77 commit 9ba77b8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/css/bloblang-playground.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@
z-index: 1000;
}

.bloblang-playground .custom-ai-help-button {
background-color: rgb(225, 66, 37);
box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 10px;
border-radius: 10px;
border: none;
color: white;
height: 32px;
display: none;
font-size: var(--secondary-font-size);
}

.bloblang-playground .custom-ai-help-button:hover {
background-color: #cc4626;
color: white;
cursor: pointer;
}

.bloblang-playground .banner span {
margin: 0;
flex-grow: 1;
Expand Down
49 changes: 48 additions & 1 deletion src/partials/bloblang-playground.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ For more details about this bundle and for the source code, see https://github.c
{{/each}}
</select>
</div>
<button
id="custom-ai-help"
type="button"
class="custom-ai-help-button"
>
Get help from AI
</button>

<div class="playground-container">
<!-- Editors -->
<section class="editors">
Expand Down Expand Up @@ -54,7 +62,7 @@ For more details about this bundle and for the source code, see https://github.c
</section>
</div>
<script>
let aceInputEditor, aceMappingEditor, aceOutputEditor,metadataDetails, choices;
let aceInputEditor, aceMappingEditor, aceOutputEditor,metadataDetails, choices, customAIButton;
const TAB_SIZE = 2;
// Keys for sessionStorage
Expand Down Expand Up @@ -98,8 +106,11 @@ function prettifyJSON(json) {
}
}
document.addEventListener("DOMContentLoaded", () => {
metadataDetails = document.getElementById("metadata-details");
customAIButton = document.getElementById("custom-ai-help");
// Initialize input editor
aceInputEditor = initializeAceEditor("ace-input", 'ace/mode/json', false, defaultInput);
Expand Down Expand Up @@ -186,6 +197,39 @@ document.addEventListener("DOMContentLoaded", () => {
saveTosessionStorage();
});
customAIButton.addEventListener("click", () => {
const input = aceInputEditor.getValue();
const mapping = aceMappingEditor.getValue();
const meta = aceInputMetadataEditor.getValue();
const output = aceOutputEditor.getValue();
const kapa = window.Kapa
// Simulate a click on the AI modal trigger
if (kapa) {
let aiPromptText = "I am using the Bloblang playground to test my Bloblang mappings for Redpanda Connect. I encountered an error with the following configuration:\n\n";
if (input && input !== "{}") {
aiPromptText += `Input:\n\n${input}\n\n`;
}
if (meta && meta !== "{}") {
aiPromptText += `Input Metadata:\n\n${meta}\n\n`;
}
if (mapping) {
aiPromptText += `Mapping:\n\n${mapping}\n\n`;
}
if (output) {
aiPromptText += `Output:\n\n${output}\n\n`;
}
aiPromptText += "Can you help debug this?";
kapa.open({
mode: 'ai',
query: aiPromptText,
submit: true
})
} else {
console.warn('Kapa AI is not available. Please check your configuration.')
}
});
// Handle prettify button
document.getElementById("prettify").addEventListener("click", () => {
try {
Expand Down Expand Up @@ -256,6 +300,7 @@ function execute() {
const result = blobl(getMapping(), getInput(), getInputMetadata());
if (isValidJSON(result)) {
customAIButton.style.display = "none";
const parsedResult = JSON.parse(result);
// Separate message and metadata
Expand All @@ -278,6 +323,7 @@ function execute() {
// If the result is not JSON, handle it as raw text
aceOutputEditor.session.setMode("ace/mode/text");
aceOutputEditor.setValue(result, 1);
customAIButton.style.display = "inline-block";
aceOutputMetadataEditor.session.setMode("ace/mode/text");
aceOutputMetadataEditor.setValue("No metadata available", 1);
Expand All @@ -286,6 +332,7 @@ function execute() {
// Handle general errors
aceOutputEditor.session.setMode("ace/mode/text");
aceOutputEditor.setValue("Error: " + error.message, 1);
customAIButton.style.display = "inline-block";
aceOutputMetadataEditor.session.setMode("ace/mode/text");
aceOutputMetadataEditor.setValue("Error: " + error.message, 1);
Expand Down

0 comments on commit 9ba77b8

Please sign in to comment.