fix: upgrade AiScript!
There are braking changes in the AiScript syntax, so existing plugins must alse be upgraded Also, I didn't include the function that can call remote servers' API (which is present in the latest Misskey) Co-authored-by: syuilo <syuilotan@yahoo.co.jp> Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com>
This commit is contained in:
parent
31ccedf177
commit
845f08893f
11 changed files with 164 additions and 101 deletions
|
@ -37,7 +37,6 @@
|
||||||
"@peertube/http-signature": "1.7.0",
|
"@peertube/http-signature": "1.7.0",
|
||||||
"@redocly/openapi-core": "1.0.2",
|
"@redocly/openapi-core": "1.0.2",
|
||||||
"@sinonjs/fake-timers": "9.1.2",
|
"@sinonjs/fake-timers": "9.1.2",
|
||||||
"@syuilo/aiscript": "0.11.1",
|
|
||||||
"@tensorflow/tfjs": "^4.2.0",
|
"@tensorflow/tfjs": "^4.2.0",
|
||||||
"adm-zip": "^0.5.10",
|
"adm-zip": "^0.5.10",
|
||||||
"ajv": "8.12.0",
|
"ajv": "8.12.0",
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
"@rollup/plugin-alias": "5.0.0",
|
"@rollup/plugin-alias": "5.0.0",
|
||||||
"@rollup/plugin-json": "6.0.0",
|
"@rollup/plugin-json": "6.0.0",
|
||||||
"@rollup/pluginutils": "^5.0.4",
|
"@rollup/pluginutils": "^5.0.4",
|
||||||
"@syuilo/aiscript": "0.11.1",
|
"@syuilo/aiscript": "0.16.0",
|
||||||
"@types/autosize": "^4.0.2",
|
"@types/autosize": "^4.0.2",
|
||||||
"@types/escape-regexp": "0.0.1",
|
"@types/escape-regexp": "0.0.1",
|
||||||
"@types/glob": "8.1.0",
|
"@types/glob": "8.1.0",
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PropType } from "vue";
|
import type { PropType } from "vue";
|
||||||
import { defineComponent, nextTick, onMounted, onUnmounted } from "vue";
|
import { defineComponent, nextTick, onMounted, onUnmounted } from "vue";
|
||||||
import { parse } from "@syuilo/aiscript";
|
import { Parser } from "@syuilo/aiscript";
|
||||||
import XBlock from "./page.block.vue";
|
import XBlock from "./page.block.vue";
|
||||||
import { Hpml } from "@/scripts/hpml/evaluator";
|
import { Hpml } from "@/scripts/hpml/evaluator";
|
||||||
import { url } from "@/config";
|
import { url } from "@/config";
|
||||||
|
@ -42,12 +42,14 @@ export default defineComponent({
|
||||||
enableAiScript: !defaultStore.state.disablePagesScript,
|
enableAiScript: !defaultStore.state.disablePagesScript,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const parser = new Parser();
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (props.page.script && hpml.aiscript) {
|
if (props.page.script && hpml.aiscript) {
|
||||||
let ast;
|
let ast;
|
||||||
try {
|
try {
|
||||||
ast = parse(props.page.script);
|
ast = parser.parse(props.page.script);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
/* os.alert({
|
/* os.alert({
|
||||||
|
|
|
@ -45,7 +45,7 @@ import "prismjs/components/prism-javascript";
|
||||||
import "prismjs/themes/prism-okaidia.css";
|
import "prismjs/themes/prism-okaidia.css";
|
||||||
import { PrismEditor } from "vue-prism-editor";
|
import { PrismEditor } from "vue-prism-editor";
|
||||||
import "vue-prism-editor/dist/prismeditor.min.css";
|
import "vue-prism-editor/dist/prismeditor.min.css";
|
||||||
import { AiScript, parse, utils } from "@syuilo/aiscript";
|
import { Interpreter, Parser, utils } from "@syuilo/aiscript";
|
||||||
import MkContainer from "@/components/MkContainer.vue";
|
import MkContainer from "@/components/MkContainer.vue";
|
||||||
import MkButton from "@/components/MkButton.vue";
|
import MkButton from "@/components/MkButton.vue";
|
||||||
import { createAiScriptEnv } from "@/scripts/aiscript/api";
|
import { createAiScriptEnv } from "@/scripts/aiscript/api";
|
||||||
|
@ -58,6 +58,8 @@ import icon from "@/scripts/icon";
|
||||||
const code = ref("");
|
const code = ref("");
|
||||||
const logs = ref<any[]>([]);
|
const logs = ref<any[]>([]);
|
||||||
|
|
||||||
|
const parser = new Parser();
|
||||||
|
|
||||||
const saved = localStorage.getItem("scratchpad");
|
const saved = localStorage.getItem("scratchpad");
|
||||||
if (saved) {
|
if (saved) {
|
||||||
code.value = saved;
|
code.value = saved;
|
||||||
|
@ -69,7 +71,7 @@ watch(code, () => {
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
logs.value = [];
|
logs.value = [];
|
||||||
const aiscript = new AiScript(
|
const aiscript = new Interpreter(
|
||||||
createAiScriptEnv({
|
createAiScriptEnv({
|
||||||
storageKey: "scratchpad",
|
storageKey: "scratchpad",
|
||||||
token: $i?.token,
|
token: $i?.token,
|
||||||
|
@ -112,11 +114,11 @@ async function run() {
|
||||||
|
|
||||||
let ast;
|
let ast;
|
||||||
try {
|
try {
|
||||||
ast = parse(code.value);
|
ast = parser.parse(code.value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: "error",
|
type: "error",
|
||||||
text: "Syntax error :(",
|
text: `Syntax error : ${error}`,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { defineAsyncComponent, nextTick, ref } from "vue";
|
import { defineAsyncComponent, nextTick, ref } from "vue";
|
||||||
import { AiScript, parse } from "@syuilo/aiscript";
|
import { Interpreter, Parser, utils } from "@syuilo/aiscript";
|
||||||
import { serialize } from "@syuilo/aiscript/built/serializer";
|
|
||||||
import { v4 as uuid } from "uuid";
|
import { v4 as uuid } from "uuid";
|
||||||
import FormTextarea from "@/components/form/textarea.vue";
|
import FormTextarea from "@/components/form/textarea.vue";
|
||||||
import FormButton from "@/components/MkButton.vue";
|
import FormButton from "@/components/MkButton.vue";
|
||||||
|
@ -30,11 +29,20 @@ import { ColdDeviceStorage } from "@/store";
|
||||||
import { unisonReload } from "@/scripts/unison-reload";
|
import { unisonReload } from "@/scripts/unison-reload";
|
||||||
import { i18n } from "@/i18n";
|
import { i18n } from "@/i18n";
|
||||||
import { definePageMetadata } from "@/scripts/page-metadata";
|
import { definePageMetadata } from "@/scripts/page-metadata";
|
||||||
|
import { compareVersions } from "compare-versions";
|
||||||
import icon from "@/scripts/icon";
|
import icon from "@/scripts/icon";
|
||||||
|
|
||||||
const code = ref(null);
|
const code = ref<string>();
|
||||||
|
|
||||||
function installPlugin({ id, meta, ast, token }) {
|
function isSupportedVersion(version: string): boolean {
|
||||||
|
try {
|
||||||
|
return compareVersions(version, "0.12.0") >= 0;
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function installPlugin({ id, meta, src, token }) {
|
||||||
ColdDeviceStorage.set(
|
ColdDeviceStorage.set(
|
||||||
"plugins",
|
"plugins",
|
||||||
ColdDeviceStorage.get("plugins").concat({
|
ColdDeviceStorage.get("plugins").concat({
|
||||||
|
@ -42,25 +50,46 @@ function installPlugin({ id, meta, ast, token }) {
|
||||||
id,
|
id,
|
||||||
active: true,
|
active: true,
|
||||||
configData: {},
|
configData: {},
|
||||||
|
src,
|
||||||
token,
|
token,
|
||||||
ast,
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parser = new Parser();
|
||||||
|
|
||||||
async function install() {
|
async function install() {
|
||||||
let ast;
|
if (code.value == null) return;
|
||||||
try {
|
|
||||||
ast = parse(code.value);
|
const scriptVersion = utils.getLangVersion(code.value);
|
||||||
} catch (err) {
|
|
||||||
|
if (scriptVersion == null) {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: "error",
|
type: "error",
|
||||||
text: "Syntax error :(",
|
text: "No language version annotation found :(",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isSupportedVersion(scriptVersion)) {
|
||||||
|
os.alert({
|
||||||
|
type: "error",
|
||||||
|
text: `aiscript version '${scriptVersion}' is not supported :(`,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const meta = AiScript.collectMetadata(ast);
|
let ast;
|
||||||
|
try {
|
||||||
|
ast = parser.parse(code.value);
|
||||||
|
} catch (err) {
|
||||||
|
os.alert({
|
||||||
|
type: "error",
|
||||||
|
text: `Syntax error : ${err}`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const meta = Interpreter.collectMetadata(ast);
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: "error",
|
type: "error",
|
||||||
|
@ -83,7 +112,7 @@ async function install() {
|
||||||
if (name == null || version == null || author == null) {
|
if (name == null || version == null || author == null) {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: "error",
|
type: "error",
|
||||||
text: "Required property not found :(",
|
text: "Required property (name, version, author) not found :(",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -134,8 +163,8 @@ async function install() {
|
||||||
permissions,
|
permissions,
|
||||||
config,
|
config,
|
||||||
},
|
},
|
||||||
|
src: code.value,
|
||||||
token,
|
token,
|
||||||
ast: serialize(ast),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
os.success();
|
os.success();
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import { AiScript, utils, values } from "@syuilo/aiscript";
|
import { Interpreter, Parser, utils, values } from "@syuilo/aiscript";
|
||||||
import { deserialize } from "@syuilo/aiscript/built/serializer";
|
|
||||||
import { jsToVal } from "@syuilo/aiscript/built/interpreter/util";
|
|
||||||
import { createAiScriptEnv } from "@/scripts/aiscript/api";
|
import { createAiScriptEnv } from "@/scripts/aiscript/api";
|
||||||
import { inputText } from "@/os";
|
import { inputText } from "@/os";
|
||||||
import {
|
import {
|
||||||
|
@ -11,12 +9,13 @@ import {
|
||||||
userActions,
|
userActions,
|
||||||
} from "@/store";
|
} from "@/store";
|
||||||
|
|
||||||
const pluginContexts = new Map<string, AiScript>();
|
const parser = new Parser();
|
||||||
|
const pluginContexts = new Map<string, Interpreter>();
|
||||||
|
|
||||||
export function install(plugin) {
|
export function install(plugin) {
|
||||||
console.info("Plugin installed:", plugin.name, `v${plugin.version}`);
|
console.info("Plugin installed:", plugin.name, `v${plugin.version}`);
|
||||||
|
|
||||||
const aiscript = new AiScript(
|
const aiscript = new Interpreter(
|
||||||
createPluginEnv({
|
createPluginEnv({
|
||||||
plugin,
|
plugin,
|
||||||
storageKey: `plugins:${plugin.id}`,
|
storageKey: `plugins:${plugin.id}`,
|
||||||
|
@ -40,15 +39,15 @@ export function install(plugin) {
|
||||||
|
|
||||||
initPlugin({ plugin, aiscript });
|
initPlugin({ plugin, aiscript });
|
||||||
|
|
||||||
aiscript.exec(deserialize(plugin.ast));
|
aiscript.exec(parser.parse(plugin.src));
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPluginEnv(opts) {
|
function createPluginEnv(opts) {
|
||||||
const config = new Map();
|
const config = new Map<string, values.Value>();
|
||||||
for (const [k, v] of Object.entries(opts.plugin.config || {})) {
|
for (const [k, v] of Object.entries(opts.plugin.config ?? {})) {
|
||||||
config.set(
|
config.set(
|
||||||
k,
|
k,
|
||||||
jsToVal(
|
utils.jsToVal(
|
||||||
typeof opts.plugin.configData[k] !== "undefined"
|
typeof opts.plugin.configData[k] !== "undefined"
|
||||||
? opts.plugin.configData[k]
|
? opts.plugin.configData[k]
|
||||||
: v.default,
|
: v.default,
|
||||||
|
@ -114,6 +113,9 @@ function createPluginEnv(opts) {
|
||||||
handler,
|
handler,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
"Plugin:register_page_view_interruptor": values.FN_NATIVE(([handler]) => {
|
||||||
|
registerPageViewInterruptor({ pluginId: opts.plugin.id, handler });
|
||||||
|
}),
|
||||||
"Plugin:open_url": values.FN_NATIVE(([url]) => {
|
"Plugin:open_url": values.FN_NATIVE(([url]) => {
|
||||||
window.open(url.value, "_blank");
|
window.open(url.value, "_blank");
|
||||||
}),
|
}),
|
||||||
|
@ -129,10 +131,17 @@ function registerPostFormAction({ pluginId, title, handler }) {
|
||||||
postFormActions.push({
|
postFormActions.push({
|
||||||
title,
|
title,
|
||||||
handler: (form, update) => {
|
handler: (form, update) => {
|
||||||
pluginContexts.get(pluginId).execFn(handler, [
|
const pluginContext = pluginContexts.get(pluginId);
|
||||||
|
if (!pluginContext) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pluginContext.execFn(handler, [
|
||||||
utils.jsToVal(form),
|
utils.jsToVal(form),
|
||||||
values.FN_NATIVE(([key, value]) => {
|
values.FN_NATIVE(([key, value]) => {
|
||||||
update(key.value, value.value);
|
if (!key || !value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
update(utils.valToJs(key), utils.valToJs(value));
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
@ -143,7 +152,11 @@ function registerUserAction({ pluginId, title, handler }) {
|
||||||
userActions.push({
|
userActions.push({
|
||||||
title,
|
title,
|
||||||
handler: (user) => {
|
handler: (user) => {
|
||||||
pluginContexts.get(pluginId).execFn(handler, [utils.jsToVal(user)]);
|
const pluginContext = pluginContexts.get(pluginId);
|
||||||
|
if (!pluginContext) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pluginContext.execFn(handler, [utils.jsToVal(user)]);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -152,7 +165,11 @@ function registerNoteAction({ pluginId, title, handler }) {
|
||||||
noteActions.push({
|
noteActions.push({
|
||||||
title,
|
title,
|
||||||
handler: (note) => {
|
handler: (note) => {
|
||||||
pluginContexts.get(pluginId).execFn(handler, [utils.jsToVal(note)]);
|
const pluginContext = pluginContexts.get(pluginId);
|
||||||
|
if (!pluginContext) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pluginContext.execFn(handler, [utils.jsToVal(user)]);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -160,10 +177,12 @@ function registerNoteAction({ pluginId, title, handler }) {
|
||||||
function registerNoteViewInterruptor({ pluginId, handler }) {
|
function registerNoteViewInterruptor({ pluginId, handler }) {
|
||||||
noteViewInterruptors.push({
|
noteViewInterruptors.push({
|
||||||
handler: async (note) => {
|
handler: async (note) => {
|
||||||
|
const pluginContext = pluginContexts.get(pluginId);
|
||||||
|
if (!pluginContext) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
return utils.valToJs(
|
return utils.valToJs(
|
||||||
await pluginContexts
|
await pluginContext.execFn(handler, [utils.jsToVal(note)]),
|
||||||
.get(pluginId)
|
|
||||||
.execFn(handler, [utils.jsToVal(note)]),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -172,10 +191,26 @@ function registerNoteViewInterruptor({ pluginId, handler }) {
|
||||||
function registerNotePostInterruptor({ pluginId, handler }) {
|
function registerNotePostInterruptor({ pluginId, handler }) {
|
||||||
notePostInterruptors.push({
|
notePostInterruptors.push({
|
||||||
handler: async (note) => {
|
handler: async (note) => {
|
||||||
|
const pluginContext = pluginContexts.get(pluginId);
|
||||||
|
if (!pluginContext) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
return utils.valToJs(
|
return utils.valToJs(
|
||||||
await pluginContexts
|
await pluginContext.execFn(handler, [utils.jsToVal(note)]),
|
||||||
.get(pluginId)
|
);
|
||||||
.execFn(handler, [utils.jsToVal(note)]),
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerPageViewInterruptor({ pluginId, handler }): void {
|
||||||
|
pageViewInterruptors.push({
|
||||||
|
handler: async (page) => {
|
||||||
|
const pluginContext = pluginContexts.get(pluginId);
|
||||||
|
if (!pluginContext) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return utils.valToJs(
|
||||||
|
await pluginContext.execFn(handler, [utils.jsToVal(page)]),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -54,5 +54,8 @@ export function createAiScriptEnv(opts) {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
"Mk:url": values.FN_NATIVE(() => {
|
||||||
|
return values.STR(window.location.href);
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import autobind from "autobind-decorator";
|
import autobind from "autobind-decorator";
|
||||||
import { AiScript, utils, values } from "@syuilo/aiscript";
|
import { Interpreter, utils, values } from "@syuilo/aiscript";
|
||||||
import type { Ref } from "vue";
|
import type { Ref } from "vue";
|
||||||
import { markRaw, ref, unref } from "vue";
|
import { markRaw, ref, unref } from "vue";
|
||||||
import { collectPageVars } from "../collect-page-vars";
|
import { collectPageVars } from "../collect-page-vars";
|
||||||
|
@ -19,7 +19,7 @@ export class Hpml {
|
||||||
private variables: Variable[];
|
private variables: Variable[];
|
||||||
private pageVars: PageVar[];
|
private pageVars: PageVar[];
|
||||||
private envVars: Record<keyof typeof envVarsDef, any>;
|
private envVars: Record<keyof typeof envVarsDef, any>;
|
||||||
public aiscript?: AiScript;
|
public aiscript?: Interpreter;
|
||||||
public pageVarUpdatedCallback?: values.VFn;
|
public pageVarUpdatedCallback?: values.VFn;
|
||||||
public canvases: Record<string, HTMLCanvasElement> = {};
|
public canvases: Record<string, HTMLCanvasElement> = {};
|
||||||
public vars: Ref<Record<string, any>> = ref({});
|
public vars: Ref<Record<string, any>> = ref({});
|
||||||
|
@ -40,7 +40,7 @@ export class Hpml {
|
||||||
|
|
||||||
if (this.opts.enableAiScript) {
|
if (this.opts.enableAiScript) {
|
||||||
this.aiscript = markRaw(
|
this.aiscript = markRaw(
|
||||||
new AiScript(
|
new Interpreter(
|
||||||
{
|
{
|
||||||
...createAiScriptEnv({
|
...createAiScriptEnv({
|
||||||
storageKey: `pages:${this.page.id}`,
|
storageKey: `pages:${this.page.id}`,
|
||||||
|
|
|
@ -27,9 +27,13 @@
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { AiScript, parse, utils } from "@syuilo/aiscript";
|
import { Interpreter, Parser, utils } from "@syuilo/aiscript";
|
||||||
import type { Widget, WidgetComponentExpose } from "./widget";
|
import {
|
||||||
import { useWidgetPropsManager } from "./widget";
|
useWidgetPropsManager,
|
||||||
|
WidgetComponentEmits,
|
||||||
|
WidgetComponentProps,
|
||||||
|
} from "./widget";
|
||||||
|
import type { WidgetComponentExpose } from "./widget";
|
||||||
import type { GetFormResultType } from "@/scripts/form";
|
import type { GetFormResultType } from "@/scripts/form";
|
||||||
import * as os from "@/os";
|
import * as os from "@/os";
|
||||||
import MkContainer from "@/components/MkContainer.vue";
|
import MkContainer from "@/components/MkContainer.vue";
|
||||||
|
@ -55,11 +59,8 @@ const widgetPropsDef = {
|
||||||
|
|
||||||
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
||||||
|
|
||||||
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
||||||
// const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
||||||
// const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
||||||
const props = defineProps<{ widget?: Widget<WidgetProps> }>();
|
|
||||||
const emit = defineEmits<{ (ev: "updateProps", props: WidgetProps) }>();
|
|
||||||
|
|
||||||
const { widgetProps, configure } = useWidgetPropsManager(
|
const { widgetProps, configure } = useWidgetPropsManager(
|
||||||
name,
|
name,
|
||||||
|
@ -76,9 +77,11 @@ const logs = ref<
|
||||||
}[]
|
}[]
|
||||||
>([]);
|
>([]);
|
||||||
|
|
||||||
|
const parser = new Parser();
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
logs.value = [];
|
logs.value = [];
|
||||||
const aiscript = new AiScript(
|
const aiscript = new Interpreter(
|
||||||
createAiScriptEnv({
|
createAiScriptEnv({
|
||||||
storageKey: "widget",
|
storageKey: "widget",
|
||||||
token: $i?.token,
|
token: $i?.token,
|
||||||
|
@ -121,11 +124,11 @@ const run = async () => {
|
||||||
|
|
||||||
let ast;
|
let ast;
|
||||||
try {
|
try {
|
||||||
ast = parse(widgetProps.script);
|
ast = parser.parse(widgetProps.script);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: "error",
|
type: "error",
|
||||||
text: "Syntax error :(",
|
text: `Syntax error : ${err}`,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -134,7 +137,7 @@ const run = async () => {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: "error",
|
type: "error",
|
||||||
text: err,
|
text: String(err),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,12 +7,17 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { AiScript, parse } from "@syuilo/aiscript";
|
import { onMounted, onUnmounted, ref, watch } from "vue";
|
||||||
import type { Widget, WidgetComponentExpose } from "./widget";
|
import { Interpreter, Parser } from "@syuilo/aiscript";
|
||||||
import { useWidgetPropsManager } from "./widget";
|
import { createAiScriptEnv } from "@/scripts/aiscript/api";
|
||||||
|
import {
|
||||||
|
useWidgetPropsManager,
|
||||||
|
WidgetComponentEmits,
|
||||||
|
WidgetComponentProps,
|
||||||
|
} from "./widget";
|
||||||
|
import type { WidgetComponentExpose } from "./widget";
|
||||||
import type { GetFormResultType } from "@/scripts/form";
|
import type { GetFormResultType } from "@/scripts/form";
|
||||||
import * as os from "@/os";
|
import * as os from "@/os";
|
||||||
import { createAiScriptEnv } from "@/scripts/aiscript/api";
|
|
||||||
import { $i } from "@/reactiveAccount";
|
import { $i } from "@/reactiveAccount";
|
||||||
import MkButton from "@/components/MkButton.vue";
|
import MkButton from "@/components/MkButton.vue";
|
||||||
|
|
||||||
|
@ -36,11 +41,8 @@ const widgetPropsDef = {
|
||||||
|
|
||||||
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
||||||
|
|
||||||
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
||||||
// const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
||||||
// const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
||||||
const props = defineProps<{ widget?: Widget<WidgetProps> }>();
|
|
||||||
const emit = defineEmits<{ (ev: "updateProps", props: WidgetProps) }>();
|
|
||||||
|
|
||||||
const { widgetProps, configure } = useWidgetPropsManager(
|
const { widgetProps, configure } = useWidgetPropsManager(
|
||||||
name,
|
name,
|
||||||
|
@ -49,8 +51,10 @@ const { widgetProps, configure } = useWidgetPropsManager(
|
||||||
emit,
|
emit,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const parser = new Parser();
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
const aiscript = new AiScript(
|
const aiscript = new Interpreter(
|
||||||
createAiScriptEnv({
|
createAiScriptEnv({
|
||||||
storageKey: "widget",
|
storageKey: "widget",
|
||||||
token: $i?.token,
|
token: $i?.token,
|
||||||
|
@ -76,11 +80,11 @@ const run = async () => {
|
||||||
|
|
||||||
let ast;
|
let ast;
|
||||||
try {
|
try {
|
||||||
ast = parse(widgetProps.script);
|
ast = parser.parse(widgetProps.script);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: "error",
|
type: "error",
|
||||||
text: "Syntax error :(",
|
text: `Syntax error: ${err}`,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +93,7 @@ const run = async () => {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
os.alert({
|
os.alert({
|
||||||
type: "error",
|
type: "error",
|
||||||
text: err,
|
text: String(err),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -100,8 +104,3 @@ defineExpose<WidgetComponentExpose>({
|
||||||
id: props.widget ? props.widget.id : null,
|
id: props.widget ? props.widget.id : null,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.mkw-button {
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -129,9 +129,6 @@ importers:
|
||||||
'@sinonjs/fake-timers':
|
'@sinonjs/fake-timers':
|
||||||
specifier: 9.1.2
|
specifier: 9.1.2
|
||||||
version: 9.1.2
|
version: 9.1.2
|
||||||
'@syuilo/aiscript':
|
|
||||||
specifier: 0.11.1
|
|
||||||
version: 0.11.1
|
|
||||||
'@tensorflow/tfjs':
|
'@tensorflow/tfjs':
|
||||||
specifier: ^4.2.0
|
specifier: ^4.2.0
|
||||||
version: 4.2.0(seedrandom@3.0.5)
|
version: 4.2.0(seedrandom@3.0.5)
|
||||||
|
@ -358,8 +355,8 @@ importers:
|
||||||
specifier: 3.4.1
|
specifier: 3.4.1
|
||||||
version: 3.4.1
|
version: 3.4.1
|
||||||
re2:
|
re2:
|
||||||
specifier: 1.20.3
|
specifier: 1.20.5
|
||||||
version: 1.20.3
|
version: 1.20.5
|
||||||
redis-semaphore:
|
redis-semaphore:
|
||||||
specifier: 5.5.0
|
specifier: 5.5.0
|
||||||
version: 5.5.0(ioredis@5.3.2)
|
version: 5.5.0(ioredis@5.3.2)
|
||||||
|
@ -666,8 +663,8 @@ importers:
|
||||||
specifier: ^5.0.4
|
specifier: ^5.0.4
|
||||||
version: 5.0.4(rollup@3.28.1)
|
version: 5.0.4(rollup@3.28.1)
|
||||||
'@syuilo/aiscript':
|
'@syuilo/aiscript':
|
||||||
specifier: 0.11.1
|
specifier: 0.16.0
|
||||||
version: 0.11.1
|
version: 0.16.0
|
||||||
'@types/autosize':
|
'@types/autosize':
|
||||||
specifier: ^4.0.2
|
specifier: ^4.0.2
|
||||||
version: 4.0.2
|
version: 4.0.2
|
||||||
|
@ -3417,14 +3414,13 @@ packages:
|
||||||
dev: false
|
dev: false
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
/@syuilo/aiscript@0.11.1:
|
/@syuilo/aiscript@0.16.0:
|
||||||
resolution: {integrity: sha512-chwOIA3yLUKvOB0G611hjLArKTeOWNmTm3lHERSaDW1d+dS6do56naX6Lkwy2UpnwWC0qzeNSgg35elk6t2gZg==}
|
resolution: {integrity: sha512-CXvoWOq6kmOSUQtKv0IEf7Ebfkk5PO1LxAgLqgRRPgssPvDvINCXu/gFNXKdapkFMkmX+Gj8qjemKR1vnUS4ZA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
autobind-decorator: 2.4.0
|
|
||||||
chalk: 4.0.0
|
|
||||||
seedrandom: 3.0.5
|
seedrandom: 3.0.5
|
||||||
stringz: 2.1.0
|
stringz: 2.1.0
|
||||||
uuid: 7.0.3
|
uuid: 9.0.1
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@szmarczak/http-timer@4.0.6:
|
/@szmarczak/http-timer@4.0.6:
|
||||||
resolution: {integrity: sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==}
|
resolution: {integrity: sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==}
|
||||||
|
@ -5739,6 +5735,7 @@ packages:
|
||||||
/autobind-decorator@2.4.0:
|
/autobind-decorator@2.4.0:
|
||||||
resolution: {integrity: sha512-OGYhWUO72V6DafbF8PM8rm3EPbfuyMZcJhtm5/n26IDwO18pohE4eNazLoCGhPiXOCD0gEGmrbU3849QvM8bbw==}
|
resolution: {integrity: sha512-OGYhWUO72V6DafbF8PM8rm3EPbfuyMZcJhtm5/n26IDwO18pohE4eNazLoCGhPiXOCD0gEGmrbU3849QvM8bbw==}
|
||||||
engines: {node: '>=8.10', npm: '>=6.4.1'}
|
engines: {node: '>=8.10', npm: '>=6.4.1'}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/autolinker@4.0.0:
|
/autolinker@4.0.0:
|
||||||
resolution: {integrity: sha512-fl5Kh6BmEEZx+IWBfEirnRUU5+cOiV0OK7PEt0RBKvJMJ8GaRseIOeDU3FKf4j3CE5HVefcjHmhYPOcaVt0bZw==}
|
resolution: {integrity: sha512-fl5Kh6BmEEZx+IWBfEirnRUU5+cOiV0OK7PEt0RBKvJMJ8GaRseIOeDU3FKf4j3CE5HVefcjHmhYPOcaVt0bZw==}
|
||||||
|
@ -6513,13 +6510,6 @@ packages:
|
||||||
escape-string-regexp: 1.0.5
|
escape-string-regexp: 1.0.5
|
||||||
supports-color: 5.5.0
|
supports-color: 5.5.0
|
||||||
|
|
||||||
/chalk@4.0.0:
|
|
||||||
resolution: {integrity: sha512-N9oWFcegS0sFr9oh1oz2d7Npos6vNoWW9HvtCg5N1KRFpUhaAhvTv5Y58g880fZaEYSNm3qDz8SU1UrGvp+n7A==}
|
|
||||||
engines: {node: '>=10'}
|
|
||||||
dependencies:
|
|
||||||
ansi-styles: 4.3.0
|
|
||||||
supports-color: 7.2.0
|
|
||||||
|
|
||||||
/chalk@4.1.2:
|
/chalk@4.1.2:
|
||||||
resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==}
|
resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
|
@ -13550,8 +13540,8 @@ packages:
|
||||||
object-assign: 4.1.1
|
object-assign: 4.1.1
|
||||||
thenify-all: 1.6.0
|
thenify-all: 1.6.0
|
||||||
|
|
||||||
/nan@2.17.0:
|
/nan@2.18.0:
|
||||||
resolution: {integrity: sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==}
|
resolution: {integrity: sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/nanoid@3.3.3:
|
/nanoid@3.3.3:
|
||||||
|
@ -15408,12 +15398,12 @@ packages:
|
||||||
setimmediate: 1.0.5
|
setimmediate: 1.0.5
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/re2@1.20.3:
|
/re2@1.20.5:
|
||||||
resolution: {integrity: sha512-g5j4YjygwGEccP9SCuDI90uPlgALLEYLotfL0K+kqL3XKB4ht7Nm1JuXfOTG96c7JozpvCUxTz1T7oTNwwMI6w==}
|
resolution: {integrity: sha512-wZAqOjJ3m0PBgM2B8KG9dNJLwSNIAOZGiHN/c0FpKpaM1Hkg5NpKNAWSVbCXe+bb2K0xmHz6DPR4HJaQ2MejgQ==}
|
||||||
requiresBuild: true
|
requiresBuild: true
|
||||||
dependencies:
|
dependencies:
|
||||||
install-artifact-from-github: 1.3.3
|
install-artifact-from-github: 1.3.3
|
||||||
nan: 2.17.0
|
nan: 2.18.0
|
||||||
node-gyp: 9.4.0
|
node-gyp: 9.4.0
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
@ -17881,10 +17871,6 @@ packages:
|
||||||
hasBin: true
|
hasBin: true
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/uuid@7.0.3:
|
|
||||||
resolution: {integrity: sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==}
|
|
||||||
hasBin: true
|
|
||||||
|
|
||||||
/uuid@8.0.0:
|
/uuid@8.0.0:
|
||||||
resolution: {integrity: sha512-jOXGuXZAWdsTH7eZLtyXMqUb9EcWMGZNbL9YcGBJl4MH4nrxHmZJhEHvyLFrkxo+28uLb/NYRcStH48fnD0Vzw==}
|
resolution: {integrity: sha512-jOXGuXZAWdsTH7eZLtyXMqUb9EcWMGZNbL9YcGBJl4MH4nrxHmZJhEHvyLFrkxo+28uLb/NYRcStH48fnD0Vzw==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
@ -17898,6 +17884,11 @@ packages:
|
||||||
resolution: {integrity: sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==}
|
resolution: {integrity: sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
|
/uuid@9.0.1:
|
||||||
|
resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==}
|
||||||
|
hasBin: true
|
||||||
|
dev: true
|
||||||
|
|
||||||
/v8-compile-cache-lib@3.0.1:
|
/v8-compile-cache-lib@3.0.1:
|
||||||
resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==}
|
resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue