Logo Hor Post Worker

Hor Post Worker

Tổ chức
openreachtech
hor-post-worker

Implement a GraphQL post-worker: a hook that fires after a query/mutation resolver has resolved and the response has been sent, to run a side effect that is not part of the API's main processing (send a welcome email after signup, emit an audit log, invalidate a cache). Use this skill whenever the user asks to add or edit a post-worker, wants "run something after this resolver / after the response", or needs to fire-and-forget a side effect right after an API call.

Tổng quan

Nhà phát hànhopenreachtech
Kho mãhora-skills-ort-renchan
Tên kỹ nănghor-post-worker
Sao
32
Bản fork
0
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépApache-2.0
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Đầy đủ trong hướng dẫn

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được openreachtech công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Hor Post Worker trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/openreachtech/hora-skills-ort-renchan/tree/main/kit/skills/hor-post-worker
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/openreachtech/hora-skills-ort-renchan.git /tmp/hora-skills-ort-renchan
mkdir -p .claude/skills
cp -r /tmp/hora-skills-ort-renchan/kit/skills/hor-post-worker .claude/skills/hor-post-worker
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Hor Post Worker trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Hor Post Worker ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Hor Post Worker không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Post-Worker (a post-response side-effect hook)

A skill for implementing BaseGraphqlPostWorker, a hook that runs a side effect — one that is not part of the API's main processing — after the resolver has resolved (after the response has been sent). It handles requirements of the form "after this operation, also run …" as a follow-up, without polluting the resolver itself.

Deciding the placement itself (whether a post-worker is even the right choice, versus enqueuing inside the resolver) is settled in section 2.2 of hor-execution-placement-pattern. This skill covers "once you've decided on a post-worker, how to implement it". The implementation of the worker body you dispatch to belongs to hor-renchan-job-bullmq.

Grand principle: a post-worker is a thin layer that only dispatches — the real work always lives in the worker

The only things you may write in a post-worker's onResolved() are the dispatch to a background worker and the branching that precedes it. Write no real work at all — no email-body assembly, no external API calls, no DB updates, no heavy loops.

  • Why only dispatch: a post-worker fires after the HTTP response has been fully sent (Express's res.on('finish')). Throwing an exception here never reaches the caller, and neither retry, progress notification, nor monitoring apply. Put real work here and logic accumulates in a place where failures get swallowed. Keep it to dispatch and the real work runs on the worker's machinery (retries, observability, scaling), while the post-worker stays predictably thin — "just enqueuing".
  • Why add a post-worker layer at all: for something like "I don't want to make the signup response wait, but I do want to send a welcome email" — writing a side effect unrelated to the main processing into the resolver itself bloats the resolver's responsibility and lets a side-effect failure drag down the main processing's response. Push it out to a post-worker and the resolver can focus on returning its proper result.
  • If the decision touches "heavy / want to retry", go to the worker. A post-worker is itself a thin hook that is never re-run, so any processing that must not fail, or that takes time, always belongs in the worker you dispatch to.
js
// Good: the post-worker only dispatches (the real work of the side effect is on the worker side)
/** @override */
async onResolved ({
  variables,
  context,
  information,
  response: {
    output,
    error,
  },
}) {
  if (error) {
    return
  }

  await context.share.jobDispatcherProvider.dispatchJob({
    DispatcherCtor: SendWelcomeEmailJobDispatcher,
    body: {
      customerId: output.customer.id,
    },
  })
}
js
// Avoid: writing email-body assembly or sending logic directly in the post-worker
//   → real work accumulates in a post-response place where failures get swallowed, and neither retry nor monitoring apply. Put the real work in the worker.
async onResolved ({ output }) {
  const html = await this.buildWelcomeMailHtml({ output }) // real work
  await this.mailer.send({ to: output.customer.email, html }) // external I/O — if it fails, no one notices
}

Comment language in the sample code

Comments in the js examples in this SKILL.md follow the prose language (here, English), because the examples are explanation of the skill. Comments inside the artifact this skill produces (the real *PostWorker.js code) follow the codebase language — English — to match the surrounding source.

1. How it works (when it fires and what it receives)

A post-worker is a hook per operation (query / mutation). The framework (renchan) fires it in the following flow.

  1. When the resolver resolves (or throws), the framework stores { variables, context, information, response } bound to the request (response is { output, error: null } on success, { output: null, error } on failure).
  2. After the HTTP response has been fully sent (res.on('finish')), using the stored content, it fires in this order:
    • first the engine-wide defineOnResolved() (a noop by default, common to all operations),
    • then the onResolved() of the post-worker whose name matches that operation.
  • The correspondence to an operation is by name match. A post-worker is called only when the string returned by its static get schema() matches the fired operation's name (the GraphQL field name, e.g. signUp). One post-worker per operation (don't define the same schema more than once).
  • onResolved() receives the same context as the resolver. This is the key point: because context reaches the shared instances (the job dispatcher, etc.), a post-worker can dispatch a worker (2).
  • variables is the operation's input arguments, output is the resolver's return value, and information is the resolve info (fieldName, etc.).

