relay/completion
Argument completion for prompts and resource templates
(completion/complete).
completion(handler) binds one handler for the server; it receives the
context and a Request naming the prompt or template, the argument being
completed, its partial value and the values of the other arguments. A
handler’s error is hidden from the client, which sees the JSON-RPC
internal error. Attach it with relay/server.with_completion; a client
asks with relay/client.complete.
import gleam/list
import gleam/string
import relay/completion
pub fn languages() -> completion.Completion(Nil) {
completion.completion(fn(_context, request: completion.Request) {
["gleam", "erlang", "elixir"]
|> list.filter(string.starts_with(_, request.value))
|> completion.values
|> Ok
})
}
Types
A completion handler.
pub type Completion(context) =
@internal Completion(context)
What is being completed: a prompt’s argument or a resource template’s variable.
pub type Reference {
PromptReference(name: String)
ResourceReference(uri_template: String)
}
Constructors
-
PromptReference(name: String) -
ResourceReference(uri_template: String)
Completion values. The wire carries at most 100; total and has_more
tell the client about the rest.
pub type Values {
Values(
values: List(String),
total: option.Option(Int),
has_more: option.Option(Bool),
)
}
Constructors
-
Values( values: List(String), total: option.Option(Int), has_more: option.Option(Bool), )
Values
pub fn completion(
complete: fn(context, Request) -> Result(Values, error),
) -> Completion(context)
A completion handler. An Error reaches the client as the JSON-RPC
internal error.