Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ProviderImplementations/Anthropic/AnthropicProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ protected static function createProviderMetadata(): ProviderMetadata
return new ProviderMetadata(
'anthropic',
'Anthropic',
ProviderTypeEnum::cloud()
ProviderTypeEnum::cloud(),
'https://console.anthropic.com/settings/keys'
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/ProviderImplementations/Google/GoogleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ protected static function createProviderMetadata(): ProviderMetadata
return new ProviderMetadata(
'google',
'Google',
ProviderTypeEnum::cloud()
ProviderTypeEnum::cloud(),
'https://aistudio.google.com/app/api-keys'
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/ProviderImplementations/OpenAi/OpenAiProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ protected static function createProviderMetadata(): ProviderMetadata
return new ProviderMetadata(
'openai',
'OpenAI',
ProviderTypeEnum::cloud()
ProviderTypeEnum::cloud(),
'https://platform.openai.com/api-keys'
);
}

Expand Down
33 changes: 30 additions & 3 deletions src/Providers/DTO/ProviderMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
* @phpstan-type ProviderMetadataArrayShape array{
* id: string,
* name: string,
* type: string
* type: string,
* credentialsUrl?: ?string
* }
*
* @extends AbstractDataTransferObject<ProviderMetadataArrayShape>
Expand All @@ -28,6 +29,7 @@ class ProviderMetadata extends AbstractDataTransferObject
public const KEY_ID = 'id';
public const KEY_NAME = 'name';
public const KEY_TYPE = 'type';
public const KEY_CREDENTIALS_URL = 'credentialsUrl';

/**
* @var string The provider's unique identifier.
Expand All @@ -44,6 +46,11 @@ class ProviderMetadata extends AbstractDataTransferObject
*/
protected ProviderTypeEnum $type;

/**
* @var string|null The URL where users can get credentials.
*/
protected ?string $credentialsUrl;

/**
* Constructor.
*
Expand All @@ -52,12 +59,14 @@ class ProviderMetadata extends AbstractDataTransferObject
* @param string $id The provider's unique identifier.
* @param string $name The provider's display name.
* @param ProviderTypeEnum $type The provider type.
* @param string|null $credentialsUrl The URL where users can get credentials.
*/
public function __construct(string $id, string $name, ProviderTypeEnum $type)
public function __construct(string $id, string $name, ProviderTypeEnum $type, ?string $credentialsUrl = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this is four parameters long and we're starting to get into optional parameters, I'm curious if we should consider either an array as an optional fourth argument that can extend over time to include more, or if we should instead add a setter for things like this.

Another option is to stick with this for now and then change it to an array later if/when the time arrives and make this parameter backwards-compatible.

What do you think, @felixarntz?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say let's do the latter. It'll be easy to keep things backward compatible in the way you're saying.

{
$this->id = $id;
$this->name = $name;
$this->type = $type;
$this->credentialsUrl = $credentialsUrl;
}

/**
Expand Down Expand Up @@ -96,6 +105,18 @@ public function getType(): ProviderTypeEnum
return $this->type;
}

/**
* Gets the credentials URL.
*
* @since 0.1.0
*
* @return string|null The credentials URL.
*/
public function getCredentialsUrl(): ?string
{
return $this->credentialsUrl;
}

/**
* {@inheritDoc}
*
Expand All @@ -119,6 +140,10 @@ public static function getJsonSchema(): array
'enum' => ProviderTypeEnum::getValues(),
'description' => 'The provider type (cloud, server, or client).',
],
self::KEY_CREDENTIALS_URL => [
'type' => 'string',
'description' => 'The URL where users can get credentials.',
],
],
'required' => [self::KEY_ID, self::KEY_NAME, self::KEY_TYPE],
];
Expand All @@ -137,6 +162,7 @@ public function toArray(): array
self::KEY_ID => $this->id,
self::KEY_NAME => $this->name,
self::KEY_TYPE => $this->type->value,
self::KEY_CREDENTIALS_URL => $this->credentialsUrl,
];
}

Expand All @@ -152,7 +178,8 @@ public static function fromArray(array $array): self
return new self(
$array[self::KEY_ID],
$array[self::KEY_NAME],
ProviderTypeEnum::from($array[self::KEY_TYPE])
ProviderTypeEnum::from($array[self::KEY_TYPE]),
$array[self::KEY_CREDENTIALS_URL] ?? null
);
}
}
30 changes: 28 additions & 2 deletions tests/unit/Providers/DTO/ProviderMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ public function testConstructorAndGetters(): void
$this->assertEquals($name, $metadata->getName());
$this->assertSame($type, $metadata->getType());
$this->assertTrue($metadata->getType()->isCloud());
$this->assertNull($metadata->getCredentialsUrl());
}

/**
* Tests constructor with credentials URL.
*
* @return void
*/
public function testConstructorWithCredentialsUrl(): void
{
$id = 'openai';
$name = 'OpenAI';
$type = ProviderTypeEnum::cloud();
$credentialsUrl = 'https://platform.openai.com/account/api-keys';

$metadata = new ProviderMetadata($id, $name, $type, $credentialsUrl);

$this->assertEquals($id, $metadata->getId());
$this->assertEquals($name, $metadata->getName());
$this->assertSame($type, $metadata->getType());
$this->assertEquals($credentialsUrl, $metadata->getCredentialsUrl());
}

/**
Expand Down Expand Up @@ -78,11 +99,13 @@ public function testGetJsonSchema(): void
$this->assertArrayHasKey(ProviderMetadata::KEY_ID, $schema['properties']);
$this->assertArrayHasKey(ProviderMetadata::KEY_NAME, $schema['properties']);
$this->assertArrayHasKey(ProviderMetadata::KEY_TYPE, $schema['properties']);
$this->assertArrayHasKey(ProviderMetadata::KEY_CREDENTIALS_URL, $schema['properties']);

// Check property types
$this->assertEquals('string', $schema['properties'][ProviderMetadata::KEY_ID]['type']);
$this->assertEquals('string', $schema['properties'][ProviderMetadata::KEY_NAME]['type']);
$this->assertEquals('string', $schema['properties'][ProviderMetadata::KEY_TYPE]['type']);
$this->assertEquals('string', $schema['properties'][ProviderMetadata::KEY_CREDENTIALS_URL]['type']);

// Check enum values for type
$this->assertArrayHasKey('enum', $schema['properties'][ProviderMetadata::KEY_TYPE]);
Expand Down Expand Up @@ -110,7 +133,8 @@ public function testToArray(): void
$this->assertEquals('anthropic', $array[ProviderMetadata::KEY_ID]);
$this->assertEquals('Anthropic', $array[ProviderMetadata::KEY_NAME]);
$this->assertEquals('cloud', $array[ProviderMetadata::KEY_TYPE]);
$this->assertCount(3, $array);
$this->assertNull($array[ProviderMetadata::KEY_CREDENTIALS_URL]);
$this->assertCount(4, $array);
}

/**
Expand All @@ -123,7 +147,8 @@ public function testFromArray(): void
$data = [
ProviderMetadata::KEY_ID => 'custom-provider',
ProviderMetadata::KEY_NAME => 'Custom Provider',
ProviderMetadata::KEY_TYPE => 'server'
ProviderMetadata::KEY_TYPE => 'server',
ProviderMetadata::KEY_CREDENTIALS_URL => 'https://example.com/credentials',
];

$metadata = ProviderMetadata::fromArray($data);
Expand All @@ -132,6 +157,7 @@ public function testFromArray(): void
$this->assertEquals('custom-provider', $metadata->getId());
$this->assertEquals('Custom Provider', $metadata->getName());
$this->assertTrue($metadata->getType()->isServer());
$this->assertEquals('https://example.com/credentials', $metadata->getCredentialsUrl());
}

/**
Expand Down