feat(Tools): Refactor the base table plugin (#9182)

Co-authored-by: 黎斌 <libin.23@bytedance.com>
This commit is contained in:
走在修行的大街上 2024-10-22 21:31:34 +08:00 • committed by GitHub
commit a9db06f5e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 1230 additions and 1282 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

View file

@ -1,47 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="240px" height="240px" viewBox="0 0 240 240" enable-background="new 0 0 240 240" xml:space="preserve"> <image id="image0" width="240" height="240" x="0" y="0"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAMAAAAJixmgAAAAIGNIUk0AAHomAACAhAAA+gAAAIDo
AAB1MAAA6mAAADqYAAAXcJy6UTwAAAINUExURQAAAJ9g6qNg6qRd6KNe6aVg6J9g6p9g359a6qRd
66Ne66Re66Rd66Rd66Re7Z9g559g76Ne7aRe6qJd76Fe66Ne66Re66Vd7KNc6aRe66Nd66Re7KRd
66Nc6p9g36Re7KRf7KRe7KNe7KNc76Va6qVd66Ne66Re66Nd6qRb6KRe66Zd66Ve7KJd6aNe66Fe
7KRd6p9Y56Re66Je6qRb6qNe66Re7KNc56Jf6qNe6qRe6qFe6KNe6qRf66Rf66Ne7KNe6qRe6qRd
66Rd7KFe6aNc6qNe6qJd7Z9b6KNd659Z7KNd66Ne6aRe66Re7KNc66Nd66Ne66Jd6qNe6qNc6aJd
6qNd6qRe66Jd7KFe6qJe66Re6qNe66Jd66Jd6aRd6qRd66Va759V6qVd6qFe56Ne6KJd6KRe66Zj
67eB79Gu9eLM+OjX+uXS+dSz9bJ37s6p9LV87q9y7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eIrOKJYGjXb26JWrB1qGndUsUg63+Dt0UxeBI
H41JLQ1sPfOsbotiMJGdWiKYxjKWCY4eaNHNUQu2IoeP6PaoBVMQywUTEEsGW5F9hq9j2eDK1ek5
WzdKLdg6tMNkcQBgsxey3ReVDras51+wdcO44K4AvCuD/KKh5I7+QMCW1fCSkWT76MsBgQ0lHzks
f8+6gvzKMcPI9quvBeitJPL6GyYNs/3mrmC9K+kZOPqWbQba3vl28N6VRBve2ftuRW1rhFd+97H3
3lfj/S8fdLd+WFevKx99/EkQdxwIgiAIgiAIgiAIgiAIgiBB519+T+5Fl+ldNwAAACV0RVh0ZGF0
ZTpjcmVhdGUAMjAyNC0wNi0xM1QwOTozMTowNiswMDowMPHqs70AAAAldEVYdGRhdGU6bW9kaWZ5
ADIwMjQtMDYtMTNUMDk6MzE6MDYrMDA6MDCAtwsBAAAAKHRFWHRkYXRlOnRpbWVzdGFtcAAyMDI0
LTA2LTEzVDA5OjMxOjA2KzAwOjAw16Iq3gAAAABJRU5ErkJggg==" />
</svg>

Before

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -1,8 +1,7 @@
from core.tools.provider.builtin.feishu_base.tools.get_tenant_access_token import GetTenantAccessTokenTool
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
from core.tools.utils.feishu_api_utils import auth
class FeishuBaseProvider(BuiltinToolProviderController):
def _validate_credentials(self, credentials: dict) -> None:
GetTenantAccessTokenTool()
pass
auth(credentials)

View file

@ -5,10 +5,32 @@ identity:
en_US: Feishu Base
zh_Hans: 飞书多维表格
description:
en_US: Feishu Base
zh_Hans: 飞书多维表格
icon: icon.svg
en_US: |
Feishu base, requires the following permissions: bitable:app.
zh_Hans: |
飞书多维表格,需要开通以下权限: bitable:app。
icon: icon.png
tags:
- social
- productivity
credentials_for_provider:
app_id:
type: text-input
required: true
label:
en_US: APP ID
placeholder:
en_US: Please input your feishu app id
zh_Hans: 请输入你的飞书 app id
help:
en_US: Get your app_id and app_secret from Feishu
zh_Hans: 从飞书获取您的 app_id 和 app_secret
url: https://open.larkoffice.com/app
app_secret:
type: secret-input
required: true
label:
en_US: APP Secret
placeholder:
en_US: Please input your app secret
zh_Hans: 请输入你的飞书 app secret

View file

@ -1,56 +0,0 @@
import json
from typing import Any, Union
import httpx
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
class AddBaseRecordTool(BuiltinTool):
def _invoke(
self, user_id: str, tool_parameters: dict[str, Any]
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
url = "https://open.feishu.cn/open-apis/bitable/v1/apps/{app_token}/tables/{table_id}/records"
access_token = tool_parameters.get("Authorization", "")
if not access_token:
return self.create_text_message("Invalid parameter access_token")
app_token = tool_parameters.get("app_token", "")
if not app_token:
return self.create_text_message("Invalid parameter app_token")
table_id = tool_parameters.get("table_id", "")
if not table_id:
return self.create_text_message("Invalid parameter table_id")
fields = tool_parameters.get("fields", "")
if not fields:
return self.create_text_message("Invalid parameter fields")
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}",
}
params = {}
payload = {"fields": json.loads(fields)}
try:
res = httpx.post(
url.format(app_token=app_token, table_id=table_id),
headers=headers,
params=params,
json=payload,
timeout=30,
)
res_json = res.json()
if res.is_success:
return self.create_text_message(text=json.dumps(res_json))
else:
return self.create_text_message(
f"Failed to add base record, status code: {res.status_code}, response: {res.text}"
)
except Exception as e:
return self.create_text_message("Failed to add base record. {}".format(e))

