mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-11-27 14:28:08 +09:00
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
206d2f246e
commit
bb4f4b4b00
36
.pnp.cjs
generated
36
.pnp.cjs
generated
@ -3726,15 +3726,13 @@ const RAW_RUNTIME_STATE =
|
||||
}]\
|
||||
]],\
|
||||
["@syuilo/aiscript", [\
|
||||
["npm:0.11.1", {\
|
||||
"packageLocation": "./.yarn/cache/@syuilo-aiscript-npm-0.11.1-451b9d1a3f-4df4bb5a25.zip/node_modules/@syuilo/aiscript/",\
|
||||
["npm:0.16.0", {\
|
||||
"packageLocation": "./.yarn/cache/@syuilo-aiscript-npm-0.16.0-078d966ef6-5c77fc596d.zip/node_modules/@syuilo/aiscript/",\
|
||||
"packageDependencies": [\
|
||||
["@syuilo/aiscript", "npm:0.11.1"],\
|
||||
["autobind-decorator", "npm:2.4.0"],\
|
||||
["chalk", "npm:4.0.0"],\
|
||||
["@syuilo/aiscript", "npm:0.16.0"],\
|
||||
["seedrandom", "npm:3.0.5"],\
|
||||
["stringz", "npm:2.1.0"],\
|
||||
["uuid", "npm:7.0.3"]\
|
||||
["uuid", "npm:9.0.1"]\
|
||||
],\
|
||||
"linkType": "HARD"\
|
||||
}]\
|
||||
@ -7154,7 +7152,6 @@ const RAW_RUNTIME_STATE =
|
||||
["@swc/cli", "virtual:aa59773ac87791c4813d53447077fcf8a847d6de5a301d34dc31286584b1dbb26d30d3adb5b4c41c1e8aea04371e926fda05c09c6253647c432e11d872a304ba#npm:0.1.62"],\
|
||||
["@swc/core", "virtual:21a30884d94fbf67bcf4a1714713cc91d32809a34424c4ce678841dfdc63b58647c5e18570d56e36b3c762ee72f81c251599477127a715978fa6e1d8b9e5d952#npm:1.3.71"],\
|
||||
["@swc/core-android-arm64", "npm:1.3.11"],\
|
||||
["@syuilo/aiscript", "npm:0.11.1"],\
|
||||
["@types/adm-zip", "npm:0.5.0"],\
|
||||
["@types/async-lock", "npm:1.4.0"],\
|
||||
["@types/bcryptjs", "npm:2.4.2"],\
|
||||
@ -8122,15 +8119,6 @@ const RAW_RUNTIME_STATE =
|
||||
],\
|
||||
"linkType": "HARD"\
|
||||
}],\
|
||||
["npm:4.0.0", {\
|
||||
"packageLocation": "./.yarn/cache/chalk-npm-4.0.0-50e5418ea0-f8ae363f43.zip/node_modules/chalk/",\
|
||||
"packageDependencies": [\
|
||||
["chalk", "npm:4.0.0"],\
|
||||
["ansi-styles", "npm:4.3.0"],\
|
||||
["supports-color", "npm:7.2.0"]\
|
||||
],\
|
||||
"linkType": "HARD"\
|
||||
}],\
|
||||
["npm:4.1.2", {\
|
||||
"packageLocation": "./.yarn/cache/chalk-npm-4.1.2-ba8b67ab80-cb3f3e5949.zip/node_modules/chalk/",\
|
||||
"packageDependencies": [\
|
||||
@ -8524,7 +8512,7 @@ const RAW_RUNTIME_STATE =
|
||||
["@rollup/plugin-alias", "virtual:658502eb4296e93abedc18b6aa9b26978f434f08d98e21ebb0e725354b8bb54b62db9c4a1893e460c694ff7500ff5cbafa4457b0dfd26b5838868666c861e990#npm:5.1.0"],\
|
||||
["@rollup/plugin-json", "virtual:658502eb4296e93abedc18b6aa9b26978f434f08d98e21ebb0e725354b8bb54b62db9c4a1893e460c694ff7500ff5cbafa4457b0dfd26b5838868666c861e990#npm:6.0.1"],\
|
||||
["@rollup/pluginutils", "virtual:658502eb4296e93abedc18b6aa9b26978f434f08d98e21ebb0e725354b8bb54b62db9c4a1893e460c694ff7500ff5cbafa4457b0dfd26b5838868666c861e990#npm:5.1.0"],\
|
||||
["@syuilo/aiscript", "npm:0.11.1"],\
|
||||
["@syuilo/aiscript", "npm:0.16.0"],\
|
||||
["@types/escape-regexp", "npm:0.0.1"],\
|
||||
["@types/glob", "npm:8.1.0"],\
|
||||
["@types/gulp", "npm:4.0.13"],\
|
||||
@ -24627,13 +24615,6 @@ const RAW_RUNTIME_STATE =
|
||||
}]\
|
||||
]],\
|
||||
["uuid", [\
|
||||
["npm:7.0.3", {\
|
||||
"packageLocation": "./.yarn/cache/uuid-npm-7.0.3-2b088bd924-b2a4d30ecd.zip/node_modules/uuid/",\
|
||||
"packageDependencies": [\
|
||||
["uuid", "npm:7.0.3"]\
|
||||
],\
|
||||
"linkType": "HARD"\
|
||||
}],\
|
||||
["npm:8.0.0", {\
|
||||
"packageLocation": "./.yarn/cache/uuid-npm-8.0.0-591e3a2e23-5086c43bbe.zip/node_modules/uuid/",\
|
||||
"packageDependencies": [\
|
||||
@ -24654,6 +24635,13 @@ const RAW_RUNTIME_STATE =
|
||||
["uuid", "npm:9.0.0"]\
|
||||
],\
|
||||
"linkType": "HARD"\
|
||||
}],\
|
||||
["npm:9.0.1", {\
|
||||
"packageLocation": "./.yarn/cache/uuid-npm-9.0.1-39a8442bc6-9d0b6adb72.zip/node_modules/uuid/",\
|
||||
"packageDependencies": [\
|
||||
["uuid", "npm:9.0.1"]\
|
||||
],\
|
||||
"linkType": "HARD"\
|
||||
}]\
|
||||
]],\
|
||||
["v8-compile-cache-lib", [\
|
||||
|
BIN
.yarn/cache/@syuilo-aiscript-npm-0.11.1-451b9d1a3f-4df4bb5a25.zip
(Stored with Git LFS)
vendored
BIN
.yarn/cache/@syuilo-aiscript-npm-0.11.1-451b9d1a3f-4df4bb5a25.zip
(Stored with Git LFS)
vendored
Binary file not shown.
BIN
.yarn/cache/@syuilo-aiscript-npm-0.16.0-078d966ef6-5c77fc596d.zip
(Stored with Git LFS)
vendored
Normal file
BIN
.yarn/cache/@syuilo-aiscript-npm-0.16.0-078d966ef6-5c77fc596d.zip
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
BIN
.yarn/cache/chalk-npm-4.0.0-50e5418ea0-f8ae363f43.zip
(Stored with Git LFS)
vendored
BIN
.yarn/cache/chalk-npm-4.0.0-50e5418ea0-f8ae363f43.zip
(Stored with Git LFS)
vendored
Binary file not shown.
BIN
.yarn/cache/uuid-npm-7.0.3-2b088bd924-b2a4d30ecd.zip
(Stored with Git LFS)
vendored
BIN
.yarn/cache/uuid-npm-7.0.3-2b088bd924-b2a4d30ecd.zip
(Stored with Git LFS)
vendored
Binary file not shown.
BIN
.yarn/cache/uuid-npm-9.0.1-39a8442bc6-9d0b6adb72.zip
(Stored with Git LFS)
vendored
Normal file
BIN
.yarn/cache/uuid-npm-9.0.1-39a8442bc6-9d0b6adb72.zip
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
@ -35,7 +35,6 @@
|
||||
"@peertube/http-signature": "1.7.0",
|
||||
"@redocly/openapi-core": "1.0.0-beta.131",
|
||||
"@sinonjs/fake-timers": "9.1.2",
|
||||
"@syuilo/aiscript": "0.11.1",
|
||||
"adm-zip": "^0.5.10",
|
||||
"ajv": "8.12.0",
|
||||
"archiver": "5.3.1",
|
||||
|
@ -17,7 +17,7 @@
|
||||
"@rollup/plugin-alias": "^5.1.0",
|
||||
"@rollup/plugin-json": "^6.0.1",
|
||||
"@rollup/pluginutils": "^5.1.0",
|
||||
"@syuilo/aiscript": "0.11.1",
|
||||
"@syuilo/aiscript": "0.16.0",
|
||||
"@types/escape-regexp": "0.0.1",
|
||||
"@types/glob": "8.1.0",
|
||||
"@types/gulp": "4.0.13",
|
||||
|
@ -22,7 +22,7 @@ import {
|
||||
onUnmounted,
|
||||
PropType,
|
||||
} from "vue";
|
||||
import { parse } from "@syuilo/aiscript";
|
||||
import { Parser } from "@syuilo/aiscript";
|
||||
import XBlock from "./page.block.vue";
|
||||
import { Hpml } from "@/scripts/hpml/evaluator";
|
||||
import { url } from "@/config";
|
||||
@ -47,12 +47,14 @@ export default defineComponent({
|
||||
enableAiScript: !defaultStore.state.disablePagesScript,
|
||||
});
|
||||
|
||||
const parser = new Parser();
|
||||
|
||||
onMounted(() => {
|
||||
nextTick(() => {
|
||||
if (props.page.script && hpml.aiscript) {
|
||||
let ast;
|
||||
try {
|
||||
ast = parse(props.page.script);
|
||||
ast = parser.parse(props.page.script);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
/*os.alert({
|
||||
|
@ -45,7 +45,7 @@ import "prismjs/components/prism-javascript";
|
||||
import "prismjs/themes/prism-okaidia.css";
|
||||
import { PrismEditor } from "vue-prism-editor";
|
||||
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 MkButton from "@/components/MkButton.vue";
|
||||
import { createAiScriptEnv } from "@/scripts/aiscript/api";
|
||||
@ -57,6 +57,8 @@ import { definePageMetadata } from "@/scripts/page-metadata";
|
||||
const code = ref("");
|
||||
const logs = ref<any[]>([]);
|
||||
|
||||
const parser = new Parser();
|
||||
|
||||
const saved = localStorage.getItem("scratchpad");
|
||||
if (saved) {
|
||||
code.value = saved;
|
||||
@ -68,7 +70,7 @@ watch(code, () => {
|
||||
|
||||
async function run() {
|
||||
logs.value = [];
|
||||
const aiscript = new AiScript(
|
||||
const aiscript = new Interpreter(
|
||||
createAiScriptEnv({
|
||||
storageKey: "scratchpad",
|
||||
token: $i?.token,
|
||||
@ -111,11 +113,11 @@ async function run() {
|
||||
|
||||
let ast;
|
||||
try {
|
||||
ast = parse(code.value);
|
||||
ast = parser.parse(code.value);
|
||||
} catch (error) {
|
||||
os.alert({
|
||||
type: "error",
|
||||
text: "Syntax error :(",
|
||||
text: `Syntax error : ${error}`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -19,8 +19,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { defineAsyncComponent, nextTick, ref } from "vue";
|
||||
import { AiScript, parse } from "@syuilo/aiscript";
|
||||
import { serialize } from "@syuilo/aiscript/built/serializer";
|
||||
import { Interpreter, Parser, utils } from "@syuilo/aiscript";
|
||||
import { v4 as uuid } from "uuid";
|
||||
import FormTextarea from "@/components/form/textarea.vue";
|
||||
import FormButton from "@/components/MkButton.vue";
|
||||
@ -30,10 +29,19 @@ import { ColdDeviceStorage } from "@/store";
|
||||
import { unisonReload } from "@/scripts/unison-reload";
|
||||
import { i18n } from "@/i18n";
|
||||
import { definePageMetadata } from "@/scripts/page-metadata";
|
||||
import { compareVersions } from "compare-versions";
|
||||
|
||||
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(
|
||||
"plugins",
|
||||
ColdDeviceStorage.get("plugins").concat({
|
||||
@ -41,25 +49,46 @@ function installPlugin({ id, meta, ast, token }) {
|
||||
id,
|
||||
active: true,
|
||||
configData: {},
|
||||
token: token,
|
||||
ast: ast,
|
||||
src,
|
||||
token,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const parser = new Parser();
|
||||
|
||||
async function install() {
|
||||
let ast;
|
||||
try {
|
||||
ast = parse(code.value);
|
||||
} catch (err) {
|
||||
if (code.value == null) return;
|
||||
|
||||
const scriptVersion = utils.getLangVersion(code.value);
|
||||
|
||||
if (scriptVersion == null) {
|
||||
os.alert({
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
os.alert({
|
||||
type: "error",
|
||||
@ -82,7 +111,7 @@ async function install() {
|
||||
if (name == null || version == null || author == null) {
|
||||
os.alert({
|
||||
type: "error",
|
||||
text: "Required property not found :(",
|
||||
text: "Required property (name, version, author) not found :(",
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -133,8 +162,8 @@ async function install() {
|
||||
permissions,
|
||||
config,
|
||||
},
|
||||
src: code.value,
|
||||
token,
|
||||
ast: serialize(ast),
|
||||
});
|
||||
|
||||
os.success();
|
||||
|
@ -1,6 +1,4 @@
|
||||
import { AiScript, utils, values } from "@syuilo/aiscript";
|
||||
import { deserialize } from "@syuilo/aiscript/built/serializer";
|
||||
import { jsToVal } from "@syuilo/aiscript/built/interpreter/util";
|
||||
import { Interpreter, Parser, utils, values } from "@syuilo/aiscript";
|
||||
import { createAiScriptEnv } from "@/scripts/aiscript/api";
|
||||
import { inputText } from "@/os";
|
||||
import {
|
||||
@ -11,12 +9,13 @@ import {
|
||||
userActions,
|
||||
} from "@/store";
|
||||
|
||||
const pluginContexts = new Map<string, AiScript>();
|
||||
const parser = new Parser();
|
||||
const pluginContexts = new Map<string, Interpreter>();
|
||||
|
||||
export function install(plugin) {
|
||||
console.info("Plugin installed:", plugin.name, `v${plugin.version}`);
|
||||
|
||||
const aiscript = new AiScript(
|
||||
const aiscript = new Interpreter(
|
||||
createPluginEnv({
|
||||
plugin: plugin,
|
||||
storageKey: `plugins:${plugin.id}`,
|
||||
@ -40,15 +39,15 @@ export function install(plugin) {
|
||||
|
||||
initPlugin({ plugin, aiscript });
|
||||
|
||||
aiscript.exec(deserialize(plugin.ast));
|
||||
aiscript.exec(parser.parse(plugin.src));
|
||||
}
|
||||
|
||||
function createPluginEnv(opts) {
|
||||
const config = new Map();
|
||||
for (const [k, v] of Object.entries(opts.plugin.config || {})) {
|
||||
const config = new Map<string, values.Value>();
|
||||
for (const [k, v] of Object.entries(opts.plugin.config ?? {})) {
|
||||
config.set(
|
||||
k,
|
||||
jsToVal(
|
||||
utils.jsToVal(
|
||||
typeof opts.plugin.configData[k] !== "undefined"
|
||||
? opts.plugin.configData[k]
|
||||
: v.default,
|
||||
@ -108,6 +107,9 @@ function createPluginEnv(opts) {
|
||||
"Plugin:register_note_post_interruptor": values.FN_NATIVE(([handler]) => {
|
||||
registerNotePostInterruptor({ pluginId: opts.plugin.id, handler });
|
||||
}),
|
||||
"Plugin:register_page_view_interruptor": values.FN_NATIVE(([handler]) => {
|
||||
registerPageViewInterruptor({ pluginId: opts.plugin.id, handler });
|
||||
}),
|
||||
"Plugin:open_url": values.FN_NATIVE(([url]) => {
|
||||
window.open(url.value, "_blank");
|
||||
}),
|
||||
@ -123,10 +125,17 @@ function registerPostFormAction({ pluginId, title, handler }) {
|
||||
postFormActions.push({
|
||||
title,
|
||||
handler: (form, update) => {
|
||||
pluginContexts.get(pluginId).execFn(handler, [
|
||||
const pluginContext = pluginContexts.get(pluginId);
|
||||
if (!pluginContext) {
|
||||
return;
|
||||
}
|
||||
pluginContext.execFn(handler, [
|
||||
utils.jsToVal(form),
|
||||
values.FN_NATIVE(([key, value]) => {
|
||||
update(key.value, value.value);
|
||||
if (!key || !value) {
|
||||
return;
|
||||
}
|
||||
update(utils.valToJs(key), utils.valToJs(value));
|
||||
}),
|
||||
]);
|
||||
},
|
||||
@ -137,7 +146,11 @@ function registerUserAction({ pluginId, title, handler }) {
|
||||
userActions.push({
|
||||
title,
|
||||
handler: (user) => {
|
||||
pluginContexts.get(pluginId).execFn(handler, [utils.jsToVal(user)]);
|
||||
const pluginContext = pluginContexts.get(pluginId);
|
||||
if (!pluginContext) {
|
||||
return;
|
||||
}
|
||||
pluginContext.execFn(handler, [utils.jsToVal(user)]);
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -146,7 +159,11 @@ function registerNoteAction({ pluginId, title, handler }) {
|
||||
noteActions.push({
|
||||
title,
|
||||
handler: (note) => {
|
||||
pluginContexts.get(pluginId).execFn(handler, [utils.jsToVal(note)]);
|
||||
const pluginContext = pluginContexts.get(pluginId);
|
||||
if (!pluginContext) {
|
||||
return;
|
||||
}
|
||||
pluginContext.execFn(handler, [utils.jsToVal(user)]);
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -154,10 +171,12 @@ function registerNoteAction({ pluginId, title, handler }) {
|
||||
function registerNoteViewInterruptor({ pluginId, handler }) {
|
||||
noteViewInterruptors.push({
|
||||
handler: async (note) => {
|
||||
const pluginContext = pluginContexts.get(pluginId);
|
||||
if (!pluginContext) {
|
||||
return;
|
||||
}
|
||||
return utils.valToJs(
|
||||
await pluginContexts
|
||||
.get(pluginId)
|
||||
.execFn(handler, [utils.jsToVal(note)]),
|
||||
await pluginContext.execFn(handler, [utils.jsToVal(note)]),
|
||||
);
|
||||
},
|
||||
});
|
||||
@ -166,10 +185,26 @@ function registerNoteViewInterruptor({ pluginId, handler }) {
|
||||
function registerNotePostInterruptor({ pluginId, handler }) {
|
||||
notePostInterruptors.push({
|
||||
handler: async (note) => {
|
||||
const pluginContext = pluginContexts.get(pluginId);
|
||||
if (!pluginContext) {
|
||||
return;
|
||||
}
|
||||
return utils.valToJs(
|
||||
await pluginContexts
|
||||
.get(pluginId)
|
||||
.execFn(handler, [utils.jsToVal(note)]),
|
||||
await pluginContext.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,7 +1,7 @@
|
||||
import autobind from "autobind-decorator";
|
||||
import { PageVar, envVarsDef, Fn, HpmlScope, HpmlError } from ".";
|
||||
import { version } from "@/config";
|
||||
import { AiScript, utils, values } from "@syuilo/aiscript";
|
||||
import { Interpreter, utils, values } from "@syuilo/aiscript";
|
||||
import { createAiScriptEnv } from "../aiscript/api";
|
||||
import { collectPageVars } from "../collect-page-vars";
|
||||
import { initHpmlLib, initAiLib } from "./lib";
|
||||
@ -16,7 +16,7 @@ export class Hpml {
|
||||
private variables: Variable[];
|
||||
private pageVars: PageVar[];
|
||||
private envVars: Record<keyof typeof envVarsDef, any>;
|
||||
public aiscript?: AiScript;
|
||||
public aiscript?: Interpreter;
|
||||
public pageVarUpdatedCallback?: values.VFn;
|
||||
public canvases: Record<string, HTMLCanvasElement> = {};
|
||||
public vars: Ref<Record<string, any>> = ref({});
|
||||
@ -37,7 +37,7 @@ export class Hpml {
|
||||
|
||||
if (this.opts.enableAiScript) {
|
||||
this.aiscript = markRaw(
|
||||
new AiScript(
|
||||
new Interpreter(
|
||||
{
|
||||
...createAiScriptEnv({
|
||||
storageKey: `pages:${this.page.id}`,
|
||||
|
@ -27,13 +27,13 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { AiScript, parse, utils } from "@syuilo/aiscript";
|
||||
import type { Widget, WidgetComponentExpose } from "./widget";
|
||||
import { Interpreter, Parser, utils } from "@syuilo/aiscript";
|
||||
import {
|
||||
useWidgetPropsManager,
|
||||
WidgetComponentEmits,
|
||||
WidgetComponentProps,
|
||||
useWidgetPropsManager,
|
||||
} from "./widget";
|
||||
import type { WidgetComponentExpose } from "./widget";
|
||||
import type { GetFormResultType } from "@/scripts/form";
|
||||
import * as os from "@/os";
|
||||
import MkContainer from "@/components/MkContainer.vue";
|
||||
@ -58,11 +58,8 @@ const widgetPropsDef = {
|
||||
|
||||
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
||||
|
||||
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
||||
// const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
||||
// const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
||||
const props = defineProps<{ widget?: Widget<WidgetProps> }>();
|
||||
const emit = defineEmits<{ (ev: "updateProps", props: WidgetProps) }>();
|
||||
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
||||
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
||||
|
||||
const { widgetProps, configure } = useWidgetPropsManager(
|
||||
name,
|
||||
@ -79,9 +76,11 @@ const logs = ref<
|
||||
}[]
|
||||
>([]);
|
||||
|
||||
const parser = new Parser();
|
||||
|
||||
const run = async () => {
|
||||
logs.value = [];
|
||||
const aiscript = new AiScript(
|
||||
const aiscript = new Interpreter(
|
||||
createAiScriptEnv({
|
||||
storageKey: "widget",
|
||||
token: $i?.token,
|
||||
@ -124,11 +123,11 @@ const run = async () => {
|
||||
|
||||
let ast;
|
||||
try {
|
||||
ast = parse(widgetProps.script);
|
||||
ast = parser.parse(widgetProps.script);
|
||||
} catch (err) {
|
||||
os.alert({
|
||||
type: "error",
|
||||
text: "Syntax error :(",
|
||||
text: `Syntax error : ${err}`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -137,7 +136,7 @@ const run = async () => {
|
||||
} catch (err) {
|
||||
os.alert({
|
||||
type: "error",
|
||||
text: err,
|
||||
text: String(err),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -8,16 +8,16 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { AiScript, parse, utils } from "@syuilo/aiscript";
|
||||
import type { Widget, WidgetComponentExpose } from "./widget";
|
||||
import { Interpreter, Parser } from "@syuilo/aiscript";
|
||||
import { createAiScriptEnv } from "@/scripts/aiscript/api";
|
||||
import {
|
||||
useWidgetPropsManager,
|
||||
WidgetComponentEmits,
|
||||
WidgetComponentProps,
|
||||
useWidgetPropsManager,
|
||||
} from "./widget";
|
||||
import type { WidgetComponentExpose } from "./widget";
|
||||
import type { GetFormResultType } from "@/scripts/form";
|
||||
import * as os from "@/os";
|
||||
import { createAiScriptEnv } from "@/scripts/aiscript/api";
|
||||
import { $i } from "@/account";
|
||||
import MkButton from "@/components/MkButton.vue";
|
||||
|
||||
@ -41,11 +41,8 @@ const widgetPropsDef = {
|
||||
|
||||
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
||||
|
||||
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
||||
// const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
||||
// const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
||||
const props = defineProps<{ widget?: Widget<WidgetProps> }>();
|
||||
const emit = defineEmits<{ (ev: "updateProps", props: WidgetProps) }>();
|
||||
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
||||
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
||||
|
||||
const { widgetProps, configure } = useWidgetPropsManager(
|
||||
name,
|
||||
@ -54,8 +51,10 @@ const { widgetProps, configure } = useWidgetPropsManager(
|
||||
emit,
|
||||
);
|
||||
|
||||
const parser = new Parser();
|
||||
|
||||
const run = async () => {
|
||||
const aiscript = new AiScript(
|
||||
const aiscript = new Interpreter(
|
||||
createAiScriptEnv({
|
||||
storageKey: "widget",
|
||||
token: $i?.token,
|
||||
@ -81,11 +80,11 @@ const run = async () => {
|
||||
|
||||
let ast;
|
||||
try {
|
||||
ast = parse(widgetProps.script);
|
||||
ast = parser.parse(widgetProps.script);
|
||||
} catch (err) {
|
||||
os.alert({
|
||||
type: "error",
|
||||
text: "Syntax error :(",
|
||||
text: `Syntax error: ${err}`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -94,7 +93,7 @@ const run = async () => {
|
||||
} catch (err) {
|
||||
os.alert({
|
||||
type: "error",
|
||||
text: err,
|
||||
text: String(err),
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -105,8 +104,3 @@ defineExpose<WidgetComponentExpose>({
|
||||
id: props.widget ? props.widget.id : null,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.mkw-button {
|
||||
}
|
||||
</style>
|
||||
|
43
yarn.lock
43
yarn.lock
@ -2691,16 +2691,14 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@syuilo/aiscript@npm:0.11.1":
|
||||
version: 0.11.1
|
||||
resolution: "@syuilo/aiscript@npm:0.11.1"
|
||||
"@syuilo/aiscript@npm:0.16.0":
|
||||
version: 0.16.0
|
||||
resolution: "@syuilo/aiscript@npm:0.16.0"
|
||||
dependencies:
|
||||
autobind-decorator: "npm:2.4.0"
|
||||
chalk: "npm:4.0.0"
|
||||
seedrandom: "npm:3.0.5"
|
||||
stringz: "npm:2.1.0"
|
||||
uuid: "npm:7.0.3"
|
||||
checksum: 10/4df4bb5a25e8334dbfecac5dfa047b7637821d31daa1ada6fb14d2f13e94be4655c3845f6f61643be327b682608456d22fc5557c23c6c68bc1cfb7c76b6970d6
|
||||
uuid: "npm:9.0.1"
|
||||
checksum: 10/5c77fc596dcff0e7ac30ba33f2550430dc1d69bd33075811d7822efb6102bae4169f455c867eac5821bee88993941bc6003bd981ad64885b2e643cb4bc260d4a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -5463,7 +5461,6 @@ __metadata:
|
||||
"@swc/cli": "npm:^0.1.62"
|
||||
"@swc/core": "npm:^1.3.68"
|
||||
"@swc/core-android-arm64": "npm:1.3.11"
|
||||
"@syuilo/aiscript": "npm:0.11.1"
|
||||
"@types/adm-zip": "npm:^0.5.0"
|
||||
"@types/async-lock": "npm:1.4.0"
|
||||
"@types/bcryptjs": "npm:2.4.2"
|
||||
@ -6339,16 +6336,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"chalk@npm:4.0.0":
|
||||
version: 4.0.0
|
||||
resolution: "chalk@npm:4.0.0"
|
||||
dependencies:
|
||||
ansi-styles: "npm:^4.1.0"
|
||||
supports-color: "npm:^7.1.0"
|
||||
checksum: 10/f8ae363f43826f0eea96f94dbf5c544ec3cda1422ec998040b82381702db54e2a056a724445f6295842790bb7a3cb352cf83c704a4fdfee2bfcd2a74ce7fea13
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"chalk@npm:4.1.2, chalk@npm:^4.0.0, chalk@npm:^4.0.2, chalk@npm:^4.1.0, chalk@npm:^4.1.2":
|
||||
version: 4.1.2
|
||||
resolution: "chalk@npm:4.1.2"
|
||||
@ -6673,7 +6660,7 @@ __metadata:
|
||||
"@rollup/plugin-alias": "npm:^5.1.0"
|
||||
"@rollup/plugin-json": "npm:^6.0.1"
|
||||
"@rollup/pluginutils": "npm:^5.1.0"
|
||||
"@syuilo/aiscript": "npm:0.11.1"
|
||||
"@syuilo/aiscript": "npm:0.16.0"
|
||||
"@types/escape-regexp": "npm:0.0.1"
|
||||
"@types/glob": "npm:8.1.0"
|
||||
"@types/gulp": "npm:4.0.13"
|
||||
@ -20813,15 +20800,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"uuid@npm:7.0.3":
|
||||
version: 7.0.3
|
||||
resolution: "uuid@npm:7.0.3"
|
||||
bin:
|
||||
uuid: dist/bin/uuid
|
||||
checksum: 10/b2a4d30ecd6581015175487426558aafd7f7b4013a2e30802c128cc28cad9abe46ecd36c02f7fbcde7908fd4672334818d56a441c0871963d6bd89d911bef2ea
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"uuid@npm:8.0.0":
|
||||
version: 8.0.0
|
||||
resolution: "uuid@npm:8.0.0"
|
||||
@ -20840,6 +20818,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"uuid@npm:9.0.1":
|
||||
version: 9.0.1
|
||||
resolution: "uuid@npm:9.0.1"
|
||||
bin:
|
||||
uuid: dist/bin/uuid
|
||||
checksum: 10/9d0b6adb72b736e36f2b1b53da0d559125ba3e39d913b6072f6f033e0c87835b414f0836b45bcfaf2bdf698f92297fea1c3cc19b0b258bc182c9c43cc0fab9f2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"uuid@npm:^8.3.0, uuid@npm:^8.3.2":
|
||||
version: 8.3.2
|
||||
resolution: "uuid@npm:8.3.2"
|
||||
|
Loading…
Reference in New Issue
Block a user