class ToolInvoker implements Errable

Traits

Methods

toJsonRpcResponse(JsonRpcRequest $request, Response|ResponseFactory|array|string $response, callable $serializable)

Serialize a response as a protocol result.

toJsonRpcStreamedResponse(JsonRpcRequest $request, iterable $responses, callable $serializable)

Stream notifications followed by the completed protocol result.

mixed
callHandler(callable $handler, JsonRpcRequest $request)

Call a handler and convert ordinary failures to protocol errors.

toJsonRpcException(Throwable $e, mixed $requestId)

Convert a handler failure to a protocol exception.

toErrorResponse(Throwable $e)

Convert a tool failure to an error response.

string
toErrorMessage(Throwable $e)

Report an internal error and choose its public message.

bool
isBinary(string $content)

Determine whether a response string contains binary data.

__construct(bool $mirrorStructuredContent = true)

Create a tool invoker with the structured-content policy.

invoke(Tool $tool, JsonRpcRequest $request)

Invoke a tool and serialize its responses.

callable
serializable(Tool $tool)

Create the serializer for a tool result.

Details

protected JsonRpcResponse toJsonRpcResponse(JsonRpcRequest $request, Response|ResponseFactory|array|string $response, callable $serializable)

Serialize a response as a protocol result.

Parameters

JsonRpcRequest $request
Response|ResponseFactory|array|string $response
callable $serializable

Return Value

JsonRpcResponse

Exceptions

JsonRpcException

protected Generator toJsonRpcStreamedResponse(JsonRpcRequest $request, iterable $responses, callable $serializable)

Stream notifications followed by the completed protocol result.

Parameters

JsonRpcRequest $request
iterable $responses
callable $serializable

Return Value

Generator

protected mixed callHandler(callable $handler, JsonRpcRequest $request)

Call a handler and convert ordinary failures to protocol errors.

Parameters

callable $handler
JsonRpcRequest $request

Return Value

mixed

protected JsonRpcException toJsonRpcException(Throwable $e, mixed $requestId)

Convert a handler failure to a protocol exception.

Parameters

Throwable $e
mixed $requestId

Return Value

JsonRpcException

protected Response toErrorResponse(Throwable $e)

Convert a tool failure to an error response.

Parameters

Throwable $e

Return Value

Response

protected string toErrorMessage(Throwable $e)

Report an internal error and choose its public message.

Parameters

Throwable $e

Return Value

string

protected bool isBinary(string $content)

Determine whether a response string contains binary data.

Parameters

string $content

Return Value

bool

at line 25
__construct(bool $mirrorStructuredContent = true)

Create a tool invoker with the structured-content policy.

Parameters

bool $mirrorStructuredContent

at line 34
Generator|JsonRpcResponse invoke(Tool $tool, JsonRpcRequest $request)

Invoke a tool and serialize its responses.

Parameters

Tool $tool
JsonRpcRequest $request

Return Value

Generator|JsonRpcResponse

at line 48
protected callable serializable(Tool $tool)

Create the serializer for a tool result.

Parameters

Tool $tool

Return Value

callable