Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add standalone assistant page #72

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
['name' => 'config#setAdminConfig', 'url' => '/admin-config', 'verb' => 'PUT'],

['name' => 'assistant#getAssistantTaskResultPage', 'url' => '/task/view/{metaTaskId}', 'verb' => 'GET'],
['name' => 'assistant#getAssistantStandalonePage', 'url' => '/', 'verb' => 'GET'],

['name' => 'Text2Image#showGenerationPage', 'url' => '/i/{imageGenId}', 'verb' => 'GET'],
['name' => 'Text2Image#getPromptHistory', 'url' => '/i/data/prompt_history', 'verb' => 'GET'],
Expand Down
24 changes: 23 additions & 1 deletion lib/Controller/AssistantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace OCA\Assistant\Controller;

use OCA\Assistant\AppInfo\Application;
use OCA\Assistant\Db\MetaTask;
use OCA\Assistant\Service\AssistantService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
Expand All @@ -11,6 +12,7 @@
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\IRequest;

#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
Expand All @@ -21,6 +23,7 @@ public function __construct(
IRequest $request,
private AssistantService $assistantService,
private IInitialState $initialStateService,
private IConfig $config,
private ?string $userId,
) {
parent::__construct($appName, $request);
Expand All @@ -37,9 +40,28 @@ public function getAssistantTaskResultPage(int $metaTaskId): TemplateResponse {
$task = $this->assistantService->getAssistantTask($this->userId, $metaTaskId);
if ($task !== null) {
$this->initialStateService->provideInitialState('task', $task->jsonSerializeCc());
return new TemplateResponse(Application::APP_ID, 'taskResultPage');
return new TemplateResponse(Application::APP_ID, 'assistantPage');
}
}
return new TemplateResponse('', '403', [], TemplateResponse::RENDER_AS_ERROR, Http::STATUS_FORBIDDEN);
}

/**
* @return TemplateResponse
*/
#[NoAdminRequired]
#[NoCSRFRequired]
public function getAssistantStandalonePage(): TemplateResponse {
if ($this->userId !== null) {
$task = new MetaTask();
$task->setTaskType($this->config->getUserValue($this->userId, Application::APP_ID, 'last_task_type'));
$task->setUserId($this->userId);
$task->setAppId(Application::APP_ID);
$task->setInputs('{"prompt":""}');
$task->setIdentifier('');
$this->initialStateService->provideInitialState('task', $task->jsonSerializeCc());
return new TemplateResponse(Application::APP_ID, 'assistantPage');
}
return new TemplateResponse('', '403', [], TemplateResponse::RENDER_AS_ERROR, Http::STATUS_FORBIDDEN);
}
}
3 changes: 3 additions & 0 deletions lib/Db/MetaTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public function jsonSerializeCc() {
* @return array
*/
public function getInputsAsArray(): array {
if ($this->inputs === null) {
return [];
}
return json_decode($this->inputs, true) ?? [];
}
}
6 changes: 6 additions & 0 deletions src/assistantPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Vue from 'vue'
import AssistantPage from './views/AssistantPage.vue'
Vue.mixin({ methods: { t, n } })

const View = Vue.extend(AssistantPage)
new View().$mount('#content')
6 changes: 0 additions & 6 deletions src/taskResultPage.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/views/TaskResultPage.vue → src/views/AssistantPage.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<template>
<NcContent app-name="assistant">
<NcAppContent>
<div v-if="task?.id"
class="assistant-wrapper">
<div class="assistant-wrapper">
<RunningEmptyContent
v-if="showSyncTaskRunning"
:description="shortInput"
Expand Down Expand Up @@ -48,7 +47,7 @@ import {
import { STATUS } from '../constants.js'

export default {
name: 'TaskResultPage',
name: 'AssistantPage',

components: {
ScheduledEmptyContent,
Expand Down Expand Up @@ -81,6 +80,7 @@ export default {
},

mounted() {
console.debug('[Assistant] task', this.task)
},

methods: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

$appId = OCA\Assistant\AppInfo\Application::APP_ID;
\OCP\Util::addScript($appId, $appId . '-taskResultPage');
\OCP\Util::addScript($appId, $appId . '-assistantPage');
2 changes: 1 addition & 1 deletion webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ webpackConfig.entry = {
personalSettings: { import: path.join(__dirname, 'src', 'personalSettings.js'), filename: appId + '-personalSettings.js' },
adminSettings: { import: path.join(__dirname, 'src', 'adminSettings.js'), filename: appId + '-adminSettings.js' },
main: { import: path.join(__dirname, 'src', 'main.js'), filename: appId + '-main.js' },
taskResultPage: { import: path.join(__dirname, 'src', 'taskResultPage.js'), filename: appId + '-taskResultPage.js' },
assistantPage: { import: path.join(__dirname, 'src', 'assistantPage.js'), filename: appId + '-assistantPage.js' },
}

webpackConfig.plugins.push(
Expand Down
Loading