-
Notifications
You must be signed in to change notification settings - Fork 7
feat(amsg-server): onBeforeFire skip 出口 + GET /messages 投影 charId/clientTaskId #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "@rei-standard/amsg-server": minor | ||
| --- | ||
|
|
||
| onBeforeFire 新增 `{ skip: true }` 出口:在第一次 LLM 调用之前结束本次 fire | ||
|
|
||
| 宿主在 fire 时刻就能判断这条消息已经多余(比如排程之后对话又有了新进展)时,`onBeforeFire` 返回 `{ skip: true }` 即可作废本次触发。这次 fire 算作一次零推送的成功投递(`status: 'skipped'`):一次性任务照删、循环任务照推进到下次,且不调用 LLM、不消耗 token。 | ||
|
|
||
| 返回 `null` 的既有语义不变(回退到排程时冻结的 completePrompt 老链路)。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@rei-standard/amsg-server": minor | ||
| --- | ||
|
|
||
| `GET /messages` 每条任务额外返回 `charId` / `clientTaskId`(取自任务 metadata 的 `charId` / `amsgClientTaskId`,缺省为 null),供宿主按角色归属筛选任务。metadata 的其余字段不回传,凭据类字段照旧不回传。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |||||
| * When the host configures fire-time hooks, an LLM task stops replaying | ||||||
| * the completePrompt frozen at schedule time. At fire time instead: | ||||||
| * | ||||||
| * onBeforeFire(fireCtx) → fresh messages (may read client_state) | ||||||
| * onBeforeFire(fireCtx) → fresh messages (may read client_state) | { skip: true } | ||||||
| * → callLlm → onLLMOutput(sessionCtx) → decision | ||||||
| * ├─ 'finish' → push decision.pushPayloads, done | ||||||
| * ├─ 'skip-push' → record, done (task counts as delivered) | ||||||
|
|
@@ -105,7 +105,7 @@ function normalizeBeforeFireResult(result) { | |||||
| }; | ||||||
| } | ||||||
| throw new TypeError( | ||||||
| 'AGENTIC_BAD_BEFORE_FIRE: onBeforeFire must return ChatMessage[] | { messages, maxToolIterations?, totalTimeoutMs? } | null' | ||||||
| 'AGENTIC_BAD_BEFORE_FIRE: onBeforeFire must return ChatMessage[] | { messages, maxToolIterations?, totalTimeoutMs? } | { skip: true } | null' | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -132,7 +132,11 @@ function firstPositiveNumber(values, fallback) { | |||||
| * @param {string} args.userKey - per-user storage key (for readState decryption) | ||||||
| * @param {Object} args.ctx - processor ctx ({ db, webpush, vapid, hooks, maxToolIterations, totalTimeoutMs }) | ||||||
| * @returns {Promise<{ handled: false } | { handled: true, result: { success: true, messagesSent: number, status: 'finished'|'skipped', iterations: number } }>} | ||||||
| * `handled: false` → caller falls back to the legacy frozen-prompt path. | ||||||
| * `handled: false` → caller falls back to the legacy frozen-prompt path | ||||||
| * (onBeforeFire returned null). | ||||||
| * `onBeforeFire` may also return `{ skip: true }` to complete the fire | ||||||
| * before the first LLM call → `status: 'skipped', iterations: 0`, same | ||||||
| * success handling as the post-LLM skip-push path. | ||||||
| * Failures (timeout / loop exceeded / config errors) throw — the caller's | ||||||
| * existing error handling turns them into task retry/failure. | ||||||
| */ | ||||||
|
|
@@ -178,6 +182,14 @@ export async function runAgenticFire({ task, decryptedPayload, userKey, ctx }) { | |||||
| const before = await hooks.onBeforeFire(fireCtx); | ||||||
| if (before == null) return { handled: false }; | ||||||
|
|
||||||
| // Pre-LLM skip: the host judged this fire moot before generation (e.g. the | ||||||
| // conversation moved on after the task was scheduled). Shaped exactly like | ||||||
| // the post-LLM 'skipped' result, so run-tick's success handling (delete | ||||||
| // once-off / advance recurrence) applies unchanged — and zero tokens spent. | ||||||
| if (typeof before === 'object' && before.skip === true) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 由于在第 183 行已经进行了
Suggested change
|
||||||
| return { handled: true, result: { success: true, messagesSent: 0, status: 'skipped', iterations: 0 } }; | ||||||
| } | ||||||
|
|
||||||
| const normalized = normalizeBeforeFireResult(before); | ||||||
| const maxToolIterations = firstPositiveInt( | ||||||
| [normalized.maxToolIterations, ctx.maxToolIterations], | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
虽然在
runAgenticFire中提前拦截了{ skip: true },但normalizeBeforeFireResult函数内部并没有实际支持{ skip: true }的解析。如果直接传入{ skip: true },该函数仍然会抛出TypeError。这使得normalizeBeforeFireResult的错误提示信息与其实际行为不一致,且验证逻辑有些分散。建议将{ skip: true }的解析和验证也统一放入normalizeBeforeFireResult中,使代码更加内聚和易于维护。