Skip to content

Commit

Permalink
Merge branch 'release/v0.4.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Feb 15, 2025
2 parents 466bfa1 + 00e38a7 commit 89850e1
Show file tree
Hide file tree
Showing 19 changed files with 442 additions and 58 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
php-version: "8.4"
extensions: "${{ env.PHP_EXTENSIONS }}"
ini-values: "post_max_size=256M"

Expand Down Expand Up @@ -60,9 +60,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
steps:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
Expand Down Expand Up @@ -101,7 +99,7 @@ jobs:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
php-version: "8.4"
extensions: "${{ env.PHP_EXTENSIONS }}"
ini-values: "post_max_size=256M"

Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v0.4.7 (2025-02-15)
* Updated Exceptional call signature
* Updated dependencies
* Added @phpstan-require-implements constraints
* Upgraded PHPStan to v2
* Tidied boolean logic
* Fixed Exceptional syntax
* Added PHP8.4 to CI workflow
* Made PHP8.4 minimum version

## v0.4.6 (2024-08-21)
* Updated dependencies
* Updated Veneer dependency and Stub
Expand Down
23 changes: 14 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
"email": "[email protected]"
} ],
"require": {
"php": "^8.1",
"php": "^8.4",

"decodelabs/archetype": "^0.3",
"decodelabs/atlas": "^0.12",
"decodelabs/coercion": "^0.2.8",
"decodelabs/dictum": "^0.6.0",
"decodelabs/exceptional": "^0.4.5",
"decodelabs/slingshot": "^0.1.7",
"decodelabs/veneer": "^0.11.6",
"decodelabs/archetype": "^0.3.8",
"decodelabs/atlas": "^0.12.3",
"decodelabs/coercion": "^0.2.15",
"decodelabs/dictum": "^0.6.9",
"decodelabs/exceptional": "^0.5.3",
"decodelabs/slingshot": "^0.1.12",
"decodelabs/veneer": "^0.12.3",

"nesbot/carbon": "^2|^3"
},
"require-dev": {
"decodelabs/phpstan-decodelabs": "^0.6.7"
"decodelabs/phpstan-decodelabs": "^0.7"
},
"autoload": {
"psr-4": {
Expand All @@ -36,5 +36,10 @@
"branch-alias": {
"dev-develop": "0.4.x-dev"
}
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}
3 changes: 2 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

return ECSConfig::configure()
->withPaths([
__DIR__ . '/src'
__DIR__ . '/src',
__DIR__ . '/tests'
])
->withPreparedSets(
cleanCode: true,
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
parameters:
paths:
- src
- src/
- tests/
level: max
3 changes: 3 additions & 0 deletions src/BlueprintTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use DecodeLabs\Prophet\Service\Medium;
use ReflectionClass;

/**
* @phpstan-require-implements Blueprint
*/
trait BlueprintTrait
{
public function getAction(): string
Expand Down
18 changes: 12 additions & 6 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function updateAssistant(

if (!$platform->updateAssistant($assistant)) {
throw Exceptional::Runtime(
'Failed to update assistant'
message: 'Failed to update assistant'
);
}

Expand Down Expand Up @@ -418,7 +418,7 @@ public function refreshThread(
): void {
if ($thread->getServiceId() === null) {
throw Exceptional::Runtime(
'Cannot refresh thread that has not completed initialization'
message: 'Cannot refresh thread that has not completed initialization'
);
}

Expand Down Expand Up @@ -469,7 +469,7 @@ public function pollThread(

if (!$thread->isReady()) {
throw Exceptional::Runtime(
'Unable to get a response'
message: 'Unable to get a response'
);
}

Expand Down Expand Up @@ -529,10 +529,13 @@ public function serializeThreadWithMessages(
int $limit = 20,
?string $afterId = null
): array {
return array_merge(
$output = array_merge(
Coercion::toArray($thread->jsonSerialize()),
$this->fetchMessages($thread, $limit, $afterId)->jsonSerialize()
);

/** @var array<string,mixed> */
return $output;
}

/**
Expand Down Expand Up @@ -562,7 +565,7 @@ public function reply(
): Message {
if ($thread->getServiceId() === null) {
throw Exceptional::Runtime(
'Cannot reply to thread that has not completed initialization'
message: 'Cannot reply to thread that has not completed initialization'
);
}

Expand All @@ -579,4 +582,7 @@ public function reply(


// Register the Veneer facade
Veneer::register(Context::class, Prophet::class);
Veneer\Manager::getGlobalManager()->register(
Context::class,
Prophet::class
);
3 changes: 3 additions & 0 deletions src/Model/AssistantTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use DecodeLabs\Prophet;
use DecodeLabs\Prophet\Service\Medium;

/**
* @phpstan-require-implements Assistant
*/
trait AssistantTrait
{
/**
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Content/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

class File implements Content
{
protected Medium $medium;
protected string $fileId;
protected(set) Medium $medium;
protected(set) string $fileId;

public function __construct(
string $fileId,
Expand Down
14 changes: 8 additions & 6 deletions src/Model/Content/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class Json implements Content
{
protected string $content;
protected(set) string $content;

public function __construct(
string $content
Expand All @@ -42,13 +42,15 @@ public function getContent(): array
$output = json_decode($this->content, true);

if ($output === null) {
throw Exceptional::UnexpectedValue([
'message' => 'Invalid JSON response',
'data' => $this->content
]);
throw Exceptional::UnexpectedValue(
message: 'Invalid JSON response',
data: $this->content
);
}

return Coercion::toArray($output);
/** @var array<string,mixed> */
$output = Coercion::toArray($output);
return $output;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Content/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

class Text implements Content
{
protected Medium $medium = Medium::Text;
protected string $content;
protected(set) Medium $medium = Medium::Text;
protected(set) string $content;

public function __construct(
string $content,
Expand Down
8 changes: 4 additions & 4 deletions src/Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public function getJsonContent(): array
}
}

throw Exceptional::UnexpectedValue([
'message' => 'Invalid JSON response',
'data' => $this->content
]);
throw Exceptional::UnexpectedValue(
message: 'Invalid JSON response',
data: $this->content
);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Model/SuggestionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace DecodeLabs\Prophet\Model;

/**
* @phpstan-require-implements Suggestion
*/
trait SuggestionTrait
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Model/ThreadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use DecodeLabs\Prophet;
use DecodeLabs\Prophet\Service\Medium;

/**
* @phpstan-require-implements Thread
*/
trait ThreadTrait
{
/**
Expand Down
44 changes: 22 additions & 22 deletions stubs/DecodeLabs/Prophet.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,68 +22,68 @@ class Prophet implements Proxy
{
use ProxyTrait;

const Veneer = 'DecodeLabs\\Prophet';
const VeneerTarget = Inst::class;
public const Veneer = 'DecodeLabs\\Prophet';
public const VeneerTarget = Inst::class;

public static Inst $instance;
protected static Inst $_veneerInstance;

public static function loadPlatform(string $name): Ref0 {
return static::$instance->loadPlatform(...func_get_args());
return static::$_veneerInstance->loadPlatform(...func_get_args());
}
public static function getRepository(): Ref1 {
return static::$instance->getRepository();
return static::$_veneerInstance->getRepository();
}
public static function loadBlueprint(string $name): Ref2 {
return static::$instance->loadBlueprint(...func_get_args());
return static::$_veneerInstance->loadBlueprint(...func_get_args());
}
public static function loadGenerator(string $name): Ref3 {
return static::$instance->loadGenerator(...func_get_args());
return static::$_veneerInstance->loadGenerator(...func_get_args());
}
public static function generate(string $name, Ref4 $subject): mixed {
return static::$instance->generate(...func_get_args());
return static::$_veneerInstance->generate(...func_get_args());
}
public static function tryLoadAssistant(Ref2|string $blueprint, string $serviceName): ?Ref5 {
return static::$instance->tryLoadAssistant(...func_get_args());
return static::$_veneerInstance->tryLoadAssistant(...func_get_args());
}
public static function loadAssistant(Ref2|string $blueprint, string $serviceName): Ref5 {
return static::$instance->loadAssistant(...func_get_args());
return static::$_veneerInstance->loadAssistant(...func_get_args());
}
public static function loadFreshAssistant(Ref2|string $blueprint, string $serviceName): Ref5 {
return static::$instance->loadFreshAssistant(...func_get_args());
return static::$_veneerInstance->loadFreshAssistant(...func_get_args());
}
public static function updateAssistant(Ref5 $assistant): void {}
public static function loadAndDeleteAssistant(Ref2|string $blueprint, string $serviceName): bool {
return static::$instance->loadAndDeleteAssistant(...func_get_args());
return static::$_veneerInstance->loadAndDeleteAssistant(...func_get_args());
}
public static function deleteAssistant(Ref5 $assistant): bool {
return static::$instance->deleteAssistant(...func_get_args());
return static::$_veneerInstance->deleteAssistant(...func_get_args());
}
public static function tryLoadThread(Ref2|string $blueprint, Ref4 $subject): ?Ref6 {
return static::$instance->tryLoadThread(...func_get_args());
return static::$_veneerInstance->tryLoadThread(...func_get_args());
}
public static function loadThread(Ref2|string $blueprint, Ref4 $subject): Ref6 {
return static::$instance->loadThread(...func_get_args());
return static::$_veneerInstance->loadThread(...func_get_args());
}
public static function refreshThread(Ref6 $thread): void {}
public static function loadAndPollThread(Ref2|string $blueprint, Ref4 $subject): Ref6 {
return static::$instance->loadAndPollThread(...func_get_args());
return static::$_veneerInstance->loadAndPollThread(...func_get_args());
}
public static function pollThread(Ref6 $thread, int $attempts = 5): Ref6 {
return static::$instance->pollThread(...func_get_args());
return static::$_veneerInstance->pollThread(...func_get_args());
}
public static function loadAndDeleteThread(Ref2|string $blueprint, Ref4 $subject): bool {
return static::$instance->loadAndDeleteThread(...func_get_args());
return static::$_veneerInstance->loadAndDeleteThread(...func_get_args());
}
public static function deleteThread(Ref6 $thread): bool {
return static::$instance->deleteThread(...func_get_args());
return static::$_veneerInstance->deleteThread(...func_get_args());
}
public static function serializeThreadWithMessages(Ref6 $thread, int $limit = 20, ?string $afterId = NULL): array {
return static::$instance->serializeThreadWithMessages(...func_get_args());
return static::$_veneerInstance->serializeThreadWithMessages(...func_get_args());
}
public static function fetchMessages(Ref6 $thread, int $limit = 20, ?string $afterId = NULL): Ref7 {
return static::$instance->fetchMessages(...func_get_args());
return static::$_veneerInstance->fetchMessages(...func_get_args());
}
public static function reply(Ref6 $thread, string $message): Ref8 {
return static::$instance->reply(...func_get_args());
return static::$_veneerInstance->reply(...func_get_args());
}
};
Loading

0 comments on commit 89850e1

Please sign in to comment.