-
Notifications
You must be signed in to change notification settings - Fork 2
feat(dify-plugin): port external PRs #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a649b99
fix(dify-plugin): allow full port range and tolerate blank numeric fo…
mislavivanda efdb9af
fix(dify-plugin): add 100MB file-size guards to upload and download
mislavivanda cc427b3
perf(dify-plugin): cache the Daytona client per credentials + broaden…
mislavivanda 284a831
feat(dify-plugin): run_command via process.exec with cwd/env/timeout
mislavivanda 3064f14
feat(dify-plugin): deliver run_code chart PNGs as image blobs
mislavivanda 229b97f
feat(dify-plugin): add in-sandbox file operation tools
mislavivanda 055cd7a
feat(dify-plugin): add git clone and sandbox management tools
mislavivanda a5b8ec5
feat(dify-plugin): add background-service tools (start_service, get_s…
mislavivanda 260bafe
fix(dify-plugin): align ported tools with current Daytona SDK (0.193+)
mislavivanda 0159592
fix(dify-plugin): enforce MAX_FILE_SIZE across read/write/upload
mislavivanda 85ed15a
fix(dify-plugin): redact clone URL credentials and drop branch when c…
mislavivanda 55c580e
fix(dify-plugin): make list_sandboxes actually cap results and valida…
mislavivanda 4c3aabb
fix(dify-plugin): stop sandbox before archiving and use shared get_sa…
mislavivanda 4bf53f6
fix(dify-plugin): use unique session ids and clean up on service laun…
mislavivanda 211b610
fix(dify-plugin): reject negative run_command timeouts
mislavivanda 147e5c1
fix(dify-plugin): clearer service log fallback text and stream joining
mislavivanda dd93e82
fix(dify-plugin): prevent credential cache key collisions
mislavivanda efb0550
docs(dify-plugin): align tool metadata and README with actual behavior
mislavivanda 29224ee
docs(dify-plugin): document run_code chart output
mislavivanda 89bb634
fix(dify-plugin): redact clone URL userinfo without corrupting IPv6/port
mislavivanda 61d38ce
fix(dify-plugin): make archiving an already-archived sandbox a no-op
mislavivanda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from collections.abc import Generator | ||
| from typing import Any | ||
|
|
||
| from dify_plugin import Tool | ||
| from dify_plugin.entities.tool import ToolInvokeMessage | ||
|
|
||
| from _client import build_client, get_sandbox | ||
|
|
||
|
|
||
| class FindInFilesTool(Tool): | ||
| def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage]: | ||
| sandbox_id = tool_parameters.get("sandbox_id") | ||
| if not sandbox_id: | ||
| raise ValueError("sandbox_id is required") | ||
|
|
||
| path = tool_parameters.get("path") | ||
| if not path: | ||
| raise ValueError("path is required") | ||
|
|
||
| pattern = tool_parameters.get("pattern") | ||
| if not pattern: | ||
| raise ValueError("pattern is required") | ||
|
|
||
| daytona = build_client(self.runtime.credentials) | ||
| sandbox = get_sandbox(daytona, sandbox_id) | ||
| # find_files returns list[Match]; each Match has flat .file / .line / .content | ||
| results = sandbox.fs.find_files(path, pattern) | ||
|
mislavivanda marked this conversation as resolved.
|
||
|
|
||
| matches = [ | ||
| { | ||
| "file": m.file, | ||
| "line_number": m.line, | ||
| "line_content": m.content, | ||
| } | ||
| for m in results | ||
| ] | ||
|
|
||
| yield self.create_json_message({ | ||
| "sandbox_id": sandbox_id, | ||
| "path": path, | ||
| "pattern": pattern, | ||
| "matches": matches, | ||
| "count": len(matches), | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| identity: | ||
| name: find_in_files | ||
| author: daytonaio | ||
| label: | ||
| en_US: Find in Files | ||
| zh_Hans: Find in Files | ||
| ja_JP: Find in Files | ||
| pt_BR: Find in Files | ||
| description: | ||
| human: | ||
| en_US: Search for a text pattern inside file contents in a Daytona sandbox (like grep). | ||
| zh_Hans: Search for a text pattern inside file contents in a Daytona sandbox (like grep). | ||
| ja_JP: Search for a text pattern inside file contents in a Daytona sandbox (like grep). | ||
| pt_BR: Search for a text pattern inside file contents in a Daytona sandbox (like grep). | ||
| llm: Search for a text pattern inside the contents of files within an existing Daytona sandbox. Returns matching results with file path, line number, and matching line content. Similar to running grep recursively. Requires a sandbox_id. | ||
| parameters: | ||
| - name: sandbox_id | ||
| type: string | ||
| required: true | ||
| label: | ||
| en_US: Sandbox ID | ||
| zh_Hans: Sandbox ID | ||
| ja_JP: Sandbox ID | ||
| pt_BR: Sandbox ID | ||
| human_description: | ||
| en_US: The ID of the sandbox to search within. | ||
| zh_Hans: The ID of the sandbox to search within. | ||
| ja_JP: The ID of the sandbox to search within. | ||
| pt_BR: The ID of the sandbox to search within. | ||
| llm_description: The ID of the Daytona sandbox to search within. | ||
| form: llm | ||
| - name: path | ||
| type: string | ||
| required: true | ||
| label: | ||
| en_US: Path | ||
| zh_Hans: Path | ||
| ja_JP: Path | ||
| pt_BR: Path | ||
| human_description: | ||
| en_US: 'Absolute directory path inside the sandbox to search within (e.g. /home/daytona).' | ||
| zh_Hans: 'Absolute directory path inside the sandbox to search within (e.g. /home/daytona).' | ||
| ja_JP: 'Absolute directory path inside the sandbox to search within (e.g. /home/daytona).' | ||
| pt_BR: 'Absolute directory path inside the sandbox to search within (e.g. /home/daytona).' | ||
| llm_description: 'Absolute directory path inside the sandbox to search within (e.g. "/home/daytona", "/tmp", "/").' | ||
| form: llm | ||
| - name: pattern | ||
| type: string | ||
| required: true | ||
| label: | ||
| en_US: Pattern | ||
| zh_Hans: Pattern | ||
| ja_JP: Pattern | ||
| pt_BR: Pattern | ||
| human_description: | ||
| en_US: 'Text pattern to search for inside file contents.' | ||
| zh_Hans: 'Text pattern to search for inside file contents.' | ||
| ja_JP: 'Text pattern to search for inside file contents.' | ||
| pt_BR: 'Text pattern to search for inside file contents.' | ||
| llm_description: 'Text pattern to search for inside file contents (e.g. "def main", "ERROR", "TODO").' | ||
| form: llm | ||
| extra: | ||
| python: | ||
| source: tools/find_in_files.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| from collections.abc import Generator | ||
| from typing import Any | ||
|
|
||
| from dify_plugin import Tool | ||
| from dify_plugin.entities.tool import ToolInvokeMessage | ||
|
|
||
| from _client import build_client, get_sandbox | ||
|
|
||
|
|
||
| class GetServiceLogsTool(Tool): | ||
| def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage]: | ||
| sandbox_id = tool_parameters.get("sandbox_id") | ||
| if not sandbox_id: | ||
| raise ValueError("sandbox_id is required") | ||
|
|
||
| session_id = tool_parameters.get("session_id") | ||
| if not session_id: | ||
| raise ValueError("session_id is required") | ||
|
|
||
| cmd_id = tool_parameters.get("cmd_id") or None | ||
|
|
||
| daytona = build_client(self.runtime.credentials) | ||
| sandbox = get_sandbox(daytona, sandbox_id) | ||
|
|
||
| if not cmd_id: | ||
| session = sandbox.process.get_session(session_id) | ||
| commands = getattr(session, "commands", None) or [] | ||
| if commands: | ||
| cmd_id = getattr(commands[-1], "id", None) | ||
| if not cmd_id: | ||
| raise ValueError( | ||
| f"Could not determine cmd_id for session '{session_id}'. " | ||
| "Provide cmd_id explicitly (from start_service output)." | ||
| ) | ||
|
|
||
| logs = sandbox.process.get_session_command_logs(session_id, cmd_id) | ||
|
mislavivanda marked this conversation as resolved.
|
||
|
|
||
| stdout = getattr(logs, "stdout", None) or "" | ||
| stderr = getattr(logs, "stderr", None) or "" | ||
| output = getattr(logs, "output", None) or "" | ||
| if output: | ||
| combined = output | ||
| elif stdout and stderr: | ||
| # Join the two streams with a single newline, without doubling one | ||
| # that stdout already ends with. | ||
| separator = "" if stdout.endswith("\n") else "\n" | ||
| combined = stdout + separator + stderr | ||
| else: | ||
| combined = stdout or stderr | ||
|
|
||
| yield self.create_text_message(combined or "(no output)") | ||
| yield self.create_json_message({ | ||
| "session_id": session_id, | ||
| "cmd_id": cmd_id, | ||
| "sandbox_id": sandbox_id, | ||
| "stdout": stdout, | ||
| "stderr": stderr, | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.