feat: lit-guide topic all returns every guide in one call
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
@@ -16,6 +16,12 @@ final class GuideAbility implements Ability
|
||||
{
|
||||
private const DEFAULT_TOPIC = 'overview';
|
||||
|
||||
/** topic = all: every topic in one call (overview first). */
|
||||
public const ALL = 'all';
|
||||
|
||||
/** Upper bound of the combined text of topic = all (bytes). */
|
||||
public const ALL_LIMIT = 100000;
|
||||
|
||||
public function __construct(private GuideRepository $guides)
|
||||
{
|
||||
}
|
||||
@@ -32,7 +38,8 @@ final class GuideAbility implements Ability
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Liefert Anleitungen zur Bedienung dieses MCP-Servers. Ohne topic: Übersicht und Liste aller Themen.';
|
||||
return 'Liefert Anleitungen zur Bedienung dieses MCP-Servers. Ohne topic: Übersicht und Liste aller Themen; '
|
||||
. 'topic = all: alle Themen in einem Aufruf (gut für den Einstieg).';
|
||||
}
|
||||
|
||||
public function inputSchema(): array
|
||||
@@ -42,7 +49,7 @@ final class GuideAbility implements Ability
|
||||
'properties' => [
|
||||
'topic' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Thema, z. B. "overview" oder "divi-shortform".',
|
||||
'description' => 'Thema, z. B. "overview" oder "divi-shortform"; "all" = alle Themen.',
|
||||
],
|
||||
],
|
||||
'additionalProperties' => false,
|
||||
@@ -83,6 +90,10 @@ final class GuideAbility implements Ability
|
||||
? $input['topic']
|
||||
: self::DEFAULT_TOPIC;
|
||||
$topics = $this->guides->topics();
|
||||
if ($topic === self::ALL) {
|
||||
return ['topic' => self::ALL, 'topics' => $topics, 'content' => $this->all($topics)];
|
||||
}
|
||||
|
||||
$content = $this->guides->get($topic);
|
||||
|
||||
if ($content === null) {
|
||||
@@ -94,4 +105,44 @@ final class GuideAbility implements Ability
|
||||
|
||||
return ['topic' => $topic, 'topics' => $topics, 'content' => $content];
|
||||
}
|
||||
|
||||
/**
|
||||
* Every topic, overview first, separated and labelled; stops before ALL_LIMIT bytes and names
|
||||
* the topics left out.
|
||||
*
|
||||
* @param list<string> $topics
|
||||
*/
|
||||
private function all(array $topics): string
|
||||
{
|
||||
$ordered = in_array(self::DEFAULT_TOPIC, $topics, true)
|
||||
? array_merge([self::DEFAULT_TOPIC], array_values(array_diff($topics, [self::DEFAULT_TOPIC])))
|
||||
: $topics;
|
||||
$parts = [];
|
||||
$size = 0;
|
||||
$left = [];
|
||||
foreach ($ordered as $topic) {
|
||||
$content = $this->guides->get($topic);
|
||||
if ($content === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$part = sprintf("---\nThema `%s`:\n\n%s", $topic, rtrim($content));
|
||||
if ($size + strlen($part) > self::ALL_LIMIT) {
|
||||
$left[] = $topic;
|
||||
continue;
|
||||
}
|
||||
|
||||
$parts[] = $part;
|
||||
$size += strlen($part) + 2;
|
||||
}
|
||||
|
||||
if ($left !== []) {
|
||||
$parts[] = sprintf(
|
||||
'Nicht enthalten (Größenlimit): %s – einzeln mit topic abrufen.',
|
||||
implode(', ', $left)
|
||||
);
|
||||
}
|
||||
|
||||
return implode("\n\n", $parts);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user