Skip to content

Docs: wrapper usage#37

Merged
JohnRichard4096 merged 1 commit intomainfrom
docs/wrapper
Mar 25, 2026
Merged

Docs: wrapper usage#37
JohnRichard4096 merged 1 commit intomainfrom
docs/wrapper

Conversation

@JohnRichard4096
Copy link
Copy Markdown
Member

@JohnRichard4096 JohnRichard4096 commented Mar 25, 2026

Summary by Sourcery

Update documentation examples to reflect the correct hook wrapper usage and fix Jinja2 template links in both English and Chinese guides.

Documentation:

  • Adjust hook decorator examples to use the new .handle() wrapper pattern across event, security, API reference, extensions, and function implementation guides in English and Chinese.
  • Correct Jinja2 template guide links in the architecture documentation for both English and Chinese versions.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Mar 25, 2026

Reviewer's Guide

Updates documentation examples to use the new hook wrapper .handle() API for event decorators and fixes Jinja2 template documentation links in both English and Chinese guides.

Sequence diagram for wrapper-based precompletion hook handling

sequenceDiagram
    actor Developer
    participant App as Application
    participant ChatObject
    participant HookSystem
    participant PreCompletionEvent
    participant Handler as handle_pre_completion

    Developer->>App: Define handler
    Note over Developer,App: @on_precompletion().handle()
    App->>HookSystem: Register Handler for PreCompletionEvent

    App->>ChatObject: Create and run chat_obj
    ChatObject->>HookSystem: Trigger PreCompletionEvent
    HookSystem->>PreCompletionEvent: Create event instance
    HookSystem->>Handler: Call handle_pre_completion(event)
    Handler-->>PreCompletionEvent: Mutate messages / context
    PreCompletionEvent-->>ChatObject: Updated event data
    ChatObject-->>App: Continue LLM request with modified messages
Loading

Class diagram for hook wrapper .handle() decorator usage

classDiagram
    class OnPrecompletionWrapper {
        +handle() HandlerDecorator
    }

    class OnCompletionWrapper {
        +handle() HandlerDecorator
    }

    class OnPresetFallbackWrapper {
        +handle() HandlerDecorator
    }

    class HandlerDecorator {
        +__call__(func) async_handler
    }

    class PreCompletionEvent {
    }

    class CompletionEvent {
    }

    class FallbackContext {
    }

    class AsyncHandler {
        +event_param
        +__call__(event)
    }

    OnPrecompletionWrapper --> HandlerDecorator : returns
    OnCompletionWrapper --> HandlerDecorator : returns
    OnPresetFallbackWrapper --> HandlerDecorator : returns

    HandlerDecorator --> AsyncHandler : wraps

    AsyncHandler --> PreCompletionEvent : uses
    AsyncHandler --> CompletionEvent : uses
    AsyncHandler --> FallbackContext : uses

    %% Example bindings illustrated
    class on_precompletion {
        +__call__() OnPrecompletionWrapper
    }

    class on_completion {
        +__call__() OnCompletionWrapper
    }

    class on_preset_fallback {
        +__call__() OnPresetFallbackWrapper
    }

    on_precompletion --> OnPrecompletionWrapper : returns
    on_completion --> OnCompletionWrapper : returns
    on_preset_fallback --> OnPresetFallbackWrapper : returns
Loading

File-Level Changes

Change Details Files
Update all event hook examples to use the new .handle() wrapper on hook decorators.
  • Replace usages of @on_precompletion() with @on_precompletion().handle() in event concept guides, security mechanism guides, API reference, function implementation docs, and extension integration docs (EN).
  • Replace usages of @on_completion() with @on_completion().handle() for completion hook examples across relevant English docs.
  • Replace usages of @on_preset_fallback() with @on_preset_fallback().handle() in fallback-related English docs.
docs/guide/concepts/event.md
docs/guide/security-mechanisms.md
docs/guide/api-reference/classes/Depends.md
docs/guide/extensions-integration.md
docs/guide/api-reference/index.md
docs/guide/function-implementation.md
docs/guide/api-reference/classes/FallbackContext.md
Mirror the new .handle() hook usage in all corresponding Chinese documentation examples.
  • Update @on_precompletion() examples to @on_precompletion().handle() in Chinese event concept and API reference docs.
  • Update @on_completion() examples to @on_completion().handle() in Chinese security, extensions integration, and API reference docs.
  • Update @on_preset_fallback() examples to @on_preset_fallback().handle() in the Chinese FallbackContext API reference.
docs/zh/guide/concepts/event.md
docs/zh/guide/security-mechanisms.md
docs/zh/guide/api-reference/classes/Depends.md
docs/zh/guide/extensions-integration.md
docs/zh/guide/api-reference/index.md
docs/zh/guide/function-implementation.md
docs/zh/guide/api-reference/classes/FallbackContext.md
Fix internal links to the Jinja2 templates documentation in the architecture guides.
  • Update the English architecture guide link to Jinja2 templates to use an absolute /guide/... path.
  • Update the Chinese architecture guide link to Jinja2 templates to use an absolute /zh/guide/... path without the .md suffix.
docs/guide/getting-started/architecture.md
docs/zh/guide/getting-started/architecture.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In getting-started/architecture.md the English link uses /guide/concepts/jinja2-templates.md while the Chinese version uses /zh/guide/concepts/jinja2-templates without the .md suffix; consider aligning these to match your docs routing conventions so locale and extension handling are consistent.
  • Since all hook examples now use @on_...().handle(), it may be helpful to add a brief note in the relevant hook or events guide explaining why .handle() is required and how it differs from using @on_...() directly to avoid confusion for readers familiar with the previous syntax.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `getting-started/architecture.md` the English link uses `/guide/concepts/jinja2-templates.md` while the Chinese version uses `/zh/guide/concepts/jinja2-templates` without the `.md` suffix; consider aligning these to match your docs routing conventions so locale and extension handling are consistent.
- Since all hook examples now use `@on_...().handle()`, it may be helpful to add a brief note in the relevant hook or events guide explaining why `.handle()` is required and how it differs from using `@on_...()` directly to avoid confusion for readers familiar with the previous syntax.

## Individual Comments

### Comment 1
<location path="docs/zh/guide/getting-started/architecture.md" line_range="186" />
<code_context>
 5. **厂商无关性**: 适配器层确保相同的agent逻辑可以与不同的LLM提供商配合工作而无需代码更改。

-6. **模板支持**: [Jinja2模板](../../concepts/jinja2-templates.md)基于上下文、记忆和配置启用动态提示构建。
+6. **模板支持**: [Jinja2模板](/zh/guide/concepts/jinja2-templates)基于上下文、记忆和配置启用动态提示构建。
</code_context>
<issue_to_address>
**issue (bug_risk):** The Jinja2 templates link in the Chinese doc likely needs a `.md` suffix for consistency and to avoid a broken link.

The previous relative link used `jinja2-templates.md`, and the English doc now points to `/guide/concepts/jinja2-templates.md`. For consistency and to avoid a 404, update this to `/zh/guide/concepts/jinja2-templates.md`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread docs/zh/guide/getting-started/architecture.md
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying amritacore with  Cloudflare Pages  Cloudflare Pages

Latest commit: d08ce21
Status: ✅  Deploy successful!
Preview URL: https://5be0edfb.amritacore.pages.dev
Branch Preview URL: https://docs-wrapper.amritacore.pages.dev

View logs

@JohnRichard4096 JohnRichard4096 merged commit 810b184 into main Mar 25, 2026
4 checks passed
@JohnRichard4096 JohnRichard4096 deleted the docs/wrapper branch March 25, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant