Skip to content

feat: add AI log analysis component and integrate into deployment views#4183

Merged
Siumauricio merged 6 commits intocanaryfrom
feat/ai-improvements
Apr 9, 2026
Merged

feat: add AI log analysis component and integrate into deployment views#4183
Siumauricio merged 6 commits intocanaryfrom
feat/ai-improvements

Conversation

@Siumauricio
Copy link
Copy Markdown
Contributor

@Siumauricio Siumauricio commented Apr 9, 2026

  • Introduced the AnalyzeLogs component for analyzing logs using AI, allowing users to select AI providers and view analysis results.
  • Integrated AnalyzeLogs into the ShowDeployment and DockerLogsId components, enabling log analysis for both build and runtime contexts.
  • Updated the AI router to include a new endpoint for log analysis, which processes logs and returns structured insights.
  • Enhanced the AI provider selection logic to support new providers, including Z.AI and MiniMax.

This feature enhances the user experience by providing actionable insights from logs, improving troubleshooting and operational efficiency.

What is this PR about?

Please describe in a short paragraph what this PR is about.

Checklist

Before submitting this PR, please make sure that:

  • You created a dedicated branch based on the canary branch.
  • You have read the suggestions in the CONTRIBUTING.md file https://github.com/Dokploy/dokploy/blob/canary/CONTRIBUTING.md#pull-request
  • You have tested this PR in your local instance. If you have not tested it yet, please do so before submitting. This helps avoid wasting maintainers' time reviewing code that has not been verified by you.

Issues related (if applicable)

closes #2440 #3831

Screenshots (if applicable)

- Introduced the AnalyzeLogs component for analyzing logs using AI, allowing users to select AI providers and view analysis results.
- Integrated AnalyzeLogs into the ShowDeployment and DockerLogsId components, enabling log analysis for both build and runtime contexts.
- Updated the AI router to include a new endpoint for log analysis, which processes logs and returns structured insights.
- Enhanced the AI provider selection logic to support new providers, including Z.AI and MiniMax.

This feature enhances the user experience by providing actionable insights from logs, improving troubleshooting and operational efficiency.
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Apr 9, 2026
@dosubot dosubot bot added the enhancement New feature or request label Apr 9, 2026
Comment thread apps/dokploy/server/api/routers/ai.ts Outdated
Comment on lines +220 to +221
.mutation(async ({ input }) => {
try {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 security Missing organization ownership check on analyzeLogs

The mutation fetches aiSettings by aiId without verifying that it belongs to the calling user's organization. Any authenticated user can pass an arbitrary aiId from a different organization and the handler will use that org's stored API key to run the analysis, burning their AI credits without consent.

Compare getEnabledProviders, which correctly scopes to ctx.session.activeOrganizationId. The same guard is missing here:

.mutation(async ({ input, ctx }) => {
    const aiSettings = await getAiSettingById(input.aiId);
    if (aiSettings.organizationId !== ctx.session.activeOrganizationId) {
        throw new TRPCError({ code: "FORBIDDEN", message: "Access denied" });
    }
    ...
})

Comment on lines +213 to +218
.input(
z.object({
aiId: z.string().min(1),
logs: z.string().min(1),
context: z.enum(["build", "runtime"]),
}),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 No upper bound on logs payload size

logs: z.string().min(1) places no upper limit. A client could send megabytes of text, inflating AI API costs and potentially hitting provider rate limits. Consider capping it to match the 200-line client-side truncation — something like z.string().min(1).max(50_000).

Suggested change
.input(
z.object({
aiId: z.string().min(1),
logs: z.string().min(1),
context: z.enum(["build", "runtime"]),
}),
logs: z.string().min(1).max(50_000),

{ name: "DeepInfra", apiUrl: "https://api.deepinfra.com/v1/openai" },
{ name: "Ollama", apiUrl: "http://localhost:11434" },
{ name: "OpenRouter", apiUrl: "https://openrouter.ai/api/v1" },
{ name: "Z.AI", apiUrl: "https://api.z.ai/api/paas/v4/" },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Trailing slash on Z.AI base URL may produce double-slash paths

https://api.z.ai/api/paas/v4/ ends with a slash. Depending on how createOpenAICompatible appends paths (e.g. /chat/completions), this can result in …/v4//chat/completions, which some servers reject. Remove the trailing slash for consistency with other providers in this list.

Suggested change
{ name: "Z.AI", apiUrl: "https://api.z.ai/api/paas/v4/" },
{ name: "Z.AI", apiUrl: "https://api.z.ai/api/paas/v4" },

- Corrected the API URL for Z.AI by removing the trailing slash.
- Modified the AI router mutation to include context and added access control to ensure users can only access their organization's AI settings.

These changes improve the accuracy of the API integration and enhance security by enforcing organizational access restrictions.
…trieval

- Implemented a new `readLogs` procedure across various routers (application, compose, libsql, mariadb, mongo, mysql, postgres, redis) to enable users to retrieve logs from containers.
- Each procedure includes input validation for parameters such as `tail`, `since`, and `search`, ensuring robust access control and authorization checks.
- Enhanced the `getContainerLogs` service to support fetching logs from both Docker containers and services, improving the logging capabilities of the application.

This feature enhances observability and troubleshooting for users by providing direct access to container logs.
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Apr 9, 2026
- Updated the `getContainerLogs` function to accept either an application name or container ID, improving flexibility in log retrieval.
- Simplified the command execution logic by consolidating the remote and local execution paths.
- Added a new parameter to directly use container IDs, streamlining the process for users.

These changes enhance the usability of the logging feature, allowing for more efficient access to container logs.
…ompt

- Updated the AnalyzeLogs component to display a message and button for configuring AI providers when none are available, improving user guidance.
- Added a link to the settings page for easy access to AI provider configuration.
- Integrated new icon for the configuration button to enhance UI clarity.

These changes improve the user experience by ensuring users are informed about the need to set up AI providers for log analysis.
@Siumauricio Siumauricio merged commit c1b1937 into canary Apr 9, 2026
4 checks passed
@Siumauricio Siumauricio deleted the feat/ai-improvements branch April 9, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow AI to be used for debugging

1 participant