View file

@ -1,66 +0,0 @@
identity:
name: add_base_record
author: Doug Lea
label:
en_US: Add Base Record
zh_Hans: 在多维表格数据表中新增一条记录
description:
human:
en_US: Add Base Record
zh_Hans: |
在多维表格数据表中新增一条记录,详细请参考:https://open.larkoffice.com/document/server-docs/docs/bitable-v1/app-table-record/create
llm: Add a new record in the multidimensional table data table.
parameters:
- name: Authorization
type: string
required: true
label:
en_US: token
zh_Hans: 凭证
human_description:
en_US: API access token parameter, tenant_access_token or user_access_token
zh_Hans: API 的访问凭证参数,tenant_access_token 或 user_access_token
llm_description: API access token parameter, tenant_access_token or user_access_token
form: llm
- name: app_token
type: string
required: true
label:
en_US: app_token
zh_Hans: 多维表格
human_description:
en_US: bitable app token
zh_Hans: 多维表格的唯一标识符 app_token
llm_description: bitable app token
form: llm
- name: table_id
type: string
required: true
label:
en_US: table_id
zh_Hans: 多维表格的数据表
human_description:
en_US: bitable table id
zh_Hans: 多维表格数据表的唯一标识符 table_id
llm_description: bitable table id
form: llm
- name: fields
type: string
required: true
label:
en_US: fields
zh_Hans: 数据表的列字段内容
human_description:
en_US: The fields of the Base data table are the columns of the data table.
zh_Hans: |
要增加一行多维表格记录,字段结构拼接如下:{"多行文本":"多行文本内容","单选":"选项1","多选":["选项1","选项2"],"复选框":true,"人员":[{"id":"ou_2910013f1e6456f16a0ce75ede950a0a"}],"群组":[{"id":"oc_cd07f55f14d6f4a4f1b51504e7e97f48"}],"电话号码":"13026162666"}
当前接口支持的字段类型为:多行文本、单选、条码、多选、日期、人员、附件、复选框、超链接、数字、单向关联、双向关联、电话号码、地理位置。
不同类型字段的数据结构请参考数据结构概述:https://open.larkoffice.com/document/server-docs/docs/bitable-v1/bitable-structure
llm_description: |
要增加一行多维表格记录,字段结构拼接如下:{"多行文本":"多行文本内容","单选":"选项1","多选":["选项1","选项2"],"复选框":true,"人员":[{"id":"ou_2910013f1e6456f16a0ce75ede950a0a"}],"群组":[{"id":"oc_cd07f55f14d6f4a4f1b51504e7e97f48"}],"电话号码":"13026162666"}
当前接口支持的字段类型为:多行文本、单选、条码、多选、日期、人员、附件、复选框、超链接、数字、单向关联、双向关联、电话号码、地理位置。
不同类型字段的数据结构请参考数据结构概述:https://open.larkoffice.com/document/server-docs/docs/bitable-v1/bitable-structure
form: llm

