0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-14 13:58:53 +08:00
discourse/plugins/discourse-ai/lib/agents/tools
Sam 0bad05d036
DEV: Extract reusable PostsFilter into core (#40436)
Promotes the posts query-string filter that previously lived in
discourse-ai's `Research::Filter` to a core `PostsFilter` class so it
can
be shared across core and plugins. The parser gains alias support
(`categories`, `exclude_category`, `exclude_tag`, `created_after`, ...),
`-`/`=`/`-=` exclusion prefixes, an `option_info` helper for
autocomplete,
and an `add_filter`/`remove_filter` extension API backed by a new
`posts_filter_options` plugin modifier.

Consumers are updated to build on the shared class:

* discourse-ai: `Research::Filter` becomes a thin subclass, the
researcher
  tool documents the new exclusion syntax, and the report context
generator builds its relation from a PostsFilter query string instead of
  hand-rolled SQL.
* discourse-assign: registers an `assigned_to:` filter (supporting
  `nobody`, `*` and usernames) and contributes its autocomplete entry.
* discourse-workflows: adds an `action:post` node with create/get/list
operations built on PostsFilter, and extracts a shared `PostHelper`
mixin
  reused by the existing create_post node.

Adds core locale strings and specs for the new class.

We also added two new APIs to node context to facilitate working with
posts:

#### `exec_ctx.create_post`

Creates a post while enforcing workflow actor permissions and preventing
recursive workflow execution.

```rb
post =
  exec_ctx.create_post(
    user: author,
    raw: "Reply body",
    topic_id: topic_id,
    reply_to_post_number: reply_to_post_number,
  )
```

Arguments:

- `user:` required `User` object used as the post author.
- `raw:` required raw post body.
- `topic_id:` required topic id where the post should be created.
- `reply_to_post_number:` optional post number to reply to.

The helper verifies that the author can see the topic, rejects closed or
archived topics, and creates the post with `skip_workflows: true`.

#### `exec_ctx.serialize_post`

Serializes a post into the standard Discourse Workflows post output
shape.

```rb
data =
  exec_ctx.serialize_post(
    post,
    guardian: actor.guardian,
    include_raw: true,
    include_cooked: false,
  )
```

Arguments:

- `post` required `Post` record.
- `guardian:` optional guardian used for permission-aware fields such as
visible tags. Defaults to the system guardian.
- `include_raw:` optional boolean. Defaults to `true`.
- `include_cooked:` optional boolean. Defaults to `false`.

Use this helper whenever a workflow node outputs post data. It keeps
post outputs consistent across action and trigger nodes.

---------

Co-authored-by: discourse-patch-triage[bot] <272280883+discourse-patch-triage[bot]@users.noreply.github.com>
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2026-06-02 14:52:47 +02:00
..
assign.rb
close_topic.rb
create_artifact.rb DEV: Enable Style/RedundantSelf rubocop rule (#40098) 2026-05-19 19:27:45 +02:00
create_image.rb DEV: Enable Style/RedundantBegin rubocop rule (#40096) 2026-05-19 18:44:54 +02:00
custom.rb
db_schema.rb FIX: Data explorer agent reliability for schema and plurality (#40152) 2026-05-19 16:23:17 +08:00
delete_topic.rb
discourse_meta_search.rb DEV: Enable Style/RedundantParentheses rubocop rule (#40095) 2026-05-19 15:48:09 +02:00
edit_category.rb
edit_image.rb
edit_post.rb
edit_tags.rb
flag_post.rb SECURITY: escape LLM triage output in review flag reasons 2026-03-19 15:21:28 +00:00
github_diff.rb
github_file_content.rb
github_search_code.rb DEV: Enable Style/RedundantParentheses rubocop rule (#40095) 2026-05-19 15:48:09 +02:00
github_search_files.rb
google.rb
grant_badge.rb
image.rb DEV: Enable Style/RedundantBegin rubocop rule (#40096) 2026-05-19 18:44:54 +02:00
javascript_evaluator.rb
list_categories.rb
list_reviewables.rb FEATURE: Add review queue tools for AI agents (#38928) 2026-03-30 14:42:54 -03:00
list_tags.rb
lock_post.rb
mark_as_solved.rb
mcp.rb FEATURE: Add MCP server integration to AI agents (#38706) 2026-03-25 17:32:27 +11:00
move_posts.rb
option.rb
perform_reviewable_action.rb FEATURE: Add review queue tools for AI agents (#38928) 2026-03-30 14:42:54 -03:00
random_picker.rb
read.rb
read_artifact.rb
researcher.rb DEV: Extract reusable PostsFilter into core (#40436) 2026-06-02 14:52:47 +02:00
search.rb
search_settings.rb
search_uploaded_documents.rb DEV: Expose agent RAG as a standard tool (#38691) 2026-03-24 10:26:13 -03:00
set_slow_mode.rb
set_topic_timer.rb
setting_context.rb DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
summarize.rb
time.rb
tool.rb DEV: Expose agent RAG as a standard tool (#38691) 2026-03-24 10:26:13 -03:00
unlist_topic.rb
update_artifact.rb DEV: Enable Style/RedundantParentheses rubocop rule (#40095) 2026-05-19 15:48:09 +02:00
web_browser.rb