### Install just with uv Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/README.md Installs the 'just' command runner using the 'uv' package manager. This is a common setup step for development. ```bash uv tool install rust-just ``` -------------------------------- ### Install and Manage Git Hooks with Prek Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/CONTRIBUTING.md Use 'uv run prek install' to install the Git hooks managed by Prek. Other commands allow running, listing, or validating Prek configurations. ```bash uv run prek install ``` ```bash uv run prek run -a ``` ```bash uv run prek list ``` ```bash uv run prek validate-config ``` -------------------------------- ### Bootstrap Development Environment Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/CONTRIBUTING.md Run 'just dev' to set up the development environment, which includes syncing dependencies and installing Git hooks. Optionally, activate the virtual environment for interactive work. ```bash just dev # optional for interactive work source .venv/bin/activate ``` -------------------------------- ### Run All Tests Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/AGENTS.md Execute all tests in the project. Use this to ensure the integrity of the SDK and examples. ```bash just test ``` -------------------------------- ### Install Plugin Dependencies Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/examples/notion_datasource/GUIDE.md Install the required Python dependencies for Dify Plugin development using `uv sync`. Add custom dependencies to `pyproject.toml` and update `uv.lock` with `uv lock`. ```bash uv sync ``` -------------------------------- ### Run Dify Plugin Locally Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/examples/notion_datasource/GUIDE.md Execute this command to start your Dify plugin for local debugging. Ensure your .env file is configured correctly. ```bash python -m main ``` -------------------------------- ### Branch Name Examples Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/CONTRIBUTING.md Examples of branch names that align with the conventional commit vocabulary. These names should reflect the type and scope of the changes being made. ```text feat/model-polling-validation fix/runtime-session-cleanup docs/contributing-guide ``` -------------------------------- ### Python SDK Version Constraint Example Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/README.md Example of how to specify version constraints for the dify_plugin SDK in a Python project. It allows patch and minor updates but prevents major version changes. ```python dify_plugin >= 0.8 ``` -------------------------------- ### Chat Functionality Setup Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/examples/neko/endpoints/girls.html Sets up event listeners for sending messages and resetting the conversation. It retrieves the bot name and conversation ID from the environment and local storage, respectively. ```javascript const botName = '{{ bot_name }}'; let conversationId = localStorage.getItem('conversation_id') || ''; const chatLog = document.getElementById('chat-log'); const userInput = document.getElementById('user-input'); const sendBtn = document.getElementById('send-btn'); const resetBtn = document.getElementById('reset-btn'); sendBtn.addEventListener('click', sendMessage); userInput.addEventListener('keypress', function (event) { if (event.key === 'Enter') { sendMessage(); } }); resetBtn.addEventListener('click', resetConversation); ``` -------------------------------- ### Conventional Commit Examples Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/CONTRIBUTING.md Examples of valid conventional commit messages required for Git commits and pull request titles. These follow a specific type-scope: description format. ```text feat(model): add polling result validation fix(runtime): close sessions after stream errors docs(contributing): clarify local validation refactor(server)!: remove deprecated transport entrypoint ``` -------------------------------- ### Recommended Local Development Sequence Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/CONTRIBUTING.md Follow this sequence for most changes to ensure code quality and build readiness before submitting a pull request. ```bash just check just test just build ``` -------------------------------- ### Build Source and Wheel Distributions Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/AGENTS.md Create distributable packages for the Python SDK. This is typically done before releasing a new version. ```bash just build ``` -------------------------------- ### Generate Schema Documentation Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/AGENTS.md Generate documentation for the SDK's schema. This is useful for understanding the structure and configuration of plugins. ```bash just docs ``` -------------------------------- ### Package Dify Plugin Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/examples/notion_datasource/GUIDE.md Run this command to package your Dify plugin into a .difypkg file for submission to the Marketplace. Replace ./ROOT_DIRECTORY_OF_YOUR_PLUGIN with the actual path to your plugin's root directory. ```bash dify-plugin plugin package ./ROOT_DIRECTORY_OF_YOUR_PLUGIN ``` -------------------------------- ### Development Commands Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/CONTRIBUTING.md Run these commands for normal development tasks like formatting, linting, checking, testing, and building. ```bash just format ``` ```bash just lint ``` ```bash just check ``` ```bash just test ``` ```bash just docs ``` ```bash just build ``` ```bash just clean ``` -------------------------------- ### Check Lockfile, Formatting, and Linting Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/AGENTS.md Perform comprehensive checks on the project's code quality and dependencies. This is a recommended step before committing changes. ```bash just check ``` -------------------------------- ### Sync Default Dev Dependencies Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/AGENTS.md Synchronize development dependencies. Use this to set up or update your local development environment. ```bash just dev ``` -------------------------------- ### Common Dify Plugin Development Commands Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/README.md Provides essential commands for local development, including dependency syncing, code checking, testing, and building. ```bash just dev ``` ```bash just check ``` ```bash just test ``` ```bash just build ``` -------------------------------- ### Targeted Tool Usage with UV Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/CONTRIBUTING.md Execute specific development tools like Ruff, Pytest, or Prek directly using 'uv run' for targeted tasks. This is useful when not using the 'just' command. ```bash uv run ruff check src/dify_plugin/path.py ``` ```bash uv run pytest tests/path/test_file.py -k keyword ``` ```bash uv run prek run -a ``` -------------------------------- ### Apply Formatting Fixes Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/AGENTS.md Automatically apply code formatting fixes to the project. Ensures consistent code style across the repository. ```bash just format ``` -------------------------------- ### Run Specific Test Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/AGENTS.md Execute a single test file. Useful for focused debugging during development. ```bash uv run pytest tests/specific_test.py ``` -------------------------------- ### Bump Project Version with uv Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/CONTRIBUTING.md Use 'uv version' commands to increment the project version by patch, minor, or major. These commands update the version in pyproject.toml without immediately syncing. ```bash uv version --no-sync --bump patch uv version --no-sync --bump minor uv version --no-sync --bump major ``` -------------------------------- ### Initialize Live2D Widget Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/examples/neko/endpoints/girls.html Initializes the Live2D widget with specified model and display settings. It uses a model map for different character models and saves the selected model in local storage. ```javascript const modelMap = { 'koharu': "https://unpkg.com/live2d-widget-model-koharu@1.0.5/assets/koharu.model.json", 'haruto': "https://unpkg.com/live2d-widget-model-haruto@1.0.5/assets/haruto.model.json", 'chitose': "https://unpkg.com/live2d-widget-model-chitose@1.0.5/assets/chitose.model.json", 'miku': "https://unpkg.com/live2d-widget-model-miku@1.0.5/assets/miku.model.json", 'shizuku': "https://unpkg.com/live2d-widget-model-shizuku@1.0.5/assets/shizuku.model.json" }; const modelSelect = document.getElementById('model-select'); const savedModel = localStorage.getItem('live2d_model') || 'koharu'; modelSelect.value = savedModel; function initLive2D(modelName) { if (window.L2Dwidget) { L2Dwidget.init({ "model": { "jsonPath": modelMap[modelName], "scale": 1 }, "display": { "position": "right", "width": 150, "height": 300, "hOffset": 0, "vOffset": -20 }, "mobile": { "show": true, "scale": 0.5 }, "react": { "opacityDefault": 0.7, "opacityOnHover": 0.2 } }); } } initLive2D(savedModel); modelSelect.addEventListener('change', (e) => { const modelName = e.target.value; localStorage.setItem('live2d_model', modelName); window.location.reload(); }); ``` -------------------------------- ### Theme Setting Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/examples/neko/endpoints/girls.html Applies a selected theme to the document by setting a data-theme attribute. The chosen theme is persisted in local storage. ```javascript const themeSelect = document.getElementById('theme-select'); const savedTheme = localStorage.getItem('theme') || 'pastel'; document.documentElement.setAttribute('data-theme', savedTheme); themeSelect.value = savedTheme; themeSelect.addEventListener('change', (e) => { const theme = e.target.value; document.documentElement.setAttribute('data-theme', theme); localStorage.setItem('theme', theme); }); ``` -------------------------------- ### Check Linting Only Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/AGENTS.md Run only the linter to check for code style issues without checking formatting or lockfiles. ```bash just lint ``` -------------------------------- ### Advanced Text-to-Speech (TTS) with Concurrency and Order Guarantee Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/examples/neko/endpoints/girls.html Manages concurrent TTS requests (up to 5) and ensures sequential playback of audio segments. It uses an AudioContext, a playback queue, and pending segment tracking to maintain order and buffer audio incrementally. ```javascript const audioContext = new (window.AudioContext || window.webkitAudioContext)(); let currentAudioSource = null; let isPlaying = false; // ---- Concurrency Control ---- const MAX_CONCURRENT_TTS = 5; let currentTtsRequests = 0; // Number of TTS requests currently in progress let ttsRequestQueue = []; // Queue for pending TTS requests // ---- Playback Queue (Sequential) + Segment ID Guarantee ---- let ttsPlaybackQueue = []; // Queue for segments to be played let pendingSegments = {}; // segmentId -> { text, buffer, ready } let globalSegmentId = 0; // Auto-incrementing segment ID let lastPlayedId = -1; // ID of the last played segment // ---- SSE Incremental Buffering ---- let accumulatedSseBuffer = ''; const MIN_LENGTH = 20; // Force flush at least every 20 characters const SPLIT_PATTERN = /[。.!?]/; // Sentence terminators // ---- Sequential Playback Queue: Plays one at a time ---- function processPlaybackQueue() { if (isPlaying || ttsPlaybackQueue.length === 0) return; const item = ttsPlaybackQueue.shift(); if (!item.buffer) return; // Should not happen theoretically isPlaying = true; currentAudioSource = audioContext.createBufferSource(); currentAudioSource.buffer = item.buffer; currentAudioSource.connect(audioContext.destination); currentAudioSource.onended = () => { isPlaying = false; processPlaybackQueue(); }; currentAudioSource.start(); } // ---- When a segment's TTS buffer is ready, attempt to advance playback ---- function attemptQueuePlay() { // Continuously check if segment `lastPlayedId + 1` is ready while (true) { const nextId = lastPlayedId + 1; if (!pendingSegments[nextId]) { break; // Segment not yet received } if (!pendingSegments[nextId].ready) { break; // Segment not yet decoded } // This segment can be played const seg = pendingSegments[nextId]; lastPlayedId++; // Add to playback queue ttsPlaybackQueue.push({ buffer: seg.buffer }); // Remove from pending segments delete pendingSegments[nextId]; } // After checking, attempt to play from the queue processPlaybackQueue(); } // ---- Initiate concurrent TTS requests with limits ---- function limitedFetchTtsBuffer(text) { return new Promise((resolve, reject) => { ttsRequestQueue.push({ text, resolve, reject }); tryStartNextTtsRequest(); }); } function tryStartNextTtsRequest() { if (ttsRequestQueue.length === 0) return; if (currentTtsRequests >= MAX_CONCURRENT_TTS) return; const { text, resolve, reject } = ttsRequestQueue.shift(); currentTtsRequests++; fetchTtsBuffer(text) .then((buf) => { resolve(buf); currentTtsRequests--; tryStartNextTtsRequest(); // Fetch the next one }) .catch((err) => { reject(err); currentTtsRequests--; tryStartNextTtsRequest(); }); } // ---- Actual TTS fetch function (implementation not shown) ---- async function fetchTtsBuffer(text) { // Placeholder for actual TTS API call console.log('Fetching TTS for:', text); // Simulate network delay and return a dummy buffer await new Promise(resolve => setTimeout(resolve, 500)); // In a real scenario, this would return an ArrayBuffer return new ArrayBuffer(1024); // Dummy buffer } ``` -------------------------------- ### Remove Local Build/Test Artifacts Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/AGENTS.md Clean up generated files from builds and tests. Use this to ensure a fresh build environment or to free up disk space. ```bash just clean ``` -------------------------------- ### Subscribe to Security Guardrails Events Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/examples/github_trigger/README.md Set up the GitHub Trigger to monitor security-related events such as code scanning alerts, Dependabot alerts, and secret scanning alerts. You can filter these alerts by severity, state, affected branch, or specific subtypes for secret scanning. ```yaml events: code_scanning_alert, dependabot_alert, secret_scanning severity: high state: open branch: main subtypes: "push,pull_request" ``` -------------------------------- ### Detect Branch Creation and Deletion Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/examples/github_trigger/README.md Configure the GitHub Trigger to detect when new branches are created or existing branches are deleted. This is achieved by subscribing to the 'ref_change' event and specifying 'create' and 'delete' as event types, with a filter for 'branch' as the reference type. ```yaml events: ref_change event_types: create,delete ref_type: branch ``` -------------------------------- ### Subscribe to PR Review Automation Source: https://github.com/langgenius/dify-plugin-sdks/blob/main/examples/github_trigger/README.md Configure the GitHub Trigger to receive events related to pull request reviews. This includes pull request events, review events, and review comment events. You can filter these events by specific review states, reviewers, authors, or content within the review body. ```yaml events: pull_request, pull_request_review, pull_request_review_comment actions: review_submitted, review_requested, review_request_removed reviewer: "your-github-username" author: "another-github-username" body_contains: "LGTM" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.