Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

DispatchModeLimit.ts

41 lines1.4 KB

1import type { ProviderInteractionMode, RuntimeMode, ThreadId } from "@t3tools/contracts";
2import * as Context from "effect/Context";
3import type * as Ref from "effect/Ref";
4​
5export interface DispatchModes {
6 readonly runtimeMode: RuntimeMode;
7 readonly interactionMode: ProviderInteractionMode;
8}
9​
10export interface DispatchModeRefusal extends DispatchModes {
11 readonly threadId: ThreadId;
12 readonly mode: "runtime" | "interaction";
14​
15/** Recheck target modes under the command lock; the user can raise them after preflight. */
16export interface DispatchModeLimitValue extends DispatchModes {
17 readonly refused?: Ref.Ref<DispatchModeRefusal | undefined>;
19​
20export const DispatchModeLimit = Context.Reference<DispatchModeLimitValue | undefined>(
21 "t3/orchestration-v2/DispatchModeLimit",
22 { defaultValue: () => undefined },
23);
24​
25const runtimeModeRank: Record<RuntimeMode, number> = {
26 "approval-required": 0,
27 "auto-accept-edits": 1,
28 auto: 2,
29 "full-access": 3,
30};
31const interactionModeRank: Record<ProviderInteractionMode, number> = { plan: 0, default: 1 };
32​
33export const exceededDispatchModeLimit = (
34 limit: DispatchModes,
35 modes: DispatchModes,
36): "runtime" | "interaction" | undefined =>
37 runtimeModeRank[modes.runtimeMode] > runtimeModeRank[limit.runtimeMode]
38 ? "runtime"
39 : interactionModeRank[modes.interactionMode] > interactionModeRank[limit.interactionMode]
40 ? "interaction"
41 : undefined;