Skip to content
Closed
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: 3 additions & 0 deletions .kosmokrator/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kosmokrator:
agent:
mode: plan
22 changes: 10 additions & 12 deletions app/Agents/Providers/DynamicProviderResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public function setWorkspaceId(?string $workspaceId): self
/**
* Parse a User's brain field and resolve to SDK provider + model.
*
* Brain format: "provider:model" (e.g. "glm-coding:glm-4.7", "anthropic:claude-sonnet-4-5-20250929")
* Brain format: "provider:model" (e.g. "z:glm-5.1", "anthropic:claude-sonnet-4-5-20250929")
*
* @return array{provider: string, model: string}
*/
public function resolve(User $agent): array
{
$this->workspaceId = $agent->workspace_id;

$brain = $agent->brain ?? 'glm-coding:glm-4.7';
$brain = $agent->brain ?? 'z:glm-5.1';
$parts = explode(':', $brain, 2);
$providerKey = $parts[0];
$model = $parts[1] ?? $this->getDefaultModel($providerKey);
Expand All @@ -55,7 +55,7 @@ public function resolveFromParts(string $providerKey, string $model): array
return ['provider' => 'codex', 'model' => $model];
}

// GLM providers use IntegrationSetting for API keys
// Custom providers use IntegrationSetting for API keys
if ($this->isGlmProvider($providerKey)) {
$this->registerGlmProvider($providerKey);
return ['provider' => $providerKey, 'model' => $model];
Expand All @@ -72,18 +72,15 @@ public function resolveFromParts(string $providerKey, string $model): array
}

/**
* Check if a provider key is a GLM variant.
* Check if a provider key is managed by Prism Relay.
*/
private function isGlmProvider(string $providerKey): bool
{
return (new RelayManager)->isRelayProvider($providerKey);
}

/**
* Dynamically register a GLM provider in the Prism config.
*
* GLM uses an OpenAI-compatible API, so we register it as an OpenAI provider
* with a custom URL and API key from IntegrationSetting.
* Dynamically register a custom provider in the Prism config.
*/
private function registerGlmProvider(string $providerKey): void
{
Expand All @@ -107,7 +104,7 @@ private function registerGlmProvider(string $providerKey): void
$apiKey = $integration->getConfigValue('api_key');
$url = $integration->getConfigValue('url') ?? $this->getDefaultGlmUrl($providerKey);

// Set Prism config for the GLM provider variant (registered via PrismManager::extend)
// Set Prism config for the provider variant (registered via PrismManager::extend)
config([
"prism.providers.{$providerKey}" => [
'api_key' => $apiKey,
Expand All @@ -116,10 +113,10 @@ private function registerGlmProvider(string $providerKey): void
]);

// Register in AI SDK config using our custom driver (registered via AiManager::extend)
// This routes through GlmPrismGateway → Prism 'glm' provider → chat/completions
// This routes through GlmPrismGateway to the matching Prism provider.
config([
"ai.providers.{$providerKey}" => [
'driver' => $providerKey, // 'glm' or 'glm-coding' — custom drivers
'driver' => $providerKey,
'key' => $apiKey,
],
]);
Expand Down Expand Up @@ -154,6 +151,7 @@ private function mapToSdkProvider(string $providerKey): ?string
'deepseek' => 'deepseek',
'mistral' => 'mistral',
'ollama' => 'ollama',
'perplexity' => 'perplexity',
];

return $map[$providerKey] ?? null;
Expand Down Expand Up @@ -190,7 +188,7 @@ private function applyIntegrationConfig(string $providerKey): void
}

/**
* Get default URL for a GLM provider.
* Get default URL for a known provider.
*/
private function getDefaultGlmUrl(string $providerKey): string
{
Expand Down
2 changes: 1 addition & 1 deletion app/Agents/Providers/GlmPrismGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

/**
* Custom PrismGateway that routes requests to custom Prism providers
* registered via PrismManager::extend() (GLM, Kimi, MiniMax, etc.).
* registered via PrismManager::extend() (Z.AI, Kimi, MiniMax, etc.).
*
* The base PrismGateway maps driver names to PrismProvider enums, which only
* works for native Prism providers. Custom providers need their string key
Expand Down
7 changes: 4 additions & 3 deletions app/Agents/Tools/ToolRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,13 @@ public function getToolCatalog(User $agent): array
/**
* Instantiate a specific tool by slug (for post-approval execution).
*/
public function instantiateToolBySlug(string $slug, User $agent): \OpenCompany\IntegrationCore\Contracts\Tool|\Laravel\Ai\Contracts\Tool|null
public function instantiateToolBySlug(string $slug, User $agent, ?string $account = null): \OpenCompany\IntegrationCore\Contracts\Tool|\Laravel\Ai\Contracts\Tool|null
{
if (! isset($this->getEffectiveToolMap()[$slug])) {
return null;
}

return $this->instantiateTool($this->getEffectiveToolMap()[$slug]['class'], $agent, $slug);
return $this->instantiateTool($this->getEffectiveToolMap()[$slug]['class'], $agent, $slug, $account);
}

/**
Expand Down Expand Up @@ -573,7 +573,7 @@ public function getAppCatalog(User $agent): string
/**
* Instantiate a tool class via its provider.
*/
private function instantiateTool(string $class, User $agent, string $slug = ''): \OpenCompany\IntegrationCore\Contracts\Tool|\Laravel\Ai\Contracts\Tool
private function instantiateTool(string $class, User $agent, string $slug = '', ?string $account = null): \OpenCompany\IntegrationCore\Contracts\Tool|\Laravel\Ai\Contracts\Tool
{
$context = [
'channel_id' => $this->currentChannelId,
Expand All @@ -589,6 +589,7 @@ private function instantiateTool(string $class, User $agent, string $slug = ''):
'agent' => $agent,
'timezone' => AppSetting::getValue('org_timezone', 'UTC'),
'tool_slug' => $toolSlug,
'account' => $account,
]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Agents/Tools/Workspace/GetIntegrationSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function schema(JsonSchema $schema): array
return [
'integrationId' => $schema
->string()
->description('Integration ID (e.g., "telegram", "glm", "plausible"). Includes both static and dynamic package-provided integrations.')
->description('Integration ID (e.g., "telegram", "z", "plausible"). Includes both static and dynamic package-provided integrations.')
->required(),
];
}
Expand Down
6 changes: 3 additions & 3 deletions app/Agents/Tools/Workspace/TestIntegrationConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function handle(Request $request): string
return $this->testTelegram($apiKey);
}

