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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ The SDK ships with an interactive AI assistant, **DashScope SDK Expert**, built

For the latest model list, visit [Bailian Model Plaza](https://bailian.console.aliyun.com/).

## Shell Completion

Run the appropriate command once, then restart your shell (or re-source your config file):

| Shell | Install command |
|-------|-----------------|
| **bash** | `dashscope --install-completion bash` |
| **zsh** | `dashscope --install-completion zsh` |
| **fish** | `dashscope --install-completion fish` |

To preview the completion script without installing:
```shell
dashscope --show-completion bash
```

## Logging
To output Dashscope logs, you need to configure the logger.
```shell
Expand Down
2 changes: 1 addition & 1 deletion dashscope/acli/cli/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
"/rule": ["list", "add", "remove", "edit", "clear"],
"/profile": ["list", "search", "add", "remove", "clear"],
"/memory": ["list", "search", "remove", "clear"],
"/session": ["new", "list", "switch", "rename", "remove"],
"/session": ["new", "list", "switch", "rename", "fork", "remove"],
"/mcp": ["list", "add", "remove"],
"/cron": ["add", "list", "remove", "pause", "resume"],
"/feedback": ["good", "bad"],
Expand Down
32 changes: 32 additions & 0 deletions dashscope/acli/cli/handlers_session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""Session management command handlers."""
# pylint: disable=too-many-branches,too-many-statements,unused-argument
# pylint: disable=too-many-return-statements

from __future__ import annotations

Expand All @@ -15,6 +16,8 @@
" /session list — list all sessions\n"
" /session switch <n> — switch to a topic\n"
" /session rename <old> <new> — rename\n"
" /session fork <new> [src] — fork a session (default src: "
"current)\n"
" /session remove <n> — remove session "
"(default cannot be removed)\n"
" /session scene — show scene memory of the current topic\n"
Expand Down Expand Up @@ -128,6 +131,35 @@ def _handle_session_command(cmd: str, config, agent) -> None:
f"or '{new_name}' already exists[/red]",
)

elif subcmd == "fork":
if len(parts) < 3:
console.print(
"[dim]Usage: /session fork <new> [src][/dim]",
)
return
fork_args = parts[2].split(maxsplit=1)
dst = fork_args[0]
src = (
fork_args[1]
if len(fork_args) > 1
else (session_mgr.get_current_topic())
)
# Flush the live conversation when forking the active topic so
# the fork carries the latest messages.
if src == session_mgr.get_current_topic():
if agent.session_path and agent.messages:
agent.save_session()
if session_mgr.fork_topic(src, dst):
console.print(
f"[green]Forked session: {src} → {dst}[/green]\n"
f" [dim]Switch with: /session switch {dst}[/dim]",
)
else:
console.print(
f"[red]Fork failed: '{src}' does not exist "
f"or '{dst}' already exists[/red]",
)

elif subcmd == "remove":
topic = parts[2] if len(parts) > 2 else ""
if not topic:
Expand Down
4 changes: 3 additions & 1 deletion dashscope/acli/cli/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ async def _handle_mcp_command(cmd: str, config: Config):
" /mcp — list connected services\n"
" /mcp list — show Bailian available services\n"
" /mcp add <svc> — add an MCP service\n"
" /mcp remove <svc> — remove an MCP service[/dim]",
" /mcp remove <svc> — remove an MCP service\n"
"Stdio servers: add [[mcp_servers]] in config.toml with "
'transport = "stdio", command and args[/dim]',
)


Expand Down
2 changes: 1 addition & 1 deletion dashscope/acli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
("/memory", "Chat history (list/search/remove <id|num>/clear)"),
(
"/session",
"Session management (new/list/switch/rename/remove/scene)",
"Sessions (new/list/switch/rename/fork/remove/scene)",
),
(
"/summarize",
Expand Down
3 changes: 2 additions & 1 deletion dashscope/acli/mcp_stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
import asyncio
import json

from dashscope.acli import __version__
from dashscope.acli.platforms.bailian.mcp import MCP_PROTOCOL_VERSION, MCPError

__all__ = ["StdioMCPClient", "MCPError"]

_CLIENT_INFO = {"name": "acli", "version": "0.1.0"}
_CLIENT_INFO = {"name": "acli", "version": __version__}
_CLOSE_TIMEOUT = 3.0
_STDERR_TAIL = 500

Expand Down
9 changes: 7 additions & 2 deletions dashscope/acli/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ def fork_topic(self, src: str, dst: str) -> bool:
if not src_dir.exists() or dst_dir.exists():
return False
try:
import shutil

dst_dir.mkdir(parents=True)
self._save_meta(
dst,
Expand All @@ -285,9 +287,12 @@ def fork_topic(self, src: str, dst: str) -> bool:
)
src_events = self._events_file(src)
if src_events.exists():
import shutil

shutil.copy2(src_events, self._events_file(dst))
# Pre-snapshot sessions keep their messages only in
# history.json; copy it too so the fork restores them.
src_history = self._history_file(src)
if src_history.exists():
shutil.copy2(src_history, self._history_file(dst))
except OSError:
return False
self.event_log(dst).append(
Expand Down
10 changes: 0 additions & 10 deletions dashscope/acli/session_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ def read(
events.append(entry)
return events

def tail(
self,
n: int,
event_type: str | None = None,
) -> list[dict[str, Any]]:
"""Return the most recent ``n`` events (optionally by type)."""
if n <= 0:
return []
return self.read(event_type)[-n:]

def read_raw(self) -> list[dict[str, Any]]:
"""Return every well-formed entry, any schema version.

Expand Down
Loading
Loading