Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/bub-dingtalk/src/bub_dingtalk/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ def onboard_config(current_config: dict[str, Any]) -> dict[str, Any] | None:
if not _channel_enabled(current_config):
return None

client_id = bub_inquirer.ask_text("DingTalk client ID")
client_secret = bub_inquirer.ask_secret("DingTalk client secret")
current = current_config.get(CHANNEL_NAME)
config = current if isinstance(current, dict) else {}
client_id = bub_inquirer.ask_text(
"DingTalk client ID", default=str(config.get("client_id") or "")
)
client_secret = bub_inquirer.ask_secret("DingTalk client secret") or str(
config.get("client_secret") or ""
)
allow_users = bub_inquirer.ask_text(
"DingTalk allowed users (comma-separated staff IDs, * for all)",
default="*",
default=str(config.get("allow_users") or "*"),
)

return {
Expand Down
25 changes: 25 additions & 0 deletions packages/bub-dingtalk/tests/test_dingtalk_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,30 @@ def test_onboard_config_collects_dingtalk_settings(monkeypatch) -> None:
}


def _accept_defaults(monkeypatch) -> None:
monkeypatch.setattr(
plugin.bub_inquirer, "ask_text", lambda message, default="": default
)
monkeypatch.setattr(plugin.bub_inquirer, "ask_secret", lambda message: "")
monkeypatch.setattr(
plugin.bub_inquirer,
"ask_select",
lambda message, choices, default="": default,
)


def test_onboard_config_keeps_existing_dingtalk_settings(monkeypatch) -> None:
_accept_defaults(monkeypatch)
existing = {
"client_id": "client-id",
"client_secret": "client-secret",
"allow_users": "staff-1",
}

assert plugin.onboard_config(
{"enabled_channels": "dingtalk", "dingtalk": existing}
) == {"dingtalk": existing}


def test_onboard_config_skips_when_dingtalk_is_disabled() -> None:
assert plugin.onboard_config({"enabled_channels": "discord"}) is None
24 changes: 19 additions & 5 deletions packages/bub-discord/src/bub_discord/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,25 @@ def onboard_config(current_config: dict[str, Any]) -> dict[str, Any] | None:
if not _channel_enabled(current_config):
return None

token = bub_inquirer.ask_secret("Discord bot token")
allow_users = bub_inquirer.ask_text("Discord allowed users (optional)")
allow_channels = bub_inquirer.ask_text("Discord allowed channels (optional)")
command_prefix = bub_inquirer.ask_text("Discord command prefix", default="!")
proxy = bub_inquirer.ask_text("Discord proxy (optional)")
current = current_config.get(CHANNEL_NAME)
config = current if isinstance(current, dict) else {}
token = bub_inquirer.ask_secret("Discord bot token") or str(
config.get("token") or ""
)
allow_users = bub_inquirer.ask_text(
"Discord allowed users (optional)",
default=str(config.get("allow_users") or ""),
)
allow_channels = bub_inquirer.ask_text(
"Discord allowed channels (optional)",
default=str(config.get("allow_channels") or ""),
)
command_prefix = bub_inquirer.ask_text(
"Discord command prefix", default=str(config.get("command_prefix") or "!")
)
proxy = bub_inquirer.ask_text(
"Discord proxy (optional)", default=str(config.get("proxy") or "")
)

