Skip to content
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

feat: Add GROWI tool #12137

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions api/core/tools/provider/builtin/growi/_assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions api/core/tools/provider/builtin/growi/growi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Any

from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController


class GrowiProvider(BuiltinToolProviderController):
def _validate_credentials(self, credentials: dict[str, Any]) -> None:
return None
35 changes: 35 additions & 0 deletions api/core/tools/provider/builtin/growi/growi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
identity:
author: Shun Miyazawa
name: growi
label:
ja_JP: GROWI
en_US: GROWI
zh_Hans: GROWI
description:
ja_JP: マークダウンを使用したチームコラボレーションソフトウェア
en_US: Team collaboration software using markdown
zh_Hans: 使用 markdown 的团队协作软件
icon: icon.svg
credentials_for_provider:
access_token:
type: secret-input
required: true
label:
en_US: GROWI access token
placeholder:
ja_JP: GROWI アクセストークンを入力してください
en_US: Please input your GROWI access token
zh_Hans: 请输入您的 GROWI 访问令牌
help:
ja_JP: ユーザー設定から API トークンを発行してください
en_US: Please issue an API Token through User Settings
zh_Hans: 请通过用户设置发行 API 令牌
growi_url:
type: text-input
required: true
label:
en_US: GROWI URL
placeholder:
ja_JP: GROWI URL を入力してください
en_US: Please input your GROWI URL
zh_Hans: 请输入您的 GROWI 站点 URL
46 changes: 46 additions & 0 deletions api/core/tools/provider/builtin/growi/tools/create-page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from typing import Any, Union

import requests

from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool


class CreatePageTool(BuiltinTool):
def _invoke(
self, user_id: str, tool_parameters: dict[str, Any]
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
# Validate credentials
growi_url = self.runtime.credentials.get("growi_url")
access_token = self.runtime.credentials.get("access_token")

if growi_url is None or access_token is None:
return self.create_text_message("Growi URL and Access Token is required.")

# Prepate request data
parent_path = tool_parameters.get("parent_path")
path = tool_parameters.get("path")
body = tool_parameters.get("body", "")

data = {
"access_token": access_token,
"body": body,
}

if not (path or parent_path):
data["parentPath"] = "/"
else:
if path:
data["path"] = path
if parent_path:
data["parentPath"] = parent_path

# Send request
try:
endpoint = f"{growi_url}/_api/v3/page"
res = requests.post(endpoint, data=data)
res.raise_for_status()
return self.create_json_message(res.json())
except requests.RequestException as e:
print(f"Failed to create page on GROWI: {e}")
return self.create_text_message(str(e))
53 changes: 53 additions & 0 deletions api/core/tools/provider/builtin/growi/tools/create-page.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
identity:
name: create-page
author: Shun Miyazawa
label:
ja_JP: 新規ページ作成
en_US: Create Page
zh_Hans: 创建页面
description:
human:
ja_JP: GROWI にページを作成します
en_US: Create a page in GROWI
zh_Hans: 在 GROWI 中创建页面
llm: Create a page in GROWI
parameters:
- name: path
type: string
required: false
label:
ja_JP: ページパス
en_US: Page path
zh_Hans: 页面路径
human_description:
ja_JP: ページのパスを指定します。
en_US: The path where the page will be created.
zh_Hans: 指定页面的路径。
llm_description: The path where the page will be created. Must start with forward slash (e.g., /user/page-name)
form: llm
- name: parent_path
type: string
required: false
label:
ja_JP: 親ページパス
en_US: Parent page path
zh_Hans: 父页面路径
human_description:
ja_JP: 親ページのパスを指定します。"path" が指定されている場合は無視されます。
en_US: The path of the parent page. Ignored if "path" is specified.
zh_Hans: 指定父页面的路径。如果指定了“path”,则忽略此参数。
llm_description: The path of the parent page. Must start with forward slash (e.g., /user/parent-page-name)
form: llm
- name: body
type: string
required: false
label:
ja_JP: ページ本文
en_US: Page body
zh_Hans: 页面内容
human_description:
ja_JP: ページの本文を指定します。
en_US: The content of the page
zh_Hans: 页面的内容
llm_description: The content of the page in Markdown format
form: llm
Loading