mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
Serve write tools whose later reads confirm the effect, and keep main's state-file ownership and part-wise reply measurement. Squashed rebase of #5600 onto the rebased #5352 tip.
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
|
import type { Result } from "../../domain/result.js";
|
|
import {
|
|
replayEnvironmentTool,
|
|
type ReplayArguments,
|
|
type ReplayResult,
|
|
} from "./environmentReplay.js";
|
|
import type {
|
|
EnvironmentManifestTool,
|
|
EnvironmentSource,
|
|
} from "./environmentSource.js";
|
|
import { answerFromState } from "./environmentStateAnswer.js";
|
|
import type { EnvironmentStateStore } from "./environmentStateStore.js";
|
|
import { answerWrite } from "./environmentStateWriteAnswer.js";
|
|
|
|
/** How a served environment answers one tool call. */
|
|
export type EnvironmentToolAnswer = (
|
|
tool: EnvironmentManifestTool,
|
|
args: ReplayArguments,
|
|
) => Result<ReplayResult, AnalysisError>;
|
|
|
|
/** The answer a served environment gives: replay without a state store; with one, a served write applies to the live state and a read answers from it. */
|
|
export const environmentToolAnswer = (
|
|
source: EnvironmentSource,
|
|
store: EnvironmentStateStore | undefined,
|
|
): EnvironmentToolAnswer =>
|
|
store === undefined
|
|
? (tool, args) => replayEnvironmentTool(source, tool, args)
|
|
: (tool, args) => {
|
|
const plan = store.state.writes.get(tool.name);
|
|
return plan?.served === true
|
|
? answerWrite({ source, store }, { tool, plan, args })
|
|
: answerFromState({ source, store }, tool, args);
|
|
};
|