chore: update api / test

This commit is contained in:
2026-04-06 15:02:31 +08:00
parent 111d2e69eb
commit fe3bef0a01
4 changed files with 7 additions and 25 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ export class GameHost<TState extends Record<string, unknown>, TResult=unknown> {
this._activePromptPlayer.value = null;
}
onInput(input: string): string | null {
tryInput(input: string): string | null {
if (this._isDisposed) {
return 'GameHost is disposed';
}
-16
View File
@@ -11,7 +11,6 @@ import type {
import { parseCommand } from './command-parse';
import { applyCommandSchema } from './command-validate';
import { parseCommandSchema } from './schema-parse';
import {AsyncQueue} from "@/utils/async-queue";
type CanRunParsed = {
runParsed<T=unknown>(command: Command): Promise<CommandResult<T>>,
@@ -89,7 +88,6 @@ type PromptEndListener = () => void;
export type CommandRunnerContextExport<TContext> = CommandRunnerContext<TContext> & {
registry: CommandRegistry<TContext>;
promptQueue: AsyncQueue<PromptEvent>;
_activePrompt: PromptEvent | null;
_tryCommit: (commandOrInput: Command | string) => string | null;
_cancel: (reason?: string) => void;
@@ -196,26 +194,12 @@ export function createCommandRunnerContext<TContext>(
_tryCommit: tryCommit,
_cancel: cancel,
_pendingInput: null,
promptQueue: null!
};
Object.defineProperty(runnerCtx, '_activePrompt', {
get: () => activePrompt,
});
let promptQueue: AsyncQueue<PromptEvent>;
Object.defineProperty(runnerCtx, 'promptQueue', {
get(){
if (!promptQueue) {
promptQueue = new AsyncQueue();
promptListeners.add(async (event) => {
promptQueue.push(event);
});
}
return promptQueue;
}
});
return runnerCtx;
}
-2
View File
@@ -1,6 +1,4 @@
import type { Command, CommandSchema } from './types';
import { parseCommand } from './command-parse';
import { applyCommandSchema } from './command-validate';
export type PromptEvent = {
schema: CommandSchema;