[03-Developer] #260 in-app tool calling (Gemma 4 multi-turn)
ADR-0005 in-process tool runtime — 6 tools (catalog 2 + tracker 2 + habit 2), ToolDispatcher with JSON-schema validation + modal ConfirmGate for destructive ops, multi-turn LlmChatSession abstraction wired to flutter_gemma 0.16.5 (ToolChoice.auto), ChatSessionController with MAX_TURNS=4 safety + 8-turn history hint, ChatScreen entry behind AI opt-in. R3/R7/R8 enforced inside handlers. 41 new tests (envelope, catalog/tracker/habit tools, dispatcher, controller loop) — 151 total passing. Refs #260
This commit is contained in:
70
app/lib/ai/tools/confirm_gate.dart
Normal file
70
app/lib/ai/tools/confirm_gate.dart
Normal file
@@ -0,0 +1,70 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'tool_definition.dart';
|
||||
|
||||
/// Modal Confirm gate for destructive tools (ADR-0005 §OQ-3).
|
||||
///
|
||||
/// Shown by [ToolDispatcher] right before invoking a destructive handler.
|
||||
/// Returns `true` only if the user explicitly tapped the confirm action;
|
||||
/// outside-tap / back-press / unmounted-context all return `false`.
|
||||
class ConfirmGate {
|
||||
const ConfirmGate();
|
||||
|
||||
Future<bool> show(
|
||||
BuildContext context,
|
||||
ToolDefinition tool,
|
||||
Map<String, dynamic> args,
|
||||
) async {
|
||||
if (!context.mounted) return false;
|
||||
final summary = tool.summarize?.call(args) ?? _fallbackSummary(args);
|
||||
|
||||
final result = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
builder: (ctx) {
|
||||
final theme = Theme.of(ctx);
|
||||
return AlertDialog(
|
||||
title: const Text('이 작업을 수행할까요?'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(tool.description, style: theme.textTheme.bodyMedium),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(summary),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
FilledButton(
|
||||
autofocus: true,
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
child: const Text('수행'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
return result ?? false;
|
||||
}
|
||||
|
||||
String _fallbackSummary(Map<String, dynamic> args) {
|
||||
try {
|
||||
return const JsonEncoder.withIndent(' ').convert(args);
|
||||
} catch (_) {
|
||||
return args.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user