Skip to content
Open
Show file tree
Hide file tree
Changes from 17 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
4 changes: 4 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Meilisearch;

use Meilisearch\Endpoints\Batches;
use Meilisearch\Endpoints\ChatWorkspaces;
use Meilisearch\Endpoints\Delegates\HandlesBatches;
use Meilisearch\Endpoints\Delegates\HandlesChatWorkspaces;
use Meilisearch\Endpoints\Delegates\HandlesDumps;
use Meilisearch\Endpoints\Delegates\HandlesIndex;
use Meilisearch\Endpoints\Delegates\HandlesKeys;
Expand All @@ -31,6 +33,7 @@

class Client
{
use HandlesChatWorkspaces;
use HandlesDumps;
use HandlesIndex;
use HandlesTasks;
Expand All @@ -53,6 +56,7 @@ public function __construct(
?StreamFactoryInterface $streamFactory = null
) {
$this->http = new MeilisearchClientAdapter($url, $apiKey, $httpClient, $requestFactory, $clientAgents, $streamFactory);
$this->chats = new ChatWorkspaces($this->http);
$this->index = new Indexes($this->http);
$this->health = new Health($this->http);
$this->version = new Version($this->http);
Expand Down
69 changes: 69 additions & 0 deletions src/Contracts/ChatWorkspacePromptsSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace Meilisearch\Contracts;

class ChatWorkspacePromptsSettings extends Data
{
public string $system;
public string $searchDescription;
public string $searchQParam;
public string $searchIndexUidParam;
Comment on lines +9 to +12
Copy link
Collaborator

@norkunas norkunas Aug 22, 2025

Choose a reason for hiding this comment

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

If you would pass empty strings, will it still work? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes!


/**
* @param array{
* system: string,
* searchDescription: string,
* searchQParam: string,
* searchIndexUidParam: string
* } $params
*/
public function __construct(array $params)
{
parent::__construct($params);

$this->system = $params['system'];
$this->searchDescription = $params['searchDescription'];
$this->searchQParam = $params['searchQParam'];
$this->searchIndexUidParam = $params['searchIndexUidParam'];
}

public function getSystem(): string
{
return $this->system;
}

public function getSearchDescription(): string
{
return $this->searchDescription;
}

public function getSearchQParam(): string
{
return $this->searchQParam;
}

public function getSearchIndexUidParam(): string
{
return $this->searchIndexUidParam;
}

/**
* @return array{
* system: string,
* searchDescription: string,
* searchQParam: string,
* searchIndexUidParam: string
* }
*/
public function toArray(): array
{
return [
'system' => $this->system,
'searchDescription' => $this->searchDescription,
'searchQParam' => $this->searchQParam,
'searchIndexUidParam' => $this->searchIndexUidParam,
];
}
}
119 changes: 119 additions & 0 deletions src/Contracts/ChatWorkspaceSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

declare(strict_types=1);

namespace Meilisearch\Contracts;

class ChatWorkspaceSettings extends Data
Copy link
Collaborator

Choose a reason for hiding this comment

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

this misses many typehints

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated 🙌

{
private string $source;
private ?string $orgId;
private ?string $projectId;
private ?string $apiVersion;
private ?string $deploymentId;
private ?string $baseUrl;
private ?string $apiKey;
Comment on lines +9 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

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

does these also work as empty strings? :)

private ChatWorkspacePromptsSettings $prompts;

/**
* @param array{
* source: string,
* orgId?: string,
* projectId?: string,
* apiVersion?: string,
* deploymentId?: string,
* baseUrl?: string,
* apiKey?: string,
* prompts: array{
* system: string,
* searchDescription: string,
* searchQParam: string,
* searchIndexUidParam: string
* }
* } $params
*/
public function __construct(array $params)
{
parent::__construct($params);

$this->source = $params['source'];
$this->orgId = $params['orgId'] ?? null;
$this->projectId = $params['projectId'] ?? null;
$this->apiVersion = $params['apiVersion'] ?? null;
$this->deploymentId = $params['deploymentId'] ?? null;
$this->baseUrl = $params['baseUrl'] ?? null;
$this->apiKey = $params['apiKey'] ?? null;
$this->prompts = new ChatWorkspacePromptsSettings($params['prompts']);
}

public function getSource(): string
{
return $this->source;
}

public function getOrgId(): ?string
{
return $this->orgId;
}

public function getProjectId(): ?string
{
return $this->projectId;
}

public function getApiVersion(): ?string
{
return $this->apiVersion;
}

public function getDeploymentId(): ?string
{
return $this->deploymentId;
}

public function getBaseUrl(): ?string
{
return $this->baseUrl;
}

public function getApiKey(): ?string
{
return $this->apiKey;
}

public function getPrompts(): ChatWorkspacePromptsSettings
{
return $this->prompts;
}

/**
* @return array{
* source: string,
* orgId?: string,
* projectId?: string,
* apiVersion?: string,
* deploymentId?: string,
* baseUrl?: string,
* apiKey?: string,
* prompts: array{
* system: string,
* searchDescription: string,
* searchQParam: string,
* searchIndexUidParam: string
* }
* }
*/
public function toArray(): array
{
return [
'source' => $this->source,
'orgId' => $this->orgId,
'projectId' => $this->projectId,
'apiVersion' => $this->apiVersion,
'deploymentId' => $this->deploymentId,
'baseUrl' => $this->baseUrl,
'apiKey' => $this->apiKey,
'prompts' => $this->prompts->toArray(),
];
}
}
59 changes: 59 additions & 0 deletions src/Contracts/ChatWorkspacesResults.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace Meilisearch\Contracts;

class ChatWorkspacesResults extends Data
{
private int $offset;
private int $limit;
private int $total;

public function __construct(array $params)
{
parent::__construct($params['results']);

$this->offset = $params['offset'];
$this->limit = $params['limit'];
$this->total = $params['total'];
}

/**
* @return array<int, array{uid: string}>
*/
public function getResults(): array
{
return $this->data;
}

public function getOffset(): int
{
return $this->offset;
}

public function getLimit(): int
{
return $this->limit;
}

public function getTotal(): int
{
return $this->total;
}

public function toArray(): array
{
return [
'results' => $this->data,
'offset' => $this->offset,
'limit' => $this->limit,
'total' => $this->total,
];
}

public function count(): int
{
return \count($this->data);
}
}
6 changes: 6 additions & 0 deletions src/Contracts/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ public function patch(string $path, $body = null, array $query = []);
* @throws JsonDecodingException
*/
public function delete(string $path, array $query = []);

/**
* @throws ApiException
* @throws JsonEncodingException
*/
public function postStream(string $path, $body = null, array $query = []): \Psr\Http\Message\StreamInterface;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This again - misses import statement and using only class name as per coding standards

}
40 changes: 40 additions & 0 deletions src/Endpoints/ChatWorkspaces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Meilisearch\Endpoints;

use Meilisearch\Contracts\ChatWorkspacesResults;
use Meilisearch\Contracts\Endpoint;
use Meilisearch\Contracts\Http;
use Meilisearch\Endpoints\Delegates\HandlesChatWorkspaceSettings;

class ChatWorkspaces extends Endpoint
{
use HandlesChatWorkspaceSettings;

protected const PATH = '/chats';

/**
* @var non-empty-string|null
*/
private ?string $workspaceName;

public function __construct(Http $http, ?string $workspaceName = null)
{
$this->workspaceName = $workspaceName;
parent::__construct($http);
}

public function listWorkspaces(): ChatWorkspacesResults
{
$response = $this->http->get(self::PATH);

return new ChatWorkspacesResults($response);
}

public function workspace(string $workspaceName): self
{
return new self($this->http, $workspaceName);
}
}
Loading
Loading