refactor(frontend/aiscript): AiScriptバージョン取得・判定ロジックを統一 (#16845)

* refactor(frontend): AiScriptバージョン取得・判定ロジックを統一

* fix
This commit is contained in:
かっこかり 2025-11-25 07:23:21 +09:00 committed by GitHub
parent 4edd6a68e6
commit 91dafc26a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 10 deletions

View File

@ -6,13 +6,6 @@
import { errors, utils } from '@syuilo/aiscript';
import type { values } from '@syuilo/aiscript';
const extractVersionIdentifier = /^\/\/\/\s*@\s*(\d+)\.(\d+)\.\d+$/m;
export function getAiScriptVersion(script: string): { major: number; minor: number } | undefined {
const match = extractVersionIdentifier.exec(script);
return match ? { major: Number(match[1]), minor: Number(match[2]) } : undefined;
}
export function assertStringAndIsIn<A extends readonly string[]>(value: values.Value | undefined, expects: A): asserts value is values.VStr & { value: A[number] } {
utils.assertString(value);
const str = value.value;

View File

@ -63,6 +63,8 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup>
import { computed, onDeactivated, onUnmounted, ref, watch, shallowRef, defineAsyncComponent } from 'vue';
import * as Misskey from 'misskey-js';
import { utils } from '@syuilo/aiscript';
import { compareVersions } from 'compare-versions';
import { url } from '@@/js/config.js';
import type { Ref } from 'vue';
import type { AsUiComponent, AsUiRoot } from '@/aiscript/ui.js';
@ -74,7 +76,6 @@ import { misskeyApi } from '@/utility/misskey-api.js';
import { i18n } from '@/i18n.js';
import { definePage } from '@/page.js';
import MkAsUi from '@/components/MkAsUi.vue';
import { getAiScriptVersion } from '@/aiscript/common.js';
import { registerAsUiLib } from '@/aiscript/ui.js';
import { aiScriptReadline, createAiScriptEnv } from '@/aiscript/api.js';
import MkFolder from '@/components/MkFolder.vue';
@ -191,12 +192,21 @@ function start() {
run();
}
function getIsLegacy(version: string | null): boolean {
if (version == null) return false;
try {
return compareVersions(version, '1.0.0') < 0;
} catch {
return false;
}
}
async function run() {
if (aiscript.value) aiscript.value.abort();
if (!flash.value) return;
const version = getAiScriptVersion(flash.value.script);
const isLegacy = version ? version.major < 1 : false;
const version = utils.getLangVersion(flash.value.script);
const isLegacy = version != null && getIsLegacy(version);
const { Interpreter, Parser, values } = isLegacy ? (await import('@syuilo/aiscript-0-19-0') as any) : await import('@syuilo/aiscript');