Arguments onResolved() receives:

ArgumentContents
variablesThe operation's input arguments (the same ones the resolver received)
contextThe same context as the resolver. context.share holds the shared instances (2)
informationGraphQL resolve info (fieldName = the operation name, etc.)
response.outputThe resolver's return value (on success). null on failure
response.errorThe error the resolver threw (on failure). null on success

2. Dispatch a worker from context.share

A post-worker receives the same context as the resolver, and context has share. share holds the instances the app uses in common, and in many renchan apps it keeps the renchan-job-bullmq dispatch entry point (jobDispatcherProvider). A post-worker uses this to enqueue a worker.

js
// Dispatch via share (a JobDispatcherProvider that reuses the connection)
await context.share.jobDispatcherProvider.dispatchJob({
  DispatcherCtor: SendWelcomeEmailJobDispatcher, // the Dispatcher of the job to enqueue
  body: {
    customerId: output.customer.id, // keep the body minimal (just ids or tokens)
  },
})
  • Why use context.share: taking the dispatch entry point from the request-scoped shared instance lets you reuse the connection to Redis, etc. Don't new a Dispatcher every time inside the post-worker.
  • The implementation of the job you dispatch (Manifest / Worker / Dispatcher) follows hor-renchan-job-bullmq. The post-worker side only decides "which Dispatcher, with what body" to enqueue.
  • What's in share is app-dependent. Confirm the name of the dispatch entry point (jobDispatcherProvider, etc.) in that app's Share implementation. If it's missing, the right move is to add it to share — don't create a connection on the fly inside the post-worker.

3. Implementation steps

Steps to add one new post-worker.

Step 1: Create the post-worker class

