MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / reducer

Function reducer

packages/plugins/mcp/src/react/AddMcpIntegration.tsx:114–160  ·  view source on GitHub ↗
(state: State, action: Action)

Source from the content-addressed store, hash-verified

112const init: State = { step: "url", url: "" };
113
114function reducer(state: State, action: Action): State {
115 return Match.value(action).pipe(
116 Match.discriminator("type")("set-url", (a): State => ({ step: "url", url: a.url })),
117 Match.discriminator("type")(
118 "probe-start",
119 (): State => ({
120 step: "probing",
121 url: state.url,
122 probe: "probe" in state ? state.probe : null,
123 }),
124 ),
125 Match.discriminator("type")(
126 "probe-ok",
127 (a): State => ({ step: "probed", url: state.url, probe: a.probe }),
128 ),
129 Match.discriminator("type")(
130 "probe-fail",
131 (a): State => ({
132 step: "error",
133 url: state.url,
134 probe: null,
135 error: a.error,
136 }),
137 ),
138 Match.discriminator("type")("add-start", (): State => {
139 const probe = "probe" in state ? state.probe : null;
140 if (!probe) return state;
141 return { step: "adding", url: state.url, probe };
142 }),
143 Match.discriminator("type")("add-fail", (a): State => {
144 if (state.step !== "adding") return state;
145 return {
146 step: "error",
147 url: state.url,
148 probe: state.probe,
149 error: a.error,
150 };
151 }),
152 Match.discriminator("type")("retry", (): State => {
153 if (state.step !== "error") return state;
154 return state.probe
155 ? { step: "probed", url: state.url, probe: state.probe }
156 : { step: "url", url: state.url };
157 }),
158 Match.exhaustive,
159 );
160}
161
162// ---------------------------------------------------------------------------
163// Component

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected