Repository navigation
Conversation
Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>
soyuka
left a comment
There was a problem hiding this comment.
Tthe approach is fine imo. CI is red because of the phpdoc tag below, and we need a CHANGELOG entry under 0.11.0 ### Client for callToolRound(). Can you also rename the PR to [Client] Allow deferring and resuming tool input?
| * a server fault, and answering it would be inventing protocol. | ||
| * | ||
| * @var array<string, class-string<Request>> | ||
| * @var array<string, class-string<ElicitRequest|CreateSamplingMessageRequest|ListRootsRequest>> |
There was a problem hiding this comment.
phpDocumentor doesn't like class-string<A|B|C>, that's what fails make docs-api in qa and Documentation. class-string<ElicitRequest>|class-string<CreateSamplingMessageRequest>|class-string<ListRootsRequest> works, or just keep class-string<Request>.
|
|
||
| $state = $result['requestState'] ?? null; | ||
|
|
||
| return new InputRequiredResult($requests, \is_string($state) ? $state : null); |
There was a problem hiding this comment.
If the server answers input_required with no requests and no state, this throws a Schema InvalidArgumentException, while the auto path throws a client RuntimeException on server faults. Maybe check it here and throw the same one?
| * | ||
| * @return Response<array<string, mixed>>|Error | ||
| */ | ||
| public function requestRound(Request $request, int $timeout, array $round, bool $withProgress = false, ?CancellationTokenInterface $cancellation = null, ?float $callTimeout = null): Response|Error |
There was a problem hiding this comment.
not a huge fan of request() -> requestWithInput() + requestRound(), an optional ?array $round = null on request() would do the same with less methods, no?
|
|
||
| $client = $this->connect(elicitation: true, httpClient: $httpClient); | ||
| // @phpstan-ignore function.alreadyNarrowedType (Run the same assertion against SDK versions without callToolRound.) | ||
| $callRound = method_exists($client, 'callToolRound') ? $client->callToolRound(...) : $client->callTool(...); |
There was a problem hiding this comment.
The method_exists fallback and its phpstan-ignore can go, it was useful to show red on base but now just call callToolRound directly.
| $this->assertNotSame($calls[0]->id, $calls[1]->id); | ||
| $this->assertSame($pending->requestState, $calls[1]->params->requestState); | ||
| $this->assertSame('Grace', $calls[1]->params->inputResponses->who->content->name); | ||
| $this->assertSame('Hello, Ada!', self::text($client->callTool('greet'))); |
There was a problem hiding this comment.
already covered by testMultiRoundTripIsTransparentToTheCaller, can be removed.
Fix the `RESOLVABLE` phpdoc (phpDocumentor rejects `class-string<A|B|C>`), throw the client `RuntimeException` when an `input_required` result carries neither input requests nor state, fold `requestRound()` into an optional `$round` argument of `request()`, add the 0.11.0 Client changelog entry, and drop the `method_exists` fallback and the redundant auto-path assertion. Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>
|
Pushed 6e9c8a1 with the review applied:
|
Fixes #767
Fixes #767. The client protocol resolves every input-required result inside the request loop, so callers cannot save the pending input and answer it later.
Add
Client::callToolRound()for the modern lifecycle. It returns the interim result and accepts keyed answers and opaque state on a later call.callTool()continues to resolve input automatically with its existing signature and return type.Tests:
vendor/bin/phpunit --colors=never --testdox tests/Integration/StatelessClientTest.php --filter testDefersAndResumesToolInput.Result: vendor/bin/phpunit --colors=never tests/Unit/Client tests/Integration/StatelessClientTest.php tests/Integration/StatelessLifecycleTest.php: passed on base (1450 tests, 5080 assertions)
Result: vendor/bin/phpunit --colors=never --testdox tests/Integration/StatelessClientTest.php --filter testDefersAndResumesToolInput: failed on base 7155eae with exit 1 (1 test, 1 assertion, 1 failure). The test used callTool on base and received CallToolResult after the automatic retry.
Result: vendor/bin/phpunit --colors=never --testdox tests/Integration/StatelessClientTest.php --filter testDefersAndResumesToolInput: passed on patched source with exit 0 (1 test, 16 assertions). The test used callToolRound and checked the real outgoing HTTP bodies.
Result: make conformance-tests: passed with exit 0 after preparing writable fixture directories (80/80 server assertions, 252/252 client assertions, all three client extension scenarios passed).
Result: make conformance-draft: passed with exit 0 (152/152 server assertions, 417/417 client assertions, including sep-2322-client-request-state).
Result: make ci: passed with exit 0 on the final source, before the HTTP capture assertions were added (PHPUnit 4435 tests, 13698 assertions, 8 existing interop skips). PHP CS Fixer, PHPStan and Deptrac also passed.
Result: make cs: passed on the final diff with 0 files fixed.
Result: make phpstan: passed on the final diff with no errors.
Result: vendor/bin/phpunit --colors=never tests/Unit/Client tests/Integration/StatelessClientTest.php tests/Integration/StatelessLifecycleTest.php tests/Integration/IntArgumentTest.php: passed with exit 0 on the final diff (1491 tests, 5154 assertions).
Result: git diff --check: passed.
Regression coverage:
tests/Integration/StatelessClientTest.php.