Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Every integration that calls the REST API directly must send two headers on ever

| header | value |
|---|---|
| `X-TF-Client-Name` | the bare integration token — the same value used for `api_integration` where one exists: `hermes`, `n8n` |
| `X-TF-Client-Name` | the bare integration token — the same value used for `api_integration` where one exists: `dify`, `hermes`, `n8n` |
| `X-TF-Client-Version` | the integration's own published version |

Do not send `X-TF-Request-Origin` yourself; `api` is the transport and the server derives it, and the `tinyfish` SDK already sets its own value. Integrations that wrap the SDK set `TF_CLIENT_NAME` / `TF_CLIENT_VERSION` alongside `TF_API_INTEGRATION` instead — the SDK turns those two into the headers above from `tinyfish>=0.5.0`, and ignores them before that. `langchain` and `google-adk` set only `TF_API_INTEGRATION` today. Without any of this, telemetry cannot tell the integration from a hand-written curl.
Expand Down
1 change: 1 addition & 0 deletions dify/.difyignore
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,4 @@ Thumbs.db
# To prevent packaging repetitively
*.difypkg

tests/
4 changes: 2 additions & 2 deletions dify/manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.0.4
version: 0.0.5
type: plugin
author: tinyfish
name: tinyfish-web-agent
Expand Down Expand Up @@ -32,7 +32,7 @@ plugins:
tags:
- productivity
meta:
version: 0.0.4
version: 0.0.5
Comment thread
londondavila marked this conversation as resolved.
arch:
- amd64
- arm64
Expand Down
1 change: 1 addition & 0 deletions dify/requirements.txt
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 added dify/tests/__init__.py
Empty file.
32 changes: 32 additions & 0 deletions dify/tests/test_headers.py
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,
)
9 changes: 7 additions & 2 deletions dify/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

import httpx

from tools.constants import API_BASE_URL
from tools.constants import API_BASE_URL, PLUGIN_VERSION


class TinyfishMixin:
"""Mixin for TinyFish tools with shared API request logic."""

@property
def _api_headers(self) -> dict[str, str]:
return {"X-API-Key": self.runtime.credentials["api_key"]}
# Without these, telemetry cannot tell the plugin from raw curl.
return {
"X-API-Key": self.runtime.credentials["api_key"],
"X-TF-Client-Name": "dify",
"X-TF-Client-Version": PLUGIN_VERSION,
}

def _tf_request(
self,
Expand Down
18 changes: 18 additions & 0 deletions dify/tools/constants.py
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()