Skip to content

Commit 3c32e97

Browse files
committed
feat(OpenMessageSchedule): refactor message content update logic and enhance data isolation handling
1 parent 8b7acc9 commit 3c32e97

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

backend/magic-service/app/Infrastructure/Core/Traits/DataIsolationTrait.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99

1010
use App\Domain\Contact\Entity\ValueObject\DataIsolation;
1111
use App\Interfaces\Authorization\Web\MagicUserAuthorization;
12+
use InvalidArgumentException;
1213
use Qbhy\HyperfAuth\Authenticatable;
1314

1415
trait DataIsolationTrait
1516
{
16-
/**
17-
* @param MagicUserAuthorization $authorization
18-
*/
19-
protected function createDataIsolation(Authenticatable $authorization): DataIsolation
17+
protected function createDataIsolation(Authenticatable|MagicUserAuthorization $authorization): DataIsolation
2018
{
2119
$dataIsolation = new DataIsolation();
2220
/* @phpstan-ignore-next-line */
@@ -25,8 +23,11 @@ protected function createDataIsolation(Authenticatable $authorization): DataIsol
2523
$dataIsolation->setCurrentUserId(currentUserId: $userId);
2624
$dataIsolation->setCurrentMagicId(currentMagicId: $authorization->getMagicId());
2725
$dataIsolation->setUserType(userType: $authorization->getUserType());
26+
$dataIsolation->setCurrentOrganizationCode(currentOrganizationCode: $authorization->getOrganizationCode());
27+
} else {
28+
throw new InvalidArgumentException(message: 'Unsupported authorization type for data isolation');
2829
}
29-
$dataIsolation->setCurrentOrganizationCode(currentOrganizationCode: $authorization->getOrganizationCode());
30+
3031
return $dataIsolation;
3132
}
3233
}

backend/super-magic-module/src/Application/SuperAgent/Service/OpenMessageScheduleAppService.php

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
namespace Dtyq\SuperMagic\Application\SuperAgent\Service;
99

10-
use App\Infrastructure\Util\IdGenerator\IdGenerator;
1110
use App\Domain\Contact\Entity\ValueObject\DataIsolation;
1211
use App\Domain\File\Service\FileDomainService;
1312
use App\Domain\Provider\Entity\ValueObject\Status;
1413
use App\Domain\Provider\Service\ProviderModelDomainService;
1514
use App\ErrorCode\GenericErrorCode;
1615
use App\Infrastructure\Core\Exception\BusinessException;
1716
use App\Infrastructure\Core\Exception\ExceptionBuilder;
17+
use App\Infrastructure\Util\IdGenerator\IdGenerator;
1818
use Cron\CronExpression;
1919
use DateTime;
2020
use Dtyq\SuperMagic\Application\SuperAgent\Assembler\TaskConfigAssembler;
@@ -337,49 +337,6 @@ protected function buildModelFromProviderModelId(string $modelId, DataIsolation
337337
];
338338
}
339339

340-
private function applyOpenMessageContentUpdates(
341-
MessageScheduleEntity $messageSchedule,
342-
OpenMessageScheduleEntity $entity,
343-
DataIsolation $dataIsolation
344-
): void {
345-
if (! $entity->hasMessageContentTextInput() && ! $entity->hasModelIdInput()) {
346-
return;
347-
}
348-
349-
$messageContent = $messageSchedule->getMessageContent();
350-
$resolvedModelId = $entity->hasModelIdInput()
351-
? (string) $entity->getModelId()
352-
: $this->extractModelIdFromMessageContent($messageContent);
353-
$model = $this->buildModelFromProviderModelId($resolvedModelId, $dataIsolation);
354-
355-
if ($entity->hasMessageContentTextInput()) {
356-
$messageSchedule->setMessageContent(
357-
$this->buildFullMessageContent((string) ($entity->getMessageContentText() ?? ''), $model)
358-
);
359-
360-
return;
361-
}
362-
363-
if (! isset($messageContent['extra']) || ! is_array($messageContent['extra'])) {
364-
$messageContent['extra'] = [];
365-
}
366-
if (! isset($messageContent['extra']['super_agent']) || ! is_array($messageContent['extra']['super_agent'])) {
367-
$messageContent['extra']['super_agent'] = [];
368-
}
369-
370-
$messageContent['extra']['super_agent']['model'] = $model;
371-
$messageSchedule->setMessageContent($messageContent);
372-
}
373-
374-
private function extractModelIdFromMessageContent(array $messageContent): string
375-
{
376-
return (string) (
377-
$messageContent['extra']['super_agent']['model']['provider_model_id']
378-
?? $messageContent['extra']['super_agent']['model']['model_id']
379-
?? ''
380-
);
381-
}
382-
383340
protected function createTimeConfigDTO(array $timeConfig): TimeConfigDTO
384341
{
385342
$timeConfigDTO = new TimeConfigDTO();
@@ -560,4 +517,47 @@ protected function shouldMarkAsCompleted(MessageScheduleEntity $messageSchedule)
560517

561518
return false;
562519
}
520+
521+
private function applyOpenMessageContentUpdates(
522+
MessageScheduleEntity $messageSchedule,
523+
OpenMessageScheduleEntity $entity,
524+
DataIsolation $dataIsolation
525+
): void {
526+
if (! $entity->hasMessageContentTextInput() && ! $entity->hasModelIdInput()) {
527+
return;
528+
}
529+
530+
$messageContent = $messageSchedule->getMessageContent();
531+
$resolvedModelId = $entity->hasModelIdInput()
532+
? (string) $entity->getModelId()
533+
: $this->extractModelIdFromMessageContent($messageContent);
534+
$model = $this->buildModelFromProviderModelId($resolvedModelId, $dataIsolation);
535+
536+
if ($entity->hasMessageContentTextInput()) {
537+
$messageSchedule->setMessageContent(
538+
$this->buildFullMessageContent((string) ($entity->getMessageContentText() ?? ''), $model)
539+
);
540+
541+
return;
542+
}
543+
544+
if (! isset($messageContent['extra']) || ! is_array($messageContent['extra'])) {
545+
$messageContent['extra'] = [];
546+
}
547+
if (! isset($messageContent['extra']['super_agent']) || ! is_array($messageContent['extra']['super_agent'])) {
548+
$messageContent['extra']['super_agent'] = [];
549+
}
550+
551+
$messageContent['extra']['super_agent']['model'] = $model;
552+
$messageSchedule->setMessageContent($messageContent);
553+
}
554+
555+
private function extractModelIdFromMessageContent(array $messageContent): string
556+
{
557+
return (string) (
558+
$messageContent['extra']['super_agent']['model']['provider_model_id']
559+
?? $messageContent['extra']['super_agent']['model']['model_id']
560+
?? ''
561+
);
562+
}
563563
}

backend/super-magic-module/src/Interfaces/SuperAgent/DTO/Request/CreateOpenMessageScheduleRequestDTO.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,4 @@ public function getRemark(): string
6767
{
6868
return $this->remark;
6969
}
70-
7170
}

0 commit comments

Comments
 (0)