Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 85c4345

Browse files
OskarStarkclaude
andcommitted
refactor\!: replace composer suggests with runtime checks
Remove the `suggest` section from composer.json and add explicit runtime checks that throw exceptions with helpful composer require commands when optional dependencies are missing. This provides better developer experience by: - Giving clear error messages when optional dependencies are needed - Providing the exact composer command to install missing packages - Following Symfony's pattern for handling optional dependencies BREAKING CHANGE: Optional dependencies now throw exceptions instead of silently failing when the required packages are not installed. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent a24724c commit 85c4345

File tree

11 files changed

+29
-16
lines changed

11 files changed

+29
-16
lines changed

composer.json

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,6 @@
6363
"symfony/process": "^6.4 || ^7.1",
6464
"symfony/var-dumper": "^6.4 || ^7.1"
6565
},
66-
"suggest": {
67-
"ext-pdo": "For using MariaDB as retrieval vector store.",
68-
"async-aws/bedrock-runtime": "For using the Bedrock platform.",
69-
"codewithkyrian/chromadb-php": "For using the ChromaDB as retrieval vector store.",
70-
"codewithkyrian/transformers": "For using the TransformersPHP with FFI to run models in PHP.",
71-
"doctrine/dbal": "For using MariaDB via Doctrine as retrieval vector store",
72-
"mongodb/mongodb": "For using MongoDB Atlas as retrieval vector store.",
73-
"mrmysql/youtube-transcript": "For using the YouTube transcription tool.",
74-
"probots-io/pinecone-php": "For using the Pinecone as retrieval vector store.",
75-
"symfony/dom-crawler": "For using the Crawler tool.",
76-
"symfony/http-foundation": "For using the SessionStore as message store.",
77-
"psr/cache": "For using the CacheStore as message store."
78-
},
7966
"config": {
8067
"allow-plugins": {
8168
"codewithkyrian/transformers-libsloader": true,

src/Chain/Chat/MessageStore/CacheStore.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public function __construct(
1616
private string $cacheKey,
1717
private int $ttl = 86400,
1818
) {
19+
if (!interface_exists(CacheItemPoolInterface::class)) {
20+
throw new \RuntimeException('For using the CacheStore as message store, the psr/cache package is required. Try running "composer require psr/cache"');
21+
}
1922
}
2023

2124
public function save(MessageBagInterface $messages): void

src/Chain/Chat/MessageStore/SessionStore.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public function __construct(
1818
RequestStack $requestStack,
1919
private string $sessionKey = 'messages',
2020
) {
21+
if (!class_exists(RequestStack::class)) {
22+
throw new \RuntimeException('For using the SessionStore as message store, the symfony/http-foundation package is required. Try running "composer require symfony/http-foundation"');
23+
}
2124
$this->session = $requestStack->getSession();
2225
}
2326

src/Chain/Toolbox/Tool/Crawler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(
1919
private HttpClientInterface $httpClient,
2020
) {
2121
if (!class_exists(DomCrawler::class)) {
22-
throw new RuntimeException('The DomCrawler component is not installed. Please install it using "composer require symfony/dom-crawler".');
22+
throw new RuntimeException('For using the Crawler tool, the symfony/dom-crawler package is required. Try running "composer require symfony/dom-crawler"');
2323
}
2424
}
2525

src/Chain/Toolbox/Tool/YouTubeTranscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
private HttpClientInterface $client,
2121
) {
2222
if (!class_exists(TranscriptListFetcher::class)) {
23-
throw new LogicException('The package `mrmysql/youtube-transcript` is required to use this tool. Try running "composer require mrmysql/youtube-transcript".');
23+
throw new LogicException('For using the YouTube transcription tool, the mrmysql/youtube-transcript package is required. Try running "composer require mrmysql/youtube-transcript"');
2424
}
2525
}
2626

src/Platform/Bridge/Bedrock/PlatformFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public static function create(
1919
BedrockRuntimeClient $bedrockRuntimeClient = new BedrockRuntimeClient(),
2020
?Contract $contract = null,
2121
): Platform {
22+
if (!class_exists(BedrockRuntimeClient::class)) {
23+
throw new \RuntimeException('For using the Bedrock platform, the async-aws/bedrock-runtime package is required. Try running "composer require async-aws/bedrock-runtime"');
24+
}
25+
2226
$modelClient[] = new ClaudeHandler($bedrockRuntimeClient);
2327
$modelClient[] = new NovaHandler($bedrockRuntimeClient);
2428
$modelClient[] = new LlamaModelClient($bedrockRuntimeClient);

src/Platform/Bridge/TransformersPHP/PlatformFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public static function create(): Platform
1616
{
1717
if (!class_exists(Transformers::class)) {
18-
throw new RuntimeException('TransformersPHP is not installed. Please install it using "composer require codewithkyrian/transformers".');
18+
throw new RuntimeException('For using the TransformersPHP with FFI to run models in PHP, the codewithkyrian/transformers package is required. Try running "composer require codewithkyrian/transformers"');
1919
}
2020

2121
return new Platform();

src/Store/Bridge/ChromaDB/Store.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public function __construct(
2020
private Client $client,
2121
private string $collectionName,
2222
) {
23+
if (!class_exists(Client::class)) {
24+
throw new \RuntimeException('For using the ChromaDB as retrieval vector store, the codewithkyrian/chromadb-php package is required. Try running "composer require codewithkyrian/chromadb-php"');
25+
}
2326
}
2427

2528
public function add(VectorDocument ...$documents): void

src/Store/Bridge/MariaDB/Store.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public function __construct(
3434
private string $indexName,
3535
private string $vectorFieldName,
3636
) {
37+
if (!extension_loaded('pdo')) {
38+
throw new \RuntimeException('For using MariaDB as retrieval vector store, the PDO extension is required. Try running "composer require ext-pdo"');
39+
}
3740
}
3841

3942
public static function fromPdo(\PDO $connection, string $tableName, string $indexName = 'embedding', string $vectorFieldName = 'embedding'): self
@@ -46,6 +49,10 @@ public static function fromPdo(\PDO $connection, string $tableName, string $inde
4649
*/
4750
public static function fromDbal(Connection $connection, string $tableName, string $indexName = 'embedding', string $vectorFieldName = 'embedding'): self
4851
{
52+
if (!class_exists(Connection::class)) {
53+
throw new \RuntimeException('For using MariaDB via Doctrine as retrieval vector store, the doctrine/dbal package is required. Try running "composer require doctrine/dbal"');
54+
}
55+
4956
$pdo = $connection->getNativeConnection();
5057

5158
if (!$pdo instanceof \PDO) {

src/Store/Bridge/MongoDB/Store.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public function __construct(
5959
private bool $bulkWrite = false,
6060
private LoggerInterface $logger = new NullLogger(),
6161
) {
62+
if (!class_exists(Client::class)) {
63+
throw new \RuntimeException('For using MongoDB Atlas as retrieval vector store, the mongodb/mongodb package is required. Try running "composer require mongodb/mongodb"');
64+
}
6265
}
6366

6467
public function add(VectorDocument ...$documents): void

0 commit comments

Comments
 (0)