Skip to content

Commit

Permalink
feat: dbgpt adaptable
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinesmilelk authored and BroKun committed Nov 18, 2024
1 parent 78eb8cb commit 67bc3ed
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 10 deletions.
5 changes: 4 additions & 1 deletion lab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
"@difizen/libro-core": "^0.2.28",
"@difizen/libro-jupyter": "^0.2.28",
"@difizen/libro-lab": "^0.2.28",
"@difizen/libro-terminal": "^0.2.28",
"@difizen/libro-prompt-cell": "^0.2.41",
"@difizen/libro-widget": "^0.2.41",
"@difizen/magent-core": "^0.1.27",
"@difizen/mana-app": "^0.1.25",
"@difizen/mana-react": "^0.1.27",
"@rjsf/antd": "^5.18.2",
Expand All @@ -40,7 +42,8 @@
"eventsource-parser": "^1.1.2",
"query-string": "^9.1.1",
"resize-observer-polyfill": "^1.5.1",
"umi": "^4.1.1"
"umi": "^4.1.1",
"uuid": "^11.0.2"
},
"devDependencies": {
"@babel/plugin-proposal-decorators": "^7.23.7",
Expand Down
62 changes: 61 additions & 1 deletion lab/src/pages/dbgpt/app.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import {
FileCommandContribution,
LibroFileService,
LibroJupyterConfiguration,
PageConfig,
ServerConnection,
ServerManager,
} from '@difizen/libro-jupyter';
import { ConfigurationService } from '@difizen/mana-app';
import { ConfigurationService, FileTreeView, FileTreeViewFactory, OpenerService, URI } from '@difizen/mana-app';
import { SlotViewManager } from '@difizen/mana-app';
import { terminalDefaultSlot } from '@difizen/libro-terminal';
import qs from 'query-string';
import { ApplicationContribution, ViewManager } from '@difizen/mana-app';
import { inject, singleton } from '@difizen/mana-app';
import { Fetcher } from '@difizen/magent-core';
import { LayoutService, LibroLabLayoutSlots } from '@difizen/libro-lab';
const ShouldPreventStoreViewKey = 'mana-should-prevent-store-view';

@singleton({ contrib: ApplicationContribution })
export class LibroApp implements ApplicationContribution {
Expand All @@ -17,7 +23,12 @@ export class LibroApp implements ApplicationContribution {
@inject(ViewManager) viewManager: ViewManager;
@inject(SlotViewManager) slotViewManager: SlotViewManager;
@inject(ConfigurationService) configurationService: ConfigurationService;
@inject(LayoutService) layoutService: LayoutService;
@inject(FileCommandContribution) fileCommandContribution: FileCommandContribution;
@inject(Fetcher) fetcher: Fetcher;
@inject(OpenerService) openerService: OpenerService;
@inject(LibroFileService) libroFileService: LibroFileService;
location: string

async onStart() {
this.configurationService.set(LibroJupyterConfiguration.AllowDownload, true);
Expand All @@ -33,10 +44,59 @@ export class LibroApp implements ApplicationContribution {
baseUrl = window.location.origin + baseUrl;
}
}
localStorage.setItem(ShouldPreventStoreViewKey, 'true');
this.configurationService.set(
LibroJupyterConfiguration['OpenSlot'],
LibroLabLayoutSlots.content,
);
this.configurationService.set(
terminalDefaultSlot,
LibroLabLayoutSlots.contentBottom,
);
this.serverConnection.updateSettings({
baseUrl,
wsUrl: baseUrl.replace(/^http(s)?/, 'ws$1'),
});
this.serverManager.launch();
this.serverManager.ready
.then(async () => {
this.layoutService.setAreaVisible(LibroLabLayoutSlots.navigator, true);
this.layoutService.setAreaVisible(LibroLabLayoutSlots.alert, false);
this.layoutService.serverSatus = 'success';
await this.initialWorkspace();
if(this.location){
const defaultOpenUri = new URI(this.location+'/__init__.py');

this.openerService.getOpener(defaultOpenUri).then((opener) => {
if (opener) {
opener.open(defaultOpenUri, {
viewOptions: {
name: '__init__.py',
},
});
}
});
}
return;
})
.catch(console.error);
}

protected async initialWorkspace() {
const queryParams = qs.parse(window.location.search);
const flow_uid = queryParams['flow_uid'];
const res = await this.fetcher.get<any>(`/api/v1/serve/awel/flow/notebook/file/path`, {
flow_uid:flow_uid,
},{baseURL:'http://localhost:5670'});
if(res.status&& res.data?.data?.path){
const view =
await this.viewManager.getOrCreateView<FileTreeView>(FileTreeViewFactory);
if (view) {
const location = res.data?.data?.path;
this.location = location;
view.model.rootVisible = false;
view.model.location = new URI(location);
}
}
}
}
17 changes: 11 additions & 6 deletions lab/src/pages/dbgpt/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LibroLabModule } from '@difizen/libro-lab';
import { LibroLabApp, LibroLabModule } from '@difizen/libro-lab';
import { ManaAppPreset, ManaComponents, ManaModule, Syringe } from '@difizen/mana-app';

import { LibroApp } from './app.js';
Expand All @@ -7,11 +7,16 @@ import { LibroPromptScript } from './prompt-script.js';
import { PromptScript } from '@difizen/libro-prompt-cell';
import { LibroSchemaFormWidgetModule } from './schema-form-widget/index.js';

const BaseModule = ManaModule.create().register(LibroApp,{
token: PromptScript,
useClass: LibroPromptScript,
lifecycle: Syringe.Lifecycle.singleton,
});
const BaseModule = ManaModule.create().register({
token:LibroLabApp,
useClass:LibroApp
},
{
token: PromptScript,
useClass: LibroPromptScript,
lifecycle: Syringe.Lifecycle.singleton,
}
);

const App = (): JSX.Element => {
return (
Expand Down
2 changes: 1 addition & 1 deletion libro-server/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "libro-server"
version = "0.1.7"
version = "0.1.8.dev1"
description = "libro server"
authors = [
{ name = "zhanba", email = "[email protected]" },
Expand Down
2 changes: 1 addition & 1 deletion libro-server/src/libro_server/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = "0.1.7"
__version__ = "0.1.8.dev1"

0 comments on commit 67bc3ed

Please sign in to comment.