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
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
..
artifact_update_strategies DEV: Enable Style/RedundantBegin rubocop rule (#40096) 2026-05-19 18:44:54 +02:00
tool_runner DEV: Enable Style/RedundantSelf rubocop rule (#40098) 2026-05-19 19:27:45 +02:00
tools DEV: Extract reusable PostsFilter into core (#40436) 2026-06-02 14:52:47 +02:00
agent.rb FEATURE: Add agent-backed sentiment classification (#40136) 2026-05-26 10:32:54 -03:00
artist.rb
bot.rb
bot_context.rb FIX: Ensure that the current user's guardian is used when running AI tools tests. (#38676) 2026-04-29 16:25:52 -03:00
chat_thread_titler.rb
concept_deduplicator.rb
concept_finder.rb
concept_matcher.rb
content_creator.rb
creative.rb
custom_prompt.rb
designer.rb
discourse_helper.rb
discover.rb
emotion_classifier.rb FEATURE: Add agent-backed sentiment classification (#40136) 2026-05-26 10:32:54 -03:00
forum_researcher.rb FEATURE: Support subcategories and IDs in researcher category filter (#39877) 2026-05-12 09:27:57 +10:00
general.rb
github_helper.rb
image_captioner.rb
locale_detector.rb DEV: Also pass configured supported locales into the prompt for language detection (#40029) 2026-05-14 21:15:26 +08:00
markdown_table_generator.rb
post_illustrator.rb
post_raw_translator.rb DEV: Update post translation prompts for german cases (#40112) 2026-05-18 20:31:13 +08:00
proofreader.rb FIX: Don't change quoted content whe proofreading (#38934) 2026-03-27 15:15:25 -03:00
report_runner.rb
researcher.rb
sentiment_classifier.rb FEATURE: Add agent-backed sentiment classification (#40136) 2026-05-26 10:32:54 -03:00
settings_explorer.rb
short_summarizer.rb
short_text_translator.rb DEV: Use structured output for translations (#39079) 2026-04-03 11:39:27 +08:00
smart_dates.rb
spam_detector.rb
sql_helper.rb DEV: Enable Style/RedundantParentheses rubocop rule (#40095) 2026-05-19 15:48:09 +02:00
summarizer.rb
titles_generator.rb
tool_runner.rb DEV: Enable Style/RedundantSelf rubocop rule (#40098) 2026-05-19 19:27:45 +02:00
topic_title_translator.rb DEV: Use structured output for translations (#39079) 2026-04-03 11:39:27 +08:00
translator.rb
tutor.rb
web_artifact_creator.rb