mirror of
https://github.com/morluto/rea.git
synced 2026-11-04 22:06:10 +00:00
- A query parameter accepts a number or boolean, which serving sends as its JSON text, as agents send page sizes and flags. - A sequence may start at the value its first create took above every value its type held (Vikunja's per-project task index), and a later create's composed, template or started-sequence rule is adopted when it also spells the first create's value. - A made-object rule explains an object the application makes with each created entity: members the request stamped, members holding the entity's own id, and counts one past the held objects' values. - A create's answer names the id of the one object a one-element array member holds, so bulk creates link to their type. - The skill reads each listed object by id before writing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
2.1 KiB
TypeScript
60 lines
2.1 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 { answerBulk } from "./environmentStateBulkAnswer.js";
|
|
import type { EnvironmentStateStore } from "./environmentStateStore.js";
|
|
import { answerWrite } from "./environmentStateWriteAnswer.js";
|
|
import { pinnedRequest } from "./environmentStateWriteQuery.js";
|
|
import { withQueryText } from "./environmentTools.js";
|
|
|
|
/** How a served environment answers one tool call. */
|
|
export type EnvironmentToolAnswer = (
|
|
tool: EnvironmentManifestTool,
|
|
args: ReplayArguments,
|
|
observedQuery?: string | null,
|
|
) => 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, observedQuery) =>
|
|
replayEnvironmentTool(
|
|
source,
|
|
tool,
|
|
withQueryText(tool, args),
|
|
observedQuery,
|
|
)
|
|
: (tool, given, observedQuery) => {
|
|
const args = withQueryText(tool, given);
|
|
const plan = store.state.writes.get(tool.name);
|
|
if (plan?.served !== true)
|
|
return answerFromState({ source, store }, tool, args, observedQuery);
|
|
const request = pinnedRequest(
|
|
{ source, store },
|
|
{
|
|
tool,
|
|
plan,
|
|
args,
|
|
...(observedQuery === undefined ? {} : { observedQuery }),
|
|
},
|
|
);
|
|
if (!request.ok) return request;
|
|
const bulk = plan.address !== undefined && plan.address.by !== "action";
|
|
return (bulk ? answerBulk : answerWrite)(
|
|
{ source, store },
|
|
request.value,
|
|
);
|
|
};
|