handle method
Implementation
@override
Future<StructuredResponse> handle(GlintSession session, CallToolRequest request) async {
final args = request.arguments ?? const {};
final edgeName = args['edge'] as String?;
if (edgeName != null) {
final edge = ScreenEdge.values.where((e) => e.name == edgeName).firstOrNull;
if (edge == null) {
return StructuredResponse.error(
summary: 'unknown edge: $edgeName',
errorKind: GlintErrorKind.invalidArgument,
nextSteps: [for (final e in ScreenEdge.values) 'edge:"${e.name}"'],
);
}
return withCoordinateChange(session, () async {
try {
await session.backend.edgeSwipe(edge);
} on Object catch (e) {
return StructuredResponse.backendError('edge swipe ${edge.name} was not delivered', e);
}
final input = session.backend.takeInput();
return StructuredResponse(
summary: 'swiped from the ${edge.name} edge${input == null ? '' : ' · ${input.label}'}',
data: {'ok': true, 'edge': edge.name, if (input != null) 'input': input.toJson()},
);
});
}
final t = readTargetedArgs(args, session.config);
// Coordinate swipe — bypasses scene resolution; the only path in device mode.
final seg = readSegment(args);
if (seg != null) {
final durationMs = argInt(args, 'durationMs') ?? 300;
return segmentSwipe(session, 'swipe', seg, durationMs,
verb: 'swiped', returnScene: t.returnScene, fetchScene: t.fetchScene);
}
final from = args['fromGlintId'] as String?;
final to = args['toGlintId'] as String?;
if (from == null || to == null) {
return StructuredResponse.error(
summary: 'swipe needs either fromGlintId + toGlintId, or x1,y1,x2,y2',
errorKind: GlintErrorKind.invalidArgument,
nextSteps: const [
'pass fromGlintId + toGlintId (from get_scene), or all four of '
'x1,y1,x2,y2',
],
);
}
final arming = await maybeAwaitReady(
session: session,
glintId: from,
awaitReady: t.awaitReady,
ceilingMs: t.readyTimeoutMs,
toolLabel: 'swipe',
);
if (arming is ArmingFailed) return arming.envelope;
final action = await openActionScene(session, snapshot: t.returnScene);
final scene = action.scene;
try {
final result = await session.interactor.run(
scene,
Swipe(SymbolicTarget(from), SymbolicTarget(to)),
);
var response = StructuredResponse.fromActionResult(result);
if (arming is ArmingReady) response = withArmedMetadata(response, arming);
return await appendPostAction(session, response, action.pre,
returnScene: t.returnScene, fetchScene: t.fetchScene);
} finally {
await action.dispose();
}
}