View file

@ -0,0 +1,21 @@
from typing import Any
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
from core.tools.utils.feishu_api_utils import FeishuRequest
class AddRecordsTool(BuiltinTool):
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage:
app_id = self.runtime.credentials.get("app_id")
app_secret = self.runtime.credentials.get("app_secret")
client = FeishuRequest(app_id, app_secret)
app_token = tool_parameters.get("app_token")
table_id = tool_parameters.get("table_id")
table_name = tool_parameters.get("table_name")
records = tool_parameters.get("records")
user_id_type = tool_parameters.get("user_id_type", "open_id")
res = client.add_records(app_token, table_id, table_name, records, user_id_type)
return self.create_json_message(res)

View file

@ -0,0 +1,91 @@
identity:
name: add_records
author: Doug Lea
label:
en_US: Add Records
zh_Hans: 新增多条记录
description:
human:
en_US: Add Multiple Records to Multidimensional Table
zh_Hans: 在多维表格数据表中新增多条记录
llm: A tool for adding multiple records to a multidimensional table. (在多维表格数据表中新增多条记录)
parameters:
- name: app_token
type: string
required: true
label:
en_US: app_token
zh_Hans: app_token
human_description:
en_US: Unique identifier for the multidimensional table, supports inputting document URL.
zh_Hans: 多维表格的唯一标识符,支持输入文档 URL。
llm_description: 多维表格的唯一标识符,支持输入文档 URL。
form: llm
- name: table_id
type: string
required: false
label:
en_US: table_id
zh_Hans: table_id
human_description:
en_US: Unique identifier for the multidimensional table data, either table_id or table_name must be provided, cannot be empty simultaneously.
zh_Hans: 多维表格数据表的唯一标识符,table_id 和 table_name 至少需要提供一个,不能同时为空。
llm_description: 多维表格数据表的唯一标识符,table_id 和 table_name 至少需要提供一个,不能同时为空。
form: llm
- name: table_name
type: string
required: false
label:
en_US: table_name
zh_Hans: table_name
human_description:
en_US: Name of the multidimensional table data, either table_name or table_id must be provided, cannot be empty simultaneously.
zh_Hans: 多维表格数据表的名称,table_name 和 table_id 至少需要提供一个,不能同时为空。
llm_description: 多维表格数据表的名称,table_name 和 table_id 至少需要提供一个,不能同时为空。
form: llm
- name: records
type: string
required: true
label:
en_US: records
zh_Hans: 记录列表
human_description:
en_US: |
List of records to be added in this request. Example value: [{"multi-line-text":"text content","single_select":"option 1","date":1674206443000}]
For supported field types, refer to the integration guide (https://open.larkoffice.com/document/server-docs/docs/bitable-v1/notification). For data structures of different field types, refer to the data structure overview (https://open.larkoffice.com/document/server-docs/docs/bitable-v1/bitable-structure).
zh_Hans: |
本次请求将要新增的记录列表,示例值:[{"多行文本":"文本内容","单选":"选项 1","日期":1674206443000}]。
当前接口支持的字段类型请参考接入指南(https://open.larkoffice.com/document/server-docs/docs/bitable-v1/notification),不同类型字段的数据结构请参考数据结构概述(https://open.larkoffice.com/document/server-docs/docs/bitable-v1/bitable-structure)。
llm_description: |
本次请求将要新增的记录列表,示例值:[{"多行文本":"文本内容","单选":"选项 1","日期":1674206443000}]。
当前接口支持的字段类型请参考接入指南(https://open.larkoffice.com/document/server-docs/docs/bitable-v1/notification),不同类型字段的数据结构请参考数据结构概述(https://open.larkoffice.com/document/server-docs/docs/bitable-v1/bitable-structure)。
form: llm
- name: user_id_type
type: select
required: false
options:
- value: open_id
label:
en_US: open_id
zh_Hans: open_id
- value: union_id
label:
en_US: union_id
zh_Hans: union_id
- value: user_id
label:
en_US: user_id
zh_Hans: user_id
default: "open_id"
label:
en_US: user_id_type
zh_Hans: 用户 ID 类型
human_description:
en_US: User ID type, optional values are open_id, union_id, user_id, with a default value of open_id.
zh_Hans: 用户 ID 类型,可选值有 open_id、union_id、user_id,默认值为 open_id。
llm_description: 用户 ID 类型,可选值有 open_id、union_id、user_id,默认值为 open_id。
form: form

View file

@ -1,41 +1,18 @@
import json
from typing import Any, Union
import httpx
from typing import Any
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
from core.tools.utils.feishu_api_utils import FeishuRequest
class CreateBaseTool(BuiltinTool):
def _invoke(
self, user_id: str, tool_parameters: dict[str, Any]
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
url = "https://open.feishu.cn/open-apis/bitable/v1/apps"
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage:
app_id = self.runtime.credentials.get("app_id")
app_secret = self.runtime.credentials.get("app_secret")
client = FeishuRequest(app_id, app_secret)
access_token = tool_parameters.get("Authorization", "")
if not access_token:
return self.create_text_message("Invalid parameter access_token")
name = tool_parameters.get("name")
folder_token = tool_parameters.get("folder_token")
name = tool_parameters.get("name", "")
folder_token = tool_parameters.get("folder_token", "")
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}",
}
params = {}
payload = {"name": name, "folder_token": folder_token}
try:
res = httpx.post(url, headers=headers, params=params, json=payload, timeout=30)
res_json = res.json()
if res.is_success:
return self.create_text_message(text=json.dumps(res_json))
else:
return self.create_text_message(
f"Failed to create base, status code: {res.status_code}, response: {res.text}"
)
except Exception as e:
return self.create_text_message("Failed to create base. {}".format(e))
res = client.create_base(name, folder_token)
return self.create_json_message(res)

View file

@ -6,32 +6,21 @@ identity:
zh_Hans: 创建多维表格
description:
human:
en_US: Create base
en_US: Create Multidimensional Table in Specified Directory
zh_Hans: 在指定目录下创建多维表格
llm: A tool for create a multidimensional table in the specified directory.
llm: A tool for creating a multidimensional table in a specified directory. (在指定目录下创建多维表格)
parameters:
- name: Authorization
type: string
required: true
label:
en_US: token
zh_Hans: 凭证
human_description:
en_US: API access token parameter, tenant_access_token or user_access_token
zh_Hans: API 的访问凭证参数,tenant_access_token 或 user_access_token
llm_description: API access token parameter, tenant_access_token or user_access_token
form: llm
- name: name
type: string
required: false
label:
en_US: name
zh_Hans: name
zh_Hans: 多维表格 App 名字
human_description:
en_US: Base App Name
zh_Hans: 多维表格App名字
llm_description: Base App Name
en_US: |
Name of the multidimensional table App. Example value: "A new multidimensional table".
zh_Hans: 多维表格 App 名字,示例值:"一篇新的多维表格"。
llm_description: 多维表格 App 名字,示例值:"一篇新的多维表格"。
form: llm
- name: folder_token
@ -39,9 +28,15 @@ parameters:
required: false
label:
en_US: folder_token
zh_Hans: 多维表格App归属文件夹
zh_Hans: 多维表格 App 归属文件夹
human_description:
en_US: Base App home folder. The default is empty, indicating that Base will be created in the cloud space root directory.
zh_Hans: 多维表格App归属文件夹。默认为空,表示多维表格将被创建在云空间根目录。
llm_description: Base App home folder. The default is empty, indicating that Base will be created in the cloud space root directory.
en_US: |
Folder where the multidimensional table App belongs. Default is empty, meaning the table will be created in the root directory of the cloud space. Example values: Fa3sfoAgDlMZCcdcJy1cDFg8nJc or https://svi136aogf123.feishu.cn/drive/folder/Fa3sfoAgDlMZCcdcJy1cDFg8nJc.
The folder_token must be an existing folder and supports inputting folder token or folder URL.
zh_Hans: |
多维表格 App 归属文件夹。默认为空,表示多维表格将被创建在云空间根目录。示例值: Fa3sfoAgDlMZCcdcJy1cDFg8nJc 或者 https://svi136aogf123.feishu.cn/drive/folder/Fa3sfoAgDlMZCcdcJy1cDFg8nJc。
folder_token 必须是已存在的文件夹,支持输入文件夹 token 或者文件夹 URL。
llm_description: |
多维表格 App 归属文件夹。默认为空,表示多维表格将被创建在云空间根目录。示例值: Fa3sfoAgDlMZCcdcJy1cDFg8nJc 或者 https://svi136aogf123.feishu.cn/drive/folder/Fa3sfoAgDlMZCcdcJy1cDFg8nJc。
folder_token 必须是已存在的文件夹,支持输入文件夹 token 或者文件夹 URL。
form: llm

View file

@ -1,48 +0,0 @@
import json
from typing import Any, Union
import httpx
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
class CreateBaseTableTool(BuiltinTool):
def _invoke(
self, user_id: str, tool_parameters: dict[str, Any]
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
url = "https://open.feishu.cn/open-apis/bitable/v1/apps/{app_token}/tables"
access_token = tool_parameters.get("Authorization", "")
if not access_token:
return self.create_text_message("Invalid parameter access_token")
app_token = tool_parameters.get("app_token", "")
if not app_token:
return self.create_text_message("Invalid parameter app_token")
name = tool_parameters.get("name", "")
fields = tool_parameters.get("fields", "")
if not fields:
return self.create_text_message("Invalid parameter fields")
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}",
}
params = {}
payload = {"table": {"name": name, "fields": json.loads(fields)}}
try:
res = httpx.post(url.format(app_token=app_token), headers=headers, params=params, json=payload, timeout=30)
res_json = res.json()
if res.is_success:
return self.create_text_message(text=json.dumps(res_json))
else:
return self.create_text_message(
f"Failed to create base table, status code: {res.status_code}, response: {res.text}"
)
except Exception as e:
return self.create_text_message("Failed to create base table. {}".format(e))

View file

@ -1,106 +0,0 @@
identity:
name: create_base_table
author: Doug Lea
label:
en_US: Create Base Table
zh_Hans: 多维表格新增一个数据表
description:
human:
en_US: Create base table
zh_Hans: |
多维表格新增一个数据表,详细请参考:https://open.larkoffice.com/document/server-docs/docs/bitable-v1/app-table/create
llm: A tool for add a new data table to the multidimensional table.
parameters:
- name: Authorization
type: string
required: true
label:
en_US: token
zh_Hans: 凭证
human_description:
en_US: API access token parameter, tenant_access_token or user_access_token
zh_Hans: API 的访问凭证参数,tenant_access_token 或 user_access_token
llm_description: API access token parameter, tenant_access_token or user_access_token
form: llm
- name: app_token
type: string
required: true
label:
en_US: app_token
zh_Hans: 多维表格
human_description:
en_US: bitable app token
zh_Hans: 多维表格的唯一标识符 app_token
llm_description: bitable app token
form: llm
- name: name
type: string
required: false
label:
en_US: name
zh_Hans: name
human_description:
en_US: Multidimensional table data table name
zh_Hans: 多维表格数据表名称
llm_description: Multidimensional table data table name
form: llm
- name: fields
type: string
required: true
label:
en_US: fields
zh_Hans: fields
human_description:
en_US: Initial fields of the data table
zh_Hans: |
数据表的初始字段,格式为:[{"field_name":"多行文本","type":1},{"field_name":"数字","type":2},{"field_name":"单选","type":3},{"field_name":"多选","type":4},{"field_name":"日期","type":5}]。
field_name:字段名;
type: 字段类型;可选值有
1:多行文本
2:数字
3:单选
4:多选
5:日期
7:复选框
11:人员
13:电话号码
15:超链接
17:附件
18:单向关联
20:公式
21:双向关联
22:地理位置
23:群组
1001:创建时间
1002:最后更新时间
1003:创建人
1004:修改人
1005:自动编号
llm_description: |
数据表的初始字段,格式为:[{"field_name":"多行文本","type":1},{"field_name":"数字","type":2},{"field_name":"单选","type":3},{"field_name":"多选","type":4},{"field_name":"日期","type":5}]。
field_name:字段名;
type: 字段类型;可选值有
1:多行文本
2:数字
3:单选
4:多选
5:日期
7:复选框
11:人员
13:电话号码
15:超链接
17:附件
18:单向关联
20:公式
21:双向关联
22:地理位置
23:群组
1001:创建时间
1002:最后更新时间
1003:创建人
1004:修改人
1005:自动编号
form: llm

View file

@ -0,0 +1,20 @@
from typing import Any
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
from core.tools.utils.feishu_api_utils import FeishuRequest
class CreateTableTool(BuiltinTool):
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage:
app_id = self.runtime.credentials.get("app_id")
app_secret = self.runtime.credentials.get("app_secret")
client = FeishuRequest(app_id, app_secret)
app_token = tool_parameters.get("app_token")
table_name = tool_parameters.get("table_name")
default_view_name = tool_parameters.get("default_view_name")
fields = tool_parameters.get("fields")
res = client.create_table(app_token, table_name, default_view_name, fields)
return self.create_json_message(res)

View file

@ -0,0 +1,61 @@
identity:
name: create_table
author: Doug Lea
label:
en_US: Create Table
zh_Hans: 新增数据表
description:
human:
en_US: Add a Data Table to Multidimensional Table
zh_Hans: 在多维表格中新增一个数据表
llm: A tool for adding a data table to a multidimensional table. (在多维表格中新增一个数据表)
parameters:
- name: app_token
type: string
required: true
label:
en_US: app_token
zh_Hans: app_token
human_description:
en_US: Unique identifier for the multidimensional table, supports inputting document URL.
zh_Hans: 多维表格的唯一标识符,支持输入文档 URL。
llm_description: 多维表格的唯一标识符,支持输入文档 URL。
form: llm
- name: table_name
type: string
required: true
label:
en_US: Table Name
zh_Hans: 数据表名称
human_description:
en_US: |
The name of the data table, length range: 1 character to 100 characters.
zh_Hans: 数据表名称,长度范围:1 字符 ~ 100 字符。
llm_description: 数据表名称,长度范围:1 字符 ~ 100 字符。
form: llm
- name: default_view_name
type: string
required: false
label:
en_US: Default View Name
zh_Hans: 默认表格视图的名称
human_description:
en_US: The name of the default table view, defaults to "Table" if not filled.
zh_Hans: 默认表格视图的名称,不填则默认为"表格"。
llm_description: 默认表格视图的名称,不填则默认为"表格"。
form: llm
- name: fields
type: string
required: true
label:
en_US: Initial Fields
zh_Hans: 初始字段
human_description:
en_US: |
Initial fields of the data table, format: [ { "field_name": "Multi-line Text","type": 1 },{ "field_name": "Number","type": 2 },{ "field_name": "Single Select","type": 3 },{ "field_name": "Multiple Select","type": 4 },{ "field_name": "Date","type": 5 } ]. For field details, refer to: https://open.larkoffice.com/document/server-docs/docs/bitable-v1/app-table-field/guide
zh_Hans: 数据表的初始字段,格式为:[{"field_name":"多行文本","type":1},{"field_name":"数字","type":2},{"field_name":"单选","type":3},{"field_name":"多选","type":4},{"field_name":"日期","type":5}]。字段详情参考:https://open.larkoffice.com/document/server-docs/docs/bitable-v1/app-table-field/guide
llm_description: 数据表的初始字段,格式为:[{"field_name":"多行文本","type":1},{"field_name":"数字","type":2},{"field_name":"单选","type":3},{"field_name":"多选","type":4},{"field_name":"日期","type":5}]。字段详情参考:https://open.larkoffice.com/document/server-docs/docs/bitable-v1/app-table-field/guide
form: llm

View file

@ -1,56 +0,0 @@
import json
from typing import Any, Union
import httpx
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
class DeleteBaseRecordsTool(BuiltinTool):
def _invoke(
self, user_id: str, tool_parameters: dict[str, Any]
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
url = "https://open.feishu.cn/open-apis/bitable/v1/apps/{app_token}/tables/{table_id}/records/batch_delete"
access_token = tool_parameters.get("Authorization", "")
if not access_token:
return self.create_text_message("Invalid parameter access_token")
app_token = tool_parameters.get("app_token", "")
if not app_token:
return self.create_text_message("Invalid parameter app_token")
table_id = tool_parameters.get("table_id", "")
if not table_id:
return self.create_text_message("Invalid parameter table_id")
record_ids = tool_parameters.get("record_ids", "")
if not record_ids:
return self.create_text_message("Invalid parameter record_ids")
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}",
}
params = {}
payload = {"records": json.loads(record_ids)}
try:
res = httpx.post(
url.format(app_token=app_token, table_id=table_id),
headers=headers,
params=params,
json=payload,
timeout=30,
)
res_json = res.json()
if res.is_success:
return self.create_text_message(text=json.dumps(res_json))
else:
return self.create_text_message(
f"Failed to delete base records, status code: {res.status_code}, response: {res.text}"
)
except Exception as e:
return self.create_text_message("Failed to delete base records. {}".format(e))

