Skip to content

Commit

Permalink
Merge pull request #16 from phillip-kruger/publisher
Browse files Browse the repository at this point in the history
Remove all code from runtime module
  • Loading branch information
phillip-kruger authored Jul 28, 2024
2 parents 9ae1631 + 6755671 commit 7f88e6e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;

import io.quarkiverse.chappie.runtime.ChappieJsonRPCService;
import io.quarkiverse.chappie.runtime.LastException;
import io.quarkus.builder.Version;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
Expand All @@ -19,8 +17,6 @@
import io.quarkus.deployment.dev.ExceptionNotificationBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.dev.console.DevConsoleManager;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import io.quarkus.devui.spi.buildtime.BuildTimeActionBuildItem;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;
Expand Down Expand Up @@ -61,42 +57,40 @@ public CardPageBuildItem pages() {

chappiePage.addPage(Page.webComponentPageBuilder()
.icon("font-awesome-solid:circle-question")
.title("AI Assistance")
.title("Help with the latest exception")
.componentLink("qwc-chappie-exception.js"));

return chappiePage;
}

@BuildStep(onlyIf = IsDevelopment.class)
JsonRPCProvidersBuildItem createJsonRPCService(LastExceptionBuildItem lastExceptionBuildItem) {

DevConsoleManager.register("chappie-exception-notification", (t) -> {
return lastExceptionBuildItem.getLastExceptionPublisher();
});

return new JsonRPCProvidersBuildItem(ChappieJsonRPCService.class);
}

@BuildStep(onlyIf = IsDevelopment.class)
BuildTimeActionBuildItem createBuildTimeActions(CurateOutcomeBuildItem curateOutcomeBuildItem,
OutputTargetBuildItem outputTargetBuildItem,
LastExceptionBuildItem lastExceptionBuildItem,
ChappieConfig chappieConfig) {

Path srcMainJava = ChappieProcessorHelper.getSourceRoot(curateOutcomeBuildItem.getApplicationModel(),
outputTargetBuildItem.getOutputDirectory());

BuildTimeActionBuildItem generateManifestActions = new BuildTimeActionBuildItem();
generateManifestActions.addAction("getLastException", ignored -> {
BuildTimeActionBuildItem buildItemActions = new BuildTimeActionBuildItem();

// This gets the last know exception. For initial load.
buildItemActions.addAction("getLastException", ignored -> {
LastException lastException = lastExceptionReference.get();
if (lastException != null) {
return lastException;
}
return null;
});

// This streams exceptions as they happen
buildItemActions.addSubscription("streamException", ignored -> {
return lastExceptionBuildItem.getLastExceptionPublisher();
});

// TODO: Get last suggested Fix

generateManifestActions.addAction("helpFix", ignored -> {
buildItemActions.addAction("helpFix", ignored -> {
LastException lastException = lastExceptionReference.get();
if (lastException != null) {
StackTraceElement stackTraceElement = lastException.stackTraceElement();
Expand All @@ -123,7 +117,7 @@ BuildTimeActionBuildItem createBuildTimeActions(CurateOutcomeBuildItem curateOut
return null;
});

return generateManifestActions;
return buildItemActions;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;

import io.quarkiverse.chappie.runtime.LastException;
import io.quarkus.builder.Version;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
Expand Down Expand Up @@ -60,7 +59,7 @@ void setupExceptionHandler(BuildProducer<ExceptionNotificationBuildItem> excepti

Vertx vertx = Vertx.vertx();
chappieConsoleContext.reset(
new ConsoleCommand('a', "Get AI to help with the last exception",
new ConsoleCommand('a', "Help with the latest exception",
new ConsoleCommand.HelpState(new Supplier<String>() {
@Override
public String get() {
Expand Down Expand Up @@ -88,7 +87,7 @@ public void run() {
String stacktraceString = lastException.getStackTraceString();

System.out.println(
"Chappie\n===============\nAsking AI to assist with the exception, please wait");
"Chappie\n===============\nAssisting with the exception, please wait");

long timer = vertx.setPeriodic(800, id -> System.out.print("."));

Expand All @@ -98,9 +97,9 @@ public void run() {
vertx.cancelTimer(timer);
System.out.println("\n\n" + suggestedFix.response());
System.out.println("\n\n" + suggestedFix.explanation());
System.out.println("------ Diff ------ ");
System.out.println("\n------ Diff ------ ");
System.out.println("\n\n" + suggestedFix.diff());
System.out.println("------ Suggested source ------ ");
System.out.println("\n------ Suggested source ------ ");
System.out.println("\n\n" + suggestedFix.suggestedSource());
}).exceptionally(throwable -> {
// Handle any errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;

import io.quarkiverse.chappie.runtime.LastException;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.workspace.WorkspaceModule;
import io.quarkus.deployment.annotations.BuildProducer;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkiverse.chappie.runtime;
package io.quarkiverse.chappie.deployment;

import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.concurrent.Flow;

import io.quarkiverse.chappie.runtime.LastException;
import io.quarkus.builder.item.SimpleBuildItem;
import io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor;

Expand All @@ -19,7 +18,6 @@ public BroadcastProcessor<LastException> getLastExceptionBroadcastProcessor() {
}

public Flow.Publisher<LastException> getLastExceptionPublisher() {
Flow.Publisher<LastException> publisher = this.lastExceptionBroadcastProcessor.toHotStream();
return publisher;
return (Flow.Publisher<LastException>) this.lastExceptionBroadcastProcessor;
}
}
4 changes: 2 additions & 2 deletions deployment/src/main/resources/dev-ui/qwc-chappie-exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class QwcChappieException extends observeState(LitElement) {
connectedCallback() {
super.connectedCallback();
// Subscribe to real-time exceptions
this._observer = this.jsonRpc.streamLastException().onNext(jsonRpcResponse => {
this._observer = this.jsonRpc.streamException().onNext(jsonRpcResponse => {
this._lastException = jsonRpcResponse.result;
this._suggestedFix = null;
});
Expand Down Expand Up @@ -109,7 +109,7 @@ export class QwcChappieException extends observeState(LitElement) {
_renderSuggestedFix(){
if(this._showProgressBar){
return html`<div>
<label class="text-secondary" id="pblbl">Talking to AI...</label>
<label class="text-secondary" id="pblbl">Talking to Chappie...</label>
<vaadin-progress-bar
indeterminate
aria-labelledby="pblbl"
Expand Down

This file was deleted.

0 comments on commit 7f88e6e

Please sign in to comment.