Extend BaseGraphqlPostWorker and override the following two. The file name is <Operation>PostWorker.js (a name that makes the corresponding operation clear; align it with the resolver's naming).

  • static get schema(): returns the operation name to hook (the GraphQL field name).
  • async onResolved({ variables, context, information, response }): write dispatch only (the grand principle at the top of this file).
js
import {
  BaseGraphqlPostWorker,
} from '@openreachtech/renchan'

import SendWelcomeEmailJobDispatcher from '../../../../app/jobs/send-welcome-email/SendWelcomeEmailJobDispatcher.js'

/**
 * Post-worker: dispatch a welcome email after signUp resolves.
 *
 * @extends {BaseGraphqlPostWorker<*, *, *>}
 */
export default class SignUpPostWorker extends BaseGraphqlPostWorker {
  /**
   * get: Operation name to hook.
   *
   * @override
   * @returns {string}
   */
  static get schema () {
    return 'signUp'
  }

  /**
   * On resolved hook. Dispatch only; the real work lives in the worker.
   *
   * @override
   */
  async onResolved ({
    variables,
    context,
    information,
    response: {
      output,
      error,
    },
  }) {
    if (error) {
      return
    }

    await context.share.jobDispatcherProvider.dispatchJob({
      DispatcherCtor: SendWelcomeEmailJobDispatcher,
      body: {
        customerId: output.customer.id,
      },
    })
  }
}

Step 2: Guard against failures and missing values

  • If there's an error, return early. Enqueuing a side effect (like sending an email) when the operation failed creates inconsistency. The standard guard is if (!output || error) { return } — treat a missing output the same as a failure.
  • Check that the values you read from output exist. A post-worker runs after the resolver succeeds, but if output's shape differs from what you expect, traverse it defensively like output?.customer?.id and don't dispatch when it's absent.
  • Don't throw from onResolved(). It's after the response has been sent, so no one can catch it. Handle it with branching and return early.
  • Don't declare an errorCodeHash getter on a post-worker. Unlike a resolver, a post-worker has no error contract with the caller (the response is already sent), so failures are handled by branching and early returns, not by raising error codes.

Step 3: Wire it into the engine (postWorkersPath)

Post-workers are auto-loaded recursively from the directory the engine's config.postWorkersPath points at (only classes extending BaseGraphqlPostWorker are picked up). While postWorkersPath is null, post-workers never fire at all.

  • Following the resolver layout, prepare a per-role directory like server/graphql/post-workers/<role>/ and point postWorkersPath at it.
js
// server/graphql/CustomerGraphqlServerEngine.js
/** @override */
static get config () {
  return {
    // ...existing config...
    actualResolversPath: rootPath.to('server/graphql/resolvers/customer/actual/'),
    // Before: postWorkersPath: null,
    postWorkersPath: rootPath.to('server/graphql/post-workers/customer/'),
  }
}
  • If you need engine-wide post-processing (common to all operations), override the engine's defineOnResolved() rather than a post-worker under postWorkersPath. The "dispatch only" principle still applies here too. Use them separately: a post-worker for a specific operation's post-processing, defineOnResolved() for post-processing across all operations.

4. Use cases (what to put in a post-worker)

All of these are side effects unrelated to the main processing that you don't want to make the response wait for, and in the post-worker you only dispatch.

Use caseExample operation to hookWhat the dispatched worker does
Notification email right after signupsignUpGenerate and send the welcome email body
Recording an audit log / operation historyEach mutationWrite the changes to the audit store
Syncing to an external system / webhook notificationcreateXxx / updateXxxPush to the external API (external API client)
Cache invalidation / rebuildData-updating mutationsDelete and warm up the cache
Sending analytics eventsAny operationSend measurement events to analytics
  • What a post-worker is not suited for: processing whose result the caller waits for / is included in the response is too late in a post-worker (since it runs after the response). Handle that in the resolver itself, or with enqueuing inside the resolver (hor-execution-placement-pattern 2.1).

5. Testing

A post-worker has thin logic (dispatch only), so keep its tests thin too. Following the hoc-jest skill, split files per class.

  • That it extends BaseGraphqlPostWorker (inheritance).
  • That static get schema() returns the correct operation name.
  • The branching in onResolved():
    • On success (error: null, output present) → dispatch is called with the expected DispatcherCtor and body.
    • On failure (error present) → dispatch is not called (early return).
  • Stub the dispatch entry point. Give context.share.jobDispatcherProvider.dispatchJob a stub function, spy that property with jest.spyOn(), and verify the arguments (DispatcherCtor / body). Don't actually enqueue a job.
js
// Success case: verify only that dispatch is called with the correct Dispatcher and body
const context = {
  share: {
    jobDispatcherProvider: {
      dispatchJob: async () => null,
    },
  },
}
const dispatchJobSpy = jest.spyOn(context.share.jobDispatcherProvider, 'dispatchJob')

await SignUpPostWorker.create({ engine })
  .onResolved({
    variables: {},
    context,
    information: {},
    response: {
      output: {
        customer: {
          id: 'fake-customer-id-001',
        },
      },
      error: null,
    },
  })

expect(dispatchJobSpy)
  .toHaveBeenCalledWith({
    DispatcherCtor: SendWelcomeEmailJobDispatcher,
    body: {
      customerId: 'fake-customer-id-001',
    },
  })

Finishing checklist

  • Is what you wrote in onResolved() only dispatch and branching (did you put the real work in the worker)?
  • Does static get schema() match the operation name it hooks (one post-worker per operation)?
  • Do you return early when there's an error, and guard against a missing output? Are you not throwing from onResolved()?
  • Is the dispatch via context.share's shared dispatch entry point (not new-ing a connection inside the post-worker)?
  • Did you wire the engine's postWorkersPath (it won't fire while it stays null)?
  • Did you use defineOnResolved() for post-processing across all operations and a post-worker for a specific operation, appropriately?
  • In tests, did you verify "dispatched on success / not on failure" with a stub of the dispatch entry point?

Câu hỏi thường gặp

Kỹ năng AI Hor Post Worker làm được gì?

Implement a GraphQL post-worker: a hook that fires after a query/mutation resolver has resolved and the response has been sent, to run a side effect that is not part of the API's main processing (send a welcome email after signup, emit an audit log, invalidate a cache). Use this skill whenever the user asks to add or edit a post-worker, wants "run something after this resolver / after the response", or needs to fire-and-forget a side effect right after an API call.

Vì sao nên dùng Hor Post Worker trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Hor Post Worker là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Hor Post Worker trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/openreachtech/hora-skills-ort-renchan/tree/main/kit/skills/hor-post-worker. TypingMind đọc tệp SKILL.md và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Hor Post Worker?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Hor Post Worker với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Hor Post Worker với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Hor Post Worker có miễn phí không?

Có. Kỹ năng này được openreachtech phát hành trên GitHub theo giấy phép Apache-2.0. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