View file

@ -1,60 +0,0 @@
identity:
name: delete_base_records
author: Doug Lea
label:
en_US: Delete Base Records
zh_Hans: 在多维表格数据表中删除多条记录
description:
human:
en_US: Delete base records
zh_Hans: |
该接口用于删除多维表格数据表中的多条记录,单次调用中最多删除 500 条记录。
llm: A tool for delete multiple records in a multidimensional table data table, up to 500 records can be deleted in a single call.
parameters:
- name: Authorization
type: string
required: true
label:
en_US: token
zh_Hans: 凭证
human_description:
en_US: API access token parameter, tenant_access_token or user_access_token
zh_Hans: API 的访问凭证参数,tenant_access_token 或 user_access_token
llm_description: API access token parameter, tenant_access_token or user_access_token
form: llm
- name: app_token
type: string
required: true
label:
en_US: app_token
zh_Hans: 多维表格
human_description:
en_US: bitable app token
zh_Hans: 多维表格的唯一标识符 app_token
llm_description: bitable app token
form: llm
- name: table_id
type: string
required: true
label:
en_US: table_id
zh_Hans: 多维表格的数据表
human_description:
en_US: bitable table id
zh_Hans: 多维表格数据表的唯一标识符 table_id
llm_description: bitable table id
form: llm
- name: record_ids
type: string
required: true
label:
en_US: record_ids
zh_Hans: record_ids
human_description:
en_US: A list of multiple record IDs to be deleted, for example ["recwNXzPQv","recpCsf4ME"]
zh_Hans: 待删除的多条记录id列表,示例为 ["recwNXzPQv","recpCsf4ME"]
llm_description: A list of multiple record IDs to be deleted, for example ["recwNXzPQv","recpCsf4ME"]
form: llm

