Files
openchamber-android-native/tool/live_probe.dart
T
blumia d7cec9d155 feat: animated folds that hold their header, folded-by-default runs
- Rebuilt the fold after dsh-Go's ExpandReveal/_holdHeader: the body grows
  from its top edge and fades in over 280ms (easeInOutCubic), and every
  frame reports the height it adds or removes *before layout*, so the list
  can scroll by exactly that much and keep the header under the finger.
  Folds nobody can see take their new size without animating or dragging
  the view.
- Finished runs now fold to their summary line, as in dsh-Go; running ones
  stay open. A tap overrides either default and is remembered.
- Streamed tool parts only carry an id and input, never the tool name, so
  live steps showed a generic "工具" label. Each step now swaps in the
  server's copy of its message when it ends, which brings the name, the
  full input and the attachments (and with them the right icon, label and
  image handling).
- getMessage read the message from the response envelope directly and
  would have thrown; it now unpacks `data`.
Version 0.3.5 (code 305).
2026-11-20 00:26:09 +08:00

62 lines
2.4 KiB
Dart

// Creates a throwaway session, prompts it, and prints the live events for it:
// type, session id, assistant message id and payload keys. This is how the
// chat's streaming path is checked against a real server.
// dart run tool/live_probe.dart [seconds]
import 'dart:async';
import 'dart:io';
import 'package:openchamber/api/client.dart';
const types = [
'session.created', 'session.renamed', 'session.execution.started',
'session.execution.succeeded', 'session.execution.failed',
'session.execution.interrupted', 'session.step.started',
'session.step.ended', 'session.step.failed', 'session.text.started',
'session.text.delta', 'session.text.ended', 'session.reasoning.started',
'session.reasoning.delta', 'session.reasoning.ended',
'session.tool.called', 'session.tool.success', 'session.tool.failed',
'permission.asked', 'permission.replied',
];
Future<void> main(List<String> args) async {
final seconds = args.isEmpty ? 40 : int.tryParse(args[0]) ?? 40;
final dir = Directory.current.path;
final client = Client(Uri.parse('http://127.0.0.1:3000'));
final session = await client.createSession(title: 'event probe', directory: dir);
print('session ${session.id}');
final counts = <String, int>{};
final sub = client.streamEvents(types: types).listen((ev) {
final type = ev['type'] as String? ?? '';
final data = ev['data'] as Map<String, dynamic>? ?? {};
final sid = data['sessionID'];
if (sid != session.id) return;
counts[type] = (counts[type] ?? 0) + 1;
print('$type msg=${data['assistantMessageID'] ?? data['messageID']} '
'part=${data['partID']} keys=${data.keys.join(',')}');
}, onError: (Object e) => print('stream error: $e'));
await Future.delayed(const Duration(milliseconds: 500));
await client.prompt(session.id,
text: args.length > 1
? args.sublist(1).join(' ')
: 'Reply with the single word: pong',
directory: dir);
print('prompted');
await Future.delayed(Duration(seconds: seconds));
await sub.cancel();
final page = await client.listMessages(session.id, limit: 50, directory: dir);
print('---- messages: ${page.data.length}');
for (final m in page.data.reversed) {
final parts = m.content.map((p) => '${p.type}${p.name == null ? '' : '(${p.name})'}').join(',');
print('${m.id} ${m.type} parts=[$parts]');
}
print('---- event counts: $counts');
await client.deleteSession(session.id);
client.close();
exit(0);
}