// GLM-style providers
// OpenAI-compatible chat-completions providers
$url = $setting->getConfigValue('url') ?? ($available[$integrationId]['default_url'] ?? '');
$model = $setting->getConfigValue('default_model') ?? array_key_first($available[$integrationId]['models'] ?? []);

Expand Down Expand Up @@ -122,8 +122,8 @@ public function schema(JsonSchema $schema): array
return [
'integrationId' => $schema
->string()
->description('Integration ID (e.g., "telegram", "glm", "plausible"). Includes both static and dynamic package-provided integrations.')
->description('Integration ID (e.g., "telegram", "z", "plausible"). Includes both static and dynamic package-provided integrations.')
->required(),
];
}
}
}
4 changes: 2 additions & 2 deletions app/Agents/Tools/Workspace/UpdateIntegrationConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function schema(JsonSchema $schema): array
return [
'integrationId' => $schema
->string()
->description('Integration ID (e.g., "telegram", "glm", "plausible"). Includes both static and dynamic package-provided integrations.')
->description('Integration ID (e.g., "telegram", "z", "plausible"). Includes both static and dynamic package-provided integrations.')
->required(),
'apiKey' => $schema
->string()
Expand Down Expand Up @@ -203,4 +203,4 @@ public function schema(JsonSchema $schema): array
->description('JSON array of site domains for string_list fields, e.g. ["example.com"].'),
];
}
}
}
16 changes: 8 additions & 8 deletions app/Console/Commands/TestGlmPing.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

class TestGlmPing extends Command
{
protected $signature = 'glm:ping {--prompt= : Custom prompt to send}';
protected $description = 'Test GLM 4.7 API connection';
protected $signature = 'z:ping {--prompt= : Custom prompt to send}';
protected $description = 'Test Z.AI API connection';

public function handle(): int
{
$this->info('Testing GLM 4.7 API connection...');
$this->info('Testing Z.AI API connection...');
$this->newLine();

$url = config('prism.providers.glm.url');
$apiKey = config('prism.providers.glm.api_key');
$url = config('prism.providers.z.url');
$apiKey = config('prism.providers.z.api_key');

$this->line('Endpoint: ' . $url);
$this->line('API Key: ' . substr($apiKey, 0, 10) . '...');
Expand All @@ -26,7 +26,7 @@ public function handle(): int

try {
$response = Prism::text()
->using('glm', 'glm-4.7')
->using('z', 'glm-5.1')
->withPrompt($prompt)
->asText();

Expand All @@ -45,11 +45,11 @@ public function handle(): int
);

$this->newLine();
$this->info('GLM 4.7 connection successful!');
$this->info('Z.AI connection successful!');

return Command::SUCCESS;
} catch (\Exception $e) {
$this->error('Failed to connect to GLM 4.7:');
$this->error('Failed to connect to Z.AI:');
$this->error($e->getMessage());

if ($this->output->isVerbose()) {
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/AgentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public function store(Request $request): JsonResponse
// Validate brain format (provider:model)
if (!str_contains($validated['brain'], ':')) {
return response()->json([
'error' => 'Invalid brain format. Expected "provider:model" (e.g., "glm:glm-4.7")',
'error' => 'Invalid brain format. Expected "provider:model" (e.g., "z:glm-5.1")',
], 422);
}

[$provider] = explode(':', $validated['brain'], 2);

// Standard providers use .env keys; only check IntegrationSetting for custom providers
$standardProviders = ['anthropic', 'openai', 'gemini', 'groq', 'xai', 'openrouter', 'deepseek', 'mistral', 'ollama'];
$standardProviders = ['anthropic', 'openai', 'gemini', 'groq', 'xai', 'openrouter', 'deepseek', 'mistral', 'ollama', 'perplexity'];

if (!in_array($provider, $standardProviders)) {
$integration = IntegrationSetting::forWorkspace()
Expand Down
Loading
Loading