12 tools for the new Confluence toolkit. | Name | Description | |----------------------------------|------------------------------------------------------------------------------------| | Confluence.CreatePage | Create a new page at the root of the given space. | | Confluence.UpdatePageContent | Update a page's content. | | Confluence.RenamePage | Rename a page by changing its title. | | Confluence.GetPage | Retrieve a SINGLE page's content by its ID or title. | | Confluence.GetPagesById | Get the content of MULTIPLE pages by their ID in a single efficient request. | | Confluence.ListPages | Get the content of multiple pages by their ID. | | Confluence.ListAttachments | List attachments in a workspace. | | Confluence.GetAttachmentsForPage | Get attachments for a page by its ID or title. | | Confluence.SearchContent | Search for content in Confluence. | | Confluence.GetSpace | Get the details of a space by its ID or key. | | Confluence.ListSpaces | List all spaces sorted by name in ascending order. | | Confluence.GetSpaceHierarchy | Retrieve the full hierarchical structure of a Confluence space as a tree structure.| ### Confluence Clients Confluence has deprecated most of their V1 endpoints, so most of the tools use V2. However, we still need a V1 client to support search. The V1 search API has not been deprecated yet, because there is no V2 equivalent. But we need to be aware in the future for when this deprecation happens. ### Future work * Content of pages are returned in the Confluence `storage` format. This is the format that Confluence uses to store pages internally. We should understand the storage format more deeply, and write utility function to transform this format into plain text. * Better protections against extremely large pages. I've tested up to 6,000 word pages. * Tools for blog posts * Tool for getting the children of a page. (`get_space_hierarchy` will suffice for now) * Allow for numerical titles
69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
from typing import Annotated
|
|
|
|
from arcade.sdk import ToolContext, tool
|
|
from arcade.sdk.auth import Atlassian
|
|
|
|
from arcade_confluence.client import ConfluenceClientV2
|
|
from arcade_confluence.enums import AttachmentSortOrder
|
|
from arcade_confluence.utils import remove_none_values
|
|
|
|
|
|
@tool(
|
|
requires_auth=Atlassian(
|
|
scopes=["read:attachment:confluence"],
|
|
)
|
|
)
|
|
async def list_attachments(
|
|
context: ToolContext,
|
|
sort_order: Annotated[
|
|
AttachmentSortOrder,
|
|
"The order of the attachments to sort by. Defaults to created-date-newest-to-oldest",
|
|
] = AttachmentSortOrder.CREATED_DATE_DESCENDING,
|
|
limit: Annotated[
|
|
int, "The maximum number of attachments to return. Defaults to 25. Max is 250"
|
|
] = 25,
|
|
pagination_token: Annotated[
|
|
str | None,
|
|
"The pagination token to use for the next page of results",
|
|
] = None,
|
|
) -> Annotated[dict, "The attachments"]:
|
|
"""List attachments in a workspace"""
|
|
client = ConfluenceClientV2(context.get_auth_token_or_empty())
|
|
params = remove_none_values({
|
|
"sort": sort_order.to_api_value(),
|
|
"limit": max(1, min(limit, 250)),
|
|
"cursor": pagination_token,
|
|
})
|
|
attachments = await client.get("attachments", params=params)
|
|
return client.transform_get_attachments_response(attachments)
|
|
|
|
|
|
@tool(
|
|
requires_auth=Atlassian(
|
|
scopes=["read:attachment:confluence"],
|
|
)
|
|
)
|
|
async def get_attachments_for_page(
|
|
context: ToolContext,
|
|
page_identifier: Annotated[str, "The ID or title of the page to get attachments for"],
|
|
limit: Annotated[
|
|
int, "The maximum number of attachments to return. Defaults to 25. Max is 250"
|
|
] = 25,
|
|
pagination_token: Annotated[
|
|
str | None,
|
|
"The pagination token to use for the next page of results",
|
|
] = None,
|
|
) -> Annotated[dict, "The attachments"]:
|
|
"""Get attachments for a page by its ID or title.
|
|
|
|
If a page title is provided, then the first page with an exact matching title will be returned.
|
|
"""
|
|
client = ConfluenceClientV2(context.get_auth_token_or_empty())
|
|
page_id = await client.get_page_id(page_identifier)
|
|
|
|
params = remove_none_values({
|
|
"limit": max(1, min(limit, 250)),
|
|
"cursor": pagination_token,
|
|
})
|
|
attachments = await client.get(f"pages/{page_id}/attachments", params=params)
|
|
return client.transform_get_attachments_response(attachments)
|