MCPcopy Create free account
hub / github.com/Effect-TS/effect / handlerWith

Function handlerWith

packages/effect/test/chat/ChatInteraction.test.ts:16–27  ·  view source on GitHub ↗
(options: {
  readonly click?: Effect.Effect<ChatInteraction.ClickReply>
  readonly submit?: Effect.Effect<ChatInteraction.SubmitReply>
  readonly command?: (command: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply
  readonly refused?: (error: ChatError.ChatError) => Effect.Effect<void>
})

Source from the content-addressed store, hash-verified

14 ChatInteraction.CommandInvoked.make({ id, text, thread, userId: "u1", raw: { id: "i1" } })
15
16const handlerWith = (options: {
17 readonly click?: Effect.Effect<ChatInteraction.ClickReply>
18 readonly submit?: Effect.Effect<ChatInteraction.SubmitReply>
19 readonly command?: (command: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply
20 readonly refused?: (error: ChatError.ChatError) => Effect.Effect<void>
21}) =>
22 ChatInteraction.Handler.of({
23 click: () => options.click ?? Effect.succeed(ChatInteraction.ack),
24 submit: () => options.submit ?? Effect.succeed(ChatInteraction.close),
25 command: (command) => Effect.succeed(options.command?.(command) ?? ChatInteraction.ack),
26 refused: (_, error) => options.refused?.(error) ?? Effect.void
27 })
28
29describe("ChatInteraction", () => {
30 it("encodes a value by its schema: a string-only schema as it is, anything else as JSON", () => {

Callers 1

Calls 3

ofMethod · 0.65
commandMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected