Skip to content

Commit 5c81a79

Browse files
committed
Updates JSON schema generator dependency and refactors SchemaMapper initialization
1 parent d299212 commit 5c81a79

File tree

3 files changed

+35
-37
lines changed

3 files changed

+35
-37
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"require": {
66
"php": "^8.3",
7-
"spiral/json-schema-generator": "^1.0",
7+
"spiral/json-schema-generator": "^2.0",
88
"llm-agents/agents": "^1.0",
99
"cuyz/valinor": "^1.12"
1010
},

src/Integration/Laravel/SchemaMapperServiceProvider.php

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,36 @@
55
namespace LLM\Agents\JsonSchema\Mapper\Integration\Laravel;
66

77
use CuyZ\Valinor\Cache\FileSystemCache;
8-
use CuyZ\Valinor\Mapper\TreeMapper;
98
use Illuminate\Contracts\Foundation\Application;
109
use Illuminate\Support\ServiceProvider;
1110
use LLM\Agents\JsonSchema\Mapper\MapperBuilder;
1211
use LLM\Agents\JsonSchema\Mapper\SchemaMapper;
1312
use LLM\Agents\Tool\SchemaMapperInterface;
13+
use Spiral\JsonSchemaGenerator\Generator;
1414

1515
final class SchemaMapperServiceProvider extends ServiceProvider
1616
{
1717
public function register(): void
1818
{
1919
$this->app->singleton(
2020
SchemaMapperInterface::class,
21-
SchemaMapper::class,
22-
);
23-
24-
$this->app->singleton(
25-
TreeMapper::class,
26-
static fn(
21+
static function (
2722
Application $app,
28-
) => $app->make(MapperBuilder::class)->build(),
29-
);
23+
) {
24+
$mapper = (new MapperBuilder(
25+
cache: match (true) {
26+
$app->environment('prod') => new FileSystemCache(
27+
cacheDir: $app->storagePath('cache/valinor'),
28+
),
29+
default => null,
30+
},
31+
))->build();
3032

31-
$this->app->singleton(
32-
MapperBuilder::class,
33-
static fn(
34-
Application $app,
35-
) => new MapperBuilder(
36-
cache: match (true) {
37-
$app->environment('prod') => new FileSystemCache(
38-
cacheDir: $app->storagePath('cache/valinor'),
39-
),
40-
default => null,
41-
},
42-
),
33+
return new SchemaMapper(
34+
generator: $app->get(Generator::class),
35+
mapper: $mapper,
36+
);
37+
},
4338
);
4439
}
4540
}

src/Integration/Spiral/SchemaMapperBootloader.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,38 @@
55
namespace LLM\Agents\JsonSchema\Mapper\Integration\Spiral;
66

77
use CuyZ\Valinor\Cache\FileSystemCache;
8-
use CuyZ\Valinor\Mapper\TreeMapper;
98
use LLM\Agents\JsonSchema\Mapper\MapperBuilder;
109
use LLM\Agents\JsonSchema\Mapper\SchemaMapper;
1110
use LLM\Agents\Tool\SchemaMapperInterface;
1211
use Spiral\Boot\Bootloader\Bootloader;
1312
use Spiral\Boot\DirectoriesInterface;
1413
use Spiral\Boot\Environment\AppEnvironment;
14+
use Spiral\JsonSchemaGenerator\Generator;
1515

1616
final class SchemaMapperBootloader extends Bootloader
1717
{
1818
public function defineSingletons(): array
1919
{
2020
return [
21-
SchemaMapperInterface::class => SchemaMapper::class,
22-
23-
TreeMapper::class => static fn(
24-
MapperBuilder $builder,
25-
) => $builder->build(),
26-
MapperBuilder::class => static fn(
21+
SchemaMapperInterface::class => static function (
2722
DirectoriesInterface $dirs,
2823
AppEnvironment $env,
29-
) => new MapperBuilder(
30-
cache: match ($env) {
31-
AppEnvironment::Production => new FileSystemCache(
32-
cacheDir: $dirs->get('runtime') . 'cache/valinor',
33-
),
34-
default => null,
35-
},
36-
),
24+
Generator $generator,
25+
) {
26+
$mapper = (new MapperBuilder(
27+
cache: match ($env) {
28+
AppEnvironment::Production => new FileSystemCache(
29+
cacheDir: $dirs->get('runtime') . 'cache/valinor',
30+
),
31+
default => null,
32+
},
33+
))->build();
34+
35+
return new SchemaMapper(
36+
generator: $generator,
37+
mapper: $mapper,
38+
);
39+
},
3740
];
3841
}
3942
}

0 commit comments

Comments
 (0)