main.bend
ezmcp@0.1.0.0 · 376 lines · 43 definitions
1
2
3
4
5
6
7
8
9
10
11import Base
12import emerging-ezjson@1.2.0.0/src/value.bend as Value
13import emerging-ezhttp@0.21.0.0/src/http.bend as Http
14import ezmcp@0.1.0.0/src/rpc.bend as Rpc
15import ezmcp@0.1.0.0/src/server.bend as Server
16import ezmcp@0.1.0.0/src/web.bend as Web
17import ezmcp@0.1.0.0/src/client.bend as Client
18import ezmcp@0.1.0.0/src/io.bend as Io
19import ezmcp@0.1.0.0/src/openapi.bend as Openapi
20
21
22
23
24
25def tool(name: String, description: String, input: Value.Json) -> Server.Tool:
26 Server.Tool{name, description, input}
27
28
29
30def server(
31 name: String,
32 version: String,
33 instructions: String,
34 tools: List<&2, Server.Tool>
35) -> Server.Server:
36 Server.Server{name, version, instructions, tools}
37
38
39def latest() -> String:
40 Server.latest()
41
42
43def revisions() -> List<&2, String>:
44 Server.revisions()
45
46
47
48
49
50
51def step(srv: Server.Server, rev: String, text: String) -> Server.Act:
52 Server.step(srv, rev, text)
53
54
55
56
57def turn(srv: Server.Server, rev: String, text: String) -> Server.Turn:
58 Server.turn(srv, rev, text)
59
60
61
62def ran(rev: String, id: Value.Json, out: Rpc.Out) -> Value.Json:
63 Server.ran(rev, id, out)
64
65
66
67def batch.reply(replies: List<&2, Maybe<&2, Value.Json>>) -> Maybe<&2, Value.Json>:
68 Server.batch.reply(replies)
69
70
71
72
73
74def ok(result: Value.Json) -> Rpc.Out:
75 Rpc.Ok{result}
76
77
78
79
80def refuse(code: Rpc.Code, message: String) -> Rpc.Out:
81 Rpc.Err{code, message}
82
83
84
85def refuse.params(message: String) -> Rpc.Out:
86 Rpc.Err{Rpc.InvalidParams{}, message}
87
88
89def refuse.internal(message: String) -> Rpc.Out:
90 Rpc.Err{Rpc.InternalError{}, message}
91
92
93
94
95def text(text2: String) -> Value.Json:
96 Server.text(text2)
97
98
99
100def result(blocks: List<&2, Value.Json>, is_error: Bool) -> Value.Json:
101 Server.result(blocks, is_error)
102
103
104def result.text(text: String) -> Value.Json:
105 Server.result([Server.text(text)], False{})
106
107
108def result.error(text: String) -> Value.Json:
109 Server.result([Server.text(text)], True{})
110
111
112
113def result.json(val: Value.Json) -> Value.Json:
114 Server.structured(val, False{})
115
116
117
118
119
120def http.decide(
121 srv: Server.Server,
122 path: String,
123 origins: List<&2, String>,
124 req: Http.Request
125) -> Web.Web:
126 Web.decide(srv, path, origins, req)
127
128
129
130def http.handle(
131 ~run: String -> Value.Json -> IO(Rpc.Out),
132 ~srv: Server.Server,
133 ~path: String,
134 ~origins: List<&2, String>,
135 req: Http.Request
136) -> IO(Http.Reply):
137 Io.http.handle(run, srv, path, origins, req)
138
139
140
141
142def http.serve(
143 ~run: String -> Value.Json -> IO(Rpc.Out),
144 ~srv: Server.Server,
145 ~path: String,
146 ~origins: List<&2, String>,
147 host: String,
148 port: U32,
149 limit: U32
150) -> IO(Unit):
151 Io.http.serve(run, srv, path, origins, host, port, limit)
152
153
154
155@unsafe def http.serve_forever(
156 ~run: String -> Value.Json -> IO(Rpc.Out),
157 ~srv: Server.Server,
158 ~path: String,
159 ~origins: List<&2, String>,
160 host: String,
161 port: U32
162) -> IO(Unit):
163 Io.http.serve_forever(run, srv, path, origins, host, port)
164
165
166
167
168
169
170
171
172
173def http.handle_with(
174 ~C: Data,
175 ~run: C -> String -> Value.Json -> IO(Rpc.Out),
176 ~srv: Server.Server,
177 ~path: String,
178 ~origins: List<&2, String>,
179 +ctx: C,
180 req: Http.Request
181) -> IO(Http.Reply):
182 Io.http.handle_with(C, run, srv, path, origins, ctx, req)
183
184
185
186
187def http.serve_with(
188 ~C: Data,
189 ~run: C -> String -> Value.Json -> IO(Rpc.Out),
190 ~srv: Server.Server,
191 ~path: String,
192 ~origins: List<&2, String>,
193 +ctx: C,
194 host: String,
195 port: U32,
196 limit: U32,
197 max: U32
198) -> IO(Unit):
199 Io.http.serve_with(C, run, srv, path, origins, ctx, host, port, limit, max)
200
201
202
203
204@unsafe def http.serve_forever_with(
205 ~C: Data,
206 ~run: C -> String -> Value.Json -> IO(Rpc.Out),
207 ~srv: Server.Server,
208 ~path: String,
209 ~origins: List<&2, String>,
210 +ctx: C,
211 host: String,
212 port: U32,
213 max: U32
214) -> IO(Unit):
215 Io.http.serve_forever_with(C, run, srv, path, origins, ctx, host, port, max)
216
217
218
219
220
221
222
223
224
225def http.handle_from(
226 ~C: Data,
227 ~srv: C -> Server.Server,
228 ~run: C -> String -> Value.Json -> IO(Rpc.Out),
229 ~path: String,
230 ~origins: List<&2, String>,
231 +ctx: C,
232 req: Http.Request
233) -> IO(Http.Reply):
234 Io.http.web(C, run, ctx, Web.decide(srv(ctx), path, origins, req))
235
236
237
238
239def http.serve_from(
240 ~C: Data,
241 ~srv: C -> Server.Server,
242 ~run: C -> String -> Value.Json -> IO(Rpc.Out),
243 ~path: String,
244 ~origins: List<&2, String>,
245 +ctx: C,
246 host: String,
247 port: U32,
248 limit: U32,
249 max: U32
250) -> IO(Unit):
251 Io.http.serve_from(C, srv, run, path, origins, ctx, host, port, limit, max)
252
253
254
255
256@unsafe def http.serve_forever_from(
257 ~C: Data,
258 ~srv: C -> Server.Server,
259 ~run: C -> String -> Value.Json -> IO(Rpc.Out),
260 ~path: String,
261 ~origins: List<&2, String>,
262 +ctx: C,
263 host: String,
264 port: U32,
265 max: U32
266) -> IO(Unit):
267 Io.http.serve_forever_from(C, srv, run, path, origins, ctx, host, port, max)
268
269
270@unsafe def stdio.serve_with(
271 ~C: Data,
272 ~run: C -> String -> Value.Json -> IO(Rpc.Out),
273 ~srv: Server.Server,
274 +ctx: C
275) -> IO(Unit):
276 Io.stdio.serve_with(C, run, srv, ctx)
277
278
279
280
281
282@unsafe def stdio.serve(
283 ~run: String -> Value.Json -> IO(Rpc.Out),
284 ~srv: Server.Server
285) -> IO(Unit):
286 Io.stdio.serve(run, srv)
287
288
289
290
291
292
293
294
295
296
297
298
299
300def openapi.ops(doc: Value.Json) -> List<&2, Openapi.Op>:
301 Openapi.ops(doc)
302
303
304def openapi.tool(op: Openapi.Op) -> Server.Tool:
305 Openapi.tool(op)
306
307
308def openapi.name(op: Openapi.Op) -> String:
309 Openapi.name(op)
310
311
312def openapi.renamed(op: Openapi.Op, name: String) -> Openapi.Op:
313 Openapi.renamed(op, name)
314
315
316
317def openapi.check(op: Openapi.Op, args: Value.Json) -> Maybe<&2, String>:
318 Openapi.check(op, args)
319
320
321
322
323
324def openapi.call(op: Openapi.Op, args: Value.Json) -> Openapi.Call:
325 Openapi.call(op, args)
326
327
328
329
330def client.initialize(
331 id: Value.Json,
332 name: String,
333 version: String
334) -> Value.Json:
335 Client.initialize(id, name, version)
336
337
338def client.initialized() -> Value.Json:
339 Client.initialized()
340
341
342def client.tools(id: Value.Json) -> Value.Json:
343 Client.tools(id)
344
345
346def client.call(id: Value.Json, name: String, args: Value.Json) -> Value.Json:
347 Client.call(id, name, args)
348
349
350
351def client.read(text: String) -> Rpc.Reply:
352 Rpc.read(text)
353
354
355def client.version(result: Value.Json) -> String:
356 Client.version(result)
357
358
359
360
361def client.ask(
362 url: String,
363 version: String,
364 timeout_ms: U32,
365 msg: Value.Json
366) -> IO(Rpc.Reply):
367 Io.client.ask(url, version, timeout_ms, msg)
368
369
370def client.tell(
371 url: String,
372 version: String,
373 timeout_ms: U32,
374 msg: Value.Json
375) -> IO(Bool):
376 Io.client.tell(url, version, timeout_ms, msg)