Skip to content

Commit 91ca8d6

Browse files
committed
refactor(httpapi): avoid redundant sync decodes
1 parent 8c3fa19 commit 91ca8d6

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

packages/opencode/src/server/routes/instance/httpapi/mcp.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ export const mcpHandlers = Layer.unwrap(
139139
})
140140

141141
const add = Effect.fn("McpHttpApi.add")(function* (ctx: { payload: typeof AddPayload.Type }) {
142-
const payload = Schema.decodeUnknownSync(AddPayload)(ctx.payload)
143-
const result = (yield* mcp.add(payload.name, payload.config)).status
144-
return Schema.decodeUnknownSync(StatusMap)("status" in result ? { [payload.name]: result } : result)
142+
const result = (yield* mcp.add(ctx.payload.name, ctx.payload.config)).status
143+
return yield* Schema.decodeUnknownEffect(StatusMap)("status" in result ? { [ctx.payload.name]: result } : result).pipe(
144+
Effect.mapError(() => new HttpApiError.BadRequest({})),
145+
)
145146
})
146147

147148
const authStart = Effect.fn("McpHttpApi.authStart")(function* (ctx: { params: { name: string } }) {

packages/opencode/src/server/routes/instance/httpapi/sync.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ export const syncHandlers = Layer.unwrap(
9696
})
9797

9898
const replay = Effect.fn("SyncHttpApi.replay")(function* (ctx: { payload: typeof ReplayPayload.Type }) {
99-
const payload = Schema.decodeUnknownSync(ReplayPayload)(ctx.payload)
100-
const events: SyncEvent.SerializedEvent[] = payload.events.map((event) => ({
99+
const events: SyncEvent.SerializedEvent[] = ctx.payload.events.map((event) => ({
101100
id: event.id,
102101
aggregateID: event.aggregateID,
103102
seq: event.seq,

packages/opencode/src/server/routes/instance/httpapi/workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export const workspaceHandlers = Layer.unwrap(
123123
return yield* Effect.promise(() =>
124124
Instance.restore(instance, () =>
125125
Workspace.create({
126-
...Schema.decodeUnknownSync(CreatePayload)(ctx.payload),
126+
...ctx.payload,
127127
projectID: instance.project.id,
128128
}),
129129
),

0 commit comments

Comments
 (0)