-
Notifications
You must be signed in to change notification settings - Fork 8
feat(dify): identify plugin requests with X-TF-Client-Name/Version #36
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
6 commits
Select commit
Hold shift + click to select a range
e54e0fe
feat(dify): identify plugin requests with X-TF-Client-Name/Version
londondavila d86135f
chore(dify): keep tests out of the .difypkg, make the version test real
londondavila 3304a8c
test(dify): anchor manifest version check to column 0
londondavila b7947fd
refactor(dify): bare client token; parse the manifest with yaml
londondavila a2f5f1e
Merge remote-tracking branch 'origin/main' into london/dify-client-he…
londondavila 29de342
docs: put dify back in the header-contract table
londondavila 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,3 +182,4 @@ Thumbs.db | |
| # To prevent packaging repetitively | ||
| *.difypkg | ||
|
|
||
| tests/ | ||
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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| dify_plugin>=0.4.0,<0.7.0 | ||
| pyyaml~=6.0 |
Empty file.
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,32 @@ | ||
| import re | ||
| from pathlib import Path | ||
| from types import SimpleNamespace | ||
|
|
||
| from tools.base import TinyfishMixin | ||
| from tools.constants import PLUGIN_VERSION | ||
|
|
||
| MANIFEST = Path(__file__).resolve().parents[1] / "manifest.yaml" | ||
|
|
||
|
|
||
| def _tool() -> TinyfishMixin: | ||
| tool = TinyfishMixin() | ||
| tool.runtime = SimpleNamespace(credentials={"api_key": "tf_test"}) # type: ignore[attr-defined] | ||
| return tool | ||
|
|
||
|
|
||
| def test_headers_identify_the_plugin() -> None: | ||
| headers = _tool()._api_headers | ||
| assert headers["X-API-Key"] == "tf_test" | ||
| assert headers["X-TF-Client-Name"] == "dify" | ||
| assert headers["X-TF-Client-Version"] == PLUGIN_VERSION | ||
|
|
||
|
|
||
| def test_plugin_version_is_a_real_release_version() -> None: | ||
| # The publish workflow greps `^version:` — same anchor the constant uses. | ||
| assert re.fullmatch(r"\d+\.\d+\.\d+", PLUGIN_VERSION), PLUGIN_VERSION | ||
| # Column 0 only: meta.version is indented and is the manifest-format version. | ||
| assert re.search( | ||
| rf"^version: {re.escape(PLUGIN_VERSION)}$", | ||
| MANIFEST.read_text(encoding="utf-8"), | ||
| re.MULTILINE, | ||
| ) |
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 |
|---|---|---|
| @@ -1 +1,19 @@ | ||
| from pathlib import Path | ||
|
|
||
| import yaml | ||
|
|
||
| API_BASE_URL = "https://agent.tinyfish.ai" | ||
|
|
||
| # Top-level `version` is the plugin; `meta.version` is the manifest format. | ||
| _MANIFEST = Path(__file__).resolve().parents[1] / "manifest.yaml" | ||
|
|
||
|
|
||
| def _manifest_version() -> str: | ||
| try: | ||
| version = yaml.safe_load(_MANIFEST.read_text(encoding="utf-8")).get("version") | ||
| except (OSError, yaml.YAMLError, AttributeError): | ||
| version = None | ||
| return str(version) if version else "0+unknown" | ||
|
|
||
|
|
||
| PLUGIN_VERSION = _manifest_version() |
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.