View file

@ -1,46 +0,0 @@
import json
from typing import Any, Union
import httpx
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
class DeleteBaseTablesTool(BuiltinTool):
def _invoke(
self, user_id: str, tool_parameters: dict[str, Any]
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
url = "https://open.feishu.cn/open-apis/bitable/v1/apps/{app_token}/tables/batch_delete"
access_token = tool_parameters.get("Authorization", "")
if not access_token:
return self.create_text_message("Invalid parameter access_token")
app_token = tool_parameters.get("app_token", "")
if not app_token:
return self.create_text_message("Invalid parameter app_token")
table_ids = tool_parameters.get("table_ids", "")
if not table_ids:
return self.create_text_message("Invalid parameter table_ids")
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}",
}
params = {}
payload = {"table_ids": json.loads(table_ids)}
try:
res = httpx.post(url.format(app_token=app_token), headers=headers, params=params, json=payload, timeout=30)
res_json = res.json()
if res.is_success:
return self.create_text_message(text=json.dumps(res_json))
else:
return self.create_text_message(
f"Failed to delete base tables, status code: {res.status_code}, response: {res.text}"
)
except Exception as e:
return self.create_text_message("Failed to delete base tables. {}".format(e))

View file

@ -1,48 +0,0 @@
identity:
name: delete_base_tables
author: Doug Lea
label:
en_US: Delete Base Tables
zh_Hans: 删除多维表格中的数据表
description:
human:
en_US: Delete base tables
zh_Hans: |
删除多维表格中的数据表
llm: A tool for deleting a data table in a multidimensional table
parameters:
- name: Authorization
type: string
required: true
label:
en_US: token
zh_Hans: 凭证
human_description:
en_US: API access token parameter, tenant_access_token or user_access_token
zh_Hans: API 的访问凭证参数,tenant_access_token 或 user_access_token
llm_description: API access token parameter, tenant_access_token or user_access_token
form: llm
- name: app_token
type: string
required: true
label:
en_US: app_token
zh_Hans: 多维表格
human_description:
en_US: bitable app token
zh_Hans: 多维表格的唯一标识符 app_token
llm_description: bitable app token
form: llm
- name: table_ids
type: string
required: true
label:
en_US: table_ids
zh_Hans: table_ids
human_description:
en_US: The ID list of the data tables to be deleted. Currently, a maximum of 50 data tables can be deleted at a time. The example is ["tbl1TkhyTWDkSoZ3","tblsRc9GRRXKqhvW"]
zh_Hans: 待删除数据表的id列表,当前一次操作最多支持50个数据表,示例为 ["tbl1TkhyTWDkSoZ3","tblsRc9GRRXKqhvW"]
llm_description: The ID list of the data tables to be deleted. Currently, a maximum of 50 data tables can be deleted at a time. The example is ["tbl1TkhyTWDkSoZ3","tblsRc9GRRXKqhvW"]
form: llm

