Skip to content

feat(openclaw-plugin): thread senderId + userMode through turn recording#1529

Open
yeyitech wants to merge 1 commit intovolcengine:mainfrom
yeyitech:feat/1479-senderid-usermode
Open

feat(openclaw-plugin): thread senderId + userMode through turn recording#1529
yeyitech wants to merge 1 commit intovolcengine:mainfrom
yeyitech:feat/1479-senderid-usermode

Conversation

@yeyitech
Copy link
Copy Markdown
Contributor

Summary

Lay down the plugin-side groundwork for multi-user OpenClaw conversations. Adds a userMode config ("single-user" default, "multi-user") and a robust extractSenderId helper that pulls a normalised speaker id out of runtimeContext. When userMode === "multi-user" and a senderId is present, the plugin records the turn with a role_id so per-speaker attribution becomes possible.

Single-user mode is unchanged.

Changes

  • context-engine.ts
    • New extractSenderId(runtimeContext) helper — trims, rejects non-string / empty / whitespace-only values, returns { found, senderId }.
    • afterTurn computes roleId = cfg.userMode === "multi-user" && sender.found ? sender.senderId : undefined and passes it through to client.addSessionMessage.
    • assemble emits a diagnostic log when a senderId is observed (no behavior change).
  • client.tsaddSessionMessage gains a 7th roleId?: string parameter and emits role_id in the request body when non-empty.
  • config.ts — new optional userMode: "single-user" | "multi-user" field with zod schema entry, allowlist registration, default, and UI description.
  • __tests__/sender-id.test.ts — 9 unit tests: 6 for extractSenderId (happy path, whitespace trim, missing context, absent key, empty/whitespace string, non-string values) + 3 for userMode schema (accepts both modes, defaults to single-user, rejects unknown values). All 9 pass.

Server-side note (intentional scope split)

The OpenViking server's AddMessageRequest (openviking/server/routers/sessions.py) does not currently declare a role_id field, so Pydantic's default extra="ignore" silently drops it. This PR only lands the plugin-side forwarding so the multi-user story can be built up incrementally; server-side ingestion of role_id is the natural next step and fits under the broader multi-user tracking in #1351.

Shipping plugin-side first is safe: the field is only sent when the operator explicitly opts into userMode: "multi-user" and supplies a senderId, and the server tolerates the extra field today.

Test plan

  • npm test -- --run sender-id in examples/openclaw-plugin/9/9 pass.
  • Existing openclaw-plugin tests unaffected by this change (pre-existing failures on main were verified to be unrelated).
  • Follow-up PR wires role_id into the server's AddMessageRequest + persistence layer.

Refs #1479

Add an extractSenderId helper that normalises runtimeContext.senderId
(trim, reject non-strings / empty values) and a userMode config field
("single-user" | "multi-user", default "single-user").

When userMode is "multi-user" and senderId is present, the plugin now
forwards it as role_id on the recorded user turn so multi-participant
conversations can be attributed back to the correct speaker. Single-user
mode preserves existing behavior.

Note: OpenViking server-side ingestion of role_id is not yet wired up
(AddMessageRequest currently drops unknown fields); plugin-side forwarding
lands first so the multi-user story can be completed end-to-end under
the follow-up tracked in volcengine#1351.

Refs volcengine#1479
@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

1479 - Fully compliant

Compliant requirements:

  • 新增 extractSenderId 函数
  • assemble 中提取并记录 senderId
  • afterTurn 中根据 userMode 传递 roleId
  • 新增 userMode 配置及验证

1351 - Not compliant

Non-compliant requirements:

  • 引入 account 级命名空间策略
  • 统一 canonical URI 与目录布局
  • 将 session 升级为 account 级共享作用域
  • 统一检索、索引与文件系统可见性
  • 引入统一 namespace resolver
  • 兼容性策略

Requires further human verification:

  • 服务端接收并处理 role_id(本 PR 仅实现插件侧传递)
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🏅 Score: 92
🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant