get<Root.User.ById>()
post<Root.Admin.Ban, _>()
post<Root.Admin.Unban, _>()
+ get<Root.Admin.NukeManagement>()
+ post<Root.Admin.NukeManagement.Update, _>()
+ post<Root.Admin.NukeManagement.Reset, _>()
get<Root.Admin.Vfs.Inline>()
get<Root.Admin.Vfs.Download>()
get<Root.Admin.Vfs.View>()
suspend fun get() = Table.get(RobotGlobalsId)
suspend fun set(instance: RobotGlobals) = Table.put(instance)
+ suspend fun delete() = Table.del(RobotGlobalsId)
override suspend fun initialize() = Unit
}
logger.info("Vector store update is complete")
}
+ suspend fun reset() {
+ RobotGlobals.get()?.gcOldThreads()?.copy(
+ lastFileUpload = null,
+ fileIdMap = emptyMap(),
+ vectorStoreId = null,
+ assistantId = null,
+ )?.save()
+
+ while (true) {
+ val assistants = robotClient.listAssistants().data
+ if (assistants.isEmpty()) break
+
+ assistants.map { it.id }.forEach {
+ robotClient.deleteAssistant(it)
+ }
+ }
+
+ while (true) {
+ val vectorStores = robotClient.listVectorStores().data
+ if (vectorStores.isEmpty()) break
+
+ vectorStores.map { it.id }.forEach {
+ robotClient.deleteVectorStore(it)
+ }
+ }
+
+ robotClient.listFiles().data.map { it.id }.forEach {
+ robotClient.deleteFile(it)
+ }
+
+ initialize()
+ }
+
inner class Conversation(private val nationId: Id<NationData>) {
private var assistantId: RobotAssistantId? = null
private var threadId: RobotThreadId? = null
import info.mechyrdia.auth.createCsrfToken
import info.mechyrdia.data.currentNation
+import info.mechyrdia.lore.adminPage
import info.mechyrdia.lore.page
import info.mechyrdia.lore.redirectHref
import info.mechyrdia.lore.standardNavBar
conversation.close()
}
+
+fun ApplicationCall.robotManagementPage(): HTML.() -> Unit {
+ val robotServiceStatus = RobotService.status
+
+ return adminPage("NUKE Management") {
+ h1 { +"NUKE Management" }
+ when (robotServiceStatus) {
+ RobotServiceStatus.NOT_CONFIGURED -> p { +"Unfortunately, the NUKE is not configured on this website." }
+ RobotServiceStatus.LOADING -> p { +"The NUKE is still in the process of initializing." }
+ RobotServiceStatus.FAILED -> p { +"Tragically, the NUKE has failed to initialize due to an internal error." }
+ RobotServiceStatus.READY -> ul {
+ li {
+ form(action = href(Root.Admin.NukeManagement.Update()), method = FormMethod.post) {
+ submitInput {
+ value = "Manually Trigger File Update"
+ }
+ }
+ }
+ li {
+ form(action = href(Root.Admin.NukeManagement.Reset()), method = FormMethod.post) {
+ submitInput(classes = "evil") {
+ value = "Reset All Data And Start Over"
+ }
+ }
+ }
+ }
+ }
+ }
+}
@Serializable
class AdminUnbanUserPayload(override val csrfToken: String? = null) : CsrfProtectedResourcePayload
+@Serializable
+class AdminNukeUpdatePayload(override val csrfToken: String? = null) : CsrfProtectedResourcePayload
+
+@Serializable
+class AdminNukeResetPayload(override val csrfToken: String? = null) : CsrfProtectedResourcePayload
+
@Serializable
class AdminVfsCopyFilePayload(val from: String, override val csrfToken: String? = null) : CsrfProtectedResourcePayload
import info.mechyrdia.auth.*
import info.mechyrdia.data.*
import info.mechyrdia.lore.*
+import info.mechyrdia.robot.RobotService
import info.mechyrdia.robot.robotConversation
+import info.mechyrdia.robot.robotManagementPage
import info.mechyrdia.robot.robotPage
import io.ktor.http.*
import io.ktor.http.content.*
}
}
+ @Resource("nuke")
+ class NukeManagement(val admin: Admin = Admin()) : ResourceFilter, ResourceHandler {
+ override suspend fun PipelineContext<Unit, ApplicationCall>.filterCall() {
+ with(admin) { filterCall() }
+ }
+
+ override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
+ filterCall()
+ call.respondHtml(HttpStatusCode.OK, call.robotManagementPage())
+ }
+
+ @Resource("update")
+ class Update(val nukeManagement: NukeManagement = NukeManagement()) : ResourceReceiver<AdminNukeUpdatePayload> {
+ override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: AdminNukeUpdatePayload) {
+ with(nukeManagement) { filterCall() }
+ with(payload) { call.verifyCsrfToken() }
+
+ RobotService.getInstance()?.performMaintenance()
+
+ call.redirectHref(NukeManagement())
+ }
+ }
+
+ @Resource("reset")
+ class Reset(val nukeManagement: NukeManagement = NukeManagement()) : ResourceReceiver<AdminNukeResetPayload> {
+ override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: AdminNukeResetPayload) {
+ with(nukeManagement) { filterCall() }
+ with(payload) { call.verifyCsrfToken() }
+
+ RobotService.getInstance()?.reset()
+
+ call.redirectHref(NukeManagement())
+ }
+ }
+ }
+
@Resource("vfs")
class Vfs(val admin: Admin = Admin()) : ResourceFilter {
override suspend fun PipelineContext<Unit, ApplicationCall>.filterCall() {