return {
CHANNEL_NAME: {
Expand Down
27 changes: 27 additions & 0 deletions packages/bub-discord/tests/test_discord_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@ def test_onboard_config_collects_discord_settings(monkeypatch) -> None:
}


def _accept_defaults(monkeypatch) -> None:
monkeypatch.setattr(
plugin.bub_inquirer, "ask_text", lambda message, default="": default
)
monkeypatch.setattr(plugin.bub_inquirer, "ask_secret", lambda message: "")
monkeypatch.setattr(
plugin.bub_inquirer,
"ask_select",
lambda message, choices, default="": default,
)


def test_onboard_config_keeps_existing_discord_settings(monkeypatch) -> None:
_accept_defaults(monkeypatch)
existing = {
"token": "token",
"allow_users": "user-1",
"allow_channels": "channel-1",
"command_prefix": "?",
"proxy": "http://proxy",
}

assert plugin.onboard_config(
{"enabled_channels": "discord", "discord": existing}
) == {"discord": existing}


def test_onboard_config_skips_when_discord_is_disabled() -> None:
assert plugin.onboard_config({"enabled_channels": "feishu"}) is None

Expand Down
39 changes: 30 additions & 9 deletions packages/bub-feishu/src/bub_feishu/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,38 @@ def onboard_config(current_config: dict[str, Any]) -> dict[str, Any] | None:
if not _channel_enabled(current_config):
return None

app_id = bub_inquirer.ask_text("Feishu app ID")
app_secret = bub_inquirer.ask_secret("Feishu app secret")
verification_token = bub_inquirer.ask_secret("Feishu verification token")
encrypt_key = bub_inquirer.ask_secret("Feishu encrypt key")
allow_users = bub_inquirer.ask_text("Feishu allowed users (optional)")
allow_chats = bub_inquirer.ask_text("Feishu allowed chats (optional)")
bot_open_id = bub_inquirer.ask_text("Feishu bot open ID (optional)")
current = current_config.get(CHANNEL_NAME)
config = current if isinstance(current, dict) else {}
app_id = bub_inquirer.ask_text(
"Feishu app ID", default=str(config.get("app_id") or "")
)
app_secret = bub_inquirer.ask_secret("Feishu app secret") or str(
config.get("app_secret") or ""
)
verification_token = bub_inquirer.ask_secret("Feishu verification token") or str(
config.get("verification_token") or ""
)
encrypt_key = bub_inquirer.ask_secret("Feishu encrypt key") or str(
config.get("encrypt_key") or ""
)
allow_users = bub_inquirer.ask_text(
"Feishu allowed users (optional)",
default=str(config.get("allow_users") or ""),
)
allow_chats = bub_inquirer.ask_text(
"Feishu allowed chats (optional)",
default=str(config.get("allow_chats") or ""),
)
bot_open_id = bub_inquirer.ask_text(
"Feishu bot open ID (optional)",
default=str(config.get("bot_open_id") or ""),
)
log_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
log_level_default = str(config.get("log_level") or "INFO").upper()
log_level = bub_inquirer.ask_select(
"Feishu log level",
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
default="INFO",
choices=log_levels,
default=log_level_default if log_level_default in log_levels else "INFO",
)

return {
Expand Down
30 changes: 30 additions & 0 deletions packages/bub-feishu/tests/test_feishu_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ def test_onboard_config_collects_feishu_settings(monkeypatch) -> None:
}


def _accept_defaults(monkeypatch) -> None:
monkeypatch.setattr(
plugin.bub_inquirer, "ask_text", lambda message, default="": default
)
monkeypatch.setattr(plugin.bub_inquirer, "ask_secret", lambda message: "")
monkeypatch.setattr(
plugin.bub_inquirer,
"ask_select",
lambda message, choices, default="": default,
)


def test_onboard_config_keeps_existing_feishu_settings(monkeypatch) -> None:
_accept_defaults(monkeypatch)
existing = {
"app_id": "app-id",
"app_secret": "app-secret",
"verification_token": "verification-token",
"encrypt_key": "encrypt-key",
"allow_users": "user-1",
"allow_chats": "chat-1",
"bot_open_id": "bot-open-id",
"log_level": "DEBUG",
}

assert plugin.onboard_config(
{"enabled_channels": "feishu", "feishu": existing}
) == {"feishu": existing}


def test_onboard_config_skips_when_feishu_is_disabled() -> None:
assert plugin.onboard_config({"enabled_channels": "discord"}) is None

Expand Down
7 changes: 3 additions & 4 deletions packages/bub-qq/src/bub_qq/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ def after_llm_call(


@hookimpl
def after_tool_call(
call: ToolCall, result: ToolCallResult, state: TurnState
) -> None:
def after_tool_call(call: ToolCall, result: ToolCallResult, state: TurnState) -> None:
qq_state = _qq_state(state)
if qq_state is None:
return
Expand Down Expand Up @@ -241,7 +239,8 @@ def onboard_config(current_config: dict[str, Any]) -> dict[str, Any] | None:
"QQ app ID",
default=str(config.get("appid") or ""),
),
"secret": bub_inquirer.ask_secret("QQ secret"),
"secret": bub_inquirer.ask_secret("QQ secret")
or str(config.get("secret") or ""),
"receive_mode": bub_inquirer.ask_select(
"QQ receive mode",
choices=RECEIVE_MODES,
Expand Down
25 changes: 25 additions & 0 deletions packages/bub-qq/tests/test_qq_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,30 @@ def test_onboard_config_collects_qq_settings(monkeypatch) -> None:
}


def _accept_defaults(monkeypatch) -> None:
monkeypatch.setattr(
plugin.bub_inquirer, "ask_text", lambda message, default="": default
)
monkeypatch.setattr(plugin.bub_inquirer, "ask_secret", lambda message: "")
monkeypatch.setattr(
plugin.bub_inquirer,
"ask_select",
lambda message, choices, default="": default,
)


def test_onboard_config_keeps_existing_qq_settings(monkeypatch) -> None:
_accept_defaults(monkeypatch)
existing = {
"appid": "app-id",
"secret": "secret",
"receive_mode": "websocket",
}

assert plugin.onboard_config({"enabled_channels": "qq", "qq": existing}) == {
"qq": existing
}


def test_onboard_config_skips_when_qq_is_disabled() -> None:
assert plugin.onboard_config({"enabled_channels": "wecom"}) is None
3 changes: 2 additions & 1 deletion packages/bub-wecom/src/bub_wecom/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def onboard_config(current_config: dict[str, Any]) -> dict[str, Any] | None:
"WeCom bot ID",
default=str(config.get("bot_id") or ""),
),
"secret": bub_inquirer.ask_secret("WeCom secret"),
"secret": bub_inquirer.ask_secret("WeCom secret")
or str(config.get("secret") or ""),
"websocket_url": bub_inquirer.ask_text(
"WeCom websocket URL",
default=str(
Expand Down
25 changes: 25 additions & 0 deletions packages/bub-wecom/tests/test_wecom_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ def test_onboard_config_collects_wecom_settings(monkeypatch) -> None:
}


def test_onboard_config_keeps_existing_wecom_settings(monkeypatch) -> None:
monkeypatch.setattr(
plugin.bub_inquirer, "ask_text", lambda message, default="": default
)
monkeypatch.setattr(plugin.bub_inquirer, "ask_secret", lambda message: "")
monkeypatch.setattr(
plugin.bub_inquirer,
"ask_select",
lambda message, choices, default="": default,
)
existing = {
"bot_id": "bot-id",
"secret": "secret",
"websocket_url": "wss://example.test/ws",
"dm_policy": "allowlist",
"allow_from": "alice",
"group_policy": "disabled",
"group_allow_from": "room-1",
}

assert plugin.onboard_config({"enabled_channels": "wecom", "wecom": existing}) == {
"wecom": existing
}


def test_onboard_config_skips_when_wecom_is_disabled() -> None:
assert plugin.onboard_config({"enabled_channels": "qq"}) is None

Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading