def act.reply

ezmcp@0.1.0.0 · src/io.bend:20

import ezmcp@0.1.0.0/src/io.bend as Io
import Base
import emerging-ezjson@1.2.0.0/src/value.bend as Value
import ezmcp@0.1.0.0/src/rpc.bend as Rpc
import ezmcp@0.1.0.0/src/server.bend as Server

20# one element of a batch, under revision `rev`: its reply, after running its
21# tool when it is a tool call; none for a notification or a response
22def act.reply(
23  ~C: Data,
24  ~run: C -> String -> Value.Json -> IO(Rpc.Out),
25  +ctx: C,
26  +rev: String,
27  act: Server.Act
28) -> IO(Maybe<&2, Value.Json>):
29  match act:
30    case Server.Quiet{}:
31      IO.pure(Maybe<&2, Value.Json>, None{})
32    case Server.Send{reply}:
33      IO.pure(Maybe<&2, Value.Json>, Some{reply})
34    case Server.Fault{reply}:
35      IO.pure(Maybe<&2, Value.Json>, Some{reply})
36    case Server.Run{id, name, args}:
37      IO.bind(Rpc.Out, Maybe<&2, Value.Json>, run(ctx, name, args),
38        out => IO.pure(Maybe<&2, Value.Json>, Some{Server.ran(rev, id, out)}))
39    case Server.Batch{acts}:
40      IO.pure(Maybe<&2, Value.Json>, None{})

Uses (9)

Used by (1)