View file

@ -0,0 +1,20 @@
from typing import Any
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
from core.tools.utils.feishu_api_utils import FeishuRequest
class DeleteRecordsTool(BuiltinTool):
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage:
app_id = self.runtime.credentials.get("app_id")
app_secret = self.runtime.credentials.get("app_secret")
client = FeishuRequest(app_id, app_secret)
app_token = tool_parameters.get("app_token")
table_id = tool_parameters.get("table_id")
table_name = tool_parameters.get("table_name")
record_ids = tool_parameters.get("record_ids")
res = client.delete_records(app_token, table_id, table_name, record_ids)
return self.create_json_message(res)

View file

@ -0,0 +1,86 @@
identity:
name: delete_records
author: Doug Lea
label:
en_US: Delete Records
zh_Hans: 删除多条记录
description:
human:
en_US: Delete Multiple Records from Multidimensional Table
zh_Hans: 删除多维表格数据表中的多条记录
llm: A tool for deleting multiple records from a multidimensional table. (删除多维表格数据表中的多条记录)
parameters:
- name: app_token
type: string
required: true
label:
en_US: app_token
zh_Hans: app_token
human_description:
en_US: Unique identifier for the multidimensional table, supports inputting document URL.
zh_Hans: 多维表格的唯一标识符,支持输入文档 URL。
llm_description: 多维表格的唯一标识符,支持输入文档 URL。
form: llm
- name: table_id
type: string
required: false
label:
en_US: table_id
zh_Hans: table_id
human_description:
en_US: Unique identifier for the multidimensional table data, either table_id or table_name must be provided, cannot be empty simultaneously.
zh_Hans: 多维表格数据表的唯一标识符,table_id 和 table_name 至少需要提供一个,不能同时为空。
llm_description: 多维表格数据表的唯一标识符,table_id 和 table_name 至少需要提供一个,不能同时为空。
form: llm
- name: table_name
type: string
required: false
label:
en_US: table_name
zh_Hans: table_name
human_description:
en_US: Name of the multidimensional table data, either table_name or table_id must be provided, cannot be empty simultaneously.
zh_Hans: 多维表格数据表的名称,table_name 和 table_id 至少需要提供一个,不能同时为空。
llm_description: 多维表格数据表的名称,table_name 和 table_id 至少需要提供一个,不能同时为空。
form: llm
- name: record_ids
type: string
required: true
label:
en_US: Record IDs
zh_Hans: 记录 ID 列表
human_description:
en_US: |
List of IDs for the records to be deleted, example value: ["recwNXzPQv"].
zh_Hans: 删除的多条记录 ID 列表,示例值:["recwNXzPQv"]。
llm_description: 删除的多条记录 ID 列表,示例值:["recwNXzPQv"]。
form: llm
- name: user_id_type
type: select
required: false
options:
- value: open_id
label:
en_US: open_id
zh_Hans: open_id
- value: union_id
label:
en_US: union_id
zh_Hans: union_id
- value: user_id
label:
en_US: user_id
zh_Hans: user_id
default: "open_id"
label:
en_US: user_id_type
zh_Hans: 用户 ID 类型
human_description:
en_US: User ID type, optional values are open_id, union_id, user_id, with a default value of open_id.
zh_Hans: 用户 ID 类型,可选值有 open_id、union_id、user_id,默认值为 open_id。
llm_description: 用户 ID 类型,可选值有 open_id、union_id、user_id,默认值为 open_id。
form: form

Some files were not shown because too many files have changed in this diff Show more