3
3
* SPDX-License-Identifier: AGPL-3.0-only
4
4
*/
5
5
6
+ import { ref } from 'vue' ;
6
7
import { Interpreter , Parser , utils , values } from '@syuilo/aiscript' ;
7
8
import { aiScriptReadline , createAiScriptEnv } from '@/scripts/aiscript/api.js' ;
8
9
import { inputText } from '@/os.js' ;
9
10
import { Plugin , noteActions , notePostInterruptors , noteViewInterruptors , postFormActions , userActions , pageViewInterruptors } from '@/store.js' ;
10
11
11
12
const parser = new Parser ( ) ;
12
13
const pluginContexts = new Map < string , Interpreter > ( ) ;
14
+ export const pluginLogs = ref ( new Map < string , string [ ] > ( ) ) ;
13
15
14
16
export async function install ( plugin : Plugin ) : Promise < void > {
15
17
// 後方互換性のため
@@ -22,21 +24,27 @@ export async function install(plugin: Plugin): Promise<void> {
22
24
in : aiScriptReadline ,
23
25
out : ( value ) : void => {
24
26
console . log ( value ) ;
27
+ pluginLogs . value . get ( plugin . id ) . push ( utils . reprValue ( value ) ) ;
25
28
} ,
26
29
log : ( ) : void => {
27
30
} ,
31
+ err : ( err ) : void => {
32
+ pluginLogs . value . get ( plugin . id ) . push ( `${ err } ` ) ;
33
+ throw err ; // install時のtry-catchに反応させる
34
+ } ,
28
35
} ) ;
29
36
30
37
initPlugin ( { plugin, aiscript } ) ;
31
38
32
- try {
33
- await aiscript . exec ( parser . parse ( plugin . src ) ) ;
34
- } catch ( err ) {
35
- console . error ( 'Plugin install failed:' , plugin . name , 'v' + plugin . version ) ;
36
- return ;
37
- }
38
-
39
- console . info ( 'Plugin installed:' , plugin . name , 'v' + plugin . version ) ;
39
+ aiscript . exec ( parser . parse ( plugin . src ) ) . then (
40
+ ( ) => {
41
+ console . info ( 'Plugin installed:' , plugin . name , 'v' + plugin . version ) ;
42
+ } ,
43
+ ( err ) => {
44
+ console . error ( 'Plugin install failed:' , plugin . name , 'v' + plugin . version ) ;
45
+ throw err ;
46
+ } ,
47
+ ) ;
40
48
}
41
49
42
50
function createPluginEnv ( opts : { plugin : Plugin ; storageKey : string } ) : Record < string , values . Value > {
@@ -92,6 +100,7 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record<s
92
100
93
101
function initPlugin ( { plugin, aiscript } ) : void {
94
102
pluginContexts . set ( plugin . id , aiscript ) ;
103
+ pluginLogs . value . set ( plugin . id , [ ] ) ;
95
104
}
96
105
97
106
function registerPostFormAction ( { pluginId, title, handler } ) : void {
0 commit comments