Chat: /new continues the same chat on a fresh session
The composer's /new used to create a separate chat. It now sends chat_new_session. The server starts a fresh native session on the chat's own harness (OpenCode, Codex or Claude Code) and re-keys the operator_sessions row in one transaction. The chat keeps its title, directory, backend, colour, star, model and mode. The old row is kept unlisted with replaced_by, and its native session stays resumable. The reply and the chat_session_changed push carry previous_id, so every client swaps the row in place and an open conversation follows it to the fresh, empty transcript with a notice.
This commit is contained in:
@@ -12,8 +12,11 @@
|
||||
// them, and keeps colours picked with chat_color;
|
||||
// `?msgs=`, `?rich=1`, `?older=1`, `?live=N` vary the chat transcripts for
|
||||
// scroll captures (tool/perf/chat_scroll_fixture.dart).
|
||||
// `/new` in a fixture chat moves it to a fresh, empty session
|
||||
// (tool/perf/chat_new_session_fixture.dart).
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
import 'chat_new_session_fixture.dart';
|
||||
import 'chat_scroll_fixture.dart';
|
||||
|
||||
Map<String, String> _params = const {};
|
||||
@@ -45,7 +48,7 @@ const _colorNames = ['teal', 'purple', null, 'amber', 'red', null, 'blue'];
|
||||
final Map<String, String?> _pickedColors = {};
|
||||
|
||||
JsonMap _chatRow(int i) {
|
||||
final id = 'perf-chat-$i';
|
||||
final id = perfChatId(i);
|
||||
if (!_colors) {
|
||||
return {
|
||||
'id': id,
|
||||
@@ -199,8 +202,7 @@ JsonMap? perfChatReply(JsonMap request) {
|
||||
final session = query is Map ? '${query['session_id'] ?? ''}' : '';
|
||||
final color = query is Map ? query['color'] as String? : null;
|
||||
_pickedColors[session] = color;
|
||||
final index = int.tryParse(session.replaceFirst('perf-chat-', '')) ?? 0;
|
||||
final row = _chatRow(index);
|
||||
final row = _chatRow(perfChatIndex(session));
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_color',
|
||||
@@ -222,6 +224,8 @@ JsonMap? perfChatReply(JsonMap request) {
|
||||
'content': json ? '{"messages":[]}\n' : '# Fixture chat\n',
|
||||
},
|
||||
};
|
||||
case 'chat_new_session':
|
||||
return perfChatNewSessionReply(request, _chatRow);
|
||||
case 'chat_subscribe':
|
||||
return {'id': id, 'type': 'chat_subscribed'};
|
||||
case 'chat_shells':
|
||||
@@ -229,13 +233,24 @@ JsonMap? perfChatReply(JsonMap request) {
|
||||
case 'chat_messages':
|
||||
final query = request['chat_query'];
|
||||
final session = query is Map ? '${query['session_id'] ?? ''}' : '';
|
||||
if (perfChatIsFresh(session)) {
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_messages',
|
||||
'chat_history': {
|
||||
'messages': const [],
|
||||
'next_cursor': '',
|
||||
'has_more': false,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (_scrollVariety) {
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_messages',
|
||||
'chat_history': chatScrollHistory(
|
||||
session,
|
||||
int.tryParse(session.replaceFirst('perf-chat-', '')) ?? 0,
|
||||
perfChatIndex(session),
|
||||
query is Map ? '${query['cursor'] ?? ''}' : '',
|
||||
),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user