The ternary branches produced structurally identical activity objects. Use destructuring + spread to build the activity once, preserving discriminated-union type safety without duplicating the object literal.
Unified · Split
| @@ -161,33 +161,20 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) => · 160 unmodified lines | ||
| 161 | 161 | readonly tone: "error"; |
| 162 | 162 | } |
| 163 | 163 | ), |
| 164 | − ) => | |
| 165 | − orchestrationEngine.dispatch({ | |
| 164 | + ) => { | |
| 165 | + const { threadId, ...rest } = input; | |
| 166 | + return orchestrationEngine.dispatch({ | |
| 166 | 167 | type: "thread.activity.append", |
| 167 | 168 | commandId: serverCommandId("setup-script-activity"), |
| 168 | − threadId: input.threadId, | |
| 169 | − activity: | |
| 170 | − input.kind === "setup-script.failed" | |
| 171 | − ? { | |
| 172 | − id: EventId.make(crypto.randomUUID()), | |
| 173 | − tone: input.tone, | |
| 174 | − kind: input.kind, | |
| 175 | − summary: input.summary, | |
| 176 | − payload: input.payload, | |
| 177 | − turnId: null, | |
| 178 | − createdAt: input.createdAt, | |
| 179 | − } | |
| 180 | − : { | |
| 181 | − id: EventId.make(crypto.randomUUID()), | |
| 182 | − tone: input.tone, | |
| 183 | − kind: input.kind, | |
| 184 | − summary: input.summary, | |
| 185 | − payload: input.payload, | |
| 186 | − turnId: null, | |
| 187 | − createdAt: input.createdAt, | |
| 188 | − }, | |
| 169 | + threadId, | |
| 170 | + activity: { | |
| 171 | + id: EventId.make(crypto.randomUUID()), | |
| 172 | + ...rest, | |
| 173 | + turnId: null, | |
| 174 | + }, | |
| 189 | 175 | createdAt: input.createdAt, |
| 190 | 176 | }); |
| 177 | + }; | |
| 191 | 178 | |
| 192 | 179 | const toDispatchCommandError = (cause: unknown, fallbackMessage: string) => |
| 193 | 180 | Schema.is(OrchestrationDispatchCommandError)(cause) |