75 lines
2.9 KiB
Dart
75 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../core/api_gateway.dart';
|
|
import '../features/chat/chat_runtime.dart';
|
|
import '../features/chat/ui/sessions/chat_create_fields.dart';
|
|
import '../features/settings/settings_store.dart';
|
|
|
|
typedef OpenInChat = Future<void> Function(BuildContext context);
|
|
|
|
String runChatReference(JsonMap run) {
|
|
final id = run['id'];
|
|
// A run summary names its pipeline in `name`; `title` is the run's own
|
|
// title, empty for an untitled run.
|
|
final title = '${run['title'] ?? ''}'.trim();
|
|
final pipeline =
|
|
'${run['pipeline_name'] ?? run['pipeline'] ?? run['name'] ?? ''}'.trim();
|
|
final version = '${run['pipeline_version'] ?? run['version'] ?? ''}'.trim();
|
|
final status = '${run['status'] ?? ''}'.trim();
|
|
return 'About Pipelines run #$id "${title.isEmpty ? 'Run $id' : title}" '
|
|
'(pipeline "${pipeline.isEmpty ? 'unknown' : pipeline}"'
|
|
'${version.isEmpty ? '' : ' v$version'}, status $status). '
|
|
'Inspect it with `pipelines inspect $id`.';
|
|
}
|
|
|
|
String pipelineChatReference(int id, String name, int version) =>
|
|
'About pipeline "$name" (id $id, version $version). '
|
|
'Show it with `pipelines show "$name"`; to change it, draft with '
|
|
'`pipelines edit` and publish with `pipelines submit`.';
|
|
|
|
/// Creates and opens a chat without showing the general-purpose create dialog.
|
|
/// The caller supplies the already-resolved directory so run and pipeline
|
|
/// screens can apply their own workspace provenance rules.
|
|
Future<void> openReferenceInChat({
|
|
required BuildContext context,
|
|
required ChatRuntime runtime,
|
|
required ValueChanged<String> selectChat,
|
|
required String directory,
|
|
required String title,
|
|
required String draft,
|
|
}) async {
|
|
try {
|
|
// Match the New chat dialog: prefer OpenCode when it is available, but
|
|
// use the first server-advertised harness on installations where it is
|
|
// not. Do not invent a backend when the catalog cannot be read.
|
|
final backends = await runtime.sessions.repository.backends();
|
|
final backend = backends.contains('opencode') ? 'opencode' : backends.first;
|
|
final session = await runtime.sessions.createOrThrow(
|
|
title: title,
|
|
directory: directory.trim().isEmpty ? chatHomeDirectory : directory,
|
|
backend: backend,
|
|
instructions: '',
|
|
operationId: 'open-in-chat-${DateTime.now().microsecondsSinceEpoch}',
|
|
);
|
|
final id = '${session['id'] ?? ''}';
|
|
if (id.isEmpty) throw StateError('The new chat has no id.');
|
|
runtime.opened[id] = session;
|
|
runtime.pendingDrafts[id] = draft;
|
|
selectChat(id);
|
|
runtime.composerFocus.request(id);
|
|
} catch (error) {
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text('Could not open in chat: $error')));
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<String> settingsWorkspace(String serverId) async {
|
|
final values = await SharedPreferencesSettingsStore(
|
|
serverId: serverId,
|
|
).load();
|
|
return values.workspace.trim();
|
|
}
|